1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2011 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. */
4096 if (it
->bidi_p
&& newpos
< ZV
)
4098 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4099 int on_newline
= FETCH_BYTE (bpos
) == '\n';
4101 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4103 /* If the invisible text ends on a newline or on a
4104 character after a newline, we can avoid the costly,
4105 character by character, bidi iteration to NEWPOS, and
4106 instead simply reseat the iterator there. That's
4107 because all bidi reordering information is tossed at
4108 the newline. This is a big win for modes that hide
4109 complete lines, like Outline, Org, etc. */
4110 if (on_newline
|| after_newline
)
4112 struct text_pos tpos
;
4113 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4115 SET_TEXT_POS (tpos
, newpos
, bpos
);
4116 reseat_1 (it
, tpos
, 0);
4117 /* If we reseat on a newline, we need to prep the
4118 bidi iterator for advancing to the next character
4119 after the newline, keeping the current paragraph
4120 direction (so that PRODUCE_GLYPHS does TRT wrt
4121 prepending/appending glyphs to a glyph row). */
4124 it
->bidi_it
.first_elt
= 0;
4125 it
->bidi_it
.paragraph_dir
= pdir
;
4126 it
->bidi_it
.ch
= '\n';
4127 it
->bidi_it
.nchars
= 1;
4128 it
->bidi_it
.ch_len
= 1;
4131 else /* Must use the slow method. */
4133 /* With bidi iteration, the region of invisible text
4134 could start and/or end in the middle of a
4135 non-base embedding level. Therefore, we need to
4136 skip invisible text using the bidi iterator,
4137 starting at IT's current position, until we find
4138 ourselves outside of the invisible text.
4139 Skipping invisible text _after_ bidi iteration
4140 avoids affecting the visual order of the
4141 displayed text when invisible properties are
4142 added or removed. */
4143 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4145 /* If we were `reseat'ed to a new paragraph,
4146 determine the paragraph base direction. We
4147 need to do it now because
4148 next_element_from_buffer may not have a
4149 chance to do it, if we are going to skip any
4150 text at the beginning, which resets the
4152 bidi_paragraph_init (it
->paragraph_embedding
,
4157 bidi_move_to_visually_next (&it
->bidi_it
);
4159 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4160 && it
->bidi_it
.charpos
< newpos
);
4161 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4162 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4163 /* If we overstepped NEWPOS, record its position in
4164 the iterator, so that we skip invisible text if
4165 later the bidi iteration lands us in the
4166 invisible region again. */
4167 if (IT_CHARPOS (*it
) >= newpos
)
4168 it
->prev_stop
= newpos
;
4173 IT_CHARPOS (*it
) = newpos
;
4174 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4177 /* If there are before-strings at the start of invisible
4178 text, and the text is invisible because of a text
4179 property, arrange to show before-strings because 20.x did
4180 it that way. (If the text is invisible because of an
4181 overlay property instead of a text property, this is
4182 already handled in the overlay code.) */
4184 && get_overlay_strings (it
, it
->stop_charpos
))
4186 handled
= HANDLED_RECOMPUTE_PROPS
;
4187 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4189 else if (display_ellipsis_p
)
4191 /* Make sure that the glyphs of the ellipsis will get
4192 correct `charpos' values. If we would not update
4193 it->position here, the glyphs would belong to the
4194 last visible character _before_ the invisible
4195 text, which confuses `set_cursor_from_row'.
4197 We use the last invisible position instead of the
4198 first because this way the cursor is always drawn on
4199 the first "." of the ellipsis, whenever PT is inside
4200 the invisible text. Otherwise the cursor would be
4201 placed _after_ the ellipsis when the point is after the
4202 first invisible character. */
4203 if (!STRINGP (it
->object
))
4205 it
->position
.charpos
= newpos
- 1;
4206 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4209 /* Let the ellipsis display before
4210 considering any properties of the following char.
4211 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4212 handled
= HANDLED_RETURN
;
4221 /* Make iterator IT return `...' next.
4222 Replaces LEN characters from buffer. */
4225 setup_for_ellipsis (struct it
*it
, int len
)
4227 /* Use the display table definition for `...'. Invalid glyphs
4228 will be handled by the method returning elements from dpvec. */
4229 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4231 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4232 it
->dpvec
= v
->contents
;
4233 it
->dpend
= v
->contents
+ v
->header
.size
;
4237 /* Default `...'. */
4238 it
->dpvec
= default_invis_vector
;
4239 it
->dpend
= default_invis_vector
+ 3;
4242 it
->dpvec_char_len
= len
;
4243 it
->current
.dpvec_index
= 0;
4244 it
->dpvec_face_id
= -1;
4246 /* Remember the current face id in case glyphs specify faces.
4247 IT's face is restored in set_iterator_to_next.
4248 saved_face_id was set to preceding char's face in handle_stop. */
4249 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4250 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4252 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4258 /***********************************************************************
4260 ***********************************************************************/
4262 /* Set up iterator IT from `display' property at its current position.
4263 Called from handle_stop.
4264 We return HANDLED_RETURN if some part of the display property
4265 overrides the display of the buffer text itself.
4266 Otherwise we return HANDLED_NORMALLY. */
4268 static enum prop_handled
4269 handle_display_prop (struct it
*it
)
4271 Lisp_Object propval
, object
, overlay
;
4272 struct text_pos
*position
;
4274 /* Nonzero if some property replaces the display of the text itself. */
4275 int display_replaced_p
= 0;
4277 if (STRINGP (it
->string
))
4279 object
= it
->string
;
4280 position
= &it
->current
.string_pos
;
4281 bufpos
= CHARPOS (it
->current
.pos
);
4285 XSETWINDOW (object
, it
->w
);
4286 position
= &it
->current
.pos
;
4287 bufpos
= CHARPOS (*position
);
4290 /* Reset those iterator values set from display property values. */
4291 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4292 it
->space_width
= Qnil
;
4293 it
->font_height
= Qnil
;
4296 /* We don't support recursive `display' properties, i.e. string
4297 values that have a string `display' property, that have a string
4298 `display' property etc. */
4299 if (!it
->string_from_display_prop_p
)
4300 it
->area
= TEXT_AREA
;
4302 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4303 Qdisplay
, object
, &overlay
);
4305 return HANDLED_NORMALLY
;
4306 /* Now OVERLAY is the overlay that gave us this property, or nil
4307 if it was a text property. */
4309 if (!STRINGP (it
->string
))
4310 object
= it
->w
->buffer
;
4312 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4314 FRAME_WINDOW_P (it
->f
));
4316 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4319 /* Subroutine of handle_display_prop. Returns non-zero if the display
4320 specification in SPEC is a replacing specification, i.e. it would
4321 replace the text covered by `display' property with something else,
4322 such as an image or a display string. If SPEC includes any kind or
4323 `(space ...) specification, the value is 2; this is used by
4324 compute_display_string_pos, which see.
4326 See handle_single_display_spec for documentation of arguments.
4327 frame_window_p is non-zero if the window being redisplayed is on a
4328 GUI frame; this argument is used only if IT is NULL, see below.
4330 IT can be NULL, if this is called by the bidi reordering code
4331 through compute_display_string_pos, which see. In that case, this
4332 function only examines SPEC, but does not otherwise "handle" it, in
4333 the sense that it doesn't set up members of IT from the display
4336 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4337 Lisp_Object overlay
, struct text_pos
*position
,
4338 ptrdiff_t bufpos
, int frame_window_p
)
4340 int replacing_p
= 0;
4344 /* Simple specerties. */
4345 && !EQ (XCAR (spec
), Qimage
)
4346 && !EQ (XCAR (spec
), Qspace
)
4347 && !EQ (XCAR (spec
), Qwhen
)
4348 && !EQ (XCAR (spec
), Qslice
)
4349 && !EQ (XCAR (spec
), Qspace_width
)
4350 && !EQ (XCAR (spec
), Qheight
)
4351 && !EQ (XCAR (spec
), Qraise
)
4352 /* Marginal area specifications. */
4353 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4354 && !EQ (XCAR (spec
), Qleft_fringe
)
4355 && !EQ (XCAR (spec
), Qright_fringe
)
4356 && !NILP (XCAR (spec
)))
4358 for (; CONSP (spec
); spec
= XCDR (spec
))
4360 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4361 overlay
, position
, bufpos
,
4362 replacing_p
, frame_window_p
)))
4365 /* If some text in a string is replaced, `position' no
4366 longer points to the position of `object'. */
4367 if (!it
|| STRINGP (object
))
4372 else if (VECTORP (spec
))
4375 for (i
= 0; i
< ASIZE (spec
); ++i
)
4376 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4377 overlay
, position
, bufpos
,
4378 replacing_p
, frame_window_p
)))
4381 /* If some text in a string is replaced, `position' no
4382 longer points to the position of `object'. */
4383 if (!it
|| STRINGP (object
))
4389 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4390 position
, bufpos
, 0,
4398 /* Value is the position of the end of the `display' property starting
4399 at START_POS in OBJECT. */
4401 static struct text_pos
4402 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4405 struct text_pos end_pos
;
4407 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4408 Qdisplay
, object
, Qnil
);
4409 CHARPOS (end_pos
) = XFASTINT (end
);
4410 if (STRINGP (object
))
4411 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4413 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4419 /* Set up IT from a single `display' property specification SPEC. OBJECT
4420 is the object in which the `display' property was found. *POSITION
4421 is the position in OBJECT at which the `display' property was found.
4422 BUFPOS is the buffer position of OBJECT (different from POSITION if
4423 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4424 previously saw a display specification which already replaced text
4425 display with something else, for example an image; we ignore such
4426 properties after the first one has been processed.
4428 OVERLAY is the overlay this `display' property came from,
4429 or nil if it was a text property.
4431 If SPEC is a `space' or `image' specification, and in some other
4432 cases too, set *POSITION to the position where the `display'
4435 If IT is NULL, only examine the property specification in SPEC, but
4436 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4437 is intended to be displayed in a window on a GUI frame.
4439 Value is non-zero if something was found which replaces the display
4440 of buffer or string text. */
4443 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4444 Lisp_Object overlay
, struct text_pos
*position
,
4445 ptrdiff_t bufpos
, int display_replaced_p
,
4449 Lisp_Object location
, value
;
4450 struct text_pos start_pos
= *position
;
4453 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4454 If the result is non-nil, use VALUE instead of SPEC. */
4456 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4465 if (!NILP (form
) && !EQ (form
, Qt
))
4467 ptrdiff_t count
= SPECPDL_INDEX ();
4468 struct gcpro gcpro1
;
4470 /* Bind `object' to the object having the `display' property, a
4471 buffer or string. Bind `position' to the position in the
4472 object where the property was found, and `buffer-position'
4473 to the current position in the buffer. */
4476 XSETBUFFER (object
, current_buffer
);
4477 specbind (Qobject
, object
);
4478 specbind (Qposition
, make_number (CHARPOS (*position
)));
4479 specbind (Qbuffer_position
, make_number (bufpos
));
4481 form
= safe_eval (form
);
4483 unbind_to (count
, Qnil
);
4489 /* Handle `(height HEIGHT)' specifications. */
4491 && EQ (XCAR (spec
), Qheight
)
4492 && CONSP (XCDR (spec
)))
4496 if (!FRAME_WINDOW_P (it
->f
))
4499 it
->font_height
= XCAR (XCDR (spec
));
4500 if (!NILP (it
->font_height
))
4502 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4503 int new_height
= -1;
4505 if (CONSP (it
->font_height
)
4506 && (EQ (XCAR (it
->font_height
), Qplus
)
4507 || EQ (XCAR (it
->font_height
), Qminus
))
4508 && CONSP (XCDR (it
->font_height
))
4509 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4511 /* `(+ N)' or `(- N)' where N is an integer. */
4512 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4513 if (EQ (XCAR (it
->font_height
), Qplus
))
4515 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4517 else if (FUNCTIONP (it
->font_height
))
4519 /* Call function with current height as argument.
4520 Value is the new height. */
4522 height
= safe_call1 (it
->font_height
,
4523 face
->lface
[LFACE_HEIGHT_INDEX
]);
4524 if (NUMBERP (height
))
4525 new_height
= XFLOATINT (height
);
4527 else if (NUMBERP (it
->font_height
))
4529 /* Value is a multiple of the canonical char height. */
4532 f
= FACE_FROM_ID (it
->f
,
4533 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4534 new_height
= (XFLOATINT (it
->font_height
)
4535 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4539 /* Evaluate IT->font_height with `height' bound to the
4540 current specified height to get the new height. */
4541 ptrdiff_t count
= SPECPDL_INDEX ();
4543 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4544 value
= safe_eval (it
->font_height
);
4545 unbind_to (count
, Qnil
);
4547 if (NUMBERP (value
))
4548 new_height
= XFLOATINT (value
);
4552 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4559 /* Handle `(space-width WIDTH)'. */
4561 && EQ (XCAR (spec
), Qspace_width
)
4562 && CONSP (XCDR (spec
)))
4566 if (!FRAME_WINDOW_P (it
->f
))
4569 value
= XCAR (XCDR (spec
));
4570 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4571 it
->space_width
= value
;
4577 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4579 && EQ (XCAR (spec
), Qslice
))
4585 if (!FRAME_WINDOW_P (it
->f
))
4588 if (tem
= XCDR (spec
), CONSP (tem
))
4590 it
->slice
.x
= XCAR (tem
);
4591 if (tem
= XCDR (tem
), CONSP (tem
))
4593 it
->slice
.y
= XCAR (tem
);
4594 if (tem
= XCDR (tem
), CONSP (tem
))
4596 it
->slice
.width
= XCAR (tem
);
4597 if (tem
= XCDR (tem
), CONSP (tem
))
4598 it
->slice
.height
= XCAR (tem
);
4607 /* Handle `(raise FACTOR)'. */
4609 && EQ (XCAR (spec
), Qraise
)
4610 && CONSP (XCDR (spec
)))
4614 if (!FRAME_WINDOW_P (it
->f
))
4617 #ifdef HAVE_WINDOW_SYSTEM
4618 value
= XCAR (XCDR (spec
));
4619 if (NUMBERP (value
))
4621 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4622 it
->voffset
= - (XFLOATINT (value
)
4623 * (FONT_HEIGHT (face
->font
)));
4625 #endif /* HAVE_WINDOW_SYSTEM */
4631 /* Don't handle the other kinds of display specifications
4632 inside a string that we got from a `display' property. */
4633 if (it
&& it
->string_from_display_prop_p
)
4636 /* Characters having this form of property are not displayed, so
4637 we have to find the end of the property. */
4640 start_pos
= *position
;
4641 *position
= display_prop_end (it
, object
, start_pos
);
4645 /* Stop the scan at that end position--we assume that all
4646 text properties change there. */
4648 it
->stop_charpos
= position
->charpos
;
4650 /* Handle `(left-fringe BITMAP [FACE])'
4651 and `(right-fringe BITMAP [FACE])'. */
4653 && (EQ (XCAR (spec
), Qleft_fringe
)
4654 || EQ (XCAR (spec
), Qright_fringe
))
4655 && CONSP (XCDR (spec
)))
4661 if (!FRAME_WINDOW_P (it
->f
))
4662 /* If we return here, POSITION has been advanced
4663 across the text with this property. */
4666 else if (!frame_window_p
)
4669 #ifdef HAVE_WINDOW_SYSTEM
4670 value
= XCAR (XCDR (spec
));
4671 if (!SYMBOLP (value
)
4672 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4673 /* If we return here, POSITION has been advanced
4674 across the text with this property. */
4679 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4681 if (CONSP (XCDR (XCDR (spec
))))
4683 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4684 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4690 /* Save current settings of IT so that we can restore them
4691 when we are finished with the glyph property value. */
4692 push_it (it
, position
);
4694 it
->area
= TEXT_AREA
;
4695 it
->what
= IT_IMAGE
;
4696 it
->image_id
= -1; /* no image */
4697 it
->position
= start_pos
;
4698 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4699 it
->method
= GET_FROM_IMAGE
;
4700 it
->from_overlay
= Qnil
;
4701 it
->face_id
= face_id
;
4702 it
->from_disp_prop_p
= 1;
4704 /* Say that we haven't consumed the characters with
4705 `display' property yet. The call to pop_it in
4706 set_iterator_to_next will clean this up. */
4707 *position
= start_pos
;
4709 if (EQ (XCAR (spec
), Qleft_fringe
))
4711 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4712 it
->left_user_fringe_face_id
= face_id
;
4716 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4717 it
->right_user_fringe_face_id
= face_id
;
4720 #endif /* HAVE_WINDOW_SYSTEM */
4724 /* Prepare to handle `((margin left-margin) ...)',
4725 `((margin right-margin) ...)' and `((margin nil) ...)'
4726 prefixes for display specifications. */
4727 location
= Qunbound
;
4728 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4732 value
= XCDR (spec
);
4734 value
= XCAR (value
);
4737 if (EQ (XCAR (tem
), Qmargin
)
4738 && (tem
= XCDR (tem
),
4739 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4741 || EQ (tem
, Qleft_margin
)
4742 || EQ (tem
, Qright_margin
))))
4746 if (EQ (location
, Qunbound
))
4752 /* After this point, VALUE is the property after any
4753 margin prefix has been stripped. It must be a string,
4754 an image specification, or `(space ...)'.
4756 LOCATION specifies where to display: `left-margin',
4757 `right-margin' or nil. */
4759 valid_p
= (STRINGP (value
)
4760 #ifdef HAVE_WINDOW_SYSTEM
4761 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4762 && valid_image_p (value
))
4763 #endif /* not HAVE_WINDOW_SYSTEM */
4764 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4766 if (valid_p
&& !display_replaced_p
)
4772 /* Callers need to know whether the display spec is any kind
4773 of `(space ...)' spec that is about to affect text-area
4775 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4780 /* Save current settings of IT so that we can restore them
4781 when we are finished with the glyph property value. */
4782 push_it (it
, position
);
4783 it
->from_overlay
= overlay
;
4784 it
->from_disp_prop_p
= 1;
4786 if (NILP (location
))
4787 it
->area
= TEXT_AREA
;
4788 else if (EQ (location
, Qleft_margin
))
4789 it
->area
= LEFT_MARGIN_AREA
;
4791 it
->area
= RIGHT_MARGIN_AREA
;
4793 if (STRINGP (value
))
4796 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4797 it
->current
.overlay_string_index
= -1;
4798 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4799 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4800 it
->method
= GET_FROM_STRING
;
4801 it
->stop_charpos
= 0;
4803 it
->base_level_stop
= 0;
4804 it
->string_from_display_prop_p
= 1;
4805 /* Say that we haven't consumed the characters with
4806 `display' property yet. The call to pop_it in
4807 set_iterator_to_next will clean this up. */
4808 if (BUFFERP (object
))
4809 *position
= start_pos
;
4811 /* Force paragraph direction to be that of the parent
4812 object. If the parent object's paragraph direction is
4813 not yet determined, default to L2R. */
4814 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4815 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4817 it
->paragraph_embedding
= L2R
;
4819 /* Set up the bidi iterator for this display string. */
4822 it
->bidi_it
.string
.lstring
= it
->string
;
4823 it
->bidi_it
.string
.s
= NULL
;
4824 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4825 it
->bidi_it
.string
.bufpos
= bufpos
;
4826 it
->bidi_it
.string
.from_disp_str
= 1;
4827 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4828 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4831 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4833 it
->method
= GET_FROM_STRETCH
;
4835 *position
= it
->position
= start_pos
;
4836 retval
= 1 + (it
->area
== TEXT_AREA
);
4838 #ifdef HAVE_WINDOW_SYSTEM
4841 it
->what
= IT_IMAGE
;
4842 it
->image_id
= lookup_image (it
->f
, value
);
4843 it
->position
= start_pos
;
4844 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4845 it
->method
= GET_FROM_IMAGE
;
4847 /* Say that we haven't consumed the characters with
4848 `display' property yet. The call to pop_it in
4849 set_iterator_to_next will clean this up. */
4850 *position
= start_pos
;
4852 #endif /* HAVE_WINDOW_SYSTEM */
4857 /* Invalid property or property not supported. Restore
4858 POSITION to what it was before. */
4859 *position
= start_pos
;
4863 /* Check if PROP is a display property value whose text should be
4864 treated as intangible. OVERLAY is the overlay from which PROP
4865 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4866 specify the buffer position covered by PROP. */
4869 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4870 ptrdiff_t charpos
, ptrdiff_t bytepos
)
4872 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4873 struct text_pos position
;
4875 SET_TEXT_POS (position
, charpos
, bytepos
);
4876 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4877 &position
, charpos
, frame_window_p
);
4881 /* Return 1 if PROP is a display sub-property value containing STRING.
4883 Implementation note: this and the following function are really
4884 special cases of handle_display_spec and
4885 handle_single_display_spec, and should ideally use the same code.
4886 Until they do, these two pairs must be consistent and must be
4887 modified in sync. */
4890 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4892 if (EQ (string
, prop
))
4895 /* Skip over `when FORM'. */
4896 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4901 /* Actually, the condition following `when' should be eval'ed,
4902 like handle_single_display_spec does, and we should return
4903 zero if it evaluates to nil. However, this function is
4904 called only when the buffer was already displayed and some
4905 glyph in the glyph matrix was found to come from a display
4906 string. Therefore, the condition was already evaluated, and
4907 the result was non-nil, otherwise the display string wouldn't
4908 have been displayed and we would have never been called for
4909 this property. Thus, we can skip the evaluation and assume
4910 its result is non-nil. */
4915 /* Skip over `margin LOCATION'. */
4916 if (EQ (XCAR (prop
), Qmargin
))
4927 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4931 /* Return 1 if STRING appears in the `display' property PROP. */
4934 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4937 && !EQ (XCAR (prop
), Qwhen
)
4938 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4940 /* A list of sub-properties. */
4941 while (CONSP (prop
))
4943 if (single_display_spec_string_p (XCAR (prop
), string
))
4948 else if (VECTORP (prop
))
4950 /* A vector of sub-properties. */
4952 for (i
= 0; i
< ASIZE (prop
); ++i
)
4953 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4957 return single_display_spec_string_p (prop
, string
);
4962 /* Look for STRING in overlays and text properties in the current
4963 buffer, between character positions FROM and TO (excluding TO).
4964 BACK_P non-zero means look back (in this case, TO is supposed to be
4966 Value is the first character position where STRING was found, or
4967 zero if it wasn't found before hitting TO.
4969 This function may only use code that doesn't eval because it is
4970 called asynchronously from note_mouse_highlight. */
4973 string_buffer_position_lim (Lisp_Object string
,
4974 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
4976 Lisp_Object limit
, prop
, pos
;
4979 pos
= make_number (from
);
4981 if (!back_p
) /* looking forward */
4983 limit
= make_number (min (to
, ZV
));
4984 while (!found
&& !EQ (pos
, limit
))
4986 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4987 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4990 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4994 else /* looking back */
4996 limit
= make_number (max (to
, BEGV
));
4997 while (!found
&& !EQ (pos
, limit
))
4999 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5000 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5003 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5008 return found
? XINT (pos
) : 0;
5011 /* Determine which buffer position in current buffer STRING comes from.
5012 AROUND_CHARPOS is an approximate position where it could come from.
5013 Value is the buffer position or 0 if it couldn't be determined.
5015 This function is necessary because we don't record buffer positions
5016 in glyphs generated from strings (to keep struct glyph small).
5017 This function may only use code that doesn't eval because it is
5018 called asynchronously from note_mouse_highlight. */
5021 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5023 const int MAX_DISTANCE
= 1000;
5024 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5025 around_charpos
+ MAX_DISTANCE
,
5029 found
= string_buffer_position_lim (string
, around_charpos
,
5030 around_charpos
- MAX_DISTANCE
, 1);
5036 /***********************************************************************
5037 `composition' property
5038 ***********************************************************************/
5040 /* Set up iterator IT from `composition' property at its current
5041 position. Called from handle_stop. */
5043 static enum prop_handled
5044 handle_composition_prop (struct it
*it
)
5046 Lisp_Object prop
, string
;
5047 ptrdiff_t pos
, pos_byte
, start
, end
;
5049 if (STRINGP (it
->string
))
5053 pos
= IT_STRING_CHARPOS (*it
);
5054 pos_byte
= IT_STRING_BYTEPOS (*it
);
5055 string
= it
->string
;
5056 s
= SDATA (string
) + pos_byte
;
5057 it
->c
= STRING_CHAR (s
);
5061 pos
= IT_CHARPOS (*it
);
5062 pos_byte
= IT_BYTEPOS (*it
);
5064 it
->c
= FETCH_CHAR (pos_byte
);
5067 /* If there's a valid composition and point is not inside of the
5068 composition (in the case that the composition is from the current
5069 buffer), draw a glyph composed from the composition components. */
5070 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5071 && COMPOSITION_VALID_P (start
, end
, prop
)
5072 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5075 /* As we can't handle this situation (perhaps font-lock added
5076 a new composition), we just return here hoping that next
5077 redisplay will detect this composition much earlier. */
5078 return HANDLED_NORMALLY
;
5081 if (STRINGP (it
->string
))
5082 pos_byte
= string_char_to_byte (it
->string
, start
);
5084 pos_byte
= CHAR_TO_BYTE (start
);
5086 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5089 if (it
->cmp_it
.id
>= 0)
5092 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5093 it
->cmp_it
.nglyphs
= -1;
5097 return HANDLED_NORMALLY
;
5102 /***********************************************************************
5104 ***********************************************************************/
5106 /* The following structure is used to record overlay strings for
5107 later sorting in load_overlay_strings. */
5109 struct overlay_entry
5111 Lisp_Object overlay
;
5118 /* Set up iterator IT from overlay strings at its current position.
5119 Called from handle_stop. */
5121 static enum prop_handled
5122 handle_overlay_change (struct it
*it
)
5124 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5125 return HANDLED_RECOMPUTE_PROPS
;
5127 return HANDLED_NORMALLY
;
5131 /* Set up the next overlay string for delivery by IT, if there is an
5132 overlay string to deliver. Called by set_iterator_to_next when the
5133 end of the current overlay string is reached. If there are more
5134 overlay strings to display, IT->string and
5135 IT->current.overlay_string_index are set appropriately here.
5136 Otherwise IT->string is set to nil. */
5139 next_overlay_string (struct it
*it
)
5141 ++it
->current
.overlay_string_index
;
5142 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5144 /* No more overlay strings. Restore IT's settings to what
5145 they were before overlay strings were processed, and
5146 continue to deliver from current_buffer. */
5148 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5151 || (NILP (it
->string
)
5152 && it
->method
== GET_FROM_BUFFER
5153 && it
->stop_charpos
>= BEGV
5154 && it
->stop_charpos
<= it
->end_charpos
));
5155 it
->current
.overlay_string_index
= -1;
5156 it
->n_overlay_strings
= 0;
5157 it
->overlay_strings_charpos
= -1;
5159 /* If we're at the end of the buffer, record that we have
5160 processed the overlay strings there already, so that
5161 next_element_from_buffer doesn't try it again. */
5162 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5163 it
->overlay_strings_at_end_processed_p
= 1;
5167 /* There are more overlay strings to process. If
5168 IT->current.overlay_string_index has advanced to a position
5169 where we must load IT->overlay_strings with more strings, do
5170 it. We must load at the IT->overlay_strings_charpos where
5171 IT->n_overlay_strings was originally computed; when invisible
5172 text is present, this might not be IT_CHARPOS (Bug#7016). */
5173 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5175 if (it
->current
.overlay_string_index
&& i
== 0)
5176 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5178 /* Initialize IT to deliver display elements from the overlay
5180 it
->string
= it
->overlay_strings
[i
];
5181 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5182 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5183 it
->method
= GET_FROM_STRING
;
5184 it
->stop_charpos
= 0;
5185 if (it
->cmp_it
.stop_pos
>= 0)
5186 it
->cmp_it
.stop_pos
= 0;
5188 it
->base_level_stop
= 0;
5190 /* Set up the bidi iterator for this overlay string. */
5193 it
->bidi_it
.string
.lstring
= it
->string
;
5194 it
->bidi_it
.string
.s
= NULL
;
5195 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5196 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5197 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5198 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5199 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5207 /* Compare two overlay_entry structures E1 and E2. Used as a
5208 comparison function for qsort in load_overlay_strings. Overlay
5209 strings for the same position are sorted so that
5211 1. All after-strings come in front of before-strings, except
5212 when they come from the same overlay.
5214 2. Within after-strings, strings are sorted so that overlay strings
5215 from overlays with higher priorities come first.
5217 2. Within before-strings, strings are sorted so that overlay
5218 strings from overlays with higher priorities come last.
5220 Value is analogous to strcmp. */
5224 compare_overlay_entries (const void *e1
, const void *e2
)
5226 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5227 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5230 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5232 /* Let after-strings appear in front of before-strings if
5233 they come from different overlays. */
5234 if (EQ (entry1
->overlay
, entry2
->overlay
))
5235 result
= entry1
->after_string_p
? 1 : -1;
5237 result
= entry1
->after_string_p
? -1 : 1;
5239 else if (entry1
->priority
!= entry2
->priority
)
5241 if (entry1
->after_string_p
)
5242 /* After-strings sorted in order of decreasing priority. */
5243 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5245 /* Before-strings sorted in order of increasing priority. */
5246 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5255 /* Load the vector IT->overlay_strings with overlay strings from IT's
5256 current buffer position, or from CHARPOS if that is > 0. Set
5257 IT->n_overlays to the total number of overlay strings found.
5259 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5260 a time. On entry into load_overlay_strings,
5261 IT->current.overlay_string_index gives the number of overlay
5262 strings that have already been loaded by previous calls to this
5265 IT->add_overlay_start contains an additional overlay start
5266 position to consider for taking overlay strings from, if non-zero.
5267 This position comes into play when the overlay has an `invisible'
5268 property, and both before and after-strings. When we've skipped to
5269 the end of the overlay, because of its `invisible' property, we
5270 nevertheless want its before-string to appear.
5271 IT->add_overlay_start will contain the overlay start position
5274 Overlay strings are sorted so that after-string strings come in
5275 front of before-string strings. Within before and after-strings,
5276 strings are sorted by overlay priority. See also function
5277 compare_overlay_entries. */
5280 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5282 Lisp_Object overlay
, window
, str
, invisible
;
5283 struct Lisp_Overlay
*ov
;
5284 ptrdiff_t start
, end
;
5285 ptrdiff_t size
= 20;
5286 ptrdiff_t n
= 0, i
, j
;
5288 struct overlay_entry
*entries
5289 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5293 charpos
= IT_CHARPOS (*it
);
5295 /* Append the overlay string STRING of overlay OVERLAY to vector
5296 `entries' which has size `size' and currently contains `n'
5297 elements. AFTER_P non-zero means STRING is an after-string of
5299 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5302 Lisp_Object priority; \
5306 struct overlay_entry *old = entries; \
5307 SAFE_NALLOCA (entries, 2, size); \
5308 memcpy (entries, old, size * sizeof *entries); \
5312 entries[n].string = (STRING); \
5313 entries[n].overlay = (OVERLAY); \
5314 priority = Foverlay_get ((OVERLAY), Qpriority); \
5315 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5316 entries[n].after_string_p = (AFTER_P); \
5321 /* Process overlay before the overlay center. */
5322 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5324 XSETMISC (overlay
, ov
);
5325 xassert (OVERLAYP (overlay
));
5326 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5327 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5332 /* Skip this overlay if it doesn't start or end at IT's current
5334 if (end
!= charpos
&& start
!= charpos
)
5337 /* Skip this overlay if it doesn't apply to IT->w. */
5338 window
= Foverlay_get (overlay
, Qwindow
);
5339 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5342 /* If the text ``under'' the overlay is invisible, both before-
5343 and after-strings from this overlay are visible; start and
5344 end position are indistinguishable. */
5345 invisible
= Foverlay_get (overlay
, Qinvisible
);
5346 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5348 /* If overlay has a non-empty before-string, record it. */
5349 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5350 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5352 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5354 /* If overlay has a non-empty after-string, record it. */
5355 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5356 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5358 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5361 /* Process overlays after the overlay center. */
5362 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5364 XSETMISC (overlay
, ov
);
5365 xassert (OVERLAYP (overlay
));
5366 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5367 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5369 if (start
> charpos
)
5372 /* Skip this overlay if it doesn't start or end at IT's current
5374 if (end
!= charpos
&& start
!= charpos
)
5377 /* Skip this overlay if it doesn't apply to IT->w. */
5378 window
= Foverlay_get (overlay
, Qwindow
);
5379 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5382 /* If the text ``under'' the overlay is invisible, it has a zero
5383 dimension, and both before- and after-strings apply. */
5384 invisible
= Foverlay_get (overlay
, Qinvisible
);
5385 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5387 /* If overlay has a non-empty before-string, record it. */
5388 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5389 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5391 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5393 /* If overlay has a non-empty after-string, record it. */
5394 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5395 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5397 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5400 #undef RECORD_OVERLAY_STRING
5404 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5406 /* Record number of overlay strings, and where we computed it. */
5407 it
->n_overlay_strings
= n
;
5408 it
->overlay_strings_charpos
= charpos
;
5410 /* IT->current.overlay_string_index is the number of overlay strings
5411 that have already been consumed by IT. Copy some of the
5412 remaining overlay strings to IT->overlay_strings. */
5414 j
= it
->current
.overlay_string_index
;
5415 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5417 it
->overlay_strings
[i
] = entries
[j
].string
;
5418 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5426 /* Get the first chunk of overlay strings at IT's current buffer
5427 position, or at CHARPOS if that is > 0. Value is non-zero if at
5428 least one overlay string was found. */
5431 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5433 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5434 process. This fills IT->overlay_strings with strings, and sets
5435 IT->n_overlay_strings to the total number of strings to process.
5436 IT->pos.overlay_string_index has to be set temporarily to zero
5437 because load_overlay_strings needs this; it must be set to -1
5438 when no overlay strings are found because a zero value would
5439 indicate a position in the first overlay string. */
5440 it
->current
.overlay_string_index
= 0;
5441 load_overlay_strings (it
, charpos
);
5443 /* If we found overlay strings, set up IT to deliver display
5444 elements from the first one. Otherwise set up IT to deliver
5445 from current_buffer. */
5446 if (it
->n_overlay_strings
)
5448 /* Make sure we know settings in current_buffer, so that we can
5449 restore meaningful values when we're done with the overlay
5452 compute_stop_pos (it
);
5453 xassert (it
->face_id
>= 0);
5455 /* Save IT's settings. They are restored after all overlay
5456 strings have been processed. */
5457 xassert (!compute_stop_p
|| it
->sp
== 0);
5459 /* When called from handle_stop, there might be an empty display
5460 string loaded. In that case, don't bother saving it. */
5461 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5464 /* Set up IT to deliver display elements from the first overlay
5466 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5467 it
->string
= it
->overlay_strings
[0];
5468 it
->from_overlay
= Qnil
;
5469 it
->stop_charpos
= 0;
5470 xassert (STRINGP (it
->string
));
5471 it
->end_charpos
= SCHARS (it
->string
);
5473 it
->base_level_stop
= 0;
5474 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5475 it
->method
= GET_FROM_STRING
;
5476 it
->from_disp_prop_p
= 0;
5478 /* Force paragraph direction to be that of the parent
5480 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5481 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5483 it
->paragraph_embedding
= L2R
;
5485 /* Set up the bidi iterator for this overlay string. */
5488 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5490 it
->bidi_it
.string
.lstring
= it
->string
;
5491 it
->bidi_it
.string
.s
= NULL
;
5492 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5493 it
->bidi_it
.string
.bufpos
= pos
;
5494 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5495 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5496 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5501 it
->current
.overlay_string_index
= -1;
5506 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5509 it
->method
= GET_FROM_BUFFER
;
5511 (void) get_overlay_strings_1 (it
, charpos
, 1);
5515 /* Value is non-zero if we found at least one overlay string. */
5516 return STRINGP (it
->string
);
5521 /***********************************************************************
5522 Saving and restoring state
5523 ***********************************************************************/
5525 /* Save current settings of IT on IT->stack. Called, for example,
5526 before setting up IT for an overlay string, to be able to restore
5527 IT's settings to what they were after the overlay string has been
5528 processed. If POSITION is non-NULL, it is the position to save on
5529 the stack instead of IT->position. */
5532 push_it (struct it
*it
, struct text_pos
*position
)
5534 struct iterator_stack_entry
*p
;
5536 xassert (it
->sp
< IT_STACK_SIZE
);
5537 p
= it
->stack
+ it
->sp
;
5539 p
->stop_charpos
= it
->stop_charpos
;
5540 p
->prev_stop
= it
->prev_stop
;
5541 p
->base_level_stop
= it
->base_level_stop
;
5542 p
->cmp_it
= it
->cmp_it
;
5543 xassert (it
->face_id
>= 0);
5544 p
->face_id
= it
->face_id
;
5545 p
->string
= it
->string
;
5546 p
->method
= it
->method
;
5547 p
->from_overlay
= it
->from_overlay
;
5550 case GET_FROM_IMAGE
:
5551 p
->u
.image
.object
= it
->object
;
5552 p
->u
.image
.image_id
= it
->image_id
;
5553 p
->u
.image
.slice
= it
->slice
;
5555 case GET_FROM_STRETCH
:
5556 p
->u
.stretch
.object
= it
->object
;
5559 p
->position
= position
? *position
: it
->position
;
5560 p
->current
= it
->current
;
5561 p
->end_charpos
= it
->end_charpos
;
5562 p
->string_nchars
= it
->string_nchars
;
5564 p
->multibyte_p
= it
->multibyte_p
;
5565 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5566 p
->space_width
= it
->space_width
;
5567 p
->font_height
= it
->font_height
;
5568 p
->voffset
= it
->voffset
;
5569 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5570 p
->display_ellipsis_p
= 0;
5571 p
->line_wrap
= it
->line_wrap
;
5572 p
->bidi_p
= it
->bidi_p
;
5573 p
->paragraph_embedding
= it
->paragraph_embedding
;
5574 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5577 /* Save the state of the bidi iterator as well. */
5579 bidi_push_it (&it
->bidi_it
);
5583 iterate_out_of_display_property (struct it
*it
)
5585 int buffer_p
= BUFFERP (it
->object
);
5586 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5587 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5589 xassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5591 /* Maybe initialize paragraph direction. If we are at the beginning
5592 of a new paragraph, next_element_from_buffer may not have a
5593 chance to do that. */
5594 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5595 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5596 /* prev_stop can be zero, so check against BEGV as well. */
5597 while (it
->bidi_it
.charpos
>= bob
5598 && it
->prev_stop
<= it
->bidi_it
.charpos
5599 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5600 && it
->bidi_it
.charpos
< eob
)
5601 bidi_move_to_visually_next (&it
->bidi_it
);
5602 /* Record the stop_pos we just crossed, for when we cross it
5604 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5605 it
->prev_stop
= CHARPOS (it
->position
);
5606 /* If we ended up not where pop_it put us, resync IT's
5607 positional members with the bidi iterator. */
5608 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5609 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5611 it
->current
.pos
= it
->position
;
5613 it
->current
.string_pos
= it
->position
;
5616 /* Restore IT's settings from IT->stack. Called, for example, when no
5617 more overlay strings must be processed, and we return to delivering
5618 display elements from a buffer, or when the end of a string from a
5619 `display' property is reached and we return to delivering display
5620 elements from an overlay string, or from a buffer. */
5623 pop_it (struct it
*it
)
5625 struct iterator_stack_entry
*p
;
5626 int from_display_prop
= it
->from_disp_prop_p
;
5628 xassert (it
->sp
> 0);
5630 p
= it
->stack
+ it
->sp
;
5631 it
->stop_charpos
= p
->stop_charpos
;
5632 it
->prev_stop
= p
->prev_stop
;
5633 it
->base_level_stop
= p
->base_level_stop
;
5634 it
->cmp_it
= p
->cmp_it
;
5635 it
->face_id
= p
->face_id
;
5636 it
->current
= p
->current
;
5637 it
->position
= p
->position
;
5638 it
->string
= p
->string
;
5639 it
->from_overlay
= p
->from_overlay
;
5640 if (NILP (it
->string
))
5641 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5642 it
->method
= p
->method
;
5645 case GET_FROM_IMAGE
:
5646 it
->image_id
= p
->u
.image
.image_id
;
5647 it
->object
= p
->u
.image
.object
;
5648 it
->slice
= p
->u
.image
.slice
;
5650 case GET_FROM_STRETCH
:
5651 it
->object
= p
->u
.stretch
.object
;
5653 case GET_FROM_BUFFER
:
5654 it
->object
= it
->w
->buffer
;
5656 case GET_FROM_STRING
:
5657 it
->object
= it
->string
;
5659 case GET_FROM_DISPLAY_VECTOR
:
5661 it
->method
= GET_FROM_C_STRING
;
5662 else if (STRINGP (it
->string
))
5663 it
->method
= GET_FROM_STRING
;
5666 it
->method
= GET_FROM_BUFFER
;
5667 it
->object
= it
->w
->buffer
;
5670 it
->end_charpos
= p
->end_charpos
;
5671 it
->string_nchars
= p
->string_nchars
;
5673 it
->multibyte_p
= p
->multibyte_p
;
5674 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5675 it
->space_width
= p
->space_width
;
5676 it
->font_height
= p
->font_height
;
5677 it
->voffset
= p
->voffset
;
5678 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5679 it
->line_wrap
= p
->line_wrap
;
5680 it
->bidi_p
= p
->bidi_p
;
5681 it
->paragraph_embedding
= p
->paragraph_embedding
;
5682 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5685 bidi_pop_it (&it
->bidi_it
);
5686 /* Bidi-iterate until we get out of the portion of text, if any,
5687 covered by a `display' text property or by an overlay with
5688 `display' property. (We cannot just jump there, because the
5689 internal coherency of the bidi iterator state can not be
5690 preserved across such jumps.) We also must determine the
5691 paragraph base direction if the overlay we just processed is
5692 at the beginning of a new paragraph. */
5693 if (from_display_prop
5694 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5695 iterate_out_of_display_property (it
);
5697 xassert ((BUFFERP (it
->object
)
5698 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5699 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5700 || (STRINGP (it
->object
)
5701 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5702 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5703 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5709 /***********************************************************************
5711 ***********************************************************************/
5713 /* Set IT's current position to the previous line start. */
5716 back_to_previous_line_start (struct it
*it
)
5718 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5719 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5723 /* Move IT to the next line start.
5725 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5726 we skipped over part of the text (as opposed to moving the iterator
5727 continuously over the text). Otherwise, don't change the value
5730 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5731 iterator on the newline, if it was found.
5733 Newlines may come from buffer text, overlay strings, or strings
5734 displayed via the `display' property. That's the reason we can't
5735 simply use find_next_newline_no_quit.
5737 Note that this function may not skip over invisible text that is so
5738 because of text properties and immediately follows a newline. If
5739 it would, function reseat_at_next_visible_line_start, when called
5740 from set_iterator_to_next, would effectively make invisible
5741 characters following a newline part of the wrong glyph row, which
5742 leads to wrong cursor motion. */
5745 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5746 struct bidi_it
*bidi_it_prev
)
5748 ptrdiff_t old_selective
;
5749 int newline_found_p
, n
;
5750 const int MAX_NEWLINE_DISTANCE
= 500;
5752 /* If already on a newline, just consume it to avoid unintended
5753 skipping over invisible text below. */
5754 if (it
->what
== IT_CHARACTER
5756 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5758 if (it
->bidi_p
&& bidi_it_prev
)
5759 *bidi_it_prev
= it
->bidi_it
;
5760 set_iterator_to_next (it
, 0);
5765 /* Don't handle selective display in the following. It's (a)
5766 unnecessary because it's done by the caller, and (b) leads to an
5767 infinite recursion because next_element_from_ellipsis indirectly
5768 calls this function. */
5769 old_selective
= it
->selective
;
5772 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5773 from buffer text. */
5774 for (n
= newline_found_p
= 0;
5775 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5776 n
+= STRINGP (it
->string
) ? 0 : 1)
5778 if (!get_next_display_element (it
))
5780 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5781 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5782 *bidi_it_prev
= it
->bidi_it
;
5783 set_iterator_to_next (it
, 0);
5786 /* If we didn't find a newline near enough, see if we can use a
5788 if (!newline_found_p
)
5790 ptrdiff_t start
= IT_CHARPOS (*it
);
5791 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5794 xassert (!STRINGP (it
->string
));
5796 /* If there isn't any `display' property in sight, and no
5797 overlays, we can just use the position of the newline in
5799 if (it
->stop_charpos
>= limit
5800 || ((pos
= Fnext_single_property_change (make_number (start
),
5802 make_number (limit
)),
5804 && next_overlay_change (start
) == ZV
))
5808 IT_CHARPOS (*it
) = limit
;
5809 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5813 struct bidi_it bprev
;
5815 /* Help bidi.c avoid expensive searches for display
5816 properties and overlays, by telling it that there are
5817 none up to `limit'. */
5818 if (it
->bidi_it
.disp_pos
< limit
)
5820 it
->bidi_it
.disp_pos
= limit
;
5821 it
->bidi_it
.disp_prop
= 0;
5824 bprev
= it
->bidi_it
;
5825 bidi_move_to_visually_next (&it
->bidi_it
);
5826 } while (it
->bidi_it
.charpos
!= limit
);
5827 IT_CHARPOS (*it
) = limit
;
5828 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5830 *bidi_it_prev
= bprev
;
5832 *skipped_p
= newline_found_p
= 1;
5836 while (get_next_display_element (it
)
5837 && !newline_found_p
)
5839 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5840 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5841 *bidi_it_prev
= it
->bidi_it
;
5842 set_iterator_to_next (it
, 0);
5847 it
->selective
= old_selective
;
5848 return newline_found_p
;
5852 /* Set IT's current position to the previous visible line start. Skip
5853 invisible text that is so either due to text properties or due to
5854 selective display. Caution: this does not change IT->current_x and
5858 back_to_previous_visible_line_start (struct it
*it
)
5860 while (IT_CHARPOS (*it
) > BEGV
)
5862 back_to_previous_line_start (it
);
5864 if (IT_CHARPOS (*it
) <= BEGV
)
5867 /* If selective > 0, then lines indented more than its value are
5869 if (it
->selective
> 0
5870 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5874 /* Check the newline before point for invisibility. */
5877 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5878 Qinvisible
, it
->window
);
5879 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5883 if (IT_CHARPOS (*it
) <= BEGV
)
5888 void *it2data
= NULL
;
5891 Lisp_Object val
, overlay
;
5893 SAVE_IT (it2
, *it
, it2data
);
5895 /* If newline is part of a composition, continue from start of composition */
5896 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5897 && beg
< IT_CHARPOS (*it
))
5900 /* If newline is replaced by a display property, find start of overlay
5901 or interval and continue search from that point. */
5902 pos
= --IT_CHARPOS (it2
);
5905 bidi_unshelve_cache (NULL
, 0);
5906 it2
.string_from_display_prop_p
= 0;
5907 it2
.from_disp_prop_p
= 0;
5908 if (handle_display_prop (&it2
) == HANDLED_RETURN
5909 && !NILP (val
= get_char_property_and_overlay
5910 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5911 && (OVERLAYP (overlay
)
5912 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5913 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5915 RESTORE_IT (it
, it
, it2data
);
5919 /* Newline is not replaced by anything -- so we are done. */
5920 RESTORE_IT (it
, it
, it2data
);
5926 IT_CHARPOS (*it
) = beg
;
5927 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5931 it
->continuation_lines_width
= 0;
5933 xassert (IT_CHARPOS (*it
) >= BEGV
);
5934 xassert (IT_CHARPOS (*it
) == BEGV
5935 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5940 /* Reseat iterator IT at the previous visible line start. Skip
5941 invisible text that is so either due to text properties or due to
5942 selective display. At the end, update IT's overlay information,
5943 face information etc. */
5946 reseat_at_previous_visible_line_start (struct it
*it
)
5948 back_to_previous_visible_line_start (it
);
5949 reseat (it
, it
->current
.pos
, 1);
5954 /* Reseat iterator IT on the next visible line start in the current
5955 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5956 preceding the line start. Skip over invisible text that is so
5957 because of selective display. Compute faces, overlays etc at the
5958 new position. Note that this function does not skip over text that
5959 is invisible because of text properties. */
5962 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5964 int newline_found_p
, skipped_p
= 0;
5965 struct bidi_it bidi_it_prev
;
5967 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
5969 /* Skip over lines that are invisible because they are indented
5970 more than the value of IT->selective. */
5971 if (it
->selective
> 0)
5972 while (IT_CHARPOS (*it
) < ZV
5973 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5976 xassert (IT_BYTEPOS (*it
) == BEGV
5977 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5979 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
5982 /* Position on the newline if that's what's requested. */
5983 if (on_newline_p
&& newline_found_p
)
5985 if (STRINGP (it
->string
))
5987 if (IT_STRING_CHARPOS (*it
) > 0)
5991 --IT_STRING_CHARPOS (*it
);
5992 --IT_STRING_BYTEPOS (*it
);
5996 /* We need to restore the bidi iterator to the state
5997 it had on the newline, and resync the IT's
5998 position with that. */
5999 it
->bidi_it
= bidi_it_prev
;
6000 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6001 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6005 else if (IT_CHARPOS (*it
) > BEGV
)
6014 /* We need to restore the bidi iterator to the state it
6015 had on the newline and resync IT with that. */
6016 it
->bidi_it
= bidi_it_prev
;
6017 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6018 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6020 reseat (it
, it
->current
.pos
, 0);
6024 reseat (it
, it
->current
.pos
, 0);
6031 /***********************************************************************
6032 Changing an iterator's position
6033 ***********************************************************************/
6035 /* Change IT's current position to POS in current_buffer. If FORCE_P
6036 is non-zero, always check for text properties at the new position.
6037 Otherwise, text properties are only looked up if POS >=
6038 IT->check_charpos of a property. */
6041 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6043 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6045 reseat_1 (it
, pos
, 0);
6047 /* Determine where to check text properties. Avoid doing it
6048 where possible because text property lookup is very expensive. */
6050 || CHARPOS (pos
) > it
->stop_charpos
6051 || CHARPOS (pos
) < original_pos
)
6055 /* For bidi iteration, we need to prime prev_stop and
6056 base_level_stop with our best estimations. */
6057 /* Implementation note: Of course, POS is not necessarily a
6058 stop position, so assigning prev_pos to it is a lie; we
6059 should have called compute_stop_backwards. However, if
6060 the current buffer does not include any R2L characters,
6061 that call would be a waste of cycles, because the
6062 iterator will never move back, and thus never cross this
6063 "fake" stop position. So we delay that backward search
6064 until the time we really need it, in next_element_from_buffer. */
6065 if (CHARPOS (pos
) != it
->prev_stop
)
6066 it
->prev_stop
= CHARPOS (pos
);
6067 if (CHARPOS (pos
) < it
->base_level_stop
)
6068 it
->base_level_stop
= 0; /* meaning it's unknown */
6074 it
->prev_stop
= it
->base_level_stop
= 0;
6083 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6084 IT->stop_pos to POS, also. */
6087 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6089 /* Don't call this function when scanning a C string. */
6090 xassert (it
->s
== NULL
);
6092 /* POS must be a reasonable value. */
6093 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6095 it
->current
.pos
= it
->position
= pos
;
6096 it
->end_charpos
= ZV
;
6098 it
->current
.dpvec_index
= -1;
6099 it
->current
.overlay_string_index
= -1;
6100 IT_STRING_CHARPOS (*it
) = -1;
6101 IT_STRING_BYTEPOS (*it
) = -1;
6103 it
->method
= GET_FROM_BUFFER
;
6104 it
->object
= it
->w
->buffer
;
6105 it
->area
= TEXT_AREA
;
6106 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6108 it
->string_from_display_prop_p
= 0;
6109 it
->from_disp_prop_p
= 0;
6110 it
->face_before_selective_p
= 0;
6113 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6115 bidi_unshelve_cache (NULL
, 0);
6116 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6117 it
->bidi_it
.string
.s
= NULL
;
6118 it
->bidi_it
.string
.lstring
= Qnil
;
6119 it
->bidi_it
.string
.bufpos
= 0;
6120 it
->bidi_it
.string
.unibyte
= 0;
6125 it
->stop_charpos
= CHARPOS (pos
);
6126 it
->base_level_stop
= CHARPOS (pos
);
6131 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6132 If S is non-null, it is a C string to iterate over. Otherwise,
6133 STRING gives a Lisp string to iterate over.
6135 If PRECISION > 0, don't return more then PRECISION number of
6136 characters from the string.
6138 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6139 characters have been returned. FIELD_WIDTH < 0 means an infinite
6142 MULTIBYTE = 0 means disable processing of multibyte characters,
6143 MULTIBYTE > 0 means enable it,
6144 MULTIBYTE < 0 means use IT->multibyte_p.
6146 IT must be initialized via a prior call to init_iterator before
6147 calling this function. */
6150 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6151 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6154 /* No region in strings. */
6155 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6157 /* No text property checks performed by default, but see below. */
6158 it
->stop_charpos
= -1;
6160 /* Set iterator position and end position. */
6161 memset (&it
->current
, 0, sizeof it
->current
);
6162 it
->current
.overlay_string_index
= -1;
6163 it
->current
.dpvec_index
= -1;
6164 xassert (charpos
>= 0);
6166 /* If STRING is specified, use its multibyteness, otherwise use the
6167 setting of MULTIBYTE, if specified. */
6169 it
->multibyte_p
= multibyte
> 0;
6171 /* Bidirectional reordering of strings is controlled by the default
6172 value of bidi-display-reordering. Don't try to reorder while
6173 loading loadup.el, as the necessary character property tables are
6174 not yet available. */
6177 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6181 xassert (STRINGP (string
));
6182 it
->string
= string
;
6184 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6185 it
->method
= GET_FROM_STRING
;
6186 it
->current
.string_pos
= string_pos (charpos
, string
);
6190 it
->bidi_it
.string
.lstring
= string
;
6191 it
->bidi_it
.string
.s
= NULL
;
6192 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6193 it
->bidi_it
.string
.bufpos
= 0;
6194 it
->bidi_it
.string
.from_disp_str
= 0;
6195 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6196 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6197 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6202 it
->s
= (const unsigned char *) s
;
6205 /* Note that we use IT->current.pos, not it->current.string_pos,
6206 for displaying C strings. */
6207 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6208 if (it
->multibyte_p
)
6210 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6211 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6215 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6216 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6221 it
->bidi_it
.string
.lstring
= Qnil
;
6222 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6223 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6224 it
->bidi_it
.string
.bufpos
= 0;
6225 it
->bidi_it
.string
.from_disp_str
= 0;
6226 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6227 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6230 it
->method
= GET_FROM_C_STRING
;
6233 /* PRECISION > 0 means don't return more than PRECISION characters
6235 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6237 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6239 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6242 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6243 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6244 FIELD_WIDTH < 0 means infinite field width. This is useful for
6245 padding with `-' at the end of a mode line. */
6246 if (field_width
< 0)
6247 field_width
= INFINITY
;
6248 /* Implementation note: We deliberately don't enlarge
6249 it->bidi_it.string.schars here to fit it->end_charpos, because
6250 the bidi iterator cannot produce characters out of thin air. */
6251 if (field_width
> it
->end_charpos
- charpos
)
6252 it
->end_charpos
= charpos
+ field_width
;
6254 /* Use the standard display table for displaying strings. */
6255 if (DISP_TABLE_P (Vstandard_display_table
))
6256 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6258 it
->stop_charpos
= charpos
;
6259 it
->prev_stop
= charpos
;
6260 it
->base_level_stop
= 0;
6263 it
->bidi_it
.first_elt
= 1;
6264 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6265 it
->bidi_it
.disp_pos
= -1;
6267 if (s
== NULL
&& it
->multibyte_p
)
6269 ptrdiff_t endpos
= SCHARS (it
->string
);
6270 if (endpos
> it
->end_charpos
)
6271 endpos
= it
->end_charpos
;
6272 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6280 /***********************************************************************
6282 ***********************************************************************/
6284 /* Map enum it_method value to corresponding next_element_from_* function. */
6286 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6288 next_element_from_buffer
,
6289 next_element_from_display_vector
,
6290 next_element_from_string
,
6291 next_element_from_c_string
,
6292 next_element_from_image
,
6293 next_element_from_stretch
6296 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6299 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6300 (possibly with the following characters). */
6302 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6303 ((IT)->cmp_it.id >= 0 \
6304 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6305 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6306 END_CHARPOS, (IT)->w, \
6307 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6311 /* Lookup the char-table Vglyphless_char_display for character C (-1
6312 if we want information for no-font case), and return the display
6313 method symbol. By side-effect, update it->what and
6314 it->glyphless_method. This function is called from
6315 get_next_display_element for each character element, and from
6316 x_produce_glyphs when no suitable font was found. */
6319 lookup_glyphless_char_display (int c
, struct it
*it
)
6321 Lisp_Object glyphless_method
= Qnil
;
6323 if (CHAR_TABLE_P (Vglyphless_char_display
)
6324 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6328 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6329 if (CONSP (glyphless_method
))
6330 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6331 ? XCAR (glyphless_method
)
6332 : XCDR (glyphless_method
);
6335 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6339 if (NILP (glyphless_method
))
6342 /* The default is to display the character by a proper font. */
6344 /* The default for the no-font case is to display an empty box. */
6345 glyphless_method
= Qempty_box
;
6347 if (EQ (glyphless_method
, Qzero_width
))
6350 return glyphless_method
;
6351 /* This method can't be used for the no-font case. */
6352 glyphless_method
= Qempty_box
;
6354 if (EQ (glyphless_method
, Qthin_space
))
6355 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6356 else if (EQ (glyphless_method
, Qempty_box
))
6357 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6358 else if (EQ (glyphless_method
, Qhex_code
))
6359 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6360 else if (STRINGP (glyphless_method
))
6361 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6364 /* Invalid value. We use the default method. */
6365 glyphless_method
= Qnil
;
6368 it
->what
= IT_GLYPHLESS
;
6369 return glyphless_method
;
6372 /* Load IT's display element fields with information about the next
6373 display element from the current position of IT. Value is zero if
6374 end of buffer (or C string) is reached. */
6376 static struct frame
*last_escape_glyph_frame
= NULL
;
6377 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6378 static int last_escape_glyph_merged_face_id
= 0;
6380 struct frame
*last_glyphless_glyph_frame
= NULL
;
6381 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6382 int last_glyphless_glyph_merged_face_id
= 0;
6385 get_next_display_element (struct it
*it
)
6387 /* Non-zero means that we found a display element. Zero means that
6388 we hit the end of what we iterate over. Performance note: the
6389 function pointer `method' used here turns out to be faster than
6390 using a sequence of if-statements. */
6394 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6396 if (it
->what
== IT_CHARACTER
)
6398 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6399 and only if (a) the resolved directionality of that character
6401 /* FIXME: Do we need an exception for characters from display
6403 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6404 it
->c
= bidi_mirror_char (it
->c
);
6405 /* Map via display table or translate control characters.
6406 IT->c, IT->len etc. have been set to the next character by
6407 the function call above. If we have a display table, and it
6408 contains an entry for IT->c, translate it. Don't do this if
6409 IT->c itself comes from a display table, otherwise we could
6410 end up in an infinite recursion. (An alternative could be to
6411 count the recursion depth of this function and signal an
6412 error when a certain maximum depth is reached.) Is it worth
6414 if (success_p
&& it
->dpvec
== NULL
)
6417 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6418 int nonascii_space_p
= 0;
6419 int nonascii_hyphen_p
= 0;
6420 int c
= it
->c
; /* This is the character to display. */
6422 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6424 xassert (SINGLE_BYTE_CHAR_P (c
));
6425 if (unibyte_display_via_language_environment
)
6427 c
= DECODE_CHAR (unibyte
, c
);
6429 c
= BYTE8_TO_CHAR (it
->c
);
6432 c
= BYTE8_TO_CHAR (it
->c
);
6436 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6439 struct Lisp_Vector
*v
= XVECTOR (dv
);
6441 /* Return the first character from the display table
6442 entry, if not empty. If empty, don't display the
6443 current character. */
6446 it
->dpvec_char_len
= it
->len
;
6447 it
->dpvec
= v
->contents
;
6448 it
->dpend
= v
->contents
+ v
->header
.size
;
6449 it
->current
.dpvec_index
= 0;
6450 it
->dpvec_face_id
= -1;
6451 it
->saved_face_id
= it
->face_id
;
6452 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6457 set_iterator_to_next (it
, 0);
6462 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6464 if (it
->what
== IT_GLYPHLESS
)
6466 /* Don't display this character. */
6467 set_iterator_to_next (it
, 0);
6471 /* If `nobreak-char-display' is non-nil, we display
6472 non-ASCII spaces and hyphens specially. */
6473 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6476 nonascii_space_p
= 1;
6477 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6478 nonascii_hyphen_p
= 1;
6481 /* Translate control characters into `\003' or `^C' form.
6482 Control characters coming from a display table entry are
6483 currently not translated because we use IT->dpvec to hold
6484 the translation. This could easily be changed but I
6485 don't believe that it is worth doing.
6487 The characters handled by `nobreak-char-display' must be
6490 Non-printable characters and raw-byte characters are also
6491 translated to octal form. */
6492 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6493 ? (it
->area
!= TEXT_AREA
6494 /* In mode line, treat \n, \t like other crl chars. */
6497 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6498 || (c
!= '\n' && c
!= '\t'))
6500 || nonascii_hyphen_p
6502 || ! CHAR_PRINTABLE_P (c
))))
6504 /* C is a control character, non-ASCII space/hyphen,
6505 raw-byte, or a non-printable character which must be
6506 displayed either as '\003' or as `^C' where the '\\'
6507 and '^' can be defined in the display table. Fill
6508 IT->ctl_chars with glyphs for what we have to
6509 display. Then, set IT->dpvec to these glyphs. */
6516 /* Handle control characters with ^. */
6518 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6522 g
= '^'; /* default glyph for Control */
6523 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6525 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6527 g
= GLYPH_CODE_CHAR (gc
);
6528 lface_id
= GLYPH_CODE_FACE (gc
);
6532 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6534 else if (it
->f
== last_escape_glyph_frame
6535 && it
->face_id
== last_escape_glyph_face_id
)
6537 face_id
= last_escape_glyph_merged_face_id
;
6541 /* Merge the escape-glyph face into the current face. */
6542 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6544 last_escape_glyph_frame
= it
->f
;
6545 last_escape_glyph_face_id
= it
->face_id
;
6546 last_escape_glyph_merged_face_id
= face_id
;
6549 XSETINT (it
->ctl_chars
[0], g
);
6550 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6552 goto display_control
;
6555 /* Handle non-ascii space in the mode where it only gets
6558 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6560 /* Merge `nobreak-space' into the current face. */
6561 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6563 XSETINT (it
->ctl_chars
[0], ' ');
6565 goto display_control
;
6568 /* Handle sequences that start with the "escape glyph". */
6570 /* the default escape glyph is \. */
6571 escape_glyph
= '\\';
6574 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6576 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6577 lface_id
= GLYPH_CODE_FACE (gc
);
6581 /* The display table specified a face.
6582 Merge it into face_id and also into escape_glyph. */
6583 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6586 else if (it
->f
== last_escape_glyph_frame
6587 && it
->face_id
== last_escape_glyph_face_id
)
6589 face_id
= last_escape_glyph_merged_face_id
;
6593 /* Merge the escape-glyph face into the current face. */
6594 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6596 last_escape_glyph_frame
= it
->f
;
6597 last_escape_glyph_face_id
= it
->face_id
;
6598 last_escape_glyph_merged_face_id
= face_id
;
6601 /* Draw non-ASCII hyphen with just highlighting: */
6603 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6605 XSETINT (it
->ctl_chars
[0], '-');
6607 goto display_control
;
6610 /* Draw non-ASCII space/hyphen with escape glyph: */
6612 if (nonascii_space_p
|| nonascii_hyphen_p
)
6614 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6615 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6617 goto display_control
;
6624 if (CHAR_BYTE8_P (c
))
6625 /* Display \200 instead of \17777600. */
6626 c
= CHAR_TO_BYTE8 (c
);
6627 len
= sprintf (str
, "%03o", c
);
6629 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6630 for (i
= 0; i
< len
; i
++)
6631 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6636 /* Set up IT->dpvec and return first character from it. */
6637 it
->dpvec_char_len
= it
->len
;
6638 it
->dpvec
= it
->ctl_chars
;
6639 it
->dpend
= it
->dpvec
+ ctl_len
;
6640 it
->current
.dpvec_index
= 0;
6641 it
->dpvec_face_id
= face_id
;
6642 it
->saved_face_id
= it
->face_id
;
6643 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6647 it
->char_to_display
= c
;
6651 it
->char_to_display
= it
->c
;
6655 /* Adjust face id for a multibyte character. There are no multibyte
6656 character in unibyte text. */
6657 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6660 && FRAME_WINDOW_P (it
->f
))
6662 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6664 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6666 /* Automatic composition with glyph-string. */
6667 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6669 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6673 ptrdiff_t pos
= (it
->s
? -1
6674 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6675 : IT_CHARPOS (*it
));
6678 if (it
->what
== IT_CHARACTER
)
6679 c
= it
->char_to_display
;
6682 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6686 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6687 /* TAB in a composition means display glyphs with
6688 padding space on the left or right. */
6689 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6692 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6697 /* Is this character the last one of a run of characters with
6698 box? If yes, set IT->end_of_box_run_p to 1. */
6702 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6704 int face_id
= underlying_face_id (it
);
6705 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6709 if (face
->box
== FACE_NO_BOX
)
6711 /* If the box comes from face properties in a
6712 display string, check faces in that string. */
6713 int string_face_id
= face_after_it_pos (it
);
6714 it
->end_of_box_run_p
6715 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6718 /* Otherwise, the box comes from the underlying face.
6719 If this is the last string character displayed, check
6720 the next buffer location. */
6721 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6722 && (it
->current
.overlay_string_index
6723 == it
->n_overlay_strings
- 1))
6727 struct text_pos pos
= it
->current
.pos
;
6728 INC_TEXT_POS (pos
, it
->multibyte_p
);
6730 next_face_id
= face_at_buffer_position
6731 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6732 it
->region_end_charpos
, &ignore
,
6733 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6735 it
->end_of_box_run_p
6736 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6743 int face_id
= face_after_it_pos (it
);
6744 it
->end_of_box_run_p
6745 = (face_id
!= it
->face_id
6746 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6750 /* Value is 0 if end of buffer or string reached. */
6755 /* Move IT to the next display element.
6757 RESEAT_P non-zero means if called on a newline in buffer text,
6758 skip to the next visible line start.
6760 Functions get_next_display_element and set_iterator_to_next are
6761 separate because I find this arrangement easier to handle than a
6762 get_next_display_element function that also increments IT's
6763 position. The way it is we can first look at an iterator's current
6764 display element, decide whether it fits on a line, and if it does,
6765 increment the iterator position. The other way around we probably
6766 would either need a flag indicating whether the iterator has to be
6767 incremented the next time, or we would have to implement a
6768 decrement position function which would not be easy to write. */
6771 set_iterator_to_next (struct it
*it
, int reseat_p
)
6773 /* Reset flags indicating start and end of a sequence of characters
6774 with box. Reset them at the start of this function because
6775 moving the iterator to a new position might set them. */
6776 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6780 case GET_FROM_BUFFER
:
6781 /* The current display element of IT is a character from
6782 current_buffer. Advance in the buffer, and maybe skip over
6783 invisible lines that are so because of selective display. */
6784 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6785 reseat_at_next_visible_line_start (it
, 0);
6786 else if (it
->cmp_it
.id
>= 0)
6788 /* We are currently getting glyphs from a composition. */
6793 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6794 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6795 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6797 it
->cmp_it
.from
= it
->cmp_it
.to
;
6802 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6804 it
->end_charpos
, Qnil
);
6807 else if (! it
->cmp_it
.reversed_p
)
6809 /* Composition created while scanning forward. */
6810 /* Update IT's char/byte positions to point to the first
6811 character of the next grapheme cluster, or to the
6812 character visually after the current composition. */
6813 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6814 bidi_move_to_visually_next (&it
->bidi_it
);
6815 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6816 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6818 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6820 /* Proceed to the next grapheme cluster. */
6821 it
->cmp_it
.from
= it
->cmp_it
.to
;
6825 /* No more grapheme clusters in this composition.
6826 Find the next stop position. */
6827 ptrdiff_t stop
= it
->end_charpos
;
6828 if (it
->bidi_it
.scan_dir
< 0)
6829 /* Now we are scanning backward and don't know
6832 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6833 IT_BYTEPOS (*it
), stop
, Qnil
);
6838 /* Composition created while scanning backward. */
6839 /* Update IT's char/byte positions to point to the last
6840 character of the previous grapheme cluster, or the
6841 character visually after the current composition. */
6842 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6843 bidi_move_to_visually_next (&it
->bidi_it
);
6844 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6845 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6846 if (it
->cmp_it
.from
> 0)
6848 /* Proceed to the previous grapheme cluster. */
6849 it
->cmp_it
.to
= it
->cmp_it
.from
;
6853 /* No more grapheme clusters in this composition.
6854 Find the next stop position. */
6855 ptrdiff_t stop
= it
->end_charpos
;
6856 if (it
->bidi_it
.scan_dir
< 0)
6857 /* Now we are scanning backward and don't know
6860 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6861 IT_BYTEPOS (*it
), stop
, Qnil
);
6867 xassert (it
->len
!= 0);
6871 IT_BYTEPOS (*it
) += it
->len
;
6872 IT_CHARPOS (*it
) += 1;
6876 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6877 /* If this is a new paragraph, determine its base
6878 direction (a.k.a. its base embedding level). */
6879 if (it
->bidi_it
.new_paragraph
)
6880 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6881 bidi_move_to_visually_next (&it
->bidi_it
);
6882 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6883 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6884 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6886 /* As the scan direction was changed, we must
6887 re-compute the stop position for composition. */
6888 ptrdiff_t stop
= it
->end_charpos
;
6889 if (it
->bidi_it
.scan_dir
< 0)
6891 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6892 IT_BYTEPOS (*it
), stop
, Qnil
);
6895 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6899 case GET_FROM_C_STRING
:
6900 /* Current display element of IT is from a C string. */
6902 /* If the string position is beyond string's end, it means
6903 next_element_from_c_string is padding the string with
6904 blanks, in which case we bypass the bidi iterator,
6905 because it cannot deal with such virtual characters. */
6906 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6908 IT_BYTEPOS (*it
) += it
->len
;
6909 IT_CHARPOS (*it
) += 1;
6913 bidi_move_to_visually_next (&it
->bidi_it
);
6914 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6915 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6919 case GET_FROM_DISPLAY_VECTOR
:
6920 /* Current display element of IT is from a display table entry.
6921 Advance in the display table definition. Reset it to null if
6922 end reached, and continue with characters from buffers/
6924 ++it
->current
.dpvec_index
;
6926 /* Restore face of the iterator to what they were before the
6927 display vector entry (these entries may contain faces). */
6928 it
->face_id
= it
->saved_face_id
;
6930 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6932 int recheck_faces
= it
->ellipsis_p
;
6935 it
->method
= GET_FROM_C_STRING
;
6936 else if (STRINGP (it
->string
))
6937 it
->method
= GET_FROM_STRING
;
6940 it
->method
= GET_FROM_BUFFER
;
6941 it
->object
= it
->w
->buffer
;
6945 it
->current
.dpvec_index
= -1;
6947 /* Skip over characters which were displayed via IT->dpvec. */
6948 if (it
->dpvec_char_len
< 0)
6949 reseat_at_next_visible_line_start (it
, 1);
6950 else if (it
->dpvec_char_len
> 0)
6952 if (it
->method
== GET_FROM_STRING
6953 && it
->n_overlay_strings
> 0)
6954 it
->ignore_overlay_strings_at_pos_p
= 1;
6955 it
->len
= it
->dpvec_char_len
;
6956 set_iterator_to_next (it
, reseat_p
);
6959 /* Maybe recheck faces after display vector */
6961 it
->stop_charpos
= IT_CHARPOS (*it
);
6965 case GET_FROM_STRING
:
6966 /* Current display element is a character from a Lisp string. */
6967 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6968 if (it
->cmp_it
.id
>= 0)
6974 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6975 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6976 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6977 it
->cmp_it
.from
= it
->cmp_it
.to
;
6981 composition_compute_stop_pos (&it
->cmp_it
,
6982 IT_STRING_CHARPOS (*it
),
6983 IT_STRING_BYTEPOS (*it
),
6984 it
->end_charpos
, it
->string
);
6987 else if (! it
->cmp_it
.reversed_p
)
6989 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6990 bidi_move_to_visually_next (&it
->bidi_it
);
6991 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6992 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6994 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6995 it
->cmp_it
.from
= it
->cmp_it
.to
;
6998 ptrdiff_t stop
= it
->end_charpos
;
6999 if (it
->bidi_it
.scan_dir
< 0)
7001 composition_compute_stop_pos (&it
->cmp_it
,
7002 IT_STRING_CHARPOS (*it
),
7003 IT_STRING_BYTEPOS (*it
), stop
,
7009 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7010 bidi_move_to_visually_next (&it
->bidi_it
);
7011 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7012 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7013 if (it
->cmp_it
.from
> 0)
7014 it
->cmp_it
.to
= it
->cmp_it
.from
;
7017 ptrdiff_t stop
= it
->end_charpos
;
7018 if (it
->bidi_it
.scan_dir
< 0)
7020 composition_compute_stop_pos (&it
->cmp_it
,
7021 IT_STRING_CHARPOS (*it
),
7022 IT_STRING_BYTEPOS (*it
), stop
,
7030 /* If the string position is beyond string's end, it
7031 means next_element_from_string is padding the string
7032 with blanks, in which case we bypass the bidi
7033 iterator, because it cannot deal with such virtual
7035 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7037 IT_STRING_BYTEPOS (*it
) += it
->len
;
7038 IT_STRING_CHARPOS (*it
) += 1;
7042 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7044 bidi_move_to_visually_next (&it
->bidi_it
);
7045 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7046 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7047 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7049 ptrdiff_t stop
= it
->end_charpos
;
7051 if (it
->bidi_it
.scan_dir
< 0)
7053 composition_compute_stop_pos (&it
->cmp_it
,
7054 IT_STRING_CHARPOS (*it
),
7055 IT_STRING_BYTEPOS (*it
), stop
,
7061 consider_string_end
:
7063 if (it
->current
.overlay_string_index
>= 0)
7065 /* IT->string is an overlay string. Advance to the
7066 next, if there is one. */
7067 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7070 next_overlay_string (it
);
7072 setup_for_ellipsis (it
, 0);
7077 /* IT->string is not an overlay string. If we reached
7078 its end, and there is something on IT->stack, proceed
7079 with what is on the stack. This can be either another
7080 string, this time an overlay string, or a buffer. */
7081 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7085 if (it
->method
== GET_FROM_STRING
)
7086 goto consider_string_end
;
7091 case GET_FROM_IMAGE
:
7092 case GET_FROM_STRETCH
:
7093 /* The position etc with which we have to proceed are on
7094 the stack. The position may be at the end of a string,
7095 if the `display' property takes up the whole string. */
7096 xassert (it
->sp
> 0);
7098 if (it
->method
== GET_FROM_STRING
)
7099 goto consider_string_end
;
7103 /* There are no other methods defined, so this should be a bug. */
7107 xassert (it
->method
!= GET_FROM_STRING
7108 || (STRINGP (it
->string
)
7109 && IT_STRING_CHARPOS (*it
) >= 0));
7112 /* Load IT's display element fields with information about the next
7113 display element which comes from a display table entry or from the
7114 result of translating a control character to one of the forms `^C'
7117 IT->dpvec holds the glyphs to return as characters.
7118 IT->saved_face_id holds the face id before the display vector--it
7119 is restored into IT->face_id in set_iterator_to_next. */
7122 next_element_from_display_vector (struct it
*it
)
7127 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7129 it
->face_id
= it
->saved_face_id
;
7131 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7132 That seemed totally bogus - so I changed it... */
7133 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7135 if (GLYPH_CODE_P (gc
))
7137 it
->c
= GLYPH_CODE_CHAR (gc
);
7138 it
->len
= CHAR_BYTES (it
->c
);
7140 /* The entry may contain a face id to use. Such a face id is
7141 the id of a Lisp face, not a realized face. A face id of
7142 zero means no face is specified. */
7143 if (it
->dpvec_face_id
>= 0)
7144 it
->face_id
= it
->dpvec_face_id
;
7147 int lface_id
= GLYPH_CODE_FACE (gc
);
7149 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7154 /* Display table entry is invalid. Return a space. */
7155 it
->c
= ' ', it
->len
= 1;
7157 /* Don't change position and object of the iterator here. They are
7158 still the values of the character that had this display table
7159 entry or was translated, and that's what we want. */
7160 it
->what
= IT_CHARACTER
;
7164 /* Get the first element of string/buffer in the visual order, after
7165 being reseated to a new position in a string or a buffer. */
7167 get_visually_first_element (struct it
*it
)
7169 int string_p
= STRINGP (it
->string
) || it
->s
;
7170 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7171 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7173 if (STRINGP (it
->string
))
7175 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7176 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7180 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7181 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7184 if (it
->bidi_it
.charpos
== eob
)
7186 /* Nothing to do, but reset the FIRST_ELT flag, like
7187 bidi_paragraph_init does, because we are not going to
7189 it
->bidi_it
.first_elt
= 0;
7191 else if (it
->bidi_it
.charpos
== bob
7193 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7194 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7196 /* If we are at the beginning of a line/string, we can produce
7197 the next element right away. */
7198 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7199 bidi_move_to_visually_next (&it
->bidi_it
);
7203 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7205 /* We need to prime the bidi iterator starting at the line's or
7206 string's beginning, before we will be able to produce the
7209 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7212 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7214 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7216 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7219 /* Now return to buffer/string position where we were asked
7220 to get the next display element, and produce that. */
7221 bidi_move_to_visually_next (&it
->bidi_it
);
7223 while (it
->bidi_it
.bytepos
!= orig_bytepos
7224 && it
->bidi_it
.charpos
< eob
);
7227 /* Adjust IT's position information to where we ended up. */
7228 if (STRINGP (it
->string
))
7230 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7231 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7235 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7236 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7239 if (STRINGP (it
->string
) || !it
->s
)
7241 ptrdiff_t stop
, charpos
, bytepos
;
7243 if (STRINGP (it
->string
))
7246 stop
= SCHARS (it
->string
);
7247 if (stop
> it
->end_charpos
)
7248 stop
= it
->end_charpos
;
7249 charpos
= IT_STRING_CHARPOS (*it
);
7250 bytepos
= IT_STRING_BYTEPOS (*it
);
7254 stop
= it
->end_charpos
;
7255 charpos
= IT_CHARPOS (*it
);
7256 bytepos
= IT_BYTEPOS (*it
);
7258 if (it
->bidi_it
.scan_dir
< 0)
7260 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7265 /* Load IT with the next display element from Lisp string IT->string.
7266 IT->current.string_pos is the current position within the string.
7267 If IT->current.overlay_string_index >= 0, the Lisp string is an
7271 next_element_from_string (struct it
*it
)
7273 struct text_pos position
;
7275 xassert (STRINGP (it
->string
));
7276 xassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7277 xassert (IT_STRING_CHARPOS (*it
) >= 0);
7278 position
= it
->current
.string_pos
;
7280 /* With bidi reordering, the character to display might not be the
7281 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7282 that we were reseat()ed to a new string, whose paragraph
7283 direction is not known. */
7284 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7286 get_visually_first_element (it
);
7287 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7290 /* Time to check for invisible text? */
7291 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7293 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7296 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7297 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7299 /* With bidi non-linear iteration, we could find
7300 ourselves far beyond the last computed stop_charpos,
7301 with several other stop positions in between that we
7302 missed. Scan them all now, in buffer's logical
7303 order, until we find and handle the last stop_charpos
7304 that precedes our current position. */
7305 handle_stop_backwards (it
, it
->stop_charpos
);
7306 return GET_NEXT_DISPLAY_ELEMENT (it
);
7312 /* Take note of the stop position we just moved
7313 across, for when we will move back across it. */
7314 it
->prev_stop
= it
->stop_charpos
;
7315 /* If we are at base paragraph embedding level, take
7316 note of the last stop position seen at this
7318 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7319 it
->base_level_stop
= it
->stop_charpos
;
7323 /* Since a handler may have changed IT->method, we must
7325 return GET_NEXT_DISPLAY_ELEMENT (it
);
7329 /* If we are before prev_stop, we may have overstepped
7330 on our way backwards a stop_pos, and if so, we need
7331 to handle that stop_pos. */
7332 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7333 /* We can sometimes back up for reasons that have nothing
7334 to do with bidi reordering. E.g., compositions. The
7335 code below is only needed when we are above the base
7336 embedding level, so test for that explicitly. */
7337 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7339 /* If we lost track of base_level_stop, we have no better
7340 place for handle_stop_backwards to start from than string
7341 beginning. This happens, e.g., when we were reseated to
7342 the previous screenful of text by vertical-motion. */
7343 if (it
->base_level_stop
<= 0
7344 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7345 it
->base_level_stop
= 0;
7346 handle_stop_backwards (it
, it
->base_level_stop
);
7347 return GET_NEXT_DISPLAY_ELEMENT (it
);
7351 if (it
->current
.overlay_string_index
>= 0)
7353 /* Get the next character from an overlay string. In overlay
7354 strings, There is no field width or padding with spaces to
7356 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7361 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7362 IT_STRING_BYTEPOS (*it
),
7363 it
->bidi_it
.scan_dir
< 0
7365 : SCHARS (it
->string
))
7366 && next_element_from_composition (it
))
7370 else if (STRING_MULTIBYTE (it
->string
))
7372 const unsigned char *s
= (SDATA (it
->string
)
7373 + IT_STRING_BYTEPOS (*it
));
7374 it
->c
= string_char_and_length (s
, &it
->len
);
7378 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7384 /* Get the next character from a Lisp string that is not an
7385 overlay string. Such strings come from the mode line, for
7386 example. We may have to pad with spaces, or truncate the
7387 string. See also next_element_from_c_string. */
7388 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7393 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7395 /* Pad with spaces. */
7396 it
->c
= ' ', it
->len
= 1;
7397 CHARPOS (position
) = BYTEPOS (position
) = -1;
7399 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7400 IT_STRING_BYTEPOS (*it
),
7401 it
->bidi_it
.scan_dir
< 0
7403 : it
->string_nchars
)
7404 && next_element_from_composition (it
))
7408 else if (STRING_MULTIBYTE (it
->string
))
7410 const unsigned char *s
= (SDATA (it
->string
)
7411 + IT_STRING_BYTEPOS (*it
));
7412 it
->c
= string_char_and_length (s
, &it
->len
);
7416 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7421 /* Record what we have and where it came from. */
7422 it
->what
= IT_CHARACTER
;
7423 it
->object
= it
->string
;
7424 it
->position
= position
;
7429 /* Load IT with next display element from C string IT->s.
7430 IT->string_nchars is the maximum number of characters to return
7431 from the string. IT->end_charpos may be greater than
7432 IT->string_nchars when this function is called, in which case we
7433 may have to return padding spaces. Value is zero if end of string
7434 reached, including padding spaces. */
7437 next_element_from_c_string (struct it
*it
)
7442 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7443 it
->what
= IT_CHARACTER
;
7444 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7447 /* With bidi reordering, the character to display might not be the
7448 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7449 we were reseated to a new string, whose paragraph direction is
7451 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7452 get_visually_first_element (it
);
7454 /* IT's position can be greater than IT->string_nchars in case a
7455 field width or precision has been specified when the iterator was
7457 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7459 /* End of the game. */
7463 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7465 /* Pad with spaces. */
7466 it
->c
= ' ', it
->len
= 1;
7467 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7469 else if (it
->multibyte_p
)
7470 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7472 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7478 /* Set up IT to return characters from an ellipsis, if appropriate.
7479 The definition of the ellipsis glyphs may come from a display table
7480 entry. This function fills IT with the first glyph from the
7481 ellipsis if an ellipsis is to be displayed. */
7484 next_element_from_ellipsis (struct it
*it
)
7486 if (it
->selective_display_ellipsis_p
)
7487 setup_for_ellipsis (it
, it
->len
);
7490 /* The face at the current position may be different from the
7491 face we find after the invisible text. Remember what it
7492 was in IT->saved_face_id, and signal that it's there by
7493 setting face_before_selective_p. */
7494 it
->saved_face_id
= it
->face_id
;
7495 it
->method
= GET_FROM_BUFFER
;
7496 it
->object
= it
->w
->buffer
;
7497 reseat_at_next_visible_line_start (it
, 1);
7498 it
->face_before_selective_p
= 1;
7501 return GET_NEXT_DISPLAY_ELEMENT (it
);
7505 /* Deliver an image display element. The iterator IT is already
7506 filled with image information (done in handle_display_prop). Value
7511 next_element_from_image (struct it
*it
)
7513 it
->what
= IT_IMAGE
;
7514 it
->ignore_overlay_strings_at_pos_p
= 0;
7519 /* Fill iterator IT with next display element from a stretch glyph
7520 property. IT->object is the value of the text property. Value is
7524 next_element_from_stretch (struct it
*it
)
7526 it
->what
= IT_STRETCH
;
7530 /* Scan backwards from IT's current position until we find a stop
7531 position, or until BEGV. This is called when we find ourself
7532 before both the last known prev_stop and base_level_stop while
7533 reordering bidirectional text. */
7536 compute_stop_pos_backwards (struct it
*it
)
7538 const int SCAN_BACK_LIMIT
= 1000;
7539 struct text_pos pos
;
7540 struct display_pos save_current
= it
->current
;
7541 struct text_pos save_position
= it
->position
;
7542 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7543 ptrdiff_t where_we_are
= charpos
;
7544 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7545 ptrdiff_t save_end_pos
= it
->end_charpos
;
7547 xassert (NILP (it
->string
) && !it
->s
);
7548 xassert (it
->bidi_p
);
7552 it
->end_charpos
= min (charpos
+ 1, ZV
);
7553 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7554 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7555 reseat_1 (it
, pos
, 0);
7556 compute_stop_pos (it
);
7557 /* We must advance forward, right? */
7558 if (it
->stop_charpos
<= charpos
)
7561 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7563 if (it
->stop_charpos
<= where_we_are
)
7564 it
->prev_stop
= it
->stop_charpos
;
7566 it
->prev_stop
= BEGV
;
7568 it
->current
= save_current
;
7569 it
->position
= save_position
;
7570 it
->stop_charpos
= save_stop_pos
;
7571 it
->end_charpos
= save_end_pos
;
7574 /* Scan forward from CHARPOS in the current buffer/string, until we
7575 find a stop position > current IT's position. Then handle the stop
7576 position before that. This is called when we bump into a stop
7577 position while reordering bidirectional text. CHARPOS should be
7578 the last previously processed stop_pos (or BEGV/0, if none were
7579 processed yet) whose position is less that IT's current
7583 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7585 int bufp
= !STRINGP (it
->string
);
7586 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7587 struct display_pos save_current
= it
->current
;
7588 struct text_pos save_position
= it
->position
;
7589 struct text_pos pos1
;
7590 ptrdiff_t next_stop
;
7592 /* Scan in strict logical order. */
7593 xassert (it
->bidi_p
);
7597 it
->prev_stop
= charpos
;
7600 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7601 reseat_1 (it
, pos1
, 0);
7604 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7605 compute_stop_pos (it
);
7606 /* We must advance forward, right? */
7607 if (it
->stop_charpos
<= it
->prev_stop
)
7609 charpos
= it
->stop_charpos
;
7611 while (charpos
<= where_we_are
);
7614 it
->current
= save_current
;
7615 it
->position
= save_position
;
7616 next_stop
= it
->stop_charpos
;
7617 it
->stop_charpos
= it
->prev_stop
;
7619 it
->stop_charpos
= next_stop
;
7622 /* Load IT with the next display element from current_buffer. Value
7623 is zero if end of buffer reached. IT->stop_charpos is the next
7624 position at which to stop and check for text properties or buffer
7628 next_element_from_buffer (struct it
*it
)
7632 xassert (IT_CHARPOS (*it
) >= BEGV
);
7633 xassert (NILP (it
->string
) && !it
->s
);
7634 xassert (!it
->bidi_p
7635 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7636 && it
->bidi_it
.string
.s
== NULL
));
7638 /* With bidi reordering, the character to display might not be the
7639 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7640 we were reseat()ed to a new buffer position, which is potentially
7641 a different paragraph. */
7642 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7644 get_visually_first_element (it
);
7645 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7648 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7650 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7652 int overlay_strings_follow_p
;
7654 /* End of the game, except when overlay strings follow that
7655 haven't been returned yet. */
7656 if (it
->overlay_strings_at_end_processed_p
)
7657 overlay_strings_follow_p
= 0;
7660 it
->overlay_strings_at_end_processed_p
= 1;
7661 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7664 if (overlay_strings_follow_p
)
7665 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7669 it
->position
= it
->current
.pos
;
7673 else if (!(!it
->bidi_p
7674 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7675 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7677 /* With bidi non-linear iteration, we could find ourselves
7678 far beyond the last computed stop_charpos, with several
7679 other stop positions in between that we missed. Scan
7680 them all now, in buffer's logical order, until we find
7681 and handle the last stop_charpos that precedes our
7682 current position. */
7683 handle_stop_backwards (it
, it
->stop_charpos
);
7684 return GET_NEXT_DISPLAY_ELEMENT (it
);
7690 /* Take note of the stop position we just moved across,
7691 for when we will move back across it. */
7692 it
->prev_stop
= it
->stop_charpos
;
7693 /* If we are at base paragraph embedding level, take
7694 note of the last stop position seen at this
7696 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7697 it
->base_level_stop
= it
->stop_charpos
;
7700 return GET_NEXT_DISPLAY_ELEMENT (it
);
7704 /* If we are before prev_stop, we may have overstepped on
7705 our way backwards a stop_pos, and if so, we need to
7706 handle that stop_pos. */
7707 && IT_CHARPOS (*it
) < it
->prev_stop
7708 /* We can sometimes back up for reasons that have nothing
7709 to do with bidi reordering. E.g., compositions. The
7710 code below is only needed when we are above the base
7711 embedding level, so test for that explicitly. */
7712 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7714 if (it
->base_level_stop
<= 0
7715 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7717 /* If we lost track of base_level_stop, we need to find
7718 prev_stop by looking backwards. This happens, e.g., when
7719 we were reseated to the previous screenful of text by
7721 it
->base_level_stop
= BEGV
;
7722 compute_stop_pos_backwards (it
);
7723 handle_stop_backwards (it
, it
->prev_stop
);
7726 handle_stop_backwards (it
, it
->base_level_stop
);
7727 return GET_NEXT_DISPLAY_ELEMENT (it
);
7731 /* No face changes, overlays etc. in sight, so just return a
7732 character from current_buffer. */
7736 /* Maybe run the redisplay end trigger hook. Performance note:
7737 This doesn't seem to cost measurable time. */
7738 if (it
->redisplay_end_trigger_charpos
7740 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7741 run_redisplay_end_trigger_hook (it
);
7743 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7744 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7746 && next_element_from_composition (it
))
7751 /* Get the next character, maybe multibyte. */
7752 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7753 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7754 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7756 it
->c
= *p
, it
->len
= 1;
7758 /* Record what we have and where it came from. */
7759 it
->what
= IT_CHARACTER
;
7760 it
->object
= it
->w
->buffer
;
7761 it
->position
= it
->current
.pos
;
7763 /* Normally we return the character found above, except when we
7764 really want to return an ellipsis for selective display. */
7769 /* A value of selective > 0 means hide lines indented more
7770 than that number of columns. */
7771 if (it
->selective
> 0
7772 && IT_CHARPOS (*it
) + 1 < ZV
7773 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7774 IT_BYTEPOS (*it
) + 1,
7777 success_p
= next_element_from_ellipsis (it
);
7778 it
->dpvec_char_len
= -1;
7781 else if (it
->c
== '\r' && it
->selective
== -1)
7783 /* A value of selective == -1 means that everything from the
7784 CR to the end of the line is invisible, with maybe an
7785 ellipsis displayed for it. */
7786 success_p
= next_element_from_ellipsis (it
);
7787 it
->dpvec_char_len
= -1;
7792 /* Value is zero if end of buffer reached. */
7793 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7798 /* Run the redisplay end trigger hook for IT. */
7801 run_redisplay_end_trigger_hook (struct it
*it
)
7803 Lisp_Object args
[3];
7805 /* IT->glyph_row should be non-null, i.e. we should be actually
7806 displaying something, or otherwise we should not run the hook. */
7807 xassert (it
->glyph_row
);
7809 /* Set up hook arguments. */
7810 args
[0] = Qredisplay_end_trigger_functions
;
7811 args
[1] = it
->window
;
7812 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7813 it
->redisplay_end_trigger_charpos
= 0;
7815 /* Since we are *trying* to run these functions, don't try to run
7816 them again, even if they get an error. */
7817 it
->w
->redisplay_end_trigger
= Qnil
;
7818 Frun_hook_with_args (3, args
);
7820 /* Notice if it changed the face of the character we are on. */
7821 handle_face_prop (it
);
7825 /* Deliver a composition display element. Unlike the other
7826 next_element_from_XXX, this function is not registered in the array
7827 get_next_element[]. It is called from next_element_from_buffer and
7828 next_element_from_string when necessary. */
7831 next_element_from_composition (struct it
*it
)
7833 it
->what
= IT_COMPOSITION
;
7834 it
->len
= it
->cmp_it
.nbytes
;
7835 if (STRINGP (it
->string
))
7839 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7840 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7843 it
->position
= it
->current
.string_pos
;
7844 it
->object
= it
->string
;
7845 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7846 IT_STRING_BYTEPOS (*it
), it
->string
);
7852 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7853 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7856 if (it
->bidi_it
.new_paragraph
)
7857 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7858 /* Resync the bidi iterator with IT's new position.
7859 FIXME: this doesn't support bidirectional text. */
7860 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7861 bidi_move_to_visually_next (&it
->bidi_it
);
7865 it
->position
= it
->current
.pos
;
7866 it
->object
= it
->w
->buffer
;
7867 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7868 IT_BYTEPOS (*it
), Qnil
);
7875 /***********************************************************************
7876 Moving an iterator without producing glyphs
7877 ***********************************************************************/
7879 /* Check if iterator is at a position corresponding to a valid buffer
7880 position after some move_it_ call. */
7882 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7883 ((it)->method == GET_FROM_STRING \
7884 ? IT_STRING_CHARPOS (*it) == 0 \
7888 /* Move iterator IT to a specified buffer or X position within one
7889 line on the display without producing glyphs.
7891 OP should be a bit mask including some or all of these bits:
7892 MOVE_TO_X: Stop upon reaching x-position TO_X.
7893 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7894 Regardless of OP's value, stop upon reaching the end of the display line.
7896 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7897 This means, in particular, that TO_X includes window's horizontal
7900 The return value has several possible values that
7901 say what condition caused the scan to stop:
7903 MOVE_POS_MATCH_OR_ZV
7904 - when TO_POS or ZV was reached.
7907 -when TO_X was reached before TO_POS or ZV were reached.
7910 - when we reached the end of the display area and the line must
7914 - when we reached the end of the display area and the line is
7918 - when we stopped at a line end, i.e. a newline or a CR and selective
7921 static enum move_it_result
7922 move_it_in_display_line_to (struct it
*it
,
7923 ptrdiff_t to_charpos
, int to_x
,
7924 enum move_operation_enum op
)
7926 enum move_it_result result
= MOVE_UNDEFINED
;
7927 struct glyph_row
*saved_glyph_row
;
7928 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
7929 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
7930 void *ppos_data
= NULL
;
7932 enum it_method prev_method
= it
->method
;
7933 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
7934 int saw_smaller_pos
= prev_pos
< to_charpos
;
7936 /* Don't produce glyphs in produce_glyphs. */
7937 saved_glyph_row
= it
->glyph_row
;
7938 it
->glyph_row
= NULL
;
7940 /* Use wrap_it to save a copy of IT wherever a word wrap could
7941 occur. Use atpos_it to save a copy of IT at the desired buffer
7942 position, if found, so that we can scan ahead and check if the
7943 word later overshoots the window edge. Use atx_it similarly, for
7949 /* Use ppos_it under bidi reordering to save a copy of IT for the
7950 position > CHARPOS that is the closest to CHARPOS. We restore
7951 that position in IT when we have scanned the entire display line
7952 without finding a match for CHARPOS and all the character
7953 positions are greater than CHARPOS. */
7956 SAVE_IT (ppos_it
, *it
, ppos_data
);
7957 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
7958 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
7959 SAVE_IT (ppos_it
, *it
, ppos_data
);
7962 #define BUFFER_POS_REACHED_P() \
7963 ((op & MOVE_TO_POS) != 0 \
7964 && BUFFERP (it->object) \
7965 && (IT_CHARPOS (*it) == to_charpos \
7967 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
7968 && IT_CHARPOS (*it) > to_charpos) \
7969 || (it->what == IT_COMPOSITION \
7970 && ((IT_CHARPOS (*it) > to_charpos \
7971 && to_charpos >= it->cmp_it.charpos) \
7972 || (IT_CHARPOS (*it) < to_charpos \
7973 && to_charpos <= it->cmp_it.charpos)))) \
7974 && (it->method == GET_FROM_BUFFER \
7975 || (it->method == GET_FROM_DISPLAY_VECTOR \
7976 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7978 /* If there's a line-/wrap-prefix, handle it. */
7979 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7980 && it
->current_y
< it
->last_visible_y
)
7981 handle_line_prefix (it
);
7983 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7984 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7988 int x
, i
, ascent
= 0, descent
= 0;
7990 /* Utility macro to reset an iterator with x, ascent, and descent. */
7991 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7992 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7993 (IT)->max_descent = descent)
7995 /* Stop if we move beyond TO_CHARPOS (after an image or a
7996 display string or stretch glyph). */
7997 if ((op
& MOVE_TO_POS
) != 0
7998 && BUFFERP (it
->object
)
7999 && it
->method
== GET_FROM_BUFFER
8001 /* When the iterator is at base embedding level, we
8002 are guaranteed that characters are delivered for
8003 display in strictly increasing order of their
8004 buffer positions. */
8005 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8006 && IT_CHARPOS (*it
) > to_charpos
)
8008 && (prev_method
== GET_FROM_IMAGE
8009 || prev_method
== GET_FROM_STRETCH
8010 || prev_method
== GET_FROM_STRING
)
8011 /* Passed TO_CHARPOS from left to right. */
8012 && ((prev_pos
< to_charpos
8013 && IT_CHARPOS (*it
) > to_charpos
)
8014 /* Passed TO_CHARPOS from right to left. */
8015 || (prev_pos
> to_charpos
8016 && IT_CHARPOS (*it
) < to_charpos
)))))
8018 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8020 result
= MOVE_POS_MATCH_OR_ZV
;
8023 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8024 /* If wrap_it is valid, the current position might be in a
8025 word that is wrapped. So, save the iterator in
8026 atpos_it and continue to see if wrapping happens. */
8027 SAVE_IT (atpos_it
, *it
, atpos_data
);
8030 /* Stop when ZV reached.
8031 We used to stop here when TO_CHARPOS reached as well, but that is
8032 too soon if this glyph does not fit on this line. So we handle it
8033 explicitly below. */
8034 if (!get_next_display_element (it
))
8036 result
= MOVE_POS_MATCH_OR_ZV
;
8040 if (it
->line_wrap
== TRUNCATE
)
8042 if (BUFFER_POS_REACHED_P ())
8044 result
= MOVE_POS_MATCH_OR_ZV
;
8050 if (it
->line_wrap
== WORD_WRAP
)
8052 if (IT_DISPLAYING_WHITESPACE (it
))
8056 /* We have reached a glyph that follows one or more
8057 whitespace characters. If the position is
8058 already found, we are done. */
8059 if (atpos_it
.sp
>= 0)
8061 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8062 result
= MOVE_POS_MATCH_OR_ZV
;
8067 RESTORE_IT (it
, &atx_it
, atx_data
);
8068 result
= MOVE_X_REACHED
;
8071 /* Otherwise, we can wrap here. */
8072 SAVE_IT (wrap_it
, *it
, wrap_data
);
8078 /* Remember the line height for the current line, in case
8079 the next element doesn't fit on the line. */
8080 ascent
= it
->max_ascent
;
8081 descent
= it
->max_descent
;
8083 /* The call to produce_glyphs will get the metrics of the
8084 display element IT is loaded with. Record the x-position
8085 before this display element, in case it doesn't fit on the
8089 PRODUCE_GLYPHS (it
);
8091 if (it
->area
!= TEXT_AREA
)
8093 prev_method
= it
->method
;
8094 if (it
->method
== GET_FROM_BUFFER
)
8095 prev_pos
= IT_CHARPOS (*it
);
8096 set_iterator_to_next (it
, 1);
8097 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8098 SET_TEXT_POS (this_line_min_pos
,
8099 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8101 && (op
& MOVE_TO_POS
)
8102 && IT_CHARPOS (*it
) > to_charpos
8103 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8104 SAVE_IT (ppos_it
, *it
, ppos_data
);
8108 /* The number of glyphs we get back in IT->nglyphs will normally
8109 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8110 character on a terminal frame, or (iii) a line end. For the
8111 second case, IT->nglyphs - 1 padding glyphs will be present.
8112 (On X frames, there is only one glyph produced for a
8113 composite character.)
8115 The behavior implemented below means, for continuation lines,
8116 that as many spaces of a TAB as fit on the current line are
8117 displayed there. For terminal frames, as many glyphs of a
8118 multi-glyph character are displayed in the current line, too.
8119 This is what the old redisplay code did, and we keep it that
8120 way. Under X, the whole shape of a complex character must
8121 fit on the line or it will be completely displayed in the
8124 Note that both for tabs and padding glyphs, all glyphs have
8128 /* More than one glyph or glyph doesn't fit on line. All
8129 glyphs have the same width. */
8130 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8132 int x_before_this_char
= x
;
8133 int hpos_before_this_char
= it
->hpos
;
8135 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8137 new_x
= x
+ single_glyph_width
;
8139 /* We want to leave anything reaching TO_X to the caller. */
8140 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8142 if (BUFFER_POS_REACHED_P ())
8144 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8145 goto buffer_pos_reached
;
8146 if (atpos_it
.sp
< 0)
8148 SAVE_IT (atpos_it
, *it
, atpos_data
);
8149 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8154 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8157 result
= MOVE_X_REACHED
;
8162 SAVE_IT (atx_it
, *it
, atx_data
);
8163 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8168 if (/* Lines are continued. */
8169 it
->line_wrap
!= TRUNCATE
8170 && (/* And glyph doesn't fit on the line. */
8171 new_x
> it
->last_visible_x
8172 /* Or it fits exactly and we're on a window
8174 || (new_x
== it
->last_visible_x
8175 && FRAME_WINDOW_P (it
->f
))))
8177 if (/* IT->hpos == 0 means the very first glyph
8178 doesn't fit on the line, e.g. a wide image. */
8180 || (new_x
== it
->last_visible_x
8181 && FRAME_WINDOW_P (it
->f
)))
8184 it
->current_x
= new_x
;
8186 /* The character's last glyph just barely fits
8188 if (i
== it
->nglyphs
- 1)
8190 /* If this is the destination position,
8191 return a position *before* it in this row,
8192 now that we know it fits in this row. */
8193 if (BUFFER_POS_REACHED_P ())
8195 if (it
->line_wrap
!= WORD_WRAP
8198 it
->hpos
= hpos_before_this_char
;
8199 it
->current_x
= x_before_this_char
;
8200 result
= MOVE_POS_MATCH_OR_ZV
;
8203 if (it
->line_wrap
== WORD_WRAP
8206 SAVE_IT (atpos_it
, *it
, atpos_data
);
8207 atpos_it
.current_x
= x_before_this_char
;
8208 atpos_it
.hpos
= hpos_before_this_char
;
8212 prev_method
= it
->method
;
8213 if (it
->method
== GET_FROM_BUFFER
)
8214 prev_pos
= IT_CHARPOS (*it
);
8215 set_iterator_to_next (it
, 1);
8216 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8217 SET_TEXT_POS (this_line_min_pos
,
8218 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8219 /* On graphical terminals, newlines may
8220 "overflow" into the fringe if
8221 overflow-newline-into-fringe is non-nil.
8222 On text-only terminals, newlines may
8223 overflow into the last glyph on the
8225 if (!FRAME_WINDOW_P (it
->f
)
8226 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8228 if (!get_next_display_element (it
))
8230 result
= MOVE_POS_MATCH_OR_ZV
;
8233 if (BUFFER_POS_REACHED_P ())
8235 if (ITERATOR_AT_END_OF_LINE_P (it
))
8236 result
= MOVE_POS_MATCH_OR_ZV
;
8238 result
= MOVE_LINE_CONTINUED
;
8241 if (ITERATOR_AT_END_OF_LINE_P (it
))
8243 result
= MOVE_NEWLINE_OR_CR
;
8250 IT_RESET_X_ASCENT_DESCENT (it
);
8252 if (wrap_it
.sp
>= 0)
8254 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8259 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8261 result
= MOVE_LINE_CONTINUED
;
8265 if (BUFFER_POS_REACHED_P ())
8267 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8268 goto buffer_pos_reached
;
8269 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8271 SAVE_IT (atpos_it
, *it
, atpos_data
);
8272 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8276 if (new_x
> it
->first_visible_x
)
8278 /* Glyph is visible. Increment number of glyphs that
8279 would be displayed. */
8284 if (result
!= MOVE_UNDEFINED
)
8287 else if (BUFFER_POS_REACHED_P ())
8290 IT_RESET_X_ASCENT_DESCENT (it
);
8291 result
= MOVE_POS_MATCH_OR_ZV
;
8294 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8296 /* Stop when TO_X specified and reached. This check is
8297 necessary here because of lines consisting of a line end,
8298 only. The line end will not produce any glyphs and we
8299 would never get MOVE_X_REACHED. */
8300 xassert (it
->nglyphs
== 0);
8301 result
= MOVE_X_REACHED
;
8305 /* Is this a line end? If yes, we're done. */
8306 if (ITERATOR_AT_END_OF_LINE_P (it
))
8308 /* If we are past TO_CHARPOS, but never saw any character
8309 positions smaller than TO_CHARPOS, return
8310 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8312 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8314 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8316 if (IT_CHARPOS (ppos_it
) < ZV
)
8318 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8319 result
= MOVE_POS_MATCH_OR_ZV
;
8322 goto buffer_pos_reached
;
8324 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8325 && IT_CHARPOS (*it
) > to_charpos
)
8326 goto buffer_pos_reached
;
8328 result
= MOVE_NEWLINE_OR_CR
;
8331 result
= MOVE_NEWLINE_OR_CR
;
8335 prev_method
= it
->method
;
8336 if (it
->method
== GET_FROM_BUFFER
)
8337 prev_pos
= IT_CHARPOS (*it
);
8338 /* The current display element has been consumed. Advance
8340 set_iterator_to_next (it
, 1);
8341 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8342 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8343 if (IT_CHARPOS (*it
) < to_charpos
)
8344 saw_smaller_pos
= 1;
8346 && (op
& MOVE_TO_POS
)
8347 && IT_CHARPOS (*it
) >= to_charpos
8348 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8349 SAVE_IT (ppos_it
, *it
, ppos_data
);
8351 /* Stop if lines are truncated and IT's current x-position is
8352 past the right edge of the window now. */
8353 if (it
->line_wrap
== TRUNCATE
8354 && it
->current_x
>= it
->last_visible_x
)
8356 if (!FRAME_WINDOW_P (it
->f
)
8357 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8361 if ((at_eob_p
= !get_next_display_element (it
))
8362 || BUFFER_POS_REACHED_P ()
8363 /* If we are past TO_CHARPOS, but never saw any
8364 character positions smaller than TO_CHARPOS,
8365 return MOVE_POS_MATCH_OR_ZV, like the
8366 unidirectional display did. */
8367 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8369 && IT_CHARPOS (*it
) > to_charpos
))
8372 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8373 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8374 result
= MOVE_POS_MATCH_OR_ZV
;
8377 if (ITERATOR_AT_END_OF_LINE_P (it
))
8379 result
= MOVE_NEWLINE_OR_CR
;
8383 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8385 && IT_CHARPOS (*it
) > to_charpos
)
8387 if (IT_CHARPOS (ppos_it
) < ZV
)
8388 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8389 result
= MOVE_POS_MATCH_OR_ZV
;
8392 result
= MOVE_LINE_TRUNCATED
;
8395 #undef IT_RESET_X_ASCENT_DESCENT
8398 #undef BUFFER_POS_REACHED_P
8400 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8401 restore the saved iterator. */
8402 if (atpos_it
.sp
>= 0)
8403 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8404 else if (atx_it
.sp
>= 0)
8405 RESTORE_IT (it
, &atx_it
, atx_data
);
8410 bidi_unshelve_cache (atpos_data
, 1);
8412 bidi_unshelve_cache (atx_data
, 1);
8414 bidi_unshelve_cache (wrap_data
, 1);
8416 bidi_unshelve_cache (ppos_data
, 1);
8418 /* Restore the iterator settings altered at the beginning of this
8420 it
->glyph_row
= saved_glyph_row
;
8424 /* For external use. */
8426 move_it_in_display_line (struct it
*it
,
8427 ptrdiff_t to_charpos
, int to_x
,
8428 enum move_operation_enum op
)
8430 if (it
->line_wrap
== WORD_WRAP
8431 && (op
& MOVE_TO_X
))
8434 void *save_data
= NULL
;
8437 SAVE_IT (save_it
, *it
, save_data
);
8438 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8439 /* When word-wrap is on, TO_X may lie past the end
8440 of a wrapped line. Then it->current is the
8441 character on the next line, so backtrack to the
8442 space before the wrap point. */
8443 if (skip
== MOVE_LINE_CONTINUED
)
8445 int prev_x
= max (it
->current_x
- 1, 0);
8446 RESTORE_IT (it
, &save_it
, save_data
);
8447 move_it_in_display_line_to
8448 (it
, -1, prev_x
, MOVE_TO_X
);
8451 bidi_unshelve_cache (save_data
, 1);
8454 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8458 /* Move IT forward until it satisfies one or more of the criteria in
8459 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8461 OP is a bit-mask that specifies where to stop, and in particular,
8462 which of those four position arguments makes a difference. See the
8463 description of enum move_operation_enum.
8465 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8466 screen line, this function will set IT to the next position that is
8467 displayed to the right of TO_CHARPOS on the screen. */
8470 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8472 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8473 int line_height
, line_start_x
= 0, reached
= 0;
8474 void *backup_data
= NULL
;
8478 if (op
& MOVE_TO_VPOS
)
8480 /* If no TO_CHARPOS and no TO_X specified, stop at the
8481 start of the line TO_VPOS. */
8482 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8484 if (it
->vpos
== to_vpos
)
8490 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8494 /* TO_VPOS >= 0 means stop at TO_X in the line at
8495 TO_VPOS, or at TO_POS, whichever comes first. */
8496 if (it
->vpos
== to_vpos
)
8502 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8504 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8509 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8511 /* We have reached TO_X but not in the line we want. */
8512 skip
= move_it_in_display_line_to (it
, to_charpos
,
8514 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8522 else if (op
& MOVE_TO_Y
)
8524 struct it it_backup
;
8526 if (it
->line_wrap
== WORD_WRAP
)
8527 SAVE_IT (it_backup
, *it
, backup_data
);
8529 /* TO_Y specified means stop at TO_X in the line containing
8530 TO_Y---or at TO_CHARPOS if this is reached first. The
8531 problem is that we can't really tell whether the line
8532 contains TO_Y before we have completely scanned it, and
8533 this may skip past TO_X. What we do is to first scan to
8536 If TO_X is not specified, use a TO_X of zero. The reason
8537 is to make the outcome of this function more predictable.
8538 If we didn't use TO_X == 0, we would stop at the end of
8539 the line which is probably not what a caller would expect
8541 skip
= move_it_in_display_line_to
8542 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8543 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8545 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8546 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8548 else if (skip
== MOVE_X_REACHED
)
8550 /* If TO_X was reached, we want to know whether TO_Y is
8551 in the line. We know this is the case if the already
8552 scanned glyphs make the line tall enough. Otherwise,
8553 we must check by scanning the rest of the line. */
8554 line_height
= it
->max_ascent
+ it
->max_descent
;
8555 if (to_y
>= it
->current_y
8556 && to_y
< it
->current_y
+ line_height
)
8561 SAVE_IT (it_backup
, *it
, backup_data
);
8562 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8563 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8565 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8566 line_height
= it
->max_ascent
+ it
->max_descent
;
8567 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8569 if (to_y
>= it
->current_y
8570 && to_y
< it
->current_y
+ line_height
)
8572 /* If TO_Y is in this line and TO_X was reached
8573 above, we scanned too far. We have to restore
8574 IT's settings to the ones before skipping. */
8575 RESTORE_IT (it
, &it_backup
, backup_data
);
8581 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8587 /* Check whether TO_Y is in this line. */
8588 line_height
= it
->max_ascent
+ it
->max_descent
;
8589 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8591 if (to_y
>= it
->current_y
8592 && to_y
< it
->current_y
+ line_height
)
8594 /* When word-wrap is on, TO_X may lie past the end
8595 of a wrapped line. Then it->current is the
8596 character on the next line, so backtrack to the
8597 space before the wrap point. */
8598 if (skip
== MOVE_LINE_CONTINUED
8599 && it
->line_wrap
== WORD_WRAP
)
8601 int prev_x
= max (it
->current_x
- 1, 0);
8602 RESTORE_IT (it
, &it_backup
, backup_data
);
8603 skip
= move_it_in_display_line_to
8604 (it
, -1, prev_x
, MOVE_TO_X
);
8613 else if (BUFFERP (it
->object
)
8614 && (it
->method
== GET_FROM_BUFFER
8615 || it
->method
== GET_FROM_STRETCH
)
8616 && IT_CHARPOS (*it
) >= to_charpos
8617 /* Under bidi iteration, a call to set_iterator_to_next
8618 can scan far beyond to_charpos if the initial
8619 portion of the next line needs to be reordered. In
8620 that case, give move_it_in_display_line_to another
8623 && it
->bidi_it
.scan_dir
== -1))
8624 skip
= MOVE_POS_MATCH_OR_ZV
;
8626 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8630 case MOVE_POS_MATCH_OR_ZV
:
8634 case MOVE_NEWLINE_OR_CR
:
8635 set_iterator_to_next (it
, 1);
8636 it
->continuation_lines_width
= 0;
8639 case MOVE_LINE_TRUNCATED
:
8640 it
->continuation_lines_width
= 0;
8641 reseat_at_next_visible_line_start (it
, 0);
8642 if ((op
& MOVE_TO_POS
) != 0
8643 && IT_CHARPOS (*it
) > to_charpos
)
8650 case MOVE_LINE_CONTINUED
:
8651 /* For continued lines ending in a tab, some of the glyphs
8652 associated with the tab are displayed on the current
8653 line. Since it->current_x does not include these glyphs,
8654 we use it->last_visible_x instead. */
8657 it
->continuation_lines_width
+= it
->last_visible_x
;
8658 /* When moving by vpos, ensure that the iterator really
8659 advances to the next line (bug#847, bug#969). Fixme:
8660 do we need to do this in other circumstances? */
8661 if (it
->current_x
!= it
->last_visible_x
8662 && (op
& MOVE_TO_VPOS
)
8663 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8665 line_start_x
= it
->current_x
+ it
->pixel_width
8666 - it
->last_visible_x
;
8667 set_iterator_to_next (it
, 0);
8671 it
->continuation_lines_width
+= it
->current_x
;
8678 /* Reset/increment for the next run. */
8679 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8680 it
->current_x
= line_start_x
;
8683 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8685 last_height
= it
->max_ascent
+ it
->max_descent
;
8686 last_max_ascent
= it
->max_ascent
;
8687 it
->max_ascent
= it
->max_descent
= 0;
8692 /* On text terminals, we may stop at the end of a line in the middle
8693 of a multi-character glyph. If the glyph itself is continued,
8694 i.e. it is actually displayed on the next line, don't treat this
8695 stopping point as valid; move to the next line instead (unless
8696 that brings us offscreen). */
8697 if (!FRAME_WINDOW_P (it
->f
)
8699 && IT_CHARPOS (*it
) == to_charpos
8700 && it
->what
== IT_CHARACTER
8702 && it
->line_wrap
== WINDOW_WRAP
8703 && it
->current_x
== it
->last_visible_x
- 1
8706 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8708 it
->continuation_lines_width
+= it
->current_x
;
8709 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8710 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8712 last_height
= it
->max_ascent
+ it
->max_descent
;
8713 last_max_ascent
= it
->max_ascent
;
8717 bidi_unshelve_cache (backup_data
, 1);
8719 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8723 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8725 If DY > 0, move IT backward at least that many pixels. DY = 0
8726 means move IT backward to the preceding line start or BEGV. This
8727 function may move over more than DY pixels if IT->current_y - DY
8728 ends up in the middle of a line; in this case IT->current_y will be
8729 set to the top of the line moved to. */
8732 move_it_vertically_backward (struct it
*it
, int dy
)
8736 void *it2data
= NULL
, *it3data
= NULL
;
8737 ptrdiff_t start_pos
;
8742 start_pos
= IT_CHARPOS (*it
);
8744 /* Estimate how many newlines we must move back. */
8745 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8747 /* Set the iterator's position that many lines back. */
8748 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8749 back_to_previous_visible_line_start (it
);
8751 /* Reseat the iterator here. When moving backward, we don't want
8752 reseat to skip forward over invisible text, set up the iterator
8753 to deliver from overlay strings at the new position etc. So,
8754 use reseat_1 here. */
8755 reseat_1 (it
, it
->current
.pos
, 1);
8757 /* We are now surely at a line start. */
8758 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8759 reordering is in effect. */
8760 it
->continuation_lines_width
= 0;
8762 /* Move forward and see what y-distance we moved. First move to the
8763 start of the next line so that we get its height. We need this
8764 height to be able to tell whether we reached the specified
8766 SAVE_IT (it2
, *it
, it2data
);
8767 it2
.max_ascent
= it2
.max_descent
= 0;
8770 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8771 MOVE_TO_POS
| MOVE_TO_VPOS
);
8773 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8774 /* If we are in a display string which starts at START_POS,
8775 and that display string includes a newline, and we are
8776 right after that newline (i.e. at the beginning of a
8777 display line), exit the loop, because otherwise we will
8778 infloop, since move_it_to will see that it is already at
8779 START_POS and will not move. */
8780 || (it2
.method
== GET_FROM_STRING
8781 && IT_CHARPOS (it2
) == start_pos
8782 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8783 xassert (IT_CHARPOS (*it
) >= BEGV
);
8784 SAVE_IT (it3
, it2
, it3data
);
8786 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8787 xassert (IT_CHARPOS (*it
) >= BEGV
);
8788 /* H is the actual vertical distance from the position in *IT
8789 and the starting position. */
8790 h
= it2
.current_y
- it
->current_y
;
8791 /* NLINES is the distance in number of lines. */
8792 nlines
= it2
.vpos
- it
->vpos
;
8794 /* Correct IT's y and vpos position
8795 so that they are relative to the starting point. */
8801 /* DY == 0 means move to the start of the screen line. The
8802 value of nlines is > 0 if continuation lines were involved,
8803 or if the original IT position was at start of a line. */
8804 RESTORE_IT (it
, it
, it2data
);
8806 move_it_by_lines (it
, nlines
);
8807 /* The above code moves us to some position NLINES down,
8808 usually to its first glyph (leftmost in an L2R line), but
8809 that's not necessarily the start of the line, under bidi
8810 reordering. We want to get to the character position
8811 that is immediately after the newline of the previous
8814 && !it
->continuation_lines_width
8815 && !STRINGP (it
->string
)
8816 && IT_CHARPOS (*it
) > BEGV
8817 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8820 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8822 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8824 bidi_unshelve_cache (it3data
, 1);
8828 /* The y-position we try to reach, relative to *IT.
8829 Note that H has been subtracted in front of the if-statement. */
8830 int target_y
= it
->current_y
+ h
- dy
;
8831 int y0
= it3
.current_y
;
8835 RESTORE_IT (&it3
, &it3
, it3data
);
8836 y1
= line_bottom_y (&it3
);
8837 line_height
= y1
- y0
;
8838 RESTORE_IT (it
, it
, it2data
);
8839 /* If we did not reach target_y, try to move further backward if
8840 we can. If we moved too far backward, try to move forward. */
8841 if (target_y
< it
->current_y
8842 /* This is heuristic. In a window that's 3 lines high, with
8843 a line height of 13 pixels each, recentering with point
8844 on the bottom line will try to move -39/2 = 19 pixels
8845 backward. Try to avoid moving into the first line. */
8846 && (it
->current_y
- target_y
8847 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8848 && IT_CHARPOS (*it
) > BEGV
)
8850 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8851 target_y
- it
->current_y
));
8852 dy
= it
->current_y
- target_y
;
8853 goto move_further_back
;
8855 else if (target_y
>= it
->current_y
+ line_height
8856 && IT_CHARPOS (*it
) < ZV
)
8858 /* Should move forward by at least one line, maybe more.
8860 Note: Calling move_it_by_lines can be expensive on
8861 terminal frames, where compute_motion is used (via
8862 vmotion) to do the job, when there are very long lines
8863 and truncate-lines is nil. That's the reason for
8864 treating terminal frames specially here. */
8866 if (!FRAME_WINDOW_P (it
->f
))
8867 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8872 move_it_by_lines (it
, 1);
8874 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8881 /* Move IT by a specified amount of pixel lines DY. DY negative means
8882 move backwards. DY = 0 means move to start of screen line. At the
8883 end, IT will be on the start of a screen line. */
8886 move_it_vertically (struct it
*it
, int dy
)
8889 move_it_vertically_backward (it
, -dy
);
8892 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8893 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8894 MOVE_TO_POS
| MOVE_TO_Y
);
8895 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8897 /* If buffer ends in ZV without a newline, move to the start of
8898 the line to satisfy the post-condition. */
8899 if (IT_CHARPOS (*it
) == ZV
8901 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8902 move_it_by_lines (it
, 0);
8907 /* Move iterator IT past the end of the text line it is in. */
8910 move_it_past_eol (struct it
*it
)
8912 enum move_it_result rc
;
8914 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8915 if (rc
== MOVE_NEWLINE_OR_CR
)
8916 set_iterator_to_next (it
, 0);
8920 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8921 negative means move up. DVPOS == 0 means move to the start of the
8924 Optimization idea: If we would know that IT->f doesn't use
8925 a face with proportional font, we could be faster for
8926 truncate-lines nil. */
8929 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
8932 /* The commented-out optimization uses vmotion on terminals. This
8933 gives bad results, because elements like it->what, on which
8934 callers such as pos_visible_p rely, aren't updated. */
8935 /* struct position pos;
8936 if (!FRAME_WINDOW_P (it->f))
8938 struct text_pos textpos;
8940 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8941 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8942 reseat (it, textpos, 1);
8943 it->vpos += pos.vpos;
8944 it->current_y += pos.vpos;
8950 /* DVPOS == 0 means move to the start of the screen line. */
8951 move_it_vertically_backward (it
, 0);
8952 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8953 /* Let next call to line_bottom_y calculate real line height */
8958 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8959 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8960 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8965 void *it2data
= NULL
;
8966 ptrdiff_t start_charpos
, i
;
8968 /* Start at the beginning of the screen line containing IT's
8969 position. This may actually move vertically backwards,
8970 in case of overlays, so adjust dvpos accordingly. */
8972 move_it_vertically_backward (it
, 0);
8975 /* Go back -DVPOS visible lines and reseat the iterator there. */
8976 start_charpos
= IT_CHARPOS (*it
);
8977 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8978 back_to_previous_visible_line_start (it
);
8979 reseat (it
, it
->current
.pos
, 1);
8981 /* Move further back if we end up in a string or an image. */
8982 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8984 /* First try to move to start of display line. */
8986 move_it_vertically_backward (it
, 0);
8988 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8990 /* If start of line is still in string or image,
8991 move further back. */
8992 back_to_previous_visible_line_start (it
);
8993 reseat (it
, it
->current
.pos
, 1);
8997 it
->current_x
= it
->hpos
= 0;
8999 /* Above call may have moved too far if continuation lines
9000 are involved. Scan forward and see if it did. */
9001 SAVE_IT (it2
, *it
, it2data
);
9002 it2
.vpos
= it2
.current_y
= 0;
9003 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9004 it
->vpos
-= it2
.vpos
;
9005 it
->current_y
-= it2
.current_y
;
9006 it
->current_x
= it
->hpos
= 0;
9008 /* If we moved too far back, move IT some lines forward. */
9009 if (it2
.vpos
> -dvpos
)
9011 int delta
= it2
.vpos
+ dvpos
;
9013 RESTORE_IT (&it2
, &it2
, it2data
);
9014 SAVE_IT (it2
, *it
, it2data
);
9015 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9016 /* Move back again if we got too far ahead. */
9017 if (IT_CHARPOS (*it
) >= start_charpos
)
9018 RESTORE_IT (it
, &it2
, it2data
);
9020 bidi_unshelve_cache (it2data
, 1);
9023 RESTORE_IT (it
, it
, it2data
);
9027 /* Return 1 if IT points into the middle of a display vector. */
9030 in_display_vector_p (struct it
*it
)
9032 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9033 && it
->current
.dpvec_index
> 0
9034 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9038 /***********************************************************************
9040 ***********************************************************************/
9043 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9047 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9049 Lisp_Object args
[3];
9050 Lisp_Object msg
, fmt
;
9053 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9056 /* Do nothing if called asynchronously. Inserting text into
9057 a buffer may call after-change-functions and alike and
9058 that would means running Lisp asynchronously. */
9059 if (handling_signal
)
9063 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9065 args
[0] = fmt
= build_string (format
);
9068 msg
= Fformat (3, args
);
9070 len
= SBYTES (msg
) + 1;
9071 SAFE_ALLOCA (buffer
, char *, len
);
9072 memcpy (buffer
, SDATA (msg
), len
);
9074 message_dolog (buffer
, len
- 1, 1, 0);
9081 /* Output a newline in the *Messages* buffer if "needs" one. */
9084 message_log_maybe_newline (void)
9086 if (message_log_need_newline
)
9087 message_dolog ("", 0, 1, 0);
9091 /* Add a string M of length NBYTES to the message log, optionally
9092 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9093 nonzero, means interpret the contents of M as multibyte. This
9094 function calls low-level routines in order to bypass text property
9095 hooks, etc. which might not be safe to run.
9097 This may GC (insert may run before/after change hooks),
9098 so the buffer M must NOT point to a Lisp string. */
9101 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9103 const unsigned char *msg
= (const unsigned char *) m
;
9105 if (!NILP (Vmemory_full
))
9108 if (!NILP (Vmessage_log_max
))
9110 struct buffer
*oldbuf
;
9111 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9112 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9113 ptrdiff_t point_at_end
= 0;
9114 ptrdiff_t zv_at_end
= 0;
9115 Lisp_Object old_deactivate_mark
, tem
;
9116 struct gcpro gcpro1
;
9118 old_deactivate_mark
= Vdeactivate_mark
;
9119 oldbuf
= current_buffer
;
9120 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9121 BVAR (current_buffer
, undo_list
) = Qt
;
9123 oldpoint
= message_dolog_marker1
;
9124 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9125 oldbegv
= message_dolog_marker2
;
9126 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9127 oldzv
= message_dolog_marker3
;
9128 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9129 GCPRO1 (old_deactivate_mark
);
9137 BEGV_BYTE
= BEG_BYTE
;
9140 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9142 /* Insert the string--maybe converting multibyte to single byte
9143 or vice versa, so that all the text fits the buffer. */
9145 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9151 /* Convert a multibyte string to single-byte
9152 for the *Message* buffer. */
9153 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9155 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9156 work
[0] = (ASCII_CHAR_P (c
)
9158 : multibyte_char_to_unibyte (c
));
9159 insert_1_both (work
, 1, 1, 1, 0, 0);
9162 else if (! multibyte
9163 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9167 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9168 /* Convert a single-byte string to multibyte
9169 for the *Message* buffer. */
9170 for (i
= 0; i
< nbytes
; i
++)
9173 MAKE_CHAR_MULTIBYTE (c
);
9174 char_bytes
= CHAR_STRING (c
, str
);
9175 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9179 insert_1 (m
, nbytes
, 1, 0, 0);
9183 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9185 insert_1 ("\n", 1, 1, 0, 0);
9187 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9189 this_bol_byte
= PT_BYTE
;
9191 /* See if this line duplicates the previous one.
9192 If so, combine duplicates. */
9195 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9197 prev_bol_byte
= PT_BYTE
;
9199 dups
= message_log_check_duplicate (prev_bol_byte
,
9203 del_range_both (prev_bol
, prev_bol_byte
,
9204 this_bol
, this_bol_byte
, 0);
9207 char dupstr
[sizeof " [ times]"
9208 + INT_STRLEN_BOUND (printmax_t
)];
9211 /* If you change this format, don't forget to also
9212 change message_log_check_duplicate. */
9213 sprintf (dupstr
, " [%"pMd
" times]", dups
);
9214 duplen
= strlen (dupstr
);
9215 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9216 insert_1 (dupstr
, duplen
, 1, 0, 1);
9221 /* If we have more than the desired maximum number of lines
9222 in the *Messages* buffer now, delete the oldest ones.
9223 This is safe because we don't have undo in this buffer. */
9225 if (NATNUMP (Vmessage_log_max
))
9227 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9228 -XFASTINT (Vmessage_log_max
) - 1, 0);
9229 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9232 BEGV
= XMARKER (oldbegv
)->charpos
;
9233 BEGV_BYTE
= marker_byte_position (oldbegv
);
9242 ZV
= XMARKER (oldzv
)->charpos
;
9243 ZV_BYTE
= marker_byte_position (oldzv
);
9247 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9249 /* We can't do Fgoto_char (oldpoint) because it will run some
9251 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9252 XMARKER (oldpoint
)->bytepos
);
9255 unchain_marker (XMARKER (oldpoint
));
9256 unchain_marker (XMARKER (oldbegv
));
9257 unchain_marker (XMARKER (oldzv
));
9259 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9260 set_buffer_internal (oldbuf
);
9262 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9263 message_log_need_newline
= !nlflag
;
9264 Vdeactivate_mark
= old_deactivate_mark
;
9269 /* We are at the end of the buffer after just having inserted a newline.
9270 (Note: We depend on the fact we won't be crossing the gap.)
9271 Check to see if the most recent message looks a lot like the previous one.
9272 Return 0 if different, 1 if the new one should just replace it, or a
9273 value N > 1 if we should also append " [N times]". */
9276 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9279 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9281 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9282 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9284 for (i
= 0; i
< len
; i
++)
9286 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9294 if (*p1
++ == ' ' && *p1
++ == '[')
9297 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9298 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9305 /* Display an echo area message M with a specified length of NBYTES
9306 bytes. The string may include null characters. If M is 0, clear
9307 out any existing message, and let the mini-buffer text show
9310 This may GC, so the buffer M must NOT point to a Lisp string. */
9313 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9315 /* First flush out any partial line written with print. */
9316 message_log_maybe_newline ();
9318 message_dolog (m
, nbytes
, 1, multibyte
);
9319 message2_nolog (m
, nbytes
, multibyte
);
9323 /* The non-logging counterpart of message2. */
9326 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9328 struct frame
*sf
= SELECTED_FRAME ();
9329 message_enable_multibyte
= multibyte
;
9331 if (FRAME_INITIAL_P (sf
))
9333 if (noninteractive_need_newline
)
9334 putc ('\n', stderr
);
9335 noninteractive_need_newline
= 0;
9337 fwrite (m
, nbytes
, 1, stderr
);
9338 if (cursor_in_echo_area
== 0)
9339 fprintf (stderr
, "\n");
9342 /* A null message buffer means that the frame hasn't really been
9343 initialized yet. Error messages get reported properly by
9344 cmd_error, so this must be just an informative message; toss it. */
9345 else if (INTERACTIVE
9346 && sf
->glyphs_initialized_p
9347 && FRAME_MESSAGE_BUF (sf
))
9349 Lisp_Object mini_window
;
9352 /* Get the frame containing the mini-buffer
9353 that the selected frame is using. */
9354 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9355 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9357 FRAME_SAMPLE_VISIBILITY (f
);
9358 if (FRAME_VISIBLE_P (sf
)
9359 && ! FRAME_VISIBLE_P (f
))
9360 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9364 set_message (m
, Qnil
, nbytes
, multibyte
);
9365 if (minibuffer_auto_raise
)
9366 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9369 clear_message (1, 1);
9371 do_pending_window_change (0);
9372 echo_area_display (1);
9373 do_pending_window_change (0);
9374 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9375 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9380 /* Display an echo area message M with a specified length of NBYTES
9381 bytes. The string may include null characters. If M is not a
9382 string, clear out any existing message, and let the mini-buffer
9385 This function cancels echoing. */
9388 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9390 struct gcpro gcpro1
;
9393 clear_message (1,1);
9396 /* First flush out any partial line written with print. */
9397 message_log_maybe_newline ();
9403 SAFE_ALLOCA (buffer
, char *, nbytes
);
9404 memcpy (buffer
, SDATA (m
), nbytes
);
9405 message_dolog (buffer
, nbytes
, 1, multibyte
);
9408 message3_nolog (m
, nbytes
, multibyte
);
9414 /* The non-logging version of message3.
9415 This does not cancel echoing, because it is used for echoing.
9416 Perhaps we need to make a separate function for echoing
9417 and make this cancel echoing. */
9420 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9422 struct frame
*sf
= SELECTED_FRAME ();
9423 message_enable_multibyte
= multibyte
;
9425 if (FRAME_INITIAL_P (sf
))
9427 if (noninteractive_need_newline
)
9428 putc ('\n', stderr
);
9429 noninteractive_need_newline
= 0;
9431 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9432 if (cursor_in_echo_area
== 0)
9433 fprintf (stderr
, "\n");
9436 /* A null message buffer means that the frame hasn't really been
9437 initialized yet. Error messages get reported properly by
9438 cmd_error, so this must be just an informative message; toss it. */
9439 else if (INTERACTIVE
9440 && sf
->glyphs_initialized_p
9441 && FRAME_MESSAGE_BUF (sf
))
9443 Lisp_Object mini_window
;
9447 /* Get the frame containing the mini-buffer
9448 that the selected frame is using. */
9449 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9450 frame
= XWINDOW (mini_window
)->frame
;
9453 FRAME_SAMPLE_VISIBILITY (f
);
9454 if (FRAME_VISIBLE_P (sf
)
9455 && !FRAME_VISIBLE_P (f
))
9456 Fmake_frame_visible (frame
);
9458 if (STRINGP (m
) && SCHARS (m
) > 0)
9460 set_message (NULL
, m
, nbytes
, multibyte
);
9461 if (minibuffer_auto_raise
)
9462 Fraise_frame (frame
);
9463 /* Assume we are not echoing.
9464 (If we are, echo_now will override this.) */
9465 echo_message_buffer
= Qnil
;
9468 clear_message (1, 1);
9470 do_pending_window_change (0);
9471 echo_area_display (1);
9472 do_pending_window_change (0);
9473 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9474 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9479 /* Display a null-terminated echo area message M. If M is 0, clear
9480 out any existing message, and let the mini-buffer text show through.
9482 The buffer M must continue to exist until after the echo area gets
9483 cleared or some other message gets displayed there. Do not pass
9484 text that is stored in a Lisp string. Do not pass text in a buffer
9485 that was alloca'd. */
9488 message1 (const char *m
)
9490 message2 (m
, (m
? strlen (m
) : 0), 0);
9494 /* The non-logging counterpart of message1. */
9497 message1_nolog (const char *m
)
9499 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9502 /* Display a message M which contains a single %s
9503 which gets replaced with STRING. */
9506 message_with_string (const char *m
, Lisp_Object string
, int log
)
9508 CHECK_STRING (string
);
9514 if (noninteractive_need_newline
)
9515 putc ('\n', stderr
);
9516 noninteractive_need_newline
= 0;
9517 fprintf (stderr
, m
, SDATA (string
));
9518 if (!cursor_in_echo_area
)
9519 fprintf (stderr
, "\n");
9523 else if (INTERACTIVE
)
9525 /* The frame whose minibuffer we're going to display the message on.
9526 It may be larger than the selected frame, so we need
9527 to use its buffer, not the selected frame's buffer. */
9528 Lisp_Object mini_window
;
9529 struct frame
*f
, *sf
= SELECTED_FRAME ();
9531 /* Get the frame containing the minibuffer
9532 that the selected frame is using. */
9533 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9534 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9536 /* A null message buffer means that the frame hasn't really been
9537 initialized yet. Error messages get reported properly by
9538 cmd_error, so this must be just an informative message; toss it. */
9539 if (FRAME_MESSAGE_BUF (f
))
9541 Lisp_Object args
[2], msg
;
9542 struct gcpro gcpro1
, gcpro2
;
9544 args
[0] = build_string (m
);
9545 args
[1] = msg
= string
;
9546 GCPRO2 (args
[0], msg
);
9549 msg
= Fformat (2, args
);
9552 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9554 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9558 /* Print should start at the beginning of the message
9559 buffer next time. */
9560 message_buf_print
= 0;
9566 /* Dump an informative message to the minibuf. If M is 0, clear out
9567 any existing message, and let the mini-buffer text show through. */
9570 vmessage (const char *m
, va_list ap
)
9576 if (noninteractive_need_newline
)
9577 putc ('\n', stderr
);
9578 noninteractive_need_newline
= 0;
9579 vfprintf (stderr
, m
, ap
);
9580 if (cursor_in_echo_area
== 0)
9581 fprintf (stderr
, "\n");
9585 else if (INTERACTIVE
)
9587 /* The frame whose mini-buffer we're going to display the message
9588 on. It may be larger than the selected frame, so we need to
9589 use its buffer, not the selected frame's buffer. */
9590 Lisp_Object mini_window
;
9591 struct frame
*f
, *sf
= SELECTED_FRAME ();
9593 /* Get the frame containing the mini-buffer
9594 that the selected frame is using. */
9595 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9596 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9598 /* A null message buffer means that the frame hasn't really been
9599 initialized yet. Error messages get reported properly by
9600 cmd_error, so this must be just an informative message; toss
9602 if (FRAME_MESSAGE_BUF (f
))
9608 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9609 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9611 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9616 /* Print should start at the beginning of the message
9617 buffer next time. */
9618 message_buf_print
= 0;
9624 message (const char *m
, ...)
9634 /* The non-logging version of message. */
9637 message_nolog (const char *m
, ...)
9639 Lisp_Object old_log_max
;
9642 old_log_max
= Vmessage_log_max
;
9643 Vmessage_log_max
= Qnil
;
9645 Vmessage_log_max
= old_log_max
;
9651 /* Display the current message in the current mini-buffer. This is
9652 only called from error handlers in process.c, and is not time
9656 update_echo_area (void)
9658 if (!NILP (echo_area_buffer
[0]))
9661 string
= Fcurrent_message ();
9662 message3 (string
, SBYTES (string
),
9663 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9668 /* Make sure echo area buffers in `echo_buffers' are live.
9669 If they aren't, make new ones. */
9672 ensure_echo_area_buffers (void)
9676 for (i
= 0; i
< 2; ++i
)
9677 if (!BUFFERP (echo_buffer
[i
])
9678 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9681 Lisp_Object old_buffer
;
9684 old_buffer
= echo_buffer
[i
];
9685 sprintf (name
, " *Echo Area %d*", i
);
9686 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9687 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9688 /* to force word wrap in echo area -
9689 it was decided to postpone this*/
9690 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9692 for (j
= 0; j
< 2; ++j
)
9693 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9694 echo_area_buffer
[j
] = echo_buffer
[i
];
9699 /* Call FN with args A1..A4 with either the current or last displayed
9700 echo_area_buffer as current buffer.
9702 WHICH zero means use the current message buffer
9703 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9704 from echo_buffer[] and clear it.
9706 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9707 suitable buffer from echo_buffer[] and clear it.
9709 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9710 that the current message becomes the last displayed one, make
9711 choose a suitable buffer for echo_area_buffer[0], and clear it.
9713 Value is what FN returns. */
9716 with_echo_area_buffer (struct window
*w
, int which
,
9717 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9718 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9721 int this_one
, the_other
, clear_buffer_p
, rc
;
9722 ptrdiff_t count
= SPECPDL_INDEX ();
9724 /* If buffers aren't live, make new ones. */
9725 ensure_echo_area_buffers ();
9730 this_one
= 0, the_other
= 1;
9732 this_one
= 1, the_other
= 0;
9735 this_one
= 0, the_other
= 1;
9738 /* We need a fresh one in case the current echo buffer equals
9739 the one containing the last displayed echo area message. */
9740 if (!NILP (echo_area_buffer
[this_one
])
9741 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9742 echo_area_buffer
[this_one
] = Qnil
;
9745 /* Choose a suitable buffer from echo_buffer[] is we don't
9747 if (NILP (echo_area_buffer
[this_one
]))
9749 echo_area_buffer
[this_one
]
9750 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9751 ? echo_buffer
[the_other
]
9752 : echo_buffer
[this_one
]);
9756 buffer
= echo_area_buffer
[this_one
];
9758 /* Don't get confused by reusing the buffer used for echoing
9759 for a different purpose. */
9760 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9763 record_unwind_protect (unwind_with_echo_area_buffer
,
9764 with_echo_area_buffer_unwind_data (w
));
9766 /* Make the echo area buffer current. Note that for display
9767 purposes, it is not necessary that the displayed window's buffer
9768 == current_buffer, except for text property lookup. So, let's
9769 only set that buffer temporarily here without doing a full
9770 Fset_window_buffer. We must also change w->pointm, though,
9771 because otherwise an assertions in unshow_buffer fails, and Emacs
9773 set_buffer_internal_1 (XBUFFER (buffer
));
9777 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9780 BVAR (current_buffer
, undo_list
) = Qt
;
9781 BVAR (current_buffer
, read_only
) = Qnil
;
9782 specbind (Qinhibit_read_only
, Qt
);
9783 specbind (Qinhibit_modification_hooks
, Qt
);
9785 if (clear_buffer_p
&& Z
> BEG
)
9788 xassert (BEGV
>= BEG
);
9789 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9791 rc
= fn (a1
, a2
, a3
, a4
);
9793 xassert (BEGV
>= BEG
);
9794 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9796 unbind_to (count
, Qnil
);
9801 /* Save state that should be preserved around the call to the function
9802 FN called in with_echo_area_buffer. */
9805 with_echo_area_buffer_unwind_data (struct window
*w
)
9808 Lisp_Object vector
, tmp
;
9810 /* Reduce consing by keeping one vector in
9811 Vwith_echo_area_save_vector. */
9812 vector
= Vwith_echo_area_save_vector
;
9813 Vwith_echo_area_save_vector
= Qnil
;
9816 vector
= Fmake_vector (make_number (7), Qnil
);
9818 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9819 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9820 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9824 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9825 ASET (vector
, i
, w
->buffer
); ++i
;
9826 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9827 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9832 for (; i
< end
; ++i
)
9833 ASET (vector
, i
, Qnil
);
9836 xassert (i
== ASIZE (vector
));
9841 /* Restore global state from VECTOR which was created by
9842 with_echo_area_buffer_unwind_data. */
9845 unwind_with_echo_area_buffer (Lisp_Object vector
)
9847 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9848 Vdeactivate_mark
= AREF (vector
, 1);
9849 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9851 if (WINDOWP (AREF (vector
, 3)))
9854 Lisp_Object buffer
, charpos
, bytepos
;
9856 w
= XWINDOW (AREF (vector
, 3));
9857 buffer
= AREF (vector
, 4);
9858 charpos
= AREF (vector
, 5);
9859 bytepos
= AREF (vector
, 6);
9862 set_marker_both (w
->pointm
, buffer
,
9863 XFASTINT (charpos
), XFASTINT (bytepos
));
9866 Vwith_echo_area_save_vector
= vector
;
9871 /* Set up the echo area for use by print functions. MULTIBYTE_P
9872 non-zero means we will print multibyte. */
9875 setup_echo_area_for_printing (int multibyte_p
)
9877 /* If we can't find an echo area any more, exit. */
9878 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9881 ensure_echo_area_buffers ();
9883 if (!message_buf_print
)
9885 /* A message has been output since the last time we printed.
9886 Choose a fresh echo area buffer. */
9887 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9888 echo_area_buffer
[0] = echo_buffer
[1];
9890 echo_area_buffer
[0] = echo_buffer
[0];
9892 /* Switch to that buffer and clear it. */
9893 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9894 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9898 ptrdiff_t count
= SPECPDL_INDEX ();
9899 specbind (Qinhibit_read_only
, Qt
);
9900 /* Note that undo recording is always disabled. */
9902 unbind_to (count
, Qnil
);
9904 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9906 /* Set up the buffer for the multibyteness we need. */
9908 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9909 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9911 /* Raise the frame containing the echo area. */
9912 if (minibuffer_auto_raise
)
9914 struct frame
*sf
= SELECTED_FRAME ();
9915 Lisp_Object mini_window
;
9916 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9917 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9920 message_log_maybe_newline ();
9921 message_buf_print
= 1;
9925 if (NILP (echo_area_buffer
[0]))
9927 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9928 echo_area_buffer
[0] = echo_buffer
[1];
9930 echo_area_buffer
[0] = echo_buffer
[0];
9933 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9935 /* Someone switched buffers between print requests. */
9936 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9937 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9943 /* Display an echo area message in window W. Value is non-zero if W's
9944 height is changed. If display_last_displayed_message_p is
9945 non-zero, display the message that was last displayed, otherwise
9946 display the current message. */
9949 display_echo_area (struct window
*w
)
9951 int i
, no_message_p
, window_height_changed_p
;
9953 /* Temporarily disable garbage collections while displaying the echo
9954 area. This is done because a GC can print a message itself.
9955 That message would modify the echo area buffer's contents while a
9956 redisplay of the buffer is going on, and seriously confuse
9958 ptrdiff_t count
= inhibit_garbage_collection ();
9960 /* If there is no message, we must call display_echo_area_1
9961 nevertheless because it resizes the window. But we will have to
9962 reset the echo_area_buffer in question to nil at the end because
9963 with_echo_area_buffer will sets it to an empty buffer. */
9964 i
= display_last_displayed_message_p
? 1 : 0;
9965 no_message_p
= NILP (echo_area_buffer
[i
]);
9967 window_height_changed_p
9968 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9969 display_echo_area_1
,
9970 (intptr_t) w
, Qnil
, 0, 0);
9973 echo_area_buffer
[i
] = Qnil
;
9975 unbind_to (count
, Qnil
);
9976 return window_height_changed_p
;
9980 /* Helper for display_echo_area. Display the current buffer which
9981 contains the current echo area message in window W, a mini-window,
9982 a pointer to which is passed in A1. A2..A4 are currently not used.
9983 Change the height of W so that all of the message is displayed.
9984 Value is non-zero if height of W was changed. */
9987 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9990 struct window
*w
= (struct window
*) i1
;
9992 struct text_pos start
;
9993 int window_height_changed_p
= 0;
9995 /* Do this before displaying, so that we have a large enough glyph
9996 matrix for the display. If we can't get enough space for the
9997 whole text, display the last N lines. That works by setting w->start. */
9998 window_height_changed_p
= resize_mini_window (w
, 0);
10000 /* Use the starting position chosen by resize_mini_window. */
10001 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10004 clear_glyph_matrix (w
->desired_matrix
);
10005 XSETWINDOW (window
, w
);
10006 try_window (window
, start
, 0);
10008 return window_height_changed_p
;
10012 /* Resize the echo area window to exactly the size needed for the
10013 currently displayed message, if there is one. If a mini-buffer
10014 is active, don't shrink it. */
10017 resize_echo_area_exactly (void)
10019 if (BUFFERP (echo_area_buffer
[0])
10020 && WINDOWP (echo_area_window
))
10022 struct window
*w
= XWINDOW (echo_area_window
);
10024 Lisp_Object resize_exactly
;
10026 if (minibuf_level
== 0)
10027 resize_exactly
= Qt
;
10029 resize_exactly
= Qnil
;
10031 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10032 (intptr_t) w
, resize_exactly
,
10036 ++windows_or_buffers_changed
;
10037 ++update_mode_lines
;
10038 redisplay_internal ();
10044 /* Callback function for with_echo_area_buffer, when used from
10045 resize_echo_area_exactly. A1 contains a pointer to the window to
10046 resize, EXACTLY non-nil means resize the mini-window exactly to the
10047 size of the text displayed. A3 and A4 are not used. Value is what
10048 resize_mini_window returns. */
10051 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10054 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10058 /* Resize mini-window W to fit the size of its contents. EXACT_P
10059 means size the window exactly to the size needed. Otherwise, it's
10060 only enlarged until W's buffer is empty.
10062 Set W->start to the right place to begin display. If the whole
10063 contents fit, start at the beginning. Otherwise, start so as
10064 to make the end of the contents appear. This is particularly
10065 important for y-or-n-p, but seems desirable generally.
10067 Value is non-zero if the window height has been changed. */
10070 resize_mini_window (struct window
*w
, int exact_p
)
10072 struct frame
*f
= XFRAME (w
->frame
);
10073 int window_height_changed_p
= 0;
10075 xassert (MINI_WINDOW_P (w
));
10077 /* By default, start display at the beginning. */
10078 set_marker_both (w
->start
, w
->buffer
,
10079 BUF_BEGV (XBUFFER (w
->buffer
)),
10080 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10082 /* Don't resize windows while redisplaying a window; it would
10083 confuse redisplay functions when the size of the window they are
10084 displaying changes from under them. Such a resizing can happen,
10085 for instance, when which-func prints a long message while
10086 we are running fontification-functions. We're running these
10087 functions with safe_call which binds inhibit-redisplay to t. */
10088 if (!NILP (Vinhibit_redisplay
))
10091 /* Nil means don't try to resize. */
10092 if (NILP (Vresize_mini_windows
)
10093 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10096 if (!FRAME_MINIBUF_ONLY_P (f
))
10099 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10100 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10102 EMACS_INT max_height
;
10103 int unit
= FRAME_LINE_HEIGHT (f
);
10104 struct text_pos start
;
10105 struct buffer
*old_current_buffer
= NULL
;
10107 if (current_buffer
!= XBUFFER (w
->buffer
))
10109 old_current_buffer
= current_buffer
;
10110 set_buffer_internal (XBUFFER (w
->buffer
));
10113 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10115 /* Compute the max. number of lines specified by the user. */
10116 if (FLOATP (Vmax_mini_window_height
))
10117 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10118 else if (INTEGERP (Vmax_mini_window_height
))
10119 max_height
= XINT (Vmax_mini_window_height
);
10121 max_height
= total_height
/ 4;
10123 /* Correct that max. height if it's bogus. */
10124 max_height
= max (1, max_height
);
10125 max_height
= min (total_height
, max_height
);
10127 /* Find out the height of the text in the window. */
10128 if (it
.line_wrap
== TRUNCATE
)
10133 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10134 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10135 height
= it
.current_y
+ last_height
;
10137 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10138 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10139 height
= (height
+ unit
- 1) / unit
;
10142 /* Compute a suitable window start. */
10143 if (height
> max_height
)
10145 height
= max_height
;
10146 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10147 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10148 start
= it
.current
.pos
;
10151 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10152 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10154 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10156 /* Let it grow only, until we display an empty message, in which
10157 case the window shrinks again. */
10158 if (height
> WINDOW_TOTAL_LINES (w
))
10160 int old_height
= WINDOW_TOTAL_LINES (w
);
10161 freeze_window_starts (f
, 1);
10162 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10163 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10165 else if (height
< WINDOW_TOTAL_LINES (w
)
10166 && (exact_p
|| BEGV
== ZV
))
10168 int old_height
= WINDOW_TOTAL_LINES (w
);
10169 freeze_window_starts (f
, 0);
10170 shrink_mini_window (w
);
10171 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10176 /* Always resize to exact size needed. */
10177 if (height
> WINDOW_TOTAL_LINES (w
))
10179 int old_height
= WINDOW_TOTAL_LINES (w
);
10180 freeze_window_starts (f
, 1);
10181 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10182 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10184 else if (height
< WINDOW_TOTAL_LINES (w
))
10186 int old_height
= WINDOW_TOTAL_LINES (w
);
10187 freeze_window_starts (f
, 0);
10188 shrink_mini_window (w
);
10192 freeze_window_starts (f
, 1);
10193 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10196 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10200 if (old_current_buffer
)
10201 set_buffer_internal (old_current_buffer
);
10204 return window_height_changed_p
;
10208 /* Value is the current message, a string, or nil if there is no
10209 current message. */
10212 current_message (void)
10216 if (!BUFFERP (echo_area_buffer
[0]))
10220 with_echo_area_buffer (0, 0, current_message_1
,
10221 (intptr_t) &msg
, Qnil
, 0, 0);
10223 echo_area_buffer
[0] = Qnil
;
10231 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10234 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10237 *msg
= make_buffer_string (BEG
, Z
, 1);
10244 /* Push the current message on Vmessage_stack for later restoration
10245 by restore_message. Value is non-zero if the current message isn't
10246 empty. This is a relatively infrequent operation, so it's not
10247 worth optimizing. */
10250 push_message (void)
10253 msg
= current_message ();
10254 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10255 return STRINGP (msg
);
10259 /* Restore message display from the top of Vmessage_stack. */
10262 restore_message (void)
10266 xassert (CONSP (Vmessage_stack
));
10267 msg
= XCAR (Vmessage_stack
);
10269 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10271 message3_nolog (msg
, 0, 0);
10275 /* Handler for record_unwind_protect calling pop_message. */
10278 pop_message_unwind (Lisp_Object dummy
)
10284 /* Pop the top-most entry off Vmessage_stack. */
10289 xassert (CONSP (Vmessage_stack
));
10290 Vmessage_stack
= XCDR (Vmessage_stack
);
10294 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10295 exits. If the stack is not empty, we have a missing pop_message
10299 check_message_stack (void)
10301 if (!NILP (Vmessage_stack
))
10306 /* Truncate to NCHARS what will be displayed in the echo area the next
10307 time we display it---but don't redisplay it now. */
10310 truncate_echo_area (ptrdiff_t nchars
)
10313 echo_area_buffer
[0] = Qnil
;
10314 /* A null message buffer means that the frame hasn't really been
10315 initialized yet. Error messages get reported properly by
10316 cmd_error, so this must be just an informative message; toss it. */
10317 else if (!noninteractive
10319 && !NILP (echo_area_buffer
[0]))
10321 struct frame
*sf
= SELECTED_FRAME ();
10322 if (FRAME_MESSAGE_BUF (sf
))
10323 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10328 /* Helper function for truncate_echo_area. Truncate the current
10329 message to at most NCHARS characters. */
10332 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10334 if (BEG
+ nchars
< Z
)
10335 del_range (BEG
+ nchars
, Z
);
10337 echo_area_buffer
[0] = Qnil
;
10342 /* Set the current message to a substring of S or STRING.
10344 If STRING is a Lisp string, set the message to the first NBYTES
10345 bytes from STRING. NBYTES zero means use the whole string. If
10346 STRING is multibyte, the message will be displayed multibyte.
10348 If S is not null, set the message to the first LEN bytes of S. LEN
10349 zero means use the whole string. MULTIBYTE_P non-zero means S is
10350 multibyte. Display the message multibyte in that case.
10352 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10353 to t before calling set_message_1 (which calls insert).
10357 set_message (const char *s
, Lisp_Object string
,
10358 ptrdiff_t nbytes
, int multibyte_p
)
10360 message_enable_multibyte
10361 = ((s
&& multibyte_p
)
10362 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10364 with_echo_area_buffer (0, -1, set_message_1
,
10365 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10366 message_buf_print
= 0;
10367 help_echo_showing_p
= 0;
10371 /* Helper function for set_message. Arguments have the same meaning
10372 as there, with A1 corresponding to S and A2 corresponding to STRING
10373 This function is called with the echo area buffer being
10377 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10380 const char *s
= (const char *) i1
;
10381 const unsigned char *msg
= (const unsigned char *) s
;
10382 Lisp_Object string
= a2
;
10384 /* Change multibyteness of the echo buffer appropriately. */
10385 if (message_enable_multibyte
10386 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10387 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10389 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10390 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10391 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10393 /* Insert new message at BEG. */
10394 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10396 if (STRINGP (string
))
10401 nbytes
= SBYTES (string
);
10402 nchars
= string_byte_to_char (string
, nbytes
);
10404 /* This function takes care of single/multibyte conversion. We
10405 just have to ensure that the echo area buffer has the right
10406 setting of enable_multibyte_characters. */
10407 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10412 nbytes
= strlen (s
);
10414 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10416 /* Convert from multi-byte to single-byte. */
10421 /* Convert a multibyte string to single-byte. */
10422 for (i
= 0; i
< nbytes
; i
+= n
)
10424 c
= string_char_and_length (msg
+ i
, &n
);
10425 work
[0] = (ASCII_CHAR_P (c
)
10427 : multibyte_char_to_unibyte (c
));
10428 insert_1_both (work
, 1, 1, 1, 0, 0);
10431 else if (!multibyte_p
10432 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10434 /* Convert from single-byte to multi-byte. */
10437 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10439 /* Convert a single-byte string to multibyte. */
10440 for (i
= 0; i
< nbytes
; i
++)
10443 MAKE_CHAR_MULTIBYTE (c
);
10444 n
= CHAR_STRING (c
, str
);
10445 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10449 insert_1 (s
, nbytes
, 1, 0, 0);
10456 /* Clear messages. CURRENT_P non-zero means clear the current
10457 message. LAST_DISPLAYED_P non-zero means clear the message
10461 clear_message (int current_p
, int last_displayed_p
)
10465 echo_area_buffer
[0] = Qnil
;
10466 message_cleared_p
= 1;
10469 if (last_displayed_p
)
10470 echo_area_buffer
[1] = Qnil
;
10472 message_buf_print
= 0;
10475 /* Clear garbaged frames.
10477 This function is used where the old redisplay called
10478 redraw_garbaged_frames which in turn called redraw_frame which in
10479 turn called clear_frame. The call to clear_frame was a source of
10480 flickering. I believe a clear_frame is not necessary. It should
10481 suffice in the new redisplay to invalidate all current matrices,
10482 and ensure a complete redisplay of all windows. */
10485 clear_garbaged_frames (void)
10487 if (frame_garbaged
)
10489 Lisp_Object tail
, frame
;
10490 int changed_count
= 0;
10492 FOR_EACH_FRAME (tail
, frame
)
10494 struct frame
*f
= XFRAME (frame
);
10496 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10500 Fredraw_frame (frame
);
10501 f
->force_flush_display_p
= 1;
10503 clear_current_matrices (f
);
10510 frame_garbaged
= 0;
10512 ++windows_or_buffers_changed
;
10517 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10518 is non-zero update selected_frame. Value is non-zero if the
10519 mini-windows height has been changed. */
10522 echo_area_display (int update_frame_p
)
10524 Lisp_Object mini_window
;
10527 int window_height_changed_p
= 0;
10528 struct frame
*sf
= SELECTED_FRAME ();
10530 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10531 w
= XWINDOW (mini_window
);
10532 f
= XFRAME (WINDOW_FRAME (w
));
10534 /* Don't display if frame is invisible or not yet initialized. */
10535 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10538 #ifdef HAVE_WINDOW_SYSTEM
10539 /* When Emacs starts, selected_frame may be the initial terminal
10540 frame. If we let this through, a message would be displayed on
10542 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10544 #endif /* HAVE_WINDOW_SYSTEM */
10546 /* Redraw garbaged frames. */
10547 if (frame_garbaged
)
10548 clear_garbaged_frames ();
10550 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10552 echo_area_window
= mini_window
;
10553 window_height_changed_p
= display_echo_area (w
);
10554 w
->must_be_updated_p
= 1;
10556 /* Update the display, unless called from redisplay_internal.
10557 Also don't update the screen during redisplay itself. The
10558 update will happen at the end of redisplay, and an update
10559 here could cause confusion. */
10560 if (update_frame_p
&& !redisplaying_p
)
10564 /* If the display update has been interrupted by pending
10565 input, update mode lines in the frame. Due to the
10566 pending input, it might have been that redisplay hasn't
10567 been called, so that mode lines above the echo area are
10568 garbaged. This looks odd, so we prevent it here. */
10569 if (!display_completed
)
10570 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10572 if (window_height_changed_p
10573 /* Don't do this if Emacs is shutting down. Redisplay
10574 needs to run hooks. */
10575 && !NILP (Vrun_hooks
))
10577 /* Must update other windows. Likewise as in other
10578 cases, don't let this update be interrupted by
10580 ptrdiff_t count
= SPECPDL_INDEX ();
10581 specbind (Qredisplay_dont_pause
, Qt
);
10582 windows_or_buffers_changed
= 1;
10583 redisplay_internal ();
10584 unbind_to (count
, Qnil
);
10586 else if (FRAME_WINDOW_P (f
) && n
== 0)
10588 /* Window configuration is the same as before.
10589 Can do with a display update of the echo area,
10590 unless we displayed some mode lines. */
10591 update_single_window (w
, 1);
10592 FRAME_RIF (f
)->flush_display (f
);
10595 update_frame (f
, 1, 1);
10597 /* If cursor is in the echo area, make sure that the next
10598 redisplay displays the minibuffer, so that the cursor will
10599 be replaced with what the minibuffer wants. */
10600 if (cursor_in_echo_area
)
10601 ++windows_or_buffers_changed
;
10604 else if (!EQ (mini_window
, selected_window
))
10605 windows_or_buffers_changed
++;
10607 /* Last displayed message is now the current message. */
10608 echo_area_buffer
[1] = echo_area_buffer
[0];
10609 /* Inform read_char that we're not echoing. */
10610 echo_message_buffer
= Qnil
;
10612 /* Prevent redisplay optimization in redisplay_internal by resetting
10613 this_line_start_pos. This is done because the mini-buffer now
10614 displays the message instead of its buffer text. */
10615 if (EQ (mini_window
, selected_window
))
10616 CHARPOS (this_line_start_pos
) = 0;
10618 return window_height_changed_p
;
10623 /***********************************************************************
10624 Mode Lines and Frame Titles
10625 ***********************************************************************/
10627 /* A buffer for constructing non-propertized mode-line strings and
10628 frame titles in it; allocated from the heap in init_xdisp and
10629 resized as needed in store_mode_line_noprop_char. */
10631 static char *mode_line_noprop_buf
;
10633 /* The buffer's end, and a current output position in it. */
10635 static char *mode_line_noprop_buf_end
;
10636 static char *mode_line_noprop_ptr
;
10638 #define MODE_LINE_NOPROP_LEN(start) \
10639 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10642 MODE_LINE_DISPLAY
= 0,
10646 } mode_line_target
;
10648 /* Alist that caches the results of :propertize.
10649 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10650 static Lisp_Object mode_line_proptrans_alist
;
10652 /* List of strings making up the mode-line. */
10653 static Lisp_Object mode_line_string_list
;
10655 /* Base face property when building propertized mode line string. */
10656 static Lisp_Object mode_line_string_face
;
10657 static Lisp_Object mode_line_string_face_prop
;
10660 /* Unwind data for mode line strings */
10662 static Lisp_Object Vmode_line_unwind_vector
;
10665 format_mode_line_unwind_data (struct buffer
*obuf
,
10667 int save_proptrans
)
10669 Lisp_Object vector
, tmp
;
10671 /* Reduce consing by keeping one vector in
10672 Vwith_echo_area_save_vector. */
10673 vector
= Vmode_line_unwind_vector
;
10674 Vmode_line_unwind_vector
= Qnil
;
10677 vector
= Fmake_vector (make_number (8), Qnil
);
10679 ASET (vector
, 0, make_number (mode_line_target
));
10680 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10681 ASET (vector
, 2, mode_line_string_list
);
10682 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10683 ASET (vector
, 4, mode_line_string_face
);
10684 ASET (vector
, 5, mode_line_string_face_prop
);
10687 XSETBUFFER (tmp
, obuf
);
10690 ASET (vector
, 6, tmp
);
10691 ASET (vector
, 7, owin
);
10697 unwind_format_mode_line (Lisp_Object vector
)
10699 mode_line_target
= XINT (AREF (vector
, 0));
10700 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10701 mode_line_string_list
= AREF (vector
, 2);
10702 if (! EQ (AREF (vector
, 3), Qt
))
10703 mode_line_proptrans_alist
= AREF (vector
, 3);
10704 mode_line_string_face
= AREF (vector
, 4);
10705 mode_line_string_face_prop
= AREF (vector
, 5);
10707 if (!NILP (AREF (vector
, 7)))
10708 /* Select window before buffer, since it may change the buffer. */
10709 Fselect_window (AREF (vector
, 7), Qt
);
10711 if (!NILP (AREF (vector
, 6)))
10713 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10714 ASET (vector
, 6, Qnil
);
10717 Vmode_line_unwind_vector
= vector
;
10722 /* Store a single character C for the frame title in mode_line_noprop_buf.
10723 Re-allocate mode_line_noprop_buf if necessary. */
10726 store_mode_line_noprop_char (char c
)
10728 /* If output position has reached the end of the allocated buffer,
10729 increase the buffer's size. */
10730 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10732 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10733 ptrdiff_t size
= len
;
10734 mode_line_noprop_buf
=
10735 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10736 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10737 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10740 *mode_line_noprop_ptr
++ = c
;
10744 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10745 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10746 characters that yield more columns than PRECISION; PRECISION <= 0
10747 means copy the whole string. Pad with spaces until FIELD_WIDTH
10748 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10749 pad. Called from display_mode_element when it is used to build a
10753 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10755 const unsigned char *str
= (const unsigned char *) string
;
10757 ptrdiff_t dummy
, nbytes
;
10759 /* Copy at most PRECISION chars from STR. */
10760 nbytes
= strlen (string
);
10761 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10763 store_mode_line_noprop_char (*str
++);
10765 /* Fill up with spaces until FIELD_WIDTH reached. */
10766 while (field_width
> 0
10767 && n
< field_width
)
10769 store_mode_line_noprop_char (' ');
10776 /***********************************************************************
10778 ***********************************************************************/
10780 #ifdef HAVE_WINDOW_SYSTEM
10782 /* Set the title of FRAME, if it has changed. The title format is
10783 Vicon_title_format if FRAME is iconified, otherwise it is
10784 frame_title_format. */
10787 x_consider_frame_title (Lisp_Object frame
)
10789 struct frame
*f
= XFRAME (frame
);
10791 if (FRAME_WINDOW_P (f
)
10792 || FRAME_MINIBUF_ONLY_P (f
)
10793 || f
->explicit_name
)
10795 /* Do we have more than one visible frame on this X display? */
10798 ptrdiff_t title_start
;
10802 ptrdiff_t count
= SPECPDL_INDEX ();
10804 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10806 Lisp_Object other_frame
= XCAR (tail
);
10807 struct frame
*tf
= XFRAME (other_frame
);
10810 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10811 && !FRAME_MINIBUF_ONLY_P (tf
)
10812 && !EQ (other_frame
, tip_frame
)
10813 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10817 /* Set global variable indicating that multiple frames exist. */
10818 multiple_frames
= CONSP (tail
);
10820 /* Switch to the buffer of selected window of the frame. Set up
10821 mode_line_target so that display_mode_element will output into
10822 mode_line_noprop_buf; then display the title. */
10823 record_unwind_protect (unwind_format_mode_line
,
10824 format_mode_line_unwind_data
10825 (current_buffer
, selected_window
, 0));
10827 Fselect_window (f
->selected_window
, Qt
);
10828 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10829 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10831 mode_line_target
= MODE_LINE_TITLE
;
10832 title_start
= MODE_LINE_NOPROP_LEN (0);
10833 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10834 NULL
, DEFAULT_FACE_ID
);
10835 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10836 len
= MODE_LINE_NOPROP_LEN (title_start
);
10837 title
= mode_line_noprop_buf
+ title_start
;
10838 unbind_to (count
, Qnil
);
10840 /* Set the title only if it's changed. This avoids consing in
10841 the common case where it hasn't. (If it turns out that we've
10842 already wasted too much time by walking through the list with
10843 display_mode_element, then we might need to optimize at a
10844 higher level than this.) */
10845 if (! STRINGP (f
->name
)
10846 || SBYTES (f
->name
) != len
10847 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10848 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10852 #endif /* not HAVE_WINDOW_SYSTEM */
10857 /***********************************************************************
10859 ***********************************************************************/
10862 /* Prepare for redisplay by updating menu-bar item lists when
10863 appropriate. This can call eval. */
10866 prepare_menu_bars (void)
10869 struct gcpro gcpro1
, gcpro2
;
10871 Lisp_Object tooltip_frame
;
10873 #ifdef HAVE_WINDOW_SYSTEM
10874 tooltip_frame
= tip_frame
;
10876 tooltip_frame
= Qnil
;
10879 /* Update all frame titles based on their buffer names, etc. We do
10880 this before the menu bars so that the buffer-menu will show the
10881 up-to-date frame titles. */
10882 #ifdef HAVE_WINDOW_SYSTEM
10883 if (windows_or_buffers_changed
|| update_mode_lines
)
10885 Lisp_Object tail
, frame
;
10887 FOR_EACH_FRAME (tail
, frame
)
10889 f
= XFRAME (frame
);
10890 if (!EQ (frame
, tooltip_frame
)
10891 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10892 x_consider_frame_title (frame
);
10895 #endif /* HAVE_WINDOW_SYSTEM */
10897 /* Update the menu bar item lists, if appropriate. This has to be
10898 done before any actual redisplay or generation of display lines. */
10899 all_windows
= (update_mode_lines
10900 || buffer_shared
> 1
10901 || windows_or_buffers_changed
);
10904 Lisp_Object tail
, frame
;
10905 ptrdiff_t count
= SPECPDL_INDEX ();
10906 /* 1 means that update_menu_bar has run its hooks
10907 so any further calls to update_menu_bar shouldn't do so again. */
10908 int menu_bar_hooks_run
= 0;
10910 record_unwind_save_match_data ();
10912 FOR_EACH_FRAME (tail
, frame
)
10914 f
= XFRAME (frame
);
10916 /* Ignore tooltip frame. */
10917 if (EQ (frame
, tooltip_frame
))
10920 /* If a window on this frame changed size, report that to
10921 the user and clear the size-change flag. */
10922 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10924 Lisp_Object functions
;
10926 /* Clear flag first in case we get an error below. */
10927 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10928 functions
= Vwindow_size_change_functions
;
10929 GCPRO2 (tail
, functions
);
10931 while (CONSP (functions
))
10933 if (!EQ (XCAR (functions
), Qt
))
10934 call1 (XCAR (functions
), frame
);
10935 functions
= XCDR (functions
);
10941 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10942 #ifdef HAVE_WINDOW_SYSTEM
10943 update_tool_bar (f
, 0);
10946 if (windows_or_buffers_changed
10948 ns_set_doc_edited (f
, Fbuffer_modified_p
10949 (XWINDOW (f
->selected_window
)->buffer
));
10954 unbind_to (count
, Qnil
);
10958 struct frame
*sf
= SELECTED_FRAME ();
10959 update_menu_bar (sf
, 1, 0);
10960 #ifdef HAVE_WINDOW_SYSTEM
10961 update_tool_bar (sf
, 1);
10967 /* Update the menu bar item list for frame F. This has to be done
10968 before we start to fill in any display lines, because it can call
10971 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10973 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10974 already ran the menu bar hooks for this redisplay, so there
10975 is no need to run them again. The return value is the
10976 updated value of this flag, to pass to the next call. */
10979 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10981 Lisp_Object window
;
10982 register struct window
*w
;
10984 /* If called recursively during a menu update, do nothing. This can
10985 happen when, for instance, an activate-menubar-hook causes a
10987 if (inhibit_menubar_update
)
10990 window
= FRAME_SELECTED_WINDOW (f
);
10991 w
= XWINDOW (window
);
10993 if (FRAME_WINDOW_P (f
)
10995 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10996 || defined (HAVE_NS) || defined (USE_GTK)
10997 FRAME_EXTERNAL_MENU_BAR (f
)
10999 FRAME_MENU_BAR_LINES (f
) > 0
11001 : FRAME_MENU_BAR_LINES (f
) > 0)
11003 /* If the user has switched buffers or windows, we need to
11004 recompute to reflect the new bindings. But we'll
11005 recompute when update_mode_lines is set too; that means
11006 that people can use force-mode-line-update to request
11007 that the menu bar be recomputed. The adverse effect on
11008 the rest of the redisplay algorithm is about the same as
11009 windows_or_buffers_changed anyway. */
11010 if (windows_or_buffers_changed
11011 /* This used to test w->update_mode_line, but we believe
11012 there is no need to recompute the menu in that case. */
11013 || update_mode_lines
11014 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11015 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11016 != !NILP (w
->last_had_star
))
11017 || ((!NILP (Vtransient_mark_mode
)
11018 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11019 != !NILP (w
->region_showing
)))
11021 struct buffer
*prev
= current_buffer
;
11022 ptrdiff_t count
= SPECPDL_INDEX ();
11024 specbind (Qinhibit_menubar_update
, Qt
);
11026 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11027 if (save_match_data
)
11028 record_unwind_save_match_data ();
11029 if (NILP (Voverriding_local_map_menu_flag
))
11031 specbind (Qoverriding_terminal_local_map
, Qnil
);
11032 specbind (Qoverriding_local_map
, Qnil
);
11037 /* Run the Lucid hook. */
11038 safe_run_hooks (Qactivate_menubar_hook
);
11040 /* If it has changed current-menubar from previous value,
11041 really recompute the menu-bar from the value. */
11042 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11043 call0 (Qrecompute_lucid_menubar
);
11045 safe_run_hooks (Qmenu_bar_update_hook
);
11050 XSETFRAME (Vmenu_updating_frame
, f
);
11051 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11053 /* Redisplay the menu bar in case we changed it. */
11054 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11055 || defined (HAVE_NS) || defined (USE_GTK)
11056 if (FRAME_WINDOW_P (f
))
11058 #if defined (HAVE_NS)
11059 /* All frames on Mac OS share the same menubar. So only
11060 the selected frame should be allowed to set it. */
11061 if (f
== SELECTED_FRAME ())
11063 set_frame_menubar (f
, 0, 0);
11066 /* On a terminal screen, the menu bar is an ordinary screen
11067 line, and this makes it get updated. */
11068 w
->update_mode_line
= Qt
;
11069 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11070 /* In the non-toolkit version, the menu bar is an ordinary screen
11071 line, and this makes it get updated. */
11072 w
->update_mode_line
= Qt
;
11073 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11075 unbind_to (count
, Qnil
);
11076 set_buffer_internal_1 (prev
);
11085 /***********************************************************************
11087 ***********************************************************************/
11089 #ifdef HAVE_WINDOW_SYSTEM
11092 Nominal cursor position -- where to draw output.
11093 HPOS and VPOS are window relative glyph matrix coordinates.
11094 X and Y are window relative pixel coordinates. */
11096 struct cursor_pos output_cursor
;
11100 Set the global variable output_cursor to CURSOR. All cursor
11101 positions are relative to updated_window. */
11104 set_output_cursor (struct cursor_pos
*cursor
)
11106 output_cursor
.hpos
= cursor
->hpos
;
11107 output_cursor
.vpos
= cursor
->vpos
;
11108 output_cursor
.x
= cursor
->x
;
11109 output_cursor
.y
= cursor
->y
;
11114 Set a nominal cursor position.
11116 HPOS and VPOS are column/row positions in a window glyph matrix. X
11117 and Y are window text area relative pixel positions.
11119 If this is done during an update, updated_window will contain the
11120 window that is being updated and the position is the future output
11121 cursor position for that window. If updated_window is null, use
11122 selected_window and display the cursor at the given position. */
11125 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11129 /* If updated_window is not set, work on selected_window. */
11130 if (updated_window
)
11131 w
= updated_window
;
11133 w
= XWINDOW (selected_window
);
11135 /* Set the output cursor. */
11136 output_cursor
.hpos
= hpos
;
11137 output_cursor
.vpos
= vpos
;
11138 output_cursor
.x
= x
;
11139 output_cursor
.y
= y
;
11141 /* If not called as part of an update, really display the cursor.
11142 This will also set the cursor position of W. */
11143 if (updated_window
== NULL
)
11146 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11147 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11148 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11153 #endif /* HAVE_WINDOW_SYSTEM */
11156 /***********************************************************************
11158 ***********************************************************************/
11160 #ifdef HAVE_WINDOW_SYSTEM
11162 /* Where the mouse was last time we reported a mouse event. */
11164 FRAME_PTR last_mouse_frame
;
11166 /* Tool-bar item index of the item on which a mouse button was pressed
11169 int last_tool_bar_item
;
11173 update_tool_bar_unwind (Lisp_Object frame
)
11175 selected_frame
= frame
;
11179 /* Update the tool-bar item list for frame F. This has to be done
11180 before we start to fill in any display lines. Called from
11181 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11182 and restore it here. */
11185 update_tool_bar (struct frame
*f
, int save_match_data
)
11187 #if defined (USE_GTK) || defined (HAVE_NS)
11188 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11190 int do_update
= WINDOWP (f
->tool_bar_window
)
11191 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11196 Lisp_Object window
;
11199 window
= FRAME_SELECTED_WINDOW (f
);
11200 w
= XWINDOW (window
);
11202 /* If the user has switched buffers or windows, we need to
11203 recompute to reflect the new bindings. But we'll
11204 recompute when update_mode_lines is set too; that means
11205 that people can use force-mode-line-update to request
11206 that the menu bar be recomputed. The adverse effect on
11207 the rest of the redisplay algorithm is about the same as
11208 windows_or_buffers_changed anyway. */
11209 if (windows_or_buffers_changed
11210 || !NILP (w
->update_mode_line
)
11211 || update_mode_lines
11212 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11213 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11214 != !NILP (w
->last_had_star
))
11215 || ((!NILP (Vtransient_mark_mode
)
11216 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11217 != !NILP (w
->region_showing
)))
11219 struct buffer
*prev
= current_buffer
;
11220 ptrdiff_t count
= SPECPDL_INDEX ();
11221 Lisp_Object frame
, new_tool_bar
;
11222 int new_n_tool_bar
;
11223 struct gcpro gcpro1
;
11225 /* Set current_buffer to the buffer of the selected
11226 window of the frame, so that we get the right local
11228 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11230 /* Save match data, if we must. */
11231 if (save_match_data
)
11232 record_unwind_save_match_data ();
11234 /* Make sure that we don't accidentally use bogus keymaps. */
11235 if (NILP (Voverriding_local_map_menu_flag
))
11237 specbind (Qoverriding_terminal_local_map
, Qnil
);
11238 specbind (Qoverriding_local_map
, Qnil
);
11241 GCPRO1 (new_tool_bar
);
11243 /* We must temporarily set the selected frame to this frame
11244 before calling tool_bar_items, because the calculation of
11245 the tool-bar keymap uses the selected frame (see
11246 `tool-bar-make-keymap' in tool-bar.el). */
11247 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11248 XSETFRAME (frame
, f
);
11249 selected_frame
= frame
;
11251 /* Build desired tool-bar items from keymaps. */
11252 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11255 /* Redisplay the tool-bar if we changed it. */
11256 if (new_n_tool_bar
!= f
->n_tool_bar_items
11257 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11259 /* Redisplay that happens asynchronously due to an expose event
11260 may access f->tool_bar_items. Make sure we update both
11261 variables within BLOCK_INPUT so no such event interrupts. */
11263 f
->tool_bar_items
= new_tool_bar
;
11264 f
->n_tool_bar_items
= new_n_tool_bar
;
11265 w
->update_mode_line
= Qt
;
11271 unbind_to (count
, Qnil
);
11272 set_buffer_internal_1 (prev
);
11278 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11279 F's desired tool-bar contents. F->tool_bar_items must have
11280 been set up previously by calling prepare_menu_bars. */
11283 build_desired_tool_bar_string (struct frame
*f
)
11285 int i
, size
, size_needed
;
11286 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11287 Lisp_Object image
, plist
, props
;
11289 image
= plist
= props
= Qnil
;
11290 GCPRO3 (image
, plist
, props
);
11292 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11293 Otherwise, make a new string. */
11295 /* The size of the string we might be able to reuse. */
11296 size
= (STRINGP (f
->desired_tool_bar_string
)
11297 ? SCHARS (f
->desired_tool_bar_string
)
11300 /* We need one space in the string for each image. */
11301 size_needed
= f
->n_tool_bar_items
;
11303 /* Reuse f->desired_tool_bar_string, if possible. */
11304 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11305 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11306 make_number (' '));
11309 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11310 Fremove_text_properties (make_number (0), make_number (size
),
11311 props
, f
->desired_tool_bar_string
);
11314 /* Put a `display' property on the string for the images to display,
11315 put a `menu_item' property on tool-bar items with a value that
11316 is the index of the item in F's tool-bar item vector. */
11317 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11319 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11321 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11322 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11323 int hmargin
, vmargin
, relief
, idx
, end
;
11325 /* If image is a vector, choose the image according to the
11327 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11328 if (VECTORP (image
))
11332 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11333 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11336 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11337 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11339 xassert (ASIZE (image
) >= idx
);
11340 image
= AREF (image
, idx
);
11345 /* Ignore invalid image specifications. */
11346 if (!valid_image_p (image
))
11349 /* Display the tool-bar button pressed, or depressed. */
11350 plist
= Fcopy_sequence (XCDR (image
));
11352 /* Compute margin and relief to draw. */
11353 relief
= (tool_bar_button_relief
>= 0
11354 ? tool_bar_button_relief
11355 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11356 hmargin
= vmargin
= relief
;
11358 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11359 INT_MAX
- max (hmargin
, vmargin
)))
11361 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11362 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11364 else if (CONSP (Vtool_bar_button_margin
))
11366 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11367 INT_MAX
- hmargin
))
11368 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11370 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11371 INT_MAX
- vmargin
))
11372 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11375 if (auto_raise_tool_bar_buttons_p
)
11377 /* Add a `:relief' property to the image spec if the item is
11381 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11388 /* If image is selected, display it pressed, i.e. with a
11389 negative relief. If it's not selected, display it with a
11391 plist
= Fplist_put (plist
, QCrelief
,
11393 ? make_number (-relief
)
11394 : make_number (relief
)));
11399 /* Put a margin around the image. */
11400 if (hmargin
|| vmargin
)
11402 if (hmargin
== vmargin
)
11403 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11405 plist
= Fplist_put (plist
, QCmargin
,
11406 Fcons (make_number (hmargin
),
11407 make_number (vmargin
)));
11410 /* If button is not enabled, and we don't have special images
11411 for the disabled state, make the image appear disabled by
11412 applying an appropriate algorithm to it. */
11413 if (!enabled_p
&& idx
< 0)
11414 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11416 /* Put a `display' text property on the string for the image to
11417 display. Put a `menu-item' property on the string that gives
11418 the start of this item's properties in the tool-bar items
11420 image
= Fcons (Qimage
, plist
);
11421 props
= list4 (Qdisplay
, image
,
11422 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11424 /* Let the last image hide all remaining spaces in the tool bar
11425 string. The string can be longer than needed when we reuse a
11426 previous string. */
11427 if (i
+ 1 == f
->n_tool_bar_items
)
11428 end
= SCHARS (f
->desired_tool_bar_string
);
11431 Fadd_text_properties (make_number (i
), make_number (end
),
11432 props
, f
->desired_tool_bar_string
);
11440 /* Display one line of the tool-bar of frame IT->f.
11442 HEIGHT specifies the desired height of the tool-bar line.
11443 If the actual height of the glyph row is less than HEIGHT, the
11444 row's height is increased to HEIGHT, and the icons are centered
11445 vertically in the new height.
11447 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11448 count a final empty row in case the tool-bar width exactly matches
11453 display_tool_bar_line (struct it
*it
, int height
)
11455 struct glyph_row
*row
= it
->glyph_row
;
11456 int max_x
= it
->last_visible_x
;
11457 struct glyph
*last
;
11459 prepare_desired_row (row
);
11460 row
->y
= it
->current_y
;
11462 /* Note that this isn't made use of if the face hasn't a box,
11463 so there's no need to check the face here. */
11464 it
->start_of_box_run_p
= 1;
11466 while (it
->current_x
< max_x
)
11468 int x
, n_glyphs_before
, i
, nglyphs
;
11469 struct it it_before
;
11471 /* Get the next display element. */
11472 if (!get_next_display_element (it
))
11474 /* Don't count empty row if we are counting needed tool-bar lines. */
11475 if (height
< 0 && !it
->hpos
)
11480 /* Produce glyphs. */
11481 n_glyphs_before
= row
->used
[TEXT_AREA
];
11484 PRODUCE_GLYPHS (it
);
11486 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11488 x
= it_before
.current_x
;
11489 while (i
< nglyphs
)
11491 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11493 if (x
+ glyph
->pixel_width
> max_x
)
11495 /* Glyph doesn't fit on line. Backtrack. */
11496 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11498 /* If this is the only glyph on this line, it will never fit on the
11499 tool-bar, so skip it. But ensure there is at least one glyph,
11500 so we don't accidentally disable the tool-bar. */
11501 if (n_glyphs_before
== 0
11502 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11508 x
+= glyph
->pixel_width
;
11512 /* Stop at line end. */
11513 if (ITERATOR_AT_END_OF_LINE_P (it
))
11516 set_iterator_to_next (it
, 1);
11521 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11523 /* Use default face for the border below the tool bar.
11525 FIXME: When auto-resize-tool-bars is grow-only, there is
11526 no additional border below the possibly empty tool-bar lines.
11527 So to make the extra empty lines look "normal", we have to
11528 use the tool-bar face for the border too. */
11529 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11530 it
->face_id
= DEFAULT_FACE_ID
;
11532 extend_face_to_end_of_line (it
);
11533 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11534 last
->right_box_line_p
= 1;
11535 if (last
== row
->glyphs
[TEXT_AREA
])
11536 last
->left_box_line_p
= 1;
11538 /* Make line the desired height and center it vertically. */
11539 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11541 /* Don't add more than one line height. */
11542 height
%= FRAME_LINE_HEIGHT (it
->f
);
11543 it
->max_ascent
+= height
/ 2;
11544 it
->max_descent
+= (height
+ 1) / 2;
11547 compute_line_metrics (it
);
11549 /* If line is empty, make it occupy the rest of the tool-bar. */
11550 if (!row
->displays_text_p
)
11552 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11553 row
->visible_height
= row
->height
;
11554 row
->ascent
= row
->phys_ascent
= 0;
11555 row
->extra_line_spacing
= 0;
11558 row
->full_width_p
= 1;
11559 row
->continued_p
= 0;
11560 row
->truncated_on_left_p
= 0;
11561 row
->truncated_on_right_p
= 0;
11563 it
->current_x
= it
->hpos
= 0;
11564 it
->current_y
+= row
->height
;
11570 /* Max tool-bar height. */
11572 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11573 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11575 /* Value is the number of screen lines needed to make all tool-bar
11576 items of frame F visible. The number of actual rows needed is
11577 returned in *N_ROWS if non-NULL. */
11580 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11582 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11584 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11585 the desired matrix, so use (unused) mode-line row as temporary row to
11586 avoid destroying the first tool-bar row. */
11587 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11589 /* Initialize an iterator for iteration over
11590 F->desired_tool_bar_string in the tool-bar window of frame F. */
11591 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11592 it
.first_visible_x
= 0;
11593 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11594 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11595 it
.paragraph_embedding
= L2R
;
11597 while (!ITERATOR_AT_END_P (&it
))
11599 clear_glyph_row (temp_row
);
11600 it
.glyph_row
= temp_row
;
11601 display_tool_bar_line (&it
, -1);
11603 clear_glyph_row (temp_row
);
11605 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11607 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11609 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11613 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11615 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11616 (Lisp_Object frame
)
11623 frame
= selected_frame
;
11625 CHECK_FRAME (frame
);
11626 f
= XFRAME (frame
);
11628 if (WINDOWP (f
->tool_bar_window
)
11629 && (w
= XWINDOW (f
->tool_bar_window
),
11630 WINDOW_TOTAL_LINES (w
) > 0))
11632 update_tool_bar (f
, 1);
11633 if (f
->n_tool_bar_items
)
11635 build_desired_tool_bar_string (f
);
11636 nlines
= tool_bar_lines_needed (f
, NULL
);
11640 return make_number (nlines
);
11644 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11645 height should be changed. */
11648 redisplay_tool_bar (struct frame
*f
)
11652 struct glyph_row
*row
;
11654 #if defined (USE_GTK) || defined (HAVE_NS)
11655 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11656 update_frame_tool_bar (f
);
11660 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11661 do anything. This means you must start with tool-bar-lines
11662 non-zero to get the auto-sizing effect. Or in other words, you
11663 can turn off tool-bars by specifying tool-bar-lines zero. */
11664 if (!WINDOWP (f
->tool_bar_window
)
11665 || (w
= XWINDOW (f
->tool_bar_window
),
11666 WINDOW_TOTAL_LINES (w
) == 0))
11669 /* Set up an iterator for the tool-bar window. */
11670 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11671 it
.first_visible_x
= 0;
11672 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11673 row
= it
.glyph_row
;
11675 /* Build a string that represents the contents of the tool-bar. */
11676 build_desired_tool_bar_string (f
);
11677 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11678 /* FIXME: This should be controlled by a user option. But it
11679 doesn't make sense to have an R2L tool bar if the menu bar cannot
11680 be drawn also R2L, and making the menu bar R2L is tricky due
11681 toolkit-specific code that implements it. If an R2L tool bar is
11682 ever supported, display_tool_bar_line should also be augmented to
11683 call unproduce_glyphs like display_line and display_string
11685 it
.paragraph_embedding
= L2R
;
11687 if (f
->n_tool_bar_rows
== 0)
11691 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11692 nlines
!= WINDOW_TOTAL_LINES (w
)))
11695 int old_height
= WINDOW_TOTAL_LINES (w
);
11697 XSETFRAME (frame
, f
);
11698 Fmodify_frame_parameters (frame
,
11699 Fcons (Fcons (Qtool_bar_lines
,
11700 make_number (nlines
)),
11702 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11704 clear_glyph_matrix (w
->desired_matrix
);
11705 fonts_changed_p
= 1;
11711 /* Display as many lines as needed to display all tool-bar items. */
11713 if (f
->n_tool_bar_rows
> 0)
11715 int border
, rows
, height
, extra
;
11717 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11718 border
= XINT (Vtool_bar_border
);
11719 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11720 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11721 else if (EQ (Vtool_bar_border
, Qborder_width
))
11722 border
= f
->border_width
;
11728 rows
= f
->n_tool_bar_rows
;
11729 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11730 extra
= it
.last_visible_y
- border
- height
* rows
;
11732 while (it
.current_y
< it
.last_visible_y
)
11735 if (extra
> 0 && rows
-- > 0)
11737 h
= (extra
+ rows
- 1) / rows
;
11740 display_tool_bar_line (&it
, height
+ h
);
11745 while (it
.current_y
< it
.last_visible_y
)
11746 display_tool_bar_line (&it
, 0);
11749 /* It doesn't make much sense to try scrolling in the tool-bar
11750 window, so don't do it. */
11751 w
->desired_matrix
->no_scrolling_p
= 1;
11752 w
->must_be_updated_p
= 1;
11754 if (!NILP (Vauto_resize_tool_bars
))
11756 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11757 int change_height_p
= 0;
11759 /* If we couldn't display everything, change the tool-bar's
11760 height if there is room for more. */
11761 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11762 && it
.current_y
< max_tool_bar_height
)
11763 change_height_p
= 1;
11765 row
= it
.glyph_row
- 1;
11767 /* If there are blank lines at the end, except for a partially
11768 visible blank line at the end that is smaller than
11769 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11770 if (!row
->displays_text_p
11771 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11772 change_height_p
= 1;
11774 /* If row displays tool-bar items, but is partially visible,
11775 change the tool-bar's height. */
11776 if (row
->displays_text_p
11777 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11778 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11779 change_height_p
= 1;
11781 /* Resize windows as needed by changing the `tool-bar-lines'
11782 frame parameter. */
11783 if (change_height_p
)
11786 int old_height
= WINDOW_TOTAL_LINES (w
);
11788 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11790 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11791 && !f
->minimize_tool_bar_window_p
)
11792 ? (nlines
> old_height
)
11793 : (nlines
!= old_height
));
11794 f
->minimize_tool_bar_window_p
= 0;
11796 if (change_height_p
)
11798 XSETFRAME (frame
, f
);
11799 Fmodify_frame_parameters (frame
,
11800 Fcons (Fcons (Qtool_bar_lines
,
11801 make_number (nlines
)),
11803 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11805 clear_glyph_matrix (w
->desired_matrix
);
11806 f
->n_tool_bar_rows
= nrows
;
11807 fonts_changed_p
= 1;
11814 f
->minimize_tool_bar_window_p
= 0;
11819 /* Get information about the tool-bar item which is displayed in GLYPH
11820 on frame F. Return in *PROP_IDX the index where tool-bar item
11821 properties start in F->tool_bar_items. Value is zero if
11822 GLYPH doesn't display a tool-bar item. */
11825 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11831 /* This function can be called asynchronously, which means we must
11832 exclude any possibility that Fget_text_property signals an
11834 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11835 charpos
= max (0, charpos
);
11837 /* Get the text property `menu-item' at pos. The value of that
11838 property is the start index of this item's properties in
11839 F->tool_bar_items. */
11840 prop
= Fget_text_property (make_number (charpos
),
11841 Qmenu_item
, f
->current_tool_bar_string
);
11842 if (INTEGERP (prop
))
11844 *prop_idx
= XINT (prop
);
11854 /* Get information about the tool-bar item at position X/Y on frame F.
11855 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11856 the current matrix of the tool-bar window of F, or NULL if not
11857 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11858 item in F->tool_bar_items. Value is
11860 -1 if X/Y is not on a tool-bar item
11861 0 if X/Y is on the same item that was highlighted before.
11865 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11866 int *hpos
, int *vpos
, int *prop_idx
)
11868 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11869 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11872 /* Find the glyph under X/Y. */
11873 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11874 if (*glyph
== NULL
)
11877 /* Get the start of this tool-bar item's properties in
11878 f->tool_bar_items. */
11879 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11882 /* Is mouse on the highlighted item? */
11883 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11884 && *vpos
>= hlinfo
->mouse_face_beg_row
11885 && *vpos
<= hlinfo
->mouse_face_end_row
11886 && (*vpos
> hlinfo
->mouse_face_beg_row
11887 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11888 && (*vpos
< hlinfo
->mouse_face_end_row
11889 || *hpos
< hlinfo
->mouse_face_end_col
11890 || hlinfo
->mouse_face_past_end
))
11898 Handle mouse button event on the tool-bar of frame F, at
11899 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11900 0 for button release. MODIFIERS is event modifiers for button
11904 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11907 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11908 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11909 int hpos
, vpos
, prop_idx
;
11910 struct glyph
*glyph
;
11911 Lisp_Object enabled_p
;
11913 /* If not on the highlighted tool-bar item, return. */
11914 frame_to_window_pixel_xy (w
, &x
, &y
);
11915 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11918 /* If item is disabled, do nothing. */
11919 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11920 if (NILP (enabled_p
))
11925 /* Show item in pressed state. */
11926 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11927 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11928 last_tool_bar_item
= prop_idx
;
11932 Lisp_Object key
, frame
;
11933 struct input_event event
;
11934 EVENT_INIT (event
);
11936 /* Show item in released state. */
11937 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11938 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11940 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11942 XSETFRAME (frame
, f
);
11943 event
.kind
= TOOL_BAR_EVENT
;
11944 event
.frame_or_window
= frame
;
11946 kbd_buffer_store_event (&event
);
11948 event
.kind
= TOOL_BAR_EVENT
;
11949 event
.frame_or_window
= frame
;
11951 event
.modifiers
= modifiers
;
11952 kbd_buffer_store_event (&event
);
11953 last_tool_bar_item
= -1;
11958 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11959 tool-bar window-relative coordinates X/Y. Called from
11960 note_mouse_highlight. */
11963 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11965 Lisp_Object window
= f
->tool_bar_window
;
11966 struct window
*w
= XWINDOW (window
);
11967 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11968 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11970 struct glyph
*glyph
;
11971 struct glyph_row
*row
;
11973 Lisp_Object enabled_p
;
11975 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11976 int mouse_down_p
, rc
;
11978 /* Function note_mouse_highlight is called with negative X/Y
11979 values when mouse moves outside of the frame. */
11980 if (x
<= 0 || y
<= 0)
11982 clear_mouse_face (hlinfo
);
11986 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11989 /* Not on tool-bar item. */
11990 clear_mouse_face (hlinfo
);
11994 /* On same tool-bar item as before. */
11995 goto set_help_echo
;
11997 clear_mouse_face (hlinfo
);
11999 /* Mouse is down, but on different tool-bar item? */
12000 mouse_down_p
= (dpyinfo
->grabbed
12001 && f
== last_mouse_frame
12002 && FRAME_LIVE_P (f
));
12004 && last_tool_bar_item
!= prop_idx
)
12007 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12008 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12010 /* If tool-bar item is not enabled, don't highlight it. */
12011 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12012 if (!NILP (enabled_p
))
12014 /* Compute the x-position of the glyph. In front and past the
12015 image is a space. We include this in the highlighted area. */
12016 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12017 for (i
= x
= 0; i
< hpos
; ++i
)
12018 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12020 /* Record this as the current active region. */
12021 hlinfo
->mouse_face_beg_col
= hpos
;
12022 hlinfo
->mouse_face_beg_row
= vpos
;
12023 hlinfo
->mouse_face_beg_x
= x
;
12024 hlinfo
->mouse_face_beg_y
= row
->y
;
12025 hlinfo
->mouse_face_past_end
= 0;
12027 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12028 hlinfo
->mouse_face_end_row
= vpos
;
12029 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12030 hlinfo
->mouse_face_end_y
= row
->y
;
12031 hlinfo
->mouse_face_window
= window
;
12032 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12034 /* Display it as active. */
12035 show_mouse_face (hlinfo
, draw
);
12036 hlinfo
->mouse_face_image_state
= draw
;
12041 /* Set help_echo_string to a help string to display for this tool-bar item.
12042 XTread_socket does the rest. */
12043 help_echo_object
= help_echo_window
= Qnil
;
12044 help_echo_pos
= -1;
12045 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12046 if (NILP (help_echo_string
))
12047 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12050 #endif /* HAVE_WINDOW_SYSTEM */
12054 /************************************************************************
12055 Horizontal scrolling
12056 ************************************************************************/
12058 static int hscroll_window_tree (Lisp_Object
);
12059 static int hscroll_windows (Lisp_Object
);
12061 /* For all leaf windows in the window tree rooted at WINDOW, set their
12062 hscroll value so that PT is (i) visible in the window, and (ii) so
12063 that it is not within a certain margin at the window's left and
12064 right border. Value is non-zero if any window's hscroll has been
12068 hscroll_window_tree (Lisp_Object window
)
12070 int hscrolled_p
= 0;
12071 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12072 int hscroll_step_abs
= 0;
12073 double hscroll_step_rel
= 0;
12075 if (hscroll_relative_p
)
12077 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12078 if (hscroll_step_rel
< 0)
12080 hscroll_relative_p
= 0;
12081 hscroll_step_abs
= 0;
12084 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12086 hscroll_step_abs
= XINT (Vhscroll_step
);
12087 if (hscroll_step_abs
< 0)
12088 hscroll_step_abs
= 0;
12091 hscroll_step_abs
= 0;
12093 while (WINDOWP (window
))
12095 struct window
*w
= XWINDOW (window
);
12097 if (WINDOWP (w
->hchild
))
12098 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12099 else if (WINDOWP (w
->vchild
))
12100 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12101 else if (w
->cursor
.vpos
>= 0)
12104 int text_area_width
;
12105 struct glyph_row
*current_cursor_row
12106 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12107 struct glyph_row
*desired_cursor_row
12108 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12109 struct glyph_row
*cursor_row
12110 = (desired_cursor_row
->enabled_p
12111 ? desired_cursor_row
12112 : current_cursor_row
);
12113 int row_r2l_p
= cursor_row
->reversed_p
;
12115 text_area_width
= window_box_width (w
, TEXT_AREA
);
12117 /* Scroll when cursor is inside this scroll margin. */
12118 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12120 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12121 /* For left-to-right rows, hscroll when cursor is either
12122 (i) inside the right hscroll margin, or (ii) if it is
12123 inside the left margin and the window is already
12126 && ((XFASTINT (w
->hscroll
)
12127 && w
->cursor
.x
<= h_margin
)
12128 || (cursor_row
->enabled_p
12129 && cursor_row
->truncated_on_right_p
12130 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12131 /* For right-to-left rows, the logic is similar,
12132 except that rules for scrolling to left and right
12133 are reversed. E.g., if cursor.x <= h_margin, we
12134 need to hscroll "to the right" unconditionally,
12135 and that will scroll the screen to the left so as
12136 to reveal the next portion of the row. */
12138 && ((cursor_row
->enabled_p
12139 /* FIXME: It is confusing to set the
12140 truncated_on_right_p flag when R2L rows
12141 are actually truncated on the left. */
12142 && cursor_row
->truncated_on_right_p
12143 && w
->cursor
.x
<= h_margin
)
12144 || (XFASTINT (w
->hscroll
)
12145 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12149 struct buffer
*saved_current_buffer
;
12153 /* Find point in a display of infinite width. */
12154 saved_current_buffer
= current_buffer
;
12155 current_buffer
= XBUFFER (w
->buffer
);
12157 if (w
== XWINDOW (selected_window
))
12161 pt
= marker_position (w
->pointm
);
12162 pt
= max (BEGV
, pt
);
12166 /* Move iterator to pt starting at cursor_row->start in
12167 a line with infinite width. */
12168 init_to_row_start (&it
, w
, cursor_row
);
12169 it
.last_visible_x
= INFINITY
;
12170 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12171 current_buffer
= saved_current_buffer
;
12173 /* Position cursor in window. */
12174 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12175 hscroll
= max (0, (it
.current_x
12176 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12177 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12178 : (text_area_width
/ 2))))
12179 / FRAME_COLUMN_WIDTH (it
.f
);
12180 else if ((!row_r2l_p
12181 && w
->cursor
.x
>= text_area_width
- h_margin
)
12182 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12184 if (hscroll_relative_p
)
12185 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12188 wanted_x
= text_area_width
12189 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12192 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12196 if (hscroll_relative_p
)
12197 wanted_x
= text_area_width
* hscroll_step_rel
12200 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12203 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12205 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
12207 /* Don't prevent redisplay optimizations if hscroll
12208 hasn't changed, as it will unnecessarily slow down
12210 if (XFASTINT (w
->hscroll
) != hscroll
)
12212 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12213 w
->hscroll
= make_number (hscroll
);
12222 /* Value is non-zero if hscroll of any leaf window has been changed. */
12223 return hscrolled_p
;
12227 /* Set hscroll so that cursor is visible and not inside horizontal
12228 scroll margins for all windows in the tree rooted at WINDOW. See
12229 also hscroll_window_tree above. Value is non-zero if any window's
12230 hscroll has been changed. If it has, desired matrices on the frame
12231 of WINDOW are cleared. */
12234 hscroll_windows (Lisp_Object window
)
12236 int hscrolled_p
= hscroll_window_tree (window
);
12238 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12239 return hscrolled_p
;
12244 /************************************************************************
12246 ************************************************************************/
12248 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12249 to a non-zero value. This is sometimes handy to have in a debugger
12254 /* First and last unchanged row for try_window_id. */
12256 static int debug_first_unchanged_at_end_vpos
;
12257 static int debug_last_unchanged_at_beg_vpos
;
12259 /* Delta vpos and y. */
12261 static int debug_dvpos
, debug_dy
;
12263 /* Delta in characters and bytes for try_window_id. */
12265 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12267 /* Values of window_end_pos and window_end_vpos at the end of
12270 static ptrdiff_t debug_end_vpos
;
12272 /* Append a string to W->desired_matrix->method. FMT is a printf
12273 format string. If trace_redisplay_p is non-zero also printf the
12274 resulting string to stderr. */
12276 static void debug_method_add (struct window
*, char const *, ...)
12277 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12280 debug_method_add (struct window
*w
, char const *fmt
, ...)
12283 char *method
= w
->desired_matrix
->method
;
12284 int len
= strlen (method
);
12285 int size
= sizeof w
->desired_matrix
->method
;
12286 int remaining
= size
- len
- 1;
12289 va_start (ap
, fmt
);
12290 vsprintf (buffer
, fmt
, ap
);
12292 if (len
&& remaining
)
12295 --remaining
, ++len
;
12298 strncpy (method
+ len
, buffer
, remaining
);
12300 if (trace_redisplay_p
)
12301 fprintf (stderr
, "%p (%s): %s\n",
12303 ((BUFFERP (w
->buffer
)
12304 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12305 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12310 #endif /* GLYPH_DEBUG */
12313 /* Value is non-zero if all changes in window W, which displays
12314 current_buffer, are in the text between START and END. START is a
12315 buffer position, END is given as a distance from Z. Used in
12316 redisplay_internal for display optimization. */
12319 text_outside_line_unchanged_p (struct window
*w
,
12320 ptrdiff_t start
, ptrdiff_t end
)
12322 int unchanged_p
= 1;
12324 /* If text or overlays have changed, see where. */
12325 if (XFASTINT (w
->last_modified
) < MODIFF
12326 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12328 /* Gap in the line? */
12329 if (GPT
< start
|| Z
- GPT
< end
)
12332 /* Changes start in front of the line, or end after it? */
12334 && (BEG_UNCHANGED
< start
- 1
12335 || END_UNCHANGED
< end
))
12338 /* If selective display, can't optimize if changes start at the
12339 beginning of the line. */
12341 && INTEGERP (BVAR (current_buffer
, selective_display
))
12342 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12343 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12346 /* If there are overlays at the start or end of the line, these
12347 may have overlay strings with newlines in them. A change at
12348 START, for instance, may actually concern the display of such
12349 overlay strings as well, and they are displayed on different
12350 lines. So, quickly rule out this case. (For the future, it
12351 might be desirable to implement something more telling than
12352 just BEG/END_UNCHANGED.) */
12355 if (BEG
+ BEG_UNCHANGED
== start
12356 && overlay_touches_p (start
))
12358 if (END_UNCHANGED
== end
12359 && overlay_touches_p (Z
- end
))
12363 /* Under bidi reordering, adding or deleting a character in the
12364 beginning of a paragraph, before the first strong directional
12365 character, can change the base direction of the paragraph (unless
12366 the buffer specifies a fixed paragraph direction), which will
12367 require to redisplay the whole paragraph. It might be worthwhile
12368 to find the paragraph limits and widen the range of redisplayed
12369 lines to that, but for now just give up this optimization. */
12370 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12371 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12375 return unchanged_p
;
12379 /* Do a frame update, taking possible shortcuts into account. This is
12380 the main external entry point for redisplay.
12382 If the last redisplay displayed an echo area message and that message
12383 is no longer requested, we clear the echo area or bring back the
12384 mini-buffer if that is in use. */
12389 redisplay_internal ();
12394 overlay_arrow_string_or_property (Lisp_Object var
)
12398 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12401 return Voverlay_arrow_string
;
12404 /* Return 1 if there are any overlay-arrows in current_buffer. */
12406 overlay_arrow_in_current_buffer_p (void)
12410 for (vlist
= Voverlay_arrow_variable_list
;
12412 vlist
= XCDR (vlist
))
12414 Lisp_Object var
= XCAR (vlist
);
12417 if (!SYMBOLP (var
))
12419 val
= find_symbol_value (var
);
12421 && current_buffer
== XMARKER (val
)->buffer
)
12428 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12432 overlay_arrows_changed_p (void)
12436 for (vlist
= Voverlay_arrow_variable_list
;
12438 vlist
= XCDR (vlist
))
12440 Lisp_Object var
= XCAR (vlist
);
12441 Lisp_Object val
, pstr
;
12443 if (!SYMBOLP (var
))
12445 val
= find_symbol_value (var
);
12446 if (!MARKERP (val
))
12448 if (! EQ (COERCE_MARKER (val
),
12449 Fget (var
, Qlast_arrow_position
))
12450 || ! (pstr
= overlay_arrow_string_or_property (var
),
12451 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12457 /* Mark overlay arrows to be updated on next redisplay. */
12460 update_overlay_arrows (int up_to_date
)
12464 for (vlist
= Voverlay_arrow_variable_list
;
12466 vlist
= XCDR (vlist
))
12468 Lisp_Object var
= XCAR (vlist
);
12470 if (!SYMBOLP (var
))
12473 if (up_to_date
> 0)
12475 Lisp_Object val
= find_symbol_value (var
);
12476 Fput (var
, Qlast_arrow_position
,
12477 COERCE_MARKER (val
));
12478 Fput (var
, Qlast_arrow_string
,
12479 overlay_arrow_string_or_property (var
));
12481 else if (up_to_date
< 0
12482 || !NILP (Fget (var
, Qlast_arrow_position
)))
12484 Fput (var
, Qlast_arrow_position
, Qt
);
12485 Fput (var
, Qlast_arrow_string
, Qt
);
12491 /* Return overlay arrow string to display at row.
12492 Return integer (bitmap number) for arrow bitmap in left fringe.
12493 Return nil if no overlay arrow. */
12496 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12500 for (vlist
= Voverlay_arrow_variable_list
;
12502 vlist
= XCDR (vlist
))
12504 Lisp_Object var
= XCAR (vlist
);
12507 if (!SYMBOLP (var
))
12510 val
= find_symbol_value (var
);
12513 && current_buffer
== XMARKER (val
)->buffer
12514 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12516 if (FRAME_WINDOW_P (it
->f
)
12517 /* FIXME: if ROW->reversed_p is set, this should test
12518 the right fringe, not the left one. */
12519 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12521 #ifdef HAVE_WINDOW_SYSTEM
12522 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12525 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12526 return make_number (fringe_bitmap
);
12529 return make_number (-1); /* Use default arrow bitmap */
12531 return overlay_arrow_string_or_property (var
);
12538 /* Return 1 if point moved out of or into a composition. Otherwise
12539 return 0. PREV_BUF and PREV_PT are the last point buffer and
12540 position. BUF and PT are the current point buffer and position. */
12543 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12544 struct buffer
*buf
, ptrdiff_t pt
)
12546 ptrdiff_t start
, end
;
12548 Lisp_Object buffer
;
12550 XSETBUFFER (buffer
, buf
);
12551 /* Check a composition at the last point if point moved within the
12553 if (prev_buf
== buf
)
12556 /* Point didn't move. */
12559 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12560 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12561 && COMPOSITION_VALID_P (start
, end
, prop
)
12562 && start
< prev_pt
&& end
> prev_pt
)
12563 /* The last point was within the composition. Return 1 iff
12564 point moved out of the composition. */
12565 return (pt
<= start
|| pt
>= end
);
12568 /* Check a composition at the current point. */
12569 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12570 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12571 && COMPOSITION_VALID_P (start
, end
, prop
)
12572 && start
< pt
&& end
> pt
);
12576 /* Reconsider the setting of B->clip_changed which is displayed
12580 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12582 if (b
->clip_changed
12583 && !NILP (w
->window_end_valid
)
12584 && w
->current_matrix
->buffer
== b
12585 && w
->current_matrix
->zv
== BUF_ZV (b
)
12586 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12587 b
->clip_changed
= 0;
12589 /* If display wasn't paused, and W is not a tool bar window, see if
12590 point has been moved into or out of a composition. In that case,
12591 we set b->clip_changed to 1 to force updating the screen. If
12592 b->clip_changed has already been set to 1, we can skip this
12594 if (!b
->clip_changed
12595 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12599 if (w
== XWINDOW (selected_window
))
12602 pt
= marker_position (w
->pointm
);
12604 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12605 || pt
!= XINT (w
->last_point
))
12606 && check_point_in_composition (w
->current_matrix
->buffer
,
12607 XINT (w
->last_point
),
12608 XBUFFER (w
->buffer
), pt
))
12609 b
->clip_changed
= 1;
12614 /* Select FRAME to forward the values of frame-local variables into C
12615 variables so that the redisplay routines can access those values
12619 select_frame_for_redisplay (Lisp_Object frame
)
12621 Lisp_Object tail
, tem
;
12622 Lisp_Object old
= selected_frame
;
12623 struct Lisp_Symbol
*sym
;
12625 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12627 selected_frame
= frame
;
12630 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12631 if (CONSP (XCAR (tail
))
12632 && (tem
= XCAR (XCAR (tail
)),
12634 && (sym
= indirect_variable (XSYMBOL (tem
)),
12635 sym
->redirect
== SYMBOL_LOCALIZED
)
12636 && sym
->val
.blv
->frame_local
)
12637 /* Use find_symbol_value rather than Fsymbol_value
12638 to avoid an error if it is void. */
12639 find_symbol_value (tem
);
12640 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12644 #define STOP_POLLING \
12645 do { if (! polling_stopped_here) stop_polling (); \
12646 polling_stopped_here = 1; } while (0)
12648 #define RESUME_POLLING \
12649 do { if (polling_stopped_here) start_polling (); \
12650 polling_stopped_here = 0; } while (0)
12653 /* Perhaps in the future avoid recentering windows if it
12654 is not necessary; currently that causes some problems. */
12657 redisplay_internal (void)
12659 struct window
*w
= XWINDOW (selected_window
);
12663 int must_finish
= 0;
12664 struct text_pos tlbufpos
, tlendpos
;
12665 int number_of_visible_frames
;
12666 ptrdiff_t count
, count1
;
12668 int polling_stopped_here
= 0;
12669 Lisp_Object old_frame
= selected_frame
;
12671 /* Non-zero means redisplay has to consider all windows on all
12672 frames. Zero means, only selected_window is considered. */
12673 int consider_all_windows_p
;
12675 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12677 /* No redisplay if running in batch mode or frame is not yet fully
12678 initialized, or redisplay is explicitly turned off by setting
12679 Vinhibit_redisplay. */
12680 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12681 || !NILP (Vinhibit_redisplay
))
12684 /* Don't examine these until after testing Vinhibit_redisplay.
12685 When Emacs is shutting down, perhaps because its connection to
12686 X has dropped, we should not look at them at all. */
12687 fr
= XFRAME (w
->frame
);
12688 sf
= SELECTED_FRAME ();
12690 if (!fr
->glyphs_initialized_p
)
12693 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12694 if (popup_activated ())
12698 /* I don't think this happens but let's be paranoid. */
12699 if (redisplaying_p
)
12702 /* Record a function that resets redisplaying_p to its old value
12703 when we leave this function. */
12704 count
= SPECPDL_INDEX ();
12705 record_unwind_protect (unwind_redisplay
,
12706 Fcons (make_number (redisplaying_p
), selected_frame
));
12708 specbind (Qinhibit_free_realized_faces
, Qnil
);
12711 Lisp_Object tail
, frame
;
12713 FOR_EACH_FRAME (tail
, frame
)
12715 struct frame
*f
= XFRAME (frame
);
12716 f
->already_hscrolled_p
= 0;
12721 /* Remember the currently selected window. */
12724 if (!EQ (old_frame
, selected_frame
)
12725 && FRAME_LIVE_P (XFRAME (old_frame
)))
12726 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12727 selected_frame and selected_window to be temporarily out-of-sync so
12728 when we come back here via `goto retry', we need to resync because we
12729 may need to run Elisp code (via prepare_menu_bars). */
12730 select_frame_for_redisplay (old_frame
);
12733 reconsider_clip_changes (w
, current_buffer
);
12734 last_escape_glyph_frame
= NULL
;
12735 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12736 last_glyphless_glyph_frame
= NULL
;
12737 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12739 /* If new fonts have been loaded that make a glyph matrix adjustment
12740 necessary, do it. */
12741 if (fonts_changed_p
)
12743 adjust_glyphs (NULL
);
12744 ++windows_or_buffers_changed
;
12745 fonts_changed_p
= 0;
12748 /* If face_change_count is non-zero, init_iterator will free all
12749 realized faces, which includes the faces referenced from current
12750 matrices. So, we can't reuse current matrices in this case. */
12751 if (face_change_count
)
12752 ++windows_or_buffers_changed
;
12754 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12755 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12757 /* Since frames on a single ASCII terminal share the same
12758 display area, displaying a different frame means redisplay
12759 the whole thing. */
12760 windows_or_buffers_changed
++;
12761 SET_FRAME_GARBAGED (sf
);
12763 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12765 FRAME_TTY (sf
)->previous_frame
= sf
;
12768 /* Set the visible flags for all frames. Do this before checking
12769 for resized or garbaged frames; they want to know if their frames
12770 are visible. See the comment in frame.h for
12771 FRAME_SAMPLE_VISIBILITY. */
12773 Lisp_Object tail
, frame
;
12775 number_of_visible_frames
= 0;
12777 FOR_EACH_FRAME (tail
, frame
)
12779 struct frame
*f
= XFRAME (frame
);
12781 FRAME_SAMPLE_VISIBILITY (f
);
12782 if (FRAME_VISIBLE_P (f
))
12783 ++number_of_visible_frames
;
12784 clear_desired_matrices (f
);
12788 /* Notice any pending interrupt request to change frame size. */
12789 do_pending_window_change (1);
12791 /* do_pending_window_change could change the selected_window due to
12792 frame resizing which makes the selected window too small. */
12793 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12796 reconsider_clip_changes (w
, current_buffer
);
12799 /* Clear frames marked as garbaged. */
12800 if (frame_garbaged
)
12801 clear_garbaged_frames ();
12803 /* Build menubar and tool-bar items. */
12804 if (NILP (Vmemory_full
))
12805 prepare_menu_bars ();
12807 if (windows_or_buffers_changed
)
12808 update_mode_lines
++;
12810 /* Detect case that we need to write or remove a star in the mode line. */
12811 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12813 w
->update_mode_line
= Qt
;
12814 if (buffer_shared
> 1)
12815 update_mode_lines
++;
12818 /* Avoid invocation of point motion hooks by `current_column' below. */
12819 count1
= SPECPDL_INDEX ();
12820 specbind (Qinhibit_point_motion_hooks
, Qt
);
12822 /* If %c is in the mode line, update it if needed. */
12823 if (!NILP (w
->column_number_displayed
)
12824 /* This alternative quickly identifies a common case
12825 where no change is needed. */
12826 && !(PT
== XFASTINT (w
->last_point
)
12827 && XFASTINT (w
->last_modified
) >= MODIFF
12828 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12829 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12830 w
->update_mode_line
= Qt
;
12832 unbind_to (count1
, Qnil
);
12834 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12836 /* The variable buffer_shared is set in redisplay_window and
12837 indicates that we redisplay a buffer in different windows. See
12839 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12840 || cursor_type_changed
);
12842 /* If specs for an arrow have changed, do thorough redisplay
12843 to ensure we remove any arrow that should no longer exist. */
12844 if (overlay_arrows_changed_p ())
12845 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12847 /* Normally the message* functions will have already displayed and
12848 updated the echo area, but the frame may have been trashed, or
12849 the update may have been preempted, so display the echo area
12850 again here. Checking message_cleared_p captures the case that
12851 the echo area should be cleared. */
12852 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12853 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12854 || (message_cleared_p
12855 && minibuf_level
== 0
12856 /* If the mini-window is currently selected, this means the
12857 echo-area doesn't show through. */
12858 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12860 int window_height_changed_p
= echo_area_display (0);
12863 /* If we don't display the current message, don't clear the
12864 message_cleared_p flag, because, if we did, we wouldn't clear
12865 the echo area in the next redisplay which doesn't preserve
12867 if (!display_last_displayed_message_p
)
12868 message_cleared_p
= 0;
12870 if (fonts_changed_p
)
12872 else if (window_height_changed_p
)
12874 consider_all_windows_p
= 1;
12875 ++update_mode_lines
;
12876 ++windows_or_buffers_changed
;
12878 /* If window configuration was changed, frames may have been
12879 marked garbaged. Clear them or we will experience
12880 surprises wrt scrolling. */
12881 if (frame_garbaged
)
12882 clear_garbaged_frames ();
12885 else if (EQ (selected_window
, minibuf_window
)
12886 && (current_buffer
->clip_changed
12887 || XFASTINT (w
->last_modified
) < MODIFF
12888 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12889 && resize_mini_window (w
, 0))
12891 /* Resized active mini-window to fit the size of what it is
12892 showing if its contents might have changed. */
12894 /* FIXME: this causes all frames to be updated, which seems unnecessary
12895 since only the current frame needs to be considered. This function needs
12896 to be rewritten with two variables, consider_all_windows and
12897 consider_all_frames. */
12898 consider_all_windows_p
= 1;
12899 ++windows_or_buffers_changed
;
12900 ++update_mode_lines
;
12902 /* If window configuration was changed, frames may have been
12903 marked garbaged. Clear them or we will experience
12904 surprises wrt scrolling. */
12905 if (frame_garbaged
)
12906 clear_garbaged_frames ();
12910 /* If showing the region, and mark has changed, we must redisplay
12911 the whole window. The assignment to this_line_start_pos prevents
12912 the optimization directly below this if-statement. */
12913 if (((!NILP (Vtransient_mark_mode
)
12914 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12915 != !NILP (w
->region_showing
))
12916 || (!NILP (w
->region_showing
)
12917 && !EQ (w
->region_showing
,
12918 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12919 CHARPOS (this_line_start_pos
) = 0;
12921 /* Optimize the case that only the line containing the cursor in the
12922 selected window has changed. Variables starting with this_ are
12923 set in display_line and record information about the line
12924 containing the cursor. */
12925 tlbufpos
= this_line_start_pos
;
12926 tlendpos
= this_line_end_pos
;
12927 if (!consider_all_windows_p
12928 && CHARPOS (tlbufpos
) > 0
12929 && NILP (w
->update_mode_line
)
12930 && !current_buffer
->clip_changed
12931 && !current_buffer
->prevent_redisplay_optimizations_p
12932 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12933 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12934 /* Make sure recorded data applies to current buffer, etc. */
12935 && this_line_buffer
== current_buffer
12936 && current_buffer
== XBUFFER (w
->buffer
)
12937 && NILP (w
->force_start
)
12938 && NILP (w
->optional_new_start
)
12939 /* Point must be on the line that we have info recorded about. */
12940 && PT
>= CHARPOS (tlbufpos
)
12941 && PT
<= Z
- CHARPOS (tlendpos
)
12942 /* All text outside that line, including its final newline,
12943 must be unchanged. */
12944 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12945 CHARPOS (tlendpos
)))
12947 if (CHARPOS (tlbufpos
) > BEGV
12948 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12949 && (CHARPOS (tlbufpos
) == ZV
12950 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12951 /* Former continuation line has disappeared by becoming empty. */
12953 else if (XFASTINT (w
->last_modified
) < MODIFF
12954 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12955 || MINI_WINDOW_P (w
))
12957 /* We have to handle the case of continuation around a
12958 wide-column character (see the comment in indent.c around
12961 For instance, in the following case:
12963 -------- Insert --------
12964 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12965 J_I_ ==> J_I_ `^^' are cursors.
12969 As we have to redraw the line above, we cannot use this
12973 int line_height_before
= this_line_pixel_height
;
12975 /* Note that start_display will handle the case that the
12976 line starting at tlbufpos is a continuation line. */
12977 start_display (&it
, w
, tlbufpos
);
12979 /* Implementation note: It this still necessary? */
12980 if (it
.current_x
!= this_line_start_x
)
12983 TRACE ((stderr
, "trying display optimization 1\n"));
12984 w
->cursor
.vpos
= -1;
12985 overlay_arrow_seen
= 0;
12986 it
.vpos
= this_line_vpos
;
12987 it
.current_y
= this_line_y
;
12988 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12989 display_line (&it
);
12991 /* If line contains point, is not continued,
12992 and ends at same distance from eob as before, we win. */
12993 if (w
->cursor
.vpos
>= 0
12994 /* Line is not continued, otherwise this_line_start_pos
12995 would have been set to 0 in display_line. */
12996 && CHARPOS (this_line_start_pos
)
12997 /* Line ends as before. */
12998 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12999 /* Line has same height as before. Otherwise other lines
13000 would have to be shifted up or down. */
13001 && this_line_pixel_height
== line_height_before
)
13003 /* If this is not the window's last line, we must adjust
13004 the charstarts of the lines below. */
13005 if (it
.current_y
< it
.last_visible_y
)
13007 struct glyph_row
*row
13008 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13009 ptrdiff_t delta
, delta_bytes
;
13011 /* We used to distinguish between two cases here,
13012 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13013 when the line ends in a newline or the end of the
13014 buffer's accessible portion. But both cases did
13015 the same, so they were collapsed. */
13017 - CHARPOS (tlendpos
)
13018 - MATRIX_ROW_START_CHARPOS (row
));
13019 delta_bytes
= (Z_BYTE
13020 - BYTEPOS (tlendpos
)
13021 - MATRIX_ROW_START_BYTEPOS (row
));
13023 increment_matrix_positions (w
->current_matrix
,
13024 this_line_vpos
+ 1,
13025 w
->current_matrix
->nrows
,
13026 delta
, delta_bytes
);
13029 /* If this row displays text now but previously didn't,
13030 or vice versa, w->window_end_vpos may have to be
13032 if ((it
.glyph_row
- 1)->displays_text_p
)
13034 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13035 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13037 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13038 && this_line_vpos
> 0)
13039 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13040 w
->window_end_valid
= Qnil
;
13042 /* Update hint: No need to try to scroll in update_window. */
13043 w
->desired_matrix
->no_scrolling_p
= 1;
13046 *w
->desired_matrix
->method
= 0;
13047 debug_method_add (w
, "optimization 1");
13049 #ifdef HAVE_WINDOW_SYSTEM
13050 update_window_fringes (w
, 0);
13057 else if (/* Cursor position hasn't changed. */
13058 PT
== XFASTINT (w
->last_point
)
13059 /* Make sure the cursor was last displayed
13060 in this window. Otherwise we have to reposition it. */
13061 && 0 <= w
->cursor
.vpos
13062 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13066 do_pending_window_change (1);
13067 /* If selected_window changed, redisplay again. */
13068 if (WINDOWP (selected_window
)
13069 && (w
= XWINDOW (selected_window
)) != sw
)
13072 /* We used to always goto end_of_redisplay here, but this
13073 isn't enough if we have a blinking cursor. */
13074 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13075 goto end_of_redisplay
;
13079 /* If highlighting the region, or if the cursor is in the echo area,
13080 then we can't just move the cursor. */
13081 else if (! (!NILP (Vtransient_mark_mode
)
13082 && !NILP (BVAR (current_buffer
, mark_active
)))
13083 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
13084 || highlight_nonselected_windows
)
13085 && NILP (w
->region_showing
)
13086 && NILP (Vshow_trailing_whitespace
)
13087 && !cursor_in_echo_area
)
13090 struct glyph_row
*row
;
13092 /* Skip from tlbufpos to PT and see where it is. Note that
13093 PT may be in invisible text. If so, we will end at the
13094 next visible position. */
13095 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13096 NULL
, DEFAULT_FACE_ID
);
13097 it
.current_x
= this_line_start_x
;
13098 it
.current_y
= this_line_y
;
13099 it
.vpos
= this_line_vpos
;
13101 /* The call to move_it_to stops in front of PT, but
13102 moves over before-strings. */
13103 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13105 if (it
.vpos
== this_line_vpos
13106 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13109 xassert (this_line_vpos
== it
.vpos
);
13110 xassert (this_line_y
== it
.current_y
);
13111 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13113 *w
->desired_matrix
->method
= 0;
13114 debug_method_add (w
, "optimization 3");
13123 /* Text changed drastically or point moved off of line. */
13124 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13127 CHARPOS (this_line_start_pos
) = 0;
13128 consider_all_windows_p
|= buffer_shared
> 1;
13129 ++clear_face_cache_count
;
13130 #ifdef HAVE_WINDOW_SYSTEM
13131 ++clear_image_cache_count
;
13134 /* Build desired matrices, and update the display. If
13135 consider_all_windows_p is non-zero, do it for all windows on all
13136 frames. Otherwise do it for selected_window, only. */
13138 if (consider_all_windows_p
)
13140 Lisp_Object tail
, frame
;
13142 FOR_EACH_FRAME (tail
, frame
)
13143 XFRAME (frame
)->updated_p
= 0;
13145 /* Recompute # windows showing selected buffer. This will be
13146 incremented each time such a window is displayed. */
13149 FOR_EACH_FRAME (tail
, frame
)
13151 struct frame
*f
= XFRAME (frame
);
13153 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13155 if (! EQ (frame
, selected_frame
))
13156 /* Select the frame, for the sake of frame-local
13158 select_frame_for_redisplay (frame
);
13160 /* Mark all the scroll bars to be removed; we'll redeem
13161 the ones we want when we redisplay their windows. */
13162 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13163 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13165 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13166 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13168 /* The X error handler may have deleted that frame. */
13169 if (!FRAME_LIVE_P (f
))
13172 /* Any scroll bars which redisplay_windows should have
13173 nuked should now go away. */
13174 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13175 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13177 /* If fonts changed, display again. */
13178 /* ??? rms: I suspect it is a mistake to jump all the way
13179 back to retry here. It should just retry this frame. */
13180 if (fonts_changed_p
)
13183 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13185 /* See if we have to hscroll. */
13186 if (!f
->already_hscrolled_p
)
13188 f
->already_hscrolled_p
= 1;
13189 if (hscroll_windows (f
->root_window
))
13193 /* Prevent various kinds of signals during display
13194 update. stdio is not robust about handling
13195 signals, which can cause an apparent I/O
13197 if (interrupt_input
)
13198 unrequest_sigio ();
13201 /* Update the display. */
13202 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13203 pending
|= update_frame (f
, 0, 0);
13209 if (!EQ (old_frame
, selected_frame
)
13210 && FRAME_LIVE_P (XFRAME (old_frame
)))
13211 /* We played a bit fast-and-loose above and allowed selected_frame
13212 and selected_window to be temporarily out-of-sync but let's make
13213 sure this stays contained. */
13214 select_frame_for_redisplay (old_frame
);
13215 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13219 /* Do the mark_window_display_accurate after all windows have
13220 been redisplayed because this call resets flags in buffers
13221 which are needed for proper redisplay. */
13222 FOR_EACH_FRAME (tail
, frame
)
13224 struct frame
*f
= XFRAME (frame
);
13227 mark_window_display_accurate (f
->root_window
, 1);
13228 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13229 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13234 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13236 Lisp_Object mini_window
;
13237 struct frame
*mini_frame
;
13239 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13240 /* Use list_of_error, not Qerror, so that
13241 we catch only errors and don't run the debugger. */
13242 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13244 redisplay_window_error
);
13246 /* Compare desired and current matrices, perform output. */
13249 /* If fonts changed, display again. */
13250 if (fonts_changed_p
)
13253 /* Prevent various kinds of signals during display update.
13254 stdio is not robust about handling signals,
13255 which can cause an apparent I/O error. */
13256 if (interrupt_input
)
13257 unrequest_sigio ();
13260 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13262 if (hscroll_windows (selected_window
))
13265 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13266 pending
= update_frame (sf
, 0, 0);
13269 /* We may have called echo_area_display at the top of this
13270 function. If the echo area is on another frame, that may
13271 have put text on a frame other than the selected one, so the
13272 above call to update_frame would not have caught it. Catch
13274 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13275 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13277 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13279 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13280 pending
|= update_frame (mini_frame
, 0, 0);
13281 if (!pending
&& hscroll_windows (mini_window
))
13286 /* If display was paused because of pending input, make sure we do a
13287 thorough update the next time. */
13290 /* Prevent the optimization at the beginning of
13291 redisplay_internal that tries a single-line update of the
13292 line containing the cursor in the selected window. */
13293 CHARPOS (this_line_start_pos
) = 0;
13295 /* Let the overlay arrow be updated the next time. */
13296 update_overlay_arrows (0);
13298 /* If we pause after scrolling, some rows in the current
13299 matrices of some windows are not valid. */
13300 if (!WINDOW_FULL_WIDTH_P (w
)
13301 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13302 update_mode_lines
= 1;
13306 if (!consider_all_windows_p
)
13308 /* This has already been done above if
13309 consider_all_windows_p is set. */
13310 mark_window_display_accurate_1 (w
, 1);
13312 /* Say overlay arrows are up to date. */
13313 update_overlay_arrows (1);
13315 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13316 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13319 update_mode_lines
= 0;
13320 windows_or_buffers_changed
= 0;
13321 cursor_type_changed
= 0;
13324 /* Start SIGIO interrupts coming again. Having them off during the
13325 code above makes it less likely one will discard output, but not
13326 impossible, since there might be stuff in the system buffer here.
13327 But it is much hairier to try to do anything about that. */
13328 if (interrupt_input
)
13332 /* If a frame has become visible which was not before, redisplay
13333 again, so that we display it. Expose events for such a frame
13334 (which it gets when becoming visible) don't call the parts of
13335 redisplay constructing glyphs, so simply exposing a frame won't
13336 display anything in this case. So, we have to display these
13337 frames here explicitly. */
13340 Lisp_Object tail
, frame
;
13343 FOR_EACH_FRAME (tail
, frame
)
13345 int this_is_visible
= 0;
13347 if (XFRAME (frame
)->visible
)
13348 this_is_visible
= 1;
13349 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13350 if (XFRAME (frame
)->visible
)
13351 this_is_visible
= 1;
13353 if (this_is_visible
)
13357 if (new_count
!= number_of_visible_frames
)
13358 windows_or_buffers_changed
++;
13361 /* Change frame size now if a change is pending. */
13362 do_pending_window_change (1);
13364 /* If we just did a pending size change, or have additional
13365 visible frames, or selected_window changed, redisplay again. */
13366 if ((windows_or_buffers_changed
&& !pending
)
13367 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13370 /* Clear the face and image caches.
13372 We used to do this only if consider_all_windows_p. But the cache
13373 needs to be cleared if a timer creates images in the current
13374 buffer (e.g. the test case in Bug#6230). */
13376 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13378 clear_face_cache (0);
13379 clear_face_cache_count
= 0;
13382 #ifdef HAVE_WINDOW_SYSTEM
13383 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13385 clear_image_caches (Qnil
);
13386 clear_image_cache_count
= 0;
13388 #endif /* HAVE_WINDOW_SYSTEM */
13391 unbind_to (count
, Qnil
);
13396 /* Redisplay, but leave alone any recent echo area message unless
13397 another message has been requested in its place.
13399 This is useful in situations where you need to redisplay but no
13400 user action has occurred, making it inappropriate for the message
13401 area to be cleared. See tracking_off and
13402 wait_reading_process_output for examples of these situations.
13404 FROM_WHERE is an integer saying from where this function was
13405 called. This is useful for debugging. */
13408 redisplay_preserve_echo_area (int from_where
)
13410 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13412 if (!NILP (echo_area_buffer
[1]))
13414 /* We have a previously displayed message, but no current
13415 message. Redisplay the previous message. */
13416 display_last_displayed_message_p
= 1;
13417 redisplay_internal ();
13418 display_last_displayed_message_p
= 0;
13421 redisplay_internal ();
13423 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13424 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13425 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13429 /* Function registered with record_unwind_protect in
13430 redisplay_internal. Reset redisplaying_p to the value it had
13431 before redisplay_internal was called, and clear
13432 prevent_freeing_realized_faces_p. It also selects the previously
13433 selected frame, unless it has been deleted (by an X connection
13434 failure during redisplay, for example). */
13437 unwind_redisplay (Lisp_Object val
)
13439 Lisp_Object old_redisplaying_p
, old_frame
;
13441 old_redisplaying_p
= XCAR (val
);
13442 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13443 old_frame
= XCDR (val
);
13444 if (! EQ (old_frame
, selected_frame
)
13445 && FRAME_LIVE_P (XFRAME (old_frame
)))
13446 select_frame_for_redisplay (old_frame
);
13451 /* Mark the display of window W as accurate or inaccurate. If
13452 ACCURATE_P is non-zero mark display of W as accurate. If
13453 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13454 redisplay_internal is called. */
13457 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13459 if (BUFFERP (w
->buffer
))
13461 struct buffer
*b
= XBUFFER (w
->buffer
);
13464 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
13465 w
->last_overlay_modified
13466 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
13468 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
13472 b
->clip_changed
= 0;
13473 b
->prevent_redisplay_optimizations_p
= 0;
13475 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13476 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13477 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13478 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13480 w
->current_matrix
->buffer
= b
;
13481 w
->current_matrix
->begv
= BUF_BEGV (b
);
13482 w
->current_matrix
->zv
= BUF_ZV (b
);
13484 w
->last_cursor
= w
->cursor
;
13485 w
->last_cursor_off_p
= w
->cursor_off_p
;
13487 if (w
== XWINDOW (selected_window
))
13488 w
->last_point
= make_number (BUF_PT (b
));
13490 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
13496 w
->window_end_valid
= w
->buffer
;
13497 w
->update_mode_line
= Qnil
;
13502 /* Mark the display of windows in the window tree rooted at WINDOW as
13503 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13504 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13505 be redisplayed the next time redisplay_internal is called. */
13508 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13512 for (; !NILP (window
); window
= w
->next
)
13514 w
= XWINDOW (window
);
13515 mark_window_display_accurate_1 (w
, accurate_p
);
13517 if (!NILP (w
->vchild
))
13518 mark_window_display_accurate (w
->vchild
, accurate_p
);
13519 if (!NILP (w
->hchild
))
13520 mark_window_display_accurate (w
->hchild
, accurate_p
);
13525 update_overlay_arrows (1);
13529 /* Force a thorough redisplay the next time by setting
13530 last_arrow_position and last_arrow_string to t, which is
13531 unequal to any useful value of Voverlay_arrow_... */
13532 update_overlay_arrows (-1);
13537 /* Return value in display table DP (Lisp_Char_Table *) for character
13538 C. Since a display table doesn't have any parent, we don't have to
13539 follow parent. Do not call this function directly but use the
13540 macro DISP_CHAR_VECTOR. */
13543 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13547 if (ASCII_CHAR_P (c
))
13550 if (SUB_CHAR_TABLE_P (val
))
13551 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13557 XSETCHAR_TABLE (table
, dp
);
13558 val
= char_table_ref (table
, c
);
13567 /***********************************************************************
13569 ***********************************************************************/
13571 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13574 redisplay_windows (Lisp_Object window
)
13576 while (!NILP (window
))
13578 struct window
*w
= XWINDOW (window
);
13580 if (!NILP (w
->hchild
))
13581 redisplay_windows (w
->hchild
);
13582 else if (!NILP (w
->vchild
))
13583 redisplay_windows (w
->vchild
);
13584 else if (!NILP (w
->buffer
))
13586 displayed_buffer
= XBUFFER (w
->buffer
);
13587 /* Use list_of_error, not Qerror, so that
13588 we catch only errors and don't run the debugger. */
13589 internal_condition_case_1 (redisplay_window_0
, window
,
13591 redisplay_window_error
);
13599 redisplay_window_error (Lisp_Object ignore
)
13601 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13606 redisplay_window_0 (Lisp_Object window
)
13608 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13609 redisplay_window (window
, 0);
13614 redisplay_window_1 (Lisp_Object window
)
13616 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13617 redisplay_window (window
, 1);
13622 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13623 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13624 which positions recorded in ROW differ from current buffer
13627 Return 0 if cursor is not on this row, 1 otherwise. */
13630 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13631 struct glyph_matrix
*matrix
,
13632 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13635 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13636 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13637 struct glyph
*cursor
= NULL
;
13638 /* The last known character position in row. */
13639 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13641 ptrdiff_t pt_old
= PT
- delta
;
13642 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13643 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13644 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13645 /* A glyph beyond the edge of TEXT_AREA which we should never
13647 struct glyph
*glyphs_end
= end
;
13648 /* Non-zero means we've found a match for cursor position, but that
13649 glyph has the avoid_cursor_p flag set. */
13650 int match_with_avoid_cursor
= 0;
13651 /* Non-zero means we've seen at least one glyph that came from a
13653 int string_seen
= 0;
13654 /* Largest and smalles buffer positions seen so far during scan of
13656 ptrdiff_t bpos_max
= pos_before
;
13657 ptrdiff_t bpos_min
= pos_after
;
13658 /* Last buffer position covered by an overlay string with an integer
13659 `cursor' property. */
13660 ptrdiff_t bpos_covered
= 0;
13661 /* Non-zero means the display string on which to display the cursor
13662 comes from a text property, not from an overlay. */
13663 int string_from_text_prop
= 0;
13665 /* Skip over glyphs not having an object at the start and the end of
13666 the row. These are special glyphs like truncation marks on
13667 terminal frames. */
13668 if (row
->displays_text_p
)
13670 if (!row
->reversed_p
)
13673 && INTEGERP (glyph
->object
)
13674 && glyph
->charpos
< 0)
13676 x
+= glyph
->pixel_width
;
13680 && INTEGERP ((end
- 1)->object
)
13681 /* CHARPOS is zero for blanks and stretch glyphs
13682 inserted by extend_face_to_end_of_line. */
13683 && (end
- 1)->charpos
<= 0)
13685 glyph_before
= glyph
- 1;
13692 /* If the glyph row is reversed, we need to process it from back
13693 to front, so swap the edge pointers. */
13694 glyphs_end
= end
= glyph
- 1;
13695 glyph
+= row
->used
[TEXT_AREA
] - 1;
13697 while (glyph
> end
+ 1
13698 && INTEGERP (glyph
->object
)
13699 && glyph
->charpos
< 0)
13702 x
-= glyph
->pixel_width
;
13704 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13706 /* By default, in reversed rows we put the cursor on the
13707 rightmost (first in the reading order) glyph. */
13708 for (g
= end
+ 1; g
< glyph
; g
++)
13709 x
+= g
->pixel_width
;
13711 && INTEGERP ((end
+ 1)->object
)
13712 && (end
+ 1)->charpos
<= 0)
13714 glyph_before
= glyph
+ 1;
13718 else if (row
->reversed_p
)
13720 /* In R2L rows that don't display text, put the cursor on the
13721 rightmost glyph. Case in point: an empty last line that is
13722 part of an R2L paragraph. */
13724 /* Avoid placing the cursor on the last glyph of the row, where
13725 on terminal frames we hold the vertical border between
13726 adjacent windows. */
13727 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13728 && !WINDOW_RIGHTMOST_P (w
)
13729 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13731 x
= -1; /* will be computed below, at label compute_x */
13734 /* Step 1: Try to find the glyph whose character position
13735 corresponds to point. If that's not possible, find 2 glyphs
13736 whose character positions are the closest to point, one before
13737 point, the other after it. */
13738 if (!row
->reversed_p
)
13739 while (/* not marched to end of glyph row */
13741 /* glyph was not inserted by redisplay for internal purposes */
13742 && !INTEGERP (glyph
->object
))
13744 if (BUFFERP (glyph
->object
))
13746 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13748 if (glyph
->charpos
> bpos_max
)
13749 bpos_max
= glyph
->charpos
;
13750 if (glyph
->charpos
< bpos_min
)
13751 bpos_min
= glyph
->charpos
;
13752 if (!glyph
->avoid_cursor_p
)
13754 /* If we hit point, we've found the glyph on which to
13755 display the cursor. */
13758 match_with_avoid_cursor
= 0;
13761 /* See if we've found a better approximation to
13762 POS_BEFORE or to POS_AFTER. Note that we want the
13763 first (leftmost) glyph of all those that are the
13764 closest from below, and the last (rightmost) of all
13765 those from above. */
13766 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13768 pos_before
= glyph
->charpos
;
13769 glyph_before
= glyph
;
13771 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13773 pos_after
= glyph
->charpos
;
13774 glyph_after
= glyph
;
13777 else if (dpos
== 0)
13778 match_with_avoid_cursor
= 1;
13780 else if (STRINGP (glyph
->object
))
13782 Lisp_Object chprop
;
13783 ptrdiff_t glyph_pos
= glyph
->charpos
;
13785 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13787 if (INTEGERP (chprop
))
13789 bpos_covered
= bpos_max
+ XINT (chprop
);
13790 /* If the `cursor' property covers buffer positions up
13791 to and including point, we should display cursor on
13792 this glyph. Note that overlays and text properties
13793 with string values stop bidi reordering, so every
13794 buffer position to the left of the string is always
13795 smaller than any position to the right of the
13796 string. Therefore, if a `cursor' property on one
13797 of the string's characters has an integer value, we
13798 will break out of the loop below _before_ we get to
13799 the position match above. IOW, integer values of
13800 the `cursor' property override the "exact match for
13801 point" strategy of positioning the cursor. */
13802 /* Implementation note: bpos_max == pt_old when, e.g.,
13803 we are in an empty line, where bpos_max is set to
13804 MATRIX_ROW_START_CHARPOS, see above. */
13805 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13814 x
+= glyph
->pixel_width
;
13817 else if (glyph
> end
) /* row is reversed */
13818 while (!INTEGERP (glyph
->object
))
13820 if (BUFFERP (glyph
->object
))
13822 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13824 if (glyph
->charpos
> bpos_max
)
13825 bpos_max
= glyph
->charpos
;
13826 if (glyph
->charpos
< bpos_min
)
13827 bpos_min
= glyph
->charpos
;
13828 if (!glyph
->avoid_cursor_p
)
13832 match_with_avoid_cursor
= 0;
13835 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13837 pos_before
= glyph
->charpos
;
13838 glyph_before
= glyph
;
13840 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13842 pos_after
= glyph
->charpos
;
13843 glyph_after
= glyph
;
13846 else if (dpos
== 0)
13847 match_with_avoid_cursor
= 1;
13849 else if (STRINGP (glyph
->object
))
13851 Lisp_Object chprop
;
13852 ptrdiff_t glyph_pos
= glyph
->charpos
;
13854 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13856 if (INTEGERP (chprop
))
13858 bpos_covered
= bpos_max
+ XINT (chprop
);
13859 /* If the `cursor' property covers buffer positions up
13860 to and including point, we should display cursor on
13862 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13871 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13873 x
--; /* can't use any pixel_width */
13876 x
-= glyph
->pixel_width
;
13879 /* Step 2: If we didn't find an exact match for point, we need to
13880 look for a proper place to put the cursor among glyphs between
13881 GLYPH_BEFORE and GLYPH_AFTER. */
13882 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13883 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13884 && bpos_covered
< pt_old
)
13886 /* An empty line has a single glyph whose OBJECT is zero and
13887 whose CHARPOS is the position of a newline on that line.
13888 Note that on a TTY, there are more glyphs after that, which
13889 were produced by extend_face_to_end_of_line, but their
13890 CHARPOS is zero or negative. */
13892 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13893 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13895 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13897 ptrdiff_t ellipsis_pos
;
13899 /* Scan back over the ellipsis glyphs. */
13900 if (!row
->reversed_p
)
13902 ellipsis_pos
= (glyph
- 1)->charpos
;
13903 while (glyph
> row
->glyphs
[TEXT_AREA
]
13904 && (glyph
- 1)->charpos
== ellipsis_pos
)
13905 glyph
--, x
-= glyph
->pixel_width
;
13906 /* That loop always goes one position too far, including
13907 the glyph before the ellipsis. So scan forward over
13909 x
+= glyph
->pixel_width
;
13912 else /* row is reversed */
13914 ellipsis_pos
= (glyph
+ 1)->charpos
;
13915 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13916 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13917 glyph
++, x
+= glyph
->pixel_width
;
13918 x
-= glyph
->pixel_width
;
13922 else if (match_with_avoid_cursor
)
13924 cursor
= glyph_after
;
13927 else if (string_seen
)
13929 int incr
= row
->reversed_p
? -1 : +1;
13931 /* Need to find the glyph that came out of a string which is
13932 present at point. That glyph is somewhere between
13933 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13934 positioned between POS_BEFORE and POS_AFTER in the
13936 struct glyph
*start
, *stop
;
13937 ptrdiff_t pos
= pos_before
;
13941 /* If the row ends in a newline from a display string,
13942 reordering could have moved the glyphs belonging to the
13943 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
13944 in this case we extend the search to the last glyph in
13945 the row that was not inserted by redisplay. */
13946 if (row
->ends_in_newline_from_string_p
)
13949 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13952 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13953 correspond to POS_BEFORE and POS_AFTER, respectively. We
13954 need START and STOP in the order that corresponds to the
13955 row's direction as given by its reversed_p flag. If the
13956 directionality of characters between POS_BEFORE and
13957 POS_AFTER is the opposite of the row's base direction,
13958 these characters will have been reordered for display,
13959 and we need to reverse START and STOP. */
13960 if (!row
->reversed_p
)
13962 start
= min (glyph_before
, glyph_after
);
13963 stop
= max (glyph_before
, glyph_after
);
13967 start
= max (glyph_before
, glyph_after
);
13968 stop
= min (glyph_before
, glyph_after
);
13970 for (glyph
= start
+ incr
;
13971 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13974 /* Any glyphs that come from the buffer are here because
13975 of bidi reordering. Skip them, and only pay
13976 attention to glyphs that came from some string. */
13977 if (STRINGP (glyph
->object
))
13981 /* If the display property covers the newline, we
13982 need to search for it one position farther. */
13983 ptrdiff_t lim
= pos_after
13984 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
13986 string_from_text_prop
= 0;
13987 str
= glyph
->object
;
13988 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
13989 if (tem
== 0 /* from overlay */
13992 /* If the string from which this glyph came is
13993 found in the buffer at point, then we've
13994 found the glyph we've been looking for. If
13995 it comes from an overlay (tem == 0), and it
13996 has the `cursor' property on one of its
13997 glyphs, record that glyph as a candidate for
13998 displaying the cursor. (As in the
13999 unidirectional version, we will display the
14000 cursor on the last candidate we find.) */
14001 if (tem
== 0 || tem
== pt_old
)
14003 /* The glyphs from this string could have
14004 been reordered. Find the one with the
14005 smallest string position. Or there could
14006 be a character in the string with the
14007 `cursor' property, which means display
14008 cursor on that character's glyph. */
14009 ptrdiff_t strpos
= glyph
->charpos
;
14014 string_from_text_prop
= 1;
14017 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14018 && EQ (glyph
->object
, str
);
14022 ptrdiff_t gpos
= glyph
->charpos
;
14024 cprop
= Fget_char_property (make_number (gpos
),
14032 if (tem
&& glyph
->charpos
< strpos
)
14034 strpos
= glyph
->charpos
;
14043 pos
= tem
+ 1; /* don't find previous instances */
14045 /* This string is not what we want; skip all of the
14046 glyphs that came from it. */
14047 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14048 && EQ (glyph
->object
, str
))
14055 /* If we reached the end of the line, and END was from a string,
14056 the cursor is not on this line. */
14058 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14059 && STRINGP (end
->object
)
14060 && row
->continued_p
)
14063 /* A truncated row may not include PT among its character positions.
14064 Setting the cursor inside the scroll margin will trigger
14065 recalculation of hscroll in hscroll_window_tree. But if a
14066 display string covers point, defer to the string-handling
14067 code below to figure this out. */
14068 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14070 cursor
= glyph_before
;
14073 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14074 /* Zero-width characters produce no glyphs. */
14076 && (row
->reversed_p
14077 ? glyph_after
> glyphs_end
14078 : glyph_after
< glyphs_end
)))
14080 cursor
= glyph_after
;
14086 if (cursor
!= NULL
)
14092 /* Need to compute x that corresponds to GLYPH. */
14093 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14095 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14097 x
+= g
->pixel_width
;
14101 /* ROW could be part of a continued line, which, under bidi
14102 reordering, might have other rows whose start and end charpos
14103 occlude point. Only set w->cursor if we found a better
14104 approximation to the cursor position than we have from previously
14105 examined candidate rows belonging to the same continued line. */
14106 if (/* we already have a candidate row */
14107 w
->cursor
.vpos
>= 0
14108 /* that candidate is not the row we are processing */
14109 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14110 /* Make sure cursor.vpos specifies a row whose start and end
14111 charpos occlude point, and it is valid candidate for being a
14112 cursor-row. This is because some callers of this function
14113 leave cursor.vpos at the row where the cursor was displayed
14114 during the last redisplay cycle. */
14115 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14116 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14117 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14120 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14122 /* Don't consider glyphs that are outside TEXT_AREA. */
14123 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14125 /* Keep the candidate whose buffer position is the closest to
14126 point or has the `cursor' property. */
14127 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14128 w
->cursor
.hpos
>= 0
14129 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14130 && ((BUFFERP (g1
->object
)
14131 && (g1
->charpos
== pt_old
/* an exact match always wins */
14132 || (BUFFERP (glyph
->object
)
14133 && eabs (g1
->charpos
- pt_old
)
14134 < eabs (glyph
->charpos
- pt_old
))))
14135 /* previous candidate is a glyph from a string that has
14136 a non-nil `cursor' property */
14137 || (STRINGP (g1
->object
)
14138 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14139 Qcursor
, g1
->object
))
14140 /* previous candidate is from the same display
14141 string as this one, and the display string
14142 came from a text property */
14143 || (EQ (g1
->object
, glyph
->object
)
14144 && string_from_text_prop
)
14145 /* this candidate is from newline and its
14146 position is not an exact match */
14147 || (INTEGERP (glyph
->object
)
14148 && glyph
->charpos
!= pt_old
)))))
14150 /* If this candidate gives an exact match, use that. */
14151 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14152 /* If this candidate is a glyph created for the
14153 terminating newline of a line, and point is on that
14154 newline, it wins because it's an exact match. */
14155 || (!row
->continued_p
14156 && INTEGERP (glyph
->object
)
14157 && glyph
->charpos
== 0
14158 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14159 /* Otherwise, keep the candidate that comes from a row
14160 spanning less buffer positions. This may win when one or
14161 both candidate positions are on glyphs that came from
14162 display strings, for which we cannot compare buffer
14164 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14165 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14166 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14169 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14171 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14172 w
->cursor
.y
= row
->y
+ dy
;
14174 if (w
== XWINDOW (selected_window
))
14176 if (!row
->continued_p
14177 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14180 this_line_buffer
= XBUFFER (w
->buffer
);
14182 CHARPOS (this_line_start_pos
)
14183 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14184 BYTEPOS (this_line_start_pos
)
14185 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14187 CHARPOS (this_line_end_pos
)
14188 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14189 BYTEPOS (this_line_end_pos
)
14190 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14192 this_line_y
= w
->cursor
.y
;
14193 this_line_pixel_height
= row
->height
;
14194 this_line_vpos
= w
->cursor
.vpos
;
14195 this_line_start_x
= row
->x
;
14198 CHARPOS (this_line_start_pos
) = 0;
14205 /* Run window scroll functions, if any, for WINDOW with new window
14206 start STARTP. Sets the window start of WINDOW to that position.
14208 We assume that the window's buffer is really current. */
14210 static inline struct text_pos
14211 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14213 struct window
*w
= XWINDOW (window
);
14214 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14216 if (current_buffer
!= XBUFFER (w
->buffer
))
14219 if (!NILP (Vwindow_scroll_functions
))
14221 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14222 make_number (CHARPOS (startp
)));
14223 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14224 /* In case the hook functions switch buffers. */
14225 if (current_buffer
!= XBUFFER (w
->buffer
))
14226 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14233 /* Make sure the line containing the cursor is fully visible.
14234 A value of 1 means there is nothing to be done.
14235 (Either the line is fully visible, or it cannot be made so,
14236 or we cannot tell.)
14238 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14239 is higher than window.
14241 A value of 0 means the caller should do scrolling
14242 as if point had gone off the screen. */
14245 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14247 struct glyph_matrix
*matrix
;
14248 struct glyph_row
*row
;
14251 if (!make_cursor_line_fully_visible_p
)
14254 /* It's not always possible to find the cursor, e.g, when a window
14255 is full of overlay strings. Don't do anything in that case. */
14256 if (w
->cursor
.vpos
< 0)
14259 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14260 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14262 /* If the cursor row is not partially visible, there's nothing to do. */
14263 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14266 /* If the row the cursor is in is taller than the window's height,
14267 it's not clear what to do, so do nothing. */
14268 window_height
= window_box_height (w
);
14269 if (row
->height
>= window_height
)
14271 if (!force_p
|| MINI_WINDOW_P (w
)
14272 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14279 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14280 non-zero means only WINDOW is redisplayed in redisplay_internal.
14281 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14282 in redisplay_window to bring a partially visible line into view in
14283 the case that only the cursor has moved.
14285 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14286 last screen line's vertical height extends past the end of the screen.
14290 1 if scrolling succeeded
14292 0 if scrolling didn't find point.
14294 -1 if new fonts have been loaded so that we must interrupt
14295 redisplay, adjust glyph matrices, and try again. */
14301 SCROLLING_NEED_LARGER_MATRICES
14304 /* If scroll-conservatively is more than this, never recenter.
14306 If you change this, don't forget to update the doc string of
14307 `scroll-conservatively' and the Emacs manual. */
14308 #define SCROLL_LIMIT 100
14311 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14312 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14313 int temp_scroll_step
, int last_line_misfit
)
14315 struct window
*w
= XWINDOW (window
);
14316 struct frame
*f
= XFRAME (w
->frame
);
14317 struct text_pos pos
, startp
;
14319 int this_scroll_margin
, scroll_max
, rc
, height
;
14320 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14321 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14322 Lisp_Object aggressive
;
14323 /* We will never try scrolling more than this number of lines. */
14324 int scroll_limit
= SCROLL_LIMIT
;
14327 debug_method_add (w
, "try_scrolling");
14330 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14332 /* Compute scroll margin height in pixels. We scroll when point is
14333 within this distance from the top or bottom of the window. */
14334 if (scroll_margin
> 0)
14335 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14336 * FRAME_LINE_HEIGHT (f
);
14338 this_scroll_margin
= 0;
14340 /* Force arg_scroll_conservatively to have a reasonable value, to
14341 avoid scrolling too far away with slow move_it_* functions. Note
14342 that the user can supply scroll-conservatively equal to
14343 `most-positive-fixnum', which can be larger than INT_MAX. */
14344 if (arg_scroll_conservatively
> scroll_limit
)
14346 arg_scroll_conservatively
= scroll_limit
+ 1;
14347 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14349 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14350 /* Compute how much we should try to scroll maximally to bring
14351 point into view. */
14352 scroll_max
= (max (scroll_step
,
14353 max (arg_scroll_conservatively
, temp_scroll_step
))
14354 * FRAME_LINE_HEIGHT (f
));
14355 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14356 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14357 /* We're trying to scroll because of aggressive scrolling but no
14358 scroll_step is set. Choose an arbitrary one. */
14359 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14365 /* Decide whether to scroll down. */
14366 if (PT
> CHARPOS (startp
))
14368 int scroll_margin_y
;
14370 /* Compute the pixel ypos of the scroll margin, then move IT to
14371 either that ypos or PT, whichever comes first. */
14372 start_display (&it
, w
, startp
);
14373 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14374 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14375 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14376 (MOVE_TO_POS
| MOVE_TO_Y
));
14378 if (PT
> CHARPOS (it
.current
.pos
))
14380 int y0
= line_bottom_y (&it
);
14381 /* Compute how many pixels below window bottom to stop searching
14382 for PT. This avoids costly search for PT that is far away if
14383 the user limited scrolling by a small number of lines, but
14384 always finds PT if scroll_conservatively is set to a large
14385 number, such as most-positive-fixnum. */
14386 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14387 int y_to_move
= it
.last_visible_y
+ slack
;
14389 /* Compute the distance from the scroll margin to PT or to
14390 the scroll limit, whichever comes first. This should
14391 include the height of the cursor line, to make that line
14393 move_it_to (&it
, PT
, -1, y_to_move
,
14394 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14395 dy
= line_bottom_y (&it
) - y0
;
14397 if (dy
> scroll_max
)
14398 return SCROLLING_FAILED
;
14407 /* Point is in or below the bottom scroll margin, so move the
14408 window start down. If scrolling conservatively, move it just
14409 enough down to make point visible. If scroll_step is set,
14410 move it down by scroll_step. */
14411 if (arg_scroll_conservatively
)
14413 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14414 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14415 else if (scroll_step
|| temp_scroll_step
)
14416 amount_to_scroll
= scroll_max
;
14419 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14420 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14421 if (NUMBERP (aggressive
))
14423 double float_amount
= XFLOATINT (aggressive
) * height
;
14424 amount_to_scroll
= float_amount
;
14425 if (amount_to_scroll
== 0 && float_amount
> 0)
14426 amount_to_scroll
= 1;
14427 /* Don't let point enter the scroll margin near top of
14429 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14430 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14434 if (amount_to_scroll
<= 0)
14435 return SCROLLING_FAILED
;
14437 start_display (&it
, w
, startp
);
14438 if (arg_scroll_conservatively
<= scroll_limit
)
14439 move_it_vertically (&it
, amount_to_scroll
);
14442 /* Extra precision for users who set scroll-conservatively
14443 to a large number: make sure the amount we scroll
14444 the window start is never less than amount_to_scroll,
14445 which was computed as distance from window bottom to
14446 point. This matters when lines at window top and lines
14447 below window bottom have different height. */
14449 void *it1data
= NULL
;
14450 /* We use a temporary it1 because line_bottom_y can modify
14451 its argument, if it moves one line down; see there. */
14454 SAVE_IT (it1
, it
, it1data
);
14455 start_y
= line_bottom_y (&it1
);
14457 RESTORE_IT (&it
, &it
, it1data
);
14458 move_it_by_lines (&it
, 1);
14459 SAVE_IT (it1
, it
, it1data
);
14460 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14463 /* If STARTP is unchanged, move it down another screen line. */
14464 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14465 move_it_by_lines (&it
, 1);
14466 startp
= it
.current
.pos
;
14470 struct text_pos scroll_margin_pos
= startp
;
14472 /* See if point is inside the scroll margin at the top of the
14474 if (this_scroll_margin
)
14476 start_display (&it
, w
, startp
);
14477 move_it_vertically (&it
, this_scroll_margin
);
14478 scroll_margin_pos
= it
.current
.pos
;
14481 if (PT
< CHARPOS (scroll_margin_pos
))
14483 /* Point is in the scroll margin at the top of the window or
14484 above what is displayed in the window. */
14487 /* Compute the vertical distance from PT to the scroll
14488 margin position. Move as far as scroll_max allows, or
14489 one screenful, or 10 screen lines, whichever is largest.
14490 Give up if distance is greater than scroll_max. */
14491 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14492 start_display (&it
, w
, pos
);
14494 y_to_move
= max (it
.last_visible_y
,
14495 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14496 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14498 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14499 dy
= it
.current_y
- y0
;
14500 if (dy
> scroll_max
)
14501 return SCROLLING_FAILED
;
14503 /* Compute new window start. */
14504 start_display (&it
, w
, startp
);
14506 if (arg_scroll_conservatively
)
14507 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14508 max (scroll_step
, temp_scroll_step
));
14509 else if (scroll_step
|| temp_scroll_step
)
14510 amount_to_scroll
= scroll_max
;
14513 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14514 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14515 if (NUMBERP (aggressive
))
14517 double float_amount
= XFLOATINT (aggressive
) * height
;
14518 amount_to_scroll
= float_amount
;
14519 if (amount_to_scroll
== 0 && float_amount
> 0)
14520 amount_to_scroll
= 1;
14521 amount_to_scroll
-=
14522 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14523 /* Don't let point enter the scroll margin near
14524 bottom of the window. */
14525 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14526 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14530 if (amount_to_scroll
<= 0)
14531 return SCROLLING_FAILED
;
14533 move_it_vertically_backward (&it
, amount_to_scroll
);
14534 startp
= it
.current
.pos
;
14538 /* Run window scroll functions. */
14539 startp
= run_window_scroll_functions (window
, startp
);
14541 /* Display the window. Give up if new fonts are loaded, or if point
14543 if (!try_window (window
, startp
, 0))
14544 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14545 else if (w
->cursor
.vpos
< 0)
14547 clear_glyph_matrix (w
->desired_matrix
);
14548 rc
= SCROLLING_FAILED
;
14552 /* Maybe forget recorded base line for line number display. */
14553 if (!just_this_one_p
14554 || current_buffer
->clip_changed
14555 || BEG_UNCHANGED
< CHARPOS (startp
))
14556 w
->base_line_number
= Qnil
;
14558 /* If cursor ends up on a partially visible line,
14559 treat that as being off the bottom of the screen. */
14560 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14561 /* It's possible that the cursor is on the first line of the
14562 buffer, which is partially obscured due to a vscroll
14563 (Bug#7537). In that case, avoid looping forever . */
14564 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14566 clear_glyph_matrix (w
->desired_matrix
);
14567 ++extra_scroll_margin_lines
;
14570 rc
= SCROLLING_SUCCESS
;
14577 /* Compute a suitable window start for window W if display of W starts
14578 on a continuation line. Value is non-zero if a new window start
14581 The new window start will be computed, based on W's width, starting
14582 from the start of the continued line. It is the start of the
14583 screen line with the minimum distance from the old start W->start. */
14586 compute_window_start_on_continuation_line (struct window
*w
)
14588 struct text_pos pos
, start_pos
;
14589 int window_start_changed_p
= 0;
14591 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14593 /* If window start is on a continuation line... Window start may be
14594 < BEGV in case there's invisible text at the start of the
14595 buffer (M-x rmail, for example). */
14596 if (CHARPOS (start_pos
) > BEGV
14597 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14600 struct glyph_row
*row
;
14602 /* Handle the case that the window start is out of range. */
14603 if (CHARPOS (start_pos
) < BEGV
)
14604 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14605 else if (CHARPOS (start_pos
) > ZV
)
14606 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14608 /* Find the start of the continued line. This should be fast
14609 because scan_buffer is fast (newline cache). */
14610 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14611 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14612 row
, DEFAULT_FACE_ID
);
14613 reseat_at_previous_visible_line_start (&it
);
14615 /* If the line start is "too far" away from the window start,
14616 say it takes too much time to compute a new window start. */
14617 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14618 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14620 int min_distance
, distance
;
14622 /* Move forward by display lines to find the new window
14623 start. If window width was enlarged, the new start can
14624 be expected to be > the old start. If window width was
14625 decreased, the new window start will be < the old start.
14626 So, we're looking for the display line start with the
14627 minimum distance from the old window start. */
14628 pos
= it
.current
.pos
;
14629 min_distance
= INFINITY
;
14630 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14631 distance
< min_distance
)
14633 min_distance
= distance
;
14634 pos
= it
.current
.pos
;
14635 move_it_by_lines (&it
, 1);
14638 /* Set the window start there. */
14639 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14640 window_start_changed_p
= 1;
14644 return window_start_changed_p
;
14648 /* Try cursor movement in case text has not changed in window WINDOW,
14649 with window start STARTP. Value is
14651 CURSOR_MOVEMENT_SUCCESS if successful
14653 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14655 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14656 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14657 we want to scroll as if scroll-step were set to 1. See the code.
14659 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14660 which case we have to abort this redisplay, and adjust matrices
14665 CURSOR_MOVEMENT_SUCCESS
,
14666 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14667 CURSOR_MOVEMENT_MUST_SCROLL
,
14668 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14672 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14674 struct window
*w
= XWINDOW (window
);
14675 struct frame
*f
= XFRAME (w
->frame
);
14676 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14679 if (inhibit_try_cursor_movement
)
14683 /* Handle case where text has not changed, only point, and it has
14684 not moved off the frame. */
14685 if (/* Point may be in this window. */
14686 PT
>= CHARPOS (startp
)
14687 /* Selective display hasn't changed. */
14688 && !current_buffer
->clip_changed
14689 /* Function force-mode-line-update is used to force a thorough
14690 redisplay. It sets either windows_or_buffers_changed or
14691 update_mode_lines. So don't take a shortcut here for these
14693 && !update_mode_lines
14694 && !windows_or_buffers_changed
14695 && !cursor_type_changed
14696 /* Can't use this case if highlighting a region. When a
14697 region exists, cursor movement has to do more than just
14699 && !(!NILP (Vtransient_mark_mode
)
14700 && !NILP (BVAR (current_buffer
, mark_active
)))
14701 && NILP (w
->region_showing
)
14702 && NILP (Vshow_trailing_whitespace
)
14703 /* Right after splitting windows, last_point may be nil. */
14704 && INTEGERP (w
->last_point
)
14705 /* This code is not used for mini-buffer for the sake of the case
14706 of redisplaying to replace an echo area message; since in
14707 that case the mini-buffer contents per se are usually
14708 unchanged. This code is of no real use in the mini-buffer
14709 since the handling of this_line_start_pos, etc., in redisplay
14710 handles the same cases. */
14711 && !EQ (window
, minibuf_window
)
14712 /* When splitting windows or for new windows, it happens that
14713 redisplay is called with a nil window_end_vpos or one being
14714 larger than the window. This should really be fixed in
14715 window.c. I don't have this on my list, now, so we do
14716 approximately the same as the old redisplay code. --gerd. */
14717 && INTEGERP (w
->window_end_vpos
)
14718 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14719 && (FRAME_WINDOW_P (f
)
14720 || !overlay_arrow_in_current_buffer_p ()))
14722 int this_scroll_margin
, top_scroll_margin
;
14723 struct glyph_row
*row
= NULL
;
14726 debug_method_add (w
, "cursor movement");
14729 /* Scroll if point within this distance from the top or bottom
14730 of the window. This is a pixel value. */
14731 if (scroll_margin
> 0)
14733 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14734 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14737 this_scroll_margin
= 0;
14739 top_scroll_margin
= this_scroll_margin
;
14740 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14741 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14743 /* Start with the row the cursor was displayed during the last
14744 not paused redisplay. Give up if that row is not valid. */
14745 if (w
->last_cursor
.vpos
< 0
14746 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14747 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14750 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14751 if (row
->mode_line_p
)
14753 if (!row
->enabled_p
)
14754 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14757 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14759 int scroll_p
= 0, must_scroll
= 0;
14760 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14762 if (PT
> XFASTINT (w
->last_point
))
14764 /* Point has moved forward. */
14765 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14766 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14768 xassert (row
->enabled_p
);
14772 /* If the end position of a row equals the start
14773 position of the next row, and PT is at that position,
14774 we would rather display cursor in the next line. */
14775 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14776 && MATRIX_ROW_END_CHARPOS (row
) == PT
14777 && row
< w
->current_matrix
->rows
14778 + w
->current_matrix
->nrows
- 1
14779 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14780 && !cursor_row_p (row
))
14783 /* If within the scroll margin, scroll. Note that
14784 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14785 the next line would be drawn, and that
14786 this_scroll_margin can be zero. */
14787 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14788 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14789 /* Line is completely visible last line in window
14790 and PT is to be set in the next line. */
14791 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14792 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14793 && !row
->ends_at_zv_p
14794 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14797 else if (PT
< XFASTINT (w
->last_point
))
14799 /* Cursor has to be moved backward. Note that PT >=
14800 CHARPOS (startp) because of the outer if-statement. */
14801 while (!row
->mode_line_p
14802 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14803 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14804 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14805 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14806 row
> w
->current_matrix
->rows
14807 && (row
-1)->ends_in_newline_from_string_p
))))
14808 && (row
->y
> top_scroll_margin
14809 || CHARPOS (startp
) == BEGV
))
14811 xassert (row
->enabled_p
);
14815 /* Consider the following case: Window starts at BEGV,
14816 there is invisible, intangible text at BEGV, so that
14817 display starts at some point START > BEGV. It can
14818 happen that we are called with PT somewhere between
14819 BEGV and START. Try to handle that case. */
14820 if (row
< w
->current_matrix
->rows
14821 || row
->mode_line_p
)
14823 row
= w
->current_matrix
->rows
;
14824 if (row
->mode_line_p
)
14828 /* Due to newlines in overlay strings, we may have to
14829 skip forward over overlay strings. */
14830 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14831 && MATRIX_ROW_END_CHARPOS (row
) == PT
14832 && !cursor_row_p (row
))
14835 /* If within the scroll margin, scroll. */
14836 if (row
->y
< top_scroll_margin
14837 && CHARPOS (startp
) != BEGV
)
14842 /* Cursor did not move. So don't scroll even if cursor line
14843 is partially visible, as it was so before. */
14844 rc
= CURSOR_MOVEMENT_SUCCESS
;
14847 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14848 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14850 /* if PT is not in the glyph row, give up. */
14851 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14854 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14855 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14857 /* If rows are bidi-reordered and point moved, back up
14858 until we find a row that does not belong to a
14859 continuation line. This is because we must consider
14860 all rows of a continued line as candidates for the
14861 new cursor positioning, since row start and end
14862 positions change non-linearly with vertical position
14864 /* FIXME: Revisit this when glyph ``spilling'' in
14865 continuation lines' rows is implemented for
14866 bidi-reordered rows. */
14867 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14869 /* If we hit the beginning of the displayed portion
14870 without finding the first row of a continued
14872 if (row
<= w
->current_matrix
->rows
)
14874 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14877 xassert (row
->enabled_p
);
14883 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14884 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14885 && make_cursor_line_fully_visible_p
)
14887 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14888 && !row
->ends_at_zv_p
14889 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14890 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14891 else if (row
->height
> window_box_height (w
))
14893 /* If we end up in a partially visible line, let's
14894 make it fully visible, except when it's taller
14895 than the window, in which case we can't do much
14898 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14902 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14903 if (!cursor_row_fully_visible_p (w
, 0, 1))
14904 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14906 rc
= CURSOR_MOVEMENT_SUCCESS
;
14910 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14911 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14912 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14914 /* With bidi-reordered rows, there could be more than
14915 one candidate row whose start and end positions
14916 occlude point. We need to let set_cursor_from_row
14917 find the best candidate. */
14918 /* FIXME: Revisit this when glyph ``spilling'' in
14919 continuation lines' rows is implemented for
14920 bidi-reordered rows. */
14925 int at_zv_p
= 0, exact_match_p
= 0;
14927 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14928 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14929 && cursor_row_p (row
))
14930 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14932 /* As soon as we've found the exact match for point,
14933 or the first suitable row whose ends_at_zv_p flag
14934 is set, we are done. */
14936 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
14938 && w
->cursor
.hpos
>= 0
14939 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
14942 struct glyph_row
*candidate
=
14943 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14945 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14946 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
14949 (BUFFERP (g
->object
) && g
->charpos
== PT
)
14950 || (INTEGERP (g
->object
)
14951 && (g
->charpos
== PT
14952 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
14954 if (rv
&& (at_zv_p
|| exact_match_p
))
14956 rc
= CURSOR_MOVEMENT_SUCCESS
;
14959 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
14963 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14964 || row
->continued_p
)
14965 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14966 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14967 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14968 /* If we didn't find any candidate rows, or exited the
14969 loop before all the candidates were examined, signal
14970 to the caller that this method failed. */
14971 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14973 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14974 && !row
->continued_p
))
14975 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14977 rc
= CURSOR_MOVEMENT_SUCCESS
;
14983 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14985 rc
= CURSOR_MOVEMENT_SUCCESS
;
14990 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14991 && MATRIX_ROW_START_CHARPOS (row
) == PT
14992 && cursor_row_p (row
));
15000 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15004 set_vertical_scroll_bar (struct window
*w
)
15006 ptrdiff_t start
, end
, whole
;
15008 /* Calculate the start and end positions for the current window.
15009 At some point, it would be nice to choose between scrollbars
15010 which reflect the whole buffer size, with special markers
15011 indicating narrowing, and scrollbars which reflect only the
15014 Note that mini-buffers sometimes aren't displaying any text. */
15015 if (!MINI_WINDOW_P (w
)
15016 || (w
== XWINDOW (minibuf_window
)
15017 && NILP (echo_area_buffer
[0])))
15019 struct buffer
*buf
= XBUFFER (w
->buffer
);
15020 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15021 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15022 /* I don't think this is guaranteed to be right. For the
15023 moment, we'll pretend it is. */
15024 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15028 if (whole
< (end
- start
))
15029 whole
= end
- start
;
15032 start
= end
= whole
= 0;
15034 /* Indicate what this scroll bar ought to be displaying now. */
15035 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15036 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15037 (w
, end
- start
, whole
, start
);
15041 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15042 selected_window is redisplayed.
15044 We can return without actually redisplaying the window if
15045 fonts_changed_p is nonzero. In that case, redisplay_internal will
15049 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15051 struct window
*w
= XWINDOW (window
);
15052 struct frame
*f
= XFRAME (w
->frame
);
15053 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15054 struct buffer
*old
= current_buffer
;
15055 struct text_pos lpoint
, opoint
, startp
;
15056 int update_mode_line
;
15059 /* Record it now because it's overwritten. */
15060 int current_matrix_up_to_date_p
= 0;
15061 int used_current_matrix_p
= 0;
15062 /* This is less strict than current_matrix_up_to_date_p.
15063 It indicates that the buffer contents and narrowing are unchanged. */
15064 int buffer_unchanged_p
= 0;
15065 int temp_scroll_step
= 0;
15066 ptrdiff_t count
= SPECPDL_INDEX ();
15068 int centering_position
= -1;
15069 int last_line_misfit
= 0;
15070 ptrdiff_t beg_unchanged
, end_unchanged
;
15072 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15075 /* W must be a leaf window here. */
15076 xassert (!NILP (w
->buffer
));
15078 *w
->desired_matrix
->method
= 0;
15082 reconsider_clip_changes (w
, buffer
);
15084 /* Has the mode line to be updated? */
15085 update_mode_line
= (!NILP (w
->update_mode_line
)
15086 || update_mode_lines
15087 || buffer
->clip_changed
15088 || buffer
->prevent_redisplay_optimizations_p
);
15090 if (MINI_WINDOW_P (w
))
15092 if (w
== XWINDOW (echo_area_window
)
15093 && !NILP (echo_area_buffer
[0]))
15095 if (update_mode_line
)
15096 /* We may have to update a tty frame's menu bar or a
15097 tool-bar. Example `M-x C-h C-h C-g'. */
15098 goto finish_menu_bars
;
15100 /* We've already displayed the echo area glyphs in this window. */
15101 goto finish_scroll_bars
;
15103 else if ((w
!= XWINDOW (minibuf_window
)
15104 || minibuf_level
== 0)
15105 /* When buffer is nonempty, redisplay window normally. */
15106 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15107 /* Quail displays non-mini buffers in minibuffer window.
15108 In that case, redisplay the window normally. */
15109 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15111 /* W is a mini-buffer window, but it's not active, so clear
15113 int yb
= window_text_bottom_y (w
);
15114 struct glyph_row
*row
;
15117 for (y
= 0, row
= w
->desired_matrix
->rows
;
15119 y
+= row
->height
, ++row
)
15120 blank_row (w
, row
, y
);
15121 goto finish_scroll_bars
;
15124 clear_glyph_matrix (w
->desired_matrix
);
15127 /* Otherwise set up data on this window; select its buffer and point
15129 /* Really select the buffer, for the sake of buffer-local
15131 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15133 current_matrix_up_to_date_p
15134 = (!NILP (w
->window_end_valid
)
15135 && !current_buffer
->clip_changed
15136 && !current_buffer
->prevent_redisplay_optimizations_p
15137 && XFASTINT (w
->last_modified
) >= MODIFF
15138 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15140 /* Run the window-bottom-change-functions
15141 if it is possible that the text on the screen has changed
15142 (either due to modification of the text, or any other reason). */
15143 if (!current_matrix_up_to_date_p
15144 && !NILP (Vwindow_text_change_functions
))
15146 safe_run_hooks (Qwindow_text_change_functions
);
15150 beg_unchanged
= BEG_UNCHANGED
;
15151 end_unchanged
= END_UNCHANGED
;
15153 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15155 specbind (Qinhibit_point_motion_hooks
, Qt
);
15158 = (!NILP (w
->window_end_valid
)
15159 && !current_buffer
->clip_changed
15160 && XFASTINT (w
->last_modified
) >= MODIFF
15161 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15163 /* When windows_or_buffers_changed is non-zero, we can't rely on
15164 the window end being valid, so set it to nil there. */
15165 if (windows_or_buffers_changed
)
15167 /* If window starts on a continuation line, maybe adjust the
15168 window start in case the window's width changed. */
15169 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15170 compute_window_start_on_continuation_line (w
);
15172 w
->window_end_valid
= Qnil
;
15175 /* Some sanity checks. */
15176 CHECK_WINDOW_END (w
);
15177 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15179 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15182 /* If %c is in mode line, update it if needed. */
15183 if (!NILP (w
->column_number_displayed
)
15184 /* This alternative quickly identifies a common case
15185 where no change is needed. */
15186 && !(PT
== XFASTINT (w
->last_point
)
15187 && XFASTINT (w
->last_modified
) >= MODIFF
15188 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
15189 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15190 update_mode_line
= 1;
15192 /* Count number of windows showing the selected buffer. An indirect
15193 buffer counts as its base buffer. */
15194 if (!just_this_one_p
)
15196 struct buffer
*current_base
, *window_base
;
15197 current_base
= current_buffer
;
15198 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15199 if (current_base
->base_buffer
)
15200 current_base
= current_base
->base_buffer
;
15201 if (window_base
->base_buffer
)
15202 window_base
= window_base
->base_buffer
;
15203 if (current_base
== window_base
)
15207 /* Point refers normally to the selected window. For any other
15208 window, set up appropriate value. */
15209 if (!EQ (window
, selected_window
))
15211 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15212 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15216 new_pt_byte
= BEGV_BYTE
;
15217 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15219 else if (new_pt
> (ZV
- 1))
15222 new_pt_byte
= ZV_BYTE
;
15223 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15226 /* We don't use SET_PT so that the point-motion hooks don't run. */
15227 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15230 /* If any of the character widths specified in the display table
15231 have changed, invalidate the width run cache. It's true that
15232 this may be a bit late to catch such changes, but the rest of
15233 redisplay goes (non-fatally) haywire when the display table is
15234 changed, so why should we worry about doing any better? */
15235 if (current_buffer
->width_run_cache
)
15237 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15239 if (! disptab_matches_widthtab (disptab
,
15240 XVECTOR (BVAR (current_buffer
, width_table
))))
15242 invalidate_region_cache (current_buffer
,
15243 current_buffer
->width_run_cache
,
15245 recompute_width_table (current_buffer
, disptab
);
15249 /* If window-start is screwed up, choose a new one. */
15250 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15253 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15255 /* If someone specified a new starting point but did not insist,
15256 check whether it can be used. */
15257 if (!NILP (w
->optional_new_start
)
15258 && CHARPOS (startp
) >= BEGV
15259 && CHARPOS (startp
) <= ZV
)
15261 w
->optional_new_start
= Qnil
;
15262 start_display (&it
, w
, startp
);
15263 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15264 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15265 if (IT_CHARPOS (it
) == PT
)
15266 w
->force_start
= Qt
;
15267 /* IT may overshoot PT if text at PT is invisible. */
15268 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15269 w
->force_start
= Qt
;
15274 /* Handle case where place to start displaying has been specified,
15275 unless the specified location is outside the accessible range. */
15276 if (!NILP (w
->force_start
)
15277 || w
->frozen_window_start_p
)
15279 /* We set this later on if we have to adjust point. */
15282 w
->force_start
= Qnil
;
15284 w
->window_end_valid
= Qnil
;
15286 /* Forget any recorded base line for line number display. */
15287 if (!buffer_unchanged_p
)
15288 w
->base_line_number
= Qnil
;
15290 /* Redisplay the mode line. Select the buffer properly for that.
15291 Also, run the hook window-scroll-functions
15292 because we have scrolled. */
15293 /* Note, we do this after clearing force_start because
15294 if there's an error, it is better to forget about force_start
15295 than to get into an infinite loop calling the hook functions
15296 and having them get more errors. */
15297 if (!update_mode_line
15298 || ! NILP (Vwindow_scroll_functions
))
15300 update_mode_line
= 1;
15301 w
->update_mode_line
= Qt
;
15302 startp
= run_window_scroll_functions (window
, startp
);
15305 w
->last_modified
= make_number (0);
15306 w
->last_overlay_modified
= make_number (0);
15307 if (CHARPOS (startp
) < BEGV
)
15308 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15309 else if (CHARPOS (startp
) > ZV
)
15310 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15312 /* Redisplay, then check if cursor has been set during the
15313 redisplay. Give up if new fonts were loaded. */
15314 /* We used to issue a CHECK_MARGINS argument to try_window here,
15315 but this causes scrolling to fail when point begins inside
15316 the scroll margin (bug#148) -- cyd */
15317 if (!try_window (window
, startp
, 0))
15319 w
->force_start
= Qt
;
15320 clear_glyph_matrix (w
->desired_matrix
);
15321 goto need_larger_matrices
;
15324 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15326 /* If point does not appear, try to move point so it does
15327 appear. The desired matrix has been built above, so we
15328 can use it here. */
15329 new_vpos
= window_box_height (w
) / 2;
15332 if (!cursor_row_fully_visible_p (w
, 0, 0))
15334 /* Point does appear, but on a line partly visible at end of window.
15335 Move it back to a fully-visible line. */
15336 new_vpos
= window_box_height (w
);
15339 /* If we need to move point for either of the above reasons,
15340 now actually do it. */
15343 struct glyph_row
*row
;
15345 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15346 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15349 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15350 MATRIX_ROW_START_BYTEPOS (row
));
15352 if (w
!= XWINDOW (selected_window
))
15353 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15354 else if (current_buffer
== old
)
15355 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15357 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15359 /* If we are highlighting the region, then we just changed
15360 the region, so redisplay to show it. */
15361 if (!NILP (Vtransient_mark_mode
)
15362 && !NILP (BVAR (current_buffer
, mark_active
)))
15364 clear_glyph_matrix (w
->desired_matrix
);
15365 if (!try_window (window
, startp
, 0))
15366 goto need_larger_matrices
;
15371 debug_method_add (w
, "forced window start");
15376 /* Handle case where text has not changed, only point, and it has
15377 not moved off the frame, and we are not retrying after hscroll.
15378 (current_matrix_up_to_date_p is nonzero when retrying.) */
15379 if (current_matrix_up_to_date_p
15380 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15381 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15385 case CURSOR_MOVEMENT_SUCCESS
:
15386 used_current_matrix_p
= 1;
15389 case CURSOR_MOVEMENT_MUST_SCROLL
:
15390 goto try_to_scroll
;
15396 /* If current starting point was originally the beginning of a line
15397 but no longer is, find a new starting point. */
15398 else if (!NILP (w
->start_at_line_beg
)
15399 && !(CHARPOS (startp
) <= BEGV
15400 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15403 debug_method_add (w
, "recenter 1");
15408 /* Try scrolling with try_window_id. Value is > 0 if update has
15409 been done, it is -1 if we know that the same window start will
15410 not work. It is 0 if unsuccessful for some other reason. */
15411 else if ((tem
= try_window_id (w
)) != 0)
15414 debug_method_add (w
, "try_window_id %d", tem
);
15417 if (fonts_changed_p
)
15418 goto need_larger_matrices
;
15422 /* Otherwise try_window_id has returned -1 which means that we
15423 don't want the alternative below this comment to execute. */
15425 else if (CHARPOS (startp
) >= BEGV
15426 && CHARPOS (startp
) <= ZV
15427 && PT
>= CHARPOS (startp
)
15428 && (CHARPOS (startp
) < ZV
15429 /* Avoid starting at end of buffer. */
15430 || CHARPOS (startp
) == BEGV
15431 || (XFASTINT (w
->last_modified
) >= MODIFF
15432 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
15434 int d1
, d2
, d3
, d4
, d5
, d6
;
15436 /* If first window line is a continuation line, and window start
15437 is inside the modified region, but the first change is before
15438 current window start, we must select a new window start.
15440 However, if this is the result of a down-mouse event (e.g. by
15441 extending the mouse-drag-overlay), we don't want to select a
15442 new window start, since that would change the position under
15443 the mouse, resulting in an unwanted mouse-movement rather
15444 than a simple mouse-click. */
15445 if (NILP (w
->start_at_line_beg
)
15446 && NILP (do_mouse_tracking
)
15447 && CHARPOS (startp
) > BEGV
15448 && CHARPOS (startp
) > BEG
+ beg_unchanged
15449 && CHARPOS (startp
) <= Z
- end_unchanged
15450 /* Even if w->start_at_line_beg is nil, a new window may
15451 start at a line_beg, since that's how set_buffer_window
15452 sets it. So, we need to check the return value of
15453 compute_window_start_on_continuation_line. (See also
15455 && XMARKER (w
->start
)->buffer
== current_buffer
15456 && compute_window_start_on_continuation_line (w
)
15457 /* It doesn't make sense to force the window start like we
15458 do at label force_start if it is already known that point
15459 will not be visible in the resulting window, because
15460 doing so will move point from its correct position
15461 instead of scrolling the window to bring point into view.
15463 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15465 w
->force_start
= Qt
;
15466 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15471 debug_method_add (w
, "same window start");
15474 /* Try to redisplay starting at same place as before.
15475 If point has not moved off frame, accept the results. */
15476 if (!current_matrix_up_to_date_p
15477 /* Don't use try_window_reusing_current_matrix in this case
15478 because a window scroll function can have changed the
15480 || !NILP (Vwindow_scroll_functions
)
15481 || MINI_WINDOW_P (w
)
15482 || !(used_current_matrix_p
15483 = try_window_reusing_current_matrix (w
)))
15485 IF_DEBUG (debug_method_add (w
, "1"));
15486 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15487 /* -1 means we need to scroll.
15488 0 means we need new matrices, but fonts_changed_p
15489 is set in that case, so we will detect it below. */
15490 goto try_to_scroll
;
15493 if (fonts_changed_p
)
15494 goto need_larger_matrices
;
15496 if (w
->cursor
.vpos
>= 0)
15498 if (!just_this_one_p
15499 || current_buffer
->clip_changed
15500 || BEG_UNCHANGED
< CHARPOS (startp
))
15501 /* Forget any recorded base line for line number display. */
15502 w
->base_line_number
= Qnil
;
15504 if (!cursor_row_fully_visible_p (w
, 1, 0))
15506 clear_glyph_matrix (w
->desired_matrix
);
15507 last_line_misfit
= 1;
15509 /* Drop through and scroll. */
15514 clear_glyph_matrix (w
->desired_matrix
);
15519 w
->last_modified
= make_number (0);
15520 w
->last_overlay_modified
= make_number (0);
15522 /* Redisplay the mode line. Select the buffer properly for that. */
15523 if (!update_mode_line
)
15525 update_mode_line
= 1;
15526 w
->update_mode_line
= Qt
;
15529 /* Try to scroll by specified few lines. */
15530 if ((scroll_conservatively
15531 || emacs_scroll_step
15532 || temp_scroll_step
15533 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15534 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15535 && CHARPOS (startp
) >= BEGV
15536 && CHARPOS (startp
) <= ZV
)
15538 /* The function returns -1 if new fonts were loaded, 1 if
15539 successful, 0 if not successful. */
15540 int ss
= try_scrolling (window
, just_this_one_p
,
15541 scroll_conservatively
,
15543 temp_scroll_step
, last_line_misfit
);
15546 case SCROLLING_SUCCESS
:
15549 case SCROLLING_NEED_LARGER_MATRICES
:
15550 goto need_larger_matrices
;
15552 case SCROLLING_FAILED
:
15560 /* Finally, just choose a place to start which positions point
15561 according to user preferences. */
15566 debug_method_add (w
, "recenter");
15569 /* w->vscroll = 0; */
15571 /* Forget any previously recorded base line for line number display. */
15572 if (!buffer_unchanged_p
)
15573 w
->base_line_number
= Qnil
;
15575 /* Determine the window start relative to point. */
15576 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15577 it
.current_y
= it
.last_visible_y
;
15578 if (centering_position
< 0)
15582 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15584 ptrdiff_t margin_pos
= CHARPOS (startp
);
15585 Lisp_Object aggressive
;
15588 /* If there is a scroll margin at the top of the window, find
15589 its character position. */
15591 /* Cannot call start_display if startp is not in the
15592 accessible region of the buffer. This can happen when we
15593 have just switched to a different buffer and/or changed
15594 its restriction. In that case, startp is initialized to
15595 the character position 1 (BEG) because we did not yet
15596 have chance to display the buffer even once. */
15597 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15600 void *it1data
= NULL
;
15602 SAVE_IT (it1
, it
, it1data
);
15603 start_display (&it1
, w
, startp
);
15604 move_it_vertically (&it1
, margin
);
15605 margin_pos
= IT_CHARPOS (it1
);
15606 RESTORE_IT (&it
, &it
, it1data
);
15608 scrolling_up
= PT
> margin_pos
;
15611 ? BVAR (current_buffer
, scroll_up_aggressively
)
15612 : BVAR (current_buffer
, scroll_down_aggressively
);
15614 if (!MINI_WINDOW_P (w
)
15615 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15619 /* Setting scroll-conservatively overrides
15620 scroll-*-aggressively. */
15621 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15623 double float_amount
= XFLOATINT (aggressive
);
15625 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15626 if (pt_offset
== 0 && float_amount
> 0)
15628 if (pt_offset
&& margin
> 0)
15631 /* Compute how much to move the window start backward from
15632 point so that point will be displayed where the user
15636 centering_position
= it
.last_visible_y
;
15638 centering_position
-= pt_offset
;
15639 centering_position
-=
15640 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15641 + WINDOW_HEADER_LINE_HEIGHT (w
);
15642 /* Don't let point enter the scroll margin near top of
15644 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15645 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15648 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15651 /* Set the window start half the height of the window backward
15653 centering_position
= window_box_height (w
) / 2;
15655 move_it_vertically_backward (&it
, centering_position
);
15657 xassert (IT_CHARPOS (it
) >= BEGV
);
15659 /* The function move_it_vertically_backward may move over more
15660 than the specified y-distance. If it->w is small, e.g. a
15661 mini-buffer window, we may end up in front of the window's
15662 display area. Start displaying at the start of the line
15663 containing PT in this case. */
15664 if (it
.current_y
<= 0)
15666 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15667 move_it_vertically_backward (&it
, 0);
15671 it
.current_x
= it
.hpos
= 0;
15673 /* Set the window start position here explicitly, to avoid an
15674 infinite loop in case the functions in window-scroll-functions
15676 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15678 /* Run scroll hooks. */
15679 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15681 /* Redisplay the window. */
15682 if (!current_matrix_up_to_date_p
15683 || windows_or_buffers_changed
15684 || cursor_type_changed
15685 /* Don't use try_window_reusing_current_matrix in this case
15686 because it can have changed the buffer. */
15687 || !NILP (Vwindow_scroll_functions
)
15688 || !just_this_one_p
15689 || MINI_WINDOW_P (w
)
15690 || !(used_current_matrix_p
15691 = try_window_reusing_current_matrix (w
)))
15692 try_window (window
, startp
, 0);
15694 /* If new fonts have been loaded (due to fontsets), give up. We
15695 have to start a new redisplay since we need to re-adjust glyph
15697 if (fonts_changed_p
)
15698 goto need_larger_matrices
;
15700 /* If cursor did not appear assume that the middle of the window is
15701 in the first line of the window. Do it again with the next line.
15702 (Imagine a window of height 100, displaying two lines of height
15703 60. Moving back 50 from it->last_visible_y will end in the first
15705 if (w
->cursor
.vpos
< 0)
15707 if (!NILP (w
->window_end_valid
)
15708 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15710 clear_glyph_matrix (w
->desired_matrix
);
15711 move_it_by_lines (&it
, 1);
15712 try_window (window
, it
.current
.pos
, 0);
15714 else if (PT
< IT_CHARPOS (it
))
15716 clear_glyph_matrix (w
->desired_matrix
);
15717 move_it_by_lines (&it
, -1);
15718 try_window (window
, it
.current
.pos
, 0);
15722 /* Not much we can do about it. */
15726 /* Consider the following case: Window starts at BEGV, there is
15727 invisible, intangible text at BEGV, so that display starts at
15728 some point START > BEGV. It can happen that we are called with
15729 PT somewhere between BEGV and START. Try to handle that case. */
15730 if (w
->cursor
.vpos
< 0)
15732 struct glyph_row
*row
= w
->current_matrix
->rows
;
15733 if (row
->mode_line_p
)
15735 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15738 if (!cursor_row_fully_visible_p (w
, 0, 0))
15740 /* If vscroll is enabled, disable it and try again. */
15744 clear_glyph_matrix (w
->desired_matrix
);
15748 /* Users who set scroll-conservatively to a large number want
15749 point just above/below the scroll margin. If we ended up
15750 with point's row partially visible, move the window start to
15751 make that row fully visible and out of the margin. */
15752 if (scroll_conservatively
> SCROLL_LIMIT
)
15756 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15758 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15760 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15761 clear_glyph_matrix (w
->desired_matrix
);
15762 if (1 == try_window (window
, it
.current
.pos
,
15763 TRY_WINDOW_CHECK_MARGINS
))
15767 /* If centering point failed to make the whole line visible,
15768 put point at the top instead. That has to make the whole line
15769 visible, if it can be done. */
15770 if (centering_position
== 0)
15773 clear_glyph_matrix (w
->desired_matrix
);
15774 centering_position
= 0;
15780 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15781 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15782 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15785 /* Display the mode line, if we must. */
15786 if ((update_mode_line
15787 /* If window not full width, must redo its mode line
15788 if (a) the window to its side is being redone and
15789 (b) we do a frame-based redisplay. This is a consequence
15790 of how inverted lines are drawn in frame-based redisplay. */
15791 || (!just_this_one_p
15792 && !FRAME_WINDOW_P (f
)
15793 && !WINDOW_FULL_WIDTH_P (w
))
15794 /* Line number to display. */
15795 || INTEGERP (w
->base_line_pos
)
15796 /* Column number is displayed and different from the one displayed. */
15797 || (!NILP (w
->column_number_displayed
)
15798 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15799 /* This means that the window has a mode line. */
15800 && (WINDOW_WANTS_MODELINE_P (w
)
15801 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15803 display_mode_lines (w
);
15805 /* If mode line height has changed, arrange for a thorough
15806 immediate redisplay using the correct mode line height. */
15807 if (WINDOW_WANTS_MODELINE_P (w
)
15808 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15810 fonts_changed_p
= 1;
15811 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15812 = DESIRED_MODE_LINE_HEIGHT (w
);
15815 /* If header line height has changed, arrange for a thorough
15816 immediate redisplay using the correct header line height. */
15817 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15818 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15820 fonts_changed_p
= 1;
15821 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15822 = DESIRED_HEADER_LINE_HEIGHT (w
);
15825 if (fonts_changed_p
)
15826 goto need_larger_matrices
;
15829 if (!line_number_displayed
15830 && !BUFFERP (w
->base_line_pos
))
15832 w
->base_line_pos
= Qnil
;
15833 w
->base_line_number
= Qnil
;
15838 /* When we reach a frame's selected window, redo the frame's menu bar. */
15839 if (update_mode_line
15840 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15842 int redisplay_menu_p
= 0;
15844 if (FRAME_WINDOW_P (f
))
15846 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15847 || defined (HAVE_NS) || defined (USE_GTK)
15848 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15850 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15854 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15856 if (redisplay_menu_p
)
15857 display_menu_bar (w
);
15859 #ifdef HAVE_WINDOW_SYSTEM
15860 if (FRAME_WINDOW_P (f
))
15862 #if defined (USE_GTK) || defined (HAVE_NS)
15863 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15864 redisplay_tool_bar (f
);
15866 if (WINDOWP (f
->tool_bar_window
)
15867 && (FRAME_TOOL_BAR_LINES (f
) > 0
15868 || !NILP (Vauto_resize_tool_bars
))
15869 && redisplay_tool_bar (f
))
15870 ignore_mouse_drag_p
= 1;
15876 #ifdef HAVE_WINDOW_SYSTEM
15877 if (FRAME_WINDOW_P (f
)
15878 && update_window_fringes (w
, (just_this_one_p
15879 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15880 || w
->pseudo_window_p
)))
15884 if (draw_window_fringes (w
, 1))
15885 x_draw_vertical_border (w
);
15889 #endif /* HAVE_WINDOW_SYSTEM */
15891 /* We go to this label, with fonts_changed_p nonzero,
15892 if it is necessary to try again using larger glyph matrices.
15893 We have to redeem the scroll bar even in this case,
15894 because the loop in redisplay_internal expects that. */
15895 need_larger_matrices
:
15897 finish_scroll_bars
:
15899 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15901 /* Set the thumb's position and size. */
15902 set_vertical_scroll_bar (w
);
15904 /* Note that we actually used the scroll bar attached to this
15905 window, so it shouldn't be deleted at the end of redisplay. */
15906 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15907 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15910 /* Restore current_buffer and value of point in it. The window
15911 update may have changed the buffer, so first make sure `opoint'
15912 is still valid (Bug#6177). */
15913 if (CHARPOS (opoint
) < BEGV
)
15914 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15915 else if (CHARPOS (opoint
) > ZV
)
15916 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15918 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15920 set_buffer_internal_1 (old
);
15921 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15922 shorter. This can be caused by log truncation in *Messages*. */
15923 if (CHARPOS (lpoint
) <= ZV
)
15924 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15926 unbind_to (count
, Qnil
);
15930 /* Build the complete desired matrix of WINDOW with a window start
15931 buffer position POS.
15933 Value is 1 if successful. It is zero if fonts were loaded during
15934 redisplay which makes re-adjusting glyph matrices necessary, and -1
15935 if point would appear in the scroll margins.
15936 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15937 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15941 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15943 struct window
*w
= XWINDOW (window
);
15945 struct glyph_row
*last_text_row
= NULL
;
15946 struct frame
*f
= XFRAME (w
->frame
);
15948 /* Make POS the new window start. */
15949 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15951 /* Mark cursor position as unknown. No overlay arrow seen. */
15952 w
->cursor
.vpos
= -1;
15953 overlay_arrow_seen
= 0;
15955 /* Initialize iterator and info to start at POS. */
15956 start_display (&it
, w
, pos
);
15958 /* Display all lines of W. */
15959 while (it
.current_y
< it
.last_visible_y
)
15961 if (display_line (&it
))
15962 last_text_row
= it
.glyph_row
- 1;
15963 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15967 /* Don't let the cursor end in the scroll margins. */
15968 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15969 && !MINI_WINDOW_P (w
))
15971 int this_scroll_margin
;
15973 if (scroll_margin
> 0)
15975 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15976 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15979 this_scroll_margin
= 0;
15981 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15982 && w
->cursor
.y
< this_scroll_margin
15983 && CHARPOS (pos
) > BEGV
15984 && IT_CHARPOS (it
) < ZV
)
15985 /* rms: considering make_cursor_line_fully_visible_p here
15986 seems to give wrong results. We don't want to recenter
15987 when the last line is partly visible, we want to allow
15988 that case to be handled in the usual way. */
15989 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15991 w
->cursor
.vpos
= -1;
15992 clear_glyph_matrix (w
->desired_matrix
);
15997 /* If bottom moved off end of frame, change mode line percentage. */
15998 if (XFASTINT (w
->window_end_pos
) <= 0
15999 && Z
!= IT_CHARPOS (it
))
16000 w
->update_mode_line
= Qt
;
16002 /* Set window_end_pos to the offset of the last character displayed
16003 on the window from the end of current_buffer. Set
16004 window_end_vpos to its row number. */
16007 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16008 w
->window_end_bytepos
16009 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16011 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16013 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16014 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16015 ->displays_text_p
);
16019 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16020 w
->window_end_pos
= make_number (Z
- ZV
);
16021 w
->window_end_vpos
= make_number (0);
16024 /* But that is not valid info until redisplay finishes. */
16025 w
->window_end_valid
= Qnil
;
16031 /************************************************************************
16032 Window redisplay reusing current matrix when buffer has not changed
16033 ************************************************************************/
16035 /* Try redisplay of window W showing an unchanged buffer with a
16036 different window start than the last time it was displayed by
16037 reusing its current matrix. Value is non-zero if successful.
16038 W->start is the new window start. */
16041 try_window_reusing_current_matrix (struct window
*w
)
16043 struct frame
*f
= XFRAME (w
->frame
);
16044 struct glyph_row
*bottom_row
;
16047 struct text_pos start
, new_start
;
16048 int nrows_scrolled
, i
;
16049 struct glyph_row
*last_text_row
;
16050 struct glyph_row
*last_reused_text_row
;
16051 struct glyph_row
*start_row
;
16052 int start_vpos
, min_y
, max_y
;
16055 if (inhibit_try_window_reusing
)
16059 if (/* This function doesn't handle terminal frames. */
16060 !FRAME_WINDOW_P (f
)
16061 /* Don't try to reuse the display if windows have been split
16063 || windows_or_buffers_changed
16064 || cursor_type_changed
)
16067 /* Can't do this if region may have changed. */
16068 if ((!NILP (Vtransient_mark_mode
)
16069 && !NILP (BVAR (current_buffer
, mark_active
)))
16070 || !NILP (w
->region_showing
)
16071 || !NILP (Vshow_trailing_whitespace
))
16074 /* If top-line visibility has changed, give up. */
16075 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16076 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16079 /* Give up if old or new display is scrolled vertically. We could
16080 make this function handle this, but right now it doesn't. */
16081 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16082 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16085 /* The variable new_start now holds the new window start. The old
16086 start `start' can be determined from the current matrix. */
16087 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16088 start
= start_row
->minpos
;
16089 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16091 /* Clear the desired matrix for the display below. */
16092 clear_glyph_matrix (w
->desired_matrix
);
16094 if (CHARPOS (new_start
) <= CHARPOS (start
))
16096 /* Don't use this method if the display starts with an ellipsis
16097 displayed for invisible text. It's not easy to handle that case
16098 below, and it's certainly not worth the effort since this is
16099 not a frequent case. */
16100 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16103 IF_DEBUG (debug_method_add (w
, "twu1"));
16105 /* Display up to a row that can be reused. The variable
16106 last_text_row is set to the last row displayed that displays
16107 text. Note that it.vpos == 0 if or if not there is a
16108 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16109 start_display (&it
, w
, new_start
);
16110 w
->cursor
.vpos
= -1;
16111 last_text_row
= last_reused_text_row
= NULL
;
16113 while (it
.current_y
< it
.last_visible_y
16114 && !fonts_changed_p
)
16116 /* If we have reached into the characters in the START row,
16117 that means the line boundaries have changed. So we
16118 can't start copying with the row START. Maybe it will
16119 work to start copying with the following row. */
16120 while (IT_CHARPOS (it
) > CHARPOS (start
))
16122 /* Advance to the next row as the "start". */
16124 start
= start_row
->minpos
;
16125 /* If there are no more rows to try, or just one, give up. */
16126 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16127 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16128 || CHARPOS (start
) == ZV
)
16130 clear_glyph_matrix (w
->desired_matrix
);
16134 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16136 /* If we have reached alignment, we can copy the rest of the
16138 if (IT_CHARPOS (it
) == CHARPOS (start
)
16139 /* Don't accept "alignment" inside a display vector,
16140 since start_row could have started in the middle of
16141 that same display vector (thus their character
16142 positions match), and we have no way of telling if
16143 that is the case. */
16144 && it
.current
.dpvec_index
< 0)
16147 if (display_line (&it
))
16148 last_text_row
= it
.glyph_row
- 1;
16152 /* A value of current_y < last_visible_y means that we stopped
16153 at the previous window start, which in turn means that we
16154 have at least one reusable row. */
16155 if (it
.current_y
< it
.last_visible_y
)
16157 struct glyph_row
*row
;
16159 /* IT.vpos always starts from 0; it counts text lines. */
16160 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16162 /* Find PT if not already found in the lines displayed. */
16163 if (w
->cursor
.vpos
< 0)
16165 int dy
= it
.current_y
- start_row
->y
;
16167 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16168 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16170 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16171 dy
, nrows_scrolled
);
16174 clear_glyph_matrix (w
->desired_matrix
);
16179 /* Scroll the display. Do it before the current matrix is
16180 changed. The problem here is that update has not yet
16181 run, i.e. part of the current matrix is not up to date.
16182 scroll_run_hook will clear the cursor, and use the
16183 current matrix to get the height of the row the cursor is
16185 run
.current_y
= start_row
->y
;
16186 run
.desired_y
= it
.current_y
;
16187 run
.height
= it
.last_visible_y
- it
.current_y
;
16189 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16192 FRAME_RIF (f
)->update_window_begin_hook (w
);
16193 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16194 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16195 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16199 /* Shift current matrix down by nrows_scrolled lines. */
16200 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16201 rotate_matrix (w
->current_matrix
,
16203 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16206 /* Disable lines that must be updated. */
16207 for (i
= 0; i
< nrows_scrolled
; ++i
)
16208 (start_row
+ i
)->enabled_p
= 0;
16210 /* Re-compute Y positions. */
16211 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16212 max_y
= it
.last_visible_y
;
16213 for (row
= start_row
+ nrows_scrolled
;
16217 row
->y
= it
.current_y
;
16218 row
->visible_height
= row
->height
;
16220 if (row
->y
< min_y
)
16221 row
->visible_height
-= min_y
- row
->y
;
16222 if (row
->y
+ row
->height
> max_y
)
16223 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16224 if (row
->fringe_bitmap_periodic_p
)
16225 row
->redraw_fringe_bitmaps_p
= 1;
16227 it
.current_y
+= row
->height
;
16229 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16230 last_reused_text_row
= row
;
16231 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16235 /* Disable lines in the current matrix which are now
16236 below the window. */
16237 for (++row
; row
< bottom_row
; ++row
)
16238 row
->enabled_p
= row
->mode_line_p
= 0;
16241 /* Update window_end_pos etc.; last_reused_text_row is the last
16242 reused row from the current matrix containing text, if any.
16243 The value of last_text_row is the last displayed line
16244 containing text. */
16245 if (last_reused_text_row
)
16247 w
->window_end_bytepos
16248 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16250 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16252 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16253 w
->current_matrix
));
16255 else if (last_text_row
)
16257 w
->window_end_bytepos
16258 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16260 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16262 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16266 /* This window must be completely empty. */
16267 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16268 w
->window_end_pos
= make_number (Z
- ZV
);
16269 w
->window_end_vpos
= make_number (0);
16271 w
->window_end_valid
= Qnil
;
16273 /* Update hint: don't try scrolling again in update_window. */
16274 w
->desired_matrix
->no_scrolling_p
= 1;
16277 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16281 else if (CHARPOS (new_start
) > CHARPOS (start
))
16283 struct glyph_row
*pt_row
, *row
;
16284 struct glyph_row
*first_reusable_row
;
16285 struct glyph_row
*first_row_to_display
;
16287 int yb
= window_text_bottom_y (w
);
16289 /* Find the row starting at new_start, if there is one. Don't
16290 reuse a partially visible line at the end. */
16291 first_reusable_row
= start_row
;
16292 while (first_reusable_row
->enabled_p
16293 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16294 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16295 < CHARPOS (new_start
)))
16296 ++first_reusable_row
;
16298 /* Give up if there is no row to reuse. */
16299 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16300 || !first_reusable_row
->enabled_p
16301 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16302 != CHARPOS (new_start
)))
16305 /* We can reuse fully visible rows beginning with
16306 first_reusable_row to the end of the window. Set
16307 first_row_to_display to the first row that cannot be reused.
16308 Set pt_row to the row containing point, if there is any. */
16310 for (first_row_to_display
= first_reusable_row
;
16311 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16312 ++first_row_to_display
)
16314 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16315 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
16316 pt_row
= first_row_to_display
;
16319 /* Start displaying at the start of first_row_to_display. */
16320 xassert (first_row_to_display
->y
< yb
);
16321 init_to_row_start (&it
, w
, first_row_to_display
);
16323 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16325 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16327 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16328 + WINDOW_HEADER_LINE_HEIGHT (w
));
16330 /* Display lines beginning with first_row_to_display in the
16331 desired matrix. Set last_text_row to the last row displayed
16332 that displays text. */
16333 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16334 if (pt_row
== NULL
)
16335 w
->cursor
.vpos
= -1;
16336 last_text_row
= NULL
;
16337 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16338 if (display_line (&it
))
16339 last_text_row
= it
.glyph_row
- 1;
16341 /* If point is in a reused row, adjust y and vpos of the cursor
16345 w
->cursor
.vpos
-= nrows_scrolled
;
16346 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16349 /* Give up if point isn't in a row displayed or reused. (This
16350 also handles the case where w->cursor.vpos < nrows_scrolled
16351 after the calls to display_line, which can happen with scroll
16352 margins. See bug#1295.) */
16353 if (w
->cursor
.vpos
< 0)
16355 clear_glyph_matrix (w
->desired_matrix
);
16359 /* Scroll the display. */
16360 run
.current_y
= first_reusable_row
->y
;
16361 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16362 run
.height
= it
.last_visible_y
- run
.current_y
;
16363 dy
= run
.current_y
- run
.desired_y
;
16368 FRAME_RIF (f
)->update_window_begin_hook (w
);
16369 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16370 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16371 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16375 /* Adjust Y positions of reused rows. */
16376 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16377 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16378 max_y
= it
.last_visible_y
;
16379 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16382 row
->visible_height
= row
->height
;
16383 if (row
->y
< min_y
)
16384 row
->visible_height
-= min_y
- row
->y
;
16385 if (row
->y
+ row
->height
> max_y
)
16386 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16387 if (row
->fringe_bitmap_periodic_p
)
16388 row
->redraw_fringe_bitmaps_p
= 1;
16391 /* Scroll the current matrix. */
16392 xassert (nrows_scrolled
> 0);
16393 rotate_matrix (w
->current_matrix
,
16395 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16398 /* Disable rows not reused. */
16399 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16400 row
->enabled_p
= 0;
16402 /* Point may have moved to a different line, so we cannot assume that
16403 the previous cursor position is valid; locate the correct row. */
16406 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16407 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
16411 w
->cursor
.y
= row
->y
;
16413 if (row
< bottom_row
)
16415 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16416 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16418 /* Can't use this optimization with bidi-reordered glyph
16419 rows, unless cursor is already at point. */
16420 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16422 if (!(w
->cursor
.hpos
>= 0
16423 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16424 && BUFFERP (glyph
->object
)
16425 && glyph
->charpos
== PT
))
16430 && (!BUFFERP (glyph
->object
)
16431 || glyph
->charpos
< PT
);
16435 w
->cursor
.x
+= glyph
->pixel_width
;
16440 /* Adjust window end. A null value of last_text_row means that
16441 the window end is in reused rows which in turn means that
16442 only its vpos can have changed. */
16445 w
->window_end_bytepos
16446 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16448 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16450 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16455 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16458 w
->window_end_valid
= Qnil
;
16459 w
->desired_matrix
->no_scrolling_p
= 1;
16462 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16472 /************************************************************************
16473 Window redisplay reusing current matrix when buffer has changed
16474 ************************************************************************/
16476 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16477 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16478 ptrdiff_t *, ptrdiff_t *);
16479 static struct glyph_row
*
16480 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16481 struct glyph_row
*);
16484 /* Return the last row in MATRIX displaying text. If row START is
16485 non-null, start searching with that row. IT gives the dimensions
16486 of the display. Value is null if matrix is empty; otherwise it is
16487 a pointer to the row found. */
16489 static struct glyph_row
*
16490 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16491 struct glyph_row
*start
)
16493 struct glyph_row
*row
, *row_found
;
16495 /* Set row_found to the last row in IT->w's current matrix
16496 displaying text. The loop looks funny but think of partially
16499 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16500 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16502 xassert (row
->enabled_p
);
16504 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16513 /* Return the last row in the current matrix of W that is not affected
16514 by changes at the start of current_buffer that occurred since W's
16515 current matrix was built. Value is null if no such row exists.
16517 BEG_UNCHANGED us the number of characters unchanged at the start of
16518 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16519 first changed character in current_buffer. Characters at positions <
16520 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16521 when the current matrix was built. */
16523 static struct glyph_row
*
16524 find_last_unchanged_at_beg_row (struct window
*w
)
16526 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16527 struct glyph_row
*row
;
16528 struct glyph_row
*row_found
= NULL
;
16529 int yb
= window_text_bottom_y (w
);
16531 /* Find the last row displaying unchanged text. */
16532 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16533 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16534 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16537 if (/* If row ends before first_changed_pos, it is unchanged,
16538 except in some case. */
16539 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16540 /* When row ends in ZV and we write at ZV it is not
16542 && !row
->ends_at_zv_p
16543 /* When first_changed_pos is the end of a continued line,
16544 row is not unchanged because it may be no longer
16546 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16547 && (row
->continued_p
16548 || row
->exact_window_width_line_p
)))
16551 /* Stop if last visible row. */
16552 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16560 /* Find the first glyph row in the current matrix of W that is not
16561 affected by changes at the end of current_buffer since the
16562 time W's current matrix was built.
16564 Return in *DELTA the number of chars by which buffer positions in
16565 unchanged text at the end of current_buffer must be adjusted.
16567 Return in *DELTA_BYTES the corresponding number of bytes.
16569 Value is null if no such row exists, i.e. all rows are affected by
16572 static struct glyph_row
*
16573 find_first_unchanged_at_end_row (struct window
*w
,
16574 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16576 struct glyph_row
*row
;
16577 struct glyph_row
*row_found
= NULL
;
16579 *delta
= *delta_bytes
= 0;
16581 /* Display must not have been paused, otherwise the current matrix
16582 is not up to date. */
16583 eassert (!NILP (w
->window_end_valid
));
16585 /* A value of window_end_pos >= END_UNCHANGED means that the window
16586 end is in the range of changed text. If so, there is no
16587 unchanged row at the end of W's current matrix. */
16588 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16591 /* Set row to the last row in W's current matrix displaying text. */
16592 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16594 /* If matrix is entirely empty, no unchanged row exists. */
16595 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16597 /* The value of row is the last glyph row in the matrix having a
16598 meaningful buffer position in it. The end position of row
16599 corresponds to window_end_pos. This allows us to translate
16600 buffer positions in the current matrix to current buffer
16601 positions for characters not in changed text. */
16603 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16604 ptrdiff_t Z_BYTE_old
=
16605 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16606 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16607 struct glyph_row
*first_text_row
16608 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16610 *delta
= Z
- Z_old
;
16611 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16613 /* Set last_unchanged_pos to the buffer position of the last
16614 character in the buffer that has not been changed. Z is the
16615 index + 1 of the last character in current_buffer, i.e. by
16616 subtracting END_UNCHANGED we get the index of the last
16617 unchanged character, and we have to add BEG to get its buffer
16619 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16620 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16622 /* Search backward from ROW for a row displaying a line that
16623 starts at a minimum position >= last_unchanged_pos_old. */
16624 for (; row
> first_text_row
; --row
)
16626 /* This used to abort, but it can happen.
16627 It is ok to just stop the search instead here. KFS. */
16628 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16631 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16636 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16642 /* Make sure that glyph rows in the current matrix of window W
16643 reference the same glyph memory as corresponding rows in the
16644 frame's frame matrix. This function is called after scrolling W's
16645 current matrix on a terminal frame in try_window_id and
16646 try_window_reusing_current_matrix. */
16649 sync_frame_with_window_matrix_rows (struct window
*w
)
16651 struct frame
*f
= XFRAME (w
->frame
);
16652 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16654 /* Preconditions: W must be a leaf window and full-width. Its frame
16655 must have a frame matrix. */
16656 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16657 xassert (WINDOW_FULL_WIDTH_P (w
));
16658 xassert (!FRAME_WINDOW_P (f
));
16660 /* If W is a full-width window, glyph pointers in W's current matrix
16661 have, by definition, to be the same as glyph pointers in the
16662 corresponding frame matrix. Note that frame matrices have no
16663 marginal areas (see build_frame_matrix). */
16664 window_row
= w
->current_matrix
->rows
;
16665 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16666 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16667 while (window_row
< window_row_end
)
16669 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16670 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16672 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16673 frame_row
->glyphs
[TEXT_AREA
] = start
;
16674 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16675 frame_row
->glyphs
[LAST_AREA
] = end
;
16677 /* Disable frame rows whose corresponding window rows have
16678 been disabled in try_window_id. */
16679 if (!window_row
->enabled_p
)
16680 frame_row
->enabled_p
= 0;
16682 ++window_row
, ++frame_row
;
16687 /* Find the glyph row in window W containing CHARPOS. Consider all
16688 rows between START and END (not inclusive). END null means search
16689 all rows to the end of the display area of W. Value is the row
16690 containing CHARPOS or null. */
16693 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16694 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16696 struct glyph_row
*row
= start
;
16697 struct glyph_row
*best_row
= NULL
;
16698 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16701 /* If we happen to start on a header-line, skip that. */
16702 if (row
->mode_line_p
)
16705 if ((end
&& row
>= end
) || !row
->enabled_p
)
16708 last_y
= window_text_bottom_y (w
) - dy
;
16712 /* Give up if we have gone too far. */
16713 if (end
&& row
>= end
)
16715 /* This formerly returned if they were equal.
16716 I think that both quantities are of a "last plus one" type;
16717 if so, when they are equal, the row is within the screen. -- rms. */
16718 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16721 /* If it is in this row, return this row. */
16722 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16723 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16724 /* The end position of a row equals the start
16725 position of the next row. If CHARPOS is there, we
16726 would rather display it in the next line, except
16727 when this line ends in ZV. */
16728 && !row
->ends_at_zv_p
16729 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16730 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16734 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16735 || (!best_row
&& !row
->continued_p
))
16737 /* In bidi-reordered rows, there could be several rows
16738 occluding point, all of them belonging to the same
16739 continued line. We need to find the row which fits
16740 CHARPOS the best. */
16741 for (g
= row
->glyphs
[TEXT_AREA
];
16742 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16745 if (!STRINGP (g
->object
))
16747 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16749 mindif
= eabs (g
->charpos
- charpos
);
16751 /* Exact match always wins. */
16758 else if (best_row
&& !row
->continued_p
)
16765 /* Try to redisplay window W by reusing its existing display. W's
16766 current matrix must be up to date when this function is called,
16767 i.e. window_end_valid must not be nil.
16771 1 if display has been updated
16772 0 if otherwise unsuccessful
16773 -1 if redisplay with same window start is known not to succeed
16775 The following steps are performed:
16777 1. Find the last row in the current matrix of W that is not
16778 affected by changes at the start of current_buffer. If no such row
16781 2. Find the first row in W's current matrix that is not affected by
16782 changes at the end of current_buffer. Maybe there is no such row.
16784 3. Display lines beginning with the row + 1 found in step 1 to the
16785 row found in step 2 or, if step 2 didn't find a row, to the end of
16788 4. If cursor is not known to appear on the window, give up.
16790 5. If display stopped at the row found in step 2, scroll the
16791 display and current matrix as needed.
16793 6. Maybe display some lines at the end of W, if we must. This can
16794 happen under various circumstances, like a partially visible line
16795 becoming fully visible, or because newly displayed lines are displayed
16796 in smaller font sizes.
16798 7. Update W's window end information. */
16801 try_window_id (struct window
*w
)
16803 struct frame
*f
= XFRAME (w
->frame
);
16804 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16805 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16806 struct glyph_row
*last_unchanged_at_beg_row
;
16807 struct glyph_row
*first_unchanged_at_end_row
;
16808 struct glyph_row
*row
;
16809 struct glyph_row
*bottom_row
;
16812 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
16814 struct text_pos start_pos
;
16816 int first_unchanged_at_end_vpos
= 0;
16817 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16818 struct text_pos start
;
16819 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
16822 if (inhibit_try_window_id
)
16826 /* This is handy for debugging. */
16828 #define GIVE_UP(X) \
16830 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16834 #define GIVE_UP(X) return 0
16837 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16839 /* Don't use this for mini-windows because these can show
16840 messages and mini-buffers, and we don't handle that here. */
16841 if (MINI_WINDOW_P (w
))
16844 /* This flag is used to prevent redisplay optimizations. */
16845 if (windows_or_buffers_changed
|| cursor_type_changed
)
16848 /* Verify that narrowing has not changed.
16849 Also verify that we were not told to prevent redisplay optimizations.
16850 It would be nice to further
16851 reduce the number of cases where this prevents try_window_id. */
16852 if (current_buffer
->clip_changed
16853 || current_buffer
->prevent_redisplay_optimizations_p
)
16856 /* Window must either use window-based redisplay or be full width. */
16857 if (!FRAME_WINDOW_P (f
)
16858 && (!FRAME_LINE_INS_DEL_OK (f
)
16859 || !WINDOW_FULL_WIDTH_P (w
)))
16862 /* Give up if point is known NOT to appear in W. */
16863 if (PT
< CHARPOS (start
))
16866 /* Another way to prevent redisplay optimizations. */
16867 if (XFASTINT (w
->last_modified
) == 0)
16870 /* Verify that window is not hscrolled. */
16871 if (XFASTINT (w
->hscroll
) != 0)
16874 /* Verify that display wasn't paused. */
16875 if (NILP (w
->window_end_valid
))
16878 /* Can't use this if highlighting a region because a cursor movement
16879 will do more than just set the cursor. */
16880 if (!NILP (Vtransient_mark_mode
)
16881 && !NILP (BVAR (current_buffer
, mark_active
)))
16884 /* Likewise if highlighting trailing whitespace. */
16885 if (!NILP (Vshow_trailing_whitespace
))
16888 /* Likewise if showing a region. */
16889 if (!NILP (w
->region_showing
))
16892 /* Can't use this if overlay arrow position and/or string have
16894 if (overlay_arrows_changed_p ())
16897 /* When word-wrap is on, adding a space to the first word of a
16898 wrapped line can change the wrap position, altering the line
16899 above it. It might be worthwhile to handle this more
16900 intelligently, but for now just redisplay from scratch. */
16901 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16904 /* Under bidi reordering, adding or deleting a character in the
16905 beginning of a paragraph, before the first strong directional
16906 character, can change the base direction of the paragraph (unless
16907 the buffer specifies a fixed paragraph direction), which will
16908 require to redisplay the whole paragraph. It might be worthwhile
16909 to find the paragraph limits and widen the range of redisplayed
16910 lines to that, but for now just give up this optimization and
16911 redisplay from scratch. */
16912 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16913 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16916 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16917 only if buffer has really changed. The reason is that the gap is
16918 initially at Z for freshly visited files. The code below would
16919 set end_unchanged to 0 in that case. */
16920 if (MODIFF
> SAVE_MODIFF
16921 /* This seems to happen sometimes after saving a buffer. */
16922 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16924 if (GPT
- BEG
< BEG_UNCHANGED
)
16925 BEG_UNCHANGED
= GPT
- BEG
;
16926 if (Z
- GPT
< END_UNCHANGED
)
16927 END_UNCHANGED
= Z
- GPT
;
16930 /* The position of the first and last character that has been changed. */
16931 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16932 last_changed_charpos
= Z
- END_UNCHANGED
;
16934 /* If window starts after a line end, and the last change is in
16935 front of that newline, then changes don't affect the display.
16936 This case happens with stealth-fontification. Note that although
16937 the display is unchanged, glyph positions in the matrix have to
16938 be adjusted, of course. */
16939 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16940 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16941 && ((last_changed_charpos
< CHARPOS (start
)
16942 && CHARPOS (start
) == BEGV
)
16943 || (last_changed_charpos
< CHARPOS (start
) - 1
16944 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16946 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16947 struct glyph_row
*r0
;
16949 /* Compute how many chars/bytes have been added to or removed
16950 from the buffer. */
16951 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16952 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16953 Z_delta
= Z
- Z_old
;
16954 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16956 /* Give up if PT is not in the window. Note that it already has
16957 been checked at the start of try_window_id that PT is not in
16958 front of the window start. */
16959 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16962 /* If window start is unchanged, we can reuse the whole matrix
16963 as is, after adjusting glyph positions. No need to compute
16964 the window end again, since its offset from Z hasn't changed. */
16965 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16966 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16967 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16968 /* PT must not be in a partially visible line. */
16969 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16970 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16972 /* Adjust positions in the glyph matrix. */
16973 if (Z_delta
|| Z_delta_bytes
)
16975 struct glyph_row
*r1
16976 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16977 increment_matrix_positions (w
->current_matrix
,
16978 MATRIX_ROW_VPOS (r0
, current_matrix
),
16979 MATRIX_ROW_VPOS (r1
, current_matrix
),
16980 Z_delta
, Z_delta_bytes
);
16983 /* Set the cursor. */
16984 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16986 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16993 /* Handle the case that changes are all below what is displayed in
16994 the window, and that PT is in the window. This shortcut cannot
16995 be taken if ZV is visible in the window, and text has been added
16996 there that is visible in the window. */
16997 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16998 /* ZV is not visible in the window, or there are no
16999 changes at ZV, actually. */
17000 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17001 || first_changed_charpos
== last_changed_charpos
))
17003 struct glyph_row
*r0
;
17005 /* Give up if PT is not in the window. Note that it already has
17006 been checked at the start of try_window_id that PT is not in
17007 front of the window start. */
17008 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17011 /* If window start is unchanged, we can reuse the whole matrix
17012 as is, without changing glyph positions since no text has
17013 been added/removed in front of the window end. */
17014 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17015 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17016 /* PT must not be in a partially visible line. */
17017 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17018 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17020 /* We have to compute the window end anew since text
17021 could have been added/removed after it. */
17023 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17024 w
->window_end_bytepos
17025 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17027 /* Set the cursor. */
17028 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17030 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17037 /* Give up if window start is in the changed area.
17039 The condition used to read
17041 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17043 but why that was tested escapes me at the moment. */
17044 if (CHARPOS (start
) >= first_changed_charpos
17045 && CHARPOS (start
) <= last_changed_charpos
)
17048 /* Check that window start agrees with the start of the first glyph
17049 row in its current matrix. Check this after we know the window
17050 start is not in changed text, otherwise positions would not be
17052 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17053 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17056 /* Give up if the window ends in strings. Overlay strings
17057 at the end are difficult to handle, so don't try. */
17058 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17059 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17062 /* Compute the position at which we have to start displaying new
17063 lines. Some of the lines at the top of the window might be
17064 reusable because they are not displaying changed text. Find the
17065 last row in W's current matrix not affected by changes at the
17066 start of current_buffer. Value is null if changes start in the
17067 first line of window. */
17068 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17069 if (last_unchanged_at_beg_row
)
17071 /* Avoid starting to display in the middle of a character, a TAB
17072 for instance. This is easier than to set up the iterator
17073 exactly, and it's not a frequent case, so the additional
17074 effort wouldn't really pay off. */
17075 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17076 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17077 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17078 --last_unchanged_at_beg_row
;
17080 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17083 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17085 start_pos
= it
.current
.pos
;
17087 /* Start displaying new lines in the desired matrix at the same
17088 vpos we would use in the current matrix, i.e. below
17089 last_unchanged_at_beg_row. */
17090 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17092 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17093 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17095 xassert (it
.hpos
== 0 && it
.current_x
== 0);
17099 /* There are no reusable lines at the start of the window.
17100 Start displaying in the first text line. */
17101 start_display (&it
, w
, start
);
17102 it
.vpos
= it
.first_vpos
;
17103 start_pos
= it
.current
.pos
;
17106 /* Find the first row that is not affected by changes at the end of
17107 the buffer. Value will be null if there is no unchanged row, in
17108 which case we must redisplay to the end of the window. delta
17109 will be set to the value by which buffer positions beginning with
17110 first_unchanged_at_end_row have to be adjusted due to text
17112 first_unchanged_at_end_row
17113 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17114 IF_DEBUG (debug_delta
= delta
);
17115 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17117 /* Set stop_pos to the buffer position up to which we will have to
17118 display new lines. If first_unchanged_at_end_row != NULL, this
17119 is the buffer position of the start of the line displayed in that
17120 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17121 that we don't stop at a buffer position. */
17123 if (first_unchanged_at_end_row
)
17125 xassert (last_unchanged_at_beg_row
== NULL
17126 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17128 /* If this is a continuation line, move forward to the next one
17129 that isn't. Changes in lines above affect this line.
17130 Caution: this may move first_unchanged_at_end_row to a row
17131 not displaying text. */
17132 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17133 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17134 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17135 < it
.last_visible_y
))
17136 ++first_unchanged_at_end_row
;
17138 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17139 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17140 >= it
.last_visible_y
))
17141 first_unchanged_at_end_row
= NULL
;
17144 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17146 first_unchanged_at_end_vpos
17147 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17148 xassert (stop_pos
>= Z
- END_UNCHANGED
);
17151 else if (last_unchanged_at_beg_row
== NULL
)
17157 /* Either there is no unchanged row at the end, or the one we have
17158 now displays text. This is a necessary condition for the window
17159 end pos calculation at the end of this function. */
17160 xassert (first_unchanged_at_end_row
== NULL
17161 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17163 debug_last_unchanged_at_beg_vpos
17164 = (last_unchanged_at_beg_row
17165 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17167 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17169 #endif /* GLYPH_DEBUG != 0 */
17172 /* Display new lines. Set last_text_row to the last new line
17173 displayed which has text on it, i.e. might end up as being the
17174 line where the window_end_vpos is. */
17175 w
->cursor
.vpos
= -1;
17176 last_text_row
= NULL
;
17177 overlay_arrow_seen
= 0;
17178 while (it
.current_y
< it
.last_visible_y
17179 && !fonts_changed_p
17180 && (first_unchanged_at_end_row
== NULL
17181 || IT_CHARPOS (it
) < stop_pos
))
17183 if (display_line (&it
))
17184 last_text_row
= it
.glyph_row
- 1;
17187 if (fonts_changed_p
)
17191 /* Compute differences in buffer positions, y-positions etc. for
17192 lines reused at the bottom of the window. Compute what we can
17194 if (first_unchanged_at_end_row
17195 /* No lines reused because we displayed everything up to the
17196 bottom of the window. */
17197 && it
.current_y
< it
.last_visible_y
)
17200 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17202 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17203 run
.current_y
= first_unchanged_at_end_row
->y
;
17204 run
.desired_y
= run
.current_y
+ dy
;
17205 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17209 delta
= delta_bytes
= dvpos
= dy
17210 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17211 first_unchanged_at_end_row
= NULL
;
17213 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17216 /* Find the cursor if not already found. We have to decide whether
17217 PT will appear on this window (it sometimes doesn't, but this is
17218 not a very frequent case.) This decision has to be made before
17219 the current matrix is altered. A value of cursor.vpos < 0 means
17220 that PT is either in one of the lines beginning at
17221 first_unchanged_at_end_row or below the window. Don't care for
17222 lines that might be displayed later at the window end; as
17223 mentioned, this is not a frequent case. */
17224 if (w
->cursor
.vpos
< 0)
17226 /* Cursor in unchanged rows at the top? */
17227 if (PT
< CHARPOS (start_pos
)
17228 && last_unchanged_at_beg_row
)
17230 row
= row_containing_pos (w
, PT
,
17231 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17232 last_unchanged_at_beg_row
+ 1, 0);
17234 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17237 /* Start from first_unchanged_at_end_row looking for PT. */
17238 else if (first_unchanged_at_end_row
)
17240 row
= row_containing_pos (w
, PT
- delta
,
17241 first_unchanged_at_end_row
, NULL
, 0);
17243 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17244 delta_bytes
, dy
, dvpos
);
17247 /* Give up if cursor was not found. */
17248 if (w
->cursor
.vpos
< 0)
17250 clear_glyph_matrix (w
->desired_matrix
);
17255 /* Don't let the cursor end in the scroll margins. */
17257 int this_scroll_margin
, cursor_height
;
17259 this_scroll_margin
=
17260 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17261 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17262 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17264 if ((w
->cursor
.y
< this_scroll_margin
17265 && CHARPOS (start
) > BEGV
)
17266 /* Old redisplay didn't take scroll margin into account at the bottom,
17267 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17268 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17269 ? cursor_height
+ this_scroll_margin
17270 : 1)) > it
.last_visible_y
)
17272 w
->cursor
.vpos
= -1;
17273 clear_glyph_matrix (w
->desired_matrix
);
17278 /* Scroll the display. Do it before changing the current matrix so
17279 that xterm.c doesn't get confused about where the cursor glyph is
17281 if (dy
&& run
.height
)
17285 if (FRAME_WINDOW_P (f
))
17287 FRAME_RIF (f
)->update_window_begin_hook (w
);
17288 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17289 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17290 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17294 /* Terminal frame. In this case, dvpos gives the number of
17295 lines to scroll by; dvpos < 0 means scroll up. */
17297 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17298 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17299 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17300 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17301 + window_internal_height (w
));
17303 #if defined (HAVE_GPM) || defined (MSDOS)
17304 x_clear_window_mouse_face (w
);
17306 /* Perform the operation on the screen. */
17309 /* Scroll last_unchanged_at_beg_row to the end of the
17310 window down dvpos lines. */
17311 set_terminal_window (f
, end
);
17313 /* On dumb terminals delete dvpos lines at the end
17314 before inserting dvpos empty lines. */
17315 if (!FRAME_SCROLL_REGION_OK (f
))
17316 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17318 /* Insert dvpos empty lines in front of
17319 last_unchanged_at_beg_row. */
17320 ins_del_lines (f
, from
, dvpos
);
17322 else if (dvpos
< 0)
17324 /* Scroll up last_unchanged_at_beg_vpos to the end of
17325 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17326 set_terminal_window (f
, end
);
17328 /* Delete dvpos lines in front of
17329 last_unchanged_at_beg_vpos. ins_del_lines will set
17330 the cursor to the given vpos and emit |dvpos| delete
17332 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17334 /* On a dumb terminal insert dvpos empty lines at the
17336 if (!FRAME_SCROLL_REGION_OK (f
))
17337 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17340 set_terminal_window (f
, 0);
17346 /* Shift reused rows of the current matrix to the right position.
17347 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17349 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17350 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17353 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17354 bottom_vpos
, dvpos
);
17355 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17358 else if (dvpos
> 0)
17360 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17361 bottom_vpos
, dvpos
);
17362 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17363 first_unchanged_at_end_vpos
+ dvpos
, 0);
17366 /* For frame-based redisplay, make sure that current frame and window
17367 matrix are in sync with respect to glyph memory. */
17368 if (!FRAME_WINDOW_P (f
))
17369 sync_frame_with_window_matrix_rows (w
);
17371 /* Adjust buffer positions in reused rows. */
17372 if (delta
|| delta_bytes
)
17373 increment_matrix_positions (current_matrix
,
17374 first_unchanged_at_end_vpos
+ dvpos
,
17375 bottom_vpos
, delta
, delta_bytes
);
17377 /* Adjust Y positions. */
17379 shift_glyph_matrix (w
, current_matrix
,
17380 first_unchanged_at_end_vpos
+ dvpos
,
17383 if (first_unchanged_at_end_row
)
17385 first_unchanged_at_end_row
+= dvpos
;
17386 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17387 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17388 first_unchanged_at_end_row
= NULL
;
17391 /* If scrolling up, there may be some lines to display at the end of
17393 last_text_row_at_end
= NULL
;
17396 /* Scrolling up can leave for example a partially visible line
17397 at the end of the window to be redisplayed. */
17398 /* Set last_row to the glyph row in the current matrix where the
17399 window end line is found. It has been moved up or down in
17400 the matrix by dvpos. */
17401 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17402 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17404 /* If last_row is the window end line, it should display text. */
17405 xassert (last_row
->displays_text_p
);
17407 /* If window end line was partially visible before, begin
17408 displaying at that line. Otherwise begin displaying with the
17409 line following it. */
17410 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17412 init_to_row_start (&it
, w
, last_row
);
17413 it
.vpos
= last_vpos
;
17414 it
.current_y
= last_row
->y
;
17418 init_to_row_end (&it
, w
, last_row
);
17419 it
.vpos
= 1 + last_vpos
;
17420 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17424 /* We may start in a continuation line. If so, we have to
17425 get the right continuation_lines_width and current_x. */
17426 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17427 it
.hpos
= it
.current_x
= 0;
17429 /* Display the rest of the lines at the window end. */
17430 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17431 while (it
.current_y
< it
.last_visible_y
17432 && !fonts_changed_p
)
17434 /* Is it always sure that the display agrees with lines in
17435 the current matrix? I don't think so, so we mark rows
17436 displayed invalid in the current matrix by setting their
17437 enabled_p flag to zero. */
17438 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17439 if (display_line (&it
))
17440 last_text_row_at_end
= it
.glyph_row
- 1;
17444 /* Update window_end_pos and window_end_vpos. */
17445 if (first_unchanged_at_end_row
17446 && !last_text_row_at_end
)
17448 /* Window end line if one of the preserved rows from the current
17449 matrix. Set row to the last row displaying text in current
17450 matrix starting at first_unchanged_at_end_row, after
17452 xassert (first_unchanged_at_end_row
->displays_text_p
);
17453 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17454 first_unchanged_at_end_row
);
17455 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17457 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17458 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17460 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17461 xassert (w
->window_end_bytepos
>= 0);
17462 IF_DEBUG (debug_method_add (w
, "A"));
17464 else if (last_text_row_at_end
)
17467 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17468 w
->window_end_bytepos
17469 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17471 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17472 xassert (w
->window_end_bytepos
>= 0);
17473 IF_DEBUG (debug_method_add (w
, "B"));
17475 else if (last_text_row
)
17477 /* We have displayed either to the end of the window or at the
17478 end of the window, i.e. the last row with text is to be found
17479 in the desired matrix. */
17481 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17482 w
->window_end_bytepos
17483 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17485 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17486 xassert (w
->window_end_bytepos
>= 0);
17488 else if (first_unchanged_at_end_row
== NULL
17489 && last_text_row
== NULL
17490 && last_text_row_at_end
== NULL
)
17492 /* Displayed to end of window, but no line containing text was
17493 displayed. Lines were deleted at the end of the window. */
17494 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17495 int vpos
= XFASTINT (w
->window_end_vpos
);
17496 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17497 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17500 row
== NULL
&& vpos
>= first_vpos
;
17501 --vpos
, --current_row
, --desired_row
)
17503 if (desired_row
->enabled_p
)
17505 if (desired_row
->displays_text_p
)
17508 else if (current_row
->displays_text_p
)
17512 xassert (row
!= NULL
);
17513 w
->window_end_vpos
= make_number (vpos
+ 1);
17514 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17515 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17516 xassert (w
->window_end_bytepos
>= 0);
17517 IF_DEBUG (debug_method_add (w
, "C"));
17522 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17523 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17525 /* Record that display has not been completed. */
17526 w
->window_end_valid
= Qnil
;
17527 w
->desired_matrix
->no_scrolling_p
= 1;
17535 /***********************************************************************
17536 More debugging support
17537 ***********************************************************************/
17541 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17542 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17543 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17546 /* Dump the contents of glyph matrix MATRIX on stderr.
17548 GLYPHS 0 means don't show glyph contents.
17549 GLYPHS 1 means show glyphs in short form
17550 GLYPHS > 1 means show glyphs in long form. */
17553 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17556 for (i
= 0; i
< matrix
->nrows
; ++i
)
17557 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17561 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17562 the glyph row and area where the glyph comes from. */
17565 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17567 if (glyph
->type
== CHAR_GLYPH
)
17570 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17571 glyph
- row
->glyphs
[TEXT_AREA
],
17574 (BUFFERP (glyph
->object
)
17576 : (STRINGP (glyph
->object
)
17579 glyph
->pixel_width
,
17581 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17585 glyph
->left_box_line_p
,
17586 glyph
->right_box_line_p
);
17588 else if (glyph
->type
== STRETCH_GLYPH
)
17591 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17592 glyph
- row
->glyphs
[TEXT_AREA
],
17595 (BUFFERP (glyph
->object
)
17597 : (STRINGP (glyph
->object
)
17600 glyph
->pixel_width
,
17604 glyph
->left_box_line_p
,
17605 glyph
->right_box_line_p
);
17607 else if (glyph
->type
== IMAGE_GLYPH
)
17610 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17611 glyph
- row
->glyphs
[TEXT_AREA
],
17614 (BUFFERP (glyph
->object
)
17616 : (STRINGP (glyph
->object
)
17619 glyph
->pixel_width
,
17623 glyph
->left_box_line_p
,
17624 glyph
->right_box_line_p
);
17626 else if (glyph
->type
== COMPOSITE_GLYPH
)
17629 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17630 glyph
- row
->glyphs
[TEXT_AREA
],
17633 (BUFFERP (glyph
->object
)
17635 : (STRINGP (glyph
->object
)
17638 glyph
->pixel_width
,
17640 if (glyph
->u
.cmp
.automatic
)
17643 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17644 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17646 glyph
->left_box_line_p
,
17647 glyph
->right_box_line_p
);
17652 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17653 GLYPHS 0 means don't show glyph contents.
17654 GLYPHS 1 means show glyphs in short form
17655 GLYPHS > 1 means show glyphs in long form. */
17658 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17662 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17663 fprintf (stderr
, "======================================================================\n");
17665 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17666 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17668 MATRIX_ROW_START_CHARPOS (row
),
17669 MATRIX_ROW_END_CHARPOS (row
),
17670 row
->used
[TEXT_AREA
],
17671 row
->contains_overlapping_glyphs_p
,
17673 row
->truncated_on_left_p
,
17674 row
->truncated_on_right_p
,
17676 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17677 row
->displays_text_p
,
17680 row
->ends_in_middle_of_char_p
,
17681 row
->starts_in_middle_of_char_p
,
17687 row
->visible_height
,
17690 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17691 row
->end
.overlay_string_index
,
17692 row
->continuation_lines_width
);
17693 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17694 CHARPOS (row
->start
.string_pos
),
17695 CHARPOS (row
->end
.string_pos
));
17696 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17697 row
->end
.dpvec_index
);
17704 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17706 struct glyph
*glyph
= row
->glyphs
[area
];
17707 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17709 /* Glyph for a line end in text. */
17710 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17713 if (glyph
< glyph_end
)
17714 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
17716 for (; glyph
< glyph_end
; ++glyph
)
17717 dump_glyph (row
, glyph
, area
);
17720 else if (glyphs
== 1)
17724 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17726 char *s
= (char *) alloca (row
->used
[area
] + 1);
17729 for (i
= 0; i
< row
->used
[area
]; ++i
)
17731 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17732 if (glyph
->type
== CHAR_GLYPH
17733 && glyph
->u
.ch
< 0x80
17734 && glyph
->u
.ch
>= ' ')
17735 s
[i
] = glyph
->u
.ch
;
17741 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17747 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17748 Sdump_glyph_matrix
, 0, 1, "p",
17749 doc
: /* Dump the current matrix of the selected window to stderr.
17750 Shows contents of glyph row structures. With non-nil
17751 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17752 glyphs in short form, otherwise show glyphs in long form. */)
17753 (Lisp_Object glyphs
)
17755 struct window
*w
= XWINDOW (selected_window
);
17756 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17758 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17759 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17760 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17761 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17762 fprintf (stderr
, "=============================================\n");
17763 dump_glyph_matrix (w
->current_matrix
,
17764 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17769 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17770 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17773 struct frame
*f
= XFRAME (selected_frame
);
17774 dump_glyph_matrix (f
->current_matrix
, 1);
17779 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17780 doc
: /* Dump glyph row ROW to stderr.
17781 GLYPH 0 means don't dump glyphs.
17782 GLYPH 1 means dump glyphs in short form.
17783 GLYPH > 1 or omitted means dump glyphs in long form. */)
17784 (Lisp_Object row
, Lisp_Object glyphs
)
17786 struct glyph_matrix
*matrix
;
17789 CHECK_NUMBER (row
);
17790 matrix
= XWINDOW (selected_window
)->current_matrix
;
17792 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17793 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17795 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17800 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17801 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17802 GLYPH 0 means don't dump glyphs.
17803 GLYPH 1 means dump glyphs in short form.
17804 GLYPH > 1 or omitted means dump glyphs in long form. */)
17805 (Lisp_Object row
, Lisp_Object glyphs
)
17807 struct frame
*sf
= SELECTED_FRAME ();
17808 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17811 CHECK_NUMBER (row
);
17813 if (vpos
>= 0 && vpos
< m
->nrows
)
17814 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17815 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17820 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17821 doc
: /* Toggle tracing of redisplay.
17822 With ARG, turn tracing on if and only if ARG is positive. */)
17826 trace_redisplay_p
= !trace_redisplay_p
;
17829 arg
= Fprefix_numeric_value (arg
);
17830 trace_redisplay_p
= XINT (arg
) > 0;
17837 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17838 doc
: /* Like `format', but print result to stderr.
17839 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17840 (ptrdiff_t nargs
, Lisp_Object
*args
)
17842 Lisp_Object s
= Fformat (nargs
, args
);
17843 fprintf (stderr
, "%s", SDATA (s
));
17847 #endif /* GLYPH_DEBUG */
17851 /***********************************************************************
17852 Building Desired Matrix Rows
17853 ***********************************************************************/
17855 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17856 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17858 static struct glyph_row
*
17859 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17861 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17862 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17863 struct buffer
*old
= current_buffer
;
17864 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17865 int arrow_len
= SCHARS (overlay_arrow_string
);
17866 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17867 const unsigned char *p
;
17870 int n_glyphs_before
;
17872 set_buffer_temp (buffer
);
17873 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17874 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17875 SET_TEXT_POS (it
.position
, 0, 0);
17877 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17879 while (p
< arrow_end
)
17881 Lisp_Object face
, ilisp
;
17883 /* Get the next character. */
17885 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17888 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17889 if (! ASCII_CHAR_P (it
.c
))
17890 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17894 /* Get its face. */
17895 ilisp
= make_number (p
- arrow_string
);
17896 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17897 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17899 /* Compute its width, get its glyphs. */
17900 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17901 SET_TEXT_POS (it
.position
, -1, -1);
17902 PRODUCE_GLYPHS (&it
);
17904 /* If this character doesn't fit any more in the line, we have
17905 to remove some glyphs. */
17906 if (it
.current_x
> it
.last_visible_x
)
17908 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17913 set_buffer_temp (old
);
17914 return it
.glyph_row
;
17918 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17919 glyphs are only inserted for terminal frames since we can't really
17920 win with truncation glyphs when partially visible glyphs are
17921 involved. Which glyphs to insert is determined by
17922 produce_special_glyphs. */
17925 insert_left_trunc_glyphs (struct it
*it
)
17927 struct it truncate_it
;
17928 struct glyph
*from
, *end
, *to
, *toend
;
17930 xassert (!FRAME_WINDOW_P (it
->f
));
17932 /* Get the truncation glyphs. */
17934 truncate_it
.current_x
= 0;
17935 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17936 truncate_it
.glyph_row
= &scratch_glyph_row
;
17937 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17938 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17939 truncate_it
.object
= make_number (0);
17940 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17942 /* Overwrite glyphs from IT with truncation glyphs. */
17943 if (!it
->glyph_row
->reversed_p
)
17945 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17946 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17947 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17948 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17953 /* There may be padding glyphs left over. Overwrite them too. */
17954 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17956 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17962 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17966 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17967 that back to front. */
17968 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17969 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17970 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17971 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17973 while (from
>= end
&& to
>= toend
)
17975 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17978 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17979 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17980 while (from
>= end
&& to
>= toend
)
17985 /* Need to free some room before prepending additional
17987 int move_by
= from
- end
+ 1;
17988 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17989 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17991 for ( ; g
>= g0
; g
--)
17993 while (from
>= end
)
17995 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18000 /* Compute the hash code for ROW. */
18002 row_hash (struct glyph_row
*row
)
18005 unsigned hashval
= 0;
18007 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18008 for (k
= 0; k
< row
->used
[area
]; ++k
)
18009 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18010 + row
->glyphs
[area
][k
].u
.val
18011 + row
->glyphs
[area
][k
].face_id
18012 + row
->glyphs
[area
][k
].padding_p
18013 + (row
->glyphs
[area
][k
].type
<< 2));
18018 /* Compute the pixel height and width of IT->glyph_row.
18020 Most of the time, ascent and height of a display line will be equal
18021 to the max_ascent and max_height values of the display iterator
18022 structure. This is not the case if
18024 1. We hit ZV without displaying anything. In this case, max_ascent
18025 and max_height will be zero.
18027 2. We have some glyphs that don't contribute to the line height.
18028 (The glyph row flag contributes_to_line_height_p is for future
18029 pixmap extensions).
18031 The first case is easily covered by using default values because in
18032 these cases, the line height does not really matter, except that it
18033 must not be zero. */
18036 compute_line_metrics (struct it
*it
)
18038 struct glyph_row
*row
= it
->glyph_row
;
18040 if (FRAME_WINDOW_P (it
->f
))
18042 int i
, min_y
, max_y
;
18044 /* The line may consist of one space only, that was added to
18045 place the cursor on it. If so, the row's height hasn't been
18047 if (row
->height
== 0)
18049 if (it
->max_ascent
+ it
->max_descent
== 0)
18050 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18051 row
->ascent
= it
->max_ascent
;
18052 row
->height
= it
->max_ascent
+ it
->max_descent
;
18053 row
->phys_ascent
= it
->max_phys_ascent
;
18054 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18055 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18058 /* Compute the width of this line. */
18059 row
->pixel_width
= row
->x
;
18060 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18061 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18063 xassert (row
->pixel_width
>= 0);
18064 xassert (row
->ascent
>= 0 && row
->height
> 0);
18066 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18067 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18069 /* If first line's physical ascent is larger than its logical
18070 ascent, use the physical ascent, and make the row taller.
18071 This makes accented characters fully visible. */
18072 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18073 && row
->phys_ascent
> row
->ascent
)
18075 row
->height
+= row
->phys_ascent
- row
->ascent
;
18076 row
->ascent
= row
->phys_ascent
;
18079 /* Compute how much of the line is visible. */
18080 row
->visible_height
= row
->height
;
18082 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18083 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18085 if (row
->y
< min_y
)
18086 row
->visible_height
-= min_y
- row
->y
;
18087 if (row
->y
+ row
->height
> max_y
)
18088 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18092 row
->pixel_width
= row
->used
[TEXT_AREA
];
18093 if (row
->continued_p
)
18094 row
->pixel_width
-= it
->continuation_pixel_width
;
18095 else if (row
->truncated_on_right_p
)
18096 row
->pixel_width
-= it
->truncation_pixel_width
;
18097 row
->ascent
= row
->phys_ascent
= 0;
18098 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18099 row
->extra_line_spacing
= 0;
18102 /* Compute a hash code for this row. */
18103 row
->hash
= row_hash (row
);
18105 it
->max_ascent
= it
->max_descent
= 0;
18106 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18110 /* Append one space to the glyph row of iterator IT if doing a
18111 window-based redisplay. The space has the same face as
18112 IT->face_id. Value is non-zero if a space was added.
18114 This function is called to make sure that there is always one glyph
18115 at the end of a glyph row that the cursor can be set on under
18116 window-systems. (If there weren't such a glyph we would not know
18117 how wide and tall a box cursor should be displayed).
18119 At the same time this space let's a nicely handle clearing to the
18120 end of the line if the row ends in italic text. */
18123 append_space_for_newline (struct it
*it
, int default_face_p
)
18125 if (FRAME_WINDOW_P (it
->f
))
18127 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18129 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18130 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18132 /* Save some values that must not be changed.
18133 Must save IT->c and IT->len because otherwise
18134 ITERATOR_AT_END_P wouldn't work anymore after
18135 append_space_for_newline has been called. */
18136 enum display_element_type saved_what
= it
->what
;
18137 int saved_c
= it
->c
, saved_len
= it
->len
;
18138 int saved_char_to_display
= it
->char_to_display
;
18139 int saved_x
= it
->current_x
;
18140 int saved_face_id
= it
->face_id
;
18141 struct text_pos saved_pos
;
18142 Lisp_Object saved_object
;
18145 saved_object
= it
->object
;
18146 saved_pos
= it
->position
;
18148 it
->what
= IT_CHARACTER
;
18149 memset (&it
->position
, 0, sizeof it
->position
);
18150 it
->object
= make_number (0);
18151 it
->c
= it
->char_to_display
= ' ';
18154 if (default_face_p
)
18155 it
->face_id
= DEFAULT_FACE_ID
;
18156 else if (it
->face_before_selective_p
)
18157 it
->face_id
= it
->saved_face_id
;
18158 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18159 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18161 PRODUCE_GLYPHS (it
);
18163 it
->override_ascent
= -1;
18164 it
->constrain_row_ascent_descent_p
= 0;
18165 it
->current_x
= saved_x
;
18166 it
->object
= saved_object
;
18167 it
->position
= saved_pos
;
18168 it
->what
= saved_what
;
18169 it
->face_id
= saved_face_id
;
18170 it
->len
= saved_len
;
18172 it
->char_to_display
= saved_char_to_display
;
18181 /* Extend the face of the last glyph in the text area of IT->glyph_row
18182 to the end of the display line. Called from display_line. If the
18183 glyph row is empty, add a space glyph to it so that we know the
18184 face to draw. Set the glyph row flag fill_line_p. If the glyph
18185 row is R2L, prepend a stretch glyph to cover the empty space to the
18186 left of the leftmost glyph. */
18189 extend_face_to_end_of_line (struct it
*it
)
18192 struct frame
*f
= it
->f
;
18194 /* If line is already filled, do nothing. Non window-system frames
18195 get a grace of one more ``pixel'' because their characters are
18196 1-``pixel'' wide, so they hit the equality too early. This grace
18197 is needed only for R2L rows that are not continued, to produce
18198 one extra blank where we could display the cursor. */
18199 if (it
->current_x
>= it
->last_visible_x
18200 + (!FRAME_WINDOW_P (f
)
18201 && it
->glyph_row
->reversed_p
18202 && !it
->glyph_row
->continued_p
))
18205 /* Face extension extends the background and box of IT->face_id
18206 to the end of the line. If the background equals the background
18207 of the frame, we don't have to do anything. */
18208 if (it
->face_before_selective_p
)
18209 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18211 face
= FACE_FROM_ID (f
, it
->face_id
);
18213 if (FRAME_WINDOW_P (f
)
18214 && it
->glyph_row
->displays_text_p
18215 && face
->box
== FACE_NO_BOX
18216 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18218 && !it
->glyph_row
->reversed_p
)
18221 /* Set the glyph row flag indicating that the face of the last glyph
18222 in the text area has to be drawn to the end of the text area. */
18223 it
->glyph_row
->fill_line_p
= 1;
18225 /* If current character of IT is not ASCII, make sure we have the
18226 ASCII face. This will be automatically undone the next time
18227 get_next_display_element returns a multibyte character. Note
18228 that the character will always be single byte in unibyte
18230 if (!ASCII_CHAR_P (it
->c
))
18232 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18235 if (FRAME_WINDOW_P (f
))
18237 /* If the row is empty, add a space with the current face of IT,
18238 so that we know which face to draw. */
18239 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18241 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18242 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
18243 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18245 #ifdef HAVE_WINDOW_SYSTEM
18246 if (it
->glyph_row
->reversed_p
)
18248 /* Prepend a stretch glyph to the row, such that the
18249 rightmost glyph will be drawn flushed all the way to the
18250 right margin of the window. The stretch glyph that will
18251 occupy the empty space, if any, to the left of the
18253 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18254 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18255 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18257 int row_width
, stretch_ascent
, stretch_width
;
18258 struct text_pos saved_pos
;
18259 int saved_face_id
, saved_avoid_cursor
;
18261 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18262 row_width
+= g
->pixel_width
;
18263 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18264 if (stretch_width
> 0)
18267 (((it
->ascent
+ it
->descent
)
18268 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18269 saved_pos
= it
->position
;
18270 memset (&it
->position
, 0, sizeof it
->position
);
18271 saved_avoid_cursor
= it
->avoid_cursor_p
;
18272 it
->avoid_cursor_p
= 1;
18273 saved_face_id
= it
->face_id
;
18274 /* The last row's stretch glyph should get the default
18275 face, to avoid painting the rest of the window with
18276 the region face, if the region ends at ZV. */
18277 if (it
->glyph_row
->ends_at_zv_p
)
18278 it
->face_id
= DEFAULT_FACE_ID
;
18280 it
->face_id
= face
->id
;
18281 append_stretch_glyph (it
, make_number (0), stretch_width
,
18282 it
->ascent
+ it
->descent
, stretch_ascent
);
18283 it
->position
= saved_pos
;
18284 it
->avoid_cursor_p
= saved_avoid_cursor
;
18285 it
->face_id
= saved_face_id
;
18288 #endif /* HAVE_WINDOW_SYSTEM */
18292 /* Save some values that must not be changed. */
18293 int saved_x
= it
->current_x
;
18294 struct text_pos saved_pos
;
18295 Lisp_Object saved_object
;
18296 enum display_element_type saved_what
= it
->what
;
18297 int saved_face_id
= it
->face_id
;
18299 saved_object
= it
->object
;
18300 saved_pos
= it
->position
;
18302 it
->what
= IT_CHARACTER
;
18303 memset (&it
->position
, 0, sizeof it
->position
);
18304 it
->object
= make_number (0);
18305 it
->c
= it
->char_to_display
= ' ';
18307 /* The last row's blank glyphs should get the default face, to
18308 avoid painting the rest of the window with the region face,
18309 if the region ends at ZV. */
18310 if (it
->glyph_row
->ends_at_zv_p
)
18311 it
->face_id
= DEFAULT_FACE_ID
;
18313 it
->face_id
= face
->id
;
18315 PRODUCE_GLYPHS (it
);
18317 while (it
->current_x
<= it
->last_visible_x
)
18318 PRODUCE_GLYPHS (it
);
18320 /* Don't count these blanks really. It would let us insert a left
18321 truncation glyph below and make us set the cursor on them, maybe. */
18322 it
->current_x
= saved_x
;
18323 it
->object
= saved_object
;
18324 it
->position
= saved_pos
;
18325 it
->what
= saved_what
;
18326 it
->face_id
= saved_face_id
;
18331 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18332 trailing whitespace. */
18335 trailing_whitespace_p (ptrdiff_t charpos
)
18337 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18340 while (bytepos
< ZV_BYTE
18341 && (c
= FETCH_CHAR (bytepos
),
18342 c
== ' ' || c
== '\t'))
18345 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18347 if (bytepos
!= PT_BYTE
)
18354 /* Highlight trailing whitespace, if any, in ROW. */
18357 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18359 int used
= row
->used
[TEXT_AREA
];
18363 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18364 struct glyph
*glyph
= start
+ used
- 1;
18366 if (row
->reversed_p
)
18368 /* Right-to-left rows need to be processed in the opposite
18369 direction, so swap the edge pointers. */
18371 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18374 /* Skip over glyphs inserted to display the cursor at the
18375 end of a line, for extending the face of the last glyph
18376 to the end of the line on terminals, and for truncation
18377 and continuation glyphs. */
18378 if (!row
->reversed_p
)
18380 while (glyph
>= start
18381 && glyph
->type
== CHAR_GLYPH
18382 && INTEGERP (glyph
->object
))
18387 while (glyph
<= start
18388 && glyph
->type
== CHAR_GLYPH
18389 && INTEGERP (glyph
->object
))
18393 /* If last glyph is a space or stretch, and it's trailing
18394 whitespace, set the face of all trailing whitespace glyphs in
18395 IT->glyph_row to `trailing-whitespace'. */
18396 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18397 && BUFFERP (glyph
->object
)
18398 && (glyph
->type
== STRETCH_GLYPH
18399 || (glyph
->type
== CHAR_GLYPH
18400 && glyph
->u
.ch
== ' '))
18401 && trailing_whitespace_p (glyph
->charpos
))
18403 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18407 if (!row
->reversed_p
)
18409 while (glyph
>= start
18410 && BUFFERP (glyph
->object
)
18411 && (glyph
->type
== STRETCH_GLYPH
18412 || (glyph
->type
== CHAR_GLYPH
18413 && glyph
->u
.ch
== ' ')))
18414 (glyph
--)->face_id
= face_id
;
18418 while (glyph
<= start
18419 && BUFFERP (glyph
->object
)
18420 && (glyph
->type
== STRETCH_GLYPH
18421 || (glyph
->type
== CHAR_GLYPH
18422 && glyph
->u
.ch
== ' ')))
18423 (glyph
++)->face_id
= face_id
;
18430 /* Value is non-zero if glyph row ROW should be
18431 used to hold the cursor. */
18434 cursor_row_p (struct glyph_row
*row
)
18438 if (PT
== CHARPOS (row
->end
.pos
)
18439 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18441 /* Suppose the row ends on a string.
18442 Unless the row is continued, that means it ends on a newline
18443 in the string. If it's anything other than a display string
18444 (e.g. a before-string from an overlay), we don't want the
18445 cursor there. (This heuristic seems to give the optimal
18446 behavior for the various types of multi-line strings.) */
18447 if (CHARPOS (row
->end
.string_pos
) >= 0)
18449 if (row
->continued_p
)
18453 /* Check for `display' property. */
18454 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18455 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18456 struct glyph
*glyph
;
18459 for (glyph
= end
; glyph
>= beg
; --glyph
)
18460 if (STRINGP (glyph
->object
))
18463 = Fget_char_property (make_number (PT
),
18467 && display_prop_string_p (prop
, glyph
->object
));
18472 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18474 /* If the row ends in middle of a real character,
18475 and the line is continued, we want the cursor here.
18476 That's because CHARPOS (ROW->end.pos) would equal
18477 PT if PT is before the character. */
18478 if (!row
->ends_in_ellipsis_p
)
18479 result
= row
->continued_p
;
18481 /* If the row ends in an ellipsis, then
18482 CHARPOS (ROW->end.pos) will equal point after the
18483 invisible text. We want that position to be displayed
18484 after the ellipsis. */
18487 /* If the row ends at ZV, display the cursor at the end of that
18488 row instead of at the start of the row below. */
18489 else if (row
->ends_at_zv_p
)
18500 /* Push the property PROP so that it will be rendered at the current
18501 position in IT. Return 1 if PROP was successfully pushed, 0
18502 otherwise. Called from handle_line_prefix to handle the
18503 `line-prefix' and `wrap-prefix' properties. */
18506 push_display_prop (struct it
*it
, Lisp_Object prop
)
18508 struct text_pos pos
=
18509 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18511 xassert (it
->method
== GET_FROM_BUFFER
18512 || it
->method
== GET_FROM_DISPLAY_VECTOR
18513 || it
->method
== GET_FROM_STRING
);
18515 /* We need to save the current buffer/string position, so it will be
18516 restored by pop_it, because iterate_out_of_display_property
18517 depends on that being set correctly, but some situations leave
18518 it->position not yet set when this function is called. */
18519 push_it (it
, &pos
);
18521 if (STRINGP (prop
))
18523 if (SCHARS (prop
) == 0)
18530 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18531 it
->current
.overlay_string_index
= -1;
18532 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18533 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18534 it
->method
= GET_FROM_STRING
;
18535 it
->stop_charpos
= 0;
18537 it
->base_level_stop
= 0;
18539 /* Force paragraph direction to be that of the parent
18541 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18542 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18544 it
->paragraph_embedding
= L2R
;
18546 /* Set up the bidi iterator for this display string. */
18549 it
->bidi_it
.string
.lstring
= it
->string
;
18550 it
->bidi_it
.string
.s
= NULL
;
18551 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18552 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18553 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18554 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18555 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18558 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18560 it
->method
= GET_FROM_STRETCH
;
18563 #ifdef HAVE_WINDOW_SYSTEM
18564 else if (IMAGEP (prop
))
18566 it
->what
= IT_IMAGE
;
18567 it
->image_id
= lookup_image (it
->f
, prop
);
18568 it
->method
= GET_FROM_IMAGE
;
18570 #endif /* HAVE_WINDOW_SYSTEM */
18573 pop_it (it
); /* bogus display property, give up */
18580 /* Return the character-property PROP at the current position in IT. */
18583 get_it_property (struct it
*it
, Lisp_Object prop
)
18585 Lisp_Object position
;
18587 if (STRINGP (it
->object
))
18588 position
= make_number (IT_STRING_CHARPOS (*it
));
18589 else if (BUFFERP (it
->object
))
18590 position
= make_number (IT_CHARPOS (*it
));
18594 return Fget_char_property (position
, prop
, it
->object
);
18597 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18600 handle_line_prefix (struct it
*it
)
18602 Lisp_Object prefix
;
18604 if (it
->continuation_lines_width
> 0)
18606 prefix
= get_it_property (it
, Qwrap_prefix
);
18608 prefix
= Vwrap_prefix
;
18612 prefix
= get_it_property (it
, Qline_prefix
);
18614 prefix
= Vline_prefix
;
18616 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
18618 /* If the prefix is wider than the window, and we try to wrap
18619 it, it would acquire its own wrap prefix, and so on till the
18620 iterator stack overflows. So, don't wrap the prefix. */
18621 it
->line_wrap
= TRUNCATE
;
18622 it
->avoid_cursor_p
= 1;
18628 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18629 only for R2L lines from display_line and display_string, when they
18630 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18631 the line/string needs to be continued on the next glyph row. */
18633 unproduce_glyphs (struct it
*it
, int n
)
18635 struct glyph
*glyph
, *end
;
18637 xassert (it
->glyph_row
);
18638 xassert (it
->glyph_row
->reversed_p
);
18639 xassert (it
->area
== TEXT_AREA
);
18640 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18642 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18643 n
= it
->glyph_row
->used
[TEXT_AREA
];
18644 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18645 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18646 for ( ; glyph
< end
; glyph
++)
18647 glyph
[-n
] = *glyph
;
18650 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18651 and ROW->maxpos. */
18653 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18654 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18655 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18657 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18658 lines' rows is implemented for bidi-reordered rows. */
18660 /* ROW->minpos is the value of min_pos, the minimal buffer position
18661 we have in ROW, or ROW->start.pos if that is smaller. */
18662 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18663 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18665 /* We didn't find buffer positions smaller than ROW->start, or
18666 didn't find _any_ valid buffer positions in any of the glyphs,
18667 so we must trust the iterator's computed positions. */
18668 row
->minpos
= row
->start
.pos
;
18671 max_pos
= CHARPOS (it
->current
.pos
);
18672 max_bpos
= BYTEPOS (it
->current
.pos
);
18675 /* Here are the various use-cases for ending the row, and the
18676 corresponding values for ROW->maxpos:
18678 Line ends in a newline from buffer eol_pos + 1
18679 Line is continued from buffer max_pos + 1
18680 Line is truncated on right it->current.pos
18681 Line ends in a newline from string max_pos + 1(*)
18682 (*) + 1 only when line ends in a forward scan
18683 Line is continued from string max_pos
18684 Line is continued from display vector max_pos
18685 Line is entirely from a string min_pos == max_pos
18686 Line is entirely from a display vector min_pos == max_pos
18687 Line that ends at ZV ZV
18689 If you discover other use-cases, please add them here as
18691 if (row
->ends_at_zv_p
)
18692 row
->maxpos
= it
->current
.pos
;
18693 else if (row
->used
[TEXT_AREA
])
18695 int seen_this_string
= 0;
18696 struct glyph_row
*r1
= row
- 1;
18698 /* Did we see the same display string on the previous row? */
18699 if (STRINGP (it
->object
)
18700 /* this is not the first row */
18701 && row
> it
->w
->desired_matrix
->rows
18702 /* previous row is not the header line */
18703 && !r1
->mode_line_p
18704 /* previous row also ends in a newline from a string */
18705 && r1
->ends_in_newline_from_string_p
)
18707 struct glyph
*start
, *end
;
18709 /* Search for the last glyph of the previous row that came
18710 from buffer or string. Depending on whether the row is
18711 L2R or R2L, we need to process it front to back or the
18712 other way round. */
18713 if (!r1
->reversed_p
)
18715 start
= r1
->glyphs
[TEXT_AREA
];
18716 end
= start
+ r1
->used
[TEXT_AREA
];
18717 /* Glyphs inserted by redisplay have an integer (zero)
18718 as their object. */
18720 && INTEGERP ((end
- 1)->object
)
18721 && (end
- 1)->charpos
<= 0)
18725 if (EQ ((end
- 1)->object
, it
->object
))
18726 seen_this_string
= 1;
18729 /* If all the glyphs of the previous row were inserted
18730 by redisplay, it means the previous row was
18731 produced from a single newline, which is only
18732 possible if that newline came from the same string
18733 as the one which produced this ROW. */
18734 seen_this_string
= 1;
18738 end
= r1
->glyphs
[TEXT_AREA
] - 1;
18739 start
= end
+ r1
->used
[TEXT_AREA
];
18741 && INTEGERP ((end
+ 1)->object
)
18742 && (end
+ 1)->charpos
<= 0)
18746 if (EQ ((end
+ 1)->object
, it
->object
))
18747 seen_this_string
= 1;
18750 seen_this_string
= 1;
18753 /* Take note of each display string that covers a newline only
18754 once, the first time we see it. This is for when a display
18755 string includes more than one newline in it. */
18756 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
18758 /* If we were scanning the buffer forward when we displayed
18759 the string, we want to account for at least one buffer
18760 position that belongs to this row (position covered by
18761 the display string), so that cursor positioning will
18762 consider this row as a candidate when point is at the end
18763 of the visual line represented by this row. This is not
18764 required when scanning back, because max_pos will already
18765 have a much larger value. */
18766 if (CHARPOS (row
->end
.pos
) > max_pos
)
18767 INC_BOTH (max_pos
, max_bpos
);
18768 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18770 else if (CHARPOS (it
->eol_pos
) > 0)
18771 SET_TEXT_POS (row
->maxpos
,
18772 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
18773 else if (row
->continued_p
)
18775 /* If max_pos is different from IT's current position, it
18776 means IT->method does not belong to the display element
18777 at max_pos. However, it also means that the display
18778 element at max_pos was displayed in its entirety on this
18779 line, which is equivalent to saying that the next line
18780 starts at the next buffer position. */
18781 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
18782 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18785 INC_BOTH (max_pos
, max_bpos
);
18786 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18789 else if (row
->truncated_on_right_p
)
18790 /* display_line already called reseat_at_next_visible_line_start,
18791 which puts the iterator at the beginning of the next line, in
18792 the logical order. */
18793 row
->maxpos
= it
->current
.pos
;
18794 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
18795 /* A line that is entirely from a string/image/stretch... */
18796 row
->maxpos
= row
->minpos
;
18801 row
->maxpos
= it
->current
.pos
;
18804 /* Construct the glyph row IT->glyph_row in the desired matrix of
18805 IT->w from text at the current position of IT. See dispextern.h
18806 for an overview of struct it. Value is non-zero if
18807 IT->glyph_row displays text, as opposed to a line displaying ZV
18811 display_line (struct it
*it
)
18813 struct glyph_row
*row
= it
->glyph_row
;
18814 Lisp_Object overlay_arrow_string
;
18816 void *wrap_data
= NULL
;
18817 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
18818 int wrap_row_used
= -1;
18819 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
18820 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
18821 int wrap_row_extra_line_spacing
IF_LINT (= 0);
18822 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
18823 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
18825 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
18826 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18828 /* We always start displaying at hpos zero even if hscrolled. */
18829 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18831 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18832 >= it
->w
->desired_matrix
->nrows
)
18834 it
->w
->nrows_scale_factor
++;
18835 fonts_changed_p
= 1;
18839 /* Is IT->w showing the region? */
18840 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18842 /* Clear the result glyph row and enable it. */
18843 prepare_desired_row (row
);
18845 row
->y
= it
->current_y
;
18846 row
->start
= it
->start
;
18847 row
->continuation_lines_width
= it
->continuation_lines_width
;
18848 row
->displays_text_p
= 1;
18849 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18850 it
->starts_in_middle_of_char_p
= 0;
18852 /* Arrange the overlays nicely for our purposes. Usually, we call
18853 display_line on only one line at a time, in which case this
18854 can't really hurt too much, or we call it on lines which appear
18855 one after another in the buffer, in which case all calls to
18856 recenter_overlay_lists but the first will be pretty cheap. */
18857 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18859 /* Move over display elements that are not visible because we are
18860 hscrolled. This may stop at an x-position < IT->first_visible_x
18861 if the first glyph is partially visible or if we hit a line end. */
18862 if (it
->current_x
< it
->first_visible_x
)
18864 this_line_min_pos
= row
->start
.pos
;
18865 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18866 MOVE_TO_POS
| MOVE_TO_X
);
18867 /* Record the smallest positions seen while we moved over
18868 display elements that are not visible. This is needed by
18869 redisplay_internal for optimizing the case where the cursor
18870 stays inside the same line. The rest of this function only
18871 considers positions that are actually displayed, so
18872 RECORD_MAX_MIN_POS will not otherwise record positions that
18873 are hscrolled to the left of the left edge of the window. */
18874 min_pos
= CHARPOS (this_line_min_pos
);
18875 min_bpos
= BYTEPOS (this_line_min_pos
);
18879 /* We only do this when not calling `move_it_in_display_line_to'
18880 above, because move_it_in_display_line_to calls
18881 handle_line_prefix itself. */
18882 handle_line_prefix (it
);
18885 /* Get the initial row height. This is either the height of the
18886 text hscrolled, if there is any, or zero. */
18887 row
->ascent
= it
->max_ascent
;
18888 row
->height
= it
->max_ascent
+ it
->max_descent
;
18889 row
->phys_ascent
= it
->max_phys_ascent
;
18890 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18891 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18893 /* Utility macro to record max and min buffer positions seen until now. */
18894 #define RECORD_MAX_MIN_POS(IT) \
18897 int composition_p = !STRINGP ((IT)->string) \
18898 && ((IT)->what == IT_COMPOSITION); \
18899 ptrdiff_t current_pos = \
18900 composition_p ? (IT)->cmp_it.charpos \
18901 : IT_CHARPOS (*(IT)); \
18902 ptrdiff_t current_bpos = \
18903 composition_p ? CHAR_TO_BYTE (current_pos) \
18904 : IT_BYTEPOS (*(IT)); \
18905 if (current_pos < min_pos) \
18907 min_pos = current_pos; \
18908 min_bpos = current_bpos; \
18910 if (IT_CHARPOS (*it) > max_pos) \
18912 max_pos = IT_CHARPOS (*it); \
18913 max_bpos = IT_BYTEPOS (*it); \
18918 /* Loop generating characters. The loop is left with IT on the next
18919 character to display. */
18922 int n_glyphs_before
, hpos_before
, x_before
;
18924 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
18926 /* Retrieve the next thing to display. Value is zero if end of
18928 if (!get_next_display_element (it
))
18930 /* Maybe add a space at the end of this line that is used to
18931 display the cursor there under X. Set the charpos of the
18932 first glyph of blank lines not corresponding to any text
18934 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18935 row
->exact_window_width_line_p
= 1;
18936 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
18937 || row
->used
[TEXT_AREA
] == 0)
18939 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
18940 row
->displays_text_p
= 0;
18942 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
18943 && (!MINI_WINDOW_P (it
->w
)
18944 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
18945 row
->indicate_empty_line_p
= 1;
18948 it
->continuation_lines_width
= 0;
18949 row
->ends_at_zv_p
= 1;
18950 /* A row that displays right-to-left text must always have
18951 its last face extended all the way to the end of line,
18952 even if this row ends in ZV, because we still write to
18953 the screen left to right. */
18954 if (row
->reversed_p
)
18955 extend_face_to_end_of_line (it
);
18959 /* Now, get the metrics of what we want to display. This also
18960 generates glyphs in `row' (which is IT->glyph_row). */
18961 n_glyphs_before
= row
->used
[TEXT_AREA
];
18964 /* Remember the line height so far in case the next element doesn't
18965 fit on the line. */
18966 if (it
->line_wrap
!= TRUNCATE
)
18968 ascent
= it
->max_ascent
;
18969 descent
= it
->max_descent
;
18970 phys_ascent
= it
->max_phys_ascent
;
18971 phys_descent
= it
->max_phys_descent
;
18973 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
18975 if (IT_DISPLAYING_WHITESPACE (it
))
18979 SAVE_IT (wrap_it
, *it
, wrap_data
);
18981 wrap_row_used
= row
->used
[TEXT_AREA
];
18982 wrap_row_ascent
= row
->ascent
;
18983 wrap_row_height
= row
->height
;
18984 wrap_row_phys_ascent
= row
->phys_ascent
;
18985 wrap_row_phys_height
= row
->phys_height
;
18986 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18987 wrap_row_min_pos
= min_pos
;
18988 wrap_row_min_bpos
= min_bpos
;
18989 wrap_row_max_pos
= max_pos
;
18990 wrap_row_max_bpos
= max_bpos
;
18996 PRODUCE_GLYPHS (it
);
18998 /* If this display element was in marginal areas, continue with
19000 if (it
->area
!= TEXT_AREA
)
19002 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19003 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19004 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19005 row
->phys_height
= max (row
->phys_height
,
19006 it
->max_phys_ascent
+ it
->max_phys_descent
);
19007 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19008 it
->max_extra_line_spacing
);
19009 set_iterator_to_next (it
, 1);
19013 /* Does the display element fit on the line? If we truncate
19014 lines, we should draw past the right edge of the window. If
19015 we don't truncate, we want to stop so that we can display the
19016 continuation glyph before the right margin. If lines are
19017 continued, there are two possible strategies for characters
19018 resulting in more than 1 glyph (e.g. tabs): Display as many
19019 glyphs as possible in this line and leave the rest for the
19020 continuation line, or display the whole element in the next
19021 line. Original redisplay did the former, so we do it also. */
19022 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19023 hpos_before
= it
->hpos
;
19026 if (/* Not a newline. */
19028 /* Glyphs produced fit entirely in the line. */
19029 && it
->current_x
< it
->last_visible_x
)
19031 it
->hpos
+= nglyphs
;
19032 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19033 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19034 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19035 row
->phys_height
= max (row
->phys_height
,
19036 it
->max_phys_ascent
+ it
->max_phys_descent
);
19037 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19038 it
->max_extra_line_spacing
);
19039 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19040 row
->x
= x
- it
->first_visible_x
;
19041 /* Record the maximum and minimum buffer positions seen so
19042 far in glyphs that will be displayed by this row. */
19044 RECORD_MAX_MIN_POS (it
);
19049 struct glyph
*glyph
;
19051 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19053 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19054 new_x
= x
+ glyph
->pixel_width
;
19056 if (/* Lines are continued. */
19057 it
->line_wrap
!= TRUNCATE
19058 && (/* Glyph doesn't fit on the line. */
19059 new_x
> it
->last_visible_x
19060 /* Or it fits exactly on a window system frame. */
19061 || (new_x
== it
->last_visible_x
19062 && FRAME_WINDOW_P (it
->f
))))
19064 /* End of a continued line. */
19067 || (new_x
== it
->last_visible_x
19068 && FRAME_WINDOW_P (it
->f
)))
19070 /* Current glyph is the only one on the line or
19071 fits exactly on the line. We must continue
19072 the line because we can't draw the cursor
19073 after the glyph. */
19074 row
->continued_p
= 1;
19075 it
->current_x
= new_x
;
19076 it
->continuation_lines_width
+= new_x
;
19078 if (i
== nglyphs
- 1)
19080 /* If line-wrap is on, check if a previous
19081 wrap point was found. */
19082 if (wrap_row_used
> 0
19083 /* Even if there is a previous wrap
19084 point, continue the line here as
19085 usual, if (i) the previous character
19086 was a space or tab AND (ii) the
19087 current character is not. */
19089 || IT_DISPLAYING_WHITESPACE (it
)))
19092 /* Record the maximum and minimum buffer
19093 positions seen so far in glyphs that will be
19094 displayed by this row. */
19096 RECORD_MAX_MIN_POS (it
);
19097 set_iterator_to_next (it
, 1);
19098 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19100 if (!get_next_display_element (it
))
19102 row
->exact_window_width_line_p
= 1;
19103 it
->continuation_lines_width
= 0;
19104 row
->continued_p
= 0;
19105 row
->ends_at_zv_p
= 1;
19107 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19109 row
->continued_p
= 0;
19110 row
->exact_window_width_line_p
= 1;
19114 else if (it
->bidi_p
)
19115 RECORD_MAX_MIN_POS (it
);
19117 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19118 && !FRAME_WINDOW_P (it
->f
))
19120 /* A padding glyph that doesn't fit on this line.
19121 This means the whole character doesn't fit
19123 if (row
->reversed_p
)
19124 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19125 - n_glyphs_before
);
19126 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19128 /* Fill the rest of the row with continuation
19129 glyphs like in 20.x. */
19130 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19131 < row
->glyphs
[1 + TEXT_AREA
])
19132 produce_special_glyphs (it
, IT_CONTINUATION
);
19134 row
->continued_p
= 1;
19135 it
->current_x
= x_before
;
19136 it
->continuation_lines_width
+= x_before
;
19138 /* Restore the height to what it was before the
19139 element not fitting on the line. */
19140 it
->max_ascent
= ascent
;
19141 it
->max_descent
= descent
;
19142 it
->max_phys_ascent
= phys_ascent
;
19143 it
->max_phys_descent
= phys_descent
;
19145 else if (wrap_row_used
> 0)
19148 if (row
->reversed_p
)
19149 unproduce_glyphs (it
,
19150 row
->used
[TEXT_AREA
] - wrap_row_used
);
19151 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19152 it
->continuation_lines_width
+= wrap_x
;
19153 row
->used
[TEXT_AREA
] = wrap_row_used
;
19154 row
->ascent
= wrap_row_ascent
;
19155 row
->height
= wrap_row_height
;
19156 row
->phys_ascent
= wrap_row_phys_ascent
;
19157 row
->phys_height
= wrap_row_phys_height
;
19158 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19159 min_pos
= wrap_row_min_pos
;
19160 min_bpos
= wrap_row_min_bpos
;
19161 max_pos
= wrap_row_max_pos
;
19162 max_bpos
= wrap_row_max_bpos
;
19163 row
->continued_p
= 1;
19164 row
->ends_at_zv_p
= 0;
19165 row
->exact_window_width_line_p
= 0;
19166 it
->continuation_lines_width
+= x
;
19168 /* Make sure that a non-default face is extended
19169 up to the right margin of the window. */
19170 extend_face_to_end_of_line (it
);
19172 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19174 /* A TAB that extends past the right edge of the
19175 window. This produces a single glyph on
19176 window system frames. We leave the glyph in
19177 this row and let it fill the row, but don't
19178 consume the TAB. */
19179 it
->continuation_lines_width
+= it
->last_visible_x
;
19180 row
->ends_in_middle_of_char_p
= 1;
19181 row
->continued_p
= 1;
19182 glyph
->pixel_width
= it
->last_visible_x
- x
;
19183 it
->starts_in_middle_of_char_p
= 1;
19187 /* Something other than a TAB that draws past
19188 the right edge of the window. Restore
19189 positions to values before the element. */
19190 if (row
->reversed_p
)
19191 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19192 - (n_glyphs_before
+ i
));
19193 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19195 /* Display continuation glyphs. */
19196 if (!FRAME_WINDOW_P (it
->f
))
19197 produce_special_glyphs (it
, IT_CONTINUATION
);
19198 row
->continued_p
= 1;
19200 it
->current_x
= x_before
;
19201 it
->continuation_lines_width
+= x
;
19202 extend_face_to_end_of_line (it
);
19204 if (nglyphs
> 1 && i
> 0)
19206 row
->ends_in_middle_of_char_p
= 1;
19207 it
->starts_in_middle_of_char_p
= 1;
19210 /* Restore the height to what it was before the
19211 element not fitting on the line. */
19212 it
->max_ascent
= ascent
;
19213 it
->max_descent
= descent
;
19214 it
->max_phys_ascent
= phys_ascent
;
19215 it
->max_phys_descent
= phys_descent
;
19220 else if (new_x
> it
->first_visible_x
)
19222 /* Increment number of glyphs actually displayed. */
19225 /* Record the maximum and minimum buffer positions
19226 seen so far in glyphs that will be displayed by
19229 RECORD_MAX_MIN_POS (it
);
19231 if (x
< it
->first_visible_x
)
19232 /* Glyph is partially visible, i.e. row starts at
19233 negative X position. */
19234 row
->x
= x
- it
->first_visible_x
;
19238 /* Glyph is completely off the left margin of the
19239 window. This should not happen because of the
19240 move_it_in_display_line at the start of this
19241 function, unless the text display area of the
19242 window is empty. */
19243 xassert (it
->first_visible_x
<= it
->last_visible_x
);
19246 /* Even if this display element produced no glyphs at all,
19247 we want to record its position. */
19248 if (it
->bidi_p
&& nglyphs
== 0)
19249 RECORD_MAX_MIN_POS (it
);
19251 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19252 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19253 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19254 row
->phys_height
= max (row
->phys_height
,
19255 it
->max_phys_ascent
+ it
->max_phys_descent
);
19256 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19257 it
->max_extra_line_spacing
);
19259 /* End of this display line if row is continued. */
19260 if (row
->continued_p
|| row
->ends_at_zv_p
)
19265 /* Is this a line end? If yes, we're also done, after making
19266 sure that a non-default face is extended up to the right
19267 margin of the window. */
19268 if (ITERATOR_AT_END_OF_LINE_P (it
))
19270 int used_before
= row
->used
[TEXT_AREA
];
19272 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19274 /* Add a space at the end of the line that is used to
19275 display the cursor there. */
19276 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19277 append_space_for_newline (it
, 0);
19279 /* Extend the face to the end of the line. */
19280 extend_face_to_end_of_line (it
);
19282 /* Make sure we have the position. */
19283 if (used_before
== 0)
19284 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19286 /* Record the position of the newline, for use in
19288 it
->eol_pos
= it
->current
.pos
;
19290 /* Consume the line end. This skips over invisible lines. */
19291 set_iterator_to_next (it
, 1);
19292 it
->continuation_lines_width
= 0;
19296 /* Proceed with next display element. Note that this skips
19297 over lines invisible because of selective display. */
19298 set_iterator_to_next (it
, 1);
19300 /* If we truncate lines, we are done when the last displayed
19301 glyphs reach past the right margin of the window. */
19302 if (it
->line_wrap
== TRUNCATE
19303 && (FRAME_WINDOW_P (it
->f
)
19304 ? (it
->current_x
>= it
->last_visible_x
)
19305 : (it
->current_x
> it
->last_visible_x
)))
19307 /* Maybe add truncation glyphs. */
19308 if (!FRAME_WINDOW_P (it
->f
))
19312 if (!row
->reversed_p
)
19314 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19315 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19320 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19321 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19323 /* Remove any padding glyphs at the front of ROW, to
19324 make room for the truncation glyphs we will be
19325 adding below. The loop below always inserts at
19326 least one truncation glyph, so also remove the
19327 last glyph added to ROW. */
19328 unproduce_glyphs (it
, i
+ 1);
19329 /* Adjust i for the loop below. */
19330 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19333 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19335 row
->used
[TEXT_AREA
] = i
;
19336 produce_special_glyphs (it
, IT_TRUNCATION
);
19339 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19341 /* Don't truncate if we can overflow newline into fringe. */
19342 if (!get_next_display_element (it
))
19344 it
->continuation_lines_width
= 0;
19345 row
->ends_at_zv_p
= 1;
19346 row
->exact_window_width_line_p
= 1;
19349 if (ITERATOR_AT_END_OF_LINE_P (it
))
19351 row
->exact_window_width_line_p
= 1;
19352 goto at_end_of_line
;
19356 row
->truncated_on_right_p
= 1;
19357 it
->continuation_lines_width
= 0;
19358 reseat_at_next_visible_line_start (it
, 0);
19359 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19360 it
->hpos
= hpos_before
;
19361 it
->current_x
= x_before
;
19367 bidi_unshelve_cache (wrap_data
, 1);
19369 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19370 at the left window margin. */
19371 if (it
->first_visible_x
19372 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19374 if (!FRAME_WINDOW_P (it
->f
))
19375 insert_left_trunc_glyphs (it
);
19376 row
->truncated_on_left_p
= 1;
19379 /* Remember the position at which this line ends.
19381 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19382 cannot be before the call to find_row_edges below, since that is
19383 where these positions are determined. */
19384 row
->end
= it
->current
;
19387 row
->minpos
= row
->start
.pos
;
19388 row
->maxpos
= row
->end
.pos
;
19392 /* ROW->minpos and ROW->maxpos must be the smallest and
19393 `1 + the largest' buffer positions in ROW. But if ROW was
19394 bidi-reordered, these two positions can be anywhere in the
19395 row, so we must determine them now. */
19396 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19399 /* If the start of this line is the overlay arrow-position, then
19400 mark this glyph row as the one containing the overlay arrow.
19401 This is clearly a mess with variable size fonts. It would be
19402 better to let it be displayed like cursors under X. */
19403 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19404 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19405 !NILP (overlay_arrow_string
)))
19407 /* Overlay arrow in window redisplay is a fringe bitmap. */
19408 if (STRINGP (overlay_arrow_string
))
19410 struct glyph_row
*arrow_row
19411 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19412 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19413 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19414 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19415 struct glyph
*p2
, *end
;
19417 /* Copy the arrow glyphs. */
19418 while (glyph
< arrow_end
)
19421 /* Throw away padding glyphs. */
19423 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19424 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19430 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19435 xassert (INTEGERP (overlay_arrow_string
));
19436 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19438 overlay_arrow_seen
= 1;
19441 /* Highlight trailing whitespace. */
19442 if (!NILP (Vshow_trailing_whitespace
))
19443 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19445 /* Compute pixel dimensions of this line. */
19446 compute_line_metrics (it
);
19448 /* Implementation note: No changes in the glyphs of ROW or in their
19449 faces can be done past this point, because compute_line_metrics
19450 computes ROW's hash value and stores it within the glyph_row
19453 /* Record whether this row ends inside an ellipsis. */
19454 row
->ends_in_ellipsis_p
19455 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19456 && it
->ellipsis_p
);
19458 /* Save fringe bitmaps in this row. */
19459 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19460 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19461 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19462 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19464 it
->left_user_fringe_bitmap
= 0;
19465 it
->left_user_fringe_face_id
= 0;
19466 it
->right_user_fringe_bitmap
= 0;
19467 it
->right_user_fringe_face_id
= 0;
19469 /* Maybe set the cursor. */
19470 cvpos
= it
->w
->cursor
.vpos
;
19472 /* In bidi-reordered rows, keep checking for proper cursor
19473 position even if one has been found already, because buffer
19474 positions in such rows change non-linearly with ROW->VPOS,
19475 when a line is continued. One exception: when we are at ZV,
19476 display cursor on the first suitable glyph row, since all
19477 the empty rows after that also have their position set to ZV. */
19478 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19479 lines' rows is implemented for bidi-reordered rows. */
19481 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19482 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19483 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19484 && cursor_row_p (row
))
19485 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19487 /* Prepare for the next line. This line starts horizontally at (X
19488 HPOS) = (0 0). Vertical positions are incremented. As a
19489 convenience for the caller, IT->glyph_row is set to the next
19491 it
->current_x
= it
->hpos
= 0;
19492 it
->current_y
+= row
->height
;
19493 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19496 /* The next row should by default use the same value of the
19497 reversed_p flag as this one. set_iterator_to_next decides when
19498 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19499 the flag accordingly. */
19500 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19501 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19502 it
->start
= row
->end
;
19503 return row
->displays_text_p
;
19505 #undef RECORD_MAX_MIN_POS
19508 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19509 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19510 doc
: /* Return paragraph direction at point in BUFFER.
19511 Value is either `left-to-right' or `right-to-left'.
19512 If BUFFER is omitted or nil, it defaults to the current buffer.
19514 Paragraph direction determines how the text in the paragraph is displayed.
19515 In left-to-right paragraphs, text begins at the left margin of the window
19516 and the reading direction is generally left to right. In right-to-left
19517 paragraphs, text begins at the right margin and is read from right to left.
19519 See also `bidi-paragraph-direction'. */)
19520 (Lisp_Object buffer
)
19522 struct buffer
*buf
= current_buffer
;
19523 struct buffer
*old
= buf
;
19525 if (! NILP (buffer
))
19527 CHECK_BUFFER (buffer
);
19528 buf
= XBUFFER (buffer
);
19531 if (NILP (BVAR (buf
, bidi_display_reordering
))
19532 || NILP (BVAR (buf
, enable_multibyte_characters
))
19533 /* When we are loading loadup.el, the character property tables
19534 needed for bidi iteration are not yet available. */
19535 || !NILP (Vpurify_flag
))
19536 return Qleft_to_right
;
19537 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19538 return BVAR (buf
, bidi_paragraph_direction
);
19541 /* Determine the direction from buffer text. We could try to
19542 use current_matrix if it is up to date, but this seems fast
19543 enough as it is. */
19544 struct bidi_it itb
;
19545 ptrdiff_t pos
= BUF_PT (buf
);
19546 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19548 void *itb_data
= bidi_shelve_cache ();
19550 set_buffer_temp (buf
);
19551 /* bidi_paragraph_init finds the base direction of the paragraph
19552 by searching forward from paragraph start. We need the base
19553 direction of the current or _previous_ paragraph, so we need
19554 to make sure we are within that paragraph. To that end, find
19555 the previous non-empty line. */
19556 if (pos
>= ZV
&& pos
> BEGV
)
19559 bytepos
= CHAR_TO_BYTE (pos
);
19561 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19562 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19564 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19565 || c
== ' ' || c
== '\t' || c
== '\f')
19567 if (bytepos
<= BEGV_BYTE
)
19572 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19575 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19576 itb
.paragraph_dir
= NEUTRAL_DIR
;
19577 itb
.string
.s
= NULL
;
19578 itb
.string
.lstring
= Qnil
;
19579 itb
.string
.bufpos
= 0;
19580 itb
.string
.unibyte
= 0;
19581 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19582 bidi_unshelve_cache (itb_data
, 0);
19583 set_buffer_temp (old
);
19584 switch (itb
.paragraph_dir
)
19587 return Qleft_to_right
;
19590 return Qright_to_left
;
19600 /***********************************************************************
19602 ***********************************************************************/
19604 /* Redisplay the menu bar in the frame for window W.
19606 The menu bar of X frames that don't have X toolkit support is
19607 displayed in a special window W->frame->menu_bar_window.
19609 The menu bar of terminal frames is treated specially as far as
19610 glyph matrices are concerned. Menu bar lines are not part of
19611 windows, so the update is done directly on the frame matrix rows
19612 for the menu bar. */
19615 display_menu_bar (struct window
*w
)
19617 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19622 /* Don't do all this for graphical frames. */
19624 if (FRAME_W32_P (f
))
19627 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19633 if (FRAME_NS_P (f
))
19635 #endif /* HAVE_NS */
19637 #ifdef USE_X_TOOLKIT
19638 xassert (!FRAME_WINDOW_P (f
));
19639 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19640 it
.first_visible_x
= 0;
19641 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19642 #else /* not USE_X_TOOLKIT */
19643 if (FRAME_WINDOW_P (f
))
19645 /* Menu bar lines are displayed in the desired matrix of the
19646 dummy window menu_bar_window. */
19647 struct window
*menu_w
;
19648 xassert (WINDOWP (f
->menu_bar_window
));
19649 menu_w
= XWINDOW (f
->menu_bar_window
);
19650 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19652 it
.first_visible_x
= 0;
19653 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19657 /* This is a TTY frame, i.e. character hpos/vpos are used as
19659 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19661 it
.first_visible_x
= 0;
19662 it
.last_visible_x
= FRAME_COLS (f
);
19664 #endif /* not USE_X_TOOLKIT */
19666 /* FIXME: This should be controlled by a user option. See the
19667 comments in redisplay_tool_bar and display_mode_line about
19669 it
.paragraph_embedding
= L2R
;
19671 if (! mode_line_inverse_video
)
19672 /* Force the menu-bar to be displayed in the default face. */
19673 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19675 /* Clear all rows of the menu bar. */
19676 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
19678 struct glyph_row
*row
= it
.glyph_row
+ i
;
19679 clear_glyph_row (row
);
19680 row
->enabled_p
= 1;
19681 row
->full_width_p
= 1;
19684 /* Display all items of the menu bar. */
19685 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
19686 for (i
= 0; i
< ASIZE (items
); i
+= 4)
19688 Lisp_Object string
;
19690 /* Stop at nil string. */
19691 string
= AREF (items
, i
+ 1);
19695 /* Remember where item was displayed. */
19696 ASET (items
, i
+ 3, make_number (it
.hpos
));
19698 /* Display the item, pad with one space. */
19699 if (it
.current_x
< it
.last_visible_x
)
19700 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
19701 SCHARS (string
) + 1, 0, 0, -1);
19704 /* Fill out the line with spaces. */
19705 if (it
.current_x
< it
.last_visible_x
)
19706 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
19708 /* Compute the total height of the lines. */
19709 compute_line_metrics (&it
);
19714 /***********************************************************************
19716 ***********************************************************************/
19718 /* Redisplay mode lines in the window tree whose root is WINDOW. If
19719 FORCE is non-zero, redisplay mode lines unconditionally.
19720 Otherwise, redisplay only mode lines that are garbaged. Value is
19721 the number of windows whose mode lines were redisplayed. */
19724 redisplay_mode_lines (Lisp_Object window
, int force
)
19728 while (!NILP (window
))
19730 struct window
*w
= XWINDOW (window
);
19732 if (WINDOWP (w
->hchild
))
19733 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
19734 else if (WINDOWP (w
->vchild
))
19735 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
19737 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
19738 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
19740 struct text_pos lpoint
;
19741 struct buffer
*old
= current_buffer
;
19743 /* Set the window's buffer for the mode line display. */
19744 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
19745 set_buffer_internal_1 (XBUFFER (w
->buffer
));
19747 /* Point refers normally to the selected window. For any
19748 other window, set up appropriate value. */
19749 if (!EQ (window
, selected_window
))
19751 struct text_pos pt
;
19753 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
19754 if (CHARPOS (pt
) < BEGV
)
19755 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
19756 else if (CHARPOS (pt
) > (ZV
- 1))
19757 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
19759 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
19762 /* Display mode lines. */
19763 clear_glyph_matrix (w
->desired_matrix
);
19764 if (display_mode_lines (w
))
19767 w
->must_be_updated_p
= 1;
19770 /* Restore old settings. */
19771 set_buffer_internal_1 (old
);
19772 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
19782 /* Display the mode and/or header line of window W. Value is the
19783 sum number of mode lines and header lines displayed. */
19786 display_mode_lines (struct window
*w
)
19788 Lisp_Object old_selected_window
, old_selected_frame
;
19791 old_selected_frame
= selected_frame
;
19792 selected_frame
= w
->frame
;
19793 old_selected_window
= selected_window
;
19794 XSETWINDOW (selected_window
, w
);
19796 /* These will be set while the mode line specs are processed. */
19797 line_number_displayed
= 0;
19798 w
->column_number_displayed
= Qnil
;
19800 if (WINDOW_WANTS_MODELINE_P (w
))
19802 struct window
*sel_w
= XWINDOW (old_selected_window
);
19804 /* Select mode line face based on the real selected window. */
19805 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
19806 BVAR (current_buffer
, mode_line_format
));
19810 if (WINDOW_WANTS_HEADER_LINE_P (w
))
19812 display_mode_line (w
, HEADER_LINE_FACE_ID
,
19813 BVAR (current_buffer
, header_line_format
));
19817 selected_frame
= old_selected_frame
;
19818 selected_window
= old_selected_window
;
19823 /* Display mode or header line of window W. FACE_ID specifies which
19824 line to display; it is either MODE_LINE_FACE_ID or
19825 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
19826 display. Value is the pixel height of the mode/header line
19830 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
19834 ptrdiff_t count
= SPECPDL_INDEX ();
19836 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19837 /* Don't extend on a previously drawn mode-line.
19838 This may happen if called from pos_visible_p. */
19839 it
.glyph_row
->enabled_p
= 0;
19840 prepare_desired_row (it
.glyph_row
);
19842 it
.glyph_row
->mode_line_p
= 1;
19844 if (! mode_line_inverse_video
)
19845 /* Force the mode-line to be displayed in the default face. */
19846 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19848 /* FIXME: This should be controlled by a user option. But
19849 supporting such an option is not trivial, since the mode line is
19850 made up of many separate strings. */
19851 it
.paragraph_embedding
= L2R
;
19853 record_unwind_protect (unwind_format_mode_line
,
19854 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19856 mode_line_target
= MODE_LINE_DISPLAY
;
19858 /* Temporarily make frame's keyboard the current kboard so that
19859 kboard-local variables in the mode_line_format will get the right
19861 push_kboard (FRAME_KBOARD (it
.f
));
19862 record_unwind_save_match_data ();
19863 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19866 unbind_to (count
, Qnil
);
19868 /* Fill up with spaces. */
19869 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
19871 compute_line_metrics (&it
);
19872 it
.glyph_row
->full_width_p
= 1;
19873 it
.glyph_row
->continued_p
= 0;
19874 it
.glyph_row
->truncated_on_left_p
= 0;
19875 it
.glyph_row
->truncated_on_right_p
= 0;
19877 /* Make a 3D mode-line have a shadow at its right end. */
19878 face
= FACE_FROM_ID (it
.f
, face_id
);
19879 extend_face_to_end_of_line (&it
);
19880 if (face
->box
!= FACE_NO_BOX
)
19882 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
19883 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
19884 last
->right_box_line_p
= 1;
19887 return it
.glyph_row
->height
;
19890 /* Move element ELT in LIST to the front of LIST.
19891 Return the updated list. */
19894 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
19896 register Lisp_Object tail
, prev
;
19897 register Lisp_Object tem
;
19901 while (CONSP (tail
))
19907 /* Splice out the link TAIL. */
19909 list
= XCDR (tail
);
19911 Fsetcdr (prev
, XCDR (tail
));
19913 /* Now make it the first. */
19914 Fsetcdr (tail
, list
);
19919 tail
= XCDR (tail
);
19923 /* Not found--return unchanged LIST. */
19927 /* Contribute ELT to the mode line for window IT->w. How it
19928 translates into text depends on its data type.
19930 IT describes the display environment in which we display, as usual.
19932 DEPTH is the depth in recursion. It is used to prevent
19933 infinite recursion here.
19935 FIELD_WIDTH is the number of characters the display of ELT should
19936 occupy in the mode line, and PRECISION is the maximum number of
19937 characters to display from ELT's representation. See
19938 display_string for details.
19940 Returns the hpos of the end of the text generated by ELT.
19942 PROPS is a property list to add to any string we encounter.
19944 If RISKY is nonzero, remove (disregard) any properties in any string
19945 we encounter, and ignore :eval and :propertize.
19947 The global variable `mode_line_target' determines whether the
19948 output is passed to `store_mode_line_noprop',
19949 `store_mode_line_string', or `display_string'. */
19952 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
19953 Lisp_Object elt
, Lisp_Object props
, int risky
)
19955 int n
= 0, field
, prec
;
19960 elt
= build_string ("*too-deep*");
19964 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
19968 /* A string: output it and check for %-constructs within it. */
19970 ptrdiff_t offset
= 0;
19972 if (SCHARS (elt
) > 0
19973 && (!NILP (props
) || risky
))
19975 Lisp_Object oprops
, aelt
;
19976 oprops
= Ftext_properties_at (make_number (0), elt
);
19978 /* If the starting string's properties are not what
19979 we want, translate the string. Also, if the string
19980 is risky, do that anyway. */
19982 if (NILP (Fequal (props
, oprops
)) || risky
)
19984 /* If the starting string has properties,
19985 merge the specified ones onto the existing ones. */
19986 if (! NILP (oprops
) && !risky
)
19990 oprops
= Fcopy_sequence (oprops
);
19992 while (CONSP (tem
))
19994 oprops
= Fplist_put (oprops
, XCAR (tem
),
19995 XCAR (XCDR (tem
)));
19996 tem
= XCDR (XCDR (tem
));
20001 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20002 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20004 /* AELT is what we want. Move it to the front
20005 without consing. */
20007 mode_line_proptrans_alist
20008 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20014 /* If AELT has the wrong props, it is useless.
20015 so get rid of it. */
20017 mode_line_proptrans_alist
20018 = Fdelq (aelt
, mode_line_proptrans_alist
);
20020 elt
= Fcopy_sequence (elt
);
20021 Fset_text_properties (make_number (0), Flength (elt
),
20023 /* Add this item to mode_line_proptrans_alist. */
20024 mode_line_proptrans_alist
20025 = Fcons (Fcons (elt
, props
),
20026 mode_line_proptrans_alist
);
20027 /* Truncate mode_line_proptrans_alist
20028 to at most 50 elements. */
20029 tem
= Fnthcdr (make_number (50),
20030 mode_line_proptrans_alist
);
20032 XSETCDR (tem
, Qnil
);
20041 prec
= precision
- n
;
20042 switch (mode_line_target
)
20044 case MODE_LINE_NOPROP
:
20045 case MODE_LINE_TITLE
:
20046 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20048 case MODE_LINE_STRING
:
20049 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20051 case MODE_LINE_DISPLAY
:
20052 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20053 0, prec
, 0, STRING_MULTIBYTE (elt
));
20060 /* Handle the non-literal case. */
20062 while ((precision
<= 0 || n
< precision
)
20063 && SREF (elt
, offset
) != 0
20064 && (mode_line_target
!= MODE_LINE_DISPLAY
20065 || it
->current_x
< it
->last_visible_x
))
20067 ptrdiff_t last_offset
= offset
;
20069 /* Advance to end of string or next format specifier. */
20070 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20073 if (offset
- 1 != last_offset
)
20075 ptrdiff_t nchars
, nbytes
;
20077 /* Output to end of string or up to '%'. Field width
20078 is length of string. Don't output more than
20079 PRECISION allows us. */
20082 prec
= c_string_width (SDATA (elt
) + last_offset
,
20083 offset
- last_offset
, precision
- n
,
20086 switch (mode_line_target
)
20088 case MODE_LINE_NOPROP
:
20089 case MODE_LINE_TITLE
:
20090 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20092 case MODE_LINE_STRING
:
20094 ptrdiff_t bytepos
= last_offset
;
20095 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20096 ptrdiff_t endpos
= (precision
<= 0
20097 ? string_byte_to_char (elt
, offset
)
20098 : charpos
+ nchars
);
20100 n
+= store_mode_line_string (NULL
,
20101 Fsubstring (elt
, make_number (charpos
),
20102 make_number (endpos
)),
20106 case MODE_LINE_DISPLAY
:
20108 ptrdiff_t bytepos
= last_offset
;
20109 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20111 if (precision
<= 0)
20112 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20113 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20115 STRING_MULTIBYTE (elt
));
20120 else /* c == '%' */
20122 ptrdiff_t percent_position
= offset
;
20124 /* Get the specified minimum width. Zero means
20127 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20128 field
= field
* 10 + c
- '0';
20130 /* Don't pad beyond the total padding allowed. */
20131 if (field_width
- n
> 0 && field
> field_width
- n
)
20132 field
= field_width
- n
;
20134 /* Note that either PRECISION <= 0 or N < PRECISION. */
20135 prec
= precision
- n
;
20138 n
+= display_mode_element (it
, depth
, field
, prec
,
20139 Vglobal_mode_string
, props
,
20144 ptrdiff_t bytepos
, charpos
;
20146 Lisp_Object string
;
20148 bytepos
= percent_position
;
20149 charpos
= (STRING_MULTIBYTE (elt
)
20150 ? string_byte_to_char (elt
, bytepos
)
20152 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20153 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20155 switch (mode_line_target
)
20157 case MODE_LINE_NOPROP
:
20158 case MODE_LINE_TITLE
:
20159 n
+= store_mode_line_noprop (spec
, field
, prec
);
20161 case MODE_LINE_STRING
:
20163 Lisp_Object tem
= build_string (spec
);
20164 props
= Ftext_properties_at (make_number (charpos
), elt
);
20165 /* Should only keep face property in props */
20166 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20169 case MODE_LINE_DISPLAY
:
20171 int nglyphs_before
, nwritten
;
20173 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20174 nwritten
= display_string (spec
, string
, elt
,
20179 /* Assign to the glyphs written above the
20180 string where the `%x' came from, position
20184 struct glyph
*glyph
20185 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20189 for (i
= 0; i
< nwritten
; ++i
)
20191 glyph
[i
].object
= elt
;
20192 glyph
[i
].charpos
= charpos
;
20209 /* A symbol: process the value of the symbol recursively
20210 as if it appeared here directly. Avoid error if symbol void.
20211 Special case: if value of symbol is a string, output the string
20214 register Lisp_Object tem
;
20216 /* If the variable is not marked as risky to set
20217 then its contents are risky to use. */
20218 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20221 tem
= Fboundp (elt
);
20224 tem
= Fsymbol_value (elt
);
20225 /* If value is a string, output that string literally:
20226 don't check for % within it. */
20230 if (!EQ (tem
, elt
))
20232 /* Give up right away for nil or t. */
20242 register Lisp_Object car
, tem
;
20244 /* A cons cell: five distinct cases.
20245 If first element is :eval or :propertize, do something special.
20246 If first element is a string or a cons, process all the elements
20247 and effectively concatenate them.
20248 If first element is a negative number, truncate displaying cdr to
20249 at most that many characters. If positive, pad (with spaces)
20250 to at least that many characters.
20251 If first element is a symbol, process the cadr or caddr recursively
20252 according to whether the symbol's value is non-nil or nil. */
20254 if (EQ (car
, QCeval
))
20256 /* An element of the form (:eval FORM) means evaluate FORM
20257 and use the result as mode line elements. */
20262 if (CONSP (XCDR (elt
)))
20265 spec
= safe_eval (XCAR (XCDR (elt
)));
20266 n
+= display_mode_element (it
, depth
, field_width
- n
,
20267 precision
- n
, spec
, props
,
20271 else if (EQ (car
, QCpropertize
))
20273 /* An element of the form (:propertize ELT PROPS...)
20274 means display ELT but applying properties PROPS. */
20279 if (CONSP (XCDR (elt
)))
20280 n
+= display_mode_element (it
, depth
, field_width
- n
,
20281 precision
- n
, XCAR (XCDR (elt
)),
20282 XCDR (XCDR (elt
)), risky
);
20284 else if (SYMBOLP (car
))
20286 tem
= Fboundp (car
);
20290 /* elt is now the cdr, and we know it is a cons cell.
20291 Use its car if CAR has a non-nil value. */
20294 tem
= Fsymbol_value (car
);
20301 /* Symbol's value is nil (or symbol is unbound)
20302 Get the cddr of the original list
20303 and if possible find the caddr and use that. */
20307 else if (!CONSP (elt
))
20312 else if (INTEGERP (car
))
20314 register int lim
= XINT (car
);
20318 /* Negative int means reduce maximum width. */
20319 if (precision
<= 0)
20322 precision
= min (precision
, -lim
);
20326 /* Padding specified. Don't let it be more than
20327 current maximum. */
20329 lim
= min (precision
, lim
);
20331 /* If that's more padding than already wanted, queue it.
20332 But don't reduce padding already specified even if
20333 that is beyond the current truncation point. */
20334 field_width
= max (lim
, field_width
);
20338 else if (STRINGP (car
) || CONSP (car
))
20340 Lisp_Object halftail
= elt
;
20344 && (precision
<= 0 || n
< precision
))
20346 n
+= display_mode_element (it
, depth
,
20347 /* Do padding only after the last
20348 element in the list. */
20349 (! CONSP (XCDR (elt
))
20352 precision
- n
, XCAR (elt
),
20356 if ((len
& 1) == 0)
20357 halftail
= XCDR (halftail
);
20358 /* Check for cycle. */
20359 if (EQ (halftail
, elt
))
20368 elt
= build_string ("*invalid*");
20372 /* Pad to FIELD_WIDTH. */
20373 if (field_width
> 0 && n
< field_width
)
20375 switch (mode_line_target
)
20377 case MODE_LINE_NOPROP
:
20378 case MODE_LINE_TITLE
:
20379 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20381 case MODE_LINE_STRING
:
20382 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20384 case MODE_LINE_DISPLAY
:
20385 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20394 /* Store a mode-line string element in mode_line_string_list.
20396 If STRING is non-null, display that C string. Otherwise, the Lisp
20397 string LISP_STRING is displayed.
20399 FIELD_WIDTH is the minimum number of output glyphs to produce.
20400 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20401 with spaces. FIELD_WIDTH <= 0 means don't pad.
20403 PRECISION is the maximum number of characters to output from
20404 STRING. PRECISION <= 0 means don't truncate the string.
20406 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20407 properties to the string.
20409 PROPS are the properties to add to the string.
20410 The mode_line_string_face face property is always added to the string.
20414 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20415 int field_width
, int precision
, Lisp_Object props
)
20420 if (string
!= NULL
)
20422 len
= strlen (string
);
20423 if (precision
> 0 && len
> precision
)
20425 lisp_string
= make_string (string
, len
);
20427 props
= mode_line_string_face_prop
;
20428 else if (!NILP (mode_line_string_face
))
20430 Lisp_Object face
= Fplist_get (props
, Qface
);
20431 props
= Fcopy_sequence (props
);
20433 face
= mode_line_string_face
;
20435 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20436 props
= Fplist_put (props
, Qface
, face
);
20438 Fadd_text_properties (make_number (0), make_number (len
),
20439 props
, lisp_string
);
20443 len
= XFASTINT (Flength (lisp_string
));
20444 if (precision
> 0 && len
> precision
)
20447 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20450 if (!NILP (mode_line_string_face
))
20454 props
= Ftext_properties_at (make_number (0), lisp_string
);
20455 face
= Fplist_get (props
, Qface
);
20457 face
= mode_line_string_face
;
20459 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20460 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20462 lisp_string
= Fcopy_sequence (lisp_string
);
20465 Fadd_text_properties (make_number (0), make_number (len
),
20466 props
, lisp_string
);
20471 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20475 if (field_width
> len
)
20477 field_width
-= len
;
20478 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20480 Fadd_text_properties (make_number (0), make_number (field_width
),
20481 props
, lisp_string
);
20482 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20490 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20492 doc
: /* Format a string out of a mode line format specification.
20493 First arg FORMAT specifies the mode line format (see `mode-line-format'
20494 for details) to use.
20496 By default, the format is evaluated for the currently selected window.
20498 Optional second arg FACE specifies the face property to put on all
20499 characters for which no face is specified. The value nil means the
20500 default face. The value t means whatever face the window's mode line
20501 currently uses (either `mode-line' or `mode-line-inactive',
20502 depending on whether the window is the selected window or not).
20503 An integer value means the value string has no text
20506 Optional third and fourth args WINDOW and BUFFER specify the window
20507 and buffer to use as the context for the formatting (defaults
20508 are the selected window and the WINDOW's buffer). */)
20509 (Lisp_Object format
, Lisp_Object face
,
20510 Lisp_Object window
, Lisp_Object buffer
)
20515 struct buffer
*old_buffer
= NULL
;
20517 int no_props
= INTEGERP (face
);
20518 ptrdiff_t count
= SPECPDL_INDEX ();
20520 int string_start
= 0;
20523 window
= selected_window
;
20524 CHECK_WINDOW (window
);
20525 w
= XWINDOW (window
);
20528 buffer
= w
->buffer
;
20529 CHECK_BUFFER (buffer
);
20531 /* Make formatting the modeline a non-op when noninteractive, otherwise
20532 there will be problems later caused by a partially initialized frame. */
20533 if (NILP (format
) || noninteractive
)
20534 return empty_unibyte_string
;
20539 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20540 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20541 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20542 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20543 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20544 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20545 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20548 if (XBUFFER (buffer
) != current_buffer
)
20549 old_buffer
= current_buffer
;
20551 /* Save things including mode_line_proptrans_alist,
20552 and set that to nil so that we don't alter the outer value. */
20553 record_unwind_protect (unwind_format_mode_line
,
20554 format_mode_line_unwind_data
20555 (old_buffer
, selected_window
, 1));
20556 mode_line_proptrans_alist
= Qnil
;
20558 Fselect_window (window
, Qt
);
20560 set_buffer_internal_1 (XBUFFER (buffer
));
20562 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20566 mode_line_target
= MODE_LINE_NOPROP
;
20567 mode_line_string_face_prop
= Qnil
;
20568 mode_line_string_list
= Qnil
;
20569 string_start
= MODE_LINE_NOPROP_LEN (0);
20573 mode_line_target
= MODE_LINE_STRING
;
20574 mode_line_string_list
= Qnil
;
20575 mode_line_string_face
= face
;
20576 mode_line_string_face_prop
20577 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20580 push_kboard (FRAME_KBOARD (it
.f
));
20581 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20586 len
= MODE_LINE_NOPROP_LEN (string_start
);
20587 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20591 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20592 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20593 empty_unibyte_string
);
20596 unbind_to (count
, Qnil
);
20600 /* Write a null-terminated, right justified decimal representation of
20601 the positive integer D to BUF using a minimal field width WIDTH. */
20604 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20606 register char *p
= buf
;
20614 *p
++ = d
% 10 + '0';
20619 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20630 /* Write a null-terminated, right justified decimal and "human
20631 readable" representation of the nonnegative integer D to BUF using
20632 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20634 static const char power_letter
[] =
20648 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20650 /* We aim to represent the nonnegative integer D as
20651 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20652 ptrdiff_t quotient
= d
;
20654 /* -1 means: do not use TENTHS. */
20658 /* Length of QUOTIENT.TENTHS as a string. */
20664 if (1000 <= quotient
)
20666 /* Scale to the appropriate EXPONENT. */
20669 remainder
= quotient
% 1000;
20673 while (1000 <= quotient
);
20675 /* Round to nearest and decide whether to use TENTHS or not. */
20678 tenths
= remainder
/ 100;
20679 if (50 <= remainder
% 100)
20686 if (quotient
== 10)
20694 if (500 <= remainder
)
20696 if (quotient
< 999)
20707 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
20708 if (tenths
== -1 && quotient
<= 99)
20715 p
= psuffix
= buf
+ max (width
, length
);
20717 /* Print EXPONENT. */
20718 *psuffix
++ = power_letter
[exponent
];
20721 /* Print TENTHS. */
20724 *--p
= '0' + tenths
;
20728 /* Print QUOTIENT. */
20731 int digit
= quotient
% 10;
20732 *--p
= '0' + digit
;
20734 while ((quotient
/= 10) != 0);
20736 /* Print leading spaces. */
20741 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
20742 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
20743 type of CODING_SYSTEM. Return updated pointer into BUF. */
20745 static unsigned char invalid_eol_type
[] = "(*invalid*)";
20748 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
20751 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
20752 const unsigned char *eol_str
;
20754 /* The EOL conversion we are using. */
20755 Lisp_Object eoltype
;
20757 val
= CODING_SYSTEM_SPEC (coding_system
);
20760 if (!VECTORP (val
)) /* Not yet decided. */
20765 eoltype
= eol_mnemonic_undecided
;
20766 /* Don't mention EOL conversion if it isn't decided. */
20771 Lisp_Object eolvalue
;
20773 attrs
= AREF (val
, 0);
20774 eolvalue
= AREF (val
, 2);
20777 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
20781 /* The EOL conversion that is normal on this system. */
20783 if (NILP (eolvalue
)) /* Not yet decided. */
20784 eoltype
= eol_mnemonic_undecided
;
20785 else if (VECTORP (eolvalue
)) /* Not yet decided. */
20786 eoltype
= eol_mnemonic_undecided
;
20787 else /* eolvalue is Qunix, Qdos, or Qmac. */
20788 eoltype
= (EQ (eolvalue
, Qunix
)
20789 ? eol_mnemonic_unix
20790 : (EQ (eolvalue
, Qdos
) == 1
20791 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
20797 /* Mention the EOL conversion if it is not the usual one. */
20798 if (STRINGP (eoltype
))
20800 eol_str
= SDATA (eoltype
);
20801 eol_str_len
= SBYTES (eoltype
);
20803 else if (CHARACTERP (eoltype
))
20805 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
20806 int c
= XFASTINT (eoltype
);
20807 eol_str_len
= CHAR_STRING (c
, tmp
);
20812 eol_str
= invalid_eol_type
;
20813 eol_str_len
= sizeof (invalid_eol_type
) - 1;
20815 memcpy (buf
, eol_str
, eol_str_len
);
20816 buf
+= eol_str_len
;
20822 /* Return a string for the output of a mode line %-spec for window W,
20823 generated by character C. FIELD_WIDTH > 0 means pad the string
20824 returned with spaces to that value. Return a Lisp string in
20825 *STRING if the resulting string is taken from that Lisp string.
20827 Note we operate on the current buffer for most purposes,
20828 the exception being w->base_line_pos. */
20830 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
20832 static const char *
20833 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
20834 Lisp_Object
*string
)
20837 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20838 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
20839 struct buffer
*b
= current_buffer
;
20847 if (!NILP (BVAR (b
, read_only
)))
20849 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20854 /* This differs from %* only for a modified read-only buffer. */
20855 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20857 if (!NILP (BVAR (b
, read_only
)))
20862 /* This differs from %* in ignoring read-only-ness. */
20863 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20875 if (command_loop_level
> 5)
20877 p
= decode_mode_spec_buf
;
20878 for (i
= 0; i
< command_loop_level
; i
++)
20881 return decode_mode_spec_buf
;
20889 if (command_loop_level
> 5)
20891 p
= decode_mode_spec_buf
;
20892 for (i
= 0; i
< command_loop_level
; i
++)
20895 return decode_mode_spec_buf
;
20902 /* Let lots_of_dashes be a string of infinite length. */
20903 if (mode_line_target
== MODE_LINE_NOPROP
||
20904 mode_line_target
== MODE_LINE_STRING
)
20906 if (field_width
<= 0
20907 || field_width
> sizeof (lots_of_dashes
))
20909 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
20910 decode_mode_spec_buf
[i
] = '-';
20911 decode_mode_spec_buf
[i
] = '\0';
20912 return decode_mode_spec_buf
;
20915 return lots_of_dashes
;
20919 obj
= BVAR (b
, name
);
20923 /* %c and %l are ignored in `frame-title-format'.
20924 (In redisplay_internal, the frame title is drawn _before_ the
20925 windows are updated, so the stuff which depends on actual
20926 window contents (such as %l) may fail to render properly, or
20927 even crash emacs.) */
20928 if (mode_line_target
== MODE_LINE_TITLE
)
20932 ptrdiff_t col
= current_column ();
20933 w
->column_number_displayed
= make_number (col
);
20934 pint2str (decode_mode_spec_buf
, field_width
, col
);
20935 return decode_mode_spec_buf
;
20939 #ifndef SYSTEM_MALLOC
20941 if (NILP (Vmemory_full
))
20944 return "!MEM FULL! ";
20951 /* %F displays the frame name. */
20952 if (!NILP (f
->title
))
20953 return SSDATA (f
->title
);
20954 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
20955 return SSDATA (f
->name
);
20959 obj
= BVAR (b
, filename
);
20964 ptrdiff_t size
= ZV
- BEGV
;
20965 pint2str (decode_mode_spec_buf
, field_width
, size
);
20966 return decode_mode_spec_buf
;
20971 ptrdiff_t size
= ZV
- BEGV
;
20972 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
20973 return decode_mode_spec_buf
;
20978 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
20979 ptrdiff_t topline
, nlines
, height
;
20982 /* %c and %l are ignored in `frame-title-format'. */
20983 if (mode_line_target
== MODE_LINE_TITLE
)
20986 startpos
= XMARKER (w
->start
)->charpos
;
20987 startpos_byte
= marker_byte_position (w
->start
);
20988 height
= WINDOW_TOTAL_LINES (w
);
20990 /* If we decided that this buffer isn't suitable for line numbers,
20991 don't forget that too fast. */
20992 if (EQ (w
->base_line_pos
, w
->buffer
))
20994 /* But do forget it, if the window shows a different buffer now. */
20995 else if (BUFFERP (w
->base_line_pos
))
20996 w
->base_line_pos
= Qnil
;
20998 /* If the buffer is very big, don't waste time. */
20999 if (INTEGERP (Vline_number_display_limit
)
21000 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21002 w
->base_line_pos
= Qnil
;
21003 w
->base_line_number
= Qnil
;
21007 if (INTEGERP (w
->base_line_number
)
21008 && INTEGERP (w
->base_line_pos
)
21009 && XFASTINT (w
->base_line_pos
) <= startpos
)
21011 line
= XFASTINT (w
->base_line_number
);
21012 linepos
= XFASTINT (w
->base_line_pos
);
21013 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21018 linepos
= BUF_BEGV (b
);
21019 linepos_byte
= BUF_BEGV_BYTE (b
);
21022 /* Count lines from base line to window start position. */
21023 nlines
= display_count_lines (linepos_byte
,
21027 topline
= nlines
+ line
;
21029 /* Determine a new base line, if the old one is too close
21030 or too far away, or if we did not have one.
21031 "Too close" means it's plausible a scroll-down would
21032 go back past it. */
21033 if (startpos
== BUF_BEGV (b
))
21035 w
->base_line_number
= make_number (topline
);
21036 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21038 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21039 || linepos
== BUF_BEGV (b
))
21041 ptrdiff_t limit
= BUF_BEGV (b
);
21042 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21043 ptrdiff_t position
;
21044 ptrdiff_t distance
=
21045 (height
* 2 + 30) * line_number_display_limit_width
;
21047 if (startpos
- distance
> limit
)
21049 limit
= startpos
- distance
;
21050 limit_byte
= CHAR_TO_BYTE (limit
);
21053 nlines
= display_count_lines (startpos_byte
,
21055 - (height
* 2 + 30),
21057 /* If we couldn't find the lines we wanted within
21058 line_number_display_limit_width chars per line,
21059 give up on line numbers for this window. */
21060 if (position
== limit_byte
&& limit
== startpos
- distance
)
21062 w
->base_line_pos
= w
->buffer
;
21063 w
->base_line_number
= Qnil
;
21067 w
->base_line_number
= make_number (topline
- nlines
);
21068 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21071 /* Now count lines from the start pos to point. */
21072 nlines
= display_count_lines (startpos_byte
,
21073 PT_BYTE
, PT
, &junk
);
21075 /* Record that we did display the line number. */
21076 line_number_displayed
= 1;
21078 /* Make the string to show. */
21079 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21080 return decode_mode_spec_buf
;
21083 char* p
= decode_mode_spec_buf
;
21084 int pad
= field_width
- 2;
21090 return decode_mode_spec_buf
;
21096 obj
= BVAR (b
, mode_name
);
21100 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21106 ptrdiff_t pos
= marker_position (w
->start
);
21107 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21109 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21111 if (pos
<= BUF_BEGV (b
))
21116 else if (pos
<= BUF_BEGV (b
))
21120 if (total
> 1000000)
21121 /* Do it differently for a large value, to avoid overflow. */
21122 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21124 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21125 /* We can't normally display a 3-digit number,
21126 so get us a 2-digit number that is close. */
21129 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21130 return decode_mode_spec_buf
;
21134 /* Display percentage of size above the bottom of the screen. */
21137 ptrdiff_t toppos
= marker_position (w
->start
);
21138 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21139 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21141 if (botpos
>= BUF_ZV (b
))
21143 if (toppos
<= BUF_BEGV (b
))
21150 if (total
> 1000000)
21151 /* Do it differently for a large value, to avoid overflow. */
21152 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21154 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21155 /* We can't normally display a 3-digit number,
21156 so get us a 2-digit number that is close. */
21159 if (toppos
<= BUF_BEGV (b
))
21160 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21162 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21163 return decode_mode_spec_buf
;
21168 /* status of process */
21169 obj
= Fget_buffer_process (Fcurrent_buffer ());
21171 return "no process";
21173 obj
= Fsymbol_name (Fprocess_status (obj
));
21179 ptrdiff_t count
= inhibit_garbage_collection ();
21180 Lisp_Object val
= call1 (intern ("file-remote-p"),
21181 BVAR (current_buffer
, directory
));
21182 unbind_to (count
, Qnil
);
21190 case 't': /* indicate TEXT or BINARY */
21194 /* coding-system (not including end-of-line format) */
21196 /* coding-system (including end-of-line type) */
21198 int eol_flag
= (c
== 'Z');
21199 char *p
= decode_mode_spec_buf
;
21201 if (! FRAME_WINDOW_P (f
))
21203 /* No need to mention EOL here--the terminal never needs
21204 to do EOL conversion. */
21205 p
= decode_mode_spec_coding (CODING_ID_NAME
21206 (FRAME_KEYBOARD_CODING (f
)->id
),
21208 p
= decode_mode_spec_coding (CODING_ID_NAME
21209 (FRAME_TERMINAL_CODING (f
)->id
),
21212 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21215 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21216 #ifdef subprocesses
21217 obj
= Fget_buffer_process (Fcurrent_buffer ());
21218 if (PROCESSP (obj
))
21220 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21222 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21225 #endif /* subprocesses */
21228 return decode_mode_spec_buf
;
21235 return SSDATA (obj
);
21242 /* Count up to COUNT lines starting from START_BYTE.
21243 But don't go beyond LIMIT_BYTE.
21244 Return the number of lines thus found (always nonnegative).
21246 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21249 display_count_lines (ptrdiff_t start_byte
,
21250 ptrdiff_t limit_byte
, ptrdiff_t count
,
21251 ptrdiff_t *byte_pos_ptr
)
21253 register unsigned char *cursor
;
21254 unsigned char *base
;
21256 register ptrdiff_t ceiling
;
21257 register unsigned char *ceiling_addr
;
21258 ptrdiff_t orig_count
= count
;
21260 /* If we are not in selective display mode,
21261 check only for newlines. */
21262 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21263 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21267 while (start_byte
< limit_byte
)
21269 ceiling
= BUFFER_CEILING_OF (start_byte
);
21270 ceiling
= min (limit_byte
- 1, ceiling
);
21271 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21272 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21275 if (selective_display
)
21276 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21279 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21282 if (cursor
!= ceiling_addr
)
21286 start_byte
+= cursor
- base
+ 1;
21287 *byte_pos_ptr
= start_byte
;
21291 if (++cursor
== ceiling_addr
)
21297 start_byte
+= cursor
- base
;
21302 while (start_byte
> limit_byte
)
21304 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21305 ceiling
= max (limit_byte
, ceiling
);
21306 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21307 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21310 if (selective_display
)
21311 while (--cursor
!= ceiling_addr
21312 && *cursor
!= '\n' && *cursor
!= 015)
21315 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21318 if (cursor
!= ceiling_addr
)
21322 start_byte
+= cursor
- base
+ 1;
21323 *byte_pos_ptr
= start_byte
;
21324 /* When scanning backwards, we should
21325 not count the newline posterior to which we stop. */
21326 return - orig_count
- 1;
21332 /* Here we add 1 to compensate for the last decrement
21333 of CURSOR, which took it past the valid range. */
21334 start_byte
+= cursor
- base
+ 1;
21338 *byte_pos_ptr
= limit_byte
;
21341 return - orig_count
+ count
;
21342 return orig_count
- count
;
21348 /***********************************************************************
21350 ***********************************************************************/
21352 /* Display a NUL-terminated string, starting with index START.
21354 If STRING is non-null, display that C string. Otherwise, the Lisp
21355 string LISP_STRING is displayed. There's a case that STRING is
21356 non-null and LISP_STRING is not nil. It means STRING is a string
21357 data of LISP_STRING. In that case, we display LISP_STRING while
21358 ignoring its text properties.
21360 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21361 FACE_STRING. Display STRING or LISP_STRING with the face at
21362 FACE_STRING_POS in FACE_STRING:
21364 Display the string in the environment given by IT, but use the
21365 standard display table, temporarily.
21367 FIELD_WIDTH is the minimum number of output glyphs to produce.
21368 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21369 with spaces. If STRING has more characters, more than FIELD_WIDTH
21370 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21372 PRECISION is the maximum number of characters to output from
21373 STRING. PRECISION < 0 means don't truncate the string.
21375 This is roughly equivalent to printf format specifiers:
21377 FIELD_WIDTH PRECISION PRINTF
21378 ----------------------------------------
21384 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21385 display them, and < 0 means obey the current buffer's value of
21386 enable_multibyte_characters.
21388 Value is the number of columns displayed. */
21391 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21392 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21393 int field_width
, int precision
, int max_x
, int multibyte
)
21395 int hpos_at_start
= it
->hpos
;
21396 int saved_face_id
= it
->face_id
;
21397 struct glyph_row
*row
= it
->glyph_row
;
21398 ptrdiff_t it_charpos
;
21400 /* Initialize the iterator IT for iteration over STRING beginning
21401 with index START. */
21402 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21403 precision
, field_width
, multibyte
);
21404 if (string
&& STRINGP (lisp_string
))
21405 /* LISP_STRING is the one returned by decode_mode_spec. We should
21406 ignore its text properties. */
21407 it
->stop_charpos
= it
->end_charpos
;
21409 /* If displaying STRING, set up the face of the iterator from
21410 FACE_STRING, if that's given. */
21411 if (STRINGP (face_string
))
21417 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21418 0, it
->region_beg_charpos
,
21419 it
->region_end_charpos
,
21420 &endptr
, it
->base_face_id
, 0);
21421 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21422 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21425 /* Set max_x to the maximum allowed X position. Don't let it go
21426 beyond the right edge of the window. */
21428 max_x
= it
->last_visible_x
;
21430 max_x
= min (max_x
, it
->last_visible_x
);
21432 /* Skip over display elements that are not visible. because IT->w is
21434 if (it
->current_x
< it
->first_visible_x
)
21435 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21436 MOVE_TO_POS
| MOVE_TO_X
);
21438 row
->ascent
= it
->max_ascent
;
21439 row
->height
= it
->max_ascent
+ it
->max_descent
;
21440 row
->phys_ascent
= it
->max_phys_ascent
;
21441 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21442 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21444 if (STRINGP (it
->string
))
21445 it_charpos
= IT_STRING_CHARPOS (*it
);
21447 it_charpos
= IT_CHARPOS (*it
);
21449 /* This condition is for the case that we are called with current_x
21450 past last_visible_x. */
21451 while (it
->current_x
< max_x
)
21453 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21455 /* Get the next display element. */
21456 if (!get_next_display_element (it
))
21459 /* Produce glyphs. */
21460 x_before
= it
->current_x
;
21461 n_glyphs_before
= row
->used
[TEXT_AREA
];
21462 PRODUCE_GLYPHS (it
);
21464 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21467 while (i
< nglyphs
)
21469 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21471 if (it
->line_wrap
!= TRUNCATE
21472 && x
+ glyph
->pixel_width
> max_x
)
21474 /* End of continued line or max_x reached. */
21475 if (CHAR_GLYPH_PADDING_P (*glyph
))
21477 /* A wide character is unbreakable. */
21478 if (row
->reversed_p
)
21479 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21480 - n_glyphs_before
);
21481 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21482 it
->current_x
= x_before
;
21486 if (row
->reversed_p
)
21487 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21488 - (n_glyphs_before
+ i
));
21489 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21494 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21496 /* Glyph is at least partially visible. */
21498 if (x
< it
->first_visible_x
)
21499 row
->x
= x
- it
->first_visible_x
;
21503 /* Glyph is off the left margin of the display area.
21504 Should not happen. */
21508 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21509 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21510 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21511 row
->phys_height
= max (row
->phys_height
,
21512 it
->max_phys_ascent
+ it
->max_phys_descent
);
21513 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21514 it
->max_extra_line_spacing
);
21515 x
+= glyph
->pixel_width
;
21519 /* Stop if max_x reached. */
21523 /* Stop at line ends. */
21524 if (ITERATOR_AT_END_OF_LINE_P (it
))
21526 it
->continuation_lines_width
= 0;
21530 set_iterator_to_next (it
, 1);
21531 if (STRINGP (it
->string
))
21532 it_charpos
= IT_STRING_CHARPOS (*it
);
21534 it_charpos
= IT_CHARPOS (*it
);
21536 /* Stop if truncating at the right edge. */
21537 if (it
->line_wrap
== TRUNCATE
21538 && it
->current_x
>= it
->last_visible_x
)
21540 /* Add truncation mark, but don't do it if the line is
21541 truncated at a padding space. */
21542 if (it_charpos
< it
->string_nchars
)
21544 if (!FRAME_WINDOW_P (it
->f
))
21548 if (it
->current_x
> it
->last_visible_x
)
21550 if (!row
->reversed_p
)
21552 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21553 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21558 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21559 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21561 unproduce_glyphs (it
, ii
+ 1);
21562 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21564 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21566 row
->used
[TEXT_AREA
] = ii
;
21567 produce_special_glyphs (it
, IT_TRUNCATION
);
21570 produce_special_glyphs (it
, IT_TRUNCATION
);
21572 row
->truncated_on_right_p
= 1;
21578 /* Maybe insert a truncation at the left. */
21579 if (it
->first_visible_x
21582 if (!FRAME_WINDOW_P (it
->f
))
21583 insert_left_trunc_glyphs (it
);
21584 row
->truncated_on_left_p
= 1;
21587 it
->face_id
= saved_face_id
;
21589 /* Value is number of columns displayed. */
21590 return it
->hpos
- hpos_at_start
;
21595 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21596 appears as an element of LIST or as the car of an element of LIST.
21597 If PROPVAL is a list, compare each element against LIST in that
21598 way, and return 1/2 if any element of PROPVAL is found in LIST.
21599 Otherwise return 0. This function cannot quit.
21600 The return value is 2 if the text is invisible but with an ellipsis
21601 and 1 if it's invisible and without an ellipsis. */
21604 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21606 register Lisp_Object tail
, proptail
;
21608 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21610 register Lisp_Object tem
;
21612 if (EQ (propval
, tem
))
21614 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21615 return NILP (XCDR (tem
)) ? 1 : 2;
21618 if (CONSP (propval
))
21620 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21622 Lisp_Object propelt
;
21623 propelt
= XCAR (proptail
);
21624 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21626 register Lisp_Object tem
;
21628 if (EQ (propelt
, tem
))
21630 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21631 return NILP (XCDR (tem
)) ? 1 : 2;
21639 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21640 doc
: /* Non-nil if the property makes the text invisible.
21641 POS-OR-PROP can be a marker or number, in which case it is taken to be
21642 a position in the current buffer and the value of the `invisible' property
21643 is checked; or it can be some other value, which is then presumed to be the
21644 value of the `invisible' property of the text of interest.
21645 The non-nil value returned can be t for truly invisible text or something
21646 else if the text is replaced by an ellipsis. */)
21647 (Lisp_Object pos_or_prop
)
21650 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21651 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21653 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21654 return (invis
== 0 ? Qnil
21656 : make_number (invis
));
21659 /* Calculate a width or height in pixels from a specification using
21660 the following elements:
21663 NUM - a (fractional) multiple of the default font width/height
21664 (NUM) - specifies exactly NUM pixels
21665 UNIT - a fixed number of pixels, see below.
21666 ELEMENT - size of a display element in pixels, see below.
21667 (NUM . SPEC) - equals NUM * SPEC
21668 (+ SPEC SPEC ...) - add pixel values
21669 (- SPEC SPEC ...) - subtract pixel values
21670 (- SPEC) - negate pixel value
21673 INT or FLOAT - a number constant
21674 SYMBOL - use symbol's (buffer local) variable binding.
21677 in - pixels per inch *)
21678 mm - pixels per 1/1000 meter *)
21679 cm - pixels per 1/100 meter *)
21680 width - width of current font in pixels.
21681 height - height of current font in pixels.
21683 *) using the ratio(s) defined in display-pixels-per-inch.
21687 left-fringe - left fringe width in pixels
21688 right-fringe - right fringe width in pixels
21690 left-margin - left margin width in pixels
21691 right-margin - right margin width in pixels
21693 scroll-bar - scroll-bar area width in pixels
21697 Pixels corresponding to 5 inches:
21700 Total width of non-text areas on left side of window (if scroll-bar is on left):
21701 '(space :width (+ left-fringe left-margin scroll-bar))
21703 Align to first text column (in header line):
21704 '(space :align-to 0)
21706 Align to middle of text area minus half the width of variable `my-image'
21707 containing a loaded image:
21708 '(space :align-to (0.5 . (- text my-image)))
21710 Width of left margin minus width of 1 character in the default font:
21711 '(space :width (- left-margin 1))
21713 Width of left margin minus width of 2 characters in the current font:
21714 '(space :width (- left-margin (2 . width)))
21716 Center 1 character over left-margin (in header line):
21717 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
21719 Different ways to express width of left fringe plus left margin minus one pixel:
21720 '(space :width (- (+ left-fringe left-margin) (1)))
21721 '(space :width (+ left-fringe left-margin (- (1))))
21722 '(space :width (+ left-fringe left-margin (-1)))
21726 #define NUMVAL(X) \
21727 ((INTEGERP (X) || FLOATP (X)) \
21732 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
21733 struct font
*font
, int width_p
, int *align_to
)
21737 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
21738 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
21741 return OK_PIXELS (0);
21743 xassert (FRAME_LIVE_P (it
->f
));
21745 if (SYMBOLP (prop
))
21747 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
21749 char *unit
= SSDATA (SYMBOL_NAME (prop
));
21751 if (unit
[0] == 'i' && unit
[1] == 'n')
21753 else if (unit
[0] == 'm' && unit
[1] == 'm')
21755 else if (unit
[0] == 'c' && unit
[1] == 'm')
21762 #ifdef HAVE_WINDOW_SYSTEM
21763 if (FRAME_WINDOW_P (it
->f
)
21765 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
21766 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
21768 return OK_PIXELS (ppi
/ pixels
);
21771 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
21772 || (CONSP (Vdisplay_pixels_per_inch
)
21774 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
21775 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
21777 return OK_PIXELS (ppi
/ pixels
);
21783 #ifdef HAVE_WINDOW_SYSTEM
21784 if (EQ (prop
, Qheight
))
21785 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
21786 if (EQ (prop
, Qwidth
))
21787 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
21789 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
21790 return OK_PIXELS (1);
21793 if (EQ (prop
, Qtext
))
21794 return OK_PIXELS (width_p
21795 ? window_box_width (it
->w
, TEXT_AREA
)
21796 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
21798 if (align_to
&& *align_to
< 0)
21801 if (EQ (prop
, Qleft
))
21802 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
21803 if (EQ (prop
, Qright
))
21804 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
21805 if (EQ (prop
, Qcenter
))
21806 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
21807 + window_box_width (it
->w
, TEXT_AREA
) / 2);
21808 if (EQ (prop
, Qleft_fringe
))
21809 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21810 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
21811 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
21812 if (EQ (prop
, Qright_fringe
))
21813 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21814 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21815 : window_box_right_offset (it
->w
, TEXT_AREA
));
21816 if (EQ (prop
, Qleft_margin
))
21817 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
21818 if (EQ (prop
, Qright_margin
))
21819 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
21820 if (EQ (prop
, Qscroll_bar
))
21821 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
21823 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21824 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21825 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21830 if (EQ (prop
, Qleft_fringe
))
21831 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
21832 if (EQ (prop
, Qright_fringe
))
21833 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
21834 if (EQ (prop
, Qleft_margin
))
21835 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
21836 if (EQ (prop
, Qright_margin
))
21837 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
21838 if (EQ (prop
, Qscroll_bar
))
21839 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
21842 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
21845 if (INTEGERP (prop
) || FLOATP (prop
))
21847 int base_unit
= (width_p
21848 ? FRAME_COLUMN_WIDTH (it
->f
)
21849 : FRAME_LINE_HEIGHT (it
->f
));
21850 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21855 Lisp_Object car
= XCAR (prop
);
21856 Lisp_Object cdr
= XCDR (prop
);
21860 #ifdef HAVE_WINDOW_SYSTEM
21861 if (FRAME_WINDOW_P (it
->f
)
21862 && valid_image_p (prop
))
21864 ptrdiff_t id
= lookup_image (it
->f
, prop
);
21865 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21867 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21870 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21876 while (CONSP (cdr
))
21878 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
21879 font
, width_p
, align_to
))
21882 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
21887 if (EQ (car
, Qminus
))
21889 return OK_PIXELS (pixels
);
21892 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
21895 if (INTEGERP (car
) || FLOATP (car
))
21898 pixels
= XFLOATINT (car
);
21900 return OK_PIXELS (pixels
);
21901 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
21902 font
, width_p
, align_to
))
21903 return OK_PIXELS (pixels
* fact
);
21914 /***********************************************************************
21916 ***********************************************************************/
21918 #ifdef HAVE_WINDOW_SYSTEM
21923 dump_glyph_string (struct glyph_string
*s
)
21925 fprintf (stderr
, "glyph string\n");
21926 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
21927 s
->x
, s
->y
, s
->width
, s
->height
);
21928 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
21929 fprintf (stderr
, " hl = %d\n", s
->hl
);
21930 fprintf (stderr
, " left overhang = %d, right = %d\n",
21931 s
->left_overhang
, s
->right_overhang
);
21932 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
21933 fprintf (stderr
, " extends to end of line = %d\n",
21934 s
->extends_to_end_of_line_p
);
21935 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
21936 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
21939 #endif /* GLYPH_DEBUG */
21941 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
21942 of XChar2b structures for S; it can't be allocated in
21943 init_glyph_string because it must be allocated via `alloca'. W
21944 is the window on which S is drawn. ROW and AREA are the glyph row
21945 and area within the row from which S is constructed. START is the
21946 index of the first glyph structure covered by S. HL is a
21947 face-override for drawing S. */
21950 #define OPTIONAL_HDC(hdc) HDC hdc,
21951 #define DECLARE_HDC(hdc) HDC hdc;
21952 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
21953 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
21956 #ifndef OPTIONAL_HDC
21957 #define OPTIONAL_HDC(hdc)
21958 #define DECLARE_HDC(hdc)
21959 #define ALLOCATE_HDC(hdc, f)
21960 #define RELEASE_HDC(hdc, f)
21964 init_glyph_string (struct glyph_string
*s
,
21966 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
21967 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
21969 memset (s
, 0, sizeof *s
);
21971 s
->f
= XFRAME (w
->frame
);
21975 s
->display
= FRAME_X_DISPLAY (s
->f
);
21976 s
->window
= FRAME_X_WINDOW (s
->f
);
21977 s
->char2b
= char2b
;
21981 s
->first_glyph
= row
->glyphs
[area
] + start
;
21982 s
->height
= row
->height
;
21983 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
21984 s
->ybase
= s
->y
+ row
->ascent
;
21988 /* Append the list of glyph strings with head H and tail T to the list
21989 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
21992 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21993 struct glyph_string
*h
, struct glyph_string
*t
)
22007 /* Prepend the list of glyph strings with head H and tail T to the
22008 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22012 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22013 struct glyph_string
*h
, struct glyph_string
*t
)
22027 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22028 Set *HEAD and *TAIL to the resulting list. */
22031 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22032 struct glyph_string
*s
)
22034 s
->next
= s
->prev
= NULL
;
22035 append_glyph_string_lists (head
, tail
, s
, s
);
22039 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22040 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22041 make sure that X resources for the face returned are allocated.
22042 Value is a pointer to a realized face that is ready for display if
22043 DISPLAY_P is non-zero. */
22045 static inline struct face
*
22046 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22047 XChar2b
*char2b
, int display_p
)
22049 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22053 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22055 if (code
!= FONT_INVALID_CODE
)
22056 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22058 STORE_XCHAR2B (char2b
, 0, 0);
22061 /* Make sure X resources of the face are allocated. */
22062 #ifdef HAVE_X_WINDOWS
22066 xassert (face
!= NULL
);
22067 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22074 /* Get face and two-byte form of character glyph GLYPH on frame F.
22075 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22076 a pointer to a realized face that is ready for display. */
22078 static inline struct face
*
22079 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22080 XChar2b
*char2b
, int *two_byte_p
)
22084 xassert (glyph
->type
== CHAR_GLYPH
);
22085 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22094 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22095 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22097 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22099 if (code
!= FONT_INVALID_CODE
)
22100 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22102 STORE_XCHAR2B (char2b
, 0, 0);
22105 /* Make sure X resources of the face are allocated. */
22106 xassert (face
!= NULL
);
22107 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22112 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22113 Return 1 if FONT has a glyph for C, otherwise return 0. */
22116 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22120 if (CHAR_BYTE8_P (c
))
22121 code
= CHAR_TO_BYTE8 (c
);
22123 code
= font
->driver
->encode_char (font
, c
);
22125 if (code
== FONT_INVALID_CODE
)
22127 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22132 /* Fill glyph string S with composition components specified by S->cmp.
22134 BASE_FACE is the base face of the composition.
22135 S->cmp_from is the index of the first component for S.
22137 OVERLAPS non-zero means S should draw the foreground only, and use
22138 its physical height for clipping. See also draw_glyphs.
22140 Value is the index of a component not in S. */
22143 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22147 /* For all glyphs of this composition, starting at the offset
22148 S->cmp_from, until we reach the end of the definition or encounter a
22149 glyph that requires the different face, add it to S. */
22154 s
->for_overlaps
= overlaps
;
22157 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22159 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22161 /* TAB in a composition means display glyphs with padding space
22162 on the left or right. */
22165 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22168 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22175 s
->font
= s
->face
->font
;
22177 else if (s
->face
!= face
)
22185 if (s
->face
== NULL
)
22187 s
->face
= base_face
->ascii_face
;
22188 s
->font
= s
->face
->font
;
22191 /* All glyph strings for the same composition has the same width,
22192 i.e. the width set for the first component of the composition. */
22193 s
->width
= s
->first_glyph
->pixel_width
;
22195 /* If the specified font could not be loaded, use the frame's
22196 default font, but record the fact that we couldn't load it in
22197 the glyph string so that we can draw rectangles for the
22198 characters of the glyph string. */
22199 if (s
->font
== NULL
)
22201 s
->font_not_found_p
= 1;
22202 s
->font
= FRAME_FONT (s
->f
);
22205 /* Adjust base line for subscript/superscript text. */
22206 s
->ybase
+= s
->first_glyph
->voffset
;
22208 /* This glyph string must always be drawn with 16-bit functions. */
22215 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22216 int start
, int end
, int overlaps
)
22218 struct glyph
*glyph
, *last
;
22219 Lisp_Object lgstring
;
22222 s
->for_overlaps
= overlaps
;
22223 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22224 last
= s
->row
->glyphs
[s
->area
] + end
;
22225 s
->cmp_id
= glyph
->u
.cmp
.id
;
22226 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22227 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22228 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22229 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22230 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22232 while (glyph
< last
22233 && glyph
->u
.cmp
.automatic
22234 && glyph
->u
.cmp
.id
== s
->cmp_id
22235 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22236 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22238 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22240 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22241 unsigned code
= LGLYPH_CODE (lglyph
);
22243 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22245 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22246 return glyph
- s
->row
->glyphs
[s
->area
];
22250 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22251 See the comment of fill_glyph_string for arguments.
22252 Value is the index of the first glyph not in S. */
22256 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22257 int start
, int end
, int overlaps
)
22259 struct glyph
*glyph
, *last
;
22262 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22263 s
->for_overlaps
= overlaps
;
22264 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22265 last
= s
->row
->glyphs
[s
->area
] + end
;
22266 voffset
= glyph
->voffset
;
22267 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22268 s
->font
= s
->face
->font
;
22270 s
->width
= glyph
->pixel_width
;
22272 while (glyph
< last
22273 && glyph
->type
== GLYPHLESS_GLYPH
22274 && glyph
->voffset
== voffset
22275 && glyph
->face_id
== face_id
)
22278 s
->width
+= glyph
->pixel_width
;
22281 s
->ybase
+= voffset
;
22282 return glyph
- s
->row
->glyphs
[s
->area
];
22286 /* Fill glyph string S from a sequence of character glyphs.
22288 FACE_ID is the face id of the string. START is the index of the
22289 first glyph to consider, END is the index of the last + 1.
22290 OVERLAPS non-zero means S should draw the foreground only, and use
22291 its physical height for clipping. See also draw_glyphs.
22293 Value is the index of the first glyph not in S. */
22296 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22297 int start
, int end
, int overlaps
)
22299 struct glyph
*glyph
, *last
;
22301 int glyph_not_available_p
;
22303 xassert (s
->f
== XFRAME (s
->w
->frame
));
22304 xassert (s
->nchars
== 0);
22305 xassert (start
>= 0 && end
> start
);
22307 s
->for_overlaps
= overlaps
;
22308 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22309 last
= s
->row
->glyphs
[s
->area
] + end
;
22310 voffset
= glyph
->voffset
;
22311 s
->padding_p
= glyph
->padding_p
;
22312 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22314 while (glyph
< last
22315 && glyph
->type
== CHAR_GLYPH
22316 && glyph
->voffset
== voffset
22317 /* Same face id implies same font, nowadays. */
22318 && glyph
->face_id
== face_id
22319 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22323 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22324 s
->char2b
+ s
->nchars
,
22326 s
->two_byte_p
= two_byte_p
;
22328 xassert (s
->nchars
<= end
- start
);
22329 s
->width
+= glyph
->pixel_width
;
22330 if (glyph
++->padding_p
!= s
->padding_p
)
22334 s
->font
= s
->face
->font
;
22336 /* If the specified font could not be loaded, use the frame's font,
22337 but record the fact that we couldn't load it in
22338 S->font_not_found_p so that we can draw rectangles for the
22339 characters of the glyph string. */
22340 if (s
->font
== NULL
|| glyph_not_available_p
)
22342 s
->font_not_found_p
= 1;
22343 s
->font
= FRAME_FONT (s
->f
);
22346 /* Adjust base line for subscript/superscript text. */
22347 s
->ybase
+= voffset
;
22349 xassert (s
->face
&& s
->face
->gc
);
22350 return glyph
- s
->row
->glyphs
[s
->area
];
22354 /* Fill glyph string S from image glyph S->first_glyph. */
22357 fill_image_glyph_string (struct glyph_string
*s
)
22359 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22360 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22362 s
->slice
= s
->first_glyph
->slice
.img
;
22363 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22364 s
->font
= s
->face
->font
;
22365 s
->width
= s
->first_glyph
->pixel_width
;
22367 /* Adjust base line for subscript/superscript text. */
22368 s
->ybase
+= s
->first_glyph
->voffset
;
22372 /* Fill glyph string S from a sequence of stretch glyphs.
22374 START is the index of the first glyph to consider,
22375 END is the index of the last + 1.
22377 Value is the index of the first glyph not in S. */
22380 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22382 struct glyph
*glyph
, *last
;
22383 int voffset
, face_id
;
22385 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22387 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22388 last
= s
->row
->glyphs
[s
->area
] + end
;
22389 face_id
= glyph
->face_id
;
22390 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22391 s
->font
= s
->face
->font
;
22392 s
->width
= glyph
->pixel_width
;
22394 voffset
= glyph
->voffset
;
22398 && glyph
->type
== STRETCH_GLYPH
22399 && glyph
->voffset
== voffset
22400 && glyph
->face_id
== face_id
);
22402 s
->width
+= glyph
->pixel_width
;
22404 /* Adjust base line for subscript/superscript text. */
22405 s
->ybase
+= voffset
;
22407 /* The case that face->gc == 0 is handled when drawing the glyph
22408 string by calling PREPARE_FACE_FOR_DISPLAY. */
22410 return glyph
- s
->row
->glyphs
[s
->area
];
22413 static struct font_metrics
*
22414 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22416 static struct font_metrics metrics
;
22417 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22419 if (! font
|| code
== FONT_INVALID_CODE
)
22421 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22426 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22427 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22428 assumed to be zero. */
22431 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22433 *left
= *right
= 0;
22435 if (glyph
->type
== CHAR_GLYPH
)
22439 struct font_metrics
*pcm
;
22441 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22442 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22444 if (pcm
->rbearing
> pcm
->width
)
22445 *right
= pcm
->rbearing
- pcm
->width
;
22446 if (pcm
->lbearing
< 0)
22447 *left
= -pcm
->lbearing
;
22450 else if (glyph
->type
== COMPOSITE_GLYPH
)
22452 if (! glyph
->u
.cmp
.automatic
)
22454 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22456 if (cmp
->rbearing
> cmp
->pixel_width
)
22457 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22458 if (cmp
->lbearing
< 0)
22459 *left
= - cmp
->lbearing
;
22463 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22464 struct font_metrics metrics
;
22466 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22467 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22468 if (metrics
.rbearing
> metrics
.width
)
22469 *right
= metrics
.rbearing
- metrics
.width
;
22470 if (metrics
.lbearing
< 0)
22471 *left
= - metrics
.lbearing
;
22477 /* Return the index of the first glyph preceding glyph string S that
22478 is overwritten by S because of S's left overhang. Value is -1
22479 if no glyphs are overwritten. */
22482 left_overwritten (struct glyph_string
*s
)
22486 if (s
->left_overhang
)
22489 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22490 int first
= s
->first_glyph
- glyphs
;
22492 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22493 x
-= glyphs
[i
].pixel_width
;
22504 /* Return the index of the first glyph preceding glyph string S that
22505 is overwriting S because of its right overhang. Value is -1 if no
22506 glyph in front of S overwrites S. */
22509 left_overwriting (struct glyph_string
*s
)
22512 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22513 int first
= s
->first_glyph
- glyphs
;
22517 for (i
= first
- 1; i
>= 0; --i
)
22520 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22523 x
-= glyphs
[i
].pixel_width
;
22530 /* Return the index of the last glyph following glyph string S that is
22531 overwritten by S because of S's right overhang. Value is -1 if
22532 no such glyph is found. */
22535 right_overwritten (struct glyph_string
*s
)
22539 if (s
->right_overhang
)
22542 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22543 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22544 int end
= s
->row
->used
[s
->area
];
22546 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22547 x
+= glyphs
[i
].pixel_width
;
22556 /* Return the index of the last glyph following glyph string S that
22557 overwrites S because of its left overhang. Value is negative
22558 if no such glyph is found. */
22561 right_overwriting (struct glyph_string
*s
)
22564 int end
= s
->row
->used
[s
->area
];
22565 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22566 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22570 for (i
= first
; i
< end
; ++i
)
22573 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22576 x
+= glyphs
[i
].pixel_width
;
22583 /* Set background width of glyph string S. START is the index of the
22584 first glyph following S. LAST_X is the right-most x-position + 1
22585 in the drawing area. */
22588 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22590 /* If the face of this glyph string has to be drawn to the end of
22591 the drawing area, set S->extends_to_end_of_line_p. */
22593 if (start
== s
->row
->used
[s
->area
]
22594 && s
->area
== TEXT_AREA
22595 && ((s
->row
->fill_line_p
22596 && (s
->hl
== DRAW_NORMAL_TEXT
22597 || s
->hl
== DRAW_IMAGE_RAISED
22598 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22599 || s
->hl
== DRAW_MOUSE_FACE
))
22600 s
->extends_to_end_of_line_p
= 1;
22602 /* If S extends its face to the end of the line, set its
22603 background_width to the distance to the right edge of the drawing
22605 if (s
->extends_to_end_of_line_p
)
22606 s
->background_width
= last_x
- s
->x
+ 1;
22608 s
->background_width
= s
->width
;
22612 /* Compute overhangs and x-positions for glyph string S and its
22613 predecessors, or successors. X is the starting x-position for S.
22614 BACKWARD_P non-zero means process predecessors. */
22617 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22623 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22624 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22634 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22635 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22645 /* The following macros are only called from draw_glyphs below.
22646 They reference the following parameters of that function directly:
22647 `w', `row', `area', and `overlap_p'
22648 as well as the following local variables:
22649 `s', `f', and `hdc' (in W32) */
22652 /* On W32, silently add local `hdc' variable to argument list of
22653 init_glyph_string. */
22654 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22655 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22657 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22658 init_glyph_string (s, char2b, w, row, area, start, hl)
22661 /* Add a glyph string for a stretch glyph to the list of strings
22662 between HEAD and TAIL. START is the index of the stretch glyph in
22663 row area AREA of glyph row ROW. END is the index of the last glyph
22664 in that glyph row area. X is the current output position assigned
22665 to the new glyph string constructed. HL overrides that face of the
22666 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22667 is the right-most x-position of the drawing area. */
22669 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
22670 and below -- keep them on one line. */
22671 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22674 s = (struct glyph_string *) alloca (sizeof *s); \
22675 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22676 START = fill_stretch_glyph_string (s, START, END); \
22677 append_glyph_string (&HEAD, &TAIL, s); \
22683 /* Add a glyph string for an image glyph to the list of strings
22684 between HEAD and TAIL. START is the index of the image glyph in
22685 row area AREA of glyph row ROW. END is the index of the last glyph
22686 in that glyph row area. X is the current output position assigned
22687 to the new glyph string constructed. HL overrides that face of the
22688 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22689 is the right-most x-position of the drawing area. */
22691 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22694 s = (struct glyph_string *) alloca (sizeof *s); \
22695 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22696 fill_image_glyph_string (s); \
22697 append_glyph_string (&HEAD, &TAIL, s); \
22704 /* Add a glyph string for a sequence of character glyphs to the list
22705 of strings between HEAD and TAIL. START is the index of the first
22706 glyph in row area AREA of glyph row ROW that is part of the new
22707 glyph string. END is the index of the last glyph in that glyph row
22708 area. X is the current output position assigned to the new glyph
22709 string constructed. HL overrides that face of the glyph; e.g. it
22710 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
22711 right-most x-position of the drawing area. */
22713 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22719 face_id = (row)->glyphs[area][START].face_id; \
22721 s = (struct glyph_string *) alloca (sizeof *s); \
22722 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
22723 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22724 append_glyph_string (&HEAD, &TAIL, s); \
22726 START = fill_glyph_string (s, face_id, START, END, overlaps); \
22731 /* Add a glyph string for a composite sequence to the list of strings
22732 between HEAD and TAIL. START is the index of the first glyph in
22733 row area AREA of glyph row ROW that is part of the new glyph
22734 string. END is the index of the last glyph in that glyph row area.
22735 X is the current output position assigned to the new glyph string
22736 constructed. HL overrides that face of the glyph; e.g. it is
22737 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
22738 x-position of the drawing area. */
22740 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22742 int face_id = (row)->glyphs[area][START].face_id; \
22743 struct face *base_face = FACE_FROM_ID (f, face_id); \
22744 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
22745 struct composition *cmp = composition_table[cmp_id]; \
22747 struct glyph_string *first_s IF_LINT (= NULL); \
22750 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
22752 /* Make glyph_strings for each glyph sequence that is drawable by \
22753 the same face, and append them to HEAD/TAIL. */ \
22754 for (n = 0; n < cmp->glyph_len;) \
22756 s = (struct glyph_string *) alloca (sizeof *s); \
22757 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22758 append_glyph_string (&(HEAD), &(TAIL), s); \
22764 n = fill_composite_glyph_string (s, base_face, overlaps); \
22772 /* Add a glyph string for a glyph-string sequence to the list of strings
22773 between HEAD and TAIL. */
22775 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22779 Lisp_Object gstring; \
22781 face_id = (row)->glyphs[area][START].face_id; \
22782 gstring = (composition_gstring_from_id \
22783 ((row)->glyphs[area][START].u.cmp.id)); \
22784 s = (struct glyph_string *) alloca (sizeof *s); \
22785 char2b = (XChar2b *) alloca ((sizeof *char2b) \
22786 * LGSTRING_GLYPH_LEN (gstring)); \
22787 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22788 append_glyph_string (&(HEAD), &(TAIL), s); \
22790 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
22794 /* Add a glyph string for a sequence of glyphless character's glyphs
22795 to the list of strings between HEAD and TAIL. The meanings of
22796 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
22798 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22803 face_id = (row)->glyphs[area][START].face_id; \
22805 s = (struct glyph_string *) alloca (sizeof *s); \
22806 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22807 append_glyph_string (&HEAD, &TAIL, s); \
22809 START = fill_glyphless_glyph_string (s, face_id, START, END, \
22815 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
22816 of AREA of glyph row ROW on window W between indices START and END.
22817 HL overrides the face for drawing glyph strings, e.g. it is
22818 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
22819 x-positions of the drawing area.
22821 This is an ugly monster macro construct because we must use alloca
22822 to allocate glyph strings (because draw_glyphs can be called
22823 asynchronously). */
22825 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22828 HEAD = TAIL = NULL; \
22829 while (START < END) \
22831 struct glyph *first_glyph = (row)->glyphs[area] + START; \
22832 switch (first_glyph->type) \
22835 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
22839 case COMPOSITE_GLYPH: \
22840 if (first_glyph->u.cmp.automatic) \
22841 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
22844 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
22848 case STRETCH_GLYPH: \
22849 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
22853 case IMAGE_GLYPH: \
22854 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
22858 case GLYPHLESS_GLYPH: \
22859 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22869 set_glyph_string_background_width (s, START, LAST_X); \
22876 /* Draw glyphs between START and END in AREA of ROW on window W,
22877 starting at x-position X. X is relative to AREA in W. HL is a
22878 face-override with the following meaning:
22880 DRAW_NORMAL_TEXT draw normally
22881 DRAW_CURSOR draw in cursor face
22882 DRAW_MOUSE_FACE draw in mouse face.
22883 DRAW_INVERSE_VIDEO draw in mode line face
22884 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
22885 DRAW_IMAGE_RAISED draw an image with a raised relief around it
22887 If OVERLAPS is non-zero, draw only the foreground of characters and
22888 clip to the physical height of ROW. Non-zero value also defines
22889 the overlapping part to be drawn:
22891 OVERLAPS_PRED overlap with preceding rows
22892 OVERLAPS_SUCC overlap with succeeding rows
22893 OVERLAPS_BOTH overlap with both preceding/succeeding rows
22894 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
22896 Value is the x-position reached, relative to AREA of W. */
22899 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
22900 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
22901 enum draw_glyphs_face hl
, int overlaps
)
22903 struct glyph_string
*head
, *tail
;
22904 struct glyph_string
*s
;
22905 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
22906 int i
, j
, x_reached
, last_x
, area_left
= 0;
22907 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22910 ALLOCATE_HDC (hdc
, f
);
22912 /* Let's rather be paranoid than getting a SEGV. */
22913 end
= min (end
, row
->used
[area
]);
22914 start
= max (0, start
);
22915 start
= min (end
, start
);
22917 /* Translate X to frame coordinates. Set last_x to the right
22918 end of the drawing area. */
22919 if (row
->full_width_p
)
22921 /* X is relative to the left edge of W, without scroll bars
22923 area_left
= WINDOW_LEFT_EDGE_X (w
);
22924 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
22928 area_left
= window_box_left (w
, area
);
22929 last_x
= area_left
+ window_box_width (w
, area
);
22933 /* Build a doubly-linked list of glyph_string structures between
22934 head and tail from what we have to draw. Note that the macro
22935 BUILD_GLYPH_STRINGS will modify its start parameter. That's
22936 the reason we use a separate variable `i'. */
22938 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
22940 x_reached
= tail
->x
+ tail
->background_width
;
22944 /* If there are any glyphs with lbearing < 0 or rbearing > width in
22945 the row, redraw some glyphs in front or following the glyph
22946 strings built above. */
22947 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
22949 struct glyph_string
*h
, *t
;
22950 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
22951 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
22952 int check_mouse_face
= 0;
22955 /* If mouse highlighting is on, we may need to draw adjacent
22956 glyphs using mouse-face highlighting. */
22957 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
22959 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
22961 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
22962 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
22964 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
22966 check_mouse_face
= 1;
22967 mouse_beg_col
= (row
== mouse_beg_row
)
22968 ? hlinfo
->mouse_face_beg_col
: 0;
22969 mouse_end_col
= (row
== mouse_end_row
)
22970 ? hlinfo
->mouse_face_end_col
22971 : row
->used
[TEXT_AREA
];
22975 /* Compute overhangs for all glyph strings. */
22976 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
22977 for (s
= head
; s
; s
= s
->next
)
22978 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
22980 /* Prepend glyph strings for glyphs in front of the first glyph
22981 string that are overwritten because of the first glyph
22982 string's left overhang. The background of all strings
22983 prepended must be drawn because the first glyph string
22985 i
= left_overwritten (head
);
22988 enum draw_glyphs_face overlap_hl
;
22990 /* If this row contains mouse highlighting, attempt to draw
22991 the overlapped glyphs with the correct highlight. This
22992 code fails if the overlap encompasses more than one glyph
22993 and mouse-highlight spans only some of these glyphs.
22994 However, making it work perfectly involves a lot more
22995 code, and I don't know if the pathological case occurs in
22996 practice, so we'll stick to this for now. --- cyd */
22997 if (check_mouse_face
22998 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22999 overlap_hl
= DRAW_MOUSE_FACE
;
23001 overlap_hl
= DRAW_NORMAL_TEXT
;
23004 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23005 overlap_hl
, dummy_x
, last_x
);
23007 compute_overhangs_and_x (t
, head
->x
, 1);
23008 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23012 /* Prepend glyph strings for glyphs in front of the first glyph
23013 string that overwrite that glyph string because of their
23014 right overhang. For these strings, only the foreground must
23015 be drawn, because it draws over the glyph string at `head'.
23016 The background must not be drawn because this would overwrite
23017 right overhangs of preceding glyphs for which no glyph
23019 i
= left_overwriting (head
);
23022 enum draw_glyphs_face overlap_hl
;
23024 if (check_mouse_face
23025 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23026 overlap_hl
= DRAW_MOUSE_FACE
;
23028 overlap_hl
= DRAW_NORMAL_TEXT
;
23031 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23032 overlap_hl
, dummy_x
, last_x
);
23033 for (s
= h
; s
; s
= s
->next
)
23034 s
->background_filled_p
= 1;
23035 compute_overhangs_and_x (t
, head
->x
, 1);
23036 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23039 /* Append glyphs strings for glyphs following the last glyph
23040 string tail that are overwritten by tail. The background of
23041 these strings has to be drawn because tail's foreground draws
23043 i
= right_overwritten (tail
);
23046 enum draw_glyphs_face overlap_hl
;
23048 if (check_mouse_face
23049 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23050 overlap_hl
= DRAW_MOUSE_FACE
;
23052 overlap_hl
= DRAW_NORMAL_TEXT
;
23054 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23055 overlap_hl
, x
, last_x
);
23056 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23057 we don't have `end = i;' here. */
23058 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23059 append_glyph_string_lists (&head
, &tail
, h
, t
);
23063 /* Append glyph strings for glyphs following the last glyph
23064 string tail that overwrite tail. The foreground of such
23065 glyphs has to be drawn because it writes into the background
23066 of tail. The background must not be drawn because it could
23067 paint over the foreground of following glyphs. */
23068 i
= right_overwriting (tail
);
23071 enum draw_glyphs_face overlap_hl
;
23072 if (check_mouse_face
23073 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23074 overlap_hl
= DRAW_MOUSE_FACE
;
23076 overlap_hl
= DRAW_NORMAL_TEXT
;
23079 i
++; /* We must include the Ith glyph. */
23080 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23081 overlap_hl
, x
, last_x
);
23082 for (s
= h
; s
; s
= s
->next
)
23083 s
->background_filled_p
= 1;
23084 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23085 append_glyph_string_lists (&head
, &tail
, h
, t
);
23087 if (clip_head
|| clip_tail
)
23088 for (s
= head
; s
; s
= s
->next
)
23090 s
->clip_head
= clip_head
;
23091 s
->clip_tail
= clip_tail
;
23095 /* Draw all strings. */
23096 for (s
= head
; s
; s
= s
->next
)
23097 FRAME_RIF (f
)->draw_glyph_string (s
);
23100 /* When focus a sole frame and move horizontally, this sets on_p to 0
23101 causing a failure to erase prev cursor position. */
23102 if (area
== TEXT_AREA
23103 && !row
->full_width_p
23104 /* When drawing overlapping rows, only the glyph strings'
23105 foreground is drawn, which doesn't erase a cursor
23109 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23110 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23111 : (tail
? tail
->x
+ tail
->background_width
: x
));
23115 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23116 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23120 /* Value is the x-position up to which drawn, relative to AREA of W.
23121 This doesn't include parts drawn because of overhangs. */
23122 if (row
->full_width_p
)
23123 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23125 x_reached
-= area_left
;
23127 RELEASE_HDC (hdc
, f
);
23132 /* Expand row matrix if too narrow. Don't expand if area
23135 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23137 if (!fonts_changed_p \
23138 && (it->glyph_row->glyphs[area] \
23139 < it->glyph_row->glyphs[area + 1])) \
23141 it->w->ncols_scale_factor++; \
23142 fonts_changed_p = 1; \
23146 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23147 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23150 append_glyph (struct it
*it
)
23152 struct glyph
*glyph
;
23153 enum glyph_row_area area
= it
->area
;
23155 xassert (it
->glyph_row
);
23156 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23158 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23159 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23161 /* If the glyph row is reversed, we need to prepend the glyph
23162 rather than append it. */
23163 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23167 /* Make room for the additional glyph. */
23168 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23170 glyph
= it
->glyph_row
->glyphs
[area
];
23172 glyph
->charpos
= CHARPOS (it
->position
);
23173 glyph
->object
= it
->object
;
23174 if (it
->pixel_width
> 0)
23176 glyph
->pixel_width
= it
->pixel_width
;
23177 glyph
->padding_p
= 0;
23181 /* Assure at least 1-pixel width. Otherwise, cursor can't
23182 be displayed correctly. */
23183 glyph
->pixel_width
= 1;
23184 glyph
->padding_p
= 1;
23186 glyph
->ascent
= it
->ascent
;
23187 glyph
->descent
= it
->descent
;
23188 glyph
->voffset
= it
->voffset
;
23189 glyph
->type
= CHAR_GLYPH
;
23190 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23191 glyph
->multibyte_p
= it
->multibyte_p
;
23192 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23193 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23194 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23195 || it
->phys_descent
> it
->descent
);
23196 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23197 glyph
->face_id
= it
->face_id
;
23198 glyph
->u
.ch
= it
->char_to_display
;
23199 glyph
->slice
.img
= null_glyph_slice
;
23200 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23203 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23204 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23206 glyph
->bidi_type
= it
->bidi_it
.type
;
23210 glyph
->resolved_level
= 0;
23211 glyph
->bidi_type
= UNKNOWN_BT
;
23213 ++it
->glyph_row
->used
[area
];
23216 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23219 /* Store one glyph for the composition IT->cmp_it.id in
23220 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23224 append_composite_glyph (struct it
*it
)
23226 struct glyph
*glyph
;
23227 enum glyph_row_area area
= it
->area
;
23229 xassert (it
->glyph_row
);
23231 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23232 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23234 /* If the glyph row is reversed, we need to prepend the glyph
23235 rather than append it. */
23236 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23240 /* Make room for the new glyph. */
23241 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23243 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23245 glyph
->charpos
= it
->cmp_it
.charpos
;
23246 glyph
->object
= it
->object
;
23247 glyph
->pixel_width
= it
->pixel_width
;
23248 glyph
->ascent
= it
->ascent
;
23249 glyph
->descent
= it
->descent
;
23250 glyph
->voffset
= it
->voffset
;
23251 glyph
->type
= COMPOSITE_GLYPH
;
23252 if (it
->cmp_it
.ch
< 0)
23254 glyph
->u
.cmp
.automatic
= 0;
23255 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23256 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23260 glyph
->u
.cmp
.automatic
= 1;
23261 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23262 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23263 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23265 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23266 glyph
->multibyte_p
= it
->multibyte_p
;
23267 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23268 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23269 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23270 || it
->phys_descent
> it
->descent
);
23271 glyph
->padding_p
= 0;
23272 glyph
->glyph_not_available_p
= 0;
23273 glyph
->face_id
= it
->face_id
;
23274 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23277 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23278 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23280 glyph
->bidi_type
= it
->bidi_it
.type
;
23282 ++it
->glyph_row
->used
[area
];
23285 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23289 /* Change IT->ascent and IT->height according to the setting of
23293 take_vertical_position_into_account (struct it
*it
)
23297 if (it
->voffset
< 0)
23298 /* Increase the ascent so that we can display the text higher
23300 it
->ascent
-= it
->voffset
;
23302 /* Increase the descent so that we can display the text lower
23304 it
->descent
+= it
->voffset
;
23309 /* Produce glyphs/get display metrics for the image IT is loaded with.
23310 See the description of struct display_iterator in dispextern.h for
23311 an overview of struct display_iterator. */
23314 produce_image_glyph (struct it
*it
)
23318 int glyph_ascent
, crop
;
23319 struct glyph_slice slice
;
23321 xassert (it
->what
== IT_IMAGE
);
23323 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23325 /* Make sure X resources of the face is loaded. */
23326 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23328 if (it
->image_id
< 0)
23330 /* Fringe bitmap. */
23331 it
->ascent
= it
->phys_ascent
= 0;
23332 it
->descent
= it
->phys_descent
= 0;
23333 it
->pixel_width
= 0;
23338 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23340 /* Make sure X resources of the image is loaded. */
23341 prepare_image_for_display (it
->f
, img
);
23343 slice
.x
= slice
.y
= 0;
23344 slice
.width
= img
->width
;
23345 slice
.height
= img
->height
;
23347 if (INTEGERP (it
->slice
.x
))
23348 slice
.x
= XINT (it
->slice
.x
);
23349 else if (FLOATP (it
->slice
.x
))
23350 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23352 if (INTEGERP (it
->slice
.y
))
23353 slice
.y
= XINT (it
->slice
.y
);
23354 else if (FLOATP (it
->slice
.y
))
23355 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23357 if (INTEGERP (it
->slice
.width
))
23358 slice
.width
= XINT (it
->slice
.width
);
23359 else if (FLOATP (it
->slice
.width
))
23360 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23362 if (INTEGERP (it
->slice
.height
))
23363 slice
.height
= XINT (it
->slice
.height
);
23364 else if (FLOATP (it
->slice
.height
))
23365 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23367 if (slice
.x
>= img
->width
)
23368 slice
.x
= img
->width
;
23369 if (slice
.y
>= img
->height
)
23370 slice
.y
= img
->height
;
23371 if (slice
.x
+ slice
.width
>= img
->width
)
23372 slice
.width
= img
->width
- slice
.x
;
23373 if (slice
.y
+ slice
.height
> img
->height
)
23374 slice
.height
= img
->height
- slice
.y
;
23376 if (slice
.width
== 0 || slice
.height
== 0)
23379 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23381 it
->descent
= slice
.height
- glyph_ascent
;
23383 it
->descent
+= img
->vmargin
;
23384 if (slice
.y
+ slice
.height
== img
->height
)
23385 it
->descent
+= img
->vmargin
;
23386 it
->phys_descent
= it
->descent
;
23388 it
->pixel_width
= slice
.width
;
23390 it
->pixel_width
+= img
->hmargin
;
23391 if (slice
.x
+ slice
.width
== img
->width
)
23392 it
->pixel_width
+= img
->hmargin
;
23394 /* It's quite possible for images to have an ascent greater than
23395 their height, so don't get confused in that case. */
23396 if (it
->descent
< 0)
23401 if (face
->box
!= FACE_NO_BOX
)
23403 if (face
->box_line_width
> 0)
23406 it
->ascent
+= face
->box_line_width
;
23407 if (slice
.y
+ slice
.height
== img
->height
)
23408 it
->descent
+= face
->box_line_width
;
23411 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23412 it
->pixel_width
+= eabs (face
->box_line_width
);
23413 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23414 it
->pixel_width
+= eabs (face
->box_line_width
);
23417 take_vertical_position_into_account (it
);
23419 /* Automatically crop wide image glyphs at right edge so we can
23420 draw the cursor on same display row. */
23421 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23422 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23424 it
->pixel_width
-= crop
;
23425 slice
.width
-= crop
;
23430 struct glyph
*glyph
;
23431 enum glyph_row_area area
= it
->area
;
23433 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23434 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23436 glyph
->charpos
= CHARPOS (it
->position
);
23437 glyph
->object
= it
->object
;
23438 glyph
->pixel_width
= it
->pixel_width
;
23439 glyph
->ascent
= glyph_ascent
;
23440 glyph
->descent
= it
->descent
;
23441 glyph
->voffset
= it
->voffset
;
23442 glyph
->type
= IMAGE_GLYPH
;
23443 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23444 glyph
->multibyte_p
= it
->multibyte_p
;
23445 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23446 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23447 glyph
->overlaps_vertically_p
= 0;
23448 glyph
->padding_p
= 0;
23449 glyph
->glyph_not_available_p
= 0;
23450 glyph
->face_id
= it
->face_id
;
23451 glyph
->u
.img_id
= img
->id
;
23452 glyph
->slice
.img
= slice
;
23453 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23456 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23457 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23459 glyph
->bidi_type
= it
->bidi_it
.type
;
23461 ++it
->glyph_row
->used
[area
];
23464 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23469 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23470 of the glyph, WIDTH and HEIGHT are the width and height of the
23471 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23474 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23475 int width
, int height
, int ascent
)
23477 struct glyph
*glyph
;
23478 enum glyph_row_area area
= it
->area
;
23480 xassert (ascent
>= 0 && ascent
<= height
);
23482 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23483 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23485 /* If the glyph row is reversed, we need to prepend the glyph
23486 rather than append it. */
23487 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23491 /* Make room for the additional glyph. */
23492 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23494 glyph
= it
->glyph_row
->glyphs
[area
];
23496 glyph
->charpos
= CHARPOS (it
->position
);
23497 glyph
->object
= object
;
23498 glyph
->pixel_width
= width
;
23499 glyph
->ascent
= ascent
;
23500 glyph
->descent
= height
- ascent
;
23501 glyph
->voffset
= it
->voffset
;
23502 glyph
->type
= STRETCH_GLYPH
;
23503 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23504 glyph
->multibyte_p
= it
->multibyte_p
;
23505 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23506 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23507 glyph
->overlaps_vertically_p
= 0;
23508 glyph
->padding_p
= 0;
23509 glyph
->glyph_not_available_p
= 0;
23510 glyph
->face_id
= it
->face_id
;
23511 glyph
->u
.stretch
.ascent
= ascent
;
23512 glyph
->u
.stretch
.height
= height
;
23513 glyph
->slice
.img
= null_glyph_slice
;
23514 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23517 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23518 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23520 glyph
->bidi_type
= it
->bidi_it
.type
;
23524 glyph
->resolved_level
= 0;
23525 glyph
->bidi_type
= UNKNOWN_BT
;
23527 ++it
->glyph_row
->used
[area
];
23530 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23533 #endif /* HAVE_WINDOW_SYSTEM */
23535 /* Produce a stretch glyph for iterator IT. IT->object is the value
23536 of the glyph property displayed. The value must be a list
23537 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23540 1. `:width WIDTH' specifies that the space should be WIDTH *
23541 canonical char width wide. WIDTH may be an integer or floating
23544 2. `:relative-width FACTOR' specifies that the width of the stretch
23545 should be computed from the width of the first character having the
23546 `glyph' property, and should be FACTOR times that width.
23548 3. `:align-to HPOS' specifies that the space should be wide enough
23549 to reach HPOS, a value in canonical character units.
23551 Exactly one of the above pairs must be present.
23553 4. `:height HEIGHT' specifies that the height of the stretch produced
23554 should be HEIGHT, measured in canonical character units.
23556 5. `:relative-height FACTOR' specifies that the height of the
23557 stretch should be FACTOR times the height of the characters having
23558 the glyph property.
23560 Either none or exactly one of 4 or 5 must be present.
23562 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23563 of the stretch should be used for the ascent of the stretch.
23564 ASCENT must be in the range 0 <= ASCENT <= 100. */
23567 produce_stretch_glyph (struct it
*it
)
23569 /* (space :width WIDTH :height HEIGHT ...) */
23570 Lisp_Object prop
, plist
;
23571 int width
= 0, height
= 0, align_to
= -1;
23572 int zero_width_ok_p
= 0;
23575 struct face
*face
= NULL
;
23576 struct font
*font
= NULL
;
23578 #ifdef HAVE_WINDOW_SYSTEM
23579 int zero_height_ok_p
= 0;
23581 if (FRAME_WINDOW_P (it
->f
))
23583 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23584 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23585 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23589 /* List should start with `space'. */
23590 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23591 plist
= XCDR (it
->object
);
23593 /* Compute the width of the stretch. */
23594 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23595 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23597 /* Absolute width `:width WIDTH' specified and valid. */
23598 zero_width_ok_p
= 1;
23601 #ifdef HAVE_WINDOW_SYSTEM
23602 else if (FRAME_WINDOW_P (it
->f
)
23603 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23605 /* Relative width `:relative-width FACTOR' specified and valid.
23606 Compute the width of the characters having the `glyph'
23609 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23612 if (it
->multibyte_p
)
23613 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23616 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23617 if (! ASCII_CHAR_P (it2
.c
))
23618 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23621 it2
.glyph_row
= NULL
;
23622 it2
.what
= IT_CHARACTER
;
23623 x_produce_glyphs (&it2
);
23624 width
= NUMVAL (prop
) * it2
.pixel_width
;
23626 #endif /* HAVE_WINDOW_SYSTEM */
23627 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23628 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23630 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23631 align_to
= (align_to
< 0
23633 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23634 else if (align_to
< 0)
23635 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23636 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23637 zero_width_ok_p
= 1;
23640 /* Nothing specified -> width defaults to canonical char width. */
23641 width
= FRAME_COLUMN_WIDTH (it
->f
);
23643 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23646 #ifdef HAVE_WINDOW_SYSTEM
23647 /* Compute height. */
23648 if (FRAME_WINDOW_P (it
->f
))
23650 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23651 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23654 zero_height_ok_p
= 1;
23656 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23658 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23660 height
= FONT_HEIGHT (font
);
23662 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
23665 /* Compute percentage of height used for ascent. If
23666 `:ascent ASCENT' is present and valid, use that. Otherwise,
23667 derive the ascent from the font in use. */
23668 if (prop
= Fplist_get (plist
, QCascent
),
23669 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
23670 ascent
= height
* NUMVAL (prop
) / 100.0;
23671 else if (!NILP (prop
)
23672 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23673 ascent
= min (max (0, (int)tem
), height
);
23675 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
23678 #endif /* HAVE_WINDOW_SYSTEM */
23681 if (width
> 0 && it
->line_wrap
!= TRUNCATE
23682 && it
->current_x
+ width
> it
->last_visible_x
)
23684 width
= it
->last_visible_x
- it
->current_x
;
23685 #ifdef HAVE_WINDOW_SYSTEM
23686 /* Subtract one more pixel from the stretch width, but only on
23687 GUI frames, since on a TTY each glyph is one "pixel" wide. */
23688 width
-= FRAME_WINDOW_P (it
->f
);
23692 if (width
> 0 && height
> 0 && it
->glyph_row
)
23694 Lisp_Object o_object
= it
->object
;
23695 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
23698 if (!STRINGP (object
))
23699 object
= it
->w
->buffer
;
23700 #ifdef HAVE_WINDOW_SYSTEM
23701 if (FRAME_WINDOW_P (it
->f
))
23702 append_stretch_glyph (it
, object
, width
, height
, ascent
);
23706 it
->object
= object
;
23707 it
->char_to_display
= ' ';
23708 it
->pixel_width
= it
->len
= 1;
23710 tty_append_glyph (it
);
23711 it
->object
= o_object
;
23715 it
->pixel_width
= width
;
23716 #ifdef HAVE_WINDOW_SYSTEM
23717 if (FRAME_WINDOW_P (it
->f
))
23719 it
->ascent
= it
->phys_ascent
= ascent
;
23720 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
23721 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
23722 take_vertical_position_into_account (it
);
23726 it
->nglyphs
= width
;
23729 #ifdef HAVE_WINDOW_SYSTEM
23731 /* Calculate line-height and line-spacing properties.
23732 An integer value specifies explicit pixel value.
23733 A float value specifies relative value to current face height.
23734 A cons (float . face-name) specifies relative value to
23735 height of specified face font.
23737 Returns height in pixels, or nil. */
23741 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
23742 int boff
, int override
)
23744 Lisp_Object face_name
= Qnil
;
23745 int ascent
, descent
, height
;
23747 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
23752 face_name
= XCAR (val
);
23754 if (!NUMBERP (val
))
23755 val
= make_number (1);
23756 if (NILP (face_name
))
23758 height
= it
->ascent
+ it
->descent
;
23763 if (NILP (face_name
))
23765 font
= FRAME_FONT (it
->f
);
23766 boff
= FRAME_BASELINE_OFFSET (it
->f
);
23768 else if (EQ (face_name
, Qt
))
23777 face_id
= lookup_named_face (it
->f
, face_name
, 0);
23779 return make_number (-1);
23781 face
= FACE_FROM_ID (it
->f
, face_id
);
23784 return make_number (-1);
23785 boff
= font
->baseline_offset
;
23786 if (font
->vertical_centering
)
23787 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23790 ascent
= FONT_BASE (font
) + boff
;
23791 descent
= FONT_DESCENT (font
) - boff
;
23795 it
->override_ascent
= ascent
;
23796 it
->override_descent
= descent
;
23797 it
->override_boff
= boff
;
23800 height
= ascent
+ descent
;
23804 height
= (int)(XFLOAT_DATA (val
) * height
);
23805 else if (INTEGERP (val
))
23806 height
*= XINT (val
);
23808 return make_number (height
);
23812 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
23813 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
23814 and only if this is for a character for which no font was found.
23816 If the display method (it->glyphless_method) is
23817 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
23818 length of the acronym or the hexadecimal string, UPPER_XOFF and
23819 UPPER_YOFF are pixel offsets for the upper part of the string,
23820 LOWER_XOFF and LOWER_YOFF are for the lower part.
23822 For the other display methods, LEN through LOWER_YOFF are zero. */
23825 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
23826 short upper_xoff
, short upper_yoff
,
23827 short lower_xoff
, short lower_yoff
)
23829 struct glyph
*glyph
;
23830 enum glyph_row_area area
= it
->area
;
23832 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23833 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23835 /* If the glyph row is reversed, we need to prepend the glyph
23836 rather than append it. */
23837 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23841 /* Make room for the additional glyph. */
23842 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23844 glyph
= it
->glyph_row
->glyphs
[area
];
23846 glyph
->charpos
= CHARPOS (it
->position
);
23847 glyph
->object
= it
->object
;
23848 glyph
->pixel_width
= it
->pixel_width
;
23849 glyph
->ascent
= it
->ascent
;
23850 glyph
->descent
= it
->descent
;
23851 glyph
->voffset
= it
->voffset
;
23852 glyph
->type
= GLYPHLESS_GLYPH
;
23853 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
23854 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
23855 glyph
->u
.glyphless
.len
= len
;
23856 glyph
->u
.glyphless
.ch
= it
->c
;
23857 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
23858 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
23859 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
23860 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
23861 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23862 glyph
->multibyte_p
= it
->multibyte_p
;
23863 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23864 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23865 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23866 || it
->phys_descent
> it
->descent
);
23867 glyph
->padding_p
= 0;
23868 glyph
->glyph_not_available_p
= 0;
23869 glyph
->face_id
= face_id
;
23870 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23873 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23874 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23876 glyph
->bidi_type
= it
->bidi_it
.type
;
23878 ++it
->glyph_row
->used
[area
];
23881 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23885 /* Produce a glyph for a glyphless character for iterator IT.
23886 IT->glyphless_method specifies which method to use for displaying
23887 the character. See the description of enum
23888 glyphless_display_method in dispextern.h for the detail.
23890 FOR_NO_FONT is nonzero if and only if this is for a character for
23891 which no font was found. ACRONYM, if non-nil, is an acronym string
23892 for the character. */
23895 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
23900 int base_width
, base_height
, width
, height
;
23901 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
23904 /* Get the metrics of the base font. We always refer to the current
23906 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
23907 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23908 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
23909 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
23910 base_height
= it
->ascent
+ it
->descent
;
23911 base_width
= font
->average_width
;
23913 /* Get a face ID for the glyph by utilizing a cache (the same way as
23914 done for `escape-glyph' in get_next_display_element). */
23915 if (it
->f
== last_glyphless_glyph_frame
23916 && it
->face_id
== last_glyphless_glyph_face_id
)
23918 face_id
= last_glyphless_glyph_merged_face_id
;
23922 /* Merge the `glyphless-char' face into the current face. */
23923 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
23924 last_glyphless_glyph_frame
= it
->f
;
23925 last_glyphless_glyph_face_id
= it
->face_id
;
23926 last_glyphless_glyph_merged_face_id
= face_id
;
23929 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
23931 it
->pixel_width
= THIN_SPACE_WIDTH
;
23933 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23935 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
23937 width
= CHAR_WIDTH (it
->c
);
23940 else if (width
> 4)
23942 it
->pixel_width
= base_width
* width
;
23944 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23950 unsigned int code
[6];
23952 int ascent
, descent
;
23953 struct font_metrics metrics_upper
, metrics_lower
;
23955 face
= FACE_FROM_ID (it
->f
, face_id
);
23956 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23957 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23959 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
23961 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
23962 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
23963 if (CONSP (acronym
))
23964 acronym
= XCAR (acronym
);
23965 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
23969 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
23970 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
23973 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
23974 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
23975 upper_len
= (len
+ 1) / 2;
23976 font
->driver
->text_extents (font
, code
, upper_len
,
23978 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
23983 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
23984 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
23985 upper_xoff
= upper_yoff
= 2; /* the typical case */
23986 if (base_width
>= width
)
23988 /* Align the upper to the left, the lower to the right. */
23989 it
->pixel_width
= base_width
;
23990 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
23994 /* Center the shorter one. */
23995 it
->pixel_width
= width
;
23996 if (metrics_upper
.width
>= metrics_lower
.width
)
23997 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24000 /* FIXME: This code doesn't look right. It formerly was
24001 missing the "lower_xoff = 0;", which couldn't have
24002 been right since it left lower_xoff uninitialized. */
24004 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24008 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24009 top, bottom, and between upper and lower strings. */
24010 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24011 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24012 /* Center vertically.
24013 H:base_height, D:base_descent
24014 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24016 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24017 descent = D - H/2 + h/2;
24018 lower_yoff = descent - 2 - ld;
24019 upper_yoff = lower_yoff - la - 1 - ud; */
24020 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24021 descent
= it
->descent
- (base_height
- height
) / 2;
24022 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24023 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24024 - metrics_upper
.descent
);
24025 /* Don't make the height shorter than the base height. */
24026 if (height
> base_height
)
24028 it
->ascent
= ascent
;
24029 it
->descent
= descent
;
24033 it
->phys_ascent
= it
->ascent
;
24034 it
->phys_descent
= it
->descent
;
24036 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24037 upper_xoff
, upper_yoff
,
24038 lower_xoff
, lower_yoff
);
24040 take_vertical_position_into_account (it
);
24045 Produce glyphs/get display metrics for the display element IT is
24046 loaded with. See the description of struct it in dispextern.h
24047 for an overview of struct it. */
24050 x_produce_glyphs (struct it
*it
)
24052 int extra_line_spacing
= it
->extra_line_spacing
;
24054 it
->glyph_not_available_p
= 0;
24056 if (it
->what
== IT_CHARACTER
)
24059 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24060 struct font
*font
= face
->font
;
24061 struct font_metrics
*pcm
= NULL
;
24062 int boff
; /* baseline offset */
24066 /* When no suitable font is found, display this character by
24067 the method specified in the first extra slot of
24068 Vglyphless_char_display. */
24069 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24071 xassert (it
->what
== IT_GLYPHLESS
);
24072 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24076 boff
= font
->baseline_offset
;
24077 if (font
->vertical_centering
)
24078 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24080 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24086 if (it
->override_ascent
>= 0)
24088 it
->ascent
= it
->override_ascent
;
24089 it
->descent
= it
->override_descent
;
24090 boff
= it
->override_boff
;
24094 it
->ascent
= FONT_BASE (font
) + boff
;
24095 it
->descent
= FONT_DESCENT (font
) - boff
;
24098 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24100 pcm
= get_per_char_metric (font
, &char2b
);
24101 if (pcm
->width
== 0
24102 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24108 it
->phys_ascent
= pcm
->ascent
+ boff
;
24109 it
->phys_descent
= pcm
->descent
- boff
;
24110 it
->pixel_width
= pcm
->width
;
24114 it
->glyph_not_available_p
= 1;
24115 it
->phys_ascent
= it
->ascent
;
24116 it
->phys_descent
= it
->descent
;
24117 it
->pixel_width
= font
->space_width
;
24120 if (it
->constrain_row_ascent_descent_p
)
24122 if (it
->descent
> it
->max_descent
)
24124 it
->ascent
+= it
->descent
- it
->max_descent
;
24125 it
->descent
= it
->max_descent
;
24127 if (it
->ascent
> it
->max_ascent
)
24129 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24130 it
->ascent
= it
->max_ascent
;
24132 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24133 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24134 extra_line_spacing
= 0;
24137 /* If this is a space inside a region of text with
24138 `space-width' property, change its width. */
24139 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24141 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24143 /* If face has a box, add the box thickness to the character
24144 height. If character has a box line to the left and/or
24145 right, add the box line width to the character's width. */
24146 if (face
->box
!= FACE_NO_BOX
)
24148 int thick
= face
->box_line_width
;
24152 it
->ascent
+= thick
;
24153 it
->descent
+= thick
;
24158 if (it
->start_of_box_run_p
)
24159 it
->pixel_width
+= thick
;
24160 if (it
->end_of_box_run_p
)
24161 it
->pixel_width
+= thick
;
24164 /* If face has an overline, add the height of the overline
24165 (1 pixel) and a 1 pixel margin to the character height. */
24166 if (face
->overline_p
)
24167 it
->ascent
+= overline_margin
;
24169 if (it
->constrain_row_ascent_descent_p
)
24171 if (it
->ascent
> it
->max_ascent
)
24172 it
->ascent
= it
->max_ascent
;
24173 if (it
->descent
> it
->max_descent
)
24174 it
->descent
= it
->max_descent
;
24177 take_vertical_position_into_account (it
);
24179 /* If we have to actually produce glyphs, do it. */
24184 /* Translate a space with a `space-width' property
24185 into a stretch glyph. */
24186 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24187 / FONT_HEIGHT (font
));
24188 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24189 it
->ascent
+ it
->descent
, ascent
);
24194 /* If characters with lbearing or rbearing are displayed
24195 in this line, record that fact in a flag of the
24196 glyph row. This is used to optimize X output code. */
24197 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24198 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24200 if (! stretched_p
&& it
->pixel_width
== 0)
24201 /* We assure that all visible glyphs have at least 1-pixel
24203 it
->pixel_width
= 1;
24205 else if (it
->char_to_display
== '\n')
24207 /* A newline has no width, but we need the height of the
24208 line. But if previous part of the line sets a height,
24209 don't increase that height */
24211 Lisp_Object height
;
24212 Lisp_Object total_height
= Qnil
;
24214 it
->override_ascent
= -1;
24215 it
->pixel_width
= 0;
24218 height
= get_it_property (it
, Qline_height
);
24219 /* Split (line-height total-height) list */
24221 && CONSP (XCDR (height
))
24222 && NILP (XCDR (XCDR (height
))))
24224 total_height
= XCAR (XCDR (height
));
24225 height
= XCAR (height
);
24227 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24229 if (it
->override_ascent
>= 0)
24231 it
->ascent
= it
->override_ascent
;
24232 it
->descent
= it
->override_descent
;
24233 boff
= it
->override_boff
;
24237 it
->ascent
= FONT_BASE (font
) + boff
;
24238 it
->descent
= FONT_DESCENT (font
) - boff
;
24241 if (EQ (height
, Qt
))
24243 if (it
->descent
> it
->max_descent
)
24245 it
->ascent
+= it
->descent
- it
->max_descent
;
24246 it
->descent
= it
->max_descent
;
24248 if (it
->ascent
> it
->max_ascent
)
24250 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24251 it
->ascent
= it
->max_ascent
;
24253 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24254 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24255 it
->constrain_row_ascent_descent_p
= 1;
24256 extra_line_spacing
= 0;
24260 Lisp_Object spacing
;
24262 it
->phys_ascent
= it
->ascent
;
24263 it
->phys_descent
= it
->descent
;
24265 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24266 && face
->box
!= FACE_NO_BOX
24267 && face
->box_line_width
> 0)
24269 it
->ascent
+= face
->box_line_width
;
24270 it
->descent
+= face
->box_line_width
;
24273 && XINT (height
) > it
->ascent
+ it
->descent
)
24274 it
->ascent
= XINT (height
) - it
->descent
;
24276 if (!NILP (total_height
))
24277 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24280 spacing
= get_it_property (it
, Qline_spacing
);
24281 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24283 if (INTEGERP (spacing
))
24285 extra_line_spacing
= XINT (spacing
);
24286 if (!NILP (total_height
))
24287 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24291 else /* i.e. (it->char_to_display == '\t') */
24293 if (font
->space_width
> 0)
24295 int tab_width
= it
->tab_width
* font
->space_width
;
24296 int x
= it
->current_x
+ it
->continuation_lines_width
;
24297 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24299 /* If the distance from the current position to the next tab
24300 stop is less than a space character width, use the
24301 tab stop after that. */
24302 if (next_tab_x
- x
< font
->space_width
)
24303 next_tab_x
+= tab_width
;
24305 it
->pixel_width
= next_tab_x
- x
;
24307 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24308 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24312 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24313 it
->ascent
+ it
->descent
, it
->ascent
);
24318 it
->pixel_width
= 0;
24323 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24325 /* A static composition.
24327 Note: A composition is represented as one glyph in the
24328 glyph matrix. There are no padding glyphs.
24330 Important note: pixel_width, ascent, and descent are the
24331 values of what is drawn by draw_glyphs (i.e. the values of
24332 the overall glyphs composed). */
24333 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24334 int boff
; /* baseline offset */
24335 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24336 int glyph_len
= cmp
->glyph_len
;
24337 struct font
*font
= face
->font
;
24341 /* If we have not yet calculated pixel size data of glyphs of
24342 the composition for the current face font, calculate them
24343 now. Theoretically, we have to check all fonts for the
24344 glyphs, but that requires much time and memory space. So,
24345 here we check only the font of the first glyph. This may
24346 lead to incorrect display, but it's very rare, and C-l
24347 (recenter-top-bottom) can correct the display anyway. */
24348 if (! cmp
->font
|| cmp
->font
!= font
)
24350 /* Ascent and descent of the font of the first character
24351 of this composition (adjusted by baseline offset).
24352 Ascent and descent of overall glyphs should not be less
24353 than these, respectively. */
24354 int font_ascent
, font_descent
, font_height
;
24355 /* Bounding box of the overall glyphs. */
24356 int leftmost
, rightmost
, lowest
, highest
;
24357 int lbearing
, rbearing
;
24358 int i
, width
, ascent
, descent
;
24359 int left_padded
= 0, right_padded
= 0;
24360 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24362 struct font_metrics
*pcm
;
24363 int font_not_found_p
;
24366 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24367 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24369 if (glyph_len
< cmp
->glyph_len
)
24371 for (i
= 0; i
< glyph_len
; i
++)
24373 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24375 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24380 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24381 : IT_CHARPOS (*it
));
24382 /* If no suitable font is found, use the default font. */
24383 font_not_found_p
= font
== NULL
;
24384 if (font_not_found_p
)
24386 face
= face
->ascii_face
;
24389 boff
= font
->baseline_offset
;
24390 if (font
->vertical_centering
)
24391 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24392 font_ascent
= FONT_BASE (font
) + boff
;
24393 font_descent
= FONT_DESCENT (font
) - boff
;
24394 font_height
= FONT_HEIGHT (font
);
24396 cmp
->font
= (void *) font
;
24399 if (! font_not_found_p
)
24401 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24403 pcm
= get_per_char_metric (font
, &char2b
);
24406 /* Initialize the bounding box. */
24409 width
= pcm
->width
;
24410 ascent
= pcm
->ascent
;
24411 descent
= pcm
->descent
;
24412 lbearing
= pcm
->lbearing
;
24413 rbearing
= pcm
->rbearing
;
24417 width
= font
->space_width
;
24418 ascent
= FONT_BASE (font
);
24419 descent
= FONT_DESCENT (font
);
24426 lowest
= - descent
+ boff
;
24427 highest
= ascent
+ boff
;
24429 if (! font_not_found_p
24430 && font
->default_ascent
24431 && CHAR_TABLE_P (Vuse_default_ascent
)
24432 && !NILP (Faref (Vuse_default_ascent
,
24433 make_number (it
->char_to_display
))))
24434 highest
= font
->default_ascent
+ boff
;
24436 /* Draw the first glyph at the normal position. It may be
24437 shifted to right later if some other glyphs are drawn
24439 cmp
->offsets
[i
* 2] = 0;
24440 cmp
->offsets
[i
* 2 + 1] = boff
;
24441 cmp
->lbearing
= lbearing
;
24442 cmp
->rbearing
= rbearing
;
24444 /* Set cmp->offsets for the remaining glyphs. */
24445 for (i
++; i
< glyph_len
; i
++)
24447 int left
, right
, btm
, top
;
24448 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24450 struct face
*this_face
;
24454 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24455 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24456 font
= this_face
->font
;
24462 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24464 pcm
= get_per_char_metric (font
, &char2b
);
24467 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24470 width
= pcm
->width
;
24471 ascent
= pcm
->ascent
;
24472 descent
= pcm
->descent
;
24473 lbearing
= pcm
->lbearing
;
24474 rbearing
= pcm
->rbearing
;
24475 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24477 /* Relative composition with or without
24478 alternate chars. */
24479 left
= (leftmost
+ rightmost
- width
) / 2;
24480 btm
= - descent
+ boff
;
24481 if (font
->relative_compose
24482 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24483 || NILP (Faref (Vignore_relative_composition
,
24484 make_number (ch
)))))
24487 if (- descent
>= font
->relative_compose
)
24488 /* One extra pixel between two glyphs. */
24490 else if (ascent
<= 0)
24491 /* One extra pixel between two glyphs. */
24492 btm
= lowest
- 1 - ascent
- descent
;
24497 /* A composition rule is specified by an integer
24498 value that encodes global and new reference
24499 points (GREF and NREF). GREF and NREF are
24500 specified by numbers as below:
24502 0---1---2 -- ascent
24506 9--10--11 -- center
24508 ---3---4---5--- baseline
24510 6---7---8 -- descent
24512 int rule
= COMPOSITION_RULE (cmp
, i
);
24513 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24515 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24516 grefx
= gref
% 3, nrefx
= nref
% 3;
24517 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24519 xoff
= font_height
* (xoff
- 128) / 256;
24521 yoff
= font_height
* (yoff
- 128) / 256;
24524 + grefx
* (rightmost
- leftmost
) / 2
24525 - nrefx
* width
/ 2
24528 btm
= ((grefy
== 0 ? highest
24530 : grefy
== 2 ? lowest
24531 : (highest
+ lowest
) / 2)
24532 - (nrefy
== 0 ? ascent
+ descent
24533 : nrefy
== 1 ? descent
- boff
24535 : (ascent
+ descent
) / 2)
24539 cmp
->offsets
[i
* 2] = left
;
24540 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24542 /* Update the bounding box of the overall glyphs. */
24545 right
= left
+ width
;
24546 if (left
< leftmost
)
24548 if (right
> rightmost
)
24551 top
= btm
+ descent
+ ascent
;
24557 if (cmp
->lbearing
> left
+ lbearing
)
24558 cmp
->lbearing
= left
+ lbearing
;
24559 if (cmp
->rbearing
< left
+ rbearing
)
24560 cmp
->rbearing
= left
+ rbearing
;
24564 /* If there are glyphs whose x-offsets are negative,
24565 shift all glyphs to the right and make all x-offsets
24569 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24570 cmp
->offsets
[i
* 2] -= leftmost
;
24571 rightmost
-= leftmost
;
24572 cmp
->lbearing
-= leftmost
;
24573 cmp
->rbearing
-= leftmost
;
24576 if (left_padded
&& cmp
->lbearing
< 0)
24578 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24579 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24580 rightmost
-= cmp
->lbearing
;
24581 cmp
->rbearing
-= cmp
->lbearing
;
24584 if (right_padded
&& rightmost
< cmp
->rbearing
)
24586 rightmost
= cmp
->rbearing
;
24589 cmp
->pixel_width
= rightmost
;
24590 cmp
->ascent
= highest
;
24591 cmp
->descent
= - lowest
;
24592 if (cmp
->ascent
< font_ascent
)
24593 cmp
->ascent
= font_ascent
;
24594 if (cmp
->descent
< font_descent
)
24595 cmp
->descent
= font_descent
;
24599 && (cmp
->lbearing
< 0
24600 || cmp
->rbearing
> cmp
->pixel_width
))
24601 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24603 it
->pixel_width
= cmp
->pixel_width
;
24604 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24605 it
->descent
= it
->phys_descent
= cmp
->descent
;
24606 if (face
->box
!= FACE_NO_BOX
)
24608 int thick
= face
->box_line_width
;
24612 it
->ascent
+= thick
;
24613 it
->descent
+= thick
;
24618 if (it
->start_of_box_run_p
)
24619 it
->pixel_width
+= thick
;
24620 if (it
->end_of_box_run_p
)
24621 it
->pixel_width
+= thick
;
24624 /* If face has an overline, add the height of the overline
24625 (1 pixel) and a 1 pixel margin to the character height. */
24626 if (face
->overline_p
)
24627 it
->ascent
+= overline_margin
;
24629 take_vertical_position_into_account (it
);
24630 if (it
->ascent
< 0)
24632 if (it
->descent
< 0)
24636 append_composite_glyph (it
);
24638 else if (it
->what
== IT_COMPOSITION
)
24640 /* A dynamic (automatic) composition. */
24641 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24642 Lisp_Object gstring
;
24643 struct font_metrics metrics
;
24647 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24649 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24652 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24653 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24654 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24655 it
->descent
= it
->phys_descent
= metrics
.descent
;
24656 if (face
->box
!= FACE_NO_BOX
)
24658 int thick
= face
->box_line_width
;
24662 it
->ascent
+= thick
;
24663 it
->descent
+= thick
;
24668 if (it
->start_of_box_run_p
)
24669 it
->pixel_width
+= thick
;
24670 if (it
->end_of_box_run_p
)
24671 it
->pixel_width
+= thick
;
24673 /* If face has an overline, add the height of the overline
24674 (1 pixel) and a 1 pixel margin to the character height. */
24675 if (face
->overline_p
)
24676 it
->ascent
+= overline_margin
;
24677 take_vertical_position_into_account (it
);
24678 if (it
->ascent
< 0)
24680 if (it
->descent
< 0)
24684 append_composite_glyph (it
);
24686 else if (it
->what
== IT_GLYPHLESS
)
24687 produce_glyphless_glyph (it
, 0, Qnil
);
24688 else if (it
->what
== IT_IMAGE
)
24689 produce_image_glyph (it
);
24690 else if (it
->what
== IT_STRETCH
)
24691 produce_stretch_glyph (it
);
24694 /* Accumulate dimensions. Note: can't assume that it->descent > 0
24695 because this isn't true for images with `:ascent 100'. */
24696 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
24697 if (it
->area
== TEXT_AREA
)
24698 it
->current_x
+= it
->pixel_width
;
24700 if (extra_line_spacing
> 0)
24702 it
->descent
+= extra_line_spacing
;
24703 if (extra_line_spacing
> it
->max_extra_line_spacing
)
24704 it
->max_extra_line_spacing
= extra_line_spacing
;
24707 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
24708 it
->max_descent
= max (it
->max_descent
, it
->descent
);
24709 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
24710 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
24714 Output LEN glyphs starting at START at the nominal cursor position.
24715 Advance the nominal cursor over the text. The global variable
24716 updated_window contains the window being updated, updated_row is
24717 the glyph row being updated, and updated_area is the area of that
24718 row being updated. */
24721 x_write_glyphs (struct glyph
*start
, int len
)
24723 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
24725 xassert (updated_window
&& updated_row
);
24726 /* When the window is hscrolled, cursor hpos can legitimately be out
24727 of bounds, but we draw the cursor at the corresponding window
24728 margin in that case. */
24729 if (!updated_row
->reversed_p
&& chpos
< 0)
24731 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
24732 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
24736 /* Write glyphs. */
24738 hpos
= start
- updated_row
->glyphs
[updated_area
];
24739 x
= draw_glyphs (updated_window
, output_cursor
.x
,
24740 updated_row
, updated_area
,
24742 DRAW_NORMAL_TEXT
, 0);
24744 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
24745 if (updated_area
== TEXT_AREA
24746 && updated_window
->phys_cursor_on_p
24747 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
24749 && chpos
< hpos
+ len
)
24750 updated_window
->phys_cursor_on_p
= 0;
24754 /* Advance the output cursor. */
24755 output_cursor
.hpos
+= len
;
24756 output_cursor
.x
= x
;
24761 Insert LEN glyphs from START at the nominal cursor position. */
24764 x_insert_glyphs (struct glyph
*start
, int len
)
24768 int line_height
, shift_by_width
, shifted_region_width
;
24769 struct glyph_row
*row
;
24770 struct glyph
*glyph
;
24771 int frame_x
, frame_y
;
24774 xassert (updated_window
&& updated_row
);
24776 w
= updated_window
;
24777 f
= XFRAME (WINDOW_FRAME (w
));
24779 /* Get the height of the line we are in. */
24781 line_height
= row
->height
;
24783 /* Get the width of the glyphs to insert. */
24784 shift_by_width
= 0;
24785 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
24786 shift_by_width
+= glyph
->pixel_width
;
24788 /* Get the width of the region to shift right. */
24789 shifted_region_width
= (window_box_width (w
, updated_area
)
24794 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
24795 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
24797 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
24798 line_height
, shift_by_width
);
24800 /* Write the glyphs. */
24801 hpos
= start
- row
->glyphs
[updated_area
];
24802 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
24804 DRAW_NORMAL_TEXT
, 0);
24806 /* Advance the output cursor. */
24807 output_cursor
.hpos
+= len
;
24808 output_cursor
.x
+= shift_by_width
;
24814 Erase the current text line from the nominal cursor position
24815 (inclusive) to pixel column TO_X (exclusive). The idea is that
24816 everything from TO_X onward is already erased.
24818 TO_X is a pixel position relative to updated_area of
24819 updated_window. TO_X == -1 means clear to the end of this area. */
24822 x_clear_end_of_line (int to_x
)
24825 struct window
*w
= updated_window
;
24826 int max_x
, min_y
, max_y
;
24827 int from_x
, from_y
, to_y
;
24829 xassert (updated_window
&& updated_row
);
24830 f
= XFRAME (w
->frame
);
24832 if (updated_row
->full_width_p
)
24833 max_x
= WINDOW_TOTAL_WIDTH (w
);
24835 max_x
= window_box_width (w
, updated_area
);
24836 max_y
= window_text_bottom_y (w
);
24838 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
24839 of window. For TO_X > 0, truncate to end of drawing area. */
24845 to_x
= min (to_x
, max_x
);
24847 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
24849 /* Notice if the cursor will be cleared by this operation. */
24850 if (!updated_row
->full_width_p
)
24851 notice_overwritten_cursor (w
, updated_area
,
24852 output_cursor
.x
, -1,
24854 MATRIX_ROW_BOTTOM_Y (updated_row
));
24856 from_x
= output_cursor
.x
;
24858 /* Translate to frame coordinates. */
24859 if (updated_row
->full_width_p
)
24861 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
24862 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
24866 int area_left
= window_box_left (w
, updated_area
);
24867 from_x
+= area_left
;
24871 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
24872 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
24873 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
24875 /* Prevent inadvertently clearing to end of the X window. */
24876 if (to_x
> from_x
&& to_y
> from_y
)
24879 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
24880 to_x
- from_x
, to_y
- from_y
);
24885 #endif /* HAVE_WINDOW_SYSTEM */
24889 /***********************************************************************
24891 ***********************************************************************/
24893 /* Value is the internal representation of the specified cursor type
24894 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
24895 of the bar cursor. */
24897 static enum text_cursor_kinds
24898 get_specified_cursor_type (Lisp_Object arg
, int *width
)
24900 enum text_cursor_kinds type
;
24905 if (EQ (arg
, Qbox
))
24906 return FILLED_BOX_CURSOR
;
24908 if (EQ (arg
, Qhollow
))
24909 return HOLLOW_BOX_CURSOR
;
24911 if (EQ (arg
, Qbar
))
24918 && EQ (XCAR (arg
), Qbar
)
24919 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
24921 *width
= XINT (XCDR (arg
));
24925 if (EQ (arg
, Qhbar
))
24928 return HBAR_CURSOR
;
24932 && EQ (XCAR (arg
), Qhbar
)
24933 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
24935 *width
= XINT (XCDR (arg
));
24936 return HBAR_CURSOR
;
24939 /* Treat anything unknown as "hollow box cursor".
24940 It was bad to signal an error; people have trouble fixing
24941 .Xdefaults with Emacs, when it has something bad in it. */
24942 type
= HOLLOW_BOX_CURSOR
;
24947 /* Set the default cursor types for specified frame. */
24949 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
24954 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
24955 FRAME_CURSOR_WIDTH (f
) = width
;
24957 /* By default, set up the blink-off state depending on the on-state. */
24959 tem
= Fassoc (arg
, Vblink_cursor_alist
);
24962 FRAME_BLINK_OFF_CURSOR (f
)
24963 = get_specified_cursor_type (XCDR (tem
), &width
);
24964 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
24967 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
24971 #ifdef HAVE_WINDOW_SYSTEM
24973 /* Return the cursor we want to be displayed in window W. Return
24974 width of bar/hbar cursor through WIDTH arg. Return with
24975 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
24976 (i.e. if the `system caret' should track this cursor).
24978 In a mini-buffer window, we want the cursor only to appear if we
24979 are reading input from this window. For the selected window, we
24980 want the cursor type given by the frame parameter or buffer local
24981 setting of cursor-type. If explicitly marked off, draw no cursor.
24982 In all other cases, we want a hollow box cursor. */
24984 static enum text_cursor_kinds
24985 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
24986 int *active_cursor
)
24988 struct frame
*f
= XFRAME (w
->frame
);
24989 struct buffer
*b
= XBUFFER (w
->buffer
);
24990 int cursor_type
= DEFAULT_CURSOR
;
24991 Lisp_Object alt_cursor
;
24992 int non_selected
= 0;
24994 *active_cursor
= 1;
24997 if (cursor_in_echo_area
24998 && FRAME_HAS_MINIBUF_P (f
)
24999 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25001 if (w
== XWINDOW (echo_area_window
))
25003 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25005 *width
= FRAME_CURSOR_WIDTH (f
);
25006 return FRAME_DESIRED_CURSOR (f
);
25009 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25012 *active_cursor
= 0;
25016 /* Detect a nonselected window or nonselected frame. */
25017 else if (w
!= XWINDOW (f
->selected_window
)
25018 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25020 *active_cursor
= 0;
25022 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25028 /* Never display a cursor in a window in which cursor-type is nil. */
25029 if (NILP (BVAR (b
, cursor_type
)))
25032 /* Get the normal cursor type for this window. */
25033 if (EQ (BVAR (b
, cursor_type
), Qt
))
25035 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25036 *width
= FRAME_CURSOR_WIDTH (f
);
25039 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25041 /* Use cursor-in-non-selected-windows instead
25042 for non-selected window or frame. */
25045 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25046 if (!EQ (Qt
, alt_cursor
))
25047 return get_specified_cursor_type (alt_cursor
, width
);
25048 /* t means modify the normal cursor type. */
25049 if (cursor_type
== FILLED_BOX_CURSOR
)
25050 cursor_type
= HOLLOW_BOX_CURSOR
;
25051 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25053 return cursor_type
;
25056 /* Use normal cursor if not blinked off. */
25057 if (!w
->cursor_off_p
)
25059 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25061 if (cursor_type
== FILLED_BOX_CURSOR
)
25063 /* Using a block cursor on large images can be very annoying.
25064 So use a hollow cursor for "large" images.
25065 If image is not transparent (no mask), also use hollow cursor. */
25066 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25067 if (img
!= NULL
&& IMAGEP (img
->spec
))
25069 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25070 where N = size of default frame font size.
25071 This should cover most of the "tiny" icons people may use. */
25073 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25074 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25075 cursor_type
= HOLLOW_BOX_CURSOR
;
25078 else if (cursor_type
!= NO_CURSOR
)
25080 /* Display current only supports BOX and HOLLOW cursors for images.
25081 So for now, unconditionally use a HOLLOW cursor when cursor is
25082 not a solid box cursor. */
25083 cursor_type
= HOLLOW_BOX_CURSOR
;
25086 return cursor_type
;
25089 /* Cursor is blinked off, so determine how to "toggle" it. */
25091 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25092 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25093 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25095 /* Then see if frame has specified a specific blink off cursor type. */
25096 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25098 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25099 return FRAME_BLINK_OFF_CURSOR (f
);
25103 /* Some people liked having a permanently visible blinking cursor,
25104 while others had very strong opinions against it. So it was
25105 decided to remove it. KFS 2003-09-03 */
25107 /* Finally perform built-in cursor blinking:
25108 filled box <-> hollow box
25109 wide [h]bar <-> narrow [h]bar
25110 narrow [h]bar <-> no cursor
25111 other type <-> no cursor */
25113 if (cursor_type
== FILLED_BOX_CURSOR
)
25114 return HOLLOW_BOX_CURSOR
;
25116 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25119 return cursor_type
;
25127 /* Notice when the text cursor of window W has been completely
25128 overwritten by a drawing operation that outputs glyphs in AREA
25129 starting at X0 and ending at X1 in the line starting at Y0 and
25130 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25131 the rest of the line after X0 has been written. Y coordinates
25132 are window-relative. */
25135 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25136 int x0
, int x1
, int y0
, int y1
)
25138 int cx0
, cx1
, cy0
, cy1
;
25139 struct glyph_row
*row
;
25141 if (!w
->phys_cursor_on_p
)
25143 if (area
!= TEXT_AREA
)
25146 if (w
->phys_cursor
.vpos
< 0
25147 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25148 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25149 !(row
->enabled_p
&& row
->displays_text_p
)))
25152 if (row
->cursor_in_fringe_p
)
25154 row
->cursor_in_fringe_p
= 0;
25155 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25156 w
->phys_cursor_on_p
= 0;
25160 cx0
= w
->phys_cursor
.x
;
25161 cx1
= cx0
+ w
->phys_cursor_width
;
25162 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25165 /* The cursor image will be completely removed from the
25166 screen if the output area intersects the cursor area in
25167 y-direction. When we draw in [y0 y1[, and some part of
25168 the cursor is at y < y0, that part must have been drawn
25169 before. When scrolling, the cursor is erased before
25170 actually scrolling, so we don't come here. When not
25171 scrolling, the rows above the old cursor row must have
25172 changed, and in this case these rows must have written
25173 over the cursor image.
25175 Likewise if part of the cursor is below y1, with the
25176 exception of the cursor being in the first blank row at
25177 the buffer and window end because update_text_area
25178 doesn't draw that row. (Except when it does, but
25179 that's handled in update_text_area.) */
25181 cy0
= w
->phys_cursor
.y
;
25182 cy1
= cy0
+ w
->phys_cursor_height
;
25183 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25186 w
->phys_cursor_on_p
= 0;
25189 #endif /* HAVE_WINDOW_SYSTEM */
25192 /************************************************************************
25194 ************************************************************************/
25196 #ifdef HAVE_WINDOW_SYSTEM
25199 Fix the display of area AREA of overlapping row ROW in window W
25200 with respect to the overlapping part OVERLAPS. */
25203 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25204 enum glyph_row_area area
, int overlaps
)
25211 for (i
= 0; i
< row
->used
[area
];)
25213 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25215 int start
= i
, start_x
= x
;
25219 x
+= row
->glyphs
[area
][i
].pixel_width
;
25222 while (i
< row
->used
[area
]
25223 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25225 draw_glyphs (w
, start_x
, row
, area
,
25227 DRAW_NORMAL_TEXT
, overlaps
);
25231 x
+= row
->glyphs
[area
][i
].pixel_width
;
25241 Draw the cursor glyph of window W in glyph row ROW. See the
25242 comment of draw_glyphs for the meaning of HL. */
25245 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25246 enum draw_glyphs_face hl
)
25248 /* If cursor hpos is out of bounds, don't draw garbage. This can
25249 happen in mini-buffer windows when switching between echo area
25250 glyphs and mini-buffer. */
25251 if ((row
->reversed_p
25252 ? (w
->phys_cursor
.hpos
>= 0)
25253 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25255 int on_p
= w
->phys_cursor_on_p
;
25257 int hpos
= w
->phys_cursor
.hpos
;
25259 /* When the window is hscrolled, cursor hpos can legitimately be
25260 out of bounds, but we draw the cursor at the corresponding
25261 window margin in that case. */
25262 if (!row
->reversed_p
&& hpos
< 0)
25264 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25265 hpos
= row
->used
[TEXT_AREA
] - 1;
25267 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25269 w
->phys_cursor_on_p
= on_p
;
25271 if (hl
== DRAW_CURSOR
)
25272 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25273 /* When we erase the cursor, and ROW is overlapped by other
25274 rows, make sure that these overlapping parts of other rows
25276 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25278 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25280 if (row
> w
->current_matrix
->rows
25281 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25282 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25283 OVERLAPS_ERASED_CURSOR
);
25285 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25286 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25287 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25288 OVERLAPS_ERASED_CURSOR
);
25295 Erase the image of a cursor of window W from the screen. */
25298 erase_phys_cursor (struct window
*w
)
25300 struct frame
*f
= XFRAME (w
->frame
);
25301 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25302 int hpos
= w
->phys_cursor
.hpos
;
25303 int vpos
= w
->phys_cursor
.vpos
;
25304 int mouse_face_here_p
= 0;
25305 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25306 struct glyph_row
*cursor_row
;
25307 struct glyph
*cursor_glyph
;
25308 enum draw_glyphs_face hl
;
25310 /* No cursor displayed or row invalidated => nothing to do on the
25312 if (w
->phys_cursor_type
== NO_CURSOR
)
25313 goto mark_cursor_off
;
25315 /* VPOS >= active_glyphs->nrows means that window has been resized.
25316 Don't bother to erase the cursor. */
25317 if (vpos
>= active_glyphs
->nrows
)
25318 goto mark_cursor_off
;
25320 /* If row containing cursor is marked invalid, there is nothing we
25322 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25323 if (!cursor_row
->enabled_p
)
25324 goto mark_cursor_off
;
25326 /* If line spacing is > 0, old cursor may only be partially visible in
25327 window after split-window. So adjust visible height. */
25328 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25329 window_text_bottom_y (w
) - cursor_row
->y
);
25331 /* If row is completely invisible, don't attempt to delete a cursor which
25332 isn't there. This can happen if cursor is at top of a window, and
25333 we switch to a buffer with a header line in that window. */
25334 if (cursor_row
->visible_height
<= 0)
25335 goto mark_cursor_off
;
25337 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25338 if (cursor_row
->cursor_in_fringe_p
)
25340 cursor_row
->cursor_in_fringe_p
= 0;
25341 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25342 goto mark_cursor_off
;
25345 /* This can happen when the new row is shorter than the old one.
25346 In this case, either draw_glyphs or clear_end_of_line
25347 should have cleared the cursor. Note that we wouldn't be
25348 able to erase the cursor in this case because we don't have a
25349 cursor glyph at hand. */
25350 if ((cursor_row
->reversed_p
25351 ? (w
->phys_cursor
.hpos
< 0)
25352 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25353 goto mark_cursor_off
;
25355 /* When the window is hscrolled, cursor hpos can legitimately be out
25356 of bounds, but we draw the cursor at the corresponding window
25357 margin in that case. */
25358 if (!cursor_row
->reversed_p
&& hpos
< 0)
25360 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25361 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25363 /* If the cursor is in the mouse face area, redisplay that when
25364 we clear the cursor. */
25365 if (! NILP (hlinfo
->mouse_face_window
)
25366 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25367 /* Don't redraw the cursor's spot in mouse face if it is at the
25368 end of a line (on a newline). The cursor appears there, but
25369 mouse highlighting does not. */
25370 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25371 mouse_face_here_p
= 1;
25373 /* Maybe clear the display under the cursor. */
25374 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25377 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25380 cursor_glyph
= get_phys_cursor_glyph (w
);
25381 if (cursor_glyph
== NULL
)
25382 goto mark_cursor_off
;
25384 width
= cursor_glyph
->pixel_width
;
25385 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25386 x
= w
->phys_cursor
.x
;
25388 width
-= left_x
- x
;
25389 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25390 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25391 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25394 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25397 /* Erase the cursor by redrawing the character underneath it. */
25398 if (mouse_face_here_p
)
25399 hl
= DRAW_MOUSE_FACE
;
25401 hl
= DRAW_NORMAL_TEXT
;
25402 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25405 w
->phys_cursor_on_p
= 0;
25406 w
->phys_cursor_type
= NO_CURSOR
;
25411 Display or clear cursor of window W. If ON is zero, clear the
25412 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25413 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25416 display_and_set_cursor (struct window
*w
, int on
,
25417 int hpos
, int vpos
, int x
, int y
)
25419 struct frame
*f
= XFRAME (w
->frame
);
25420 int new_cursor_type
;
25421 int new_cursor_width
;
25423 struct glyph_row
*glyph_row
;
25424 struct glyph
*glyph
;
25426 /* This is pointless on invisible frames, and dangerous on garbaged
25427 windows and frames; in the latter case, the frame or window may
25428 be in the midst of changing its size, and x and y may be off the
25430 if (! FRAME_VISIBLE_P (f
)
25431 || FRAME_GARBAGED_P (f
)
25432 || vpos
>= w
->current_matrix
->nrows
25433 || hpos
>= w
->current_matrix
->matrix_w
)
25436 /* If cursor is off and we want it off, return quickly. */
25437 if (!on
&& !w
->phys_cursor_on_p
)
25440 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25441 /* If cursor row is not enabled, we don't really know where to
25442 display the cursor. */
25443 if (!glyph_row
->enabled_p
)
25445 w
->phys_cursor_on_p
= 0;
25450 if (!glyph_row
->exact_window_width_line_p
25451 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25452 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25454 xassert (interrupt_input_blocked
);
25456 /* Set new_cursor_type to the cursor we want to be displayed. */
25457 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25458 &new_cursor_width
, &active_cursor
);
25460 /* If cursor is currently being shown and we don't want it to be or
25461 it is in the wrong place, or the cursor type is not what we want,
25463 if (w
->phys_cursor_on_p
25465 || w
->phys_cursor
.x
!= x
25466 || w
->phys_cursor
.y
!= y
25467 || new_cursor_type
!= w
->phys_cursor_type
25468 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25469 && new_cursor_width
!= w
->phys_cursor_width
)))
25470 erase_phys_cursor (w
);
25472 /* Don't check phys_cursor_on_p here because that flag is only set
25473 to zero in some cases where we know that the cursor has been
25474 completely erased, to avoid the extra work of erasing the cursor
25475 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25476 still not be visible, or it has only been partly erased. */
25479 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25480 w
->phys_cursor_height
= glyph_row
->height
;
25482 /* Set phys_cursor_.* before x_draw_.* is called because some
25483 of them may need the information. */
25484 w
->phys_cursor
.x
= x
;
25485 w
->phys_cursor
.y
= glyph_row
->y
;
25486 w
->phys_cursor
.hpos
= hpos
;
25487 w
->phys_cursor
.vpos
= vpos
;
25490 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25491 new_cursor_type
, new_cursor_width
,
25492 on
, active_cursor
);
25496 /* Switch the display of W's cursor on or off, according to the value
25500 update_window_cursor (struct window
*w
, int on
)
25502 /* Don't update cursor in windows whose frame is in the process
25503 of being deleted. */
25504 if (w
->current_matrix
)
25506 int hpos
= w
->phys_cursor
.hpos
;
25507 int vpos
= w
->phys_cursor
.vpos
;
25508 struct glyph_row
*row
;
25510 if (vpos
>= w
->current_matrix
->nrows
25511 || hpos
>= w
->current_matrix
->matrix_w
)
25514 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25516 /* When the window is hscrolled, cursor hpos can legitimately be
25517 out of bounds, but we draw the cursor at the corresponding
25518 window margin in that case. */
25519 if (!row
->reversed_p
&& hpos
< 0)
25521 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25522 hpos
= row
->used
[TEXT_AREA
] - 1;
25525 display_and_set_cursor (w
, on
, hpos
, vpos
,
25526 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25532 /* Call update_window_cursor with parameter ON_P on all leaf windows
25533 in the window tree rooted at W. */
25536 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25540 if (!NILP (w
->hchild
))
25541 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25542 else if (!NILP (w
->vchild
))
25543 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25545 update_window_cursor (w
, on_p
);
25547 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25553 Display the cursor on window W, or clear it, according to ON_P.
25554 Don't change the cursor's position. */
25557 x_update_cursor (struct frame
*f
, int on_p
)
25559 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25564 Clear the cursor of window W to background color, and mark the
25565 cursor as not shown. This is used when the text where the cursor
25566 is about to be rewritten. */
25569 x_clear_cursor (struct window
*w
)
25571 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25572 update_window_cursor (w
, 0);
25575 #endif /* HAVE_WINDOW_SYSTEM */
25577 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25580 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25581 int start_hpos
, int end_hpos
,
25582 enum draw_glyphs_face draw
)
25584 #ifdef HAVE_WINDOW_SYSTEM
25585 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25587 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25591 #if defined (HAVE_GPM) || defined (MSDOS)
25592 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25596 /* Display the active region described by mouse_face_* according to DRAW. */
25599 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25601 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25602 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25604 if (/* If window is in the process of being destroyed, don't bother
25606 w
->current_matrix
!= NULL
25607 /* Don't update mouse highlight if hidden */
25608 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25609 /* Recognize when we are called to operate on rows that don't exist
25610 anymore. This can happen when a window is split. */
25611 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25613 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25614 struct glyph_row
*row
, *first
, *last
;
25616 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25617 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25619 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25621 int start_hpos
, end_hpos
, start_x
;
25623 /* For all but the first row, the highlight starts at column 0. */
25626 /* R2L rows have BEG and END in reversed order, but the
25627 screen drawing geometry is always left to right. So
25628 we need to mirror the beginning and end of the
25629 highlighted area in R2L rows. */
25630 if (!row
->reversed_p
)
25632 start_hpos
= hlinfo
->mouse_face_beg_col
;
25633 start_x
= hlinfo
->mouse_face_beg_x
;
25635 else if (row
== last
)
25637 start_hpos
= hlinfo
->mouse_face_end_col
;
25638 start_x
= hlinfo
->mouse_face_end_x
;
25646 else if (row
->reversed_p
&& row
== last
)
25648 start_hpos
= hlinfo
->mouse_face_end_col
;
25649 start_x
= hlinfo
->mouse_face_end_x
;
25659 if (!row
->reversed_p
)
25660 end_hpos
= hlinfo
->mouse_face_end_col
;
25661 else if (row
== first
)
25662 end_hpos
= hlinfo
->mouse_face_beg_col
;
25665 end_hpos
= row
->used
[TEXT_AREA
];
25666 if (draw
== DRAW_NORMAL_TEXT
)
25667 row
->fill_line_p
= 1; /* Clear to end of line */
25670 else if (row
->reversed_p
&& row
== first
)
25671 end_hpos
= hlinfo
->mouse_face_beg_col
;
25674 end_hpos
= row
->used
[TEXT_AREA
];
25675 if (draw
== DRAW_NORMAL_TEXT
)
25676 row
->fill_line_p
= 1; /* Clear to end of line */
25679 if (end_hpos
> start_hpos
)
25681 draw_row_with_mouse_face (w
, start_x
, row
,
25682 start_hpos
, end_hpos
, draw
);
25685 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
25689 #ifdef HAVE_WINDOW_SYSTEM
25690 /* When we've written over the cursor, arrange for it to
25691 be displayed again. */
25692 if (FRAME_WINDOW_P (f
)
25693 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
25695 int hpos
= w
->phys_cursor
.hpos
;
25697 /* When the window is hscrolled, cursor hpos can legitimately be
25698 out of bounds, but we draw the cursor at the corresponding
25699 window margin in that case. */
25700 if (!row
->reversed_p
&& hpos
< 0)
25702 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25703 hpos
= row
->used
[TEXT_AREA
] - 1;
25706 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
25707 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25710 #endif /* HAVE_WINDOW_SYSTEM */
25713 #ifdef HAVE_WINDOW_SYSTEM
25714 /* Change the mouse cursor. */
25715 if (FRAME_WINDOW_P (f
))
25717 if (draw
== DRAW_NORMAL_TEXT
25718 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
25719 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
25720 else if (draw
== DRAW_MOUSE_FACE
)
25721 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
25723 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
25725 #endif /* HAVE_WINDOW_SYSTEM */
25729 Clear out the mouse-highlighted active region.
25730 Redraw it un-highlighted first. Value is non-zero if mouse
25731 face was actually drawn unhighlighted. */
25734 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
25738 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
25740 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
25744 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25745 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25746 hlinfo
->mouse_face_window
= Qnil
;
25747 hlinfo
->mouse_face_overlay
= Qnil
;
25751 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
25752 within the mouse face on that window. */
25754 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
25756 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25758 /* Quickly resolve the easy cases. */
25759 if (!(WINDOWP (hlinfo
->mouse_face_window
)
25760 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
25762 if (vpos
< hlinfo
->mouse_face_beg_row
25763 || vpos
> hlinfo
->mouse_face_end_row
)
25765 if (vpos
> hlinfo
->mouse_face_beg_row
25766 && vpos
< hlinfo
->mouse_face_end_row
)
25769 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
25771 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25773 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
25776 else if ((vpos
== hlinfo
->mouse_face_beg_row
25777 && hpos
>= hlinfo
->mouse_face_beg_col
)
25778 || (vpos
== hlinfo
->mouse_face_end_row
25779 && hpos
< hlinfo
->mouse_face_end_col
))
25784 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25786 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
25789 else if ((vpos
== hlinfo
->mouse_face_beg_row
25790 && hpos
<= hlinfo
->mouse_face_beg_col
)
25791 || (vpos
== hlinfo
->mouse_face_end_row
25792 && hpos
> hlinfo
->mouse_face_end_col
))
25800 Non-zero if physical cursor of window W is within mouse face. */
25803 cursor_in_mouse_face_p (struct window
*w
)
25805 int hpos
= w
->phys_cursor
.hpos
;
25806 int vpos
= w
->phys_cursor
.vpos
;
25807 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25809 /* When the window is hscrolled, cursor hpos can legitimately be out
25810 of bounds, but we draw the cursor at the corresponding window
25811 margin in that case. */
25812 if (!row
->reversed_p
&& hpos
< 0)
25814 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25815 hpos
= row
->used
[TEXT_AREA
] - 1;
25817 return coords_in_mouse_face_p (w
, hpos
, vpos
);
25822 /* Find the glyph rows START_ROW and END_ROW of window W that display
25823 characters between buffer positions START_CHARPOS and END_CHARPOS
25824 (excluding END_CHARPOS). This is similar to row_containing_pos,
25825 but is more accurate when bidi reordering makes buffer positions
25826 change non-linearly with glyph rows. */
25828 rows_from_pos_range (struct window
*w
,
25829 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
25830 struct glyph_row
**start
, struct glyph_row
**end
)
25832 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25833 int last_y
= window_text_bottom_y (w
);
25834 struct glyph_row
*row
;
25839 while (!first
->enabled_p
25840 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
25843 /* Find the START row. */
25845 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
25848 /* A row can potentially be the START row if the range of the
25849 characters it displays intersects the range
25850 [START_CHARPOS..END_CHARPOS). */
25851 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
25852 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
25853 /* See the commentary in row_containing_pos, for the
25854 explanation of the complicated way to check whether
25855 some position is beyond the end of the characters
25856 displayed by a row. */
25857 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25858 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25859 && !row
->ends_at_zv_p
25860 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
25861 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25862 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25863 && !row
->ends_at_zv_p
25864 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
25866 /* Found a candidate row. Now make sure at least one of the
25867 glyphs it displays has a charpos from the range
25868 [START_CHARPOS..END_CHARPOS).
25870 This is not obvious because bidi reordering could make
25871 buffer positions of a row be 1,2,3,102,101,100, and if we
25872 want to highlight characters in [50..60), we don't want
25873 this row, even though [50..60) does intersect [1..103),
25874 the range of character positions given by the row's start
25875 and end positions. */
25876 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
25877 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
25881 if ((BUFFERP (g
->object
) || INTEGERP (g
->object
))
25882 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
25891 /* Find the END row. */
25893 /* If the last row is partially visible, start looking for END
25894 from that row, instead of starting from FIRST. */
25895 && !(row
->enabled_p
25896 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
25898 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
25900 struct glyph_row
*next
= row
+ 1;
25902 if (!next
->enabled_p
25903 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
25904 /* The first row >= START whose range of displayed characters
25905 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
25906 is the row END + 1. */
25907 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
25908 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
25909 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
25910 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
25911 && !next
->ends_at_zv_p
25912 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
25913 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
25914 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
25915 && !next
->ends_at_zv_p
25916 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
25923 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
25924 but none of the characters it displays are in the range, it is
25926 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
25927 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
25931 if ((BUFFERP (g
->object
) || INTEGERP (g
->object
))
25932 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
25945 /* This function sets the mouse_face_* elements of HLINFO, assuming
25946 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
25947 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
25948 for the overlay or run of text properties specifying the mouse
25949 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
25950 before-string and after-string that must also be highlighted.
25951 DISP_STRING, if non-nil, is a display string that may cover some
25952 or all of the highlighted text. */
25955 mouse_face_from_buffer_pos (Lisp_Object window
,
25956 Mouse_HLInfo
*hlinfo
,
25957 ptrdiff_t mouse_charpos
,
25958 ptrdiff_t start_charpos
,
25959 ptrdiff_t end_charpos
,
25960 Lisp_Object before_string
,
25961 Lisp_Object after_string
,
25962 Lisp_Object disp_string
)
25964 struct window
*w
= XWINDOW (window
);
25965 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25966 struct glyph_row
*r1
, *r2
;
25967 struct glyph
*glyph
, *end
;
25968 ptrdiff_t ignore
, pos
;
25971 xassert (NILP (disp_string
) || STRINGP (disp_string
));
25972 xassert (NILP (before_string
) || STRINGP (before_string
));
25973 xassert (NILP (after_string
) || STRINGP (after_string
));
25975 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
25976 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
25978 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25979 /* If the before-string or display-string contains newlines,
25980 rows_from_pos_range skips to its last row. Move back. */
25981 if (!NILP (before_string
) || !NILP (disp_string
))
25983 struct glyph_row
*prev
;
25984 while ((prev
= r1
- 1, prev
>= first
)
25985 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
25986 && prev
->used
[TEXT_AREA
] > 0)
25988 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
25989 glyph
= beg
+ prev
->used
[TEXT_AREA
];
25990 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
25992 || !(EQ (glyph
->object
, before_string
)
25993 || EQ (glyph
->object
, disp_string
)))
26000 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26001 hlinfo
->mouse_face_past_end
= 1;
26003 else if (!NILP (after_string
))
26005 /* If the after-string has newlines, advance to its last row. */
26006 struct glyph_row
*next
;
26007 struct glyph_row
*last
26008 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26010 for (next
= r2
+ 1;
26012 && next
->used
[TEXT_AREA
] > 0
26013 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26017 /* The rest of the display engine assumes that mouse_face_beg_row is
26018 either above mouse_face_end_row or identical to it. But with
26019 bidi-reordered continued lines, the row for START_CHARPOS could
26020 be below the row for END_CHARPOS. If so, swap the rows and store
26021 them in correct order. */
26024 struct glyph_row
*tem
= r2
;
26030 hlinfo
->mouse_face_beg_y
= r1
->y
;
26031 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26032 hlinfo
->mouse_face_end_y
= r2
->y
;
26033 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26035 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26036 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26037 could be anywhere in the row and in any order. The strategy
26038 below is to find the leftmost and the rightmost glyph that
26039 belongs to either of these 3 strings, or whose position is
26040 between START_CHARPOS and END_CHARPOS, and highlight all the
26041 glyphs between those two. This may cover more than just the text
26042 between START_CHARPOS and END_CHARPOS if the range of characters
26043 strides the bidi level boundary, e.g. if the beginning is in R2L
26044 text while the end is in L2R text or vice versa. */
26045 if (!r1
->reversed_p
)
26047 /* This row is in a left to right paragraph. Scan it left to
26049 glyph
= r1
->glyphs
[TEXT_AREA
];
26050 end
= glyph
+ r1
->used
[TEXT_AREA
];
26053 /* Skip truncation glyphs at the start of the glyph row. */
26054 if (r1
->displays_text_p
)
26056 && INTEGERP (glyph
->object
)
26057 && glyph
->charpos
< 0;
26059 x
+= glyph
->pixel_width
;
26061 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26062 or DISP_STRING, and the first glyph from buffer whose
26063 position is between START_CHARPOS and END_CHARPOS. */
26065 && !INTEGERP (glyph
->object
)
26066 && !EQ (glyph
->object
, disp_string
)
26067 && !(BUFFERP (glyph
->object
)
26068 && (glyph
->charpos
>= start_charpos
26069 && glyph
->charpos
< end_charpos
));
26072 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26073 are present at buffer positions between START_CHARPOS and
26074 END_CHARPOS, or if they come from an overlay. */
26075 if (EQ (glyph
->object
, before_string
))
26077 pos
= string_buffer_position (before_string
,
26079 /* If pos == 0, it means before_string came from an
26080 overlay, not from a buffer position. */
26081 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26084 else if (EQ (glyph
->object
, after_string
))
26086 pos
= string_buffer_position (after_string
, end_charpos
);
26087 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26090 x
+= glyph
->pixel_width
;
26092 hlinfo
->mouse_face_beg_x
= x
;
26093 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26097 /* This row is in a right to left paragraph. Scan it right to
26101 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26102 glyph
= end
+ r1
->used
[TEXT_AREA
];
26104 /* Skip truncation glyphs at the start of the glyph row. */
26105 if (r1
->displays_text_p
)
26107 && INTEGERP (glyph
->object
)
26108 && glyph
->charpos
< 0;
26112 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26113 or DISP_STRING, and the first glyph from buffer whose
26114 position is between START_CHARPOS and END_CHARPOS. */
26116 && !INTEGERP (glyph
->object
)
26117 && !EQ (glyph
->object
, disp_string
)
26118 && !(BUFFERP (glyph
->object
)
26119 && (glyph
->charpos
>= start_charpos
26120 && glyph
->charpos
< end_charpos
));
26123 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26124 are present at buffer positions between START_CHARPOS and
26125 END_CHARPOS, or if they come from an overlay. */
26126 if (EQ (glyph
->object
, before_string
))
26128 pos
= string_buffer_position (before_string
, start_charpos
);
26129 /* If pos == 0, it means before_string came from an
26130 overlay, not from a buffer position. */
26131 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26134 else if (EQ (glyph
->object
, after_string
))
26136 pos
= string_buffer_position (after_string
, end_charpos
);
26137 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26142 glyph
++; /* first glyph to the right of the highlighted area */
26143 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26144 x
+= g
->pixel_width
;
26145 hlinfo
->mouse_face_beg_x
= x
;
26146 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26149 /* If the highlight ends in a different row, compute GLYPH and END
26150 for the end row. Otherwise, reuse the values computed above for
26151 the row where the highlight begins. */
26154 if (!r2
->reversed_p
)
26156 glyph
= r2
->glyphs
[TEXT_AREA
];
26157 end
= glyph
+ r2
->used
[TEXT_AREA
];
26162 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26163 glyph
= end
+ r2
->used
[TEXT_AREA
];
26167 if (!r2
->reversed_p
)
26169 /* Skip truncation and continuation glyphs near the end of the
26170 row, and also blanks and stretch glyphs inserted by
26171 extend_face_to_end_of_line. */
26173 && INTEGERP ((end
- 1)->object
))
26175 /* Scan the rest of the glyph row from the end, looking for the
26176 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26177 DISP_STRING, or whose position is between START_CHARPOS
26181 && !INTEGERP (end
->object
)
26182 && !EQ (end
->object
, disp_string
)
26183 && !(BUFFERP (end
->object
)
26184 && (end
->charpos
>= start_charpos
26185 && end
->charpos
< end_charpos
));
26188 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26189 are present at buffer positions between START_CHARPOS and
26190 END_CHARPOS, or if they come from an overlay. */
26191 if (EQ (end
->object
, before_string
))
26193 pos
= string_buffer_position (before_string
, start_charpos
);
26194 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26197 else if (EQ (end
->object
, after_string
))
26199 pos
= string_buffer_position (after_string
, end_charpos
);
26200 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26204 /* Find the X coordinate of the last glyph to be highlighted. */
26205 for (; glyph
<= end
; ++glyph
)
26206 x
+= glyph
->pixel_width
;
26208 hlinfo
->mouse_face_end_x
= x
;
26209 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26213 /* Skip truncation and continuation glyphs near the end of the
26214 row, and also blanks and stretch glyphs inserted by
26215 extend_face_to_end_of_line. */
26219 && INTEGERP (end
->object
))
26221 x
+= end
->pixel_width
;
26224 /* Scan the rest of the glyph row from the end, looking for the
26225 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26226 DISP_STRING, or whose position is between START_CHARPOS
26230 && !INTEGERP (end
->object
)
26231 && !EQ (end
->object
, disp_string
)
26232 && !(BUFFERP (end
->object
)
26233 && (end
->charpos
>= start_charpos
26234 && end
->charpos
< end_charpos
));
26237 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26238 are present at buffer positions between START_CHARPOS and
26239 END_CHARPOS, or if they come from an overlay. */
26240 if (EQ (end
->object
, before_string
))
26242 pos
= string_buffer_position (before_string
, start_charpos
);
26243 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26246 else if (EQ (end
->object
, after_string
))
26248 pos
= string_buffer_position (after_string
, end_charpos
);
26249 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26252 x
+= end
->pixel_width
;
26254 hlinfo
->mouse_face_end_x
= x
;
26255 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26258 hlinfo
->mouse_face_window
= window
;
26259 hlinfo
->mouse_face_face_id
26260 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26262 !hlinfo
->mouse_face_hidden
, -1);
26263 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26266 /* The following function is not used anymore (replaced with
26267 mouse_face_from_string_pos), but I leave it here for the time
26268 being, in case someone would. */
26270 #if 0 /* not used */
26272 /* Find the position of the glyph for position POS in OBJECT in
26273 window W's current matrix, and return in *X, *Y the pixel
26274 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26276 RIGHT_P non-zero means return the position of the right edge of the
26277 glyph, RIGHT_P zero means return the left edge position.
26279 If no glyph for POS exists in the matrix, return the position of
26280 the glyph with the next smaller position that is in the matrix, if
26281 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26282 exists in the matrix, return the position of the glyph with the
26283 next larger position in OBJECT.
26285 Value is non-zero if a glyph was found. */
26288 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26289 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26291 int yb
= window_text_bottom_y (w
);
26292 struct glyph_row
*r
;
26293 struct glyph
*best_glyph
= NULL
;
26294 struct glyph_row
*best_row
= NULL
;
26297 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26298 r
->enabled_p
&& r
->y
< yb
;
26301 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26302 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26305 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26306 if (EQ (g
->object
, object
))
26308 if (g
->charpos
== pos
)
26315 else if (best_glyph
== NULL
26316 || ((eabs (g
->charpos
- pos
)
26317 < eabs (best_glyph
->charpos
- pos
))
26320 : g
->charpos
> pos
)))
26334 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26338 *x
+= best_glyph
->pixel_width
;
26343 *vpos
= best_row
- w
->current_matrix
->rows
;
26346 return best_glyph
!= NULL
;
26348 #endif /* not used */
26350 /* Find the positions of the first and the last glyphs in window W's
26351 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26352 (assumed to be a string), and return in HLINFO's mouse_face_*
26353 members the pixel and column/row coordinates of those glyphs. */
26356 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26357 Lisp_Object object
,
26358 ptrdiff_t startpos
, ptrdiff_t endpos
)
26360 int yb
= window_text_bottom_y (w
);
26361 struct glyph_row
*r
;
26362 struct glyph
*g
, *e
;
26366 /* Find the glyph row with at least one position in the range
26367 [STARTPOS..ENDPOS], and the first glyph in that row whose
26368 position belongs to that range. */
26369 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26370 r
->enabled_p
&& r
->y
< yb
;
26373 if (!r
->reversed_p
)
26375 g
= r
->glyphs
[TEXT_AREA
];
26376 e
= g
+ r
->used
[TEXT_AREA
];
26377 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26378 if (EQ (g
->object
, object
)
26379 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26381 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26382 hlinfo
->mouse_face_beg_y
= r
->y
;
26383 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26384 hlinfo
->mouse_face_beg_x
= gx
;
26393 e
= r
->glyphs
[TEXT_AREA
];
26394 g
= e
+ r
->used
[TEXT_AREA
];
26395 for ( ; g
> e
; --g
)
26396 if (EQ ((g
-1)->object
, object
)
26397 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26399 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26400 hlinfo
->mouse_face_beg_y
= r
->y
;
26401 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26402 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26403 gx
+= g1
->pixel_width
;
26404 hlinfo
->mouse_face_beg_x
= gx
;
26416 /* Starting with the next row, look for the first row which does NOT
26417 include any glyphs whose positions are in the range. */
26418 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26420 g
= r
->glyphs
[TEXT_AREA
];
26421 e
= g
+ r
->used
[TEXT_AREA
];
26423 for ( ; g
< e
; ++g
)
26424 if (EQ (g
->object
, object
)
26425 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26434 /* The highlighted region ends on the previous row. */
26437 /* Set the end row and its vertical pixel coordinate. */
26438 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26439 hlinfo
->mouse_face_end_y
= r
->y
;
26441 /* Compute and set the end column and the end column's horizontal
26442 pixel coordinate. */
26443 if (!r
->reversed_p
)
26445 g
= r
->glyphs
[TEXT_AREA
];
26446 e
= g
+ r
->used
[TEXT_AREA
];
26447 for ( ; e
> g
; --e
)
26448 if (EQ ((e
-1)->object
, object
)
26449 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26451 hlinfo
->mouse_face_end_col
= e
- g
;
26453 for (gx
= r
->x
; g
< e
; ++g
)
26454 gx
+= g
->pixel_width
;
26455 hlinfo
->mouse_face_end_x
= gx
;
26459 e
= r
->glyphs
[TEXT_AREA
];
26460 g
= e
+ r
->used
[TEXT_AREA
];
26461 for (gx
= r
->x
; e
< g
; ++e
)
26463 if (EQ (e
->object
, object
)
26464 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26466 gx
+= e
->pixel_width
;
26468 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26469 hlinfo
->mouse_face_end_x
= gx
;
26473 #ifdef HAVE_WINDOW_SYSTEM
26475 /* See if position X, Y is within a hot-spot of an image. */
26478 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26480 if (!CONSP (hot_spot
))
26483 if (EQ (XCAR (hot_spot
), Qrect
))
26485 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26486 Lisp_Object rect
= XCDR (hot_spot
);
26490 if (!CONSP (XCAR (rect
)))
26492 if (!CONSP (XCDR (rect
)))
26494 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26496 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26498 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26500 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26504 else if (EQ (XCAR (hot_spot
), Qcircle
))
26506 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26507 Lisp_Object circ
= XCDR (hot_spot
);
26508 Lisp_Object lr
, lx0
, ly0
;
26510 && CONSP (XCAR (circ
))
26511 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26512 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26513 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26515 double r
= XFLOATINT (lr
);
26516 double dx
= XINT (lx0
) - x
;
26517 double dy
= XINT (ly0
) - y
;
26518 return (dx
* dx
+ dy
* dy
<= r
* r
);
26521 else if (EQ (XCAR (hot_spot
), Qpoly
))
26523 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26524 if (VECTORP (XCDR (hot_spot
)))
26526 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26527 Lisp_Object
*poly
= v
->contents
;
26528 ptrdiff_t n
= v
->header
.size
;
26531 Lisp_Object lx
, ly
;
26534 /* Need an even number of coordinates, and at least 3 edges. */
26535 if (n
< 6 || n
& 1)
26538 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26539 If count is odd, we are inside polygon. Pixels on edges
26540 may or may not be included depending on actual geometry of the
26542 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26543 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26545 x0
= XINT (lx
), y0
= XINT (ly
);
26546 for (i
= 0; i
< n
; i
+= 2)
26548 int x1
= x0
, y1
= y0
;
26549 if ((lx
= poly
[i
], !INTEGERP (lx
))
26550 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26552 x0
= XINT (lx
), y0
= XINT (ly
);
26554 /* Does this segment cross the X line? */
26562 if (y
> y0
&& y
> y1
)
26564 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26574 find_hot_spot (Lisp_Object map
, int x
, int y
)
26576 while (CONSP (map
))
26578 if (CONSP (XCAR (map
))
26579 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26587 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26589 doc
: /* Lookup in image map MAP coordinates X and Y.
26590 An image map is an alist where each element has the format (AREA ID PLIST).
26591 An AREA is specified as either a rectangle, a circle, or a polygon:
26592 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26593 pixel coordinates of the upper left and bottom right corners.
26594 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26595 and the radius of the circle; r may be a float or integer.
26596 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26597 vector describes one corner in the polygon.
26598 Returns the alist element for the first matching AREA in MAP. */)
26599 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26607 return find_hot_spot (map
,
26608 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
26609 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
26613 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26615 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26617 /* Do not change cursor shape while dragging mouse. */
26618 if (!NILP (do_mouse_tracking
))
26621 if (!NILP (pointer
))
26623 if (EQ (pointer
, Qarrow
))
26624 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26625 else if (EQ (pointer
, Qhand
))
26626 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
26627 else if (EQ (pointer
, Qtext
))
26628 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26629 else if (EQ (pointer
, intern ("hdrag")))
26630 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26631 #ifdef HAVE_X_WINDOWS
26632 else if (EQ (pointer
, intern ("vdrag")))
26633 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
26635 else if (EQ (pointer
, intern ("hourglass")))
26636 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
26637 else if (EQ (pointer
, Qmodeline
))
26638 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
26640 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26643 if (cursor
!= No_Cursor
)
26644 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
26647 #endif /* HAVE_WINDOW_SYSTEM */
26649 /* Take proper action when mouse has moved to the mode or header line
26650 or marginal area AREA of window W, x-position X and y-position Y.
26651 X is relative to the start of the text display area of W, so the
26652 width of bitmap areas and scroll bars must be subtracted to get a
26653 position relative to the start of the mode line. */
26656 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
26657 enum window_part area
)
26659 struct window
*w
= XWINDOW (window
);
26660 struct frame
*f
= XFRAME (w
->frame
);
26661 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26662 #ifdef HAVE_WINDOW_SYSTEM
26663 Display_Info
*dpyinfo
;
26665 Cursor cursor
= No_Cursor
;
26666 Lisp_Object pointer
= Qnil
;
26667 int dx
, dy
, width
, height
;
26669 Lisp_Object string
, object
= Qnil
;
26670 Lisp_Object pos
, help
;
26672 Lisp_Object mouse_face
;
26673 int original_x_pixel
= x
;
26674 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
26675 struct glyph_row
*row
;
26677 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
26682 /* Kludge alert: mode_line_string takes X/Y in pixels, but
26683 returns them in row/column units! */
26684 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
26685 &object
, &dx
, &dy
, &width
, &height
);
26687 row
= (area
== ON_MODE_LINE
26688 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
26689 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
26691 /* Find the glyph under the mouse pointer. */
26692 if (row
->mode_line_p
&& row
->enabled_p
)
26694 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
26695 end
= glyph
+ row
->used
[TEXT_AREA
];
26697 for (x0
= original_x_pixel
;
26698 glyph
< end
&& x0
>= glyph
->pixel_width
;
26700 x0
-= glyph
->pixel_width
;
26708 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
26709 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
26710 returns them in row/column units! */
26711 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
26712 &object
, &dx
, &dy
, &width
, &height
);
26717 #ifdef HAVE_WINDOW_SYSTEM
26718 if (IMAGEP (object
))
26720 Lisp_Object image_map
, hotspot
;
26721 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
26723 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
26725 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26729 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
26730 If so, we could look for mouse-enter, mouse-leave
26731 properties in PLIST (and do something...). */
26732 hotspot
= XCDR (hotspot
);
26733 if (CONSP (hotspot
)
26734 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26736 pointer
= Fplist_get (plist
, Qpointer
);
26737 if (NILP (pointer
))
26739 help
= Fplist_get (plist
, Qhelp_echo
);
26742 help_echo_string
= help
;
26743 /* Is this correct? ++kfs */
26744 XSETWINDOW (help_echo_window
, w
);
26745 help_echo_object
= w
->buffer
;
26746 help_echo_pos
= charpos
;
26750 if (NILP (pointer
))
26751 pointer
= Fplist_get (XCDR (object
), QCpointer
);
26753 #endif /* HAVE_WINDOW_SYSTEM */
26755 if (STRINGP (string
))
26757 pos
= make_number (charpos
);
26758 /* If we're on a string with `help-echo' text property, arrange
26759 for the help to be displayed. This is done by setting the
26760 global variable help_echo_string to the help string. */
26763 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
26766 help_echo_string
= help
;
26767 XSETWINDOW (help_echo_window
, w
);
26768 help_echo_object
= string
;
26769 help_echo_pos
= charpos
;
26773 #ifdef HAVE_WINDOW_SYSTEM
26774 if (FRAME_WINDOW_P (f
))
26776 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
26777 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26778 if (NILP (pointer
))
26779 pointer
= Fget_text_property (pos
, Qpointer
, string
);
26781 /* Change the mouse pointer according to what is under X/Y. */
26783 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
26786 map
= Fget_text_property (pos
, Qlocal_map
, string
);
26787 if (!KEYMAPP (map
))
26788 map
= Fget_text_property (pos
, Qkeymap
, string
);
26789 if (!KEYMAPP (map
))
26790 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
26795 /* Change the mouse face according to what is under X/Y. */
26796 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
26797 if (!NILP (mouse_face
)
26798 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26803 struct glyph
* tmp_glyph
;
26807 int total_pixel_width
;
26808 ptrdiff_t begpos
, endpos
, ignore
;
26812 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
26813 Qmouse_face
, string
, Qnil
);
26819 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
26821 endpos
= SCHARS (string
);
26825 /* Calculate the glyph position GPOS of GLYPH in the
26826 displayed string, relative to the beginning of the
26827 highlighted part of the string.
26829 Note: GPOS is different from CHARPOS. CHARPOS is the
26830 position of GLYPH in the internal string object. A mode
26831 line string format has structures which are converted to
26832 a flattened string by the Emacs Lisp interpreter. The
26833 internal string is an element of those structures. The
26834 displayed string is the flattened string. */
26835 tmp_glyph
= row_start_glyph
;
26836 while (tmp_glyph
< glyph
26837 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
26838 && begpos
<= tmp_glyph
->charpos
26839 && tmp_glyph
->charpos
< endpos
)))
26841 gpos
= glyph
- tmp_glyph
;
26843 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
26844 the highlighted part of the displayed string to which
26845 GLYPH belongs. Note: GSEQ_LENGTH is different from
26846 SCHARS (STRING), because the latter returns the length of
26847 the internal string. */
26848 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
26850 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
26851 && begpos
<= tmp_glyph
->charpos
26852 && tmp_glyph
->charpos
< endpos
));
26855 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
26857 /* Calculate the total pixel width of all the glyphs between
26858 the beginning of the highlighted area and GLYPH. */
26859 total_pixel_width
= 0;
26860 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
26861 total_pixel_width
+= tmp_glyph
->pixel_width
;
26863 /* Pre calculation of re-rendering position. Note: X is in
26864 column units here, after the call to mode_line_string or
26865 marginal_area_string. */
26867 vpos
= (area
== ON_MODE_LINE
26868 ? (w
->current_matrix
)->nrows
- 1
26871 /* If GLYPH's position is included in the region that is
26872 already drawn in mouse face, we have nothing to do. */
26873 if ( EQ (window
, hlinfo
->mouse_face_window
)
26874 && (!row
->reversed_p
26875 ? (hlinfo
->mouse_face_beg_col
<= hpos
26876 && hpos
< hlinfo
->mouse_face_end_col
)
26877 /* In R2L rows we swap BEG and END, see below. */
26878 : (hlinfo
->mouse_face_end_col
<= hpos
26879 && hpos
< hlinfo
->mouse_face_beg_col
))
26880 && hlinfo
->mouse_face_beg_row
== vpos
)
26883 if (clear_mouse_face (hlinfo
))
26884 cursor
= No_Cursor
;
26886 if (!row
->reversed_p
)
26888 hlinfo
->mouse_face_beg_col
= hpos
;
26889 hlinfo
->mouse_face_beg_x
= original_x_pixel
26890 - (total_pixel_width
+ dx
);
26891 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
26892 hlinfo
->mouse_face_end_x
= 0;
26896 /* In R2L rows, show_mouse_face expects BEG and END
26897 coordinates to be swapped. */
26898 hlinfo
->mouse_face_end_col
= hpos
;
26899 hlinfo
->mouse_face_end_x
= original_x_pixel
26900 - (total_pixel_width
+ dx
);
26901 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
26902 hlinfo
->mouse_face_beg_x
= 0;
26905 hlinfo
->mouse_face_beg_row
= vpos
;
26906 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
26907 hlinfo
->mouse_face_beg_y
= 0;
26908 hlinfo
->mouse_face_end_y
= 0;
26909 hlinfo
->mouse_face_past_end
= 0;
26910 hlinfo
->mouse_face_window
= window
;
26912 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
26918 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26920 if (NILP (pointer
))
26923 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26924 clear_mouse_face (hlinfo
);
26926 #ifdef HAVE_WINDOW_SYSTEM
26927 if (FRAME_WINDOW_P (f
))
26928 define_frame_cursor1 (f
, cursor
, pointer
);
26934 Take proper action when the mouse has moved to position X, Y on
26935 frame F as regards highlighting characters that have mouse-face
26936 properties. Also de-highlighting chars where the mouse was before.
26937 X and Y can be negative or out of range. */
26940 note_mouse_highlight (struct frame
*f
, int x
, int y
)
26942 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26943 enum window_part part
= ON_NOTHING
;
26944 Lisp_Object window
;
26946 Cursor cursor
= No_Cursor
;
26947 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
26950 /* When a menu is active, don't highlight because this looks odd. */
26951 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
26952 if (popup_activated ())
26956 if (NILP (Vmouse_highlight
)
26957 || !f
->glyphs_initialized_p
26958 || f
->pointer_invisible
)
26961 hlinfo
->mouse_face_mouse_x
= x
;
26962 hlinfo
->mouse_face_mouse_y
= y
;
26963 hlinfo
->mouse_face_mouse_frame
= f
;
26965 if (hlinfo
->mouse_face_defer
)
26968 if (gc_in_progress
)
26970 hlinfo
->mouse_face_deferred_gc
= 1;
26974 /* Which window is that in? */
26975 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
26977 /* If displaying active text in another window, clear that. */
26978 if (! EQ (window
, hlinfo
->mouse_face_window
)
26979 /* Also clear if we move out of text area in same window. */
26980 || (!NILP (hlinfo
->mouse_face_window
)
26983 && part
!= ON_MODE_LINE
26984 && part
!= ON_HEADER_LINE
))
26985 clear_mouse_face (hlinfo
);
26987 /* Not on a window -> return. */
26988 if (!WINDOWP (window
))
26991 /* Reset help_echo_string. It will get recomputed below. */
26992 help_echo_string
= Qnil
;
26994 /* Convert to window-relative pixel coordinates. */
26995 w
= XWINDOW (window
);
26996 frame_to_window_pixel_xy (w
, &x
, &y
);
26998 #ifdef HAVE_WINDOW_SYSTEM
26999 /* Handle tool-bar window differently since it doesn't display a
27001 if (EQ (window
, f
->tool_bar_window
))
27003 note_tool_bar_highlight (f
, x
, y
);
27008 /* Mouse is on the mode, header line or margin? */
27009 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27010 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27012 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27016 #ifdef HAVE_WINDOW_SYSTEM
27017 if (part
== ON_VERTICAL_BORDER
)
27019 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27020 help_echo_string
= build_string ("drag-mouse-1: resize");
27022 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27023 || part
== ON_SCROLL_BAR
)
27024 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27026 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27029 /* Are we in a window whose display is up to date?
27030 And verify the buffer's text has not changed. */
27031 b
= XBUFFER (w
->buffer
);
27032 if (part
== ON_TEXT
27033 && EQ (w
->window_end_valid
, w
->buffer
)
27034 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
27035 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
27037 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27039 struct glyph
*glyph
;
27040 Lisp_Object object
;
27041 Lisp_Object mouse_face
= Qnil
, position
;
27042 Lisp_Object
*overlay_vec
= NULL
;
27043 ptrdiff_t i
, noverlays
;
27044 struct buffer
*obuf
;
27045 ptrdiff_t obegv
, ozv
;
27048 /* Find the glyph under X/Y. */
27049 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27051 #ifdef HAVE_WINDOW_SYSTEM
27052 /* Look for :pointer property on image. */
27053 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27055 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27056 if (img
!= NULL
&& IMAGEP (img
->spec
))
27058 Lisp_Object image_map
, hotspot
;
27059 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27061 && (hotspot
= find_hot_spot (image_map
,
27062 glyph
->slice
.img
.x
+ dx
,
27063 glyph
->slice
.img
.y
+ dy
),
27065 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27069 /* Could check XCAR (hotspot) to see if we enter/leave
27071 If so, we could look for mouse-enter, mouse-leave
27072 properties in PLIST (and do something...). */
27073 hotspot
= XCDR (hotspot
);
27074 if (CONSP (hotspot
)
27075 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27077 pointer
= Fplist_get (plist
, Qpointer
);
27078 if (NILP (pointer
))
27080 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27081 if (!NILP (help_echo_string
))
27083 help_echo_window
= window
;
27084 help_echo_object
= glyph
->object
;
27085 help_echo_pos
= glyph
->charpos
;
27089 if (NILP (pointer
))
27090 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27093 #endif /* HAVE_WINDOW_SYSTEM */
27095 /* Clear mouse face if X/Y not over text. */
27097 || area
!= TEXT_AREA
27098 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27099 /* Glyph's OBJECT is an integer for glyphs inserted by the
27100 display engine for its internal purposes, like truncation
27101 and continuation glyphs and blanks beyond the end of
27102 line's text on text terminals. If we are over such a
27103 glyph, we are not over any text. */
27104 || INTEGERP (glyph
->object
)
27105 /* R2L rows have a stretch glyph at their front, which
27106 stands for no text, whereas L2R rows have no glyphs at
27107 all beyond the end of text. Treat such stretch glyphs
27108 like we do with NULL glyphs in L2R rows. */
27109 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27110 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27111 && glyph
->type
== STRETCH_GLYPH
27112 && glyph
->avoid_cursor_p
))
27114 if (clear_mouse_face (hlinfo
))
27115 cursor
= No_Cursor
;
27116 #ifdef HAVE_WINDOW_SYSTEM
27117 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27119 if (area
!= TEXT_AREA
)
27120 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27122 pointer
= Vvoid_text_area_pointer
;
27128 pos
= glyph
->charpos
;
27129 object
= glyph
->object
;
27130 if (!STRINGP (object
) && !BUFFERP (object
))
27133 /* If we get an out-of-range value, return now; avoid an error. */
27134 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27137 /* Make the window's buffer temporarily current for
27138 overlays_at and compute_char_face. */
27139 obuf
= current_buffer
;
27140 current_buffer
= b
;
27146 /* Is this char mouse-active or does it have help-echo? */
27147 position
= make_number (pos
);
27149 if (BUFFERP (object
))
27151 /* Put all the overlays we want in a vector in overlay_vec. */
27152 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27153 /* Sort overlays into increasing priority order. */
27154 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27159 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27162 cursor
= No_Cursor
;
27164 /* Check mouse-face highlighting. */
27166 /* If there exists an overlay with mouse-face overlapping
27167 the one we are currently highlighting, we have to
27168 check if we enter the overlapping overlay, and then
27169 highlight only that. */
27170 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27171 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27173 /* Find the highest priority overlay with a mouse-face. */
27174 Lisp_Object overlay
= Qnil
;
27175 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27177 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27178 if (!NILP (mouse_face
))
27179 overlay
= overlay_vec
[i
];
27182 /* If we're highlighting the same overlay as before, there's
27183 no need to do that again. */
27184 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27185 goto check_help_echo
;
27186 hlinfo
->mouse_face_overlay
= overlay
;
27188 /* Clear the display of the old active region, if any. */
27189 if (clear_mouse_face (hlinfo
))
27190 cursor
= No_Cursor
;
27192 /* If no overlay applies, get a text property. */
27193 if (NILP (overlay
))
27194 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27196 /* Next, compute the bounds of the mouse highlighting and
27198 if (!NILP (mouse_face
) && STRINGP (object
))
27200 /* The mouse-highlighting comes from a display string
27201 with a mouse-face. */
27205 s
= Fprevious_single_property_change
27206 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27207 e
= Fnext_single_property_change
27208 (position
, Qmouse_face
, object
, Qnil
);
27210 s
= make_number (0);
27212 e
= make_number (SCHARS (object
) - 1);
27213 mouse_face_from_string_pos (w
, hlinfo
, object
,
27214 XINT (s
), XINT (e
));
27215 hlinfo
->mouse_face_past_end
= 0;
27216 hlinfo
->mouse_face_window
= window
;
27217 hlinfo
->mouse_face_face_id
27218 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27219 glyph
->face_id
, 1);
27220 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27221 cursor
= No_Cursor
;
27225 /* The mouse-highlighting, if any, comes from an overlay
27226 or text property in the buffer. */
27227 Lisp_Object buffer
IF_LINT (= Qnil
);
27228 Lisp_Object disp_string
IF_LINT (= Qnil
);
27230 if (STRINGP (object
))
27232 /* If we are on a display string with no mouse-face,
27233 check if the text under it has one. */
27234 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27235 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27236 pos
= string_buffer_position (object
, start
);
27239 mouse_face
= get_char_property_and_overlay
27240 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27241 buffer
= w
->buffer
;
27242 disp_string
= object
;
27248 disp_string
= Qnil
;
27251 if (!NILP (mouse_face
))
27253 Lisp_Object before
, after
;
27254 Lisp_Object before_string
, after_string
;
27255 /* To correctly find the limits of mouse highlight
27256 in a bidi-reordered buffer, we must not use the
27257 optimization of limiting the search in
27258 previous-single-property-change and
27259 next-single-property-change, because
27260 rows_from_pos_range needs the real start and end
27261 positions to DTRT in this case. That's because
27262 the first row visible in a window does not
27263 necessarily display the character whose position
27264 is the smallest. */
27266 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27267 ? Fmarker_position (w
->start
)
27270 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27271 ? make_number (BUF_Z (XBUFFER (buffer
))
27272 - XFASTINT (w
->window_end_pos
))
27275 if (NILP (overlay
))
27277 /* Handle the text property case. */
27278 before
= Fprevious_single_property_change
27279 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27280 after
= Fnext_single_property_change
27281 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27282 before_string
= after_string
= Qnil
;
27286 /* Handle the overlay case. */
27287 before
= Foverlay_start (overlay
);
27288 after
= Foverlay_end (overlay
);
27289 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27290 after_string
= Foverlay_get (overlay
, Qafter_string
);
27292 if (!STRINGP (before_string
)) before_string
= Qnil
;
27293 if (!STRINGP (after_string
)) after_string
= Qnil
;
27296 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27299 : XFASTINT (before
),
27301 ? BUF_Z (XBUFFER (buffer
))
27302 : XFASTINT (after
),
27303 before_string
, after_string
,
27305 cursor
= No_Cursor
;
27312 /* Look for a `help-echo' property. */
27313 if (NILP (help_echo_string
)) {
27314 Lisp_Object help
, overlay
;
27316 /* Check overlays first. */
27317 help
= overlay
= Qnil
;
27318 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27320 overlay
= overlay_vec
[i
];
27321 help
= Foverlay_get (overlay
, Qhelp_echo
);
27326 help_echo_string
= help
;
27327 help_echo_window
= window
;
27328 help_echo_object
= overlay
;
27329 help_echo_pos
= pos
;
27333 Lisp_Object obj
= glyph
->object
;
27334 ptrdiff_t charpos
= glyph
->charpos
;
27336 /* Try text properties. */
27339 && charpos
< SCHARS (obj
))
27341 help
= Fget_text_property (make_number (charpos
),
27345 /* If the string itself doesn't specify a help-echo,
27346 see if the buffer text ``under'' it does. */
27347 struct glyph_row
*r
27348 = MATRIX_ROW (w
->current_matrix
, vpos
);
27349 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27350 ptrdiff_t p
= string_buffer_position (obj
, start
);
27353 help
= Fget_char_property (make_number (p
),
27354 Qhelp_echo
, w
->buffer
);
27363 else if (BUFFERP (obj
)
27366 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27371 help_echo_string
= help
;
27372 help_echo_window
= window
;
27373 help_echo_object
= obj
;
27374 help_echo_pos
= charpos
;
27379 #ifdef HAVE_WINDOW_SYSTEM
27380 /* Look for a `pointer' property. */
27381 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27383 /* Check overlays first. */
27384 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27385 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27387 if (NILP (pointer
))
27389 Lisp_Object obj
= glyph
->object
;
27390 ptrdiff_t charpos
= glyph
->charpos
;
27392 /* Try text properties. */
27395 && charpos
< SCHARS (obj
))
27397 pointer
= Fget_text_property (make_number (charpos
),
27399 if (NILP (pointer
))
27401 /* If the string itself doesn't specify a pointer,
27402 see if the buffer text ``under'' it does. */
27403 struct glyph_row
*r
27404 = MATRIX_ROW (w
->current_matrix
, vpos
);
27405 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27406 ptrdiff_t p
= string_buffer_position (obj
, start
);
27408 pointer
= Fget_char_property (make_number (p
),
27409 Qpointer
, w
->buffer
);
27412 else if (BUFFERP (obj
)
27415 pointer
= Fget_text_property (make_number (charpos
),
27419 #endif /* HAVE_WINDOW_SYSTEM */
27423 current_buffer
= obuf
;
27428 #ifdef HAVE_WINDOW_SYSTEM
27429 if (FRAME_WINDOW_P (f
))
27430 define_frame_cursor1 (f
, cursor
, pointer
);
27432 /* This is here to prevent a compiler error, about "label at end of
27433 compound statement". */
27440 Clear any mouse-face on window W. This function is part of the
27441 redisplay interface, and is called from try_window_id and similar
27442 functions to ensure the mouse-highlight is off. */
27445 x_clear_window_mouse_face (struct window
*w
)
27447 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27448 Lisp_Object window
;
27451 XSETWINDOW (window
, w
);
27452 if (EQ (window
, hlinfo
->mouse_face_window
))
27453 clear_mouse_face (hlinfo
);
27459 Just discard the mouse face information for frame F, if any.
27460 This is used when the size of F is changed. */
27463 cancel_mouse_face (struct frame
*f
)
27465 Lisp_Object window
;
27466 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27468 window
= hlinfo
->mouse_face_window
;
27469 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27471 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27472 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27473 hlinfo
->mouse_face_window
= Qnil
;
27479 /***********************************************************************
27481 ***********************************************************************/
27483 #ifdef HAVE_WINDOW_SYSTEM
27485 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27486 which intersects rectangle R. R is in window-relative coordinates. */
27489 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27490 enum glyph_row_area area
)
27492 struct glyph
*first
= row
->glyphs
[area
];
27493 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27494 struct glyph
*last
;
27495 int first_x
, start_x
, x
;
27497 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27498 /* If row extends face to end of line write the whole line. */
27499 draw_glyphs (w
, 0, row
, area
,
27500 0, row
->used
[area
],
27501 DRAW_NORMAL_TEXT
, 0);
27504 /* Set START_X to the window-relative start position for drawing glyphs of
27505 AREA. The first glyph of the text area can be partially visible.
27506 The first glyphs of other areas cannot. */
27507 start_x
= window_box_left_offset (w
, area
);
27509 if (area
== TEXT_AREA
)
27512 /* Find the first glyph that must be redrawn. */
27514 && x
+ first
->pixel_width
< r
->x
)
27516 x
+= first
->pixel_width
;
27520 /* Find the last one. */
27524 && x
< r
->x
+ r
->width
)
27526 x
+= last
->pixel_width
;
27532 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27533 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27534 DRAW_NORMAL_TEXT
, 0);
27539 /* Redraw the parts of the glyph row ROW on window W intersecting
27540 rectangle R. R is in window-relative coordinates. Value is
27541 non-zero if mouse-face was overwritten. */
27544 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27546 xassert (row
->enabled_p
);
27548 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27549 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27550 0, row
->used
[TEXT_AREA
],
27551 DRAW_NORMAL_TEXT
, 0);
27554 if (row
->used
[LEFT_MARGIN_AREA
])
27555 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27556 if (row
->used
[TEXT_AREA
])
27557 expose_area (w
, row
, r
, TEXT_AREA
);
27558 if (row
->used
[RIGHT_MARGIN_AREA
])
27559 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27560 draw_row_fringe_bitmaps (w
, row
);
27563 return row
->mouse_face_p
;
27567 /* Redraw those parts of glyphs rows during expose event handling that
27568 overlap other rows. Redrawing of an exposed line writes over parts
27569 of lines overlapping that exposed line; this function fixes that.
27571 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27572 row in W's current matrix that is exposed and overlaps other rows.
27573 LAST_OVERLAPPING_ROW is the last such row. */
27576 expose_overlaps (struct window
*w
,
27577 struct glyph_row
*first_overlapping_row
,
27578 struct glyph_row
*last_overlapping_row
,
27581 struct glyph_row
*row
;
27583 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27584 if (row
->overlapping_p
)
27586 xassert (row
->enabled_p
&& !row
->mode_line_p
);
27589 if (row
->used
[LEFT_MARGIN_AREA
])
27590 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
27592 if (row
->used
[TEXT_AREA
])
27593 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
27595 if (row
->used
[RIGHT_MARGIN_AREA
])
27596 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
27602 /* Return non-zero if W's cursor intersects rectangle R. */
27605 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
27607 XRectangle cr
, result
;
27608 struct glyph
*cursor_glyph
;
27609 struct glyph_row
*row
;
27611 if (w
->phys_cursor
.vpos
>= 0
27612 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
27613 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
27615 && row
->cursor_in_fringe_p
)
27617 /* Cursor is in the fringe. */
27618 cr
.x
= window_box_right_offset (w
,
27619 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
27620 ? RIGHT_MARGIN_AREA
27623 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
27624 cr
.height
= row
->height
;
27625 return x_intersect_rectangles (&cr
, r
, &result
);
27628 cursor_glyph
= get_phys_cursor_glyph (w
);
27631 /* r is relative to W's box, but w->phys_cursor.x is relative
27632 to left edge of W's TEXT area. Adjust it. */
27633 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
27634 cr
.y
= w
->phys_cursor
.y
;
27635 cr
.width
= cursor_glyph
->pixel_width
;
27636 cr
.height
= w
->phys_cursor_height
;
27637 /* ++KFS: W32 version used W32-specific IntersectRect here, but
27638 I assume the effect is the same -- and this is portable. */
27639 return x_intersect_rectangles (&cr
, r
, &result
);
27641 /* If we don't understand the format, pretend we're not in the hot-spot. */
27647 Draw a vertical window border to the right of window W if W doesn't
27648 have vertical scroll bars. */
27651 x_draw_vertical_border (struct window
*w
)
27653 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27655 /* We could do better, if we knew what type of scroll-bar the adjacent
27656 windows (on either side) have... But we don't :-(
27657 However, I think this works ok. ++KFS 2003-04-25 */
27659 /* Redraw borders between horizontally adjacent windows. Don't
27660 do it for frames with vertical scroll bars because either the
27661 right scroll bar of a window, or the left scroll bar of its
27662 neighbor will suffice as a border. */
27663 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
27666 if (!WINDOW_RIGHTMOST_P (w
)
27667 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
27669 int x0
, x1
, y0
, y1
;
27671 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27674 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27677 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
27679 else if (!WINDOW_LEFTMOST_P (w
)
27680 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
27682 int x0
, x1
, y0
, y1
;
27684 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27687 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27690 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
27695 /* Redraw the part of window W intersection rectangle FR. Pixel
27696 coordinates in FR are frame-relative. Call this function with
27697 input blocked. Value is non-zero if the exposure overwrites
27701 expose_window (struct window
*w
, XRectangle
*fr
)
27703 struct frame
*f
= XFRAME (w
->frame
);
27705 int mouse_face_overwritten_p
= 0;
27707 /* If window is not yet fully initialized, do nothing. This can
27708 happen when toolkit scroll bars are used and a window is split.
27709 Reconfiguring the scroll bar will generate an expose for a newly
27711 if (w
->current_matrix
== NULL
)
27714 /* When we're currently updating the window, display and current
27715 matrix usually don't agree. Arrange for a thorough display
27717 if (w
== updated_window
)
27719 SET_FRAME_GARBAGED (f
);
27723 /* Frame-relative pixel rectangle of W. */
27724 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
27725 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
27726 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
27727 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
27729 if (x_intersect_rectangles (fr
, &wr
, &r
))
27731 int yb
= window_text_bottom_y (w
);
27732 struct glyph_row
*row
;
27733 int cursor_cleared_p
, phys_cursor_on_p
;
27734 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
27736 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
27737 r
.x
, r
.y
, r
.width
, r
.height
));
27739 /* Convert to window coordinates. */
27740 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
27741 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
27743 /* Turn off the cursor. */
27744 if (!w
->pseudo_window_p
27745 && phys_cursor_in_rect_p (w
, &r
))
27747 x_clear_cursor (w
);
27748 cursor_cleared_p
= 1;
27751 cursor_cleared_p
= 0;
27753 /* If the row containing the cursor extends face to end of line,
27754 then expose_area might overwrite the cursor outside the
27755 rectangle and thus notice_overwritten_cursor might clear
27756 w->phys_cursor_on_p. We remember the original value and
27757 check later if it is changed. */
27758 phys_cursor_on_p
= w
->phys_cursor_on_p
;
27760 /* Update lines intersecting rectangle R. */
27761 first_overlapping_row
= last_overlapping_row
= NULL
;
27762 for (row
= w
->current_matrix
->rows
;
27767 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
27769 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
27770 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
27771 || (r
.y
>= y0
&& r
.y
< y1
)
27772 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
27774 /* A header line may be overlapping, but there is no need
27775 to fix overlapping areas for them. KFS 2005-02-12 */
27776 if (row
->overlapping_p
&& !row
->mode_line_p
)
27778 if (first_overlapping_row
== NULL
)
27779 first_overlapping_row
= row
;
27780 last_overlapping_row
= row
;
27784 if (expose_line (w
, row
, &r
))
27785 mouse_face_overwritten_p
= 1;
27788 else if (row
->overlapping_p
)
27790 /* We must redraw a row overlapping the exposed area. */
27792 ? y0
+ row
->phys_height
> r
.y
27793 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
27795 if (first_overlapping_row
== NULL
)
27796 first_overlapping_row
= row
;
27797 last_overlapping_row
= row
;
27805 /* Display the mode line if there is one. */
27806 if (WINDOW_WANTS_MODELINE_P (w
)
27807 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
27809 && row
->y
< r
.y
+ r
.height
)
27811 if (expose_line (w
, row
, &r
))
27812 mouse_face_overwritten_p
= 1;
27815 if (!w
->pseudo_window_p
)
27817 /* Fix the display of overlapping rows. */
27818 if (first_overlapping_row
)
27819 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
27822 /* Draw border between windows. */
27823 x_draw_vertical_border (w
);
27825 /* Turn the cursor on again. */
27826 if (cursor_cleared_p
27827 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
27828 update_window_cursor (w
, 1);
27832 return mouse_face_overwritten_p
;
27837 /* Redraw (parts) of all windows in the window tree rooted at W that
27838 intersect R. R contains frame pixel coordinates. Value is
27839 non-zero if the exposure overwrites mouse-face. */
27842 expose_window_tree (struct window
*w
, XRectangle
*r
)
27844 struct frame
*f
= XFRAME (w
->frame
);
27845 int mouse_face_overwritten_p
= 0;
27847 while (w
&& !FRAME_GARBAGED_P (f
))
27849 if (!NILP (w
->hchild
))
27850 mouse_face_overwritten_p
27851 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
27852 else if (!NILP (w
->vchild
))
27853 mouse_face_overwritten_p
27854 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
27856 mouse_face_overwritten_p
|= expose_window (w
, r
);
27858 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
27861 return mouse_face_overwritten_p
;
27866 Redisplay an exposed area of frame F. X and Y are the upper-left
27867 corner of the exposed rectangle. W and H are width and height of
27868 the exposed area. All are pixel values. W or H zero means redraw
27869 the entire frame. */
27872 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
27875 int mouse_face_overwritten_p
= 0;
27877 TRACE ((stderr
, "expose_frame "));
27879 /* No need to redraw if frame will be redrawn soon. */
27880 if (FRAME_GARBAGED_P (f
))
27882 TRACE ((stderr
, " garbaged\n"));
27886 /* If basic faces haven't been realized yet, there is no point in
27887 trying to redraw anything. This can happen when we get an expose
27888 event while Emacs is starting, e.g. by moving another window. */
27889 if (FRAME_FACE_CACHE (f
) == NULL
27890 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
27892 TRACE ((stderr
, " no faces\n"));
27896 if (w
== 0 || h
== 0)
27899 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
27900 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
27910 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
27911 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
27913 if (WINDOWP (f
->tool_bar_window
))
27914 mouse_face_overwritten_p
27915 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
27917 #ifdef HAVE_X_WINDOWS
27919 #ifndef USE_X_TOOLKIT
27920 if (WINDOWP (f
->menu_bar_window
))
27921 mouse_face_overwritten_p
27922 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
27923 #endif /* not USE_X_TOOLKIT */
27927 /* Some window managers support a focus-follows-mouse style with
27928 delayed raising of frames. Imagine a partially obscured frame,
27929 and moving the mouse into partially obscured mouse-face on that
27930 frame. The visible part of the mouse-face will be highlighted,
27931 then the WM raises the obscured frame. With at least one WM, KDE
27932 2.1, Emacs is not getting any event for the raising of the frame
27933 (even tried with SubstructureRedirectMask), only Expose events.
27934 These expose events will draw text normally, i.e. not
27935 highlighted. Which means we must redo the highlight here.
27936 Subsume it under ``we love X''. --gerd 2001-08-15 */
27937 /* Included in Windows version because Windows most likely does not
27938 do the right thing if any third party tool offers
27939 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
27940 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
27942 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27943 if (f
== hlinfo
->mouse_face_mouse_frame
)
27945 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
27946 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
27947 clear_mouse_face (hlinfo
);
27948 note_mouse_highlight (f
, mouse_x
, mouse_y
);
27955 Determine the intersection of two rectangles R1 and R2. Return
27956 the intersection in *RESULT. Value is non-zero if RESULT is not
27960 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
27962 XRectangle
*left
, *right
;
27963 XRectangle
*upper
, *lower
;
27964 int intersection_p
= 0;
27966 /* Rearrange so that R1 is the left-most rectangle. */
27968 left
= r1
, right
= r2
;
27970 left
= r2
, right
= r1
;
27972 /* X0 of the intersection is right.x0, if this is inside R1,
27973 otherwise there is no intersection. */
27974 if (right
->x
<= left
->x
+ left
->width
)
27976 result
->x
= right
->x
;
27978 /* The right end of the intersection is the minimum of
27979 the right ends of left and right. */
27980 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
27983 /* Same game for Y. */
27985 upper
= r1
, lower
= r2
;
27987 upper
= r2
, lower
= r1
;
27989 /* The upper end of the intersection is lower.y0, if this is inside
27990 of upper. Otherwise, there is no intersection. */
27991 if (lower
->y
<= upper
->y
+ upper
->height
)
27993 result
->y
= lower
->y
;
27995 /* The lower end of the intersection is the minimum of the lower
27996 ends of upper and lower. */
27997 result
->height
= (min (lower
->y
+ lower
->height
,
27998 upper
->y
+ upper
->height
)
28000 intersection_p
= 1;
28004 return intersection_p
;
28007 #endif /* HAVE_WINDOW_SYSTEM */
28010 /***********************************************************************
28012 ***********************************************************************/
28015 syms_of_xdisp (void)
28017 Vwith_echo_area_save_vector
= Qnil
;
28018 staticpro (&Vwith_echo_area_save_vector
);
28020 Vmessage_stack
= Qnil
;
28021 staticpro (&Vmessage_stack
);
28023 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28025 message_dolog_marker1
= Fmake_marker ();
28026 staticpro (&message_dolog_marker1
);
28027 message_dolog_marker2
= Fmake_marker ();
28028 staticpro (&message_dolog_marker2
);
28029 message_dolog_marker3
= Fmake_marker ();
28030 staticpro (&message_dolog_marker3
);
28033 defsubr (&Sdump_frame_glyph_matrix
);
28034 defsubr (&Sdump_glyph_matrix
);
28035 defsubr (&Sdump_glyph_row
);
28036 defsubr (&Sdump_tool_bar_row
);
28037 defsubr (&Strace_redisplay
);
28038 defsubr (&Strace_to_stderr
);
28040 #ifdef HAVE_WINDOW_SYSTEM
28041 defsubr (&Stool_bar_lines_needed
);
28042 defsubr (&Slookup_image_map
);
28044 defsubr (&Sformat_mode_line
);
28045 defsubr (&Sinvisible_p
);
28046 defsubr (&Scurrent_bidi_paragraph_direction
);
28048 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28049 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28050 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28051 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28052 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28053 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28054 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28055 DEFSYM (Qeval
, "eval");
28056 DEFSYM (QCdata
, ":data");
28057 DEFSYM (Qdisplay
, "display");
28058 DEFSYM (Qspace_width
, "space-width");
28059 DEFSYM (Qraise
, "raise");
28060 DEFSYM (Qslice
, "slice");
28061 DEFSYM (Qspace
, "space");
28062 DEFSYM (Qmargin
, "margin");
28063 DEFSYM (Qpointer
, "pointer");
28064 DEFSYM (Qleft_margin
, "left-margin");
28065 DEFSYM (Qright_margin
, "right-margin");
28066 DEFSYM (Qcenter
, "center");
28067 DEFSYM (Qline_height
, "line-height");
28068 DEFSYM (QCalign_to
, ":align-to");
28069 DEFSYM (QCrelative_width
, ":relative-width");
28070 DEFSYM (QCrelative_height
, ":relative-height");
28071 DEFSYM (QCeval
, ":eval");
28072 DEFSYM (QCpropertize
, ":propertize");
28073 DEFSYM (QCfile
, ":file");
28074 DEFSYM (Qfontified
, "fontified");
28075 DEFSYM (Qfontification_functions
, "fontification-functions");
28076 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28077 DEFSYM (Qescape_glyph
, "escape-glyph");
28078 DEFSYM (Qnobreak_space
, "nobreak-space");
28079 DEFSYM (Qimage
, "image");
28080 DEFSYM (Qtext
, "text");
28081 DEFSYM (Qboth
, "both");
28082 DEFSYM (Qboth_horiz
, "both-horiz");
28083 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28084 DEFSYM (QCmap
, ":map");
28085 DEFSYM (QCpointer
, ":pointer");
28086 DEFSYM (Qrect
, "rect");
28087 DEFSYM (Qcircle
, "circle");
28088 DEFSYM (Qpoly
, "poly");
28089 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28090 DEFSYM (Qgrow_only
, "grow-only");
28091 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28092 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28093 DEFSYM (Qposition
, "position");
28094 DEFSYM (Qbuffer_position
, "buffer-position");
28095 DEFSYM (Qobject
, "object");
28096 DEFSYM (Qbar
, "bar");
28097 DEFSYM (Qhbar
, "hbar");
28098 DEFSYM (Qbox
, "box");
28099 DEFSYM (Qhollow
, "hollow");
28100 DEFSYM (Qhand
, "hand");
28101 DEFSYM (Qarrow
, "arrow");
28102 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28104 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28105 Fcons (intern_c_string ("void-variable"), Qnil
)),
28107 staticpro (&list_of_error
);
28109 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28110 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28111 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28112 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28114 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28115 staticpro (&echo_buffer
[0]);
28116 staticpro (&echo_buffer
[1]);
28118 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28119 staticpro (&echo_area_buffer
[0]);
28120 staticpro (&echo_area_buffer
[1]);
28122 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28123 staticpro (&Vmessages_buffer_name
);
28125 mode_line_proptrans_alist
= Qnil
;
28126 staticpro (&mode_line_proptrans_alist
);
28127 mode_line_string_list
= Qnil
;
28128 staticpro (&mode_line_string_list
);
28129 mode_line_string_face
= Qnil
;
28130 staticpro (&mode_line_string_face
);
28131 mode_line_string_face_prop
= Qnil
;
28132 staticpro (&mode_line_string_face_prop
);
28133 Vmode_line_unwind_vector
= Qnil
;
28134 staticpro (&Vmode_line_unwind_vector
);
28136 help_echo_string
= Qnil
;
28137 staticpro (&help_echo_string
);
28138 help_echo_object
= Qnil
;
28139 staticpro (&help_echo_object
);
28140 help_echo_window
= Qnil
;
28141 staticpro (&help_echo_window
);
28142 previous_help_echo_string
= Qnil
;
28143 staticpro (&previous_help_echo_string
);
28144 help_echo_pos
= -1;
28146 DEFSYM (Qright_to_left
, "right-to-left");
28147 DEFSYM (Qleft_to_right
, "left-to-right");
28149 #ifdef HAVE_WINDOW_SYSTEM
28150 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28151 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
28152 For example, if a block cursor is over a tab, it will be drawn as
28153 wide as that tab on the display. */);
28154 x_stretch_cursor_p
= 0;
28157 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28158 doc
: /* *Non-nil means highlight trailing whitespace.
28159 The face used for trailing whitespace is `trailing-whitespace'. */);
28160 Vshow_trailing_whitespace
= Qnil
;
28162 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28163 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28164 If the value is t, Emacs highlights non-ASCII chars which have the
28165 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28166 or `escape-glyph' face respectively.
28168 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28169 U+2011 (non-breaking hyphen) are affected.
28171 Any other non-nil value means to display these characters as a escape
28172 glyph followed by an ordinary space or hyphen.
28174 A value of nil means no special handling of these characters. */);
28175 Vnobreak_char_display
= Qt
;
28177 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28178 doc
: /* *The pointer shape to show in void text areas.
28179 A value of nil means to show the text pointer. Other options are `arrow',
28180 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28181 Vvoid_text_area_pointer
= Qarrow
;
28183 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28184 doc
: /* Non-nil means don't actually do any redisplay.
28185 This is used for internal purposes. */);
28186 Vinhibit_redisplay
= Qnil
;
28188 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28189 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28190 Vglobal_mode_string
= Qnil
;
28192 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28193 doc
: /* Marker for where to display an arrow on top of the buffer text.
28194 This must be the beginning of a line in order to work.
28195 See also `overlay-arrow-string'. */);
28196 Voverlay_arrow_position
= Qnil
;
28198 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28199 doc
: /* String to display as an arrow in non-window frames.
28200 See also `overlay-arrow-position'. */);
28201 Voverlay_arrow_string
= make_pure_c_string ("=>");
28203 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28204 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28205 The symbols on this list are examined during redisplay to determine
28206 where to display overlay arrows. */);
28207 Voverlay_arrow_variable_list
28208 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28210 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28211 doc
: /* *The number of lines to try scrolling a window by when point moves out.
28212 If that fails to bring point back on frame, point is centered instead.
28213 If this is zero, point is always centered after it moves off frame.
28214 If you want scrolling to always be a line at a time, you should set
28215 `scroll-conservatively' to a large value rather than set this to 1. */);
28217 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28218 doc
: /* *Scroll up to this many lines, to bring point back on screen.
28219 If point moves off-screen, redisplay will scroll by up to
28220 `scroll-conservatively' lines in order to bring point just barely
28221 onto the screen again. If that cannot be done, then redisplay
28222 recenters point as usual.
28224 If the value is greater than 100, redisplay will never recenter point,
28225 but will always scroll just enough text to bring point into view, even
28226 if you move far away.
28228 A value of zero means always recenter point if it moves off screen. */);
28229 scroll_conservatively
= 0;
28231 DEFVAR_INT ("scroll-margin", scroll_margin
,
28232 doc
: /* *Number of lines of margin at the top and bottom of a window.
28233 Recenter the window whenever point gets within this many lines
28234 of the top or bottom of the window. */);
28237 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28238 doc
: /* Pixels per inch value for non-window system displays.
28239 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28240 Vdisplay_pixels_per_inch
= make_float (72.0);
28243 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28246 DEFVAR_LISP ("truncate-partial-width-windows",
28247 Vtruncate_partial_width_windows
,
28248 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28249 For an integer value, truncate lines in each window narrower than the
28250 full frame width, provided the window width is less than that integer;
28251 otherwise, respect the value of `truncate-lines'.
28253 For any other non-nil value, truncate lines in all windows that do
28254 not span the full frame width.
28256 A value of nil means to respect the value of `truncate-lines'.
28258 If `word-wrap' is enabled, you might want to reduce this. */);
28259 Vtruncate_partial_width_windows
= make_number (50);
28261 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28262 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28263 Any other value means to use the appropriate face, `mode-line',
28264 `header-line', or `menu' respectively. */);
28265 mode_line_inverse_video
= 1;
28267 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28268 doc
: /* *Maximum buffer size for which line number should be displayed.
28269 If the buffer is bigger than this, the line number does not appear
28270 in the mode line. A value of nil means no limit. */);
28271 Vline_number_display_limit
= Qnil
;
28273 DEFVAR_INT ("line-number-display-limit-width",
28274 line_number_display_limit_width
,
28275 doc
: /* *Maximum line width (in characters) for line number display.
28276 If the average length of the lines near point is bigger than this, then the
28277 line number may be omitted from the mode line. */);
28278 line_number_display_limit_width
= 200;
28280 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28281 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
28282 highlight_nonselected_windows
= 0;
28284 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28285 doc
: /* Non-nil if more than one frame is visible on this display.
28286 Minibuffer-only frames don't count, but iconified frames do.
28287 This variable is not guaranteed to be accurate except while processing
28288 `frame-title-format' and `icon-title-format'. */);
28290 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28291 doc
: /* Template for displaying the title bar of visible frames.
28292 \(Assuming the window manager supports this feature.)
28294 This variable has the same structure as `mode-line-format', except that
28295 the %c and %l constructs are ignored. It is used only on frames for
28296 which no explicit name has been set \(see `modify-frame-parameters'). */);
28298 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28299 doc
: /* Template for displaying the title bar of an iconified frame.
28300 \(Assuming the window manager supports this feature.)
28301 This variable has the same structure as `mode-line-format' (which see),
28302 and is used only on frames for which no explicit name has been set
28303 \(see `modify-frame-parameters'). */);
28305 = Vframe_title_format
28306 = pure_cons (intern_c_string ("multiple-frames"),
28307 pure_cons (make_pure_c_string ("%b"),
28308 pure_cons (pure_cons (empty_unibyte_string
,
28309 pure_cons (intern_c_string ("invocation-name"),
28310 pure_cons (make_pure_c_string ("@"),
28311 pure_cons (intern_c_string ("system-name"),
28315 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28316 doc
: /* Maximum number of lines to keep in the message log buffer.
28317 If nil, disable message logging. If t, log messages but don't truncate
28318 the buffer when it becomes large. */);
28319 Vmessage_log_max
= make_number (100);
28321 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28322 doc
: /* Functions called before redisplay, if window sizes have changed.
28323 The value should be a list of functions that take one argument.
28324 Just before redisplay, for each frame, if any of its windows have changed
28325 size since the last redisplay, or have been split or deleted,
28326 all the functions in the list are called, with the frame as argument. */);
28327 Vwindow_size_change_functions
= Qnil
;
28329 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28330 doc
: /* List of functions to call before redisplaying a window with scrolling.
28331 Each function is called with two arguments, the window and its new
28332 display-start position. Note that these functions are also called by
28333 `set-window-buffer'. Also note that the value of `window-end' is not
28334 valid when these functions are called. */);
28335 Vwindow_scroll_functions
= Qnil
;
28337 DEFVAR_LISP ("window-text-change-functions",
28338 Vwindow_text_change_functions
,
28339 doc
: /* Functions to call in redisplay when text in the window might change. */);
28340 Vwindow_text_change_functions
= Qnil
;
28342 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28343 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28344 Each function is called with two arguments, the window and the end trigger value.
28345 See `set-window-redisplay-end-trigger'. */);
28346 Vredisplay_end_trigger_functions
= Qnil
;
28348 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28349 doc
: /* *Non-nil means autoselect window with mouse pointer.
28350 If nil, do not autoselect windows.
28351 A positive number means delay autoselection by that many seconds: a
28352 window is autoselected only after the mouse has remained in that
28353 window for the duration of the delay.
28354 A negative number has a similar effect, but causes windows to be
28355 autoselected only after the mouse has stopped moving. \(Because of
28356 the way Emacs compares mouse events, you will occasionally wait twice
28357 that time before the window gets selected.\)
28358 Any other value means to autoselect window instantaneously when the
28359 mouse pointer enters it.
28361 Autoselection selects the minibuffer only if it is active, and never
28362 unselects the minibuffer if it is active.
28364 When customizing this variable make sure that the actual value of
28365 `focus-follows-mouse' matches the behavior of your window manager. */);
28366 Vmouse_autoselect_window
= Qnil
;
28368 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28369 doc
: /* *Non-nil means automatically resize tool-bars.
28370 This dynamically changes the tool-bar's height to the minimum height
28371 that is needed to make all tool-bar items visible.
28372 If value is `grow-only', the tool-bar's height is only increased
28373 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28374 Vauto_resize_tool_bars
= Qt
;
28376 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28377 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28378 auto_raise_tool_bar_buttons_p
= 1;
28380 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28381 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28382 make_cursor_line_fully_visible_p
= 1;
28384 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28385 doc
: /* *Border below tool-bar in pixels.
28386 If an integer, use it as the height of the border.
28387 If it is one of `internal-border-width' or `border-width', use the
28388 value of the corresponding frame parameter.
28389 Otherwise, no border is added below the tool-bar. */);
28390 Vtool_bar_border
= Qinternal_border_width
;
28392 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28393 doc
: /* *Margin around tool-bar buttons in pixels.
28394 If an integer, use that for both horizontal and vertical margins.
28395 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28396 HORZ specifying the horizontal margin, and VERT specifying the
28397 vertical margin. */);
28398 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28400 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28401 doc
: /* *Relief thickness of tool-bar buttons. */);
28402 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28404 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28405 doc
: /* Tool bar style to use.
28407 image - show images only
28408 text - show text only
28409 both - show both, text below image
28410 both-horiz - show text to the right of the image
28411 text-image-horiz - show text to the left of the image
28412 any other - use system default or image if no system default. */);
28413 Vtool_bar_style
= Qnil
;
28415 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28416 doc
: /* *Maximum number of characters a label can have to be shown.
28417 The tool bar style must also show labels for this to have any effect, see
28418 `tool-bar-style'. */);
28419 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28421 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28422 doc
: /* List of functions to call to fontify regions of text.
28423 Each function is called with one argument POS. Functions must
28424 fontify a region starting at POS in the current buffer, and give
28425 fontified regions the property `fontified'. */);
28426 Vfontification_functions
= Qnil
;
28427 Fmake_variable_buffer_local (Qfontification_functions
);
28429 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28430 unibyte_display_via_language_environment
,
28431 doc
: /* *Non-nil means display unibyte text according to language environment.
28432 Specifically, this means that raw bytes in the range 160-255 decimal
28433 are displayed by converting them to the equivalent multibyte characters
28434 according to the current language environment. As a result, they are
28435 displayed according to the current fontset.
28437 Note that this variable affects only how these bytes are displayed,
28438 but does not change the fact they are interpreted as raw bytes. */);
28439 unibyte_display_via_language_environment
= 0;
28441 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28442 doc
: /* *Maximum height for resizing mini-windows (the minibuffer and the echo area).
28443 If a float, it specifies a fraction of the mini-window frame's height.
28444 If an integer, it specifies a number of lines. */);
28445 Vmax_mini_window_height
= make_float (0.25);
28447 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28448 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28449 A value of nil means don't automatically resize mini-windows.
28450 A value of t means resize them to fit the text displayed in them.
28451 A value of `grow-only', the default, means let mini-windows grow only;
28452 they return to their normal size when the minibuffer is closed, or the
28453 echo area becomes empty. */);
28454 Vresize_mini_windows
= Qgrow_only
;
28456 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28457 doc
: /* Alist specifying how to blink the cursor off.
28458 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28459 `cursor-type' frame-parameter or variable equals ON-STATE,
28460 comparing using `equal', Emacs uses OFF-STATE to specify
28461 how to blink it off. ON-STATE and OFF-STATE are values for
28462 the `cursor-type' frame parameter.
28464 If a frame's ON-STATE has no entry in this list,
28465 the frame's other specifications determine how to blink the cursor off. */);
28466 Vblink_cursor_alist
= Qnil
;
28468 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28469 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28470 If non-nil, windows are automatically scrolled horizontally to make
28471 point visible. */);
28472 automatic_hscrolling_p
= 1;
28473 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28475 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28476 doc
: /* *How many columns away from the window edge point is allowed to get
28477 before automatic hscrolling will horizontally scroll the window. */);
28478 hscroll_margin
= 5;
28480 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28481 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
28482 When point is less than `hscroll-margin' columns from the window
28483 edge, automatic hscrolling will scroll the window by the amount of columns
28484 determined by this variable. If its value is a positive integer, scroll that
28485 many columns. If it's a positive floating-point number, it specifies the
28486 fraction of the window's width to scroll. If it's nil or zero, point will be
28487 centered horizontally after the scroll. Any other value, including negative
28488 numbers, are treated as if the value were zero.
28490 Automatic hscrolling always moves point outside the scroll margin, so if
28491 point was more than scroll step columns inside the margin, the window will
28492 scroll more than the value given by the scroll step.
28494 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28495 and `scroll-right' overrides this variable's effect. */);
28496 Vhscroll_step
= make_number (0);
28498 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28499 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28500 Bind this around calls to `message' to let it take effect. */);
28501 message_truncate_lines
= 0;
28503 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28504 doc
: /* Normal hook run to update the menu bar definitions.
28505 Redisplay runs this hook before it redisplays the menu bar.
28506 This is used to update submenus such as Buffers,
28507 whose contents depend on various data. */);
28508 Vmenu_bar_update_hook
= Qnil
;
28510 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28511 doc
: /* Frame for which we are updating a menu.
28512 The enable predicate for a menu binding should check this variable. */);
28513 Vmenu_updating_frame
= Qnil
;
28515 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28516 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28517 inhibit_menubar_update
= 0;
28519 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28520 doc
: /* Prefix prepended to all continuation lines at display time.
28521 The value may be a string, an image, or a stretch-glyph; it is
28522 interpreted in the same way as the value of a `display' text property.
28524 This variable is overridden by any `wrap-prefix' text or overlay
28527 To add a prefix to non-continuation lines, use `line-prefix'. */);
28528 Vwrap_prefix
= Qnil
;
28529 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28530 Fmake_variable_buffer_local (Qwrap_prefix
);
28532 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28533 doc
: /* Prefix prepended to all non-continuation lines at display time.
28534 The value may be a string, an image, or a stretch-glyph; it is
28535 interpreted in the same way as the value of a `display' text property.
28537 This variable is overridden by any `line-prefix' text or overlay
28540 To add a prefix to continuation lines, use `wrap-prefix'. */);
28541 Vline_prefix
= Qnil
;
28542 DEFSYM (Qline_prefix
, "line-prefix");
28543 Fmake_variable_buffer_local (Qline_prefix
);
28545 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28546 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28547 inhibit_eval_during_redisplay
= 0;
28549 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28550 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28551 inhibit_free_realized_faces
= 0;
28554 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28555 doc
: /* Inhibit try_window_id display optimization. */);
28556 inhibit_try_window_id
= 0;
28558 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28559 doc
: /* Inhibit try_window_reusing display optimization. */);
28560 inhibit_try_window_reusing
= 0;
28562 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28563 doc
: /* Inhibit try_cursor_movement display optimization. */);
28564 inhibit_try_cursor_movement
= 0;
28565 #endif /* GLYPH_DEBUG */
28567 DEFVAR_INT ("overline-margin", overline_margin
,
28568 doc
: /* *Space between overline and text, in pixels.
28569 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28570 margin to the character height. */);
28571 overline_margin
= 2;
28573 DEFVAR_INT ("underline-minimum-offset",
28574 underline_minimum_offset
,
28575 doc
: /* Minimum distance between baseline and underline.
28576 This can improve legibility of underlined text at small font sizes,
28577 particularly when using variable `x-use-underline-position-properties'
28578 with fonts that specify an UNDERLINE_POSITION relatively close to the
28579 baseline. The default value is 1. */);
28580 underline_minimum_offset
= 1;
28582 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
28583 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
28584 This feature only works when on a window system that can change
28585 cursor shapes. */);
28586 display_hourglass_p
= 1;
28588 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
28589 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
28590 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
28592 hourglass_atimer
= NULL
;
28593 hourglass_shown_p
= 0;
28595 DEFSYM (Qglyphless_char
, "glyphless-char");
28596 DEFSYM (Qhex_code
, "hex-code");
28597 DEFSYM (Qempty_box
, "empty-box");
28598 DEFSYM (Qthin_space
, "thin-space");
28599 DEFSYM (Qzero_width
, "zero-width");
28601 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
28602 /* Intern this now in case it isn't already done.
28603 Setting this variable twice is harmless.
28604 But don't staticpro it here--that is done in alloc.c. */
28605 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
28606 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
28608 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
28609 doc
: /* Char-table defining glyphless characters.
28610 Each element, if non-nil, should be one of the following:
28611 an ASCII acronym string: display this string in a box
28612 `hex-code': display the hexadecimal code of a character in a box
28613 `empty-box': display as an empty box
28614 `thin-space': display as 1-pixel width space
28615 `zero-width': don't display
28616 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
28617 display method for graphical terminals and text terminals respectively.
28618 GRAPHICAL and TEXT should each have one of the values listed above.
28620 The char-table has one extra slot to control the display of a character for
28621 which no font is found. This slot only takes effect on graphical terminals.
28622 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
28623 `thin-space'. The default is `empty-box'. */);
28624 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
28625 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
28630 /* Initialize this module when Emacs starts. */
28635 current_header_line_height
= current_mode_line_height
= -1;
28637 CHARPOS (this_line_start_pos
) = 0;
28639 if (!noninteractive
)
28641 struct window
*m
= XWINDOW (minibuf_window
);
28642 Lisp_Object frame
= m
->frame
;
28643 struct frame
*f
= XFRAME (frame
);
28644 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
28645 struct window
*r
= XWINDOW (root
);
28648 echo_area_window
= minibuf_window
;
28650 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
28651 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
28652 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
28653 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
28654 XSETFASTINT (m
->total_lines
, 1);
28655 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
28657 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
28658 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
28659 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
28661 /* The default ellipsis glyphs `...'. */
28662 for (i
= 0; i
< 3; ++i
)
28663 default_invis_vector
[i
] = make_number ('.');
28667 /* Allocate the buffer for frame titles.
28668 Also used for `format-mode-line'. */
28670 mode_line_noprop_buf
= (char *) xmalloc (size
);
28671 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
28672 mode_line_noprop_ptr
= mode_line_noprop_buf
;
28673 mode_line_target
= MODE_LINE_DISPLAY
;
28676 help_echo_showing_p
= 0;
28679 /* Since w32 does not support atimers, it defines its own implementation of
28680 the following three functions in w32fns.c. */
28683 /* Platform-independent portion of hourglass implementation. */
28685 /* Return non-zero if hourglass timer has been started or hourglass is
28688 hourglass_started (void)
28690 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
28693 /* Cancel a currently active hourglass timer, and start a new one. */
28695 start_hourglass (void)
28697 #if defined (HAVE_WINDOW_SYSTEM)
28699 int secs
= DEFAULT_HOURGLASS_DELAY
, usecs
= 0;
28701 cancel_hourglass ();
28703 if (NUMBERP (Vhourglass_delay
))
28705 double duration
= extract_float (Vhourglass_delay
);
28707 duration_to_sec_usec (duration
, &secs
, &usecs
);
28710 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
28711 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
28712 show_hourglass
, NULL
);
28717 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
28720 cancel_hourglass (void)
28722 #if defined (HAVE_WINDOW_SYSTEM)
28723 if (hourglass_atimer
)
28725 cancel_atimer (hourglass_atimer
);
28726 hourglass_atimer
= NULL
;
28729 if (hourglass_shown_p
)
28733 #endif /* ! WINDOWSNT */