1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
285 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT, or the underlying buffer
387 or string character, is a space or a TAB character. This is used
388 to determine where word wrapping can occur. */
390 #define IT_DISPLAYING_WHITESPACE(it) \
391 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
392 || ((STRINGP (it->string) \
393 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
394 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
396 && (it->s[IT_BYTEPOS (*it)] == ' ' \
397 || it->s[IT_BYTEPOS (*it)] == '\t')) \
398 || (IT_BYTEPOS (*it) < ZV_BYTE \
399 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
400 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
402 /* Name of the face used to highlight trailing whitespace. */
404 static Lisp_Object Qtrailing_whitespace
;
406 /* Name and number of the face used to highlight escape glyphs. */
408 static Lisp_Object Qescape_glyph
;
410 /* Name and number of the face used to highlight non-breaking spaces. */
412 static Lisp_Object Qnobreak_space
;
414 /* The symbol `image' which is the car of the lists used to represent
415 images in Lisp. Also a tool bar style. */
419 /* The image map types. */
421 static Lisp_Object QCpointer
;
422 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
424 /* Tool bar styles */
425 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
427 /* Non-zero means print newline to stdout before next mini-buffer
430 int noninteractive_need_newline
;
432 /* Non-zero means print newline to message log before next message. */
434 static int message_log_need_newline
;
436 /* Three markers that message_dolog uses.
437 It could allocate them itself, but that causes trouble
438 in handling memory-full errors. */
439 static Lisp_Object message_dolog_marker1
;
440 static Lisp_Object message_dolog_marker2
;
441 static Lisp_Object message_dolog_marker3
;
443 /* The buffer position of the first character appearing entirely or
444 partially on the line of the selected window which contains the
445 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
446 redisplay optimization in redisplay_internal. */
448 static struct text_pos this_line_start_pos
;
450 /* Number of characters past the end of the line above, including the
451 terminating newline. */
453 static struct text_pos this_line_end_pos
;
455 /* The vertical positions and the height of this line. */
457 static int this_line_vpos
;
458 static int this_line_y
;
459 static int this_line_pixel_height
;
461 /* X position at which this display line starts. Usually zero;
462 negative if first character is partially visible. */
464 static int this_line_start_x
;
466 /* The smallest character position seen by move_it_* functions as they
467 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
468 hscrolled lines, see display_line. */
470 static struct text_pos this_line_min_pos
;
472 /* Buffer that this_line_.* variables are referring to. */
474 static struct buffer
*this_line_buffer
;
477 /* Values of those variables at last redisplay are stored as
478 properties on `overlay-arrow-position' symbol. However, if
479 Voverlay_arrow_position is a marker, last-arrow-position is its
480 numerical position. */
482 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
484 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
485 properties on a symbol in overlay-arrow-variable-list. */
487 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
489 Lisp_Object Qmenu_bar_update_hook
;
491 /* Nonzero if an overlay arrow has been displayed in this window. */
493 static int overlay_arrow_seen
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* This is the window where the echo area message was displayed. It
506 is always a mini-buffer window, but it may not be the same window
507 currently active as a mini-buffer. */
509 Lisp_Object echo_area_window
;
511 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
512 pushes the current message and the value of
513 message_enable_multibyte on the stack, the function restore_message
514 pops the stack and displays MESSAGE again. */
516 static Lisp_Object Vmessage_stack
;
518 /* Nonzero means multibyte characters were enabled when the echo area
519 message was specified. */
521 static int message_enable_multibyte
;
523 /* Nonzero if we should redraw the mode lines on the next redisplay. */
525 int update_mode_lines
;
527 /* Nonzero if window sizes or contents have changed since last
528 redisplay that finished. */
530 int windows_or_buffers_changed
;
532 /* Nonzero means a frame's cursor type has been changed. */
534 int cursor_type_changed
;
536 /* Nonzero after display_mode_line if %l was used and it displayed a
539 static int line_number_displayed
;
541 /* The name of the *Messages* buffer, a string. */
543 static Lisp_Object Vmessages_buffer_name
;
545 /* Current, index 0, and last displayed echo area message. Either
546 buffers from echo_buffers, or nil to indicate no message. */
548 Lisp_Object echo_area_buffer
[2];
550 /* The buffers referenced from echo_area_buffer. */
552 static Lisp_Object echo_buffer
[2];
554 /* A vector saved used in with_area_buffer to reduce consing. */
556 static Lisp_Object Vwith_echo_area_save_vector
;
558 /* Non-zero means display_echo_area should display the last echo area
559 message again. Set by redisplay_preserve_echo_area. */
561 static int display_last_displayed_message_p
;
563 /* Nonzero if echo area is being used by print; zero if being used by
566 static int message_buf_print
;
568 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
570 static Lisp_Object Qinhibit_menubar_update
;
571 static Lisp_Object Qmessage_truncate_lines
;
573 /* Set to 1 in clear_message to make redisplay_internal aware
574 of an emptied echo area. */
576 static int message_cleared_p
;
578 /* A scratch glyph row with contents used for generating truncation
579 glyphs. Also used in direct_output_for_insert. */
581 #define MAX_SCRATCH_GLYPHS 100
582 static struct glyph_row scratch_glyph_row
;
583 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
585 /* Ascent and height of the last line processed by move_it_to. */
587 static int last_max_ascent
, last_height
;
589 /* Non-zero if there's a help-echo in the echo area. */
591 int help_echo_showing_p
;
593 /* If >= 0, computed, exact values of mode-line and header-line height
594 to use in the macros CURRENT_MODE_LINE_HEIGHT and
595 CURRENT_HEADER_LINE_HEIGHT. */
597 int current_mode_line_height
, current_header_line_height
;
599 /* The maximum distance to look ahead for text properties. Values
600 that are too small let us call compute_char_face and similar
601 functions too often which is expensive. Values that are too large
602 let us call compute_char_face and alike too often because we
603 might not be interested in text properties that far away. */
605 #define TEXT_PROP_DISTANCE_LIMIT 100
607 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
608 iterator state and later restore it. This is needed because the
609 bidi iterator on bidi.c keeps a stacked cache of its states, which
610 is really a singleton. When we use scratch iterator objects to
611 move around the buffer, we can cause the bidi cache to be pushed or
612 popped, and therefore we need to restore the cache state when we
613 return to the original iterator. */
614 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
617 bidi_unshelve_cache (CACHE, 1); \
619 CACHE = bidi_shelve_cache (); \
622 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
624 if (pITORIG != pITCOPY) \
625 *(pITORIG) = *(pITCOPY); \
626 bidi_unshelve_cache (CACHE, 0); \
632 /* Non-zero means print traces of redisplay if compiled with
635 int trace_redisplay_p
;
637 #endif /* GLYPH_DEBUG */
639 #ifdef DEBUG_TRACE_MOVE
640 /* Non-zero means trace with TRACE_MOVE to stderr. */
643 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
645 #define TRACE_MOVE(x) (void) 0
648 static Lisp_Object Qauto_hscroll_mode
;
650 /* Buffer being redisplayed -- for redisplay_window_error. */
652 static struct buffer
*displayed_buffer
;
654 /* Value returned from text property handlers (see below). */
659 HANDLED_RECOMPUTE_PROPS
,
660 HANDLED_OVERLAY_STRING_CONSUMED
,
664 /* A description of text properties that redisplay is interested
669 /* The name of the property. */
672 /* A unique index for the property. */
675 /* A handler function called to set up iterator IT from the property
676 at IT's current position. Value is used to steer handle_stop. */
677 enum prop_handled (*handler
) (struct it
*it
);
680 static enum prop_handled
handle_face_prop (struct it
*);
681 static enum prop_handled
handle_invisible_prop (struct it
*);
682 static enum prop_handled
handle_display_prop (struct it
*);
683 static enum prop_handled
handle_composition_prop (struct it
*);
684 static enum prop_handled
handle_overlay_change (struct it
*);
685 static enum prop_handled
handle_fontified_prop (struct it
*);
687 /* Properties handled by iterators. */
689 static struct props it_props
[] =
691 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
692 /* Handle `face' before `display' because some sub-properties of
693 `display' need to know the face. */
694 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
695 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
696 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
697 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
701 /* Value is the position described by X. If X is a marker, value is
702 the marker_position of X. Otherwise, value is X. */
704 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
706 /* Enumeration returned by some move_it_.* functions internally. */
710 /* Not used. Undefined value. */
713 /* Move ended at the requested buffer position or ZV. */
714 MOVE_POS_MATCH_OR_ZV
,
716 /* Move ended at the requested X pixel position. */
719 /* Move within a line ended at the end of a line that must be
723 /* Move within a line ended at the end of a line that would
724 be displayed truncated. */
727 /* Move within a line ended at a line end. */
731 /* This counter is used to clear the face cache every once in a while
732 in redisplay_internal. It is incremented for each redisplay.
733 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
736 #define CLEAR_FACE_CACHE_COUNT 500
737 static int clear_face_cache_count
;
739 /* Similarly for the image cache. */
741 #ifdef HAVE_WINDOW_SYSTEM
742 #define CLEAR_IMAGE_CACHE_COUNT 101
743 static int clear_image_cache_count
;
745 /* Null glyph slice */
746 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
749 /* Non-zero while redisplay_internal is in progress. */
753 static Lisp_Object Qinhibit_free_realized_faces
;
755 /* If a string, XTread_socket generates an event to display that string.
756 (The display is done in read_char.) */
758 Lisp_Object help_echo_string
;
759 Lisp_Object help_echo_window
;
760 Lisp_Object help_echo_object
;
761 EMACS_INT help_echo_pos
;
763 /* Temporary variable for XTread_socket. */
765 Lisp_Object previous_help_echo_string
;
767 /* Platform-independent portion of hourglass implementation. */
769 /* Non-zero means an hourglass cursor is currently shown. */
770 int hourglass_shown_p
;
772 /* If non-null, an asynchronous timer that, when it expires, displays
773 an hourglass cursor on all frames. */
774 struct atimer
*hourglass_atimer
;
776 /* Name of the face used to display glyphless characters. */
777 Lisp_Object Qglyphless_char
;
779 /* Symbol for the purpose of Vglyphless_char_display. */
780 static Lisp_Object Qglyphless_char_display
;
782 /* Method symbols for Vglyphless_char_display. */
783 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
785 /* Default pixel width of `thin-space' display method. */
786 #define THIN_SPACE_WIDTH 1
788 /* Default number of seconds to wait before displaying an hourglass
790 #define DEFAULT_HOURGLASS_DELAY 1
793 /* Function prototypes. */
795 static void setup_for_ellipsis (struct it
*, int);
796 static void set_iterator_to_next (struct it
*, int);
797 static void mark_window_display_accurate_1 (struct window
*, int);
798 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
799 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
800 static int cursor_row_p (struct glyph_row
*);
801 static int redisplay_mode_lines (Lisp_Object
, int);
802 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
804 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
806 static void handle_line_prefix (struct it
*);
808 static void pint2str (char *, int, EMACS_INT
);
809 static void pint2hrstr (char *, int, EMACS_INT
);
810 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
812 static void reconsider_clip_changes (struct window
*, struct buffer
*);
813 static int text_outside_line_unchanged_p (struct window
*,
814 EMACS_INT
, EMACS_INT
);
815 static void store_mode_line_noprop_char (char);
816 static int store_mode_line_noprop (const char *, int, int);
817 static void handle_stop (struct it
*);
818 static void handle_stop_backwards (struct it
*, EMACS_INT
);
819 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
820 static void ensure_echo_area_buffers (void);
821 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
822 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
823 static int with_echo_area_buffer (struct window
*, int,
824 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
825 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
826 static void clear_garbaged_frames (void);
827 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
828 static void pop_message (void);
829 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
830 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
831 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
832 static int display_echo_area (struct window
*);
833 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
834 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
835 static Lisp_Object
unwind_redisplay (Lisp_Object
);
836 static int string_char_and_length (const unsigned char *, int *);
837 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
839 static int compute_window_start_on_continuation_line (struct window
*);
840 static Lisp_Object
safe_eval_handler (Lisp_Object
);
841 static void insert_left_trunc_glyphs (struct it
*);
842 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
844 static void extend_face_to_end_of_line (struct it
*);
845 static int append_space_for_newline (struct it
*, int);
846 static int cursor_row_fully_visible_p (struct window
*, int, int);
847 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
848 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
849 static int trailing_whitespace_p (EMACS_INT
);
850 static intmax_t message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
851 static void push_it (struct it
*, struct text_pos
*);
852 static void pop_it (struct it
*);
853 static void sync_frame_with_window_matrix_rows (struct window
*);
854 static void select_frame_for_redisplay (Lisp_Object
);
855 static void redisplay_internal (void);
856 static int echo_area_display (int);
857 static void redisplay_windows (Lisp_Object
);
858 static void redisplay_window (Lisp_Object
, int);
859 static Lisp_Object
redisplay_window_error (Lisp_Object
);
860 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
861 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
862 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
863 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
865 static int update_menu_bar (struct frame
*, int, int);
866 static int try_window_reusing_current_matrix (struct window
*);
867 static int try_window_id (struct window
*);
868 static int display_line (struct it
*);
869 static int display_mode_lines (struct window
*);
870 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
871 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
872 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
873 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
874 static void display_menu_bar (struct window
*);
875 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
877 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
878 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
879 static void compute_line_metrics (struct it
*);
880 static void run_redisplay_end_trigger_hook (struct it
*);
881 static int get_overlay_strings (struct it
*, EMACS_INT
);
882 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
883 static void next_overlay_string (struct it
*);
884 static void reseat (struct it
*, struct text_pos
, int);
885 static void reseat_1 (struct it
*, struct text_pos
, int);
886 static void back_to_previous_visible_line_start (struct it
*);
887 void reseat_at_previous_visible_line_start (struct it
*);
888 static void reseat_at_next_visible_line_start (struct it
*, int);
889 static int next_element_from_ellipsis (struct it
*);
890 static int next_element_from_display_vector (struct it
*);
891 static int next_element_from_string (struct it
*);
892 static int next_element_from_c_string (struct it
*);
893 static int next_element_from_buffer (struct it
*);
894 static int next_element_from_composition (struct it
*);
895 static int next_element_from_image (struct it
*);
896 static int next_element_from_stretch (struct it
*);
897 static void load_overlay_strings (struct it
*, EMACS_INT
);
898 static int init_from_display_pos (struct it
*, struct window
*,
899 struct display_pos
*);
900 static void reseat_to_string (struct it
*, const char *,
901 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
902 static int get_next_display_element (struct it
*);
903 static enum move_it_result
904 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
905 enum move_operation_enum
);
906 void move_it_vertically_backward (struct it
*, int);
907 static void init_to_row_start (struct it
*, struct window
*,
909 static int init_to_row_end (struct it
*, struct window
*,
911 static void back_to_previous_line_start (struct it
*);
912 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
913 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
914 Lisp_Object
, EMACS_INT
);
915 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
916 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
917 static EMACS_INT
number_of_chars (const char *, int);
918 static void compute_stop_pos (struct it
*);
919 static void compute_string_pos (struct text_pos
*, struct text_pos
,
921 static int face_before_or_after_it_pos (struct it
*, int);
922 static EMACS_INT
next_overlay_change (EMACS_INT
);
923 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
924 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
925 static int handle_single_display_spec (struct it
*, Lisp_Object
,
926 Lisp_Object
, Lisp_Object
,
927 struct text_pos
*, EMACS_INT
, int, int);
928 static int underlying_face_id (struct it
*);
929 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
932 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
933 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
935 #ifdef HAVE_WINDOW_SYSTEM
937 static void x_consider_frame_title (Lisp_Object
);
938 static int tool_bar_lines_needed (struct frame
*, int *);
939 static void update_tool_bar (struct frame
*, int);
940 static void build_desired_tool_bar_string (struct frame
*f
);
941 static int redisplay_tool_bar (struct frame
*);
942 static void display_tool_bar_line (struct it
*, int);
943 static void notice_overwritten_cursor (struct window
*,
946 static void append_stretch_glyph (struct it
*, Lisp_Object
,
950 #endif /* HAVE_WINDOW_SYSTEM */
952 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
953 static int coords_in_mouse_face_p (struct window
*, int, int);
957 /***********************************************************************
958 Window display dimensions
959 ***********************************************************************/
961 /* Return the bottom boundary y-position for text lines in window W.
962 This is the first y position at which a line cannot start.
963 It is relative to the top of the window.
965 This is the height of W minus the height of a mode line, if any. */
968 window_text_bottom_y (struct window
*w
)
970 int height
= WINDOW_TOTAL_HEIGHT (w
);
972 if (WINDOW_WANTS_MODELINE_P (w
))
973 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
977 /* Return the pixel width of display area AREA of window W. AREA < 0
978 means return the total width of W, not including fringes to
979 the left and right of the window. */
982 window_box_width (struct window
*w
, int area
)
984 int cols
= XFASTINT (w
->total_cols
);
987 if (!w
->pseudo_window_p
)
989 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
991 if (area
== TEXT_AREA
)
993 if (INTEGERP (w
->left_margin_cols
))
994 cols
-= XFASTINT (w
->left_margin_cols
);
995 if (INTEGERP (w
->right_margin_cols
))
996 cols
-= XFASTINT (w
->right_margin_cols
);
997 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
999 else if (area
== LEFT_MARGIN_AREA
)
1001 cols
= (INTEGERP (w
->left_margin_cols
)
1002 ? XFASTINT (w
->left_margin_cols
) : 0);
1005 else if (area
== RIGHT_MARGIN_AREA
)
1007 cols
= (INTEGERP (w
->right_margin_cols
)
1008 ? XFASTINT (w
->right_margin_cols
) : 0);
1013 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1017 /* Return the pixel height of the display area of window W, not
1018 including mode lines of W, if any. */
1021 window_box_height (struct window
*w
)
1023 struct frame
*f
= XFRAME (w
->frame
);
1024 int height
= WINDOW_TOTAL_HEIGHT (w
);
1026 xassert (height
>= 0);
1028 /* Note: the code below that determines the mode-line/header-line
1029 height is essentially the same as that contained in the macro
1030 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1031 the appropriate glyph row has its `mode_line_p' flag set,
1032 and if it doesn't, uses estimate_mode_line_height instead. */
1034 if (WINDOW_WANTS_MODELINE_P (w
))
1036 struct glyph_row
*ml_row
1037 = (w
->current_matrix
&& w
->current_matrix
->rows
1038 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1040 if (ml_row
&& ml_row
->mode_line_p
)
1041 height
-= ml_row
->height
;
1043 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1046 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1048 struct glyph_row
*hl_row
1049 = (w
->current_matrix
&& w
->current_matrix
->rows
1050 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1052 if (hl_row
&& hl_row
->mode_line_p
)
1053 height
-= hl_row
->height
;
1055 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1058 /* With a very small font and a mode-line that's taller than
1059 default, we might end up with a negative height. */
1060 return max (0, height
);
1063 /* Return the window-relative coordinate of the left edge of display
1064 area AREA of window W. AREA < 0 means return the left edge of the
1065 whole window, to the right of the left fringe of W. */
1068 window_box_left_offset (struct window
*w
, int area
)
1072 if (w
->pseudo_window_p
)
1075 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1077 if (area
== TEXT_AREA
)
1078 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1079 + window_box_width (w
, LEFT_MARGIN_AREA
));
1080 else if (area
== RIGHT_MARGIN_AREA
)
1081 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1082 + window_box_width (w
, LEFT_MARGIN_AREA
)
1083 + window_box_width (w
, TEXT_AREA
)
1084 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1086 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1087 else if (area
== LEFT_MARGIN_AREA
1088 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1089 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1095 /* Return the window-relative coordinate of the right edge of display
1096 area AREA of window W. AREA < 0 means return the right edge of the
1097 whole window, to the left of the right fringe of W. */
1100 window_box_right_offset (struct window
*w
, int area
)
1102 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1105 /* Return the frame-relative coordinate of the left edge of display
1106 area AREA of window W. AREA < 0 means return the left edge of the
1107 whole window, to the right of the left fringe of W. */
1110 window_box_left (struct window
*w
, int area
)
1112 struct frame
*f
= XFRAME (w
->frame
);
1115 if (w
->pseudo_window_p
)
1116 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1118 x
= (WINDOW_LEFT_EDGE_X (w
)
1119 + window_box_left_offset (w
, area
));
1125 /* Return the frame-relative coordinate of the right edge of display
1126 area AREA of window W. AREA < 0 means return the right edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right (struct window
*w
, int area
)
1132 return window_box_left (w
, area
) + window_box_width (w
, area
);
1135 /* Get the bounding box of the display area AREA of window W, without
1136 mode lines, in frame-relative coordinates. AREA < 0 means the
1137 whole window, not including the left and right fringes of
1138 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1139 coordinates of the upper-left corner of the box. Return in
1140 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1143 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1144 int *box_width
, int *box_height
)
1147 *box_width
= window_box_width (w
, area
);
1149 *box_height
= window_box_height (w
);
1151 *box_x
= window_box_left (w
, area
);
1154 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1155 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1156 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1161 /* Get the bounding box of the display area AREA of window W, without
1162 mode lines. AREA < 0 means the whole window, not including the
1163 left and right fringe of the window. Return in *TOP_LEFT_X
1164 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1165 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1166 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1170 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1171 int *bottom_right_x
, int *bottom_right_y
)
1173 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1175 *bottom_right_x
+= *top_left_x
;
1176 *bottom_right_y
+= *top_left_y
;
1181 /***********************************************************************
1183 ***********************************************************************/
1185 /* Return the bottom y-position of the line the iterator IT is in.
1186 This can modify IT's settings. */
1189 line_bottom_y (struct it
*it
)
1191 int line_height
= it
->max_ascent
+ it
->max_descent
;
1192 int line_top_y
= it
->current_y
;
1194 if (line_height
== 0)
1197 line_height
= last_height
;
1198 else if (IT_CHARPOS (*it
) < ZV
)
1200 move_it_by_lines (it
, 1);
1201 line_height
= (it
->max_ascent
|| it
->max_descent
1202 ? it
->max_ascent
+ it
->max_descent
1207 struct glyph_row
*row
= it
->glyph_row
;
1209 /* Use the default character height. */
1210 it
->glyph_row
= NULL
;
1211 it
->what
= IT_CHARACTER
;
1214 PRODUCE_GLYPHS (it
);
1215 line_height
= it
->ascent
+ it
->descent
;
1216 it
->glyph_row
= row
;
1220 return line_top_y
+ line_height
;
1223 /* Subroutine of pos_visible_p below. Extracts a display string, if
1224 any, from the display spec given as its argument. */
1226 string_from_display_spec (Lisp_Object spec
)
1230 while (CONSP (spec
))
1232 if (STRINGP (XCAR (spec
)))
1237 else if (VECTORP (spec
))
1241 for (i
= 0; i
< ASIZE (spec
); i
++)
1243 if (STRINGP (AREF (spec
, i
)))
1244 return AREF (spec
, i
);
1252 /* Return 1 if position CHARPOS is visible in window W.
1253 CHARPOS < 0 means return info about WINDOW_END position.
1254 If visible, set *X and *Y to pixel coordinates of top left corner.
1255 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1256 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1259 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1260 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1263 void *itdata
= bidi_shelve_cache ();
1264 struct text_pos top
;
1266 struct buffer
*old_buffer
= NULL
;
1268 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1271 if (XBUFFER (w
->buffer
) != current_buffer
)
1273 old_buffer
= current_buffer
;
1274 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1277 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1278 /* Scrolling a minibuffer window via scroll bar when the echo area
1279 shows long text sometimes resets the minibuffer contents behind
1281 if (CHARPOS (top
) > ZV
)
1282 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1284 /* Compute exact mode line heights. */
1285 if (WINDOW_WANTS_MODELINE_P (w
))
1286 current_mode_line_height
1287 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1288 BVAR (current_buffer
, mode_line_format
));
1290 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1291 current_header_line_height
1292 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1293 BVAR (current_buffer
, header_line_format
));
1295 start_display (&it
, w
, top
);
1296 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1297 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1300 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1301 && IT_CHARPOS (it
) >= charpos
)
1302 /* When scanning backwards under bidi iteration, move_it_to
1303 stops at or _before_ CHARPOS, because it stops at or to
1304 the _right_ of the character at CHARPOS. */
1305 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1306 && IT_CHARPOS (it
) <= charpos
)))
1308 /* We have reached CHARPOS, or passed it. How the call to
1309 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1310 or covered by a display property, move_it_to stops at the end
1311 of the invisible text, to the right of CHARPOS. (ii) If
1312 CHARPOS is in a display vector, move_it_to stops on its last
1314 int top_x
= it
.current_x
;
1315 int top_y
= it
.current_y
;
1316 enum it_method it_method
= it
.method
;
1317 /* Calling line_bottom_y may change it.method, it.position, etc. */
1318 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1319 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1321 if (top_y
< window_top_y
)
1322 visible_p
= bottom_y
> window_top_y
;
1323 else if (top_y
< it
.last_visible_y
)
1327 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1329 /* We stopped on the last glyph of a display vector.
1330 Try and recompute. Hack alert! */
1331 if (charpos
< 2 || top
.charpos
>= charpos
)
1332 top_x
= it
.glyph_row
->x
;
1336 start_display (&it2
, w
, top
);
1337 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1338 get_next_display_element (&it2
);
1339 PRODUCE_GLYPHS (&it2
);
1340 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1341 || it2
.current_x
> it2
.last_visible_x
)
1342 top_x
= it
.glyph_row
->x
;
1345 top_x
= it2
.current_x
;
1346 top_y
= it2
.current_y
;
1350 else if (IT_CHARPOS (it
) != charpos
)
1352 Lisp_Object cpos
= make_number (charpos
);
1353 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1354 Lisp_Object string
= string_from_display_spec (spec
);
1355 int newline_in_string
= 0;
1357 if (STRINGP (string
))
1359 const char *s
= SSDATA (string
);
1360 const char *e
= s
+ SBYTES (string
);
1365 newline_in_string
= 1;
1370 /* The tricky code below is needed because there's a
1371 discrepancy between move_it_to and how we set cursor
1372 when the display line ends in a newline from a
1373 display string. move_it_to will stop _after_ such
1374 display strings, whereas set_cursor_from_row
1375 conspires with cursor_row_p to place the cursor on
1376 the first glyph produced from the display string. */
1378 /* We have overshoot PT because it is covered by a
1379 display property whose value is a string. If the
1380 string includes embedded newlines, we are also in the
1381 wrong display line. Backtrack to the correct line,
1382 where the display string begins. */
1383 if (newline_in_string
)
1385 Lisp_Object startpos
, endpos
;
1386 EMACS_INT start
, end
;
1389 /* Find the first and the last buffer positions
1390 covered by the display string. */
1392 Fnext_single_char_property_change (cpos
, Qdisplay
,
1395 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1397 start
= XFASTINT (startpos
);
1398 end
= XFASTINT (endpos
);
1399 /* Move to the last buffer position before the
1400 display property. */
1401 start_display (&it3
, w
, top
);
1402 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1403 /* Move forward one more line if the position before
1404 the display string is a newline or if it is the
1405 rightmost character on a line that is
1406 continued or word-wrapped. */
1407 if (it3
.method
== GET_FROM_BUFFER
1409 move_it_by_lines (&it3
, 1);
1410 else if (move_it_in_display_line_to (&it3
, -1,
1414 == MOVE_LINE_CONTINUED
)
1416 move_it_by_lines (&it3
, 1);
1417 /* When we are under word-wrap, the #$@%!
1418 move_it_by_lines moves 2 lines, so we need to
1420 if (it3
.line_wrap
== WORD_WRAP
)
1421 move_it_by_lines (&it3
, -1);
1424 /* Record the vertical coordinate of the display
1425 line where we wound up. */
1426 top_y
= it3
.current_y
;
1429 /* When characters are reordered for display,
1430 the character displayed to the left of the
1431 display string could be _after_ the display
1432 property in the logical order. Use the
1433 smallest vertical position of these two. */
1434 start_display (&it3
, w
, top
);
1435 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1436 if (it3
.current_y
< top_y
)
1437 top_y
= it3
.current_y
;
1439 /* Move from the top of the window to the beginning
1440 of the display line where the display string
1442 start_display (&it3
, w
, top
);
1443 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1444 /* Finally, advance the iterator until we hit the
1445 first display element whose character position is
1446 CHARPOS, or until the first newline from the
1447 display string, which signals the end of the
1449 while (get_next_display_element (&it3
))
1451 PRODUCE_GLYPHS (&it3
);
1452 if (IT_CHARPOS (it3
) == charpos
1453 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1455 set_iterator_to_next (&it3
, 0);
1457 top_x
= it3
.current_x
- it3
.pixel_width
;
1458 /* Normally, we would exit the above loop because we
1459 found the display element whose character
1460 position is CHARPOS. For the contingency that we
1461 didn't, and stopped at the first newline from the
1462 display string, move back over the glyphs
1463 produced from the string, until we find the
1464 rightmost glyph not from the string. */
1465 if (IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1467 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1468 + it3
.glyph_row
->used
[TEXT_AREA
];
1470 while (EQ ((g
- 1)->object
, string
))
1473 top_x
-= g
->pixel_width
;
1475 xassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1476 + it3
.glyph_row
->used
[TEXT_AREA
]);
1482 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1483 *rtop
= max (0, window_top_y
- top_y
);
1484 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1485 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1486 - max (top_y
, window_top_y
)));
1492 /* We were asked to provide info about WINDOW_END. */
1494 void *it2data
= NULL
;
1496 SAVE_IT (it2
, it
, it2data
);
1497 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1498 move_it_by_lines (&it
, 1);
1499 if (charpos
< IT_CHARPOS (it
)
1500 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1503 RESTORE_IT (&it2
, &it2
, it2data
);
1504 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1506 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1507 *rtop
= max (0, -it2
.current_y
);
1508 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1509 - it
.last_visible_y
));
1510 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1512 - max (it2
.current_y
,
1513 WINDOW_HEADER_LINE_HEIGHT (w
))));
1517 bidi_unshelve_cache (it2data
, 1);
1519 bidi_unshelve_cache (itdata
, 0);
1522 set_buffer_internal_1 (old_buffer
);
1524 current_header_line_height
= current_mode_line_height
= -1;
1526 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1527 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1530 /* Debugging code. */
1532 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1533 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1535 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1542 /* Return the next character from STR. Return in *LEN the length of
1543 the character. This is like STRING_CHAR_AND_LENGTH but never
1544 returns an invalid character. If we find one, we return a `?', but
1545 with the length of the invalid character. */
1548 string_char_and_length (const unsigned char *str
, int *len
)
1552 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1553 if (!CHAR_VALID_P (c
))
1554 /* We may not change the length here because other places in Emacs
1555 don't use this function, i.e. they silently accept invalid
1564 /* Given a position POS containing a valid character and byte position
1565 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1567 static struct text_pos
1568 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1570 xassert (STRINGP (string
) && nchars
>= 0);
1572 if (STRING_MULTIBYTE (string
))
1574 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1579 string_char_and_length (p
, &len
);
1582 BYTEPOS (pos
) += len
;
1586 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1592 /* Value is the text position, i.e. character and byte position,
1593 for character position CHARPOS in STRING. */
1595 static inline struct text_pos
1596 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1598 struct text_pos pos
;
1599 xassert (STRINGP (string
));
1600 xassert (charpos
>= 0);
1601 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1606 /* Value is a text position, i.e. character and byte position, for
1607 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1608 means recognize multibyte characters. */
1610 static struct text_pos
1611 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1613 struct text_pos pos
;
1615 xassert (s
!= NULL
);
1616 xassert (charpos
>= 0);
1622 SET_TEXT_POS (pos
, 0, 0);
1625 string_char_and_length ((const unsigned char *) s
, &len
);
1628 BYTEPOS (pos
) += len
;
1632 SET_TEXT_POS (pos
, charpos
, charpos
);
1638 /* Value is the number of characters in C string S. MULTIBYTE_P
1639 non-zero means recognize multibyte characters. */
1642 number_of_chars (const char *s
, int multibyte_p
)
1648 EMACS_INT rest
= strlen (s
);
1650 const unsigned char *p
= (const unsigned char *) s
;
1652 for (nchars
= 0; rest
> 0; ++nchars
)
1654 string_char_and_length (p
, &len
);
1655 rest
-= len
, p
+= len
;
1659 nchars
= strlen (s
);
1665 /* Compute byte position NEWPOS->bytepos corresponding to
1666 NEWPOS->charpos. POS is a known position in string STRING.
1667 NEWPOS->charpos must be >= POS.charpos. */
1670 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1672 xassert (STRINGP (string
));
1673 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1675 if (STRING_MULTIBYTE (string
))
1676 *newpos
= string_pos_nchars_ahead (pos
, string
,
1677 CHARPOS (*newpos
) - CHARPOS (pos
));
1679 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1683 Return an estimation of the pixel height of mode or header lines on
1684 frame F. FACE_ID specifies what line's height to estimate. */
1687 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1689 #ifdef HAVE_WINDOW_SYSTEM
1690 if (FRAME_WINDOW_P (f
))
1692 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1694 /* This function is called so early when Emacs starts that the face
1695 cache and mode line face are not yet initialized. */
1696 if (FRAME_FACE_CACHE (f
))
1698 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1702 height
= FONT_HEIGHT (face
->font
);
1703 if (face
->box_line_width
> 0)
1704 height
+= 2 * face
->box_line_width
;
1715 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1716 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1717 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1718 not force the value into range. */
1721 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1722 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1725 #ifdef HAVE_WINDOW_SYSTEM
1726 if (FRAME_WINDOW_P (f
))
1728 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1729 even for negative values. */
1731 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1733 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1735 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1736 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1739 STORE_NATIVE_RECT (*bounds
,
1740 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1741 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1742 FRAME_COLUMN_WIDTH (f
) - 1,
1743 FRAME_LINE_HEIGHT (f
) - 1);
1749 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1750 pix_x
= FRAME_TOTAL_COLS (f
);
1754 else if (pix_y
> FRAME_LINES (f
))
1755 pix_y
= FRAME_LINES (f
);
1765 /* Find the glyph under window-relative coordinates X/Y in window W.
1766 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1767 strings. Return in *HPOS and *VPOS the row and column number of
1768 the glyph found. Return in *AREA the glyph area containing X.
1769 Value is a pointer to the glyph found or null if X/Y is not on
1770 text, or we can't tell because W's current matrix is not up to
1775 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1776 int *dx
, int *dy
, int *area
)
1778 struct glyph
*glyph
, *end
;
1779 struct glyph_row
*row
= NULL
;
1782 /* Find row containing Y. Give up if some row is not enabled. */
1783 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1785 row
= MATRIX_ROW (w
->current_matrix
, i
);
1786 if (!row
->enabled_p
)
1788 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1795 /* Give up if Y is not in the window. */
1796 if (i
== w
->current_matrix
->nrows
)
1799 /* Get the glyph area containing X. */
1800 if (w
->pseudo_window_p
)
1807 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1809 *area
= LEFT_MARGIN_AREA
;
1810 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1812 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1815 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1819 *area
= RIGHT_MARGIN_AREA
;
1820 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1824 /* Find glyph containing X. */
1825 glyph
= row
->glyphs
[*area
];
1826 end
= glyph
+ row
->used
[*area
];
1828 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1830 x
-= glyph
->pixel_width
;
1840 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1843 *hpos
= glyph
- row
->glyphs
[*area
];
1847 /* Convert frame-relative x/y to coordinates relative to window W.
1848 Takes pseudo-windows into account. */
1851 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1853 if (w
->pseudo_window_p
)
1855 /* A pseudo-window is always full-width, and starts at the
1856 left edge of the frame, plus a frame border. */
1857 struct frame
*f
= XFRAME (w
->frame
);
1858 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1859 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1863 *x
-= WINDOW_LEFT_EDGE_X (w
);
1864 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1868 #ifdef HAVE_WINDOW_SYSTEM
1871 Return in RECTS[] at most N clipping rectangles for glyph string S.
1872 Return the number of stored rectangles. */
1875 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1882 if (s
->row
->full_width_p
)
1884 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1885 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1886 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1888 /* Unless displaying a mode or menu bar line, which are always
1889 fully visible, clip to the visible part of the row. */
1890 if (s
->w
->pseudo_window_p
)
1891 r
.height
= s
->row
->visible_height
;
1893 r
.height
= s
->height
;
1897 /* This is a text line that may be partially visible. */
1898 r
.x
= window_box_left (s
->w
, s
->area
);
1899 r
.width
= window_box_width (s
->w
, s
->area
);
1900 r
.height
= s
->row
->visible_height
;
1904 if (r
.x
< s
->clip_head
->x
)
1906 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1907 r
.width
-= s
->clip_head
->x
- r
.x
;
1910 r
.x
= s
->clip_head
->x
;
1913 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1915 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1916 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1921 /* If S draws overlapping rows, it's sufficient to use the top and
1922 bottom of the window for clipping because this glyph string
1923 intentionally draws over other lines. */
1924 if (s
->for_overlaps
)
1926 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1927 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1929 /* Alas, the above simple strategy does not work for the
1930 environments with anti-aliased text: if the same text is
1931 drawn onto the same place multiple times, it gets thicker.
1932 If the overlap we are processing is for the erased cursor, we
1933 take the intersection with the rectangle of the cursor. */
1934 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1936 XRectangle rc
, r_save
= r
;
1938 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1939 rc
.y
= s
->w
->phys_cursor
.y
;
1940 rc
.width
= s
->w
->phys_cursor_width
;
1941 rc
.height
= s
->w
->phys_cursor_height
;
1943 x_intersect_rectangles (&r_save
, &rc
, &r
);
1948 /* Don't use S->y for clipping because it doesn't take partially
1949 visible lines into account. For example, it can be negative for
1950 partially visible lines at the top of a window. */
1951 if (!s
->row
->full_width_p
1952 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1953 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1955 r
.y
= max (0, s
->row
->y
);
1958 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1960 /* If drawing the cursor, don't let glyph draw outside its
1961 advertised boundaries. Cleartype does this under some circumstances. */
1962 if (s
->hl
== DRAW_CURSOR
)
1964 struct glyph
*glyph
= s
->first_glyph
;
1969 r
.width
-= s
->x
- r
.x
;
1972 r
.width
= min (r
.width
, glyph
->pixel_width
);
1974 /* If r.y is below window bottom, ensure that we still see a cursor. */
1975 height
= min (glyph
->ascent
+ glyph
->descent
,
1976 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1977 max_y
= window_text_bottom_y (s
->w
) - height
;
1978 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1979 if (s
->ybase
- glyph
->ascent
> max_y
)
1986 /* Don't draw cursor glyph taller than our actual glyph. */
1987 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1988 if (height
< r
.height
)
1990 max_y
= r
.y
+ r
.height
;
1991 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1992 r
.height
= min (max_y
- r
.y
, height
);
1999 XRectangle r_save
= r
;
2001 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2005 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2006 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2008 #ifdef CONVERT_FROM_XRECT
2009 CONVERT_FROM_XRECT (r
, *rects
);
2017 /* If we are processing overlapping and allowed to return
2018 multiple clipping rectangles, we exclude the row of the glyph
2019 string from the clipping rectangle. This is to avoid drawing
2020 the same text on the environment with anti-aliasing. */
2021 #ifdef CONVERT_FROM_XRECT
2024 XRectangle
*rs
= rects
;
2026 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2028 if (s
->for_overlaps
& OVERLAPS_PRED
)
2031 if (r
.y
+ r
.height
> row_y
)
2034 rs
[i
].height
= row_y
- r
.y
;
2040 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2043 if (r
.y
< row_y
+ s
->row
->visible_height
)
2045 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2047 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2048 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2057 #ifdef CONVERT_FROM_XRECT
2058 for (i
= 0; i
< n
; i
++)
2059 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2066 Return in *NR the clipping rectangle for glyph string S. */
2069 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2071 get_glyph_string_clip_rects (s
, nr
, 1);
2076 Return the position and height of the phys cursor in window W.
2077 Set w->phys_cursor_width to width of phys cursor.
2081 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2082 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2084 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2085 int x
, y
, wd
, h
, h0
, y0
;
2087 /* Compute the width of the rectangle to draw. If on a stretch
2088 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2089 rectangle as wide as the glyph, but use a canonical character
2091 wd
= glyph
->pixel_width
- 1;
2092 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2096 x
= w
->phys_cursor
.x
;
2103 if (glyph
->type
== STRETCH_GLYPH
2104 && !x_stretch_cursor_p
)
2105 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2106 w
->phys_cursor_width
= wd
;
2108 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2110 /* If y is below window bottom, ensure that we still see a cursor. */
2111 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2113 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2114 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2116 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2119 h
= max (h
- (y0
- y
) + 1, h0
);
2124 y0
= window_text_bottom_y (w
) - h0
;
2132 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2133 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2138 * Remember which glyph the mouse is over.
2142 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2146 struct glyph_row
*r
, *gr
, *end_row
;
2147 enum window_part part
;
2148 enum glyph_row_area area
;
2149 int x
, y
, width
, height
;
2151 /* Try to determine frame pixel position and size of the glyph under
2152 frame pixel coordinates X/Y on frame F. */
2154 if (!f
->glyphs_initialized_p
2155 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2158 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2159 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2163 w
= XWINDOW (window
);
2164 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2165 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2167 x
= window_relative_x_coord (w
, part
, gx
);
2168 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2170 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2171 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2173 if (w
->pseudo_window_p
)
2176 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2182 case ON_LEFT_MARGIN
:
2183 area
= LEFT_MARGIN_AREA
;
2186 case ON_RIGHT_MARGIN
:
2187 area
= RIGHT_MARGIN_AREA
;
2190 case ON_HEADER_LINE
:
2192 gr
= (part
== ON_HEADER_LINE
2193 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2194 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2197 goto text_glyph_row_found
;
2204 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2205 if (r
->y
+ r
->height
> y
)
2211 text_glyph_row_found
:
2214 struct glyph
*g
= gr
->glyphs
[area
];
2215 struct glyph
*end
= g
+ gr
->used
[area
];
2217 height
= gr
->height
;
2218 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2219 if (gx
+ g
->pixel_width
> x
)
2224 if (g
->type
== IMAGE_GLYPH
)
2226 /* Don't remember when mouse is over image, as
2227 image may have hot-spots. */
2228 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2231 width
= g
->pixel_width
;
2235 /* Use nominal char spacing at end of line. */
2237 gx
+= (x
/ width
) * width
;
2240 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2241 gx
+= window_box_left_offset (w
, area
);
2245 /* Use nominal line height at end of window. */
2246 gx
= (x
/ width
) * width
;
2248 gy
+= (y
/ height
) * height
;
2252 case ON_LEFT_FRINGE
:
2253 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2254 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2255 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2256 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2259 case ON_RIGHT_FRINGE
:
2260 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2261 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2262 : window_box_right_offset (w
, TEXT_AREA
));
2263 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2267 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2269 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2270 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2271 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2273 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2277 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2278 if (r
->y
+ r
->height
> y
)
2285 height
= gr
->height
;
2288 /* Use nominal line height at end of window. */
2290 gy
+= (y
/ height
) * height
;
2297 /* If there is no glyph under the mouse, then we divide the screen
2298 into a grid of the smallest glyph in the frame, and use that
2301 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2302 round down even for negative values. */
2308 gx
= (gx
/ width
) * width
;
2309 gy
= (gy
/ height
) * height
;
2314 gx
+= WINDOW_LEFT_EDGE_X (w
);
2315 gy
+= WINDOW_TOP_EDGE_Y (w
);
2318 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2320 /* Visible feedback for debugging. */
2323 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2324 f
->output_data
.x
->normal_gc
,
2325 gx
, gy
, width
, height
);
2331 #endif /* HAVE_WINDOW_SYSTEM */
2334 /***********************************************************************
2335 Lisp form evaluation
2336 ***********************************************************************/
2338 /* Error handler for safe_eval and safe_call. */
2341 safe_eval_handler (Lisp_Object arg
)
2343 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2348 /* Evaluate SEXPR and return the result, or nil if something went
2349 wrong. Prevent redisplay during the evaluation. */
2351 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2352 Return the result, or nil if something went wrong. Prevent
2353 redisplay during the evaluation. */
2356 safe_call (ptrdiff_t nargs
, Lisp_Object
*args
)
2360 if (inhibit_eval_during_redisplay
)
2364 int count
= SPECPDL_INDEX ();
2365 struct gcpro gcpro1
;
2368 gcpro1
.nvars
= nargs
;
2369 specbind (Qinhibit_redisplay
, Qt
);
2370 /* Use Qt to ensure debugger does not run,
2371 so there is no possibility of wanting to redisplay. */
2372 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2375 val
= unbind_to (count
, val
);
2382 /* Call function FN with one argument ARG.
2383 Return the result, or nil if something went wrong. */
2386 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2388 Lisp_Object args
[2];
2391 return safe_call (2, args
);
2394 static Lisp_Object Qeval
;
2397 safe_eval (Lisp_Object sexpr
)
2399 return safe_call1 (Qeval
, sexpr
);
2402 /* Call function FN with one argument ARG.
2403 Return the result, or nil if something went wrong. */
2406 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2408 Lisp_Object args
[3];
2412 return safe_call (3, args
);
2417 /***********************************************************************
2419 ***********************************************************************/
2423 /* Define CHECK_IT to perform sanity checks on iterators.
2424 This is for debugging. It is too slow to do unconditionally. */
2427 check_it (struct it
*it
)
2429 if (it
->method
== GET_FROM_STRING
)
2431 xassert (STRINGP (it
->string
));
2432 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2436 xassert (IT_STRING_CHARPOS (*it
) < 0);
2437 if (it
->method
== GET_FROM_BUFFER
)
2439 /* Check that character and byte positions agree. */
2440 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2445 xassert (it
->current
.dpvec_index
>= 0);
2447 xassert (it
->current
.dpvec_index
< 0);
2450 #define CHECK_IT(IT) check_it ((IT))
2454 #define CHECK_IT(IT) (void) 0
2459 #if GLYPH_DEBUG && XASSERTS
2461 /* Check that the window end of window W is what we expect it
2462 to be---the last row in the current matrix displaying text. */
2465 check_window_end (struct window
*w
)
2467 if (!MINI_WINDOW_P (w
)
2468 && !NILP (w
->window_end_valid
))
2470 struct glyph_row
*row
;
2471 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2472 XFASTINT (w
->window_end_vpos
)),
2474 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2475 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2479 #define CHECK_WINDOW_END(W) check_window_end ((W))
2483 #define CHECK_WINDOW_END(W) (void) 0
2489 /***********************************************************************
2490 Iterator initialization
2491 ***********************************************************************/
2493 /* Initialize IT for displaying current_buffer in window W, starting
2494 at character position CHARPOS. CHARPOS < 0 means that no buffer
2495 position is specified which is useful when the iterator is assigned
2496 a position later. BYTEPOS is the byte position corresponding to
2497 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2499 If ROW is not null, calls to produce_glyphs with IT as parameter
2500 will produce glyphs in that row.
2502 BASE_FACE_ID is the id of a base face to use. It must be one of
2503 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2504 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2505 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2507 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2508 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2509 will be initialized to use the corresponding mode line glyph row of
2510 the desired matrix of W. */
2513 init_iterator (struct it
*it
, struct window
*w
,
2514 EMACS_INT charpos
, EMACS_INT bytepos
,
2515 struct glyph_row
*row
, enum face_id base_face_id
)
2517 int highlight_region_p
;
2518 enum face_id remapped_base_face_id
= base_face_id
;
2520 /* Some precondition checks. */
2521 xassert (w
!= NULL
&& it
!= NULL
);
2522 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2525 /* If face attributes have been changed since the last redisplay,
2526 free realized faces now because they depend on face definitions
2527 that might have changed. Don't free faces while there might be
2528 desired matrices pending which reference these faces. */
2529 if (face_change_count
&& !inhibit_free_realized_faces
)
2531 face_change_count
= 0;
2532 free_all_realized_faces (Qnil
);
2535 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2536 if (! NILP (Vface_remapping_alist
))
2537 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2539 /* Use one of the mode line rows of W's desired matrix if
2543 if (base_face_id
== MODE_LINE_FACE_ID
2544 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2545 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2546 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2547 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2551 memset (it
, 0, sizeof *it
);
2552 it
->current
.overlay_string_index
= -1;
2553 it
->current
.dpvec_index
= -1;
2554 it
->base_face_id
= remapped_base_face_id
;
2556 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2557 it
->paragraph_embedding
= L2R
;
2558 it
->bidi_it
.string
.lstring
= Qnil
;
2559 it
->bidi_it
.string
.s
= NULL
;
2560 it
->bidi_it
.string
.bufpos
= 0;
2562 /* The window in which we iterate over current_buffer: */
2563 XSETWINDOW (it
->window
, w
);
2565 it
->f
= XFRAME (w
->frame
);
2569 /* Extra space between lines (on window systems only). */
2570 if (base_face_id
== DEFAULT_FACE_ID
2571 && FRAME_WINDOW_P (it
->f
))
2573 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2574 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2575 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2576 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2577 * FRAME_LINE_HEIGHT (it
->f
));
2578 else if (it
->f
->extra_line_spacing
> 0)
2579 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2580 it
->max_extra_line_spacing
= 0;
2583 /* If realized faces have been removed, e.g. because of face
2584 attribute changes of named faces, recompute them. When running
2585 in batch mode, the face cache of the initial frame is null. If
2586 we happen to get called, make a dummy face cache. */
2587 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2588 init_frame_faces (it
->f
);
2589 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2590 recompute_basic_faces (it
->f
);
2592 /* Current value of the `slice', `space-width', and 'height' properties. */
2593 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2594 it
->space_width
= Qnil
;
2595 it
->font_height
= Qnil
;
2596 it
->override_ascent
= -1;
2598 /* Are control characters displayed as `^C'? */
2599 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2601 /* -1 means everything between a CR and the following line end
2602 is invisible. >0 means lines indented more than this value are
2604 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2605 ? XINT (BVAR (current_buffer
, selective_display
))
2606 : (!NILP (BVAR (current_buffer
, selective_display
))
2608 it
->selective_display_ellipsis_p
2609 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2611 /* Display table to use. */
2612 it
->dp
= window_display_table (w
);
2614 /* Are multibyte characters enabled in current_buffer? */
2615 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2617 /* Non-zero if we should highlight the region. */
2619 = (!NILP (Vtransient_mark_mode
)
2620 && !NILP (BVAR (current_buffer
, mark_active
))
2621 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2623 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2624 start and end of a visible region in window IT->w. Set both to
2625 -1 to indicate no region. */
2626 if (highlight_region_p
2627 /* Maybe highlight only in selected window. */
2628 && (/* Either show region everywhere. */
2629 highlight_nonselected_windows
2630 /* Or show region in the selected window. */
2631 || w
== XWINDOW (selected_window
)
2632 /* Or show the region if we are in the mini-buffer and W is
2633 the window the mini-buffer refers to. */
2634 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2635 && WINDOWP (minibuf_selected_window
)
2636 && w
== XWINDOW (minibuf_selected_window
))))
2638 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2639 it
->region_beg_charpos
= min (PT
, markpos
);
2640 it
->region_end_charpos
= max (PT
, markpos
);
2643 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2645 /* Get the position at which the redisplay_end_trigger hook should
2646 be run, if it is to be run at all. */
2647 if (MARKERP (w
->redisplay_end_trigger
)
2648 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2649 it
->redisplay_end_trigger_charpos
2650 = marker_position (w
->redisplay_end_trigger
);
2651 else if (INTEGERP (w
->redisplay_end_trigger
))
2652 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2654 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2656 /* Are lines in the display truncated? */
2657 if (base_face_id
!= DEFAULT_FACE_ID
2658 || XINT (it
->w
->hscroll
)
2659 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2660 && ((!NILP (Vtruncate_partial_width_windows
)
2661 && !INTEGERP (Vtruncate_partial_width_windows
))
2662 || (INTEGERP (Vtruncate_partial_width_windows
)
2663 && (WINDOW_TOTAL_COLS (it
->w
)
2664 < XINT (Vtruncate_partial_width_windows
))))))
2665 it
->line_wrap
= TRUNCATE
;
2666 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2667 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2668 ? WINDOW_WRAP
: WORD_WRAP
;
2670 it
->line_wrap
= TRUNCATE
;
2672 /* Get dimensions of truncation and continuation glyphs. These are
2673 displayed as fringe bitmaps under X, so we don't need them for such
2675 if (!FRAME_WINDOW_P (it
->f
))
2677 if (it
->line_wrap
== TRUNCATE
)
2679 /* We will need the truncation glyph. */
2680 xassert (it
->glyph_row
== NULL
);
2681 produce_special_glyphs (it
, IT_TRUNCATION
);
2682 it
->truncation_pixel_width
= it
->pixel_width
;
2686 /* We will need the continuation glyph. */
2687 xassert (it
->glyph_row
== NULL
);
2688 produce_special_glyphs (it
, IT_CONTINUATION
);
2689 it
->continuation_pixel_width
= it
->pixel_width
;
2692 /* Reset these values to zero because the produce_special_glyphs
2693 above has changed them. */
2694 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2695 it
->phys_ascent
= it
->phys_descent
= 0;
2698 /* Set this after getting the dimensions of truncation and
2699 continuation glyphs, so that we don't produce glyphs when calling
2700 produce_special_glyphs, above. */
2701 it
->glyph_row
= row
;
2702 it
->area
= TEXT_AREA
;
2704 /* Forget any previous info about this row being reversed. */
2706 it
->glyph_row
->reversed_p
= 0;
2708 /* Get the dimensions of the display area. The display area
2709 consists of the visible window area plus a horizontally scrolled
2710 part to the left of the window. All x-values are relative to the
2711 start of this total display area. */
2712 if (base_face_id
!= DEFAULT_FACE_ID
)
2714 /* Mode lines, menu bar in terminal frames. */
2715 it
->first_visible_x
= 0;
2716 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2721 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2722 it
->last_visible_x
= (it
->first_visible_x
2723 + window_box_width (w
, TEXT_AREA
));
2725 /* If we truncate lines, leave room for the truncator glyph(s) at
2726 the right margin. Otherwise, leave room for the continuation
2727 glyph(s). Truncation and continuation glyphs are not inserted
2728 for window-based redisplay. */
2729 if (!FRAME_WINDOW_P (it
->f
))
2731 if (it
->line_wrap
== TRUNCATE
)
2732 it
->last_visible_x
-= it
->truncation_pixel_width
;
2734 it
->last_visible_x
-= it
->continuation_pixel_width
;
2737 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2738 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2741 /* Leave room for a border glyph. */
2742 if (!FRAME_WINDOW_P (it
->f
)
2743 && !WINDOW_RIGHTMOST_P (it
->w
))
2744 it
->last_visible_x
-= 1;
2746 it
->last_visible_y
= window_text_bottom_y (w
);
2748 /* For mode lines and alike, arrange for the first glyph having a
2749 left box line if the face specifies a box. */
2750 if (base_face_id
!= DEFAULT_FACE_ID
)
2754 it
->face_id
= remapped_base_face_id
;
2756 /* If we have a boxed mode line, make the first character appear
2757 with a left box line. */
2758 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2759 if (face
->box
!= FACE_NO_BOX
)
2760 it
->start_of_box_run_p
= 1;
2763 /* If a buffer position was specified, set the iterator there,
2764 getting overlays and face properties from that position. */
2765 if (charpos
>= BUF_BEG (current_buffer
))
2767 it
->end_charpos
= ZV
;
2768 IT_CHARPOS (*it
) = charpos
;
2770 /* We will rely on `reseat' to set this up properly, via
2771 handle_face_prop. */
2772 it
->face_id
= it
->base_face_id
;
2774 /* Compute byte position if not specified. */
2775 if (bytepos
< charpos
)
2776 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2778 IT_BYTEPOS (*it
) = bytepos
;
2780 it
->start
= it
->current
;
2781 /* Do we need to reorder bidirectional text? Not if this is a
2782 unibyte buffer: by definition, none of the single-byte
2783 characters are strong R2L, so no reordering is needed. And
2784 bidi.c doesn't support unibyte buffers anyway. Also, don't
2785 reorder while we are loading loadup.el, since the tables of
2786 character properties needed for reordering are not yet
2790 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2793 /* If we are to reorder bidirectional text, init the bidi
2797 /* Note the paragraph direction that this buffer wants to
2799 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2801 it
->paragraph_embedding
= L2R
;
2802 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2804 it
->paragraph_embedding
= R2L
;
2806 it
->paragraph_embedding
= NEUTRAL_DIR
;
2807 bidi_unshelve_cache (NULL
, 0);
2808 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2812 /* Compute faces etc. */
2813 reseat (it
, it
->current
.pos
, 1);
2820 /* Initialize IT for the display of window W with window start POS. */
2823 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2825 struct glyph_row
*row
;
2826 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2828 row
= w
->desired_matrix
->rows
+ first_vpos
;
2829 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2830 it
->first_vpos
= first_vpos
;
2832 /* Don't reseat to previous visible line start if current start
2833 position is in a string or image. */
2834 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2836 int start_at_line_beg_p
;
2837 int first_y
= it
->current_y
;
2839 /* If window start is not at a line start, skip forward to POS to
2840 get the correct continuation lines width. */
2841 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2842 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2843 if (!start_at_line_beg_p
)
2847 reseat_at_previous_visible_line_start (it
);
2848 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2850 new_x
= it
->current_x
+ it
->pixel_width
;
2852 /* If lines are continued, this line may end in the middle
2853 of a multi-glyph character (e.g. a control character
2854 displayed as \003, or in the middle of an overlay
2855 string). In this case move_it_to above will not have
2856 taken us to the start of the continuation line but to the
2857 end of the continued line. */
2858 if (it
->current_x
> 0
2859 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2860 && (/* And glyph doesn't fit on the line. */
2861 new_x
> it
->last_visible_x
2862 /* Or it fits exactly and we're on a window
2864 || (new_x
== it
->last_visible_x
2865 && FRAME_WINDOW_P (it
->f
))))
2867 if ((it
->current
.dpvec_index
>= 0
2868 || it
->current
.overlay_string_index
>= 0)
2869 /* If we are on a newline from a display vector or
2870 overlay string, then we are already at the end of
2871 a screen line; no need to go to the next line in
2872 that case, as this line is not really continued.
2873 (If we do go to the next line, C-e will not DTRT.) */
2876 set_iterator_to_next (it
, 1);
2877 move_it_in_display_line_to (it
, -1, -1, 0);
2880 it
->continuation_lines_width
+= it
->current_x
;
2882 /* If the character at POS is displayed via a display
2883 vector, move_it_to above stops at the final glyph of
2884 IT->dpvec. To make the caller redisplay that character
2885 again (a.k.a. start at POS), we need to reset the
2886 dpvec_index to the beginning of IT->dpvec. */
2887 else if (it
->current
.dpvec_index
>= 0)
2888 it
->current
.dpvec_index
= 0;
2890 /* We're starting a new display line, not affected by the
2891 height of the continued line, so clear the appropriate
2892 fields in the iterator structure. */
2893 it
->max_ascent
= it
->max_descent
= 0;
2894 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2896 it
->current_y
= first_y
;
2898 it
->current_x
= it
->hpos
= 0;
2904 /* Return 1 if POS is a position in ellipses displayed for invisible
2905 text. W is the window we display, for text property lookup. */
2908 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2910 Lisp_Object prop
, window
;
2912 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2914 /* If POS specifies a position in a display vector, this might
2915 be for an ellipsis displayed for invisible text. We won't
2916 get the iterator set up for delivering that ellipsis unless
2917 we make sure that it gets aware of the invisible text. */
2918 if (pos
->dpvec_index
>= 0
2919 && pos
->overlay_string_index
< 0
2920 && CHARPOS (pos
->string_pos
) < 0
2922 && (XSETWINDOW (window
, w
),
2923 prop
= Fget_char_property (make_number (charpos
),
2924 Qinvisible
, window
),
2925 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2927 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2929 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2936 /* Initialize IT for stepping through current_buffer in window W,
2937 starting at position POS that includes overlay string and display
2938 vector/ control character translation position information. Value
2939 is zero if there are overlay strings with newlines at POS. */
2942 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2944 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2945 int i
, overlay_strings_with_newlines
= 0;
2947 /* If POS specifies a position in a display vector, this might
2948 be for an ellipsis displayed for invisible text. We won't
2949 get the iterator set up for delivering that ellipsis unless
2950 we make sure that it gets aware of the invisible text. */
2951 if (in_ellipses_for_invisible_text_p (pos
, w
))
2957 /* Keep in mind: the call to reseat in init_iterator skips invisible
2958 text, so we might end up at a position different from POS. This
2959 is only a problem when POS is a row start after a newline and an
2960 overlay starts there with an after-string, and the overlay has an
2961 invisible property. Since we don't skip invisible text in
2962 display_line and elsewhere immediately after consuming the
2963 newline before the row start, such a POS will not be in a string,
2964 but the call to init_iterator below will move us to the
2966 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2968 /* This only scans the current chunk -- it should scan all chunks.
2969 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2970 to 16 in 22.1 to make this a lesser problem. */
2971 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2973 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2974 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2976 while (s
< e
&& *s
!= '\n')
2981 overlay_strings_with_newlines
= 1;
2986 /* If position is within an overlay string, set up IT to the right
2988 if (pos
->overlay_string_index
>= 0)
2992 /* If the first overlay string happens to have a `display'
2993 property for an image, the iterator will be set up for that
2994 image, and we have to undo that setup first before we can
2995 correct the overlay string index. */
2996 if (it
->method
== GET_FROM_IMAGE
)
2999 /* We already have the first chunk of overlay strings in
3000 IT->overlay_strings. Load more until the one for
3001 pos->overlay_string_index is in IT->overlay_strings. */
3002 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3004 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3005 it
->current
.overlay_string_index
= 0;
3008 load_overlay_strings (it
, 0);
3009 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3013 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3014 relative_index
= (it
->current
.overlay_string_index
3015 % OVERLAY_STRING_CHUNK_SIZE
);
3016 it
->string
= it
->overlay_strings
[relative_index
];
3017 xassert (STRINGP (it
->string
));
3018 it
->current
.string_pos
= pos
->string_pos
;
3019 it
->method
= GET_FROM_STRING
;
3022 if (CHARPOS (pos
->string_pos
) >= 0)
3024 /* Recorded position is not in an overlay string, but in another
3025 string. This can only be a string from a `display' property.
3026 IT should already be filled with that string. */
3027 it
->current
.string_pos
= pos
->string_pos
;
3028 xassert (STRINGP (it
->string
));
3031 /* Restore position in display vector translations, control
3032 character translations or ellipses. */
3033 if (pos
->dpvec_index
>= 0)
3035 if (it
->dpvec
== NULL
)
3036 get_next_display_element (it
);
3037 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3038 it
->current
.dpvec_index
= pos
->dpvec_index
;
3042 return !overlay_strings_with_newlines
;
3046 /* Initialize IT for stepping through current_buffer in window W
3047 starting at ROW->start. */
3050 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3052 init_from_display_pos (it
, w
, &row
->start
);
3053 it
->start
= row
->start
;
3054 it
->continuation_lines_width
= row
->continuation_lines_width
;
3059 /* Initialize IT for stepping through current_buffer in window W
3060 starting in the line following ROW, i.e. starting at ROW->end.
3061 Value is zero if there are overlay strings with newlines at ROW's
3065 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3069 if (init_from_display_pos (it
, w
, &row
->end
))
3071 if (row
->continued_p
)
3072 it
->continuation_lines_width
3073 = row
->continuation_lines_width
+ row
->pixel_width
;
3084 /***********************************************************************
3086 ***********************************************************************/
3088 /* Called when IT reaches IT->stop_charpos. Handle text property and
3089 overlay changes. Set IT->stop_charpos to the next position where
3093 handle_stop (struct it
*it
)
3095 enum prop_handled handled
;
3096 int handle_overlay_change_p
;
3100 it
->current
.dpvec_index
= -1;
3101 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3102 it
->ignore_overlay_strings_at_pos_p
= 0;
3105 /* Use face of preceding text for ellipsis (if invisible) */
3106 if (it
->selective_display_ellipsis_p
)
3107 it
->saved_face_id
= it
->face_id
;
3111 handled
= HANDLED_NORMALLY
;
3113 /* Call text property handlers. */
3114 for (p
= it_props
; p
->handler
; ++p
)
3116 handled
= p
->handler (it
);
3118 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3120 else if (handled
== HANDLED_RETURN
)
3122 /* We still want to show before and after strings from
3123 overlays even if the actual buffer text is replaced. */
3124 if (!handle_overlay_change_p
3126 || !get_overlay_strings_1 (it
, 0, 0))
3129 setup_for_ellipsis (it
, 0);
3130 /* When handling a display spec, we might load an
3131 empty string. In that case, discard it here. We
3132 used to discard it in handle_single_display_spec,
3133 but that causes get_overlay_strings_1, above, to
3134 ignore overlay strings that we must check. */
3135 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3139 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3143 it
->ignore_overlay_strings_at_pos_p
= 1;
3144 it
->string_from_display_prop_p
= 0;
3145 it
->from_disp_prop_p
= 0;
3146 handle_overlay_change_p
= 0;
3148 handled
= HANDLED_RECOMPUTE_PROPS
;
3151 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3152 handle_overlay_change_p
= 0;
3155 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3157 /* Don't check for overlay strings below when set to deliver
3158 characters from a display vector. */
3159 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3160 handle_overlay_change_p
= 0;
3162 /* Handle overlay changes.
3163 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3164 if it finds overlays. */
3165 if (handle_overlay_change_p
)
3166 handled
= handle_overlay_change (it
);
3171 setup_for_ellipsis (it
, 0);
3175 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3177 /* Determine where to stop next. */
3178 if (handled
== HANDLED_NORMALLY
)
3179 compute_stop_pos (it
);
3183 /* Compute IT->stop_charpos from text property and overlay change
3184 information for IT's current position. */
3187 compute_stop_pos (struct it
*it
)
3189 register INTERVAL iv
, next_iv
;
3190 Lisp_Object object
, limit
, position
;
3191 EMACS_INT charpos
, bytepos
;
3193 if (STRINGP (it
->string
))
3195 /* Strings are usually short, so don't limit the search for
3197 it
->stop_charpos
= it
->end_charpos
;
3198 object
= it
->string
;
3200 charpos
= IT_STRING_CHARPOS (*it
);
3201 bytepos
= IT_STRING_BYTEPOS (*it
);
3207 /* If end_charpos is out of range for some reason, such as a
3208 misbehaving display function, rationalize it (Bug#5984). */
3209 if (it
->end_charpos
> ZV
)
3210 it
->end_charpos
= ZV
;
3211 it
->stop_charpos
= it
->end_charpos
;
3213 /* If next overlay change is in front of the current stop pos
3214 (which is IT->end_charpos), stop there. Note: value of
3215 next_overlay_change is point-max if no overlay change
3217 charpos
= IT_CHARPOS (*it
);
3218 bytepos
= IT_BYTEPOS (*it
);
3219 pos
= next_overlay_change (charpos
);
3220 if (pos
< it
->stop_charpos
)
3221 it
->stop_charpos
= pos
;
3223 /* If showing the region, we have to stop at the region
3224 start or end because the face might change there. */
3225 if (it
->region_beg_charpos
> 0)
3227 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3228 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3229 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3230 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3233 /* Set up variables for computing the stop position from text
3234 property changes. */
3235 XSETBUFFER (object
, current_buffer
);
3236 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3239 /* Get the interval containing IT's position. Value is a null
3240 interval if there isn't such an interval. */
3241 position
= make_number (charpos
);
3242 iv
= validate_interval_range (object
, &position
, &position
, 0);
3243 if (!NULL_INTERVAL_P (iv
))
3245 Lisp_Object values_here
[LAST_PROP_IDX
];
3248 /* Get properties here. */
3249 for (p
= it_props
; p
->handler
; ++p
)
3250 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3252 /* Look for an interval following iv that has different
3254 for (next_iv
= next_interval (iv
);
3255 (!NULL_INTERVAL_P (next_iv
)
3257 || XFASTINT (limit
) > next_iv
->position
));
3258 next_iv
= next_interval (next_iv
))
3260 for (p
= it_props
; p
->handler
; ++p
)
3262 Lisp_Object new_value
;
3264 new_value
= textget (next_iv
->plist
, *p
->name
);
3265 if (!EQ (values_here
[p
->idx
], new_value
))
3273 if (!NULL_INTERVAL_P (next_iv
))
3275 if (INTEGERP (limit
)
3276 && next_iv
->position
>= XFASTINT (limit
))
3277 /* No text property change up to limit. */
3278 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3280 /* Text properties change in next_iv. */
3281 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3285 if (it
->cmp_it
.id
< 0)
3287 EMACS_INT stoppos
= it
->end_charpos
;
3289 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3291 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3292 stoppos
, it
->string
);
3295 xassert (STRINGP (it
->string
)
3296 || (it
->stop_charpos
>= BEGV
3297 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3301 /* Return the position of the next overlay change after POS in
3302 current_buffer. Value is point-max if no overlay change
3303 follows. This is like `next-overlay-change' but doesn't use
3307 next_overlay_change (EMACS_INT pos
)
3309 ptrdiff_t i
, noverlays
;
3311 Lisp_Object
*overlays
;
3313 /* Get all overlays at the given position. */
3314 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3316 /* If any of these overlays ends before endpos,
3317 use its ending point instead. */
3318 for (i
= 0; i
< noverlays
; ++i
)
3323 oend
= OVERLAY_END (overlays
[i
]);
3324 oendpos
= OVERLAY_POSITION (oend
);
3325 endpos
= min (endpos
, oendpos
);
3331 /* How many characters forward to search for a display property or
3332 display string. Searching too far forward makes the bidi display
3333 sluggish, especially in small windows. */
3334 #define MAX_DISP_SCAN 250
3336 /* Return the character position of a display string at or after
3337 position specified by POSITION. If no display string exists at or
3338 after POSITION, return ZV. A display string is either an overlay
3339 with `display' property whose value is a string, or a `display'
3340 text property whose value is a string. STRING is data about the
3341 string to iterate; if STRING->lstring is nil, we are iterating a
3342 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3343 on a GUI frame. DISP_PROP is set to zero if we searched
3344 MAX_DISP_SCAN characters forward without finding any display
3345 strings, non-zero otherwise. It is set to 2 if the display string
3346 uses any kind of `(space ...)' spec that will produce a stretch of
3347 white space in the text area. */
3349 compute_display_string_pos (struct text_pos
*position
,
3350 struct bidi_string_data
*string
,
3351 int frame_window_p
, int *disp_prop
)
3353 /* OBJECT = nil means current buffer. */
3354 Lisp_Object object
=
3355 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3356 Lisp_Object pos
, spec
, limpos
;
3357 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3358 EMACS_INT eob
= string_p
? string
->schars
: ZV
;
3359 EMACS_INT begb
= string_p
? 0 : BEGV
;
3360 EMACS_INT bufpos
, charpos
= CHARPOS (*position
);
3362 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3363 struct text_pos tpos
;
3369 /* We don't support display properties whose values are strings
3370 that have display string properties. */
3371 || string
->from_disp_str
3372 /* C strings cannot have display properties. */
3373 || (string
->s
&& !STRINGP (object
)))
3379 /* If the character at CHARPOS is where the display string begins,
3381 pos
= make_number (charpos
);
3382 if (STRINGP (object
))
3383 bufpos
= string
->bufpos
;
3387 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3389 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3392 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3400 /* Look forward for the first character with a `display' property
3401 that will replace the underlying text when displayed. */
3402 limpos
= make_number (lim
);
3404 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3405 CHARPOS (tpos
) = XFASTINT (pos
);
3406 if (CHARPOS (tpos
) >= lim
)
3411 if (STRINGP (object
))
3412 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3414 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3415 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3416 if (!STRINGP (object
))
3417 bufpos
= CHARPOS (tpos
);
3418 } while (NILP (spec
)
3419 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3420 bufpos
, frame_window_p
)));
3424 return CHARPOS (tpos
);
3427 /* Return the character position of the end of the display string that
3428 started at CHARPOS. If there's no display string at CHARPOS,
3429 return -1. A display string is either an overlay with `display'
3430 property whose value is a string or a `display' text property whose
3431 value is a string. */
3433 compute_display_string_end (EMACS_INT charpos
, struct bidi_string_data
*string
)
3435 /* OBJECT = nil means current buffer. */
3436 Lisp_Object object
=
3437 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3438 Lisp_Object pos
= make_number (charpos
);
3440 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3442 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3445 /* It could happen that the display property or overlay was removed
3446 since we found it in compute_display_string_pos above. One way
3447 this can happen is if JIT font-lock was called (through
3448 handle_fontified_prop), and jit-lock-functions remove text
3449 properties or overlays from the portion of buffer that includes
3450 CHARPOS. Muse mode is known to do that, for example. In this
3451 case, we return -1 to the caller, to signal that no display
3452 string is actually present at CHARPOS. See bidi_fetch_char for
3453 how this is handled.
3455 An alternative would be to never look for display properties past
3456 it->stop_charpos. But neither compute_display_string_pos nor
3457 bidi_fetch_char that calls it know or care where the next
3459 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3462 /* Look forward for the first character where the `display' property
3464 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3466 return XFASTINT (pos
);
3471 /***********************************************************************
3473 ***********************************************************************/
3475 /* Handle changes in the `fontified' property of the current buffer by
3476 calling hook functions from Qfontification_functions to fontify
3479 static enum prop_handled
3480 handle_fontified_prop (struct it
*it
)
3482 Lisp_Object prop
, pos
;
3483 enum prop_handled handled
= HANDLED_NORMALLY
;
3485 if (!NILP (Vmemory_full
))
3488 /* Get the value of the `fontified' property at IT's current buffer
3489 position. (The `fontified' property doesn't have a special
3490 meaning in strings.) If the value is nil, call functions from
3491 Qfontification_functions. */
3492 if (!STRINGP (it
->string
)
3494 && !NILP (Vfontification_functions
)
3495 && !NILP (Vrun_hooks
)
3496 && (pos
= make_number (IT_CHARPOS (*it
)),
3497 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3498 /* Ignore the special cased nil value always present at EOB since
3499 no amount of fontifying will be able to change it. */
3500 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3502 int count
= SPECPDL_INDEX ();
3504 struct buffer
*obuf
= current_buffer
;
3505 int begv
= BEGV
, zv
= ZV
;
3506 int old_clip_changed
= current_buffer
->clip_changed
;
3508 val
= Vfontification_functions
;
3509 specbind (Qfontification_functions
, Qnil
);
3511 xassert (it
->end_charpos
== ZV
);
3513 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3514 safe_call1 (val
, pos
);
3517 Lisp_Object fns
, fn
;
3518 struct gcpro gcpro1
, gcpro2
;
3523 for (; CONSP (val
); val
= XCDR (val
))
3529 /* A value of t indicates this hook has a local
3530 binding; it means to run the global binding too.
3531 In a global value, t should not occur. If it
3532 does, we must ignore it to avoid an endless
3534 for (fns
= Fdefault_value (Qfontification_functions
);
3540 safe_call1 (fn
, pos
);
3544 safe_call1 (fn
, pos
);
3550 unbind_to (count
, Qnil
);
3552 /* Fontification functions routinely call `save-restriction'.
3553 Normally, this tags clip_changed, which can confuse redisplay
3554 (see discussion in Bug#6671). Since we don't perform any
3555 special handling of fontification changes in the case where
3556 `save-restriction' isn't called, there's no point doing so in
3557 this case either. So, if the buffer's restrictions are
3558 actually left unchanged, reset clip_changed. */
3559 if (obuf
== current_buffer
)
3561 if (begv
== BEGV
&& zv
== ZV
)
3562 current_buffer
->clip_changed
= old_clip_changed
;
3564 /* There isn't much we can reasonably do to protect against
3565 misbehaving fontification, but here's a fig leaf. */
3566 else if (!NILP (BVAR (obuf
, name
)))
3567 set_buffer_internal_1 (obuf
);
3569 /* The fontification code may have added/removed text.
3570 It could do even a lot worse, but let's at least protect against
3571 the most obvious case where only the text past `pos' gets changed',
3572 as is/was done in grep.el where some escapes sequences are turned
3573 into face properties (bug#7876). */
3574 it
->end_charpos
= ZV
;
3576 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3577 something. This avoids an endless loop if they failed to
3578 fontify the text for which reason ever. */
3579 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3580 handled
= HANDLED_RECOMPUTE_PROPS
;
3588 /***********************************************************************
3590 ***********************************************************************/
3592 /* Set up iterator IT from face properties at its current position.
3593 Called from handle_stop. */
3595 static enum prop_handled
3596 handle_face_prop (struct it
*it
)
3599 EMACS_INT next_stop
;
3601 if (!STRINGP (it
->string
))
3604 = face_at_buffer_position (it
->w
,
3606 it
->region_beg_charpos
,
3607 it
->region_end_charpos
,
3610 + TEXT_PROP_DISTANCE_LIMIT
),
3611 0, it
->base_face_id
);
3613 /* Is this a start of a run of characters with box face?
3614 Caveat: this can be called for a freshly initialized
3615 iterator; face_id is -1 in this case. We know that the new
3616 face will not change until limit, i.e. if the new face has a
3617 box, all characters up to limit will have one. But, as
3618 usual, we don't know whether limit is really the end. */
3619 if (new_face_id
!= it
->face_id
)
3621 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3623 /* If new face has a box but old face has not, this is
3624 the start of a run of characters with box, i.e. it has
3625 a shadow on the left side. The value of face_id of the
3626 iterator will be -1 if this is the initial call that gets
3627 the face. In this case, we have to look in front of IT's
3628 position and see whether there is a face != new_face_id. */
3629 it
->start_of_box_run_p
3630 = (new_face
->box
!= FACE_NO_BOX
3631 && (it
->face_id
>= 0
3632 || IT_CHARPOS (*it
) == BEG
3633 || new_face_id
!= face_before_it_pos (it
)));
3634 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3642 Lisp_Object from_overlay
3643 = (it
->current
.overlay_string_index
>= 0
3644 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3647 /* See if we got to this string directly or indirectly from
3648 an overlay property. That includes the before-string or
3649 after-string of an overlay, strings in display properties
3650 provided by an overlay, their text properties, etc.
3652 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3653 if (! NILP (from_overlay
))
3654 for (i
= it
->sp
- 1; i
>= 0; i
--)
3656 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3658 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3659 else if (! NILP (it
->stack
[i
].from_overlay
))
3660 from_overlay
= it
->stack
[i
].from_overlay
;
3662 if (!NILP (from_overlay
))
3666 if (! NILP (from_overlay
))
3668 bufpos
= IT_CHARPOS (*it
);
3669 /* For a string from an overlay, the base face depends
3670 only on text properties and ignores overlays. */
3672 = face_for_overlay_string (it
->w
,
3674 it
->region_beg_charpos
,
3675 it
->region_end_charpos
,
3678 + TEXT_PROP_DISTANCE_LIMIT
),
3686 /* For strings from a `display' property, use the face at
3687 IT's current buffer position as the base face to merge
3688 with, so that overlay strings appear in the same face as
3689 surrounding text, unless they specify their own
3691 base_face_id
= it
->string_from_prefix_prop_p
3693 : underlying_face_id (it
);
3696 new_face_id
= face_at_string_position (it
->w
,
3698 IT_STRING_CHARPOS (*it
),
3700 it
->region_beg_charpos
,
3701 it
->region_end_charpos
,
3705 /* Is this a start of a run of characters with box? Caveat:
3706 this can be called for a freshly allocated iterator; face_id
3707 is -1 is this case. We know that the new face will not
3708 change until the next check pos, i.e. if the new face has a
3709 box, all characters up to that position will have a
3710 box. But, as usual, we don't know whether that position
3711 is really the end. */
3712 if (new_face_id
!= it
->face_id
)
3714 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3715 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3717 /* If new face has a box but old face hasn't, this is the
3718 start of a run of characters with box, i.e. it has a
3719 shadow on the left side. */
3720 it
->start_of_box_run_p
3721 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3722 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3726 it
->face_id
= new_face_id
;
3727 return HANDLED_NORMALLY
;
3731 /* Return the ID of the face ``underlying'' IT's current position,
3732 which is in a string. If the iterator is associated with a
3733 buffer, return the face at IT's current buffer position.
3734 Otherwise, use the iterator's base_face_id. */
3737 underlying_face_id (struct it
*it
)
3739 int face_id
= it
->base_face_id
, i
;
3741 xassert (STRINGP (it
->string
));
3743 for (i
= it
->sp
- 1; i
>= 0; --i
)
3744 if (NILP (it
->stack
[i
].string
))
3745 face_id
= it
->stack
[i
].face_id
;
3751 /* Compute the face one character before or after the current position
3752 of IT, in the visual order. BEFORE_P non-zero means get the face
3753 in front (to the left in L2R paragraphs, to the right in R2L
3754 paragraphs) of IT's screen position. Value is the ID of the face. */
3757 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3760 EMACS_INT next_check_charpos
;
3762 void *it_copy_data
= NULL
;
3764 xassert (it
->s
== NULL
);
3766 if (STRINGP (it
->string
))
3768 EMACS_INT bufpos
, charpos
;
3771 /* No face change past the end of the string (for the case
3772 we are padding with spaces). No face change before the
3774 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3775 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3780 /* Set charpos to the position before or after IT's current
3781 position, in the logical order, which in the non-bidi
3782 case is the same as the visual order. */
3784 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3785 else if (it
->what
== IT_COMPOSITION
)
3786 /* For composition, we must check the character after the
3788 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3790 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3796 /* With bidi iteration, the character before the current
3797 in the visual order cannot be found by simple
3798 iteration, because "reverse" reordering is not
3799 supported. Instead, we need to use the move_it_*
3800 family of functions. */
3801 /* Ignore face changes before the first visible
3802 character on this display line. */
3803 if (it
->current_x
<= it
->first_visible_x
)
3805 SAVE_IT (it_copy
, *it
, it_copy_data
);
3806 /* Implementation note: Since move_it_in_display_line
3807 works in the iterator geometry, and thinks the first
3808 character is always the leftmost, even in R2L lines,
3809 we don't need to distinguish between the R2L and L2R
3811 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3812 it_copy
.current_x
- 1, MOVE_TO_X
);
3813 charpos
= IT_STRING_CHARPOS (it_copy
);
3814 RESTORE_IT (it
, it
, it_copy_data
);
3818 /* Set charpos to the string position of the character
3819 that comes after IT's current position in the visual
3821 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3825 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3827 charpos
= it_copy
.bidi_it
.charpos
;
3830 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3832 if (it
->current
.overlay_string_index
>= 0)
3833 bufpos
= IT_CHARPOS (*it
);
3837 base_face_id
= underlying_face_id (it
);
3839 /* Get the face for ASCII, or unibyte. */
3840 face_id
= face_at_string_position (it
->w
,
3844 it
->region_beg_charpos
,
3845 it
->region_end_charpos
,
3846 &next_check_charpos
,
3849 /* Correct the face for charsets different from ASCII. Do it
3850 for the multibyte case only. The face returned above is
3851 suitable for unibyte text if IT->string is unibyte. */
3852 if (STRING_MULTIBYTE (it
->string
))
3854 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3855 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3857 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3859 c
= string_char_and_length (p
, &len
);
3860 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3865 struct text_pos pos
;
3867 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3868 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3871 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3872 pos
= it
->current
.pos
;
3877 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3880 if (it
->what
== IT_COMPOSITION
)
3882 /* For composition, we must check the position after
3884 pos
.charpos
+= it
->cmp_it
.nchars
;
3885 pos
.bytepos
+= it
->len
;
3888 INC_TEXT_POS (pos
, it
->multibyte_p
);
3895 /* With bidi iteration, the character before the current
3896 in the visual order cannot be found by simple
3897 iteration, because "reverse" reordering is not
3898 supported. Instead, we need to use the move_it_*
3899 family of functions. */
3900 /* Ignore face changes before the first visible
3901 character on this display line. */
3902 if (it
->current_x
<= it
->first_visible_x
)
3904 SAVE_IT (it_copy
, *it
, it_copy_data
);
3905 /* Implementation note: Since move_it_in_display_line
3906 works in the iterator geometry, and thinks the first
3907 character is always the leftmost, even in R2L lines,
3908 we don't need to distinguish between the R2L and L2R
3910 move_it_in_display_line (&it_copy
, ZV
,
3911 it_copy
.current_x
- 1, MOVE_TO_X
);
3912 pos
= it_copy
.current
.pos
;
3913 RESTORE_IT (it
, it
, it_copy_data
);
3917 /* Set charpos to the buffer position of the character
3918 that comes after IT's current position in the visual
3920 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3924 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3927 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3930 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3932 /* Determine face for CHARSET_ASCII, or unibyte. */
3933 face_id
= face_at_buffer_position (it
->w
,
3935 it
->region_beg_charpos
,
3936 it
->region_end_charpos
,
3937 &next_check_charpos
,
3940 /* Correct the face for charsets different from ASCII. Do it
3941 for the multibyte case only. The face returned above is
3942 suitable for unibyte text if current_buffer is unibyte. */
3943 if (it
->multibyte_p
)
3945 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3946 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3947 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3956 /***********************************************************************
3958 ***********************************************************************/
3960 /* Set up iterator IT from invisible properties at its current
3961 position. Called from handle_stop. */
3963 static enum prop_handled
3964 handle_invisible_prop (struct it
*it
)
3966 enum prop_handled handled
= HANDLED_NORMALLY
;
3968 if (STRINGP (it
->string
))
3970 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3972 /* Get the value of the invisible text property at the
3973 current position. Value will be nil if there is no such
3975 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3976 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3979 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3983 handled
= HANDLED_RECOMPUTE_PROPS
;
3985 /* Get the position at which the next change of the
3986 invisible text property can be found in IT->string.
3987 Value will be nil if the property value is the same for
3988 all the rest of IT->string. */
3989 XSETINT (limit
, SCHARS (it
->string
));
3990 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3993 /* Text at current position is invisible. The next
3994 change in the property is at position end_charpos.
3995 Move IT's current position to that position. */
3996 if (INTEGERP (end_charpos
)
3997 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3999 struct text_pos old
;
4002 old
= it
->current
.string_pos
;
4003 oldpos
= CHARPOS (old
);
4006 if (it
->bidi_it
.first_elt
4007 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4008 bidi_paragraph_init (it
->paragraph_embedding
,
4010 /* Bidi-iterate out of the invisible text. */
4013 bidi_move_to_visually_next (&it
->bidi_it
);
4015 while (oldpos
<= it
->bidi_it
.charpos
4016 && it
->bidi_it
.charpos
< endpos
);
4018 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4019 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4020 if (IT_CHARPOS (*it
) >= endpos
)
4021 it
->prev_stop
= endpos
;
4025 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4026 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4031 /* The rest of the string is invisible. If this is an
4032 overlay string, proceed with the next overlay string
4033 or whatever comes and return a character from there. */
4034 if (it
->current
.overlay_string_index
>= 0)
4036 next_overlay_string (it
);
4037 /* Don't check for overlay strings when we just
4038 finished processing them. */
4039 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4043 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4044 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4052 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
4053 Lisp_Object pos
, prop
, overlay
;
4055 /* First of all, is there invisible text at this position? */
4056 tem
= start_charpos
= IT_CHARPOS (*it
);
4057 pos
= make_number (tem
);
4058 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4060 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4062 /* If we are on invisible text, skip over it. */
4063 if (invis_p
&& start_charpos
< it
->end_charpos
)
4065 /* Record whether we have to display an ellipsis for the
4067 int display_ellipsis_p
= invis_p
== 2;
4069 handled
= HANDLED_RECOMPUTE_PROPS
;
4071 /* Loop skipping over invisible text. The loop is left at
4072 ZV or with IT on the first char being visible again. */
4075 /* Try to skip some invisible text. Return value is the
4076 position reached which can be equal to where we start
4077 if there is nothing invisible there. This skips both
4078 over invisible text properties and overlays with
4079 invisible property. */
4080 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4082 /* If we skipped nothing at all we weren't at invisible
4083 text in the first place. If everything to the end of
4084 the buffer was skipped, end the loop. */
4085 if (newpos
== tem
|| newpos
>= ZV
)
4089 /* We skipped some characters but not necessarily
4090 all there are. Check if we ended up on visible
4091 text. Fget_char_property returns the property of
4092 the char before the given position, i.e. if we
4093 get invis_p = 0, this means that the char at
4094 newpos is visible. */
4095 pos
= make_number (newpos
);
4096 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4097 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4100 /* If we ended up on invisible text, proceed to
4101 skip starting with next_stop. */
4105 /* If there are adjacent invisible texts, don't lose the
4106 second one's ellipsis. */
4108 display_ellipsis_p
= 1;
4112 /* The position newpos is now either ZV or on visible text. */
4115 EMACS_INT bpos
= CHAR_TO_BYTE (newpos
);
4117 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4119 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4121 /* If the invisible text ends on a newline or on a
4122 character after a newline, we can avoid the costly,
4123 character by character, bidi iteration to NEWPOS, and
4124 instead simply reseat the iterator there. That's
4125 because all bidi reordering information is tossed at
4126 the newline. This is a big win for modes that hide
4127 complete lines, like Outline, Org, etc. */
4128 if (on_newline
|| after_newline
)
4130 struct text_pos tpos
;
4131 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4133 SET_TEXT_POS (tpos
, newpos
, bpos
);
4134 reseat_1 (it
, tpos
, 0);
4135 /* If we reseat on a newline/ZV, we need to prep the
4136 bidi iterator for advancing to the next character
4137 after the newline/EOB, keeping the current paragraph
4138 direction (so that PRODUCE_GLYPHS does TRT wrt
4139 prepending/appending glyphs to a glyph row). */
4142 it
->bidi_it
.first_elt
= 0;
4143 it
->bidi_it
.paragraph_dir
= pdir
;
4144 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4145 it
->bidi_it
.nchars
= 1;
4146 it
->bidi_it
.ch_len
= 1;
4149 else /* Must use the slow method. */
4151 /* With bidi iteration, the region of invisible text
4152 could start and/or end in the middle of a
4153 non-base embedding level. Therefore, we need to
4154 skip invisible text using the bidi iterator,
4155 starting at IT's current position, until we find
4156 ourselves outside of the invisible text.
4157 Skipping invisible text _after_ bidi iteration
4158 avoids affecting the visual order of the
4159 displayed text when invisible properties are
4160 added or removed. */
4161 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4163 /* If we were `reseat'ed to a new paragraph,
4164 determine the paragraph base direction. We
4165 need to do it now because
4166 next_element_from_buffer may not have a
4167 chance to do it, if we are going to skip any
4168 text at the beginning, which resets the
4170 bidi_paragraph_init (it
->paragraph_embedding
,
4175 bidi_move_to_visually_next (&it
->bidi_it
);
4177 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4178 && it
->bidi_it
.charpos
< newpos
);
4179 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4180 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4181 /* If we overstepped NEWPOS, record its position in
4182 the iterator, so that we skip invisible text if
4183 later the bidi iteration lands us in the
4184 invisible region again. */
4185 if (IT_CHARPOS (*it
) >= newpos
)
4186 it
->prev_stop
= newpos
;
4191 IT_CHARPOS (*it
) = newpos
;
4192 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4195 /* If there are before-strings at the start of invisible
4196 text, and the text is invisible because of a text
4197 property, arrange to show before-strings because 20.x did
4198 it that way. (If the text is invisible because of an
4199 overlay property instead of a text property, this is
4200 already handled in the overlay code.) */
4202 && get_overlay_strings (it
, it
->stop_charpos
))
4204 handled
= HANDLED_RECOMPUTE_PROPS
;
4205 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4207 else if (display_ellipsis_p
)
4209 /* Make sure that the glyphs of the ellipsis will get
4210 correct `charpos' values. If we would not update
4211 it->position here, the glyphs would belong to the
4212 last visible character _before_ the invisible
4213 text, which confuses `set_cursor_from_row'.
4215 We use the last invisible position instead of the
4216 first because this way the cursor is always drawn on
4217 the first "." of the ellipsis, whenever PT is inside
4218 the invisible text. Otherwise the cursor would be
4219 placed _after_ the ellipsis when the point is after the
4220 first invisible character. */
4221 if (!STRINGP (it
->object
))
4223 it
->position
.charpos
= newpos
- 1;
4224 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4227 /* Let the ellipsis display before
4228 considering any properties of the following char.
4229 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4230 handled
= HANDLED_RETURN
;
4239 /* Make iterator IT return `...' next.
4240 Replaces LEN characters from buffer. */
4243 setup_for_ellipsis (struct it
*it
, int len
)
4245 /* Use the display table definition for `...'. Invalid glyphs
4246 will be handled by the method returning elements from dpvec. */
4247 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4249 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4250 it
->dpvec
= v
->contents
;
4251 it
->dpend
= v
->contents
+ v
->header
.size
;
4255 /* Default `...'. */
4256 it
->dpvec
= default_invis_vector
;
4257 it
->dpend
= default_invis_vector
+ 3;
4260 it
->dpvec_char_len
= len
;
4261 it
->current
.dpvec_index
= 0;
4262 it
->dpvec_face_id
= -1;
4264 /* Remember the current face id in case glyphs specify faces.
4265 IT's face is restored in set_iterator_to_next.
4266 saved_face_id was set to preceding char's face in handle_stop. */
4267 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4268 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4270 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4276 /***********************************************************************
4278 ***********************************************************************/
4280 /* Set up iterator IT from `display' property at its current position.
4281 Called from handle_stop.
4282 We return HANDLED_RETURN if some part of the display property
4283 overrides the display of the buffer text itself.
4284 Otherwise we return HANDLED_NORMALLY. */
4286 static enum prop_handled
4287 handle_display_prop (struct it
*it
)
4289 Lisp_Object propval
, object
, overlay
;
4290 struct text_pos
*position
;
4292 /* Nonzero if some property replaces the display of the text itself. */
4293 int display_replaced_p
= 0;
4295 if (STRINGP (it
->string
))
4297 object
= it
->string
;
4298 position
= &it
->current
.string_pos
;
4299 bufpos
= CHARPOS (it
->current
.pos
);
4303 XSETWINDOW (object
, it
->w
);
4304 position
= &it
->current
.pos
;
4305 bufpos
= CHARPOS (*position
);
4308 /* Reset those iterator values set from display property values. */
4309 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4310 it
->space_width
= Qnil
;
4311 it
->font_height
= Qnil
;
4314 /* We don't support recursive `display' properties, i.e. string
4315 values that have a string `display' property, that have a string
4316 `display' property etc. */
4317 if (!it
->string_from_display_prop_p
)
4318 it
->area
= TEXT_AREA
;
4320 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4321 Qdisplay
, object
, &overlay
);
4323 return HANDLED_NORMALLY
;
4324 /* Now OVERLAY is the overlay that gave us this property, or nil
4325 if it was a text property. */
4327 if (!STRINGP (it
->string
))
4328 object
= it
->w
->buffer
;
4330 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4332 FRAME_WINDOW_P (it
->f
));
4334 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4337 /* Subroutine of handle_display_prop. Returns non-zero if the display
4338 specification in SPEC is a replacing specification, i.e. it would
4339 replace the text covered by `display' property with something else,
4340 such as an image or a display string. If SPEC includes any kind or
4341 `(space ...) specification, the value is 2; this is used by
4342 compute_display_string_pos, which see.
4344 See handle_single_display_spec for documentation of arguments.
4345 frame_window_p is non-zero if the window being redisplayed is on a
4346 GUI frame; this argument is used only if IT is NULL, see below.
4348 IT can be NULL, if this is called by the bidi reordering code
4349 through compute_display_string_pos, which see. In that case, this
4350 function only examines SPEC, but does not otherwise "handle" it, in
4351 the sense that it doesn't set up members of IT from the display
4354 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4355 Lisp_Object overlay
, struct text_pos
*position
,
4356 EMACS_INT bufpos
, int frame_window_p
)
4358 int replacing_p
= 0;
4362 /* Simple specifications. */
4363 && !EQ (XCAR (spec
), Qimage
)
4364 && !EQ (XCAR (spec
), Qspace
)
4365 && !EQ (XCAR (spec
), Qwhen
)
4366 && !EQ (XCAR (spec
), Qslice
)
4367 && !EQ (XCAR (spec
), Qspace_width
)
4368 && !EQ (XCAR (spec
), Qheight
)
4369 && !EQ (XCAR (spec
), Qraise
)
4370 /* Marginal area specifications. */
4371 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4372 && !EQ (XCAR (spec
), Qleft_fringe
)
4373 && !EQ (XCAR (spec
), Qright_fringe
)
4374 && !NILP (XCAR (spec
)))
4376 for (; CONSP (spec
); spec
= XCDR (spec
))
4378 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4379 overlay
, position
, bufpos
,
4380 replacing_p
, frame_window_p
)))
4383 /* If some text in a string is replaced, `position' no
4384 longer points to the position of `object'. */
4385 if (!it
|| STRINGP (object
))
4390 else if (VECTORP (spec
))
4393 for (i
= 0; i
< ASIZE (spec
); ++i
)
4394 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4395 overlay
, position
, bufpos
,
4396 replacing_p
, frame_window_p
)))
4399 /* If some text in a string is replaced, `position' no
4400 longer points to the position of `object'. */
4401 if (!it
|| STRINGP (object
))
4407 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4408 position
, bufpos
, 0,
4416 /* Value is the position of the end of the `display' property starting
4417 at START_POS in OBJECT. */
4419 static struct text_pos
4420 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4423 struct text_pos end_pos
;
4425 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4426 Qdisplay
, object
, Qnil
);
4427 CHARPOS (end_pos
) = XFASTINT (end
);
4428 if (STRINGP (object
))
4429 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4431 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4437 /* Set up IT from a single `display' property specification SPEC. OBJECT
4438 is the object in which the `display' property was found. *POSITION
4439 is the position in OBJECT at which the `display' property was found.
4440 BUFPOS is the buffer position of OBJECT (different from POSITION if
4441 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4442 previously saw a display specification which already replaced text
4443 display with something else, for example an image; we ignore such
4444 properties after the first one has been processed.
4446 OVERLAY is the overlay this `display' property came from,
4447 or nil if it was a text property.
4449 If SPEC is a `space' or `image' specification, and in some other
4450 cases too, set *POSITION to the position where the `display'
4453 If IT is NULL, only examine the property specification in SPEC, but
4454 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4455 is intended to be displayed in a window on a GUI frame.
4457 Value is non-zero if something was found which replaces the display
4458 of buffer or string text. */
4461 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4462 Lisp_Object overlay
, struct text_pos
*position
,
4463 EMACS_INT bufpos
, int display_replaced_p
,
4467 Lisp_Object location
, value
;
4468 struct text_pos start_pos
= *position
;
4471 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4472 If the result is non-nil, use VALUE instead of SPEC. */
4474 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4483 if (!NILP (form
) && !EQ (form
, Qt
))
4485 int count
= SPECPDL_INDEX ();
4486 struct gcpro gcpro1
;
4488 /* Bind `object' to the object having the `display' property, a
4489 buffer or string. Bind `position' to the position in the
4490 object where the property was found, and `buffer-position'
4491 to the current position in the buffer. */
4494 XSETBUFFER (object
, current_buffer
);
4495 specbind (Qobject
, object
);
4496 specbind (Qposition
, make_number (CHARPOS (*position
)));
4497 specbind (Qbuffer_position
, make_number (bufpos
));
4499 form
= safe_eval (form
);
4501 unbind_to (count
, Qnil
);
4507 /* Handle `(height HEIGHT)' specifications. */
4509 && EQ (XCAR (spec
), Qheight
)
4510 && CONSP (XCDR (spec
)))
4514 if (!FRAME_WINDOW_P (it
->f
))
4517 it
->font_height
= XCAR (XCDR (spec
));
4518 if (!NILP (it
->font_height
))
4520 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4521 int new_height
= -1;
4523 if (CONSP (it
->font_height
)
4524 && (EQ (XCAR (it
->font_height
), Qplus
)
4525 || EQ (XCAR (it
->font_height
), Qminus
))
4526 && CONSP (XCDR (it
->font_height
))
4527 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4529 /* `(+ N)' or `(- N)' where N is an integer. */
4530 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4531 if (EQ (XCAR (it
->font_height
), Qplus
))
4533 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4535 else if (FUNCTIONP (it
->font_height
))
4537 /* Call function with current height as argument.
4538 Value is the new height. */
4540 height
= safe_call1 (it
->font_height
,
4541 face
->lface
[LFACE_HEIGHT_INDEX
]);
4542 if (NUMBERP (height
))
4543 new_height
= XFLOATINT (height
);
4545 else if (NUMBERP (it
->font_height
))
4547 /* Value is a multiple of the canonical char height. */
4550 f
= FACE_FROM_ID (it
->f
,
4551 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4552 new_height
= (XFLOATINT (it
->font_height
)
4553 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4557 /* Evaluate IT->font_height with `height' bound to the
4558 current specified height to get the new height. */
4559 int count
= SPECPDL_INDEX ();
4561 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4562 value
= safe_eval (it
->font_height
);
4563 unbind_to (count
, Qnil
);
4565 if (NUMBERP (value
))
4566 new_height
= XFLOATINT (value
);
4570 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4577 /* Handle `(space-width WIDTH)'. */
4579 && EQ (XCAR (spec
), Qspace_width
)
4580 && CONSP (XCDR (spec
)))
4584 if (!FRAME_WINDOW_P (it
->f
))
4587 value
= XCAR (XCDR (spec
));
4588 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4589 it
->space_width
= value
;
4595 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4597 && EQ (XCAR (spec
), Qslice
))
4603 if (!FRAME_WINDOW_P (it
->f
))
4606 if (tem
= XCDR (spec
), CONSP (tem
))
4608 it
->slice
.x
= XCAR (tem
);
4609 if (tem
= XCDR (tem
), CONSP (tem
))
4611 it
->slice
.y
= XCAR (tem
);
4612 if (tem
= XCDR (tem
), CONSP (tem
))
4614 it
->slice
.width
= XCAR (tem
);
4615 if (tem
= XCDR (tem
), CONSP (tem
))
4616 it
->slice
.height
= XCAR (tem
);
4625 /* Handle `(raise FACTOR)'. */
4627 && EQ (XCAR (spec
), Qraise
)
4628 && CONSP (XCDR (spec
)))
4632 if (!FRAME_WINDOW_P (it
->f
))
4635 #ifdef HAVE_WINDOW_SYSTEM
4636 value
= XCAR (XCDR (spec
));
4637 if (NUMBERP (value
))
4639 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4640 it
->voffset
= - (XFLOATINT (value
)
4641 * (FONT_HEIGHT (face
->font
)));
4643 #endif /* HAVE_WINDOW_SYSTEM */
4649 /* Don't handle the other kinds of display specifications
4650 inside a string that we got from a `display' property. */
4651 if (it
&& it
->string_from_display_prop_p
)
4654 /* Characters having this form of property are not displayed, so
4655 we have to find the end of the property. */
4658 start_pos
= *position
;
4659 *position
= display_prop_end (it
, object
, start_pos
);
4663 /* Stop the scan at that end position--we assume that all
4664 text properties change there. */
4666 it
->stop_charpos
= position
->charpos
;
4668 /* Handle `(left-fringe BITMAP [FACE])'
4669 and `(right-fringe BITMAP [FACE])'. */
4671 && (EQ (XCAR (spec
), Qleft_fringe
)
4672 || EQ (XCAR (spec
), Qright_fringe
))
4673 && CONSP (XCDR (spec
)))
4679 if (!FRAME_WINDOW_P (it
->f
))
4680 /* If we return here, POSITION has been advanced
4681 across the text with this property. */
4684 else if (!frame_window_p
)
4687 #ifdef HAVE_WINDOW_SYSTEM
4688 value
= XCAR (XCDR (spec
));
4689 if (!SYMBOLP (value
)
4690 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4691 /* If we return here, POSITION has been advanced
4692 across the text with this property. */
4697 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4699 if (CONSP (XCDR (XCDR (spec
))))
4701 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4702 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4708 /* Save current settings of IT so that we can restore them
4709 when we are finished with the glyph property value. */
4710 push_it (it
, position
);
4712 it
->area
= TEXT_AREA
;
4713 it
->what
= IT_IMAGE
;
4714 it
->image_id
= -1; /* no image */
4715 it
->position
= start_pos
;
4716 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4717 it
->method
= GET_FROM_IMAGE
;
4718 it
->from_overlay
= Qnil
;
4719 it
->face_id
= face_id
;
4720 it
->from_disp_prop_p
= 1;
4722 /* Say that we haven't consumed the characters with
4723 `display' property yet. The call to pop_it in
4724 set_iterator_to_next will clean this up. */
4725 *position
= start_pos
;
4727 if (EQ (XCAR (spec
), Qleft_fringe
))
4729 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4730 it
->left_user_fringe_face_id
= face_id
;
4734 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4735 it
->right_user_fringe_face_id
= face_id
;
4738 #endif /* HAVE_WINDOW_SYSTEM */
4742 /* Prepare to handle `((margin left-margin) ...)',
4743 `((margin right-margin) ...)' and `((margin nil) ...)'
4744 prefixes for display specifications. */
4745 location
= Qunbound
;
4746 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4750 value
= XCDR (spec
);
4752 value
= XCAR (value
);
4755 if (EQ (XCAR (tem
), Qmargin
)
4756 && (tem
= XCDR (tem
),
4757 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4759 || EQ (tem
, Qleft_margin
)
4760 || EQ (tem
, Qright_margin
))))
4764 if (EQ (location
, Qunbound
))
4770 /* After this point, VALUE is the property after any
4771 margin prefix has been stripped. It must be a string,
4772 an image specification, or `(space ...)'.
4774 LOCATION specifies where to display: `left-margin',
4775 `right-margin' or nil. */
4777 valid_p
= (STRINGP (value
)
4778 #ifdef HAVE_WINDOW_SYSTEM
4779 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4780 && valid_image_p (value
))
4781 #endif /* not HAVE_WINDOW_SYSTEM */
4782 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4784 if (valid_p
&& !display_replaced_p
)
4790 /* Callers need to know whether the display spec is any kind
4791 of `(space ...)' spec that is about to affect text-area
4793 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4798 /* Save current settings of IT so that we can restore them
4799 when we are finished with the glyph property value. */
4800 push_it (it
, position
);
4801 it
->from_overlay
= overlay
;
4802 it
->from_disp_prop_p
= 1;
4804 if (NILP (location
))
4805 it
->area
= TEXT_AREA
;
4806 else if (EQ (location
, Qleft_margin
))
4807 it
->area
= LEFT_MARGIN_AREA
;
4809 it
->area
= RIGHT_MARGIN_AREA
;
4811 if (STRINGP (value
))
4814 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4815 it
->current
.overlay_string_index
= -1;
4816 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4817 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4818 it
->method
= GET_FROM_STRING
;
4819 it
->stop_charpos
= 0;
4821 it
->base_level_stop
= 0;
4822 it
->string_from_display_prop_p
= 1;
4823 /* Say that we haven't consumed the characters with
4824 `display' property yet. The call to pop_it in
4825 set_iterator_to_next will clean this up. */
4826 if (BUFFERP (object
))
4827 *position
= start_pos
;
4829 /* Force paragraph direction to be that of the parent
4830 object. If the parent object's paragraph direction is
4831 not yet determined, default to L2R. */
4832 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4833 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4835 it
->paragraph_embedding
= L2R
;
4837 /* Set up the bidi iterator for this display string. */
4840 it
->bidi_it
.string
.lstring
= it
->string
;
4841 it
->bidi_it
.string
.s
= NULL
;
4842 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4843 it
->bidi_it
.string
.bufpos
= bufpos
;
4844 it
->bidi_it
.string
.from_disp_str
= 1;
4845 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4846 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4849 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4851 it
->method
= GET_FROM_STRETCH
;
4853 *position
= it
->position
= start_pos
;
4854 retval
= 1 + (it
->area
== TEXT_AREA
);
4856 #ifdef HAVE_WINDOW_SYSTEM
4859 it
->what
= IT_IMAGE
;
4860 it
->image_id
= lookup_image (it
->f
, value
);
4861 it
->position
= start_pos
;
4862 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4863 it
->method
= GET_FROM_IMAGE
;
4865 /* Say that we haven't consumed the characters with
4866 `display' property yet. The call to pop_it in
4867 set_iterator_to_next will clean this up. */
4868 *position
= start_pos
;
4870 #endif /* HAVE_WINDOW_SYSTEM */
4875 /* Invalid property or property not supported. Restore
4876 POSITION to what it was before. */
4877 *position
= start_pos
;
4881 /* Check if PROP is a display property value whose text should be
4882 treated as intangible. OVERLAY is the overlay from which PROP
4883 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4884 specify the buffer position covered by PROP. */
4887 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4888 EMACS_INT charpos
, EMACS_INT bytepos
)
4890 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4891 struct text_pos position
;
4893 SET_TEXT_POS (position
, charpos
, bytepos
);
4894 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4895 &position
, charpos
, frame_window_p
);
4899 /* Return 1 if PROP is a display sub-property value containing STRING.
4901 Implementation note: this and the following function are really
4902 special cases of handle_display_spec and
4903 handle_single_display_spec, and should ideally use the same code.
4904 Until they do, these two pairs must be consistent and must be
4905 modified in sync. */
4908 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4910 if (EQ (string
, prop
))
4913 /* Skip over `when FORM'. */
4914 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4919 /* Actually, the condition following `when' should be eval'ed,
4920 like handle_single_display_spec does, and we should return
4921 zero if it evaluates to nil. However, this function is
4922 called only when the buffer was already displayed and some
4923 glyph in the glyph matrix was found to come from a display
4924 string. Therefore, the condition was already evaluated, and
4925 the result was non-nil, otherwise the display string wouldn't
4926 have been displayed and we would have never been called for
4927 this property. Thus, we can skip the evaluation and assume
4928 its result is non-nil. */
4933 /* Skip over `margin LOCATION'. */
4934 if (EQ (XCAR (prop
), Qmargin
))
4945 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4949 /* Return 1 if STRING appears in the `display' property PROP. */
4952 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4955 && !EQ (XCAR (prop
), Qwhen
)
4956 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4958 /* A list of sub-properties. */
4959 while (CONSP (prop
))
4961 if (single_display_spec_string_p (XCAR (prop
), string
))
4966 else if (VECTORP (prop
))
4968 /* A vector of sub-properties. */
4970 for (i
= 0; i
< ASIZE (prop
); ++i
)
4971 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4975 return single_display_spec_string_p (prop
, string
);
4980 /* Look for STRING in overlays and text properties in the current
4981 buffer, between character positions FROM and TO (excluding TO).
4982 BACK_P non-zero means look back (in this case, TO is supposed to be
4984 Value is the first character position where STRING was found, or
4985 zero if it wasn't found before hitting TO.
4987 This function may only use code that doesn't eval because it is
4988 called asynchronously from note_mouse_highlight. */
4991 string_buffer_position_lim (Lisp_Object string
,
4992 EMACS_INT from
, EMACS_INT to
, int back_p
)
4994 Lisp_Object limit
, prop
, pos
;
4997 pos
= make_number (max (from
, BEGV
));
4999 if (!back_p
) /* looking forward */
5001 limit
= make_number (min (to
, ZV
));
5002 while (!found
&& !EQ (pos
, limit
))
5004 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5005 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5008 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5012 else /* looking back */
5014 limit
= make_number (max (to
, BEGV
));
5015 while (!found
&& !EQ (pos
, limit
))
5017 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5018 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5021 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5026 return found
? XINT (pos
) : 0;
5029 /* Determine which buffer position in current buffer STRING comes from.
5030 AROUND_CHARPOS is an approximate position where it could come from.
5031 Value is the buffer position or 0 if it couldn't be determined.
5033 This function is necessary because we don't record buffer positions
5034 in glyphs generated from strings (to keep struct glyph small).
5035 This function may only use code that doesn't eval because it is
5036 called asynchronously from note_mouse_highlight. */
5039 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
5041 const int MAX_DISTANCE
= 1000;
5042 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
5043 around_charpos
+ MAX_DISTANCE
,
5047 found
= string_buffer_position_lim (string
, around_charpos
,
5048 around_charpos
- MAX_DISTANCE
, 1);
5054 /***********************************************************************
5055 `composition' property
5056 ***********************************************************************/
5058 /* Set up iterator IT from `composition' property at its current
5059 position. Called from handle_stop. */
5061 static enum prop_handled
5062 handle_composition_prop (struct it
*it
)
5064 Lisp_Object prop
, string
;
5065 EMACS_INT pos
, pos_byte
, start
, end
;
5067 if (STRINGP (it
->string
))
5071 pos
= IT_STRING_CHARPOS (*it
);
5072 pos_byte
= IT_STRING_BYTEPOS (*it
);
5073 string
= it
->string
;
5074 s
= SDATA (string
) + pos_byte
;
5075 it
->c
= STRING_CHAR (s
);
5079 pos
= IT_CHARPOS (*it
);
5080 pos_byte
= IT_BYTEPOS (*it
);
5082 it
->c
= FETCH_CHAR (pos_byte
);
5085 /* If there's a valid composition and point is not inside of the
5086 composition (in the case that the composition is from the current
5087 buffer), draw a glyph composed from the composition components. */
5088 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5089 && COMPOSITION_VALID_P (start
, end
, prop
)
5090 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5093 /* As we can't handle this situation (perhaps font-lock added
5094 a new composition), we just return here hoping that next
5095 redisplay will detect this composition much earlier. */
5096 return HANDLED_NORMALLY
;
5099 if (STRINGP (it
->string
))
5100 pos_byte
= string_char_to_byte (it
->string
, start
);
5102 pos_byte
= CHAR_TO_BYTE (start
);
5104 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5107 if (it
->cmp_it
.id
>= 0)
5110 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5111 it
->cmp_it
.nglyphs
= -1;
5115 return HANDLED_NORMALLY
;
5120 /***********************************************************************
5122 ***********************************************************************/
5124 /* The following structure is used to record overlay strings for
5125 later sorting in load_overlay_strings. */
5127 struct overlay_entry
5129 Lisp_Object overlay
;
5136 /* Set up iterator IT from overlay strings at its current position.
5137 Called from handle_stop. */
5139 static enum prop_handled
5140 handle_overlay_change (struct it
*it
)
5142 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5143 return HANDLED_RECOMPUTE_PROPS
;
5145 return HANDLED_NORMALLY
;
5149 /* Set up the next overlay string for delivery by IT, if there is an
5150 overlay string to deliver. Called by set_iterator_to_next when the
5151 end of the current overlay string is reached. If there are more
5152 overlay strings to display, IT->string and
5153 IT->current.overlay_string_index are set appropriately here.
5154 Otherwise IT->string is set to nil. */
5157 next_overlay_string (struct it
*it
)
5159 ++it
->current
.overlay_string_index
;
5160 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5162 /* No more overlay strings. Restore IT's settings to what
5163 they were before overlay strings were processed, and
5164 continue to deliver from current_buffer. */
5166 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5169 || (NILP (it
->string
)
5170 && it
->method
== GET_FROM_BUFFER
5171 && it
->stop_charpos
>= BEGV
5172 && it
->stop_charpos
<= it
->end_charpos
));
5173 it
->current
.overlay_string_index
= -1;
5174 it
->n_overlay_strings
= 0;
5175 it
->overlay_strings_charpos
= -1;
5176 /* If there's an empty display string on the stack, pop the
5177 stack, to resync the bidi iterator with IT's position. Such
5178 empty strings are pushed onto the stack in
5179 get_overlay_strings_1. */
5180 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5183 /* If we're at the end of the buffer, record that we have
5184 processed the overlay strings there already, so that
5185 next_element_from_buffer doesn't try it again. */
5186 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5187 it
->overlay_strings_at_end_processed_p
= 1;
5191 /* There are more overlay strings to process. If
5192 IT->current.overlay_string_index has advanced to a position
5193 where we must load IT->overlay_strings with more strings, do
5194 it. We must load at the IT->overlay_strings_charpos where
5195 IT->n_overlay_strings was originally computed; when invisible
5196 text is present, this might not be IT_CHARPOS (Bug#7016). */
5197 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5199 if (it
->current
.overlay_string_index
&& i
== 0)
5200 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5202 /* Initialize IT to deliver display elements from the overlay
5204 it
->string
= it
->overlay_strings
[i
];
5205 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5206 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5207 it
->method
= GET_FROM_STRING
;
5208 it
->stop_charpos
= 0;
5209 if (it
->cmp_it
.stop_pos
>= 0)
5210 it
->cmp_it
.stop_pos
= 0;
5212 it
->base_level_stop
= 0;
5214 /* Set up the bidi iterator for this overlay string. */
5217 it
->bidi_it
.string
.lstring
= it
->string
;
5218 it
->bidi_it
.string
.s
= NULL
;
5219 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5220 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5221 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5222 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5223 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5231 /* Compare two overlay_entry structures E1 and E2. Used as a
5232 comparison function for qsort in load_overlay_strings. Overlay
5233 strings for the same position are sorted so that
5235 1. All after-strings come in front of before-strings, except
5236 when they come from the same overlay.
5238 2. Within after-strings, strings are sorted so that overlay strings
5239 from overlays with higher priorities come first.
5241 2. Within before-strings, strings are sorted so that overlay
5242 strings from overlays with higher priorities come last.
5244 Value is analogous to strcmp. */
5248 compare_overlay_entries (const void *e1
, const void *e2
)
5250 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5251 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5254 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5256 /* Let after-strings appear in front of before-strings if
5257 they come from different overlays. */
5258 if (EQ (entry1
->overlay
, entry2
->overlay
))
5259 result
= entry1
->after_string_p
? 1 : -1;
5261 result
= entry1
->after_string_p
? -1 : 1;
5263 else if (entry1
->after_string_p
)
5264 /* After-strings sorted in order of decreasing priority. */
5265 result
= entry2
->priority
- entry1
->priority
;
5267 /* Before-strings sorted in order of increasing priority. */
5268 result
= entry1
->priority
- entry2
->priority
;
5274 /* Load the vector IT->overlay_strings with overlay strings from IT's
5275 current buffer position, or from CHARPOS if that is > 0. Set
5276 IT->n_overlays to the total number of overlay strings found.
5278 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5279 a time. On entry into load_overlay_strings,
5280 IT->current.overlay_string_index gives the number of overlay
5281 strings that have already been loaded by previous calls to this
5284 IT->add_overlay_start contains an additional overlay start
5285 position to consider for taking overlay strings from, if non-zero.
5286 This position comes into play when the overlay has an `invisible'
5287 property, and both before and after-strings. When we've skipped to
5288 the end of the overlay, because of its `invisible' property, we
5289 nevertheless want its before-string to appear.
5290 IT->add_overlay_start will contain the overlay start position
5293 Overlay strings are sorted so that after-string strings come in
5294 front of before-string strings. Within before and after-strings,
5295 strings are sorted by overlay priority. See also function
5296 compare_overlay_entries. */
5299 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5301 Lisp_Object overlay
, window
, str
, invisible
;
5302 struct Lisp_Overlay
*ov
;
5303 EMACS_INT start
, end
;
5305 int n
= 0, i
, j
, invis_p
;
5306 struct overlay_entry
*entries
5307 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5310 charpos
= IT_CHARPOS (*it
);
5312 /* Append the overlay string STRING of overlay OVERLAY to vector
5313 `entries' which has size `size' and currently contains `n'
5314 elements. AFTER_P non-zero means STRING is an after-string of
5316 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5319 Lisp_Object priority; \
5323 int new_size = 2 * size; \
5324 struct overlay_entry *old = entries; \
5326 (struct overlay_entry *) alloca (new_size \
5327 * sizeof *entries); \
5328 memcpy (entries, old, size * sizeof *entries); \
5332 entries[n].string = (STRING); \
5333 entries[n].overlay = (OVERLAY); \
5334 priority = Foverlay_get ((OVERLAY), Qpriority); \
5335 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5336 entries[n].after_string_p = (AFTER_P); \
5341 /* Process overlay before the overlay center. */
5342 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5344 XSETMISC (overlay
, ov
);
5345 xassert (OVERLAYP (overlay
));
5346 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5347 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5352 /* Skip this overlay if it doesn't start or end at IT's current
5354 if (end
!= charpos
&& start
!= charpos
)
5357 /* Skip this overlay if it doesn't apply to IT->w. */
5358 window
= Foverlay_get (overlay
, Qwindow
);
5359 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5362 /* If the text ``under'' the overlay is invisible, both before-
5363 and after-strings from this overlay are visible; start and
5364 end position are indistinguishable. */
5365 invisible
= Foverlay_get (overlay
, Qinvisible
);
5366 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5368 /* If overlay has a non-empty before-string, record it. */
5369 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5370 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5372 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5374 /* If overlay has a non-empty after-string, record it. */
5375 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5376 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5378 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5381 /* Process overlays after the overlay center. */
5382 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5384 XSETMISC (overlay
, ov
);
5385 xassert (OVERLAYP (overlay
));
5386 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5387 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5389 if (start
> charpos
)
5392 /* Skip this overlay if it doesn't start or end at IT's current
5394 if (end
!= charpos
&& start
!= charpos
)
5397 /* Skip this overlay if it doesn't apply to IT->w. */
5398 window
= Foverlay_get (overlay
, Qwindow
);
5399 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5402 /* If the text ``under'' the overlay is invisible, it has a zero
5403 dimension, and both before- and after-strings apply. */
5404 invisible
= Foverlay_get (overlay
, Qinvisible
);
5405 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5407 /* If overlay has a non-empty before-string, record it. */
5408 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5409 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5411 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5413 /* If overlay has a non-empty after-string, record it. */
5414 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5415 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5417 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5420 #undef RECORD_OVERLAY_STRING
5424 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5426 /* Record number of overlay strings, and where we computed it. */
5427 it
->n_overlay_strings
= n
;
5428 it
->overlay_strings_charpos
= charpos
;
5430 /* IT->current.overlay_string_index is the number of overlay strings
5431 that have already been consumed by IT. Copy some of the
5432 remaining overlay strings to IT->overlay_strings. */
5434 j
= it
->current
.overlay_string_index
;
5435 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5437 it
->overlay_strings
[i
] = entries
[j
].string
;
5438 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5445 /* Get the first chunk of overlay strings at IT's current buffer
5446 position, or at CHARPOS if that is > 0. Value is non-zero if at
5447 least one overlay string was found. */
5450 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5452 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5453 process. This fills IT->overlay_strings with strings, and sets
5454 IT->n_overlay_strings to the total number of strings to process.
5455 IT->pos.overlay_string_index has to be set temporarily to zero
5456 because load_overlay_strings needs this; it must be set to -1
5457 when no overlay strings are found because a zero value would
5458 indicate a position in the first overlay string. */
5459 it
->current
.overlay_string_index
= 0;
5460 load_overlay_strings (it
, charpos
);
5462 /* If we found overlay strings, set up IT to deliver display
5463 elements from the first one. Otherwise set up IT to deliver
5464 from current_buffer. */
5465 if (it
->n_overlay_strings
)
5467 /* Make sure we know settings in current_buffer, so that we can
5468 restore meaningful values when we're done with the overlay
5471 compute_stop_pos (it
);
5472 xassert (it
->face_id
>= 0);
5474 /* Save IT's settings. They are restored after all overlay
5475 strings have been processed. */
5476 xassert (!compute_stop_p
|| it
->sp
== 0);
5478 /* When called from handle_stop, there might be an empty display
5479 string loaded. In that case, don't bother saving it. But
5480 don't use this optimization with the bidi iterator, since we
5481 need the corresponding pop_it call to resync the bidi
5482 iterator's position with IT's position, after we are done
5483 with the overlay strings. (The corresponding call to pop_it
5484 in case of an empty display string is in
5485 next_overlay_string.) */
5487 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5490 /* Set up IT to deliver display elements from the first overlay
5492 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5493 it
->string
= it
->overlay_strings
[0];
5494 it
->from_overlay
= Qnil
;
5495 it
->stop_charpos
= 0;
5496 xassert (STRINGP (it
->string
));
5497 it
->end_charpos
= SCHARS (it
->string
);
5499 it
->base_level_stop
= 0;
5500 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5501 it
->method
= GET_FROM_STRING
;
5502 it
->from_disp_prop_p
= 0;
5504 /* Force paragraph direction to be that of the parent
5506 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5507 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5509 it
->paragraph_embedding
= L2R
;
5511 /* Set up the bidi iterator for this overlay string. */
5514 EMACS_INT pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5516 it
->bidi_it
.string
.lstring
= it
->string
;
5517 it
->bidi_it
.string
.s
= NULL
;
5518 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5519 it
->bidi_it
.string
.bufpos
= pos
;
5520 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5521 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5522 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5527 it
->current
.overlay_string_index
= -1;
5532 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5535 it
->method
= GET_FROM_BUFFER
;
5537 (void) get_overlay_strings_1 (it
, charpos
, 1);
5541 /* Value is non-zero if we found at least one overlay string. */
5542 return STRINGP (it
->string
);
5547 /***********************************************************************
5548 Saving and restoring state
5549 ***********************************************************************/
5551 /* Save current settings of IT on IT->stack. Called, for example,
5552 before setting up IT for an overlay string, to be able to restore
5553 IT's settings to what they were after the overlay string has been
5554 processed. If POSITION is non-NULL, it is the position to save on
5555 the stack instead of IT->position. */
5558 push_it (struct it
*it
, struct text_pos
*position
)
5560 struct iterator_stack_entry
*p
;
5562 xassert (it
->sp
< IT_STACK_SIZE
);
5563 p
= it
->stack
+ it
->sp
;
5565 p
->stop_charpos
= it
->stop_charpos
;
5566 p
->prev_stop
= it
->prev_stop
;
5567 p
->base_level_stop
= it
->base_level_stop
;
5568 p
->cmp_it
= it
->cmp_it
;
5569 xassert (it
->face_id
>= 0);
5570 p
->face_id
= it
->face_id
;
5571 p
->string
= it
->string
;
5572 p
->method
= it
->method
;
5573 p
->from_overlay
= it
->from_overlay
;
5576 case GET_FROM_IMAGE
:
5577 p
->u
.image
.object
= it
->object
;
5578 p
->u
.image
.image_id
= it
->image_id
;
5579 p
->u
.image
.slice
= it
->slice
;
5581 case GET_FROM_STRETCH
:
5582 p
->u
.stretch
.object
= it
->object
;
5585 p
->position
= position
? *position
: it
->position
;
5586 p
->current
= it
->current
;
5587 p
->end_charpos
= it
->end_charpos
;
5588 p
->string_nchars
= it
->string_nchars
;
5590 p
->multibyte_p
= it
->multibyte_p
;
5591 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5592 p
->space_width
= it
->space_width
;
5593 p
->font_height
= it
->font_height
;
5594 p
->voffset
= it
->voffset
;
5595 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5596 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5597 p
->display_ellipsis_p
= 0;
5598 p
->line_wrap
= it
->line_wrap
;
5599 p
->bidi_p
= it
->bidi_p
;
5600 p
->paragraph_embedding
= it
->paragraph_embedding
;
5601 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5604 /* Save the state of the bidi iterator as well. */
5606 bidi_push_it (&it
->bidi_it
);
5610 iterate_out_of_display_property (struct it
*it
)
5612 int buffer_p
= BUFFERP (it
->object
);
5613 EMACS_INT eob
= (buffer_p
? ZV
: it
->end_charpos
);
5614 EMACS_INT bob
= (buffer_p
? BEGV
: 0);
5616 xassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5618 /* Maybe initialize paragraph direction. If we are at the beginning
5619 of a new paragraph, next_element_from_buffer may not have a
5620 chance to do that. */
5621 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5622 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5623 /* prev_stop can be zero, so check against BEGV as well. */
5624 while (it
->bidi_it
.charpos
>= bob
5625 && it
->prev_stop
<= it
->bidi_it
.charpos
5626 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5627 && it
->bidi_it
.charpos
< eob
)
5628 bidi_move_to_visually_next (&it
->bidi_it
);
5629 /* Record the stop_pos we just crossed, for when we cross it
5631 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5632 it
->prev_stop
= CHARPOS (it
->position
);
5633 /* If we ended up not where pop_it put us, resync IT's
5634 positional members with the bidi iterator. */
5635 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5636 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5638 it
->current
.pos
= it
->position
;
5640 it
->current
.string_pos
= it
->position
;
5643 /* Restore IT's settings from IT->stack. Called, for example, when no
5644 more overlay strings must be processed, and we return to delivering
5645 display elements from a buffer, or when the end of a string from a
5646 `display' property is reached and we return to delivering display
5647 elements from an overlay string, or from a buffer. */
5650 pop_it (struct it
*it
)
5652 struct iterator_stack_entry
*p
;
5653 int from_display_prop
= it
->from_disp_prop_p
;
5655 xassert (it
->sp
> 0);
5657 p
= it
->stack
+ it
->sp
;
5658 it
->stop_charpos
= p
->stop_charpos
;
5659 it
->prev_stop
= p
->prev_stop
;
5660 it
->base_level_stop
= p
->base_level_stop
;
5661 it
->cmp_it
= p
->cmp_it
;
5662 it
->face_id
= p
->face_id
;
5663 it
->current
= p
->current
;
5664 it
->position
= p
->position
;
5665 it
->string
= p
->string
;
5666 it
->from_overlay
= p
->from_overlay
;
5667 if (NILP (it
->string
))
5668 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5669 it
->method
= p
->method
;
5672 case GET_FROM_IMAGE
:
5673 it
->image_id
= p
->u
.image
.image_id
;
5674 it
->object
= p
->u
.image
.object
;
5675 it
->slice
= p
->u
.image
.slice
;
5677 case GET_FROM_STRETCH
:
5678 it
->object
= p
->u
.stretch
.object
;
5680 case GET_FROM_BUFFER
:
5681 it
->object
= it
->w
->buffer
;
5683 case GET_FROM_STRING
:
5684 it
->object
= it
->string
;
5686 case GET_FROM_DISPLAY_VECTOR
:
5688 it
->method
= GET_FROM_C_STRING
;
5689 else if (STRINGP (it
->string
))
5690 it
->method
= GET_FROM_STRING
;
5693 it
->method
= GET_FROM_BUFFER
;
5694 it
->object
= it
->w
->buffer
;
5697 it
->end_charpos
= p
->end_charpos
;
5698 it
->string_nchars
= p
->string_nchars
;
5700 it
->multibyte_p
= p
->multibyte_p
;
5701 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5702 it
->space_width
= p
->space_width
;
5703 it
->font_height
= p
->font_height
;
5704 it
->voffset
= p
->voffset
;
5705 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5706 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5707 it
->line_wrap
= p
->line_wrap
;
5708 it
->bidi_p
= p
->bidi_p
;
5709 it
->paragraph_embedding
= p
->paragraph_embedding
;
5710 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5713 bidi_pop_it (&it
->bidi_it
);
5714 /* Bidi-iterate until we get out of the portion of text, if any,
5715 covered by a `display' text property or by an overlay with
5716 `display' property. (We cannot just jump there, because the
5717 internal coherency of the bidi iterator state can not be
5718 preserved across such jumps.) We also must determine the
5719 paragraph base direction if the overlay we just processed is
5720 at the beginning of a new paragraph. */
5721 if (from_display_prop
5722 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5723 iterate_out_of_display_property (it
);
5725 xassert ((BUFFERP (it
->object
)
5726 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5727 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5728 || (STRINGP (it
->object
)
5729 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5730 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5731 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5737 /***********************************************************************
5739 ***********************************************************************/
5741 /* Set IT's current position to the previous line start. */
5744 back_to_previous_line_start (struct it
*it
)
5746 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5747 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5751 /* Move IT to the next line start.
5753 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5754 we skipped over part of the text (as opposed to moving the iterator
5755 continuously over the text). Otherwise, don't change the value
5758 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5759 iterator on the newline, if it was found.
5761 Newlines may come from buffer text, overlay strings, or strings
5762 displayed via the `display' property. That's the reason we can't
5763 simply use find_next_newline_no_quit.
5765 Note that this function may not skip over invisible text that is so
5766 because of text properties and immediately follows a newline. If
5767 it would, function reseat_at_next_visible_line_start, when called
5768 from set_iterator_to_next, would effectively make invisible
5769 characters following a newline part of the wrong glyph row, which
5770 leads to wrong cursor motion. */
5773 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5774 struct bidi_it
*bidi_it_prev
)
5776 EMACS_INT old_selective
;
5777 int newline_found_p
, n
;
5778 const int MAX_NEWLINE_DISTANCE
= 500;
5780 /* If already on a newline, just consume it to avoid unintended
5781 skipping over invisible text below. */
5782 if (it
->what
== IT_CHARACTER
5784 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5786 if (it
->bidi_p
&& bidi_it_prev
)
5787 *bidi_it_prev
= it
->bidi_it
;
5788 set_iterator_to_next (it
, 0);
5793 /* Don't handle selective display in the following. It's (a)
5794 unnecessary because it's done by the caller, and (b) leads to an
5795 infinite recursion because next_element_from_ellipsis indirectly
5796 calls this function. */
5797 old_selective
= it
->selective
;
5800 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5801 from buffer text. */
5802 for (n
= newline_found_p
= 0;
5803 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5804 n
+= STRINGP (it
->string
) ? 0 : 1)
5806 if (!get_next_display_element (it
))
5808 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5809 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5810 *bidi_it_prev
= it
->bidi_it
;
5811 set_iterator_to_next (it
, 0);
5814 /* If we didn't find a newline near enough, see if we can use a
5816 if (!newline_found_p
)
5818 EMACS_INT start
= IT_CHARPOS (*it
);
5819 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5822 xassert (!STRINGP (it
->string
));
5824 /* If there isn't any `display' property in sight, and no
5825 overlays, we can just use the position of the newline in
5827 if (it
->stop_charpos
>= limit
5828 || ((pos
= Fnext_single_property_change (make_number (start
),
5830 make_number (limit
)),
5832 && next_overlay_change (start
) == ZV
))
5836 IT_CHARPOS (*it
) = limit
;
5837 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5841 struct bidi_it bprev
;
5843 /* Help bidi.c avoid expensive searches for display
5844 properties and overlays, by telling it that there are
5845 none up to `limit'. */
5846 if (it
->bidi_it
.disp_pos
< limit
)
5848 it
->bidi_it
.disp_pos
= limit
;
5849 it
->bidi_it
.disp_prop
= 0;
5852 bprev
= it
->bidi_it
;
5853 bidi_move_to_visually_next (&it
->bidi_it
);
5854 } while (it
->bidi_it
.charpos
!= limit
);
5855 IT_CHARPOS (*it
) = limit
;
5856 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5858 *bidi_it_prev
= bprev
;
5860 *skipped_p
= newline_found_p
= 1;
5864 while (get_next_display_element (it
)
5865 && !newline_found_p
)
5867 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5868 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5869 *bidi_it_prev
= it
->bidi_it
;
5870 set_iterator_to_next (it
, 0);
5875 it
->selective
= old_selective
;
5876 return newline_found_p
;
5880 /* Set IT's current position to the previous visible line start. Skip
5881 invisible text that is so either due to text properties or due to
5882 selective display. Caution: this does not change IT->current_x and
5886 back_to_previous_visible_line_start (struct it
*it
)
5888 while (IT_CHARPOS (*it
) > BEGV
)
5890 back_to_previous_line_start (it
);
5892 if (IT_CHARPOS (*it
) <= BEGV
)
5895 /* If selective > 0, then lines indented more than its value are
5897 if (it
->selective
> 0
5898 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5902 /* Check the newline before point for invisibility. */
5905 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5906 Qinvisible
, it
->window
);
5907 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5911 if (IT_CHARPOS (*it
) <= BEGV
)
5916 void *it2data
= NULL
;
5919 Lisp_Object val
, overlay
;
5921 SAVE_IT (it2
, *it
, it2data
);
5923 /* If newline is part of a composition, continue from start of composition */
5924 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5925 && beg
< IT_CHARPOS (*it
))
5928 /* If newline is replaced by a display property, find start of overlay
5929 or interval and continue search from that point. */
5930 pos
= --IT_CHARPOS (it2
);
5933 bidi_unshelve_cache (NULL
, 0);
5934 it2
.string_from_display_prop_p
= 0;
5935 it2
.from_disp_prop_p
= 0;
5936 if (handle_display_prop (&it2
) == HANDLED_RETURN
5937 && !NILP (val
= get_char_property_and_overlay
5938 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5939 && (OVERLAYP (overlay
)
5940 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5941 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5943 RESTORE_IT (it
, it
, it2data
);
5947 /* Newline is not replaced by anything -- so we are done. */
5948 RESTORE_IT (it
, it
, it2data
);
5954 IT_CHARPOS (*it
) = beg
;
5955 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5959 it
->continuation_lines_width
= 0;
5961 xassert (IT_CHARPOS (*it
) >= BEGV
);
5962 xassert (IT_CHARPOS (*it
) == BEGV
5963 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5968 /* Reseat iterator IT at the previous visible line start. Skip
5969 invisible text that is so either due to text properties or due to
5970 selective display. At the end, update IT's overlay information,
5971 face information etc. */
5974 reseat_at_previous_visible_line_start (struct it
*it
)
5976 back_to_previous_visible_line_start (it
);
5977 reseat (it
, it
->current
.pos
, 1);
5982 /* Reseat iterator IT on the next visible line start in the current
5983 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5984 preceding the line start. Skip over invisible text that is so
5985 because of selective display. Compute faces, overlays etc at the
5986 new position. Note that this function does not skip over text that
5987 is invisible because of text properties. */
5990 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5992 int newline_found_p
, skipped_p
= 0;
5993 struct bidi_it bidi_it_prev
;
5995 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
5997 /* Skip over lines that are invisible because they are indented
5998 more than the value of IT->selective. */
5999 if (it
->selective
> 0)
6000 while (IT_CHARPOS (*it
) < ZV
6001 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6004 xassert (IT_BYTEPOS (*it
) == BEGV
6005 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6007 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6010 /* Position on the newline if that's what's requested. */
6011 if (on_newline_p
&& newline_found_p
)
6013 if (STRINGP (it
->string
))
6015 if (IT_STRING_CHARPOS (*it
) > 0)
6019 --IT_STRING_CHARPOS (*it
);
6020 --IT_STRING_BYTEPOS (*it
);
6024 /* We need to restore the bidi iterator to the state
6025 it had on the newline, and resync the IT's
6026 position with that. */
6027 it
->bidi_it
= bidi_it_prev
;
6028 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6029 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6033 else if (IT_CHARPOS (*it
) > BEGV
)
6042 /* We need to restore the bidi iterator to the state it
6043 had on the newline and resync IT with that. */
6044 it
->bidi_it
= bidi_it_prev
;
6045 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6046 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6048 reseat (it
, it
->current
.pos
, 0);
6052 reseat (it
, it
->current
.pos
, 0);
6059 /***********************************************************************
6060 Changing an iterator's position
6061 ***********************************************************************/
6063 /* Change IT's current position to POS in current_buffer. If FORCE_P
6064 is non-zero, always check for text properties at the new position.
6065 Otherwise, text properties are only looked up if POS >=
6066 IT->check_charpos of a property. */
6069 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6071 EMACS_INT original_pos
= IT_CHARPOS (*it
);
6073 reseat_1 (it
, pos
, 0);
6075 /* Determine where to check text properties. Avoid doing it
6076 where possible because text property lookup is very expensive. */
6078 || CHARPOS (pos
) > it
->stop_charpos
6079 || CHARPOS (pos
) < original_pos
)
6083 /* For bidi iteration, we need to prime prev_stop and
6084 base_level_stop with our best estimations. */
6085 /* Implementation note: Of course, POS is not necessarily a
6086 stop position, so assigning prev_pos to it is a lie; we
6087 should have called compute_stop_backwards. However, if
6088 the current buffer does not include any R2L characters,
6089 that call would be a waste of cycles, because the
6090 iterator will never move back, and thus never cross this
6091 "fake" stop position. So we delay that backward search
6092 until the time we really need it, in next_element_from_buffer. */
6093 if (CHARPOS (pos
) != it
->prev_stop
)
6094 it
->prev_stop
= CHARPOS (pos
);
6095 if (CHARPOS (pos
) < it
->base_level_stop
)
6096 it
->base_level_stop
= 0; /* meaning it's unknown */
6102 it
->prev_stop
= it
->base_level_stop
= 0;
6111 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6112 IT->stop_pos to POS, also. */
6115 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6117 /* Don't call this function when scanning a C string. */
6118 xassert (it
->s
== NULL
);
6120 /* POS must be a reasonable value. */
6121 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6123 it
->current
.pos
= it
->position
= pos
;
6124 it
->end_charpos
= ZV
;
6126 it
->current
.dpvec_index
= -1;
6127 it
->current
.overlay_string_index
= -1;
6128 IT_STRING_CHARPOS (*it
) = -1;
6129 IT_STRING_BYTEPOS (*it
) = -1;
6131 it
->method
= GET_FROM_BUFFER
;
6132 it
->object
= it
->w
->buffer
;
6133 it
->area
= TEXT_AREA
;
6134 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6136 it
->string_from_display_prop_p
= 0;
6137 it
->string_from_prefix_prop_p
= 0;
6139 it
->from_disp_prop_p
= 0;
6140 it
->face_before_selective_p
= 0;
6143 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6145 bidi_unshelve_cache (NULL
, 0);
6146 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6147 it
->bidi_it
.string
.s
= NULL
;
6148 it
->bidi_it
.string
.lstring
= Qnil
;
6149 it
->bidi_it
.string
.bufpos
= 0;
6150 it
->bidi_it
.string
.unibyte
= 0;
6155 it
->stop_charpos
= CHARPOS (pos
);
6156 it
->base_level_stop
= CHARPOS (pos
);
6161 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6162 If S is non-null, it is a C string to iterate over. Otherwise,
6163 STRING gives a Lisp string to iterate over.
6165 If PRECISION > 0, don't return more then PRECISION number of
6166 characters from the string.
6168 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6169 characters have been returned. FIELD_WIDTH < 0 means an infinite
6172 MULTIBYTE = 0 means disable processing of multibyte characters,
6173 MULTIBYTE > 0 means enable it,
6174 MULTIBYTE < 0 means use IT->multibyte_p.
6176 IT must be initialized via a prior call to init_iterator before
6177 calling this function. */
6180 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6181 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
6184 /* No region in strings. */
6185 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6187 /* No text property checks performed by default, but see below. */
6188 it
->stop_charpos
= -1;
6190 /* Set iterator position and end position. */
6191 memset (&it
->current
, 0, sizeof it
->current
);
6192 it
->current
.overlay_string_index
= -1;
6193 it
->current
.dpvec_index
= -1;
6194 xassert (charpos
>= 0);
6196 /* If STRING is specified, use its multibyteness, otherwise use the
6197 setting of MULTIBYTE, if specified. */
6199 it
->multibyte_p
= multibyte
> 0;
6201 /* Bidirectional reordering of strings is controlled by the default
6202 value of bidi-display-reordering. Don't try to reorder while
6203 loading loadup.el, as the necessary character property tables are
6204 not yet available. */
6207 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6211 xassert (STRINGP (string
));
6212 it
->string
= string
;
6214 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6215 it
->method
= GET_FROM_STRING
;
6216 it
->current
.string_pos
= string_pos (charpos
, string
);
6220 it
->bidi_it
.string
.lstring
= string
;
6221 it
->bidi_it
.string
.s
= NULL
;
6222 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6223 it
->bidi_it
.string
.bufpos
= 0;
6224 it
->bidi_it
.string
.from_disp_str
= 0;
6225 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6226 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6227 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6232 it
->s
= (const unsigned char *) s
;
6235 /* Note that we use IT->current.pos, not it->current.string_pos,
6236 for displaying C strings. */
6237 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6238 if (it
->multibyte_p
)
6240 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6241 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6245 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6246 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6251 it
->bidi_it
.string
.lstring
= Qnil
;
6252 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6253 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6254 it
->bidi_it
.string
.bufpos
= 0;
6255 it
->bidi_it
.string
.from_disp_str
= 0;
6256 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6257 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6260 it
->method
= GET_FROM_C_STRING
;
6263 /* PRECISION > 0 means don't return more than PRECISION characters
6265 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6267 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6269 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6272 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6273 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6274 FIELD_WIDTH < 0 means infinite field width. This is useful for
6275 padding with `-' at the end of a mode line. */
6276 if (field_width
< 0)
6277 field_width
= INFINITY
;
6278 /* Implementation note: We deliberately don't enlarge
6279 it->bidi_it.string.schars here to fit it->end_charpos, because
6280 the bidi iterator cannot produce characters out of thin air. */
6281 if (field_width
> it
->end_charpos
- charpos
)
6282 it
->end_charpos
= charpos
+ field_width
;
6284 /* Use the standard display table for displaying strings. */
6285 if (DISP_TABLE_P (Vstandard_display_table
))
6286 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6288 it
->stop_charpos
= charpos
;
6289 it
->prev_stop
= charpos
;
6290 it
->base_level_stop
= 0;
6293 it
->bidi_it
.first_elt
= 1;
6294 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6295 it
->bidi_it
.disp_pos
= -1;
6297 if (s
== NULL
&& it
->multibyte_p
)
6299 EMACS_INT endpos
= SCHARS (it
->string
);
6300 if (endpos
> it
->end_charpos
)
6301 endpos
= it
->end_charpos
;
6302 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6310 /***********************************************************************
6312 ***********************************************************************/
6314 /* Map enum it_method value to corresponding next_element_from_* function. */
6316 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6318 next_element_from_buffer
,
6319 next_element_from_display_vector
,
6320 next_element_from_string
,
6321 next_element_from_c_string
,
6322 next_element_from_image
,
6323 next_element_from_stretch
6326 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6329 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6330 (possibly with the following characters). */
6332 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6333 ((IT)->cmp_it.id >= 0 \
6334 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6335 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6336 END_CHARPOS, (IT)->w, \
6337 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6341 /* Lookup the char-table Vglyphless_char_display for character C (-1
6342 if we want information for no-font case), and return the display
6343 method symbol. By side-effect, update it->what and
6344 it->glyphless_method. This function is called from
6345 get_next_display_element for each character element, and from
6346 x_produce_glyphs when no suitable font was found. */
6349 lookup_glyphless_char_display (int c
, struct it
*it
)
6351 Lisp_Object glyphless_method
= Qnil
;
6353 if (CHAR_TABLE_P (Vglyphless_char_display
)
6354 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6358 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6359 if (CONSP (glyphless_method
))
6360 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6361 ? XCAR (glyphless_method
)
6362 : XCDR (glyphless_method
);
6365 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6369 if (NILP (glyphless_method
))
6372 /* The default is to display the character by a proper font. */
6374 /* The default for the no-font case is to display an empty box. */
6375 glyphless_method
= Qempty_box
;
6377 if (EQ (glyphless_method
, Qzero_width
))
6380 return glyphless_method
;
6381 /* This method can't be used for the no-font case. */
6382 glyphless_method
= Qempty_box
;
6384 if (EQ (glyphless_method
, Qthin_space
))
6385 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6386 else if (EQ (glyphless_method
, Qempty_box
))
6387 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6388 else if (EQ (glyphless_method
, Qhex_code
))
6389 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6390 else if (STRINGP (glyphless_method
))
6391 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6394 /* Invalid value. We use the default method. */
6395 glyphless_method
= Qnil
;
6398 it
->what
= IT_GLYPHLESS
;
6399 return glyphless_method
;
6402 /* Load IT's display element fields with information about the next
6403 display element from the current position of IT. Value is zero if
6404 end of buffer (or C string) is reached. */
6406 static struct frame
*last_escape_glyph_frame
= NULL
;
6407 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6408 static int last_escape_glyph_merged_face_id
= 0;
6410 struct frame
*last_glyphless_glyph_frame
= NULL
;
6411 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6412 int last_glyphless_glyph_merged_face_id
= 0;
6415 get_next_display_element (struct it
*it
)
6417 /* Non-zero means that we found a display element. Zero means that
6418 we hit the end of what we iterate over. Performance note: the
6419 function pointer `method' used here turns out to be faster than
6420 using a sequence of if-statements. */
6424 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6426 if (it
->what
== IT_CHARACTER
)
6428 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6429 and only if (a) the resolved directionality of that character
6431 /* FIXME: Do we need an exception for characters from display
6433 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6434 it
->c
= bidi_mirror_char (it
->c
);
6435 /* Map via display table or translate control characters.
6436 IT->c, IT->len etc. have been set to the next character by
6437 the function call above. If we have a display table, and it
6438 contains an entry for IT->c, translate it. Don't do this if
6439 IT->c itself comes from a display table, otherwise we could
6440 end up in an infinite recursion. (An alternative could be to
6441 count the recursion depth of this function and signal an
6442 error when a certain maximum depth is reached.) Is it worth
6444 if (success_p
&& it
->dpvec
== NULL
)
6447 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6448 int nonascii_space_p
= 0;
6449 int nonascii_hyphen_p
= 0;
6450 int c
= it
->c
; /* This is the character to display. */
6452 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6454 xassert (SINGLE_BYTE_CHAR_P (c
));
6455 if (unibyte_display_via_language_environment
)
6457 c
= DECODE_CHAR (unibyte
, c
);
6459 c
= BYTE8_TO_CHAR (it
->c
);
6462 c
= BYTE8_TO_CHAR (it
->c
);
6466 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6469 struct Lisp_Vector
*v
= XVECTOR (dv
);
6471 /* Return the first character from the display table
6472 entry, if not empty. If empty, don't display the
6473 current character. */
6476 it
->dpvec_char_len
= it
->len
;
6477 it
->dpvec
= v
->contents
;
6478 it
->dpend
= v
->contents
+ v
->header
.size
;
6479 it
->current
.dpvec_index
= 0;
6480 it
->dpvec_face_id
= -1;
6481 it
->saved_face_id
= it
->face_id
;
6482 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6487 set_iterator_to_next (it
, 0);
6492 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6494 if (it
->what
== IT_GLYPHLESS
)
6496 /* Don't display this character. */
6497 set_iterator_to_next (it
, 0);
6501 /* If `nobreak-char-display' is non-nil, we display
6502 non-ASCII spaces and hyphens specially. */
6503 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6506 nonascii_space_p
= 1;
6507 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6508 nonascii_hyphen_p
= 1;
6511 /* Translate control characters into `\003' or `^C' form.
6512 Control characters coming from a display table entry are
6513 currently not translated because we use IT->dpvec to hold
6514 the translation. This could easily be changed but I
6515 don't believe that it is worth doing.
6517 The characters handled by `nobreak-char-display' must be
6520 Non-printable characters and raw-byte characters are also
6521 translated to octal form. */
6522 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6523 ? (it
->area
!= TEXT_AREA
6524 /* In mode line, treat \n, \t like other crl chars. */
6527 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6528 || (c
!= '\n' && c
!= '\t'))
6530 || nonascii_hyphen_p
6532 || ! CHAR_PRINTABLE_P (c
))))
6534 /* C is a control character, non-ASCII space/hyphen,
6535 raw-byte, or a non-printable character which must be
6536 displayed either as '\003' or as `^C' where the '\\'
6537 and '^' can be defined in the display table. Fill
6538 IT->ctl_chars with glyphs for what we have to
6539 display. Then, set IT->dpvec to these glyphs. */
6543 EMACS_INT lface_id
= 0;
6546 /* Handle control characters with ^. */
6548 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6552 g
= '^'; /* default glyph for Control */
6553 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6555 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6556 && GLYPH_CODE_CHAR_VALID_P (gc
))
6558 g
= GLYPH_CODE_CHAR (gc
);
6559 lface_id
= GLYPH_CODE_FACE (gc
);
6563 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6565 else if (it
->f
== last_escape_glyph_frame
6566 && it
->face_id
== last_escape_glyph_face_id
)
6568 face_id
= last_escape_glyph_merged_face_id
;
6572 /* Merge the escape-glyph face into the current face. */
6573 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6575 last_escape_glyph_frame
= it
->f
;
6576 last_escape_glyph_face_id
= it
->face_id
;
6577 last_escape_glyph_merged_face_id
= face_id
;
6580 XSETINT (it
->ctl_chars
[0], g
);
6581 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6583 goto display_control
;
6586 /* Handle non-ascii space in the mode where it only gets
6589 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6591 /* Merge `nobreak-space' into the current face. */
6592 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6594 XSETINT (it
->ctl_chars
[0], ' ');
6596 goto display_control
;
6599 /* Handle sequences that start with the "escape glyph". */
6601 /* the default escape glyph is \. */
6602 escape_glyph
= '\\';
6605 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6606 && GLYPH_CODE_CHAR_VALID_P (gc
))
6608 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6609 lface_id
= GLYPH_CODE_FACE (gc
);
6613 /* The display table specified a face.
6614 Merge it into face_id and also into escape_glyph. */
6615 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6618 else if (it
->f
== last_escape_glyph_frame
6619 && it
->face_id
== last_escape_glyph_face_id
)
6621 face_id
= last_escape_glyph_merged_face_id
;
6625 /* Merge the escape-glyph face into the current face. */
6626 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6628 last_escape_glyph_frame
= it
->f
;
6629 last_escape_glyph_face_id
= it
->face_id
;
6630 last_escape_glyph_merged_face_id
= face_id
;
6633 /* Draw non-ASCII hyphen with just highlighting: */
6635 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6637 XSETINT (it
->ctl_chars
[0], '-');
6639 goto display_control
;
6642 /* Draw non-ASCII space/hyphen with escape glyph: */
6644 if (nonascii_space_p
|| nonascii_hyphen_p
)
6646 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6647 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6649 goto display_control
;
6656 if (CHAR_BYTE8_P (c
))
6657 /* Display \200 instead of \17777600. */
6658 c
= CHAR_TO_BYTE8 (c
);
6659 len
= sprintf (str
, "%03o", c
);
6661 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6662 for (i
= 0; i
< len
; i
++)
6663 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6668 /* Set up IT->dpvec and return first character from it. */
6669 it
->dpvec_char_len
= it
->len
;
6670 it
->dpvec
= it
->ctl_chars
;
6671 it
->dpend
= it
->dpvec
+ ctl_len
;
6672 it
->current
.dpvec_index
= 0;
6673 it
->dpvec_face_id
= face_id
;
6674 it
->saved_face_id
= it
->face_id
;
6675 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6679 it
->char_to_display
= c
;
6683 it
->char_to_display
= it
->c
;
6687 /* Adjust face id for a multibyte character. There are no multibyte
6688 character in unibyte text. */
6689 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6692 && FRAME_WINDOW_P (it
->f
))
6694 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6696 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6698 /* Automatic composition with glyph-string. */
6699 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6701 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6705 EMACS_INT pos
= (it
->s
? -1
6706 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6707 : IT_CHARPOS (*it
));
6710 if (it
->what
== IT_CHARACTER
)
6711 c
= it
->char_to_display
;
6714 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6718 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6719 /* TAB in a composition means display glyphs with
6720 padding space on the left or right. */
6721 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6724 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6729 /* Is this character the last one of a run of characters with
6730 box? If yes, set IT->end_of_box_run_p to 1. */
6734 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6736 int face_id
= underlying_face_id (it
);
6737 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6741 if (face
->box
== FACE_NO_BOX
)
6743 /* If the box comes from face properties in a
6744 display string, check faces in that string. */
6745 int string_face_id
= face_after_it_pos (it
);
6746 it
->end_of_box_run_p
6747 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6750 /* Otherwise, the box comes from the underlying face.
6751 If this is the last string character displayed, check
6752 the next buffer location. */
6753 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6754 && (it
->current
.overlay_string_index
6755 == it
->n_overlay_strings
- 1))
6759 struct text_pos pos
= it
->current
.pos
;
6760 INC_TEXT_POS (pos
, it
->multibyte_p
);
6762 next_face_id
= face_at_buffer_position
6763 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6764 it
->region_end_charpos
, &ignore
,
6765 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6767 it
->end_of_box_run_p
6768 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6775 int face_id
= face_after_it_pos (it
);
6776 it
->end_of_box_run_p
6777 = (face_id
!= it
->face_id
6778 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6782 /* Value is 0 if end of buffer or string reached. */
6787 /* Move IT to the next display element.
6789 RESEAT_P non-zero means if called on a newline in buffer text,
6790 skip to the next visible line start.
6792 Functions get_next_display_element and set_iterator_to_next are
6793 separate because I find this arrangement easier to handle than a
6794 get_next_display_element function that also increments IT's
6795 position. The way it is we can first look at an iterator's current
6796 display element, decide whether it fits on a line, and if it does,
6797 increment the iterator position. The other way around we probably
6798 would either need a flag indicating whether the iterator has to be
6799 incremented the next time, or we would have to implement a
6800 decrement position function which would not be easy to write. */
6803 set_iterator_to_next (struct it
*it
, int reseat_p
)
6805 /* Reset flags indicating start and end of a sequence of characters
6806 with box. Reset them at the start of this function because
6807 moving the iterator to a new position might set them. */
6808 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6812 case GET_FROM_BUFFER
:
6813 /* The current display element of IT is a character from
6814 current_buffer. Advance in the buffer, and maybe skip over
6815 invisible lines that are so because of selective display. */
6816 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6817 reseat_at_next_visible_line_start (it
, 0);
6818 else if (it
->cmp_it
.id
>= 0)
6820 /* We are currently getting glyphs from a composition. */
6825 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6826 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6827 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6829 it
->cmp_it
.from
= it
->cmp_it
.to
;
6834 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6836 it
->end_charpos
, Qnil
);
6839 else if (! it
->cmp_it
.reversed_p
)
6841 /* Composition created while scanning forward. */
6842 /* Update IT's char/byte positions to point to the first
6843 character of the next grapheme cluster, or to the
6844 character visually after the current composition. */
6845 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6846 bidi_move_to_visually_next (&it
->bidi_it
);
6847 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6848 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6850 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6852 /* Proceed to the next grapheme cluster. */
6853 it
->cmp_it
.from
= it
->cmp_it
.to
;
6857 /* No more grapheme clusters in this composition.
6858 Find the next stop position. */
6859 EMACS_INT stop
= it
->end_charpos
;
6860 if (it
->bidi_it
.scan_dir
< 0)
6861 /* Now we are scanning backward and don't know
6864 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6865 IT_BYTEPOS (*it
), stop
, Qnil
);
6870 /* Composition created while scanning backward. */
6871 /* Update IT's char/byte positions to point to the last
6872 character of the previous grapheme cluster, or the
6873 character visually after the current composition. */
6874 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6875 bidi_move_to_visually_next (&it
->bidi_it
);
6876 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6877 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6878 if (it
->cmp_it
.from
> 0)
6880 /* Proceed to the previous grapheme cluster. */
6881 it
->cmp_it
.to
= it
->cmp_it
.from
;
6885 /* No more grapheme clusters in this composition.
6886 Find the next stop position. */
6887 EMACS_INT stop
= it
->end_charpos
;
6888 if (it
->bidi_it
.scan_dir
< 0)
6889 /* Now we are scanning backward and don't know
6892 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6893 IT_BYTEPOS (*it
), stop
, Qnil
);
6899 xassert (it
->len
!= 0);
6903 IT_BYTEPOS (*it
) += it
->len
;
6904 IT_CHARPOS (*it
) += 1;
6908 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6909 /* If this is a new paragraph, determine its base
6910 direction (a.k.a. its base embedding level). */
6911 if (it
->bidi_it
.new_paragraph
)
6912 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
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
;
6916 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6918 /* As the scan direction was changed, we must
6919 re-compute the stop position for composition. */
6920 EMACS_INT stop
= it
->end_charpos
;
6921 if (it
->bidi_it
.scan_dir
< 0)
6923 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6924 IT_BYTEPOS (*it
), stop
, Qnil
);
6927 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6931 case GET_FROM_C_STRING
:
6932 /* Current display element of IT is from a C string. */
6934 /* If the string position is beyond string's end, it means
6935 next_element_from_c_string is padding the string with
6936 blanks, in which case we bypass the bidi iterator,
6937 because it cannot deal with such virtual characters. */
6938 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6940 IT_BYTEPOS (*it
) += it
->len
;
6941 IT_CHARPOS (*it
) += 1;
6945 bidi_move_to_visually_next (&it
->bidi_it
);
6946 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6947 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6951 case GET_FROM_DISPLAY_VECTOR
:
6952 /* Current display element of IT is from a display table entry.
6953 Advance in the display table definition. Reset it to null if
6954 end reached, and continue with characters from buffers/
6956 ++it
->current
.dpvec_index
;
6958 /* Restore face of the iterator to what they were before the
6959 display vector entry (these entries may contain faces). */
6960 it
->face_id
= it
->saved_face_id
;
6962 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6964 int recheck_faces
= it
->ellipsis_p
;
6967 it
->method
= GET_FROM_C_STRING
;
6968 else if (STRINGP (it
->string
))
6969 it
->method
= GET_FROM_STRING
;
6972 it
->method
= GET_FROM_BUFFER
;
6973 it
->object
= it
->w
->buffer
;
6977 it
->current
.dpvec_index
= -1;
6979 /* Skip over characters which were displayed via IT->dpvec. */
6980 if (it
->dpvec_char_len
< 0)
6981 reseat_at_next_visible_line_start (it
, 1);
6982 else if (it
->dpvec_char_len
> 0)
6984 if (it
->method
== GET_FROM_STRING
6985 && it
->n_overlay_strings
> 0)
6986 it
->ignore_overlay_strings_at_pos_p
= 1;
6987 it
->len
= it
->dpvec_char_len
;
6988 set_iterator_to_next (it
, reseat_p
);
6991 /* Maybe recheck faces after display vector */
6993 it
->stop_charpos
= IT_CHARPOS (*it
);
6997 case GET_FROM_STRING
:
6998 /* Current display element is a character from a Lisp string. */
6999 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
7000 if (it
->cmp_it
.id
>= 0)
7006 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7007 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7008 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7009 it
->cmp_it
.from
= it
->cmp_it
.to
;
7013 composition_compute_stop_pos (&it
->cmp_it
,
7014 IT_STRING_CHARPOS (*it
),
7015 IT_STRING_BYTEPOS (*it
),
7016 it
->end_charpos
, it
->string
);
7019 else if (! it
->cmp_it
.reversed_p
)
7021 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7022 bidi_move_to_visually_next (&it
->bidi_it
);
7023 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7024 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7026 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7027 it
->cmp_it
.from
= it
->cmp_it
.to
;
7030 EMACS_INT stop
= it
->end_charpos
;
7031 if (it
->bidi_it
.scan_dir
< 0)
7033 composition_compute_stop_pos (&it
->cmp_it
,
7034 IT_STRING_CHARPOS (*it
),
7035 IT_STRING_BYTEPOS (*it
), stop
,
7041 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7042 bidi_move_to_visually_next (&it
->bidi_it
);
7043 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7044 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7045 if (it
->cmp_it
.from
> 0)
7046 it
->cmp_it
.to
= it
->cmp_it
.from
;
7049 EMACS_INT stop
= it
->end_charpos
;
7050 if (it
->bidi_it
.scan_dir
< 0)
7052 composition_compute_stop_pos (&it
->cmp_it
,
7053 IT_STRING_CHARPOS (*it
),
7054 IT_STRING_BYTEPOS (*it
), stop
,
7062 /* If the string position is beyond string's end, it
7063 means next_element_from_string is padding the string
7064 with blanks, in which case we bypass the bidi
7065 iterator, because it cannot deal with such virtual
7067 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7069 IT_STRING_BYTEPOS (*it
) += it
->len
;
7070 IT_STRING_CHARPOS (*it
) += 1;
7074 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7076 bidi_move_to_visually_next (&it
->bidi_it
);
7077 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7078 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7079 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7081 EMACS_INT stop
= it
->end_charpos
;
7083 if (it
->bidi_it
.scan_dir
< 0)
7085 composition_compute_stop_pos (&it
->cmp_it
,
7086 IT_STRING_CHARPOS (*it
),
7087 IT_STRING_BYTEPOS (*it
), stop
,
7093 consider_string_end
:
7095 if (it
->current
.overlay_string_index
>= 0)
7097 /* IT->string is an overlay string. Advance to the
7098 next, if there is one. */
7099 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7102 next_overlay_string (it
);
7104 setup_for_ellipsis (it
, 0);
7109 /* IT->string is not an overlay string. If we reached
7110 its end, and there is something on IT->stack, proceed
7111 with what is on the stack. This can be either another
7112 string, this time an overlay string, or a buffer. */
7113 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7117 if (it
->method
== GET_FROM_STRING
)
7118 goto consider_string_end
;
7123 case GET_FROM_IMAGE
:
7124 case GET_FROM_STRETCH
:
7125 /* The position etc with which we have to proceed are on
7126 the stack. The position may be at the end of a string,
7127 if the `display' property takes up the whole string. */
7128 xassert (it
->sp
> 0);
7130 if (it
->method
== GET_FROM_STRING
)
7131 goto consider_string_end
;
7135 /* There are no other methods defined, so this should be a bug. */
7139 xassert (it
->method
!= GET_FROM_STRING
7140 || (STRINGP (it
->string
)
7141 && IT_STRING_CHARPOS (*it
) >= 0));
7144 /* Load IT's display element fields with information about the next
7145 display element which comes from a display table entry or from the
7146 result of translating a control character to one of the forms `^C'
7149 IT->dpvec holds the glyphs to return as characters.
7150 IT->saved_face_id holds the face id before the display vector--it
7151 is restored into IT->face_id in set_iterator_to_next. */
7154 next_element_from_display_vector (struct it
*it
)
7159 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7161 it
->face_id
= it
->saved_face_id
;
7163 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7164 That seemed totally bogus - so I changed it... */
7165 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7167 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
7169 it
->c
= GLYPH_CODE_CHAR (gc
);
7170 it
->len
= CHAR_BYTES (it
->c
);
7172 /* The entry may contain a face id to use. Such a face id is
7173 the id of a Lisp face, not a realized face. A face id of
7174 zero means no face is specified. */
7175 if (it
->dpvec_face_id
>= 0)
7176 it
->face_id
= it
->dpvec_face_id
;
7179 EMACS_INT lface_id
= GLYPH_CODE_FACE (gc
);
7181 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7186 /* Display table entry is invalid. Return a space. */
7187 it
->c
= ' ', it
->len
= 1;
7189 /* Don't change position and object of the iterator here. They are
7190 still the values of the character that had this display table
7191 entry or was translated, and that's what we want. */
7192 it
->what
= IT_CHARACTER
;
7196 /* Get the first element of string/buffer in the visual order, after
7197 being reseated to a new position in a string or a buffer. */
7199 get_visually_first_element (struct it
*it
)
7201 int string_p
= STRINGP (it
->string
) || it
->s
;
7202 EMACS_INT eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7203 EMACS_INT bob
= (string_p
? 0 : BEGV
);
7205 if (STRINGP (it
->string
))
7207 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7208 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7212 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7213 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7216 if (it
->bidi_it
.charpos
== eob
)
7218 /* Nothing to do, but reset the FIRST_ELT flag, like
7219 bidi_paragraph_init does, because we are not going to
7221 it
->bidi_it
.first_elt
= 0;
7223 else if (it
->bidi_it
.charpos
== bob
7225 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7226 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7228 /* If we are at the beginning of a line/string, we can produce
7229 the next element right away. */
7230 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7231 bidi_move_to_visually_next (&it
->bidi_it
);
7235 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
7237 /* We need to prime the bidi iterator starting at the line's or
7238 string's beginning, before we will be able to produce the
7241 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7244 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7246 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7248 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7251 /* Now return to buffer/string position where we were asked
7252 to get the next display element, and produce that. */
7253 bidi_move_to_visually_next (&it
->bidi_it
);
7255 while (it
->bidi_it
.bytepos
!= orig_bytepos
7256 && it
->bidi_it
.charpos
< eob
);
7259 /* Adjust IT's position information to where we ended up. */
7260 if (STRINGP (it
->string
))
7262 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7263 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7267 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7268 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7271 if (STRINGP (it
->string
) || !it
->s
)
7273 EMACS_INT stop
, charpos
, bytepos
;
7275 if (STRINGP (it
->string
))
7278 stop
= SCHARS (it
->string
);
7279 if (stop
> it
->end_charpos
)
7280 stop
= it
->end_charpos
;
7281 charpos
= IT_STRING_CHARPOS (*it
);
7282 bytepos
= IT_STRING_BYTEPOS (*it
);
7286 stop
= it
->end_charpos
;
7287 charpos
= IT_CHARPOS (*it
);
7288 bytepos
= IT_BYTEPOS (*it
);
7290 if (it
->bidi_it
.scan_dir
< 0)
7292 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7297 /* Load IT with the next display element from Lisp string IT->string.
7298 IT->current.string_pos is the current position within the string.
7299 If IT->current.overlay_string_index >= 0, the Lisp string is an
7303 next_element_from_string (struct it
*it
)
7305 struct text_pos position
;
7307 xassert (STRINGP (it
->string
));
7308 xassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7309 xassert (IT_STRING_CHARPOS (*it
) >= 0);
7310 position
= it
->current
.string_pos
;
7312 /* With bidi reordering, the character to display might not be the
7313 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7314 that we were reseat()ed to a new string, whose paragraph
7315 direction is not known. */
7316 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7318 get_visually_first_element (it
);
7319 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7322 /* Time to check for invisible text? */
7323 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7325 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7328 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7329 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7331 /* With bidi non-linear iteration, we could find
7332 ourselves far beyond the last computed stop_charpos,
7333 with several other stop positions in between that we
7334 missed. Scan them all now, in buffer's logical
7335 order, until we find and handle the last stop_charpos
7336 that precedes our current position. */
7337 handle_stop_backwards (it
, it
->stop_charpos
);
7338 return GET_NEXT_DISPLAY_ELEMENT (it
);
7344 /* Take note of the stop position we just moved
7345 across, for when we will move back across it. */
7346 it
->prev_stop
= it
->stop_charpos
;
7347 /* If we are at base paragraph embedding level, take
7348 note of the last stop position seen at this
7350 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7351 it
->base_level_stop
= it
->stop_charpos
;
7355 /* Since a handler may have changed IT->method, we must
7357 return GET_NEXT_DISPLAY_ELEMENT (it
);
7361 /* If we are before prev_stop, we may have overstepped
7362 on our way backwards a stop_pos, and if so, we need
7363 to handle that stop_pos. */
7364 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7365 /* We can sometimes back up for reasons that have nothing
7366 to do with bidi reordering. E.g., compositions. The
7367 code below is only needed when we are above the base
7368 embedding level, so test for that explicitly. */
7369 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7371 /* If we lost track of base_level_stop, we have no better
7372 place for handle_stop_backwards to start from than string
7373 beginning. This happens, e.g., when we were reseated to
7374 the previous screenful of text by vertical-motion. */
7375 if (it
->base_level_stop
<= 0
7376 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7377 it
->base_level_stop
= 0;
7378 handle_stop_backwards (it
, it
->base_level_stop
);
7379 return GET_NEXT_DISPLAY_ELEMENT (it
);
7383 if (it
->current
.overlay_string_index
>= 0)
7385 /* Get the next character from an overlay string. In overlay
7386 strings, there is no field width or padding with spaces to
7388 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7393 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7394 IT_STRING_BYTEPOS (*it
),
7395 it
->bidi_it
.scan_dir
< 0
7397 : SCHARS (it
->string
))
7398 && next_element_from_composition (it
))
7402 else if (STRING_MULTIBYTE (it
->string
))
7404 const unsigned char *s
= (SDATA (it
->string
)
7405 + IT_STRING_BYTEPOS (*it
));
7406 it
->c
= string_char_and_length (s
, &it
->len
);
7410 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7416 /* Get the next character from a Lisp string that is not an
7417 overlay string. Such strings come from the mode line, for
7418 example. We may have to pad with spaces, or truncate the
7419 string. See also next_element_from_c_string. */
7420 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7425 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7427 /* Pad with spaces. */
7428 it
->c
= ' ', it
->len
= 1;
7429 CHARPOS (position
) = BYTEPOS (position
) = -1;
7431 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7432 IT_STRING_BYTEPOS (*it
),
7433 it
->bidi_it
.scan_dir
< 0
7435 : it
->string_nchars
)
7436 && next_element_from_composition (it
))
7440 else if (STRING_MULTIBYTE (it
->string
))
7442 const unsigned char *s
= (SDATA (it
->string
)
7443 + IT_STRING_BYTEPOS (*it
));
7444 it
->c
= string_char_and_length (s
, &it
->len
);
7448 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7453 /* Record what we have and where it came from. */
7454 it
->what
= IT_CHARACTER
;
7455 it
->object
= it
->string
;
7456 it
->position
= position
;
7461 /* Load IT with next display element from C string IT->s.
7462 IT->string_nchars is the maximum number of characters to return
7463 from the string. IT->end_charpos may be greater than
7464 IT->string_nchars when this function is called, in which case we
7465 may have to return padding spaces. Value is zero if end of string
7466 reached, including padding spaces. */
7469 next_element_from_c_string (struct it
*it
)
7474 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7475 it
->what
= IT_CHARACTER
;
7476 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7479 /* With bidi reordering, the character to display might not be the
7480 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7481 we were reseated to a new string, whose paragraph direction is
7483 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7484 get_visually_first_element (it
);
7486 /* IT's position can be greater than IT->string_nchars in case a
7487 field width or precision has been specified when the iterator was
7489 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7491 /* End of the game. */
7495 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7497 /* Pad with spaces. */
7498 it
->c
= ' ', it
->len
= 1;
7499 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7501 else if (it
->multibyte_p
)
7502 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7504 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7510 /* Set up IT to return characters from an ellipsis, if appropriate.
7511 The definition of the ellipsis glyphs may come from a display table
7512 entry. This function fills IT with the first glyph from the
7513 ellipsis if an ellipsis is to be displayed. */
7516 next_element_from_ellipsis (struct it
*it
)
7518 if (it
->selective_display_ellipsis_p
)
7519 setup_for_ellipsis (it
, it
->len
);
7522 /* The face at the current position may be different from the
7523 face we find after the invisible text. Remember what it
7524 was in IT->saved_face_id, and signal that it's there by
7525 setting face_before_selective_p. */
7526 it
->saved_face_id
= it
->face_id
;
7527 it
->method
= GET_FROM_BUFFER
;
7528 it
->object
= it
->w
->buffer
;
7529 reseat_at_next_visible_line_start (it
, 1);
7530 it
->face_before_selective_p
= 1;
7533 return GET_NEXT_DISPLAY_ELEMENT (it
);
7537 /* Deliver an image display element. The iterator IT is already
7538 filled with image information (done in handle_display_prop). Value
7543 next_element_from_image (struct it
*it
)
7545 it
->what
= IT_IMAGE
;
7546 it
->ignore_overlay_strings_at_pos_p
= 0;
7551 /* Fill iterator IT with next display element from a stretch glyph
7552 property. IT->object is the value of the text property. Value is
7556 next_element_from_stretch (struct it
*it
)
7558 it
->what
= IT_STRETCH
;
7562 /* Scan backwards from IT's current position until we find a stop
7563 position, or until BEGV. This is called when we find ourself
7564 before both the last known prev_stop and base_level_stop while
7565 reordering bidirectional text. */
7568 compute_stop_pos_backwards (struct it
*it
)
7570 const int SCAN_BACK_LIMIT
= 1000;
7571 struct text_pos pos
;
7572 struct display_pos save_current
= it
->current
;
7573 struct text_pos save_position
= it
->position
;
7574 EMACS_INT charpos
= IT_CHARPOS (*it
);
7575 EMACS_INT where_we_are
= charpos
;
7576 EMACS_INT save_stop_pos
= it
->stop_charpos
;
7577 EMACS_INT save_end_pos
= it
->end_charpos
;
7579 xassert (NILP (it
->string
) && !it
->s
);
7580 xassert (it
->bidi_p
);
7584 it
->end_charpos
= min (charpos
+ 1, ZV
);
7585 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7586 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7587 reseat_1 (it
, pos
, 0);
7588 compute_stop_pos (it
);
7589 /* We must advance forward, right? */
7590 if (it
->stop_charpos
<= charpos
)
7593 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7595 if (it
->stop_charpos
<= where_we_are
)
7596 it
->prev_stop
= it
->stop_charpos
;
7598 it
->prev_stop
= BEGV
;
7600 it
->current
= save_current
;
7601 it
->position
= save_position
;
7602 it
->stop_charpos
= save_stop_pos
;
7603 it
->end_charpos
= save_end_pos
;
7606 /* Scan forward from CHARPOS in the current buffer/string, until we
7607 find a stop position > current IT's position. Then handle the stop
7608 position before that. This is called when we bump into a stop
7609 position while reordering bidirectional text. CHARPOS should be
7610 the last previously processed stop_pos (or BEGV/0, if none were
7611 processed yet) whose position is less that IT's current
7615 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7617 int bufp
= !STRINGP (it
->string
);
7618 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7619 struct display_pos save_current
= it
->current
;
7620 struct text_pos save_position
= it
->position
;
7621 struct text_pos pos1
;
7622 EMACS_INT next_stop
;
7624 /* Scan in strict logical order. */
7625 xassert (it
->bidi_p
);
7629 it
->prev_stop
= charpos
;
7632 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7633 reseat_1 (it
, pos1
, 0);
7636 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7637 compute_stop_pos (it
);
7638 /* We must advance forward, right? */
7639 if (it
->stop_charpos
<= it
->prev_stop
)
7641 charpos
= it
->stop_charpos
;
7643 while (charpos
<= where_we_are
);
7646 it
->current
= save_current
;
7647 it
->position
= save_position
;
7648 next_stop
= it
->stop_charpos
;
7649 it
->stop_charpos
= it
->prev_stop
;
7651 it
->stop_charpos
= next_stop
;
7654 /* Load IT with the next display element from current_buffer. Value
7655 is zero if end of buffer reached. IT->stop_charpos is the next
7656 position at which to stop and check for text properties or buffer
7660 next_element_from_buffer (struct it
*it
)
7664 xassert (IT_CHARPOS (*it
) >= BEGV
);
7665 xassert (NILP (it
->string
) && !it
->s
);
7666 xassert (!it
->bidi_p
7667 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7668 && it
->bidi_it
.string
.s
== NULL
));
7670 /* With bidi reordering, the character to display might not be the
7671 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7672 we were reseat()ed to a new buffer position, which is potentially
7673 a different paragraph. */
7674 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7676 get_visually_first_element (it
);
7677 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7680 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7682 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7684 int overlay_strings_follow_p
;
7686 /* End of the game, except when overlay strings follow that
7687 haven't been returned yet. */
7688 if (it
->overlay_strings_at_end_processed_p
)
7689 overlay_strings_follow_p
= 0;
7692 it
->overlay_strings_at_end_processed_p
= 1;
7693 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7696 if (overlay_strings_follow_p
)
7697 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7701 it
->position
= it
->current
.pos
;
7705 else if (!(!it
->bidi_p
7706 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7707 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7709 /* With bidi non-linear iteration, we could find ourselves
7710 far beyond the last computed stop_charpos, with several
7711 other stop positions in between that we missed. Scan
7712 them all now, in buffer's logical order, until we find
7713 and handle the last stop_charpos that precedes our
7714 current position. */
7715 handle_stop_backwards (it
, it
->stop_charpos
);
7716 return GET_NEXT_DISPLAY_ELEMENT (it
);
7722 /* Take note of the stop position we just moved across,
7723 for when we will move back across it. */
7724 it
->prev_stop
= it
->stop_charpos
;
7725 /* If we are at base paragraph embedding level, take
7726 note of the last stop position seen at this
7728 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7729 it
->base_level_stop
= it
->stop_charpos
;
7732 return GET_NEXT_DISPLAY_ELEMENT (it
);
7736 /* If we are before prev_stop, we may have overstepped on
7737 our way backwards a stop_pos, and if so, we need to
7738 handle that stop_pos. */
7739 && IT_CHARPOS (*it
) < it
->prev_stop
7740 /* We can sometimes back up for reasons that have nothing
7741 to do with bidi reordering. E.g., compositions. The
7742 code below is only needed when we are above the base
7743 embedding level, so test for that explicitly. */
7744 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7746 if (it
->base_level_stop
<= 0
7747 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7749 /* If we lost track of base_level_stop, we need to find
7750 prev_stop by looking backwards. This happens, e.g., when
7751 we were reseated to the previous screenful of text by
7753 it
->base_level_stop
= BEGV
;
7754 compute_stop_pos_backwards (it
);
7755 handle_stop_backwards (it
, it
->prev_stop
);
7758 handle_stop_backwards (it
, it
->base_level_stop
);
7759 return GET_NEXT_DISPLAY_ELEMENT (it
);
7763 /* No face changes, overlays etc. in sight, so just return a
7764 character from current_buffer. */
7768 /* Maybe run the redisplay end trigger hook. Performance note:
7769 This doesn't seem to cost measurable time. */
7770 if (it
->redisplay_end_trigger_charpos
7772 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7773 run_redisplay_end_trigger_hook (it
);
7775 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7776 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7778 && next_element_from_composition (it
))
7783 /* Get the next character, maybe multibyte. */
7784 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7785 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7786 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7788 it
->c
= *p
, it
->len
= 1;
7790 /* Record what we have and where it came from. */
7791 it
->what
= IT_CHARACTER
;
7792 it
->object
= it
->w
->buffer
;
7793 it
->position
= it
->current
.pos
;
7795 /* Normally we return the character found above, except when we
7796 really want to return an ellipsis for selective display. */
7801 /* A value of selective > 0 means hide lines indented more
7802 than that number of columns. */
7803 if (it
->selective
> 0
7804 && IT_CHARPOS (*it
) + 1 < ZV
7805 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7806 IT_BYTEPOS (*it
) + 1,
7809 success_p
= next_element_from_ellipsis (it
);
7810 it
->dpvec_char_len
= -1;
7813 else if (it
->c
== '\r' && it
->selective
== -1)
7815 /* A value of selective == -1 means that everything from the
7816 CR to the end of the line is invisible, with maybe an
7817 ellipsis displayed for it. */
7818 success_p
= next_element_from_ellipsis (it
);
7819 it
->dpvec_char_len
= -1;
7824 /* Value is zero if end of buffer reached. */
7825 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7830 /* Run the redisplay end trigger hook for IT. */
7833 run_redisplay_end_trigger_hook (struct it
*it
)
7835 Lisp_Object args
[3];
7837 /* IT->glyph_row should be non-null, i.e. we should be actually
7838 displaying something, or otherwise we should not run the hook. */
7839 xassert (it
->glyph_row
);
7841 /* Set up hook arguments. */
7842 args
[0] = Qredisplay_end_trigger_functions
;
7843 args
[1] = it
->window
;
7844 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7845 it
->redisplay_end_trigger_charpos
= 0;
7847 /* Since we are *trying* to run these functions, don't try to run
7848 them again, even if they get an error. */
7849 it
->w
->redisplay_end_trigger
= Qnil
;
7850 Frun_hook_with_args (3, args
);
7852 /* Notice if it changed the face of the character we are on. */
7853 handle_face_prop (it
);
7857 /* Deliver a composition display element. Unlike the other
7858 next_element_from_XXX, this function is not registered in the array
7859 get_next_element[]. It is called from next_element_from_buffer and
7860 next_element_from_string when necessary. */
7863 next_element_from_composition (struct it
*it
)
7865 it
->what
= IT_COMPOSITION
;
7866 it
->len
= it
->cmp_it
.nbytes
;
7867 if (STRINGP (it
->string
))
7871 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7872 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7875 it
->position
= it
->current
.string_pos
;
7876 it
->object
= it
->string
;
7877 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7878 IT_STRING_BYTEPOS (*it
), it
->string
);
7884 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7885 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7888 if (it
->bidi_it
.new_paragraph
)
7889 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7890 /* Resync the bidi iterator with IT's new position.
7891 FIXME: this doesn't support bidirectional text. */
7892 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7893 bidi_move_to_visually_next (&it
->bidi_it
);
7897 it
->position
= it
->current
.pos
;
7898 it
->object
= it
->w
->buffer
;
7899 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7900 IT_BYTEPOS (*it
), Qnil
);
7907 /***********************************************************************
7908 Moving an iterator without producing glyphs
7909 ***********************************************************************/
7911 /* Check if iterator is at a position corresponding to a valid buffer
7912 position after some move_it_ call. */
7914 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7915 ((it)->method == GET_FROM_STRING \
7916 ? IT_STRING_CHARPOS (*it) == 0 \
7920 /* Move iterator IT to a specified buffer or X position within one
7921 line on the display without producing glyphs.
7923 OP should be a bit mask including some or all of these bits:
7924 MOVE_TO_X: Stop upon reaching x-position TO_X.
7925 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7926 Regardless of OP's value, stop upon reaching the end of the display line.
7928 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7929 This means, in particular, that TO_X includes window's horizontal
7932 The return value has several possible values that
7933 say what condition caused the scan to stop:
7935 MOVE_POS_MATCH_OR_ZV
7936 - when TO_POS or ZV was reached.
7939 -when TO_X was reached before TO_POS or ZV were reached.
7942 - when we reached the end of the display area and the line must
7946 - when we reached the end of the display area and the line is
7950 - when we stopped at a line end, i.e. a newline or a CR and selective
7953 static enum move_it_result
7954 move_it_in_display_line_to (struct it
*it
,
7955 EMACS_INT to_charpos
, int to_x
,
7956 enum move_operation_enum op
)
7958 enum move_it_result result
= MOVE_UNDEFINED
;
7959 struct glyph_row
*saved_glyph_row
;
7960 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
7961 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
7962 void *ppos_data
= NULL
;
7964 enum it_method prev_method
= it
->method
;
7965 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7966 int saw_smaller_pos
= prev_pos
< to_charpos
;
7968 /* Don't produce glyphs in produce_glyphs. */
7969 saved_glyph_row
= it
->glyph_row
;
7970 it
->glyph_row
= NULL
;
7972 /* Use wrap_it to save a copy of IT wherever a word wrap could
7973 occur. Use atpos_it to save a copy of IT at the desired buffer
7974 position, if found, so that we can scan ahead and check if the
7975 word later overshoots the window edge. Use atx_it similarly, for
7981 /* Use ppos_it under bidi reordering to save a copy of IT for the
7982 position > CHARPOS that is the closest to CHARPOS. We restore
7983 that position in IT when we have scanned the entire display line
7984 without finding a match for CHARPOS and all the character
7985 positions are greater than CHARPOS. */
7988 SAVE_IT (ppos_it
, *it
, ppos_data
);
7989 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
7990 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
7991 SAVE_IT (ppos_it
, *it
, ppos_data
);
7994 #define BUFFER_POS_REACHED_P() \
7995 ((op & MOVE_TO_POS) != 0 \
7996 && BUFFERP (it->object) \
7997 && (IT_CHARPOS (*it) == to_charpos \
7999 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8000 && IT_CHARPOS (*it) > to_charpos) \
8001 || (it->what == IT_COMPOSITION \
8002 && ((IT_CHARPOS (*it) > to_charpos \
8003 && to_charpos >= it->cmp_it.charpos) \
8004 || (IT_CHARPOS (*it) < to_charpos \
8005 && to_charpos <= it->cmp_it.charpos)))) \
8006 && (it->method == GET_FROM_BUFFER \
8007 || (it->method == GET_FROM_DISPLAY_VECTOR \
8008 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8010 /* If there's a line-/wrap-prefix, handle it. */
8011 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8012 && it
->current_y
< it
->last_visible_y
)
8013 handle_line_prefix (it
);
8015 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8016 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8020 int x
, i
, ascent
= 0, descent
= 0;
8022 /* Utility macro to reset an iterator with x, ascent, and descent. */
8023 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8024 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8025 (IT)->max_descent = descent)
8027 /* Stop if we move beyond TO_CHARPOS (after an image or a
8028 display string or stretch glyph). */
8029 if ((op
& MOVE_TO_POS
) != 0
8030 && BUFFERP (it
->object
)
8031 && it
->method
== GET_FROM_BUFFER
8033 /* When the iterator is at base embedding level, we
8034 are guaranteed that characters are delivered for
8035 display in strictly increasing order of their
8036 buffer positions. */
8037 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8038 && IT_CHARPOS (*it
) > to_charpos
)
8040 && (prev_method
== GET_FROM_IMAGE
8041 || prev_method
== GET_FROM_STRETCH
8042 || prev_method
== GET_FROM_STRING
)
8043 /* Passed TO_CHARPOS from left to right. */
8044 && ((prev_pos
< to_charpos
8045 && IT_CHARPOS (*it
) > to_charpos
)
8046 /* Passed TO_CHARPOS from right to left. */
8047 || (prev_pos
> to_charpos
8048 && IT_CHARPOS (*it
) < to_charpos
)))))
8050 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8052 result
= MOVE_POS_MATCH_OR_ZV
;
8055 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8056 /* If wrap_it is valid, the current position might be in a
8057 word that is wrapped. So, save the iterator in
8058 atpos_it and continue to see if wrapping happens. */
8059 SAVE_IT (atpos_it
, *it
, atpos_data
);
8062 /* Stop when ZV reached.
8063 We used to stop here when TO_CHARPOS reached as well, but that is
8064 too soon if this glyph does not fit on this line. So we handle it
8065 explicitly below. */
8066 if (!get_next_display_element (it
))
8068 result
= MOVE_POS_MATCH_OR_ZV
;
8072 if (it
->line_wrap
== TRUNCATE
)
8074 if (BUFFER_POS_REACHED_P ())
8076 result
= MOVE_POS_MATCH_OR_ZV
;
8082 if (it
->line_wrap
== WORD_WRAP
)
8084 if (IT_DISPLAYING_WHITESPACE (it
))
8088 /* We have reached a glyph that follows one or more
8089 whitespace characters. If the position is
8090 already found, we are done. */
8091 if (atpos_it
.sp
>= 0)
8093 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8094 result
= MOVE_POS_MATCH_OR_ZV
;
8099 RESTORE_IT (it
, &atx_it
, atx_data
);
8100 result
= MOVE_X_REACHED
;
8103 /* Otherwise, we can wrap here. */
8104 SAVE_IT (wrap_it
, *it
, wrap_data
);
8110 /* Remember the line height for the current line, in case
8111 the next element doesn't fit on the line. */
8112 ascent
= it
->max_ascent
;
8113 descent
= it
->max_descent
;
8115 /* The call to produce_glyphs will get the metrics of the
8116 display element IT is loaded with. Record the x-position
8117 before this display element, in case it doesn't fit on the
8121 PRODUCE_GLYPHS (it
);
8123 if (it
->area
!= TEXT_AREA
)
8125 prev_method
= it
->method
;
8126 if (it
->method
== GET_FROM_BUFFER
)
8127 prev_pos
= IT_CHARPOS (*it
);
8128 set_iterator_to_next (it
, 1);
8129 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8130 SET_TEXT_POS (this_line_min_pos
,
8131 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8133 && (op
& MOVE_TO_POS
)
8134 && IT_CHARPOS (*it
) > to_charpos
8135 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8136 SAVE_IT (ppos_it
, *it
, ppos_data
);
8140 /* The number of glyphs we get back in IT->nglyphs will normally
8141 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8142 character on a terminal frame, or (iii) a line end. For the
8143 second case, IT->nglyphs - 1 padding glyphs will be present.
8144 (On X frames, there is only one glyph produced for a
8145 composite character.)
8147 The behavior implemented below means, for continuation lines,
8148 that as many spaces of a TAB as fit on the current line are
8149 displayed there. For terminal frames, as many glyphs of a
8150 multi-glyph character are displayed in the current line, too.
8151 This is what the old redisplay code did, and we keep it that
8152 way. Under X, the whole shape of a complex character must
8153 fit on the line or it will be completely displayed in the
8156 Note that both for tabs and padding glyphs, all glyphs have
8160 /* More than one glyph or glyph doesn't fit on line. All
8161 glyphs have the same width. */
8162 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8164 int x_before_this_char
= x
;
8165 int hpos_before_this_char
= it
->hpos
;
8167 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8169 new_x
= x
+ single_glyph_width
;
8171 /* We want to leave anything reaching TO_X to the caller. */
8172 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8174 if (BUFFER_POS_REACHED_P ())
8176 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8177 goto buffer_pos_reached
;
8178 if (atpos_it
.sp
< 0)
8180 SAVE_IT (atpos_it
, *it
, atpos_data
);
8181 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8186 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8189 result
= MOVE_X_REACHED
;
8194 SAVE_IT (atx_it
, *it
, atx_data
);
8195 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8200 if (/* Lines are continued. */
8201 it
->line_wrap
!= TRUNCATE
8202 && (/* And glyph doesn't fit on the line. */
8203 new_x
> it
->last_visible_x
8204 /* Or it fits exactly and we're on a window
8206 || (new_x
== it
->last_visible_x
8207 && FRAME_WINDOW_P (it
->f
))))
8209 if (/* IT->hpos == 0 means the very first glyph
8210 doesn't fit on the line, e.g. a wide image. */
8212 || (new_x
== it
->last_visible_x
8213 && FRAME_WINDOW_P (it
->f
)))
8216 it
->current_x
= new_x
;
8218 /* The character's last glyph just barely fits
8220 if (i
== it
->nglyphs
- 1)
8222 /* If this is the destination position,
8223 return a position *before* it in this row,
8224 now that we know it fits in this row. */
8225 if (BUFFER_POS_REACHED_P ())
8227 if (it
->line_wrap
!= WORD_WRAP
8230 it
->hpos
= hpos_before_this_char
;
8231 it
->current_x
= x_before_this_char
;
8232 result
= MOVE_POS_MATCH_OR_ZV
;
8235 if (it
->line_wrap
== WORD_WRAP
8238 SAVE_IT (atpos_it
, *it
, atpos_data
);
8239 atpos_it
.current_x
= x_before_this_char
;
8240 atpos_it
.hpos
= hpos_before_this_char
;
8244 prev_method
= it
->method
;
8245 if (it
->method
== GET_FROM_BUFFER
)
8246 prev_pos
= IT_CHARPOS (*it
);
8247 set_iterator_to_next (it
, 1);
8248 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8249 SET_TEXT_POS (this_line_min_pos
,
8250 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8251 /* On graphical terminals, newlines may
8252 "overflow" into the fringe if
8253 overflow-newline-into-fringe is non-nil.
8254 On text-only terminals, newlines may
8255 overflow into the last glyph on the
8257 if (!FRAME_WINDOW_P (it
->f
)
8258 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8260 if (!get_next_display_element (it
))
8262 result
= MOVE_POS_MATCH_OR_ZV
;
8265 if (BUFFER_POS_REACHED_P ())
8267 if (ITERATOR_AT_END_OF_LINE_P (it
))
8268 result
= MOVE_POS_MATCH_OR_ZV
;
8270 result
= MOVE_LINE_CONTINUED
;
8273 if (ITERATOR_AT_END_OF_LINE_P (it
))
8275 result
= MOVE_NEWLINE_OR_CR
;
8282 IT_RESET_X_ASCENT_DESCENT (it
);
8284 if (wrap_it
.sp
>= 0)
8286 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8291 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8293 result
= MOVE_LINE_CONTINUED
;
8297 if (BUFFER_POS_REACHED_P ())
8299 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8300 goto buffer_pos_reached
;
8301 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8303 SAVE_IT (atpos_it
, *it
, atpos_data
);
8304 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8308 if (new_x
> it
->first_visible_x
)
8310 /* Glyph is visible. Increment number of glyphs that
8311 would be displayed. */
8316 if (result
!= MOVE_UNDEFINED
)
8319 else if (BUFFER_POS_REACHED_P ())
8322 IT_RESET_X_ASCENT_DESCENT (it
);
8323 result
= MOVE_POS_MATCH_OR_ZV
;
8326 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8328 /* Stop when TO_X specified and reached. This check is
8329 necessary here because of lines consisting of a line end,
8330 only. The line end will not produce any glyphs and we
8331 would never get MOVE_X_REACHED. */
8332 xassert (it
->nglyphs
== 0);
8333 result
= MOVE_X_REACHED
;
8337 /* Is this a line end? If yes, we're done. */
8338 if (ITERATOR_AT_END_OF_LINE_P (it
))
8340 /* If we are past TO_CHARPOS, but never saw any character
8341 positions smaller than TO_CHARPOS, return
8342 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8344 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8346 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8348 if (IT_CHARPOS (ppos_it
) < ZV
)
8350 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8351 result
= MOVE_POS_MATCH_OR_ZV
;
8354 goto buffer_pos_reached
;
8356 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8357 && IT_CHARPOS (*it
) > to_charpos
)
8358 goto buffer_pos_reached
;
8360 result
= MOVE_NEWLINE_OR_CR
;
8363 result
= MOVE_NEWLINE_OR_CR
;
8367 prev_method
= it
->method
;
8368 if (it
->method
== GET_FROM_BUFFER
)
8369 prev_pos
= IT_CHARPOS (*it
);
8370 /* The current display element has been consumed. Advance
8372 set_iterator_to_next (it
, 1);
8373 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8374 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8375 if (IT_CHARPOS (*it
) < to_charpos
)
8376 saw_smaller_pos
= 1;
8378 && (op
& MOVE_TO_POS
)
8379 && IT_CHARPOS (*it
) >= to_charpos
8380 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8381 SAVE_IT (ppos_it
, *it
, ppos_data
);
8383 /* Stop if lines are truncated and IT's current x-position is
8384 past the right edge of the window now. */
8385 if (it
->line_wrap
== TRUNCATE
8386 && it
->current_x
>= it
->last_visible_x
)
8388 if (!FRAME_WINDOW_P (it
->f
)
8389 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8393 if ((at_eob_p
= !get_next_display_element (it
))
8394 || BUFFER_POS_REACHED_P ()
8395 /* If we are past TO_CHARPOS, but never saw any
8396 character positions smaller than TO_CHARPOS,
8397 return MOVE_POS_MATCH_OR_ZV, like the
8398 unidirectional display did. */
8399 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8401 && IT_CHARPOS (*it
) > to_charpos
))
8404 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8405 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8406 result
= MOVE_POS_MATCH_OR_ZV
;
8409 if (ITERATOR_AT_END_OF_LINE_P (it
))
8411 result
= MOVE_NEWLINE_OR_CR
;
8415 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8417 && IT_CHARPOS (*it
) > to_charpos
)
8419 if (IT_CHARPOS (ppos_it
) < ZV
)
8420 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8421 result
= MOVE_POS_MATCH_OR_ZV
;
8424 result
= MOVE_LINE_TRUNCATED
;
8427 #undef IT_RESET_X_ASCENT_DESCENT
8430 #undef BUFFER_POS_REACHED_P
8432 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8433 restore the saved iterator. */
8434 if (atpos_it
.sp
>= 0)
8435 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8436 else if (atx_it
.sp
>= 0)
8437 RESTORE_IT (it
, &atx_it
, atx_data
);
8442 bidi_unshelve_cache (atpos_data
, 1);
8444 bidi_unshelve_cache (atx_data
, 1);
8446 bidi_unshelve_cache (wrap_data
, 1);
8448 bidi_unshelve_cache (ppos_data
, 1);
8450 /* Restore the iterator settings altered at the beginning of this
8452 it
->glyph_row
= saved_glyph_row
;
8456 /* For external use. */
8458 move_it_in_display_line (struct it
*it
,
8459 EMACS_INT to_charpos
, int to_x
,
8460 enum move_operation_enum op
)
8462 if (it
->line_wrap
== WORD_WRAP
8463 && (op
& MOVE_TO_X
))
8466 void *save_data
= NULL
;
8469 SAVE_IT (save_it
, *it
, save_data
);
8470 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8471 /* When word-wrap is on, TO_X may lie past the end
8472 of a wrapped line. Then it->current is the
8473 character on the next line, so backtrack to the
8474 space before the wrap point. */
8475 if (skip
== MOVE_LINE_CONTINUED
)
8477 int prev_x
= max (it
->current_x
- 1, 0);
8478 RESTORE_IT (it
, &save_it
, save_data
);
8479 move_it_in_display_line_to
8480 (it
, -1, prev_x
, MOVE_TO_X
);
8483 bidi_unshelve_cache (save_data
, 1);
8486 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8490 /* Move IT forward until it satisfies one or more of the criteria in
8491 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8493 OP is a bit-mask that specifies where to stop, and in particular,
8494 which of those four position arguments makes a difference. See the
8495 description of enum move_operation_enum.
8497 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8498 screen line, this function will set IT to the next position that is
8499 displayed to the right of TO_CHARPOS on the screen. */
8502 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8504 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8505 int line_height
, line_start_x
= 0, reached
= 0;
8506 void *backup_data
= NULL
;
8510 if (op
& MOVE_TO_VPOS
)
8512 /* If no TO_CHARPOS and no TO_X specified, stop at the
8513 start of the line TO_VPOS. */
8514 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8516 if (it
->vpos
== to_vpos
)
8522 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8526 /* TO_VPOS >= 0 means stop at TO_X in the line at
8527 TO_VPOS, or at TO_POS, whichever comes first. */
8528 if (it
->vpos
== to_vpos
)
8534 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8536 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8541 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8543 /* We have reached TO_X but not in the line we want. */
8544 skip
= move_it_in_display_line_to (it
, to_charpos
,
8546 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8554 else if (op
& MOVE_TO_Y
)
8556 struct it it_backup
;
8558 if (it
->line_wrap
== WORD_WRAP
)
8559 SAVE_IT (it_backup
, *it
, backup_data
);
8561 /* TO_Y specified means stop at TO_X in the line containing
8562 TO_Y---or at TO_CHARPOS if this is reached first. The
8563 problem is that we can't really tell whether the line
8564 contains TO_Y before we have completely scanned it, and
8565 this may skip past TO_X. What we do is to first scan to
8568 If TO_X is not specified, use a TO_X of zero. The reason
8569 is to make the outcome of this function more predictable.
8570 If we didn't use TO_X == 0, we would stop at the end of
8571 the line which is probably not what a caller would expect
8573 skip
= move_it_in_display_line_to
8574 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8575 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8577 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8578 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8580 else if (skip
== MOVE_X_REACHED
)
8582 /* If TO_X was reached, we want to know whether TO_Y is
8583 in the line. We know this is the case if the already
8584 scanned glyphs make the line tall enough. Otherwise,
8585 we must check by scanning the rest of the line. */
8586 line_height
= it
->max_ascent
+ it
->max_descent
;
8587 if (to_y
>= it
->current_y
8588 && to_y
< it
->current_y
+ line_height
)
8593 SAVE_IT (it_backup
, *it
, backup_data
);
8594 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8595 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8597 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8598 line_height
= it
->max_ascent
+ it
->max_descent
;
8599 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8601 if (to_y
>= it
->current_y
8602 && to_y
< it
->current_y
+ line_height
)
8604 /* If TO_Y is in this line and TO_X was reached
8605 above, we scanned too far. We have to restore
8606 IT's settings to the ones before skipping. */
8607 RESTORE_IT (it
, &it_backup
, backup_data
);
8613 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8619 /* Check whether TO_Y is in this line. */
8620 line_height
= it
->max_ascent
+ it
->max_descent
;
8621 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8623 if (to_y
>= it
->current_y
8624 && to_y
< it
->current_y
+ line_height
)
8626 /* When word-wrap is on, TO_X may lie past the end
8627 of a wrapped line. Then it->current is the
8628 character on the next line, so backtrack to the
8629 space before the wrap point. */
8630 if (skip
== MOVE_LINE_CONTINUED
8631 && it
->line_wrap
== WORD_WRAP
)
8633 int prev_x
= max (it
->current_x
- 1, 0);
8634 RESTORE_IT (it
, &it_backup
, backup_data
);
8635 skip
= move_it_in_display_line_to
8636 (it
, -1, prev_x
, MOVE_TO_X
);
8645 else if (BUFFERP (it
->object
)
8646 && (it
->method
== GET_FROM_BUFFER
8647 || it
->method
== GET_FROM_STRETCH
)
8648 && IT_CHARPOS (*it
) >= to_charpos
8649 /* Under bidi iteration, a call to set_iterator_to_next
8650 can scan far beyond to_charpos if the initial
8651 portion of the next line needs to be reordered. In
8652 that case, give move_it_in_display_line_to another
8655 && it
->bidi_it
.scan_dir
== -1))
8656 skip
= MOVE_POS_MATCH_OR_ZV
;
8658 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8662 case MOVE_POS_MATCH_OR_ZV
:
8666 case MOVE_NEWLINE_OR_CR
:
8667 set_iterator_to_next (it
, 1);
8668 it
->continuation_lines_width
= 0;
8671 case MOVE_LINE_TRUNCATED
:
8672 it
->continuation_lines_width
= 0;
8673 reseat_at_next_visible_line_start (it
, 0);
8674 if ((op
& MOVE_TO_POS
) != 0
8675 && IT_CHARPOS (*it
) > to_charpos
)
8682 case MOVE_LINE_CONTINUED
:
8683 /* For continued lines ending in a tab, some of the glyphs
8684 associated with the tab are displayed on the current
8685 line. Since it->current_x does not include these glyphs,
8686 we use it->last_visible_x instead. */
8689 it
->continuation_lines_width
+= it
->last_visible_x
;
8690 /* When moving by vpos, ensure that the iterator really
8691 advances to the next line (bug#847, bug#969). Fixme:
8692 do we need to do this in other circumstances? */
8693 if (it
->current_x
!= it
->last_visible_x
8694 && (op
& MOVE_TO_VPOS
)
8695 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8697 line_start_x
= it
->current_x
+ it
->pixel_width
8698 - it
->last_visible_x
;
8699 set_iterator_to_next (it
, 0);
8703 it
->continuation_lines_width
+= it
->current_x
;
8710 /* Reset/increment for the next run. */
8711 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8712 it
->current_x
= line_start_x
;
8715 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8717 last_height
= it
->max_ascent
+ it
->max_descent
;
8718 last_max_ascent
= it
->max_ascent
;
8719 it
->max_ascent
= it
->max_descent
= 0;
8724 /* On text terminals, we may stop at the end of a line in the middle
8725 of a multi-character glyph. If the glyph itself is continued,
8726 i.e. it is actually displayed on the next line, don't treat this
8727 stopping point as valid; move to the next line instead (unless
8728 that brings us offscreen). */
8729 if (!FRAME_WINDOW_P (it
->f
)
8731 && IT_CHARPOS (*it
) == to_charpos
8732 && it
->what
== IT_CHARACTER
8734 && it
->line_wrap
== WINDOW_WRAP
8735 && it
->current_x
== it
->last_visible_x
- 1
8738 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8740 it
->continuation_lines_width
+= it
->current_x
;
8741 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8742 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8744 last_height
= it
->max_ascent
+ it
->max_descent
;
8745 last_max_ascent
= it
->max_ascent
;
8749 bidi_unshelve_cache (backup_data
, 1);
8751 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8755 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8757 If DY > 0, move IT backward at least that many pixels. DY = 0
8758 means move IT backward to the preceding line start or BEGV. This
8759 function may move over more than DY pixels if IT->current_y - DY
8760 ends up in the middle of a line; in this case IT->current_y will be
8761 set to the top of the line moved to. */
8764 move_it_vertically_backward (struct it
*it
, int dy
)
8768 void *it2data
= NULL
, *it3data
= NULL
;
8769 EMACS_INT start_pos
;
8774 start_pos
= IT_CHARPOS (*it
);
8776 /* Estimate how many newlines we must move back. */
8777 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8779 /* Set the iterator's position that many lines back. */
8780 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8781 back_to_previous_visible_line_start (it
);
8783 /* Reseat the iterator here. When moving backward, we don't want
8784 reseat to skip forward over invisible text, set up the iterator
8785 to deliver from overlay strings at the new position etc. So,
8786 use reseat_1 here. */
8787 reseat_1 (it
, it
->current
.pos
, 1);
8789 /* We are now surely at a line start. */
8790 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8791 reordering is in effect. */
8792 it
->continuation_lines_width
= 0;
8794 /* Move forward and see what y-distance we moved. First move to the
8795 start of the next line so that we get its height. We need this
8796 height to be able to tell whether we reached the specified
8798 SAVE_IT (it2
, *it
, it2data
);
8799 it2
.max_ascent
= it2
.max_descent
= 0;
8802 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8803 MOVE_TO_POS
| MOVE_TO_VPOS
);
8805 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8806 /* If we are in a display string which starts at START_POS,
8807 and that display string includes a newline, and we are
8808 right after that newline (i.e. at the beginning of a
8809 display line), exit the loop, because otherwise we will
8810 infloop, since move_it_to will see that it is already at
8811 START_POS and will not move. */
8812 || (it2
.method
== GET_FROM_STRING
8813 && IT_CHARPOS (it2
) == start_pos
8814 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8815 xassert (IT_CHARPOS (*it
) >= BEGV
);
8816 SAVE_IT (it3
, it2
, it3data
);
8818 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8819 xassert (IT_CHARPOS (*it
) >= BEGV
);
8820 /* H is the actual vertical distance from the position in *IT
8821 and the starting position. */
8822 h
= it2
.current_y
- it
->current_y
;
8823 /* NLINES is the distance in number of lines. */
8824 nlines
= it2
.vpos
- it
->vpos
;
8826 /* Correct IT's y and vpos position
8827 so that they are relative to the starting point. */
8833 /* DY == 0 means move to the start of the screen line. The
8834 value of nlines is > 0 if continuation lines were involved,
8835 or if the original IT position was at start of a line. */
8836 RESTORE_IT (it
, it
, it2data
);
8838 move_it_by_lines (it
, nlines
);
8839 /* The above code moves us to some position NLINES down,
8840 usually to its first glyph (leftmost in an L2R line), but
8841 that's not necessarily the start of the line, under bidi
8842 reordering. We want to get to the character position
8843 that is immediately after the newline of the previous
8846 && !it
->continuation_lines_width
8847 && !STRINGP (it
->string
)
8848 && IT_CHARPOS (*it
) > BEGV
8849 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8852 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8854 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8856 bidi_unshelve_cache (it3data
, 1);
8860 /* The y-position we try to reach, relative to *IT.
8861 Note that H has been subtracted in front of the if-statement. */
8862 int target_y
= it
->current_y
+ h
- dy
;
8863 int y0
= it3
.current_y
;
8867 RESTORE_IT (&it3
, &it3
, it3data
);
8868 y1
= line_bottom_y (&it3
);
8869 line_height
= y1
- y0
;
8870 RESTORE_IT (it
, it
, it2data
);
8871 /* If we did not reach target_y, try to move further backward if
8872 we can. If we moved too far backward, try to move forward. */
8873 if (target_y
< it
->current_y
8874 /* This is heuristic. In a window that's 3 lines high, with
8875 a line height of 13 pixels each, recentering with point
8876 on the bottom line will try to move -39/2 = 19 pixels
8877 backward. Try to avoid moving into the first line. */
8878 && (it
->current_y
- target_y
8879 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8880 && IT_CHARPOS (*it
) > BEGV
)
8882 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8883 target_y
- it
->current_y
));
8884 dy
= it
->current_y
- target_y
;
8885 goto move_further_back
;
8887 else if (target_y
>= it
->current_y
+ line_height
8888 && IT_CHARPOS (*it
) < ZV
)
8890 /* Should move forward by at least one line, maybe more.
8892 Note: Calling move_it_by_lines can be expensive on
8893 terminal frames, where compute_motion is used (via
8894 vmotion) to do the job, when there are very long lines
8895 and truncate-lines is nil. That's the reason for
8896 treating terminal frames specially here. */
8898 if (!FRAME_WINDOW_P (it
->f
))
8899 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8904 move_it_by_lines (it
, 1);
8906 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8913 /* Move IT by a specified amount of pixel lines DY. DY negative means
8914 move backwards. DY = 0 means move to start of screen line. At the
8915 end, IT will be on the start of a screen line. */
8918 move_it_vertically (struct it
*it
, int dy
)
8921 move_it_vertically_backward (it
, -dy
);
8924 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8925 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8926 MOVE_TO_POS
| MOVE_TO_Y
);
8927 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8929 /* If buffer ends in ZV without a newline, move to the start of
8930 the line to satisfy the post-condition. */
8931 if (IT_CHARPOS (*it
) == ZV
8933 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8934 move_it_by_lines (it
, 0);
8939 /* Move iterator IT past the end of the text line it is in. */
8942 move_it_past_eol (struct it
*it
)
8944 enum move_it_result rc
;
8946 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8947 if (rc
== MOVE_NEWLINE_OR_CR
)
8948 set_iterator_to_next (it
, 0);
8952 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8953 negative means move up. DVPOS == 0 means move to the start of the
8956 Optimization idea: If we would know that IT->f doesn't use
8957 a face with proportional font, we could be faster for
8958 truncate-lines nil. */
8961 move_it_by_lines (struct it
*it
, int dvpos
)
8964 /* The commented-out optimization uses vmotion on terminals. This
8965 gives bad results, because elements like it->what, on which
8966 callers such as pos_visible_p rely, aren't updated. */
8967 /* struct position pos;
8968 if (!FRAME_WINDOW_P (it->f))
8970 struct text_pos textpos;
8972 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8973 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8974 reseat (it, textpos, 1);
8975 it->vpos += pos.vpos;
8976 it->current_y += pos.vpos;
8982 /* DVPOS == 0 means move to the start of the screen line. */
8983 move_it_vertically_backward (it
, 0);
8984 /* Let next call to line_bottom_y calculate real line height */
8989 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8990 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8992 /* Only move to the next buffer position if we ended up in a
8993 string from display property, not in an overlay string
8994 (before-string or after-string). That is because the
8995 latter don't conceal the underlying buffer position, so
8996 we can ask to move the iterator to the exact position we
8997 are interested in. Note that, even if we are already at
8998 IT_CHARPOS (*it), the call below is not a no-op, as it
8999 will detect that we are at the end of the string, pop the
9000 iterator, and compute it->current_x and it->hpos
9002 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9003 -1, -1, -1, MOVE_TO_POS
);
9009 void *it2data
= NULL
;
9010 EMACS_INT start_charpos
, i
;
9012 /* Start at the beginning of the screen line containing IT's
9013 position. This may actually move vertically backwards,
9014 in case of overlays, so adjust dvpos accordingly. */
9016 move_it_vertically_backward (it
, 0);
9019 /* Go back -DVPOS visible lines and reseat the iterator there. */
9020 start_charpos
= IT_CHARPOS (*it
);
9021 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9022 back_to_previous_visible_line_start (it
);
9023 reseat (it
, it
->current
.pos
, 1);
9025 /* Move further back if we end up in a string or an image. */
9026 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9028 /* First try to move to start of display line. */
9030 move_it_vertically_backward (it
, 0);
9032 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9034 /* If start of line is still in string or image,
9035 move further back. */
9036 back_to_previous_visible_line_start (it
);
9037 reseat (it
, it
->current
.pos
, 1);
9041 it
->current_x
= it
->hpos
= 0;
9043 /* Above call may have moved too far if continuation lines
9044 are involved. Scan forward and see if it did. */
9045 SAVE_IT (it2
, *it
, it2data
);
9046 it2
.vpos
= it2
.current_y
= 0;
9047 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9048 it
->vpos
-= it2
.vpos
;
9049 it
->current_y
-= it2
.current_y
;
9050 it
->current_x
= it
->hpos
= 0;
9052 /* If we moved too far back, move IT some lines forward. */
9053 if (it2
.vpos
> -dvpos
)
9055 int delta
= it2
.vpos
+ dvpos
;
9057 RESTORE_IT (&it2
, &it2
, it2data
);
9058 SAVE_IT (it2
, *it
, it2data
);
9059 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9060 /* Move back again if we got too far ahead. */
9061 if (IT_CHARPOS (*it
) >= start_charpos
)
9062 RESTORE_IT (it
, &it2
, it2data
);
9064 bidi_unshelve_cache (it2data
, 1);
9067 RESTORE_IT (it
, it
, it2data
);
9071 /* Return 1 if IT points into the middle of a display vector. */
9074 in_display_vector_p (struct it
*it
)
9076 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9077 && it
->current
.dpvec_index
> 0
9078 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9082 /***********************************************************************
9084 ***********************************************************************/
9087 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9091 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9093 Lisp_Object args
[3];
9094 Lisp_Object msg
, fmt
;
9097 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9100 /* Do nothing if called asynchronously. Inserting text into
9101 a buffer may call after-change-functions and alike and
9102 that would means running Lisp asynchronously. */
9103 if (handling_signal
)
9107 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9109 args
[0] = fmt
= build_string (format
);
9112 msg
= Fformat (3, args
);
9114 len
= SBYTES (msg
) + 1;
9115 SAFE_ALLOCA (buffer
, char *, len
);
9116 memcpy (buffer
, SDATA (msg
), len
);
9118 message_dolog (buffer
, len
- 1, 1, 0);
9125 /* Output a newline in the *Messages* buffer if "needs" one. */
9128 message_log_maybe_newline (void)
9130 if (message_log_need_newline
)
9131 message_dolog ("", 0, 1, 0);
9135 /* Add a string M of length NBYTES to the message log, optionally
9136 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9137 nonzero, means interpret the contents of M as multibyte. This
9138 function calls low-level routines in order to bypass text property
9139 hooks, etc. which might not be safe to run.
9141 This may GC (insert may run before/after change hooks),
9142 so the buffer M must NOT point to a Lisp string. */
9145 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
9147 const unsigned char *msg
= (const unsigned char *) m
;
9149 if (!NILP (Vmemory_full
))
9152 if (!NILP (Vmessage_log_max
))
9154 struct buffer
*oldbuf
;
9155 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9156 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9157 EMACS_INT point_at_end
= 0;
9158 EMACS_INT zv_at_end
= 0;
9159 Lisp_Object old_deactivate_mark
, tem
;
9160 struct gcpro gcpro1
;
9162 old_deactivate_mark
= Vdeactivate_mark
;
9163 oldbuf
= current_buffer
;
9164 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9165 BVAR (current_buffer
, undo_list
) = Qt
;
9167 oldpoint
= message_dolog_marker1
;
9168 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9169 oldbegv
= message_dolog_marker2
;
9170 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9171 oldzv
= message_dolog_marker3
;
9172 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9173 GCPRO1 (old_deactivate_mark
);
9181 BEGV_BYTE
= BEG_BYTE
;
9184 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9186 /* Insert the string--maybe converting multibyte to single byte
9187 or vice versa, so that all the text fits the buffer. */
9189 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9195 /* Convert a multibyte string to single-byte
9196 for the *Message* buffer. */
9197 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9199 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9200 work
[0] = (ASCII_CHAR_P (c
)
9202 : multibyte_char_to_unibyte (c
));
9203 insert_1_both (work
, 1, 1, 1, 0, 0);
9206 else if (! multibyte
9207 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9211 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9212 /* Convert a single-byte string to multibyte
9213 for the *Message* buffer. */
9214 for (i
= 0; i
< nbytes
; i
++)
9217 MAKE_CHAR_MULTIBYTE (c
);
9218 char_bytes
= CHAR_STRING (c
, str
);
9219 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9223 insert_1 (m
, nbytes
, 1, 0, 0);
9227 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9229 insert_1 ("\n", 1, 1, 0, 0);
9231 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9233 this_bol_byte
= PT_BYTE
;
9235 /* See if this line duplicates the previous one.
9236 If so, combine duplicates. */
9239 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9241 prev_bol_byte
= PT_BYTE
;
9243 dups
= message_log_check_duplicate (prev_bol_byte
,
9247 del_range_both (prev_bol
, prev_bol_byte
,
9248 this_bol
, this_bol_byte
, 0);
9251 char dupstr
[sizeof " [ times]"
9252 + INT_STRLEN_BOUND (printmax_t
)];
9255 /* If you change this format, don't forget to also
9256 change message_log_check_duplicate. */
9257 sprintf (dupstr
, " [%"pMd
" times]", dups
);
9258 duplen
= strlen (dupstr
);
9259 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9260 insert_1 (dupstr
, duplen
, 1, 0, 1);
9265 /* If we have more than the desired maximum number of lines
9266 in the *Messages* buffer now, delete the oldest ones.
9267 This is safe because we don't have undo in this buffer. */
9269 if (NATNUMP (Vmessage_log_max
))
9271 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9272 -XFASTINT (Vmessage_log_max
) - 1, 0);
9273 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9276 BEGV
= XMARKER (oldbegv
)->charpos
;
9277 BEGV_BYTE
= marker_byte_position (oldbegv
);
9286 ZV
= XMARKER (oldzv
)->charpos
;
9287 ZV_BYTE
= marker_byte_position (oldzv
);
9291 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9293 /* We can't do Fgoto_char (oldpoint) because it will run some
9295 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9296 XMARKER (oldpoint
)->bytepos
);
9299 unchain_marker (XMARKER (oldpoint
));
9300 unchain_marker (XMARKER (oldbegv
));
9301 unchain_marker (XMARKER (oldzv
));
9303 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9304 set_buffer_internal (oldbuf
);
9306 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9307 message_log_need_newline
= !nlflag
;
9308 Vdeactivate_mark
= old_deactivate_mark
;
9313 /* We are at the end of the buffer after just having inserted a newline.
9314 (Note: We depend on the fact we won't be crossing the gap.)
9315 Check to see if the most recent message looks a lot like the previous one.
9316 Return 0 if different, 1 if the new one should just replace it, or a
9317 value N > 1 if we should also append " [N times]". */
9320 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
9323 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
9325 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9326 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9328 for (i
= 0; i
< len
; i
++)
9330 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9338 if (*p1
++ == ' ' && *p1
++ == '[')
9341 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9342 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9349 /* Display an echo area message M with a specified length of NBYTES
9350 bytes. The string may include null characters. If M is 0, clear
9351 out any existing message, and let the mini-buffer text show
9354 This may GC, so the buffer M must NOT point to a Lisp string. */
9357 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
9359 /* First flush out any partial line written with print. */
9360 message_log_maybe_newline ();
9362 message_dolog (m
, nbytes
, 1, multibyte
);
9363 message2_nolog (m
, nbytes
, multibyte
);
9367 /* The non-logging counterpart of message2. */
9370 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
9372 struct frame
*sf
= SELECTED_FRAME ();
9373 message_enable_multibyte
= multibyte
;
9375 if (FRAME_INITIAL_P (sf
))
9377 if (noninteractive_need_newline
)
9378 putc ('\n', stderr
);
9379 noninteractive_need_newline
= 0;
9381 fwrite (m
, nbytes
, 1, stderr
);
9382 if (cursor_in_echo_area
== 0)
9383 fprintf (stderr
, "\n");
9386 /* A null message buffer means that the frame hasn't really been
9387 initialized yet. Error messages get reported properly by
9388 cmd_error, so this must be just an informative message; toss it. */
9389 else if (INTERACTIVE
9390 && sf
->glyphs_initialized_p
9391 && FRAME_MESSAGE_BUF (sf
))
9393 Lisp_Object mini_window
;
9396 /* Get the frame containing the mini-buffer
9397 that the selected frame is using. */
9398 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9399 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9401 FRAME_SAMPLE_VISIBILITY (f
);
9402 if (FRAME_VISIBLE_P (sf
)
9403 && ! FRAME_VISIBLE_P (f
))
9404 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9408 set_message (m
, Qnil
, nbytes
, multibyte
);
9409 if (minibuffer_auto_raise
)
9410 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9413 clear_message (1, 1);
9415 do_pending_window_change (0);
9416 echo_area_display (1);
9417 do_pending_window_change (0);
9418 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9419 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9424 /* Display an echo area message M with a specified length of NBYTES
9425 bytes. The string may include null characters. If M is not a
9426 string, clear out any existing message, and let the mini-buffer
9429 This function cancels echoing. */
9432 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
9434 struct gcpro gcpro1
;
9437 clear_message (1,1);
9440 /* First flush out any partial line written with print. */
9441 message_log_maybe_newline ();
9447 SAFE_ALLOCA (buffer
, char *, nbytes
);
9448 memcpy (buffer
, SDATA (m
), nbytes
);
9449 message_dolog (buffer
, nbytes
, 1, multibyte
);
9452 message3_nolog (m
, nbytes
, multibyte
);
9458 /* The non-logging version of message3.
9459 This does not cancel echoing, because it is used for echoing.
9460 Perhaps we need to make a separate function for echoing
9461 and make this cancel echoing. */
9464 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
9466 struct frame
*sf
= SELECTED_FRAME ();
9467 message_enable_multibyte
= multibyte
;
9469 if (FRAME_INITIAL_P (sf
))
9471 if (noninteractive_need_newline
)
9472 putc ('\n', stderr
);
9473 noninteractive_need_newline
= 0;
9475 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9476 if (cursor_in_echo_area
== 0)
9477 fprintf (stderr
, "\n");
9480 /* A null message buffer means that the frame hasn't really been
9481 initialized yet. Error messages get reported properly by
9482 cmd_error, so this must be just an informative message; toss it. */
9483 else if (INTERACTIVE
9484 && sf
->glyphs_initialized_p
9485 && FRAME_MESSAGE_BUF (sf
))
9487 Lisp_Object mini_window
;
9491 /* Get the frame containing the mini-buffer
9492 that the selected frame is using. */
9493 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9494 frame
= XWINDOW (mini_window
)->frame
;
9497 FRAME_SAMPLE_VISIBILITY (f
);
9498 if (FRAME_VISIBLE_P (sf
)
9499 && !FRAME_VISIBLE_P (f
))
9500 Fmake_frame_visible (frame
);
9502 if (STRINGP (m
) && SCHARS (m
) > 0)
9504 set_message (NULL
, m
, nbytes
, multibyte
);
9505 if (minibuffer_auto_raise
)
9506 Fraise_frame (frame
);
9507 /* Assume we are not echoing.
9508 (If we are, echo_now will override this.) */
9509 echo_message_buffer
= Qnil
;
9512 clear_message (1, 1);
9514 do_pending_window_change (0);
9515 echo_area_display (1);
9516 do_pending_window_change (0);
9517 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9518 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9523 /* Display a null-terminated echo area message M. If M is 0, clear
9524 out any existing message, and let the mini-buffer text show through.
9526 The buffer M must continue to exist until after the echo area gets
9527 cleared or some other message gets displayed there. Do not pass
9528 text that is stored in a Lisp string. Do not pass text in a buffer
9529 that was alloca'd. */
9532 message1 (const char *m
)
9534 message2 (m
, (m
? strlen (m
) : 0), 0);
9538 /* The non-logging counterpart of message1. */
9541 message1_nolog (const char *m
)
9543 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9546 /* Display a message M which contains a single %s
9547 which gets replaced with STRING. */
9550 message_with_string (const char *m
, Lisp_Object string
, int log
)
9552 CHECK_STRING (string
);
9558 if (noninteractive_need_newline
)
9559 putc ('\n', stderr
);
9560 noninteractive_need_newline
= 0;
9561 fprintf (stderr
, m
, SDATA (string
));
9562 if (!cursor_in_echo_area
)
9563 fprintf (stderr
, "\n");
9567 else if (INTERACTIVE
)
9569 /* The frame whose minibuffer we're going to display the message on.
9570 It may be larger than the selected frame, so we need
9571 to use its buffer, not the selected frame's buffer. */
9572 Lisp_Object mini_window
;
9573 struct frame
*f
, *sf
= SELECTED_FRAME ();
9575 /* Get the frame containing the minibuffer
9576 that the selected frame is using. */
9577 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9578 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9580 /* A null message buffer means that the frame hasn't really been
9581 initialized yet. Error messages get reported properly by
9582 cmd_error, so this must be just an informative message; toss it. */
9583 if (FRAME_MESSAGE_BUF (f
))
9585 Lisp_Object args
[2], msg
;
9586 struct gcpro gcpro1
, gcpro2
;
9588 args
[0] = build_string (m
);
9589 args
[1] = msg
= string
;
9590 GCPRO2 (args
[0], msg
);
9593 msg
= Fformat (2, args
);
9596 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9598 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9602 /* Print should start at the beginning of the message
9603 buffer next time. */
9604 message_buf_print
= 0;
9610 /* Dump an informative message to the minibuf. If M is 0, clear out
9611 any existing message, and let the mini-buffer text show through. */
9614 vmessage (const char *m
, va_list ap
)
9620 if (noninteractive_need_newline
)
9621 putc ('\n', stderr
);
9622 noninteractive_need_newline
= 0;
9623 vfprintf (stderr
, m
, ap
);
9624 if (cursor_in_echo_area
== 0)
9625 fprintf (stderr
, "\n");
9629 else if (INTERACTIVE
)
9631 /* The frame whose mini-buffer we're going to display the message
9632 on. It may be larger than the selected frame, so we need to
9633 use its buffer, not the selected frame's buffer. */
9634 Lisp_Object mini_window
;
9635 struct frame
*f
, *sf
= SELECTED_FRAME ();
9637 /* Get the frame containing the mini-buffer
9638 that the selected frame is using. */
9639 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9640 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9642 /* A null message buffer means that the frame hasn't really been
9643 initialized yet. Error messages get reported properly by
9644 cmd_error, so this must be just an informative message; toss
9646 if (FRAME_MESSAGE_BUF (f
))
9652 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9653 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9655 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9660 /* Print should start at the beginning of the message
9661 buffer next time. */
9662 message_buf_print
= 0;
9668 message (const char *m
, ...)
9678 /* The non-logging version of message. */
9681 message_nolog (const char *m
, ...)
9683 Lisp_Object old_log_max
;
9686 old_log_max
= Vmessage_log_max
;
9687 Vmessage_log_max
= Qnil
;
9689 Vmessage_log_max
= old_log_max
;
9695 /* Display the current message in the current mini-buffer. This is
9696 only called from error handlers in process.c, and is not time
9700 update_echo_area (void)
9702 if (!NILP (echo_area_buffer
[0]))
9705 string
= Fcurrent_message ();
9706 message3 (string
, SBYTES (string
),
9707 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9712 /* Make sure echo area buffers in `echo_buffers' are live.
9713 If they aren't, make new ones. */
9716 ensure_echo_area_buffers (void)
9720 for (i
= 0; i
< 2; ++i
)
9721 if (!BUFFERP (echo_buffer
[i
])
9722 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9725 Lisp_Object old_buffer
;
9728 old_buffer
= echo_buffer
[i
];
9729 sprintf (name
, " *Echo Area %d*", i
);
9730 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9731 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9732 /* to force word wrap in echo area -
9733 it was decided to postpone this*/
9734 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9736 for (j
= 0; j
< 2; ++j
)
9737 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9738 echo_area_buffer
[j
] = echo_buffer
[i
];
9743 /* Call FN with args A1..A4 with either the current or last displayed
9744 echo_area_buffer as current buffer.
9746 WHICH zero means use the current message buffer
9747 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9748 from echo_buffer[] and clear it.
9750 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9751 suitable buffer from echo_buffer[] and clear it.
9753 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9754 that the current message becomes the last displayed one, make
9755 choose a suitable buffer for echo_area_buffer[0], and clear it.
9757 Value is what FN returns. */
9760 with_echo_area_buffer (struct window
*w
, int which
,
9761 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9762 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9765 int this_one
, the_other
, clear_buffer_p
, rc
;
9766 int count
= SPECPDL_INDEX ();
9768 /* If buffers aren't live, make new ones. */
9769 ensure_echo_area_buffers ();
9774 this_one
= 0, the_other
= 1;
9776 this_one
= 1, the_other
= 0;
9779 this_one
= 0, the_other
= 1;
9782 /* We need a fresh one in case the current echo buffer equals
9783 the one containing the last displayed echo area message. */
9784 if (!NILP (echo_area_buffer
[this_one
])
9785 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9786 echo_area_buffer
[this_one
] = Qnil
;
9789 /* Choose a suitable buffer from echo_buffer[] is we don't
9791 if (NILP (echo_area_buffer
[this_one
]))
9793 echo_area_buffer
[this_one
]
9794 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9795 ? echo_buffer
[the_other
]
9796 : echo_buffer
[this_one
]);
9800 buffer
= echo_area_buffer
[this_one
];
9802 /* Don't get confused by reusing the buffer used for echoing
9803 for a different purpose. */
9804 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9807 record_unwind_protect (unwind_with_echo_area_buffer
,
9808 with_echo_area_buffer_unwind_data (w
));
9810 /* Make the echo area buffer current. Note that for display
9811 purposes, it is not necessary that the displayed window's buffer
9812 == current_buffer, except for text property lookup. So, let's
9813 only set that buffer temporarily here without doing a full
9814 Fset_window_buffer. We must also change w->pointm, though,
9815 because otherwise an assertions in unshow_buffer fails, and Emacs
9817 set_buffer_internal_1 (XBUFFER (buffer
));
9821 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9824 BVAR (current_buffer
, undo_list
) = Qt
;
9825 BVAR (current_buffer
, read_only
) = Qnil
;
9826 specbind (Qinhibit_read_only
, Qt
);
9827 specbind (Qinhibit_modification_hooks
, Qt
);
9829 if (clear_buffer_p
&& Z
> BEG
)
9832 xassert (BEGV
>= BEG
);
9833 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9835 rc
= fn (a1
, a2
, a3
, a4
);
9837 xassert (BEGV
>= BEG
);
9838 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9840 unbind_to (count
, Qnil
);
9845 /* Save state that should be preserved around the call to the function
9846 FN called in with_echo_area_buffer. */
9849 with_echo_area_buffer_unwind_data (struct window
*w
)
9852 Lisp_Object vector
, tmp
;
9854 /* Reduce consing by keeping one vector in
9855 Vwith_echo_area_save_vector. */
9856 vector
= Vwith_echo_area_save_vector
;
9857 Vwith_echo_area_save_vector
= Qnil
;
9860 vector
= Fmake_vector (make_number (7), Qnil
);
9862 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9863 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9864 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9868 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9869 ASET (vector
, i
, w
->buffer
); ++i
;
9870 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9871 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9876 for (; i
< end
; ++i
)
9877 ASET (vector
, i
, Qnil
);
9880 xassert (i
== ASIZE (vector
));
9885 /* Restore global state from VECTOR which was created by
9886 with_echo_area_buffer_unwind_data. */
9889 unwind_with_echo_area_buffer (Lisp_Object vector
)
9891 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9892 Vdeactivate_mark
= AREF (vector
, 1);
9893 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9895 if (WINDOWP (AREF (vector
, 3)))
9898 Lisp_Object buffer
, charpos
, bytepos
;
9900 w
= XWINDOW (AREF (vector
, 3));
9901 buffer
= AREF (vector
, 4);
9902 charpos
= AREF (vector
, 5);
9903 bytepos
= AREF (vector
, 6);
9906 set_marker_both (w
->pointm
, buffer
,
9907 XFASTINT (charpos
), XFASTINT (bytepos
));
9910 Vwith_echo_area_save_vector
= vector
;
9915 /* Set up the echo area for use by print functions. MULTIBYTE_P
9916 non-zero means we will print multibyte. */
9919 setup_echo_area_for_printing (int multibyte_p
)
9921 /* If we can't find an echo area any more, exit. */
9922 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9925 ensure_echo_area_buffers ();
9927 if (!message_buf_print
)
9929 /* A message has been output since the last time we printed.
9930 Choose a fresh echo area buffer. */
9931 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9932 echo_area_buffer
[0] = echo_buffer
[1];
9934 echo_area_buffer
[0] = echo_buffer
[0];
9936 /* Switch to that buffer and clear it. */
9937 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9938 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9942 int count
= SPECPDL_INDEX ();
9943 specbind (Qinhibit_read_only
, Qt
);
9944 /* Note that undo recording is always disabled. */
9946 unbind_to (count
, Qnil
);
9948 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9950 /* Set up the buffer for the multibyteness we need. */
9952 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9953 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9955 /* Raise the frame containing the echo area. */
9956 if (minibuffer_auto_raise
)
9958 struct frame
*sf
= SELECTED_FRAME ();
9959 Lisp_Object mini_window
;
9960 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9961 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9964 message_log_maybe_newline ();
9965 message_buf_print
= 1;
9969 if (NILP (echo_area_buffer
[0]))
9971 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9972 echo_area_buffer
[0] = echo_buffer
[1];
9974 echo_area_buffer
[0] = echo_buffer
[0];
9977 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9979 /* Someone switched buffers between print requests. */
9980 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9981 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9987 /* Display an echo area message in window W. Value is non-zero if W's
9988 height is changed. If display_last_displayed_message_p is
9989 non-zero, display the message that was last displayed, otherwise
9990 display the current message. */
9993 display_echo_area (struct window
*w
)
9995 int i
, no_message_p
, window_height_changed_p
, count
;
9997 /* Temporarily disable garbage collections while displaying the echo
9998 area. This is done because a GC can print a message itself.
9999 That message would modify the echo area buffer's contents while a
10000 redisplay of the buffer is going on, and seriously confuse
10002 count
= inhibit_garbage_collection ();
10004 /* If there is no message, we must call display_echo_area_1
10005 nevertheless because it resizes the window. But we will have to
10006 reset the echo_area_buffer in question to nil at the end because
10007 with_echo_area_buffer will sets it to an empty buffer. */
10008 i
= display_last_displayed_message_p
? 1 : 0;
10009 no_message_p
= NILP (echo_area_buffer
[i
]);
10011 window_height_changed_p
10012 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10013 display_echo_area_1
,
10014 (intptr_t) w
, Qnil
, 0, 0);
10017 echo_area_buffer
[i
] = Qnil
;
10019 unbind_to (count
, Qnil
);
10020 return window_height_changed_p
;
10024 /* Helper for display_echo_area. Display the current buffer which
10025 contains the current echo area message in window W, a mini-window,
10026 a pointer to which is passed in A1. A2..A4 are currently not used.
10027 Change the height of W so that all of the message is displayed.
10028 Value is non-zero if height of W was changed. */
10031 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
10034 struct window
*w
= (struct window
*) i1
;
10035 Lisp_Object window
;
10036 struct text_pos start
;
10037 int window_height_changed_p
= 0;
10039 /* Do this before displaying, so that we have a large enough glyph
10040 matrix for the display. If we can't get enough space for the
10041 whole text, display the last N lines. That works by setting w->start. */
10042 window_height_changed_p
= resize_mini_window (w
, 0);
10044 /* Use the starting position chosen by resize_mini_window. */
10045 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10048 clear_glyph_matrix (w
->desired_matrix
);
10049 XSETWINDOW (window
, w
);
10050 try_window (window
, start
, 0);
10052 return window_height_changed_p
;
10056 /* Resize the echo area window to exactly the size needed for the
10057 currently displayed message, if there is one. If a mini-buffer
10058 is active, don't shrink it. */
10061 resize_echo_area_exactly (void)
10063 if (BUFFERP (echo_area_buffer
[0])
10064 && WINDOWP (echo_area_window
))
10066 struct window
*w
= XWINDOW (echo_area_window
);
10068 Lisp_Object resize_exactly
;
10070 if (minibuf_level
== 0)
10071 resize_exactly
= Qt
;
10073 resize_exactly
= Qnil
;
10075 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10076 (intptr_t) w
, resize_exactly
,
10080 ++windows_or_buffers_changed
;
10081 ++update_mode_lines
;
10082 redisplay_internal ();
10088 /* Callback function for with_echo_area_buffer, when used from
10089 resize_echo_area_exactly. A1 contains a pointer to the window to
10090 resize, EXACTLY non-nil means resize the mini-window exactly to the
10091 size of the text displayed. A3 and A4 are not used. Value is what
10092 resize_mini_window returns. */
10095 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
10098 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10102 /* Resize mini-window W to fit the size of its contents. EXACT_P
10103 means size the window exactly to the size needed. Otherwise, it's
10104 only enlarged until W's buffer is empty.
10106 Set W->start to the right place to begin display. If the whole
10107 contents fit, start at the beginning. Otherwise, start so as
10108 to make the end of the contents appear. This is particularly
10109 important for y-or-n-p, but seems desirable generally.
10111 Value is non-zero if the window height has been changed. */
10114 resize_mini_window (struct window
*w
, int exact_p
)
10116 struct frame
*f
= XFRAME (w
->frame
);
10117 int window_height_changed_p
= 0;
10119 xassert (MINI_WINDOW_P (w
));
10121 /* By default, start display at the beginning. */
10122 set_marker_both (w
->start
, w
->buffer
,
10123 BUF_BEGV (XBUFFER (w
->buffer
)),
10124 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10126 /* Don't resize windows while redisplaying a window; it would
10127 confuse redisplay functions when the size of the window they are
10128 displaying changes from under them. Such a resizing can happen,
10129 for instance, when which-func prints a long message while
10130 we are running fontification-functions. We're running these
10131 functions with safe_call which binds inhibit-redisplay to t. */
10132 if (!NILP (Vinhibit_redisplay
))
10135 /* Nil means don't try to resize. */
10136 if (NILP (Vresize_mini_windows
)
10137 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10140 if (!FRAME_MINIBUF_ONLY_P (f
))
10143 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10144 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10145 int height
, max_height
;
10146 int unit
= FRAME_LINE_HEIGHT (f
);
10147 struct text_pos start
;
10148 struct buffer
*old_current_buffer
= NULL
;
10150 if (current_buffer
!= XBUFFER (w
->buffer
))
10152 old_current_buffer
= current_buffer
;
10153 set_buffer_internal (XBUFFER (w
->buffer
));
10156 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10158 /* Compute the max. number of lines specified by the user. */
10159 if (FLOATP (Vmax_mini_window_height
))
10160 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10161 else if (INTEGERP (Vmax_mini_window_height
))
10162 max_height
= XINT (Vmax_mini_window_height
);
10164 max_height
= total_height
/ 4;
10166 /* Correct that max. height if it's bogus. */
10167 max_height
= max (1, max_height
);
10168 max_height
= min (total_height
, max_height
);
10170 /* Find out the height of the text in the window. */
10171 if (it
.line_wrap
== TRUNCATE
)
10176 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10177 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10178 height
= it
.current_y
+ last_height
;
10180 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10181 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10182 height
= (height
+ unit
- 1) / unit
;
10185 /* Compute a suitable window start. */
10186 if (height
> max_height
)
10188 height
= max_height
;
10189 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10190 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10191 start
= it
.current
.pos
;
10194 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10195 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10197 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10199 /* Let it grow only, until we display an empty message, in which
10200 case the window shrinks again. */
10201 if (height
> WINDOW_TOTAL_LINES (w
))
10203 int old_height
= WINDOW_TOTAL_LINES (w
);
10204 freeze_window_starts (f
, 1);
10205 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10206 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10208 else if (height
< WINDOW_TOTAL_LINES (w
)
10209 && (exact_p
|| BEGV
== ZV
))
10211 int old_height
= WINDOW_TOTAL_LINES (w
);
10212 freeze_window_starts (f
, 0);
10213 shrink_mini_window (w
);
10214 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10219 /* Always resize to exact size needed. */
10220 if (height
> WINDOW_TOTAL_LINES (w
))
10222 int old_height
= WINDOW_TOTAL_LINES (w
);
10223 freeze_window_starts (f
, 1);
10224 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10225 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10227 else if (height
< WINDOW_TOTAL_LINES (w
))
10229 int old_height
= WINDOW_TOTAL_LINES (w
);
10230 freeze_window_starts (f
, 0);
10231 shrink_mini_window (w
);
10235 freeze_window_starts (f
, 1);
10236 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10239 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10243 if (old_current_buffer
)
10244 set_buffer_internal (old_current_buffer
);
10247 return window_height_changed_p
;
10251 /* Value is the current message, a string, or nil if there is no
10252 current message. */
10255 current_message (void)
10259 if (!BUFFERP (echo_area_buffer
[0]))
10263 with_echo_area_buffer (0, 0, current_message_1
,
10264 (intptr_t) &msg
, Qnil
, 0, 0);
10266 echo_area_buffer
[0] = Qnil
;
10274 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
10277 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10280 *msg
= make_buffer_string (BEG
, Z
, 1);
10287 /* Push the current message on Vmessage_stack for later restoration
10288 by restore_message. Value is non-zero if the current message isn't
10289 empty. This is a relatively infrequent operation, so it's not
10290 worth optimizing. */
10293 push_message (void)
10296 msg
= current_message ();
10297 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10298 return STRINGP (msg
);
10302 /* Restore message display from the top of Vmessage_stack. */
10305 restore_message (void)
10309 xassert (CONSP (Vmessage_stack
));
10310 msg
= XCAR (Vmessage_stack
);
10312 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10314 message3_nolog (msg
, 0, 0);
10318 /* Handler for record_unwind_protect calling pop_message. */
10321 pop_message_unwind (Lisp_Object dummy
)
10327 /* Pop the top-most entry off Vmessage_stack. */
10332 xassert (CONSP (Vmessage_stack
));
10333 Vmessage_stack
= XCDR (Vmessage_stack
);
10337 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10338 exits. If the stack is not empty, we have a missing pop_message
10342 check_message_stack (void)
10344 if (!NILP (Vmessage_stack
))
10349 /* Truncate to NCHARS what will be displayed in the echo area the next
10350 time we display it---but don't redisplay it now. */
10353 truncate_echo_area (EMACS_INT nchars
)
10356 echo_area_buffer
[0] = Qnil
;
10357 /* A null message buffer means that the frame hasn't really been
10358 initialized yet. Error messages get reported properly by
10359 cmd_error, so this must be just an informative message; toss it. */
10360 else if (!noninteractive
10362 && !NILP (echo_area_buffer
[0]))
10364 struct frame
*sf
= SELECTED_FRAME ();
10365 if (FRAME_MESSAGE_BUF (sf
))
10366 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10371 /* Helper function for truncate_echo_area. Truncate the current
10372 message to at most NCHARS characters. */
10375 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
10377 if (BEG
+ nchars
< Z
)
10378 del_range (BEG
+ nchars
, Z
);
10380 echo_area_buffer
[0] = Qnil
;
10385 /* Set the current message to a substring of S or STRING.
10387 If STRING is a Lisp string, set the message to the first NBYTES
10388 bytes from STRING. NBYTES zero means use the whole string. If
10389 STRING is multibyte, the message will be displayed multibyte.
10391 If S is not null, set the message to the first LEN bytes of S. LEN
10392 zero means use the whole string. MULTIBYTE_P non-zero means S is
10393 multibyte. Display the message multibyte in that case.
10395 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10396 to t before calling set_message_1 (which calls insert).
10400 set_message (const char *s
, Lisp_Object string
,
10401 EMACS_INT nbytes
, int multibyte_p
)
10403 message_enable_multibyte
10404 = ((s
&& multibyte_p
)
10405 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10407 with_echo_area_buffer (0, -1, set_message_1
,
10408 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10409 message_buf_print
= 0;
10410 help_echo_showing_p
= 0;
10414 /* Helper function for set_message. Arguments have the same meaning
10415 as there, with A1 corresponding to S and A2 corresponding to STRING
10416 This function is called with the echo area buffer being
10420 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
10423 const char *s
= (const char *) i1
;
10424 const unsigned char *msg
= (const unsigned char *) s
;
10425 Lisp_Object string
= a2
;
10427 /* Change multibyteness of the echo buffer appropriately. */
10428 if (message_enable_multibyte
10429 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10430 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10432 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10433 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10434 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10436 /* Insert new message at BEG. */
10437 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10439 if (STRINGP (string
))
10444 nbytes
= SBYTES (string
);
10445 nchars
= string_byte_to_char (string
, nbytes
);
10447 /* This function takes care of single/multibyte conversion. We
10448 just have to ensure that the echo area buffer has the right
10449 setting of enable_multibyte_characters. */
10450 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10455 nbytes
= strlen (s
);
10457 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10459 /* Convert from multi-byte to single-byte. */
10464 /* Convert a multibyte string to single-byte. */
10465 for (i
= 0; i
< nbytes
; i
+= n
)
10467 c
= string_char_and_length (msg
+ i
, &n
);
10468 work
[0] = (ASCII_CHAR_P (c
)
10470 : multibyte_char_to_unibyte (c
));
10471 insert_1_both (work
, 1, 1, 1, 0, 0);
10474 else if (!multibyte_p
10475 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10477 /* Convert from single-byte to multi-byte. */
10480 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10482 /* Convert a single-byte string to multibyte. */
10483 for (i
= 0; i
< nbytes
; i
++)
10486 MAKE_CHAR_MULTIBYTE (c
);
10487 n
= CHAR_STRING (c
, str
);
10488 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10492 insert_1 (s
, nbytes
, 1, 0, 0);
10499 /* Clear messages. CURRENT_P non-zero means clear the current
10500 message. LAST_DISPLAYED_P non-zero means clear the message
10504 clear_message (int current_p
, int last_displayed_p
)
10508 echo_area_buffer
[0] = Qnil
;
10509 message_cleared_p
= 1;
10512 if (last_displayed_p
)
10513 echo_area_buffer
[1] = Qnil
;
10515 message_buf_print
= 0;
10518 /* Clear garbaged frames.
10520 This function is used where the old redisplay called
10521 redraw_garbaged_frames which in turn called redraw_frame which in
10522 turn called clear_frame. The call to clear_frame was a source of
10523 flickering. I believe a clear_frame is not necessary. It should
10524 suffice in the new redisplay to invalidate all current matrices,
10525 and ensure a complete redisplay of all windows. */
10528 clear_garbaged_frames (void)
10530 if (frame_garbaged
)
10532 Lisp_Object tail
, frame
;
10533 int changed_count
= 0;
10535 FOR_EACH_FRAME (tail
, frame
)
10537 struct frame
*f
= XFRAME (frame
);
10539 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10543 Fredraw_frame (frame
);
10544 f
->force_flush_display_p
= 1;
10546 clear_current_matrices (f
);
10553 frame_garbaged
= 0;
10555 ++windows_or_buffers_changed
;
10560 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10561 is non-zero update selected_frame. Value is non-zero if the
10562 mini-windows height has been changed. */
10565 echo_area_display (int update_frame_p
)
10567 Lisp_Object mini_window
;
10570 int window_height_changed_p
= 0;
10571 struct frame
*sf
= SELECTED_FRAME ();
10573 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10574 w
= XWINDOW (mini_window
);
10575 f
= XFRAME (WINDOW_FRAME (w
));
10577 /* Don't display if frame is invisible or not yet initialized. */
10578 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10581 #ifdef HAVE_WINDOW_SYSTEM
10582 /* When Emacs starts, selected_frame may be the initial terminal
10583 frame. If we let this through, a message would be displayed on
10585 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10587 #endif /* HAVE_WINDOW_SYSTEM */
10589 /* Redraw garbaged frames. */
10590 if (frame_garbaged
)
10591 clear_garbaged_frames ();
10593 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10595 echo_area_window
= mini_window
;
10596 window_height_changed_p
= display_echo_area (w
);
10597 w
->must_be_updated_p
= 1;
10599 /* Update the display, unless called from redisplay_internal.
10600 Also don't update the screen during redisplay itself. The
10601 update will happen at the end of redisplay, and an update
10602 here could cause confusion. */
10603 if (update_frame_p
&& !redisplaying_p
)
10607 /* If the display update has been interrupted by pending
10608 input, update mode lines in the frame. Due to the
10609 pending input, it might have been that redisplay hasn't
10610 been called, so that mode lines above the echo area are
10611 garbaged. This looks odd, so we prevent it here. */
10612 if (!display_completed
)
10613 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10615 if (window_height_changed_p
10616 /* Don't do this if Emacs is shutting down. Redisplay
10617 needs to run hooks. */
10618 && !NILP (Vrun_hooks
))
10620 /* Must update other windows. Likewise as in other
10621 cases, don't let this update be interrupted by
10623 int count
= SPECPDL_INDEX ();
10624 specbind (Qredisplay_dont_pause
, Qt
);
10625 windows_or_buffers_changed
= 1;
10626 redisplay_internal ();
10627 unbind_to (count
, Qnil
);
10629 else if (FRAME_WINDOW_P (f
) && n
== 0)
10631 /* Window configuration is the same as before.
10632 Can do with a display update of the echo area,
10633 unless we displayed some mode lines. */
10634 update_single_window (w
, 1);
10635 FRAME_RIF (f
)->flush_display (f
);
10638 update_frame (f
, 1, 1);
10640 /* If cursor is in the echo area, make sure that the next
10641 redisplay displays the minibuffer, so that the cursor will
10642 be replaced with what the minibuffer wants. */
10643 if (cursor_in_echo_area
)
10644 ++windows_or_buffers_changed
;
10647 else if (!EQ (mini_window
, selected_window
))
10648 windows_or_buffers_changed
++;
10650 /* Last displayed message is now the current message. */
10651 echo_area_buffer
[1] = echo_area_buffer
[0];
10652 /* Inform read_char that we're not echoing. */
10653 echo_message_buffer
= Qnil
;
10655 /* Prevent redisplay optimization in redisplay_internal by resetting
10656 this_line_start_pos. This is done because the mini-buffer now
10657 displays the message instead of its buffer text. */
10658 if (EQ (mini_window
, selected_window
))
10659 CHARPOS (this_line_start_pos
) = 0;
10661 return window_height_changed_p
;
10666 /***********************************************************************
10667 Mode Lines and Frame Titles
10668 ***********************************************************************/
10670 /* A buffer for constructing non-propertized mode-line strings and
10671 frame titles in it; allocated from the heap in init_xdisp and
10672 resized as needed in store_mode_line_noprop_char. */
10674 static char *mode_line_noprop_buf
;
10676 /* The buffer's end, and a current output position in it. */
10678 static char *mode_line_noprop_buf_end
;
10679 static char *mode_line_noprop_ptr
;
10681 #define MODE_LINE_NOPROP_LEN(start) \
10682 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10685 MODE_LINE_DISPLAY
= 0,
10689 } mode_line_target
;
10691 /* Alist that caches the results of :propertize.
10692 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10693 static Lisp_Object mode_line_proptrans_alist
;
10695 /* List of strings making up the mode-line. */
10696 static Lisp_Object mode_line_string_list
;
10698 /* Base face property when building propertized mode line string. */
10699 static Lisp_Object mode_line_string_face
;
10700 static Lisp_Object mode_line_string_face_prop
;
10703 /* Unwind data for mode line strings */
10705 static Lisp_Object Vmode_line_unwind_vector
;
10708 format_mode_line_unwind_data (struct buffer
*obuf
,
10710 int save_proptrans
)
10712 Lisp_Object vector
, tmp
;
10714 /* Reduce consing by keeping one vector in
10715 Vwith_echo_area_save_vector. */
10716 vector
= Vmode_line_unwind_vector
;
10717 Vmode_line_unwind_vector
= Qnil
;
10720 vector
= Fmake_vector (make_number (8), Qnil
);
10722 ASET (vector
, 0, make_number (mode_line_target
));
10723 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10724 ASET (vector
, 2, mode_line_string_list
);
10725 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10726 ASET (vector
, 4, mode_line_string_face
);
10727 ASET (vector
, 5, mode_line_string_face_prop
);
10730 XSETBUFFER (tmp
, obuf
);
10733 ASET (vector
, 6, tmp
);
10734 ASET (vector
, 7, owin
);
10740 unwind_format_mode_line (Lisp_Object vector
)
10742 mode_line_target
= XINT (AREF (vector
, 0));
10743 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10744 mode_line_string_list
= AREF (vector
, 2);
10745 if (! EQ (AREF (vector
, 3), Qt
))
10746 mode_line_proptrans_alist
= AREF (vector
, 3);
10747 mode_line_string_face
= AREF (vector
, 4);
10748 mode_line_string_face_prop
= AREF (vector
, 5);
10750 if (!NILP (AREF (vector
, 7)))
10751 /* Select window before buffer, since it may change the buffer. */
10752 Fselect_window (AREF (vector
, 7), Qt
);
10754 if (!NILP (AREF (vector
, 6)))
10756 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10757 ASET (vector
, 6, Qnil
);
10760 Vmode_line_unwind_vector
= vector
;
10765 /* Store a single character C for the frame title in mode_line_noprop_buf.
10766 Re-allocate mode_line_noprop_buf if necessary. */
10769 store_mode_line_noprop_char (char c
)
10771 /* If output position has reached the end of the allocated buffer,
10772 increase the buffer's size. */
10773 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10775 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10776 ptrdiff_t size
= len
;
10777 mode_line_noprop_buf
=
10778 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10779 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10780 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10783 *mode_line_noprop_ptr
++ = c
;
10787 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10788 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10789 characters that yield more columns than PRECISION; PRECISION <= 0
10790 means copy the whole string. Pad with spaces until FIELD_WIDTH
10791 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10792 pad. Called from display_mode_element when it is used to build a
10796 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10798 const unsigned char *str
= (const unsigned char *) string
;
10800 EMACS_INT dummy
, nbytes
;
10802 /* Copy at most PRECISION chars from STR. */
10803 nbytes
= strlen (string
);
10804 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10806 store_mode_line_noprop_char (*str
++);
10808 /* Fill up with spaces until FIELD_WIDTH reached. */
10809 while (field_width
> 0
10810 && n
< field_width
)
10812 store_mode_line_noprop_char (' ');
10819 /***********************************************************************
10821 ***********************************************************************/
10823 #ifdef HAVE_WINDOW_SYSTEM
10825 /* Set the title of FRAME, if it has changed. The title format is
10826 Vicon_title_format if FRAME is iconified, otherwise it is
10827 frame_title_format. */
10830 x_consider_frame_title (Lisp_Object frame
)
10832 struct frame
*f
= XFRAME (frame
);
10834 if (FRAME_WINDOW_P (f
)
10835 || FRAME_MINIBUF_ONLY_P (f
)
10836 || f
->explicit_name
)
10838 /* Do we have more than one visible frame on this X display? */
10841 ptrdiff_t title_start
;
10845 int count
= SPECPDL_INDEX ();
10847 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10849 Lisp_Object other_frame
= XCAR (tail
);
10850 struct frame
*tf
= XFRAME (other_frame
);
10853 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10854 && !FRAME_MINIBUF_ONLY_P (tf
)
10855 && !EQ (other_frame
, tip_frame
)
10856 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10860 /* Set global variable indicating that multiple frames exist. */
10861 multiple_frames
= CONSP (tail
);
10863 /* Switch to the buffer of selected window of the frame. Set up
10864 mode_line_target so that display_mode_element will output into
10865 mode_line_noprop_buf; then display the title. */
10866 record_unwind_protect (unwind_format_mode_line
,
10867 format_mode_line_unwind_data
10868 (current_buffer
, selected_window
, 0));
10870 Fselect_window (f
->selected_window
, Qt
);
10871 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10872 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10874 mode_line_target
= MODE_LINE_TITLE
;
10875 title_start
= MODE_LINE_NOPROP_LEN (0);
10876 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10877 NULL
, DEFAULT_FACE_ID
);
10878 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10879 len
= MODE_LINE_NOPROP_LEN (title_start
);
10880 title
= mode_line_noprop_buf
+ title_start
;
10881 unbind_to (count
, Qnil
);
10883 /* Set the title only if it's changed. This avoids consing in
10884 the common case where it hasn't. (If it turns out that we've
10885 already wasted too much time by walking through the list with
10886 display_mode_element, then we might need to optimize at a
10887 higher level than this.) */
10888 if (! STRINGP (f
->name
)
10889 || SBYTES (f
->name
) != len
10890 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10891 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10895 #endif /* not HAVE_WINDOW_SYSTEM */
10900 /***********************************************************************
10902 ***********************************************************************/
10905 /* Prepare for redisplay by updating menu-bar item lists when
10906 appropriate. This can call eval. */
10909 prepare_menu_bars (void)
10912 struct gcpro gcpro1
, gcpro2
;
10914 Lisp_Object tooltip_frame
;
10916 #ifdef HAVE_WINDOW_SYSTEM
10917 tooltip_frame
= tip_frame
;
10919 tooltip_frame
= Qnil
;
10922 /* Update all frame titles based on their buffer names, etc. We do
10923 this before the menu bars so that the buffer-menu will show the
10924 up-to-date frame titles. */
10925 #ifdef HAVE_WINDOW_SYSTEM
10926 if (windows_or_buffers_changed
|| update_mode_lines
)
10928 Lisp_Object tail
, frame
;
10930 FOR_EACH_FRAME (tail
, frame
)
10932 f
= XFRAME (frame
);
10933 if (!EQ (frame
, tooltip_frame
)
10934 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10935 x_consider_frame_title (frame
);
10938 #endif /* HAVE_WINDOW_SYSTEM */
10940 /* Update the menu bar item lists, if appropriate. This has to be
10941 done before any actual redisplay or generation of display lines. */
10942 all_windows
= (update_mode_lines
10943 || buffer_shared
> 1
10944 || windows_or_buffers_changed
);
10947 Lisp_Object tail
, frame
;
10948 int count
= SPECPDL_INDEX ();
10949 /* 1 means that update_menu_bar has run its hooks
10950 so any further calls to update_menu_bar shouldn't do so again. */
10951 int menu_bar_hooks_run
= 0;
10953 record_unwind_save_match_data ();
10955 FOR_EACH_FRAME (tail
, frame
)
10957 f
= XFRAME (frame
);
10959 /* Ignore tooltip frame. */
10960 if (EQ (frame
, tooltip_frame
))
10963 /* If a window on this frame changed size, report that to
10964 the user and clear the size-change flag. */
10965 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10967 Lisp_Object functions
;
10969 /* Clear flag first in case we get an error below. */
10970 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10971 functions
= Vwindow_size_change_functions
;
10972 GCPRO2 (tail
, functions
);
10974 while (CONSP (functions
))
10976 if (!EQ (XCAR (functions
), Qt
))
10977 call1 (XCAR (functions
), frame
);
10978 functions
= XCDR (functions
);
10984 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10985 #ifdef HAVE_WINDOW_SYSTEM
10986 update_tool_bar (f
, 0);
10989 if (windows_or_buffers_changed
10991 ns_set_doc_edited (f
, Fbuffer_modified_p
10992 (XWINDOW (f
->selected_window
)->buffer
));
10997 unbind_to (count
, Qnil
);
11001 struct frame
*sf
= SELECTED_FRAME ();
11002 update_menu_bar (sf
, 1, 0);
11003 #ifdef HAVE_WINDOW_SYSTEM
11004 update_tool_bar (sf
, 1);
11010 /* Update the menu bar item list for frame F. This has to be done
11011 before we start to fill in any display lines, because it can call
11014 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11016 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11017 already ran the menu bar hooks for this redisplay, so there
11018 is no need to run them again. The return value is the
11019 updated value of this flag, to pass to the next call. */
11022 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11024 Lisp_Object window
;
11025 register struct window
*w
;
11027 /* If called recursively during a menu update, do nothing. This can
11028 happen when, for instance, an activate-menubar-hook causes a
11030 if (inhibit_menubar_update
)
11033 window
= FRAME_SELECTED_WINDOW (f
);
11034 w
= XWINDOW (window
);
11036 if (FRAME_WINDOW_P (f
)
11038 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11039 || defined (HAVE_NS) || defined (USE_GTK)
11040 FRAME_EXTERNAL_MENU_BAR (f
)
11042 FRAME_MENU_BAR_LINES (f
) > 0
11044 : FRAME_MENU_BAR_LINES (f
) > 0)
11046 /* If the user has switched buffers or windows, we need to
11047 recompute to reflect the new bindings. But we'll
11048 recompute when update_mode_lines is set too; that means
11049 that people can use force-mode-line-update to request
11050 that the menu bar be recomputed. The adverse effect on
11051 the rest of the redisplay algorithm is about the same as
11052 windows_or_buffers_changed anyway. */
11053 if (windows_or_buffers_changed
11054 /* This used to test w->update_mode_line, but we believe
11055 there is no need to recompute the menu in that case. */
11056 || update_mode_lines
11057 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11058 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11059 != !NILP (w
->last_had_star
))
11060 || ((!NILP (Vtransient_mark_mode
)
11061 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11062 != !NILP (w
->region_showing
)))
11064 struct buffer
*prev
= current_buffer
;
11065 int count
= SPECPDL_INDEX ();
11067 specbind (Qinhibit_menubar_update
, Qt
);
11069 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11070 if (save_match_data
)
11071 record_unwind_save_match_data ();
11072 if (NILP (Voverriding_local_map_menu_flag
))
11074 specbind (Qoverriding_terminal_local_map
, Qnil
);
11075 specbind (Qoverriding_local_map
, Qnil
);
11080 /* Run the Lucid hook. */
11081 safe_run_hooks (Qactivate_menubar_hook
);
11083 /* If it has changed current-menubar from previous value,
11084 really recompute the menu-bar from the value. */
11085 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11086 call0 (Qrecompute_lucid_menubar
);
11088 safe_run_hooks (Qmenu_bar_update_hook
);
11093 XSETFRAME (Vmenu_updating_frame
, f
);
11094 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11096 /* Redisplay the menu bar in case we changed it. */
11097 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11098 || defined (HAVE_NS) || defined (USE_GTK)
11099 if (FRAME_WINDOW_P (f
))
11101 #if defined (HAVE_NS)
11102 /* All frames on Mac OS share the same menubar. So only
11103 the selected frame should be allowed to set it. */
11104 if (f
== SELECTED_FRAME ())
11106 set_frame_menubar (f
, 0, 0);
11109 /* On a terminal screen, the menu bar is an ordinary screen
11110 line, and this makes it get updated. */
11111 w
->update_mode_line
= Qt
;
11112 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11113 /* In the non-toolkit version, the menu bar is an ordinary screen
11114 line, and this makes it get updated. */
11115 w
->update_mode_line
= Qt
;
11116 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11118 unbind_to (count
, Qnil
);
11119 set_buffer_internal_1 (prev
);
11128 /***********************************************************************
11130 ***********************************************************************/
11132 #ifdef HAVE_WINDOW_SYSTEM
11135 Nominal cursor position -- where to draw output.
11136 HPOS and VPOS are window relative glyph matrix coordinates.
11137 X and Y are window relative pixel coordinates. */
11139 struct cursor_pos output_cursor
;
11143 Set the global variable output_cursor to CURSOR. All cursor
11144 positions are relative to updated_window. */
11147 set_output_cursor (struct cursor_pos
*cursor
)
11149 output_cursor
.hpos
= cursor
->hpos
;
11150 output_cursor
.vpos
= cursor
->vpos
;
11151 output_cursor
.x
= cursor
->x
;
11152 output_cursor
.y
= cursor
->y
;
11157 Set a nominal cursor position.
11159 HPOS and VPOS are column/row positions in a window glyph matrix. X
11160 and Y are window text area relative pixel positions.
11162 If this is done during an update, updated_window will contain the
11163 window that is being updated and the position is the future output
11164 cursor position for that window. If updated_window is null, use
11165 selected_window and display the cursor at the given position. */
11168 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11172 /* If updated_window is not set, work on selected_window. */
11173 if (updated_window
)
11174 w
= updated_window
;
11176 w
= XWINDOW (selected_window
);
11178 /* Set the output cursor. */
11179 output_cursor
.hpos
= hpos
;
11180 output_cursor
.vpos
= vpos
;
11181 output_cursor
.x
= x
;
11182 output_cursor
.y
= y
;
11184 /* If not called as part of an update, really display the cursor.
11185 This will also set the cursor position of W. */
11186 if (updated_window
== NULL
)
11189 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11190 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11191 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11196 #endif /* HAVE_WINDOW_SYSTEM */
11199 /***********************************************************************
11201 ***********************************************************************/
11203 #ifdef HAVE_WINDOW_SYSTEM
11205 /* Where the mouse was last time we reported a mouse event. */
11207 FRAME_PTR last_mouse_frame
;
11209 /* Tool-bar item index of the item on which a mouse button was pressed
11212 int last_tool_bar_item
;
11216 update_tool_bar_unwind (Lisp_Object frame
)
11218 selected_frame
= frame
;
11222 /* Update the tool-bar item list for frame F. This has to be done
11223 before we start to fill in any display lines. Called from
11224 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11225 and restore it here. */
11228 update_tool_bar (struct frame
*f
, int save_match_data
)
11230 #if defined (USE_GTK) || defined (HAVE_NS)
11231 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11233 int do_update
= WINDOWP (f
->tool_bar_window
)
11234 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11239 Lisp_Object window
;
11242 window
= FRAME_SELECTED_WINDOW (f
);
11243 w
= XWINDOW (window
);
11245 /* If the user has switched buffers or windows, we need to
11246 recompute to reflect the new bindings. But we'll
11247 recompute when update_mode_lines is set too; that means
11248 that people can use force-mode-line-update to request
11249 that the menu bar be recomputed. The adverse effect on
11250 the rest of the redisplay algorithm is about the same as
11251 windows_or_buffers_changed anyway. */
11252 if (windows_or_buffers_changed
11253 || !NILP (w
->update_mode_line
)
11254 || update_mode_lines
11255 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11256 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11257 != !NILP (w
->last_had_star
))
11258 || ((!NILP (Vtransient_mark_mode
)
11259 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11260 != !NILP (w
->region_showing
)))
11262 struct buffer
*prev
= current_buffer
;
11263 int count
= SPECPDL_INDEX ();
11264 Lisp_Object frame
, new_tool_bar
;
11265 int new_n_tool_bar
;
11266 struct gcpro gcpro1
;
11268 /* Set current_buffer to the buffer of the selected
11269 window of the frame, so that we get the right local
11271 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11273 /* Save match data, if we must. */
11274 if (save_match_data
)
11275 record_unwind_save_match_data ();
11277 /* Make sure that we don't accidentally use bogus keymaps. */
11278 if (NILP (Voverriding_local_map_menu_flag
))
11280 specbind (Qoverriding_terminal_local_map
, Qnil
);
11281 specbind (Qoverriding_local_map
, Qnil
);
11284 GCPRO1 (new_tool_bar
);
11286 /* We must temporarily set the selected frame to this frame
11287 before calling tool_bar_items, because the calculation of
11288 the tool-bar keymap uses the selected frame (see
11289 `tool-bar-make-keymap' in tool-bar.el). */
11290 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11291 XSETFRAME (frame
, f
);
11292 selected_frame
= frame
;
11294 /* Build desired tool-bar items from keymaps. */
11295 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11298 /* Redisplay the tool-bar if we changed it. */
11299 if (new_n_tool_bar
!= f
->n_tool_bar_items
11300 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11302 /* Redisplay that happens asynchronously due to an expose event
11303 may access f->tool_bar_items. Make sure we update both
11304 variables within BLOCK_INPUT so no such event interrupts. */
11306 f
->tool_bar_items
= new_tool_bar
;
11307 f
->n_tool_bar_items
= new_n_tool_bar
;
11308 w
->update_mode_line
= Qt
;
11314 unbind_to (count
, Qnil
);
11315 set_buffer_internal_1 (prev
);
11321 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11322 F's desired tool-bar contents. F->tool_bar_items must have
11323 been set up previously by calling prepare_menu_bars. */
11326 build_desired_tool_bar_string (struct frame
*f
)
11328 int i
, size
, size_needed
;
11329 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11330 Lisp_Object image
, plist
, props
;
11332 image
= plist
= props
= Qnil
;
11333 GCPRO3 (image
, plist
, props
);
11335 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11336 Otherwise, make a new string. */
11338 /* The size of the string we might be able to reuse. */
11339 size
= (STRINGP (f
->desired_tool_bar_string
)
11340 ? SCHARS (f
->desired_tool_bar_string
)
11343 /* We need one space in the string for each image. */
11344 size_needed
= f
->n_tool_bar_items
;
11346 /* Reuse f->desired_tool_bar_string, if possible. */
11347 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11348 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11349 make_number (' '));
11352 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11353 Fremove_text_properties (make_number (0), make_number (size
),
11354 props
, f
->desired_tool_bar_string
);
11357 /* Put a `display' property on the string for the images to display,
11358 put a `menu_item' property on tool-bar items with a value that
11359 is the index of the item in F's tool-bar item vector. */
11360 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11362 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11364 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11365 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11366 int hmargin
, vmargin
, relief
, idx
, end
;
11368 /* If image is a vector, choose the image according to the
11370 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11371 if (VECTORP (image
))
11375 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11376 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11379 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11380 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11382 xassert (ASIZE (image
) >= idx
);
11383 image
= AREF (image
, idx
);
11388 /* Ignore invalid image specifications. */
11389 if (!valid_image_p (image
))
11392 /* Display the tool-bar button pressed, or depressed. */
11393 plist
= Fcopy_sequence (XCDR (image
));
11395 /* Compute margin and relief to draw. */
11396 relief
= (tool_bar_button_relief
>= 0
11397 ? tool_bar_button_relief
11398 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11399 hmargin
= vmargin
= relief
;
11401 if (INTEGERP (Vtool_bar_button_margin
)
11402 && XINT (Vtool_bar_button_margin
) > 0)
11404 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11405 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11407 else if (CONSP (Vtool_bar_button_margin
))
11409 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
11410 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
11411 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11413 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
11414 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
11415 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11418 if (auto_raise_tool_bar_buttons_p
)
11420 /* Add a `:relief' property to the image spec if the item is
11424 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11431 /* If image is selected, display it pressed, i.e. with a
11432 negative relief. If it's not selected, display it with a
11434 plist
= Fplist_put (plist
, QCrelief
,
11436 ? make_number (-relief
)
11437 : make_number (relief
)));
11442 /* Put a margin around the image. */
11443 if (hmargin
|| vmargin
)
11445 if (hmargin
== vmargin
)
11446 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11448 plist
= Fplist_put (plist
, QCmargin
,
11449 Fcons (make_number (hmargin
),
11450 make_number (vmargin
)));
11453 /* If button is not enabled, and we don't have special images
11454 for the disabled state, make the image appear disabled by
11455 applying an appropriate algorithm to it. */
11456 if (!enabled_p
&& idx
< 0)
11457 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11459 /* Put a `display' text property on the string for the image to
11460 display. Put a `menu-item' property on the string that gives
11461 the start of this item's properties in the tool-bar items
11463 image
= Fcons (Qimage
, plist
);
11464 props
= list4 (Qdisplay
, image
,
11465 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11467 /* Let the last image hide all remaining spaces in the tool bar
11468 string. The string can be longer than needed when we reuse a
11469 previous string. */
11470 if (i
+ 1 == f
->n_tool_bar_items
)
11471 end
= SCHARS (f
->desired_tool_bar_string
);
11474 Fadd_text_properties (make_number (i
), make_number (end
),
11475 props
, f
->desired_tool_bar_string
);
11483 /* Display one line of the tool-bar of frame IT->f.
11485 HEIGHT specifies the desired height of the tool-bar line.
11486 If the actual height of the glyph row is less than HEIGHT, the
11487 row's height is increased to HEIGHT, and the icons are centered
11488 vertically in the new height.
11490 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11491 count a final empty row in case the tool-bar width exactly matches
11496 display_tool_bar_line (struct it
*it
, int height
)
11498 struct glyph_row
*row
= it
->glyph_row
;
11499 int max_x
= it
->last_visible_x
;
11500 struct glyph
*last
;
11502 prepare_desired_row (row
);
11503 row
->y
= it
->current_y
;
11505 /* Note that this isn't made use of if the face hasn't a box,
11506 so there's no need to check the face here. */
11507 it
->start_of_box_run_p
= 1;
11509 while (it
->current_x
< max_x
)
11511 int x
, n_glyphs_before
, i
, nglyphs
;
11512 struct it it_before
;
11514 /* Get the next display element. */
11515 if (!get_next_display_element (it
))
11517 /* Don't count empty row if we are counting needed tool-bar lines. */
11518 if (height
< 0 && !it
->hpos
)
11523 /* Produce glyphs. */
11524 n_glyphs_before
= row
->used
[TEXT_AREA
];
11527 PRODUCE_GLYPHS (it
);
11529 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11531 x
= it_before
.current_x
;
11532 while (i
< nglyphs
)
11534 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11536 if (x
+ glyph
->pixel_width
> max_x
)
11538 /* Glyph doesn't fit on line. Backtrack. */
11539 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11541 /* If this is the only glyph on this line, it will never fit on the
11542 tool-bar, so skip it. But ensure there is at least one glyph,
11543 so we don't accidentally disable the tool-bar. */
11544 if (n_glyphs_before
== 0
11545 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11551 x
+= glyph
->pixel_width
;
11555 /* Stop at line end. */
11556 if (ITERATOR_AT_END_OF_LINE_P (it
))
11559 set_iterator_to_next (it
, 1);
11564 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11566 /* Use default face for the border below the tool bar.
11568 FIXME: When auto-resize-tool-bars is grow-only, there is
11569 no additional border below the possibly empty tool-bar lines.
11570 So to make the extra empty lines look "normal", we have to
11571 use the tool-bar face for the border too. */
11572 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11573 it
->face_id
= DEFAULT_FACE_ID
;
11575 extend_face_to_end_of_line (it
);
11576 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11577 last
->right_box_line_p
= 1;
11578 if (last
== row
->glyphs
[TEXT_AREA
])
11579 last
->left_box_line_p
= 1;
11581 /* Make line the desired height and center it vertically. */
11582 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11584 /* Don't add more than one line height. */
11585 height
%= FRAME_LINE_HEIGHT (it
->f
);
11586 it
->max_ascent
+= height
/ 2;
11587 it
->max_descent
+= (height
+ 1) / 2;
11590 compute_line_metrics (it
);
11592 /* If line is empty, make it occupy the rest of the tool-bar. */
11593 if (!row
->displays_text_p
)
11595 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11596 row
->visible_height
= row
->height
;
11597 row
->ascent
= row
->phys_ascent
= 0;
11598 row
->extra_line_spacing
= 0;
11601 row
->full_width_p
= 1;
11602 row
->continued_p
= 0;
11603 row
->truncated_on_left_p
= 0;
11604 row
->truncated_on_right_p
= 0;
11606 it
->current_x
= it
->hpos
= 0;
11607 it
->current_y
+= row
->height
;
11613 /* Max tool-bar height. */
11615 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11616 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11618 /* Value is the number of screen lines needed to make all tool-bar
11619 items of frame F visible. The number of actual rows needed is
11620 returned in *N_ROWS if non-NULL. */
11623 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11625 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11627 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11628 the desired matrix, so use (unused) mode-line row as temporary row to
11629 avoid destroying the first tool-bar row. */
11630 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11632 /* Initialize an iterator for iteration over
11633 F->desired_tool_bar_string in the tool-bar window of frame F. */
11634 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11635 it
.first_visible_x
= 0;
11636 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11637 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11638 it
.paragraph_embedding
= L2R
;
11640 while (!ITERATOR_AT_END_P (&it
))
11642 clear_glyph_row (temp_row
);
11643 it
.glyph_row
= temp_row
;
11644 display_tool_bar_line (&it
, -1);
11646 clear_glyph_row (temp_row
);
11648 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11650 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11652 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11656 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11658 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11659 (Lisp_Object frame
)
11666 frame
= selected_frame
;
11668 CHECK_FRAME (frame
);
11669 f
= XFRAME (frame
);
11671 if (WINDOWP (f
->tool_bar_window
)
11672 && (w
= XWINDOW (f
->tool_bar_window
),
11673 WINDOW_TOTAL_LINES (w
) > 0))
11675 update_tool_bar (f
, 1);
11676 if (f
->n_tool_bar_items
)
11678 build_desired_tool_bar_string (f
);
11679 nlines
= tool_bar_lines_needed (f
, NULL
);
11683 return make_number (nlines
);
11687 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11688 height should be changed. */
11691 redisplay_tool_bar (struct frame
*f
)
11695 struct glyph_row
*row
;
11697 #if defined (USE_GTK) || defined (HAVE_NS)
11698 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11699 update_frame_tool_bar (f
);
11703 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11704 do anything. This means you must start with tool-bar-lines
11705 non-zero to get the auto-sizing effect. Or in other words, you
11706 can turn off tool-bars by specifying tool-bar-lines zero. */
11707 if (!WINDOWP (f
->tool_bar_window
)
11708 || (w
= XWINDOW (f
->tool_bar_window
),
11709 WINDOW_TOTAL_LINES (w
) == 0))
11712 /* Set up an iterator for the tool-bar window. */
11713 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11714 it
.first_visible_x
= 0;
11715 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11716 row
= it
.glyph_row
;
11718 /* Build a string that represents the contents of the tool-bar. */
11719 build_desired_tool_bar_string (f
);
11720 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11721 /* FIXME: This should be controlled by a user option. But it
11722 doesn't make sense to have an R2L tool bar if the menu bar cannot
11723 be drawn also R2L, and making the menu bar R2L is tricky due
11724 toolkit-specific code that implements it. If an R2L tool bar is
11725 ever supported, display_tool_bar_line should also be augmented to
11726 call unproduce_glyphs like display_line and display_string
11728 it
.paragraph_embedding
= L2R
;
11730 if (f
->n_tool_bar_rows
== 0)
11734 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11735 nlines
!= WINDOW_TOTAL_LINES (w
)))
11738 int old_height
= WINDOW_TOTAL_LINES (w
);
11740 XSETFRAME (frame
, f
);
11741 Fmodify_frame_parameters (frame
,
11742 Fcons (Fcons (Qtool_bar_lines
,
11743 make_number (nlines
)),
11745 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11747 clear_glyph_matrix (w
->desired_matrix
);
11748 fonts_changed_p
= 1;
11754 /* Display as many lines as needed to display all tool-bar items. */
11756 if (f
->n_tool_bar_rows
> 0)
11758 int border
, rows
, height
, extra
;
11760 if (INTEGERP (Vtool_bar_border
))
11761 border
= XINT (Vtool_bar_border
);
11762 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11763 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11764 else if (EQ (Vtool_bar_border
, Qborder_width
))
11765 border
= f
->border_width
;
11771 rows
= f
->n_tool_bar_rows
;
11772 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11773 extra
= it
.last_visible_y
- border
- height
* rows
;
11775 while (it
.current_y
< it
.last_visible_y
)
11778 if (extra
> 0 && rows
-- > 0)
11780 h
= (extra
+ rows
- 1) / rows
;
11783 display_tool_bar_line (&it
, height
+ h
);
11788 while (it
.current_y
< it
.last_visible_y
)
11789 display_tool_bar_line (&it
, 0);
11792 /* It doesn't make much sense to try scrolling in the tool-bar
11793 window, so don't do it. */
11794 w
->desired_matrix
->no_scrolling_p
= 1;
11795 w
->must_be_updated_p
= 1;
11797 if (!NILP (Vauto_resize_tool_bars
))
11799 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11800 int change_height_p
= 0;
11802 /* If we couldn't display everything, change the tool-bar's
11803 height if there is room for more. */
11804 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11805 && it
.current_y
< max_tool_bar_height
)
11806 change_height_p
= 1;
11808 row
= it
.glyph_row
- 1;
11810 /* If there are blank lines at the end, except for a partially
11811 visible blank line at the end that is smaller than
11812 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11813 if (!row
->displays_text_p
11814 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11815 change_height_p
= 1;
11817 /* If row displays tool-bar items, but is partially visible,
11818 change the tool-bar's height. */
11819 if (row
->displays_text_p
11820 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11821 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11822 change_height_p
= 1;
11824 /* Resize windows as needed by changing the `tool-bar-lines'
11825 frame parameter. */
11826 if (change_height_p
)
11829 int old_height
= WINDOW_TOTAL_LINES (w
);
11831 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11833 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11834 && !f
->minimize_tool_bar_window_p
)
11835 ? (nlines
> old_height
)
11836 : (nlines
!= old_height
));
11837 f
->minimize_tool_bar_window_p
= 0;
11839 if (change_height_p
)
11841 XSETFRAME (frame
, f
);
11842 Fmodify_frame_parameters (frame
,
11843 Fcons (Fcons (Qtool_bar_lines
,
11844 make_number (nlines
)),
11846 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11848 clear_glyph_matrix (w
->desired_matrix
);
11849 f
->n_tool_bar_rows
= nrows
;
11850 fonts_changed_p
= 1;
11857 f
->minimize_tool_bar_window_p
= 0;
11862 /* Get information about the tool-bar item which is displayed in GLYPH
11863 on frame F. Return in *PROP_IDX the index where tool-bar item
11864 properties start in F->tool_bar_items. Value is zero if
11865 GLYPH doesn't display a tool-bar item. */
11868 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11874 /* This function can be called asynchronously, which means we must
11875 exclude any possibility that Fget_text_property signals an
11877 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11878 charpos
= max (0, charpos
);
11880 /* Get the text property `menu-item' at pos. The value of that
11881 property is the start index of this item's properties in
11882 F->tool_bar_items. */
11883 prop
= Fget_text_property (make_number (charpos
),
11884 Qmenu_item
, f
->current_tool_bar_string
);
11885 if (INTEGERP (prop
))
11887 *prop_idx
= XINT (prop
);
11897 /* Get information about the tool-bar item at position X/Y on frame F.
11898 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11899 the current matrix of the tool-bar window of F, or NULL if not
11900 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11901 item in F->tool_bar_items. Value is
11903 -1 if X/Y is not on a tool-bar item
11904 0 if X/Y is on the same item that was highlighted before.
11908 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11909 int *hpos
, int *vpos
, int *prop_idx
)
11911 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11912 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11915 /* Find the glyph under X/Y. */
11916 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11917 if (*glyph
== NULL
)
11920 /* Get the start of this tool-bar item's properties in
11921 f->tool_bar_items. */
11922 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11925 /* Is mouse on the highlighted item? */
11926 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11927 && *vpos
>= hlinfo
->mouse_face_beg_row
11928 && *vpos
<= hlinfo
->mouse_face_end_row
11929 && (*vpos
> hlinfo
->mouse_face_beg_row
11930 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11931 && (*vpos
< hlinfo
->mouse_face_end_row
11932 || *hpos
< hlinfo
->mouse_face_end_col
11933 || hlinfo
->mouse_face_past_end
))
11941 Handle mouse button event on the tool-bar of frame F, at
11942 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11943 0 for button release. MODIFIERS is event modifiers for button
11947 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11948 unsigned int modifiers
)
11950 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11951 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11952 int hpos
, vpos
, prop_idx
;
11953 struct glyph
*glyph
;
11954 Lisp_Object enabled_p
;
11956 /* If not on the highlighted tool-bar item, return. */
11957 frame_to_window_pixel_xy (w
, &x
, &y
);
11958 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11961 /* If item is disabled, do nothing. */
11962 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11963 if (NILP (enabled_p
))
11968 /* Show item in pressed state. */
11969 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11970 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11971 last_tool_bar_item
= prop_idx
;
11975 Lisp_Object key
, frame
;
11976 struct input_event event
;
11977 EVENT_INIT (event
);
11979 /* Show item in released state. */
11980 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11981 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11983 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11985 XSETFRAME (frame
, f
);
11986 event
.kind
= TOOL_BAR_EVENT
;
11987 event
.frame_or_window
= frame
;
11989 kbd_buffer_store_event (&event
);
11991 event
.kind
= TOOL_BAR_EVENT
;
11992 event
.frame_or_window
= frame
;
11994 event
.modifiers
= modifiers
;
11995 kbd_buffer_store_event (&event
);
11996 last_tool_bar_item
= -1;
12001 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12002 tool-bar window-relative coordinates X/Y. Called from
12003 note_mouse_highlight. */
12006 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12008 Lisp_Object window
= f
->tool_bar_window
;
12009 struct window
*w
= XWINDOW (window
);
12010 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12011 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12013 struct glyph
*glyph
;
12014 struct glyph_row
*row
;
12016 Lisp_Object enabled_p
;
12018 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12019 int mouse_down_p
, rc
;
12021 /* Function note_mouse_highlight is called with negative X/Y
12022 values when mouse moves outside of the frame. */
12023 if (x
<= 0 || y
<= 0)
12025 clear_mouse_face (hlinfo
);
12029 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12032 /* Not on tool-bar item. */
12033 clear_mouse_face (hlinfo
);
12037 /* On same tool-bar item as before. */
12038 goto set_help_echo
;
12040 clear_mouse_face (hlinfo
);
12042 /* Mouse is down, but on different tool-bar item? */
12043 mouse_down_p
= (dpyinfo
->grabbed
12044 && f
== last_mouse_frame
12045 && FRAME_LIVE_P (f
));
12047 && last_tool_bar_item
!= prop_idx
)
12050 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12051 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12053 /* If tool-bar item is not enabled, don't highlight it. */
12054 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12055 if (!NILP (enabled_p
))
12057 /* Compute the x-position of the glyph. In front and past the
12058 image is a space. We include this in the highlighted area. */
12059 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12060 for (i
= x
= 0; i
< hpos
; ++i
)
12061 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12063 /* Record this as the current active region. */
12064 hlinfo
->mouse_face_beg_col
= hpos
;
12065 hlinfo
->mouse_face_beg_row
= vpos
;
12066 hlinfo
->mouse_face_beg_x
= x
;
12067 hlinfo
->mouse_face_beg_y
= row
->y
;
12068 hlinfo
->mouse_face_past_end
= 0;
12070 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12071 hlinfo
->mouse_face_end_row
= vpos
;
12072 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12073 hlinfo
->mouse_face_end_y
= row
->y
;
12074 hlinfo
->mouse_face_window
= window
;
12075 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12077 /* Display it as active. */
12078 show_mouse_face (hlinfo
, draw
);
12079 hlinfo
->mouse_face_image_state
= draw
;
12084 /* Set help_echo_string to a help string to display for this tool-bar item.
12085 XTread_socket does the rest. */
12086 help_echo_object
= help_echo_window
= Qnil
;
12087 help_echo_pos
= -1;
12088 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12089 if (NILP (help_echo_string
))
12090 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12093 #endif /* HAVE_WINDOW_SYSTEM */
12097 /************************************************************************
12098 Horizontal scrolling
12099 ************************************************************************/
12101 static int hscroll_window_tree (Lisp_Object
);
12102 static int hscroll_windows (Lisp_Object
);
12104 /* For all leaf windows in the window tree rooted at WINDOW, set their
12105 hscroll value so that PT is (i) visible in the window, and (ii) so
12106 that it is not within a certain margin at the window's left and
12107 right border. Value is non-zero if any window's hscroll has been
12111 hscroll_window_tree (Lisp_Object window
)
12113 int hscrolled_p
= 0;
12114 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12115 int hscroll_step_abs
= 0;
12116 double hscroll_step_rel
= 0;
12118 if (hscroll_relative_p
)
12120 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12121 if (hscroll_step_rel
< 0)
12123 hscroll_relative_p
= 0;
12124 hscroll_step_abs
= 0;
12127 else if (INTEGERP (Vhscroll_step
))
12129 hscroll_step_abs
= XINT (Vhscroll_step
);
12130 if (hscroll_step_abs
< 0)
12131 hscroll_step_abs
= 0;
12134 hscroll_step_abs
= 0;
12136 while (WINDOWP (window
))
12138 struct window
*w
= XWINDOW (window
);
12140 if (WINDOWP (w
->hchild
))
12141 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12142 else if (WINDOWP (w
->vchild
))
12143 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12144 else if (w
->cursor
.vpos
>= 0)
12147 int text_area_width
;
12148 struct glyph_row
*current_cursor_row
12149 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12150 struct glyph_row
*desired_cursor_row
12151 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12152 struct glyph_row
*cursor_row
12153 = (desired_cursor_row
->enabled_p
12154 ? desired_cursor_row
12155 : current_cursor_row
);
12156 int row_r2l_p
= cursor_row
->reversed_p
;
12158 text_area_width
= window_box_width (w
, TEXT_AREA
);
12160 /* Scroll when cursor is inside this scroll margin. */
12161 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12163 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12164 /* For left-to-right rows, hscroll when cursor is either
12165 (i) inside the right hscroll margin, or (ii) if it is
12166 inside the left margin and the window is already
12169 && ((XFASTINT (w
->hscroll
)
12170 && w
->cursor
.x
<= h_margin
)
12171 || (cursor_row
->enabled_p
12172 && cursor_row
->truncated_on_right_p
12173 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12174 /* For right-to-left rows, the logic is similar,
12175 except that rules for scrolling to left and right
12176 are reversed. E.g., if cursor.x <= h_margin, we
12177 need to hscroll "to the right" unconditionally,
12178 and that will scroll the screen to the left so as
12179 to reveal the next portion of the row. */
12181 && ((cursor_row
->enabled_p
12182 /* FIXME: It is confusing to set the
12183 truncated_on_right_p flag when R2L rows
12184 are actually truncated on the left. */
12185 && cursor_row
->truncated_on_right_p
12186 && w
->cursor
.x
<= h_margin
)
12187 || (XFASTINT (w
->hscroll
)
12188 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12192 struct buffer
*saved_current_buffer
;
12196 /* Find point in a display of infinite width. */
12197 saved_current_buffer
= current_buffer
;
12198 current_buffer
= XBUFFER (w
->buffer
);
12200 if (w
== XWINDOW (selected_window
))
12204 pt
= marker_position (w
->pointm
);
12205 pt
= max (BEGV
, pt
);
12209 /* Move iterator to pt starting at cursor_row->start in
12210 a line with infinite width. */
12211 init_to_row_start (&it
, w
, cursor_row
);
12212 it
.last_visible_x
= INFINITY
;
12213 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12214 current_buffer
= saved_current_buffer
;
12216 /* Position cursor in window. */
12217 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12218 hscroll
= max (0, (it
.current_x
12219 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12220 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12221 : (text_area_width
/ 2))))
12222 / FRAME_COLUMN_WIDTH (it
.f
);
12223 else if ((!row_r2l_p
12224 && w
->cursor
.x
>= text_area_width
- h_margin
)
12225 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12227 if (hscroll_relative_p
)
12228 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12231 wanted_x
= text_area_width
12232 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12235 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12239 if (hscroll_relative_p
)
12240 wanted_x
= text_area_width
* hscroll_step_rel
12243 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12246 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12248 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
12250 /* Don't prevent redisplay optimizations if hscroll
12251 hasn't changed, as it will unnecessarily slow down
12253 if (XFASTINT (w
->hscroll
) != hscroll
)
12255 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12256 w
->hscroll
= make_number (hscroll
);
12265 /* Value is non-zero if hscroll of any leaf window has been changed. */
12266 return hscrolled_p
;
12270 /* Set hscroll so that cursor is visible and not inside horizontal
12271 scroll margins for all windows in the tree rooted at WINDOW. See
12272 also hscroll_window_tree above. Value is non-zero if any window's
12273 hscroll has been changed. If it has, desired matrices on the frame
12274 of WINDOW are cleared. */
12277 hscroll_windows (Lisp_Object window
)
12279 int hscrolled_p
= hscroll_window_tree (window
);
12281 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12282 return hscrolled_p
;
12287 /************************************************************************
12289 ************************************************************************/
12291 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12292 to a non-zero value. This is sometimes handy to have in a debugger
12297 /* First and last unchanged row for try_window_id. */
12299 static int debug_first_unchanged_at_end_vpos
;
12300 static int debug_last_unchanged_at_beg_vpos
;
12302 /* Delta vpos and y. */
12304 static int debug_dvpos
, debug_dy
;
12306 /* Delta in characters and bytes for try_window_id. */
12308 static EMACS_INT debug_delta
, debug_delta_bytes
;
12310 /* Values of window_end_pos and window_end_vpos at the end of
12313 static EMACS_INT debug_end_vpos
;
12315 /* Append a string to W->desired_matrix->method. FMT is a printf
12316 format string. If trace_redisplay_p is non-zero also printf the
12317 resulting string to stderr. */
12319 static void debug_method_add (struct window
*, char const *, ...)
12320 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12323 debug_method_add (struct window
*w
, char const *fmt
, ...)
12326 char *method
= w
->desired_matrix
->method
;
12327 int len
= strlen (method
);
12328 int size
= sizeof w
->desired_matrix
->method
;
12329 int remaining
= size
- len
- 1;
12332 va_start (ap
, fmt
);
12333 vsprintf (buffer
, fmt
, ap
);
12335 if (len
&& remaining
)
12338 --remaining
, ++len
;
12341 strncpy (method
+ len
, buffer
, remaining
);
12343 if (trace_redisplay_p
)
12344 fprintf (stderr
, "%p (%s): %s\n",
12346 ((BUFFERP (w
->buffer
)
12347 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12348 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12353 #endif /* GLYPH_DEBUG */
12356 /* Value is non-zero if all changes in window W, which displays
12357 current_buffer, are in the text between START and END. START is a
12358 buffer position, END is given as a distance from Z. Used in
12359 redisplay_internal for display optimization. */
12362 text_outside_line_unchanged_p (struct window
*w
,
12363 EMACS_INT start
, EMACS_INT end
)
12365 int unchanged_p
= 1;
12367 /* If text or overlays have changed, see where. */
12368 if (XFASTINT (w
->last_modified
) < MODIFF
12369 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12371 /* Gap in the line? */
12372 if (GPT
< start
|| Z
- GPT
< end
)
12375 /* Changes start in front of the line, or end after it? */
12377 && (BEG_UNCHANGED
< start
- 1
12378 || END_UNCHANGED
< end
))
12381 /* If selective display, can't optimize if changes start at the
12382 beginning of the line. */
12384 && INTEGERP (BVAR (current_buffer
, selective_display
))
12385 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12386 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12389 /* If there are overlays at the start or end of the line, these
12390 may have overlay strings with newlines in them. A change at
12391 START, for instance, may actually concern the display of such
12392 overlay strings as well, and they are displayed on different
12393 lines. So, quickly rule out this case. (For the future, it
12394 might be desirable to implement something more telling than
12395 just BEG/END_UNCHANGED.) */
12398 if (BEG
+ BEG_UNCHANGED
== start
12399 && overlay_touches_p (start
))
12401 if (END_UNCHANGED
== end
12402 && overlay_touches_p (Z
- end
))
12406 /* Under bidi reordering, adding or deleting a character in the
12407 beginning of a paragraph, before the first strong directional
12408 character, can change the base direction of the paragraph (unless
12409 the buffer specifies a fixed paragraph direction), which will
12410 require to redisplay the whole paragraph. It might be worthwhile
12411 to find the paragraph limits and widen the range of redisplayed
12412 lines to that, but for now just give up this optimization. */
12413 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12414 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12418 return unchanged_p
;
12422 /* Do a frame update, taking possible shortcuts into account. This is
12423 the main external entry point for redisplay.
12425 If the last redisplay displayed an echo area message and that message
12426 is no longer requested, we clear the echo area or bring back the
12427 mini-buffer if that is in use. */
12432 redisplay_internal ();
12437 overlay_arrow_string_or_property (Lisp_Object var
)
12441 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12444 return Voverlay_arrow_string
;
12447 /* Return 1 if there are any overlay-arrows in current_buffer. */
12449 overlay_arrow_in_current_buffer_p (void)
12453 for (vlist
= Voverlay_arrow_variable_list
;
12455 vlist
= XCDR (vlist
))
12457 Lisp_Object var
= XCAR (vlist
);
12460 if (!SYMBOLP (var
))
12462 val
= find_symbol_value (var
);
12464 && current_buffer
== XMARKER (val
)->buffer
)
12471 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12475 overlay_arrows_changed_p (void)
12479 for (vlist
= Voverlay_arrow_variable_list
;
12481 vlist
= XCDR (vlist
))
12483 Lisp_Object var
= XCAR (vlist
);
12484 Lisp_Object val
, pstr
;
12486 if (!SYMBOLP (var
))
12488 val
= find_symbol_value (var
);
12489 if (!MARKERP (val
))
12491 if (! EQ (COERCE_MARKER (val
),
12492 Fget (var
, Qlast_arrow_position
))
12493 || ! (pstr
= overlay_arrow_string_or_property (var
),
12494 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12500 /* Mark overlay arrows to be updated on next redisplay. */
12503 update_overlay_arrows (int up_to_date
)
12507 for (vlist
= Voverlay_arrow_variable_list
;
12509 vlist
= XCDR (vlist
))
12511 Lisp_Object var
= XCAR (vlist
);
12513 if (!SYMBOLP (var
))
12516 if (up_to_date
> 0)
12518 Lisp_Object val
= find_symbol_value (var
);
12519 Fput (var
, Qlast_arrow_position
,
12520 COERCE_MARKER (val
));
12521 Fput (var
, Qlast_arrow_string
,
12522 overlay_arrow_string_or_property (var
));
12524 else if (up_to_date
< 0
12525 || !NILP (Fget (var
, Qlast_arrow_position
)))
12527 Fput (var
, Qlast_arrow_position
, Qt
);
12528 Fput (var
, Qlast_arrow_string
, Qt
);
12534 /* Return overlay arrow string to display at row.
12535 Return integer (bitmap number) for arrow bitmap in left fringe.
12536 Return nil if no overlay arrow. */
12539 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12543 for (vlist
= Voverlay_arrow_variable_list
;
12545 vlist
= XCDR (vlist
))
12547 Lisp_Object var
= XCAR (vlist
);
12550 if (!SYMBOLP (var
))
12553 val
= find_symbol_value (var
);
12556 && current_buffer
== XMARKER (val
)->buffer
12557 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12559 if (FRAME_WINDOW_P (it
->f
)
12560 /* FIXME: if ROW->reversed_p is set, this should test
12561 the right fringe, not the left one. */
12562 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12564 #ifdef HAVE_WINDOW_SYSTEM
12565 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12568 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12569 return make_number (fringe_bitmap
);
12572 return make_number (-1); /* Use default arrow bitmap */
12574 return overlay_arrow_string_or_property (var
);
12581 /* Return 1 if point moved out of or into a composition. Otherwise
12582 return 0. PREV_BUF and PREV_PT are the last point buffer and
12583 position. BUF and PT are the current point buffer and position. */
12586 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
12587 struct buffer
*buf
, EMACS_INT pt
)
12589 EMACS_INT start
, end
;
12591 Lisp_Object buffer
;
12593 XSETBUFFER (buffer
, buf
);
12594 /* Check a composition at the last point if point moved within the
12596 if (prev_buf
== buf
)
12599 /* Point didn't move. */
12602 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12603 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12604 && COMPOSITION_VALID_P (start
, end
, prop
)
12605 && start
< prev_pt
&& end
> prev_pt
)
12606 /* The last point was within the composition. Return 1 iff
12607 point moved out of the composition. */
12608 return (pt
<= start
|| pt
>= end
);
12611 /* Check a composition at the current point. */
12612 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12613 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12614 && COMPOSITION_VALID_P (start
, end
, prop
)
12615 && start
< pt
&& end
> pt
);
12619 /* Reconsider the setting of B->clip_changed which is displayed
12623 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12625 if (b
->clip_changed
12626 && !NILP (w
->window_end_valid
)
12627 && w
->current_matrix
->buffer
== b
12628 && w
->current_matrix
->zv
== BUF_ZV (b
)
12629 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12630 b
->clip_changed
= 0;
12632 /* If display wasn't paused, and W is not a tool bar window, see if
12633 point has been moved into or out of a composition. In that case,
12634 we set b->clip_changed to 1 to force updating the screen. If
12635 b->clip_changed has already been set to 1, we can skip this
12637 if (!b
->clip_changed
12638 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12642 if (w
== XWINDOW (selected_window
))
12645 pt
= marker_position (w
->pointm
);
12647 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12648 || pt
!= XINT (w
->last_point
))
12649 && check_point_in_composition (w
->current_matrix
->buffer
,
12650 XINT (w
->last_point
),
12651 XBUFFER (w
->buffer
), pt
))
12652 b
->clip_changed
= 1;
12657 /* Select FRAME to forward the values of frame-local variables into C
12658 variables so that the redisplay routines can access those values
12662 select_frame_for_redisplay (Lisp_Object frame
)
12664 Lisp_Object tail
, tem
;
12665 Lisp_Object old
= selected_frame
;
12666 struct Lisp_Symbol
*sym
;
12668 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12670 selected_frame
= frame
;
12673 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12674 if (CONSP (XCAR (tail
))
12675 && (tem
= XCAR (XCAR (tail
)),
12677 && (sym
= indirect_variable (XSYMBOL (tem
)),
12678 sym
->redirect
== SYMBOL_LOCALIZED
)
12679 && sym
->val
.blv
->frame_local
)
12680 /* Use find_symbol_value rather than Fsymbol_value
12681 to avoid an error if it is void. */
12682 find_symbol_value (tem
);
12683 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12687 #define STOP_POLLING \
12688 do { if (! polling_stopped_here) stop_polling (); \
12689 polling_stopped_here = 1; } while (0)
12691 #define RESUME_POLLING \
12692 do { if (polling_stopped_here) start_polling (); \
12693 polling_stopped_here = 0; } while (0)
12696 /* Perhaps in the future avoid recentering windows if it
12697 is not necessary; currently that causes some problems. */
12700 redisplay_internal (void)
12702 struct window
*w
= XWINDOW (selected_window
);
12706 int must_finish
= 0;
12707 struct text_pos tlbufpos
, tlendpos
;
12708 int number_of_visible_frames
;
12711 int polling_stopped_here
= 0;
12712 Lisp_Object old_frame
= selected_frame
;
12714 /* Non-zero means redisplay has to consider all windows on all
12715 frames. Zero means, only selected_window is considered. */
12716 int consider_all_windows_p
;
12718 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12720 /* No redisplay if running in batch mode or frame is not yet fully
12721 initialized, or redisplay is explicitly turned off by setting
12722 Vinhibit_redisplay. */
12723 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12724 || !NILP (Vinhibit_redisplay
))
12727 /* Don't examine these until after testing Vinhibit_redisplay.
12728 When Emacs is shutting down, perhaps because its connection to
12729 X has dropped, we should not look at them at all. */
12730 fr
= XFRAME (w
->frame
);
12731 sf
= SELECTED_FRAME ();
12733 if (!fr
->glyphs_initialized_p
)
12736 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12737 if (popup_activated ())
12741 /* I don't think this happens but let's be paranoid. */
12742 if (redisplaying_p
)
12745 /* Record a function that resets redisplaying_p to its old value
12746 when we leave this function. */
12747 count
= SPECPDL_INDEX ();
12748 record_unwind_protect (unwind_redisplay
,
12749 Fcons (make_number (redisplaying_p
), selected_frame
));
12751 specbind (Qinhibit_free_realized_faces
, Qnil
);
12754 Lisp_Object tail
, frame
;
12756 FOR_EACH_FRAME (tail
, frame
)
12758 struct frame
*f
= XFRAME (frame
);
12759 f
->already_hscrolled_p
= 0;
12764 /* Remember the currently selected window. */
12767 if (!EQ (old_frame
, selected_frame
)
12768 && FRAME_LIVE_P (XFRAME (old_frame
)))
12769 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12770 selected_frame and selected_window to be temporarily out-of-sync so
12771 when we come back here via `goto retry', we need to resync because we
12772 may need to run Elisp code (via prepare_menu_bars). */
12773 select_frame_for_redisplay (old_frame
);
12776 reconsider_clip_changes (w
, current_buffer
);
12777 last_escape_glyph_frame
= NULL
;
12778 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12779 last_glyphless_glyph_frame
= NULL
;
12780 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12782 /* If new fonts have been loaded that make a glyph matrix adjustment
12783 necessary, do it. */
12784 if (fonts_changed_p
)
12786 adjust_glyphs (NULL
);
12787 ++windows_or_buffers_changed
;
12788 fonts_changed_p
= 0;
12791 /* If face_change_count is non-zero, init_iterator will free all
12792 realized faces, which includes the faces referenced from current
12793 matrices. So, we can't reuse current matrices in this case. */
12794 if (face_change_count
)
12795 ++windows_or_buffers_changed
;
12797 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12798 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12800 /* Since frames on a single ASCII terminal share the same
12801 display area, displaying a different frame means redisplay
12802 the whole thing. */
12803 windows_or_buffers_changed
++;
12804 SET_FRAME_GARBAGED (sf
);
12806 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12808 FRAME_TTY (sf
)->previous_frame
= sf
;
12811 /* Set the visible flags for all frames. Do this before checking
12812 for resized or garbaged frames; they want to know if their frames
12813 are visible. See the comment in frame.h for
12814 FRAME_SAMPLE_VISIBILITY. */
12816 Lisp_Object tail
, frame
;
12818 number_of_visible_frames
= 0;
12820 FOR_EACH_FRAME (tail
, frame
)
12822 struct frame
*f
= XFRAME (frame
);
12824 FRAME_SAMPLE_VISIBILITY (f
);
12825 if (FRAME_VISIBLE_P (f
))
12826 ++number_of_visible_frames
;
12827 clear_desired_matrices (f
);
12831 /* Notice any pending interrupt request to change frame size. */
12832 do_pending_window_change (1);
12834 /* do_pending_window_change could change the selected_window due to
12835 frame resizing which makes the selected window too small. */
12836 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12839 reconsider_clip_changes (w
, current_buffer
);
12842 /* Clear frames marked as garbaged. */
12843 if (frame_garbaged
)
12844 clear_garbaged_frames ();
12846 /* Build menubar and tool-bar items. */
12847 if (NILP (Vmemory_full
))
12848 prepare_menu_bars ();
12850 if (windows_or_buffers_changed
)
12851 update_mode_lines
++;
12853 /* Detect case that we need to write or remove a star in the mode line. */
12854 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12856 w
->update_mode_line
= Qt
;
12857 if (buffer_shared
> 1)
12858 update_mode_lines
++;
12861 /* Avoid invocation of point motion hooks by `current_column' below. */
12862 count1
= SPECPDL_INDEX ();
12863 specbind (Qinhibit_point_motion_hooks
, Qt
);
12865 /* If %c is in the mode line, update it if needed. */
12866 if (!NILP (w
->column_number_displayed
)
12867 /* This alternative quickly identifies a common case
12868 where no change is needed. */
12869 && !(PT
== XFASTINT (w
->last_point
)
12870 && XFASTINT (w
->last_modified
) >= MODIFF
12871 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12872 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12873 w
->update_mode_line
= Qt
;
12875 unbind_to (count1
, Qnil
);
12877 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12879 /* The variable buffer_shared is set in redisplay_window and
12880 indicates that we redisplay a buffer in different windows. See
12882 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12883 || cursor_type_changed
);
12885 /* If specs for an arrow have changed, do thorough redisplay
12886 to ensure we remove any arrow that should no longer exist. */
12887 if (overlay_arrows_changed_p ())
12888 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12890 /* Normally the message* functions will have already displayed and
12891 updated the echo area, but the frame may have been trashed, or
12892 the update may have been preempted, so display the echo area
12893 again here. Checking message_cleared_p captures the case that
12894 the echo area should be cleared. */
12895 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12896 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12897 || (message_cleared_p
12898 && minibuf_level
== 0
12899 /* If the mini-window is currently selected, this means the
12900 echo-area doesn't show through. */
12901 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12903 int window_height_changed_p
= echo_area_display (0);
12906 /* If we don't display the current message, don't clear the
12907 message_cleared_p flag, because, if we did, we wouldn't clear
12908 the echo area in the next redisplay which doesn't preserve
12910 if (!display_last_displayed_message_p
)
12911 message_cleared_p
= 0;
12913 if (fonts_changed_p
)
12915 else if (window_height_changed_p
)
12917 consider_all_windows_p
= 1;
12918 ++update_mode_lines
;
12919 ++windows_or_buffers_changed
;
12921 /* If window configuration was changed, frames may have been
12922 marked garbaged. Clear them or we will experience
12923 surprises wrt scrolling. */
12924 if (frame_garbaged
)
12925 clear_garbaged_frames ();
12928 else if (EQ (selected_window
, minibuf_window
)
12929 && (current_buffer
->clip_changed
12930 || XFASTINT (w
->last_modified
) < MODIFF
12931 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12932 && resize_mini_window (w
, 0))
12934 /* Resized active mini-window to fit the size of what it is
12935 showing if its contents might have changed. */
12937 /* FIXME: this causes all frames to be updated, which seems unnecessary
12938 since only the current frame needs to be considered. This function needs
12939 to be rewritten with two variables, consider_all_windows and
12940 consider_all_frames. */
12941 consider_all_windows_p
= 1;
12942 ++windows_or_buffers_changed
;
12943 ++update_mode_lines
;
12945 /* If window configuration was changed, frames may have been
12946 marked garbaged. Clear them or we will experience
12947 surprises wrt scrolling. */
12948 if (frame_garbaged
)
12949 clear_garbaged_frames ();
12953 /* If showing the region, and mark has changed, we must redisplay
12954 the whole window. The assignment to this_line_start_pos prevents
12955 the optimization directly below this if-statement. */
12956 if (((!NILP (Vtransient_mark_mode
)
12957 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12958 != !NILP (w
->region_showing
))
12959 || (!NILP (w
->region_showing
)
12960 && !EQ (w
->region_showing
,
12961 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12962 CHARPOS (this_line_start_pos
) = 0;
12964 /* Optimize the case that only the line containing the cursor in the
12965 selected window has changed. Variables starting with this_ are
12966 set in display_line and record information about the line
12967 containing the cursor. */
12968 tlbufpos
= this_line_start_pos
;
12969 tlendpos
= this_line_end_pos
;
12970 if (!consider_all_windows_p
12971 && CHARPOS (tlbufpos
) > 0
12972 && NILP (w
->update_mode_line
)
12973 && !current_buffer
->clip_changed
12974 && !current_buffer
->prevent_redisplay_optimizations_p
12975 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12976 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12977 /* Make sure recorded data applies to current buffer, etc. */
12978 && this_line_buffer
== current_buffer
12979 && current_buffer
== XBUFFER (w
->buffer
)
12980 && NILP (w
->force_start
)
12981 && NILP (w
->optional_new_start
)
12982 /* Point must be on the line that we have info recorded about. */
12983 && PT
>= CHARPOS (tlbufpos
)
12984 && PT
<= Z
- CHARPOS (tlendpos
)
12985 /* All text outside that line, including its final newline,
12986 must be unchanged. */
12987 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12988 CHARPOS (tlendpos
)))
12990 if (CHARPOS (tlbufpos
) > BEGV
12991 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12992 && (CHARPOS (tlbufpos
) == ZV
12993 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12994 /* Former continuation line has disappeared by becoming empty. */
12996 else if (XFASTINT (w
->last_modified
) < MODIFF
12997 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12998 || MINI_WINDOW_P (w
))
13000 /* We have to handle the case of continuation around a
13001 wide-column character (see the comment in indent.c around
13004 For instance, in the following case:
13006 -------- Insert --------
13007 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13008 J_I_ ==> J_I_ `^^' are cursors.
13012 As we have to redraw the line above, we cannot use this
13016 int line_height_before
= this_line_pixel_height
;
13018 /* Note that start_display will handle the case that the
13019 line starting at tlbufpos is a continuation line. */
13020 start_display (&it
, w
, tlbufpos
);
13022 /* Implementation note: It this still necessary? */
13023 if (it
.current_x
!= this_line_start_x
)
13026 TRACE ((stderr
, "trying display optimization 1\n"));
13027 w
->cursor
.vpos
= -1;
13028 overlay_arrow_seen
= 0;
13029 it
.vpos
= this_line_vpos
;
13030 it
.current_y
= this_line_y
;
13031 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13032 display_line (&it
);
13034 /* If line contains point, is not continued,
13035 and ends at same distance from eob as before, we win. */
13036 if (w
->cursor
.vpos
>= 0
13037 /* Line is not continued, otherwise this_line_start_pos
13038 would have been set to 0 in display_line. */
13039 && CHARPOS (this_line_start_pos
)
13040 /* Line ends as before. */
13041 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13042 /* Line has same height as before. Otherwise other lines
13043 would have to be shifted up or down. */
13044 && this_line_pixel_height
== line_height_before
)
13046 /* If this is not the window's last line, we must adjust
13047 the charstarts of the lines below. */
13048 if (it
.current_y
< it
.last_visible_y
)
13050 struct glyph_row
*row
13051 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13052 EMACS_INT delta
, delta_bytes
;
13054 /* We used to distinguish between two cases here,
13055 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13056 when the line ends in a newline or the end of the
13057 buffer's accessible portion. But both cases did
13058 the same, so they were collapsed. */
13060 - CHARPOS (tlendpos
)
13061 - MATRIX_ROW_START_CHARPOS (row
));
13062 delta_bytes
= (Z_BYTE
13063 - BYTEPOS (tlendpos
)
13064 - MATRIX_ROW_START_BYTEPOS (row
));
13066 increment_matrix_positions (w
->current_matrix
,
13067 this_line_vpos
+ 1,
13068 w
->current_matrix
->nrows
,
13069 delta
, delta_bytes
);
13072 /* If this row displays text now but previously didn't,
13073 or vice versa, w->window_end_vpos may have to be
13075 if ((it
.glyph_row
- 1)->displays_text_p
)
13077 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13078 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13080 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13081 && this_line_vpos
> 0)
13082 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13083 w
->window_end_valid
= Qnil
;
13085 /* Update hint: No need to try to scroll in update_window. */
13086 w
->desired_matrix
->no_scrolling_p
= 1;
13089 *w
->desired_matrix
->method
= 0;
13090 debug_method_add (w
, "optimization 1");
13092 #ifdef HAVE_WINDOW_SYSTEM
13093 update_window_fringes (w
, 0);
13100 else if (/* Cursor position hasn't changed. */
13101 PT
== XFASTINT (w
->last_point
)
13102 /* Make sure the cursor was last displayed
13103 in this window. Otherwise we have to reposition it. */
13104 && 0 <= w
->cursor
.vpos
13105 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13109 do_pending_window_change (1);
13110 /* If selected_window changed, redisplay again. */
13111 if (WINDOWP (selected_window
)
13112 && (w
= XWINDOW (selected_window
)) != sw
)
13115 /* We used to always goto end_of_redisplay here, but this
13116 isn't enough if we have a blinking cursor. */
13117 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13118 goto end_of_redisplay
;
13122 /* If highlighting the region, or if the cursor is in the echo area,
13123 then we can't just move the cursor. */
13124 else if (! (!NILP (Vtransient_mark_mode
)
13125 && !NILP (BVAR (current_buffer
, mark_active
)))
13126 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
13127 || highlight_nonselected_windows
)
13128 && NILP (w
->region_showing
)
13129 && NILP (Vshow_trailing_whitespace
)
13130 && !cursor_in_echo_area
)
13133 struct glyph_row
*row
;
13135 /* Skip from tlbufpos to PT and see where it is. Note that
13136 PT may be in invisible text. If so, we will end at the
13137 next visible position. */
13138 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13139 NULL
, DEFAULT_FACE_ID
);
13140 it
.current_x
= this_line_start_x
;
13141 it
.current_y
= this_line_y
;
13142 it
.vpos
= this_line_vpos
;
13144 /* The call to move_it_to stops in front of PT, but
13145 moves over before-strings. */
13146 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13148 if (it
.vpos
== this_line_vpos
13149 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13152 xassert (this_line_vpos
== it
.vpos
);
13153 xassert (this_line_y
== it
.current_y
);
13154 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13156 *w
->desired_matrix
->method
= 0;
13157 debug_method_add (w
, "optimization 3");
13166 /* Text changed drastically or point moved off of line. */
13167 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13170 CHARPOS (this_line_start_pos
) = 0;
13171 consider_all_windows_p
|= buffer_shared
> 1;
13172 ++clear_face_cache_count
;
13173 #ifdef HAVE_WINDOW_SYSTEM
13174 ++clear_image_cache_count
;
13177 /* Build desired matrices, and update the display. If
13178 consider_all_windows_p is non-zero, do it for all windows on all
13179 frames. Otherwise do it for selected_window, only. */
13181 if (consider_all_windows_p
)
13183 Lisp_Object tail
, frame
;
13185 FOR_EACH_FRAME (tail
, frame
)
13186 XFRAME (frame
)->updated_p
= 0;
13188 /* Recompute # windows showing selected buffer. This will be
13189 incremented each time such a window is displayed. */
13192 FOR_EACH_FRAME (tail
, frame
)
13194 struct frame
*f
= XFRAME (frame
);
13196 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13198 if (! EQ (frame
, selected_frame
))
13199 /* Select the frame, for the sake of frame-local
13201 select_frame_for_redisplay (frame
);
13203 /* Mark all the scroll bars to be removed; we'll redeem
13204 the ones we want when we redisplay their windows. */
13205 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13206 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13208 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13209 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13211 /* The X error handler may have deleted that frame. */
13212 if (!FRAME_LIVE_P (f
))
13215 /* Any scroll bars which redisplay_windows should have
13216 nuked should now go away. */
13217 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13218 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13220 /* If fonts changed, display again. */
13221 /* ??? rms: I suspect it is a mistake to jump all the way
13222 back to retry here. It should just retry this frame. */
13223 if (fonts_changed_p
)
13226 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13228 /* See if we have to hscroll. */
13229 if (!f
->already_hscrolled_p
)
13231 f
->already_hscrolled_p
= 1;
13232 if (hscroll_windows (f
->root_window
))
13236 /* Prevent various kinds of signals during display
13237 update. stdio is not robust about handling
13238 signals, which can cause an apparent I/O
13240 if (interrupt_input
)
13241 unrequest_sigio ();
13244 /* Update the display. */
13245 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13246 pending
|= update_frame (f
, 0, 0);
13252 if (!EQ (old_frame
, selected_frame
)
13253 && FRAME_LIVE_P (XFRAME (old_frame
)))
13254 /* We played a bit fast-and-loose above and allowed selected_frame
13255 and selected_window to be temporarily out-of-sync but let's make
13256 sure this stays contained. */
13257 select_frame_for_redisplay (old_frame
);
13258 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13262 /* Do the mark_window_display_accurate after all windows have
13263 been redisplayed because this call resets flags in buffers
13264 which are needed for proper redisplay. */
13265 FOR_EACH_FRAME (tail
, frame
)
13267 struct frame
*f
= XFRAME (frame
);
13270 mark_window_display_accurate (f
->root_window
, 1);
13271 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13272 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13277 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13279 Lisp_Object mini_window
;
13280 struct frame
*mini_frame
;
13282 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13283 /* Use list_of_error, not Qerror, so that
13284 we catch only errors and don't run the debugger. */
13285 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13287 redisplay_window_error
);
13289 /* Compare desired and current matrices, perform output. */
13292 /* If fonts changed, display again. */
13293 if (fonts_changed_p
)
13296 /* Prevent various kinds of signals during display update.
13297 stdio is not robust about handling signals,
13298 which can cause an apparent I/O error. */
13299 if (interrupt_input
)
13300 unrequest_sigio ();
13303 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13305 if (hscroll_windows (selected_window
))
13308 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13309 pending
= update_frame (sf
, 0, 0);
13312 /* We may have called echo_area_display at the top of this
13313 function. If the echo area is on another frame, that may
13314 have put text on a frame other than the selected one, so the
13315 above call to update_frame would not have caught it. Catch
13317 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13318 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13320 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13322 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13323 pending
|= update_frame (mini_frame
, 0, 0);
13324 if (!pending
&& hscroll_windows (mini_window
))
13329 /* If display was paused because of pending input, make sure we do a
13330 thorough update the next time. */
13333 /* Prevent the optimization at the beginning of
13334 redisplay_internal that tries a single-line update of the
13335 line containing the cursor in the selected window. */
13336 CHARPOS (this_line_start_pos
) = 0;
13338 /* Let the overlay arrow be updated the next time. */
13339 update_overlay_arrows (0);
13341 /* If we pause after scrolling, some rows in the current
13342 matrices of some windows are not valid. */
13343 if (!WINDOW_FULL_WIDTH_P (w
)
13344 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13345 update_mode_lines
= 1;
13349 if (!consider_all_windows_p
)
13351 /* This has already been done above if
13352 consider_all_windows_p is set. */
13353 mark_window_display_accurate_1 (w
, 1);
13355 /* Say overlay arrows are up to date. */
13356 update_overlay_arrows (1);
13358 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13359 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13362 update_mode_lines
= 0;
13363 windows_or_buffers_changed
= 0;
13364 cursor_type_changed
= 0;
13367 /* Start SIGIO interrupts coming again. Having them off during the
13368 code above makes it less likely one will discard output, but not
13369 impossible, since there might be stuff in the system buffer here.
13370 But it is much hairier to try to do anything about that. */
13371 if (interrupt_input
)
13375 /* If a frame has become visible which was not before, redisplay
13376 again, so that we display it. Expose events for such a frame
13377 (which it gets when becoming visible) don't call the parts of
13378 redisplay constructing glyphs, so simply exposing a frame won't
13379 display anything in this case. So, we have to display these
13380 frames here explicitly. */
13383 Lisp_Object tail
, frame
;
13386 FOR_EACH_FRAME (tail
, frame
)
13388 int this_is_visible
= 0;
13390 if (XFRAME (frame
)->visible
)
13391 this_is_visible
= 1;
13392 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13393 if (XFRAME (frame
)->visible
)
13394 this_is_visible
= 1;
13396 if (this_is_visible
)
13400 if (new_count
!= number_of_visible_frames
)
13401 windows_or_buffers_changed
++;
13404 /* Change frame size now if a change is pending. */
13405 do_pending_window_change (1);
13407 /* If we just did a pending size change, or have additional
13408 visible frames, or selected_window changed, redisplay again. */
13409 if ((windows_or_buffers_changed
&& !pending
)
13410 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13413 /* Clear the face and image caches.
13415 We used to do this only if consider_all_windows_p. But the cache
13416 needs to be cleared if a timer creates images in the current
13417 buffer (e.g. the test case in Bug#6230). */
13419 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13421 clear_face_cache (0);
13422 clear_face_cache_count
= 0;
13425 #ifdef HAVE_WINDOW_SYSTEM
13426 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13428 clear_image_caches (Qnil
);
13429 clear_image_cache_count
= 0;
13431 #endif /* HAVE_WINDOW_SYSTEM */
13434 unbind_to (count
, Qnil
);
13439 /* Redisplay, but leave alone any recent echo area message unless
13440 another message has been requested in its place.
13442 This is useful in situations where you need to redisplay but no
13443 user action has occurred, making it inappropriate for the message
13444 area to be cleared. See tracking_off and
13445 wait_reading_process_output for examples of these situations.
13447 FROM_WHERE is an integer saying from where this function was
13448 called. This is useful for debugging. */
13451 redisplay_preserve_echo_area (int from_where
)
13453 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13455 if (!NILP (echo_area_buffer
[1]))
13457 /* We have a previously displayed message, but no current
13458 message. Redisplay the previous message. */
13459 display_last_displayed_message_p
= 1;
13460 redisplay_internal ();
13461 display_last_displayed_message_p
= 0;
13464 redisplay_internal ();
13466 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13467 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13468 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13472 /* Function registered with record_unwind_protect in
13473 redisplay_internal. Reset redisplaying_p to the value it had
13474 before redisplay_internal was called, and clear
13475 prevent_freeing_realized_faces_p. It also selects the previously
13476 selected frame, unless it has been deleted (by an X connection
13477 failure during redisplay, for example). */
13480 unwind_redisplay (Lisp_Object val
)
13482 Lisp_Object old_redisplaying_p
, old_frame
;
13484 old_redisplaying_p
= XCAR (val
);
13485 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13486 old_frame
= XCDR (val
);
13487 if (! EQ (old_frame
, selected_frame
)
13488 && FRAME_LIVE_P (XFRAME (old_frame
)))
13489 select_frame_for_redisplay (old_frame
);
13494 /* Mark the display of window W as accurate or inaccurate. If
13495 ACCURATE_P is non-zero mark display of W as accurate. If
13496 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13497 redisplay_internal is called. */
13500 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13502 if (BUFFERP (w
->buffer
))
13504 struct buffer
*b
= XBUFFER (w
->buffer
);
13507 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
13508 w
->last_overlay_modified
13509 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
13511 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
13515 b
->clip_changed
= 0;
13516 b
->prevent_redisplay_optimizations_p
= 0;
13518 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13519 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13520 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13521 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13523 w
->current_matrix
->buffer
= b
;
13524 w
->current_matrix
->begv
= BUF_BEGV (b
);
13525 w
->current_matrix
->zv
= BUF_ZV (b
);
13527 w
->last_cursor
= w
->cursor
;
13528 w
->last_cursor_off_p
= w
->cursor_off_p
;
13530 if (w
== XWINDOW (selected_window
))
13531 w
->last_point
= make_number (BUF_PT (b
));
13533 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
13539 w
->window_end_valid
= w
->buffer
;
13540 w
->update_mode_line
= Qnil
;
13545 /* Mark the display of windows in the window tree rooted at WINDOW as
13546 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13547 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13548 be redisplayed the next time redisplay_internal is called. */
13551 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13555 for (; !NILP (window
); window
= w
->next
)
13557 w
= XWINDOW (window
);
13558 mark_window_display_accurate_1 (w
, accurate_p
);
13560 if (!NILP (w
->vchild
))
13561 mark_window_display_accurate (w
->vchild
, accurate_p
);
13562 if (!NILP (w
->hchild
))
13563 mark_window_display_accurate (w
->hchild
, accurate_p
);
13568 update_overlay_arrows (1);
13572 /* Force a thorough redisplay the next time by setting
13573 last_arrow_position and last_arrow_string to t, which is
13574 unequal to any useful value of Voverlay_arrow_... */
13575 update_overlay_arrows (-1);
13580 /* Return value in display table DP (Lisp_Char_Table *) for character
13581 C. Since a display table doesn't have any parent, we don't have to
13582 follow parent. Do not call this function directly but use the
13583 macro DISP_CHAR_VECTOR. */
13586 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13590 if (ASCII_CHAR_P (c
))
13593 if (SUB_CHAR_TABLE_P (val
))
13594 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13600 XSETCHAR_TABLE (table
, dp
);
13601 val
= char_table_ref (table
, c
);
13610 /***********************************************************************
13612 ***********************************************************************/
13614 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13617 redisplay_windows (Lisp_Object window
)
13619 while (!NILP (window
))
13621 struct window
*w
= XWINDOW (window
);
13623 if (!NILP (w
->hchild
))
13624 redisplay_windows (w
->hchild
);
13625 else if (!NILP (w
->vchild
))
13626 redisplay_windows (w
->vchild
);
13627 else if (!NILP (w
->buffer
))
13629 displayed_buffer
= XBUFFER (w
->buffer
);
13630 /* Use list_of_error, not Qerror, so that
13631 we catch only errors and don't run the debugger. */
13632 internal_condition_case_1 (redisplay_window_0
, window
,
13634 redisplay_window_error
);
13642 redisplay_window_error (Lisp_Object ignore
)
13644 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13649 redisplay_window_0 (Lisp_Object window
)
13651 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13652 redisplay_window (window
, 0);
13657 redisplay_window_1 (Lisp_Object window
)
13659 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13660 redisplay_window (window
, 1);
13665 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13666 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13667 which positions recorded in ROW differ from current buffer
13670 Return 0 if cursor is not on this row, 1 otherwise. */
13673 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13674 struct glyph_matrix
*matrix
,
13675 EMACS_INT delta
, EMACS_INT delta_bytes
,
13678 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13679 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13680 struct glyph
*cursor
= NULL
;
13681 /* The last known character position in row. */
13682 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13684 EMACS_INT pt_old
= PT
- delta
;
13685 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13686 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13687 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13688 /* A glyph beyond the edge of TEXT_AREA which we should never
13690 struct glyph
*glyphs_end
= end
;
13691 /* Non-zero means we've found a match for cursor position, but that
13692 glyph has the avoid_cursor_p flag set. */
13693 int match_with_avoid_cursor
= 0;
13694 /* Non-zero means we've seen at least one glyph that came from a
13696 int string_seen
= 0;
13697 /* Largest and smallest buffer positions seen so far during scan of
13699 EMACS_INT bpos_max
= pos_before
;
13700 EMACS_INT bpos_min
= pos_after
;
13701 /* Last buffer position covered by an overlay string with an integer
13702 `cursor' property. */
13703 EMACS_INT bpos_covered
= 0;
13704 /* Non-zero means the display string on which to display the cursor
13705 comes from a text property, not from an overlay. */
13706 int string_from_text_prop
= 0;
13708 /* Don't even try doing anything if called for a mode-line or
13709 header-line row, since the rest of the code isn't prepared to
13710 deal with such calamities. */
13711 xassert (!row
->mode_line_p
);
13712 if (row
->mode_line_p
)
13715 /* Skip over glyphs not having an object at the start and the end of
13716 the row. These are special glyphs like truncation marks on
13717 terminal frames. */
13718 if (row
->displays_text_p
)
13720 if (!row
->reversed_p
)
13723 && INTEGERP (glyph
->object
)
13724 && glyph
->charpos
< 0)
13726 x
+= glyph
->pixel_width
;
13730 && INTEGERP ((end
- 1)->object
)
13731 /* CHARPOS is zero for blanks and stretch glyphs
13732 inserted by extend_face_to_end_of_line. */
13733 && (end
- 1)->charpos
<= 0)
13735 glyph_before
= glyph
- 1;
13742 /* If the glyph row is reversed, we need to process it from back
13743 to front, so swap the edge pointers. */
13744 glyphs_end
= end
= glyph
- 1;
13745 glyph
+= row
->used
[TEXT_AREA
] - 1;
13747 while (glyph
> end
+ 1
13748 && INTEGERP (glyph
->object
)
13749 && glyph
->charpos
< 0)
13752 x
-= glyph
->pixel_width
;
13754 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13756 /* By default, in reversed rows we put the cursor on the
13757 rightmost (first in the reading order) glyph. */
13758 for (g
= end
+ 1; g
< glyph
; g
++)
13759 x
+= g
->pixel_width
;
13761 && INTEGERP ((end
+ 1)->object
)
13762 && (end
+ 1)->charpos
<= 0)
13764 glyph_before
= glyph
+ 1;
13768 else if (row
->reversed_p
)
13770 /* In R2L rows that don't display text, put the cursor on the
13771 rightmost glyph. Case in point: an empty last line that is
13772 part of an R2L paragraph. */
13774 /* Avoid placing the cursor on the last glyph of the row, where
13775 on terminal frames we hold the vertical border between
13776 adjacent windows. */
13777 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13778 && !WINDOW_RIGHTMOST_P (w
)
13779 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13781 x
= -1; /* will be computed below, at label compute_x */
13784 /* Step 1: Try to find the glyph whose character position
13785 corresponds to point. If that's not possible, find 2 glyphs
13786 whose character positions are the closest to point, one before
13787 point, the other after it. */
13788 if (!row
->reversed_p
)
13789 while (/* not marched to end of glyph row */
13791 /* glyph was not inserted by redisplay for internal purposes */
13792 && !INTEGERP (glyph
->object
))
13794 if (BUFFERP (glyph
->object
))
13796 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13798 if (glyph
->charpos
> bpos_max
)
13799 bpos_max
= glyph
->charpos
;
13800 if (glyph
->charpos
< bpos_min
)
13801 bpos_min
= glyph
->charpos
;
13802 if (!glyph
->avoid_cursor_p
)
13804 /* If we hit point, we've found the glyph on which to
13805 display the cursor. */
13808 match_with_avoid_cursor
= 0;
13811 /* See if we've found a better approximation to
13812 POS_BEFORE or to POS_AFTER. Note that we want the
13813 first (leftmost) glyph of all those that are the
13814 closest from below, and the last (rightmost) of all
13815 those from above. */
13816 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13818 pos_before
= glyph
->charpos
;
13819 glyph_before
= glyph
;
13821 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13823 pos_after
= glyph
->charpos
;
13824 glyph_after
= glyph
;
13827 else if (dpos
== 0)
13828 match_with_avoid_cursor
= 1;
13830 else if (STRINGP (glyph
->object
))
13832 Lisp_Object chprop
;
13833 EMACS_INT glyph_pos
= glyph
->charpos
;
13835 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13837 if (!NILP (chprop
))
13839 /* If the string came from a `display' text property,
13840 look up the buffer position of that property and
13841 use that position to update bpos_max, as if we
13842 actually saw such a position in one of the row's
13843 glyphs. This helps with supporting integer values
13844 of `cursor' property on the display string in
13845 situations where most or all of the row's buffer
13846 text is completely covered by display properties,
13847 so that no glyph with valid buffer positions is
13848 ever seen in the row. */
13849 EMACS_INT prop_pos
=
13850 string_buffer_position_lim (glyph
->object
, pos_before
,
13853 if (prop_pos
>= pos_before
)
13854 bpos_max
= prop_pos
- 1;
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
13861 this glyph. Note that, if a `cursor' property on one
13862 of the string's characters has an integer value, we
13863 will break out of the loop below _before_ we get to
13864 the position match above. IOW, integer values of
13865 the `cursor' property override the "exact match for
13866 point" strategy of positioning the cursor. */
13867 /* Implementation note: bpos_max == pt_old when, e.g.,
13868 we are in an empty line, where bpos_max is set to
13869 MATRIX_ROW_START_CHARPOS, see above. */
13870 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13879 x
+= glyph
->pixel_width
;
13882 else if (glyph
> end
) /* row is reversed */
13883 while (!INTEGERP (glyph
->object
))
13885 if (BUFFERP (glyph
->object
))
13887 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13889 if (glyph
->charpos
> bpos_max
)
13890 bpos_max
= glyph
->charpos
;
13891 if (glyph
->charpos
< bpos_min
)
13892 bpos_min
= glyph
->charpos
;
13893 if (!glyph
->avoid_cursor_p
)
13897 match_with_avoid_cursor
= 0;
13900 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13902 pos_before
= glyph
->charpos
;
13903 glyph_before
= glyph
;
13905 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13907 pos_after
= glyph
->charpos
;
13908 glyph_after
= glyph
;
13911 else if (dpos
== 0)
13912 match_with_avoid_cursor
= 1;
13914 else if (STRINGP (glyph
->object
))
13916 Lisp_Object chprop
;
13917 EMACS_INT glyph_pos
= glyph
->charpos
;
13919 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13921 if (!NILP (chprop
))
13923 EMACS_INT prop_pos
=
13924 string_buffer_position_lim (glyph
->object
, pos_before
,
13927 if (prop_pos
>= pos_before
)
13928 bpos_max
= prop_pos
- 1;
13930 if (INTEGERP (chprop
))
13932 bpos_covered
= bpos_max
+ XINT (chprop
);
13933 /* If the `cursor' property covers buffer positions up
13934 to and including point, we should display cursor on
13936 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13945 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13947 x
--; /* can't use any pixel_width */
13950 x
-= glyph
->pixel_width
;
13953 /* Step 2: If we didn't find an exact match for point, we need to
13954 look for a proper place to put the cursor among glyphs between
13955 GLYPH_BEFORE and GLYPH_AFTER. */
13956 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13957 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13958 && bpos_covered
< pt_old
)
13960 /* An empty line has a single glyph whose OBJECT is zero and
13961 whose CHARPOS is the position of a newline on that line.
13962 Note that on a TTY, there are more glyphs after that, which
13963 were produced by extend_face_to_end_of_line, but their
13964 CHARPOS is zero or negative. */
13966 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13967 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13969 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13971 EMACS_INT ellipsis_pos
;
13973 /* Scan back over the ellipsis glyphs. */
13974 if (!row
->reversed_p
)
13976 ellipsis_pos
= (glyph
- 1)->charpos
;
13977 while (glyph
> row
->glyphs
[TEXT_AREA
]
13978 && (glyph
- 1)->charpos
== ellipsis_pos
)
13979 glyph
--, x
-= glyph
->pixel_width
;
13980 /* That loop always goes one position too far, including
13981 the glyph before the ellipsis. So scan forward over
13983 x
+= glyph
->pixel_width
;
13986 else /* row is reversed */
13988 ellipsis_pos
= (glyph
+ 1)->charpos
;
13989 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13990 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13991 glyph
++, x
+= glyph
->pixel_width
;
13992 x
-= glyph
->pixel_width
;
13996 else if (match_with_avoid_cursor
)
13998 cursor
= glyph_after
;
14001 else if (string_seen
)
14003 int incr
= row
->reversed_p
? -1 : +1;
14005 /* Need to find the glyph that came out of a string which is
14006 present at point. That glyph is somewhere between
14007 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14008 positioned between POS_BEFORE and POS_AFTER in the
14010 struct glyph
*start
, *stop
;
14011 EMACS_INT pos
= pos_before
;
14015 /* If the row ends in a newline from a display string,
14016 reordering could have moved the glyphs belonging to the
14017 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14018 in this case we extend the search to the last glyph in
14019 the row that was not inserted by redisplay. */
14020 if (row
->ends_in_newline_from_string_p
)
14023 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14026 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14027 correspond to POS_BEFORE and POS_AFTER, respectively. We
14028 need START and STOP in the order that corresponds to the
14029 row's direction as given by its reversed_p flag. If the
14030 directionality of characters between POS_BEFORE and
14031 POS_AFTER is the opposite of the row's base direction,
14032 these characters will have been reordered for display,
14033 and we need to reverse START and STOP. */
14034 if (!row
->reversed_p
)
14036 start
= min (glyph_before
, glyph_after
);
14037 stop
= max (glyph_before
, glyph_after
);
14041 start
= max (glyph_before
, glyph_after
);
14042 stop
= min (glyph_before
, glyph_after
);
14044 for (glyph
= start
+ incr
;
14045 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14048 /* Any glyphs that come from the buffer are here because
14049 of bidi reordering. Skip them, and only pay
14050 attention to glyphs that came from some string. */
14051 if (STRINGP (glyph
->object
))
14055 /* If the display property covers the newline, we
14056 need to search for it one position farther. */
14057 EMACS_INT lim
= pos_after
14058 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14060 string_from_text_prop
= 0;
14061 str
= glyph
->object
;
14062 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14063 if (tem
== 0 /* from overlay */
14066 /* If the string from which this glyph came is
14067 found in the buffer at point, or at position
14068 that is closer to point than pos_after, then
14069 we've found the glyph we've been looking for.
14070 If it comes from an overlay (tem == 0), and
14071 it has the `cursor' property on one of its
14072 glyphs, record that glyph as a candidate for
14073 displaying the cursor. (As in the
14074 unidirectional version, we will display the
14075 cursor on the last candidate we find.) */
14078 || (tem
- pt_old
> 0 && tem
< pos_after
))
14080 /* The glyphs from this string could have
14081 been reordered. Find the one with the
14082 smallest string position. Or there could
14083 be a character in the string with the
14084 `cursor' property, which means display
14085 cursor on that character's glyph. */
14086 EMACS_INT strpos
= glyph
->charpos
;
14091 string_from_text_prop
= 1;
14094 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14095 && EQ (glyph
->object
, str
);
14099 EMACS_INT gpos
= glyph
->charpos
;
14101 cprop
= Fget_char_property (make_number (gpos
),
14109 if (tem
&& glyph
->charpos
< strpos
)
14111 strpos
= glyph
->charpos
;
14117 || (tem
- pt_old
> 0 && tem
< pos_after
))
14121 pos
= tem
+ 1; /* don't find previous instances */
14123 /* This string is not what we want; skip all of the
14124 glyphs that came from it. */
14125 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14126 && EQ (glyph
->object
, str
))
14133 /* If we reached the end of the line, and END was from a string,
14134 the cursor is not on this line. */
14136 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14137 && STRINGP (end
->object
)
14138 && row
->continued_p
)
14141 /* A truncated row may not include PT among its character positions.
14142 Setting the cursor inside the scroll margin will trigger
14143 recalculation of hscroll in hscroll_window_tree. But if a
14144 display string covers point, defer to the string-handling
14145 code below to figure this out. */
14146 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14148 cursor
= glyph_before
;
14151 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14152 /* Zero-width characters produce no glyphs. */
14154 && (row
->reversed_p
14155 ? glyph_after
> glyphs_end
14156 : glyph_after
< glyphs_end
)))
14158 cursor
= glyph_after
;
14164 if (cursor
!= NULL
)
14170 /* Need to compute x that corresponds to GLYPH. */
14171 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14173 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14175 x
+= g
->pixel_width
;
14179 /* ROW could be part of a continued line, which, under bidi
14180 reordering, might have other rows whose start and end charpos
14181 occlude point. Only set w->cursor if we found a better
14182 approximation to the cursor position than we have from previously
14183 examined candidate rows belonging to the same continued line. */
14184 if (/* we already have a candidate row */
14185 w
->cursor
.vpos
>= 0
14186 /* that candidate is not the row we are processing */
14187 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14188 /* Make sure cursor.vpos specifies a row whose start and end
14189 charpos occlude point, and it is valid candidate for being a
14190 cursor-row. This is because some callers of this function
14191 leave cursor.vpos at the row where the cursor was displayed
14192 during the last redisplay cycle. */
14193 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14194 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14195 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14198 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14200 /* Don't consider glyphs that are outside TEXT_AREA. */
14201 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14203 /* Keep the candidate whose buffer position is the closest to
14204 point or has the `cursor' property. */
14205 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14206 w
->cursor
.hpos
>= 0
14207 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14208 && ((BUFFERP (g1
->object
)
14209 && (g1
->charpos
== pt_old
/* an exact match always wins */
14210 || (BUFFERP (glyph
->object
)
14211 && eabs (g1
->charpos
- pt_old
)
14212 < eabs (glyph
->charpos
- pt_old
))))
14213 /* previous candidate is a glyph from a string that has
14214 a non-nil `cursor' property */
14215 || (STRINGP (g1
->object
)
14216 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14217 Qcursor
, g1
->object
))
14218 /* previous candidate is from the same display
14219 string as this one, and the display string
14220 came from a text property */
14221 || (EQ (g1
->object
, glyph
->object
)
14222 && string_from_text_prop
)
14223 /* this candidate is from newline and its
14224 position is not an exact match */
14225 || (INTEGERP (glyph
->object
)
14226 && glyph
->charpos
!= pt_old
)))))
14228 /* If this candidate gives an exact match, use that. */
14229 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14230 /* If this candidate is a glyph created for the
14231 terminating newline of a line, and point is on that
14232 newline, it wins because it's an exact match. */
14233 || (!row
->continued_p
14234 && INTEGERP (glyph
->object
)
14235 && glyph
->charpos
== 0
14236 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14237 /* Otherwise, keep the candidate that comes from a row
14238 spanning less buffer positions. This may win when one or
14239 both candidate positions are on glyphs that came from
14240 display strings, for which we cannot compare buffer
14242 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14243 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14244 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14247 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14249 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14250 w
->cursor
.y
= row
->y
+ dy
;
14252 if (w
== XWINDOW (selected_window
))
14254 if (!row
->continued_p
14255 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14258 this_line_buffer
= XBUFFER (w
->buffer
);
14260 CHARPOS (this_line_start_pos
)
14261 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14262 BYTEPOS (this_line_start_pos
)
14263 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14265 CHARPOS (this_line_end_pos
)
14266 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14267 BYTEPOS (this_line_end_pos
)
14268 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14270 this_line_y
= w
->cursor
.y
;
14271 this_line_pixel_height
= row
->height
;
14272 this_line_vpos
= w
->cursor
.vpos
;
14273 this_line_start_x
= row
->x
;
14276 CHARPOS (this_line_start_pos
) = 0;
14283 /* Run window scroll functions, if any, for WINDOW with new window
14284 start STARTP. Sets the window start of WINDOW to that position.
14286 We assume that the window's buffer is really current. */
14288 static inline struct text_pos
14289 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14291 struct window
*w
= XWINDOW (window
);
14292 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14294 if (current_buffer
!= XBUFFER (w
->buffer
))
14297 if (!NILP (Vwindow_scroll_functions
))
14299 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14300 make_number (CHARPOS (startp
)));
14301 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14302 /* In case the hook functions switch buffers. */
14303 if (current_buffer
!= XBUFFER (w
->buffer
))
14304 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14311 /* Make sure the line containing the cursor is fully visible.
14312 A value of 1 means there is nothing to be done.
14313 (Either the line is fully visible, or it cannot be made so,
14314 or we cannot tell.)
14316 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14317 is higher than window.
14319 A value of 0 means the caller should do scrolling
14320 as if point had gone off the screen. */
14323 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14325 struct glyph_matrix
*matrix
;
14326 struct glyph_row
*row
;
14329 if (!make_cursor_line_fully_visible_p
)
14332 /* It's not always possible to find the cursor, e.g, when a window
14333 is full of overlay strings. Don't do anything in that case. */
14334 if (w
->cursor
.vpos
< 0)
14337 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14338 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14340 /* If the cursor row is not partially visible, there's nothing to do. */
14341 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14344 /* If the row the cursor is in is taller than the window's height,
14345 it's not clear what to do, so do nothing. */
14346 window_height
= window_box_height (w
);
14347 if (row
->height
>= window_height
)
14349 if (!force_p
|| MINI_WINDOW_P (w
)
14350 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14357 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14358 non-zero means only WINDOW is redisplayed in redisplay_internal.
14359 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14360 in redisplay_window to bring a partially visible line into view in
14361 the case that only the cursor has moved.
14363 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14364 last screen line's vertical height extends past the end of the screen.
14368 1 if scrolling succeeded
14370 0 if scrolling didn't find point.
14372 -1 if new fonts have been loaded so that we must interrupt
14373 redisplay, adjust glyph matrices, and try again. */
14379 SCROLLING_NEED_LARGER_MATRICES
14382 /* If scroll-conservatively is more than this, never recenter.
14384 If you change this, don't forget to update the doc string of
14385 `scroll-conservatively' and the Emacs manual. */
14386 #define SCROLL_LIMIT 100
14389 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14390 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
14391 int temp_scroll_step
, int last_line_misfit
)
14393 struct window
*w
= XWINDOW (window
);
14394 struct frame
*f
= XFRAME (w
->frame
);
14395 struct text_pos pos
, startp
;
14397 int this_scroll_margin
, scroll_max
, rc
, height
;
14398 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14399 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14400 Lisp_Object aggressive
;
14401 /* We will never try scrolling more than this number of lines. */
14402 int scroll_limit
= SCROLL_LIMIT
;
14405 debug_method_add (w
, "try_scrolling");
14408 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14410 /* Compute scroll margin height in pixels. We scroll when point is
14411 within this distance from the top or bottom of the window. */
14412 if (scroll_margin
> 0)
14413 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14414 * FRAME_LINE_HEIGHT (f
);
14416 this_scroll_margin
= 0;
14418 /* Force arg_scroll_conservatively to have a reasonable value, to
14419 avoid scrolling too far away with slow move_it_* functions. Note
14420 that the user can supply scroll-conservatively equal to
14421 `most-positive-fixnum', which can be larger than INT_MAX. */
14422 if (arg_scroll_conservatively
> scroll_limit
)
14424 arg_scroll_conservatively
= scroll_limit
+ 1;
14425 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14427 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14428 /* Compute how much we should try to scroll maximally to bring
14429 point into view. */
14430 scroll_max
= (max (scroll_step
,
14431 max (arg_scroll_conservatively
, temp_scroll_step
))
14432 * FRAME_LINE_HEIGHT (f
));
14433 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14434 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14435 /* We're trying to scroll because of aggressive scrolling but no
14436 scroll_step is set. Choose an arbitrary one. */
14437 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14443 /* Decide whether to scroll down. */
14444 if (PT
> CHARPOS (startp
))
14446 int scroll_margin_y
;
14448 /* Compute the pixel ypos of the scroll margin, then move IT to
14449 either that ypos or PT, whichever comes first. */
14450 start_display (&it
, w
, startp
);
14451 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14452 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14453 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14454 (MOVE_TO_POS
| MOVE_TO_Y
));
14456 if (PT
> CHARPOS (it
.current
.pos
))
14458 int y0
= line_bottom_y (&it
);
14459 /* Compute how many pixels below window bottom to stop searching
14460 for PT. This avoids costly search for PT that is far away if
14461 the user limited scrolling by a small number of lines, but
14462 always finds PT if scroll_conservatively is set to a large
14463 number, such as most-positive-fixnum. */
14464 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14465 int y_to_move
= it
.last_visible_y
+ slack
;
14467 /* Compute the distance from the scroll margin to PT or to
14468 the scroll limit, whichever comes first. This should
14469 include the height of the cursor line, to make that line
14471 move_it_to (&it
, PT
, -1, y_to_move
,
14472 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14473 dy
= line_bottom_y (&it
) - y0
;
14475 if (dy
> scroll_max
)
14476 return SCROLLING_FAILED
;
14485 /* Point is in or below the bottom scroll margin, so move the
14486 window start down. If scrolling conservatively, move it just
14487 enough down to make point visible. If scroll_step is set,
14488 move it down by scroll_step. */
14489 if (arg_scroll_conservatively
)
14491 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14492 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14493 else if (scroll_step
|| temp_scroll_step
)
14494 amount_to_scroll
= scroll_max
;
14497 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14498 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14499 if (NUMBERP (aggressive
))
14501 double float_amount
= XFLOATINT (aggressive
) * height
;
14502 amount_to_scroll
= float_amount
;
14503 if (amount_to_scroll
== 0 && float_amount
> 0)
14504 amount_to_scroll
= 1;
14505 /* Don't let point enter the scroll margin near top of
14507 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14508 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14512 if (amount_to_scroll
<= 0)
14513 return SCROLLING_FAILED
;
14515 start_display (&it
, w
, startp
);
14516 if (arg_scroll_conservatively
<= scroll_limit
)
14517 move_it_vertically (&it
, amount_to_scroll
);
14520 /* Extra precision for users who set scroll-conservatively
14521 to a large number: make sure the amount we scroll
14522 the window start is never less than amount_to_scroll,
14523 which was computed as distance from window bottom to
14524 point. This matters when lines at window top and lines
14525 below window bottom have different height. */
14527 void *it1data
= NULL
;
14528 /* We use a temporary it1 because line_bottom_y can modify
14529 its argument, if it moves one line down; see there. */
14532 SAVE_IT (it1
, it
, it1data
);
14533 start_y
= line_bottom_y (&it1
);
14535 RESTORE_IT (&it
, &it
, it1data
);
14536 move_it_by_lines (&it
, 1);
14537 SAVE_IT (it1
, it
, it1data
);
14538 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14541 /* If STARTP is unchanged, move it down another screen line. */
14542 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14543 move_it_by_lines (&it
, 1);
14544 startp
= it
.current
.pos
;
14548 struct text_pos scroll_margin_pos
= startp
;
14550 /* See if point is inside the scroll margin at the top of the
14552 if (this_scroll_margin
)
14554 start_display (&it
, w
, startp
);
14555 move_it_vertically (&it
, this_scroll_margin
);
14556 scroll_margin_pos
= it
.current
.pos
;
14559 if (PT
< CHARPOS (scroll_margin_pos
))
14561 /* Point is in the scroll margin at the top of the window or
14562 above what is displayed in the window. */
14565 /* Compute the vertical distance from PT to the scroll
14566 margin position. Move as far as scroll_max allows, or
14567 one screenful, or 10 screen lines, whichever is largest.
14568 Give up if distance is greater than scroll_max. */
14569 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14570 start_display (&it
, w
, pos
);
14572 y_to_move
= max (it
.last_visible_y
,
14573 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14574 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14576 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14577 dy
= it
.current_y
- y0
;
14578 if (dy
> scroll_max
)
14579 return SCROLLING_FAILED
;
14581 /* Compute new window start. */
14582 start_display (&it
, w
, startp
);
14584 if (arg_scroll_conservatively
)
14585 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14586 max (scroll_step
, temp_scroll_step
));
14587 else if (scroll_step
|| temp_scroll_step
)
14588 amount_to_scroll
= scroll_max
;
14591 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14592 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14593 if (NUMBERP (aggressive
))
14595 double float_amount
= XFLOATINT (aggressive
) * height
;
14596 amount_to_scroll
= float_amount
;
14597 if (amount_to_scroll
== 0 && float_amount
> 0)
14598 amount_to_scroll
= 1;
14599 amount_to_scroll
-=
14600 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14601 /* Don't let point enter the scroll margin near
14602 bottom of the window. */
14603 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14604 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14608 if (amount_to_scroll
<= 0)
14609 return SCROLLING_FAILED
;
14611 move_it_vertically_backward (&it
, amount_to_scroll
);
14612 startp
= it
.current
.pos
;
14616 /* Run window scroll functions. */
14617 startp
= run_window_scroll_functions (window
, startp
);
14619 /* Display the window. Give up if new fonts are loaded, or if point
14621 if (!try_window (window
, startp
, 0))
14622 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14623 else if (w
->cursor
.vpos
< 0)
14625 clear_glyph_matrix (w
->desired_matrix
);
14626 rc
= SCROLLING_FAILED
;
14630 /* Maybe forget recorded base line for line number display. */
14631 if (!just_this_one_p
14632 || current_buffer
->clip_changed
14633 || BEG_UNCHANGED
< CHARPOS (startp
))
14634 w
->base_line_number
= Qnil
;
14636 /* If cursor ends up on a partially visible line,
14637 treat that as being off the bottom of the screen. */
14638 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14639 /* It's possible that the cursor is on the first line of the
14640 buffer, which is partially obscured due to a vscroll
14641 (Bug#7537). In that case, avoid looping forever . */
14642 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14644 clear_glyph_matrix (w
->desired_matrix
);
14645 ++extra_scroll_margin_lines
;
14648 rc
= SCROLLING_SUCCESS
;
14655 /* Compute a suitable window start for window W if display of W starts
14656 on a continuation line. Value is non-zero if a new window start
14659 The new window start will be computed, based on W's width, starting
14660 from the start of the continued line. It is the start of the
14661 screen line with the minimum distance from the old start W->start. */
14664 compute_window_start_on_continuation_line (struct window
*w
)
14666 struct text_pos pos
, start_pos
;
14667 int window_start_changed_p
= 0;
14669 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14671 /* If window start is on a continuation line... Window start may be
14672 < BEGV in case there's invisible text at the start of the
14673 buffer (M-x rmail, for example). */
14674 if (CHARPOS (start_pos
) > BEGV
14675 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14678 struct glyph_row
*row
;
14680 /* Handle the case that the window start is out of range. */
14681 if (CHARPOS (start_pos
) < BEGV
)
14682 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14683 else if (CHARPOS (start_pos
) > ZV
)
14684 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14686 /* Find the start of the continued line. This should be fast
14687 because scan_buffer is fast (newline cache). */
14688 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14689 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14690 row
, DEFAULT_FACE_ID
);
14691 reseat_at_previous_visible_line_start (&it
);
14693 /* If the line start is "too far" away from the window start,
14694 say it takes too much time to compute a new window start. */
14695 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14696 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14698 int min_distance
, distance
;
14700 /* Move forward by display lines to find the new window
14701 start. If window width was enlarged, the new start can
14702 be expected to be > the old start. If window width was
14703 decreased, the new window start will be < the old start.
14704 So, we're looking for the display line start with the
14705 minimum distance from the old window start. */
14706 pos
= it
.current
.pos
;
14707 min_distance
= INFINITY
;
14708 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14709 distance
< min_distance
)
14711 min_distance
= distance
;
14712 pos
= it
.current
.pos
;
14713 move_it_by_lines (&it
, 1);
14716 /* Set the window start there. */
14717 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14718 window_start_changed_p
= 1;
14722 return window_start_changed_p
;
14726 /* Try cursor movement in case text has not changed in window WINDOW,
14727 with window start STARTP. Value is
14729 CURSOR_MOVEMENT_SUCCESS if successful
14731 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14733 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14734 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14735 we want to scroll as if scroll-step were set to 1. See the code.
14737 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14738 which case we have to abort this redisplay, and adjust matrices
14743 CURSOR_MOVEMENT_SUCCESS
,
14744 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14745 CURSOR_MOVEMENT_MUST_SCROLL
,
14746 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14750 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14752 struct window
*w
= XWINDOW (window
);
14753 struct frame
*f
= XFRAME (w
->frame
);
14754 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14757 if (inhibit_try_cursor_movement
)
14761 /* Handle case where text has not changed, only point, and it has
14762 not moved off the frame. */
14763 if (/* Point may be in this window. */
14764 PT
>= CHARPOS (startp
)
14765 /* Selective display hasn't changed. */
14766 && !current_buffer
->clip_changed
14767 /* Function force-mode-line-update is used to force a thorough
14768 redisplay. It sets either windows_or_buffers_changed or
14769 update_mode_lines. So don't take a shortcut here for these
14771 && !update_mode_lines
14772 && !windows_or_buffers_changed
14773 && !cursor_type_changed
14774 /* Can't use this case if highlighting a region. When a
14775 region exists, cursor movement has to do more than just
14777 && !(!NILP (Vtransient_mark_mode
)
14778 && !NILP (BVAR (current_buffer
, mark_active
)))
14779 && NILP (w
->region_showing
)
14780 && NILP (Vshow_trailing_whitespace
)
14781 /* Right after splitting windows, last_point may be nil. */
14782 && INTEGERP (w
->last_point
)
14783 /* This code is not used for mini-buffer for the sake of the case
14784 of redisplaying to replace an echo area message; since in
14785 that case the mini-buffer contents per se are usually
14786 unchanged. This code is of no real use in the mini-buffer
14787 since the handling of this_line_start_pos, etc., in redisplay
14788 handles the same cases. */
14789 && !EQ (window
, minibuf_window
)
14790 /* When splitting windows or for new windows, it happens that
14791 redisplay is called with a nil window_end_vpos or one being
14792 larger than the window. This should really be fixed in
14793 window.c. I don't have this on my list, now, so we do
14794 approximately the same as the old redisplay code. --gerd. */
14795 && INTEGERP (w
->window_end_vpos
)
14796 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14797 && (FRAME_WINDOW_P (f
)
14798 || !overlay_arrow_in_current_buffer_p ()))
14800 int this_scroll_margin
, top_scroll_margin
;
14801 struct glyph_row
*row
= NULL
;
14804 debug_method_add (w
, "cursor movement");
14807 /* Scroll if point within this distance from the top or bottom
14808 of the window. This is a pixel value. */
14809 if (scroll_margin
> 0)
14811 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14812 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14815 this_scroll_margin
= 0;
14817 top_scroll_margin
= this_scroll_margin
;
14818 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14819 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14821 /* Start with the row the cursor was displayed during the last
14822 not paused redisplay. Give up if that row is not valid. */
14823 if (w
->last_cursor
.vpos
< 0
14824 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14825 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14828 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14829 if (row
->mode_line_p
)
14831 if (!row
->enabled_p
)
14832 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14835 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14837 int scroll_p
= 0, must_scroll
= 0;
14838 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14840 if (PT
> XFASTINT (w
->last_point
))
14842 /* Point has moved forward. */
14843 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14844 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14846 xassert (row
->enabled_p
);
14850 /* If the end position of a row equals the start
14851 position of the next row, and PT is at that position,
14852 we would rather display cursor in the next line. */
14853 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14854 && MATRIX_ROW_END_CHARPOS (row
) == PT
14855 && row
< w
->current_matrix
->rows
14856 + w
->current_matrix
->nrows
- 1
14857 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14858 && !cursor_row_p (row
))
14861 /* If within the scroll margin, scroll. Note that
14862 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14863 the next line would be drawn, and that
14864 this_scroll_margin can be zero. */
14865 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14866 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14867 /* Line is completely visible last line in window
14868 and PT is to be set in the next line. */
14869 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14870 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14871 && !row
->ends_at_zv_p
14872 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14875 else if (PT
< XFASTINT (w
->last_point
))
14877 /* Cursor has to be moved backward. Note that PT >=
14878 CHARPOS (startp) because of the outer if-statement. */
14879 while (!row
->mode_line_p
14880 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14881 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14882 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14883 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14884 row
> w
->current_matrix
->rows
14885 && (row
-1)->ends_in_newline_from_string_p
))))
14886 && (row
->y
> top_scroll_margin
14887 || CHARPOS (startp
) == BEGV
))
14889 xassert (row
->enabled_p
);
14893 /* Consider the following case: Window starts at BEGV,
14894 there is invisible, intangible text at BEGV, so that
14895 display starts at some point START > BEGV. It can
14896 happen that we are called with PT somewhere between
14897 BEGV and START. Try to handle that case. */
14898 if (row
< w
->current_matrix
->rows
14899 || row
->mode_line_p
)
14901 row
= w
->current_matrix
->rows
;
14902 if (row
->mode_line_p
)
14906 /* Due to newlines in overlay strings, we may have to
14907 skip forward over overlay strings. */
14908 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14909 && MATRIX_ROW_END_CHARPOS (row
) == PT
14910 && !cursor_row_p (row
))
14913 /* If within the scroll margin, scroll. */
14914 if (row
->y
< top_scroll_margin
14915 && CHARPOS (startp
) != BEGV
)
14920 /* Cursor did not move. So don't scroll even if cursor line
14921 is partially visible, as it was so before. */
14922 rc
= CURSOR_MOVEMENT_SUCCESS
;
14925 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14926 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14928 /* if PT is not in the glyph row, give up. */
14929 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14932 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14933 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14935 struct glyph_row
*row1
;
14937 /* If rows are bidi-reordered and point moved, back up
14938 until we find a row that does not belong to a
14939 continuation line. This is because we must consider
14940 all rows of a continued line as candidates for the
14941 new cursor positioning, since row start and end
14942 positions change non-linearly with vertical position
14944 /* FIXME: Revisit this when glyph ``spilling'' in
14945 continuation lines' rows is implemented for
14946 bidi-reordered rows. */
14947 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14948 MATRIX_ROW_CONTINUATION_LINE_P (row
);
14951 /* If we hit the beginning of the displayed portion
14952 without finding the first row of a continued
14956 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14959 xassert (row
->enabled_p
);
14964 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14965 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14966 /* Make sure this isn't a header line by any chance, since
14967 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
14968 && !row
->mode_line_p
14969 && make_cursor_line_fully_visible_p
)
14971 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14972 && !row
->ends_at_zv_p
14973 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14974 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14975 else if (row
->height
> window_box_height (w
))
14977 /* If we end up in a partially visible line, let's
14978 make it fully visible, except when it's taller
14979 than the window, in which case we can't do much
14982 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14986 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14987 if (!cursor_row_fully_visible_p (w
, 0, 1))
14988 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14990 rc
= CURSOR_MOVEMENT_SUCCESS
;
14994 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14995 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14996 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14998 /* With bidi-reordered rows, there could be more than
14999 one candidate row whose start and end positions
15000 occlude point. We need to let set_cursor_from_row
15001 find the best candidate. */
15002 /* FIXME: Revisit this when glyph ``spilling'' in
15003 continuation lines' rows is implemented for
15004 bidi-reordered rows. */
15009 int at_zv_p
= 0, exact_match_p
= 0;
15011 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15012 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15013 && cursor_row_p (row
))
15014 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15016 /* As soon as we've found the exact match for point,
15017 or the first suitable row whose ends_at_zv_p flag
15018 is set, we are done. */
15020 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15022 && w
->cursor
.hpos
>= 0
15023 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15026 struct glyph_row
*candidate
=
15027 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15029 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15030 EMACS_INT endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15033 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15034 || (INTEGERP (g
->object
)
15035 && (g
->charpos
== PT
15036 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15038 if (rv
&& (at_zv_p
|| exact_match_p
))
15040 rc
= CURSOR_MOVEMENT_SUCCESS
;
15043 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15047 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15048 || row
->continued_p
)
15049 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15050 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15051 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15052 /* If we didn't find any candidate rows, or exited the
15053 loop before all the candidates were examined, signal
15054 to the caller that this method failed. */
15055 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15057 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15058 && !row
->continued_p
))
15059 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15061 rc
= CURSOR_MOVEMENT_SUCCESS
;
15067 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15069 rc
= CURSOR_MOVEMENT_SUCCESS
;
15074 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15075 && MATRIX_ROW_START_CHARPOS (row
) == PT
15076 && cursor_row_p (row
));
15084 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15088 set_vertical_scroll_bar (struct window
*w
)
15090 EMACS_INT start
, end
, whole
;
15092 /* Calculate the start and end positions for the current window.
15093 At some point, it would be nice to choose between scrollbars
15094 which reflect the whole buffer size, with special markers
15095 indicating narrowing, and scrollbars which reflect only the
15098 Note that mini-buffers sometimes aren't displaying any text. */
15099 if (!MINI_WINDOW_P (w
)
15100 || (w
== XWINDOW (minibuf_window
)
15101 && NILP (echo_area_buffer
[0])))
15103 struct buffer
*buf
= XBUFFER (w
->buffer
);
15104 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15105 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15106 /* I don't think this is guaranteed to be right. For the
15107 moment, we'll pretend it is. */
15108 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15112 if (whole
< (end
- start
))
15113 whole
= end
- start
;
15116 start
= end
= whole
= 0;
15118 /* Indicate what this scroll bar ought to be displaying now. */
15119 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15120 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15121 (w
, end
- start
, whole
, start
);
15125 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15126 selected_window is redisplayed.
15128 We can return without actually redisplaying the window if
15129 fonts_changed_p is nonzero. In that case, redisplay_internal will
15133 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15135 struct window
*w
= XWINDOW (window
);
15136 struct frame
*f
= XFRAME (w
->frame
);
15137 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15138 struct buffer
*old
= current_buffer
;
15139 struct text_pos lpoint
, opoint
, startp
;
15140 int update_mode_line
;
15143 /* Record it now because it's overwritten. */
15144 int current_matrix_up_to_date_p
= 0;
15145 int used_current_matrix_p
= 0;
15146 /* This is less strict than current_matrix_up_to_date_p.
15147 It indicates that the buffer contents and narrowing are unchanged. */
15148 int buffer_unchanged_p
= 0;
15149 int temp_scroll_step
= 0;
15150 int count
= SPECPDL_INDEX ();
15152 int centering_position
= -1;
15153 int last_line_misfit
= 0;
15154 EMACS_INT beg_unchanged
, end_unchanged
;
15156 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15159 /* W must be a leaf window here. */
15160 xassert (!NILP (w
->buffer
));
15162 *w
->desired_matrix
->method
= 0;
15166 reconsider_clip_changes (w
, buffer
);
15168 /* Has the mode line to be updated? */
15169 update_mode_line
= (!NILP (w
->update_mode_line
)
15170 || update_mode_lines
15171 || buffer
->clip_changed
15172 || buffer
->prevent_redisplay_optimizations_p
);
15174 if (MINI_WINDOW_P (w
))
15176 if (w
== XWINDOW (echo_area_window
)
15177 && !NILP (echo_area_buffer
[0]))
15179 if (update_mode_line
)
15180 /* We may have to update a tty frame's menu bar or a
15181 tool-bar. Example `M-x C-h C-h C-g'. */
15182 goto finish_menu_bars
;
15184 /* We've already displayed the echo area glyphs in this window. */
15185 goto finish_scroll_bars
;
15187 else if ((w
!= XWINDOW (minibuf_window
)
15188 || minibuf_level
== 0)
15189 /* When buffer is nonempty, redisplay window normally. */
15190 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15191 /* Quail displays non-mini buffers in minibuffer window.
15192 In that case, redisplay the window normally. */
15193 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15195 /* W is a mini-buffer window, but it's not active, so clear
15197 int yb
= window_text_bottom_y (w
);
15198 struct glyph_row
*row
;
15201 for (y
= 0, row
= w
->desired_matrix
->rows
;
15203 y
+= row
->height
, ++row
)
15204 blank_row (w
, row
, y
);
15205 goto finish_scroll_bars
;
15208 clear_glyph_matrix (w
->desired_matrix
);
15211 /* Otherwise set up data on this window; select its buffer and point
15213 /* Really select the buffer, for the sake of buffer-local
15215 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15217 current_matrix_up_to_date_p
15218 = (!NILP (w
->window_end_valid
)
15219 && !current_buffer
->clip_changed
15220 && !current_buffer
->prevent_redisplay_optimizations_p
15221 && XFASTINT (w
->last_modified
) >= MODIFF
15222 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15224 /* Run the window-bottom-change-functions
15225 if it is possible that the text on the screen has changed
15226 (either due to modification of the text, or any other reason). */
15227 if (!current_matrix_up_to_date_p
15228 && !NILP (Vwindow_text_change_functions
))
15230 safe_run_hooks (Qwindow_text_change_functions
);
15234 beg_unchanged
= BEG_UNCHANGED
;
15235 end_unchanged
= END_UNCHANGED
;
15237 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15239 specbind (Qinhibit_point_motion_hooks
, Qt
);
15242 = (!NILP (w
->window_end_valid
)
15243 && !current_buffer
->clip_changed
15244 && XFASTINT (w
->last_modified
) >= MODIFF
15245 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15247 /* When windows_or_buffers_changed is non-zero, we can't rely on
15248 the window end being valid, so set it to nil there. */
15249 if (windows_or_buffers_changed
)
15251 /* If window starts on a continuation line, maybe adjust the
15252 window start in case the window's width changed. */
15253 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15254 compute_window_start_on_continuation_line (w
);
15256 w
->window_end_valid
= Qnil
;
15259 /* Some sanity checks. */
15260 CHECK_WINDOW_END (w
);
15261 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15263 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15266 /* If %c is in mode line, update it if needed. */
15267 if (!NILP (w
->column_number_displayed
)
15268 /* This alternative quickly identifies a common case
15269 where no change is needed. */
15270 && !(PT
== XFASTINT (w
->last_point
)
15271 && XFASTINT (w
->last_modified
) >= MODIFF
15272 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
15273 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15274 update_mode_line
= 1;
15276 /* Count number of windows showing the selected buffer. An indirect
15277 buffer counts as its base buffer. */
15278 if (!just_this_one_p
)
15280 struct buffer
*current_base
, *window_base
;
15281 current_base
= current_buffer
;
15282 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15283 if (current_base
->base_buffer
)
15284 current_base
= current_base
->base_buffer
;
15285 if (window_base
->base_buffer
)
15286 window_base
= window_base
->base_buffer
;
15287 if (current_base
== window_base
)
15291 /* Point refers normally to the selected window. For any other
15292 window, set up appropriate value. */
15293 if (!EQ (window
, selected_window
))
15295 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
15296 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
15300 new_pt_byte
= BEGV_BYTE
;
15301 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15303 else if (new_pt
> (ZV
- 1))
15306 new_pt_byte
= ZV_BYTE
;
15307 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15310 /* We don't use SET_PT so that the point-motion hooks don't run. */
15311 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15314 /* If any of the character widths specified in the display table
15315 have changed, invalidate the width run cache. It's true that
15316 this may be a bit late to catch such changes, but the rest of
15317 redisplay goes (non-fatally) haywire when the display table is
15318 changed, so why should we worry about doing any better? */
15319 if (current_buffer
->width_run_cache
)
15321 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15323 if (! disptab_matches_widthtab (disptab
,
15324 XVECTOR (BVAR (current_buffer
, width_table
))))
15326 invalidate_region_cache (current_buffer
,
15327 current_buffer
->width_run_cache
,
15329 recompute_width_table (current_buffer
, disptab
);
15333 /* If window-start is screwed up, choose a new one. */
15334 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15337 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15339 /* If someone specified a new starting point but did not insist,
15340 check whether it can be used. */
15341 if (!NILP (w
->optional_new_start
)
15342 && CHARPOS (startp
) >= BEGV
15343 && CHARPOS (startp
) <= ZV
)
15345 w
->optional_new_start
= Qnil
;
15346 start_display (&it
, w
, startp
);
15347 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15348 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15349 if (IT_CHARPOS (it
) == PT
)
15350 w
->force_start
= Qt
;
15351 /* IT may overshoot PT if text at PT is invisible. */
15352 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15353 w
->force_start
= Qt
;
15358 /* Handle case where place to start displaying has been specified,
15359 unless the specified location is outside the accessible range. */
15360 if (!NILP (w
->force_start
)
15361 || w
->frozen_window_start_p
)
15363 /* We set this later on if we have to adjust point. */
15366 w
->force_start
= Qnil
;
15368 w
->window_end_valid
= Qnil
;
15370 /* Forget any recorded base line for line number display. */
15371 if (!buffer_unchanged_p
)
15372 w
->base_line_number
= Qnil
;
15374 /* Redisplay the mode line. Select the buffer properly for that.
15375 Also, run the hook window-scroll-functions
15376 because we have scrolled. */
15377 /* Note, we do this after clearing force_start because
15378 if there's an error, it is better to forget about force_start
15379 than to get into an infinite loop calling the hook functions
15380 and having them get more errors. */
15381 if (!update_mode_line
15382 || ! NILP (Vwindow_scroll_functions
))
15384 update_mode_line
= 1;
15385 w
->update_mode_line
= Qt
;
15386 startp
= run_window_scroll_functions (window
, startp
);
15389 w
->last_modified
= make_number (0);
15390 w
->last_overlay_modified
= make_number (0);
15391 if (CHARPOS (startp
) < BEGV
)
15392 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15393 else if (CHARPOS (startp
) > ZV
)
15394 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15396 /* Redisplay, then check if cursor has been set during the
15397 redisplay. Give up if new fonts were loaded. */
15398 /* We used to issue a CHECK_MARGINS argument to try_window here,
15399 but this causes scrolling to fail when point begins inside
15400 the scroll margin (bug#148) -- cyd */
15401 if (!try_window (window
, startp
, 0))
15403 w
->force_start
= Qt
;
15404 clear_glyph_matrix (w
->desired_matrix
);
15405 goto need_larger_matrices
;
15408 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15410 /* If point does not appear, try to move point so it does
15411 appear. The desired matrix has been built above, so we
15412 can use it here. */
15413 new_vpos
= window_box_height (w
) / 2;
15416 if (!cursor_row_fully_visible_p (w
, 0, 0))
15418 /* Point does appear, but on a line partly visible at end of window.
15419 Move it back to a fully-visible line. */
15420 new_vpos
= window_box_height (w
);
15423 /* If we need to move point for either of the above reasons,
15424 now actually do it. */
15427 struct glyph_row
*row
;
15429 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15430 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15433 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15434 MATRIX_ROW_START_BYTEPOS (row
));
15436 if (w
!= XWINDOW (selected_window
))
15437 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15438 else if (current_buffer
== old
)
15439 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15441 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15443 /* If we are highlighting the region, then we just changed
15444 the region, so redisplay to show it. */
15445 if (!NILP (Vtransient_mark_mode
)
15446 && !NILP (BVAR (current_buffer
, mark_active
)))
15448 clear_glyph_matrix (w
->desired_matrix
);
15449 if (!try_window (window
, startp
, 0))
15450 goto need_larger_matrices
;
15455 debug_method_add (w
, "forced window start");
15460 /* Handle case where text has not changed, only point, and it has
15461 not moved off the frame, and we are not retrying after hscroll.
15462 (current_matrix_up_to_date_p is nonzero when retrying.) */
15463 if (current_matrix_up_to_date_p
15464 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15465 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15469 case CURSOR_MOVEMENT_SUCCESS
:
15470 used_current_matrix_p
= 1;
15473 case CURSOR_MOVEMENT_MUST_SCROLL
:
15474 goto try_to_scroll
;
15480 /* If current starting point was originally the beginning of a line
15481 but no longer is, find a new starting point. */
15482 else if (!NILP (w
->start_at_line_beg
)
15483 && !(CHARPOS (startp
) <= BEGV
15484 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15487 debug_method_add (w
, "recenter 1");
15492 /* Try scrolling with try_window_id. Value is > 0 if update has
15493 been done, it is -1 if we know that the same window start will
15494 not work. It is 0 if unsuccessful for some other reason. */
15495 else if ((tem
= try_window_id (w
)) != 0)
15498 debug_method_add (w
, "try_window_id %d", tem
);
15501 if (fonts_changed_p
)
15502 goto need_larger_matrices
;
15506 /* Otherwise try_window_id has returned -1 which means that we
15507 don't want the alternative below this comment to execute. */
15509 else if (CHARPOS (startp
) >= BEGV
15510 && CHARPOS (startp
) <= ZV
15511 && PT
>= CHARPOS (startp
)
15512 && (CHARPOS (startp
) < ZV
15513 /* Avoid starting at end of buffer. */
15514 || CHARPOS (startp
) == BEGV
15515 || (XFASTINT (w
->last_modified
) >= MODIFF
15516 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
15518 int d1
, d2
, d3
, d4
, d5
, d6
;
15520 /* If first window line is a continuation line, and window start
15521 is inside the modified region, but the first change is before
15522 current window start, we must select a new window start.
15524 However, if this is the result of a down-mouse event (e.g. by
15525 extending the mouse-drag-overlay), we don't want to select a
15526 new window start, since that would change the position under
15527 the mouse, resulting in an unwanted mouse-movement rather
15528 than a simple mouse-click. */
15529 if (NILP (w
->start_at_line_beg
)
15530 && NILP (do_mouse_tracking
)
15531 && CHARPOS (startp
) > BEGV
15532 && CHARPOS (startp
) > BEG
+ beg_unchanged
15533 && CHARPOS (startp
) <= Z
- end_unchanged
15534 /* Even if w->start_at_line_beg is nil, a new window may
15535 start at a line_beg, since that's how set_buffer_window
15536 sets it. So, we need to check the return value of
15537 compute_window_start_on_continuation_line. (See also
15539 && XMARKER (w
->start
)->buffer
== current_buffer
15540 && compute_window_start_on_continuation_line (w
)
15541 /* It doesn't make sense to force the window start like we
15542 do at label force_start if it is already known that point
15543 will not be visible in the resulting window, because
15544 doing so will move point from its correct position
15545 instead of scrolling the window to bring point into view.
15547 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15549 w
->force_start
= Qt
;
15550 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15555 debug_method_add (w
, "same window start");
15558 /* Try to redisplay starting at same place as before.
15559 If point has not moved off frame, accept the results. */
15560 if (!current_matrix_up_to_date_p
15561 /* Don't use try_window_reusing_current_matrix in this case
15562 because a window scroll function can have changed the
15564 || !NILP (Vwindow_scroll_functions
)
15565 || MINI_WINDOW_P (w
)
15566 || !(used_current_matrix_p
15567 = try_window_reusing_current_matrix (w
)))
15569 IF_DEBUG (debug_method_add (w
, "1"));
15570 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15571 /* -1 means we need to scroll.
15572 0 means we need new matrices, but fonts_changed_p
15573 is set in that case, so we will detect it below. */
15574 goto try_to_scroll
;
15577 if (fonts_changed_p
)
15578 goto need_larger_matrices
;
15580 if (w
->cursor
.vpos
>= 0)
15582 if (!just_this_one_p
15583 || current_buffer
->clip_changed
15584 || BEG_UNCHANGED
< CHARPOS (startp
))
15585 /* Forget any recorded base line for line number display. */
15586 w
->base_line_number
= Qnil
;
15588 if (!cursor_row_fully_visible_p (w
, 1, 0))
15590 clear_glyph_matrix (w
->desired_matrix
);
15591 last_line_misfit
= 1;
15593 /* Drop through and scroll. */
15598 clear_glyph_matrix (w
->desired_matrix
);
15603 w
->last_modified
= make_number (0);
15604 w
->last_overlay_modified
= make_number (0);
15606 /* Redisplay the mode line. Select the buffer properly for that. */
15607 if (!update_mode_line
)
15609 update_mode_line
= 1;
15610 w
->update_mode_line
= Qt
;
15613 /* Try to scroll by specified few lines. */
15614 if ((scroll_conservatively
15615 || emacs_scroll_step
15616 || temp_scroll_step
15617 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15618 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15619 && CHARPOS (startp
) >= BEGV
15620 && CHARPOS (startp
) <= ZV
)
15622 /* The function returns -1 if new fonts were loaded, 1 if
15623 successful, 0 if not successful. */
15624 int ss
= try_scrolling (window
, just_this_one_p
,
15625 scroll_conservatively
,
15627 temp_scroll_step
, last_line_misfit
);
15630 case SCROLLING_SUCCESS
:
15633 case SCROLLING_NEED_LARGER_MATRICES
:
15634 goto need_larger_matrices
;
15636 case SCROLLING_FAILED
:
15644 /* Finally, just choose a place to start which positions point
15645 according to user preferences. */
15650 debug_method_add (w
, "recenter");
15653 /* w->vscroll = 0; */
15655 /* Forget any previously recorded base line for line number display. */
15656 if (!buffer_unchanged_p
)
15657 w
->base_line_number
= Qnil
;
15659 /* Determine the window start relative to point. */
15660 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15661 it
.current_y
= it
.last_visible_y
;
15662 if (centering_position
< 0)
15666 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15668 EMACS_INT margin_pos
= CHARPOS (startp
);
15669 Lisp_Object aggressive
;
15672 /* If there is a scroll margin at the top of the window, find
15673 its character position. */
15675 /* Cannot call start_display if startp is not in the
15676 accessible region of the buffer. This can happen when we
15677 have just switched to a different buffer and/or changed
15678 its restriction. In that case, startp is initialized to
15679 the character position 1 (BEGV) because we did not yet
15680 have chance to display the buffer even once. */
15681 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15684 void *it1data
= NULL
;
15686 SAVE_IT (it1
, it
, it1data
);
15687 start_display (&it1
, w
, startp
);
15688 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15689 margin_pos
= IT_CHARPOS (it1
);
15690 RESTORE_IT (&it
, &it
, it1data
);
15692 scrolling_up
= PT
> margin_pos
;
15695 ? BVAR (current_buffer
, scroll_up_aggressively
)
15696 : BVAR (current_buffer
, scroll_down_aggressively
);
15698 if (!MINI_WINDOW_P (w
)
15699 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15703 /* Setting scroll-conservatively overrides
15704 scroll-*-aggressively. */
15705 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15707 double float_amount
= XFLOATINT (aggressive
);
15709 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15710 if (pt_offset
== 0 && float_amount
> 0)
15712 if (pt_offset
&& margin
> 0)
15715 /* Compute how much to move the window start backward from
15716 point so that point will be displayed where the user
15720 centering_position
= it
.last_visible_y
;
15722 centering_position
-= pt_offset
;
15723 centering_position
-=
15724 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15725 + WINDOW_HEADER_LINE_HEIGHT (w
);
15726 /* Don't let point enter the scroll margin near top of
15728 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15729 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15732 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15735 /* Set the window start half the height of the window backward
15737 centering_position
= window_box_height (w
) / 2;
15739 move_it_vertically_backward (&it
, centering_position
);
15741 xassert (IT_CHARPOS (it
) >= BEGV
);
15743 /* The function move_it_vertically_backward may move over more
15744 than the specified y-distance. If it->w is small, e.g. a
15745 mini-buffer window, we may end up in front of the window's
15746 display area. Start displaying at the start of the line
15747 containing PT in this case. */
15748 if (it
.current_y
<= 0)
15750 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15751 move_it_vertically_backward (&it
, 0);
15755 it
.current_x
= it
.hpos
= 0;
15757 /* Set the window start position here explicitly, to avoid an
15758 infinite loop in case the functions in window-scroll-functions
15760 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15762 /* Run scroll hooks. */
15763 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15765 /* Redisplay the window. */
15766 if (!current_matrix_up_to_date_p
15767 || windows_or_buffers_changed
15768 || cursor_type_changed
15769 /* Don't use try_window_reusing_current_matrix in this case
15770 because it can have changed the buffer. */
15771 || !NILP (Vwindow_scroll_functions
)
15772 || !just_this_one_p
15773 || MINI_WINDOW_P (w
)
15774 || !(used_current_matrix_p
15775 = try_window_reusing_current_matrix (w
)))
15776 try_window (window
, startp
, 0);
15778 /* If new fonts have been loaded (due to fontsets), give up. We
15779 have to start a new redisplay since we need to re-adjust glyph
15781 if (fonts_changed_p
)
15782 goto need_larger_matrices
;
15784 /* If cursor did not appear assume that the middle of the window is
15785 in the first line of the window. Do it again with the next line.
15786 (Imagine a window of height 100, displaying two lines of height
15787 60. Moving back 50 from it->last_visible_y will end in the first
15789 if (w
->cursor
.vpos
< 0)
15791 if (!NILP (w
->window_end_valid
)
15792 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15794 clear_glyph_matrix (w
->desired_matrix
);
15795 move_it_by_lines (&it
, 1);
15796 try_window (window
, it
.current
.pos
, 0);
15798 else if (PT
< IT_CHARPOS (it
))
15800 clear_glyph_matrix (w
->desired_matrix
);
15801 move_it_by_lines (&it
, -1);
15802 try_window (window
, it
.current
.pos
, 0);
15806 /* Not much we can do about it. */
15810 /* Consider the following case: Window starts at BEGV, there is
15811 invisible, intangible text at BEGV, so that display starts at
15812 some point START > BEGV. It can happen that we are called with
15813 PT somewhere between BEGV and START. Try to handle that case. */
15814 if (w
->cursor
.vpos
< 0)
15816 struct glyph_row
*row
= w
->current_matrix
->rows
;
15817 if (row
->mode_line_p
)
15819 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15822 if (!cursor_row_fully_visible_p (w
, 0, 0))
15824 /* If vscroll is enabled, disable it and try again. */
15828 clear_glyph_matrix (w
->desired_matrix
);
15832 /* Users who set scroll-conservatively to a large number want
15833 point just above/below the scroll margin. If we ended up
15834 with point's row partially visible, move the window start to
15835 make that row fully visible and out of the margin. */
15836 if (scroll_conservatively
> SCROLL_LIMIT
)
15840 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15842 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15844 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15845 clear_glyph_matrix (w
->desired_matrix
);
15846 if (1 == try_window (window
, it
.current
.pos
,
15847 TRY_WINDOW_CHECK_MARGINS
))
15851 /* If centering point failed to make the whole line visible,
15852 put point at the top instead. That has to make the whole line
15853 visible, if it can be done. */
15854 if (centering_position
== 0)
15857 clear_glyph_matrix (w
->desired_matrix
);
15858 centering_position
= 0;
15864 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15865 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15866 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15869 /* Display the mode line, if we must. */
15870 if ((update_mode_line
15871 /* If window not full width, must redo its mode line
15872 if (a) the window to its side is being redone and
15873 (b) we do a frame-based redisplay. This is a consequence
15874 of how inverted lines are drawn in frame-based redisplay. */
15875 || (!just_this_one_p
15876 && !FRAME_WINDOW_P (f
)
15877 && !WINDOW_FULL_WIDTH_P (w
))
15878 /* Line number to display. */
15879 || INTEGERP (w
->base_line_pos
)
15880 /* Column number is displayed and different from the one displayed. */
15881 || (!NILP (w
->column_number_displayed
)
15882 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15883 /* This means that the window has a mode line. */
15884 && (WINDOW_WANTS_MODELINE_P (w
)
15885 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15887 display_mode_lines (w
);
15889 /* If mode line height has changed, arrange for a thorough
15890 immediate redisplay using the correct mode line height. */
15891 if (WINDOW_WANTS_MODELINE_P (w
)
15892 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15894 fonts_changed_p
= 1;
15895 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15896 = DESIRED_MODE_LINE_HEIGHT (w
);
15899 /* If header line height has changed, arrange for a thorough
15900 immediate redisplay using the correct header line height. */
15901 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15902 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15904 fonts_changed_p
= 1;
15905 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15906 = DESIRED_HEADER_LINE_HEIGHT (w
);
15909 if (fonts_changed_p
)
15910 goto need_larger_matrices
;
15913 if (!line_number_displayed
15914 && !BUFFERP (w
->base_line_pos
))
15916 w
->base_line_pos
= Qnil
;
15917 w
->base_line_number
= Qnil
;
15922 /* When we reach a frame's selected window, redo the frame's menu bar. */
15923 if (update_mode_line
15924 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15926 int redisplay_menu_p
= 0;
15928 if (FRAME_WINDOW_P (f
))
15930 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15931 || defined (HAVE_NS) || defined (USE_GTK)
15932 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15934 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15938 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15940 if (redisplay_menu_p
)
15941 display_menu_bar (w
);
15943 #ifdef HAVE_WINDOW_SYSTEM
15944 if (FRAME_WINDOW_P (f
))
15946 #if defined (USE_GTK) || defined (HAVE_NS)
15947 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15948 redisplay_tool_bar (f
);
15950 if (WINDOWP (f
->tool_bar_window
)
15951 && (FRAME_TOOL_BAR_LINES (f
) > 0
15952 || !NILP (Vauto_resize_tool_bars
))
15953 && redisplay_tool_bar (f
))
15954 ignore_mouse_drag_p
= 1;
15960 #ifdef HAVE_WINDOW_SYSTEM
15961 if (FRAME_WINDOW_P (f
)
15962 && update_window_fringes (w
, (just_this_one_p
15963 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15964 || w
->pseudo_window_p
)))
15968 if (draw_window_fringes (w
, 1))
15969 x_draw_vertical_border (w
);
15973 #endif /* HAVE_WINDOW_SYSTEM */
15975 /* We go to this label, with fonts_changed_p nonzero,
15976 if it is necessary to try again using larger glyph matrices.
15977 We have to redeem the scroll bar even in this case,
15978 because the loop in redisplay_internal expects that. */
15979 need_larger_matrices
:
15981 finish_scroll_bars
:
15983 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15985 /* Set the thumb's position and size. */
15986 set_vertical_scroll_bar (w
);
15988 /* Note that we actually used the scroll bar attached to this
15989 window, so it shouldn't be deleted at the end of redisplay. */
15990 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15991 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15994 /* Restore current_buffer and value of point in it. The window
15995 update may have changed the buffer, so first make sure `opoint'
15996 is still valid (Bug#6177). */
15997 if (CHARPOS (opoint
) < BEGV
)
15998 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15999 else if (CHARPOS (opoint
) > ZV
)
16000 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16002 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16004 set_buffer_internal_1 (old
);
16005 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16006 shorter. This can be caused by log truncation in *Messages*. */
16007 if (CHARPOS (lpoint
) <= ZV
)
16008 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16010 unbind_to (count
, Qnil
);
16014 /* Build the complete desired matrix of WINDOW with a window start
16015 buffer position POS.
16017 Value is 1 if successful. It is zero if fonts were loaded during
16018 redisplay which makes re-adjusting glyph matrices necessary, and -1
16019 if point would appear in the scroll margins.
16020 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16021 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16025 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16027 struct window
*w
= XWINDOW (window
);
16029 struct glyph_row
*last_text_row
= NULL
;
16030 struct frame
*f
= XFRAME (w
->frame
);
16032 /* Make POS the new window start. */
16033 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16035 /* Mark cursor position as unknown. No overlay arrow seen. */
16036 w
->cursor
.vpos
= -1;
16037 overlay_arrow_seen
= 0;
16039 /* Initialize iterator and info to start at POS. */
16040 start_display (&it
, w
, pos
);
16042 /* Display all lines of W. */
16043 while (it
.current_y
< it
.last_visible_y
)
16045 if (display_line (&it
))
16046 last_text_row
= it
.glyph_row
- 1;
16047 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16051 /* Don't let the cursor end in the scroll margins. */
16052 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16053 && !MINI_WINDOW_P (w
))
16055 int this_scroll_margin
;
16057 if (scroll_margin
> 0)
16059 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16060 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16063 this_scroll_margin
= 0;
16065 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16066 && w
->cursor
.y
< this_scroll_margin
16067 && CHARPOS (pos
) > BEGV
16068 && IT_CHARPOS (it
) < ZV
)
16069 /* rms: considering make_cursor_line_fully_visible_p here
16070 seems to give wrong results. We don't want to recenter
16071 when the last line is partly visible, we want to allow
16072 that case to be handled in the usual way. */
16073 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16075 w
->cursor
.vpos
= -1;
16076 clear_glyph_matrix (w
->desired_matrix
);
16081 /* If bottom moved off end of frame, change mode line percentage. */
16082 if (XFASTINT (w
->window_end_pos
) <= 0
16083 && Z
!= IT_CHARPOS (it
))
16084 w
->update_mode_line
= Qt
;
16086 /* Set window_end_pos to the offset of the last character displayed
16087 on the window from the end of current_buffer. Set
16088 window_end_vpos to its row number. */
16091 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16092 w
->window_end_bytepos
16093 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16095 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16097 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16098 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16099 ->displays_text_p
);
16103 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16104 w
->window_end_pos
= make_number (Z
- ZV
);
16105 w
->window_end_vpos
= make_number (0);
16108 /* But that is not valid info until redisplay finishes. */
16109 w
->window_end_valid
= Qnil
;
16115 /************************************************************************
16116 Window redisplay reusing current matrix when buffer has not changed
16117 ************************************************************************/
16119 /* Try redisplay of window W showing an unchanged buffer with a
16120 different window start than the last time it was displayed by
16121 reusing its current matrix. Value is non-zero if successful.
16122 W->start is the new window start. */
16125 try_window_reusing_current_matrix (struct window
*w
)
16127 struct frame
*f
= XFRAME (w
->frame
);
16128 struct glyph_row
*bottom_row
;
16131 struct text_pos start
, new_start
;
16132 int nrows_scrolled
, i
;
16133 struct glyph_row
*last_text_row
;
16134 struct glyph_row
*last_reused_text_row
;
16135 struct glyph_row
*start_row
;
16136 int start_vpos
, min_y
, max_y
;
16139 if (inhibit_try_window_reusing
)
16143 if (/* This function doesn't handle terminal frames. */
16144 !FRAME_WINDOW_P (f
)
16145 /* Don't try to reuse the display if windows have been split
16147 || windows_or_buffers_changed
16148 || cursor_type_changed
)
16151 /* Can't do this if region may have changed. */
16152 if ((!NILP (Vtransient_mark_mode
)
16153 && !NILP (BVAR (current_buffer
, mark_active
)))
16154 || !NILP (w
->region_showing
)
16155 || !NILP (Vshow_trailing_whitespace
))
16158 /* If top-line visibility has changed, give up. */
16159 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16160 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16163 /* Give up if old or new display is scrolled vertically. We could
16164 make this function handle this, but right now it doesn't. */
16165 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16166 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16169 /* The variable new_start now holds the new window start. The old
16170 start `start' can be determined from the current matrix. */
16171 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16172 start
= start_row
->minpos
;
16173 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16175 /* Clear the desired matrix for the display below. */
16176 clear_glyph_matrix (w
->desired_matrix
);
16178 if (CHARPOS (new_start
) <= CHARPOS (start
))
16180 /* Don't use this method if the display starts with an ellipsis
16181 displayed for invisible text. It's not easy to handle that case
16182 below, and it's certainly not worth the effort since this is
16183 not a frequent case. */
16184 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16187 IF_DEBUG (debug_method_add (w
, "twu1"));
16189 /* Display up to a row that can be reused. The variable
16190 last_text_row is set to the last row displayed that displays
16191 text. Note that it.vpos == 0 if or if not there is a
16192 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16193 start_display (&it
, w
, new_start
);
16194 w
->cursor
.vpos
= -1;
16195 last_text_row
= last_reused_text_row
= NULL
;
16197 while (it
.current_y
< it
.last_visible_y
16198 && !fonts_changed_p
)
16200 /* If we have reached into the characters in the START row,
16201 that means the line boundaries have changed. So we
16202 can't start copying with the row START. Maybe it will
16203 work to start copying with the following row. */
16204 while (IT_CHARPOS (it
) > CHARPOS (start
))
16206 /* Advance to the next row as the "start". */
16208 start
= start_row
->minpos
;
16209 /* If there are no more rows to try, or just one, give up. */
16210 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16211 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16212 || CHARPOS (start
) == ZV
)
16214 clear_glyph_matrix (w
->desired_matrix
);
16218 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16220 /* If we have reached alignment, we can copy the rest of the
16222 if (IT_CHARPOS (it
) == CHARPOS (start
)
16223 /* Don't accept "alignment" inside a display vector,
16224 since start_row could have started in the middle of
16225 that same display vector (thus their character
16226 positions match), and we have no way of telling if
16227 that is the case. */
16228 && it
.current
.dpvec_index
< 0)
16231 if (display_line (&it
))
16232 last_text_row
= it
.glyph_row
- 1;
16236 /* A value of current_y < last_visible_y means that we stopped
16237 at the previous window start, which in turn means that we
16238 have at least one reusable row. */
16239 if (it
.current_y
< it
.last_visible_y
)
16241 struct glyph_row
*row
;
16243 /* IT.vpos always starts from 0; it counts text lines. */
16244 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16246 /* Find PT if not already found in the lines displayed. */
16247 if (w
->cursor
.vpos
< 0)
16249 int dy
= it
.current_y
- start_row
->y
;
16251 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16252 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16254 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16255 dy
, nrows_scrolled
);
16258 clear_glyph_matrix (w
->desired_matrix
);
16263 /* Scroll the display. Do it before the current matrix is
16264 changed. The problem here is that update has not yet
16265 run, i.e. part of the current matrix is not up to date.
16266 scroll_run_hook will clear the cursor, and use the
16267 current matrix to get the height of the row the cursor is
16269 run
.current_y
= start_row
->y
;
16270 run
.desired_y
= it
.current_y
;
16271 run
.height
= it
.last_visible_y
- it
.current_y
;
16273 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16276 FRAME_RIF (f
)->update_window_begin_hook (w
);
16277 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16278 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16279 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16283 /* Shift current matrix down by nrows_scrolled lines. */
16284 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16285 rotate_matrix (w
->current_matrix
,
16287 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16290 /* Disable lines that must be updated. */
16291 for (i
= 0; i
< nrows_scrolled
; ++i
)
16292 (start_row
+ i
)->enabled_p
= 0;
16294 /* Re-compute Y positions. */
16295 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16296 max_y
= it
.last_visible_y
;
16297 for (row
= start_row
+ nrows_scrolled
;
16301 row
->y
= it
.current_y
;
16302 row
->visible_height
= row
->height
;
16304 if (row
->y
< min_y
)
16305 row
->visible_height
-= min_y
- row
->y
;
16306 if (row
->y
+ row
->height
> max_y
)
16307 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16308 if (row
->fringe_bitmap_periodic_p
)
16309 row
->redraw_fringe_bitmaps_p
= 1;
16311 it
.current_y
+= row
->height
;
16313 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16314 last_reused_text_row
= row
;
16315 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16319 /* Disable lines in the current matrix which are now
16320 below the window. */
16321 for (++row
; row
< bottom_row
; ++row
)
16322 row
->enabled_p
= row
->mode_line_p
= 0;
16325 /* Update window_end_pos etc.; last_reused_text_row is the last
16326 reused row from the current matrix containing text, if any.
16327 The value of last_text_row is the last displayed line
16328 containing text. */
16329 if (last_reused_text_row
)
16331 w
->window_end_bytepos
16332 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16334 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16336 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16337 w
->current_matrix
));
16339 else if (last_text_row
)
16341 w
->window_end_bytepos
16342 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16344 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16346 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16350 /* This window must be completely empty. */
16351 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16352 w
->window_end_pos
= make_number (Z
- ZV
);
16353 w
->window_end_vpos
= make_number (0);
16355 w
->window_end_valid
= Qnil
;
16357 /* Update hint: don't try scrolling again in update_window. */
16358 w
->desired_matrix
->no_scrolling_p
= 1;
16361 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16365 else if (CHARPOS (new_start
) > CHARPOS (start
))
16367 struct glyph_row
*pt_row
, *row
;
16368 struct glyph_row
*first_reusable_row
;
16369 struct glyph_row
*first_row_to_display
;
16371 int yb
= window_text_bottom_y (w
);
16373 /* Find the row starting at new_start, if there is one. Don't
16374 reuse a partially visible line at the end. */
16375 first_reusable_row
= start_row
;
16376 while (first_reusable_row
->enabled_p
16377 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16378 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16379 < CHARPOS (new_start
)))
16380 ++first_reusable_row
;
16382 /* Give up if there is no row to reuse. */
16383 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16384 || !first_reusable_row
->enabled_p
16385 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16386 != CHARPOS (new_start
)))
16389 /* We can reuse fully visible rows beginning with
16390 first_reusable_row to the end of the window. Set
16391 first_row_to_display to the first row that cannot be reused.
16392 Set pt_row to the row containing point, if there is any. */
16394 for (first_row_to_display
= first_reusable_row
;
16395 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16396 ++first_row_to_display
)
16398 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16399 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16400 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16401 && first_row_to_display
->ends_at_zv_p
16402 && pt_row
== NULL
)))
16403 pt_row
= first_row_to_display
;
16406 /* Start displaying at the start of first_row_to_display. */
16407 xassert (first_row_to_display
->y
< yb
);
16408 init_to_row_start (&it
, w
, first_row_to_display
);
16410 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16412 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16414 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16415 + WINDOW_HEADER_LINE_HEIGHT (w
));
16417 /* Display lines beginning with first_row_to_display in the
16418 desired matrix. Set last_text_row to the last row displayed
16419 that displays text. */
16420 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16421 if (pt_row
== NULL
)
16422 w
->cursor
.vpos
= -1;
16423 last_text_row
= NULL
;
16424 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16425 if (display_line (&it
))
16426 last_text_row
= it
.glyph_row
- 1;
16428 /* If point is in a reused row, adjust y and vpos of the cursor
16432 w
->cursor
.vpos
-= nrows_scrolled
;
16433 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16436 /* Give up if point isn't in a row displayed or reused. (This
16437 also handles the case where w->cursor.vpos < nrows_scrolled
16438 after the calls to display_line, which can happen with scroll
16439 margins. See bug#1295.) */
16440 if (w
->cursor
.vpos
< 0)
16442 clear_glyph_matrix (w
->desired_matrix
);
16446 /* Scroll the display. */
16447 run
.current_y
= first_reusable_row
->y
;
16448 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16449 run
.height
= it
.last_visible_y
- run
.current_y
;
16450 dy
= run
.current_y
- run
.desired_y
;
16455 FRAME_RIF (f
)->update_window_begin_hook (w
);
16456 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16457 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16458 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16462 /* Adjust Y positions of reused rows. */
16463 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16464 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16465 max_y
= it
.last_visible_y
;
16466 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16469 row
->visible_height
= row
->height
;
16470 if (row
->y
< min_y
)
16471 row
->visible_height
-= min_y
- row
->y
;
16472 if (row
->y
+ row
->height
> max_y
)
16473 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16474 if (row
->fringe_bitmap_periodic_p
)
16475 row
->redraw_fringe_bitmaps_p
= 1;
16478 /* Scroll the current matrix. */
16479 xassert (nrows_scrolled
> 0);
16480 rotate_matrix (w
->current_matrix
,
16482 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16485 /* Disable rows not reused. */
16486 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16487 row
->enabled_p
= 0;
16489 /* Point may have moved to a different line, so we cannot assume that
16490 the previous cursor position is valid; locate the correct row. */
16493 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16495 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16496 && !row
->ends_at_zv_p
;
16500 w
->cursor
.y
= row
->y
;
16502 if (row
< bottom_row
)
16504 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16505 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16507 /* Can't use this optimization with bidi-reordered glyph
16508 rows, unless cursor is already at point. */
16509 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16511 if (!(w
->cursor
.hpos
>= 0
16512 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16513 && BUFFERP (glyph
->object
)
16514 && glyph
->charpos
== PT
))
16519 && (!BUFFERP (glyph
->object
)
16520 || glyph
->charpos
< PT
);
16524 w
->cursor
.x
+= glyph
->pixel_width
;
16529 /* Adjust window end. A null value of last_text_row means that
16530 the window end is in reused rows which in turn means that
16531 only its vpos can have changed. */
16534 w
->window_end_bytepos
16535 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16537 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16539 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16544 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16547 w
->window_end_valid
= Qnil
;
16548 w
->desired_matrix
->no_scrolling_p
= 1;
16551 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16561 /************************************************************************
16562 Window redisplay reusing current matrix when buffer has changed
16563 ************************************************************************/
16565 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16566 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16567 EMACS_INT
*, EMACS_INT
*);
16568 static struct glyph_row
*
16569 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16570 struct glyph_row
*);
16573 /* Return the last row in MATRIX displaying text. If row START is
16574 non-null, start searching with that row. IT gives the dimensions
16575 of the display. Value is null if matrix is empty; otherwise it is
16576 a pointer to the row found. */
16578 static struct glyph_row
*
16579 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16580 struct glyph_row
*start
)
16582 struct glyph_row
*row
, *row_found
;
16584 /* Set row_found to the last row in IT->w's current matrix
16585 displaying text. The loop looks funny but think of partially
16588 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16589 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16591 xassert (row
->enabled_p
);
16593 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16602 /* Return the last row in the current matrix of W that is not affected
16603 by changes at the start of current_buffer that occurred since W's
16604 current matrix was built. Value is null if no such row exists.
16606 BEG_UNCHANGED us the number of characters unchanged at the start of
16607 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16608 first changed character in current_buffer. Characters at positions <
16609 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16610 when the current matrix was built. */
16612 static struct glyph_row
*
16613 find_last_unchanged_at_beg_row (struct window
*w
)
16615 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16616 struct glyph_row
*row
;
16617 struct glyph_row
*row_found
= NULL
;
16618 int yb
= window_text_bottom_y (w
);
16620 /* Find the last row displaying unchanged text. */
16621 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16622 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16623 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16626 if (/* If row ends before first_changed_pos, it is unchanged,
16627 except in some case. */
16628 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16629 /* When row ends in ZV and we write at ZV it is not
16631 && !row
->ends_at_zv_p
16632 /* When first_changed_pos is the end of a continued line,
16633 row is not unchanged because it may be no longer
16635 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16636 && (row
->continued_p
16637 || row
->exact_window_width_line_p
))
16638 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16639 needs to be recomputed, so don't consider this row as
16640 unchanged. This happens when the last line was
16641 bidi-reordered and was killed immediately before this
16642 redisplay cycle. In that case, ROW->end stores the
16643 buffer position of the first visual-order character of
16644 the killed text, which is now beyond ZV. */
16645 && CHARPOS (row
->end
.pos
) <= ZV
)
16648 /* Stop if last visible row. */
16649 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16657 /* Find the first glyph row in the current matrix of W that is not
16658 affected by changes at the end of current_buffer since the
16659 time W's current matrix was built.
16661 Return in *DELTA the number of chars by which buffer positions in
16662 unchanged text at the end of current_buffer must be adjusted.
16664 Return in *DELTA_BYTES the corresponding number of bytes.
16666 Value is null if no such row exists, i.e. all rows are affected by
16669 static struct glyph_row
*
16670 find_first_unchanged_at_end_row (struct window
*w
,
16671 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
16673 struct glyph_row
*row
;
16674 struct glyph_row
*row_found
= NULL
;
16676 *delta
= *delta_bytes
= 0;
16678 /* Display must not have been paused, otherwise the current matrix
16679 is not up to date. */
16680 eassert (!NILP (w
->window_end_valid
));
16682 /* A value of window_end_pos >= END_UNCHANGED means that the window
16683 end is in the range of changed text. If so, there is no
16684 unchanged row at the end of W's current matrix. */
16685 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16688 /* Set row to the last row in W's current matrix displaying text. */
16689 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16691 /* If matrix is entirely empty, no unchanged row exists. */
16692 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16694 /* The value of row is the last glyph row in the matrix having a
16695 meaningful buffer position in it. The end position of row
16696 corresponds to window_end_pos. This allows us to translate
16697 buffer positions in the current matrix to current buffer
16698 positions for characters not in changed text. */
16700 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16701 EMACS_INT Z_BYTE_old
=
16702 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16703 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
16704 struct glyph_row
*first_text_row
16705 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16707 *delta
= Z
- Z_old
;
16708 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16710 /* Set last_unchanged_pos to the buffer position of the last
16711 character in the buffer that has not been changed. Z is the
16712 index + 1 of the last character in current_buffer, i.e. by
16713 subtracting END_UNCHANGED we get the index of the last
16714 unchanged character, and we have to add BEG to get its buffer
16716 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16717 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16719 /* Search backward from ROW for a row displaying a line that
16720 starts at a minimum position >= last_unchanged_pos_old. */
16721 for (; row
> first_text_row
; --row
)
16723 /* This used to abort, but it can happen.
16724 It is ok to just stop the search instead here. KFS. */
16725 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16728 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16733 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16739 /* Make sure that glyph rows in the current matrix of window W
16740 reference the same glyph memory as corresponding rows in the
16741 frame's frame matrix. This function is called after scrolling W's
16742 current matrix on a terminal frame in try_window_id and
16743 try_window_reusing_current_matrix. */
16746 sync_frame_with_window_matrix_rows (struct window
*w
)
16748 struct frame
*f
= XFRAME (w
->frame
);
16749 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16751 /* Preconditions: W must be a leaf window and full-width. Its frame
16752 must have a frame matrix. */
16753 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16754 xassert (WINDOW_FULL_WIDTH_P (w
));
16755 xassert (!FRAME_WINDOW_P (f
));
16757 /* If W is a full-width window, glyph pointers in W's current matrix
16758 have, by definition, to be the same as glyph pointers in the
16759 corresponding frame matrix. Note that frame matrices have no
16760 marginal areas (see build_frame_matrix). */
16761 window_row
= w
->current_matrix
->rows
;
16762 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16763 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16764 while (window_row
< window_row_end
)
16766 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16767 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16769 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16770 frame_row
->glyphs
[TEXT_AREA
] = start
;
16771 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16772 frame_row
->glyphs
[LAST_AREA
] = end
;
16774 /* Disable frame rows whose corresponding window rows have
16775 been disabled in try_window_id. */
16776 if (!window_row
->enabled_p
)
16777 frame_row
->enabled_p
= 0;
16779 ++window_row
, ++frame_row
;
16784 /* Find the glyph row in window W containing CHARPOS. Consider all
16785 rows between START and END (not inclusive). END null means search
16786 all rows to the end of the display area of W. Value is the row
16787 containing CHARPOS or null. */
16790 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
16791 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16793 struct glyph_row
*row
= start
;
16794 struct glyph_row
*best_row
= NULL
;
16795 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16798 /* If we happen to start on a header-line, skip that. */
16799 if (row
->mode_line_p
)
16802 if ((end
&& row
>= end
) || !row
->enabled_p
)
16805 last_y
= window_text_bottom_y (w
) - dy
;
16809 /* Give up if we have gone too far. */
16810 if (end
&& row
>= end
)
16812 /* This formerly returned if they were equal.
16813 I think that both quantities are of a "last plus one" type;
16814 if so, when they are equal, the row is within the screen. -- rms. */
16815 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16818 /* If it is in this row, return this row. */
16819 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16820 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16821 /* The end position of a row equals the start
16822 position of the next row. If CHARPOS is there, we
16823 would rather display it in the next line, except
16824 when this line ends in ZV. */
16825 && !row
->ends_at_zv_p
16826 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16827 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16831 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16832 || (!best_row
&& !row
->continued_p
))
16834 /* In bidi-reordered rows, there could be several rows
16835 occluding point, all of them belonging to the same
16836 continued line. We need to find the row which fits
16837 CHARPOS the best. */
16838 for (g
= row
->glyphs
[TEXT_AREA
];
16839 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16842 if (!STRINGP (g
->object
))
16844 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16846 mindif
= eabs (g
->charpos
- charpos
);
16848 /* Exact match always wins. */
16855 else if (best_row
&& !row
->continued_p
)
16862 /* Try to redisplay window W by reusing its existing display. W's
16863 current matrix must be up to date when this function is called,
16864 i.e. window_end_valid must not be nil.
16868 1 if display has been updated
16869 0 if otherwise unsuccessful
16870 -1 if redisplay with same window start is known not to succeed
16872 The following steps are performed:
16874 1. Find the last row in the current matrix of W that is not
16875 affected by changes at the start of current_buffer. If no such row
16878 2. Find the first row in W's current matrix that is not affected by
16879 changes at the end of current_buffer. Maybe there is no such row.
16881 3. Display lines beginning with the row + 1 found in step 1 to the
16882 row found in step 2 or, if step 2 didn't find a row, to the end of
16885 4. If cursor is not known to appear on the window, give up.
16887 5. If display stopped at the row found in step 2, scroll the
16888 display and current matrix as needed.
16890 6. Maybe display some lines at the end of W, if we must. This can
16891 happen under various circumstances, like a partially visible line
16892 becoming fully visible, or because newly displayed lines are displayed
16893 in smaller font sizes.
16895 7. Update W's window end information. */
16898 try_window_id (struct window
*w
)
16900 struct frame
*f
= XFRAME (w
->frame
);
16901 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16902 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16903 struct glyph_row
*last_unchanged_at_beg_row
;
16904 struct glyph_row
*first_unchanged_at_end_row
;
16905 struct glyph_row
*row
;
16906 struct glyph_row
*bottom_row
;
16909 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
16911 struct text_pos start_pos
;
16913 int first_unchanged_at_end_vpos
= 0;
16914 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16915 struct text_pos start
;
16916 EMACS_INT first_changed_charpos
, last_changed_charpos
;
16919 if (inhibit_try_window_id
)
16923 /* This is handy for debugging. */
16925 #define GIVE_UP(X) \
16927 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16931 #define GIVE_UP(X) return 0
16934 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16936 /* Don't use this for mini-windows because these can show
16937 messages and mini-buffers, and we don't handle that here. */
16938 if (MINI_WINDOW_P (w
))
16941 /* This flag is used to prevent redisplay optimizations. */
16942 if (windows_or_buffers_changed
|| cursor_type_changed
)
16945 /* Verify that narrowing has not changed.
16946 Also verify that we were not told to prevent redisplay optimizations.
16947 It would be nice to further
16948 reduce the number of cases where this prevents try_window_id. */
16949 if (current_buffer
->clip_changed
16950 || current_buffer
->prevent_redisplay_optimizations_p
)
16953 /* Window must either use window-based redisplay or be full width. */
16954 if (!FRAME_WINDOW_P (f
)
16955 && (!FRAME_LINE_INS_DEL_OK (f
)
16956 || !WINDOW_FULL_WIDTH_P (w
)))
16959 /* Give up if point is known NOT to appear in W. */
16960 if (PT
< CHARPOS (start
))
16963 /* Another way to prevent redisplay optimizations. */
16964 if (XFASTINT (w
->last_modified
) == 0)
16967 /* Verify that window is not hscrolled. */
16968 if (XFASTINT (w
->hscroll
) != 0)
16971 /* Verify that display wasn't paused. */
16972 if (NILP (w
->window_end_valid
))
16975 /* Can't use this if highlighting a region because a cursor movement
16976 will do more than just set the cursor. */
16977 if (!NILP (Vtransient_mark_mode
)
16978 && !NILP (BVAR (current_buffer
, mark_active
)))
16981 /* Likewise if highlighting trailing whitespace. */
16982 if (!NILP (Vshow_trailing_whitespace
))
16985 /* Likewise if showing a region. */
16986 if (!NILP (w
->region_showing
))
16989 /* Can't use this if overlay arrow position and/or string have
16991 if (overlay_arrows_changed_p ())
16994 /* When word-wrap is on, adding a space to the first word of a
16995 wrapped line can change the wrap position, altering the line
16996 above it. It might be worthwhile to handle this more
16997 intelligently, but for now just redisplay from scratch. */
16998 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17001 /* Under bidi reordering, adding or deleting a character in the
17002 beginning of a paragraph, before the first strong directional
17003 character, can change the base direction of the paragraph (unless
17004 the buffer specifies a fixed paragraph direction), which will
17005 require to redisplay the whole paragraph. It might be worthwhile
17006 to find the paragraph limits and widen the range of redisplayed
17007 lines to that, but for now just give up this optimization and
17008 redisplay from scratch. */
17009 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17010 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17013 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17014 only if buffer has really changed. The reason is that the gap is
17015 initially at Z for freshly visited files. The code below would
17016 set end_unchanged to 0 in that case. */
17017 if (MODIFF
> SAVE_MODIFF
17018 /* This seems to happen sometimes after saving a buffer. */
17019 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17021 if (GPT
- BEG
< BEG_UNCHANGED
)
17022 BEG_UNCHANGED
= GPT
- BEG
;
17023 if (Z
- GPT
< END_UNCHANGED
)
17024 END_UNCHANGED
= Z
- GPT
;
17027 /* The position of the first and last character that has been changed. */
17028 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17029 last_changed_charpos
= Z
- END_UNCHANGED
;
17031 /* If window starts after a line end, and the last change is in
17032 front of that newline, then changes don't affect the display.
17033 This case happens with stealth-fontification. Note that although
17034 the display is unchanged, glyph positions in the matrix have to
17035 be adjusted, of course. */
17036 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17037 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17038 && ((last_changed_charpos
< CHARPOS (start
)
17039 && CHARPOS (start
) == BEGV
)
17040 || (last_changed_charpos
< CHARPOS (start
) - 1
17041 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17043 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17044 struct glyph_row
*r0
;
17046 /* Compute how many chars/bytes have been added to or removed
17047 from the buffer. */
17048 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17049 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17050 Z_delta
= Z
- Z_old
;
17051 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17053 /* Give up if PT is not in the window. Note that it already has
17054 been checked at the start of try_window_id that PT is not in
17055 front of the window start. */
17056 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17059 /* If window start is unchanged, we can reuse the whole matrix
17060 as is, after adjusting glyph positions. No need to compute
17061 the window end again, since its offset from Z hasn't changed. */
17062 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17063 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17064 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17065 /* PT must not be in a partially visible line. */
17066 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17067 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17069 /* Adjust positions in the glyph matrix. */
17070 if (Z_delta
|| Z_delta_bytes
)
17072 struct glyph_row
*r1
17073 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17074 increment_matrix_positions (w
->current_matrix
,
17075 MATRIX_ROW_VPOS (r0
, current_matrix
),
17076 MATRIX_ROW_VPOS (r1
, current_matrix
),
17077 Z_delta
, Z_delta_bytes
);
17080 /* Set the cursor. */
17081 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17083 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17090 /* Handle the case that changes are all below what is displayed in
17091 the window, and that PT is in the window. This shortcut cannot
17092 be taken if ZV is visible in the window, and text has been added
17093 there that is visible in the window. */
17094 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17095 /* ZV is not visible in the window, or there are no
17096 changes at ZV, actually. */
17097 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17098 || first_changed_charpos
== last_changed_charpos
))
17100 struct glyph_row
*r0
;
17102 /* Give up if PT is not in the window. Note that it already has
17103 been checked at the start of try_window_id that PT is not in
17104 front of the window start. */
17105 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17108 /* If window start is unchanged, we can reuse the whole matrix
17109 as is, without changing glyph positions since no text has
17110 been added/removed in front of the window end. */
17111 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17112 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17113 /* PT must not be in a partially visible line. */
17114 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17115 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17117 /* We have to compute the window end anew since text
17118 could have been added/removed after it. */
17120 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17121 w
->window_end_bytepos
17122 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17124 /* Set the cursor. */
17125 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17127 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17134 /* Give up if window start is in the changed area.
17136 The condition used to read
17138 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17140 but why that was tested escapes me at the moment. */
17141 if (CHARPOS (start
) >= first_changed_charpos
17142 && CHARPOS (start
) <= last_changed_charpos
)
17145 /* Check that window start agrees with the start of the first glyph
17146 row in its current matrix. Check this after we know the window
17147 start is not in changed text, otherwise positions would not be
17149 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17150 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17153 /* Give up if the window ends in strings. Overlay strings
17154 at the end are difficult to handle, so don't try. */
17155 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17156 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17159 /* Compute the position at which we have to start displaying new
17160 lines. Some of the lines at the top of the window might be
17161 reusable because they are not displaying changed text. Find the
17162 last row in W's current matrix not affected by changes at the
17163 start of current_buffer. Value is null if changes start in the
17164 first line of window. */
17165 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17166 if (last_unchanged_at_beg_row
)
17168 /* Avoid starting to display in the middle of a character, a TAB
17169 for instance. This is easier than to set up the iterator
17170 exactly, and it's not a frequent case, so the additional
17171 effort wouldn't really pay off. */
17172 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17173 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17174 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17175 --last_unchanged_at_beg_row
;
17177 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17180 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17182 start_pos
= it
.current
.pos
;
17184 /* Start displaying new lines in the desired matrix at the same
17185 vpos we would use in the current matrix, i.e. below
17186 last_unchanged_at_beg_row. */
17187 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17189 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17190 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17192 xassert (it
.hpos
== 0 && it
.current_x
== 0);
17196 /* There are no reusable lines at the start of the window.
17197 Start displaying in the first text line. */
17198 start_display (&it
, w
, start
);
17199 it
.vpos
= it
.first_vpos
;
17200 start_pos
= it
.current
.pos
;
17203 /* Find the first row that is not affected by changes at the end of
17204 the buffer. Value will be null if there is no unchanged row, in
17205 which case we must redisplay to the end of the window. delta
17206 will be set to the value by which buffer positions beginning with
17207 first_unchanged_at_end_row have to be adjusted due to text
17209 first_unchanged_at_end_row
17210 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17211 IF_DEBUG (debug_delta
= delta
);
17212 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17214 /* Set stop_pos to the buffer position up to which we will have to
17215 display new lines. If first_unchanged_at_end_row != NULL, this
17216 is the buffer position of the start of the line displayed in that
17217 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17218 that we don't stop at a buffer position. */
17220 if (first_unchanged_at_end_row
)
17222 xassert (last_unchanged_at_beg_row
== NULL
17223 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17225 /* If this is a continuation line, move forward to the next one
17226 that isn't. Changes in lines above affect this line.
17227 Caution: this may move first_unchanged_at_end_row to a row
17228 not displaying text. */
17229 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17230 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17231 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17232 < it
.last_visible_y
))
17233 ++first_unchanged_at_end_row
;
17235 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17236 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17237 >= it
.last_visible_y
))
17238 first_unchanged_at_end_row
= NULL
;
17241 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17243 first_unchanged_at_end_vpos
17244 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17245 xassert (stop_pos
>= Z
- END_UNCHANGED
);
17248 else if (last_unchanged_at_beg_row
== NULL
)
17254 /* Either there is no unchanged row at the end, or the one we have
17255 now displays text. This is a necessary condition for the window
17256 end pos calculation at the end of this function. */
17257 xassert (first_unchanged_at_end_row
== NULL
17258 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17260 debug_last_unchanged_at_beg_vpos
17261 = (last_unchanged_at_beg_row
17262 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17264 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17266 #endif /* GLYPH_DEBUG != 0 */
17269 /* Display new lines. Set last_text_row to the last new line
17270 displayed which has text on it, i.e. might end up as being the
17271 line where the window_end_vpos is. */
17272 w
->cursor
.vpos
= -1;
17273 last_text_row
= NULL
;
17274 overlay_arrow_seen
= 0;
17275 while (it
.current_y
< it
.last_visible_y
17276 && !fonts_changed_p
17277 && (first_unchanged_at_end_row
== NULL
17278 || IT_CHARPOS (it
) < stop_pos
))
17280 if (display_line (&it
))
17281 last_text_row
= it
.glyph_row
- 1;
17284 if (fonts_changed_p
)
17288 /* Compute differences in buffer positions, y-positions etc. for
17289 lines reused at the bottom of the window. Compute what we can
17291 if (first_unchanged_at_end_row
17292 /* No lines reused because we displayed everything up to the
17293 bottom of the window. */
17294 && it
.current_y
< it
.last_visible_y
)
17297 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17299 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17300 run
.current_y
= first_unchanged_at_end_row
->y
;
17301 run
.desired_y
= run
.current_y
+ dy
;
17302 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17306 delta
= delta_bytes
= dvpos
= dy
17307 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17308 first_unchanged_at_end_row
= NULL
;
17310 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17313 /* Find the cursor if not already found. We have to decide whether
17314 PT will appear on this window (it sometimes doesn't, but this is
17315 not a very frequent case.) This decision has to be made before
17316 the current matrix is altered. A value of cursor.vpos < 0 means
17317 that PT is either in one of the lines beginning at
17318 first_unchanged_at_end_row or below the window. Don't care for
17319 lines that might be displayed later at the window end; as
17320 mentioned, this is not a frequent case. */
17321 if (w
->cursor
.vpos
< 0)
17323 /* Cursor in unchanged rows at the top? */
17324 if (PT
< CHARPOS (start_pos
)
17325 && last_unchanged_at_beg_row
)
17327 row
= row_containing_pos (w
, PT
,
17328 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17329 last_unchanged_at_beg_row
+ 1, 0);
17331 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17334 /* Start from first_unchanged_at_end_row looking for PT. */
17335 else if (first_unchanged_at_end_row
)
17337 row
= row_containing_pos (w
, PT
- delta
,
17338 first_unchanged_at_end_row
, NULL
, 0);
17340 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17341 delta_bytes
, dy
, dvpos
);
17344 /* Give up if cursor was not found. */
17345 if (w
->cursor
.vpos
< 0)
17347 clear_glyph_matrix (w
->desired_matrix
);
17352 /* Don't let the cursor end in the scroll margins. */
17354 int this_scroll_margin
, cursor_height
;
17356 this_scroll_margin
=
17357 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17358 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17359 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17361 if ((w
->cursor
.y
< this_scroll_margin
17362 && CHARPOS (start
) > BEGV
)
17363 /* Old redisplay didn't take scroll margin into account at the bottom,
17364 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17365 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17366 ? cursor_height
+ this_scroll_margin
17367 : 1)) > it
.last_visible_y
)
17369 w
->cursor
.vpos
= -1;
17370 clear_glyph_matrix (w
->desired_matrix
);
17375 /* Scroll the display. Do it before changing the current matrix so
17376 that xterm.c doesn't get confused about where the cursor glyph is
17378 if (dy
&& run
.height
)
17382 if (FRAME_WINDOW_P (f
))
17384 FRAME_RIF (f
)->update_window_begin_hook (w
);
17385 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17386 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17387 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17391 /* Terminal frame. In this case, dvpos gives the number of
17392 lines to scroll by; dvpos < 0 means scroll up. */
17394 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17395 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17396 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17397 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17398 + window_internal_height (w
));
17400 #if defined (HAVE_GPM) || defined (MSDOS)
17401 x_clear_window_mouse_face (w
);
17403 /* Perform the operation on the screen. */
17406 /* Scroll last_unchanged_at_beg_row to the end of the
17407 window down dvpos lines. */
17408 set_terminal_window (f
, end
);
17410 /* On dumb terminals delete dvpos lines at the end
17411 before inserting dvpos empty lines. */
17412 if (!FRAME_SCROLL_REGION_OK (f
))
17413 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17415 /* Insert dvpos empty lines in front of
17416 last_unchanged_at_beg_row. */
17417 ins_del_lines (f
, from
, dvpos
);
17419 else if (dvpos
< 0)
17421 /* Scroll up last_unchanged_at_beg_vpos to the end of
17422 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17423 set_terminal_window (f
, end
);
17425 /* Delete dvpos lines in front of
17426 last_unchanged_at_beg_vpos. ins_del_lines will set
17427 the cursor to the given vpos and emit |dvpos| delete
17429 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17431 /* On a dumb terminal insert dvpos empty lines at the
17433 if (!FRAME_SCROLL_REGION_OK (f
))
17434 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17437 set_terminal_window (f
, 0);
17443 /* Shift reused rows of the current matrix to the right position.
17444 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17446 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17447 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17450 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17451 bottom_vpos
, dvpos
);
17452 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17455 else if (dvpos
> 0)
17457 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17458 bottom_vpos
, dvpos
);
17459 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17460 first_unchanged_at_end_vpos
+ dvpos
, 0);
17463 /* For frame-based redisplay, make sure that current frame and window
17464 matrix are in sync with respect to glyph memory. */
17465 if (!FRAME_WINDOW_P (f
))
17466 sync_frame_with_window_matrix_rows (w
);
17468 /* Adjust buffer positions in reused rows. */
17469 if (delta
|| delta_bytes
)
17470 increment_matrix_positions (current_matrix
,
17471 first_unchanged_at_end_vpos
+ dvpos
,
17472 bottom_vpos
, delta
, delta_bytes
);
17474 /* Adjust Y positions. */
17476 shift_glyph_matrix (w
, current_matrix
,
17477 first_unchanged_at_end_vpos
+ dvpos
,
17480 if (first_unchanged_at_end_row
)
17482 first_unchanged_at_end_row
+= dvpos
;
17483 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17484 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17485 first_unchanged_at_end_row
= NULL
;
17488 /* If scrolling up, there may be some lines to display at the end of
17490 last_text_row_at_end
= NULL
;
17493 /* Scrolling up can leave for example a partially visible line
17494 at the end of the window to be redisplayed. */
17495 /* Set last_row to the glyph row in the current matrix where the
17496 window end line is found. It has been moved up or down in
17497 the matrix by dvpos. */
17498 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17499 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17501 /* If last_row is the window end line, it should display text. */
17502 xassert (last_row
->displays_text_p
);
17504 /* If window end line was partially visible before, begin
17505 displaying at that line. Otherwise begin displaying with the
17506 line following it. */
17507 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17509 init_to_row_start (&it
, w
, last_row
);
17510 it
.vpos
= last_vpos
;
17511 it
.current_y
= last_row
->y
;
17515 init_to_row_end (&it
, w
, last_row
);
17516 it
.vpos
= 1 + last_vpos
;
17517 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17521 /* We may start in a continuation line. If so, we have to
17522 get the right continuation_lines_width and current_x. */
17523 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17524 it
.hpos
= it
.current_x
= 0;
17526 /* Display the rest of the lines at the window end. */
17527 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17528 while (it
.current_y
< it
.last_visible_y
17529 && !fonts_changed_p
)
17531 /* Is it always sure that the display agrees with lines in
17532 the current matrix? I don't think so, so we mark rows
17533 displayed invalid in the current matrix by setting their
17534 enabled_p flag to zero. */
17535 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17536 if (display_line (&it
))
17537 last_text_row_at_end
= it
.glyph_row
- 1;
17541 /* Update window_end_pos and window_end_vpos. */
17542 if (first_unchanged_at_end_row
17543 && !last_text_row_at_end
)
17545 /* Window end line if one of the preserved rows from the current
17546 matrix. Set row to the last row displaying text in current
17547 matrix starting at first_unchanged_at_end_row, after
17549 xassert (first_unchanged_at_end_row
->displays_text_p
);
17550 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17551 first_unchanged_at_end_row
);
17552 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17554 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17555 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17557 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17558 xassert (w
->window_end_bytepos
>= 0);
17559 IF_DEBUG (debug_method_add (w
, "A"));
17561 else if (last_text_row_at_end
)
17564 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17565 w
->window_end_bytepos
17566 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17568 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17569 xassert (w
->window_end_bytepos
>= 0);
17570 IF_DEBUG (debug_method_add (w
, "B"));
17572 else if (last_text_row
)
17574 /* We have displayed either to the end of the window or at the
17575 end of the window, i.e. the last row with text is to be found
17576 in the desired matrix. */
17578 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17579 w
->window_end_bytepos
17580 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17582 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17583 xassert (w
->window_end_bytepos
>= 0);
17585 else if (first_unchanged_at_end_row
== NULL
17586 && last_text_row
== NULL
17587 && last_text_row_at_end
== NULL
)
17589 /* Displayed to end of window, but no line containing text was
17590 displayed. Lines were deleted at the end of the window. */
17591 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17592 int vpos
= XFASTINT (w
->window_end_vpos
);
17593 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17594 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17597 row
== NULL
&& vpos
>= first_vpos
;
17598 --vpos
, --current_row
, --desired_row
)
17600 if (desired_row
->enabled_p
)
17602 if (desired_row
->displays_text_p
)
17605 else if (current_row
->displays_text_p
)
17609 xassert (row
!= NULL
);
17610 w
->window_end_vpos
= make_number (vpos
+ 1);
17611 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17612 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17613 xassert (w
->window_end_bytepos
>= 0);
17614 IF_DEBUG (debug_method_add (w
, "C"));
17619 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17620 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17622 /* Record that display has not been completed. */
17623 w
->window_end_valid
= Qnil
;
17624 w
->desired_matrix
->no_scrolling_p
= 1;
17632 /***********************************************************************
17633 More debugging support
17634 ***********************************************************************/
17638 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17639 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17640 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17643 /* Dump the contents of glyph matrix MATRIX on stderr.
17645 GLYPHS 0 means don't show glyph contents.
17646 GLYPHS 1 means show glyphs in short form
17647 GLYPHS > 1 means show glyphs in long form. */
17650 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17653 for (i
= 0; i
< matrix
->nrows
; ++i
)
17654 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17658 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17659 the glyph row and area where the glyph comes from. */
17662 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17664 if (glyph
->type
== CHAR_GLYPH
)
17667 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17668 glyph
- row
->glyphs
[TEXT_AREA
],
17671 (BUFFERP (glyph
->object
)
17673 : (STRINGP (glyph
->object
)
17676 glyph
->pixel_width
,
17678 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17682 glyph
->left_box_line_p
,
17683 glyph
->right_box_line_p
);
17685 else if (glyph
->type
== STRETCH_GLYPH
)
17688 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17689 glyph
- row
->glyphs
[TEXT_AREA
],
17692 (BUFFERP (glyph
->object
)
17694 : (STRINGP (glyph
->object
)
17697 glyph
->pixel_width
,
17701 glyph
->left_box_line_p
,
17702 glyph
->right_box_line_p
);
17704 else if (glyph
->type
== IMAGE_GLYPH
)
17707 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17708 glyph
- row
->glyphs
[TEXT_AREA
],
17711 (BUFFERP (glyph
->object
)
17713 : (STRINGP (glyph
->object
)
17716 glyph
->pixel_width
,
17720 glyph
->left_box_line_p
,
17721 glyph
->right_box_line_p
);
17723 else if (glyph
->type
== COMPOSITE_GLYPH
)
17726 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17727 glyph
- row
->glyphs
[TEXT_AREA
],
17730 (BUFFERP (glyph
->object
)
17732 : (STRINGP (glyph
->object
)
17735 glyph
->pixel_width
,
17737 if (glyph
->u
.cmp
.automatic
)
17740 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17741 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17743 glyph
->left_box_line_p
,
17744 glyph
->right_box_line_p
);
17749 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17750 GLYPHS 0 means don't show glyph contents.
17751 GLYPHS 1 means show glyphs in short form
17752 GLYPHS > 1 means show glyphs in long form. */
17755 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17759 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17760 fprintf (stderr
, "======================================================================\n");
17762 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17763 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17765 MATRIX_ROW_START_CHARPOS (row
),
17766 MATRIX_ROW_END_CHARPOS (row
),
17767 row
->used
[TEXT_AREA
],
17768 row
->contains_overlapping_glyphs_p
,
17770 row
->truncated_on_left_p
,
17771 row
->truncated_on_right_p
,
17773 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17774 row
->displays_text_p
,
17777 row
->ends_in_middle_of_char_p
,
17778 row
->starts_in_middle_of_char_p
,
17784 row
->visible_height
,
17787 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
17788 row
->end
.overlay_string_index
,
17789 row
->continuation_lines_width
);
17790 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17791 CHARPOS (row
->start
.string_pos
),
17792 CHARPOS (row
->end
.string_pos
));
17793 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17794 row
->end
.dpvec_index
);
17801 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17803 struct glyph
*glyph
= row
->glyphs
[area
];
17804 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17806 /* Glyph for a line end in text. */
17807 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17810 if (glyph
< glyph_end
)
17811 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
17813 for (; glyph
< glyph_end
; ++glyph
)
17814 dump_glyph (row
, glyph
, area
);
17817 else if (glyphs
== 1)
17821 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17823 char *s
= (char *) alloca (row
->used
[area
] + 1);
17826 for (i
= 0; i
< row
->used
[area
]; ++i
)
17828 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17829 if (glyph
->type
== CHAR_GLYPH
17830 && glyph
->u
.ch
< 0x80
17831 && glyph
->u
.ch
>= ' ')
17832 s
[i
] = glyph
->u
.ch
;
17838 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17844 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17845 Sdump_glyph_matrix
, 0, 1, "p",
17846 doc
: /* Dump the current matrix of the selected window to stderr.
17847 Shows contents of glyph row structures. With non-nil
17848 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17849 glyphs in short form, otherwise show glyphs in long form. */)
17850 (Lisp_Object glyphs
)
17852 struct window
*w
= XWINDOW (selected_window
);
17853 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17855 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17856 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17857 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17858 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17859 fprintf (stderr
, "=============================================\n");
17860 dump_glyph_matrix (w
->current_matrix
,
17861 NILP (glyphs
) ? 0 : XINT (glyphs
));
17866 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17867 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17870 struct frame
*f
= XFRAME (selected_frame
);
17871 dump_glyph_matrix (f
->current_matrix
, 1);
17876 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17877 doc
: /* Dump glyph row ROW to stderr.
17878 GLYPH 0 means don't dump glyphs.
17879 GLYPH 1 means dump glyphs in short form.
17880 GLYPH > 1 or omitted means dump glyphs in long form. */)
17881 (Lisp_Object row
, Lisp_Object glyphs
)
17883 struct glyph_matrix
*matrix
;
17886 CHECK_NUMBER (row
);
17887 matrix
= XWINDOW (selected_window
)->current_matrix
;
17889 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17890 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17892 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17897 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17898 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17899 GLYPH 0 means don't dump glyphs.
17900 GLYPH 1 means dump glyphs in short form.
17901 GLYPH > 1 or omitted means dump glyphs in long form. */)
17902 (Lisp_Object row
, Lisp_Object glyphs
)
17904 struct frame
*sf
= SELECTED_FRAME ();
17905 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17908 CHECK_NUMBER (row
);
17910 if (vpos
>= 0 && vpos
< m
->nrows
)
17911 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17912 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17917 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17918 doc
: /* Toggle tracing of redisplay.
17919 With ARG, turn tracing on if and only if ARG is positive. */)
17923 trace_redisplay_p
= !trace_redisplay_p
;
17926 arg
= Fprefix_numeric_value (arg
);
17927 trace_redisplay_p
= XINT (arg
) > 0;
17934 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17935 doc
: /* Like `format', but print result to stderr.
17936 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17937 (ptrdiff_t nargs
, Lisp_Object
*args
)
17939 Lisp_Object s
= Fformat (nargs
, args
);
17940 fprintf (stderr
, "%s", SDATA (s
));
17944 #endif /* GLYPH_DEBUG */
17948 /***********************************************************************
17949 Building Desired Matrix Rows
17950 ***********************************************************************/
17952 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17953 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17955 static struct glyph_row
*
17956 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17958 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17959 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17960 struct buffer
*old
= current_buffer
;
17961 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17962 int arrow_len
= SCHARS (overlay_arrow_string
);
17963 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17964 const unsigned char *p
;
17967 int n_glyphs_before
;
17969 set_buffer_temp (buffer
);
17970 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17971 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17972 SET_TEXT_POS (it
.position
, 0, 0);
17974 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17976 while (p
< arrow_end
)
17978 Lisp_Object face
, ilisp
;
17980 /* Get the next character. */
17982 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17985 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17986 if (! ASCII_CHAR_P (it
.c
))
17987 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17991 /* Get its face. */
17992 ilisp
= make_number (p
- arrow_string
);
17993 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17994 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17996 /* Compute its width, get its glyphs. */
17997 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17998 SET_TEXT_POS (it
.position
, -1, -1);
17999 PRODUCE_GLYPHS (&it
);
18001 /* If this character doesn't fit any more in the line, we have
18002 to remove some glyphs. */
18003 if (it
.current_x
> it
.last_visible_x
)
18005 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18010 set_buffer_temp (old
);
18011 return it
.glyph_row
;
18015 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
18016 glyphs are only inserted for terminal frames since we can't really
18017 win with truncation glyphs when partially visible glyphs are
18018 involved. Which glyphs to insert is determined by
18019 produce_special_glyphs. */
18022 insert_left_trunc_glyphs (struct it
*it
)
18024 struct it truncate_it
;
18025 struct glyph
*from
, *end
, *to
, *toend
;
18027 xassert (!FRAME_WINDOW_P (it
->f
));
18029 /* Get the truncation glyphs. */
18031 truncate_it
.current_x
= 0;
18032 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18033 truncate_it
.glyph_row
= &scratch_glyph_row
;
18034 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18035 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18036 truncate_it
.object
= make_number (0);
18037 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18039 /* Overwrite glyphs from IT with truncation glyphs. */
18040 if (!it
->glyph_row
->reversed_p
)
18042 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18043 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
18044 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18045 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18050 /* There may be padding glyphs left over. Overwrite them too. */
18051 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18053 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18059 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18063 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18064 that back to front. */
18065 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18066 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18067 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18068 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18070 while (from
>= end
&& to
>= toend
)
18072 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18075 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18076 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18077 while (from
>= end
&& to
>= toend
)
18082 /* Need to free some room before prepending additional
18084 int move_by
= from
- end
+ 1;
18085 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18086 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18088 for ( ; g
>= g0
; g
--)
18090 while (from
>= end
)
18092 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18097 /* Compute the hash code for ROW. */
18099 row_hash (struct glyph_row
*row
)
18102 unsigned hashval
= 0;
18104 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18105 for (k
= 0; k
< row
->used
[area
]; ++k
)
18106 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18107 + row
->glyphs
[area
][k
].u
.val
18108 + row
->glyphs
[area
][k
].face_id
18109 + row
->glyphs
[area
][k
].padding_p
18110 + (row
->glyphs
[area
][k
].type
<< 2));
18115 /* Compute the pixel height and width of IT->glyph_row.
18117 Most of the time, ascent and height of a display line will be equal
18118 to the max_ascent and max_height values of the display iterator
18119 structure. This is not the case if
18121 1. We hit ZV without displaying anything. In this case, max_ascent
18122 and max_height will be zero.
18124 2. We have some glyphs that don't contribute to the line height.
18125 (The glyph row flag contributes_to_line_height_p is for future
18126 pixmap extensions).
18128 The first case is easily covered by using default values because in
18129 these cases, the line height does not really matter, except that it
18130 must not be zero. */
18133 compute_line_metrics (struct it
*it
)
18135 struct glyph_row
*row
= it
->glyph_row
;
18137 if (FRAME_WINDOW_P (it
->f
))
18139 int i
, min_y
, max_y
;
18141 /* The line may consist of one space only, that was added to
18142 place the cursor on it. If so, the row's height hasn't been
18144 if (row
->height
== 0)
18146 if (it
->max_ascent
+ it
->max_descent
== 0)
18147 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18148 row
->ascent
= it
->max_ascent
;
18149 row
->height
= it
->max_ascent
+ it
->max_descent
;
18150 row
->phys_ascent
= it
->max_phys_ascent
;
18151 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18152 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18155 /* Compute the width of this line. */
18156 row
->pixel_width
= row
->x
;
18157 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18158 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18160 xassert (row
->pixel_width
>= 0);
18161 xassert (row
->ascent
>= 0 && row
->height
> 0);
18163 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18164 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18166 /* If first line's physical ascent is larger than its logical
18167 ascent, use the physical ascent, and make the row taller.
18168 This makes accented characters fully visible. */
18169 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18170 && row
->phys_ascent
> row
->ascent
)
18172 row
->height
+= row
->phys_ascent
- row
->ascent
;
18173 row
->ascent
= row
->phys_ascent
;
18176 /* Compute how much of the line is visible. */
18177 row
->visible_height
= row
->height
;
18179 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18180 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18182 if (row
->y
< min_y
)
18183 row
->visible_height
-= min_y
- row
->y
;
18184 if (row
->y
+ row
->height
> max_y
)
18185 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18189 row
->pixel_width
= row
->used
[TEXT_AREA
];
18190 if (row
->continued_p
)
18191 row
->pixel_width
-= it
->continuation_pixel_width
;
18192 else if (row
->truncated_on_right_p
)
18193 row
->pixel_width
-= it
->truncation_pixel_width
;
18194 row
->ascent
= row
->phys_ascent
= 0;
18195 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18196 row
->extra_line_spacing
= 0;
18199 /* Compute a hash code for this row. */
18200 row
->hash
= row_hash (row
);
18202 it
->max_ascent
= it
->max_descent
= 0;
18203 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18207 /* Append one space to the glyph row of iterator IT if doing a
18208 window-based redisplay. The space has the same face as
18209 IT->face_id. Value is non-zero if a space was added.
18211 This function is called to make sure that there is always one glyph
18212 at the end of a glyph row that the cursor can be set on under
18213 window-systems. (If there weren't such a glyph we would not know
18214 how wide and tall a box cursor should be displayed).
18216 At the same time this space let's a nicely handle clearing to the
18217 end of the line if the row ends in italic text. */
18220 append_space_for_newline (struct it
*it
, int default_face_p
)
18222 if (FRAME_WINDOW_P (it
->f
))
18224 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18226 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18227 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18229 /* Save some values that must not be changed.
18230 Must save IT->c and IT->len because otherwise
18231 ITERATOR_AT_END_P wouldn't work anymore after
18232 append_space_for_newline has been called. */
18233 enum display_element_type saved_what
= it
->what
;
18234 int saved_c
= it
->c
, saved_len
= it
->len
;
18235 int saved_char_to_display
= it
->char_to_display
;
18236 int saved_x
= it
->current_x
;
18237 int saved_face_id
= it
->face_id
;
18238 struct text_pos saved_pos
;
18239 Lisp_Object saved_object
;
18242 saved_object
= it
->object
;
18243 saved_pos
= it
->position
;
18245 it
->what
= IT_CHARACTER
;
18246 memset (&it
->position
, 0, sizeof it
->position
);
18247 it
->object
= make_number (0);
18248 it
->c
= it
->char_to_display
= ' ';
18251 /* If the default face was remapped, be sure to use the
18252 remapped face for the appended newline. */
18253 if (default_face_p
)
18254 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18255 else if (it
->face_before_selective_p
)
18256 it
->face_id
= it
->saved_face_id
;
18257 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18258 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18260 PRODUCE_GLYPHS (it
);
18262 it
->override_ascent
= -1;
18263 it
->constrain_row_ascent_descent_p
= 0;
18264 it
->current_x
= saved_x
;
18265 it
->object
= saved_object
;
18266 it
->position
= saved_pos
;
18267 it
->what
= saved_what
;
18268 it
->face_id
= saved_face_id
;
18269 it
->len
= saved_len
;
18271 it
->char_to_display
= saved_char_to_display
;
18280 /* Extend the face of the last glyph in the text area of IT->glyph_row
18281 to the end of the display line. Called from display_line. If the
18282 glyph row is empty, add a space glyph to it so that we know the
18283 face to draw. Set the glyph row flag fill_line_p. If the glyph
18284 row is R2L, prepend a stretch glyph to cover the empty space to the
18285 left of the leftmost glyph. */
18288 extend_face_to_end_of_line (struct it
*it
)
18290 struct face
*face
, *default_face
;
18291 struct frame
*f
= it
->f
;
18293 /* If line is already filled, do nothing. Non window-system frames
18294 get a grace of one more ``pixel'' because their characters are
18295 1-``pixel'' wide, so they hit the equality too early. This grace
18296 is needed only for R2L rows that are not continued, to produce
18297 one extra blank where we could display the cursor. */
18298 if (it
->current_x
>= it
->last_visible_x
18299 + (!FRAME_WINDOW_P (f
)
18300 && it
->glyph_row
->reversed_p
18301 && !it
->glyph_row
->continued_p
))
18304 /* The default face, possibly remapped. */
18305 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18307 /* Face extension extends the background and box of IT->face_id
18308 to the end of the line. If the background equals the background
18309 of the frame, we don't have to do anything. */
18310 if (it
->face_before_selective_p
)
18311 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18313 face
= FACE_FROM_ID (f
, it
->face_id
);
18315 if (FRAME_WINDOW_P (f
)
18316 && it
->glyph_row
->displays_text_p
18317 && face
->box
== FACE_NO_BOX
18318 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18320 && !it
->glyph_row
->reversed_p
)
18323 /* Set the glyph row flag indicating that the face of the last glyph
18324 in the text area has to be drawn to the end of the text area. */
18325 it
->glyph_row
->fill_line_p
= 1;
18327 /* If current character of IT is not ASCII, make sure we have the
18328 ASCII face. This will be automatically undone the next time
18329 get_next_display_element returns a multibyte character. Note
18330 that the character will always be single byte in unibyte
18332 if (!ASCII_CHAR_P (it
->c
))
18334 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18337 if (FRAME_WINDOW_P (f
))
18339 /* If the row is empty, add a space with the current face of IT,
18340 so that we know which face to draw. */
18341 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18343 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18344 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18345 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18347 #ifdef HAVE_WINDOW_SYSTEM
18348 if (it
->glyph_row
->reversed_p
)
18350 /* Prepend a stretch glyph to the row, such that the
18351 rightmost glyph will be drawn flushed all the way to the
18352 right margin of the window. The stretch glyph that will
18353 occupy the empty space, if any, to the left of the
18355 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18356 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18357 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18359 int row_width
, stretch_ascent
, stretch_width
;
18360 struct text_pos saved_pos
;
18361 int saved_face_id
, saved_avoid_cursor
;
18363 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18364 row_width
+= g
->pixel_width
;
18365 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18366 if (stretch_width
> 0)
18369 (((it
->ascent
+ it
->descent
)
18370 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18371 saved_pos
= it
->position
;
18372 memset (&it
->position
, 0, sizeof it
->position
);
18373 saved_avoid_cursor
= it
->avoid_cursor_p
;
18374 it
->avoid_cursor_p
= 1;
18375 saved_face_id
= it
->face_id
;
18376 /* The last row's stretch glyph should get the default
18377 face, to avoid painting the rest of the window with
18378 the region face, if the region ends at ZV. */
18379 if (it
->glyph_row
->ends_at_zv_p
)
18380 it
->face_id
= default_face
->id
;
18382 it
->face_id
= face
->id
;
18383 append_stretch_glyph (it
, make_number (0), stretch_width
,
18384 it
->ascent
+ it
->descent
, stretch_ascent
);
18385 it
->position
= saved_pos
;
18386 it
->avoid_cursor_p
= saved_avoid_cursor
;
18387 it
->face_id
= saved_face_id
;
18390 #endif /* HAVE_WINDOW_SYSTEM */
18394 /* Save some values that must not be changed. */
18395 int saved_x
= it
->current_x
;
18396 struct text_pos saved_pos
;
18397 Lisp_Object saved_object
;
18398 enum display_element_type saved_what
= it
->what
;
18399 int saved_face_id
= it
->face_id
;
18401 saved_object
= it
->object
;
18402 saved_pos
= it
->position
;
18404 it
->what
= IT_CHARACTER
;
18405 memset (&it
->position
, 0, sizeof it
->position
);
18406 it
->object
= make_number (0);
18407 it
->c
= it
->char_to_display
= ' ';
18409 /* The last row's blank glyphs should get the default face, to
18410 avoid painting the rest of the window with the region face,
18411 if the region ends at ZV. */
18412 if (it
->glyph_row
->ends_at_zv_p
)
18413 it
->face_id
= default_face
->id
;
18415 it
->face_id
= face
->id
;
18417 PRODUCE_GLYPHS (it
);
18419 while (it
->current_x
<= it
->last_visible_x
)
18420 PRODUCE_GLYPHS (it
);
18422 /* Don't count these blanks really. It would let us insert a left
18423 truncation glyph below and make us set the cursor on them, maybe. */
18424 it
->current_x
= saved_x
;
18425 it
->object
= saved_object
;
18426 it
->position
= saved_pos
;
18427 it
->what
= saved_what
;
18428 it
->face_id
= saved_face_id
;
18433 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18434 trailing whitespace. */
18437 trailing_whitespace_p (EMACS_INT charpos
)
18439 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
18442 while (bytepos
< ZV_BYTE
18443 && (c
= FETCH_CHAR (bytepos
),
18444 c
== ' ' || c
== '\t'))
18447 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18449 if (bytepos
!= PT_BYTE
)
18456 /* Highlight trailing whitespace, if any, in ROW. */
18459 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18461 int used
= row
->used
[TEXT_AREA
];
18465 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18466 struct glyph
*glyph
= start
+ used
- 1;
18468 if (row
->reversed_p
)
18470 /* Right-to-left rows need to be processed in the opposite
18471 direction, so swap the edge pointers. */
18473 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18476 /* Skip over glyphs inserted to display the cursor at the
18477 end of a line, for extending the face of the last glyph
18478 to the end of the line on terminals, and for truncation
18479 and continuation glyphs. */
18480 if (!row
->reversed_p
)
18482 while (glyph
>= start
18483 && glyph
->type
== CHAR_GLYPH
18484 && INTEGERP (glyph
->object
))
18489 while (glyph
<= start
18490 && glyph
->type
== CHAR_GLYPH
18491 && INTEGERP (glyph
->object
))
18495 /* If last glyph is a space or stretch, and it's trailing
18496 whitespace, set the face of all trailing whitespace glyphs in
18497 IT->glyph_row to `trailing-whitespace'. */
18498 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18499 && BUFFERP (glyph
->object
)
18500 && (glyph
->type
== STRETCH_GLYPH
18501 || (glyph
->type
== CHAR_GLYPH
18502 && glyph
->u
.ch
== ' '))
18503 && trailing_whitespace_p (glyph
->charpos
))
18505 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18509 if (!row
->reversed_p
)
18511 while (glyph
>= start
18512 && BUFFERP (glyph
->object
)
18513 && (glyph
->type
== STRETCH_GLYPH
18514 || (glyph
->type
== CHAR_GLYPH
18515 && glyph
->u
.ch
== ' ')))
18516 (glyph
--)->face_id
= face_id
;
18520 while (glyph
<= start
18521 && BUFFERP (glyph
->object
)
18522 && (glyph
->type
== STRETCH_GLYPH
18523 || (glyph
->type
== CHAR_GLYPH
18524 && glyph
->u
.ch
== ' ')))
18525 (glyph
++)->face_id
= face_id
;
18532 /* Value is non-zero if glyph row ROW should be
18533 used to hold the cursor. */
18536 cursor_row_p (struct glyph_row
*row
)
18540 if (PT
== CHARPOS (row
->end
.pos
)
18541 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18543 /* Suppose the row ends on a string.
18544 Unless the row is continued, that means it ends on a newline
18545 in the string. If it's anything other than a display string
18546 (e.g., a before-string from an overlay), we don't want the
18547 cursor there. (This heuristic seems to give the optimal
18548 behavior for the various types of multi-line strings.)
18549 One exception: if the string has `cursor' property on one of
18550 its characters, we _do_ want the cursor there. */
18551 if (CHARPOS (row
->end
.string_pos
) >= 0)
18553 if (row
->continued_p
)
18557 /* Check for `display' property. */
18558 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18559 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18560 struct glyph
*glyph
;
18563 for (glyph
= end
; glyph
>= beg
; --glyph
)
18564 if (STRINGP (glyph
->object
))
18567 = Fget_char_property (make_number (PT
),
18571 && display_prop_string_p (prop
, glyph
->object
));
18572 /* If there's a `cursor' property on one of the
18573 string's characters, this row is a cursor row,
18574 even though this is not a display string. */
18577 Lisp_Object s
= glyph
->object
;
18579 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18581 EMACS_INT gpos
= glyph
->charpos
;
18583 if (!NILP (Fget_char_property (make_number (gpos
),
18595 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18597 /* If the row ends in middle of a real character,
18598 and the line is continued, we want the cursor here.
18599 That's because CHARPOS (ROW->end.pos) would equal
18600 PT if PT is before the character. */
18601 if (!row
->ends_in_ellipsis_p
)
18602 result
= row
->continued_p
;
18604 /* If the row ends in an ellipsis, then
18605 CHARPOS (ROW->end.pos) will equal point after the
18606 invisible text. We want that position to be displayed
18607 after the ellipsis. */
18610 /* If the row ends at ZV, display the cursor at the end of that
18611 row instead of at the start of the row below. */
18612 else if (row
->ends_at_zv_p
)
18623 /* Push the property PROP so that it will be rendered at the current
18624 position in IT. Return 1 if PROP was successfully pushed, 0
18625 otherwise. Called from handle_line_prefix to handle the
18626 `line-prefix' and `wrap-prefix' properties. */
18629 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18631 struct text_pos pos
=
18632 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18634 xassert (it
->method
== GET_FROM_BUFFER
18635 || it
->method
== GET_FROM_DISPLAY_VECTOR
18636 || it
->method
== GET_FROM_STRING
);
18638 /* We need to save the current buffer/string position, so it will be
18639 restored by pop_it, because iterate_out_of_display_property
18640 depends on that being set correctly, but some situations leave
18641 it->position not yet set when this function is called. */
18642 push_it (it
, &pos
);
18644 if (STRINGP (prop
))
18646 if (SCHARS (prop
) == 0)
18653 it
->string_from_prefix_prop_p
= 1;
18654 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18655 it
->current
.overlay_string_index
= -1;
18656 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18657 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18658 it
->method
= GET_FROM_STRING
;
18659 it
->stop_charpos
= 0;
18661 it
->base_level_stop
= 0;
18663 /* Force paragraph direction to be that of the parent
18665 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18666 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18668 it
->paragraph_embedding
= L2R
;
18670 /* Set up the bidi iterator for this display string. */
18673 it
->bidi_it
.string
.lstring
= it
->string
;
18674 it
->bidi_it
.string
.s
= NULL
;
18675 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18676 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18677 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18678 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18679 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18682 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18684 it
->method
= GET_FROM_STRETCH
;
18687 #ifdef HAVE_WINDOW_SYSTEM
18688 else if (IMAGEP (prop
))
18690 it
->what
= IT_IMAGE
;
18691 it
->image_id
= lookup_image (it
->f
, prop
);
18692 it
->method
= GET_FROM_IMAGE
;
18694 #endif /* HAVE_WINDOW_SYSTEM */
18697 pop_it (it
); /* bogus display property, give up */
18704 /* Return the character-property PROP at the current position in IT. */
18707 get_it_property (struct it
*it
, Lisp_Object prop
)
18709 Lisp_Object position
;
18711 if (STRINGP (it
->object
))
18712 position
= make_number (IT_STRING_CHARPOS (*it
));
18713 else if (BUFFERP (it
->object
))
18714 position
= make_number (IT_CHARPOS (*it
));
18718 return Fget_char_property (position
, prop
, it
->object
);
18721 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18724 handle_line_prefix (struct it
*it
)
18726 Lisp_Object prefix
;
18728 if (it
->continuation_lines_width
> 0)
18730 prefix
= get_it_property (it
, Qwrap_prefix
);
18732 prefix
= Vwrap_prefix
;
18736 prefix
= get_it_property (it
, Qline_prefix
);
18738 prefix
= Vline_prefix
;
18740 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18742 /* If the prefix is wider than the window, and we try to wrap
18743 it, it would acquire its own wrap prefix, and so on till the
18744 iterator stack overflows. So, don't wrap the prefix. */
18745 it
->line_wrap
= TRUNCATE
;
18746 it
->avoid_cursor_p
= 1;
18752 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18753 only for R2L lines from display_line and display_string, when they
18754 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18755 the line/string needs to be continued on the next glyph row. */
18757 unproduce_glyphs (struct it
*it
, int n
)
18759 struct glyph
*glyph
, *end
;
18761 xassert (it
->glyph_row
);
18762 xassert (it
->glyph_row
->reversed_p
);
18763 xassert (it
->area
== TEXT_AREA
);
18764 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18766 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18767 n
= it
->glyph_row
->used
[TEXT_AREA
];
18768 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18769 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18770 for ( ; glyph
< end
; glyph
++)
18771 glyph
[-n
] = *glyph
;
18774 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18775 and ROW->maxpos. */
18777 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18778 EMACS_INT min_pos
, EMACS_INT min_bpos
,
18779 EMACS_INT max_pos
, EMACS_INT max_bpos
)
18781 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18782 lines' rows is implemented for bidi-reordered rows. */
18784 /* ROW->minpos is the value of min_pos, the minimal buffer position
18785 we have in ROW, or ROW->start.pos if that is smaller. */
18786 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18787 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18789 /* We didn't find buffer positions smaller than ROW->start, or
18790 didn't find _any_ valid buffer positions in any of the glyphs,
18791 so we must trust the iterator's computed positions. */
18792 row
->minpos
= row
->start
.pos
;
18795 max_pos
= CHARPOS (it
->current
.pos
);
18796 max_bpos
= BYTEPOS (it
->current
.pos
);
18799 /* Here are the various use-cases for ending the row, and the
18800 corresponding values for ROW->maxpos:
18802 Line ends in a newline from buffer eol_pos + 1
18803 Line is continued from buffer max_pos + 1
18804 Line is truncated on right it->current.pos
18805 Line ends in a newline from string max_pos + 1(*)
18806 (*) + 1 only when line ends in a forward scan
18807 Line is continued from string max_pos
18808 Line is continued from display vector max_pos
18809 Line is entirely from a string min_pos == max_pos
18810 Line is entirely from a display vector min_pos == max_pos
18811 Line that ends at ZV ZV
18813 If you discover other use-cases, please add them here as
18815 if (row
->ends_at_zv_p
)
18816 row
->maxpos
= it
->current
.pos
;
18817 else if (row
->used
[TEXT_AREA
])
18819 int seen_this_string
= 0;
18820 struct glyph_row
*r1
= row
- 1;
18822 /* Did we see the same display string on the previous row? */
18823 if (STRINGP (it
->object
)
18824 /* this is not the first row */
18825 && row
> it
->w
->desired_matrix
->rows
18826 /* previous row is not the header line */
18827 && !r1
->mode_line_p
18828 /* previous row also ends in a newline from a string */
18829 && r1
->ends_in_newline_from_string_p
)
18831 struct glyph
*start
, *end
;
18833 /* Search for the last glyph of the previous row that came
18834 from buffer or string. Depending on whether the row is
18835 L2R or R2L, we need to process it front to back or the
18836 other way round. */
18837 if (!r1
->reversed_p
)
18839 start
= r1
->glyphs
[TEXT_AREA
];
18840 end
= start
+ r1
->used
[TEXT_AREA
];
18841 /* Glyphs inserted by redisplay have an integer (zero)
18842 as their object. */
18844 && INTEGERP ((end
- 1)->object
)
18845 && (end
- 1)->charpos
<= 0)
18849 if (EQ ((end
- 1)->object
, it
->object
))
18850 seen_this_string
= 1;
18853 /* If all the glyphs of the previous row were inserted
18854 by redisplay, it means the previous row was
18855 produced from a single newline, which is only
18856 possible if that newline came from the same string
18857 as the one which produced this ROW. */
18858 seen_this_string
= 1;
18862 end
= r1
->glyphs
[TEXT_AREA
] - 1;
18863 start
= end
+ r1
->used
[TEXT_AREA
];
18865 && INTEGERP ((end
+ 1)->object
)
18866 && (end
+ 1)->charpos
<= 0)
18870 if (EQ ((end
+ 1)->object
, it
->object
))
18871 seen_this_string
= 1;
18874 seen_this_string
= 1;
18877 /* Take note of each display string that covers a newline only
18878 once, the first time we see it. This is for when a display
18879 string includes more than one newline in it. */
18880 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
18882 /* If we were scanning the buffer forward when we displayed
18883 the string, we want to account for at least one buffer
18884 position that belongs to this row (position covered by
18885 the display string), so that cursor positioning will
18886 consider this row as a candidate when point is at the end
18887 of the visual line represented by this row. This is not
18888 required when scanning back, because max_pos will already
18889 have a much larger value. */
18890 if (CHARPOS (row
->end
.pos
) > max_pos
)
18891 INC_BOTH (max_pos
, max_bpos
);
18892 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18894 else if (CHARPOS (it
->eol_pos
) > 0)
18895 SET_TEXT_POS (row
->maxpos
,
18896 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
18897 else if (row
->continued_p
)
18899 /* If max_pos is different from IT's current position, it
18900 means IT->method does not belong to the display element
18901 at max_pos. However, it also means that the display
18902 element at max_pos was displayed in its entirety on this
18903 line, which is equivalent to saying that the next line
18904 starts at the next buffer position. */
18905 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
18906 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18909 INC_BOTH (max_pos
, max_bpos
);
18910 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18913 else if (row
->truncated_on_right_p
)
18914 /* display_line already called reseat_at_next_visible_line_start,
18915 which puts the iterator at the beginning of the next line, in
18916 the logical order. */
18917 row
->maxpos
= it
->current
.pos
;
18918 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
18919 /* A line that is entirely from a string/image/stretch... */
18920 row
->maxpos
= row
->minpos
;
18925 row
->maxpos
= it
->current
.pos
;
18928 /* Construct the glyph row IT->glyph_row in the desired matrix of
18929 IT->w from text at the current position of IT. See dispextern.h
18930 for an overview of struct it. Value is non-zero if
18931 IT->glyph_row displays text, as opposed to a line displaying ZV
18935 display_line (struct it
*it
)
18937 struct glyph_row
*row
= it
->glyph_row
;
18938 Lisp_Object overlay_arrow_string
;
18940 void *wrap_data
= NULL
;
18941 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
18942 int wrap_row_used
= -1;
18943 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
18944 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
18945 int wrap_row_extra_line_spacing
IF_LINT (= 0);
18946 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
18947 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
18949 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
18950 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18952 /* We always start displaying at hpos zero even if hscrolled. */
18953 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18955 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18956 >= it
->w
->desired_matrix
->nrows
)
18958 it
->w
->nrows_scale_factor
++;
18959 fonts_changed_p
= 1;
18963 /* Is IT->w showing the region? */
18964 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18966 /* Clear the result glyph row and enable it. */
18967 prepare_desired_row (row
);
18969 row
->y
= it
->current_y
;
18970 row
->start
= it
->start
;
18971 row
->continuation_lines_width
= it
->continuation_lines_width
;
18972 row
->displays_text_p
= 1;
18973 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18974 it
->starts_in_middle_of_char_p
= 0;
18976 /* Arrange the overlays nicely for our purposes. Usually, we call
18977 display_line on only one line at a time, in which case this
18978 can't really hurt too much, or we call it on lines which appear
18979 one after another in the buffer, in which case all calls to
18980 recenter_overlay_lists but the first will be pretty cheap. */
18981 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18983 /* Move over display elements that are not visible because we are
18984 hscrolled. This may stop at an x-position < IT->first_visible_x
18985 if the first glyph is partially visible or if we hit a line end. */
18986 if (it
->current_x
< it
->first_visible_x
)
18988 this_line_min_pos
= row
->start
.pos
;
18989 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18990 MOVE_TO_POS
| MOVE_TO_X
);
18991 /* Record the smallest positions seen while we moved over
18992 display elements that are not visible. This is needed by
18993 redisplay_internal for optimizing the case where the cursor
18994 stays inside the same line. The rest of this function only
18995 considers positions that are actually displayed, so
18996 RECORD_MAX_MIN_POS will not otherwise record positions that
18997 are hscrolled to the left of the left edge of the window. */
18998 min_pos
= CHARPOS (this_line_min_pos
);
18999 min_bpos
= BYTEPOS (this_line_min_pos
);
19003 /* We only do this when not calling `move_it_in_display_line_to'
19004 above, because move_it_in_display_line_to calls
19005 handle_line_prefix itself. */
19006 handle_line_prefix (it
);
19009 /* Get the initial row height. This is either the height of the
19010 text hscrolled, if there is any, or zero. */
19011 row
->ascent
= it
->max_ascent
;
19012 row
->height
= it
->max_ascent
+ it
->max_descent
;
19013 row
->phys_ascent
= it
->max_phys_ascent
;
19014 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19015 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19017 /* Utility macro to record max and min buffer positions seen until now. */
19018 #define RECORD_MAX_MIN_POS(IT) \
19021 int composition_p = !STRINGP ((IT)->string) \
19022 && ((IT)->what == IT_COMPOSITION); \
19023 EMACS_INT current_pos = \
19024 composition_p ? (IT)->cmp_it.charpos \
19025 : IT_CHARPOS (*(IT)); \
19026 EMACS_INT current_bpos = \
19027 composition_p ? CHAR_TO_BYTE (current_pos) \
19028 : IT_BYTEPOS (*(IT)); \
19029 if (current_pos < min_pos) \
19031 min_pos = current_pos; \
19032 min_bpos = current_bpos; \
19034 if (IT_CHARPOS (*it) > max_pos) \
19036 max_pos = IT_CHARPOS (*it); \
19037 max_bpos = IT_BYTEPOS (*it); \
19042 /* Loop generating characters. The loop is left with IT on the next
19043 character to display. */
19046 int n_glyphs_before
, hpos_before
, x_before
;
19048 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19050 /* Retrieve the next thing to display. Value is zero if end of
19052 if (!get_next_display_element (it
))
19054 /* Maybe add a space at the end of this line that is used to
19055 display the cursor there under X. Set the charpos of the
19056 first glyph of blank lines not corresponding to any text
19058 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19059 row
->exact_window_width_line_p
= 1;
19060 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19061 || row
->used
[TEXT_AREA
] == 0)
19063 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19064 row
->displays_text_p
= 0;
19066 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19067 && (!MINI_WINDOW_P (it
->w
)
19068 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19069 row
->indicate_empty_line_p
= 1;
19072 it
->continuation_lines_width
= 0;
19073 row
->ends_at_zv_p
= 1;
19074 /* A row that displays right-to-left text must always have
19075 its last face extended all the way to the end of line,
19076 even if this row ends in ZV, because we still write to
19077 the screen left to right. We also need to extend the
19078 last face if the default face is remapped to some
19079 different face, otherwise the functions that clear
19080 portions of the screen will clear with the default face's
19081 background color. */
19082 if (row
->reversed_p
19083 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19084 extend_face_to_end_of_line (it
);
19088 /* Now, get the metrics of what we want to display. This also
19089 generates glyphs in `row' (which is IT->glyph_row). */
19090 n_glyphs_before
= row
->used
[TEXT_AREA
];
19093 /* Remember the line height so far in case the next element doesn't
19094 fit on the line. */
19095 if (it
->line_wrap
!= TRUNCATE
)
19097 ascent
= it
->max_ascent
;
19098 descent
= it
->max_descent
;
19099 phys_ascent
= it
->max_phys_ascent
;
19100 phys_descent
= it
->max_phys_descent
;
19102 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19104 if (IT_DISPLAYING_WHITESPACE (it
))
19108 SAVE_IT (wrap_it
, *it
, wrap_data
);
19110 wrap_row_used
= row
->used
[TEXT_AREA
];
19111 wrap_row_ascent
= row
->ascent
;
19112 wrap_row_height
= row
->height
;
19113 wrap_row_phys_ascent
= row
->phys_ascent
;
19114 wrap_row_phys_height
= row
->phys_height
;
19115 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19116 wrap_row_min_pos
= min_pos
;
19117 wrap_row_min_bpos
= min_bpos
;
19118 wrap_row_max_pos
= max_pos
;
19119 wrap_row_max_bpos
= max_bpos
;
19125 PRODUCE_GLYPHS (it
);
19127 /* If this display element was in marginal areas, continue with
19129 if (it
->area
!= TEXT_AREA
)
19131 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19132 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19133 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19134 row
->phys_height
= max (row
->phys_height
,
19135 it
->max_phys_ascent
+ it
->max_phys_descent
);
19136 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19137 it
->max_extra_line_spacing
);
19138 set_iterator_to_next (it
, 1);
19142 /* Does the display element fit on the line? If we truncate
19143 lines, we should draw past the right edge of the window. If
19144 we don't truncate, we want to stop so that we can display the
19145 continuation glyph before the right margin. If lines are
19146 continued, there are two possible strategies for characters
19147 resulting in more than 1 glyph (e.g. tabs): Display as many
19148 glyphs as possible in this line and leave the rest for the
19149 continuation line, or display the whole element in the next
19150 line. Original redisplay did the former, so we do it also. */
19151 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19152 hpos_before
= it
->hpos
;
19155 if (/* Not a newline. */
19157 /* Glyphs produced fit entirely in the line. */
19158 && it
->current_x
< it
->last_visible_x
)
19160 it
->hpos
+= nglyphs
;
19161 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19162 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19163 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19164 row
->phys_height
= max (row
->phys_height
,
19165 it
->max_phys_ascent
+ it
->max_phys_descent
);
19166 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19167 it
->max_extra_line_spacing
);
19168 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19169 row
->x
= x
- it
->first_visible_x
;
19170 /* Record the maximum and minimum buffer positions seen so
19171 far in glyphs that will be displayed by this row. */
19173 RECORD_MAX_MIN_POS (it
);
19178 struct glyph
*glyph
;
19180 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19182 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19183 new_x
= x
+ glyph
->pixel_width
;
19185 if (/* Lines are continued. */
19186 it
->line_wrap
!= TRUNCATE
19187 && (/* Glyph doesn't fit on the line. */
19188 new_x
> it
->last_visible_x
19189 /* Or it fits exactly on a window system frame. */
19190 || (new_x
== it
->last_visible_x
19191 && FRAME_WINDOW_P (it
->f
))))
19193 /* End of a continued line. */
19196 || (new_x
== it
->last_visible_x
19197 && FRAME_WINDOW_P (it
->f
)))
19199 /* Current glyph is the only one on the line or
19200 fits exactly on the line. We must continue
19201 the line because we can't draw the cursor
19202 after the glyph. */
19203 row
->continued_p
= 1;
19204 it
->current_x
= new_x
;
19205 it
->continuation_lines_width
+= new_x
;
19207 if (i
== nglyphs
- 1)
19209 /* If line-wrap is on, check if a previous
19210 wrap point was found. */
19211 if (wrap_row_used
> 0
19212 /* Even if there is a previous wrap
19213 point, continue the line here as
19214 usual, if (i) the previous character
19215 was a space or tab AND (ii) the
19216 current character is not. */
19218 || IT_DISPLAYING_WHITESPACE (it
)))
19221 /* Record the maximum and minimum buffer
19222 positions seen so far in glyphs that will be
19223 displayed by this row. */
19225 RECORD_MAX_MIN_POS (it
);
19226 set_iterator_to_next (it
, 1);
19227 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19229 if (!get_next_display_element (it
))
19231 row
->exact_window_width_line_p
= 1;
19232 it
->continuation_lines_width
= 0;
19233 row
->continued_p
= 0;
19234 row
->ends_at_zv_p
= 1;
19236 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19238 row
->continued_p
= 0;
19239 row
->exact_window_width_line_p
= 1;
19243 else if (it
->bidi_p
)
19244 RECORD_MAX_MIN_POS (it
);
19246 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19247 && !FRAME_WINDOW_P (it
->f
))
19249 /* A padding glyph that doesn't fit on this line.
19250 This means the whole character doesn't fit
19252 if (row
->reversed_p
)
19253 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19254 - n_glyphs_before
);
19255 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19257 /* Fill the rest of the row with continuation
19258 glyphs like in 20.x. */
19259 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19260 < row
->glyphs
[1 + TEXT_AREA
])
19261 produce_special_glyphs (it
, IT_CONTINUATION
);
19263 row
->continued_p
= 1;
19264 it
->current_x
= x_before
;
19265 it
->continuation_lines_width
+= x_before
;
19267 /* Restore the height to what it was before the
19268 element not fitting on the line. */
19269 it
->max_ascent
= ascent
;
19270 it
->max_descent
= descent
;
19271 it
->max_phys_ascent
= phys_ascent
;
19272 it
->max_phys_descent
= phys_descent
;
19274 else if (wrap_row_used
> 0)
19277 if (row
->reversed_p
)
19278 unproduce_glyphs (it
,
19279 row
->used
[TEXT_AREA
] - wrap_row_used
);
19280 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19281 it
->continuation_lines_width
+= wrap_x
;
19282 row
->used
[TEXT_AREA
] = wrap_row_used
;
19283 row
->ascent
= wrap_row_ascent
;
19284 row
->height
= wrap_row_height
;
19285 row
->phys_ascent
= wrap_row_phys_ascent
;
19286 row
->phys_height
= wrap_row_phys_height
;
19287 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19288 min_pos
= wrap_row_min_pos
;
19289 min_bpos
= wrap_row_min_bpos
;
19290 max_pos
= wrap_row_max_pos
;
19291 max_bpos
= wrap_row_max_bpos
;
19292 row
->continued_p
= 1;
19293 row
->ends_at_zv_p
= 0;
19294 row
->exact_window_width_line_p
= 0;
19295 it
->continuation_lines_width
+= x
;
19297 /* Make sure that a non-default face is extended
19298 up to the right margin of the window. */
19299 extend_face_to_end_of_line (it
);
19301 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19303 /* A TAB that extends past the right edge of the
19304 window. This produces a single glyph on
19305 window system frames. We leave the glyph in
19306 this row and let it fill the row, but don't
19307 consume the TAB. */
19308 it
->continuation_lines_width
+= it
->last_visible_x
;
19309 row
->ends_in_middle_of_char_p
= 1;
19310 row
->continued_p
= 1;
19311 glyph
->pixel_width
= it
->last_visible_x
- x
;
19312 it
->starts_in_middle_of_char_p
= 1;
19316 /* Something other than a TAB that draws past
19317 the right edge of the window. Restore
19318 positions to values before the element. */
19319 if (row
->reversed_p
)
19320 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19321 - (n_glyphs_before
+ i
));
19322 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19324 /* Display continuation glyphs. */
19325 if (!FRAME_WINDOW_P (it
->f
))
19326 produce_special_glyphs (it
, IT_CONTINUATION
);
19327 row
->continued_p
= 1;
19329 it
->current_x
= x_before
;
19330 it
->continuation_lines_width
+= x
;
19331 extend_face_to_end_of_line (it
);
19333 if (nglyphs
> 1 && i
> 0)
19335 row
->ends_in_middle_of_char_p
= 1;
19336 it
->starts_in_middle_of_char_p
= 1;
19339 /* Restore the height to what it was before the
19340 element not fitting on the line. */
19341 it
->max_ascent
= ascent
;
19342 it
->max_descent
= descent
;
19343 it
->max_phys_ascent
= phys_ascent
;
19344 it
->max_phys_descent
= phys_descent
;
19349 else if (new_x
> it
->first_visible_x
)
19351 /* Increment number of glyphs actually displayed. */
19354 /* Record the maximum and minimum buffer positions
19355 seen so far in glyphs that will be displayed by
19358 RECORD_MAX_MIN_POS (it
);
19360 if (x
< it
->first_visible_x
)
19361 /* Glyph is partially visible, i.e. row starts at
19362 negative X position. */
19363 row
->x
= x
- it
->first_visible_x
;
19367 /* Glyph is completely off the left margin of the
19368 window. This should not happen because of the
19369 move_it_in_display_line at the start of this
19370 function, unless the text display area of the
19371 window is empty. */
19372 xassert (it
->first_visible_x
<= it
->last_visible_x
);
19375 /* Even if this display element produced no glyphs at all,
19376 we want to record its position. */
19377 if (it
->bidi_p
&& nglyphs
== 0)
19378 RECORD_MAX_MIN_POS (it
);
19380 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19381 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19382 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19383 row
->phys_height
= max (row
->phys_height
,
19384 it
->max_phys_ascent
+ it
->max_phys_descent
);
19385 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19386 it
->max_extra_line_spacing
);
19388 /* End of this display line if row is continued. */
19389 if (row
->continued_p
|| row
->ends_at_zv_p
)
19394 /* Is this a line end? If yes, we're also done, after making
19395 sure that a non-default face is extended up to the right
19396 margin of the window. */
19397 if (ITERATOR_AT_END_OF_LINE_P (it
))
19399 int used_before
= row
->used
[TEXT_AREA
];
19401 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19403 /* Add a space at the end of the line that is used to
19404 display the cursor there. */
19405 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19406 append_space_for_newline (it
, 0);
19408 /* Extend the face to the end of the line. */
19409 extend_face_to_end_of_line (it
);
19411 /* Make sure we have the position. */
19412 if (used_before
== 0)
19413 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19415 /* Record the position of the newline, for use in
19417 it
->eol_pos
= it
->current
.pos
;
19419 /* Consume the line end. This skips over invisible lines. */
19420 set_iterator_to_next (it
, 1);
19421 it
->continuation_lines_width
= 0;
19425 /* Proceed with next display element. Note that this skips
19426 over lines invisible because of selective display. */
19427 set_iterator_to_next (it
, 1);
19429 /* If we truncate lines, we are done when the last displayed
19430 glyphs reach past the right margin of the window. */
19431 if (it
->line_wrap
== TRUNCATE
19432 && (FRAME_WINDOW_P (it
->f
)
19433 ? (it
->current_x
>= it
->last_visible_x
)
19434 : (it
->current_x
> it
->last_visible_x
)))
19436 /* Maybe add truncation glyphs. */
19437 if (!FRAME_WINDOW_P (it
->f
))
19441 if (!row
->reversed_p
)
19443 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19444 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19449 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19450 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19452 /* Remove any padding glyphs at the front of ROW, to
19453 make room for the truncation glyphs we will be
19454 adding below. The loop below always inserts at
19455 least one truncation glyph, so also remove the
19456 last glyph added to ROW. */
19457 unproduce_glyphs (it
, i
+ 1);
19458 /* Adjust i for the loop below. */
19459 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19462 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19464 row
->used
[TEXT_AREA
] = i
;
19465 produce_special_glyphs (it
, IT_TRUNCATION
);
19468 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19470 /* Don't truncate if we can overflow newline into fringe. */
19471 if (!get_next_display_element (it
))
19473 it
->continuation_lines_width
= 0;
19474 row
->ends_at_zv_p
= 1;
19475 row
->exact_window_width_line_p
= 1;
19478 if (ITERATOR_AT_END_OF_LINE_P (it
))
19480 row
->exact_window_width_line_p
= 1;
19481 goto at_end_of_line
;
19485 row
->truncated_on_right_p
= 1;
19486 it
->continuation_lines_width
= 0;
19487 reseat_at_next_visible_line_start (it
, 0);
19488 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19489 it
->hpos
= hpos_before
;
19490 it
->current_x
= x_before
;
19496 bidi_unshelve_cache (wrap_data
, 1);
19498 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19499 at the left window margin. */
19500 if (it
->first_visible_x
19501 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19503 if (!FRAME_WINDOW_P (it
->f
))
19504 insert_left_trunc_glyphs (it
);
19505 row
->truncated_on_left_p
= 1;
19508 /* Remember the position at which this line ends.
19510 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19511 cannot be before the call to find_row_edges below, since that is
19512 where these positions are determined. */
19513 row
->end
= it
->current
;
19516 row
->minpos
= row
->start
.pos
;
19517 row
->maxpos
= row
->end
.pos
;
19521 /* ROW->minpos and ROW->maxpos must be the smallest and
19522 `1 + the largest' buffer positions in ROW. But if ROW was
19523 bidi-reordered, these two positions can be anywhere in the
19524 row, so we must determine them now. */
19525 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19528 /* If the start of this line is the overlay arrow-position, then
19529 mark this glyph row as the one containing the overlay arrow.
19530 This is clearly a mess with variable size fonts. It would be
19531 better to let it be displayed like cursors under X. */
19532 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19533 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19534 !NILP (overlay_arrow_string
)))
19536 /* Overlay arrow in window redisplay is a fringe bitmap. */
19537 if (STRINGP (overlay_arrow_string
))
19539 struct glyph_row
*arrow_row
19540 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19541 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19542 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19543 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19544 struct glyph
*p2
, *end
;
19546 /* Copy the arrow glyphs. */
19547 while (glyph
< arrow_end
)
19550 /* Throw away padding glyphs. */
19552 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19553 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19559 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19564 xassert (INTEGERP (overlay_arrow_string
));
19565 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19567 overlay_arrow_seen
= 1;
19570 /* Highlight trailing whitespace. */
19571 if (!NILP (Vshow_trailing_whitespace
))
19572 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19574 /* Compute pixel dimensions of this line. */
19575 compute_line_metrics (it
);
19577 /* Implementation note: No changes in the glyphs of ROW or in their
19578 faces can be done past this point, because compute_line_metrics
19579 computes ROW's hash value and stores it within the glyph_row
19582 /* Record whether this row ends inside an ellipsis. */
19583 row
->ends_in_ellipsis_p
19584 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19585 && it
->ellipsis_p
);
19587 /* Save fringe bitmaps in this row. */
19588 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19589 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19590 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19591 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19593 it
->left_user_fringe_bitmap
= 0;
19594 it
->left_user_fringe_face_id
= 0;
19595 it
->right_user_fringe_bitmap
= 0;
19596 it
->right_user_fringe_face_id
= 0;
19598 /* Maybe set the cursor. */
19599 cvpos
= it
->w
->cursor
.vpos
;
19601 /* In bidi-reordered rows, keep checking for proper cursor
19602 position even if one has been found already, because buffer
19603 positions in such rows change non-linearly with ROW->VPOS,
19604 when a line is continued. One exception: when we are at ZV,
19605 display cursor on the first suitable glyph row, since all
19606 the empty rows after that also have their position set to ZV. */
19607 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19608 lines' rows is implemented for bidi-reordered rows. */
19610 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19611 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19612 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19613 && cursor_row_p (row
))
19614 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19616 /* Prepare for the next line. This line starts horizontally at (X
19617 HPOS) = (0 0). Vertical positions are incremented. As a
19618 convenience for the caller, IT->glyph_row is set to the next
19620 it
->current_x
= it
->hpos
= 0;
19621 it
->current_y
+= row
->height
;
19622 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19625 /* The next row should by default use the same value of the
19626 reversed_p flag as this one. set_iterator_to_next decides when
19627 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19628 the flag accordingly. */
19629 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19630 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19631 it
->start
= row
->end
;
19632 return row
->displays_text_p
;
19634 #undef RECORD_MAX_MIN_POS
19637 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19638 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19639 doc
: /* Return paragraph direction at point in BUFFER.
19640 Value is either `left-to-right' or `right-to-left'.
19641 If BUFFER is omitted or nil, it defaults to the current buffer.
19643 Paragraph direction determines how the text in the paragraph is displayed.
19644 In left-to-right paragraphs, text begins at the left margin of the window
19645 and the reading direction is generally left to right. In right-to-left
19646 paragraphs, text begins at the right margin and is read from right to left.
19648 See also `bidi-paragraph-direction'. */)
19649 (Lisp_Object buffer
)
19651 struct buffer
*buf
= current_buffer
;
19652 struct buffer
*old
= buf
;
19654 if (! NILP (buffer
))
19656 CHECK_BUFFER (buffer
);
19657 buf
= XBUFFER (buffer
);
19660 if (NILP (BVAR (buf
, bidi_display_reordering
))
19661 || NILP (BVAR (buf
, enable_multibyte_characters
))
19662 /* When we are loading loadup.el, the character property tables
19663 needed for bidi iteration are not yet available. */
19664 || !NILP (Vpurify_flag
))
19665 return Qleft_to_right
;
19666 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19667 return BVAR (buf
, bidi_paragraph_direction
);
19670 /* Determine the direction from buffer text. We could try to
19671 use current_matrix if it is up to date, but this seems fast
19672 enough as it is. */
19673 struct bidi_it itb
;
19674 EMACS_INT pos
= BUF_PT (buf
);
19675 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
19677 void *itb_data
= bidi_shelve_cache ();
19679 set_buffer_temp (buf
);
19680 /* bidi_paragraph_init finds the base direction of the paragraph
19681 by searching forward from paragraph start. We need the base
19682 direction of the current or _previous_ paragraph, so we need
19683 to make sure we are within that paragraph. To that end, find
19684 the previous non-empty line. */
19685 if (pos
>= ZV
&& pos
> BEGV
)
19688 bytepos
= CHAR_TO_BYTE (pos
);
19690 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19691 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19693 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19694 || c
== ' ' || c
== '\t' || c
== '\f')
19696 if (bytepos
<= BEGV_BYTE
)
19701 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19704 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19705 itb
.paragraph_dir
= NEUTRAL_DIR
;
19706 itb
.string
.s
= NULL
;
19707 itb
.string
.lstring
= Qnil
;
19708 itb
.string
.bufpos
= 0;
19709 itb
.string
.unibyte
= 0;
19710 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19711 bidi_unshelve_cache (itb_data
, 0);
19712 set_buffer_temp (old
);
19713 switch (itb
.paragraph_dir
)
19716 return Qleft_to_right
;
19719 return Qright_to_left
;
19729 /***********************************************************************
19731 ***********************************************************************/
19733 /* Redisplay the menu bar in the frame for window W.
19735 The menu bar of X frames that don't have X toolkit support is
19736 displayed in a special window W->frame->menu_bar_window.
19738 The menu bar of terminal frames is treated specially as far as
19739 glyph matrices are concerned. Menu bar lines are not part of
19740 windows, so the update is done directly on the frame matrix rows
19741 for the menu bar. */
19744 display_menu_bar (struct window
*w
)
19746 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19751 /* Don't do all this for graphical frames. */
19753 if (FRAME_W32_P (f
))
19756 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19762 if (FRAME_NS_P (f
))
19764 #endif /* HAVE_NS */
19766 #ifdef USE_X_TOOLKIT
19767 xassert (!FRAME_WINDOW_P (f
));
19768 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19769 it
.first_visible_x
= 0;
19770 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19771 #else /* not USE_X_TOOLKIT */
19772 if (FRAME_WINDOW_P (f
))
19774 /* Menu bar lines are displayed in the desired matrix of the
19775 dummy window menu_bar_window. */
19776 struct window
*menu_w
;
19777 xassert (WINDOWP (f
->menu_bar_window
));
19778 menu_w
= XWINDOW (f
->menu_bar_window
);
19779 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19781 it
.first_visible_x
= 0;
19782 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19786 /* This is a TTY frame, i.e. character hpos/vpos are used as
19788 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19790 it
.first_visible_x
= 0;
19791 it
.last_visible_x
= FRAME_COLS (f
);
19793 #endif /* not USE_X_TOOLKIT */
19795 /* FIXME: This should be controlled by a user option. See the
19796 comments in redisplay_tool_bar and display_mode_line about
19798 it
.paragraph_embedding
= L2R
;
19800 if (! mode_line_inverse_video
)
19801 /* Force the menu-bar to be displayed in the default face. */
19802 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19804 /* Clear all rows of the menu bar. */
19805 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
19807 struct glyph_row
*row
= it
.glyph_row
+ i
;
19808 clear_glyph_row (row
);
19809 row
->enabled_p
= 1;
19810 row
->full_width_p
= 1;
19813 /* Display all items of the menu bar. */
19814 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
19815 for (i
= 0; i
< ASIZE (items
); i
+= 4)
19817 Lisp_Object string
;
19819 /* Stop at nil string. */
19820 string
= AREF (items
, i
+ 1);
19824 /* Remember where item was displayed. */
19825 ASET (items
, i
+ 3, make_number (it
.hpos
));
19827 /* Display the item, pad with one space. */
19828 if (it
.current_x
< it
.last_visible_x
)
19829 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
19830 SCHARS (string
) + 1, 0, 0, -1);
19833 /* Fill out the line with spaces. */
19834 if (it
.current_x
< it
.last_visible_x
)
19835 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
19837 /* Compute the total height of the lines. */
19838 compute_line_metrics (&it
);
19843 /***********************************************************************
19845 ***********************************************************************/
19847 /* Redisplay mode lines in the window tree whose root is WINDOW. If
19848 FORCE is non-zero, redisplay mode lines unconditionally.
19849 Otherwise, redisplay only mode lines that are garbaged. Value is
19850 the number of windows whose mode lines were redisplayed. */
19853 redisplay_mode_lines (Lisp_Object window
, int force
)
19857 while (!NILP (window
))
19859 struct window
*w
= XWINDOW (window
);
19861 if (WINDOWP (w
->hchild
))
19862 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
19863 else if (WINDOWP (w
->vchild
))
19864 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
19866 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
19867 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
19869 struct text_pos lpoint
;
19870 struct buffer
*old
= current_buffer
;
19872 /* Set the window's buffer for the mode line display. */
19873 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
19874 set_buffer_internal_1 (XBUFFER (w
->buffer
));
19876 /* Point refers normally to the selected window. For any
19877 other window, set up appropriate value. */
19878 if (!EQ (window
, selected_window
))
19880 struct text_pos pt
;
19882 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
19883 if (CHARPOS (pt
) < BEGV
)
19884 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
19885 else if (CHARPOS (pt
) > (ZV
- 1))
19886 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
19888 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
19891 /* Display mode lines. */
19892 clear_glyph_matrix (w
->desired_matrix
);
19893 if (display_mode_lines (w
))
19896 w
->must_be_updated_p
= 1;
19899 /* Restore old settings. */
19900 set_buffer_internal_1 (old
);
19901 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
19911 /* Display the mode and/or header line of window W. Value is the
19912 sum number of mode lines and header lines displayed. */
19915 display_mode_lines (struct window
*w
)
19917 Lisp_Object old_selected_window
, old_selected_frame
;
19920 old_selected_frame
= selected_frame
;
19921 selected_frame
= w
->frame
;
19922 old_selected_window
= selected_window
;
19923 XSETWINDOW (selected_window
, w
);
19925 /* These will be set while the mode line specs are processed. */
19926 line_number_displayed
= 0;
19927 w
->column_number_displayed
= Qnil
;
19929 if (WINDOW_WANTS_MODELINE_P (w
))
19931 struct window
*sel_w
= XWINDOW (old_selected_window
);
19933 /* Select mode line face based on the real selected window. */
19934 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
19935 BVAR (current_buffer
, mode_line_format
));
19939 if (WINDOW_WANTS_HEADER_LINE_P (w
))
19941 display_mode_line (w
, HEADER_LINE_FACE_ID
,
19942 BVAR (current_buffer
, header_line_format
));
19946 selected_frame
= old_selected_frame
;
19947 selected_window
= old_selected_window
;
19952 /* Display mode or header line of window W. FACE_ID specifies which
19953 line to display; it is either MODE_LINE_FACE_ID or
19954 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
19955 display. Value is the pixel height of the mode/header line
19959 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
19963 int count
= SPECPDL_INDEX ();
19965 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19966 /* Don't extend on a previously drawn mode-line.
19967 This may happen if called from pos_visible_p. */
19968 it
.glyph_row
->enabled_p
= 0;
19969 prepare_desired_row (it
.glyph_row
);
19971 it
.glyph_row
->mode_line_p
= 1;
19973 if (! mode_line_inverse_video
)
19974 /* Force the mode-line to be displayed in the default face. */
19975 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19977 /* FIXME: This should be controlled by a user option. But
19978 supporting such an option is not trivial, since the mode line is
19979 made up of many separate strings. */
19980 it
.paragraph_embedding
= L2R
;
19982 record_unwind_protect (unwind_format_mode_line
,
19983 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19985 mode_line_target
= MODE_LINE_DISPLAY
;
19987 /* Temporarily make frame's keyboard the current kboard so that
19988 kboard-local variables in the mode_line_format will get the right
19990 push_kboard (FRAME_KBOARD (it
.f
));
19991 record_unwind_save_match_data ();
19992 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19995 unbind_to (count
, Qnil
);
19997 /* Fill up with spaces. */
19998 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20000 compute_line_metrics (&it
);
20001 it
.glyph_row
->full_width_p
= 1;
20002 it
.glyph_row
->continued_p
= 0;
20003 it
.glyph_row
->truncated_on_left_p
= 0;
20004 it
.glyph_row
->truncated_on_right_p
= 0;
20006 /* Make a 3D mode-line have a shadow at its right end. */
20007 face
= FACE_FROM_ID (it
.f
, face_id
);
20008 extend_face_to_end_of_line (&it
);
20009 if (face
->box
!= FACE_NO_BOX
)
20011 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20012 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20013 last
->right_box_line_p
= 1;
20016 return it
.glyph_row
->height
;
20019 /* Move element ELT in LIST to the front of LIST.
20020 Return the updated list. */
20023 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20025 register Lisp_Object tail
, prev
;
20026 register Lisp_Object tem
;
20030 while (CONSP (tail
))
20036 /* Splice out the link TAIL. */
20038 list
= XCDR (tail
);
20040 Fsetcdr (prev
, XCDR (tail
));
20042 /* Now make it the first. */
20043 Fsetcdr (tail
, list
);
20048 tail
= XCDR (tail
);
20052 /* Not found--return unchanged LIST. */
20056 /* Contribute ELT to the mode line for window IT->w. How it
20057 translates into text depends on its data type.
20059 IT describes the display environment in which we display, as usual.
20061 DEPTH is the depth in recursion. It is used to prevent
20062 infinite recursion here.
20064 FIELD_WIDTH is the number of characters the display of ELT should
20065 occupy in the mode line, and PRECISION is the maximum number of
20066 characters to display from ELT's representation. See
20067 display_string for details.
20069 Returns the hpos of the end of the text generated by ELT.
20071 PROPS is a property list to add to any string we encounter.
20073 If RISKY is nonzero, remove (disregard) any properties in any string
20074 we encounter, and ignore :eval and :propertize.
20076 The global variable `mode_line_target' determines whether the
20077 output is passed to `store_mode_line_noprop',
20078 `store_mode_line_string', or `display_string'. */
20081 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20082 Lisp_Object elt
, Lisp_Object props
, int risky
)
20084 int n
= 0, field
, prec
;
20089 elt
= build_string ("*too-deep*");
20093 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
20097 /* A string: output it and check for %-constructs within it. */
20099 EMACS_INT offset
= 0;
20101 if (SCHARS (elt
) > 0
20102 && (!NILP (props
) || risky
))
20104 Lisp_Object oprops
, aelt
;
20105 oprops
= Ftext_properties_at (make_number (0), elt
);
20107 /* If the starting string's properties are not what
20108 we want, translate the string. Also, if the string
20109 is risky, do that anyway. */
20111 if (NILP (Fequal (props
, oprops
)) || risky
)
20113 /* If the starting string has properties,
20114 merge the specified ones onto the existing ones. */
20115 if (! NILP (oprops
) && !risky
)
20119 oprops
= Fcopy_sequence (oprops
);
20121 while (CONSP (tem
))
20123 oprops
= Fplist_put (oprops
, XCAR (tem
),
20124 XCAR (XCDR (tem
)));
20125 tem
= XCDR (XCDR (tem
));
20130 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20131 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20133 /* AELT is what we want. Move it to the front
20134 without consing. */
20136 mode_line_proptrans_alist
20137 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20143 /* If AELT has the wrong props, it is useless.
20144 so get rid of it. */
20146 mode_line_proptrans_alist
20147 = Fdelq (aelt
, mode_line_proptrans_alist
);
20149 elt
= Fcopy_sequence (elt
);
20150 Fset_text_properties (make_number (0), Flength (elt
),
20152 /* Add this item to mode_line_proptrans_alist. */
20153 mode_line_proptrans_alist
20154 = Fcons (Fcons (elt
, props
),
20155 mode_line_proptrans_alist
);
20156 /* Truncate mode_line_proptrans_alist
20157 to at most 50 elements. */
20158 tem
= Fnthcdr (make_number (50),
20159 mode_line_proptrans_alist
);
20161 XSETCDR (tem
, Qnil
);
20170 prec
= precision
- n
;
20171 switch (mode_line_target
)
20173 case MODE_LINE_NOPROP
:
20174 case MODE_LINE_TITLE
:
20175 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20177 case MODE_LINE_STRING
:
20178 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20180 case MODE_LINE_DISPLAY
:
20181 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20182 0, prec
, 0, STRING_MULTIBYTE (elt
));
20189 /* Handle the non-literal case. */
20191 while ((precision
<= 0 || n
< precision
)
20192 && SREF (elt
, offset
) != 0
20193 && (mode_line_target
!= MODE_LINE_DISPLAY
20194 || it
->current_x
< it
->last_visible_x
))
20196 EMACS_INT last_offset
= offset
;
20198 /* Advance to end of string or next format specifier. */
20199 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20202 if (offset
- 1 != last_offset
)
20204 EMACS_INT nchars
, nbytes
;
20206 /* Output to end of string or up to '%'. Field width
20207 is length of string. Don't output more than
20208 PRECISION allows us. */
20211 prec
= c_string_width (SDATA (elt
) + last_offset
,
20212 offset
- last_offset
, precision
- n
,
20215 switch (mode_line_target
)
20217 case MODE_LINE_NOPROP
:
20218 case MODE_LINE_TITLE
:
20219 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20221 case MODE_LINE_STRING
:
20223 EMACS_INT bytepos
= last_offset
;
20224 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
20225 EMACS_INT endpos
= (precision
<= 0
20226 ? string_byte_to_char (elt
, offset
)
20227 : charpos
+ nchars
);
20229 n
+= store_mode_line_string (NULL
,
20230 Fsubstring (elt
, make_number (charpos
),
20231 make_number (endpos
)),
20235 case MODE_LINE_DISPLAY
:
20237 EMACS_INT bytepos
= last_offset
;
20238 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
20240 if (precision
<= 0)
20241 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20242 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20244 STRING_MULTIBYTE (elt
));
20249 else /* c == '%' */
20251 EMACS_INT percent_position
= offset
;
20253 /* Get the specified minimum width. Zero means
20256 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20257 field
= field
* 10 + c
- '0';
20259 /* Don't pad beyond the total padding allowed. */
20260 if (field_width
- n
> 0 && field
> field_width
- n
)
20261 field
= field_width
- n
;
20263 /* Note that either PRECISION <= 0 or N < PRECISION. */
20264 prec
= precision
- n
;
20267 n
+= display_mode_element (it
, depth
, field
, prec
,
20268 Vglobal_mode_string
, props
,
20273 EMACS_INT bytepos
, charpos
;
20275 Lisp_Object string
;
20277 bytepos
= percent_position
;
20278 charpos
= (STRING_MULTIBYTE (elt
)
20279 ? string_byte_to_char (elt
, bytepos
)
20281 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20282 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20284 switch (mode_line_target
)
20286 case MODE_LINE_NOPROP
:
20287 case MODE_LINE_TITLE
:
20288 n
+= store_mode_line_noprop (spec
, field
, prec
);
20290 case MODE_LINE_STRING
:
20292 Lisp_Object tem
= build_string (spec
);
20293 props
= Ftext_properties_at (make_number (charpos
), elt
);
20294 /* Should only keep face property in props */
20295 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20298 case MODE_LINE_DISPLAY
:
20300 int nglyphs_before
, nwritten
;
20302 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20303 nwritten
= display_string (spec
, string
, elt
,
20308 /* Assign to the glyphs written above the
20309 string where the `%x' came from, position
20313 struct glyph
*glyph
20314 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20318 for (i
= 0; i
< nwritten
; ++i
)
20320 glyph
[i
].object
= elt
;
20321 glyph
[i
].charpos
= charpos
;
20338 /* A symbol: process the value of the symbol recursively
20339 as if it appeared here directly. Avoid error if symbol void.
20340 Special case: if value of symbol is a string, output the string
20343 register Lisp_Object tem
;
20345 /* If the variable is not marked as risky to set
20346 then its contents are risky to use. */
20347 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20350 tem
= Fboundp (elt
);
20353 tem
= Fsymbol_value (elt
);
20354 /* If value is a string, output that string literally:
20355 don't check for % within it. */
20359 if (!EQ (tem
, elt
))
20361 /* Give up right away for nil or t. */
20371 register Lisp_Object car
, tem
;
20373 /* A cons cell: five distinct cases.
20374 If first element is :eval or :propertize, do something special.
20375 If first element is a string or a cons, process all the elements
20376 and effectively concatenate them.
20377 If first element is a negative number, truncate displaying cdr to
20378 at most that many characters. If positive, pad (with spaces)
20379 to at least that many characters.
20380 If first element is a symbol, process the cadr or caddr recursively
20381 according to whether the symbol's value is non-nil or nil. */
20383 if (EQ (car
, QCeval
))
20385 /* An element of the form (:eval FORM) means evaluate FORM
20386 and use the result as mode line elements. */
20391 if (CONSP (XCDR (elt
)))
20394 spec
= safe_eval (XCAR (XCDR (elt
)));
20395 n
+= display_mode_element (it
, depth
, field_width
- n
,
20396 precision
- n
, spec
, props
,
20400 else if (EQ (car
, QCpropertize
))
20402 /* An element of the form (:propertize ELT PROPS...)
20403 means display ELT but applying properties PROPS. */
20408 if (CONSP (XCDR (elt
)))
20409 n
+= display_mode_element (it
, depth
, field_width
- n
,
20410 precision
- n
, XCAR (XCDR (elt
)),
20411 XCDR (XCDR (elt
)), risky
);
20413 else if (SYMBOLP (car
))
20415 tem
= Fboundp (car
);
20419 /* elt is now the cdr, and we know it is a cons cell.
20420 Use its car if CAR has a non-nil value. */
20423 tem
= Fsymbol_value (car
);
20430 /* Symbol's value is nil (or symbol is unbound)
20431 Get the cddr of the original list
20432 and if possible find the caddr and use that. */
20436 else if (!CONSP (elt
))
20441 else if (INTEGERP (car
))
20443 register int lim
= XINT (car
);
20447 /* Negative int means reduce maximum width. */
20448 if (precision
<= 0)
20451 precision
= min (precision
, -lim
);
20455 /* Padding specified. Don't let it be more than
20456 current maximum. */
20458 lim
= min (precision
, lim
);
20460 /* If that's more padding than already wanted, queue it.
20461 But don't reduce padding already specified even if
20462 that is beyond the current truncation point. */
20463 field_width
= max (lim
, field_width
);
20467 else if (STRINGP (car
) || CONSP (car
))
20469 Lisp_Object halftail
= elt
;
20473 && (precision
<= 0 || n
< precision
))
20475 n
+= display_mode_element (it
, depth
,
20476 /* Do padding only after the last
20477 element in the list. */
20478 (! CONSP (XCDR (elt
))
20481 precision
- n
, XCAR (elt
),
20485 if ((len
& 1) == 0)
20486 halftail
= XCDR (halftail
);
20487 /* Check for cycle. */
20488 if (EQ (halftail
, elt
))
20497 elt
= build_string ("*invalid*");
20501 /* Pad to FIELD_WIDTH. */
20502 if (field_width
> 0 && n
< field_width
)
20504 switch (mode_line_target
)
20506 case MODE_LINE_NOPROP
:
20507 case MODE_LINE_TITLE
:
20508 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20510 case MODE_LINE_STRING
:
20511 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20513 case MODE_LINE_DISPLAY
:
20514 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20523 /* Store a mode-line string element in mode_line_string_list.
20525 If STRING is non-null, display that C string. Otherwise, the Lisp
20526 string LISP_STRING is displayed.
20528 FIELD_WIDTH is the minimum number of output glyphs to produce.
20529 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20530 with spaces. FIELD_WIDTH <= 0 means don't pad.
20532 PRECISION is the maximum number of characters to output from
20533 STRING. PRECISION <= 0 means don't truncate the string.
20535 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20536 properties to the string.
20538 PROPS are the properties to add to the string.
20539 The mode_line_string_face face property is always added to the string.
20543 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20544 int field_width
, int precision
, Lisp_Object props
)
20549 if (string
!= NULL
)
20551 len
= strlen (string
);
20552 if (precision
> 0 && len
> precision
)
20554 lisp_string
= make_string (string
, len
);
20556 props
= mode_line_string_face_prop
;
20557 else if (!NILP (mode_line_string_face
))
20559 Lisp_Object face
= Fplist_get (props
, Qface
);
20560 props
= Fcopy_sequence (props
);
20562 face
= mode_line_string_face
;
20564 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20565 props
= Fplist_put (props
, Qface
, face
);
20567 Fadd_text_properties (make_number (0), make_number (len
),
20568 props
, lisp_string
);
20572 len
= XFASTINT (Flength (lisp_string
));
20573 if (precision
> 0 && len
> precision
)
20576 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20579 if (!NILP (mode_line_string_face
))
20583 props
= Ftext_properties_at (make_number (0), lisp_string
);
20584 face
= Fplist_get (props
, Qface
);
20586 face
= mode_line_string_face
;
20588 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20589 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20591 lisp_string
= Fcopy_sequence (lisp_string
);
20594 Fadd_text_properties (make_number (0), make_number (len
),
20595 props
, lisp_string
);
20600 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20604 if (field_width
> len
)
20606 field_width
-= len
;
20607 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20609 Fadd_text_properties (make_number (0), make_number (field_width
),
20610 props
, lisp_string
);
20611 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20619 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20621 doc
: /* Format a string out of a mode line format specification.
20622 First arg FORMAT specifies the mode line format (see `mode-line-format'
20623 for details) to use.
20625 By default, the format is evaluated for the currently selected window.
20627 Optional second arg FACE specifies the face property to put on all
20628 characters for which no face is specified. The value nil means the
20629 default face. The value t means whatever face the window's mode line
20630 currently uses (either `mode-line' or `mode-line-inactive',
20631 depending on whether the window is the selected window or not).
20632 An integer value means the value string has no text
20635 Optional third and fourth args WINDOW and BUFFER specify the window
20636 and buffer to use as the context for the formatting (defaults
20637 are the selected window and the WINDOW's buffer). */)
20638 (Lisp_Object format
, Lisp_Object face
,
20639 Lisp_Object window
, Lisp_Object buffer
)
20644 struct buffer
*old_buffer
= NULL
;
20646 int no_props
= INTEGERP (face
);
20647 int count
= SPECPDL_INDEX ();
20649 int string_start
= 0;
20652 window
= selected_window
;
20653 CHECK_WINDOW (window
);
20654 w
= XWINDOW (window
);
20657 buffer
= w
->buffer
;
20658 CHECK_BUFFER (buffer
);
20660 /* Make formatting the modeline a non-op when noninteractive, otherwise
20661 there will be problems later caused by a partially initialized frame. */
20662 if (NILP (format
) || noninteractive
)
20663 return empty_unibyte_string
;
20668 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20669 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20670 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20671 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20672 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20673 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20674 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20677 if (XBUFFER (buffer
) != current_buffer
)
20678 old_buffer
= current_buffer
;
20680 /* Save things including mode_line_proptrans_alist,
20681 and set that to nil so that we don't alter the outer value. */
20682 record_unwind_protect (unwind_format_mode_line
,
20683 format_mode_line_unwind_data
20684 (old_buffer
, selected_window
, 1));
20685 mode_line_proptrans_alist
= Qnil
;
20687 Fselect_window (window
, Qt
);
20689 set_buffer_internal_1 (XBUFFER (buffer
));
20691 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20695 mode_line_target
= MODE_LINE_NOPROP
;
20696 mode_line_string_face_prop
= Qnil
;
20697 mode_line_string_list
= Qnil
;
20698 string_start
= MODE_LINE_NOPROP_LEN (0);
20702 mode_line_target
= MODE_LINE_STRING
;
20703 mode_line_string_list
= Qnil
;
20704 mode_line_string_face
= face
;
20705 mode_line_string_face_prop
20706 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20709 push_kboard (FRAME_KBOARD (it
.f
));
20710 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20715 len
= MODE_LINE_NOPROP_LEN (string_start
);
20716 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20720 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20721 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20722 empty_unibyte_string
);
20725 unbind_to (count
, Qnil
);
20729 /* Write a null-terminated, right justified decimal representation of
20730 the positive integer D to BUF using a minimal field width WIDTH. */
20733 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
20735 register char *p
= buf
;
20743 *p
++ = d
% 10 + '0';
20748 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20759 /* Write a null-terminated, right justified decimal and "human
20760 readable" representation of the nonnegative integer D to BUF using
20761 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20763 static const char power_letter
[] =
20777 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
20779 /* We aim to represent the nonnegative integer D as
20780 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20781 EMACS_INT quotient
= d
;
20783 /* -1 means: do not use TENTHS. */
20787 /* Length of QUOTIENT.TENTHS as a string. */
20793 if (1000 <= quotient
)
20795 /* Scale to the appropriate EXPONENT. */
20798 remainder
= quotient
% 1000;
20802 while (1000 <= quotient
);
20804 /* Round to nearest and decide whether to use TENTHS or not. */
20807 tenths
= remainder
/ 100;
20808 if (50 <= remainder
% 100)
20815 if (quotient
== 10)
20823 if (500 <= remainder
)
20825 if (quotient
< 999)
20836 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
20837 if (tenths
== -1 && quotient
<= 99)
20844 p
= psuffix
= buf
+ max (width
, length
);
20846 /* Print EXPONENT. */
20847 *psuffix
++ = power_letter
[exponent
];
20850 /* Print TENTHS. */
20853 *--p
= '0' + tenths
;
20857 /* Print QUOTIENT. */
20860 int digit
= quotient
% 10;
20861 *--p
= '0' + digit
;
20863 while ((quotient
/= 10) != 0);
20865 /* Print leading spaces. */
20870 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
20871 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
20872 type of CODING_SYSTEM. Return updated pointer into BUF. */
20874 static unsigned char invalid_eol_type
[] = "(*invalid*)";
20877 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
20880 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
20881 const unsigned char *eol_str
;
20883 /* The EOL conversion we are using. */
20884 Lisp_Object eoltype
;
20886 val
= CODING_SYSTEM_SPEC (coding_system
);
20889 if (!VECTORP (val
)) /* Not yet decided. */
20894 eoltype
= eol_mnemonic_undecided
;
20895 /* Don't mention EOL conversion if it isn't decided. */
20900 Lisp_Object eolvalue
;
20902 attrs
= AREF (val
, 0);
20903 eolvalue
= AREF (val
, 2);
20906 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
20910 /* The EOL conversion that is normal on this system. */
20912 if (NILP (eolvalue
)) /* Not yet decided. */
20913 eoltype
= eol_mnemonic_undecided
;
20914 else if (VECTORP (eolvalue
)) /* Not yet decided. */
20915 eoltype
= eol_mnemonic_undecided
;
20916 else /* eolvalue is Qunix, Qdos, or Qmac. */
20917 eoltype
= (EQ (eolvalue
, Qunix
)
20918 ? eol_mnemonic_unix
20919 : (EQ (eolvalue
, Qdos
) == 1
20920 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
20926 /* Mention the EOL conversion if it is not the usual one. */
20927 if (STRINGP (eoltype
))
20929 eol_str
= SDATA (eoltype
);
20930 eol_str_len
= SBYTES (eoltype
);
20932 else if (CHARACTERP (eoltype
))
20934 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
20935 int c
= XFASTINT (eoltype
);
20936 eol_str_len
= CHAR_STRING (c
, tmp
);
20941 eol_str
= invalid_eol_type
;
20942 eol_str_len
= sizeof (invalid_eol_type
) - 1;
20944 memcpy (buf
, eol_str
, eol_str_len
);
20945 buf
+= eol_str_len
;
20951 /* Return a string for the output of a mode line %-spec for window W,
20952 generated by character C. FIELD_WIDTH > 0 means pad the string
20953 returned with spaces to that value. Return a Lisp string in
20954 *STRING if the resulting string is taken from that Lisp string.
20956 Note we operate on the current buffer for most purposes,
20957 the exception being w->base_line_pos. */
20959 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
20961 static const char *
20962 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
20963 Lisp_Object
*string
)
20966 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20967 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
20968 struct buffer
*b
= current_buffer
;
20976 if (!NILP (BVAR (b
, read_only
)))
20978 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20983 /* This differs from %* only for a modified read-only buffer. */
20984 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20986 if (!NILP (BVAR (b
, read_only
)))
20991 /* This differs from %* in ignoring read-only-ness. */
20992 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21004 if (command_loop_level
> 5)
21006 p
= decode_mode_spec_buf
;
21007 for (i
= 0; i
< command_loop_level
; i
++)
21010 return decode_mode_spec_buf
;
21018 if (command_loop_level
> 5)
21020 p
= decode_mode_spec_buf
;
21021 for (i
= 0; i
< command_loop_level
; i
++)
21024 return decode_mode_spec_buf
;
21031 /* Let lots_of_dashes be a string of infinite length. */
21032 if (mode_line_target
== MODE_LINE_NOPROP
||
21033 mode_line_target
== MODE_LINE_STRING
)
21035 if (field_width
<= 0
21036 || field_width
> sizeof (lots_of_dashes
))
21038 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21039 decode_mode_spec_buf
[i
] = '-';
21040 decode_mode_spec_buf
[i
] = '\0';
21041 return decode_mode_spec_buf
;
21044 return lots_of_dashes
;
21048 obj
= BVAR (b
, name
);
21052 /* %c and %l are ignored in `frame-title-format'.
21053 (In redisplay_internal, the frame title is drawn _before_ the
21054 windows are updated, so the stuff which depends on actual
21055 window contents (such as %l) may fail to render properly, or
21056 even crash emacs.) */
21057 if (mode_line_target
== MODE_LINE_TITLE
)
21061 EMACS_INT col
= current_column ();
21062 w
->column_number_displayed
= make_number (col
);
21063 pint2str (decode_mode_spec_buf
, field_width
, col
);
21064 return decode_mode_spec_buf
;
21068 #ifndef SYSTEM_MALLOC
21070 if (NILP (Vmemory_full
))
21073 return "!MEM FULL! ";
21080 /* %F displays the frame name. */
21081 if (!NILP (f
->title
))
21082 return SSDATA (f
->title
);
21083 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21084 return SSDATA (f
->name
);
21088 obj
= BVAR (b
, filename
);
21093 EMACS_INT size
= ZV
- BEGV
;
21094 pint2str (decode_mode_spec_buf
, field_width
, size
);
21095 return decode_mode_spec_buf
;
21100 EMACS_INT size
= ZV
- BEGV
;
21101 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21102 return decode_mode_spec_buf
;
21107 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21108 EMACS_INT topline
, nlines
, height
;
21111 /* %c and %l are ignored in `frame-title-format'. */
21112 if (mode_line_target
== MODE_LINE_TITLE
)
21115 startpos
= XMARKER (w
->start
)->charpos
;
21116 startpos_byte
= marker_byte_position (w
->start
);
21117 height
= WINDOW_TOTAL_LINES (w
);
21119 /* If we decided that this buffer isn't suitable for line numbers,
21120 don't forget that too fast. */
21121 if (EQ (w
->base_line_pos
, w
->buffer
))
21123 /* But do forget it, if the window shows a different buffer now. */
21124 else if (BUFFERP (w
->base_line_pos
))
21125 w
->base_line_pos
= Qnil
;
21127 /* If the buffer is very big, don't waste time. */
21128 if (INTEGERP (Vline_number_display_limit
)
21129 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21131 w
->base_line_pos
= Qnil
;
21132 w
->base_line_number
= Qnil
;
21136 if (INTEGERP (w
->base_line_number
)
21137 && INTEGERP (w
->base_line_pos
)
21138 && XFASTINT (w
->base_line_pos
) <= startpos
)
21140 line
= XFASTINT (w
->base_line_number
);
21141 linepos
= XFASTINT (w
->base_line_pos
);
21142 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21147 linepos
= BUF_BEGV (b
);
21148 linepos_byte
= BUF_BEGV_BYTE (b
);
21151 /* Count lines from base line to window start position. */
21152 nlines
= display_count_lines (linepos_byte
,
21156 topline
= nlines
+ line
;
21158 /* Determine a new base line, if the old one is too close
21159 or too far away, or if we did not have one.
21160 "Too close" means it's plausible a scroll-down would
21161 go back past it. */
21162 if (startpos
== BUF_BEGV (b
))
21164 w
->base_line_number
= make_number (topline
);
21165 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21167 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21168 || linepos
== BUF_BEGV (b
))
21170 EMACS_INT limit
= BUF_BEGV (b
);
21171 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
21172 EMACS_INT position
;
21173 EMACS_INT distance
=
21174 (height
* 2 + 30) * line_number_display_limit_width
;
21176 if (startpos
- distance
> limit
)
21178 limit
= startpos
- distance
;
21179 limit_byte
= CHAR_TO_BYTE (limit
);
21182 nlines
= display_count_lines (startpos_byte
,
21184 - (height
* 2 + 30),
21186 /* If we couldn't find the lines we wanted within
21187 line_number_display_limit_width chars per line,
21188 give up on line numbers for this window. */
21189 if (position
== limit_byte
&& limit
== startpos
- distance
)
21191 w
->base_line_pos
= w
->buffer
;
21192 w
->base_line_number
= Qnil
;
21196 w
->base_line_number
= make_number (topline
- nlines
);
21197 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21200 /* Now count lines from the start pos to point. */
21201 nlines
= display_count_lines (startpos_byte
,
21202 PT_BYTE
, PT
, &junk
);
21204 /* Record that we did display the line number. */
21205 line_number_displayed
= 1;
21207 /* Make the string to show. */
21208 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21209 return decode_mode_spec_buf
;
21212 char* p
= decode_mode_spec_buf
;
21213 int pad
= field_width
- 2;
21219 return decode_mode_spec_buf
;
21225 obj
= BVAR (b
, mode_name
);
21229 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21235 EMACS_INT pos
= marker_position (w
->start
);
21236 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
21238 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21240 if (pos
<= BUF_BEGV (b
))
21245 else if (pos
<= BUF_BEGV (b
))
21249 if (total
> 1000000)
21250 /* Do it differently for a large value, to avoid overflow. */
21251 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21253 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21254 /* We can't normally display a 3-digit number,
21255 so get us a 2-digit number that is close. */
21258 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
21259 return decode_mode_spec_buf
;
21263 /* Display percentage of size above the bottom of the screen. */
21266 EMACS_INT toppos
= marker_position (w
->start
);
21267 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21268 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
21270 if (botpos
>= BUF_ZV (b
))
21272 if (toppos
<= BUF_BEGV (b
))
21279 if (total
> 1000000)
21280 /* Do it differently for a large value, to avoid overflow. */
21281 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21283 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21284 /* We can't normally display a 3-digit number,
21285 so get us a 2-digit number that is close. */
21288 if (toppos
<= BUF_BEGV (b
))
21289 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
21291 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
21292 return decode_mode_spec_buf
;
21297 /* status of process */
21298 obj
= Fget_buffer_process (Fcurrent_buffer ());
21300 return "no process";
21302 obj
= Fsymbol_name (Fprocess_status (obj
));
21308 int count
= inhibit_garbage_collection ();
21309 Lisp_Object val
= call1 (intern ("file-remote-p"),
21310 BVAR (current_buffer
, directory
));
21311 unbind_to (count
, Qnil
);
21319 case 't': /* indicate TEXT or BINARY */
21323 /* coding-system (not including end-of-line format) */
21325 /* coding-system (including end-of-line type) */
21327 int eol_flag
= (c
== 'Z');
21328 char *p
= decode_mode_spec_buf
;
21330 if (! FRAME_WINDOW_P (f
))
21332 /* No need to mention EOL here--the terminal never needs
21333 to do EOL conversion. */
21334 p
= decode_mode_spec_coding (CODING_ID_NAME
21335 (FRAME_KEYBOARD_CODING (f
)->id
),
21337 p
= decode_mode_spec_coding (CODING_ID_NAME
21338 (FRAME_TERMINAL_CODING (f
)->id
),
21341 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21344 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21345 #ifdef subprocesses
21346 obj
= Fget_buffer_process (Fcurrent_buffer ());
21347 if (PROCESSP (obj
))
21349 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21351 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21354 #endif /* subprocesses */
21357 return decode_mode_spec_buf
;
21364 return SSDATA (obj
);
21371 /* Count up to COUNT lines starting from START_BYTE.
21372 But don't go beyond LIMIT_BYTE.
21373 Return the number of lines thus found (always nonnegative).
21375 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21378 display_count_lines (EMACS_INT start_byte
,
21379 EMACS_INT limit_byte
, EMACS_INT count
,
21380 EMACS_INT
*byte_pos_ptr
)
21382 register unsigned char *cursor
;
21383 unsigned char *base
;
21385 register EMACS_INT ceiling
;
21386 register unsigned char *ceiling_addr
;
21387 EMACS_INT orig_count
= count
;
21389 /* If we are not in selective display mode,
21390 check only for newlines. */
21391 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21392 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21396 while (start_byte
< limit_byte
)
21398 ceiling
= BUFFER_CEILING_OF (start_byte
);
21399 ceiling
= min (limit_byte
- 1, ceiling
);
21400 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21401 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21404 if (selective_display
)
21405 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21408 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21411 if (cursor
!= ceiling_addr
)
21415 start_byte
+= cursor
- base
+ 1;
21416 *byte_pos_ptr
= start_byte
;
21420 if (++cursor
== ceiling_addr
)
21426 start_byte
+= cursor
- base
;
21431 while (start_byte
> limit_byte
)
21433 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21434 ceiling
= max (limit_byte
, ceiling
);
21435 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21436 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21439 if (selective_display
)
21440 while (--cursor
!= ceiling_addr
21441 && *cursor
!= '\n' && *cursor
!= 015)
21444 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21447 if (cursor
!= ceiling_addr
)
21451 start_byte
+= cursor
- base
+ 1;
21452 *byte_pos_ptr
= start_byte
;
21453 /* When scanning backwards, we should
21454 not count the newline posterior to which we stop. */
21455 return - orig_count
- 1;
21461 /* Here we add 1 to compensate for the last decrement
21462 of CURSOR, which took it past the valid range. */
21463 start_byte
+= cursor
- base
+ 1;
21467 *byte_pos_ptr
= limit_byte
;
21470 return - orig_count
+ count
;
21471 return orig_count
- count
;
21477 /***********************************************************************
21479 ***********************************************************************/
21481 /* Display a NUL-terminated string, starting with index START.
21483 If STRING is non-null, display that C string. Otherwise, the Lisp
21484 string LISP_STRING is displayed. There's a case that STRING is
21485 non-null and LISP_STRING is not nil. It means STRING is a string
21486 data of LISP_STRING. In that case, we display LISP_STRING while
21487 ignoring its text properties.
21489 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21490 FACE_STRING. Display STRING or LISP_STRING with the face at
21491 FACE_STRING_POS in FACE_STRING:
21493 Display the string in the environment given by IT, but use the
21494 standard display table, temporarily.
21496 FIELD_WIDTH is the minimum number of output glyphs to produce.
21497 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21498 with spaces. If STRING has more characters, more than FIELD_WIDTH
21499 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21501 PRECISION is the maximum number of characters to output from
21502 STRING. PRECISION < 0 means don't truncate the string.
21504 This is roughly equivalent to printf format specifiers:
21506 FIELD_WIDTH PRECISION PRINTF
21507 ----------------------------------------
21513 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21514 display them, and < 0 means obey the current buffer's value of
21515 enable_multibyte_characters.
21517 Value is the number of columns displayed. */
21520 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21521 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
21522 int field_width
, int precision
, int max_x
, int multibyte
)
21524 int hpos_at_start
= it
->hpos
;
21525 int saved_face_id
= it
->face_id
;
21526 struct glyph_row
*row
= it
->glyph_row
;
21527 EMACS_INT it_charpos
;
21529 /* Initialize the iterator IT for iteration over STRING beginning
21530 with index START. */
21531 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21532 precision
, field_width
, multibyte
);
21533 if (string
&& STRINGP (lisp_string
))
21534 /* LISP_STRING is the one returned by decode_mode_spec. We should
21535 ignore its text properties. */
21536 it
->stop_charpos
= it
->end_charpos
;
21538 /* If displaying STRING, set up the face of the iterator from
21539 FACE_STRING, if that's given. */
21540 if (STRINGP (face_string
))
21546 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21547 0, it
->region_beg_charpos
,
21548 it
->region_end_charpos
,
21549 &endptr
, it
->base_face_id
, 0);
21550 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21551 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21554 /* Set max_x to the maximum allowed X position. Don't let it go
21555 beyond the right edge of the window. */
21557 max_x
= it
->last_visible_x
;
21559 max_x
= min (max_x
, it
->last_visible_x
);
21561 /* Skip over display elements that are not visible. because IT->w is
21563 if (it
->current_x
< it
->first_visible_x
)
21564 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21565 MOVE_TO_POS
| MOVE_TO_X
);
21567 row
->ascent
= it
->max_ascent
;
21568 row
->height
= it
->max_ascent
+ it
->max_descent
;
21569 row
->phys_ascent
= it
->max_phys_ascent
;
21570 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21571 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21573 if (STRINGP (it
->string
))
21574 it_charpos
= IT_STRING_CHARPOS (*it
);
21576 it_charpos
= IT_CHARPOS (*it
);
21578 /* This condition is for the case that we are called with current_x
21579 past last_visible_x. */
21580 while (it
->current_x
< max_x
)
21582 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21584 /* Get the next display element. */
21585 if (!get_next_display_element (it
))
21588 /* Produce glyphs. */
21589 x_before
= it
->current_x
;
21590 n_glyphs_before
= row
->used
[TEXT_AREA
];
21591 PRODUCE_GLYPHS (it
);
21593 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21596 while (i
< nglyphs
)
21598 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21600 if (it
->line_wrap
!= TRUNCATE
21601 && x
+ glyph
->pixel_width
> max_x
)
21603 /* End of continued line or max_x reached. */
21604 if (CHAR_GLYPH_PADDING_P (*glyph
))
21606 /* A wide character is unbreakable. */
21607 if (row
->reversed_p
)
21608 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21609 - n_glyphs_before
);
21610 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21611 it
->current_x
= x_before
;
21615 if (row
->reversed_p
)
21616 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21617 - (n_glyphs_before
+ i
));
21618 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21623 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21625 /* Glyph is at least partially visible. */
21627 if (x
< it
->first_visible_x
)
21628 row
->x
= x
- it
->first_visible_x
;
21632 /* Glyph is off the left margin of the display area.
21633 Should not happen. */
21637 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21638 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21639 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21640 row
->phys_height
= max (row
->phys_height
,
21641 it
->max_phys_ascent
+ it
->max_phys_descent
);
21642 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21643 it
->max_extra_line_spacing
);
21644 x
+= glyph
->pixel_width
;
21648 /* Stop if max_x reached. */
21652 /* Stop at line ends. */
21653 if (ITERATOR_AT_END_OF_LINE_P (it
))
21655 it
->continuation_lines_width
= 0;
21659 set_iterator_to_next (it
, 1);
21660 if (STRINGP (it
->string
))
21661 it_charpos
= IT_STRING_CHARPOS (*it
);
21663 it_charpos
= IT_CHARPOS (*it
);
21665 /* Stop if truncating at the right edge. */
21666 if (it
->line_wrap
== TRUNCATE
21667 && it
->current_x
>= it
->last_visible_x
)
21669 /* Add truncation mark, but don't do it if the line is
21670 truncated at a padding space. */
21671 if (it_charpos
< it
->string_nchars
)
21673 if (!FRAME_WINDOW_P (it
->f
))
21677 if (it
->current_x
> it
->last_visible_x
)
21679 if (!row
->reversed_p
)
21681 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21682 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21687 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21688 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21690 unproduce_glyphs (it
, ii
+ 1);
21691 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21693 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21695 row
->used
[TEXT_AREA
] = ii
;
21696 produce_special_glyphs (it
, IT_TRUNCATION
);
21699 produce_special_glyphs (it
, IT_TRUNCATION
);
21701 row
->truncated_on_right_p
= 1;
21707 /* Maybe insert a truncation at the left. */
21708 if (it
->first_visible_x
21711 if (!FRAME_WINDOW_P (it
->f
))
21712 insert_left_trunc_glyphs (it
);
21713 row
->truncated_on_left_p
= 1;
21716 it
->face_id
= saved_face_id
;
21718 /* Value is number of columns displayed. */
21719 return it
->hpos
- hpos_at_start
;
21724 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21725 appears as an element of LIST or as the car of an element of LIST.
21726 If PROPVAL is a list, compare each element against LIST in that
21727 way, and return 1/2 if any element of PROPVAL is found in LIST.
21728 Otherwise return 0. This function cannot quit.
21729 The return value is 2 if the text is invisible but with an ellipsis
21730 and 1 if it's invisible and without an ellipsis. */
21733 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21735 register Lisp_Object tail
, proptail
;
21737 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21739 register Lisp_Object tem
;
21741 if (EQ (propval
, tem
))
21743 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21744 return NILP (XCDR (tem
)) ? 1 : 2;
21747 if (CONSP (propval
))
21749 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21751 Lisp_Object propelt
;
21752 propelt
= XCAR (proptail
);
21753 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21755 register Lisp_Object tem
;
21757 if (EQ (propelt
, tem
))
21759 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21760 return NILP (XCDR (tem
)) ? 1 : 2;
21768 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21769 doc
: /* Non-nil if the property makes the text invisible.
21770 POS-OR-PROP can be a marker or number, in which case it is taken to be
21771 a position in the current buffer and the value of the `invisible' property
21772 is checked; or it can be some other value, which is then presumed to be the
21773 value of the `invisible' property of the text of interest.
21774 The non-nil value returned can be t for truly invisible text or something
21775 else if the text is replaced by an ellipsis. */)
21776 (Lisp_Object pos_or_prop
)
21779 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21780 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21782 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21783 return (invis
== 0 ? Qnil
21785 : make_number (invis
));
21788 /* Calculate a width or height in pixels from a specification using
21789 the following elements:
21792 NUM - a (fractional) multiple of the default font width/height
21793 (NUM) - specifies exactly NUM pixels
21794 UNIT - a fixed number of pixels, see below.
21795 ELEMENT - size of a display element in pixels, see below.
21796 (NUM . SPEC) - equals NUM * SPEC
21797 (+ SPEC SPEC ...) - add pixel values
21798 (- SPEC SPEC ...) - subtract pixel values
21799 (- SPEC) - negate pixel value
21802 INT or FLOAT - a number constant
21803 SYMBOL - use symbol's (buffer local) variable binding.
21806 in - pixels per inch *)
21807 mm - pixels per 1/1000 meter *)
21808 cm - pixels per 1/100 meter *)
21809 width - width of current font in pixels.
21810 height - height of current font in pixels.
21812 *) using the ratio(s) defined in display-pixels-per-inch.
21816 left-fringe - left fringe width in pixels
21817 right-fringe - right fringe width in pixels
21819 left-margin - left margin width in pixels
21820 right-margin - right margin width in pixels
21822 scroll-bar - scroll-bar area width in pixels
21826 Pixels corresponding to 5 inches:
21829 Total width of non-text areas on left side of window (if scroll-bar is on left):
21830 '(space :width (+ left-fringe left-margin scroll-bar))
21832 Align to first text column (in header line):
21833 '(space :align-to 0)
21835 Align to middle of text area minus half the width of variable `my-image'
21836 containing a loaded image:
21837 '(space :align-to (0.5 . (- text my-image)))
21839 Width of left margin minus width of 1 character in the default font:
21840 '(space :width (- left-margin 1))
21842 Width of left margin minus width of 2 characters in the current font:
21843 '(space :width (- left-margin (2 . width)))
21845 Center 1 character over left-margin (in header line):
21846 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
21848 Different ways to express width of left fringe plus left margin minus one pixel:
21849 '(space :width (- (+ left-fringe left-margin) (1)))
21850 '(space :width (+ left-fringe left-margin (- (1))))
21851 '(space :width (+ left-fringe left-margin (-1)))
21855 #define NUMVAL(X) \
21856 ((INTEGERP (X) || FLOATP (X)) \
21861 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
21862 struct font
*font
, int width_p
, int *align_to
)
21866 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
21867 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
21870 return OK_PIXELS (0);
21872 xassert (FRAME_LIVE_P (it
->f
));
21874 if (SYMBOLP (prop
))
21876 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
21878 char *unit
= SSDATA (SYMBOL_NAME (prop
));
21880 if (unit
[0] == 'i' && unit
[1] == 'n')
21882 else if (unit
[0] == 'm' && unit
[1] == 'm')
21884 else if (unit
[0] == 'c' && unit
[1] == 'm')
21891 #ifdef HAVE_WINDOW_SYSTEM
21892 if (FRAME_WINDOW_P (it
->f
)
21894 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
21895 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
21897 return OK_PIXELS (ppi
/ pixels
);
21900 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
21901 || (CONSP (Vdisplay_pixels_per_inch
)
21903 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
21904 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
21906 return OK_PIXELS (ppi
/ pixels
);
21912 #ifdef HAVE_WINDOW_SYSTEM
21913 if (EQ (prop
, Qheight
))
21914 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
21915 if (EQ (prop
, Qwidth
))
21916 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
21918 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
21919 return OK_PIXELS (1);
21922 if (EQ (prop
, Qtext
))
21923 return OK_PIXELS (width_p
21924 ? window_box_width (it
->w
, TEXT_AREA
)
21925 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
21927 if (align_to
&& *align_to
< 0)
21930 if (EQ (prop
, Qleft
))
21931 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
21932 if (EQ (prop
, Qright
))
21933 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
21934 if (EQ (prop
, Qcenter
))
21935 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
21936 + window_box_width (it
->w
, TEXT_AREA
) / 2);
21937 if (EQ (prop
, Qleft_fringe
))
21938 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21939 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
21940 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
21941 if (EQ (prop
, Qright_fringe
))
21942 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21943 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21944 : window_box_right_offset (it
->w
, TEXT_AREA
));
21945 if (EQ (prop
, Qleft_margin
))
21946 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
21947 if (EQ (prop
, Qright_margin
))
21948 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
21949 if (EQ (prop
, Qscroll_bar
))
21950 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
21952 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21953 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21954 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21959 if (EQ (prop
, Qleft_fringe
))
21960 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
21961 if (EQ (prop
, Qright_fringe
))
21962 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
21963 if (EQ (prop
, Qleft_margin
))
21964 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
21965 if (EQ (prop
, Qright_margin
))
21966 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
21967 if (EQ (prop
, Qscroll_bar
))
21968 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
21971 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
21974 if (INTEGERP (prop
) || FLOATP (prop
))
21976 int base_unit
= (width_p
21977 ? FRAME_COLUMN_WIDTH (it
->f
)
21978 : FRAME_LINE_HEIGHT (it
->f
));
21979 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21984 Lisp_Object car
= XCAR (prop
);
21985 Lisp_Object cdr
= XCDR (prop
);
21989 #ifdef HAVE_WINDOW_SYSTEM
21990 if (FRAME_WINDOW_P (it
->f
)
21991 && valid_image_p (prop
))
21993 ptrdiff_t id
= lookup_image (it
->f
, prop
);
21994 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21996 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21999 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22005 while (CONSP (cdr
))
22007 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22008 font
, width_p
, align_to
))
22011 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22016 if (EQ (car
, Qminus
))
22018 return OK_PIXELS (pixels
);
22021 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
22024 if (INTEGERP (car
) || FLOATP (car
))
22027 pixels
= XFLOATINT (car
);
22029 return OK_PIXELS (pixels
);
22030 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22031 font
, width_p
, align_to
))
22032 return OK_PIXELS (pixels
* fact
);
22043 /***********************************************************************
22045 ***********************************************************************/
22047 #ifdef HAVE_WINDOW_SYSTEM
22052 dump_glyph_string (struct glyph_string
*s
)
22054 fprintf (stderr
, "glyph string\n");
22055 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22056 s
->x
, s
->y
, s
->width
, s
->height
);
22057 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22058 fprintf (stderr
, " hl = %d\n", s
->hl
);
22059 fprintf (stderr
, " left overhang = %d, right = %d\n",
22060 s
->left_overhang
, s
->right_overhang
);
22061 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22062 fprintf (stderr
, " extends to end of line = %d\n",
22063 s
->extends_to_end_of_line_p
);
22064 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22065 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22068 #endif /* GLYPH_DEBUG */
22070 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22071 of XChar2b structures for S; it can't be allocated in
22072 init_glyph_string because it must be allocated via `alloca'. W
22073 is the window on which S is drawn. ROW and AREA are the glyph row
22074 and area within the row from which S is constructed. START is the
22075 index of the first glyph structure covered by S. HL is a
22076 face-override for drawing S. */
22079 #define OPTIONAL_HDC(hdc) HDC hdc,
22080 #define DECLARE_HDC(hdc) HDC hdc;
22081 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22082 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22085 #ifndef OPTIONAL_HDC
22086 #define OPTIONAL_HDC(hdc)
22087 #define DECLARE_HDC(hdc)
22088 #define ALLOCATE_HDC(hdc, f)
22089 #define RELEASE_HDC(hdc, f)
22093 init_glyph_string (struct glyph_string
*s
,
22095 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22096 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22098 memset (s
, 0, sizeof *s
);
22100 s
->f
= XFRAME (w
->frame
);
22104 s
->display
= FRAME_X_DISPLAY (s
->f
);
22105 s
->window
= FRAME_X_WINDOW (s
->f
);
22106 s
->char2b
= char2b
;
22110 s
->first_glyph
= row
->glyphs
[area
] + start
;
22111 s
->height
= row
->height
;
22112 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22113 s
->ybase
= s
->y
+ row
->ascent
;
22117 /* Append the list of glyph strings with head H and tail T to the list
22118 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22121 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22122 struct glyph_string
*h
, struct glyph_string
*t
)
22136 /* Prepend the list of glyph strings with head H and tail T to the
22137 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22141 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22142 struct glyph_string
*h
, struct glyph_string
*t
)
22156 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22157 Set *HEAD and *TAIL to the resulting list. */
22160 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22161 struct glyph_string
*s
)
22163 s
->next
= s
->prev
= NULL
;
22164 append_glyph_string_lists (head
, tail
, s
, s
);
22168 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22169 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22170 make sure that X resources for the face returned are allocated.
22171 Value is a pointer to a realized face that is ready for display if
22172 DISPLAY_P is non-zero. */
22174 static inline struct face
*
22175 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22176 XChar2b
*char2b
, int display_p
)
22178 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22182 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22184 if (code
!= FONT_INVALID_CODE
)
22185 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22187 STORE_XCHAR2B (char2b
, 0, 0);
22190 /* Make sure X resources of the face are allocated. */
22191 #ifdef HAVE_X_WINDOWS
22195 xassert (face
!= NULL
);
22196 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22203 /* Get face and two-byte form of character glyph GLYPH on frame F.
22204 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22205 a pointer to a realized face that is ready for display. */
22207 static inline struct face
*
22208 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22209 XChar2b
*char2b
, int *two_byte_p
)
22213 xassert (glyph
->type
== CHAR_GLYPH
);
22214 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22223 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22224 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22226 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22228 if (code
!= FONT_INVALID_CODE
)
22229 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22231 STORE_XCHAR2B (char2b
, 0, 0);
22234 /* Make sure X resources of the face are allocated. */
22235 xassert (face
!= NULL
);
22236 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22241 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22242 Return 1 if FONT has a glyph for C, otherwise return 0. */
22245 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22249 if (CHAR_BYTE8_P (c
))
22250 code
= CHAR_TO_BYTE8 (c
);
22252 code
= font
->driver
->encode_char (font
, c
);
22254 if (code
== FONT_INVALID_CODE
)
22256 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22261 /* Fill glyph string S with composition components specified by S->cmp.
22263 BASE_FACE is the base face of the composition.
22264 S->cmp_from is the index of the first component for S.
22266 OVERLAPS non-zero means S should draw the foreground only, and use
22267 its physical height for clipping. See also draw_glyphs.
22269 Value is the index of a component not in S. */
22272 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22276 /* For all glyphs of this composition, starting at the offset
22277 S->cmp_from, until we reach the end of the definition or encounter a
22278 glyph that requires the different face, add it to S. */
22283 s
->for_overlaps
= overlaps
;
22286 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22288 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22290 /* TAB in a composition means display glyphs with padding space
22291 on the left or right. */
22294 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22297 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22304 s
->font
= s
->face
->font
;
22306 else if (s
->face
!= face
)
22314 if (s
->face
== NULL
)
22316 s
->face
= base_face
->ascii_face
;
22317 s
->font
= s
->face
->font
;
22320 /* All glyph strings for the same composition has the same width,
22321 i.e. the width set for the first component of the composition. */
22322 s
->width
= s
->first_glyph
->pixel_width
;
22324 /* If the specified font could not be loaded, use the frame's
22325 default font, but record the fact that we couldn't load it in
22326 the glyph string so that we can draw rectangles for the
22327 characters of the glyph string. */
22328 if (s
->font
== NULL
)
22330 s
->font_not_found_p
= 1;
22331 s
->font
= FRAME_FONT (s
->f
);
22334 /* Adjust base line for subscript/superscript text. */
22335 s
->ybase
+= s
->first_glyph
->voffset
;
22337 /* This glyph string must always be drawn with 16-bit functions. */
22344 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22345 int start
, int end
, int overlaps
)
22347 struct glyph
*glyph
, *last
;
22348 Lisp_Object lgstring
;
22351 s
->for_overlaps
= overlaps
;
22352 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22353 last
= s
->row
->glyphs
[s
->area
] + end
;
22354 s
->cmp_id
= glyph
->u
.cmp
.id
;
22355 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22356 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22357 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22358 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22359 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22361 while (glyph
< last
22362 && glyph
->u
.cmp
.automatic
22363 && glyph
->u
.cmp
.id
== s
->cmp_id
22364 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22365 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22367 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22369 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22370 unsigned code
= LGLYPH_CODE (lglyph
);
22372 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22374 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22375 return glyph
- s
->row
->glyphs
[s
->area
];
22379 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22380 See the comment of fill_glyph_string for arguments.
22381 Value is the index of the first glyph not in S. */
22385 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22386 int start
, int end
, int overlaps
)
22388 struct glyph
*glyph
, *last
;
22391 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22392 s
->for_overlaps
= overlaps
;
22393 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22394 last
= s
->row
->glyphs
[s
->area
] + end
;
22395 voffset
= glyph
->voffset
;
22396 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22397 s
->font
= s
->face
->font
;
22399 s
->width
= glyph
->pixel_width
;
22401 while (glyph
< last
22402 && glyph
->type
== GLYPHLESS_GLYPH
22403 && glyph
->voffset
== voffset
22404 && glyph
->face_id
== face_id
)
22407 s
->width
+= glyph
->pixel_width
;
22410 s
->ybase
+= voffset
;
22411 return glyph
- s
->row
->glyphs
[s
->area
];
22415 /* Fill glyph string S from a sequence of character glyphs.
22417 FACE_ID is the face id of the string. START is the index of the
22418 first glyph to consider, END is the index of the last + 1.
22419 OVERLAPS non-zero means S should draw the foreground only, and use
22420 its physical height for clipping. See also draw_glyphs.
22422 Value is the index of the first glyph not in S. */
22425 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22426 int start
, int end
, int overlaps
)
22428 struct glyph
*glyph
, *last
;
22430 int glyph_not_available_p
;
22432 xassert (s
->f
== XFRAME (s
->w
->frame
));
22433 xassert (s
->nchars
== 0);
22434 xassert (start
>= 0 && end
> start
);
22436 s
->for_overlaps
= overlaps
;
22437 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22438 last
= s
->row
->glyphs
[s
->area
] + end
;
22439 voffset
= glyph
->voffset
;
22440 s
->padding_p
= glyph
->padding_p
;
22441 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22443 while (glyph
< last
22444 && glyph
->type
== CHAR_GLYPH
22445 && glyph
->voffset
== voffset
22446 /* Same face id implies same font, nowadays. */
22447 && glyph
->face_id
== face_id
22448 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22452 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22453 s
->char2b
+ s
->nchars
,
22455 s
->two_byte_p
= two_byte_p
;
22457 xassert (s
->nchars
<= end
- start
);
22458 s
->width
+= glyph
->pixel_width
;
22459 if (glyph
++->padding_p
!= s
->padding_p
)
22463 s
->font
= s
->face
->font
;
22465 /* If the specified font could not be loaded, use the frame's font,
22466 but record the fact that we couldn't load it in
22467 S->font_not_found_p so that we can draw rectangles for the
22468 characters of the glyph string. */
22469 if (s
->font
== NULL
|| glyph_not_available_p
)
22471 s
->font_not_found_p
= 1;
22472 s
->font
= FRAME_FONT (s
->f
);
22475 /* Adjust base line for subscript/superscript text. */
22476 s
->ybase
+= voffset
;
22478 xassert (s
->face
&& s
->face
->gc
);
22479 return glyph
- s
->row
->glyphs
[s
->area
];
22483 /* Fill glyph string S from image glyph S->first_glyph. */
22486 fill_image_glyph_string (struct glyph_string
*s
)
22488 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22489 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22491 s
->slice
= s
->first_glyph
->slice
.img
;
22492 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22493 s
->font
= s
->face
->font
;
22494 s
->width
= s
->first_glyph
->pixel_width
;
22496 /* Adjust base line for subscript/superscript text. */
22497 s
->ybase
+= s
->first_glyph
->voffset
;
22501 /* Fill glyph string S from a sequence of stretch glyphs.
22503 START is the index of the first glyph to consider,
22504 END is the index of the last + 1.
22506 Value is the index of the first glyph not in S. */
22509 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22511 struct glyph
*glyph
, *last
;
22512 int voffset
, face_id
;
22514 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22516 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22517 last
= s
->row
->glyphs
[s
->area
] + end
;
22518 face_id
= glyph
->face_id
;
22519 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22520 s
->font
= s
->face
->font
;
22521 s
->width
= glyph
->pixel_width
;
22523 voffset
= glyph
->voffset
;
22527 && glyph
->type
== STRETCH_GLYPH
22528 && glyph
->voffset
== voffset
22529 && glyph
->face_id
== face_id
);
22531 s
->width
+= glyph
->pixel_width
;
22533 /* Adjust base line for subscript/superscript text. */
22534 s
->ybase
+= voffset
;
22536 /* The case that face->gc == 0 is handled when drawing the glyph
22537 string by calling PREPARE_FACE_FOR_DISPLAY. */
22539 return glyph
- s
->row
->glyphs
[s
->area
];
22542 static struct font_metrics
*
22543 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22545 static struct font_metrics metrics
;
22546 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22548 if (! font
|| code
== FONT_INVALID_CODE
)
22550 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22555 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22556 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22557 assumed to be zero. */
22560 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22562 *left
= *right
= 0;
22564 if (glyph
->type
== CHAR_GLYPH
)
22568 struct font_metrics
*pcm
;
22570 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22571 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22573 if (pcm
->rbearing
> pcm
->width
)
22574 *right
= pcm
->rbearing
- pcm
->width
;
22575 if (pcm
->lbearing
< 0)
22576 *left
= -pcm
->lbearing
;
22579 else if (glyph
->type
== COMPOSITE_GLYPH
)
22581 if (! glyph
->u
.cmp
.automatic
)
22583 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22585 if (cmp
->rbearing
> cmp
->pixel_width
)
22586 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22587 if (cmp
->lbearing
< 0)
22588 *left
= - cmp
->lbearing
;
22592 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22593 struct font_metrics metrics
;
22595 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22596 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22597 if (metrics
.rbearing
> metrics
.width
)
22598 *right
= metrics
.rbearing
- metrics
.width
;
22599 if (metrics
.lbearing
< 0)
22600 *left
= - metrics
.lbearing
;
22606 /* Return the index of the first glyph preceding glyph string S that
22607 is overwritten by S because of S's left overhang. Value is -1
22608 if no glyphs are overwritten. */
22611 left_overwritten (struct glyph_string
*s
)
22615 if (s
->left_overhang
)
22618 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22619 int first
= s
->first_glyph
- glyphs
;
22621 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22622 x
-= glyphs
[i
].pixel_width
;
22633 /* Return the index of the first glyph preceding glyph string S that
22634 is overwriting S because of its right overhang. Value is -1 if no
22635 glyph in front of S overwrites S. */
22638 left_overwriting (struct glyph_string
*s
)
22641 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22642 int first
= s
->first_glyph
- glyphs
;
22646 for (i
= first
- 1; i
>= 0; --i
)
22649 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22652 x
-= glyphs
[i
].pixel_width
;
22659 /* Return the index of the last glyph following glyph string S that is
22660 overwritten by S because of S's right overhang. Value is -1 if
22661 no such glyph is found. */
22664 right_overwritten (struct glyph_string
*s
)
22668 if (s
->right_overhang
)
22671 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22672 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22673 int end
= s
->row
->used
[s
->area
];
22675 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22676 x
+= glyphs
[i
].pixel_width
;
22685 /* Return the index of the last glyph following glyph string S that
22686 overwrites S because of its left overhang. Value is negative
22687 if no such glyph is found. */
22690 right_overwriting (struct glyph_string
*s
)
22693 int end
= s
->row
->used
[s
->area
];
22694 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22695 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22699 for (i
= first
; i
< end
; ++i
)
22702 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22705 x
+= glyphs
[i
].pixel_width
;
22712 /* Set background width of glyph string S. START is the index of the
22713 first glyph following S. LAST_X is the right-most x-position + 1
22714 in the drawing area. */
22717 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22719 /* If the face of this glyph string has to be drawn to the end of
22720 the drawing area, set S->extends_to_end_of_line_p. */
22722 if (start
== s
->row
->used
[s
->area
]
22723 && s
->area
== TEXT_AREA
22724 && ((s
->row
->fill_line_p
22725 && (s
->hl
== DRAW_NORMAL_TEXT
22726 || s
->hl
== DRAW_IMAGE_RAISED
22727 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22728 || s
->hl
== DRAW_MOUSE_FACE
))
22729 s
->extends_to_end_of_line_p
= 1;
22731 /* If S extends its face to the end of the line, set its
22732 background_width to the distance to the right edge of the drawing
22734 if (s
->extends_to_end_of_line_p
)
22735 s
->background_width
= last_x
- s
->x
+ 1;
22737 s
->background_width
= s
->width
;
22741 /* Compute overhangs and x-positions for glyph string S and its
22742 predecessors, or successors. X is the starting x-position for S.
22743 BACKWARD_P non-zero means process predecessors. */
22746 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22752 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22753 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22763 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22764 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22774 /* The following macros are only called from draw_glyphs below.
22775 They reference the following parameters of that function directly:
22776 `w', `row', `area', and `overlap_p'
22777 as well as the following local variables:
22778 `s', `f', and `hdc' (in W32) */
22781 /* On W32, silently add local `hdc' variable to argument list of
22782 init_glyph_string. */
22783 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22784 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22786 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22787 init_glyph_string (s, char2b, w, row, area, start, hl)
22790 /* Add a glyph string for a stretch glyph to the list of strings
22791 between HEAD and TAIL. START is the index of the stretch glyph in
22792 row area AREA of glyph row ROW. END is the index of the last glyph
22793 in that glyph row area. X is the current output position assigned
22794 to the new glyph string constructed. HL overrides that face of the
22795 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22796 is the right-most x-position of the drawing area. */
22798 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
22799 and below -- keep them on one line. */
22800 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22803 s = (struct glyph_string *) alloca (sizeof *s); \
22804 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22805 START = fill_stretch_glyph_string (s, START, END); \
22806 append_glyph_string (&HEAD, &TAIL, s); \
22812 /* Add a glyph string for an image glyph to the list of strings
22813 between HEAD and TAIL. START is the index of the image glyph in
22814 row area AREA of glyph row ROW. END is the index of the last glyph
22815 in that glyph row area. X is the current output position assigned
22816 to the new glyph string constructed. HL overrides that face of the
22817 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22818 is the right-most x-position of the drawing area. */
22820 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22823 s = (struct glyph_string *) alloca (sizeof *s); \
22824 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22825 fill_image_glyph_string (s); \
22826 append_glyph_string (&HEAD, &TAIL, s); \
22833 /* Add a glyph string for a sequence of character glyphs to the list
22834 of strings between HEAD and TAIL. START is the index of the first
22835 glyph in row area AREA of glyph row ROW that is part of the new
22836 glyph string. END is the index of the last glyph in that glyph row
22837 area. X is the current output position assigned to the new glyph
22838 string constructed. HL overrides that face of the glyph; e.g. it
22839 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
22840 right-most x-position of the drawing area. */
22842 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22848 face_id = (row)->glyphs[area][START].face_id; \
22850 s = (struct glyph_string *) alloca (sizeof *s); \
22851 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
22852 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22853 append_glyph_string (&HEAD, &TAIL, s); \
22855 START = fill_glyph_string (s, face_id, START, END, overlaps); \
22860 /* Add a glyph string for a composite sequence to the list of strings
22861 between HEAD and TAIL. START is the index of the first glyph in
22862 row area AREA of glyph row ROW that is part of the new glyph
22863 string. END is the index of the last glyph in that glyph row area.
22864 X is the current output position assigned to the new glyph string
22865 constructed. HL overrides that face of the glyph; e.g. it is
22866 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
22867 x-position of the drawing area. */
22869 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22871 int face_id = (row)->glyphs[area][START].face_id; \
22872 struct face *base_face = FACE_FROM_ID (f, face_id); \
22873 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
22874 struct composition *cmp = composition_table[cmp_id]; \
22876 struct glyph_string *first_s = NULL; \
22879 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
22881 /* Make glyph_strings for each glyph sequence that is drawable by \
22882 the same face, and append them to HEAD/TAIL. */ \
22883 for (n = 0; n < cmp->glyph_len;) \
22885 s = (struct glyph_string *) alloca (sizeof *s); \
22886 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22887 append_glyph_string (&(HEAD), &(TAIL), s); \
22893 n = fill_composite_glyph_string (s, base_face, overlaps); \
22901 /* Add a glyph string for a glyph-string sequence to the list of strings
22902 between HEAD and TAIL. */
22904 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22908 Lisp_Object gstring; \
22910 face_id = (row)->glyphs[area][START].face_id; \
22911 gstring = (composition_gstring_from_id \
22912 ((row)->glyphs[area][START].u.cmp.id)); \
22913 s = (struct glyph_string *) alloca (sizeof *s); \
22914 char2b = (XChar2b *) alloca ((sizeof *char2b) \
22915 * LGSTRING_GLYPH_LEN (gstring)); \
22916 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22917 append_glyph_string (&(HEAD), &(TAIL), s); \
22919 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
22923 /* Add a glyph string for a sequence of glyphless character's glyphs
22924 to the list of strings between HEAD and TAIL. The meanings of
22925 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
22927 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22932 face_id = (row)->glyphs[area][START].face_id; \
22934 s = (struct glyph_string *) alloca (sizeof *s); \
22935 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22936 append_glyph_string (&HEAD, &TAIL, s); \
22938 START = fill_glyphless_glyph_string (s, face_id, START, END, \
22944 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
22945 of AREA of glyph row ROW on window W between indices START and END.
22946 HL overrides the face for drawing glyph strings, e.g. it is
22947 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
22948 x-positions of the drawing area.
22950 This is an ugly monster macro construct because we must use alloca
22951 to allocate glyph strings (because draw_glyphs can be called
22952 asynchronously). */
22954 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22957 HEAD = TAIL = NULL; \
22958 while (START < END) \
22960 struct glyph *first_glyph = (row)->glyphs[area] + START; \
22961 switch (first_glyph->type) \
22964 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
22968 case COMPOSITE_GLYPH: \
22969 if (first_glyph->u.cmp.automatic) \
22970 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
22973 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
22977 case STRETCH_GLYPH: \
22978 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
22982 case IMAGE_GLYPH: \
22983 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
22987 case GLYPHLESS_GLYPH: \
22988 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22998 set_glyph_string_background_width (s, START, LAST_X); \
23005 /* Draw glyphs between START and END in AREA of ROW on window W,
23006 starting at x-position X. X is relative to AREA in W. HL is a
23007 face-override with the following meaning:
23009 DRAW_NORMAL_TEXT draw normally
23010 DRAW_CURSOR draw in cursor face
23011 DRAW_MOUSE_FACE draw in mouse face.
23012 DRAW_INVERSE_VIDEO draw in mode line face
23013 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23014 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23016 If OVERLAPS is non-zero, draw only the foreground of characters and
23017 clip to the physical height of ROW. Non-zero value also defines
23018 the overlapping part to be drawn:
23020 OVERLAPS_PRED overlap with preceding rows
23021 OVERLAPS_SUCC overlap with succeeding rows
23022 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23023 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23025 Value is the x-position reached, relative to AREA of W. */
23028 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23029 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
23030 enum draw_glyphs_face hl
, int overlaps
)
23032 struct glyph_string
*head
, *tail
;
23033 struct glyph_string
*s
;
23034 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23035 int i
, j
, x_reached
, last_x
, area_left
= 0;
23036 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23039 ALLOCATE_HDC (hdc
, f
);
23041 /* Let's rather be paranoid than getting a SEGV. */
23042 end
= min (end
, row
->used
[area
]);
23043 start
= max (0, start
);
23044 start
= min (end
, start
);
23046 /* Translate X to frame coordinates. Set last_x to the right
23047 end of the drawing area. */
23048 if (row
->full_width_p
)
23050 /* X is relative to the left edge of W, without scroll bars
23052 area_left
= WINDOW_LEFT_EDGE_X (w
);
23053 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23057 area_left
= window_box_left (w
, area
);
23058 last_x
= area_left
+ window_box_width (w
, area
);
23062 /* Build a doubly-linked list of glyph_string structures between
23063 head and tail from what we have to draw. Note that the macro
23064 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23065 the reason we use a separate variable `i'. */
23067 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23069 x_reached
= tail
->x
+ tail
->background_width
;
23073 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23074 the row, redraw some glyphs in front or following the glyph
23075 strings built above. */
23076 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23078 struct glyph_string
*h
, *t
;
23079 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23080 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23081 int check_mouse_face
= 0;
23084 /* If mouse highlighting is on, we may need to draw adjacent
23085 glyphs using mouse-face highlighting. */
23086 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23088 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23090 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23091 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23093 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23095 check_mouse_face
= 1;
23096 mouse_beg_col
= (row
== mouse_beg_row
)
23097 ? hlinfo
->mouse_face_beg_col
: 0;
23098 mouse_end_col
= (row
== mouse_end_row
)
23099 ? hlinfo
->mouse_face_end_col
23100 : row
->used
[TEXT_AREA
];
23104 /* Compute overhangs for all glyph strings. */
23105 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23106 for (s
= head
; s
; s
= s
->next
)
23107 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23109 /* Prepend glyph strings for glyphs in front of the first glyph
23110 string that are overwritten because of the first glyph
23111 string's left overhang. The background of all strings
23112 prepended must be drawn because the first glyph string
23114 i
= left_overwritten (head
);
23117 enum draw_glyphs_face overlap_hl
;
23119 /* If this row contains mouse highlighting, attempt to draw
23120 the overlapped glyphs with the correct highlight. This
23121 code fails if the overlap encompasses more than one glyph
23122 and mouse-highlight spans only some of these glyphs.
23123 However, making it work perfectly involves a lot more
23124 code, and I don't know if the pathological case occurs in
23125 practice, so we'll stick to this for now. --- cyd */
23126 if (check_mouse_face
23127 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23128 overlap_hl
= DRAW_MOUSE_FACE
;
23130 overlap_hl
= DRAW_NORMAL_TEXT
;
23133 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23134 overlap_hl
, dummy_x
, last_x
);
23136 compute_overhangs_and_x (t
, head
->x
, 1);
23137 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23141 /* Prepend glyph strings for glyphs in front of the first glyph
23142 string that overwrite that glyph string because of their
23143 right overhang. For these strings, only the foreground must
23144 be drawn, because it draws over the glyph string at `head'.
23145 The background must not be drawn because this would overwrite
23146 right overhangs of preceding glyphs for which no glyph
23148 i
= left_overwriting (head
);
23151 enum draw_glyphs_face overlap_hl
;
23153 if (check_mouse_face
23154 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23155 overlap_hl
= DRAW_MOUSE_FACE
;
23157 overlap_hl
= DRAW_NORMAL_TEXT
;
23160 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23161 overlap_hl
, dummy_x
, last_x
);
23162 for (s
= h
; s
; s
= s
->next
)
23163 s
->background_filled_p
= 1;
23164 compute_overhangs_and_x (t
, head
->x
, 1);
23165 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23168 /* Append glyphs strings for glyphs following the last glyph
23169 string tail that are overwritten by tail. The background of
23170 these strings has to be drawn because tail's foreground draws
23172 i
= right_overwritten (tail
);
23175 enum draw_glyphs_face overlap_hl
;
23177 if (check_mouse_face
23178 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23179 overlap_hl
= DRAW_MOUSE_FACE
;
23181 overlap_hl
= DRAW_NORMAL_TEXT
;
23183 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23184 overlap_hl
, x
, last_x
);
23185 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23186 we don't have `end = i;' here. */
23187 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23188 append_glyph_string_lists (&head
, &tail
, h
, t
);
23192 /* Append glyph strings for glyphs following the last glyph
23193 string tail that overwrite tail. The foreground of such
23194 glyphs has to be drawn because it writes into the background
23195 of tail. The background must not be drawn because it could
23196 paint over the foreground of following glyphs. */
23197 i
= right_overwriting (tail
);
23200 enum draw_glyphs_face overlap_hl
;
23201 if (check_mouse_face
23202 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23203 overlap_hl
= DRAW_MOUSE_FACE
;
23205 overlap_hl
= DRAW_NORMAL_TEXT
;
23208 i
++; /* We must include the Ith glyph. */
23209 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23210 overlap_hl
, x
, last_x
);
23211 for (s
= h
; s
; s
= s
->next
)
23212 s
->background_filled_p
= 1;
23213 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23214 append_glyph_string_lists (&head
, &tail
, h
, t
);
23216 if (clip_head
|| clip_tail
)
23217 for (s
= head
; s
; s
= s
->next
)
23219 s
->clip_head
= clip_head
;
23220 s
->clip_tail
= clip_tail
;
23224 /* Draw all strings. */
23225 for (s
= head
; s
; s
= s
->next
)
23226 FRAME_RIF (f
)->draw_glyph_string (s
);
23229 /* When focus a sole frame and move horizontally, this sets on_p to 0
23230 causing a failure to erase prev cursor position. */
23231 if (area
== TEXT_AREA
23232 && !row
->full_width_p
23233 /* When drawing overlapping rows, only the glyph strings'
23234 foreground is drawn, which doesn't erase a cursor
23238 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23239 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23240 : (tail
? tail
->x
+ tail
->background_width
: x
));
23244 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23245 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23249 /* Value is the x-position up to which drawn, relative to AREA of W.
23250 This doesn't include parts drawn because of overhangs. */
23251 if (row
->full_width_p
)
23252 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23254 x_reached
-= area_left
;
23256 RELEASE_HDC (hdc
, f
);
23261 /* Expand row matrix if too narrow. Don't expand if area
23264 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23266 if (!fonts_changed_p \
23267 && (it->glyph_row->glyphs[area] \
23268 < it->glyph_row->glyphs[area + 1])) \
23270 it->w->ncols_scale_factor++; \
23271 fonts_changed_p = 1; \
23275 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23276 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23279 append_glyph (struct it
*it
)
23281 struct glyph
*glyph
;
23282 enum glyph_row_area area
= it
->area
;
23284 xassert (it
->glyph_row
);
23285 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23287 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23288 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23290 /* If the glyph row is reversed, we need to prepend the glyph
23291 rather than append it. */
23292 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23296 /* Make room for the additional glyph. */
23297 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23299 glyph
= it
->glyph_row
->glyphs
[area
];
23301 glyph
->charpos
= CHARPOS (it
->position
);
23302 glyph
->object
= it
->object
;
23303 if (it
->pixel_width
> 0)
23305 glyph
->pixel_width
= it
->pixel_width
;
23306 glyph
->padding_p
= 0;
23310 /* Assure at least 1-pixel width. Otherwise, cursor can't
23311 be displayed correctly. */
23312 glyph
->pixel_width
= 1;
23313 glyph
->padding_p
= 1;
23315 glyph
->ascent
= it
->ascent
;
23316 glyph
->descent
= it
->descent
;
23317 glyph
->voffset
= it
->voffset
;
23318 glyph
->type
= CHAR_GLYPH
;
23319 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23320 glyph
->multibyte_p
= it
->multibyte_p
;
23321 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23322 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23323 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23324 || it
->phys_descent
> it
->descent
);
23325 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23326 glyph
->face_id
= it
->face_id
;
23327 glyph
->u
.ch
= it
->char_to_display
;
23328 glyph
->slice
.img
= null_glyph_slice
;
23329 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23332 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23333 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23335 glyph
->bidi_type
= it
->bidi_it
.type
;
23339 glyph
->resolved_level
= 0;
23340 glyph
->bidi_type
= UNKNOWN_BT
;
23342 ++it
->glyph_row
->used
[area
];
23345 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23348 /* Store one glyph for the composition IT->cmp_it.id in
23349 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23353 append_composite_glyph (struct it
*it
)
23355 struct glyph
*glyph
;
23356 enum glyph_row_area area
= it
->area
;
23358 xassert (it
->glyph_row
);
23360 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23361 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23363 /* If the glyph row is reversed, we need to prepend the glyph
23364 rather than append it. */
23365 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23369 /* Make room for the new glyph. */
23370 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23372 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23374 glyph
->charpos
= it
->cmp_it
.charpos
;
23375 glyph
->object
= it
->object
;
23376 glyph
->pixel_width
= it
->pixel_width
;
23377 glyph
->ascent
= it
->ascent
;
23378 glyph
->descent
= it
->descent
;
23379 glyph
->voffset
= it
->voffset
;
23380 glyph
->type
= COMPOSITE_GLYPH
;
23381 if (it
->cmp_it
.ch
< 0)
23383 glyph
->u
.cmp
.automatic
= 0;
23384 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23385 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23389 glyph
->u
.cmp
.automatic
= 1;
23390 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23391 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23392 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23394 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23395 glyph
->multibyte_p
= it
->multibyte_p
;
23396 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23397 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23398 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23399 || it
->phys_descent
> it
->descent
);
23400 glyph
->padding_p
= 0;
23401 glyph
->glyph_not_available_p
= 0;
23402 glyph
->face_id
= it
->face_id
;
23403 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23406 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23407 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23409 glyph
->bidi_type
= it
->bidi_it
.type
;
23411 ++it
->glyph_row
->used
[area
];
23414 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23418 /* Change IT->ascent and IT->height according to the setting of
23422 take_vertical_position_into_account (struct it
*it
)
23426 if (it
->voffset
< 0)
23427 /* Increase the ascent so that we can display the text higher
23429 it
->ascent
-= it
->voffset
;
23431 /* Increase the descent so that we can display the text lower
23433 it
->descent
+= it
->voffset
;
23438 /* Produce glyphs/get display metrics for the image IT is loaded with.
23439 See the description of struct display_iterator in dispextern.h for
23440 an overview of struct display_iterator. */
23443 produce_image_glyph (struct it
*it
)
23447 int glyph_ascent
, crop
;
23448 struct glyph_slice slice
;
23450 xassert (it
->what
== IT_IMAGE
);
23452 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23454 /* Make sure X resources of the face is loaded. */
23455 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23457 if (it
->image_id
< 0)
23459 /* Fringe bitmap. */
23460 it
->ascent
= it
->phys_ascent
= 0;
23461 it
->descent
= it
->phys_descent
= 0;
23462 it
->pixel_width
= 0;
23467 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23469 /* Make sure X resources of the image is loaded. */
23470 prepare_image_for_display (it
->f
, img
);
23472 slice
.x
= slice
.y
= 0;
23473 slice
.width
= img
->width
;
23474 slice
.height
= img
->height
;
23476 if (INTEGERP (it
->slice
.x
))
23477 slice
.x
= XINT (it
->slice
.x
);
23478 else if (FLOATP (it
->slice
.x
))
23479 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23481 if (INTEGERP (it
->slice
.y
))
23482 slice
.y
= XINT (it
->slice
.y
);
23483 else if (FLOATP (it
->slice
.y
))
23484 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23486 if (INTEGERP (it
->slice
.width
))
23487 slice
.width
= XINT (it
->slice
.width
);
23488 else if (FLOATP (it
->slice
.width
))
23489 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23491 if (INTEGERP (it
->slice
.height
))
23492 slice
.height
= XINT (it
->slice
.height
);
23493 else if (FLOATP (it
->slice
.height
))
23494 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23496 if (slice
.x
>= img
->width
)
23497 slice
.x
= img
->width
;
23498 if (slice
.y
>= img
->height
)
23499 slice
.y
= img
->height
;
23500 if (slice
.x
+ slice
.width
>= img
->width
)
23501 slice
.width
= img
->width
- slice
.x
;
23502 if (slice
.y
+ slice
.height
> img
->height
)
23503 slice
.height
= img
->height
- slice
.y
;
23505 if (slice
.width
== 0 || slice
.height
== 0)
23508 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23510 it
->descent
= slice
.height
- glyph_ascent
;
23512 it
->descent
+= img
->vmargin
;
23513 if (slice
.y
+ slice
.height
== img
->height
)
23514 it
->descent
+= img
->vmargin
;
23515 it
->phys_descent
= it
->descent
;
23517 it
->pixel_width
= slice
.width
;
23519 it
->pixel_width
+= img
->hmargin
;
23520 if (slice
.x
+ slice
.width
== img
->width
)
23521 it
->pixel_width
+= img
->hmargin
;
23523 /* It's quite possible for images to have an ascent greater than
23524 their height, so don't get confused in that case. */
23525 if (it
->descent
< 0)
23530 if (face
->box
!= FACE_NO_BOX
)
23532 if (face
->box_line_width
> 0)
23535 it
->ascent
+= face
->box_line_width
;
23536 if (slice
.y
+ slice
.height
== img
->height
)
23537 it
->descent
+= face
->box_line_width
;
23540 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23541 it
->pixel_width
+= eabs (face
->box_line_width
);
23542 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23543 it
->pixel_width
+= eabs (face
->box_line_width
);
23546 take_vertical_position_into_account (it
);
23548 /* Automatically crop wide image glyphs at right edge so we can
23549 draw the cursor on same display row. */
23550 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23551 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23553 it
->pixel_width
-= crop
;
23554 slice
.width
-= crop
;
23559 struct glyph
*glyph
;
23560 enum glyph_row_area area
= it
->area
;
23562 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23563 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23565 glyph
->charpos
= CHARPOS (it
->position
);
23566 glyph
->object
= it
->object
;
23567 glyph
->pixel_width
= it
->pixel_width
;
23568 glyph
->ascent
= glyph_ascent
;
23569 glyph
->descent
= it
->descent
;
23570 glyph
->voffset
= it
->voffset
;
23571 glyph
->type
= IMAGE_GLYPH
;
23572 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23573 glyph
->multibyte_p
= it
->multibyte_p
;
23574 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23575 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23576 glyph
->overlaps_vertically_p
= 0;
23577 glyph
->padding_p
= 0;
23578 glyph
->glyph_not_available_p
= 0;
23579 glyph
->face_id
= it
->face_id
;
23580 glyph
->u
.img_id
= img
->id
;
23581 glyph
->slice
.img
= slice
;
23582 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23585 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23586 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23588 glyph
->bidi_type
= it
->bidi_it
.type
;
23590 ++it
->glyph_row
->used
[area
];
23593 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23598 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23599 of the glyph, WIDTH and HEIGHT are the width and height of the
23600 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23603 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23604 int width
, int height
, int ascent
)
23606 struct glyph
*glyph
;
23607 enum glyph_row_area area
= it
->area
;
23609 xassert (ascent
>= 0 && ascent
<= height
);
23611 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23612 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23614 /* If the glyph row is reversed, we need to prepend the glyph
23615 rather than append it. */
23616 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23620 /* Make room for the additional glyph. */
23621 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23623 glyph
= it
->glyph_row
->glyphs
[area
];
23625 glyph
->charpos
= CHARPOS (it
->position
);
23626 glyph
->object
= object
;
23627 glyph
->pixel_width
= width
;
23628 glyph
->ascent
= ascent
;
23629 glyph
->descent
= height
- ascent
;
23630 glyph
->voffset
= it
->voffset
;
23631 glyph
->type
= STRETCH_GLYPH
;
23632 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23633 glyph
->multibyte_p
= it
->multibyte_p
;
23634 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23635 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23636 glyph
->overlaps_vertically_p
= 0;
23637 glyph
->padding_p
= 0;
23638 glyph
->glyph_not_available_p
= 0;
23639 glyph
->face_id
= it
->face_id
;
23640 glyph
->u
.stretch
.ascent
= ascent
;
23641 glyph
->u
.stretch
.height
= height
;
23642 glyph
->slice
.img
= null_glyph_slice
;
23643 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23646 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23647 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23649 glyph
->bidi_type
= it
->bidi_it
.type
;
23653 glyph
->resolved_level
= 0;
23654 glyph
->bidi_type
= UNKNOWN_BT
;
23656 ++it
->glyph_row
->used
[area
];
23659 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23662 #endif /* HAVE_WINDOW_SYSTEM */
23664 /* Produce a stretch glyph for iterator IT. IT->object is the value
23665 of the glyph property displayed. The value must be a list
23666 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23669 1. `:width WIDTH' specifies that the space should be WIDTH *
23670 canonical char width wide. WIDTH may be an integer or floating
23673 2. `:relative-width FACTOR' specifies that the width of the stretch
23674 should be computed from the width of the first character having the
23675 `glyph' property, and should be FACTOR times that width.
23677 3. `:align-to HPOS' specifies that the space should be wide enough
23678 to reach HPOS, a value in canonical character units.
23680 Exactly one of the above pairs must be present.
23682 4. `:height HEIGHT' specifies that the height of the stretch produced
23683 should be HEIGHT, measured in canonical character units.
23685 5. `:relative-height FACTOR' specifies that the height of the
23686 stretch should be FACTOR times the height of the characters having
23687 the glyph property.
23689 Either none or exactly one of 4 or 5 must be present.
23691 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23692 of the stretch should be used for the ascent of the stretch.
23693 ASCENT must be in the range 0 <= ASCENT <= 100. */
23696 produce_stretch_glyph (struct it
*it
)
23698 /* (space :width WIDTH :height HEIGHT ...) */
23699 Lisp_Object prop
, plist
;
23700 int width
= 0, height
= 0, align_to
= -1;
23701 int zero_width_ok_p
= 0;
23704 struct face
*face
= NULL
;
23705 struct font
*font
= NULL
;
23707 #ifdef HAVE_WINDOW_SYSTEM
23708 int zero_height_ok_p
= 0;
23710 if (FRAME_WINDOW_P (it
->f
))
23712 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23713 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23714 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23718 /* List should start with `space'. */
23719 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23720 plist
= XCDR (it
->object
);
23722 /* Compute the width of the stretch. */
23723 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23724 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23726 /* Absolute width `:width WIDTH' specified and valid. */
23727 zero_width_ok_p
= 1;
23730 #ifdef HAVE_WINDOW_SYSTEM
23731 else if (FRAME_WINDOW_P (it
->f
)
23732 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23734 /* Relative width `:relative-width FACTOR' specified and valid.
23735 Compute the width of the characters having the `glyph'
23738 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23741 if (it
->multibyte_p
)
23742 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23745 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23746 if (! ASCII_CHAR_P (it2
.c
))
23747 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23750 it2
.glyph_row
= NULL
;
23751 it2
.what
= IT_CHARACTER
;
23752 x_produce_glyphs (&it2
);
23753 width
= NUMVAL (prop
) * it2
.pixel_width
;
23755 #endif /* HAVE_WINDOW_SYSTEM */
23756 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23757 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23759 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23760 align_to
= (align_to
< 0
23762 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23763 else if (align_to
< 0)
23764 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23765 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23766 zero_width_ok_p
= 1;
23769 /* Nothing specified -> width defaults to canonical char width. */
23770 width
= FRAME_COLUMN_WIDTH (it
->f
);
23772 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23775 #ifdef HAVE_WINDOW_SYSTEM
23776 /* Compute height. */
23777 if (FRAME_WINDOW_P (it
->f
))
23779 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23780 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23783 zero_height_ok_p
= 1;
23785 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23787 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23789 height
= FONT_HEIGHT (font
);
23791 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
23794 /* Compute percentage of height used for ascent. If
23795 `:ascent ASCENT' is present and valid, use that. Otherwise,
23796 derive the ascent from the font in use. */
23797 if (prop
= Fplist_get (plist
, QCascent
),
23798 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
23799 ascent
= height
* NUMVAL (prop
) / 100.0;
23800 else if (!NILP (prop
)
23801 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23802 ascent
= min (max (0, (int)tem
), height
);
23804 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
23807 #endif /* HAVE_WINDOW_SYSTEM */
23810 if (width
> 0 && it
->line_wrap
!= TRUNCATE
23811 && it
->current_x
+ width
> it
->last_visible_x
)
23813 width
= it
->last_visible_x
- it
->current_x
;
23814 #ifdef HAVE_WINDOW_SYSTEM
23815 /* Subtract one more pixel from the stretch width, but only on
23816 GUI frames, since on a TTY each glyph is one "pixel" wide. */
23817 width
-= FRAME_WINDOW_P (it
->f
);
23821 if (width
> 0 && height
> 0 && it
->glyph_row
)
23823 Lisp_Object o_object
= it
->object
;
23824 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
23827 if (!STRINGP (object
))
23828 object
= it
->w
->buffer
;
23829 #ifdef HAVE_WINDOW_SYSTEM
23830 if (FRAME_WINDOW_P (it
->f
))
23831 append_stretch_glyph (it
, object
, width
, height
, ascent
);
23835 it
->object
= object
;
23836 it
->char_to_display
= ' ';
23837 it
->pixel_width
= it
->len
= 1;
23839 tty_append_glyph (it
);
23840 it
->object
= o_object
;
23844 it
->pixel_width
= width
;
23845 #ifdef HAVE_WINDOW_SYSTEM
23846 if (FRAME_WINDOW_P (it
->f
))
23848 it
->ascent
= it
->phys_ascent
= ascent
;
23849 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
23850 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
23851 take_vertical_position_into_account (it
);
23855 it
->nglyphs
= width
;
23858 #ifdef HAVE_WINDOW_SYSTEM
23860 /* Calculate line-height and line-spacing properties.
23861 An integer value specifies explicit pixel value.
23862 A float value specifies relative value to current face height.
23863 A cons (float . face-name) specifies relative value to
23864 height of specified face font.
23866 Returns height in pixels, or nil. */
23870 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
23871 int boff
, int override
)
23873 Lisp_Object face_name
= Qnil
;
23874 int ascent
, descent
, height
;
23876 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
23881 face_name
= XCAR (val
);
23883 if (!NUMBERP (val
))
23884 val
= make_number (1);
23885 if (NILP (face_name
))
23887 height
= it
->ascent
+ it
->descent
;
23892 if (NILP (face_name
))
23894 font
= FRAME_FONT (it
->f
);
23895 boff
= FRAME_BASELINE_OFFSET (it
->f
);
23897 else if (EQ (face_name
, Qt
))
23906 face_id
= lookup_named_face (it
->f
, face_name
, 0);
23908 return make_number (-1);
23910 face
= FACE_FROM_ID (it
->f
, face_id
);
23913 return make_number (-1);
23914 boff
= font
->baseline_offset
;
23915 if (font
->vertical_centering
)
23916 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23919 ascent
= FONT_BASE (font
) + boff
;
23920 descent
= FONT_DESCENT (font
) - boff
;
23924 it
->override_ascent
= ascent
;
23925 it
->override_descent
= descent
;
23926 it
->override_boff
= boff
;
23929 height
= ascent
+ descent
;
23933 height
= (int)(XFLOAT_DATA (val
) * height
);
23934 else if (INTEGERP (val
))
23935 height
*= XINT (val
);
23937 return make_number (height
);
23941 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
23942 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
23943 and only if this is for a character for which no font was found.
23945 If the display method (it->glyphless_method) is
23946 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
23947 length of the acronym or the hexadecimal string, UPPER_XOFF and
23948 UPPER_YOFF are pixel offsets for the upper part of the string,
23949 LOWER_XOFF and LOWER_YOFF are for the lower part.
23951 For the other display methods, LEN through LOWER_YOFF are zero. */
23954 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
23955 short upper_xoff
, short upper_yoff
,
23956 short lower_xoff
, short lower_yoff
)
23958 struct glyph
*glyph
;
23959 enum glyph_row_area area
= it
->area
;
23961 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23962 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23964 /* If the glyph row is reversed, we need to prepend the glyph
23965 rather than append it. */
23966 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23970 /* Make room for the additional glyph. */
23971 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23973 glyph
= it
->glyph_row
->glyphs
[area
];
23975 glyph
->charpos
= CHARPOS (it
->position
);
23976 glyph
->object
= it
->object
;
23977 glyph
->pixel_width
= it
->pixel_width
;
23978 glyph
->ascent
= it
->ascent
;
23979 glyph
->descent
= it
->descent
;
23980 glyph
->voffset
= it
->voffset
;
23981 glyph
->type
= GLYPHLESS_GLYPH
;
23982 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
23983 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
23984 glyph
->u
.glyphless
.len
= len
;
23985 glyph
->u
.glyphless
.ch
= it
->c
;
23986 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
23987 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
23988 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
23989 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
23990 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23991 glyph
->multibyte_p
= it
->multibyte_p
;
23992 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23993 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23994 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23995 || it
->phys_descent
> it
->descent
);
23996 glyph
->padding_p
= 0;
23997 glyph
->glyph_not_available_p
= 0;
23998 glyph
->face_id
= face_id
;
23999 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24002 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24003 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24005 glyph
->bidi_type
= it
->bidi_it
.type
;
24007 ++it
->glyph_row
->used
[area
];
24010 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24014 /* Produce a glyph for a glyphless character for iterator IT.
24015 IT->glyphless_method specifies which method to use for displaying
24016 the character. See the description of enum
24017 glyphless_display_method in dispextern.h for the detail.
24019 FOR_NO_FONT is nonzero if and only if this is for a character for
24020 which no font was found. ACRONYM, if non-nil, is an acronym string
24021 for the character. */
24024 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24029 int base_width
, base_height
, width
, height
;
24030 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24033 /* Get the metrics of the base font. We always refer to the current
24035 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24036 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24037 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24038 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24039 base_height
= it
->ascent
+ it
->descent
;
24040 base_width
= font
->average_width
;
24042 /* Get a face ID for the glyph by utilizing a cache (the same way as
24043 done for `escape-glyph' in get_next_display_element). */
24044 if (it
->f
== last_glyphless_glyph_frame
24045 && it
->face_id
== last_glyphless_glyph_face_id
)
24047 face_id
= last_glyphless_glyph_merged_face_id
;
24051 /* Merge the `glyphless-char' face into the current face. */
24052 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24053 last_glyphless_glyph_frame
= it
->f
;
24054 last_glyphless_glyph_face_id
= it
->face_id
;
24055 last_glyphless_glyph_merged_face_id
= face_id
;
24058 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24060 it
->pixel_width
= THIN_SPACE_WIDTH
;
24062 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24064 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24066 width
= CHAR_WIDTH (it
->c
);
24069 else if (width
> 4)
24071 it
->pixel_width
= base_width
* width
;
24073 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24079 unsigned int code
[6];
24081 int ascent
, descent
;
24082 struct font_metrics metrics_upper
, metrics_lower
;
24084 face
= FACE_FROM_ID (it
->f
, face_id
);
24085 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24086 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24088 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24090 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24091 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24092 if (CONSP (acronym
))
24093 acronym
= XCAR (acronym
);
24094 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24098 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24099 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24102 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24103 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24104 upper_len
= (len
+ 1) / 2;
24105 font
->driver
->text_extents (font
, code
, upper_len
,
24107 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24112 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24113 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24114 upper_xoff
= upper_yoff
= 2; /* the typical case */
24115 if (base_width
>= width
)
24117 /* Align the upper to the left, the lower to the right. */
24118 it
->pixel_width
= base_width
;
24119 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24123 /* Center the shorter one. */
24124 it
->pixel_width
= width
;
24125 if (metrics_upper
.width
>= metrics_lower
.width
)
24126 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24129 /* FIXME: This code doesn't look right. It formerly was
24130 missing the "lower_xoff = 0;", which couldn't have
24131 been right since it left lower_xoff uninitialized. */
24133 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24137 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24138 top, bottom, and between upper and lower strings. */
24139 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24140 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24141 /* Center vertically.
24142 H:base_height, D:base_descent
24143 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24145 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24146 descent = D - H/2 + h/2;
24147 lower_yoff = descent - 2 - ld;
24148 upper_yoff = lower_yoff - la - 1 - ud; */
24149 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24150 descent
= it
->descent
- (base_height
- height
) / 2;
24151 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24152 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24153 - metrics_upper
.descent
);
24154 /* Don't make the height shorter than the base height. */
24155 if (height
> base_height
)
24157 it
->ascent
= ascent
;
24158 it
->descent
= descent
;
24162 it
->phys_ascent
= it
->ascent
;
24163 it
->phys_descent
= it
->descent
;
24165 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24166 upper_xoff
, upper_yoff
,
24167 lower_xoff
, lower_yoff
);
24169 take_vertical_position_into_account (it
);
24174 Produce glyphs/get display metrics for the display element IT is
24175 loaded with. See the description of struct it in dispextern.h
24176 for an overview of struct it. */
24179 x_produce_glyphs (struct it
*it
)
24181 int extra_line_spacing
= it
->extra_line_spacing
;
24183 it
->glyph_not_available_p
= 0;
24185 if (it
->what
== IT_CHARACTER
)
24188 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24189 struct font
*font
= face
->font
;
24190 struct font_metrics
*pcm
= NULL
;
24191 int boff
; /* baseline offset */
24195 /* When no suitable font is found, display this character by
24196 the method specified in the first extra slot of
24197 Vglyphless_char_display. */
24198 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24200 xassert (it
->what
== IT_GLYPHLESS
);
24201 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24205 boff
= font
->baseline_offset
;
24206 if (font
->vertical_centering
)
24207 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24209 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24215 if (it
->override_ascent
>= 0)
24217 it
->ascent
= it
->override_ascent
;
24218 it
->descent
= it
->override_descent
;
24219 boff
= it
->override_boff
;
24223 it
->ascent
= FONT_BASE (font
) + boff
;
24224 it
->descent
= FONT_DESCENT (font
) - boff
;
24227 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24229 pcm
= get_per_char_metric (font
, &char2b
);
24230 if (pcm
->width
== 0
24231 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24237 it
->phys_ascent
= pcm
->ascent
+ boff
;
24238 it
->phys_descent
= pcm
->descent
- boff
;
24239 it
->pixel_width
= pcm
->width
;
24243 it
->glyph_not_available_p
= 1;
24244 it
->phys_ascent
= it
->ascent
;
24245 it
->phys_descent
= it
->descent
;
24246 it
->pixel_width
= font
->space_width
;
24249 if (it
->constrain_row_ascent_descent_p
)
24251 if (it
->descent
> it
->max_descent
)
24253 it
->ascent
+= it
->descent
- it
->max_descent
;
24254 it
->descent
= it
->max_descent
;
24256 if (it
->ascent
> it
->max_ascent
)
24258 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24259 it
->ascent
= it
->max_ascent
;
24261 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24262 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24263 extra_line_spacing
= 0;
24266 /* If this is a space inside a region of text with
24267 `space-width' property, change its width. */
24268 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24270 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24272 /* If face has a box, add the box thickness to the character
24273 height. If character has a box line to the left and/or
24274 right, add the box line width to the character's width. */
24275 if (face
->box
!= FACE_NO_BOX
)
24277 int thick
= face
->box_line_width
;
24281 it
->ascent
+= thick
;
24282 it
->descent
+= thick
;
24287 if (it
->start_of_box_run_p
)
24288 it
->pixel_width
+= thick
;
24289 if (it
->end_of_box_run_p
)
24290 it
->pixel_width
+= thick
;
24293 /* If face has an overline, add the height of the overline
24294 (1 pixel) and a 1 pixel margin to the character height. */
24295 if (face
->overline_p
)
24296 it
->ascent
+= overline_margin
;
24298 if (it
->constrain_row_ascent_descent_p
)
24300 if (it
->ascent
> it
->max_ascent
)
24301 it
->ascent
= it
->max_ascent
;
24302 if (it
->descent
> it
->max_descent
)
24303 it
->descent
= it
->max_descent
;
24306 take_vertical_position_into_account (it
);
24308 /* If we have to actually produce glyphs, do it. */
24313 /* Translate a space with a `space-width' property
24314 into a stretch glyph. */
24315 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24316 / FONT_HEIGHT (font
));
24317 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24318 it
->ascent
+ it
->descent
, ascent
);
24323 /* If characters with lbearing or rbearing are displayed
24324 in this line, record that fact in a flag of the
24325 glyph row. This is used to optimize X output code. */
24326 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24327 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24329 if (! stretched_p
&& it
->pixel_width
== 0)
24330 /* We assure that all visible glyphs have at least 1-pixel
24332 it
->pixel_width
= 1;
24334 else if (it
->char_to_display
== '\n')
24336 /* A newline has no width, but we need the height of the
24337 line. But if previous part of the line sets a height,
24338 don't increase that height */
24340 Lisp_Object height
;
24341 Lisp_Object total_height
= Qnil
;
24343 it
->override_ascent
= -1;
24344 it
->pixel_width
= 0;
24347 height
= get_it_property (it
, Qline_height
);
24348 /* Split (line-height total-height) list */
24350 && CONSP (XCDR (height
))
24351 && NILP (XCDR (XCDR (height
))))
24353 total_height
= XCAR (XCDR (height
));
24354 height
= XCAR (height
);
24356 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24358 if (it
->override_ascent
>= 0)
24360 it
->ascent
= it
->override_ascent
;
24361 it
->descent
= it
->override_descent
;
24362 boff
= it
->override_boff
;
24366 it
->ascent
= FONT_BASE (font
) + boff
;
24367 it
->descent
= FONT_DESCENT (font
) - boff
;
24370 if (EQ (height
, Qt
))
24372 if (it
->descent
> it
->max_descent
)
24374 it
->ascent
+= it
->descent
- it
->max_descent
;
24375 it
->descent
= it
->max_descent
;
24377 if (it
->ascent
> it
->max_ascent
)
24379 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24380 it
->ascent
= it
->max_ascent
;
24382 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24383 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24384 it
->constrain_row_ascent_descent_p
= 1;
24385 extra_line_spacing
= 0;
24389 Lisp_Object spacing
;
24391 it
->phys_ascent
= it
->ascent
;
24392 it
->phys_descent
= it
->descent
;
24394 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24395 && face
->box
!= FACE_NO_BOX
24396 && face
->box_line_width
> 0)
24398 it
->ascent
+= face
->box_line_width
;
24399 it
->descent
+= face
->box_line_width
;
24402 && XINT (height
) > it
->ascent
+ it
->descent
)
24403 it
->ascent
= XINT (height
) - it
->descent
;
24405 if (!NILP (total_height
))
24406 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24409 spacing
= get_it_property (it
, Qline_spacing
);
24410 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24412 if (INTEGERP (spacing
))
24414 extra_line_spacing
= XINT (spacing
);
24415 if (!NILP (total_height
))
24416 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24420 else /* i.e. (it->char_to_display == '\t') */
24422 if (font
->space_width
> 0)
24424 int tab_width
= it
->tab_width
* font
->space_width
;
24425 int x
= it
->current_x
+ it
->continuation_lines_width
;
24426 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24428 /* If the distance from the current position to the next tab
24429 stop is less than a space character width, use the
24430 tab stop after that. */
24431 if (next_tab_x
- x
< font
->space_width
)
24432 next_tab_x
+= tab_width
;
24434 it
->pixel_width
= next_tab_x
- x
;
24436 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24437 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24441 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24442 it
->ascent
+ it
->descent
, it
->ascent
);
24447 it
->pixel_width
= 0;
24452 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24454 /* A static composition.
24456 Note: A composition is represented as one glyph in the
24457 glyph matrix. There are no padding glyphs.
24459 Important note: pixel_width, ascent, and descent are the
24460 values of what is drawn by draw_glyphs (i.e. the values of
24461 the overall glyphs composed). */
24462 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24463 int boff
; /* baseline offset */
24464 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24465 int glyph_len
= cmp
->glyph_len
;
24466 struct font
*font
= face
->font
;
24470 /* If we have not yet calculated pixel size data of glyphs of
24471 the composition for the current face font, calculate them
24472 now. Theoretically, we have to check all fonts for the
24473 glyphs, but that requires much time and memory space. So,
24474 here we check only the font of the first glyph. This may
24475 lead to incorrect display, but it's very rare, and C-l
24476 (recenter-top-bottom) can correct the display anyway. */
24477 if (! cmp
->font
|| cmp
->font
!= font
)
24479 /* Ascent and descent of the font of the first character
24480 of this composition (adjusted by baseline offset).
24481 Ascent and descent of overall glyphs should not be less
24482 than these, respectively. */
24483 int font_ascent
, font_descent
, font_height
;
24484 /* Bounding box of the overall glyphs. */
24485 int leftmost
, rightmost
, lowest
, highest
;
24486 int lbearing
, rbearing
;
24487 int i
, width
, ascent
, descent
;
24488 int left_padded
= 0, right_padded
= 0;
24489 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24491 struct font_metrics
*pcm
;
24492 int font_not_found_p
;
24495 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24496 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24498 if (glyph_len
< cmp
->glyph_len
)
24500 for (i
= 0; i
< glyph_len
; i
++)
24502 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24504 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24509 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24510 : IT_CHARPOS (*it
));
24511 /* If no suitable font is found, use the default font. */
24512 font_not_found_p
= font
== NULL
;
24513 if (font_not_found_p
)
24515 face
= face
->ascii_face
;
24518 boff
= font
->baseline_offset
;
24519 if (font
->vertical_centering
)
24520 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24521 font_ascent
= FONT_BASE (font
) + boff
;
24522 font_descent
= FONT_DESCENT (font
) - boff
;
24523 font_height
= FONT_HEIGHT (font
);
24525 cmp
->font
= (void *) font
;
24528 if (! font_not_found_p
)
24530 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24532 pcm
= get_per_char_metric (font
, &char2b
);
24535 /* Initialize the bounding box. */
24538 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24539 ascent
= pcm
->ascent
;
24540 descent
= pcm
->descent
;
24541 lbearing
= pcm
->lbearing
;
24542 rbearing
= pcm
->rbearing
;
24546 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24547 ascent
= FONT_BASE (font
);
24548 descent
= FONT_DESCENT (font
);
24555 lowest
= - descent
+ boff
;
24556 highest
= ascent
+ boff
;
24558 if (! font_not_found_p
24559 && font
->default_ascent
24560 && CHAR_TABLE_P (Vuse_default_ascent
)
24561 && !NILP (Faref (Vuse_default_ascent
,
24562 make_number (it
->char_to_display
))))
24563 highest
= font
->default_ascent
+ boff
;
24565 /* Draw the first glyph at the normal position. It may be
24566 shifted to right later if some other glyphs are drawn
24568 cmp
->offsets
[i
* 2] = 0;
24569 cmp
->offsets
[i
* 2 + 1] = boff
;
24570 cmp
->lbearing
= lbearing
;
24571 cmp
->rbearing
= rbearing
;
24573 /* Set cmp->offsets for the remaining glyphs. */
24574 for (i
++; i
< glyph_len
; i
++)
24576 int left
, right
, btm
, top
;
24577 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24579 struct face
*this_face
;
24583 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24584 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24585 font
= this_face
->font
;
24591 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24593 pcm
= get_per_char_metric (font
, &char2b
);
24596 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24599 width
= pcm
->width
;
24600 ascent
= pcm
->ascent
;
24601 descent
= pcm
->descent
;
24602 lbearing
= pcm
->lbearing
;
24603 rbearing
= pcm
->rbearing
;
24604 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24606 /* Relative composition with or without
24607 alternate chars. */
24608 left
= (leftmost
+ rightmost
- width
) / 2;
24609 btm
= - descent
+ boff
;
24610 if (font
->relative_compose
24611 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24612 || NILP (Faref (Vignore_relative_composition
,
24613 make_number (ch
)))))
24616 if (- descent
>= font
->relative_compose
)
24617 /* One extra pixel between two glyphs. */
24619 else if (ascent
<= 0)
24620 /* One extra pixel between two glyphs. */
24621 btm
= lowest
- 1 - ascent
- descent
;
24626 /* A composition rule is specified by an integer
24627 value that encodes global and new reference
24628 points (GREF and NREF). GREF and NREF are
24629 specified by numbers as below:
24631 0---1---2 -- ascent
24635 9--10--11 -- center
24637 ---3---4---5--- baseline
24639 6---7---8 -- descent
24641 int rule
= COMPOSITION_RULE (cmp
, i
);
24642 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24644 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24645 grefx
= gref
% 3, nrefx
= nref
% 3;
24646 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24648 xoff
= font_height
* (xoff
- 128) / 256;
24650 yoff
= font_height
* (yoff
- 128) / 256;
24653 + grefx
* (rightmost
- leftmost
) / 2
24654 - nrefx
* width
/ 2
24657 btm
= ((grefy
== 0 ? highest
24659 : grefy
== 2 ? lowest
24660 : (highest
+ lowest
) / 2)
24661 - (nrefy
== 0 ? ascent
+ descent
24662 : nrefy
== 1 ? descent
- boff
24664 : (ascent
+ descent
) / 2)
24668 cmp
->offsets
[i
* 2] = left
;
24669 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24671 /* Update the bounding box of the overall glyphs. */
24674 right
= left
+ width
;
24675 if (left
< leftmost
)
24677 if (right
> rightmost
)
24680 top
= btm
+ descent
+ ascent
;
24686 if (cmp
->lbearing
> left
+ lbearing
)
24687 cmp
->lbearing
= left
+ lbearing
;
24688 if (cmp
->rbearing
< left
+ rbearing
)
24689 cmp
->rbearing
= left
+ rbearing
;
24693 /* If there are glyphs whose x-offsets are negative,
24694 shift all glyphs to the right and make all x-offsets
24698 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24699 cmp
->offsets
[i
* 2] -= leftmost
;
24700 rightmost
-= leftmost
;
24701 cmp
->lbearing
-= leftmost
;
24702 cmp
->rbearing
-= leftmost
;
24705 if (left_padded
&& cmp
->lbearing
< 0)
24707 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24708 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24709 rightmost
-= cmp
->lbearing
;
24710 cmp
->rbearing
-= cmp
->lbearing
;
24713 if (right_padded
&& rightmost
< cmp
->rbearing
)
24715 rightmost
= cmp
->rbearing
;
24718 cmp
->pixel_width
= rightmost
;
24719 cmp
->ascent
= highest
;
24720 cmp
->descent
= - lowest
;
24721 if (cmp
->ascent
< font_ascent
)
24722 cmp
->ascent
= font_ascent
;
24723 if (cmp
->descent
< font_descent
)
24724 cmp
->descent
= font_descent
;
24728 && (cmp
->lbearing
< 0
24729 || cmp
->rbearing
> cmp
->pixel_width
))
24730 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24732 it
->pixel_width
= cmp
->pixel_width
;
24733 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24734 it
->descent
= it
->phys_descent
= cmp
->descent
;
24735 if (face
->box
!= FACE_NO_BOX
)
24737 int thick
= face
->box_line_width
;
24741 it
->ascent
+= thick
;
24742 it
->descent
+= thick
;
24747 if (it
->start_of_box_run_p
)
24748 it
->pixel_width
+= thick
;
24749 if (it
->end_of_box_run_p
)
24750 it
->pixel_width
+= thick
;
24753 /* If face has an overline, add the height of the overline
24754 (1 pixel) and a 1 pixel margin to the character height. */
24755 if (face
->overline_p
)
24756 it
->ascent
+= overline_margin
;
24758 take_vertical_position_into_account (it
);
24759 if (it
->ascent
< 0)
24761 if (it
->descent
< 0)
24764 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24765 append_composite_glyph (it
);
24767 else if (it
->what
== IT_COMPOSITION
)
24769 /* A dynamic (automatic) composition. */
24770 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24771 Lisp_Object gstring
;
24772 struct font_metrics metrics
;
24776 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24778 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24781 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24782 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24783 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24784 it
->descent
= it
->phys_descent
= metrics
.descent
;
24785 if (face
->box
!= FACE_NO_BOX
)
24787 int thick
= face
->box_line_width
;
24791 it
->ascent
+= thick
;
24792 it
->descent
+= thick
;
24797 if (it
->start_of_box_run_p
)
24798 it
->pixel_width
+= thick
;
24799 if (it
->end_of_box_run_p
)
24800 it
->pixel_width
+= thick
;
24802 /* If face has an overline, add the height of the overline
24803 (1 pixel) and a 1 pixel margin to the character height. */
24804 if (face
->overline_p
)
24805 it
->ascent
+= overline_margin
;
24806 take_vertical_position_into_account (it
);
24807 if (it
->ascent
< 0)
24809 if (it
->descent
< 0)
24813 append_composite_glyph (it
);
24815 else if (it
->what
== IT_GLYPHLESS
)
24816 produce_glyphless_glyph (it
, 0, Qnil
);
24817 else if (it
->what
== IT_IMAGE
)
24818 produce_image_glyph (it
);
24819 else if (it
->what
== IT_STRETCH
)
24820 produce_stretch_glyph (it
);
24823 /* Accumulate dimensions. Note: can't assume that it->descent > 0
24824 because this isn't true for images with `:ascent 100'. */
24825 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
24826 if (it
->area
== TEXT_AREA
)
24827 it
->current_x
+= it
->pixel_width
;
24829 if (extra_line_spacing
> 0)
24831 it
->descent
+= extra_line_spacing
;
24832 if (extra_line_spacing
> it
->max_extra_line_spacing
)
24833 it
->max_extra_line_spacing
= extra_line_spacing
;
24836 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
24837 it
->max_descent
= max (it
->max_descent
, it
->descent
);
24838 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
24839 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
24843 Output LEN glyphs starting at START at the nominal cursor position.
24844 Advance the nominal cursor over the text. The global variable
24845 updated_window contains the window being updated, updated_row is
24846 the glyph row being updated, and updated_area is the area of that
24847 row being updated. */
24850 x_write_glyphs (struct glyph
*start
, int len
)
24852 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
24854 xassert (updated_window
&& updated_row
);
24855 /* When the window is hscrolled, cursor hpos can legitimately be out
24856 of bounds, but we draw the cursor at the corresponding window
24857 margin in that case. */
24858 if (!updated_row
->reversed_p
&& chpos
< 0)
24860 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
24861 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
24865 /* Write glyphs. */
24867 hpos
= start
- updated_row
->glyphs
[updated_area
];
24868 x
= draw_glyphs (updated_window
, output_cursor
.x
,
24869 updated_row
, updated_area
,
24871 DRAW_NORMAL_TEXT
, 0);
24873 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
24874 if (updated_area
== TEXT_AREA
24875 && updated_window
->phys_cursor_on_p
24876 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
24878 && chpos
< hpos
+ len
)
24879 updated_window
->phys_cursor_on_p
= 0;
24883 /* Advance the output cursor. */
24884 output_cursor
.hpos
+= len
;
24885 output_cursor
.x
= x
;
24890 Insert LEN glyphs from START at the nominal cursor position. */
24893 x_insert_glyphs (struct glyph
*start
, int len
)
24897 int line_height
, shift_by_width
, shifted_region_width
;
24898 struct glyph_row
*row
;
24899 struct glyph
*glyph
;
24900 int frame_x
, frame_y
;
24903 xassert (updated_window
&& updated_row
);
24905 w
= updated_window
;
24906 f
= XFRAME (WINDOW_FRAME (w
));
24908 /* Get the height of the line we are in. */
24910 line_height
= row
->height
;
24912 /* Get the width of the glyphs to insert. */
24913 shift_by_width
= 0;
24914 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
24915 shift_by_width
+= glyph
->pixel_width
;
24917 /* Get the width of the region to shift right. */
24918 shifted_region_width
= (window_box_width (w
, updated_area
)
24923 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
24924 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
24926 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
24927 line_height
, shift_by_width
);
24929 /* Write the glyphs. */
24930 hpos
= start
- row
->glyphs
[updated_area
];
24931 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
24933 DRAW_NORMAL_TEXT
, 0);
24935 /* Advance the output cursor. */
24936 output_cursor
.hpos
+= len
;
24937 output_cursor
.x
+= shift_by_width
;
24943 Erase the current text line from the nominal cursor position
24944 (inclusive) to pixel column TO_X (exclusive). The idea is that
24945 everything from TO_X onward is already erased.
24947 TO_X is a pixel position relative to updated_area of
24948 updated_window. TO_X == -1 means clear to the end of this area. */
24951 x_clear_end_of_line (int to_x
)
24954 struct window
*w
= updated_window
;
24955 int max_x
, min_y
, max_y
;
24956 int from_x
, from_y
, to_y
;
24958 xassert (updated_window
&& updated_row
);
24959 f
= XFRAME (w
->frame
);
24961 if (updated_row
->full_width_p
)
24962 max_x
= WINDOW_TOTAL_WIDTH (w
);
24964 max_x
= window_box_width (w
, updated_area
);
24965 max_y
= window_text_bottom_y (w
);
24967 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
24968 of window. For TO_X > 0, truncate to end of drawing area. */
24974 to_x
= min (to_x
, max_x
);
24976 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
24978 /* Notice if the cursor will be cleared by this operation. */
24979 if (!updated_row
->full_width_p
)
24980 notice_overwritten_cursor (w
, updated_area
,
24981 output_cursor
.x
, -1,
24983 MATRIX_ROW_BOTTOM_Y (updated_row
));
24985 from_x
= output_cursor
.x
;
24987 /* Translate to frame coordinates. */
24988 if (updated_row
->full_width_p
)
24990 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
24991 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
24995 int area_left
= window_box_left (w
, updated_area
);
24996 from_x
+= area_left
;
25000 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25001 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25002 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25004 /* Prevent inadvertently clearing to end of the X window. */
25005 if (to_x
> from_x
&& to_y
> from_y
)
25008 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25009 to_x
- from_x
, to_y
- from_y
);
25014 #endif /* HAVE_WINDOW_SYSTEM */
25018 /***********************************************************************
25020 ***********************************************************************/
25022 /* Value is the internal representation of the specified cursor type
25023 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25024 of the bar cursor. */
25026 static enum text_cursor_kinds
25027 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25029 enum text_cursor_kinds type
;
25034 if (EQ (arg
, Qbox
))
25035 return FILLED_BOX_CURSOR
;
25037 if (EQ (arg
, Qhollow
))
25038 return HOLLOW_BOX_CURSOR
;
25040 if (EQ (arg
, Qbar
))
25047 && EQ (XCAR (arg
), Qbar
)
25048 && INTEGERP (XCDR (arg
))
25049 && XINT (XCDR (arg
)) >= 0)
25051 *width
= XINT (XCDR (arg
));
25055 if (EQ (arg
, Qhbar
))
25058 return HBAR_CURSOR
;
25062 && EQ (XCAR (arg
), Qhbar
)
25063 && INTEGERP (XCDR (arg
))
25064 && XINT (XCDR (arg
)) >= 0)
25066 *width
= XINT (XCDR (arg
));
25067 return HBAR_CURSOR
;
25070 /* Treat anything unknown as "hollow box cursor".
25071 It was bad to signal an error; people have trouble fixing
25072 .Xdefaults with Emacs, when it has something bad in it. */
25073 type
= HOLLOW_BOX_CURSOR
;
25078 /* Set the default cursor types for specified frame. */
25080 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25085 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25086 FRAME_CURSOR_WIDTH (f
) = width
;
25088 /* By default, set up the blink-off state depending on the on-state. */
25090 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25093 FRAME_BLINK_OFF_CURSOR (f
)
25094 = get_specified_cursor_type (XCDR (tem
), &width
);
25095 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25098 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25102 #ifdef HAVE_WINDOW_SYSTEM
25104 /* Return the cursor we want to be displayed in window W. Return
25105 width of bar/hbar cursor through WIDTH arg. Return with
25106 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25107 (i.e. if the `system caret' should track this cursor).
25109 In a mini-buffer window, we want the cursor only to appear if we
25110 are reading input from this window. For the selected window, we
25111 want the cursor type given by the frame parameter or buffer local
25112 setting of cursor-type. If explicitly marked off, draw no cursor.
25113 In all other cases, we want a hollow box cursor. */
25115 static enum text_cursor_kinds
25116 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25117 int *active_cursor
)
25119 struct frame
*f
= XFRAME (w
->frame
);
25120 struct buffer
*b
= XBUFFER (w
->buffer
);
25121 int cursor_type
= DEFAULT_CURSOR
;
25122 Lisp_Object alt_cursor
;
25123 int non_selected
= 0;
25125 *active_cursor
= 1;
25128 if (cursor_in_echo_area
25129 && FRAME_HAS_MINIBUF_P (f
)
25130 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25132 if (w
== XWINDOW (echo_area_window
))
25134 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25136 *width
= FRAME_CURSOR_WIDTH (f
);
25137 return FRAME_DESIRED_CURSOR (f
);
25140 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25143 *active_cursor
= 0;
25147 /* Detect a nonselected window or nonselected frame. */
25148 else if (w
!= XWINDOW (f
->selected_window
)
25149 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25151 *active_cursor
= 0;
25153 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25159 /* Never display a cursor in a window in which cursor-type is nil. */
25160 if (NILP (BVAR (b
, cursor_type
)))
25163 /* Get the normal cursor type for this window. */
25164 if (EQ (BVAR (b
, cursor_type
), Qt
))
25166 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25167 *width
= FRAME_CURSOR_WIDTH (f
);
25170 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25172 /* Use cursor-in-non-selected-windows instead
25173 for non-selected window or frame. */
25176 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25177 if (!EQ (Qt
, alt_cursor
))
25178 return get_specified_cursor_type (alt_cursor
, width
);
25179 /* t means modify the normal cursor type. */
25180 if (cursor_type
== FILLED_BOX_CURSOR
)
25181 cursor_type
= HOLLOW_BOX_CURSOR
;
25182 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25184 return cursor_type
;
25187 /* Use normal cursor if not blinked off. */
25188 if (!w
->cursor_off_p
)
25190 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25192 if (cursor_type
== FILLED_BOX_CURSOR
)
25194 /* Using a block cursor on large images can be very annoying.
25195 So use a hollow cursor for "large" images.
25196 If image is not transparent (no mask), also use hollow cursor. */
25197 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25198 if (img
!= NULL
&& IMAGEP (img
->spec
))
25200 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25201 where N = size of default frame font size.
25202 This should cover most of the "tiny" icons people may use. */
25204 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25205 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25206 cursor_type
= HOLLOW_BOX_CURSOR
;
25209 else if (cursor_type
!= NO_CURSOR
)
25211 /* Display current only supports BOX and HOLLOW cursors for images.
25212 So for now, unconditionally use a HOLLOW cursor when cursor is
25213 not a solid box cursor. */
25214 cursor_type
= HOLLOW_BOX_CURSOR
;
25217 return cursor_type
;
25220 /* Cursor is blinked off, so determine how to "toggle" it. */
25222 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25223 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25224 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25226 /* Then see if frame has specified a specific blink off cursor type. */
25227 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25229 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25230 return FRAME_BLINK_OFF_CURSOR (f
);
25234 /* Some people liked having a permanently visible blinking cursor,
25235 while others had very strong opinions against it. So it was
25236 decided to remove it. KFS 2003-09-03 */
25238 /* Finally perform built-in cursor blinking:
25239 filled box <-> hollow box
25240 wide [h]bar <-> narrow [h]bar
25241 narrow [h]bar <-> no cursor
25242 other type <-> no cursor */
25244 if (cursor_type
== FILLED_BOX_CURSOR
)
25245 return HOLLOW_BOX_CURSOR
;
25247 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25250 return cursor_type
;
25258 /* Notice when the text cursor of window W has been completely
25259 overwritten by a drawing operation that outputs glyphs in AREA
25260 starting at X0 and ending at X1 in the line starting at Y0 and
25261 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25262 the rest of the line after X0 has been written. Y coordinates
25263 are window-relative. */
25266 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25267 int x0
, int x1
, int y0
, int y1
)
25269 int cx0
, cx1
, cy0
, cy1
;
25270 struct glyph_row
*row
;
25272 if (!w
->phys_cursor_on_p
)
25274 if (area
!= TEXT_AREA
)
25277 if (w
->phys_cursor
.vpos
< 0
25278 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25279 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25280 !(row
->enabled_p
&& row
->displays_text_p
)))
25283 if (row
->cursor_in_fringe_p
)
25285 row
->cursor_in_fringe_p
= 0;
25286 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25287 w
->phys_cursor_on_p
= 0;
25291 cx0
= w
->phys_cursor
.x
;
25292 cx1
= cx0
+ w
->phys_cursor_width
;
25293 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25296 /* The cursor image will be completely removed from the
25297 screen if the output area intersects the cursor area in
25298 y-direction. When we draw in [y0 y1[, and some part of
25299 the cursor is at y < y0, that part must have been drawn
25300 before. When scrolling, the cursor is erased before
25301 actually scrolling, so we don't come here. When not
25302 scrolling, the rows above the old cursor row must have
25303 changed, and in this case these rows must have written
25304 over the cursor image.
25306 Likewise if part of the cursor is below y1, with the
25307 exception of the cursor being in the first blank row at
25308 the buffer and window end because update_text_area
25309 doesn't draw that row. (Except when it does, but
25310 that's handled in update_text_area.) */
25312 cy0
= w
->phys_cursor
.y
;
25313 cy1
= cy0
+ w
->phys_cursor_height
;
25314 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25317 w
->phys_cursor_on_p
= 0;
25320 #endif /* HAVE_WINDOW_SYSTEM */
25323 /************************************************************************
25325 ************************************************************************/
25327 #ifdef HAVE_WINDOW_SYSTEM
25330 Fix the display of area AREA of overlapping row ROW in window W
25331 with respect to the overlapping part OVERLAPS. */
25334 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25335 enum glyph_row_area area
, int overlaps
)
25342 for (i
= 0; i
< row
->used
[area
];)
25344 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25346 int start
= i
, start_x
= x
;
25350 x
+= row
->glyphs
[area
][i
].pixel_width
;
25353 while (i
< row
->used
[area
]
25354 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25356 draw_glyphs (w
, start_x
, row
, area
,
25358 DRAW_NORMAL_TEXT
, overlaps
);
25362 x
+= row
->glyphs
[area
][i
].pixel_width
;
25372 Draw the cursor glyph of window W in glyph row ROW. See the
25373 comment of draw_glyphs for the meaning of HL. */
25376 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25377 enum draw_glyphs_face hl
)
25379 /* If cursor hpos is out of bounds, don't draw garbage. This can
25380 happen in mini-buffer windows when switching between echo area
25381 glyphs and mini-buffer. */
25382 if ((row
->reversed_p
25383 ? (w
->phys_cursor
.hpos
>= 0)
25384 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25386 int on_p
= w
->phys_cursor_on_p
;
25388 int hpos
= w
->phys_cursor
.hpos
;
25390 /* When the window is hscrolled, cursor hpos can legitimately be
25391 out of bounds, but we draw the cursor at the corresponding
25392 window margin in that case. */
25393 if (!row
->reversed_p
&& hpos
< 0)
25395 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25396 hpos
= row
->used
[TEXT_AREA
] - 1;
25398 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25400 w
->phys_cursor_on_p
= on_p
;
25402 if (hl
== DRAW_CURSOR
)
25403 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25404 /* When we erase the cursor, and ROW is overlapped by other
25405 rows, make sure that these overlapping parts of other rows
25407 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25409 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25411 if (row
> w
->current_matrix
->rows
25412 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25413 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25414 OVERLAPS_ERASED_CURSOR
);
25416 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25417 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25418 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25419 OVERLAPS_ERASED_CURSOR
);
25426 Erase the image of a cursor of window W from the screen. */
25429 erase_phys_cursor (struct window
*w
)
25431 struct frame
*f
= XFRAME (w
->frame
);
25432 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25433 int hpos
= w
->phys_cursor
.hpos
;
25434 int vpos
= w
->phys_cursor
.vpos
;
25435 int mouse_face_here_p
= 0;
25436 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25437 struct glyph_row
*cursor_row
;
25438 struct glyph
*cursor_glyph
;
25439 enum draw_glyphs_face hl
;
25441 /* No cursor displayed or row invalidated => nothing to do on the
25443 if (w
->phys_cursor_type
== NO_CURSOR
)
25444 goto mark_cursor_off
;
25446 /* VPOS >= active_glyphs->nrows means that window has been resized.
25447 Don't bother to erase the cursor. */
25448 if (vpos
>= active_glyphs
->nrows
)
25449 goto mark_cursor_off
;
25451 /* If row containing cursor is marked invalid, there is nothing we
25453 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25454 if (!cursor_row
->enabled_p
)
25455 goto mark_cursor_off
;
25457 /* If line spacing is > 0, old cursor may only be partially visible in
25458 window after split-window. So adjust visible height. */
25459 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25460 window_text_bottom_y (w
) - cursor_row
->y
);
25462 /* If row is completely invisible, don't attempt to delete a cursor which
25463 isn't there. This can happen if cursor is at top of a window, and
25464 we switch to a buffer with a header line in that window. */
25465 if (cursor_row
->visible_height
<= 0)
25466 goto mark_cursor_off
;
25468 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25469 if (cursor_row
->cursor_in_fringe_p
)
25471 cursor_row
->cursor_in_fringe_p
= 0;
25472 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25473 goto mark_cursor_off
;
25476 /* This can happen when the new row is shorter than the old one.
25477 In this case, either draw_glyphs or clear_end_of_line
25478 should have cleared the cursor. Note that we wouldn't be
25479 able to erase the cursor in this case because we don't have a
25480 cursor glyph at hand. */
25481 if ((cursor_row
->reversed_p
25482 ? (w
->phys_cursor
.hpos
< 0)
25483 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25484 goto mark_cursor_off
;
25486 /* When the window is hscrolled, cursor hpos can legitimately be out
25487 of bounds, but we draw the cursor at the corresponding window
25488 margin in that case. */
25489 if (!cursor_row
->reversed_p
&& hpos
< 0)
25491 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25492 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25494 /* If the cursor is in the mouse face area, redisplay that when
25495 we clear the cursor. */
25496 if (! NILP (hlinfo
->mouse_face_window
)
25497 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25498 /* Don't redraw the cursor's spot in mouse face if it is at the
25499 end of a line (on a newline). The cursor appears there, but
25500 mouse highlighting does not. */
25501 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25502 mouse_face_here_p
= 1;
25504 /* Maybe clear the display under the cursor. */
25505 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25508 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25511 cursor_glyph
= get_phys_cursor_glyph (w
);
25512 if (cursor_glyph
== NULL
)
25513 goto mark_cursor_off
;
25515 width
= cursor_glyph
->pixel_width
;
25516 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25517 x
= w
->phys_cursor
.x
;
25519 width
-= left_x
- x
;
25520 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25521 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25522 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25525 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25528 /* Erase the cursor by redrawing the character underneath it. */
25529 if (mouse_face_here_p
)
25530 hl
= DRAW_MOUSE_FACE
;
25532 hl
= DRAW_NORMAL_TEXT
;
25533 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25536 w
->phys_cursor_on_p
= 0;
25537 w
->phys_cursor_type
= NO_CURSOR
;
25542 Display or clear cursor of window W. If ON is zero, clear the
25543 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25544 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25547 display_and_set_cursor (struct window
*w
, int on
,
25548 int hpos
, int vpos
, int x
, int y
)
25550 struct frame
*f
= XFRAME (w
->frame
);
25551 int new_cursor_type
;
25552 int new_cursor_width
;
25554 struct glyph_row
*glyph_row
;
25555 struct glyph
*glyph
;
25557 /* This is pointless on invisible frames, and dangerous on garbaged
25558 windows and frames; in the latter case, the frame or window may
25559 be in the midst of changing its size, and x and y may be off the
25561 if (! FRAME_VISIBLE_P (f
)
25562 || FRAME_GARBAGED_P (f
)
25563 || vpos
>= w
->current_matrix
->nrows
25564 || hpos
>= w
->current_matrix
->matrix_w
)
25567 /* If cursor is off and we want it off, return quickly. */
25568 if (!on
&& !w
->phys_cursor_on_p
)
25571 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25572 /* If cursor row is not enabled, we don't really know where to
25573 display the cursor. */
25574 if (!glyph_row
->enabled_p
)
25576 w
->phys_cursor_on_p
= 0;
25581 if (!glyph_row
->exact_window_width_line_p
25582 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25583 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25585 xassert (interrupt_input_blocked
);
25587 /* Set new_cursor_type to the cursor we want to be displayed. */
25588 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25589 &new_cursor_width
, &active_cursor
);
25591 /* If cursor is currently being shown and we don't want it to be or
25592 it is in the wrong place, or the cursor type is not what we want,
25594 if (w
->phys_cursor_on_p
25596 || w
->phys_cursor
.x
!= x
25597 || w
->phys_cursor
.y
!= y
25598 || new_cursor_type
!= w
->phys_cursor_type
25599 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25600 && new_cursor_width
!= w
->phys_cursor_width
)))
25601 erase_phys_cursor (w
);
25603 /* Don't check phys_cursor_on_p here because that flag is only set
25604 to zero in some cases where we know that the cursor has been
25605 completely erased, to avoid the extra work of erasing the cursor
25606 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25607 still not be visible, or it has only been partly erased. */
25610 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25611 w
->phys_cursor_height
= glyph_row
->height
;
25613 /* Set phys_cursor_.* before x_draw_.* is called because some
25614 of them may need the information. */
25615 w
->phys_cursor
.x
= x
;
25616 w
->phys_cursor
.y
= glyph_row
->y
;
25617 w
->phys_cursor
.hpos
= hpos
;
25618 w
->phys_cursor
.vpos
= vpos
;
25621 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25622 new_cursor_type
, new_cursor_width
,
25623 on
, active_cursor
);
25627 /* Switch the display of W's cursor on or off, according to the value
25631 update_window_cursor (struct window
*w
, int on
)
25633 /* Don't update cursor in windows whose frame is in the process
25634 of being deleted. */
25635 if (w
->current_matrix
)
25637 int hpos
= w
->phys_cursor
.hpos
;
25638 int vpos
= w
->phys_cursor
.vpos
;
25639 struct glyph_row
*row
;
25641 if (vpos
>= w
->current_matrix
->nrows
25642 || hpos
>= w
->current_matrix
->matrix_w
)
25645 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25647 /* When the window is hscrolled, cursor hpos can legitimately be
25648 out of bounds, but we draw the cursor at the corresponding
25649 window margin in that case. */
25650 if (!row
->reversed_p
&& hpos
< 0)
25652 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25653 hpos
= row
->used
[TEXT_AREA
] - 1;
25656 display_and_set_cursor (w
, on
, hpos
, vpos
,
25657 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25663 /* Call update_window_cursor with parameter ON_P on all leaf windows
25664 in the window tree rooted at W. */
25667 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25671 if (!NILP (w
->hchild
))
25672 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25673 else if (!NILP (w
->vchild
))
25674 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25676 update_window_cursor (w
, on_p
);
25678 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25684 Display the cursor on window W, or clear it, according to ON_P.
25685 Don't change the cursor's position. */
25688 x_update_cursor (struct frame
*f
, int on_p
)
25690 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25695 Clear the cursor of window W to background color, and mark the
25696 cursor as not shown. This is used when the text where the cursor
25697 is about to be rewritten. */
25700 x_clear_cursor (struct window
*w
)
25702 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25703 update_window_cursor (w
, 0);
25706 #endif /* HAVE_WINDOW_SYSTEM */
25708 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25711 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25712 int start_hpos
, int end_hpos
,
25713 enum draw_glyphs_face draw
)
25715 #ifdef HAVE_WINDOW_SYSTEM
25716 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25718 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25722 #if defined (HAVE_GPM) || defined (MSDOS)
25723 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25727 /* Display the active region described by mouse_face_* according to DRAW. */
25730 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25732 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25733 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25735 if (/* If window is in the process of being destroyed, don't bother
25737 w
->current_matrix
!= NULL
25738 /* Don't update mouse highlight if hidden */
25739 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25740 /* Recognize when we are called to operate on rows that don't exist
25741 anymore. This can happen when a window is split. */
25742 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25744 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25745 struct glyph_row
*row
, *first
, *last
;
25747 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25748 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25750 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25752 int start_hpos
, end_hpos
, start_x
;
25754 /* For all but the first row, the highlight starts at column 0. */
25757 /* R2L rows have BEG and END in reversed order, but the
25758 screen drawing geometry is always left to right. So
25759 we need to mirror the beginning and end of the
25760 highlighted area in R2L rows. */
25761 if (!row
->reversed_p
)
25763 start_hpos
= hlinfo
->mouse_face_beg_col
;
25764 start_x
= hlinfo
->mouse_face_beg_x
;
25766 else if (row
== last
)
25768 start_hpos
= hlinfo
->mouse_face_end_col
;
25769 start_x
= hlinfo
->mouse_face_end_x
;
25777 else if (row
->reversed_p
&& row
== last
)
25779 start_hpos
= hlinfo
->mouse_face_end_col
;
25780 start_x
= hlinfo
->mouse_face_end_x
;
25790 if (!row
->reversed_p
)
25791 end_hpos
= hlinfo
->mouse_face_end_col
;
25792 else if (row
== first
)
25793 end_hpos
= hlinfo
->mouse_face_beg_col
;
25796 end_hpos
= row
->used
[TEXT_AREA
];
25797 if (draw
== DRAW_NORMAL_TEXT
)
25798 row
->fill_line_p
= 1; /* Clear to end of line */
25801 else if (row
->reversed_p
&& row
== first
)
25802 end_hpos
= hlinfo
->mouse_face_beg_col
;
25805 end_hpos
= row
->used
[TEXT_AREA
];
25806 if (draw
== DRAW_NORMAL_TEXT
)
25807 row
->fill_line_p
= 1; /* Clear to end of line */
25810 if (end_hpos
> start_hpos
)
25812 draw_row_with_mouse_face (w
, start_x
, row
,
25813 start_hpos
, end_hpos
, draw
);
25816 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
25820 #ifdef HAVE_WINDOW_SYSTEM
25821 /* When we've written over the cursor, arrange for it to
25822 be displayed again. */
25823 if (FRAME_WINDOW_P (f
)
25824 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
25826 int hpos
= w
->phys_cursor
.hpos
;
25828 /* When the window is hscrolled, cursor hpos can legitimately be
25829 out of bounds, but we draw the cursor at the corresponding
25830 window margin in that case. */
25831 if (!row
->reversed_p
&& hpos
< 0)
25833 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25834 hpos
= row
->used
[TEXT_AREA
] - 1;
25837 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
25838 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25841 #endif /* HAVE_WINDOW_SYSTEM */
25844 #ifdef HAVE_WINDOW_SYSTEM
25845 /* Change the mouse cursor. */
25846 if (FRAME_WINDOW_P (f
))
25848 if (draw
== DRAW_NORMAL_TEXT
25849 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
25850 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
25851 else if (draw
== DRAW_MOUSE_FACE
)
25852 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
25854 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
25856 #endif /* HAVE_WINDOW_SYSTEM */
25860 Clear out the mouse-highlighted active region.
25861 Redraw it un-highlighted first. Value is non-zero if mouse
25862 face was actually drawn unhighlighted. */
25865 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
25869 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
25871 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
25875 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25876 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25877 hlinfo
->mouse_face_window
= Qnil
;
25878 hlinfo
->mouse_face_overlay
= Qnil
;
25882 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
25883 within the mouse face on that window. */
25885 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
25887 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25889 /* Quickly resolve the easy cases. */
25890 if (!(WINDOWP (hlinfo
->mouse_face_window
)
25891 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
25893 if (vpos
< hlinfo
->mouse_face_beg_row
25894 || vpos
> hlinfo
->mouse_face_end_row
)
25896 if (vpos
> hlinfo
->mouse_face_beg_row
25897 && vpos
< hlinfo
->mouse_face_end_row
)
25900 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
25902 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25904 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
25907 else if ((vpos
== hlinfo
->mouse_face_beg_row
25908 && hpos
>= hlinfo
->mouse_face_beg_col
)
25909 || (vpos
== hlinfo
->mouse_face_end_row
25910 && hpos
< hlinfo
->mouse_face_end_col
))
25915 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25917 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
25920 else if ((vpos
== hlinfo
->mouse_face_beg_row
25921 && hpos
<= hlinfo
->mouse_face_beg_col
)
25922 || (vpos
== hlinfo
->mouse_face_end_row
25923 && hpos
> hlinfo
->mouse_face_end_col
))
25931 Non-zero if physical cursor of window W is within mouse face. */
25934 cursor_in_mouse_face_p (struct window
*w
)
25936 int hpos
= w
->phys_cursor
.hpos
;
25937 int vpos
= w
->phys_cursor
.vpos
;
25938 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25940 /* When the window is hscrolled, cursor hpos can legitimately be out
25941 of bounds, but we draw the cursor at the corresponding window
25942 margin in that case. */
25943 if (!row
->reversed_p
&& hpos
< 0)
25945 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25946 hpos
= row
->used
[TEXT_AREA
] - 1;
25948 return coords_in_mouse_face_p (w
, hpos
, vpos
);
25953 /* Find the glyph rows START_ROW and END_ROW of window W that display
25954 characters between buffer positions START_CHARPOS and END_CHARPOS
25955 (excluding END_CHARPOS). DISP_STRING is a display string that
25956 covers these buffer positions. This is similar to
25957 row_containing_pos, but is more accurate when bidi reordering makes
25958 buffer positions change non-linearly with glyph rows. */
25960 rows_from_pos_range (struct window
*w
,
25961 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
25962 Lisp_Object disp_string
,
25963 struct glyph_row
**start
, struct glyph_row
**end
)
25965 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25966 int last_y
= window_text_bottom_y (w
);
25967 struct glyph_row
*row
;
25972 while (!first
->enabled_p
25973 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
25976 /* Find the START row. */
25978 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
25981 /* A row can potentially be the START row if the range of the
25982 characters it displays intersects the range
25983 [START_CHARPOS..END_CHARPOS). */
25984 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
25985 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
25986 /* See the commentary in row_containing_pos, for the
25987 explanation of the complicated way to check whether
25988 some position is beyond the end of the characters
25989 displayed by a row. */
25990 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25991 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25992 && !row
->ends_at_zv_p
25993 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
25994 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
25995 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
25996 && !row
->ends_at_zv_p
25997 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
25999 /* Found a candidate row. Now make sure at least one of the
26000 glyphs it displays has a charpos from the range
26001 [START_CHARPOS..END_CHARPOS).
26003 This is not obvious because bidi reordering could make
26004 buffer positions of a row be 1,2,3,102,101,100, and if we
26005 want to highlight characters in [50..60), we don't want
26006 this row, even though [50..60) does intersect [1..103),
26007 the range of character positions given by the row's start
26008 and end positions. */
26009 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26010 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26014 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26015 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26016 /* A glyph that comes from DISP_STRING is by
26017 definition to be highlighted. */
26018 || EQ (g
->object
, disp_string
))
26027 /* Find the END row. */
26029 /* If the last row is partially visible, start looking for END
26030 from that row, instead of starting from FIRST. */
26031 && !(row
->enabled_p
26032 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26034 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26036 struct glyph_row
*next
= row
+ 1;
26037 EMACS_INT next_start
= MATRIX_ROW_START_CHARPOS (next
);
26039 if (!next
->enabled_p
26040 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26041 /* The first row >= START whose range of displayed characters
26042 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26043 is the row END + 1. */
26044 || (start_charpos
< next_start
26045 && end_charpos
< next_start
)
26046 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26047 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26048 && !next
->ends_at_zv_p
26049 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26050 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26051 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26052 && !next
->ends_at_zv_p
26053 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26060 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26061 but none of the characters it displays are in the range, it is
26063 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26064 struct glyph
*s
= g
;
26065 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26069 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26070 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26071 /* If the buffer position of the first glyph in
26072 the row is equal to END_CHARPOS, it means
26073 the last character to be highlighted is the
26074 newline of ROW, and we must consider NEXT as
26076 || (((!next
->reversed_p
&& g
== s
)
26077 || (next
->reversed_p
&& g
== e
- 1))
26078 && (g
->charpos
== end_charpos
26079 /* Special case for when NEXT is an
26080 empty line at ZV. */
26081 || (g
->charpos
== -1
26082 && !row
->ends_at_zv_p
26083 && next_start
== end_charpos
)))))
26084 /* A glyph that comes from DISP_STRING is by
26085 definition to be highlighted. */
26086 || EQ (g
->object
, disp_string
))
26095 /* The first row that ends at ZV must be the last to be
26097 else if (next
->ends_at_zv_p
)
26106 /* This function sets the mouse_face_* elements of HLINFO, assuming
26107 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26108 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26109 for the overlay or run of text properties specifying the mouse
26110 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26111 before-string and after-string that must also be highlighted.
26112 DISP_STRING, if non-nil, is a display string that may cover some
26113 or all of the highlighted text. */
26116 mouse_face_from_buffer_pos (Lisp_Object window
,
26117 Mouse_HLInfo
*hlinfo
,
26118 EMACS_INT mouse_charpos
,
26119 EMACS_INT start_charpos
,
26120 EMACS_INT end_charpos
,
26121 Lisp_Object before_string
,
26122 Lisp_Object after_string
,
26123 Lisp_Object disp_string
)
26125 struct window
*w
= XWINDOW (window
);
26126 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26127 struct glyph_row
*r1
, *r2
;
26128 struct glyph
*glyph
, *end
;
26129 EMACS_INT ignore
, pos
;
26132 xassert (NILP (disp_string
) || STRINGP (disp_string
));
26133 xassert (NILP (before_string
) || STRINGP (before_string
));
26134 xassert (NILP (after_string
) || STRINGP (after_string
));
26136 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26137 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26139 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26140 /* If the before-string or display-string contains newlines,
26141 rows_from_pos_range skips to its last row. Move back. */
26142 if (!NILP (before_string
) || !NILP (disp_string
))
26144 struct glyph_row
*prev
;
26145 while ((prev
= r1
- 1, prev
>= first
)
26146 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26147 && prev
->used
[TEXT_AREA
] > 0)
26149 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26150 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26151 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26153 || !(EQ (glyph
->object
, before_string
)
26154 || EQ (glyph
->object
, disp_string
)))
26161 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26162 hlinfo
->mouse_face_past_end
= 1;
26164 else if (!NILP (after_string
))
26166 /* If the after-string has newlines, advance to its last row. */
26167 struct glyph_row
*next
;
26168 struct glyph_row
*last
26169 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26171 for (next
= r2
+ 1;
26173 && next
->used
[TEXT_AREA
] > 0
26174 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26178 /* The rest of the display engine assumes that mouse_face_beg_row is
26179 either above mouse_face_end_row or identical to it. But with
26180 bidi-reordered continued lines, the row for START_CHARPOS could
26181 be below the row for END_CHARPOS. If so, swap the rows and store
26182 them in correct order. */
26185 struct glyph_row
*tem
= r2
;
26191 hlinfo
->mouse_face_beg_y
= r1
->y
;
26192 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26193 hlinfo
->mouse_face_end_y
= r2
->y
;
26194 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26196 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26197 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26198 could be anywhere in the row and in any order. The strategy
26199 below is to find the leftmost and the rightmost glyph that
26200 belongs to either of these 3 strings, or whose position is
26201 between START_CHARPOS and END_CHARPOS, and highlight all the
26202 glyphs between those two. This may cover more than just the text
26203 between START_CHARPOS and END_CHARPOS if the range of characters
26204 strides the bidi level boundary, e.g. if the beginning is in R2L
26205 text while the end is in L2R text or vice versa. */
26206 if (!r1
->reversed_p
)
26208 /* This row is in a left to right paragraph. Scan it left to
26210 glyph
= r1
->glyphs
[TEXT_AREA
];
26211 end
= glyph
+ r1
->used
[TEXT_AREA
];
26214 /* Skip truncation glyphs at the start of the glyph row. */
26215 if (r1
->displays_text_p
)
26217 && INTEGERP (glyph
->object
)
26218 && glyph
->charpos
< 0;
26220 x
+= glyph
->pixel_width
;
26222 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26223 or DISP_STRING, and the first glyph from buffer whose
26224 position is between START_CHARPOS and END_CHARPOS. */
26226 && !INTEGERP (glyph
->object
)
26227 && !EQ (glyph
->object
, disp_string
)
26228 && !(BUFFERP (glyph
->object
)
26229 && (glyph
->charpos
>= start_charpos
26230 && glyph
->charpos
< end_charpos
));
26233 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26234 are present at buffer positions between START_CHARPOS and
26235 END_CHARPOS, or if they come from an overlay. */
26236 if (EQ (glyph
->object
, before_string
))
26238 pos
= string_buffer_position (before_string
,
26240 /* If pos == 0, it means before_string came from an
26241 overlay, not from a buffer position. */
26242 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26245 else if (EQ (glyph
->object
, after_string
))
26247 pos
= string_buffer_position (after_string
, end_charpos
);
26248 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26251 x
+= glyph
->pixel_width
;
26253 hlinfo
->mouse_face_beg_x
= x
;
26254 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26258 /* This row is in a right to left paragraph. Scan it right to
26262 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26263 glyph
= end
+ r1
->used
[TEXT_AREA
];
26265 /* Skip truncation glyphs at the start of the glyph row. */
26266 if (r1
->displays_text_p
)
26268 && INTEGERP (glyph
->object
)
26269 && glyph
->charpos
< 0;
26273 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26274 or DISP_STRING, and the first glyph from buffer whose
26275 position is between START_CHARPOS and END_CHARPOS. */
26277 && !INTEGERP (glyph
->object
)
26278 && !EQ (glyph
->object
, disp_string
)
26279 && !(BUFFERP (glyph
->object
)
26280 && (glyph
->charpos
>= start_charpos
26281 && glyph
->charpos
< end_charpos
));
26284 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26285 are present at buffer positions between START_CHARPOS and
26286 END_CHARPOS, or if they come from an overlay. */
26287 if (EQ (glyph
->object
, before_string
))
26289 pos
= string_buffer_position (before_string
, start_charpos
);
26290 /* If pos == 0, it means before_string came from an
26291 overlay, not from a buffer position. */
26292 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26295 else if (EQ (glyph
->object
, after_string
))
26297 pos
= string_buffer_position (after_string
, end_charpos
);
26298 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26303 glyph
++; /* first glyph to the right of the highlighted area */
26304 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26305 x
+= g
->pixel_width
;
26306 hlinfo
->mouse_face_beg_x
= x
;
26307 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26310 /* If the highlight ends in a different row, compute GLYPH and END
26311 for the end row. Otherwise, reuse the values computed above for
26312 the row where the highlight begins. */
26315 if (!r2
->reversed_p
)
26317 glyph
= r2
->glyphs
[TEXT_AREA
];
26318 end
= glyph
+ r2
->used
[TEXT_AREA
];
26323 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26324 glyph
= end
+ r2
->used
[TEXT_AREA
];
26328 if (!r2
->reversed_p
)
26330 /* Skip truncation and continuation glyphs near the end of the
26331 row, and also blanks and stretch glyphs inserted by
26332 extend_face_to_end_of_line. */
26334 && INTEGERP ((end
- 1)->object
))
26336 /* Scan the rest of the glyph row from the end, looking for the
26337 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26338 DISP_STRING, or whose position is between START_CHARPOS
26342 && !INTEGERP (end
->object
)
26343 && !EQ (end
->object
, disp_string
)
26344 && !(BUFFERP (end
->object
)
26345 && (end
->charpos
>= start_charpos
26346 && end
->charpos
< end_charpos
));
26349 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26350 are present at buffer positions between START_CHARPOS and
26351 END_CHARPOS, or if they come from an overlay. */
26352 if (EQ (end
->object
, before_string
))
26354 pos
= string_buffer_position (before_string
, start_charpos
);
26355 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26358 else if (EQ (end
->object
, after_string
))
26360 pos
= string_buffer_position (after_string
, end_charpos
);
26361 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26365 /* Find the X coordinate of the last glyph to be highlighted. */
26366 for (; glyph
<= end
; ++glyph
)
26367 x
+= glyph
->pixel_width
;
26369 hlinfo
->mouse_face_end_x
= x
;
26370 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26374 /* Skip truncation and continuation glyphs near the end of the
26375 row, and also blanks and stretch glyphs inserted by
26376 extend_face_to_end_of_line. */
26380 && INTEGERP (end
->object
))
26382 x
+= end
->pixel_width
;
26385 /* Scan the rest of the glyph row from the end, looking for the
26386 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26387 DISP_STRING, or whose position is between START_CHARPOS
26391 && !INTEGERP (end
->object
)
26392 && !EQ (end
->object
, disp_string
)
26393 && !(BUFFERP (end
->object
)
26394 && (end
->charpos
>= start_charpos
26395 && end
->charpos
< end_charpos
));
26398 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26399 are present at buffer positions between START_CHARPOS and
26400 END_CHARPOS, or if they come from an overlay. */
26401 if (EQ (end
->object
, before_string
))
26403 pos
= string_buffer_position (before_string
, start_charpos
);
26404 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26407 else if (EQ (end
->object
, after_string
))
26409 pos
= string_buffer_position (after_string
, end_charpos
);
26410 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26413 x
+= end
->pixel_width
;
26415 /* If we exited the above loop because we arrived at the last
26416 glyph of the row, and its buffer position is still not in
26417 range, it means the last character in range is the preceding
26418 newline. Bump the end column and x values to get past the
26421 && BUFFERP (end
->object
)
26422 && (end
->charpos
< start_charpos
26423 || end
->charpos
>= end_charpos
))
26425 x
+= end
->pixel_width
;
26428 hlinfo
->mouse_face_end_x
= x
;
26429 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26432 hlinfo
->mouse_face_window
= window
;
26433 hlinfo
->mouse_face_face_id
26434 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26436 !hlinfo
->mouse_face_hidden
, -1);
26437 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26440 /* The following function is not used anymore (replaced with
26441 mouse_face_from_string_pos), but I leave it here for the time
26442 being, in case someone would. */
26444 #if 0 /* not used */
26446 /* Find the position of the glyph for position POS in OBJECT in
26447 window W's current matrix, and return in *X, *Y the pixel
26448 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26450 RIGHT_P non-zero means return the position of the right edge of the
26451 glyph, RIGHT_P zero means return the left edge position.
26453 If no glyph for POS exists in the matrix, return the position of
26454 the glyph with the next smaller position that is in the matrix, if
26455 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26456 exists in the matrix, return the position of the glyph with the
26457 next larger position in OBJECT.
26459 Value is non-zero if a glyph was found. */
26462 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
26463 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26465 int yb
= window_text_bottom_y (w
);
26466 struct glyph_row
*r
;
26467 struct glyph
*best_glyph
= NULL
;
26468 struct glyph_row
*best_row
= NULL
;
26471 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26472 r
->enabled_p
&& r
->y
< yb
;
26475 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26476 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26479 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26480 if (EQ (g
->object
, object
))
26482 if (g
->charpos
== pos
)
26489 else if (best_glyph
== NULL
26490 || ((eabs (g
->charpos
- pos
)
26491 < eabs (best_glyph
->charpos
- pos
))
26494 : g
->charpos
> pos
)))
26508 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26512 *x
+= best_glyph
->pixel_width
;
26517 *vpos
= best_row
- w
->current_matrix
->rows
;
26520 return best_glyph
!= NULL
;
26522 #endif /* not used */
26524 /* Find the positions of the first and the last glyphs in window W's
26525 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26526 (assumed to be a string), and return in HLINFO's mouse_face_*
26527 members the pixel and column/row coordinates of those glyphs. */
26530 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26531 Lisp_Object object
,
26532 EMACS_INT startpos
, EMACS_INT endpos
)
26534 int yb
= window_text_bottom_y (w
);
26535 struct glyph_row
*r
;
26536 struct glyph
*g
, *e
;
26540 /* Find the glyph row with at least one position in the range
26541 [STARTPOS..ENDPOS], and the first glyph in that row whose
26542 position belongs to that range. */
26543 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26544 r
->enabled_p
&& r
->y
< yb
;
26547 if (!r
->reversed_p
)
26549 g
= r
->glyphs
[TEXT_AREA
];
26550 e
= g
+ r
->used
[TEXT_AREA
];
26551 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26552 if (EQ (g
->object
, object
)
26553 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26555 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26556 hlinfo
->mouse_face_beg_y
= r
->y
;
26557 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26558 hlinfo
->mouse_face_beg_x
= gx
;
26567 e
= r
->glyphs
[TEXT_AREA
];
26568 g
= e
+ r
->used
[TEXT_AREA
];
26569 for ( ; g
> e
; --g
)
26570 if (EQ ((g
-1)->object
, object
)
26571 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26573 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26574 hlinfo
->mouse_face_beg_y
= r
->y
;
26575 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26576 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26577 gx
+= g1
->pixel_width
;
26578 hlinfo
->mouse_face_beg_x
= gx
;
26590 /* Starting with the next row, look for the first row which does NOT
26591 include any glyphs whose positions are in the range. */
26592 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26594 g
= r
->glyphs
[TEXT_AREA
];
26595 e
= g
+ r
->used
[TEXT_AREA
];
26597 for ( ; g
< e
; ++g
)
26598 if (EQ (g
->object
, object
)
26599 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26608 /* The highlighted region ends on the previous row. */
26611 /* Set the end row and its vertical pixel coordinate. */
26612 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26613 hlinfo
->mouse_face_end_y
= r
->y
;
26615 /* Compute and set the end column and the end column's horizontal
26616 pixel coordinate. */
26617 if (!r
->reversed_p
)
26619 g
= r
->glyphs
[TEXT_AREA
];
26620 e
= g
+ r
->used
[TEXT_AREA
];
26621 for ( ; e
> g
; --e
)
26622 if (EQ ((e
-1)->object
, object
)
26623 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26625 hlinfo
->mouse_face_end_col
= e
- g
;
26627 for (gx
= r
->x
; g
< e
; ++g
)
26628 gx
+= g
->pixel_width
;
26629 hlinfo
->mouse_face_end_x
= gx
;
26633 e
= r
->glyphs
[TEXT_AREA
];
26634 g
= e
+ r
->used
[TEXT_AREA
];
26635 for (gx
= r
->x
; e
< g
; ++e
)
26637 if (EQ (e
->object
, object
)
26638 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26640 gx
+= e
->pixel_width
;
26642 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26643 hlinfo
->mouse_face_end_x
= gx
;
26647 #ifdef HAVE_WINDOW_SYSTEM
26649 /* See if position X, Y is within a hot-spot of an image. */
26652 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26654 if (!CONSP (hot_spot
))
26657 if (EQ (XCAR (hot_spot
), Qrect
))
26659 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26660 Lisp_Object rect
= XCDR (hot_spot
);
26664 if (!CONSP (XCAR (rect
)))
26666 if (!CONSP (XCDR (rect
)))
26668 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26670 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26672 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26674 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26678 else if (EQ (XCAR (hot_spot
), Qcircle
))
26680 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26681 Lisp_Object circ
= XCDR (hot_spot
);
26682 Lisp_Object lr
, lx0
, ly0
;
26684 && CONSP (XCAR (circ
))
26685 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26686 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26687 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26689 double r
= XFLOATINT (lr
);
26690 double dx
= XINT (lx0
) - x
;
26691 double dy
= XINT (ly0
) - y
;
26692 return (dx
* dx
+ dy
* dy
<= r
* r
);
26695 else if (EQ (XCAR (hot_spot
), Qpoly
))
26697 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26698 if (VECTORP (XCDR (hot_spot
)))
26700 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26701 Lisp_Object
*poly
= v
->contents
;
26702 int n
= v
->header
.size
;
26705 Lisp_Object lx
, ly
;
26708 /* Need an even number of coordinates, and at least 3 edges. */
26709 if (n
< 6 || n
& 1)
26712 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26713 If count is odd, we are inside polygon. Pixels on edges
26714 may or may not be included depending on actual geometry of the
26716 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26717 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26719 x0
= XINT (lx
), y0
= XINT (ly
);
26720 for (i
= 0; i
< n
; i
+= 2)
26722 int x1
= x0
, y1
= y0
;
26723 if ((lx
= poly
[i
], !INTEGERP (lx
))
26724 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26726 x0
= XINT (lx
), y0
= XINT (ly
);
26728 /* Does this segment cross the X line? */
26736 if (y
> y0
&& y
> y1
)
26738 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26748 find_hot_spot (Lisp_Object map
, int x
, int y
)
26750 while (CONSP (map
))
26752 if (CONSP (XCAR (map
))
26753 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26761 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26763 doc
: /* Lookup in image map MAP coordinates X and Y.
26764 An image map is an alist where each element has the format (AREA ID PLIST).
26765 An AREA is specified as either a rectangle, a circle, or a polygon:
26766 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26767 pixel coordinates of the upper left and bottom right corners.
26768 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26769 and the radius of the circle; r may be a float or integer.
26770 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26771 vector describes one corner in the polygon.
26772 Returns the alist element for the first matching AREA in MAP. */)
26773 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26781 return find_hot_spot (map
, XINT (x
), XINT (y
));
26785 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26787 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26789 /* Do not change cursor shape while dragging mouse. */
26790 if (!NILP (do_mouse_tracking
))
26793 if (!NILP (pointer
))
26795 if (EQ (pointer
, Qarrow
))
26796 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26797 else if (EQ (pointer
, Qhand
))
26798 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
26799 else if (EQ (pointer
, Qtext
))
26800 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26801 else if (EQ (pointer
, intern ("hdrag")))
26802 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26803 #ifdef HAVE_X_WINDOWS
26804 else if (EQ (pointer
, intern ("vdrag")))
26805 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
26807 else if (EQ (pointer
, intern ("hourglass")))
26808 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
26809 else if (EQ (pointer
, Qmodeline
))
26810 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
26812 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26815 if (cursor
!= No_Cursor
)
26816 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
26819 #endif /* HAVE_WINDOW_SYSTEM */
26821 /* Take proper action when mouse has moved to the mode or header line
26822 or marginal area AREA of window W, x-position X and y-position Y.
26823 X is relative to the start of the text display area of W, so the
26824 width of bitmap areas and scroll bars must be subtracted to get a
26825 position relative to the start of the mode line. */
26828 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
26829 enum window_part area
)
26831 struct window
*w
= XWINDOW (window
);
26832 struct frame
*f
= XFRAME (w
->frame
);
26833 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26834 #ifdef HAVE_WINDOW_SYSTEM
26835 Display_Info
*dpyinfo
;
26837 Cursor cursor
= No_Cursor
;
26838 Lisp_Object pointer
= Qnil
;
26839 int dx
, dy
, width
, height
;
26841 Lisp_Object string
, object
= Qnil
;
26842 Lisp_Object pos
, help
;
26844 Lisp_Object mouse_face
;
26845 int original_x_pixel
= x
;
26846 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
26847 struct glyph_row
*row
;
26849 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
26854 /* Kludge alert: mode_line_string takes X/Y in pixels, but
26855 returns them in row/column units! */
26856 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
26857 &object
, &dx
, &dy
, &width
, &height
);
26859 row
= (area
== ON_MODE_LINE
26860 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
26861 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
26863 /* Find the glyph under the mouse pointer. */
26864 if (row
->mode_line_p
&& row
->enabled_p
)
26866 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
26867 end
= glyph
+ row
->used
[TEXT_AREA
];
26869 for (x0
= original_x_pixel
;
26870 glyph
< end
&& x0
>= glyph
->pixel_width
;
26872 x0
-= glyph
->pixel_width
;
26880 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
26881 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
26882 returns them in row/column units! */
26883 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
26884 &object
, &dx
, &dy
, &width
, &height
);
26889 #ifdef HAVE_WINDOW_SYSTEM
26890 if (IMAGEP (object
))
26892 Lisp_Object image_map
, hotspot
;
26893 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
26895 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
26897 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26901 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
26902 If so, we could look for mouse-enter, mouse-leave
26903 properties in PLIST (and do something...). */
26904 hotspot
= XCDR (hotspot
);
26905 if (CONSP (hotspot
)
26906 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26908 pointer
= Fplist_get (plist
, Qpointer
);
26909 if (NILP (pointer
))
26911 help
= Fplist_get (plist
, Qhelp_echo
);
26914 help_echo_string
= help
;
26915 /* Is this correct? ++kfs */
26916 XSETWINDOW (help_echo_window
, w
);
26917 help_echo_object
= w
->buffer
;
26918 help_echo_pos
= charpos
;
26922 if (NILP (pointer
))
26923 pointer
= Fplist_get (XCDR (object
), QCpointer
);
26925 #endif /* HAVE_WINDOW_SYSTEM */
26927 if (STRINGP (string
))
26929 pos
= make_number (charpos
);
26930 /* If we're on a string with `help-echo' text property, arrange
26931 for the help to be displayed. This is done by setting the
26932 global variable help_echo_string to the help string. */
26935 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
26938 help_echo_string
= help
;
26939 XSETWINDOW (help_echo_window
, w
);
26940 help_echo_object
= string
;
26941 help_echo_pos
= charpos
;
26945 #ifdef HAVE_WINDOW_SYSTEM
26946 if (FRAME_WINDOW_P (f
))
26948 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
26949 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26950 if (NILP (pointer
))
26951 pointer
= Fget_text_property (pos
, Qpointer
, string
);
26953 /* Change the mouse pointer according to what is under X/Y. */
26955 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
26958 map
= Fget_text_property (pos
, Qlocal_map
, string
);
26959 if (!KEYMAPP (map
))
26960 map
= Fget_text_property (pos
, Qkeymap
, string
);
26961 if (!KEYMAPP (map
))
26962 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
26967 /* Change the mouse face according to what is under X/Y. */
26968 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
26969 if (!NILP (mouse_face
)
26970 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26975 struct glyph
* tmp_glyph
;
26979 int total_pixel_width
;
26980 EMACS_INT begpos
, endpos
, ignore
;
26984 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
26985 Qmouse_face
, string
, Qnil
);
26991 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
26993 endpos
= SCHARS (string
);
26997 /* Calculate the glyph position GPOS of GLYPH in the
26998 displayed string, relative to the beginning of the
26999 highlighted part of the string.
27001 Note: GPOS is different from CHARPOS. CHARPOS is the
27002 position of GLYPH in the internal string object. A mode
27003 line string format has structures which are converted to
27004 a flattened string by the Emacs Lisp interpreter. The
27005 internal string is an element of those structures. The
27006 displayed string is the flattened string. */
27007 tmp_glyph
= row_start_glyph
;
27008 while (tmp_glyph
< glyph
27009 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27010 && begpos
<= tmp_glyph
->charpos
27011 && tmp_glyph
->charpos
< endpos
)))
27013 gpos
= glyph
- tmp_glyph
;
27015 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27016 the highlighted part of the displayed string to which
27017 GLYPH belongs. Note: GSEQ_LENGTH is different from
27018 SCHARS (STRING), because the latter returns the length of
27019 the internal string. */
27020 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27022 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27023 && begpos
<= tmp_glyph
->charpos
27024 && tmp_glyph
->charpos
< endpos
));
27027 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27029 /* Calculate the total pixel width of all the glyphs between
27030 the beginning of the highlighted area and GLYPH. */
27031 total_pixel_width
= 0;
27032 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27033 total_pixel_width
+= tmp_glyph
->pixel_width
;
27035 /* Pre calculation of re-rendering position. Note: X is in
27036 column units here, after the call to mode_line_string or
27037 marginal_area_string. */
27039 vpos
= (area
== ON_MODE_LINE
27040 ? (w
->current_matrix
)->nrows
- 1
27043 /* If GLYPH's position is included in the region that is
27044 already drawn in mouse face, we have nothing to do. */
27045 if ( EQ (window
, hlinfo
->mouse_face_window
)
27046 && (!row
->reversed_p
27047 ? (hlinfo
->mouse_face_beg_col
<= hpos
27048 && hpos
< hlinfo
->mouse_face_end_col
)
27049 /* In R2L rows we swap BEG and END, see below. */
27050 : (hlinfo
->mouse_face_end_col
<= hpos
27051 && hpos
< hlinfo
->mouse_face_beg_col
))
27052 && hlinfo
->mouse_face_beg_row
== vpos
)
27055 if (clear_mouse_face (hlinfo
))
27056 cursor
= No_Cursor
;
27058 if (!row
->reversed_p
)
27060 hlinfo
->mouse_face_beg_col
= hpos
;
27061 hlinfo
->mouse_face_beg_x
= original_x_pixel
27062 - (total_pixel_width
+ dx
);
27063 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27064 hlinfo
->mouse_face_end_x
= 0;
27068 /* In R2L rows, show_mouse_face expects BEG and END
27069 coordinates to be swapped. */
27070 hlinfo
->mouse_face_end_col
= hpos
;
27071 hlinfo
->mouse_face_end_x
= original_x_pixel
27072 - (total_pixel_width
+ dx
);
27073 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27074 hlinfo
->mouse_face_beg_x
= 0;
27077 hlinfo
->mouse_face_beg_row
= vpos
;
27078 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27079 hlinfo
->mouse_face_beg_y
= 0;
27080 hlinfo
->mouse_face_end_y
= 0;
27081 hlinfo
->mouse_face_past_end
= 0;
27082 hlinfo
->mouse_face_window
= window
;
27084 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27090 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27092 if (NILP (pointer
))
27095 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27096 clear_mouse_face (hlinfo
);
27098 #ifdef HAVE_WINDOW_SYSTEM
27099 if (FRAME_WINDOW_P (f
))
27100 define_frame_cursor1 (f
, cursor
, pointer
);
27106 Take proper action when the mouse has moved to position X, Y on
27107 frame F as regards highlighting characters that have mouse-face
27108 properties. Also de-highlighting chars where the mouse was before.
27109 X and Y can be negative or out of range. */
27112 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27114 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27115 enum window_part part
= ON_NOTHING
;
27116 Lisp_Object window
;
27118 Cursor cursor
= No_Cursor
;
27119 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27122 /* When a menu is active, don't highlight because this looks odd. */
27123 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27124 if (popup_activated ())
27128 if (NILP (Vmouse_highlight
)
27129 || !f
->glyphs_initialized_p
27130 || f
->pointer_invisible
)
27133 hlinfo
->mouse_face_mouse_x
= x
;
27134 hlinfo
->mouse_face_mouse_y
= y
;
27135 hlinfo
->mouse_face_mouse_frame
= f
;
27137 if (hlinfo
->mouse_face_defer
)
27140 if (gc_in_progress
)
27142 hlinfo
->mouse_face_deferred_gc
= 1;
27146 /* Which window is that in? */
27147 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27149 /* If displaying active text in another window, clear that. */
27150 if (! EQ (window
, hlinfo
->mouse_face_window
)
27151 /* Also clear if we move out of text area in same window. */
27152 || (!NILP (hlinfo
->mouse_face_window
)
27155 && part
!= ON_MODE_LINE
27156 && part
!= ON_HEADER_LINE
))
27157 clear_mouse_face (hlinfo
);
27159 /* Not on a window -> return. */
27160 if (!WINDOWP (window
))
27163 /* Reset help_echo_string. It will get recomputed below. */
27164 help_echo_string
= Qnil
;
27166 /* Convert to window-relative pixel coordinates. */
27167 w
= XWINDOW (window
);
27168 frame_to_window_pixel_xy (w
, &x
, &y
);
27170 #ifdef HAVE_WINDOW_SYSTEM
27171 /* Handle tool-bar window differently since it doesn't display a
27173 if (EQ (window
, f
->tool_bar_window
))
27175 note_tool_bar_highlight (f
, x
, y
);
27180 /* Mouse is on the mode, header line or margin? */
27181 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27182 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27184 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27188 #ifdef HAVE_WINDOW_SYSTEM
27189 if (part
== ON_VERTICAL_BORDER
)
27191 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27192 help_echo_string
= build_string ("drag-mouse-1: resize");
27194 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27195 || part
== ON_SCROLL_BAR
)
27196 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27198 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27201 /* Are we in a window whose display is up to date?
27202 And verify the buffer's text has not changed. */
27203 b
= XBUFFER (w
->buffer
);
27204 if (part
== ON_TEXT
27205 && EQ (w
->window_end_valid
, w
->buffer
)
27206 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
27207 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
27209 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27211 struct glyph
*glyph
;
27212 Lisp_Object object
;
27213 Lisp_Object mouse_face
= Qnil
, position
;
27214 Lisp_Object
*overlay_vec
= NULL
;
27215 ptrdiff_t i
, noverlays
;
27216 struct buffer
*obuf
;
27217 EMACS_INT obegv
, ozv
;
27220 /* Find the glyph under X/Y. */
27221 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27223 #ifdef HAVE_WINDOW_SYSTEM
27224 /* Look for :pointer property on image. */
27225 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27227 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27228 if (img
!= NULL
&& IMAGEP (img
->spec
))
27230 Lisp_Object image_map
, hotspot
;
27231 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27233 && (hotspot
= find_hot_spot (image_map
,
27234 glyph
->slice
.img
.x
+ dx
,
27235 glyph
->slice
.img
.y
+ dy
),
27237 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27241 /* Could check XCAR (hotspot) to see if we enter/leave
27243 If so, we could look for mouse-enter, mouse-leave
27244 properties in PLIST (and do something...). */
27245 hotspot
= XCDR (hotspot
);
27246 if (CONSP (hotspot
)
27247 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27249 pointer
= Fplist_get (plist
, Qpointer
);
27250 if (NILP (pointer
))
27252 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27253 if (!NILP (help_echo_string
))
27255 help_echo_window
= window
;
27256 help_echo_object
= glyph
->object
;
27257 help_echo_pos
= glyph
->charpos
;
27261 if (NILP (pointer
))
27262 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27265 #endif /* HAVE_WINDOW_SYSTEM */
27267 /* Clear mouse face if X/Y not over text. */
27269 || area
!= TEXT_AREA
27270 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27271 /* Glyph's OBJECT is an integer for glyphs inserted by the
27272 display engine for its internal purposes, like truncation
27273 and continuation glyphs and blanks beyond the end of
27274 line's text on text terminals. If we are over such a
27275 glyph, we are not over any text. */
27276 || INTEGERP (glyph
->object
)
27277 /* R2L rows have a stretch glyph at their front, which
27278 stands for no text, whereas L2R rows have no glyphs at
27279 all beyond the end of text. Treat such stretch glyphs
27280 like we do with NULL glyphs in L2R rows. */
27281 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27282 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27283 && glyph
->type
== STRETCH_GLYPH
27284 && glyph
->avoid_cursor_p
))
27286 if (clear_mouse_face (hlinfo
))
27287 cursor
= No_Cursor
;
27288 #ifdef HAVE_WINDOW_SYSTEM
27289 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27291 if (area
!= TEXT_AREA
)
27292 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27294 pointer
= Vvoid_text_area_pointer
;
27300 pos
= glyph
->charpos
;
27301 object
= glyph
->object
;
27302 if (!STRINGP (object
) && !BUFFERP (object
))
27305 /* If we get an out-of-range value, return now; avoid an error. */
27306 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27309 /* Make the window's buffer temporarily current for
27310 overlays_at and compute_char_face. */
27311 obuf
= current_buffer
;
27312 current_buffer
= b
;
27318 /* Is this char mouse-active or does it have help-echo? */
27319 position
= make_number (pos
);
27321 if (BUFFERP (object
))
27323 /* Put all the overlays we want in a vector in overlay_vec. */
27324 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27325 /* Sort overlays into increasing priority order. */
27326 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27331 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27334 cursor
= No_Cursor
;
27336 /* Check mouse-face highlighting. */
27338 /* If there exists an overlay with mouse-face overlapping
27339 the one we are currently highlighting, we have to
27340 check if we enter the overlapping overlay, and then
27341 highlight only that. */
27342 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27343 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27345 /* Find the highest priority overlay with a mouse-face. */
27346 Lisp_Object overlay
= Qnil
;
27347 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27349 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27350 if (!NILP (mouse_face
))
27351 overlay
= overlay_vec
[i
];
27354 /* If we're highlighting the same overlay as before, there's
27355 no need to do that again. */
27356 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27357 goto check_help_echo
;
27358 hlinfo
->mouse_face_overlay
= overlay
;
27360 /* Clear the display of the old active region, if any. */
27361 if (clear_mouse_face (hlinfo
))
27362 cursor
= No_Cursor
;
27364 /* If no overlay applies, get a text property. */
27365 if (NILP (overlay
))
27366 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27368 /* Next, compute the bounds of the mouse highlighting and
27370 if (!NILP (mouse_face
) && STRINGP (object
))
27372 /* The mouse-highlighting comes from a display string
27373 with a mouse-face. */
27377 s
= Fprevious_single_property_change
27378 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27379 e
= Fnext_single_property_change
27380 (position
, Qmouse_face
, object
, Qnil
);
27382 s
= make_number (0);
27384 e
= make_number (SCHARS (object
) - 1);
27385 mouse_face_from_string_pos (w
, hlinfo
, object
,
27386 XINT (s
), XINT (e
));
27387 hlinfo
->mouse_face_past_end
= 0;
27388 hlinfo
->mouse_face_window
= window
;
27389 hlinfo
->mouse_face_face_id
27390 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27391 glyph
->face_id
, 1);
27392 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27393 cursor
= No_Cursor
;
27397 /* The mouse-highlighting, if any, comes from an overlay
27398 or text property in the buffer. */
27399 Lisp_Object buffer
IF_LINT (= Qnil
);
27400 Lisp_Object disp_string
IF_LINT (= Qnil
);
27402 if (STRINGP (object
))
27404 /* If we are on a display string with no mouse-face,
27405 check if the text under it has one. */
27406 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27407 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
27408 pos
= string_buffer_position (object
, start
);
27411 mouse_face
= get_char_property_and_overlay
27412 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27413 buffer
= w
->buffer
;
27414 disp_string
= object
;
27420 disp_string
= Qnil
;
27423 if (!NILP (mouse_face
))
27425 Lisp_Object before
, after
;
27426 Lisp_Object before_string
, after_string
;
27427 /* To correctly find the limits of mouse highlight
27428 in a bidi-reordered buffer, we must not use the
27429 optimization of limiting the search in
27430 previous-single-property-change and
27431 next-single-property-change, because
27432 rows_from_pos_range needs the real start and end
27433 positions to DTRT in this case. That's because
27434 the first row visible in a window does not
27435 necessarily display the character whose position
27436 is the smallest. */
27438 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27439 ? Fmarker_position (w
->start
)
27442 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27443 ? make_number (BUF_Z (XBUFFER (buffer
))
27444 - XFASTINT (w
->window_end_pos
))
27447 if (NILP (overlay
))
27449 /* Handle the text property case. */
27450 before
= Fprevious_single_property_change
27451 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27452 after
= Fnext_single_property_change
27453 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27454 before_string
= after_string
= Qnil
;
27458 /* Handle the overlay case. */
27459 before
= Foverlay_start (overlay
);
27460 after
= Foverlay_end (overlay
);
27461 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27462 after_string
= Foverlay_get (overlay
, Qafter_string
);
27464 if (!STRINGP (before_string
)) before_string
= Qnil
;
27465 if (!STRINGP (after_string
)) after_string
= Qnil
;
27468 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27471 : XFASTINT (before
),
27473 ? BUF_Z (XBUFFER (buffer
))
27474 : XFASTINT (after
),
27475 before_string
, after_string
,
27477 cursor
= No_Cursor
;
27484 /* Look for a `help-echo' property. */
27485 if (NILP (help_echo_string
)) {
27486 Lisp_Object help
, overlay
;
27488 /* Check overlays first. */
27489 help
= overlay
= Qnil
;
27490 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27492 overlay
= overlay_vec
[i
];
27493 help
= Foverlay_get (overlay
, Qhelp_echo
);
27498 help_echo_string
= help
;
27499 help_echo_window
= window
;
27500 help_echo_object
= overlay
;
27501 help_echo_pos
= pos
;
27505 Lisp_Object obj
= glyph
->object
;
27506 EMACS_INT charpos
= glyph
->charpos
;
27508 /* Try text properties. */
27511 && charpos
< SCHARS (obj
))
27513 help
= Fget_text_property (make_number (charpos
),
27517 /* If the string itself doesn't specify a help-echo,
27518 see if the buffer text ``under'' it does. */
27519 struct glyph_row
*r
27520 = MATRIX_ROW (w
->current_matrix
, vpos
);
27521 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
27522 EMACS_INT p
= string_buffer_position (obj
, start
);
27525 help
= Fget_char_property (make_number (p
),
27526 Qhelp_echo
, w
->buffer
);
27535 else if (BUFFERP (obj
)
27538 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27543 help_echo_string
= help
;
27544 help_echo_window
= window
;
27545 help_echo_object
= obj
;
27546 help_echo_pos
= charpos
;
27551 #ifdef HAVE_WINDOW_SYSTEM
27552 /* Look for a `pointer' property. */
27553 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27555 /* Check overlays first. */
27556 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27557 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27559 if (NILP (pointer
))
27561 Lisp_Object obj
= glyph
->object
;
27562 EMACS_INT charpos
= glyph
->charpos
;
27564 /* Try text properties. */
27567 && charpos
< SCHARS (obj
))
27569 pointer
= Fget_text_property (make_number (charpos
),
27571 if (NILP (pointer
))
27573 /* If the string itself doesn't specify a pointer,
27574 see if the buffer text ``under'' it does. */
27575 struct glyph_row
*r
27576 = MATRIX_ROW (w
->current_matrix
, vpos
);
27577 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
27578 EMACS_INT p
= string_buffer_position (obj
, start
);
27580 pointer
= Fget_char_property (make_number (p
),
27581 Qpointer
, w
->buffer
);
27584 else if (BUFFERP (obj
)
27587 pointer
= Fget_text_property (make_number (charpos
),
27591 #endif /* HAVE_WINDOW_SYSTEM */
27595 current_buffer
= obuf
;
27600 #ifdef HAVE_WINDOW_SYSTEM
27601 if (FRAME_WINDOW_P (f
))
27602 define_frame_cursor1 (f
, cursor
, pointer
);
27604 /* This is here to prevent a compiler error, about "label at end of
27605 compound statement". */
27612 Clear any mouse-face on window W. This function is part of the
27613 redisplay interface, and is called from try_window_id and similar
27614 functions to ensure the mouse-highlight is off. */
27617 x_clear_window_mouse_face (struct window
*w
)
27619 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27620 Lisp_Object window
;
27623 XSETWINDOW (window
, w
);
27624 if (EQ (window
, hlinfo
->mouse_face_window
))
27625 clear_mouse_face (hlinfo
);
27631 Just discard the mouse face information for frame F, if any.
27632 This is used when the size of F is changed. */
27635 cancel_mouse_face (struct frame
*f
)
27637 Lisp_Object window
;
27638 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27640 window
= hlinfo
->mouse_face_window
;
27641 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27643 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27644 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27645 hlinfo
->mouse_face_window
= Qnil
;
27651 /***********************************************************************
27653 ***********************************************************************/
27655 #ifdef HAVE_WINDOW_SYSTEM
27657 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27658 which intersects rectangle R. R is in window-relative coordinates. */
27661 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27662 enum glyph_row_area area
)
27664 struct glyph
*first
= row
->glyphs
[area
];
27665 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27666 struct glyph
*last
;
27667 int first_x
, start_x
, x
;
27669 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27670 /* If row extends face to end of line write the whole line. */
27671 draw_glyphs (w
, 0, row
, area
,
27672 0, row
->used
[area
],
27673 DRAW_NORMAL_TEXT
, 0);
27676 /* Set START_X to the window-relative start position for drawing glyphs of
27677 AREA. The first glyph of the text area can be partially visible.
27678 The first glyphs of other areas cannot. */
27679 start_x
= window_box_left_offset (w
, area
);
27681 if (area
== TEXT_AREA
)
27684 /* Find the first glyph that must be redrawn. */
27686 && x
+ first
->pixel_width
< r
->x
)
27688 x
+= first
->pixel_width
;
27692 /* Find the last one. */
27696 && x
< r
->x
+ r
->width
)
27698 x
+= last
->pixel_width
;
27704 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27705 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27706 DRAW_NORMAL_TEXT
, 0);
27711 /* Redraw the parts of the glyph row ROW on window W intersecting
27712 rectangle R. R is in window-relative coordinates. Value is
27713 non-zero if mouse-face was overwritten. */
27716 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27718 xassert (row
->enabled_p
);
27720 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27721 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27722 0, row
->used
[TEXT_AREA
],
27723 DRAW_NORMAL_TEXT
, 0);
27726 if (row
->used
[LEFT_MARGIN_AREA
])
27727 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27728 if (row
->used
[TEXT_AREA
])
27729 expose_area (w
, row
, r
, TEXT_AREA
);
27730 if (row
->used
[RIGHT_MARGIN_AREA
])
27731 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27732 draw_row_fringe_bitmaps (w
, row
);
27735 return row
->mouse_face_p
;
27739 /* Redraw those parts of glyphs rows during expose event handling that
27740 overlap other rows. Redrawing of an exposed line writes over parts
27741 of lines overlapping that exposed line; this function fixes that.
27743 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27744 row in W's current matrix that is exposed and overlaps other rows.
27745 LAST_OVERLAPPING_ROW is the last such row. */
27748 expose_overlaps (struct window
*w
,
27749 struct glyph_row
*first_overlapping_row
,
27750 struct glyph_row
*last_overlapping_row
,
27753 struct glyph_row
*row
;
27755 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27756 if (row
->overlapping_p
)
27758 xassert (row
->enabled_p
&& !row
->mode_line_p
);
27761 if (row
->used
[LEFT_MARGIN_AREA
])
27762 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
27764 if (row
->used
[TEXT_AREA
])
27765 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
27767 if (row
->used
[RIGHT_MARGIN_AREA
])
27768 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
27774 /* Return non-zero if W's cursor intersects rectangle R. */
27777 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
27779 XRectangle cr
, result
;
27780 struct glyph
*cursor_glyph
;
27781 struct glyph_row
*row
;
27783 if (w
->phys_cursor
.vpos
>= 0
27784 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
27785 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
27787 && row
->cursor_in_fringe_p
)
27789 /* Cursor is in the fringe. */
27790 cr
.x
= window_box_right_offset (w
,
27791 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
27792 ? RIGHT_MARGIN_AREA
27795 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
27796 cr
.height
= row
->height
;
27797 return x_intersect_rectangles (&cr
, r
, &result
);
27800 cursor_glyph
= get_phys_cursor_glyph (w
);
27803 /* r is relative to W's box, but w->phys_cursor.x is relative
27804 to left edge of W's TEXT area. Adjust it. */
27805 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
27806 cr
.y
= w
->phys_cursor
.y
;
27807 cr
.width
= cursor_glyph
->pixel_width
;
27808 cr
.height
= w
->phys_cursor_height
;
27809 /* ++KFS: W32 version used W32-specific IntersectRect here, but
27810 I assume the effect is the same -- and this is portable. */
27811 return x_intersect_rectangles (&cr
, r
, &result
);
27813 /* If we don't understand the format, pretend we're not in the hot-spot. */
27819 Draw a vertical window border to the right of window W if W doesn't
27820 have vertical scroll bars. */
27823 x_draw_vertical_border (struct window
*w
)
27825 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27827 /* We could do better, if we knew what type of scroll-bar the adjacent
27828 windows (on either side) have... But we don't :-(
27829 However, I think this works ok. ++KFS 2003-04-25 */
27831 /* Redraw borders between horizontally adjacent windows. Don't
27832 do it for frames with vertical scroll bars because either the
27833 right scroll bar of a window, or the left scroll bar of its
27834 neighbor will suffice as a border. */
27835 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
27838 if (!WINDOW_RIGHTMOST_P (w
)
27839 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
27841 int x0
, x1
, y0
, y1
;
27843 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27846 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27849 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
27851 else if (!WINDOW_LEFTMOST_P (w
)
27852 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
27854 int x0
, x1
, y0
, y1
;
27856 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27859 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27862 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
27867 /* Redraw the part of window W intersection rectangle FR. Pixel
27868 coordinates in FR are frame-relative. Call this function with
27869 input blocked. Value is non-zero if the exposure overwrites
27873 expose_window (struct window
*w
, XRectangle
*fr
)
27875 struct frame
*f
= XFRAME (w
->frame
);
27877 int mouse_face_overwritten_p
= 0;
27879 /* If window is not yet fully initialized, do nothing. This can
27880 happen when toolkit scroll bars are used and a window is split.
27881 Reconfiguring the scroll bar will generate an expose for a newly
27883 if (w
->current_matrix
== NULL
)
27886 /* When we're currently updating the window, display and current
27887 matrix usually don't agree. Arrange for a thorough display
27889 if (w
== updated_window
)
27891 SET_FRAME_GARBAGED (f
);
27895 /* Frame-relative pixel rectangle of W. */
27896 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
27897 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
27898 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
27899 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
27901 if (x_intersect_rectangles (fr
, &wr
, &r
))
27903 int yb
= window_text_bottom_y (w
);
27904 struct glyph_row
*row
;
27905 int cursor_cleared_p
, phys_cursor_on_p
;
27906 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
27908 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
27909 r
.x
, r
.y
, r
.width
, r
.height
));
27911 /* Convert to window coordinates. */
27912 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
27913 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
27915 /* Turn off the cursor. */
27916 if (!w
->pseudo_window_p
27917 && phys_cursor_in_rect_p (w
, &r
))
27919 x_clear_cursor (w
);
27920 cursor_cleared_p
= 1;
27923 cursor_cleared_p
= 0;
27925 /* If the row containing the cursor extends face to end of line,
27926 then expose_area might overwrite the cursor outside the
27927 rectangle and thus notice_overwritten_cursor might clear
27928 w->phys_cursor_on_p. We remember the original value and
27929 check later if it is changed. */
27930 phys_cursor_on_p
= w
->phys_cursor_on_p
;
27932 /* Update lines intersecting rectangle R. */
27933 first_overlapping_row
= last_overlapping_row
= NULL
;
27934 for (row
= w
->current_matrix
->rows
;
27939 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
27941 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
27942 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
27943 || (r
.y
>= y0
&& r
.y
< y1
)
27944 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
27946 /* A header line may be overlapping, but there is no need
27947 to fix overlapping areas for them. KFS 2005-02-12 */
27948 if (row
->overlapping_p
&& !row
->mode_line_p
)
27950 if (first_overlapping_row
== NULL
)
27951 first_overlapping_row
= row
;
27952 last_overlapping_row
= row
;
27956 if (expose_line (w
, row
, &r
))
27957 mouse_face_overwritten_p
= 1;
27960 else if (row
->overlapping_p
)
27962 /* We must redraw a row overlapping the exposed area. */
27964 ? y0
+ row
->phys_height
> r
.y
27965 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
27967 if (first_overlapping_row
== NULL
)
27968 first_overlapping_row
= row
;
27969 last_overlapping_row
= row
;
27977 /* Display the mode line if there is one. */
27978 if (WINDOW_WANTS_MODELINE_P (w
)
27979 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
27981 && row
->y
< r
.y
+ r
.height
)
27983 if (expose_line (w
, row
, &r
))
27984 mouse_face_overwritten_p
= 1;
27987 if (!w
->pseudo_window_p
)
27989 /* Fix the display of overlapping rows. */
27990 if (first_overlapping_row
)
27991 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
27994 /* Draw border between windows. */
27995 x_draw_vertical_border (w
);
27997 /* Turn the cursor on again. */
27998 if (cursor_cleared_p
27999 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28000 update_window_cursor (w
, 1);
28004 return mouse_face_overwritten_p
;
28009 /* Redraw (parts) of all windows in the window tree rooted at W that
28010 intersect R. R contains frame pixel coordinates. Value is
28011 non-zero if the exposure overwrites mouse-face. */
28014 expose_window_tree (struct window
*w
, XRectangle
*r
)
28016 struct frame
*f
= XFRAME (w
->frame
);
28017 int mouse_face_overwritten_p
= 0;
28019 while (w
&& !FRAME_GARBAGED_P (f
))
28021 if (!NILP (w
->hchild
))
28022 mouse_face_overwritten_p
28023 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28024 else if (!NILP (w
->vchild
))
28025 mouse_face_overwritten_p
28026 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28028 mouse_face_overwritten_p
|= expose_window (w
, r
);
28030 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28033 return mouse_face_overwritten_p
;
28038 Redisplay an exposed area of frame F. X and Y are the upper-left
28039 corner of the exposed rectangle. W and H are width and height of
28040 the exposed area. All are pixel values. W or H zero means redraw
28041 the entire frame. */
28044 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28047 int mouse_face_overwritten_p
= 0;
28049 TRACE ((stderr
, "expose_frame "));
28051 /* No need to redraw if frame will be redrawn soon. */
28052 if (FRAME_GARBAGED_P (f
))
28054 TRACE ((stderr
, " garbaged\n"));
28058 /* If basic faces haven't been realized yet, there is no point in
28059 trying to redraw anything. This can happen when we get an expose
28060 event while Emacs is starting, e.g. by moving another window. */
28061 if (FRAME_FACE_CACHE (f
) == NULL
28062 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28064 TRACE ((stderr
, " no faces\n"));
28068 if (w
== 0 || h
== 0)
28071 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28072 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28082 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28083 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28085 if (WINDOWP (f
->tool_bar_window
))
28086 mouse_face_overwritten_p
28087 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28089 #ifdef HAVE_X_WINDOWS
28091 #ifndef USE_X_TOOLKIT
28092 if (WINDOWP (f
->menu_bar_window
))
28093 mouse_face_overwritten_p
28094 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28095 #endif /* not USE_X_TOOLKIT */
28099 /* Some window managers support a focus-follows-mouse style with
28100 delayed raising of frames. Imagine a partially obscured frame,
28101 and moving the mouse into partially obscured mouse-face on that
28102 frame. The visible part of the mouse-face will be highlighted,
28103 then the WM raises the obscured frame. With at least one WM, KDE
28104 2.1, Emacs is not getting any event for the raising of the frame
28105 (even tried with SubstructureRedirectMask), only Expose events.
28106 These expose events will draw text normally, i.e. not
28107 highlighted. Which means we must redo the highlight here.
28108 Subsume it under ``we love X''. --gerd 2001-08-15 */
28109 /* Included in Windows version because Windows most likely does not
28110 do the right thing if any third party tool offers
28111 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28112 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28114 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28115 if (f
== hlinfo
->mouse_face_mouse_frame
)
28117 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28118 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28119 clear_mouse_face (hlinfo
);
28120 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28127 Determine the intersection of two rectangles R1 and R2. Return
28128 the intersection in *RESULT. Value is non-zero if RESULT is not
28132 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28134 XRectangle
*left
, *right
;
28135 XRectangle
*upper
, *lower
;
28136 int intersection_p
= 0;
28138 /* Rearrange so that R1 is the left-most rectangle. */
28140 left
= r1
, right
= r2
;
28142 left
= r2
, right
= r1
;
28144 /* X0 of the intersection is right.x0, if this is inside R1,
28145 otherwise there is no intersection. */
28146 if (right
->x
<= left
->x
+ left
->width
)
28148 result
->x
= right
->x
;
28150 /* The right end of the intersection is the minimum of
28151 the right ends of left and right. */
28152 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28155 /* Same game for Y. */
28157 upper
= r1
, lower
= r2
;
28159 upper
= r2
, lower
= r1
;
28161 /* The upper end of the intersection is lower.y0, if this is inside
28162 of upper. Otherwise, there is no intersection. */
28163 if (lower
->y
<= upper
->y
+ upper
->height
)
28165 result
->y
= lower
->y
;
28167 /* The lower end of the intersection is the minimum of the lower
28168 ends of upper and lower. */
28169 result
->height
= (min (lower
->y
+ lower
->height
,
28170 upper
->y
+ upper
->height
)
28172 intersection_p
= 1;
28176 return intersection_p
;
28179 #endif /* HAVE_WINDOW_SYSTEM */
28182 /***********************************************************************
28184 ***********************************************************************/
28187 syms_of_xdisp (void)
28189 Vwith_echo_area_save_vector
= Qnil
;
28190 staticpro (&Vwith_echo_area_save_vector
);
28192 Vmessage_stack
= Qnil
;
28193 staticpro (&Vmessage_stack
);
28195 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28197 message_dolog_marker1
= Fmake_marker ();
28198 staticpro (&message_dolog_marker1
);
28199 message_dolog_marker2
= Fmake_marker ();
28200 staticpro (&message_dolog_marker2
);
28201 message_dolog_marker3
= Fmake_marker ();
28202 staticpro (&message_dolog_marker3
);
28205 defsubr (&Sdump_frame_glyph_matrix
);
28206 defsubr (&Sdump_glyph_matrix
);
28207 defsubr (&Sdump_glyph_row
);
28208 defsubr (&Sdump_tool_bar_row
);
28209 defsubr (&Strace_redisplay
);
28210 defsubr (&Strace_to_stderr
);
28212 #ifdef HAVE_WINDOW_SYSTEM
28213 defsubr (&Stool_bar_lines_needed
);
28214 defsubr (&Slookup_image_map
);
28216 defsubr (&Sformat_mode_line
);
28217 defsubr (&Sinvisible_p
);
28218 defsubr (&Scurrent_bidi_paragraph_direction
);
28220 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28221 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28222 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28223 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28224 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28225 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28226 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28227 DEFSYM (Qeval
, "eval");
28228 DEFSYM (QCdata
, ":data");
28229 DEFSYM (Qdisplay
, "display");
28230 DEFSYM (Qspace_width
, "space-width");
28231 DEFSYM (Qraise
, "raise");
28232 DEFSYM (Qslice
, "slice");
28233 DEFSYM (Qspace
, "space");
28234 DEFSYM (Qmargin
, "margin");
28235 DEFSYM (Qpointer
, "pointer");
28236 DEFSYM (Qleft_margin
, "left-margin");
28237 DEFSYM (Qright_margin
, "right-margin");
28238 DEFSYM (Qcenter
, "center");
28239 DEFSYM (Qline_height
, "line-height");
28240 DEFSYM (QCalign_to
, ":align-to");
28241 DEFSYM (QCrelative_width
, ":relative-width");
28242 DEFSYM (QCrelative_height
, ":relative-height");
28243 DEFSYM (QCeval
, ":eval");
28244 DEFSYM (QCpropertize
, ":propertize");
28245 DEFSYM (QCfile
, ":file");
28246 DEFSYM (Qfontified
, "fontified");
28247 DEFSYM (Qfontification_functions
, "fontification-functions");
28248 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28249 DEFSYM (Qescape_glyph
, "escape-glyph");
28250 DEFSYM (Qnobreak_space
, "nobreak-space");
28251 DEFSYM (Qimage
, "image");
28252 DEFSYM (Qtext
, "text");
28253 DEFSYM (Qboth
, "both");
28254 DEFSYM (Qboth_horiz
, "both-horiz");
28255 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28256 DEFSYM (QCmap
, ":map");
28257 DEFSYM (QCpointer
, ":pointer");
28258 DEFSYM (Qrect
, "rect");
28259 DEFSYM (Qcircle
, "circle");
28260 DEFSYM (Qpoly
, "poly");
28261 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28262 DEFSYM (Qgrow_only
, "grow-only");
28263 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28264 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28265 DEFSYM (Qposition
, "position");
28266 DEFSYM (Qbuffer_position
, "buffer-position");
28267 DEFSYM (Qobject
, "object");
28268 DEFSYM (Qbar
, "bar");
28269 DEFSYM (Qhbar
, "hbar");
28270 DEFSYM (Qbox
, "box");
28271 DEFSYM (Qhollow
, "hollow");
28272 DEFSYM (Qhand
, "hand");
28273 DEFSYM (Qarrow
, "arrow");
28274 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28276 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28277 Fcons (intern_c_string ("void-variable"), Qnil
)),
28279 staticpro (&list_of_error
);
28281 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28282 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28283 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28284 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28286 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28287 staticpro (&echo_buffer
[0]);
28288 staticpro (&echo_buffer
[1]);
28290 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28291 staticpro (&echo_area_buffer
[0]);
28292 staticpro (&echo_area_buffer
[1]);
28294 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28295 staticpro (&Vmessages_buffer_name
);
28297 mode_line_proptrans_alist
= Qnil
;
28298 staticpro (&mode_line_proptrans_alist
);
28299 mode_line_string_list
= Qnil
;
28300 staticpro (&mode_line_string_list
);
28301 mode_line_string_face
= Qnil
;
28302 staticpro (&mode_line_string_face
);
28303 mode_line_string_face_prop
= Qnil
;
28304 staticpro (&mode_line_string_face_prop
);
28305 Vmode_line_unwind_vector
= Qnil
;
28306 staticpro (&Vmode_line_unwind_vector
);
28308 help_echo_string
= Qnil
;
28309 staticpro (&help_echo_string
);
28310 help_echo_object
= Qnil
;
28311 staticpro (&help_echo_object
);
28312 help_echo_window
= Qnil
;
28313 staticpro (&help_echo_window
);
28314 previous_help_echo_string
= Qnil
;
28315 staticpro (&previous_help_echo_string
);
28316 help_echo_pos
= -1;
28318 DEFSYM (Qright_to_left
, "right-to-left");
28319 DEFSYM (Qleft_to_right
, "left-to-right");
28321 #ifdef HAVE_WINDOW_SYSTEM
28322 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28323 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28324 For example, if a block cursor is over a tab, it will be drawn as
28325 wide as that tab on the display. */);
28326 x_stretch_cursor_p
= 0;
28329 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28330 doc
: /* Non-nil means highlight trailing whitespace.
28331 The face used for trailing whitespace is `trailing-whitespace'. */);
28332 Vshow_trailing_whitespace
= Qnil
;
28334 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28335 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28336 If the value is t, Emacs highlights non-ASCII chars which have the
28337 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28338 or `escape-glyph' face respectively.
28340 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28341 U+2011 (non-breaking hyphen) are affected.
28343 Any other non-nil value means to display these characters as a escape
28344 glyph followed by an ordinary space or hyphen.
28346 A value of nil means no special handling of these characters. */);
28347 Vnobreak_char_display
= Qt
;
28349 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28350 doc
: /* The pointer shape to show in void text areas.
28351 A value of nil means to show the text pointer. Other options are `arrow',
28352 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28353 Vvoid_text_area_pointer
= Qarrow
;
28355 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28356 doc
: /* Non-nil means don't actually do any redisplay.
28357 This is used for internal purposes. */);
28358 Vinhibit_redisplay
= Qnil
;
28360 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28361 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28362 Vglobal_mode_string
= Qnil
;
28364 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28365 doc
: /* Marker for where to display an arrow on top of the buffer text.
28366 This must be the beginning of a line in order to work.
28367 See also `overlay-arrow-string'. */);
28368 Voverlay_arrow_position
= Qnil
;
28370 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28371 doc
: /* String to display as an arrow in non-window frames.
28372 See also `overlay-arrow-position'. */);
28373 Voverlay_arrow_string
= make_pure_c_string ("=>");
28375 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28376 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28377 The symbols on this list are examined during redisplay to determine
28378 where to display overlay arrows. */);
28379 Voverlay_arrow_variable_list
28380 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28382 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28383 doc
: /* The number of lines to try scrolling a window by when point moves out.
28384 If that fails to bring point back on frame, point is centered instead.
28385 If this is zero, point is always centered after it moves off frame.
28386 If you want scrolling to always be a line at a time, you should set
28387 `scroll-conservatively' to a large value rather than set this to 1. */);
28389 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28390 doc
: /* Scroll up to this many lines, to bring point back on screen.
28391 If point moves off-screen, redisplay will scroll by up to
28392 `scroll-conservatively' lines in order to bring point just barely
28393 onto the screen again. If that cannot be done, then redisplay
28394 recenters point as usual.
28396 If the value is greater than 100, redisplay will never recenter point,
28397 but will always scroll just enough text to bring point into view, even
28398 if you move far away.
28400 A value of zero means always recenter point if it moves off screen. */);
28401 scroll_conservatively
= 0;
28403 DEFVAR_INT ("scroll-margin", scroll_margin
,
28404 doc
: /* Number of lines of margin at the top and bottom of a window.
28405 Recenter the window whenever point gets within this many lines
28406 of the top or bottom of the window. */);
28409 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28410 doc
: /* Pixels per inch value for non-window system displays.
28411 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28412 Vdisplay_pixels_per_inch
= make_float (72.0);
28415 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28418 DEFVAR_LISP ("truncate-partial-width-windows",
28419 Vtruncate_partial_width_windows
,
28420 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28421 For an integer value, truncate lines in each window narrower than the
28422 full frame width, provided the window width is less than that integer;
28423 otherwise, respect the value of `truncate-lines'.
28425 For any other non-nil value, truncate lines in all windows that do
28426 not span the full frame width.
28428 A value of nil means to respect the value of `truncate-lines'.
28430 If `word-wrap' is enabled, you might want to reduce this. */);
28431 Vtruncate_partial_width_windows
= make_number (50);
28433 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28434 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28435 Any other value means to use the appropriate face, `mode-line',
28436 `header-line', or `menu' respectively. */);
28437 mode_line_inverse_video
= 1;
28439 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28440 doc
: /* Maximum buffer size for which line number should be displayed.
28441 If the buffer is bigger than this, the line number does not appear
28442 in the mode line. A value of nil means no limit. */);
28443 Vline_number_display_limit
= Qnil
;
28445 DEFVAR_INT ("line-number-display-limit-width",
28446 line_number_display_limit_width
,
28447 doc
: /* Maximum line width (in characters) for line number display.
28448 If the average length of the lines near point is bigger than this, then the
28449 line number may be omitted from the mode line. */);
28450 line_number_display_limit_width
= 200;
28452 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28453 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28454 highlight_nonselected_windows
= 0;
28456 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28457 doc
: /* Non-nil if more than one frame is visible on this display.
28458 Minibuffer-only frames don't count, but iconified frames do.
28459 This variable is not guaranteed to be accurate except while processing
28460 `frame-title-format' and `icon-title-format'. */);
28462 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28463 doc
: /* Template for displaying the title bar of visible frames.
28464 \(Assuming the window manager supports this feature.)
28466 This variable has the same structure as `mode-line-format', except that
28467 the %c and %l constructs are ignored. It is used only on frames for
28468 which no explicit name has been set \(see `modify-frame-parameters'). */);
28470 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28471 doc
: /* Template for displaying the title bar of an iconified frame.
28472 \(Assuming the window manager supports this feature.)
28473 This variable has the same structure as `mode-line-format' (which see),
28474 and is used only on frames for which no explicit name has been set
28475 \(see `modify-frame-parameters'). */);
28477 = Vframe_title_format
28478 = pure_cons (intern_c_string ("multiple-frames"),
28479 pure_cons (make_pure_c_string ("%b"),
28480 pure_cons (pure_cons (empty_unibyte_string
,
28481 pure_cons (intern_c_string ("invocation-name"),
28482 pure_cons (make_pure_c_string ("@"),
28483 pure_cons (intern_c_string ("system-name"),
28487 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28488 doc
: /* Maximum number of lines to keep in the message log buffer.
28489 If nil, disable message logging. If t, log messages but don't truncate
28490 the buffer when it becomes large. */);
28491 Vmessage_log_max
= make_number (100);
28493 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28494 doc
: /* Functions called before redisplay, if window sizes have changed.
28495 The value should be a list of functions that take one argument.
28496 Just before redisplay, for each frame, if any of its windows have changed
28497 size since the last redisplay, or have been split or deleted,
28498 all the functions in the list are called, with the frame as argument. */);
28499 Vwindow_size_change_functions
= Qnil
;
28501 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28502 doc
: /* List of functions to call before redisplaying a window with scrolling.
28503 Each function is called with two arguments, the window and its new
28504 display-start position. Note that these functions are also called by
28505 `set-window-buffer'. Also note that the value of `window-end' is not
28506 valid when these functions are called.
28508 Warning: Do not use this feature to alter the way the window
28509 is scrolled. It is not designed for that, and such use probably won't
28511 Vwindow_scroll_functions
= Qnil
;
28513 DEFVAR_LISP ("window-text-change-functions",
28514 Vwindow_text_change_functions
,
28515 doc
: /* Functions to call in redisplay when text in the window might change. */);
28516 Vwindow_text_change_functions
= Qnil
;
28518 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28519 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28520 Each function is called with two arguments, the window and the end trigger value.
28521 See `set-window-redisplay-end-trigger'. */);
28522 Vredisplay_end_trigger_functions
= Qnil
;
28524 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28525 doc
: /* Non-nil means autoselect window with mouse pointer.
28526 If nil, do not autoselect windows.
28527 A positive number means delay autoselection by that many seconds: a
28528 window is autoselected only after the mouse has remained in that
28529 window for the duration of the delay.
28530 A negative number has a similar effect, but causes windows to be
28531 autoselected only after the mouse has stopped moving. \(Because of
28532 the way Emacs compares mouse events, you will occasionally wait twice
28533 that time before the window gets selected.\)
28534 Any other value means to autoselect window instantaneously when the
28535 mouse pointer enters it.
28537 Autoselection selects the minibuffer only if it is active, and never
28538 unselects the minibuffer if it is active.
28540 When customizing this variable make sure that the actual value of
28541 `focus-follows-mouse' matches the behavior of your window manager. */);
28542 Vmouse_autoselect_window
= Qnil
;
28544 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28545 doc
: /* Non-nil means automatically resize tool-bars.
28546 This dynamically changes the tool-bar's height to the minimum height
28547 that is needed to make all tool-bar items visible.
28548 If value is `grow-only', the tool-bar's height is only increased
28549 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28550 Vauto_resize_tool_bars
= Qt
;
28552 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28553 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28554 auto_raise_tool_bar_buttons_p
= 1;
28556 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28557 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28558 make_cursor_line_fully_visible_p
= 1;
28560 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28561 doc
: /* Border below tool-bar in pixels.
28562 If an integer, use it as the height of the border.
28563 If it is one of `internal-border-width' or `border-width', use the
28564 value of the corresponding frame parameter.
28565 Otherwise, no border is added below the tool-bar. */);
28566 Vtool_bar_border
= Qinternal_border_width
;
28568 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28569 doc
: /* Margin around tool-bar buttons in pixels.
28570 If an integer, use that for both horizontal and vertical margins.
28571 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28572 HORZ specifying the horizontal margin, and VERT specifying the
28573 vertical margin. */);
28574 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28576 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28577 doc
: /* Relief thickness of tool-bar buttons. */);
28578 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28580 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28581 doc
: /* Tool bar style to use.
28583 image - show images only
28584 text - show text only
28585 both - show both, text below image
28586 both-horiz - show text to the right of the image
28587 text-image-horiz - show text to the left of the image
28588 any other - use system default or image if no system default. */);
28589 Vtool_bar_style
= Qnil
;
28591 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28592 doc
: /* Maximum number of characters a label can have to be shown.
28593 The tool bar style must also show labels for this to have any effect, see
28594 `tool-bar-style'. */);
28595 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28597 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28598 doc
: /* List of functions to call to fontify regions of text.
28599 Each function is called with one argument POS. Functions must
28600 fontify a region starting at POS in the current buffer, and give
28601 fontified regions the property `fontified'. */);
28602 Vfontification_functions
= Qnil
;
28603 Fmake_variable_buffer_local (Qfontification_functions
);
28605 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28606 unibyte_display_via_language_environment
,
28607 doc
: /* Non-nil means display unibyte text according to language environment.
28608 Specifically, this means that raw bytes in the range 160-255 decimal
28609 are displayed by converting them to the equivalent multibyte characters
28610 according to the current language environment. As a result, they are
28611 displayed according to the current fontset.
28613 Note that this variable affects only how these bytes are displayed,
28614 but does not change the fact they are interpreted as raw bytes. */);
28615 unibyte_display_via_language_environment
= 0;
28617 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28618 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
28619 If a float, it specifies a fraction of the mini-window frame's height.
28620 If an integer, it specifies a number of lines. */);
28621 Vmax_mini_window_height
= make_float (0.25);
28623 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28624 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28625 A value of nil means don't automatically resize mini-windows.
28626 A value of t means resize them to fit the text displayed in them.
28627 A value of `grow-only', the default, means let mini-windows grow only;
28628 they return to their normal size when the minibuffer is closed, or the
28629 echo area becomes empty. */);
28630 Vresize_mini_windows
= Qgrow_only
;
28632 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28633 doc
: /* Alist specifying how to blink the cursor off.
28634 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28635 `cursor-type' frame-parameter or variable equals ON-STATE,
28636 comparing using `equal', Emacs uses OFF-STATE to specify
28637 how to blink it off. ON-STATE and OFF-STATE are values for
28638 the `cursor-type' frame parameter.
28640 If a frame's ON-STATE has no entry in this list,
28641 the frame's other specifications determine how to blink the cursor off. */);
28642 Vblink_cursor_alist
= Qnil
;
28644 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28645 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28646 If non-nil, windows are automatically scrolled horizontally to make
28647 point visible. */);
28648 automatic_hscrolling_p
= 1;
28649 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28651 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28652 doc
: /* How many columns away from the window edge point is allowed to get
28653 before automatic hscrolling will horizontally scroll the window. */);
28654 hscroll_margin
= 5;
28656 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28657 doc
: /* How many columns to scroll the window when point gets too close to the edge.
28658 When point is less than `hscroll-margin' columns from the window
28659 edge, automatic hscrolling will scroll the window by the amount of columns
28660 determined by this variable. If its value is a positive integer, scroll that
28661 many columns. If it's a positive floating-point number, it specifies the
28662 fraction of the window's width to scroll. If it's nil or zero, point will be
28663 centered horizontally after the scroll. Any other value, including negative
28664 numbers, are treated as if the value were zero.
28666 Automatic hscrolling always moves point outside the scroll margin, so if
28667 point was more than scroll step columns inside the margin, the window will
28668 scroll more than the value given by the scroll step.
28670 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28671 and `scroll-right' overrides this variable's effect. */);
28672 Vhscroll_step
= make_number (0);
28674 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28675 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28676 Bind this around calls to `message' to let it take effect. */);
28677 message_truncate_lines
= 0;
28679 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28680 doc
: /* Normal hook run to update the menu bar definitions.
28681 Redisplay runs this hook before it redisplays the menu bar.
28682 This is used to update submenus such as Buffers,
28683 whose contents depend on various data. */);
28684 Vmenu_bar_update_hook
= Qnil
;
28686 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28687 doc
: /* Frame for which we are updating a menu.
28688 The enable predicate for a menu binding should check this variable. */);
28689 Vmenu_updating_frame
= Qnil
;
28691 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28692 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28693 inhibit_menubar_update
= 0;
28695 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28696 doc
: /* Prefix prepended to all continuation lines at display time.
28697 The value may be a string, an image, or a stretch-glyph; it is
28698 interpreted in the same way as the value of a `display' text property.
28700 This variable is overridden by any `wrap-prefix' text or overlay
28703 To add a prefix to non-continuation lines, use `line-prefix'. */);
28704 Vwrap_prefix
= Qnil
;
28705 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28706 Fmake_variable_buffer_local (Qwrap_prefix
);
28708 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28709 doc
: /* Prefix prepended to all non-continuation lines at display time.
28710 The value may be a string, an image, or a stretch-glyph; it is
28711 interpreted in the same way as the value of a `display' text property.
28713 This variable is overridden by any `line-prefix' text or overlay
28716 To add a prefix to continuation lines, use `wrap-prefix'. */);
28717 Vline_prefix
= Qnil
;
28718 DEFSYM (Qline_prefix
, "line-prefix");
28719 Fmake_variable_buffer_local (Qline_prefix
);
28721 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28722 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28723 inhibit_eval_during_redisplay
= 0;
28725 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28726 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28727 inhibit_free_realized_faces
= 0;
28730 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28731 doc
: /* Inhibit try_window_id display optimization. */);
28732 inhibit_try_window_id
= 0;
28734 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28735 doc
: /* Inhibit try_window_reusing display optimization. */);
28736 inhibit_try_window_reusing
= 0;
28738 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28739 doc
: /* Inhibit try_cursor_movement display optimization. */);
28740 inhibit_try_cursor_movement
= 0;
28741 #endif /* GLYPH_DEBUG */
28743 DEFVAR_INT ("overline-margin", overline_margin
,
28744 doc
: /* Space between overline and text, in pixels.
28745 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28746 margin to the character height. */);
28747 overline_margin
= 2;
28749 DEFVAR_INT ("underline-minimum-offset",
28750 underline_minimum_offset
,
28751 doc
: /* Minimum distance between baseline and underline.
28752 This can improve legibility of underlined text at small font sizes,
28753 particularly when using variable `x-use-underline-position-properties'
28754 with fonts that specify an UNDERLINE_POSITION relatively close to the
28755 baseline. The default value is 1. */);
28756 underline_minimum_offset
= 1;
28758 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
28759 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
28760 This feature only works when on a window system that can change
28761 cursor shapes. */);
28762 display_hourglass_p
= 1;
28764 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
28765 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
28766 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
28768 hourglass_atimer
= NULL
;
28769 hourglass_shown_p
= 0;
28771 DEFSYM (Qglyphless_char
, "glyphless-char");
28772 DEFSYM (Qhex_code
, "hex-code");
28773 DEFSYM (Qempty_box
, "empty-box");
28774 DEFSYM (Qthin_space
, "thin-space");
28775 DEFSYM (Qzero_width
, "zero-width");
28777 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
28778 /* Intern this now in case it isn't already done.
28779 Setting this variable twice is harmless.
28780 But don't staticpro it here--that is done in alloc.c. */
28781 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
28782 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
28784 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
28785 doc
: /* Char-table defining glyphless characters.
28786 Each element, if non-nil, should be one of the following:
28787 an ASCII acronym string: display this string in a box
28788 `hex-code': display the hexadecimal code of a character in a box
28789 `empty-box': display as an empty box
28790 `thin-space': display as 1-pixel width space
28791 `zero-width': don't display
28792 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
28793 display method for graphical terminals and text terminals respectively.
28794 GRAPHICAL and TEXT should each have one of the values listed above.
28796 The char-table has one extra slot to control the display of a character for
28797 which no font is found. This slot only takes effect on graphical terminals.
28798 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
28799 `thin-space'. The default is `empty-box'. */);
28800 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
28801 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
28806 /* Initialize this module when Emacs starts. */
28811 current_header_line_height
= current_mode_line_height
= -1;
28813 CHARPOS (this_line_start_pos
) = 0;
28815 if (!noninteractive
)
28817 struct window
*m
= XWINDOW (minibuf_window
);
28818 Lisp_Object frame
= m
->frame
;
28819 struct frame
*f
= XFRAME (frame
);
28820 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
28821 struct window
*r
= XWINDOW (root
);
28824 echo_area_window
= minibuf_window
;
28826 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
28827 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
28828 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
28829 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
28830 XSETFASTINT (m
->total_lines
, 1);
28831 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
28833 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
28834 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
28835 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
28837 /* The default ellipsis glyphs `...'. */
28838 for (i
= 0; i
< 3; ++i
)
28839 default_invis_vector
[i
] = make_number ('.');
28843 /* Allocate the buffer for frame titles.
28844 Also used for `format-mode-line'. */
28846 mode_line_noprop_buf
= (char *) xmalloc (size
);
28847 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
28848 mode_line_noprop_ptr
= mode_line_noprop_buf
;
28849 mode_line_target
= MODE_LINE_DISPLAY
;
28852 help_echo_showing_p
= 0;
28855 /* Since w32 does not support atimers, it defines its own implementation of
28856 the following three functions in w32fns.c. */
28859 /* Platform-independent portion of hourglass implementation. */
28861 /* Return non-zero if hourglass timer has been started or hourglass is
28864 hourglass_started (void)
28866 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
28869 /* Cancel a currently active hourglass timer, and start a new one. */
28871 start_hourglass (void)
28873 #if defined (HAVE_WINDOW_SYSTEM)
28875 int secs
, usecs
= 0;
28877 cancel_hourglass ();
28879 if (INTEGERP (Vhourglass_delay
)
28880 && XINT (Vhourglass_delay
) > 0)
28881 secs
= XFASTINT (Vhourglass_delay
);
28882 else if (FLOATP (Vhourglass_delay
)
28883 && XFLOAT_DATA (Vhourglass_delay
) > 0)
28886 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
28887 secs
= XFASTINT (tem
);
28888 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
28891 secs
= DEFAULT_HOURGLASS_DELAY
;
28893 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
28894 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
28895 show_hourglass
, NULL
);
28900 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
28903 cancel_hourglass (void)
28905 #if defined (HAVE_WINDOW_SYSTEM)
28906 if (hourglass_atimer
)
28908 cancel_atimer (hourglass_atimer
);
28909 hourglass_atimer
= NULL
;
28912 if (hourglass_shown_p
)
28916 #endif /* ! WINDOWSNT */