1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
285 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT is a space or tab
387 character. This is used to determine word wrapping. */
389 #define IT_DISPLAYING_WHITESPACE(it) \
390 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
392 /* Name of the face used to highlight trailing whitespace. */
394 static Lisp_Object Qtrailing_whitespace
;
396 /* Name and number of the face used to highlight escape glyphs. */
398 static Lisp_Object Qescape_glyph
;
400 /* Name and number of the face used to highlight non-breaking spaces. */
402 static Lisp_Object Qnobreak_space
;
404 /* The symbol `image' which is the car of the lists used to represent
405 images in Lisp. Also a tool bar style. */
409 /* The image map types. */
411 static Lisp_Object QCpointer
;
412 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
414 /* Tool bar styles */
415 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
417 /* Non-zero means print newline to stdout before next mini-buffer
420 int noninteractive_need_newline
;
422 /* Non-zero means print newline to message log before next message. */
424 static int message_log_need_newline
;
426 /* Three markers that message_dolog uses.
427 It could allocate them itself, but that causes trouble
428 in handling memory-full errors. */
429 static Lisp_Object message_dolog_marker1
;
430 static Lisp_Object message_dolog_marker2
;
431 static Lisp_Object message_dolog_marker3
;
433 /* The buffer position of the first character appearing entirely or
434 partially on the line of the selected window which contains the
435 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
436 redisplay optimization in redisplay_internal. */
438 static struct text_pos this_line_start_pos
;
440 /* Number of characters past the end of the line above, including the
441 terminating newline. */
443 static struct text_pos this_line_end_pos
;
445 /* The vertical positions and the height of this line. */
447 static int this_line_vpos
;
448 static int this_line_y
;
449 static int this_line_pixel_height
;
451 /* X position at which this display line starts. Usually zero;
452 negative if first character is partially visible. */
454 static int this_line_start_x
;
456 /* The smallest character position seen by move_it_* functions as they
457 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
458 hscrolled lines, see display_line. */
460 static struct text_pos this_line_min_pos
;
462 /* Buffer that this_line_.* variables are referring to. */
464 static struct buffer
*this_line_buffer
;
467 /* Values of those variables at last redisplay are stored as
468 properties on `overlay-arrow-position' symbol. However, if
469 Voverlay_arrow_position is a marker, last-arrow-position is its
470 numerical position. */
472 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
474 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
475 properties on a symbol in overlay-arrow-variable-list. */
477 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
479 Lisp_Object Qmenu_bar_update_hook
;
481 /* Nonzero if an overlay arrow has been displayed in this window. */
483 static int overlay_arrow_seen
;
485 /* Number of windows showing the buffer of the selected window (or
486 another buffer with the same base buffer). keyboard.c refers to
491 /* Vector containing glyphs for an ellipsis `...'. */
493 static Lisp_Object default_invis_vector
[3];
495 /* This is the window where the echo area message was displayed. It
496 is always a mini-buffer window, but it may not be the same window
497 currently active as a mini-buffer. */
499 Lisp_Object echo_area_window
;
501 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
502 pushes the current message and the value of
503 message_enable_multibyte on the stack, the function restore_message
504 pops the stack and displays MESSAGE again. */
506 static Lisp_Object Vmessage_stack
;
508 /* Nonzero means multibyte characters were enabled when the echo area
509 message was specified. */
511 static int message_enable_multibyte
;
513 /* Nonzero if we should redraw the mode lines on the next redisplay. */
515 int update_mode_lines
;
517 /* Nonzero if window sizes or contents have changed since last
518 redisplay that finished. */
520 int windows_or_buffers_changed
;
522 /* Nonzero means a frame's cursor type has been changed. */
524 int cursor_type_changed
;
526 /* Nonzero after display_mode_line if %l was used and it displayed a
529 static int line_number_displayed
;
531 /* The name of the *Messages* buffer, a string. */
533 static Lisp_Object Vmessages_buffer_name
;
535 /* Current, index 0, and last displayed echo area message. Either
536 buffers from echo_buffers, or nil to indicate no message. */
538 Lisp_Object echo_area_buffer
[2];
540 /* The buffers referenced from echo_area_buffer. */
542 static Lisp_Object echo_buffer
[2];
544 /* A vector saved used in with_area_buffer to reduce consing. */
546 static Lisp_Object Vwith_echo_area_save_vector
;
548 /* Non-zero means display_echo_area should display the last echo area
549 message again. Set by redisplay_preserve_echo_area. */
551 static int display_last_displayed_message_p
;
553 /* Nonzero if echo area is being used by print; zero if being used by
556 static int message_buf_print
;
558 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
560 static Lisp_Object Qinhibit_menubar_update
;
561 static Lisp_Object Qmessage_truncate_lines
;
563 /* Set to 1 in clear_message to make redisplay_internal aware
564 of an emptied echo area. */
566 static int message_cleared_p
;
568 /* A scratch glyph row with contents used for generating truncation
569 glyphs. Also used in direct_output_for_insert. */
571 #define MAX_SCRATCH_GLYPHS 100
572 static struct glyph_row scratch_glyph_row
;
573 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
575 /* Ascent and height of the last line processed by move_it_to. */
577 static int last_max_ascent
, last_height
;
579 /* Non-zero if there's a help-echo in the echo area. */
581 int help_echo_showing_p
;
583 /* If >= 0, computed, exact values of mode-line and header-line height
584 to use in the macros CURRENT_MODE_LINE_HEIGHT and
585 CURRENT_HEADER_LINE_HEIGHT. */
587 int current_mode_line_height
, current_header_line_height
;
589 /* The maximum distance to look ahead for text properties. Values
590 that are too small let us call compute_char_face and similar
591 functions too often which is expensive. Values that are too large
592 let us call compute_char_face and alike too often because we
593 might not be interested in text properties that far away. */
595 #define TEXT_PROP_DISTANCE_LIMIT 100
597 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
598 iterator state and later restore it. This is needed because the
599 bidi iterator on bidi.c keeps a stacked cache of its states, which
600 is really a singleton. When we use scratch iterator objects to
601 move around the buffer, we can cause the bidi cache to be pushed or
602 popped, and therefore we need to restore the cache state when we
603 return to the original iterator. */
604 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
607 bidi_unshelve_cache (CACHE, 1); \
609 CACHE = bidi_shelve_cache (); \
612 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
614 if (pITORIG != pITCOPY) \
615 *(pITORIG) = *(pITCOPY); \
616 bidi_unshelve_cache (CACHE, 0); \
622 /* Non-zero means print traces of redisplay if compiled with
625 int trace_redisplay_p
;
627 #endif /* GLYPH_DEBUG */
629 #ifdef DEBUG_TRACE_MOVE
630 /* Non-zero means trace with TRACE_MOVE to stderr. */
633 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
635 #define TRACE_MOVE(x) (void) 0
638 static Lisp_Object Qauto_hscroll_mode
;
640 /* Buffer being redisplayed -- for redisplay_window_error. */
642 static struct buffer
*displayed_buffer
;
644 /* Value returned from text property handlers (see below). */
649 HANDLED_RECOMPUTE_PROPS
,
650 HANDLED_OVERLAY_STRING_CONSUMED
,
654 /* A description of text properties that redisplay is interested
659 /* The name of the property. */
662 /* A unique index for the property. */
665 /* A handler function called to set up iterator IT from the property
666 at IT's current position. Value is used to steer handle_stop. */
667 enum prop_handled (*handler
) (struct it
*it
);
670 static enum prop_handled
handle_face_prop (struct it
*);
671 static enum prop_handled
handle_invisible_prop (struct it
*);
672 static enum prop_handled
handle_display_prop (struct it
*);
673 static enum prop_handled
handle_composition_prop (struct it
*);
674 static enum prop_handled
handle_overlay_change (struct it
*);
675 static enum prop_handled
handle_fontified_prop (struct it
*);
677 /* Properties handled by iterators. */
679 static struct props it_props
[] =
681 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
682 /* Handle `face' before `display' because some sub-properties of
683 `display' need to know the face. */
684 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
685 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
686 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
687 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
691 /* Value is the position described by X. If X is a marker, value is
692 the marker_position of X. Otherwise, value is X. */
694 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
696 /* Enumeration returned by some move_it_.* functions internally. */
700 /* Not used. Undefined value. */
703 /* Move ended at the requested buffer position or ZV. */
704 MOVE_POS_MATCH_OR_ZV
,
706 /* Move ended at the requested X pixel position. */
709 /* Move within a line ended at the end of a line that must be
713 /* Move within a line ended at the end of a line that would
714 be displayed truncated. */
717 /* Move within a line ended at a line end. */
721 /* This counter is used to clear the face cache every once in a while
722 in redisplay_internal. It is incremented for each redisplay.
723 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
726 #define CLEAR_FACE_CACHE_COUNT 500
727 static int clear_face_cache_count
;
729 /* Similarly for the image cache. */
731 #ifdef HAVE_WINDOW_SYSTEM
732 #define CLEAR_IMAGE_CACHE_COUNT 101
733 static int clear_image_cache_count
;
735 /* Null glyph slice */
736 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
739 /* Non-zero while redisplay_internal is in progress. */
743 static Lisp_Object Qinhibit_free_realized_faces
;
745 /* If a string, XTread_socket generates an event to display that string.
746 (The display is done in read_char.) */
748 Lisp_Object help_echo_string
;
749 Lisp_Object help_echo_window
;
750 Lisp_Object help_echo_object
;
751 ptrdiff_t help_echo_pos
;
753 /* Temporary variable for XTread_socket. */
755 Lisp_Object previous_help_echo_string
;
757 /* Platform-independent portion of hourglass implementation. */
759 /* Non-zero means an hourglass cursor is currently shown. */
760 int hourglass_shown_p
;
762 /* If non-null, an asynchronous timer that, when it expires, displays
763 an hourglass cursor on all frames. */
764 struct atimer
*hourglass_atimer
;
766 /* Name of the face used to display glyphless characters. */
767 Lisp_Object Qglyphless_char
;
769 /* Symbol for the purpose of Vglyphless_char_display. */
770 static Lisp_Object Qglyphless_char_display
;
772 /* Method symbols for Vglyphless_char_display. */
773 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
775 /* Default pixel width of `thin-space' display method. */
776 #define THIN_SPACE_WIDTH 1
778 /* Default number of seconds to wait before displaying an hourglass
780 #define DEFAULT_HOURGLASS_DELAY 1
783 /* Function prototypes. */
785 static void setup_for_ellipsis (struct it
*, int);
786 static void set_iterator_to_next (struct it
*, int);
787 static void mark_window_display_accurate_1 (struct window
*, int);
788 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
789 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
790 static int cursor_row_p (struct glyph_row
*);
791 static int redisplay_mode_lines (Lisp_Object
, int);
792 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
794 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
796 static void handle_line_prefix (struct it
*);
798 static void pint2str (char *, int, ptrdiff_t);
799 static void pint2hrstr (char *, int, ptrdiff_t);
800 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
802 static void reconsider_clip_changes (struct window
*, struct buffer
*);
803 static int text_outside_line_unchanged_p (struct window
*,
804 ptrdiff_t, ptrdiff_t);
805 static void store_mode_line_noprop_char (char);
806 static int store_mode_line_noprop (const char *, int, int);
807 static void handle_stop (struct it
*);
808 static void handle_stop_backwards (struct it
*, ptrdiff_t);
809 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
810 static void ensure_echo_area_buffers (void);
811 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
812 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
813 static int with_echo_area_buffer (struct window
*, int,
814 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
815 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
816 static void clear_garbaged_frames (void);
817 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
818 static void pop_message (void);
819 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
820 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
821 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
822 static int display_echo_area (struct window
*);
823 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
824 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
825 static Lisp_Object
unwind_redisplay (Lisp_Object
);
826 static int string_char_and_length (const unsigned char *, int *);
827 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
829 static int compute_window_start_on_continuation_line (struct window
*);
830 static Lisp_Object
safe_eval_handler (Lisp_Object
);
831 static void insert_left_trunc_glyphs (struct it
*);
832 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
834 static void extend_face_to_end_of_line (struct it
*);
835 static int append_space_for_newline (struct it
*, int);
836 static int cursor_row_fully_visible_p (struct window
*, int, int);
837 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
838 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
839 static int trailing_whitespace_p (ptrdiff_t);
840 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
841 static void push_it (struct it
*, struct text_pos
*);
842 static void pop_it (struct it
*);
843 static void sync_frame_with_window_matrix_rows (struct window
*);
844 static void select_frame_for_redisplay (Lisp_Object
);
845 static void redisplay_internal (void);
846 static int echo_area_display (int);
847 static void redisplay_windows (Lisp_Object
);
848 static void redisplay_window (Lisp_Object
, int);
849 static Lisp_Object
redisplay_window_error (Lisp_Object
);
850 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
851 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
852 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
853 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
855 static int update_menu_bar (struct frame
*, int, int);
856 static int try_window_reusing_current_matrix (struct window
*);
857 static int try_window_id (struct window
*);
858 static int display_line (struct it
*);
859 static int display_mode_lines (struct window
*);
860 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
861 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
862 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
863 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
864 static void display_menu_bar (struct window
*);
865 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
867 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
868 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
869 static void compute_line_metrics (struct it
*);
870 static void run_redisplay_end_trigger_hook (struct it
*);
871 static int get_overlay_strings (struct it
*, ptrdiff_t);
872 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
873 static void next_overlay_string (struct it
*);
874 static void reseat (struct it
*, struct text_pos
, int);
875 static void reseat_1 (struct it
*, struct text_pos
, int);
876 static void back_to_previous_visible_line_start (struct it
*);
877 void reseat_at_previous_visible_line_start (struct it
*);
878 static void reseat_at_next_visible_line_start (struct it
*, int);
879 static int next_element_from_ellipsis (struct it
*);
880 static int next_element_from_display_vector (struct it
*);
881 static int next_element_from_string (struct it
*);
882 static int next_element_from_c_string (struct it
*);
883 static int next_element_from_buffer (struct it
*);
884 static int next_element_from_composition (struct it
*);
885 static int next_element_from_image (struct it
*);
886 static int next_element_from_stretch (struct it
*);
887 static void load_overlay_strings (struct it
*, ptrdiff_t);
888 static int init_from_display_pos (struct it
*, struct window
*,
889 struct display_pos
*);
890 static void reseat_to_string (struct it
*, const char *,
891 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
892 static int get_next_display_element (struct it
*);
893 static enum move_it_result
894 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
895 enum move_operation_enum
);
896 void move_it_vertically_backward (struct it
*, int);
897 static void init_to_row_start (struct it
*, struct window
*,
899 static int init_to_row_end (struct it
*, struct window
*,
901 static void back_to_previous_line_start (struct it
*);
902 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
903 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
904 Lisp_Object
, ptrdiff_t);
905 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
906 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
907 static ptrdiff_t number_of_chars (const char *, int);
908 static void compute_stop_pos (struct it
*);
909 static void compute_string_pos (struct text_pos
*, struct text_pos
,
911 static int face_before_or_after_it_pos (struct it
*, int);
912 static ptrdiff_t next_overlay_change (ptrdiff_t);
913 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
914 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
915 static int handle_single_display_spec (struct it
*, Lisp_Object
,
916 Lisp_Object
, Lisp_Object
,
917 struct text_pos
*, ptrdiff_t, int, int);
918 static int underlying_face_id (struct it
*);
919 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
922 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
923 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
925 #ifdef HAVE_WINDOW_SYSTEM
927 static void x_consider_frame_title (Lisp_Object
);
928 static int tool_bar_lines_needed (struct frame
*, int *);
929 static void update_tool_bar (struct frame
*, int);
930 static void build_desired_tool_bar_string (struct frame
*f
);
931 static int redisplay_tool_bar (struct frame
*);
932 static void display_tool_bar_line (struct it
*, int);
933 static void notice_overwritten_cursor (struct window
*,
936 static void append_stretch_glyph (struct it
*, Lisp_Object
,
940 #endif /* HAVE_WINDOW_SYSTEM */
942 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
943 static int coords_in_mouse_face_p (struct window
*, int, int);
947 /***********************************************************************
948 Window display dimensions
949 ***********************************************************************/
951 /* Return the bottom boundary y-position for text lines in window W.
952 This is the first y position at which a line cannot start.
953 It is relative to the top of the window.
955 This is the height of W minus the height of a mode line, if any. */
958 window_text_bottom_y (struct window
*w
)
960 int height
= WINDOW_TOTAL_HEIGHT (w
);
962 if (WINDOW_WANTS_MODELINE_P (w
))
963 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
967 /* Return the pixel width of display area AREA of window W. AREA < 0
968 means return the total width of W, not including fringes to
969 the left and right of the window. */
972 window_box_width (struct window
*w
, int area
)
974 int cols
= XFASTINT (w
->total_cols
);
977 if (!w
->pseudo_window_p
)
979 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
981 if (area
== TEXT_AREA
)
983 if (INTEGERP (w
->left_margin_cols
))
984 cols
-= XFASTINT (w
->left_margin_cols
);
985 if (INTEGERP (w
->right_margin_cols
))
986 cols
-= XFASTINT (w
->right_margin_cols
);
987 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
989 else if (area
== LEFT_MARGIN_AREA
)
991 cols
= (INTEGERP (w
->left_margin_cols
)
992 ? XFASTINT (w
->left_margin_cols
) : 0);
995 else if (area
== RIGHT_MARGIN_AREA
)
997 cols
= (INTEGERP (w
->right_margin_cols
)
998 ? XFASTINT (w
->right_margin_cols
) : 0);
1003 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1007 /* Return the pixel height of the display area of window W, not
1008 including mode lines of W, if any. */
1011 window_box_height (struct window
*w
)
1013 struct frame
*f
= XFRAME (w
->frame
);
1014 int height
= WINDOW_TOTAL_HEIGHT (w
);
1016 xassert (height
>= 0);
1018 /* Note: the code below that determines the mode-line/header-line
1019 height is essentially the same as that contained in the macro
1020 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1021 the appropriate glyph row has its `mode_line_p' flag set,
1022 and if it doesn't, uses estimate_mode_line_height instead. */
1024 if (WINDOW_WANTS_MODELINE_P (w
))
1026 struct glyph_row
*ml_row
1027 = (w
->current_matrix
&& w
->current_matrix
->rows
1028 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1030 if (ml_row
&& ml_row
->mode_line_p
)
1031 height
-= ml_row
->height
;
1033 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1036 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1038 struct glyph_row
*hl_row
1039 = (w
->current_matrix
&& w
->current_matrix
->rows
1040 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1042 if (hl_row
&& hl_row
->mode_line_p
)
1043 height
-= hl_row
->height
;
1045 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1048 /* With a very small font and a mode-line that's taller than
1049 default, we might end up with a negative height. */
1050 return max (0, height
);
1053 /* Return the window-relative coordinate of the left edge of display
1054 area AREA of window W. AREA < 0 means return the left edge of the
1055 whole window, to the right of the left fringe of W. */
1058 window_box_left_offset (struct window
*w
, int area
)
1062 if (w
->pseudo_window_p
)
1065 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1067 if (area
== TEXT_AREA
)
1068 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1069 + window_box_width (w
, LEFT_MARGIN_AREA
));
1070 else if (area
== RIGHT_MARGIN_AREA
)
1071 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1072 + window_box_width (w
, LEFT_MARGIN_AREA
)
1073 + window_box_width (w
, TEXT_AREA
)
1074 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1076 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1077 else if (area
== LEFT_MARGIN_AREA
1078 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1079 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1085 /* Return the window-relative coordinate of the right edge of display
1086 area AREA of window W. AREA < 0 means return the right edge of the
1087 whole window, to the left of the right fringe of W. */
1090 window_box_right_offset (struct window
*w
, int area
)
1092 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1095 /* Return the frame-relative coordinate of the left edge of display
1096 area AREA of window W. AREA < 0 means return the left edge of the
1097 whole window, to the right of the left fringe of W. */
1100 window_box_left (struct window
*w
, int area
)
1102 struct frame
*f
= XFRAME (w
->frame
);
1105 if (w
->pseudo_window_p
)
1106 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1108 x
= (WINDOW_LEFT_EDGE_X (w
)
1109 + window_box_left_offset (w
, area
));
1115 /* Return the frame-relative coordinate of the right edge of display
1116 area AREA of window W. AREA < 0 means return the right edge of the
1117 whole window, to the left of the right fringe of W. */
1120 window_box_right (struct window
*w
, int area
)
1122 return window_box_left (w
, area
) + window_box_width (w
, area
);
1125 /* Get the bounding box of the display area AREA of window W, without
1126 mode lines, in frame-relative coordinates. AREA < 0 means the
1127 whole window, not including the left and right fringes of
1128 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1129 coordinates of the upper-left corner of the box. Return in
1130 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1133 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1134 int *box_width
, int *box_height
)
1137 *box_width
= window_box_width (w
, area
);
1139 *box_height
= window_box_height (w
);
1141 *box_x
= window_box_left (w
, area
);
1144 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1145 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1146 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1151 /* Get the bounding box of the display area AREA of window W, without
1152 mode lines. AREA < 0 means the whole window, not including the
1153 left and right fringe of the window. Return in *TOP_LEFT_X
1154 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1155 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1156 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1160 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1161 int *bottom_right_x
, int *bottom_right_y
)
1163 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1165 *bottom_right_x
+= *top_left_x
;
1166 *bottom_right_y
+= *top_left_y
;
1171 /***********************************************************************
1173 ***********************************************************************/
1175 /* Return the bottom y-position of the line the iterator IT is in.
1176 This can modify IT's settings. */
1179 line_bottom_y (struct it
*it
)
1181 int line_height
= it
->max_ascent
+ it
->max_descent
;
1182 int line_top_y
= it
->current_y
;
1184 if (line_height
== 0)
1187 line_height
= last_height
;
1188 else if (IT_CHARPOS (*it
) < ZV
)
1190 move_it_by_lines (it
, 1);
1191 line_height
= (it
->max_ascent
|| it
->max_descent
1192 ? it
->max_ascent
+ it
->max_descent
1197 struct glyph_row
*row
= it
->glyph_row
;
1199 /* Use the default character height. */
1200 it
->glyph_row
= NULL
;
1201 it
->what
= IT_CHARACTER
;
1204 PRODUCE_GLYPHS (it
);
1205 line_height
= it
->ascent
+ it
->descent
;
1206 it
->glyph_row
= row
;
1210 return line_top_y
+ line_height
;
1213 /* Subroutine of pos_visible_p below. Extracts a display string, if
1214 any, from the display spec given as its argument. */
1216 string_from_display_spec (Lisp_Object spec
)
1220 while (CONSP (spec
))
1222 if (STRINGP (XCAR (spec
)))
1227 else if (VECTORP (spec
))
1231 for (i
= 0; i
< ASIZE (spec
); i
++)
1233 if (STRINGP (AREF (spec
, i
)))
1234 return AREF (spec
, i
);
1242 /* Return 1 if position CHARPOS is visible in window W.
1243 CHARPOS < 0 means return info about WINDOW_END position.
1244 If visible, set *X and *Y to pixel coordinates of top left corner.
1245 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1246 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1249 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1250 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1253 void *itdata
= bidi_shelve_cache ();
1254 struct text_pos top
;
1256 struct buffer
*old_buffer
= NULL
;
1258 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1261 if (XBUFFER (w
->buffer
) != current_buffer
)
1263 old_buffer
= current_buffer
;
1264 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1267 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1269 /* Compute exact mode line heights. */
1270 if (WINDOW_WANTS_MODELINE_P (w
))
1271 current_mode_line_height
1272 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1273 BVAR (current_buffer
, mode_line_format
));
1275 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1276 current_header_line_height
1277 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1278 BVAR (current_buffer
, header_line_format
));
1280 start_display (&it
, w
, top
);
1281 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1282 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1285 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1286 && IT_CHARPOS (it
) >= charpos
)
1287 /* When scanning backwards under bidi iteration, move_it_to
1288 stops at or _before_ CHARPOS, because it stops at or to
1289 the _right_ of the character at CHARPOS. */
1290 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1291 && IT_CHARPOS (it
) <= charpos
)))
1293 /* We have reached CHARPOS, or passed it. How the call to
1294 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1295 or covered by a display property, move_it_to stops at the end
1296 of the invisible text, to the right of CHARPOS. (ii) If
1297 CHARPOS is in a display vector, move_it_to stops on its last
1299 int top_x
= it
.current_x
;
1300 int top_y
= it
.current_y
;
1301 enum it_method it_method
= it
.method
;
1302 /* Calling line_bottom_y may change it.method, it.position, etc. */
1303 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1304 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1306 if (top_y
< window_top_y
)
1307 visible_p
= bottom_y
> window_top_y
;
1308 else if (top_y
< it
.last_visible_y
)
1312 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1314 /* We stopped on the last glyph of a display vector.
1315 Try and recompute. Hack alert! */
1316 if (charpos
< 2 || top
.charpos
>= charpos
)
1317 top_x
= it
.glyph_row
->x
;
1321 start_display (&it2
, w
, top
);
1322 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1323 get_next_display_element (&it2
);
1324 PRODUCE_GLYPHS (&it2
);
1325 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1326 || it2
.current_x
> it2
.last_visible_x
)
1327 top_x
= it
.glyph_row
->x
;
1330 top_x
= it2
.current_x
;
1331 top_y
= it2
.current_y
;
1335 else if (IT_CHARPOS (it
) != charpos
)
1337 Lisp_Object cpos
= make_number (charpos
);
1338 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1339 Lisp_Object string
= string_from_display_spec (spec
);
1340 int newline_in_string
= 0;
1342 if (STRINGP (string
))
1344 const char *s
= SSDATA (string
);
1345 const char *e
= s
+ SBYTES (string
);
1350 newline_in_string
= 1;
1355 /* The tricky code below is needed because there's a
1356 discrepancy between move_it_to and how we set cursor
1357 when the display line ends in a newline from a
1358 display string. move_it_to will stop _after_ such
1359 display strings, whereas set_cursor_from_row
1360 conspires with cursor_row_p to place the cursor on
1361 the first glyph produced from the display string. */
1363 /* We have overshoot PT because it is covered by a
1364 display property whose value is a string. If the
1365 string includes embedded newlines, we are also in the
1366 wrong display line. Backtrack to the correct line,
1367 where the display string begins. */
1368 if (newline_in_string
)
1370 Lisp_Object startpos
, endpos
;
1371 EMACS_INT start
, end
;
1374 /* Find the first and the last buffer positions
1375 covered by the display string. */
1377 Fnext_single_char_property_change (cpos
, Qdisplay
,
1380 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1382 start
= XFASTINT (startpos
);
1383 end
= XFASTINT (endpos
);
1384 /* Move to the last buffer position before the
1385 display property. */
1386 start_display (&it3
, w
, top
);
1387 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1388 /* Move forward one more line if the position before
1389 the display string is a newline or if it is the
1390 rightmost character on a line that is
1391 continued or word-wrapped. */
1392 if (it3
.method
== GET_FROM_BUFFER
1394 move_it_by_lines (&it3
, 1);
1395 else if (move_it_in_display_line_to (&it3
, -1,
1399 == MOVE_LINE_CONTINUED
)
1401 move_it_by_lines (&it3
, 1);
1402 /* When we are under word-wrap, the #$@%!
1403 move_it_by_lines moves 2 lines, so we need to
1405 if (it3
.line_wrap
== WORD_WRAP
)
1406 move_it_by_lines (&it3
, -1);
1409 /* Record the vertical coordinate of the display
1410 line where we wound up. */
1411 top_y
= it3
.current_y
;
1414 /* When characters are reordered for display,
1415 the character displayed to the left of the
1416 display string could be _after_ the display
1417 property in the logical order. Use the
1418 smallest vertical position of these two. */
1419 start_display (&it3
, w
, top
);
1420 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1421 if (it3
.current_y
< top_y
)
1422 top_y
= it3
.current_y
;
1424 /* Move from the top of the window to the beginning
1425 of the display line where the display string
1427 start_display (&it3
, w
, top
);
1428 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1429 /* Finally, advance the iterator until we hit the
1430 first display element whose character position is
1431 CHARPOS, or until the first newline from the
1432 display string, which signals the end of the
1434 while (get_next_display_element (&it3
))
1436 PRODUCE_GLYPHS (&it3
);
1437 if (IT_CHARPOS (it3
) == charpos
1438 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1440 set_iterator_to_next (&it3
, 0);
1442 top_x
= it3
.current_x
- it3
.pixel_width
;
1443 /* Normally, we would exit the above loop because we
1444 found the display element whose character
1445 position is CHARPOS. For the contingency that we
1446 didn't, and stopped at the first newline from the
1447 display string, move back over the glyphs
1448 produced from the string, until we find the
1449 rightmost glyph not from the string. */
1450 if (IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1452 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1453 + it3
.glyph_row
->used
[TEXT_AREA
];
1455 while (EQ ((g
- 1)->object
, string
))
1458 top_x
-= g
->pixel_width
;
1460 xassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1461 + it3
.glyph_row
->used
[TEXT_AREA
]);
1467 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1468 *rtop
= max (0, window_top_y
- top_y
);
1469 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1470 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1471 - max (top_y
, window_top_y
)));
1477 /* We were asked to provide info about WINDOW_END. */
1479 void *it2data
= NULL
;
1481 SAVE_IT (it2
, it
, it2data
);
1482 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1483 move_it_by_lines (&it
, 1);
1484 if (charpos
< IT_CHARPOS (it
)
1485 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1488 RESTORE_IT (&it2
, &it2
, it2data
);
1489 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1491 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1492 *rtop
= max (0, -it2
.current_y
);
1493 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1494 - it
.last_visible_y
));
1495 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1497 - max (it2
.current_y
,
1498 WINDOW_HEADER_LINE_HEIGHT (w
))));
1502 bidi_unshelve_cache (it2data
, 1);
1504 bidi_unshelve_cache (itdata
, 0);
1507 set_buffer_internal_1 (old_buffer
);
1509 current_header_line_height
= current_mode_line_height
= -1;
1511 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1512 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1515 /* Debugging code. */
1517 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1518 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1520 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1527 /* Return the next character from STR. Return in *LEN the length of
1528 the character. This is like STRING_CHAR_AND_LENGTH but never
1529 returns an invalid character. If we find one, we return a `?', but
1530 with the length of the invalid character. */
1533 string_char_and_length (const unsigned char *str
, int *len
)
1537 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1538 if (!CHAR_VALID_P (c
))
1539 /* We may not change the length here because other places in Emacs
1540 don't use this function, i.e. they silently accept invalid
1549 /* Given a position POS containing a valid character and byte position
1550 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1552 static struct text_pos
1553 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1555 xassert (STRINGP (string
) && nchars
>= 0);
1557 if (STRING_MULTIBYTE (string
))
1559 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1564 string_char_and_length (p
, &len
);
1567 BYTEPOS (pos
) += len
;
1571 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1577 /* Value is the text position, i.e. character and byte position,
1578 for character position CHARPOS in STRING. */
1580 static inline struct text_pos
1581 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1583 struct text_pos pos
;
1584 xassert (STRINGP (string
));
1585 xassert (charpos
>= 0);
1586 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1591 /* Value is a text position, i.e. character and byte position, for
1592 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1593 means recognize multibyte characters. */
1595 static struct text_pos
1596 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1598 struct text_pos pos
;
1600 xassert (s
!= NULL
);
1601 xassert (charpos
>= 0);
1607 SET_TEXT_POS (pos
, 0, 0);
1610 string_char_and_length ((const unsigned char *) s
, &len
);
1613 BYTEPOS (pos
) += len
;
1617 SET_TEXT_POS (pos
, charpos
, charpos
);
1623 /* Value is the number of characters in C string S. MULTIBYTE_P
1624 non-zero means recognize multibyte characters. */
1627 number_of_chars (const char *s
, int multibyte_p
)
1633 ptrdiff_t rest
= strlen (s
);
1635 const unsigned char *p
= (const unsigned char *) s
;
1637 for (nchars
= 0; rest
> 0; ++nchars
)
1639 string_char_and_length (p
, &len
);
1640 rest
-= len
, p
+= len
;
1644 nchars
= strlen (s
);
1650 /* Compute byte position NEWPOS->bytepos corresponding to
1651 NEWPOS->charpos. POS is a known position in string STRING.
1652 NEWPOS->charpos must be >= POS.charpos. */
1655 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1657 xassert (STRINGP (string
));
1658 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1660 if (STRING_MULTIBYTE (string
))
1661 *newpos
= string_pos_nchars_ahead (pos
, string
,
1662 CHARPOS (*newpos
) - CHARPOS (pos
));
1664 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1668 Return an estimation of the pixel height of mode or header lines on
1669 frame F. FACE_ID specifies what line's height to estimate. */
1672 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1674 #ifdef HAVE_WINDOW_SYSTEM
1675 if (FRAME_WINDOW_P (f
))
1677 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1679 /* This function is called so early when Emacs starts that the face
1680 cache and mode line face are not yet initialized. */
1681 if (FRAME_FACE_CACHE (f
))
1683 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1687 height
= FONT_HEIGHT (face
->font
);
1688 if (face
->box_line_width
> 0)
1689 height
+= 2 * face
->box_line_width
;
1700 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1701 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1702 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1703 not force the value into range. */
1706 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1707 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1710 #ifdef HAVE_WINDOW_SYSTEM
1711 if (FRAME_WINDOW_P (f
))
1713 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1714 even for negative values. */
1716 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1718 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1720 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1721 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1724 STORE_NATIVE_RECT (*bounds
,
1725 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1726 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1727 FRAME_COLUMN_WIDTH (f
) - 1,
1728 FRAME_LINE_HEIGHT (f
) - 1);
1734 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1735 pix_x
= FRAME_TOTAL_COLS (f
);
1739 else if (pix_y
> FRAME_LINES (f
))
1740 pix_y
= FRAME_LINES (f
);
1750 /* Find the glyph under window-relative coordinates X/Y in window W.
1751 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1752 strings. Return in *HPOS and *VPOS the row and column number of
1753 the glyph found. Return in *AREA the glyph area containing X.
1754 Value is a pointer to the glyph found or null if X/Y is not on
1755 text, or we can't tell because W's current matrix is not up to
1760 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1761 int *dx
, int *dy
, int *area
)
1763 struct glyph
*glyph
, *end
;
1764 struct glyph_row
*row
= NULL
;
1767 /* Find row containing Y. Give up if some row is not enabled. */
1768 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1770 row
= MATRIX_ROW (w
->current_matrix
, i
);
1771 if (!row
->enabled_p
)
1773 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1780 /* Give up if Y is not in the window. */
1781 if (i
== w
->current_matrix
->nrows
)
1784 /* Get the glyph area containing X. */
1785 if (w
->pseudo_window_p
)
1792 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1794 *area
= LEFT_MARGIN_AREA
;
1795 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1797 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1800 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1804 *area
= RIGHT_MARGIN_AREA
;
1805 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1809 /* Find glyph containing X. */
1810 glyph
= row
->glyphs
[*area
];
1811 end
= glyph
+ row
->used
[*area
];
1813 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1815 x
-= glyph
->pixel_width
;
1825 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1828 *hpos
= glyph
- row
->glyphs
[*area
];
1832 /* Convert frame-relative x/y to coordinates relative to window W.
1833 Takes pseudo-windows into account. */
1836 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1838 if (w
->pseudo_window_p
)
1840 /* A pseudo-window is always full-width, and starts at the
1841 left edge of the frame, plus a frame border. */
1842 struct frame
*f
= XFRAME (w
->frame
);
1843 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1844 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1848 *x
-= WINDOW_LEFT_EDGE_X (w
);
1849 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1853 #ifdef HAVE_WINDOW_SYSTEM
1856 Return in RECTS[] at most N clipping rectangles for glyph string S.
1857 Return the number of stored rectangles. */
1860 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1867 if (s
->row
->full_width_p
)
1869 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1870 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1871 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1873 /* Unless displaying a mode or menu bar line, which are always
1874 fully visible, clip to the visible part of the row. */
1875 if (s
->w
->pseudo_window_p
)
1876 r
.height
= s
->row
->visible_height
;
1878 r
.height
= s
->height
;
1882 /* This is a text line that may be partially visible. */
1883 r
.x
= window_box_left (s
->w
, s
->area
);
1884 r
.width
= window_box_width (s
->w
, s
->area
);
1885 r
.height
= s
->row
->visible_height
;
1889 if (r
.x
< s
->clip_head
->x
)
1891 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1892 r
.width
-= s
->clip_head
->x
- r
.x
;
1895 r
.x
= s
->clip_head
->x
;
1898 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1900 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1901 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1906 /* If S draws overlapping rows, it's sufficient to use the top and
1907 bottom of the window for clipping because this glyph string
1908 intentionally draws over other lines. */
1909 if (s
->for_overlaps
)
1911 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1912 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1914 /* Alas, the above simple strategy does not work for the
1915 environments with anti-aliased text: if the same text is
1916 drawn onto the same place multiple times, it gets thicker.
1917 If the overlap we are processing is for the erased cursor, we
1918 take the intersection with the rectangle of the cursor. */
1919 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1921 XRectangle rc
, r_save
= r
;
1923 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1924 rc
.y
= s
->w
->phys_cursor
.y
;
1925 rc
.width
= s
->w
->phys_cursor_width
;
1926 rc
.height
= s
->w
->phys_cursor_height
;
1928 x_intersect_rectangles (&r_save
, &rc
, &r
);
1933 /* Don't use S->y for clipping because it doesn't take partially
1934 visible lines into account. For example, it can be negative for
1935 partially visible lines at the top of a window. */
1936 if (!s
->row
->full_width_p
1937 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1938 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1940 r
.y
= max (0, s
->row
->y
);
1943 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1945 /* If drawing the cursor, don't let glyph draw outside its
1946 advertised boundaries. Cleartype does this under some circumstances. */
1947 if (s
->hl
== DRAW_CURSOR
)
1949 struct glyph
*glyph
= s
->first_glyph
;
1954 r
.width
-= s
->x
- r
.x
;
1957 r
.width
= min (r
.width
, glyph
->pixel_width
);
1959 /* If r.y is below window bottom, ensure that we still see a cursor. */
1960 height
= min (glyph
->ascent
+ glyph
->descent
,
1961 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1962 max_y
= window_text_bottom_y (s
->w
) - height
;
1963 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1964 if (s
->ybase
- glyph
->ascent
> max_y
)
1971 /* Don't draw cursor glyph taller than our actual glyph. */
1972 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1973 if (height
< r
.height
)
1975 max_y
= r
.y
+ r
.height
;
1976 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1977 r
.height
= min (max_y
- r
.y
, height
);
1984 XRectangle r_save
= r
;
1986 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1990 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1991 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1993 #ifdef CONVERT_FROM_XRECT
1994 CONVERT_FROM_XRECT (r
, *rects
);
2002 /* If we are processing overlapping and allowed to return
2003 multiple clipping rectangles, we exclude the row of the glyph
2004 string from the clipping rectangle. This is to avoid drawing
2005 the same text on the environment with anti-aliasing. */
2006 #ifdef CONVERT_FROM_XRECT
2009 XRectangle
*rs
= rects
;
2011 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2013 if (s
->for_overlaps
& OVERLAPS_PRED
)
2016 if (r
.y
+ r
.height
> row_y
)
2019 rs
[i
].height
= row_y
- r
.y
;
2025 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2028 if (r
.y
< row_y
+ s
->row
->visible_height
)
2030 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2032 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2033 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2042 #ifdef CONVERT_FROM_XRECT
2043 for (i
= 0; i
< n
; i
++)
2044 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2051 Return in *NR the clipping rectangle for glyph string S. */
2054 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2056 get_glyph_string_clip_rects (s
, nr
, 1);
2061 Return the position and height of the phys cursor in window W.
2062 Set w->phys_cursor_width to width of phys cursor.
2066 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2067 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2069 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2070 int x
, y
, wd
, h
, h0
, y0
;
2072 /* Compute the width of the rectangle to draw. If on a stretch
2073 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2074 rectangle as wide as the glyph, but use a canonical character
2076 wd
= glyph
->pixel_width
- 1;
2077 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2081 x
= w
->phys_cursor
.x
;
2088 if (glyph
->type
== STRETCH_GLYPH
2089 && !x_stretch_cursor_p
)
2090 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2091 w
->phys_cursor_width
= wd
;
2093 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2095 /* If y is below window bottom, ensure that we still see a cursor. */
2096 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2098 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2099 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2101 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2104 h
= max (h
- (y0
- y
) + 1, h0
);
2109 y0
= window_text_bottom_y (w
) - h0
;
2117 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2118 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2123 * Remember which glyph the mouse is over.
2127 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2131 struct glyph_row
*r
, *gr
, *end_row
;
2132 enum window_part part
;
2133 enum glyph_row_area area
;
2134 int x
, y
, width
, height
;
2136 /* Try to determine frame pixel position and size of the glyph under
2137 frame pixel coordinates X/Y on frame F. */
2139 if (!f
->glyphs_initialized_p
2140 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2143 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2144 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2148 w
= XWINDOW (window
);
2149 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2150 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2152 x
= window_relative_x_coord (w
, part
, gx
);
2153 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2155 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2156 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2158 if (w
->pseudo_window_p
)
2161 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2167 case ON_LEFT_MARGIN
:
2168 area
= LEFT_MARGIN_AREA
;
2171 case ON_RIGHT_MARGIN
:
2172 area
= RIGHT_MARGIN_AREA
;
2175 case ON_HEADER_LINE
:
2177 gr
= (part
== ON_HEADER_LINE
2178 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2179 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2182 goto text_glyph_row_found
;
2189 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2190 if (r
->y
+ r
->height
> y
)
2196 text_glyph_row_found
:
2199 struct glyph
*g
= gr
->glyphs
[area
];
2200 struct glyph
*end
= g
+ gr
->used
[area
];
2202 height
= gr
->height
;
2203 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2204 if (gx
+ g
->pixel_width
> x
)
2209 if (g
->type
== IMAGE_GLYPH
)
2211 /* Don't remember when mouse is over image, as
2212 image may have hot-spots. */
2213 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2216 width
= g
->pixel_width
;
2220 /* Use nominal char spacing at end of line. */
2222 gx
+= (x
/ width
) * width
;
2225 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2226 gx
+= window_box_left_offset (w
, area
);
2230 /* Use nominal line height at end of window. */
2231 gx
= (x
/ width
) * width
;
2233 gy
+= (y
/ height
) * height
;
2237 case ON_LEFT_FRINGE
:
2238 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2239 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2240 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2241 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2244 case ON_RIGHT_FRINGE
:
2245 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2246 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2247 : window_box_right_offset (w
, TEXT_AREA
));
2248 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2252 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2254 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2255 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2256 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2258 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2262 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2263 if (r
->y
+ r
->height
> y
)
2270 height
= gr
->height
;
2273 /* Use nominal line height at end of window. */
2275 gy
+= (y
/ height
) * height
;
2282 /* If there is no glyph under the mouse, then we divide the screen
2283 into a grid of the smallest glyph in the frame, and use that
2286 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2287 round down even for negative values. */
2293 gx
= (gx
/ width
) * width
;
2294 gy
= (gy
/ height
) * height
;
2299 gx
+= WINDOW_LEFT_EDGE_X (w
);
2300 gy
+= WINDOW_TOP_EDGE_Y (w
);
2303 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2305 /* Visible feedback for debugging. */
2308 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2309 f
->output_data
.x
->normal_gc
,
2310 gx
, gy
, width
, height
);
2316 #endif /* HAVE_WINDOW_SYSTEM */
2319 /***********************************************************************
2320 Lisp form evaluation
2321 ***********************************************************************/
2323 /* Error handler for safe_eval and safe_call. */
2326 safe_eval_handler (Lisp_Object arg
)
2328 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2333 /* Evaluate SEXPR and return the result, or nil if something went
2334 wrong. Prevent redisplay during the evaluation. */
2336 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2337 Return the result, or nil if something went wrong. Prevent
2338 redisplay during the evaluation. */
2341 safe_call (ptrdiff_t nargs
, Lisp_Object
*args
)
2345 if (inhibit_eval_during_redisplay
)
2349 ptrdiff_t count
= SPECPDL_INDEX ();
2350 struct gcpro gcpro1
;
2353 gcpro1
.nvars
= nargs
;
2354 specbind (Qinhibit_redisplay
, Qt
);
2355 /* Use Qt to ensure debugger does not run,
2356 so there is no possibility of wanting to redisplay. */
2357 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2360 val
= unbind_to (count
, val
);
2367 /* Call function FN with one argument ARG.
2368 Return the result, or nil if something went wrong. */
2371 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2373 Lisp_Object args
[2];
2376 return safe_call (2, args
);
2379 static Lisp_Object Qeval
;
2382 safe_eval (Lisp_Object sexpr
)
2384 return safe_call1 (Qeval
, sexpr
);
2387 /* Call function FN with one argument ARG.
2388 Return the result, or nil if something went wrong. */
2391 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2393 Lisp_Object args
[3];
2397 return safe_call (3, args
);
2402 /***********************************************************************
2404 ***********************************************************************/
2408 /* Define CHECK_IT to perform sanity checks on iterators.
2409 This is for debugging. It is too slow to do unconditionally. */
2412 check_it (struct it
*it
)
2414 if (it
->method
== GET_FROM_STRING
)
2416 xassert (STRINGP (it
->string
));
2417 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2421 xassert (IT_STRING_CHARPOS (*it
) < 0);
2422 if (it
->method
== GET_FROM_BUFFER
)
2424 /* Check that character and byte positions agree. */
2425 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2430 xassert (it
->current
.dpvec_index
>= 0);
2432 xassert (it
->current
.dpvec_index
< 0);
2435 #define CHECK_IT(IT) check_it ((IT))
2439 #define CHECK_IT(IT) (void) 0
2444 #if GLYPH_DEBUG && XASSERTS
2446 /* Check that the window end of window W is what we expect it
2447 to be---the last row in the current matrix displaying text. */
2450 check_window_end (struct window
*w
)
2452 if (!MINI_WINDOW_P (w
)
2453 && !NILP (w
->window_end_valid
))
2455 struct glyph_row
*row
;
2456 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2457 XFASTINT (w
->window_end_vpos
)),
2459 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2460 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2464 #define CHECK_WINDOW_END(W) check_window_end ((W))
2468 #define CHECK_WINDOW_END(W) (void) 0
2474 /***********************************************************************
2475 Iterator initialization
2476 ***********************************************************************/
2478 /* Initialize IT for displaying current_buffer in window W, starting
2479 at character position CHARPOS. CHARPOS < 0 means that no buffer
2480 position is specified which is useful when the iterator is assigned
2481 a position later. BYTEPOS is the byte position corresponding to
2482 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2484 If ROW is not null, calls to produce_glyphs with IT as parameter
2485 will produce glyphs in that row.
2487 BASE_FACE_ID is the id of a base face to use. It must be one of
2488 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2489 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2490 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2492 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2493 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2494 will be initialized to use the corresponding mode line glyph row of
2495 the desired matrix of W. */
2498 init_iterator (struct it
*it
, struct window
*w
,
2499 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2500 struct glyph_row
*row
, enum face_id base_face_id
)
2502 int highlight_region_p
;
2503 enum face_id remapped_base_face_id
= base_face_id
;
2505 /* Some precondition checks. */
2506 xassert (w
!= NULL
&& it
!= NULL
);
2507 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2510 /* If face attributes have been changed since the last redisplay,
2511 free realized faces now because they depend on face definitions
2512 that might have changed. Don't free faces while there might be
2513 desired matrices pending which reference these faces. */
2514 if (face_change_count
&& !inhibit_free_realized_faces
)
2516 face_change_count
= 0;
2517 free_all_realized_faces (Qnil
);
2520 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2521 if (! NILP (Vface_remapping_alist
))
2522 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2524 /* Use one of the mode line rows of W's desired matrix if
2528 if (base_face_id
== MODE_LINE_FACE_ID
2529 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2530 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2531 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2532 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2536 memset (it
, 0, sizeof *it
);
2537 it
->current
.overlay_string_index
= -1;
2538 it
->current
.dpvec_index
= -1;
2539 it
->base_face_id
= remapped_base_face_id
;
2541 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2542 it
->paragraph_embedding
= L2R
;
2543 it
->bidi_it
.string
.lstring
= Qnil
;
2544 it
->bidi_it
.string
.s
= NULL
;
2545 it
->bidi_it
.string
.bufpos
= 0;
2547 /* The window in which we iterate over current_buffer: */
2548 XSETWINDOW (it
->window
, w
);
2550 it
->f
= XFRAME (w
->frame
);
2554 /* Extra space between lines (on window systems only). */
2555 if (base_face_id
== DEFAULT_FACE_ID
2556 && FRAME_WINDOW_P (it
->f
))
2558 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2559 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2560 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2561 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2562 * FRAME_LINE_HEIGHT (it
->f
));
2563 else if (it
->f
->extra_line_spacing
> 0)
2564 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2565 it
->max_extra_line_spacing
= 0;
2568 /* If realized faces have been removed, e.g. because of face
2569 attribute changes of named faces, recompute them. When running
2570 in batch mode, the face cache of the initial frame is null. If
2571 we happen to get called, make a dummy face cache. */
2572 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2573 init_frame_faces (it
->f
);
2574 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2575 recompute_basic_faces (it
->f
);
2577 /* Current value of the `slice', `space-width', and 'height' properties. */
2578 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2579 it
->space_width
= Qnil
;
2580 it
->font_height
= Qnil
;
2581 it
->override_ascent
= -1;
2583 /* Are control characters displayed as `^C'? */
2584 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2586 /* -1 means everything between a CR and the following line end
2587 is invisible. >0 means lines indented more than this value are
2589 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2590 ? clip_to_bounds (-1, XINT (BVAR (current_buffer
,
2591 selective_display
)),
2593 : (!NILP (BVAR (current_buffer
, selective_display
))
2595 it
->selective_display_ellipsis_p
2596 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2598 /* Display table to use. */
2599 it
->dp
= window_display_table (w
);
2601 /* Are multibyte characters enabled in current_buffer? */
2602 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2604 /* Non-zero if we should highlight the region. */
2606 = (!NILP (Vtransient_mark_mode
)
2607 && !NILP (BVAR (current_buffer
, mark_active
))
2608 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2610 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2611 start and end of a visible region in window IT->w. Set both to
2612 -1 to indicate no region. */
2613 if (highlight_region_p
2614 /* Maybe highlight only in selected window. */
2615 && (/* Either show region everywhere. */
2616 highlight_nonselected_windows
2617 /* Or show region in the selected window. */
2618 || w
== XWINDOW (selected_window
)
2619 /* Or show the region if we are in the mini-buffer and W is
2620 the window the mini-buffer refers to. */
2621 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2622 && WINDOWP (minibuf_selected_window
)
2623 && w
== XWINDOW (minibuf_selected_window
))))
2625 ptrdiff_t markpos
= marker_position (BVAR (current_buffer
, mark
));
2626 it
->region_beg_charpos
= min (PT
, markpos
);
2627 it
->region_end_charpos
= max (PT
, markpos
);
2630 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2632 /* Get the position at which the redisplay_end_trigger hook should
2633 be run, if it is to be run at all. */
2634 if (MARKERP (w
->redisplay_end_trigger
)
2635 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2636 it
->redisplay_end_trigger_charpos
2637 = marker_position (w
->redisplay_end_trigger
);
2638 else if (INTEGERP (w
->redisplay_end_trigger
))
2639 it
->redisplay_end_trigger_charpos
=
2640 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2642 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2644 /* Are lines in the display truncated? */
2645 if (base_face_id
!= DEFAULT_FACE_ID
2646 || XINT (it
->w
->hscroll
)
2647 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2648 && ((!NILP (Vtruncate_partial_width_windows
)
2649 && !INTEGERP (Vtruncate_partial_width_windows
))
2650 || (INTEGERP (Vtruncate_partial_width_windows
)
2651 && (WINDOW_TOTAL_COLS (it
->w
)
2652 < XINT (Vtruncate_partial_width_windows
))))))
2653 it
->line_wrap
= TRUNCATE
;
2654 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2655 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2656 ? WINDOW_WRAP
: WORD_WRAP
;
2658 it
->line_wrap
= TRUNCATE
;
2660 /* Get dimensions of truncation and continuation glyphs. These are
2661 displayed as fringe bitmaps under X, so we don't need them for such
2663 if (!FRAME_WINDOW_P (it
->f
))
2665 if (it
->line_wrap
== TRUNCATE
)
2667 /* We will need the truncation glyph. */
2668 xassert (it
->glyph_row
== NULL
);
2669 produce_special_glyphs (it
, IT_TRUNCATION
);
2670 it
->truncation_pixel_width
= it
->pixel_width
;
2674 /* We will need the continuation glyph. */
2675 xassert (it
->glyph_row
== NULL
);
2676 produce_special_glyphs (it
, IT_CONTINUATION
);
2677 it
->continuation_pixel_width
= it
->pixel_width
;
2680 /* Reset these values to zero because the produce_special_glyphs
2681 above has changed them. */
2682 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2683 it
->phys_ascent
= it
->phys_descent
= 0;
2686 /* Set this after getting the dimensions of truncation and
2687 continuation glyphs, so that we don't produce glyphs when calling
2688 produce_special_glyphs, above. */
2689 it
->glyph_row
= row
;
2690 it
->area
= TEXT_AREA
;
2692 /* Forget any previous info about this row being reversed. */
2694 it
->glyph_row
->reversed_p
= 0;
2696 /* Get the dimensions of the display area. The display area
2697 consists of the visible window area plus a horizontally scrolled
2698 part to the left of the window. All x-values are relative to the
2699 start of this total display area. */
2700 if (base_face_id
!= DEFAULT_FACE_ID
)
2702 /* Mode lines, menu bar in terminal frames. */
2703 it
->first_visible_x
= 0;
2704 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2709 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2710 it
->last_visible_x
= (it
->first_visible_x
2711 + window_box_width (w
, TEXT_AREA
));
2713 /* If we truncate lines, leave room for the truncator glyph(s) at
2714 the right margin. Otherwise, leave room for the continuation
2715 glyph(s). Truncation and continuation glyphs are not inserted
2716 for window-based redisplay. */
2717 if (!FRAME_WINDOW_P (it
->f
))
2719 if (it
->line_wrap
== TRUNCATE
)
2720 it
->last_visible_x
-= it
->truncation_pixel_width
;
2722 it
->last_visible_x
-= it
->continuation_pixel_width
;
2725 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2726 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2729 /* Leave room for a border glyph. */
2730 if (!FRAME_WINDOW_P (it
->f
)
2731 && !WINDOW_RIGHTMOST_P (it
->w
))
2732 it
->last_visible_x
-= 1;
2734 it
->last_visible_y
= window_text_bottom_y (w
);
2736 /* For mode lines and alike, arrange for the first glyph having a
2737 left box line if the face specifies a box. */
2738 if (base_face_id
!= DEFAULT_FACE_ID
)
2742 it
->face_id
= remapped_base_face_id
;
2744 /* If we have a boxed mode line, make the first character appear
2745 with a left box line. */
2746 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2747 if (face
->box
!= FACE_NO_BOX
)
2748 it
->start_of_box_run_p
= 1;
2751 /* If a buffer position was specified, set the iterator there,
2752 getting overlays and face properties from that position. */
2753 if (charpos
>= BUF_BEG (current_buffer
))
2755 it
->end_charpos
= ZV
;
2756 IT_CHARPOS (*it
) = charpos
;
2758 /* We will rely on `reseat' to set this up properly, via
2759 handle_face_prop. */
2760 it
->face_id
= it
->base_face_id
;
2762 /* Compute byte position if not specified. */
2763 if (bytepos
< charpos
)
2764 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2766 IT_BYTEPOS (*it
) = bytepos
;
2768 it
->start
= it
->current
;
2769 /* Do we need to reorder bidirectional text? Not if this is a
2770 unibyte buffer: by definition, none of the single-byte
2771 characters are strong R2L, so no reordering is needed. And
2772 bidi.c doesn't support unibyte buffers anyway. Also, don't
2773 reorder while we are loading loadup.el, since the tables of
2774 character properties needed for reordering are not yet
2778 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2781 /* If we are to reorder bidirectional text, init the bidi
2785 /* Note the paragraph direction that this buffer wants to
2787 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2789 it
->paragraph_embedding
= L2R
;
2790 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2792 it
->paragraph_embedding
= R2L
;
2794 it
->paragraph_embedding
= NEUTRAL_DIR
;
2795 bidi_unshelve_cache (NULL
, 0);
2796 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2800 /* Compute faces etc. */
2801 reseat (it
, it
->current
.pos
, 1);
2808 /* Initialize IT for the display of window W with window start POS. */
2811 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2813 struct glyph_row
*row
;
2814 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2816 row
= w
->desired_matrix
->rows
+ first_vpos
;
2817 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2818 it
->first_vpos
= first_vpos
;
2820 /* Don't reseat to previous visible line start if current start
2821 position is in a string or image. */
2822 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2824 int start_at_line_beg_p
;
2825 int first_y
= it
->current_y
;
2827 /* If window start is not at a line start, skip forward to POS to
2828 get the correct continuation lines width. */
2829 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2830 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2831 if (!start_at_line_beg_p
)
2835 reseat_at_previous_visible_line_start (it
);
2836 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2838 new_x
= it
->current_x
+ it
->pixel_width
;
2840 /* If lines are continued, this line may end in the middle
2841 of a multi-glyph character (e.g. a control character
2842 displayed as \003, or in the middle of an overlay
2843 string). In this case move_it_to above will not have
2844 taken us to the start of the continuation line but to the
2845 end of the continued line. */
2846 if (it
->current_x
> 0
2847 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2848 && (/* And glyph doesn't fit on the line. */
2849 new_x
> it
->last_visible_x
2850 /* Or it fits exactly and we're on a window
2852 || (new_x
== it
->last_visible_x
2853 && FRAME_WINDOW_P (it
->f
))))
2855 if ((it
->current
.dpvec_index
>= 0
2856 || it
->current
.overlay_string_index
>= 0)
2857 /* If we are on a newline from a display vector or
2858 overlay string, then we are already at the end of
2859 a screen line; no need to go to the next line in
2860 that case, as this line is not really continued.
2861 (If we do go to the next line, C-e will not DTRT.) */
2864 set_iterator_to_next (it
, 1);
2865 move_it_in_display_line_to (it
, -1, -1, 0);
2868 it
->continuation_lines_width
+= it
->current_x
;
2870 /* If the character at POS is displayed via a display
2871 vector, move_it_to above stops at the final glyph of
2872 IT->dpvec. To make the caller redisplay that character
2873 again (a.k.a. start at POS), we need to reset the
2874 dpvec_index to the beginning of IT->dpvec. */
2875 else if (it
->current
.dpvec_index
>= 0)
2876 it
->current
.dpvec_index
= 0;
2878 /* We're starting a new display line, not affected by the
2879 height of the continued line, so clear the appropriate
2880 fields in the iterator structure. */
2881 it
->max_ascent
= it
->max_descent
= 0;
2882 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2884 it
->current_y
= first_y
;
2886 it
->current_x
= it
->hpos
= 0;
2892 /* Return 1 if POS is a position in ellipses displayed for invisible
2893 text. W is the window we display, for text property lookup. */
2896 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2898 Lisp_Object prop
, window
;
2900 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2902 /* If POS specifies a position in a display vector, this might
2903 be for an ellipsis displayed for invisible text. We won't
2904 get the iterator set up for delivering that ellipsis unless
2905 we make sure that it gets aware of the invisible text. */
2906 if (pos
->dpvec_index
>= 0
2907 && pos
->overlay_string_index
< 0
2908 && CHARPOS (pos
->string_pos
) < 0
2910 && (XSETWINDOW (window
, w
),
2911 prop
= Fget_char_property (make_number (charpos
),
2912 Qinvisible
, window
),
2913 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2915 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2917 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2924 /* Initialize IT for stepping through current_buffer in window W,
2925 starting at position POS that includes overlay string and display
2926 vector/ control character translation position information. Value
2927 is zero if there are overlay strings with newlines at POS. */
2930 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2932 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2933 int i
, overlay_strings_with_newlines
= 0;
2935 /* If POS specifies a position in a display vector, this might
2936 be for an ellipsis displayed for invisible text. We won't
2937 get the iterator set up for delivering that ellipsis unless
2938 we make sure that it gets aware of the invisible text. */
2939 if (in_ellipses_for_invisible_text_p (pos
, w
))
2945 /* Keep in mind: the call to reseat in init_iterator skips invisible
2946 text, so we might end up at a position different from POS. This
2947 is only a problem when POS is a row start after a newline and an
2948 overlay starts there with an after-string, and the overlay has an
2949 invisible property. Since we don't skip invisible text in
2950 display_line and elsewhere immediately after consuming the
2951 newline before the row start, such a POS will not be in a string,
2952 but the call to init_iterator below will move us to the
2954 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2956 /* This only scans the current chunk -- it should scan all chunks.
2957 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2958 to 16 in 22.1 to make this a lesser problem. */
2959 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2961 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2962 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2964 while (s
< e
&& *s
!= '\n')
2969 overlay_strings_with_newlines
= 1;
2974 /* If position is within an overlay string, set up IT to the right
2976 if (pos
->overlay_string_index
>= 0)
2980 /* If the first overlay string happens to have a `display'
2981 property for an image, the iterator will be set up for that
2982 image, and we have to undo that setup first before we can
2983 correct the overlay string index. */
2984 if (it
->method
== GET_FROM_IMAGE
)
2987 /* We already have the first chunk of overlay strings in
2988 IT->overlay_strings. Load more until the one for
2989 pos->overlay_string_index is in IT->overlay_strings. */
2990 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2992 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2993 it
->current
.overlay_string_index
= 0;
2996 load_overlay_strings (it
, 0);
2997 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3001 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3002 relative_index
= (it
->current
.overlay_string_index
3003 % OVERLAY_STRING_CHUNK_SIZE
);
3004 it
->string
= it
->overlay_strings
[relative_index
];
3005 xassert (STRINGP (it
->string
));
3006 it
->current
.string_pos
= pos
->string_pos
;
3007 it
->method
= GET_FROM_STRING
;
3010 if (CHARPOS (pos
->string_pos
) >= 0)
3012 /* Recorded position is not in an overlay string, but in another
3013 string. This can only be a string from a `display' property.
3014 IT should already be filled with that string. */
3015 it
->current
.string_pos
= pos
->string_pos
;
3016 xassert (STRINGP (it
->string
));
3019 /* Restore position in display vector translations, control
3020 character translations or ellipses. */
3021 if (pos
->dpvec_index
>= 0)
3023 if (it
->dpvec
== NULL
)
3024 get_next_display_element (it
);
3025 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3026 it
->current
.dpvec_index
= pos
->dpvec_index
;
3030 return !overlay_strings_with_newlines
;
3034 /* Initialize IT for stepping through current_buffer in window W
3035 starting at ROW->start. */
3038 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3040 init_from_display_pos (it
, w
, &row
->start
);
3041 it
->start
= row
->start
;
3042 it
->continuation_lines_width
= row
->continuation_lines_width
;
3047 /* Initialize IT for stepping through current_buffer in window W
3048 starting in the line following ROW, i.e. starting at ROW->end.
3049 Value is zero if there are overlay strings with newlines at ROW's
3053 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3057 if (init_from_display_pos (it
, w
, &row
->end
))
3059 if (row
->continued_p
)
3060 it
->continuation_lines_width
3061 = row
->continuation_lines_width
+ row
->pixel_width
;
3072 /***********************************************************************
3074 ***********************************************************************/
3076 /* Called when IT reaches IT->stop_charpos. Handle text property and
3077 overlay changes. Set IT->stop_charpos to the next position where
3081 handle_stop (struct it
*it
)
3083 enum prop_handled handled
;
3084 int handle_overlay_change_p
;
3088 it
->current
.dpvec_index
= -1;
3089 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3090 it
->ignore_overlay_strings_at_pos_p
= 0;
3093 /* Use face of preceding text for ellipsis (if invisible) */
3094 if (it
->selective_display_ellipsis_p
)
3095 it
->saved_face_id
= it
->face_id
;
3099 handled
= HANDLED_NORMALLY
;
3101 /* Call text property handlers. */
3102 for (p
= it_props
; p
->handler
; ++p
)
3104 handled
= p
->handler (it
);
3106 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3108 else if (handled
== HANDLED_RETURN
)
3110 /* We still want to show before and after strings from
3111 overlays even if the actual buffer text is replaced. */
3112 if (!handle_overlay_change_p
3114 || !get_overlay_strings_1 (it
, 0, 0))
3117 setup_for_ellipsis (it
, 0);
3118 /* When handling a display spec, we might load an
3119 empty string. In that case, discard it here. We
3120 used to discard it in handle_single_display_spec,
3121 but that causes get_overlay_strings_1, above, to
3122 ignore overlay strings that we must check. */
3123 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3127 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3131 it
->ignore_overlay_strings_at_pos_p
= 1;
3132 it
->string_from_display_prop_p
= 0;
3133 it
->from_disp_prop_p
= 0;
3134 handle_overlay_change_p
= 0;
3136 handled
= HANDLED_RECOMPUTE_PROPS
;
3139 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3140 handle_overlay_change_p
= 0;
3143 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3145 /* Don't check for overlay strings below when set to deliver
3146 characters from a display vector. */
3147 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3148 handle_overlay_change_p
= 0;
3150 /* Handle overlay changes.
3151 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3152 if it finds overlays. */
3153 if (handle_overlay_change_p
)
3154 handled
= handle_overlay_change (it
);
3159 setup_for_ellipsis (it
, 0);
3163 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3165 /* Determine where to stop next. */
3166 if (handled
== HANDLED_NORMALLY
)
3167 compute_stop_pos (it
);
3171 /* Compute IT->stop_charpos from text property and overlay change
3172 information for IT's current position. */
3175 compute_stop_pos (struct it
*it
)
3177 register INTERVAL iv
, next_iv
;
3178 Lisp_Object object
, limit
, position
;
3179 ptrdiff_t charpos
, bytepos
;
3181 if (STRINGP (it
->string
))
3183 /* Strings are usually short, so don't limit the search for
3185 it
->stop_charpos
= it
->end_charpos
;
3186 object
= it
->string
;
3188 charpos
= IT_STRING_CHARPOS (*it
);
3189 bytepos
= IT_STRING_BYTEPOS (*it
);
3195 /* If end_charpos is out of range for some reason, such as a
3196 misbehaving display function, rationalize it (Bug#5984). */
3197 if (it
->end_charpos
> ZV
)
3198 it
->end_charpos
= ZV
;
3199 it
->stop_charpos
= it
->end_charpos
;
3201 /* If next overlay change is in front of the current stop pos
3202 (which is IT->end_charpos), stop there. Note: value of
3203 next_overlay_change is point-max if no overlay change
3205 charpos
= IT_CHARPOS (*it
);
3206 bytepos
= IT_BYTEPOS (*it
);
3207 pos
= next_overlay_change (charpos
);
3208 if (pos
< it
->stop_charpos
)
3209 it
->stop_charpos
= pos
;
3211 /* If showing the region, we have to stop at the region
3212 start or end because the face might change there. */
3213 if (it
->region_beg_charpos
> 0)
3215 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3216 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3217 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3218 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3221 /* Set up variables for computing the stop position from text
3222 property changes. */
3223 XSETBUFFER (object
, current_buffer
);
3224 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3227 /* Get the interval containing IT's position. Value is a null
3228 interval if there isn't such an interval. */
3229 position
= make_number (charpos
);
3230 iv
= validate_interval_range (object
, &position
, &position
, 0);
3231 if (!NULL_INTERVAL_P (iv
))
3233 Lisp_Object values_here
[LAST_PROP_IDX
];
3236 /* Get properties here. */
3237 for (p
= it_props
; p
->handler
; ++p
)
3238 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3240 /* Look for an interval following iv that has different
3242 for (next_iv
= next_interval (iv
);
3243 (!NULL_INTERVAL_P (next_iv
)
3245 || XFASTINT (limit
) > next_iv
->position
));
3246 next_iv
= next_interval (next_iv
))
3248 for (p
= it_props
; p
->handler
; ++p
)
3250 Lisp_Object new_value
;
3252 new_value
= textget (next_iv
->plist
, *p
->name
);
3253 if (!EQ (values_here
[p
->idx
], new_value
))
3261 if (!NULL_INTERVAL_P (next_iv
))
3263 if (INTEGERP (limit
)
3264 && next_iv
->position
>= XFASTINT (limit
))
3265 /* No text property change up to limit. */
3266 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3268 /* Text properties change in next_iv. */
3269 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3273 if (it
->cmp_it
.id
< 0)
3275 ptrdiff_t stoppos
= it
->end_charpos
;
3277 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3279 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3280 stoppos
, it
->string
);
3283 xassert (STRINGP (it
->string
)
3284 || (it
->stop_charpos
>= BEGV
3285 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3289 /* Return the position of the next overlay change after POS in
3290 current_buffer. Value is point-max if no overlay change
3291 follows. This is like `next-overlay-change' but doesn't use
3295 next_overlay_change (ptrdiff_t pos
)
3297 ptrdiff_t i
, noverlays
;
3299 Lisp_Object
*overlays
;
3301 /* Get all overlays at the given position. */
3302 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3304 /* If any of these overlays ends before endpos,
3305 use its ending point instead. */
3306 for (i
= 0; i
< noverlays
; ++i
)
3311 oend
= OVERLAY_END (overlays
[i
]);
3312 oendpos
= OVERLAY_POSITION (oend
);
3313 endpos
= min (endpos
, oendpos
);
3319 /* How many characters forward to search for a display property or
3320 display string. Searching too far forward makes the bidi display
3321 sluggish, especially in small windows. */
3322 #define MAX_DISP_SCAN 250
3324 /* Return the character position of a display string at or after
3325 position specified by POSITION. If no display string exists at or
3326 after POSITION, return ZV. A display string is either an overlay
3327 with `display' property whose value is a string, or a `display'
3328 text property whose value is a string. STRING is data about the
3329 string to iterate; if STRING->lstring is nil, we are iterating a
3330 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3331 on a GUI frame. DISP_PROP is set to zero if we searched
3332 MAX_DISP_SCAN characters forward without finding any display
3333 strings, non-zero otherwise. It is set to 2 if the display string
3334 uses any kind of `(space ...)' spec that will produce a stretch of
3335 white space in the text area. */
3337 compute_display_string_pos (struct text_pos
*position
,
3338 struct bidi_string_data
*string
,
3339 int frame_window_p
, int *disp_prop
)
3341 /* OBJECT = nil means current buffer. */
3342 Lisp_Object object
=
3343 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3344 Lisp_Object pos
, spec
, limpos
;
3345 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3346 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3347 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3348 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3350 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3351 struct text_pos tpos
;
3357 /* We don't support display properties whose values are strings
3358 that have display string properties. */
3359 || string
->from_disp_str
3360 /* C strings cannot have display properties. */
3361 || (string
->s
&& !STRINGP (object
)))
3367 /* If the character at CHARPOS is where the display string begins,
3369 pos
= make_number (charpos
);
3370 if (STRINGP (object
))
3371 bufpos
= string
->bufpos
;
3375 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3377 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3380 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3388 /* Look forward for the first character with a `display' property
3389 that will replace the underlying text when displayed. */
3390 limpos
= make_number (lim
);
3392 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3393 CHARPOS (tpos
) = XFASTINT (pos
);
3394 if (CHARPOS (tpos
) >= lim
)
3399 if (STRINGP (object
))
3400 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3402 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3403 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3404 if (!STRINGP (object
))
3405 bufpos
= CHARPOS (tpos
);
3406 } while (NILP (spec
)
3407 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3408 bufpos
, frame_window_p
)));
3412 return CHARPOS (tpos
);
3415 /* Return the character position of the end of the display string that
3416 started at CHARPOS. If there's no display string at CHARPOS,
3417 return -1. A display string is either an overlay with `display'
3418 property whose value is a string or a `display' text property whose
3419 value is a string. */
3421 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3423 /* OBJECT = nil means current buffer. */
3424 Lisp_Object object
=
3425 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3426 Lisp_Object pos
= make_number (charpos
);
3428 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3430 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3433 /* It could happen that the display property or overlay was removed
3434 since we found it in compute_display_string_pos above. One way
3435 this can happen is if JIT font-lock was called (through
3436 handle_fontified_prop), and jit-lock-functions remove text
3437 properties or overlays from the portion of buffer that includes
3438 CHARPOS. Muse mode is known to do that, for example. In this
3439 case, we return -1 to the caller, to signal that no display
3440 string is actually present at CHARPOS. See bidi_fetch_char for
3441 how this is handled.
3443 An alternative would be to never look for display properties past
3444 it->stop_charpos. But neither compute_display_string_pos nor
3445 bidi_fetch_char that calls it know or care where the next
3447 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3450 /* Look forward for the first character where the `display' property
3452 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3454 return XFASTINT (pos
);
3459 /***********************************************************************
3461 ***********************************************************************/
3463 /* Handle changes in the `fontified' property of the current buffer by
3464 calling hook functions from Qfontification_functions to fontify
3467 static enum prop_handled
3468 handle_fontified_prop (struct it
*it
)
3470 Lisp_Object prop
, pos
;
3471 enum prop_handled handled
= HANDLED_NORMALLY
;
3473 if (!NILP (Vmemory_full
))
3476 /* Get the value of the `fontified' property at IT's current buffer
3477 position. (The `fontified' property doesn't have a special
3478 meaning in strings.) If the value is nil, call functions from
3479 Qfontification_functions. */
3480 if (!STRINGP (it
->string
)
3482 && !NILP (Vfontification_functions
)
3483 && !NILP (Vrun_hooks
)
3484 && (pos
= make_number (IT_CHARPOS (*it
)),
3485 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3486 /* Ignore the special cased nil value always present at EOB since
3487 no amount of fontifying will be able to change it. */
3488 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3490 ptrdiff_t count
= SPECPDL_INDEX ();
3492 struct buffer
*obuf
= current_buffer
;
3493 int begv
= BEGV
, zv
= ZV
;
3494 int old_clip_changed
= current_buffer
->clip_changed
;
3496 val
= Vfontification_functions
;
3497 specbind (Qfontification_functions
, Qnil
);
3499 xassert (it
->end_charpos
== ZV
);
3501 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3502 safe_call1 (val
, pos
);
3505 Lisp_Object fns
, fn
;
3506 struct gcpro gcpro1
, gcpro2
;
3511 for (; CONSP (val
); val
= XCDR (val
))
3517 /* A value of t indicates this hook has a local
3518 binding; it means to run the global binding too.
3519 In a global value, t should not occur. If it
3520 does, we must ignore it to avoid an endless
3522 for (fns
= Fdefault_value (Qfontification_functions
);
3528 safe_call1 (fn
, pos
);
3532 safe_call1 (fn
, pos
);
3538 unbind_to (count
, Qnil
);
3540 /* Fontification functions routinely call `save-restriction'.
3541 Normally, this tags clip_changed, which can confuse redisplay
3542 (see discussion in Bug#6671). Since we don't perform any
3543 special handling of fontification changes in the case where
3544 `save-restriction' isn't called, there's no point doing so in
3545 this case either. So, if the buffer's restrictions are
3546 actually left unchanged, reset clip_changed. */
3547 if (obuf
== current_buffer
)
3549 if (begv
== BEGV
&& zv
== ZV
)
3550 current_buffer
->clip_changed
= old_clip_changed
;
3552 /* There isn't much we can reasonably do to protect against
3553 misbehaving fontification, but here's a fig leaf. */
3554 else if (!NILP (BVAR (obuf
, name
)))
3555 set_buffer_internal_1 (obuf
);
3557 /* The fontification code may have added/removed text.
3558 It could do even a lot worse, but let's at least protect against
3559 the most obvious case where only the text past `pos' gets changed',
3560 as is/was done in grep.el where some escapes sequences are turned
3561 into face properties (bug#7876). */
3562 it
->end_charpos
= ZV
;
3564 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3565 something. This avoids an endless loop if they failed to
3566 fontify the text for which reason ever. */
3567 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3568 handled
= HANDLED_RECOMPUTE_PROPS
;
3576 /***********************************************************************
3578 ***********************************************************************/
3580 /* Set up iterator IT from face properties at its current position.
3581 Called from handle_stop. */
3583 static enum prop_handled
3584 handle_face_prop (struct it
*it
)
3587 ptrdiff_t next_stop
;
3589 if (!STRINGP (it
->string
))
3592 = face_at_buffer_position (it
->w
,
3594 it
->region_beg_charpos
,
3595 it
->region_end_charpos
,
3598 + TEXT_PROP_DISTANCE_LIMIT
),
3599 0, it
->base_face_id
);
3601 /* Is this a start of a run of characters with box face?
3602 Caveat: this can be called for a freshly initialized
3603 iterator; face_id is -1 in this case. We know that the new
3604 face will not change until limit, i.e. if the new face has a
3605 box, all characters up to limit will have one. But, as
3606 usual, we don't know whether limit is really the end. */
3607 if (new_face_id
!= it
->face_id
)
3609 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3611 /* If new face has a box but old face has not, this is
3612 the start of a run of characters with box, i.e. it has
3613 a shadow on the left side. The value of face_id of the
3614 iterator will be -1 if this is the initial call that gets
3615 the face. In this case, we have to look in front of IT's
3616 position and see whether there is a face != new_face_id. */
3617 it
->start_of_box_run_p
3618 = (new_face
->box
!= FACE_NO_BOX
3619 && (it
->face_id
>= 0
3620 || IT_CHARPOS (*it
) == BEG
3621 || new_face_id
!= face_before_it_pos (it
)));
3622 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3630 Lisp_Object from_overlay
3631 = (it
->current
.overlay_string_index
>= 0
3632 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3635 /* See if we got to this string directly or indirectly from
3636 an overlay property. That includes the before-string or
3637 after-string of an overlay, strings in display properties
3638 provided by an overlay, their text properties, etc.
3640 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3641 if (! NILP (from_overlay
))
3642 for (i
= it
->sp
- 1; i
>= 0; i
--)
3644 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3646 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3647 else if (! NILP (it
->stack
[i
].from_overlay
))
3648 from_overlay
= it
->stack
[i
].from_overlay
;
3650 if (!NILP (from_overlay
))
3654 if (! NILP (from_overlay
))
3656 bufpos
= IT_CHARPOS (*it
);
3657 /* For a string from an overlay, the base face depends
3658 only on text properties and ignores overlays. */
3660 = face_for_overlay_string (it
->w
,
3662 it
->region_beg_charpos
,
3663 it
->region_end_charpos
,
3666 + TEXT_PROP_DISTANCE_LIMIT
),
3674 /* For strings from a `display' property, use the face at
3675 IT's current buffer position as the base face to merge
3676 with, so that overlay strings appear in the same face as
3677 surrounding text, unless they specify their own
3679 base_face_id
= it
->string_from_prefix_prop_p
3681 : underlying_face_id (it
);
3684 new_face_id
= face_at_string_position (it
->w
,
3686 IT_STRING_CHARPOS (*it
),
3688 it
->region_beg_charpos
,
3689 it
->region_end_charpos
,
3693 /* Is this a start of a run of characters with box? Caveat:
3694 this can be called for a freshly allocated iterator; face_id
3695 is -1 is this case. We know that the new face will not
3696 change until the next check pos, i.e. if the new face has a
3697 box, all characters up to that position will have a
3698 box. But, as usual, we don't know whether that position
3699 is really the end. */
3700 if (new_face_id
!= it
->face_id
)
3702 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3703 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3705 /* If new face has a box but old face hasn't, this is the
3706 start of a run of characters with box, i.e. it has a
3707 shadow on the left side. */
3708 it
->start_of_box_run_p
3709 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3710 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3714 it
->face_id
= new_face_id
;
3715 return HANDLED_NORMALLY
;
3719 /* Return the ID of the face ``underlying'' IT's current position,
3720 which is in a string. If the iterator is associated with a
3721 buffer, return the face at IT's current buffer position.
3722 Otherwise, use the iterator's base_face_id. */
3725 underlying_face_id (struct it
*it
)
3727 int face_id
= it
->base_face_id
, i
;
3729 xassert (STRINGP (it
->string
));
3731 for (i
= it
->sp
- 1; i
>= 0; --i
)
3732 if (NILP (it
->stack
[i
].string
))
3733 face_id
= it
->stack
[i
].face_id
;
3739 /* Compute the face one character before or after the current position
3740 of IT, in the visual order. BEFORE_P non-zero means get the face
3741 in front (to the left in L2R paragraphs, to the right in R2L
3742 paragraphs) of IT's screen position. Value is the ID of the face. */
3745 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3748 ptrdiff_t next_check_charpos
;
3750 void *it_copy_data
= NULL
;
3752 xassert (it
->s
== NULL
);
3754 if (STRINGP (it
->string
))
3756 ptrdiff_t bufpos
, charpos
;
3759 /* No face change past the end of the string (for the case
3760 we are padding with spaces). No face change before the
3762 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3763 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3768 /* Set charpos to the position before or after IT's current
3769 position, in the logical order, which in the non-bidi
3770 case is the same as the visual order. */
3772 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3773 else if (it
->what
== IT_COMPOSITION
)
3774 /* For composition, we must check the character after the
3776 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3778 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3784 /* With bidi iteration, the character before the current
3785 in the visual order cannot be found by simple
3786 iteration, because "reverse" reordering is not
3787 supported. Instead, we need to use the move_it_*
3788 family of functions. */
3789 /* Ignore face changes before the first visible
3790 character on this display line. */
3791 if (it
->current_x
<= it
->first_visible_x
)
3793 SAVE_IT (it_copy
, *it
, it_copy_data
);
3794 /* Implementation note: Since move_it_in_display_line
3795 works in the iterator geometry, and thinks the first
3796 character is always the leftmost, even in R2L lines,
3797 we don't need to distinguish between the R2L and L2R
3799 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3800 it_copy
.current_x
- 1, MOVE_TO_X
);
3801 charpos
= IT_STRING_CHARPOS (it_copy
);
3802 RESTORE_IT (it
, it
, it_copy_data
);
3806 /* Set charpos to the string position of the character
3807 that comes after IT's current position in the visual
3809 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3813 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3815 charpos
= it_copy
.bidi_it
.charpos
;
3818 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3820 if (it
->current
.overlay_string_index
>= 0)
3821 bufpos
= IT_CHARPOS (*it
);
3825 base_face_id
= underlying_face_id (it
);
3827 /* Get the face for ASCII, or unibyte. */
3828 face_id
= face_at_string_position (it
->w
,
3832 it
->region_beg_charpos
,
3833 it
->region_end_charpos
,
3834 &next_check_charpos
,
3837 /* Correct the face for charsets different from ASCII. Do it
3838 for the multibyte case only. The face returned above is
3839 suitable for unibyte text if IT->string is unibyte. */
3840 if (STRING_MULTIBYTE (it
->string
))
3842 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3843 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3845 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3847 c
= string_char_and_length (p
, &len
);
3848 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3853 struct text_pos pos
;
3855 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3856 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3859 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3860 pos
= it
->current
.pos
;
3865 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3868 if (it
->what
== IT_COMPOSITION
)
3870 /* For composition, we must check the position after
3872 pos
.charpos
+= it
->cmp_it
.nchars
;
3873 pos
.bytepos
+= it
->len
;
3876 INC_TEXT_POS (pos
, it
->multibyte_p
);
3883 /* With bidi iteration, the character before the current
3884 in the visual order cannot be found by simple
3885 iteration, because "reverse" reordering is not
3886 supported. Instead, we need to use the move_it_*
3887 family of functions. */
3888 /* Ignore face changes before the first visible
3889 character on this display line. */
3890 if (it
->current_x
<= it
->first_visible_x
)
3892 SAVE_IT (it_copy
, *it
, it_copy_data
);
3893 /* Implementation note: Since move_it_in_display_line
3894 works in the iterator geometry, and thinks the first
3895 character is always the leftmost, even in R2L lines,
3896 we don't need to distinguish between the R2L and L2R
3898 move_it_in_display_line (&it_copy
, ZV
,
3899 it_copy
.current_x
- 1, MOVE_TO_X
);
3900 pos
= it_copy
.current
.pos
;
3901 RESTORE_IT (it
, it
, it_copy_data
);
3905 /* Set charpos to the buffer position of the character
3906 that comes after IT's current position in the visual
3908 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3912 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3915 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3918 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3920 /* Determine face for CHARSET_ASCII, or unibyte. */
3921 face_id
= face_at_buffer_position (it
->w
,
3923 it
->region_beg_charpos
,
3924 it
->region_end_charpos
,
3925 &next_check_charpos
,
3928 /* Correct the face for charsets different from ASCII. Do it
3929 for the multibyte case only. The face returned above is
3930 suitable for unibyte text if current_buffer is unibyte. */
3931 if (it
->multibyte_p
)
3933 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3934 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3935 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3944 /***********************************************************************
3946 ***********************************************************************/
3948 /* Set up iterator IT from invisible properties at its current
3949 position. Called from handle_stop. */
3951 static enum prop_handled
3952 handle_invisible_prop (struct it
*it
)
3954 enum prop_handled handled
= HANDLED_NORMALLY
;
3956 if (STRINGP (it
->string
))
3958 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3960 /* Get the value of the invisible text property at the
3961 current position. Value will be nil if there is no such
3963 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3964 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3967 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3971 handled
= HANDLED_RECOMPUTE_PROPS
;
3973 /* Get the position at which the next change of the
3974 invisible text property can be found in IT->string.
3975 Value will be nil if the property value is the same for
3976 all the rest of IT->string. */
3977 XSETINT (limit
, SCHARS (it
->string
));
3978 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3981 /* Text at current position is invisible. The next
3982 change in the property is at position end_charpos.
3983 Move IT's current position to that position. */
3984 if (INTEGERP (end_charpos
)
3985 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3987 struct text_pos old
;
3990 old
= it
->current
.string_pos
;
3991 oldpos
= CHARPOS (old
);
3994 if (it
->bidi_it
.first_elt
3995 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
3996 bidi_paragraph_init (it
->paragraph_embedding
,
3998 /* Bidi-iterate out of the invisible text. */
4001 bidi_move_to_visually_next (&it
->bidi_it
);
4003 while (oldpos
<= it
->bidi_it
.charpos
4004 && it
->bidi_it
.charpos
< endpos
);
4006 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4007 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4008 if (IT_CHARPOS (*it
) >= endpos
)
4009 it
->prev_stop
= endpos
;
4013 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4014 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4019 /* The rest of the string is invisible. If this is an
4020 overlay string, proceed with the next overlay string
4021 or whatever comes and return a character from there. */
4022 if (it
->current
.overlay_string_index
>= 0)
4024 next_overlay_string (it
);
4025 /* Don't check for overlay strings when we just
4026 finished processing them. */
4027 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4031 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4032 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4040 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4041 Lisp_Object pos
, prop
, overlay
;
4043 /* First of all, is there invisible text at this position? */
4044 tem
= start_charpos
= IT_CHARPOS (*it
);
4045 pos
= make_number (tem
);
4046 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4048 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4050 /* If we are on invisible text, skip over it. */
4051 if (invis_p
&& start_charpos
< it
->end_charpos
)
4053 /* Record whether we have to display an ellipsis for the
4055 int display_ellipsis_p
= invis_p
== 2;
4057 handled
= HANDLED_RECOMPUTE_PROPS
;
4059 /* Loop skipping over invisible text. The loop is left at
4060 ZV or with IT on the first char being visible again. */
4063 /* Try to skip some invisible text. Return value is the
4064 position reached which can be equal to where we start
4065 if there is nothing invisible there. This skips both
4066 over invisible text properties and overlays with
4067 invisible property. */
4068 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4070 /* If we skipped nothing at all we weren't at invisible
4071 text in the first place. If everything to the end of
4072 the buffer was skipped, end the loop. */
4073 if (newpos
== tem
|| newpos
>= ZV
)
4077 /* We skipped some characters but not necessarily
4078 all there are. Check if we ended up on visible
4079 text. Fget_char_property returns the property of
4080 the char before the given position, i.e. if we
4081 get invis_p = 0, this means that the char at
4082 newpos is visible. */
4083 pos
= make_number (newpos
);
4084 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4085 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4088 /* If we ended up on invisible text, proceed to
4089 skip starting with next_stop. */
4093 /* If there are adjacent invisible texts, don't lose the
4094 second one's ellipsis. */
4096 display_ellipsis_p
= 1;
4100 /* The position newpos is now either ZV or on visible text. */
4103 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4105 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4107 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4109 /* If the invisible text ends on a newline or on a
4110 character after a newline, we can avoid the costly,
4111 character by character, bidi iteration to NEWPOS, and
4112 instead simply reseat the iterator there. That's
4113 because all bidi reordering information is tossed at
4114 the newline. This is a big win for modes that hide
4115 complete lines, like Outline, Org, etc. */
4116 if (on_newline
|| after_newline
)
4118 struct text_pos tpos
;
4119 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4121 SET_TEXT_POS (tpos
, newpos
, bpos
);
4122 reseat_1 (it
, tpos
, 0);
4123 /* If we reseat on a newline/ZV, we need to prep the
4124 bidi iterator for advancing to the next character
4125 after the newline/EOB, keeping the current paragraph
4126 direction (so that PRODUCE_GLYPHS does TRT wrt
4127 prepending/appending glyphs to a glyph row). */
4130 it
->bidi_it
.first_elt
= 0;
4131 it
->bidi_it
.paragraph_dir
= pdir
;
4132 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4133 it
->bidi_it
.nchars
= 1;
4134 it
->bidi_it
.ch_len
= 1;
4137 else /* Must use the slow method. */
4139 /* With bidi iteration, the region of invisible text
4140 could start and/or end in the middle of a
4141 non-base embedding level. Therefore, we need to
4142 skip invisible text using the bidi iterator,
4143 starting at IT's current position, until we find
4144 ourselves outside of the invisible text.
4145 Skipping invisible text _after_ bidi iteration
4146 avoids affecting the visual order of the
4147 displayed text when invisible properties are
4148 added or removed. */
4149 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4151 /* If we were `reseat'ed to a new paragraph,
4152 determine the paragraph base direction. We
4153 need to do it now because
4154 next_element_from_buffer may not have a
4155 chance to do it, if we are going to skip any
4156 text at the beginning, which resets the
4158 bidi_paragraph_init (it
->paragraph_embedding
,
4163 bidi_move_to_visually_next (&it
->bidi_it
);
4165 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4166 && it
->bidi_it
.charpos
< newpos
);
4167 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4168 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4169 /* If we overstepped NEWPOS, record its position in
4170 the iterator, so that we skip invisible text if
4171 later the bidi iteration lands us in the
4172 invisible region again. */
4173 if (IT_CHARPOS (*it
) >= newpos
)
4174 it
->prev_stop
= newpos
;
4179 IT_CHARPOS (*it
) = newpos
;
4180 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4183 /* If there are before-strings at the start of invisible
4184 text, and the text is invisible because of a text
4185 property, arrange to show before-strings because 20.x did
4186 it that way. (If the text is invisible because of an
4187 overlay property instead of a text property, this is
4188 already handled in the overlay code.) */
4190 && get_overlay_strings (it
, it
->stop_charpos
))
4192 handled
= HANDLED_RECOMPUTE_PROPS
;
4193 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4195 else if (display_ellipsis_p
)
4197 /* Make sure that the glyphs of the ellipsis will get
4198 correct `charpos' values. If we would not update
4199 it->position here, the glyphs would belong to the
4200 last visible character _before_ the invisible
4201 text, which confuses `set_cursor_from_row'.
4203 We use the last invisible position instead of the
4204 first because this way the cursor is always drawn on
4205 the first "." of the ellipsis, whenever PT is inside
4206 the invisible text. Otherwise the cursor would be
4207 placed _after_ the ellipsis when the point is after the
4208 first invisible character. */
4209 if (!STRINGP (it
->object
))
4211 it
->position
.charpos
= newpos
- 1;
4212 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4215 /* Let the ellipsis display before
4216 considering any properties of the following char.
4217 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4218 handled
= HANDLED_RETURN
;
4227 /* Make iterator IT return `...' next.
4228 Replaces LEN characters from buffer. */
4231 setup_for_ellipsis (struct it
*it
, int len
)
4233 /* Use the display table definition for `...'. Invalid glyphs
4234 will be handled by the method returning elements from dpvec. */
4235 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4237 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4238 it
->dpvec
= v
->contents
;
4239 it
->dpend
= v
->contents
+ v
->header
.size
;
4243 /* Default `...'. */
4244 it
->dpvec
= default_invis_vector
;
4245 it
->dpend
= default_invis_vector
+ 3;
4248 it
->dpvec_char_len
= len
;
4249 it
->current
.dpvec_index
= 0;
4250 it
->dpvec_face_id
= -1;
4252 /* Remember the current face id in case glyphs specify faces.
4253 IT's face is restored in set_iterator_to_next.
4254 saved_face_id was set to preceding char's face in handle_stop. */
4255 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4256 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4258 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4264 /***********************************************************************
4266 ***********************************************************************/
4268 /* Set up iterator IT from `display' property at its current position.
4269 Called from handle_stop.
4270 We return HANDLED_RETURN if some part of the display property
4271 overrides the display of the buffer text itself.
4272 Otherwise we return HANDLED_NORMALLY. */
4274 static enum prop_handled
4275 handle_display_prop (struct it
*it
)
4277 Lisp_Object propval
, object
, overlay
;
4278 struct text_pos
*position
;
4280 /* Nonzero if some property replaces the display of the text itself. */
4281 int display_replaced_p
= 0;
4283 if (STRINGP (it
->string
))
4285 object
= it
->string
;
4286 position
= &it
->current
.string_pos
;
4287 bufpos
= CHARPOS (it
->current
.pos
);
4291 XSETWINDOW (object
, it
->w
);
4292 position
= &it
->current
.pos
;
4293 bufpos
= CHARPOS (*position
);
4296 /* Reset those iterator values set from display property values. */
4297 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4298 it
->space_width
= Qnil
;
4299 it
->font_height
= Qnil
;
4302 /* We don't support recursive `display' properties, i.e. string
4303 values that have a string `display' property, that have a string
4304 `display' property etc. */
4305 if (!it
->string_from_display_prop_p
)
4306 it
->area
= TEXT_AREA
;
4308 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4309 Qdisplay
, object
, &overlay
);
4311 return HANDLED_NORMALLY
;
4312 /* Now OVERLAY is the overlay that gave us this property, or nil
4313 if it was a text property. */
4315 if (!STRINGP (it
->string
))
4316 object
= it
->w
->buffer
;
4318 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4320 FRAME_WINDOW_P (it
->f
));
4322 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4325 /* Subroutine of handle_display_prop. Returns non-zero if the display
4326 specification in SPEC is a replacing specification, i.e. it would
4327 replace the text covered by `display' property with something else,
4328 such as an image or a display string. If SPEC includes any kind or
4329 `(space ...) specification, the value is 2; this is used by
4330 compute_display_string_pos, which see.
4332 See handle_single_display_spec for documentation of arguments.
4333 frame_window_p is non-zero if the window being redisplayed is on a
4334 GUI frame; this argument is used only if IT is NULL, see below.
4336 IT can be NULL, if this is called by the bidi reordering code
4337 through compute_display_string_pos, which see. In that case, this
4338 function only examines SPEC, but does not otherwise "handle" it, in
4339 the sense that it doesn't set up members of IT from the display
4342 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4343 Lisp_Object overlay
, struct text_pos
*position
,
4344 ptrdiff_t bufpos
, int frame_window_p
)
4346 int replacing_p
= 0;
4350 /* Simple specifications. */
4351 && !EQ (XCAR (spec
), Qimage
)
4352 && !EQ (XCAR (spec
), Qspace
)
4353 && !EQ (XCAR (spec
), Qwhen
)
4354 && !EQ (XCAR (spec
), Qslice
)
4355 && !EQ (XCAR (spec
), Qspace_width
)
4356 && !EQ (XCAR (spec
), Qheight
)
4357 && !EQ (XCAR (spec
), Qraise
)
4358 /* Marginal area specifications. */
4359 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4360 && !EQ (XCAR (spec
), Qleft_fringe
)
4361 && !EQ (XCAR (spec
), Qright_fringe
)
4362 && !NILP (XCAR (spec
)))
4364 for (; CONSP (spec
); spec
= XCDR (spec
))
4366 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4367 overlay
, position
, bufpos
,
4368 replacing_p
, frame_window_p
)))
4371 /* If some text in a string is replaced, `position' no
4372 longer points to the position of `object'. */
4373 if (!it
|| STRINGP (object
))
4378 else if (VECTORP (spec
))
4381 for (i
= 0; i
< ASIZE (spec
); ++i
)
4382 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4383 overlay
, position
, bufpos
,
4384 replacing_p
, frame_window_p
)))
4387 /* If some text in a string is replaced, `position' no
4388 longer points to the position of `object'. */
4389 if (!it
|| STRINGP (object
))
4395 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4396 position
, bufpos
, 0,
4404 /* Value is the position of the end of the `display' property starting
4405 at START_POS in OBJECT. */
4407 static struct text_pos
4408 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4411 struct text_pos end_pos
;
4413 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4414 Qdisplay
, object
, Qnil
);
4415 CHARPOS (end_pos
) = XFASTINT (end
);
4416 if (STRINGP (object
))
4417 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4419 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4425 /* Set up IT from a single `display' property specification SPEC. OBJECT
4426 is the object in which the `display' property was found. *POSITION
4427 is the position in OBJECT at which the `display' property was found.
4428 BUFPOS is the buffer position of OBJECT (different from POSITION if
4429 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4430 previously saw a display specification which already replaced text
4431 display with something else, for example an image; we ignore such
4432 properties after the first one has been processed.
4434 OVERLAY is the overlay this `display' property came from,
4435 or nil if it was a text property.
4437 If SPEC is a `space' or `image' specification, and in some other
4438 cases too, set *POSITION to the position where the `display'
4441 If IT is NULL, only examine the property specification in SPEC, but
4442 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4443 is intended to be displayed in a window on a GUI frame.
4445 Value is non-zero if something was found which replaces the display
4446 of buffer or string text. */
4449 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4450 Lisp_Object overlay
, struct text_pos
*position
,
4451 ptrdiff_t bufpos
, int display_replaced_p
,
4455 Lisp_Object location
, value
;
4456 struct text_pos start_pos
= *position
;
4459 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4460 If the result is non-nil, use VALUE instead of SPEC. */
4462 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4471 if (!NILP (form
) && !EQ (form
, Qt
))
4473 ptrdiff_t count
= SPECPDL_INDEX ();
4474 struct gcpro gcpro1
;
4476 /* Bind `object' to the object having the `display' property, a
4477 buffer or string. Bind `position' to the position in the
4478 object where the property was found, and `buffer-position'
4479 to the current position in the buffer. */
4482 XSETBUFFER (object
, current_buffer
);
4483 specbind (Qobject
, object
);
4484 specbind (Qposition
, make_number (CHARPOS (*position
)));
4485 specbind (Qbuffer_position
, make_number (bufpos
));
4487 form
= safe_eval (form
);
4489 unbind_to (count
, Qnil
);
4495 /* Handle `(height HEIGHT)' specifications. */
4497 && EQ (XCAR (spec
), Qheight
)
4498 && CONSP (XCDR (spec
)))
4502 if (!FRAME_WINDOW_P (it
->f
))
4505 it
->font_height
= XCAR (XCDR (spec
));
4506 if (!NILP (it
->font_height
))
4508 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4509 int new_height
= -1;
4511 if (CONSP (it
->font_height
)
4512 && (EQ (XCAR (it
->font_height
), Qplus
)
4513 || EQ (XCAR (it
->font_height
), Qminus
))
4514 && CONSP (XCDR (it
->font_height
))
4515 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4517 /* `(+ N)' or `(- N)' where N is an integer. */
4518 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4519 if (EQ (XCAR (it
->font_height
), Qplus
))
4521 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4523 else if (FUNCTIONP (it
->font_height
))
4525 /* Call function with current height as argument.
4526 Value is the new height. */
4528 height
= safe_call1 (it
->font_height
,
4529 face
->lface
[LFACE_HEIGHT_INDEX
]);
4530 if (NUMBERP (height
))
4531 new_height
= XFLOATINT (height
);
4533 else if (NUMBERP (it
->font_height
))
4535 /* Value is a multiple of the canonical char height. */
4538 f
= FACE_FROM_ID (it
->f
,
4539 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4540 new_height
= (XFLOATINT (it
->font_height
)
4541 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4545 /* Evaluate IT->font_height with `height' bound to the
4546 current specified height to get the new height. */
4547 ptrdiff_t count
= SPECPDL_INDEX ();
4549 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4550 value
= safe_eval (it
->font_height
);
4551 unbind_to (count
, Qnil
);
4553 if (NUMBERP (value
))
4554 new_height
= XFLOATINT (value
);
4558 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4565 /* Handle `(space-width WIDTH)'. */
4567 && EQ (XCAR (spec
), Qspace_width
)
4568 && CONSP (XCDR (spec
)))
4572 if (!FRAME_WINDOW_P (it
->f
))
4575 value
= XCAR (XCDR (spec
));
4576 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4577 it
->space_width
= value
;
4583 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4585 && EQ (XCAR (spec
), Qslice
))
4591 if (!FRAME_WINDOW_P (it
->f
))
4594 if (tem
= XCDR (spec
), CONSP (tem
))
4596 it
->slice
.x
= XCAR (tem
);
4597 if (tem
= XCDR (tem
), CONSP (tem
))
4599 it
->slice
.y
= XCAR (tem
);
4600 if (tem
= XCDR (tem
), CONSP (tem
))
4602 it
->slice
.width
= XCAR (tem
);
4603 if (tem
= XCDR (tem
), CONSP (tem
))
4604 it
->slice
.height
= XCAR (tem
);
4613 /* Handle `(raise FACTOR)'. */
4615 && EQ (XCAR (spec
), Qraise
)
4616 && CONSP (XCDR (spec
)))
4620 if (!FRAME_WINDOW_P (it
->f
))
4623 #ifdef HAVE_WINDOW_SYSTEM
4624 value
= XCAR (XCDR (spec
));
4625 if (NUMBERP (value
))
4627 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4628 it
->voffset
= - (XFLOATINT (value
)
4629 * (FONT_HEIGHT (face
->font
)));
4631 #endif /* HAVE_WINDOW_SYSTEM */
4637 /* Don't handle the other kinds of display specifications
4638 inside a string that we got from a `display' property. */
4639 if (it
&& it
->string_from_display_prop_p
)
4642 /* Characters having this form of property are not displayed, so
4643 we have to find the end of the property. */
4646 start_pos
= *position
;
4647 *position
= display_prop_end (it
, object
, start_pos
);
4651 /* Stop the scan at that end position--we assume that all
4652 text properties change there. */
4654 it
->stop_charpos
= position
->charpos
;
4656 /* Handle `(left-fringe BITMAP [FACE])'
4657 and `(right-fringe BITMAP [FACE])'. */
4659 && (EQ (XCAR (spec
), Qleft_fringe
)
4660 || EQ (XCAR (spec
), Qright_fringe
))
4661 && CONSP (XCDR (spec
)))
4667 if (!FRAME_WINDOW_P (it
->f
))
4668 /* If we return here, POSITION has been advanced
4669 across the text with this property. */
4672 else if (!frame_window_p
)
4675 #ifdef HAVE_WINDOW_SYSTEM
4676 value
= XCAR (XCDR (spec
));
4677 if (!SYMBOLP (value
)
4678 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4679 /* If we return here, POSITION has been advanced
4680 across the text with this property. */
4685 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4687 if (CONSP (XCDR (XCDR (spec
))))
4689 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4690 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4696 /* Save current settings of IT so that we can restore them
4697 when we are finished with the glyph property value. */
4698 push_it (it
, position
);
4700 it
->area
= TEXT_AREA
;
4701 it
->what
= IT_IMAGE
;
4702 it
->image_id
= -1; /* no image */
4703 it
->position
= start_pos
;
4704 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4705 it
->method
= GET_FROM_IMAGE
;
4706 it
->from_overlay
= Qnil
;
4707 it
->face_id
= face_id
;
4708 it
->from_disp_prop_p
= 1;
4710 /* Say that we haven't consumed the characters with
4711 `display' property yet. The call to pop_it in
4712 set_iterator_to_next will clean this up. */
4713 *position
= start_pos
;
4715 if (EQ (XCAR (spec
), Qleft_fringe
))
4717 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4718 it
->left_user_fringe_face_id
= face_id
;
4722 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4723 it
->right_user_fringe_face_id
= face_id
;
4726 #endif /* HAVE_WINDOW_SYSTEM */
4730 /* Prepare to handle `((margin left-margin) ...)',
4731 `((margin right-margin) ...)' and `((margin nil) ...)'
4732 prefixes for display specifications. */
4733 location
= Qunbound
;
4734 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4738 value
= XCDR (spec
);
4740 value
= XCAR (value
);
4743 if (EQ (XCAR (tem
), Qmargin
)
4744 && (tem
= XCDR (tem
),
4745 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4747 || EQ (tem
, Qleft_margin
)
4748 || EQ (tem
, Qright_margin
))))
4752 if (EQ (location
, Qunbound
))
4758 /* After this point, VALUE is the property after any
4759 margin prefix has been stripped. It must be a string,
4760 an image specification, or `(space ...)'.
4762 LOCATION specifies where to display: `left-margin',
4763 `right-margin' or nil. */
4765 valid_p
= (STRINGP (value
)
4766 #ifdef HAVE_WINDOW_SYSTEM
4767 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4768 && valid_image_p (value
))
4769 #endif /* not HAVE_WINDOW_SYSTEM */
4770 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4772 if (valid_p
&& !display_replaced_p
)
4778 /* Callers need to know whether the display spec is any kind
4779 of `(space ...)' spec that is about to affect text-area
4781 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4786 /* Save current settings of IT so that we can restore them
4787 when we are finished with the glyph property value. */
4788 push_it (it
, position
);
4789 it
->from_overlay
= overlay
;
4790 it
->from_disp_prop_p
= 1;
4792 if (NILP (location
))
4793 it
->area
= TEXT_AREA
;
4794 else if (EQ (location
, Qleft_margin
))
4795 it
->area
= LEFT_MARGIN_AREA
;
4797 it
->area
= RIGHT_MARGIN_AREA
;
4799 if (STRINGP (value
))
4802 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4803 it
->current
.overlay_string_index
= -1;
4804 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4805 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4806 it
->method
= GET_FROM_STRING
;
4807 it
->stop_charpos
= 0;
4809 it
->base_level_stop
= 0;
4810 it
->string_from_display_prop_p
= 1;
4811 /* Say that we haven't consumed the characters with
4812 `display' property yet. The call to pop_it in
4813 set_iterator_to_next will clean this up. */
4814 if (BUFFERP (object
))
4815 *position
= start_pos
;
4817 /* Force paragraph direction to be that of the parent
4818 object. If the parent object's paragraph direction is
4819 not yet determined, default to L2R. */
4820 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4821 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4823 it
->paragraph_embedding
= L2R
;
4825 /* Set up the bidi iterator for this display string. */
4828 it
->bidi_it
.string
.lstring
= it
->string
;
4829 it
->bidi_it
.string
.s
= NULL
;
4830 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4831 it
->bidi_it
.string
.bufpos
= bufpos
;
4832 it
->bidi_it
.string
.from_disp_str
= 1;
4833 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4834 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4837 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4839 it
->method
= GET_FROM_STRETCH
;
4841 *position
= it
->position
= start_pos
;
4842 retval
= 1 + (it
->area
== TEXT_AREA
);
4844 #ifdef HAVE_WINDOW_SYSTEM
4847 it
->what
= IT_IMAGE
;
4848 it
->image_id
= lookup_image (it
->f
, value
);
4849 it
->position
= start_pos
;
4850 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4851 it
->method
= GET_FROM_IMAGE
;
4853 /* Say that we haven't consumed the characters with
4854 `display' property yet. The call to pop_it in
4855 set_iterator_to_next will clean this up. */
4856 *position
= start_pos
;
4858 #endif /* HAVE_WINDOW_SYSTEM */
4863 /* Invalid property or property not supported. Restore
4864 POSITION to what it was before. */
4865 *position
= start_pos
;
4869 /* Check if PROP is a display property value whose text should be
4870 treated as intangible. OVERLAY is the overlay from which PROP
4871 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4872 specify the buffer position covered by PROP. */
4875 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4876 ptrdiff_t charpos
, ptrdiff_t bytepos
)
4878 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4879 struct text_pos position
;
4881 SET_TEXT_POS (position
, charpos
, bytepos
);
4882 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4883 &position
, charpos
, frame_window_p
);
4887 /* Return 1 if PROP is a display sub-property value containing STRING.
4889 Implementation note: this and the following function are really
4890 special cases of handle_display_spec and
4891 handle_single_display_spec, and should ideally use the same code.
4892 Until they do, these two pairs must be consistent and must be
4893 modified in sync. */
4896 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4898 if (EQ (string
, prop
))
4901 /* Skip over `when FORM'. */
4902 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4907 /* Actually, the condition following `when' should be eval'ed,
4908 like handle_single_display_spec does, and we should return
4909 zero if it evaluates to nil. However, this function is
4910 called only when the buffer was already displayed and some
4911 glyph in the glyph matrix was found to come from a display
4912 string. Therefore, the condition was already evaluated, and
4913 the result was non-nil, otherwise the display string wouldn't
4914 have been displayed and we would have never been called for
4915 this property. Thus, we can skip the evaluation and assume
4916 its result is non-nil. */
4921 /* Skip over `margin LOCATION'. */
4922 if (EQ (XCAR (prop
), Qmargin
))
4933 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4937 /* Return 1 if STRING appears in the `display' property PROP. */
4940 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4943 && !EQ (XCAR (prop
), Qwhen
)
4944 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4946 /* A list of sub-properties. */
4947 while (CONSP (prop
))
4949 if (single_display_spec_string_p (XCAR (prop
), string
))
4954 else if (VECTORP (prop
))
4956 /* A vector of sub-properties. */
4958 for (i
= 0; i
< ASIZE (prop
); ++i
)
4959 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4963 return single_display_spec_string_p (prop
, string
);
4968 /* Look for STRING in overlays and text properties in the current
4969 buffer, between character positions FROM and TO (excluding TO).
4970 BACK_P non-zero means look back (in this case, TO is supposed to be
4972 Value is the first character position where STRING was found, or
4973 zero if it wasn't found before hitting TO.
4975 This function may only use code that doesn't eval because it is
4976 called asynchronously from note_mouse_highlight. */
4979 string_buffer_position_lim (Lisp_Object string
,
4980 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
4982 Lisp_Object limit
, prop
, pos
;
4985 pos
= make_number (max (from
, BEGV
));
4987 if (!back_p
) /* looking forward */
4989 limit
= make_number (min (to
, ZV
));
4990 while (!found
&& !EQ (pos
, limit
))
4992 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4993 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4996 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5000 else /* looking back */
5002 limit
= make_number (max (to
, BEGV
));
5003 while (!found
&& !EQ (pos
, limit
))
5005 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5006 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5009 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5014 return found
? XINT (pos
) : 0;
5017 /* Determine which buffer position in current buffer STRING comes from.
5018 AROUND_CHARPOS is an approximate position where it could come from.
5019 Value is the buffer position or 0 if it couldn't be determined.
5021 This function is necessary because we don't record buffer positions
5022 in glyphs generated from strings (to keep struct glyph small).
5023 This function may only use code that doesn't eval because it is
5024 called asynchronously from note_mouse_highlight. */
5027 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5029 const int MAX_DISTANCE
= 1000;
5030 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5031 around_charpos
+ MAX_DISTANCE
,
5035 found
= string_buffer_position_lim (string
, around_charpos
,
5036 around_charpos
- MAX_DISTANCE
, 1);
5042 /***********************************************************************
5043 `composition' property
5044 ***********************************************************************/
5046 /* Set up iterator IT from `composition' property at its current
5047 position. Called from handle_stop. */
5049 static enum prop_handled
5050 handle_composition_prop (struct it
*it
)
5052 Lisp_Object prop
, string
;
5053 ptrdiff_t pos
, pos_byte
, start
, end
;
5055 if (STRINGP (it
->string
))
5059 pos
= IT_STRING_CHARPOS (*it
);
5060 pos_byte
= IT_STRING_BYTEPOS (*it
);
5061 string
= it
->string
;
5062 s
= SDATA (string
) + pos_byte
;
5063 it
->c
= STRING_CHAR (s
);
5067 pos
= IT_CHARPOS (*it
);
5068 pos_byte
= IT_BYTEPOS (*it
);
5070 it
->c
= FETCH_CHAR (pos_byte
);
5073 /* If there's a valid composition and point is not inside of the
5074 composition (in the case that the composition is from the current
5075 buffer), draw a glyph composed from the composition components. */
5076 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5077 && COMPOSITION_VALID_P (start
, end
, prop
)
5078 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5081 /* As we can't handle this situation (perhaps font-lock added
5082 a new composition), we just return here hoping that next
5083 redisplay will detect this composition much earlier. */
5084 return HANDLED_NORMALLY
;
5087 if (STRINGP (it
->string
))
5088 pos_byte
= string_char_to_byte (it
->string
, start
);
5090 pos_byte
= CHAR_TO_BYTE (start
);
5092 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5095 if (it
->cmp_it
.id
>= 0)
5098 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5099 it
->cmp_it
.nglyphs
= -1;
5103 return HANDLED_NORMALLY
;
5108 /***********************************************************************
5110 ***********************************************************************/
5112 /* The following structure is used to record overlay strings for
5113 later sorting in load_overlay_strings. */
5115 struct overlay_entry
5117 Lisp_Object overlay
;
5124 /* Set up iterator IT from overlay strings at its current position.
5125 Called from handle_stop. */
5127 static enum prop_handled
5128 handle_overlay_change (struct it
*it
)
5130 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5131 return HANDLED_RECOMPUTE_PROPS
;
5133 return HANDLED_NORMALLY
;
5137 /* Set up the next overlay string for delivery by IT, if there is an
5138 overlay string to deliver. Called by set_iterator_to_next when the
5139 end of the current overlay string is reached. If there are more
5140 overlay strings to display, IT->string and
5141 IT->current.overlay_string_index are set appropriately here.
5142 Otherwise IT->string is set to nil. */
5145 next_overlay_string (struct it
*it
)
5147 ++it
->current
.overlay_string_index
;
5148 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5150 /* No more overlay strings. Restore IT's settings to what
5151 they were before overlay strings were processed, and
5152 continue to deliver from current_buffer. */
5154 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5157 || (NILP (it
->string
)
5158 && it
->method
== GET_FROM_BUFFER
5159 && it
->stop_charpos
>= BEGV
5160 && it
->stop_charpos
<= it
->end_charpos
));
5161 it
->current
.overlay_string_index
= -1;
5162 it
->n_overlay_strings
= 0;
5163 it
->overlay_strings_charpos
= -1;
5164 /* If there's an empty display string on the stack, pop the
5165 stack, to resync the bidi iterator with IT's position. Such
5166 empty strings are pushed onto the stack in
5167 get_overlay_strings_1. */
5168 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5171 /* If we're at the end of the buffer, record that we have
5172 processed the overlay strings there already, so that
5173 next_element_from_buffer doesn't try it again. */
5174 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5175 it
->overlay_strings_at_end_processed_p
= 1;
5179 /* There are more overlay strings to process. If
5180 IT->current.overlay_string_index has advanced to a position
5181 where we must load IT->overlay_strings with more strings, do
5182 it. We must load at the IT->overlay_strings_charpos where
5183 IT->n_overlay_strings was originally computed; when invisible
5184 text is present, this might not be IT_CHARPOS (Bug#7016). */
5185 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5187 if (it
->current
.overlay_string_index
&& i
== 0)
5188 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5190 /* Initialize IT to deliver display elements from the overlay
5192 it
->string
= it
->overlay_strings
[i
];
5193 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5194 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5195 it
->method
= GET_FROM_STRING
;
5196 it
->stop_charpos
= 0;
5197 if (it
->cmp_it
.stop_pos
>= 0)
5198 it
->cmp_it
.stop_pos
= 0;
5200 it
->base_level_stop
= 0;
5202 /* Set up the bidi iterator for this overlay string. */
5205 it
->bidi_it
.string
.lstring
= it
->string
;
5206 it
->bidi_it
.string
.s
= NULL
;
5207 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5208 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5209 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5210 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5211 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5219 /* Compare two overlay_entry structures E1 and E2. Used as a
5220 comparison function for qsort in load_overlay_strings. Overlay
5221 strings for the same position are sorted so that
5223 1. All after-strings come in front of before-strings, except
5224 when they come from the same overlay.
5226 2. Within after-strings, strings are sorted so that overlay strings
5227 from overlays with higher priorities come first.
5229 2. Within before-strings, strings are sorted so that overlay
5230 strings from overlays with higher priorities come last.
5232 Value is analogous to strcmp. */
5236 compare_overlay_entries (const void *e1
, const void *e2
)
5238 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5239 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5242 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5244 /* Let after-strings appear in front of before-strings if
5245 they come from different overlays. */
5246 if (EQ (entry1
->overlay
, entry2
->overlay
))
5247 result
= entry1
->after_string_p
? 1 : -1;
5249 result
= entry1
->after_string_p
? -1 : 1;
5251 else if (entry1
->priority
!= entry2
->priority
)
5253 if (entry1
->after_string_p
)
5254 /* After-strings sorted in order of decreasing priority. */
5255 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5257 /* Before-strings sorted in order of increasing priority. */
5258 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5267 /* Load the vector IT->overlay_strings with overlay strings from IT's
5268 current buffer position, or from CHARPOS if that is > 0. Set
5269 IT->n_overlays to the total number of overlay strings found.
5271 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5272 a time. On entry into load_overlay_strings,
5273 IT->current.overlay_string_index gives the number of overlay
5274 strings that have already been loaded by previous calls to this
5277 IT->add_overlay_start contains an additional overlay start
5278 position to consider for taking overlay strings from, if non-zero.
5279 This position comes into play when the overlay has an `invisible'
5280 property, and both before and after-strings. When we've skipped to
5281 the end of the overlay, because of its `invisible' property, we
5282 nevertheless want its before-string to appear.
5283 IT->add_overlay_start will contain the overlay start position
5286 Overlay strings are sorted so that after-string strings come in
5287 front of before-string strings. Within before and after-strings,
5288 strings are sorted by overlay priority. See also function
5289 compare_overlay_entries. */
5292 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5294 Lisp_Object overlay
, window
, str
, invisible
;
5295 struct Lisp_Overlay
*ov
;
5296 ptrdiff_t start
, end
;
5297 ptrdiff_t size
= 20;
5298 ptrdiff_t n
= 0, i
, j
;
5300 struct overlay_entry
*entries
5301 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5305 charpos
= IT_CHARPOS (*it
);
5307 /* Append the overlay string STRING of overlay OVERLAY to vector
5308 `entries' which has size `size' and currently contains `n'
5309 elements. AFTER_P non-zero means STRING is an after-string of
5311 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5314 Lisp_Object priority; \
5318 struct overlay_entry *old = entries; \
5319 SAFE_NALLOCA (entries, 2, size); \
5320 memcpy (entries, old, size * sizeof *entries); \
5324 entries[n].string = (STRING); \
5325 entries[n].overlay = (OVERLAY); \
5326 priority = Foverlay_get ((OVERLAY), Qpriority); \
5327 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5328 entries[n].after_string_p = (AFTER_P); \
5333 /* Process overlay before the overlay center. */
5334 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5336 XSETMISC (overlay
, ov
);
5337 xassert (OVERLAYP (overlay
));
5338 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5339 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5344 /* Skip this overlay if it doesn't start or end at IT's current
5346 if (end
!= charpos
&& start
!= charpos
)
5349 /* Skip this overlay if it doesn't apply to IT->w. */
5350 window
= Foverlay_get (overlay
, Qwindow
);
5351 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5354 /* If the text ``under'' the overlay is invisible, both before-
5355 and after-strings from this overlay are visible; start and
5356 end position are indistinguishable. */
5357 invisible
= Foverlay_get (overlay
, Qinvisible
);
5358 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5360 /* If overlay has a non-empty before-string, record it. */
5361 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5362 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5364 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5366 /* If overlay has a non-empty after-string, record it. */
5367 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5368 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5370 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5373 /* Process overlays after the overlay center. */
5374 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5376 XSETMISC (overlay
, ov
);
5377 xassert (OVERLAYP (overlay
));
5378 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5379 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5381 if (start
> charpos
)
5384 /* Skip this overlay if it doesn't start or end at IT's current
5386 if (end
!= charpos
&& start
!= charpos
)
5389 /* Skip this overlay if it doesn't apply to IT->w. */
5390 window
= Foverlay_get (overlay
, Qwindow
);
5391 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5394 /* If the text ``under'' the overlay is invisible, it has a zero
5395 dimension, and both before- and after-strings apply. */
5396 invisible
= Foverlay_get (overlay
, Qinvisible
);
5397 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5399 /* If overlay has a non-empty before-string, record it. */
5400 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5401 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5403 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5405 /* If overlay has a non-empty after-string, record it. */
5406 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5407 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5409 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5412 #undef RECORD_OVERLAY_STRING
5416 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5418 /* Record number of overlay strings, and where we computed it. */
5419 it
->n_overlay_strings
= n
;
5420 it
->overlay_strings_charpos
= charpos
;
5422 /* IT->current.overlay_string_index is the number of overlay strings
5423 that have already been consumed by IT. Copy some of the
5424 remaining overlay strings to IT->overlay_strings. */
5426 j
= it
->current
.overlay_string_index
;
5427 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5429 it
->overlay_strings
[i
] = entries
[j
].string
;
5430 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5438 /* Get the first chunk of overlay strings at IT's current buffer
5439 position, or at CHARPOS if that is > 0. Value is non-zero if at
5440 least one overlay string was found. */
5443 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5445 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5446 process. This fills IT->overlay_strings with strings, and sets
5447 IT->n_overlay_strings to the total number of strings to process.
5448 IT->pos.overlay_string_index has to be set temporarily to zero
5449 because load_overlay_strings needs this; it must be set to -1
5450 when no overlay strings are found because a zero value would
5451 indicate a position in the first overlay string. */
5452 it
->current
.overlay_string_index
= 0;
5453 load_overlay_strings (it
, charpos
);
5455 /* If we found overlay strings, set up IT to deliver display
5456 elements from the first one. Otherwise set up IT to deliver
5457 from current_buffer. */
5458 if (it
->n_overlay_strings
)
5460 /* Make sure we know settings in current_buffer, so that we can
5461 restore meaningful values when we're done with the overlay
5464 compute_stop_pos (it
);
5465 xassert (it
->face_id
>= 0);
5467 /* Save IT's settings. They are restored after all overlay
5468 strings have been processed. */
5469 xassert (!compute_stop_p
|| it
->sp
== 0);
5471 /* When called from handle_stop, there might be an empty display
5472 string loaded. In that case, don't bother saving it. But
5473 don't use this optimization with the bidi iterator, since we
5474 need the corresponding pop_it call to resync the bidi
5475 iterator's position with IT's position, after we are done
5476 with the overlay strings. (The corresponding call to pop_it
5477 in case of an empty display string is in
5478 next_overlay_string.) */
5480 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5483 /* Set up IT to deliver display elements from the first overlay
5485 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5486 it
->string
= it
->overlay_strings
[0];
5487 it
->from_overlay
= Qnil
;
5488 it
->stop_charpos
= 0;
5489 xassert (STRINGP (it
->string
));
5490 it
->end_charpos
= SCHARS (it
->string
);
5492 it
->base_level_stop
= 0;
5493 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5494 it
->method
= GET_FROM_STRING
;
5495 it
->from_disp_prop_p
= 0;
5497 /* Force paragraph direction to be that of the parent
5499 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5500 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5502 it
->paragraph_embedding
= L2R
;
5504 /* Set up the bidi iterator for this overlay string. */
5507 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5509 it
->bidi_it
.string
.lstring
= it
->string
;
5510 it
->bidi_it
.string
.s
= NULL
;
5511 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5512 it
->bidi_it
.string
.bufpos
= pos
;
5513 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5514 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5515 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5520 it
->current
.overlay_string_index
= -1;
5525 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5528 it
->method
= GET_FROM_BUFFER
;
5530 (void) get_overlay_strings_1 (it
, charpos
, 1);
5534 /* Value is non-zero if we found at least one overlay string. */
5535 return STRINGP (it
->string
);
5540 /***********************************************************************
5541 Saving and restoring state
5542 ***********************************************************************/
5544 /* Save current settings of IT on IT->stack. Called, for example,
5545 before setting up IT for an overlay string, to be able to restore
5546 IT's settings to what they were after the overlay string has been
5547 processed. If POSITION is non-NULL, it is the position to save on
5548 the stack instead of IT->position. */
5551 push_it (struct it
*it
, struct text_pos
*position
)
5553 struct iterator_stack_entry
*p
;
5555 xassert (it
->sp
< IT_STACK_SIZE
);
5556 p
= it
->stack
+ it
->sp
;
5558 p
->stop_charpos
= it
->stop_charpos
;
5559 p
->prev_stop
= it
->prev_stop
;
5560 p
->base_level_stop
= it
->base_level_stop
;
5561 p
->cmp_it
= it
->cmp_it
;
5562 xassert (it
->face_id
>= 0);
5563 p
->face_id
= it
->face_id
;
5564 p
->string
= it
->string
;
5565 p
->method
= it
->method
;
5566 p
->from_overlay
= it
->from_overlay
;
5569 case GET_FROM_IMAGE
:
5570 p
->u
.image
.object
= it
->object
;
5571 p
->u
.image
.image_id
= it
->image_id
;
5572 p
->u
.image
.slice
= it
->slice
;
5574 case GET_FROM_STRETCH
:
5575 p
->u
.stretch
.object
= it
->object
;
5578 p
->position
= position
? *position
: it
->position
;
5579 p
->current
= it
->current
;
5580 p
->end_charpos
= it
->end_charpos
;
5581 p
->string_nchars
= it
->string_nchars
;
5583 p
->multibyte_p
= it
->multibyte_p
;
5584 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5585 p
->space_width
= it
->space_width
;
5586 p
->font_height
= it
->font_height
;
5587 p
->voffset
= it
->voffset
;
5588 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5589 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5590 p
->display_ellipsis_p
= 0;
5591 p
->line_wrap
= it
->line_wrap
;
5592 p
->bidi_p
= it
->bidi_p
;
5593 p
->paragraph_embedding
= it
->paragraph_embedding
;
5594 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5597 /* Save the state of the bidi iterator as well. */
5599 bidi_push_it (&it
->bidi_it
);
5603 iterate_out_of_display_property (struct it
*it
)
5605 int buffer_p
= BUFFERP (it
->object
);
5606 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5607 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5609 xassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5611 /* Maybe initialize paragraph direction. If we are at the beginning
5612 of a new paragraph, next_element_from_buffer may not have a
5613 chance to do that. */
5614 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5615 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5616 /* prev_stop can be zero, so check against BEGV as well. */
5617 while (it
->bidi_it
.charpos
>= bob
5618 && it
->prev_stop
<= it
->bidi_it
.charpos
5619 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5620 && it
->bidi_it
.charpos
< eob
)
5621 bidi_move_to_visually_next (&it
->bidi_it
);
5622 /* Record the stop_pos we just crossed, for when we cross it
5624 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5625 it
->prev_stop
= CHARPOS (it
->position
);
5626 /* If we ended up not where pop_it put us, resync IT's
5627 positional members with the bidi iterator. */
5628 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5629 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5631 it
->current
.pos
= it
->position
;
5633 it
->current
.string_pos
= it
->position
;
5636 /* Restore IT's settings from IT->stack. Called, for example, when no
5637 more overlay strings must be processed, and we return to delivering
5638 display elements from a buffer, or when the end of a string from a
5639 `display' property is reached and we return to delivering display
5640 elements from an overlay string, or from a buffer. */
5643 pop_it (struct it
*it
)
5645 struct iterator_stack_entry
*p
;
5646 int from_display_prop
= it
->from_disp_prop_p
;
5648 xassert (it
->sp
> 0);
5650 p
= it
->stack
+ it
->sp
;
5651 it
->stop_charpos
= p
->stop_charpos
;
5652 it
->prev_stop
= p
->prev_stop
;
5653 it
->base_level_stop
= p
->base_level_stop
;
5654 it
->cmp_it
= p
->cmp_it
;
5655 it
->face_id
= p
->face_id
;
5656 it
->current
= p
->current
;
5657 it
->position
= p
->position
;
5658 it
->string
= p
->string
;
5659 it
->from_overlay
= p
->from_overlay
;
5660 if (NILP (it
->string
))
5661 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5662 it
->method
= p
->method
;
5665 case GET_FROM_IMAGE
:
5666 it
->image_id
= p
->u
.image
.image_id
;
5667 it
->object
= p
->u
.image
.object
;
5668 it
->slice
= p
->u
.image
.slice
;
5670 case GET_FROM_STRETCH
:
5671 it
->object
= p
->u
.stretch
.object
;
5673 case GET_FROM_BUFFER
:
5674 it
->object
= it
->w
->buffer
;
5676 case GET_FROM_STRING
:
5677 it
->object
= it
->string
;
5679 case GET_FROM_DISPLAY_VECTOR
:
5681 it
->method
= GET_FROM_C_STRING
;
5682 else if (STRINGP (it
->string
))
5683 it
->method
= GET_FROM_STRING
;
5686 it
->method
= GET_FROM_BUFFER
;
5687 it
->object
= it
->w
->buffer
;
5690 it
->end_charpos
= p
->end_charpos
;
5691 it
->string_nchars
= p
->string_nchars
;
5693 it
->multibyte_p
= p
->multibyte_p
;
5694 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5695 it
->space_width
= p
->space_width
;
5696 it
->font_height
= p
->font_height
;
5697 it
->voffset
= p
->voffset
;
5698 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5699 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5700 it
->line_wrap
= p
->line_wrap
;
5701 it
->bidi_p
= p
->bidi_p
;
5702 it
->paragraph_embedding
= p
->paragraph_embedding
;
5703 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5706 bidi_pop_it (&it
->bidi_it
);
5707 /* Bidi-iterate until we get out of the portion of text, if any,
5708 covered by a `display' text property or by an overlay with
5709 `display' property. (We cannot just jump there, because the
5710 internal coherency of the bidi iterator state can not be
5711 preserved across such jumps.) We also must determine the
5712 paragraph base direction if the overlay we just processed is
5713 at the beginning of a new paragraph. */
5714 if (from_display_prop
5715 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5716 iterate_out_of_display_property (it
);
5718 xassert ((BUFFERP (it
->object
)
5719 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5720 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5721 || (STRINGP (it
->object
)
5722 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5723 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5724 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5730 /***********************************************************************
5732 ***********************************************************************/
5734 /* Set IT's current position to the previous line start. */
5737 back_to_previous_line_start (struct it
*it
)
5739 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5740 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5744 /* Move IT to the next line start.
5746 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5747 we skipped over part of the text (as opposed to moving the iterator
5748 continuously over the text). Otherwise, don't change the value
5751 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5752 iterator on the newline, if it was found.
5754 Newlines may come from buffer text, overlay strings, or strings
5755 displayed via the `display' property. That's the reason we can't
5756 simply use find_next_newline_no_quit.
5758 Note that this function may not skip over invisible text that is so
5759 because of text properties and immediately follows a newline. If
5760 it would, function reseat_at_next_visible_line_start, when called
5761 from set_iterator_to_next, would effectively make invisible
5762 characters following a newline part of the wrong glyph row, which
5763 leads to wrong cursor motion. */
5766 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5767 struct bidi_it
*bidi_it_prev
)
5769 ptrdiff_t old_selective
;
5770 int newline_found_p
, n
;
5771 const int MAX_NEWLINE_DISTANCE
= 500;
5773 /* If already on a newline, just consume it to avoid unintended
5774 skipping over invisible text below. */
5775 if (it
->what
== IT_CHARACTER
5777 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5779 if (it
->bidi_p
&& bidi_it_prev
)
5780 *bidi_it_prev
= it
->bidi_it
;
5781 set_iterator_to_next (it
, 0);
5786 /* Don't handle selective display in the following. It's (a)
5787 unnecessary because it's done by the caller, and (b) leads to an
5788 infinite recursion because next_element_from_ellipsis indirectly
5789 calls this function. */
5790 old_selective
= it
->selective
;
5793 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5794 from buffer text. */
5795 for (n
= newline_found_p
= 0;
5796 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5797 n
+= STRINGP (it
->string
) ? 0 : 1)
5799 if (!get_next_display_element (it
))
5801 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5802 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5803 *bidi_it_prev
= it
->bidi_it
;
5804 set_iterator_to_next (it
, 0);
5807 /* If we didn't find a newline near enough, see if we can use a
5809 if (!newline_found_p
)
5811 ptrdiff_t start
= IT_CHARPOS (*it
);
5812 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5815 xassert (!STRINGP (it
->string
));
5817 /* If there isn't any `display' property in sight, and no
5818 overlays, we can just use the position of the newline in
5820 if (it
->stop_charpos
>= limit
5821 || ((pos
= Fnext_single_property_change (make_number (start
),
5823 make_number (limit
)),
5825 && next_overlay_change (start
) == ZV
))
5829 IT_CHARPOS (*it
) = limit
;
5830 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5834 struct bidi_it bprev
;
5836 /* Help bidi.c avoid expensive searches for display
5837 properties and overlays, by telling it that there are
5838 none up to `limit'. */
5839 if (it
->bidi_it
.disp_pos
< limit
)
5841 it
->bidi_it
.disp_pos
= limit
;
5842 it
->bidi_it
.disp_prop
= 0;
5845 bprev
= it
->bidi_it
;
5846 bidi_move_to_visually_next (&it
->bidi_it
);
5847 } while (it
->bidi_it
.charpos
!= limit
);
5848 IT_CHARPOS (*it
) = limit
;
5849 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5851 *bidi_it_prev
= bprev
;
5853 *skipped_p
= newline_found_p
= 1;
5857 while (get_next_display_element (it
)
5858 && !newline_found_p
)
5860 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5861 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5862 *bidi_it_prev
= it
->bidi_it
;
5863 set_iterator_to_next (it
, 0);
5868 it
->selective
= old_selective
;
5869 return newline_found_p
;
5873 /* Set IT's current position to the previous visible line start. Skip
5874 invisible text that is so either due to text properties or due to
5875 selective display. Caution: this does not change IT->current_x and
5879 back_to_previous_visible_line_start (struct it
*it
)
5881 while (IT_CHARPOS (*it
) > BEGV
)
5883 back_to_previous_line_start (it
);
5885 if (IT_CHARPOS (*it
) <= BEGV
)
5888 /* If selective > 0, then lines indented more than its value are
5890 if (it
->selective
> 0
5891 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5895 /* Check the newline before point for invisibility. */
5898 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5899 Qinvisible
, it
->window
);
5900 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5904 if (IT_CHARPOS (*it
) <= BEGV
)
5909 void *it2data
= NULL
;
5912 Lisp_Object val
, overlay
;
5914 SAVE_IT (it2
, *it
, it2data
);
5916 /* If newline is part of a composition, continue from start of composition */
5917 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5918 && beg
< IT_CHARPOS (*it
))
5921 /* If newline is replaced by a display property, find start of overlay
5922 or interval and continue search from that point. */
5923 pos
= --IT_CHARPOS (it2
);
5926 bidi_unshelve_cache (NULL
, 0);
5927 it2
.string_from_display_prop_p
= 0;
5928 it2
.from_disp_prop_p
= 0;
5929 if (handle_display_prop (&it2
) == HANDLED_RETURN
5930 && !NILP (val
= get_char_property_and_overlay
5931 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5932 && (OVERLAYP (overlay
)
5933 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5934 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5936 RESTORE_IT (it
, it
, it2data
);
5940 /* Newline is not replaced by anything -- so we are done. */
5941 RESTORE_IT (it
, it
, it2data
);
5947 IT_CHARPOS (*it
) = beg
;
5948 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5952 it
->continuation_lines_width
= 0;
5954 xassert (IT_CHARPOS (*it
) >= BEGV
);
5955 xassert (IT_CHARPOS (*it
) == BEGV
5956 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5961 /* Reseat iterator IT at the previous visible line start. Skip
5962 invisible text that is so either due to text properties or due to
5963 selective display. At the end, update IT's overlay information,
5964 face information etc. */
5967 reseat_at_previous_visible_line_start (struct it
*it
)
5969 back_to_previous_visible_line_start (it
);
5970 reseat (it
, it
->current
.pos
, 1);
5975 /* Reseat iterator IT on the next visible line start in the current
5976 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5977 preceding the line start. Skip over invisible text that is so
5978 because of selective display. Compute faces, overlays etc at the
5979 new position. Note that this function does not skip over text that
5980 is invisible because of text properties. */
5983 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5985 int newline_found_p
, skipped_p
= 0;
5986 struct bidi_it bidi_it_prev
;
5988 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
5990 /* Skip over lines that are invisible because they are indented
5991 more than the value of IT->selective. */
5992 if (it
->selective
> 0)
5993 while (IT_CHARPOS (*it
) < ZV
5994 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5997 xassert (IT_BYTEPOS (*it
) == BEGV
5998 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6000 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6003 /* Position on the newline if that's what's requested. */
6004 if (on_newline_p
&& newline_found_p
)
6006 if (STRINGP (it
->string
))
6008 if (IT_STRING_CHARPOS (*it
) > 0)
6012 --IT_STRING_CHARPOS (*it
);
6013 --IT_STRING_BYTEPOS (*it
);
6017 /* We need to restore the bidi iterator to the state
6018 it had on the newline, and resync the IT's
6019 position with that. */
6020 it
->bidi_it
= bidi_it_prev
;
6021 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6022 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6026 else if (IT_CHARPOS (*it
) > BEGV
)
6035 /* We need to restore the bidi iterator to the state it
6036 had on the newline and resync IT with that. */
6037 it
->bidi_it
= bidi_it_prev
;
6038 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6039 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6041 reseat (it
, it
->current
.pos
, 0);
6045 reseat (it
, it
->current
.pos
, 0);
6052 /***********************************************************************
6053 Changing an iterator's position
6054 ***********************************************************************/
6056 /* Change IT's current position to POS in current_buffer. If FORCE_P
6057 is non-zero, always check for text properties at the new position.
6058 Otherwise, text properties are only looked up if POS >=
6059 IT->check_charpos of a property. */
6062 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6064 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6066 reseat_1 (it
, pos
, 0);
6068 /* Determine where to check text properties. Avoid doing it
6069 where possible because text property lookup is very expensive. */
6071 || CHARPOS (pos
) > it
->stop_charpos
6072 || CHARPOS (pos
) < original_pos
)
6076 /* For bidi iteration, we need to prime prev_stop and
6077 base_level_stop with our best estimations. */
6078 /* Implementation note: Of course, POS is not necessarily a
6079 stop position, so assigning prev_pos to it is a lie; we
6080 should have called compute_stop_backwards. However, if
6081 the current buffer does not include any R2L characters,
6082 that call would be a waste of cycles, because the
6083 iterator will never move back, and thus never cross this
6084 "fake" stop position. So we delay that backward search
6085 until the time we really need it, in next_element_from_buffer. */
6086 if (CHARPOS (pos
) != it
->prev_stop
)
6087 it
->prev_stop
= CHARPOS (pos
);
6088 if (CHARPOS (pos
) < it
->base_level_stop
)
6089 it
->base_level_stop
= 0; /* meaning it's unknown */
6095 it
->prev_stop
= it
->base_level_stop
= 0;
6104 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6105 IT->stop_pos to POS, also. */
6108 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6110 /* Don't call this function when scanning a C string. */
6111 xassert (it
->s
== NULL
);
6113 /* POS must be a reasonable value. */
6114 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6116 it
->current
.pos
= it
->position
= pos
;
6117 it
->end_charpos
= ZV
;
6119 it
->current
.dpvec_index
= -1;
6120 it
->current
.overlay_string_index
= -1;
6121 IT_STRING_CHARPOS (*it
) = -1;
6122 IT_STRING_BYTEPOS (*it
) = -1;
6124 it
->method
= GET_FROM_BUFFER
;
6125 it
->object
= it
->w
->buffer
;
6126 it
->area
= TEXT_AREA
;
6127 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6129 it
->string_from_display_prop_p
= 0;
6130 it
->string_from_prefix_prop_p
= 0;
6132 it
->from_disp_prop_p
= 0;
6133 it
->face_before_selective_p
= 0;
6136 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6138 bidi_unshelve_cache (NULL
, 0);
6139 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6140 it
->bidi_it
.string
.s
= NULL
;
6141 it
->bidi_it
.string
.lstring
= Qnil
;
6142 it
->bidi_it
.string
.bufpos
= 0;
6143 it
->bidi_it
.string
.unibyte
= 0;
6148 it
->stop_charpos
= CHARPOS (pos
);
6149 it
->base_level_stop
= CHARPOS (pos
);
6154 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6155 If S is non-null, it is a C string to iterate over. Otherwise,
6156 STRING gives a Lisp string to iterate over.
6158 If PRECISION > 0, don't return more then PRECISION number of
6159 characters from the string.
6161 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6162 characters have been returned. FIELD_WIDTH < 0 means an infinite
6165 MULTIBYTE = 0 means disable processing of multibyte characters,
6166 MULTIBYTE > 0 means enable it,
6167 MULTIBYTE < 0 means use IT->multibyte_p.
6169 IT must be initialized via a prior call to init_iterator before
6170 calling this function. */
6173 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6174 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6177 /* No region in strings. */
6178 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6180 /* No text property checks performed by default, but see below. */
6181 it
->stop_charpos
= -1;
6183 /* Set iterator position and end position. */
6184 memset (&it
->current
, 0, sizeof it
->current
);
6185 it
->current
.overlay_string_index
= -1;
6186 it
->current
.dpvec_index
= -1;
6187 xassert (charpos
>= 0);
6189 /* If STRING is specified, use its multibyteness, otherwise use the
6190 setting of MULTIBYTE, if specified. */
6192 it
->multibyte_p
= multibyte
> 0;
6194 /* Bidirectional reordering of strings is controlled by the default
6195 value of bidi-display-reordering. Don't try to reorder while
6196 loading loadup.el, as the necessary character property tables are
6197 not yet available. */
6200 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6204 xassert (STRINGP (string
));
6205 it
->string
= string
;
6207 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6208 it
->method
= GET_FROM_STRING
;
6209 it
->current
.string_pos
= string_pos (charpos
, string
);
6213 it
->bidi_it
.string
.lstring
= string
;
6214 it
->bidi_it
.string
.s
= NULL
;
6215 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6216 it
->bidi_it
.string
.bufpos
= 0;
6217 it
->bidi_it
.string
.from_disp_str
= 0;
6218 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6219 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6220 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6225 it
->s
= (const unsigned char *) s
;
6228 /* Note that we use IT->current.pos, not it->current.string_pos,
6229 for displaying C strings. */
6230 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6231 if (it
->multibyte_p
)
6233 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6234 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6238 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6239 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6244 it
->bidi_it
.string
.lstring
= Qnil
;
6245 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6246 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6247 it
->bidi_it
.string
.bufpos
= 0;
6248 it
->bidi_it
.string
.from_disp_str
= 0;
6249 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6250 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6253 it
->method
= GET_FROM_C_STRING
;
6256 /* PRECISION > 0 means don't return more than PRECISION characters
6258 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6260 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6262 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6265 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6266 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6267 FIELD_WIDTH < 0 means infinite field width. This is useful for
6268 padding with `-' at the end of a mode line. */
6269 if (field_width
< 0)
6270 field_width
= INFINITY
;
6271 /* Implementation note: We deliberately don't enlarge
6272 it->bidi_it.string.schars here to fit it->end_charpos, because
6273 the bidi iterator cannot produce characters out of thin air. */
6274 if (field_width
> it
->end_charpos
- charpos
)
6275 it
->end_charpos
= charpos
+ field_width
;
6277 /* Use the standard display table for displaying strings. */
6278 if (DISP_TABLE_P (Vstandard_display_table
))
6279 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6281 it
->stop_charpos
= charpos
;
6282 it
->prev_stop
= charpos
;
6283 it
->base_level_stop
= 0;
6286 it
->bidi_it
.first_elt
= 1;
6287 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6288 it
->bidi_it
.disp_pos
= -1;
6290 if (s
== NULL
&& it
->multibyte_p
)
6292 ptrdiff_t endpos
= SCHARS (it
->string
);
6293 if (endpos
> it
->end_charpos
)
6294 endpos
= it
->end_charpos
;
6295 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6303 /***********************************************************************
6305 ***********************************************************************/
6307 /* Map enum it_method value to corresponding next_element_from_* function. */
6309 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6311 next_element_from_buffer
,
6312 next_element_from_display_vector
,
6313 next_element_from_string
,
6314 next_element_from_c_string
,
6315 next_element_from_image
,
6316 next_element_from_stretch
6319 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6322 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6323 (possibly with the following characters). */
6325 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6326 ((IT)->cmp_it.id >= 0 \
6327 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6328 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6329 END_CHARPOS, (IT)->w, \
6330 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6334 /* Lookup the char-table Vglyphless_char_display for character C (-1
6335 if we want information for no-font case), and return the display
6336 method symbol. By side-effect, update it->what and
6337 it->glyphless_method. This function is called from
6338 get_next_display_element for each character element, and from
6339 x_produce_glyphs when no suitable font was found. */
6342 lookup_glyphless_char_display (int c
, struct it
*it
)
6344 Lisp_Object glyphless_method
= Qnil
;
6346 if (CHAR_TABLE_P (Vglyphless_char_display
)
6347 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6351 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6352 if (CONSP (glyphless_method
))
6353 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6354 ? XCAR (glyphless_method
)
6355 : XCDR (glyphless_method
);
6358 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6362 if (NILP (glyphless_method
))
6365 /* The default is to display the character by a proper font. */
6367 /* The default for the no-font case is to display an empty box. */
6368 glyphless_method
= Qempty_box
;
6370 if (EQ (glyphless_method
, Qzero_width
))
6373 return glyphless_method
;
6374 /* This method can't be used for the no-font case. */
6375 glyphless_method
= Qempty_box
;
6377 if (EQ (glyphless_method
, Qthin_space
))
6378 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6379 else if (EQ (glyphless_method
, Qempty_box
))
6380 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6381 else if (EQ (glyphless_method
, Qhex_code
))
6382 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6383 else if (STRINGP (glyphless_method
))
6384 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6387 /* Invalid value. We use the default method. */
6388 glyphless_method
= Qnil
;
6391 it
->what
= IT_GLYPHLESS
;
6392 return glyphless_method
;
6395 /* Load IT's display element fields with information about the next
6396 display element from the current position of IT. Value is zero if
6397 end of buffer (or C string) is reached. */
6399 static struct frame
*last_escape_glyph_frame
= NULL
;
6400 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6401 static int last_escape_glyph_merged_face_id
= 0;
6403 struct frame
*last_glyphless_glyph_frame
= NULL
;
6404 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6405 int last_glyphless_glyph_merged_face_id
= 0;
6408 get_next_display_element (struct it
*it
)
6410 /* Non-zero means that we found a display element. Zero means that
6411 we hit the end of what we iterate over. Performance note: the
6412 function pointer `method' used here turns out to be faster than
6413 using a sequence of if-statements. */
6417 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6419 if (it
->what
== IT_CHARACTER
)
6421 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6422 and only if (a) the resolved directionality of that character
6424 /* FIXME: Do we need an exception for characters from display
6426 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6427 it
->c
= bidi_mirror_char (it
->c
);
6428 /* Map via display table or translate control characters.
6429 IT->c, IT->len etc. have been set to the next character by
6430 the function call above. If we have a display table, and it
6431 contains an entry for IT->c, translate it. Don't do this if
6432 IT->c itself comes from a display table, otherwise we could
6433 end up in an infinite recursion. (An alternative could be to
6434 count the recursion depth of this function and signal an
6435 error when a certain maximum depth is reached.) Is it worth
6437 if (success_p
&& it
->dpvec
== NULL
)
6440 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6441 int nonascii_space_p
= 0;
6442 int nonascii_hyphen_p
= 0;
6443 int c
= it
->c
; /* This is the character to display. */
6445 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6447 xassert (SINGLE_BYTE_CHAR_P (c
));
6448 if (unibyte_display_via_language_environment
)
6450 c
= DECODE_CHAR (unibyte
, c
);
6452 c
= BYTE8_TO_CHAR (it
->c
);
6455 c
= BYTE8_TO_CHAR (it
->c
);
6459 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6462 struct Lisp_Vector
*v
= XVECTOR (dv
);
6464 /* Return the first character from the display table
6465 entry, if not empty. If empty, don't display the
6466 current character. */
6469 it
->dpvec_char_len
= it
->len
;
6470 it
->dpvec
= v
->contents
;
6471 it
->dpend
= v
->contents
+ v
->header
.size
;
6472 it
->current
.dpvec_index
= 0;
6473 it
->dpvec_face_id
= -1;
6474 it
->saved_face_id
= it
->face_id
;
6475 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6480 set_iterator_to_next (it
, 0);
6485 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6487 if (it
->what
== IT_GLYPHLESS
)
6489 /* Don't display this character. */
6490 set_iterator_to_next (it
, 0);
6494 /* If `nobreak-char-display' is non-nil, we display
6495 non-ASCII spaces and hyphens specially. */
6496 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6499 nonascii_space_p
= 1;
6500 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6501 nonascii_hyphen_p
= 1;
6504 /* Translate control characters into `\003' or `^C' form.
6505 Control characters coming from a display table entry are
6506 currently not translated because we use IT->dpvec to hold
6507 the translation. This could easily be changed but I
6508 don't believe that it is worth doing.
6510 The characters handled by `nobreak-char-display' must be
6513 Non-printable characters and raw-byte characters are also
6514 translated to octal form. */
6515 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6516 ? (it
->area
!= TEXT_AREA
6517 /* In mode line, treat \n, \t like other crl chars. */
6520 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6521 || (c
!= '\n' && c
!= '\t'))
6523 || nonascii_hyphen_p
6525 || ! CHAR_PRINTABLE_P (c
))))
6527 /* C is a control character, non-ASCII space/hyphen,
6528 raw-byte, or a non-printable character which must be
6529 displayed either as '\003' or as `^C' where the '\\'
6530 and '^' can be defined in the display table. Fill
6531 IT->ctl_chars with glyphs for what we have to
6532 display. Then, set IT->dpvec to these glyphs. */
6539 /* Handle control characters with ^. */
6541 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6545 g
= '^'; /* default glyph for Control */
6546 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6548 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6550 g
= GLYPH_CODE_CHAR (gc
);
6551 lface_id
= GLYPH_CODE_FACE (gc
);
6555 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6557 else if (it
->f
== last_escape_glyph_frame
6558 && it
->face_id
== last_escape_glyph_face_id
)
6560 face_id
= last_escape_glyph_merged_face_id
;
6564 /* Merge the escape-glyph face into the current face. */
6565 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6567 last_escape_glyph_frame
= it
->f
;
6568 last_escape_glyph_face_id
= it
->face_id
;
6569 last_escape_glyph_merged_face_id
= face_id
;
6572 XSETINT (it
->ctl_chars
[0], g
);
6573 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6575 goto display_control
;
6578 /* Handle non-ascii space in the mode where it only gets
6581 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6583 /* Merge `nobreak-space' into the current face. */
6584 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6586 XSETINT (it
->ctl_chars
[0], ' ');
6588 goto display_control
;
6591 /* Handle sequences that start with the "escape glyph". */
6593 /* the default escape glyph is \. */
6594 escape_glyph
= '\\';
6597 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6599 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6600 lface_id
= GLYPH_CODE_FACE (gc
);
6604 /* The display table specified a face.
6605 Merge it into face_id and also into escape_glyph. */
6606 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6609 else if (it
->f
== last_escape_glyph_frame
6610 && it
->face_id
== last_escape_glyph_face_id
)
6612 face_id
= last_escape_glyph_merged_face_id
;
6616 /* Merge the escape-glyph face into the current face. */
6617 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6619 last_escape_glyph_frame
= it
->f
;
6620 last_escape_glyph_face_id
= it
->face_id
;
6621 last_escape_glyph_merged_face_id
= face_id
;
6624 /* Draw non-ASCII hyphen with just highlighting: */
6626 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6628 XSETINT (it
->ctl_chars
[0], '-');
6630 goto display_control
;
6633 /* Draw non-ASCII space/hyphen with escape glyph: */
6635 if (nonascii_space_p
|| nonascii_hyphen_p
)
6637 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6638 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6640 goto display_control
;
6647 if (CHAR_BYTE8_P (c
))
6648 /* Display \200 instead of \17777600. */
6649 c
= CHAR_TO_BYTE8 (c
);
6650 len
= sprintf (str
, "%03o", c
);
6652 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6653 for (i
= 0; i
< len
; i
++)
6654 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6659 /* Set up IT->dpvec and return first character from it. */
6660 it
->dpvec_char_len
= it
->len
;
6661 it
->dpvec
= it
->ctl_chars
;
6662 it
->dpend
= it
->dpvec
+ ctl_len
;
6663 it
->current
.dpvec_index
= 0;
6664 it
->dpvec_face_id
= face_id
;
6665 it
->saved_face_id
= it
->face_id
;
6666 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6670 it
->char_to_display
= c
;
6674 it
->char_to_display
= it
->c
;
6678 /* Adjust face id for a multibyte character. There are no multibyte
6679 character in unibyte text. */
6680 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6683 && FRAME_WINDOW_P (it
->f
))
6685 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6687 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6689 /* Automatic composition with glyph-string. */
6690 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6692 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6696 ptrdiff_t pos
= (it
->s
? -1
6697 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6698 : IT_CHARPOS (*it
));
6701 if (it
->what
== IT_CHARACTER
)
6702 c
= it
->char_to_display
;
6705 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6709 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6710 /* TAB in a composition means display glyphs with
6711 padding space on the left or right. */
6712 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6715 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6720 /* Is this character the last one of a run of characters with
6721 box? If yes, set IT->end_of_box_run_p to 1. */
6725 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6727 int face_id
= underlying_face_id (it
);
6728 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6732 if (face
->box
== FACE_NO_BOX
)
6734 /* If the box comes from face properties in a
6735 display string, check faces in that string. */
6736 int string_face_id
= face_after_it_pos (it
);
6737 it
->end_of_box_run_p
6738 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6741 /* Otherwise, the box comes from the underlying face.
6742 If this is the last string character displayed, check
6743 the next buffer location. */
6744 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6745 && (it
->current
.overlay_string_index
6746 == it
->n_overlay_strings
- 1))
6750 struct text_pos pos
= it
->current
.pos
;
6751 INC_TEXT_POS (pos
, it
->multibyte_p
);
6753 next_face_id
= face_at_buffer_position
6754 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6755 it
->region_end_charpos
, &ignore
,
6756 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6758 it
->end_of_box_run_p
6759 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6766 int face_id
= face_after_it_pos (it
);
6767 it
->end_of_box_run_p
6768 = (face_id
!= it
->face_id
6769 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6773 /* Value is 0 if end of buffer or string reached. */
6778 /* Move IT to the next display element.
6780 RESEAT_P non-zero means if called on a newline in buffer text,
6781 skip to the next visible line start.
6783 Functions get_next_display_element and set_iterator_to_next are
6784 separate because I find this arrangement easier to handle than a
6785 get_next_display_element function that also increments IT's
6786 position. The way it is we can first look at an iterator's current
6787 display element, decide whether it fits on a line, and if it does,
6788 increment the iterator position. The other way around we probably
6789 would either need a flag indicating whether the iterator has to be
6790 incremented the next time, or we would have to implement a
6791 decrement position function which would not be easy to write. */
6794 set_iterator_to_next (struct it
*it
, int reseat_p
)
6796 /* Reset flags indicating start and end of a sequence of characters
6797 with box. Reset them at the start of this function because
6798 moving the iterator to a new position might set them. */
6799 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6803 case GET_FROM_BUFFER
:
6804 /* The current display element of IT is a character from
6805 current_buffer. Advance in the buffer, and maybe skip over
6806 invisible lines that are so because of selective display. */
6807 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6808 reseat_at_next_visible_line_start (it
, 0);
6809 else if (it
->cmp_it
.id
>= 0)
6811 /* We are currently getting glyphs from a composition. */
6816 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6817 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6818 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6820 it
->cmp_it
.from
= it
->cmp_it
.to
;
6825 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6827 it
->end_charpos
, Qnil
);
6830 else if (! it
->cmp_it
.reversed_p
)
6832 /* Composition created while scanning forward. */
6833 /* Update IT's char/byte positions to point to the first
6834 character of the next grapheme cluster, or to the
6835 character visually after the current composition. */
6836 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6837 bidi_move_to_visually_next (&it
->bidi_it
);
6838 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6839 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6841 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6843 /* Proceed to the next grapheme cluster. */
6844 it
->cmp_it
.from
= it
->cmp_it
.to
;
6848 /* No more grapheme clusters in this composition.
6849 Find the next stop position. */
6850 ptrdiff_t stop
= it
->end_charpos
;
6851 if (it
->bidi_it
.scan_dir
< 0)
6852 /* Now we are scanning backward and don't know
6855 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6856 IT_BYTEPOS (*it
), stop
, Qnil
);
6861 /* Composition created while scanning backward. */
6862 /* Update IT's char/byte positions to point to the last
6863 character of the previous grapheme cluster, or the
6864 character visually after the current composition. */
6865 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6866 bidi_move_to_visually_next (&it
->bidi_it
);
6867 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6868 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6869 if (it
->cmp_it
.from
> 0)
6871 /* Proceed to the previous grapheme cluster. */
6872 it
->cmp_it
.to
= it
->cmp_it
.from
;
6876 /* No more grapheme clusters in this composition.
6877 Find the next stop position. */
6878 ptrdiff_t stop
= it
->end_charpos
;
6879 if (it
->bidi_it
.scan_dir
< 0)
6880 /* Now we are scanning backward and don't know
6883 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6884 IT_BYTEPOS (*it
), stop
, Qnil
);
6890 xassert (it
->len
!= 0);
6894 IT_BYTEPOS (*it
) += it
->len
;
6895 IT_CHARPOS (*it
) += 1;
6899 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6900 /* If this is a new paragraph, determine its base
6901 direction (a.k.a. its base embedding level). */
6902 if (it
->bidi_it
.new_paragraph
)
6903 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6904 bidi_move_to_visually_next (&it
->bidi_it
);
6905 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6906 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6907 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6909 /* As the scan direction was changed, we must
6910 re-compute the stop position for composition. */
6911 ptrdiff_t stop
= it
->end_charpos
;
6912 if (it
->bidi_it
.scan_dir
< 0)
6914 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6915 IT_BYTEPOS (*it
), stop
, Qnil
);
6918 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6922 case GET_FROM_C_STRING
:
6923 /* Current display element of IT is from a C string. */
6925 /* If the string position is beyond string's end, it means
6926 next_element_from_c_string is padding the string with
6927 blanks, in which case we bypass the bidi iterator,
6928 because it cannot deal with such virtual characters. */
6929 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6931 IT_BYTEPOS (*it
) += it
->len
;
6932 IT_CHARPOS (*it
) += 1;
6936 bidi_move_to_visually_next (&it
->bidi_it
);
6937 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6938 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6942 case GET_FROM_DISPLAY_VECTOR
:
6943 /* Current display element of IT is from a display table entry.
6944 Advance in the display table definition. Reset it to null if
6945 end reached, and continue with characters from buffers/
6947 ++it
->current
.dpvec_index
;
6949 /* Restore face of the iterator to what they were before the
6950 display vector entry (these entries may contain faces). */
6951 it
->face_id
= it
->saved_face_id
;
6953 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6955 int recheck_faces
= it
->ellipsis_p
;
6958 it
->method
= GET_FROM_C_STRING
;
6959 else if (STRINGP (it
->string
))
6960 it
->method
= GET_FROM_STRING
;
6963 it
->method
= GET_FROM_BUFFER
;
6964 it
->object
= it
->w
->buffer
;
6968 it
->current
.dpvec_index
= -1;
6970 /* Skip over characters which were displayed via IT->dpvec. */
6971 if (it
->dpvec_char_len
< 0)
6972 reseat_at_next_visible_line_start (it
, 1);
6973 else if (it
->dpvec_char_len
> 0)
6975 if (it
->method
== GET_FROM_STRING
6976 && it
->n_overlay_strings
> 0)
6977 it
->ignore_overlay_strings_at_pos_p
= 1;
6978 it
->len
= it
->dpvec_char_len
;
6979 set_iterator_to_next (it
, reseat_p
);
6982 /* Maybe recheck faces after display vector */
6984 it
->stop_charpos
= IT_CHARPOS (*it
);
6988 case GET_FROM_STRING
:
6989 /* Current display element is a character from a Lisp string. */
6990 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6991 if (it
->cmp_it
.id
>= 0)
6997 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6998 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6999 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7000 it
->cmp_it
.from
= it
->cmp_it
.to
;
7004 composition_compute_stop_pos (&it
->cmp_it
,
7005 IT_STRING_CHARPOS (*it
),
7006 IT_STRING_BYTEPOS (*it
),
7007 it
->end_charpos
, it
->string
);
7010 else if (! it
->cmp_it
.reversed_p
)
7012 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7013 bidi_move_to_visually_next (&it
->bidi_it
);
7014 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7015 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7017 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7018 it
->cmp_it
.from
= it
->cmp_it
.to
;
7021 ptrdiff_t stop
= it
->end_charpos
;
7022 if (it
->bidi_it
.scan_dir
< 0)
7024 composition_compute_stop_pos (&it
->cmp_it
,
7025 IT_STRING_CHARPOS (*it
),
7026 IT_STRING_BYTEPOS (*it
), stop
,
7032 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7033 bidi_move_to_visually_next (&it
->bidi_it
);
7034 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7035 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7036 if (it
->cmp_it
.from
> 0)
7037 it
->cmp_it
.to
= it
->cmp_it
.from
;
7040 ptrdiff_t stop
= it
->end_charpos
;
7041 if (it
->bidi_it
.scan_dir
< 0)
7043 composition_compute_stop_pos (&it
->cmp_it
,
7044 IT_STRING_CHARPOS (*it
),
7045 IT_STRING_BYTEPOS (*it
), stop
,
7053 /* If the string position is beyond string's end, it
7054 means next_element_from_string is padding the string
7055 with blanks, in which case we bypass the bidi
7056 iterator, because it cannot deal with such virtual
7058 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7060 IT_STRING_BYTEPOS (*it
) += it
->len
;
7061 IT_STRING_CHARPOS (*it
) += 1;
7065 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7067 bidi_move_to_visually_next (&it
->bidi_it
);
7068 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7069 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7070 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7072 ptrdiff_t stop
= it
->end_charpos
;
7074 if (it
->bidi_it
.scan_dir
< 0)
7076 composition_compute_stop_pos (&it
->cmp_it
,
7077 IT_STRING_CHARPOS (*it
),
7078 IT_STRING_BYTEPOS (*it
), stop
,
7084 consider_string_end
:
7086 if (it
->current
.overlay_string_index
>= 0)
7088 /* IT->string is an overlay string. Advance to the
7089 next, if there is one. */
7090 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7093 next_overlay_string (it
);
7095 setup_for_ellipsis (it
, 0);
7100 /* IT->string is not an overlay string. If we reached
7101 its end, and there is something on IT->stack, proceed
7102 with what is on the stack. This can be either another
7103 string, this time an overlay string, or a buffer. */
7104 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7108 if (it
->method
== GET_FROM_STRING
)
7109 goto consider_string_end
;
7114 case GET_FROM_IMAGE
:
7115 case GET_FROM_STRETCH
:
7116 /* The position etc with which we have to proceed are on
7117 the stack. The position may be at the end of a string,
7118 if the `display' property takes up the whole string. */
7119 xassert (it
->sp
> 0);
7121 if (it
->method
== GET_FROM_STRING
)
7122 goto consider_string_end
;
7126 /* There are no other methods defined, so this should be a bug. */
7130 xassert (it
->method
!= GET_FROM_STRING
7131 || (STRINGP (it
->string
)
7132 && IT_STRING_CHARPOS (*it
) >= 0));
7135 /* Load IT's display element fields with information about the next
7136 display element which comes from a display table entry or from the
7137 result of translating a control character to one of the forms `^C'
7140 IT->dpvec holds the glyphs to return as characters.
7141 IT->saved_face_id holds the face id before the display vector--it
7142 is restored into IT->face_id in set_iterator_to_next. */
7145 next_element_from_display_vector (struct it
*it
)
7150 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7152 it
->face_id
= it
->saved_face_id
;
7154 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7155 That seemed totally bogus - so I changed it... */
7156 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7158 if (GLYPH_CODE_P (gc
))
7160 it
->c
= GLYPH_CODE_CHAR (gc
);
7161 it
->len
= CHAR_BYTES (it
->c
);
7163 /* The entry may contain a face id to use. Such a face id is
7164 the id of a Lisp face, not a realized face. A face id of
7165 zero means no face is specified. */
7166 if (it
->dpvec_face_id
>= 0)
7167 it
->face_id
= it
->dpvec_face_id
;
7170 int lface_id
= GLYPH_CODE_FACE (gc
);
7172 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7177 /* Display table entry is invalid. Return a space. */
7178 it
->c
= ' ', it
->len
= 1;
7180 /* Don't change position and object of the iterator here. They are
7181 still the values of the character that had this display table
7182 entry or was translated, and that's what we want. */
7183 it
->what
= IT_CHARACTER
;
7187 /* Get the first element of string/buffer in the visual order, after
7188 being reseated to a new position in a string or a buffer. */
7190 get_visually_first_element (struct it
*it
)
7192 int string_p
= STRINGP (it
->string
) || it
->s
;
7193 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7194 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7196 if (STRINGP (it
->string
))
7198 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7199 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7203 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7204 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7207 if (it
->bidi_it
.charpos
== eob
)
7209 /* Nothing to do, but reset the FIRST_ELT flag, like
7210 bidi_paragraph_init does, because we are not going to
7212 it
->bidi_it
.first_elt
= 0;
7214 else if (it
->bidi_it
.charpos
== bob
7216 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7217 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7219 /* If we are at the beginning of a line/string, we can produce
7220 the next element right away. */
7221 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7222 bidi_move_to_visually_next (&it
->bidi_it
);
7226 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7228 /* We need to prime the bidi iterator starting at the line's or
7229 string's beginning, before we will be able to produce the
7232 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7235 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7237 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7239 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7242 /* Now return to buffer/string position where we were asked
7243 to get the next display element, and produce that. */
7244 bidi_move_to_visually_next (&it
->bidi_it
);
7246 while (it
->bidi_it
.bytepos
!= orig_bytepos
7247 && it
->bidi_it
.charpos
< eob
);
7250 /* Adjust IT's position information to where we ended up. */
7251 if (STRINGP (it
->string
))
7253 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7254 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7258 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7259 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7262 if (STRINGP (it
->string
) || !it
->s
)
7264 ptrdiff_t stop
, charpos
, bytepos
;
7266 if (STRINGP (it
->string
))
7269 stop
= SCHARS (it
->string
);
7270 if (stop
> it
->end_charpos
)
7271 stop
= it
->end_charpos
;
7272 charpos
= IT_STRING_CHARPOS (*it
);
7273 bytepos
= IT_STRING_BYTEPOS (*it
);
7277 stop
= it
->end_charpos
;
7278 charpos
= IT_CHARPOS (*it
);
7279 bytepos
= IT_BYTEPOS (*it
);
7281 if (it
->bidi_it
.scan_dir
< 0)
7283 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7288 /* Load IT with the next display element from Lisp string IT->string.
7289 IT->current.string_pos is the current position within the string.
7290 If IT->current.overlay_string_index >= 0, the Lisp string is an
7294 next_element_from_string (struct it
*it
)
7296 struct text_pos position
;
7298 xassert (STRINGP (it
->string
));
7299 xassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7300 xassert (IT_STRING_CHARPOS (*it
) >= 0);
7301 position
= it
->current
.string_pos
;
7303 /* With bidi reordering, the character to display might not be the
7304 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7305 that we were reseat()ed to a new string, whose paragraph
7306 direction is not known. */
7307 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7309 get_visually_first_element (it
);
7310 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7313 /* Time to check for invisible text? */
7314 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7316 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7319 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7320 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7322 /* With bidi non-linear iteration, we could find
7323 ourselves far beyond the last computed stop_charpos,
7324 with several other stop positions in between that we
7325 missed. Scan them all now, in buffer's logical
7326 order, until we find and handle the last stop_charpos
7327 that precedes our current position. */
7328 handle_stop_backwards (it
, it
->stop_charpos
);
7329 return GET_NEXT_DISPLAY_ELEMENT (it
);
7335 /* Take note of the stop position we just moved
7336 across, for when we will move back across it. */
7337 it
->prev_stop
= it
->stop_charpos
;
7338 /* If we are at base paragraph embedding level, take
7339 note of the last stop position seen at this
7341 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7342 it
->base_level_stop
= it
->stop_charpos
;
7346 /* Since a handler may have changed IT->method, we must
7348 return GET_NEXT_DISPLAY_ELEMENT (it
);
7352 /* If we are before prev_stop, we may have overstepped
7353 on our way backwards a stop_pos, and if so, we need
7354 to handle that stop_pos. */
7355 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7356 /* We can sometimes back up for reasons that have nothing
7357 to do with bidi reordering. E.g., compositions. The
7358 code below is only needed when we are above the base
7359 embedding level, so test for that explicitly. */
7360 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7362 /* If we lost track of base_level_stop, we have no better
7363 place for handle_stop_backwards to start from than string
7364 beginning. This happens, e.g., when we were reseated to
7365 the previous screenful of text by vertical-motion. */
7366 if (it
->base_level_stop
<= 0
7367 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7368 it
->base_level_stop
= 0;
7369 handle_stop_backwards (it
, it
->base_level_stop
);
7370 return GET_NEXT_DISPLAY_ELEMENT (it
);
7374 if (it
->current
.overlay_string_index
>= 0)
7376 /* Get the next character from an overlay string. In overlay
7377 strings, there is no field width or padding with spaces to
7379 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7384 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7385 IT_STRING_BYTEPOS (*it
),
7386 it
->bidi_it
.scan_dir
< 0
7388 : SCHARS (it
->string
))
7389 && next_element_from_composition (it
))
7393 else if (STRING_MULTIBYTE (it
->string
))
7395 const unsigned char *s
= (SDATA (it
->string
)
7396 + IT_STRING_BYTEPOS (*it
));
7397 it
->c
= string_char_and_length (s
, &it
->len
);
7401 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7407 /* Get the next character from a Lisp string that is not an
7408 overlay string. Such strings come from the mode line, for
7409 example. We may have to pad with spaces, or truncate the
7410 string. See also next_element_from_c_string. */
7411 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7416 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7418 /* Pad with spaces. */
7419 it
->c
= ' ', it
->len
= 1;
7420 CHARPOS (position
) = BYTEPOS (position
) = -1;
7422 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7423 IT_STRING_BYTEPOS (*it
),
7424 it
->bidi_it
.scan_dir
< 0
7426 : it
->string_nchars
)
7427 && next_element_from_composition (it
))
7431 else if (STRING_MULTIBYTE (it
->string
))
7433 const unsigned char *s
= (SDATA (it
->string
)
7434 + IT_STRING_BYTEPOS (*it
));
7435 it
->c
= string_char_and_length (s
, &it
->len
);
7439 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7444 /* Record what we have and where it came from. */
7445 it
->what
= IT_CHARACTER
;
7446 it
->object
= it
->string
;
7447 it
->position
= position
;
7452 /* Load IT with next display element from C string IT->s.
7453 IT->string_nchars is the maximum number of characters to return
7454 from the string. IT->end_charpos may be greater than
7455 IT->string_nchars when this function is called, in which case we
7456 may have to return padding spaces. Value is zero if end of string
7457 reached, including padding spaces. */
7460 next_element_from_c_string (struct it
*it
)
7465 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7466 it
->what
= IT_CHARACTER
;
7467 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7470 /* With bidi reordering, the character to display might not be the
7471 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7472 we were reseated to a new string, whose paragraph direction is
7474 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7475 get_visually_first_element (it
);
7477 /* IT's position can be greater than IT->string_nchars in case a
7478 field width or precision has been specified when the iterator was
7480 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7482 /* End of the game. */
7486 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7488 /* Pad with spaces. */
7489 it
->c
= ' ', it
->len
= 1;
7490 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7492 else if (it
->multibyte_p
)
7493 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7495 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7501 /* Set up IT to return characters from an ellipsis, if appropriate.
7502 The definition of the ellipsis glyphs may come from a display table
7503 entry. This function fills IT with the first glyph from the
7504 ellipsis if an ellipsis is to be displayed. */
7507 next_element_from_ellipsis (struct it
*it
)
7509 if (it
->selective_display_ellipsis_p
)
7510 setup_for_ellipsis (it
, it
->len
);
7513 /* The face at the current position may be different from the
7514 face we find after the invisible text. Remember what it
7515 was in IT->saved_face_id, and signal that it's there by
7516 setting face_before_selective_p. */
7517 it
->saved_face_id
= it
->face_id
;
7518 it
->method
= GET_FROM_BUFFER
;
7519 it
->object
= it
->w
->buffer
;
7520 reseat_at_next_visible_line_start (it
, 1);
7521 it
->face_before_selective_p
= 1;
7524 return GET_NEXT_DISPLAY_ELEMENT (it
);
7528 /* Deliver an image display element. The iterator IT is already
7529 filled with image information (done in handle_display_prop). Value
7534 next_element_from_image (struct it
*it
)
7536 it
->what
= IT_IMAGE
;
7537 it
->ignore_overlay_strings_at_pos_p
= 0;
7542 /* Fill iterator IT with next display element from a stretch glyph
7543 property. IT->object is the value of the text property. Value is
7547 next_element_from_stretch (struct it
*it
)
7549 it
->what
= IT_STRETCH
;
7553 /* Scan backwards from IT's current position until we find a stop
7554 position, or until BEGV. This is called when we find ourself
7555 before both the last known prev_stop and base_level_stop while
7556 reordering bidirectional text. */
7559 compute_stop_pos_backwards (struct it
*it
)
7561 const int SCAN_BACK_LIMIT
= 1000;
7562 struct text_pos pos
;
7563 struct display_pos save_current
= it
->current
;
7564 struct text_pos save_position
= it
->position
;
7565 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7566 ptrdiff_t where_we_are
= charpos
;
7567 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7568 ptrdiff_t save_end_pos
= it
->end_charpos
;
7570 xassert (NILP (it
->string
) && !it
->s
);
7571 xassert (it
->bidi_p
);
7575 it
->end_charpos
= min (charpos
+ 1, ZV
);
7576 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7577 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7578 reseat_1 (it
, pos
, 0);
7579 compute_stop_pos (it
);
7580 /* We must advance forward, right? */
7581 if (it
->stop_charpos
<= charpos
)
7584 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7586 if (it
->stop_charpos
<= where_we_are
)
7587 it
->prev_stop
= it
->stop_charpos
;
7589 it
->prev_stop
= BEGV
;
7591 it
->current
= save_current
;
7592 it
->position
= save_position
;
7593 it
->stop_charpos
= save_stop_pos
;
7594 it
->end_charpos
= save_end_pos
;
7597 /* Scan forward from CHARPOS in the current buffer/string, until we
7598 find a stop position > current IT's position. Then handle the stop
7599 position before that. This is called when we bump into a stop
7600 position while reordering bidirectional text. CHARPOS should be
7601 the last previously processed stop_pos (or BEGV/0, if none were
7602 processed yet) whose position is less that IT's current
7606 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7608 int bufp
= !STRINGP (it
->string
);
7609 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7610 struct display_pos save_current
= it
->current
;
7611 struct text_pos save_position
= it
->position
;
7612 struct text_pos pos1
;
7613 ptrdiff_t next_stop
;
7615 /* Scan in strict logical order. */
7616 xassert (it
->bidi_p
);
7620 it
->prev_stop
= charpos
;
7623 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7624 reseat_1 (it
, pos1
, 0);
7627 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7628 compute_stop_pos (it
);
7629 /* We must advance forward, right? */
7630 if (it
->stop_charpos
<= it
->prev_stop
)
7632 charpos
= it
->stop_charpos
;
7634 while (charpos
<= where_we_are
);
7637 it
->current
= save_current
;
7638 it
->position
= save_position
;
7639 next_stop
= it
->stop_charpos
;
7640 it
->stop_charpos
= it
->prev_stop
;
7642 it
->stop_charpos
= next_stop
;
7645 /* Load IT with the next display element from current_buffer. Value
7646 is zero if end of buffer reached. IT->stop_charpos is the next
7647 position at which to stop and check for text properties or buffer
7651 next_element_from_buffer (struct it
*it
)
7655 xassert (IT_CHARPOS (*it
) >= BEGV
);
7656 xassert (NILP (it
->string
) && !it
->s
);
7657 xassert (!it
->bidi_p
7658 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7659 && it
->bidi_it
.string
.s
== NULL
));
7661 /* With bidi reordering, the character to display might not be the
7662 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7663 we were reseat()ed to a new buffer position, which is potentially
7664 a different paragraph. */
7665 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7667 get_visually_first_element (it
);
7668 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7671 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7673 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7675 int overlay_strings_follow_p
;
7677 /* End of the game, except when overlay strings follow that
7678 haven't been returned yet. */
7679 if (it
->overlay_strings_at_end_processed_p
)
7680 overlay_strings_follow_p
= 0;
7683 it
->overlay_strings_at_end_processed_p
= 1;
7684 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7687 if (overlay_strings_follow_p
)
7688 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7692 it
->position
= it
->current
.pos
;
7696 else if (!(!it
->bidi_p
7697 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7698 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7700 /* With bidi non-linear iteration, we could find ourselves
7701 far beyond the last computed stop_charpos, with several
7702 other stop positions in between that we missed. Scan
7703 them all now, in buffer's logical order, until we find
7704 and handle the last stop_charpos that precedes our
7705 current position. */
7706 handle_stop_backwards (it
, it
->stop_charpos
);
7707 return GET_NEXT_DISPLAY_ELEMENT (it
);
7713 /* Take note of the stop position we just moved across,
7714 for when we will move back across it. */
7715 it
->prev_stop
= it
->stop_charpos
;
7716 /* If we are at base paragraph embedding level, take
7717 note of the last stop position seen at this
7719 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7720 it
->base_level_stop
= it
->stop_charpos
;
7723 return GET_NEXT_DISPLAY_ELEMENT (it
);
7727 /* If we are before prev_stop, we may have overstepped on
7728 our way backwards a stop_pos, and if so, we need to
7729 handle that stop_pos. */
7730 && IT_CHARPOS (*it
) < it
->prev_stop
7731 /* We can sometimes back up for reasons that have nothing
7732 to do with bidi reordering. E.g., compositions. The
7733 code below is only needed when we are above the base
7734 embedding level, so test for that explicitly. */
7735 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7737 if (it
->base_level_stop
<= 0
7738 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7740 /* If we lost track of base_level_stop, we need to find
7741 prev_stop by looking backwards. This happens, e.g., when
7742 we were reseated to the previous screenful of text by
7744 it
->base_level_stop
= BEGV
;
7745 compute_stop_pos_backwards (it
);
7746 handle_stop_backwards (it
, it
->prev_stop
);
7749 handle_stop_backwards (it
, it
->base_level_stop
);
7750 return GET_NEXT_DISPLAY_ELEMENT (it
);
7754 /* No face changes, overlays etc. in sight, so just return a
7755 character from current_buffer. */
7759 /* Maybe run the redisplay end trigger hook. Performance note:
7760 This doesn't seem to cost measurable time. */
7761 if (it
->redisplay_end_trigger_charpos
7763 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7764 run_redisplay_end_trigger_hook (it
);
7766 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7767 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7769 && next_element_from_composition (it
))
7774 /* Get the next character, maybe multibyte. */
7775 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7776 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7777 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7779 it
->c
= *p
, it
->len
= 1;
7781 /* Record what we have and where it came from. */
7782 it
->what
= IT_CHARACTER
;
7783 it
->object
= it
->w
->buffer
;
7784 it
->position
= it
->current
.pos
;
7786 /* Normally we return the character found above, except when we
7787 really want to return an ellipsis for selective display. */
7792 /* A value of selective > 0 means hide lines indented more
7793 than that number of columns. */
7794 if (it
->selective
> 0
7795 && IT_CHARPOS (*it
) + 1 < ZV
7796 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7797 IT_BYTEPOS (*it
) + 1,
7800 success_p
= next_element_from_ellipsis (it
);
7801 it
->dpvec_char_len
= -1;
7804 else if (it
->c
== '\r' && it
->selective
== -1)
7806 /* A value of selective == -1 means that everything from the
7807 CR to the end of the line is invisible, with maybe an
7808 ellipsis displayed for it. */
7809 success_p
= next_element_from_ellipsis (it
);
7810 it
->dpvec_char_len
= -1;
7815 /* Value is zero if end of buffer reached. */
7816 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7821 /* Run the redisplay end trigger hook for IT. */
7824 run_redisplay_end_trigger_hook (struct it
*it
)
7826 Lisp_Object args
[3];
7828 /* IT->glyph_row should be non-null, i.e. we should be actually
7829 displaying something, or otherwise we should not run the hook. */
7830 xassert (it
->glyph_row
);
7832 /* Set up hook arguments. */
7833 args
[0] = Qredisplay_end_trigger_functions
;
7834 args
[1] = it
->window
;
7835 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7836 it
->redisplay_end_trigger_charpos
= 0;
7838 /* Since we are *trying* to run these functions, don't try to run
7839 them again, even if they get an error. */
7840 it
->w
->redisplay_end_trigger
= Qnil
;
7841 Frun_hook_with_args (3, args
);
7843 /* Notice if it changed the face of the character we are on. */
7844 handle_face_prop (it
);
7848 /* Deliver a composition display element. Unlike the other
7849 next_element_from_XXX, this function is not registered in the array
7850 get_next_element[]. It is called from next_element_from_buffer and
7851 next_element_from_string when necessary. */
7854 next_element_from_composition (struct it
*it
)
7856 it
->what
= IT_COMPOSITION
;
7857 it
->len
= it
->cmp_it
.nbytes
;
7858 if (STRINGP (it
->string
))
7862 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7863 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7866 it
->position
= it
->current
.string_pos
;
7867 it
->object
= it
->string
;
7868 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7869 IT_STRING_BYTEPOS (*it
), it
->string
);
7875 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7876 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7879 if (it
->bidi_it
.new_paragraph
)
7880 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7881 /* Resync the bidi iterator with IT's new position.
7882 FIXME: this doesn't support bidirectional text. */
7883 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7884 bidi_move_to_visually_next (&it
->bidi_it
);
7888 it
->position
= it
->current
.pos
;
7889 it
->object
= it
->w
->buffer
;
7890 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7891 IT_BYTEPOS (*it
), Qnil
);
7898 /***********************************************************************
7899 Moving an iterator without producing glyphs
7900 ***********************************************************************/
7902 /* Check if iterator is at a position corresponding to a valid buffer
7903 position after some move_it_ call. */
7905 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7906 ((it)->method == GET_FROM_STRING \
7907 ? IT_STRING_CHARPOS (*it) == 0 \
7911 /* Move iterator IT to a specified buffer or X position within one
7912 line on the display without producing glyphs.
7914 OP should be a bit mask including some or all of these bits:
7915 MOVE_TO_X: Stop upon reaching x-position TO_X.
7916 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7917 Regardless of OP's value, stop upon reaching the end of the display line.
7919 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7920 This means, in particular, that TO_X includes window's horizontal
7923 The return value has several possible values that
7924 say what condition caused the scan to stop:
7926 MOVE_POS_MATCH_OR_ZV
7927 - when TO_POS or ZV was reached.
7930 -when TO_X was reached before TO_POS or ZV were reached.
7933 - when we reached the end of the display area and the line must
7937 - when we reached the end of the display area and the line is
7941 - when we stopped at a line end, i.e. a newline or a CR and selective
7944 static enum move_it_result
7945 move_it_in_display_line_to (struct it
*it
,
7946 ptrdiff_t to_charpos
, int to_x
,
7947 enum move_operation_enum op
)
7949 enum move_it_result result
= MOVE_UNDEFINED
;
7950 struct glyph_row
*saved_glyph_row
;
7951 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
7952 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
7953 void *ppos_data
= NULL
;
7955 enum it_method prev_method
= it
->method
;
7956 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
7957 int saw_smaller_pos
= prev_pos
< to_charpos
;
7959 /* Don't produce glyphs in produce_glyphs. */
7960 saved_glyph_row
= it
->glyph_row
;
7961 it
->glyph_row
= NULL
;
7963 /* Use wrap_it to save a copy of IT wherever a word wrap could
7964 occur. Use atpos_it to save a copy of IT at the desired buffer
7965 position, if found, so that we can scan ahead and check if the
7966 word later overshoots the window edge. Use atx_it similarly, for
7972 /* Use ppos_it under bidi reordering to save a copy of IT for the
7973 position > CHARPOS that is the closest to CHARPOS. We restore
7974 that position in IT when we have scanned the entire display line
7975 without finding a match for CHARPOS and all the character
7976 positions are greater than CHARPOS. */
7979 SAVE_IT (ppos_it
, *it
, ppos_data
);
7980 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
7981 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
7982 SAVE_IT (ppos_it
, *it
, ppos_data
);
7985 #define BUFFER_POS_REACHED_P() \
7986 ((op & MOVE_TO_POS) != 0 \
7987 && BUFFERP (it->object) \
7988 && (IT_CHARPOS (*it) == to_charpos \
7990 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
7991 && IT_CHARPOS (*it) > to_charpos) \
7992 || (it->what == IT_COMPOSITION \
7993 && ((IT_CHARPOS (*it) > to_charpos \
7994 && to_charpos >= it->cmp_it.charpos) \
7995 || (IT_CHARPOS (*it) < to_charpos \
7996 && to_charpos <= it->cmp_it.charpos)))) \
7997 && (it->method == GET_FROM_BUFFER \
7998 || (it->method == GET_FROM_DISPLAY_VECTOR \
7999 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8001 /* If there's a line-/wrap-prefix, handle it. */
8002 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8003 && it
->current_y
< it
->last_visible_y
)
8004 handle_line_prefix (it
);
8006 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8007 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8011 int x
, i
, ascent
= 0, descent
= 0;
8013 /* Utility macro to reset an iterator with x, ascent, and descent. */
8014 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8015 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8016 (IT)->max_descent = descent)
8018 /* Stop if we move beyond TO_CHARPOS (after an image or a
8019 display string or stretch glyph). */
8020 if ((op
& MOVE_TO_POS
) != 0
8021 && BUFFERP (it
->object
)
8022 && it
->method
== GET_FROM_BUFFER
8024 /* When the iterator is at base embedding level, we
8025 are guaranteed that characters are delivered for
8026 display in strictly increasing order of their
8027 buffer positions. */
8028 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8029 && IT_CHARPOS (*it
) > to_charpos
)
8031 && (prev_method
== GET_FROM_IMAGE
8032 || prev_method
== GET_FROM_STRETCH
8033 || prev_method
== GET_FROM_STRING
)
8034 /* Passed TO_CHARPOS from left to right. */
8035 && ((prev_pos
< to_charpos
8036 && IT_CHARPOS (*it
) > to_charpos
)
8037 /* Passed TO_CHARPOS from right to left. */
8038 || (prev_pos
> to_charpos
8039 && IT_CHARPOS (*it
) < to_charpos
)))))
8041 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8043 result
= MOVE_POS_MATCH_OR_ZV
;
8046 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8047 /* If wrap_it is valid, the current position might be in a
8048 word that is wrapped. So, save the iterator in
8049 atpos_it and continue to see if wrapping happens. */
8050 SAVE_IT (atpos_it
, *it
, atpos_data
);
8053 /* Stop when ZV reached.
8054 We used to stop here when TO_CHARPOS reached as well, but that is
8055 too soon if this glyph does not fit on this line. So we handle it
8056 explicitly below. */
8057 if (!get_next_display_element (it
))
8059 result
= MOVE_POS_MATCH_OR_ZV
;
8063 if (it
->line_wrap
== TRUNCATE
)
8065 if (BUFFER_POS_REACHED_P ())
8067 result
= MOVE_POS_MATCH_OR_ZV
;
8073 if (it
->line_wrap
== WORD_WRAP
)
8075 if (IT_DISPLAYING_WHITESPACE (it
))
8079 /* We have reached a glyph that follows one or more
8080 whitespace characters. If the position is
8081 already found, we are done. */
8082 if (atpos_it
.sp
>= 0)
8084 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8085 result
= MOVE_POS_MATCH_OR_ZV
;
8090 RESTORE_IT (it
, &atx_it
, atx_data
);
8091 result
= MOVE_X_REACHED
;
8094 /* Otherwise, we can wrap here. */
8095 SAVE_IT (wrap_it
, *it
, wrap_data
);
8101 /* Remember the line height for the current line, in case
8102 the next element doesn't fit on the line. */
8103 ascent
= it
->max_ascent
;
8104 descent
= it
->max_descent
;
8106 /* The call to produce_glyphs will get the metrics of the
8107 display element IT is loaded with. Record the x-position
8108 before this display element, in case it doesn't fit on the
8112 PRODUCE_GLYPHS (it
);
8114 if (it
->area
!= TEXT_AREA
)
8116 prev_method
= it
->method
;
8117 if (it
->method
== GET_FROM_BUFFER
)
8118 prev_pos
= IT_CHARPOS (*it
);
8119 set_iterator_to_next (it
, 1);
8120 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8121 SET_TEXT_POS (this_line_min_pos
,
8122 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8124 && (op
& MOVE_TO_POS
)
8125 && IT_CHARPOS (*it
) > to_charpos
8126 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8127 SAVE_IT (ppos_it
, *it
, ppos_data
);
8131 /* The number of glyphs we get back in IT->nglyphs will normally
8132 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8133 character on a terminal frame, or (iii) a line end. For the
8134 second case, IT->nglyphs - 1 padding glyphs will be present.
8135 (On X frames, there is only one glyph produced for a
8136 composite character.)
8138 The behavior implemented below means, for continuation lines,
8139 that as many spaces of a TAB as fit on the current line are
8140 displayed there. For terminal frames, as many glyphs of a
8141 multi-glyph character are displayed in the current line, too.
8142 This is what the old redisplay code did, and we keep it that
8143 way. Under X, the whole shape of a complex character must
8144 fit on the line or it will be completely displayed in the
8147 Note that both for tabs and padding glyphs, all glyphs have
8151 /* More than one glyph or glyph doesn't fit on line. All
8152 glyphs have the same width. */
8153 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8155 int x_before_this_char
= x
;
8156 int hpos_before_this_char
= it
->hpos
;
8158 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8160 new_x
= x
+ single_glyph_width
;
8162 /* We want to leave anything reaching TO_X to the caller. */
8163 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8165 if (BUFFER_POS_REACHED_P ())
8167 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8168 goto buffer_pos_reached
;
8169 if (atpos_it
.sp
< 0)
8171 SAVE_IT (atpos_it
, *it
, atpos_data
);
8172 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8177 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8180 result
= MOVE_X_REACHED
;
8185 SAVE_IT (atx_it
, *it
, atx_data
);
8186 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8191 if (/* Lines are continued. */
8192 it
->line_wrap
!= TRUNCATE
8193 && (/* And glyph doesn't fit on the line. */
8194 new_x
> it
->last_visible_x
8195 /* Or it fits exactly and we're on a window
8197 || (new_x
== it
->last_visible_x
8198 && FRAME_WINDOW_P (it
->f
))))
8200 if (/* IT->hpos == 0 means the very first glyph
8201 doesn't fit on the line, e.g. a wide image. */
8203 || (new_x
== it
->last_visible_x
8204 && FRAME_WINDOW_P (it
->f
)))
8207 it
->current_x
= new_x
;
8209 /* The character's last glyph just barely fits
8211 if (i
== it
->nglyphs
- 1)
8213 /* If this is the destination position,
8214 return a position *before* it in this row,
8215 now that we know it fits in this row. */
8216 if (BUFFER_POS_REACHED_P ())
8218 if (it
->line_wrap
!= WORD_WRAP
8221 it
->hpos
= hpos_before_this_char
;
8222 it
->current_x
= x_before_this_char
;
8223 result
= MOVE_POS_MATCH_OR_ZV
;
8226 if (it
->line_wrap
== WORD_WRAP
8229 SAVE_IT (atpos_it
, *it
, atpos_data
);
8230 atpos_it
.current_x
= x_before_this_char
;
8231 atpos_it
.hpos
= hpos_before_this_char
;
8235 prev_method
= it
->method
;
8236 if (it
->method
== GET_FROM_BUFFER
)
8237 prev_pos
= IT_CHARPOS (*it
);
8238 set_iterator_to_next (it
, 1);
8239 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8240 SET_TEXT_POS (this_line_min_pos
,
8241 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8242 /* On graphical terminals, newlines may
8243 "overflow" into the fringe if
8244 overflow-newline-into-fringe is non-nil.
8245 On text-only terminals, newlines may
8246 overflow into the last glyph on the
8248 if (!FRAME_WINDOW_P (it
->f
)
8249 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8251 if (!get_next_display_element (it
))
8253 result
= MOVE_POS_MATCH_OR_ZV
;
8256 if (BUFFER_POS_REACHED_P ())
8258 if (ITERATOR_AT_END_OF_LINE_P (it
))
8259 result
= MOVE_POS_MATCH_OR_ZV
;
8261 result
= MOVE_LINE_CONTINUED
;
8264 if (ITERATOR_AT_END_OF_LINE_P (it
))
8266 result
= MOVE_NEWLINE_OR_CR
;
8273 IT_RESET_X_ASCENT_DESCENT (it
);
8275 if (wrap_it
.sp
>= 0)
8277 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8282 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8284 result
= MOVE_LINE_CONTINUED
;
8288 if (BUFFER_POS_REACHED_P ())
8290 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8291 goto buffer_pos_reached
;
8292 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8294 SAVE_IT (atpos_it
, *it
, atpos_data
);
8295 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8299 if (new_x
> it
->first_visible_x
)
8301 /* Glyph is visible. Increment number of glyphs that
8302 would be displayed. */
8307 if (result
!= MOVE_UNDEFINED
)
8310 else if (BUFFER_POS_REACHED_P ())
8313 IT_RESET_X_ASCENT_DESCENT (it
);
8314 result
= MOVE_POS_MATCH_OR_ZV
;
8317 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8319 /* Stop when TO_X specified and reached. This check is
8320 necessary here because of lines consisting of a line end,
8321 only. The line end will not produce any glyphs and we
8322 would never get MOVE_X_REACHED. */
8323 xassert (it
->nglyphs
== 0);
8324 result
= MOVE_X_REACHED
;
8328 /* Is this a line end? If yes, we're done. */
8329 if (ITERATOR_AT_END_OF_LINE_P (it
))
8331 /* If we are past TO_CHARPOS, but never saw any character
8332 positions smaller than TO_CHARPOS, return
8333 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8335 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8337 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8339 if (IT_CHARPOS (ppos_it
) < ZV
)
8341 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8342 result
= MOVE_POS_MATCH_OR_ZV
;
8345 goto buffer_pos_reached
;
8347 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8348 && IT_CHARPOS (*it
) > to_charpos
)
8349 goto buffer_pos_reached
;
8351 result
= MOVE_NEWLINE_OR_CR
;
8354 result
= MOVE_NEWLINE_OR_CR
;
8358 prev_method
= it
->method
;
8359 if (it
->method
== GET_FROM_BUFFER
)
8360 prev_pos
= IT_CHARPOS (*it
);
8361 /* The current display element has been consumed. Advance
8363 set_iterator_to_next (it
, 1);
8364 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8365 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8366 if (IT_CHARPOS (*it
) < to_charpos
)
8367 saw_smaller_pos
= 1;
8369 && (op
& MOVE_TO_POS
)
8370 && IT_CHARPOS (*it
) >= to_charpos
8371 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8372 SAVE_IT (ppos_it
, *it
, ppos_data
);
8374 /* Stop if lines are truncated and IT's current x-position is
8375 past the right edge of the window now. */
8376 if (it
->line_wrap
== TRUNCATE
8377 && it
->current_x
>= it
->last_visible_x
)
8379 if (!FRAME_WINDOW_P (it
->f
)
8380 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8384 if ((at_eob_p
= !get_next_display_element (it
))
8385 || BUFFER_POS_REACHED_P ()
8386 /* If we are past TO_CHARPOS, but never saw any
8387 character positions smaller than TO_CHARPOS,
8388 return MOVE_POS_MATCH_OR_ZV, like the
8389 unidirectional display did. */
8390 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8392 && IT_CHARPOS (*it
) > to_charpos
))
8395 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8396 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8397 result
= MOVE_POS_MATCH_OR_ZV
;
8400 if (ITERATOR_AT_END_OF_LINE_P (it
))
8402 result
= MOVE_NEWLINE_OR_CR
;
8406 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8408 && IT_CHARPOS (*it
) > to_charpos
)
8410 if (IT_CHARPOS (ppos_it
) < ZV
)
8411 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8412 result
= MOVE_POS_MATCH_OR_ZV
;
8415 result
= MOVE_LINE_TRUNCATED
;
8418 #undef IT_RESET_X_ASCENT_DESCENT
8421 #undef BUFFER_POS_REACHED_P
8423 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8424 restore the saved iterator. */
8425 if (atpos_it
.sp
>= 0)
8426 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8427 else if (atx_it
.sp
>= 0)
8428 RESTORE_IT (it
, &atx_it
, atx_data
);
8433 bidi_unshelve_cache (atpos_data
, 1);
8435 bidi_unshelve_cache (atx_data
, 1);
8437 bidi_unshelve_cache (wrap_data
, 1);
8439 bidi_unshelve_cache (ppos_data
, 1);
8441 /* Restore the iterator settings altered at the beginning of this
8443 it
->glyph_row
= saved_glyph_row
;
8447 /* For external use. */
8449 move_it_in_display_line (struct it
*it
,
8450 ptrdiff_t to_charpos
, int to_x
,
8451 enum move_operation_enum op
)
8453 if (it
->line_wrap
== WORD_WRAP
8454 && (op
& MOVE_TO_X
))
8457 void *save_data
= NULL
;
8460 SAVE_IT (save_it
, *it
, save_data
);
8461 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8462 /* When word-wrap is on, TO_X may lie past the end
8463 of a wrapped line. Then it->current is the
8464 character on the next line, so backtrack to the
8465 space before the wrap point. */
8466 if (skip
== MOVE_LINE_CONTINUED
)
8468 int prev_x
= max (it
->current_x
- 1, 0);
8469 RESTORE_IT (it
, &save_it
, save_data
);
8470 move_it_in_display_line_to
8471 (it
, -1, prev_x
, MOVE_TO_X
);
8474 bidi_unshelve_cache (save_data
, 1);
8477 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8481 /* Move IT forward until it satisfies one or more of the criteria in
8482 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8484 OP is a bit-mask that specifies where to stop, and in particular,
8485 which of those four position arguments makes a difference. See the
8486 description of enum move_operation_enum.
8488 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8489 screen line, this function will set IT to the next position that is
8490 displayed to the right of TO_CHARPOS on the screen. */
8493 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8495 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8496 int line_height
, line_start_x
= 0, reached
= 0;
8497 void *backup_data
= NULL
;
8501 if (op
& MOVE_TO_VPOS
)
8503 /* If no TO_CHARPOS and no TO_X specified, stop at the
8504 start of the line TO_VPOS. */
8505 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8507 if (it
->vpos
== to_vpos
)
8513 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8517 /* TO_VPOS >= 0 means stop at TO_X in the line at
8518 TO_VPOS, or at TO_POS, whichever comes first. */
8519 if (it
->vpos
== to_vpos
)
8525 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8527 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8532 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8534 /* We have reached TO_X but not in the line we want. */
8535 skip
= move_it_in_display_line_to (it
, to_charpos
,
8537 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8545 else if (op
& MOVE_TO_Y
)
8547 struct it it_backup
;
8549 if (it
->line_wrap
== WORD_WRAP
)
8550 SAVE_IT (it_backup
, *it
, backup_data
);
8552 /* TO_Y specified means stop at TO_X in the line containing
8553 TO_Y---or at TO_CHARPOS if this is reached first. The
8554 problem is that we can't really tell whether the line
8555 contains TO_Y before we have completely scanned it, and
8556 this may skip past TO_X. What we do is to first scan to
8559 If TO_X is not specified, use a TO_X of zero. The reason
8560 is to make the outcome of this function more predictable.
8561 If we didn't use TO_X == 0, we would stop at the end of
8562 the line which is probably not what a caller would expect
8564 skip
= move_it_in_display_line_to
8565 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8566 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8568 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8569 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8571 else if (skip
== MOVE_X_REACHED
)
8573 /* If TO_X was reached, we want to know whether TO_Y is
8574 in the line. We know this is the case if the already
8575 scanned glyphs make the line tall enough. Otherwise,
8576 we must check by scanning the rest of the line. */
8577 line_height
= it
->max_ascent
+ it
->max_descent
;
8578 if (to_y
>= it
->current_y
8579 && to_y
< it
->current_y
+ line_height
)
8584 SAVE_IT (it_backup
, *it
, backup_data
);
8585 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8586 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8588 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8589 line_height
= it
->max_ascent
+ it
->max_descent
;
8590 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8592 if (to_y
>= it
->current_y
8593 && to_y
< it
->current_y
+ line_height
)
8595 /* If TO_Y is in this line and TO_X was reached
8596 above, we scanned too far. We have to restore
8597 IT's settings to the ones before skipping. */
8598 RESTORE_IT (it
, &it_backup
, backup_data
);
8604 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8610 /* Check whether TO_Y is in this line. */
8611 line_height
= it
->max_ascent
+ it
->max_descent
;
8612 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8614 if (to_y
>= it
->current_y
8615 && to_y
< it
->current_y
+ line_height
)
8617 /* When word-wrap is on, TO_X may lie past the end
8618 of a wrapped line. Then it->current is the
8619 character on the next line, so backtrack to the
8620 space before the wrap point. */
8621 if (skip
== MOVE_LINE_CONTINUED
8622 && it
->line_wrap
== WORD_WRAP
)
8624 int prev_x
= max (it
->current_x
- 1, 0);
8625 RESTORE_IT (it
, &it_backup
, backup_data
);
8626 skip
= move_it_in_display_line_to
8627 (it
, -1, prev_x
, MOVE_TO_X
);
8636 else if (BUFFERP (it
->object
)
8637 && (it
->method
== GET_FROM_BUFFER
8638 || it
->method
== GET_FROM_STRETCH
)
8639 && IT_CHARPOS (*it
) >= to_charpos
8640 /* Under bidi iteration, a call to set_iterator_to_next
8641 can scan far beyond to_charpos if the initial
8642 portion of the next line needs to be reordered. In
8643 that case, give move_it_in_display_line_to another
8646 && it
->bidi_it
.scan_dir
== -1))
8647 skip
= MOVE_POS_MATCH_OR_ZV
;
8649 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8653 case MOVE_POS_MATCH_OR_ZV
:
8657 case MOVE_NEWLINE_OR_CR
:
8658 set_iterator_to_next (it
, 1);
8659 it
->continuation_lines_width
= 0;
8662 case MOVE_LINE_TRUNCATED
:
8663 it
->continuation_lines_width
= 0;
8664 reseat_at_next_visible_line_start (it
, 0);
8665 if ((op
& MOVE_TO_POS
) != 0
8666 && IT_CHARPOS (*it
) > to_charpos
)
8673 case MOVE_LINE_CONTINUED
:
8674 /* For continued lines ending in a tab, some of the glyphs
8675 associated with the tab are displayed on the current
8676 line. Since it->current_x does not include these glyphs,
8677 we use it->last_visible_x instead. */
8680 it
->continuation_lines_width
+= it
->last_visible_x
;
8681 /* When moving by vpos, ensure that the iterator really
8682 advances to the next line (bug#847, bug#969). Fixme:
8683 do we need to do this in other circumstances? */
8684 if (it
->current_x
!= it
->last_visible_x
8685 && (op
& MOVE_TO_VPOS
)
8686 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8688 line_start_x
= it
->current_x
+ it
->pixel_width
8689 - it
->last_visible_x
;
8690 set_iterator_to_next (it
, 0);
8694 it
->continuation_lines_width
+= it
->current_x
;
8701 /* Reset/increment for the next run. */
8702 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8703 it
->current_x
= line_start_x
;
8706 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8708 last_height
= it
->max_ascent
+ it
->max_descent
;
8709 last_max_ascent
= it
->max_ascent
;
8710 it
->max_ascent
= it
->max_descent
= 0;
8715 /* On text terminals, we may stop at the end of a line in the middle
8716 of a multi-character glyph. If the glyph itself is continued,
8717 i.e. it is actually displayed on the next line, don't treat this
8718 stopping point as valid; move to the next line instead (unless
8719 that brings us offscreen). */
8720 if (!FRAME_WINDOW_P (it
->f
)
8722 && IT_CHARPOS (*it
) == to_charpos
8723 && it
->what
== IT_CHARACTER
8725 && it
->line_wrap
== WINDOW_WRAP
8726 && it
->current_x
== it
->last_visible_x
- 1
8729 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8731 it
->continuation_lines_width
+= it
->current_x
;
8732 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8733 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8735 last_height
= it
->max_ascent
+ it
->max_descent
;
8736 last_max_ascent
= it
->max_ascent
;
8740 bidi_unshelve_cache (backup_data
, 1);
8742 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8746 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8748 If DY > 0, move IT backward at least that many pixels. DY = 0
8749 means move IT backward to the preceding line start or BEGV. This
8750 function may move over more than DY pixels if IT->current_y - DY
8751 ends up in the middle of a line; in this case IT->current_y will be
8752 set to the top of the line moved to. */
8755 move_it_vertically_backward (struct it
*it
, int dy
)
8759 void *it2data
= NULL
, *it3data
= NULL
;
8760 ptrdiff_t start_pos
;
8765 start_pos
= IT_CHARPOS (*it
);
8767 /* Estimate how many newlines we must move back. */
8768 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8770 /* Set the iterator's position that many lines back. */
8771 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8772 back_to_previous_visible_line_start (it
);
8774 /* Reseat the iterator here. When moving backward, we don't want
8775 reseat to skip forward over invisible text, set up the iterator
8776 to deliver from overlay strings at the new position etc. So,
8777 use reseat_1 here. */
8778 reseat_1 (it
, it
->current
.pos
, 1);
8780 /* We are now surely at a line start. */
8781 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8782 reordering is in effect. */
8783 it
->continuation_lines_width
= 0;
8785 /* Move forward and see what y-distance we moved. First move to the
8786 start of the next line so that we get its height. We need this
8787 height to be able to tell whether we reached the specified
8789 SAVE_IT (it2
, *it
, it2data
);
8790 it2
.max_ascent
= it2
.max_descent
= 0;
8793 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8794 MOVE_TO_POS
| MOVE_TO_VPOS
);
8796 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8797 /* If we are in a display string which starts at START_POS,
8798 and that display string includes a newline, and we are
8799 right after that newline (i.e. at the beginning of a
8800 display line), exit the loop, because otherwise we will
8801 infloop, since move_it_to will see that it is already at
8802 START_POS and will not move. */
8803 || (it2
.method
== GET_FROM_STRING
8804 && IT_CHARPOS (it2
) == start_pos
8805 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8806 xassert (IT_CHARPOS (*it
) >= BEGV
);
8807 SAVE_IT (it3
, it2
, it3data
);
8809 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8810 xassert (IT_CHARPOS (*it
) >= BEGV
);
8811 /* H is the actual vertical distance from the position in *IT
8812 and the starting position. */
8813 h
= it2
.current_y
- it
->current_y
;
8814 /* NLINES is the distance in number of lines. */
8815 nlines
= it2
.vpos
- it
->vpos
;
8817 /* Correct IT's y and vpos position
8818 so that they are relative to the starting point. */
8824 /* DY == 0 means move to the start of the screen line. The
8825 value of nlines is > 0 if continuation lines were involved,
8826 or if the original IT position was at start of a line. */
8827 RESTORE_IT (it
, it
, it2data
);
8829 move_it_by_lines (it
, nlines
);
8830 /* The above code moves us to some position NLINES down,
8831 usually to its first glyph (leftmost in an L2R line), but
8832 that's not necessarily the start of the line, under bidi
8833 reordering. We want to get to the character position
8834 that is immediately after the newline of the previous
8837 && !it
->continuation_lines_width
8838 && !STRINGP (it
->string
)
8839 && IT_CHARPOS (*it
) > BEGV
8840 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8843 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8845 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8847 bidi_unshelve_cache (it3data
, 1);
8851 /* The y-position we try to reach, relative to *IT.
8852 Note that H has been subtracted in front of the if-statement. */
8853 int target_y
= it
->current_y
+ h
- dy
;
8854 int y0
= it3
.current_y
;
8858 RESTORE_IT (&it3
, &it3
, it3data
);
8859 y1
= line_bottom_y (&it3
);
8860 line_height
= y1
- y0
;
8861 RESTORE_IT (it
, it
, it2data
);
8862 /* If we did not reach target_y, try to move further backward if
8863 we can. If we moved too far backward, try to move forward. */
8864 if (target_y
< it
->current_y
8865 /* This is heuristic. In a window that's 3 lines high, with
8866 a line height of 13 pixels each, recentering with point
8867 on the bottom line will try to move -39/2 = 19 pixels
8868 backward. Try to avoid moving into the first line. */
8869 && (it
->current_y
- target_y
8870 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8871 && IT_CHARPOS (*it
) > BEGV
)
8873 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8874 target_y
- it
->current_y
));
8875 dy
= it
->current_y
- target_y
;
8876 goto move_further_back
;
8878 else if (target_y
>= it
->current_y
+ line_height
8879 && IT_CHARPOS (*it
) < ZV
)
8881 /* Should move forward by at least one line, maybe more.
8883 Note: Calling move_it_by_lines can be expensive on
8884 terminal frames, where compute_motion is used (via
8885 vmotion) to do the job, when there are very long lines
8886 and truncate-lines is nil. That's the reason for
8887 treating terminal frames specially here. */
8889 if (!FRAME_WINDOW_P (it
->f
))
8890 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8895 move_it_by_lines (it
, 1);
8897 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8904 /* Move IT by a specified amount of pixel lines DY. DY negative means
8905 move backwards. DY = 0 means move to start of screen line. At the
8906 end, IT will be on the start of a screen line. */
8909 move_it_vertically (struct it
*it
, int dy
)
8912 move_it_vertically_backward (it
, -dy
);
8915 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8916 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8917 MOVE_TO_POS
| MOVE_TO_Y
);
8918 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8920 /* If buffer ends in ZV without a newline, move to the start of
8921 the line to satisfy the post-condition. */
8922 if (IT_CHARPOS (*it
) == ZV
8924 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8925 move_it_by_lines (it
, 0);
8930 /* Move iterator IT past the end of the text line it is in. */
8933 move_it_past_eol (struct it
*it
)
8935 enum move_it_result rc
;
8937 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8938 if (rc
== MOVE_NEWLINE_OR_CR
)
8939 set_iterator_to_next (it
, 0);
8943 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8944 negative means move up. DVPOS == 0 means move to the start of the
8947 Optimization idea: If we would know that IT->f doesn't use
8948 a face with proportional font, we could be faster for
8949 truncate-lines nil. */
8952 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
8955 /* The commented-out optimization uses vmotion on terminals. This
8956 gives bad results, because elements like it->what, on which
8957 callers such as pos_visible_p rely, aren't updated. */
8958 /* struct position pos;
8959 if (!FRAME_WINDOW_P (it->f))
8961 struct text_pos textpos;
8963 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8964 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8965 reseat (it, textpos, 1);
8966 it->vpos += pos.vpos;
8967 it->current_y += pos.vpos;
8973 /* DVPOS == 0 means move to the start of the screen line. */
8974 move_it_vertically_backward (it
, 0);
8975 /* Let next call to line_bottom_y calculate real line height */
8980 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8981 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8983 /* Only move to the next buffer position if we ended up in a
8984 string from display property, not in an overlay string
8985 (before-string or after-string). That is because the
8986 latter don't conceal the underlying buffer position, so
8987 we can ask to move the iterator to the exact position we
8988 are interested in. Note that, even if we are already at
8989 IT_CHARPOS (*it), the call below is not a no-op, as it
8990 will detect that we are at the end of the string, pop the
8991 iterator, and compute it->current_x and it->hpos
8993 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
8994 -1, -1, -1, MOVE_TO_POS
);
9000 void *it2data
= NULL
;
9001 ptrdiff_t start_charpos
, i
;
9003 /* Start at the beginning of the screen line containing IT's
9004 position. This may actually move vertically backwards,
9005 in case of overlays, so adjust dvpos accordingly. */
9007 move_it_vertically_backward (it
, 0);
9010 /* Go back -DVPOS visible lines and reseat the iterator there. */
9011 start_charpos
= IT_CHARPOS (*it
);
9012 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9013 back_to_previous_visible_line_start (it
);
9014 reseat (it
, it
->current
.pos
, 1);
9016 /* Move further back if we end up in a string or an image. */
9017 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9019 /* First try to move to start of display line. */
9021 move_it_vertically_backward (it
, 0);
9023 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9025 /* If start of line is still in string or image,
9026 move further back. */
9027 back_to_previous_visible_line_start (it
);
9028 reseat (it
, it
->current
.pos
, 1);
9032 it
->current_x
= it
->hpos
= 0;
9034 /* Above call may have moved too far if continuation lines
9035 are involved. Scan forward and see if it did. */
9036 SAVE_IT (it2
, *it
, it2data
);
9037 it2
.vpos
= it2
.current_y
= 0;
9038 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9039 it
->vpos
-= it2
.vpos
;
9040 it
->current_y
-= it2
.current_y
;
9041 it
->current_x
= it
->hpos
= 0;
9043 /* If we moved too far back, move IT some lines forward. */
9044 if (it2
.vpos
> -dvpos
)
9046 int delta
= it2
.vpos
+ dvpos
;
9048 RESTORE_IT (&it2
, &it2
, it2data
);
9049 SAVE_IT (it2
, *it
, it2data
);
9050 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9051 /* Move back again if we got too far ahead. */
9052 if (IT_CHARPOS (*it
) >= start_charpos
)
9053 RESTORE_IT (it
, &it2
, it2data
);
9055 bidi_unshelve_cache (it2data
, 1);
9058 RESTORE_IT (it
, it
, it2data
);
9062 /* Return 1 if IT points into the middle of a display vector. */
9065 in_display_vector_p (struct it
*it
)
9067 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9068 && it
->current
.dpvec_index
> 0
9069 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9073 /***********************************************************************
9075 ***********************************************************************/
9078 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9082 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9084 Lisp_Object args
[3];
9085 Lisp_Object msg
, fmt
;
9088 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9091 /* Do nothing if called asynchronously. Inserting text into
9092 a buffer may call after-change-functions and alike and
9093 that would means running Lisp asynchronously. */
9094 if (handling_signal
)
9098 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9100 args
[0] = fmt
= build_string (format
);
9103 msg
= Fformat (3, args
);
9105 len
= SBYTES (msg
) + 1;
9106 SAFE_ALLOCA (buffer
, char *, len
);
9107 memcpy (buffer
, SDATA (msg
), len
);
9109 message_dolog (buffer
, len
- 1, 1, 0);
9116 /* Output a newline in the *Messages* buffer if "needs" one. */
9119 message_log_maybe_newline (void)
9121 if (message_log_need_newline
)
9122 message_dolog ("", 0, 1, 0);
9126 /* Add a string M of length NBYTES to the message log, optionally
9127 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9128 nonzero, means interpret the contents of M as multibyte. This
9129 function calls low-level routines in order to bypass text property
9130 hooks, etc. which might not be safe to run.
9132 This may GC (insert may run before/after change hooks),
9133 so the buffer M must NOT point to a Lisp string. */
9136 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9138 const unsigned char *msg
= (const unsigned char *) m
;
9140 if (!NILP (Vmemory_full
))
9143 if (!NILP (Vmessage_log_max
))
9145 struct buffer
*oldbuf
;
9146 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9147 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9148 ptrdiff_t point_at_end
= 0;
9149 ptrdiff_t zv_at_end
= 0;
9150 Lisp_Object old_deactivate_mark
, tem
;
9151 struct gcpro gcpro1
;
9153 old_deactivate_mark
= Vdeactivate_mark
;
9154 oldbuf
= current_buffer
;
9155 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9156 BVAR (current_buffer
, undo_list
) = Qt
;
9158 oldpoint
= message_dolog_marker1
;
9159 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9160 oldbegv
= message_dolog_marker2
;
9161 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9162 oldzv
= message_dolog_marker3
;
9163 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9164 GCPRO1 (old_deactivate_mark
);
9172 BEGV_BYTE
= BEG_BYTE
;
9175 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9177 /* Insert the string--maybe converting multibyte to single byte
9178 or vice versa, so that all the text fits the buffer. */
9180 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9186 /* Convert a multibyte string to single-byte
9187 for the *Message* buffer. */
9188 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9190 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9191 work
[0] = (ASCII_CHAR_P (c
)
9193 : multibyte_char_to_unibyte (c
));
9194 insert_1_both (work
, 1, 1, 1, 0, 0);
9197 else if (! multibyte
9198 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9202 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9203 /* Convert a single-byte string to multibyte
9204 for the *Message* buffer. */
9205 for (i
= 0; i
< nbytes
; i
++)
9208 MAKE_CHAR_MULTIBYTE (c
);
9209 char_bytes
= CHAR_STRING (c
, str
);
9210 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9214 insert_1 (m
, nbytes
, 1, 0, 0);
9218 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9220 insert_1 ("\n", 1, 1, 0, 0);
9222 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9224 this_bol_byte
= PT_BYTE
;
9226 /* See if this line duplicates the previous one.
9227 If so, combine duplicates. */
9230 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9232 prev_bol_byte
= PT_BYTE
;
9234 dups
= message_log_check_duplicate (prev_bol_byte
,
9238 del_range_both (prev_bol
, prev_bol_byte
,
9239 this_bol
, this_bol_byte
, 0);
9242 char dupstr
[sizeof " [ times]"
9243 + INT_STRLEN_BOUND (printmax_t
)];
9246 /* If you change this format, don't forget to also
9247 change message_log_check_duplicate. */
9248 sprintf (dupstr
, " [%"pMd
" times]", dups
);
9249 duplen
= strlen (dupstr
);
9250 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9251 insert_1 (dupstr
, duplen
, 1, 0, 1);
9256 /* If we have more than the desired maximum number of lines
9257 in the *Messages* buffer now, delete the oldest ones.
9258 This is safe because we don't have undo in this buffer. */
9260 if (NATNUMP (Vmessage_log_max
))
9262 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9263 -XFASTINT (Vmessage_log_max
) - 1, 0);
9264 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9267 BEGV
= XMARKER (oldbegv
)->charpos
;
9268 BEGV_BYTE
= marker_byte_position (oldbegv
);
9277 ZV
= XMARKER (oldzv
)->charpos
;
9278 ZV_BYTE
= marker_byte_position (oldzv
);
9282 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9284 /* We can't do Fgoto_char (oldpoint) because it will run some
9286 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9287 XMARKER (oldpoint
)->bytepos
);
9290 unchain_marker (XMARKER (oldpoint
));
9291 unchain_marker (XMARKER (oldbegv
));
9292 unchain_marker (XMARKER (oldzv
));
9294 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9295 set_buffer_internal (oldbuf
);
9297 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9298 message_log_need_newline
= !nlflag
;
9299 Vdeactivate_mark
= old_deactivate_mark
;
9304 /* We are at the end of the buffer after just having inserted a newline.
9305 (Note: We depend on the fact we won't be crossing the gap.)
9306 Check to see if the most recent message looks a lot like the previous one.
9307 Return 0 if different, 1 if the new one should just replace it, or a
9308 value N > 1 if we should also append " [N times]". */
9311 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9314 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9316 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9317 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9319 for (i
= 0; i
< len
; i
++)
9321 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9329 if (*p1
++ == ' ' && *p1
++ == '[')
9332 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9333 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9340 /* Display an echo area message M with a specified length of NBYTES
9341 bytes. The string may include null characters. If M is 0, clear
9342 out any existing message, and let the mini-buffer text show
9345 This may GC, so the buffer M must NOT point to a Lisp string. */
9348 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9350 /* First flush out any partial line written with print. */
9351 message_log_maybe_newline ();
9353 message_dolog (m
, nbytes
, 1, multibyte
);
9354 message2_nolog (m
, nbytes
, multibyte
);
9358 /* The non-logging counterpart of message2. */
9361 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9363 struct frame
*sf
= SELECTED_FRAME ();
9364 message_enable_multibyte
= multibyte
;
9366 if (FRAME_INITIAL_P (sf
))
9368 if (noninteractive_need_newline
)
9369 putc ('\n', stderr
);
9370 noninteractive_need_newline
= 0;
9372 fwrite (m
, nbytes
, 1, stderr
);
9373 if (cursor_in_echo_area
== 0)
9374 fprintf (stderr
, "\n");
9377 /* A null message buffer means that the frame hasn't really been
9378 initialized yet. Error messages get reported properly by
9379 cmd_error, so this must be just an informative message; toss it. */
9380 else if (INTERACTIVE
9381 && sf
->glyphs_initialized_p
9382 && FRAME_MESSAGE_BUF (sf
))
9384 Lisp_Object mini_window
;
9387 /* Get the frame containing the mini-buffer
9388 that the selected frame is using. */
9389 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9390 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9392 FRAME_SAMPLE_VISIBILITY (f
);
9393 if (FRAME_VISIBLE_P (sf
)
9394 && ! FRAME_VISIBLE_P (f
))
9395 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9399 set_message (m
, Qnil
, nbytes
, multibyte
);
9400 if (minibuffer_auto_raise
)
9401 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9404 clear_message (1, 1);
9406 do_pending_window_change (0);
9407 echo_area_display (1);
9408 do_pending_window_change (0);
9409 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9410 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9415 /* Display an echo area message M with a specified length of NBYTES
9416 bytes. The string may include null characters. If M is not a
9417 string, clear out any existing message, and let the mini-buffer
9420 This function cancels echoing. */
9423 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9425 struct gcpro gcpro1
;
9428 clear_message (1,1);
9431 /* First flush out any partial line written with print. */
9432 message_log_maybe_newline ();
9438 SAFE_ALLOCA (buffer
, char *, nbytes
);
9439 memcpy (buffer
, SDATA (m
), nbytes
);
9440 message_dolog (buffer
, nbytes
, 1, multibyte
);
9443 message3_nolog (m
, nbytes
, multibyte
);
9449 /* The non-logging version of message3.
9450 This does not cancel echoing, because it is used for echoing.
9451 Perhaps we need to make a separate function for echoing
9452 and make this cancel echoing. */
9455 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9457 struct frame
*sf
= SELECTED_FRAME ();
9458 message_enable_multibyte
= multibyte
;
9460 if (FRAME_INITIAL_P (sf
))
9462 if (noninteractive_need_newline
)
9463 putc ('\n', stderr
);
9464 noninteractive_need_newline
= 0;
9466 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9467 if (cursor_in_echo_area
== 0)
9468 fprintf (stderr
, "\n");
9471 /* A null message buffer means that the frame hasn't really been
9472 initialized yet. Error messages get reported properly by
9473 cmd_error, so this must be just an informative message; toss it. */
9474 else if (INTERACTIVE
9475 && sf
->glyphs_initialized_p
9476 && FRAME_MESSAGE_BUF (sf
))
9478 Lisp_Object mini_window
;
9482 /* Get the frame containing the mini-buffer
9483 that the selected frame is using. */
9484 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9485 frame
= XWINDOW (mini_window
)->frame
;
9488 FRAME_SAMPLE_VISIBILITY (f
);
9489 if (FRAME_VISIBLE_P (sf
)
9490 && !FRAME_VISIBLE_P (f
))
9491 Fmake_frame_visible (frame
);
9493 if (STRINGP (m
) && SCHARS (m
) > 0)
9495 set_message (NULL
, m
, nbytes
, multibyte
);
9496 if (minibuffer_auto_raise
)
9497 Fraise_frame (frame
);
9498 /* Assume we are not echoing.
9499 (If we are, echo_now will override this.) */
9500 echo_message_buffer
= Qnil
;
9503 clear_message (1, 1);
9505 do_pending_window_change (0);
9506 echo_area_display (1);
9507 do_pending_window_change (0);
9508 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9509 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9514 /* Display a null-terminated echo area message M. If M is 0, clear
9515 out any existing message, and let the mini-buffer text show through.
9517 The buffer M must continue to exist until after the echo area gets
9518 cleared or some other message gets displayed there. Do not pass
9519 text that is stored in a Lisp string. Do not pass text in a buffer
9520 that was alloca'd. */
9523 message1 (const char *m
)
9525 message2 (m
, (m
? strlen (m
) : 0), 0);
9529 /* The non-logging counterpart of message1. */
9532 message1_nolog (const char *m
)
9534 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9537 /* Display a message M which contains a single %s
9538 which gets replaced with STRING. */
9541 message_with_string (const char *m
, Lisp_Object string
, int log
)
9543 CHECK_STRING (string
);
9549 if (noninteractive_need_newline
)
9550 putc ('\n', stderr
);
9551 noninteractive_need_newline
= 0;
9552 fprintf (stderr
, m
, SDATA (string
));
9553 if (!cursor_in_echo_area
)
9554 fprintf (stderr
, "\n");
9558 else if (INTERACTIVE
)
9560 /* The frame whose minibuffer we're going to display the message on.
9561 It may be larger than the selected frame, so we need
9562 to use its buffer, not the selected frame's buffer. */
9563 Lisp_Object mini_window
;
9564 struct frame
*f
, *sf
= SELECTED_FRAME ();
9566 /* Get the frame containing the minibuffer
9567 that the selected frame is using. */
9568 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9569 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9571 /* A null message buffer means that the frame hasn't really been
9572 initialized yet. Error messages get reported properly by
9573 cmd_error, so this must be just an informative message; toss it. */
9574 if (FRAME_MESSAGE_BUF (f
))
9576 Lisp_Object args
[2], msg
;
9577 struct gcpro gcpro1
, gcpro2
;
9579 args
[0] = build_string (m
);
9580 args
[1] = msg
= string
;
9581 GCPRO2 (args
[0], msg
);
9584 msg
= Fformat (2, args
);
9587 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9589 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9593 /* Print should start at the beginning of the message
9594 buffer next time. */
9595 message_buf_print
= 0;
9601 /* Dump an informative message to the minibuf. If M is 0, clear out
9602 any existing message, and let the mini-buffer text show through. */
9605 vmessage (const char *m
, va_list ap
)
9611 if (noninteractive_need_newline
)
9612 putc ('\n', stderr
);
9613 noninteractive_need_newline
= 0;
9614 vfprintf (stderr
, m
, ap
);
9615 if (cursor_in_echo_area
== 0)
9616 fprintf (stderr
, "\n");
9620 else if (INTERACTIVE
)
9622 /* The frame whose mini-buffer we're going to display the message
9623 on. It may be larger than the selected frame, so we need to
9624 use its buffer, not the selected frame's buffer. */
9625 Lisp_Object mini_window
;
9626 struct frame
*f
, *sf
= SELECTED_FRAME ();
9628 /* Get the frame containing the mini-buffer
9629 that the selected frame is using. */
9630 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9631 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9633 /* A null message buffer means that the frame hasn't really been
9634 initialized yet. Error messages get reported properly by
9635 cmd_error, so this must be just an informative message; toss
9637 if (FRAME_MESSAGE_BUF (f
))
9643 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9644 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9646 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9651 /* Print should start at the beginning of the message
9652 buffer next time. */
9653 message_buf_print
= 0;
9659 message (const char *m
, ...)
9669 /* The non-logging version of message. */
9672 message_nolog (const char *m
, ...)
9674 Lisp_Object old_log_max
;
9677 old_log_max
= Vmessage_log_max
;
9678 Vmessage_log_max
= Qnil
;
9680 Vmessage_log_max
= old_log_max
;
9686 /* Display the current message in the current mini-buffer. This is
9687 only called from error handlers in process.c, and is not time
9691 update_echo_area (void)
9693 if (!NILP (echo_area_buffer
[0]))
9696 string
= Fcurrent_message ();
9697 message3 (string
, SBYTES (string
),
9698 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9703 /* Make sure echo area buffers in `echo_buffers' are live.
9704 If they aren't, make new ones. */
9707 ensure_echo_area_buffers (void)
9711 for (i
= 0; i
< 2; ++i
)
9712 if (!BUFFERP (echo_buffer
[i
])
9713 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9716 Lisp_Object old_buffer
;
9719 old_buffer
= echo_buffer
[i
];
9720 sprintf (name
, " *Echo Area %d*", i
);
9721 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9722 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9723 /* to force word wrap in echo area -
9724 it was decided to postpone this*/
9725 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9727 for (j
= 0; j
< 2; ++j
)
9728 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9729 echo_area_buffer
[j
] = echo_buffer
[i
];
9734 /* Call FN with args A1..A4 with either the current or last displayed
9735 echo_area_buffer as current buffer.
9737 WHICH zero means use the current message buffer
9738 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9739 from echo_buffer[] and clear it.
9741 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9742 suitable buffer from echo_buffer[] and clear it.
9744 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9745 that the current message becomes the last displayed one, make
9746 choose a suitable buffer for echo_area_buffer[0], and clear it.
9748 Value is what FN returns. */
9751 with_echo_area_buffer (struct window
*w
, int which
,
9752 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9753 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9756 int this_one
, the_other
, clear_buffer_p
, rc
;
9757 ptrdiff_t count
= SPECPDL_INDEX ();
9759 /* If buffers aren't live, make new ones. */
9760 ensure_echo_area_buffers ();
9765 this_one
= 0, the_other
= 1;
9767 this_one
= 1, the_other
= 0;
9770 this_one
= 0, the_other
= 1;
9773 /* We need a fresh one in case the current echo buffer equals
9774 the one containing the last displayed echo area message. */
9775 if (!NILP (echo_area_buffer
[this_one
])
9776 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9777 echo_area_buffer
[this_one
] = Qnil
;
9780 /* Choose a suitable buffer from echo_buffer[] is we don't
9782 if (NILP (echo_area_buffer
[this_one
]))
9784 echo_area_buffer
[this_one
]
9785 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9786 ? echo_buffer
[the_other
]
9787 : echo_buffer
[this_one
]);
9791 buffer
= echo_area_buffer
[this_one
];
9793 /* Don't get confused by reusing the buffer used for echoing
9794 for a different purpose. */
9795 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9798 record_unwind_protect (unwind_with_echo_area_buffer
,
9799 with_echo_area_buffer_unwind_data (w
));
9801 /* Make the echo area buffer current. Note that for display
9802 purposes, it is not necessary that the displayed window's buffer
9803 == current_buffer, except for text property lookup. So, let's
9804 only set that buffer temporarily here without doing a full
9805 Fset_window_buffer. We must also change w->pointm, though,
9806 because otherwise an assertions in unshow_buffer fails, and Emacs
9808 set_buffer_internal_1 (XBUFFER (buffer
));
9812 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9815 BVAR (current_buffer
, undo_list
) = Qt
;
9816 BVAR (current_buffer
, read_only
) = Qnil
;
9817 specbind (Qinhibit_read_only
, Qt
);
9818 specbind (Qinhibit_modification_hooks
, Qt
);
9820 if (clear_buffer_p
&& Z
> BEG
)
9823 xassert (BEGV
>= BEG
);
9824 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9826 rc
= fn (a1
, a2
, a3
, a4
);
9828 xassert (BEGV
>= BEG
);
9829 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9831 unbind_to (count
, Qnil
);
9836 /* Save state that should be preserved around the call to the function
9837 FN called in with_echo_area_buffer. */
9840 with_echo_area_buffer_unwind_data (struct window
*w
)
9843 Lisp_Object vector
, tmp
;
9845 /* Reduce consing by keeping one vector in
9846 Vwith_echo_area_save_vector. */
9847 vector
= Vwith_echo_area_save_vector
;
9848 Vwith_echo_area_save_vector
= Qnil
;
9851 vector
= Fmake_vector (make_number (7), Qnil
);
9853 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9854 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9855 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9859 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9860 ASET (vector
, i
, w
->buffer
); ++i
;
9861 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9862 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9867 for (; i
< end
; ++i
)
9868 ASET (vector
, i
, Qnil
);
9871 xassert (i
== ASIZE (vector
));
9876 /* Restore global state from VECTOR which was created by
9877 with_echo_area_buffer_unwind_data. */
9880 unwind_with_echo_area_buffer (Lisp_Object vector
)
9882 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9883 Vdeactivate_mark
= AREF (vector
, 1);
9884 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9886 if (WINDOWP (AREF (vector
, 3)))
9889 Lisp_Object buffer
, charpos
, bytepos
;
9891 w
= XWINDOW (AREF (vector
, 3));
9892 buffer
= AREF (vector
, 4);
9893 charpos
= AREF (vector
, 5);
9894 bytepos
= AREF (vector
, 6);
9897 set_marker_both (w
->pointm
, buffer
,
9898 XFASTINT (charpos
), XFASTINT (bytepos
));
9901 Vwith_echo_area_save_vector
= vector
;
9906 /* Set up the echo area for use by print functions. MULTIBYTE_P
9907 non-zero means we will print multibyte. */
9910 setup_echo_area_for_printing (int multibyte_p
)
9912 /* If we can't find an echo area any more, exit. */
9913 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9916 ensure_echo_area_buffers ();
9918 if (!message_buf_print
)
9920 /* A message has been output since the last time we printed.
9921 Choose a fresh echo area buffer. */
9922 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9923 echo_area_buffer
[0] = echo_buffer
[1];
9925 echo_area_buffer
[0] = echo_buffer
[0];
9927 /* Switch to that buffer and clear it. */
9928 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9929 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9933 ptrdiff_t count
= SPECPDL_INDEX ();
9934 specbind (Qinhibit_read_only
, Qt
);
9935 /* Note that undo recording is always disabled. */
9937 unbind_to (count
, Qnil
);
9939 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9941 /* Set up the buffer for the multibyteness we need. */
9943 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9944 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9946 /* Raise the frame containing the echo area. */
9947 if (minibuffer_auto_raise
)
9949 struct frame
*sf
= SELECTED_FRAME ();
9950 Lisp_Object mini_window
;
9951 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9952 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9955 message_log_maybe_newline ();
9956 message_buf_print
= 1;
9960 if (NILP (echo_area_buffer
[0]))
9962 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9963 echo_area_buffer
[0] = echo_buffer
[1];
9965 echo_area_buffer
[0] = echo_buffer
[0];
9968 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9970 /* Someone switched buffers between print requests. */
9971 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9972 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9978 /* Display an echo area message in window W. Value is non-zero if W's
9979 height is changed. If display_last_displayed_message_p is
9980 non-zero, display the message that was last displayed, otherwise
9981 display the current message. */
9984 display_echo_area (struct window
*w
)
9986 int i
, no_message_p
, window_height_changed_p
;
9988 /* Temporarily disable garbage collections while displaying the echo
9989 area. This is done because a GC can print a message itself.
9990 That message would modify the echo area buffer's contents while a
9991 redisplay of the buffer is going on, and seriously confuse
9993 ptrdiff_t count
= inhibit_garbage_collection ();
9995 /* If there is no message, we must call display_echo_area_1
9996 nevertheless because it resizes the window. But we will have to
9997 reset the echo_area_buffer in question to nil at the end because
9998 with_echo_area_buffer will sets it to an empty buffer. */
9999 i
= display_last_displayed_message_p
? 1 : 0;
10000 no_message_p
= NILP (echo_area_buffer
[i
]);
10002 window_height_changed_p
10003 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10004 display_echo_area_1
,
10005 (intptr_t) w
, Qnil
, 0, 0);
10008 echo_area_buffer
[i
] = Qnil
;
10010 unbind_to (count
, Qnil
);
10011 return window_height_changed_p
;
10015 /* Helper for display_echo_area. Display the current buffer which
10016 contains the current echo area message in window W, a mini-window,
10017 a pointer to which is passed in A1. A2..A4 are currently not used.
10018 Change the height of W so that all of the message is displayed.
10019 Value is non-zero if height of W was changed. */
10022 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10025 struct window
*w
= (struct window
*) i1
;
10026 Lisp_Object window
;
10027 struct text_pos start
;
10028 int window_height_changed_p
= 0;
10030 /* Do this before displaying, so that we have a large enough glyph
10031 matrix for the display. If we can't get enough space for the
10032 whole text, display the last N lines. That works by setting w->start. */
10033 window_height_changed_p
= resize_mini_window (w
, 0);
10035 /* Use the starting position chosen by resize_mini_window. */
10036 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10039 clear_glyph_matrix (w
->desired_matrix
);
10040 XSETWINDOW (window
, w
);
10041 try_window (window
, start
, 0);
10043 return window_height_changed_p
;
10047 /* Resize the echo area window to exactly the size needed for the
10048 currently displayed message, if there is one. If a mini-buffer
10049 is active, don't shrink it. */
10052 resize_echo_area_exactly (void)
10054 if (BUFFERP (echo_area_buffer
[0])
10055 && WINDOWP (echo_area_window
))
10057 struct window
*w
= XWINDOW (echo_area_window
);
10059 Lisp_Object resize_exactly
;
10061 if (minibuf_level
== 0)
10062 resize_exactly
= Qt
;
10064 resize_exactly
= Qnil
;
10066 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10067 (intptr_t) w
, resize_exactly
,
10071 ++windows_or_buffers_changed
;
10072 ++update_mode_lines
;
10073 redisplay_internal ();
10079 /* Callback function for with_echo_area_buffer, when used from
10080 resize_echo_area_exactly. A1 contains a pointer to the window to
10081 resize, EXACTLY non-nil means resize the mini-window exactly to the
10082 size of the text displayed. A3 and A4 are not used. Value is what
10083 resize_mini_window returns. */
10086 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10089 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10093 /* Resize mini-window W to fit the size of its contents. EXACT_P
10094 means size the window exactly to the size needed. Otherwise, it's
10095 only enlarged until W's buffer is empty.
10097 Set W->start to the right place to begin display. If the whole
10098 contents fit, start at the beginning. Otherwise, start so as
10099 to make the end of the contents appear. This is particularly
10100 important for y-or-n-p, but seems desirable generally.
10102 Value is non-zero if the window height has been changed. */
10105 resize_mini_window (struct window
*w
, int exact_p
)
10107 struct frame
*f
= XFRAME (w
->frame
);
10108 int window_height_changed_p
= 0;
10110 xassert (MINI_WINDOW_P (w
));
10112 /* By default, start display at the beginning. */
10113 set_marker_both (w
->start
, w
->buffer
,
10114 BUF_BEGV (XBUFFER (w
->buffer
)),
10115 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10117 /* Don't resize windows while redisplaying a window; it would
10118 confuse redisplay functions when the size of the window they are
10119 displaying changes from under them. Such a resizing can happen,
10120 for instance, when which-func prints a long message while
10121 we are running fontification-functions. We're running these
10122 functions with safe_call which binds inhibit-redisplay to t. */
10123 if (!NILP (Vinhibit_redisplay
))
10126 /* Nil means don't try to resize. */
10127 if (NILP (Vresize_mini_windows
)
10128 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10131 if (!FRAME_MINIBUF_ONLY_P (f
))
10134 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10135 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10137 EMACS_INT max_height
;
10138 int unit
= FRAME_LINE_HEIGHT (f
);
10139 struct text_pos start
;
10140 struct buffer
*old_current_buffer
= NULL
;
10142 if (current_buffer
!= XBUFFER (w
->buffer
))
10144 old_current_buffer
= current_buffer
;
10145 set_buffer_internal (XBUFFER (w
->buffer
));
10148 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10150 /* Compute the max. number of lines specified by the user. */
10151 if (FLOATP (Vmax_mini_window_height
))
10152 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10153 else if (INTEGERP (Vmax_mini_window_height
))
10154 max_height
= XINT (Vmax_mini_window_height
);
10156 max_height
= total_height
/ 4;
10158 /* Correct that max. height if it's bogus. */
10159 max_height
= max (1, max_height
);
10160 max_height
= min (total_height
, max_height
);
10162 /* Find out the height of the text in the window. */
10163 if (it
.line_wrap
== TRUNCATE
)
10168 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10169 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10170 height
= it
.current_y
+ last_height
;
10172 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10173 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10174 height
= (height
+ unit
- 1) / unit
;
10177 /* Compute a suitable window start. */
10178 if (height
> max_height
)
10180 height
= max_height
;
10181 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10182 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10183 start
= it
.current
.pos
;
10186 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10187 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10189 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10191 /* Let it grow only, until we display an empty message, in which
10192 case the window shrinks again. */
10193 if (height
> WINDOW_TOTAL_LINES (w
))
10195 int old_height
= WINDOW_TOTAL_LINES (w
);
10196 freeze_window_starts (f
, 1);
10197 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10198 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10200 else if (height
< WINDOW_TOTAL_LINES (w
)
10201 && (exact_p
|| BEGV
== ZV
))
10203 int old_height
= WINDOW_TOTAL_LINES (w
);
10204 freeze_window_starts (f
, 0);
10205 shrink_mini_window (w
);
10206 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10211 /* Always resize to exact size needed. */
10212 if (height
> WINDOW_TOTAL_LINES (w
))
10214 int old_height
= WINDOW_TOTAL_LINES (w
);
10215 freeze_window_starts (f
, 1);
10216 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10217 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10219 else if (height
< WINDOW_TOTAL_LINES (w
))
10221 int old_height
= WINDOW_TOTAL_LINES (w
);
10222 freeze_window_starts (f
, 0);
10223 shrink_mini_window (w
);
10227 freeze_window_starts (f
, 1);
10228 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10231 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10235 if (old_current_buffer
)
10236 set_buffer_internal (old_current_buffer
);
10239 return window_height_changed_p
;
10243 /* Value is the current message, a string, or nil if there is no
10244 current message. */
10247 current_message (void)
10251 if (!BUFFERP (echo_area_buffer
[0]))
10255 with_echo_area_buffer (0, 0, current_message_1
,
10256 (intptr_t) &msg
, Qnil
, 0, 0);
10258 echo_area_buffer
[0] = Qnil
;
10266 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10269 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10272 *msg
= make_buffer_string (BEG
, Z
, 1);
10279 /* Push the current message on Vmessage_stack for later restoration
10280 by restore_message. Value is non-zero if the current message isn't
10281 empty. This is a relatively infrequent operation, so it's not
10282 worth optimizing. */
10285 push_message (void)
10288 msg
= current_message ();
10289 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10290 return STRINGP (msg
);
10294 /* Restore message display from the top of Vmessage_stack. */
10297 restore_message (void)
10301 xassert (CONSP (Vmessage_stack
));
10302 msg
= XCAR (Vmessage_stack
);
10304 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10306 message3_nolog (msg
, 0, 0);
10310 /* Handler for record_unwind_protect calling pop_message. */
10313 pop_message_unwind (Lisp_Object dummy
)
10319 /* Pop the top-most entry off Vmessage_stack. */
10324 xassert (CONSP (Vmessage_stack
));
10325 Vmessage_stack
= XCDR (Vmessage_stack
);
10329 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10330 exits. If the stack is not empty, we have a missing pop_message
10334 check_message_stack (void)
10336 if (!NILP (Vmessage_stack
))
10341 /* Truncate to NCHARS what will be displayed in the echo area the next
10342 time we display it---but don't redisplay it now. */
10345 truncate_echo_area (ptrdiff_t nchars
)
10348 echo_area_buffer
[0] = Qnil
;
10349 /* A null message buffer means that the frame hasn't really been
10350 initialized yet. Error messages get reported properly by
10351 cmd_error, so this must be just an informative message; toss it. */
10352 else if (!noninteractive
10354 && !NILP (echo_area_buffer
[0]))
10356 struct frame
*sf
= SELECTED_FRAME ();
10357 if (FRAME_MESSAGE_BUF (sf
))
10358 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10363 /* Helper function for truncate_echo_area. Truncate the current
10364 message to at most NCHARS characters. */
10367 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10369 if (BEG
+ nchars
< Z
)
10370 del_range (BEG
+ nchars
, Z
);
10372 echo_area_buffer
[0] = Qnil
;
10377 /* Set the current message to a substring of S or STRING.
10379 If STRING is a Lisp string, set the message to the first NBYTES
10380 bytes from STRING. NBYTES zero means use the whole string. If
10381 STRING is multibyte, the message will be displayed multibyte.
10383 If S is not null, set the message to the first LEN bytes of S. LEN
10384 zero means use the whole string. MULTIBYTE_P non-zero means S is
10385 multibyte. Display the message multibyte in that case.
10387 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10388 to t before calling set_message_1 (which calls insert).
10392 set_message (const char *s
, Lisp_Object string
,
10393 ptrdiff_t nbytes
, int multibyte_p
)
10395 message_enable_multibyte
10396 = ((s
&& multibyte_p
)
10397 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10399 with_echo_area_buffer (0, -1, set_message_1
,
10400 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10401 message_buf_print
= 0;
10402 help_echo_showing_p
= 0;
10406 /* Helper function for set_message. Arguments have the same meaning
10407 as there, with A1 corresponding to S and A2 corresponding to STRING
10408 This function is called with the echo area buffer being
10412 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10415 const char *s
= (const char *) i1
;
10416 const unsigned char *msg
= (const unsigned char *) s
;
10417 Lisp_Object string
= a2
;
10419 /* Change multibyteness of the echo buffer appropriately. */
10420 if (message_enable_multibyte
10421 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10422 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10424 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10425 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10426 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10428 /* Insert new message at BEG. */
10429 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10431 if (STRINGP (string
))
10436 nbytes
= SBYTES (string
);
10437 nchars
= string_byte_to_char (string
, nbytes
);
10439 /* This function takes care of single/multibyte conversion. We
10440 just have to ensure that the echo area buffer has the right
10441 setting of enable_multibyte_characters. */
10442 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10447 nbytes
= strlen (s
);
10449 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10451 /* Convert from multi-byte to single-byte. */
10456 /* Convert a multibyte string to single-byte. */
10457 for (i
= 0; i
< nbytes
; i
+= n
)
10459 c
= string_char_and_length (msg
+ i
, &n
);
10460 work
[0] = (ASCII_CHAR_P (c
)
10462 : multibyte_char_to_unibyte (c
));
10463 insert_1_both (work
, 1, 1, 1, 0, 0);
10466 else if (!multibyte_p
10467 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10469 /* Convert from single-byte to multi-byte. */
10472 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10474 /* Convert a single-byte string to multibyte. */
10475 for (i
= 0; i
< nbytes
; i
++)
10478 MAKE_CHAR_MULTIBYTE (c
);
10479 n
= CHAR_STRING (c
, str
);
10480 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10484 insert_1 (s
, nbytes
, 1, 0, 0);
10491 /* Clear messages. CURRENT_P non-zero means clear the current
10492 message. LAST_DISPLAYED_P non-zero means clear the message
10496 clear_message (int current_p
, int last_displayed_p
)
10500 echo_area_buffer
[0] = Qnil
;
10501 message_cleared_p
= 1;
10504 if (last_displayed_p
)
10505 echo_area_buffer
[1] = Qnil
;
10507 message_buf_print
= 0;
10510 /* Clear garbaged frames.
10512 This function is used where the old redisplay called
10513 redraw_garbaged_frames which in turn called redraw_frame which in
10514 turn called clear_frame. The call to clear_frame was a source of
10515 flickering. I believe a clear_frame is not necessary. It should
10516 suffice in the new redisplay to invalidate all current matrices,
10517 and ensure a complete redisplay of all windows. */
10520 clear_garbaged_frames (void)
10522 if (frame_garbaged
)
10524 Lisp_Object tail
, frame
;
10525 int changed_count
= 0;
10527 FOR_EACH_FRAME (tail
, frame
)
10529 struct frame
*f
= XFRAME (frame
);
10531 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10535 Fredraw_frame (frame
);
10536 f
->force_flush_display_p
= 1;
10538 clear_current_matrices (f
);
10545 frame_garbaged
= 0;
10547 ++windows_or_buffers_changed
;
10552 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10553 is non-zero update selected_frame. Value is non-zero if the
10554 mini-windows height has been changed. */
10557 echo_area_display (int update_frame_p
)
10559 Lisp_Object mini_window
;
10562 int window_height_changed_p
= 0;
10563 struct frame
*sf
= SELECTED_FRAME ();
10565 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10566 w
= XWINDOW (mini_window
);
10567 f
= XFRAME (WINDOW_FRAME (w
));
10569 /* Don't display if frame is invisible or not yet initialized. */
10570 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10573 #ifdef HAVE_WINDOW_SYSTEM
10574 /* When Emacs starts, selected_frame may be the initial terminal
10575 frame. If we let this through, a message would be displayed on
10577 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10579 #endif /* HAVE_WINDOW_SYSTEM */
10581 /* Redraw garbaged frames. */
10582 if (frame_garbaged
)
10583 clear_garbaged_frames ();
10585 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10587 echo_area_window
= mini_window
;
10588 window_height_changed_p
= display_echo_area (w
);
10589 w
->must_be_updated_p
= 1;
10591 /* Update the display, unless called from redisplay_internal.
10592 Also don't update the screen during redisplay itself. The
10593 update will happen at the end of redisplay, and an update
10594 here could cause confusion. */
10595 if (update_frame_p
&& !redisplaying_p
)
10599 /* If the display update has been interrupted by pending
10600 input, update mode lines in the frame. Due to the
10601 pending input, it might have been that redisplay hasn't
10602 been called, so that mode lines above the echo area are
10603 garbaged. This looks odd, so we prevent it here. */
10604 if (!display_completed
)
10605 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10607 if (window_height_changed_p
10608 /* Don't do this if Emacs is shutting down. Redisplay
10609 needs to run hooks. */
10610 && !NILP (Vrun_hooks
))
10612 /* Must update other windows. Likewise as in other
10613 cases, don't let this update be interrupted by
10615 ptrdiff_t count
= SPECPDL_INDEX ();
10616 specbind (Qredisplay_dont_pause
, Qt
);
10617 windows_or_buffers_changed
= 1;
10618 redisplay_internal ();
10619 unbind_to (count
, Qnil
);
10621 else if (FRAME_WINDOW_P (f
) && n
== 0)
10623 /* Window configuration is the same as before.
10624 Can do with a display update of the echo area,
10625 unless we displayed some mode lines. */
10626 update_single_window (w
, 1);
10627 FRAME_RIF (f
)->flush_display (f
);
10630 update_frame (f
, 1, 1);
10632 /* If cursor is in the echo area, make sure that the next
10633 redisplay displays the minibuffer, so that the cursor will
10634 be replaced with what the minibuffer wants. */
10635 if (cursor_in_echo_area
)
10636 ++windows_or_buffers_changed
;
10639 else if (!EQ (mini_window
, selected_window
))
10640 windows_or_buffers_changed
++;
10642 /* Last displayed message is now the current message. */
10643 echo_area_buffer
[1] = echo_area_buffer
[0];
10644 /* Inform read_char that we're not echoing. */
10645 echo_message_buffer
= Qnil
;
10647 /* Prevent redisplay optimization in redisplay_internal by resetting
10648 this_line_start_pos. This is done because the mini-buffer now
10649 displays the message instead of its buffer text. */
10650 if (EQ (mini_window
, selected_window
))
10651 CHARPOS (this_line_start_pos
) = 0;
10653 return window_height_changed_p
;
10658 /***********************************************************************
10659 Mode Lines and Frame Titles
10660 ***********************************************************************/
10662 /* A buffer for constructing non-propertized mode-line strings and
10663 frame titles in it; allocated from the heap in init_xdisp and
10664 resized as needed in store_mode_line_noprop_char. */
10666 static char *mode_line_noprop_buf
;
10668 /* The buffer's end, and a current output position in it. */
10670 static char *mode_line_noprop_buf_end
;
10671 static char *mode_line_noprop_ptr
;
10673 #define MODE_LINE_NOPROP_LEN(start) \
10674 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10677 MODE_LINE_DISPLAY
= 0,
10681 } mode_line_target
;
10683 /* Alist that caches the results of :propertize.
10684 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10685 static Lisp_Object mode_line_proptrans_alist
;
10687 /* List of strings making up the mode-line. */
10688 static Lisp_Object mode_line_string_list
;
10690 /* Base face property when building propertized mode line string. */
10691 static Lisp_Object mode_line_string_face
;
10692 static Lisp_Object mode_line_string_face_prop
;
10695 /* Unwind data for mode line strings */
10697 static Lisp_Object Vmode_line_unwind_vector
;
10700 format_mode_line_unwind_data (struct buffer
*obuf
,
10702 int save_proptrans
)
10704 Lisp_Object vector
, tmp
;
10706 /* Reduce consing by keeping one vector in
10707 Vwith_echo_area_save_vector. */
10708 vector
= Vmode_line_unwind_vector
;
10709 Vmode_line_unwind_vector
= Qnil
;
10712 vector
= Fmake_vector (make_number (8), Qnil
);
10714 ASET (vector
, 0, make_number (mode_line_target
));
10715 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10716 ASET (vector
, 2, mode_line_string_list
);
10717 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10718 ASET (vector
, 4, mode_line_string_face
);
10719 ASET (vector
, 5, mode_line_string_face_prop
);
10722 XSETBUFFER (tmp
, obuf
);
10725 ASET (vector
, 6, tmp
);
10726 ASET (vector
, 7, owin
);
10732 unwind_format_mode_line (Lisp_Object vector
)
10734 mode_line_target
= XINT (AREF (vector
, 0));
10735 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10736 mode_line_string_list
= AREF (vector
, 2);
10737 if (! EQ (AREF (vector
, 3), Qt
))
10738 mode_line_proptrans_alist
= AREF (vector
, 3);
10739 mode_line_string_face
= AREF (vector
, 4);
10740 mode_line_string_face_prop
= AREF (vector
, 5);
10742 if (!NILP (AREF (vector
, 7)))
10743 /* Select window before buffer, since it may change the buffer. */
10744 Fselect_window (AREF (vector
, 7), Qt
);
10746 if (!NILP (AREF (vector
, 6)))
10748 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10749 ASET (vector
, 6, Qnil
);
10752 Vmode_line_unwind_vector
= vector
;
10757 /* Store a single character C for the frame title in mode_line_noprop_buf.
10758 Re-allocate mode_line_noprop_buf if necessary. */
10761 store_mode_line_noprop_char (char c
)
10763 /* If output position has reached the end of the allocated buffer,
10764 increase the buffer's size. */
10765 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10767 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10768 ptrdiff_t size
= len
;
10769 mode_line_noprop_buf
=
10770 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10771 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10772 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10775 *mode_line_noprop_ptr
++ = c
;
10779 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10780 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10781 characters that yield more columns than PRECISION; PRECISION <= 0
10782 means copy the whole string. Pad with spaces until FIELD_WIDTH
10783 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10784 pad. Called from display_mode_element when it is used to build a
10788 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10790 const unsigned char *str
= (const unsigned char *) string
;
10792 ptrdiff_t dummy
, nbytes
;
10794 /* Copy at most PRECISION chars from STR. */
10795 nbytes
= strlen (string
);
10796 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10798 store_mode_line_noprop_char (*str
++);
10800 /* Fill up with spaces until FIELD_WIDTH reached. */
10801 while (field_width
> 0
10802 && n
< field_width
)
10804 store_mode_line_noprop_char (' ');
10811 /***********************************************************************
10813 ***********************************************************************/
10815 #ifdef HAVE_WINDOW_SYSTEM
10817 /* Set the title of FRAME, if it has changed. The title format is
10818 Vicon_title_format if FRAME is iconified, otherwise it is
10819 frame_title_format. */
10822 x_consider_frame_title (Lisp_Object frame
)
10824 struct frame
*f
= XFRAME (frame
);
10826 if (FRAME_WINDOW_P (f
)
10827 || FRAME_MINIBUF_ONLY_P (f
)
10828 || f
->explicit_name
)
10830 /* Do we have more than one visible frame on this X display? */
10833 ptrdiff_t title_start
;
10837 ptrdiff_t count
= SPECPDL_INDEX ();
10839 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10841 Lisp_Object other_frame
= XCAR (tail
);
10842 struct frame
*tf
= XFRAME (other_frame
);
10845 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10846 && !FRAME_MINIBUF_ONLY_P (tf
)
10847 && !EQ (other_frame
, tip_frame
)
10848 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10852 /* Set global variable indicating that multiple frames exist. */
10853 multiple_frames
= CONSP (tail
);
10855 /* Switch to the buffer of selected window of the frame. Set up
10856 mode_line_target so that display_mode_element will output into
10857 mode_line_noprop_buf; then display the title. */
10858 record_unwind_protect (unwind_format_mode_line
,
10859 format_mode_line_unwind_data
10860 (current_buffer
, selected_window
, 0));
10862 Fselect_window (f
->selected_window
, Qt
);
10863 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10864 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10866 mode_line_target
= MODE_LINE_TITLE
;
10867 title_start
= MODE_LINE_NOPROP_LEN (0);
10868 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10869 NULL
, DEFAULT_FACE_ID
);
10870 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10871 len
= MODE_LINE_NOPROP_LEN (title_start
);
10872 title
= mode_line_noprop_buf
+ title_start
;
10873 unbind_to (count
, Qnil
);
10875 /* Set the title only if it's changed. This avoids consing in
10876 the common case where it hasn't. (If it turns out that we've
10877 already wasted too much time by walking through the list with
10878 display_mode_element, then we might need to optimize at a
10879 higher level than this.) */
10880 if (! STRINGP (f
->name
)
10881 || SBYTES (f
->name
) != len
10882 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10883 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10887 #endif /* not HAVE_WINDOW_SYSTEM */
10892 /***********************************************************************
10894 ***********************************************************************/
10897 /* Prepare for redisplay by updating menu-bar item lists when
10898 appropriate. This can call eval. */
10901 prepare_menu_bars (void)
10904 struct gcpro gcpro1
, gcpro2
;
10906 Lisp_Object tooltip_frame
;
10908 #ifdef HAVE_WINDOW_SYSTEM
10909 tooltip_frame
= tip_frame
;
10911 tooltip_frame
= Qnil
;
10914 /* Update all frame titles based on their buffer names, etc. We do
10915 this before the menu bars so that the buffer-menu will show the
10916 up-to-date frame titles. */
10917 #ifdef HAVE_WINDOW_SYSTEM
10918 if (windows_or_buffers_changed
|| update_mode_lines
)
10920 Lisp_Object tail
, frame
;
10922 FOR_EACH_FRAME (tail
, frame
)
10924 f
= XFRAME (frame
);
10925 if (!EQ (frame
, tooltip_frame
)
10926 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10927 x_consider_frame_title (frame
);
10930 #endif /* HAVE_WINDOW_SYSTEM */
10932 /* Update the menu bar item lists, if appropriate. This has to be
10933 done before any actual redisplay or generation of display lines. */
10934 all_windows
= (update_mode_lines
10935 || buffer_shared
> 1
10936 || windows_or_buffers_changed
);
10939 Lisp_Object tail
, frame
;
10940 ptrdiff_t count
= SPECPDL_INDEX ();
10941 /* 1 means that update_menu_bar has run its hooks
10942 so any further calls to update_menu_bar shouldn't do so again. */
10943 int menu_bar_hooks_run
= 0;
10945 record_unwind_save_match_data ();
10947 FOR_EACH_FRAME (tail
, frame
)
10949 f
= XFRAME (frame
);
10951 /* Ignore tooltip frame. */
10952 if (EQ (frame
, tooltip_frame
))
10955 /* If a window on this frame changed size, report that to
10956 the user and clear the size-change flag. */
10957 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10959 Lisp_Object functions
;
10961 /* Clear flag first in case we get an error below. */
10962 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10963 functions
= Vwindow_size_change_functions
;
10964 GCPRO2 (tail
, functions
);
10966 while (CONSP (functions
))
10968 if (!EQ (XCAR (functions
), Qt
))
10969 call1 (XCAR (functions
), frame
);
10970 functions
= XCDR (functions
);
10976 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10977 #ifdef HAVE_WINDOW_SYSTEM
10978 update_tool_bar (f
, 0);
10981 if (windows_or_buffers_changed
10983 ns_set_doc_edited (f
, Fbuffer_modified_p
10984 (XWINDOW (f
->selected_window
)->buffer
));
10989 unbind_to (count
, Qnil
);
10993 struct frame
*sf
= SELECTED_FRAME ();
10994 update_menu_bar (sf
, 1, 0);
10995 #ifdef HAVE_WINDOW_SYSTEM
10996 update_tool_bar (sf
, 1);
11002 /* Update the menu bar item list for frame F. This has to be done
11003 before we start to fill in any display lines, because it can call
11006 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11008 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11009 already ran the menu bar hooks for this redisplay, so there
11010 is no need to run them again. The return value is the
11011 updated value of this flag, to pass to the next call. */
11014 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11016 Lisp_Object window
;
11017 register struct window
*w
;
11019 /* If called recursively during a menu update, do nothing. This can
11020 happen when, for instance, an activate-menubar-hook causes a
11022 if (inhibit_menubar_update
)
11025 window
= FRAME_SELECTED_WINDOW (f
);
11026 w
= XWINDOW (window
);
11028 if (FRAME_WINDOW_P (f
)
11030 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11031 || defined (HAVE_NS) || defined (USE_GTK)
11032 FRAME_EXTERNAL_MENU_BAR (f
)
11034 FRAME_MENU_BAR_LINES (f
) > 0
11036 : FRAME_MENU_BAR_LINES (f
) > 0)
11038 /* If the user has switched buffers or windows, we need to
11039 recompute to reflect the new bindings. But we'll
11040 recompute when update_mode_lines is set too; that means
11041 that people can use force-mode-line-update to request
11042 that the menu bar be recomputed. The adverse effect on
11043 the rest of the redisplay algorithm is about the same as
11044 windows_or_buffers_changed anyway. */
11045 if (windows_or_buffers_changed
11046 /* This used to test w->update_mode_line, but we believe
11047 there is no need to recompute the menu in that case. */
11048 || update_mode_lines
11049 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11050 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11051 != !NILP (w
->last_had_star
))
11052 || ((!NILP (Vtransient_mark_mode
)
11053 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11054 != !NILP (w
->region_showing
)))
11056 struct buffer
*prev
= current_buffer
;
11057 ptrdiff_t count
= SPECPDL_INDEX ();
11059 specbind (Qinhibit_menubar_update
, Qt
);
11061 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11062 if (save_match_data
)
11063 record_unwind_save_match_data ();
11064 if (NILP (Voverriding_local_map_menu_flag
))
11066 specbind (Qoverriding_terminal_local_map
, Qnil
);
11067 specbind (Qoverriding_local_map
, Qnil
);
11072 /* Run the Lucid hook. */
11073 safe_run_hooks (Qactivate_menubar_hook
);
11075 /* If it has changed current-menubar from previous value,
11076 really recompute the menu-bar from the value. */
11077 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11078 call0 (Qrecompute_lucid_menubar
);
11080 safe_run_hooks (Qmenu_bar_update_hook
);
11085 XSETFRAME (Vmenu_updating_frame
, f
);
11086 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11088 /* Redisplay the menu bar in case we changed it. */
11089 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11090 || defined (HAVE_NS) || defined (USE_GTK)
11091 if (FRAME_WINDOW_P (f
))
11093 #if defined (HAVE_NS)
11094 /* All frames on Mac OS share the same menubar. So only
11095 the selected frame should be allowed to set it. */
11096 if (f
== SELECTED_FRAME ())
11098 set_frame_menubar (f
, 0, 0);
11101 /* On a terminal screen, the menu bar is an ordinary screen
11102 line, and this makes it get updated. */
11103 w
->update_mode_line
= Qt
;
11104 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11105 /* In the non-toolkit version, the menu bar is an ordinary screen
11106 line, and this makes it get updated. */
11107 w
->update_mode_line
= Qt
;
11108 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11110 unbind_to (count
, Qnil
);
11111 set_buffer_internal_1 (prev
);
11120 /***********************************************************************
11122 ***********************************************************************/
11124 #ifdef HAVE_WINDOW_SYSTEM
11127 Nominal cursor position -- where to draw output.
11128 HPOS and VPOS are window relative glyph matrix coordinates.
11129 X and Y are window relative pixel coordinates. */
11131 struct cursor_pos output_cursor
;
11135 Set the global variable output_cursor to CURSOR. All cursor
11136 positions are relative to updated_window. */
11139 set_output_cursor (struct cursor_pos
*cursor
)
11141 output_cursor
.hpos
= cursor
->hpos
;
11142 output_cursor
.vpos
= cursor
->vpos
;
11143 output_cursor
.x
= cursor
->x
;
11144 output_cursor
.y
= cursor
->y
;
11149 Set a nominal cursor position.
11151 HPOS and VPOS are column/row positions in a window glyph matrix. X
11152 and Y are window text area relative pixel positions.
11154 If this is done during an update, updated_window will contain the
11155 window that is being updated and the position is the future output
11156 cursor position for that window. If updated_window is null, use
11157 selected_window and display the cursor at the given position. */
11160 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11164 /* If updated_window is not set, work on selected_window. */
11165 if (updated_window
)
11166 w
= updated_window
;
11168 w
= XWINDOW (selected_window
);
11170 /* Set the output cursor. */
11171 output_cursor
.hpos
= hpos
;
11172 output_cursor
.vpos
= vpos
;
11173 output_cursor
.x
= x
;
11174 output_cursor
.y
= y
;
11176 /* If not called as part of an update, really display the cursor.
11177 This will also set the cursor position of W. */
11178 if (updated_window
== NULL
)
11181 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11182 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11183 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11188 #endif /* HAVE_WINDOW_SYSTEM */
11191 /***********************************************************************
11193 ***********************************************************************/
11195 #ifdef HAVE_WINDOW_SYSTEM
11197 /* Where the mouse was last time we reported a mouse event. */
11199 FRAME_PTR last_mouse_frame
;
11201 /* Tool-bar item index of the item on which a mouse button was pressed
11204 int last_tool_bar_item
;
11208 update_tool_bar_unwind (Lisp_Object frame
)
11210 selected_frame
= frame
;
11214 /* Update the tool-bar item list for frame F. This has to be done
11215 before we start to fill in any display lines. Called from
11216 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11217 and restore it here. */
11220 update_tool_bar (struct frame
*f
, int save_match_data
)
11222 #if defined (USE_GTK) || defined (HAVE_NS)
11223 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11225 int do_update
= WINDOWP (f
->tool_bar_window
)
11226 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11231 Lisp_Object window
;
11234 window
= FRAME_SELECTED_WINDOW (f
);
11235 w
= XWINDOW (window
);
11237 /* If the user has switched buffers or windows, we need to
11238 recompute to reflect the new bindings. But we'll
11239 recompute when update_mode_lines is set too; that means
11240 that people can use force-mode-line-update to request
11241 that the menu bar be recomputed. The adverse effect on
11242 the rest of the redisplay algorithm is about the same as
11243 windows_or_buffers_changed anyway. */
11244 if (windows_or_buffers_changed
11245 || !NILP (w
->update_mode_line
)
11246 || update_mode_lines
11247 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11248 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11249 != !NILP (w
->last_had_star
))
11250 || ((!NILP (Vtransient_mark_mode
)
11251 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11252 != !NILP (w
->region_showing
)))
11254 struct buffer
*prev
= current_buffer
;
11255 ptrdiff_t count
= SPECPDL_INDEX ();
11256 Lisp_Object frame
, new_tool_bar
;
11257 int new_n_tool_bar
;
11258 struct gcpro gcpro1
;
11260 /* Set current_buffer to the buffer of the selected
11261 window of the frame, so that we get the right local
11263 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11265 /* Save match data, if we must. */
11266 if (save_match_data
)
11267 record_unwind_save_match_data ();
11269 /* Make sure that we don't accidentally use bogus keymaps. */
11270 if (NILP (Voverriding_local_map_menu_flag
))
11272 specbind (Qoverriding_terminal_local_map
, Qnil
);
11273 specbind (Qoverriding_local_map
, Qnil
);
11276 GCPRO1 (new_tool_bar
);
11278 /* We must temporarily set the selected frame to this frame
11279 before calling tool_bar_items, because the calculation of
11280 the tool-bar keymap uses the selected frame (see
11281 `tool-bar-make-keymap' in tool-bar.el). */
11282 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11283 XSETFRAME (frame
, f
);
11284 selected_frame
= frame
;
11286 /* Build desired tool-bar items from keymaps. */
11287 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11290 /* Redisplay the tool-bar if we changed it. */
11291 if (new_n_tool_bar
!= f
->n_tool_bar_items
11292 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11294 /* Redisplay that happens asynchronously due to an expose event
11295 may access f->tool_bar_items. Make sure we update both
11296 variables within BLOCK_INPUT so no such event interrupts. */
11298 f
->tool_bar_items
= new_tool_bar
;
11299 f
->n_tool_bar_items
= new_n_tool_bar
;
11300 w
->update_mode_line
= Qt
;
11306 unbind_to (count
, Qnil
);
11307 set_buffer_internal_1 (prev
);
11313 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11314 F's desired tool-bar contents. F->tool_bar_items must have
11315 been set up previously by calling prepare_menu_bars. */
11318 build_desired_tool_bar_string (struct frame
*f
)
11320 int i
, size
, size_needed
;
11321 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11322 Lisp_Object image
, plist
, props
;
11324 image
= plist
= props
= Qnil
;
11325 GCPRO3 (image
, plist
, props
);
11327 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11328 Otherwise, make a new string. */
11330 /* The size of the string we might be able to reuse. */
11331 size
= (STRINGP (f
->desired_tool_bar_string
)
11332 ? SCHARS (f
->desired_tool_bar_string
)
11335 /* We need one space in the string for each image. */
11336 size_needed
= f
->n_tool_bar_items
;
11338 /* Reuse f->desired_tool_bar_string, if possible. */
11339 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11340 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11341 make_number (' '));
11344 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11345 Fremove_text_properties (make_number (0), make_number (size
),
11346 props
, f
->desired_tool_bar_string
);
11349 /* Put a `display' property on the string for the images to display,
11350 put a `menu_item' property on tool-bar items with a value that
11351 is the index of the item in F's tool-bar item vector. */
11352 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11354 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11356 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11357 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11358 int hmargin
, vmargin
, relief
, idx
, end
;
11360 /* If image is a vector, choose the image according to the
11362 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11363 if (VECTORP (image
))
11367 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11368 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11371 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11372 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11374 xassert (ASIZE (image
) >= idx
);
11375 image
= AREF (image
, idx
);
11380 /* Ignore invalid image specifications. */
11381 if (!valid_image_p (image
))
11384 /* Display the tool-bar button pressed, or depressed. */
11385 plist
= Fcopy_sequence (XCDR (image
));
11387 /* Compute margin and relief to draw. */
11388 relief
= (tool_bar_button_relief
>= 0
11389 ? tool_bar_button_relief
11390 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11391 hmargin
= vmargin
= relief
;
11393 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11394 INT_MAX
- max (hmargin
, vmargin
)))
11396 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11397 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11399 else if (CONSP (Vtool_bar_button_margin
))
11401 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11402 INT_MAX
- hmargin
))
11403 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11405 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11406 INT_MAX
- vmargin
))
11407 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11410 if (auto_raise_tool_bar_buttons_p
)
11412 /* Add a `:relief' property to the image spec if the item is
11416 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11423 /* If image is selected, display it pressed, i.e. with a
11424 negative relief. If it's not selected, display it with a
11426 plist
= Fplist_put (plist
, QCrelief
,
11428 ? make_number (-relief
)
11429 : make_number (relief
)));
11434 /* Put a margin around the image. */
11435 if (hmargin
|| vmargin
)
11437 if (hmargin
== vmargin
)
11438 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11440 plist
= Fplist_put (plist
, QCmargin
,
11441 Fcons (make_number (hmargin
),
11442 make_number (vmargin
)));
11445 /* If button is not enabled, and we don't have special images
11446 for the disabled state, make the image appear disabled by
11447 applying an appropriate algorithm to it. */
11448 if (!enabled_p
&& idx
< 0)
11449 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11451 /* Put a `display' text property on the string for the image to
11452 display. Put a `menu-item' property on the string that gives
11453 the start of this item's properties in the tool-bar items
11455 image
= Fcons (Qimage
, plist
);
11456 props
= list4 (Qdisplay
, image
,
11457 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11459 /* Let the last image hide all remaining spaces in the tool bar
11460 string. The string can be longer than needed when we reuse a
11461 previous string. */
11462 if (i
+ 1 == f
->n_tool_bar_items
)
11463 end
= SCHARS (f
->desired_tool_bar_string
);
11466 Fadd_text_properties (make_number (i
), make_number (end
),
11467 props
, f
->desired_tool_bar_string
);
11475 /* Display one line of the tool-bar of frame IT->f.
11477 HEIGHT specifies the desired height of the tool-bar line.
11478 If the actual height of the glyph row is less than HEIGHT, the
11479 row's height is increased to HEIGHT, and the icons are centered
11480 vertically in the new height.
11482 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11483 count a final empty row in case the tool-bar width exactly matches
11488 display_tool_bar_line (struct it
*it
, int height
)
11490 struct glyph_row
*row
= it
->glyph_row
;
11491 int max_x
= it
->last_visible_x
;
11492 struct glyph
*last
;
11494 prepare_desired_row (row
);
11495 row
->y
= it
->current_y
;
11497 /* Note that this isn't made use of if the face hasn't a box,
11498 so there's no need to check the face here. */
11499 it
->start_of_box_run_p
= 1;
11501 while (it
->current_x
< max_x
)
11503 int x
, n_glyphs_before
, i
, nglyphs
;
11504 struct it it_before
;
11506 /* Get the next display element. */
11507 if (!get_next_display_element (it
))
11509 /* Don't count empty row if we are counting needed tool-bar lines. */
11510 if (height
< 0 && !it
->hpos
)
11515 /* Produce glyphs. */
11516 n_glyphs_before
= row
->used
[TEXT_AREA
];
11519 PRODUCE_GLYPHS (it
);
11521 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11523 x
= it_before
.current_x
;
11524 while (i
< nglyphs
)
11526 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11528 if (x
+ glyph
->pixel_width
> max_x
)
11530 /* Glyph doesn't fit on line. Backtrack. */
11531 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11533 /* If this is the only glyph on this line, it will never fit on the
11534 tool-bar, so skip it. But ensure there is at least one glyph,
11535 so we don't accidentally disable the tool-bar. */
11536 if (n_glyphs_before
== 0
11537 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11543 x
+= glyph
->pixel_width
;
11547 /* Stop at line end. */
11548 if (ITERATOR_AT_END_OF_LINE_P (it
))
11551 set_iterator_to_next (it
, 1);
11556 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11558 /* Use default face for the border below the tool bar.
11560 FIXME: When auto-resize-tool-bars is grow-only, there is
11561 no additional border below the possibly empty tool-bar lines.
11562 So to make the extra empty lines look "normal", we have to
11563 use the tool-bar face for the border too. */
11564 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11565 it
->face_id
= DEFAULT_FACE_ID
;
11567 extend_face_to_end_of_line (it
);
11568 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11569 last
->right_box_line_p
= 1;
11570 if (last
== row
->glyphs
[TEXT_AREA
])
11571 last
->left_box_line_p
= 1;
11573 /* Make line the desired height and center it vertically. */
11574 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11576 /* Don't add more than one line height. */
11577 height
%= FRAME_LINE_HEIGHT (it
->f
);
11578 it
->max_ascent
+= height
/ 2;
11579 it
->max_descent
+= (height
+ 1) / 2;
11582 compute_line_metrics (it
);
11584 /* If line is empty, make it occupy the rest of the tool-bar. */
11585 if (!row
->displays_text_p
)
11587 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11588 row
->visible_height
= row
->height
;
11589 row
->ascent
= row
->phys_ascent
= 0;
11590 row
->extra_line_spacing
= 0;
11593 row
->full_width_p
= 1;
11594 row
->continued_p
= 0;
11595 row
->truncated_on_left_p
= 0;
11596 row
->truncated_on_right_p
= 0;
11598 it
->current_x
= it
->hpos
= 0;
11599 it
->current_y
+= row
->height
;
11605 /* Max tool-bar height. */
11607 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11608 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11610 /* Value is the number of screen lines needed to make all tool-bar
11611 items of frame F visible. The number of actual rows needed is
11612 returned in *N_ROWS if non-NULL. */
11615 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11617 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11619 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11620 the desired matrix, so use (unused) mode-line row as temporary row to
11621 avoid destroying the first tool-bar row. */
11622 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11624 /* Initialize an iterator for iteration over
11625 F->desired_tool_bar_string in the tool-bar window of frame F. */
11626 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11627 it
.first_visible_x
= 0;
11628 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11629 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11630 it
.paragraph_embedding
= L2R
;
11632 while (!ITERATOR_AT_END_P (&it
))
11634 clear_glyph_row (temp_row
);
11635 it
.glyph_row
= temp_row
;
11636 display_tool_bar_line (&it
, -1);
11638 clear_glyph_row (temp_row
);
11640 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11642 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11644 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11648 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11650 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11651 (Lisp_Object frame
)
11658 frame
= selected_frame
;
11660 CHECK_FRAME (frame
);
11661 f
= XFRAME (frame
);
11663 if (WINDOWP (f
->tool_bar_window
)
11664 && (w
= XWINDOW (f
->tool_bar_window
),
11665 WINDOW_TOTAL_LINES (w
) > 0))
11667 update_tool_bar (f
, 1);
11668 if (f
->n_tool_bar_items
)
11670 build_desired_tool_bar_string (f
);
11671 nlines
= tool_bar_lines_needed (f
, NULL
);
11675 return make_number (nlines
);
11679 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11680 height should be changed. */
11683 redisplay_tool_bar (struct frame
*f
)
11687 struct glyph_row
*row
;
11689 #if defined (USE_GTK) || defined (HAVE_NS)
11690 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11691 update_frame_tool_bar (f
);
11695 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11696 do anything. This means you must start with tool-bar-lines
11697 non-zero to get the auto-sizing effect. Or in other words, you
11698 can turn off tool-bars by specifying tool-bar-lines zero. */
11699 if (!WINDOWP (f
->tool_bar_window
)
11700 || (w
= XWINDOW (f
->tool_bar_window
),
11701 WINDOW_TOTAL_LINES (w
) == 0))
11704 /* Set up an iterator for the tool-bar window. */
11705 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11706 it
.first_visible_x
= 0;
11707 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11708 row
= it
.glyph_row
;
11710 /* Build a string that represents the contents of the tool-bar. */
11711 build_desired_tool_bar_string (f
);
11712 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11713 /* FIXME: This should be controlled by a user option. But it
11714 doesn't make sense to have an R2L tool bar if the menu bar cannot
11715 be drawn also R2L, and making the menu bar R2L is tricky due
11716 toolkit-specific code that implements it. If an R2L tool bar is
11717 ever supported, display_tool_bar_line should also be augmented to
11718 call unproduce_glyphs like display_line and display_string
11720 it
.paragraph_embedding
= L2R
;
11722 if (f
->n_tool_bar_rows
== 0)
11726 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11727 nlines
!= WINDOW_TOTAL_LINES (w
)))
11730 int old_height
= WINDOW_TOTAL_LINES (w
);
11732 XSETFRAME (frame
, f
);
11733 Fmodify_frame_parameters (frame
,
11734 Fcons (Fcons (Qtool_bar_lines
,
11735 make_number (nlines
)),
11737 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11739 clear_glyph_matrix (w
->desired_matrix
);
11740 fonts_changed_p
= 1;
11746 /* Display as many lines as needed to display all tool-bar items. */
11748 if (f
->n_tool_bar_rows
> 0)
11750 int border
, rows
, height
, extra
;
11752 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11753 border
= XINT (Vtool_bar_border
);
11754 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11755 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11756 else if (EQ (Vtool_bar_border
, Qborder_width
))
11757 border
= f
->border_width
;
11763 rows
= f
->n_tool_bar_rows
;
11764 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11765 extra
= it
.last_visible_y
- border
- height
* rows
;
11767 while (it
.current_y
< it
.last_visible_y
)
11770 if (extra
> 0 && rows
-- > 0)
11772 h
= (extra
+ rows
- 1) / rows
;
11775 display_tool_bar_line (&it
, height
+ h
);
11780 while (it
.current_y
< it
.last_visible_y
)
11781 display_tool_bar_line (&it
, 0);
11784 /* It doesn't make much sense to try scrolling in the tool-bar
11785 window, so don't do it. */
11786 w
->desired_matrix
->no_scrolling_p
= 1;
11787 w
->must_be_updated_p
= 1;
11789 if (!NILP (Vauto_resize_tool_bars
))
11791 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11792 int change_height_p
= 0;
11794 /* If we couldn't display everything, change the tool-bar's
11795 height if there is room for more. */
11796 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11797 && it
.current_y
< max_tool_bar_height
)
11798 change_height_p
= 1;
11800 row
= it
.glyph_row
- 1;
11802 /* If there are blank lines at the end, except for a partially
11803 visible blank line at the end that is smaller than
11804 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11805 if (!row
->displays_text_p
11806 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11807 change_height_p
= 1;
11809 /* If row displays tool-bar items, but is partially visible,
11810 change the tool-bar's height. */
11811 if (row
->displays_text_p
11812 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11813 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11814 change_height_p
= 1;
11816 /* Resize windows as needed by changing the `tool-bar-lines'
11817 frame parameter. */
11818 if (change_height_p
)
11821 int old_height
= WINDOW_TOTAL_LINES (w
);
11823 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11825 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11826 && !f
->minimize_tool_bar_window_p
)
11827 ? (nlines
> old_height
)
11828 : (nlines
!= old_height
));
11829 f
->minimize_tool_bar_window_p
= 0;
11831 if (change_height_p
)
11833 XSETFRAME (frame
, f
);
11834 Fmodify_frame_parameters (frame
,
11835 Fcons (Fcons (Qtool_bar_lines
,
11836 make_number (nlines
)),
11838 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11840 clear_glyph_matrix (w
->desired_matrix
);
11841 f
->n_tool_bar_rows
= nrows
;
11842 fonts_changed_p
= 1;
11849 f
->minimize_tool_bar_window_p
= 0;
11854 /* Get information about the tool-bar item which is displayed in GLYPH
11855 on frame F. Return in *PROP_IDX the index where tool-bar item
11856 properties start in F->tool_bar_items. Value is zero if
11857 GLYPH doesn't display a tool-bar item. */
11860 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11866 /* This function can be called asynchronously, which means we must
11867 exclude any possibility that Fget_text_property signals an
11869 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11870 charpos
= max (0, charpos
);
11872 /* Get the text property `menu-item' at pos. The value of that
11873 property is the start index of this item's properties in
11874 F->tool_bar_items. */
11875 prop
= Fget_text_property (make_number (charpos
),
11876 Qmenu_item
, f
->current_tool_bar_string
);
11877 if (INTEGERP (prop
))
11879 *prop_idx
= XINT (prop
);
11889 /* Get information about the tool-bar item at position X/Y on frame F.
11890 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11891 the current matrix of the tool-bar window of F, or NULL if not
11892 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11893 item in F->tool_bar_items. Value is
11895 -1 if X/Y is not on a tool-bar item
11896 0 if X/Y is on the same item that was highlighted before.
11900 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11901 int *hpos
, int *vpos
, int *prop_idx
)
11903 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11904 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11907 /* Find the glyph under X/Y. */
11908 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11909 if (*glyph
== NULL
)
11912 /* Get the start of this tool-bar item's properties in
11913 f->tool_bar_items. */
11914 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11917 /* Is mouse on the highlighted item? */
11918 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11919 && *vpos
>= hlinfo
->mouse_face_beg_row
11920 && *vpos
<= hlinfo
->mouse_face_end_row
11921 && (*vpos
> hlinfo
->mouse_face_beg_row
11922 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11923 && (*vpos
< hlinfo
->mouse_face_end_row
11924 || *hpos
< hlinfo
->mouse_face_end_col
11925 || hlinfo
->mouse_face_past_end
))
11933 Handle mouse button event on the tool-bar of frame F, at
11934 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11935 0 for button release. MODIFIERS is event modifiers for button
11939 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11942 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11943 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11944 int hpos
, vpos
, prop_idx
;
11945 struct glyph
*glyph
;
11946 Lisp_Object enabled_p
;
11948 /* If not on the highlighted tool-bar item, return. */
11949 frame_to_window_pixel_xy (w
, &x
, &y
);
11950 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11953 /* If item is disabled, do nothing. */
11954 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11955 if (NILP (enabled_p
))
11960 /* Show item in pressed state. */
11961 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11962 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11963 last_tool_bar_item
= prop_idx
;
11967 Lisp_Object key
, frame
;
11968 struct input_event event
;
11969 EVENT_INIT (event
);
11971 /* Show item in released state. */
11972 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11973 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11975 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11977 XSETFRAME (frame
, f
);
11978 event
.kind
= TOOL_BAR_EVENT
;
11979 event
.frame_or_window
= frame
;
11981 kbd_buffer_store_event (&event
);
11983 event
.kind
= TOOL_BAR_EVENT
;
11984 event
.frame_or_window
= frame
;
11986 event
.modifiers
= modifiers
;
11987 kbd_buffer_store_event (&event
);
11988 last_tool_bar_item
= -1;
11993 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11994 tool-bar window-relative coordinates X/Y. Called from
11995 note_mouse_highlight. */
11998 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12000 Lisp_Object window
= f
->tool_bar_window
;
12001 struct window
*w
= XWINDOW (window
);
12002 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12003 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12005 struct glyph
*glyph
;
12006 struct glyph_row
*row
;
12008 Lisp_Object enabled_p
;
12010 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12011 int mouse_down_p
, rc
;
12013 /* Function note_mouse_highlight is called with negative X/Y
12014 values when mouse moves outside of the frame. */
12015 if (x
<= 0 || y
<= 0)
12017 clear_mouse_face (hlinfo
);
12021 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12024 /* Not on tool-bar item. */
12025 clear_mouse_face (hlinfo
);
12029 /* On same tool-bar item as before. */
12030 goto set_help_echo
;
12032 clear_mouse_face (hlinfo
);
12034 /* Mouse is down, but on different tool-bar item? */
12035 mouse_down_p
= (dpyinfo
->grabbed
12036 && f
== last_mouse_frame
12037 && FRAME_LIVE_P (f
));
12039 && last_tool_bar_item
!= prop_idx
)
12042 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12043 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12045 /* If tool-bar item is not enabled, don't highlight it. */
12046 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12047 if (!NILP (enabled_p
))
12049 /* Compute the x-position of the glyph. In front and past the
12050 image is a space. We include this in the highlighted area. */
12051 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12052 for (i
= x
= 0; i
< hpos
; ++i
)
12053 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12055 /* Record this as the current active region. */
12056 hlinfo
->mouse_face_beg_col
= hpos
;
12057 hlinfo
->mouse_face_beg_row
= vpos
;
12058 hlinfo
->mouse_face_beg_x
= x
;
12059 hlinfo
->mouse_face_beg_y
= row
->y
;
12060 hlinfo
->mouse_face_past_end
= 0;
12062 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12063 hlinfo
->mouse_face_end_row
= vpos
;
12064 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12065 hlinfo
->mouse_face_end_y
= row
->y
;
12066 hlinfo
->mouse_face_window
= window
;
12067 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12069 /* Display it as active. */
12070 show_mouse_face (hlinfo
, draw
);
12071 hlinfo
->mouse_face_image_state
= draw
;
12076 /* Set help_echo_string to a help string to display for this tool-bar item.
12077 XTread_socket does the rest. */
12078 help_echo_object
= help_echo_window
= Qnil
;
12079 help_echo_pos
= -1;
12080 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12081 if (NILP (help_echo_string
))
12082 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12085 #endif /* HAVE_WINDOW_SYSTEM */
12089 /************************************************************************
12090 Horizontal scrolling
12091 ************************************************************************/
12093 static int hscroll_window_tree (Lisp_Object
);
12094 static int hscroll_windows (Lisp_Object
);
12096 /* For all leaf windows in the window tree rooted at WINDOW, set their
12097 hscroll value so that PT is (i) visible in the window, and (ii) so
12098 that it is not within a certain margin at the window's left and
12099 right border. Value is non-zero if any window's hscroll has been
12103 hscroll_window_tree (Lisp_Object window
)
12105 int hscrolled_p
= 0;
12106 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12107 int hscroll_step_abs
= 0;
12108 double hscroll_step_rel
= 0;
12110 if (hscroll_relative_p
)
12112 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12113 if (hscroll_step_rel
< 0)
12115 hscroll_relative_p
= 0;
12116 hscroll_step_abs
= 0;
12119 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12121 hscroll_step_abs
= XINT (Vhscroll_step
);
12122 if (hscroll_step_abs
< 0)
12123 hscroll_step_abs
= 0;
12126 hscroll_step_abs
= 0;
12128 while (WINDOWP (window
))
12130 struct window
*w
= XWINDOW (window
);
12132 if (WINDOWP (w
->hchild
))
12133 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12134 else if (WINDOWP (w
->vchild
))
12135 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12136 else if (w
->cursor
.vpos
>= 0)
12139 int text_area_width
;
12140 struct glyph_row
*current_cursor_row
12141 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12142 struct glyph_row
*desired_cursor_row
12143 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12144 struct glyph_row
*cursor_row
12145 = (desired_cursor_row
->enabled_p
12146 ? desired_cursor_row
12147 : current_cursor_row
);
12148 int row_r2l_p
= cursor_row
->reversed_p
;
12150 text_area_width
= window_box_width (w
, TEXT_AREA
);
12152 /* Scroll when cursor is inside this scroll margin. */
12153 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12155 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12156 /* For left-to-right rows, hscroll when cursor is either
12157 (i) inside the right hscroll margin, or (ii) if it is
12158 inside the left margin and the window is already
12161 && ((XFASTINT (w
->hscroll
)
12162 && w
->cursor
.x
<= h_margin
)
12163 || (cursor_row
->enabled_p
12164 && cursor_row
->truncated_on_right_p
12165 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12166 /* For right-to-left rows, the logic is similar,
12167 except that rules for scrolling to left and right
12168 are reversed. E.g., if cursor.x <= h_margin, we
12169 need to hscroll "to the right" unconditionally,
12170 and that will scroll the screen to the left so as
12171 to reveal the next portion of the row. */
12173 && ((cursor_row
->enabled_p
12174 /* FIXME: It is confusing to set the
12175 truncated_on_right_p flag when R2L rows
12176 are actually truncated on the left. */
12177 && cursor_row
->truncated_on_right_p
12178 && w
->cursor
.x
<= h_margin
)
12179 || (XFASTINT (w
->hscroll
)
12180 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12184 struct buffer
*saved_current_buffer
;
12188 /* Find point in a display of infinite width. */
12189 saved_current_buffer
= current_buffer
;
12190 current_buffer
= XBUFFER (w
->buffer
);
12192 if (w
== XWINDOW (selected_window
))
12196 pt
= marker_position (w
->pointm
);
12197 pt
= max (BEGV
, pt
);
12201 /* Move iterator to pt starting at cursor_row->start in
12202 a line with infinite width. */
12203 init_to_row_start (&it
, w
, cursor_row
);
12204 it
.last_visible_x
= INFINITY
;
12205 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12206 current_buffer
= saved_current_buffer
;
12208 /* Position cursor in window. */
12209 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12210 hscroll
= max (0, (it
.current_x
12211 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12212 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12213 : (text_area_width
/ 2))))
12214 / FRAME_COLUMN_WIDTH (it
.f
);
12215 else if ((!row_r2l_p
12216 && w
->cursor
.x
>= text_area_width
- h_margin
)
12217 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12219 if (hscroll_relative_p
)
12220 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12223 wanted_x
= text_area_width
12224 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12227 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12231 if (hscroll_relative_p
)
12232 wanted_x
= text_area_width
* hscroll_step_rel
12235 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12238 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12240 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
12242 /* Don't prevent redisplay optimizations if hscroll
12243 hasn't changed, as it will unnecessarily slow down
12245 if (XFASTINT (w
->hscroll
) != hscroll
)
12247 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12248 w
->hscroll
= make_number (hscroll
);
12257 /* Value is non-zero if hscroll of any leaf window has been changed. */
12258 return hscrolled_p
;
12262 /* Set hscroll so that cursor is visible and not inside horizontal
12263 scroll margins for all windows in the tree rooted at WINDOW. See
12264 also hscroll_window_tree above. Value is non-zero if any window's
12265 hscroll has been changed. If it has, desired matrices on the frame
12266 of WINDOW are cleared. */
12269 hscroll_windows (Lisp_Object window
)
12271 int hscrolled_p
= hscroll_window_tree (window
);
12273 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12274 return hscrolled_p
;
12279 /************************************************************************
12281 ************************************************************************/
12283 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12284 to a non-zero value. This is sometimes handy to have in a debugger
12289 /* First and last unchanged row for try_window_id. */
12291 static int debug_first_unchanged_at_end_vpos
;
12292 static int debug_last_unchanged_at_beg_vpos
;
12294 /* Delta vpos and y. */
12296 static int debug_dvpos
, debug_dy
;
12298 /* Delta in characters and bytes for try_window_id. */
12300 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12302 /* Values of window_end_pos and window_end_vpos at the end of
12305 static ptrdiff_t debug_end_vpos
;
12307 /* Append a string to W->desired_matrix->method. FMT is a printf
12308 format string. If trace_redisplay_p is non-zero also printf the
12309 resulting string to stderr. */
12311 static void debug_method_add (struct window
*, char const *, ...)
12312 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12315 debug_method_add (struct window
*w
, char const *fmt
, ...)
12318 char *method
= w
->desired_matrix
->method
;
12319 int len
= strlen (method
);
12320 int size
= sizeof w
->desired_matrix
->method
;
12321 int remaining
= size
- len
- 1;
12324 va_start (ap
, fmt
);
12325 vsprintf (buffer
, fmt
, ap
);
12327 if (len
&& remaining
)
12330 --remaining
, ++len
;
12333 strncpy (method
+ len
, buffer
, remaining
);
12335 if (trace_redisplay_p
)
12336 fprintf (stderr
, "%p (%s): %s\n",
12338 ((BUFFERP (w
->buffer
)
12339 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12340 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12345 #endif /* GLYPH_DEBUG */
12348 /* Value is non-zero if all changes in window W, which displays
12349 current_buffer, are in the text between START and END. START is a
12350 buffer position, END is given as a distance from Z. Used in
12351 redisplay_internal for display optimization. */
12354 text_outside_line_unchanged_p (struct window
*w
,
12355 ptrdiff_t start
, ptrdiff_t end
)
12357 int unchanged_p
= 1;
12359 /* If text or overlays have changed, see where. */
12360 if (XFASTINT (w
->last_modified
) < MODIFF
12361 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12363 /* Gap in the line? */
12364 if (GPT
< start
|| Z
- GPT
< end
)
12367 /* Changes start in front of the line, or end after it? */
12369 && (BEG_UNCHANGED
< start
- 1
12370 || END_UNCHANGED
< end
))
12373 /* If selective display, can't optimize if changes start at the
12374 beginning of the line. */
12376 && INTEGERP (BVAR (current_buffer
, selective_display
))
12377 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12378 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12381 /* If there are overlays at the start or end of the line, these
12382 may have overlay strings with newlines in them. A change at
12383 START, for instance, may actually concern the display of such
12384 overlay strings as well, and they are displayed on different
12385 lines. So, quickly rule out this case. (For the future, it
12386 might be desirable to implement something more telling than
12387 just BEG/END_UNCHANGED.) */
12390 if (BEG
+ BEG_UNCHANGED
== start
12391 && overlay_touches_p (start
))
12393 if (END_UNCHANGED
== end
12394 && overlay_touches_p (Z
- end
))
12398 /* Under bidi reordering, adding or deleting a character in the
12399 beginning of a paragraph, before the first strong directional
12400 character, can change the base direction of the paragraph (unless
12401 the buffer specifies a fixed paragraph direction), which will
12402 require to redisplay the whole paragraph. It might be worthwhile
12403 to find the paragraph limits and widen the range of redisplayed
12404 lines to that, but for now just give up this optimization. */
12405 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12406 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12410 return unchanged_p
;
12414 /* Do a frame update, taking possible shortcuts into account. This is
12415 the main external entry point for redisplay.
12417 If the last redisplay displayed an echo area message and that message
12418 is no longer requested, we clear the echo area or bring back the
12419 mini-buffer if that is in use. */
12424 redisplay_internal ();
12429 overlay_arrow_string_or_property (Lisp_Object var
)
12433 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12436 return Voverlay_arrow_string
;
12439 /* Return 1 if there are any overlay-arrows in current_buffer. */
12441 overlay_arrow_in_current_buffer_p (void)
12445 for (vlist
= Voverlay_arrow_variable_list
;
12447 vlist
= XCDR (vlist
))
12449 Lisp_Object var
= XCAR (vlist
);
12452 if (!SYMBOLP (var
))
12454 val
= find_symbol_value (var
);
12456 && current_buffer
== XMARKER (val
)->buffer
)
12463 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12467 overlay_arrows_changed_p (void)
12471 for (vlist
= Voverlay_arrow_variable_list
;
12473 vlist
= XCDR (vlist
))
12475 Lisp_Object var
= XCAR (vlist
);
12476 Lisp_Object val
, pstr
;
12478 if (!SYMBOLP (var
))
12480 val
= find_symbol_value (var
);
12481 if (!MARKERP (val
))
12483 if (! EQ (COERCE_MARKER (val
),
12484 Fget (var
, Qlast_arrow_position
))
12485 || ! (pstr
= overlay_arrow_string_or_property (var
),
12486 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12492 /* Mark overlay arrows to be updated on next redisplay. */
12495 update_overlay_arrows (int up_to_date
)
12499 for (vlist
= Voverlay_arrow_variable_list
;
12501 vlist
= XCDR (vlist
))
12503 Lisp_Object var
= XCAR (vlist
);
12505 if (!SYMBOLP (var
))
12508 if (up_to_date
> 0)
12510 Lisp_Object val
= find_symbol_value (var
);
12511 Fput (var
, Qlast_arrow_position
,
12512 COERCE_MARKER (val
));
12513 Fput (var
, Qlast_arrow_string
,
12514 overlay_arrow_string_or_property (var
));
12516 else if (up_to_date
< 0
12517 || !NILP (Fget (var
, Qlast_arrow_position
)))
12519 Fput (var
, Qlast_arrow_position
, Qt
);
12520 Fput (var
, Qlast_arrow_string
, Qt
);
12526 /* Return overlay arrow string to display at row.
12527 Return integer (bitmap number) for arrow bitmap in left fringe.
12528 Return nil if no overlay arrow. */
12531 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12535 for (vlist
= Voverlay_arrow_variable_list
;
12537 vlist
= XCDR (vlist
))
12539 Lisp_Object var
= XCAR (vlist
);
12542 if (!SYMBOLP (var
))
12545 val
= find_symbol_value (var
);
12548 && current_buffer
== XMARKER (val
)->buffer
12549 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12551 if (FRAME_WINDOW_P (it
->f
)
12552 /* FIXME: if ROW->reversed_p is set, this should test
12553 the right fringe, not the left one. */
12554 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12556 #ifdef HAVE_WINDOW_SYSTEM
12557 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12560 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12561 return make_number (fringe_bitmap
);
12564 return make_number (-1); /* Use default arrow bitmap */
12566 return overlay_arrow_string_or_property (var
);
12573 /* Return 1 if point moved out of or into a composition. Otherwise
12574 return 0. PREV_BUF and PREV_PT are the last point buffer and
12575 position. BUF and PT are the current point buffer and position. */
12578 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12579 struct buffer
*buf
, ptrdiff_t pt
)
12581 ptrdiff_t start
, end
;
12583 Lisp_Object buffer
;
12585 XSETBUFFER (buffer
, buf
);
12586 /* Check a composition at the last point if point moved within the
12588 if (prev_buf
== buf
)
12591 /* Point didn't move. */
12594 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12595 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12596 && COMPOSITION_VALID_P (start
, end
, prop
)
12597 && start
< prev_pt
&& end
> prev_pt
)
12598 /* The last point was within the composition. Return 1 iff
12599 point moved out of the composition. */
12600 return (pt
<= start
|| pt
>= end
);
12603 /* Check a composition at the current point. */
12604 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12605 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12606 && COMPOSITION_VALID_P (start
, end
, prop
)
12607 && start
< pt
&& end
> pt
);
12611 /* Reconsider the setting of B->clip_changed which is displayed
12615 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12617 if (b
->clip_changed
12618 && !NILP (w
->window_end_valid
)
12619 && w
->current_matrix
->buffer
== b
12620 && w
->current_matrix
->zv
== BUF_ZV (b
)
12621 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12622 b
->clip_changed
= 0;
12624 /* If display wasn't paused, and W is not a tool bar window, see if
12625 point has been moved into or out of a composition. In that case,
12626 we set b->clip_changed to 1 to force updating the screen. If
12627 b->clip_changed has already been set to 1, we can skip this
12629 if (!b
->clip_changed
12630 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12634 if (w
== XWINDOW (selected_window
))
12637 pt
= marker_position (w
->pointm
);
12639 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12640 || pt
!= XINT (w
->last_point
))
12641 && check_point_in_composition (w
->current_matrix
->buffer
,
12642 XINT (w
->last_point
),
12643 XBUFFER (w
->buffer
), pt
))
12644 b
->clip_changed
= 1;
12649 /* Select FRAME to forward the values of frame-local variables into C
12650 variables so that the redisplay routines can access those values
12654 select_frame_for_redisplay (Lisp_Object frame
)
12656 Lisp_Object tail
, tem
;
12657 Lisp_Object old
= selected_frame
;
12658 struct Lisp_Symbol
*sym
;
12660 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12662 selected_frame
= frame
;
12665 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12666 if (CONSP (XCAR (tail
))
12667 && (tem
= XCAR (XCAR (tail
)),
12669 && (sym
= indirect_variable (XSYMBOL (tem
)),
12670 sym
->redirect
== SYMBOL_LOCALIZED
)
12671 && sym
->val
.blv
->frame_local
)
12672 /* Use find_symbol_value rather than Fsymbol_value
12673 to avoid an error if it is void. */
12674 find_symbol_value (tem
);
12675 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12679 #define STOP_POLLING \
12680 do { if (! polling_stopped_here) stop_polling (); \
12681 polling_stopped_here = 1; } while (0)
12683 #define RESUME_POLLING \
12684 do { if (polling_stopped_here) start_polling (); \
12685 polling_stopped_here = 0; } while (0)
12688 /* Perhaps in the future avoid recentering windows if it
12689 is not necessary; currently that causes some problems. */
12692 redisplay_internal (void)
12694 struct window
*w
= XWINDOW (selected_window
);
12698 int must_finish
= 0;
12699 struct text_pos tlbufpos
, tlendpos
;
12700 int number_of_visible_frames
;
12701 ptrdiff_t count
, count1
;
12703 int polling_stopped_here
= 0;
12704 Lisp_Object old_frame
= selected_frame
;
12706 /* Non-zero means redisplay has to consider all windows on all
12707 frames. Zero means, only selected_window is considered. */
12708 int consider_all_windows_p
;
12710 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12712 /* No redisplay if running in batch mode or frame is not yet fully
12713 initialized, or redisplay is explicitly turned off by setting
12714 Vinhibit_redisplay. */
12715 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12716 || !NILP (Vinhibit_redisplay
))
12719 /* Don't examine these until after testing Vinhibit_redisplay.
12720 When Emacs is shutting down, perhaps because its connection to
12721 X has dropped, we should not look at them at all. */
12722 fr
= XFRAME (w
->frame
);
12723 sf
= SELECTED_FRAME ();
12725 if (!fr
->glyphs_initialized_p
)
12728 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12729 if (popup_activated ())
12733 /* I don't think this happens but let's be paranoid. */
12734 if (redisplaying_p
)
12737 /* Record a function that resets redisplaying_p to its old value
12738 when we leave this function. */
12739 count
= SPECPDL_INDEX ();
12740 record_unwind_protect (unwind_redisplay
,
12741 Fcons (make_number (redisplaying_p
), selected_frame
));
12743 specbind (Qinhibit_free_realized_faces
, Qnil
);
12746 Lisp_Object tail
, frame
;
12748 FOR_EACH_FRAME (tail
, frame
)
12750 struct frame
*f
= XFRAME (frame
);
12751 f
->already_hscrolled_p
= 0;
12756 /* Remember the currently selected window. */
12759 if (!EQ (old_frame
, selected_frame
)
12760 && FRAME_LIVE_P (XFRAME (old_frame
)))
12761 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12762 selected_frame and selected_window to be temporarily out-of-sync so
12763 when we come back here via `goto retry', we need to resync because we
12764 may need to run Elisp code (via prepare_menu_bars). */
12765 select_frame_for_redisplay (old_frame
);
12768 reconsider_clip_changes (w
, current_buffer
);
12769 last_escape_glyph_frame
= NULL
;
12770 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12771 last_glyphless_glyph_frame
= NULL
;
12772 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12774 /* If new fonts have been loaded that make a glyph matrix adjustment
12775 necessary, do it. */
12776 if (fonts_changed_p
)
12778 adjust_glyphs (NULL
);
12779 ++windows_or_buffers_changed
;
12780 fonts_changed_p
= 0;
12783 /* If face_change_count is non-zero, init_iterator will free all
12784 realized faces, which includes the faces referenced from current
12785 matrices. So, we can't reuse current matrices in this case. */
12786 if (face_change_count
)
12787 ++windows_or_buffers_changed
;
12789 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12790 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12792 /* Since frames on a single ASCII terminal share the same
12793 display area, displaying a different frame means redisplay
12794 the whole thing. */
12795 windows_or_buffers_changed
++;
12796 SET_FRAME_GARBAGED (sf
);
12798 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12800 FRAME_TTY (sf
)->previous_frame
= sf
;
12803 /* Set the visible flags for all frames. Do this before checking
12804 for resized or garbaged frames; they want to know if their frames
12805 are visible. See the comment in frame.h for
12806 FRAME_SAMPLE_VISIBILITY. */
12808 Lisp_Object tail
, frame
;
12810 number_of_visible_frames
= 0;
12812 FOR_EACH_FRAME (tail
, frame
)
12814 struct frame
*f
= XFRAME (frame
);
12816 FRAME_SAMPLE_VISIBILITY (f
);
12817 if (FRAME_VISIBLE_P (f
))
12818 ++number_of_visible_frames
;
12819 clear_desired_matrices (f
);
12823 /* Notice any pending interrupt request to change frame size. */
12824 do_pending_window_change (1);
12826 /* do_pending_window_change could change the selected_window due to
12827 frame resizing which makes the selected window too small. */
12828 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12831 reconsider_clip_changes (w
, current_buffer
);
12834 /* Clear frames marked as garbaged. */
12835 if (frame_garbaged
)
12836 clear_garbaged_frames ();
12838 /* Build menubar and tool-bar items. */
12839 if (NILP (Vmemory_full
))
12840 prepare_menu_bars ();
12842 if (windows_or_buffers_changed
)
12843 update_mode_lines
++;
12845 /* Detect case that we need to write or remove a star in the mode line. */
12846 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12848 w
->update_mode_line
= Qt
;
12849 if (buffer_shared
> 1)
12850 update_mode_lines
++;
12853 /* Avoid invocation of point motion hooks by `current_column' below. */
12854 count1
= SPECPDL_INDEX ();
12855 specbind (Qinhibit_point_motion_hooks
, Qt
);
12857 /* If %c is in the mode line, update it if needed. */
12858 if (!NILP (w
->column_number_displayed
)
12859 /* This alternative quickly identifies a common case
12860 where no change is needed. */
12861 && !(PT
== XFASTINT (w
->last_point
)
12862 && XFASTINT (w
->last_modified
) >= MODIFF
12863 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12864 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12865 w
->update_mode_line
= Qt
;
12867 unbind_to (count1
, Qnil
);
12869 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12871 /* The variable buffer_shared is set in redisplay_window and
12872 indicates that we redisplay a buffer in different windows. See
12874 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12875 || cursor_type_changed
);
12877 /* If specs for an arrow have changed, do thorough redisplay
12878 to ensure we remove any arrow that should no longer exist. */
12879 if (overlay_arrows_changed_p ())
12880 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12882 /* Normally the message* functions will have already displayed and
12883 updated the echo area, but the frame may have been trashed, or
12884 the update may have been preempted, so display the echo area
12885 again here. Checking message_cleared_p captures the case that
12886 the echo area should be cleared. */
12887 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12888 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12889 || (message_cleared_p
12890 && minibuf_level
== 0
12891 /* If the mini-window is currently selected, this means the
12892 echo-area doesn't show through. */
12893 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12895 int window_height_changed_p
= echo_area_display (0);
12898 /* If we don't display the current message, don't clear the
12899 message_cleared_p flag, because, if we did, we wouldn't clear
12900 the echo area in the next redisplay which doesn't preserve
12902 if (!display_last_displayed_message_p
)
12903 message_cleared_p
= 0;
12905 if (fonts_changed_p
)
12907 else if (window_height_changed_p
)
12909 consider_all_windows_p
= 1;
12910 ++update_mode_lines
;
12911 ++windows_or_buffers_changed
;
12913 /* If window configuration was changed, frames may have been
12914 marked garbaged. Clear them or we will experience
12915 surprises wrt scrolling. */
12916 if (frame_garbaged
)
12917 clear_garbaged_frames ();
12920 else if (EQ (selected_window
, minibuf_window
)
12921 && (current_buffer
->clip_changed
12922 || XFASTINT (w
->last_modified
) < MODIFF
12923 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12924 && resize_mini_window (w
, 0))
12926 /* Resized active mini-window to fit the size of what it is
12927 showing if its contents might have changed. */
12929 /* FIXME: this causes all frames to be updated, which seems unnecessary
12930 since only the current frame needs to be considered. This function needs
12931 to be rewritten with two variables, consider_all_windows and
12932 consider_all_frames. */
12933 consider_all_windows_p
= 1;
12934 ++windows_or_buffers_changed
;
12935 ++update_mode_lines
;
12937 /* If window configuration was changed, frames may have been
12938 marked garbaged. Clear them or we will experience
12939 surprises wrt scrolling. */
12940 if (frame_garbaged
)
12941 clear_garbaged_frames ();
12945 /* If showing the region, and mark has changed, we must redisplay
12946 the whole window. The assignment to this_line_start_pos prevents
12947 the optimization directly below this if-statement. */
12948 if (((!NILP (Vtransient_mark_mode
)
12949 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12950 != !NILP (w
->region_showing
))
12951 || (!NILP (w
->region_showing
)
12952 && !EQ (w
->region_showing
,
12953 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12954 CHARPOS (this_line_start_pos
) = 0;
12956 /* Optimize the case that only the line containing the cursor in the
12957 selected window has changed. Variables starting with this_ are
12958 set in display_line and record information about the line
12959 containing the cursor. */
12960 tlbufpos
= this_line_start_pos
;
12961 tlendpos
= this_line_end_pos
;
12962 if (!consider_all_windows_p
12963 && CHARPOS (tlbufpos
) > 0
12964 && NILP (w
->update_mode_line
)
12965 && !current_buffer
->clip_changed
12966 && !current_buffer
->prevent_redisplay_optimizations_p
12967 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12968 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12969 /* Make sure recorded data applies to current buffer, etc. */
12970 && this_line_buffer
== current_buffer
12971 && current_buffer
== XBUFFER (w
->buffer
)
12972 && NILP (w
->force_start
)
12973 && NILP (w
->optional_new_start
)
12974 /* Point must be on the line that we have info recorded about. */
12975 && PT
>= CHARPOS (tlbufpos
)
12976 && PT
<= Z
- CHARPOS (tlendpos
)
12977 /* All text outside that line, including its final newline,
12978 must be unchanged. */
12979 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12980 CHARPOS (tlendpos
)))
12982 if (CHARPOS (tlbufpos
) > BEGV
12983 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12984 && (CHARPOS (tlbufpos
) == ZV
12985 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12986 /* Former continuation line has disappeared by becoming empty. */
12988 else if (XFASTINT (w
->last_modified
) < MODIFF
12989 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12990 || MINI_WINDOW_P (w
))
12992 /* We have to handle the case of continuation around a
12993 wide-column character (see the comment in indent.c around
12996 For instance, in the following case:
12998 -------- Insert --------
12999 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13000 J_I_ ==> J_I_ `^^' are cursors.
13004 As we have to redraw the line above, we cannot use this
13008 int line_height_before
= this_line_pixel_height
;
13010 /* Note that start_display will handle the case that the
13011 line starting at tlbufpos is a continuation line. */
13012 start_display (&it
, w
, tlbufpos
);
13014 /* Implementation note: It this still necessary? */
13015 if (it
.current_x
!= this_line_start_x
)
13018 TRACE ((stderr
, "trying display optimization 1\n"));
13019 w
->cursor
.vpos
= -1;
13020 overlay_arrow_seen
= 0;
13021 it
.vpos
= this_line_vpos
;
13022 it
.current_y
= this_line_y
;
13023 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13024 display_line (&it
);
13026 /* If line contains point, is not continued,
13027 and ends at same distance from eob as before, we win. */
13028 if (w
->cursor
.vpos
>= 0
13029 /* Line is not continued, otherwise this_line_start_pos
13030 would have been set to 0 in display_line. */
13031 && CHARPOS (this_line_start_pos
)
13032 /* Line ends as before. */
13033 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13034 /* Line has same height as before. Otherwise other lines
13035 would have to be shifted up or down. */
13036 && this_line_pixel_height
== line_height_before
)
13038 /* If this is not the window's last line, we must adjust
13039 the charstarts of the lines below. */
13040 if (it
.current_y
< it
.last_visible_y
)
13042 struct glyph_row
*row
13043 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13044 ptrdiff_t delta
, delta_bytes
;
13046 /* We used to distinguish between two cases here,
13047 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13048 when the line ends in a newline or the end of the
13049 buffer's accessible portion. But both cases did
13050 the same, so they were collapsed. */
13052 - CHARPOS (tlendpos
)
13053 - MATRIX_ROW_START_CHARPOS (row
));
13054 delta_bytes
= (Z_BYTE
13055 - BYTEPOS (tlendpos
)
13056 - MATRIX_ROW_START_BYTEPOS (row
));
13058 increment_matrix_positions (w
->current_matrix
,
13059 this_line_vpos
+ 1,
13060 w
->current_matrix
->nrows
,
13061 delta
, delta_bytes
);
13064 /* If this row displays text now but previously didn't,
13065 or vice versa, w->window_end_vpos may have to be
13067 if ((it
.glyph_row
- 1)->displays_text_p
)
13069 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13070 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13072 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13073 && this_line_vpos
> 0)
13074 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13075 w
->window_end_valid
= Qnil
;
13077 /* Update hint: No need to try to scroll in update_window. */
13078 w
->desired_matrix
->no_scrolling_p
= 1;
13081 *w
->desired_matrix
->method
= 0;
13082 debug_method_add (w
, "optimization 1");
13084 #ifdef HAVE_WINDOW_SYSTEM
13085 update_window_fringes (w
, 0);
13092 else if (/* Cursor position hasn't changed. */
13093 PT
== XFASTINT (w
->last_point
)
13094 /* Make sure the cursor was last displayed
13095 in this window. Otherwise we have to reposition it. */
13096 && 0 <= w
->cursor
.vpos
13097 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13101 do_pending_window_change (1);
13102 /* If selected_window changed, redisplay again. */
13103 if (WINDOWP (selected_window
)
13104 && (w
= XWINDOW (selected_window
)) != sw
)
13107 /* We used to always goto end_of_redisplay here, but this
13108 isn't enough if we have a blinking cursor. */
13109 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13110 goto end_of_redisplay
;
13114 /* If highlighting the region, or if the cursor is in the echo area,
13115 then we can't just move the cursor. */
13116 else if (! (!NILP (Vtransient_mark_mode
)
13117 && !NILP (BVAR (current_buffer
, mark_active
)))
13118 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
13119 || highlight_nonselected_windows
)
13120 && NILP (w
->region_showing
)
13121 && NILP (Vshow_trailing_whitespace
)
13122 && !cursor_in_echo_area
)
13125 struct glyph_row
*row
;
13127 /* Skip from tlbufpos to PT and see where it is. Note that
13128 PT may be in invisible text. If so, we will end at the
13129 next visible position. */
13130 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13131 NULL
, DEFAULT_FACE_ID
);
13132 it
.current_x
= this_line_start_x
;
13133 it
.current_y
= this_line_y
;
13134 it
.vpos
= this_line_vpos
;
13136 /* The call to move_it_to stops in front of PT, but
13137 moves over before-strings. */
13138 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13140 if (it
.vpos
== this_line_vpos
13141 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13144 xassert (this_line_vpos
== it
.vpos
);
13145 xassert (this_line_y
== it
.current_y
);
13146 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13148 *w
->desired_matrix
->method
= 0;
13149 debug_method_add (w
, "optimization 3");
13158 /* Text changed drastically or point moved off of line. */
13159 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13162 CHARPOS (this_line_start_pos
) = 0;
13163 consider_all_windows_p
|= buffer_shared
> 1;
13164 ++clear_face_cache_count
;
13165 #ifdef HAVE_WINDOW_SYSTEM
13166 ++clear_image_cache_count
;
13169 /* Build desired matrices, and update the display. If
13170 consider_all_windows_p is non-zero, do it for all windows on all
13171 frames. Otherwise do it for selected_window, only. */
13173 if (consider_all_windows_p
)
13175 Lisp_Object tail
, frame
;
13177 FOR_EACH_FRAME (tail
, frame
)
13178 XFRAME (frame
)->updated_p
= 0;
13180 /* Recompute # windows showing selected buffer. This will be
13181 incremented each time such a window is displayed. */
13184 FOR_EACH_FRAME (tail
, frame
)
13186 struct frame
*f
= XFRAME (frame
);
13188 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13190 if (! EQ (frame
, selected_frame
))
13191 /* Select the frame, for the sake of frame-local
13193 select_frame_for_redisplay (frame
);
13195 /* Mark all the scroll bars to be removed; we'll redeem
13196 the ones we want when we redisplay their windows. */
13197 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13198 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13200 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13201 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13203 /* The X error handler may have deleted that frame. */
13204 if (!FRAME_LIVE_P (f
))
13207 /* Any scroll bars which redisplay_windows should have
13208 nuked should now go away. */
13209 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13210 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13212 /* If fonts changed, display again. */
13213 /* ??? rms: I suspect it is a mistake to jump all the way
13214 back to retry here. It should just retry this frame. */
13215 if (fonts_changed_p
)
13218 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13220 /* See if we have to hscroll. */
13221 if (!f
->already_hscrolled_p
)
13223 f
->already_hscrolled_p
= 1;
13224 if (hscroll_windows (f
->root_window
))
13228 /* Prevent various kinds of signals during display
13229 update. stdio is not robust about handling
13230 signals, which can cause an apparent I/O
13232 if (interrupt_input
)
13233 unrequest_sigio ();
13236 /* Update the display. */
13237 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13238 pending
|= update_frame (f
, 0, 0);
13244 if (!EQ (old_frame
, selected_frame
)
13245 && FRAME_LIVE_P (XFRAME (old_frame
)))
13246 /* We played a bit fast-and-loose above and allowed selected_frame
13247 and selected_window to be temporarily out-of-sync but let's make
13248 sure this stays contained. */
13249 select_frame_for_redisplay (old_frame
);
13250 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13254 /* Do the mark_window_display_accurate after all windows have
13255 been redisplayed because this call resets flags in buffers
13256 which are needed for proper redisplay. */
13257 FOR_EACH_FRAME (tail
, frame
)
13259 struct frame
*f
= XFRAME (frame
);
13262 mark_window_display_accurate (f
->root_window
, 1);
13263 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13264 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13269 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13271 Lisp_Object mini_window
;
13272 struct frame
*mini_frame
;
13274 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13275 /* Use list_of_error, not Qerror, so that
13276 we catch only errors and don't run the debugger. */
13277 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13279 redisplay_window_error
);
13281 /* Compare desired and current matrices, perform output. */
13284 /* If fonts changed, display again. */
13285 if (fonts_changed_p
)
13288 /* Prevent various kinds of signals during display update.
13289 stdio is not robust about handling signals,
13290 which can cause an apparent I/O error. */
13291 if (interrupt_input
)
13292 unrequest_sigio ();
13295 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13297 if (hscroll_windows (selected_window
))
13300 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13301 pending
= update_frame (sf
, 0, 0);
13304 /* We may have called echo_area_display at the top of this
13305 function. If the echo area is on another frame, that may
13306 have put text on a frame other than the selected one, so the
13307 above call to update_frame would not have caught it. Catch
13309 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13310 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13312 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13314 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13315 pending
|= update_frame (mini_frame
, 0, 0);
13316 if (!pending
&& hscroll_windows (mini_window
))
13321 /* If display was paused because of pending input, make sure we do a
13322 thorough update the next time. */
13325 /* Prevent the optimization at the beginning of
13326 redisplay_internal that tries a single-line update of the
13327 line containing the cursor in the selected window. */
13328 CHARPOS (this_line_start_pos
) = 0;
13330 /* Let the overlay arrow be updated the next time. */
13331 update_overlay_arrows (0);
13333 /* If we pause after scrolling, some rows in the current
13334 matrices of some windows are not valid. */
13335 if (!WINDOW_FULL_WIDTH_P (w
)
13336 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13337 update_mode_lines
= 1;
13341 if (!consider_all_windows_p
)
13343 /* This has already been done above if
13344 consider_all_windows_p is set. */
13345 mark_window_display_accurate_1 (w
, 1);
13347 /* Say overlay arrows are up to date. */
13348 update_overlay_arrows (1);
13350 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13351 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13354 update_mode_lines
= 0;
13355 windows_or_buffers_changed
= 0;
13356 cursor_type_changed
= 0;
13359 /* Start SIGIO interrupts coming again. Having them off during the
13360 code above makes it less likely one will discard output, but not
13361 impossible, since there might be stuff in the system buffer here.
13362 But it is much hairier to try to do anything about that. */
13363 if (interrupt_input
)
13367 /* If a frame has become visible which was not before, redisplay
13368 again, so that we display it. Expose events for such a frame
13369 (which it gets when becoming visible) don't call the parts of
13370 redisplay constructing glyphs, so simply exposing a frame won't
13371 display anything in this case. So, we have to display these
13372 frames here explicitly. */
13375 Lisp_Object tail
, frame
;
13378 FOR_EACH_FRAME (tail
, frame
)
13380 int this_is_visible
= 0;
13382 if (XFRAME (frame
)->visible
)
13383 this_is_visible
= 1;
13384 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13385 if (XFRAME (frame
)->visible
)
13386 this_is_visible
= 1;
13388 if (this_is_visible
)
13392 if (new_count
!= number_of_visible_frames
)
13393 windows_or_buffers_changed
++;
13396 /* Change frame size now if a change is pending. */
13397 do_pending_window_change (1);
13399 /* If we just did a pending size change, or have additional
13400 visible frames, or selected_window changed, redisplay again. */
13401 if ((windows_or_buffers_changed
&& !pending
)
13402 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13405 /* Clear the face and image caches.
13407 We used to do this only if consider_all_windows_p. But the cache
13408 needs to be cleared if a timer creates images in the current
13409 buffer (e.g. the test case in Bug#6230). */
13411 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13413 clear_face_cache (0);
13414 clear_face_cache_count
= 0;
13417 #ifdef HAVE_WINDOW_SYSTEM
13418 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13420 clear_image_caches (Qnil
);
13421 clear_image_cache_count
= 0;
13423 #endif /* HAVE_WINDOW_SYSTEM */
13426 unbind_to (count
, Qnil
);
13431 /* Redisplay, but leave alone any recent echo area message unless
13432 another message has been requested in its place.
13434 This is useful in situations where you need to redisplay but no
13435 user action has occurred, making it inappropriate for the message
13436 area to be cleared. See tracking_off and
13437 wait_reading_process_output for examples of these situations.
13439 FROM_WHERE is an integer saying from where this function was
13440 called. This is useful for debugging. */
13443 redisplay_preserve_echo_area (int from_where
)
13445 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13447 if (!NILP (echo_area_buffer
[1]))
13449 /* We have a previously displayed message, but no current
13450 message. Redisplay the previous message. */
13451 display_last_displayed_message_p
= 1;
13452 redisplay_internal ();
13453 display_last_displayed_message_p
= 0;
13456 redisplay_internal ();
13458 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13459 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13460 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13464 /* Function registered with record_unwind_protect in
13465 redisplay_internal. Reset redisplaying_p to the value it had
13466 before redisplay_internal was called, and clear
13467 prevent_freeing_realized_faces_p. It also selects the previously
13468 selected frame, unless it has been deleted (by an X connection
13469 failure during redisplay, for example). */
13472 unwind_redisplay (Lisp_Object val
)
13474 Lisp_Object old_redisplaying_p
, old_frame
;
13476 old_redisplaying_p
= XCAR (val
);
13477 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13478 old_frame
= XCDR (val
);
13479 if (! EQ (old_frame
, selected_frame
)
13480 && FRAME_LIVE_P (XFRAME (old_frame
)))
13481 select_frame_for_redisplay (old_frame
);
13486 /* Mark the display of window W as accurate or inaccurate. If
13487 ACCURATE_P is non-zero mark display of W as accurate. If
13488 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13489 redisplay_internal is called. */
13492 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13494 if (BUFFERP (w
->buffer
))
13496 struct buffer
*b
= XBUFFER (w
->buffer
);
13499 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
13500 w
->last_overlay_modified
13501 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
13503 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
13507 b
->clip_changed
= 0;
13508 b
->prevent_redisplay_optimizations_p
= 0;
13510 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13511 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13512 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13513 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13515 w
->current_matrix
->buffer
= b
;
13516 w
->current_matrix
->begv
= BUF_BEGV (b
);
13517 w
->current_matrix
->zv
= BUF_ZV (b
);
13519 w
->last_cursor
= w
->cursor
;
13520 w
->last_cursor_off_p
= w
->cursor_off_p
;
13522 if (w
== XWINDOW (selected_window
))
13523 w
->last_point
= make_number (BUF_PT (b
));
13525 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
13531 w
->window_end_valid
= w
->buffer
;
13532 w
->update_mode_line
= Qnil
;
13537 /* Mark the display of windows in the window tree rooted at WINDOW as
13538 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13539 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13540 be redisplayed the next time redisplay_internal is called. */
13543 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13547 for (; !NILP (window
); window
= w
->next
)
13549 w
= XWINDOW (window
);
13550 mark_window_display_accurate_1 (w
, accurate_p
);
13552 if (!NILP (w
->vchild
))
13553 mark_window_display_accurate (w
->vchild
, accurate_p
);
13554 if (!NILP (w
->hchild
))
13555 mark_window_display_accurate (w
->hchild
, accurate_p
);
13560 update_overlay_arrows (1);
13564 /* Force a thorough redisplay the next time by setting
13565 last_arrow_position and last_arrow_string to t, which is
13566 unequal to any useful value of Voverlay_arrow_... */
13567 update_overlay_arrows (-1);
13572 /* Return value in display table DP (Lisp_Char_Table *) for character
13573 C. Since a display table doesn't have any parent, we don't have to
13574 follow parent. Do not call this function directly but use the
13575 macro DISP_CHAR_VECTOR. */
13578 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13582 if (ASCII_CHAR_P (c
))
13585 if (SUB_CHAR_TABLE_P (val
))
13586 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13592 XSETCHAR_TABLE (table
, dp
);
13593 val
= char_table_ref (table
, c
);
13602 /***********************************************************************
13604 ***********************************************************************/
13606 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13609 redisplay_windows (Lisp_Object window
)
13611 while (!NILP (window
))
13613 struct window
*w
= XWINDOW (window
);
13615 if (!NILP (w
->hchild
))
13616 redisplay_windows (w
->hchild
);
13617 else if (!NILP (w
->vchild
))
13618 redisplay_windows (w
->vchild
);
13619 else if (!NILP (w
->buffer
))
13621 displayed_buffer
= XBUFFER (w
->buffer
);
13622 /* Use list_of_error, not Qerror, so that
13623 we catch only errors and don't run the debugger. */
13624 internal_condition_case_1 (redisplay_window_0
, window
,
13626 redisplay_window_error
);
13634 redisplay_window_error (Lisp_Object ignore
)
13636 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13641 redisplay_window_0 (Lisp_Object window
)
13643 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13644 redisplay_window (window
, 0);
13649 redisplay_window_1 (Lisp_Object window
)
13651 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13652 redisplay_window (window
, 1);
13657 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13658 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13659 which positions recorded in ROW differ from current buffer
13662 Return 0 if cursor is not on this row, 1 otherwise. */
13665 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13666 struct glyph_matrix
*matrix
,
13667 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13670 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13671 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13672 struct glyph
*cursor
= NULL
;
13673 /* The last known character position in row. */
13674 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13676 ptrdiff_t pt_old
= PT
- delta
;
13677 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13678 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13679 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13680 /* A glyph beyond the edge of TEXT_AREA which we should never
13682 struct glyph
*glyphs_end
= end
;
13683 /* Non-zero means we've found a match for cursor position, but that
13684 glyph has the avoid_cursor_p flag set. */
13685 int match_with_avoid_cursor
= 0;
13686 /* Non-zero means we've seen at least one glyph that came from a
13688 int string_seen
= 0;
13689 /* Largest and smallest buffer positions seen so far during scan of
13691 ptrdiff_t bpos_max
= pos_before
;
13692 ptrdiff_t bpos_min
= pos_after
;
13693 /* Last buffer position covered by an overlay string with an integer
13694 `cursor' property. */
13695 ptrdiff_t bpos_covered
= 0;
13696 /* Non-zero means the display string on which to display the cursor
13697 comes from a text property, not from an overlay. */
13698 int string_from_text_prop
= 0;
13700 /* Don't even try doing anything if called for a mode-line or
13701 header-line row, since the rest of the code isn't prepared to
13702 deal with such calamities. */
13703 xassert (!row
->mode_line_p
);
13704 if (row
->mode_line_p
)
13707 /* Skip over glyphs not having an object at the start and the end of
13708 the row. These are special glyphs like truncation marks on
13709 terminal frames. */
13710 if (row
->displays_text_p
)
13712 if (!row
->reversed_p
)
13715 && INTEGERP (glyph
->object
)
13716 && glyph
->charpos
< 0)
13718 x
+= glyph
->pixel_width
;
13722 && INTEGERP ((end
- 1)->object
)
13723 /* CHARPOS is zero for blanks and stretch glyphs
13724 inserted by extend_face_to_end_of_line. */
13725 && (end
- 1)->charpos
<= 0)
13727 glyph_before
= glyph
- 1;
13734 /* If the glyph row is reversed, we need to process it from back
13735 to front, so swap the edge pointers. */
13736 glyphs_end
= end
= glyph
- 1;
13737 glyph
+= row
->used
[TEXT_AREA
] - 1;
13739 while (glyph
> end
+ 1
13740 && INTEGERP (glyph
->object
)
13741 && glyph
->charpos
< 0)
13744 x
-= glyph
->pixel_width
;
13746 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13748 /* By default, in reversed rows we put the cursor on the
13749 rightmost (first in the reading order) glyph. */
13750 for (g
= end
+ 1; g
< glyph
; g
++)
13751 x
+= g
->pixel_width
;
13753 && INTEGERP ((end
+ 1)->object
)
13754 && (end
+ 1)->charpos
<= 0)
13756 glyph_before
= glyph
+ 1;
13760 else if (row
->reversed_p
)
13762 /* In R2L rows that don't display text, put the cursor on the
13763 rightmost glyph. Case in point: an empty last line that is
13764 part of an R2L paragraph. */
13766 /* Avoid placing the cursor on the last glyph of the row, where
13767 on terminal frames we hold the vertical border between
13768 adjacent windows. */
13769 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13770 && !WINDOW_RIGHTMOST_P (w
)
13771 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13773 x
= -1; /* will be computed below, at label compute_x */
13776 /* Step 1: Try to find the glyph whose character position
13777 corresponds to point. If that's not possible, find 2 glyphs
13778 whose character positions are the closest to point, one before
13779 point, the other after it. */
13780 if (!row
->reversed_p
)
13781 while (/* not marched to end of glyph row */
13783 /* glyph was not inserted by redisplay for internal purposes */
13784 && !INTEGERP (glyph
->object
))
13786 if (BUFFERP (glyph
->object
))
13788 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13790 if (glyph
->charpos
> bpos_max
)
13791 bpos_max
= glyph
->charpos
;
13792 if (glyph
->charpos
< bpos_min
)
13793 bpos_min
= glyph
->charpos
;
13794 if (!glyph
->avoid_cursor_p
)
13796 /* If we hit point, we've found the glyph on which to
13797 display the cursor. */
13800 match_with_avoid_cursor
= 0;
13803 /* See if we've found a better approximation to
13804 POS_BEFORE or to POS_AFTER. Note that we want the
13805 first (leftmost) glyph of all those that are the
13806 closest from below, and the last (rightmost) of all
13807 those from above. */
13808 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13810 pos_before
= glyph
->charpos
;
13811 glyph_before
= glyph
;
13813 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13815 pos_after
= glyph
->charpos
;
13816 glyph_after
= glyph
;
13819 else if (dpos
== 0)
13820 match_with_avoid_cursor
= 1;
13822 else if (STRINGP (glyph
->object
))
13824 Lisp_Object chprop
;
13825 ptrdiff_t glyph_pos
= glyph
->charpos
;
13827 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13829 if (!NILP (chprop
))
13831 /* If the string came from a `display' text property,
13832 look up the buffer position of that property and
13833 use that position to update bpos_max, as if we
13834 actually saw such a position in one of the row's
13835 glyphs. This helps with supporting integer values
13836 of `cursor' property on the display string in
13837 situations where most or all of the row's buffer
13838 text is completely covered by display properties,
13839 so that no glyph with valid buffer positions is
13840 ever seen in the row. */
13841 ptrdiff_t prop_pos
=
13842 string_buffer_position_lim (glyph
->object
, pos_before
,
13845 if (prop_pos
>= pos_before
)
13846 bpos_max
= prop_pos
- 1;
13848 if (INTEGERP (chprop
))
13850 bpos_covered
= bpos_max
+ XINT (chprop
);
13851 /* If the `cursor' property covers buffer positions up
13852 to and including point, we should display cursor on
13853 this glyph. Note that, if a `cursor' property on one
13854 of the string's characters has an integer value, we
13855 will break out of the loop below _before_ we get to
13856 the position match above. IOW, integer values of
13857 the `cursor' property override the "exact match for
13858 point" strategy of positioning the cursor. */
13859 /* Implementation note: bpos_max == pt_old when, e.g.,
13860 we are in an empty line, where bpos_max is set to
13861 MATRIX_ROW_START_CHARPOS, see above. */
13862 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13871 x
+= glyph
->pixel_width
;
13874 else if (glyph
> end
) /* row is reversed */
13875 while (!INTEGERP (glyph
->object
))
13877 if (BUFFERP (glyph
->object
))
13879 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13881 if (glyph
->charpos
> bpos_max
)
13882 bpos_max
= glyph
->charpos
;
13883 if (glyph
->charpos
< bpos_min
)
13884 bpos_min
= glyph
->charpos
;
13885 if (!glyph
->avoid_cursor_p
)
13889 match_with_avoid_cursor
= 0;
13892 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13894 pos_before
= glyph
->charpos
;
13895 glyph_before
= glyph
;
13897 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13899 pos_after
= glyph
->charpos
;
13900 glyph_after
= glyph
;
13903 else if (dpos
== 0)
13904 match_with_avoid_cursor
= 1;
13906 else if (STRINGP (glyph
->object
))
13908 Lisp_Object chprop
;
13909 ptrdiff_t glyph_pos
= glyph
->charpos
;
13911 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13913 if (!NILP (chprop
))
13915 ptrdiff_t prop_pos
=
13916 string_buffer_position_lim (glyph
->object
, pos_before
,
13919 if (prop_pos
>= pos_before
)
13920 bpos_max
= prop_pos
- 1;
13922 if (INTEGERP (chprop
))
13924 bpos_covered
= bpos_max
+ XINT (chprop
);
13925 /* If the `cursor' property covers buffer positions up
13926 to and including point, we should display cursor on
13928 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13937 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13939 x
--; /* can't use any pixel_width */
13942 x
-= glyph
->pixel_width
;
13945 /* Step 2: If we didn't find an exact match for point, we need to
13946 look for a proper place to put the cursor among glyphs between
13947 GLYPH_BEFORE and GLYPH_AFTER. */
13948 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13949 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13950 && bpos_covered
< pt_old
)
13952 /* An empty line has a single glyph whose OBJECT is zero and
13953 whose CHARPOS is the position of a newline on that line.
13954 Note that on a TTY, there are more glyphs after that, which
13955 were produced by extend_face_to_end_of_line, but their
13956 CHARPOS is zero or negative. */
13958 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13959 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13961 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13963 ptrdiff_t ellipsis_pos
;
13965 /* Scan back over the ellipsis glyphs. */
13966 if (!row
->reversed_p
)
13968 ellipsis_pos
= (glyph
- 1)->charpos
;
13969 while (glyph
> row
->glyphs
[TEXT_AREA
]
13970 && (glyph
- 1)->charpos
== ellipsis_pos
)
13971 glyph
--, x
-= glyph
->pixel_width
;
13972 /* That loop always goes one position too far, including
13973 the glyph before the ellipsis. So scan forward over
13975 x
+= glyph
->pixel_width
;
13978 else /* row is reversed */
13980 ellipsis_pos
= (glyph
+ 1)->charpos
;
13981 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13982 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13983 glyph
++, x
+= glyph
->pixel_width
;
13984 x
-= glyph
->pixel_width
;
13988 else if (match_with_avoid_cursor
)
13990 cursor
= glyph_after
;
13993 else if (string_seen
)
13995 int incr
= row
->reversed_p
? -1 : +1;
13997 /* Need to find the glyph that came out of a string which is
13998 present at point. That glyph is somewhere between
13999 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14000 positioned between POS_BEFORE and POS_AFTER in the
14002 struct glyph
*start
, *stop
;
14003 ptrdiff_t pos
= pos_before
;
14007 /* If the row ends in a newline from a display string,
14008 reordering could have moved the glyphs belonging to the
14009 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14010 in this case we extend the search to the last glyph in
14011 the row that was not inserted by redisplay. */
14012 if (row
->ends_in_newline_from_string_p
)
14015 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14018 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14019 correspond to POS_BEFORE and POS_AFTER, respectively. We
14020 need START and STOP in the order that corresponds to the
14021 row's direction as given by its reversed_p flag. If the
14022 directionality of characters between POS_BEFORE and
14023 POS_AFTER is the opposite of the row's base direction,
14024 these characters will have been reordered for display,
14025 and we need to reverse START and STOP. */
14026 if (!row
->reversed_p
)
14028 start
= min (glyph_before
, glyph_after
);
14029 stop
= max (glyph_before
, glyph_after
);
14033 start
= max (glyph_before
, glyph_after
);
14034 stop
= min (glyph_before
, glyph_after
);
14036 for (glyph
= start
+ incr
;
14037 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14040 /* Any glyphs that come from the buffer are here because
14041 of bidi reordering. Skip them, and only pay
14042 attention to glyphs that came from some string. */
14043 if (STRINGP (glyph
->object
))
14047 /* If the display property covers the newline, we
14048 need to search for it one position farther. */
14049 ptrdiff_t lim
= pos_after
14050 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14052 string_from_text_prop
= 0;
14053 str
= glyph
->object
;
14054 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14055 if (tem
== 0 /* from overlay */
14058 /* If the string from which this glyph came is
14059 found in the buffer at point, or at position
14060 that is closer to point than pos_after, then
14061 we've found the glyph we've been looking for.
14062 If it comes from an overlay (tem == 0), and
14063 it has the `cursor' property on one of its
14064 glyphs, record that glyph as a candidate for
14065 displaying the cursor. (As in the
14066 unidirectional version, we will display the
14067 cursor on the last candidate we find.) */
14070 || (tem
- pt_old
> 0 && tem
< pos_after
))
14072 /* The glyphs from this string could have
14073 been reordered. Find the one with the
14074 smallest string position. Or there could
14075 be a character in the string with the
14076 `cursor' property, which means display
14077 cursor on that character's glyph. */
14078 ptrdiff_t strpos
= glyph
->charpos
;
14083 string_from_text_prop
= 1;
14086 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14087 && EQ (glyph
->object
, str
);
14091 ptrdiff_t gpos
= glyph
->charpos
;
14093 cprop
= Fget_char_property (make_number (gpos
),
14101 if (tem
&& glyph
->charpos
< strpos
)
14103 strpos
= glyph
->charpos
;
14109 || (tem
- pt_old
> 0 && tem
< pos_after
))
14113 pos
= tem
+ 1; /* don't find previous instances */
14115 /* This string is not what we want; skip all of the
14116 glyphs that came from it. */
14117 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14118 && EQ (glyph
->object
, str
))
14125 /* If we reached the end of the line, and END was from a string,
14126 the cursor is not on this line. */
14128 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14129 && STRINGP (end
->object
)
14130 && row
->continued_p
)
14133 /* A truncated row may not include PT among its character positions.
14134 Setting the cursor inside the scroll margin will trigger
14135 recalculation of hscroll in hscroll_window_tree. But if a
14136 display string covers point, defer to the string-handling
14137 code below to figure this out. */
14138 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14140 cursor
= glyph_before
;
14143 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14144 /* Zero-width characters produce no glyphs. */
14146 && (row
->reversed_p
14147 ? glyph_after
> glyphs_end
14148 : glyph_after
< glyphs_end
)))
14150 cursor
= glyph_after
;
14156 if (cursor
!= NULL
)
14162 /* Need to compute x that corresponds to GLYPH. */
14163 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14165 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14167 x
+= g
->pixel_width
;
14171 /* ROW could be part of a continued line, which, under bidi
14172 reordering, might have other rows whose start and end charpos
14173 occlude point. Only set w->cursor if we found a better
14174 approximation to the cursor position than we have from previously
14175 examined candidate rows belonging to the same continued line. */
14176 if (/* we already have a candidate row */
14177 w
->cursor
.vpos
>= 0
14178 /* that candidate is not the row we are processing */
14179 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14180 /* Make sure cursor.vpos specifies a row whose start and end
14181 charpos occlude point, and it is valid candidate for being a
14182 cursor-row. This is because some callers of this function
14183 leave cursor.vpos at the row where the cursor was displayed
14184 during the last redisplay cycle. */
14185 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14186 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14187 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14190 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14192 /* Don't consider glyphs that are outside TEXT_AREA. */
14193 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14195 /* Keep the candidate whose buffer position is the closest to
14196 point or has the `cursor' property. */
14197 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14198 w
->cursor
.hpos
>= 0
14199 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14200 && ((BUFFERP (g1
->object
)
14201 && (g1
->charpos
== pt_old
/* an exact match always wins */
14202 || (BUFFERP (glyph
->object
)
14203 && eabs (g1
->charpos
- pt_old
)
14204 < eabs (glyph
->charpos
- pt_old
))))
14205 /* previous candidate is a glyph from a string that has
14206 a non-nil `cursor' property */
14207 || (STRINGP (g1
->object
)
14208 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14209 Qcursor
, g1
->object
))
14210 /* previous candidate is from the same display
14211 string as this one, and the display string
14212 came from a text property */
14213 || (EQ (g1
->object
, glyph
->object
)
14214 && string_from_text_prop
)
14215 /* this candidate is from newline and its
14216 position is not an exact match */
14217 || (INTEGERP (glyph
->object
)
14218 && glyph
->charpos
!= pt_old
)))))
14220 /* If this candidate gives an exact match, use that. */
14221 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14222 /* If this candidate is a glyph created for the
14223 terminating newline of a line, and point is on that
14224 newline, it wins because it's an exact match. */
14225 || (!row
->continued_p
14226 && INTEGERP (glyph
->object
)
14227 && glyph
->charpos
== 0
14228 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14229 /* Otherwise, keep the candidate that comes from a row
14230 spanning less buffer positions. This may win when one or
14231 both candidate positions are on glyphs that came from
14232 display strings, for which we cannot compare buffer
14234 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14235 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14236 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14239 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14241 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14242 w
->cursor
.y
= row
->y
+ dy
;
14244 if (w
== XWINDOW (selected_window
))
14246 if (!row
->continued_p
14247 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14250 this_line_buffer
= XBUFFER (w
->buffer
);
14252 CHARPOS (this_line_start_pos
)
14253 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14254 BYTEPOS (this_line_start_pos
)
14255 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14257 CHARPOS (this_line_end_pos
)
14258 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14259 BYTEPOS (this_line_end_pos
)
14260 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14262 this_line_y
= w
->cursor
.y
;
14263 this_line_pixel_height
= row
->height
;
14264 this_line_vpos
= w
->cursor
.vpos
;
14265 this_line_start_x
= row
->x
;
14268 CHARPOS (this_line_start_pos
) = 0;
14275 /* Run window scroll functions, if any, for WINDOW with new window
14276 start STARTP. Sets the window start of WINDOW to that position.
14278 We assume that the window's buffer is really current. */
14280 static inline struct text_pos
14281 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14283 struct window
*w
= XWINDOW (window
);
14284 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14286 if (current_buffer
!= XBUFFER (w
->buffer
))
14289 if (!NILP (Vwindow_scroll_functions
))
14291 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14292 make_number (CHARPOS (startp
)));
14293 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14294 /* In case the hook functions switch buffers. */
14295 if (current_buffer
!= XBUFFER (w
->buffer
))
14296 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14303 /* Make sure the line containing the cursor is fully visible.
14304 A value of 1 means there is nothing to be done.
14305 (Either the line is fully visible, or it cannot be made so,
14306 or we cannot tell.)
14308 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14309 is higher than window.
14311 A value of 0 means the caller should do scrolling
14312 as if point had gone off the screen. */
14315 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14317 struct glyph_matrix
*matrix
;
14318 struct glyph_row
*row
;
14321 if (!make_cursor_line_fully_visible_p
)
14324 /* It's not always possible to find the cursor, e.g, when a window
14325 is full of overlay strings. Don't do anything in that case. */
14326 if (w
->cursor
.vpos
< 0)
14329 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14330 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14332 /* If the cursor row is not partially visible, there's nothing to do. */
14333 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14336 /* If the row the cursor is in is taller than the window's height,
14337 it's not clear what to do, so do nothing. */
14338 window_height
= window_box_height (w
);
14339 if (row
->height
>= window_height
)
14341 if (!force_p
|| MINI_WINDOW_P (w
)
14342 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14349 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14350 non-zero means only WINDOW is redisplayed in redisplay_internal.
14351 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14352 in redisplay_window to bring a partially visible line into view in
14353 the case that only the cursor has moved.
14355 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14356 last screen line's vertical height extends past the end of the screen.
14360 1 if scrolling succeeded
14362 0 if scrolling didn't find point.
14364 -1 if new fonts have been loaded so that we must interrupt
14365 redisplay, adjust glyph matrices, and try again. */
14371 SCROLLING_NEED_LARGER_MATRICES
14374 /* If scroll-conservatively is more than this, never recenter.
14376 If you change this, don't forget to update the doc string of
14377 `scroll-conservatively' and the Emacs manual. */
14378 #define SCROLL_LIMIT 100
14381 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14382 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14383 int temp_scroll_step
, int last_line_misfit
)
14385 struct window
*w
= XWINDOW (window
);
14386 struct frame
*f
= XFRAME (w
->frame
);
14387 struct text_pos pos
, startp
;
14389 int this_scroll_margin
, scroll_max
, rc
, height
;
14390 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14391 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14392 Lisp_Object aggressive
;
14393 /* We will never try scrolling more than this number of lines. */
14394 int scroll_limit
= SCROLL_LIMIT
;
14397 debug_method_add (w
, "try_scrolling");
14400 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14402 /* Compute scroll margin height in pixels. We scroll when point is
14403 within this distance from the top or bottom of the window. */
14404 if (scroll_margin
> 0)
14405 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14406 * FRAME_LINE_HEIGHT (f
);
14408 this_scroll_margin
= 0;
14410 /* Force arg_scroll_conservatively to have a reasonable value, to
14411 avoid scrolling too far away with slow move_it_* functions. Note
14412 that the user can supply scroll-conservatively equal to
14413 `most-positive-fixnum', which can be larger than INT_MAX. */
14414 if (arg_scroll_conservatively
> scroll_limit
)
14416 arg_scroll_conservatively
= scroll_limit
+ 1;
14417 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14419 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14420 /* Compute how much we should try to scroll maximally to bring
14421 point into view. */
14422 scroll_max
= (max (scroll_step
,
14423 max (arg_scroll_conservatively
, temp_scroll_step
))
14424 * FRAME_LINE_HEIGHT (f
));
14425 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14426 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14427 /* We're trying to scroll because of aggressive scrolling but no
14428 scroll_step is set. Choose an arbitrary one. */
14429 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14435 /* Decide whether to scroll down. */
14436 if (PT
> CHARPOS (startp
))
14438 int scroll_margin_y
;
14440 /* Compute the pixel ypos of the scroll margin, then move IT to
14441 either that ypos or PT, whichever comes first. */
14442 start_display (&it
, w
, startp
);
14443 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14444 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14445 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14446 (MOVE_TO_POS
| MOVE_TO_Y
));
14448 if (PT
> CHARPOS (it
.current
.pos
))
14450 int y0
= line_bottom_y (&it
);
14451 /* Compute how many pixels below window bottom to stop searching
14452 for PT. This avoids costly search for PT that is far away if
14453 the user limited scrolling by a small number of lines, but
14454 always finds PT if scroll_conservatively is set to a large
14455 number, such as most-positive-fixnum. */
14456 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14457 int y_to_move
= it
.last_visible_y
+ slack
;
14459 /* Compute the distance from the scroll margin to PT or to
14460 the scroll limit, whichever comes first. This should
14461 include the height of the cursor line, to make that line
14463 move_it_to (&it
, PT
, -1, y_to_move
,
14464 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14465 dy
= line_bottom_y (&it
) - y0
;
14467 if (dy
> scroll_max
)
14468 return SCROLLING_FAILED
;
14477 /* Point is in or below the bottom scroll margin, so move the
14478 window start down. If scrolling conservatively, move it just
14479 enough down to make point visible. If scroll_step is set,
14480 move it down by scroll_step. */
14481 if (arg_scroll_conservatively
)
14483 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14484 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14485 else if (scroll_step
|| temp_scroll_step
)
14486 amount_to_scroll
= scroll_max
;
14489 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14490 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14491 if (NUMBERP (aggressive
))
14493 double float_amount
= XFLOATINT (aggressive
) * height
;
14494 amount_to_scroll
= float_amount
;
14495 if (amount_to_scroll
== 0 && float_amount
> 0)
14496 amount_to_scroll
= 1;
14497 /* Don't let point enter the scroll margin near top of
14499 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14500 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14504 if (amount_to_scroll
<= 0)
14505 return SCROLLING_FAILED
;
14507 start_display (&it
, w
, startp
);
14508 if (arg_scroll_conservatively
<= scroll_limit
)
14509 move_it_vertically (&it
, amount_to_scroll
);
14512 /* Extra precision for users who set scroll-conservatively
14513 to a large number: make sure the amount we scroll
14514 the window start is never less than amount_to_scroll,
14515 which was computed as distance from window bottom to
14516 point. This matters when lines at window top and lines
14517 below window bottom have different height. */
14519 void *it1data
= NULL
;
14520 /* We use a temporary it1 because line_bottom_y can modify
14521 its argument, if it moves one line down; see there. */
14524 SAVE_IT (it1
, it
, it1data
);
14525 start_y
= line_bottom_y (&it1
);
14527 RESTORE_IT (&it
, &it
, it1data
);
14528 move_it_by_lines (&it
, 1);
14529 SAVE_IT (it1
, it
, it1data
);
14530 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14533 /* If STARTP is unchanged, move it down another screen line. */
14534 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14535 move_it_by_lines (&it
, 1);
14536 startp
= it
.current
.pos
;
14540 struct text_pos scroll_margin_pos
= startp
;
14542 /* See if point is inside the scroll margin at the top of the
14544 if (this_scroll_margin
)
14546 start_display (&it
, w
, startp
);
14547 move_it_vertically (&it
, this_scroll_margin
);
14548 scroll_margin_pos
= it
.current
.pos
;
14551 if (PT
< CHARPOS (scroll_margin_pos
))
14553 /* Point is in the scroll margin at the top of the window or
14554 above what is displayed in the window. */
14557 /* Compute the vertical distance from PT to the scroll
14558 margin position. Move as far as scroll_max allows, or
14559 one screenful, or 10 screen lines, whichever is largest.
14560 Give up if distance is greater than scroll_max. */
14561 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14562 start_display (&it
, w
, pos
);
14564 y_to_move
= max (it
.last_visible_y
,
14565 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14566 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14568 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14569 dy
= it
.current_y
- y0
;
14570 if (dy
> scroll_max
)
14571 return SCROLLING_FAILED
;
14573 /* Compute new window start. */
14574 start_display (&it
, w
, startp
);
14576 if (arg_scroll_conservatively
)
14577 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14578 max (scroll_step
, temp_scroll_step
));
14579 else if (scroll_step
|| temp_scroll_step
)
14580 amount_to_scroll
= scroll_max
;
14583 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14584 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14585 if (NUMBERP (aggressive
))
14587 double float_amount
= XFLOATINT (aggressive
) * height
;
14588 amount_to_scroll
= float_amount
;
14589 if (amount_to_scroll
== 0 && float_amount
> 0)
14590 amount_to_scroll
= 1;
14591 amount_to_scroll
-=
14592 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14593 /* Don't let point enter the scroll margin near
14594 bottom of the window. */
14595 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14596 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14600 if (amount_to_scroll
<= 0)
14601 return SCROLLING_FAILED
;
14603 move_it_vertically_backward (&it
, amount_to_scroll
);
14604 startp
= it
.current
.pos
;
14608 /* Run window scroll functions. */
14609 startp
= run_window_scroll_functions (window
, startp
);
14611 /* Display the window. Give up if new fonts are loaded, or if point
14613 if (!try_window (window
, startp
, 0))
14614 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14615 else if (w
->cursor
.vpos
< 0)
14617 clear_glyph_matrix (w
->desired_matrix
);
14618 rc
= SCROLLING_FAILED
;
14622 /* Maybe forget recorded base line for line number display. */
14623 if (!just_this_one_p
14624 || current_buffer
->clip_changed
14625 || BEG_UNCHANGED
< CHARPOS (startp
))
14626 w
->base_line_number
= Qnil
;
14628 /* If cursor ends up on a partially visible line,
14629 treat that as being off the bottom of the screen. */
14630 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14631 /* It's possible that the cursor is on the first line of the
14632 buffer, which is partially obscured due to a vscroll
14633 (Bug#7537). In that case, avoid looping forever . */
14634 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14636 clear_glyph_matrix (w
->desired_matrix
);
14637 ++extra_scroll_margin_lines
;
14640 rc
= SCROLLING_SUCCESS
;
14647 /* Compute a suitable window start for window W if display of W starts
14648 on a continuation line. Value is non-zero if a new window start
14651 The new window start will be computed, based on W's width, starting
14652 from the start of the continued line. It is the start of the
14653 screen line with the minimum distance from the old start W->start. */
14656 compute_window_start_on_continuation_line (struct window
*w
)
14658 struct text_pos pos
, start_pos
;
14659 int window_start_changed_p
= 0;
14661 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14663 /* If window start is on a continuation line... Window start may be
14664 < BEGV in case there's invisible text at the start of the
14665 buffer (M-x rmail, for example). */
14666 if (CHARPOS (start_pos
) > BEGV
14667 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14670 struct glyph_row
*row
;
14672 /* Handle the case that the window start is out of range. */
14673 if (CHARPOS (start_pos
) < BEGV
)
14674 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14675 else if (CHARPOS (start_pos
) > ZV
)
14676 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14678 /* Find the start of the continued line. This should be fast
14679 because scan_buffer is fast (newline cache). */
14680 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14681 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14682 row
, DEFAULT_FACE_ID
);
14683 reseat_at_previous_visible_line_start (&it
);
14685 /* If the line start is "too far" away from the window start,
14686 say it takes too much time to compute a new window start. */
14687 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14688 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14690 int min_distance
, distance
;
14692 /* Move forward by display lines to find the new window
14693 start. If window width was enlarged, the new start can
14694 be expected to be > the old start. If window width was
14695 decreased, the new window start will be < the old start.
14696 So, we're looking for the display line start with the
14697 minimum distance from the old window start. */
14698 pos
= it
.current
.pos
;
14699 min_distance
= INFINITY
;
14700 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14701 distance
< min_distance
)
14703 min_distance
= distance
;
14704 pos
= it
.current
.pos
;
14705 move_it_by_lines (&it
, 1);
14708 /* Set the window start there. */
14709 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14710 window_start_changed_p
= 1;
14714 return window_start_changed_p
;
14718 /* Try cursor movement in case text has not changed in window WINDOW,
14719 with window start STARTP. Value is
14721 CURSOR_MOVEMENT_SUCCESS if successful
14723 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14725 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14726 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14727 we want to scroll as if scroll-step were set to 1. See the code.
14729 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14730 which case we have to abort this redisplay, and adjust matrices
14735 CURSOR_MOVEMENT_SUCCESS
,
14736 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14737 CURSOR_MOVEMENT_MUST_SCROLL
,
14738 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14742 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14744 struct window
*w
= XWINDOW (window
);
14745 struct frame
*f
= XFRAME (w
->frame
);
14746 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14749 if (inhibit_try_cursor_movement
)
14753 /* Handle case where text has not changed, only point, and it has
14754 not moved off the frame. */
14755 if (/* Point may be in this window. */
14756 PT
>= CHARPOS (startp
)
14757 /* Selective display hasn't changed. */
14758 && !current_buffer
->clip_changed
14759 /* Function force-mode-line-update is used to force a thorough
14760 redisplay. It sets either windows_or_buffers_changed or
14761 update_mode_lines. So don't take a shortcut here for these
14763 && !update_mode_lines
14764 && !windows_or_buffers_changed
14765 && !cursor_type_changed
14766 /* Can't use this case if highlighting a region. When a
14767 region exists, cursor movement has to do more than just
14769 && !(!NILP (Vtransient_mark_mode
)
14770 && !NILP (BVAR (current_buffer
, mark_active
)))
14771 && NILP (w
->region_showing
)
14772 && NILP (Vshow_trailing_whitespace
)
14773 /* Right after splitting windows, last_point may be nil. */
14774 && INTEGERP (w
->last_point
)
14775 /* This code is not used for mini-buffer for the sake of the case
14776 of redisplaying to replace an echo area message; since in
14777 that case the mini-buffer contents per se are usually
14778 unchanged. This code is of no real use in the mini-buffer
14779 since the handling of this_line_start_pos, etc., in redisplay
14780 handles the same cases. */
14781 && !EQ (window
, minibuf_window
)
14782 /* When splitting windows or for new windows, it happens that
14783 redisplay is called with a nil window_end_vpos or one being
14784 larger than the window. This should really be fixed in
14785 window.c. I don't have this on my list, now, so we do
14786 approximately the same as the old redisplay code. --gerd. */
14787 && INTEGERP (w
->window_end_vpos
)
14788 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14789 && (FRAME_WINDOW_P (f
)
14790 || !overlay_arrow_in_current_buffer_p ()))
14792 int this_scroll_margin
, top_scroll_margin
;
14793 struct glyph_row
*row
= NULL
;
14796 debug_method_add (w
, "cursor movement");
14799 /* Scroll if point within this distance from the top or bottom
14800 of the window. This is a pixel value. */
14801 if (scroll_margin
> 0)
14803 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14804 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14807 this_scroll_margin
= 0;
14809 top_scroll_margin
= this_scroll_margin
;
14810 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14811 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14813 /* Start with the row the cursor was displayed during the last
14814 not paused redisplay. Give up if that row is not valid. */
14815 if (w
->last_cursor
.vpos
< 0
14816 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14817 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14820 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14821 if (row
->mode_line_p
)
14823 if (!row
->enabled_p
)
14824 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14827 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14829 int scroll_p
= 0, must_scroll
= 0;
14830 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14832 if (PT
> XFASTINT (w
->last_point
))
14834 /* Point has moved forward. */
14835 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14836 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14838 xassert (row
->enabled_p
);
14842 /* If the end position of a row equals the start
14843 position of the next row, and PT is at that position,
14844 we would rather display cursor in the next line. */
14845 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14846 && MATRIX_ROW_END_CHARPOS (row
) == PT
14847 && row
< w
->current_matrix
->rows
14848 + w
->current_matrix
->nrows
- 1
14849 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14850 && !cursor_row_p (row
))
14853 /* If within the scroll margin, scroll. Note that
14854 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14855 the next line would be drawn, and that
14856 this_scroll_margin can be zero. */
14857 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14858 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14859 /* Line is completely visible last line in window
14860 and PT is to be set in the next line. */
14861 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14862 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14863 && !row
->ends_at_zv_p
14864 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14867 else if (PT
< XFASTINT (w
->last_point
))
14869 /* Cursor has to be moved backward. Note that PT >=
14870 CHARPOS (startp) because of the outer if-statement. */
14871 while (!row
->mode_line_p
14872 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14873 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14874 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14875 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14876 row
> w
->current_matrix
->rows
14877 && (row
-1)->ends_in_newline_from_string_p
))))
14878 && (row
->y
> top_scroll_margin
14879 || CHARPOS (startp
) == BEGV
))
14881 xassert (row
->enabled_p
);
14885 /* Consider the following case: Window starts at BEGV,
14886 there is invisible, intangible text at BEGV, so that
14887 display starts at some point START > BEGV. It can
14888 happen that we are called with PT somewhere between
14889 BEGV and START. Try to handle that case. */
14890 if (row
< w
->current_matrix
->rows
14891 || row
->mode_line_p
)
14893 row
= w
->current_matrix
->rows
;
14894 if (row
->mode_line_p
)
14898 /* Due to newlines in overlay strings, we may have to
14899 skip forward over overlay strings. */
14900 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14901 && MATRIX_ROW_END_CHARPOS (row
) == PT
14902 && !cursor_row_p (row
))
14905 /* If within the scroll margin, scroll. */
14906 if (row
->y
< top_scroll_margin
14907 && CHARPOS (startp
) != BEGV
)
14912 /* Cursor did not move. So don't scroll even if cursor line
14913 is partially visible, as it was so before. */
14914 rc
= CURSOR_MOVEMENT_SUCCESS
;
14917 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14918 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14920 /* if PT is not in the glyph row, give up. */
14921 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14924 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14925 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14927 struct glyph_row
*row1
;
14929 /* If rows are bidi-reordered and point moved, back up
14930 until we find a row that does not belong to a
14931 continuation line. This is because we must consider
14932 all rows of a continued line as candidates for the
14933 new cursor positioning, since row start and end
14934 positions change non-linearly with vertical position
14936 /* FIXME: Revisit this when glyph ``spilling'' in
14937 continuation lines' rows is implemented for
14938 bidi-reordered rows. */
14939 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14940 MATRIX_ROW_CONTINUATION_LINE_P (row
);
14943 /* If we hit the beginning of the displayed portion
14944 without finding the first row of a continued
14948 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14951 xassert (row
->enabled_p
);
14956 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14957 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14958 /* Make sure this isn't a header line by any chance, since
14959 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
14960 && !row
->mode_line_p
14961 && make_cursor_line_fully_visible_p
)
14963 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14964 && !row
->ends_at_zv_p
14965 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14966 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14967 else if (row
->height
> window_box_height (w
))
14969 /* If we end up in a partially visible line, let's
14970 make it fully visible, except when it's taller
14971 than the window, in which case we can't do much
14974 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14978 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14979 if (!cursor_row_fully_visible_p (w
, 0, 1))
14980 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14982 rc
= CURSOR_MOVEMENT_SUCCESS
;
14986 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14987 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14988 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14990 /* With bidi-reordered rows, there could be more than
14991 one candidate row whose start and end positions
14992 occlude point. We need to let set_cursor_from_row
14993 find the best candidate. */
14994 /* FIXME: Revisit this when glyph ``spilling'' in
14995 continuation lines' rows is implemented for
14996 bidi-reordered rows. */
15001 int at_zv_p
= 0, exact_match_p
= 0;
15003 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15004 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15005 && cursor_row_p (row
))
15006 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15008 /* As soon as we've found the exact match for point,
15009 or the first suitable row whose ends_at_zv_p flag
15010 is set, we are done. */
15012 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15014 && w
->cursor
.hpos
>= 0
15015 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15018 struct glyph_row
*candidate
=
15019 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15021 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15022 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15025 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15026 || (INTEGERP (g
->object
)
15027 && (g
->charpos
== PT
15028 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15030 if (rv
&& (at_zv_p
|| exact_match_p
))
15032 rc
= CURSOR_MOVEMENT_SUCCESS
;
15035 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15039 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15040 || row
->continued_p
)
15041 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15042 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15043 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15044 /* If we didn't find any candidate rows, or exited the
15045 loop before all the candidates were examined, signal
15046 to the caller that this method failed. */
15047 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15049 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15050 && !row
->continued_p
))
15051 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15053 rc
= CURSOR_MOVEMENT_SUCCESS
;
15059 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15061 rc
= CURSOR_MOVEMENT_SUCCESS
;
15066 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15067 && MATRIX_ROW_START_CHARPOS (row
) == PT
15068 && cursor_row_p (row
));
15076 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15080 set_vertical_scroll_bar (struct window
*w
)
15082 ptrdiff_t start
, end
, whole
;
15084 /* Calculate the start and end positions for the current window.
15085 At some point, it would be nice to choose between scrollbars
15086 which reflect the whole buffer size, with special markers
15087 indicating narrowing, and scrollbars which reflect only the
15090 Note that mini-buffers sometimes aren't displaying any text. */
15091 if (!MINI_WINDOW_P (w
)
15092 || (w
== XWINDOW (minibuf_window
)
15093 && NILP (echo_area_buffer
[0])))
15095 struct buffer
*buf
= XBUFFER (w
->buffer
);
15096 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15097 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15098 /* I don't think this is guaranteed to be right. For the
15099 moment, we'll pretend it is. */
15100 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15104 if (whole
< (end
- start
))
15105 whole
= end
- start
;
15108 start
= end
= whole
= 0;
15110 /* Indicate what this scroll bar ought to be displaying now. */
15111 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15112 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15113 (w
, end
- start
, whole
, start
);
15117 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15118 selected_window is redisplayed.
15120 We can return without actually redisplaying the window if
15121 fonts_changed_p is nonzero. In that case, redisplay_internal will
15125 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15127 struct window
*w
= XWINDOW (window
);
15128 struct frame
*f
= XFRAME (w
->frame
);
15129 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15130 struct buffer
*old
= current_buffer
;
15131 struct text_pos lpoint
, opoint
, startp
;
15132 int update_mode_line
;
15135 /* Record it now because it's overwritten. */
15136 int current_matrix_up_to_date_p
= 0;
15137 int used_current_matrix_p
= 0;
15138 /* This is less strict than current_matrix_up_to_date_p.
15139 It indicates that the buffer contents and narrowing are unchanged. */
15140 int buffer_unchanged_p
= 0;
15141 int temp_scroll_step
= 0;
15142 ptrdiff_t count
= SPECPDL_INDEX ();
15144 int centering_position
= -1;
15145 int last_line_misfit
= 0;
15146 ptrdiff_t beg_unchanged
, end_unchanged
;
15148 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15151 /* W must be a leaf window here. */
15152 xassert (!NILP (w
->buffer
));
15154 *w
->desired_matrix
->method
= 0;
15158 reconsider_clip_changes (w
, buffer
);
15160 /* Has the mode line to be updated? */
15161 update_mode_line
= (!NILP (w
->update_mode_line
)
15162 || update_mode_lines
15163 || buffer
->clip_changed
15164 || buffer
->prevent_redisplay_optimizations_p
);
15166 if (MINI_WINDOW_P (w
))
15168 if (w
== XWINDOW (echo_area_window
)
15169 && !NILP (echo_area_buffer
[0]))
15171 if (update_mode_line
)
15172 /* We may have to update a tty frame's menu bar or a
15173 tool-bar. Example `M-x C-h C-h C-g'. */
15174 goto finish_menu_bars
;
15176 /* We've already displayed the echo area glyphs in this window. */
15177 goto finish_scroll_bars
;
15179 else if ((w
!= XWINDOW (minibuf_window
)
15180 || minibuf_level
== 0)
15181 /* When buffer is nonempty, redisplay window normally. */
15182 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15183 /* Quail displays non-mini buffers in minibuffer window.
15184 In that case, redisplay the window normally. */
15185 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15187 /* W is a mini-buffer window, but it's not active, so clear
15189 int yb
= window_text_bottom_y (w
);
15190 struct glyph_row
*row
;
15193 for (y
= 0, row
= w
->desired_matrix
->rows
;
15195 y
+= row
->height
, ++row
)
15196 blank_row (w
, row
, y
);
15197 goto finish_scroll_bars
;
15200 clear_glyph_matrix (w
->desired_matrix
);
15203 /* Otherwise set up data on this window; select its buffer and point
15205 /* Really select the buffer, for the sake of buffer-local
15207 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15209 current_matrix_up_to_date_p
15210 = (!NILP (w
->window_end_valid
)
15211 && !current_buffer
->clip_changed
15212 && !current_buffer
->prevent_redisplay_optimizations_p
15213 && XFASTINT (w
->last_modified
) >= MODIFF
15214 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15216 /* Run the window-bottom-change-functions
15217 if it is possible that the text on the screen has changed
15218 (either due to modification of the text, or any other reason). */
15219 if (!current_matrix_up_to_date_p
15220 && !NILP (Vwindow_text_change_functions
))
15222 safe_run_hooks (Qwindow_text_change_functions
);
15226 beg_unchanged
= BEG_UNCHANGED
;
15227 end_unchanged
= END_UNCHANGED
;
15229 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15231 specbind (Qinhibit_point_motion_hooks
, Qt
);
15234 = (!NILP (w
->window_end_valid
)
15235 && !current_buffer
->clip_changed
15236 && XFASTINT (w
->last_modified
) >= MODIFF
15237 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15239 /* When windows_or_buffers_changed is non-zero, we can't rely on
15240 the window end being valid, so set it to nil there. */
15241 if (windows_or_buffers_changed
)
15243 /* If window starts on a continuation line, maybe adjust the
15244 window start in case the window's width changed. */
15245 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15246 compute_window_start_on_continuation_line (w
);
15248 w
->window_end_valid
= Qnil
;
15251 /* Some sanity checks. */
15252 CHECK_WINDOW_END (w
);
15253 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15255 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15258 /* If %c is in mode line, update it if needed. */
15259 if (!NILP (w
->column_number_displayed
)
15260 /* This alternative quickly identifies a common case
15261 where no change is needed. */
15262 && !(PT
== XFASTINT (w
->last_point
)
15263 && XFASTINT (w
->last_modified
) >= MODIFF
15264 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
15265 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15266 update_mode_line
= 1;
15268 /* Count number of windows showing the selected buffer. An indirect
15269 buffer counts as its base buffer. */
15270 if (!just_this_one_p
)
15272 struct buffer
*current_base
, *window_base
;
15273 current_base
= current_buffer
;
15274 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15275 if (current_base
->base_buffer
)
15276 current_base
= current_base
->base_buffer
;
15277 if (window_base
->base_buffer
)
15278 window_base
= window_base
->base_buffer
;
15279 if (current_base
== window_base
)
15283 /* Point refers normally to the selected window. For any other
15284 window, set up appropriate value. */
15285 if (!EQ (window
, selected_window
))
15287 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15288 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15292 new_pt_byte
= BEGV_BYTE
;
15293 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15295 else if (new_pt
> (ZV
- 1))
15298 new_pt_byte
= ZV_BYTE
;
15299 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15302 /* We don't use SET_PT so that the point-motion hooks don't run. */
15303 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15306 /* If any of the character widths specified in the display table
15307 have changed, invalidate the width run cache. It's true that
15308 this may be a bit late to catch such changes, but the rest of
15309 redisplay goes (non-fatally) haywire when the display table is
15310 changed, so why should we worry about doing any better? */
15311 if (current_buffer
->width_run_cache
)
15313 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15315 if (! disptab_matches_widthtab (disptab
,
15316 XVECTOR (BVAR (current_buffer
, width_table
))))
15318 invalidate_region_cache (current_buffer
,
15319 current_buffer
->width_run_cache
,
15321 recompute_width_table (current_buffer
, disptab
);
15325 /* If window-start is screwed up, choose a new one. */
15326 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15329 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15331 /* If someone specified a new starting point but did not insist,
15332 check whether it can be used. */
15333 if (!NILP (w
->optional_new_start
)
15334 && CHARPOS (startp
) >= BEGV
15335 && CHARPOS (startp
) <= ZV
)
15337 w
->optional_new_start
= Qnil
;
15338 start_display (&it
, w
, startp
);
15339 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15340 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15341 if (IT_CHARPOS (it
) == PT
)
15342 w
->force_start
= Qt
;
15343 /* IT may overshoot PT if text at PT is invisible. */
15344 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15345 w
->force_start
= Qt
;
15350 /* Handle case where place to start displaying has been specified,
15351 unless the specified location is outside the accessible range. */
15352 if (!NILP (w
->force_start
)
15353 || w
->frozen_window_start_p
)
15355 /* We set this later on if we have to adjust point. */
15358 w
->force_start
= Qnil
;
15360 w
->window_end_valid
= Qnil
;
15362 /* Forget any recorded base line for line number display. */
15363 if (!buffer_unchanged_p
)
15364 w
->base_line_number
= Qnil
;
15366 /* Redisplay the mode line. Select the buffer properly for that.
15367 Also, run the hook window-scroll-functions
15368 because we have scrolled. */
15369 /* Note, we do this after clearing force_start because
15370 if there's an error, it is better to forget about force_start
15371 than to get into an infinite loop calling the hook functions
15372 and having them get more errors. */
15373 if (!update_mode_line
15374 || ! NILP (Vwindow_scroll_functions
))
15376 update_mode_line
= 1;
15377 w
->update_mode_line
= Qt
;
15378 startp
= run_window_scroll_functions (window
, startp
);
15381 w
->last_modified
= make_number (0);
15382 w
->last_overlay_modified
= make_number (0);
15383 if (CHARPOS (startp
) < BEGV
)
15384 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15385 else if (CHARPOS (startp
) > ZV
)
15386 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15388 /* Redisplay, then check if cursor has been set during the
15389 redisplay. Give up if new fonts were loaded. */
15390 /* We used to issue a CHECK_MARGINS argument to try_window here,
15391 but this causes scrolling to fail when point begins inside
15392 the scroll margin (bug#148) -- cyd */
15393 if (!try_window (window
, startp
, 0))
15395 w
->force_start
= Qt
;
15396 clear_glyph_matrix (w
->desired_matrix
);
15397 goto need_larger_matrices
;
15400 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15402 /* If point does not appear, try to move point so it does
15403 appear. The desired matrix has been built above, so we
15404 can use it here. */
15405 new_vpos
= window_box_height (w
) / 2;
15408 if (!cursor_row_fully_visible_p (w
, 0, 0))
15410 /* Point does appear, but on a line partly visible at end of window.
15411 Move it back to a fully-visible line. */
15412 new_vpos
= window_box_height (w
);
15415 /* If we need to move point for either of the above reasons,
15416 now actually do it. */
15419 struct glyph_row
*row
;
15421 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15422 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15425 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15426 MATRIX_ROW_START_BYTEPOS (row
));
15428 if (w
!= XWINDOW (selected_window
))
15429 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15430 else if (current_buffer
== old
)
15431 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15433 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15435 /* If we are highlighting the region, then we just changed
15436 the region, so redisplay to show it. */
15437 if (!NILP (Vtransient_mark_mode
)
15438 && !NILP (BVAR (current_buffer
, mark_active
)))
15440 clear_glyph_matrix (w
->desired_matrix
);
15441 if (!try_window (window
, startp
, 0))
15442 goto need_larger_matrices
;
15447 debug_method_add (w
, "forced window start");
15452 /* Handle case where text has not changed, only point, and it has
15453 not moved off the frame, and we are not retrying after hscroll.
15454 (current_matrix_up_to_date_p is nonzero when retrying.) */
15455 if (current_matrix_up_to_date_p
15456 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15457 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15461 case CURSOR_MOVEMENT_SUCCESS
:
15462 used_current_matrix_p
= 1;
15465 case CURSOR_MOVEMENT_MUST_SCROLL
:
15466 goto try_to_scroll
;
15472 /* If current starting point was originally the beginning of a line
15473 but no longer is, find a new starting point. */
15474 else if (!NILP (w
->start_at_line_beg
)
15475 && !(CHARPOS (startp
) <= BEGV
15476 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15479 debug_method_add (w
, "recenter 1");
15484 /* Try scrolling with try_window_id. Value is > 0 if update has
15485 been done, it is -1 if we know that the same window start will
15486 not work. It is 0 if unsuccessful for some other reason. */
15487 else if ((tem
= try_window_id (w
)) != 0)
15490 debug_method_add (w
, "try_window_id %d", tem
);
15493 if (fonts_changed_p
)
15494 goto need_larger_matrices
;
15498 /* Otherwise try_window_id has returned -1 which means that we
15499 don't want the alternative below this comment to execute. */
15501 else if (CHARPOS (startp
) >= BEGV
15502 && CHARPOS (startp
) <= ZV
15503 && PT
>= CHARPOS (startp
)
15504 && (CHARPOS (startp
) < ZV
15505 /* Avoid starting at end of buffer. */
15506 || CHARPOS (startp
) == BEGV
15507 || (XFASTINT (w
->last_modified
) >= MODIFF
15508 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
15510 int d1
, d2
, d3
, d4
, d5
, d6
;
15512 /* If first window line is a continuation line, and window start
15513 is inside the modified region, but the first change is before
15514 current window start, we must select a new window start.
15516 However, if this is the result of a down-mouse event (e.g. by
15517 extending the mouse-drag-overlay), we don't want to select a
15518 new window start, since that would change the position under
15519 the mouse, resulting in an unwanted mouse-movement rather
15520 than a simple mouse-click. */
15521 if (NILP (w
->start_at_line_beg
)
15522 && NILP (do_mouse_tracking
)
15523 && CHARPOS (startp
) > BEGV
15524 && CHARPOS (startp
) > BEG
+ beg_unchanged
15525 && CHARPOS (startp
) <= Z
- end_unchanged
15526 /* Even if w->start_at_line_beg is nil, a new window may
15527 start at a line_beg, since that's how set_buffer_window
15528 sets it. So, we need to check the return value of
15529 compute_window_start_on_continuation_line. (See also
15531 && XMARKER (w
->start
)->buffer
== current_buffer
15532 && compute_window_start_on_continuation_line (w
)
15533 /* It doesn't make sense to force the window start like we
15534 do at label force_start if it is already known that point
15535 will not be visible in the resulting window, because
15536 doing so will move point from its correct position
15537 instead of scrolling the window to bring point into view.
15539 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15541 w
->force_start
= Qt
;
15542 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15547 debug_method_add (w
, "same window start");
15550 /* Try to redisplay starting at same place as before.
15551 If point has not moved off frame, accept the results. */
15552 if (!current_matrix_up_to_date_p
15553 /* Don't use try_window_reusing_current_matrix in this case
15554 because a window scroll function can have changed the
15556 || !NILP (Vwindow_scroll_functions
)
15557 || MINI_WINDOW_P (w
)
15558 || !(used_current_matrix_p
15559 = try_window_reusing_current_matrix (w
)))
15561 IF_DEBUG (debug_method_add (w
, "1"));
15562 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15563 /* -1 means we need to scroll.
15564 0 means we need new matrices, but fonts_changed_p
15565 is set in that case, so we will detect it below. */
15566 goto try_to_scroll
;
15569 if (fonts_changed_p
)
15570 goto need_larger_matrices
;
15572 if (w
->cursor
.vpos
>= 0)
15574 if (!just_this_one_p
15575 || current_buffer
->clip_changed
15576 || BEG_UNCHANGED
< CHARPOS (startp
))
15577 /* Forget any recorded base line for line number display. */
15578 w
->base_line_number
= Qnil
;
15580 if (!cursor_row_fully_visible_p (w
, 1, 0))
15582 clear_glyph_matrix (w
->desired_matrix
);
15583 last_line_misfit
= 1;
15585 /* Drop through and scroll. */
15590 clear_glyph_matrix (w
->desired_matrix
);
15595 w
->last_modified
= make_number (0);
15596 w
->last_overlay_modified
= make_number (0);
15598 /* Redisplay the mode line. Select the buffer properly for that. */
15599 if (!update_mode_line
)
15601 update_mode_line
= 1;
15602 w
->update_mode_line
= Qt
;
15605 /* Try to scroll by specified few lines. */
15606 if ((scroll_conservatively
15607 || emacs_scroll_step
15608 || temp_scroll_step
15609 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15610 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15611 && CHARPOS (startp
) >= BEGV
15612 && CHARPOS (startp
) <= ZV
)
15614 /* The function returns -1 if new fonts were loaded, 1 if
15615 successful, 0 if not successful. */
15616 int ss
= try_scrolling (window
, just_this_one_p
,
15617 scroll_conservatively
,
15619 temp_scroll_step
, last_line_misfit
);
15622 case SCROLLING_SUCCESS
:
15625 case SCROLLING_NEED_LARGER_MATRICES
:
15626 goto need_larger_matrices
;
15628 case SCROLLING_FAILED
:
15636 /* Finally, just choose a place to start which positions point
15637 according to user preferences. */
15642 debug_method_add (w
, "recenter");
15645 /* w->vscroll = 0; */
15647 /* Forget any previously recorded base line for line number display. */
15648 if (!buffer_unchanged_p
)
15649 w
->base_line_number
= Qnil
;
15651 /* Determine the window start relative to point. */
15652 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15653 it
.current_y
= it
.last_visible_y
;
15654 if (centering_position
< 0)
15658 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15660 ptrdiff_t margin_pos
= CHARPOS (startp
);
15661 Lisp_Object aggressive
;
15664 /* If there is a scroll margin at the top of the window, find
15665 its character position. */
15667 /* Cannot call start_display if startp is not in the
15668 accessible region of the buffer. This can happen when we
15669 have just switched to a different buffer and/or changed
15670 its restriction. In that case, startp is initialized to
15671 the character position 1 (BEGV) because we did not yet
15672 have chance to display the buffer even once. */
15673 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15676 void *it1data
= NULL
;
15678 SAVE_IT (it1
, it
, it1data
);
15679 start_display (&it1
, w
, startp
);
15680 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15681 margin_pos
= IT_CHARPOS (it1
);
15682 RESTORE_IT (&it
, &it
, it1data
);
15684 scrolling_up
= PT
> margin_pos
;
15687 ? BVAR (current_buffer
, scroll_up_aggressively
)
15688 : BVAR (current_buffer
, scroll_down_aggressively
);
15690 if (!MINI_WINDOW_P (w
)
15691 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15695 /* Setting scroll-conservatively overrides
15696 scroll-*-aggressively. */
15697 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15699 double float_amount
= XFLOATINT (aggressive
);
15701 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15702 if (pt_offset
== 0 && float_amount
> 0)
15704 if (pt_offset
&& margin
> 0)
15707 /* Compute how much to move the window start backward from
15708 point so that point will be displayed where the user
15712 centering_position
= it
.last_visible_y
;
15714 centering_position
-= pt_offset
;
15715 centering_position
-=
15716 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15717 + WINDOW_HEADER_LINE_HEIGHT (w
);
15718 /* Don't let point enter the scroll margin near top of
15720 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15721 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15724 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15727 /* Set the window start half the height of the window backward
15729 centering_position
= window_box_height (w
) / 2;
15731 move_it_vertically_backward (&it
, centering_position
);
15733 xassert (IT_CHARPOS (it
) >= BEGV
);
15735 /* The function move_it_vertically_backward may move over more
15736 than the specified y-distance. If it->w is small, e.g. a
15737 mini-buffer window, we may end up in front of the window's
15738 display area. Start displaying at the start of the line
15739 containing PT in this case. */
15740 if (it
.current_y
<= 0)
15742 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15743 move_it_vertically_backward (&it
, 0);
15747 it
.current_x
= it
.hpos
= 0;
15749 /* Set the window start position here explicitly, to avoid an
15750 infinite loop in case the functions in window-scroll-functions
15752 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15754 /* Run scroll hooks. */
15755 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15757 /* Redisplay the window. */
15758 if (!current_matrix_up_to_date_p
15759 || windows_or_buffers_changed
15760 || cursor_type_changed
15761 /* Don't use try_window_reusing_current_matrix in this case
15762 because it can have changed the buffer. */
15763 || !NILP (Vwindow_scroll_functions
)
15764 || !just_this_one_p
15765 || MINI_WINDOW_P (w
)
15766 || !(used_current_matrix_p
15767 = try_window_reusing_current_matrix (w
)))
15768 try_window (window
, startp
, 0);
15770 /* If new fonts have been loaded (due to fontsets), give up. We
15771 have to start a new redisplay since we need to re-adjust glyph
15773 if (fonts_changed_p
)
15774 goto need_larger_matrices
;
15776 /* If cursor did not appear assume that the middle of the window is
15777 in the first line of the window. Do it again with the next line.
15778 (Imagine a window of height 100, displaying two lines of height
15779 60. Moving back 50 from it->last_visible_y will end in the first
15781 if (w
->cursor
.vpos
< 0)
15783 if (!NILP (w
->window_end_valid
)
15784 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15786 clear_glyph_matrix (w
->desired_matrix
);
15787 move_it_by_lines (&it
, 1);
15788 try_window (window
, it
.current
.pos
, 0);
15790 else if (PT
< IT_CHARPOS (it
))
15792 clear_glyph_matrix (w
->desired_matrix
);
15793 move_it_by_lines (&it
, -1);
15794 try_window (window
, it
.current
.pos
, 0);
15798 /* Not much we can do about it. */
15802 /* Consider the following case: Window starts at BEGV, there is
15803 invisible, intangible text at BEGV, so that display starts at
15804 some point START > BEGV. It can happen that we are called with
15805 PT somewhere between BEGV and START. Try to handle that case. */
15806 if (w
->cursor
.vpos
< 0)
15808 struct glyph_row
*row
= w
->current_matrix
->rows
;
15809 if (row
->mode_line_p
)
15811 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15814 if (!cursor_row_fully_visible_p (w
, 0, 0))
15816 /* If vscroll is enabled, disable it and try again. */
15820 clear_glyph_matrix (w
->desired_matrix
);
15824 /* Users who set scroll-conservatively to a large number want
15825 point just above/below the scroll margin. If we ended up
15826 with point's row partially visible, move the window start to
15827 make that row fully visible and out of the margin. */
15828 if (scroll_conservatively
> SCROLL_LIMIT
)
15832 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15834 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15836 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15837 clear_glyph_matrix (w
->desired_matrix
);
15838 if (1 == try_window (window
, it
.current
.pos
,
15839 TRY_WINDOW_CHECK_MARGINS
))
15843 /* If centering point failed to make the whole line visible,
15844 put point at the top instead. That has to make the whole line
15845 visible, if it can be done. */
15846 if (centering_position
== 0)
15849 clear_glyph_matrix (w
->desired_matrix
);
15850 centering_position
= 0;
15856 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15857 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15858 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15861 /* Display the mode line, if we must. */
15862 if ((update_mode_line
15863 /* If window not full width, must redo its mode line
15864 if (a) the window to its side is being redone and
15865 (b) we do a frame-based redisplay. This is a consequence
15866 of how inverted lines are drawn in frame-based redisplay. */
15867 || (!just_this_one_p
15868 && !FRAME_WINDOW_P (f
)
15869 && !WINDOW_FULL_WIDTH_P (w
))
15870 /* Line number to display. */
15871 || INTEGERP (w
->base_line_pos
)
15872 /* Column number is displayed and different from the one displayed. */
15873 || (!NILP (w
->column_number_displayed
)
15874 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15875 /* This means that the window has a mode line. */
15876 && (WINDOW_WANTS_MODELINE_P (w
)
15877 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15879 display_mode_lines (w
);
15881 /* If mode line height has changed, arrange for a thorough
15882 immediate redisplay using the correct mode line height. */
15883 if (WINDOW_WANTS_MODELINE_P (w
)
15884 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15886 fonts_changed_p
= 1;
15887 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15888 = DESIRED_MODE_LINE_HEIGHT (w
);
15891 /* If header line height has changed, arrange for a thorough
15892 immediate redisplay using the correct header line height. */
15893 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15894 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15896 fonts_changed_p
= 1;
15897 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15898 = DESIRED_HEADER_LINE_HEIGHT (w
);
15901 if (fonts_changed_p
)
15902 goto need_larger_matrices
;
15905 if (!line_number_displayed
15906 && !BUFFERP (w
->base_line_pos
))
15908 w
->base_line_pos
= Qnil
;
15909 w
->base_line_number
= Qnil
;
15914 /* When we reach a frame's selected window, redo the frame's menu bar. */
15915 if (update_mode_line
15916 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15918 int redisplay_menu_p
= 0;
15920 if (FRAME_WINDOW_P (f
))
15922 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15923 || defined (HAVE_NS) || defined (USE_GTK)
15924 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15926 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15930 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15932 if (redisplay_menu_p
)
15933 display_menu_bar (w
);
15935 #ifdef HAVE_WINDOW_SYSTEM
15936 if (FRAME_WINDOW_P (f
))
15938 #if defined (USE_GTK) || defined (HAVE_NS)
15939 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15940 redisplay_tool_bar (f
);
15942 if (WINDOWP (f
->tool_bar_window
)
15943 && (FRAME_TOOL_BAR_LINES (f
) > 0
15944 || !NILP (Vauto_resize_tool_bars
))
15945 && redisplay_tool_bar (f
))
15946 ignore_mouse_drag_p
= 1;
15952 #ifdef HAVE_WINDOW_SYSTEM
15953 if (FRAME_WINDOW_P (f
)
15954 && update_window_fringes (w
, (just_this_one_p
15955 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15956 || w
->pseudo_window_p
)))
15960 if (draw_window_fringes (w
, 1))
15961 x_draw_vertical_border (w
);
15965 #endif /* HAVE_WINDOW_SYSTEM */
15967 /* We go to this label, with fonts_changed_p nonzero,
15968 if it is necessary to try again using larger glyph matrices.
15969 We have to redeem the scroll bar even in this case,
15970 because the loop in redisplay_internal expects that. */
15971 need_larger_matrices
:
15973 finish_scroll_bars
:
15975 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15977 /* Set the thumb's position and size. */
15978 set_vertical_scroll_bar (w
);
15980 /* Note that we actually used the scroll bar attached to this
15981 window, so it shouldn't be deleted at the end of redisplay. */
15982 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15983 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15986 /* Restore current_buffer and value of point in it. The window
15987 update may have changed the buffer, so first make sure `opoint'
15988 is still valid (Bug#6177). */
15989 if (CHARPOS (opoint
) < BEGV
)
15990 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15991 else if (CHARPOS (opoint
) > ZV
)
15992 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15994 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15996 set_buffer_internal_1 (old
);
15997 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15998 shorter. This can be caused by log truncation in *Messages*. */
15999 if (CHARPOS (lpoint
) <= ZV
)
16000 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16002 unbind_to (count
, Qnil
);
16006 /* Build the complete desired matrix of WINDOW with a window start
16007 buffer position POS.
16009 Value is 1 if successful. It is zero if fonts were loaded during
16010 redisplay which makes re-adjusting glyph matrices necessary, and -1
16011 if point would appear in the scroll margins.
16012 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16013 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16017 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16019 struct window
*w
= XWINDOW (window
);
16021 struct glyph_row
*last_text_row
= NULL
;
16022 struct frame
*f
= XFRAME (w
->frame
);
16024 /* Make POS the new window start. */
16025 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16027 /* Mark cursor position as unknown. No overlay arrow seen. */
16028 w
->cursor
.vpos
= -1;
16029 overlay_arrow_seen
= 0;
16031 /* Initialize iterator and info to start at POS. */
16032 start_display (&it
, w
, pos
);
16034 /* Display all lines of W. */
16035 while (it
.current_y
< it
.last_visible_y
)
16037 if (display_line (&it
))
16038 last_text_row
= it
.glyph_row
- 1;
16039 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16043 /* Don't let the cursor end in the scroll margins. */
16044 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16045 && !MINI_WINDOW_P (w
))
16047 int this_scroll_margin
;
16049 if (scroll_margin
> 0)
16051 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16052 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16055 this_scroll_margin
= 0;
16057 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16058 && w
->cursor
.y
< this_scroll_margin
16059 && CHARPOS (pos
) > BEGV
16060 && IT_CHARPOS (it
) < ZV
)
16061 /* rms: considering make_cursor_line_fully_visible_p here
16062 seems to give wrong results. We don't want to recenter
16063 when the last line is partly visible, we want to allow
16064 that case to be handled in the usual way. */
16065 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16067 w
->cursor
.vpos
= -1;
16068 clear_glyph_matrix (w
->desired_matrix
);
16073 /* If bottom moved off end of frame, change mode line percentage. */
16074 if (XFASTINT (w
->window_end_pos
) <= 0
16075 && Z
!= IT_CHARPOS (it
))
16076 w
->update_mode_line
= Qt
;
16078 /* Set window_end_pos to the offset of the last character displayed
16079 on the window from the end of current_buffer. Set
16080 window_end_vpos to its row number. */
16083 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16084 w
->window_end_bytepos
16085 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16087 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16089 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16090 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16091 ->displays_text_p
);
16095 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16096 w
->window_end_pos
= make_number (Z
- ZV
);
16097 w
->window_end_vpos
= make_number (0);
16100 /* But that is not valid info until redisplay finishes. */
16101 w
->window_end_valid
= Qnil
;
16107 /************************************************************************
16108 Window redisplay reusing current matrix when buffer has not changed
16109 ************************************************************************/
16111 /* Try redisplay of window W showing an unchanged buffer with a
16112 different window start than the last time it was displayed by
16113 reusing its current matrix. Value is non-zero if successful.
16114 W->start is the new window start. */
16117 try_window_reusing_current_matrix (struct window
*w
)
16119 struct frame
*f
= XFRAME (w
->frame
);
16120 struct glyph_row
*bottom_row
;
16123 struct text_pos start
, new_start
;
16124 int nrows_scrolled
, i
;
16125 struct glyph_row
*last_text_row
;
16126 struct glyph_row
*last_reused_text_row
;
16127 struct glyph_row
*start_row
;
16128 int start_vpos
, min_y
, max_y
;
16131 if (inhibit_try_window_reusing
)
16135 if (/* This function doesn't handle terminal frames. */
16136 !FRAME_WINDOW_P (f
)
16137 /* Don't try to reuse the display if windows have been split
16139 || windows_or_buffers_changed
16140 || cursor_type_changed
)
16143 /* Can't do this if region may have changed. */
16144 if ((!NILP (Vtransient_mark_mode
)
16145 && !NILP (BVAR (current_buffer
, mark_active
)))
16146 || !NILP (w
->region_showing
)
16147 || !NILP (Vshow_trailing_whitespace
))
16150 /* If top-line visibility has changed, give up. */
16151 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16152 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16155 /* Give up if old or new display is scrolled vertically. We could
16156 make this function handle this, but right now it doesn't. */
16157 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16158 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16161 /* The variable new_start now holds the new window start. The old
16162 start `start' can be determined from the current matrix. */
16163 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16164 start
= start_row
->minpos
;
16165 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16167 /* Clear the desired matrix for the display below. */
16168 clear_glyph_matrix (w
->desired_matrix
);
16170 if (CHARPOS (new_start
) <= CHARPOS (start
))
16172 /* Don't use this method if the display starts with an ellipsis
16173 displayed for invisible text. It's not easy to handle that case
16174 below, and it's certainly not worth the effort since this is
16175 not a frequent case. */
16176 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16179 IF_DEBUG (debug_method_add (w
, "twu1"));
16181 /* Display up to a row that can be reused. The variable
16182 last_text_row is set to the last row displayed that displays
16183 text. Note that it.vpos == 0 if or if not there is a
16184 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16185 start_display (&it
, w
, new_start
);
16186 w
->cursor
.vpos
= -1;
16187 last_text_row
= last_reused_text_row
= NULL
;
16189 while (it
.current_y
< it
.last_visible_y
16190 && !fonts_changed_p
)
16192 /* If we have reached into the characters in the START row,
16193 that means the line boundaries have changed. So we
16194 can't start copying with the row START. Maybe it will
16195 work to start copying with the following row. */
16196 while (IT_CHARPOS (it
) > CHARPOS (start
))
16198 /* Advance to the next row as the "start". */
16200 start
= start_row
->minpos
;
16201 /* If there are no more rows to try, or just one, give up. */
16202 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16203 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16204 || CHARPOS (start
) == ZV
)
16206 clear_glyph_matrix (w
->desired_matrix
);
16210 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16212 /* If we have reached alignment, we can copy the rest of the
16214 if (IT_CHARPOS (it
) == CHARPOS (start
)
16215 /* Don't accept "alignment" inside a display vector,
16216 since start_row could have started in the middle of
16217 that same display vector (thus their character
16218 positions match), and we have no way of telling if
16219 that is the case. */
16220 && it
.current
.dpvec_index
< 0)
16223 if (display_line (&it
))
16224 last_text_row
= it
.glyph_row
- 1;
16228 /* A value of current_y < last_visible_y means that we stopped
16229 at the previous window start, which in turn means that we
16230 have at least one reusable row. */
16231 if (it
.current_y
< it
.last_visible_y
)
16233 struct glyph_row
*row
;
16235 /* IT.vpos always starts from 0; it counts text lines. */
16236 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16238 /* Find PT if not already found in the lines displayed. */
16239 if (w
->cursor
.vpos
< 0)
16241 int dy
= it
.current_y
- start_row
->y
;
16243 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16244 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16246 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16247 dy
, nrows_scrolled
);
16250 clear_glyph_matrix (w
->desired_matrix
);
16255 /* Scroll the display. Do it before the current matrix is
16256 changed. The problem here is that update has not yet
16257 run, i.e. part of the current matrix is not up to date.
16258 scroll_run_hook will clear the cursor, and use the
16259 current matrix to get the height of the row the cursor is
16261 run
.current_y
= start_row
->y
;
16262 run
.desired_y
= it
.current_y
;
16263 run
.height
= it
.last_visible_y
- it
.current_y
;
16265 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16268 FRAME_RIF (f
)->update_window_begin_hook (w
);
16269 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16270 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16271 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16275 /* Shift current matrix down by nrows_scrolled lines. */
16276 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16277 rotate_matrix (w
->current_matrix
,
16279 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16282 /* Disable lines that must be updated. */
16283 for (i
= 0; i
< nrows_scrolled
; ++i
)
16284 (start_row
+ i
)->enabled_p
= 0;
16286 /* Re-compute Y positions. */
16287 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16288 max_y
= it
.last_visible_y
;
16289 for (row
= start_row
+ nrows_scrolled
;
16293 row
->y
= it
.current_y
;
16294 row
->visible_height
= row
->height
;
16296 if (row
->y
< min_y
)
16297 row
->visible_height
-= min_y
- row
->y
;
16298 if (row
->y
+ row
->height
> max_y
)
16299 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16300 if (row
->fringe_bitmap_periodic_p
)
16301 row
->redraw_fringe_bitmaps_p
= 1;
16303 it
.current_y
+= row
->height
;
16305 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16306 last_reused_text_row
= row
;
16307 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16311 /* Disable lines in the current matrix which are now
16312 below the window. */
16313 for (++row
; row
< bottom_row
; ++row
)
16314 row
->enabled_p
= row
->mode_line_p
= 0;
16317 /* Update window_end_pos etc.; last_reused_text_row is the last
16318 reused row from the current matrix containing text, if any.
16319 The value of last_text_row is the last displayed line
16320 containing text. */
16321 if (last_reused_text_row
)
16323 w
->window_end_bytepos
16324 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16326 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16328 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16329 w
->current_matrix
));
16331 else if (last_text_row
)
16333 w
->window_end_bytepos
16334 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16336 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16338 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16342 /* This window must be completely empty. */
16343 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16344 w
->window_end_pos
= make_number (Z
- ZV
);
16345 w
->window_end_vpos
= make_number (0);
16347 w
->window_end_valid
= Qnil
;
16349 /* Update hint: don't try scrolling again in update_window. */
16350 w
->desired_matrix
->no_scrolling_p
= 1;
16353 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16357 else if (CHARPOS (new_start
) > CHARPOS (start
))
16359 struct glyph_row
*pt_row
, *row
;
16360 struct glyph_row
*first_reusable_row
;
16361 struct glyph_row
*first_row_to_display
;
16363 int yb
= window_text_bottom_y (w
);
16365 /* Find the row starting at new_start, if there is one. Don't
16366 reuse a partially visible line at the end. */
16367 first_reusable_row
= start_row
;
16368 while (first_reusable_row
->enabled_p
16369 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16370 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16371 < CHARPOS (new_start
)))
16372 ++first_reusable_row
;
16374 /* Give up if there is no row to reuse. */
16375 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16376 || !first_reusable_row
->enabled_p
16377 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16378 != CHARPOS (new_start
)))
16381 /* We can reuse fully visible rows beginning with
16382 first_reusable_row to the end of the window. Set
16383 first_row_to_display to the first row that cannot be reused.
16384 Set pt_row to the row containing point, if there is any. */
16386 for (first_row_to_display
= first_reusable_row
;
16387 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16388 ++first_row_to_display
)
16390 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16391 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16392 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16393 && first_row_to_display
->ends_at_zv_p
16394 && pt_row
== NULL
)))
16395 pt_row
= first_row_to_display
;
16398 /* Start displaying at the start of first_row_to_display. */
16399 xassert (first_row_to_display
->y
< yb
);
16400 init_to_row_start (&it
, w
, first_row_to_display
);
16402 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16404 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16406 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16407 + WINDOW_HEADER_LINE_HEIGHT (w
));
16409 /* Display lines beginning with first_row_to_display in the
16410 desired matrix. Set last_text_row to the last row displayed
16411 that displays text. */
16412 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16413 if (pt_row
== NULL
)
16414 w
->cursor
.vpos
= -1;
16415 last_text_row
= NULL
;
16416 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16417 if (display_line (&it
))
16418 last_text_row
= it
.glyph_row
- 1;
16420 /* If point is in a reused row, adjust y and vpos of the cursor
16424 w
->cursor
.vpos
-= nrows_scrolled
;
16425 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16428 /* Give up if point isn't in a row displayed or reused. (This
16429 also handles the case where w->cursor.vpos < nrows_scrolled
16430 after the calls to display_line, which can happen with scroll
16431 margins. See bug#1295.) */
16432 if (w
->cursor
.vpos
< 0)
16434 clear_glyph_matrix (w
->desired_matrix
);
16438 /* Scroll the display. */
16439 run
.current_y
= first_reusable_row
->y
;
16440 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16441 run
.height
= it
.last_visible_y
- run
.current_y
;
16442 dy
= run
.current_y
- run
.desired_y
;
16447 FRAME_RIF (f
)->update_window_begin_hook (w
);
16448 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16449 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16450 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16454 /* Adjust Y positions of reused rows. */
16455 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16456 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16457 max_y
= it
.last_visible_y
;
16458 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16461 row
->visible_height
= row
->height
;
16462 if (row
->y
< min_y
)
16463 row
->visible_height
-= min_y
- row
->y
;
16464 if (row
->y
+ row
->height
> max_y
)
16465 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16466 if (row
->fringe_bitmap_periodic_p
)
16467 row
->redraw_fringe_bitmaps_p
= 1;
16470 /* Scroll the current matrix. */
16471 xassert (nrows_scrolled
> 0);
16472 rotate_matrix (w
->current_matrix
,
16474 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16477 /* Disable rows not reused. */
16478 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16479 row
->enabled_p
= 0;
16481 /* Point may have moved to a different line, so we cannot assume that
16482 the previous cursor position is valid; locate the correct row. */
16485 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16487 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16488 && !row
->ends_at_zv_p
;
16492 w
->cursor
.y
= row
->y
;
16494 if (row
< bottom_row
)
16496 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16497 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16499 /* Can't use this optimization with bidi-reordered glyph
16500 rows, unless cursor is already at point. */
16501 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16503 if (!(w
->cursor
.hpos
>= 0
16504 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16505 && BUFFERP (glyph
->object
)
16506 && glyph
->charpos
== PT
))
16511 && (!BUFFERP (glyph
->object
)
16512 || glyph
->charpos
< PT
);
16516 w
->cursor
.x
+= glyph
->pixel_width
;
16521 /* Adjust window end. A null value of last_text_row means that
16522 the window end is in reused rows which in turn means that
16523 only its vpos can have changed. */
16526 w
->window_end_bytepos
16527 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16529 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16531 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16536 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16539 w
->window_end_valid
= Qnil
;
16540 w
->desired_matrix
->no_scrolling_p
= 1;
16543 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16553 /************************************************************************
16554 Window redisplay reusing current matrix when buffer has changed
16555 ************************************************************************/
16557 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16558 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16559 ptrdiff_t *, ptrdiff_t *);
16560 static struct glyph_row
*
16561 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16562 struct glyph_row
*);
16565 /* Return the last row in MATRIX displaying text. If row START is
16566 non-null, start searching with that row. IT gives the dimensions
16567 of the display. Value is null if matrix is empty; otherwise it is
16568 a pointer to the row found. */
16570 static struct glyph_row
*
16571 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16572 struct glyph_row
*start
)
16574 struct glyph_row
*row
, *row_found
;
16576 /* Set row_found to the last row in IT->w's current matrix
16577 displaying text. The loop looks funny but think of partially
16580 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16581 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16583 xassert (row
->enabled_p
);
16585 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16594 /* Return the last row in the current matrix of W that is not affected
16595 by changes at the start of current_buffer that occurred since W's
16596 current matrix was built. Value is null if no such row exists.
16598 BEG_UNCHANGED us the number of characters unchanged at the start of
16599 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16600 first changed character in current_buffer. Characters at positions <
16601 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16602 when the current matrix was built. */
16604 static struct glyph_row
*
16605 find_last_unchanged_at_beg_row (struct window
*w
)
16607 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16608 struct glyph_row
*row
;
16609 struct glyph_row
*row_found
= NULL
;
16610 int yb
= window_text_bottom_y (w
);
16612 /* Find the last row displaying unchanged text. */
16613 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16614 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16615 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16618 if (/* If row ends before first_changed_pos, it is unchanged,
16619 except in some case. */
16620 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16621 /* When row ends in ZV and we write at ZV it is not
16623 && !row
->ends_at_zv_p
16624 /* When first_changed_pos is the end of a continued line,
16625 row is not unchanged because it may be no longer
16627 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16628 && (row
->continued_p
16629 || row
->exact_window_width_line_p
))
16630 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16631 needs to be recomputed, so don't consider this row as
16632 unchanged. This happens when the last line was
16633 bidi-reordered and was killed immediately before this
16634 redisplay cycle. In that case, ROW->end stores the
16635 buffer position of the first visual-order character of
16636 the killed text, which is now beyond ZV. */
16637 && CHARPOS (row
->end
.pos
) <= ZV
)
16640 /* Stop if last visible row. */
16641 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16649 /* Find the first glyph row in the current matrix of W that is not
16650 affected by changes at the end of current_buffer since the
16651 time W's current matrix was built.
16653 Return in *DELTA the number of chars by which buffer positions in
16654 unchanged text at the end of current_buffer must be adjusted.
16656 Return in *DELTA_BYTES the corresponding number of bytes.
16658 Value is null if no such row exists, i.e. all rows are affected by
16661 static struct glyph_row
*
16662 find_first_unchanged_at_end_row (struct window
*w
,
16663 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16665 struct glyph_row
*row
;
16666 struct glyph_row
*row_found
= NULL
;
16668 *delta
= *delta_bytes
= 0;
16670 /* Display must not have been paused, otherwise the current matrix
16671 is not up to date. */
16672 eassert (!NILP (w
->window_end_valid
));
16674 /* A value of window_end_pos >= END_UNCHANGED means that the window
16675 end is in the range of changed text. If so, there is no
16676 unchanged row at the end of W's current matrix. */
16677 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16680 /* Set row to the last row in W's current matrix displaying text. */
16681 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16683 /* If matrix is entirely empty, no unchanged row exists. */
16684 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16686 /* The value of row is the last glyph row in the matrix having a
16687 meaningful buffer position in it. The end position of row
16688 corresponds to window_end_pos. This allows us to translate
16689 buffer positions in the current matrix to current buffer
16690 positions for characters not in changed text. */
16692 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16693 ptrdiff_t Z_BYTE_old
=
16694 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16695 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16696 struct glyph_row
*first_text_row
16697 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16699 *delta
= Z
- Z_old
;
16700 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16702 /* Set last_unchanged_pos to the buffer position of the last
16703 character in the buffer that has not been changed. Z is the
16704 index + 1 of the last character in current_buffer, i.e. by
16705 subtracting END_UNCHANGED we get the index of the last
16706 unchanged character, and we have to add BEG to get its buffer
16708 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16709 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16711 /* Search backward from ROW for a row displaying a line that
16712 starts at a minimum position >= last_unchanged_pos_old. */
16713 for (; row
> first_text_row
; --row
)
16715 /* This used to abort, but it can happen.
16716 It is ok to just stop the search instead here. KFS. */
16717 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16720 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16725 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16731 /* Make sure that glyph rows in the current matrix of window W
16732 reference the same glyph memory as corresponding rows in the
16733 frame's frame matrix. This function is called after scrolling W's
16734 current matrix on a terminal frame in try_window_id and
16735 try_window_reusing_current_matrix. */
16738 sync_frame_with_window_matrix_rows (struct window
*w
)
16740 struct frame
*f
= XFRAME (w
->frame
);
16741 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16743 /* Preconditions: W must be a leaf window and full-width. Its frame
16744 must have a frame matrix. */
16745 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16746 xassert (WINDOW_FULL_WIDTH_P (w
));
16747 xassert (!FRAME_WINDOW_P (f
));
16749 /* If W is a full-width window, glyph pointers in W's current matrix
16750 have, by definition, to be the same as glyph pointers in the
16751 corresponding frame matrix. Note that frame matrices have no
16752 marginal areas (see build_frame_matrix). */
16753 window_row
= w
->current_matrix
->rows
;
16754 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16755 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16756 while (window_row
< window_row_end
)
16758 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16759 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16761 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16762 frame_row
->glyphs
[TEXT_AREA
] = start
;
16763 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16764 frame_row
->glyphs
[LAST_AREA
] = end
;
16766 /* Disable frame rows whose corresponding window rows have
16767 been disabled in try_window_id. */
16768 if (!window_row
->enabled_p
)
16769 frame_row
->enabled_p
= 0;
16771 ++window_row
, ++frame_row
;
16776 /* Find the glyph row in window W containing CHARPOS. Consider all
16777 rows between START and END (not inclusive). END null means search
16778 all rows to the end of the display area of W. Value is the row
16779 containing CHARPOS or null. */
16782 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16783 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16785 struct glyph_row
*row
= start
;
16786 struct glyph_row
*best_row
= NULL
;
16787 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16790 /* If we happen to start on a header-line, skip that. */
16791 if (row
->mode_line_p
)
16794 if ((end
&& row
>= end
) || !row
->enabled_p
)
16797 last_y
= window_text_bottom_y (w
) - dy
;
16801 /* Give up if we have gone too far. */
16802 if (end
&& row
>= end
)
16804 /* This formerly returned if they were equal.
16805 I think that both quantities are of a "last plus one" type;
16806 if so, when they are equal, the row is within the screen. -- rms. */
16807 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16810 /* If it is in this row, return this row. */
16811 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16812 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16813 /* The end position of a row equals the start
16814 position of the next row. If CHARPOS is there, we
16815 would rather display it in the next line, except
16816 when this line ends in ZV. */
16817 && !row
->ends_at_zv_p
16818 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16819 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16823 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16824 || (!best_row
&& !row
->continued_p
))
16826 /* In bidi-reordered rows, there could be several rows
16827 occluding point, all of them belonging to the same
16828 continued line. We need to find the row which fits
16829 CHARPOS the best. */
16830 for (g
= row
->glyphs
[TEXT_AREA
];
16831 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16834 if (!STRINGP (g
->object
))
16836 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16838 mindif
= eabs (g
->charpos
- charpos
);
16840 /* Exact match always wins. */
16847 else if (best_row
&& !row
->continued_p
)
16854 /* Try to redisplay window W by reusing its existing display. W's
16855 current matrix must be up to date when this function is called,
16856 i.e. window_end_valid must not be nil.
16860 1 if display has been updated
16861 0 if otherwise unsuccessful
16862 -1 if redisplay with same window start is known not to succeed
16864 The following steps are performed:
16866 1. Find the last row in the current matrix of W that is not
16867 affected by changes at the start of current_buffer. If no such row
16870 2. Find the first row in W's current matrix that is not affected by
16871 changes at the end of current_buffer. Maybe there is no such row.
16873 3. Display lines beginning with the row + 1 found in step 1 to the
16874 row found in step 2 or, if step 2 didn't find a row, to the end of
16877 4. If cursor is not known to appear on the window, give up.
16879 5. If display stopped at the row found in step 2, scroll the
16880 display and current matrix as needed.
16882 6. Maybe display some lines at the end of W, if we must. This can
16883 happen under various circumstances, like a partially visible line
16884 becoming fully visible, or because newly displayed lines are displayed
16885 in smaller font sizes.
16887 7. Update W's window end information. */
16890 try_window_id (struct window
*w
)
16892 struct frame
*f
= XFRAME (w
->frame
);
16893 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16894 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16895 struct glyph_row
*last_unchanged_at_beg_row
;
16896 struct glyph_row
*first_unchanged_at_end_row
;
16897 struct glyph_row
*row
;
16898 struct glyph_row
*bottom_row
;
16901 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
16903 struct text_pos start_pos
;
16905 int first_unchanged_at_end_vpos
= 0;
16906 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16907 struct text_pos start
;
16908 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
16911 if (inhibit_try_window_id
)
16915 /* This is handy for debugging. */
16917 #define GIVE_UP(X) \
16919 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16923 #define GIVE_UP(X) return 0
16926 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16928 /* Don't use this for mini-windows because these can show
16929 messages and mini-buffers, and we don't handle that here. */
16930 if (MINI_WINDOW_P (w
))
16933 /* This flag is used to prevent redisplay optimizations. */
16934 if (windows_or_buffers_changed
|| cursor_type_changed
)
16937 /* Verify that narrowing has not changed.
16938 Also verify that we were not told to prevent redisplay optimizations.
16939 It would be nice to further
16940 reduce the number of cases where this prevents try_window_id. */
16941 if (current_buffer
->clip_changed
16942 || current_buffer
->prevent_redisplay_optimizations_p
)
16945 /* Window must either use window-based redisplay or be full width. */
16946 if (!FRAME_WINDOW_P (f
)
16947 && (!FRAME_LINE_INS_DEL_OK (f
)
16948 || !WINDOW_FULL_WIDTH_P (w
)))
16951 /* Give up if point is known NOT to appear in W. */
16952 if (PT
< CHARPOS (start
))
16955 /* Another way to prevent redisplay optimizations. */
16956 if (XFASTINT (w
->last_modified
) == 0)
16959 /* Verify that window is not hscrolled. */
16960 if (XFASTINT (w
->hscroll
) != 0)
16963 /* Verify that display wasn't paused. */
16964 if (NILP (w
->window_end_valid
))
16967 /* Can't use this if highlighting a region because a cursor movement
16968 will do more than just set the cursor. */
16969 if (!NILP (Vtransient_mark_mode
)
16970 && !NILP (BVAR (current_buffer
, mark_active
)))
16973 /* Likewise if highlighting trailing whitespace. */
16974 if (!NILP (Vshow_trailing_whitespace
))
16977 /* Likewise if showing a region. */
16978 if (!NILP (w
->region_showing
))
16981 /* Can't use this if overlay arrow position and/or string have
16983 if (overlay_arrows_changed_p ())
16986 /* When word-wrap is on, adding a space to the first word of a
16987 wrapped line can change the wrap position, altering the line
16988 above it. It might be worthwhile to handle this more
16989 intelligently, but for now just redisplay from scratch. */
16990 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16993 /* Under bidi reordering, adding or deleting a character in the
16994 beginning of a paragraph, before the first strong directional
16995 character, can change the base direction of the paragraph (unless
16996 the buffer specifies a fixed paragraph direction), which will
16997 require to redisplay the whole paragraph. It might be worthwhile
16998 to find the paragraph limits and widen the range of redisplayed
16999 lines to that, but for now just give up this optimization and
17000 redisplay from scratch. */
17001 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17002 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17005 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17006 only if buffer has really changed. The reason is that the gap is
17007 initially at Z for freshly visited files. The code below would
17008 set end_unchanged to 0 in that case. */
17009 if (MODIFF
> SAVE_MODIFF
17010 /* This seems to happen sometimes after saving a buffer. */
17011 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17013 if (GPT
- BEG
< BEG_UNCHANGED
)
17014 BEG_UNCHANGED
= GPT
- BEG
;
17015 if (Z
- GPT
< END_UNCHANGED
)
17016 END_UNCHANGED
= Z
- GPT
;
17019 /* The position of the first and last character that has been changed. */
17020 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17021 last_changed_charpos
= Z
- END_UNCHANGED
;
17023 /* If window starts after a line end, and the last change is in
17024 front of that newline, then changes don't affect the display.
17025 This case happens with stealth-fontification. Note that although
17026 the display is unchanged, glyph positions in the matrix have to
17027 be adjusted, of course. */
17028 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17029 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17030 && ((last_changed_charpos
< CHARPOS (start
)
17031 && CHARPOS (start
) == BEGV
)
17032 || (last_changed_charpos
< CHARPOS (start
) - 1
17033 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17035 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17036 struct glyph_row
*r0
;
17038 /* Compute how many chars/bytes have been added to or removed
17039 from the buffer. */
17040 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17041 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17042 Z_delta
= Z
- Z_old
;
17043 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17045 /* Give up if PT is not in the window. Note that it already has
17046 been checked at the start of try_window_id that PT is not in
17047 front of the window start. */
17048 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17051 /* If window start is unchanged, we can reuse the whole matrix
17052 as is, after adjusting glyph positions. No need to compute
17053 the window end again, since its offset from Z hasn't changed. */
17054 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17055 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17056 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17057 /* PT must not be in a partially visible line. */
17058 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17059 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17061 /* Adjust positions in the glyph matrix. */
17062 if (Z_delta
|| Z_delta_bytes
)
17064 struct glyph_row
*r1
17065 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17066 increment_matrix_positions (w
->current_matrix
,
17067 MATRIX_ROW_VPOS (r0
, current_matrix
),
17068 MATRIX_ROW_VPOS (r1
, current_matrix
),
17069 Z_delta
, Z_delta_bytes
);
17072 /* Set the cursor. */
17073 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17075 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17082 /* Handle the case that changes are all below what is displayed in
17083 the window, and that PT is in the window. This shortcut cannot
17084 be taken if ZV is visible in the window, and text has been added
17085 there that is visible in the window. */
17086 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17087 /* ZV is not visible in the window, or there are no
17088 changes at ZV, actually. */
17089 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17090 || first_changed_charpos
== last_changed_charpos
))
17092 struct glyph_row
*r0
;
17094 /* Give up if PT is not in the window. Note that it already has
17095 been checked at the start of try_window_id that PT is not in
17096 front of the window start. */
17097 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17100 /* If window start is unchanged, we can reuse the whole matrix
17101 as is, without changing glyph positions since no text has
17102 been added/removed in front of the window end. */
17103 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17104 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17105 /* PT must not be in a partially visible line. */
17106 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17107 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17109 /* We have to compute the window end anew since text
17110 could have been added/removed after it. */
17112 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17113 w
->window_end_bytepos
17114 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17116 /* Set the cursor. */
17117 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17119 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17126 /* Give up if window start is in the changed area.
17128 The condition used to read
17130 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17132 but why that was tested escapes me at the moment. */
17133 if (CHARPOS (start
) >= first_changed_charpos
17134 && CHARPOS (start
) <= last_changed_charpos
)
17137 /* Check that window start agrees with the start of the first glyph
17138 row in its current matrix. Check this after we know the window
17139 start is not in changed text, otherwise positions would not be
17141 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17142 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17145 /* Give up if the window ends in strings. Overlay strings
17146 at the end are difficult to handle, so don't try. */
17147 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17148 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17151 /* Compute the position at which we have to start displaying new
17152 lines. Some of the lines at the top of the window might be
17153 reusable because they are not displaying changed text. Find the
17154 last row in W's current matrix not affected by changes at the
17155 start of current_buffer. Value is null if changes start in the
17156 first line of window. */
17157 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17158 if (last_unchanged_at_beg_row
)
17160 /* Avoid starting to display in the middle of a character, a TAB
17161 for instance. This is easier than to set up the iterator
17162 exactly, and it's not a frequent case, so the additional
17163 effort wouldn't really pay off. */
17164 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17165 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17166 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17167 --last_unchanged_at_beg_row
;
17169 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17172 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17174 start_pos
= it
.current
.pos
;
17176 /* Start displaying new lines in the desired matrix at the same
17177 vpos we would use in the current matrix, i.e. below
17178 last_unchanged_at_beg_row. */
17179 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17181 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17182 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17184 xassert (it
.hpos
== 0 && it
.current_x
== 0);
17188 /* There are no reusable lines at the start of the window.
17189 Start displaying in the first text line. */
17190 start_display (&it
, w
, start
);
17191 it
.vpos
= it
.first_vpos
;
17192 start_pos
= it
.current
.pos
;
17195 /* Find the first row that is not affected by changes at the end of
17196 the buffer. Value will be null if there is no unchanged row, in
17197 which case we must redisplay to the end of the window. delta
17198 will be set to the value by which buffer positions beginning with
17199 first_unchanged_at_end_row have to be adjusted due to text
17201 first_unchanged_at_end_row
17202 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17203 IF_DEBUG (debug_delta
= delta
);
17204 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17206 /* Set stop_pos to the buffer position up to which we will have to
17207 display new lines. If first_unchanged_at_end_row != NULL, this
17208 is the buffer position of the start of the line displayed in that
17209 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17210 that we don't stop at a buffer position. */
17212 if (first_unchanged_at_end_row
)
17214 xassert (last_unchanged_at_beg_row
== NULL
17215 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17217 /* If this is a continuation line, move forward to the next one
17218 that isn't. Changes in lines above affect this line.
17219 Caution: this may move first_unchanged_at_end_row to a row
17220 not displaying text. */
17221 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17222 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17223 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17224 < it
.last_visible_y
))
17225 ++first_unchanged_at_end_row
;
17227 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17228 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17229 >= it
.last_visible_y
))
17230 first_unchanged_at_end_row
= NULL
;
17233 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17235 first_unchanged_at_end_vpos
17236 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17237 xassert (stop_pos
>= Z
- END_UNCHANGED
);
17240 else if (last_unchanged_at_beg_row
== NULL
)
17246 /* Either there is no unchanged row at the end, or the one we have
17247 now displays text. This is a necessary condition for the window
17248 end pos calculation at the end of this function. */
17249 xassert (first_unchanged_at_end_row
== NULL
17250 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17252 debug_last_unchanged_at_beg_vpos
17253 = (last_unchanged_at_beg_row
17254 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17256 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17258 #endif /* GLYPH_DEBUG != 0 */
17261 /* Display new lines. Set last_text_row to the last new line
17262 displayed which has text on it, i.e. might end up as being the
17263 line where the window_end_vpos is. */
17264 w
->cursor
.vpos
= -1;
17265 last_text_row
= NULL
;
17266 overlay_arrow_seen
= 0;
17267 while (it
.current_y
< it
.last_visible_y
17268 && !fonts_changed_p
17269 && (first_unchanged_at_end_row
== NULL
17270 || IT_CHARPOS (it
) < stop_pos
))
17272 if (display_line (&it
))
17273 last_text_row
= it
.glyph_row
- 1;
17276 if (fonts_changed_p
)
17280 /* Compute differences in buffer positions, y-positions etc. for
17281 lines reused at the bottom of the window. Compute what we can
17283 if (first_unchanged_at_end_row
17284 /* No lines reused because we displayed everything up to the
17285 bottom of the window. */
17286 && it
.current_y
< it
.last_visible_y
)
17289 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17291 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17292 run
.current_y
= first_unchanged_at_end_row
->y
;
17293 run
.desired_y
= run
.current_y
+ dy
;
17294 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17298 delta
= delta_bytes
= dvpos
= dy
17299 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17300 first_unchanged_at_end_row
= NULL
;
17302 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17305 /* Find the cursor if not already found. We have to decide whether
17306 PT will appear on this window (it sometimes doesn't, but this is
17307 not a very frequent case.) This decision has to be made before
17308 the current matrix is altered. A value of cursor.vpos < 0 means
17309 that PT is either in one of the lines beginning at
17310 first_unchanged_at_end_row or below the window. Don't care for
17311 lines that might be displayed later at the window end; as
17312 mentioned, this is not a frequent case. */
17313 if (w
->cursor
.vpos
< 0)
17315 /* Cursor in unchanged rows at the top? */
17316 if (PT
< CHARPOS (start_pos
)
17317 && last_unchanged_at_beg_row
)
17319 row
= row_containing_pos (w
, PT
,
17320 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17321 last_unchanged_at_beg_row
+ 1, 0);
17323 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17326 /* Start from first_unchanged_at_end_row looking for PT. */
17327 else if (first_unchanged_at_end_row
)
17329 row
= row_containing_pos (w
, PT
- delta
,
17330 first_unchanged_at_end_row
, NULL
, 0);
17332 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17333 delta_bytes
, dy
, dvpos
);
17336 /* Give up if cursor was not found. */
17337 if (w
->cursor
.vpos
< 0)
17339 clear_glyph_matrix (w
->desired_matrix
);
17344 /* Don't let the cursor end in the scroll margins. */
17346 int this_scroll_margin
, cursor_height
;
17348 this_scroll_margin
=
17349 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17350 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17351 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17353 if ((w
->cursor
.y
< this_scroll_margin
17354 && CHARPOS (start
) > BEGV
)
17355 /* Old redisplay didn't take scroll margin into account at the bottom,
17356 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17357 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17358 ? cursor_height
+ this_scroll_margin
17359 : 1)) > it
.last_visible_y
)
17361 w
->cursor
.vpos
= -1;
17362 clear_glyph_matrix (w
->desired_matrix
);
17367 /* Scroll the display. Do it before changing the current matrix so
17368 that xterm.c doesn't get confused about where the cursor glyph is
17370 if (dy
&& run
.height
)
17374 if (FRAME_WINDOW_P (f
))
17376 FRAME_RIF (f
)->update_window_begin_hook (w
);
17377 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17378 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17379 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17383 /* Terminal frame. In this case, dvpos gives the number of
17384 lines to scroll by; dvpos < 0 means scroll up. */
17386 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17387 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17388 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17389 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17390 + window_internal_height (w
));
17392 #if defined (HAVE_GPM) || defined (MSDOS)
17393 x_clear_window_mouse_face (w
);
17395 /* Perform the operation on the screen. */
17398 /* Scroll last_unchanged_at_beg_row to the end of the
17399 window down dvpos lines. */
17400 set_terminal_window (f
, end
);
17402 /* On dumb terminals delete dvpos lines at the end
17403 before inserting dvpos empty lines. */
17404 if (!FRAME_SCROLL_REGION_OK (f
))
17405 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17407 /* Insert dvpos empty lines in front of
17408 last_unchanged_at_beg_row. */
17409 ins_del_lines (f
, from
, dvpos
);
17411 else if (dvpos
< 0)
17413 /* Scroll up last_unchanged_at_beg_vpos to the end of
17414 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17415 set_terminal_window (f
, end
);
17417 /* Delete dvpos lines in front of
17418 last_unchanged_at_beg_vpos. ins_del_lines will set
17419 the cursor to the given vpos and emit |dvpos| delete
17421 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17423 /* On a dumb terminal insert dvpos empty lines at the
17425 if (!FRAME_SCROLL_REGION_OK (f
))
17426 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17429 set_terminal_window (f
, 0);
17435 /* Shift reused rows of the current matrix to the right position.
17436 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17438 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17439 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17442 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17443 bottom_vpos
, dvpos
);
17444 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17447 else if (dvpos
> 0)
17449 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17450 bottom_vpos
, dvpos
);
17451 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17452 first_unchanged_at_end_vpos
+ dvpos
, 0);
17455 /* For frame-based redisplay, make sure that current frame and window
17456 matrix are in sync with respect to glyph memory. */
17457 if (!FRAME_WINDOW_P (f
))
17458 sync_frame_with_window_matrix_rows (w
);
17460 /* Adjust buffer positions in reused rows. */
17461 if (delta
|| delta_bytes
)
17462 increment_matrix_positions (current_matrix
,
17463 first_unchanged_at_end_vpos
+ dvpos
,
17464 bottom_vpos
, delta
, delta_bytes
);
17466 /* Adjust Y positions. */
17468 shift_glyph_matrix (w
, current_matrix
,
17469 first_unchanged_at_end_vpos
+ dvpos
,
17472 if (first_unchanged_at_end_row
)
17474 first_unchanged_at_end_row
+= dvpos
;
17475 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17476 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17477 first_unchanged_at_end_row
= NULL
;
17480 /* If scrolling up, there may be some lines to display at the end of
17482 last_text_row_at_end
= NULL
;
17485 /* Scrolling up can leave for example a partially visible line
17486 at the end of the window to be redisplayed. */
17487 /* Set last_row to the glyph row in the current matrix where the
17488 window end line is found. It has been moved up or down in
17489 the matrix by dvpos. */
17490 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17491 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17493 /* If last_row is the window end line, it should display text. */
17494 xassert (last_row
->displays_text_p
);
17496 /* If window end line was partially visible before, begin
17497 displaying at that line. Otherwise begin displaying with the
17498 line following it. */
17499 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17501 init_to_row_start (&it
, w
, last_row
);
17502 it
.vpos
= last_vpos
;
17503 it
.current_y
= last_row
->y
;
17507 init_to_row_end (&it
, w
, last_row
);
17508 it
.vpos
= 1 + last_vpos
;
17509 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17513 /* We may start in a continuation line. If so, we have to
17514 get the right continuation_lines_width and current_x. */
17515 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17516 it
.hpos
= it
.current_x
= 0;
17518 /* Display the rest of the lines at the window end. */
17519 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17520 while (it
.current_y
< it
.last_visible_y
17521 && !fonts_changed_p
)
17523 /* Is it always sure that the display agrees with lines in
17524 the current matrix? I don't think so, so we mark rows
17525 displayed invalid in the current matrix by setting their
17526 enabled_p flag to zero. */
17527 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17528 if (display_line (&it
))
17529 last_text_row_at_end
= it
.glyph_row
- 1;
17533 /* Update window_end_pos and window_end_vpos. */
17534 if (first_unchanged_at_end_row
17535 && !last_text_row_at_end
)
17537 /* Window end line if one of the preserved rows from the current
17538 matrix. Set row to the last row displaying text in current
17539 matrix starting at first_unchanged_at_end_row, after
17541 xassert (first_unchanged_at_end_row
->displays_text_p
);
17542 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17543 first_unchanged_at_end_row
);
17544 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17546 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17547 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17549 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17550 xassert (w
->window_end_bytepos
>= 0);
17551 IF_DEBUG (debug_method_add (w
, "A"));
17553 else if (last_text_row_at_end
)
17556 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17557 w
->window_end_bytepos
17558 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17560 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17561 xassert (w
->window_end_bytepos
>= 0);
17562 IF_DEBUG (debug_method_add (w
, "B"));
17564 else if (last_text_row
)
17566 /* We have displayed either to the end of the window or at the
17567 end of the window, i.e. the last row with text is to be found
17568 in the desired matrix. */
17570 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17571 w
->window_end_bytepos
17572 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17574 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17575 xassert (w
->window_end_bytepos
>= 0);
17577 else if (first_unchanged_at_end_row
== NULL
17578 && last_text_row
== NULL
17579 && last_text_row_at_end
== NULL
)
17581 /* Displayed to end of window, but no line containing text was
17582 displayed. Lines were deleted at the end of the window. */
17583 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17584 int vpos
= XFASTINT (w
->window_end_vpos
);
17585 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17586 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17589 row
== NULL
&& vpos
>= first_vpos
;
17590 --vpos
, --current_row
, --desired_row
)
17592 if (desired_row
->enabled_p
)
17594 if (desired_row
->displays_text_p
)
17597 else if (current_row
->displays_text_p
)
17601 xassert (row
!= NULL
);
17602 w
->window_end_vpos
= make_number (vpos
+ 1);
17603 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17604 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17605 xassert (w
->window_end_bytepos
>= 0);
17606 IF_DEBUG (debug_method_add (w
, "C"));
17611 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17612 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17614 /* Record that display has not been completed. */
17615 w
->window_end_valid
= Qnil
;
17616 w
->desired_matrix
->no_scrolling_p
= 1;
17624 /***********************************************************************
17625 More debugging support
17626 ***********************************************************************/
17630 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17631 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17632 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17635 /* Dump the contents of glyph matrix MATRIX on stderr.
17637 GLYPHS 0 means don't show glyph contents.
17638 GLYPHS 1 means show glyphs in short form
17639 GLYPHS > 1 means show glyphs in long form. */
17642 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17645 for (i
= 0; i
< matrix
->nrows
; ++i
)
17646 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17650 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17651 the glyph row and area where the glyph comes from. */
17654 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17656 if (glyph
->type
== CHAR_GLYPH
)
17659 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17660 glyph
- row
->glyphs
[TEXT_AREA
],
17663 (BUFFERP (glyph
->object
)
17665 : (STRINGP (glyph
->object
)
17668 glyph
->pixel_width
,
17670 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17674 glyph
->left_box_line_p
,
17675 glyph
->right_box_line_p
);
17677 else if (glyph
->type
== STRETCH_GLYPH
)
17680 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17681 glyph
- row
->glyphs
[TEXT_AREA
],
17684 (BUFFERP (glyph
->object
)
17686 : (STRINGP (glyph
->object
)
17689 glyph
->pixel_width
,
17693 glyph
->left_box_line_p
,
17694 glyph
->right_box_line_p
);
17696 else if (glyph
->type
== IMAGE_GLYPH
)
17699 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17700 glyph
- row
->glyphs
[TEXT_AREA
],
17703 (BUFFERP (glyph
->object
)
17705 : (STRINGP (glyph
->object
)
17708 glyph
->pixel_width
,
17712 glyph
->left_box_line_p
,
17713 glyph
->right_box_line_p
);
17715 else if (glyph
->type
== COMPOSITE_GLYPH
)
17718 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17719 glyph
- row
->glyphs
[TEXT_AREA
],
17722 (BUFFERP (glyph
->object
)
17724 : (STRINGP (glyph
->object
)
17727 glyph
->pixel_width
,
17729 if (glyph
->u
.cmp
.automatic
)
17732 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17733 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17735 glyph
->left_box_line_p
,
17736 glyph
->right_box_line_p
);
17741 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17742 GLYPHS 0 means don't show glyph contents.
17743 GLYPHS 1 means show glyphs in short form
17744 GLYPHS > 1 means show glyphs in long form. */
17747 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17751 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17752 fprintf (stderr
, "======================================================================\n");
17754 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17755 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17757 MATRIX_ROW_START_CHARPOS (row
),
17758 MATRIX_ROW_END_CHARPOS (row
),
17759 row
->used
[TEXT_AREA
],
17760 row
->contains_overlapping_glyphs_p
,
17762 row
->truncated_on_left_p
,
17763 row
->truncated_on_right_p
,
17765 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17766 row
->displays_text_p
,
17769 row
->ends_in_middle_of_char_p
,
17770 row
->starts_in_middle_of_char_p
,
17776 row
->visible_height
,
17779 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17780 row
->end
.overlay_string_index
,
17781 row
->continuation_lines_width
);
17782 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17783 CHARPOS (row
->start
.string_pos
),
17784 CHARPOS (row
->end
.string_pos
));
17785 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17786 row
->end
.dpvec_index
);
17793 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17795 struct glyph
*glyph
= row
->glyphs
[area
];
17796 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17798 /* Glyph for a line end in text. */
17799 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17802 if (glyph
< glyph_end
)
17803 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
17805 for (; glyph
< glyph_end
; ++glyph
)
17806 dump_glyph (row
, glyph
, area
);
17809 else if (glyphs
== 1)
17813 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17815 char *s
= (char *) alloca (row
->used
[area
] + 1);
17818 for (i
= 0; i
< row
->used
[area
]; ++i
)
17820 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17821 if (glyph
->type
== CHAR_GLYPH
17822 && glyph
->u
.ch
< 0x80
17823 && glyph
->u
.ch
>= ' ')
17824 s
[i
] = glyph
->u
.ch
;
17830 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17836 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17837 Sdump_glyph_matrix
, 0, 1, "p",
17838 doc
: /* Dump the current matrix of the selected window to stderr.
17839 Shows contents of glyph row structures. With non-nil
17840 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17841 glyphs in short form, otherwise show glyphs in long form. */)
17842 (Lisp_Object glyphs
)
17844 struct window
*w
= XWINDOW (selected_window
);
17845 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17847 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17848 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17849 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17850 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17851 fprintf (stderr
, "=============================================\n");
17852 dump_glyph_matrix (w
->current_matrix
,
17853 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17858 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17859 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17862 struct frame
*f
= XFRAME (selected_frame
);
17863 dump_glyph_matrix (f
->current_matrix
, 1);
17868 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17869 doc
: /* Dump glyph row ROW to stderr.
17870 GLYPH 0 means don't dump glyphs.
17871 GLYPH 1 means dump glyphs in short form.
17872 GLYPH > 1 or omitted means dump glyphs in long form. */)
17873 (Lisp_Object row
, Lisp_Object glyphs
)
17875 struct glyph_matrix
*matrix
;
17878 CHECK_NUMBER (row
);
17879 matrix
= XWINDOW (selected_window
)->current_matrix
;
17881 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17882 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17884 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17889 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17890 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17891 GLYPH 0 means don't dump glyphs.
17892 GLYPH 1 means dump glyphs in short form.
17893 GLYPH > 1 or omitted means dump glyphs in long form. */)
17894 (Lisp_Object row
, Lisp_Object glyphs
)
17896 struct frame
*sf
= SELECTED_FRAME ();
17897 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17900 CHECK_NUMBER (row
);
17902 if (vpos
>= 0 && vpos
< m
->nrows
)
17903 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17904 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17909 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17910 doc
: /* Toggle tracing of redisplay.
17911 With ARG, turn tracing on if and only if ARG is positive. */)
17915 trace_redisplay_p
= !trace_redisplay_p
;
17918 arg
= Fprefix_numeric_value (arg
);
17919 trace_redisplay_p
= XINT (arg
) > 0;
17926 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17927 doc
: /* Like `format', but print result to stderr.
17928 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17929 (ptrdiff_t nargs
, Lisp_Object
*args
)
17931 Lisp_Object s
= Fformat (nargs
, args
);
17932 fprintf (stderr
, "%s", SDATA (s
));
17936 #endif /* GLYPH_DEBUG */
17940 /***********************************************************************
17941 Building Desired Matrix Rows
17942 ***********************************************************************/
17944 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17945 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17947 static struct glyph_row
*
17948 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17950 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17951 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17952 struct buffer
*old
= current_buffer
;
17953 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17954 int arrow_len
= SCHARS (overlay_arrow_string
);
17955 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17956 const unsigned char *p
;
17959 int n_glyphs_before
;
17961 set_buffer_temp (buffer
);
17962 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17963 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17964 SET_TEXT_POS (it
.position
, 0, 0);
17966 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17968 while (p
< arrow_end
)
17970 Lisp_Object face
, ilisp
;
17972 /* Get the next character. */
17974 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17977 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17978 if (! ASCII_CHAR_P (it
.c
))
17979 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17983 /* Get its face. */
17984 ilisp
= make_number (p
- arrow_string
);
17985 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17986 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17988 /* Compute its width, get its glyphs. */
17989 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17990 SET_TEXT_POS (it
.position
, -1, -1);
17991 PRODUCE_GLYPHS (&it
);
17993 /* If this character doesn't fit any more in the line, we have
17994 to remove some glyphs. */
17995 if (it
.current_x
> it
.last_visible_x
)
17997 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18002 set_buffer_temp (old
);
18003 return it
.glyph_row
;
18007 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
18008 glyphs are only inserted for terminal frames since we can't really
18009 win with truncation glyphs when partially visible glyphs are
18010 involved. Which glyphs to insert is determined by
18011 produce_special_glyphs. */
18014 insert_left_trunc_glyphs (struct it
*it
)
18016 struct it truncate_it
;
18017 struct glyph
*from
, *end
, *to
, *toend
;
18019 xassert (!FRAME_WINDOW_P (it
->f
));
18021 /* Get the truncation glyphs. */
18023 truncate_it
.current_x
= 0;
18024 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18025 truncate_it
.glyph_row
= &scratch_glyph_row
;
18026 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18027 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18028 truncate_it
.object
= make_number (0);
18029 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18031 /* Overwrite glyphs from IT with truncation glyphs. */
18032 if (!it
->glyph_row
->reversed_p
)
18034 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18035 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
18036 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18037 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18042 /* There may be padding glyphs left over. Overwrite them too. */
18043 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18045 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18051 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18055 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18056 that back to front. */
18057 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18058 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18059 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18060 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18062 while (from
>= end
&& to
>= toend
)
18064 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18067 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18068 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18069 while (from
>= end
&& to
>= toend
)
18074 /* Need to free some room before prepending additional
18076 int move_by
= from
- end
+ 1;
18077 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18078 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18080 for ( ; g
>= g0
; g
--)
18082 while (from
>= end
)
18084 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18089 /* Compute the hash code for ROW. */
18091 row_hash (struct glyph_row
*row
)
18094 unsigned hashval
= 0;
18096 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18097 for (k
= 0; k
< row
->used
[area
]; ++k
)
18098 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18099 + row
->glyphs
[area
][k
].u
.val
18100 + row
->glyphs
[area
][k
].face_id
18101 + row
->glyphs
[area
][k
].padding_p
18102 + (row
->glyphs
[area
][k
].type
<< 2));
18107 /* Compute the pixel height and width of IT->glyph_row.
18109 Most of the time, ascent and height of a display line will be equal
18110 to the max_ascent and max_height values of the display iterator
18111 structure. This is not the case if
18113 1. We hit ZV without displaying anything. In this case, max_ascent
18114 and max_height will be zero.
18116 2. We have some glyphs that don't contribute to the line height.
18117 (The glyph row flag contributes_to_line_height_p is for future
18118 pixmap extensions).
18120 The first case is easily covered by using default values because in
18121 these cases, the line height does not really matter, except that it
18122 must not be zero. */
18125 compute_line_metrics (struct it
*it
)
18127 struct glyph_row
*row
= it
->glyph_row
;
18129 if (FRAME_WINDOW_P (it
->f
))
18131 int i
, min_y
, max_y
;
18133 /* The line may consist of one space only, that was added to
18134 place the cursor on it. If so, the row's height hasn't been
18136 if (row
->height
== 0)
18138 if (it
->max_ascent
+ it
->max_descent
== 0)
18139 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18140 row
->ascent
= it
->max_ascent
;
18141 row
->height
= it
->max_ascent
+ it
->max_descent
;
18142 row
->phys_ascent
= it
->max_phys_ascent
;
18143 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18144 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18147 /* Compute the width of this line. */
18148 row
->pixel_width
= row
->x
;
18149 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18150 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18152 xassert (row
->pixel_width
>= 0);
18153 xassert (row
->ascent
>= 0 && row
->height
> 0);
18155 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18156 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18158 /* If first line's physical ascent is larger than its logical
18159 ascent, use the physical ascent, and make the row taller.
18160 This makes accented characters fully visible. */
18161 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18162 && row
->phys_ascent
> row
->ascent
)
18164 row
->height
+= row
->phys_ascent
- row
->ascent
;
18165 row
->ascent
= row
->phys_ascent
;
18168 /* Compute how much of the line is visible. */
18169 row
->visible_height
= row
->height
;
18171 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18172 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18174 if (row
->y
< min_y
)
18175 row
->visible_height
-= min_y
- row
->y
;
18176 if (row
->y
+ row
->height
> max_y
)
18177 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18181 row
->pixel_width
= row
->used
[TEXT_AREA
];
18182 if (row
->continued_p
)
18183 row
->pixel_width
-= it
->continuation_pixel_width
;
18184 else if (row
->truncated_on_right_p
)
18185 row
->pixel_width
-= it
->truncation_pixel_width
;
18186 row
->ascent
= row
->phys_ascent
= 0;
18187 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18188 row
->extra_line_spacing
= 0;
18191 /* Compute a hash code for this row. */
18192 row
->hash
= row_hash (row
);
18194 it
->max_ascent
= it
->max_descent
= 0;
18195 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18199 /* Append one space to the glyph row of iterator IT if doing a
18200 window-based redisplay. The space has the same face as
18201 IT->face_id. Value is non-zero if a space was added.
18203 This function is called to make sure that there is always one glyph
18204 at the end of a glyph row that the cursor can be set on under
18205 window-systems. (If there weren't such a glyph we would not know
18206 how wide and tall a box cursor should be displayed).
18208 At the same time this space let's a nicely handle clearing to the
18209 end of the line if the row ends in italic text. */
18212 append_space_for_newline (struct it
*it
, int default_face_p
)
18214 if (FRAME_WINDOW_P (it
->f
))
18216 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18218 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18219 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18221 /* Save some values that must not be changed.
18222 Must save IT->c and IT->len because otherwise
18223 ITERATOR_AT_END_P wouldn't work anymore after
18224 append_space_for_newline has been called. */
18225 enum display_element_type saved_what
= it
->what
;
18226 int saved_c
= it
->c
, saved_len
= it
->len
;
18227 int saved_char_to_display
= it
->char_to_display
;
18228 int saved_x
= it
->current_x
;
18229 int saved_face_id
= it
->face_id
;
18230 struct text_pos saved_pos
;
18231 Lisp_Object saved_object
;
18234 saved_object
= it
->object
;
18235 saved_pos
= it
->position
;
18237 it
->what
= IT_CHARACTER
;
18238 memset (&it
->position
, 0, sizeof it
->position
);
18239 it
->object
= make_number (0);
18240 it
->c
= it
->char_to_display
= ' ';
18243 /* If the default face was remapped, be sure to use the
18244 remapped face for the appended newline. */
18245 if (default_face_p
)
18246 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18247 else if (it
->face_before_selective_p
)
18248 it
->face_id
= it
->saved_face_id
;
18249 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18250 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18252 PRODUCE_GLYPHS (it
);
18254 it
->override_ascent
= -1;
18255 it
->constrain_row_ascent_descent_p
= 0;
18256 it
->current_x
= saved_x
;
18257 it
->object
= saved_object
;
18258 it
->position
= saved_pos
;
18259 it
->what
= saved_what
;
18260 it
->face_id
= saved_face_id
;
18261 it
->len
= saved_len
;
18263 it
->char_to_display
= saved_char_to_display
;
18272 /* Extend the face of the last glyph in the text area of IT->glyph_row
18273 to the end of the display line. Called from display_line. If the
18274 glyph row is empty, add a space glyph to it so that we know the
18275 face to draw. Set the glyph row flag fill_line_p. If the glyph
18276 row is R2L, prepend a stretch glyph to cover the empty space to the
18277 left of the leftmost glyph. */
18280 extend_face_to_end_of_line (struct it
*it
)
18282 struct face
*face
, *default_face
;
18283 struct frame
*f
= it
->f
;
18285 /* If line is already filled, do nothing. Non window-system frames
18286 get a grace of one more ``pixel'' because their characters are
18287 1-``pixel'' wide, so they hit the equality too early. This grace
18288 is needed only for R2L rows that are not continued, to produce
18289 one extra blank where we could display the cursor. */
18290 if (it
->current_x
>= it
->last_visible_x
18291 + (!FRAME_WINDOW_P (f
)
18292 && it
->glyph_row
->reversed_p
18293 && !it
->glyph_row
->continued_p
))
18296 /* The default face, possibly remapped. */
18297 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18299 /* Face extension extends the background and box of IT->face_id
18300 to the end of the line. If the background equals the background
18301 of the frame, we don't have to do anything. */
18302 if (it
->face_before_selective_p
)
18303 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18305 face
= FACE_FROM_ID (f
, it
->face_id
);
18307 if (FRAME_WINDOW_P (f
)
18308 && it
->glyph_row
->displays_text_p
18309 && face
->box
== FACE_NO_BOX
18310 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18312 && !it
->glyph_row
->reversed_p
)
18315 /* Set the glyph row flag indicating that the face of the last glyph
18316 in the text area has to be drawn to the end of the text area. */
18317 it
->glyph_row
->fill_line_p
= 1;
18319 /* If current character of IT is not ASCII, make sure we have the
18320 ASCII face. This will be automatically undone the next time
18321 get_next_display_element returns a multibyte character. Note
18322 that the character will always be single byte in unibyte
18324 if (!ASCII_CHAR_P (it
->c
))
18326 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18329 if (FRAME_WINDOW_P (f
))
18331 /* If the row is empty, add a space with the current face of IT,
18332 so that we know which face to draw. */
18333 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18335 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18336 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18337 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18339 #ifdef HAVE_WINDOW_SYSTEM
18340 if (it
->glyph_row
->reversed_p
)
18342 /* Prepend a stretch glyph to the row, such that the
18343 rightmost glyph will be drawn flushed all the way to the
18344 right margin of the window. The stretch glyph that will
18345 occupy the empty space, if any, to the left of the
18347 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18348 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18349 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18351 int row_width
, stretch_ascent
, stretch_width
;
18352 struct text_pos saved_pos
;
18353 int saved_face_id
, saved_avoid_cursor
;
18355 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18356 row_width
+= g
->pixel_width
;
18357 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18358 if (stretch_width
> 0)
18361 (((it
->ascent
+ it
->descent
)
18362 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18363 saved_pos
= it
->position
;
18364 memset (&it
->position
, 0, sizeof it
->position
);
18365 saved_avoid_cursor
= it
->avoid_cursor_p
;
18366 it
->avoid_cursor_p
= 1;
18367 saved_face_id
= it
->face_id
;
18368 /* The last row's stretch glyph should get the default
18369 face, to avoid painting the rest of the window with
18370 the region face, if the region ends at ZV. */
18371 if (it
->glyph_row
->ends_at_zv_p
)
18372 it
->face_id
= default_face
->id
;
18374 it
->face_id
= face
->id
;
18375 append_stretch_glyph (it
, make_number (0), stretch_width
,
18376 it
->ascent
+ it
->descent
, stretch_ascent
);
18377 it
->position
= saved_pos
;
18378 it
->avoid_cursor_p
= saved_avoid_cursor
;
18379 it
->face_id
= saved_face_id
;
18382 #endif /* HAVE_WINDOW_SYSTEM */
18386 /* Save some values that must not be changed. */
18387 int saved_x
= it
->current_x
;
18388 struct text_pos saved_pos
;
18389 Lisp_Object saved_object
;
18390 enum display_element_type saved_what
= it
->what
;
18391 int saved_face_id
= it
->face_id
;
18393 saved_object
= it
->object
;
18394 saved_pos
= it
->position
;
18396 it
->what
= IT_CHARACTER
;
18397 memset (&it
->position
, 0, sizeof it
->position
);
18398 it
->object
= make_number (0);
18399 it
->c
= it
->char_to_display
= ' ';
18401 /* The last row's blank glyphs should get the default face, to
18402 avoid painting the rest of the window with the region face,
18403 if the region ends at ZV. */
18404 if (it
->glyph_row
->ends_at_zv_p
)
18405 it
->face_id
= default_face
->id
;
18407 it
->face_id
= face
->id
;
18409 PRODUCE_GLYPHS (it
);
18411 while (it
->current_x
<= it
->last_visible_x
)
18412 PRODUCE_GLYPHS (it
);
18414 /* Don't count these blanks really. It would let us insert a left
18415 truncation glyph below and make us set the cursor on them, maybe. */
18416 it
->current_x
= saved_x
;
18417 it
->object
= saved_object
;
18418 it
->position
= saved_pos
;
18419 it
->what
= saved_what
;
18420 it
->face_id
= saved_face_id
;
18425 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18426 trailing whitespace. */
18429 trailing_whitespace_p (ptrdiff_t charpos
)
18431 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18434 while (bytepos
< ZV_BYTE
18435 && (c
= FETCH_CHAR (bytepos
),
18436 c
== ' ' || c
== '\t'))
18439 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18441 if (bytepos
!= PT_BYTE
)
18448 /* Highlight trailing whitespace, if any, in ROW. */
18451 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18453 int used
= row
->used
[TEXT_AREA
];
18457 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18458 struct glyph
*glyph
= start
+ used
- 1;
18460 if (row
->reversed_p
)
18462 /* Right-to-left rows need to be processed in the opposite
18463 direction, so swap the edge pointers. */
18465 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18468 /* Skip over glyphs inserted to display the cursor at the
18469 end of a line, for extending the face of the last glyph
18470 to the end of the line on terminals, and for truncation
18471 and continuation glyphs. */
18472 if (!row
->reversed_p
)
18474 while (glyph
>= start
18475 && glyph
->type
== CHAR_GLYPH
18476 && INTEGERP (glyph
->object
))
18481 while (glyph
<= start
18482 && glyph
->type
== CHAR_GLYPH
18483 && INTEGERP (glyph
->object
))
18487 /* If last glyph is a space or stretch, and it's trailing
18488 whitespace, set the face of all trailing whitespace glyphs in
18489 IT->glyph_row to `trailing-whitespace'. */
18490 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18491 && BUFFERP (glyph
->object
)
18492 && (glyph
->type
== STRETCH_GLYPH
18493 || (glyph
->type
== CHAR_GLYPH
18494 && glyph
->u
.ch
== ' '))
18495 && trailing_whitespace_p (glyph
->charpos
))
18497 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18501 if (!row
->reversed_p
)
18503 while (glyph
>= start
18504 && BUFFERP (glyph
->object
)
18505 && (glyph
->type
== STRETCH_GLYPH
18506 || (glyph
->type
== CHAR_GLYPH
18507 && glyph
->u
.ch
== ' ')))
18508 (glyph
--)->face_id
= face_id
;
18512 while (glyph
<= start
18513 && BUFFERP (glyph
->object
)
18514 && (glyph
->type
== STRETCH_GLYPH
18515 || (glyph
->type
== CHAR_GLYPH
18516 && glyph
->u
.ch
== ' ')))
18517 (glyph
++)->face_id
= face_id
;
18524 /* Value is non-zero if glyph row ROW should be
18525 used to hold the cursor. */
18528 cursor_row_p (struct glyph_row
*row
)
18532 if (PT
== CHARPOS (row
->end
.pos
)
18533 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18535 /* Suppose the row ends on a string.
18536 Unless the row is continued, that means it ends on a newline
18537 in the string. If it's anything other than a display string
18538 (e.g., a before-string from an overlay), we don't want the
18539 cursor there. (This heuristic seems to give the optimal
18540 behavior for the various types of multi-line strings.)
18541 One exception: if the string has `cursor' property on one of
18542 its characters, we _do_ want the cursor there. */
18543 if (CHARPOS (row
->end
.string_pos
) >= 0)
18545 if (row
->continued_p
)
18549 /* Check for `display' property. */
18550 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18551 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18552 struct glyph
*glyph
;
18555 for (glyph
= end
; glyph
>= beg
; --glyph
)
18556 if (STRINGP (glyph
->object
))
18559 = Fget_char_property (make_number (PT
),
18563 && display_prop_string_p (prop
, glyph
->object
));
18564 /* If there's a `cursor' property on one of the
18565 string's characters, this row is a cursor row,
18566 even though this is not a display string. */
18569 Lisp_Object s
= glyph
->object
;
18571 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18573 ptrdiff_t gpos
= glyph
->charpos
;
18575 if (!NILP (Fget_char_property (make_number (gpos
),
18587 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18589 /* If the row ends in middle of a real character,
18590 and the line is continued, we want the cursor here.
18591 That's because CHARPOS (ROW->end.pos) would equal
18592 PT if PT is before the character. */
18593 if (!row
->ends_in_ellipsis_p
)
18594 result
= row
->continued_p
;
18596 /* If the row ends in an ellipsis, then
18597 CHARPOS (ROW->end.pos) will equal point after the
18598 invisible text. We want that position to be displayed
18599 after the ellipsis. */
18602 /* If the row ends at ZV, display the cursor at the end of that
18603 row instead of at the start of the row below. */
18604 else if (row
->ends_at_zv_p
)
18615 /* Push the property PROP so that it will be rendered at the current
18616 position in IT. Return 1 if PROP was successfully pushed, 0
18617 otherwise. Called from handle_line_prefix to handle the
18618 `line-prefix' and `wrap-prefix' properties. */
18621 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18623 struct text_pos pos
=
18624 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18626 xassert (it
->method
== GET_FROM_BUFFER
18627 || it
->method
== GET_FROM_DISPLAY_VECTOR
18628 || it
->method
== GET_FROM_STRING
);
18630 /* We need to save the current buffer/string position, so it will be
18631 restored by pop_it, because iterate_out_of_display_property
18632 depends on that being set correctly, but some situations leave
18633 it->position not yet set when this function is called. */
18634 push_it (it
, &pos
);
18636 if (STRINGP (prop
))
18638 if (SCHARS (prop
) == 0)
18645 it
->string_from_prefix_prop_p
= 1;
18646 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18647 it
->current
.overlay_string_index
= -1;
18648 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18649 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18650 it
->method
= GET_FROM_STRING
;
18651 it
->stop_charpos
= 0;
18653 it
->base_level_stop
= 0;
18655 /* Force paragraph direction to be that of the parent
18657 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18658 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18660 it
->paragraph_embedding
= L2R
;
18662 /* Set up the bidi iterator for this display string. */
18665 it
->bidi_it
.string
.lstring
= it
->string
;
18666 it
->bidi_it
.string
.s
= NULL
;
18667 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18668 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18669 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18670 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18671 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18674 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18676 it
->method
= GET_FROM_STRETCH
;
18679 #ifdef HAVE_WINDOW_SYSTEM
18680 else if (IMAGEP (prop
))
18682 it
->what
= IT_IMAGE
;
18683 it
->image_id
= lookup_image (it
->f
, prop
);
18684 it
->method
= GET_FROM_IMAGE
;
18686 #endif /* HAVE_WINDOW_SYSTEM */
18689 pop_it (it
); /* bogus display property, give up */
18696 /* Return the character-property PROP at the current position in IT. */
18699 get_it_property (struct it
*it
, Lisp_Object prop
)
18701 Lisp_Object position
;
18703 if (STRINGP (it
->object
))
18704 position
= make_number (IT_STRING_CHARPOS (*it
));
18705 else if (BUFFERP (it
->object
))
18706 position
= make_number (IT_CHARPOS (*it
));
18710 return Fget_char_property (position
, prop
, it
->object
);
18713 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18716 handle_line_prefix (struct it
*it
)
18718 Lisp_Object prefix
;
18720 if (it
->continuation_lines_width
> 0)
18722 prefix
= get_it_property (it
, Qwrap_prefix
);
18724 prefix
= Vwrap_prefix
;
18728 prefix
= get_it_property (it
, Qline_prefix
);
18730 prefix
= Vline_prefix
;
18732 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18734 /* If the prefix is wider than the window, and we try to wrap
18735 it, it would acquire its own wrap prefix, and so on till the
18736 iterator stack overflows. So, don't wrap the prefix. */
18737 it
->line_wrap
= TRUNCATE
;
18738 it
->avoid_cursor_p
= 1;
18744 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18745 only for R2L lines from display_line and display_string, when they
18746 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18747 the line/string needs to be continued on the next glyph row. */
18749 unproduce_glyphs (struct it
*it
, int n
)
18751 struct glyph
*glyph
, *end
;
18753 xassert (it
->glyph_row
);
18754 xassert (it
->glyph_row
->reversed_p
);
18755 xassert (it
->area
== TEXT_AREA
);
18756 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18758 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18759 n
= it
->glyph_row
->used
[TEXT_AREA
];
18760 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18761 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18762 for ( ; glyph
< end
; glyph
++)
18763 glyph
[-n
] = *glyph
;
18766 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18767 and ROW->maxpos. */
18769 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18770 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18771 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18773 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18774 lines' rows is implemented for bidi-reordered rows. */
18776 /* ROW->minpos is the value of min_pos, the minimal buffer position
18777 we have in ROW, or ROW->start.pos if that is smaller. */
18778 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18779 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18781 /* We didn't find buffer positions smaller than ROW->start, or
18782 didn't find _any_ valid buffer positions in any of the glyphs,
18783 so we must trust the iterator's computed positions. */
18784 row
->minpos
= row
->start
.pos
;
18787 max_pos
= CHARPOS (it
->current
.pos
);
18788 max_bpos
= BYTEPOS (it
->current
.pos
);
18791 /* Here are the various use-cases for ending the row, and the
18792 corresponding values for ROW->maxpos:
18794 Line ends in a newline from buffer eol_pos + 1
18795 Line is continued from buffer max_pos + 1
18796 Line is truncated on right it->current.pos
18797 Line ends in a newline from string max_pos + 1(*)
18798 (*) + 1 only when line ends in a forward scan
18799 Line is continued from string max_pos
18800 Line is continued from display vector max_pos
18801 Line is entirely from a string min_pos == max_pos
18802 Line is entirely from a display vector min_pos == max_pos
18803 Line that ends at ZV ZV
18805 If you discover other use-cases, please add them here as
18807 if (row
->ends_at_zv_p
)
18808 row
->maxpos
= it
->current
.pos
;
18809 else if (row
->used
[TEXT_AREA
])
18811 int seen_this_string
= 0;
18812 struct glyph_row
*r1
= row
- 1;
18814 /* Did we see the same display string on the previous row? */
18815 if (STRINGP (it
->object
)
18816 /* this is not the first row */
18817 && row
> it
->w
->desired_matrix
->rows
18818 /* previous row is not the header line */
18819 && !r1
->mode_line_p
18820 /* previous row also ends in a newline from a string */
18821 && r1
->ends_in_newline_from_string_p
)
18823 struct glyph
*start
, *end
;
18825 /* Search for the last glyph of the previous row that came
18826 from buffer or string. Depending on whether the row is
18827 L2R or R2L, we need to process it front to back or the
18828 other way round. */
18829 if (!r1
->reversed_p
)
18831 start
= r1
->glyphs
[TEXT_AREA
];
18832 end
= start
+ r1
->used
[TEXT_AREA
];
18833 /* Glyphs inserted by redisplay have an integer (zero)
18834 as their object. */
18836 && INTEGERP ((end
- 1)->object
)
18837 && (end
- 1)->charpos
<= 0)
18841 if (EQ ((end
- 1)->object
, it
->object
))
18842 seen_this_string
= 1;
18845 /* If all the glyphs of the previous row were inserted
18846 by redisplay, it means the previous row was
18847 produced from a single newline, which is only
18848 possible if that newline came from the same string
18849 as the one which produced this ROW. */
18850 seen_this_string
= 1;
18854 end
= r1
->glyphs
[TEXT_AREA
] - 1;
18855 start
= end
+ r1
->used
[TEXT_AREA
];
18857 && INTEGERP ((end
+ 1)->object
)
18858 && (end
+ 1)->charpos
<= 0)
18862 if (EQ ((end
+ 1)->object
, it
->object
))
18863 seen_this_string
= 1;
18866 seen_this_string
= 1;
18869 /* Take note of each display string that covers a newline only
18870 once, the first time we see it. This is for when a display
18871 string includes more than one newline in it. */
18872 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
18874 /* If we were scanning the buffer forward when we displayed
18875 the string, we want to account for at least one buffer
18876 position that belongs to this row (position covered by
18877 the display string), so that cursor positioning will
18878 consider this row as a candidate when point is at the end
18879 of the visual line represented by this row. This is not
18880 required when scanning back, because max_pos will already
18881 have a much larger value. */
18882 if (CHARPOS (row
->end
.pos
) > max_pos
)
18883 INC_BOTH (max_pos
, max_bpos
);
18884 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18886 else if (CHARPOS (it
->eol_pos
) > 0)
18887 SET_TEXT_POS (row
->maxpos
,
18888 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
18889 else if (row
->continued_p
)
18891 /* If max_pos is different from IT's current position, it
18892 means IT->method does not belong to the display element
18893 at max_pos. However, it also means that the display
18894 element at max_pos was displayed in its entirety on this
18895 line, which is equivalent to saying that the next line
18896 starts at the next buffer position. */
18897 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
18898 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18901 INC_BOTH (max_pos
, max_bpos
);
18902 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18905 else if (row
->truncated_on_right_p
)
18906 /* display_line already called reseat_at_next_visible_line_start,
18907 which puts the iterator at the beginning of the next line, in
18908 the logical order. */
18909 row
->maxpos
= it
->current
.pos
;
18910 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
18911 /* A line that is entirely from a string/image/stretch... */
18912 row
->maxpos
= row
->minpos
;
18917 row
->maxpos
= it
->current
.pos
;
18920 /* Construct the glyph row IT->glyph_row in the desired matrix of
18921 IT->w from text at the current position of IT. See dispextern.h
18922 for an overview of struct it. Value is non-zero if
18923 IT->glyph_row displays text, as opposed to a line displaying ZV
18927 display_line (struct it
*it
)
18929 struct glyph_row
*row
= it
->glyph_row
;
18930 Lisp_Object overlay_arrow_string
;
18932 void *wrap_data
= NULL
;
18933 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
18934 int wrap_row_used
= -1;
18935 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
18936 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
18937 int wrap_row_extra_line_spacing
IF_LINT (= 0);
18938 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
18939 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
18941 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
18942 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18944 /* We always start displaying at hpos zero even if hscrolled. */
18945 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18947 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18948 >= it
->w
->desired_matrix
->nrows
)
18950 it
->w
->nrows_scale_factor
++;
18951 fonts_changed_p
= 1;
18955 /* Is IT->w showing the region? */
18956 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18958 /* Clear the result glyph row and enable it. */
18959 prepare_desired_row (row
);
18961 row
->y
= it
->current_y
;
18962 row
->start
= it
->start
;
18963 row
->continuation_lines_width
= it
->continuation_lines_width
;
18964 row
->displays_text_p
= 1;
18965 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18966 it
->starts_in_middle_of_char_p
= 0;
18968 /* Arrange the overlays nicely for our purposes. Usually, we call
18969 display_line on only one line at a time, in which case this
18970 can't really hurt too much, or we call it on lines which appear
18971 one after another in the buffer, in which case all calls to
18972 recenter_overlay_lists but the first will be pretty cheap. */
18973 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18975 /* Move over display elements that are not visible because we are
18976 hscrolled. This may stop at an x-position < IT->first_visible_x
18977 if the first glyph is partially visible or if we hit a line end. */
18978 if (it
->current_x
< it
->first_visible_x
)
18980 this_line_min_pos
= row
->start
.pos
;
18981 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18982 MOVE_TO_POS
| MOVE_TO_X
);
18983 /* Record the smallest positions seen while we moved over
18984 display elements that are not visible. This is needed by
18985 redisplay_internal for optimizing the case where the cursor
18986 stays inside the same line. The rest of this function only
18987 considers positions that are actually displayed, so
18988 RECORD_MAX_MIN_POS will not otherwise record positions that
18989 are hscrolled to the left of the left edge of the window. */
18990 min_pos
= CHARPOS (this_line_min_pos
);
18991 min_bpos
= BYTEPOS (this_line_min_pos
);
18995 /* We only do this when not calling `move_it_in_display_line_to'
18996 above, because move_it_in_display_line_to calls
18997 handle_line_prefix itself. */
18998 handle_line_prefix (it
);
19001 /* Get the initial row height. This is either the height of the
19002 text hscrolled, if there is any, or zero. */
19003 row
->ascent
= it
->max_ascent
;
19004 row
->height
= it
->max_ascent
+ it
->max_descent
;
19005 row
->phys_ascent
= it
->max_phys_ascent
;
19006 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19007 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19009 /* Utility macro to record max and min buffer positions seen until now. */
19010 #define RECORD_MAX_MIN_POS(IT) \
19013 int composition_p = !STRINGP ((IT)->string) \
19014 && ((IT)->what == IT_COMPOSITION); \
19015 ptrdiff_t current_pos = \
19016 composition_p ? (IT)->cmp_it.charpos \
19017 : IT_CHARPOS (*(IT)); \
19018 ptrdiff_t current_bpos = \
19019 composition_p ? CHAR_TO_BYTE (current_pos) \
19020 : IT_BYTEPOS (*(IT)); \
19021 if (current_pos < min_pos) \
19023 min_pos = current_pos; \
19024 min_bpos = current_bpos; \
19026 if (IT_CHARPOS (*it) > max_pos) \
19028 max_pos = IT_CHARPOS (*it); \
19029 max_bpos = IT_BYTEPOS (*it); \
19034 /* Loop generating characters. The loop is left with IT on the next
19035 character to display. */
19038 int n_glyphs_before
, hpos_before
, x_before
;
19040 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19042 /* Retrieve the next thing to display. Value is zero if end of
19044 if (!get_next_display_element (it
))
19046 /* Maybe add a space at the end of this line that is used to
19047 display the cursor there under X. Set the charpos of the
19048 first glyph of blank lines not corresponding to any text
19050 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19051 row
->exact_window_width_line_p
= 1;
19052 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19053 || row
->used
[TEXT_AREA
] == 0)
19055 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19056 row
->displays_text_p
= 0;
19058 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19059 && (!MINI_WINDOW_P (it
->w
)
19060 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19061 row
->indicate_empty_line_p
= 1;
19064 it
->continuation_lines_width
= 0;
19065 row
->ends_at_zv_p
= 1;
19066 /* A row that displays right-to-left text must always have
19067 its last face extended all the way to the end of line,
19068 even if this row ends in ZV, because we still write to
19069 the screen left to right. We also need to extend the
19070 last face if the default face is remapped to some
19071 different face, otherwise the functions that clear
19072 portions of the screen will clear with the default face's
19073 background color. */
19074 if (row
->reversed_p
19075 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19076 extend_face_to_end_of_line (it
);
19080 /* Now, get the metrics of what we want to display. This also
19081 generates glyphs in `row' (which is IT->glyph_row). */
19082 n_glyphs_before
= row
->used
[TEXT_AREA
];
19085 /* Remember the line height so far in case the next element doesn't
19086 fit on the line. */
19087 if (it
->line_wrap
!= TRUNCATE
)
19089 ascent
= it
->max_ascent
;
19090 descent
= it
->max_descent
;
19091 phys_ascent
= it
->max_phys_ascent
;
19092 phys_descent
= it
->max_phys_descent
;
19094 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19096 if (IT_DISPLAYING_WHITESPACE (it
))
19100 SAVE_IT (wrap_it
, *it
, wrap_data
);
19102 wrap_row_used
= row
->used
[TEXT_AREA
];
19103 wrap_row_ascent
= row
->ascent
;
19104 wrap_row_height
= row
->height
;
19105 wrap_row_phys_ascent
= row
->phys_ascent
;
19106 wrap_row_phys_height
= row
->phys_height
;
19107 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19108 wrap_row_min_pos
= min_pos
;
19109 wrap_row_min_bpos
= min_bpos
;
19110 wrap_row_max_pos
= max_pos
;
19111 wrap_row_max_bpos
= max_bpos
;
19117 PRODUCE_GLYPHS (it
);
19119 /* If this display element was in marginal areas, continue with
19121 if (it
->area
!= TEXT_AREA
)
19123 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19124 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19125 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19126 row
->phys_height
= max (row
->phys_height
,
19127 it
->max_phys_ascent
+ it
->max_phys_descent
);
19128 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19129 it
->max_extra_line_spacing
);
19130 set_iterator_to_next (it
, 1);
19134 /* Does the display element fit on the line? If we truncate
19135 lines, we should draw past the right edge of the window. If
19136 we don't truncate, we want to stop so that we can display the
19137 continuation glyph before the right margin. If lines are
19138 continued, there are two possible strategies for characters
19139 resulting in more than 1 glyph (e.g. tabs): Display as many
19140 glyphs as possible in this line and leave the rest for the
19141 continuation line, or display the whole element in the next
19142 line. Original redisplay did the former, so we do it also. */
19143 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19144 hpos_before
= it
->hpos
;
19147 if (/* Not a newline. */
19149 /* Glyphs produced fit entirely in the line. */
19150 && it
->current_x
< it
->last_visible_x
)
19152 it
->hpos
+= nglyphs
;
19153 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19154 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19155 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19156 row
->phys_height
= max (row
->phys_height
,
19157 it
->max_phys_ascent
+ it
->max_phys_descent
);
19158 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19159 it
->max_extra_line_spacing
);
19160 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19161 row
->x
= x
- it
->first_visible_x
;
19162 /* Record the maximum and minimum buffer positions seen so
19163 far in glyphs that will be displayed by this row. */
19165 RECORD_MAX_MIN_POS (it
);
19170 struct glyph
*glyph
;
19172 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19174 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19175 new_x
= x
+ glyph
->pixel_width
;
19177 if (/* Lines are continued. */
19178 it
->line_wrap
!= TRUNCATE
19179 && (/* Glyph doesn't fit on the line. */
19180 new_x
> it
->last_visible_x
19181 /* Or it fits exactly on a window system frame. */
19182 || (new_x
== it
->last_visible_x
19183 && FRAME_WINDOW_P (it
->f
))))
19185 /* End of a continued line. */
19188 || (new_x
== it
->last_visible_x
19189 && FRAME_WINDOW_P (it
->f
)))
19191 /* Current glyph is the only one on the line or
19192 fits exactly on the line. We must continue
19193 the line because we can't draw the cursor
19194 after the glyph. */
19195 row
->continued_p
= 1;
19196 it
->current_x
= new_x
;
19197 it
->continuation_lines_width
+= new_x
;
19199 if (i
== nglyphs
- 1)
19201 /* If line-wrap is on, check if a previous
19202 wrap point was found. */
19203 if (wrap_row_used
> 0
19204 /* Even if there is a previous wrap
19205 point, continue the line here as
19206 usual, if (i) the previous character
19207 was a space or tab AND (ii) the
19208 current character is not. */
19210 || IT_DISPLAYING_WHITESPACE (it
)))
19213 /* Record the maximum and minimum buffer
19214 positions seen so far in glyphs that will be
19215 displayed by this row. */
19217 RECORD_MAX_MIN_POS (it
);
19218 set_iterator_to_next (it
, 1);
19219 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19221 if (!get_next_display_element (it
))
19223 row
->exact_window_width_line_p
= 1;
19224 it
->continuation_lines_width
= 0;
19225 row
->continued_p
= 0;
19226 row
->ends_at_zv_p
= 1;
19228 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19230 row
->continued_p
= 0;
19231 row
->exact_window_width_line_p
= 1;
19235 else if (it
->bidi_p
)
19236 RECORD_MAX_MIN_POS (it
);
19238 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19239 && !FRAME_WINDOW_P (it
->f
))
19241 /* A padding glyph that doesn't fit on this line.
19242 This means the whole character doesn't fit
19244 if (row
->reversed_p
)
19245 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19246 - n_glyphs_before
);
19247 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19249 /* Fill the rest of the row with continuation
19250 glyphs like in 20.x. */
19251 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19252 < row
->glyphs
[1 + TEXT_AREA
])
19253 produce_special_glyphs (it
, IT_CONTINUATION
);
19255 row
->continued_p
= 1;
19256 it
->current_x
= x_before
;
19257 it
->continuation_lines_width
+= x_before
;
19259 /* Restore the height to what it was before the
19260 element not fitting on the line. */
19261 it
->max_ascent
= ascent
;
19262 it
->max_descent
= descent
;
19263 it
->max_phys_ascent
= phys_ascent
;
19264 it
->max_phys_descent
= phys_descent
;
19266 else if (wrap_row_used
> 0)
19269 if (row
->reversed_p
)
19270 unproduce_glyphs (it
,
19271 row
->used
[TEXT_AREA
] - wrap_row_used
);
19272 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19273 it
->continuation_lines_width
+= wrap_x
;
19274 row
->used
[TEXT_AREA
] = wrap_row_used
;
19275 row
->ascent
= wrap_row_ascent
;
19276 row
->height
= wrap_row_height
;
19277 row
->phys_ascent
= wrap_row_phys_ascent
;
19278 row
->phys_height
= wrap_row_phys_height
;
19279 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19280 min_pos
= wrap_row_min_pos
;
19281 min_bpos
= wrap_row_min_bpos
;
19282 max_pos
= wrap_row_max_pos
;
19283 max_bpos
= wrap_row_max_bpos
;
19284 row
->continued_p
= 1;
19285 row
->ends_at_zv_p
= 0;
19286 row
->exact_window_width_line_p
= 0;
19287 it
->continuation_lines_width
+= x
;
19289 /* Make sure that a non-default face is extended
19290 up to the right margin of the window. */
19291 extend_face_to_end_of_line (it
);
19293 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19295 /* A TAB that extends past the right edge of the
19296 window. This produces a single glyph on
19297 window system frames. We leave the glyph in
19298 this row and let it fill the row, but don't
19299 consume the TAB. */
19300 it
->continuation_lines_width
+= it
->last_visible_x
;
19301 row
->ends_in_middle_of_char_p
= 1;
19302 row
->continued_p
= 1;
19303 glyph
->pixel_width
= it
->last_visible_x
- x
;
19304 it
->starts_in_middle_of_char_p
= 1;
19308 /* Something other than a TAB that draws past
19309 the right edge of the window. Restore
19310 positions to values before the element. */
19311 if (row
->reversed_p
)
19312 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19313 - (n_glyphs_before
+ i
));
19314 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19316 /* Display continuation glyphs. */
19317 if (!FRAME_WINDOW_P (it
->f
))
19318 produce_special_glyphs (it
, IT_CONTINUATION
);
19319 row
->continued_p
= 1;
19321 it
->current_x
= x_before
;
19322 it
->continuation_lines_width
+= x
;
19323 extend_face_to_end_of_line (it
);
19325 if (nglyphs
> 1 && i
> 0)
19327 row
->ends_in_middle_of_char_p
= 1;
19328 it
->starts_in_middle_of_char_p
= 1;
19331 /* Restore the height to what it was before the
19332 element not fitting on the line. */
19333 it
->max_ascent
= ascent
;
19334 it
->max_descent
= descent
;
19335 it
->max_phys_ascent
= phys_ascent
;
19336 it
->max_phys_descent
= phys_descent
;
19341 else if (new_x
> it
->first_visible_x
)
19343 /* Increment number of glyphs actually displayed. */
19346 /* Record the maximum and minimum buffer positions
19347 seen so far in glyphs that will be displayed by
19350 RECORD_MAX_MIN_POS (it
);
19352 if (x
< it
->first_visible_x
)
19353 /* Glyph is partially visible, i.e. row starts at
19354 negative X position. */
19355 row
->x
= x
- it
->first_visible_x
;
19359 /* Glyph is completely off the left margin of the
19360 window. This should not happen because of the
19361 move_it_in_display_line at the start of this
19362 function, unless the text display area of the
19363 window is empty. */
19364 xassert (it
->first_visible_x
<= it
->last_visible_x
);
19367 /* Even if this display element produced no glyphs at all,
19368 we want to record its position. */
19369 if (it
->bidi_p
&& nglyphs
== 0)
19370 RECORD_MAX_MIN_POS (it
);
19372 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19373 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19374 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19375 row
->phys_height
= max (row
->phys_height
,
19376 it
->max_phys_ascent
+ it
->max_phys_descent
);
19377 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19378 it
->max_extra_line_spacing
);
19380 /* End of this display line if row is continued. */
19381 if (row
->continued_p
|| row
->ends_at_zv_p
)
19386 /* Is this a line end? If yes, we're also done, after making
19387 sure that a non-default face is extended up to the right
19388 margin of the window. */
19389 if (ITERATOR_AT_END_OF_LINE_P (it
))
19391 int used_before
= row
->used
[TEXT_AREA
];
19393 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19395 /* Add a space at the end of the line that is used to
19396 display the cursor there. */
19397 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19398 append_space_for_newline (it
, 0);
19400 /* Extend the face to the end of the line. */
19401 extend_face_to_end_of_line (it
);
19403 /* Make sure we have the position. */
19404 if (used_before
== 0)
19405 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19407 /* Record the position of the newline, for use in
19409 it
->eol_pos
= it
->current
.pos
;
19411 /* Consume the line end. This skips over invisible lines. */
19412 set_iterator_to_next (it
, 1);
19413 it
->continuation_lines_width
= 0;
19417 /* Proceed with next display element. Note that this skips
19418 over lines invisible because of selective display. */
19419 set_iterator_to_next (it
, 1);
19421 /* If we truncate lines, we are done when the last displayed
19422 glyphs reach past the right margin of the window. */
19423 if (it
->line_wrap
== TRUNCATE
19424 && (FRAME_WINDOW_P (it
->f
)
19425 ? (it
->current_x
>= it
->last_visible_x
)
19426 : (it
->current_x
> it
->last_visible_x
)))
19428 /* Maybe add truncation glyphs. */
19429 if (!FRAME_WINDOW_P (it
->f
))
19433 if (!row
->reversed_p
)
19435 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19436 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19441 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19442 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19444 /* Remove any padding glyphs at the front of ROW, to
19445 make room for the truncation glyphs we will be
19446 adding below. The loop below always inserts at
19447 least one truncation glyph, so also remove the
19448 last glyph added to ROW. */
19449 unproduce_glyphs (it
, i
+ 1);
19450 /* Adjust i for the loop below. */
19451 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19454 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19456 row
->used
[TEXT_AREA
] = i
;
19457 produce_special_glyphs (it
, IT_TRUNCATION
);
19460 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19462 /* Don't truncate if we can overflow newline into fringe. */
19463 if (!get_next_display_element (it
))
19465 it
->continuation_lines_width
= 0;
19466 row
->ends_at_zv_p
= 1;
19467 row
->exact_window_width_line_p
= 1;
19470 if (ITERATOR_AT_END_OF_LINE_P (it
))
19472 row
->exact_window_width_line_p
= 1;
19473 goto at_end_of_line
;
19477 row
->truncated_on_right_p
= 1;
19478 it
->continuation_lines_width
= 0;
19479 reseat_at_next_visible_line_start (it
, 0);
19480 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19481 it
->hpos
= hpos_before
;
19482 it
->current_x
= x_before
;
19488 bidi_unshelve_cache (wrap_data
, 1);
19490 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19491 at the left window margin. */
19492 if (it
->first_visible_x
19493 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19495 if (!FRAME_WINDOW_P (it
->f
))
19496 insert_left_trunc_glyphs (it
);
19497 row
->truncated_on_left_p
= 1;
19500 /* Remember the position at which this line ends.
19502 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19503 cannot be before the call to find_row_edges below, since that is
19504 where these positions are determined. */
19505 row
->end
= it
->current
;
19508 row
->minpos
= row
->start
.pos
;
19509 row
->maxpos
= row
->end
.pos
;
19513 /* ROW->minpos and ROW->maxpos must be the smallest and
19514 `1 + the largest' buffer positions in ROW. But if ROW was
19515 bidi-reordered, these two positions can be anywhere in the
19516 row, so we must determine them now. */
19517 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19520 /* If the start of this line is the overlay arrow-position, then
19521 mark this glyph row as the one containing the overlay arrow.
19522 This is clearly a mess with variable size fonts. It would be
19523 better to let it be displayed like cursors under X. */
19524 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19525 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19526 !NILP (overlay_arrow_string
)))
19528 /* Overlay arrow in window redisplay is a fringe bitmap. */
19529 if (STRINGP (overlay_arrow_string
))
19531 struct glyph_row
*arrow_row
19532 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19533 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19534 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19535 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19536 struct glyph
*p2
, *end
;
19538 /* Copy the arrow glyphs. */
19539 while (glyph
< arrow_end
)
19542 /* Throw away padding glyphs. */
19544 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19545 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19551 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19556 xassert (INTEGERP (overlay_arrow_string
));
19557 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19559 overlay_arrow_seen
= 1;
19562 /* Highlight trailing whitespace. */
19563 if (!NILP (Vshow_trailing_whitespace
))
19564 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19566 /* Compute pixel dimensions of this line. */
19567 compute_line_metrics (it
);
19569 /* Implementation note: No changes in the glyphs of ROW or in their
19570 faces can be done past this point, because compute_line_metrics
19571 computes ROW's hash value and stores it within the glyph_row
19574 /* Record whether this row ends inside an ellipsis. */
19575 row
->ends_in_ellipsis_p
19576 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19577 && it
->ellipsis_p
);
19579 /* Save fringe bitmaps in this row. */
19580 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19581 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19582 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19583 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19585 it
->left_user_fringe_bitmap
= 0;
19586 it
->left_user_fringe_face_id
= 0;
19587 it
->right_user_fringe_bitmap
= 0;
19588 it
->right_user_fringe_face_id
= 0;
19590 /* Maybe set the cursor. */
19591 cvpos
= it
->w
->cursor
.vpos
;
19593 /* In bidi-reordered rows, keep checking for proper cursor
19594 position even if one has been found already, because buffer
19595 positions in such rows change non-linearly with ROW->VPOS,
19596 when a line is continued. One exception: when we are at ZV,
19597 display cursor on the first suitable glyph row, since all
19598 the empty rows after that also have their position set to ZV. */
19599 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19600 lines' rows is implemented for bidi-reordered rows. */
19602 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19603 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19604 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19605 && cursor_row_p (row
))
19606 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19608 /* Prepare for the next line. This line starts horizontally at (X
19609 HPOS) = (0 0). Vertical positions are incremented. As a
19610 convenience for the caller, IT->glyph_row is set to the next
19612 it
->current_x
= it
->hpos
= 0;
19613 it
->current_y
+= row
->height
;
19614 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19617 /* The next row should by default use the same value of the
19618 reversed_p flag as this one. set_iterator_to_next decides when
19619 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19620 the flag accordingly. */
19621 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19622 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19623 it
->start
= row
->end
;
19624 return row
->displays_text_p
;
19626 #undef RECORD_MAX_MIN_POS
19629 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19630 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19631 doc
: /* Return paragraph direction at point in BUFFER.
19632 Value is either `left-to-right' or `right-to-left'.
19633 If BUFFER is omitted or nil, it defaults to the current buffer.
19635 Paragraph direction determines how the text in the paragraph is displayed.
19636 In left-to-right paragraphs, text begins at the left margin of the window
19637 and the reading direction is generally left to right. In right-to-left
19638 paragraphs, text begins at the right margin and is read from right to left.
19640 See also `bidi-paragraph-direction'. */)
19641 (Lisp_Object buffer
)
19643 struct buffer
*buf
= current_buffer
;
19644 struct buffer
*old
= buf
;
19646 if (! NILP (buffer
))
19648 CHECK_BUFFER (buffer
);
19649 buf
= XBUFFER (buffer
);
19652 if (NILP (BVAR (buf
, bidi_display_reordering
))
19653 || NILP (BVAR (buf
, enable_multibyte_characters
))
19654 /* When we are loading loadup.el, the character property tables
19655 needed for bidi iteration are not yet available. */
19656 || !NILP (Vpurify_flag
))
19657 return Qleft_to_right
;
19658 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19659 return BVAR (buf
, bidi_paragraph_direction
);
19662 /* Determine the direction from buffer text. We could try to
19663 use current_matrix if it is up to date, but this seems fast
19664 enough as it is. */
19665 struct bidi_it itb
;
19666 ptrdiff_t pos
= BUF_PT (buf
);
19667 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19669 void *itb_data
= bidi_shelve_cache ();
19671 set_buffer_temp (buf
);
19672 /* bidi_paragraph_init finds the base direction of the paragraph
19673 by searching forward from paragraph start. We need the base
19674 direction of the current or _previous_ paragraph, so we need
19675 to make sure we are within that paragraph. To that end, find
19676 the previous non-empty line. */
19677 if (pos
>= ZV
&& pos
> BEGV
)
19680 bytepos
= CHAR_TO_BYTE (pos
);
19682 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19683 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19685 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19686 || c
== ' ' || c
== '\t' || c
== '\f')
19688 if (bytepos
<= BEGV_BYTE
)
19693 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19696 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19697 itb
.paragraph_dir
= NEUTRAL_DIR
;
19698 itb
.string
.s
= NULL
;
19699 itb
.string
.lstring
= Qnil
;
19700 itb
.string
.bufpos
= 0;
19701 itb
.string
.unibyte
= 0;
19702 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19703 bidi_unshelve_cache (itb_data
, 0);
19704 set_buffer_temp (old
);
19705 switch (itb
.paragraph_dir
)
19708 return Qleft_to_right
;
19711 return Qright_to_left
;
19721 /***********************************************************************
19723 ***********************************************************************/
19725 /* Redisplay the menu bar in the frame for window W.
19727 The menu bar of X frames that don't have X toolkit support is
19728 displayed in a special window W->frame->menu_bar_window.
19730 The menu bar of terminal frames is treated specially as far as
19731 glyph matrices are concerned. Menu bar lines are not part of
19732 windows, so the update is done directly on the frame matrix rows
19733 for the menu bar. */
19736 display_menu_bar (struct window
*w
)
19738 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19743 /* Don't do all this for graphical frames. */
19745 if (FRAME_W32_P (f
))
19748 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19754 if (FRAME_NS_P (f
))
19756 #endif /* HAVE_NS */
19758 #ifdef USE_X_TOOLKIT
19759 xassert (!FRAME_WINDOW_P (f
));
19760 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19761 it
.first_visible_x
= 0;
19762 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19763 #else /* not USE_X_TOOLKIT */
19764 if (FRAME_WINDOW_P (f
))
19766 /* Menu bar lines are displayed in the desired matrix of the
19767 dummy window menu_bar_window. */
19768 struct window
*menu_w
;
19769 xassert (WINDOWP (f
->menu_bar_window
));
19770 menu_w
= XWINDOW (f
->menu_bar_window
);
19771 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19773 it
.first_visible_x
= 0;
19774 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19778 /* This is a TTY frame, i.e. character hpos/vpos are used as
19780 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19782 it
.first_visible_x
= 0;
19783 it
.last_visible_x
= FRAME_COLS (f
);
19785 #endif /* not USE_X_TOOLKIT */
19787 /* FIXME: This should be controlled by a user option. See the
19788 comments in redisplay_tool_bar and display_mode_line about
19790 it
.paragraph_embedding
= L2R
;
19792 if (! mode_line_inverse_video
)
19793 /* Force the menu-bar to be displayed in the default face. */
19794 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19796 /* Clear all rows of the menu bar. */
19797 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
19799 struct glyph_row
*row
= it
.glyph_row
+ i
;
19800 clear_glyph_row (row
);
19801 row
->enabled_p
= 1;
19802 row
->full_width_p
= 1;
19805 /* Display all items of the menu bar. */
19806 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
19807 for (i
= 0; i
< ASIZE (items
); i
+= 4)
19809 Lisp_Object string
;
19811 /* Stop at nil string. */
19812 string
= AREF (items
, i
+ 1);
19816 /* Remember where item was displayed. */
19817 ASET (items
, i
+ 3, make_number (it
.hpos
));
19819 /* Display the item, pad with one space. */
19820 if (it
.current_x
< it
.last_visible_x
)
19821 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
19822 SCHARS (string
) + 1, 0, 0, -1);
19825 /* Fill out the line with spaces. */
19826 if (it
.current_x
< it
.last_visible_x
)
19827 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
19829 /* Compute the total height of the lines. */
19830 compute_line_metrics (&it
);
19835 /***********************************************************************
19837 ***********************************************************************/
19839 /* Redisplay mode lines in the window tree whose root is WINDOW. If
19840 FORCE is non-zero, redisplay mode lines unconditionally.
19841 Otherwise, redisplay only mode lines that are garbaged. Value is
19842 the number of windows whose mode lines were redisplayed. */
19845 redisplay_mode_lines (Lisp_Object window
, int force
)
19849 while (!NILP (window
))
19851 struct window
*w
= XWINDOW (window
);
19853 if (WINDOWP (w
->hchild
))
19854 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
19855 else if (WINDOWP (w
->vchild
))
19856 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
19858 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
19859 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
19861 struct text_pos lpoint
;
19862 struct buffer
*old
= current_buffer
;
19864 /* Set the window's buffer for the mode line display. */
19865 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
19866 set_buffer_internal_1 (XBUFFER (w
->buffer
));
19868 /* Point refers normally to the selected window. For any
19869 other window, set up appropriate value. */
19870 if (!EQ (window
, selected_window
))
19872 struct text_pos pt
;
19874 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
19875 if (CHARPOS (pt
) < BEGV
)
19876 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
19877 else if (CHARPOS (pt
) > (ZV
- 1))
19878 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
19880 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
19883 /* Display mode lines. */
19884 clear_glyph_matrix (w
->desired_matrix
);
19885 if (display_mode_lines (w
))
19888 w
->must_be_updated_p
= 1;
19891 /* Restore old settings. */
19892 set_buffer_internal_1 (old
);
19893 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
19903 /* Display the mode and/or header line of window W. Value is the
19904 sum number of mode lines and header lines displayed. */
19907 display_mode_lines (struct window
*w
)
19909 Lisp_Object old_selected_window
, old_selected_frame
;
19912 old_selected_frame
= selected_frame
;
19913 selected_frame
= w
->frame
;
19914 old_selected_window
= selected_window
;
19915 XSETWINDOW (selected_window
, w
);
19917 /* These will be set while the mode line specs are processed. */
19918 line_number_displayed
= 0;
19919 w
->column_number_displayed
= Qnil
;
19921 if (WINDOW_WANTS_MODELINE_P (w
))
19923 struct window
*sel_w
= XWINDOW (old_selected_window
);
19925 /* Select mode line face based on the real selected window. */
19926 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
19927 BVAR (current_buffer
, mode_line_format
));
19931 if (WINDOW_WANTS_HEADER_LINE_P (w
))
19933 display_mode_line (w
, HEADER_LINE_FACE_ID
,
19934 BVAR (current_buffer
, header_line_format
));
19938 selected_frame
= old_selected_frame
;
19939 selected_window
= old_selected_window
;
19944 /* Display mode or header line of window W. FACE_ID specifies which
19945 line to display; it is either MODE_LINE_FACE_ID or
19946 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
19947 display. Value is the pixel height of the mode/header line
19951 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
19955 ptrdiff_t count
= SPECPDL_INDEX ();
19957 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19958 /* Don't extend on a previously drawn mode-line.
19959 This may happen if called from pos_visible_p. */
19960 it
.glyph_row
->enabled_p
= 0;
19961 prepare_desired_row (it
.glyph_row
);
19963 it
.glyph_row
->mode_line_p
= 1;
19965 if (! mode_line_inverse_video
)
19966 /* Force the mode-line to be displayed in the default face. */
19967 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19969 /* FIXME: This should be controlled by a user option. But
19970 supporting such an option is not trivial, since the mode line is
19971 made up of many separate strings. */
19972 it
.paragraph_embedding
= L2R
;
19974 record_unwind_protect (unwind_format_mode_line
,
19975 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19977 mode_line_target
= MODE_LINE_DISPLAY
;
19979 /* Temporarily make frame's keyboard the current kboard so that
19980 kboard-local variables in the mode_line_format will get the right
19982 push_kboard (FRAME_KBOARD (it
.f
));
19983 record_unwind_save_match_data ();
19984 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19987 unbind_to (count
, Qnil
);
19989 /* Fill up with spaces. */
19990 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
19992 compute_line_metrics (&it
);
19993 it
.glyph_row
->full_width_p
= 1;
19994 it
.glyph_row
->continued_p
= 0;
19995 it
.glyph_row
->truncated_on_left_p
= 0;
19996 it
.glyph_row
->truncated_on_right_p
= 0;
19998 /* Make a 3D mode-line have a shadow at its right end. */
19999 face
= FACE_FROM_ID (it
.f
, face_id
);
20000 extend_face_to_end_of_line (&it
);
20001 if (face
->box
!= FACE_NO_BOX
)
20003 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20004 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20005 last
->right_box_line_p
= 1;
20008 return it
.glyph_row
->height
;
20011 /* Move element ELT in LIST to the front of LIST.
20012 Return the updated list. */
20015 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20017 register Lisp_Object tail
, prev
;
20018 register Lisp_Object tem
;
20022 while (CONSP (tail
))
20028 /* Splice out the link TAIL. */
20030 list
= XCDR (tail
);
20032 Fsetcdr (prev
, XCDR (tail
));
20034 /* Now make it the first. */
20035 Fsetcdr (tail
, list
);
20040 tail
= XCDR (tail
);
20044 /* Not found--return unchanged LIST. */
20048 /* Contribute ELT to the mode line for window IT->w. How it
20049 translates into text depends on its data type.
20051 IT describes the display environment in which we display, as usual.
20053 DEPTH is the depth in recursion. It is used to prevent
20054 infinite recursion here.
20056 FIELD_WIDTH is the number of characters the display of ELT should
20057 occupy in the mode line, and PRECISION is the maximum number of
20058 characters to display from ELT's representation. See
20059 display_string for details.
20061 Returns the hpos of the end of the text generated by ELT.
20063 PROPS is a property list to add to any string we encounter.
20065 If RISKY is nonzero, remove (disregard) any properties in any string
20066 we encounter, and ignore :eval and :propertize.
20068 The global variable `mode_line_target' determines whether the
20069 output is passed to `store_mode_line_noprop',
20070 `store_mode_line_string', or `display_string'. */
20073 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20074 Lisp_Object elt
, Lisp_Object props
, int risky
)
20076 int n
= 0, field
, prec
;
20081 elt
= build_string ("*too-deep*");
20085 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
20089 /* A string: output it and check for %-constructs within it. */
20091 ptrdiff_t offset
= 0;
20093 if (SCHARS (elt
) > 0
20094 && (!NILP (props
) || risky
))
20096 Lisp_Object oprops
, aelt
;
20097 oprops
= Ftext_properties_at (make_number (0), elt
);
20099 /* If the starting string's properties are not what
20100 we want, translate the string. Also, if the string
20101 is risky, do that anyway. */
20103 if (NILP (Fequal (props
, oprops
)) || risky
)
20105 /* If the starting string has properties,
20106 merge the specified ones onto the existing ones. */
20107 if (! NILP (oprops
) && !risky
)
20111 oprops
= Fcopy_sequence (oprops
);
20113 while (CONSP (tem
))
20115 oprops
= Fplist_put (oprops
, XCAR (tem
),
20116 XCAR (XCDR (tem
)));
20117 tem
= XCDR (XCDR (tem
));
20122 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20123 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20125 /* AELT is what we want. Move it to the front
20126 without consing. */
20128 mode_line_proptrans_alist
20129 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20135 /* If AELT has the wrong props, it is useless.
20136 so get rid of it. */
20138 mode_line_proptrans_alist
20139 = Fdelq (aelt
, mode_line_proptrans_alist
);
20141 elt
= Fcopy_sequence (elt
);
20142 Fset_text_properties (make_number (0), Flength (elt
),
20144 /* Add this item to mode_line_proptrans_alist. */
20145 mode_line_proptrans_alist
20146 = Fcons (Fcons (elt
, props
),
20147 mode_line_proptrans_alist
);
20148 /* Truncate mode_line_proptrans_alist
20149 to at most 50 elements. */
20150 tem
= Fnthcdr (make_number (50),
20151 mode_line_proptrans_alist
);
20153 XSETCDR (tem
, Qnil
);
20162 prec
= precision
- n
;
20163 switch (mode_line_target
)
20165 case MODE_LINE_NOPROP
:
20166 case MODE_LINE_TITLE
:
20167 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20169 case MODE_LINE_STRING
:
20170 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20172 case MODE_LINE_DISPLAY
:
20173 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20174 0, prec
, 0, STRING_MULTIBYTE (elt
));
20181 /* Handle the non-literal case. */
20183 while ((precision
<= 0 || n
< precision
)
20184 && SREF (elt
, offset
) != 0
20185 && (mode_line_target
!= MODE_LINE_DISPLAY
20186 || it
->current_x
< it
->last_visible_x
))
20188 ptrdiff_t last_offset
= offset
;
20190 /* Advance to end of string or next format specifier. */
20191 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20194 if (offset
- 1 != last_offset
)
20196 ptrdiff_t nchars
, nbytes
;
20198 /* Output to end of string or up to '%'. Field width
20199 is length of string. Don't output more than
20200 PRECISION allows us. */
20203 prec
= c_string_width (SDATA (elt
) + last_offset
,
20204 offset
- last_offset
, precision
- n
,
20207 switch (mode_line_target
)
20209 case MODE_LINE_NOPROP
:
20210 case MODE_LINE_TITLE
:
20211 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20213 case MODE_LINE_STRING
:
20215 ptrdiff_t bytepos
= last_offset
;
20216 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20217 ptrdiff_t endpos
= (precision
<= 0
20218 ? string_byte_to_char (elt
, offset
)
20219 : charpos
+ nchars
);
20221 n
+= store_mode_line_string (NULL
,
20222 Fsubstring (elt
, make_number (charpos
),
20223 make_number (endpos
)),
20227 case MODE_LINE_DISPLAY
:
20229 ptrdiff_t bytepos
= last_offset
;
20230 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20232 if (precision
<= 0)
20233 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20234 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20236 STRING_MULTIBYTE (elt
));
20241 else /* c == '%' */
20243 ptrdiff_t percent_position
= offset
;
20245 /* Get the specified minimum width. Zero means
20248 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20249 field
= field
* 10 + c
- '0';
20251 /* Don't pad beyond the total padding allowed. */
20252 if (field_width
- n
> 0 && field
> field_width
- n
)
20253 field
= field_width
- n
;
20255 /* Note that either PRECISION <= 0 or N < PRECISION. */
20256 prec
= precision
- n
;
20259 n
+= display_mode_element (it
, depth
, field
, prec
,
20260 Vglobal_mode_string
, props
,
20265 ptrdiff_t bytepos
, charpos
;
20267 Lisp_Object string
;
20269 bytepos
= percent_position
;
20270 charpos
= (STRING_MULTIBYTE (elt
)
20271 ? string_byte_to_char (elt
, bytepos
)
20273 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20274 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20276 switch (mode_line_target
)
20278 case MODE_LINE_NOPROP
:
20279 case MODE_LINE_TITLE
:
20280 n
+= store_mode_line_noprop (spec
, field
, prec
);
20282 case MODE_LINE_STRING
:
20284 Lisp_Object tem
= build_string (spec
);
20285 props
= Ftext_properties_at (make_number (charpos
), elt
);
20286 /* Should only keep face property in props */
20287 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20290 case MODE_LINE_DISPLAY
:
20292 int nglyphs_before
, nwritten
;
20294 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20295 nwritten
= display_string (spec
, string
, elt
,
20300 /* Assign to the glyphs written above the
20301 string where the `%x' came from, position
20305 struct glyph
*glyph
20306 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20310 for (i
= 0; i
< nwritten
; ++i
)
20312 glyph
[i
].object
= elt
;
20313 glyph
[i
].charpos
= charpos
;
20330 /* A symbol: process the value of the symbol recursively
20331 as if it appeared here directly. Avoid error if symbol void.
20332 Special case: if value of symbol is a string, output the string
20335 register Lisp_Object tem
;
20337 /* If the variable is not marked as risky to set
20338 then its contents are risky to use. */
20339 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20342 tem
= Fboundp (elt
);
20345 tem
= Fsymbol_value (elt
);
20346 /* If value is a string, output that string literally:
20347 don't check for % within it. */
20351 if (!EQ (tem
, elt
))
20353 /* Give up right away for nil or t. */
20363 register Lisp_Object car
, tem
;
20365 /* A cons cell: five distinct cases.
20366 If first element is :eval or :propertize, do something special.
20367 If first element is a string or a cons, process all the elements
20368 and effectively concatenate them.
20369 If first element is a negative number, truncate displaying cdr to
20370 at most that many characters. If positive, pad (with spaces)
20371 to at least that many characters.
20372 If first element is a symbol, process the cadr or caddr recursively
20373 according to whether the symbol's value is non-nil or nil. */
20375 if (EQ (car
, QCeval
))
20377 /* An element of the form (:eval FORM) means evaluate FORM
20378 and use the result as mode line elements. */
20383 if (CONSP (XCDR (elt
)))
20386 spec
= safe_eval (XCAR (XCDR (elt
)));
20387 n
+= display_mode_element (it
, depth
, field_width
- n
,
20388 precision
- n
, spec
, props
,
20392 else if (EQ (car
, QCpropertize
))
20394 /* An element of the form (:propertize ELT PROPS...)
20395 means display ELT but applying properties PROPS. */
20400 if (CONSP (XCDR (elt
)))
20401 n
+= display_mode_element (it
, depth
, field_width
- n
,
20402 precision
- n
, XCAR (XCDR (elt
)),
20403 XCDR (XCDR (elt
)), risky
);
20405 else if (SYMBOLP (car
))
20407 tem
= Fboundp (car
);
20411 /* elt is now the cdr, and we know it is a cons cell.
20412 Use its car if CAR has a non-nil value. */
20415 tem
= Fsymbol_value (car
);
20422 /* Symbol's value is nil (or symbol is unbound)
20423 Get the cddr of the original list
20424 and if possible find the caddr and use that. */
20428 else if (!CONSP (elt
))
20433 else if (INTEGERP (car
))
20435 register int lim
= XINT (car
);
20439 /* Negative int means reduce maximum width. */
20440 if (precision
<= 0)
20443 precision
= min (precision
, -lim
);
20447 /* Padding specified. Don't let it be more than
20448 current maximum. */
20450 lim
= min (precision
, lim
);
20452 /* If that's more padding than already wanted, queue it.
20453 But don't reduce padding already specified even if
20454 that is beyond the current truncation point. */
20455 field_width
= max (lim
, field_width
);
20459 else if (STRINGP (car
) || CONSP (car
))
20461 Lisp_Object halftail
= elt
;
20465 && (precision
<= 0 || n
< precision
))
20467 n
+= display_mode_element (it
, depth
,
20468 /* Do padding only after the last
20469 element in the list. */
20470 (! CONSP (XCDR (elt
))
20473 precision
- n
, XCAR (elt
),
20477 if ((len
& 1) == 0)
20478 halftail
= XCDR (halftail
);
20479 /* Check for cycle. */
20480 if (EQ (halftail
, elt
))
20489 elt
= build_string ("*invalid*");
20493 /* Pad to FIELD_WIDTH. */
20494 if (field_width
> 0 && n
< field_width
)
20496 switch (mode_line_target
)
20498 case MODE_LINE_NOPROP
:
20499 case MODE_LINE_TITLE
:
20500 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20502 case MODE_LINE_STRING
:
20503 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20505 case MODE_LINE_DISPLAY
:
20506 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20515 /* Store a mode-line string element in mode_line_string_list.
20517 If STRING is non-null, display that C string. Otherwise, the Lisp
20518 string LISP_STRING is displayed.
20520 FIELD_WIDTH is the minimum number of output glyphs to produce.
20521 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20522 with spaces. FIELD_WIDTH <= 0 means don't pad.
20524 PRECISION is the maximum number of characters to output from
20525 STRING. PRECISION <= 0 means don't truncate the string.
20527 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20528 properties to the string.
20530 PROPS are the properties to add to the string.
20531 The mode_line_string_face face property is always added to the string.
20535 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20536 int field_width
, int precision
, Lisp_Object props
)
20541 if (string
!= NULL
)
20543 len
= strlen (string
);
20544 if (precision
> 0 && len
> precision
)
20546 lisp_string
= make_string (string
, len
);
20548 props
= mode_line_string_face_prop
;
20549 else if (!NILP (mode_line_string_face
))
20551 Lisp_Object face
= Fplist_get (props
, Qface
);
20552 props
= Fcopy_sequence (props
);
20554 face
= mode_line_string_face
;
20556 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20557 props
= Fplist_put (props
, Qface
, face
);
20559 Fadd_text_properties (make_number (0), make_number (len
),
20560 props
, lisp_string
);
20564 len
= XFASTINT (Flength (lisp_string
));
20565 if (precision
> 0 && len
> precision
)
20568 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20571 if (!NILP (mode_line_string_face
))
20575 props
= Ftext_properties_at (make_number (0), lisp_string
);
20576 face
= Fplist_get (props
, Qface
);
20578 face
= mode_line_string_face
;
20580 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20581 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20583 lisp_string
= Fcopy_sequence (lisp_string
);
20586 Fadd_text_properties (make_number (0), make_number (len
),
20587 props
, lisp_string
);
20592 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20596 if (field_width
> len
)
20598 field_width
-= len
;
20599 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20601 Fadd_text_properties (make_number (0), make_number (field_width
),
20602 props
, lisp_string
);
20603 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20611 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20613 doc
: /* Format a string out of a mode line format specification.
20614 First arg FORMAT specifies the mode line format (see `mode-line-format'
20615 for details) to use.
20617 By default, the format is evaluated for the currently selected window.
20619 Optional second arg FACE specifies the face property to put on all
20620 characters for which no face is specified. The value nil means the
20621 default face. The value t means whatever face the window's mode line
20622 currently uses (either `mode-line' or `mode-line-inactive',
20623 depending on whether the window is the selected window or not).
20624 An integer value means the value string has no text
20627 Optional third and fourth args WINDOW and BUFFER specify the window
20628 and buffer to use as the context for the formatting (defaults
20629 are the selected window and the WINDOW's buffer). */)
20630 (Lisp_Object format
, Lisp_Object face
,
20631 Lisp_Object window
, Lisp_Object buffer
)
20636 struct buffer
*old_buffer
= NULL
;
20638 int no_props
= INTEGERP (face
);
20639 ptrdiff_t count
= SPECPDL_INDEX ();
20641 int string_start
= 0;
20644 window
= selected_window
;
20645 CHECK_WINDOW (window
);
20646 w
= XWINDOW (window
);
20649 buffer
= w
->buffer
;
20650 CHECK_BUFFER (buffer
);
20652 /* Make formatting the modeline a non-op when noninteractive, otherwise
20653 there will be problems later caused by a partially initialized frame. */
20654 if (NILP (format
) || noninteractive
)
20655 return empty_unibyte_string
;
20660 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20661 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20662 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20663 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20664 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20665 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20666 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20669 if (XBUFFER (buffer
) != current_buffer
)
20670 old_buffer
= current_buffer
;
20672 /* Save things including mode_line_proptrans_alist,
20673 and set that to nil so that we don't alter the outer value. */
20674 record_unwind_protect (unwind_format_mode_line
,
20675 format_mode_line_unwind_data
20676 (old_buffer
, selected_window
, 1));
20677 mode_line_proptrans_alist
= Qnil
;
20679 Fselect_window (window
, Qt
);
20681 set_buffer_internal_1 (XBUFFER (buffer
));
20683 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20687 mode_line_target
= MODE_LINE_NOPROP
;
20688 mode_line_string_face_prop
= Qnil
;
20689 mode_line_string_list
= Qnil
;
20690 string_start
= MODE_LINE_NOPROP_LEN (0);
20694 mode_line_target
= MODE_LINE_STRING
;
20695 mode_line_string_list
= Qnil
;
20696 mode_line_string_face
= face
;
20697 mode_line_string_face_prop
20698 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20701 push_kboard (FRAME_KBOARD (it
.f
));
20702 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20707 len
= MODE_LINE_NOPROP_LEN (string_start
);
20708 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20712 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20713 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20714 empty_unibyte_string
);
20717 unbind_to (count
, Qnil
);
20721 /* Write a null-terminated, right justified decimal representation of
20722 the positive integer D to BUF using a minimal field width WIDTH. */
20725 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20727 register char *p
= buf
;
20735 *p
++ = d
% 10 + '0';
20740 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20751 /* Write a null-terminated, right justified decimal and "human
20752 readable" representation of the nonnegative integer D to BUF using
20753 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20755 static const char power_letter
[] =
20769 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20771 /* We aim to represent the nonnegative integer D as
20772 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20773 ptrdiff_t quotient
= d
;
20775 /* -1 means: do not use TENTHS. */
20779 /* Length of QUOTIENT.TENTHS as a string. */
20785 if (1000 <= quotient
)
20787 /* Scale to the appropriate EXPONENT. */
20790 remainder
= quotient
% 1000;
20794 while (1000 <= quotient
);
20796 /* Round to nearest and decide whether to use TENTHS or not. */
20799 tenths
= remainder
/ 100;
20800 if (50 <= remainder
% 100)
20807 if (quotient
== 10)
20815 if (500 <= remainder
)
20817 if (quotient
< 999)
20828 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
20829 if (tenths
== -1 && quotient
<= 99)
20836 p
= psuffix
= buf
+ max (width
, length
);
20838 /* Print EXPONENT. */
20839 *psuffix
++ = power_letter
[exponent
];
20842 /* Print TENTHS. */
20845 *--p
= '0' + tenths
;
20849 /* Print QUOTIENT. */
20852 int digit
= quotient
% 10;
20853 *--p
= '0' + digit
;
20855 while ((quotient
/= 10) != 0);
20857 /* Print leading spaces. */
20862 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
20863 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
20864 type of CODING_SYSTEM. Return updated pointer into BUF. */
20866 static unsigned char invalid_eol_type
[] = "(*invalid*)";
20869 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
20872 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
20873 const unsigned char *eol_str
;
20875 /* The EOL conversion we are using. */
20876 Lisp_Object eoltype
;
20878 val
= CODING_SYSTEM_SPEC (coding_system
);
20881 if (!VECTORP (val
)) /* Not yet decided. */
20886 eoltype
= eol_mnemonic_undecided
;
20887 /* Don't mention EOL conversion if it isn't decided. */
20892 Lisp_Object eolvalue
;
20894 attrs
= AREF (val
, 0);
20895 eolvalue
= AREF (val
, 2);
20898 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
20902 /* The EOL conversion that is normal on this system. */
20904 if (NILP (eolvalue
)) /* Not yet decided. */
20905 eoltype
= eol_mnemonic_undecided
;
20906 else if (VECTORP (eolvalue
)) /* Not yet decided. */
20907 eoltype
= eol_mnemonic_undecided
;
20908 else /* eolvalue is Qunix, Qdos, or Qmac. */
20909 eoltype
= (EQ (eolvalue
, Qunix
)
20910 ? eol_mnemonic_unix
20911 : (EQ (eolvalue
, Qdos
) == 1
20912 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
20918 /* Mention the EOL conversion if it is not the usual one. */
20919 if (STRINGP (eoltype
))
20921 eol_str
= SDATA (eoltype
);
20922 eol_str_len
= SBYTES (eoltype
);
20924 else if (CHARACTERP (eoltype
))
20926 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
20927 int c
= XFASTINT (eoltype
);
20928 eol_str_len
= CHAR_STRING (c
, tmp
);
20933 eol_str
= invalid_eol_type
;
20934 eol_str_len
= sizeof (invalid_eol_type
) - 1;
20936 memcpy (buf
, eol_str
, eol_str_len
);
20937 buf
+= eol_str_len
;
20943 /* Return a string for the output of a mode line %-spec for window W,
20944 generated by character C. FIELD_WIDTH > 0 means pad the string
20945 returned with spaces to that value. Return a Lisp string in
20946 *STRING if the resulting string is taken from that Lisp string.
20948 Note we operate on the current buffer for most purposes,
20949 the exception being w->base_line_pos. */
20951 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
20953 static const char *
20954 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
20955 Lisp_Object
*string
)
20958 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20959 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
20960 struct buffer
*b
= current_buffer
;
20968 if (!NILP (BVAR (b
, read_only
)))
20970 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20975 /* This differs from %* only for a modified read-only buffer. */
20976 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20978 if (!NILP (BVAR (b
, read_only
)))
20983 /* This differs from %* in ignoring read-only-ness. */
20984 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20996 if (command_loop_level
> 5)
20998 p
= decode_mode_spec_buf
;
20999 for (i
= 0; i
< command_loop_level
; i
++)
21002 return decode_mode_spec_buf
;
21010 if (command_loop_level
> 5)
21012 p
= decode_mode_spec_buf
;
21013 for (i
= 0; i
< command_loop_level
; i
++)
21016 return decode_mode_spec_buf
;
21023 /* Let lots_of_dashes be a string of infinite length. */
21024 if (mode_line_target
== MODE_LINE_NOPROP
||
21025 mode_line_target
== MODE_LINE_STRING
)
21027 if (field_width
<= 0
21028 || field_width
> sizeof (lots_of_dashes
))
21030 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21031 decode_mode_spec_buf
[i
] = '-';
21032 decode_mode_spec_buf
[i
] = '\0';
21033 return decode_mode_spec_buf
;
21036 return lots_of_dashes
;
21040 obj
= BVAR (b
, name
);
21044 /* %c and %l are ignored in `frame-title-format'.
21045 (In redisplay_internal, the frame title is drawn _before_ the
21046 windows are updated, so the stuff which depends on actual
21047 window contents (such as %l) may fail to render properly, or
21048 even crash emacs.) */
21049 if (mode_line_target
== MODE_LINE_TITLE
)
21053 ptrdiff_t col
= current_column ();
21054 w
->column_number_displayed
= make_number (col
);
21055 pint2str (decode_mode_spec_buf
, field_width
, col
);
21056 return decode_mode_spec_buf
;
21060 #ifndef SYSTEM_MALLOC
21062 if (NILP (Vmemory_full
))
21065 return "!MEM FULL! ";
21072 /* %F displays the frame name. */
21073 if (!NILP (f
->title
))
21074 return SSDATA (f
->title
);
21075 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21076 return SSDATA (f
->name
);
21080 obj
= BVAR (b
, filename
);
21085 ptrdiff_t size
= ZV
- BEGV
;
21086 pint2str (decode_mode_spec_buf
, field_width
, size
);
21087 return decode_mode_spec_buf
;
21092 ptrdiff_t size
= ZV
- BEGV
;
21093 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21094 return decode_mode_spec_buf
;
21099 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21100 ptrdiff_t topline
, nlines
, height
;
21103 /* %c and %l are ignored in `frame-title-format'. */
21104 if (mode_line_target
== MODE_LINE_TITLE
)
21107 startpos
= XMARKER (w
->start
)->charpos
;
21108 startpos_byte
= marker_byte_position (w
->start
);
21109 height
= WINDOW_TOTAL_LINES (w
);
21111 /* If we decided that this buffer isn't suitable for line numbers,
21112 don't forget that too fast. */
21113 if (EQ (w
->base_line_pos
, w
->buffer
))
21115 /* But do forget it, if the window shows a different buffer now. */
21116 else if (BUFFERP (w
->base_line_pos
))
21117 w
->base_line_pos
= Qnil
;
21119 /* If the buffer is very big, don't waste time. */
21120 if (INTEGERP (Vline_number_display_limit
)
21121 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21123 w
->base_line_pos
= Qnil
;
21124 w
->base_line_number
= Qnil
;
21128 if (INTEGERP (w
->base_line_number
)
21129 && INTEGERP (w
->base_line_pos
)
21130 && XFASTINT (w
->base_line_pos
) <= startpos
)
21132 line
= XFASTINT (w
->base_line_number
);
21133 linepos
= XFASTINT (w
->base_line_pos
);
21134 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21139 linepos
= BUF_BEGV (b
);
21140 linepos_byte
= BUF_BEGV_BYTE (b
);
21143 /* Count lines from base line to window start position. */
21144 nlines
= display_count_lines (linepos_byte
,
21148 topline
= nlines
+ line
;
21150 /* Determine a new base line, if the old one is too close
21151 or too far away, or if we did not have one.
21152 "Too close" means it's plausible a scroll-down would
21153 go back past it. */
21154 if (startpos
== BUF_BEGV (b
))
21156 w
->base_line_number
= make_number (topline
);
21157 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21159 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21160 || linepos
== BUF_BEGV (b
))
21162 ptrdiff_t limit
= BUF_BEGV (b
);
21163 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21164 ptrdiff_t position
;
21165 ptrdiff_t distance
=
21166 (height
* 2 + 30) * line_number_display_limit_width
;
21168 if (startpos
- distance
> limit
)
21170 limit
= startpos
- distance
;
21171 limit_byte
= CHAR_TO_BYTE (limit
);
21174 nlines
= display_count_lines (startpos_byte
,
21176 - (height
* 2 + 30),
21178 /* If we couldn't find the lines we wanted within
21179 line_number_display_limit_width chars per line,
21180 give up on line numbers for this window. */
21181 if (position
== limit_byte
&& limit
== startpos
- distance
)
21183 w
->base_line_pos
= w
->buffer
;
21184 w
->base_line_number
= Qnil
;
21188 w
->base_line_number
= make_number (topline
- nlines
);
21189 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21192 /* Now count lines from the start pos to point. */
21193 nlines
= display_count_lines (startpos_byte
,
21194 PT_BYTE
, PT
, &junk
);
21196 /* Record that we did display the line number. */
21197 line_number_displayed
= 1;
21199 /* Make the string to show. */
21200 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21201 return decode_mode_spec_buf
;
21204 char* p
= decode_mode_spec_buf
;
21205 int pad
= field_width
- 2;
21211 return decode_mode_spec_buf
;
21217 obj
= BVAR (b
, mode_name
);
21221 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21227 ptrdiff_t pos
= marker_position (w
->start
);
21228 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21230 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21232 if (pos
<= BUF_BEGV (b
))
21237 else if (pos
<= BUF_BEGV (b
))
21241 if (total
> 1000000)
21242 /* Do it differently for a large value, to avoid overflow. */
21243 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21245 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21246 /* We can't normally display a 3-digit number,
21247 so get us a 2-digit number that is close. */
21250 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21251 return decode_mode_spec_buf
;
21255 /* Display percentage of size above the bottom of the screen. */
21258 ptrdiff_t toppos
= marker_position (w
->start
);
21259 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21260 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21262 if (botpos
>= BUF_ZV (b
))
21264 if (toppos
<= BUF_BEGV (b
))
21271 if (total
> 1000000)
21272 /* Do it differently for a large value, to avoid overflow. */
21273 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21275 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21276 /* We can't normally display a 3-digit number,
21277 so get us a 2-digit number that is close. */
21280 if (toppos
<= BUF_BEGV (b
))
21281 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21283 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21284 return decode_mode_spec_buf
;
21289 /* status of process */
21290 obj
= Fget_buffer_process (Fcurrent_buffer ());
21292 return "no process";
21294 obj
= Fsymbol_name (Fprocess_status (obj
));
21300 ptrdiff_t count
= inhibit_garbage_collection ();
21301 Lisp_Object val
= call1 (intern ("file-remote-p"),
21302 BVAR (current_buffer
, directory
));
21303 unbind_to (count
, Qnil
);
21311 case 't': /* indicate TEXT or BINARY */
21315 /* coding-system (not including end-of-line format) */
21317 /* coding-system (including end-of-line type) */
21319 int eol_flag
= (c
== 'Z');
21320 char *p
= decode_mode_spec_buf
;
21322 if (! FRAME_WINDOW_P (f
))
21324 /* No need to mention EOL here--the terminal never needs
21325 to do EOL conversion. */
21326 p
= decode_mode_spec_coding (CODING_ID_NAME
21327 (FRAME_KEYBOARD_CODING (f
)->id
),
21329 p
= decode_mode_spec_coding (CODING_ID_NAME
21330 (FRAME_TERMINAL_CODING (f
)->id
),
21333 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21336 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21337 #ifdef subprocesses
21338 obj
= Fget_buffer_process (Fcurrent_buffer ());
21339 if (PROCESSP (obj
))
21341 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21343 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21346 #endif /* subprocesses */
21349 return decode_mode_spec_buf
;
21356 return SSDATA (obj
);
21363 /* Count up to COUNT lines starting from START_BYTE.
21364 But don't go beyond LIMIT_BYTE.
21365 Return the number of lines thus found (always nonnegative).
21367 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21370 display_count_lines (ptrdiff_t start_byte
,
21371 ptrdiff_t limit_byte
, ptrdiff_t count
,
21372 ptrdiff_t *byte_pos_ptr
)
21374 register unsigned char *cursor
;
21375 unsigned char *base
;
21377 register ptrdiff_t ceiling
;
21378 register unsigned char *ceiling_addr
;
21379 ptrdiff_t orig_count
= count
;
21381 /* If we are not in selective display mode,
21382 check only for newlines. */
21383 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21384 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21388 while (start_byte
< limit_byte
)
21390 ceiling
= BUFFER_CEILING_OF (start_byte
);
21391 ceiling
= min (limit_byte
- 1, ceiling
);
21392 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21393 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21396 if (selective_display
)
21397 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21400 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21403 if (cursor
!= ceiling_addr
)
21407 start_byte
+= cursor
- base
+ 1;
21408 *byte_pos_ptr
= start_byte
;
21412 if (++cursor
== ceiling_addr
)
21418 start_byte
+= cursor
- base
;
21423 while (start_byte
> limit_byte
)
21425 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21426 ceiling
= max (limit_byte
, ceiling
);
21427 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21428 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21431 if (selective_display
)
21432 while (--cursor
!= ceiling_addr
21433 && *cursor
!= '\n' && *cursor
!= 015)
21436 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21439 if (cursor
!= ceiling_addr
)
21443 start_byte
+= cursor
- base
+ 1;
21444 *byte_pos_ptr
= start_byte
;
21445 /* When scanning backwards, we should
21446 not count the newline posterior to which we stop. */
21447 return - orig_count
- 1;
21453 /* Here we add 1 to compensate for the last decrement
21454 of CURSOR, which took it past the valid range. */
21455 start_byte
+= cursor
- base
+ 1;
21459 *byte_pos_ptr
= limit_byte
;
21462 return - orig_count
+ count
;
21463 return orig_count
- count
;
21469 /***********************************************************************
21471 ***********************************************************************/
21473 /* Display a NUL-terminated string, starting with index START.
21475 If STRING is non-null, display that C string. Otherwise, the Lisp
21476 string LISP_STRING is displayed. There's a case that STRING is
21477 non-null and LISP_STRING is not nil. It means STRING is a string
21478 data of LISP_STRING. In that case, we display LISP_STRING while
21479 ignoring its text properties.
21481 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21482 FACE_STRING. Display STRING or LISP_STRING with the face at
21483 FACE_STRING_POS in FACE_STRING:
21485 Display the string in the environment given by IT, but use the
21486 standard display table, temporarily.
21488 FIELD_WIDTH is the minimum number of output glyphs to produce.
21489 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21490 with spaces. If STRING has more characters, more than FIELD_WIDTH
21491 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21493 PRECISION is the maximum number of characters to output from
21494 STRING. PRECISION < 0 means don't truncate the string.
21496 This is roughly equivalent to printf format specifiers:
21498 FIELD_WIDTH PRECISION PRINTF
21499 ----------------------------------------
21505 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21506 display them, and < 0 means obey the current buffer's value of
21507 enable_multibyte_characters.
21509 Value is the number of columns displayed. */
21512 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21513 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21514 int field_width
, int precision
, int max_x
, int multibyte
)
21516 int hpos_at_start
= it
->hpos
;
21517 int saved_face_id
= it
->face_id
;
21518 struct glyph_row
*row
= it
->glyph_row
;
21519 ptrdiff_t it_charpos
;
21521 /* Initialize the iterator IT for iteration over STRING beginning
21522 with index START. */
21523 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21524 precision
, field_width
, multibyte
);
21525 if (string
&& STRINGP (lisp_string
))
21526 /* LISP_STRING is the one returned by decode_mode_spec. We should
21527 ignore its text properties. */
21528 it
->stop_charpos
= it
->end_charpos
;
21530 /* If displaying STRING, set up the face of the iterator from
21531 FACE_STRING, if that's given. */
21532 if (STRINGP (face_string
))
21538 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21539 0, it
->region_beg_charpos
,
21540 it
->region_end_charpos
,
21541 &endptr
, it
->base_face_id
, 0);
21542 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21543 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21546 /* Set max_x to the maximum allowed X position. Don't let it go
21547 beyond the right edge of the window. */
21549 max_x
= it
->last_visible_x
;
21551 max_x
= min (max_x
, it
->last_visible_x
);
21553 /* Skip over display elements that are not visible. because IT->w is
21555 if (it
->current_x
< it
->first_visible_x
)
21556 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21557 MOVE_TO_POS
| MOVE_TO_X
);
21559 row
->ascent
= it
->max_ascent
;
21560 row
->height
= it
->max_ascent
+ it
->max_descent
;
21561 row
->phys_ascent
= it
->max_phys_ascent
;
21562 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21563 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21565 if (STRINGP (it
->string
))
21566 it_charpos
= IT_STRING_CHARPOS (*it
);
21568 it_charpos
= IT_CHARPOS (*it
);
21570 /* This condition is for the case that we are called with current_x
21571 past last_visible_x. */
21572 while (it
->current_x
< max_x
)
21574 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21576 /* Get the next display element. */
21577 if (!get_next_display_element (it
))
21580 /* Produce glyphs. */
21581 x_before
= it
->current_x
;
21582 n_glyphs_before
= row
->used
[TEXT_AREA
];
21583 PRODUCE_GLYPHS (it
);
21585 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21588 while (i
< nglyphs
)
21590 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21592 if (it
->line_wrap
!= TRUNCATE
21593 && x
+ glyph
->pixel_width
> max_x
)
21595 /* End of continued line or max_x reached. */
21596 if (CHAR_GLYPH_PADDING_P (*glyph
))
21598 /* A wide character is unbreakable. */
21599 if (row
->reversed_p
)
21600 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21601 - n_glyphs_before
);
21602 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21603 it
->current_x
= x_before
;
21607 if (row
->reversed_p
)
21608 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21609 - (n_glyphs_before
+ i
));
21610 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21615 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21617 /* Glyph is at least partially visible. */
21619 if (x
< it
->first_visible_x
)
21620 row
->x
= x
- it
->first_visible_x
;
21624 /* Glyph is off the left margin of the display area.
21625 Should not happen. */
21629 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21630 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21631 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21632 row
->phys_height
= max (row
->phys_height
,
21633 it
->max_phys_ascent
+ it
->max_phys_descent
);
21634 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21635 it
->max_extra_line_spacing
);
21636 x
+= glyph
->pixel_width
;
21640 /* Stop if max_x reached. */
21644 /* Stop at line ends. */
21645 if (ITERATOR_AT_END_OF_LINE_P (it
))
21647 it
->continuation_lines_width
= 0;
21651 set_iterator_to_next (it
, 1);
21652 if (STRINGP (it
->string
))
21653 it_charpos
= IT_STRING_CHARPOS (*it
);
21655 it_charpos
= IT_CHARPOS (*it
);
21657 /* Stop if truncating at the right edge. */
21658 if (it
->line_wrap
== TRUNCATE
21659 && it
->current_x
>= it
->last_visible_x
)
21661 /* Add truncation mark, but don't do it if the line is
21662 truncated at a padding space. */
21663 if (it_charpos
< it
->string_nchars
)
21665 if (!FRAME_WINDOW_P (it
->f
))
21669 if (it
->current_x
> it
->last_visible_x
)
21671 if (!row
->reversed_p
)
21673 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21674 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21679 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21680 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21682 unproduce_glyphs (it
, ii
+ 1);
21683 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21685 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21687 row
->used
[TEXT_AREA
] = ii
;
21688 produce_special_glyphs (it
, IT_TRUNCATION
);
21691 produce_special_glyphs (it
, IT_TRUNCATION
);
21693 row
->truncated_on_right_p
= 1;
21699 /* Maybe insert a truncation at the left. */
21700 if (it
->first_visible_x
21703 if (!FRAME_WINDOW_P (it
->f
))
21704 insert_left_trunc_glyphs (it
);
21705 row
->truncated_on_left_p
= 1;
21708 it
->face_id
= saved_face_id
;
21710 /* Value is number of columns displayed. */
21711 return it
->hpos
- hpos_at_start
;
21716 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21717 appears as an element of LIST or as the car of an element of LIST.
21718 If PROPVAL is a list, compare each element against LIST in that
21719 way, and return 1/2 if any element of PROPVAL is found in LIST.
21720 Otherwise return 0. This function cannot quit.
21721 The return value is 2 if the text is invisible but with an ellipsis
21722 and 1 if it's invisible and without an ellipsis. */
21725 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21727 register Lisp_Object tail
, proptail
;
21729 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21731 register Lisp_Object tem
;
21733 if (EQ (propval
, tem
))
21735 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21736 return NILP (XCDR (tem
)) ? 1 : 2;
21739 if (CONSP (propval
))
21741 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21743 Lisp_Object propelt
;
21744 propelt
= XCAR (proptail
);
21745 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21747 register Lisp_Object tem
;
21749 if (EQ (propelt
, tem
))
21751 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21752 return NILP (XCDR (tem
)) ? 1 : 2;
21760 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21761 doc
: /* Non-nil if the property makes the text invisible.
21762 POS-OR-PROP can be a marker or number, in which case it is taken to be
21763 a position in the current buffer and the value of the `invisible' property
21764 is checked; or it can be some other value, which is then presumed to be the
21765 value of the `invisible' property of the text of interest.
21766 The non-nil value returned can be t for truly invisible text or something
21767 else if the text is replaced by an ellipsis. */)
21768 (Lisp_Object pos_or_prop
)
21771 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21772 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21774 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21775 return (invis
== 0 ? Qnil
21777 : make_number (invis
));
21780 /* Calculate a width or height in pixels from a specification using
21781 the following elements:
21784 NUM - a (fractional) multiple of the default font width/height
21785 (NUM) - specifies exactly NUM pixels
21786 UNIT - a fixed number of pixels, see below.
21787 ELEMENT - size of a display element in pixels, see below.
21788 (NUM . SPEC) - equals NUM * SPEC
21789 (+ SPEC SPEC ...) - add pixel values
21790 (- SPEC SPEC ...) - subtract pixel values
21791 (- SPEC) - negate pixel value
21794 INT or FLOAT - a number constant
21795 SYMBOL - use symbol's (buffer local) variable binding.
21798 in - pixels per inch *)
21799 mm - pixels per 1/1000 meter *)
21800 cm - pixels per 1/100 meter *)
21801 width - width of current font in pixels.
21802 height - height of current font in pixels.
21804 *) using the ratio(s) defined in display-pixels-per-inch.
21808 left-fringe - left fringe width in pixels
21809 right-fringe - right fringe width in pixels
21811 left-margin - left margin width in pixels
21812 right-margin - right margin width in pixels
21814 scroll-bar - scroll-bar area width in pixels
21818 Pixels corresponding to 5 inches:
21821 Total width of non-text areas on left side of window (if scroll-bar is on left):
21822 '(space :width (+ left-fringe left-margin scroll-bar))
21824 Align to first text column (in header line):
21825 '(space :align-to 0)
21827 Align to middle of text area minus half the width of variable `my-image'
21828 containing a loaded image:
21829 '(space :align-to (0.5 . (- text my-image)))
21831 Width of left margin minus width of 1 character in the default font:
21832 '(space :width (- left-margin 1))
21834 Width of left margin minus width of 2 characters in the current font:
21835 '(space :width (- left-margin (2 . width)))
21837 Center 1 character over left-margin (in header line):
21838 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
21840 Different ways to express width of left fringe plus left margin minus one pixel:
21841 '(space :width (- (+ left-fringe left-margin) (1)))
21842 '(space :width (+ left-fringe left-margin (- (1))))
21843 '(space :width (+ left-fringe left-margin (-1)))
21847 #define NUMVAL(X) \
21848 ((INTEGERP (X) || FLOATP (X)) \
21853 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
21854 struct font
*font
, int width_p
, int *align_to
)
21858 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
21859 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
21862 return OK_PIXELS (0);
21864 xassert (FRAME_LIVE_P (it
->f
));
21866 if (SYMBOLP (prop
))
21868 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
21870 char *unit
= SSDATA (SYMBOL_NAME (prop
));
21872 if (unit
[0] == 'i' && unit
[1] == 'n')
21874 else if (unit
[0] == 'm' && unit
[1] == 'm')
21876 else if (unit
[0] == 'c' && unit
[1] == 'm')
21883 #ifdef HAVE_WINDOW_SYSTEM
21884 if (FRAME_WINDOW_P (it
->f
)
21886 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
21887 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
21889 return OK_PIXELS (ppi
/ pixels
);
21892 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
21893 || (CONSP (Vdisplay_pixels_per_inch
)
21895 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
21896 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
21898 return OK_PIXELS (ppi
/ pixels
);
21904 #ifdef HAVE_WINDOW_SYSTEM
21905 if (EQ (prop
, Qheight
))
21906 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
21907 if (EQ (prop
, Qwidth
))
21908 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
21910 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
21911 return OK_PIXELS (1);
21914 if (EQ (prop
, Qtext
))
21915 return OK_PIXELS (width_p
21916 ? window_box_width (it
->w
, TEXT_AREA
)
21917 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
21919 if (align_to
&& *align_to
< 0)
21922 if (EQ (prop
, Qleft
))
21923 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
21924 if (EQ (prop
, Qright
))
21925 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
21926 if (EQ (prop
, Qcenter
))
21927 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
21928 + window_box_width (it
->w
, TEXT_AREA
) / 2);
21929 if (EQ (prop
, Qleft_fringe
))
21930 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21931 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
21932 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
21933 if (EQ (prop
, Qright_fringe
))
21934 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21935 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21936 : window_box_right_offset (it
->w
, TEXT_AREA
));
21937 if (EQ (prop
, Qleft_margin
))
21938 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
21939 if (EQ (prop
, Qright_margin
))
21940 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
21941 if (EQ (prop
, Qscroll_bar
))
21942 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
21944 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21945 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21946 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21951 if (EQ (prop
, Qleft_fringe
))
21952 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
21953 if (EQ (prop
, Qright_fringe
))
21954 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
21955 if (EQ (prop
, Qleft_margin
))
21956 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
21957 if (EQ (prop
, Qright_margin
))
21958 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
21959 if (EQ (prop
, Qscroll_bar
))
21960 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
21963 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
21966 if (INTEGERP (prop
) || FLOATP (prop
))
21968 int base_unit
= (width_p
21969 ? FRAME_COLUMN_WIDTH (it
->f
)
21970 : FRAME_LINE_HEIGHT (it
->f
));
21971 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21976 Lisp_Object car
= XCAR (prop
);
21977 Lisp_Object cdr
= XCDR (prop
);
21981 #ifdef HAVE_WINDOW_SYSTEM
21982 if (FRAME_WINDOW_P (it
->f
)
21983 && valid_image_p (prop
))
21985 ptrdiff_t id
= lookup_image (it
->f
, prop
);
21986 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21988 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21991 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21997 while (CONSP (cdr
))
21999 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22000 font
, width_p
, align_to
))
22003 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22008 if (EQ (car
, Qminus
))
22010 return OK_PIXELS (pixels
);
22013 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
22016 if (INTEGERP (car
) || FLOATP (car
))
22019 pixels
= XFLOATINT (car
);
22021 return OK_PIXELS (pixels
);
22022 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22023 font
, width_p
, align_to
))
22024 return OK_PIXELS (pixels
* fact
);
22035 /***********************************************************************
22037 ***********************************************************************/
22039 #ifdef HAVE_WINDOW_SYSTEM
22044 dump_glyph_string (struct glyph_string
*s
)
22046 fprintf (stderr
, "glyph string\n");
22047 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22048 s
->x
, s
->y
, s
->width
, s
->height
);
22049 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22050 fprintf (stderr
, " hl = %d\n", s
->hl
);
22051 fprintf (stderr
, " left overhang = %d, right = %d\n",
22052 s
->left_overhang
, s
->right_overhang
);
22053 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22054 fprintf (stderr
, " extends to end of line = %d\n",
22055 s
->extends_to_end_of_line_p
);
22056 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22057 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22060 #endif /* GLYPH_DEBUG */
22062 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22063 of XChar2b structures for S; it can't be allocated in
22064 init_glyph_string because it must be allocated via `alloca'. W
22065 is the window on which S is drawn. ROW and AREA are the glyph row
22066 and area within the row from which S is constructed. START is the
22067 index of the first glyph structure covered by S. HL is a
22068 face-override for drawing S. */
22071 #define OPTIONAL_HDC(hdc) HDC hdc,
22072 #define DECLARE_HDC(hdc) HDC hdc;
22073 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22074 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22077 #ifndef OPTIONAL_HDC
22078 #define OPTIONAL_HDC(hdc)
22079 #define DECLARE_HDC(hdc)
22080 #define ALLOCATE_HDC(hdc, f)
22081 #define RELEASE_HDC(hdc, f)
22085 init_glyph_string (struct glyph_string
*s
,
22087 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22088 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22090 memset (s
, 0, sizeof *s
);
22092 s
->f
= XFRAME (w
->frame
);
22096 s
->display
= FRAME_X_DISPLAY (s
->f
);
22097 s
->window
= FRAME_X_WINDOW (s
->f
);
22098 s
->char2b
= char2b
;
22102 s
->first_glyph
= row
->glyphs
[area
] + start
;
22103 s
->height
= row
->height
;
22104 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22105 s
->ybase
= s
->y
+ row
->ascent
;
22109 /* Append the list of glyph strings with head H and tail T to the list
22110 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22113 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22114 struct glyph_string
*h
, struct glyph_string
*t
)
22128 /* Prepend the list of glyph strings with head H and tail T to the
22129 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22133 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22134 struct glyph_string
*h
, struct glyph_string
*t
)
22148 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22149 Set *HEAD and *TAIL to the resulting list. */
22152 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22153 struct glyph_string
*s
)
22155 s
->next
= s
->prev
= NULL
;
22156 append_glyph_string_lists (head
, tail
, s
, s
);
22160 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22161 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22162 make sure that X resources for the face returned are allocated.
22163 Value is a pointer to a realized face that is ready for display if
22164 DISPLAY_P is non-zero. */
22166 static inline struct face
*
22167 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22168 XChar2b
*char2b
, int display_p
)
22170 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22174 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22176 if (code
!= FONT_INVALID_CODE
)
22177 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22179 STORE_XCHAR2B (char2b
, 0, 0);
22182 /* Make sure X resources of the face are allocated. */
22183 #ifdef HAVE_X_WINDOWS
22187 xassert (face
!= NULL
);
22188 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22195 /* Get face and two-byte form of character glyph GLYPH on frame F.
22196 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22197 a pointer to a realized face that is ready for display. */
22199 static inline struct face
*
22200 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22201 XChar2b
*char2b
, int *two_byte_p
)
22205 xassert (glyph
->type
== CHAR_GLYPH
);
22206 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22215 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22216 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22218 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22220 if (code
!= FONT_INVALID_CODE
)
22221 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22223 STORE_XCHAR2B (char2b
, 0, 0);
22226 /* Make sure X resources of the face are allocated. */
22227 xassert (face
!= NULL
);
22228 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22233 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22234 Return 1 if FONT has a glyph for C, otherwise return 0. */
22237 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22241 if (CHAR_BYTE8_P (c
))
22242 code
= CHAR_TO_BYTE8 (c
);
22244 code
= font
->driver
->encode_char (font
, c
);
22246 if (code
== FONT_INVALID_CODE
)
22248 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22253 /* Fill glyph string S with composition components specified by S->cmp.
22255 BASE_FACE is the base face of the composition.
22256 S->cmp_from is the index of the first component for S.
22258 OVERLAPS non-zero means S should draw the foreground only, and use
22259 its physical height for clipping. See also draw_glyphs.
22261 Value is the index of a component not in S. */
22264 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22268 /* For all glyphs of this composition, starting at the offset
22269 S->cmp_from, until we reach the end of the definition or encounter a
22270 glyph that requires the different face, add it to S. */
22275 s
->for_overlaps
= overlaps
;
22278 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22280 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22282 /* TAB in a composition means display glyphs with padding space
22283 on the left or right. */
22286 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22289 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22296 s
->font
= s
->face
->font
;
22298 else if (s
->face
!= face
)
22306 if (s
->face
== NULL
)
22308 s
->face
= base_face
->ascii_face
;
22309 s
->font
= s
->face
->font
;
22312 /* All glyph strings for the same composition has the same width,
22313 i.e. the width set for the first component of the composition. */
22314 s
->width
= s
->first_glyph
->pixel_width
;
22316 /* If the specified font could not be loaded, use the frame's
22317 default font, but record the fact that we couldn't load it in
22318 the glyph string so that we can draw rectangles for the
22319 characters of the glyph string. */
22320 if (s
->font
== NULL
)
22322 s
->font_not_found_p
= 1;
22323 s
->font
= FRAME_FONT (s
->f
);
22326 /* Adjust base line for subscript/superscript text. */
22327 s
->ybase
+= s
->first_glyph
->voffset
;
22329 /* This glyph string must always be drawn with 16-bit functions. */
22336 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22337 int start
, int end
, int overlaps
)
22339 struct glyph
*glyph
, *last
;
22340 Lisp_Object lgstring
;
22343 s
->for_overlaps
= overlaps
;
22344 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22345 last
= s
->row
->glyphs
[s
->area
] + end
;
22346 s
->cmp_id
= glyph
->u
.cmp
.id
;
22347 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22348 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22349 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22350 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22351 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22353 while (glyph
< last
22354 && glyph
->u
.cmp
.automatic
22355 && glyph
->u
.cmp
.id
== s
->cmp_id
22356 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22357 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22359 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22361 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22362 unsigned code
= LGLYPH_CODE (lglyph
);
22364 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22366 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22367 return glyph
- s
->row
->glyphs
[s
->area
];
22371 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22372 See the comment of fill_glyph_string for arguments.
22373 Value is the index of the first glyph not in S. */
22377 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22378 int start
, int end
, int overlaps
)
22380 struct glyph
*glyph
, *last
;
22383 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22384 s
->for_overlaps
= overlaps
;
22385 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22386 last
= s
->row
->glyphs
[s
->area
] + end
;
22387 voffset
= glyph
->voffset
;
22388 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22389 s
->font
= s
->face
->font
;
22391 s
->width
= glyph
->pixel_width
;
22393 while (glyph
< last
22394 && glyph
->type
== GLYPHLESS_GLYPH
22395 && glyph
->voffset
== voffset
22396 && glyph
->face_id
== face_id
)
22399 s
->width
+= glyph
->pixel_width
;
22402 s
->ybase
+= voffset
;
22403 return glyph
- s
->row
->glyphs
[s
->area
];
22407 /* Fill glyph string S from a sequence of character glyphs.
22409 FACE_ID is the face id of the string. START is the index of the
22410 first glyph to consider, END is the index of the last + 1.
22411 OVERLAPS non-zero means S should draw the foreground only, and use
22412 its physical height for clipping. See also draw_glyphs.
22414 Value is the index of the first glyph not in S. */
22417 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22418 int start
, int end
, int overlaps
)
22420 struct glyph
*glyph
, *last
;
22422 int glyph_not_available_p
;
22424 xassert (s
->f
== XFRAME (s
->w
->frame
));
22425 xassert (s
->nchars
== 0);
22426 xassert (start
>= 0 && end
> start
);
22428 s
->for_overlaps
= overlaps
;
22429 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22430 last
= s
->row
->glyphs
[s
->area
] + end
;
22431 voffset
= glyph
->voffset
;
22432 s
->padding_p
= glyph
->padding_p
;
22433 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22435 while (glyph
< last
22436 && glyph
->type
== CHAR_GLYPH
22437 && glyph
->voffset
== voffset
22438 /* Same face id implies same font, nowadays. */
22439 && glyph
->face_id
== face_id
22440 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22444 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22445 s
->char2b
+ s
->nchars
,
22447 s
->two_byte_p
= two_byte_p
;
22449 xassert (s
->nchars
<= end
- start
);
22450 s
->width
+= glyph
->pixel_width
;
22451 if (glyph
++->padding_p
!= s
->padding_p
)
22455 s
->font
= s
->face
->font
;
22457 /* If the specified font could not be loaded, use the frame's font,
22458 but record the fact that we couldn't load it in
22459 S->font_not_found_p so that we can draw rectangles for the
22460 characters of the glyph string. */
22461 if (s
->font
== NULL
|| glyph_not_available_p
)
22463 s
->font_not_found_p
= 1;
22464 s
->font
= FRAME_FONT (s
->f
);
22467 /* Adjust base line for subscript/superscript text. */
22468 s
->ybase
+= voffset
;
22470 xassert (s
->face
&& s
->face
->gc
);
22471 return glyph
- s
->row
->glyphs
[s
->area
];
22475 /* Fill glyph string S from image glyph S->first_glyph. */
22478 fill_image_glyph_string (struct glyph_string
*s
)
22480 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22481 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22483 s
->slice
= s
->first_glyph
->slice
.img
;
22484 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22485 s
->font
= s
->face
->font
;
22486 s
->width
= s
->first_glyph
->pixel_width
;
22488 /* Adjust base line for subscript/superscript text. */
22489 s
->ybase
+= s
->first_glyph
->voffset
;
22493 /* Fill glyph string S from a sequence of stretch glyphs.
22495 START is the index of the first glyph to consider,
22496 END is the index of the last + 1.
22498 Value is the index of the first glyph not in S. */
22501 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22503 struct glyph
*glyph
, *last
;
22504 int voffset
, face_id
;
22506 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22508 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22509 last
= s
->row
->glyphs
[s
->area
] + end
;
22510 face_id
= glyph
->face_id
;
22511 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22512 s
->font
= s
->face
->font
;
22513 s
->width
= glyph
->pixel_width
;
22515 voffset
= glyph
->voffset
;
22519 && glyph
->type
== STRETCH_GLYPH
22520 && glyph
->voffset
== voffset
22521 && glyph
->face_id
== face_id
);
22523 s
->width
+= glyph
->pixel_width
;
22525 /* Adjust base line for subscript/superscript text. */
22526 s
->ybase
+= voffset
;
22528 /* The case that face->gc == 0 is handled when drawing the glyph
22529 string by calling PREPARE_FACE_FOR_DISPLAY. */
22531 return glyph
- s
->row
->glyphs
[s
->area
];
22534 static struct font_metrics
*
22535 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22537 static struct font_metrics metrics
;
22538 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22540 if (! font
|| code
== FONT_INVALID_CODE
)
22542 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22547 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22548 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22549 assumed to be zero. */
22552 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22554 *left
= *right
= 0;
22556 if (glyph
->type
== CHAR_GLYPH
)
22560 struct font_metrics
*pcm
;
22562 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22563 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22565 if (pcm
->rbearing
> pcm
->width
)
22566 *right
= pcm
->rbearing
- pcm
->width
;
22567 if (pcm
->lbearing
< 0)
22568 *left
= -pcm
->lbearing
;
22571 else if (glyph
->type
== COMPOSITE_GLYPH
)
22573 if (! glyph
->u
.cmp
.automatic
)
22575 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22577 if (cmp
->rbearing
> cmp
->pixel_width
)
22578 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22579 if (cmp
->lbearing
< 0)
22580 *left
= - cmp
->lbearing
;
22584 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22585 struct font_metrics metrics
;
22587 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22588 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22589 if (metrics
.rbearing
> metrics
.width
)
22590 *right
= metrics
.rbearing
- metrics
.width
;
22591 if (metrics
.lbearing
< 0)
22592 *left
= - metrics
.lbearing
;
22598 /* Return the index of the first glyph preceding glyph string S that
22599 is overwritten by S because of S's left overhang. Value is -1
22600 if no glyphs are overwritten. */
22603 left_overwritten (struct glyph_string
*s
)
22607 if (s
->left_overhang
)
22610 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22611 int first
= s
->first_glyph
- glyphs
;
22613 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22614 x
-= glyphs
[i
].pixel_width
;
22625 /* Return the index of the first glyph preceding glyph string S that
22626 is overwriting S because of its right overhang. Value is -1 if no
22627 glyph in front of S overwrites S. */
22630 left_overwriting (struct glyph_string
*s
)
22633 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22634 int first
= s
->first_glyph
- glyphs
;
22638 for (i
= first
- 1; i
>= 0; --i
)
22641 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22644 x
-= glyphs
[i
].pixel_width
;
22651 /* Return the index of the last glyph following glyph string S that is
22652 overwritten by S because of S's right overhang. Value is -1 if
22653 no such glyph is found. */
22656 right_overwritten (struct glyph_string
*s
)
22660 if (s
->right_overhang
)
22663 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22664 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22665 int end
= s
->row
->used
[s
->area
];
22667 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22668 x
+= glyphs
[i
].pixel_width
;
22677 /* Return the index of the last glyph following glyph string S that
22678 overwrites S because of its left overhang. Value is negative
22679 if no such glyph is found. */
22682 right_overwriting (struct glyph_string
*s
)
22685 int end
= s
->row
->used
[s
->area
];
22686 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22687 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22691 for (i
= first
; i
< end
; ++i
)
22694 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22697 x
+= glyphs
[i
].pixel_width
;
22704 /* Set background width of glyph string S. START is the index of the
22705 first glyph following S. LAST_X is the right-most x-position + 1
22706 in the drawing area. */
22709 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22711 /* If the face of this glyph string has to be drawn to the end of
22712 the drawing area, set S->extends_to_end_of_line_p. */
22714 if (start
== s
->row
->used
[s
->area
]
22715 && s
->area
== TEXT_AREA
22716 && ((s
->row
->fill_line_p
22717 && (s
->hl
== DRAW_NORMAL_TEXT
22718 || s
->hl
== DRAW_IMAGE_RAISED
22719 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22720 || s
->hl
== DRAW_MOUSE_FACE
))
22721 s
->extends_to_end_of_line_p
= 1;
22723 /* If S extends its face to the end of the line, set its
22724 background_width to the distance to the right edge of the drawing
22726 if (s
->extends_to_end_of_line_p
)
22727 s
->background_width
= last_x
- s
->x
+ 1;
22729 s
->background_width
= s
->width
;
22733 /* Compute overhangs and x-positions for glyph string S and its
22734 predecessors, or successors. X is the starting x-position for S.
22735 BACKWARD_P non-zero means process predecessors. */
22738 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22744 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22745 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22755 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22756 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22766 /* The following macros are only called from draw_glyphs below.
22767 They reference the following parameters of that function directly:
22768 `w', `row', `area', and `overlap_p'
22769 as well as the following local variables:
22770 `s', `f', and `hdc' (in W32) */
22773 /* On W32, silently add local `hdc' variable to argument list of
22774 init_glyph_string. */
22775 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22776 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22778 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22779 init_glyph_string (s, char2b, w, row, area, start, hl)
22782 /* Add a glyph string for a stretch glyph to the list of strings
22783 between HEAD and TAIL. START is the index of the stretch glyph in
22784 row area AREA of glyph row ROW. END is the index of the last glyph
22785 in that glyph row area. X is the current output position assigned
22786 to the new glyph string constructed. HL overrides that face of the
22787 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22788 is the right-most x-position of the drawing area. */
22790 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
22791 and below -- keep them on one line. */
22792 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22795 s = (struct glyph_string *) alloca (sizeof *s); \
22796 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22797 START = fill_stretch_glyph_string (s, START, END); \
22798 append_glyph_string (&HEAD, &TAIL, s); \
22804 /* Add a glyph string for an image glyph to the list of strings
22805 between HEAD and TAIL. START is the index of the image glyph in
22806 row area AREA of glyph row ROW. END is the index of the last glyph
22807 in that glyph row area. X is the current output position assigned
22808 to the new glyph string constructed. HL overrides that face of the
22809 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22810 is the right-most x-position of the drawing area. */
22812 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22815 s = (struct glyph_string *) alloca (sizeof *s); \
22816 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22817 fill_image_glyph_string (s); \
22818 append_glyph_string (&HEAD, &TAIL, s); \
22825 /* Add a glyph string for a sequence of character glyphs to the list
22826 of strings between HEAD and TAIL. START is the index of the first
22827 glyph in row area AREA of glyph row ROW that is part of the new
22828 glyph string. END is the index of the last glyph in that glyph row
22829 area. X is the current output position assigned to the new glyph
22830 string constructed. HL overrides that face of the glyph; e.g. it
22831 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
22832 right-most x-position of the drawing area. */
22834 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22840 face_id = (row)->glyphs[area][START].face_id; \
22842 s = (struct glyph_string *) alloca (sizeof *s); \
22843 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
22844 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22845 append_glyph_string (&HEAD, &TAIL, s); \
22847 START = fill_glyph_string (s, face_id, START, END, overlaps); \
22852 /* Add a glyph string for a composite sequence to the list of strings
22853 between HEAD and TAIL. START is the index of the first glyph in
22854 row area AREA of glyph row ROW that is part of the new glyph
22855 string. END is the index of the last glyph in that glyph row area.
22856 X is the current output position assigned to the new glyph string
22857 constructed. HL overrides that face of the glyph; e.g. it is
22858 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
22859 x-position of the drawing area. */
22861 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22863 int face_id = (row)->glyphs[area][START].face_id; \
22864 struct face *base_face = FACE_FROM_ID (f, face_id); \
22865 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
22866 struct composition *cmp = composition_table[cmp_id]; \
22868 struct glyph_string *first_s = NULL; \
22871 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
22873 /* Make glyph_strings for each glyph sequence that is drawable by \
22874 the same face, and append them to HEAD/TAIL. */ \
22875 for (n = 0; n < cmp->glyph_len;) \
22877 s = (struct glyph_string *) alloca (sizeof *s); \
22878 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22879 append_glyph_string (&(HEAD), &(TAIL), s); \
22885 n = fill_composite_glyph_string (s, base_face, overlaps); \
22893 /* Add a glyph string for a glyph-string sequence to the list of strings
22894 between HEAD and TAIL. */
22896 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22900 Lisp_Object gstring; \
22902 face_id = (row)->glyphs[area][START].face_id; \
22903 gstring = (composition_gstring_from_id \
22904 ((row)->glyphs[area][START].u.cmp.id)); \
22905 s = (struct glyph_string *) alloca (sizeof *s); \
22906 char2b = (XChar2b *) alloca ((sizeof *char2b) \
22907 * LGSTRING_GLYPH_LEN (gstring)); \
22908 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22909 append_glyph_string (&(HEAD), &(TAIL), s); \
22911 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
22915 /* Add a glyph string for a sequence of glyphless character's glyphs
22916 to the list of strings between HEAD and TAIL. The meanings of
22917 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
22919 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22924 face_id = (row)->glyphs[area][START].face_id; \
22926 s = (struct glyph_string *) alloca (sizeof *s); \
22927 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22928 append_glyph_string (&HEAD, &TAIL, s); \
22930 START = fill_glyphless_glyph_string (s, face_id, START, END, \
22936 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
22937 of AREA of glyph row ROW on window W between indices START and END.
22938 HL overrides the face for drawing glyph strings, e.g. it is
22939 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
22940 x-positions of the drawing area.
22942 This is an ugly monster macro construct because we must use alloca
22943 to allocate glyph strings (because draw_glyphs can be called
22944 asynchronously). */
22946 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22949 HEAD = TAIL = NULL; \
22950 while (START < END) \
22952 struct glyph *first_glyph = (row)->glyphs[area] + START; \
22953 switch (first_glyph->type) \
22956 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
22960 case COMPOSITE_GLYPH: \
22961 if (first_glyph->u.cmp.automatic) \
22962 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
22965 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
22969 case STRETCH_GLYPH: \
22970 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
22974 case IMAGE_GLYPH: \
22975 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
22979 case GLYPHLESS_GLYPH: \
22980 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22990 set_glyph_string_background_width (s, START, LAST_X); \
22997 /* Draw glyphs between START and END in AREA of ROW on window W,
22998 starting at x-position X. X is relative to AREA in W. HL is a
22999 face-override with the following meaning:
23001 DRAW_NORMAL_TEXT draw normally
23002 DRAW_CURSOR draw in cursor face
23003 DRAW_MOUSE_FACE draw in mouse face.
23004 DRAW_INVERSE_VIDEO draw in mode line face
23005 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23006 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23008 If OVERLAPS is non-zero, draw only the foreground of characters and
23009 clip to the physical height of ROW. Non-zero value also defines
23010 the overlapping part to be drawn:
23012 OVERLAPS_PRED overlap with preceding rows
23013 OVERLAPS_SUCC overlap with succeeding rows
23014 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23015 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23017 Value is the x-position reached, relative to AREA of W. */
23020 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23021 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23022 enum draw_glyphs_face hl
, int overlaps
)
23024 struct glyph_string
*head
, *tail
;
23025 struct glyph_string
*s
;
23026 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23027 int i
, j
, x_reached
, last_x
, area_left
= 0;
23028 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23031 ALLOCATE_HDC (hdc
, f
);
23033 /* Let's rather be paranoid than getting a SEGV. */
23034 end
= min (end
, row
->used
[area
]);
23035 start
= max (0, start
);
23036 start
= min (end
, start
);
23038 /* Translate X to frame coordinates. Set last_x to the right
23039 end of the drawing area. */
23040 if (row
->full_width_p
)
23042 /* X is relative to the left edge of W, without scroll bars
23044 area_left
= WINDOW_LEFT_EDGE_X (w
);
23045 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23049 area_left
= window_box_left (w
, area
);
23050 last_x
= area_left
+ window_box_width (w
, area
);
23054 /* Build a doubly-linked list of glyph_string structures between
23055 head and tail from what we have to draw. Note that the macro
23056 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23057 the reason we use a separate variable `i'. */
23059 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23061 x_reached
= tail
->x
+ tail
->background_width
;
23065 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23066 the row, redraw some glyphs in front or following the glyph
23067 strings built above. */
23068 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23070 struct glyph_string
*h
, *t
;
23071 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23072 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23073 int check_mouse_face
= 0;
23076 /* If mouse highlighting is on, we may need to draw adjacent
23077 glyphs using mouse-face highlighting. */
23078 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23080 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23082 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23083 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23085 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23087 check_mouse_face
= 1;
23088 mouse_beg_col
= (row
== mouse_beg_row
)
23089 ? hlinfo
->mouse_face_beg_col
: 0;
23090 mouse_end_col
= (row
== mouse_end_row
)
23091 ? hlinfo
->mouse_face_end_col
23092 : row
->used
[TEXT_AREA
];
23096 /* Compute overhangs for all glyph strings. */
23097 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23098 for (s
= head
; s
; s
= s
->next
)
23099 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23101 /* Prepend glyph strings for glyphs in front of the first glyph
23102 string that are overwritten because of the first glyph
23103 string's left overhang. The background of all strings
23104 prepended must be drawn because the first glyph string
23106 i
= left_overwritten (head
);
23109 enum draw_glyphs_face overlap_hl
;
23111 /* If this row contains mouse highlighting, attempt to draw
23112 the overlapped glyphs with the correct highlight. This
23113 code fails if the overlap encompasses more than one glyph
23114 and mouse-highlight spans only some of these glyphs.
23115 However, making it work perfectly involves a lot more
23116 code, and I don't know if the pathological case occurs in
23117 practice, so we'll stick to this for now. --- cyd */
23118 if (check_mouse_face
23119 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23120 overlap_hl
= DRAW_MOUSE_FACE
;
23122 overlap_hl
= DRAW_NORMAL_TEXT
;
23125 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23126 overlap_hl
, dummy_x
, last_x
);
23128 compute_overhangs_and_x (t
, head
->x
, 1);
23129 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23133 /* Prepend glyph strings for glyphs in front of the first glyph
23134 string that overwrite that glyph string because of their
23135 right overhang. For these strings, only the foreground must
23136 be drawn, because it draws over the glyph string at `head'.
23137 The background must not be drawn because this would overwrite
23138 right overhangs of preceding glyphs for which no glyph
23140 i
= left_overwriting (head
);
23143 enum draw_glyphs_face overlap_hl
;
23145 if (check_mouse_face
23146 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23147 overlap_hl
= DRAW_MOUSE_FACE
;
23149 overlap_hl
= DRAW_NORMAL_TEXT
;
23152 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23153 overlap_hl
, dummy_x
, last_x
);
23154 for (s
= h
; s
; s
= s
->next
)
23155 s
->background_filled_p
= 1;
23156 compute_overhangs_and_x (t
, head
->x
, 1);
23157 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23160 /* Append glyphs strings for glyphs following the last glyph
23161 string tail that are overwritten by tail. The background of
23162 these strings has to be drawn because tail's foreground draws
23164 i
= right_overwritten (tail
);
23167 enum draw_glyphs_face overlap_hl
;
23169 if (check_mouse_face
23170 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23171 overlap_hl
= DRAW_MOUSE_FACE
;
23173 overlap_hl
= DRAW_NORMAL_TEXT
;
23175 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23176 overlap_hl
, x
, last_x
);
23177 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23178 we don't have `end = i;' here. */
23179 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23180 append_glyph_string_lists (&head
, &tail
, h
, t
);
23184 /* Append glyph strings for glyphs following the last glyph
23185 string tail that overwrite tail. The foreground of such
23186 glyphs has to be drawn because it writes into the background
23187 of tail. The background must not be drawn because it could
23188 paint over the foreground of following glyphs. */
23189 i
= right_overwriting (tail
);
23192 enum draw_glyphs_face overlap_hl
;
23193 if (check_mouse_face
23194 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23195 overlap_hl
= DRAW_MOUSE_FACE
;
23197 overlap_hl
= DRAW_NORMAL_TEXT
;
23200 i
++; /* We must include the Ith glyph. */
23201 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23202 overlap_hl
, x
, last_x
);
23203 for (s
= h
; s
; s
= s
->next
)
23204 s
->background_filled_p
= 1;
23205 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23206 append_glyph_string_lists (&head
, &tail
, h
, t
);
23208 if (clip_head
|| clip_tail
)
23209 for (s
= head
; s
; s
= s
->next
)
23211 s
->clip_head
= clip_head
;
23212 s
->clip_tail
= clip_tail
;
23216 /* Draw all strings. */
23217 for (s
= head
; s
; s
= s
->next
)
23218 FRAME_RIF (f
)->draw_glyph_string (s
);
23221 /* When focus a sole frame and move horizontally, this sets on_p to 0
23222 causing a failure to erase prev cursor position. */
23223 if (area
== TEXT_AREA
23224 && !row
->full_width_p
23225 /* When drawing overlapping rows, only the glyph strings'
23226 foreground is drawn, which doesn't erase a cursor
23230 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23231 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23232 : (tail
? tail
->x
+ tail
->background_width
: x
));
23236 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23237 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23241 /* Value is the x-position up to which drawn, relative to AREA of W.
23242 This doesn't include parts drawn because of overhangs. */
23243 if (row
->full_width_p
)
23244 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23246 x_reached
-= area_left
;
23248 RELEASE_HDC (hdc
, f
);
23253 /* Expand row matrix if too narrow. Don't expand if area
23256 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23258 if (!fonts_changed_p \
23259 && (it->glyph_row->glyphs[area] \
23260 < it->glyph_row->glyphs[area + 1])) \
23262 it->w->ncols_scale_factor++; \
23263 fonts_changed_p = 1; \
23267 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23268 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23271 append_glyph (struct it
*it
)
23273 struct glyph
*glyph
;
23274 enum glyph_row_area area
= it
->area
;
23276 xassert (it
->glyph_row
);
23277 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23279 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23280 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23282 /* If the glyph row is reversed, we need to prepend the glyph
23283 rather than append it. */
23284 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23288 /* Make room for the additional glyph. */
23289 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23291 glyph
= it
->glyph_row
->glyphs
[area
];
23293 glyph
->charpos
= CHARPOS (it
->position
);
23294 glyph
->object
= it
->object
;
23295 if (it
->pixel_width
> 0)
23297 glyph
->pixel_width
= it
->pixel_width
;
23298 glyph
->padding_p
= 0;
23302 /* Assure at least 1-pixel width. Otherwise, cursor can't
23303 be displayed correctly. */
23304 glyph
->pixel_width
= 1;
23305 glyph
->padding_p
= 1;
23307 glyph
->ascent
= it
->ascent
;
23308 glyph
->descent
= it
->descent
;
23309 glyph
->voffset
= it
->voffset
;
23310 glyph
->type
= CHAR_GLYPH
;
23311 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23312 glyph
->multibyte_p
= it
->multibyte_p
;
23313 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23314 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23315 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23316 || it
->phys_descent
> it
->descent
);
23317 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23318 glyph
->face_id
= it
->face_id
;
23319 glyph
->u
.ch
= it
->char_to_display
;
23320 glyph
->slice
.img
= null_glyph_slice
;
23321 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23324 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23325 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23327 glyph
->bidi_type
= it
->bidi_it
.type
;
23331 glyph
->resolved_level
= 0;
23332 glyph
->bidi_type
= UNKNOWN_BT
;
23334 ++it
->glyph_row
->used
[area
];
23337 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23340 /* Store one glyph for the composition IT->cmp_it.id in
23341 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23345 append_composite_glyph (struct it
*it
)
23347 struct glyph
*glyph
;
23348 enum glyph_row_area area
= it
->area
;
23350 xassert (it
->glyph_row
);
23352 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23353 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23355 /* If the glyph row is reversed, we need to prepend the glyph
23356 rather than append it. */
23357 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23361 /* Make room for the new glyph. */
23362 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23364 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23366 glyph
->charpos
= it
->cmp_it
.charpos
;
23367 glyph
->object
= it
->object
;
23368 glyph
->pixel_width
= it
->pixel_width
;
23369 glyph
->ascent
= it
->ascent
;
23370 glyph
->descent
= it
->descent
;
23371 glyph
->voffset
= it
->voffset
;
23372 glyph
->type
= COMPOSITE_GLYPH
;
23373 if (it
->cmp_it
.ch
< 0)
23375 glyph
->u
.cmp
.automatic
= 0;
23376 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23377 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23381 glyph
->u
.cmp
.automatic
= 1;
23382 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23383 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23384 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23386 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23387 glyph
->multibyte_p
= it
->multibyte_p
;
23388 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23389 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23390 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23391 || it
->phys_descent
> it
->descent
);
23392 glyph
->padding_p
= 0;
23393 glyph
->glyph_not_available_p
= 0;
23394 glyph
->face_id
= it
->face_id
;
23395 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23398 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23399 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23401 glyph
->bidi_type
= it
->bidi_it
.type
;
23403 ++it
->glyph_row
->used
[area
];
23406 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23410 /* Change IT->ascent and IT->height according to the setting of
23414 take_vertical_position_into_account (struct it
*it
)
23418 if (it
->voffset
< 0)
23419 /* Increase the ascent so that we can display the text higher
23421 it
->ascent
-= it
->voffset
;
23423 /* Increase the descent so that we can display the text lower
23425 it
->descent
+= it
->voffset
;
23430 /* Produce glyphs/get display metrics for the image IT is loaded with.
23431 See the description of struct display_iterator in dispextern.h for
23432 an overview of struct display_iterator. */
23435 produce_image_glyph (struct it
*it
)
23439 int glyph_ascent
, crop
;
23440 struct glyph_slice slice
;
23442 xassert (it
->what
== IT_IMAGE
);
23444 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23446 /* Make sure X resources of the face is loaded. */
23447 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23449 if (it
->image_id
< 0)
23451 /* Fringe bitmap. */
23452 it
->ascent
= it
->phys_ascent
= 0;
23453 it
->descent
= it
->phys_descent
= 0;
23454 it
->pixel_width
= 0;
23459 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23461 /* Make sure X resources of the image is loaded. */
23462 prepare_image_for_display (it
->f
, img
);
23464 slice
.x
= slice
.y
= 0;
23465 slice
.width
= img
->width
;
23466 slice
.height
= img
->height
;
23468 if (INTEGERP (it
->slice
.x
))
23469 slice
.x
= XINT (it
->slice
.x
);
23470 else if (FLOATP (it
->slice
.x
))
23471 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23473 if (INTEGERP (it
->slice
.y
))
23474 slice
.y
= XINT (it
->slice
.y
);
23475 else if (FLOATP (it
->slice
.y
))
23476 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23478 if (INTEGERP (it
->slice
.width
))
23479 slice
.width
= XINT (it
->slice
.width
);
23480 else if (FLOATP (it
->slice
.width
))
23481 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23483 if (INTEGERP (it
->slice
.height
))
23484 slice
.height
= XINT (it
->slice
.height
);
23485 else if (FLOATP (it
->slice
.height
))
23486 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23488 if (slice
.x
>= img
->width
)
23489 slice
.x
= img
->width
;
23490 if (slice
.y
>= img
->height
)
23491 slice
.y
= img
->height
;
23492 if (slice
.x
+ slice
.width
>= img
->width
)
23493 slice
.width
= img
->width
- slice
.x
;
23494 if (slice
.y
+ slice
.height
> img
->height
)
23495 slice
.height
= img
->height
- slice
.y
;
23497 if (slice
.width
== 0 || slice
.height
== 0)
23500 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23502 it
->descent
= slice
.height
- glyph_ascent
;
23504 it
->descent
+= img
->vmargin
;
23505 if (slice
.y
+ slice
.height
== img
->height
)
23506 it
->descent
+= img
->vmargin
;
23507 it
->phys_descent
= it
->descent
;
23509 it
->pixel_width
= slice
.width
;
23511 it
->pixel_width
+= img
->hmargin
;
23512 if (slice
.x
+ slice
.width
== img
->width
)
23513 it
->pixel_width
+= img
->hmargin
;
23515 /* It's quite possible for images to have an ascent greater than
23516 their height, so don't get confused in that case. */
23517 if (it
->descent
< 0)
23522 if (face
->box
!= FACE_NO_BOX
)
23524 if (face
->box_line_width
> 0)
23527 it
->ascent
+= face
->box_line_width
;
23528 if (slice
.y
+ slice
.height
== img
->height
)
23529 it
->descent
+= face
->box_line_width
;
23532 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23533 it
->pixel_width
+= eabs (face
->box_line_width
);
23534 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23535 it
->pixel_width
+= eabs (face
->box_line_width
);
23538 take_vertical_position_into_account (it
);
23540 /* Automatically crop wide image glyphs at right edge so we can
23541 draw the cursor on same display row. */
23542 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23543 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23545 it
->pixel_width
-= crop
;
23546 slice
.width
-= crop
;
23551 struct glyph
*glyph
;
23552 enum glyph_row_area area
= it
->area
;
23554 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23555 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23557 glyph
->charpos
= CHARPOS (it
->position
);
23558 glyph
->object
= it
->object
;
23559 glyph
->pixel_width
= it
->pixel_width
;
23560 glyph
->ascent
= glyph_ascent
;
23561 glyph
->descent
= it
->descent
;
23562 glyph
->voffset
= it
->voffset
;
23563 glyph
->type
= IMAGE_GLYPH
;
23564 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23565 glyph
->multibyte_p
= it
->multibyte_p
;
23566 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23567 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23568 glyph
->overlaps_vertically_p
= 0;
23569 glyph
->padding_p
= 0;
23570 glyph
->glyph_not_available_p
= 0;
23571 glyph
->face_id
= it
->face_id
;
23572 glyph
->u
.img_id
= img
->id
;
23573 glyph
->slice
.img
= slice
;
23574 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23577 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23578 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23580 glyph
->bidi_type
= it
->bidi_it
.type
;
23582 ++it
->glyph_row
->used
[area
];
23585 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23590 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23591 of the glyph, WIDTH and HEIGHT are the width and height of the
23592 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23595 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23596 int width
, int height
, int ascent
)
23598 struct glyph
*glyph
;
23599 enum glyph_row_area area
= it
->area
;
23601 xassert (ascent
>= 0 && ascent
<= height
);
23603 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23604 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23606 /* If the glyph row is reversed, we need to prepend the glyph
23607 rather than append it. */
23608 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23612 /* Make room for the additional glyph. */
23613 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23615 glyph
= it
->glyph_row
->glyphs
[area
];
23617 glyph
->charpos
= CHARPOS (it
->position
);
23618 glyph
->object
= object
;
23619 glyph
->pixel_width
= width
;
23620 glyph
->ascent
= ascent
;
23621 glyph
->descent
= height
- ascent
;
23622 glyph
->voffset
= it
->voffset
;
23623 glyph
->type
= STRETCH_GLYPH
;
23624 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23625 glyph
->multibyte_p
= it
->multibyte_p
;
23626 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23627 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23628 glyph
->overlaps_vertically_p
= 0;
23629 glyph
->padding_p
= 0;
23630 glyph
->glyph_not_available_p
= 0;
23631 glyph
->face_id
= it
->face_id
;
23632 glyph
->u
.stretch
.ascent
= ascent
;
23633 glyph
->u
.stretch
.height
= height
;
23634 glyph
->slice
.img
= null_glyph_slice
;
23635 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23638 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23639 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23641 glyph
->bidi_type
= it
->bidi_it
.type
;
23645 glyph
->resolved_level
= 0;
23646 glyph
->bidi_type
= UNKNOWN_BT
;
23648 ++it
->glyph_row
->used
[area
];
23651 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23654 #endif /* HAVE_WINDOW_SYSTEM */
23656 /* Produce a stretch glyph for iterator IT. IT->object is the value
23657 of the glyph property displayed. The value must be a list
23658 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23661 1. `:width WIDTH' specifies that the space should be WIDTH *
23662 canonical char width wide. WIDTH may be an integer or floating
23665 2. `:relative-width FACTOR' specifies that the width of the stretch
23666 should be computed from the width of the first character having the
23667 `glyph' property, and should be FACTOR times that width.
23669 3. `:align-to HPOS' specifies that the space should be wide enough
23670 to reach HPOS, a value in canonical character units.
23672 Exactly one of the above pairs must be present.
23674 4. `:height HEIGHT' specifies that the height of the stretch produced
23675 should be HEIGHT, measured in canonical character units.
23677 5. `:relative-height FACTOR' specifies that the height of the
23678 stretch should be FACTOR times the height of the characters having
23679 the glyph property.
23681 Either none or exactly one of 4 or 5 must be present.
23683 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23684 of the stretch should be used for the ascent of the stretch.
23685 ASCENT must be in the range 0 <= ASCENT <= 100. */
23688 produce_stretch_glyph (struct it
*it
)
23690 /* (space :width WIDTH :height HEIGHT ...) */
23691 Lisp_Object prop
, plist
;
23692 int width
= 0, height
= 0, align_to
= -1;
23693 int zero_width_ok_p
= 0;
23696 struct face
*face
= NULL
;
23697 struct font
*font
= NULL
;
23699 #ifdef HAVE_WINDOW_SYSTEM
23700 int zero_height_ok_p
= 0;
23702 if (FRAME_WINDOW_P (it
->f
))
23704 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23705 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23706 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23710 /* List should start with `space'. */
23711 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23712 plist
= XCDR (it
->object
);
23714 /* Compute the width of the stretch. */
23715 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23716 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23718 /* Absolute width `:width WIDTH' specified and valid. */
23719 zero_width_ok_p
= 1;
23722 #ifdef HAVE_WINDOW_SYSTEM
23723 else if (FRAME_WINDOW_P (it
->f
)
23724 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23726 /* Relative width `:relative-width FACTOR' specified and valid.
23727 Compute the width of the characters having the `glyph'
23730 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23733 if (it
->multibyte_p
)
23734 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23737 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23738 if (! ASCII_CHAR_P (it2
.c
))
23739 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23742 it2
.glyph_row
= NULL
;
23743 it2
.what
= IT_CHARACTER
;
23744 x_produce_glyphs (&it2
);
23745 width
= NUMVAL (prop
) * it2
.pixel_width
;
23747 #endif /* HAVE_WINDOW_SYSTEM */
23748 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23749 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23751 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23752 align_to
= (align_to
< 0
23754 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23755 else if (align_to
< 0)
23756 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23757 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23758 zero_width_ok_p
= 1;
23761 /* Nothing specified -> width defaults to canonical char width. */
23762 width
= FRAME_COLUMN_WIDTH (it
->f
);
23764 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23767 #ifdef HAVE_WINDOW_SYSTEM
23768 /* Compute height. */
23769 if (FRAME_WINDOW_P (it
->f
))
23771 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23772 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23775 zero_height_ok_p
= 1;
23777 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23779 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23781 height
= FONT_HEIGHT (font
);
23783 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
23786 /* Compute percentage of height used for ascent. If
23787 `:ascent ASCENT' is present and valid, use that. Otherwise,
23788 derive the ascent from the font in use. */
23789 if (prop
= Fplist_get (plist
, QCascent
),
23790 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
23791 ascent
= height
* NUMVAL (prop
) / 100.0;
23792 else if (!NILP (prop
)
23793 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23794 ascent
= min (max (0, (int)tem
), height
);
23796 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
23799 #endif /* HAVE_WINDOW_SYSTEM */
23802 if (width
> 0 && it
->line_wrap
!= TRUNCATE
23803 && it
->current_x
+ width
> it
->last_visible_x
)
23805 width
= it
->last_visible_x
- it
->current_x
;
23806 #ifdef HAVE_WINDOW_SYSTEM
23807 /* Subtract one more pixel from the stretch width, but only on
23808 GUI frames, since on a TTY each glyph is one "pixel" wide. */
23809 width
-= FRAME_WINDOW_P (it
->f
);
23813 if (width
> 0 && height
> 0 && it
->glyph_row
)
23815 Lisp_Object o_object
= it
->object
;
23816 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
23819 if (!STRINGP (object
))
23820 object
= it
->w
->buffer
;
23821 #ifdef HAVE_WINDOW_SYSTEM
23822 if (FRAME_WINDOW_P (it
->f
))
23823 append_stretch_glyph (it
, object
, width
, height
, ascent
);
23827 it
->object
= object
;
23828 it
->char_to_display
= ' ';
23829 it
->pixel_width
= it
->len
= 1;
23831 tty_append_glyph (it
);
23832 it
->object
= o_object
;
23836 it
->pixel_width
= width
;
23837 #ifdef HAVE_WINDOW_SYSTEM
23838 if (FRAME_WINDOW_P (it
->f
))
23840 it
->ascent
= it
->phys_ascent
= ascent
;
23841 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
23842 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
23843 take_vertical_position_into_account (it
);
23847 it
->nglyphs
= width
;
23850 #ifdef HAVE_WINDOW_SYSTEM
23852 /* Calculate line-height and line-spacing properties.
23853 An integer value specifies explicit pixel value.
23854 A float value specifies relative value to current face height.
23855 A cons (float . face-name) specifies relative value to
23856 height of specified face font.
23858 Returns height in pixels, or nil. */
23862 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
23863 int boff
, int override
)
23865 Lisp_Object face_name
= Qnil
;
23866 int ascent
, descent
, height
;
23868 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
23873 face_name
= XCAR (val
);
23875 if (!NUMBERP (val
))
23876 val
= make_number (1);
23877 if (NILP (face_name
))
23879 height
= it
->ascent
+ it
->descent
;
23884 if (NILP (face_name
))
23886 font
= FRAME_FONT (it
->f
);
23887 boff
= FRAME_BASELINE_OFFSET (it
->f
);
23889 else if (EQ (face_name
, Qt
))
23898 face_id
= lookup_named_face (it
->f
, face_name
, 0);
23900 return make_number (-1);
23902 face
= FACE_FROM_ID (it
->f
, face_id
);
23905 return make_number (-1);
23906 boff
= font
->baseline_offset
;
23907 if (font
->vertical_centering
)
23908 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23911 ascent
= FONT_BASE (font
) + boff
;
23912 descent
= FONT_DESCENT (font
) - boff
;
23916 it
->override_ascent
= ascent
;
23917 it
->override_descent
= descent
;
23918 it
->override_boff
= boff
;
23921 height
= ascent
+ descent
;
23925 height
= (int)(XFLOAT_DATA (val
) * height
);
23926 else if (INTEGERP (val
))
23927 height
*= XINT (val
);
23929 return make_number (height
);
23933 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
23934 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
23935 and only if this is for a character for which no font was found.
23937 If the display method (it->glyphless_method) is
23938 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
23939 length of the acronym or the hexadecimal string, UPPER_XOFF and
23940 UPPER_YOFF are pixel offsets for the upper part of the string,
23941 LOWER_XOFF and LOWER_YOFF are for the lower part.
23943 For the other display methods, LEN through LOWER_YOFF are zero. */
23946 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
23947 short upper_xoff
, short upper_yoff
,
23948 short lower_xoff
, short lower_yoff
)
23950 struct glyph
*glyph
;
23951 enum glyph_row_area area
= it
->area
;
23953 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23954 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23956 /* If the glyph row is reversed, we need to prepend the glyph
23957 rather than append it. */
23958 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23962 /* Make room for the additional glyph. */
23963 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23965 glyph
= it
->glyph_row
->glyphs
[area
];
23967 glyph
->charpos
= CHARPOS (it
->position
);
23968 glyph
->object
= it
->object
;
23969 glyph
->pixel_width
= it
->pixel_width
;
23970 glyph
->ascent
= it
->ascent
;
23971 glyph
->descent
= it
->descent
;
23972 glyph
->voffset
= it
->voffset
;
23973 glyph
->type
= GLYPHLESS_GLYPH
;
23974 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
23975 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
23976 glyph
->u
.glyphless
.len
= len
;
23977 glyph
->u
.glyphless
.ch
= it
->c
;
23978 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
23979 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
23980 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
23981 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
23982 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23983 glyph
->multibyte_p
= it
->multibyte_p
;
23984 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23985 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23986 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23987 || it
->phys_descent
> it
->descent
);
23988 glyph
->padding_p
= 0;
23989 glyph
->glyph_not_available_p
= 0;
23990 glyph
->face_id
= face_id
;
23991 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23994 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23995 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23997 glyph
->bidi_type
= it
->bidi_it
.type
;
23999 ++it
->glyph_row
->used
[area
];
24002 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24006 /* Produce a glyph for a glyphless character for iterator IT.
24007 IT->glyphless_method specifies which method to use for displaying
24008 the character. See the description of enum
24009 glyphless_display_method in dispextern.h for the detail.
24011 FOR_NO_FONT is nonzero if and only if this is for a character for
24012 which no font was found. ACRONYM, if non-nil, is an acronym string
24013 for the character. */
24016 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24021 int base_width
, base_height
, width
, height
;
24022 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24025 /* Get the metrics of the base font. We always refer to the current
24027 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24028 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24029 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24030 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24031 base_height
= it
->ascent
+ it
->descent
;
24032 base_width
= font
->average_width
;
24034 /* Get a face ID for the glyph by utilizing a cache (the same way as
24035 done for `escape-glyph' in get_next_display_element). */
24036 if (it
->f
== last_glyphless_glyph_frame
24037 && it
->face_id
== last_glyphless_glyph_face_id
)
24039 face_id
= last_glyphless_glyph_merged_face_id
;
24043 /* Merge the `glyphless-char' face into the current face. */
24044 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24045 last_glyphless_glyph_frame
= it
->f
;
24046 last_glyphless_glyph_face_id
= it
->face_id
;
24047 last_glyphless_glyph_merged_face_id
= face_id
;
24050 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24052 it
->pixel_width
= THIN_SPACE_WIDTH
;
24054 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24056 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24058 width
= CHAR_WIDTH (it
->c
);
24061 else if (width
> 4)
24063 it
->pixel_width
= base_width
* width
;
24065 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24071 unsigned int code
[6];
24073 int ascent
, descent
;
24074 struct font_metrics metrics_upper
, metrics_lower
;
24076 face
= FACE_FROM_ID (it
->f
, face_id
);
24077 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24078 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24080 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24082 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24083 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24084 if (CONSP (acronym
))
24085 acronym
= XCAR (acronym
);
24086 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24090 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24091 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24094 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24095 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24096 upper_len
= (len
+ 1) / 2;
24097 font
->driver
->text_extents (font
, code
, upper_len
,
24099 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24104 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24105 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24106 upper_xoff
= upper_yoff
= 2; /* the typical case */
24107 if (base_width
>= width
)
24109 /* Align the upper to the left, the lower to the right. */
24110 it
->pixel_width
= base_width
;
24111 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24115 /* Center the shorter one. */
24116 it
->pixel_width
= width
;
24117 if (metrics_upper
.width
>= metrics_lower
.width
)
24118 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24121 /* FIXME: This code doesn't look right. It formerly was
24122 missing the "lower_xoff = 0;", which couldn't have
24123 been right since it left lower_xoff uninitialized. */
24125 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24129 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24130 top, bottom, and between upper and lower strings. */
24131 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24132 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24133 /* Center vertically.
24134 H:base_height, D:base_descent
24135 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24137 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24138 descent = D - H/2 + h/2;
24139 lower_yoff = descent - 2 - ld;
24140 upper_yoff = lower_yoff - la - 1 - ud; */
24141 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24142 descent
= it
->descent
- (base_height
- height
) / 2;
24143 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24144 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24145 - metrics_upper
.descent
);
24146 /* Don't make the height shorter than the base height. */
24147 if (height
> base_height
)
24149 it
->ascent
= ascent
;
24150 it
->descent
= descent
;
24154 it
->phys_ascent
= it
->ascent
;
24155 it
->phys_descent
= it
->descent
;
24157 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24158 upper_xoff
, upper_yoff
,
24159 lower_xoff
, lower_yoff
);
24161 take_vertical_position_into_account (it
);
24166 Produce glyphs/get display metrics for the display element IT is
24167 loaded with. See the description of struct it in dispextern.h
24168 for an overview of struct it. */
24171 x_produce_glyphs (struct it
*it
)
24173 int extra_line_spacing
= it
->extra_line_spacing
;
24175 it
->glyph_not_available_p
= 0;
24177 if (it
->what
== IT_CHARACTER
)
24180 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24181 struct font
*font
= face
->font
;
24182 struct font_metrics
*pcm
= NULL
;
24183 int boff
; /* baseline offset */
24187 /* When no suitable font is found, display this character by
24188 the method specified in the first extra slot of
24189 Vglyphless_char_display. */
24190 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24192 xassert (it
->what
== IT_GLYPHLESS
);
24193 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24197 boff
= font
->baseline_offset
;
24198 if (font
->vertical_centering
)
24199 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24201 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24207 if (it
->override_ascent
>= 0)
24209 it
->ascent
= it
->override_ascent
;
24210 it
->descent
= it
->override_descent
;
24211 boff
= it
->override_boff
;
24215 it
->ascent
= FONT_BASE (font
) + boff
;
24216 it
->descent
= FONT_DESCENT (font
) - boff
;
24219 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24221 pcm
= get_per_char_metric (font
, &char2b
);
24222 if (pcm
->width
== 0
24223 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24229 it
->phys_ascent
= pcm
->ascent
+ boff
;
24230 it
->phys_descent
= pcm
->descent
- boff
;
24231 it
->pixel_width
= pcm
->width
;
24235 it
->glyph_not_available_p
= 1;
24236 it
->phys_ascent
= it
->ascent
;
24237 it
->phys_descent
= it
->descent
;
24238 it
->pixel_width
= font
->space_width
;
24241 if (it
->constrain_row_ascent_descent_p
)
24243 if (it
->descent
> it
->max_descent
)
24245 it
->ascent
+= it
->descent
- it
->max_descent
;
24246 it
->descent
= it
->max_descent
;
24248 if (it
->ascent
> it
->max_ascent
)
24250 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24251 it
->ascent
= it
->max_ascent
;
24253 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24254 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24255 extra_line_spacing
= 0;
24258 /* If this is a space inside a region of text with
24259 `space-width' property, change its width. */
24260 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24262 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24264 /* If face has a box, add the box thickness to the character
24265 height. If character has a box line to the left and/or
24266 right, add the box line width to the character's width. */
24267 if (face
->box
!= FACE_NO_BOX
)
24269 int thick
= face
->box_line_width
;
24273 it
->ascent
+= thick
;
24274 it
->descent
+= thick
;
24279 if (it
->start_of_box_run_p
)
24280 it
->pixel_width
+= thick
;
24281 if (it
->end_of_box_run_p
)
24282 it
->pixel_width
+= thick
;
24285 /* If face has an overline, add the height of the overline
24286 (1 pixel) and a 1 pixel margin to the character height. */
24287 if (face
->overline_p
)
24288 it
->ascent
+= overline_margin
;
24290 if (it
->constrain_row_ascent_descent_p
)
24292 if (it
->ascent
> it
->max_ascent
)
24293 it
->ascent
= it
->max_ascent
;
24294 if (it
->descent
> it
->max_descent
)
24295 it
->descent
= it
->max_descent
;
24298 take_vertical_position_into_account (it
);
24300 /* If we have to actually produce glyphs, do it. */
24305 /* Translate a space with a `space-width' property
24306 into a stretch glyph. */
24307 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24308 / FONT_HEIGHT (font
));
24309 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24310 it
->ascent
+ it
->descent
, ascent
);
24315 /* If characters with lbearing or rbearing are displayed
24316 in this line, record that fact in a flag of the
24317 glyph row. This is used to optimize X output code. */
24318 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24319 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24321 if (! stretched_p
&& it
->pixel_width
== 0)
24322 /* We assure that all visible glyphs have at least 1-pixel
24324 it
->pixel_width
= 1;
24326 else if (it
->char_to_display
== '\n')
24328 /* A newline has no width, but we need the height of the
24329 line. But if previous part of the line sets a height,
24330 don't increase that height */
24332 Lisp_Object height
;
24333 Lisp_Object total_height
= Qnil
;
24335 it
->override_ascent
= -1;
24336 it
->pixel_width
= 0;
24339 height
= get_it_property (it
, Qline_height
);
24340 /* Split (line-height total-height) list */
24342 && CONSP (XCDR (height
))
24343 && NILP (XCDR (XCDR (height
))))
24345 total_height
= XCAR (XCDR (height
));
24346 height
= XCAR (height
);
24348 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24350 if (it
->override_ascent
>= 0)
24352 it
->ascent
= it
->override_ascent
;
24353 it
->descent
= it
->override_descent
;
24354 boff
= it
->override_boff
;
24358 it
->ascent
= FONT_BASE (font
) + boff
;
24359 it
->descent
= FONT_DESCENT (font
) - boff
;
24362 if (EQ (height
, Qt
))
24364 if (it
->descent
> it
->max_descent
)
24366 it
->ascent
+= it
->descent
- it
->max_descent
;
24367 it
->descent
= it
->max_descent
;
24369 if (it
->ascent
> it
->max_ascent
)
24371 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24372 it
->ascent
= it
->max_ascent
;
24374 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24375 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24376 it
->constrain_row_ascent_descent_p
= 1;
24377 extra_line_spacing
= 0;
24381 Lisp_Object spacing
;
24383 it
->phys_ascent
= it
->ascent
;
24384 it
->phys_descent
= it
->descent
;
24386 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24387 && face
->box
!= FACE_NO_BOX
24388 && face
->box_line_width
> 0)
24390 it
->ascent
+= face
->box_line_width
;
24391 it
->descent
+= face
->box_line_width
;
24394 && XINT (height
) > it
->ascent
+ it
->descent
)
24395 it
->ascent
= XINT (height
) - it
->descent
;
24397 if (!NILP (total_height
))
24398 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24401 spacing
= get_it_property (it
, Qline_spacing
);
24402 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24404 if (INTEGERP (spacing
))
24406 extra_line_spacing
= XINT (spacing
);
24407 if (!NILP (total_height
))
24408 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24412 else /* i.e. (it->char_to_display == '\t') */
24414 if (font
->space_width
> 0)
24416 int tab_width
= it
->tab_width
* font
->space_width
;
24417 int x
= it
->current_x
+ it
->continuation_lines_width
;
24418 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24420 /* If the distance from the current position to the next tab
24421 stop is less than a space character width, use the
24422 tab stop after that. */
24423 if (next_tab_x
- x
< font
->space_width
)
24424 next_tab_x
+= tab_width
;
24426 it
->pixel_width
= next_tab_x
- x
;
24428 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24429 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24433 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24434 it
->ascent
+ it
->descent
, it
->ascent
);
24439 it
->pixel_width
= 0;
24444 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24446 /* A static composition.
24448 Note: A composition is represented as one glyph in the
24449 glyph matrix. There are no padding glyphs.
24451 Important note: pixel_width, ascent, and descent are the
24452 values of what is drawn by draw_glyphs (i.e. the values of
24453 the overall glyphs composed). */
24454 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24455 int boff
; /* baseline offset */
24456 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24457 int glyph_len
= cmp
->glyph_len
;
24458 struct font
*font
= face
->font
;
24462 /* If we have not yet calculated pixel size data of glyphs of
24463 the composition for the current face font, calculate them
24464 now. Theoretically, we have to check all fonts for the
24465 glyphs, but that requires much time and memory space. So,
24466 here we check only the font of the first glyph. This may
24467 lead to incorrect display, but it's very rare, and C-l
24468 (recenter-top-bottom) can correct the display anyway. */
24469 if (! cmp
->font
|| cmp
->font
!= font
)
24471 /* Ascent and descent of the font of the first character
24472 of this composition (adjusted by baseline offset).
24473 Ascent and descent of overall glyphs should not be less
24474 than these, respectively. */
24475 int font_ascent
, font_descent
, font_height
;
24476 /* Bounding box of the overall glyphs. */
24477 int leftmost
, rightmost
, lowest
, highest
;
24478 int lbearing
, rbearing
;
24479 int i
, width
, ascent
, descent
;
24480 int left_padded
= 0, right_padded
= 0;
24481 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24483 struct font_metrics
*pcm
;
24484 int font_not_found_p
;
24487 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24488 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24490 if (glyph_len
< cmp
->glyph_len
)
24492 for (i
= 0; i
< glyph_len
; i
++)
24494 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24496 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24501 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24502 : IT_CHARPOS (*it
));
24503 /* If no suitable font is found, use the default font. */
24504 font_not_found_p
= font
== NULL
;
24505 if (font_not_found_p
)
24507 face
= face
->ascii_face
;
24510 boff
= font
->baseline_offset
;
24511 if (font
->vertical_centering
)
24512 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24513 font_ascent
= FONT_BASE (font
) + boff
;
24514 font_descent
= FONT_DESCENT (font
) - boff
;
24515 font_height
= FONT_HEIGHT (font
);
24517 cmp
->font
= (void *) font
;
24520 if (! font_not_found_p
)
24522 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24524 pcm
= get_per_char_metric (font
, &char2b
);
24527 /* Initialize the bounding box. */
24530 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24531 ascent
= pcm
->ascent
;
24532 descent
= pcm
->descent
;
24533 lbearing
= pcm
->lbearing
;
24534 rbearing
= pcm
->rbearing
;
24538 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24539 ascent
= FONT_BASE (font
);
24540 descent
= FONT_DESCENT (font
);
24547 lowest
= - descent
+ boff
;
24548 highest
= ascent
+ boff
;
24550 if (! font_not_found_p
24551 && font
->default_ascent
24552 && CHAR_TABLE_P (Vuse_default_ascent
)
24553 && !NILP (Faref (Vuse_default_ascent
,
24554 make_number (it
->char_to_display
))))
24555 highest
= font
->default_ascent
+ boff
;
24557 /* Draw the first glyph at the normal position. It may be
24558 shifted to right later if some other glyphs are drawn
24560 cmp
->offsets
[i
* 2] = 0;
24561 cmp
->offsets
[i
* 2 + 1] = boff
;
24562 cmp
->lbearing
= lbearing
;
24563 cmp
->rbearing
= rbearing
;
24565 /* Set cmp->offsets for the remaining glyphs. */
24566 for (i
++; i
< glyph_len
; i
++)
24568 int left
, right
, btm
, top
;
24569 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24571 struct face
*this_face
;
24575 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24576 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24577 font
= this_face
->font
;
24583 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24585 pcm
= get_per_char_metric (font
, &char2b
);
24588 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24591 width
= pcm
->width
;
24592 ascent
= pcm
->ascent
;
24593 descent
= pcm
->descent
;
24594 lbearing
= pcm
->lbearing
;
24595 rbearing
= pcm
->rbearing
;
24596 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24598 /* Relative composition with or without
24599 alternate chars. */
24600 left
= (leftmost
+ rightmost
- width
) / 2;
24601 btm
= - descent
+ boff
;
24602 if (font
->relative_compose
24603 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24604 || NILP (Faref (Vignore_relative_composition
,
24605 make_number (ch
)))))
24608 if (- descent
>= font
->relative_compose
)
24609 /* One extra pixel between two glyphs. */
24611 else if (ascent
<= 0)
24612 /* One extra pixel between two glyphs. */
24613 btm
= lowest
- 1 - ascent
- descent
;
24618 /* A composition rule is specified by an integer
24619 value that encodes global and new reference
24620 points (GREF and NREF). GREF and NREF are
24621 specified by numbers as below:
24623 0---1---2 -- ascent
24627 9--10--11 -- center
24629 ---3---4---5--- baseline
24631 6---7---8 -- descent
24633 int rule
= COMPOSITION_RULE (cmp
, i
);
24634 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24636 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24637 grefx
= gref
% 3, nrefx
= nref
% 3;
24638 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24640 xoff
= font_height
* (xoff
- 128) / 256;
24642 yoff
= font_height
* (yoff
- 128) / 256;
24645 + grefx
* (rightmost
- leftmost
) / 2
24646 - nrefx
* width
/ 2
24649 btm
= ((grefy
== 0 ? highest
24651 : grefy
== 2 ? lowest
24652 : (highest
+ lowest
) / 2)
24653 - (nrefy
== 0 ? ascent
+ descent
24654 : nrefy
== 1 ? descent
- boff
24656 : (ascent
+ descent
) / 2)
24660 cmp
->offsets
[i
* 2] = left
;
24661 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24663 /* Update the bounding box of the overall glyphs. */
24666 right
= left
+ width
;
24667 if (left
< leftmost
)
24669 if (right
> rightmost
)
24672 top
= btm
+ descent
+ ascent
;
24678 if (cmp
->lbearing
> left
+ lbearing
)
24679 cmp
->lbearing
= left
+ lbearing
;
24680 if (cmp
->rbearing
< left
+ rbearing
)
24681 cmp
->rbearing
= left
+ rbearing
;
24685 /* If there are glyphs whose x-offsets are negative,
24686 shift all glyphs to the right and make all x-offsets
24690 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24691 cmp
->offsets
[i
* 2] -= leftmost
;
24692 rightmost
-= leftmost
;
24693 cmp
->lbearing
-= leftmost
;
24694 cmp
->rbearing
-= leftmost
;
24697 if (left_padded
&& cmp
->lbearing
< 0)
24699 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24700 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24701 rightmost
-= cmp
->lbearing
;
24702 cmp
->rbearing
-= cmp
->lbearing
;
24705 if (right_padded
&& rightmost
< cmp
->rbearing
)
24707 rightmost
= cmp
->rbearing
;
24710 cmp
->pixel_width
= rightmost
;
24711 cmp
->ascent
= highest
;
24712 cmp
->descent
= - lowest
;
24713 if (cmp
->ascent
< font_ascent
)
24714 cmp
->ascent
= font_ascent
;
24715 if (cmp
->descent
< font_descent
)
24716 cmp
->descent
= font_descent
;
24720 && (cmp
->lbearing
< 0
24721 || cmp
->rbearing
> cmp
->pixel_width
))
24722 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24724 it
->pixel_width
= cmp
->pixel_width
;
24725 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24726 it
->descent
= it
->phys_descent
= cmp
->descent
;
24727 if (face
->box
!= FACE_NO_BOX
)
24729 int thick
= face
->box_line_width
;
24733 it
->ascent
+= thick
;
24734 it
->descent
+= thick
;
24739 if (it
->start_of_box_run_p
)
24740 it
->pixel_width
+= thick
;
24741 if (it
->end_of_box_run_p
)
24742 it
->pixel_width
+= thick
;
24745 /* If face has an overline, add the height of the overline
24746 (1 pixel) and a 1 pixel margin to the character height. */
24747 if (face
->overline_p
)
24748 it
->ascent
+= overline_margin
;
24750 take_vertical_position_into_account (it
);
24751 if (it
->ascent
< 0)
24753 if (it
->descent
< 0)
24756 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24757 append_composite_glyph (it
);
24759 else if (it
->what
== IT_COMPOSITION
)
24761 /* A dynamic (automatic) composition. */
24762 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24763 Lisp_Object gstring
;
24764 struct font_metrics metrics
;
24768 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24770 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24773 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24774 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24775 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24776 it
->descent
= it
->phys_descent
= metrics
.descent
;
24777 if (face
->box
!= FACE_NO_BOX
)
24779 int thick
= face
->box_line_width
;
24783 it
->ascent
+= thick
;
24784 it
->descent
+= thick
;
24789 if (it
->start_of_box_run_p
)
24790 it
->pixel_width
+= thick
;
24791 if (it
->end_of_box_run_p
)
24792 it
->pixel_width
+= thick
;
24794 /* If face has an overline, add the height of the overline
24795 (1 pixel) and a 1 pixel margin to the character height. */
24796 if (face
->overline_p
)
24797 it
->ascent
+= overline_margin
;
24798 take_vertical_position_into_account (it
);
24799 if (it
->ascent
< 0)
24801 if (it
->descent
< 0)
24805 append_composite_glyph (it
);
24807 else if (it
->what
== IT_GLYPHLESS
)
24808 produce_glyphless_glyph (it
, 0, Qnil
);
24809 else if (it
->what
== IT_IMAGE
)
24810 produce_image_glyph (it
);
24811 else if (it
->what
== IT_STRETCH
)
24812 produce_stretch_glyph (it
);
24815 /* Accumulate dimensions. Note: can't assume that it->descent > 0
24816 because this isn't true for images with `:ascent 100'. */
24817 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
24818 if (it
->area
== TEXT_AREA
)
24819 it
->current_x
+= it
->pixel_width
;
24821 if (extra_line_spacing
> 0)
24823 it
->descent
+= extra_line_spacing
;
24824 if (extra_line_spacing
> it
->max_extra_line_spacing
)
24825 it
->max_extra_line_spacing
= extra_line_spacing
;
24828 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
24829 it
->max_descent
= max (it
->max_descent
, it
->descent
);
24830 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
24831 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
24835 Output LEN glyphs starting at START at the nominal cursor position.
24836 Advance the nominal cursor over the text. The global variable
24837 updated_window contains the window being updated, updated_row is
24838 the glyph row being updated, and updated_area is the area of that
24839 row being updated. */
24842 x_write_glyphs (struct glyph
*start
, int len
)
24844 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
24846 xassert (updated_window
&& updated_row
);
24847 /* When the window is hscrolled, cursor hpos can legitimately be out
24848 of bounds, but we draw the cursor at the corresponding window
24849 margin in that case. */
24850 if (!updated_row
->reversed_p
&& chpos
< 0)
24852 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
24853 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
24857 /* Write glyphs. */
24859 hpos
= start
- updated_row
->glyphs
[updated_area
];
24860 x
= draw_glyphs (updated_window
, output_cursor
.x
,
24861 updated_row
, updated_area
,
24863 DRAW_NORMAL_TEXT
, 0);
24865 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
24866 if (updated_area
== TEXT_AREA
24867 && updated_window
->phys_cursor_on_p
24868 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
24870 && chpos
< hpos
+ len
)
24871 updated_window
->phys_cursor_on_p
= 0;
24875 /* Advance the output cursor. */
24876 output_cursor
.hpos
+= len
;
24877 output_cursor
.x
= x
;
24882 Insert LEN glyphs from START at the nominal cursor position. */
24885 x_insert_glyphs (struct glyph
*start
, int len
)
24889 int line_height
, shift_by_width
, shifted_region_width
;
24890 struct glyph_row
*row
;
24891 struct glyph
*glyph
;
24892 int frame_x
, frame_y
;
24895 xassert (updated_window
&& updated_row
);
24897 w
= updated_window
;
24898 f
= XFRAME (WINDOW_FRAME (w
));
24900 /* Get the height of the line we are in. */
24902 line_height
= row
->height
;
24904 /* Get the width of the glyphs to insert. */
24905 shift_by_width
= 0;
24906 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
24907 shift_by_width
+= glyph
->pixel_width
;
24909 /* Get the width of the region to shift right. */
24910 shifted_region_width
= (window_box_width (w
, updated_area
)
24915 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
24916 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
24918 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
24919 line_height
, shift_by_width
);
24921 /* Write the glyphs. */
24922 hpos
= start
- row
->glyphs
[updated_area
];
24923 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
24925 DRAW_NORMAL_TEXT
, 0);
24927 /* Advance the output cursor. */
24928 output_cursor
.hpos
+= len
;
24929 output_cursor
.x
+= shift_by_width
;
24935 Erase the current text line from the nominal cursor position
24936 (inclusive) to pixel column TO_X (exclusive). The idea is that
24937 everything from TO_X onward is already erased.
24939 TO_X is a pixel position relative to updated_area of
24940 updated_window. TO_X == -1 means clear to the end of this area. */
24943 x_clear_end_of_line (int to_x
)
24946 struct window
*w
= updated_window
;
24947 int max_x
, min_y
, max_y
;
24948 int from_x
, from_y
, to_y
;
24950 xassert (updated_window
&& updated_row
);
24951 f
= XFRAME (w
->frame
);
24953 if (updated_row
->full_width_p
)
24954 max_x
= WINDOW_TOTAL_WIDTH (w
);
24956 max_x
= window_box_width (w
, updated_area
);
24957 max_y
= window_text_bottom_y (w
);
24959 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
24960 of window. For TO_X > 0, truncate to end of drawing area. */
24966 to_x
= min (to_x
, max_x
);
24968 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
24970 /* Notice if the cursor will be cleared by this operation. */
24971 if (!updated_row
->full_width_p
)
24972 notice_overwritten_cursor (w
, updated_area
,
24973 output_cursor
.x
, -1,
24975 MATRIX_ROW_BOTTOM_Y (updated_row
));
24977 from_x
= output_cursor
.x
;
24979 /* Translate to frame coordinates. */
24980 if (updated_row
->full_width_p
)
24982 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
24983 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
24987 int area_left
= window_box_left (w
, updated_area
);
24988 from_x
+= area_left
;
24992 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
24993 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
24994 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
24996 /* Prevent inadvertently clearing to end of the X window. */
24997 if (to_x
> from_x
&& to_y
> from_y
)
25000 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25001 to_x
- from_x
, to_y
- from_y
);
25006 #endif /* HAVE_WINDOW_SYSTEM */
25010 /***********************************************************************
25012 ***********************************************************************/
25014 /* Value is the internal representation of the specified cursor type
25015 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25016 of the bar cursor. */
25018 static enum text_cursor_kinds
25019 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25021 enum text_cursor_kinds type
;
25026 if (EQ (arg
, Qbox
))
25027 return FILLED_BOX_CURSOR
;
25029 if (EQ (arg
, Qhollow
))
25030 return HOLLOW_BOX_CURSOR
;
25032 if (EQ (arg
, Qbar
))
25039 && EQ (XCAR (arg
), Qbar
)
25040 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25042 *width
= XINT (XCDR (arg
));
25046 if (EQ (arg
, Qhbar
))
25049 return HBAR_CURSOR
;
25053 && EQ (XCAR (arg
), Qhbar
)
25054 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25056 *width
= XINT (XCDR (arg
));
25057 return HBAR_CURSOR
;
25060 /* Treat anything unknown as "hollow box cursor".
25061 It was bad to signal an error; people have trouble fixing
25062 .Xdefaults with Emacs, when it has something bad in it. */
25063 type
= HOLLOW_BOX_CURSOR
;
25068 /* Set the default cursor types for specified frame. */
25070 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25075 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25076 FRAME_CURSOR_WIDTH (f
) = width
;
25078 /* By default, set up the blink-off state depending on the on-state. */
25080 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25083 FRAME_BLINK_OFF_CURSOR (f
)
25084 = get_specified_cursor_type (XCDR (tem
), &width
);
25085 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25088 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25092 #ifdef HAVE_WINDOW_SYSTEM
25094 /* Return the cursor we want to be displayed in window W. Return
25095 width of bar/hbar cursor through WIDTH arg. Return with
25096 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25097 (i.e. if the `system caret' should track this cursor).
25099 In a mini-buffer window, we want the cursor only to appear if we
25100 are reading input from this window. For the selected window, we
25101 want the cursor type given by the frame parameter or buffer local
25102 setting of cursor-type. If explicitly marked off, draw no cursor.
25103 In all other cases, we want a hollow box cursor. */
25105 static enum text_cursor_kinds
25106 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25107 int *active_cursor
)
25109 struct frame
*f
= XFRAME (w
->frame
);
25110 struct buffer
*b
= XBUFFER (w
->buffer
);
25111 int cursor_type
= DEFAULT_CURSOR
;
25112 Lisp_Object alt_cursor
;
25113 int non_selected
= 0;
25115 *active_cursor
= 1;
25118 if (cursor_in_echo_area
25119 && FRAME_HAS_MINIBUF_P (f
)
25120 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25122 if (w
== XWINDOW (echo_area_window
))
25124 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25126 *width
= FRAME_CURSOR_WIDTH (f
);
25127 return FRAME_DESIRED_CURSOR (f
);
25130 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25133 *active_cursor
= 0;
25137 /* Detect a nonselected window or nonselected frame. */
25138 else if (w
!= XWINDOW (f
->selected_window
)
25139 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25141 *active_cursor
= 0;
25143 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25149 /* Never display a cursor in a window in which cursor-type is nil. */
25150 if (NILP (BVAR (b
, cursor_type
)))
25153 /* Get the normal cursor type for this window. */
25154 if (EQ (BVAR (b
, cursor_type
), Qt
))
25156 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25157 *width
= FRAME_CURSOR_WIDTH (f
);
25160 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25162 /* Use cursor-in-non-selected-windows instead
25163 for non-selected window or frame. */
25166 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25167 if (!EQ (Qt
, alt_cursor
))
25168 return get_specified_cursor_type (alt_cursor
, width
);
25169 /* t means modify the normal cursor type. */
25170 if (cursor_type
== FILLED_BOX_CURSOR
)
25171 cursor_type
= HOLLOW_BOX_CURSOR
;
25172 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25174 return cursor_type
;
25177 /* Use normal cursor if not blinked off. */
25178 if (!w
->cursor_off_p
)
25180 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25182 if (cursor_type
== FILLED_BOX_CURSOR
)
25184 /* Using a block cursor on large images can be very annoying.
25185 So use a hollow cursor for "large" images.
25186 If image is not transparent (no mask), also use hollow cursor. */
25187 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25188 if (img
!= NULL
&& IMAGEP (img
->spec
))
25190 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25191 where N = size of default frame font size.
25192 This should cover most of the "tiny" icons people may use. */
25194 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25195 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25196 cursor_type
= HOLLOW_BOX_CURSOR
;
25199 else if (cursor_type
!= NO_CURSOR
)
25201 /* Display current only supports BOX and HOLLOW cursors for images.
25202 So for now, unconditionally use a HOLLOW cursor when cursor is
25203 not a solid box cursor. */
25204 cursor_type
= HOLLOW_BOX_CURSOR
;
25207 return cursor_type
;
25210 /* Cursor is blinked off, so determine how to "toggle" it. */
25212 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25213 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25214 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25216 /* Then see if frame has specified a specific blink off cursor type. */
25217 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25219 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25220 return FRAME_BLINK_OFF_CURSOR (f
);
25224 /* Some people liked having a permanently visible blinking cursor,
25225 while others had very strong opinions against it. So it was
25226 decided to remove it. KFS 2003-09-03 */
25228 /* Finally perform built-in cursor blinking:
25229 filled box <-> hollow box
25230 wide [h]bar <-> narrow [h]bar
25231 narrow [h]bar <-> no cursor
25232 other type <-> no cursor */
25234 if (cursor_type
== FILLED_BOX_CURSOR
)
25235 return HOLLOW_BOX_CURSOR
;
25237 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25240 return cursor_type
;
25248 /* Notice when the text cursor of window W has been completely
25249 overwritten by a drawing operation that outputs glyphs in AREA
25250 starting at X0 and ending at X1 in the line starting at Y0 and
25251 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25252 the rest of the line after X0 has been written. Y coordinates
25253 are window-relative. */
25256 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25257 int x0
, int x1
, int y0
, int y1
)
25259 int cx0
, cx1
, cy0
, cy1
;
25260 struct glyph_row
*row
;
25262 if (!w
->phys_cursor_on_p
)
25264 if (area
!= TEXT_AREA
)
25267 if (w
->phys_cursor
.vpos
< 0
25268 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25269 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25270 !(row
->enabled_p
&& row
->displays_text_p
)))
25273 if (row
->cursor_in_fringe_p
)
25275 row
->cursor_in_fringe_p
= 0;
25276 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25277 w
->phys_cursor_on_p
= 0;
25281 cx0
= w
->phys_cursor
.x
;
25282 cx1
= cx0
+ w
->phys_cursor_width
;
25283 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25286 /* The cursor image will be completely removed from the
25287 screen if the output area intersects the cursor area in
25288 y-direction. When we draw in [y0 y1[, and some part of
25289 the cursor is at y < y0, that part must have been drawn
25290 before. When scrolling, the cursor is erased before
25291 actually scrolling, so we don't come here. When not
25292 scrolling, the rows above the old cursor row must have
25293 changed, and in this case these rows must have written
25294 over the cursor image.
25296 Likewise if part of the cursor is below y1, with the
25297 exception of the cursor being in the first blank row at
25298 the buffer and window end because update_text_area
25299 doesn't draw that row. (Except when it does, but
25300 that's handled in update_text_area.) */
25302 cy0
= w
->phys_cursor
.y
;
25303 cy1
= cy0
+ w
->phys_cursor_height
;
25304 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25307 w
->phys_cursor_on_p
= 0;
25310 #endif /* HAVE_WINDOW_SYSTEM */
25313 /************************************************************************
25315 ************************************************************************/
25317 #ifdef HAVE_WINDOW_SYSTEM
25320 Fix the display of area AREA of overlapping row ROW in window W
25321 with respect to the overlapping part OVERLAPS. */
25324 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25325 enum glyph_row_area area
, int overlaps
)
25332 for (i
= 0; i
< row
->used
[area
];)
25334 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25336 int start
= i
, start_x
= x
;
25340 x
+= row
->glyphs
[area
][i
].pixel_width
;
25343 while (i
< row
->used
[area
]
25344 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25346 draw_glyphs (w
, start_x
, row
, area
,
25348 DRAW_NORMAL_TEXT
, overlaps
);
25352 x
+= row
->glyphs
[area
][i
].pixel_width
;
25362 Draw the cursor glyph of window W in glyph row ROW. See the
25363 comment of draw_glyphs for the meaning of HL. */
25366 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25367 enum draw_glyphs_face hl
)
25369 /* If cursor hpos is out of bounds, don't draw garbage. This can
25370 happen in mini-buffer windows when switching between echo area
25371 glyphs and mini-buffer. */
25372 if ((row
->reversed_p
25373 ? (w
->phys_cursor
.hpos
>= 0)
25374 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25376 int on_p
= w
->phys_cursor_on_p
;
25378 int hpos
= w
->phys_cursor
.hpos
;
25380 /* When the window is hscrolled, cursor hpos can legitimately be
25381 out of bounds, but we draw the cursor at the corresponding
25382 window margin in that case. */
25383 if (!row
->reversed_p
&& hpos
< 0)
25385 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25386 hpos
= row
->used
[TEXT_AREA
] - 1;
25388 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25390 w
->phys_cursor_on_p
= on_p
;
25392 if (hl
== DRAW_CURSOR
)
25393 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25394 /* When we erase the cursor, and ROW is overlapped by other
25395 rows, make sure that these overlapping parts of other rows
25397 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25399 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25401 if (row
> w
->current_matrix
->rows
25402 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25403 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25404 OVERLAPS_ERASED_CURSOR
);
25406 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25407 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25408 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25409 OVERLAPS_ERASED_CURSOR
);
25416 Erase the image of a cursor of window W from the screen. */
25419 erase_phys_cursor (struct window
*w
)
25421 struct frame
*f
= XFRAME (w
->frame
);
25422 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25423 int hpos
= w
->phys_cursor
.hpos
;
25424 int vpos
= w
->phys_cursor
.vpos
;
25425 int mouse_face_here_p
= 0;
25426 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25427 struct glyph_row
*cursor_row
;
25428 struct glyph
*cursor_glyph
;
25429 enum draw_glyphs_face hl
;
25431 /* No cursor displayed or row invalidated => nothing to do on the
25433 if (w
->phys_cursor_type
== NO_CURSOR
)
25434 goto mark_cursor_off
;
25436 /* VPOS >= active_glyphs->nrows means that window has been resized.
25437 Don't bother to erase the cursor. */
25438 if (vpos
>= active_glyphs
->nrows
)
25439 goto mark_cursor_off
;
25441 /* If row containing cursor is marked invalid, there is nothing we
25443 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25444 if (!cursor_row
->enabled_p
)
25445 goto mark_cursor_off
;
25447 /* If line spacing is > 0, old cursor may only be partially visible in
25448 window after split-window. So adjust visible height. */
25449 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25450 window_text_bottom_y (w
) - cursor_row
->y
);
25452 /* If row is completely invisible, don't attempt to delete a cursor which
25453 isn't there. This can happen if cursor is at top of a window, and
25454 we switch to a buffer with a header line in that window. */
25455 if (cursor_row
->visible_height
<= 0)
25456 goto mark_cursor_off
;
25458 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25459 if (cursor_row
->cursor_in_fringe_p
)
25461 cursor_row
->cursor_in_fringe_p
= 0;
25462 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25463 goto mark_cursor_off
;
25466 /* This can happen when the new row is shorter than the old one.
25467 In this case, either draw_glyphs or clear_end_of_line
25468 should have cleared the cursor. Note that we wouldn't be
25469 able to erase the cursor in this case because we don't have a
25470 cursor glyph at hand. */
25471 if ((cursor_row
->reversed_p
25472 ? (w
->phys_cursor
.hpos
< 0)
25473 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25474 goto mark_cursor_off
;
25476 /* When the window is hscrolled, cursor hpos can legitimately be out
25477 of bounds, but we draw the cursor at the corresponding window
25478 margin in that case. */
25479 if (!cursor_row
->reversed_p
&& hpos
< 0)
25481 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25482 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25484 /* If the cursor is in the mouse face area, redisplay that when
25485 we clear the cursor. */
25486 if (! NILP (hlinfo
->mouse_face_window
)
25487 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25488 /* Don't redraw the cursor's spot in mouse face if it is at the
25489 end of a line (on a newline). The cursor appears there, but
25490 mouse highlighting does not. */
25491 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25492 mouse_face_here_p
= 1;
25494 /* Maybe clear the display under the cursor. */
25495 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25498 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25501 cursor_glyph
= get_phys_cursor_glyph (w
);
25502 if (cursor_glyph
== NULL
)
25503 goto mark_cursor_off
;
25505 width
= cursor_glyph
->pixel_width
;
25506 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25507 x
= w
->phys_cursor
.x
;
25509 width
-= left_x
- x
;
25510 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25511 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25512 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25515 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25518 /* Erase the cursor by redrawing the character underneath it. */
25519 if (mouse_face_here_p
)
25520 hl
= DRAW_MOUSE_FACE
;
25522 hl
= DRAW_NORMAL_TEXT
;
25523 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25526 w
->phys_cursor_on_p
= 0;
25527 w
->phys_cursor_type
= NO_CURSOR
;
25532 Display or clear cursor of window W. If ON is zero, clear the
25533 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25534 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25537 display_and_set_cursor (struct window
*w
, int on
,
25538 int hpos
, int vpos
, int x
, int y
)
25540 struct frame
*f
= XFRAME (w
->frame
);
25541 int new_cursor_type
;
25542 int new_cursor_width
;
25544 struct glyph_row
*glyph_row
;
25545 struct glyph
*glyph
;
25547 /* This is pointless on invisible frames, and dangerous on garbaged
25548 windows and frames; in the latter case, the frame or window may
25549 be in the midst of changing its size, and x and y may be off the
25551 if (! FRAME_VISIBLE_P (f
)
25552 || FRAME_GARBAGED_P (f
)
25553 || vpos
>= w
->current_matrix
->nrows
25554 || hpos
>= w
->current_matrix
->matrix_w
)
25557 /* If cursor is off and we want it off, return quickly. */
25558 if (!on
&& !w
->phys_cursor_on_p
)
25561 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25562 /* If cursor row is not enabled, we don't really know where to
25563 display the cursor. */
25564 if (!glyph_row
->enabled_p
)
25566 w
->phys_cursor_on_p
= 0;
25571 if (!glyph_row
->exact_window_width_line_p
25572 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25573 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25575 xassert (interrupt_input_blocked
);
25577 /* Set new_cursor_type to the cursor we want to be displayed. */
25578 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25579 &new_cursor_width
, &active_cursor
);
25581 /* If cursor is currently being shown and we don't want it to be or
25582 it is in the wrong place, or the cursor type is not what we want,
25584 if (w
->phys_cursor_on_p
25586 || w
->phys_cursor
.x
!= x
25587 || w
->phys_cursor
.y
!= y
25588 || new_cursor_type
!= w
->phys_cursor_type
25589 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25590 && new_cursor_width
!= w
->phys_cursor_width
)))
25591 erase_phys_cursor (w
);
25593 /* Don't check phys_cursor_on_p here because that flag is only set
25594 to zero in some cases where we know that the cursor has been
25595 completely erased, to avoid the extra work of erasing the cursor
25596 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25597 still not be visible, or it has only been partly erased. */
25600 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25601 w
->phys_cursor_height
= glyph_row
->height
;
25603 /* Set phys_cursor_.* before x_draw_.* is called because some
25604 of them may need the information. */
25605 w
->phys_cursor
.x
= x
;
25606 w
->phys_cursor
.y
= glyph_row
->y
;
25607 w
->phys_cursor
.hpos
= hpos
;
25608 w
->phys_cursor
.vpos
= vpos
;
25611 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25612 new_cursor_type
, new_cursor_width
,
25613 on
, active_cursor
);
25617 /* Switch the display of W's cursor on or off, according to the value
25621 update_window_cursor (struct window
*w
, int on
)
25623 /* Don't update cursor in windows whose frame is in the process
25624 of being deleted. */
25625 if (w
->current_matrix
)
25627 int hpos
= w
->phys_cursor
.hpos
;
25628 int vpos
= w
->phys_cursor
.vpos
;
25629 struct glyph_row
*row
;
25631 if (vpos
>= w
->current_matrix
->nrows
25632 || hpos
>= w
->current_matrix
->matrix_w
)
25635 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25637 /* When the window is hscrolled, cursor hpos can legitimately be
25638 out of bounds, but we draw the cursor at the corresponding
25639 window margin in that case. */
25640 if (!row
->reversed_p
&& hpos
< 0)
25642 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25643 hpos
= row
->used
[TEXT_AREA
] - 1;
25646 display_and_set_cursor (w
, on
, hpos
, vpos
,
25647 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25653 /* Call update_window_cursor with parameter ON_P on all leaf windows
25654 in the window tree rooted at W. */
25657 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25661 if (!NILP (w
->hchild
))
25662 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25663 else if (!NILP (w
->vchild
))
25664 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25666 update_window_cursor (w
, on_p
);
25668 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25674 Display the cursor on window W, or clear it, according to ON_P.
25675 Don't change the cursor's position. */
25678 x_update_cursor (struct frame
*f
, int on_p
)
25680 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25685 Clear the cursor of window W to background color, and mark the
25686 cursor as not shown. This is used when the text where the cursor
25687 is about to be rewritten. */
25690 x_clear_cursor (struct window
*w
)
25692 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25693 update_window_cursor (w
, 0);
25696 #endif /* HAVE_WINDOW_SYSTEM */
25698 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25701 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25702 int start_hpos
, int end_hpos
,
25703 enum draw_glyphs_face draw
)
25705 #ifdef HAVE_WINDOW_SYSTEM
25706 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25708 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25712 #if defined (HAVE_GPM) || defined (MSDOS)
25713 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25717 /* Display the active region described by mouse_face_* according to DRAW. */
25720 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25722 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25723 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25725 if (/* If window is in the process of being destroyed, don't bother
25727 w
->current_matrix
!= NULL
25728 /* Don't update mouse highlight if hidden */
25729 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25730 /* Recognize when we are called to operate on rows that don't exist
25731 anymore. This can happen when a window is split. */
25732 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25734 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25735 struct glyph_row
*row
, *first
, *last
;
25737 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25738 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25740 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25742 int start_hpos
, end_hpos
, start_x
;
25744 /* For all but the first row, the highlight starts at column 0. */
25747 /* R2L rows have BEG and END in reversed order, but the
25748 screen drawing geometry is always left to right. So
25749 we need to mirror the beginning and end of the
25750 highlighted area in R2L rows. */
25751 if (!row
->reversed_p
)
25753 start_hpos
= hlinfo
->mouse_face_beg_col
;
25754 start_x
= hlinfo
->mouse_face_beg_x
;
25756 else if (row
== last
)
25758 start_hpos
= hlinfo
->mouse_face_end_col
;
25759 start_x
= hlinfo
->mouse_face_end_x
;
25767 else if (row
->reversed_p
&& row
== last
)
25769 start_hpos
= hlinfo
->mouse_face_end_col
;
25770 start_x
= hlinfo
->mouse_face_end_x
;
25780 if (!row
->reversed_p
)
25781 end_hpos
= hlinfo
->mouse_face_end_col
;
25782 else if (row
== first
)
25783 end_hpos
= hlinfo
->mouse_face_beg_col
;
25786 end_hpos
= row
->used
[TEXT_AREA
];
25787 if (draw
== DRAW_NORMAL_TEXT
)
25788 row
->fill_line_p
= 1; /* Clear to end of line */
25791 else if (row
->reversed_p
&& row
== first
)
25792 end_hpos
= hlinfo
->mouse_face_beg_col
;
25795 end_hpos
= row
->used
[TEXT_AREA
];
25796 if (draw
== DRAW_NORMAL_TEXT
)
25797 row
->fill_line_p
= 1; /* Clear to end of line */
25800 if (end_hpos
> start_hpos
)
25802 draw_row_with_mouse_face (w
, start_x
, row
,
25803 start_hpos
, end_hpos
, draw
);
25806 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
25810 #ifdef HAVE_WINDOW_SYSTEM
25811 /* When we've written over the cursor, arrange for it to
25812 be displayed again. */
25813 if (FRAME_WINDOW_P (f
)
25814 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
25816 int hpos
= w
->phys_cursor
.hpos
;
25818 /* When the window is hscrolled, cursor hpos can legitimately be
25819 out of bounds, but we draw the cursor at the corresponding
25820 window margin in that case. */
25821 if (!row
->reversed_p
&& hpos
< 0)
25823 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25824 hpos
= row
->used
[TEXT_AREA
] - 1;
25827 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
25828 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25831 #endif /* HAVE_WINDOW_SYSTEM */
25834 #ifdef HAVE_WINDOW_SYSTEM
25835 /* Change the mouse cursor. */
25836 if (FRAME_WINDOW_P (f
))
25838 if (draw
== DRAW_NORMAL_TEXT
25839 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
25840 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
25841 else if (draw
== DRAW_MOUSE_FACE
)
25842 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
25844 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
25846 #endif /* HAVE_WINDOW_SYSTEM */
25850 Clear out the mouse-highlighted active region.
25851 Redraw it un-highlighted first. Value is non-zero if mouse
25852 face was actually drawn unhighlighted. */
25855 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
25859 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
25861 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
25865 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25866 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25867 hlinfo
->mouse_face_window
= Qnil
;
25868 hlinfo
->mouse_face_overlay
= Qnil
;
25872 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
25873 within the mouse face on that window. */
25875 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
25877 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25879 /* Quickly resolve the easy cases. */
25880 if (!(WINDOWP (hlinfo
->mouse_face_window
)
25881 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
25883 if (vpos
< hlinfo
->mouse_face_beg_row
25884 || vpos
> hlinfo
->mouse_face_end_row
)
25886 if (vpos
> hlinfo
->mouse_face_beg_row
25887 && vpos
< hlinfo
->mouse_face_end_row
)
25890 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
25892 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25894 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
25897 else if ((vpos
== hlinfo
->mouse_face_beg_row
25898 && hpos
>= hlinfo
->mouse_face_beg_col
)
25899 || (vpos
== hlinfo
->mouse_face_end_row
25900 && hpos
< hlinfo
->mouse_face_end_col
))
25905 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25907 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
25910 else if ((vpos
== hlinfo
->mouse_face_beg_row
25911 && hpos
<= hlinfo
->mouse_face_beg_col
)
25912 || (vpos
== hlinfo
->mouse_face_end_row
25913 && hpos
> hlinfo
->mouse_face_end_col
))
25921 Non-zero if physical cursor of window W is within mouse face. */
25924 cursor_in_mouse_face_p (struct window
*w
)
25926 int hpos
= w
->phys_cursor
.hpos
;
25927 int vpos
= w
->phys_cursor
.vpos
;
25928 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25930 /* When the window is hscrolled, cursor hpos can legitimately be out
25931 of bounds, but we draw the cursor at the corresponding window
25932 margin in that case. */
25933 if (!row
->reversed_p
&& hpos
< 0)
25935 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25936 hpos
= row
->used
[TEXT_AREA
] - 1;
25938 return coords_in_mouse_face_p (w
, hpos
, vpos
);
25943 /* Find the glyph rows START_ROW and END_ROW of window W that display
25944 characters between buffer positions START_CHARPOS and END_CHARPOS
25945 (excluding END_CHARPOS). DISP_STRING is a display string that
25946 covers these buffer positions. This is similar to
25947 row_containing_pos, but is more accurate when bidi reordering makes
25948 buffer positions change non-linearly with glyph rows. */
25950 rows_from_pos_range (struct window
*w
,
25951 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
25952 Lisp_Object disp_string
,
25953 struct glyph_row
**start
, struct glyph_row
**end
)
25955 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25956 int last_y
= window_text_bottom_y (w
);
25957 struct glyph_row
*row
;
25962 while (!first
->enabled_p
25963 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
25966 /* Find the START row. */
25968 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
25971 /* A row can potentially be the START row if the range of the
25972 characters it displays intersects the range
25973 [START_CHARPOS..END_CHARPOS). */
25974 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
25975 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
25976 /* See the commentary in row_containing_pos, for the
25977 explanation of the complicated way to check whether
25978 some position is beyond the end of the characters
25979 displayed by a row. */
25980 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25981 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25982 && !row
->ends_at_zv_p
25983 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
25984 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25985 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25986 && !row
->ends_at_zv_p
25987 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
25989 /* Found a candidate row. Now make sure at least one of the
25990 glyphs it displays has a charpos from the range
25991 [START_CHARPOS..END_CHARPOS).
25993 This is not obvious because bidi reordering could make
25994 buffer positions of a row be 1,2,3,102,101,100, and if we
25995 want to highlight characters in [50..60), we don't want
25996 this row, even though [50..60) does intersect [1..103),
25997 the range of character positions given by the row's start
25998 and end positions. */
25999 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26000 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26004 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26005 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26006 /* A glyph that comes from DISP_STRING is by
26007 definition to be highlighted. */
26008 || EQ (g
->object
, disp_string
))
26017 /* Find the END row. */
26019 /* If the last row is partially visible, start looking for END
26020 from that row, instead of starting from FIRST. */
26021 && !(row
->enabled_p
26022 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26024 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26026 struct glyph_row
*next
= row
+ 1;
26027 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26029 if (!next
->enabled_p
26030 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26031 /* The first row >= START whose range of displayed characters
26032 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26033 is the row END + 1. */
26034 || (start_charpos
< next_start
26035 && end_charpos
< next_start
)
26036 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26037 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26038 && !next
->ends_at_zv_p
26039 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26040 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26041 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26042 && !next
->ends_at_zv_p
26043 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26050 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26051 but none of the characters it displays are in the range, it is
26053 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26054 struct glyph
*s
= g
;
26055 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26059 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26060 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26061 /* If the buffer position of the first glyph in
26062 the row is equal to END_CHARPOS, it means
26063 the last character to be highlighted is the
26064 newline of ROW, and we must consider NEXT as
26066 || (((!next
->reversed_p
&& g
== s
)
26067 || (next
->reversed_p
&& g
== e
- 1))
26068 && (g
->charpos
== end_charpos
26069 /* Special case for when NEXT is an
26070 empty line at ZV. */
26071 || (g
->charpos
== -1
26072 && !row
->ends_at_zv_p
26073 && next_start
== end_charpos
)))))
26074 /* A glyph that comes from DISP_STRING is by
26075 definition to be highlighted. */
26076 || EQ (g
->object
, disp_string
))
26085 /* The first row that ends at ZV must be the last to be
26087 else if (next
->ends_at_zv_p
)
26096 /* This function sets the mouse_face_* elements of HLINFO, assuming
26097 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26098 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26099 for the overlay or run of text properties specifying the mouse
26100 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26101 before-string and after-string that must also be highlighted.
26102 DISP_STRING, if non-nil, is a display string that may cover some
26103 or all of the highlighted text. */
26106 mouse_face_from_buffer_pos (Lisp_Object window
,
26107 Mouse_HLInfo
*hlinfo
,
26108 ptrdiff_t mouse_charpos
,
26109 ptrdiff_t start_charpos
,
26110 ptrdiff_t end_charpos
,
26111 Lisp_Object before_string
,
26112 Lisp_Object after_string
,
26113 Lisp_Object disp_string
)
26115 struct window
*w
= XWINDOW (window
);
26116 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26117 struct glyph_row
*r1
, *r2
;
26118 struct glyph
*glyph
, *end
;
26119 ptrdiff_t ignore
, pos
;
26122 xassert (NILP (disp_string
) || STRINGP (disp_string
));
26123 xassert (NILP (before_string
) || STRINGP (before_string
));
26124 xassert (NILP (after_string
) || STRINGP (after_string
));
26126 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26127 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26129 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26130 /* If the before-string or display-string contains newlines,
26131 rows_from_pos_range skips to its last row. Move back. */
26132 if (!NILP (before_string
) || !NILP (disp_string
))
26134 struct glyph_row
*prev
;
26135 while ((prev
= r1
- 1, prev
>= first
)
26136 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26137 && prev
->used
[TEXT_AREA
] > 0)
26139 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26140 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26141 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26143 || !(EQ (glyph
->object
, before_string
)
26144 || EQ (glyph
->object
, disp_string
)))
26151 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26152 hlinfo
->mouse_face_past_end
= 1;
26154 else if (!NILP (after_string
))
26156 /* If the after-string has newlines, advance to its last row. */
26157 struct glyph_row
*next
;
26158 struct glyph_row
*last
26159 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26161 for (next
= r2
+ 1;
26163 && next
->used
[TEXT_AREA
] > 0
26164 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26168 /* The rest of the display engine assumes that mouse_face_beg_row is
26169 either above mouse_face_end_row or identical to it. But with
26170 bidi-reordered continued lines, the row for START_CHARPOS could
26171 be below the row for END_CHARPOS. If so, swap the rows and store
26172 them in correct order. */
26175 struct glyph_row
*tem
= r2
;
26181 hlinfo
->mouse_face_beg_y
= r1
->y
;
26182 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26183 hlinfo
->mouse_face_end_y
= r2
->y
;
26184 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26186 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26187 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26188 could be anywhere in the row and in any order. The strategy
26189 below is to find the leftmost and the rightmost glyph that
26190 belongs to either of these 3 strings, or whose position is
26191 between START_CHARPOS and END_CHARPOS, and highlight all the
26192 glyphs between those two. This may cover more than just the text
26193 between START_CHARPOS and END_CHARPOS if the range of characters
26194 strides the bidi level boundary, e.g. if the beginning is in R2L
26195 text while the end is in L2R text or vice versa. */
26196 if (!r1
->reversed_p
)
26198 /* This row is in a left to right paragraph. Scan it left to
26200 glyph
= r1
->glyphs
[TEXT_AREA
];
26201 end
= glyph
+ r1
->used
[TEXT_AREA
];
26204 /* Skip truncation glyphs at the start of the glyph row. */
26205 if (r1
->displays_text_p
)
26207 && INTEGERP (glyph
->object
)
26208 && glyph
->charpos
< 0;
26210 x
+= glyph
->pixel_width
;
26212 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26213 or DISP_STRING, and the first glyph from buffer whose
26214 position is between START_CHARPOS and END_CHARPOS. */
26216 && !INTEGERP (glyph
->object
)
26217 && !EQ (glyph
->object
, disp_string
)
26218 && !(BUFFERP (glyph
->object
)
26219 && (glyph
->charpos
>= start_charpos
26220 && glyph
->charpos
< end_charpos
));
26223 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26224 are present at buffer positions between START_CHARPOS and
26225 END_CHARPOS, or if they come from an overlay. */
26226 if (EQ (glyph
->object
, before_string
))
26228 pos
= string_buffer_position (before_string
,
26230 /* If pos == 0, it means before_string came from an
26231 overlay, not from a buffer position. */
26232 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26235 else if (EQ (glyph
->object
, after_string
))
26237 pos
= string_buffer_position (after_string
, end_charpos
);
26238 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26241 x
+= glyph
->pixel_width
;
26243 hlinfo
->mouse_face_beg_x
= x
;
26244 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26248 /* This row is in a right to left paragraph. Scan it right to
26252 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26253 glyph
= end
+ r1
->used
[TEXT_AREA
];
26255 /* Skip truncation glyphs at the start of the glyph row. */
26256 if (r1
->displays_text_p
)
26258 && INTEGERP (glyph
->object
)
26259 && glyph
->charpos
< 0;
26263 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26264 or DISP_STRING, and the first glyph from buffer whose
26265 position is between START_CHARPOS and END_CHARPOS. */
26267 && !INTEGERP (glyph
->object
)
26268 && !EQ (glyph
->object
, disp_string
)
26269 && !(BUFFERP (glyph
->object
)
26270 && (glyph
->charpos
>= start_charpos
26271 && glyph
->charpos
< end_charpos
));
26274 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26275 are present at buffer positions between START_CHARPOS and
26276 END_CHARPOS, or if they come from an overlay. */
26277 if (EQ (glyph
->object
, before_string
))
26279 pos
= string_buffer_position (before_string
, start_charpos
);
26280 /* If pos == 0, it means before_string came from an
26281 overlay, not from a buffer position. */
26282 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26285 else if (EQ (glyph
->object
, after_string
))
26287 pos
= string_buffer_position (after_string
, end_charpos
);
26288 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26293 glyph
++; /* first glyph to the right of the highlighted area */
26294 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26295 x
+= g
->pixel_width
;
26296 hlinfo
->mouse_face_beg_x
= x
;
26297 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26300 /* If the highlight ends in a different row, compute GLYPH and END
26301 for the end row. Otherwise, reuse the values computed above for
26302 the row where the highlight begins. */
26305 if (!r2
->reversed_p
)
26307 glyph
= r2
->glyphs
[TEXT_AREA
];
26308 end
= glyph
+ r2
->used
[TEXT_AREA
];
26313 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26314 glyph
= end
+ r2
->used
[TEXT_AREA
];
26318 if (!r2
->reversed_p
)
26320 /* Skip truncation and continuation glyphs near the end of the
26321 row, and also blanks and stretch glyphs inserted by
26322 extend_face_to_end_of_line. */
26324 && INTEGERP ((end
- 1)->object
))
26326 /* Scan the rest of the glyph row from the end, looking for the
26327 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26328 DISP_STRING, or whose position is between START_CHARPOS
26332 && !INTEGERP (end
->object
)
26333 && !EQ (end
->object
, disp_string
)
26334 && !(BUFFERP (end
->object
)
26335 && (end
->charpos
>= start_charpos
26336 && end
->charpos
< end_charpos
));
26339 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26340 are present at buffer positions between START_CHARPOS and
26341 END_CHARPOS, or if they come from an overlay. */
26342 if (EQ (end
->object
, before_string
))
26344 pos
= string_buffer_position (before_string
, start_charpos
);
26345 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26348 else if (EQ (end
->object
, after_string
))
26350 pos
= string_buffer_position (after_string
, end_charpos
);
26351 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26355 /* Find the X coordinate of the last glyph to be highlighted. */
26356 for (; glyph
<= end
; ++glyph
)
26357 x
+= glyph
->pixel_width
;
26359 hlinfo
->mouse_face_end_x
= x
;
26360 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26364 /* Skip truncation and continuation glyphs near the end of the
26365 row, and also blanks and stretch glyphs inserted by
26366 extend_face_to_end_of_line. */
26370 && INTEGERP (end
->object
))
26372 x
+= end
->pixel_width
;
26375 /* Scan the rest of the glyph row from the end, looking for the
26376 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26377 DISP_STRING, or whose position is between START_CHARPOS
26381 && !INTEGERP (end
->object
)
26382 && !EQ (end
->object
, disp_string
)
26383 && !(BUFFERP (end
->object
)
26384 && (end
->charpos
>= start_charpos
26385 && end
->charpos
< end_charpos
));
26388 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26389 are present at buffer positions between START_CHARPOS and
26390 END_CHARPOS, or if they come from an overlay. */
26391 if (EQ (end
->object
, before_string
))
26393 pos
= string_buffer_position (before_string
, start_charpos
);
26394 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26397 else if (EQ (end
->object
, after_string
))
26399 pos
= string_buffer_position (after_string
, end_charpos
);
26400 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26403 x
+= end
->pixel_width
;
26405 /* If we exited the above loop because we arrived at the last
26406 glyph of the row, and its buffer position is still not in
26407 range, it means the last character in range is the preceding
26408 newline. Bump the end column and x values to get past the
26411 && BUFFERP (end
->object
)
26412 && (end
->charpos
< start_charpos
26413 || end
->charpos
>= end_charpos
))
26415 x
+= end
->pixel_width
;
26418 hlinfo
->mouse_face_end_x
= x
;
26419 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26422 hlinfo
->mouse_face_window
= window
;
26423 hlinfo
->mouse_face_face_id
26424 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26426 !hlinfo
->mouse_face_hidden
, -1);
26427 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26430 /* The following function is not used anymore (replaced with
26431 mouse_face_from_string_pos), but I leave it here for the time
26432 being, in case someone would. */
26434 #if 0 /* not used */
26436 /* Find the position of the glyph for position POS in OBJECT in
26437 window W's current matrix, and return in *X, *Y the pixel
26438 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26440 RIGHT_P non-zero means return the position of the right edge of the
26441 glyph, RIGHT_P zero means return the left edge position.
26443 If no glyph for POS exists in the matrix, return the position of
26444 the glyph with the next smaller position that is in the matrix, if
26445 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26446 exists in the matrix, return the position of the glyph with the
26447 next larger position in OBJECT.
26449 Value is non-zero if a glyph was found. */
26452 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26453 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26455 int yb
= window_text_bottom_y (w
);
26456 struct glyph_row
*r
;
26457 struct glyph
*best_glyph
= NULL
;
26458 struct glyph_row
*best_row
= NULL
;
26461 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26462 r
->enabled_p
&& r
->y
< yb
;
26465 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26466 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26469 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26470 if (EQ (g
->object
, object
))
26472 if (g
->charpos
== pos
)
26479 else if (best_glyph
== NULL
26480 || ((eabs (g
->charpos
- pos
)
26481 < eabs (best_glyph
->charpos
- pos
))
26484 : g
->charpos
> pos
)))
26498 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26502 *x
+= best_glyph
->pixel_width
;
26507 *vpos
= best_row
- w
->current_matrix
->rows
;
26510 return best_glyph
!= NULL
;
26512 #endif /* not used */
26514 /* Find the positions of the first and the last glyphs in window W's
26515 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26516 (assumed to be a string), and return in HLINFO's mouse_face_*
26517 members the pixel and column/row coordinates of those glyphs. */
26520 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26521 Lisp_Object object
,
26522 ptrdiff_t startpos
, ptrdiff_t endpos
)
26524 int yb
= window_text_bottom_y (w
);
26525 struct glyph_row
*r
;
26526 struct glyph
*g
, *e
;
26530 /* Find the glyph row with at least one position in the range
26531 [STARTPOS..ENDPOS], and the first glyph in that row whose
26532 position belongs to that range. */
26533 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26534 r
->enabled_p
&& r
->y
< yb
;
26537 if (!r
->reversed_p
)
26539 g
= r
->glyphs
[TEXT_AREA
];
26540 e
= g
+ r
->used
[TEXT_AREA
];
26541 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26542 if (EQ (g
->object
, object
)
26543 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26545 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26546 hlinfo
->mouse_face_beg_y
= r
->y
;
26547 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26548 hlinfo
->mouse_face_beg_x
= gx
;
26557 e
= r
->glyphs
[TEXT_AREA
];
26558 g
= e
+ r
->used
[TEXT_AREA
];
26559 for ( ; g
> e
; --g
)
26560 if (EQ ((g
-1)->object
, object
)
26561 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26563 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26564 hlinfo
->mouse_face_beg_y
= r
->y
;
26565 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26566 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26567 gx
+= g1
->pixel_width
;
26568 hlinfo
->mouse_face_beg_x
= gx
;
26580 /* Starting with the next row, look for the first row which does NOT
26581 include any glyphs whose positions are in the range. */
26582 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26584 g
= r
->glyphs
[TEXT_AREA
];
26585 e
= g
+ r
->used
[TEXT_AREA
];
26587 for ( ; g
< e
; ++g
)
26588 if (EQ (g
->object
, object
)
26589 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26598 /* The highlighted region ends on the previous row. */
26601 /* Set the end row and its vertical pixel coordinate. */
26602 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26603 hlinfo
->mouse_face_end_y
= r
->y
;
26605 /* Compute and set the end column and the end column's horizontal
26606 pixel coordinate. */
26607 if (!r
->reversed_p
)
26609 g
= r
->glyphs
[TEXT_AREA
];
26610 e
= g
+ r
->used
[TEXT_AREA
];
26611 for ( ; e
> g
; --e
)
26612 if (EQ ((e
-1)->object
, object
)
26613 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26615 hlinfo
->mouse_face_end_col
= e
- g
;
26617 for (gx
= r
->x
; g
< e
; ++g
)
26618 gx
+= g
->pixel_width
;
26619 hlinfo
->mouse_face_end_x
= gx
;
26623 e
= r
->glyphs
[TEXT_AREA
];
26624 g
= e
+ r
->used
[TEXT_AREA
];
26625 for (gx
= r
->x
; e
< g
; ++e
)
26627 if (EQ (e
->object
, object
)
26628 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26630 gx
+= e
->pixel_width
;
26632 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26633 hlinfo
->mouse_face_end_x
= gx
;
26637 #ifdef HAVE_WINDOW_SYSTEM
26639 /* See if position X, Y is within a hot-spot of an image. */
26642 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26644 if (!CONSP (hot_spot
))
26647 if (EQ (XCAR (hot_spot
), Qrect
))
26649 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26650 Lisp_Object rect
= XCDR (hot_spot
);
26654 if (!CONSP (XCAR (rect
)))
26656 if (!CONSP (XCDR (rect
)))
26658 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26660 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26662 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26664 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26668 else if (EQ (XCAR (hot_spot
), Qcircle
))
26670 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26671 Lisp_Object circ
= XCDR (hot_spot
);
26672 Lisp_Object lr
, lx0
, ly0
;
26674 && CONSP (XCAR (circ
))
26675 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26676 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26677 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26679 double r
= XFLOATINT (lr
);
26680 double dx
= XINT (lx0
) - x
;
26681 double dy
= XINT (ly0
) - y
;
26682 return (dx
* dx
+ dy
* dy
<= r
* r
);
26685 else if (EQ (XCAR (hot_spot
), Qpoly
))
26687 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26688 if (VECTORP (XCDR (hot_spot
)))
26690 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26691 Lisp_Object
*poly
= v
->contents
;
26692 ptrdiff_t n
= v
->header
.size
;
26695 Lisp_Object lx
, ly
;
26698 /* Need an even number of coordinates, and at least 3 edges. */
26699 if (n
< 6 || n
& 1)
26702 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26703 If count is odd, we are inside polygon. Pixels on edges
26704 may or may not be included depending on actual geometry of the
26706 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26707 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26709 x0
= XINT (lx
), y0
= XINT (ly
);
26710 for (i
= 0; i
< n
; i
+= 2)
26712 int x1
= x0
, y1
= y0
;
26713 if ((lx
= poly
[i
], !INTEGERP (lx
))
26714 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26716 x0
= XINT (lx
), y0
= XINT (ly
);
26718 /* Does this segment cross the X line? */
26726 if (y
> y0
&& y
> y1
)
26728 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26738 find_hot_spot (Lisp_Object map
, int x
, int y
)
26740 while (CONSP (map
))
26742 if (CONSP (XCAR (map
))
26743 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26751 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26753 doc
: /* Lookup in image map MAP coordinates X and Y.
26754 An image map is an alist where each element has the format (AREA ID PLIST).
26755 An AREA is specified as either a rectangle, a circle, or a polygon:
26756 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26757 pixel coordinates of the upper left and bottom right corners.
26758 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26759 and the radius of the circle; r may be a float or integer.
26760 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26761 vector describes one corner in the polygon.
26762 Returns the alist element for the first matching AREA in MAP. */)
26763 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26771 return find_hot_spot (map
,
26772 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
26773 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
26777 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26779 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26781 /* Do not change cursor shape while dragging mouse. */
26782 if (!NILP (do_mouse_tracking
))
26785 if (!NILP (pointer
))
26787 if (EQ (pointer
, Qarrow
))
26788 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26789 else if (EQ (pointer
, Qhand
))
26790 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
26791 else if (EQ (pointer
, Qtext
))
26792 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26793 else if (EQ (pointer
, intern ("hdrag")))
26794 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26795 #ifdef HAVE_X_WINDOWS
26796 else if (EQ (pointer
, intern ("vdrag")))
26797 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
26799 else if (EQ (pointer
, intern ("hourglass")))
26800 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
26801 else if (EQ (pointer
, Qmodeline
))
26802 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
26804 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26807 if (cursor
!= No_Cursor
)
26808 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
26811 #endif /* HAVE_WINDOW_SYSTEM */
26813 /* Take proper action when mouse has moved to the mode or header line
26814 or marginal area AREA of window W, x-position X and y-position Y.
26815 X is relative to the start of the text display area of W, so the
26816 width of bitmap areas and scroll bars must be subtracted to get a
26817 position relative to the start of the mode line. */
26820 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
26821 enum window_part area
)
26823 struct window
*w
= XWINDOW (window
);
26824 struct frame
*f
= XFRAME (w
->frame
);
26825 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26826 #ifdef HAVE_WINDOW_SYSTEM
26827 Display_Info
*dpyinfo
;
26829 Cursor cursor
= No_Cursor
;
26830 Lisp_Object pointer
= Qnil
;
26831 int dx
, dy
, width
, height
;
26833 Lisp_Object string
, object
= Qnil
;
26834 Lisp_Object pos
, help
;
26836 Lisp_Object mouse_face
;
26837 int original_x_pixel
= x
;
26838 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
26839 struct glyph_row
*row
;
26841 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
26846 /* Kludge alert: mode_line_string takes X/Y in pixels, but
26847 returns them in row/column units! */
26848 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
26849 &object
, &dx
, &dy
, &width
, &height
);
26851 row
= (area
== ON_MODE_LINE
26852 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
26853 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
26855 /* Find the glyph under the mouse pointer. */
26856 if (row
->mode_line_p
&& row
->enabled_p
)
26858 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
26859 end
= glyph
+ row
->used
[TEXT_AREA
];
26861 for (x0
= original_x_pixel
;
26862 glyph
< end
&& x0
>= glyph
->pixel_width
;
26864 x0
-= glyph
->pixel_width
;
26872 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
26873 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
26874 returns them in row/column units! */
26875 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
26876 &object
, &dx
, &dy
, &width
, &height
);
26881 #ifdef HAVE_WINDOW_SYSTEM
26882 if (IMAGEP (object
))
26884 Lisp_Object image_map
, hotspot
;
26885 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
26887 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
26889 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26893 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
26894 If so, we could look for mouse-enter, mouse-leave
26895 properties in PLIST (and do something...). */
26896 hotspot
= XCDR (hotspot
);
26897 if (CONSP (hotspot
)
26898 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26900 pointer
= Fplist_get (plist
, Qpointer
);
26901 if (NILP (pointer
))
26903 help
= Fplist_get (plist
, Qhelp_echo
);
26906 help_echo_string
= help
;
26907 /* Is this correct? ++kfs */
26908 XSETWINDOW (help_echo_window
, w
);
26909 help_echo_object
= w
->buffer
;
26910 help_echo_pos
= charpos
;
26914 if (NILP (pointer
))
26915 pointer
= Fplist_get (XCDR (object
), QCpointer
);
26917 #endif /* HAVE_WINDOW_SYSTEM */
26919 if (STRINGP (string
))
26921 pos
= make_number (charpos
);
26922 /* If we're on a string with `help-echo' text property, arrange
26923 for the help to be displayed. This is done by setting the
26924 global variable help_echo_string to the help string. */
26927 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
26930 help_echo_string
= help
;
26931 XSETWINDOW (help_echo_window
, w
);
26932 help_echo_object
= string
;
26933 help_echo_pos
= charpos
;
26937 #ifdef HAVE_WINDOW_SYSTEM
26938 if (FRAME_WINDOW_P (f
))
26940 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
26941 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26942 if (NILP (pointer
))
26943 pointer
= Fget_text_property (pos
, Qpointer
, string
);
26945 /* Change the mouse pointer according to what is under X/Y. */
26947 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
26950 map
= Fget_text_property (pos
, Qlocal_map
, string
);
26951 if (!KEYMAPP (map
))
26952 map
= Fget_text_property (pos
, Qkeymap
, string
);
26953 if (!KEYMAPP (map
))
26954 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
26959 /* Change the mouse face according to what is under X/Y. */
26960 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
26961 if (!NILP (mouse_face
)
26962 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26967 struct glyph
* tmp_glyph
;
26971 int total_pixel_width
;
26972 ptrdiff_t begpos
, endpos
, ignore
;
26976 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
26977 Qmouse_face
, string
, Qnil
);
26983 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
26985 endpos
= SCHARS (string
);
26989 /* Calculate the glyph position GPOS of GLYPH in the
26990 displayed string, relative to the beginning of the
26991 highlighted part of the string.
26993 Note: GPOS is different from CHARPOS. CHARPOS is the
26994 position of GLYPH in the internal string object. A mode
26995 line string format has structures which are converted to
26996 a flattened string by the Emacs Lisp interpreter. The
26997 internal string is an element of those structures. The
26998 displayed string is the flattened string. */
26999 tmp_glyph
= row_start_glyph
;
27000 while (tmp_glyph
< glyph
27001 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27002 && begpos
<= tmp_glyph
->charpos
27003 && tmp_glyph
->charpos
< endpos
)))
27005 gpos
= glyph
- tmp_glyph
;
27007 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27008 the highlighted part of the displayed string to which
27009 GLYPH belongs. Note: GSEQ_LENGTH is different from
27010 SCHARS (STRING), because the latter returns the length of
27011 the internal string. */
27012 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27014 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27015 && begpos
<= tmp_glyph
->charpos
27016 && tmp_glyph
->charpos
< endpos
));
27019 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27021 /* Calculate the total pixel width of all the glyphs between
27022 the beginning of the highlighted area and GLYPH. */
27023 total_pixel_width
= 0;
27024 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27025 total_pixel_width
+= tmp_glyph
->pixel_width
;
27027 /* Pre calculation of re-rendering position. Note: X is in
27028 column units here, after the call to mode_line_string or
27029 marginal_area_string. */
27031 vpos
= (area
== ON_MODE_LINE
27032 ? (w
->current_matrix
)->nrows
- 1
27035 /* If GLYPH's position is included in the region that is
27036 already drawn in mouse face, we have nothing to do. */
27037 if ( EQ (window
, hlinfo
->mouse_face_window
)
27038 && (!row
->reversed_p
27039 ? (hlinfo
->mouse_face_beg_col
<= hpos
27040 && hpos
< hlinfo
->mouse_face_end_col
)
27041 /* In R2L rows we swap BEG and END, see below. */
27042 : (hlinfo
->mouse_face_end_col
<= hpos
27043 && hpos
< hlinfo
->mouse_face_beg_col
))
27044 && hlinfo
->mouse_face_beg_row
== vpos
)
27047 if (clear_mouse_face (hlinfo
))
27048 cursor
= No_Cursor
;
27050 if (!row
->reversed_p
)
27052 hlinfo
->mouse_face_beg_col
= hpos
;
27053 hlinfo
->mouse_face_beg_x
= original_x_pixel
27054 - (total_pixel_width
+ dx
);
27055 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27056 hlinfo
->mouse_face_end_x
= 0;
27060 /* In R2L rows, show_mouse_face expects BEG and END
27061 coordinates to be swapped. */
27062 hlinfo
->mouse_face_end_col
= hpos
;
27063 hlinfo
->mouse_face_end_x
= original_x_pixel
27064 - (total_pixel_width
+ dx
);
27065 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27066 hlinfo
->mouse_face_beg_x
= 0;
27069 hlinfo
->mouse_face_beg_row
= vpos
;
27070 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27071 hlinfo
->mouse_face_beg_y
= 0;
27072 hlinfo
->mouse_face_end_y
= 0;
27073 hlinfo
->mouse_face_past_end
= 0;
27074 hlinfo
->mouse_face_window
= window
;
27076 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27082 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27084 if (NILP (pointer
))
27087 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27088 clear_mouse_face (hlinfo
);
27090 #ifdef HAVE_WINDOW_SYSTEM
27091 if (FRAME_WINDOW_P (f
))
27092 define_frame_cursor1 (f
, cursor
, pointer
);
27098 Take proper action when the mouse has moved to position X, Y on
27099 frame F as regards highlighting characters that have mouse-face
27100 properties. Also de-highlighting chars where the mouse was before.
27101 X and Y can be negative or out of range. */
27104 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27106 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27107 enum window_part part
= ON_NOTHING
;
27108 Lisp_Object window
;
27110 Cursor cursor
= No_Cursor
;
27111 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27114 /* When a menu is active, don't highlight because this looks odd. */
27115 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27116 if (popup_activated ())
27120 if (NILP (Vmouse_highlight
)
27121 || !f
->glyphs_initialized_p
27122 || f
->pointer_invisible
)
27125 hlinfo
->mouse_face_mouse_x
= x
;
27126 hlinfo
->mouse_face_mouse_y
= y
;
27127 hlinfo
->mouse_face_mouse_frame
= f
;
27129 if (hlinfo
->mouse_face_defer
)
27132 if (gc_in_progress
)
27134 hlinfo
->mouse_face_deferred_gc
= 1;
27138 /* Which window is that in? */
27139 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27141 /* If displaying active text in another window, clear that. */
27142 if (! EQ (window
, hlinfo
->mouse_face_window
)
27143 /* Also clear if we move out of text area in same window. */
27144 || (!NILP (hlinfo
->mouse_face_window
)
27147 && part
!= ON_MODE_LINE
27148 && part
!= ON_HEADER_LINE
))
27149 clear_mouse_face (hlinfo
);
27151 /* Not on a window -> return. */
27152 if (!WINDOWP (window
))
27155 /* Reset help_echo_string. It will get recomputed below. */
27156 help_echo_string
= Qnil
;
27158 /* Convert to window-relative pixel coordinates. */
27159 w
= XWINDOW (window
);
27160 frame_to_window_pixel_xy (w
, &x
, &y
);
27162 #ifdef HAVE_WINDOW_SYSTEM
27163 /* Handle tool-bar window differently since it doesn't display a
27165 if (EQ (window
, f
->tool_bar_window
))
27167 note_tool_bar_highlight (f
, x
, y
);
27172 /* Mouse is on the mode, header line or margin? */
27173 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27174 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27176 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27180 #ifdef HAVE_WINDOW_SYSTEM
27181 if (part
== ON_VERTICAL_BORDER
)
27183 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27184 help_echo_string
= build_string ("drag-mouse-1: resize");
27186 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27187 || part
== ON_SCROLL_BAR
)
27188 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27190 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27193 /* Are we in a window whose display is up to date?
27194 And verify the buffer's text has not changed. */
27195 b
= XBUFFER (w
->buffer
);
27196 if (part
== ON_TEXT
27197 && EQ (w
->window_end_valid
, w
->buffer
)
27198 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
27199 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
27201 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27203 struct glyph
*glyph
;
27204 Lisp_Object object
;
27205 Lisp_Object mouse_face
= Qnil
, position
;
27206 Lisp_Object
*overlay_vec
= NULL
;
27207 ptrdiff_t i
, noverlays
;
27208 struct buffer
*obuf
;
27209 ptrdiff_t obegv
, ozv
;
27212 /* Find the glyph under X/Y. */
27213 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27215 #ifdef HAVE_WINDOW_SYSTEM
27216 /* Look for :pointer property on image. */
27217 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27219 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27220 if (img
!= NULL
&& IMAGEP (img
->spec
))
27222 Lisp_Object image_map
, hotspot
;
27223 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27225 && (hotspot
= find_hot_spot (image_map
,
27226 glyph
->slice
.img
.x
+ dx
,
27227 glyph
->slice
.img
.y
+ dy
),
27229 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27233 /* Could check XCAR (hotspot) to see if we enter/leave
27235 If so, we could look for mouse-enter, mouse-leave
27236 properties in PLIST (and do something...). */
27237 hotspot
= XCDR (hotspot
);
27238 if (CONSP (hotspot
)
27239 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27241 pointer
= Fplist_get (plist
, Qpointer
);
27242 if (NILP (pointer
))
27244 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27245 if (!NILP (help_echo_string
))
27247 help_echo_window
= window
;
27248 help_echo_object
= glyph
->object
;
27249 help_echo_pos
= glyph
->charpos
;
27253 if (NILP (pointer
))
27254 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27257 #endif /* HAVE_WINDOW_SYSTEM */
27259 /* Clear mouse face if X/Y not over text. */
27261 || area
!= TEXT_AREA
27262 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27263 /* Glyph's OBJECT is an integer for glyphs inserted by the
27264 display engine for its internal purposes, like truncation
27265 and continuation glyphs and blanks beyond the end of
27266 line's text on text terminals. If we are over such a
27267 glyph, we are not over any text. */
27268 || INTEGERP (glyph
->object
)
27269 /* R2L rows have a stretch glyph at their front, which
27270 stands for no text, whereas L2R rows have no glyphs at
27271 all beyond the end of text. Treat such stretch glyphs
27272 like we do with NULL glyphs in L2R rows. */
27273 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27274 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27275 && glyph
->type
== STRETCH_GLYPH
27276 && glyph
->avoid_cursor_p
))
27278 if (clear_mouse_face (hlinfo
))
27279 cursor
= No_Cursor
;
27280 #ifdef HAVE_WINDOW_SYSTEM
27281 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27283 if (area
!= TEXT_AREA
)
27284 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27286 pointer
= Vvoid_text_area_pointer
;
27292 pos
= glyph
->charpos
;
27293 object
= glyph
->object
;
27294 if (!STRINGP (object
) && !BUFFERP (object
))
27297 /* If we get an out-of-range value, return now; avoid an error. */
27298 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27301 /* Make the window's buffer temporarily current for
27302 overlays_at and compute_char_face. */
27303 obuf
= current_buffer
;
27304 current_buffer
= b
;
27310 /* Is this char mouse-active or does it have help-echo? */
27311 position
= make_number (pos
);
27313 if (BUFFERP (object
))
27315 /* Put all the overlays we want in a vector in overlay_vec. */
27316 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27317 /* Sort overlays into increasing priority order. */
27318 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27323 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27326 cursor
= No_Cursor
;
27328 /* Check mouse-face highlighting. */
27330 /* If there exists an overlay with mouse-face overlapping
27331 the one we are currently highlighting, we have to
27332 check if we enter the overlapping overlay, and then
27333 highlight only that. */
27334 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27335 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27337 /* Find the highest priority overlay with a mouse-face. */
27338 Lisp_Object overlay
= Qnil
;
27339 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27341 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27342 if (!NILP (mouse_face
))
27343 overlay
= overlay_vec
[i
];
27346 /* If we're highlighting the same overlay as before, there's
27347 no need to do that again. */
27348 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27349 goto check_help_echo
;
27350 hlinfo
->mouse_face_overlay
= overlay
;
27352 /* Clear the display of the old active region, if any. */
27353 if (clear_mouse_face (hlinfo
))
27354 cursor
= No_Cursor
;
27356 /* If no overlay applies, get a text property. */
27357 if (NILP (overlay
))
27358 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27360 /* Next, compute the bounds of the mouse highlighting and
27362 if (!NILP (mouse_face
) && STRINGP (object
))
27364 /* The mouse-highlighting comes from a display string
27365 with a mouse-face. */
27369 s
= Fprevious_single_property_change
27370 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27371 e
= Fnext_single_property_change
27372 (position
, Qmouse_face
, object
, Qnil
);
27374 s
= make_number (0);
27376 e
= make_number (SCHARS (object
) - 1);
27377 mouse_face_from_string_pos (w
, hlinfo
, object
,
27378 XINT (s
), XINT (e
));
27379 hlinfo
->mouse_face_past_end
= 0;
27380 hlinfo
->mouse_face_window
= window
;
27381 hlinfo
->mouse_face_face_id
27382 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27383 glyph
->face_id
, 1);
27384 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27385 cursor
= No_Cursor
;
27389 /* The mouse-highlighting, if any, comes from an overlay
27390 or text property in the buffer. */
27391 Lisp_Object buffer
IF_LINT (= Qnil
);
27392 Lisp_Object disp_string
IF_LINT (= Qnil
);
27394 if (STRINGP (object
))
27396 /* If we are on a display string with no mouse-face,
27397 check if the text under it has one. */
27398 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27399 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27400 pos
= string_buffer_position (object
, start
);
27403 mouse_face
= get_char_property_and_overlay
27404 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27405 buffer
= w
->buffer
;
27406 disp_string
= object
;
27412 disp_string
= Qnil
;
27415 if (!NILP (mouse_face
))
27417 Lisp_Object before
, after
;
27418 Lisp_Object before_string
, after_string
;
27419 /* To correctly find the limits of mouse highlight
27420 in a bidi-reordered buffer, we must not use the
27421 optimization of limiting the search in
27422 previous-single-property-change and
27423 next-single-property-change, because
27424 rows_from_pos_range needs the real start and end
27425 positions to DTRT in this case. That's because
27426 the first row visible in a window does not
27427 necessarily display the character whose position
27428 is the smallest. */
27430 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27431 ? Fmarker_position (w
->start
)
27434 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27435 ? make_number (BUF_Z (XBUFFER (buffer
))
27436 - XFASTINT (w
->window_end_pos
))
27439 if (NILP (overlay
))
27441 /* Handle the text property case. */
27442 before
= Fprevious_single_property_change
27443 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27444 after
= Fnext_single_property_change
27445 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27446 before_string
= after_string
= Qnil
;
27450 /* Handle the overlay case. */
27451 before
= Foverlay_start (overlay
);
27452 after
= Foverlay_end (overlay
);
27453 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27454 after_string
= Foverlay_get (overlay
, Qafter_string
);
27456 if (!STRINGP (before_string
)) before_string
= Qnil
;
27457 if (!STRINGP (after_string
)) after_string
= Qnil
;
27460 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27463 : XFASTINT (before
),
27465 ? BUF_Z (XBUFFER (buffer
))
27466 : XFASTINT (after
),
27467 before_string
, after_string
,
27469 cursor
= No_Cursor
;
27476 /* Look for a `help-echo' property. */
27477 if (NILP (help_echo_string
)) {
27478 Lisp_Object help
, overlay
;
27480 /* Check overlays first. */
27481 help
= overlay
= Qnil
;
27482 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27484 overlay
= overlay_vec
[i
];
27485 help
= Foverlay_get (overlay
, Qhelp_echo
);
27490 help_echo_string
= help
;
27491 help_echo_window
= window
;
27492 help_echo_object
= overlay
;
27493 help_echo_pos
= pos
;
27497 Lisp_Object obj
= glyph
->object
;
27498 ptrdiff_t charpos
= glyph
->charpos
;
27500 /* Try text properties. */
27503 && charpos
< SCHARS (obj
))
27505 help
= Fget_text_property (make_number (charpos
),
27509 /* If the string itself doesn't specify a help-echo,
27510 see if the buffer text ``under'' it does. */
27511 struct glyph_row
*r
27512 = MATRIX_ROW (w
->current_matrix
, vpos
);
27513 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27514 ptrdiff_t p
= string_buffer_position (obj
, start
);
27517 help
= Fget_char_property (make_number (p
),
27518 Qhelp_echo
, w
->buffer
);
27527 else if (BUFFERP (obj
)
27530 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27535 help_echo_string
= help
;
27536 help_echo_window
= window
;
27537 help_echo_object
= obj
;
27538 help_echo_pos
= charpos
;
27543 #ifdef HAVE_WINDOW_SYSTEM
27544 /* Look for a `pointer' property. */
27545 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27547 /* Check overlays first. */
27548 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27549 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27551 if (NILP (pointer
))
27553 Lisp_Object obj
= glyph
->object
;
27554 ptrdiff_t charpos
= glyph
->charpos
;
27556 /* Try text properties. */
27559 && charpos
< SCHARS (obj
))
27561 pointer
= Fget_text_property (make_number (charpos
),
27563 if (NILP (pointer
))
27565 /* If the string itself doesn't specify a pointer,
27566 see if the buffer text ``under'' it does. */
27567 struct glyph_row
*r
27568 = MATRIX_ROW (w
->current_matrix
, vpos
);
27569 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27570 ptrdiff_t p
= string_buffer_position (obj
, start
);
27572 pointer
= Fget_char_property (make_number (p
),
27573 Qpointer
, w
->buffer
);
27576 else if (BUFFERP (obj
)
27579 pointer
= Fget_text_property (make_number (charpos
),
27583 #endif /* HAVE_WINDOW_SYSTEM */
27587 current_buffer
= obuf
;
27592 #ifdef HAVE_WINDOW_SYSTEM
27593 if (FRAME_WINDOW_P (f
))
27594 define_frame_cursor1 (f
, cursor
, pointer
);
27596 /* This is here to prevent a compiler error, about "label at end of
27597 compound statement". */
27604 Clear any mouse-face on window W. This function is part of the
27605 redisplay interface, and is called from try_window_id and similar
27606 functions to ensure the mouse-highlight is off. */
27609 x_clear_window_mouse_face (struct window
*w
)
27611 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27612 Lisp_Object window
;
27615 XSETWINDOW (window
, w
);
27616 if (EQ (window
, hlinfo
->mouse_face_window
))
27617 clear_mouse_face (hlinfo
);
27623 Just discard the mouse face information for frame F, if any.
27624 This is used when the size of F is changed. */
27627 cancel_mouse_face (struct frame
*f
)
27629 Lisp_Object window
;
27630 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27632 window
= hlinfo
->mouse_face_window
;
27633 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27635 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27636 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27637 hlinfo
->mouse_face_window
= Qnil
;
27643 /***********************************************************************
27645 ***********************************************************************/
27647 #ifdef HAVE_WINDOW_SYSTEM
27649 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27650 which intersects rectangle R. R is in window-relative coordinates. */
27653 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27654 enum glyph_row_area area
)
27656 struct glyph
*first
= row
->glyphs
[area
];
27657 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27658 struct glyph
*last
;
27659 int first_x
, start_x
, x
;
27661 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27662 /* If row extends face to end of line write the whole line. */
27663 draw_glyphs (w
, 0, row
, area
,
27664 0, row
->used
[area
],
27665 DRAW_NORMAL_TEXT
, 0);
27668 /* Set START_X to the window-relative start position for drawing glyphs of
27669 AREA. The first glyph of the text area can be partially visible.
27670 The first glyphs of other areas cannot. */
27671 start_x
= window_box_left_offset (w
, area
);
27673 if (area
== TEXT_AREA
)
27676 /* Find the first glyph that must be redrawn. */
27678 && x
+ first
->pixel_width
< r
->x
)
27680 x
+= first
->pixel_width
;
27684 /* Find the last one. */
27688 && x
< r
->x
+ r
->width
)
27690 x
+= last
->pixel_width
;
27696 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27697 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27698 DRAW_NORMAL_TEXT
, 0);
27703 /* Redraw the parts of the glyph row ROW on window W intersecting
27704 rectangle R. R is in window-relative coordinates. Value is
27705 non-zero if mouse-face was overwritten. */
27708 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27710 xassert (row
->enabled_p
);
27712 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27713 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27714 0, row
->used
[TEXT_AREA
],
27715 DRAW_NORMAL_TEXT
, 0);
27718 if (row
->used
[LEFT_MARGIN_AREA
])
27719 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27720 if (row
->used
[TEXT_AREA
])
27721 expose_area (w
, row
, r
, TEXT_AREA
);
27722 if (row
->used
[RIGHT_MARGIN_AREA
])
27723 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27724 draw_row_fringe_bitmaps (w
, row
);
27727 return row
->mouse_face_p
;
27731 /* Redraw those parts of glyphs rows during expose event handling that
27732 overlap other rows. Redrawing of an exposed line writes over parts
27733 of lines overlapping that exposed line; this function fixes that.
27735 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27736 row in W's current matrix that is exposed and overlaps other rows.
27737 LAST_OVERLAPPING_ROW is the last such row. */
27740 expose_overlaps (struct window
*w
,
27741 struct glyph_row
*first_overlapping_row
,
27742 struct glyph_row
*last_overlapping_row
,
27745 struct glyph_row
*row
;
27747 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27748 if (row
->overlapping_p
)
27750 xassert (row
->enabled_p
&& !row
->mode_line_p
);
27753 if (row
->used
[LEFT_MARGIN_AREA
])
27754 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
27756 if (row
->used
[TEXT_AREA
])
27757 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
27759 if (row
->used
[RIGHT_MARGIN_AREA
])
27760 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
27766 /* Return non-zero if W's cursor intersects rectangle R. */
27769 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
27771 XRectangle cr
, result
;
27772 struct glyph
*cursor_glyph
;
27773 struct glyph_row
*row
;
27775 if (w
->phys_cursor
.vpos
>= 0
27776 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
27777 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
27779 && row
->cursor_in_fringe_p
)
27781 /* Cursor is in the fringe. */
27782 cr
.x
= window_box_right_offset (w
,
27783 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
27784 ? RIGHT_MARGIN_AREA
27787 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
27788 cr
.height
= row
->height
;
27789 return x_intersect_rectangles (&cr
, r
, &result
);
27792 cursor_glyph
= get_phys_cursor_glyph (w
);
27795 /* r is relative to W's box, but w->phys_cursor.x is relative
27796 to left edge of W's TEXT area. Adjust it. */
27797 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
27798 cr
.y
= w
->phys_cursor
.y
;
27799 cr
.width
= cursor_glyph
->pixel_width
;
27800 cr
.height
= w
->phys_cursor_height
;
27801 /* ++KFS: W32 version used W32-specific IntersectRect here, but
27802 I assume the effect is the same -- and this is portable. */
27803 return x_intersect_rectangles (&cr
, r
, &result
);
27805 /* If we don't understand the format, pretend we're not in the hot-spot. */
27811 Draw a vertical window border to the right of window W if W doesn't
27812 have vertical scroll bars. */
27815 x_draw_vertical_border (struct window
*w
)
27817 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27819 /* We could do better, if we knew what type of scroll-bar the adjacent
27820 windows (on either side) have... But we don't :-(
27821 However, I think this works ok. ++KFS 2003-04-25 */
27823 /* Redraw borders between horizontally adjacent windows. Don't
27824 do it for frames with vertical scroll bars because either the
27825 right scroll bar of a window, or the left scroll bar of its
27826 neighbor will suffice as a border. */
27827 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
27830 if (!WINDOW_RIGHTMOST_P (w
)
27831 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
27833 int x0
, x1
, y0
, y1
;
27835 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27838 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27841 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
27843 else if (!WINDOW_LEFTMOST_P (w
)
27844 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
27846 int x0
, x1
, y0
, y1
;
27848 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27851 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27854 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
27859 /* Redraw the part of window W intersection rectangle FR. Pixel
27860 coordinates in FR are frame-relative. Call this function with
27861 input blocked. Value is non-zero if the exposure overwrites
27865 expose_window (struct window
*w
, XRectangle
*fr
)
27867 struct frame
*f
= XFRAME (w
->frame
);
27869 int mouse_face_overwritten_p
= 0;
27871 /* If window is not yet fully initialized, do nothing. This can
27872 happen when toolkit scroll bars are used and a window is split.
27873 Reconfiguring the scroll bar will generate an expose for a newly
27875 if (w
->current_matrix
== NULL
)
27878 /* When we're currently updating the window, display and current
27879 matrix usually don't agree. Arrange for a thorough display
27881 if (w
== updated_window
)
27883 SET_FRAME_GARBAGED (f
);
27887 /* Frame-relative pixel rectangle of W. */
27888 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
27889 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
27890 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
27891 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
27893 if (x_intersect_rectangles (fr
, &wr
, &r
))
27895 int yb
= window_text_bottom_y (w
);
27896 struct glyph_row
*row
;
27897 int cursor_cleared_p
, phys_cursor_on_p
;
27898 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
27900 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
27901 r
.x
, r
.y
, r
.width
, r
.height
));
27903 /* Convert to window coordinates. */
27904 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
27905 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
27907 /* Turn off the cursor. */
27908 if (!w
->pseudo_window_p
27909 && phys_cursor_in_rect_p (w
, &r
))
27911 x_clear_cursor (w
);
27912 cursor_cleared_p
= 1;
27915 cursor_cleared_p
= 0;
27917 /* If the row containing the cursor extends face to end of line,
27918 then expose_area might overwrite the cursor outside the
27919 rectangle and thus notice_overwritten_cursor might clear
27920 w->phys_cursor_on_p. We remember the original value and
27921 check later if it is changed. */
27922 phys_cursor_on_p
= w
->phys_cursor_on_p
;
27924 /* Update lines intersecting rectangle R. */
27925 first_overlapping_row
= last_overlapping_row
= NULL
;
27926 for (row
= w
->current_matrix
->rows
;
27931 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
27933 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
27934 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
27935 || (r
.y
>= y0
&& r
.y
< y1
)
27936 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
27938 /* A header line may be overlapping, but there is no need
27939 to fix overlapping areas for them. KFS 2005-02-12 */
27940 if (row
->overlapping_p
&& !row
->mode_line_p
)
27942 if (first_overlapping_row
== NULL
)
27943 first_overlapping_row
= row
;
27944 last_overlapping_row
= row
;
27948 if (expose_line (w
, row
, &r
))
27949 mouse_face_overwritten_p
= 1;
27952 else if (row
->overlapping_p
)
27954 /* We must redraw a row overlapping the exposed area. */
27956 ? y0
+ row
->phys_height
> r
.y
27957 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
27959 if (first_overlapping_row
== NULL
)
27960 first_overlapping_row
= row
;
27961 last_overlapping_row
= row
;
27969 /* Display the mode line if there is one. */
27970 if (WINDOW_WANTS_MODELINE_P (w
)
27971 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
27973 && row
->y
< r
.y
+ r
.height
)
27975 if (expose_line (w
, row
, &r
))
27976 mouse_face_overwritten_p
= 1;
27979 if (!w
->pseudo_window_p
)
27981 /* Fix the display of overlapping rows. */
27982 if (first_overlapping_row
)
27983 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
27986 /* Draw border between windows. */
27987 x_draw_vertical_border (w
);
27989 /* Turn the cursor on again. */
27990 if (cursor_cleared_p
27991 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
27992 update_window_cursor (w
, 1);
27996 return mouse_face_overwritten_p
;
28001 /* Redraw (parts) of all windows in the window tree rooted at W that
28002 intersect R. R contains frame pixel coordinates. Value is
28003 non-zero if the exposure overwrites mouse-face. */
28006 expose_window_tree (struct window
*w
, XRectangle
*r
)
28008 struct frame
*f
= XFRAME (w
->frame
);
28009 int mouse_face_overwritten_p
= 0;
28011 while (w
&& !FRAME_GARBAGED_P (f
))
28013 if (!NILP (w
->hchild
))
28014 mouse_face_overwritten_p
28015 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28016 else if (!NILP (w
->vchild
))
28017 mouse_face_overwritten_p
28018 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28020 mouse_face_overwritten_p
|= expose_window (w
, r
);
28022 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28025 return mouse_face_overwritten_p
;
28030 Redisplay an exposed area of frame F. X and Y are the upper-left
28031 corner of the exposed rectangle. W and H are width and height of
28032 the exposed area. All are pixel values. W or H zero means redraw
28033 the entire frame. */
28036 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28039 int mouse_face_overwritten_p
= 0;
28041 TRACE ((stderr
, "expose_frame "));
28043 /* No need to redraw if frame will be redrawn soon. */
28044 if (FRAME_GARBAGED_P (f
))
28046 TRACE ((stderr
, " garbaged\n"));
28050 /* If basic faces haven't been realized yet, there is no point in
28051 trying to redraw anything. This can happen when we get an expose
28052 event while Emacs is starting, e.g. by moving another window. */
28053 if (FRAME_FACE_CACHE (f
) == NULL
28054 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28056 TRACE ((stderr
, " no faces\n"));
28060 if (w
== 0 || h
== 0)
28063 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28064 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28074 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28075 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28077 if (WINDOWP (f
->tool_bar_window
))
28078 mouse_face_overwritten_p
28079 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28081 #ifdef HAVE_X_WINDOWS
28083 #ifndef USE_X_TOOLKIT
28084 if (WINDOWP (f
->menu_bar_window
))
28085 mouse_face_overwritten_p
28086 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28087 #endif /* not USE_X_TOOLKIT */
28091 /* Some window managers support a focus-follows-mouse style with
28092 delayed raising of frames. Imagine a partially obscured frame,
28093 and moving the mouse into partially obscured mouse-face on that
28094 frame. The visible part of the mouse-face will be highlighted,
28095 then the WM raises the obscured frame. With at least one WM, KDE
28096 2.1, Emacs is not getting any event for the raising of the frame
28097 (even tried with SubstructureRedirectMask), only Expose events.
28098 These expose events will draw text normally, i.e. not
28099 highlighted. Which means we must redo the highlight here.
28100 Subsume it under ``we love X''. --gerd 2001-08-15 */
28101 /* Included in Windows version because Windows most likely does not
28102 do the right thing if any third party tool offers
28103 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28104 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28106 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28107 if (f
== hlinfo
->mouse_face_mouse_frame
)
28109 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28110 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28111 clear_mouse_face (hlinfo
);
28112 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28119 Determine the intersection of two rectangles R1 and R2. Return
28120 the intersection in *RESULT. Value is non-zero if RESULT is not
28124 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28126 XRectangle
*left
, *right
;
28127 XRectangle
*upper
, *lower
;
28128 int intersection_p
= 0;
28130 /* Rearrange so that R1 is the left-most rectangle. */
28132 left
= r1
, right
= r2
;
28134 left
= r2
, right
= r1
;
28136 /* X0 of the intersection is right.x0, if this is inside R1,
28137 otherwise there is no intersection. */
28138 if (right
->x
<= left
->x
+ left
->width
)
28140 result
->x
= right
->x
;
28142 /* The right end of the intersection is the minimum of
28143 the right ends of left and right. */
28144 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28147 /* Same game for Y. */
28149 upper
= r1
, lower
= r2
;
28151 upper
= r2
, lower
= r1
;
28153 /* The upper end of the intersection is lower.y0, if this is inside
28154 of upper. Otherwise, there is no intersection. */
28155 if (lower
->y
<= upper
->y
+ upper
->height
)
28157 result
->y
= lower
->y
;
28159 /* The lower end of the intersection is the minimum of the lower
28160 ends of upper and lower. */
28161 result
->height
= (min (lower
->y
+ lower
->height
,
28162 upper
->y
+ upper
->height
)
28164 intersection_p
= 1;
28168 return intersection_p
;
28171 #endif /* HAVE_WINDOW_SYSTEM */
28174 /***********************************************************************
28176 ***********************************************************************/
28179 syms_of_xdisp (void)
28181 Vwith_echo_area_save_vector
= Qnil
;
28182 staticpro (&Vwith_echo_area_save_vector
);
28184 Vmessage_stack
= Qnil
;
28185 staticpro (&Vmessage_stack
);
28187 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28189 message_dolog_marker1
= Fmake_marker ();
28190 staticpro (&message_dolog_marker1
);
28191 message_dolog_marker2
= Fmake_marker ();
28192 staticpro (&message_dolog_marker2
);
28193 message_dolog_marker3
= Fmake_marker ();
28194 staticpro (&message_dolog_marker3
);
28197 defsubr (&Sdump_frame_glyph_matrix
);
28198 defsubr (&Sdump_glyph_matrix
);
28199 defsubr (&Sdump_glyph_row
);
28200 defsubr (&Sdump_tool_bar_row
);
28201 defsubr (&Strace_redisplay
);
28202 defsubr (&Strace_to_stderr
);
28204 #ifdef HAVE_WINDOW_SYSTEM
28205 defsubr (&Stool_bar_lines_needed
);
28206 defsubr (&Slookup_image_map
);
28208 defsubr (&Sformat_mode_line
);
28209 defsubr (&Sinvisible_p
);
28210 defsubr (&Scurrent_bidi_paragraph_direction
);
28212 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28213 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28214 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28215 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28216 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28217 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28218 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28219 DEFSYM (Qeval
, "eval");
28220 DEFSYM (QCdata
, ":data");
28221 DEFSYM (Qdisplay
, "display");
28222 DEFSYM (Qspace_width
, "space-width");
28223 DEFSYM (Qraise
, "raise");
28224 DEFSYM (Qslice
, "slice");
28225 DEFSYM (Qspace
, "space");
28226 DEFSYM (Qmargin
, "margin");
28227 DEFSYM (Qpointer
, "pointer");
28228 DEFSYM (Qleft_margin
, "left-margin");
28229 DEFSYM (Qright_margin
, "right-margin");
28230 DEFSYM (Qcenter
, "center");
28231 DEFSYM (Qline_height
, "line-height");
28232 DEFSYM (QCalign_to
, ":align-to");
28233 DEFSYM (QCrelative_width
, ":relative-width");
28234 DEFSYM (QCrelative_height
, ":relative-height");
28235 DEFSYM (QCeval
, ":eval");
28236 DEFSYM (QCpropertize
, ":propertize");
28237 DEFSYM (QCfile
, ":file");
28238 DEFSYM (Qfontified
, "fontified");
28239 DEFSYM (Qfontification_functions
, "fontification-functions");
28240 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28241 DEFSYM (Qescape_glyph
, "escape-glyph");
28242 DEFSYM (Qnobreak_space
, "nobreak-space");
28243 DEFSYM (Qimage
, "image");
28244 DEFSYM (Qtext
, "text");
28245 DEFSYM (Qboth
, "both");
28246 DEFSYM (Qboth_horiz
, "both-horiz");
28247 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28248 DEFSYM (QCmap
, ":map");
28249 DEFSYM (QCpointer
, ":pointer");
28250 DEFSYM (Qrect
, "rect");
28251 DEFSYM (Qcircle
, "circle");
28252 DEFSYM (Qpoly
, "poly");
28253 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28254 DEFSYM (Qgrow_only
, "grow-only");
28255 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28256 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28257 DEFSYM (Qposition
, "position");
28258 DEFSYM (Qbuffer_position
, "buffer-position");
28259 DEFSYM (Qobject
, "object");
28260 DEFSYM (Qbar
, "bar");
28261 DEFSYM (Qhbar
, "hbar");
28262 DEFSYM (Qbox
, "box");
28263 DEFSYM (Qhollow
, "hollow");
28264 DEFSYM (Qhand
, "hand");
28265 DEFSYM (Qarrow
, "arrow");
28266 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28268 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28269 Fcons (intern_c_string ("void-variable"), Qnil
)),
28271 staticpro (&list_of_error
);
28273 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28274 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28275 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28276 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28278 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28279 staticpro (&echo_buffer
[0]);
28280 staticpro (&echo_buffer
[1]);
28282 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28283 staticpro (&echo_area_buffer
[0]);
28284 staticpro (&echo_area_buffer
[1]);
28286 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28287 staticpro (&Vmessages_buffer_name
);
28289 mode_line_proptrans_alist
= Qnil
;
28290 staticpro (&mode_line_proptrans_alist
);
28291 mode_line_string_list
= Qnil
;
28292 staticpro (&mode_line_string_list
);
28293 mode_line_string_face
= Qnil
;
28294 staticpro (&mode_line_string_face
);
28295 mode_line_string_face_prop
= Qnil
;
28296 staticpro (&mode_line_string_face_prop
);
28297 Vmode_line_unwind_vector
= Qnil
;
28298 staticpro (&Vmode_line_unwind_vector
);
28300 help_echo_string
= Qnil
;
28301 staticpro (&help_echo_string
);
28302 help_echo_object
= Qnil
;
28303 staticpro (&help_echo_object
);
28304 help_echo_window
= Qnil
;
28305 staticpro (&help_echo_window
);
28306 previous_help_echo_string
= Qnil
;
28307 staticpro (&previous_help_echo_string
);
28308 help_echo_pos
= -1;
28310 DEFSYM (Qright_to_left
, "right-to-left");
28311 DEFSYM (Qleft_to_right
, "left-to-right");
28313 #ifdef HAVE_WINDOW_SYSTEM
28314 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28315 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28316 For example, if a block cursor is over a tab, it will be drawn as
28317 wide as that tab on the display. */);
28318 x_stretch_cursor_p
= 0;
28321 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28322 doc
: /* Non-nil means highlight trailing whitespace.
28323 The face used for trailing whitespace is `trailing-whitespace'. */);
28324 Vshow_trailing_whitespace
= Qnil
;
28326 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28327 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28328 If the value is t, Emacs highlights non-ASCII chars which have the
28329 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28330 or `escape-glyph' face respectively.
28332 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28333 U+2011 (non-breaking hyphen) are affected.
28335 Any other non-nil value means to display these characters as a escape
28336 glyph followed by an ordinary space or hyphen.
28338 A value of nil means no special handling of these characters. */);
28339 Vnobreak_char_display
= Qt
;
28341 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28342 doc
: /* The pointer shape to show in void text areas.
28343 A value of nil means to show the text pointer. Other options are `arrow',
28344 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28345 Vvoid_text_area_pointer
= Qarrow
;
28347 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28348 doc
: /* Non-nil means don't actually do any redisplay.
28349 This is used for internal purposes. */);
28350 Vinhibit_redisplay
= Qnil
;
28352 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28353 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28354 Vglobal_mode_string
= Qnil
;
28356 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28357 doc
: /* Marker for where to display an arrow on top of the buffer text.
28358 This must be the beginning of a line in order to work.
28359 See also `overlay-arrow-string'. */);
28360 Voverlay_arrow_position
= Qnil
;
28362 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28363 doc
: /* String to display as an arrow in non-window frames.
28364 See also `overlay-arrow-position'. */);
28365 Voverlay_arrow_string
= make_pure_c_string ("=>");
28367 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28368 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28369 The symbols on this list are examined during redisplay to determine
28370 where to display overlay arrows. */);
28371 Voverlay_arrow_variable_list
28372 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28374 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28375 doc
: /* The number of lines to try scrolling a window by when point moves out.
28376 If that fails to bring point back on frame, point is centered instead.
28377 If this is zero, point is always centered after it moves off frame.
28378 If you want scrolling to always be a line at a time, you should set
28379 `scroll-conservatively' to a large value rather than set this to 1. */);
28381 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28382 doc
: /* Scroll up to this many lines, to bring point back on screen.
28383 If point moves off-screen, redisplay will scroll by up to
28384 `scroll-conservatively' lines in order to bring point just barely
28385 onto the screen again. If that cannot be done, then redisplay
28386 recenters point as usual.
28388 If the value is greater than 100, redisplay will never recenter point,
28389 but will always scroll just enough text to bring point into view, even
28390 if you move far away.
28392 A value of zero means always recenter point if it moves off screen. */);
28393 scroll_conservatively
= 0;
28395 DEFVAR_INT ("scroll-margin", scroll_margin
,
28396 doc
: /* Number of lines of margin at the top and bottom of a window.
28397 Recenter the window whenever point gets within this many lines
28398 of the top or bottom of the window. */);
28401 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28402 doc
: /* Pixels per inch value for non-window system displays.
28403 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28404 Vdisplay_pixels_per_inch
= make_float (72.0);
28407 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28410 DEFVAR_LISP ("truncate-partial-width-windows",
28411 Vtruncate_partial_width_windows
,
28412 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28413 For an integer value, truncate lines in each window narrower than the
28414 full frame width, provided the window width is less than that integer;
28415 otherwise, respect the value of `truncate-lines'.
28417 For any other non-nil value, truncate lines in all windows that do
28418 not span the full frame width.
28420 A value of nil means to respect the value of `truncate-lines'.
28422 If `word-wrap' is enabled, you might want to reduce this. */);
28423 Vtruncate_partial_width_windows
= make_number (50);
28425 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28426 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28427 Any other value means to use the appropriate face, `mode-line',
28428 `header-line', or `menu' respectively. */);
28429 mode_line_inverse_video
= 1;
28431 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28432 doc
: /* Maximum buffer size for which line number should be displayed.
28433 If the buffer is bigger than this, the line number does not appear
28434 in the mode line. A value of nil means no limit. */);
28435 Vline_number_display_limit
= Qnil
;
28437 DEFVAR_INT ("line-number-display-limit-width",
28438 line_number_display_limit_width
,
28439 doc
: /* Maximum line width (in characters) for line number display.
28440 If the average length of the lines near point is bigger than this, then the
28441 line number may be omitted from the mode line. */);
28442 line_number_display_limit_width
= 200;
28444 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28445 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28446 highlight_nonselected_windows
= 0;
28448 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28449 doc
: /* Non-nil if more than one frame is visible on this display.
28450 Minibuffer-only frames don't count, but iconified frames do.
28451 This variable is not guaranteed to be accurate except while processing
28452 `frame-title-format' and `icon-title-format'. */);
28454 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28455 doc
: /* Template for displaying the title bar of visible frames.
28456 \(Assuming the window manager supports this feature.)
28458 This variable has the same structure as `mode-line-format', except that
28459 the %c and %l constructs are ignored. It is used only on frames for
28460 which no explicit name has been set \(see `modify-frame-parameters'). */);
28462 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28463 doc
: /* Template for displaying the title bar of an iconified frame.
28464 \(Assuming the window manager supports this feature.)
28465 This variable has the same structure as `mode-line-format' (which see),
28466 and is used only on frames for which no explicit name has been set
28467 \(see `modify-frame-parameters'). */);
28469 = Vframe_title_format
28470 = pure_cons (intern_c_string ("multiple-frames"),
28471 pure_cons (make_pure_c_string ("%b"),
28472 pure_cons (pure_cons (empty_unibyte_string
,
28473 pure_cons (intern_c_string ("invocation-name"),
28474 pure_cons (make_pure_c_string ("@"),
28475 pure_cons (intern_c_string ("system-name"),
28479 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28480 doc
: /* Maximum number of lines to keep in the message log buffer.
28481 If nil, disable message logging. If t, log messages but don't truncate
28482 the buffer when it becomes large. */);
28483 Vmessage_log_max
= make_number (100);
28485 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28486 doc
: /* Functions called before redisplay, if window sizes have changed.
28487 The value should be a list of functions that take one argument.
28488 Just before redisplay, for each frame, if any of its windows have changed
28489 size since the last redisplay, or have been split or deleted,
28490 all the functions in the list are called, with the frame as argument. */);
28491 Vwindow_size_change_functions
= Qnil
;
28493 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28494 doc
: /* List of functions to call before redisplaying a window with scrolling.
28495 Each function is called with two arguments, the window and its new
28496 display-start position. Note that these functions are also called by
28497 `set-window-buffer'. Also note that the value of `window-end' is not
28498 valid when these functions are called.
28500 Warning: Do not use this feature to alter the way the window
28501 is scrolled. It is not designed for that, and such use probably won't
28503 Vwindow_scroll_functions
= Qnil
;
28505 DEFVAR_LISP ("window-text-change-functions",
28506 Vwindow_text_change_functions
,
28507 doc
: /* Functions to call in redisplay when text in the window might change. */);
28508 Vwindow_text_change_functions
= Qnil
;
28510 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28511 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28512 Each function is called with two arguments, the window and the end trigger value.
28513 See `set-window-redisplay-end-trigger'. */);
28514 Vredisplay_end_trigger_functions
= Qnil
;
28516 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28517 doc
: /* Non-nil means autoselect window with mouse pointer.
28518 If nil, do not autoselect windows.
28519 A positive number means delay autoselection by that many seconds: a
28520 window is autoselected only after the mouse has remained in that
28521 window for the duration of the delay.
28522 A negative number has a similar effect, but causes windows to be
28523 autoselected only after the mouse has stopped moving. \(Because of
28524 the way Emacs compares mouse events, you will occasionally wait twice
28525 that time before the window gets selected.\)
28526 Any other value means to autoselect window instantaneously when the
28527 mouse pointer enters it.
28529 Autoselection selects the minibuffer only if it is active, and never
28530 unselects the minibuffer if it is active.
28532 When customizing this variable make sure that the actual value of
28533 `focus-follows-mouse' matches the behavior of your window manager. */);
28534 Vmouse_autoselect_window
= Qnil
;
28536 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28537 doc
: /* Non-nil means automatically resize tool-bars.
28538 This dynamically changes the tool-bar's height to the minimum height
28539 that is needed to make all tool-bar items visible.
28540 If value is `grow-only', the tool-bar's height is only increased
28541 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28542 Vauto_resize_tool_bars
= Qt
;
28544 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28545 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28546 auto_raise_tool_bar_buttons_p
= 1;
28548 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28549 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28550 make_cursor_line_fully_visible_p
= 1;
28552 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28553 doc
: /* Border below tool-bar in pixels.
28554 If an integer, use it as the height of the border.
28555 If it is one of `internal-border-width' or `border-width', use the
28556 value of the corresponding frame parameter.
28557 Otherwise, no border is added below the tool-bar. */);
28558 Vtool_bar_border
= Qinternal_border_width
;
28560 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28561 doc
: /* Margin around tool-bar buttons in pixels.
28562 If an integer, use that for both horizontal and vertical margins.
28563 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28564 HORZ specifying the horizontal margin, and VERT specifying the
28565 vertical margin. */);
28566 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28568 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28569 doc
: /* Relief thickness of tool-bar buttons. */);
28570 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28572 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28573 doc
: /* Tool bar style to use.
28575 image - show images only
28576 text - show text only
28577 both - show both, text below image
28578 both-horiz - show text to the right of the image
28579 text-image-horiz - show text to the left of the image
28580 any other - use system default or image if no system default. */);
28581 Vtool_bar_style
= Qnil
;
28583 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28584 doc
: /* Maximum number of characters a label can have to be shown.
28585 The tool bar style must also show labels for this to have any effect, see
28586 `tool-bar-style'. */);
28587 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28589 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28590 doc
: /* List of functions to call to fontify regions of text.
28591 Each function is called with one argument POS. Functions must
28592 fontify a region starting at POS in the current buffer, and give
28593 fontified regions the property `fontified'. */);
28594 Vfontification_functions
= Qnil
;
28595 Fmake_variable_buffer_local (Qfontification_functions
);
28597 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28598 unibyte_display_via_language_environment
,
28599 doc
: /* Non-nil means display unibyte text according to language environment.
28600 Specifically, this means that raw bytes in the range 160-255 decimal
28601 are displayed by converting them to the equivalent multibyte characters
28602 according to the current language environment. As a result, they are
28603 displayed according to the current fontset.
28605 Note that this variable affects only how these bytes are displayed,
28606 but does not change the fact they are interpreted as raw bytes. */);
28607 unibyte_display_via_language_environment
= 0;
28609 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28610 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
28611 If a float, it specifies a fraction of the mini-window frame's height.
28612 If an integer, it specifies a number of lines. */);
28613 Vmax_mini_window_height
= make_float (0.25);
28615 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28616 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28617 A value of nil means don't automatically resize mini-windows.
28618 A value of t means resize them to fit the text displayed in them.
28619 A value of `grow-only', the default, means let mini-windows grow only;
28620 they return to their normal size when the minibuffer is closed, or the
28621 echo area becomes empty. */);
28622 Vresize_mini_windows
= Qgrow_only
;
28624 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28625 doc
: /* Alist specifying how to blink the cursor off.
28626 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28627 `cursor-type' frame-parameter or variable equals ON-STATE,
28628 comparing using `equal', Emacs uses OFF-STATE to specify
28629 how to blink it off. ON-STATE and OFF-STATE are values for
28630 the `cursor-type' frame parameter.
28632 If a frame's ON-STATE has no entry in this list,
28633 the frame's other specifications determine how to blink the cursor off. */);
28634 Vblink_cursor_alist
= Qnil
;
28636 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28637 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28638 If non-nil, windows are automatically scrolled horizontally to make
28639 point visible. */);
28640 automatic_hscrolling_p
= 1;
28641 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28643 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28644 doc
: /* How many columns away from the window edge point is allowed to get
28645 before automatic hscrolling will horizontally scroll the window. */);
28646 hscroll_margin
= 5;
28648 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28649 doc
: /* How many columns to scroll the window when point gets too close to the edge.
28650 When point is less than `hscroll-margin' columns from the window
28651 edge, automatic hscrolling will scroll the window by the amount of columns
28652 determined by this variable. If its value is a positive integer, scroll that
28653 many columns. If it's a positive floating-point number, it specifies the
28654 fraction of the window's width to scroll. If it's nil or zero, point will be
28655 centered horizontally after the scroll. Any other value, including negative
28656 numbers, are treated as if the value were zero.
28658 Automatic hscrolling always moves point outside the scroll margin, so if
28659 point was more than scroll step columns inside the margin, the window will
28660 scroll more than the value given by the scroll step.
28662 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28663 and `scroll-right' overrides this variable's effect. */);
28664 Vhscroll_step
= make_number (0);
28666 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28667 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28668 Bind this around calls to `message' to let it take effect. */);
28669 message_truncate_lines
= 0;
28671 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28672 doc
: /* Normal hook run to update the menu bar definitions.
28673 Redisplay runs this hook before it redisplays the menu bar.
28674 This is used to update submenus such as Buffers,
28675 whose contents depend on various data. */);
28676 Vmenu_bar_update_hook
= Qnil
;
28678 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28679 doc
: /* Frame for which we are updating a menu.
28680 The enable predicate for a menu binding should check this variable. */);
28681 Vmenu_updating_frame
= Qnil
;
28683 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28684 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28685 inhibit_menubar_update
= 0;
28687 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28688 doc
: /* Prefix prepended to all continuation lines at display time.
28689 The value may be a string, an image, or a stretch-glyph; it is
28690 interpreted in the same way as the value of a `display' text property.
28692 This variable is overridden by any `wrap-prefix' text or overlay
28695 To add a prefix to non-continuation lines, use `line-prefix'. */);
28696 Vwrap_prefix
= Qnil
;
28697 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28698 Fmake_variable_buffer_local (Qwrap_prefix
);
28700 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28701 doc
: /* Prefix prepended to all non-continuation lines at display time.
28702 The value may be a string, an image, or a stretch-glyph; it is
28703 interpreted in the same way as the value of a `display' text property.
28705 This variable is overridden by any `line-prefix' text or overlay
28708 To add a prefix to continuation lines, use `wrap-prefix'. */);
28709 Vline_prefix
= Qnil
;
28710 DEFSYM (Qline_prefix
, "line-prefix");
28711 Fmake_variable_buffer_local (Qline_prefix
);
28713 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28714 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28715 inhibit_eval_during_redisplay
= 0;
28717 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28718 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28719 inhibit_free_realized_faces
= 0;
28722 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28723 doc
: /* Inhibit try_window_id display optimization. */);
28724 inhibit_try_window_id
= 0;
28726 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28727 doc
: /* Inhibit try_window_reusing display optimization. */);
28728 inhibit_try_window_reusing
= 0;
28730 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28731 doc
: /* Inhibit try_cursor_movement display optimization. */);
28732 inhibit_try_cursor_movement
= 0;
28733 #endif /* GLYPH_DEBUG */
28735 DEFVAR_INT ("overline-margin", overline_margin
,
28736 doc
: /* Space between overline and text, in pixels.
28737 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28738 margin to the character height. */);
28739 overline_margin
= 2;
28741 DEFVAR_INT ("underline-minimum-offset",
28742 underline_minimum_offset
,
28743 doc
: /* Minimum distance between baseline and underline.
28744 This can improve legibility of underlined text at small font sizes,
28745 particularly when using variable `x-use-underline-position-properties'
28746 with fonts that specify an UNDERLINE_POSITION relatively close to the
28747 baseline. The default value is 1. */);
28748 underline_minimum_offset
= 1;
28750 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
28751 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
28752 This feature only works when on a window system that can change
28753 cursor shapes. */);
28754 display_hourglass_p
= 1;
28756 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
28757 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
28758 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
28760 hourglass_atimer
= NULL
;
28761 hourglass_shown_p
= 0;
28763 DEFSYM (Qglyphless_char
, "glyphless-char");
28764 DEFSYM (Qhex_code
, "hex-code");
28765 DEFSYM (Qempty_box
, "empty-box");
28766 DEFSYM (Qthin_space
, "thin-space");
28767 DEFSYM (Qzero_width
, "zero-width");
28769 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
28770 /* Intern this now in case it isn't already done.
28771 Setting this variable twice is harmless.
28772 But don't staticpro it here--that is done in alloc.c. */
28773 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
28774 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
28776 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
28777 doc
: /* Char-table defining glyphless characters.
28778 Each element, if non-nil, should be one of the following:
28779 an ASCII acronym string: display this string in a box
28780 `hex-code': display the hexadecimal code of a character in a box
28781 `empty-box': display as an empty box
28782 `thin-space': display as 1-pixel width space
28783 `zero-width': don't display
28784 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
28785 display method for graphical terminals and text terminals respectively.
28786 GRAPHICAL and TEXT should each have one of the values listed above.
28788 The char-table has one extra slot to control the display of a character for
28789 which no font is found. This slot only takes effect on graphical terminals.
28790 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
28791 `thin-space'. The default is `empty-box'. */);
28792 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
28793 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
28798 /* Initialize this module when Emacs starts. */
28803 current_header_line_height
= current_mode_line_height
= -1;
28805 CHARPOS (this_line_start_pos
) = 0;
28807 if (!noninteractive
)
28809 struct window
*m
= XWINDOW (minibuf_window
);
28810 Lisp_Object frame
= m
->frame
;
28811 struct frame
*f
= XFRAME (frame
);
28812 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
28813 struct window
*r
= XWINDOW (root
);
28816 echo_area_window
= minibuf_window
;
28818 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
28819 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
28820 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
28821 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
28822 XSETFASTINT (m
->total_lines
, 1);
28823 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
28825 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
28826 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
28827 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
28829 /* The default ellipsis glyphs `...'. */
28830 for (i
= 0; i
< 3; ++i
)
28831 default_invis_vector
[i
] = make_number ('.');
28835 /* Allocate the buffer for frame titles.
28836 Also used for `format-mode-line'. */
28838 mode_line_noprop_buf
= (char *) xmalloc (size
);
28839 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
28840 mode_line_noprop_ptr
= mode_line_noprop_buf
;
28841 mode_line_target
= MODE_LINE_DISPLAY
;
28844 help_echo_showing_p
= 0;
28847 /* Since w32 does not support atimers, it defines its own implementation of
28848 the following three functions in w32fns.c. */
28851 /* Platform-independent portion of hourglass implementation. */
28853 /* Return non-zero if hourglass timer has been started or hourglass is
28856 hourglass_started (void)
28858 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
28861 /* Cancel a currently active hourglass timer, and start a new one. */
28863 start_hourglass (void)
28865 #if defined (HAVE_WINDOW_SYSTEM)
28867 int secs
= DEFAULT_HOURGLASS_DELAY
, usecs
= 0;
28869 cancel_hourglass ();
28871 if (NUMBERP (Vhourglass_delay
))
28873 double duration
= extract_float (Vhourglass_delay
);
28875 duration_to_sec_usec (duration
, &secs
, &usecs
);
28878 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
28879 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
28880 show_hourglass
, NULL
);
28885 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
28888 cancel_hourglass (void)
28890 #if defined (HAVE_WINDOW_SYSTEM)
28891 if (hourglass_atimer
)
28893 cancel_atimer (hourglass_atimer
);
28894 hourglass_atimer
= NULL
;
28897 if (hourglass_shown_p
)
28901 #endif /* ! WINDOWSNT */