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
;
2757 IT_CHARPOS (*it
) = charpos
;
2759 /* Compute byte position if not specified. */
2760 if (bytepos
< charpos
)
2761 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2763 IT_BYTEPOS (*it
) = bytepos
;
2765 it
->start
= it
->current
;
2766 /* Do we need to reorder bidirectional text? Not if this is a
2767 unibyte buffer: by definition, none of the single-byte
2768 characters are strong R2L, so no reordering is needed. And
2769 bidi.c doesn't support unibyte buffers anyway. Also, don't
2770 reorder while we are loading loadup.el, since the tables of
2771 character properties needed for reordering are not yet
2775 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2778 /* If we are to reorder bidirectional text, init the bidi
2782 /* Note the paragraph direction that this buffer wants to
2784 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2786 it
->paragraph_embedding
= L2R
;
2787 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2789 it
->paragraph_embedding
= R2L
;
2791 it
->paragraph_embedding
= NEUTRAL_DIR
;
2792 bidi_unshelve_cache (NULL
, 0);
2793 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2797 /* Compute faces etc. */
2798 reseat (it
, it
->current
.pos
, 1);
2805 /* Initialize IT for the display of window W with window start POS. */
2808 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2810 struct glyph_row
*row
;
2811 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2813 row
= w
->desired_matrix
->rows
+ first_vpos
;
2814 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2815 it
->first_vpos
= first_vpos
;
2817 /* Don't reseat to previous visible line start if current start
2818 position is in a string or image. */
2819 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2821 int start_at_line_beg_p
;
2822 int first_y
= it
->current_y
;
2824 /* If window start is not at a line start, skip forward to POS to
2825 get the correct continuation lines width. */
2826 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2827 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2828 if (!start_at_line_beg_p
)
2832 reseat_at_previous_visible_line_start (it
);
2833 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2835 new_x
= it
->current_x
+ it
->pixel_width
;
2837 /* If lines are continued, this line may end in the middle
2838 of a multi-glyph character (e.g. a control character
2839 displayed as \003, or in the middle of an overlay
2840 string). In this case move_it_to above will not have
2841 taken us to the start of the continuation line but to the
2842 end of the continued line. */
2843 if (it
->current_x
> 0
2844 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2845 && (/* And glyph doesn't fit on the line. */
2846 new_x
> it
->last_visible_x
2847 /* Or it fits exactly and we're on a window
2849 || (new_x
== it
->last_visible_x
2850 && FRAME_WINDOW_P (it
->f
))))
2852 if ((it
->current
.dpvec_index
>= 0
2853 || it
->current
.overlay_string_index
>= 0)
2854 /* If we are on a newline from a display vector or
2855 overlay string, then we are already at the end of
2856 a screen line; no need to go to the next line in
2857 that case, as this line is not really continued.
2858 (If we do go to the next line, C-e will not DTRT.) */
2861 set_iterator_to_next (it
, 1);
2862 move_it_in_display_line_to (it
, -1, -1, 0);
2865 it
->continuation_lines_width
+= it
->current_x
;
2867 /* If the character at POS is displayed via a display
2868 vector, move_it_to above stops at the final glyph of
2869 IT->dpvec. To make the caller redisplay that character
2870 again (a.k.a. start at POS), we need to reset the
2871 dpvec_index to the beginning of IT->dpvec. */
2872 else if (it
->current
.dpvec_index
>= 0)
2873 it
->current
.dpvec_index
= 0;
2875 /* We're starting a new display line, not affected by the
2876 height of the continued line, so clear the appropriate
2877 fields in the iterator structure. */
2878 it
->max_ascent
= it
->max_descent
= 0;
2879 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2881 it
->current_y
= first_y
;
2883 it
->current_x
= it
->hpos
= 0;
2889 /* Return 1 if POS is a position in ellipses displayed for invisible
2890 text. W is the window we display, for text property lookup. */
2893 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2895 Lisp_Object prop
, window
;
2897 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2899 /* If POS specifies a position in a display vector, this might
2900 be for an ellipsis displayed for invisible text. We won't
2901 get the iterator set up for delivering that ellipsis unless
2902 we make sure that it gets aware of the invisible text. */
2903 if (pos
->dpvec_index
>= 0
2904 && pos
->overlay_string_index
< 0
2905 && CHARPOS (pos
->string_pos
) < 0
2907 && (XSETWINDOW (window
, w
),
2908 prop
= Fget_char_property (make_number (charpos
),
2909 Qinvisible
, window
),
2910 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2912 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2914 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2921 /* Initialize IT for stepping through current_buffer in window W,
2922 starting at position POS that includes overlay string and display
2923 vector/ control character translation position information. Value
2924 is zero if there are overlay strings with newlines at POS. */
2927 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2929 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2930 int i
, overlay_strings_with_newlines
= 0;
2932 /* If POS specifies a position in a display vector, this might
2933 be for an ellipsis displayed for invisible text. We won't
2934 get the iterator set up for delivering that ellipsis unless
2935 we make sure that it gets aware of the invisible text. */
2936 if (in_ellipses_for_invisible_text_p (pos
, w
))
2942 /* Keep in mind: the call to reseat in init_iterator skips invisible
2943 text, so we might end up at a position different from POS. This
2944 is only a problem when POS is a row start after a newline and an
2945 overlay starts there with an after-string, and the overlay has an
2946 invisible property. Since we don't skip invisible text in
2947 display_line and elsewhere immediately after consuming the
2948 newline before the row start, such a POS will not be in a string,
2949 but the call to init_iterator below will move us to the
2951 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2953 /* This only scans the current chunk -- it should scan all chunks.
2954 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2955 to 16 in 22.1 to make this a lesser problem. */
2956 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2958 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2959 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2961 while (s
< e
&& *s
!= '\n')
2966 overlay_strings_with_newlines
= 1;
2971 /* If position is within an overlay string, set up IT to the right
2973 if (pos
->overlay_string_index
>= 0)
2977 /* If the first overlay string happens to have a `display'
2978 property for an image, the iterator will be set up for that
2979 image, and we have to undo that setup first before we can
2980 correct the overlay string index. */
2981 if (it
->method
== GET_FROM_IMAGE
)
2984 /* We already have the first chunk of overlay strings in
2985 IT->overlay_strings. Load more until the one for
2986 pos->overlay_string_index is in IT->overlay_strings. */
2987 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2989 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2990 it
->current
.overlay_string_index
= 0;
2993 load_overlay_strings (it
, 0);
2994 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2998 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2999 relative_index
= (it
->current
.overlay_string_index
3000 % OVERLAY_STRING_CHUNK_SIZE
);
3001 it
->string
= it
->overlay_strings
[relative_index
];
3002 xassert (STRINGP (it
->string
));
3003 it
->current
.string_pos
= pos
->string_pos
;
3004 it
->method
= GET_FROM_STRING
;
3007 if (CHARPOS (pos
->string_pos
) >= 0)
3009 /* Recorded position is not in an overlay string, but in another
3010 string. This can only be a string from a `display' property.
3011 IT should already be filled with that string. */
3012 it
->current
.string_pos
= pos
->string_pos
;
3013 xassert (STRINGP (it
->string
));
3016 /* Restore position in display vector translations, control
3017 character translations or ellipses. */
3018 if (pos
->dpvec_index
>= 0)
3020 if (it
->dpvec
== NULL
)
3021 get_next_display_element (it
);
3022 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3023 it
->current
.dpvec_index
= pos
->dpvec_index
;
3027 return !overlay_strings_with_newlines
;
3031 /* Initialize IT for stepping through current_buffer in window W
3032 starting at ROW->start. */
3035 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3037 init_from_display_pos (it
, w
, &row
->start
);
3038 it
->start
= row
->start
;
3039 it
->continuation_lines_width
= row
->continuation_lines_width
;
3044 /* Initialize IT for stepping through current_buffer in window W
3045 starting in the line following ROW, i.e. starting at ROW->end.
3046 Value is zero if there are overlay strings with newlines at ROW's
3050 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3054 if (init_from_display_pos (it
, w
, &row
->end
))
3056 if (row
->continued_p
)
3057 it
->continuation_lines_width
3058 = row
->continuation_lines_width
+ row
->pixel_width
;
3069 /***********************************************************************
3071 ***********************************************************************/
3073 /* Called when IT reaches IT->stop_charpos. Handle text property and
3074 overlay changes. Set IT->stop_charpos to the next position where
3078 handle_stop (struct it
*it
)
3080 enum prop_handled handled
;
3081 int handle_overlay_change_p
;
3085 it
->current
.dpvec_index
= -1;
3086 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3087 it
->ignore_overlay_strings_at_pos_p
= 0;
3090 /* Use face of preceding text for ellipsis (if invisible) */
3091 if (it
->selective_display_ellipsis_p
)
3092 it
->saved_face_id
= it
->face_id
;
3096 handled
= HANDLED_NORMALLY
;
3098 /* Call text property handlers. */
3099 for (p
= it_props
; p
->handler
; ++p
)
3101 handled
= p
->handler (it
);
3103 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3105 else if (handled
== HANDLED_RETURN
)
3107 /* We still want to show before and after strings from
3108 overlays even if the actual buffer text is replaced. */
3109 if (!handle_overlay_change_p
3111 || !get_overlay_strings_1 (it
, 0, 0))
3114 setup_for_ellipsis (it
, 0);
3115 /* When handling a display spec, we might load an
3116 empty string. In that case, discard it here. We
3117 used to discard it in handle_single_display_spec,
3118 but that causes get_overlay_strings_1, above, to
3119 ignore overlay strings that we must check. */
3120 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3124 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3128 it
->ignore_overlay_strings_at_pos_p
= 1;
3129 it
->string_from_display_prop_p
= 0;
3130 it
->from_disp_prop_p
= 0;
3131 handle_overlay_change_p
= 0;
3133 handled
= HANDLED_RECOMPUTE_PROPS
;
3136 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3137 handle_overlay_change_p
= 0;
3140 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3142 /* Don't check for overlay strings below when set to deliver
3143 characters from a display vector. */
3144 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3145 handle_overlay_change_p
= 0;
3147 /* Handle overlay changes.
3148 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3149 if it finds overlays. */
3150 if (handle_overlay_change_p
)
3151 handled
= handle_overlay_change (it
);
3156 setup_for_ellipsis (it
, 0);
3160 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3162 /* Determine where to stop next. */
3163 if (handled
== HANDLED_NORMALLY
)
3164 compute_stop_pos (it
);
3168 /* Compute IT->stop_charpos from text property and overlay change
3169 information for IT's current position. */
3172 compute_stop_pos (struct it
*it
)
3174 register INTERVAL iv
, next_iv
;
3175 Lisp_Object object
, limit
, position
;
3176 ptrdiff_t charpos
, bytepos
;
3178 if (STRINGP (it
->string
))
3180 /* Strings are usually short, so don't limit the search for
3182 it
->stop_charpos
= it
->end_charpos
;
3183 object
= it
->string
;
3185 charpos
= IT_STRING_CHARPOS (*it
);
3186 bytepos
= IT_STRING_BYTEPOS (*it
);
3192 /* If end_charpos is out of range for some reason, such as a
3193 misbehaving display function, rationalize it (Bug#5984). */
3194 if (it
->end_charpos
> ZV
)
3195 it
->end_charpos
= ZV
;
3196 it
->stop_charpos
= it
->end_charpos
;
3198 /* If next overlay change is in front of the current stop pos
3199 (which is IT->end_charpos), stop there. Note: value of
3200 next_overlay_change is point-max if no overlay change
3202 charpos
= IT_CHARPOS (*it
);
3203 bytepos
= IT_BYTEPOS (*it
);
3204 pos
= next_overlay_change (charpos
);
3205 if (pos
< it
->stop_charpos
)
3206 it
->stop_charpos
= pos
;
3208 /* If showing the region, we have to stop at the region
3209 start or end because the face might change there. */
3210 if (it
->region_beg_charpos
> 0)
3212 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3213 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3214 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3215 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3218 /* Set up variables for computing the stop position from text
3219 property changes. */
3220 XSETBUFFER (object
, current_buffer
);
3221 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3224 /* Get the interval containing IT's position. Value is a null
3225 interval if there isn't such an interval. */
3226 position
= make_number (charpos
);
3227 iv
= validate_interval_range (object
, &position
, &position
, 0);
3228 if (!NULL_INTERVAL_P (iv
))
3230 Lisp_Object values_here
[LAST_PROP_IDX
];
3233 /* Get properties here. */
3234 for (p
= it_props
; p
->handler
; ++p
)
3235 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3237 /* Look for an interval following iv that has different
3239 for (next_iv
= next_interval (iv
);
3240 (!NULL_INTERVAL_P (next_iv
)
3242 || XFASTINT (limit
) > next_iv
->position
));
3243 next_iv
= next_interval (next_iv
))
3245 for (p
= it_props
; p
->handler
; ++p
)
3247 Lisp_Object new_value
;
3249 new_value
= textget (next_iv
->plist
, *p
->name
);
3250 if (!EQ (values_here
[p
->idx
], new_value
))
3258 if (!NULL_INTERVAL_P (next_iv
))
3260 if (INTEGERP (limit
)
3261 && next_iv
->position
>= XFASTINT (limit
))
3262 /* No text property change up to limit. */
3263 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3265 /* Text properties change in next_iv. */
3266 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3270 if (it
->cmp_it
.id
< 0)
3272 ptrdiff_t stoppos
= it
->end_charpos
;
3274 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3276 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3277 stoppos
, it
->string
);
3280 xassert (STRINGP (it
->string
)
3281 || (it
->stop_charpos
>= BEGV
3282 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3286 /* Return the position of the next overlay change after POS in
3287 current_buffer. Value is point-max if no overlay change
3288 follows. This is like `next-overlay-change' but doesn't use
3292 next_overlay_change (ptrdiff_t pos
)
3294 ptrdiff_t i
, noverlays
;
3296 Lisp_Object
*overlays
;
3298 /* Get all overlays at the given position. */
3299 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3301 /* If any of these overlays ends before endpos,
3302 use its ending point instead. */
3303 for (i
= 0; i
< noverlays
; ++i
)
3308 oend
= OVERLAY_END (overlays
[i
]);
3309 oendpos
= OVERLAY_POSITION (oend
);
3310 endpos
= min (endpos
, oendpos
);
3316 /* How many characters forward to search for a display property or
3317 display string. Searching too far forward makes the bidi display
3318 sluggish, especially in small windows. */
3319 #define MAX_DISP_SCAN 250
3321 /* Return the character position of a display string at or after
3322 position specified by POSITION. If no display string exists at or
3323 after POSITION, return ZV. A display string is either an overlay
3324 with `display' property whose value is a string, or a `display'
3325 text property whose value is a string. STRING is data about the
3326 string to iterate; if STRING->lstring is nil, we are iterating a
3327 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3328 on a GUI frame. DISP_PROP is set to zero if we searched
3329 MAX_DISP_SCAN characters forward without finding any display
3330 strings, non-zero otherwise. It is set to 2 if the display string
3331 uses any kind of `(space ...)' spec that will produce a stretch of
3332 white space in the text area. */
3334 compute_display_string_pos (struct text_pos
*position
,
3335 struct bidi_string_data
*string
,
3336 int frame_window_p
, int *disp_prop
)
3338 /* OBJECT = nil means current buffer. */
3339 Lisp_Object object
=
3340 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3341 Lisp_Object pos
, spec
, limpos
;
3342 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3343 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3344 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3345 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3347 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3348 struct text_pos tpos
;
3354 /* We don't support display properties whose values are strings
3355 that have display string properties. */
3356 || string
->from_disp_str
3357 /* C strings cannot have display properties. */
3358 || (string
->s
&& !STRINGP (object
)))
3364 /* If the character at CHARPOS is where the display string begins,
3366 pos
= make_number (charpos
);
3367 if (STRINGP (object
))
3368 bufpos
= string
->bufpos
;
3372 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3374 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3377 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3385 /* Look forward for the first character with a `display' property
3386 that will replace the underlying text when displayed. */
3387 limpos
= make_number (lim
);
3389 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3390 CHARPOS (tpos
) = XFASTINT (pos
);
3391 if (CHARPOS (tpos
) >= lim
)
3396 if (STRINGP (object
))
3397 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3399 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3400 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3401 if (!STRINGP (object
))
3402 bufpos
= CHARPOS (tpos
);
3403 } while (NILP (spec
)
3404 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3405 bufpos
, frame_window_p
)));
3409 return CHARPOS (tpos
);
3412 /* Return the character position of the end of the display string that
3413 started at CHARPOS. If there's no display string at CHARPOS,
3414 return -1. A display string is either an overlay with `display'
3415 property whose value is a string or a `display' text property whose
3416 value is a string. */
3418 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3420 /* OBJECT = nil means current buffer. */
3421 Lisp_Object object
=
3422 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3423 Lisp_Object pos
= make_number (charpos
);
3425 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3427 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3430 /* It could happen that the display property or overlay was removed
3431 since we found it in compute_display_string_pos above. One way
3432 this can happen is if JIT font-lock was called (through
3433 handle_fontified_prop), and jit-lock-functions remove text
3434 properties or overlays from the portion of buffer that includes
3435 CHARPOS. Muse mode is known to do that, for example. In this
3436 case, we return -1 to the caller, to signal that no display
3437 string is actually present at CHARPOS. See bidi_fetch_char for
3438 how this is handled.
3440 An alternative would be to never look for display properties past
3441 it->stop_charpos. But neither compute_display_string_pos nor
3442 bidi_fetch_char that calls it know or care where the next
3444 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3447 /* Look forward for the first character where the `display' property
3449 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3451 return XFASTINT (pos
);
3456 /***********************************************************************
3458 ***********************************************************************/
3460 /* Handle changes in the `fontified' property of the current buffer by
3461 calling hook functions from Qfontification_functions to fontify
3464 static enum prop_handled
3465 handle_fontified_prop (struct it
*it
)
3467 Lisp_Object prop
, pos
;
3468 enum prop_handled handled
= HANDLED_NORMALLY
;
3470 if (!NILP (Vmemory_full
))
3473 /* Get the value of the `fontified' property at IT's current buffer
3474 position. (The `fontified' property doesn't have a special
3475 meaning in strings.) If the value is nil, call functions from
3476 Qfontification_functions. */
3477 if (!STRINGP (it
->string
)
3479 && !NILP (Vfontification_functions
)
3480 && !NILP (Vrun_hooks
)
3481 && (pos
= make_number (IT_CHARPOS (*it
)),
3482 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3483 /* Ignore the special cased nil value always present at EOB since
3484 no amount of fontifying will be able to change it. */
3485 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3487 ptrdiff_t count
= SPECPDL_INDEX ();
3489 struct buffer
*obuf
= current_buffer
;
3490 int begv
= BEGV
, zv
= ZV
;
3491 int old_clip_changed
= current_buffer
->clip_changed
;
3493 val
= Vfontification_functions
;
3494 specbind (Qfontification_functions
, Qnil
);
3496 xassert (it
->end_charpos
== ZV
);
3498 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3499 safe_call1 (val
, pos
);
3502 Lisp_Object fns
, fn
;
3503 struct gcpro gcpro1
, gcpro2
;
3508 for (; CONSP (val
); val
= XCDR (val
))
3514 /* A value of t indicates this hook has a local
3515 binding; it means to run the global binding too.
3516 In a global value, t should not occur. If it
3517 does, we must ignore it to avoid an endless
3519 for (fns
= Fdefault_value (Qfontification_functions
);
3525 safe_call1 (fn
, pos
);
3529 safe_call1 (fn
, pos
);
3535 unbind_to (count
, Qnil
);
3537 /* Fontification functions routinely call `save-restriction'.
3538 Normally, this tags clip_changed, which can confuse redisplay
3539 (see discussion in Bug#6671). Since we don't perform any
3540 special handling of fontification changes in the case where
3541 `save-restriction' isn't called, there's no point doing so in
3542 this case either. So, if the buffer's restrictions are
3543 actually left unchanged, reset clip_changed. */
3544 if (obuf
== current_buffer
)
3546 if (begv
== BEGV
&& zv
== ZV
)
3547 current_buffer
->clip_changed
= old_clip_changed
;
3549 /* There isn't much we can reasonably do to protect against
3550 misbehaving fontification, but here's a fig leaf. */
3551 else if (!NILP (BVAR (obuf
, name
)))
3552 set_buffer_internal_1 (obuf
);
3554 /* The fontification code may have added/removed text.
3555 It could do even a lot worse, but let's at least protect against
3556 the most obvious case where only the text past `pos' gets changed',
3557 as is/was done in grep.el where some escapes sequences are turned
3558 into face properties (bug#7876). */
3559 it
->end_charpos
= ZV
;
3561 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3562 something. This avoids an endless loop if they failed to
3563 fontify the text for which reason ever. */
3564 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3565 handled
= HANDLED_RECOMPUTE_PROPS
;
3573 /***********************************************************************
3575 ***********************************************************************/
3577 /* Set up iterator IT from face properties at its current position.
3578 Called from handle_stop. */
3580 static enum prop_handled
3581 handle_face_prop (struct it
*it
)
3584 ptrdiff_t next_stop
;
3586 if (!STRINGP (it
->string
))
3589 = face_at_buffer_position (it
->w
,
3591 it
->region_beg_charpos
,
3592 it
->region_end_charpos
,
3595 + TEXT_PROP_DISTANCE_LIMIT
),
3596 0, it
->base_face_id
);
3598 /* Is this a start of a run of characters with box face?
3599 Caveat: this can be called for a freshly initialized
3600 iterator; face_id is -1 in this case. We know that the new
3601 face will not change until limit, i.e. if the new face has a
3602 box, all characters up to limit will have one. But, as
3603 usual, we don't know whether limit is really the end. */
3604 if (new_face_id
!= it
->face_id
)
3606 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3608 /* If new face has a box but old face has not, this is
3609 the start of a run of characters with box, i.e. it has
3610 a shadow on the left side. The value of face_id of the
3611 iterator will be -1 if this is the initial call that gets
3612 the face. In this case, we have to look in front of IT's
3613 position and see whether there is a face != new_face_id. */
3614 it
->start_of_box_run_p
3615 = (new_face
->box
!= FACE_NO_BOX
3616 && (it
->face_id
>= 0
3617 || IT_CHARPOS (*it
) == BEG
3618 || new_face_id
!= face_before_it_pos (it
)));
3619 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3627 Lisp_Object from_overlay
3628 = (it
->current
.overlay_string_index
>= 0
3629 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3632 /* See if we got to this string directly or indirectly from
3633 an overlay property. That includes the before-string or
3634 after-string of an overlay, strings in display properties
3635 provided by an overlay, their text properties, etc.
3637 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3638 if (! NILP (from_overlay
))
3639 for (i
= it
->sp
- 1; i
>= 0; i
--)
3641 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3643 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3644 else if (! NILP (it
->stack
[i
].from_overlay
))
3645 from_overlay
= it
->stack
[i
].from_overlay
;
3647 if (!NILP (from_overlay
))
3651 if (! NILP (from_overlay
))
3653 bufpos
= IT_CHARPOS (*it
);
3654 /* For a string from an overlay, the base face depends
3655 only on text properties and ignores overlays. */
3657 = face_for_overlay_string (it
->w
,
3659 it
->region_beg_charpos
,
3660 it
->region_end_charpos
,
3663 + TEXT_PROP_DISTANCE_LIMIT
),
3671 /* For strings from a `display' property, use the face at
3672 IT's current buffer position as the base face to merge
3673 with, so that overlay strings appear in the same face as
3674 surrounding text, unless they specify their own
3676 base_face_id
= underlying_face_id (it
);
3679 new_face_id
= face_at_string_position (it
->w
,
3681 IT_STRING_CHARPOS (*it
),
3683 it
->region_beg_charpos
,
3684 it
->region_end_charpos
,
3688 /* Is this a start of a run of characters with box? Caveat:
3689 this can be called for a freshly allocated iterator; face_id
3690 is -1 is this case. We know that the new face will not
3691 change until the next check pos, i.e. if the new face has a
3692 box, all characters up to that position will have a
3693 box. But, as usual, we don't know whether that position
3694 is really the end. */
3695 if (new_face_id
!= it
->face_id
)
3697 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3698 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3700 /* If new face has a box but old face hasn't, this is the
3701 start of a run of characters with box, i.e. it has a
3702 shadow on the left side. */
3703 it
->start_of_box_run_p
3704 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3705 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3709 it
->face_id
= new_face_id
;
3710 return HANDLED_NORMALLY
;
3714 /* Return the ID of the face ``underlying'' IT's current position,
3715 which is in a string. If the iterator is associated with a
3716 buffer, return the face at IT's current buffer position.
3717 Otherwise, use the iterator's base_face_id. */
3720 underlying_face_id (struct it
*it
)
3722 int face_id
= it
->base_face_id
, i
;
3724 xassert (STRINGP (it
->string
));
3726 for (i
= it
->sp
- 1; i
>= 0; --i
)
3727 if (NILP (it
->stack
[i
].string
))
3728 face_id
= it
->stack
[i
].face_id
;
3734 /* Compute the face one character before or after the current position
3735 of IT, in the visual order. BEFORE_P non-zero means get the face
3736 in front (to the left in L2R paragraphs, to the right in R2L
3737 paragraphs) of IT's screen position. Value is the ID of the face. */
3740 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3743 ptrdiff_t next_check_charpos
;
3745 void *it_copy_data
= NULL
;
3747 xassert (it
->s
== NULL
);
3749 if (STRINGP (it
->string
))
3751 ptrdiff_t bufpos
, charpos
;
3754 /* No face change past the end of the string (for the case
3755 we are padding with spaces). No face change before the
3757 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3758 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3763 /* Set charpos to the position before or after IT's current
3764 position, in the logical order, which in the non-bidi
3765 case is the same as the visual order. */
3767 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3768 else if (it
->what
== IT_COMPOSITION
)
3769 /* For composition, we must check the character after the
3771 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3773 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3779 /* With bidi iteration, the character before the current
3780 in the visual order cannot be found by simple
3781 iteration, because "reverse" reordering is not
3782 supported. Instead, we need to use the move_it_*
3783 family of functions. */
3784 /* Ignore face changes before the first visible
3785 character on this display line. */
3786 if (it
->current_x
<= it
->first_visible_x
)
3788 SAVE_IT (it_copy
, *it
, it_copy_data
);
3789 /* Implementation note: Since move_it_in_display_line
3790 works in the iterator geometry, and thinks the first
3791 character is always the leftmost, even in R2L lines,
3792 we don't need to distinguish between the R2L and L2R
3794 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3795 it_copy
.current_x
- 1, MOVE_TO_X
);
3796 charpos
= IT_STRING_CHARPOS (it_copy
);
3797 RESTORE_IT (it
, it
, it_copy_data
);
3801 /* Set charpos to the string position of the character
3802 that comes after IT's current position in the visual
3804 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3808 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3810 charpos
= it_copy
.bidi_it
.charpos
;
3813 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3815 if (it
->current
.overlay_string_index
>= 0)
3816 bufpos
= IT_CHARPOS (*it
);
3820 base_face_id
= underlying_face_id (it
);
3822 /* Get the face for ASCII, or unibyte. */
3823 face_id
= face_at_string_position (it
->w
,
3827 it
->region_beg_charpos
,
3828 it
->region_end_charpos
,
3829 &next_check_charpos
,
3832 /* Correct the face for charsets different from ASCII. Do it
3833 for the multibyte case only. The face returned above is
3834 suitable for unibyte text if IT->string is unibyte. */
3835 if (STRING_MULTIBYTE (it
->string
))
3837 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3838 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3840 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3842 c
= string_char_and_length (p
, &len
);
3843 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3848 struct text_pos pos
;
3850 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3851 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3854 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3855 pos
= it
->current
.pos
;
3860 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3863 if (it
->what
== IT_COMPOSITION
)
3865 /* For composition, we must check the position after
3867 pos
.charpos
+= it
->cmp_it
.nchars
;
3868 pos
.bytepos
+= it
->len
;
3871 INC_TEXT_POS (pos
, it
->multibyte_p
);
3878 /* With bidi iteration, the character before the current
3879 in the visual order cannot be found by simple
3880 iteration, because "reverse" reordering is not
3881 supported. Instead, we need to use the move_it_*
3882 family of functions. */
3883 /* Ignore face changes before the first visible
3884 character on this display line. */
3885 if (it
->current_x
<= it
->first_visible_x
)
3887 SAVE_IT (it_copy
, *it
, it_copy_data
);
3888 /* Implementation note: Since move_it_in_display_line
3889 works in the iterator geometry, and thinks the first
3890 character is always the leftmost, even in R2L lines,
3891 we don't need to distinguish between the R2L and L2R
3893 move_it_in_display_line (&it_copy
, ZV
,
3894 it_copy
.current_x
- 1, MOVE_TO_X
);
3895 pos
= it_copy
.current
.pos
;
3896 RESTORE_IT (it
, it
, it_copy_data
);
3900 /* Set charpos to the buffer position of the character
3901 that comes after IT's current position in the visual
3903 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3907 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3910 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3913 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3915 /* Determine face for CHARSET_ASCII, or unibyte. */
3916 face_id
= face_at_buffer_position (it
->w
,
3918 it
->region_beg_charpos
,
3919 it
->region_end_charpos
,
3920 &next_check_charpos
,
3923 /* Correct the face for charsets different from ASCII. Do it
3924 for the multibyte case only. The face returned above is
3925 suitable for unibyte text if current_buffer is unibyte. */
3926 if (it
->multibyte_p
)
3928 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3929 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3930 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3939 /***********************************************************************
3941 ***********************************************************************/
3943 /* Set up iterator IT from invisible properties at its current
3944 position. Called from handle_stop. */
3946 static enum prop_handled
3947 handle_invisible_prop (struct it
*it
)
3949 enum prop_handled handled
= HANDLED_NORMALLY
;
3951 if (STRINGP (it
->string
))
3953 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3955 /* Get the value of the invisible text property at the
3956 current position. Value will be nil if there is no such
3958 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3959 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3962 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3966 handled
= HANDLED_RECOMPUTE_PROPS
;
3968 /* Get the position at which the next change of the
3969 invisible text property can be found in IT->string.
3970 Value will be nil if the property value is the same for
3971 all the rest of IT->string. */
3972 XSETINT (limit
, SCHARS (it
->string
));
3973 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3976 /* Text at current position is invisible. The next
3977 change in the property is at position end_charpos.
3978 Move IT's current position to that position. */
3979 if (INTEGERP (end_charpos
)
3980 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3982 struct text_pos old
;
3985 old
= it
->current
.string_pos
;
3986 oldpos
= CHARPOS (old
);
3989 if (it
->bidi_it
.first_elt
3990 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
3991 bidi_paragraph_init (it
->paragraph_embedding
,
3993 /* Bidi-iterate out of the invisible text. */
3996 bidi_move_to_visually_next (&it
->bidi_it
);
3998 while (oldpos
<= it
->bidi_it
.charpos
3999 && it
->bidi_it
.charpos
< endpos
);
4001 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4002 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4003 if (IT_CHARPOS (*it
) >= endpos
)
4004 it
->prev_stop
= endpos
;
4008 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4009 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4014 /* The rest of the string is invisible. If this is an
4015 overlay string, proceed with the next overlay string
4016 or whatever comes and return a character from there. */
4017 if (it
->current
.overlay_string_index
>= 0)
4019 next_overlay_string (it
);
4020 /* Don't check for overlay strings when we just
4021 finished processing them. */
4022 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4026 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4027 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4035 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4036 Lisp_Object pos
, prop
, overlay
;
4038 /* First of all, is there invisible text at this position? */
4039 tem
= start_charpos
= IT_CHARPOS (*it
);
4040 pos
= make_number (tem
);
4041 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4043 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4045 /* If we are on invisible text, skip over it. */
4046 if (invis_p
&& start_charpos
< it
->end_charpos
)
4048 /* Record whether we have to display an ellipsis for the
4050 int display_ellipsis_p
= invis_p
== 2;
4052 handled
= HANDLED_RECOMPUTE_PROPS
;
4054 /* Loop skipping over invisible text. The loop is left at
4055 ZV or with IT on the first char being visible again. */
4058 /* Try to skip some invisible text. Return value is the
4059 position reached which can be equal to where we start
4060 if there is nothing invisible there. This skips both
4061 over invisible text properties and overlays with
4062 invisible property. */
4063 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4065 /* If we skipped nothing at all we weren't at invisible
4066 text in the first place. If everything to the end of
4067 the buffer was skipped, end the loop. */
4068 if (newpos
== tem
|| newpos
>= ZV
)
4072 /* We skipped some characters but not necessarily
4073 all there are. Check if we ended up on visible
4074 text. Fget_char_property returns the property of
4075 the char before the given position, i.e. if we
4076 get invis_p = 0, this means that the char at
4077 newpos is visible. */
4078 pos
= make_number (newpos
);
4079 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4080 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4083 /* If we ended up on invisible text, proceed to
4084 skip starting with next_stop. */
4088 /* If there are adjacent invisible texts, don't lose the
4089 second one's ellipsis. */
4091 display_ellipsis_p
= 1;
4095 /* The position newpos is now either ZV or on visible text. */
4098 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4100 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4102 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4104 /* If the invisible text ends on a newline or on a
4105 character after a newline, we can avoid the costly,
4106 character by character, bidi iteration to NEWPOS, and
4107 instead simply reseat the iterator there. That's
4108 because all bidi reordering information is tossed at
4109 the newline. This is a big win for modes that hide
4110 complete lines, like Outline, Org, etc. */
4111 if (on_newline
|| after_newline
)
4113 struct text_pos tpos
;
4114 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4116 SET_TEXT_POS (tpos
, newpos
, bpos
);
4117 reseat_1 (it
, tpos
, 0);
4118 /* If we reseat on a newline/ZV, we need to prep the
4119 bidi iterator for advancing to the next character
4120 after the newline/EOB, keeping the current paragraph
4121 direction (so that PRODUCE_GLYPHS does TRT wrt
4122 prepending/appending glyphs to a glyph row). */
4125 it
->bidi_it
.first_elt
= 0;
4126 it
->bidi_it
.paragraph_dir
= pdir
;
4127 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4128 it
->bidi_it
.nchars
= 1;
4129 it
->bidi_it
.ch_len
= 1;
4132 else /* Must use the slow method. */
4134 /* With bidi iteration, the region of invisible text
4135 could start and/or end in the middle of a
4136 non-base embedding level. Therefore, we need to
4137 skip invisible text using the bidi iterator,
4138 starting at IT's current position, until we find
4139 ourselves outside of the invisible text.
4140 Skipping invisible text _after_ bidi iteration
4141 avoids affecting the visual order of the
4142 displayed text when invisible properties are
4143 added or removed. */
4144 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4146 /* If we were `reseat'ed to a new paragraph,
4147 determine the paragraph base direction. We
4148 need to do it now because
4149 next_element_from_buffer may not have a
4150 chance to do it, if we are going to skip any
4151 text at the beginning, which resets the
4153 bidi_paragraph_init (it
->paragraph_embedding
,
4158 bidi_move_to_visually_next (&it
->bidi_it
);
4160 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4161 && it
->bidi_it
.charpos
< newpos
);
4162 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4163 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4164 /* If we overstepped NEWPOS, record its position in
4165 the iterator, so that we skip invisible text if
4166 later the bidi iteration lands us in the
4167 invisible region again. */
4168 if (IT_CHARPOS (*it
) >= newpos
)
4169 it
->prev_stop
= newpos
;
4174 IT_CHARPOS (*it
) = newpos
;
4175 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4178 /* If there are before-strings at the start of invisible
4179 text, and the text is invisible because of a text
4180 property, arrange to show before-strings because 20.x did
4181 it that way. (If the text is invisible because of an
4182 overlay property instead of a text property, this is
4183 already handled in the overlay code.) */
4185 && get_overlay_strings (it
, it
->stop_charpos
))
4187 handled
= HANDLED_RECOMPUTE_PROPS
;
4188 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4190 else if (display_ellipsis_p
)
4192 /* Make sure that the glyphs of the ellipsis will get
4193 correct `charpos' values. If we would not update
4194 it->position here, the glyphs would belong to the
4195 last visible character _before_ the invisible
4196 text, which confuses `set_cursor_from_row'.
4198 We use the last invisible position instead of the
4199 first because this way the cursor is always drawn on
4200 the first "." of the ellipsis, whenever PT is inside
4201 the invisible text. Otherwise the cursor would be
4202 placed _after_ the ellipsis when the point is after the
4203 first invisible character. */
4204 if (!STRINGP (it
->object
))
4206 it
->position
.charpos
= newpos
- 1;
4207 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4210 /* Let the ellipsis display before
4211 considering any properties of the following char.
4212 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4213 handled
= HANDLED_RETURN
;
4222 /* Make iterator IT return `...' next.
4223 Replaces LEN characters from buffer. */
4226 setup_for_ellipsis (struct it
*it
, int len
)
4228 /* Use the display table definition for `...'. Invalid glyphs
4229 will be handled by the method returning elements from dpvec. */
4230 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4232 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4233 it
->dpvec
= v
->contents
;
4234 it
->dpend
= v
->contents
+ v
->header
.size
;
4238 /* Default `...'. */
4239 it
->dpvec
= default_invis_vector
;
4240 it
->dpend
= default_invis_vector
+ 3;
4243 it
->dpvec_char_len
= len
;
4244 it
->current
.dpvec_index
= 0;
4245 it
->dpvec_face_id
= -1;
4247 /* Remember the current face id in case glyphs specify faces.
4248 IT's face is restored in set_iterator_to_next.
4249 saved_face_id was set to preceding char's face in handle_stop. */
4250 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4251 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4253 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4259 /***********************************************************************
4261 ***********************************************************************/
4263 /* Set up iterator IT from `display' property at its current position.
4264 Called from handle_stop.
4265 We return HANDLED_RETURN if some part of the display property
4266 overrides the display of the buffer text itself.
4267 Otherwise we return HANDLED_NORMALLY. */
4269 static enum prop_handled
4270 handle_display_prop (struct it
*it
)
4272 Lisp_Object propval
, object
, overlay
;
4273 struct text_pos
*position
;
4275 /* Nonzero if some property replaces the display of the text itself. */
4276 int display_replaced_p
= 0;
4278 if (STRINGP (it
->string
))
4280 object
= it
->string
;
4281 position
= &it
->current
.string_pos
;
4282 bufpos
= CHARPOS (it
->current
.pos
);
4286 XSETWINDOW (object
, it
->w
);
4287 position
= &it
->current
.pos
;
4288 bufpos
= CHARPOS (*position
);
4291 /* Reset those iterator values set from display property values. */
4292 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4293 it
->space_width
= Qnil
;
4294 it
->font_height
= Qnil
;
4297 /* We don't support recursive `display' properties, i.e. string
4298 values that have a string `display' property, that have a string
4299 `display' property etc. */
4300 if (!it
->string_from_display_prop_p
)
4301 it
->area
= TEXT_AREA
;
4303 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4304 Qdisplay
, object
, &overlay
);
4306 return HANDLED_NORMALLY
;
4307 /* Now OVERLAY is the overlay that gave us this property, or nil
4308 if it was a text property. */
4310 if (!STRINGP (it
->string
))
4311 object
= it
->w
->buffer
;
4313 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4315 FRAME_WINDOW_P (it
->f
));
4317 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4320 /* Subroutine of handle_display_prop. Returns non-zero if the display
4321 specification in SPEC is a replacing specification, i.e. it would
4322 replace the text covered by `display' property with something else,
4323 such as an image or a display string. If SPEC includes any kind or
4324 `(space ...) specification, the value is 2; this is used by
4325 compute_display_string_pos, which see.
4327 See handle_single_display_spec for documentation of arguments.
4328 frame_window_p is non-zero if the window being redisplayed is on a
4329 GUI frame; this argument is used only if IT is NULL, see below.
4331 IT can be NULL, if this is called by the bidi reordering code
4332 through compute_display_string_pos, which see. In that case, this
4333 function only examines SPEC, but does not otherwise "handle" it, in
4334 the sense that it doesn't set up members of IT from the display
4337 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4338 Lisp_Object overlay
, struct text_pos
*position
,
4339 ptrdiff_t bufpos
, int frame_window_p
)
4341 int replacing_p
= 0;
4345 /* Simple specifications. */
4346 && !EQ (XCAR (spec
), Qimage
)
4347 && !EQ (XCAR (spec
), Qspace
)
4348 && !EQ (XCAR (spec
), Qwhen
)
4349 && !EQ (XCAR (spec
), Qslice
)
4350 && !EQ (XCAR (spec
), Qspace_width
)
4351 && !EQ (XCAR (spec
), Qheight
)
4352 && !EQ (XCAR (spec
), Qraise
)
4353 /* Marginal area specifications. */
4354 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4355 && !EQ (XCAR (spec
), Qleft_fringe
)
4356 && !EQ (XCAR (spec
), Qright_fringe
)
4357 && !NILP (XCAR (spec
)))
4359 for (; CONSP (spec
); spec
= XCDR (spec
))
4361 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4362 overlay
, position
, bufpos
,
4363 replacing_p
, frame_window_p
)))
4366 /* If some text in a string is replaced, `position' no
4367 longer points to the position of `object'. */
4368 if (!it
|| STRINGP (object
))
4373 else if (VECTORP (spec
))
4376 for (i
= 0; i
< ASIZE (spec
); ++i
)
4377 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4378 overlay
, position
, bufpos
,
4379 replacing_p
, frame_window_p
)))
4382 /* If some text in a string is replaced, `position' no
4383 longer points to the position of `object'. */
4384 if (!it
|| STRINGP (object
))
4390 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4391 position
, bufpos
, 0,
4399 /* Value is the position of the end of the `display' property starting
4400 at START_POS in OBJECT. */
4402 static struct text_pos
4403 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4406 struct text_pos end_pos
;
4408 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4409 Qdisplay
, object
, Qnil
);
4410 CHARPOS (end_pos
) = XFASTINT (end
);
4411 if (STRINGP (object
))
4412 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4414 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4420 /* Set up IT from a single `display' property specification SPEC. OBJECT
4421 is the object in which the `display' property was found. *POSITION
4422 is the position in OBJECT at which the `display' property was found.
4423 BUFPOS is the buffer position of OBJECT (different from POSITION if
4424 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4425 previously saw a display specification which already replaced text
4426 display with something else, for example an image; we ignore such
4427 properties after the first one has been processed.
4429 OVERLAY is the overlay this `display' property came from,
4430 or nil if it was a text property.
4432 If SPEC is a `space' or `image' specification, and in some other
4433 cases too, set *POSITION to the position where the `display'
4436 If IT is NULL, only examine the property specification in SPEC, but
4437 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4438 is intended to be displayed in a window on a GUI frame.
4440 Value is non-zero if something was found which replaces the display
4441 of buffer or string text. */
4444 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4445 Lisp_Object overlay
, struct text_pos
*position
,
4446 ptrdiff_t bufpos
, int display_replaced_p
,
4450 Lisp_Object location
, value
;
4451 struct text_pos start_pos
= *position
;
4454 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4455 If the result is non-nil, use VALUE instead of SPEC. */
4457 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4466 if (!NILP (form
) && !EQ (form
, Qt
))
4468 ptrdiff_t count
= SPECPDL_INDEX ();
4469 struct gcpro gcpro1
;
4471 /* Bind `object' to the object having the `display' property, a
4472 buffer or string. Bind `position' to the position in the
4473 object where the property was found, and `buffer-position'
4474 to the current position in the buffer. */
4477 XSETBUFFER (object
, current_buffer
);
4478 specbind (Qobject
, object
);
4479 specbind (Qposition
, make_number (CHARPOS (*position
)));
4480 specbind (Qbuffer_position
, make_number (bufpos
));
4482 form
= safe_eval (form
);
4484 unbind_to (count
, Qnil
);
4490 /* Handle `(height HEIGHT)' specifications. */
4492 && EQ (XCAR (spec
), Qheight
)
4493 && CONSP (XCDR (spec
)))
4497 if (!FRAME_WINDOW_P (it
->f
))
4500 it
->font_height
= XCAR (XCDR (spec
));
4501 if (!NILP (it
->font_height
))
4503 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4504 int new_height
= -1;
4506 if (CONSP (it
->font_height
)
4507 && (EQ (XCAR (it
->font_height
), Qplus
)
4508 || EQ (XCAR (it
->font_height
), Qminus
))
4509 && CONSP (XCDR (it
->font_height
))
4510 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4512 /* `(+ N)' or `(- N)' where N is an integer. */
4513 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4514 if (EQ (XCAR (it
->font_height
), Qplus
))
4516 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4518 else if (FUNCTIONP (it
->font_height
))
4520 /* Call function with current height as argument.
4521 Value is the new height. */
4523 height
= safe_call1 (it
->font_height
,
4524 face
->lface
[LFACE_HEIGHT_INDEX
]);
4525 if (NUMBERP (height
))
4526 new_height
= XFLOATINT (height
);
4528 else if (NUMBERP (it
->font_height
))
4530 /* Value is a multiple of the canonical char height. */
4533 f
= FACE_FROM_ID (it
->f
,
4534 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4535 new_height
= (XFLOATINT (it
->font_height
)
4536 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4540 /* Evaluate IT->font_height with `height' bound to the
4541 current specified height to get the new height. */
4542 ptrdiff_t count
= SPECPDL_INDEX ();
4544 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4545 value
= safe_eval (it
->font_height
);
4546 unbind_to (count
, Qnil
);
4548 if (NUMBERP (value
))
4549 new_height
= XFLOATINT (value
);
4553 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4560 /* Handle `(space-width WIDTH)'. */
4562 && EQ (XCAR (spec
), Qspace_width
)
4563 && CONSP (XCDR (spec
)))
4567 if (!FRAME_WINDOW_P (it
->f
))
4570 value
= XCAR (XCDR (spec
));
4571 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4572 it
->space_width
= value
;
4578 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4580 && EQ (XCAR (spec
), Qslice
))
4586 if (!FRAME_WINDOW_P (it
->f
))
4589 if (tem
= XCDR (spec
), CONSP (tem
))
4591 it
->slice
.x
= XCAR (tem
);
4592 if (tem
= XCDR (tem
), CONSP (tem
))
4594 it
->slice
.y
= XCAR (tem
);
4595 if (tem
= XCDR (tem
), CONSP (tem
))
4597 it
->slice
.width
= XCAR (tem
);
4598 if (tem
= XCDR (tem
), CONSP (tem
))
4599 it
->slice
.height
= XCAR (tem
);
4608 /* Handle `(raise FACTOR)'. */
4610 && EQ (XCAR (spec
), Qraise
)
4611 && CONSP (XCDR (spec
)))
4615 if (!FRAME_WINDOW_P (it
->f
))
4618 #ifdef HAVE_WINDOW_SYSTEM
4619 value
= XCAR (XCDR (spec
));
4620 if (NUMBERP (value
))
4622 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4623 it
->voffset
= - (XFLOATINT (value
)
4624 * (FONT_HEIGHT (face
->font
)));
4626 #endif /* HAVE_WINDOW_SYSTEM */
4632 /* Don't handle the other kinds of display specifications
4633 inside a string that we got from a `display' property. */
4634 if (it
&& it
->string_from_display_prop_p
)
4637 /* Characters having this form of property are not displayed, so
4638 we have to find the end of the property. */
4641 start_pos
= *position
;
4642 *position
= display_prop_end (it
, object
, start_pos
);
4646 /* Stop the scan at that end position--we assume that all
4647 text properties change there. */
4649 it
->stop_charpos
= position
->charpos
;
4651 /* Handle `(left-fringe BITMAP [FACE])'
4652 and `(right-fringe BITMAP [FACE])'. */
4654 && (EQ (XCAR (spec
), Qleft_fringe
)
4655 || EQ (XCAR (spec
), Qright_fringe
))
4656 && CONSP (XCDR (spec
)))
4662 if (!FRAME_WINDOW_P (it
->f
))
4663 /* If we return here, POSITION has been advanced
4664 across the text with this property. */
4667 else if (!frame_window_p
)
4670 #ifdef HAVE_WINDOW_SYSTEM
4671 value
= XCAR (XCDR (spec
));
4672 if (!SYMBOLP (value
)
4673 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4674 /* If we return here, POSITION has been advanced
4675 across the text with this property. */
4680 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4682 if (CONSP (XCDR (XCDR (spec
))))
4684 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4685 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4691 /* Save current settings of IT so that we can restore them
4692 when we are finished with the glyph property value. */
4693 push_it (it
, position
);
4695 it
->area
= TEXT_AREA
;
4696 it
->what
= IT_IMAGE
;
4697 it
->image_id
= -1; /* no image */
4698 it
->position
= start_pos
;
4699 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4700 it
->method
= GET_FROM_IMAGE
;
4701 it
->from_overlay
= Qnil
;
4702 it
->face_id
= face_id
;
4703 it
->from_disp_prop_p
= 1;
4705 /* Say that we haven't consumed the characters with
4706 `display' property yet. The call to pop_it in
4707 set_iterator_to_next will clean this up. */
4708 *position
= start_pos
;
4710 if (EQ (XCAR (spec
), Qleft_fringe
))
4712 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4713 it
->left_user_fringe_face_id
= face_id
;
4717 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4718 it
->right_user_fringe_face_id
= face_id
;
4721 #endif /* HAVE_WINDOW_SYSTEM */
4725 /* Prepare to handle `((margin left-margin) ...)',
4726 `((margin right-margin) ...)' and `((margin nil) ...)'
4727 prefixes for display specifications. */
4728 location
= Qunbound
;
4729 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4733 value
= XCDR (spec
);
4735 value
= XCAR (value
);
4738 if (EQ (XCAR (tem
), Qmargin
)
4739 && (tem
= XCDR (tem
),
4740 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4742 || EQ (tem
, Qleft_margin
)
4743 || EQ (tem
, Qright_margin
))))
4747 if (EQ (location
, Qunbound
))
4753 /* After this point, VALUE is the property after any
4754 margin prefix has been stripped. It must be a string,
4755 an image specification, or `(space ...)'.
4757 LOCATION specifies where to display: `left-margin',
4758 `right-margin' or nil. */
4760 valid_p
= (STRINGP (value
)
4761 #ifdef HAVE_WINDOW_SYSTEM
4762 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4763 && valid_image_p (value
))
4764 #endif /* not HAVE_WINDOW_SYSTEM */
4765 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4767 if (valid_p
&& !display_replaced_p
)
4773 /* Callers need to know whether the display spec is any kind
4774 of `(space ...)' spec that is about to affect text-area
4776 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4781 /* Save current settings of IT so that we can restore them
4782 when we are finished with the glyph property value. */
4783 push_it (it
, position
);
4784 it
->from_overlay
= overlay
;
4785 it
->from_disp_prop_p
= 1;
4787 if (NILP (location
))
4788 it
->area
= TEXT_AREA
;
4789 else if (EQ (location
, Qleft_margin
))
4790 it
->area
= LEFT_MARGIN_AREA
;
4792 it
->area
= RIGHT_MARGIN_AREA
;
4794 if (STRINGP (value
))
4797 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4798 it
->current
.overlay_string_index
= -1;
4799 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4800 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4801 it
->method
= GET_FROM_STRING
;
4802 it
->stop_charpos
= 0;
4804 it
->base_level_stop
= 0;
4805 it
->string_from_display_prop_p
= 1;
4806 /* Say that we haven't consumed the characters with
4807 `display' property yet. The call to pop_it in
4808 set_iterator_to_next will clean this up. */
4809 if (BUFFERP (object
))
4810 *position
= start_pos
;
4812 /* Force paragraph direction to be that of the parent
4813 object. If the parent object's paragraph direction is
4814 not yet determined, default to L2R. */
4815 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4816 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4818 it
->paragraph_embedding
= L2R
;
4820 /* Set up the bidi iterator for this display string. */
4823 it
->bidi_it
.string
.lstring
= it
->string
;
4824 it
->bidi_it
.string
.s
= NULL
;
4825 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4826 it
->bidi_it
.string
.bufpos
= bufpos
;
4827 it
->bidi_it
.string
.from_disp_str
= 1;
4828 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4829 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4832 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4834 it
->method
= GET_FROM_STRETCH
;
4836 *position
= it
->position
= start_pos
;
4837 retval
= 1 + (it
->area
== TEXT_AREA
);
4839 #ifdef HAVE_WINDOW_SYSTEM
4842 it
->what
= IT_IMAGE
;
4843 it
->image_id
= lookup_image (it
->f
, value
);
4844 it
->position
= start_pos
;
4845 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4846 it
->method
= GET_FROM_IMAGE
;
4848 /* Say that we haven't consumed the characters with
4849 `display' property yet. The call to pop_it in
4850 set_iterator_to_next will clean this up. */
4851 *position
= start_pos
;
4853 #endif /* HAVE_WINDOW_SYSTEM */
4858 /* Invalid property or property not supported. Restore
4859 POSITION to what it was before. */
4860 *position
= start_pos
;
4864 /* Check if PROP is a display property value whose text should be
4865 treated as intangible. OVERLAY is the overlay from which PROP
4866 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4867 specify the buffer position covered by PROP. */
4870 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4871 ptrdiff_t charpos
, ptrdiff_t bytepos
)
4873 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4874 struct text_pos position
;
4876 SET_TEXT_POS (position
, charpos
, bytepos
);
4877 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4878 &position
, charpos
, frame_window_p
);
4882 /* Return 1 if PROP is a display sub-property value containing STRING.
4884 Implementation note: this and the following function are really
4885 special cases of handle_display_spec and
4886 handle_single_display_spec, and should ideally use the same code.
4887 Until they do, these two pairs must be consistent and must be
4888 modified in sync. */
4891 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4893 if (EQ (string
, prop
))
4896 /* Skip over `when FORM'. */
4897 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4902 /* Actually, the condition following `when' should be eval'ed,
4903 like handle_single_display_spec does, and we should return
4904 zero if it evaluates to nil. However, this function is
4905 called only when the buffer was already displayed and some
4906 glyph in the glyph matrix was found to come from a display
4907 string. Therefore, the condition was already evaluated, and
4908 the result was non-nil, otherwise the display string wouldn't
4909 have been displayed and we would have never been called for
4910 this property. Thus, we can skip the evaluation and assume
4911 its result is non-nil. */
4916 /* Skip over `margin LOCATION'. */
4917 if (EQ (XCAR (prop
), Qmargin
))
4928 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4932 /* Return 1 if STRING appears in the `display' property PROP. */
4935 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4938 && !EQ (XCAR (prop
), Qwhen
)
4939 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4941 /* A list of sub-properties. */
4942 while (CONSP (prop
))
4944 if (single_display_spec_string_p (XCAR (prop
), string
))
4949 else if (VECTORP (prop
))
4951 /* A vector of sub-properties. */
4953 for (i
= 0; i
< ASIZE (prop
); ++i
)
4954 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4958 return single_display_spec_string_p (prop
, string
);
4963 /* Look for STRING in overlays and text properties in the current
4964 buffer, between character positions FROM and TO (excluding TO).
4965 BACK_P non-zero means look back (in this case, TO is supposed to be
4967 Value is the first character position where STRING was found, or
4968 zero if it wasn't found before hitting TO.
4970 This function may only use code that doesn't eval because it is
4971 called asynchronously from note_mouse_highlight. */
4974 string_buffer_position_lim (Lisp_Object string
,
4975 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
4977 Lisp_Object limit
, prop
, pos
;
4980 pos
= make_number (from
);
4982 if (!back_p
) /* looking forward */
4984 limit
= make_number (min (to
, ZV
));
4985 while (!found
&& !EQ (pos
, limit
))
4987 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4988 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4991 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4995 else /* looking back */
4997 limit
= make_number (max (to
, BEGV
));
4998 while (!found
&& !EQ (pos
, limit
))
5000 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5001 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5004 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5009 return found
? XINT (pos
) : 0;
5012 /* Determine which buffer position in current buffer STRING comes from.
5013 AROUND_CHARPOS is an approximate position where it could come from.
5014 Value is the buffer position or 0 if it couldn't be determined.
5016 This function is necessary because we don't record buffer positions
5017 in glyphs generated from strings (to keep struct glyph small).
5018 This function may only use code that doesn't eval because it is
5019 called asynchronously from note_mouse_highlight. */
5022 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5024 const int MAX_DISTANCE
= 1000;
5025 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5026 around_charpos
+ MAX_DISTANCE
,
5030 found
= string_buffer_position_lim (string
, around_charpos
,
5031 around_charpos
- MAX_DISTANCE
, 1);
5037 /***********************************************************************
5038 `composition' property
5039 ***********************************************************************/
5041 /* Set up iterator IT from `composition' property at its current
5042 position. Called from handle_stop. */
5044 static enum prop_handled
5045 handle_composition_prop (struct it
*it
)
5047 Lisp_Object prop
, string
;
5048 ptrdiff_t pos
, pos_byte
, start
, end
;
5050 if (STRINGP (it
->string
))
5054 pos
= IT_STRING_CHARPOS (*it
);
5055 pos_byte
= IT_STRING_BYTEPOS (*it
);
5056 string
= it
->string
;
5057 s
= SDATA (string
) + pos_byte
;
5058 it
->c
= STRING_CHAR (s
);
5062 pos
= IT_CHARPOS (*it
);
5063 pos_byte
= IT_BYTEPOS (*it
);
5065 it
->c
= FETCH_CHAR (pos_byte
);
5068 /* If there's a valid composition and point is not inside of the
5069 composition (in the case that the composition is from the current
5070 buffer), draw a glyph composed from the composition components. */
5071 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5072 && COMPOSITION_VALID_P (start
, end
, prop
)
5073 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5076 /* As we can't handle this situation (perhaps font-lock added
5077 a new composition), we just return here hoping that next
5078 redisplay will detect this composition much earlier. */
5079 return HANDLED_NORMALLY
;
5082 if (STRINGP (it
->string
))
5083 pos_byte
= string_char_to_byte (it
->string
, start
);
5085 pos_byte
= CHAR_TO_BYTE (start
);
5087 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5090 if (it
->cmp_it
.id
>= 0)
5093 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5094 it
->cmp_it
.nglyphs
= -1;
5098 return HANDLED_NORMALLY
;
5103 /***********************************************************************
5105 ***********************************************************************/
5107 /* The following structure is used to record overlay strings for
5108 later sorting in load_overlay_strings. */
5110 struct overlay_entry
5112 Lisp_Object overlay
;
5119 /* Set up iterator IT from overlay strings at its current position.
5120 Called from handle_stop. */
5122 static enum prop_handled
5123 handle_overlay_change (struct it
*it
)
5125 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5126 return HANDLED_RECOMPUTE_PROPS
;
5128 return HANDLED_NORMALLY
;
5132 /* Set up the next overlay string for delivery by IT, if there is an
5133 overlay string to deliver. Called by set_iterator_to_next when the
5134 end of the current overlay string is reached. If there are more
5135 overlay strings to display, IT->string and
5136 IT->current.overlay_string_index are set appropriately here.
5137 Otherwise IT->string is set to nil. */
5140 next_overlay_string (struct it
*it
)
5142 ++it
->current
.overlay_string_index
;
5143 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5145 /* No more overlay strings. Restore IT's settings to what
5146 they were before overlay strings were processed, and
5147 continue to deliver from current_buffer. */
5149 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5152 || (NILP (it
->string
)
5153 && it
->method
== GET_FROM_BUFFER
5154 && it
->stop_charpos
>= BEGV
5155 && it
->stop_charpos
<= it
->end_charpos
));
5156 it
->current
.overlay_string_index
= -1;
5157 it
->n_overlay_strings
= 0;
5158 it
->overlay_strings_charpos
= -1;
5160 /* If we're at the end of the buffer, record that we have
5161 processed the overlay strings there already, so that
5162 next_element_from_buffer doesn't try it again. */
5163 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5164 it
->overlay_strings_at_end_processed_p
= 1;
5168 /* There are more overlay strings to process. If
5169 IT->current.overlay_string_index has advanced to a position
5170 where we must load IT->overlay_strings with more strings, do
5171 it. We must load at the IT->overlay_strings_charpos where
5172 IT->n_overlay_strings was originally computed; when invisible
5173 text is present, this might not be IT_CHARPOS (Bug#7016). */
5174 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5176 if (it
->current
.overlay_string_index
&& i
== 0)
5177 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5179 /* Initialize IT to deliver display elements from the overlay
5181 it
->string
= it
->overlay_strings
[i
];
5182 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5183 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5184 it
->method
= GET_FROM_STRING
;
5185 it
->stop_charpos
= 0;
5186 if (it
->cmp_it
.stop_pos
>= 0)
5187 it
->cmp_it
.stop_pos
= 0;
5189 it
->base_level_stop
= 0;
5191 /* Set up the bidi iterator for this overlay string. */
5194 it
->bidi_it
.string
.lstring
= it
->string
;
5195 it
->bidi_it
.string
.s
= NULL
;
5196 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5197 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5198 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5199 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5200 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5208 /* Compare two overlay_entry structures E1 and E2. Used as a
5209 comparison function for qsort in load_overlay_strings. Overlay
5210 strings for the same position are sorted so that
5212 1. All after-strings come in front of before-strings, except
5213 when they come from the same overlay.
5215 2. Within after-strings, strings are sorted so that overlay strings
5216 from overlays with higher priorities come first.
5218 2. Within before-strings, strings are sorted so that overlay
5219 strings from overlays with higher priorities come last.
5221 Value is analogous to strcmp. */
5225 compare_overlay_entries (const void *e1
, const void *e2
)
5227 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5228 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5231 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5233 /* Let after-strings appear in front of before-strings if
5234 they come from different overlays. */
5235 if (EQ (entry1
->overlay
, entry2
->overlay
))
5236 result
= entry1
->after_string_p
? 1 : -1;
5238 result
= entry1
->after_string_p
? -1 : 1;
5240 else if (entry1
->priority
!= entry2
->priority
)
5242 if (entry1
->after_string_p
)
5243 /* After-strings sorted in order of decreasing priority. */
5244 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5246 /* Before-strings sorted in order of increasing priority. */
5247 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5256 /* Load the vector IT->overlay_strings with overlay strings from IT's
5257 current buffer position, or from CHARPOS if that is > 0. Set
5258 IT->n_overlays to the total number of overlay strings found.
5260 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5261 a time. On entry into load_overlay_strings,
5262 IT->current.overlay_string_index gives the number of overlay
5263 strings that have already been loaded by previous calls to this
5266 IT->add_overlay_start contains an additional overlay start
5267 position to consider for taking overlay strings from, if non-zero.
5268 This position comes into play when the overlay has an `invisible'
5269 property, and both before and after-strings. When we've skipped to
5270 the end of the overlay, because of its `invisible' property, we
5271 nevertheless want its before-string to appear.
5272 IT->add_overlay_start will contain the overlay start position
5275 Overlay strings are sorted so that after-string strings come in
5276 front of before-string strings. Within before and after-strings,
5277 strings are sorted by overlay priority. See also function
5278 compare_overlay_entries. */
5281 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5283 Lisp_Object overlay
, window
, str
, invisible
;
5284 struct Lisp_Overlay
*ov
;
5285 ptrdiff_t start
, end
;
5286 ptrdiff_t size
= 20;
5287 ptrdiff_t n
= 0, i
, j
;
5289 struct overlay_entry
*entries
5290 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5294 charpos
= IT_CHARPOS (*it
);
5296 /* Append the overlay string STRING of overlay OVERLAY to vector
5297 `entries' which has size `size' and currently contains `n'
5298 elements. AFTER_P non-zero means STRING is an after-string of
5300 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5303 Lisp_Object priority; \
5307 struct overlay_entry *old = entries; \
5308 SAFE_NALLOCA (entries, 2, size); \
5309 memcpy (entries, old, size * sizeof *entries); \
5313 entries[n].string = (STRING); \
5314 entries[n].overlay = (OVERLAY); \
5315 priority = Foverlay_get ((OVERLAY), Qpriority); \
5316 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5317 entries[n].after_string_p = (AFTER_P); \
5322 /* Process overlay before the overlay center. */
5323 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5325 XSETMISC (overlay
, ov
);
5326 xassert (OVERLAYP (overlay
));
5327 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5328 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5333 /* Skip this overlay if it doesn't start or end at IT's current
5335 if (end
!= charpos
&& start
!= charpos
)
5338 /* Skip this overlay if it doesn't apply to IT->w. */
5339 window
= Foverlay_get (overlay
, Qwindow
);
5340 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5343 /* If the text ``under'' the overlay is invisible, both before-
5344 and after-strings from this overlay are visible; start and
5345 end position are indistinguishable. */
5346 invisible
= Foverlay_get (overlay
, Qinvisible
);
5347 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5349 /* If overlay has a non-empty before-string, record it. */
5350 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5351 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5353 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5355 /* If overlay has a non-empty after-string, record it. */
5356 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5357 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5359 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5362 /* Process overlays after the overlay center. */
5363 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5365 XSETMISC (overlay
, ov
);
5366 xassert (OVERLAYP (overlay
));
5367 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5368 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5370 if (start
> charpos
)
5373 /* Skip this overlay if it doesn't start or end at IT's current
5375 if (end
!= charpos
&& start
!= charpos
)
5378 /* Skip this overlay if it doesn't apply to IT->w. */
5379 window
= Foverlay_get (overlay
, Qwindow
);
5380 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5383 /* If the text ``under'' the overlay is invisible, it has a zero
5384 dimension, and both before- and after-strings apply. */
5385 invisible
= Foverlay_get (overlay
, Qinvisible
);
5386 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5388 /* If overlay has a non-empty before-string, record it. */
5389 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5390 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5392 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5394 /* If overlay has a non-empty after-string, record it. */
5395 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5396 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5398 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5401 #undef RECORD_OVERLAY_STRING
5405 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5407 /* Record number of overlay strings, and where we computed it. */
5408 it
->n_overlay_strings
= n
;
5409 it
->overlay_strings_charpos
= charpos
;
5411 /* IT->current.overlay_string_index is the number of overlay strings
5412 that have already been consumed by IT. Copy some of the
5413 remaining overlay strings to IT->overlay_strings. */
5415 j
= it
->current
.overlay_string_index
;
5416 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5418 it
->overlay_strings
[i
] = entries
[j
].string
;
5419 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5427 /* Get the first chunk of overlay strings at IT's current buffer
5428 position, or at CHARPOS if that is > 0. Value is non-zero if at
5429 least one overlay string was found. */
5432 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5434 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5435 process. This fills IT->overlay_strings with strings, and sets
5436 IT->n_overlay_strings to the total number of strings to process.
5437 IT->pos.overlay_string_index has to be set temporarily to zero
5438 because load_overlay_strings needs this; it must be set to -1
5439 when no overlay strings are found because a zero value would
5440 indicate a position in the first overlay string. */
5441 it
->current
.overlay_string_index
= 0;
5442 load_overlay_strings (it
, charpos
);
5444 /* If we found overlay strings, set up IT to deliver display
5445 elements from the first one. Otherwise set up IT to deliver
5446 from current_buffer. */
5447 if (it
->n_overlay_strings
)
5449 /* Make sure we know settings in current_buffer, so that we can
5450 restore meaningful values when we're done with the overlay
5453 compute_stop_pos (it
);
5454 xassert (it
->face_id
>= 0);
5456 /* Save IT's settings. They are restored after all overlay
5457 strings have been processed. */
5458 xassert (!compute_stop_p
|| it
->sp
== 0);
5460 /* When called from handle_stop, there might be an empty display
5461 string loaded. In that case, don't bother saving it. */
5462 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5465 /* Set up IT to deliver display elements from the first overlay
5467 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5468 it
->string
= it
->overlay_strings
[0];
5469 it
->from_overlay
= Qnil
;
5470 it
->stop_charpos
= 0;
5471 xassert (STRINGP (it
->string
));
5472 it
->end_charpos
= SCHARS (it
->string
);
5474 it
->base_level_stop
= 0;
5475 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5476 it
->method
= GET_FROM_STRING
;
5477 it
->from_disp_prop_p
= 0;
5479 /* Force paragraph direction to be that of the parent
5481 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5482 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5484 it
->paragraph_embedding
= L2R
;
5486 /* Set up the bidi iterator for this overlay string. */
5489 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5491 it
->bidi_it
.string
.lstring
= it
->string
;
5492 it
->bidi_it
.string
.s
= NULL
;
5493 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5494 it
->bidi_it
.string
.bufpos
= pos
;
5495 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5496 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5497 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5502 it
->current
.overlay_string_index
= -1;
5507 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5510 it
->method
= GET_FROM_BUFFER
;
5512 (void) get_overlay_strings_1 (it
, charpos
, 1);
5516 /* Value is non-zero if we found at least one overlay string. */
5517 return STRINGP (it
->string
);
5522 /***********************************************************************
5523 Saving and restoring state
5524 ***********************************************************************/
5526 /* Save current settings of IT on IT->stack. Called, for example,
5527 before setting up IT for an overlay string, to be able to restore
5528 IT's settings to what they were after the overlay string has been
5529 processed. If POSITION is non-NULL, it is the position to save on
5530 the stack instead of IT->position. */
5533 push_it (struct it
*it
, struct text_pos
*position
)
5535 struct iterator_stack_entry
*p
;
5537 xassert (it
->sp
< IT_STACK_SIZE
);
5538 p
= it
->stack
+ it
->sp
;
5540 p
->stop_charpos
= it
->stop_charpos
;
5541 p
->prev_stop
= it
->prev_stop
;
5542 p
->base_level_stop
= it
->base_level_stop
;
5543 p
->cmp_it
= it
->cmp_it
;
5544 xassert (it
->face_id
>= 0);
5545 p
->face_id
= it
->face_id
;
5546 p
->string
= it
->string
;
5547 p
->method
= it
->method
;
5548 p
->from_overlay
= it
->from_overlay
;
5551 case GET_FROM_IMAGE
:
5552 p
->u
.image
.object
= it
->object
;
5553 p
->u
.image
.image_id
= it
->image_id
;
5554 p
->u
.image
.slice
= it
->slice
;
5556 case GET_FROM_STRETCH
:
5557 p
->u
.stretch
.object
= it
->object
;
5560 p
->position
= position
? *position
: it
->position
;
5561 p
->current
= it
->current
;
5562 p
->end_charpos
= it
->end_charpos
;
5563 p
->string_nchars
= it
->string_nchars
;
5565 p
->multibyte_p
= it
->multibyte_p
;
5566 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5567 p
->space_width
= it
->space_width
;
5568 p
->font_height
= it
->font_height
;
5569 p
->voffset
= it
->voffset
;
5570 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5571 p
->display_ellipsis_p
= 0;
5572 p
->line_wrap
= it
->line_wrap
;
5573 p
->bidi_p
= it
->bidi_p
;
5574 p
->paragraph_embedding
= it
->paragraph_embedding
;
5575 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5578 /* Save the state of the bidi iterator as well. */
5580 bidi_push_it (&it
->bidi_it
);
5584 iterate_out_of_display_property (struct it
*it
)
5586 int buffer_p
= BUFFERP (it
->object
);
5587 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5588 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5590 xassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5592 /* Maybe initialize paragraph direction. If we are at the beginning
5593 of a new paragraph, next_element_from_buffer may not have a
5594 chance to do that. */
5595 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5596 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5597 /* prev_stop can be zero, so check against BEGV as well. */
5598 while (it
->bidi_it
.charpos
>= bob
5599 && it
->prev_stop
<= it
->bidi_it
.charpos
5600 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5601 && it
->bidi_it
.charpos
< eob
)
5602 bidi_move_to_visually_next (&it
->bidi_it
);
5603 /* Record the stop_pos we just crossed, for when we cross it
5605 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5606 it
->prev_stop
= CHARPOS (it
->position
);
5607 /* If we ended up not where pop_it put us, resync IT's
5608 positional members with the bidi iterator. */
5609 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5610 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5612 it
->current
.pos
= it
->position
;
5614 it
->current
.string_pos
= it
->position
;
5617 /* Restore IT's settings from IT->stack. Called, for example, when no
5618 more overlay strings must be processed, and we return to delivering
5619 display elements from a buffer, or when the end of a string from a
5620 `display' property is reached and we return to delivering display
5621 elements from an overlay string, or from a buffer. */
5624 pop_it (struct it
*it
)
5626 struct iterator_stack_entry
*p
;
5627 int from_display_prop
= it
->from_disp_prop_p
;
5629 xassert (it
->sp
> 0);
5631 p
= it
->stack
+ it
->sp
;
5632 it
->stop_charpos
= p
->stop_charpos
;
5633 it
->prev_stop
= p
->prev_stop
;
5634 it
->base_level_stop
= p
->base_level_stop
;
5635 it
->cmp_it
= p
->cmp_it
;
5636 it
->face_id
= p
->face_id
;
5637 it
->current
= p
->current
;
5638 it
->position
= p
->position
;
5639 it
->string
= p
->string
;
5640 it
->from_overlay
= p
->from_overlay
;
5641 if (NILP (it
->string
))
5642 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5643 it
->method
= p
->method
;
5646 case GET_FROM_IMAGE
:
5647 it
->image_id
= p
->u
.image
.image_id
;
5648 it
->object
= p
->u
.image
.object
;
5649 it
->slice
= p
->u
.image
.slice
;
5651 case GET_FROM_STRETCH
:
5652 it
->object
= p
->u
.stretch
.object
;
5654 case GET_FROM_BUFFER
:
5655 it
->object
= it
->w
->buffer
;
5657 case GET_FROM_STRING
:
5658 it
->object
= it
->string
;
5660 case GET_FROM_DISPLAY_VECTOR
:
5662 it
->method
= GET_FROM_C_STRING
;
5663 else if (STRINGP (it
->string
))
5664 it
->method
= GET_FROM_STRING
;
5667 it
->method
= GET_FROM_BUFFER
;
5668 it
->object
= it
->w
->buffer
;
5671 it
->end_charpos
= p
->end_charpos
;
5672 it
->string_nchars
= p
->string_nchars
;
5674 it
->multibyte_p
= p
->multibyte_p
;
5675 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5676 it
->space_width
= p
->space_width
;
5677 it
->font_height
= p
->font_height
;
5678 it
->voffset
= p
->voffset
;
5679 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5680 it
->line_wrap
= p
->line_wrap
;
5681 it
->bidi_p
= p
->bidi_p
;
5682 it
->paragraph_embedding
= p
->paragraph_embedding
;
5683 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5686 bidi_pop_it (&it
->bidi_it
);
5687 /* Bidi-iterate until we get out of the portion of text, if any,
5688 covered by a `display' text property or by an overlay with
5689 `display' property. (We cannot just jump there, because the
5690 internal coherency of the bidi iterator state can not be
5691 preserved across such jumps.) We also must determine the
5692 paragraph base direction if the overlay we just processed is
5693 at the beginning of a new paragraph. */
5694 if (from_display_prop
5695 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5696 iterate_out_of_display_property (it
);
5698 xassert ((BUFFERP (it
->object
)
5699 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5700 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5701 || (STRINGP (it
->object
)
5702 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5703 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5704 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5710 /***********************************************************************
5712 ***********************************************************************/
5714 /* Set IT's current position to the previous line start. */
5717 back_to_previous_line_start (struct it
*it
)
5719 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5720 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5724 /* Move IT to the next line start.
5726 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5727 we skipped over part of the text (as opposed to moving the iterator
5728 continuously over the text). Otherwise, don't change the value
5731 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5732 iterator on the newline, if it was found.
5734 Newlines may come from buffer text, overlay strings, or strings
5735 displayed via the `display' property. That's the reason we can't
5736 simply use find_next_newline_no_quit.
5738 Note that this function may not skip over invisible text that is so
5739 because of text properties and immediately follows a newline. If
5740 it would, function reseat_at_next_visible_line_start, when called
5741 from set_iterator_to_next, would effectively make invisible
5742 characters following a newline part of the wrong glyph row, which
5743 leads to wrong cursor motion. */
5746 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5747 struct bidi_it
*bidi_it_prev
)
5749 ptrdiff_t old_selective
;
5750 int newline_found_p
, n
;
5751 const int MAX_NEWLINE_DISTANCE
= 500;
5753 /* If already on a newline, just consume it to avoid unintended
5754 skipping over invisible text below. */
5755 if (it
->what
== IT_CHARACTER
5757 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5759 if (it
->bidi_p
&& bidi_it_prev
)
5760 *bidi_it_prev
= it
->bidi_it
;
5761 set_iterator_to_next (it
, 0);
5766 /* Don't handle selective display in the following. It's (a)
5767 unnecessary because it's done by the caller, and (b) leads to an
5768 infinite recursion because next_element_from_ellipsis indirectly
5769 calls this function. */
5770 old_selective
= it
->selective
;
5773 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5774 from buffer text. */
5775 for (n
= newline_found_p
= 0;
5776 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5777 n
+= STRINGP (it
->string
) ? 0 : 1)
5779 if (!get_next_display_element (it
))
5781 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5782 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5783 *bidi_it_prev
= it
->bidi_it
;
5784 set_iterator_to_next (it
, 0);
5787 /* If we didn't find a newline near enough, see if we can use a
5789 if (!newline_found_p
)
5791 ptrdiff_t start
= IT_CHARPOS (*it
);
5792 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5795 xassert (!STRINGP (it
->string
));
5797 /* If there isn't any `display' property in sight, and no
5798 overlays, we can just use the position of the newline in
5800 if (it
->stop_charpos
>= limit
5801 || ((pos
= Fnext_single_property_change (make_number (start
),
5803 make_number (limit
)),
5805 && next_overlay_change (start
) == ZV
))
5809 IT_CHARPOS (*it
) = limit
;
5810 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5814 struct bidi_it bprev
;
5816 /* Help bidi.c avoid expensive searches for display
5817 properties and overlays, by telling it that there are
5818 none up to `limit'. */
5819 if (it
->bidi_it
.disp_pos
< limit
)
5821 it
->bidi_it
.disp_pos
= limit
;
5822 it
->bidi_it
.disp_prop
= 0;
5825 bprev
= it
->bidi_it
;
5826 bidi_move_to_visually_next (&it
->bidi_it
);
5827 } while (it
->bidi_it
.charpos
!= limit
);
5828 IT_CHARPOS (*it
) = limit
;
5829 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5831 *bidi_it_prev
= bprev
;
5833 *skipped_p
= newline_found_p
= 1;
5837 while (get_next_display_element (it
)
5838 && !newline_found_p
)
5840 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5841 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5842 *bidi_it_prev
= it
->bidi_it
;
5843 set_iterator_to_next (it
, 0);
5848 it
->selective
= old_selective
;
5849 return newline_found_p
;
5853 /* Set IT's current position to the previous visible line start. Skip
5854 invisible text that is so either due to text properties or due to
5855 selective display. Caution: this does not change IT->current_x and
5859 back_to_previous_visible_line_start (struct it
*it
)
5861 while (IT_CHARPOS (*it
) > BEGV
)
5863 back_to_previous_line_start (it
);
5865 if (IT_CHARPOS (*it
) <= BEGV
)
5868 /* If selective > 0, then lines indented more than its value are
5870 if (it
->selective
> 0
5871 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5875 /* Check the newline before point for invisibility. */
5878 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5879 Qinvisible
, it
->window
);
5880 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5884 if (IT_CHARPOS (*it
) <= BEGV
)
5889 void *it2data
= NULL
;
5892 Lisp_Object val
, overlay
;
5894 SAVE_IT (it2
, *it
, it2data
);
5896 /* If newline is part of a composition, continue from start of composition */
5897 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5898 && beg
< IT_CHARPOS (*it
))
5901 /* If newline is replaced by a display property, find start of overlay
5902 or interval and continue search from that point. */
5903 pos
= --IT_CHARPOS (it2
);
5906 bidi_unshelve_cache (NULL
, 0);
5907 it2
.string_from_display_prop_p
= 0;
5908 it2
.from_disp_prop_p
= 0;
5909 if (handle_display_prop (&it2
) == HANDLED_RETURN
5910 && !NILP (val
= get_char_property_and_overlay
5911 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5912 && (OVERLAYP (overlay
)
5913 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5914 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5916 RESTORE_IT (it
, it
, it2data
);
5920 /* Newline is not replaced by anything -- so we are done. */
5921 RESTORE_IT (it
, it
, it2data
);
5927 IT_CHARPOS (*it
) = beg
;
5928 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5932 it
->continuation_lines_width
= 0;
5934 xassert (IT_CHARPOS (*it
) >= BEGV
);
5935 xassert (IT_CHARPOS (*it
) == BEGV
5936 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5941 /* Reseat iterator IT at the previous visible line start. Skip
5942 invisible text that is so either due to text properties or due to
5943 selective display. At the end, update IT's overlay information,
5944 face information etc. */
5947 reseat_at_previous_visible_line_start (struct it
*it
)
5949 back_to_previous_visible_line_start (it
);
5950 reseat (it
, it
->current
.pos
, 1);
5955 /* Reseat iterator IT on the next visible line start in the current
5956 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5957 preceding the line start. Skip over invisible text that is so
5958 because of selective display. Compute faces, overlays etc at the
5959 new position. Note that this function does not skip over text that
5960 is invisible because of text properties. */
5963 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5965 int newline_found_p
, skipped_p
= 0;
5966 struct bidi_it bidi_it_prev
;
5968 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
5970 /* Skip over lines that are invisible because they are indented
5971 more than the value of IT->selective. */
5972 if (it
->selective
> 0)
5973 while (IT_CHARPOS (*it
) < ZV
5974 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5977 xassert (IT_BYTEPOS (*it
) == BEGV
5978 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5980 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
5983 /* Position on the newline if that's what's requested. */
5984 if (on_newline_p
&& newline_found_p
)
5986 if (STRINGP (it
->string
))
5988 if (IT_STRING_CHARPOS (*it
) > 0)
5992 --IT_STRING_CHARPOS (*it
);
5993 --IT_STRING_BYTEPOS (*it
);
5997 /* We need to restore the bidi iterator to the state
5998 it had on the newline, and resync the IT's
5999 position with that. */
6000 it
->bidi_it
= bidi_it_prev
;
6001 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6002 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6006 else if (IT_CHARPOS (*it
) > BEGV
)
6015 /* We need to restore the bidi iterator to the state it
6016 had on the newline and resync IT with that. */
6017 it
->bidi_it
= bidi_it_prev
;
6018 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6019 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6021 reseat (it
, it
->current
.pos
, 0);
6025 reseat (it
, it
->current
.pos
, 0);
6032 /***********************************************************************
6033 Changing an iterator's position
6034 ***********************************************************************/
6036 /* Change IT's current position to POS in current_buffer. If FORCE_P
6037 is non-zero, always check for text properties at the new position.
6038 Otherwise, text properties are only looked up if POS >=
6039 IT->check_charpos of a property. */
6042 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6044 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6046 reseat_1 (it
, pos
, 0);
6048 /* Determine where to check text properties. Avoid doing it
6049 where possible because text property lookup is very expensive. */
6051 || CHARPOS (pos
) > it
->stop_charpos
6052 || CHARPOS (pos
) < original_pos
)
6056 /* For bidi iteration, we need to prime prev_stop and
6057 base_level_stop with our best estimations. */
6058 /* Implementation note: Of course, POS is not necessarily a
6059 stop position, so assigning prev_pos to it is a lie; we
6060 should have called compute_stop_backwards. However, if
6061 the current buffer does not include any R2L characters,
6062 that call would be a waste of cycles, because the
6063 iterator will never move back, and thus never cross this
6064 "fake" stop position. So we delay that backward search
6065 until the time we really need it, in next_element_from_buffer. */
6066 if (CHARPOS (pos
) != it
->prev_stop
)
6067 it
->prev_stop
= CHARPOS (pos
);
6068 if (CHARPOS (pos
) < it
->base_level_stop
)
6069 it
->base_level_stop
= 0; /* meaning it's unknown */
6075 it
->prev_stop
= it
->base_level_stop
= 0;
6084 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6085 IT->stop_pos to POS, also. */
6088 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6090 /* Don't call this function when scanning a C string. */
6091 xassert (it
->s
== NULL
);
6093 /* POS must be a reasonable value. */
6094 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6096 it
->current
.pos
= it
->position
= pos
;
6097 it
->end_charpos
= ZV
;
6099 it
->current
.dpvec_index
= -1;
6100 it
->current
.overlay_string_index
= -1;
6101 IT_STRING_CHARPOS (*it
) = -1;
6102 IT_STRING_BYTEPOS (*it
) = -1;
6104 it
->method
= GET_FROM_BUFFER
;
6105 it
->object
= it
->w
->buffer
;
6106 it
->area
= TEXT_AREA
;
6107 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6109 it
->string_from_display_prop_p
= 0;
6110 it
->from_disp_prop_p
= 0;
6111 it
->face_before_selective_p
= 0;
6114 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6116 bidi_unshelve_cache (NULL
, 0);
6117 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6118 it
->bidi_it
.string
.s
= NULL
;
6119 it
->bidi_it
.string
.lstring
= Qnil
;
6120 it
->bidi_it
.string
.bufpos
= 0;
6121 it
->bidi_it
.string
.unibyte
= 0;
6126 it
->stop_charpos
= CHARPOS (pos
);
6127 it
->base_level_stop
= CHARPOS (pos
);
6132 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6133 If S is non-null, it is a C string to iterate over. Otherwise,
6134 STRING gives a Lisp string to iterate over.
6136 If PRECISION > 0, don't return more then PRECISION number of
6137 characters from the string.
6139 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6140 characters have been returned. FIELD_WIDTH < 0 means an infinite
6143 MULTIBYTE = 0 means disable processing of multibyte characters,
6144 MULTIBYTE > 0 means enable it,
6145 MULTIBYTE < 0 means use IT->multibyte_p.
6147 IT must be initialized via a prior call to init_iterator before
6148 calling this function. */
6151 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6152 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6155 /* No region in strings. */
6156 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6158 /* No text property checks performed by default, but see below. */
6159 it
->stop_charpos
= -1;
6161 /* Set iterator position and end position. */
6162 memset (&it
->current
, 0, sizeof it
->current
);
6163 it
->current
.overlay_string_index
= -1;
6164 it
->current
.dpvec_index
= -1;
6165 xassert (charpos
>= 0);
6167 /* If STRING is specified, use its multibyteness, otherwise use the
6168 setting of MULTIBYTE, if specified. */
6170 it
->multibyte_p
= multibyte
> 0;
6172 /* Bidirectional reordering of strings is controlled by the default
6173 value of bidi-display-reordering. Don't try to reorder while
6174 loading loadup.el, as the necessary character property tables are
6175 not yet available. */
6178 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6182 xassert (STRINGP (string
));
6183 it
->string
= string
;
6185 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6186 it
->method
= GET_FROM_STRING
;
6187 it
->current
.string_pos
= string_pos (charpos
, string
);
6191 it
->bidi_it
.string
.lstring
= string
;
6192 it
->bidi_it
.string
.s
= NULL
;
6193 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6194 it
->bidi_it
.string
.bufpos
= 0;
6195 it
->bidi_it
.string
.from_disp_str
= 0;
6196 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6197 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6198 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6203 it
->s
= (const unsigned char *) s
;
6206 /* Note that we use IT->current.pos, not it->current.string_pos,
6207 for displaying C strings. */
6208 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6209 if (it
->multibyte_p
)
6211 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6212 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6216 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6217 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6222 it
->bidi_it
.string
.lstring
= Qnil
;
6223 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6224 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6225 it
->bidi_it
.string
.bufpos
= 0;
6226 it
->bidi_it
.string
.from_disp_str
= 0;
6227 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6228 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6231 it
->method
= GET_FROM_C_STRING
;
6234 /* PRECISION > 0 means don't return more than PRECISION characters
6236 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6238 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6240 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6243 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6244 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6245 FIELD_WIDTH < 0 means infinite field width. This is useful for
6246 padding with `-' at the end of a mode line. */
6247 if (field_width
< 0)
6248 field_width
= INFINITY
;
6249 /* Implementation note: We deliberately don't enlarge
6250 it->bidi_it.string.schars here to fit it->end_charpos, because
6251 the bidi iterator cannot produce characters out of thin air. */
6252 if (field_width
> it
->end_charpos
- charpos
)
6253 it
->end_charpos
= charpos
+ field_width
;
6255 /* Use the standard display table for displaying strings. */
6256 if (DISP_TABLE_P (Vstandard_display_table
))
6257 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6259 it
->stop_charpos
= charpos
;
6260 it
->prev_stop
= charpos
;
6261 it
->base_level_stop
= 0;
6264 it
->bidi_it
.first_elt
= 1;
6265 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6266 it
->bidi_it
.disp_pos
= -1;
6268 if (s
== NULL
&& it
->multibyte_p
)
6270 ptrdiff_t endpos
= SCHARS (it
->string
);
6271 if (endpos
> it
->end_charpos
)
6272 endpos
= it
->end_charpos
;
6273 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6281 /***********************************************************************
6283 ***********************************************************************/
6285 /* Map enum it_method value to corresponding next_element_from_* function. */
6287 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6289 next_element_from_buffer
,
6290 next_element_from_display_vector
,
6291 next_element_from_string
,
6292 next_element_from_c_string
,
6293 next_element_from_image
,
6294 next_element_from_stretch
6297 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6300 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6301 (possibly with the following characters). */
6303 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6304 ((IT)->cmp_it.id >= 0 \
6305 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6306 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6307 END_CHARPOS, (IT)->w, \
6308 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6312 /* Lookup the char-table Vglyphless_char_display for character C (-1
6313 if we want information for no-font case), and return the display
6314 method symbol. By side-effect, update it->what and
6315 it->glyphless_method. This function is called from
6316 get_next_display_element for each character element, and from
6317 x_produce_glyphs when no suitable font was found. */
6320 lookup_glyphless_char_display (int c
, struct it
*it
)
6322 Lisp_Object glyphless_method
= Qnil
;
6324 if (CHAR_TABLE_P (Vglyphless_char_display
)
6325 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6329 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6330 if (CONSP (glyphless_method
))
6331 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6332 ? XCAR (glyphless_method
)
6333 : XCDR (glyphless_method
);
6336 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6340 if (NILP (glyphless_method
))
6343 /* The default is to display the character by a proper font. */
6345 /* The default for the no-font case is to display an empty box. */
6346 glyphless_method
= Qempty_box
;
6348 if (EQ (glyphless_method
, Qzero_width
))
6351 return glyphless_method
;
6352 /* This method can't be used for the no-font case. */
6353 glyphless_method
= Qempty_box
;
6355 if (EQ (glyphless_method
, Qthin_space
))
6356 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6357 else if (EQ (glyphless_method
, Qempty_box
))
6358 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6359 else if (EQ (glyphless_method
, Qhex_code
))
6360 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6361 else if (STRINGP (glyphless_method
))
6362 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6365 /* Invalid value. We use the default method. */
6366 glyphless_method
= Qnil
;
6369 it
->what
= IT_GLYPHLESS
;
6370 return glyphless_method
;
6373 /* Load IT's display element fields with information about the next
6374 display element from the current position of IT. Value is zero if
6375 end of buffer (or C string) is reached. */
6377 static struct frame
*last_escape_glyph_frame
= NULL
;
6378 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6379 static int last_escape_glyph_merged_face_id
= 0;
6381 struct frame
*last_glyphless_glyph_frame
= NULL
;
6382 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6383 int last_glyphless_glyph_merged_face_id
= 0;
6386 get_next_display_element (struct it
*it
)
6388 /* Non-zero means that we found a display element. Zero means that
6389 we hit the end of what we iterate over. Performance note: the
6390 function pointer `method' used here turns out to be faster than
6391 using a sequence of if-statements. */
6395 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6397 if (it
->what
== IT_CHARACTER
)
6399 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6400 and only if (a) the resolved directionality of that character
6402 /* FIXME: Do we need an exception for characters from display
6404 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6405 it
->c
= bidi_mirror_char (it
->c
);
6406 /* Map via display table or translate control characters.
6407 IT->c, IT->len etc. have been set to the next character by
6408 the function call above. If we have a display table, and it
6409 contains an entry for IT->c, translate it. Don't do this if
6410 IT->c itself comes from a display table, otherwise we could
6411 end up in an infinite recursion. (An alternative could be to
6412 count the recursion depth of this function and signal an
6413 error when a certain maximum depth is reached.) Is it worth
6415 if (success_p
&& it
->dpvec
== NULL
)
6418 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6419 int nonascii_space_p
= 0;
6420 int nonascii_hyphen_p
= 0;
6421 int c
= it
->c
; /* This is the character to display. */
6423 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6425 xassert (SINGLE_BYTE_CHAR_P (c
));
6426 if (unibyte_display_via_language_environment
)
6428 c
= DECODE_CHAR (unibyte
, c
);
6430 c
= BYTE8_TO_CHAR (it
->c
);
6433 c
= BYTE8_TO_CHAR (it
->c
);
6437 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6440 struct Lisp_Vector
*v
= XVECTOR (dv
);
6442 /* Return the first character from the display table
6443 entry, if not empty. If empty, don't display the
6444 current character. */
6447 it
->dpvec_char_len
= it
->len
;
6448 it
->dpvec
= v
->contents
;
6449 it
->dpend
= v
->contents
+ v
->header
.size
;
6450 it
->current
.dpvec_index
= 0;
6451 it
->dpvec_face_id
= -1;
6452 it
->saved_face_id
= it
->face_id
;
6453 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6458 set_iterator_to_next (it
, 0);
6463 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6465 if (it
->what
== IT_GLYPHLESS
)
6467 /* Don't display this character. */
6468 set_iterator_to_next (it
, 0);
6472 /* If `nobreak-char-display' is non-nil, we display
6473 non-ASCII spaces and hyphens specially. */
6474 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6477 nonascii_space_p
= 1;
6478 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6479 nonascii_hyphen_p
= 1;
6482 /* Translate control characters into `\003' or `^C' form.
6483 Control characters coming from a display table entry are
6484 currently not translated because we use IT->dpvec to hold
6485 the translation. This could easily be changed but I
6486 don't believe that it is worth doing.
6488 The characters handled by `nobreak-char-display' must be
6491 Non-printable characters and raw-byte characters are also
6492 translated to octal form. */
6493 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6494 ? (it
->area
!= TEXT_AREA
6495 /* In mode line, treat \n, \t like other crl chars. */
6498 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6499 || (c
!= '\n' && c
!= '\t'))
6501 || nonascii_hyphen_p
6503 || ! CHAR_PRINTABLE_P (c
))))
6505 /* C is a control character, non-ASCII space/hyphen,
6506 raw-byte, or a non-printable character which must be
6507 displayed either as '\003' or as `^C' where the '\\'
6508 and '^' can be defined in the display table. Fill
6509 IT->ctl_chars with glyphs for what we have to
6510 display. Then, set IT->dpvec to these glyphs. */
6517 /* Handle control characters with ^. */
6519 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6523 g
= '^'; /* default glyph for Control */
6524 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6526 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6528 g
= GLYPH_CODE_CHAR (gc
);
6529 lface_id
= GLYPH_CODE_FACE (gc
);
6533 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6535 else if (it
->f
== last_escape_glyph_frame
6536 && it
->face_id
== last_escape_glyph_face_id
)
6538 face_id
= last_escape_glyph_merged_face_id
;
6542 /* Merge the escape-glyph face into the current face. */
6543 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6545 last_escape_glyph_frame
= it
->f
;
6546 last_escape_glyph_face_id
= it
->face_id
;
6547 last_escape_glyph_merged_face_id
= face_id
;
6550 XSETINT (it
->ctl_chars
[0], g
);
6551 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6553 goto display_control
;
6556 /* Handle non-ascii space in the mode where it only gets
6559 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6561 /* Merge `nobreak-space' into the current face. */
6562 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6564 XSETINT (it
->ctl_chars
[0], ' ');
6566 goto display_control
;
6569 /* Handle sequences that start with the "escape glyph". */
6571 /* the default escape glyph is \. */
6572 escape_glyph
= '\\';
6575 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6577 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6578 lface_id
= GLYPH_CODE_FACE (gc
);
6582 /* The display table specified a face.
6583 Merge it into face_id and also into escape_glyph. */
6584 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6587 else if (it
->f
== last_escape_glyph_frame
6588 && it
->face_id
== last_escape_glyph_face_id
)
6590 face_id
= last_escape_glyph_merged_face_id
;
6594 /* Merge the escape-glyph face into the current face. */
6595 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6597 last_escape_glyph_frame
= it
->f
;
6598 last_escape_glyph_face_id
= it
->face_id
;
6599 last_escape_glyph_merged_face_id
= face_id
;
6602 /* Draw non-ASCII hyphen with just highlighting: */
6604 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6606 XSETINT (it
->ctl_chars
[0], '-');
6608 goto display_control
;
6611 /* Draw non-ASCII space/hyphen with escape glyph: */
6613 if (nonascii_space_p
|| nonascii_hyphen_p
)
6615 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6616 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6618 goto display_control
;
6625 if (CHAR_BYTE8_P (c
))
6626 /* Display \200 instead of \17777600. */
6627 c
= CHAR_TO_BYTE8 (c
);
6628 len
= sprintf (str
, "%03o", c
);
6630 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6631 for (i
= 0; i
< len
; i
++)
6632 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6637 /* Set up IT->dpvec and return first character from it. */
6638 it
->dpvec_char_len
= it
->len
;
6639 it
->dpvec
= it
->ctl_chars
;
6640 it
->dpend
= it
->dpvec
+ ctl_len
;
6641 it
->current
.dpvec_index
= 0;
6642 it
->dpvec_face_id
= face_id
;
6643 it
->saved_face_id
= it
->face_id
;
6644 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6648 it
->char_to_display
= c
;
6652 it
->char_to_display
= it
->c
;
6656 /* Adjust face id for a multibyte character. There are no multibyte
6657 character in unibyte text. */
6658 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6661 && FRAME_WINDOW_P (it
->f
))
6663 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6665 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6667 /* Automatic composition with glyph-string. */
6668 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6670 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6674 ptrdiff_t pos
= (it
->s
? -1
6675 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6676 : IT_CHARPOS (*it
));
6679 if (it
->what
== IT_CHARACTER
)
6680 c
= it
->char_to_display
;
6683 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6687 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6688 /* TAB in a composition means display glyphs with
6689 padding space on the left or right. */
6690 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6693 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6698 /* Is this character the last one of a run of characters with
6699 box? If yes, set IT->end_of_box_run_p to 1. */
6703 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6705 int face_id
= underlying_face_id (it
);
6706 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6710 if (face
->box
== FACE_NO_BOX
)
6712 /* If the box comes from face properties in a
6713 display string, check faces in that string. */
6714 int string_face_id
= face_after_it_pos (it
);
6715 it
->end_of_box_run_p
6716 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6719 /* Otherwise, the box comes from the underlying face.
6720 If this is the last string character displayed, check
6721 the next buffer location. */
6722 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6723 && (it
->current
.overlay_string_index
6724 == it
->n_overlay_strings
- 1))
6728 struct text_pos pos
= it
->current
.pos
;
6729 INC_TEXT_POS (pos
, it
->multibyte_p
);
6731 next_face_id
= face_at_buffer_position
6732 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6733 it
->region_end_charpos
, &ignore
,
6734 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6736 it
->end_of_box_run_p
6737 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6744 int face_id
= face_after_it_pos (it
);
6745 it
->end_of_box_run_p
6746 = (face_id
!= it
->face_id
6747 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6751 /* Value is 0 if end of buffer or string reached. */
6756 /* Move IT to the next display element.
6758 RESEAT_P non-zero means if called on a newline in buffer text,
6759 skip to the next visible line start.
6761 Functions get_next_display_element and set_iterator_to_next are
6762 separate because I find this arrangement easier to handle than a
6763 get_next_display_element function that also increments IT's
6764 position. The way it is we can first look at an iterator's current
6765 display element, decide whether it fits on a line, and if it does,
6766 increment the iterator position. The other way around we probably
6767 would either need a flag indicating whether the iterator has to be
6768 incremented the next time, or we would have to implement a
6769 decrement position function which would not be easy to write. */
6772 set_iterator_to_next (struct it
*it
, int reseat_p
)
6774 /* Reset flags indicating start and end of a sequence of characters
6775 with box. Reset them at the start of this function because
6776 moving the iterator to a new position might set them. */
6777 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6781 case GET_FROM_BUFFER
:
6782 /* The current display element of IT is a character from
6783 current_buffer. Advance in the buffer, and maybe skip over
6784 invisible lines that are so because of selective display. */
6785 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6786 reseat_at_next_visible_line_start (it
, 0);
6787 else if (it
->cmp_it
.id
>= 0)
6789 /* We are currently getting glyphs from a composition. */
6794 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6795 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6796 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6798 it
->cmp_it
.from
= it
->cmp_it
.to
;
6803 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6805 it
->end_charpos
, Qnil
);
6808 else if (! it
->cmp_it
.reversed_p
)
6810 /* Composition created while scanning forward. */
6811 /* Update IT's char/byte positions to point to the first
6812 character of the next grapheme cluster, or to the
6813 character visually after the current composition. */
6814 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6815 bidi_move_to_visually_next (&it
->bidi_it
);
6816 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6817 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6819 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6821 /* Proceed to the next grapheme cluster. */
6822 it
->cmp_it
.from
= it
->cmp_it
.to
;
6826 /* No more grapheme clusters in this composition.
6827 Find the next stop position. */
6828 ptrdiff_t stop
= it
->end_charpos
;
6829 if (it
->bidi_it
.scan_dir
< 0)
6830 /* Now we are scanning backward and don't know
6833 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6834 IT_BYTEPOS (*it
), stop
, Qnil
);
6839 /* Composition created while scanning backward. */
6840 /* Update IT's char/byte positions to point to the last
6841 character of the previous grapheme cluster, or the
6842 character visually after the current composition. */
6843 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6844 bidi_move_to_visually_next (&it
->bidi_it
);
6845 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6846 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6847 if (it
->cmp_it
.from
> 0)
6849 /* Proceed to the previous grapheme cluster. */
6850 it
->cmp_it
.to
= it
->cmp_it
.from
;
6854 /* No more grapheme clusters in this composition.
6855 Find the next stop position. */
6856 ptrdiff_t stop
= it
->end_charpos
;
6857 if (it
->bidi_it
.scan_dir
< 0)
6858 /* Now we are scanning backward and don't know
6861 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6862 IT_BYTEPOS (*it
), stop
, Qnil
);
6868 xassert (it
->len
!= 0);
6872 IT_BYTEPOS (*it
) += it
->len
;
6873 IT_CHARPOS (*it
) += 1;
6877 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6878 /* If this is a new paragraph, determine its base
6879 direction (a.k.a. its base embedding level). */
6880 if (it
->bidi_it
.new_paragraph
)
6881 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6882 bidi_move_to_visually_next (&it
->bidi_it
);
6883 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6884 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6885 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6887 /* As the scan direction was changed, we must
6888 re-compute the stop position for composition. */
6889 ptrdiff_t stop
= it
->end_charpos
;
6890 if (it
->bidi_it
.scan_dir
< 0)
6892 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6893 IT_BYTEPOS (*it
), stop
, Qnil
);
6896 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6900 case GET_FROM_C_STRING
:
6901 /* Current display element of IT is from a C string. */
6903 /* If the string position is beyond string's end, it means
6904 next_element_from_c_string is padding the string with
6905 blanks, in which case we bypass the bidi iterator,
6906 because it cannot deal with such virtual characters. */
6907 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6909 IT_BYTEPOS (*it
) += it
->len
;
6910 IT_CHARPOS (*it
) += 1;
6914 bidi_move_to_visually_next (&it
->bidi_it
);
6915 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6916 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6920 case GET_FROM_DISPLAY_VECTOR
:
6921 /* Current display element of IT is from a display table entry.
6922 Advance in the display table definition. Reset it to null if
6923 end reached, and continue with characters from buffers/
6925 ++it
->current
.dpvec_index
;
6927 /* Restore face of the iterator to what they were before the
6928 display vector entry (these entries may contain faces). */
6929 it
->face_id
= it
->saved_face_id
;
6931 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6933 int recheck_faces
= it
->ellipsis_p
;
6936 it
->method
= GET_FROM_C_STRING
;
6937 else if (STRINGP (it
->string
))
6938 it
->method
= GET_FROM_STRING
;
6941 it
->method
= GET_FROM_BUFFER
;
6942 it
->object
= it
->w
->buffer
;
6946 it
->current
.dpvec_index
= -1;
6948 /* Skip over characters which were displayed via IT->dpvec. */
6949 if (it
->dpvec_char_len
< 0)
6950 reseat_at_next_visible_line_start (it
, 1);
6951 else if (it
->dpvec_char_len
> 0)
6953 if (it
->method
== GET_FROM_STRING
6954 && it
->n_overlay_strings
> 0)
6955 it
->ignore_overlay_strings_at_pos_p
= 1;
6956 it
->len
= it
->dpvec_char_len
;
6957 set_iterator_to_next (it
, reseat_p
);
6960 /* Maybe recheck faces after display vector */
6962 it
->stop_charpos
= IT_CHARPOS (*it
);
6966 case GET_FROM_STRING
:
6967 /* Current display element is a character from a Lisp string. */
6968 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6969 if (it
->cmp_it
.id
>= 0)
6975 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6976 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6977 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6978 it
->cmp_it
.from
= it
->cmp_it
.to
;
6982 composition_compute_stop_pos (&it
->cmp_it
,
6983 IT_STRING_CHARPOS (*it
),
6984 IT_STRING_BYTEPOS (*it
),
6985 it
->end_charpos
, it
->string
);
6988 else if (! it
->cmp_it
.reversed_p
)
6990 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6991 bidi_move_to_visually_next (&it
->bidi_it
);
6992 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6993 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6995 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6996 it
->cmp_it
.from
= it
->cmp_it
.to
;
6999 ptrdiff_t stop
= it
->end_charpos
;
7000 if (it
->bidi_it
.scan_dir
< 0)
7002 composition_compute_stop_pos (&it
->cmp_it
,
7003 IT_STRING_CHARPOS (*it
),
7004 IT_STRING_BYTEPOS (*it
), stop
,
7010 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7011 bidi_move_to_visually_next (&it
->bidi_it
);
7012 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7013 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7014 if (it
->cmp_it
.from
> 0)
7015 it
->cmp_it
.to
= it
->cmp_it
.from
;
7018 ptrdiff_t stop
= it
->end_charpos
;
7019 if (it
->bidi_it
.scan_dir
< 0)
7021 composition_compute_stop_pos (&it
->cmp_it
,
7022 IT_STRING_CHARPOS (*it
),
7023 IT_STRING_BYTEPOS (*it
), stop
,
7031 /* If the string position is beyond string's end, it
7032 means next_element_from_string is padding the string
7033 with blanks, in which case we bypass the bidi
7034 iterator, because it cannot deal with such virtual
7036 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7038 IT_STRING_BYTEPOS (*it
) += it
->len
;
7039 IT_STRING_CHARPOS (*it
) += 1;
7043 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7045 bidi_move_to_visually_next (&it
->bidi_it
);
7046 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7047 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7048 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7050 ptrdiff_t stop
= it
->end_charpos
;
7052 if (it
->bidi_it
.scan_dir
< 0)
7054 composition_compute_stop_pos (&it
->cmp_it
,
7055 IT_STRING_CHARPOS (*it
),
7056 IT_STRING_BYTEPOS (*it
), stop
,
7062 consider_string_end
:
7064 if (it
->current
.overlay_string_index
>= 0)
7066 /* IT->string is an overlay string. Advance to the
7067 next, if there is one. */
7068 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7071 next_overlay_string (it
);
7073 setup_for_ellipsis (it
, 0);
7078 /* IT->string is not an overlay string. If we reached
7079 its end, and there is something on IT->stack, proceed
7080 with what is on the stack. This can be either another
7081 string, this time an overlay string, or a buffer. */
7082 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7086 if (it
->method
== GET_FROM_STRING
)
7087 goto consider_string_end
;
7092 case GET_FROM_IMAGE
:
7093 case GET_FROM_STRETCH
:
7094 /* The position etc with which we have to proceed are on
7095 the stack. The position may be at the end of a string,
7096 if the `display' property takes up the whole string. */
7097 xassert (it
->sp
> 0);
7099 if (it
->method
== GET_FROM_STRING
)
7100 goto consider_string_end
;
7104 /* There are no other methods defined, so this should be a bug. */
7108 xassert (it
->method
!= GET_FROM_STRING
7109 || (STRINGP (it
->string
)
7110 && IT_STRING_CHARPOS (*it
) >= 0));
7113 /* Load IT's display element fields with information about the next
7114 display element which comes from a display table entry or from the
7115 result of translating a control character to one of the forms `^C'
7118 IT->dpvec holds the glyphs to return as characters.
7119 IT->saved_face_id holds the face id before the display vector--it
7120 is restored into IT->face_id in set_iterator_to_next. */
7123 next_element_from_display_vector (struct it
*it
)
7128 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7130 it
->face_id
= it
->saved_face_id
;
7132 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7133 That seemed totally bogus - so I changed it... */
7134 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7136 if (GLYPH_CODE_P (gc
))
7138 it
->c
= GLYPH_CODE_CHAR (gc
);
7139 it
->len
= CHAR_BYTES (it
->c
);
7141 /* The entry may contain a face id to use. Such a face id is
7142 the id of a Lisp face, not a realized face. A face id of
7143 zero means no face is specified. */
7144 if (it
->dpvec_face_id
>= 0)
7145 it
->face_id
= it
->dpvec_face_id
;
7148 int lface_id
= GLYPH_CODE_FACE (gc
);
7150 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7155 /* Display table entry is invalid. Return a space. */
7156 it
->c
= ' ', it
->len
= 1;
7158 /* Don't change position and object of the iterator here. They are
7159 still the values of the character that had this display table
7160 entry or was translated, and that's what we want. */
7161 it
->what
= IT_CHARACTER
;
7165 /* Get the first element of string/buffer in the visual order, after
7166 being reseated to a new position in a string or a buffer. */
7168 get_visually_first_element (struct it
*it
)
7170 int string_p
= STRINGP (it
->string
) || it
->s
;
7171 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7172 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7174 if (STRINGP (it
->string
))
7176 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7177 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7181 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7182 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7185 if (it
->bidi_it
.charpos
== eob
)
7187 /* Nothing to do, but reset the FIRST_ELT flag, like
7188 bidi_paragraph_init does, because we are not going to
7190 it
->bidi_it
.first_elt
= 0;
7192 else if (it
->bidi_it
.charpos
== bob
7194 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7195 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7197 /* If we are at the beginning of a line/string, we can produce
7198 the next element right away. */
7199 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7200 bidi_move_to_visually_next (&it
->bidi_it
);
7204 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7206 /* We need to prime the bidi iterator starting at the line's or
7207 string's beginning, before we will be able to produce the
7210 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7213 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7215 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7217 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7220 /* Now return to buffer/string position where we were asked
7221 to get the next display element, and produce that. */
7222 bidi_move_to_visually_next (&it
->bidi_it
);
7224 while (it
->bidi_it
.bytepos
!= orig_bytepos
7225 && it
->bidi_it
.charpos
< eob
);
7228 /* Adjust IT's position information to where we ended up. */
7229 if (STRINGP (it
->string
))
7231 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7232 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7236 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7237 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7240 if (STRINGP (it
->string
) || !it
->s
)
7242 ptrdiff_t stop
, charpos
, bytepos
;
7244 if (STRINGP (it
->string
))
7247 stop
= SCHARS (it
->string
);
7248 if (stop
> it
->end_charpos
)
7249 stop
= it
->end_charpos
;
7250 charpos
= IT_STRING_CHARPOS (*it
);
7251 bytepos
= IT_STRING_BYTEPOS (*it
);
7255 stop
= it
->end_charpos
;
7256 charpos
= IT_CHARPOS (*it
);
7257 bytepos
= IT_BYTEPOS (*it
);
7259 if (it
->bidi_it
.scan_dir
< 0)
7261 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7266 /* Load IT with the next display element from Lisp string IT->string.
7267 IT->current.string_pos is the current position within the string.
7268 If IT->current.overlay_string_index >= 0, the Lisp string is an
7272 next_element_from_string (struct it
*it
)
7274 struct text_pos position
;
7276 xassert (STRINGP (it
->string
));
7277 xassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7278 xassert (IT_STRING_CHARPOS (*it
) >= 0);
7279 position
= it
->current
.string_pos
;
7281 /* With bidi reordering, the character to display might not be the
7282 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7283 that we were reseat()ed to a new string, whose paragraph
7284 direction is not known. */
7285 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7287 get_visually_first_element (it
);
7288 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7291 /* Time to check for invisible text? */
7292 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7294 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7297 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7298 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7300 /* With bidi non-linear iteration, we could find
7301 ourselves far beyond the last computed stop_charpos,
7302 with several other stop positions in between that we
7303 missed. Scan them all now, in buffer's logical
7304 order, until we find and handle the last stop_charpos
7305 that precedes our current position. */
7306 handle_stop_backwards (it
, it
->stop_charpos
);
7307 return GET_NEXT_DISPLAY_ELEMENT (it
);
7313 /* Take note of the stop position we just moved
7314 across, for when we will move back across it. */
7315 it
->prev_stop
= it
->stop_charpos
;
7316 /* If we are at base paragraph embedding level, take
7317 note of the last stop position seen at this
7319 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7320 it
->base_level_stop
= it
->stop_charpos
;
7324 /* Since a handler may have changed IT->method, we must
7326 return GET_NEXT_DISPLAY_ELEMENT (it
);
7330 /* If we are before prev_stop, we may have overstepped
7331 on our way backwards a stop_pos, and if so, we need
7332 to handle that stop_pos. */
7333 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7334 /* We can sometimes back up for reasons that have nothing
7335 to do with bidi reordering. E.g., compositions. The
7336 code below is only needed when we are above the base
7337 embedding level, so test for that explicitly. */
7338 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7340 /* If we lost track of base_level_stop, we have no better
7341 place for handle_stop_backwards to start from than string
7342 beginning. This happens, e.g., when we were reseated to
7343 the previous screenful of text by vertical-motion. */
7344 if (it
->base_level_stop
<= 0
7345 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7346 it
->base_level_stop
= 0;
7347 handle_stop_backwards (it
, it
->base_level_stop
);
7348 return GET_NEXT_DISPLAY_ELEMENT (it
);
7352 if (it
->current
.overlay_string_index
>= 0)
7354 /* Get the next character from an overlay string. In overlay
7355 strings, There is no field width or padding with spaces to
7357 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7362 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7363 IT_STRING_BYTEPOS (*it
),
7364 it
->bidi_it
.scan_dir
< 0
7366 : SCHARS (it
->string
))
7367 && next_element_from_composition (it
))
7371 else if (STRING_MULTIBYTE (it
->string
))
7373 const unsigned char *s
= (SDATA (it
->string
)
7374 + IT_STRING_BYTEPOS (*it
));
7375 it
->c
= string_char_and_length (s
, &it
->len
);
7379 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7385 /* Get the next character from a Lisp string that is not an
7386 overlay string. Such strings come from the mode line, for
7387 example. We may have to pad with spaces, or truncate the
7388 string. See also next_element_from_c_string. */
7389 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7394 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7396 /* Pad with spaces. */
7397 it
->c
= ' ', it
->len
= 1;
7398 CHARPOS (position
) = BYTEPOS (position
) = -1;
7400 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7401 IT_STRING_BYTEPOS (*it
),
7402 it
->bidi_it
.scan_dir
< 0
7404 : it
->string_nchars
)
7405 && next_element_from_composition (it
))
7409 else if (STRING_MULTIBYTE (it
->string
))
7411 const unsigned char *s
= (SDATA (it
->string
)
7412 + IT_STRING_BYTEPOS (*it
));
7413 it
->c
= string_char_and_length (s
, &it
->len
);
7417 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7422 /* Record what we have and where it came from. */
7423 it
->what
= IT_CHARACTER
;
7424 it
->object
= it
->string
;
7425 it
->position
= position
;
7430 /* Load IT with next display element from C string IT->s.
7431 IT->string_nchars is the maximum number of characters to return
7432 from the string. IT->end_charpos may be greater than
7433 IT->string_nchars when this function is called, in which case we
7434 may have to return padding spaces. Value is zero if end of string
7435 reached, including padding spaces. */
7438 next_element_from_c_string (struct it
*it
)
7443 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7444 it
->what
= IT_CHARACTER
;
7445 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7448 /* With bidi reordering, the character to display might not be the
7449 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7450 we were reseated to a new string, whose paragraph direction is
7452 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7453 get_visually_first_element (it
);
7455 /* IT's position can be greater than IT->string_nchars in case a
7456 field width or precision has been specified when the iterator was
7458 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7460 /* End of the game. */
7464 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7466 /* Pad with spaces. */
7467 it
->c
= ' ', it
->len
= 1;
7468 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7470 else if (it
->multibyte_p
)
7471 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7473 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7479 /* Set up IT to return characters from an ellipsis, if appropriate.
7480 The definition of the ellipsis glyphs may come from a display table
7481 entry. This function fills IT with the first glyph from the
7482 ellipsis if an ellipsis is to be displayed. */
7485 next_element_from_ellipsis (struct it
*it
)
7487 if (it
->selective_display_ellipsis_p
)
7488 setup_for_ellipsis (it
, it
->len
);
7491 /* The face at the current position may be different from the
7492 face we find after the invisible text. Remember what it
7493 was in IT->saved_face_id, and signal that it's there by
7494 setting face_before_selective_p. */
7495 it
->saved_face_id
= it
->face_id
;
7496 it
->method
= GET_FROM_BUFFER
;
7497 it
->object
= it
->w
->buffer
;
7498 reseat_at_next_visible_line_start (it
, 1);
7499 it
->face_before_selective_p
= 1;
7502 return GET_NEXT_DISPLAY_ELEMENT (it
);
7506 /* Deliver an image display element. The iterator IT is already
7507 filled with image information (done in handle_display_prop). Value
7512 next_element_from_image (struct it
*it
)
7514 it
->what
= IT_IMAGE
;
7515 it
->ignore_overlay_strings_at_pos_p
= 0;
7520 /* Fill iterator IT with next display element from a stretch glyph
7521 property. IT->object is the value of the text property. Value is
7525 next_element_from_stretch (struct it
*it
)
7527 it
->what
= IT_STRETCH
;
7531 /* Scan backwards from IT's current position until we find a stop
7532 position, or until BEGV. This is called when we find ourself
7533 before both the last known prev_stop and base_level_stop while
7534 reordering bidirectional text. */
7537 compute_stop_pos_backwards (struct it
*it
)
7539 const int SCAN_BACK_LIMIT
= 1000;
7540 struct text_pos pos
;
7541 struct display_pos save_current
= it
->current
;
7542 struct text_pos save_position
= it
->position
;
7543 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7544 ptrdiff_t where_we_are
= charpos
;
7545 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7546 ptrdiff_t save_end_pos
= it
->end_charpos
;
7548 xassert (NILP (it
->string
) && !it
->s
);
7549 xassert (it
->bidi_p
);
7553 it
->end_charpos
= min (charpos
+ 1, ZV
);
7554 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7555 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7556 reseat_1 (it
, pos
, 0);
7557 compute_stop_pos (it
);
7558 /* We must advance forward, right? */
7559 if (it
->stop_charpos
<= charpos
)
7562 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7564 if (it
->stop_charpos
<= where_we_are
)
7565 it
->prev_stop
= it
->stop_charpos
;
7567 it
->prev_stop
= BEGV
;
7569 it
->current
= save_current
;
7570 it
->position
= save_position
;
7571 it
->stop_charpos
= save_stop_pos
;
7572 it
->end_charpos
= save_end_pos
;
7575 /* Scan forward from CHARPOS in the current buffer/string, until we
7576 find a stop position > current IT's position. Then handle the stop
7577 position before that. This is called when we bump into a stop
7578 position while reordering bidirectional text. CHARPOS should be
7579 the last previously processed stop_pos (or BEGV/0, if none were
7580 processed yet) whose position is less that IT's current
7584 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7586 int bufp
= !STRINGP (it
->string
);
7587 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7588 struct display_pos save_current
= it
->current
;
7589 struct text_pos save_position
= it
->position
;
7590 struct text_pos pos1
;
7591 ptrdiff_t next_stop
;
7593 /* Scan in strict logical order. */
7594 xassert (it
->bidi_p
);
7598 it
->prev_stop
= charpos
;
7601 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7602 reseat_1 (it
, pos1
, 0);
7605 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7606 compute_stop_pos (it
);
7607 /* We must advance forward, right? */
7608 if (it
->stop_charpos
<= it
->prev_stop
)
7610 charpos
= it
->stop_charpos
;
7612 while (charpos
<= where_we_are
);
7615 it
->current
= save_current
;
7616 it
->position
= save_position
;
7617 next_stop
= it
->stop_charpos
;
7618 it
->stop_charpos
= it
->prev_stop
;
7620 it
->stop_charpos
= next_stop
;
7623 /* Load IT with the next display element from current_buffer. Value
7624 is zero if end of buffer reached. IT->stop_charpos is the next
7625 position at which to stop and check for text properties or buffer
7629 next_element_from_buffer (struct it
*it
)
7633 xassert (IT_CHARPOS (*it
) >= BEGV
);
7634 xassert (NILP (it
->string
) && !it
->s
);
7635 xassert (!it
->bidi_p
7636 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7637 && it
->bidi_it
.string
.s
== NULL
));
7639 /* With bidi reordering, the character to display might not be the
7640 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7641 we were reseat()ed to a new buffer position, which is potentially
7642 a different paragraph. */
7643 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7645 get_visually_first_element (it
);
7646 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7649 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7651 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7653 int overlay_strings_follow_p
;
7655 /* End of the game, except when overlay strings follow that
7656 haven't been returned yet. */
7657 if (it
->overlay_strings_at_end_processed_p
)
7658 overlay_strings_follow_p
= 0;
7661 it
->overlay_strings_at_end_processed_p
= 1;
7662 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7665 if (overlay_strings_follow_p
)
7666 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7670 it
->position
= it
->current
.pos
;
7674 else if (!(!it
->bidi_p
7675 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7676 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7678 /* With bidi non-linear iteration, we could find ourselves
7679 far beyond the last computed stop_charpos, with several
7680 other stop positions in between that we missed. Scan
7681 them all now, in buffer's logical order, until we find
7682 and handle the last stop_charpos that precedes our
7683 current position. */
7684 handle_stop_backwards (it
, it
->stop_charpos
);
7685 return GET_NEXT_DISPLAY_ELEMENT (it
);
7691 /* Take note of the stop position we just moved across,
7692 for when we will move back across it. */
7693 it
->prev_stop
= it
->stop_charpos
;
7694 /* If we are at base paragraph embedding level, take
7695 note of the last stop position seen at this
7697 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7698 it
->base_level_stop
= it
->stop_charpos
;
7701 return GET_NEXT_DISPLAY_ELEMENT (it
);
7705 /* If we are before prev_stop, we may have overstepped on
7706 our way backwards a stop_pos, and if so, we need to
7707 handle that stop_pos. */
7708 && IT_CHARPOS (*it
) < it
->prev_stop
7709 /* We can sometimes back up for reasons that have nothing
7710 to do with bidi reordering. E.g., compositions. The
7711 code below is only needed when we are above the base
7712 embedding level, so test for that explicitly. */
7713 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7715 if (it
->base_level_stop
<= 0
7716 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7718 /* If we lost track of base_level_stop, we need to find
7719 prev_stop by looking backwards. This happens, e.g., when
7720 we were reseated to the previous screenful of text by
7722 it
->base_level_stop
= BEGV
;
7723 compute_stop_pos_backwards (it
);
7724 handle_stop_backwards (it
, it
->prev_stop
);
7727 handle_stop_backwards (it
, it
->base_level_stop
);
7728 return GET_NEXT_DISPLAY_ELEMENT (it
);
7732 /* No face changes, overlays etc. in sight, so just return a
7733 character from current_buffer. */
7737 /* Maybe run the redisplay end trigger hook. Performance note:
7738 This doesn't seem to cost measurable time. */
7739 if (it
->redisplay_end_trigger_charpos
7741 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7742 run_redisplay_end_trigger_hook (it
);
7744 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7745 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7747 && next_element_from_composition (it
))
7752 /* Get the next character, maybe multibyte. */
7753 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7754 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7755 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7757 it
->c
= *p
, it
->len
= 1;
7759 /* Record what we have and where it came from. */
7760 it
->what
= IT_CHARACTER
;
7761 it
->object
= it
->w
->buffer
;
7762 it
->position
= it
->current
.pos
;
7764 /* Normally we return the character found above, except when we
7765 really want to return an ellipsis for selective display. */
7770 /* A value of selective > 0 means hide lines indented more
7771 than that number of columns. */
7772 if (it
->selective
> 0
7773 && IT_CHARPOS (*it
) + 1 < ZV
7774 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7775 IT_BYTEPOS (*it
) + 1,
7778 success_p
= next_element_from_ellipsis (it
);
7779 it
->dpvec_char_len
= -1;
7782 else if (it
->c
== '\r' && it
->selective
== -1)
7784 /* A value of selective == -1 means that everything from the
7785 CR to the end of the line is invisible, with maybe an
7786 ellipsis displayed for it. */
7787 success_p
= next_element_from_ellipsis (it
);
7788 it
->dpvec_char_len
= -1;
7793 /* Value is zero if end of buffer reached. */
7794 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7799 /* Run the redisplay end trigger hook for IT. */
7802 run_redisplay_end_trigger_hook (struct it
*it
)
7804 Lisp_Object args
[3];
7806 /* IT->glyph_row should be non-null, i.e. we should be actually
7807 displaying something, or otherwise we should not run the hook. */
7808 xassert (it
->glyph_row
);
7810 /* Set up hook arguments. */
7811 args
[0] = Qredisplay_end_trigger_functions
;
7812 args
[1] = it
->window
;
7813 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7814 it
->redisplay_end_trigger_charpos
= 0;
7816 /* Since we are *trying* to run these functions, don't try to run
7817 them again, even if they get an error. */
7818 it
->w
->redisplay_end_trigger
= Qnil
;
7819 Frun_hook_with_args (3, args
);
7821 /* Notice if it changed the face of the character we are on. */
7822 handle_face_prop (it
);
7826 /* Deliver a composition display element. Unlike the other
7827 next_element_from_XXX, this function is not registered in the array
7828 get_next_element[]. It is called from next_element_from_buffer and
7829 next_element_from_string when necessary. */
7832 next_element_from_composition (struct it
*it
)
7834 it
->what
= IT_COMPOSITION
;
7835 it
->len
= it
->cmp_it
.nbytes
;
7836 if (STRINGP (it
->string
))
7840 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7841 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7844 it
->position
= it
->current
.string_pos
;
7845 it
->object
= it
->string
;
7846 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7847 IT_STRING_BYTEPOS (*it
), it
->string
);
7853 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7854 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7857 if (it
->bidi_it
.new_paragraph
)
7858 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7859 /* Resync the bidi iterator with IT's new position.
7860 FIXME: this doesn't support bidirectional text. */
7861 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7862 bidi_move_to_visually_next (&it
->bidi_it
);
7866 it
->position
= it
->current
.pos
;
7867 it
->object
= it
->w
->buffer
;
7868 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7869 IT_BYTEPOS (*it
), Qnil
);
7876 /***********************************************************************
7877 Moving an iterator without producing glyphs
7878 ***********************************************************************/
7880 /* Check if iterator is at a position corresponding to a valid buffer
7881 position after some move_it_ call. */
7883 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7884 ((it)->method == GET_FROM_STRING \
7885 ? IT_STRING_CHARPOS (*it) == 0 \
7889 /* Move iterator IT to a specified buffer or X position within one
7890 line on the display without producing glyphs.
7892 OP should be a bit mask including some or all of these bits:
7893 MOVE_TO_X: Stop upon reaching x-position TO_X.
7894 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7895 Regardless of OP's value, stop upon reaching the end of the display line.
7897 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7898 This means, in particular, that TO_X includes window's horizontal
7901 The return value has several possible values that
7902 say what condition caused the scan to stop:
7904 MOVE_POS_MATCH_OR_ZV
7905 - when TO_POS or ZV was reached.
7908 -when TO_X was reached before TO_POS or ZV were reached.
7911 - when we reached the end of the display area and the line must
7915 - when we reached the end of the display area and the line is
7919 - when we stopped at a line end, i.e. a newline or a CR and selective
7922 static enum move_it_result
7923 move_it_in_display_line_to (struct it
*it
,
7924 ptrdiff_t to_charpos
, int to_x
,
7925 enum move_operation_enum op
)
7927 enum move_it_result result
= MOVE_UNDEFINED
;
7928 struct glyph_row
*saved_glyph_row
;
7929 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
7930 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
7931 void *ppos_data
= NULL
;
7933 enum it_method prev_method
= it
->method
;
7934 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
7935 int saw_smaller_pos
= prev_pos
< to_charpos
;
7937 /* Don't produce glyphs in produce_glyphs. */
7938 saved_glyph_row
= it
->glyph_row
;
7939 it
->glyph_row
= NULL
;
7941 /* Use wrap_it to save a copy of IT wherever a word wrap could
7942 occur. Use atpos_it to save a copy of IT at the desired buffer
7943 position, if found, so that we can scan ahead and check if the
7944 word later overshoots the window edge. Use atx_it similarly, for
7950 /* Use ppos_it under bidi reordering to save a copy of IT for the
7951 position > CHARPOS that is the closest to CHARPOS. We restore
7952 that position in IT when we have scanned the entire display line
7953 without finding a match for CHARPOS and all the character
7954 positions are greater than CHARPOS. */
7957 SAVE_IT (ppos_it
, *it
, ppos_data
);
7958 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
7959 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
7960 SAVE_IT (ppos_it
, *it
, ppos_data
);
7963 #define BUFFER_POS_REACHED_P() \
7964 ((op & MOVE_TO_POS) != 0 \
7965 && BUFFERP (it->object) \
7966 && (IT_CHARPOS (*it) == to_charpos \
7968 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
7969 && IT_CHARPOS (*it) > to_charpos) \
7970 || (it->what == IT_COMPOSITION \
7971 && ((IT_CHARPOS (*it) > to_charpos \
7972 && to_charpos >= it->cmp_it.charpos) \
7973 || (IT_CHARPOS (*it) < to_charpos \
7974 && to_charpos <= it->cmp_it.charpos)))) \
7975 && (it->method == GET_FROM_BUFFER \
7976 || (it->method == GET_FROM_DISPLAY_VECTOR \
7977 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7979 /* If there's a line-/wrap-prefix, handle it. */
7980 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7981 && it
->current_y
< it
->last_visible_y
)
7982 handle_line_prefix (it
);
7984 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7985 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7989 int x
, i
, ascent
= 0, descent
= 0;
7991 /* Utility macro to reset an iterator with x, ascent, and descent. */
7992 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7993 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7994 (IT)->max_descent = descent)
7996 /* Stop if we move beyond TO_CHARPOS (after an image or a
7997 display string or stretch glyph). */
7998 if ((op
& MOVE_TO_POS
) != 0
7999 && BUFFERP (it
->object
)
8000 && it
->method
== GET_FROM_BUFFER
8002 /* When the iterator is at base embedding level, we
8003 are guaranteed that characters are delivered for
8004 display in strictly increasing order of their
8005 buffer positions. */
8006 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8007 && IT_CHARPOS (*it
) > to_charpos
)
8009 && (prev_method
== GET_FROM_IMAGE
8010 || prev_method
== GET_FROM_STRETCH
8011 || prev_method
== GET_FROM_STRING
)
8012 /* Passed TO_CHARPOS from left to right. */
8013 && ((prev_pos
< to_charpos
8014 && IT_CHARPOS (*it
) > to_charpos
)
8015 /* Passed TO_CHARPOS from right to left. */
8016 || (prev_pos
> to_charpos
8017 && IT_CHARPOS (*it
) < to_charpos
)))))
8019 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8021 result
= MOVE_POS_MATCH_OR_ZV
;
8024 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8025 /* If wrap_it is valid, the current position might be in a
8026 word that is wrapped. So, save the iterator in
8027 atpos_it and continue to see if wrapping happens. */
8028 SAVE_IT (atpos_it
, *it
, atpos_data
);
8031 /* Stop when ZV reached.
8032 We used to stop here when TO_CHARPOS reached as well, but that is
8033 too soon if this glyph does not fit on this line. So we handle it
8034 explicitly below. */
8035 if (!get_next_display_element (it
))
8037 result
= MOVE_POS_MATCH_OR_ZV
;
8041 if (it
->line_wrap
== TRUNCATE
)
8043 if (BUFFER_POS_REACHED_P ())
8045 result
= MOVE_POS_MATCH_OR_ZV
;
8051 if (it
->line_wrap
== WORD_WRAP
)
8053 if (IT_DISPLAYING_WHITESPACE (it
))
8057 /* We have reached a glyph that follows one or more
8058 whitespace characters. If the position is
8059 already found, we are done. */
8060 if (atpos_it
.sp
>= 0)
8062 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8063 result
= MOVE_POS_MATCH_OR_ZV
;
8068 RESTORE_IT (it
, &atx_it
, atx_data
);
8069 result
= MOVE_X_REACHED
;
8072 /* Otherwise, we can wrap here. */
8073 SAVE_IT (wrap_it
, *it
, wrap_data
);
8079 /* Remember the line height for the current line, in case
8080 the next element doesn't fit on the line. */
8081 ascent
= it
->max_ascent
;
8082 descent
= it
->max_descent
;
8084 /* The call to produce_glyphs will get the metrics of the
8085 display element IT is loaded with. Record the x-position
8086 before this display element, in case it doesn't fit on the
8090 PRODUCE_GLYPHS (it
);
8092 if (it
->area
!= TEXT_AREA
)
8094 prev_method
= it
->method
;
8095 if (it
->method
== GET_FROM_BUFFER
)
8096 prev_pos
= IT_CHARPOS (*it
);
8097 set_iterator_to_next (it
, 1);
8098 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8099 SET_TEXT_POS (this_line_min_pos
,
8100 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8102 && (op
& MOVE_TO_POS
)
8103 && IT_CHARPOS (*it
) > to_charpos
8104 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8105 SAVE_IT (ppos_it
, *it
, ppos_data
);
8109 /* The number of glyphs we get back in IT->nglyphs will normally
8110 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8111 character on a terminal frame, or (iii) a line end. For the
8112 second case, IT->nglyphs - 1 padding glyphs will be present.
8113 (On X frames, there is only one glyph produced for a
8114 composite character.)
8116 The behavior implemented below means, for continuation lines,
8117 that as many spaces of a TAB as fit on the current line are
8118 displayed there. For terminal frames, as many glyphs of a
8119 multi-glyph character are displayed in the current line, too.
8120 This is what the old redisplay code did, and we keep it that
8121 way. Under X, the whole shape of a complex character must
8122 fit on the line or it will be completely displayed in the
8125 Note that both for tabs and padding glyphs, all glyphs have
8129 /* More than one glyph or glyph doesn't fit on line. All
8130 glyphs have the same width. */
8131 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8133 int x_before_this_char
= x
;
8134 int hpos_before_this_char
= it
->hpos
;
8136 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8138 new_x
= x
+ single_glyph_width
;
8140 /* We want to leave anything reaching TO_X to the caller. */
8141 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8143 if (BUFFER_POS_REACHED_P ())
8145 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8146 goto buffer_pos_reached
;
8147 if (atpos_it
.sp
< 0)
8149 SAVE_IT (atpos_it
, *it
, atpos_data
);
8150 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8155 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8158 result
= MOVE_X_REACHED
;
8163 SAVE_IT (atx_it
, *it
, atx_data
);
8164 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8169 if (/* Lines are continued. */
8170 it
->line_wrap
!= TRUNCATE
8171 && (/* And glyph doesn't fit on the line. */
8172 new_x
> it
->last_visible_x
8173 /* Or it fits exactly and we're on a window
8175 || (new_x
== it
->last_visible_x
8176 && FRAME_WINDOW_P (it
->f
))))
8178 if (/* IT->hpos == 0 means the very first glyph
8179 doesn't fit on the line, e.g. a wide image. */
8181 || (new_x
== it
->last_visible_x
8182 && FRAME_WINDOW_P (it
->f
)))
8185 it
->current_x
= new_x
;
8187 /* The character's last glyph just barely fits
8189 if (i
== it
->nglyphs
- 1)
8191 /* If this is the destination position,
8192 return a position *before* it in this row,
8193 now that we know it fits in this row. */
8194 if (BUFFER_POS_REACHED_P ())
8196 if (it
->line_wrap
!= WORD_WRAP
8199 it
->hpos
= hpos_before_this_char
;
8200 it
->current_x
= x_before_this_char
;
8201 result
= MOVE_POS_MATCH_OR_ZV
;
8204 if (it
->line_wrap
== WORD_WRAP
8207 SAVE_IT (atpos_it
, *it
, atpos_data
);
8208 atpos_it
.current_x
= x_before_this_char
;
8209 atpos_it
.hpos
= hpos_before_this_char
;
8213 prev_method
= it
->method
;
8214 if (it
->method
== GET_FROM_BUFFER
)
8215 prev_pos
= IT_CHARPOS (*it
);
8216 set_iterator_to_next (it
, 1);
8217 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8218 SET_TEXT_POS (this_line_min_pos
,
8219 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8220 /* On graphical terminals, newlines may
8221 "overflow" into the fringe if
8222 overflow-newline-into-fringe is non-nil.
8223 On text-only terminals, newlines may
8224 overflow into the last glyph on the
8226 if (!FRAME_WINDOW_P (it
->f
)
8227 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8229 if (!get_next_display_element (it
))
8231 result
= MOVE_POS_MATCH_OR_ZV
;
8234 if (BUFFER_POS_REACHED_P ())
8236 if (ITERATOR_AT_END_OF_LINE_P (it
))
8237 result
= MOVE_POS_MATCH_OR_ZV
;
8239 result
= MOVE_LINE_CONTINUED
;
8242 if (ITERATOR_AT_END_OF_LINE_P (it
))
8244 result
= MOVE_NEWLINE_OR_CR
;
8251 IT_RESET_X_ASCENT_DESCENT (it
);
8253 if (wrap_it
.sp
>= 0)
8255 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8260 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8262 result
= MOVE_LINE_CONTINUED
;
8266 if (BUFFER_POS_REACHED_P ())
8268 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8269 goto buffer_pos_reached
;
8270 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8272 SAVE_IT (atpos_it
, *it
, atpos_data
);
8273 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8277 if (new_x
> it
->first_visible_x
)
8279 /* Glyph is visible. Increment number of glyphs that
8280 would be displayed. */
8285 if (result
!= MOVE_UNDEFINED
)
8288 else if (BUFFER_POS_REACHED_P ())
8291 IT_RESET_X_ASCENT_DESCENT (it
);
8292 result
= MOVE_POS_MATCH_OR_ZV
;
8295 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8297 /* Stop when TO_X specified and reached. This check is
8298 necessary here because of lines consisting of a line end,
8299 only. The line end will not produce any glyphs and we
8300 would never get MOVE_X_REACHED. */
8301 xassert (it
->nglyphs
== 0);
8302 result
= MOVE_X_REACHED
;
8306 /* Is this a line end? If yes, we're done. */
8307 if (ITERATOR_AT_END_OF_LINE_P (it
))
8309 /* If we are past TO_CHARPOS, but never saw any character
8310 positions smaller than TO_CHARPOS, return
8311 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8313 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8315 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8317 if (IT_CHARPOS (ppos_it
) < ZV
)
8319 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8320 result
= MOVE_POS_MATCH_OR_ZV
;
8323 goto buffer_pos_reached
;
8325 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8326 && IT_CHARPOS (*it
) > to_charpos
)
8327 goto buffer_pos_reached
;
8329 result
= MOVE_NEWLINE_OR_CR
;
8332 result
= MOVE_NEWLINE_OR_CR
;
8336 prev_method
= it
->method
;
8337 if (it
->method
== GET_FROM_BUFFER
)
8338 prev_pos
= IT_CHARPOS (*it
);
8339 /* The current display element has been consumed. Advance
8341 set_iterator_to_next (it
, 1);
8342 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8343 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8344 if (IT_CHARPOS (*it
) < to_charpos
)
8345 saw_smaller_pos
= 1;
8347 && (op
& MOVE_TO_POS
)
8348 && IT_CHARPOS (*it
) >= to_charpos
8349 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8350 SAVE_IT (ppos_it
, *it
, ppos_data
);
8352 /* Stop if lines are truncated and IT's current x-position is
8353 past the right edge of the window now. */
8354 if (it
->line_wrap
== TRUNCATE
8355 && it
->current_x
>= it
->last_visible_x
)
8357 if (!FRAME_WINDOW_P (it
->f
)
8358 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8362 if ((at_eob_p
= !get_next_display_element (it
))
8363 || BUFFER_POS_REACHED_P ()
8364 /* If we are past TO_CHARPOS, but never saw any
8365 character positions smaller than TO_CHARPOS,
8366 return MOVE_POS_MATCH_OR_ZV, like the
8367 unidirectional display did. */
8368 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8370 && IT_CHARPOS (*it
) > to_charpos
))
8373 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8374 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8375 result
= MOVE_POS_MATCH_OR_ZV
;
8378 if (ITERATOR_AT_END_OF_LINE_P (it
))
8380 result
= MOVE_NEWLINE_OR_CR
;
8384 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8386 && IT_CHARPOS (*it
) > to_charpos
)
8388 if (IT_CHARPOS (ppos_it
) < ZV
)
8389 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8390 result
= MOVE_POS_MATCH_OR_ZV
;
8393 result
= MOVE_LINE_TRUNCATED
;
8396 #undef IT_RESET_X_ASCENT_DESCENT
8399 #undef BUFFER_POS_REACHED_P
8401 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8402 restore the saved iterator. */
8403 if (atpos_it
.sp
>= 0)
8404 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8405 else if (atx_it
.sp
>= 0)
8406 RESTORE_IT (it
, &atx_it
, atx_data
);
8411 bidi_unshelve_cache (atpos_data
, 1);
8413 bidi_unshelve_cache (atx_data
, 1);
8415 bidi_unshelve_cache (wrap_data
, 1);
8417 bidi_unshelve_cache (ppos_data
, 1);
8419 /* Restore the iterator settings altered at the beginning of this
8421 it
->glyph_row
= saved_glyph_row
;
8425 /* For external use. */
8427 move_it_in_display_line (struct it
*it
,
8428 ptrdiff_t to_charpos
, int to_x
,
8429 enum move_operation_enum op
)
8431 if (it
->line_wrap
== WORD_WRAP
8432 && (op
& MOVE_TO_X
))
8435 void *save_data
= NULL
;
8438 SAVE_IT (save_it
, *it
, save_data
);
8439 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8440 /* When word-wrap is on, TO_X may lie past the end
8441 of a wrapped line. Then it->current is the
8442 character on the next line, so backtrack to the
8443 space before the wrap point. */
8444 if (skip
== MOVE_LINE_CONTINUED
)
8446 int prev_x
= max (it
->current_x
- 1, 0);
8447 RESTORE_IT (it
, &save_it
, save_data
);
8448 move_it_in_display_line_to
8449 (it
, -1, prev_x
, MOVE_TO_X
);
8452 bidi_unshelve_cache (save_data
, 1);
8455 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8459 /* Move IT forward until it satisfies one or more of the criteria in
8460 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8462 OP is a bit-mask that specifies where to stop, and in particular,
8463 which of those four position arguments makes a difference. See the
8464 description of enum move_operation_enum.
8466 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8467 screen line, this function will set IT to the next position that is
8468 displayed to the right of TO_CHARPOS on the screen. */
8471 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8473 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8474 int line_height
, line_start_x
= 0, reached
= 0;
8475 void *backup_data
= NULL
;
8479 if (op
& MOVE_TO_VPOS
)
8481 /* If no TO_CHARPOS and no TO_X specified, stop at the
8482 start of the line TO_VPOS. */
8483 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8485 if (it
->vpos
== to_vpos
)
8491 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8495 /* TO_VPOS >= 0 means stop at TO_X in the line at
8496 TO_VPOS, or at TO_POS, whichever comes first. */
8497 if (it
->vpos
== to_vpos
)
8503 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8505 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8510 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8512 /* We have reached TO_X but not in the line we want. */
8513 skip
= move_it_in_display_line_to (it
, to_charpos
,
8515 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8523 else if (op
& MOVE_TO_Y
)
8525 struct it it_backup
;
8527 if (it
->line_wrap
== WORD_WRAP
)
8528 SAVE_IT (it_backup
, *it
, backup_data
);
8530 /* TO_Y specified means stop at TO_X in the line containing
8531 TO_Y---or at TO_CHARPOS if this is reached first. The
8532 problem is that we can't really tell whether the line
8533 contains TO_Y before we have completely scanned it, and
8534 this may skip past TO_X. What we do is to first scan to
8537 If TO_X is not specified, use a TO_X of zero. The reason
8538 is to make the outcome of this function more predictable.
8539 If we didn't use TO_X == 0, we would stop at the end of
8540 the line which is probably not what a caller would expect
8542 skip
= move_it_in_display_line_to
8543 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8544 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8546 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8547 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8549 else if (skip
== MOVE_X_REACHED
)
8551 /* If TO_X was reached, we want to know whether TO_Y is
8552 in the line. We know this is the case if the already
8553 scanned glyphs make the line tall enough. Otherwise,
8554 we must check by scanning the rest of the line. */
8555 line_height
= it
->max_ascent
+ it
->max_descent
;
8556 if (to_y
>= it
->current_y
8557 && to_y
< it
->current_y
+ line_height
)
8562 SAVE_IT (it_backup
, *it
, backup_data
);
8563 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8564 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8566 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8567 line_height
= it
->max_ascent
+ it
->max_descent
;
8568 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8570 if (to_y
>= it
->current_y
8571 && to_y
< it
->current_y
+ line_height
)
8573 /* If TO_Y is in this line and TO_X was reached
8574 above, we scanned too far. We have to restore
8575 IT's settings to the ones before skipping. */
8576 RESTORE_IT (it
, &it_backup
, backup_data
);
8582 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8588 /* Check whether TO_Y is in this line. */
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 /* When word-wrap is on, TO_X may lie past the end
8596 of a wrapped line. Then it->current is the
8597 character on the next line, so backtrack to the
8598 space before the wrap point. */
8599 if (skip
== MOVE_LINE_CONTINUED
8600 && it
->line_wrap
== WORD_WRAP
)
8602 int prev_x
= max (it
->current_x
- 1, 0);
8603 RESTORE_IT (it
, &it_backup
, backup_data
);
8604 skip
= move_it_in_display_line_to
8605 (it
, -1, prev_x
, MOVE_TO_X
);
8614 else if (BUFFERP (it
->object
)
8615 && (it
->method
== GET_FROM_BUFFER
8616 || it
->method
== GET_FROM_STRETCH
)
8617 && IT_CHARPOS (*it
) >= to_charpos
8618 /* Under bidi iteration, a call to set_iterator_to_next
8619 can scan far beyond to_charpos if the initial
8620 portion of the next line needs to be reordered. In
8621 that case, give move_it_in_display_line_to another
8624 && it
->bidi_it
.scan_dir
== -1))
8625 skip
= MOVE_POS_MATCH_OR_ZV
;
8627 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8631 case MOVE_POS_MATCH_OR_ZV
:
8635 case MOVE_NEWLINE_OR_CR
:
8636 set_iterator_to_next (it
, 1);
8637 it
->continuation_lines_width
= 0;
8640 case MOVE_LINE_TRUNCATED
:
8641 it
->continuation_lines_width
= 0;
8642 reseat_at_next_visible_line_start (it
, 0);
8643 if ((op
& MOVE_TO_POS
) != 0
8644 && IT_CHARPOS (*it
) > to_charpos
)
8651 case MOVE_LINE_CONTINUED
:
8652 /* For continued lines ending in a tab, some of the glyphs
8653 associated with the tab are displayed on the current
8654 line. Since it->current_x does not include these glyphs,
8655 we use it->last_visible_x instead. */
8658 it
->continuation_lines_width
+= it
->last_visible_x
;
8659 /* When moving by vpos, ensure that the iterator really
8660 advances to the next line (bug#847, bug#969). Fixme:
8661 do we need to do this in other circumstances? */
8662 if (it
->current_x
!= it
->last_visible_x
8663 && (op
& MOVE_TO_VPOS
)
8664 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8666 line_start_x
= it
->current_x
+ it
->pixel_width
8667 - it
->last_visible_x
;
8668 set_iterator_to_next (it
, 0);
8672 it
->continuation_lines_width
+= it
->current_x
;
8679 /* Reset/increment for the next run. */
8680 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8681 it
->current_x
= line_start_x
;
8684 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8686 last_height
= it
->max_ascent
+ it
->max_descent
;
8687 last_max_ascent
= it
->max_ascent
;
8688 it
->max_ascent
= it
->max_descent
= 0;
8693 /* On text terminals, we may stop at the end of a line in the middle
8694 of a multi-character glyph. If the glyph itself is continued,
8695 i.e. it is actually displayed on the next line, don't treat this
8696 stopping point as valid; move to the next line instead (unless
8697 that brings us offscreen). */
8698 if (!FRAME_WINDOW_P (it
->f
)
8700 && IT_CHARPOS (*it
) == to_charpos
8701 && it
->what
== IT_CHARACTER
8703 && it
->line_wrap
== WINDOW_WRAP
8704 && it
->current_x
== it
->last_visible_x
- 1
8707 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8709 it
->continuation_lines_width
+= it
->current_x
;
8710 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8711 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8713 last_height
= it
->max_ascent
+ it
->max_descent
;
8714 last_max_ascent
= it
->max_ascent
;
8718 bidi_unshelve_cache (backup_data
, 1);
8720 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8724 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8726 If DY > 0, move IT backward at least that many pixels. DY = 0
8727 means move IT backward to the preceding line start or BEGV. This
8728 function may move over more than DY pixels if IT->current_y - DY
8729 ends up in the middle of a line; in this case IT->current_y will be
8730 set to the top of the line moved to. */
8733 move_it_vertically_backward (struct it
*it
, int dy
)
8737 void *it2data
= NULL
, *it3data
= NULL
;
8738 ptrdiff_t start_pos
;
8743 start_pos
= IT_CHARPOS (*it
);
8745 /* Estimate how many newlines we must move back. */
8746 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8748 /* Set the iterator's position that many lines back. */
8749 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8750 back_to_previous_visible_line_start (it
);
8752 /* Reseat the iterator here. When moving backward, we don't want
8753 reseat to skip forward over invisible text, set up the iterator
8754 to deliver from overlay strings at the new position etc. So,
8755 use reseat_1 here. */
8756 reseat_1 (it
, it
->current
.pos
, 1);
8758 /* We are now surely at a line start. */
8759 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8760 reordering is in effect. */
8761 it
->continuation_lines_width
= 0;
8763 /* Move forward and see what y-distance we moved. First move to the
8764 start of the next line so that we get its height. We need this
8765 height to be able to tell whether we reached the specified
8767 SAVE_IT (it2
, *it
, it2data
);
8768 it2
.max_ascent
= it2
.max_descent
= 0;
8771 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8772 MOVE_TO_POS
| MOVE_TO_VPOS
);
8774 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8775 /* If we are in a display string which starts at START_POS,
8776 and that display string includes a newline, and we are
8777 right after that newline (i.e. at the beginning of a
8778 display line), exit the loop, because otherwise we will
8779 infloop, since move_it_to will see that it is already at
8780 START_POS and will not move. */
8781 || (it2
.method
== GET_FROM_STRING
8782 && IT_CHARPOS (it2
) == start_pos
8783 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8784 xassert (IT_CHARPOS (*it
) >= BEGV
);
8785 SAVE_IT (it3
, it2
, it3data
);
8787 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8788 xassert (IT_CHARPOS (*it
) >= BEGV
);
8789 /* H is the actual vertical distance from the position in *IT
8790 and the starting position. */
8791 h
= it2
.current_y
- it
->current_y
;
8792 /* NLINES is the distance in number of lines. */
8793 nlines
= it2
.vpos
- it
->vpos
;
8795 /* Correct IT's y and vpos position
8796 so that they are relative to the starting point. */
8802 /* DY == 0 means move to the start of the screen line. The
8803 value of nlines is > 0 if continuation lines were involved,
8804 or if the original IT position was at start of a line. */
8805 RESTORE_IT (it
, it
, it2data
);
8807 move_it_by_lines (it
, nlines
);
8808 /* The above code moves us to some position NLINES down,
8809 usually to its first glyph (leftmost in an L2R line), but
8810 that's not necessarily the start of the line, under bidi
8811 reordering. We want to get to the character position
8812 that is immediately after the newline of the previous
8815 && !it
->continuation_lines_width
8816 && !STRINGP (it
->string
)
8817 && IT_CHARPOS (*it
) > BEGV
8818 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8821 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8823 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8825 bidi_unshelve_cache (it3data
, 1);
8829 /* The y-position we try to reach, relative to *IT.
8830 Note that H has been subtracted in front of the if-statement. */
8831 int target_y
= it
->current_y
+ h
- dy
;
8832 int y0
= it3
.current_y
;
8836 RESTORE_IT (&it3
, &it3
, it3data
);
8837 y1
= line_bottom_y (&it3
);
8838 line_height
= y1
- y0
;
8839 RESTORE_IT (it
, it
, it2data
);
8840 /* If we did not reach target_y, try to move further backward if
8841 we can. If we moved too far backward, try to move forward. */
8842 if (target_y
< it
->current_y
8843 /* This is heuristic. In a window that's 3 lines high, with
8844 a line height of 13 pixels each, recentering with point
8845 on the bottom line will try to move -39/2 = 19 pixels
8846 backward. Try to avoid moving into the first line. */
8847 && (it
->current_y
- target_y
8848 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8849 && IT_CHARPOS (*it
) > BEGV
)
8851 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8852 target_y
- it
->current_y
));
8853 dy
= it
->current_y
- target_y
;
8854 goto move_further_back
;
8856 else if (target_y
>= it
->current_y
+ line_height
8857 && IT_CHARPOS (*it
) < ZV
)
8859 /* Should move forward by at least one line, maybe more.
8861 Note: Calling move_it_by_lines can be expensive on
8862 terminal frames, where compute_motion is used (via
8863 vmotion) to do the job, when there are very long lines
8864 and truncate-lines is nil. That's the reason for
8865 treating terminal frames specially here. */
8867 if (!FRAME_WINDOW_P (it
->f
))
8868 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8873 move_it_by_lines (it
, 1);
8875 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8882 /* Move IT by a specified amount of pixel lines DY. DY negative means
8883 move backwards. DY = 0 means move to start of screen line. At the
8884 end, IT will be on the start of a screen line. */
8887 move_it_vertically (struct it
*it
, int dy
)
8890 move_it_vertically_backward (it
, -dy
);
8893 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8894 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8895 MOVE_TO_POS
| MOVE_TO_Y
);
8896 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8898 /* If buffer ends in ZV without a newline, move to the start of
8899 the line to satisfy the post-condition. */
8900 if (IT_CHARPOS (*it
) == ZV
8902 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8903 move_it_by_lines (it
, 0);
8908 /* Move iterator IT past the end of the text line it is in. */
8911 move_it_past_eol (struct it
*it
)
8913 enum move_it_result rc
;
8915 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8916 if (rc
== MOVE_NEWLINE_OR_CR
)
8917 set_iterator_to_next (it
, 0);
8921 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8922 negative means move up. DVPOS == 0 means move to the start of the
8925 Optimization idea: If we would know that IT->f doesn't use
8926 a face with proportional font, we could be faster for
8927 truncate-lines nil. */
8930 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
8933 /* The commented-out optimization uses vmotion on terminals. This
8934 gives bad results, because elements like it->what, on which
8935 callers such as pos_visible_p rely, aren't updated. */
8936 /* struct position pos;
8937 if (!FRAME_WINDOW_P (it->f))
8939 struct text_pos textpos;
8941 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8942 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8943 reseat (it, textpos, 1);
8944 it->vpos += pos.vpos;
8945 it->current_y += pos.vpos;
8951 /* DVPOS == 0 means move to the start of the screen line. */
8952 move_it_vertically_backward (it
, 0);
8953 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8954 /* Let next call to line_bottom_y calculate real line height */
8959 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8960 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8961 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8966 void *it2data
= NULL
;
8967 ptrdiff_t start_charpos
, i
;
8969 /* Start at the beginning of the screen line containing IT's
8970 position. This may actually move vertically backwards,
8971 in case of overlays, so adjust dvpos accordingly. */
8973 move_it_vertically_backward (it
, 0);
8976 /* Go back -DVPOS visible lines and reseat the iterator there. */
8977 start_charpos
= IT_CHARPOS (*it
);
8978 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8979 back_to_previous_visible_line_start (it
);
8980 reseat (it
, it
->current
.pos
, 1);
8982 /* Move further back if we end up in a string or an image. */
8983 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8985 /* First try to move to start of display line. */
8987 move_it_vertically_backward (it
, 0);
8989 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8991 /* If start of line is still in string or image,
8992 move further back. */
8993 back_to_previous_visible_line_start (it
);
8994 reseat (it
, it
->current
.pos
, 1);
8998 it
->current_x
= it
->hpos
= 0;
9000 /* Above call may have moved too far if continuation lines
9001 are involved. Scan forward and see if it did. */
9002 SAVE_IT (it2
, *it
, it2data
);
9003 it2
.vpos
= it2
.current_y
= 0;
9004 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9005 it
->vpos
-= it2
.vpos
;
9006 it
->current_y
-= it2
.current_y
;
9007 it
->current_x
= it
->hpos
= 0;
9009 /* If we moved too far back, move IT some lines forward. */
9010 if (it2
.vpos
> -dvpos
)
9012 int delta
= it2
.vpos
+ dvpos
;
9014 RESTORE_IT (&it2
, &it2
, it2data
);
9015 SAVE_IT (it2
, *it
, it2data
);
9016 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9017 /* Move back again if we got too far ahead. */
9018 if (IT_CHARPOS (*it
) >= start_charpos
)
9019 RESTORE_IT (it
, &it2
, it2data
);
9021 bidi_unshelve_cache (it2data
, 1);
9024 RESTORE_IT (it
, it
, it2data
);
9028 /* Return 1 if IT points into the middle of a display vector. */
9031 in_display_vector_p (struct it
*it
)
9033 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9034 && it
->current
.dpvec_index
> 0
9035 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9039 /***********************************************************************
9041 ***********************************************************************/
9044 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9048 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9050 Lisp_Object args
[3];
9051 Lisp_Object msg
, fmt
;
9054 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9057 /* Do nothing if called asynchronously. Inserting text into
9058 a buffer may call after-change-functions and alike and
9059 that would means running Lisp asynchronously. */
9060 if (handling_signal
)
9064 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9066 args
[0] = fmt
= build_string (format
);
9069 msg
= Fformat (3, args
);
9071 len
= SBYTES (msg
) + 1;
9072 SAFE_ALLOCA (buffer
, char *, len
);
9073 memcpy (buffer
, SDATA (msg
), len
);
9075 message_dolog (buffer
, len
- 1, 1, 0);
9082 /* Output a newline in the *Messages* buffer if "needs" one. */
9085 message_log_maybe_newline (void)
9087 if (message_log_need_newline
)
9088 message_dolog ("", 0, 1, 0);
9092 /* Add a string M of length NBYTES to the message log, optionally
9093 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9094 nonzero, means interpret the contents of M as multibyte. This
9095 function calls low-level routines in order to bypass text property
9096 hooks, etc. which might not be safe to run.
9098 This may GC (insert may run before/after change hooks),
9099 so the buffer M must NOT point to a Lisp string. */
9102 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9104 const unsigned char *msg
= (const unsigned char *) m
;
9106 if (!NILP (Vmemory_full
))
9109 if (!NILP (Vmessage_log_max
))
9111 struct buffer
*oldbuf
;
9112 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9113 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9114 ptrdiff_t point_at_end
= 0;
9115 ptrdiff_t zv_at_end
= 0;
9116 Lisp_Object old_deactivate_mark
, tem
;
9117 struct gcpro gcpro1
;
9119 old_deactivate_mark
= Vdeactivate_mark
;
9120 oldbuf
= current_buffer
;
9121 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9122 BVAR (current_buffer
, undo_list
) = Qt
;
9124 oldpoint
= message_dolog_marker1
;
9125 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9126 oldbegv
= message_dolog_marker2
;
9127 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9128 oldzv
= message_dolog_marker3
;
9129 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9130 GCPRO1 (old_deactivate_mark
);
9138 BEGV_BYTE
= BEG_BYTE
;
9141 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9143 /* Insert the string--maybe converting multibyte to single byte
9144 or vice versa, so that all the text fits the buffer. */
9146 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9152 /* Convert a multibyte string to single-byte
9153 for the *Message* buffer. */
9154 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9156 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9157 work
[0] = (ASCII_CHAR_P (c
)
9159 : multibyte_char_to_unibyte (c
));
9160 insert_1_both (work
, 1, 1, 1, 0, 0);
9163 else if (! multibyte
9164 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9168 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9169 /* Convert a single-byte string to multibyte
9170 for the *Message* buffer. */
9171 for (i
= 0; i
< nbytes
; i
++)
9174 MAKE_CHAR_MULTIBYTE (c
);
9175 char_bytes
= CHAR_STRING (c
, str
);
9176 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9180 insert_1 (m
, nbytes
, 1, 0, 0);
9184 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9186 insert_1 ("\n", 1, 1, 0, 0);
9188 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9190 this_bol_byte
= PT_BYTE
;
9192 /* See if this line duplicates the previous one.
9193 If so, combine duplicates. */
9196 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9198 prev_bol_byte
= PT_BYTE
;
9200 dups
= message_log_check_duplicate (prev_bol_byte
,
9204 del_range_both (prev_bol
, prev_bol_byte
,
9205 this_bol
, this_bol_byte
, 0);
9208 char dupstr
[sizeof " [ times]"
9209 + INT_STRLEN_BOUND (printmax_t
)];
9212 /* If you change this format, don't forget to also
9213 change message_log_check_duplicate. */
9214 sprintf (dupstr
, " [%"pMd
" times]", dups
);
9215 duplen
= strlen (dupstr
);
9216 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9217 insert_1 (dupstr
, duplen
, 1, 0, 1);
9222 /* If we have more than the desired maximum number of lines
9223 in the *Messages* buffer now, delete the oldest ones.
9224 This is safe because we don't have undo in this buffer. */
9226 if (NATNUMP (Vmessage_log_max
))
9228 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9229 -XFASTINT (Vmessage_log_max
) - 1, 0);
9230 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9233 BEGV
= XMARKER (oldbegv
)->charpos
;
9234 BEGV_BYTE
= marker_byte_position (oldbegv
);
9243 ZV
= XMARKER (oldzv
)->charpos
;
9244 ZV_BYTE
= marker_byte_position (oldzv
);
9248 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9250 /* We can't do Fgoto_char (oldpoint) because it will run some
9252 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9253 XMARKER (oldpoint
)->bytepos
);
9256 unchain_marker (XMARKER (oldpoint
));
9257 unchain_marker (XMARKER (oldbegv
));
9258 unchain_marker (XMARKER (oldzv
));
9260 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9261 set_buffer_internal (oldbuf
);
9263 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9264 message_log_need_newline
= !nlflag
;
9265 Vdeactivate_mark
= old_deactivate_mark
;
9270 /* We are at the end of the buffer after just having inserted a newline.
9271 (Note: We depend on the fact we won't be crossing the gap.)
9272 Check to see if the most recent message looks a lot like the previous one.
9273 Return 0 if different, 1 if the new one should just replace it, or a
9274 value N > 1 if we should also append " [N times]". */
9277 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9280 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9282 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9283 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9285 for (i
= 0; i
< len
; i
++)
9287 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9295 if (*p1
++ == ' ' && *p1
++ == '[')
9298 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9299 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9306 /* Display an echo area message M with a specified length of NBYTES
9307 bytes. The string may include null characters. If M is 0, clear
9308 out any existing message, and let the mini-buffer text show
9311 This may GC, so the buffer M must NOT point to a Lisp string. */
9314 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9316 /* First flush out any partial line written with print. */
9317 message_log_maybe_newline ();
9319 message_dolog (m
, nbytes
, 1, multibyte
);
9320 message2_nolog (m
, nbytes
, multibyte
);
9324 /* The non-logging counterpart of message2. */
9327 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9329 struct frame
*sf
= SELECTED_FRAME ();
9330 message_enable_multibyte
= multibyte
;
9332 if (FRAME_INITIAL_P (sf
))
9334 if (noninteractive_need_newline
)
9335 putc ('\n', stderr
);
9336 noninteractive_need_newline
= 0;
9338 fwrite (m
, nbytes
, 1, stderr
);
9339 if (cursor_in_echo_area
== 0)
9340 fprintf (stderr
, "\n");
9343 /* A null message buffer means that the frame hasn't really been
9344 initialized yet. Error messages get reported properly by
9345 cmd_error, so this must be just an informative message; toss it. */
9346 else if (INTERACTIVE
9347 && sf
->glyphs_initialized_p
9348 && FRAME_MESSAGE_BUF (sf
))
9350 Lisp_Object mini_window
;
9353 /* Get the frame containing the mini-buffer
9354 that the selected frame is using. */
9355 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9356 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9358 FRAME_SAMPLE_VISIBILITY (f
);
9359 if (FRAME_VISIBLE_P (sf
)
9360 && ! FRAME_VISIBLE_P (f
))
9361 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9365 set_message (m
, Qnil
, nbytes
, multibyte
);
9366 if (minibuffer_auto_raise
)
9367 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9370 clear_message (1, 1);
9372 do_pending_window_change (0);
9373 echo_area_display (1);
9374 do_pending_window_change (0);
9375 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9376 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9381 /* Display an echo area message M with a specified length of NBYTES
9382 bytes. The string may include null characters. If M is not a
9383 string, clear out any existing message, and let the mini-buffer
9386 This function cancels echoing. */
9389 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9391 struct gcpro gcpro1
;
9394 clear_message (1,1);
9397 /* First flush out any partial line written with print. */
9398 message_log_maybe_newline ();
9404 SAFE_ALLOCA (buffer
, char *, nbytes
);
9405 memcpy (buffer
, SDATA (m
), nbytes
);
9406 message_dolog (buffer
, nbytes
, 1, multibyte
);
9409 message3_nolog (m
, nbytes
, multibyte
);
9415 /* The non-logging version of message3.
9416 This does not cancel echoing, because it is used for echoing.
9417 Perhaps we need to make a separate function for echoing
9418 and make this cancel echoing. */
9421 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9423 struct frame
*sf
= SELECTED_FRAME ();
9424 message_enable_multibyte
= multibyte
;
9426 if (FRAME_INITIAL_P (sf
))
9428 if (noninteractive_need_newline
)
9429 putc ('\n', stderr
);
9430 noninteractive_need_newline
= 0;
9432 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9433 if (cursor_in_echo_area
== 0)
9434 fprintf (stderr
, "\n");
9437 /* A null message buffer means that the frame hasn't really been
9438 initialized yet. Error messages get reported properly by
9439 cmd_error, so this must be just an informative message; toss it. */
9440 else if (INTERACTIVE
9441 && sf
->glyphs_initialized_p
9442 && FRAME_MESSAGE_BUF (sf
))
9444 Lisp_Object mini_window
;
9448 /* Get the frame containing the mini-buffer
9449 that the selected frame is using. */
9450 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9451 frame
= XWINDOW (mini_window
)->frame
;
9454 FRAME_SAMPLE_VISIBILITY (f
);
9455 if (FRAME_VISIBLE_P (sf
)
9456 && !FRAME_VISIBLE_P (f
))
9457 Fmake_frame_visible (frame
);
9459 if (STRINGP (m
) && SCHARS (m
) > 0)
9461 set_message (NULL
, m
, nbytes
, multibyte
);
9462 if (minibuffer_auto_raise
)
9463 Fraise_frame (frame
);
9464 /* Assume we are not echoing.
9465 (If we are, echo_now will override this.) */
9466 echo_message_buffer
= Qnil
;
9469 clear_message (1, 1);
9471 do_pending_window_change (0);
9472 echo_area_display (1);
9473 do_pending_window_change (0);
9474 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9475 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9480 /* Display a null-terminated echo area message M. If M is 0, clear
9481 out any existing message, and let the mini-buffer text show through.
9483 The buffer M must continue to exist until after the echo area gets
9484 cleared or some other message gets displayed there. Do not pass
9485 text that is stored in a Lisp string. Do not pass text in a buffer
9486 that was alloca'd. */
9489 message1 (const char *m
)
9491 message2 (m
, (m
? strlen (m
) : 0), 0);
9495 /* The non-logging counterpart of message1. */
9498 message1_nolog (const char *m
)
9500 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9503 /* Display a message M which contains a single %s
9504 which gets replaced with STRING. */
9507 message_with_string (const char *m
, Lisp_Object string
, int log
)
9509 CHECK_STRING (string
);
9515 if (noninteractive_need_newline
)
9516 putc ('\n', stderr
);
9517 noninteractive_need_newline
= 0;
9518 fprintf (stderr
, m
, SDATA (string
));
9519 if (!cursor_in_echo_area
)
9520 fprintf (stderr
, "\n");
9524 else if (INTERACTIVE
)
9526 /* The frame whose minibuffer we're going to display the message on.
9527 It may be larger than the selected frame, so we need
9528 to use its buffer, not the selected frame's buffer. */
9529 Lisp_Object mini_window
;
9530 struct frame
*f
, *sf
= SELECTED_FRAME ();
9532 /* Get the frame containing the minibuffer
9533 that the selected frame is using. */
9534 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9535 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9537 /* A null message buffer means that the frame hasn't really been
9538 initialized yet. Error messages get reported properly by
9539 cmd_error, so this must be just an informative message; toss it. */
9540 if (FRAME_MESSAGE_BUF (f
))
9542 Lisp_Object args
[2], msg
;
9543 struct gcpro gcpro1
, gcpro2
;
9545 args
[0] = build_string (m
);
9546 args
[1] = msg
= string
;
9547 GCPRO2 (args
[0], msg
);
9550 msg
= Fformat (2, args
);
9553 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9555 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9559 /* Print should start at the beginning of the message
9560 buffer next time. */
9561 message_buf_print
= 0;
9567 /* Dump an informative message to the minibuf. If M is 0, clear out
9568 any existing message, and let the mini-buffer text show through. */
9571 vmessage (const char *m
, va_list ap
)
9577 if (noninteractive_need_newline
)
9578 putc ('\n', stderr
);
9579 noninteractive_need_newline
= 0;
9580 vfprintf (stderr
, m
, ap
);
9581 if (cursor_in_echo_area
== 0)
9582 fprintf (stderr
, "\n");
9586 else if (INTERACTIVE
)
9588 /* The frame whose mini-buffer we're going to display the message
9589 on. It may be larger than the selected frame, so we need to
9590 use its buffer, not the selected frame's buffer. */
9591 Lisp_Object mini_window
;
9592 struct frame
*f
, *sf
= SELECTED_FRAME ();
9594 /* Get the frame containing the mini-buffer
9595 that the selected frame is using. */
9596 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9597 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9599 /* A null message buffer means that the frame hasn't really been
9600 initialized yet. Error messages get reported properly by
9601 cmd_error, so this must be just an informative message; toss
9603 if (FRAME_MESSAGE_BUF (f
))
9609 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9610 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9612 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9617 /* Print should start at the beginning of the message
9618 buffer next time. */
9619 message_buf_print
= 0;
9625 message (const char *m
, ...)
9635 /* The non-logging version of message. */
9638 message_nolog (const char *m
, ...)
9640 Lisp_Object old_log_max
;
9643 old_log_max
= Vmessage_log_max
;
9644 Vmessage_log_max
= Qnil
;
9646 Vmessage_log_max
= old_log_max
;
9652 /* Display the current message in the current mini-buffer. This is
9653 only called from error handlers in process.c, and is not time
9657 update_echo_area (void)
9659 if (!NILP (echo_area_buffer
[0]))
9662 string
= Fcurrent_message ();
9663 message3 (string
, SBYTES (string
),
9664 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9669 /* Make sure echo area buffers in `echo_buffers' are live.
9670 If they aren't, make new ones. */
9673 ensure_echo_area_buffers (void)
9677 for (i
= 0; i
< 2; ++i
)
9678 if (!BUFFERP (echo_buffer
[i
])
9679 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9682 Lisp_Object old_buffer
;
9685 old_buffer
= echo_buffer
[i
];
9686 sprintf (name
, " *Echo Area %d*", i
);
9687 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9688 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9689 /* to force word wrap in echo area -
9690 it was decided to postpone this*/
9691 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9693 for (j
= 0; j
< 2; ++j
)
9694 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9695 echo_area_buffer
[j
] = echo_buffer
[i
];
9700 /* Call FN with args A1..A4 with either the current or last displayed
9701 echo_area_buffer as current buffer.
9703 WHICH zero means use the current message buffer
9704 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9705 from echo_buffer[] and clear it.
9707 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9708 suitable buffer from echo_buffer[] and clear it.
9710 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9711 that the current message becomes the last displayed one, make
9712 choose a suitable buffer for echo_area_buffer[0], and clear it.
9714 Value is what FN returns. */
9717 with_echo_area_buffer (struct window
*w
, int which
,
9718 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9719 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9722 int this_one
, the_other
, clear_buffer_p
, rc
;
9723 ptrdiff_t count
= SPECPDL_INDEX ();
9725 /* If buffers aren't live, make new ones. */
9726 ensure_echo_area_buffers ();
9731 this_one
= 0, the_other
= 1;
9733 this_one
= 1, the_other
= 0;
9736 this_one
= 0, the_other
= 1;
9739 /* We need a fresh one in case the current echo buffer equals
9740 the one containing the last displayed echo area message. */
9741 if (!NILP (echo_area_buffer
[this_one
])
9742 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9743 echo_area_buffer
[this_one
] = Qnil
;
9746 /* Choose a suitable buffer from echo_buffer[] is we don't
9748 if (NILP (echo_area_buffer
[this_one
]))
9750 echo_area_buffer
[this_one
]
9751 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9752 ? echo_buffer
[the_other
]
9753 : echo_buffer
[this_one
]);
9757 buffer
= echo_area_buffer
[this_one
];
9759 /* Don't get confused by reusing the buffer used for echoing
9760 for a different purpose. */
9761 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9764 record_unwind_protect (unwind_with_echo_area_buffer
,
9765 with_echo_area_buffer_unwind_data (w
));
9767 /* Make the echo area buffer current. Note that for display
9768 purposes, it is not necessary that the displayed window's buffer
9769 == current_buffer, except for text property lookup. So, let's
9770 only set that buffer temporarily here without doing a full
9771 Fset_window_buffer. We must also change w->pointm, though,
9772 because otherwise an assertions in unshow_buffer fails, and Emacs
9774 set_buffer_internal_1 (XBUFFER (buffer
));
9778 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9781 BVAR (current_buffer
, undo_list
) = Qt
;
9782 BVAR (current_buffer
, read_only
) = Qnil
;
9783 specbind (Qinhibit_read_only
, Qt
);
9784 specbind (Qinhibit_modification_hooks
, Qt
);
9786 if (clear_buffer_p
&& Z
> BEG
)
9789 xassert (BEGV
>= BEG
);
9790 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9792 rc
= fn (a1
, a2
, a3
, a4
);
9794 xassert (BEGV
>= BEG
);
9795 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9797 unbind_to (count
, Qnil
);
9802 /* Save state that should be preserved around the call to the function
9803 FN called in with_echo_area_buffer. */
9806 with_echo_area_buffer_unwind_data (struct window
*w
)
9809 Lisp_Object vector
, tmp
;
9811 /* Reduce consing by keeping one vector in
9812 Vwith_echo_area_save_vector. */
9813 vector
= Vwith_echo_area_save_vector
;
9814 Vwith_echo_area_save_vector
= Qnil
;
9817 vector
= Fmake_vector (make_number (7), Qnil
);
9819 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9820 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9821 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9825 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9826 ASET (vector
, i
, w
->buffer
); ++i
;
9827 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9828 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9833 for (; i
< end
; ++i
)
9834 ASET (vector
, i
, Qnil
);
9837 xassert (i
== ASIZE (vector
));
9842 /* Restore global state from VECTOR which was created by
9843 with_echo_area_buffer_unwind_data. */
9846 unwind_with_echo_area_buffer (Lisp_Object vector
)
9848 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9849 Vdeactivate_mark
= AREF (vector
, 1);
9850 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9852 if (WINDOWP (AREF (vector
, 3)))
9855 Lisp_Object buffer
, charpos
, bytepos
;
9857 w
= XWINDOW (AREF (vector
, 3));
9858 buffer
= AREF (vector
, 4);
9859 charpos
= AREF (vector
, 5);
9860 bytepos
= AREF (vector
, 6);
9863 set_marker_both (w
->pointm
, buffer
,
9864 XFASTINT (charpos
), XFASTINT (bytepos
));
9867 Vwith_echo_area_save_vector
= vector
;
9872 /* Set up the echo area for use by print functions. MULTIBYTE_P
9873 non-zero means we will print multibyte. */
9876 setup_echo_area_for_printing (int multibyte_p
)
9878 /* If we can't find an echo area any more, exit. */
9879 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9882 ensure_echo_area_buffers ();
9884 if (!message_buf_print
)
9886 /* A message has been output since the last time we printed.
9887 Choose a fresh echo area buffer. */
9888 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9889 echo_area_buffer
[0] = echo_buffer
[1];
9891 echo_area_buffer
[0] = echo_buffer
[0];
9893 /* Switch to that buffer and clear it. */
9894 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9895 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9899 ptrdiff_t count
= SPECPDL_INDEX ();
9900 specbind (Qinhibit_read_only
, Qt
);
9901 /* Note that undo recording is always disabled. */
9903 unbind_to (count
, Qnil
);
9905 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9907 /* Set up the buffer for the multibyteness we need. */
9909 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9910 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9912 /* Raise the frame containing the echo area. */
9913 if (minibuffer_auto_raise
)
9915 struct frame
*sf
= SELECTED_FRAME ();
9916 Lisp_Object mini_window
;
9917 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9918 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9921 message_log_maybe_newline ();
9922 message_buf_print
= 1;
9926 if (NILP (echo_area_buffer
[0]))
9928 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9929 echo_area_buffer
[0] = echo_buffer
[1];
9931 echo_area_buffer
[0] = echo_buffer
[0];
9934 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9936 /* Someone switched buffers between print requests. */
9937 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9938 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9944 /* Display an echo area message in window W. Value is non-zero if W's
9945 height is changed. If display_last_displayed_message_p is
9946 non-zero, display the message that was last displayed, otherwise
9947 display the current message. */
9950 display_echo_area (struct window
*w
)
9952 int i
, no_message_p
, window_height_changed_p
;
9954 /* Temporarily disable garbage collections while displaying the echo
9955 area. This is done because a GC can print a message itself.
9956 That message would modify the echo area buffer's contents while a
9957 redisplay of the buffer is going on, and seriously confuse
9959 ptrdiff_t count
= inhibit_garbage_collection ();
9961 /* If there is no message, we must call display_echo_area_1
9962 nevertheless because it resizes the window. But we will have to
9963 reset the echo_area_buffer in question to nil at the end because
9964 with_echo_area_buffer will sets it to an empty buffer. */
9965 i
= display_last_displayed_message_p
? 1 : 0;
9966 no_message_p
= NILP (echo_area_buffer
[i
]);
9968 window_height_changed_p
9969 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9970 display_echo_area_1
,
9971 (intptr_t) w
, Qnil
, 0, 0);
9974 echo_area_buffer
[i
] = Qnil
;
9976 unbind_to (count
, Qnil
);
9977 return window_height_changed_p
;
9981 /* Helper for display_echo_area. Display the current buffer which
9982 contains the current echo area message in window W, a mini-window,
9983 a pointer to which is passed in A1. A2..A4 are currently not used.
9984 Change the height of W so that all of the message is displayed.
9985 Value is non-zero if height of W was changed. */
9988 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9991 struct window
*w
= (struct window
*) i1
;
9993 struct text_pos start
;
9994 int window_height_changed_p
= 0;
9996 /* Do this before displaying, so that we have a large enough glyph
9997 matrix for the display. If we can't get enough space for the
9998 whole text, display the last N lines. That works by setting w->start. */
9999 window_height_changed_p
= resize_mini_window (w
, 0);
10001 /* Use the starting position chosen by resize_mini_window. */
10002 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10005 clear_glyph_matrix (w
->desired_matrix
);
10006 XSETWINDOW (window
, w
);
10007 try_window (window
, start
, 0);
10009 return window_height_changed_p
;
10013 /* Resize the echo area window to exactly the size needed for the
10014 currently displayed message, if there is one. If a mini-buffer
10015 is active, don't shrink it. */
10018 resize_echo_area_exactly (void)
10020 if (BUFFERP (echo_area_buffer
[0])
10021 && WINDOWP (echo_area_window
))
10023 struct window
*w
= XWINDOW (echo_area_window
);
10025 Lisp_Object resize_exactly
;
10027 if (minibuf_level
== 0)
10028 resize_exactly
= Qt
;
10030 resize_exactly
= Qnil
;
10032 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10033 (intptr_t) w
, resize_exactly
,
10037 ++windows_or_buffers_changed
;
10038 ++update_mode_lines
;
10039 redisplay_internal ();
10045 /* Callback function for with_echo_area_buffer, when used from
10046 resize_echo_area_exactly. A1 contains a pointer to the window to
10047 resize, EXACTLY non-nil means resize the mini-window exactly to the
10048 size of the text displayed. A3 and A4 are not used. Value is what
10049 resize_mini_window returns. */
10052 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10055 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10059 /* Resize mini-window W to fit the size of its contents. EXACT_P
10060 means size the window exactly to the size needed. Otherwise, it's
10061 only enlarged until W's buffer is empty.
10063 Set W->start to the right place to begin display. If the whole
10064 contents fit, start at the beginning. Otherwise, start so as
10065 to make the end of the contents appear. This is particularly
10066 important for y-or-n-p, but seems desirable generally.
10068 Value is non-zero if the window height has been changed. */
10071 resize_mini_window (struct window
*w
, int exact_p
)
10073 struct frame
*f
= XFRAME (w
->frame
);
10074 int window_height_changed_p
= 0;
10076 xassert (MINI_WINDOW_P (w
));
10078 /* By default, start display at the beginning. */
10079 set_marker_both (w
->start
, w
->buffer
,
10080 BUF_BEGV (XBUFFER (w
->buffer
)),
10081 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10083 /* Don't resize windows while redisplaying a window; it would
10084 confuse redisplay functions when the size of the window they are
10085 displaying changes from under them. Such a resizing can happen,
10086 for instance, when which-func prints a long message while
10087 we are running fontification-functions. We're running these
10088 functions with safe_call which binds inhibit-redisplay to t. */
10089 if (!NILP (Vinhibit_redisplay
))
10092 /* Nil means don't try to resize. */
10093 if (NILP (Vresize_mini_windows
)
10094 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10097 if (!FRAME_MINIBUF_ONLY_P (f
))
10100 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10101 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10103 EMACS_INT max_height
;
10104 int unit
= FRAME_LINE_HEIGHT (f
);
10105 struct text_pos start
;
10106 struct buffer
*old_current_buffer
= NULL
;
10108 if (current_buffer
!= XBUFFER (w
->buffer
))
10110 old_current_buffer
= current_buffer
;
10111 set_buffer_internal (XBUFFER (w
->buffer
));
10114 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10116 /* Compute the max. number of lines specified by the user. */
10117 if (FLOATP (Vmax_mini_window_height
))
10118 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10119 else if (INTEGERP (Vmax_mini_window_height
))
10120 max_height
= XINT (Vmax_mini_window_height
);
10122 max_height
= total_height
/ 4;
10124 /* Correct that max. height if it's bogus. */
10125 max_height
= max (1, max_height
);
10126 max_height
= min (total_height
, max_height
);
10128 /* Find out the height of the text in the window. */
10129 if (it
.line_wrap
== TRUNCATE
)
10134 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10135 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10136 height
= it
.current_y
+ last_height
;
10138 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10139 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10140 height
= (height
+ unit
- 1) / unit
;
10143 /* Compute a suitable window start. */
10144 if (height
> max_height
)
10146 height
= max_height
;
10147 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10148 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10149 start
= it
.current
.pos
;
10152 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10153 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10155 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10157 /* Let it grow only, until we display an empty message, in which
10158 case the window shrinks again. */
10159 if (height
> WINDOW_TOTAL_LINES (w
))
10161 int old_height
= WINDOW_TOTAL_LINES (w
);
10162 freeze_window_starts (f
, 1);
10163 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10164 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10166 else if (height
< WINDOW_TOTAL_LINES (w
)
10167 && (exact_p
|| BEGV
== ZV
))
10169 int old_height
= WINDOW_TOTAL_LINES (w
);
10170 freeze_window_starts (f
, 0);
10171 shrink_mini_window (w
);
10172 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10177 /* Always resize to exact size needed. */
10178 if (height
> WINDOW_TOTAL_LINES (w
))
10180 int old_height
= WINDOW_TOTAL_LINES (w
);
10181 freeze_window_starts (f
, 1);
10182 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10183 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10185 else if (height
< WINDOW_TOTAL_LINES (w
))
10187 int old_height
= WINDOW_TOTAL_LINES (w
);
10188 freeze_window_starts (f
, 0);
10189 shrink_mini_window (w
);
10193 freeze_window_starts (f
, 1);
10194 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10197 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10201 if (old_current_buffer
)
10202 set_buffer_internal (old_current_buffer
);
10205 return window_height_changed_p
;
10209 /* Value is the current message, a string, or nil if there is no
10210 current message. */
10213 current_message (void)
10217 if (!BUFFERP (echo_area_buffer
[0]))
10221 with_echo_area_buffer (0, 0, current_message_1
,
10222 (intptr_t) &msg
, Qnil
, 0, 0);
10224 echo_area_buffer
[0] = Qnil
;
10232 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10235 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10238 *msg
= make_buffer_string (BEG
, Z
, 1);
10245 /* Push the current message on Vmessage_stack for later restoration
10246 by restore_message. Value is non-zero if the current message isn't
10247 empty. This is a relatively infrequent operation, so it's not
10248 worth optimizing. */
10251 push_message (void)
10254 msg
= current_message ();
10255 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10256 return STRINGP (msg
);
10260 /* Restore message display from the top of Vmessage_stack. */
10263 restore_message (void)
10267 xassert (CONSP (Vmessage_stack
));
10268 msg
= XCAR (Vmessage_stack
);
10270 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10272 message3_nolog (msg
, 0, 0);
10276 /* Handler for record_unwind_protect calling pop_message. */
10279 pop_message_unwind (Lisp_Object dummy
)
10285 /* Pop the top-most entry off Vmessage_stack. */
10290 xassert (CONSP (Vmessage_stack
));
10291 Vmessage_stack
= XCDR (Vmessage_stack
);
10295 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10296 exits. If the stack is not empty, we have a missing pop_message
10300 check_message_stack (void)
10302 if (!NILP (Vmessage_stack
))
10307 /* Truncate to NCHARS what will be displayed in the echo area the next
10308 time we display it---but don't redisplay it now. */
10311 truncate_echo_area (ptrdiff_t nchars
)
10314 echo_area_buffer
[0] = Qnil
;
10315 /* A null message buffer means that the frame hasn't really been
10316 initialized yet. Error messages get reported properly by
10317 cmd_error, so this must be just an informative message; toss it. */
10318 else if (!noninteractive
10320 && !NILP (echo_area_buffer
[0]))
10322 struct frame
*sf
= SELECTED_FRAME ();
10323 if (FRAME_MESSAGE_BUF (sf
))
10324 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10329 /* Helper function for truncate_echo_area. Truncate the current
10330 message to at most NCHARS characters. */
10333 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10335 if (BEG
+ nchars
< Z
)
10336 del_range (BEG
+ nchars
, Z
);
10338 echo_area_buffer
[0] = Qnil
;
10343 /* Set the current message to a substring of S or STRING.
10345 If STRING is a Lisp string, set the message to the first NBYTES
10346 bytes from STRING. NBYTES zero means use the whole string. If
10347 STRING is multibyte, the message will be displayed multibyte.
10349 If S is not null, set the message to the first LEN bytes of S. LEN
10350 zero means use the whole string. MULTIBYTE_P non-zero means S is
10351 multibyte. Display the message multibyte in that case.
10353 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10354 to t before calling set_message_1 (which calls insert).
10358 set_message (const char *s
, Lisp_Object string
,
10359 ptrdiff_t nbytes
, int multibyte_p
)
10361 message_enable_multibyte
10362 = ((s
&& multibyte_p
)
10363 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10365 with_echo_area_buffer (0, -1, set_message_1
,
10366 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10367 message_buf_print
= 0;
10368 help_echo_showing_p
= 0;
10372 /* Helper function for set_message. Arguments have the same meaning
10373 as there, with A1 corresponding to S and A2 corresponding to STRING
10374 This function is called with the echo area buffer being
10378 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10381 const char *s
= (const char *) i1
;
10382 const unsigned char *msg
= (const unsigned char *) s
;
10383 Lisp_Object string
= a2
;
10385 /* Change multibyteness of the echo buffer appropriately. */
10386 if (message_enable_multibyte
10387 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10388 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10390 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10391 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10392 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10394 /* Insert new message at BEG. */
10395 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10397 if (STRINGP (string
))
10402 nbytes
= SBYTES (string
);
10403 nchars
= string_byte_to_char (string
, nbytes
);
10405 /* This function takes care of single/multibyte conversion. We
10406 just have to ensure that the echo area buffer has the right
10407 setting of enable_multibyte_characters. */
10408 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10413 nbytes
= strlen (s
);
10415 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10417 /* Convert from multi-byte to single-byte. */
10422 /* Convert a multibyte string to single-byte. */
10423 for (i
= 0; i
< nbytes
; i
+= n
)
10425 c
= string_char_and_length (msg
+ i
, &n
);
10426 work
[0] = (ASCII_CHAR_P (c
)
10428 : multibyte_char_to_unibyte (c
));
10429 insert_1_both (work
, 1, 1, 1, 0, 0);
10432 else if (!multibyte_p
10433 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10435 /* Convert from single-byte to multi-byte. */
10438 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10440 /* Convert a single-byte string to multibyte. */
10441 for (i
= 0; i
< nbytes
; i
++)
10444 MAKE_CHAR_MULTIBYTE (c
);
10445 n
= CHAR_STRING (c
, str
);
10446 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10450 insert_1 (s
, nbytes
, 1, 0, 0);
10457 /* Clear messages. CURRENT_P non-zero means clear the current
10458 message. LAST_DISPLAYED_P non-zero means clear the message
10462 clear_message (int current_p
, int last_displayed_p
)
10466 echo_area_buffer
[0] = Qnil
;
10467 message_cleared_p
= 1;
10470 if (last_displayed_p
)
10471 echo_area_buffer
[1] = Qnil
;
10473 message_buf_print
= 0;
10476 /* Clear garbaged frames.
10478 This function is used where the old redisplay called
10479 redraw_garbaged_frames which in turn called redraw_frame which in
10480 turn called clear_frame. The call to clear_frame was a source of
10481 flickering. I believe a clear_frame is not necessary. It should
10482 suffice in the new redisplay to invalidate all current matrices,
10483 and ensure a complete redisplay of all windows. */
10486 clear_garbaged_frames (void)
10488 if (frame_garbaged
)
10490 Lisp_Object tail
, frame
;
10491 int changed_count
= 0;
10493 FOR_EACH_FRAME (tail
, frame
)
10495 struct frame
*f
= XFRAME (frame
);
10497 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10501 Fredraw_frame (frame
);
10502 f
->force_flush_display_p
= 1;
10504 clear_current_matrices (f
);
10511 frame_garbaged
= 0;
10513 ++windows_or_buffers_changed
;
10518 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10519 is non-zero update selected_frame. Value is non-zero if the
10520 mini-windows height has been changed. */
10523 echo_area_display (int update_frame_p
)
10525 Lisp_Object mini_window
;
10528 int window_height_changed_p
= 0;
10529 struct frame
*sf
= SELECTED_FRAME ();
10531 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10532 w
= XWINDOW (mini_window
);
10533 f
= XFRAME (WINDOW_FRAME (w
));
10535 /* Don't display if frame is invisible or not yet initialized. */
10536 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10539 #ifdef HAVE_WINDOW_SYSTEM
10540 /* When Emacs starts, selected_frame may be the initial terminal
10541 frame. If we let this through, a message would be displayed on
10543 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10545 #endif /* HAVE_WINDOW_SYSTEM */
10547 /* Redraw garbaged frames. */
10548 if (frame_garbaged
)
10549 clear_garbaged_frames ();
10551 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10553 echo_area_window
= mini_window
;
10554 window_height_changed_p
= display_echo_area (w
);
10555 w
->must_be_updated_p
= 1;
10557 /* Update the display, unless called from redisplay_internal.
10558 Also don't update the screen during redisplay itself. The
10559 update will happen at the end of redisplay, and an update
10560 here could cause confusion. */
10561 if (update_frame_p
&& !redisplaying_p
)
10565 /* If the display update has been interrupted by pending
10566 input, update mode lines in the frame. Due to the
10567 pending input, it might have been that redisplay hasn't
10568 been called, so that mode lines above the echo area are
10569 garbaged. This looks odd, so we prevent it here. */
10570 if (!display_completed
)
10571 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10573 if (window_height_changed_p
10574 /* Don't do this if Emacs is shutting down. Redisplay
10575 needs to run hooks. */
10576 && !NILP (Vrun_hooks
))
10578 /* Must update other windows. Likewise as in other
10579 cases, don't let this update be interrupted by
10581 ptrdiff_t count
= SPECPDL_INDEX ();
10582 specbind (Qredisplay_dont_pause
, Qt
);
10583 windows_or_buffers_changed
= 1;
10584 redisplay_internal ();
10585 unbind_to (count
, Qnil
);
10587 else if (FRAME_WINDOW_P (f
) && n
== 0)
10589 /* Window configuration is the same as before.
10590 Can do with a display update of the echo area,
10591 unless we displayed some mode lines. */
10592 update_single_window (w
, 1);
10593 FRAME_RIF (f
)->flush_display (f
);
10596 update_frame (f
, 1, 1);
10598 /* If cursor is in the echo area, make sure that the next
10599 redisplay displays the minibuffer, so that the cursor will
10600 be replaced with what the minibuffer wants. */
10601 if (cursor_in_echo_area
)
10602 ++windows_or_buffers_changed
;
10605 else if (!EQ (mini_window
, selected_window
))
10606 windows_or_buffers_changed
++;
10608 /* Last displayed message is now the current message. */
10609 echo_area_buffer
[1] = echo_area_buffer
[0];
10610 /* Inform read_char that we're not echoing. */
10611 echo_message_buffer
= Qnil
;
10613 /* Prevent redisplay optimization in redisplay_internal by resetting
10614 this_line_start_pos. This is done because the mini-buffer now
10615 displays the message instead of its buffer text. */
10616 if (EQ (mini_window
, selected_window
))
10617 CHARPOS (this_line_start_pos
) = 0;
10619 return window_height_changed_p
;
10624 /***********************************************************************
10625 Mode Lines and Frame Titles
10626 ***********************************************************************/
10628 /* A buffer for constructing non-propertized mode-line strings and
10629 frame titles in it; allocated from the heap in init_xdisp and
10630 resized as needed in store_mode_line_noprop_char. */
10632 static char *mode_line_noprop_buf
;
10634 /* The buffer's end, and a current output position in it. */
10636 static char *mode_line_noprop_buf_end
;
10637 static char *mode_line_noprop_ptr
;
10639 #define MODE_LINE_NOPROP_LEN(start) \
10640 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10643 MODE_LINE_DISPLAY
= 0,
10647 } mode_line_target
;
10649 /* Alist that caches the results of :propertize.
10650 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10651 static Lisp_Object mode_line_proptrans_alist
;
10653 /* List of strings making up the mode-line. */
10654 static Lisp_Object mode_line_string_list
;
10656 /* Base face property when building propertized mode line string. */
10657 static Lisp_Object mode_line_string_face
;
10658 static Lisp_Object mode_line_string_face_prop
;
10661 /* Unwind data for mode line strings */
10663 static Lisp_Object Vmode_line_unwind_vector
;
10666 format_mode_line_unwind_data (struct buffer
*obuf
,
10668 int save_proptrans
)
10670 Lisp_Object vector
, tmp
;
10672 /* Reduce consing by keeping one vector in
10673 Vwith_echo_area_save_vector. */
10674 vector
= Vmode_line_unwind_vector
;
10675 Vmode_line_unwind_vector
= Qnil
;
10678 vector
= Fmake_vector (make_number (8), Qnil
);
10680 ASET (vector
, 0, make_number (mode_line_target
));
10681 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10682 ASET (vector
, 2, mode_line_string_list
);
10683 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10684 ASET (vector
, 4, mode_line_string_face
);
10685 ASET (vector
, 5, mode_line_string_face_prop
);
10688 XSETBUFFER (tmp
, obuf
);
10691 ASET (vector
, 6, tmp
);
10692 ASET (vector
, 7, owin
);
10698 unwind_format_mode_line (Lisp_Object vector
)
10700 mode_line_target
= XINT (AREF (vector
, 0));
10701 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10702 mode_line_string_list
= AREF (vector
, 2);
10703 if (! EQ (AREF (vector
, 3), Qt
))
10704 mode_line_proptrans_alist
= AREF (vector
, 3);
10705 mode_line_string_face
= AREF (vector
, 4);
10706 mode_line_string_face_prop
= AREF (vector
, 5);
10708 if (!NILP (AREF (vector
, 7)))
10709 /* Select window before buffer, since it may change the buffer. */
10710 Fselect_window (AREF (vector
, 7), Qt
);
10712 if (!NILP (AREF (vector
, 6)))
10714 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10715 ASET (vector
, 6, Qnil
);
10718 Vmode_line_unwind_vector
= vector
;
10723 /* Store a single character C for the frame title in mode_line_noprop_buf.
10724 Re-allocate mode_line_noprop_buf if necessary. */
10727 store_mode_line_noprop_char (char c
)
10729 /* If output position has reached the end of the allocated buffer,
10730 increase the buffer's size. */
10731 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10733 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10734 ptrdiff_t size
= len
;
10735 mode_line_noprop_buf
=
10736 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10737 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10738 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10741 *mode_line_noprop_ptr
++ = c
;
10745 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10746 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10747 characters that yield more columns than PRECISION; PRECISION <= 0
10748 means copy the whole string. Pad with spaces until FIELD_WIDTH
10749 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10750 pad. Called from display_mode_element when it is used to build a
10754 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10756 const unsigned char *str
= (const unsigned char *) string
;
10758 ptrdiff_t dummy
, nbytes
;
10760 /* Copy at most PRECISION chars from STR. */
10761 nbytes
= strlen (string
);
10762 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10764 store_mode_line_noprop_char (*str
++);
10766 /* Fill up with spaces until FIELD_WIDTH reached. */
10767 while (field_width
> 0
10768 && n
< field_width
)
10770 store_mode_line_noprop_char (' ');
10777 /***********************************************************************
10779 ***********************************************************************/
10781 #ifdef HAVE_WINDOW_SYSTEM
10783 /* Set the title of FRAME, if it has changed. The title format is
10784 Vicon_title_format if FRAME is iconified, otherwise it is
10785 frame_title_format. */
10788 x_consider_frame_title (Lisp_Object frame
)
10790 struct frame
*f
= XFRAME (frame
);
10792 if (FRAME_WINDOW_P (f
)
10793 || FRAME_MINIBUF_ONLY_P (f
)
10794 || f
->explicit_name
)
10796 /* Do we have more than one visible frame on this X display? */
10799 ptrdiff_t title_start
;
10803 ptrdiff_t count
= SPECPDL_INDEX ();
10805 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10807 Lisp_Object other_frame
= XCAR (tail
);
10808 struct frame
*tf
= XFRAME (other_frame
);
10811 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10812 && !FRAME_MINIBUF_ONLY_P (tf
)
10813 && !EQ (other_frame
, tip_frame
)
10814 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10818 /* Set global variable indicating that multiple frames exist. */
10819 multiple_frames
= CONSP (tail
);
10821 /* Switch to the buffer of selected window of the frame. Set up
10822 mode_line_target so that display_mode_element will output into
10823 mode_line_noprop_buf; then display the title. */
10824 record_unwind_protect (unwind_format_mode_line
,
10825 format_mode_line_unwind_data
10826 (current_buffer
, selected_window
, 0));
10828 Fselect_window (f
->selected_window
, Qt
);
10829 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10830 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10832 mode_line_target
= MODE_LINE_TITLE
;
10833 title_start
= MODE_LINE_NOPROP_LEN (0);
10834 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10835 NULL
, DEFAULT_FACE_ID
);
10836 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10837 len
= MODE_LINE_NOPROP_LEN (title_start
);
10838 title
= mode_line_noprop_buf
+ title_start
;
10839 unbind_to (count
, Qnil
);
10841 /* Set the title only if it's changed. This avoids consing in
10842 the common case where it hasn't. (If it turns out that we've
10843 already wasted too much time by walking through the list with
10844 display_mode_element, then we might need to optimize at a
10845 higher level than this.) */
10846 if (! STRINGP (f
->name
)
10847 || SBYTES (f
->name
) != len
10848 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10849 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10853 #endif /* not HAVE_WINDOW_SYSTEM */
10858 /***********************************************************************
10860 ***********************************************************************/
10863 /* Prepare for redisplay by updating menu-bar item lists when
10864 appropriate. This can call eval. */
10867 prepare_menu_bars (void)
10870 struct gcpro gcpro1
, gcpro2
;
10872 Lisp_Object tooltip_frame
;
10874 #ifdef HAVE_WINDOW_SYSTEM
10875 tooltip_frame
= tip_frame
;
10877 tooltip_frame
= Qnil
;
10880 /* Update all frame titles based on their buffer names, etc. We do
10881 this before the menu bars so that the buffer-menu will show the
10882 up-to-date frame titles. */
10883 #ifdef HAVE_WINDOW_SYSTEM
10884 if (windows_or_buffers_changed
|| update_mode_lines
)
10886 Lisp_Object tail
, frame
;
10888 FOR_EACH_FRAME (tail
, frame
)
10890 f
= XFRAME (frame
);
10891 if (!EQ (frame
, tooltip_frame
)
10892 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10893 x_consider_frame_title (frame
);
10896 #endif /* HAVE_WINDOW_SYSTEM */
10898 /* Update the menu bar item lists, if appropriate. This has to be
10899 done before any actual redisplay or generation of display lines. */
10900 all_windows
= (update_mode_lines
10901 || buffer_shared
> 1
10902 || windows_or_buffers_changed
);
10905 Lisp_Object tail
, frame
;
10906 ptrdiff_t count
= SPECPDL_INDEX ();
10907 /* 1 means that update_menu_bar has run its hooks
10908 so any further calls to update_menu_bar shouldn't do so again. */
10909 int menu_bar_hooks_run
= 0;
10911 record_unwind_save_match_data ();
10913 FOR_EACH_FRAME (tail
, frame
)
10915 f
= XFRAME (frame
);
10917 /* Ignore tooltip frame. */
10918 if (EQ (frame
, tooltip_frame
))
10921 /* If a window on this frame changed size, report that to
10922 the user and clear the size-change flag. */
10923 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10925 Lisp_Object functions
;
10927 /* Clear flag first in case we get an error below. */
10928 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10929 functions
= Vwindow_size_change_functions
;
10930 GCPRO2 (tail
, functions
);
10932 while (CONSP (functions
))
10934 if (!EQ (XCAR (functions
), Qt
))
10935 call1 (XCAR (functions
), frame
);
10936 functions
= XCDR (functions
);
10942 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10943 #ifdef HAVE_WINDOW_SYSTEM
10944 update_tool_bar (f
, 0);
10947 if (windows_or_buffers_changed
10949 ns_set_doc_edited (f
, Fbuffer_modified_p
10950 (XWINDOW (f
->selected_window
)->buffer
));
10955 unbind_to (count
, Qnil
);
10959 struct frame
*sf
= SELECTED_FRAME ();
10960 update_menu_bar (sf
, 1, 0);
10961 #ifdef HAVE_WINDOW_SYSTEM
10962 update_tool_bar (sf
, 1);
10968 /* Update the menu bar item list for frame F. This has to be done
10969 before we start to fill in any display lines, because it can call
10972 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10974 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10975 already ran the menu bar hooks for this redisplay, so there
10976 is no need to run them again. The return value is the
10977 updated value of this flag, to pass to the next call. */
10980 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10982 Lisp_Object window
;
10983 register struct window
*w
;
10985 /* If called recursively during a menu update, do nothing. This can
10986 happen when, for instance, an activate-menubar-hook causes a
10988 if (inhibit_menubar_update
)
10991 window
= FRAME_SELECTED_WINDOW (f
);
10992 w
= XWINDOW (window
);
10994 if (FRAME_WINDOW_P (f
)
10996 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10997 || defined (HAVE_NS) || defined (USE_GTK)
10998 FRAME_EXTERNAL_MENU_BAR (f
)
11000 FRAME_MENU_BAR_LINES (f
) > 0
11002 : FRAME_MENU_BAR_LINES (f
) > 0)
11004 /* If the user has switched buffers or windows, we need to
11005 recompute to reflect the new bindings. But we'll
11006 recompute when update_mode_lines is set too; that means
11007 that people can use force-mode-line-update to request
11008 that the menu bar be recomputed. The adverse effect on
11009 the rest of the redisplay algorithm is about the same as
11010 windows_or_buffers_changed anyway. */
11011 if (windows_or_buffers_changed
11012 /* This used to test w->update_mode_line, but we believe
11013 there is no need to recompute the menu in that case. */
11014 || update_mode_lines
11015 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11016 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11017 != !NILP (w
->last_had_star
))
11018 || ((!NILP (Vtransient_mark_mode
)
11019 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11020 != !NILP (w
->region_showing
)))
11022 struct buffer
*prev
= current_buffer
;
11023 ptrdiff_t count
= SPECPDL_INDEX ();
11025 specbind (Qinhibit_menubar_update
, Qt
);
11027 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11028 if (save_match_data
)
11029 record_unwind_save_match_data ();
11030 if (NILP (Voverriding_local_map_menu_flag
))
11032 specbind (Qoverriding_terminal_local_map
, Qnil
);
11033 specbind (Qoverriding_local_map
, Qnil
);
11038 /* Run the Lucid hook. */
11039 safe_run_hooks (Qactivate_menubar_hook
);
11041 /* If it has changed current-menubar from previous value,
11042 really recompute the menu-bar from the value. */
11043 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11044 call0 (Qrecompute_lucid_menubar
);
11046 safe_run_hooks (Qmenu_bar_update_hook
);
11051 XSETFRAME (Vmenu_updating_frame
, f
);
11052 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11054 /* Redisplay the menu bar in case we changed it. */
11055 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11056 || defined (HAVE_NS) || defined (USE_GTK)
11057 if (FRAME_WINDOW_P (f
))
11059 #if defined (HAVE_NS)
11060 /* All frames on Mac OS share the same menubar. So only
11061 the selected frame should be allowed to set it. */
11062 if (f
== SELECTED_FRAME ())
11064 set_frame_menubar (f
, 0, 0);
11067 /* On a terminal screen, the menu bar is an ordinary screen
11068 line, and this makes it get updated. */
11069 w
->update_mode_line
= Qt
;
11070 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11071 /* In the non-toolkit version, the menu bar is an ordinary screen
11072 line, and this makes it get updated. */
11073 w
->update_mode_line
= Qt
;
11074 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11076 unbind_to (count
, Qnil
);
11077 set_buffer_internal_1 (prev
);
11086 /***********************************************************************
11088 ***********************************************************************/
11090 #ifdef HAVE_WINDOW_SYSTEM
11093 Nominal cursor position -- where to draw output.
11094 HPOS and VPOS are window relative glyph matrix coordinates.
11095 X and Y are window relative pixel coordinates. */
11097 struct cursor_pos output_cursor
;
11101 Set the global variable output_cursor to CURSOR. All cursor
11102 positions are relative to updated_window. */
11105 set_output_cursor (struct cursor_pos
*cursor
)
11107 output_cursor
.hpos
= cursor
->hpos
;
11108 output_cursor
.vpos
= cursor
->vpos
;
11109 output_cursor
.x
= cursor
->x
;
11110 output_cursor
.y
= cursor
->y
;
11115 Set a nominal cursor position.
11117 HPOS and VPOS are column/row positions in a window glyph matrix. X
11118 and Y are window text area relative pixel positions.
11120 If this is done during an update, updated_window will contain the
11121 window that is being updated and the position is the future output
11122 cursor position for that window. If updated_window is null, use
11123 selected_window and display the cursor at the given position. */
11126 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11130 /* If updated_window is not set, work on selected_window. */
11131 if (updated_window
)
11132 w
= updated_window
;
11134 w
= XWINDOW (selected_window
);
11136 /* Set the output cursor. */
11137 output_cursor
.hpos
= hpos
;
11138 output_cursor
.vpos
= vpos
;
11139 output_cursor
.x
= x
;
11140 output_cursor
.y
= y
;
11142 /* If not called as part of an update, really display the cursor.
11143 This will also set the cursor position of W. */
11144 if (updated_window
== NULL
)
11147 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11148 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11149 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11154 #endif /* HAVE_WINDOW_SYSTEM */
11157 /***********************************************************************
11159 ***********************************************************************/
11161 #ifdef HAVE_WINDOW_SYSTEM
11163 /* Where the mouse was last time we reported a mouse event. */
11165 FRAME_PTR last_mouse_frame
;
11167 /* Tool-bar item index of the item on which a mouse button was pressed
11170 int last_tool_bar_item
;
11174 update_tool_bar_unwind (Lisp_Object frame
)
11176 selected_frame
= frame
;
11180 /* Update the tool-bar item list for frame F. This has to be done
11181 before we start to fill in any display lines. Called from
11182 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11183 and restore it here. */
11186 update_tool_bar (struct frame
*f
, int save_match_data
)
11188 #if defined (USE_GTK) || defined (HAVE_NS)
11189 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11191 int do_update
= WINDOWP (f
->tool_bar_window
)
11192 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11197 Lisp_Object window
;
11200 window
= FRAME_SELECTED_WINDOW (f
);
11201 w
= XWINDOW (window
);
11203 /* If the user has switched buffers or windows, we need to
11204 recompute to reflect the new bindings. But we'll
11205 recompute when update_mode_lines is set too; that means
11206 that people can use force-mode-line-update to request
11207 that the menu bar be recomputed. The adverse effect on
11208 the rest of the redisplay algorithm is about the same as
11209 windows_or_buffers_changed anyway. */
11210 if (windows_or_buffers_changed
11211 || !NILP (w
->update_mode_line
)
11212 || update_mode_lines
11213 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11214 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11215 != !NILP (w
->last_had_star
))
11216 || ((!NILP (Vtransient_mark_mode
)
11217 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11218 != !NILP (w
->region_showing
)))
11220 struct buffer
*prev
= current_buffer
;
11221 ptrdiff_t count
= SPECPDL_INDEX ();
11222 Lisp_Object frame
, new_tool_bar
;
11223 int new_n_tool_bar
;
11224 struct gcpro gcpro1
;
11226 /* Set current_buffer to the buffer of the selected
11227 window of the frame, so that we get the right local
11229 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11231 /* Save match data, if we must. */
11232 if (save_match_data
)
11233 record_unwind_save_match_data ();
11235 /* Make sure that we don't accidentally use bogus keymaps. */
11236 if (NILP (Voverriding_local_map_menu_flag
))
11238 specbind (Qoverriding_terminal_local_map
, Qnil
);
11239 specbind (Qoverriding_local_map
, Qnil
);
11242 GCPRO1 (new_tool_bar
);
11244 /* We must temporarily set the selected frame to this frame
11245 before calling tool_bar_items, because the calculation of
11246 the tool-bar keymap uses the selected frame (see
11247 `tool-bar-make-keymap' in tool-bar.el). */
11248 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11249 XSETFRAME (frame
, f
);
11250 selected_frame
= frame
;
11252 /* Build desired tool-bar items from keymaps. */
11253 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11256 /* Redisplay the tool-bar if we changed it. */
11257 if (new_n_tool_bar
!= f
->n_tool_bar_items
11258 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11260 /* Redisplay that happens asynchronously due to an expose event
11261 may access f->tool_bar_items. Make sure we update both
11262 variables within BLOCK_INPUT so no such event interrupts. */
11264 f
->tool_bar_items
= new_tool_bar
;
11265 f
->n_tool_bar_items
= new_n_tool_bar
;
11266 w
->update_mode_line
= Qt
;
11272 unbind_to (count
, Qnil
);
11273 set_buffer_internal_1 (prev
);
11279 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11280 F's desired tool-bar contents. F->tool_bar_items must have
11281 been set up previously by calling prepare_menu_bars. */
11284 build_desired_tool_bar_string (struct frame
*f
)
11286 int i
, size
, size_needed
;
11287 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11288 Lisp_Object image
, plist
, props
;
11290 image
= plist
= props
= Qnil
;
11291 GCPRO3 (image
, plist
, props
);
11293 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11294 Otherwise, make a new string. */
11296 /* The size of the string we might be able to reuse. */
11297 size
= (STRINGP (f
->desired_tool_bar_string
)
11298 ? SCHARS (f
->desired_tool_bar_string
)
11301 /* We need one space in the string for each image. */
11302 size_needed
= f
->n_tool_bar_items
;
11304 /* Reuse f->desired_tool_bar_string, if possible. */
11305 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11306 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11307 make_number (' '));
11310 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11311 Fremove_text_properties (make_number (0), make_number (size
),
11312 props
, f
->desired_tool_bar_string
);
11315 /* Put a `display' property on the string for the images to display,
11316 put a `menu_item' property on tool-bar items with a value that
11317 is the index of the item in F's tool-bar item vector. */
11318 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11320 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11322 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11323 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11324 int hmargin
, vmargin
, relief
, idx
, end
;
11326 /* If image is a vector, choose the image according to the
11328 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11329 if (VECTORP (image
))
11333 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11334 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11337 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11338 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11340 xassert (ASIZE (image
) >= idx
);
11341 image
= AREF (image
, idx
);
11346 /* Ignore invalid image specifications. */
11347 if (!valid_image_p (image
))
11350 /* Display the tool-bar button pressed, or depressed. */
11351 plist
= Fcopy_sequence (XCDR (image
));
11353 /* Compute margin and relief to draw. */
11354 relief
= (tool_bar_button_relief
>= 0
11355 ? tool_bar_button_relief
11356 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11357 hmargin
= vmargin
= relief
;
11359 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11360 INT_MAX
- max (hmargin
, vmargin
)))
11362 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11363 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11365 else if (CONSP (Vtool_bar_button_margin
))
11367 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11368 INT_MAX
- hmargin
))
11369 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11371 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11372 INT_MAX
- vmargin
))
11373 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11376 if (auto_raise_tool_bar_buttons_p
)
11378 /* Add a `:relief' property to the image spec if the item is
11382 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11389 /* If image is selected, display it pressed, i.e. with a
11390 negative relief. If it's not selected, display it with a
11392 plist
= Fplist_put (plist
, QCrelief
,
11394 ? make_number (-relief
)
11395 : make_number (relief
)));
11400 /* Put a margin around the image. */
11401 if (hmargin
|| vmargin
)
11403 if (hmargin
== vmargin
)
11404 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11406 plist
= Fplist_put (plist
, QCmargin
,
11407 Fcons (make_number (hmargin
),
11408 make_number (vmargin
)));
11411 /* If button is not enabled, and we don't have special images
11412 for the disabled state, make the image appear disabled by
11413 applying an appropriate algorithm to it. */
11414 if (!enabled_p
&& idx
< 0)
11415 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11417 /* Put a `display' text property on the string for the image to
11418 display. Put a `menu-item' property on the string that gives
11419 the start of this item's properties in the tool-bar items
11421 image
= Fcons (Qimage
, plist
);
11422 props
= list4 (Qdisplay
, image
,
11423 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11425 /* Let the last image hide all remaining spaces in the tool bar
11426 string. The string can be longer than needed when we reuse a
11427 previous string. */
11428 if (i
+ 1 == f
->n_tool_bar_items
)
11429 end
= SCHARS (f
->desired_tool_bar_string
);
11432 Fadd_text_properties (make_number (i
), make_number (end
),
11433 props
, f
->desired_tool_bar_string
);
11441 /* Display one line of the tool-bar of frame IT->f.
11443 HEIGHT specifies the desired height of the tool-bar line.
11444 If the actual height of the glyph row is less than HEIGHT, the
11445 row's height is increased to HEIGHT, and the icons are centered
11446 vertically in the new height.
11448 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11449 count a final empty row in case the tool-bar width exactly matches
11454 display_tool_bar_line (struct it
*it
, int height
)
11456 struct glyph_row
*row
= it
->glyph_row
;
11457 int max_x
= it
->last_visible_x
;
11458 struct glyph
*last
;
11460 prepare_desired_row (row
);
11461 row
->y
= it
->current_y
;
11463 /* Note that this isn't made use of if the face hasn't a box,
11464 so there's no need to check the face here. */
11465 it
->start_of_box_run_p
= 1;
11467 while (it
->current_x
< max_x
)
11469 int x
, n_glyphs_before
, i
, nglyphs
;
11470 struct it it_before
;
11472 /* Get the next display element. */
11473 if (!get_next_display_element (it
))
11475 /* Don't count empty row if we are counting needed tool-bar lines. */
11476 if (height
< 0 && !it
->hpos
)
11481 /* Produce glyphs. */
11482 n_glyphs_before
= row
->used
[TEXT_AREA
];
11485 PRODUCE_GLYPHS (it
);
11487 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11489 x
= it_before
.current_x
;
11490 while (i
< nglyphs
)
11492 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11494 if (x
+ glyph
->pixel_width
> max_x
)
11496 /* Glyph doesn't fit on line. Backtrack. */
11497 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11499 /* If this is the only glyph on this line, it will never fit on the
11500 tool-bar, so skip it. But ensure there is at least one glyph,
11501 so we don't accidentally disable the tool-bar. */
11502 if (n_glyphs_before
== 0
11503 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11509 x
+= glyph
->pixel_width
;
11513 /* Stop at line end. */
11514 if (ITERATOR_AT_END_OF_LINE_P (it
))
11517 set_iterator_to_next (it
, 1);
11522 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11524 /* Use default face for the border below the tool bar.
11526 FIXME: When auto-resize-tool-bars is grow-only, there is
11527 no additional border below the possibly empty tool-bar lines.
11528 So to make the extra empty lines look "normal", we have to
11529 use the tool-bar face for the border too. */
11530 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11531 it
->face_id
= DEFAULT_FACE_ID
;
11533 extend_face_to_end_of_line (it
);
11534 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11535 last
->right_box_line_p
= 1;
11536 if (last
== row
->glyphs
[TEXT_AREA
])
11537 last
->left_box_line_p
= 1;
11539 /* Make line the desired height and center it vertically. */
11540 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11542 /* Don't add more than one line height. */
11543 height
%= FRAME_LINE_HEIGHT (it
->f
);
11544 it
->max_ascent
+= height
/ 2;
11545 it
->max_descent
+= (height
+ 1) / 2;
11548 compute_line_metrics (it
);
11550 /* If line is empty, make it occupy the rest of the tool-bar. */
11551 if (!row
->displays_text_p
)
11553 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11554 row
->visible_height
= row
->height
;
11555 row
->ascent
= row
->phys_ascent
= 0;
11556 row
->extra_line_spacing
= 0;
11559 row
->full_width_p
= 1;
11560 row
->continued_p
= 0;
11561 row
->truncated_on_left_p
= 0;
11562 row
->truncated_on_right_p
= 0;
11564 it
->current_x
= it
->hpos
= 0;
11565 it
->current_y
+= row
->height
;
11571 /* Max tool-bar height. */
11573 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11574 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11576 /* Value is the number of screen lines needed to make all tool-bar
11577 items of frame F visible. The number of actual rows needed is
11578 returned in *N_ROWS if non-NULL. */
11581 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11583 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11585 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11586 the desired matrix, so use (unused) mode-line row as temporary row to
11587 avoid destroying the first tool-bar row. */
11588 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11590 /* Initialize an iterator for iteration over
11591 F->desired_tool_bar_string in the tool-bar window of frame F. */
11592 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11593 it
.first_visible_x
= 0;
11594 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11595 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11596 it
.paragraph_embedding
= L2R
;
11598 while (!ITERATOR_AT_END_P (&it
))
11600 clear_glyph_row (temp_row
);
11601 it
.glyph_row
= temp_row
;
11602 display_tool_bar_line (&it
, -1);
11604 clear_glyph_row (temp_row
);
11606 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11608 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11610 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11614 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11616 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11617 (Lisp_Object frame
)
11624 frame
= selected_frame
;
11626 CHECK_FRAME (frame
);
11627 f
= XFRAME (frame
);
11629 if (WINDOWP (f
->tool_bar_window
)
11630 && (w
= XWINDOW (f
->tool_bar_window
),
11631 WINDOW_TOTAL_LINES (w
) > 0))
11633 update_tool_bar (f
, 1);
11634 if (f
->n_tool_bar_items
)
11636 build_desired_tool_bar_string (f
);
11637 nlines
= tool_bar_lines_needed (f
, NULL
);
11641 return make_number (nlines
);
11645 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11646 height should be changed. */
11649 redisplay_tool_bar (struct frame
*f
)
11653 struct glyph_row
*row
;
11655 #if defined (USE_GTK) || defined (HAVE_NS)
11656 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11657 update_frame_tool_bar (f
);
11661 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11662 do anything. This means you must start with tool-bar-lines
11663 non-zero to get the auto-sizing effect. Or in other words, you
11664 can turn off tool-bars by specifying tool-bar-lines zero. */
11665 if (!WINDOWP (f
->tool_bar_window
)
11666 || (w
= XWINDOW (f
->tool_bar_window
),
11667 WINDOW_TOTAL_LINES (w
) == 0))
11670 /* Set up an iterator for the tool-bar window. */
11671 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11672 it
.first_visible_x
= 0;
11673 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11674 row
= it
.glyph_row
;
11676 /* Build a string that represents the contents of the tool-bar. */
11677 build_desired_tool_bar_string (f
);
11678 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11679 /* FIXME: This should be controlled by a user option. But it
11680 doesn't make sense to have an R2L tool bar if the menu bar cannot
11681 be drawn also R2L, and making the menu bar R2L is tricky due
11682 toolkit-specific code that implements it. If an R2L tool bar is
11683 ever supported, display_tool_bar_line should also be augmented to
11684 call unproduce_glyphs like display_line and display_string
11686 it
.paragraph_embedding
= L2R
;
11688 if (f
->n_tool_bar_rows
== 0)
11692 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11693 nlines
!= WINDOW_TOTAL_LINES (w
)))
11696 int old_height
= WINDOW_TOTAL_LINES (w
);
11698 XSETFRAME (frame
, f
);
11699 Fmodify_frame_parameters (frame
,
11700 Fcons (Fcons (Qtool_bar_lines
,
11701 make_number (nlines
)),
11703 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11705 clear_glyph_matrix (w
->desired_matrix
);
11706 fonts_changed_p
= 1;
11712 /* Display as many lines as needed to display all tool-bar items. */
11714 if (f
->n_tool_bar_rows
> 0)
11716 int border
, rows
, height
, extra
;
11718 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11719 border
= XINT (Vtool_bar_border
);
11720 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11721 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11722 else if (EQ (Vtool_bar_border
, Qborder_width
))
11723 border
= f
->border_width
;
11729 rows
= f
->n_tool_bar_rows
;
11730 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11731 extra
= it
.last_visible_y
- border
- height
* rows
;
11733 while (it
.current_y
< it
.last_visible_y
)
11736 if (extra
> 0 && rows
-- > 0)
11738 h
= (extra
+ rows
- 1) / rows
;
11741 display_tool_bar_line (&it
, height
+ h
);
11746 while (it
.current_y
< it
.last_visible_y
)
11747 display_tool_bar_line (&it
, 0);
11750 /* It doesn't make much sense to try scrolling in the tool-bar
11751 window, so don't do it. */
11752 w
->desired_matrix
->no_scrolling_p
= 1;
11753 w
->must_be_updated_p
= 1;
11755 if (!NILP (Vauto_resize_tool_bars
))
11757 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11758 int change_height_p
= 0;
11760 /* If we couldn't display everything, change the tool-bar's
11761 height if there is room for more. */
11762 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11763 && it
.current_y
< max_tool_bar_height
)
11764 change_height_p
= 1;
11766 row
= it
.glyph_row
- 1;
11768 /* If there are blank lines at the end, except for a partially
11769 visible blank line at the end that is smaller than
11770 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11771 if (!row
->displays_text_p
11772 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11773 change_height_p
= 1;
11775 /* If row displays tool-bar items, but is partially visible,
11776 change the tool-bar's height. */
11777 if (row
->displays_text_p
11778 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11779 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11780 change_height_p
= 1;
11782 /* Resize windows as needed by changing the `tool-bar-lines'
11783 frame parameter. */
11784 if (change_height_p
)
11787 int old_height
= WINDOW_TOTAL_LINES (w
);
11789 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11791 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11792 && !f
->minimize_tool_bar_window_p
)
11793 ? (nlines
> old_height
)
11794 : (nlines
!= old_height
));
11795 f
->minimize_tool_bar_window_p
= 0;
11797 if (change_height_p
)
11799 XSETFRAME (frame
, f
);
11800 Fmodify_frame_parameters (frame
,
11801 Fcons (Fcons (Qtool_bar_lines
,
11802 make_number (nlines
)),
11804 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11806 clear_glyph_matrix (w
->desired_matrix
);
11807 f
->n_tool_bar_rows
= nrows
;
11808 fonts_changed_p
= 1;
11815 f
->minimize_tool_bar_window_p
= 0;
11820 /* Get information about the tool-bar item which is displayed in GLYPH
11821 on frame F. Return in *PROP_IDX the index where tool-bar item
11822 properties start in F->tool_bar_items. Value is zero if
11823 GLYPH doesn't display a tool-bar item. */
11826 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11832 /* This function can be called asynchronously, which means we must
11833 exclude any possibility that Fget_text_property signals an
11835 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11836 charpos
= max (0, charpos
);
11838 /* Get the text property `menu-item' at pos. The value of that
11839 property is the start index of this item's properties in
11840 F->tool_bar_items. */
11841 prop
= Fget_text_property (make_number (charpos
),
11842 Qmenu_item
, f
->current_tool_bar_string
);
11843 if (INTEGERP (prop
))
11845 *prop_idx
= XINT (prop
);
11855 /* Get information about the tool-bar item at position X/Y on frame F.
11856 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11857 the current matrix of the tool-bar window of F, or NULL if not
11858 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11859 item in F->tool_bar_items. Value is
11861 -1 if X/Y is not on a tool-bar item
11862 0 if X/Y is on the same item that was highlighted before.
11866 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11867 int *hpos
, int *vpos
, int *prop_idx
)
11869 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11870 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11873 /* Find the glyph under X/Y. */
11874 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11875 if (*glyph
== NULL
)
11878 /* Get the start of this tool-bar item's properties in
11879 f->tool_bar_items. */
11880 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11883 /* Is mouse on the highlighted item? */
11884 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11885 && *vpos
>= hlinfo
->mouse_face_beg_row
11886 && *vpos
<= hlinfo
->mouse_face_end_row
11887 && (*vpos
> hlinfo
->mouse_face_beg_row
11888 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11889 && (*vpos
< hlinfo
->mouse_face_end_row
11890 || *hpos
< hlinfo
->mouse_face_end_col
11891 || hlinfo
->mouse_face_past_end
))
11899 Handle mouse button event on the tool-bar of frame F, at
11900 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11901 0 for button release. MODIFIERS is event modifiers for button
11905 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11908 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11909 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11910 int hpos
, vpos
, prop_idx
;
11911 struct glyph
*glyph
;
11912 Lisp_Object enabled_p
;
11914 /* If not on the highlighted tool-bar item, return. */
11915 frame_to_window_pixel_xy (w
, &x
, &y
);
11916 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11919 /* If item is disabled, do nothing. */
11920 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11921 if (NILP (enabled_p
))
11926 /* Show item in pressed state. */
11927 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11928 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11929 last_tool_bar_item
= prop_idx
;
11933 Lisp_Object key
, frame
;
11934 struct input_event event
;
11935 EVENT_INIT (event
);
11937 /* Show item in released state. */
11938 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11939 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11941 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11943 XSETFRAME (frame
, f
);
11944 event
.kind
= TOOL_BAR_EVENT
;
11945 event
.frame_or_window
= frame
;
11947 kbd_buffer_store_event (&event
);
11949 event
.kind
= TOOL_BAR_EVENT
;
11950 event
.frame_or_window
= frame
;
11952 event
.modifiers
= modifiers
;
11953 kbd_buffer_store_event (&event
);
11954 last_tool_bar_item
= -1;
11959 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11960 tool-bar window-relative coordinates X/Y. Called from
11961 note_mouse_highlight. */
11964 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11966 Lisp_Object window
= f
->tool_bar_window
;
11967 struct window
*w
= XWINDOW (window
);
11968 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11969 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11971 struct glyph
*glyph
;
11972 struct glyph_row
*row
;
11974 Lisp_Object enabled_p
;
11976 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11977 int mouse_down_p
, rc
;
11979 /* Function note_mouse_highlight is called with negative X/Y
11980 values when mouse moves outside of the frame. */
11981 if (x
<= 0 || y
<= 0)
11983 clear_mouse_face (hlinfo
);
11987 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11990 /* Not on tool-bar item. */
11991 clear_mouse_face (hlinfo
);
11995 /* On same tool-bar item as before. */
11996 goto set_help_echo
;
11998 clear_mouse_face (hlinfo
);
12000 /* Mouse is down, but on different tool-bar item? */
12001 mouse_down_p
= (dpyinfo
->grabbed
12002 && f
== last_mouse_frame
12003 && FRAME_LIVE_P (f
));
12005 && last_tool_bar_item
!= prop_idx
)
12008 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12009 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12011 /* If tool-bar item is not enabled, don't highlight it. */
12012 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12013 if (!NILP (enabled_p
))
12015 /* Compute the x-position of the glyph. In front and past the
12016 image is a space. We include this in the highlighted area. */
12017 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12018 for (i
= x
= 0; i
< hpos
; ++i
)
12019 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12021 /* Record this as the current active region. */
12022 hlinfo
->mouse_face_beg_col
= hpos
;
12023 hlinfo
->mouse_face_beg_row
= vpos
;
12024 hlinfo
->mouse_face_beg_x
= x
;
12025 hlinfo
->mouse_face_beg_y
= row
->y
;
12026 hlinfo
->mouse_face_past_end
= 0;
12028 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12029 hlinfo
->mouse_face_end_row
= vpos
;
12030 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12031 hlinfo
->mouse_face_end_y
= row
->y
;
12032 hlinfo
->mouse_face_window
= window
;
12033 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12035 /* Display it as active. */
12036 show_mouse_face (hlinfo
, draw
);
12037 hlinfo
->mouse_face_image_state
= draw
;
12042 /* Set help_echo_string to a help string to display for this tool-bar item.
12043 XTread_socket does the rest. */
12044 help_echo_object
= help_echo_window
= Qnil
;
12045 help_echo_pos
= -1;
12046 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12047 if (NILP (help_echo_string
))
12048 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12051 #endif /* HAVE_WINDOW_SYSTEM */
12055 /************************************************************************
12056 Horizontal scrolling
12057 ************************************************************************/
12059 static int hscroll_window_tree (Lisp_Object
);
12060 static int hscroll_windows (Lisp_Object
);
12062 /* For all leaf windows in the window tree rooted at WINDOW, set their
12063 hscroll value so that PT is (i) visible in the window, and (ii) so
12064 that it is not within a certain margin at the window's left and
12065 right border. Value is non-zero if any window's hscroll has been
12069 hscroll_window_tree (Lisp_Object window
)
12071 int hscrolled_p
= 0;
12072 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12073 int hscroll_step_abs
= 0;
12074 double hscroll_step_rel
= 0;
12076 if (hscroll_relative_p
)
12078 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12079 if (hscroll_step_rel
< 0)
12081 hscroll_relative_p
= 0;
12082 hscroll_step_abs
= 0;
12085 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12087 hscroll_step_abs
= XINT (Vhscroll_step
);
12088 if (hscroll_step_abs
< 0)
12089 hscroll_step_abs
= 0;
12092 hscroll_step_abs
= 0;
12094 while (WINDOWP (window
))
12096 struct window
*w
= XWINDOW (window
);
12098 if (WINDOWP (w
->hchild
))
12099 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12100 else if (WINDOWP (w
->vchild
))
12101 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12102 else if (w
->cursor
.vpos
>= 0)
12105 int text_area_width
;
12106 struct glyph_row
*current_cursor_row
12107 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12108 struct glyph_row
*desired_cursor_row
12109 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12110 struct glyph_row
*cursor_row
12111 = (desired_cursor_row
->enabled_p
12112 ? desired_cursor_row
12113 : current_cursor_row
);
12114 int row_r2l_p
= cursor_row
->reversed_p
;
12116 text_area_width
= window_box_width (w
, TEXT_AREA
);
12118 /* Scroll when cursor is inside this scroll margin. */
12119 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12121 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12122 /* For left-to-right rows, hscroll when cursor is either
12123 (i) inside the right hscroll margin, or (ii) if it is
12124 inside the left margin and the window is already
12127 && ((XFASTINT (w
->hscroll
)
12128 && w
->cursor
.x
<= h_margin
)
12129 || (cursor_row
->enabled_p
12130 && cursor_row
->truncated_on_right_p
12131 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12132 /* For right-to-left rows, the logic is similar,
12133 except that rules for scrolling to left and right
12134 are reversed. E.g., if cursor.x <= h_margin, we
12135 need to hscroll "to the right" unconditionally,
12136 and that will scroll the screen to the left so as
12137 to reveal the next portion of the row. */
12139 && ((cursor_row
->enabled_p
12140 /* FIXME: It is confusing to set the
12141 truncated_on_right_p flag when R2L rows
12142 are actually truncated on the left. */
12143 && cursor_row
->truncated_on_right_p
12144 && w
->cursor
.x
<= h_margin
)
12145 || (XFASTINT (w
->hscroll
)
12146 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12150 struct buffer
*saved_current_buffer
;
12154 /* Find point in a display of infinite width. */
12155 saved_current_buffer
= current_buffer
;
12156 current_buffer
= XBUFFER (w
->buffer
);
12158 if (w
== XWINDOW (selected_window
))
12162 pt
= marker_position (w
->pointm
);
12163 pt
= max (BEGV
, pt
);
12167 /* Move iterator to pt starting at cursor_row->start in
12168 a line with infinite width. */
12169 init_to_row_start (&it
, w
, cursor_row
);
12170 it
.last_visible_x
= INFINITY
;
12171 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12172 current_buffer
= saved_current_buffer
;
12174 /* Position cursor in window. */
12175 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12176 hscroll
= max (0, (it
.current_x
12177 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12178 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12179 : (text_area_width
/ 2))))
12180 / FRAME_COLUMN_WIDTH (it
.f
);
12181 else if ((!row_r2l_p
12182 && w
->cursor
.x
>= text_area_width
- h_margin
)
12183 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12185 if (hscroll_relative_p
)
12186 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12189 wanted_x
= text_area_width
12190 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12193 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12197 if (hscroll_relative_p
)
12198 wanted_x
= text_area_width
* hscroll_step_rel
12201 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12204 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12206 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
12208 /* Don't prevent redisplay optimizations if hscroll
12209 hasn't changed, as it will unnecessarily slow down
12211 if (XFASTINT (w
->hscroll
) != hscroll
)
12213 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12214 w
->hscroll
= make_number (hscroll
);
12223 /* Value is non-zero if hscroll of any leaf window has been changed. */
12224 return hscrolled_p
;
12228 /* Set hscroll so that cursor is visible and not inside horizontal
12229 scroll margins for all windows in the tree rooted at WINDOW. See
12230 also hscroll_window_tree above. Value is non-zero if any window's
12231 hscroll has been changed. If it has, desired matrices on the frame
12232 of WINDOW are cleared. */
12235 hscroll_windows (Lisp_Object window
)
12237 int hscrolled_p
= hscroll_window_tree (window
);
12239 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12240 return hscrolled_p
;
12245 /************************************************************************
12247 ************************************************************************/
12249 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12250 to a non-zero value. This is sometimes handy to have in a debugger
12255 /* First and last unchanged row for try_window_id. */
12257 static int debug_first_unchanged_at_end_vpos
;
12258 static int debug_last_unchanged_at_beg_vpos
;
12260 /* Delta vpos and y. */
12262 static int debug_dvpos
, debug_dy
;
12264 /* Delta in characters and bytes for try_window_id. */
12266 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12268 /* Values of window_end_pos and window_end_vpos at the end of
12271 static ptrdiff_t debug_end_vpos
;
12273 /* Append a string to W->desired_matrix->method. FMT is a printf
12274 format string. If trace_redisplay_p is non-zero also printf the
12275 resulting string to stderr. */
12277 static void debug_method_add (struct window
*, char const *, ...)
12278 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12281 debug_method_add (struct window
*w
, char const *fmt
, ...)
12284 char *method
= w
->desired_matrix
->method
;
12285 int len
= strlen (method
);
12286 int size
= sizeof w
->desired_matrix
->method
;
12287 int remaining
= size
- len
- 1;
12290 va_start (ap
, fmt
);
12291 vsprintf (buffer
, fmt
, ap
);
12293 if (len
&& remaining
)
12296 --remaining
, ++len
;
12299 strncpy (method
+ len
, buffer
, remaining
);
12301 if (trace_redisplay_p
)
12302 fprintf (stderr
, "%p (%s): %s\n",
12304 ((BUFFERP (w
->buffer
)
12305 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12306 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12311 #endif /* GLYPH_DEBUG */
12314 /* Value is non-zero if all changes in window W, which displays
12315 current_buffer, are in the text between START and END. START is a
12316 buffer position, END is given as a distance from Z. Used in
12317 redisplay_internal for display optimization. */
12320 text_outside_line_unchanged_p (struct window
*w
,
12321 ptrdiff_t start
, ptrdiff_t end
)
12323 int unchanged_p
= 1;
12325 /* If text or overlays have changed, see where. */
12326 if (XFASTINT (w
->last_modified
) < MODIFF
12327 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12329 /* Gap in the line? */
12330 if (GPT
< start
|| Z
- GPT
< end
)
12333 /* Changes start in front of the line, or end after it? */
12335 && (BEG_UNCHANGED
< start
- 1
12336 || END_UNCHANGED
< end
))
12339 /* If selective display, can't optimize if changes start at the
12340 beginning of the line. */
12342 && INTEGERP (BVAR (current_buffer
, selective_display
))
12343 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12344 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12347 /* If there are overlays at the start or end of the line, these
12348 may have overlay strings with newlines in them. A change at
12349 START, for instance, may actually concern the display of such
12350 overlay strings as well, and they are displayed on different
12351 lines. So, quickly rule out this case. (For the future, it
12352 might be desirable to implement something more telling than
12353 just BEG/END_UNCHANGED.) */
12356 if (BEG
+ BEG_UNCHANGED
== start
12357 && overlay_touches_p (start
))
12359 if (END_UNCHANGED
== end
12360 && overlay_touches_p (Z
- end
))
12364 /* Under bidi reordering, adding or deleting a character in the
12365 beginning of a paragraph, before the first strong directional
12366 character, can change the base direction of the paragraph (unless
12367 the buffer specifies a fixed paragraph direction), which will
12368 require to redisplay the whole paragraph. It might be worthwhile
12369 to find the paragraph limits and widen the range of redisplayed
12370 lines to that, but for now just give up this optimization. */
12371 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12372 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12376 return unchanged_p
;
12380 /* Do a frame update, taking possible shortcuts into account. This is
12381 the main external entry point for redisplay.
12383 If the last redisplay displayed an echo area message and that message
12384 is no longer requested, we clear the echo area or bring back the
12385 mini-buffer if that is in use. */
12390 redisplay_internal ();
12395 overlay_arrow_string_or_property (Lisp_Object var
)
12399 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12402 return Voverlay_arrow_string
;
12405 /* Return 1 if there are any overlay-arrows in current_buffer. */
12407 overlay_arrow_in_current_buffer_p (void)
12411 for (vlist
= Voverlay_arrow_variable_list
;
12413 vlist
= XCDR (vlist
))
12415 Lisp_Object var
= XCAR (vlist
);
12418 if (!SYMBOLP (var
))
12420 val
= find_symbol_value (var
);
12422 && current_buffer
== XMARKER (val
)->buffer
)
12429 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12433 overlay_arrows_changed_p (void)
12437 for (vlist
= Voverlay_arrow_variable_list
;
12439 vlist
= XCDR (vlist
))
12441 Lisp_Object var
= XCAR (vlist
);
12442 Lisp_Object val
, pstr
;
12444 if (!SYMBOLP (var
))
12446 val
= find_symbol_value (var
);
12447 if (!MARKERP (val
))
12449 if (! EQ (COERCE_MARKER (val
),
12450 Fget (var
, Qlast_arrow_position
))
12451 || ! (pstr
= overlay_arrow_string_or_property (var
),
12452 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12458 /* Mark overlay arrows to be updated on next redisplay. */
12461 update_overlay_arrows (int up_to_date
)
12465 for (vlist
= Voverlay_arrow_variable_list
;
12467 vlist
= XCDR (vlist
))
12469 Lisp_Object var
= XCAR (vlist
);
12471 if (!SYMBOLP (var
))
12474 if (up_to_date
> 0)
12476 Lisp_Object val
= find_symbol_value (var
);
12477 Fput (var
, Qlast_arrow_position
,
12478 COERCE_MARKER (val
));
12479 Fput (var
, Qlast_arrow_string
,
12480 overlay_arrow_string_or_property (var
));
12482 else if (up_to_date
< 0
12483 || !NILP (Fget (var
, Qlast_arrow_position
)))
12485 Fput (var
, Qlast_arrow_position
, Qt
);
12486 Fput (var
, Qlast_arrow_string
, Qt
);
12492 /* Return overlay arrow string to display at row.
12493 Return integer (bitmap number) for arrow bitmap in left fringe.
12494 Return nil if no overlay arrow. */
12497 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12501 for (vlist
= Voverlay_arrow_variable_list
;
12503 vlist
= XCDR (vlist
))
12505 Lisp_Object var
= XCAR (vlist
);
12508 if (!SYMBOLP (var
))
12511 val
= find_symbol_value (var
);
12514 && current_buffer
== XMARKER (val
)->buffer
12515 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12517 if (FRAME_WINDOW_P (it
->f
)
12518 /* FIXME: if ROW->reversed_p is set, this should test
12519 the right fringe, not the left one. */
12520 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12522 #ifdef HAVE_WINDOW_SYSTEM
12523 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12526 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12527 return make_number (fringe_bitmap
);
12530 return make_number (-1); /* Use default arrow bitmap */
12532 return overlay_arrow_string_or_property (var
);
12539 /* Return 1 if point moved out of or into a composition. Otherwise
12540 return 0. PREV_BUF and PREV_PT are the last point buffer and
12541 position. BUF and PT are the current point buffer and position. */
12544 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12545 struct buffer
*buf
, ptrdiff_t pt
)
12547 ptrdiff_t start
, end
;
12549 Lisp_Object buffer
;
12551 XSETBUFFER (buffer
, buf
);
12552 /* Check a composition at the last point if point moved within the
12554 if (prev_buf
== buf
)
12557 /* Point didn't move. */
12560 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12561 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12562 && COMPOSITION_VALID_P (start
, end
, prop
)
12563 && start
< prev_pt
&& end
> prev_pt
)
12564 /* The last point was within the composition. Return 1 iff
12565 point moved out of the composition. */
12566 return (pt
<= start
|| pt
>= end
);
12569 /* Check a composition at the current point. */
12570 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12571 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12572 && COMPOSITION_VALID_P (start
, end
, prop
)
12573 && start
< pt
&& end
> pt
);
12577 /* Reconsider the setting of B->clip_changed which is displayed
12581 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12583 if (b
->clip_changed
12584 && !NILP (w
->window_end_valid
)
12585 && w
->current_matrix
->buffer
== b
12586 && w
->current_matrix
->zv
== BUF_ZV (b
)
12587 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12588 b
->clip_changed
= 0;
12590 /* If display wasn't paused, and W is not a tool bar window, see if
12591 point has been moved into or out of a composition. In that case,
12592 we set b->clip_changed to 1 to force updating the screen. If
12593 b->clip_changed has already been set to 1, we can skip this
12595 if (!b
->clip_changed
12596 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12600 if (w
== XWINDOW (selected_window
))
12603 pt
= marker_position (w
->pointm
);
12605 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12606 || pt
!= XINT (w
->last_point
))
12607 && check_point_in_composition (w
->current_matrix
->buffer
,
12608 XINT (w
->last_point
),
12609 XBUFFER (w
->buffer
), pt
))
12610 b
->clip_changed
= 1;
12615 /* Select FRAME to forward the values of frame-local variables into C
12616 variables so that the redisplay routines can access those values
12620 select_frame_for_redisplay (Lisp_Object frame
)
12622 Lisp_Object tail
, tem
;
12623 Lisp_Object old
= selected_frame
;
12624 struct Lisp_Symbol
*sym
;
12626 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12628 selected_frame
= frame
;
12631 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12632 if (CONSP (XCAR (tail
))
12633 && (tem
= XCAR (XCAR (tail
)),
12635 && (sym
= indirect_variable (XSYMBOL (tem
)),
12636 sym
->redirect
== SYMBOL_LOCALIZED
)
12637 && sym
->val
.blv
->frame_local
)
12638 /* Use find_symbol_value rather than Fsymbol_value
12639 to avoid an error if it is void. */
12640 find_symbol_value (tem
);
12641 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12645 #define STOP_POLLING \
12646 do { if (! polling_stopped_here) stop_polling (); \
12647 polling_stopped_here = 1; } while (0)
12649 #define RESUME_POLLING \
12650 do { if (polling_stopped_here) start_polling (); \
12651 polling_stopped_here = 0; } while (0)
12654 /* Perhaps in the future avoid recentering windows if it
12655 is not necessary; currently that causes some problems. */
12658 redisplay_internal (void)
12660 struct window
*w
= XWINDOW (selected_window
);
12664 int must_finish
= 0;
12665 struct text_pos tlbufpos
, tlendpos
;
12666 int number_of_visible_frames
;
12667 ptrdiff_t count
, count1
;
12669 int polling_stopped_here
= 0;
12670 Lisp_Object old_frame
= selected_frame
;
12672 /* Non-zero means redisplay has to consider all windows on all
12673 frames. Zero means, only selected_window is considered. */
12674 int consider_all_windows_p
;
12676 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12678 /* No redisplay if running in batch mode or frame is not yet fully
12679 initialized, or redisplay is explicitly turned off by setting
12680 Vinhibit_redisplay. */
12681 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12682 || !NILP (Vinhibit_redisplay
))
12685 /* Don't examine these until after testing Vinhibit_redisplay.
12686 When Emacs is shutting down, perhaps because its connection to
12687 X has dropped, we should not look at them at all. */
12688 fr
= XFRAME (w
->frame
);
12689 sf
= SELECTED_FRAME ();
12691 if (!fr
->glyphs_initialized_p
)
12694 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12695 if (popup_activated ())
12699 /* I don't think this happens but let's be paranoid. */
12700 if (redisplaying_p
)
12703 /* Record a function that resets redisplaying_p to its old value
12704 when we leave this function. */
12705 count
= SPECPDL_INDEX ();
12706 record_unwind_protect (unwind_redisplay
,
12707 Fcons (make_number (redisplaying_p
), selected_frame
));
12709 specbind (Qinhibit_free_realized_faces
, Qnil
);
12712 Lisp_Object tail
, frame
;
12714 FOR_EACH_FRAME (tail
, frame
)
12716 struct frame
*f
= XFRAME (frame
);
12717 f
->already_hscrolled_p
= 0;
12722 /* Remember the currently selected window. */
12725 if (!EQ (old_frame
, selected_frame
)
12726 && FRAME_LIVE_P (XFRAME (old_frame
)))
12727 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12728 selected_frame and selected_window to be temporarily out-of-sync so
12729 when we come back here via `goto retry', we need to resync because we
12730 may need to run Elisp code (via prepare_menu_bars). */
12731 select_frame_for_redisplay (old_frame
);
12734 reconsider_clip_changes (w
, current_buffer
);
12735 last_escape_glyph_frame
= NULL
;
12736 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12737 last_glyphless_glyph_frame
= NULL
;
12738 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12740 /* If new fonts have been loaded that make a glyph matrix adjustment
12741 necessary, do it. */
12742 if (fonts_changed_p
)
12744 adjust_glyphs (NULL
);
12745 ++windows_or_buffers_changed
;
12746 fonts_changed_p
= 0;
12749 /* If face_change_count is non-zero, init_iterator will free all
12750 realized faces, which includes the faces referenced from current
12751 matrices. So, we can't reuse current matrices in this case. */
12752 if (face_change_count
)
12753 ++windows_or_buffers_changed
;
12755 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12756 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12758 /* Since frames on a single ASCII terminal share the same
12759 display area, displaying a different frame means redisplay
12760 the whole thing. */
12761 windows_or_buffers_changed
++;
12762 SET_FRAME_GARBAGED (sf
);
12764 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12766 FRAME_TTY (sf
)->previous_frame
= sf
;
12769 /* Set the visible flags for all frames. Do this before checking
12770 for resized or garbaged frames; they want to know if their frames
12771 are visible. See the comment in frame.h for
12772 FRAME_SAMPLE_VISIBILITY. */
12774 Lisp_Object tail
, frame
;
12776 number_of_visible_frames
= 0;
12778 FOR_EACH_FRAME (tail
, frame
)
12780 struct frame
*f
= XFRAME (frame
);
12782 FRAME_SAMPLE_VISIBILITY (f
);
12783 if (FRAME_VISIBLE_P (f
))
12784 ++number_of_visible_frames
;
12785 clear_desired_matrices (f
);
12789 /* Notice any pending interrupt request to change frame size. */
12790 do_pending_window_change (1);
12792 /* do_pending_window_change could change the selected_window due to
12793 frame resizing which makes the selected window too small. */
12794 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12797 reconsider_clip_changes (w
, current_buffer
);
12800 /* Clear frames marked as garbaged. */
12801 if (frame_garbaged
)
12802 clear_garbaged_frames ();
12804 /* Build menubar and tool-bar items. */
12805 if (NILP (Vmemory_full
))
12806 prepare_menu_bars ();
12808 if (windows_or_buffers_changed
)
12809 update_mode_lines
++;
12811 /* Detect case that we need to write or remove a star in the mode line. */
12812 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12814 w
->update_mode_line
= Qt
;
12815 if (buffer_shared
> 1)
12816 update_mode_lines
++;
12819 /* Avoid invocation of point motion hooks by `current_column' below. */
12820 count1
= SPECPDL_INDEX ();
12821 specbind (Qinhibit_point_motion_hooks
, Qt
);
12823 /* If %c is in the mode line, update it if needed. */
12824 if (!NILP (w
->column_number_displayed
)
12825 /* This alternative quickly identifies a common case
12826 where no change is needed. */
12827 && !(PT
== XFASTINT (w
->last_point
)
12828 && XFASTINT (w
->last_modified
) >= MODIFF
12829 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12830 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12831 w
->update_mode_line
= Qt
;
12833 unbind_to (count1
, Qnil
);
12835 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12837 /* The variable buffer_shared is set in redisplay_window and
12838 indicates that we redisplay a buffer in different windows. See
12840 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12841 || cursor_type_changed
);
12843 /* If specs for an arrow have changed, do thorough redisplay
12844 to ensure we remove any arrow that should no longer exist. */
12845 if (overlay_arrows_changed_p ())
12846 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12848 /* Normally the message* functions will have already displayed and
12849 updated the echo area, but the frame may have been trashed, or
12850 the update may have been preempted, so display the echo area
12851 again here. Checking message_cleared_p captures the case that
12852 the echo area should be cleared. */
12853 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12854 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12855 || (message_cleared_p
12856 && minibuf_level
== 0
12857 /* If the mini-window is currently selected, this means the
12858 echo-area doesn't show through. */
12859 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12861 int window_height_changed_p
= echo_area_display (0);
12864 /* If we don't display the current message, don't clear the
12865 message_cleared_p flag, because, if we did, we wouldn't clear
12866 the echo area in the next redisplay which doesn't preserve
12868 if (!display_last_displayed_message_p
)
12869 message_cleared_p
= 0;
12871 if (fonts_changed_p
)
12873 else if (window_height_changed_p
)
12875 consider_all_windows_p
= 1;
12876 ++update_mode_lines
;
12877 ++windows_or_buffers_changed
;
12879 /* If window configuration was changed, frames may have been
12880 marked garbaged. Clear them or we will experience
12881 surprises wrt scrolling. */
12882 if (frame_garbaged
)
12883 clear_garbaged_frames ();
12886 else if (EQ (selected_window
, minibuf_window
)
12887 && (current_buffer
->clip_changed
12888 || XFASTINT (w
->last_modified
) < MODIFF
12889 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12890 && resize_mini_window (w
, 0))
12892 /* Resized active mini-window to fit the size of what it is
12893 showing if its contents might have changed. */
12895 /* FIXME: this causes all frames to be updated, which seems unnecessary
12896 since only the current frame needs to be considered. This function needs
12897 to be rewritten with two variables, consider_all_windows and
12898 consider_all_frames. */
12899 consider_all_windows_p
= 1;
12900 ++windows_or_buffers_changed
;
12901 ++update_mode_lines
;
12903 /* If window configuration was changed, frames may have been
12904 marked garbaged. Clear them or we will experience
12905 surprises wrt scrolling. */
12906 if (frame_garbaged
)
12907 clear_garbaged_frames ();
12911 /* If showing the region, and mark has changed, we must redisplay
12912 the whole window. The assignment to this_line_start_pos prevents
12913 the optimization directly below this if-statement. */
12914 if (((!NILP (Vtransient_mark_mode
)
12915 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12916 != !NILP (w
->region_showing
))
12917 || (!NILP (w
->region_showing
)
12918 && !EQ (w
->region_showing
,
12919 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12920 CHARPOS (this_line_start_pos
) = 0;
12922 /* Optimize the case that only the line containing the cursor in the
12923 selected window has changed. Variables starting with this_ are
12924 set in display_line and record information about the line
12925 containing the cursor. */
12926 tlbufpos
= this_line_start_pos
;
12927 tlendpos
= this_line_end_pos
;
12928 if (!consider_all_windows_p
12929 && CHARPOS (tlbufpos
) > 0
12930 && NILP (w
->update_mode_line
)
12931 && !current_buffer
->clip_changed
12932 && !current_buffer
->prevent_redisplay_optimizations_p
12933 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12934 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12935 /* Make sure recorded data applies to current buffer, etc. */
12936 && this_line_buffer
== current_buffer
12937 && current_buffer
== XBUFFER (w
->buffer
)
12938 && NILP (w
->force_start
)
12939 && NILP (w
->optional_new_start
)
12940 /* Point must be on the line that we have info recorded about. */
12941 && PT
>= CHARPOS (tlbufpos
)
12942 && PT
<= Z
- CHARPOS (tlendpos
)
12943 /* All text outside that line, including its final newline,
12944 must be unchanged. */
12945 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12946 CHARPOS (tlendpos
)))
12948 if (CHARPOS (tlbufpos
) > BEGV
12949 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12950 && (CHARPOS (tlbufpos
) == ZV
12951 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12952 /* Former continuation line has disappeared by becoming empty. */
12954 else if (XFASTINT (w
->last_modified
) < MODIFF
12955 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12956 || MINI_WINDOW_P (w
))
12958 /* We have to handle the case of continuation around a
12959 wide-column character (see the comment in indent.c around
12962 For instance, in the following case:
12964 -------- Insert --------
12965 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12966 J_I_ ==> J_I_ `^^' are cursors.
12970 As we have to redraw the line above, we cannot use this
12974 int line_height_before
= this_line_pixel_height
;
12976 /* Note that start_display will handle the case that the
12977 line starting at tlbufpos is a continuation line. */
12978 start_display (&it
, w
, tlbufpos
);
12980 /* Implementation note: It this still necessary? */
12981 if (it
.current_x
!= this_line_start_x
)
12984 TRACE ((stderr
, "trying display optimization 1\n"));
12985 w
->cursor
.vpos
= -1;
12986 overlay_arrow_seen
= 0;
12987 it
.vpos
= this_line_vpos
;
12988 it
.current_y
= this_line_y
;
12989 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12990 display_line (&it
);
12992 /* If line contains point, is not continued,
12993 and ends at same distance from eob as before, we win. */
12994 if (w
->cursor
.vpos
>= 0
12995 /* Line is not continued, otherwise this_line_start_pos
12996 would have been set to 0 in display_line. */
12997 && CHARPOS (this_line_start_pos
)
12998 /* Line ends as before. */
12999 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13000 /* Line has same height as before. Otherwise other lines
13001 would have to be shifted up or down. */
13002 && this_line_pixel_height
== line_height_before
)
13004 /* If this is not the window's last line, we must adjust
13005 the charstarts of the lines below. */
13006 if (it
.current_y
< it
.last_visible_y
)
13008 struct glyph_row
*row
13009 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13010 ptrdiff_t delta
, delta_bytes
;
13012 /* We used to distinguish between two cases here,
13013 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13014 when the line ends in a newline or the end of the
13015 buffer's accessible portion. But both cases did
13016 the same, so they were collapsed. */
13018 - CHARPOS (tlendpos
)
13019 - MATRIX_ROW_START_CHARPOS (row
));
13020 delta_bytes
= (Z_BYTE
13021 - BYTEPOS (tlendpos
)
13022 - MATRIX_ROW_START_BYTEPOS (row
));
13024 increment_matrix_positions (w
->current_matrix
,
13025 this_line_vpos
+ 1,
13026 w
->current_matrix
->nrows
,
13027 delta
, delta_bytes
);
13030 /* If this row displays text now but previously didn't,
13031 or vice versa, w->window_end_vpos may have to be
13033 if ((it
.glyph_row
- 1)->displays_text_p
)
13035 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13036 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13038 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13039 && this_line_vpos
> 0)
13040 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13041 w
->window_end_valid
= Qnil
;
13043 /* Update hint: No need to try to scroll in update_window. */
13044 w
->desired_matrix
->no_scrolling_p
= 1;
13047 *w
->desired_matrix
->method
= 0;
13048 debug_method_add (w
, "optimization 1");
13050 #ifdef HAVE_WINDOW_SYSTEM
13051 update_window_fringes (w
, 0);
13058 else if (/* Cursor position hasn't changed. */
13059 PT
== XFASTINT (w
->last_point
)
13060 /* Make sure the cursor was last displayed
13061 in this window. Otherwise we have to reposition it. */
13062 && 0 <= w
->cursor
.vpos
13063 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13067 do_pending_window_change (1);
13068 /* If selected_window changed, redisplay again. */
13069 if (WINDOWP (selected_window
)
13070 && (w
= XWINDOW (selected_window
)) != sw
)
13073 /* We used to always goto end_of_redisplay here, but this
13074 isn't enough if we have a blinking cursor. */
13075 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13076 goto end_of_redisplay
;
13080 /* If highlighting the region, or if the cursor is in the echo area,
13081 then we can't just move the cursor. */
13082 else if (! (!NILP (Vtransient_mark_mode
)
13083 && !NILP (BVAR (current_buffer
, mark_active
)))
13084 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
13085 || highlight_nonselected_windows
)
13086 && NILP (w
->region_showing
)
13087 && NILP (Vshow_trailing_whitespace
)
13088 && !cursor_in_echo_area
)
13091 struct glyph_row
*row
;
13093 /* Skip from tlbufpos to PT and see where it is. Note that
13094 PT may be in invisible text. If so, we will end at the
13095 next visible position. */
13096 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13097 NULL
, DEFAULT_FACE_ID
);
13098 it
.current_x
= this_line_start_x
;
13099 it
.current_y
= this_line_y
;
13100 it
.vpos
= this_line_vpos
;
13102 /* The call to move_it_to stops in front of PT, but
13103 moves over before-strings. */
13104 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13106 if (it
.vpos
== this_line_vpos
13107 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13110 xassert (this_line_vpos
== it
.vpos
);
13111 xassert (this_line_y
== it
.current_y
);
13112 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13114 *w
->desired_matrix
->method
= 0;
13115 debug_method_add (w
, "optimization 3");
13124 /* Text changed drastically or point moved off of line. */
13125 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13128 CHARPOS (this_line_start_pos
) = 0;
13129 consider_all_windows_p
|= buffer_shared
> 1;
13130 ++clear_face_cache_count
;
13131 #ifdef HAVE_WINDOW_SYSTEM
13132 ++clear_image_cache_count
;
13135 /* Build desired matrices, and update the display. If
13136 consider_all_windows_p is non-zero, do it for all windows on all
13137 frames. Otherwise do it for selected_window, only. */
13139 if (consider_all_windows_p
)
13141 Lisp_Object tail
, frame
;
13143 FOR_EACH_FRAME (tail
, frame
)
13144 XFRAME (frame
)->updated_p
= 0;
13146 /* Recompute # windows showing selected buffer. This will be
13147 incremented each time such a window is displayed. */
13150 FOR_EACH_FRAME (tail
, frame
)
13152 struct frame
*f
= XFRAME (frame
);
13154 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13156 if (! EQ (frame
, selected_frame
))
13157 /* Select the frame, for the sake of frame-local
13159 select_frame_for_redisplay (frame
);
13161 /* Mark all the scroll bars to be removed; we'll redeem
13162 the ones we want when we redisplay their windows. */
13163 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13164 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13166 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13167 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13169 /* The X error handler may have deleted that frame. */
13170 if (!FRAME_LIVE_P (f
))
13173 /* Any scroll bars which redisplay_windows should have
13174 nuked should now go away. */
13175 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13176 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13178 /* If fonts changed, display again. */
13179 /* ??? rms: I suspect it is a mistake to jump all the way
13180 back to retry here. It should just retry this frame. */
13181 if (fonts_changed_p
)
13184 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13186 /* See if we have to hscroll. */
13187 if (!f
->already_hscrolled_p
)
13189 f
->already_hscrolled_p
= 1;
13190 if (hscroll_windows (f
->root_window
))
13194 /* Prevent various kinds of signals during display
13195 update. stdio is not robust about handling
13196 signals, which can cause an apparent I/O
13198 if (interrupt_input
)
13199 unrequest_sigio ();
13202 /* Update the display. */
13203 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13204 pending
|= update_frame (f
, 0, 0);
13210 if (!EQ (old_frame
, selected_frame
)
13211 && FRAME_LIVE_P (XFRAME (old_frame
)))
13212 /* We played a bit fast-and-loose above and allowed selected_frame
13213 and selected_window to be temporarily out-of-sync but let's make
13214 sure this stays contained. */
13215 select_frame_for_redisplay (old_frame
);
13216 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13220 /* Do the mark_window_display_accurate after all windows have
13221 been redisplayed because this call resets flags in buffers
13222 which are needed for proper redisplay. */
13223 FOR_EACH_FRAME (tail
, frame
)
13225 struct frame
*f
= XFRAME (frame
);
13228 mark_window_display_accurate (f
->root_window
, 1);
13229 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13230 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13235 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13237 Lisp_Object mini_window
;
13238 struct frame
*mini_frame
;
13240 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13241 /* Use list_of_error, not Qerror, so that
13242 we catch only errors and don't run the debugger. */
13243 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13245 redisplay_window_error
);
13247 /* Compare desired and current matrices, perform output. */
13250 /* If fonts changed, display again. */
13251 if (fonts_changed_p
)
13254 /* Prevent various kinds of signals during display update.
13255 stdio is not robust about handling signals,
13256 which can cause an apparent I/O error. */
13257 if (interrupt_input
)
13258 unrequest_sigio ();
13261 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13263 if (hscroll_windows (selected_window
))
13266 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13267 pending
= update_frame (sf
, 0, 0);
13270 /* We may have called echo_area_display at the top of this
13271 function. If the echo area is on another frame, that may
13272 have put text on a frame other than the selected one, so the
13273 above call to update_frame would not have caught it. Catch
13275 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13276 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13278 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13280 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13281 pending
|= update_frame (mini_frame
, 0, 0);
13282 if (!pending
&& hscroll_windows (mini_window
))
13287 /* If display was paused because of pending input, make sure we do a
13288 thorough update the next time. */
13291 /* Prevent the optimization at the beginning of
13292 redisplay_internal that tries a single-line update of the
13293 line containing the cursor in the selected window. */
13294 CHARPOS (this_line_start_pos
) = 0;
13296 /* Let the overlay arrow be updated the next time. */
13297 update_overlay_arrows (0);
13299 /* If we pause after scrolling, some rows in the current
13300 matrices of some windows are not valid. */
13301 if (!WINDOW_FULL_WIDTH_P (w
)
13302 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13303 update_mode_lines
= 1;
13307 if (!consider_all_windows_p
)
13309 /* This has already been done above if
13310 consider_all_windows_p is set. */
13311 mark_window_display_accurate_1 (w
, 1);
13313 /* Say overlay arrows are up to date. */
13314 update_overlay_arrows (1);
13316 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13317 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13320 update_mode_lines
= 0;
13321 windows_or_buffers_changed
= 0;
13322 cursor_type_changed
= 0;
13325 /* Start SIGIO interrupts coming again. Having them off during the
13326 code above makes it less likely one will discard output, but not
13327 impossible, since there might be stuff in the system buffer here.
13328 But it is much hairier to try to do anything about that. */
13329 if (interrupt_input
)
13333 /* If a frame has become visible which was not before, redisplay
13334 again, so that we display it. Expose events for such a frame
13335 (which it gets when becoming visible) don't call the parts of
13336 redisplay constructing glyphs, so simply exposing a frame won't
13337 display anything in this case. So, we have to display these
13338 frames here explicitly. */
13341 Lisp_Object tail
, frame
;
13344 FOR_EACH_FRAME (tail
, frame
)
13346 int this_is_visible
= 0;
13348 if (XFRAME (frame
)->visible
)
13349 this_is_visible
= 1;
13350 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13351 if (XFRAME (frame
)->visible
)
13352 this_is_visible
= 1;
13354 if (this_is_visible
)
13358 if (new_count
!= number_of_visible_frames
)
13359 windows_or_buffers_changed
++;
13362 /* Change frame size now if a change is pending. */
13363 do_pending_window_change (1);
13365 /* If we just did a pending size change, or have additional
13366 visible frames, or selected_window changed, redisplay again. */
13367 if ((windows_or_buffers_changed
&& !pending
)
13368 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13371 /* Clear the face and image caches.
13373 We used to do this only if consider_all_windows_p. But the cache
13374 needs to be cleared if a timer creates images in the current
13375 buffer (e.g. the test case in Bug#6230). */
13377 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13379 clear_face_cache (0);
13380 clear_face_cache_count
= 0;
13383 #ifdef HAVE_WINDOW_SYSTEM
13384 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13386 clear_image_caches (Qnil
);
13387 clear_image_cache_count
= 0;
13389 #endif /* HAVE_WINDOW_SYSTEM */
13392 unbind_to (count
, Qnil
);
13397 /* Redisplay, but leave alone any recent echo area message unless
13398 another message has been requested in its place.
13400 This is useful in situations where you need to redisplay but no
13401 user action has occurred, making it inappropriate for the message
13402 area to be cleared. See tracking_off and
13403 wait_reading_process_output for examples of these situations.
13405 FROM_WHERE is an integer saying from where this function was
13406 called. This is useful for debugging. */
13409 redisplay_preserve_echo_area (int from_where
)
13411 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13413 if (!NILP (echo_area_buffer
[1]))
13415 /* We have a previously displayed message, but no current
13416 message. Redisplay the previous message. */
13417 display_last_displayed_message_p
= 1;
13418 redisplay_internal ();
13419 display_last_displayed_message_p
= 0;
13422 redisplay_internal ();
13424 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13425 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13426 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13430 /* Function registered with record_unwind_protect in
13431 redisplay_internal. Reset redisplaying_p to the value it had
13432 before redisplay_internal was called, and clear
13433 prevent_freeing_realized_faces_p. It also selects the previously
13434 selected frame, unless it has been deleted (by an X connection
13435 failure during redisplay, for example). */
13438 unwind_redisplay (Lisp_Object val
)
13440 Lisp_Object old_redisplaying_p
, old_frame
;
13442 old_redisplaying_p
= XCAR (val
);
13443 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13444 old_frame
= XCDR (val
);
13445 if (! EQ (old_frame
, selected_frame
)
13446 && FRAME_LIVE_P (XFRAME (old_frame
)))
13447 select_frame_for_redisplay (old_frame
);
13452 /* Mark the display of window W as accurate or inaccurate. If
13453 ACCURATE_P is non-zero mark display of W as accurate. If
13454 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13455 redisplay_internal is called. */
13458 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13460 if (BUFFERP (w
->buffer
))
13462 struct buffer
*b
= XBUFFER (w
->buffer
);
13465 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
13466 w
->last_overlay_modified
13467 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
13469 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
13473 b
->clip_changed
= 0;
13474 b
->prevent_redisplay_optimizations_p
= 0;
13476 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13477 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13478 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13479 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13481 w
->current_matrix
->buffer
= b
;
13482 w
->current_matrix
->begv
= BUF_BEGV (b
);
13483 w
->current_matrix
->zv
= BUF_ZV (b
);
13485 w
->last_cursor
= w
->cursor
;
13486 w
->last_cursor_off_p
= w
->cursor_off_p
;
13488 if (w
== XWINDOW (selected_window
))
13489 w
->last_point
= make_number (BUF_PT (b
));
13491 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
13497 w
->window_end_valid
= w
->buffer
;
13498 w
->update_mode_line
= Qnil
;
13503 /* Mark the display of windows in the window tree rooted at WINDOW as
13504 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13505 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13506 be redisplayed the next time redisplay_internal is called. */
13509 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13513 for (; !NILP (window
); window
= w
->next
)
13515 w
= XWINDOW (window
);
13516 mark_window_display_accurate_1 (w
, accurate_p
);
13518 if (!NILP (w
->vchild
))
13519 mark_window_display_accurate (w
->vchild
, accurate_p
);
13520 if (!NILP (w
->hchild
))
13521 mark_window_display_accurate (w
->hchild
, accurate_p
);
13526 update_overlay_arrows (1);
13530 /* Force a thorough redisplay the next time by setting
13531 last_arrow_position and last_arrow_string to t, which is
13532 unequal to any useful value of Voverlay_arrow_... */
13533 update_overlay_arrows (-1);
13538 /* Return value in display table DP (Lisp_Char_Table *) for character
13539 C. Since a display table doesn't have any parent, we don't have to
13540 follow parent. Do not call this function directly but use the
13541 macro DISP_CHAR_VECTOR. */
13544 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13548 if (ASCII_CHAR_P (c
))
13551 if (SUB_CHAR_TABLE_P (val
))
13552 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13558 XSETCHAR_TABLE (table
, dp
);
13559 val
= char_table_ref (table
, c
);
13568 /***********************************************************************
13570 ***********************************************************************/
13572 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13575 redisplay_windows (Lisp_Object window
)
13577 while (!NILP (window
))
13579 struct window
*w
= XWINDOW (window
);
13581 if (!NILP (w
->hchild
))
13582 redisplay_windows (w
->hchild
);
13583 else if (!NILP (w
->vchild
))
13584 redisplay_windows (w
->vchild
);
13585 else if (!NILP (w
->buffer
))
13587 displayed_buffer
= XBUFFER (w
->buffer
);
13588 /* Use list_of_error, not Qerror, so that
13589 we catch only errors and don't run the debugger. */
13590 internal_condition_case_1 (redisplay_window_0
, window
,
13592 redisplay_window_error
);
13600 redisplay_window_error (Lisp_Object ignore
)
13602 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13607 redisplay_window_0 (Lisp_Object window
)
13609 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13610 redisplay_window (window
, 0);
13615 redisplay_window_1 (Lisp_Object window
)
13617 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13618 redisplay_window (window
, 1);
13623 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13624 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13625 which positions recorded in ROW differ from current buffer
13628 Return 0 if cursor is not on this row, 1 otherwise. */
13631 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13632 struct glyph_matrix
*matrix
,
13633 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13636 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13637 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13638 struct glyph
*cursor
= NULL
;
13639 /* The last known character position in row. */
13640 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13642 ptrdiff_t pt_old
= PT
- delta
;
13643 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13644 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13645 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13646 /* A glyph beyond the edge of TEXT_AREA which we should never
13648 struct glyph
*glyphs_end
= end
;
13649 /* Non-zero means we've found a match for cursor position, but that
13650 glyph has the avoid_cursor_p flag set. */
13651 int match_with_avoid_cursor
= 0;
13652 /* Non-zero means we've seen at least one glyph that came from a
13654 int string_seen
= 0;
13655 /* Largest and smallest buffer positions seen so far during scan of
13657 ptrdiff_t bpos_max
= pos_before
;
13658 ptrdiff_t bpos_min
= pos_after
;
13659 /* Last buffer position covered by an overlay string with an integer
13660 `cursor' property. */
13661 ptrdiff_t bpos_covered
= 0;
13662 /* Non-zero means the display string on which to display the cursor
13663 comes from a text property, not from an overlay. */
13664 int string_from_text_prop
= 0;
13666 /* Skip over glyphs not having an object at the start and the end of
13667 the row. These are special glyphs like truncation marks on
13668 terminal frames. */
13669 if (row
->displays_text_p
)
13671 if (!row
->reversed_p
)
13674 && INTEGERP (glyph
->object
)
13675 && glyph
->charpos
< 0)
13677 x
+= glyph
->pixel_width
;
13681 && INTEGERP ((end
- 1)->object
)
13682 /* CHARPOS is zero for blanks and stretch glyphs
13683 inserted by extend_face_to_end_of_line. */
13684 && (end
- 1)->charpos
<= 0)
13686 glyph_before
= glyph
- 1;
13693 /* If the glyph row is reversed, we need to process it from back
13694 to front, so swap the edge pointers. */
13695 glyphs_end
= end
= glyph
- 1;
13696 glyph
+= row
->used
[TEXT_AREA
] - 1;
13698 while (glyph
> end
+ 1
13699 && INTEGERP (glyph
->object
)
13700 && glyph
->charpos
< 0)
13703 x
-= glyph
->pixel_width
;
13705 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13707 /* By default, in reversed rows we put the cursor on the
13708 rightmost (first in the reading order) glyph. */
13709 for (g
= end
+ 1; g
< glyph
; g
++)
13710 x
+= g
->pixel_width
;
13712 && INTEGERP ((end
+ 1)->object
)
13713 && (end
+ 1)->charpos
<= 0)
13715 glyph_before
= glyph
+ 1;
13719 else if (row
->reversed_p
)
13721 /* In R2L rows that don't display text, put the cursor on the
13722 rightmost glyph. Case in point: an empty last line that is
13723 part of an R2L paragraph. */
13725 /* Avoid placing the cursor on the last glyph of the row, where
13726 on terminal frames we hold the vertical border between
13727 adjacent windows. */
13728 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13729 && !WINDOW_RIGHTMOST_P (w
)
13730 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13732 x
= -1; /* will be computed below, at label compute_x */
13735 /* Step 1: Try to find the glyph whose character position
13736 corresponds to point. If that's not possible, find 2 glyphs
13737 whose character positions are the closest to point, one before
13738 point, the other after it. */
13739 if (!row
->reversed_p
)
13740 while (/* not marched to end of glyph row */
13742 /* glyph was not inserted by redisplay for internal purposes */
13743 && !INTEGERP (glyph
->object
))
13745 if (BUFFERP (glyph
->object
))
13747 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13749 if (glyph
->charpos
> bpos_max
)
13750 bpos_max
= glyph
->charpos
;
13751 if (glyph
->charpos
< bpos_min
)
13752 bpos_min
= glyph
->charpos
;
13753 if (!glyph
->avoid_cursor_p
)
13755 /* If we hit point, we've found the glyph on which to
13756 display the cursor. */
13759 match_with_avoid_cursor
= 0;
13762 /* See if we've found a better approximation to
13763 POS_BEFORE or to POS_AFTER. Note that we want the
13764 first (leftmost) glyph of all those that are the
13765 closest from below, and the last (rightmost) of all
13766 those from above. */
13767 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13769 pos_before
= glyph
->charpos
;
13770 glyph_before
= glyph
;
13772 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13774 pos_after
= glyph
->charpos
;
13775 glyph_after
= glyph
;
13778 else if (dpos
== 0)
13779 match_with_avoid_cursor
= 1;
13781 else if (STRINGP (glyph
->object
))
13783 Lisp_Object chprop
;
13784 ptrdiff_t glyph_pos
= glyph
->charpos
;
13786 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13788 if (INTEGERP (chprop
))
13790 bpos_covered
= bpos_max
+ XINT (chprop
);
13791 /* If the `cursor' property covers buffer positions up
13792 to and including point, we should display cursor on
13793 this glyph. Note that overlays and text properties
13794 with string values stop bidi reordering, so every
13795 buffer position to the left of the string is always
13796 smaller than any position to the right of the
13797 string. Therefore, if a `cursor' property on one
13798 of the string's characters has an integer value, we
13799 will break out of the loop below _before_ we get to
13800 the position match above. IOW, integer values of
13801 the `cursor' property override the "exact match for
13802 point" strategy of positioning the cursor. */
13803 /* Implementation note: bpos_max == pt_old when, e.g.,
13804 we are in an empty line, where bpos_max is set to
13805 MATRIX_ROW_START_CHARPOS, see above. */
13806 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13815 x
+= glyph
->pixel_width
;
13818 else if (glyph
> end
) /* row is reversed */
13819 while (!INTEGERP (glyph
->object
))
13821 if (BUFFERP (glyph
->object
))
13823 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13825 if (glyph
->charpos
> bpos_max
)
13826 bpos_max
= glyph
->charpos
;
13827 if (glyph
->charpos
< bpos_min
)
13828 bpos_min
= glyph
->charpos
;
13829 if (!glyph
->avoid_cursor_p
)
13833 match_with_avoid_cursor
= 0;
13836 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13838 pos_before
= glyph
->charpos
;
13839 glyph_before
= glyph
;
13841 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13843 pos_after
= glyph
->charpos
;
13844 glyph_after
= glyph
;
13847 else if (dpos
== 0)
13848 match_with_avoid_cursor
= 1;
13850 else if (STRINGP (glyph
->object
))
13852 Lisp_Object chprop
;
13853 ptrdiff_t glyph_pos
= glyph
->charpos
;
13855 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13857 if (INTEGERP (chprop
))
13859 bpos_covered
= bpos_max
+ XINT (chprop
);
13860 /* If the `cursor' property covers buffer positions up
13861 to and including point, we should display cursor on
13863 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13872 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13874 x
--; /* can't use any pixel_width */
13877 x
-= glyph
->pixel_width
;
13880 /* Step 2: If we didn't find an exact match for point, we need to
13881 look for a proper place to put the cursor among glyphs between
13882 GLYPH_BEFORE and GLYPH_AFTER. */
13883 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13884 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13885 && bpos_covered
< pt_old
)
13887 /* An empty line has a single glyph whose OBJECT is zero and
13888 whose CHARPOS is the position of a newline on that line.
13889 Note that on a TTY, there are more glyphs after that, which
13890 were produced by extend_face_to_end_of_line, but their
13891 CHARPOS is zero or negative. */
13893 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13894 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13896 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13898 ptrdiff_t ellipsis_pos
;
13900 /* Scan back over the ellipsis glyphs. */
13901 if (!row
->reversed_p
)
13903 ellipsis_pos
= (glyph
- 1)->charpos
;
13904 while (glyph
> row
->glyphs
[TEXT_AREA
]
13905 && (glyph
- 1)->charpos
== ellipsis_pos
)
13906 glyph
--, x
-= glyph
->pixel_width
;
13907 /* That loop always goes one position too far, including
13908 the glyph before the ellipsis. So scan forward over
13910 x
+= glyph
->pixel_width
;
13913 else /* row is reversed */
13915 ellipsis_pos
= (glyph
+ 1)->charpos
;
13916 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13917 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13918 glyph
++, x
+= glyph
->pixel_width
;
13919 x
-= glyph
->pixel_width
;
13923 else if (match_with_avoid_cursor
)
13925 cursor
= glyph_after
;
13928 else if (string_seen
)
13930 int incr
= row
->reversed_p
? -1 : +1;
13932 /* Need to find the glyph that came out of a string which is
13933 present at point. That glyph is somewhere between
13934 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13935 positioned between POS_BEFORE and POS_AFTER in the
13937 struct glyph
*start
, *stop
;
13938 ptrdiff_t pos
= pos_before
;
13942 /* If the row ends in a newline from a display string,
13943 reordering could have moved the glyphs belonging to the
13944 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
13945 in this case we extend the search to the last glyph in
13946 the row that was not inserted by redisplay. */
13947 if (row
->ends_in_newline_from_string_p
)
13950 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13953 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13954 correspond to POS_BEFORE and POS_AFTER, respectively. We
13955 need START and STOP in the order that corresponds to the
13956 row's direction as given by its reversed_p flag. If the
13957 directionality of characters between POS_BEFORE and
13958 POS_AFTER is the opposite of the row's base direction,
13959 these characters will have been reordered for display,
13960 and we need to reverse START and STOP. */
13961 if (!row
->reversed_p
)
13963 start
= min (glyph_before
, glyph_after
);
13964 stop
= max (glyph_before
, glyph_after
);
13968 start
= max (glyph_before
, glyph_after
);
13969 stop
= min (glyph_before
, glyph_after
);
13971 for (glyph
= start
+ incr
;
13972 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13975 /* Any glyphs that come from the buffer are here because
13976 of bidi reordering. Skip them, and only pay
13977 attention to glyphs that came from some string. */
13978 if (STRINGP (glyph
->object
))
13982 /* If the display property covers the newline, we
13983 need to search for it one position farther. */
13984 ptrdiff_t lim
= pos_after
13985 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
13987 string_from_text_prop
= 0;
13988 str
= glyph
->object
;
13989 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
13990 if (tem
== 0 /* from overlay */
13993 /* If the string from which this glyph came is
13994 found in the buffer at point, then we've
13995 found the glyph we've been looking for. If
13996 it comes from an overlay (tem == 0), and it
13997 has the `cursor' property on one of its
13998 glyphs, record that glyph as a candidate for
13999 displaying the cursor. (As in the
14000 unidirectional version, we will display the
14001 cursor on the last candidate we find.) */
14002 if (tem
== 0 || tem
== pt_old
)
14004 /* The glyphs from this string could have
14005 been reordered. Find the one with the
14006 smallest string position. Or there could
14007 be a character in the string with the
14008 `cursor' property, which means display
14009 cursor on that character's glyph. */
14010 ptrdiff_t strpos
= glyph
->charpos
;
14015 string_from_text_prop
= 1;
14018 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14019 && EQ (glyph
->object
, str
);
14023 ptrdiff_t gpos
= glyph
->charpos
;
14025 cprop
= Fget_char_property (make_number (gpos
),
14033 if (tem
&& glyph
->charpos
< strpos
)
14035 strpos
= glyph
->charpos
;
14044 pos
= tem
+ 1; /* don't find previous instances */
14046 /* This string is not what we want; skip all of the
14047 glyphs that came from it. */
14048 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14049 && EQ (glyph
->object
, str
))
14056 /* If we reached the end of the line, and END was from a string,
14057 the cursor is not on this line. */
14059 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14060 && STRINGP (end
->object
)
14061 && row
->continued_p
)
14064 /* A truncated row may not include PT among its character positions.
14065 Setting the cursor inside the scroll margin will trigger
14066 recalculation of hscroll in hscroll_window_tree. But if a
14067 display string covers point, defer to the string-handling
14068 code below to figure this out. */
14069 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14071 cursor
= glyph_before
;
14074 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14075 /* Zero-width characters produce no glyphs. */
14077 && (row
->reversed_p
14078 ? glyph_after
> glyphs_end
14079 : glyph_after
< glyphs_end
)))
14081 cursor
= glyph_after
;
14087 if (cursor
!= NULL
)
14093 /* Need to compute x that corresponds to GLYPH. */
14094 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14096 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14098 x
+= g
->pixel_width
;
14102 /* ROW could be part of a continued line, which, under bidi
14103 reordering, might have other rows whose start and end charpos
14104 occlude point. Only set w->cursor if we found a better
14105 approximation to the cursor position than we have from previously
14106 examined candidate rows belonging to the same continued line. */
14107 if (/* we already have a candidate row */
14108 w
->cursor
.vpos
>= 0
14109 /* that candidate is not the row we are processing */
14110 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14111 /* Make sure cursor.vpos specifies a row whose start and end
14112 charpos occlude point, and it is valid candidate for being a
14113 cursor-row. This is because some callers of this function
14114 leave cursor.vpos at the row where the cursor was displayed
14115 during the last redisplay cycle. */
14116 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14117 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14118 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14121 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14123 /* Don't consider glyphs that are outside TEXT_AREA. */
14124 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14126 /* Keep the candidate whose buffer position is the closest to
14127 point or has the `cursor' property. */
14128 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14129 w
->cursor
.hpos
>= 0
14130 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14131 && ((BUFFERP (g1
->object
)
14132 && (g1
->charpos
== pt_old
/* an exact match always wins */
14133 || (BUFFERP (glyph
->object
)
14134 && eabs (g1
->charpos
- pt_old
)
14135 < eabs (glyph
->charpos
- pt_old
))))
14136 /* previous candidate is a glyph from a string that has
14137 a non-nil `cursor' property */
14138 || (STRINGP (g1
->object
)
14139 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14140 Qcursor
, g1
->object
))
14141 /* previous candidate is from the same display
14142 string as this one, and the display string
14143 came from a text property */
14144 || (EQ (g1
->object
, glyph
->object
)
14145 && string_from_text_prop
)
14146 /* this candidate is from newline and its
14147 position is not an exact match */
14148 || (INTEGERP (glyph
->object
)
14149 && glyph
->charpos
!= pt_old
)))))
14151 /* If this candidate gives an exact match, use that. */
14152 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14153 /* If this candidate is a glyph created for the
14154 terminating newline of a line, and point is on that
14155 newline, it wins because it's an exact match. */
14156 || (!row
->continued_p
14157 && INTEGERP (glyph
->object
)
14158 && glyph
->charpos
== 0
14159 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14160 /* Otherwise, keep the candidate that comes from a row
14161 spanning less buffer positions. This may win when one or
14162 both candidate positions are on glyphs that came from
14163 display strings, for which we cannot compare buffer
14165 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14166 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14167 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14170 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14172 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14173 w
->cursor
.y
= row
->y
+ dy
;
14175 if (w
== XWINDOW (selected_window
))
14177 if (!row
->continued_p
14178 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14181 this_line_buffer
= XBUFFER (w
->buffer
);
14183 CHARPOS (this_line_start_pos
)
14184 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14185 BYTEPOS (this_line_start_pos
)
14186 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14188 CHARPOS (this_line_end_pos
)
14189 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14190 BYTEPOS (this_line_end_pos
)
14191 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14193 this_line_y
= w
->cursor
.y
;
14194 this_line_pixel_height
= row
->height
;
14195 this_line_vpos
= w
->cursor
.vpos
;
14196 this_line_start_x
= row
->x
;
14199 CHARPOS (this_line_start_pos
) = 0;
14206 /* Run window scroll functions, if any, for WINDOW with new window
14207 start STARTP. Sets the window start of WINDOW to that position.
14209 We assume that the window's buffer is really current. */
14211 static inline struct text_pos
14212 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14214 struct window
*w
= XWINDOW (window
);
14215 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14217 if (current_buffer
!= XBUFFER (w
->buffer
))
14220 if (!NILP (Vwindow_scroll_functions
))
14222 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14223 make_number (CHARPOS (startp
)));
14224 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14225 /* In case the hook functions switch buffers. */
14226 if (current_buffer
!= XBUFFER (w
->buffer
))
14227 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14234 /* Make sure the line containing the cursor is fully visible.
14235 A value of 1 means there is nothing to be done.
14236 (Either the line is fully visible, or it cannot be made so,
14237 or we cannot tell.)
14239 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14240 is higher than window.
14242 A value of 0 means the caller should do scrolling
14243 as if point had gone off the screen. */
14246 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14248 struct glyph_matrix
*matrix
;
14249 struct glyph_row
*row
;
14252 if (!make_cursor_line_fully_visible_p
)
14255 /* It's not always possible to find the cursor, e.g, when a window
14256 is full of overlay strings. Don't do anything in that case. */
14257 if (w
->cursor
.vpos
< 0)
14260 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14261 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14263 /* If the cursor row is not partially visible, there's nothing to do. */
14264 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14267 /* If the row the cursor is in is taller than the window's height,
14268 it's not clear what to do, so do nothing. */
14269 window_height
= window_box_height (w
);
14270 if (row
->height
>= window_height
)
14272 if (!force_p
|| MINI_WINDOW_P (w
)
14273 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14280 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14281 non-zero means only WINDOW is redisplayed in redisplay_internal.
14282 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14283 in redisplay_window to bring a partially visible line into view in
14284 the case that only the cursor has moved.
14286 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14287 last screen line's vertical height extends past the end of the screen.
14291 1 if scrolling succeeded
14293 0 if scrolling didn't find point.
14295 -1 if new fonts have been loaded so that we must interrupt
14296 redisplay, adjust glyph matrices, and try again. */
14302 SCROLLING_NEED_LARGER_MATRICES
14305 /* If scroll-conservatively is more than this, never recenter.
14307 If you change this, don't forget to update the doc string of
14308 `scroll-conservatively' and the Emacs manual. */
14309 #define SCROLL_LIMIT 100
14312 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14313 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14314 int temp_scroll_step
, int last_line_misfit
)
14316 struct window
*w
= XWINDOW (window
);
14317 struct frame
*f
= XFRAME (w
->frame
);
14318 struct text_pos pos
, startp
;
14320 int this_scroll_margin
, scroll_max
, rc
, height
;
14321 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14322 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14323 Lisp_Object aggressive
;
14324 /* We will never try scrolling more than this number of lines. */
14325 int scroll_limit
= SCROLL_LIMIT
;
14328 debug_method_add (w
, "try_scrolling");
14331 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14333 /* Compute scroll margin height in pixels. We scroll when point is
14334 within this distance from the top or bottom of the window. */
14335 if (scroll_margin
> 0)
14336 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14337 * FRAME_LINE_HEIGHT (f
);
14339 this_scroll_margin
= 0;
14341 /* Force arg_scroll_conservatively to have a reasonable value, to
14342 avoid scrolling too far away with slow move_it_* functions. Note
14343 that the user can supply scroll-conservatively equal to
14344 `most-positive-fixnum', which can be larger than INT_MAX. */
14345 if (arg_scroll_conservatively
> scroll_limit
)
14347 arg_scroll_conservatively
= scroll_limit
+ 1;
14348 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14350 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14351 /* Compute how much we should try to scroll maximally to bring
14352 point into view. */
14353 scroll_max
= (max (scroll_step
,
14354 max (arg_scroll_conservatively
, temp_scroll_step
))
14355 * FRAME_LINE_HEIGHT (f
));
14356 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14357 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14358 /* We're trying to scroll because of aggressive scrolling but no
14359 scroll_step is set. Choose an arbitrary one. */
14360 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14366 /* Decide whether to scroll down. */
14367 if (PT
> CHARPOS (startp
))
14369 int scroll_margin_y
;
14371 /* Compute the pixel ypos of the scroll margin, then move IT to
14372 either that ypos or PT, whichever comes first. */
14373 start_display (&it
, w
, startp
);
14374 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14375 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14376 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14377 (MOVE_TO_POS
| MOVE_TO_Y
));
14379 if (PT
> CHARPOS (it
.current
.pos
))
14381 int y0
= line_bottom_y (&it
);
14382 /* Compute how many pixels below window bottom to stop searching
14383 for PT. This avoids costly search for PT that is far away if
14384 the user limited scrolling by a small number of lines, but
14385 always finds PT if scroll_conservatively is set to a large
14386 number, such as most-positive-fixnum. */
14387 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14388 int y_to_move
= it
.last_visible_y
+ slack
;
14390 /* Compute the distance from the scroll margin to PT or to
14391 the scroll limit, whichever comes first. This should
14392 include the height of the cursor line, to make that line
14394 move_it_to (&it
, PT
, -1, y_to_move
,
14395 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14396 dy
= line_bottom_y (&it
) - y0
;
14398 if (dy
> scroll_max
)
14399 return SCROLLING_FAILED
;
14408 /* Point is in or below the bottom scroll margin, so move the
14409 window start down. If scrolling conservatively, move it just
14410 enough down to make point visible. If scroll_step is set,
14411 move it down by scroll_step. */
14412 if (arg_scroll_conservatively
)
14414 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14415 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14416 else if (scroll_step
|| temp_scroll_step
)
14417 amount_to_scroll
= scroll_max
;
14420 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14421 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14422 if (NUMBERP (aggressive
))
14424 double float_amount
= XFLOATINT (aggressive
) * height
;
14425 amount_to_scroll
= float_amount
;
14426 if (amount_to_scroll
== 0 && float_amount
> 0)
14427 amount_to_scroll
= 1;
14428 /* Don't let point enter the scroll margin near top of
14430 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14431 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14435 if (amount_to_scroll
<= 0)
14436 return SCROLLING_FAILED
;
14438 start_display (&it
, w
, startp
);
14439 if (arg_scroll_conservatively
<= scroll_limit
)
14440 move_it_vertically (&it
, amount_to_scroll
);
14443 /* Extra precision for users who set scroll-conservatively
14444 to a large number: make sure the amount we scroll
14445 the window start is never less than amount_to_scroll,
14446 which was computed as distance from window bottom to
14447 point. This matters when lines at window top and lines
14448 below window bottom have different height. */
14450 void *it1data
= NULL
;
14451 /* We use a temporary it1 because line_bottom_y can modify
14452 its argument, if it moves one line down; see there. */
14455 SAVE_IT (it1
, it
, it1data
);
14456 start_y
= line_bottom_y (&it1
);
14458 RESTORE_IT (&it
, &it
, it1data
);
14459 move_it_by_lines (&it
, 1);
14460 SAVE_IT (it1
, it
, it1data
);
14461 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14464 /* If STARTP is unchanged, move it down another screen line. */
14465 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14466 move_it_by_lines (&it
, 1);
14467 startp
= it
.current
.pos
;
14471 struct text_pos scroll_margin_pos
= startp
;
14473 /* See if point is inside the scroll margin at the top of the
14475 if (this_scroll_margin
)
14477 start_display (&it
, w
, startp
);
14478 move_it_vertically (&it
, this_scroll_margin
);
14479 scroll_margin_pos
= it
.current
.pos
;
14482 if (PT
< CHARPOS (scroll_margin_pos
))
14484 /* Point is in the scroll margin at the top of the window or
14485 above what is displayed in the window. */
14488 /* Compute the vertical distance from PT to the scroll
14489 margin position. Move as far as scroll_max allows, or
14490 one screenful, or 10 screen lines, whichever is largest.
14491 Give up if distance is greater than scroll_max. */
14492 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14493 start_display (&it
, w
, pos
);
14495 y_to_move
= max (it
.last_visible_y
,
14496 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14497 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14499 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14500 dy
= it
.current_y
- y0
;
14501 if (dy
> scroll_max
)
14502 return SCROLLING_FAILED
;
14504 /* Compute new window start. */
14505 start_display (&it
, w
, startp
);
14507 if (arg_scroll_conservatively
)
14508 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14509 max (scroll_step
, temp_scroll_step
));
14510 else if (scroll_step
|| temp_scroll_step
)
14511 amount_to_scroll
= scroll_max
;
14514 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14515 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14516 if (NUMBERP (aggressive
))
14518 double float_amount
= XFLOATINT (aggressive
) * height
;
14519 amount_to_scroll
= float_amount
;
14520 if (amount_to_scroll
== 0 && float_amount
> 0)
14521 amount_to_scroll
= 1;
14522 amount_to_scroll
-=
14523 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14524 /* Don't let point enter the scroll margin near
14525 bottom of the window. */
14526 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14527 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14531 if (amount_to_scroll
<= 0)
14532 return SCROLLING_FAILED
;
14534 move_it_vertically_backward (&it
, amount_to_scroll
);
14535 startp
= it
.current
.pos
;
14539 /* Run window scroll functions. */
14540 startp
= run_window_scroll_functions (window
, startp
);
14542 /* Display the window. Give up if new fonts are loaded, or if point
14544 if (!try_window (window
, startp
, 0))
14545 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14546 else if (w
->cursor
.vpos
< 0)
14548 clear_glyph_matrix (w
->desired_matrix
);
14549 rc
= SCROLLING_FAILED
;
14553 /* Maybe forget recorded base line for line number display. */
14554 if (!just_this_one_p
14555 || current_buffer
->clip_changed
14556 || BEG_UNCHANGED
< CHARPOS (startp
))
14557 w
->base_line_number
= Qnil
;
14559 /* If cursor ends up on a partially visible line,
14560 treat that as being off the bottom of the screen. */
14561 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14562 /* It's possible that the cursor is on the first line of the
14563 buffer, which is partially obscured due to a vscroll
14564 (Bug#7537). In that case, avoid looping forever . */
14565 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14567 clear_glyph_matrix (w
->desired_matrix
);
14568 ++extra_scroll_margin_lines
;
14571 rc
= SCROLLING_SUCCESS
;
14578 /* Compute a suitable window start for window W if display of W starts
14579 on a continuation line. Value is non-zero if a new window start
14582 The new window start will be computed, based on W's width, starting
14583 from the start of the continued line. It is the start of the
14584 screen line with the minimum distance from the old start W->start. */
14587 compute_window_start_on_continuation_line (struct window
*w
)
14589 struct text_pos pos
, start_pos
;
14590 int window_start_changed_p
= 0;
14592 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14594 /* If window start is on a continuation line... Window start may be
14595 < BEGV in case there's invisible text at the start of the
14596 buffer (M-x rmail, for example). */
14597 if (CHARPOS (start_pos
) > BEGV
14598 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14601 struct glyph_row
*row
;
14603 /* Handle the case that the window start is out of range. */
14604 if (CHARPOS (start_pos
) < BEGV
)
14605 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14606 else if (CHARPOS (start_pos
) > ZV
)
14607 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14609 /* Find the start of the continued line. This should be fast
14610 because scan_buffer is fast (newline cache). */
14611 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14612 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14613 row
, DEFAULT_FACE_ID
);
14614 reseat_at_previous_visible_line_start (&it
);
14616 /* If the line start is "too far" away from the window start,
14617 say it takes too much time to compute a new window start. */
14618 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14619 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14621 int min_distance
, distance
;
14623 /* Move forward by display lines to find the new window
14624 start. If window width was enlarged, the new start can
14625 be expected to be > the old start. If window width was
14626 decreased, the new window start will be < the old start.
14627 So, we're looking for the display line start with the
14628 minimum distance from the old window start. */
14629 pos
= it
.current
.pos
;
14630 min_distance
= INFINITY
;
14631 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14632 distance
< min_distance
)
14634 min_distance
= distance
;
14635 pos
= it
.current
.pos
;
14636 move_it_by_lines (&it
, 1);
14639 /* Set the window start there. */
14640 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14641 window_start_changed_p
= 1;
14645 return window_start_changed_p
;
14649 /* Try cursor movement in case text has not changed in window WINDOW,
14650 with window start STARTP. Value is
14652 CURSOR_MOVEMENT_SUCCESS if successful
14654 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14656 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14657 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14658 we want to scroll as if scroll-step were set to 1. See the code.
14660 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14661 which case we have to abort this redisplay, and adjust matrices
14666 CURSOR_MOVEMENT_SUCCESS
,
14667 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14668 CURSOR_MOVEMENT_MUST_SCROLL
,
14669 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14673 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14675 struct window
*w
= XWINDOW (window
);
14676 struct frame
*f
= XFRAME (w
->frame
);
14677 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14680 if (inhibit_try_cursor_movement
)
14684 /* Handle case where text has not changed, only point, and it has
14685 not moved off the frame. */
14686 if (/* Point may be in this window. */
14687 PT
>= CHARPOS (startp
)
14688 /* Selective display hasn't changed. */
14689 && !current_buffer
->clip_changed
14690 /* Function force-mode-line-update is used to force a thorough
14691 redisplay. It sets either windows_or_buffers_changed or
14692 update_mode_lines. So don't take a shortcut here for these
14694 && !update_mode_lines
14695 && !windows_or_buffers_changed
14696 && !cursor_type_changed
14697 /* Can't use this case if highlighting a region. When a
14698 region exists, cursor movement has to do more than just
14700 && !(!NILP (Vtransient_mark_mode
)
14701 && !NILP (BVAR (current_buffer
, mark_active
)))
14702 && NILP (w
->region_showing
)
14703 && NILP (Vshow_trailing_whitespace
)
14704 /* Right after splitting windows, last_point may be nil. */
14705 && INTEGERP (w
->last_point
)
14706 /* This code is not used for mini-buffer for the sake of the case
14707 of redisplaying to replace an echo area message; since in
14708 that case the mini-buffer contents per se are usually
14709 unchanged. This code is of no real use in the mini-buffer
14710 since the handling of this_line_start_pos, etc., in redisplay
14711 handles the same cases. */
14712 && !EQ (window
, minibuf_window
)
14713 /* When splitting windows or for new windows, it happens that
14714 redisplay is called with a nil window_end_vpos or one being
14715 larger than the window. This should really be fixed in
14716 window.c. I don't have this on my list, now, so we do
14717 approximately the same as the old redisplay code. --gerd. */
14718 && INTEGERP (w
->window_end_vpos
)
14719 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14720 && (FRAME_WINDOW_P (f
)
14721 || !overlay_arrow_in_current_buffer_p ()))
14723 int this_scroll_margin
, top_scroll_margin
;
14724 struct glyph_row
*row
= NULL
;
14727 debug_method_add (w
, "cursor movement");
14730 /* Scroll if point within this distance from the top or bottom
14731 of the window. This is a pixel value. */
14732 if (scroll_margin
> 0)
14734 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14735 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14738 this_scroll_margin
= 0;
14740 top_scroll_margin
= this_scroll_margin
;
14741 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14742 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14744 /* Start with the row the cursor was displayed during the last
14745 not paused redisplay. Give up if that row is not valid. */
14746 if (w
->last_cursor
.vpos
< 0
14747 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14748 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14751 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14752 if (row
->mode_line_p
)
14754 if (!row
->enabled_p
)
14755 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14758 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14760 int scroll_p
= 0, must_scroll
= 0;
14761 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14763 if (PT
> XFASTINT (w
->last_point
))
14765 /* Point has moved forward. */
14766 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14767 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14769 xassert (row
->enabled_p
);
14773 /* If the end position of a row equals the start
14774 position of the next row, and PT is at that position,
14775 we would rather display cursor in the next line. */
14776 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14777 && MATRIX_ROW_END_CHARPOS (row
) == PT
14778 && row
< w
->current_matrix
->rows
14779 + w
->current_matrix
->nrows
- 1
14780 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14781 && !cursor_row_p (row
))
14784 /* If within the scroll margin, scroll. Note that
14785 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14786 the next line would be drawn, and that
14787 this_scroll_margin can be zero. */
14788 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14789 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14790 /* Line is completely visible last line in window
14791 and PT is to be set in the next line. */
14792 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14793 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14794 && !row
->ends_at_zv_p
14795 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14798 else if (PT
< XFASTINT (w
->last_point
))
14800 /* Cursor has to be moved backward. Note that PT >=
14801 CHARPOS (startp) because of the outer if-statement. */
14802 while (!row
->mode_line_p
14803 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14804 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14805 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14806 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14807 row
> w
->current_matrix
->rows
14808 && (row
-1)->ends_in_newline_from_string_p
))))
14809 && (row
->y
> top_scroll_margin
14810 || CHARPOS (startp
) == BEGV
))
14812 xassert (row
->enabled_p
);
14816 /* Consider the following case: Window starts at BEGV,
14817 there is invisible, intangible text at BEGV, so that
14818 display starts at some point START > BEGV. It can
14819 happen that we are called with PT somewhere between
14820 BEGV and START. Try to handle that case. */
14821 if (row
< w
->current_matrix
->rows
14822 || row
->mode_line_p
)
14824 row
= w
->current_matrix
->rows
;
14825 if (row
->mode_line_p
)
14829 /* Due to newlines in overlay strings, we may have to
14830 skip forward over overlay strings. */
14831 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14832 && MATRIX_ROW_END_CHARPOS (row
) == PT
14833 && !cursor_row_p (row
))
14836 /* If within the scroll margin, scroll. */
14837 if (row
->y
< top_scroll_margin
14838 && CHARPOS (startp
) != BEGV
)
14843 /* Cursor did not move. So don't scroll even if cursor line
14844 is partially visible, as it was so before. */
14845 rc
= CURSOR_MOVEMENT_SUCCESS
;
14848 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14849 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14851 /* if PT is not in the glyph row, give up. */
14852 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14855 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14856 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14858 /* If rows are bidi-reordered and point moved, back up
14859 until we find a row that does not belong to a
14860 continuation line. This is because we must consider
14861 all rows of a continued line as candidates for the
14862 new cursor positioning, since row start and end
14863 positions change non-linearly with vertical position
14865 /* FIXME: Revisit this when glyph ``spilling'' in
14866 continuation lines' rows is implemented for
14867 bidi-reordered rows. */
14868 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14870 /* If we hit the beginning of the displayed portion
14871 without finding the first row of a continued
14873 if (row
<= w
->current_matrix
->rows
)
14875 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14878 xassert (row
->enabled_p
);
14884 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14885 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14886 && make_cursor_line_fully_visible_p
)
14888 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14889 && !row
->ends_at_zv_p
14890 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14891 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14892 else if (row
->height
> window_box_height (w
))
14894 /* If we end up in a partially visible line, let's
14895 make it fully visible, except when it's taller
14896 than the window, in which case we can't do much
14899 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14903 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14904 if (!cursor_row_fully_visible_p (w
, 0, 1))
14905 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14907 rc
= CURSOR_MOVEMENT_SUCCESS
;
14911 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14912 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14913 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14915 /* With bidi-reordered rows, there could be more than
14916 one candidate row whose start and end positions
14917 occlude point. We need to let set_cursor_from_row
14918 find the best candidate. */
14919 /* FIXME: Revisit this when glyph ``spilling'' in
14920 continuation lines' rows is implemented for
14921 bidi-reordered rows. */
14926 int at_zv_p
= 0, exact_match_p
= 0;
14928 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14929 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14930 && cursor_row_p (row
))
14931 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14933 /* As soon as we've found the exact match for point,
14934 or the first suitable row whose ends_at_zv_p flag
14935 is set, we are done. */
14937 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
14939 && w
->cursor
.hpos
>= 0
14940 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
14943 struct glyph_row
*candidate
=
14944 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14946 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14947 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
14950 (BUFFERP (g
->object
) && g
->charpos
== PT
)
14951 || (INTEGERP (g
->object
)
14952 && (g
->charpos
== PT
14953 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
14955 if (rv
&& (at_zv_p
|| exact_match_p
))
14957 rc
= CURSOR_MOVEMENT_SUCCESS
;
14960 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
14964 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14965 || row
->continued_p
)
14966 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14967 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14968 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14969 /* If we didn't find any candidate rows, or exited the
14970 loop before all the candidates were examined, signal
14971 to the caller that this method failed. */
14972 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14974 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14975 && !row
->continued_p
))
14976 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14978 rc
= CURSOR_MOVEMENT_SUCCESS
;
14984 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14986 rc
= CURSOR_MOVEMENT_SUCCESS
;
14991 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14992 && MATRIX_ROW_START_CHARPOS (row
) == PT
14993 && cursor_row_p (row
));
15001 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15005 set_vertical_scroll_bar (struct window
*w
)
15007 ptrdiff_t start
, end
, whole
;
15009 /* Calculate the start and end positions for the current window.
15010 At some point, it would be nice to choose between scrollbars
15011 which reflect the whole buffer size, with special markers
15012 indicating narrowing, and scrollbars which reflect only the
15015 Note that mini-buffers sometimes aren't displaying any text. */
15016 if (!MINI_WINDOW_P (w
)
15017 || (w
== XWINDOW (minibuf_window
)
15018 && NILP (echo_area_buffer
[0])))
15020 struct buffer
*buf
= XBUFFER (w
->buffer
);
15021 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15022 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15023 /* I don't think this is guaranteed to be right. For the
15024 moment, we'll pretend it is. */
15025 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15029 if (whole
< (end
- start
))
15030 whole
= end
- start
;
15033 start
= end
= whole
= 0;
15035 /* Indicate what this scroll bar ought to be displaying now. */
15036 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15037 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15038 (w
, end
- start
, whole
, start
);
15042 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15043 selected_window is redisplayed.
15045 We can return without actually redisplaying the window if
15046 fonts_changed_p is nonzero. In that case, redisplay_internal will
15050 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15052 struct window
*w
= XWINDOW (window
);
15053 struct frame
*f
= XFRAME (w
->frame
);
15054 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15055 struct buffer
*old
= current_buffer
;
15056 struct text_pos lpoint
, opoint
, startp
;
15057 int update_mode_line
;
15060 /* Record it now because it's overwritten. */
15061 int current_matrix_up_to_date_p
= 0;
15062 int used_current_matrix_p
= 0;
15063 /* This is less strict than current_matrix_up_to_date_p.
15064 It indicates that the buffer contents and narrowing are unchanged. */
15065 int buffer_unchanged_p
= 0;
15066 int temp_scroll_step
= 0;
15067 ptrdiff_t count
= SPECPDL_INDEX ();
15069 int centering_position
= -1;
15070 int last_line_misfit
= 0;
15071 ptrdiff_t beg_unchanged
, end_unchanged
;
15073 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15076 /* W must be a leaf window here. */
15077 xassert (!NILP (w
->buffer
));
15079 *w
->desired_matrix
->method
= 0;
15083 reconsider_clip_changes (w
, buffer
);
15085 /* Has the mode line to be updated? */
15086 update_mode_line
= (!NILP (w
->update_mode_line
)
15087 || update_mode_lines
15088 || buffer
->clip_changed
15089 || buffer
->prevent_redisplay_optimizations_p
);
15091 if (MINI_WINDOW_P (w
))
15093 if (w
== XWINDOW (echo_area_window
)
15094 && !NILP (echo_area_buffer
[0]))
15096 if (update_mode_line
)
15097 /* We may have to update a tty frame's menu bar or a
15098 tool-bar. Example `M-x C-h C-h C-g'. */
15099 goto finish_menu_bars
;
15101 /* We've already displayed the echo area glyphs in this window. */
15102 goto finish_scroll_bars
;
15104 else if ((w
!= XWINDOW (minibuf_window
)
15105 || minibuf_level
== 0)
15106 /* When buffer is nonempty, redisplay window normally. */
15107 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15108 /* Quail displays non-mini buffers in minibuffer window.
15109 In that case, redisplay the window normally. */
15110 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15112 /* W is a mini-buffer window, but it's not active, so clear
15114 int yb
= window_text_bottom_y (w
);
15115 struct glyph_row
*row
;
15118 for (y
= 0, row
= w
->desired_matrix
->rows
;
15120 y
+= row
->height
, ++row
)
15121 blank_row (w
, row
, y
);
15122 goto finish_scroll_bars
;
15125 clear_glyph_matrix (w
->desired_matrix
);
15128 /* Otherwise set up data on this window; select its buffer and point
15130 /* Really select the buffer, for the sake of buffer-local
15132 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15134 current_matrix_up_to_date_p
15135 = (!NILP (w
->window_end_valid
)
15136 && !current_buffer
->clip_changed
15137 && !current_buffer
->prevent_redisplay_optimizations_p
15138 && XFASTINT (w
->last_modified
) >= MODIFF
15139 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15141 /* Run the window-bottom-change-functions
15142 if it is possible that the text on the screen has changed
15143 (either due to modification of the text, or any other reason). */
15144 if (!current_matrix_up_to_date_p
15145 && !NILP (Vwindow_text_change_functions
))
15147 safe_run_hooks (Qwindow_text_change_functions
);
15151 beg_unchanged
= BEG_UNCHANGED
;
15152 end_unchanged
= END_UNCHANGED
;
15154 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15156 specbind (Qinhibit_point_motion_hooks
, Qt
);
15159 = (!NILP (w
->window_end_valid
)
15160 && !current_buffer
->clip_changed
15161 && XFASTINT (w
->last_modified
) >= MODIFF
15162 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15164 /* When windows_or_buffers_changed is non-zero, we can't rely on
15165 the window end being valid, so set it to nil there. */
15166 if (windows_or_buffers_changed
)
15168 /* If window starts on a continuation line, maybe adjust the
15169 window start in case the window's width changed. */
15170 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15171 compute_window_start_on_continuation_line (w
);
15173 w
->window_end_valid
= Qnil
;
15176 /* Some sanity checks. */
15177 CHECK_WINDOW_END (w
);
15178 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15180 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15183 /* If %c is in mode line, update it if needed. */
15184 if (!NILP (w
->column_number_displayed
)
15185 /* This alternative quickly identifies a common case
15186 where no change is needed. */
15187 && !(PT
== XFASTINT (w
->last_point
)
15188 && XFASTINT (w
->last_modified
) >= MODIFF
15189 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
15190 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15191 update_mode_line
= 1;
15193 /* Count number of windows showing the selected buffer. An indirect
15194 buffer counts as its base buffer. */
15195 if (!just_this_one_p
)
15197 struct buffer
*current_base
, *window_base
;
15198 current_base
= current_buffer
;
15199 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15200 if (current_base
->base_buffer
)
15201 current_base
= current_base
->base_buffer
;
15202 if (window_base
->base_buffer
)
15203 window_base
= window_base
->base_buffer
;
15204 if (current_base
== window_base
)
15208 /* Point refers normally to the selected window. For any other
15209 window, set up appropriate value. */
15210 if (!EQ (window
, selected_window
))
15212 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15213 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15217 new_pt_byte
= BEGV_BYTE
;
15218 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15220 else if (new_pt
> (ZV
- 1))
15223 new_pt_byte
= ZV_BYTE
;
15224 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15227 /* We don't use SET_PT so that the point-motion hooks don't run. */
15228 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15231 /* If any of the character widths specified in the display table
15232 have changed, invalidate the width run cache. It's true that
15233 this may be a bit late to catch such changes, but the rest of
15234 redisplay goes (non-fatally) haywire when the display table is
15235 changed, so why should we worry about doing any better? */
15236 if (current_buffer
->width_run_cache
)
15238 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15240 if (! disptab_matches_widthtab (disptab
,
15241 XVECTOR (BVAR (current_buffer
, width_table
))))
15243 invalidate_region_cache (current_buffer
,
15244 current_buffer
->width_run_cache
,
15246 recompute_width_table (current_buffer
, disptab
);
15250 /* If window-start is screwed up, choose a new one. */
15251 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15254 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15256 /* If someone specified a new starting point but did not insist,
15257 check whether it can be used. */
15258 if (!NILP (w
->optional_new_start
)
15259 && CHARPOS (startp
) >= BEGV
15260 && CHARPOS (startp
) <= ZV
)
15262 w
->optional_new_start
= Qnil
;
15263 start_display (&it
, w
, startp
);
15264 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15265 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15266 if (IT_CHARPOS (it
) == PT
)
15267 w
->force_start
= Qt
;
15268 /* IT may overshoot PT if text at PT is invisible. */
15269 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15270 w
->force_start
= Qt
;
15275 /* Handle case where place to start displaying has been specified,
15276 unless the specified location is outside the accessible range. */
15277 if (!NILP (w
->force_start
)
15278 || w
->frozen_window_start_p
)
15280 /* We set this later on if we have to adjust point. */
15283 w
->force_start
= Qnil
;
15285 w
->window_end_valid
= Qnil
;
15287 /* Forget any recorded base line for line number display. */
15288 if (!buffer_unchanged_p
)
15289 w
->base_line_number
= Qnil
;
15291 /* Redisplay the mode line. Select the buffer properly for that.
15292 Also, run the hook window-scroll-functions
15293 because we have scrolled. */
15294 /* Note, we do this after clearing force_start because
15295 if there's an error, it is better to forget about force_start
15296 than to get into an infinite loop calling the hook functions
15297 and having them get more errors. */
15298 if (!update_mode_line
15299 || ! NILP (Vwindow_scroll_functions
))
15301 update_mode_line
= 1;
15302 w
->update_mode_line
= Qt
;
15303 startp
= run_window_scroll_functions (window
, startp
);
15306 w
->last_modified
= make_number (0);
15307 w
->last_overlay_modified
= make_number (0);
15308 if (CHARPOS (startp
) < BEGV
)
15309 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15310 else if (CHARPOS (startp
) > ZV
)
15311 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15313 /* Redisplay, then check if cursor has been set during the
15314 redisplay. Give up if new fonts were loaded. */
15315 /* We used to issue a CHECK_MARGINS argument to try_window here,
15316 but this causes scrolling to fail when point begins inside
15317 the scroll margin (bug#148) -- cyd */
15318 if (!try_window (window
, startp
, 0))
15320 w
->force_start
= Qt
;
15321 clear_glyph_matrix (w
->desired_matrix
);
15322 goto need_larger_matrices
;
15325 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15327 /* If point does not appear, try to move point so it does
15328 appear. The desired matrix has been built above, so we
15329 can use it here. */
15330 new_vpos
= window_box_height (w
) / 2;
15333 if (!cursor_row_fully_visible_p (w
, 0, 0))
15335 /* Point does appear, but on a line partly visible at end of window.
15336 Move it back to a fully-visible line. */
15337 new_vpos
= window_box_height (w
);
15340 /* If we need to move point for either of the above reasons,
15341 now actually do it. */
15344 struct glyph_row
*row
;
15346 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15347 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15350 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15351 MATRIX_ROW_START_BYTEPOS (row
));
15353 if (w
!= XWINDOW (selected_window
))
15354 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15355 else if (current_buffer
== old
)
15356 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15358 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15360 /* If we are highlighting the region, then we just changed
15361 the region, so redisplay to show it. */
15362 if (!NILP (Vtransient_mark_mode
)
15363 && !NILP (BVAR (current_buffer
, mark_active
)))
15365 clear_glyph_matrix (w
->desired_matrix
);
15366 if (!try_window (window
, startp
, 0))
15367 goto need_larger_matrices
;
15372 debug_method_add (w
, "forced window start");
15377 /* Handle case where text has not changed, only point, and it has
15378 not moved off the frame, and we are not retrying after hscroll.
15379 (current_matrix_up_to_date_p is nonzero when retrying.) */
15380 if (current_matrix_up_to_date_p
15381 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15382 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15386 case CURSOR_MOVEMENT_SUCCESS
:
15387 used_current_matrix_p
= 1;
15390 case CURSOR_MOVEMENT_MUST_SCROLL
:
15391 goto try_to_scroll
;
15397 /* If current starting point was originally the beginning of a line
15398 but no longer is, find a new starting point. */
15399 else if (!NILP (w
->start_at_line_beg
)
15400 && !(CHARPOS (startp
) <= BEGV
15401 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15404 debug_method_add (w
, "recenter 1");
15409 /* Try scrolling with try_window_id. Value is > 0 if update has
15410 been done, it is -1 if we know that the same window start will
15411 not work. It is 0 if unsuccessful for some other reason. */
15412 else if ((tem
= try_window_id (w
)) != 0)
15415 debug_method_add (w
, "try_window_id %d", tem
);
15418 if (fonts_changed_p
)
15419 goto need_larger_matrices
;
15423 /* Otherwise try_window_id has returned -1 which means that we
15424 don't want the alternative below this comment to execute. */
15426 else if (CHARPOS (startp
) >= BEGV
15427 && CHARPOS (startp
) <= ZV
15428 && PT
>= CHARPOS (startp
)
15429 && (CHARPOS (startp
) < ZV
15430 /* Avoid starting at end of buffer. */
15431 || CHARPOS (startp
) == BEGV
15432 || (XFASTINT (w
->last_modified
) >= MODIFF
15433 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
15435 int d1
, d2
, d3
, d4
, d5
, d6
;
15437 /* If first window line is a continuation line, and window start
15438 is inside the modified region, but the first change is before
15439 current window start, we must select a new window start.
15441 However, if this is the result of a down-mouse event (e.g. by
15442 extending the mouse-drag-overlay), we don't want to select a
15443 new window start, since that would change the position under
15444 the mouse, resulting in an unwanted mouse-movement rather
15445 than a simple mouse-click. */
15446 if (NILP (w
->start_at_line_beg
)
15447 && NILP (do_mouse_tracking
)
15448 && CHARPOS (startp
) > BEGV
15449 && CHARPOS (startp
) > BEG
+ beg_unchanged
15450 && CHARPOS (startp
) <= Z
- end_unchanged
15451 /* Even if w->start_at_line_beg is nil, a new window may
15452 start at a line_beg, since that's how set_buffer_window
15453 sets it. So, we need to check the return value of
15454 compute_window_start_on_continuation_line. (See also
15456 && XMARKER (w
->start
)->buffer
== current_buffer
15457 && compute_window_start_on_continuation_line (w
)
15458 /* It doesn't make sense to force the window start like we
15459 do at label force_start if it is already known that point
15460 will not be visible in the resulting window, because
15461 doing so will move point from its correct position
15462 instead of scrolling the window to bring point into view.
15464 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15466 w
->force_start
= Qt
;
15467 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15472 debug_method_add (w
, "same window start");
15475 /* Try to redisplay starting at same place as before.
15476 If point has not moved off frame, accept the results. */
15477 if (!current_matrix_up_to_date_p
15478 /* Don't use try_window_reusing_current_matrix in this case
15479 because a window scroll function can have changed the
15481 || !NILP (Vwindow_scroll_functions
)
15482 || MINI_WINDOW_P (w
)
15483 || !(used_current_matrix_p
15484 = try_window_reusing_current_matrix (w
)))
15486 IF_DEBUG (debug_method_add (w
, "1"));
15487 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15488 /* -1 means we need to scroll.
15489 0 means we need new matrices, but fonts_changed_p
15490 is set in that case, so we will detect it below. */
15491 goto try_to_scroll
;
15494 if (fonts_changed_p
)
15495 goto need_larger_matrices
;
15497 if (w
->cursor
.vpos
>= 0)
15499 if (!just_this_one_p
15500 || current_buffer
->clip_changed
15501 || BEG_UNCHANGED
< CHARPOS (startp
))
15502 /* Forget any recorded base line for line number display. */
15503 w
->base_line_number
= Qnil
;
15505 if (!cursor_row_fully_visible_p (w
, 1, 0))
15507 clear_glyph_matrix (w
->desired_matrix
);
15508 last_line_misfit
= 1;
15510 /* Drop through and scroll. */
15515 clear_glyph_matrix (w
->desired_matrix
);
15520 w
->last_modified
= make_number (0);
15521 w
->last_overlay_modified
= make_number (0);
15523 /* Redisplay the mode line. Select the buffer properly for that. */
15524 if (!update_mode_line
)
15526 update_mode_line
= 1;
15527 w
->update_mode_line
= Qt
;
15530 /* Try to scroll by specified few lines. */
15531 if ((scroll_conservatively
15532 || emacs_scroll_step
15533 || temp_scroll_step
15534 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15535 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15536 && CHARPOS (startp
) >= BEGV
15537 && CHARPOS (startp
) <= ZV
)
15539 /* The function returns -1 if new fonts were loaded, 1 if
15540 successful, 0 if not successful. */
15541 int ss
= try_scrolling (window
, just_this_one_p
,
15542 scroll_conservatively
,
15544 temp_scroll_step
, last_line_misfit
);
15547 case SCROLLING_SUCCESS
:
15550 case SCROLLING_NEED_LARGER_MATRICES
:
15551 goto need_larger_matrices
;
15553 case SCROLLING_FAILED
:
15561 /* Finally, just choose a place to start which positions point
15562 according to user preferences. */
15567 debug_method_add (w
, "recenter");
15570 /* w->vscroll = 0; */
15572 /* Forget any previously recorded base line for line number display. */
15573 if (!buffer_unchanged_p
)
15574 w
->base_line_number
= Qnil
;
15576 /* Determine the window start relative to point. */
15577 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15578 it
.current_y
= it
.last_visible_y
;
15579 if (centering_position
< 0)
15583 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15585 ptrdiff_t margin_pos
= CHARPOS (startp
);
15586 Lisp_Object aggressive
;
15589 /* If there is a scroll margin at the top of the window, find
15590 its character position. */
15592 /* Cannot call start_display if startp is not in the
15593 accessible region of the buffer. This can happen when we
15594 have just switched to a different buffer and/or changed
15595 its restriction. In that case, startp is initialized to
15596 the character position 1 (BEG) because we did not yet
15597 have chance to display the buffer even once. */
15598 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15601 void *it1data
= NULL
;
15603 SAVE_IT (it1
, it
, it1data
);
15604 start_display (&it1
, w
, startp
);
15605 move_it_vertically (&it1
, margin
);
15606 margin_pos
= IT_CHARPOS (it1
);
15607 RESTORE_IT (&it
, &it
, it1data
);
15609 scrolling_up
= PT
> margin_pos
;
15612 ? BVAR (current_buffer
, scroll_up_aggressively
)
15613 : BVAR (current_buffer
, scroll_down_aggressively
);
15615 if (!MINI_WINDOW_P (w
)
15616 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15620 /* Setting scroll-conservatively overrides
15621 scroll-*-aggressively. */
15622 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15624 double float_amount
= XFLOATINT (aggressive
);
15626 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15627 if (pt_offset
== 0 && float_amount
> 0)
15629 if (pt_offset
&& margin
> 0)
15632 /* Compute how much to move the window start backward from
15633 point so that point will be displayed where the user
15637 centering_position
= it
.last_visible_y
;
15639 centering_position
-= pt_offset
;
15640 centering_position
-=
15641 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15642 + WINDOW_HEADER_LINE_HEIGHT (w
);
15643 /* Don't let point enter the scroll margin near top of
15645 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15646 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15649 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15652 /* Set the window start half the height of the window backward
15654 centering_position
= window_box_height (w
) / 2;
15656 move_it_vertically_backward (&it
, centering_position
);
15658 xassert (IT_CHARPOS (it
) >= BEGV
);
15660 /* The function move_it_vertically_backward may move over more
15661 than the specified y-distance. If it->w is small, e.g. a
15662 mini-buffer window, we may end up in front of the window's
15663 display area. Start displaying at the start of the line
15664 containing PT in this case. */
15665 if (it
.current_y
<= 0)
15667 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15668 move_it_vertically_backward (&it
, 0);
15672 it
.current_x
= it
.hpos
= 0;
15674 /* Set the window start position here explicitly, to avoid an
15675 infinite loop in case the functions in window-scroll-functions
15677 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15679 /* Run scroll hooks. */
15680 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15682 /* Redisplay the window. */
15683 if (!current_matrix_up_to_date_p
15684 || windows_or_buffers_changed
15685 || cursor_type_changed
15686 /* Don't use try_window_reusing_current_matrix in this case
15687 because it can have changed the buffer. */
15688 || !NILP (Vwindow_scroll_functions
)
15689 || !just_this_one_p
15690 || MINI_WINDOW_P (w
)
15691 || !(used_current_matrix_p
15692 = try_window_reusing_current_matrix (w
)))
15693 try_window (window
, startp
, 0);
15695 /* If new fonts have been loaded (due to fontsets), give up. We
15696 have to start a new redisplay since we need to re-adjust glyph
15698 if (fonts_changed_p
)
15699 goto need_larger_matrices
;
15701 /* If cursor did not appear assume that the middle of the window is
15702 in the first line of the window. Do it again with the next line.
15703 (Imagine a window of height 100, displaying two lines of height
15704 60. Moving back 50 from it->last_visible_y will end in the first
15706 if (w
->cursor
.vpos
< 0)
15708 if (!NILP (w
->window_end_valid
)
15709 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15711 clear_glyph_matrix (w
->desired_matrix
);
15712 move_it_by_lines (&it
, 1);
15713 try_window (window
, it
.current
.pos
, 0);
15715 else if (PT
< IT_CHARPOS (it
))
15717 clear_glyph_matrix (w
->desired_matrix
);
15718 move_it_by_lines (&it
, -1);
15719 try_window (window
, it
.current
.pos
, 0);
15723 /* Not much we can do about it. */
15727 /* Consider the following case: Window starts at BEGV, there is
15728 invisible, intangible text at BEGV, so that display starts at
15729 some point START > BEGV. It can happen that we are called with
15730 PT somewhere between BEGV and START. Try to handle that case. */
15731 if (w
->cursor
.vpos
< 0)
15733 struct glyph_row
*row
= w
->current_matrix
->rows
;
15734 if (row
->mode_line_p
)
15736 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15739 if (!cursor_row_fully_visible_p (w
, 0, 0))
15741 /* If vscroll is enabled, disable it and try again. */
15745 clear_glyph_matrix (w
->desired_matrix
);
15749 /* Users who set scroll-conservatively to a large number want
15750 point just above/below the scroll margin. If we ended up
15751 with point's row partially visible, move the window start to
15752 make that row fully visible and out of the margin. */
15753 if (scroll_conservatively
> SCROLL_LIMIT
)
15757 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15759 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15761 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15762 clear_glyph_matrix (w
->desired_matrix
);
15763 if (1 == try_window (window
, it
.current
.pos
,
15764 TRY_WINDOW_CHECK_MARGINS
))
15768 /* If centering point failed to make the whole line visible,
15769 put point at the top instead. That has to make the whole line
15770 visible, if it can be done. */
15771 if (centering_position
== 0)
15774 clear_glyph_matrix (w
->desired_matrix
);
15775 centering_position
= 0;
15781 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15782 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15783 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15786 /* Display the mode line, if we must. */
15787 if ((update_mode_line
15788 /* If window not full width, must redo its mode line
15789 if (a) the window to its side is being redone and
15790 (b) we do a frame-based redisplay. This is a consequence
15791 of how inverted lines are drawn in frame-based redisplay. */
15792 || (!just_this_one_p
15793 && !FRAME_WINDOW_P (f
)
15794 && !WINDOW_FULL_WIDTH_P (w
))
15795 /* Line number to display. */
15796 || INTEGERP (w
->base_line_pos
)
15797 /* Column number is displayed and different from the one displayed. */
15798 || (!NILP (w
->column_number_displayed
)
15799 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15800 /* This means that the window has a mode line. */
15801 && (WINDOW_WANTS_MODELINE_P (w
)
15802 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15804 display_mode_lines (w
);
15806 /* If mode line height has changed, arrange for a thorough
15807 immediate redisplay using the correct mode line height. */
15808 if (WINDOW_WANTS_MODELINE_P (w
)
15809 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15811 fonts_changed_p
= 1;
15812 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15813 = DESIRED_MODE_LINE_HEIGHT (w
);
15816 /* If header line height has changed, arrange for a thorough
15817 immediate redisplay using the correct header line height. */
15818 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15819 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15821 fonts_changed_p
= 1;
15822 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15823 = DESIRED_HEADER_LINE_HEIGHT (w
);
15826 if (fonts_changed_p
)
15827 goto need_larger_matrices
;
15830 if (!line_number_displayed
15831 && !BUFFERP (w
->base_line_pos
))
15833 w
->base_line_pos
= Qnil
;
15834 w
->base_line_number
= Qnil
;
15839 /* When we reach a frame's selected window, redo the frame's menu bar. */
15840 if (update_mode_line
15841 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15843 int redisplay_menu_p
= 0;
15845 if (FRAME_WINDOW_P (f
))
15847 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15848 || defined (HAVE_NS) || defined (USE_GTK)
15849 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15851 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15855 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15857 if (redisplay_menu_p
)
15858 display_menu_bar (w
);
15860 #ifdef HAVE_WINDOW_SYSTEM
15861 if (FRAME_WINDOW_P (f
))
15863 #if defined (USE_GTK) || defined (HAVE_NS)
15864 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15865 redisplay_tool_bar (f
);
15867 if (WINDOWP (f
->tool_bar_window
)
15868 && (FRAME_TOOL_BAR_LINES (f
) > 0
15869 || !NILP (Vauto_resize_tool_bars
))
15870 && redisplay_tool_bar (f
))
15871 ignore_mouse_drag_p
= 1;
15877 #ifdef HAVE_WINDOW_SYSTEM
15878 if (FRAME_WINDOW_P (f
)
15879 && update_window_fringes (w
, (just_this_one_p
15880 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15881 || w
->pseudo_window_p
)))
15885 if (draw_window_fringes (w
, 1))
15886 x_draw_vertical_border (w
);
15890 #endif /* HAVE_WINDOW_SYSTEM */
15892 /* We go to this label, with fonts_changed_p nonzero,
15893 if it is necessary to try again using larger glyph matrices.
15894 We have to redeem the scroll bar even in this case,
15895 because the loop in redisplay_internal expects that. */
15896 need_larger_matrices
:
15898 finish_scroll_bars
:
15900 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15902 /* Set the thumb's position and size. */
15903 set_vertical_scroll_bar (w
);
15905 /* Note that we actually used the scroll bar attached to this
15906 window, so it shouldn't be deleted at the end of redisplay. */
15907 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15908 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15911 /* Restore current_buffer and value of point in it. The window
15912 update may have changed the buffer, so first make sure `opoint'
15913 is still valid (Bug#6177). */
15914 if (CHARPOS (opoint
) < BEGV
)
15915 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15916 else if (CHARPOS (opoint
) > ZV
)
15917 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15919 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15921 set_buffer_internal_1 (old
);
15922 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15923 shorter. This can be caused by log truncation in *Messages*. */
15924 if (CHARPOS (lpoint
) <= ZV
)
15925 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15927 unbind_to (count
, Qnil
);
15931 /* Build the complete desired matrix of WINDOW with a window start
15932 buffer position POS.
15934 Value is 1 if successful. It is zero if fonts were loaded during
15935 redisplay which makes re-adjusting glyph matrices necessary, and -1
15936 if point would appear in the scroll margins.
15937 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15938 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15942 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15944 struct window
*w
= XWINDOW (window
);
15946 struct glyph_row
*last_text_row
= NULL
;
15947 struct frame
*f
= XFRAME (w
->frame
);
15949 /* Make POS the new window start. */
15950 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15952 /* Mark cursor position as unknown. No overlay arrow seen. */
15953 w
->cursor
.vpos
= -1;
15954 overlay_arrow_seen
= 0;
15956 /* Initialize iterator and info to start at POS. */
15957 start_display (&it
, w
, pos
);
15959 /* Display all lines of W. */
15960 while (it
.current_y
< it
.last_visible_y
)
15962 if (display_line (&it
))
15963 last_text_row
= it
.glyph_row
- 1;
15964 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15968 /* Don't let the cursor end in the scroll margins. */
15969 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15970 && !MINI_WINDOW_P (w
))
15972 int this_scroll_margin
;
15974 if (scroll_margin
> 0)
15976 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15977 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15980 this_scroll_margin
= 0;
15982 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15983 && w
->cursor
.y
< this_scroll_margin
15984 && CHARPOS (pos
) > BEGV
15985 && IT_CHARPOS (it
) < ZV
)
15986 /* rms: considering make_cursor_line_fully_visible_p here
15987 seems to give wrong results. We don't want to recenter
15988 when the last line is partly visible, we want to allow
15989 that case to be handled in the usual way. */
15990 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15992 w
->cursor
.vpos
= -1;
15993 clear_glyph_matrix (w
->desired_matrix
);
15998 /* If bottom moved off end of frame, change mode line percentage. */
15999 if (XFASTINT (w
->window_end_pos
) <= 0
16000 && Z
!= IT_CHARPOS (it
))
16001 w
->update_mode_line
= Qt
;
16003 /* Set window_end_pos to the offset of the last character displayed
16004 on the window from the end of current_buffer. Set
16005 window_end_vpos to its row number. */
16008 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16009 w
->window_end_bytepos
16010 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16012 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16014 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16015 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16016 ->displays_text_p
);
16020 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16021 w
->window_end_pos
= make_number (Z
- ZV
);
16022 w
->window_end_vpos
= make_number (0);
16025 /* But that is not valid info until redisplay finishes. */
16026 w
->window_end_valid
= Qnil
;
16032 /************************************************************************
16033 Window redisplay reusing current matrix when buffer has not changed
16034 ************************************************************************/
16036 /* Try redisplay of window W showing an unchanged buffer with a
16037 different window start than the last time it was displayed by
16038 reusing its current matrix. Value is non-zero if successful.
16039 W->start is the new window start. */
16042 try_window_reusing_current_matrix (struct window
*w
)
16044 struct frame
*f
= XFRAME (w
->frame
);
16045 struct glyph_row
*bottom_row
;
16048 struct text_pos start
, new_start
;
16049 int nrows_scrolled
, i
;
16050 struct glyph_row
*last_text_row
;
16051 struct glyph_row
*last_reused_text_row
;
16052 struct glyph_row
*start_row
;
16053 int start_vpos
, min_y
, max_y
;
16056 if (inhibit_try_window_reusing
)
16060 if (/* This function doesn't handle terminal frames. */
16061 !FRAME_WINDOW_P (f
)
16062 /* Don't try to reuse the display if windows have been split
16064 || windows_or_buffers_changed
16065 || cursor_type_changed
)
16068 /* Can't do this if region may have changed. */
16069 if ((!NILP (Vtransient_mark_mode
)
16070 && !NILP (BVAR (current_buffer
, mark_active
)))
16071 || !NILP (w
->region_showing
)
16072 || !NILP (Vshow_trailing_whitespace
))
16075 /* If top-line visibility has changed, give up. */
16076 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16077 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16080 /* Give up if old or new display is scrolled vertically. We could
16081 make this function handle this, but right now it doesn't. */
16082 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16083 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16086 /* The variable new_start now holds the new window start. The old
16087 start `start' can be determined from the current matrix. */
16088 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16089 start
= start_row
->minpos
;
16090 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16092 /* Clear the desired matrix for the display below. */
16093 clear_glyph_matrix (w
->desired_matrix
);
16095 if (CHARPOS (new_start
) <= CHARPOS (start
))
16097 /* Don't use this method if the display starts with an ellipsis
16098 displayed for invisible text. It's not easy to handle that case
16099 below, and it's certainly not worth the effort since this is
16100 not a frequent case. */
16101 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16104 IF_DEBUG (debug_method_add (w
, "twu1"));
16106 /* Display up to a row that can be reused. The variable
16107 last_text_row is set to the last row displayed that displays
16108 text. Note that it.vpos == 0 if or if not there is a
16109 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16110 start_display (&it
, w
, new_start
);
16111 w
->cursor
.vpos
= -1;
16112 last_text_row
= last_reused_text_row
= NULL
;
16114 while (it
.current_y
< it
.last_visible_y
16115 && !fonts_changed_p
)
16117 /* If we have reached into the characters in the START row,
16118 that means the line boundaries have changed. So we
16119 can't start copying with the row START. Maybe it will
16120 work to start copying with the following row. */
16121 while (IT_CHARPOS (it
) > CHARPOS (start
))
16123 /* Advance to the next row as the "start". */
16125 start
= start_row
->minpos
;
16126 /* If there are no more rows to try, or just one, give up. */
16127 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16128 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16129 || CHARPOS (start
) == ZV
)
16131 clear_glyph_matrix (w
->desired_matrix
);
16135 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16137 /* If we have reached alignment, we can copy the rest of the
16139 if (IT_CHARPOS (it
) == CHARPOS (start
)
16140 /* Don't accept "alignment" inside a display vector,
16141 since start_row could have started in the middle of
16142 that same display vector (thus their character
16143 positions match), and we have no way of telling if
16144 that is the case. */
16145 && it
.current
.dpvec_index
< 0)
16148 if (display_line (&it
))
16149 last_text_row
= it
.glyph_row
- 1;
16153 /* A value of current_y < last_visible_y means that we stopped
16154 at the previous window start, which in turn means that we
16155 have at least one reusable row. */
16156 if (it
.current_y
< it
.last_visible_y
)
16158 struct glyph_row
*row
;
16160 /* IT.vpos always starts from 0; it counts text lines. */
16161 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16163 /* Find PT if not already found in the lines displayed. */
16164 if (w
->cursor
.vpos
< 0)
16166 int dy
= it
.current_y
- start_row
->y
;
16168 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16169 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16171 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16172 dy
, nrows_scrolled
);
16175 clear_glyph_matrix (w
->desired_matrix
);
16180 /* Scroll the display. Do it before the current matrix is
16181 changed. The problem here is that update has not yet
16182 run, i.e. part of the current matrix is not up to date.
16183 scroll_run_hook will clear the cursor, and use the
16184 current matrix to get the height of the row the cursor is
16186 run
.current_y
= start_row
->y
;
16187 run
.desired_y
= it
.current_y
;
16188 run
.height
= it
.last_visible_y
- it
.current_y
;
16190 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16193 FRAME_RIF (f
)->update_window_begin_hook (w
);
16194 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16195 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16196 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16200 /* Shift current matrix down by nrows_scrolled lines. */
16201 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16202 rotate_matrix (w
->current_matrix
,
16204 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16207 /* Disable lines that must be updated. */
16208 for (i
= 0; i
< nrows_scrolled
; ++i
)
16209 (start_row
+ i
)->enabled_p
= 0;
16211 /* Re-compute Y positions. */
16212 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16213 max_y
= it
.last_visible_y
;
16214 for (row
= start_row
+ nrows_scrolled
;
16218 row
->y
= it
.current_y
;
16219 row
->visible_height
= row
->height
;
16221 if (row
->y
< min_y
)
16222 row
->visible_height
-= min_y
- row
->y
;
16223 if (row
->y
+ row
->height
> max_y
)
16224 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16225 if (row
->fringe_bitmap_periodic_p
)
16226 row
->redraw_fringe_bitmaps_p
= 1;
16228 it
.current_y
+= row
->height
;
16230 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16231 last_reused_text_row
= row
;
16232 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16236 /* Disable lines in the current matrix which are now
16237 below the window. */
16238 for (++row
; row
< bottom_row
; ++row
)
16239 row
->enabled_p
= row
->mode_line_p
= 0;
16242 /* Update window_end_pos etc.; last_reused_text_row is the last
16243 reused row from the current matrix containing text, if any.
16244 The value of last_text_row is the last displayed line
16245 containing text. */
16246 if (last_reused_text_row
)
16248 w
->window_end_bytepos
16249 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16251 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16253 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16254 w
->current_matrix
));
16256 else if (last_text_row
)
16258 w
->window_end_bytepos
16259 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16261 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16263 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16267 /* This window must be completely empty. */
16268 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16269 w
->window_end_pos
= make_number (Z
- ZV
);
16270 w
->window_end_vpos
= make_number (0);
16272 w
->window_end_valid
= Qnil
;
16274 /* Update hint: don't try scrolling again in update_window. */
16275 w
->desired_matrix
->no_scrolling_p
= 1;
16278 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16282 else if (CHARPOS (new_start
) > CHARPOS (start
))
16284 struct glyph_row
*pt_row
, *row
;
16285 struct glyph_row
*first_reusable_row
;
16286 struct glyph_row
*first_row_to_display
;
16288 int yb
= window_text_bottom_y (w
);
16290 /* Find the row starting at new_start, if there is one. Don't
16291 reuse a partially visible line at the end. */
16292 first_reusable_row
= start_row
;
16293 while (first_reusable_row
->enabled_p
16294 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16295 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16296 < CHARPOS (new_start
)))
16297 ++first_reusable_row
;
16299 /* Give up if there is no row to reuse. */
16300 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16301 || !first_reusable_row
->enabled_p
16302 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16303 != CHARPOS (new_start
)))
16306 /* We can reuse fully visible rows beginning with
16307 first_reusable_row to the end of the window. Set
16308 first_row_to_display to the first row that cannot be reused.
16309 Set pt_row to the row containing point, if there is any. */
16311 for (first_row_to_display
= first_reusable_row
;
16312 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16313 ++first_row_to_display
)
16315 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16316 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
16317 pt_row
= first_row_to_display
;
16320 /* Start displaying at the start of first_row_to_display. */
16321 xassert (first_row_to_display
->y
< yb
);
16322 init_to_row_start (&it
, w
, first_row_to_display
);
16324 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16326 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16328 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16329 + WINDOW_HEADER_LINE_HEIGHT (w
));
16331 /* Display lines beginning with first_row_to_display in the
16332 desired matrix. Set last_text_row to the last row displayed
16333 that displays text. */
16334 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16335 if (pt_row
== NULL
)
16336 w
->cursor
.vpos
= -1;
16337 last_text_row
= NULL
;
16338 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16339 if (display_line (&it
))
16340 last_text_row
= it
.glyph_row
- 1;
16342 /* If point is in a reused row, adjust y and vpos of the cursor
16346 w
->cursor
.vpos
-= nrows_scrolled
;
16347 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16350 /* Give up if point isn't in a row displayed or reused. (This
16351 also handles the case where w->cursor.vpos < nrows_scrolled
16352 after the calls to display_line, which can happen with scroll
16353 margins. See bug#1295.) */
16354 if (w
->cursor
.vpos
< 0)
16356 clear_glyph_matrix (w
->desired_matrix
);
16360 /* Scroll the display. */
16361 run
.current_y
= first_reusable_row
->y
;
16362 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16363 run
.height
= it
.last_visible_y
- run
.current_y
;
16364 dy
= run
.current_y
- run
.desired_y
;
16369 FRAME_RIF (f
)->update_window_begin_hook (w
);
16370 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16371 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16372 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16376 /* Adjust Y positions of reused rows. */
16377 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16378 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16379 max_y
= it
.last_visible_y
;
16380 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16383 row
->visible_height
= row
->height
;
16384 if (row
->y
< min_y
)
16385 row
->visible_height
-= min_y
- row
->y
;
16386 if (row
->y
+ row
->height
> max_y
)
16387 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16388 if (row
->fringe_bitmap_periodic_p
)
16389 row
->redraw_fringe_bitmaps_p
= 1;
16392 /* Scroll the current matrix. */
16393 xassert (nrows_scrolled
> 0);
16394 rotate_matrix (w
->current_matrix
,
16396 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16399 /* Disable rows not reused. */
16400 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16401 row
->enabled_p
= 0;
16403 /* Point may have moved to a different line, so we cannot assume that
16404 the previous cursor position is valid; locate the correct row. */
16407 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16408 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
16412 w
->cursor
.y
= row
->y
;
16414 if (row
< bottom_row
)
16416 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16417 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16419 /* Can't use this optimization with bidi-reordered glyph
16420 rows, unless cursor is already at point. */
16421 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16423 if (!(w
->cursor
.hpos
>= 0
16424 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16425 && BUFFERP (glyph
->object
)
16426 && glyph
->charpos
== PT
))
16431 && (!BUFFERP (glyph
->object
)
16432 || glyph
->charpos
< PT
);
16436 w
->cursor
.x
+= glyph
->pixel_width
;
16441 /* Adjust window end. A null value of last_text_row means that
16442 the window end is in reused rows which in turn means that
16443 only its vpos can have changed. */
16446 w
->window_end_bytepos
16447 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16449 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16451 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16456 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16459 w
->window_end_valid
= Qnil
;
16460 w
->desired_matrix
->no_scrolling_p
= 1;
16463 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16473 /************************************************************************
16474 Window redisplay reusing current matrix when buffer has changed
16475 ************************************************************************/
16477 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16478 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16479 ptrdiff_t *, ptrdiff_t *);
16480 static struct glyph_row
*
16481 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16482 struct glyph_row
*);
16485 /* Return the last row in MATRIX displaying text. If row START is
16486 non-null, start searching with that row. IT gives the dimensions
16487 of the display. Value is null if matrix is empty; otherwise it is
16488 a pointer to the row found. */
16490 static struct glyph_row
*
16491 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16492 struct glyph_row
*start
)
16494 struct glyph_row
*row
, *row_found
;
16496 /* Set row_found to the last row in IT->w's current matrix
16497 displaying text. The loop looks funny but think of partially
16500 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16501 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16503 xassert (row
->enabled_p
);
16505 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16514 /* Return the last row in the current matrix of W that is not affected
16515 by changes at the start of current_buffer that occurred since W's
16516 current matrix was built. Value is null if no such row exists.
16518 BEG_UNCHANGED us the number of characters unchanged at the start of
16519 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16520 first changed character in current_buffer. Characters at positions <
16521 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16522 when the current matrix was built. */
16524 static struct glyph_row
*
16525 find_last_unchanged_at_beg_row (struct window
*w
)
16527 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16528 struct glyph_row
*row
;
16529 struct glyph_row
*row_found
= NULL
;
16530 int yb
= window_text_bottom_y (w
);
16532 /* Find the last row displaying unchanged text. */
16533 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16534 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16535 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16538 if (/* If row ends before first_changed_pos, it is unchanged,
16539 except in some case. */
16540 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16541 /* When row ends in ZV and we write at ZV it is not
16543 && !row
->ends_at_zv_p
16544 /* When first_changed_pos is the end of a continued line,
16545 row is not unchanged because it may be no longer
16547 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16548 && (row
->continued_p
16549 || row
->exact_window_width_line_p
)))
16552 /* Stop if last visible row. */
16553 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16561 /* Find the first glyph row in the current matrix of W that is not
16562 affected by changes at the end of current_buffer since the
16563 time W's current matrix was built.
16565 Return in *DELTA the number of chars by which buffer positions in
16566 unchanged text at the end of current_buffer must be adjusted.
16568 Return in *DELTA_BYTES the corresponding number of bytes.
16570 Value is null if no such row exists, i.e. all rows are affected by
16573 static struct glyph_row
*
16574 find_first_unchanged_at_end_row (struct window
*w
,
16575 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16577 struct glyph_row
*row
;
16578 struct glyph_row
*row_found
= NULL
;
16580 *delta
= *delta_bytes
= 0;
16582 /* Display must not have been paused, otherwise the current matrix
16583 is not up to date. */
16584 eassert (!NILP (w
->window_end_valid
));
16586 /* A value of window_end_pos >= END_UNCHANGED means that the window
16587 end is in the range of changed text. If so, there is no
16588 unchanged row at the end of W's current matrix. */
16589 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16592 /* Set row to the last row in W's current matrix displaying text. */
16593 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16595 /* If matrix is entirely empty, no unchanged row exists. */
16596 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16598 /* The value of row is the last glyph row in the matrix having a
16599 meaningful buffer position in it. The end position of row
16600 corresponds to window_end_pos. This allows us to translate
16601 buffer positions in the current matrix to current buffer
16602 positions for characters not in changed text. */
16604 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16605 ptrdiff_t Z_BYTE_old
=
16606 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16607 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16608 struct glyph_row
*first_text_row
16609 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16611 *delta
= Z
- Z_old
;
16612 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16614 /* Set last_unchanged_pos to the buffer position of the last
16615 character in the buffer that has not been changed. Z is the
16616 index + 1 of the last character in current_buffer, i.e. by
16617 subtracting END_UNCHANGED we get the index of the last
16618 unchanged character, and we have to add BEG to get its buffer
16620 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16621 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16623 /* Search backward from ROW for a row displaying a line that
16624 starts at a minimum position >= last_unchanged_pos_old. */
16625 for (; row
> first_text_row
; --row
)
16627 /* This used to abort, but it can happen.
16628 It is ok to just stop the search instead here. KFS. */
16629 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16632 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16637 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16643 /* Make sure that glyph rows in the current matrix of window W
16644 reference the same glyph memory as corresponding rows in the
16645 frame's frame matrix. This function is called after scrolling W's
16646 current matrix on a terminal frame in try_window_id and
16647 try_window_reusing_current_matrix. */
16650 sync_frame_with_window_matrix_rows (struct window
*w
)
16652 struct frame
*f
= XFRAME (w
->frame
);
16653 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16655 /* Preconditions: W must be a leaf window and full-width. Its frame
16656 must have a frame matrix. */
16657 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16658 xassert (WINDOW_FULL_WIDTH_P (w
));
16659 xassert (!FRAME_WINDOW_P (f
));
16661 /* If W is a full-width window, glyph pointers in W's current matrix
16662 have, by definition, to be the same as glyph pointers in the
16663 corresponding frame matrix. Note that frame matrices have no
16664 marginal areas (see build_frame_matrix). */
16665 window_row
= w
->current_matrix
->rows
;
16666 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16667 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16668 while (window_row
< window_row_end
)
16670 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16671 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16673 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16674 frame_row
->glyphs
[TEXT_AREA
] = start
;
16675 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16676 frame_row
->glyphs
[LAST_AREA
] = end
;
16678 /* Disable frame rows whose corresponding window rows have
16679 been disabled in try_window_id. */
16680 if (!window_row
->enabled_p
)
16681 frame_row
->enabled_p
= 0;
16683 ++window_row
, ++frame_row
;
16688 /* Find the glyph row in window W containing CHARPOS. Consider all
16689 rows between START and END (not inclusive). END null means search
16690 all rows to the end of the display area of W. Value is the row
16691 containing CHARPOS or null. */
16694 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16695 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16697 struct glyph_row
*row
= start
;
16698 struct glyph_row
*best_row
= NULL
;
16699 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16702 /* If we happen to start on a header-line, skip that. */
16703 if (row
->mode_line_p
)
16706 if ((end
&& row
>= end
) || !row
->enabled_p
)
16709 last_y
= window_text_bottom_y (w
) - dy
;
16713 /* Give up if we have gone too far. */
16714 if (end
&& row
>= end
)
16716 /* This formerly returned if they were equal.
16717 I think that both quantities are of a "last plus one" type;
16718 if so, when they are equal, the row is within the screen. -- rms. */
16719 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16722 /* If it is in this row, return this row. */
16723 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16724 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16725 /* The end position of a row equals the start
16726 position of the next row. If CHARPOS is there, we
16727 would rather display it in the next line, except
16728 when this line ends in ZV. */
16729 && !row
->ends_at_zv_p
16730 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16731 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16735 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16736 || (!best_row
&& !row
->continued_p
))
16738 /* In bidi-reordered rows, there could be several rows
16739 occluding point, all of them belonging to the same
16740 continued line. We need to find the row which fits
16741 CHARPOS the best. */
16742 for (g
= row
->glyphs
[TEXT_AREA
];
16743 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16746 if (!STRINGP (g
->object
))
16748 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16750 mindif
= eabs (g
->charpos
- charpos
);
16752 /* Exact match always wins. */
16759 else if (best_row
&& !row
->continued_p
)
16766 /* Try to redisplay window W by reusing its existing display. W's
16767 current matrix must be up to date when this function is called,
16768 i.e. window_end_valid must not be nil.
16772 1 if display has been updated
16773 0 if otherwise unsuccessful
16774 -1 if redisplay with same window start is known not to succeed
16776 The following steps are performed:
16778 1. Find the last row in the current matrix of W that is not
16779 affected by changes at the start of current_buffer. If no such row
16782 2. Find the first row in W's current matrix that is not affected by
16783 changes at the end of current_buffer. Maybe there is no such row.
16785 3. Display lines beginning with the row + 1 found in step 1 to the
16786 row found in step 2 or, if step 2 didn't find a row, to the end of
16789 4. If cursor is not known to appear on the window, give up.
16791 5. If display stopped at the row found in step 2, scroll the
16792 display and current matrix as needed.
16794 6. Maybe display some lines at the end of W, if we must. This can
16795 happen under various circumstances, like a partially visible line
16796 becoming fully visible, or because newly displayed lines are displayed
16797 in smaller font sizes.
16799 7. Update W's window end information. */
16802 try_window_id (struct window
*w
)
16804 struct frame
*f
= XFRAME (w
->frame
);
16805 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16806 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16807 struct glyph_row
*last_unchanged_at_beg_row
;
16808 struct glyph_row
*first_unchanged_at_end_row
;
16809 struct glyph_row
*row
;
16810 struct glyph_row
*bottom_row
;
16813 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
16815 struct text_pos start_pos
;
16817 int first_unchanged_at_end_vpos
= 0;
16818 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16819 struct text_pos start
;
16820 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
16823 if (inhibit_try_window_id
)
16827 /* This is handy for debugging. */
16829 #define GIVE_UP(X) \
16831 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16835 #define GIVE_UP(X) return 0
16838 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16840 /* Don't use this for mini-windows because these can show
16841 messages and mini-buffers, and we don't handle that here. */
16842 if (MINI_WINDOW_P (w
))
16845 /* This flag is used to prevent redisplay optimizations. */
16846 if (windows_or_buffers_changed
|| cursor_type_changed
)
16849 /* Verify that narrowing has not changed.
16850 Also verify that we were not told to prevent redisplay optimizations.
16851 It would be nice to further
16852 reduce the number of cases where this prevents try_window_id. */
16853 if (current_buffer
->clip_changed
16854 || current_buffer
->prevent_redisplay_optimizations_p
)
16857 /* Window must either use window-based redisplay or be full width. */
16858 if (!FRAME_WINDOW_P (f
)
16859 && (!FRAME_LINE_INS_DEL_OK (f
)
16860 || !WINDOW_FULL_WIDTH_P (w
)))
16863 /* Give up if point is known NOT to appear in W. */
16864 if (PT
< CHARPOS (start
))
16867 /* Another way to prevent redisplay optimizations. */
16868 if (XFASTINT (w
->last_modified
) == 0)
16871 /* Verify that window is not hscrolled. */
16872 if (XFASTINT (w
->hscroll
) != 0)
16875 /* Verify that display wasn't paused. */
16876 if (NILP (w
->window_end_valid
))
16879 /* Can't use this if highlighting a region because a cursor movement
16880 will do more than just set the cursor. */
16881 if (!NILP (Vtransient_mark_mode
)
16882 && !NILP (BVAR (current_buffer
, mark_active
)))
16885 /* Likewise if highlighting trailing whitespace. */
16886 if (!NILP (Vshow_trailing_whitespace
))
16889 /* Likewise if showing a region. */
16890 if (!NILP (w
->region_showing
))
16893 /* Can't use this if overlay arrow position and/or string have
16895 if (overlay_arrows_changed_p ())
16898 /* When word-wrap is on, adding a space to the first word of a
16899 wrapped line can change the wrap position, altering the line
16900 above it. It might be worthwhile to handle this more
16901 intelligently, but for now just redisplay from scratch. */
16902 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16905 /* Under bidi reordering, adding or deleting a character in the
16906 beginning of a paragraph, before the first strong directional
16907 character, can change the base direction of the paragraph (unless
16908 the buffer specifies a fixed paragraph direction), which will
16909 require to redisplay the whole paragraph. It might be worthwhile
16910 to find the paragraph limits and widen the range of redisplayed
16911 lines to that, but for now just give up this optimization and
16912 redisplay from scratch. */
16913 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16914 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16917 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16918 only if buffer has really changed. The reason is that the gap is
16919 initially at Z for freshly visited files. The code below would
16920 set end_unchanged to 0 in that case. */
16921 if (MODIFF
> SAVE_MODIFF
16922 /* This seems to happen sometimes after saving a buffer. */
16923 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16925 if (GPT
- BEG
< BEG_UNCHANGED
)
16926 BEG_UNCHANGED
= GPT
- BEG
;
16927 if (Z
- GPT
< END_UNCHANGED
)
16928 END_UNCHANGED
= Z
- GPT
;
16931 /* The position of the first and last character that has been changed. */
16932 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16933 last_changed_charpos
= Z
- END_UNCHANGED
;
16935 /* If window starts after a line end, and the last change is in
16936 front of that newline, then changes don't affect the display.
16937 This case happens with stealth-fontification. Note that although
16938 the display is unchanged, glyph positions in the matrix have to
16939 be adjusted, of course. */
16940 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16941 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16942 && ((last_changed_charpos
< CHARPOS (start
)
16943 && CHARPOS (start
) == BEGV
)
16944 || (last_changed_charpos
< CHARPOS (start
) - 1
16945 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16947 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16948 struct glyph_row
*r0
;
16950 /* Compute how many chars/bytes have been added to or removed
16951 from the buffer. */
16952 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16953 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16954 Z_delta
= Z
- Z_old
;
16955 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16957 /* Give up if PT is not in the window. Note that it already has
16958 been checked at the start of try_window_id that PT is not in
16959 front of the window start. */
16960 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16963 /* If window start is unchanged, we can reuse the whole matrix
16964 as is, after adjusting glyph positions. No need to compute
16965 the window end again, since its offset from Z hasn't changed. */
16966 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16967 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16968 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16969 /* PT must not be in a partially visible line. */
16970 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16971 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16973 /* Adjust positions in the glyph matrix. */
16974 if (Z_delta
|| Z_delta_bytes
)
16976 struct glyph_row
*r1
16977 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16978 increment_matrix_positions (w
->current_matrix
,
16979 MATRIX_ROW_VPOS (r0
, current_matrix
),
16980 MATRIX_ROW_VPOS (r1
, current_matrix
),
16981 Z_delta
, Z_delta_bytes
);
16984 /* Set the cursor. */
16985 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16987 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16994 /* Handle the case that changes are all below what is displayed in
16995 the window, and that PT is in the window. This shortcut cannot
16996 be taken if ZV is visible in the window, and text has been added
16997 there that is visible in the window. */
16998 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16999 /* ZV is not visible in the window, or there are no
17000 changes at ZV, actually. */
17001 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17002 || first_changed_charpos
== last_changed_charpos
))
17004 struct glyph_row
*r0
;
17006 /* Give up if PT is not in the window. Note that it already has
17007 been checked at the start of try_window_id that PT is not in
17008 front of the window start. */
17009 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17012 /* If window start is unchanged, we can reuse the whole matrix
17013 as is, without changing glyph positions since no text has
17014 been added/removed in front of the window end. */
17015 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17016 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17017 /* PT must not be in a partially visible line. */
17018 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17019 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17021 /* We have to compute the window end anew since text
17022 could have been added/removed after it. */
17024 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17025 w
->window_end_bytepos
17026 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17028 /* Set the cursor. */
17029 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17031 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17038 /* Give up if window start is in the changed area.
17040 The condition used to read
17042 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17044 but why that was tested escapes me at the moment. */
17045 if (CHARPOS (start
) >= first_changed_charpos
17046 && CHARPOS (start
) <= last_changed_charpos
)
17049 /* Check that window start agrees with the start of the first glyph
17050 row in its current matrix. Check this after we know the window
17051 start is not in changed text, otherwise positions would not be
17053 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17054 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17057 /* Give up if the window ends in strings. Overlay strings
17058 at the end are difficult to handle, so don't try. */
17059 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17060 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17063 /* Compute the position at which we have to start displaying new
17064 lines. Some of the lines at the top of the window might be
17065 reusable because they are not displaying changed text. Find the
17066 last row in W's current matrix not affected by changes at the
17067 start of current_buffer. Value is null if changes start in the
17068 first line of window. */
17069 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17070 if (last_unchanged_at_beg_row
)
17072 /* Avoid starting to display in the middle of a character, a TAB
17073 for instance. This is easier than to set up the iterator
17074 exactly, and it's not a frequent case, so the additional
17075 effort wouldn't really pay off. */
17076 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17077 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17078 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17079 --last_unchanged_at_beg_row
;
17081 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17084 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17086 start_pos
= it
.current
.pos
;
17088 /* Start displaying new lines in the desired matrix at the same
17089 vpos we would use in the current matrix, i.e. below
17090 last_unchanged_at_beg_row. */
17091 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17093 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17094 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17096 xassert (it
.hpos
== 0 && it
.current_x
== 0);
17100 /* There are no reusable lines at the start of the window.
17101 Start displaying in the first text line. */
17102 start_display (&it
, w
, start
);
17103 it
.vpos
= it
.first_vpos
;
17104 start_pos
= it
.current
.pos
;
17107 /* Find the first row that is not affected by changes at the end of
17108 the buffer. Value will be null if there is no unchanged row, in
17109 which case we must redisplay to the end of the window. delta
17110 will be set to the value by which buffer positions beginning with
17111 first_unchanged_at_end_row have to be adjusted due to text
17113 first_unchanged_at_end_row
17114 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17115 IF_DEBUG (debug_delta
= delta
);
17116 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17118 /* Set stop_pos to the buffer position up to which we will have to
17119 display new lines. If first_unchanged_at_end_row != NULL, this
17120 is the buffer position of the start of the line displayed in that
17121 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17122 that we don't stop at a buffer position. */
17124 if (first_unchanged_at_end_row
)
17126 xassert (last_unchanged_at_beg_row
== NULL
17127 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17129 /* If this is a continuation line, move forward to the next one
17130 that isn't. Changes in lines above affect this line.
17131 Caution: this may move first_unchanged_at_end_row to a row
17132 not displaying text. */
17133 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17134 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17135 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17136 < it
.last_visible_y
))
17137 ++first_unchanged_at_end_row
;
17139 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17140 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17141 >= it
.last_visible_y
))
17142 first_unchanged_at_end_row
= NULL
;
17145 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17147 first_unchanged_at_end_vpos
17148 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17149 xassert (stop_pos
>= Z
- END_UNCHANGED
);
17152 else if (last_unchanged_at_beg_row
== NULL
)
17158 /* Either there is no unchanged row at the end, or the one we have
17159 now displays text. This is a necessary condition for the window
17160 end pos calculation at the end of this function. */
17161 xassert (first_unchanged_at_end_row
== NULL
17162 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17164 debug_last_unchanged_at_beg_vpos
17165 = (last_unchanged_at_beg_row
17166 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17168 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17170 #endif /* GLYPH_DEBUG != 0 */
17173 /* Display new lines. Set last_text_row to the last new line
17174 displayed which has text on it, i.e. might end up as being the
17175 line where the window_end_vpos is. */
17176 w
->cursor
.vpos
= -1;
17177 last_text_row
= NULL
;
17178 overlay_arrow_seen
= 0;
17179 while (it
.current_y
< it
.last_visible_y
17180 && !fonts_changed_p
17181 && (first_unchanged_at_end_row
== NULL
17182 || IT_CHARPOS (it
) < stop_pos
))
17184 if (display_line (&it
))
17185 last_text_row
= it
.glyph_row
- 1;
17188 if (fonts_changed_p
)
17192 /* Compute differences in buffer positions, y-positions etc. for
17193 lines reused at the bottom of the window. Compute what we can
17195 if (first_unchanged_at_end_row
17196 /* No lines reused because we displayed everything up to the
17197 bottom of the window. */
17198 && it
.current_y
< it
.last_visible_y
)
17201 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17203 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17204 run
.current_y
= first_unchanged_at_end_row
->y
;
17205 run
.desired_y
= run
.current_y
+ dy
;
17206 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17210 delta
= delta_bytes
= dvpos
= dy
17211 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17212 first_unchanged_at_end_row
= NULL
;
17214 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17217 /* Find the cursor if not already found. We have to decide whether
17218 PT will appear on this window (it sometimes doesn't, but this is
17219 not a very frequent case.) This decision has to be made before
17220 the current matrix is altered. A value of cursor.vpos < 0 means
17221 that PT is either in one of the lines beginning at
17222 first_unchanged_at_end_row or below the window. Don't care for
17223 lines that might be displayed later at the window end; as
17224 mentioned, this is not a frequent case. */
17225 if (w
->cursor
.vpos
< 0)
17227 /* Cursor in unchanged rows at the top? */
17228 if (PT
< CHARPOS (start_pos
)
17229 && last_unchanged_at_beg_row
)
17231 row
= row_containing_pos (w
, PT
,
17232 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17233 last_unchanged_at_beg_row
+ 1, 0);
17235 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17238 /* Start from first_unchanged_at_end_row looking for PT. */
17239 else if (first_unchanged_at_end_row
)
17241 row
= row_containing_pos (w
, PT
- delta
,
17242 first_unchanged_at_end_row
, NULL
, 0);
17244 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17245 delta_bytes
, dy
, dvpos
);
17248 /* Give up if cursor was not found. */
17249 if (w
->cursor
.vpos
< 0)
17251 clear_glyph_matrix (w
->desired_matrix
);
17256 /* Don't let the cursor end in the scroll margins. */
17258 int this_scroll_margin
, cursor_height
;
17260 this_scroll_margin
=
17261 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17262 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17263 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17265 if ((w
->cursor
.y
< this_scroll_margin
17266 && CHARPOS (start
) > BEGV
)
17267 /* Old redisplay didn't take scroll margin into account at the bottom,
17268 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17269 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17270 ? cursor_height
+ this_scroll_margin
17271 : 1)) > it
.last_visible_y
)
17273 w
->cursor
.vpos
= -1;
17274 clear_glyph_matrix (w
->desired_matrix
);
17279 /* Scroll the display. Do it before changing the current matrix so
17280 that xterm.c doesn't get confused about where the cursor glyph is
17282 if (dy
&& run
.height
)
17286 if (FRAME_WINDOW_P (f
))
17288 FRAME_RIF (f
)->update_window_begin_hook (w
);
17289 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17290 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17291 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17295 /* Terminal frame. In this case, dvpos gives the number of
17296 lines to scroll by; dvpos < 0 means scroll up. */
17298 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17299 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17300 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17301 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17302 + window_internal_height (w
));
17304 #if defined (HAVE_GPM) || defined (MSDOS)
17305 x_clear_window_mouse_face (w
);
17307 /* Perform the operation on the screen. */
17310 /* Scroll last_unchanged_at_beg_row to the end of the
17311 window down dvpos lines. */
17312 set_terminal_window (f
, end
);
17314 /* On dumb terminals delete dvpos lines at the end
17315 before inserting dvpos empty lines. */
17316 if (!FRAME_SCROLL_REGION_OK (f
))
17317 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17319 /* Insert dvpos empty lines in front of
17320 last_unchanged_at_beg_row. */
17321 ins_del_lines (f
, from
, dvpos
);
17323 else if (dvpos
< 0)
17325 /* Scroll up last_unchanged_at_beg_vpos to the end of
17326 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17327 set_terminal_window (f
, end
);
17329 /* Delete dvpos lines in front of
17330 last_unchanged_at_beg_vpos. ins_del_lines will set
17331 the cursor to the given vpos and emit |dvpos| delete
17333 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17335 /* On a dumb terminal insert dvpos empty lines at the
17337 if (!FRAME_SCROLL_REGION_OK (f
))
17338 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17341 set_terminal_window (f
, 0);
17347 /* Shift reused rows of the current matrix to the right position.
17348 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17350 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17351 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17354 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17355 bottom_vpos
, dvpos
);
17356 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17359 else if (dvpos
> 0)
17361 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17362 bottom_vpos
, dvpos
);
17363 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17364 first_unchanged_at_end_vpos
+ dvpos
, 0);
17367 /* For frame-based redisplay, make sure that current frame and window
17368 matrix are in sync with respect to glyph memory. */
17369 if (!FRAME_WINDOW_P (f
))
17370 sync_frame_with_window_matrix_rows (w
);
17372 /* Adjust buffer positions in reused rows. */
17373 if (delta
|| delta_bytes
)
17374 increment_matrix_positions (current_matrix
,
17375 first_unchanged_at_end_vpos
+ dvpos
,
17376 bottom_vpos
, delta
, delta_bytes
);
17378 /* Adjust Y positions. */
17380 shift_glyph_matrix (w
, current_matrix
,
17381 first_unchanged_at_end_vpos
+ dvpos
,
17384 if (first_unchanged_at_end_row
)
17386 first_unchanged_at_end_row
+= dvpos
;
17387 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17388 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17389 first_unchanged_at_end_row
= NULL
;
17392 /* If scrolling up, there may be some lines to display at the end of
17394 last_text_row_at_end
= NULL
;
17397 /* Scrolling up can leave for example a partially visible line
17398 at the end of the window to be redisplayed. */
17399 /* Set last_row to the glyph row in the current matrix where the
17400 window end line is found. It has been moved up or down in
17401 the matrix by dvpos. */
17402 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17403 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17405 /* If last_row is the window end line, it should display text. */
17406 xassert (last_row
->displays_text_p
);
17408 /* If window end line was partially visible before, begin
17409 displaying at that line. Otherwise begin displaying with the
17410 line following it. */
17411 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17413 init_to_row_start (&it
, w
, last_row
);
17414 it
.vpos
= last_vpos
;
17415 it
.current_y
= last_row
->y
;
17419 init_to_row_end (&it
, w
, last_row
);
17420 it
.vpos
= 1 + last_vpos
;
17421 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17425 /* We may start in a continuation line. If so, we have to
17426 get the right continuation_lines_width and current_x. */
17427 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17428 it
.hpos
= it
.current_x
= 0;
17430 /* Display the rest of the lines at the window end. */
17431 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17432 while (it
.current_y
< it
.last_visible_y
17433 && !fonts_changed_p
)
17435 /* Is it always sure that the display agrees with lines in
17436 the current matrix? I don't think so, so we mark rows
17437 displayed invalid in the current matrix by setting their
17438 enabled_p flag to zero. */
17439 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17440 if (display_line (&it
))
17441 last_text_row_at_end
= it
.glyph_row
- 1;
17445 /* Update window_end_pos and window_end_vpos. */
17446 if (first_unchanged_at_end_row
17447 && !last_text_row_at_end
)
17449 /* Window end line if one of the preserved rows from the current
17450 matrix. Set row to the last row displaying text in current
17451 matrix starting at first_unchanged_at_end_row, after
17453 xassert (first_unchanged_at_end_row
->displays_text_p
);
17454 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17455 first_unchanged_at_end_row
);
17456 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17458 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17459 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17461 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17462 xassert (w
->window_end_bytepos
>= 0);
17463 IF_DEBUG (debug_method_add (w
, "A"));
17465 else if (last_text_row_at_end
)
17468 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17469 w
->window_end_bytepos
17470 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17472 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17473 xassert (w
->window_end_bytepos
>= 0);
17474 IF_DEBUG (debug_method_add (w
, "B"));
17476 else if (last_text_row
)
17478 /* We have displayed either to the end of the window or at the
17479 end of the window, i.e. the last row with text is to be found
17480 in the desired matrix. */
17482 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17483 w
->window_end_bytepos
17484 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17486 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17487 xassert (w
->window_end_bytepos
>= 0);
17489 else if (first_unchanged_at_end_row
== NULL
17490 && last_text_row
== NULL
17491 && last_text_row_at_end
== NULL
)
17493 /* Displayed to end of window, but no line containing text was
17494 displayed. Lines were deleted at the end of the window. */
17495 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17496 int vpos
= XFASTINT (w
->window_end_vpos
);
17497 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17498 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17501 row
== NULL
&& vpos
>= first_vpos
;
17502 --vpos
, --current_row
, --desired_row
)
17504 if (desired_row
->enabled_p
)
17506 if (desired_row
->displays_text_p
)
17509 else if (current_row
->displays_text_p
)
17513 xassert (row
!= NULL
);
17514 w
->window_end_vpos
= make_number (vpos
+ 1);
17515 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17516 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17517 xassert (w
->window_end_bytepos
>= 0);
17518 IF_DEBUG (debug_method_add (w
, "C"));
17523 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17524 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17526 /* Record that display has not been completed. */
17527 w
->window_end_valid
= Qnil
;
17528 w
->desired_matrix
->no_scrolling_p
= 1;
17536 /***********************************************************************
17537 More debugging support
17538 ***********************************************************************/
17542 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17543 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17544 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17547 /* Dump the contents of glyph matrix MATRIX on stderr.
17549 GLYPHS 0 means don't show glyph contents.
17550 GLYPHS 1 means show glyphs in short form
17551 GLYPHS > 1 means show glyphs in long form. */
17554 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17557 for (i
= 0; i
< matrix
->nrows
; ++i
)
17558 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17562 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17563 the glyph row and area where the glyph comes from. */
17566 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17568 if (glyph
->type
== CHAR_GLYPH
)
17571 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17572 glyph
- row
->glyphs
[TEXT_AREA
],
17575 (BUFFERP (glyph
->object
)
17577 : (STRINGP (glyph
->object
)
17580 glyph
->pixel_width
,
17582 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17586 glyph
->left_box_line_p
,
17587 glyph
->right_box_line_p
);
17589 else if (glyph
->type
== STRETCH_GLYPH
)
17592 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17593 glyph
- row
->glyphs
[TEXT_AREA
],
17596 (BUFFERP (glyph
->object
)
17598 : (STRINGP (glyph
->object
)
17601 glyph
->pixel_width
,
17605 glyph
->left_box_line_p
,
17606 glyph
->right_box_line_p
);
17608 else if (glyph
->type
== IMAGE_GLYPH
)
17611 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17612 glyph
- row
->glyphs
[TEXT_AREA
],
17615 (BUFFERP (glyph
->object
)
17617 : (STRINGP (glyph
->object
)
17620 glyph
->pixel_width
,
17624 glyph
->left_box_line_p
,
17625 glyph
->right_box_line_p
);
17627 else if (glyph
->type
== COMPOSITE_GLYPH
)
17630 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17631 glyph
- row
->glyphs
[TEXT_AREA
],
17634 (BUFFERP (glyph
->object
)
17636 : (STRINGP (glyph
->object
)
17639 glyph
->pixel_width
,
17641 if (glyph
->u
.cmp
.automatic
)
17644 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17645 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17647 glyph
->left_box_line_p
,
17648 glyph
->right_box_line_p
);
17653 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17654 GLYPHS 0 means don't show glyph contents.
17655 GLYPHS 1 means show glyphs in short form
17656 GLYPHS > 1 means show glyphs in long form. */
17659 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17663 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17664 fprintf (stderr
, "======================================================================\n");
17666 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17667 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17669 MATRIX_ROW_START_CHARPOS (row
),
17670 MATRIX_ROW_END_CHARPOS (row
),
17671 row
->used
[TEXT_AREA
],
17672 row
->contains_overlapping_glyphs_p
,
17674 row
->truncated_on_left_p
,
17675 row
->truncated_on_right_p
,
17677 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17678 row
->displays_text_p
,
17681 row
->ends_in_middle_of_char_p
,
17682 row
->starts_in_middle_of_char_p
,
17688 row
->visible_height
,
17691 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17692 row
->end
.overlay_string_index
,
17693 row
->continuation_lines_width
);
17694 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17695 CHARPOS (row
->start
.string_pos
),
17696 CHARPOS (row
->end
.string_pos
));
17697 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17698 row
->end
.dpvec_index
);
17705 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17707 struct glyph
*glyph
= row
->glyphs
[area
];
17708 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17710 /* Glyph for a line end in text. */
17711 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17714 if (glyph
< glyph_end
)
17715 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
17717 for (; glyph
< glyph_end
; ++glyph
)
17718 dump_glyph (row
, glyph
, area
);
17721 else if (glyphs
== 1)
17725 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17727 char *s
= (char *) alloca (row
->used
[area
] + 1);
17730 for (i
= 0; i
< row
->used
[area
]; ++i
)
17732 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17733 if (glyph
->type
== CHAR_GLYPH
17734 && glyph
->u
.ch
< 0x80
17735 && glyph
->u
.ch
>= ' ')
17736 s
[i
] = glyph
->u
.ch
;
17742 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17748 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17749 Sdump_glyph_matrix
, 0, 1, "p",
17750 doc
: /* Dump the current matrix of the selected window to stderr.
17751 Shows contents of glyph row structures. With non-nil
17752 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17753 glyphs in short form, otherwise show glyphs in long form. */)
17754 (Lisp_Object glyphs
)
17756 struct window
*w
= XWINDOW (selected_window
);
17757 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17759 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17760 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17761 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17762 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17763 fprintf (stderr
, "=============================================\n");
17764 dump_glyph_matrix (w
->current_matrix
,
17765 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17770 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17771 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17774 struct frame
*f
= XFRAME (selected_frame
);
17775 dump_glyph_matrix (f
->current_matrix
, 1);
17780 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17781 doc
: /* Dump glyph row ROW to stderr.
17782 GLYPH 0 means don't dump glyphs.
17783 GLYPH 1 means dump glyphs in short form.
17784 GLYPH > 1 or omitted means dump glyphs in long form. */)
17785 (Lisp_Object row
, Lisp_Object glyphs
)
17787 struct glyph_matrix
*matrix
;
17790 CHECK_NUMBER (row
);
17791 matrix
= XWINDOW (selected_window
)->current_matrix
;
17793 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17794 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17796 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17801 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17802 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17803 GLYPH 0 means don't dump glyphs.
17804 GLYPH 1 means dump glyphs in short form.
17805 GLYPH > 1 or omitted means dump glyphs in long form. */)
17806 (Lisp_Object row
, Lisp_Object glyphs
)
17808 struct frame
*sf
= SELECTED_FRAME ();
17809 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17812 CHECK_NUMBER (row
);
17814 if (vpos
>= 0 && vpos
< m
->nrows
)
17815 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17816 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17821 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17822 doc
: /* Toggle tracing of redisplay.
17823 With ARG, turn tracing on if and only if ARG is positive. */)
17827 trace_redisplay_p
= !trace_redisplay_p
;
17830 arg
= Fprefix_numeric_value (arg
);
17831 trace_redisplay_p
= XINT (arg
) > 0;
17838 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17839 doc
: /* Like `format', but print result to stderr.
17840 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17841 (ptrdiff_t nargs
, Lisp_Object
*args
)
17843 Lisp_Object s
= Fformat (nargs
, args
);
17844 fprintf (stderr
, "%s", SDATA (s
));
17848 #endif /* GLYPH_DEBUG */
17852 /***********************************************************************
17853 Building Desired Matrix Rows
17854 ***********************************************************************/
17856 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17857 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17859 static struct glyph_row
*
17860 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17862 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17863 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17864 struct buffer
*old
= current_buffer
;
17865 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17866 int arrow_len
= SCHARS (overlay_arrow_string
);
17867 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17868 const unsigned char *p
;
17871 int n_glyphs_before
;
17873 set_buffer_temp (buffer
);
17874 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17875 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17876 SET_TEXT_POS (it
.position
, 0, 0);
17878 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17880 while (p
< arrow_end
)
17882 Lisp_Object face
, ilisp
;
17884 /* Get the next character. */
17886 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17889 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17890 if (! ASCII_CHAR_P (it
.c
))
17891 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17895 /* Get its face. */
17896 ilisp
= make_number (p
- arrow_string
);
17897 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17898 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17900 /* Compute its width, get its glyphs. */
17901 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17902 SET_TEXT_POS (it
.position
, -1, -1);
17903 PRODUCE_GLYPHS (&it
);
17905 /* If this character doesn't fit any more in the line, we have
17906 to remove some glyphs. */
17907 if (it
.current_x
> it
.last_visible_x
)
17909 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17914 set_buffer_temp (old
);
17915 return it
.glyph_row
;
17919 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17920 glyphs are only inserted for terminal frames since we can't really
17921 win with truncation glyphs when partially visible glyphs are
17922 involved. Which glyphs to insert is determined by
17923 produce_special_glyphs. */
17926 insert_left_trunc_glyphs (struct it
*it
)
17928 struct it truncate_it
;
17929 struct glyph
*from
, *end
, *to
, *toend
;
17931 xassert (!FRAME_WINDOW_P (it
->f
));
17933 /* Get the truncation glyphs. */
17935 truncate_it
.current_x
= 0;
17936 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17937 truncate_it
.glyph_row
= &scratch_glyph_row
;
17938 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17939 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17940 truncate_it
.object
= make_number (0);
17941 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17943 /* Overwrite glyphs from IT with truncation glyphs. */
17944 if (!it
->glyph_row
->reversed_p
)
17946 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17947 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17948 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17949 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17954 /* There may be padding glyphs left over. Overwrite them too. */
17955 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17957 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17963 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17967 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17968 that back to front. */
17969 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17970 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17971 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17972 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17974 while (from
>= end
&& to
>= toend
)
17976 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17979 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17980 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17981 while (from
>= end
&& to
>= toend
)
17986 /* Need to free some room before prepending additional
17988 int move_by
= from
- end
+ 1;
17989 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17990 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17992 for ( ; g
>= g0
; g
--)
17994 while (from
>= end
)
17996 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18001 /* Compute the hash code for ROW. */
18003 row_hash (struct glyph_row
*row
)
18006 unsigned hashval
= 0;
18008 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18009 for (k
= 0; k
< row
->used
[area
]; ++k
)
18010 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18011 + row
->glyphs
[area
][k
].u
.val
18012 + row
->glyphs
[area
][k
].face_id
18013 + row
->glyphs
[area
][k
].padding_p
18014 + (row
->glyphs
[area
][k
].type
<< 2));
18019 /* Compute the pixel height and width of IT->glyph_row.
18021 Most of the time, ascent and height of a display line will be equal
18022 to the max_ascent and max_height values of the display iterator
18023 structure. This is not the case if
18025 1. We hit ZV without displaying anything. In this case, max_ascent
18026 and max_height will be zero.
18028 2. We have some glyphs that don't contribute to the line height.
18029 (The glyph row flag contributes_to_line_height_p is for future
18030 pixmap extensions).
18032 The first case is easily covered by using default values because in
18033 these cases, the line height does not really matter, except that it
18034 must not be zero. */
18037 compute_line_metrics (struct it
*it
)
18039 struct glyph_row
*row
= it
->glyph_row
;
18041 if (FRAME_WINDOW_P (it
->f
))
18043 int i
, min_y
, max_y
;
18045 /* The line may consist of one space only, that was added to
18046 place the cursor on it. If so, the row's height hasn't been
18048 if (row
->height
== 0)
18050 if (it
->max_ascent
+ it
->max_descent
== 0)
18051 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18052 row
->ascent
= it
->max_ascent
;
18053 row
->height
= it
->max_ascent
+ it
->max_descent
;
18054 row
->phys_ascent
= it
->max_phys_ascent
;
18055 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18056 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18059 /* Compute the width of this line. */
18060 row
->pixel_width
= row
->x
;
18061 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18062 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18064 xassert (row
->pixel_width
>= 0);
18065 xassert (row
->ascent
>= 0 && row
->height
> 0);
18067 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18068 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18070 /* If first line's physical ascent is larger than its logical
18071 ascent, use the physical ascent, and make the row taller.
18072 This makes accented characters fully visible. */
18073 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18074 && row
->phys_ascent
> row
->ascent
)
18076 row
->height
+= row
->phys_ascent
- row
->ascent
;
18077 row
->ascent
= row
->phys_ascent
;
18080 /* Compute how much of the line is visible. */
18081 row
->visible_height
= row
->height
;
18083 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18084 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18086 if (row
->y
< min_y
)
18087 row
->visible_height
-= min_y
- row
->y
;
18088 if (row
->y
+ row
->height
> max_y
)
18089 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18093 row
->pixel_width
= row
->used
[TEXT_AREA
];
18094 if (row
->continued_p
)
18095 row
->pixel_width
-= it
->continuation_pixel_width
;
18096 else if (row
->truncated_on_right_p
)
18097 row
->pixel_width
-= it
->truncation_pixel_width
;
18098 row
->ascent
= row
->phys_ascent
= 0;
18099 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18100 row
->extra_line_spacing
= 0;
18103 /* Compute a hash code for this row. */
18104 row
->hash
= row_hash (row
);
18106 it
->max_ascent
= it
->max_descent
= 0;
18107 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18111 /* Append one space to the glyph row of iterator IT if doing a
18112 window-based redisplay. The space has the same face as
18113 IT->face_id. Value is non-zero if a space was added.
18115 This function is called to make sure that there is always one glyph
18116 at the end of a glyph row that the cursor can be set on under
18117 window-systems. (If there weren't such a glyph we would not know
18118 how wide and tall a box cursor should be displayed).
18120 At the same time this space let's a nicely handle clearing to the
18121 end of the line if the row ends in italic text. */
18124 append_space_for_newline (struct it
*it
, int default_face_p
)
18126 if (FRAME_WINDOW_P (it
->f
))
18128 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18130 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18131 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18133 /* Save some values that must not be changed.
18134 Must save IT->c and IT->len because otherwise
18135 ITERATOR_AT_END_P wouldn't work anymore after
18136 append_space_for_newline has been called. */
18137 enum display_element_type saved_what
= it
->what
;
18138 int saved_c
= it
->c
, saved_len
= it
->len
;
18139 int saved_char_to_display
= it
->char_to_display
;
18140 int saved_x
= it
->current_x
;
18141 int saved_face_id
= it
->face_id
;
18142 struct text_pos saved_pos
;
18143 Lisp_Object saved_object
;
18146 saved_object
= it
->object
;
18147 saved_pos
= it
->position
;
18149 it
->what
= IT_CHARACTER
;
18150 memset (&it
->position
, 0, sizeof it
->position
);
18151 it
->object
= make_number (0);
18152 it
->c
= it
->char_to_display
= ' ';
18155 if (default_face_p
)
18156 it
->face_id
= DEFAULT_FACE_ID
;
18157 else if (it
->face_before_selective_p
)
18158 it
->face_id
= it
->saved_face_id
;
18159 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18160 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18162 PRODUCE_GLYPHS (it
);
18164 it
->override_ascent
= -1;
18165 it
->constrain_row_ascent_descent_p
= 0;
18166 it
->current_x
= saved_x
;
18167 it
->object
= saved_object
;
18168 it
->position
= saved_pos
;
18169 it
->what
= saved_what
;
18170 it
->face_id
= saved_face_id
;
18171 it
->len
= saved_len
;
18173 it
->char_to_display
= saved_char_to_display
;
18182 /* Extend the face of the last glyph in the text area of IT->glyph_row
18183 to the end of the display line. Called from display_line. If the
18184 glyph row is empty, add a space glyph to it so that we know the
18185 face to draw. Set the glyph row flag fill_line_p. If the glyph
18186 row is R2L, prepend a stretch glyph to cover the empty space to the
18187 left of the leftmost glyph. */
18190 extend_face_to_end_of_line (struct it
*it
)
18193 struct frame
*f
= it
->f
;
18195 /* If line is already filled, do nothing. Non window-system frames
18196 get a grace of one more ``pixel'' because their characters are
18197 1-``pixel'' wide, so they hit the equality too early. This grace
18198 is needed only for R2L rows that are not continued, to produce
18199 one extra blank where we could display the cursor. */
18200 if (it
->current_x
>= it
->last_visible_x
18201 + (!FRAME_WINDOW_P (f
)
18202 && it
->glyph_row
->reversed_p
18203 && !it
->glyph_row
->continued_p
))
18206 /* Face extension extends the background and box of IT->face_id
18207 to the end of the line. If the background equals the background
18208 of the frame, we don't have to do anything. */
18209 if (it
->face_before_selective_p
)
18210 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18212 face
= FACE_FROM_ID (f
, it
->face_id
);
18214 if (FRAME_WINDOW_P (f
)
18215 && it
->glyph_row
->displays_text_p
18216 && face
->box
== FACE_NO_BOX
18217 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18219 && !it
->glyph_row
->reversed_p
)
18222 /* Set the glyph row flag indicating that the face of the last glyph
18223 in the text area has to be drawn to the end of the text area. */
18224 it
->glyph_row
->fill_line_p
= 1;
18226 /* If current character of IT is not ASCII, make sure we have the
18227 ASCII face. This will be automatically undone the next time
18228 get_next_display_element returns a multibyte character. Note
18229 that the character will always be single byte in unibyte
18231 if (!ASCII_CHAR_P (it
->c
))
18233 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18236 if (FRAME_WINDOW_P (f
))
18238 /* If the row is empty, add a space with the current face of IT,
18239 so that we know which face to draw. */
18240 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18242 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18243 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
18244 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18246 #ifdef HAVE_WINDOW_SYSTEM
18247 if (it
->glyph_row
->reversed_p
)
18249 /* Prepend a stretch glyph to the row, such that the
18250 rightmost glyph will be drawn flushed all the way to the
18251 right margin of the window. The stretch glyph that will
18252 occupy the empty space, if any, to the left of the
18254 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18255 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18256 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18258 int row_width
, stretch_ascent
, stretch_width
;
18259 struct text_pos saved_pos
;
18260 int saved_face_id
, saved_avoid_cursor
;
18262 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18263 row_width
+= g
->pixel_width
;
18264 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18265 if (stretch_width
> 0)
18268 (((it
->ascent
+ it
->descent
)
18269 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18270 saved_pos
= it
->position
;
18271 memset (&it
->position
, 0, sizeof it
->position
);
18272 saved_avoid_cursor
= it
->avoid_cursor_p
;
18273 it
->avoid_cursor_p
= 1;
18274 saved_face_id
= it
->face_id
;
18275 /* The last row's stretch glyph should get the default
18276 face, to avoid painting the rest of the window with
18277 the region face, if the region ends at ZV. */
18278 if (it
->glyph_row
->ends_at_zv_p
)
18279 it
->face_id
= DEFAULT_FACE_ID
;
18281 it
->face_id
= face
->id
;
18282 append_stretch_glyph (it
, make_number (0), stretch_width
,
18283 it
->ascent
+ it
->descent
, stretch_ascent
);
18284 it
->position
= saved_pos
;
18285 it
->avoid_cursor_p
= saved_avoid_cursor
;
18286 it
->face_id
= saved_face_id
;
18289 #endif /* HAVE_WINDOW_SYSTEM */
18293 /* Save some values that must not be changed. */
18294 int saved_x
= it
->current_x
;
18295 struct text_pos saved_pos
;
18296 Lisp_Object saved_object
;
18297 enum display_element_type saved_what
= it
->what
;
18298 int saved_face_id
= it
->face_id
;
18300 saved_object
= it
->object
;
18301 saved_pos
= it
->position
;
18303 it
->what
= IT_CHARACTER
;
18304 memset (&it
->position
, 0, sizeof it
->position
);
18305 it
->object
= make_number (0);
18306 it
->c
= it
->char_to_display
= ' ';
18308 /* The last row's blank glyphs should get the default face, to
18309 avoid painting the rest of the window with the region face,
18310 if the region ends at ZV. */
18311 if (it
->glyph_row
->ends_at_zv_p
)
18312 it
->face_id
= DEFAULT_FACE_ID
;
18314 it
->face_id
= face
->id
;
18316 PRODUCE_GLYPHS (it
);
18318 while (it
->current_x
<= it
->last_visible_x
)
18319 PRODUCE_GLYPHS (it
);
18321 /* Don't count these blanks really. It would let us insert a left
18322 truncation glyph below and make us set the cursor on them, maybe. */
18323 it
->current_x
= saved_x
;
18324 it
->object
= saved_object
;
18325 it
->position
= saved_pos
;
18326 it
->what
= saved_what
;
18327 it
->face_id
= saved_face_id
;
18332 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18333 trailing whitespace. */
18336 trailing_whitespace_p (ptrdiff_t charpos
)
18338 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18341 while (bytepos
< ZV_BYTE
18342 && (c
= FETCH_CHAR (bytepos
),
18343 c
== ' ' || c
== '\t'))
18346 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18348 if (bytepos
!= PT_BYTE
)
18355 /* Highlight trailing whitespace, if any, in ROW. */
18358 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18360 int used
= row
->used
[TEXT_AREA
];
18364 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18365 struct glyph
*glyph
= start
+ used
- 1;
18367 if (row
->reversed_p
)
18369 /* Right-to-left rows need to be processed in the opposite
18370 direction, so swap the edge pointers. */
18372 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18375 /* Skip over glyphs inserted to display the cursor at the
18376 end of a line, for extending the face of the last glyph
18377 to the end of the line on terminals, and for truncation
18378 and continuation glyphs. */
18379 if (!row
->reversed_p
)
18381 while (glyph
>= start
18382 && glyph
->type
== CHAR_GLYPH
18383 && INTEGERP (glyph
->object
))
18388 while (glyph
<= start
18389 && glyph
->type
== CHAR_GLYPH
18390 && INTEGERP (glyph
->object
))
18394 /* If last glyph is a space or stretch, and it's trailing
18395 whitespace, set the face of all trailing whitespace glyphs in
18396 IT->glyph_row to `trailing-whitespace'. */
18397 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18398 && BUFFERP (glyph
->object
)
18399 && (glyph
->type
== STRETCH_GLYPH
18400 || (glyph
->type
== CHAR_GLYPH
18401 && glyph
->u
.ch
== ' '))
18402 && trailing_whitespace_p (glyph
->charpos
))
18404 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18408 if (!row
->reversed_p
)
18410 while (glyph
>= start
18411 && BUFFERP (glyph
->object
)
18412 && (glyph
->type
== STRETCH_GLYPH
18413 || (glyph
->type
== CHAR_GLYPH
18414 && glyph
->u
.ch
== ' ')))
18415 (glyph
--)->face_id
= face_id
;
18419 while (glyph
<= start
18420 && BUFFERP (glyph
->object
)
18421 && (glyph
->type
== STRETCH_GLYPH
18422 || (glyph
->type
== CHAR_GLYPH
18423 && glyph
->u
.ch
== ' ')))
18424 (glyph
++)->face_id
= face_id
;
18431 /* Value is non-zero if glyph row ROW should be
18432 used to hold the cursor. */
18435 cursor_row_p (struct glyph_row
*row
)
18439 if (PT
== CHARPOS (row
->end
.pos
)
18440 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18442 /* Suppose the row ends on a string.
18443 Unless the row is continued, that means it ends on a newline
18444 in the string. If it's anything other than a display string
18445 (e.g. a before-string from an overlay), we don't want the
18446 cursor there. (This heuristic seems to give the optimal
18447 behavior for the various types of multi-line strings.) */
18448 if (CHARPOS (row
->end
.string_pos
) >= 0)
18450 if (row
->continued_p
)
18454 /* Check for `display' property. */
18455 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18456 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18457 struct glyph
*glyph
;
18460 for (glyph
= end
; glyph
>= beg
; --glyph
)
18461 if (STRINGP (glyph
->object
))
18464 = Fget_char_property (make_number (PT
),
18468 && display_prop_string_p (prop
, glyph
->object
));
18473 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18475 /* If the row ends in middle of a real character,
18476 and the line is continued, we want the cursor here.
18477 That's because CHARPOS (ROW->end.pos) would equal
18478 PT if PT is before the character. */
18479 if (!row
->ends_in_ellipsis_p
)
18480 result
= row
->continued_p
;
18482 /* If the row ends in an ellipsis, then
18483 CHARPOS (ROW->end.pos) will equal point after the
18484 invisible text. We want that position to be displayed
18485 after the ellipsis. */
18488 /* If the row ends at ZV, display the cursor at the end of that
18489 row instead of at the start of the row below. */
18490 else if (row
->ends_at_zv_p
)
18501 /* Push the property PROP so that it will be rendered at the current
18502 position in IT. Return 1 if PROP was successfully pushed, 0
18503 otherwise. Called from handle_line_prefix to handle the
18504 `line-prefix' and `wrap-prefix' properties. */
18507 push_display_prop (struct it
*it
, Lisp_Object prop
)
18509 struct text_pos pos
=
18510 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18512 xassert (it
->method
== GET_FROM_BUFFER
18513 || it
->method
== GET_FROM_DISPLAY_VECTOR
18514 || it
->method
== GET_FROM_STRING
);
18516 /* We need to save the current buffer/string position, so it will be
18517 restored by pop_it, because iterate_out_of_display_property
18518 depends on that being set correctly, but some situations leave
18519 it->position not yet set when this function is called. */
18520 push_it (it
, &pos
);
18522 if (STRINGP (prop
))
18524 if (SCHARS (prop
) == 0)
18531 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18532 it
->current
.overlay_string_index
= -1;
18533 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18534 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18535 it
->method
= GET_FROM_STRING
;
18536 it
->stop_charpos
= 0;
18538 it
->base_level_stop
= 0;
18540 /* Force paragraph direction to be that of the parent
18542 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18543 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18545 it
->paragraph_embedding
= L2R
;
18547 /* Set up the bidi iterator for this display string. */
18550 it
->bidi_it
.string
.lstring
= it
->string
;
18551 it
->bidi_it
.string
.s
= NULL
;
18552 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18553 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18554 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18555 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18556 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18559 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18561 it
->method
= GET_FROM_STRETCH
;
18564 #ifdef HAVE_WINDOW_SYSTEM
18565 else if (IMAGEP (prop
))
18567 it
->what
= IT_IMAGE
;
18568 it
->image_id
= lookup_image (it
->f
, prop
);
18569 it
->method
= GET_FROM_IMAGE
;
18571 #endif /* HAVE_WINDOW_SYSTEM */
18574 pop_it (it
); /* bogus display property, give up */
18581 /* Return the character-property PROP at the current position in IT. */
18584 get_it_property (struct it
*it
, Lisp_Object prop
)
18586 Lisp_Object position
;
18588 if (STRINGP (it
->object
))
18589 position
= make_number (IT_STRING_CHARPOS (*it
));
18590 else if (BUFFERP (it
->object
))
18591 position
= make_number (IT_CHARPOS (*it
));
18595 return Fget_char_property (position
, prop
, it
->object
);
18598 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18601 handle_line_prefix (struct it
*it
)
18603 Lisp_Object prefix
;
18605 if (it
->continuation_lines_width
> 0)
18607 prefix
= get_it_property (it
, Qwrap_prefix
);
18609 prefix
= Vwrap_prefix
;
18613 prefix
= get_it_property (it
, Qline_prefix
);
18615 prefix
= Vline_prefix
;
18617 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
18619 /* If the prefix is wider than the window, and we try to wrap
18620 it, it would acquire its own wrap prefix, and so on till the
18621 iterator stack overflows. So, don't wrap the prefix. */
18622 it
->line_wrap
= TRUNCATE
;
18623 it
->avoid_cursor_p
= 1;
18629 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18630 only for R2L lines from display_line and display_string, when they
18631 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18632 the line/string needs to be continued on the next glyph row. */
18634 unproduce_glyphs (struct it
*it
, int n
)
18636 struct glyph
*glyph
, *end
;
18638 xassert (it
->glyph_row
);
18639 xassert (it
->glyph_row
->reversed_p
);
18640 xassert (it
->area
== TEXT_AREA
);
18641 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18643 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18644 n
= it
->glyph_row
->used
[TEXT_AREA
];
18645 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18646 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18647 for ( ; glyph
< end
; glyph
++)
18648 glyph
[-n
] = *glyph
;
18651 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18652 and ROW->maxpos. */
18654 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18655 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18656 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18658 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18659 lines' rows is implemented for bidi-reordered rows. */
18661 /* ROW->minpos is the value of min_pos, the minimal buffer position
18662 we have in ROW, or ROW->start.pos if that is smaller. */
18663 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18664 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18666 /* We didn't find buffer positions smaller than ROW->start, or
18667 didn't find _any_ valid buffer positions in any of the glyphs,
18668 so we must trust the iterator's computed positions. */
18669 row
->minpos
= row
->start
.pos
;
18672 max_pos
= CHARPOS (it
->current
.pos
);
18673 max_bpos
= BYTEPOS (it
->current
.pos
);
18676 /* Here are the various use-cases for ending the row, and the
18677 corresponding values for ROW->maxpos:
18679 Line ends in a newline from buffer eol_pos + 1
18680 Line is continued from buffer max_pos + 1
18681 Line is truncated on right it->current.pos
18682 Line ends in a newline from string max_pos + 1(*)
18683 (*) + 1 only when line ends in a forward scan
18684 Line is continued from string max_pos
18685 Line is continued from display vector max_pos
18686 Line is entirely from a string min_pos == max_pos
18687 Line is entirely from a display vector min_pos == max_pos
18688 Line that ends at ZV ZV
18690 If you discover other use-cases, please add them here as
18692 if (row
->ends_at_zv_p
)
18693 row
->maxpos
= it
->current
.pos
;
18694 else if (row
->used
[TEXT_AREA
])
18696 int seen_this_string
= 0;
18697 struct glyph_row
*r1
= row
- 1;
18699 /* Did we see the same display string on the previous row? */
18700 if (STRINGP (it
->object
)
18701 /* this is not the first row */
18702 && row
> it
->w
->desired_matrix
->rows
18703 /* previous row is not the header line */
18704 && !r1
->mode_line_p
18705 /* previous row also ends in a newline from a string */
18706 && r1
->ends_in_newline_from_string_p
)
18708 struct glyph
*start
, *end
;
18710 /* Search for the last glyph of the previous row that came
18711 from buffer or string. Depending on whether the row is
18712 L2R or R2L, we need to process it front to back or the
18713 other way round. */
18714 if (!r1
->reversed_p
)
18716 start
= r1
->glyphs
[TEXT_AREA
];
18717 end
= start
+ r1
->used
[TEXT_AREA
];
18718 /* Glyphs inserted by redisplay have an integer (zero)
18719 as their object. */
18721 && INTEGERP ((end
- 1)->object
)
18722 && (end
- 1)->charpos
<= 0)
18726 if (EQ ((end
- 1)->object
, it
->object
))
18727 seen_this_string
= 1;
18730 /* If all the glyphs of the previous row were inserted
18731 by redisplay, it means the previous row was
18732 produced from a single newline, which is only
18733 possible if that newline came from the same string
18734 as the one which produced this ROW. */
18735 seen_this_string
= 1;
18739 end
= r1
->glyphs
[TEXT_AREA
] - 1;
18740 start
= end
+ r1
->used
[TEXT_AREA
];
18742 && INTEGERP ((end
+ 1)->object
)
18743 && (end
+ 1)->charpos
<= 0)
18747 if (EQ ((end
+ 1)->object
, it
->object
))
18748 seen_this_string
= 1;
18751 seen_this_string
= 1;
18754 /* Take note of each display string that covers a newline only
18755 once, the first time we see it. This is for when a display
18756 string includes more than one newline in it. */
18757 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
18759 /* If we were scanning the buffer forward when we displayed
18760 the string, we want to account for at least one buffer
18761 position that belongs to this row (position covered by
18762 the display string), so that cursor positioning will
18763 consider this row as a candidate when point is at the end
18764 of the visual line represented by this row. This is not
18765 required when scanning back, because max_pos will already
18766 have a much larger value. */
18767 if (CHARPOS (row
->end
.pos
) > max_pos
)
18768 INC_BOTH (max_pos
, max_bpos
);
18769 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18771 else if (CHARPOS (it
->eol_pos
) > 0)
18772 SET_TEXT_POS (row
->maxpos
,
18773 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
18774 else if (row
->continued_p
)
18776 /* If max_pos is different from IT's current position, it
18777 means IT->method does not belong to the display element
18778 at max_pos. However, it also means that the display
18779 element at max_pos was displayed in its entirety on this
18780 line, which is equivalent to saying that the next line
18781 starts at the next buffer position. */
18782 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
18783 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18786 INC_BOTH (max_pos
, max_bpos
);
18787 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18790 else if (row
->truncated_on_right_p
)
18791 /* display_line already called reseat_at_next_visible_line_start,
18792 which puts the iterator at the beginning of the next line, in
18793 the logical order. */
18794 row
->maxpos
= it
->current
.pos
;
18795 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
18796 /* A line that is entirely from a string/image/stretch... */
18797 row
->maxpos
= row
->minpos
;
18802 row
->maxpos
= it
->current
.pos
;
18805 /* Construct the glyph row IT->glyph_row in the desired matrix of
18806 IT->w from text at the current position of IT. See dispextern.h
18807 for an overview of struct it. Value is non-zero if
18808 IT->glyph_row displays text, as opposed to a line displaying ZV
18812 display_line (struct it
*it
)
18814 struct glyph_row
*row
= it
->glyph_row
;
18815 Lisp_Object overlay_arrow_string
;
18817 void *wrap_data
= NULL
;
18818 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
18819 int wrap_row_used
= -1;
18820 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
18821 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
18822 int wrap_row_extra_line_spacing
IF_LINT (= 0);
18823 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
18824 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
18826 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
18827 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18829 /* We always start displaying at hpos zero even if hscrolled. */
18830 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18832 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18833 >= it
->w
->desired_matrix
->nrows
)
18835 it
->w
->nrows_scale_factor
++;
18836 fonts_changed_p
= 1;
18840 /* Is IT->w showing the region? */
18841 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18843 /* Clear the result glyph row and enable it. */
18844 prepare_desired_row (row
);
18846 row
->y
= it
->current_y
;
18847 row
->start
= it
->start
;
18848 row
->continuation_lines_width
= it
->continuation_lines_width
;
18849 row
->displays_text_p
= 1;
18850 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18851 it
->starts_in_middle_of_char_p
= 0;
18853 /* Arrange the overlays nicely for our purposes. Usually, we call
18854 display_line on only one line at a time, in which case this
18855 can't really hurt too much, or we call it on lines which appear
18856 one after another in the buffer, in which case all calls to
18857 recenter_overlay_lists but the first will be pretty cheap. */
18858 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18860 /* Move over display elements that are not visible because we are
18861 hscrolled. This may stop at an x-position < IT->first_visible_x
18862 if the first glyph is partially visible or if we hit a line end. */
18863 if (it
->current_x
< it
->first_visible_x
)
18865 this_line_min_pos
= row
->start
.pos
;
18866 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18867 MOVE_TO_POS
| MOVE_TO_X
);
18868 /* Record the smallest positions seen while we moved over
18869 display elements that are not visible. This is needed by
18870 redisplay_internal for optimizing the case where the cursor
18871 stays inside the same line. The rest of this function only
18872 considers positions that are actually displayed, so
18873 RECORD_MAX_MIN_POS will not otherwise record positions that
18874 are hscrolled to the left of the left edge of the window. */
18875 min_pos
= CHARPOS (this_line_min_pos
);
18876 min_bpos
= BYTEPOS (this_line_min_pos
);
18880 /* We only do this when not calling `move_it_in_display_line_to'
18881 above, because move_it_in_display_line_to calls
18882 handle_line_prefix itself. */
18883 handle_line_prefix (it
);
18886 /* Get the initial row height. This is either the height of the
18887 text hscrolled, if there is any, or zero. */
18888 row
->ascent
= it
->max_ascent
;
18889 row
->height
= it
->max_ascent
+ it
->max_descent
;
18890 row
->phys_ascent
= it
->max_phys_ascent
;
18891 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18892 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18894 /* Utility macro to record max and min buffer positions seen until now. */
18895 #define RECORD_MAX_MIN_POS(IT) \
18898 int composition_p = !STRINGP ((IT)->string) \
18899 && ((IT)->what == IT_COMPOSITION); \
18900 ptrdiff_t current_pos = \
18901 composition_p ? (IT)->cmp_it.charpos \
18902 : IT_CHARPOS (*(IT)); \
18903 ptrdiff_t current_bpos = \
18904 composition_p ? CHAR_TO_BYTE (current_pos) \
18905 : IT_BYTEPOS (*(IT)); \
18906 if (current_pos < min_pos) \
18908 min_pos = current_pos; \
18909 min_bpos = current_bpos; \
18911 if (IT_CHARPOS (*it) > max_pos) \
18913 max_pos = IT_CHARPOS (*it); \
18914 max_bpos = IT_BYTEPOS (*it); \
18919 /* Loop generating characters. The loop is left with IT on the next
18920 character to display. */
18923 int n_glyphs_before
, hpos_before
, x_before
;
18925 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
18927 /* Retrieve the next thing to display. Value is zero if end of
18929 if (!get_next_display_element (it
))
18931 /* Maybe add a space at the end of this line that is used to
18932 display the cursor there under X. Set the charpos of the
18933 first glyph of blank lines not corresponding to any text
18935 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18936 row
->exact_window_width_line_p
= 1;
18937 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
18938 || row
->used
[TEXT_AREA
] == 0)
18940 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
18941 row
->displays_text_p
= 0;
18943 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
18944 && (!MINI_WINDOW_P (it
->w
)
18945 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
18946 row
->indicate_empty_line_p
= 1;
18949 it
->continuation_lines_width
= 0;
18950 row
->ends_at_zv_p
= 1;
18951 /* A row that displays right-to-left text must always have
18952 its last face extended all the way to the end of line,
18953 even if this row ends in ZV, because we still write to
18954 the screen left to right. */
18955 if (row
->reversed_p
)
18956 extend_face_to_end_of_line (it
);
18960 /* Now, get the metrics of what we want to display. This also
18961 generates glyphs in `row' (which is IT->glyph_row). */
18962 n_glyphs_before
= row
->used
[TEXT_AREA
];
18965 /* Remember the line height so far in case the next element doesn't
18966 fit on the line. */
18967 if (it
->line_wrap
!= TRUNCATE
)
18969 ascent
= it
->max_ascent
;
18970 descent
= it
->max_descent
;
18971 phys_ascent
= it
->max_phys_ascent
;
18972 phys_descent
= it
->max_phys_descent
;
18974 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
18976 if (IT_DISPLAYING_WHITESPACE (it
))
18980 SAVE_IT (wrap_it
, *it
, wrap_data
);
18982 wrap_row_used
= row
->used
[TEXT_AREA
];
18983 wrap_row_ascent
= row
->ascent
;
18984 wrap_row_height
= row
->height
;
18985 wrap_row_phys_ascent
= row
->phys_ascent
;
18986 wrap_row_phys_height
= row
->phys_height
;
18987 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18988 wrap_row_min_pos
= min_pos
;
18989 wrap_row_min_bpos
= min_bpos
;
18990 wrap_row_max_pos
= max_pos
;
18991 wrap_row_max_bpos
= max_bpos
;
18997 PRODUCE_GLYPHS (it
);
18999 /* If this display element was in marginal areas, continue with
19001 if (it
->area
!= TEXT_AREA
)
19003 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19004 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19005 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19006 row
->phys_height
= max (row
->phys_height
,
19007 it
->max_phys_ascent
+ it
->max_phys_descent
);
19008 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19009 it
->max_extra_line_spacing
);
19010 set_iterator_to_next (it
, 1);
19014 /* Does the display element fit on the line? If we truncate
19015 lines, we should draw past the right edge of the window. If
19016 we don't truncate, we want to stop so that we can display the
19017 continuation glyph before the right margin. If lines are
19018 continued, there are two possible strategies for characters
19019 resulting in more than 1 glyph (e.g. tabs): Display as many
19020 glyphs as possible in this line and leave the rest for the
19021 continuation line, or display the whole element in the next
19022 line. Original redisplay did the former, so we do it also. */
19023 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19024 hpos_before
= it
->hpos
;
19027 if (/* Not a newline. */
19029 /* Glyphs produced fit entirely in the line. */
19030 && it
->current_x
< it
->last_visible_x
)
19032 it
->hpos
+= nglyphs
;
19033 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19034 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19035 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19036 row
->phys_height
= max (row
->phys_height
,
19037 it
->max_phys_ascent
+ it
->max_phys_descent
);
19038 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19039 it
->max_extra_line_spacing
);
19040 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19041 row
->x
= x
- it
->first_visible_x
;
19042 /* Record the maximum and minimum buffer positions seen so
19043 far in glyphs that will be displayed by this row. */
19045 RECORD_MAX_MIN_POS (it
);
19050 struct glyph
*glyph
;
19052 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19054 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19055 new_x
= x
+ glyph
->pixel_width
;
19057 if (/* Lines are continued. */
19058 it
->line_wrap
!= TRUNCATE
19059 && (/* Glyph doesn't fit on the line. */
19060 new_x
> it
->last_visible_x
19061 /* Or it fits exactly on a window system frame. */
19062 || (new_x
== it
->last_visible_x
19063 && FRAME_WINDOW_P (it
->f
))))
19065 /* End of a continued line. */
19068 || (new_x
== it
->last_visible_x
19069 && FRAME_WINDOW_P (it
->f
)))
19071 /* Current glyph is the only one on the line or
19072 fits exactly on the line. We must continue
19073 the line because we can't draw the cursor
19074 after the glyph. */
19075 row
->continued_p
= 1;
19076 it
->current_x
= new_x
;
19077 it
->continuation_lines_width
+= new_x
;
19079 if (i
== nglyphs
- 1)
19081 /* If line-wrap is on, check if a previous
19082 wrap point was found. */
19083 if (wrap_row_used
> 0
19084 /* Even if there is a previous wrap
19085 point, continue the line here as
19086 usual, if (i) the previous character
19087 was a space or tab AND (ii) the
19088 current character is not. */
19090 || IT_DISPLAYING_WHITESPACE (it
)))
19093 /* Record the maximum and minimum buffer
19094 positions seen so far in glyphs that will be
19095 displayed by this row. */
19097 RECORD_MAX_MIN_POS (it
);
19098 set_iterator_to_next (it
, 1);
19099 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19101 if (!get_next_display_element (it
))
19103 row
->exact_window_width_line_p
= 1;
19104 it
->continuation_lines_width
= 0;
19105 row
->continued_p
= 0;
19106 row
->ends_at_zv_p
= 1;
19108 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19110 row
->continued_p
= 0;
19111 row
->exact_window_width_line_p
= 1;
19115 else if (it
->bidi_p
)
19116 RECORD_MAX_MIN_POS (it
);
19118 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19119 && !FRAME_WINDOW_P (it
->f
))
19121 /* A padding glyph that doesn't fit on this line.
19122 This means the whole character doesn't fit
19124 if (row
->reversed_p
)
19125 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19126 - n_glyphs_before
);
19127 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19129 /* Fill the rest of the row with continuation
19130 glyphs like in 20.x. */
19131 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19132 < row
->glyphs
[1 + TEXT_AREA
])
19133 produce_special_glyphs (it
, IT_CONTINUATION
);
19135 row
->continued_p
= 1;
19136 it
->current_x
= x_before
;
19137 it
->continuation_lines_width
+= x_before
;
19139 /* Restore the height to what it was before the
19140 element not fitting on the line. */
19141 it
->max_ascent
= ascent
;
19142 it
->max_descent
= descent
;
19143 it
->max_phys_ascent
= phys_ascent
;
19144 it
->max_phys_descent
= phys_descent
;
19146 else if (wrap_row_used
> 0)
19149 if (row
->reversed_p
)
19150 unproduce_glyphs (it
,
19151 row
->used
[TEXT_AREA
] - wrap_row_used
);
19152 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19153 it
->continuation_lines_width
+= wrap_x
;
19154 row
->used
[TEXT_AREA
] = wrap_row_used
;
19155 row
->ascent
= wrap_row_ascent
;
19156 row
->height
= wrap_row_height
;
19157 row
->phys_ascent
= wrap_row_phys_ascent
;
19158 row
->phys_height
= wrap_row_phys_height
;
19159 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19160 min_pos
= wrap_row_min_pos
;
19161 min_bpos
= wrap_row_min_bpos
;
19162 max_pos
= wrap_row_max_pos
;
19163 max_bpos
= wrap_row_max_bpos
;
19164 row
->continued_p
= 1;
19165 row
->ends_at_zv_p
= 0;
19166 row
->exact_window_width_line_p
= 0;
19167 it
->continuation_lines_width
+= x
;
19169 /* Make sure that a non-default face is extended
19170 up to the right margin of the window. */
19171 extend_face_to_end_of_line (it
);
19173 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19175 /* A TAB that extends past the right edge of the
19176 window. This produces a single glyph on
19177 window system frames. We leave the glyph in
19178 this row and let it fill the row, but don't
19179 consume the TAB. */
19180 it
->continuation_lines_width
+= it
->last_visible_x
;
19181 row
->ends_in_middle_of_char_p
= 1;
19182 row
->continued_p
= 1;
19183 glyph
->pixel_width
= it
->last_visible_x
- x
;
19184 it
->starts_in_middle_of_char_p
= 1;
19188 /* Something other than a TAB that draws past
19189 the right edge of the window. Restore
19190 positions to values before the element. */
19191 if (row
->reversed_p
)
19192 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19193 - (n_glyphs_before
+ i
));
19194 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19196 /* Display continuation glyphs. */
19197 if (!FRAME_WINDOW_P (it
->f
))
19198 produce_special_glyphs (it
, IT_CONTINUATION
);
19199 row
->continued_p
= 1;
19201 it
->current_x
= x_before
;
19202 it
->continuation_lines_width
+= x
;
19203 extend_face_to_end_of_line (it
);
19205 if (nglyphs
> 1 && i
> 0)
19207 row
->ends_in_middle_of_char_p
= 1;
19208 it
->starts_in_middle_of_char_p
= 1;
19211 /* Restore the height to what it was before the
19212 element not fitting on the line. */
19213 it
->max_ascent
= ascent
;
19214 it
->max_descent
= descent
;
19215 it
->max_phys_ascent
= phys_ascent
;
19216 it
->max_phys_descent
= phys_descent
;
19221 else if (new_x
> it
->first_visible_x
)
19223 /* Increment number of glyphs actually displayed. */
19226 /* Record the maximum and minimum buffer positions
19227 seen so far in glyphs that will be displayed by
19230 RECORD_MAX_MIN_POS (it
);
19232 if (x
< it
->first_visible_x
)
19233 /* Glyph is partially visible, i.e. row starts at
19234 negative X position. */
19235 row
->x
= x
- it
->first_visible_x
;
19239 /* Glyph is completely off the left margin of the
19240 window. This should not happen because of the
19241 move_it_in_display_line at the start of this
19242 function, unless the text display area of the
19243 window is empty. */
19244 xassert (it
->first_visible_x
<= it
->last_visible_x
);
19247 /* Even if this display element produced no glyphs at all,
19248 we want to record its position. */
19249 if (it
->bidi_p
&& nglyphs
== 0)
19250 RECORD_MAX_MIN_POS (it
);
19252 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19253 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19254 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19255 row
->phys_height
= max (row
->phys_height
,
19256 it
->max_phys_ascent
+ it
->max_phys_descent
);
19257 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19258 it
->max_extra_line_spacing
);
19260 /* End of this display line if row is continued. */
19261 if (row
->continued_p
|| row
->ends_at_zv_p
)
19266 /* Is this a line end? If yes, we're also done, after making
19267 sure that a non-default face is extended up to the right
19268 margin of the window. */
19269 if (ITERATOR_AT_END_OF_LINE_P (it
))
19271 int used_before
= row
->used
[TEXT_AREA
];
19273 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19275 /* Add a space at the end of the line that is used to
19276 display the cursor there. */
19277 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19278 append_space_for_newline (it
, 0);
19280 /* Extend the face to the end of the line. */
19281 extend_face_to_end_of_line (it
);
19283 /* Make sure we have the position. */
19284 if (used_before
== 0)
19285 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19287 /* Record the position of the newline, for use in
19289 it
->eol_pos
= it
->current
.pos
;
19291 /* Consume the line end. This skips over invisible lines. */
19292 set_iterator_to_next (it
, 1);
19293 it
->continuation_lines_width
= 0;
19297 /* Proceed with next display element. Note that this skips
19298 over lines invisible because of selective display. */
19299 set_iterator_to_next (it
, 1);
19301 /* If we truncate lines, we are done when the last displayed
19302 glyphs reach past the right margin of the window. */
19303 if (it
->line_wrap
== TRUNCATE
19304 && (FRAME_WINDOW_P (it
->f
)
19305 ? (it
->current_x
>= it
->last_visible_x
)
19306 : (it
->current_x
> it
->last_visible_x
)))
19308 /* Maybe add truncation glyphs. */
19309 if (!FRAME_WINDOW_P (it
->f
))
19313 if (!row
->reversed_p
)
19315 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19316 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19321 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19322 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19324 /* Remove any padding glyphs at the front of ROW, to
19325 make room for the truncation glyphs we will be
19326 adding below. The loop below always inserts at
19327 least one truncation glyph, so also remove the
19328 last glyph added to ROW. */
19329 unproduce_glyphs (it
, i
+ 1);
19330 /* Adjust i for the loop below. */
19331 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19334 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19336 row
->used
[TEXT_AREA
] = i
;
19337 produce_special_glyphs (it
, IT_TRUNCATION
);
19340 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19342 /* Don't truncate if we can overflow newline into fringe. */
19343 if (!get_next_display_element (it
))
19345 it
->continuation_lines_width
= 0;
19346 row
->ends_at_zv_p
= 1;
19347 row
->exact_window_width_line_p
= 1;
19350 if (ITERATOR_AT_END_OF_LINE_P (it
))
19352 row
->exact_window_width_line_p
= 1;
19353 goto at_end_of_line
;
19357 row
->truncated_on_right_p
= 1;
19358 it
->continuation_lines_width
= 0;
19359 reseat_at_next_visible_line_start (it
, 0);
19360 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19361 it
->hpos
= hpos_before
;
19362 it
->current_x
= x_before
;
19368 bidi_unshelve_cache (wrap_data
, 1);
19370 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19371 at the left window margin. */
19372 if (it
->first_visible_x
19373 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19375 if (!FRAME_WINDOW_P (it
->f
))
19376 insert_left_trunc_glyphs (it
);
19377 row
->truncated_on_left_p
= 1;
19380 /* Remember the position at which this line ends.
19382 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19383 cannot be before the call to find_row_edges below, since that is
19384 where these positions are determined. */
19385 row
->end
= it
->current
;
19388 row
->minpos
= row
->start
.pos
;
19389 row
->maxpos
= row
->end
.pos
;
19393 /* ROW->minpos and ROW->maxpos must be the smallest and
19394 `1 + the largest' buffer positions in ROW. But if ROW was
19395 bidi-reordered, these two positions can be anywhere in the
19396 row, so we must determine them now. */
19397 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19400 /* If the start of this line is the overlay arrow-position, then
19401 mark this glyph row as the one containing the overlay arrow.
19402 This is clearly a mess with variable size fonts. It would be
19403 better to let it be displayed like cursors under X. */
19404 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19405 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19406 !NILP (overlay_arrow_string
)))
19408 /* Overlay arrow in window redisplay is a fringe bitmap. */
19409 if (STRINGP (overlay_arrow_string
))
19411 struct glyph_row
*arrow_row
19412 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19413 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19414 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19415 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19416 struct glyph
*p2
, *end
;
19418 /* Copy the arrow glyphs. */
19419 while (glyph
< arrow_end
)
19422 /* Throw away padding glyphs. */
19424 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19425 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19431 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19436 xassert (INTEGERP (overlay_arrow_string
));
19437 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19439 overlay_arrow_seen
= 1;
19442 /* Highlight trailing whitespace. */
19443 if (!NILP (Vshow_trailing_whitespace
))
19444 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19446 /* Compute pixel dimensions of this line. */
19447 compute_line_metrics (it
);
19449 /* Implementation note: No changes in the glyphs of ROW or in their
19450 faces can be done past this point, because compute_line_metrics
19451 computes ROW's hash value and stores it within the glyph_row
19454 /* Record whether this row ends inside an ellipsis. */
19455 row
->ends_in_ellipsis_p
19456 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19457 && it
->ellipsis_p
);
19459 /* Save fringe bitmaps in this row. */
19460 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19461 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19462 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19463 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19465 it
->left_user_fringe_bitmap
= 0;
19466 it
->left_user_fringe_face_id
= 0;
19467 it
->right_user_fringe_bitmap
= 0;
19468 it
->right_user_fringe_face_id
= 0;
19470 /* Maybe set the cursor. */
19471 cvpos
= it
->w
->cursor
.vpos
;
19473 /* In bidi-reordered rows, keep checking for proper cursor
19474 position even if one has been found already, because buffer
19475 positions in such rows change non-linearly with ROW->VPOS,
19476 when a line is continued. One exception: when we are at ZV,
19477 display cursor on the first suitable glyph row, since all
19478 the empty rows after that also have their position set to ZV. */
19479 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19480 lines' rows is implemented for bidi-reordered rows. */
19482 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19483 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19484 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19485 && cursor_row_p (row
))
19486 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19488 /* Prepare for the next line. This line starts horizontally at (X
19489 HPOS) = (0 0). Vertical positions are incremented. As a
19490 convenience for the caller, IT->glyph_row is set to the next
19492 it
->current_x
= it
->hpos
= 0;
19493 it
->current_y
+= row
->height
;
19494 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19497 /* The next row should by default use the same value of the
19498 reversed_p flag as this one. set_iterator_to_next decides when
19499 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19500 the flag accordingly. */
19501 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19502 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19503 it
->start
= row
->end
;
19504 return row
->displays_text_p
;
19506 #undef RECORD_MAX_MIN_POS
19509 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19510 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19511 doc
: /* Return paragraph direction at point in BUFFER.
19512 Value is either `left-to-right' or `right-to-left'.
19513 If BUFFER is omitted or nil, it defaults to the current buffer.
19515 Paragraph direction determines how the text in the paragraph is displayed.
19516 In left-to-right paragraphs, text begins at the left margin of the window
19517 and the reading direction is generally left to right. In right-to-left
19518 paragraphs, text begins at the right margin and is read from right to left.
19520 See also `bidi-paragraph-direction'. */)
19521 (Lisp_Object buffer
)
19523 struct buffer
*buf
= current_buffer
;
19524 struct buffer
*old
= buf
;
19526 if (! NILP (buffer
))
19528 CHECK_BUFFER (buffer
);
19529 buf
= XBUFFER (buffer
);
19532 if (NILP (BVAR (buf
, bidi_display_reordering
))
19533 || NILP (BVAR (buf
, enable_multibyte_characters
))
19534 /* When we are loading loadup.el, the character property tables
19535 needed for bidi iteration are not yet available. */
19536 || !NILP (Vpurify_flag
))
19537 return Qleft_to_right
;
19538 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19539 return BVAR (buf
, bidi_paragraph_direction
);
19542 /* Determine the direction from buffer text. We could try to
19543 use current_matrix if it is up to date, but this seems fast
19544 enough as it is. */
19545 struct bidi_it itb
;
19546 ptrdiff_t pos
= BUF_PT (buf
);
19547 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19549 void *itb_data
= bidi_shelve_cache ();
19551 set_buffer_temp (buf
);
19552 /* bidi_paragraph_init finds the base direction of the paragraph
19553 by searching forward from paragraph start. We need the base
19554 direction of the current or _previous_ paragraph, so we need
19555 to make sure we are within that paragraph. To that end, find
19556 the previous non-empty line. */
19557 if (pos
>= ZV
&& pos
> BEGV
)
19560 bytepos
= CHAR_TO_BYTE (pos
);
19562 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19563 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19565 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19566 || c
== ' ' || c
== '\t' || c
== '\f')
19568 if (bytepos
<= BEGV_BYTE
)
19573 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19576 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19577 itb
.paragraph_dir
= NEUTRAL_DIR
;
19578 itb
.string
.s
= NULL
;
19579 itb
.string
.lstring
= Qnil
;
19580 itb
.string
.bufpos
= 0;
19581 itb
.string
.unibyte
= 0;
19582 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19583 bidi_unshelve_cache (itb_data
, 0);
19584 set_buffer_temp (old
);
19585 switch (itb
.paragraph_dir
)
19588 return Qleft_to_right
;
19591 return Qright_to_left
;
19601 /***********************************************************************
19603 ***********************************************************************/
19605 /* Redisplay the menu bar in the frame for window W.
19607 The menu bar of X frames that don't have X toolkit support is
19608 displayed in a special window W->frame->menu_bar_window.
19610 The menu bar of terminal frames is treated specially as far as
19611 glyph matrices are concerned. Menu bar lines are not part of
19612 windows, so the update is done directly on the frame matrix rows
19613 for the menu bar. */
19616 display_menu_bar (struct window
*w
)
19618 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19623 /* Don't do all this for graphical frames. */
19625 if (FRAME_W32_P (f
))
19628 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19634 if (FRAME_NS_P (f
))
19636 #endif /* HAVE_NS */
19638 #ifdef USE_X_TOOLKIT
19639 xassert (!FRAME_WINDOW_P (f
));
19640 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19641 it
.first_visible_x
= 0;
19642 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19643 #else /* not USE_X_TOOLKIT */
19644 if (FRAME_WINDOW_P (f
))
19646 /* Menu bar lines are displayed in the desired matrix of the
19647 dummy window menu_bar_window. */
19648 struct window
*menu_w
;
19649 xassert (WINDOWP (f
->menu_bar_window
));
19650 menu_w
= XWINDOW (f
->menu_bar_window
);
19651 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19653 it
.first_visible_x
= 0;
19654 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19658 /* This is a TTY frame, i.e. character hpos/vpos are used as
19660 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19662 it
.first_visible_x
= 0;
19663 it
.last_visible_x
= FRAME_COLS (f
);
19665 #endif /* not USE_X_TOOLKIT */
19667 /* FIXME: This should be controlled by a user option. See the
19668 comments in redisplay_tool_bar and display_mode_line about
19670 it
.paragraph_embedding
= L2R
;
19672 if (! mode_line_inverse_video
)
19673 /* Force the menu-bar to be displayed in the default face. */
19674 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19676 /* Clear all rows of the menu bar. */
19677 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
19679 struct glyph_row
*row
= it
.glyph_row
+ i
;
19680 clear_glyph_row (row
);
19681 row
->enabled_p
= 1;
19682 row
->full_width_p
= 1;
19685 /* Display all items of the menu bar. */
19686 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
19687 for (i
= 0; i
< ASIZE (items
); i
+= 4)
19689 Lisp_Object string
;
19691 /* Stop at nil string. */
19692 string
= AREF (items
, i
+ 1);
19696 /* Remember where item was displayed. */
19697 ASET (items
, i
+ 3, make_number (it
.hpos
));
19699 /* Display the item, pad with one space. */
19700 if (it
.current_x
< it
.last_visible_x
)
19701 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
19702 SCHARS (string
) + 1, 0, 0, -1);
19705 /* Fill out the line with spaces. */
19706 if (it
.current_x
< it
.last_visible_x
)
19707 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
19709 /* Compute the total height of the lines. */
19710 compute_line_metrics (&it
);
19715 /***********************************************************************
19717 ***********************************************************************/
19719 /* Redisplay mode lines in the window tree whose root is WINDOW. If
19720 FORCE is non-zero, redisplay mode lines unconditionally.
19721 Otherwise, redisplay only mode lines that are garbaged. Value is
19722 the number of windows whose mode lines were redisplayed. */
19725 redisplay_mode_lines (Lisp_Object window
, int force
)
19729 while (!NILP (window
))
19731 struct window
*w
= XWINDOW (window
);
19733 if (WINDOWP (w
->hchild
))
19734 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
19735 else if (WINDOWP (w
->vchild
))
19736 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
19738 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
19739 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
19741 struct text_pos lpoint
;
19742 struct buffer
*old
= current_buffer
;
19744 /* Set the window's buffer for the mode line display. */
19745 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
19746 set_buffer_internal_1 (XBUFFER (w
->buffer
));
19748 /* Point refers normally to the selected window. For any
19749 other window, set up appropriate value. */
19750 if (!EQ (window
, selected_window
))
19752 struct text_pos pt
;
19754 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
19755 if (CHARPOS (pt
) < BEGV
)
19756 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
19757 else if (CHARPOS (pt
) > (ZV
- 1))
19758 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
19760 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
19763 /* Display mode lines. */
19764 clear_glyph_matrix (w
->desired_matrix
);
19765 if (display_mode_lines (w
))
19768 w
->must_be_updated_p
= 1;
19771 /* Restore old settings. */
19772 set_buffer_internal_1 (old
);
19773 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
19783 /* Display the mode and/or header line of window W. Value is the
19784 sum number of mode lines and header lines displayed. */
19787 display_mode_lines (struct window
*w
)
19789 Lisp_Object old_selected_window
, old_selected_frame
;
19792 old_selected_frame
= selected_frame
;
19793 selected_frame
= w
->frame
;
19794 old_selected_window
= selected_window
;
19795 XSETWINDOW (selected_window
, w
);
19797 /* These will be set while the mode line specs are processed. */
19798 line_number_displayed
= 0;
19799 w
->column_number_displayed
= Qnil
;
19801 if (WINDOW_WANTS_MODELINE_P (w
))
19803 struct window
*sel_w
= XWINDOW (old_selected_window
);
19805 /* Select mode line face based on the real selected window. */
19806 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
19807 BVAR (current_buffer
, mode_line_format
));
19811 if (WINDOW_WANTS_HEADER_LINE_P (w
))
19813 display_mode_line (w
, HEADER_LINE_FACE_ID
,
19814 BVAR (current_buffer
, header_line_format
));
19818 selected_frame
= old_selected_frame
;
19819 selected_window
= old_selected_window
;
19824 /* Display mode or header line of window W. FACE_ID specifies which
19825 line to display; it is either MODE_LINE_FACE_ID or
19826 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
19827 display. Value is the pixel height of the mode/header line
19831 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
19835 ptrdiff_t count
= SPECPDL_INDEX ();
19837 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19838 /* Don't extend on a previously drawn mode-line.
19839 This may happen if called from pos_visible_p. */
19840 it
.glyph_row
->enabled_p
= 0;
19841 prepare_desired_row (it
.glyph_row
);
19843 it
.glyph_row
->mode_line_p
= 1;
19845 if (! mode_line_inverse_video
)
19846 /* Force the mode-line to be displayed in the default face. */
19847 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19849 /* FIXME: This should be controlled by a user option. But
19850 supporting such an option is not trivial, since the mode line is
19851 made up of many separate strings. */
19852 it
.paragraph_embedding
= L2R
;
19854 record_unwind_protect (unwind_format_mode_line
,
19855 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19857 mode_line_target
= MODE_LINE_DISPLAY
;
19859 /* Temporarily make frame's keyboard the current kboard so that
19860 kboard-local variables in the mode_line_format will get the right
19862 push_kboard (FRAME_KBOARD (it
.f
));
19863 record_unwind_save_match_data ();
19864 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19867 unbind_to (count
, Qnil
);
19869 /* Fill up with spaces. */
19870 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
19872 compute_line_metrics (&it
);
19873 it
.glyph_row
->full_width_p
= 1;
19874 it
.glyph_row
->continued_p
= 0;
19875 it
.glyph_row
->truncated_on_left_p
= 0;
19876 it
.glyph_row
->truncated_on_right_p
= 0;
19878 /* Make a 3D mode-line have a shadow at its right end. */
19879 face
= FACE_FROM_ID (it
.f
, face_id
);
19880 extend_face_to_end_of_line (&it
);
19881 if (face
->box
!= FACE_NO_BOX
)
19883 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
19884 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
19885 last
->right_box_line_p
= 1;
19888 return it
.glyph_row
->height
;
19891 /* Move element ELT in LIST to the front of LIST.
19892 Return the updated list. */
19895 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
19897 register Lisp_Object tail
, prev
;
19898 register Lisp_Object tem
;
19902 while (CONSP (tail
))
19908 /* Splice out the link TAIL. */
19910 list
= XCDR (tail
);
19912 Fsetcdr (prev
, XCDR (tail
));
19914 /* Now make it the first. */
19915 Fsetcdr (tail
, list
);
19920 tail
= XCDR (tail
);
19924 /* Not found--return unchanged LIST. */
19928 /* Contribute ELT to the mode line for window IT->w. How it
19929 translates into text depends on its data type.
19931 IT describes the display environment in which we display, as usual.
19933 DEPTH is the depth in recursion. It is used to prevent
19934 infinite recursion here.
19936 FIELD_WIDTH is the number of characters the display of ELT should
19937 occupy in the mode line, and PRECISION is the maximum number of
19938 characters to display from ELT's representation. See
19939 display_string for details.
19941 Returns the hpos of the end of the text generated by ELT.
19943 PROPS is a property list to add to any string we encounter.
19945 If RISKY is nonzero, remove (disregard) any properties in any string
19946 we encounter, and ignore :eval and :propertize.
19948 The global variable `mode_line_target' determines whether the
19949 output is passed to `store_mode_line_noprop',
19950 `store_mode_line_string', or `display_string'. */
19953 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
19954 Lisp_Object elt
, Lisp_Object props
, int risky
)
19956 int n
= 0, field
, prec
;
19961 elt
= build_string ("*too-deep*");
19965 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
19969 /* A string: output it and check for %-constructs within it. */
19971 ptrdiff_t offset
= 0;
19973 if (SCHARS (elt
) > 0
19974 && (!NILP (props
) || risky
))
19976 Lisp_Object oprops
, aelt
;
19977 oprops
= Ftext_properties_at (make_number (0), elt
);
19979 /* If the starting string's properties are not what
19980 we want, translate the string. Also, if the string
19981 is risky, do that anyway. */
19983 if (NILP (Fequal (props
, oprops
)) || risky
)
19985 /* If the starting string has properties,
19986 merge the specified ones onto the existing ones. */
19987 if (! NILP (oprops
) && !risky
)
19991 oprops
= Fcopy_sequence (oprops
);
19993 while (CONSP (tem
))
19995 oprops
= Fplist_put (oprops
, XCAR (tem
),
19996 XCAR (XCDR (tem
)));
19997 tem
= XCDR (XCDR (tem
));
20002 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20003 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20005 /* AELT is what we want. Move it to the front
20006 without consing. */
20008 mode_line_proptrans_alist
20009 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20015 /* If AELT has the wrong props, it is useless.
20016 so get rid of it. */
20018 mode_line_proptrans_alist
20019 = Fdelq (aelt
, mode_line_proptrans_alist
);
20021 elt
= Fcopy_sequence (elt
);
20022 Fset_text_properties (make_number (0), Flength (elt
),
20024 /* Add this item to mode_line_proptrans_alist. */
20025 mode_line_proptrans_alist
20026 = Fcons (Fcons (elt
, props
),
20027 mode_line_proptrans_alist
);
20028 /* Truncate mode_line_proptrans_alist
20029 to at most 50 elements. */
20030 tem
= Fnthcdr (make_number (50),
20031 mode_line_proptrans_alist
);
20033 XSETCDR (tem
, Qnil
);
20042 prec
= precision
- n
;
20043 switch (mode_line_target
)
20045 case MODE_LINE_NOPROP
:
20046 case MODE_LINE_TITLE
:
20047 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20049 case MODE_LINE_STRING
:
20050 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20052 case MODE_LINE_DISPLAY
:
20053 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20054 0, prec
, 0, STRING_MULTIBYTE (elt
));
20061 /* Handle the non-literal case. */
20063 while ((precision
<= 0 || n
< precision
)
20064 && SREF (elt
, offset
) != 0
20065 && (mode_line_target
!= MODE_LINE_DISPLAY
20066 || it
->current_x
< it
->last_visible_x
))
20068 ptrdiff_t last_offset
= offset
;
20070 /* Advance to end of string or next format specifier. */
20071 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20074 if (offset
- 1 != last_offset
)
20076 ptrdiff_t nchars
, nbytes
;
20078 /* Output to end of string or up to '%'. Field width
20079 is length of string. Don't output more than
20080 PRECISION allows us. */
20083 prec
= c_string_width (SDATA (elt
) + last_offset
,
20084 offset
- last_offset
, precision
- n
,
20087 switch (mode_line_target
)
20089 case MODE_LINE_NOPROP
:
20090 case MODE_LINE_TITLE
:
20091 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20093 case MODE_LINE_STRING
:
20095 ptrdiff_t bytepos
= last_offset
;
20096 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20097 ptrdiff_t endpos
= (precision
<= 0
20098 ? string_byte_to_char (elt
, offset
)
20099 : charpos
+ nchars
);
20101 n
+= store_mode_line_string (NULL
,
20102 Fsubstring (elt
, make_number (charpos
),
20103 make_number (endpos
)),
20107 case MODE_LINE_DISPLAY
:
20109 ptrdiff_t bytepos
= last_offset
;
20110 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20112 if (precision
<= 0)
20113 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20114 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20116 STRING_MULTIBYTE (elt
));
20121 else /* c == '%' */
20123 ptrdiff_t percent_position
= offset
;
20125 /* Get the specified minimum width. Zero means
20128 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20129 field
= field
* 10 + c
- '0';
20131 /* Don't pad beyond the total padding allowed. */
20132 if (field_width
- n
> 0 && field
> field_width
- n
)
20133 field
= field_width
- n
;
20135 /* Note that either PRECISION <= 0 or N < PRECISION. */
20136 prec
= precision
- n
;
20139 n
+= display_mode_element (it
, depth
, field
, prec
,
20140 Vglobal_mode_string
, props
,
20145 ptrdiff_t bytepos
, charpos
;
20147 Lisp_Object string
;
20149 bytepos
= percent_position
;
20150 charpos
= (STRING_MULTIBYTE (elt
)
20151 ? string_byte_to_char (elt
, bytepos
)
20153 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20154 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20156 switch (mode_line_target
)
20158 case MODE_LINE_NOPROP
:
20159 case MODE_LINE_TITLE
:
20160 n
+= store_mode_line_noprop (spec
, field
, prec
);
20162 case MODE_LINE_STRING
:
20164 Lisp_Object tem
= build_string (spec
);
20165 props
= Ftext_properties_at (make_number (charpos
), elt
);
20166 /* Should only keep face property in props */
20167 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20170 case MODE_LINE_DISPLAY
:
20172 int nglyphs_before
, nwritten
;
20174 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20175 nwritten
= display_string (spec
, string
, elt
,
20180 /* Assign to the glyphs written above the
20181 string where the `%x' came from, position
20185 struct glyph
*glyph
20186 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20190 for (i
= 0; i
< nwritten
; ++i
)
20192 glyph
[i
].object
= elt
;
20193 glyph
[i
].charpos
= charpos
;
20210 /* A symbol: process the value of the symbol recursively
20211 as if it appeared here directly. Avoid error if symbol void.
20212 Special case: if value of symbol is a string, output the string
20215 register Lisp_Object tem
;
20217 /* If the variable is not marked as risky to set
20218 then its contents are risky to use. */
20219 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20222 tem
= Fboundp (elt
);
20225 tem
= Fsymbol_value (elt
);
20226 /* If value is a string, output that string literally:
20227 don't check for % within it. */
20231 if (!EQ (tem
, elt
))
20233 /* Give up right away for nil or t. */
20243 register Lisp_Object car
, tem
;
20245 /* A cons cell: five distinct cases.
20246 If first element is :eval or :propertize, do something special.
20247 If first element is a string or a cons, process all the elements
20248 and effectively concatenate them.
20249 If first element is a negative number, truncate displaying cdr to
20250 at most that many characters. If positive, pad (with spaces)
20251 to at least that many characters.
20252 If first element is a symbol, process the cadr or caddr recursively
20253 according to whether the symbol's value is non-nil or nil. */
20255 if (EQ (car
, QCeval
))
20257 /* An element of the form (:eval FORM) means evaluate FORM
20258 and use the result as mode line elements. */
20263 if (CONSP (XCDR (elt
)))
20266 spec
= safe_eval (XCAR (XCDR (elt
)));
20267 n
+= display_mode_element (it
, depth
, field_width
- n
,
20268 precision
- n
, spec
, props
,
20272 else if (EQ (car
, QCpropertize
))
20274 /* An element of the form (:propertize ELT PROPS...)
20275 means display ELT but applying properties PROPS. */
20280 if (CONSP (XCDR (elt
)))
20281 n
+= display_mode_element (it
, depth
, field_width
- n
,
20282 precision
- n
, XCAR (XCDR (elt
)),
20283 XCDR (XCDR (elt
)), risky
);
20285 else if (SYMBOLP (car
))
20287 tem
= Fboundp (car
);
20291 /* elt is now the cdr, and we know it is a cons cell.
20292 Use its car if CAR has a non-nil value. */
20295 tem
= Fsymbol_value (car
);
20302 /* Symbol's value is nil (or symbol is unbound)
20303 Get the cddr of the original list
20304 and if possible find the caddr and use that. */
20308 else if (!CONSP (elt
))
20313 else if (INTEGERP (car
))
20315 register int lim
= XINT (car
);
20319 /* Negative int means reduce maximum width. */
20320 if (precision
<= 0)
20323 precision
= min (precision
, -lim
);
20327 /* Padding specified. Don't let it be more than
20328 current maximum. */
20330 lim
= min (precision
, lim
);
20332 /* If that's more padding than already wanted, queue it.
20333 But don't reduce padding already specified even if
20334 that is beyond the current truncation point. */
20335 field_width
= max (lim
, field_width
);
20339 else if (STRINGP (car
) || CONSP (car
))
20341 Lisp_Object halftail
= elt
;
20345 && (precision
<= 0 || n
< precision
))
20347 n
+= display_mode_element (it
, depth
,
20348 /* Do padding only after the last
20349 element in the list. */
20350 (! CONSP (XCDR (elt
))
20353 precision
- n
, XCAR (elt
),
20357 if ((len
& 1) == 0)
20358 halftail
= XCDR (halftail
);
20359 /* Check for cycle. */
20360 if (EQ (halftail
, elt
))
20369 elt
= build_string ("*invalid*");
20373 /* Pad to FIELD_WIDTH. */
20374 if (field_width
> 0 && n
< field_width
)
20376 switch (mode_line_target
)
20378 case MODE_LINE_NOPROP
:
20379 case MODE_LINE_TITLE
:
20380 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20382 case MODE_LINE_STRING
:
20383 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20385 case MODE_LINE_DISPLAY
:
20386 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20395 /* Store a mode-line string element in mode_line_string_list.
20397 If STRING is non-null, display that C string. Otherwise, the Lisp
20398 string LISP_STRING is displayed.
20400 FIELD_WIDTH is the minimum number of output glyphs to produce.
20401 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20402 with spaces. FIELD_WIDTH <= 0 means don't pad.
20404 PRECISION is the maximum number of characters to output from
20405 STRING. PRECISION <= 0 means don't truncate the string.
20407 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20408 properties to the string.
20410 PROPS are the properties to add to the string.
20411 The mode_line_string_face face property is always added to the string.
20415 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20416 int field_width
, int precision
, Lisp_Object props
)
20421 if (string
!= NULL
)
20423 len
= strlen (string
);
20424 if (precision
> 0 && len
> precision
)
20426 lisp_string
= make_string (string
, len
);
20428 props
= mode_line_string_face_prop
;
20429 else if (!NILP (mode_line_string_face
))
20431 Lisp_Object face
= Fplist_get (props
, Qface
);
20432 props
= Fcopy_sequence (props
);
20434 face
= mode_line_string_face
;
20436 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20437 props
= Fplist_put (props
, Qface
, face
);
20439 Fadd_text_properties (make_number (0), make_number (len
),
20440 props
, lisp_string
);
20444 len
= XFASTINT (Flength (lisp_string
));
20445 if (precision
> 0 && len
> precision
)
20448 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20451 if (!NILP (mode_line_string_face
))
20455 props
= Ftext_properties_at (make_number (0), lisp_string
);
20456 face
= Fplist_get (props
, Qface
);
20458 face
= mode_line_string_face
;
20460 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20461 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20463 lisp_string
= Fcopy_sequence (lisp_string
);
20466 Fadd_text_properties (make_number (0), make_number (len
),
20467 props
, lisp_string
);
20472 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20476 if (field_width
> len
)
20478 field_width
-= len
;
20479 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20481 Fadd_text_properties (make_number (0), make_number (field_width
),
20482 props
, lisp_string
);
20483 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20491 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20493 doc
: /* Format a string out of a mode line format specification.
20494 First arg FORMAT specifies the mode line format (see `mode-line-format'
20495 for details) to use.
20497 By default, the format is evaluated for the currently selected window.
20499 Optional second arg FACE specifies the face property to put on all
20500 characters for which no face is specified. The value nil means the
20501 default face. The value t means whatever face the window's mode line
20502 currently uses (either `mode-line' or `mode-line-inactive',
20503 depending on whether the window is the selected window or not).
20504 An integer value means the value string has no text
20507 Optional third and fourth args WINDOW and BUFFER specify the window
20508 and buffer to use as the context for the formatting (defaults
20509 are the selected window and the WINDOW's buffer). */)
20510 (Lisp_Object format
, Lisp_Object face
,
20511 Lisp_Object window
, Lisp_Object buffer
)
20516 struct buffer
*old_buffer
= NULL
;
20518 int no_props
= INTEGERP (face
);
20519 ptrdiff_t count
= SPECPDL_INDEX ();
20521 int string_start
= 0;
20524 window
= selected_window
;
20525 CHECK_WINDOW (window
);
20526 w
= XWINDOW (window
);
20529 buffer
= w
->buffer
;
20530 CHECK_BUFFER (buffer
);
20532 /* Make formatting the modeline a non-op when noninteractive, otherwise
20533 there will be problems later caused by a partially initialized frame. */
20534 if (NILP (format
) || noninteractive
)
20535 return empty_unibyte_string
;
20540 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20541 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20542 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20543 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20544 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20545 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20546 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20549 if (XBUFFER (buffer
) != current_buffer
)
20550 old_buffer
= current_buffer
;
20552 /* Save things including mode_line_proptrans_alist,
20553 and set that to nil so that we don't alter the outer value. */
20554 record_unwind_protect (unwind_format_mode_line
,
20555 format_mode_line_unwind_data
20556 (old_buffer
, selected_window
, 1));
20557 mode_line_proptrans_alist
= Qnil
;
20559 Fselect_window (window
, Qt
);
20561 set_buffer_internal_1 (XBUFFER (buffer
));
20563 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20567 mode_line_target
= MODE_LINE_NOPROP
;
20568 mode_line_string_face_prop
= Qnil
;
20569 mode_line_string_list
= Qnil
;
20570 string_start
= MODE_LINE_NOPROP_LEN (0);
20574 mode_line_target
= MODE_LINE_STRING
;
20575 mode_line_string_list
= Qnil
;
20576 mode_line_string_face
= face
;
20577 mode_line_string_face_prop
20578 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20581 push_kboard (FRAME_KBOARD (it
.f
));
20582 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20587 len
= MODE_LINE_NOPROP_LEN (string_start
);
20588 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20592 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20593 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20594 empty_unibyte_string
);
20597 unbind_to (count
, Qnil
);
20601 /* Write a null-terminated, right justified decimal representation of
20602 the positive integer D to BUF using a minimal field width WIDTH. */
20605 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20607 register char *p
= buf
;
20615 *p
++ = d
% 10 + '0';
20620 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20631 /* Write a null-terminated, right justified decimal and "human
20632 readable" representation of the nonnegative integer D to BUF using
20633 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20635 static const char power_letter
[] =
20649 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20651 /* We aim to represent the nonnegative integer D as
20652 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20653 ptrdiff_t quotient
= d
;
20655 /* -1 means: do not use TENTHS. */
20659 /* Length of QUOTIENT.TENTHS as a string. */
20665 if (1000 <= quotient
)
20667 /* Scale to the appropriate EXPONENT. */
20670 remainder
= quotient
% 1000;
20674 while (1000 <= quotient
);
20676 /* Round to nearest and decide whether to use TENTHS or not. */
20679 tenths
= remainder
/ 100;
20680 if (50 <= remainder
% 100)
20687 if (quotient
== 10)
20695 if (500 <= remainder
)
20697 if (quotient
< 999)
20708 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
20709 if (tenths
== -1 && quotient
<= 99)
20716 p
= psuffix
= buf
+ max (width
, length
);
20718 /* Print EXPONENT. */
20719 *psuffix
++ = power_letter
[exponent
];
20722 /* Print TENTHS. */
20725 *--p
= '0' + tenths
;
20729 /* Print QUOTIENT. */
20732 int digit
= quotient
% 10;
20733 *--p
= '0' + digit
;
20735 while ((quotient
/= 10) != 0);
20737 /* Print leading spaces. */
20742 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
20743 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
20744 type of CODING_SYSTEM. Return updated pointer into BUF. */
20746 static unsigned char invalid_eol_type
[] = "(*invalid*)";
20749 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
20752 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
20753 const unsigned char *eol_str
;
20755 /* The EOL conversion we are using. */
20756 Lisp_Object eoltype
;
20758 val
= CODING_SYSTEM_SPEC (coding_system
);
20761 if (!VECTORP (val
)) /* Not yet decided. */
20766 eoltype
= eol_mnemonic_undecided
;
20767 /* Don't mention EOL conversion if it isn't decided. */
20772 Lisp_Object eolvalue
;
20774 attrs
= AREF (val
, 0);
20775 eolvalue
= AREF (val
, 2);
20778 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
20782 /* The EOL conversion that is normal on this system. */
20784 if (NILP (eolvalue
)) /* Not yet decided. */
20785 eoltype
= eol_mnemonic_undecided
;
20786 else if (VECTORP (eolvalue
)) /* Not yet decided. */
20787 eoltype
= eol_mnemonic_undecided
;
20788 else /* eolvalue is Qunix, Qdos, or Qmac. */
20789 eoltype
= (EQ (eolvalue
, Qunix
)
20790 ? eol_mnemonic_unix
20791 : (EQ (eolvalue
, Qdos
) == 1
20792 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
20798 /* Mention the EOL conversion if it is not the usual one. */
20799 if (STRINGP (eoltype
))
20801 eol_str
= SDATA (eoltype
);
20802 eol_str_len
= SBYTES (eoltype
);
20804 else if (CHARACTERP (eoltype
))
20806 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
20807 int c
= XFASTINT (eoltype
);
20808 eol_str_len
= CHAR_STRING (c
, tmp
);
20813 eol_str
= invalid_eol_type
;
20814 eol_str_len
= sizeof (invalid_eol_type
) - 1;
20816 memcpy (buf
, eol_str
, eol_str_len
);
20817 buf
+= eol_str_len
;
20823 /* Return a string for the output of a mode line %-spec for window W,
20824 generated by character C. FIELD_WIDTH > 0 means pad the string
20825 returned with spaces to that value. Return a Lisp string in
20826 *STRING if the resulting string is taken from that Lisp string.
20828 Note we operate on the current buffer for most purposes,
20829 the exception being w->base_line_pos. */
20831 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
20833 static const char *
20834 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
20835 Lisp_Object
*string
)
20838 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20839 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
20840 struct buffer
*b
= current_buffer
;
20848 if (!NILP (BVAR (b
, read_only
)))
20850 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20855 /* This differs from %* only for a modified read-only buffer. */
20856 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20858 if (!NILP (BVAR (b
, read_only
)))
20863 /* This differs from %* in ignoring read-only-ness. */
20864 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20876 if (command_loop_level
> 5)
20878 p
= decode_mode_spec_buf
;
20879 for (i
= 0; i
< command_loop_level
; i
++)
20882 return decode_mode_spec_buf
;
20890 if (command_loop_level
> 5)
20892 p
= decode_mode_spec_buf
;
20893 for (i
= 0; i
< command_loop_level
; i
++)
20896 return decode_mode_spec_buf
;
20903 /* Let lots_of_dashes be a string of infinite length. */
20904 if (mode_line_target
== MODE_LINE_NOPROP
||
20905 mode_line_target
== MODE_LINE_STRING
)
20907 if (field_width
<= 0
20908 || field_width
> sizeof (lots_of_dashes
))
20910 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
20911 decode_mode_spec_buf
[i
] = '-';
20912 decode_mode_spec_buf
[i
] = '\0';
20913 return decode_mode_spec_buf
;
20916 return lots_of_dashes
;
20920 obj
= BVAR (b
, name
);
20924 /* %c and %l are ignored in `frame-title-format'.
20925 (In redisplay_internal, the frame title is drawn _before_ the
20926 windows are updated, so the stuff which depends on actual
20927 window contents (such as %l) may fail to render properly, or
20928 even crash emacs.) */
20929 if (mode_line_target
== MODE_LINE_TITLE
)
20933 ptrdiff_t col
= current_column ();
20934 w
->column_number_displayed
= make_number (col
);
20935 pint2str (decode_mode_spec_buf
, field_width
, col
);
20936 return decode_mode_spec_buf
;
20940 #ifndef SYSTEM_MALLOC
20942 if (NILP (Vmemory_full
))
20945 return "!MEM FULL! ";
20952 /* %F displays the frame name. */
20953 if (!NILP (f
->title
))
20954 return SSDATA (f
->title
);
20955 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
20956 return SSDATA (f
->name
);
20960 obj
= BVAR (b
, filename
);
20965 ptrdiff_t size
= ZV
- BEGV
;
20966 pint2str (decode_mode_spec_buf
, field_width
, size
);
20967 return decode_mode_spec_buf
;
20972 ptrdiff_t size
= ZV
- BEGV
;
20973 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
20974 return decode_mode_spec_buf
;
20979 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
20980 ptrdiff_t topline
, nlines
, height
;
20983 /* %c and %l are ignored in `frame-title-format'. */
20984 if (mode_line_target
== MODE_LINE_TITLE
)
20987 startpos
= XMARKER (w
->start
)->charpos
;
20988 startpos_byte
= marker_byte_position (w
->start
);
20989 height
= WINDOW_TOTAL_LINES (w
);
20991 /* If we decided that this buffer isn't suitable for line numbers,
20992 don't forget that too fast. */
20993 if (EQ (w
->base_line_pos
, w
->buffer
))
20995 /* But do forget it, if the window shows a different buffer now. */
20996 else if (BUFFERP (w
->base_line_pos
))
20997 w
->base_line_pos
= Qnil
;
20999 /* If the buffer is very big, don't waste time. */
21000 if (INTEGERP (Vline_number_display_limit
)
21001 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21003 w
->base_line_pos
= Qnil
;
21004 w
->base_line_number
= Qnil
;
21008 if (INTEGERP (w
->base_line_number
)
21009 && INTEGERP (w
->base_line_pos
)
21010 && XFASTINT (w
->base_line_pos
) <= startpos
)
21012 line
= XFASTINT (w
->base_line_number
);
21013 linepos
= XFASTINT (w
->base_line_pos
);
21014 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21019 linepos
= BUF_BEGV (b
);
21020 linepos_byte
= BUF_BEGV_BYTE (b
);
21023 /* Count lines from base line to window start position. */
21024 nlines
= display_count_lines (linepos_byte
,
21028 topline
= nlines
+ line
;
21030 /* Determine a new base line, if the old one is too close
21031 or too far away, or if we did not have one.
21032 "Too close" means it's plausible a scroll-down would
21033 go back past it. */
21034 if (startpos
== BUF_BEGV (b
))
21036 w
->base_line_number
= make_number (topline
);
21037 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21039 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21040 || linepos
== BUF_BEGV (b
))
21042 ptrdiff_t limit
= BUF_BEGV (b
);
21043 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21044 ptrdiff_t position
;
21045 ptrdiff_t distance
=
21046 (height
* 2 + 30) * line_number_display_limit_width
;
21048 if (startpos
- distance
> limit
)
21050 limit
= startpos
- distance
;
21051 limit_byte
= CHAR_TO_BYTE (limit
);
21054 nlines
= display_count_lines (startpos_byte
,
21056 - (height
* 2 + 30),
21058 /* If we couldn't find the lines we wanted within
21059 line_number_display_limit_width chars per line,
21060 give up on line numbers for this window. */
21061 if (position
== limit_byte
&& limit
== startpos
- distance
)
21063 w
->base_line_pos
= w
->buffer
;
21064 w
->base_line_number
= Qnil
;
21068 w
->base_line_number
= make_number (topline
- nlines
);
21069 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21072 /* Now count lines from the start pos to point. */
21073 nlines
= display_count_lines (startpos_byte
,
21074 PT_BYTE
, PT
, &junk
);
21076 /* Record that we did display the line number. */
21077 line_number_displayed
= 1;
21079 /* Make the string to show. */
21080 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21081 return decode_mode_spec_buf
;
21084 char* p
= decode_mode_spec_buf
;
21085 int pad
= field_width
- 2;
21091 return decode_mode_spec_buf
;
21097 obj
= BVAR (b
, mode_name
);
21101 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21107 ptrdiff_t pos
= marker_position (w
->start
);
21108 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21110 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21112 if (pos
<= BUF_BEGV (b
))
21117 else if (pos
<= BUF_BEGV (b
))
21121 if (total
> 1000000)
21122 /* Do it differently for a large value, to avoid overflow. */
21123 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21125 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21126 /* We can't normally display a 3-digit number,
21127 so get us a 2-digit number that is close. */
21130 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21131 return decode_mode_spec_buf
;
21135 /* Display percentage of size above the bottom of the screen. */
21138 ptrdiff_t toppos
= marker_position (w
->start
);
21139 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21140 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21142 if (botpos
>= BUF_ZV (b
))
21144 if (toppos
<= BUF_BEGV (b
))
21151 if (total
> 1000000)
21152 /* Do it differently for a large value, to avoid overflow. */
21153 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21155 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21156 /* We can't normally display a 3-digit number,
21157 so get us a 2-digit number that is close. */
21160 if (toppos
<= BUF_BEGV (b
))
21161 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21163 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21164 return decode_mode_spec_buf
;
21169 /* status of process */
21170 obj
= Fget_buffer_process (Fcurrent_buffer ());
21172 return "no process";
21174 obj
= Fsymbol_name (Fprocess_status (obj
));
21180 ptrdiff_t count
= inhibit_garbage_collection ();
21181 Lisp_Object val
= call1 (intern ("file-remote-p"),
21182 BVAR (current_buffer
, directory
));
21183 unbind_to (count
, Qnil
);
21191 case 't': /* indicate TEXT or BINARY */
21195 /* coding-system (not including end-of-line format) */
21197 /* coding-system (including end-of-line type) */
21199 int eol_flag
= (c
== 'Z');
21200 char *p
= decode_mode_spec_buf
;
21202 if (! FRAME_WINDOW_P (f
))
21204 /* No need to mention EOL here--the terminal never needs
21205 to do EOL conversion. */
21206 p
= decode_mode_spec_coding (CODING_ID_NAME
21207 (FRAME_KEYBOARD_CODING (f
)->id
),
21209 p
= decode_mode_spec_coding (CODING_ID_NAME
21210 (FRAME_TERMINAL_CODING (f
)->id
),
21213 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21216 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21217 #ifdef subprocesses
21218 obj
= Fget_buffer_process (Fcurrent_buffer ());
21219 if (PROCESSP (obj
))
21221 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21223 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21226 #endif /* subprocesses */
21229 return decode_mode_spec_buf
;
21236 return SSDATA (obj
);
21243 /* Count up to COUNT lines starting from START_BYTE.
21244 But don't go beyond LIMIT_BYTE.
21245 Return the number of lines thus found (always nonnegative).
21247 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21250 display_count_lines (ptrdiff_t start_byte
,
21251 ptrdiff_t limit_byte
, ptrdiff_t count
,
21252 ptrdiff_t *byte_pos_ptr
)
21254 register unsigned char *cursor
;
21255 unsigned char *base
;
21257 register ptrdiff_t ceiling
;
21258 register unsigned char *ceiling_addr
;
21259 ptrdiff_t orig_count
= count
;
21261 /* If we are not in selective display mode,
21262 check only for newlines. */
21263 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21264 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21268 while (start_byte
< limit_byte
)
21270 ceiling
= BUFFER_CEILING_OF (start_byte
);
21271 ceiling
= min (limit_byte
- 1, ceiling
);
21272 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21273 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21276 if (selective_display
)
21277 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21280 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21283 if (cursor
!= ceiling_addr
)
21287 start_byte
+= cursor
- base
+ 1;
21288 *byte_pos_ptr
= start_byte
;
21292 if (++cursor
== ceiling_addr
)
21298 start_byte
+= cursor
- base
;
21303 while (start_byte
> limit_byte
)
21305 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21306 ceiling
= max (limit_byte
, ceiling
);
21307 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21308 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21311 if (selective_display
)
21312 while (--cursor
!= ceiling_addr
21313 && *cursor
!= '\n' && *cursor
!= 015)
21316 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21319 if (cursor
!= ceiling_addr
)
21323 start_byte
+= cursor
- base
+ 1;
21324 *byte_pos_ptr
= start_byte
;
21325 /* When scanning backwards, we should
21326 not count the newline posterior to which we stop. */
21327 return - orig_count
- 1;
21333 /* Here we add 1 to compensate for the last decrement
21334 of CURSOR, which took it past the valid range. */
21335 start_byte
+= cursor
- base
+ 1;
21339 *byte_pos_ptr
= limit_byte
;
21342 return - orig_count
+ count
;
21343 return orig_count
- count
;
21349 /***********************************************************************
21351 ***********************************************************************/
21353 /* Display a NUL-terminated string, starting with index START.
21355 If STRING is non-null, display that C string. Otherwise, the Lisp
21356 string LISP_STRING is displayed. There's a case that STRING is
21357 non-null and LISP_STRING is not nil. It means STRING is a string
21358 data of LISP_STRING. In that case, we display LISP_STRING while
21359 ignoring its text properties.
21361 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21362 FACE_STRING. Display STRING or LISP_STRING with the face at
21363 FACE_STRING_POS in FACE_STRING:
21365 Display the string in the environment given by IT, but use the
21366 standard display table, temporarily.
21368 FIELD_WIDTH is the minimum number of output glyphs to produce.
21369 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21370 with spaces. If STRING has more characters, more than FIELD_WIDTH
21371 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21373 PRECISION is the maximum number of characters to output from
21374 STRING. PRECISION < 0 means don't truncate the string.
21376 This is roughly equivalent to printf format specifiers:
21378 FIELD_WIDTH PRECISION PRINTF
21379 ----------------------------------------
21385 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21386 display them, and < 0 means obey the current buffer's value of
21387 enable_multibyte_characters.
21389 Value is the number of columns displayed. */
21392 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21393 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21394 int field_width
, int precision
, int max_x
, int multibyte
)
21396 int hpos_at_start
= it
->hpos
;
21397 int saved_face_id
= it
->face_id
;
21398 struct glyph_row
*row
= it
->glyph_row
;
21399 ptrdiff_t it_charpos
;
21401 /* Initialize the iterator IT for iteration over STRING beginning
21402 with index START. */
21403 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21404 precision
, field_width
, multibyte
);
21405 if (string
&& STRINGP (lisp_string
))
21406 /* LISP_STRING is the one returned by decode_mode_spec. We should
21407 ignore its text properties. */
21408 it
->stop_charpos
= it
->end_charpos
;
21410 /* If displaying STRING, set up the face of the iterator from
21411 FACE_STRING, if that's given. */
21412 if (STRINGP (face_string
))
21418 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21419 0, it
->region_beg_charpos
,
21420 it
->region_end_charpos
,
21421 &endptr
, it
->base_face_id
, 0);
21422 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21423 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21426 /* Set max_x to the maximum allowed X position. Don't let it go
21427 beyond the right edge of the window. */
21429 max_x
= it
->last_visible_x
;
21431 max_x
= min (max_x
, it
->last_visible_x
);
21433 /* Skip over display elements that are not visible. because IT->w is
21435 if (it
->current_x
< it
->first_visible_x
)
21436 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21437 MOVE_TO_POS
| MOVE_TO_X
);
21439 row
->ascent
= it
->max_ascent
;
21440 row
->height
= it
->max_ascent
+ it
->max_descent
;
21441 row
->phys_ascent
= it
->max_phys_ascent
;
21442 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21443 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21445 if (STRINGP (it
->string
))
21446 it_charpos
= IT_STRING_CHARPOS (*it
);
21448 it_charpos
= IT_CHARPOS (*it
);
21450 /* This condition is for the case that we are called with current_x
21451 past last_visible_x. */
21452 while (it
->current_x
< max_x
)
21454 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21456 /* Get the next display element. */
21457 if (!get_next_display_element (it
))
21460 /* Produce glyphs. */
21461 x_before
= it
->current_x
;
21462 n_glyphs_before
= row
->used
[TEXT_AREA
];
21463 PRODUCE_GLYPHS (it
);
21465 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21468 while (i
< nglyphs
)
21470 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21472 if (it
->line_wrap
!= TRUNCATE
21473 && x
+ glyph
->pixel_width
> max_x
)
21475 /* End of continued line or max_x reached. */
21476 if (CHAR_GLYPH_PADDING_P (*glyph
))
21478 /* A wide character is unbreakable. */
21479 if (row
->reversed_p
)
21480 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21481 - n_glyphs_before
);
21482 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21483 it
->current_x
= x_before
;
21487 if (row
->reversed_p
)
21488 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21489 - (n_glyphs_before
+ i
));
21490 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21495 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21497 /* Glyph is at least partially visible. */
21499 if (x
< it
->first_visible_x
)
21500 row
->x
= x
- it
->first_visible_x
;
21504 /* Glyph is off the left margin of the display area.
21505 Should not happen. */
21509 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21510 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21511 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21512 row
->phys_height
= max (row
->phys_height
,
21513 it
->max_phys_ascent
+ it
->max_phys_descent
);
21514 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21515 it
->max_extra_line_spacing
);
21516 x
+= glyph
->pixel_width
;
21520 /* Stop if max_x reached. */
21524 /* Stop at line ends. */
21525 if (ITERATOR_AT_END_OF_LINE_P (it
))
21527 it
->continuation_lines_width
= 0;
21531 set_iterator_to_next (it
, 1);
21532 if (STRINGP (it
->string
))
21533 it_charpos
= IT_STRING_CHARPOS (*it
);
21535 it_charpos
= IT_CHARPOS (*it
);
21537 /* Stop if truncating at the right edge. */
21538 if (it
->line_wrap
== TRUNCATE
21539 && it
->current_x
>= it
->last_visible_x
)
21541 /* Add truncation mark, but don't do it if the line is
21542 truncated at a padding space. */
21543 if (it_charpos
< it
->string_nchars
)
21545 if (!FRAME_WINDOW_P (it
->f
))
21549 if (it
->current_x
> it
->last_visible_x
)
21551 if (!row
->reversed_p
)
21553 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21554 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21559 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21560 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21562 unproduce_glyphs (it
, ii
+ 1);
21563 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21565 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21567 row
->used
[TEXT_AREA
] = ii
;
21568 produce_special_glyphs (it
, IT_TRUNCATION
);
21571 produce_special_glyphs (it
, IT_TRUNCATION
);
21573 row
->truncated_on_right_p
= 1;
21579 /* Maybe insert a truncation at the left. */
21580 if (it
->first_visible_x
21583 if (!FRAME_WINDOW_P (it
->f
))
21584 insert_left_trunc_glyphs (it
);
21585 row
->truncated_on_left_p
= 1;
21588 it
->face_id
= saved_face_id
;
21590 /* Value is number of columns displayed. */
21591 return it
->hpos
- hpos_at_start
;
21596 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21597 appears as an element of LIST or as the car of an element of LIST.
21598 If PROPVAL is a list, compare each element against LIST in that
21599 way, and return 1/2 if any element of PROPVAL is found in LIST.
21600 Otherwise return 0. This function cannot quit.
21601 The return value is 2 if the text is invisible but with an ellipsis
21602 and 1 if it's invisible and without an ellipsis. */
21605 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21607 register Lisp_Object tail
, proptail
;
21609 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21611 register Lisp_Object tem
;
21613 if (EQ (propval
, tem
))
21615 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21616 return NILP (XCDR (tem
)) ? 1 : 2;
21619 if (CONSP (propval
))
21621 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21623 Lisp_Object propelt
;
21624 propelt
= XCAR (proptail
);
21625 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21627 register Lisp_Object tem
;
21629 if (EQ (propelt
, tem
))
21631 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21632 return NILP (XCDR (tem
)) ? 1 : 2;
21640 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21641 doc
: /* Non-nil if the property makes the text invisible.
21642 POS-OR-PROP can be a marker or number, in which case it is taken to be
21643 a position in the current buffer and the value of the `invisible' property
21644 is checked; or it can be some other value, which is then presumed to be the
21645 value of the `invisible' property of the text of interest.
21646 The non-nil value returned can be t for truly invisible text or something
21647 else if the text is replaced by an ellipsis. */)
21648 (Lisp_Object pos_or_prop
)
21651 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21652 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21654 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21655 return (invis
== 0 ? Qnil
21657 : make_number (invis
));
21660 /* Calculate a width or height in pixels from a specification using
21661 the following elements:
21664 NUM - a (fractional) multiple of the default font width/height
21665 (NUM) - specifies exactly NUM pixels
21666 UNIT - a fixed number of pixels, see below.
21667 ELEMENT - size of a display element in pixels, see below.
21668 (NUM . SPEC) - equals NUM * SPEC
21669 (+ SPEC SPEC ...) - add pixel values
21670 (- SPEC SPEC ...) - subtract pixel values
21671 (- SPEC) - negate pixel value
21674 INT or FLOAT - a number constant
21675 SYMBOL - use symbol's (buffer local) variable binding.
21678 in - pixels per inch *)
21679 mm - pixels per 1/1000 meter *)
21680 cm - pixels per 1/100 meter *)
21681 width - width of current font in pixels.
21682 height - height of current font in pixels.
21684 *) using the ratio(s) defined in display-pixels-per-inch.
21688 left-fringe - left fringe width in pixels
21689 right-fringe - right fringe width in pixels
21691 left-margin - left margin width in pixels
21692 right-margin - right margin width in pixels
21694 scroll-bar - scroll-bar area width in pixels
21698 Pixels corresponding to 5 inches:
21701 Total width of non-text areas on left side of window (if scroll-bar is on left):
21702 '(space :width (+ left-fringe left-margin scroll-bar))
21704 Align to first text column (in header line):
21705 '(space :align-to 0)
21707 Align to middle of text area minus half the width of variable `my-image'
21708 containing a loaded image:
21709 '(space :align-to (0.5 . (- text my-image)))
21711 Width of left margin minus width of 1 character in the default font:
21712 '(space :width (- left-margin 1))
21714 Width of left margin minus width of 2 characters in the current font:
21715 '(space :width (- left-margin (2 . width)))
21717 Center 1 character over left-margin (in header line):
21718 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
21720 Different ways to express width of left fringe plus left margin minus one pixel:
21721 '(space :width (- (+ left-fringe left-margin) (1)))
21722 '(space :width (+ left-fringe left-margin (- (1))))
21723 '(space :width (+ left-fringe left-margin (-1)))
21727 #define NUMVAL(X) \
21728 ((INTEGERP (X) || FLOATP (X)) \
21733 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
21734 struct font
*font
, int width_p
, int *align_to
)
21738 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
21739 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
21742 return OK_PIXELS (0);
21744 xassert (FRAME_LIVE_P (it
->f
));
21746 if (SYMBOLP (prop
))
21748 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
21750 char *unit
= SSDATA (SYMBOL_NAME (prop
));
21752 if (unit
[0] == 'i' && unit
[1] == 'n')
21754 else if (unit
[0] == 'm' && unit
[1] == 'm')
21756 else if (unit
[0] == 'c' && unit
[1] == 'm')
21763 #ifdef HAVE_WINDOW_SYSTEM
21764 if (FRAME_WINDOW_P (it
->f
)
21766 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
21767 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
21769 return OK_PIXELS (ppi
/ pixels
);
21772 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
21773 || (CONSP (Vdisplay_pixels_per_inch
)
21775 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
21776 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
21778 return OK_PIXELS (ppi
/ pixels
);
21784 #ifdef HAVE_WINDOW_SYSTEM
21785 if (EQ (prop
, Qheight
))
21786 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
21787 if (EQ (prop
, Qwidth
))
21788 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
21790 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
21791 return OK_PIXELS (1);
21794 if (EQ (prop
, Qtext
))
21795 return OK_PIXELS (width_p
21796 ? window_box_width (it
->w
, TEXT_AREA
)
21797 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
21799 if (align_to
&& *align_to
< 0)
21802 if (EQ (prop
, Qleft
))
21803 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
21804 if (EQ (prop
, Qright
))
21805 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
21806 if (EQ (prop
, Qcenter
))
21807 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
21808 + window_box_width (it
->w
, TEXT_AREA
) / 2);
21809 if (EQ (prop
, Qleft_fringe
))
21810 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21811 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
21812 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
21813 if (EQ (prop
, Qright_fringe
))
21814 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21815 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21816 : window_box_right_offset (it
->w
, TEXT_AREA
));
21817 if (EQ (prop
, Qleft_margin
))
21818 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
21819 if (EQ (prop
, Qright_margin
))
21820 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
21821 if (EQ (prop
, Qscroll_bar
))
21822 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
21824 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21825 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21826 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21831 if (EQ (prop
, Qleft_fringe
))
21832 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
21833 if (EQ (prop
, Qright_fringe
))
21834 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
21835 if (EQ (prop
, Qleft_margin
))
21836 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
21837 if (EQ (prop
, Qright_margin
))
21838 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
21839 if (EQ (prop
, Qscroll_bar
))
21840 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
21843 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
21846 if (INTEGERP (prop
) || FLOATP (prop
))
21848 int base_unit
= (width_p
21849 ? FRAME_COLUMN_WIDTH (it
->f
)
21850 : FRAME_LINE_HEIGHT (it
->f
));
21851 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21856 Lisp_Object car
= XCAR (prop
);
21857 Lisp_Object cdr
= XCDR (prop
);
21861 #ifdef HAVE_WINDOW_SYSTEM
21862 if (FRAME_WINDOW_P (it
->f
)
21863 && valid_image_p (prop
))
21865 ptrdiff_t id
= lookup_image (it
->f
, prop
);
21866 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21868 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21871 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21877 while (CONSP (cdr
))
21879 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
21880 font
, width_p
, align_to
))
21883 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
21888 if (EQ (car
, Qminus
))
21890 return OK_PIXELS (pixels
);
21893 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
21896 if (INTEGERP (car
) || FLOATP (car
))
21899 pixels
= XFLOATINT (car
);
21901 return OK_PIXELS (pixels
);
21902 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
21903 font
, width_p
, align_to
))
21904 return OK_PIXELS (pixels
* fact
);
21915 /***********************************************************************
21917 ***********************************************************************/
21919 #ifdef HAVE_WINDOW_SYSTEM
21924 dump_glyph_string (struct glyph_string
*s
)
21926 fprintf (stderr
, "glyph string\n");
21927 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
21928 s
->x
, s
->y
, s
->width
, s
->height
);
21929 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
21930 fprintf (stderr
, " hl = %d\n", s
->hl
);
21931 fprintf (stderr
, " left overhang = %d, right = %d\n",
21932 s
->left_overhang
, s
->right_overhang
);
21933 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
21934 fprintf (stderr
, " extends to end of line = %d\n",
21935 s
->extends_to_end_of_line_p
);
21936 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
21937 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
21940 #endif /* GLYPH_DEBUG */
21942 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
21943 of XChar2b structures for S; it can't be allocated in
21944 init_glyph_string because it must be allocated via `alloca'. W
21945 is the window on which S is drawn. ROW and AREA are the glyph row
21946 and area within the row from which S is constructed. START is the
21947 index of the first glyph structure covered by S. HL is a
21948 face-override for drawing S. */
21951 #define OPTIONAL_HDC(hdc) HDC hdc,
21952 #define DECLARE_HDC(hdc) HDC hdc;
21953 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
21954 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
21957 #ifndef OPTIONAL_HDC
21958 #define OPTIONAL_HDC(hdc)
21959 #define DECLARE_HDC(hdc)
21960 #define ALLOCATE_HDC(hdc, f)
21961 #define RELEASE_HDC(hdc, f)
21965 init_glyph_string (struct glyph_string
*s
,
21967 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
21968 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
21970 memset (s
, 0, sizeof *s
);
21972 s
->f
= XFRAME (w
->frame
);
21976 s
->display
= FRAME_X_DISPLAY (s
->f
);
21977 s
->window
= FRAME_X_WINDOW (s
->f
);
21978 s
->char2b
= char2b
;
21982 s
->first_glyph
= row
->glyphs
[area
] + start
;
21983 s
->height
= row
->height
;
21984 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
21985 s
->ybase
= s
->y
+ row
->ascent
;
21989 /* Append the list of glyph strings with head H and tail T to the list
21990 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
21993 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21994 struct glyph_string
*h
, struct glyph_string
*t
)
22008 /* Prepend the list of glyph strings with head H and tail T to the
22009 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22013 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22014 struct glyph_string
*h
, struct glyph_string
*t
)
22028 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22029 Set *HEAD and *TAIL to the resulting list. */
22032 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22033 struct glyph_string
*s
)
22035 s
->next
= s
->prev
= NULL
;
22036 append_glyph_string_lists (head
, tail
, s
, s
);
22040 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22041 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22042 make sure that X resources for the face returned are allocated.
22043 Value is a pointer to a realized face that is ready for display if
22044 DISPLAY_P is non-zero. */
22046 static inline struct face
*
22047 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22048 XChar2b
*char2b
, int display_p
)
22050 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22054 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22056 if (code
!= FONT_INVALID_CODE
)
22057 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22059 STORE_XCHAR2B (char2b
, 0, 0);
22062 /* Make sure X resources of the face are allocated. */
22063 #ifdef HAVE_X_WINDOWS
22067 xassert (face
!= NULL
);
22068 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22075 /* Get face and two-byte form of character glyph GLYPH on frame F.
22076 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22077 a pointer to a realized face that is ready for display. */
22079 static inline struct face
*
22080 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22081 XChar2b
*char2b
, int *two_byte_p
)
22085 xassert (glyph
->type
== CHAR_GLYPH
);
22086 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22095 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22096 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22098 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22100 if (code
!= FONT_INVALID_CODE
)
22101 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22103 STORE_XCHAR2B (char2b
, 0, 0);
22106 /* Make sure X resources of the face are allocated. */
22107 xassert (face
!= NULL
);
22108 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22113 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22114 Return 1 if FONT has a glyph for C, otherwise return 0. */
22117 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22121 if (CHAR_BYTE8_P (c
))
22122 code
= CHAR_TO_BYTE8 (c
);
22124 code
= font
->driver
->encode_char (font
, c
);
22126 if (code
== FONT_INVALID_CODE
)
22128 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22133 /* Fill glyph string S with composition components specified by S->cmp.
22135 BASE_FACE is the base face of the composition.
22136 S->cmp_from is the index of the first component for S.
22138 OVERLAPS non-zero means S should draw the foreground only, and use
22139 its physical height for clipping. See also draw_glyphs.
22141 Value is the index of a component not in S. */
22144 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22148 /* For all glyphs of this composition, starting at the offset
22149 S->cmp_from, until we reach the end of the definition or encounter a
22150 glyph that requires the different face, add it to S. */
22155 s
->for_overlaps
= overlaps
;
22158 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22160 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22162 /* TAB in a composition means display glyphs with padding space
22163 on the left or right. */
22166 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22169 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22176 s
->font
= s
->face
->font
;
22178 else if (s
->face
!= face
)
22186 if (s
->face
== NULL
)
22188 s
->face
= base_face
->ascii_face
;
22189 s
->font
= s
->face
->font
;
22192 /* All glyph strings for the same composition has the same width,
22193 i.e. the width set for the first component of the composition. */
22194 s
->width
= s
->first_glyph
->pixel_width
;
22196 /* If the specified font could not be loaded, use the frame's
22197 default font, but record the fact that we couldn't load it in
22198 the glyph string so that we can draw rectangles for the
22199 characters of the glyph string. */
22200 if (s
->font
== NULL
)
22202 s
->font_not_found_p
= 1;
22203 s
->font
= FRAME_FONT (s
->f
);
22206 /* Adjust base line for subscript/superscript text. */
22207 s
->ybase
+= s
->first_glyph
->voffset
;
22209 /* This glyph string must always be drawn with 16-bit functions. */
22216 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22217 int start
, int end
, int overlaps
)
22219 struct glyph
*glyph
, *last
;
22220 Lisp_Object lgstring
;
22223 s
->for_overlaps
= overlaps
;
22224 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22225 last
= s
->row
->glyphs
[s
->area
] + end
;
22226 s
->cmp_id
= glyph
->u
.cmp
.id
;
22227 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22228 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22229 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22230 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22231 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22233 while (glyph
< last
22234 && glyph
->u
.cmp
.automatic
22235 && glyph
->u
.cmp
.id
== s
->cmp_id
22236 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22237 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22239 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22241 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22242 unsigned code
= LGLYPH_CODE (lglyph
);
22244 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22246 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22247 return glyph
- s
->row
->glyphs
[s
->area
];
22251 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22252 See the comment of fill_glyph_string for arguments.
22253 Value is the index of the first glyph not in S. */
22257 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22258 int start
, int end
, int overlaps
)
22260 struct glyph
*glyph
, *last
;
22263 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22264 s
->for_overlaps
= overlaps
;
22265 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22266 last
= s
->row
->glyphs
[s
->area
] + end
;
22267 voffset
= glyph
->voffset
;
22268 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22269 s
->font
= s
->face
->font
;
22271 s
->width
= glyph
->pixel_width
;
22273 while (glyph
< last
22274 && glyph
->type
== GLYPHLESS_GLYPH
22275 && glyph
->voffset
== voffset
22276 && glyph
->face_id
== face_id
)
22279 s
->width
+= glyph
->pixel_width
;
22282 s
->ybase
+= voffset
;
22283 return glyph
- s
->row
->glyphs
[s
->area
];
22287 /* Fill glyph string S from a sequence of character glyphs.
22289 FACE_ID is the face id of the string. START is the index of the
22290 first glyph to consider, END is the index of the last + 1.
22291 OVERLAPS non-zero means S should draw the foreground only, and use
22292 its physical height for clipping. See also draw_glyphs.
22294 Value is the index of the first glyph not in S. */
22297 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22298 int start
, int end
, int overlaps
)
22300 struct glyph
*glyph
, *last
;
22302 int glyph_not_available_p
;
22304 xassert (s
->f
== XFRAME (s
->w
->frame
));
22305 xassert (s
->nchars
== 0);
22306 xassert (start
>= 0 && end
> start
);
22308 s
->for_overlaps
= overlaps
;
22309 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22310 last
= s
->row
->glyphs
[s
->area
] + end
;
22311 voffset
= glyph
->voffset
;
22312 s
->padding_p
= glyph
->padding_p
;
22313 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22315 while (glyph
< last
22316 && glyph
->type
== CHAR_GLYPH
22317 && glyph
->voffset
== voffset
22318 /* Same face id implies same font, nowadays. */
22319 && glyph
->face_id
== face_id
22320 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22324 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22325 s
->char2b
+ s
->nchars
,
22327 s
->two_byte_p
= two_byte_p
;
22329 xassert (s
->nchars
<= end
- start
);
22330 s
->width
+= glyph
->pixel_width
;
22331 if (glyph
++->padding_p
!= s
->padding_p
)
22335 s
->font
= s
->face
->font
;
22337 /* If the specified font could not be loaded, use the frame's font,
22338 but record the fact that we couldn't load it in
22339 S->font_not_found_p so that we can draw rectangles for the
22340 characters of the glyph string. */
22341 if (s
->font
== NULL
|| glyph_not_available_p
)
22343 s
->font_not_found_p
= 1;
22344 s
->font
= FRAME_FONT (s
->f
);
22347 /* Adjust base line for subscript/superscript text. */
22348 s
->ybase
+= voffset
;
22350 xassert (s
->face
&& s
->face
->gc
);
22351 return glyph
- s
->row
->glyphs
[s
->area
];
22355 /* Fill glyph string S from image glyph S->first_glyph. */
22358 fill_image_glyph_string (struct glyph_string
*s
)
22360 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22361 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22363 s
->slice
= s
->first_glyph
->slice
.img
;
22364 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22365 s
->font
= s
->face
->font
;
22366 s
->width
= s
->first_glyph
->pixel_width
;
22368 /* Adjust base line for subscript/superscript text. */
22369 s
->ybase
+= s
->first_glyph
->voffset
;
22373 /* Fill glyph string S from a sequence of stretch glyphs.
22375 START is the index of the first glyph to consider,
22376 END is the index of the last + 1.
22378 Value is the index of the first glyph not in S. */
22381 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22383 struct glyph
*glyph
, *last
;
22384 int voffset
, face_id
;
22386 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22388 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22389 last
= s
->row
->glyphs
[s
->area
] + end
;
22390 face_id
= glyph
->face_id
;
22391 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22392 s
->font
= s
->face
->font
;
22393 s
->width
= glyph
->pixel_width
;
22395 voffset
= glyph
->voffset
;
22399 && glyph
->type
== STRETCH_GLYPH
22400 && glyph
->voffset
== voffset
22401 && glyph
->face_id
== face_id
);
22403 s
->width
+= glyph
->pixel_width
;
22405 /* Adjust base line for subscript/superscript text. */
22406 s
->ybase
+= voffset
;
22408 /* The case that face->gc == 0 is handled when drawing the glyph
22409 string by calling PREPARE_FACE_FOR_DISPLAY. */
22411 return glyph
- s
->row
->glyphs
[s
->area
];
22414 static struct font_metrics
*
22415 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22417 static struct font_metrics metrics
;
22418 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22420 if (! font
|| code
== FONT_INVALID_CODE
)
22422 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22427 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22428 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22429 assumed to be zero. */
22432 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22434 *left
= *right
= 0;
22436 if (glyph
->type
== CHAR_GLYPH
)
22440 struct font_metrics
*pcm
;
22442 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22443 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22445 if (pcm
->rbearing
> pcm
->width
)
22446 *right
= pcm
->rbearing
- pcm
->width
;
22447 if (pcm
->lbearing
< 0)
22448 *left
= -pcm
->lbearing
;
22451 else if (glyph
->type
== COMPOSITE_GLYPH
)
22453 if (! glyph
->u
.cmp
.automatic
)
22455 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22457 if (cmp
->rbearing
> cmp
->pixel_width
)
22458 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22459 if (cmp
->lbearing
< 0)
22460 *left
= - cmp
->lbearing
;
22464 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22465 struct font_metrics metrics
;
22467 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22468 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22469 if (metrics
.rbearing
> metrics
.width
)
22470 *right
= metrics
.rbearing
- metrics
.width
;
22471 if (metrics
.lbearing
< 0)
22472 *left
= - metrics
.lbearing
;
22478 /* Return the index of the first glyph preceding glyph string S that
22479 is overwritten by S because of S's left overhang. Value is -1
22480 if no glyphs are overwritten. */
22483 left_overwritten (struct glyph_string
*s
)
22487 if (s
->left_overhang
)
22490 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22491 int first
= s
->first_glyph
- glyphs
;
22493 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22494 x
-= glyphs
[i
].pixel_width
;
22505 /* Return the index of the first glyph preceding glyph string S that
22506 is overwriting S because of its right overhang. Value is -1 if no
22507 glyph in front of S overwrites S. */
22510 left_overwriting (struct glyph_string
*s
)
22513 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22514 int first
= s
->first_glyph
- glyphs
;
22518 for (i
= first
- 1; i
>= 0; --i
)
22521 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22524 x
-= glyphs
[i
].pixel_width
;
22531 /* Return the index of the last glyph following glyph string S that is
22532 overwritten by S because of S's right overhang. Value is -1 if
22533 no such glyph is found. */
22536 right_overwritten (struct glyph_string
*s
)
22540 if (s
->right_overhang
)
22543 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22544 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22545 int end
= s
->row
->used
[s
->area
];
22547 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22548 x
+= glyphs
[i
].pixel_width
;
22557 /* Return the index of the last glyph following glyph string S that
22558 overwrites S because of its left overhang. Value is negative
22559 if no such glyph is found. */
22562 right_overwriting (struct glyph_string
*s
)
22565 int end
= s
->row
->used
[s
->area
];
22566 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22567 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22571 for (i
= first
; i
< end
; ++i
)
22574 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22577 x
+= glyphs
[i
].pixel_width
;
22584 /* Set background width of glyph string S. START is the index of the
22585 first glyph following S. LAST_X is the right-most x-position + 1
22586 in the drawing area. */
22589 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22591 /* If the face of this glyph string has to be drawn to the end of
22592 the drawing area, set S->extends_to_end_of_line_p. */
22594 if (start
== s
->row
->used
[s
->area
]
22595 && s
->area
== TEXT_AREA
22596 && ((s
->row
->fill_line_p
22597 && (s
->hl
== DRAW_NORMAL_TEXT
22598 || s
->hl
== DRAW_IMAGE_RAISED
22599 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22600 || s
->hl
== DRAW_MOUSE_FACE
))
22601 s
->extends_to_end_of_line_p
= 1;
22603 /* If S extends its face to the end of the line, set its
22604 background_width to the distance to the right edge of the drawing
22606 if (s
->extends_to_end_of_line_p
)
22607 s
->background_width
= last_x
- s
->x
+ 1;
22609 s
->background_width
= s
->width
;
22613 /* Compute overhangs and x-positions for glyph string S and its
22614 predecessors, or successors. X is the starting x-position for S.
22615 BACKWARD_P non-zero means process predecessors. */
22618 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22624 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22625 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22635 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22636 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22646 /* The following macros are only called from draw_glyphs below.
22647 They reference the following parameters of that function directly:
22648 `w', `row', `area', and `overlap_p'
22649 as well as the following local variables:
22650 `s', `f', and `hdc' (in W32) */
22653 /* On W32, silently add local `hdc' variable to argument list of
22654 init_glyph_string. */
22655 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22656 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22658 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22659 init_glyph_string (s, char2b, w, row, area, start, hl)
22662 /* Add a glyph string for a stretch glyph to the list of strings
22663 between HEAD and TAIL. START is the index of the stretch glyph in
22664 row area AREA of glyph row ROW. END is the index of the last glyph
22665 in that glyph row area. X is the current output position assigned
22666 to the new glyph string constructed. HL overrides that face of the
22667 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22668 is the right-most x-position of the drawing area. */
22670 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
22671 and below -- keep them on one line. */
22672 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22675 s = (struct glyph_string *) alloca (sizeof *s); \
22676 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22677 START = fill_stretch_glyph_string (s, START, END); \
22678 append_glyph_string (&HEAD, &TAIL, s); \
22684 /* Add a glyph string for an image glyph to the list of strings
22685 between HEAD and TAIL. START is the index of the image glyph in
22686 row area AREA of glyph row ROW. END is the index of the last glyph
22687 in that glyph row area. X is the current output position assigned
22688 to the new glyph string constructed. HL overrides that face of the
22689 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22690 is the right-most x-position of the drawing area. */
22692 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22695 s = (struct glyph_string *) alloca (sizeof *s); \
22696 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22697 fill_image_glyph_string (s); \
22698 append_glyph_string (&HEAD, &TAIL, s); \
22705 /* Add a glyph string for a sequence of character glyphs to the list
22706 of strings between HEAD and TAIL. START is the index of the first
22707 glyph in row area AREA of glyph row ROW that is part of the new
22708 glyph string. END is the index of the last glyph in that glyph row
22709 area. X is the current output position assigned to the new glyph
22710 string constructed. HL overrides that face of the glyph; e.g. it
22711 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
22712 right-most x-position of the drawing area. */
22714 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22720 face_id = (row)->glyphs[area][START].face_id; \
22722 s = (struct glyph_string *) alloca (sizeof *s); \
22723 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
22724 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22725 append_glyph_string (&HEAD, &TAIL, s); \
22727 START = fill_glyph_string (s, face_id, START, END, overlaps); \
22732 /* Add a glyph string for a composite sequence to the list of strings
22733 between HEAD and TAIL. START is the index of the first glyph in
22734 row area AREA of glyph row ROW that is part of the new glyph
22735 string. END is the index of the last glyph in that glyph row area.
22736 X is the current output position assigned to the new glyph string
22737 constructed. HL overrides that face of the glyph; e.g. it is
22738 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
22739 x-position of the drawing area. */
22741 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22743 int face_id = (row)->glyphs[area][START].face_id; \
22744 struct face *base_face = FACE_FROM_ID (f, face_id); \
22745 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
22746 struct composition *cmp = composition_table[cmp_id]; \
22748 struct glyph_string *first_s = NULL; \
22751 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
22753 /* Make glyph_strings for each glyph sequence that is drawable by \
22754 the same face, and append them to HEAD/TAIL. */ \
22755 for (n = 0; n < cmp->glyph_len;) \
22757 s = (struct glyph_string *) alloca (sizeof *s); \
22758 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22759 append_glyph_string (&(HEAD), &(TAIL), s); \
22765 n = fill_composite_glyph_string (s, base_face, overlaps); \
22773 /* Add a glyph string for a glyph-string sequence to the list of strings
22774 between HEAD and TAIL. */
22776 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22780 Lisp_Object gstring; \
22782 face_id = (row)->glyphs[area][START].face_id; \
22783 gstring = (composition_gstring_from_id \
22784 ((row)->glyphs[area][START].u.cmp.id)); \
22785 s = (struct glyph_string *) alloca (sizeof *s); \
22786 char2b = (XChar2b *) alloca ((sizeof *char2b) \
22787 * LGSTRING_GLYPH_LEN (gstring)); \
22788 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22789 append_glyph_string (&(HEAD), &(TAIL), s); \
22791 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
22795 /* Add a glyph string for a sequence of glyphless character's glyphs
22796 to the list of strings between HEAD and TAIL. The meanings of
22797 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
22799 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22804 face_id = (row)->glyphs[area][START].face_id; \
22806 s = (struct glyph_string *) alloca (sizeof *s); \
22807 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22808 append_glyph_string (&HEAD, &TAIL, s); \
22810 START = fill_glyphless_glyph_string (s, face_id, START, END, \
22816 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
22817 of AREA of glyph row ROW on window W between indices START and END.
22818 HL overrides the face for drawing glyph strings, e.g. it is
22819 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
22820 x-positions of the drawing area.
22822 This is an ugly monster macro construct because we must use alloca
22823 to allocate glyph strings (because draw_glyphs can be called
22824 asynchronously). */
22826 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22829 HEAD = TAIL = NULL; \
22830 while (START < END) \
22832 struct glyph *first_glyph = (row)->glyphs[area] + START; \
22833 switch (first_glyph->type) \
22836 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
22840 case COMPOSITE_GLYPH: \
22841 if (first_glyph->u.cmp.automatic) \
22842 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
22845 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
22849 case STRETCH_GLYPH: \
22850 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
22854 case IMAGE_GLYPH: \
22855 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
22859 case GLYPHLESS_GLYPH: \
22860 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22870 set_glyph_string_background_width (s, START, LAST_X); \
22877 /* Draw glyphs between START and END in AREA of ROW on window W,
22878 starting at x-position X. X is relative to AREA in W. HL is a
22879 face-override with the following meaning:
22881 DRAW_NORMAL_TEXT draw normally
22882 DRAW_CURSOR draw in cursor face
22883 DRAW_MOUSE_FACE draw in mouse face.
22884 DRAW_INVERSE_VIDEO draw in mode line face
22885 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
22886 DRAW_IMAGE_RAISED draw an image with a raised relief around it
22888 If OVERLAPS is non-zero, draw only the foreground of characters and
22889 clip to the physical height of ROW. Non-zero value also defines
22890 the overlapping part to be drawn:
22892 OVERLAPS_PRED overlap with preceding rows
22893 OVERLAPS_SUCC overlap with succeeding rows
22894 OVERLAPS_BOTH overlap with both preceding/succeeding rows
22895 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
22897 Value is the x-position reached, relative to AREA of W. */
22900 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
22901 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
22902 enum draw_glyphs_face hl
, int overlaps
)
22904 struct glyph_string
*head
, *tail
;
22905 struct glyph_string
*s
;
22906 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
22907 int i
, j
, x_reached
, last_x
, area_left
= 0;
22908 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22911 ALLOCATE_HDC (hdc
, f
);
22913 /* Let's rather be paranoid than getting a SEGV. */
22914 end
= min (end
, row
->used
[area
]);
22915 start
= max (0, start
);
22916 start
= min (end
, start
);
22918 /* Translate X to frame coordinates. Set last_x to the right
22919 end of the drawing area. */
22920 if (row
->full_width_p
)
22922 /* X is relative to the left edge of W, without scroll bars
22924 area_left
= WINDOW_LEFT_EDGE_X (w
);
22925 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
22929 area_left
= window_box_left (w
, area
);
22930 last_x
= area_left
+ window_box_width (w
, area
);
22934 /* Build a doubly-linked list of glyph_string structures between
22935 head and tail from what we have to draw. Note that the macro
22936 BUILD_GLYPH_STRINGS will modify its start parameter. That's
22937 the reason we use a separate variable `i'. */
22939 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
22941 x_reached
= tail
->x
+ tail
->background_width
;
22945 /* If there are any glyphs with lbearing < 0 or rbearing > width in
22946 the row, redraw some glyphs in front or following the glyph
22947 strings built above. */
22948 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
22950 struct glyph_string
*h
, *t
;
22951 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
22952 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
22953 int check_mouse_face
= 0;
22956 /* If mouse highlighting is on, we may need to draw adjacent
22957 glyphs using mouse-face highlighting. */
22958 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
22960 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
22962 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
22963 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
22965 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
22967 check_mouse_face
= 1;
22968 mouse_beg_col
= (row
== mouse_beg_row
)
22969 ? hlinfo
->mouse_face_beg_col
: 0;
22970 mouse_end_col
= (row
== mouse_end_row
)
22971 ? hlinfo
->mouse_face_end_col
22972 : row
->used
[TEXT_AREA
];
22976 /* Compute overhangs for all glyph strings. */
22977 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
22978 for (s
= head
; s
; s
= s
->next
)
22979 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
22981 /* Prepend glyph strings for glyphs in front of the first glyph
22982 string that are overwritten because of the first glyph
22983 string's left overhang. The background of all strings
22984 prepended must be drawn because the first glyph string
22986 i
= left_overwritten (head
);
22989 enum draw_glyphs_face overlap_hl
;
22991 /* If this row contains mouse highlighting, attempt to draw
22992 the overlapped glyphs with the correct highlight. This
22993 code fails if the overlap encompasses more than one glyph
22994 and mouse-highlight spans only some of these glyphs.
22995 However, making it work perfectly involves a lot more
22996 code, and I don't know if the pathological case occurs in
22997 practice, so we'll stick to this for now. --- cyd */
22998 if (check_mouse_face
22999 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23000 overlap_hl
= DRAW_MOUSE_FACE
;
23002 overlap_hl
= DRAW_NORMAL_TEXT
;
23005 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23006 overlap_hl
, dummy_x
, last_x
);
23008 compute_overhangs_and_x (t
, head
->x
, 1);
23009 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23013 /* Prepend glyph strings for glyphs in front of the first glyph
23014 string that overwrite that glyph string because of their
23015 right overhang. For these strings, only the foreground must
23016 be drawn, because it draws over the glyph string at `head'.
23017 The background must not be drawn because this would overwrite
23018 right overhangs of preceding glyphs for which no glyph
23020 i
= left_overwriting (head
);
23023 enum draw_glyphs_face overlap_hl
;
23025 if (check_mouse_face
23026 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23027 overlap_hl
= DRAW_MOUSE_FACE
;
23029 overlap_hl
= DRAW_NORMAL_TEXT
;
23032 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23033 overlap_hl
, dummy_x
, last_x
);
23034 for (s
= h
; s
; s
= s
->next
)
23035 s
->background_filled_p
= 1;
23036 compute_overhangs_and_x (t
, head
->x
, 1);
23037 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23040 /* Append glyphs strings for glyphs following the last glyph
23041 string tail that are overwritten by tail. The background of
23042 these strings has to be drawn because tail's foreground draws
23044 i
= right_overwritten (tail
);
23047 enum draw_glyphs_face overlap_hl
;
23049 if (check_mouse_face
23050 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23051 overlap_hl
= DRAW_MOUSE_FACE
;
23053 overlap_hl
= DRAW_NORMAL_TEXT
;
23055 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23056 overlap_hl
, x
, last_x
);
23057 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23058 we don't have `end = i;' here. */
23059 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23060 append_glyph_string_lists (&head
, &tail
, h
, t
);
23064 /* Append glyph strings for glyphs following the last glyph
23065 string tail that overwrite tail. The foreground of such
23066 glyphs has to be drawn because it writes into the background
23067 of tail. The background must not be drawn because it could
23068 paint over the foreground of following glyphs. */
23069 i
= right_overwriting (tail
);
23072 enum draw_glyphs_face overlap_hl
;
23073 if (check_mouse_face
23074 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23075 overlap_hl
= DRAW_MOUSE_FACE
;
23077 overlap_hl
= DRAW_NORMAL_TEXT
;
23080 i
++; /* We must include the Ith glyph. */
23081 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23082 overlap_hl
, x
, last_x
);
23083 for (s
= h
; s
; s
= s
->next
)
23084 s
->background_filled_p
= 1;
23085 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23086 append_glyph_string_lists (&head
, &tail
, h
, t
);
23088 if (clip_head
|| clip_tail
)
23089 for (s
= head
; s
; s
= s
->next
)
23091 s
->clip_head
= clip_head
;
23092 s
->clip_tail
= clip_tail
;
23096 /* Draw all strings. */
23097 for (s
= head
; s
; s
= s
->next
)
23098 FRAME_RIF (f
)->draw_glyph_string (s
);
23101 /* When focus a sole frame and move horizontally, this sets on_p to 0
23102 causing a failure to erase prev cursor position. */
23103 if (area
== TEXT_AREA
23104 && !row
->full_width_p
23105 /* When drawing overlapping rows, only the glyph strings'
23106 foreground is drawn, which doesn't erase a cursor
23110 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23111 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23112 : (tail
? tail
->x
+ tail
->background_width
: x
));
23116 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23117 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23121 /* Value is the x-position up to which drawn, relative to AREA of W.
23122 This doesn't include parts drawn because of overhangs. */
23123 if (row
->full_width_p
)
23124 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23126 x_reached
-= area_left
;
23128 RELEASE_HDC (hdc
, f
);
23133 /* Expand row matrix if too narrow. Don't expand if area
23136 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23138 if (!fonts_changed_p \
23139 && (it->glyph_row->glyphs[area] \
23140 < it->glyph_row->glyphs[area + 1])) \
23142 it->w->ncols_scale_factor++; \
23143 fonts_changed_p = 1; \
23147 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23148 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23151 append_glyph (struct it
*it
)
23153 struct glyph
*glyph
;
23154 enum glyph_row_area area
= it
->area
;
23156 xassert (it
->glyph_row
);
23157 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23159 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23160 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23162 /* If the glyph row is reversed, we need to prepend the glyph
23163 rather than append it. */
23164 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23168 /* Make room for the additional glyph. */
23169 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23171 glyph
= it
->glyph_row
->glyphs
[area
];
23173 glyph
->charpos
= CHARPOS (it
->position
);
23174 glyph
->object
= it
->object
;
23175 if (it
->pixel_width
> 0)
23177 glyph
->pixel_width
= it
->pixel_width
;
23178 glyph
->padding_p
= 0;
23182 /* Assure at least 1-pixel width. Otherwise, cursor can't
23183 be displayed correctly. */
23184 glyph
->pixel_width
= 1;
23185 glyph
->padding_p
= 1;
23187 glyph
->ascent
= it
->ascent
;
23188 glyph
->descent
= it
->descent
;
23189 glyph
->voffset
= it
->voffset
;
23190 glyph
->type
= CHAR_GLYPH
;
23191 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23192 glyph
->multibyte_p
= it
->multibyte_p
;
23193 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23194 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23195 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23196 || it
->phys_descent
> it
->descent
);
23197 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23198 glyph
->face_id
= it
->face_id
;
23199 glyph
->u
.ch
= it
->char_to_display
;
23200 glyph
->slice
.img
= null_glyph_slice
;
23201 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23204 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23205 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23207 glyph
->bidi_type
= it
->bidi_it
.type
;
23211 glyph
->resolved_level
= 0;
23212 glyph
->bidi_type
= UNKNOWN_BT
;
23214 ++it
->glyph_row
->used
[area
];
23217 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23220 /* Store one glyph for the composition IT->cmp_it.id in
23221 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23225 append_composite_glyph (struct it
*it
)
23227 struct glyph
*glyph
;
23228 enum glyph_row_area area
= it
->area
;
23230 xassert (it
->glyph_row
);
23232 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23233 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23235 /* If the glyph row is reversed, we need to prepend the glyph
23236 rather than append it. */
23237 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23241 /* Make room for the new glyph. */
23242 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23244 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23246 glyph
->charpos
= it
->cmp_it
.charpos
;
23247 glyph
->object
= it
->object
;
23248 glyph
->pixel_width
= it
->pixel_width
;
23249 glyph
->ascent
= it
->ascent
;
23250 glyph
->descent
= it
->descent
;
23251 glyph
->voffset
= it
->voffset
;
23252 glyph
->type
= COMPOSITE_GLYPH
;
23253 if (it
->cmp_it
.ch
< 0)
23255 glyph
->u
.cmp
.automatic
= 0;
23256 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23257 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23261 glyph
->u
.cmp
.automatic
= 1;
23262 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23263 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23264 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23266 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23267 glyph
->multibyte_p
= it
->multibyte_p
;
23268 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23269 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23270 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23271 || it
->phys_descent
> it
->descent
);
23272 glyph
->padding_p
= 0;
23273 glyph
->glyph_not_available_p
= 0;
23274 glyph
->face_id
= it
->face_id
;
23275 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23278 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23279 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23281 glyph
->bidi_type
= it
->bidi_it
.type
;
23283 ++it
->glyph_row
->used
[area
];
23286 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23290 /* Change IT->ascent and IT->height according to the setting of
23294 take_vertical_position_into_account (struct it
*it
)
23298 if (it
->voffset
< 0)
23299 /* Increase the ascent so that we can display the text higher
23301 it
->ascent
-= it
->voffset
;
23303 /* Increase the descent so that we can display the text lower
23305 it
->descent
+= it
->voffset
;
23310 /* Produce glyphs/get display metrics for the image IT is loaded with.
23311 See the description of struct display_iterator in dispextern.h for
23312 an overview of struct display_iterator. */
23315 produce_image_glyph (struct it
*it
)
23319 int glyph_ascent
, crop
;
23320 struct glyph_slice slice
;
23322 xassert (it
->what
== IT_IMAGE
);
23324 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23326 /* Make sure X resources of the face is loaded. */
23327 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23329 if (it
->image_id
< 0)
23331 /* Fringe bitmap. */
23332 it
->ascent
= it
->phys_ascent
= 0;
23333 it
->descent
= it
->phys_descent
= 0;
23334 it
->pixel_width
= 0;
23339 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23341 /* Make sure X resources of the image is loaded. */
23342 prepare_image_for_display (it
->f
, img
);
23344 slice
.x
= slice
.y
= 0;
23345 slice
.width
= img
->width
;
23346 slice
.height
= img
->height
;
23348 if (INTEGERP (it
->slice
.x
))
23349 slice
.x
= XINT (it
->slice
.x
);
23350 else if (FLOATP (it
->slice
.x
))
23351 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23353 if (INTEGERP (it
->slice
.y
))
23354 slice
.y
= XINT (it
->slice
.y
);
23355 else if (FLOATP (it
->slice
.y
))
23356 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23358 if (INTEGERP (it
->slice
.width
))
23359 slice
.width
= XINT (it
->slice
.width
);
23360 else if (FLOATP (it
->slice
.width
))
23361 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23363 if (INTEGERP (it
->slice
.height
))
23364 slice
.height
= XINT (it
->slice
.height
);
23365 else if (FLOATP (it
->slice
.height
))
23366 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23368 if (slice
.x
>= img
->width
)
23369 slice
.x
= img
->width
;
23370 if (slice
.y
>= img
->height
)
23371 slice
.y
= img
->height
;
23372 if (slice
.x
+ slice
.width
>= img
->width
)
23373 slice
.width
= img
->width
- slice
.x
;
23374 if (slice
.y
+ slice
.height
> img
->height
)
23375 slice
.height
= img
->height
- slice
.y
;
23377 if (slice
.width
== 0 || slice
.height
== 0)
23380 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23382 it
->descent
= slice
.height
- glyph_ascent
;
23384 it
->descent
+= img
->vmargin
;
23385 if (slice
.y
+ slice
.height
== img
->height
)
23386 it
->descent
+= img
->vmargin
;
23387 it
->phys_descent
= it
->descent
;
23389 it
->pixel_width
= slice
.width
;
23391 it
->pixel_width
+= img
->hmargin
;
23392 if (slice
.x
+ slice
.width
== img
->width
)
23393 it
->pixel_width
+= img
->hmargin
;
23395 /* It's quite possible for images to have an ascent greater than
23396 their height, so don't get confused in that case. */
23397 if (it
->descent
< 0)
23402 if (face
->box
!= FACE_NO_BOX
)
23404 if (face
->box_line_width
> 0)
23407 it
->ascent
+= face
->box_line_width
;
23408 if (slice
.y
+ slice
.height
== img
->height
)
23409 it
->descent
+= face
->box_line_width
;
23412 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23413 it
->pixel_width
+= eabs (face
->box_line_width
);
23414 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23415 it
->pixel_width
+= eabs (face
->box_line_width
);
23418 take_vertical_position_into_account (it
);
23420 /* Automatically crop wide image glyphs at right edge so we can
23421 draw the cursor on same display row. */
23422 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23423 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23425 it
->pixel_width
-= crop
;
23426 slice
.width
-= crop
;
23431 struct glyph
*glyph
;
23432 enum glyph_row_area area
= it
->area
;
23434 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23435 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23437 glyph
->charpos
= CHARPOS (it
->position
);
23438 glyph
->object
= it
->object
;
23439 glyph
->pixel_width
= it
->pixel_width
;
23440 glyph
->ascent
= glyph_ascent
;
23441 glyph
->descent
= it
->descent
;
23442 glyph
->voffset
= it
->voffset
;
23443 glyph
->type
= IMAGE_GLYPH
;
23444 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23445 glyph
->multibyte_p
= it
->multibyte_p
;
23446 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23447 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23448 glyph
->overlaps_vertically_p
= 0;
23449 glyph
->padding_p
= 0;
23450 glyph
->glyph_not_available_p
= 0;
23451 glyph
->face_id
= it
->face_id
;
23452 glyph
->u
.img_id
= img
->id
;
23453 glyph
->slice
.img
= slice
;
23454 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23457 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23458 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23460 glyph
->bidi_type
= it
->bidi_it
.type
;
23462 ++it
->glyph_row
->used
[area
];
23465 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23470 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23471 of the glyph, WIDTH and HEIGHT are the width and height of the
23472 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23475 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23476 int width
, int height
, int ascent
)
23478 struct glyph
*glyph
;
23479 enum glyph_row_area area
= it
->area
;
23481 xassert (ascent
>= 0 && ascent
<= height
);
23483 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23484 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23486 /* If the glyph row is reversed, we need to prepend the glyph
23487 rather than append it. */
23488 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23492 /* Make room for the additional glyph. */
23493 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23495 glyph
= it
->glyph_row
->glyphs
[area
];
23497 glyph
->charpos
= CHARPOS (it
->position
);
23498 glyph
->object
= object
;
23499 glyph
->pixel_width
= width
;
23500 glyph
->ascent
= ascent
;
23501 glyph
->descent
= height
- ascent
;
23502 glyph
->voffset
= it
->voffset
;
23503 glyph
->type
= STRETCH_GLYPH
;
23504 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23505 glyph
->multibyte_p
= it
->multibyte_p
;
23506 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23507 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23508 glyph
->overlaps_vertically_p
= 0;
23509 glyph
->padding_p
= 0;
23510 glyph
->glyph_not_available_p
= 0;
23511 glyph
->face_id
= it
->face_id
;
23512 glyph
->u
.stretch
.ascent
= ascent
;
23513 glyph
->u
.stretch
.height
= height
;
23514 glyph
->slice
.img
= null_glyph_slice
;
23515 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23518 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23519 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23521 glyph
->bidi_type
= it
->bidi_it
.type
;
23525 glyph
->resolved_level
= 0;
23526 glyph
->bidi_type
= UNKNOWN_BT
;
23528 ++it
->glyph_row
->used
[area
];
23531 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23534 #endif /* HAVE_WINDOW_SYSTEM */
23536 /* Produce a stretch glyph for iterator IT. IT->object is the value
23537 of the glyph property displayed. The value must be a list
23538 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23541 1. `:width WIDTH' specifies that the space should be WIDTH *
23542 canonical char width wide. WIDTH may be an integer or floating
23545 2. `:relative-width FACTOR' specifies that the width of the stretch
23546 should be computed from the width of the first character having the
23547 `glyph' property, and should be FACTOR times that width.
23549 3. `:align-to HPOS' specifies that the space should be wide enough
23550 to reach HPOS, a value in canonical character units.
23552 Exactly one of the above pairs must be present.
23554 4. `:height HEIGHT' specifies that the height of the stretch produced
23555 should be HEIGHT, measured in canonical character units.
23557 5. `:relative-height FACTOR' specifies that the height of the
23558 stretch should be FACTOR times the height of the characters having
23559 the glyph property.
23561 Either none or exactly one of 4 or 5 must be present.
23563 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23564 of the stretch should be used for the ascent of the stretch.
23565 ASCENT must be in the range 0 <= ASCENT <= 100. */
23568 produce_stretch_glyph (struct it
*it
)
23570 /* (space :width WIDTH :height HEIGHT ...) */
23571 Lisp_Object prop
, plist
;
23572 int width
= 0, height
= 0, align_to
= -1;
23573 int zero_width_ok_p
= 0;
23576 struct face
*face
= NULL
;
23577 struct font
*font
= NULL
;
23579 #ifdef HAVE_WINDOW_SYSTEM
23580 int zero_height_ok_p
= 0;
23582 if (FRAME_WINDOW_P (it
->f
))
23584 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23585 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23586 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23590 /* List should start with `space'. */
23591 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23592 plist
= XCDR (it
->object
);
23594 /* Compute the width of the stretch. */
23595 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23596 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23598 /* Absolute width `:width WIDTH' specified and valid. */
23599 zero_width_ok_p
= 1;
23602 #ifdef HAVE_WINDOW_SYSTEM
23603 else if (FRAME_WINDOW_P (it
->f
)
23604 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23606 /* Relative width `:relative-width FACTOR' specified and valid.
23607 Compute the width of the characters having the `glyph'
23610 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23613 if (it
->multibyte_p
)
23614 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23617 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23618 if (! ASCII_CHAR_P (it2
.c
))
23619 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23622 it2
.glyph_row
= NULL
;
23623 it2
.what
= IT_CHARACTER
;
23624 x_produce_glyphs (&it2
);
23625 width
= NUMVAL (prop
) * it2
.pixel_width
;
23627 #endif /* HAVE_WINDOW_SYSTEM */
23628 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23629 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23631 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23632 align_to
= (align_to
< 0
23634 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23635 else if (align_to
< 0)
23636 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23637 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23638 zero_width_ok_p
= 1;
23641 /* Nothing specified -> width defaults to canonical char width. */
23642 width
= FRAME_COLUMN_WIDTH (it
->f
);
23644 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23647 #ifdef HAVE_WINDOW_SYSTEM
23648 /* Compute height. */
23649 if (FRAME_WINDOW_P (it
->f
))
23651 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23652 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23655 zero_height_ok_p
= 1;
23657 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23659 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23661 height
= FONT_HEIGHT (font
);
23663 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
23666 /* Compute percentage of height used for ascent. If
23667 `:ascent ASCENT' is present and valid, use that. Otherwise,
23668 derive the ascent from the font in use. */
23669 if (prop
= Fplist_get (plist
, QCascent
),
23670 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
23671 ascent
= height
* NUMVAL (prop
) / 100.0;
23672 else if (!NILP (prop
)
23673 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23674 ascent
= min (max (0, (int)tem
), height
);
23676 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
23679 #endif /* HAVE_WINDOW_SYSTEM */
23682 if (width
> 0 && it
->line_wrap
!= TRUNCATE
23683 && it
->current_x
+ width
> it
->last_visible_x
)
23685 width
= it
->last_visible_x
- it
->current_x
;
23686 #ifdef HAVE_WINDOW_SYSTEM
23687 /* Subtract one more pixel from the stretch width, but only on
23688 GUI frames, since on a TTY each glyph is one "pixel" wide. */
23689 width
-= FRAME_WINDOW_P (it
->f
);
23693 if (width
> 0 && height
> 0 && it
->glyph_row
)
23695 Lisp_Object o_object
= it
->object
;
23696 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
23699 if (!STRINGP (object
))
23700 object
= it
->w
->buffer
;
23701 #ifdef HAVE_WINDOW_SYSTEM
23702 if (FRAME_WINDOW_P (it
->f
))
23703 append_stretch_glyph (it
, object
, width
, height
, ascent
);
23707 it
->object
= object
;
23708 it
->char_to_display
= ' ';
23709 it
->pixel_width
= it
->len
= 1;
23711 tty_append_glyph (it
);
23712 it
->object
= o_object
;
23716 it
->pixel_width
= width
;
23717 #ifdef HAVE_WINDOW_SYSTEM
23718 if (FRAME_WINDOW_P (it
->f
))
23720 it
->ascent
= it
->phys_ascent
= ascent
;
23721 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
23722 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
23723 take_vertical_position_into_account (it
);
23727 it
->nglyphs
= width
;
23730 #ifdef HAVE_WINDOW_SYSTEM
23732 /* Calculate line-height and line-spacing properties.
23733 An integer value specifies explicit pixel value.
23734 A float value specifies relative value to current face height.
23735 A cons (float . face-name) specifies relative value to
23736 height of specified face font.
23738 Returns height in pixels, or nil. */
23742 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
23743 int boff
, int override
)
23745 Lisp_Object face_name
= Qnil
;
23746 int ascent
, descent
, height
;
23748 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
23753 face_name
= XCAR (val
);
23755 if (!NUMBERP (val
))
23756 val
= make_number (1);
23757 if (NILP (face_name
))
23759 height
= it
->ascent
+ it
->descent
;
23764 if (NILP (face_name
))
23766 font
= FRAME_FONT (it
->f
);
23767 boff
= FRAME_BASELINE_OFFSET (it
->f
);
23769 else if (EQ (face_name
, Qt
))
23778 face_id
= lookup_named_face (it
->f
, face_name
, 0);
23780 return make_number (-1);
23782 face
= FACE_FROM_ID (it
->f
, face_id
);
23785 return make_number (-1);
23786 boff
= font
->baseline_offset
;
23787 if (font
->vertical_centering
)
23788 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23791 ascent
= FONT_BASE (font
) + boff
;
23792 descent
= FONT_DESCENT (font
) - boff
;
23796 it
->override_ascent
= ascent
;
23797 it
->override_descent
= descent
;
23798 it
->override_boff
= boff
;
23801 height
= ascent
+ descent
;
23805 height
= (int)(XFLOAT_DATA (val
) * height
);
23806 else if (INTEGERP (val
))
23807 height
*= XINT (val
);
23809 return make_number (height
);
23813 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
23814 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
23815 and only if this is for a character for which no font was found.
23817 If the display method (it->glyphless_method) is
23818 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
23819 length of the acronym or the hexadecimal string, UPPER_XOFF and
23820 UPPER_YOFF are pixel offsets for the upper part of the string,
23821 LOWER_XOFF and LOWER_YOFF are for the lower part.
23823 For the other display methods, LEN through LOWER_YOFF are zero. */
23826 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
23827 short upper_xoff
, short upper_yoff
,
23828 short lower_xoff
, short lower_yoff
)
23830 struct glyph
*glyph
;
23831 enum glyph_row_area area
= it
->area
;
23833 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23834 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23836 /* If the glyph row is reversed, we need to prepend the glyph
23837 rather than append it. */
23838 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23842 /* Make room for the additional glyph. */
23843 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23845 glyph
= it
->glyph_row
->glyphs
[area
];
23847 glyph
->charpos
= CHARPOS (it
->position
);
23848 glyph
->object
= it
->object
;
23849 glyph
->pixel_width
= it
->pixel_width
;
23850 glyph
->ascent
= it
->ascent
;
23851 glyph
->descent
= it
->descent
;
23852 glyph
->voffset
= it
->voffset
;
23853 glyph
->type
= GLYPHLESS_GLYPH
;
23854 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
23855 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
23856 glyph
->u
.glyphless
.len
= len
;
23857 glyph
->u
.glyphless
.ch
= it
->c
;
23858 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
23859 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
23860 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
23861 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
23862 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23863 glyph
->multibyte_p
= it
->multibyte_p
;
23864 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23865 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23866 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23867 || it
->phys_descent
> it
->descent
);
23868 glyph
->padding_p
= 0;
23869 glyph
->glyph_not_available_p
= 0;
23870 glyph
->face_id
= face_id
;
23871 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23874 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23875 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23877 glyph
->bidi_type
= it
->bidi_it
.type
;
23879 ++it
->glyph_row
->used
[area
];
23882 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23886 /* Produce a glyph for a glyphless character for iterator IT.
23887 IT->glyphless_method specifies which method to use for displaying
23888 the character. See the description of enum
23889 glyphless_display_method in dispextern.h for the detail.
23891 FOR_NO_FONT is nonzero if and only if this is for a character for
23892 which no font was found. ACRONYM, if non-nil, is an acronym string
23893 for the character. */
23896 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
23901 int base_width
, base_height
, width
, height
;
23902 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
23905 /* Get the metrics of the base font. We always refer to the current
23907 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
23908 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23909 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
23910 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
23911 base_height
= it
->ascent
+ it
->descent
;
23912 base_width
= font
->average_width
;
23914 /* Get a face ID for the glyph by utilizing a cache (the same way as
23915 done for `escape-glyph' in get_next_display_element). */
23916 if (it
->f
== last_glyphless_glyph_frame
23917 && it
->face_id
== last_glyphless_glyph_face_id
)
23919 face_id
= last_glyphless_glyph_merged_face_id
;
23923 /* Merge the `glyphless-char' face into the current face. */
23924 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
23925 last_glyphless_glyph_frame
= it
->f
;
23926 last_glyphless_glyph_face_id
= it
->face_id
;
23927 last_glyphless_glyph_merged_face_id
= face_id
;
23930 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
23932 it
->pixel_width
= THIN_SPACE_WIDTH
;
23934 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23936 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
23938 width
= CHAR_WIDTH (it
->c
);
23941 else if (width
> 4)
23943 it
->pixel_width
= base_width
* width
;
23945 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23951 unsigned int code
[6];
23953 int ascent
, descent
;
23954 struct font_metrics metrics_upper
, metrics_lower
;
23956 face
= FACE_FROM_ID (it
->f
, face_id
);
23957 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23958 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23960 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
23962 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
23963 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
23964 if (CONSP (acronym
))
23965 acronym
= XCAR (acronym
);
23966 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
23970 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
23971 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
23974 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
23975 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
23976 upper_len
= (len
+ 1) / 2;
23977 font
->driver
->text_extents (font
, code
, upper_len
,
23979 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
23984 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
23985 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
23986 upper_xoff
= upper_yoff
= 2; /* the typical case */
23987 if (base_width
>= width
)
23989 /* Align the upper to the left, the lower to the right. */
23990 it
->pixel_width
= base_width
;
23991 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
23995 /* Center the shorter one. */
23996 it
->pixel_width
= width
;
23997 if (metrics_upper
.width
>= metrics_lower
.width
)
23998 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24001 /* FIXME: This code doesn't look right. It formerly was
24002 missing the "lower_xoff = 0;", which couldn't have
24003 been right since it left lower_xoff uninitialized. */
24005 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24009 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24010 top, bottom, and between upper and lower strings. */
24011 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24012 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24013 /* Center vertically.
24014 H:base_height, D:base_descent
24015 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24017 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24018 descent = D - H/2 + h/2;
24019 lower_yoff = descent - 2 - ld;
24020 upper_yoff = lower_yoff - la - 1 - ud; */
24021 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24022 descent
= it
->descent
- (base_height
- height
) / 2;
24023 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24024 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24025 - metrics_upper
.descent
);
24026 /* Don't make the height shorter than the base height. */
24027 if (height
> base_height
)
24029 it
->ascent
= ascent
;
24030 it
->descent
= descent
;
24034 it
->phys_ascent
= it
->ascent
;
24035 it
->phys_descent
= it
->descent
;
24037 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24038 upper_xoff
, upper_yoff
,
24039 lower_xoff
, lower_yoff
);
24041 take_vertical_position_into_account (it
);
24046 Produce glyphs/get display metrics for the display element IT is
24047 loaded with. See the description of struct it in dispextern.h
24048 for an overview of struct it. */
24051 x_produce_glyphs (struct it
*it
)
24053 int extra_line_spacing
= it
->extra_line_spacing
;
24055 it
->glyph_not_available_p
= 0;
24057 if (it
->what
== IT_CHARACTER
)
24060 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24061 struct font
*font
= face
->font
;
24062 struct font_metrics
*pcm
= NULL
;
24063 int boff
; /* baseline offset */
24067 /* When no suitable font is found, display this character by
24068 the method specified in the first extra slot of
24069 Vglyphless_char_display. */
24070 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24072 xassert (it
->what
== IT_GLYPHLESS
);
24073 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24077 boff
= font
->baseline_offset
;
24078 if (font
->vertical_centering
)
24079 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24081 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24087 if (it
->override_ascent
>= 0)
24089 it
->ascent
= it
->override_ascent
;
24090 it
->descent
= it
->override_descent
;
24091 boff
= it
->override_boff
;
24095 it
->ascent
= FONT_BASE (font
) + boff
;
24096 it
->descent
= FONT_DESCENT (font
) - boff
;
24099 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24101 pcm
= get_per_char_metric (font
, &char2b
);
24102 if (pcm
->width
== 0
24103 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24109 it
->phys_ascent
= pcm
->ascent
+ boff
;
24110 it
->phys_descent
= pcm
->descent
- boff
;
24111 it
->pixel_width
= pcm
->width
;
24115 it
->glyph_not_available_p
= 1;
24116 it
->phys_ascent
= it
->ascent
;
24117 it
->phys_descent
= it
->descent
;
24118 it
->pixel_width
= font
->space_width
;
24121 if (it
->constrain_row_ascent_descent_p
)
24123 if (it
->descent
> it
->max_descent
)
24125 it
->ascent
+= it
->descent
- it
->max_descent
;
24126 it
->descent
= it
->max_descent
;
24128 if (it
->ascent
> it
->max_ascent
)
24130 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24131 it
->ascent
= it
->max_ascent
;
24133 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24134 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24135 extra_line_spacing
= 0;
24138 /* If this is a space inside a region of text with
24139 `space-width' property, change its width. */
24140 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24142 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24144 /* If face has a box, add the box thickness to the character
24145 height. If character has a box line to the left and/or
24146 right, add the box line width to the character's width. */
24147 if (face
->box
!= FACE_NO_BOX
)
24149 int thick
= face
->box_line_width
;
24153 it
->ascent
+= thick
;
24154 it
->descent
+= thick
;
24159 if (it
->start_of_box_run_p
)
24160 it
->pixel_width
+= thick
;
24161 if (it
->end_of_box_run_p
)
24162 it
->pixel_width
+= thick
;
24165 /* If face has an overline, add the height of the overline
24166 (1 pixel) and a 1 pixel margin to the character height. */
24167 if (face
->overline_p
)
24168 it
->ascent
+= overline_margin
;
24170 if (it
->constrain_row_ascent_descent_p
)
24172 if (it
->ascent
> it
->max_ascent
)
24173 it
->ascent
= it
->max_ascent
;
24174 if (it
->descent
> it
->max_descent
)
24175 it
->descent
= it
->max_descent
;
24178 take_vertical_position_into_account (it
);
24180 /* If we have to actually produce glyphs, do it. */
24185 /* Translate a space with a `space-width' property
24186 into a stretch glyph. */
24187 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24188 / FONT_HEIGHT (font
));
24189 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24190 it
->ascent
+ it
->descent
, ascent
);
24195 /* If characters with lbearing or rbearing are displayed
24196 in this line, record that fact in a flag of the
24197 glyph row. This is used to optimize X output code. */
24198 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24199 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24201 if (! stretched_p
&& it
->pixel_width
== 0)
24202 /* We assure that all visible glyphs have at least 1-pixel
24204 it
->pixel_width
= 1;
24206 else if (it
->char_to_display
== '\n')
24208 /* A newline has no width, but we need the height of the
24209 line. But if previous part of the line sets a height,
24210 don't increase that height */
24212 Lisp_Object height
;
24213 Lisp_Object total_height
= Qnil
;
24215 it
->override_ascent
= -1;
24216 it
->pixel_width
= 0;
24219 height
= get_it_property (it
, Qline_height
);
24220 /* Split (line-height total-height) list */
24222 && CONSP (XCDR (height
))
24223 && NILP (XCDR (XCDR (height
))))
24225 total_height
= XCAR (XCDR (height
));
24226 height
= XCAR (height
);
24228 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24230 if (it
->override_ascent
>= 0)
24232 it
->ascent
= it
->override_ascent
;
24233 it
->descent
= it
->override_descent
;
24234 boff
= it
->override_boff
;
24238 it
->ascent
= FONT_BASE (font
) + boff
;
24239 it
->descent
= FONT_DESCENT (font
) - boff
;
24242 if (EQ (height
, Qt
))
24244 if (it
->descent
> it
->max_descent
)
24246 it
->ascent
+= it
->descent
- it
->max_descent
;
24247 it
->descent
= it
->max_descent
;
24249 if (it
->ascent
> it
->max_ascent
)
24251 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24252 it
->ascent
= it
->max_ascent
;
24254 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24255 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24256 it
->constrain_row_ascent_descent_p
= 1;
24257 extra_line_spacing
= 0;
24261 Lisp_Object spacing
;
24263 it
->phys_ascent
= it
->ascent
;
24264 it
->phys_descent
= it
->descent
;
24266 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24267 && face
->box
!= FACE_NO_BOX
24268 && face
->box_line_width
> 0)
24270 it
->ascent
+= face
->box_line_width
;
24271 it
->descent
+= face
->box_line_width
;
24274 && XINT (height
) > it
->ascent
+ it
->descent
)
24275 it
->ascent
= XINT (height
) - it
->descent
;
24277 if (!NILP (total_height
))
24278 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24281 spacing
= get_it_property (it
, Qline_spacing
);
24282 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24284 if (INTEGERP (spacing
))
24286 extra_line_spacing
= XINT (spacing
);
24287 if (!NILP (total_height
))
24288 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24292 else /* i.e. (it->char_to_display == '\t') */
24294 if (font
->space_width
> 0)
24296 int tab_width
= it
->tab_width
* font
->space_width
;
24297 int x
= it
->current_x
+ it
->continuation_lines_width
;
24298 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24300 /* If the distance from the current position to the next tab
24301 stop is less than a space character width, use the
24302 tab stop after that. */
24303 if (next_tab_x
- x
< font
->space_width
)
24304 next_tab_x
+= tab_width
;
24306 it
->pixel_width
= next_tab_x
- x
;
24308 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24309 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24313 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24314 it
->ascent
+ it
->descent
, it
->ascent
);
24319 it
->pixel_width
= 0;
24324 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24326 /* A static composition.
24328 Note: A composition is represented as one glyph in the
24329 glyph matrix. There are no padding glyphs.
24331 Important note: pixel_width, ascent, and descent are the
24332 values of what is drawn by draw_glyphs (i.e. the values of
24333 the overall glyphs composed). */
24334 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24335 int boff
; /* baseline offset */
24336 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24337 int glyph_len
= cmp
->glyph_len
;
24338 struct font
*font
= face
->font
;
24342 /* If we have not yet calculated pixel size data of glyphs of
24343 the composition for the current face font, calculate them
24344 now. Theoretically, we have to check all fonts for the
24345 glyphs, but that requires much time and memory space. So,
24346 here we check only the font of the first glyph. This may
24347 lead to incorrect display, but it's very rare, and C-l
24348 (recenter-top-bottom) can correct the display anyway. */
24349 if (! cmp
->font
|| cmp
->font
!= font
)
24351 /* Ascent and descent of the font of the first character
24352 of this composition (adjusted by baseline offset).
24353 Ascent and descent of overall glyphs should not be less
24354 than these, respectively. */
24355 int font_ascent
, font_descent
, font_height
;
24356 /* Bounding box of the overall glyphs. */
24357 int leftmost
, rightmost
, lowest
, highest
;
24358 int lbearing
, rbearing
;
24359 int i
, width
, ascent
, descent
;
24360 int left_padded
= 0, right_padded
= 0;
24361 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24363 struct font_metrics
*pcm
;
24364 int font_not_found_p
;
24367 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24368 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24370 if (glyph_len
< cmp
->glyph_len
)
24372 for (i
= 0; i
< glyph_len
; i
++)
24374 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24376 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24381 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24382 : IT_CHARPOS (*it
));
24383 /* If no suitable font is found, use the default font. */
24384 font_not_found_p
= font
== NULL
;
24385 if (font_not_found_p
)
24387 face
= face
->ascii_face
;
24390 boff
= font
->baseline_offset
;
24391 if (font
->vertical_centering
)
24392 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24393 font_ascent
= FONT_BASE (font
) + boff
;
24394 font_descent
= FONT_DESCENT (font
) - boff
;
24395 font_height
= FONT_HEIGHT (font
);
24397 cmp
->font
= (void *) font
;
24400 if (! font_not_found_p
)
24402 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24404 pcm
= get_per_char_metric (font
, &char2b
);
24407 /* Initialize the bounding box. */
24410 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24411 ascent
= pcm
->ascent
;
24412 descent
= pcm
->descent
;
24413 lbearing
= pcm
->lbearing
;
24414 rbearing
= pcm
->rbearing
;
24418 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24419 ascent
= FONT_BASE (font
);
24420 descent
= FONT_DESCENT (font
);
24427 lowest
= - descent
+ boff
;
24428 highest
= ascent
+ boff
;
24430 if (! font_not_found_p
24431 && font
->default_ascent
24432 && CHAR_TABLE_P (Vuse_default_ascent
)
24433 && !NILP (Faref (Vuse_default_ascent
,
24434 make_number (it
->char_to_display
))))
24435 highest
= font
->default_ascent
+ boff
;
24437 /* Draw the first glyph at the normal position. It may be
24438 shifted to right later if some other glyphs are drawn
24440 cmp
->offsets
[i
* 2] = 0;
24441 cmp
->offsets
[i
* 2 + 1] = boff
;
24442 cmp
->lbearing
= lbearing
;
24443 cmp
->rbearing
= rbearing
;
24445 /* Set cmp->offsets for the remaining glyphs. */
24446 for (i
++; i
< glyph_len
; i
++)
24448 int left
, right
, btm
, top
;
24449 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24451 struct face
*this_face
;
24455 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24456 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24457 font
= this_face
->font
;
24463 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24465 pcm
= get_per_char_metric (font
, &char2b
);
24468 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24471 width
= pcm
->width
;
24472 ascent
= pcm
->ascent
;
24473 descent
= pcm
->descent
;
24474 lbearing
= pcm
->lbearing
;
24475 rbearing
= pcm
->rbearing
;
24476 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24478 /* Relative composition with or without
24479 alternate chars. */
24480 left
= (leftmost
+ rightmost
- width
) / 2;
24481 btm
= - descent
+ boff
;
24482 if (font
->relative_compose
24483 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24484 || NILP (Faref (Vignore_relative_composition
,
24485 make_number (ch
)))))
24488 if (- descent
>= font
->relative_compose
)
24489 /* One extra pixel between two glyphs. */
24491 else if (ascent
<= 0)
24492 /* One extra pixel between two glyphs. */
24493 btm
= lowest
- 1 - ascent
- descent
;
24498 /* A composition rule is specified by an integer
24499 value that encodes global and new reference
24500 points (GREF and NREF). GREF and NREF are
24501 specified by numbers as below:
24503 0---1---2 -- ascent
24507 9--10--11 -- center
24509 ---3---4---5--- baseline
24511 6---7---8 -- descent
24513 int rule
= COMPOSITION_RULE (cmp
, i
);
24514 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24516 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24517 grefx
= gref
% 3, nrefx
= nref
% 3;
24518 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24520 xoff
= font_height
* (xoff
- 128) / 256;
24522 yoff
= font_height
* (yoff
- 128) / 256;
24525 + grefx
* (rightmost
- leftmost
) / 2
24526 - nrefx
* width
/ 2
24529 btm
= ((grefy
== 0 ? highest
24531 : grefy
== 2 ? lowest
24532 : (highest
+ lowest
) / 2)
24533 - (nrefy
== 0 ? ascent
+ descent
24534 : nrefy
== 1 ? descent
- boff
24536 : (ascent
+ descent
) / 2)
24540 cmp
->offsets
[i
* 2] = left
;
24541 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24543 /* Update the bounding box of the overall glyphs. */
24546 right
= left
+ width
;
24547 if (left
< leftmost
)
24549 if (right
> rightmost
)
24552 top
= btm
+ descent
+ ascent
;
24558 if (cmp
->lbearing
> left
+ lbearing
)
24559 cmp
->lbearing
= left
+ lbearing
;
24560 if (cmp
->rbearing
< left
+ rbearing
)
24561 cmp
->rbearing
= left
+ rbearing
;
24565 /* If there are glyphs whose x-offsets are negative,
24566 shift all glyphs to the right and make all x-offsets
24570 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24571 cmp
->offsets
[i
* 2] -= leftmost
;
24572 rightmost
-= leftmost
;
24573 cmp
->lbearing
-= leftmost
;
24574 cmp
->rbearing
-= leftmost
;
24577 if (left_padded
&& cmp
->lbearing
< 0)
24579 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24580 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24581 rightmost
-= cmp
->lbearing
;
24582 cmp
->rbearing
-= cmp
->lbearing
;
24585 if (right_padded
&& rightmost
< cmp
->rbearing
)
24587 rightmost
= cmp
->rbearing
;
24590 cmp
->pixel_width
= rightmost
;
24591 cmp
->ascent
= highest
;
24592 cmp
->descent
= - lowest
;
24593 if (cmp
->ascent
< font_ascent
)
24594 cmp
->ascent
= font_ascent
;
24595 if (cmp
->descent
< font_descent
)
24596 cmp
->descent
= font_descent
;
24600 && (cmp
->lbearing
< 0
24601 || cmp
->rbearing
> cmp
->pixel_width
))
24602 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24604 it
->pixel_width
= cmp
->pixel_width
;
24605 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24606 it
->descent
= it
->phys_descent
= cmp
->descent
;
24607 if (face
->box
!= FACE_NO_BOX
)
24609 int thick
= face
->box_line_width
;
24613 it
->ascent
+= thick
;
24614 it
->descent
+= thick
;
24619 if (it
->start_of_box_run_p
)
24620 it
->pixel_width
+= thick
;
24621 if (it
->end_of_box_run_p
)
24622 it
->pixel_width
+= thick
;
24625 /* If face has an overline, add the height of the overline
24626 (1 pixel) and a 1 pixel margin to the character height. */
24627 if (face
->overline_p
)
24628 it
->ascent
+= overline_margin
;
24630 take_vertical_position_into_account (it
);
24631 if (it
->ascent
< 0)
24633 if (it
->descent
< 0)
24636 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24637 append_composite_glyph (it
);
24639 else if (it
->what
== IT_COMPOSITION
)
24641 /* A dynamic (automatic) composition. */
24642 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24643 Lisp_Object gstring
;
24644 struct font_metrics metrics
;
24648 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24650 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24653 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24654 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24655 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24656 it
->descent
= it
->phys_descent
= metrics
.descent
;
24657 if (face
->box
!= FACE_NO_BOX
)
24659 int thick
= face
->box_line_width
;
24663 it
->ascent
+= thick
;
24664 it
->descent
+= thick
;
24669 if (it
->start_of_box_run_p
)
24670 it
->pixel_width
+= thick
;
24671 if (it
->end_of_box_run_p
)
24672 it
->pixel_width
+= thick
;
24674 /* If face has an overline, add the height of the overline
24675 (1 pixel) and a 1 pixel margin to the character height. */
24676 if (face
->overline_p
)
24677 it
->ascent
+= overline_margin
;
24678 take_vertical_position_into_account (it
);
24679 if (it
->ascent
< 0)
24681 if (it
->descent
< 0)
24685 append_composite_glyph (it
);
24687 else if (it
->what
== IT_GLYPHLESS
)
24688 produce_glyphless_glyph (it
, 0, Qnil
);
24689 else if (it
->what
== IT_IMAGE
)
24690 produce_image_glyph (it
);
24691 else if (it
->what
== IT_STRETCH
)
24692 produce_stretch_glyph (it
);
24695 /* Accumulate dimensions. Note: can't assume that it->descent > 0
24696 because this isn't true for images with `:ascent 100'. */
24697 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
24698 if (it
->area
== TEXT_AREA
)
24699 it
->current_x
+= it
->pixel_width
;
24701 if (extra_line_spacing
> 0)
24703 it
->descent
+= extra_line_spacing
;
24704 if (extra_line_spacing
> it
->max_extra_line_spacing
)
24705 it
->max_extra_line_spacing
= extra_line_spacing
;
24708 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
24709 it
->max_descent
= max (it
->max_descent
, it
->descent
);
24710 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
24711 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
24715 Output LEN glyphs starting at START at the nominal cursor position.
24716 Advance the nominal cursor over the text. The global variable
24717 updated_window contains the window being updated, updated_row is
24718 the glyph row being updated, and updated_area is the area of that
24719 row being updated. */
24722 x_write_glyphs (struct glyph
*start
, int len
)
24724 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
24726 xassert (updated_window
&& updated_row
);
24727 /* When the window is hscrolled, cursor hpos can legitimately be out
24728 of bounds, but we draw the cursor at the corresponding window
24729 margin in that case. */
24730 if (!updated_row
->reversed_p
&& chpos
< 0)
24732 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
24733 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
24737 /* Write glyphs. */
24739 hpos
= start
- updated_row
->glyphs
[updated_area
];
24740 x
= draw_glyphs (updated_window
, output_cursor
.x
,
24741 updated_row
, updated_area
,
24743 DRAW_NORMAL_TEXT
, 0);
24745 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
24746 if (updated_area
== TEXT_AREA
24747 && updated_window
->phys_cursor_on_p
24748 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
24750 && chpos
< hpos
+ len
)
24751 updated_window
->phys_cursor_on_p
= 0;
24755 /* Advance the output cursor. */
24756 output_cursor
.hpos
+= len
;
24757 output_cursor
.x
= x
;
24762 Insert LEN glyphs from START at the nominal cursor position. */
24765 x_insert_glyphs (struct glyph
*start
, int len
)
24769 int line_height
, shift_by_width
, shifted_region_width
;
24770 struct glyph_row
*row
;
24771 struct glyph
*glyph
;
24772 int frame_x
, frame_y
;
24775 xassert (updated_window
&& updated_row
);
24777 w
= updated_window
;
24778 f
= XFRAME (WINDOW_FRAME (w
));
24780 /* Get the height of the line we are in. */
24782 line_height
= row
->height
;
24784 /* Get the width of the glyphs to insert. */
24785 shift_by_width
= 0;
24786 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
24787 shift_by_width
+= glyph
->pixel_width
;
24789 /* Get the width of the region to shift right. */
24790 shifted_region_width
= (window_box_width (w
, updated_area
)
24795 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
24796 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
24798 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
24799 line_height
, shift_by_width
);
24801 /* Write the glyphs. */
24802 hpos
= start
- row
->glyphs
[updated_area
];
24803 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
24805 DRAW_NORMAL_TEXT
, 0);
24807 /* Advance the output cursor. */
24808 output_cursor
.hpos
+= len
;
24809 output_cursor
.x
+= shift_by_width
;
24815 Erase the current text line from the nominal cursor position
24816 (inclusive) to pixel column TO_X (exclusive). The idea is that
24817 everything from TO_X onward is already erased.
24819 TO_X is a pixel position relative to updated_area of
24820 updated_window. TO_X == -1 means clear to the end of this area. */
24823 x_clear_end_of_line (int to_x
)
24826 struct window
*w
= updated_window
;
24827 int max_x
, min_y
, max_y
;
24828 int from_x
, from_y
, to_y
;
24830 xassert (updated_window
&& updated_row
);
24831 f
= XFRAME (w
->frame
);
24833 if (updated_row
->full_width_p
)
24834 max_x
= WINDOW_TOTAL_WIDTH (w
);
24836 max_x
= window_box_width (w
, updated_area
);
24837 max_y
= window_text_bottom_y (w
);
24839 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
24840 of window. For TO_X > 0, truncate to end of drawing area. */
24846 to_x
= min (to_x
, max_x
);
24848 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
24850 /* Notice if the cursor will be cleared by this operation. */
24851 if (!updated_row
->full_width_p
)
24852 notice_overwritten_cursor (w
, updated_area
,
24853 output_cursor
.x
, -1,
24855 MATRIX_ROW_BOTTOM_Y (updated_row
));
24857 from_x
= output_cursor
.x
;
24859 /* Translate to frame coordinates. */
24860 if (updated_row
->full_width_p
)
24862 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
24863 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
24867 int area_left
= window_box_left (w
, updated_area
);
24868 from_x
+= area_left
;
24872 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
24873 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
24874 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
24876 /* Prevent inadvertently clearing to end of the X window. */
24877 if (to_x
> from_x
&& to_y
> from_y
)
24880 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
24881 to_x
- from_x
, to_y
- from_y
);
24886 #endif /* HAVE_WINDOW_SYSTEM */
24890 /***********************************************************************
24892 ***********************************************************************/
24894 /* Value is the internal representation of the specified cursor type
24895 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
24896 of the bar cursor. */
24898 static enum text_cursor_kinds
24899 get_specified_cursor_type (Lisp_Object arg
, int *width
)
24901 enum text_cursor_kinds type
;
24906 if (EQ (arg
, Qbox
))
24907 return FILLED_BOX_CURSOR
;
24909 if (EQ (arg
, Qhollow
))
24910 return HOLLOW_BOX_CURSOR
;
24912 if (EQ (arg
, Qbar
))
24919 && EQ (XCAR (arg
), Qbar
)
24920 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
24922 *width
= XINT (XCDR (arg
));
24926 if (EQ (arg
, Qhbar
))
24929 return HBAR_CURSOR
;
24933 && EQ (XCAR (arg
), Qhbar
)
24934 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
24936 *width
= XINT (XCDR (arg
));
24937 return HBAR_CURSOR
;
24940 /* Treat anything unknown as "hollow box cursor".
24941 It was bad to signal an error; people have trouble fixing
24942 .Xdefaults with Emacs, when it has something bad in it. */
24943 type
= HOLLOW_BOX_CURSOR
;
24948 /* Set the default cursor types for specified frame. */
24950 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
24955 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
24956 FRAME_CURSOR_WIDTH (f
) = width
;
24958 /* By default, set up the blink-off state depending on the on-state. */
24960 tem
= Fassoc (arg
, Vblink_cursor_alist
);
24963 FRAME_BLINK_OFF_CURSOR (f
)
24964 = get_specified_cursor_type (XCDR (tem
), &width
);
24965 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
24968 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
24972 #ifdef HAVE_WINDOW_SYSTEM
24974 /* Return the cursor we want to be displayed in window W. Return
24975 width of bar/hbar cursor through WIDTH arg. Return with
24976 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
24977 (i.e. if the `system caret' should track this cursor).
24979 In a mini-buffer window, we want the cursor only to appear if we
24980 are reading input from this window. For the selected window, we
24981 want the cursor type given by the frame parameter or buffer local
24982 setting of cursor-type. If explicitly marked off, draw no cursor.
24983 In all other cases, we want a hollow box cursor. */
24985 static enum text_cursor_kinds
24986 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
24987 int *active_cursor
)
24989 struct frame
*f
= XFRAME (w
->frame
);
24990 struct buffer
*b
= XBUFFER (w
->buffer
);
24991 int cursor_type
= DEFAULT_CURSOR
;
24992 Lisp_Object alt_cursor
;
24993 int non_selected
= 0;
24995 *active_cursor
= 1;
24998 if (cursor_in_echo_area
24999 && FRAME_HAS_MINIBUF_P (f
)
25000 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25002 if (w
== XWINDOW (echo_area_window
))
25004 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25006 *width
= FRAME_CURSOR_WIDTH (f
);
25007 return FRAME_DESIRED_CURSOR (f
);
25010 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25013 *active_cursor
= 0;
25017 /* Detect a nonselected window or nonselected frame. */
25018 else if (w
!= XWINDOW (f
->selected_window
)
25019 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25021 *active_cursor
= 0;
25023 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25029 /* Never display a cursor in a window in which cursor-type is nil. */
25030 if (NILP (BVAR (b
, cursor_type
)))
25033 /* Get the normal cursor type for this window. */
25034 if (EQ (BVAR (b
, cursor_type
), Qt
))
25036 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25037 *width
= FRAME_CURSOR_WIDTH (f
);
25040 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25042 /* Use cursor-in-non-selected-windows instead
25043 for non-selected window or frame. */
25046 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25047 if (!EQ (Qt
, alt_cursor
))
25048 return get_specified_cursor_type (alt_cursor
, width
);
25049 /* t means modify the normal cursor type. */
25050 if (cursor_type
== FILLED_BOX_CURSOR
)
25051 cursor_type
= HOLLOW_BOX_CURSOR
;
25052 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25054 return cursor_type
;
25057 /* Use normal cursor if not blinked off. */
25058 if (!w
->cursor_off_p
)
25060 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25062 if (cursor_type
== FILLED_BOX_CURSOR
)
25064 /* Using a block cursor on large images can be very annoying.
25065 So use a hollow cursor for "large" images.
25066 If image is not transparent (no mask), also use hollow cursor. */
25067 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25068 if (img
!= NULL
&& IMAGEP (img
->spec
))
25070 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25071 where N = size of default frame font size.
25072 This should cover most of the "tiny" icons people may use. */
25074 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25075 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25076 cursor_type
= HOLLOW_BOX_CURSOR
;
25079 else if (cursor_type
!= NO_CURSOR
)
25081 /* Display current only supports BOX and HOLLOW cursors for images.
25082 So for now, unconditionally use a HOLLOW cursor when cursor is
25083 not a solid box cursor. */
25084 cursor_type
= HOLLOW_BOX_CURSOR
;
25087 return cursor_type
;
25090 /* Cursor is blinked off, so determine how to "toggle" it. */
25092 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25093 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25094 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25096 /* Then see if frame has specified a specific blink off cursor type. */
25097 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25099 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25100 return FRAME_BLINK_OFF_CURSOR (f
);
25104 /* Some people liked having a permanently visible blinking cursor,
25105 while others had very strong opinions against it. So it was
25106 decided to remove it. KFS 2003-09-03 */
25108 /* Finally perform built-in cursor blinking:
25109 filled box <-> hollow box
25110 wide [h]bar <-> narrow [h]bar
25111 narrow [h]bar <-> no cursor
25112 other type <-> no cursor */
25114 if (cursor_type
== FILLED_BOX_CURSOR
)
25115 return HOLLOW_BOX_CURSOR
;
25117 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25120 return cursor_type
;
25128 /* Notice when the text cursor of window W has been completely
25129 overwritten by a drawing operation that outputs glyphs in AREA
25130 starting at X0 and ending at X1 in the line starting at Y0 and
25131 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25132 the rest of the line after X0 has been written. Y coordinates
25133 are window-relative. */
25136 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25137 int x0
, int x1
, int y0
, int y1
)
25139 int cx0
, cx1
, cy0
, cy1
;
25140 struct glyph_row
*row
;
25142 if (!w
->phys_cursor_on_p
)
25144 if (area
!= TEXT_AREA
)
25147 if (w
->phys_cursor
.vpos
< 0
25148 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25149 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25150 !(row
->enabled_p
&& row
->displays_text_p
)))
25153 if (row
->cursor_in_fringe_p
)
25155 row
->cursor_in_fringe_p
= 0;
25156 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25157 w
->phys_cursor_on_p
= 0;
25161 cx0
= w
->phys_cursor
.x
;
25162 cx1
= cx0
+ w
->phys_cursor_width
;
25163 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25166 /* The cursor image will be completely removed from the
25167 screen if the output area intersects the cursor area in
25168 y-direction. When we draw in [y0 y1[, and some part of
25169 the cursor is at y < y0, that part must have been drawn
25170 before. When scrolling, the cursor is erased before
25171 actually scrolling, so we don't come here. When not
25172 scrolling, the rows above the old cursor row must have
25173 changed, and in this case these rows must have written
25174 over the cursor image.
25176 Likewise if part of the cursor is below y1, with the
25177 exception of the cursor being in the first blank row at
25178 the buffer and window end because update_text_area
25179 doesn't draw that row. (Except when it does, but
25180 that's handled in update_text_area.) */
25182 cy0
= w
->phys_cursor
.y
;
25183 cy1
= cy0
+ w
->phys_cursor_height
;
25184 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25187 w
->phys_cursor_on_p
= 0;
25190 #endif /* HAVE_WINDOW_SYSTEM */
25193 /************************************************************************
25195 ************************************************************************/
25197 #ifdef HAVE_WINDOW_SYSTEM
25200 Fix the display of area AREA of overlapping row ROW in window W
25201 with respect to the overlapping part OVERLAPS. */
25204 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25205 enum glyph_row_area area
, int overlaps
)
25212 for (i
= 0; i
< row
->used
[area
];)
25214 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25216 int start
= i
, start_x
= x
;
25220 x
+= row
->glyphs
[area
][i
].pixel_width
;
25223 while (i
< row
->used
[area
]
25224 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25226 draw_glyphs (w
, start_x
, row
, area
,
25228 DRAW_NORMAL_TEXT
, overlaps
);
25232 x
+= row
->glyphs
[area
][i
].pixel_width
;
25242 Draw the cursor glyph of window W in glyph row ROW. See the
25243 comment of draw_glyphs for the meaning of HL. */
25246 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25247 enum draw_glyphs_face hl
)
25249 /* If cursor hpos is out of bounds, don't draw garbage. This can
25250 happen in mini-buffer windows when switching between echo area
25251 glyphs and mini-buffer. */
25252 if ((row
->reversed_p
25253 ? (w
->phys_cursor
.hpos
>= 0)
25254 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25256 int on_p
= w
->phys_cursor_on_p
;
25258 int hpos
= w
->phys_cursor
.hpos
;
25260 /* When the window is hscrolled, cursor hpos can legitimately be
25261 out of bounds, but we draw the cursor at the corresponding
25262 window margin in that case. */
25263 if (!row
->reversed_p
&& hpos
< 0)
25265 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25266 hpos
= row
->used
[TEXT_AREA
] - 1;
25268 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25270 w
->phys_cursor_on_p
= on_p
;
25272 if (hl
== DRAW_CURSOR
)
25273 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25274 /* When we erase the cursor, and ROW is overlapped by other
25275 rows, make sure that these overlapping parts of other rows
25277 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25279 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25281 if (row
> w
->current_matrix
->rows
25282 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25283 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25284 OVERLAPS_ERASED_CURSOR
);
25286 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25287 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25288 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25289 OVERLAPS_ERASED_CURSOR
);
25296 Erase the image of a cursor of window W from the screen. */
25299 erase_phys_cursor (struct window
*w
)
25301 struct frame
*f
= XFRAME (w
->frame
);
25302 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25303 int hpos
= w
->phys_cursor
.hpos
;
25304 int vpos
= w
->phys_cursor
.vpos
;
25305 int mouse_face_here_p
= 0;
25306 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25307 struct glyph_row
*cursor_row
;
25308 struct glyph
*cursor_glyph
;
25309 enum draw_glyphs_face hl
;
25311 /* No cursor displayed or row invalidated => nothing to do on the
25313 if (w
->phys_cursor_type
== NO_CURSOR
)
25314 goto mark_cursor_off
;
25316 /* VPOS >= active_glyphs->nrows means that window has been resized.
25317 Don't bother to erase the cursor. */
25318 if (vpos
>= active_glyphs
->nrows
)
25319 goto mark_cursor_off
;
25321 /* If row containing cursor is marked invalid, there is nothing we
25323 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25324 if (!cursor_row
->enabled_p
)
25325 goto mark_cursor_off
;
25327 /* If line spacing is > 0, old cursor may only be partially visible in
25328 window after split-window. So adjust visible height. */
25329 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25330 window_text_bottom_y (w
) - cursor_row
->y
);
25332 /* If row is completely invisible, don't attempt to delete a cursor which
25333 isn't there. This can happen if cursor is at top of a window, and
25334 we switch to a buffer with a header line in that window. */
25335 if (cursor_row
->visible_height
<= 0)
25336 goto mark_cursor_off
;
25338 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25339 if (cursor_row
->cursor_in_fringe_p
)
25341 cursor_row
->cursor_in_fringe_p
= 0;
25342 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25343 goto mark_cursor_off
;
25346 /* This can happen when the new row is shorter than the old one.
25347 In this case, either draw_glyphs or clear_end_of_line
25348 should have cleared the cursor. Note that we wouldn't be
25349 able to erase the cursor in this case because we don't have a
25350 cursor glyph at hand. */
25351 if ((cursor_row
->reversed_p
25352 ? (w
->phys_cursor
.hpos
< 0)
25353 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25354 goto mark_cursor_off
;
25356 /* When the window is hscrolled, cursor hpos can legitimately be out
25357 of bounds, but we draw the cursor at the corresponding window
25358 margin in that case. */
25359 if (!cursor_row
->reversed_p
&& hpos
< 0)
25361 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25362 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25364 /* If the cursor is in the mouse face area, redisplay that when
25365 we clear the cursor. */
25366 if (! NILP (hlinfo
->mouse_face_window
)
25367 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25368 /* Don't redraw the cursor's spot in mouse face if it is at the
25369 end of a line (on a newline). The cursor appears there, but
25370 mouse highlighting does not. */
25371 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25372 mouse_face_here_p
= 1;
25374 /* Maybe clear the display under the cursor. */
25375 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25378 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25381 cursor_glyph
= get_phys_cursor_glyph (w
);
25382 if (cursor_glyph
== NULL
)
25383 goto mark_cursor_off
;
25385 width
= cursor_glyph
->pixel_width
;
25386 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25387 x
= w
->phys_cursor
.x
;
25389 width
-= left_x
- x
;
25390 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25391 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25392 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25395 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25398 /* Erase the cursor by redrawing the character underneath it. */
25399 if (mouse_face_here_p
)
25400 hl
= DRAW_MOUSE_FACE
;
25402 hl
= DRAW_NORMAL_TEXT
;
25403 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25406 w
->phys_cursor_on_p
= 0;
25407 w
->phys_cursor_type
= NO_CURSOR
;
25412 Display or clear cursor of window W. If ON is zero, clear the
25413 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25414 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25417 display_and_set_cursor (struct window
*w
, int on
,
25418 int hpos
, int vpos
, int x
, int y
)
25420 struct frame
*f
= XFRAME (w
->frame
);
25421 int new_cursor_type
;
25422 int new_cursor_width
;
25424 struct glyph_row
*glyph_row
;
25425 struct glyph
*glyph
;
25427 /* This is pointless on invisible frames, and dangerous on garbaged
25428 windows and frames; in the latter case, the frame or window may
25429 be in the midst of changing its size, and x and y may be off the
25431 if (! FRAME_VISIBLE_P (f
)
25432 || FRAME_GARBAGED_P (f
)
25433 || vpos
>= w
->current_matrix
->nrows
25434 || hpos
>= w
->current_matrix
->matrix_w
)
25437 /* If cursor is off and we want it off, return quickly. */
25438 if (!on
&& !w
->phys_cursor_on_p
)
25441 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25442 /* If cursor row is not enabled, we don't really know where to
25443 display the cursor. */
25444 if (!glyph_row
->enabled_p
)
25446 w
->phys_cursor_on_p
= 0;
25451 if (!glyph_row
->exact_window_width_line_p
25452 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25453 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25455 xassert (interrupt_input_blocked
);
25457 /* Set new_cursor_type to the cursor we want to be displayed. */
25458 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25459 &new_cursor_width
, &active_cursor
);
25461 /* If cursor is currently being shown and we don't want it to be or
25462 it is in the wrong place, or the cursor type is not what we want,
25464 if (w
->phys_cursor_on_p
25466 || w
->phys_cursor
.x
!= x
25467 || w
->phys_cursor
.y
!= y
25468 || new_cursor_type
!= w
->phys_cursor_type
25469 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25470 && new_cursor_width
!= w
->phys_cursor_width
)))
25471 erase_phys_cursor (w
);
25473 /* Don't check phys_cursor_on_p here because that flag is only set
25474 to zero in some cases where we know that the cursor has been
25475 completely erased, to avoid the extra work of erasing the cursor
25476 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25477 still not be visible, or it has only been partly erased. */
25480 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25481 w
->phys_cursor_height
= glyph_row
->height
;
25483 /* Set phys_cursor_.* before x_draw_.* is called because some
25484 of them may need the information. */
25485 w
->phys_cursor
.x
= x
;
25486 w
->phys_cursor
.y
= glyph_row
->y
;
25487 w
->phys_cursor
.hpos
= hpos
;
25488 w
->phys_cursor
.vpos
= vpos
;
25491 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25492 new_cursor_type
, new_cursor_width
,
25493 on
, active_cursor
);
25497 /* Switch the display of W's cursor on or off, according to the value
25501 update_window_cursor (struct window
*w
, int on
)
25503 /* Don't update cursor in windows whose frame is in the process
25504 of being deleted. */
25505 if (w
->current_matrix
)
25507 int hpos
= w
->phys_cursor
.hpos
;
25508 int vpos
= w
->phys_cursor
.vpos
;
25509 struct glyph_row
*row
;
25511 if (vpos
>= w
->current_matrix
->nrows
25512 || hpos
>= w
->current_matrix
->matrix_w
)
25515 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25517 /* When the window is hscrolled, cursor hpos can legitimately be
25518 out of bounds, but we draw the cursor at the corresponding
25519 window margin in that case. */
25520 if (!row
->reversed_p
&& hpos
< 0)
25522 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25523 hpos
= row
->used
[TEXT_AREA
] - 1;
25526 display_and_set_cursor (w
, on
, hpos
, vpos
,
25527 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25533 /* Call update_window_cursor with parameter ON_P on all leaf windows
25534 in the window tree rooted at W. */
25537 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25541 if (!NILP (w
->hchild
))
25542 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25543 else if (!NILP (w
->vchild
))
25544 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25546 update_window_cursor (w
, on_p
);
25548 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25554 Display the cursor on window W, or clear it, according to ON_P.
25555 Don't change the cursor's position. */
25558 x_update_cursor (struct frame
*f
, int on_p
)
25560 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25565 Clear the cursor of window W to background color, and mark the
25566 cursor as not shown. This is used when the text where the cursor
25567 is about to be rewritten. */
25570 x_clear_cursor (struct window
*w
)
25572 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25573 update_window_cursor (w
, 0);
25576 #endif /* HAVE_WINDOW_SYSTEM */
25578 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25581 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25582 int start_hpos
, int end_hpos
,
25583 enum draw_glyphs_face draw
)
25585 #ifdef HAVE_WINDOW_SYSTEM
25586 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25588 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25592 #if defined (HAVE_GPM) || defined (MSDOS)
25593 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25597 /* Display the active region described by mouse_face_* according to DRAW. */
25600 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25602 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25603 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25605 if (/* If window is in the process of being destroyed, don't bother
25607 w
->current_matrix
!= NULL
25608 /* Don't update mouse highlight if hidden */
25609 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25610 /* Recognize when we are called to operate on rows that don't exist
25611 anymore. This can happen when a window is split. */
25612 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25614 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25615 struct glyph_row
*row
, *first
, *last
;
25617 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25618 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25620 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25622 int start_hpos
, end_hpos
, start_x
;
25624 /* For all but the first row, the highlight starts at column 0. */
25627 /* R2L rows have BEG and END in reversed order, but the
25628 screen drawing geometry is always left to right. So
25629 we need to mirror the beginning and end of the
25630 highlighted area in R2L rows. */
25631 if (!row
->reversed_p
)
25633 start_hpos
= hlinfo
->mouse_face_beg_col
;
25634 start_x
= hlinfo
->mouse_face_beg_x
;
25636 else if (row
== last
)
25638 start_hpos
= hlinfo
->mouse_face_end_col
;
25639 start_x
= hlinfo
->mouse_face_end_x
;
25647 else if (row
->reversed_p
&& row
== last
)
25649 start_hpos
= hlinfo
->mouse_face_end_col
;
25650 start_x
= hlinfo
->mouse_face_end_x
;
25660 if (!row
->reversed_p
)
25661 end_hpos
= hlinfo
->mouse_face_end_col
;
25662 else if (row
== first
)
25663 end_hpos
= hlinfo
->mouse_face_beg_col
;
25666 end_hpos
= row
->used
[TEXT_AREA
];
25667 if (draw
== DRAW_NORMAL_TEXT
)
25668 row
->fill_line_p
= 1; /* Clear to end of line */
25671 else if (row
->reversed_p
&& row
== first
)
25672 end_hpos
= hlinfo
->mouse_face_beg_col
;
25675 end_hpos
= row
->used
[TEXT_AREA
];
25676 if (draw
== DRAW_NORMAL_TEXT
)
25677 row
->fill_line_p
= 1; /* Clear to end of line */
25680 if (end_hpos
> start_hpos
)
25682 draw_row_with_mouse_face (w
, start_x
, row
,
25683 start_hpos
, end_hpos
, draw
);
25686 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
25690 #ifdef HAVE_WINDOW_SYSTEM
25691 /* When we've written over the cursor, arrange for it to
25692 be displayed again. */
25693 if (FRAME_WINDOW_P (f
)
25694 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
25696 int hpos
= w
->phys_cursor
.hpos
;
25698 /* When the window is hscrolled, cursor hpos can legitimately be
25699 out of bounds, but we draw the cursor at the corresponding
25700 window margin in that case. */
25701 if (!row
->reversed_p
&& hpos
< 0)
25703 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25704 hpos
= row
->used
[TEXT_AREA
] - 1;
25707 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
25708 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25711 #endif /* HAVE_WINDOW_SYSTEM */
25714 #ifdef HAVE_WINDOW_SYSTEM
25715 /* Change the mouse cursor. */
25716 if (FRAME_WINDOW_P (f
))
25718 if (draw
== DRAW_NORMAL_TEXT
25719 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
25720 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
25721 else if (draw
== DRAW_MOUSE_FACE
)
25722 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
25724 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
25726 #endif /* HAVE_WINDOW_SYSTEM */
25730 Clear out the mouse-highlighted active region.
25731 Redraw it un-highlighted first. Value is non-zero if mouse
25732 face was actually drawn unhighlighted. */
25735 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
25739 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
25741 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
25745 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25746 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25747 hlinfo
->mouse_face_window
= Qnil
;
25748 hlinfo
->mouse_face_overlay
= Qnil
;
25752 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
25753 within the mouse face on that window. */
25755 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
25757 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25759 /* Quickly resolve the easy cases. */
25760 if (!(WINDOWP (hlinfo
->mouse_face_window
)
25761 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
25763 if (vpos
< hlinfo
->mouse_face_beg_row
25764 || vpos
> hlinfo
->mouse_face_end_row
)
25766 if (vpos
> hlinfo
->mouse_face_beg_row
25767 && vpos
< hlinfo
->mouse_face_end_row
)
25770 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
25772 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25774 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
25777 else if ((vpos
== hlinfo
->mouse_face_beg_row
25778 && hpos
>= hlinfo
->mouse_face_beg_col
)
25779 || (vpos
== hlinfo
->mouse_face_end_row
25780 && hpos
< hlinfo
->mouse_face_end_col
))
25785 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25787 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
25790 else if ((vpos
== hlinfo
->mouse_face_beg_row
25791 && hpos
<= hlinfo
->mouse_face_beg_col
)
25792 || (vpos
== hlinfo
->mouse_face_end_row
25793 && hpos
> hlinfo
->mouse_face_end_col
))
25801 Non-zero if physical cursor of window W is within mouse face. */
25804 cursor_in_mouse_face_p (struct window
*w
)
25806 int hpos
= w
->phys_cursor
.hpos
;
25807 int vpos
= w
->phys_cursor
.vpos
;
25808 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25810 /* When the window is hscrolled, cursor hpos can legitimately be out
25811 of bounds, but we draw the cursor at the corresponding window
25812 margin in that case. */
25813 if (!row
->reversed_p
&& hpos
< 0)
25815 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25816 hpos
= row
->used
[TEXT_AREA
] - 1;
25818 return coords_in_mouse_face_p (w
, hpos
, vpos
);
25823 /* Find the glyph rows START_ROW and END_ROW of window W that display
25824 characters between buffer positions START_CHARPOS and END_CHARPOS
25825 (excluding END_CHARPOS). DISP_STRING is a display string that
25826 covers these buffer positions. This is similar to
25827 row_containing_pos, but is more accurate when bidi reordering makes
25828 buffer positions change non-linearly with glyph rows. */
25830 rows_from_pos_range (struct window
*w
,
25831 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
25832 Lisp_Object disp_string
,
25833 struct glyph_row
**start
, struct glyph_row
**end
)
25835 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25836 int last_y
= window_text_bottom_y (w
);
25837 struct glyph_row
*row
;
25842 while (!first
->enabled_p
25843 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
25846 /* Find the START row. */
25848 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
25851 /* A row can potentially be the START row if the range of the
25852 characters it displays intersects the range
25853 [START_CHARPOS..END_CHARPOS). */
25854 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
25855 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
25856 /* See the commentary in row_containing_pos, for the
25857 explanation of the complicated way to check whether
25858 some position is beyond the end of the characters
25859 displayed by a row. */
25860 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25861 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25862 && !row
->ends_at_zv_p
25863 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
25864 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25865 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25866 && !row
->ends_at_zv_p
25867 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
25869 /* Found a candidate row. Now make sure at least one of the
25870 glyphs it displays has a charpos from the range
25871 [START_CHARPOS..END_CHARPOS).
25873 This is not obvious because bidi reordering could make
25874 buffer positions of a row be 1,2,3,102,101,100, and if we
25875 want to highlight characters in [50..60), we don't want
25876 this row, even though [50..60) does intersect [1..103),
25877 the range of character positions given by the row's start
25878 and end positions. */
25879 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
25880 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
25884 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
25885 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
25886 /* A glyph that comes from DISP_STRING is by
25887 definition to be highlighted. */
25888 || EQ (g
->object
, disp_string
))
25897 /* Find the END row. */
25899 /* If the last row is partially visible, start looking for END
25900 from that row, instead of starting from FIRST. */
25901 && !(row
->enabled_p
25902 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
25904 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
25906 struct glyph_row
*next
= row
+ 1;
25907 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
25909 if (!next
->enabled_p
25910 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
25911 /* The first row >= START whose range of displayed characters
25912 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
25913 is the row END + 1. */
25914 || (start_charpos
< next_start
25915 && end_charpos
< next_start
)
25916 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
25917 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
25918 && !next
->ends_at_zv_p
25919 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
25920 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
25921 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
25922 && !next
->ends_at_zv_p
25923 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
25930 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
25931 but none of the characters it displays are in the range, it is
25933 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
25934 struct glyph
*s
= g
;
25935 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
25939 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
25940 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
25941 /* If the buffer position of the first glyph in
25942 the row is equal to END_CHARPOS, it means
25943 the last character to be highlighted is the
25944 newline of ROW, and we must consider NEXT as
25946 || (((!next
->reversed_p
&& g
== s
)
25947 || (next
->reversed_p
&& g
== e
- 1))
25948 && (g
->charpos
== end_charpos
25949 /* Special case for when NEXT is an
25950 empty line at ZV. */
25951 || (g
->charpos
== -1
25952 && !row
->ends_at_zv_p
25953 && next_start
== end_charpos
)))))
25954 /* A glyph that comes from DISP_STRING is by
25955 definition to be highlighted. */
25956 || EQ (g
->object
, disp_string
))
25965 /* The first row that ends at ZV must be the last to be
25967 else if (next
->ends_at_zv_p
)
25976 /* This function sets the mouse_face_* elements of HLINFO, assuming
25977 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
25978 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
25979 for the overlay or run of text properties specifying the mouse
25980 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
25981 before-string and after-string that must also be highlighted.
25982 DISP_STRING, if non-nil, is a display string that may cover some
25983 or all of the highlighted text. */
25986 mouse_face_from_buffer_pos (Lisp_Object window
,
25987 Mouse_HLInfo
*hlinfo
,
25988 ptrdiff_t mouse_charpos
,
25989 ptrdiff_t start_charpos
,
25990 ptrdiff_t end_charpos
,
25991 Lisp_Object before_string
,
25992 Lisp_Object after_string
,
25993 Lisp_Object disp_string
)
25995 struct window
*w
= XWINDOW (window
);
25996 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25997 struct glyph_row
*r1
, *r2
;
25998 struct glyph
*glyph
, *end
;
25999 ptrdiff_t ignore
, pos
;
26002 xassert (NILP (disp_string
) || STRINGP (disp_string
));
26003 xassert (NILP (before_string
) || STRINGP (before_string
));
26004 xassert (NILP (after_string
) || STRINGP (after_string
));
26006 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26007 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26009 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26010 /* If the before-string or display-string contains newlines,
26011 rows_from_pos_range skips to its last row. Move back. */
26012 if (!NILP (before_string
) || !NILP (disp_string
))
26014 struct glyph_row
*prev
;
26015 while ((prev
= r1
- 1, prev
>= first
)
26016 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26017 && prev
->used
[TEXT_AREA
] > 0)
26019 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26020 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26021 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26023 || !(EQ (glyph
->object
, before_string
)
26024 || EQ (glyph
->object
, disp_string
)))
26031 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26032 hlinfo
->mouse_face_past_end
= 1;
26034 else if (!NILP (after_string
))
26036 /* If the after-string has newlines, advance to its last row. */
26037 struct glyph_row
*next
;
26038 struct glyph_row
*last
26039 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26041 for (next
= r2
+ 1;
26043 && next
->used
[TEXT_AREA
] > 0
26044 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26048 /* The rest of the display engine assumes that mouse_face_beg_row is
26049 either above mouse_face_end_row or identical to it. But with
26050 bidi-reordered continued lines, the row for START_CHARPOS could
26051 be below the row for END_CHARPOS. If so, swap the rows and store
26052 them in correct order. */
26055 struct glyph_row
*tem
= r2
;
26061 hlinfo
->mouse_face_beg_y
= r1
->y
;
26062 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26063 hlinfo
->mouse_face_end_y
= r2
->y
;
26064 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26066 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26067 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26068 could be anywhere in the row and in any order. The strategy
26069 below is to find the leftmost and the rightmost glyph that
26070 belongs to either of these 3 strings, or whose position is
26071 between START_CHARPOS and END_CHARPOS, and highlight all the
26072 glyphs between those two. This may cover more than just the text
26073 between START_CHARPOS and END_CHARPOS if the range of characters
26074 strides the bidi level boundary, e.g. if the beginning is in R2L
26075 text while the end is in L2R text or vice versa. */
26076 if (!r1
->reversed_p
)
26078 /* This row is in a left to right paragraph. Scan it left to
26080 glyph
= r1
->glyphs
[TEXT_AREA
];
26081 end
= glyph
+ r1
->used
[TEXT_AREA
];
26084 /* Skip truncation glyphs at the start of the glyph row. */
26085 if (r1
->displays_text_p
)
26087 && INTEGERP (glyph
->object
)
26088 && glyph
->charpos
< 0;
26090 x
+= glyph
->pixel_width
;
26092 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26093 or DISP_STRING, and the first glyph from buffer whose
26094 position is between START_CHARPOS and END_CHARPOS. */
26096 && !INTEGERP (glyph
->object
)
26097 && !EQ (glyph
->object
, disp_string
)
26098 && !(BUFFERP (glyph
->object
)
26099 && (glyph
->charpos
>= start_charpos
26100 && glyph
->charpos
< end_charpos
));
26103 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26104 are present at buffer positions between START_CHARPOS and
26105 END_CHARPOS, or if they come from an overlay. */
26106 if (EQ (glyph
->object
, before_string
))
26108 pos
= string_buffer_position (before_string
,
26110 /* If pos == 0, it means before_string came from an
26111 overlay, not from a buffer position. */
26112 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26115 else if (EQ (glyph
->object
, after_string
))
26117 pos
= string_buffer_position (after_string
, end_charpos
);
26118 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26121 x
+= glyph
->pixel_width
;
26123 hlinfo
->mouse_face_beg_x
= x
;
26124 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26128 /* This row is in a right to left paragraph. Scan it right to
26132 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26133 glyph
= end
+ r1
->used
[TEXT_AREA
];
26135 /* Skip truncation glyphs at the start of the glyph row. */
26136 if (r1
->displays_text_p
)
26138 && INTEGERP (glyph
->object
)
26139 && glyph
->charpos
< 0;
26143 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26144 or DISP_STRING, and the first glyph from buffer whose
26145 position is between START_CHARPOS and END_CHARPOS. */
26147 && !INTEGERP (glyph
->object
)
26148 && !EQ (glyph
->object
, disp_string
)
26149 && !(BUFFERP (glyph
->object
)
26150 && (glyph
->charpos
>= start_charpos
26151 && glyph
->charpos
< end_charpos
));
26154 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26155 are present at buffer positions between START_CHARPOS and
26156 END_CHARPOS, or if they come from an overlay. */
26157 if (EQ (glyph
->object
, before_string
))
26159 pos
= string_buffer_position (before_string
, start_charpos
);
26160 /* If pos == 0, it means before_string came from an
26161 overlay, not from a buffer position. */
26162 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26165 else if (EQ (glyph
->object
, after_string
))
26167 pos
= string_buffer_position (after_string
, end_charpos
);
26168 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26173 glyph
++; /* first glyph to the right of the highlighted area */
26174 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26175 x
+= g
->pixel_width
;
26176 hlinfo
->mouse_face_beg_x
= x
;
26177 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26180 /* If the highlight ends in a different row, compute GLYPH and END
26181 for the end row. Otherwise, reuse the values computed above for
26182 the row where the highlight begins. */
26185 if (!r2
->reversed_p
)
26187 glyph
= r2
->glyphs
[TEXT_AREA
];
26188 end
= glyph
+ r2
->used
[TEXT_AREA
];
26193 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26194 glyph
= end
+ r2
->used
[TEXT_AREA
];
26198 if (!r2
->reversed_p
)
26200 /* Skip truncation and continuation glyphs near the end of the
26201 row, and also blanks and stretch glyphs inserted by
26202 extend_face_to_end_of_line. */
26204 && INTEGERP ((end
- 1)->object
))
26206 /* Scan the rest of the glyph row from the end, looking for the
26207 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26208 DISP_STRING, or whose position is between START_CHARPOS
26212 && !INTEGERP (end
->object
)
26213 && !EQ (end
->object
, disp_string
)
26214 && !(BUFFERP (end
->object
)
26215 && (end
->charpos
>= start_charpos
26216 && end
->charpos
< end_charpos
));
26219 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26220 are present at buffer positions between START_CHARPOS and
26221 END_CHARPOS, or if they come from an overlay. */
26222 if (EQ (end
->object
, before_string
))
26224 pos
= string_buffer_position (before_string
, start_charpos
);
26225 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26228 else if (EQ (end
->object
, after_string
))
26230 pos
= string_buffer_position (after_string
, end_charpos
);
26231 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26235 /* Find the X coordinate of the last glyph to be highlighted. */
26236 for (; glyph
<= end
; ++glyph
)
26237 x
+= glyph
->pixel_width
;
26239 hlinfo
->mouse_face_end_x
= x
;
26240 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26244 /* Skip truncation and continuation glyphs near the end of the
26245 row, and also blanks and stretch glyphs inserted by
26246 extend_face_to_end_of_line. */
26250 && INTEGERP (end
->object
))
26252 x
+= end
->pixel_width
;
26255 /* Scan the rest of the glyph row from the end, looking for the
26256 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26257 DISP_STRING, or whose position is between START_CHARPOS
26261 && !INTEGERP (end
->object
)
26262 && !EQ (end
->object
, disp_string
)
26263 && !(BUFFERP (end
->object
)
26264 && (end
->charpos
>= start_charpos
26265 && end
->charpos
< end_charpos
));
26268 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26269 are present at buffer positions between START_CHARPOS and
26270 END_CHARPOS, or if they come from an overlay. */
26271 if (EQ (end
->object
, before_string
))
26273 pos
= string_buffer_position (before_string
, start_charpos
);
26274 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26277 else if (EQ (end
->object
, after_string
))
26279 pos
= string_buffer_position (after_string
, end_charpos
);
26280 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26283 x
+= end
->pixel_width
;
26285 /* If we exited the above loop because we arrived at the last
26286 glyph of the row, and its buffer position is still not in
26287 range, it means the last character in range is the preceding
26288 newline. Bump the end column and x values to get past the
26291 && BUFFERP (end
->object
)
26292 && (end
->charpos
< start_charpos
26293 || end
->charpos
>= end_charpos
))
26295 x
+= end
->pixel_width
;
26298 hlinfo
->mouse_face_end_x
= x
;
26299 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26302 hlinfo
->mouse_face_window
= window
;
26303 hlinfo
->mouse_face_face_id
26304 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26306 !hlinfo
->mouse_face_hidden
, -1);
26307 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26310 /* The following function is not used anymore (replaced with
26311 mouse_face_from_string_pos), but I leave it here for the time
26312 being, in case someone would. */
26314 #if 0 /* not used */
26316 /* Find the position of the glyph for position POS in OBJECT in
26317 window W's current matrix, and return in *X, *Y the pixel
26318 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26320 RIGHT_P non-zero means return the position of the right edge of the
26321 glyph, RIGHT_P zero means return the left edge position.
26323 If no glyph for POS exists in the matrix, return the position of
26324 the glyph with the next smaller position that is in the matrix, if
26325 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26326 exists in the matrix, return the position of the glyph with the
26327 next larger position in OBJECT.
26329 Value is non-zero if a glyph was found. */
26332 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26333 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26335 int yb
= window_text_bottom_y (w
);
26336 struct glyph_row
*r
;
26337 struct glyph
*best_glyph
= NULL
;
26338 struct glyph_row
*best_row
= NULL
;
26341 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26342 r
->enabled_p
&& r
->y
< yb
;
26345 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26346 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26349 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26350 if (EQ (g
->object
, object
))
26352 if (g
->charpos
== pos
)
26359 else if (best_glyph
== NULL
26360 || ((eabs (g
->charpos
- pos
)
26361 < eabs (best_glyph
->charpos
- pos
))
26364 : g
->charpos
> pos
)))
26378 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26382 *x
+= best_glyph
->pixel_width
;
26387 *vpos
= best_row
- w
->current_matrix
->rows
;
26390 return best_glyph
!= NULL
;
26392 #endif /* not used */
26394 /* Find the positions of the first and the last glyphs in window W's
26395 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26396 (assumed to be a string), and return in HLINFO's mouse_face_*
26397 members the pixel and column/row coordinates of those glyphs. */
26400 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26401 Lisp_Object object
,
26402 ptrdiff_t startpos
, ptrdiff_t endpos
)
26404 int yb
= window_text_bottom_y (w
);
26405 struct glyph_row
*r
;
26406 struct glyph
*g
, *e
;
26410 /* Find the glyph row with at least one position in the range
26411 [STARTPOS..ENDPOS], and the first glyph in that row whose
26412 position belongs to that range. */
26413 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26414 r
->enabled_p
&& r
->y
< yb
;
26417 if (!r
->reversed_p
)
26419 g
= r
->glyphs
[TEXT_AREA
];
26420 e
= g
+ r
->used
[TEXT_AREA
];
26421 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26422 if (EQ (g
->object
, object
)
26423 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26425 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26426 hlinfo
->mouse_face_beg_y
= r
->y
;
26427 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26428 hlinfo
->mouse_face_beg_x
= gx
;
26437 e
= r
->glyphs
[TEXT_AREA
];
26438 g
= e
+ r
->used
[TEXT_AREA
];
26439 for ( ; g
> e
; --g
)
26440 if (EQ ((g
-1)->object
, object
)
26441 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26443 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26444 hlinfo
->mouse_face_beg_y
= r
->y
;
26445 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26446 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26447 gx
+= g1
->pixel_width
;
26448 hlinfo
->mouse_face_beg_x
= gx
;
26460 /* Starting with the next row, look for the first row which does NOT
26461 include any glyphs whose positions are in the range. */
26462 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26464 g
= r
->glyphs
[TEXT_AREA
];
26465 e
= g
+ r
->used
[TEXT_AREA
];
26467 for ( ; g
< e
; ++g
)
26468 if (EQ (g
->object
, object
)
26469 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26478 /* The highlighted region ends on the previous row. */
26481 /* Set the end row and its vertical pixel coordinate. */
26482 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26483 hlinfo
->mouse_face_end_y
= r
->y
;
26485 /* Compute and set the end column and the end column's horizontal
26486 pixel coordinate. */
26487 if (!r
->reversed_p
)
26489 g
= r
->glyphs
[TEXT_AREA
];
26490 e
= g
+ r
->used
[TEXT_AREA
];
26491 for ( ; e
> g
; --e
)
26492 if (EQ ((e
-1)->object
, object
)
26493 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26495 hlinfo
->mouse_face_end_col
= e
- g
;
26497 for (gx
= r
->x
; g
< e
; ++g
)
26498 gx
+= g
->pixel_width
;
26499 hlinfo
->mouse_face_end_x
= gx
;
26503 e
= r
->glyphs
[TEXT_AREA
];
26504 g
= e
+ r
->used
[TEXT_AREA
];
26505 for (gx
= r
->x
; e
< g
; ++e
)
26507 if (EQ (e
->object
, object
)
26508 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26510 gx
+= e
->pixel_width
;
26512 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26513 hlinfo
->mouse_face_end_x
= gx
;
26517 #ifdef HAVE_WINDOW_SYSTEM
26519 /* See if position X, Y is within a hot-spot of an image. */
26522 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26524 if (!CONSP (hot_spot
))
26527 if (EQ (XCAR (hot_spot
), Qrect
))
26529 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26530 Lisp_Object rect
= XCDR (hot_spot
);
26534 if (!CONSP (XCAR (rect
)))
26536 if (!CONSP (XCDR (rect
)))
26538 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26540 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26542 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26544 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26548 else if (EQ (XCAR (hot_spot
), Qcircle
))
26550 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26551 Lisp_Object circ
= XCDR (hot_spot
);
26552 Lisp_Object lr
, lx0
, ly0
;
26554 && CONSP (XCAR (circ
))
26555 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26556 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26557 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26559 double r
= XFLOATINT (lr
);
26560 double dx
= XINT (lx0
) - x
;
26561 double dy
= XINT (ly0
) - y
;
26562 return (dx
* dx
+ dy
* dy
<= r
* r
);
26565 else if (EQ (XCAR (hot_spot
), Qpoly
))
26567 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26568 if (VECTORP (XCDR (hot_spot
)))
26570 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26571 Lisp_Object
*poly
= v
->contents
;
26572 ptrdiff_t n
= v
->header
.size
;
26575 Lisp_Object lx
, ly
;
26578 /* Need an even number of coordinates, and at least 3 edges. */
26579 if (n
< 6 || n
& 1)
26582 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26583 If count is odd, we are inside polygon. Pixels on edges
26584 may or may not be included depending on actual geometry of the
26586 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26587 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26589 x0
= XINT (lx
), y0
= XINT (ly
);
26590 for (i
= 0; i
< n
; i
+= 2)
26592 int x1
= x0
, y1
= y0
;
26593 if ((lx
= poly
[i
], !INTEGERP (lx
))
26594 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26596 x0
= XINT (lx
), y0
= XINT (ly
);
26598 /* Does this segment cross the X line? */
26606 if (y
> y0
&& y
> y1
)
26608 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26618 find_hot_spot (Lisp_Object map
, int x
, int y
)
26620 while (CONSP (map
))
26622 if (CONSP (XCAR (map
))
26623 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26631 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26633 doc
: /* Lookup in image map MAP coordinates X and Y.
26634 An image map is an alist where each element has the format (AREA ID PLIST).
26635 An AREA is specified as either a rectangle, a circle, or a polygon:
26636 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26637 pixel coordinates of the upper left and bottom right corners.
26638 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26639 and the radius of the circle; r may be a float or integer.
26640 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26641 vector describes one corner in the polygon.
26642 Returns the alist element for the first matching AREA in MAP. */)
26643 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26651 return find_hot_spot (map
,
26652 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
26653 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
26657 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26659 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26661 /* Do not change cursor shape while dragging mouse. */
26662 if (!NILP (do_mouse_tracking
))
26665 if (!NILP (pointer
))
26667 if (EQ (pointer
, Qarrow
))
26668 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26669 else if (EQ (pointer
, Qhand
))
26670 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
26671 else if (EQ (pointer
, Qtext
))
26672 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26673 else if (EQ (pointer
, intern ("hdrag")))
26674 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26675 #ifdef HAVE_X_WINDOWS
26676 else if (EQ (pointer
, intern ("vdrag")))
26677 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
26679 else if (EQ (pointer
, intern ("hourglass")))
26680 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
26681 else if (EQ (pointer
, Qmodeline
))
26682 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
26684 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26687 if (cursor
!= No_Cursor
)
26688 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
26691 #endif /* HAVE_WINDOW_SYSTEM */
26693 /* Take proper action when mouse has moved to the mode or header line
26694 or marginal area AREA of window W, x-position X and y-position Y.
26695 X is relative to the start of the text display area of W, so the
26696 width of bitmap areas and scroll bars must be subtracted to get a
26697 position relative to the start of the mode line. */
26700 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
26701 enum window_part area
)
26703 struct window
*w
= XWINDOW (window
);
26704 struct frame
*f
= XFRAME (w
->frame
);
26705 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26706 #ifdef HAVE_WINDOW_SYSTEM
26707 Display_Info
*dpyinfo
;
26709 Cursor cursor
= No_Cursor
;
26710 Lisp_Object pointer
= Qnil
;
26711 int dx
, dy
, width
, height
;
26713 Lisp_Object string
, object
= Qnil
;
26714 Lisp_Object pos
, help
;
26716 Lisp_Object mouse_face
;
26717 int original_x_pixel
= x
;
26718 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
26719 struct glyph_row
*row
;
26721 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
26726 /* Kludge alert: mode_line_string takes X/Y in pixels, but
26727 returns them in row/column units! */
26728 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
26729 &object
, &dx
, &dy
, &width
, &height
);
26731 row
= (area
== ON_MODE_LINE
26732 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
26733 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
26735 /* Find the glyph under the mouse pointer. */
26736 if (row
->mode_line_p
&& row
->enabled_p
)
26738 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
26739 end
= glyph
+ row
->used
[TEXT_AREA
];
26741 for (x0
= original_x_pixel
;
26742 glyph
< end
&& x0
>= glyph
->pixel_width
;
26744 x0
-= glyph
->pixel_width
;
26752 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
26753 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
26754 returns them in row/column units! */
26755 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
26756 &object
, &dx
, &dy
, &width
, &height
);
26761 #ifdef HAVE_WINDOW_SYSTEM
26762 if (IMAGEP (object
))
26764 Lisp_Object image_map
, hotspot
;
26765 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
26767 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
26769 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26773 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
26774 If so, we could look for mouse-enter, mouse-leave
26775 properties in PLIST (and do something...). */
26776 hotspot
= XCDR (hotspot
);
26777 if (CONSP (hotspot
)
26778 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26780 pointer
= Fplist_get (plist
, Qpointer
);
26781 if (NILP (pointer
))
26783 help
= Fplist_get (plist
, Qhelp_echo
);
26786 help_echo_string
= help
;
26787 /* Is this correct? ++kfs */
26788 XSETWINDOW (help_echo_window
, w
);
26789 help_echo_object
= w
->buffer
;
26790 help_echo_pos
= charpos
;
26794 if (NILP (pointer
))
26795 pointer
= Fplist_get (XCDR (object
), QCpointer
);
26797 #endif /* HAVE_WINDOW_SYSTEM */
26799 if (STRINGP (string
))
26801 pos
= make_number (charpos
);
26802 /* If we're on a string with `help-echo' text property, arrange
26803 for the help to be displayed. This is done by setting the
26804 global variable help_echo_string to the help string. */
26807 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
26810 help_echo_string
= help
;
26811 XSETWINDOW (help_echo_window
, w
);
26812 help_echo_object
= string
;
26813 help_echo_pos
= charpos
;
26817 #ifdef HAVE_WINDOW_SYSTEM
26818 if (FRAME_WINDOW_P (f
))
26820 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
26821 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26822 if (NILP (pointer
))
26823 pointer
= Fget_text_property (pos
, Qpointer
, string
);
26825 /* Change the mouse pointer according to what is under X/Y. */
26827 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
26830 map
= Fget_text_property (pos
, Qlocal_map
, string
);
26831 if (!KEYMAPP (map
))
26832 map
= Fget_text_property (pos
, Qkeymap
, string
);
26833 if (!KEYMAPP (map
))
26834 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
26839 /* Change the mouse face according to what is under X/Y. */
26840 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
26841 if (!NILP (mouse_face
)
26842 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26847 struct glyph
* tmp_glyph
;
26851 int total_pixel_width
;
26852 ptrdiff_t begpos
, endpos
, ignore
;
26856 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
26857 Qmouse_face
, string
, Qnil
);
26863 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
26865 endpos
= SCHARS (string
);
26869 /* Calculate the glyph position GPOS of GLYPH in the
26870 displayed string, relative to the beginning of the
26871 highlighted part of the string.
26873 Note: GPOS is different from CHARPOS. CHARPOS is the
26874 position of GLYPH in the internal string object. A mode
26875 line string format has structures which are converted to
26876 a flattened string by the Emacs Lisp interpreter. The
26877 internal string is an element of those structures. The
26878 displayed string is the flattened string. */
26879 tmp_glyph
= row_start_glyph
;
26880 while (tmp_glyph
< glyph
26881 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
26882 && begpos
<= tmp_glyph
->charpos
26883 && tmp_glyph
->charpos
< endpos
)))
26885 gpos
= glyph
- tmp_glyph
;
26887 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
26888 the highlighted part of the displayed string to which
26889 GLYPH belongs. Note: GSEQ_LENGTH is different from
26890 SCHARS (STRING), because the latter returns the length of
26891 the internal string. */
26892 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
26894 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
26895 && begpos
<= tmp_glyph
->charpos
26896 && tmp_glyph
->charpos
< endpos
));
26899 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
26901 /* Calculate the total pixel width of all the glyphs between
26902 the beginning of the highlighted area and GLYPH. */
26903 total_pixel_width
= 0;
26904 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
26905 total_pixel_width
+= tmp_glyph
->pixel_width
;
26907 /* Pre calculation of re-rendering position. Note: X is in
26908 column units here, after the call to mode_line_string or
26909 marginal_area_string. */
26911 vpos
= (area
== ON_MODE_LINE
26912 ? (w
->current_matrix
)->nrows
- 1
26915 /* If GLYPH's position is included in the region that is
26916 already drawn in mouse face, we have nothing to do. */
26917 if ( EQ (window
, hlinfo
->mouse_face_window
)
26918 && (!row
->reversed_p
26919 ? (hlinfo
->mouse_face_beg_col
<= hpos
26920 && hpos
< hlinfo
->mouse_face_end_col
)
26921 /* In R2L rows we swap BEG and END, see below. */
26922 : (hlinfo
->mouse_face_end_col
<= hpos
26923 && hpos
< hlinfo
->mouse_face_beg_col
))
26924 && hlinfo
->mouse_face_beg_row
== vpos
)
26927 if (clear_mouse_face (hlinfo
))
26928 cursor
= No_Cursor
;
26930 if (!row
->reversed_p
)
26932 hlinfo
->mouse_face_beg_col
= hpos
;
26933 hlinfo
->mouse_face_beg_x
= original_x_pixel
26934 - (total_pixel_width
+ dx
);
26935 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
26936 hlinfo
->mouse_face_end_x
= 0;
26940 /* In R2L rows, show_mouse_face expects BEG and END
26941 coordinates to be swapped. */
26942 hlinfo
->mouse_face_end_col
= hpos
;
26943 hlinfo
->mouse_face_end_x
= original_x_pixel
26944 - (total_pixel_width
+ dx
);
26945 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
26946 hlinfo
->mouse_face_beg_x
= 0;
26949 hlinfo
->mouse_face_beg_row
= vpos
;
26950 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
26951 hlinfo
->mouse_face_beg_y
= 0;
26952 hlinfo
->mouse_face_end_y
= 0;
26953 hlinfo
->mouse_face_past_end
= 0;
26954 hlinfo
->mouse_face_window
= window
;
26956 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
26962 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26964 if (NILP (pointer
))
26967 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26968 clear_mouse_face (hlinfo
);
26970 #ifdef HAVE_WINDOW_SYSTEM
26971 if (FRAME_WINDOW_P (f
))
26972 define_frame_cursor1 (f
, cursor
, pointer
);
26978 Take proper action when the mouse has moved to position X, Y on
26979 frame F as regards highlighting characters that have mouse-face
26980 properties. Also de-highlighting chars where the mouse was before.
26981 X and Y can be negative or out of range. */
26984 note_mouse_highlight (struct frame
*f
, int x
, int y
)
26986 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26987 enum window_part part
= ON_NOTHING
;
26988 Lisp_Object window
;
26990 Cursor cursor
= No_Cursor
;
26991 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
26994 /* When a menu is active, don't highlight because this looks odd. */
26995 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
26996 if (popup_activated ())
27000 if (NILP (Vmouse_highlight
)
27001 || !f
->glyphs_initialized_p
27002 || f
->pointer_invisible
)
27005 hlinfo
->mouse_face_mouse_x
= x
;
27006 hlinfo
->mouse_face_mouse_y
= y
;
27007 hlinfo
->mouse_face_mouse_frame
= f
;
27009 if (hlinfo
->mouse_face_defer
)
27012 if (gc_in_progress
)
27014 hlinfo
->mouse_face_deferred_gc
= 1;
27018 /* Which window is that in? */
27019 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27021 /* If displaying active text in another window, clear that. */
27022 if (! EQ (window
, hlinfo
->mouse_face_window
)
27023 /* Also clear if we move out of text area in same window. */
27024 || (!NILP (hlinfo
->mouse_face_window
)
27027 && part
!= ON_MODE_LINE
27028 && part
!= ON_HEADER_LINE
))
27029 clear_mouse_face (hlinfo
);
27031 /* Not on a window -> return. */
27032 if (!WINDOWP (window
))
27035 /* Reset help_echo_string. It will get recomputed below. */
27036 help_echo_string
= Qnil
;
27038 /* Convert to window-relative pixel coordinates. */
27039 w
= XWINDOW (window
);
27040 frame_to_window_pixel_xy (w
, &x
, &y
);
27042 #ifdef HAVE_WINDOW_SYSTEM
27043 /* Handle tool-bar window differently since it doesn't display a
27045 if (EQ (window
, f
->tool_bar_window
))
27047 note_tool_bar_highlight (f
, x
, y
);
27052 /* Mouse is on the mode, header line or margin? */
27053 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27054 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27056 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27060 #ifdef HAVE_WINDOW_SYSTEM
27061 if (part
== ON_VERTICAL_BORDER
)
27063 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27064 help_echo_string
= build_string ("drag-mouse-1: resize");
27066 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27067 || part
== ON_SCROLL_BAR
)
27068 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27070 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27073 /* Are we in a window whose display is up to date?
27074 And verify the buffer's text has not changed. */
27075 b
= XBUFFER (w
->buffer
);
27076 if (part
== ON_TEXT
27077 && EQ (w
->window_end_valid
, w
->buffer
)
27078 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
27079 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
27081 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27083 struct glyph
*glyph
;
27084 Lisp_Object object
;
27085 Lisp_Object mouse_face
= Qnil
, position
;
27086 Lisp_Object
*overlay_vec
= NULL
;
27087 ptrdiff_t i
, noverlays
;
27088 struct buffer
*obuf
;
27089 ptrdiff_t obegv
, ozv
;
27092 /* Find the glyph under X/Y. */
27093 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27095 #ifdef HAVE_WINDOW_SYSTEM
27096 /* Look for :pointer property on image. */
27097 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27099 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27100 if (img
!= NULL
&& IMAGEP (img
->spec
))
27102 Lisp_Object image_map
, hotspot
;
27103 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27105 && (hotspot
= find_hot_spot (image_map
,
27106 glyph
->slice
.img
.x
+ dx
,
27107 glyph
->slice
.img
.y
+ dy
),
27109 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27113 /* Could check XCAR (hotspot) to see if we enter/leave
27115 If so, we could look for mouse-enter, mouse-leave
27116 properties in PLIST (and do something...). */
27117 hotspot
= XCDR (hotspot
);
27118 if (CONSP (hotspot
)
27119 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27121 pointer
= Fplist_get (plist
, Qpointer
);
27122 if (NILP (pointer
))
27124 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27125 if (!NILP (help_echo_string
))
27127 help_echo_window
= window
;
27128 help_echo_object
= glyph
->object
;
27129 help_echo_pos
= glyph
->charpos
;
27133 if (NILP (pointer
))
27134 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27137 #endif /* HAVE_WINDOW_SYSTEM */
27139 /* Clear mouse face if X/Y not over text. */
27141 || area
!= TEXT_AREA
27142 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27143 /* Glyph's OBJECT is an integer for glyphs inserted by the
27144 display engine for its internal purposes, like truncation
27145 and continuation glyphs and blanks beyond the end of
27146 line's text on text terminals. If we are over such a
27147 glyph, we are not over any text. */
27148 || INTEGERP (glyph
->object
)
27149 /* R2L rows have a stretch glyph at their front, which
27150 stands for no text, whereas L2R rows have no glyphs at
27151 all beyond the end of text. Treat such stretch glyphs
27152 like we do with NULL glyphs in L2R rows. */
27153 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27154 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27155 && glyph
->type
== STRETCH_GLYPH
27156 && glyph
->avoid_cursor_p
))
27158 if (clear_mouse_face (hlinfo
))
27159 cursor
= No_Cursor
;
27160 #ifdef HAVE_WINDOW_SYSTEM
27161 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27163 if (area
!= TEXT_AREA
)
27164 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27166 pointer
= Vvoid_text_area_pointer
;
27172 pos
= glyph
->charpos
;
27173 object
= glyph
->object
;
27174 if (!STRINGP (object
) && !BUFFERP (object
))
27177 /* If we get an out-of-range value, return now; avoid an error. */
27178 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27181 /* Make the window's buffer temporarily current for
27182 overlays_at and compute_char_face. */
27183 obuf
= current_buffer
;
27184 current_buffer
= b
;
27190 /* Is this char mouse-active or does it have help-echo? */
27191 position
= make_number (pos
);
27193 if (BUFFERP (object
))
27195 /* Put all the overlays we want in a vector in overlay_vec. */
27196 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27197 /* Sort overlays into increasing priority order. */
27198 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27203 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27206 cursor
= No_Cursor
;
27208 /* Check mouse-face highlighting. */
27210 /* If there exists an overlay with mouse-face overlapping
27211 the one we are currently highlighting, we have to
27212 check if we enter the overlapping overlay, and then
27213 highlight only that. */
27214 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27215 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27217 /* Find the highest priority overlay with a mouse-face. */
27218 Lisp_Object overlay
= Qnil
;
27219 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27221 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27222 if (!NILP (mouse_face
))
27223 overlay
= overlay_vec
[i
];
27226 /* If we're highlighting the same overlay as before, there's
27227 no need to do that again. */
27228 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27229 goto check_help_echo
;
27230 hlinfo
->mouse_face_overlay
= overlay
;
27232 /* Clear the display of the old active region, if any. */
27233 if (clear_mouse_face (hlinfo
))
27234 cursor
= No_Cursor
;
27236 /* If no overlay applies, get a text property. */
27237 if (NILP (overlay
))
27238 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27240 /* Next, compute the bounds of the mouse highlighting and
27242 if (!NILP (mouse_face
) && STRINGP (object
))
27244 /* The mouse-highlighting comes from a display string
27245 with a mouse-face. */
27249 s
= Fprevious_single_property_change
27250 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27251 e
= Fnext_single_property_change
27252 (position
, Qmouse_face
, object
, Qnil
);
27254 s
= make_number (0);
27256 e
= make_number (SCHARS (object
) - 1);
27257 mouse_face_from_string_pos (w
, hlinfo
, object
,
27258 XINT (s
), XINT (e
));
27259 hlinfo
->mouse_face_past_end
= 0;
27260 hlinfo
->mouse_face_window
= window
;
27261 hlinfo
->mouse_face_face_id
27262 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27263 glyph
->face_id
, 1);
27264 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27265 cursor
= No_Cursor
;
27269 /* The mouse-highlighting, if any, comes from an overlay
27270 or text property in the buffer. */
27271 Lisp_Object buffer
IF_LINT (= Qnil
);
27272 Lisp_Object disp_string
IF_LINT (= Qnil
);
27274 if (STRINGP (object
))
27276 /* If we are on a display string with no mouse-face,
27277 check if the text under it has one. */
27278 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27279 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27280 pos
= string_buffer_position (object
, start
);
27283 mouse_face
= get_char_property_and_overlay
27284 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27285 buffer
= w
->buffer
;
27286 disp_string
= object
;
27292 disp_string
= Qnil
;
27295 if (!NILP (mouse_face
))
27297 Lisp_Object before
, after
;
27298 Lisp_Object before_string
, after_string
;
27299 /* To correctly find the limits of mouse highlight
27300 in a bidi-reordered buffer, we must not use the
27301 optimization of limiting the search in
27302 previous-single-property-change and
27303 next-single-property-change, because
27304 rows_from_pos_range needs the real start and end
27305 positions to DTRT in this case. That's because
27306 the first row visible in a window does not
27307 necessarily display the character whose position
27308 is the smallest. */
27310 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27311 ? Fmarker_position (w
->start
)
27314 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27315 ? make_number (BUF_Z (XBUFFER (buffer
))
27316 - XFASTINT (w
->window_end_pos
))
27319 if (NILP (overlay
))
27321 /* Handle the text property case. */
27322 before
= Fprevious_single_property_change
27323 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27324 after
= Fnext_single_property_change
27325 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27326 before_string
= after_string
= Qnil
;
27330 /* Handle the overlay case. */
27331 before
= Foverlay_start (overlay
);
27332 after
= Foverlay_end (overlay
);
27333 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27334 after_string
= Foverlay_get (overlay
, Qafter_string
);
27336 if (!STRINGP (before_string
)) before_string
= Qnil
;
27337 if (!STRINGP (after_string
)) after_string
= Qnil
;
27340 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27343 : XFASTINT (before
),
27345 ? BUF_Z (XBUFFER (buffer
))
27346 : XFASTINT (after
),
27347 before_string
, after_string
,
27349 cursor
= No_Cursor
;
27356 /* Look for a `help-echo' property. */
27357 if (NILP (help_echo_string
)) {
27358 Lisp_Object help
, overlay
;
27360 /* Check overlays first. */
27361 help
= overlay
= Qnil
;
27362 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27364 overlay
= overlay_vec
[i
];
27365 help
= Foverlay_get (overlay
, Qhelp_echo
);
27370 help_echo_string
= help
;
27371 help_echo_window
= window
;
27372 help_echo_object
= overlay
;
27373 help_echo_pos
= pos
;
27377 Lisp_Object obj
= glyph
->object
;
27378 ptrdiff_t charpos
= glyph
->charpos
;
27380 /* Try text properties. */
27383 && charpos
< SCHARS (obj
))
27385 help
= Fget_text_property (make_number (charpos
),
27389 /* If the string itself doesn't specify a help-echo,
27390 see if the buffer text ``under'' it does. */
27391 struct glyph_row
*r
27392 = MATRIX_ROW (w
->current_matrix
, vpos
);
27393 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27394 ptrdiff_t p
= string_buffer_position (obj
, start
);
27397 help
= Fget_char_property (make_number (p
),
27398 Qhelp_echo
, w
->buffer
);
27407 else if (BUFFERP (obj
)
27410 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27415 help_echo_string
= help
;
27416 help_echo_window
= window
;
27417 help_echo_object
= obj
;
27418 help_echo_pos
= charpos
;
27423 #ifdef HAVE_WINDOW_SYSTEM
27424 /* Look for a `pointer' property. */
27425 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27427 /* Check overlays first. */
27428 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27429 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27431 if (NILP (pointer
))
27433 Lisp_Object obj
= glyph
->object
;
27434 ptrdiff_t charpos
= glyph
->charpos
;
27436 /* Try text properties. */
27439 && charpos
< SCHARS (obj
))
27441 pointer
= Fget_text_property (make_number (charpos
),
27443 if (NILP (pointer
))
27445 /* If the string itself doesn't specify a pointer,
27446 see if the buffer text ``under'' it does. */
27447 struct glyph_row
*r
27448 = MATRIX_ROW (w
->current_matrix
, vpos
);
27449 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27450 ptrdiff_t p
= string_buffer_position (obj
, start
);
27452 pointer
= Fget_char_property (make_number (p
),
27453 Qpointer
, w
->buffer
);
27456 else if (BUFFERP (obj
)
27459 pointer
= Fget_text_property (make_number (charpos
),
27463 #endif /* HAVE_WINDOW_SYSTEM */
27467 current_buffer
= obuf
;
27472 #ifdef HAVE_WINDOW_SYSTEM
27473 if (FRAME_WINDOW_P (f
))
27474 define_frame_cursor1 (f
, cursor
, pointer
);
27476 /* This is here to prevent a compiler error, about "label at end of
27477 compound statement". */
27484 Clear any mouse-face on window W. This function is part of the
27485 redisplay interface, and is called from try_window_id and similar
27486 functions to ensure the mouse-highlight is off. */
27489 x_clear_window_mouse_face (struct window
*w
)
27491 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27492 Lisp_Object window
;
27495 XSETWINDOW (window
, w
);
27496 if (EQ (window
, hlinfo
->mouse_face_window
))
27497 clear_mouse_face (hlinfo
);
27503 Just discard the mouse face information for frame F, if any.
27504 This is used when the size of F is changed. */
27507 cancel_mouse_face (struct frame
*f
)
27509 Lisp_Object window
;
27510 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27512 window
= hlinfo
->mouse_face_window
;
27513 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27515 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27516 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27517 hlinfo
->mouse_face_window
= Qnil
;
27523 /***********************************************************************
27525 ***********************************************************************/
27527 #ifdef HAVE_WINDOW_SYSTEM
27529 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27530 which intersects rectangle R. R is in window-relative coordinates. */
27533 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27534 enum glyph_row_area area
)
27536 struct glyph
*first
= row
->glyphs
[area
];
27537 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27538 struct glyph
*last
;
27539 int first_x
, start_x
, x
;
27541 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27542 /* If row extends face to end of line write the whole line. */
27543 draw_glyphs (w
, 0, row
, area
,
27544 0, row
->used
[area
],
27545 DRAW_NORMAL_TEXT
, 0);
27548 /* Set START_X to the window-relative start position for drawing glyphs of
27549 AREA. The first glyph of the text area can be partially visible.
27550 The first glyphs of other areas cannot. */
27551 start_x
= window_box_left_offset (w
, area
);
27553 if (area
== TEXT_AREA
)
27556 /* Find the first glyph that must be redrawn. */
27558 && x
+ first
->pixel_width
< r
->x
)
27560 x
+= first
->pixel_width
;
27564 /* Find the last one. */
27568 && x
< r
->x
+ r
->width
)
27570 x
+= last
->pixel_width
;
27576 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27577 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27578 DRAW_NORMAL_TEXT
, 0);
27583 /* Redraw the parts of the glyph row ROW on window W intersecting
27584 rectangle R. R is in window-relative coordinates. Value is
27585 non-zero if mouse-face was overwritten. */
27588 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27590 xassert (row
->enabled_p
);
27592 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27593 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27594 0, row
->used
[TEXT_AREA
],
27595 DRAW_NORMAL_TEXT
, 0);
27598 if (row
->used
[LEFT_MARGIN_AREA
])
27599 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27600 if (row
->used
[TEXT_AREA
])
27601 expose_area (w
, row
, r
, TEXT_AREA
);
27602 if (row
->used
[RIGHT_MARGIN_AREA
])
27603 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27604 draw_row_fringe_bitmaps (w
, row
);
27607 return row
->mouse_face_p
;
27611 /* Redraw those parts of glyphs rows during expose event handling that
27612 overlap other rows. Redrawing of an exposed line writes over parts
27613 of lines overlapping that exposed line; this function fixes that.
27615 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27616 row in W's current matrix that is exposed and overlaps other rows.
27617 LAST_OVERLAPPING_ROW is the last such row. */
27620 expose_overlaps (struct window
*w
,
27621 struct glyph_row
*first_overlapping_row
,
27622 struct glyph_row
*last_overlapping_row
,
27625 struct glyph_row
*row
;
27627 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27628 if (row
->overlapping_p
)
27630 xassert (row
->enabled_p
&& !row
->mode_line_p
);
27633 if (row
->used
[LEFT_MARGIN_AREA
])
27634 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
27636 if (row
->used
[TEXT_AREA
])
27637 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
27639 if (row
->used
[RIGHT_MARGIN_AREA
])
27640 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
27646 /* Return non-zero if W's cursor intersects rectangle R. */
27649 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
27651 XRectangle cr
, result
;
27652 struct glyph
*cursor_glyph
;
27653 struct glyph_row
*row
;
27655 if (w
->phys_cursor
.vpos
>= 0
27656 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
27657 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
27659 && row
->cursor_in_fringe_p
)
27661 /* Cursor is in the fringe. */
27662 cr
.x
= window_box_right_offset (w
,
27663 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
27664 ? RIGHT_MARGIN_AREA
27667 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
27668 cr
.height
= row
->height
;
27669 return x_intersect_rectangles (&cr
, r
, &result
);
27672 cursor_glyph
= get_phys_cursor_glyph (w
);
27675 /* r is relative to W's box, but w->phys_cursor.x is relative
27676 to left edge of W's TEXT area. Adjust it. */
27677 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
27678 cr
.y
= w
->phys_cursor
.y
;
27679 cr
.width
= cursor_glyph
->pixel_width
;
27680 cr
.height
= w
->phys_cursor_height
;
27681 /* ++KFS: W32 version used W32-specific IntersectRect here, but
27682 I assume the effect is the same -- and this is portable. */
27683 return x_intersect_rectangles (&cr
, r
, &result
);
27685 /* If we don't understand the format, pretend we're not in the hot-spot. */
27691 Draw a vertical window border to the right of window W if W doesn't
27692 have vertical scroll bars. */
27695 x_draw_vertical_border (struct window
*w
)
27697 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27699 /* We could do better, if we knew what type of scroll-bar the adjacent
27700 windows (on either side) have... But we don't :-(
27701 However, I think this works ok. ++KFS 2003-04-25 */
27703 /* Redraw borders between horizontally adjacent windows. Don't
27704 do it for frames with vertical scroll bars because either the
27705 right scroll bar of a window, or the left scroll bar of its
27706 neighbor will suffice as a border. */
27707 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
27710 if (!WINDOW_RIGHTMOST_P (w
)
27711 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
27713 int x0
, x1
, y0
, y1
;
27715 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27718 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27721 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
27723 else if (!WINDOW_LEFTMOST_P (w
)
27724 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
27726 int x0
, x1
, y0
, y1
;
27728 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27731 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27734 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
27739 /* Redraw the part of window W intersection rectangle FR. Pixel
27740 coordinates in FR are frame-relative. Call this function with
27741 input blocked. Value is non-zero if the exposure overwrites
27745 expose_window (struct window
*w
, XRectangle
*fr
)
27747 struct frame
*f
= XFRAME (w
->frame
);
27749 int mouse_face_overwritten_p
= 0;
27751 /* If window is not yet fully initialized, do nothing. This can
27752 happen when toolkit scroll bars are used and a window is split.
27753 Reconfiguring the scroll bar will generate an expose for a newly
27755 if (w
->current_matrix
== NULL
)
27758 /* When we're currently updating the window, display and current
27759 matrix usually don't agree. Arrange for a thorough display
27761 if (w
== updated_window
)
27763 SET_FRAME_GARBAGED (f
);
27767 /* Frame-relative pixel rectangle of W. */
27768 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
27769 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
27770 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
27771 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
27773 if (x_intersect_rectangles (fr
, &wr
, &r
))
27775 int yb
= window_text_bottom_y (w
);
27776 struct glyph_row
*row
;
27777 int cursor_cleared_p
, phys_cursor_on_p
;
27778 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
27780 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
27781 r
.x
, r
.y
, r
.width
, r
.height
));
27783 /* Convert to window coordinates. */
27784 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
27785 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
27787 /* Turn off the cursor. */
27788 if (!w
->pseudo_window_p
27789 && phys_cursor_in_rect_p (w
, &r
))
27791 x_clear_cursor (w
);
27792 cursor_cleared_p
= 1;
27795 cursor_cleared_p
= 0;
27797 /* If the row containing the cursor extends face to end of line,
27798 then expose_area might overwrite the cursor outside the
27799 rectangle and thus notice_overwritten_cursor might clear
27800 w->phys_cursor_on_p. We remember the original value and
27801 check later if it is changed. */
27802 phys_cursor_on_p
= w
->phys_cursor_on_p
;
27804 /* Update lines intersecting rectangle R. */
27805 first_overlapping_row
= last_overlapping_row
= NULL
;
27806 for (row
= w
->current_matrix
->rows
;
27811 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
27813 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
27814 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
27815 || (r
.y
>= y0
&& r
.y
< y1
)
27816 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
27818 /* A header line may be overlapping, but there is no need
27819 to fix overlapping areas for them. KFS 2005-02-12 */
27820 if (row
->overlapping_p
&& !row
->mode_line_p
)
27822 if (first_overlapping_row
== NULL
)
27823 first_overlapping_row
= row
;
27824 last_overlapping_row
= row
;
27828 if (expose_line (w
, row
, &r
))
27829 mouse_face_overwritten_p
= 1;
27832 else if (row
->overlapping_p
)
27834 /* We must redraw a row overlapping the exposed area. */
27836 ? y0
+ row
->phys_height
> r
.y
27837 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
27839 if (first_overlapping_row
== NULL
)
27840 first_overlapping_row
= row
;
27841 last_overlapping_row
= row
;
27849 /* Display the mode line if there is one. */
27850 if (WINDOW_WANTS_MODELINE_P (w
)
27851 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
27853 && row
->y
< r
.y
+ r
.height
)
27855 if (expose_line (w
, row
, &r
))
27856 mouse_face_overwritten_p
= 1;
27859 if (!w
->pseudo_window_p
)
27861 /* Fix the display of overlapping rows. */
27862 if (first_overlapping_row
)
27863 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
27866 /* Draw border between windows. */
27867 x_draw_vertical_border (w
);
27869 /* Turn the cursor on again. */
27870 if (cursor_cleared_p
27871 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
27872 update_window_cursor (w
, 1);
27876 return mouse_face_overwritten_p
;
27881 /* Redraw (parts) of all windows in the window tree rooted at W that
27882 intersect R. R contains frame pixel coordinates. Value is
27883 non-zero if the exposure overwrites mouse-face. */
27886 expose_window_tree (struct window
*w
, XRectangle
*r
)
27888 struct frame
*f
= XFRAME (w
->frame
);
27889 int mouse_face_overwritten_p
= 0;
27891 while (w
&& !FRAME_GARBAGED_P (f
))
27893 if (!NILP (w
->hchild
))
27894 mouse_face_overwritten_p
27895 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
27896 else if (!NILP (w
->vchild
))
27897 mouse_face_overwritten_p
27898 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
27900 mouse_face_overwritten_p
|= expose_window (w
, r
);
27902 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
27905 return mouse_face_overwritten_p
;
27910 Redisplay an exposed area of frame F. X and Y are the upper-left
27911 corner of the exposed rectangle. W and H are width and height of
27912 the exposed area. All are pixel values. W or H zero means redraw
27913 the entire frame. */
27916 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
27919 int mouse_face_overwritten_p
= 0;
27921 TRACE ((stderr
, "expose_frame "));
27923 /* No need to redraw if frame will be redrawn soon. */
27924 if (FRAME_GARBAGED_P (f
))
27926 TRACE ((stderr
, " garbaged\n"));
27930 /* If basic faces haven't been realized yet, there is no point in
27931 trying to redraw anything. This can happen when we get an expose
27932 event while Emacs is starting, e.g. by moving another window. */
27933 if (FRAME_FACE_CACHE (f
) == NULL
27934 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
27936 TRACE ((stderr
, " no faces\n"));
27940 if (w
== 0 || h
== 0)
27943 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
27944 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
27954 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
27955 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
27957 if (WINDOWP (f
->tool_bar_window
))
27958 mouse_face_overwritten_p
27959 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
27961 #ifdef HAVE_X_WINDOWS
27963 #ifndef USE_X_TOOLKIT
27964 if (WINDOWP (f
->menu_bar_window
))
27965 mouse_face_overwritten_p
27966 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
27967 #endif /* not USE_X_TOOLKIT */
27971 /* Some window managers support a focus-follows-mouse style with
27972 delayed raising of frames. Imagine a partially obscured frame,
27973 and moving the mouse into partially obscured mouse-face on that
27974 frame. The visible part of the mouse-face will be highlighted,
27975 then the WM raises the obscured frame. With at least one WM, KDE
27976 2.1, Emacs is not getting any event for the raising of the frame
27977 (even tried with SubstructureRedirectMask), only Expose events.
27978 These expose events will draw text normally, i.e. not
27979 highlighted. Which means we must redo the highlight here.
27980 Subsume it under ``we love X''. --gerd 2001-08-15 */
27981 /* Included in Windows version because Windows most likely does not
27982 do the right thing if any third party tool offers
27983 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
27984 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
27986 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27987 if (f
== hlinfo
->mouse_face_mouse_frame
)
27989 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
27990 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
27991 clear_mouse_face (hlinfo
);
27992 note_mouse_highlight (f
, mouse_x
, mouse_y
);
27999 Determine the intersection of two rectangles R1 and R2. Return
28000 the intersection in *RESULT. Value is non-zero if RESULT is not
28004 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28006 XRectangle
*left
, *right
;
28007 XRectangle
*upper
, *lower
;
28008 int intersection_p
= 0;
28010 /* Rearrange so that R1 is the left-most rectangle. */
28012 left
= r1
, right
= r2
;
28014 left
= r2
, right
= r1
;
28016 /* X0 of the intersection is right.x0, if this is inside R1,
28017 otherwise there is no intersection. */
28018 if (right
->x
<= left
->x
+ left
->width
)
28020 result
->x
= right
->x
;
28022 /* The right end of the intersection is the minimum of
28023 the right ends of left and right. */
28024 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28027 /* Same game for Y. */
28029 upper
= r1
, lower
= r2
;
28031 upper
= r2
, lower
= r1
;
28033 /* The upper end of the intersection is lower.y0, if this is inside
28034 of upper. Otherwise, there is no intersection. */
28035 if (lower
->y
<= upper
->y
+ upper
->height
)
28037 result
->y
= lower
->y
;
28039 /* The lower end of the intersection is the minimum of the lower
28040 ends of upper and lower. */
28041 result
->height
= (min (lower
->y
+ lower
->height
,
28042 upper
->y
+ upper
->height
)
28044 intersection_p
= 1;
28048 return intersection_p
;
28051 #endif /* HAVE_WINDOW_SYSTEM */
28054 /***********************************************************************
28056 ***********************************************************************/
28059 syms_of_xdisp (void)
28061 Vwith_echo_area_save_vector
= Qnil
;
28062 staticpro (&Vwith_echo_area_save_vector
);
28064 Vmessage_stack
= Qnil
;
28065 staticpro (&Vmessage_stack
);
28067 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28069 message_dolog_marker1
= Fmake_marker ();
28070 staticpro (&message_dolog_marker1
);
28071 message_dolog_marker2
= Fmake_marker ();
28072 staticpro (&message_dolog_marker2
);
28073 message_dolog_marker3
= Fmake_marker ();
28074 staticpro (&message_dolog_marker3
);
28077 defsubr (&Sdump_frame_glyph_matrix
);
28078 defsubr (&Sdump_glyph_matrix
);
28079 defsubr (&Sdump_glyph_row
);
28080 defsubr (&Sdump_tool_bar_row
);
28081 defsubr (&Strace_redisplay
);
28082 defsubr (&Strace_to_stderr
);
28084 #ifdef HAVE_WINDOW_SYSTEM
28085 defsubr (&Stool_bar_lines_needed
);
28086 defsubr (&Slookup_image_map
);
28088 defsubr (&Sformat_mode_line
);
28089 defsubr (&Sinvisible_p
);
28090 defsubr (&Scurrent_bidi_paragraph_direction
);
28092 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28093 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28094 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28095 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28096 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28097 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28098 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28099 DEFSYM (Qeval
, "eval");
28100 DEFSYM (QCdata
, ":data");
28101 DEFSYM (Qdisplay
, "display");
28102 DEFSYM (Qspace_width
, "space-width");
28103 DEFSYM (Qraise
, "raise");
28104 DEFSYM (Qslice
, "slice");
28105 DEFSYM (Qspace
, "space");
28106 DEFSYM (Qmargin
, "margin");
28107 DEFSYM (Qpointer
, "pointer");
28108 DEFSYM (Qleft_margin
, "left-margin");
28109 DEFSYM (Qright_margin
, "right-margin");
28110 DEFSYM (Qcenter
, "center");
28111 DEFSYM (Qline_height
, "line-height");
28112 DEFSYM (QCalign_to
, ":align-to");
28113 DEFSYM (QCrelative_width
, ":relative-width");
28114 DEFSYM (QCrelative_height
, ":relative-height");
28115 DEFSYM (QCeval
, ":eval");
28116 DEFSYM (QCpropertize
, ":propertize");
28117 DEFSYM (QCfile
, ":file");
28118 DEFSYM (Qfontified
, "fontified");
28119 DEFSYM (Qfontification_functions
, "fontification-functions");
28120 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28121 DEFSYM (Qescape_glyph
, "escape-glyph");
28122 DEFSYM (Qnobreak_space
, "nobreak-space");
28123 DEFSYM (Qimage
, "image");
28124 DEFSYM (Qtext
, "text");
28125 DEFSYM (Qboth
, "both");
28126 DEFSYM (Qboth_horiz
, "both-horiz");
28127 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28128 DEFSYM (QCmap
, ":map");
28129 DEFSYM (QCpointer
, ":pointer");
28130 DEFSYM (Qrect
, "rect");
28131 DEFSYM (Qcircle
, "circle");
28132 DEFSYM (Qpoly
, "poly");
28133 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28134 DEFSYM (Qgrow_only
, "grow-only");
28135 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28136 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28137 DEFSYM (Qposition
, "position");
28138 DEFSYM (Qbuffer_position
, "buffer-position");
28139 DEFSYM (Qobject
, "object");
28140 DEFSYM (Qbar
, "bar");
28141 DEFSYM (Qhbar
, "hbar");
28142 DEFSYM (Qbox
, "box");
28143 DEFSYM (Qhollow
, "hollow");
28144 DEFSYM (Qhand
, "hand");
28145 DEFSYM (Qarrow
, "arrow");
28146 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28148 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28149 Fcons (intern_c_string ("void-variable"), Qnil
)),
28151 staticpro (&list_of_error
);
28153 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28154 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28155 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28156 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28158 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28159 staticpro (&echo_buffer
[0]);
28160 staticpro (&echo_buffer
[1]);
28162 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28163 staticpro (&echo_area_buffer
[0]);
28164 staticpro (&echo_area_buffer
[1]);
28166 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28167 staticpro (&Vmessages_buffer_name
);
28169 mode_line_proptrans_alist
= Qnil
;
28170 staticpro (&mode_line_proptrans_alist
);
28171 mode_line_string_list
= Qnil
;
28172 staticpro (&mode_line_string_list
);
28173 mode_line_string_face
= Qnil
;
28174 staticpro (&mode_line_string_face
);
28175 mode_line_string_face_prop
= Qnil
;
28176 staticpro (&mode_line_string_face_prop
);
28177 Vmode_line_unwind_vector
= Qnil
;
28178 staticpro (&Vmode_line_unwind_vector
);
28180 help_echo_string
= Qnil
;
28181 staticpro (&help_echo_string
);
28182 help_echo_object
= Qnil
;
28183 staticpro (&help_echo_object
);
28184 help_echo_window
= Qnil
;
28185 staticpro (&help_echo_window
);
28186 previous_help_echo_string
= Qnil
;
28187 staticpro (&previous_help_echo_string
);
28188 help_echo_pos
= -1;
28190 DEFSYM (Qright_to_left
, "right-to-left");
28191 DEFSYM (Qleft_to_right
, "left-to-right");
28193 #ifdef HAVE_WINDOW_SYSTEM
28194 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28195 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
28196 For example, if a block cursor is over a tab, it will be drawn as
28197 wide as that tab on the display. */);
28198 x_stretch_cursor_p
= 0;
28201 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28202 doc
: /* *Non-nil means highlight trailing whitespace.
28203 The face used for trailing whitespace is `trailing-whitespace'. */);
28204 Vshow_trailing_whitespace
= Qnil
;
28206 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28207 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28208 If the value is t, Emacs highlights non-ASCII chars which have the
28209 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28210 or `escape-glyph' face respectively.
28212 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28213 U+2011 (non-breaking hyphen) are affected.
28215 Any other non-nil value means to display these characters as a escape
28216 glyph followed by an ordinary space or hyphen.
28218 A value of nil means no special handling of these characters. */);
28219 Vnobreak_char_display
= Qt
;
28221 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28222 doc
: /* *The pointer shape to show in void text areas.
28223 A value of nil means to show the text pointer. Other options are `arrow',
28224 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28225 Vvoid_text_area_pointer
= Qarrow
;
28227 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28228 doc
: /* Non-nil means don't actually do any redisplay.
28229 This is used for internal purposes. */);
28230 Vinhibit_redisplay
= Qnil
;
28232 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28233 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28234 Vglobal_mode_string
= Qnil
;
28236 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28237 doc
: /* Marker for where to display an arrow on top of the buffer text.
28238 This must be the beginning of a line in order to work.
28239 See also `overlay-arrow-string'. */);
28240 Voverlay_arrow_position
= Qnil
;
28242 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28243 doc
: /* String to display as an arrow in non-window frames.
28244 See also `overlay-arrow-position'. */);
28245 Voverlay_arrow_string
= make_pure_c_string ("=>");
28247 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28248 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28249 The symbols on this list are examined during redisplay to determine
28250 where to display overlay arrows. */);
28251 Voverlay_arrow_variable_list
28252 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28254 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28255 doc
: /* *The number of lines to try scrolling a window by when point moves out.
28256 If that fails to bring point back on frame, point is centered instead.
28257 If this is zero, point is always centered after it moves off frame.
28258 If you want scrolling to always be a line at a time, you should set
28259 `scroll-conservatively' to a large value rather than set this to 1. */);
28261 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28262 doc
: /* *Scroll up to this many lines, to bring point back on screen.
28263 If point moves off-screen, redisplay will scroll by up to
28264 `scroll-conservatively' lines in order to bring point just barely
28265 onto the screen again. If that cannot be done, then redisplay
28266 recenters point as usual.
28268 If the value is greater than 100, redisplay will never recenter point,
28269 but will always scroll just enough text to bring point into view, even
28270 if you move far away.
28272 A value of zero means always recenter point if it moves off screen. */);
28273 scroll_conservatively
= 0;
28275 DEFVAR_INT ("scroll-margin", scroll_margin
,
28276 doc
: /* *Number of lines of margin at the top and bottom of a window.
28277 Recenter the window whenever point gets within this many lines
28278 of the top or bottom of the window. */);
28281 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28282 doc
: /* Pixels per inch value for non-window system displays.
28283 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28284 Vdisplay_pixels_per_inch
= make_float (72.0);
28287 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28290 DEFVAR_LISP ("truncate-partial-width-windows",
28291 Vtruncate_partial_width_windows
,
28292 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28293 For an integer value, truncate lines in each window narrower than the
28294 full frame width, provided the window width is less than that integer;
28295 otherwise, respect the value of `truncate-lines'.
28297 For any other non-nil value, truncate lines in all windows that do
28298 not span the full frame width.
28300 A value of nil means to respect the value of `truncate-lines'.
28302 If `word-wrap' is enabled, you might want to reduce this. */);
28303 Vtruncate_partial_width_windows
= make_number (50);
28305 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28306 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28307 Any other value means to use the appropriate face, `mode-line',
28308 `header-line', or `menu' respectively. */);
28309 mode_line_inverse_video
= 1;
28311 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28312 doc
: /* *Maximum buffer size for which line number should be displayed.
28313 If the buffer is bigger than this, the line number does not appear
28314 in the mode line. A value of nil means no limit. */);
28315 Vline_number_display_limit
= Qnil
;
28317 DEFVAR_INT ("line-number-display-limit-width",
28318 line_number_display_limit_width
,
28319 doc
: /* *Maximum line width (in characters) for line number display.
28320 If the average length of the lines near point is bigger than this, then the
28321 line number may be omitted from the mode line. */);
28322 line_number_display_limit_width
= 200;
28324 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28325 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
28326 highlight_nonselected_windows
= 0;
28328 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28329 doc
: /* Non-nil if more than one frame is visible on this display.
28330 Minibuffer-only frames don't count, but iconified frames do.
28331 This variable is not guaranteed to be accurate except while processing
28332 `frame-title-format' and `icon-title-format'. */);
28334 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28335 doc
: /* Template for displaying the title bar of visible frames.
28336 \(Assuming the window manager supports this feature.)
28338 This variable has the same structure as `mode-line-format', except that
28339 the %c and %l constructs are ignored. It is used only on frames for
28340 which no explicit name has been set \(see `modify-frame-parameters'). */);
28342 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28343 doc
: /* Template for displaying the title bar of an iconified frame.
28344 \(Assuming the window manager supports this feature.)
28345 This variable has the same structure as `mode-line-format' (which see),
28346 and is used only on frames for which no explicit name has been set
28347 \(see `modify-frame-parameters'). */);
28349 = Vframe_title_format
28350 = pure_cons (intern_c_string ("multiple-frames"),
28351 pure_cons (make_pure_c_string ("%b"),
28352 pure_cons (pure_cons (empty_unibyte_string
,
28353 pure_cons (intern_c_string ("invocation-name"),
28354 pure_cons (make_pure_c_string ("@"),
28355 pure_cons (intern_c_string ("system-name"),
28359 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28360 doc
: /* Maximum number of lines to keep in the message log buffer.
28361 If nil, disable message logging. If t, log messages but don't truncate
28362 the buffer when it becomes large. */);
28363 Vmessage_log_max
= make_number (100);
28365 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28366 doc
: /* Functions called before redisplay, if window sizes have changed.
28367 The value should be a list of functions that take one argument.
28368 Just before redisplay, for each frame, if any of its windows have changed
28369 size since the last redisplay, or have been split or deleted,
28370 all the functions in the list are called, with the frame as argument. */);
28371 Vwindow_size_change_functions
= Qnil
;
28373 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28374 doc
: /* List of functions to call before redisplaying a window with scrolling.
28375 Each function is called with two arguments, the window and its new
28376 display-start position. Note that these functions are also called by
28377 `set-window-buffer'. Also note that the value of `window-end' is not
28378 valid when these functions are called.
28380 Warning: Do not use this feature to alter the way the window
28381 is scrolled. It is not designed for that, and such use probably won't
28383 Vwindow_scroll_functions
= Qnil
;
28385 DEFVAR_LISP ("window-text-change-functions",
28386 Vwindow_text_change_functions
,
28387 doc
: /* Functions to call in redisplay when text in the window might change. */);
28388 Vwindow_text_change_functions
= Qnil
;
28390 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28391 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28392 Each function is called with two arguments, the window and the end trigger value.
28393 See `set-window-redisplay-end-trigger'. */);
28394 Vredisplay_end_trigger_functions
= Qnil
;
28396 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28397 doc
: /* *Non-nil means autoselect window with mouse pointer.
28398 If nil, do not autoselect windows.
28399 A positive number means delay autoselection by that many seconds: a
28400 window is autoselected only after the mouse has remained in that
28401 window for the duration of the delay.
28402 A negative number has a similar effect, but causes windows to be
28403 autoselected only after the mouse has stopped moving. \(Because of
28404 the way Emacs compares mouse events, you will occasionally wait twice
28405 that time before the window gets selected.\)
28406 Any other value means to autoselect window instantaneously when the
28407 mouse pointer enters it.
28409 Autoselection selects the minibuffer only if it is active, and never
28410 unselects the minibuffer if it is active.
28412 When customizing this variable make sure that the actual value of
28413 `focus-follows-mouse' matches the behavior of your window manager. */);
28414 Vmouse_autoselect_window
= Qnil
;
28416 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28417 doc
: /* *Non-nil means automatically resize tool-bars.
28418 This dynamically changes the tool-bar's height to the minimum height
28419 that is needed to make all tool-bar items visible.
28420 If value is `grow-only', the tool-bar's height is only increased
28421 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28422 Vauto_resize_tool_bars
= Qt
;
28424 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28425 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28426 auto_raise_tool_bar_buttons_p
= 1;
28428 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28429 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28430 make_cursor_line_fully_visible_p
= 1;
28432 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28433 doc
: /* *Border below tool-bar in pixels.
28434 If an integer, use it as the height of the border.
28435 If it is one of `internal-border-width' or `border-width', use the
28436 value of the corresponding frame parameter.
28437 Otherwise, no border is added below the tool-bar. */);
28438 Vtool_bar_border
= Qinternal_border_width
;
28440 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28441 doc
: /* *Margin around tool-bar buttons in pixels.
28442 If an integer, use that for both horizontal and vertical margins.
28443 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28444 HORZ specifying the horizontal margin, and VERT specifying the
28445 vertical margin. */);
28446 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28448 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28449 doc
: /* *Relief thickness of tool-bar buttons. */);
28450 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28452 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28453 doc
: /* Tool bar style to use.
28455 image - show images only
28456 text - show text only
28457 both - show both, text below image
28458 both-horiz - show text to the right of the image
28459 text-image-horiz - show text to the left of the image
28460 any other - use system default or image if no system default. */);
28461 Vtool_bar_style
= Qnil
;
28463 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28464 doc
: /* *Maximum number of characters a label can have to be shown.
28465 The tool bar style must also show labels for this to have any effect, see
28466 `tool-bar-style'. */);
28467 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28469 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28470 doc
: /* List of functions to call to fontify regions of text.
28471 Each function is called with one argument POS. Functions must
28472 fontify a region starting at POS in the current buffer, and give
28473 fontified regions the property `fontified'. */);
28474 Vfontification_functions
= Qnil
;
28475 Fmake_variable_buffer_local (Qfontification_functions
);
28477 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28478 unibyte_display_via_language_environment
,
28479 doc
: /* *Non-nil means display unibyte text according to language environment.
28480 Specifically, this means that raw bytes in the range 160-255 decimal
28481 are displayed by converting them to the equivalent multibyte characters
28482 according to the current language environment. As a result, they are
28483 displayed according to the current fontset.
28485 Note that this variable affects only how these bytes are displayed,
28486 but does not change the fact they are interpreted as raw bytes. */);
28487 unibyte_display_via_language_environment
= 0;
28489 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28490 doc
: /* *Maximum height for resizing mini-windows (the minibuffer and the echo area).
28491 If a float, it specifies a fraction of the mini-window frame's height.
28492 If an integer, it specifies a number of lines. */);
28493 Vmax_mini_window_height
= make_float (0.25);
28495 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28496 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28497 A value of nil means don't automatically resize mini-windows.
28498 A value of t means resize them to fit the text displayed in them.
28499 A value of `grow-only', the default, means let mini-windows grow only;
28500 they return to their normal size when the minibuffer is closed, or the
28501 echo area becomes empty. */);
28502 Vresize_mini_windows
= Qgrow_only
;
28504 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28505 doc
: /* Alist specifying how to blink the cursor off.
28506 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28507 `cursor-type' frame-parameter or variable equals ON-STATE,
28508 comparing using `equal', Emacs uses OFF-STATE to specify
28509 how to blink it off. ON-STATE and OFF-STATE are values for
28510 the `cursor-type' frame parameter.
28512 If a frame's ON-STATE has no entry in this list,
28513 the frame's other specifications determine how to blink the cursor off. */);
28514 Vblink_cursor_alist
= Qnil
;
28516 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28517 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28518 If non-nil, windows are automatically scrolled horizontally to make
28519 point visible. */);
28520 automatic_hscrolling_p
= 1;
28521 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28523 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28524 doc
: /* *How many columns away from the window edge point is allowed to get
28525 before automatic hscrolling will horizontally scroll the window. */);
28526 hscroll_margin
= 5;
28528 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28529 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
28530 When point is less than `hscroll-margin' columns from the window
28531 edge, automatic hscrolling will scroll the window by the amount of columns
28532 determined by this variable. If its value is a positive integer, scroll that
28533 many columns. If it's a positive floating-point number, it specifies the
28534 fraction of the window's width to scroll. If it's nil or zero, point will be
28535 centered horizontally after the scroll. Any other value, including negative
28536 numbers, are treated as if the value were zero.
28538 Automatic hscrolling always moves point outside the scroll margin, so if
28539 point was more than scroll step columns inside the margin, the window will
28540 scroll more than the value given by the scroll step.
28542 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28543 and `scroll-right' overrides this variable's effect. */);
28544 Vhscroll_step
= make_number (0);
28546 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28547 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28548 Bind this around calls to `message' to let it take effect. */);
28549 message_truncate_lines
= 0;
28551 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28552 doc
: /* Normal hook run to update the menu bar definitions.
28553 Redisplay runs this hook before it redisplays the menu bar.
28554 This is used to update submenus such as Buffers,
28555 whose contents depend on various data. */);
28556 Vmenu_bar_update_hook
= Qnil
;
28558 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28559 doc
: /* Frame for which we are updating a menu.
28560 The enable predicate for a menu binding should check this variable. */);
28561 Vmenu_updating_frame
= Qnil
;
28563 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28564 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28565 inhibit_menubar_update
= 0;
28567 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28568 doc
: /* Prefix prepended to all continuation lines at display time.
28569 The value may be a string, an image, or a stretch-glyph; it is
28570 interpreted in the same way as the value of a `display' text property.
28572 This variable is overridden by any `wrap-prefix' text or overlay
28575 To add a prefix to non-continuation lines, use `line-prefix'. */);
28576 Vwrap_prefix
= Qnil
;
28577 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28578 Fmake_variable_buffer_local (Qwrap_prefix
);
28580 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28581 doc
: /* Prefix prepended to all non-continuation lines at display time.
28582 The value may be a string, an image, or a stretch-glyph; it is
28583 interpreted in the same way as the value of a `display' text property.
28585 This variable is overridden by any `line-prefix' text or overlay
28588 To add a prefix to continuation lines, use `wrap-prefix'. */);
28589 Vline_prefix
= Qnil
;
28590 DEFSYM (Qline_prefix
, "line-prefix");
28591 Fmake_variable_buffer_local (Qline_prefix
);
28593 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28594 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28595 inhibit_eval_during_redisplay
= 0;
28597 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28598 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28599 inhibit_free_realized_faces
= 0;
28602 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28603 doc
: /* Inhibit try_window_id display optimization. */);
28604 inhibit_try_window_id
= 0;
28606 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28607 doc
: /* Inhibit try_window_reusing display optimization. */);
28608 inhibit_try_window_reusing
= 0;
28610 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28611 doc
: /* Inhibit try_cursor_movement display optimization. */);
28612 inhibit_try_cursor_movement
= 0;
28613 #endif /* GLYPH_DEBUG */
28615 DEFVAR_INT ("overline-margin", overline_margin
,
28616 doc
: /* *Space between overline and text, in pixels.
28617 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28618 margin to the character height. */);
28619 overline_margin
= 2;
28621 DEFVAR_INT ("underline-minimum-offset",
28622 underline_minimum_offset
,
28623 doc
: /* Minimum distance between baseline and underline.
28624 This can improve legibility of underlined text at small font sizes,
28625 particularly when using variable `x-use-underline-position-properties'
28626 with fonts that specify an UNDERLINE_POSITION relatively close to the
28627 baseline. The default value is 1. */);
28628 underline_minimum_offset
= 1;
28630 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
28631 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
28632 This feature only works when on a window system that can change
28633 cursor shapes. */);
28634 display_hourglass_p
= 1;
28636 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
28637 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
28638 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
28640 hourglass_atimer
= NULL
;
28641 hourglass_shown_p
= 0;
28643 DEFSYM (Qglyphless_char
, "glyphless-char");
28644 DEFSYM (Qhex_code
, "hex-code");
28645 DEFSYM (Qempty_box
, "empty-box");
28646 DEFSYM (Qthin_space
, "thin-space");
28647 DEFSYM (Qzero_width
, "zero-width");
28649 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
28650 /* Intern this now in case it isn't already done.
28651 Setting this variable twice is harmless.
28652 But don't staticpro it here--that is done in alloc.c. */
28653 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
28654 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
28656 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
28657 doc
: /* Char-table defining glyphless characters.
28658 Each element, if non-nil, should be one of the following:
28659 an ASCII acronym string: display this string in a box
28660 `hex-code': display the hexadecimal code of a character in a box
28661 `empty-box': display as an empty box
28662 `thin-space': display as 1-pixel width space
28663 `zero-width': don't display
28664 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
28665 display method for graphical terminals and text terminals respectively.
28666 GRAPHICAL and TEXT should each have one of the values listed above.
28668 The char-table has one extra slot to control the display of a character for
28669 which no font is found. This slot only takes effect on graphical terminals.
28670 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
28671 `thin-space'. The default is `empty-box'. */);
28672 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
28673 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
28678 /* Initialize this module when Emacs starts. */
28683 current_header_line_height
= current_mode_line_height
= -1;
28685 CHARPOS (this_line_start_pos
) = 0;
28687 if (!noninteractive
)
28689 struct window
*m
= XWINDOW (minibuf_window
);
28690 Lisp_Object frame
= m
->frame
;
28691 struct frame
*f
= XFRAME (frame
);
28692 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
28693 struct window
*r
= XWINDOW (root
);
28696 echo_area_window
= minibuf_window
;
28698 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
28699 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
28700 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
28701 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
28702 XSETFASTINT (m
->total_lines
, 1);
28703 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
28705 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
28706 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
28707 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
28709 /* The default ellipsis glyphs `...'. */
28710 for (i
= 0; i
< 3; ++i
)
28711 default_invis_vector
[i
] = make_number ('.');
28715 /* Allocate the buffer for frame titles.
28716 Also used for `format-mode-line'. */
28718 mode_line_noprop_buf
= (char *) xmalloc (size
);
28719 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
28720 mode_line_noprop_ptr
= mode_line_noprop_buf
;
28721 mode_line_target
= MODE_LINE_DISPLAY
;
28724 help_echo_showing_p
= 0;
28727 /* Since w32 does not support atimers, it defines its own implementation of
28728 the following three functions in w32fns.c. */
28731 /* Platform-independent portion of hourglass implementation. */
28733 /* Return non-zero if hourglass timer has been started or hourglass is
28736 hourglass_started (void)
28738 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
28741 /* Cancel a currently active hourglass timer, and start a new one. */
28743 start_hourglass (void)
28745 #if defined (HAVE_WINDOW_SYSTEM)
28747 int secs
= DEFAULT_HOURGLASS_DELAY
, usecs
= 0;
28749 cancel_hourglass ();
28751 if (NUMBERP (Vhourglass_delay
))
28753 double duration
= extract_float (Vhourglass_delay
);
28755 duration_to_sec_usec (duration
, &secs
, &usecs
);
28758 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
28759 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
28760 show_hourglass
, NULL
);
28765 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
28768 cancel_hourglass (void)
28770 #if defined (HAVE_WINDOW_SYSTEM)
28771 if (hourglass_atimer
)
28773 cancel_atimer (hourglass_atimer
);
28774 hourglass_atimer
= NULL
;
28777 if (hourglass_shown_p
)
28781 #endif /* ! WINDOWSNT */