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"
284 #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
633 GLYPH_DEBUG defined. */
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
;
754 static Lisp_Object Qmode_line_default_help_echo
;
756 /* If a string, XTread_socket generates an event to display that string.
757 (The display is done in read_char.) */
759 Lisp_Object help_echo_string
;
760 Lisp_Object help_echo_window
;
761 Lisp_Object help_echo_object
;
762 ptrdiff_t help_echo_pos
;
764 /* Temporary variable for XTread_socket. */
766 Lisp_Object previous_help_echo_string
;
768 /* Platform-independent portion of hourglass implementation. */
770 /* Non-zero means an hourglass cursor is currently shown. */
771 int hourglass_shown_p
;
773 /* If non-null, an asynchronous timer that, when it expires, displays
774 an hourglass cursor on all frames. */
775 struct atimer
*hourglass_atimer
;
777 /* Name of the face used to display glyphless characters. */
778 Lisp_Object Qglyphless_char
;
780 /* Symbol for the purpose of Vglyphless_char_display. */
781 static Lisp_Object Qglyphless_char_display
;
783 /* Method symbols for Vglyphless_char_display. */
784 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
786 /* Default pixel width of `thin-space' display method. */
787 #define THIN_SPACE_WIDTH 1
789 /* Default number of seconds to wait before displaying an hourglass
791 #define DEFAULT_HOURGLASS_DELAY 1
794 /* Function prototypes. */
796 static void setup_for_ellipsis (struct it
*, int);
797 static void set_iterator_to_next (struct it
*, int);
798 static void mark_window_display_accurate_1 (struct window
*, int);
799 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
800 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
801 static int cursor_row_p (struct glyph_row
*);
802 static int redisplay_mode_lines (Lisp_Object
, int);
803 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
805 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
807 static void handle_line_prefix (struct it
*);
809 static void pint2str (char *, int, ptrdiff_t);
810 static void pint2hrstr (char *, int, ptrdiff_t);
811 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
813 static void reconsider_clip_changes (struct window
*, struct buffer
*);
814 static int text_outside_line_unchanged_p (struct window
*,
815 ptrdiff_t, ptrdiff_t);
816 static void store_mode_line_noprop_char (char);
817 static int store_mode_line_noprop (const char *, int, int);
818 static void handle_stop (struct it
*);
819 static void handle_stop_backwards (struct it
*, ptrdiff_t);
820 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
821 static void ensure_echo_area_buffers (void);
822 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
823 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
824 static int with_echo_area_buffer (struct window
*, int,
825 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
826 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
827 static void clear_garbaged_frames (void);
828 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
829 static void pop_message (void);
830 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
831 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
832 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
833 static int display_echo_area (struct window
*);
834 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
835 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
836 static Lisp_Object
unwind_redisplay (Lisp_Object
);
837 static int string_char_and_length (const unsigned char *, int *);
838 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
840 static int compute_window_start_on_continuation_line (struct window
*);
841 static Lisp_Object
safe_eval_handler (Lisp_Object
);
842 static void insert_left_trunc_glyphs (struct it
*);
843 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
845 static void extend_face_to_end_of_line (struct it
*);
846 static int append_space_for_newline (struct it
*, int);
847 static int cursor_row_fully_visible_p (struct window
*, int, int);
848 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
849 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
850 static int trailing_whitespace_p (ptrdiff_t);
851 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
852 static void push_it (struct it
*, struct text_pos
*);
853 static void iterate_out_of_display_property (struct it
*);
854 static void pop_it (struct it
*);
855 static void sync_frame_with_window_matrix_rows (struct window
*);
856 static void select_frame_for_redisplay (Lisp_Object
);
857 static void redisplay_internal (void);
858 static int echo_area_display (int);
859 static void redisplay_windows (Lisp_Object
);
860 static void redisplay_window (Lisp_Object
, int);
861 static Lisp_Object
redisplay_window_error (Lisp_Object
);
862 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
863 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
864 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
865 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
867 static int update_menu_bar (struct frame
*, int, int);
868 static int try_window_reusing_current_matrix (struct window
*);
869 static int try_window_id (struct window
*);
870 static int display_line (struct it
*);
871 static int display_mode_lines (struct window
*);
872 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
873 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
874 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
875 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
876 static void display_menu_bar (struct window
*);
877 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
879 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
880 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
881 static void compute_line_metrics (struct it
*);
882 static void run_redisplay_end_trigger_hook (struct it
*);
883 static int get_overlay_strings (struct it
*, ptrdiff_t);
884 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
885 static void next_overlay_string (struct it
*);
886 static void reseat (struct it
*, struct text_pos
, int);
887 static void reseat_1 (struct it
*, struct text_pos
, int);
888 static void back_to_previous_visible_line_start (struct it
*);
889 void reseat_at_previous_visible_line_start (struct it
*);
890 static void reseat_at_next_visible_line_start (struct it
*, int);
891 static int next_element_from_ellipsis (struct it
*);
892 static int next_element_from_display_vector (struct it
*);
893 static int next_element_from_string (struct it
*);
894 static int next_element_from_c_string (struct it
*);
895 static int next_element_from_buffer (struct it
*);
896 static int next_element_from_composition (struct it
*);
897 static int next_element_from_image (struct it
*);
898 static int next_element_from_stretch (struct it
*);
899 static void load_overlay_strings (struct it
*, ptrdiff_t);
900 static int init_from_display_pos (struct it
*, struct window
*,
901 struct display_pos
*);
902 static void reseat_to_string (struct it
*, const char *,
903 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
904 static int get_next_display_element (struct it
*);
905 static enum move_it_result
906 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
907 enum move_operation_enum
);
908 void move_it_vertically_backward (struct it
*, int);
909 static void init_to_row_start (struct it
*, struct window
*,
911 static int init_to_row_end (struct it
*, struct window
*,
913 static void back_to_previous_line_start (struct it
*);
914 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
915 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
916 Lisp_Object
, ptrdiff_t);
917 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
918 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
919 static ptrdiff_t number_of_chars (const char *, int);
920 static void compute_stop_pos (struct it
*);
921 static void compute_string_pos (struct text_pos
*, struct text_pos
,
923 static int face_before_or_after_it_pos (struct it
*, int);
924 static ptrdiff_t next_overlay_change (ptrdiff_t);
925 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
926 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
927 static int handle_single_display_spec (struct it
*, Lisp_Object
,
928 Lisp_Object
, Lisp_Object
,
929 struct text_pos
*, ptrdiff_t, int, int);
930 static int underlying_face_id (struct it
*);
931 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
934 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
935 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
937 #ifdef HAVE_WINDOW_SYSTEM
939 static void x_consider_frame_title (Lisp_Object
);
940 static int tool_bar_lines_needed (struct frame
*, int *);
941 static void update_tool_bar (struct frame
*, int);
942 static void build_desired_tool_bar_string (struct frame
*f
);
943 static int redisplay_tool_bar (struct frame
*);
944 static void display_tool_bar_line (struct it
*, int);
945 static void notice_overwritten_cursor (struct window
*,
948 static void append_stretch_glyph (struct it
*, Lisp_Object
,
952 #endif /* HAVE_WINDOW_SYSTEM */
954 static void produce_special_glyphs (struct it
*, enum display_element_type
);
955 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
956 static int coords_in_mouse_face_p (struct window
*, int, int);
960 /***********************************************************************
961 Window display dimensions
962 ***********************************************************************/
964 /* Return the bottom boundary y-position for text lines in window W.
965 This is the first y position at which a line cannot start.
966 It is relative to the top of the window.
968 This is the height of W minus the height of a mode line, if any. */
971 window_text_bottom_y (struct window
*w
)
973 int height
= WINDOW_TOTAL_HEIGHT (w
);
975 if (WINDOW_WANTS_MODELINE_P (w
))
976 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
980 /* Return the pixel width of display area AREA of window W. AREA < 0
981 means return the total width of W, not including fringes to
982 the left and right of the window. */
985 window_box_width (struct window
*w
, int area
)
987 int cols
= XFASTINT (WVAR (w
, total_cols
));
990 if (!w
->pseudo_window_p
)
992 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
994 if (area
== TEXT_AREA
)
996 if (INTEGERP (WVAR (w
, left_margin_cols
)))
997 cols
-= XFASTINT (WVAR (w
, left_margin_cols
));
998 if (INTEGERP (WVAR (w
, right_margin_cols
)))
999 cols
-= XFASTINT (WVAR (w
, right_margin_cols
));
1000 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1002 else if (area
== LEFT_MARGIN_AREA
)
1004 cols
= (INTEGERP (WVAR (w
, left_margin_cols
))
1005 ? XFASTINT (WVAR (w
, left_margin_cols
)) : 0);
1008 else if (area
== RIGHT_MARGIN_AREA
)
1010 cols
= (INTEGERP (WVAR (w
, right_margin_cols
))
1011 ? XFASTINT (WVAR (w
, right_margin_cols
)) : 0);
1016 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1020 /* Return the pixel height of the display area of window W, not
1021 including mode lines of W, if any. */
1024 window_box_height (struct window
*w
)
1026 struct frame
*f
= XFRAME (WVAR (w
, frame
));
1027 int height
= WINDOW_TOTAL_HEIGHT (w
);
1029 eassert (height
>= 0);
1031 /* Note: the code below that determines the mode-line/header-line
1032 height is essentially the same as that contained in the macro
1033 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1034 the appropriate glyph row has its `mode_line_p' flag set,
1035 and if it doesn't, uses estimate_mode_line_height instead. */
1037 if (WINDOW_WANTS_MODELINE_P (w
))
1039 struct glyph_row
*ml_row
1040 = (w
->current_matrix
&& w
->current_matrix
->rows
1041 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1043 if (ml_row
&& ml_row
->mode_line_p
)
1044 height
-= ml_row
->height
;
1046 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1049 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1051 struct glyph_row
*hl_row
1052 = (w
->current_matrix
&& w
->current_matrix
->rows
1053 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1055 if (hl_row
&& hl_row
->mode_line_p
)
1056 height
-= hl_row
->height
;
1058 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1061 /* With a very small font and a mode-line that's taller than
1062 default, we might end up with a negative height. */
1063 return max (0, height
);
1066 /* Return the window-relative coordinate of the left edge of display
1067 area AREA of window W. AREA < 0 means return the left edge of the
1068 whole window, to the right of the left fringe of W. */
1071 window_box_left_offset (struct window
*w
, int area
)
1075 if (w
->pseudo_window_p
)
1078 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1080 if (area
== TEXT_AREA
)
1081 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1082 + window_box_width (w
, LEFT_MARGIN_AREA
));
1083 else if (area
== RIGHT_MARGIN_AREA
)
1084 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1085 + window_box_width (w
, LEFT_MARGIN_AREA
)
1086 + window_box_width (w
, TEXT_AREA
)
1087 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1089 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1090 else if (area
== LEFT_MARGIN_AREA
1091 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1092 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1098 /* Return the window-relative coordinate of the right edge of display
1099 area AREA of window W. AREA < 0 means return the right edge of the
1100 whole window, to the left of the right fringe of W. */
1103 window_box_right_offset (struct window
*w
, int area
)
1105 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1108 /* Return the frame-relative coordinate of the left edge of display
1109 area AREA of window W. AREA < 0 means return the left edge of the
1110 whole window, to the right of the left fringe of W. */
1113 window_box_left (struct window
*w
, int area
)
1115 struct frame
*f
= XFRAME (WVAR (w
, frame
));
1118 if (w
->pseudo_window_p
)
1119 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1121 x
= (WINDOW_LEFT_EDGE_X (w
)
1122 + window_box_left_offset (w
, area
));
1128 /* Return the frame-relative coordinate of the right edge of display
1129 area AREA of window W. AREA < 0 means return the right edge of the
1130 whole window, to the left of the right fringe of W. */
1133 window_box_right (struct window
*w
, int area
)
1135 return window_box_left (w
, area
) + window_box_width (w
, area
);
1138 /* Get the bounding box of the display area AREA of window W, without
1139 mode lines, in frame-relative coordinates. AREA < 0 means the
1140 whole window, not including the left and right fringes of
1141 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1142 coordinates of the upper-left corner of the box. Return in
1143 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1146 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1147 int *box_width
, int *box_height
)
1150 *box_width
= window_box_width (w
, area
);
1152 *box_height
= window_box_height (w
);
1154 *box_x
= window_box_left (w
, area
);
1157 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1158 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1159 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1164 /* Get the bounding box of the display area AREA of window W, without
1165 mode lines. AREA < 0 means the whole window, not including the
1166 left and right fringe of the window. Return in *TOP_LEFT_X
1167 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1168 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1169 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1173 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1174 int *bottom_right_x
, int *bottom_right_y
)
1176 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1178 *bottom_right_x
+= *top_left_x
;
1179 *bottom_right_y
+= *top_left_y
;
1184 /***********************************************************************
1186 ***********************************************************************/
1188 /* Return the bottom y-position of the line the iterator IT is in.
1189 This can modify IT's settings. */
1192 line_bottom_y (struct it
*it
)
1194 int line_height
= it
->max_ascent
+ it
->max_descent
;
1195 int line_top_y
= it
->current_y
;
1197 if (line_height
== 0)
1200 line_height
= last_height
;
1201 else if (IT_CHARPOS (*it
) < ZV
)
1203 move_it_by_lines (it
, 1);
1204 line_height
= (it
->max_ascent
|| it
->max_descent
1205 ? it
->max_ascent
+ it
->max_descent
1210 struct glyph_row
*row
= it
->glyph_row
;
1212 /* Use the default character height. */
1213 it
->glyph_row
= NULL
;
1214 it
->what
= IT_CHARACTER
;
1217 PRODUCE_GLYPHS (it
);
1218 line_height
= it
->ascent
+ it
->descent
;
1219 it
->glyph_row
= row
;
1223 return line_top_y
+ line_height
;
1226 /* Subroutine of pos_visible_p below. Extracts a display string, if
1227 any, from the display spec given as its argument. */
1229 string_from_display_spec (Lisp_Object spec
)
1233 while (CONSP (spec
))
1235 if (STRINGP (XCAR (spec
)))
1240 else if (VECTORP (spec
))
1244 for (i
= 0; i
< ASIZE (spec
); i
++)
1246 if (STRINGP (AREF (spec
, i
)))
1247 return AREF (spec
, i
);
1256 /* Limit insanely large values of W->hscroll on frame F to the largest
1257 value that will still prevent first_visible_x and last_visible_x of
1258 'struct it' from overflowing an int. */
1260 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1262 ptrdiff_t window_hscroll
= w
->hscroll
;
1263 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1264 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1266 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1267 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1269 return window_hscroll
;
1272 /* Return 1 if position CHARPOS is visible in window W.
1273 CHARPOS < 0 means return info about WINDOW_END position.
1274 If visible, set *X and *Y to pixel coordinates of top left corner.
1275 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1276 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1279 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1280 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1283 void *itdata
= bidi_shelve_cache ();
1284 struct text_pos top
;
1286 struct buffer
*old_buffer
= NULL
;
1288 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1291 if (XBUFFER (WVAR (w
, buffer
)) != current_buffer
)
1293 old_buffer
= current_buffer
;
1294 set_buffer_internal_1 (XBUFFER (WVAR (w
, buffer
)));
1297 SET_TEXT_POS_FROM_MARKER (top
, WVAR (w
, start
));
1298 /* Scrolling a minibuffer window via scroll bar when the echo area
1299 shows long text sometimes resets the minibuffer contents behind
1301 if (CHARPOS (top
) > ZV
)
1302 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1304 /* Compute exact mode line heights. */
1305 if (WINDOW_WANTS_MODELINE_P (w
))
1306 current_mode_line_height
1307 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1308 BVAR (current_buffer
, mode_line_format
));
1310 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1311 current_header_line_height
1312 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1313 BVAR (current_buffer
, header_line_format
));
1315 start_display (&it
, w
, top
);
1316 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1317 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1320 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1321 && IT_CHARPOS (it
) >= charpos
)
1322 /* When scanning backwards under bidi iteration, move_it_to
1323 stops at or _before_ CHARPOS, because it stops at or to
1324 the _right_ of the character at CHARPOS. */
1325 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1326 && IT_CHARPOS (it
) <= charpos
)))
1328 /* We have reached CHARPOS, or passed it. How the call to
1329 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1330 or covered by a display property, move_it_to stops at the end
1331 of the invisible text, to the right of CHARPOS. (ii) If
1332 CHARPOS is in a display vector, move_it_to stops on its last
1334 int top_x
= it
.current_x
;
1335 int top_y
= it
.current_y
;
1336 /* Calling line_bottom_y may change it.method, it.position, etc. */
1337 enum it_method it_method
= it
.method
;
1338 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1339 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1341 if (top_y
< window_top_y
)
1342 visible_p
= bottom_y
> window_top_y
;
1343 else if (top_y
< it
.last_visible_y
)
1345 if (bottom_y
>= it
.last_visible_y
1346 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1347 && IT_CHARPOS (it
) < charpos
)
1349 /* When the last line of the window is scanned backwards
1350 under bidi iteration, we could be duped into thinking
1351 that we have passed CHARPOS, when in fact move_it_to
1352 simply stopped short of CHARPOS because it reached
1353 last_visible_y. To see if that's what happened, we call
1354 move_it_to again with a slightly larger vertical limit,
1355 and see if it actually moved vertically; if it did, we
1356 didn't really reach CHARPOS, which is beyond window end. */
1357 struct it save_it
= it
;
1358 /* Why 10? because we don't know how many canonical lines
1359 will the height of the next line(s) be. So we guess. */
1360 int ten_more_lines
=
1361 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1363 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1364 MOVE_TO_POS
| MOVE_TO_Y
);
1365 if (it
.current_y
> top_y
)
1372 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1374 /* We stopped on the last glyph of a display vector.
1375 Try and recompute. Hack alert! */
1376 if (charpos
< 2 || top
.charpos
>= charpos
)
1377 top_x
= it
.glyph_row
->x
;
1381 start_display (&it2
, w
, top
);
1382 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1383 get_next_display_element (&it2
);
1384 PRODUCE_GLYPHS (&it2
);
1385 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1386 || it2
.current_x
> it2
.last_visible_x
)
1387 top_x
= it
.glyph_row
->x
;
1390 top_x
= it2
.current_x
;
1391 top_y
= it2
.current_y
;
1395 else if (IT_CHARPOS (it
) != charpos
)
1397 Lisp_Object cpos
= make_number (charpos
);
1398 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1399 Lisp_Object string
= string_from_display_spec (spec
);
1400 int newline_in_string
= 0;
1402 if (STRINGP (string
))
1404 const char *s
= SSDATA (string
);
1405 const char *e
= s
+ SBYTES (string
);
1410 newline_in_string
= 1;
1415 /* The tricky code below is needed because there's a
1416 discrepancy between move_it_to and how we set cursor
1417 when the display line ends in a newline from a
1418 display string. move_it_to will stop _after_ such
1419 display strings, whereas set_cursor_from_row
1420 conspires with cursor_row_p to place the cursor on
1421 the first glyph produced from the display string. */
1423 /* We have overshoot PT because it is covered by a
1424 display property whose value is a string. If the
1425 string includes embedded newlines, we are also in the
1426 wrong display line. Backtrack to the correct line,
1427 where the display string begins. */
1428 if (newline_in_string
)
1430 Lisp_Object startpos
, endpos
;
1431 EMACS_INT start
, end
;
1435 /* Find the first and the last buffer positions
1436 covered by the display string. */
1438 Fnext_single_char_property_change (cpos
, Qdisplay
,
1441 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1443 start
= XFASTINT (startpos
);
1444 end
= XFASTINT (endpos
);
1445 /* Move to the last buffer position before the
1446 display property. */
1447 start_display (&it3
, w
, top
);
1448 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1449 /* Move forward one more line if the position before
1450 the display string is a newline or if it is the
1451 rightmost character on a line that is
1452 continued or word-wrapped. */
1453 if (it3
.method
== GET_FROM_BUFFER
1455 move_it_by_lines (&it3
, 1);
1456 else if (move_it_in_display_line_to (&it3
, -1,
1460 == MOVE_LINE_CONTINUED
)
1462 move_it_by_lines (&it3
, 1);
1463 /* When we are under word-wrap, the #$@%!
1464 move_it_by_lines moves 2 lines, so we need to
1466 if (it3
.line_wrap
== WORD_WRAP
)
1467 move_it_by_lines (&it3
, -1);
1470 /* Record the vertical coordinate of the display
1471 line where we wound up. */
1472 top_y
= it3
.current_y
;
1475 /* When characters are reordered for display,
1476 the character displayed to the left of the
1477 display string could be _after_ the display
1478 property in the logical order. Use the
1479 smallest vertical position of these two. */
1480 start_display (&it3
, w
, top
);
1481 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1482 if (it3
.current_y
< top_y
)
1483 top_y
= it3
.current_y
;
1485 /* Move from the top of the window to the beginning
1486 of the display line where the display string
1488 start_display (&it3
, w
, top
);
1489 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1490 /* If it3_moved stays zero after the 'while' loop
1491 below, that means we already were at a newline
1492 before the loop (e.g., the display string begins
1493 with a newline), so we don't need to (and cannot)
1494 inspect the glyphs of it3.glyph_row, because
1495 PRODUCE_GLYPHS will not produce anything for a
1496 newline, and thus it3.glyph_row stays at its
1497 stale content it got at top of the window. */
1499 /* Finally, advance the iterator until we hit the
1500 first display element whose character position is
1501 CHARPOS, or until the first newline from the
1502 display string, which signals the end of the
1504 while (get_next_display_element (&it3
))
1506 PRODUCE_GLYPHS (&it3
);
1507 if (IT_CHARPOS (it3
) == charpos
1508 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1511 set_iterator_to_next (&it3
, 0);
1513 top_x
= it3
.current_x
- it3
.pixel_width
;
1514 /* Normally, we would exit the above loop because we
1515 found the display element whose character
1516 position is CHARPOS. For the contingency that we
1517 didn't, and stopped at the first newline from the
1518 display string, move back over the glyphs
1519 produced from the string, until we find the
1520 rightmost glyph not from the string. */
1522 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1524 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1525 + it3
.glyph_row
->used
[TEXT_AREA
];
1527 while (EQ ((g
- 1)->object
, string
))
1530 top_x
-= g
->pixel_width
;
1532 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1533 + it3
.glyph_row
->used
[TEXT_AREA
]);
1539 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1540 *rtop
= max (0, window_top_y
- top_y
);
1541 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1542 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1543 - max (top_y
, window_top_y
)));
1549 /* We were asked to provide info about WINDOW_END. */
1551 void *it2data
= NULL
;
1553 SAVE_IT (it2
, it
, it2data
);
1554 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1555 move_it_by_lines (&it
, 1);
1556 if (charpos
< IT_CHARPOS (it
)
1557 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1560 RESTORE_IT (&it2
, &it2
, it2data
);
1561 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1563 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1564 *rtop
= max (0, -it2
.current_y
);
1565 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1566 - it
.last_visible_y
));
1567 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1569 - max (it2
.current_y
,
1570 WINDOW_HEADER_LINE_HEIGHT (w
))));
1574 bidi_unshelve_cache (it2data
, 1);
1576 bidi_unshelve_cache (itdata
, 0);
1579 set_buffer_internal_1 (old_buffer
);
1581 current_header_line_height
= current_mode_line_height
= -1;
1583 if (visible_p
&& w
->hscroll
> 0)
1585 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1586 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1589 /* Debugging code. */
1591 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1592 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1594 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1601 /* Return the next character from STR. Return in *LEN the length of
1602 the character. This is like STRING_CHAR_AND_LENGTH but never
1603 returns an invalid character. If we find one, we return a `?', but
1604 with the length of the invalid character. */
1607 string_char_and_length (const unsigned char *str
, int *len
)
1611 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1612 if (!CHAR_VALID_P (c
))
1613 /* We may not change the length here because other places in Emacs
1614 don't use this function, i.e. they silently accept invalid
1623 /* Given a position POS containing a valid character and byte position
1624 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1626 static struct text_pos
1627 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1629 eassert (STRINGP (string
) && nchars
>= 0);
1631 if (STRING_MULTIBYTE (string
))
1633 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1638 string_char_and_length (p
, &len
);
1641 BYTEPOS (pos
) += len
;
1645 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1651 /* Value is the text position, i.e. character and byte position,
1652 for character position CHARPOS in STRING. */
1654 static inline struct text_pos
1655 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1657 struct text_pos pos
;
1658 eassert (STRINGP (string
));
1659 eassert (charpos
>= 0);
1660 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1665 /* Value is a text position, i.e. character and byte position, for
1666 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1667 means recognize multibyte characters. */
1669 static struct text_pos
1670 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1672 struct text_pos pos
;
1674 eassert (s
!= NULL
);
1675 eassert (charpos
>= 0);
1681 SET_TEXT_POS (pos
, 0, 0);
1684 string_char_and_length ((const unsigned char *) s
, &len
);
1687 BYTEPOS (pos
) += len
;
1691 SET_TEXT_POS (pos
, charpos
, charpos
);
1697 /* Value is the number of characters in C string S. MULTIBYTE_P
1698 non-zero means recognize multibyte characters. */
1701 number_of_chars (const char *s
, int multibyte_p
)
1707 ptrdiff_t rest
= strlen (s
);
1709 const unsigned char *p
= (const unsigned char *) s
;
1711 for (nchars
= 0; rest
> 0; ++nchars
)
1713 string_char_and_length (p
, &len
);
1714 rest
-= len
, p
+= len
;
1718 nchars
= strlen (s
);
1724 /* Compute byte position NEWPOS->bytepos corresponding to
1725 NEWPOS->charpos. POS is a known position in string STRING.
1726 NEWPOS->charpos must be >= POS.charpos. */
1729 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1731 eassert (STRINGP (string
));
1732 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1734 if (STRING_MULTIBYTE (string
))
1735 *newpos
= string_pos_nchars_ahead (pos
, string
,
1736 CHARPOS (*newpos
) - CHARPOS (pos
));
1738 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1742 Return an estimation of the pixel height of mode or header lines on
1743 frame F. FACE_ID specifies what line's height to estimate. */
1746 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1748 #ifdef HAVE_WINDOW_SYSTEM
1749 if (FRAME_WINDOW_P (f
))
1751 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1753 /* This function is called so early when Emacs starts that the face
1754 cache and mode line face are not yet initialized. */
1755 if (FRAME_FACE_CACHE (f
))
1757 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1761 height
= FONT_HEIGHT (face
->font
);
1762 if (face
->box_line_width
> 0)
1763 height
+= 2 * face
->box_line_width
;
1774 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1775 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1776 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1777 not force the value into range. */
1780 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1781 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1784 #ifdef HAVE_WINDOW_SYSTEM
1785 if (FRAME_WINDOW_P (f
))
1787 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1788 even for negative values. */
1790 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1792 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1794 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1795 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1798 STORE_NATIVE_RECT (*bounds
,
1799 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1800 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1801 FRAME_COLUMN_WIDTH (f
) - 1,
1802 FRAME_LINE_HEIGHT (f
) - 1);
1808 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1809 pix_x
= FRAME_TOTAL_COLS (f
);
1813 else if (pix_y
> FRAME_LINES (f
))
1814 pix_y
= FRAME_LINES (f
);
1824 /* Find the glyph under window-relative coordinates X/Y in window W.
1825 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1826 strings. Return in *HPOS and *VPOS the row and column number of
1827 the glyph found. Return in *AREA the glyph area containing X.
1828 Value is a pointer to the glyph found or null if X/Y is not on
1829 text, or we can't tell because W's current matrix is not up to
1834 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1835 int *dx
, int *dy
, int *area
)
1837 struct glyph
*glyph
, *end
;
1838 struct glyph_row
*row
= NULL
;
1841 /* Find row containing Y. Give up if some row is not enabled. */
1842 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1844 row
= MATRIX_ROW (w
->current_matrix
, i
);
1845 if (!row
->enabled_p
)
1847 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1854 /* Give up if Y is not in the window. */
1855 if (i
== w
->current_matrix
->nrows
)
1858 /* Get the glyph area containing X. */
1859 if (w
->pseudo_window_p
)
1866 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1868 *area
= LEFT_MARGIN_AREA
;
1869 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1871 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1874 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1878 *area
= RIGHT_MARGIN_AREA
;
1879 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1883 /* Find glyph containing X. */
1884 glyph
= row
->glyphs
[*area
];
1885 end
= glyph
+ row
->used
[*area
];
1887 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1889 x
-= glyph
->pixel_width
;
1899 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1902 *hpos
= glyph
- row
->glyphs
[*area
];
1906 /* Convert frame-relative x/y to coordinates relative to window W.
1907 Takes pseudo-windows into account. */
1910 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1912 if (w
->pseudo_window_p
)
1914 /* A pseudo-window is always full-width, and starts at the
1915 left edge of the frame, plus a frame border. */
1916 struct frame
*f
= XFRAME (WVAR (w
, frame
));
1917 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1918 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1922 *x
-= WINDOW_LEFT_EDGE_X (w
);
1923 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1927 #ifdef HAVE_WINDOW_SYSTEM
1930 Return in RECTS[] at most N clipping rectangles for glyph string S.
1931 Return the number of stored rectangles. */
1934 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1941 if (s
->row
->full_width_p
)
1943 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1944 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1945 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1947 /* Unless displaying a mode or menu bar line, which are always
1948 fully visible, clip to the visible part of the row. */
1949 if (s
->w
->pseudo_window_p
)
1950 r
.height
= s
->row
->visible_height
;
1952 r
.height
= s
->height
;
1956 /* This is a text line that may be partially visible. */
1957 r
.x
= window_box_left (s
->w
, s
->area
);
1958 r
.width
= window_box_width (s
->w
, s
->area
);
1959 r
.height
= s
->row
->visible_height
;
1963 if (r
.x
< s
->clip_head
->x
)
1965 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1966 r
.width
-= s
->clip_head
->x
- r
.x
;
1969 r
.x
= s
->clip_head
->x
;
1972 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1974 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1975 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1980 /* If S draws overlapping rows, it's sufficient to use the top and
1981 bottom of the window for clipping because this glyph string
1982 intentionally draws over other lines. */
1983 if (s
->for_overlaps
)
1985 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1986 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1988 /* Alas, the above simple strategy does not work for the
1989 environments with anti-aliased text: if the same text is
1990 drawn onto the same place multiple times, it gets thicker.
1991 If the overlap we are processing is for the erased cursor, we
1992 take the intersection with the rectangle of the cursor. */
1993 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1995 XRectangle rc
, r_save
= r
;
1997 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1998 rc
.y
= s
->w
->phys_cursor
.y
;
1999 rc
.width
= s
->w
->phys_cursor_width
;
2000 rc
.height
= s
->w
->phys_cursor_height
;
2002 x_intersect_rectangles (&r_save
, &rc
, &r
);
2007 /* Don't use S->y for clipping because it doesn't take partially
2008 visible lines into account. For example, it can be negative for
2009 partially visible lines at the top of a window. */
2010 if (!s
->row
->full_width_p
2011 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2012 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2014 r
.y
= max (0, s
->row
->y
);
2017 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2019 /* If drawing the cursor, don't let glyph draw outside its
2020 advertised boundaries. Cleartype does this under some circumstances. */
2021 if (s
->hl
== DRAW_CURSOR
)
2023 struct glyph
*glyph
= s
->first_glyph
;
2028 r
.width
-= s
->x
- r
.x
;
2031 r
.width
= min (r
.width
, glyph
->pixel_width
);
2033 /* If r.y is below window bottom, ensure that we still see a cursor. */
2034 height
= min (glyph
->ascent
+ glyph
->descent
,
2035 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2036 max_y
= window_text_bottom_y (s
->w
) - height
;
2037 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2038 if (s
->ybase
- glyph
->ascent
> max_y
)
2045 /* Don't draw cursor glyph taller than our actual glyph. */
2046 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2047 if (height
< r
.height
)
2049 max_y
= r
.y
+ r
.height
;
2050 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2051 r
.height
= min (max_y
- r
.y
, height
);
2058 XRectangle r_save
= r
;
2060 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2064 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2065 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2067 #ifdef CONVERT_FROM_XRECT
2068 CONVERT_FROM_XRECT (r
, *rects
);
2076 /* If we are processing overlapping and allowed to return
2077 multiple clipping rectangles, we exclude the row of the glyph
2078 string from the clipping rectangle. This is to avoid drawing
2079 the same text on the environment with anti-aliasing. */
2080 #ifdef CONVERT_FROM_XRECT
2083 XRectangle
*rs
= rects
;
2085 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2087 if (s
->for_overlaps
& OVERLAPS_PRED
)
2090 if (r
.y
+ r
.height
> row_y
)
2093 rs
[i
].height
= row_y
- r
.y
;
2099 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2102 if (r
.y
< row_y
+ s
->row
->visible_height
)
2104 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2106 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2107 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2116 #ifdef CONVERT_FROM_XRECT
2117 for (i
= 0; i
< n
; i
++)
2118 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2125 Return in *NR the clipping rectangle for glyph string S. */
2128 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2130 get_glyph_string_clip_rects (s
, nr
, 1);
2135 Return the position and height of the phys cursor in window W.
2136 Set w->phys_cursor_width to width of phys cursor.
2140 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2141 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2143 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2144 int x
, y
, wd
, h
, h0
, y0
;
2146 /* Compute the width of the rectangle to draw. If on a stretch
2147 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2148 rectangle as wide as the glyph, but use a canonical character
2150 wd
= glyph
->pixel_width
- 1;
2151 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2155 x
= w
->phys_cursor
.x
;
2162 if (glyph
->type
== STRETCH_GLYPH
2163 && !x_stretch_cursor_p
)
2164 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2165 w
->phys_cursor_width
= wd
;
2167 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2169 /* If y is below window bottom, ensure that we still see a cursor. */
2170 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2172 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2173 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2175 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2178 h
= max (h
- (y0
- y
) + 1, h0
);
2183 y0
= window_text_bottom_y (w
) - h0
;
2191 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2192 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2197 * Remember which glyph the mouse is over.
2201 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2205 struct glyph_row
*r
, *gr
, *end_row
;
2206 enum window_part part
;
2207 enum glyph_row_area area
;
2208 int x
, y
, width
, height
;
2210 /* Try to determine frame pixel position and size of the glyph under
2211 frame pixel coordinates X/Y on frame F. */
2213 if (!f
->glyphs_initialized_p
2214 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2217 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2218 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2222 w
= XWINDOW (window
);
2223 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2224 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2226 x
= window_relative_x_coord (w
, part
, gx
);
2227 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2229 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2230 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2232 if (w
->pseudo_window_p
)
2235 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2241 case ON_LEFT_MARGIN
:
2242 area
= LEFT_MARGIN_AREA
;
2245 case ON_RIGHT_MARGIN
:
2246 area
= RIGHT_MARGIN_AREA
;
2249 case ON_HEADER_LINE
:
2251 gr
= (part
== ON_HEADER_LINE
2252 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2253 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2256 goto text_glyph_row_found
;
2263 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2264 if (r
->y
+ r
->height
> y
)
2270 text_glyph_row_found
:
2273 struct glyph
*g
= gr
->glyphs
[area
];
2274 struct glyph
*end
= g
+ gr
->used
[area
];
2276 height
= gr
->height
;
2277 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2278 if (gx
+ g
->pixel_width
> x
)
2283 if (g
->type
== IMAGE_GLYPH
)
2285 /* Don't remember when mouse is over image, as
2286 image may have hot-spots. */
2287 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2290 width
= g
->pixel_width
;
2294 /* Use nominal char spacing at end of line. */
2296 gx
+= (x
/ width
) * width
;
2299 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2300 gx
+= window_box_left_offset (w
, area
);
2304 /* Use nominal line height at end of window. */
2305 gx
= (x
/ width
) * width
;
2307 gy
+= (y
/ height
) * height
;
2311 case ON_LEFT_FRINGE
:
2312 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2313 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2314 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2315 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2318 case ON_RIGHT_FRINGE
:
2319 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2320 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2321 : window_box_right_offset (w
, TEXT_AREA
));
2322 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2326 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2328 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2329 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2330 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2332 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2336 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2337 if (r
->y
+ r
->height
> y
)
2344 height
= gr
->height
;
2347 /* Use nominal line height at end of window. */
2349 gy
+= (y
/ height
) * height
;
2356 /* If there is no glyph under the mouse, then we divide the screen
2357 into a grid of the smallest glyph in the frame, and use that
2360 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2361 round down even for negative values. */
2367 gx
= (gx
/ width
) * width
;
2368 gy
= (gy
/ height
) * height
;
2373 gx
+= WINDOW_LEFT_EDGE_X (w
);
2374 gy
+= WINDOW_TOP_EDGE_Y (w
);
2377 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2379 /* Visible feedback for debugging. */
2382 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2383 f
->output_data
.x
->normal_gc
,
2384 gx
, gy
, width
, height
);
2390 #endif /* HAVE_WINDOW_SYSTEM */
2393 /***********************************************************************
2394 Lisp form evaluation
2395 ***********************************************************************/
2397 /* Error handler for safe_eval and safe_call. */
2400 safe_eval_handler (Lisp_Object arg
)
2402 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2406 /* Call function FUNC with the rest of NARGS - 1 arguments
2407 following. Return the result, or nil if something went
2408 wrong. Prevent redisplay during the evaluation. */
2411 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2415 if (inhibit_eval_during_redisplay
)
2421 ptrdiff_t count
= SPECPDL_INDEX ();
2422 struct gcpro gcpro1
;
2423 Lisp_Object
*args
= alloca (nargs
* sizeof (Lisp_Object
));
2426 va_start (ap
, func
);
2427 for (i
= 1; i
< nargs
; i
++)
2428 args
[i
] = va_arg (ap
, Lisp_Object
);
2432 gcpro1
.nvars
= nargs
;
2433 specbind (Qinhibit_redisplay
, Qt
);
2434 /* Use Qt to ensure debugger does not run,
2435 so there is no possibility of wanting to redisplay. */
2436 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2439 val
= unbind_to (count
, val
);
2446 /* Call function FN with one argument ARG.
2447 Return the result, or nil if something went wrong. */
2450 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2452 return safe_call (2, fn
, arg
);
2455 static Lisp_Object Qeval
;
2458 safe_eval (Lisp_Object sexpr
)
2460 return safe_call1 (Qeval
, sexpr
);
2463 /* Call function FN with two arguments ARG1 and ARG2.
2464 Return the result, or nil if something went wrong. */
2467 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2469 return safe_call (3, fn
, arg1
, arg2
);
2474 /***********************************************************************
2476 ***********************************************************************/
2480 /* Define CHECK_IT to perform sanity checks on iterators.
2481 This is for debugging. It is too slow to do unconditionally. */
2484 check_it (struct it
*it
)
2486 if (it
->method
== GET_FROM_STRING
)
2488 eassert (STRINGP (it
->string
));
2489 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2493 eassert (IT_STRING_CHARPOS (*it
) < 0);
2494 if (it
->method
== GET_FROM_BUFFER
)
2496 /* Check that character and byte positions agree. */
2497 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2502 eassert (it
->current
.dpvec_index
>= 0);
2504 eassert (it
->current
.dpvec_index
< 0);
2507 #define CHECK_IT(IT) check_it ((IT))
2511 #define CHECK_IT(IT) (void) 0
2516 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2518 /* Check that the window end of window W is what we expect it
2519 to be---the last row in the current matrix displaying text. */
2522 check_window_end (struct window
*w
)
2524 if (!MINI_WINDOW_P (w
)
2525 && !NILP (WVAR (w
, window_end_valid
)))
2527 struct glyph_row
*row
;
2528 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2529 XFASTINT (WVAR (w
, window_end_vpos
))),
2531 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2532 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2536 #define CHECK_WINDOW_END(W) check_window_end ((W))
2540 #define CHECK_WINDOW_END(W) (void) 0
2542 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2546 /***********************************************************************
2547 Iterator initialization
2548 ***********************************************************************/
2550 /* Initialize IT for displaying current_buffer in window W, starting
2551 at character position CHARPOS. CHARPOS < 0 means that no buffer
2552 position is specified which is useful when the iterator is assigned
2553 a position later. BYTEPOS is the byte position corresponding to
2554 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2556 If ROW is not null, calls to produce_glyphs with IT as parameter
2557 will produce glyphs in that row.
2559 BASE_FACE_ID is the id of a base face to use. It must be one of
2560 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2561 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2562 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2564 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2565 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2566 will be initialized to use the corresponding mode line glyph row of
2567 the desired matrix of W. */
2570 init_iterator (struct it
*it
, struct window
*w
,
2571 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2572 struct glyph_row
*row
, enum face_id base_face_id
)
2574 int highlight_region_p
;
2575 enum face_id remapped_base_face_id
= base_face_id
;
2577 /* Some precondition checks. */
2578 eassert (w
!= NULL
&& it
!= NULL
);
2579 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2582 /* If face attributes have been changed since the last redisplay,
2583 free realized faces now because they depend on face definitions
2584 that might have changed. Don't free faces while there might be
2585 desired matrices pending which reference these faces. */
2586 if (face_change_count
&& !inhibit_free_realized_faces
)
2588 face_change_count
= 0;
2589 free_all_realized_faces (Qnil
);
2592 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2593 if (! NILP (Vface_remapping_alist
))
2594 remapped_base_face_id
2595 = lookup_basic_face (XFRAME (WVAR (w
, frame
)), base_face_id
);
2597 /* Use one of the mode line rows of W's desired matrix if
2601 if (base_face_id
== MODE_LINE_FACE_ID
2602 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2603 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2604 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2605 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2609 memset (it
, 0, sizeof *it
);
2610 it
->current
.overlay_string_index
= -1;
2611 it
->current
.dpvec_index
= -1;
2612 it
->base_face_id
= remapped_base_face_id
;
2614 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2615 it
->paragraph_embedding
= L2R
;
2616 it
->bidi_it
.string
.lstring
= Qnil
;
2617 it
->bidi_it
.string
.s
= NULL
;
2618 it
->bidi_it
.string
.bufpos
= 0;
2620 /* The window in which we iterate over current_buffer: */
2621 XSETWINDOW (it
->window
, w
);
2623 it
->f
= XFRAME (WVAR (w
, frame
));
2627 /* Extra space between lines (on window systems only). */
2628 if (base_face_id
== DEFAULT_FACE_ID
2629 && FRAME_WINDOW_P (it
->f
))
2631 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2632 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2633 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2634 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2635 * FRAME_LINE_HEIGHT (it
->f
));
2636 else if (it
->f
->extra_line_spacing
> 0)
2637 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2638 it
->max_extra_line_spacing
= 0;
2641 /* If realized faces have been removed, e.g. because of face
2642 attribute changes of named faces, recompute them. When running
2643 in batch mode, the face cache of the initial frame is null. If
2644 we happen to get called, make a dummy face cache. */
2645 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2646 init_frame_faces (it
->f
);
2647 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2648 recompute_basic_faces (it
->f
);
2650 /* Current value of the `slice', `space-width', and 'height' properties. */
2651 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2652 it
->space_width
= Qnil
;
2653 it
->font_height
= Qnil
;
2654 it
->override_ascent
= -1;
2656 /* Are control characters displayed as `^C'? */
2657 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2659 /* -1 means everything between a CR and the following line end
2660 is invisible. >0 means lines indented more than this value are
2662 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2664 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2666 : (!NILP (BVAR (current_buffer
, selective_display
))
2668 it
->selective_display_ellipsis_p
2669 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2671 /* Display table to use. */
2672 it
->dp
= window_display_table (w
);
2674 /* Are multibyte characters enabled in current_buffer? */
2675 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2677 /* Non-zero if we should highlight the region. */
2679 = (!NILP (Vtransient_mark_mode
)
2680 && !NILP (BVAR (current_buffer
, mark_active
))
2681 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2683 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2684 start and end of a visible region in window IT->w. Set both to
2685 -1 to indicate no region. */
2686 if (highlight_region_p
2687 /* Maybe highlight only in selected window. */
2688 && (/* Either show region everywhere. */
2689 highlight_nonselected_windows
2690 /* Or show region in the selected window. */
2691 || w
== XWINDOW (selected_window
)
2692 /* Or show the region if we are in the mini-buffer and W is
2693 the window the mini-buffer refers to. */
2694 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2695 && WINDOWP (minibuf_selected_window
)
2696 && w
== XWINDOW (minibuf_selected_window
))))
2698 ptrdiff_t markpos
= marker_position (BVAR (current_buffer
, mark
));
2699 it
->region_beg_charpos
= min (PT
, markpos
);
2700 it
->region_end_charpos
= max (PT
, markpos
);
2703 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2705 /* Get the position at which the redisplay_end_trigger hook should
2706 be run, if it is to be run at all. */
2707 if (MARKERP (WVAR (w
, redisplay_end_trigger
))
2708 && XMARKER (WVAR (w
, redisplay_end_trigger
))->buffer
!= 0)
2709 it
->redisplay_end_trigger_charpos
2710 = marker_position (WVAR (w
, redisplay_end_trigger
));
2711 else if (INTEGERP (WVAR (w
, redisplay_end_trigger
)))
2712 it
->redisplay_end_trigger_charpos
=
2713 clip_to_bounds (PTRDIFF_MIN
, XINT (WVAR (w
, redisplay_end_trigger
)), PTRDIFF_MAX
);
2715 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2717 /* Are lines in the display truncated? */
2718 if (base_face_id
!= DEFAULT_FACE_ID
2720 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2721 && ((!NILP (Vtruncate_partial_width_windows
)
2722 && !INTEGERP (Vtruncate_partial_width_windows
))
2723 || (INTEGERP (Vtruncate_partial_width_windows
)
2724 && (WINDOW_TOTAL_COLS (it
->w
)
2725 < XINT (Vtruncate_partial_width_windows
))))))
2726 it
->line_wrap
= TRUNCATE
;
2727 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2728 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2729 ? WINDOW_WRAP
: WORD_WRAP
;
2731 it
->line_wrap
= TRUNCATE
;
2733 /* Get dimensions of truncation and continuation glyphs. These are
2734 displayed as fringe bitmaps under X, but we need them for such
2735 frames when the fringes are turned off. But leave the dimensions
2736 zero for tooltip frames, as these glyphs look ugly there and also
2737 sabotage calculations of tooltip dimensions in x-show-tip. */
2738 #ifdef HAVE_WINDOW_SYSTEM
2739 if (!(FRAME_WINDOW_P (it
->f
)
2740 && FRAMEP (tip_frame
)
2741 && it
->f
== XFRAME (tip_frame
)))
2744 if (it
->line_wrap
== TRUNCATE
)
2746 /* We will need the truncation glyph. */
2747 eassert (it
->glyph_row
== NULL
);
2748 produce_special_glyphs (it
, IT_TRUNCATION
);
2749 it
->truncation_pixel_width
= it
->pixel_width
;
2753 /* We will need the continuation glyph. */
2754 eassert (it
->glyph_row
== NULL
);
2755 produce_special_glyphs (it
, IT_CONTINUATION
);
2756 it
->continuation_pixel_width
= it
->pixel_width
;
2760 /* Reset these values to zero because the produce_special_glyphs
2761 above has changed them. */
2762 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2763 it
->phys_ascent
= it
->phys_descent
= 0;
2765 /* Set this after getting the dimensions of truncation and
2766 continuation glyphs, so that we don't produce glyphs when calling
2767 produce_special_glyphs, above. */
2768 it
->glyph_row
= row
;
2769 it
->area
= TEXT_AREA
;
2771 /* Forget any previous info about this row being reversed. */
2773 it
->glyph_row
->reversed_p
= 0;
2775 /* Get the dimensions of the display area. The display area
2776 consists of the visible window area plus a horizontally scrolled
2777 part to the left of the window. All x-values are relative to the
2778 start of this total display area. */
2779 if (base_face_id
!= DEFAULT_FACE_ID
)
2781 /* Mode lines, menu bar in terminal frames. */
2782 it
->first_visible_x
= 0;
2783 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2787 it
->first_visible_x
=
2788 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2789 it
->last_visible_x
= (it
->first_visible_x
2790 + window_box_width (w
, TEXT_AREA
));
2792 /* If we truncate lines, leave room for the truncation glyph(s) at
2793 the right margin. Otherwise, leave room for the continuation
2794 glyph(s). Done only if the window has no fringes. Since we
2795 don't know at this point whether there will be any R2L lines in
2796 the window, we reserve space for truncation/continuation glyphs
2797 even if only one of the fringes is absent. */
2798 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2799 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2801 if (it
->line_wrap
== TRUNCATE
)
2802 it
->last_visible_x
-= it
->truncation_pixel_width
;
2804 it
->last_visible_x
-= it
->continuation_pixel_width
;
2807 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2808 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2811 /* Leave room for a border glyph. */
2812 if (!FRAME_WINDOW_P (it
->f
)
2813 && !WINDOW_RIGHTMOST_P (it
->w
))
2814 it
->last_visible_x
-= 1;
2816 it
->last_visible_y
= window_text_bottom_y (w
);
2818 /* For mode lines and alike, arrange for the first glyph having a
2819 left box line if the face specifies a box. */
2820 if (base_face_id
!= DEFAULT_FACE_ID
)
2824 it
->face_id
= remapped_base_face_id
;
2826 /* If we have a boxed mode line, make the first character appear
2827 with a left box line. */
2828 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2829 if (face
->box
!= FACE_NO_BOX
)
2830 it
->start_of_box_run_p
= 1;
2833 /* If a buffer position was specified, set the iterator there,
2834 getting overlays and face properties from that position. */
2835 if (charpos
>= BUF_BEG (current_buffer
))
2837 it
->end_charpos
= ZV
;
2838 IT_CHARPOS (*it
) = charpos
;
2840 /* We will rely on `reseat' to set this up properly, via
2841 handle_face_prop. */
2842 it
->face_id
= it
->base_face_id
;
2844 /* Compute byte position if not specified. */
2845 if (bytepos
< charpos
)
2846 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2848 IT_BYTEPOS (*it
) = bytepos
;
2850 it
->start
= it
->current
;
2851 /* Do we need to reorder bidirectional text? Not if this is a
2852 unibyte buffer: by definition, none of the single-byte
2853 characters are strong R2L, so no reordering is needed. And
2854 bidi.c doesn't support unibyte buffers anyway. Also, don't
2855 reorder while we are loading loadup.el, since the tables of
2856 character properties needed for reordering are not yet
2860 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2863 /* If we are to reorder bidirectional text, init the bidi
2867 /* Note the paragraph direction that this buffer wants to
2869 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2871 it
->paragraph_embedding
= L2R
;
2872 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2874 it
->paragraph_embedding
= R2L
;
2876 it
->paragraph_embedding
= NEUTRAL_DIR
;
2877 bidi_unshelve_cache (NULL
, 0);
2878 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2882 /* Compute faces etc. */
2883 reseat (it
, it
->current
.pos
, 1);
2890 /* Initialize IT for the display of window W with window start POS. */
2893 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2895 struct glyph_row
*row
;
2896 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2898 row
= w
->desired_matrix
->rows
+ first_vpos
;
2899 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2900 it
->first_vpos
= first_vpos
;
2902 /* Don't reseat to previous visible line start if current start
2903 position is in a string or image. */
2904 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2906 int start_at_line_beg_p
;
2907 int first_y
= it
->current_y
;
2909 /* If window start is not at a line start, skip forward to POS to
2910 get the correct continuation lines width. */
2911 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2912 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2913 if (!start_at_line_beg_p
)
2917 reseat_at_previous_visible_line_start (it
);
2918 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2920 new_x
= it
->current_x
+ it
->pixel_width
;
2922 /* If lines are continued, this line may end in the middle
2923 of a multi-glyph character (e.g. a control character
2924 displayed as \003, or in the middle of an overlay
2925 string). In this case move_it_to above will not have
2926 taken us to the start of the continuation line but to the
2927 end of the continued line. */
2928 if (it
->current_x
> 0
2929 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2930 && (/* And glyph doesn't fit on the line. */
2931 new_x
> it
->last_visible_x
2932 /* Or it fits exactly and we're on a window
2934 || (new_x
== it
->last_visible_x
2935 && FRAME_WINDOW_P (it
->f
)
2936 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2937 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2938 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2940 if ((it
->current
.dpvec_index
>= 0
2941 || it
->current
.overlay_string_index
>= 0)
2942 /* If we are on a newline from a display vector or
2943 overlay string, then we are already at the end of
2944 a screen line; no need to go to the next line in
2945 that case, as this line is not really continued.
2946 (If we do go to the next line, C-e will not DTRT.) */
2949 set_iterator_to_next (it
, 1);
2950 move_it_in_display_line_to (it
, -1, -1, 0);
2953 it
->continuation_lines_width
+= it
->current_x
;
2955 /* If the character at POS is displayed via a display
2956 vector, move_it_to above stops at the final glyph of
2957 IT->dpvec. To make the caller redisplay that character
2958 again (a.k.a. start at POS), we need to reset the
2959 dpvec_index to the beginning of IT->dpvec. */
2960 else if (it
->current
.dpvec_index
>= 0)
2961 it
->current
.dpvec_index
= 0;
2963 /* We're starting a new display line, not affected by the
2964 height of the continued line, so clear the appropriate
2965 fields in the iterator structure. */
2966 it
->max_ascent
= it
->max_descent
= 0;
2967 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2969 it
->current_y
= first_y
;
2971 it
->current_x
= it
->hpos
= 0;
2977 /* Return 1 if POS is a position in ellipses displayed for invisible
2978 text. W is the window we display, for text property lookup. */
2981 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2983 Lisp_Object prop
, window
;
2985 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2987 /* If POS specifies a position in a display vector, this might
2988 be for an ellipsis displayed for invisible text. We won't
2989 get the iterator set up for delivering that ellipsis unless
2990 we make sure that it gets aware of the invisible text. */
2991 if (pos
->dpvec_index
>= 0
2992 && pos
->overlay_string_index
< 0
2993 && CHARPOS (pos
->string_pos
) < 0
2995 && (XSETWINDOW (window
, w
),
2996 prop
= Fget_char_property (make_number (charpos
),
2997 Qinvisible
, window
),
2998 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3000 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3002 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3009 /* Initialize IT for stepping through current_buffer in window W,
3010 starting at position POS that includes overlay string and display
3011 vector/ control character translation position information. Value
3012 is zero if there are overlay strings with newlines at POS. */
3015 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3017 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3018 int i
, overlay_strings_with_newlines
= 0;
3020 /* If POS specifies a position in a display vector, this might
3021 be for an ellipsis displayed for invisible text. We won't
3022 get the iterator set up for delivering that ellipsis unless
3023 we make sure that it gets aware of the invisible text. */
3024 if (in_ellipses_for_invisible_text_p (pos
, w
))
3030 /* Keep in mind: the call to reseat in init_iterator skips invisible
3031 text, so we might end up at a position different from POS. This
3032 is only a problem when POS is a row start after a newline and an
3033 overlay starts there with an after-string, and the overlay has an
3034 invisible property. Since we don't skip invisible text in
3035 display_line and elsewhere immediately after consuming the
3036 newline before the row start, such a POS will not be in a string,
3037 but the call to init_iterator below will move us to the
3039 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3041 /* This only scans the current chunk -- it should scan all chunks.
3042 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3043 to 16 in 22.1 to make this a lesser problem. */
3044 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3046 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3047 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3049 while (s
< e
&& *s
!= '\n')
3054 overlay_strings_with_newlines
= 1;
3059 /* If position is within an overlay string, set up IT to the right
3061 if (pos
->overlay_string_index
>= 0)
3065 /* If the first overlay string happens to have a `display'
3066 property for an image, the iterator will be set up for that
3067 image, and we have to undo that setup first before we can
3068 correct the overlay string index. */
3069 if (it
->method
== GET_FROM_IMAGE
)
3072 /* We already have the first chunk of overlay strings in
3073 IT->overlay_strings. Load more until the one for
3074 pos->overlay_string_index is in IT->overlay_strings. */
3075 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3077 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3078 it
->current
.overlay_string_index
= 0;
3081 load_overlay_strings (it
, 0);
3082 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3086 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3087 relative_index
= (it
->current
.overlay_string_index
3088 % OVERLAY_STRING_CHUNK_SIZE
);
3089 it
->string
= it
->overlay_strings
[relative_index
];
3090 eassert (STRINGP (it
->string
));
3091 it
->current
.string_pos
= pos
->string_pos
;
3092 it
->method
= GET_FROM_STRING
;
3095 if (CHARPOS (pos
->string_pos
) >= 0)
3097 /* Recorded position is not in an overlay string, but in another
3098 string. This can only be a string from a `display' property.
3099 IT should already be filled with that string. */
3100 it
->current
.string_pos
= pos
->string_pos
;
3101 eassert (STRINGP (it
->string
));
3104 /* Restore position in display vector translations, control
3105 character translations or ellipses. */
3106 if (pos
->dpvec_index
>= 0)
3108 if (it
->dpvec
== NULL
)
3109 get_next_display_element (it
);
3110 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3111 it
->current
.dpvec_index
= pos
->dpvec_index
;
3115 return !overlay_strings_with_newlines
;
3119 /* Initialize IT for stepping through current_buffer in window W
3120 starting at ROW->start. */
3123 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3125 init_from_display_pos (it
, w
, &row
->start
);
3126 it
->start
= row
->start
;
3127 it
->continuation_lines_width
= row
->continuation_lines_width
;
3132 /* Initialize IT for stepping through current_buffer in window W
3133 starting in the line following ROW, i.e. starting at ROW->end.
3134 Value is zero if there are overlay strings with newlines at ROW's
3138 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3142 if (init_from_display_pos (it
, w
, &row
->end
))
3144 if (row
->continued_p
)
3145 it
->continuation_lines_width
3146 = row
->continuation_lines_width
+ row
->pixel_width
;
3157 /***********************************************************************
3159 ***********************************************************************/
3161 /* Called when IT reaches IT->stop_charpos. Handle text property and
3162 overlay changes. Set IT->stop_charpos to the next position where
3166 handle_stop (struct it
*it
)
3168 enum prop_handled handled
;
3169 int handle_overlay_change_p
;
3173 it
->current
.dpvec_index
= -1;
3174 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3175 it
->ignore_overlay_strings_at_pos_p
= 0;
3178 /* Use face of preceding text for ellipsis (if invisible) */
3179 if (it
->selective_display_ellipsis_p
)
3180 it
->saved_face_id
= it
->face_id
;
3184 handled
= HANDLED_NORMALLY
;
3186 /* Call text property handlers. */
3187 for (p
= it_props
; p
->handler
; ++p
)
3189 handled
= p
->handler (it
);
3191 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3193 else if (handled
== HANDLED_RETURN
)
3195 /* We still want to show before and after strings from
3196 overlays even if the actual buffer text is replaced. */
3197 if (!handle_overlay_change_p
3199 /* Don't call get_overlay_strings_1 if we already
3200 have overlay strings loaded, because doing so
3201 will load them again and push the iterator state
3202 onto the stack one more time, which is not
3203 expected by the rest of the code that processes
3205 || (it
->current
.overlay_string_index
< 0
3206 ? !get_overlay_strings_1 (it
, 0, 0)
3210 setup_for_ellipsis (it
, 0);
3211 /* When handling a display spec, we might load an
3212 empty string. In that case, discard it here. We
3213 used to discard it in handle_single_display_spec,
3214 but that causes get_overlay_strings_1, above, to
3215 ignore overlay strings that we must check. */
3216 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3220 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3224 it
->ignore_overlay_strings_at_pos_p
= 1;
3225 it
->string_from_display_prop_p
= 0;
3226 it
->from_disp_prop_p
= 0;
3227 handle_overlay_change_p
= 0;
3229 handled
= HANDLED_RECOMPUTE_PROPS
;
3232 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3233 handle_overlay_change_p
= 0;
3236 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3238 /* Don't check for overlay strings below when set to deliver
3239 characters from a display vector. */
3240 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3241 handle_overlay_change_p
= 0;
3243 /* Handle overlay changes.
3244 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3245 if it finds overlays. */
3246 if (handle_overlay_change_p
)
3247 handled
= handle_overlay_change (it
);
3252 setup_for_ellipsis (it
, 0);
3256 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3258 /* Determine where to stop next. */
3259 if (handled
== HANDLED_NORMALLY
)
3260 compute_stop_pos (it
);
3264 /* Compute IT->stop_charpos from text property and overlay change
3265 information for IT's current position. */
3268 compute_stop_pos (struct it
*it
)
3270 register INTERVAL iv
, next_iv
;
3271 Lisp_Object object
, limit
, position
;
3272 ptrdiff_t charpos
, bytepos
;
3274 if (STRINGP (it
->string
))
3276 /* Strings are usually short, so don't limit the search for
3278 it
->stop_charpos
= it
->end_charpos
;
3279 object
= it
->string
;
3281 charpos
= IT_STRING_CHARPOS (*it
);
3282 bytepos
= IT_STRING_BYTEPOS (*it
);
3288 /* If end_charpos is out of range for some reason, such as a
3289 misbehaving display function, rationalize it (Bug#5984). */
3290 if (it
->end_charpos
> ZV
)
3291 it
->end_charpos
= ZV
;
3292 it
->stop_charpos
= it
->end_charpos
;
3294 /* If next overlay change is in front of the current stop pos
3295 (which is IT->end_charpos), stop there. Note: value of
3296 next_overlay_change is point-max if no overlay change
3298 charpos
= IT_CHARPOS (*it
);
3299 bytepos
= IT_BYTEPOS (*it
);
3300 pos
= next_overlay_change (charpos
);
3301 if (pos
< it
->stop_charpos
)
3302 it
->stop_charpos
= pos
;
3304 /* If showing the region, we have to stop at the region
3305 start or end because the face might change there. */
3306 if (it
->region_beg_charpos
> 0)
3308 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3309 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3310 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3311 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3314 /* Set up variables for computing the stop position from text
3315 property changes. */
3316 XSETBUFFER (object
, current_buffer
);
3317 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3320 /* Get the interval containing IT's position. Value is a null
3321 interval if there isn't such an interval. */
3322 position
= make_number (charpos
);
3323 iv
= validate_interval_range (object
, &position
, &position
, 0);
3324 if (!NULL_INTERVAL_P (iv
))
3326 Lisp_Object values_here
[LAST_PROP_IDX
];
3329 /* Get properties here. */
3330 for (p
= it_props
; p
->handler
; ++p
)
3331 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3333 /* Look for an interval following iv that has different
3335 for (next_iv
= next_interval (iv
);
3336 (!NULL_INTERVAL_P (next_iv
)
3338 || XFASTINT (limit
) > next_iv
->position
));
3339 next_iv
= next_interval (next_iv
))
3341 for (p
= it_props
; p
->handler
; ++p
)
3343 Lisp_Object new_value
;
3345 new_value
= textget (next_iv
->plist
, *p
->name
);
3346 if (!EQ (values_here
[p
->idx
], new_value
))
3354 if (!NULL_INTERVAL_P (next_iv
))
3356 if (INTEGERP (limit
)
3357 && next_iv
->position
>= XFASTINT (limit
))
3358 /* No text property change up to limit. */
3359 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3361 /* Text properties change in next_iv. */
3362 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3366 if (it
->cmp_it
.id
< 0)
3368 ptrdiff_t stoppos
= it
->end_charpos
;
3370 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3372 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3373 stoppos
, it
->string
);
3376 eassert (STRINGP (it
->string
)
3377 || (it
->stop_charpos
>= BEGV
3378 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3382 /* Return the position of the next overlay change after POS in
3383 current_buffer. Value is point-max if no overlay change
3384 follows. This is like `next-overlay-change' but doesn't use
3388 next_overlay_change (ptrdiff_t pos
)
3390 ptrdiff_t i
, noverlays
;
3392 Lisp_Object
*overlays
;
3394 /* Get all overlays at the given position. */
3395 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3397 /* If any of these overlays ends before endpos,
3398 use its ending point instead. */
3399 for (i
= 0; i
< noverlays
; ++i
)
3404 oend
= OVERLAY_END (overlays
[i
]);
3405 oendpos
= OVERLAY_POSITION (oend
);
3406 endpos
= min (endpos
, oendpos
);
3412 /* How many characters forward to search for a display property or
3413 display string. Searching too far forward makes the bidi display
3414 sluggish, especially in small windows. */
3415 #define MAX_DISP_SCAN 250
3417 /* Return the character position of a display string at or after
3418 position specified by POSITION. If no display string exists at or
3419 after POSITION, return ZV. A display string is either an overlay
3420 with `display' property whose value is a string, or a `display'
3421 text property whose value is a string. STRING is data about the
3422 string to iterate; if STRING->lstring is nil, we are iterating a
3423 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3424 on a GUI frame. DISP_PROP is set to zero if we searched
3425 MAX_DISP_SCAN characters forward without finding any display
3426 strings, non-zero otherwise. It is set to 2 if the display string
3427 uses any kind of `(space ...)' spec that will produce a stretch of
3428 white space in the text area. */
3430 compute_display_string_pos (struct text_pos
*position
,
3431 struct bidi_string_data
*string
,
3432 int frame_window_p
, int *disp_prop
)
3434 /* OBJECT = nil means current buffer. */
3435 Lisp_Object object
=
3436 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3437 Lisp_Object pos
, spec
, limpos
;
3438 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3439 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3440 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3441 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3443 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3444 struct text_pos tpos
;
3450 /* We don't support display properties whose values are strings
3451 that have display string properties. */
3452 || string
->from_disp_str
3453 /* C strings cannot have display properties. */
3454 || (string
->s
&& !STRINGP (object
)))
3460 /* If the character at CHARPOS is where the display string begins,
3462 pos
= make_number (charpos
);
3463 if (STRINGP (object
))
3464 bufpos
= string
->bufpos
;
3468 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3470 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3473 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3481 /* Look forward for the first character with a `display' property
3482 that will replace the underlying text when displayed. */
3483 limpos
= make_number (lim
);
3485 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3486 CHARPOS (tpos
) = XFASTINT (pos
);
3487 if (CHARPOS (tpos
) >= lim
)
3492 if (STRINGP (object
))
3493 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3495 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3496 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3497 if (!STRINGP (object
))
3498 bufpos
= CHARPOS (tpos
);
3499 } while (NILP (spec
)
3500 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3501 bufpos
, frame_window_p
)));
3505 return CHARPOS (tpos
);
3508 /* Return the character position of the end of the display string that
3509 started at CHARPOS. If there's no display string at CHARPOS,
3510 return -1. A display string is either an overlay with `display'
3511 property whose value is a string or a `display' text property whose
3512 value is a string. */
3514 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3516 /* OBJECT = nil means current buffer. */
3517 Lisp_Object object
=
3518 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3519 Lisp_Object pos
= make_number (charpos
);
3521 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3523 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3526 /* It could happen that the display property or overlay was removed
3527 since we found it in compute_display_string_pos above. One way
3528 this can happen is if JIT font-lock was called (through
3529 handle_fontified_prop), and jit-lock-functions remove text
3530 properties or overlays from the portion of buffer that includes
3531 CHARPOS. Muse mode is known to do that, for example. In this
3532 case, we return -1 to the caller, to signal that no display
3533 string is actually present at CHARPOS. See bidi_fetch_char for
3534 how this is handled.
3536 An alternative would be to never look for display properties past
3537 it->stop_charpos. But neither compute_display_string_pos nor
3538 bidi_fetch_char that calls it know or care where the next
3540 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3543 /* Look forward for the first character where the `display' property
3545 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3547 return XFASTINT (pos
);
3552 /***********************************************************************
3554 ***********************************************************************/
3556 /* Handle changes in the `fontified' property of the current buffer by
3557 calling hook functions from Qfontification_functions to fontify
3560 static enum prop_handled
3561 handle_fontified_prop (struct it
*it
)
3563 Lisp_Object prop
, pos
;
3564 enum prop_handled handled
= HANDLED_NORMALLY
;
3566 if (!NILP (Vmemory_full
))
3569 /* Get the value of the `fontified' property at IT's current buffer
3570 position. (The `fontified' property doesn't have a special
3571 meaning in strings.) If the value is nil, call functions from
3572 Qfontification_functions. */
3573 if (!STRINGP (it
->string
)
3575 && !NILP (Vfontification_functions
)
3576 && !NILP (Vrun_hooks
)
3577 && (pos
= make_number (IT_CHARPOS (*it
)),
3578 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3579 /* Ignore the special cased nil value always present at EOB since
3580 no amount of fontifying will be able to change it. */
3581 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3583 ptrdiff_t count
= SPECPDL_INDEX ();
3585 struct buffer
*obuf
= current_buffer
;
3586 int begv
= BEGV
, zv
= ZV
;
3587 int old_clip_changed
= current_buffer
->clip_changed
;
3589 val
= Vfontification_functions
;
3590 specbind (Qfontification_functions
, Qnil
);
3592 eassert (it
->end_charpos
== ZV
);
3594 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3595 safe_call1 (val
, pos
);
3598 Lisp_Object fns
, fn
;
3599 struct gcpro gcpro1
, gcpro2
;
3604 for (; CONSP (val
); val
= XCDR (val
))
3610 /* A value of t indicates this hook has a local
3611 binding; it means to run the global binding too.
3612 In a global value, t should not occur. If it
3613 does, we must ignore it to avoid an endless
3615 for (fns
= Fdefault_value (Qfontification_functions
);
3621 safe_call1 (fn
, pos
);
3625 safe_call1 (fn
, pos
);
3631 unbind_to (count
, Qnil
);
3633 /* Fontification functions routinely call `save-restriction'.
3634 Normally, this tags clip_changed, which can confuse redisplay
3635 (see discussion in Bug#6671). Since we don't perform any
3636 special handling of fontification changes in the case where
3637 `save-restriction' isn't called, there's no point doing so in
3638 this case either. So, if the buffer's restrictions are
3639 actually left unchanged, reset clip_changed. */
3640 if (obuf
== current_buffer
)
3642 if (begv
== BEGV
&& zv
== ZV
)
3643 current_buffer
->clip_changed
= old_clip_changed
;
3645 /* There isn't much we can reasonably do to protect against
3646 misbehaving fontification, but here's a fig leaf. */
3647 else if (!NILP (BVAR (obuf
, name
)))
3648 set_buffer_internal_1 (obuf
);
3650 /* The fontification code may have added/removed text.
3651 It could do even a lot worse, but let's at least protect against
3652 the most obvious case where only the text past `pos' gets changed',
3653 as is/was done in grep.el where some escapes sequences are turned
3654 into face properties (bug#7876). */
3655 it
->end_charpos
= ZV
;
3657 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3658 something. This avoids an endless loop if they failed to
3659 fontify the text for which reason ever. */
3660 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3661 handled
= HANDLED_RECOMPUTE_PROPS
;
3669 /***********************************************************************
3671 ***********************************************************************/
3673 /* Set up iterator IT from face properties at its current position.
3674 Called from handle_stop. */
3676 static enum prop_handled
3677 handle_face_prop (struct it
*it
)
3680 ptrdiff_t next_stop
;
3682 if (!STRINGP (it
->string
))
3685 = face_at_buffer_position (it
->w
,
3687 it
->region_beg_charpos
,
3688 it
->region_end_charpos
,
3691 + TEXT_PROP_DISTANCE_LIMIT
),
3692 0, it
->base_face_id
);
3694 /* Is this a start of a run of characters with box face?
3695 Caveat: this can be called for a freshly initialized
3696 iterator; face_id is -1 in this case. We know that the new
3697 face will not change until limit, i.e. if the new face has a
3698 box, all characters up to limit will have one. But, as
3699 usual, we don't know whether limit is really the end. */
3700 if (new_face_id
!= it
->face_id
)
3702 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3704 /* If new face has a box but old face has not, this is
3705 the start of a run of characters with box, i.e. it has
3706 a shadow on the left side. The value of face_id of the
3707 iterator will be -1 if this is the initial call that gets
3708 the face. In this case, we have to look in front of IT's
3709 position and see whether there is a face != new_face_id. */
3710 it
->start_of_box_run_p
3711 = (new_face
->box
!= FACE_NO_BOX
3712 && (it
->face_id
>= 0
3713 || IT_CHARPOS (*it
) == BEG
3714 || new_face_id
!= face_before_it_pos (it
)));
3715 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3723 Lisp_Object from_overlay
3724 = (it
->current
.overlay_string_index
>= 0
3725 ? it
->string_overlays
[it
->current
.overlay_string_index
3726 % OVERLAY_STRING_CHUNK_SIZE
]
3729 /* See if we got to this string directly or indirectly from
3730 an overlay property. That includes the before-string or
3731 after-string of an overlay, strings in display properties
3732 provided by an overlay, their text properties, etc.
3734 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3735 if (! NILP (from_overlay
))
3736 for (i
= it
->sp
- 1; i
>= 0; i
--)
3738 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3740 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3741 % OVERLAY_STRING_CHUNK_SIZE
];
3742 else if (! NILP (it
->stack
[i
].from_overlay
))
3743 from_overlay
= it
->stack
[i
].from_overlay
;
3745 if (!NILP (from_overlay
))
3749 if (! NILP (from_overlay
))
3751 bufpos
= IT_CHARPOS (*it
);
3752 /* For a string from an overlay, the base face depends
3753 only on text properties and ignores overlays. */
3755 = face_for_overlay_string (it
->w
,
3757 it
->region_beg_charpos
,
3758 it
->region_end_charpos
,
3761 + TEXT_PROP_DISTANCE_LIMIT
),
3769 /* For strings from a `display' property, use the face at
3770 IT's current buffer position as the base face to merge
3771 with, so that overlay strings appear in the same face as
3772 surrounding text, unless they specify their own
3774 base_face_id
= it
->string_from_prefix_prop_p
3776 : underlying_face_id (it
);
3779 new_face_id
= face_at_string_position (it
->w
,
3781 IT_STRING_CHARPOS (*it
),
3783 it
->region_beg_charpos
,
3784 it
->region_end_charpos
,
3788 /* Is this a start of a run of characters with box? Caveat:
3789 this can be called for a freshly allocated iterator; face_id
3790 is -1 is this case. We know that the new face will not
3791 change until the next check pos, i.e. if the new face has a
3792 box, all characters up to that position will have a
3793 box. But, as usual, we don't know whether that position
3794 is really the end. */
3795 if (new_face_id
!= it
->face_id
)
3797 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3798 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3800 /* If new face has a box but old face hasn't, this is the
3801 start of a run of characters with box, i.e. it has a
3802 shadow on the left side. */
3803 it
->start_of_box_run_p
3804 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3805 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3809 it
->face_id
= new_face_id
;
3810 return HANDLED_NORMALLY
;
3814 /* Return the ID of the face ``underlying'' IT's current position,
3815 which is in a string. If the iterator is associated with a
3816 buffer, return the face at IT's current buffer position.
3817 Otherwise, use the iterator's base_face_id. */
3820 underlying_face_id (struct it
*it
)
3822 int face_id
= it
->base_face_id
, i
;
3824 eassert (STRINGP (it
->string
));
3826 for (i
= it
->sp
- 1; i
>= 0; --i
)
3827 if (NILP (it
->stack
[i
].string
))
3828 face_id
= it
->stack
[i
].face_id
;
3834 /* Compute the face one character before or after the current position
3835 of IT, in the visual order. BEFORE_P non-zero means get the face
3836 in front (to the left in L2R paragraphs, to the right in R2L
3837 paragraphs) of IT's screen position. Value is the ID of the face. */
3840 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3843 ptrdiff_t next_check_charpos
;
3845 void *it_copy_data
= NULL
;
3847 eassert (it
->s
== NULL
);
3849 if (STRINGP (it
->string
))
3851 ptrdiff_t bufpos
, charpos
;
3854 /* No face change past the end of the string (for the case
3855 we are padding with spaces). No face change before the
3857 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3858 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3863 /* Set charpos to the position before or after IT's current
3864 position, in the logical order, which in the non-bidi
3865 case is the same as the visual order. */
3867 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3868 else if (it
->what
== IT_COMPOSITION
)
3869 /* For composition, we must check the character after the
3871 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3873 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3879 /* With bidi iteration, the character before the current
3880 in the visual order cannot be found by simple
3881 iteration, because "reverse" reordering is not
3882 supported. Instead, we need to use the move_it_*
3883 family of functions. */
3884 /* Ignore face changes before the first visible
3885 character on this display line. */
3886 if (it
->current_x
<= it
->first_visible_x
)
3888 SAVE_IT (it_copy
, *it
, it_copy_data
);
3889 /* Implementation note: Since move_it_in_display_line
3890 works in the iterator geometry, and thinks the first
3891 character is always the leftmost, even in R2L lines,
3892 we don't need to distinguish between the R2L and L2R
3894 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3895 it_copy
.current_x
- 1, MOVE_TO_X
);
3896 charpos
= IT_STRING_CHARPOS (it_copy
);
3897 RESTORE_IT (it
, it
, it_copy_data
);
3901 /* Set charpos to the string position of the character
3902 that comes after IT's current position in the visual
3904 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3908 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3910 charpos
= it_copy
.bidi_it
.charpos
;
3913 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3915 if (it
->current
.overlay_string_index
>= 0)
3916 bufpos
= IT_CHARPOS (*it
);
3920 base_face_id
= underlying_face_id (it
);
3922 /* Get the face for ASCII, or unibyte. */
3923 face_id
= face_at_string_position (it
->w
,
3927 it
->region_beg_charpos
,
3928 it
->region_end_charpos
,
3929 &next_check_charpos
,
3932 /* Correct the face for charsets different from ASCII. Do it
3933 for the multibyte case only. The face returned above is
3934 suitable for unibyte text if IT->string is unibyte. */
3935 if (STRING_MULTIBYTE (it
->string
))
3937 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3938 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3940 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3942 c
= string_char_and_length (p
, &len
);
3943 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3948 struct text_pos pos
;
3950 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3951 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3954 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3955 pos
= it
->current
.pos
;
3960 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3963 if (it
->what
== IT_COMPOSITION
)
3965 /* For composition, we must check the position after
3967 pos
.charpos
+= it
->cmp_it
.nchars
;
3968 pos
.bytepos
+= it
->len
;
3971 INC_TEXT_POS (pos
, it
->multibyte_p
);
3978 /* With bidi iteration, the character before the current
3979 in the visual order cannot be found by simple
3980 iteration, because "reverse" reordering is not
3981 supported. Instead, we need to use the move_it_*
3982 family of functions. */
3983 /* Ignore face changes before the first visible
3984 character on this display line. */
3985 if (it
->current_x
<= it
->first_visible_x
)
3987 SAVE_IT (it_copy
, *it
, it_copy_data
);
3988 /* Implementation note: Since move_it_in_display_line
3989 works in the iterator geometry, and thinks the first
3990 character is always the leftmost, even in R2L lines,
3991 we don't need to distinguish between the R2L and L2R
3993 move_it_in_display_line (&it_copy
, ZV
,
3994 it_copy
.current_x
- 1, MOVE_TO_X
);
3995 pos
= it_copy
.current
.pos
;
3996 RESTORE_IT (it
, it
, it_copy_data
);
4000 /* Set charpos to the buffer position of the character
4001 that comes after IT's current position in the visual
4003 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4007 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4010 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4013 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4015 /* Determine face for CHARSET_ASCII, or unibyte. */
4016 face_id
= face_at_buffer_position (it
->w
,
4018 it
->region_beg_charpos
,
4019 it
->region_end_charpos
,
4020 &next_check_charpos
,
4023 /* Correct the face for charsets different from ASCII. Do it
4024 for the multibyte case only. The face returned above is
4025 suitable for unibyte text if current_buffer is unibyte. */
4026 if (it
->multibyte_p
)
4028 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4029 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4030 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4039 /***********************************************************************
4041 ***********************************************************************/
4043 /* Set up iterator IT from invisible properties at its current
4044 position. Called from handle_stop. */
4046 static enum prop_handled
4047 handle_invisible_prop (struct it
*it
)
4049 enum prop_handled handled
= HANDLED_NORMALLY
;
4051 if (STRINGP (it
->string
))
4053 Lisp_Object prop
, end_charpos
, limit
, charpos
;
4055 /* Get the value of the invisible text property at the
4056 current position. Value will be nil if there is no such
4058 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4059 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4062 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4066 handled
= HANDLED_RECOMPUTE_PROPS
;
4068 /* Get the position at which the next change of the
4069 invisible text property can be found in IT->string.
4070 Value will be nil if the property value is the same for
4071 all the rest of IT->string. */
4072 XSETINT (limit
, SCHARS (it
->string
));
4073 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4076 /* Text at current position is invisible. The next
4077 change in the property is at position end_charpos.
4078 Move IT's current position to that position. */
4079 if (INTEGERP (end_charpos
)
4080 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
4082 struct text_pos old
;
4085 old
= it
->current
.string_pos
;
4086 oldpos
= CHARPOS (old
);
4089 if (it
->bidi_it
.first_elt
4090 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4091 bidi_paragraph_init (it
->paragraph_embedding
,
4093 /* Bidi-iterate out of the invisible text. */
4096 bidi_move_to_visually_next (&it
->bidi_it
);
4098 while (oldpos
<= it
->bidi_it
.charpos
4099 && it
->bidi_it
.charpos
< endpos
);
4101 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4102 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4103 if (IT_CHARPOS (*it
) >= endpos
)
4104 it
->prev_stop
= endpos
;
4108 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4109 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4114 /* The rest of the string is invisible. If this is an
4115 overlay string, proceed with the next overlay string
4116 or whatever comes and return a character from there. */
4117 if (it
->current
.overlay_string_index
>= 0)
4119 next_overlay_string (it
);
4120 /* Don't check for overlay strings when we just
4121 finished processing them. */
4122 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4126 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4127 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4135 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4136 Lisp_Object pos
, prop
, overlay
;
4138 /* First of all, is there invisible text at this position? */
4139 tem
= start_charpos
= IT_CHARPOS (*it
);
4140 pos
= make_number (tem
);
4141 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4143 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4145 /* If we are on invisible text, skip over it. */
4146 if (invis_p
&& start_charpos
< it
->end_charpos
)
4148 /* Record whether we have to display an ellipsis for the
4150 int display_ellipsis_p
= invis_p
== 2;
4152 handled
= HANDLED_RECOMPUTE_PROPS
;
4154 /* Loop skipping over invisible text. The loop is left at
4155 ZV or with IT on the first char being visible again. */
4158 /* Try to skip some invisible text. Return value is the
4159 position reached which can be equal to where we start
4160 if there is nothing invisible there. This skips both
4161 over invisible text properties and overlays with
4162 invisible property. */
4163 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4165 /* If we skipped nothing at all we weren't at invisible
4166 text in the first place. If everything to the end of
4167 the buffer was skipped, end the loop. */
4168 if (newpos
== tem
|| newpos
>= ZV
)
4172 /* We skipped some characters but not necessarily
4173 all there are. Check if we ended up on visible
4174 text. Fget_char_property returns the property of
4175 the char before the given position, i.e. if we
4176 get invis_p = 0, this means that the char at
4177 newpos is visible. */
4178 pos
= make_number (newpos
);
4179 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4180 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4183 /* If we ended up on invisible text, proceed to
4184 skip starting with next_stop. */
4188 /* If there are adjacent invisible texts, don't lose the
4189 second one's ellipsis. */
4191 display_ellipsis_p
= 1;
4195 /* The position newpos is now either ZV or on visible text. */
4198 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4200 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4202 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4204 /* If the invisible text ends on a newline or on a
4205 character after a newline, we can avoid the costly,
4206 character by character, bidi iteration to NEWPOS, and
4207 instead simply reseat the iterator there. That's
4208 because all bidi reordering information is tossed at
4209 the newline. This is a big win for modes that hide
4210 complete lines, like Outline, Org, etc. */
4211 if (on_newline
|| after_newline
)
4213 struct text_pos tpos
;
4214 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4216 SET_TEXT_POS (tpos
, newpos
, bpos
);
4217 reseat_1 (it
, tpos
, 0);
4218 /* If we reseat on a newline/ZV, we need to prep the
4219 bidi iterator for advancing to the next character
4220 after the newline/EOB, keeping the current paragraph
4221 direction (so that PRODUCE_GLYPHS does TRT wrt
4222 prepending/appending glyphs to a glyph row). */
4225 it
->bidi_it
.first_elt
= 0;
4226 it
->bidi_it
.paragraph_dir
= pdir
;
4227 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4228 it
->bidi_it
.nchars
= 1;
4229 it
->bidi_it
.ch_len
= 1;
4232 else /* Must use the slow method. */
4234 /* With bidi iteration, the region of invisible text
4235 could start and/or end in the middle of a
4236 non-base embedding level. Therefore, we need to
4237 skip invisible text using the bidi iterator,
4238 starting at IT's current position, until we find
4239 ourselves outside of the invisible text.
4240 Skipping invisible text _after_ bidi iteration
4241 avoids affecting the visual order of the
4242 displayed text when invisible properties are
4243 added or removed. */
4244 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4246 /* If we were `reseat'ed to a new paragraph,
4247 determine the paragraph base direction. We
4248 need to do it now because
4249 next_element_from_buffer may not have a
4250 chance to do it, if we are going to skip any
4251 text at the beginning, which resets the
4253 bidi_paragraph_init (it
->paragraph_embedding
,
4258 bidi_move_to_visually_next (&it
->bidi_it
);
4260 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4261 && it
->bidi_it
.charpos
< newpos
);
4262 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4263 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4264 /* If we overstepped NEWPOS, record its position in
4265 the iterator, so that we skip invisible text if
4266 later the bidi iteration lands us in the
4267 invisible region again. */
4268 if (IT_CHARPOS (*it
) >= newpos
)
4269 it
->prev_stop
= newpos
;
4274 IT_CHARPOS (*it
) = newpos
;
4275 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4278 /* If there are before-strings at the start of invisible
4279 text, and the text is invisible because of a text
4280 property, arrange to show before-strings because 20.x did
4281 it that way. (If the text is invisible because of an
4282 overlay property instead of a text property, this is
4283 already handled in the overlay code.) */
4285 && get_overlay_strings (it
, it
->stop_charpos
))
4287 handled
= HANDLED_RECOMPUTE_PROPS
;
4288 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4290 else if (display_ellipsis_p
)
4292 /* Make sure that the glyphs of the ellipsis will get
4293 correct `charpos' values. If we would not update
4294 it->position here, the glyphs would belong to the
4295 last visible character _before_ the invisible
4296 text, which confuses `set_cursor_from_row'.
4298 We use the last invisible position instead of the
4299 first because this way the cursor is always drawn on
4300 the first "." of the ellipsis, whenever PT is inside
4301 the invisible text. Otherwise the cursor would be
4302 placed _after_ the ellipsis when the point is after the
4303 first invisible character. */
4304 if (!STRINGP (it
->object
))
4306 it
->position
.charpos
= newpos
- 1;
4307 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4310 /* Let the ellipsis display before
4311 considering any properties of the following char.
4312 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4313 handled
= HANDLED_RETURN
;
4322 /* Make iterator IT return `...' next.
4323 Replaces LEN characters from buffer. */
4326 setup_for_ellipsis (struct it
*it
, int len
)
4328 /* Use the display table definition for `...'. Invalid glyphs
4329 will be handled by the method returning elements from dpvec. */
4330 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4332 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4333 it
->dpvec
= v
->contents
;
4334 it
->dpend
= v
->contents
+ v
->header
.size
;
4338 /* Default `...'. */
4339 it
->dpvec
= default_invis_vector
;
4340 it
->dpend
= default_invis_vector
+ 3;
4343 it
->dpvec_char_len
= len
;
4344 it
->current
.dpvec_index
= 0;
4345 it
->dpvec_face_id
= -1;
4347 /* Remember the current face id in case glyphs specify faces.
4348 IT's face is restored in set_iterator_to_next.
4349 saved_face_id was set to preceding char's face in handle_stop. */
4350 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4351 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4353 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4359 /***********************************************************************
4361 ***********************************************************************/
4363 /* Set up iterator IT from `display' property at its current position.
4364 Called from handle_stop.
4365 We return HANDLED_RETURN if some part of the display property
4366 overrides the display of the buffer text itself.
4367 Otherwise we return HANDLED_NORMALLY. */
4369 static enum prop_handled
4370 handle_display_prop (struct it
*it
)
4372 Lisp_Object propval
, object
, overlay
;
4373 struct text_pos
*position
;
4375 /* Nonzero if some property replaces the display of the text itself. */
4376 int display_replaced_p
= 0;
4378 if (STRINGP (it
->string
))
4380 object
= it
->string
;
4381 position
= &it
->current
.string_pos
;
4382 bufpos
= CHARPOS (it
->current
.pos
);
4386 XSETWINDOW (object
, it
->w
);
4387 position
= &it
->current
.pos
;
4388 bufpos
= CHARPOS (*position
);
4391 /* Reset those iterator values set from display property values. */
4392 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4393 it
->space_width
= Qnil
;
4394 it
->font_height
= Qnil
;
4397 /* We don't support recursive `display' properties, i.e. string
4398 values that have a string `display' property, that have a string
4399 `display' property etc. */
4400 if (!it
->string_from_display_prop_p
)
4401 it
->area
= TEXT_AREA
;
4403 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4404 Qdisplay
, object
, &overlay
);
4406 return HANDLED_NORMALLY
;
4407 /* Now OVERLAY is the overlay that gave us this property, or nil
4408 if it was a text property. */
4410 if (!STRINGP (it
->string
))
4411 object
= WVAR (it
->w
, buffer
);
4413 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4415 FRAME_WINDOW_P (it
->f
));
4417 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4420 /* Subroutine of handle_display_prop. Returns non-zero if the display
4421 specification in SPEC is a replacing specification, i.e. it would
4422 replace the text covered by `display' property with something else,
4423 such as an image or a display string. If SPEC includes any kind or
4424 `(space ...) specification, the value is 2; this is used by
4425 compute_display_string_pos, which see.
4427 See handle_single_display_spec for documentation of arguments.
4428 frame_window_p is non-zero if the window being redisplayed is on a
4429 GUI frame; this argument is used only if IT is NULL, see below.
4431 IT can be NULL, if this is called by the bidi reordering code
4432 through compute_display_string_pos, which see. In that case, this
4433 function only examines SPEC, but does not otherwise "handle" it, in
4434 the sense that it doesn't set up members of IT from the display
4437 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4438 Lisp_Object overlay
, struct text_pos
*position
,
4439 ptrdiff_t bufpos
, int frame_window_p
)
4441 int replacing_p
= 0;
4445 /* Simple specifications. */
4446 && !EQ (XCAR (spec
), Qimage
)
4447 && !EQ (XCAR (spec
), Qspace
)
4448 && !EQ (XCAR (spec
), Qwhen
)
4449 && !EQ (XCAR (spec
), Qslice
)
4450 && !EQ (XCAR (spec
), Qspace_width
)
4451 && !EQ (XCAR (spec
), Qheight
)
4452 && !EQ (XCAR (spec
), Qraise
)
4453 /* Marginal area specifications. */
4454 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4455 && !EQ (XCAR (spec
), Qleft_fringe
)
4456 && !EQ (XCAR (spec
), Qright_fringe
)
4457 && !NILP (XCAR (spec
)))
4459 for (; CONSP (spec
); spec
= XCDR (spec
))
4461 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4462 overlay
, position
, bufpos
,
4463 replacing_p
, frame_window_p
)))
4466 /* If some text in a string is replaced, `position' no
4467 longer points to the position of `object'. */
4468 if (!it
|| STRINGP (object
))
4473 else if (VECTORP (spec
))
4476 for (i
= 0; i
< ASIZE (spec
); ++i
)
4477 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4478 overlay
, position
, bufpos
,
4479 replacing_p
, frame_window_p
)))
4482 /* If some text in a string is replaced, `position' no
4483 longer points to the position of `object'. */
4484 if (!it
|| STRINGP (object
))
4490 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4491 position
, bufpos
, 0,
4499 /* Value is the position of the end of the `display' property starting
4500 at START_POS in OBJECT. */
4502 static struct text_pos
4503 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4506 struct text_pos end_pos
;
4508 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4509 Qdisplay
, object
, Qnil
);
4510 CHARPOS (end_pos
) = XFASTINT (end
);
4511 if (STRINGP (object
))
4512 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4514 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4520 /* Set up IT from a single `display' property specification SPEC. OBJECT
4521 is the object in which the `display' property was found. *POSITION
4522 is the position in OBJECT at which the `display' property was found.
4523 BUFPOS is the buffer position of OBJECT (different from POSITION if
4524 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4525 previously saw a display specification which already replaced text
4526 display with something else, for example an image; we ignore such
4527 properties after the first one has been processed.
4529 OVERLAY is the overlay this `display' property came from,
4530 or nil if it was a text property.
4532 If SPEC is a `space' or `image' specification, and in some other
4533 cases too, set *POSITION to the position where the `display'
4536 If IT is NULL, only examine the property specification in SPEC, but
4537 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4538 is intended to be displayed in a window on a GUI frame.
4540 Value is non-zero if something was found which replaces the display
4541 of buffer or string text. */
4544 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4545 Lisp_Object overlay
, struct text_pos
*position
,
4546 ptrdiff_t bufpos
, int display_replaced_p
,
4550 Lisp_Object location
, value
;
4551 struct text_pos start_pos
= *position
;
4554 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4555 If the result is non-nil, use VALUE instead of SPEC. */
4557 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4566 if (!NILP (form
) && !EQ (form
, Qt
))
4568 ptrdiff_t count
= SPECPDL_INDEX ();
4569 struct gcpro gcpro1
;
4571 /* Bind `object' to the object having the `display' property, a
4572 buffer or string. Bind `position' to the position in the
4573 object where the property was found, and `buffer-position'
4574 to the current position in the buffer. */
4577 XSETBUFFER (object
, current_buffer
);
4578 specbind (Qobject
, object
);
4579 specbind (Qposition
, make_number (CHARPOS (*position
)));
4580 specbind (Qbuffer_position
, make_number (bufpos
));
4582 form
= safe_eval (form
);
4584 unbind_to (count
, Qnil
);
4590 /* Handle `(height HEIGHT)' specifications. */
4592 && EQ (XCAR (spec
), Qheight
)
4593 && CONSP (XCDR (spec
)))
4597 if (!FRAME_WINDOW_P (it
->f
))
4600 it
->font_height
= XCAR (XCDR (spec
));
4601 if (!NILP (it
->font_height
))
4603 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4604 int new_height
= -1;
4606 if (CONSP (it
->font_height
)
4607 && (EQ (XCAR (it
->font_height
), Qplus
)
4608 || EQ (XCAR (it
->font_height
), Qminus
))
4609 && CONSP (XCDR (it
->font_height
))
4610 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4612 /* `(+ N)' or `(- N)' where N is an integer. */
4613 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4614 if (EQ (XCAR (it
->font_height
), Qplus
))
4616 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4618 else if (FUNCTIONP (it
->font_height
))
4620 /* Call function with current height as argument.
4621 Value is the new height. */
4623 height
= safe_call1 (it
->font_height
,
4624 face
->lface
[LFACE_HEIGHT_INDEX
]);
4625 if (NUMBERP (height
))
4626 new_height
= XFLOATINT (height
);
4628 else if (NUMBERP (it
->font_height
))
4630 /* Value is a multiple of the canonical char height. */
4633 f
= FACE_FROM_ID (it
->f
,
4634 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4635 new_height
= (XFLOATINT (it
->font_height
)
4636 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4640 /* Evaluate IT->font_height with `height' bound to the
4641 current specified height to get the new height. */
4642 ptrdiff_t count
= SPECPDL_INDEX ();
4644 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4645 value
= safe_eval (it
->font_height
);
4646 unbind_to (count
, Qnil
);
4648 if (NUMBERP (value
))
4649 new_height
= XFLOATINT (value
);
4653 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4660 /* Handle `(space-width WIDTH)'. */
4662 && EQ (XCAR (spec
), Qspace_width
)
4663 && CONSP (XCDR (spec
)))
4667 if (!FRAME_WINDOW_P (it
->f
))
4670 value
= XCAR (XCDR (spec
));
4671 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4672 it
->space_width
= value
;
4678 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4680 && EQ (XCAR (spec
), Qslice
))
4686 if (!FRAME_WINDOW_P (it
->f
))
4689 if (tem
= XCDR (spec
), CONSP (tem
))
4691 it
->slice
.x
= XCAR (tem
);
4692 if (tem
= XCDR (tem
), CONSP (tem
))
4694 it
->slice
.y
= XCAR (tem
);
4695 if (tem
= XCDR (tem
), CONSP (tem
))
4697 it
->slice
.width
= XCAR (tem
);
4698 if (tem
= XCDR (tem
), CONSP (tem
))
4699 it
->slice
.height
= XCAR (tem
);
4708 /* Handle `(raise FACTOR)'. */
4710 && EQ (XCAR (spec
), Qraise
)
4711 && CONSP (XCDR (spec
)))
4715 if (!FRAME_WINDOW_P (it
->f
))
4718 #ifdef HAVE_WINDOW_SYSTEM
4719 value
= XCAR (XCDR (spec
));
4720 if (NUMBERP (value
))
4722 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4723 it
->voffset
= - (XFLOATINT (value
)
4724 * (FONT_HEIGHT (face
->font
)));
4726 #endif /* HAVE_WINDOW_SYSTEM */
4732 /* Don't handle the other kinds of display specifications
4733 inside a string that we got from a `display' property. */
4734 if (it
&& it
->string_from_display_prop_p
)
4737 /* Characters having this form of property are not displayed, so
4738 we have to find the end of the property. */
4741 start_pos
= *position
;
4742 *position
= display_prop_end (it
, object
, start_pos
);
4746 /* Stop the scan at that end position--we assume that all
4747 text properties change there. */
4749 it
->stop_charpos
= position
->charpos
;
4751 /* Handle `(left-fringe BITMAP [FACE])'
4752 and `(right-fringe BITMAP [FACE])'. */
4754 && (EQ (XCAR (spec
), Qleft_fringe
)
4755 || EQ (XCAR (spec
), Qright_fringe
))
4756 && CONSP (XCDR (spec
)))
4762 if (!FRAME_WINDOW_P (it
->f
))
4763 /* If we return here, POSITION has been advanced
4764 across the text with this property. */
4766 /* Synchronize the bidi iterator with POSITION. This is
4767 needed because we are not going to push the iterator
4768 on behalf of this display property, so there will be
4769 no pop_it call to do this synchronization for us. */
4772 it
->position
= *position
;
4773 iterate_out_of_display_property (it
);
4774 *position
= it
->position
;
4779 else if (!frame_window_p
)
4782 #ifdef HAVE_WINDOW_SYSTEM
4783 value
= XCAR (XCDR (spec
));
4784 if (!SYMBOLP (value
)
4785 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4786 /* If we return here, POSITION has been advanced
4787 across the text with this property. */
4789 if (it
&& it
->bidi_p
)
4791 it
->position
= *position
;
4792 iterate_out_of_display_property (it
);
4793 *position
= it
->position
;
4800 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4802 if (CONSP (XCDR (XCDR (spec
))))
4804 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4805 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4811 /* Save current settings of IT so that we can restore them
4812 when we are finished with the glyph property value. */
4813 push_it (it
, position
);
4815 it
->area
= TEXT_AREA
;
4816 it
->what
= IT_IMAGE
;
4817 it
->image_id
= -1; /* no image */
4818 it
->position
= start_pos
;
4819 it
->object
= NILP (object
) ? WVAR (it
->w
, buffer
) : object
;
4820 it
->method
= GET_FROM_IMAGE
;
4821 it
->from_overlay
= Qnil
;
4822 it
->face_id
= face_id
;
4823 it
->from_disp_prop_p
= 1;
4825 /* Say that we haven't consumed the characters with
4826 `display' property yet. The call to pop_it in
4827 set_iterator_to_next will clean this up. */
4828 *position
= start_pos
;
4830 if (EQ (XCAR (spec
), Qleft_fringe
))
4832 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4833 it
->left_user_fringe_face_id
= face_id
;
4837 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4838 it
->right_user_fringe_face_id
= face_id
;
4841 #endif /* HAVE_WINDOW_SYSTEM */
4845 /* Prepare to handle `((margin left-margin) ...)',
4846 `((margin right-margin) ...)' and `((margin nil) ...)'
4847 prefixes for display specifications. */
4848 location
= Qunbound
;
4849 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4853 value
= XCDR (spec
);
4855 value
= XCAR (value
);
4858 if (EQ (XCAR (tem
), Qmargin
)
4859 && (tem
= XCDR (tem
),
4860 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4862 || EQ (tem
, Qleft_margin
)
4863 || EQ (tem
, Qright_margin
))))
4867 if (EQ (location
, Qunbound
))
4873 /* After this point, VALUE is the property after any
4874 margin prefix has been stripped. It must be a string,
4875 an image specification, or `(space ...)'.
4877 LOCATION specifies where to display: `left-margin',
4878 `right-margin' or nil. */
4880 valid_p
= (STRINGP (value
)
4881 #ifdef HAVE_WINDOW_SYSTEM
4882 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4883 && valid_image_p (value
))
4884 #endif /* not HAVE_WINDOW_SYSTEM */
4885 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4887 if (valid_p
&& !display_replaced_p
)
4893 /* Callers need to know whether the display spec is any kind
4894 of `(space ...)' spec that is about to affect text-area
4896 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4901 /* Save current settings of IT so that we can restore them
4902 when we are finished with the glyph property value. */
4903 push_it (it
, position
);
4904 it
->from_overlay
= overlay
;
4905 it
->from_disp_prop_p
= 1;
4907 if (NILP (location
))
4908 it
->area
= TEXT_AREA
;
4909 else if (EQ (location
, Qleft_margin
))
4910 it
->area
= LEFT_MARGIN_AREA
;
4912 it
->area
= RIGHT_MARGIN_AREA
;
4914 if (STRINGP (value
))
4917 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4918 it
->current
.overlay_string_index
= -1;
4919 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4920 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4921 it
->method
= GET_FROM_STRING
;
4922 it
->stop_charpos
= 0;
4924 it
->base_level_stop
= 0;
4925 it
->string_from_display_prop_p
= 1;
4926 /* Say that we haven't consumed the characters with
4927 `display' property yet. The call to pop_it in
4928 set_iterator_to_next will clean this up. */
4929 if (BUFFERP (object
))
4930 *position
= start_pos
;
4932 /* Force paragraph direction to be that of the parent
4933 object. If the parent object's paragraph direction is
4934 not yet determined, default to L2R. */
4935 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4936 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4938 it
->paragraph_embedding
= L2R
;
4940 /* Set up the bidi iterator for this display string. */
4943 it
->bidi_it
.string
.lstring
= it
->string
;
4944 it
->bidi_it
.string
.s
= NULL
;
4945 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4946 it
->bidi_it
.string
.bufpos
= bufpos
;
4947 it
->bidi_it
.string
.from_disp_str
= 1;
4948 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4949 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4952 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4954 it
->method
= GET_FROM_STRETCH
;
4956 *position
= it
->position
= start_pos
;
4957 retval
= 1 + (it
->area
== TEXT_AREA
);
4959 #ifdef HAVE_WINDOW_SYSTEM
4962 it
->what
= IT_IMAGE
;
4963 it
->image_id
= lookup_image (it
->f
, value
);
4964 it
->position
= start_pos
;
4965 it
->object
= NILP (object
) ? WVAR (it
->w
, buffer
) : object
;
4966 it
->method
= GET_FROM_IMAGE
;
4968 /* Say that we haven't consumed the characters with
4969 `display' property yet. The call to pop_it in
4970 set_iterator_to_next will clean this up. */
4971 *position
= start_pos
;
4973 #endif /* HAVE_WINDOW_SYSTEM */
4978 /* Invalid property or property not supported. Restore
4979 POSITION to what it was before. */
4980 *position
= start_pos
;
4984 /* Check if PROP is a display property value whose text should be
4985 treated as intangible. OVERLAY is the overlay from which PROP
4986 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4987 specify the buffer position covered by PROP. */
4990 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4991 ptrdiff_t charpos
, ptrdiff_t bytepos
)
4993 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4994 struct text_pos position
;
4996 SET_TEXT_POS (position
, charpos
, bytepos
);
4997 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4998 &position
, charpos
, frame_window_p
);
5002 /* Return 1 if PROP is a display sub-property value containing STRING.
5004 Implementation note: this and the following function are really
5005 special cases of handle_display_spec and
5006 handle_single_display_spec, and should ideally use the same code.
5007 Until they do, these two pairs must be consistent and must be
5008 modified in sync. */
5011 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5013 if (EQ (string
, prop
))
5016 /* Skip over `when FORM'. */
5017 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5022 /* Actually, the condition following `when' should be eval'ed,
5023 like handle_single_display_spec does, and we should return
5024 zero if it evaluates to nil. However, this function is
5025 called only when the buffer was already displayed and some
5026 glyph in the glyph matrix was found to come from a display
5027 string. Therefore, the condition was already evaluated, and
5028 the result was non-nil, otherwise the display string wouldn't
5029 have been displayed and we would have never been called for
5030 this property. Thus, we can skip the evaluation and assume
5031 its result is non-nil. */
5036 /* Skip over `margin LOCATION'. */
5037 if (EQ (XCAR (prop
), Qmargin
))
5048 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5052 /* Return 1 if STRING appears in the `display' property PROP. */
5055 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5058 && !EQ (XCAR (prop
), Qwhen
)
5059 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5061 /* A list of sub-properties. */
5062 while (CONSP (prop
))
5064 if (single_display_spec_string_p (XCAR (prop
), string
))
5069 else if (VECTORP (prop
))
5071 /* A vector of sub-properties. */
5073 for (i
= 0; i
< ASIZE (prop
); ++i
)
5074 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5078 return single_display_spec_string_p (prop
, string
);
5083 /* Look for STRING in overlays and text properties in the current
5084 buffer, between character positions FROM and TO (excluding TO).
5085 BACK_P non-zero means look back (in this case, TO is supposed to be
5087 Value is the first character position where STRING was found, or
5088 zero if it wasn't found before hitting TO.
5090 This function may only use code that doesn't eval because it is
5091 called asynchronously from note_mouse_highlight. */
5094 string_buffer_position_lim (Lisp_Object string
,
5095 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5097 Lisp_Object limit
, prop
, pos
;
5100 pos
= make_number (max (from
, BEGV
));
5102 if (!back_p
) /* looking forward */
5104 limit
= make_number (min (to
, ZV
));
5105 while (!found
&& !EQ (pos
, limit
))
5107 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5108 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5111 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5115 else /* looking back */
5117 limit
= make_number (max (to
, BEGV
));
5118 while (!found
&& !EQ (pos
, limit
))
5120 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5121 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5124 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5129 return found
? XINT (pos
) : 0;
5132 /* Determine which buffer position in current buffer STRING comes from.
5133 AROUND_CHARPOS is an approximate position where it could come from.
5134 Value is the buffer position or 0 if it couldn't be determined.
5136 This function is necessary because we don't record buffer positions
5137 in glyphs generated from strings (to keep struct glyph small).
5138 This function may only use code that doesn't eval because it is
5139 called asynchronously from note_mouse_highlight. */
5142 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5144 const int MAX_DISTANCE
= 1000;
5145 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5146 around_charpos
+ MAX_DISTANCE
,
5150 found
= string_buffer_position_lim (string
, around_charpos
,
5151 around_charpos
- MAX_DISTANCE
, 1);
5157 /***********************************************************************
5158 `composition' property
5159 ***********************************************************************/
5161 /* Set up iterator IT from `composition' property at its current
5162 position. Called from handle_stop. */
5164 static enum prop_handled
5165 handle_composition_prop (struct it
*it
)
5167 Lisp_Object prop
, string
;
5168 ptrdiff_t pos
, pos_byte
, start
, end
;
5170 if (STRINGP (it
->string
))
5174 pos
= IT_STRING_CHARPOS (*it
);
5175 pos_byte
= IT_STRING_BYTEPOS (*it
);
5176 string
= it
->string
;
5177 s
= SDATA (string
) + pos_byte
;
5178 it
->c
= STRING_CHAR (s
);
5182 pos
= IT_CHARPOS (*it
);
5183 pos_byte
= IT_BYTEPOS (*it
);
5185 it
->c
= FETCH_CHAR (pos_byte
);
5188 /* If there's a valid composition and point is not inside of the
5189 composition (in the case that the composition is from the current
5190 buffer), draw a glyph composed from the composition components. */
5191 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5192 && COMPOSITION_VALID_P (start
, end
, prop
)
5193 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5196 /* As we can't handle this situation (perhaps font-lock added
5197 a new composition), we just return here hoping that next
5198 redisplay will detect this composition much earlier. */
5199 return HANDLED_NORMALLY
;
5202 if (STRINGP (it
->string
))
5203 pos_byte
= string_char_to_byte (it
->string
, start
);
5205 pos_byte
= CHAR_TO_BYTE (start
);
5207 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5210 if (it
->cmp_it
.id
>= 0)
5213 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5214 it
->cmp_it
.nglyphs
= -1;
5218 return HANDLED_NORMALLY
;
5223 /***********************************************************************
5225 ***********************************************************************/
5227 /* The following structure is used to record overlay strings for
5228 later sorting in load_overlay_strings. */
5230 struct overlay_entry
5232 Lisp_Object overlay
;
5239 /* Set up iterator IT from overlay strings at its current position.
5240 Called from handle_stop. */
5242 static enum prop_handled
5243 handle_overlay_change (struct it
*it
)
5245 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5246 return HANDLED_RECOMPUTE_PROPS
;
5248 return HANDLED_NORMALLY
;
5252 /* Set up the next overlay string for delivery by IT, if there is an
5253 overlay string to deliver. Called by set_iterator_to_next when the
5254 end of the current overlay string is reached. If there are more
5255 overlay strings to display, IT->string and
5256 IT->current.overlay_string_index are set appropriately here.
5257 Otherwise IT->string is set to nil. */
5260 next_overlay_string (struct it
*it
)
5262 ++it
->current
.overlay_string_index
;
5263 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5265 /* No more overlay strings. Restore IT's settings to what
5266 they were before overlay strings were processed, and
5267 continue to deliver from current_buffer. */
5269 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5272 || (NILP (it
->string
)
5273 && it
->method
== GET_FROM_BUFFER
5274 && it
->stop_charpos
>= BEGV
5275 && it
->stop_charpos
<= it
->end_charpos
));
5276 it
->current
.overlay_string_index
= -1;
5277 it
->n_overlay_strings
= 0;
5278 it
->overlay_strings_charpos
= -1;
5279 /* If there's an empty display string on the stack, pop the
5280 stack, to resync the bidi iterator with IT's position. Such
5281 empty strings are pushed onto the stack in
5282 get_overlay_strings_1. */
5283 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5286 /* If we're at the end of the buffer, record that we have
5287 processed the overlay strings there already, so that
5288 next_element_from_buffer doesn't try it again. */
5289 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5290 it
->overlay_strings_at_end_processed_p
= 1;
5294 /* There are more overlay strings to process. If
5295 IT->current.overlay_string_index has advanced to a position
5296 where we must load IT->overlay_strings with more strings, do
5297 it. We must load at the IT->overlay_strings_charpos where
5298 IT->n_overlay_strings was originally computed; when invisible
5299 text is present, this might not be IT_CHARPOS (Bug#7016). */
5300 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5302 if (it
->current
.overlay_string_index
&& i
== 0)
5303 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5305 /* Initialize IT to deliver display elements from the overlay
5307 it
->string
= it
->overlay_strings
[i
];
5308 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5309 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5310 it
->method
= GET_FROM_STRING
;
5311 it
->stop_charpos
= 0;
5312 if (it
->cmp_it
.stop_pos
>= 0)
5313 it
->cmp_it
.stop_pos
= 0;
5315 it
->base_level_stop
= 0;
5317 /* Set up the bidi iterator for this overlay string. */
5320 it
->bidi_it
.string
.lstring
= it
->string
;
5321 it
->bidi_it
.string
.s
= NULL
;
5322 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5323 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5324 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5325 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5326 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5334 /* Compare two overlay_entry structures E1 and E2. Used as a
5335 comparison function for qsort in load_overlay_strings. Overlay
5336 strings for the same position are sorted so that
5338 1. All after-strings come in front of before-strings, except
5339 when they come from the same overlay.
5341 2. Within after-strings, strings are sorted so that overlay strings
5342 from overlays with higher priorities come first.
5344 2. Within before-strings, strings are sorted so that overlay
5345 strings from overlays with higher priorities come last.
5347 Value is analogous to strcmp. */
5351 compare_overlay_entries (const void *e1
, const void *e2
)
5353 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5354 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5357 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5359 /* Let after-strings appear in front of before-strings if
5360 they come from different overlays. */
5361 if (EQ (entry1
->overlay
, entry2
->overlay
))
5362 result
= entry1
->after_string_p
? 1 : -1;
5364 result
= entry1
->after_string_p
? -1 : 1;
5366 else if (entry1
->priority
!= entry2
->priority
)
5368 if (entry1
->after_string_p
)
5369 /* After-strings sorted in order of decreasing priority. */
5370 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5372 /* Before-strings sorted in order of increasing priority. */
5373 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5382 /* Load the vector IT->overlay_strings with overlay strings from IT's
5383 current buffer position, or from CHARPOS if that is > 0. Set
5384 IT->n_overlays to the total number of overlay strings found.
5386 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5387 a time. On entry into load_overlay_strings,
5388 IT->current.overlay_string_index gives the number of overlay
5389 strings that have already been loaded by previous calls to this
5392 IT->add_overlay_start contains an additional overlay start
5393 position to consider for taking overlay strings from, if non-zero.
5394 This position comes into play when the overlay has an `invisible'
5395 property, and both before and after-strings. When we've skipped to
5396 the end of the overlay, because of its `invisible' property, we
5397 nevertheless want its before-string to appear.
5398 IT->add_overlay_start will contain the overlay start position
5401 Overlay strings are sorted so that after-string strings come in
5402 front of before-string strings. Within before and after-strings,
5403 strings are sorted by overlay priority. See also function
5404 compare_overlay_entries. */
5407 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5409 Lisp_Object overlay
, window
, str
, invisible
;
5410 struct Lisp_Overlay
*ov
;
5411 ptrdiff_t start
, end
;
5412 ptrdiff_t size
= 20;
5413 ptrdiff_t n
= 0, i
, j
;
5415 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5419 charpos
= IT_CHARPOS (*it
);
5421 /* Append the overlay string STRING of overlay OVERLAY to vector
5422 `entries' which has size `size' and currently contains `n'
5423 elements. AFTER_P non-zero means STRING is an after-string of
5425 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5428 Lisp_Object priority; \
5432 struct overlay_entry *old = entries; \
5433 SAFE_NALLOCA (entries, 2, size); \
5434 memcpy (entries, old, size * sizeof *entries); \
5438 entries[n].string = (STRING); \
5439 entries[n].overlay = (OVERLAY); \
5440 priority = Foverlay_get ((OVERLAY), Qpriority); \
5441 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5442 entries[n].after_string_p = (AFTER_P); \
5447 /* Process overlay before the overlay center. */
5448 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5450 XSETMISC (overlay
, ov
);
5451 eassert (OVERLAYP (overlay
));
5452 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5453 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5458 /* Skip this overlay if it doesn't start or end at IT's current
5460 if (end
!= charpos
&& start
!= charpos
)
5463 /* Skip this overlay if it doesn't apply to IT->w. */
5464 window
= Foverlay_get (overlay
, Qwindow
);
5465 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5468 /* If the text ``under'' the overlay is invisible, both before-
5469 and after-strings from this overlay are visible; start and
5470 end position are indistinguishable. */
5471 invisible
= Foverlay_get (overlay
, Qinvisible
);
5472 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5474 /* If overlay has a non-empty before-string, record it. */
5475 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5476 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5478 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5480 /* If overlay has a non-empty after-string, record it. */
5481 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5482 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5484 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5487 /* Process overlays after the overlay center. */
5488 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5490 XSETMISC (overlay
, ov
);
5491 eassert (OVERLAYP (overlay
));
5492 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5493 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5495 if (start
> charpos
)
5498 /* Skip this overlay if it doesn't start or end at IT's current
5500 if (end
!= charpos
&& start
!= charpos
)
5503 /* Skip this overlay if it doesn't apply to IT->w. */
5504 window
= Foverlay_get (overlay
, Qwindow
);
5505 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5508 /* If the text ``under'' the overlay is invisible, it has a zero
5509 dimension, and both before- and after-strings apply. */
5510 invisible
= Foverlay_get (overlay
, Qinvisible
);
5511 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5513 /* If overlay has a non-empty before-string, record it. */
5514 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5515 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5517 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5519 /* If overlay has a non-empty after-string, record it. */
5520 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5521 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5523 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5526 #undef RECORD_OVERLAY_STRING
5530 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5532 /* Record number of overlay strings, and where we computed it. */
5533 it
->n_overlay_strings
= n
;
5534 it
->overlay_strings_charpos
= charpos
;
5536 /* IT->current.overlay_string_index is the number of overlay strings
5537 that have already been consumed by IT. Copy some of the
5538 remaining overlay strings to IT->overlay_strings. */
5540 j
= it
->current
.overlay_string_index
;
5541 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5543 it
->overlay_strings
[i
] = entries
[j
].string
;
5544 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5552 /* Get the first chunk of overlay strings at IT's current buffer
5553 position, or at CHARPOS if that is > 0. Value is non-zero if at
5554 least one overlay string was found. */
5557 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5559 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5560 process. This fills IT->overlay_strings with strings, and sets
5561 IT->n_overlay_strings to the total number of strings to process.
5562 IT->pos.overlay_string_index has to be set temporarily to zero
5563 because load_overlay_strings needs this; it must be set to -1
5564 when no overlay strings are found because a zero value would
5565 indicate a position in the first overlay string. */
5566 it
->current
.overlay_string_index
= 0;
5567 load_overlay_strings (it
, charpos
);
5569 /* If we found overlay strings, set up IT to deliver display
5570 elements from the first one. Otherwise set up IT to deliver
5571 from current_buffer. */
5572 if (it
->n_overlay_strings
)
5574 /* Make sure we know settings in current_buffer, so that we can
5575 restore meaningful values when we're done with the overlay
5578 compute_stop_pos (it
);
5579 eassert (it
->face_id
>= 0);
5581 /* Save IT's settings. They are restored after all overlay
5582 strings have been processed. */
5583 eassert (!compute_stop_p
|| it
->sp
== 0);
5585 /* When called from handle_stop, there might be an empty display
5586 string loaded. In that case, don't bother saving it. But
5587 don't use this optimization with the bidi iterator, since we
5588 need the corresponding pop_it call to resync the bidi
5589 iterator's position with IT's position, after we are done
5590 with the overlay strings. (The corresponding call to pop_it
5591 in case of an empty display string is in
5592 next_overlay_string.) */
5594 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5597 /* Set up IT to deliver display elements from the first overlay
5599 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5600 it
->string
= it
->overlay_strings
[0];
5601 it
->from_overlay
= Qnil
;
5602 it
->stop_charpos
= 0;
5603 eassert (STRINGP (it
->string
));
5604 it
->end_charpos
= SCHARS (it
->string
);
5606 it
->base_level_stop
= 0;
5607 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5608 it
->method
= GET_FROM_STRING
;
5609 it
->from_disp_prop_p
= 0;
5611 /* Force paragraph direction to be that of the parent
5613 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5614 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5616 it
->paragraph_embedding
= L2R
;
5618 /* Set up the bidi iterator for this overlay string. */
5621 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5623 it
->bidi_it
.string
.lstring
= it
->string
;
5624 it
->bidi_it
.string
.s
= NULL
;
5625 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5626 it
->bidi_it
.string
.bufpos
= pos
;
5627 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5628 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5629 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5634 it
->current
.overlay_string_index
= -1;
5639 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5642 it
->method
= GET_FROM_BUFFER
;
5644 (void) get_overlay_strings_1 (it
, charpos
, 1);
5648 /* Value is non-zero if we found at least one overlay string. */
5649 return STRINGP (it
->string
);
5654 /***********************************************************************
5655 Saving and restoring state
5656 ***********************************************************************/
5658 /* Save current settings of IT on IT->stack. Called, for example,
5659 before setting up IT for an overlay string, to be able to restore
5660 IT's settings to what they were after the overlay string has been
5661 processed. If POSITION is non-NULL, it is the position to save on
5662 the stack instead of IT->position. */
5665 push_it (struct it
*it
, struct text_pos
*position
)
5667 struct iterator_stack_entry
*p
;
5669 eassert (it
->sp
< IT_STACK_SIZE
);
5670 p
= it
->stack
+ it
->sp
;
5672 p
->stop_charpos
= it
->stop_charpos
;
5673 p
->prev_stop
= it
->prev_stop
;
5674 p
->base_level_stop
= it
->base_level_stop
;
5675 p
->cmp_it
= it
->cmp_it
;
5676 eassert (it
->face_id
>= 0);
5677 p
->face_id
= it
->face_id
;
5678 p
->string
= it
->string
;
5679 p
->method
= it
->method
;
5680 p
->from_overlay
= it
->from_overlay
;
5683 case GET_FROM_IMAGE
:
5684 p
->u
.image
.object
= it
->object
;
5685 p
->u
.image
.image_id
= it
->image_id
;
5686 p
->u
.image
.slice
= it
->slice
;
5688 case GET_FROM_STRETCH
:
5689 p
->u
.stretch
.object
= it
->object
;
5692 p
->position
= position
? *position
: it
->position
;
5693 p
->current
= it
->current
;
5694 p
->end_charpos
= it
->end_charpos
;
5695 p
->string_nchars
= it
->string_nchars
;
5697 p
->multibyte_p
= it
->multibyte_p
;
5698 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5699 p
->space_width
= it
->space_width
;
5700 p
->font_height
= it
->font_height
;
5701 p
->voffset
= it
->voffset
;
5702 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5703 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5704 p
->display_ellipsis_p
= 0;
5705 p
->line_wrap
= it
->line_wrap
;
5706 p
->bidi_p
= it
->bidi_p
;
5707 p
->paragraph_embedding
= it
->paragraph_embedding
;
5708 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5711 /* Save the state of the bidi iterator as well. */
5713 bidi_push_it (&it
->bidi_it
);
5717 iterate_out_of_display_property (struct it
*it
)
5719 int buffer_p
= !STRINGP (it
->string
);
5720 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5721 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5723 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5725 /* Maybe initialize paragraph direction. If we are at the beginning
5726 of a new paragraph, next_element_from_buffer may not have a
5727 chance to do that. */
5728 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5729 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5730 /* prev_stop can be zero, so check against BEGV as well. */
5731 while (it
->bidi_it
.charpos
>= bob
5732 && it
->prev_stop
<= it
->bidi_it
.charpos
5733 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5734 && it
->bidi_it
.charpos
< eob
)
5735 bidi_move_to_visually_next (&it
->bidi_it
);
5736 /* Record the stop_pos we just crossed, for when we cross it
5738 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5739 it
->prev_stop
= CHARPOS (it
->position
);
5740 /* If we ended up not where pop_it put us, resync IT's
5741 positional members with the bidi iterator. */
5742 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5743 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5745 it
->current
.pos
= it
->position
;
5747 it
->current
.string_pos
= it
->position
;
5750 /* Restore IT's settings from IT->stack. Called, for example, when no
5751 more overlay strings must be processed, and we return to delivering
5752 display elements from a buffer, or when the end of a string from a
5753 `display' property is reached and we return to delivering display
5754 elements from an overlay string, or from a buffer. */
5757 pop_it (struct it
*it
)
5759 struct iterator_stack_entry
*p
;
5760 int from_display_prop
= it
->from_disp_prop_p
;
5762 eassert (it
->sp
> 0);
5764 p
= it
->stack
+ it
->sp
;
5765 it
->stop_charpos
= p
->stop_charpos
;
5766 it
->prev_stop
= p
->prev_stop
;
5767 it
->base_level_stop
= p
->base_level_stop
;
5768 it
->cmp_it
= p
->cmp_it
;
5769 it
->face_id
= p
->face_id
;
5770 it
->current
= p
->current
;
5771 it
->position
= p
->position
;
5772 it
->string
= p
->string
;
5773 it
->from_overlay
= p
->from_overlay
;
5774 if (NILP (it
->string
))
5775 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5776 it
->method
= p
->method
;
5779 case GET_FROM_IMAGE
:
5780 it
->image_id
= p
->u
.image
.image_id
;
5781 it
->object
= p
->u
.image
.object
;
5782 it
->slice
= p
->u
.image
.slice
;
5784 case GET_FROM_STRETCH
:
5785 it
->object
= p
->u
.stretch
.object
;
5787 case GET_FROM_BUFFER
:
5788 it
->object
= WVAR (it
->w
, buffer
);
5790 case GET_FROM_STRING
:
5791 it
->object
= it
->string
;
5793 case GET_FROM_DISPLAY_VECTOR
:
5795 it
->method
= GET_FROM_C_STRING
;
5796 else if (STRINGP (it
->string
))
5797 it
->method
= GET_FROM_STRING
;
5800 it
->method
= GET_FROM_BUFFER
;
5801 it
->object
= WVAR (it
->w
, buffer
);
5804 it
->end_charpos
= p
->end_charpos
;
5805 it
->string_nchars
= p
->string_nchars
;
5807 it
->multibyte_p
= p
->multibyte_p
;
5808 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5809 it
->space_width
= p
->space_width
;
5810 it
->font_height
= p
->font_height
;
5811 it
->voffset
= p
->voffset
;
5812 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5813 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5814 it
->line_wrap
= p
->line_wrap
;
5815 it
->bidi_p
= p
->bidi_p
;
5816 it
->paragraph_embedding
= p
->paragraph_embedding
;
5817 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5820 bidi_pop_it (&it
->bidi_it
);
5821 /* Bidi-iterate until we get out of the portion of text, if any,
5822 covered by a `display' text property or by an overlay with
5823 `display' property. (We cannot just jump there, because the
5824 internal coherency of the bidi iterator state can not be
5825 preserved across such jumps.) We also must determine the
5826 paragraph base direction if the overlay we just processed is
5827 at the beginning of a new paragraph. */
5828 if (from_display_prop
5829 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5830 iterate_out_of_display_property (it
);
5832 eassert ((BUFFERP (it
->object
)
5833 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5834 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5835 || (STRINGP (it
->object
)
5836 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5837 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5838 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5844 /***********************************************************************
5846 ***********************************************************************/
5848 /* Set IT's current position to the previous line start. */
5851 back_to_previous_line_start (struct it
*it
)
5853 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5854 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5858 /* Move IT to the next line start.
5860 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5861 we skipped over part of the text (as opposed to moving the iterator
5862 continuously over the text). Otherwise, don't change the value
5865 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5866 iterator on the newline, if it was found.
5868 Newlines may come from buffer text, overlay strings, or strings
5869 displayed via the `display' property. That's the reason we can't
5870 simply use find_next_newline_no_quit.
5872 Note that this function may not skip over invisible text that is so
5873 because of text properties and immediately follows a newline. If
5874 it would, function reseat_at_next_visible_line_start, when called
5875 from set_iterator_to_next, would effectively make invisible
5876 characters following a newline part of the wrong glyph row, which
5877 leads to wrong cursor motion. */
5880 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5881 struct bidi_it
*bidi_it_prev
)
5883 ptrdiff_t old_selective
;
5884 int newline_found_p
, n
;
5885 const int MAX_NEWLINE_DISTANCE
= 500;
5887 /* If already on a newline, just consume it to avoid unintended
5888 skipping over invisible text below. */
5889 if (it
->what
== IT_CHARACTER
5891 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5893 if (it
->bidi_p
&& bidi_it_prev
)
5894 *bidi_it_prev
= it
->bidi_it
;
5895 set_iterator_to_next (it
, 0);
5900 /* Don't handle selective display in the following. It's (a)
5901 unnecessary because it's done by the caller, and (b) leads to an
5902 infinite recursion because next_element_from_ellipsis indirectly
5903 calls this function. */
5904 old_selective
= it
->selective
;
5907 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5908 from buffer text. */
5909 for (n
= newline_found_p
= 0;
5910 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5911 n
+= STRINGP (it
->string
) ? 0 : 1)
5913 if (!get_next_display_element (it
))
5915 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5916 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5917 *bidi_it_prev
= it
->bidi_it
;
5918 set_iterator_to_next (it
, 0);
5921 /* If we didn't find a newline near enough, see if we can use a
5923 if (!newline_found_p
)
5925 ptrdiff_t start
= IT_CHARPOS (*it
);
5926 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5929 eassert (!STRINGP (it
->string
));
5931 /* If there isn't any `display' property in sight, and no
5932 overlays, we can just use the position of the newline in
5934 if (it
->stop_charpos
>= limit
5935 || ((pos
= Fnext_single_property_change (make_number (start
),
5937 make_number (limit
)),
5939 && next_overlay_change (start
) == ZV
))
5943 IT_CHARPOS (*it
) = limit
;
5944 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5948 struct bidi_it bprev
;
5950 /* Help bidi.c avoid expensive searches for display
5951 properties and overlays, by telling it that there are
5952 none up to `limit'. */
5953 if (it
->bidi_it
.disp_pos
< limit
)
5955 it
->bidi_it
.disp_pos
= limit
;
5956 it
->bidi_it
.disp_prop
= 0;
5959 bprev
= it
->bidi_it
;
5960 bidi_move_to_visually_next (&it
->bidi_it
);
5961 } while (it
->bidi_it
.charpos
!= limit
);
5962 IT_CHARPOS (*it
) = limit
;
5963 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5965 *bidi_it_prev
= bprev
;
5967 *skipped_p
= newline_found_p
= 1;
5971 while (get_next_display_element (it
)
5972 && !newline_found_p
)
5974 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5975 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5976 *bidi_it_prev
= it
->bidi_it
;
5977 set_iterator_to_next (it
, 0);
5982 it
->selective
= old_selective
;
5983 return newline_found_p
;
5987 /* Set IT's current position to the previous visible line start. Skip
5988 invisible text that is so either due to text properties or due to
5989 selective display. Caution: this does not change IT->current_x and
5993 back_to_previous_visible_line_start (struct it
*it
)
5995 while (IT_CHARPOS (*it
) > BEGV
)
5997 back_to_previous_line_start (it
);
5999 if (IT_CHARPOS (*it
) <= BEGV
)
6002 /* If selective > 0, then lines indented more than its value are
6004 if (it
->selective
> 0
6005 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6009 /* Check the newline before point for invisibility. */
6012 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6013 Qinvisible
, it
->window
);
6014 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6018 if (IT_CHARPOS (*it
) <= BEGV
)
6023 void *it2data
= NULL
;
6026 Lisp_Object val
, overlay
;
6028 SAVE_IT (it2
, *it
, it2data
);
6030 /* If newline is part of a composition, continue from start of composition */
6031 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6032 && beg
< IT_CHARPOS (*it
))
6035 /* If newline is replaced by a display property, find start of overlay
6036 or interval and continue search from that point. */
6037 pos
= --IT_CHARPOS (it2
);
6040 bidi_unshelve_cache (NULL
, 0);
6041 it2
.string_from_display_prop_p
= 0;
6042 it2
.from_disp_prop_p
= 0;
6043 if (handle_display_prop (&it2
) == HANDLED_RETURN
6044 && !NILP (val
= get_char_property_and_overlay
6045 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6046 && (OVERLAYP (overlay
)
6047 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6048 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6050 RESTORE_IT (it
, it
, it2data
);
6054 /* Newline is not replaced by anything -- so we are done. */
6055 RESTORE_IT (it
, it
, it2data
);
6061 IT_CHARPOS (*it
) = beg
;
6062 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6066 it
->continuation_lines_width
= 0;
6068 eassert (IT_CHARPOS (*it
) >= BEGV
);
6069 eassert (IT_CHARPOS (*it
) == BEGV
6070 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6075 /* Reseat iterator IT at the previous visible line start. Skip
6076 invisible text that is so either due to text properties or due to
6077 selective display. At the end, update IT's overlay information,
6078 face information etc. */
6081 reseat_at_previous_visible_line_start (struct it
*it
)
6083 back_to_previous_visible_line_start (it
);
6084 reseat (it
, it
->current
.pos
, 1);
6089 /* Reseat iterator IT on the next visible line start in the current
6090 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6091 preceding the line start. Skip over invisible text that is so
6092 because of selective display. Compute faces, overlays etc at the
6093 new position. Note that this function does not skip over text that
6094 is invisible because of text properties. */
6097 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6099 int newline_found_p
, skipped_p
= 0;
6100 struct bidi_it bidi_it_prev
;
6102 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6104 /* Skip over lines that are invisible because they are indented
6105 more than the value of IT->selective. */
6106 if (it
->selective
> 0)
6107 while (IT_CHARPOS (*it
) < ZV
6108 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6111 eassert (IT_BYTEPOS (*it
) == BEGV
6112 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6114 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6117 /* Position on the newline if that's what's requested. */
6118 if (on_newline_p
&& newline_found_p
)
6120 if (STRINGP (it
->string
))
6122 if (IT_STRING_CHARPOS (*it
) > 0)
6126 --IT_STRING_CHARPOS (*it
);
6127 --IT_STRING_BYTEPOS (*it
);
6131 /* We need to restore the bidi iterator to the state
6132 it had on the newline, and resync the IT's
6133 position with that. */
6134 it
->bidi_it
= bidi_it_prev
;
6135 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6136 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6140 else if (IT_CHARPOS (*it
) > BEGV
)
6149 /* We need to restore the bidi iterator to the state it
6150 had on the newline and resync IT with that. */
6151 it
->bidi_it
= bidi_it_prev
;
6152 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6153 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6155 reseat (it
, it
->current
.pos
, 0);
6159 reseat (it
, it
->current
.pos
, 0);
6166 /***********************************************************************
6167 Changing an iterator's position
6168 ***********************************************************************/
6170 /* Change IT's current position to POS in current_buffer. If FORCE_P
6171 is non-zero, always check for text properties at the new position.
6172 Otherwise, text properties are only looked up if POS >=
6173 IT->check_charpos of a property. */
6176 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6178 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6180 reseat_1 (it
, pos
, 0);
6182 /* Determine where to check text properties. Avoid doing it
6183 where possible because text property lookup is very expensive. */
6185 || CHARPOS (pos
) > it
->stop_charpos
6186 || CHARPOS (pos
) < original_pos
)
6190 /* For bidi iteration, we need to prime prev_stop and
6191 base_level_stop with our best estimations. */
6192 /* Implementation note: Of course, POS is not necessarily a
6193 stop position, so assigning prev_pos to it is a lie; we
6194 should have called compute_stop_backwards. However, if
6195 the current buffer does not include any R2L characters,
6196 that call would be a waste of cycles, because the
6197 iterator will never move back, and thus never cross this
6198 "fake" stop position. So we delay that backward search
6199 until the time we really need it, in next_element_from_buffer. */
6200 if (CHARPOS (pos
) != it
->prev_stop
)
6201 it
->prev_stop
= CHARPOS (pos
);
6202 if (CHARPOS (pos
) < it
->base_level_stop
)
6203 it
->base_level_stop
= 0; /* meaning it's unknown */
6209 it
->prev_stop
= it
->base_level_stop
= 0;
6218 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6219 IT->stop_pos to POS, also. */
6222 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6224 /* Don't call this function when scanning a C string. */
6225 eassert (it
->s
== NULL
);
6227 /* POS must be a reasonable value. */
6228 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6230 it
->current
.pos
= it
->position
= pos
;
6231 it
->end_charpos
= ZV
;
6233 it
->current
.dpvec_index
= -1;
6234 it
->current
.overlay_string_index
= -1;
6235 IT_STRING_CHARPOS (*it
) = -1;
6236 IT_STRING_BYTEPOS (*it
) = -1;
6238 it
->method
= GET_FROM_BUFFER
;
6239 it
->object
= WVAR (it
->w
, buffer
);
6240 it
->area
= TEXT_AREA
;
6241 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6243 it
->string_from_display_prop_p
= 0;
6244 it
->string_from_prefix_prop_p
= 0;
6246 it
->from_disp_prop_p
= 0;
6247 it
->face_before_selective_p
= 0;
6250 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6252 bidi_unshelve_cache (NULL
, 0);
6253 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6254 it
->bidi_it
.string
.s
= NULL
;
6255 it
->bidi_it
.string
.lstring
= Qnil
;
6256 it
->bidi_it
.string
.bufpos
= 0;
6257 it
->bidi_it
.string
.unibyte
= 0;
6262 it
->stop_charpos
= CHARPOS (pos
);
6263 it
->base_level_stop
= CHARPOS (pos
);
6268 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6269 If S is non-null, it is a C string to iterate over. Otherwise,
6270 STRING gives a Lisp string to iterate over.
6272 If PRECISION > 0, don't return more then PRECISION number of
6273 characters from the string.
6275 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6276 characters have been returned. FIELD_WIDTH < 0 means an infinite
6279 MULTIBYTE = 0 means disable processing of multibyte characters,
6280 MULTIBYTE > 0 means enable it,
6281 MULTIBYTE < 0 means use IT->multibyte_p.
6283 IT must be initialized via a prior call to init_iterator before
6284 calling this function. */
6287 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6288 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6291 /* No region in strings. */
6292 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6294 /* No text property checks performed by default, but see below. */
6295 it
->stop_charpos
= -1;
6297 /* Set iterator position and end position. */
6298 memset (&it
->current
, 0, sizeof it
->current
);
6299 it
->current
.overlay_string_index
= -1;
6300 it
->current
.dpvec_index
= -1;
6301 eassert (charpos
>= 0);
6303 /* If STRING is specified, use its multibyteness, otherwise use the
6304 setting of MULTIBYTE, if specified. */
6306 it
->multibyte_p
= multibyte
> 0;
6308 /* Bidirectional reordering of strings is controlled by the default
6309 value of bidi-display-reordering. Don't try to reorder while
6310 loading loadup.el, as the necessary character property tables are
6311 not yet available. */
6314 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6318 eassert (STRINGP (string
));
6319 it
->string
= string
;
6321 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6322 it
->method
= GET_FROM_STRING
;
6323 it
->current
.string_pos
= string_pos (charpos
, string
);
6327 it
->bidi_it
.string
.lstring
= string
;
6328 it
->bidi_it
.string
.s
= NULL
;
6329 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6330 it
->bidi_it
.string
.bufpos
= 0;
6331 it
->bidi_it
.string
.from_disp_str
= 0;
6332 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6333 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6334 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6339 it
->s
= (const unsigned char *) s
;
6342 /* Note that we use IT->current.pos, not it->current.string_pos,
6343 for displaying C strings. */
6344 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6345 if (it
->multibyte_p
)
6347 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6348 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6352 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6353 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6358 it
->bidi_it
.string
.lstring
= Qnil
;
6359 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6360 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6361 it
->bidi_it
.string
.bufpos
= 0;
6362 it
->bidi_it
.string
.from_disp_str
= 0;
6363 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6364 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6367 it
->method
= GET_FROM_C_STRING
;
6370 /* PRECISION > 0 means don't return more than PRECISION characters
6372 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6374 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6376 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6379 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6380 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6381 FIELD_WIDTH < 0 means infinite field width. This is useful for
6382 padding with `-' at the end of a mode line. */
6383 if (field_width
< 0)
6384 field_width
= INFINITY
;
6385 /* Implementation note: We deliberately don't enlarge
6386 it->bidi_it.string.schars here to fit it->end_charpos, because
6387 the bidi iterator cannot produce characters out of thin air. */
6388 if (field_width
> it
->end_charpos
- charpos
)
6389 it
->end_charpos
= charpos
+ field_width
;
6391 /* Use the standard display table for displaying strings. */
6392 if (DISP_TABLE_P (Vstandard_display_table
))
6393 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6395 it
->stop_charpos
= charpos
;
6396 it
->prev_stop
= charpos
;
6397 it
->base_level_stop
= 0;
6400 it
->bidi_it
.first_elt
= 1;
6401 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6402 it
->bidi_it
.disp_pos
= -1;
6404 if (s
== NULL
&& it
->multibyte_p
)
6406 ptrdiff_t endpos
= SCHARS (it
->string
);
6407 if (endpos
> it
->end_charpos
)
6408 endpos
= it
->end_charpos
;
6409 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6417 /***********************************************************************
6419 ***********************************************************************/
6421 /* Map enum it_method value to corresponding next_element_from_* function. */
6423 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6425 next_element_from_buffer
,
6426 next_element_from_display_vector
,
6427 next_element_from_string
,
6428 next_element_from_c_string
,
6429 next_element_from_image
,
6430 next_element_from_stretch
6433 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6436 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6437 (possibly with the following characters). */
6439 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6440 ((IT)->cmp_it.id >= 0 \
6441 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6442 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6443 END_CHARPOS, (IT)->w, \
6444 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6448 /* Lookup the char-table Vglyphless_char_display for character C (-1
6449 if we want information for no-font case), and return the display
6450 method symbol. By side-effect, update it->what and
6451 it->glyphless_method. This function is called from
6452 get_next_display_element for each character element, and from
6453 x_produce_glyphs when no suitable font was found. */
6456 lookup_glyphless_char_display (int c
, struct it
*it
)
6458 Lisp_Object glyphless_method
= Qnil
;
6460 if (CHAR_TABLE_P (Vglyphless_char_display
)
6461 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6465 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6466 if (CONSP (glyphless_method
))
6467 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6468 ? XCAR (glyphless_method
)
6469 : XCDR (glyphless_method
);
6472 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6476 if (NILP (glyphless_method
))
6479 /* The default is to display the character by a proper font. */
6481 /* The default for the no-font case is to display an empty box. */
6482 glyphless_method
= Qempty_box
;
6484 if (EQ (glyphless_method
, Qzero_width
))
6487 return glyphless_method
;
6488 /* This method can't be used for the no-font case. */
6489 glyphless_method
= Qempty_box
;
6491 if (EQ (glyphless_method
, Qthin_space
))
6492 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6493 else if (EQ (glyphless_method
, Qempty_box
))
6494 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6495 else if (EQ (glyphless_method
, Qhex_code
))
6496 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6497 else if (STRINGP (glyphless_method
))
6498 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6501 /* Invalid value. We use the default method. */
6502 glyphless_method
= Qnil
;
6505 it
->what
= IT_GLYPHLESS
;
6506 return glyphless_method
;
6509 /* Load IT's display element fields with information about the next
6510 display element from the current position of IT. Value is zero if
6511 end of buffer (or C string) is reached. */
6513 static struct frame
*last_escape_glyph_frame
= NULL
;
6514 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6515 static int last_escape_glyph_merged_face_id
= 0;
6517 struct frame
*last_glyphless_glyph_frame
= NULL
;
6518 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6519 int last_glyphless_glyph_merged_face_id
= 0;
6522 get_next_display_element (struct it
*it
)
6524 /* Non-zero means that we found a display element. Zero means that
6525 we hit the end of what we iterate over. Performance note: the
6526 function pointer `method' used here turns out to be faster than
6527 using a sequence of if-statements. */
6531 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6533 if (it
->what
== IT_CHARACTER
)
6535 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6536 and only if (a) the resolved directionality of that character
6538 /* FIXME: Do we need an exception for characters from display
6540 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6541 it
->c
= bidi_mirror_char (it
->c
);
6542 /* Map via display table or translate control characters.
6543 IT->c, IT->len etc. have been set to the next character by
6544 the function call above. If we have a display table, and it
6545 contains an entry for IT->c, translate it. Don't do this if
6546 IT->c itself comes from a display table, otherwise we could
6547 end up in an infinite recursion. (An alternative could be to
6548 count the recursion depth of this function and signal an
6549 error when a certain maximum depth is reached.) Is it worth
6551 if (success_p
&& it
->dpvec
== NULL
)
6554 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6555 int nonascii_space_p
= 0;
6556 int nonascii_hyphen_p
= 0;
6557 int c
= it
->c
; /* This is the character to display. */
6559 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6561 eassert (SINGLE_BYTE_CHAR_P (c
));
6562 if (unibyte_display_via_language_environment
)
6564 c
= DECODE_CHAR (unibyte
, c
);
6566 c
= BYTE8_TO_CHAR (it
->c
);
6569 c
= BYTE8_TO_CHAR (it
->c
);
6573 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6576 struct Lisp_Vector
*v
= XVECTOR (dv
);
6578 /* Return the first character from the display table
6579 entry, if not empty. If empty, don't display the
6580 current character. */
6583 it
->dpvec_char_len
= it
->len
;
6584 it
->dpvec
= v
->contents
;
6585 it
->dpend
= v
->contents
+ v
->header
.size
;
6586 it
->current
.dpvec_index
= 0;
6587 it
->dpvec_face_id
= -1;
6588 it
->saved_face_id
= it
->face_id
;
6589 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6594 set_iterator_to_next (it
, 0);
6599 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6601 if (it
->what
== IT_GLYPHLESS
)
6603 /* Don't display this character. */
6604 set_iterator_to_next (it
, 0);
6608 /* If `nobreak-char-display' is non-nil, we display
6609 non-ASCII spaces and hyphens specially. */
6610 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6613 nonascii_space_p
= 1;
6614 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6615 nonascii_hyphen_p
= 1;
6618 /* Translate control characters into `\003' or `^C' form.
6619 Control characters coming from a display table entry are
6620 currently not translated because we use IT->dpvec to hold
6621 the translation. This could easily be changed but I
6622 don't believe that it is worth doing.
6624 The characters handled by `nobreak-char-display' must be
6627 Non-printable characters and raw-byte characters are also
6628 translated to octal form. */
6629 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6630 ? (it
->area
!= TEXT_AREA
6631 /* In mode line, treat \n, \t like other crl chars. */
6634 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6635 || (c
!= '\n' && c
!= '\t'))
6637 || nonascii_hyphen_p
6639 || ! CHAR_PRINTABLE_P (c
))))
6641 /* C is a control character, non-ASCII space/hyphen,
6642 raw-byte, or a non-printable character which must be
6643 displayed either as '\003' or as `^C' where the '\\'
6644 and '^' can be defined in the display table. Fill
6645 IT->ctl_chars with glyphs for what we have to
6646 display. Then, set IT->dpvec to these glyphs. */
6653 /* Handle control characters with ^. */
6655 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6659 g
= '^'; /* default glyph for Control */
6660 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6662 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6664 g
= GLYPH_CODE_CHAR (gc
);
6665 lface_id
= GLYPH_CODE_FACE (gc
);
6669 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6671 else if (it
->f
== last_escape_glyph_frame
6672 && it
->face_id
== last_escape_glyph_face_id
)
6674 face_id
= last_escape_glyph_merged_face_id
;
6678 /* Merge the escape-glyph face into the current face. */
6679 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6681 last_escape_glyph_frame
= it
->f
;
6682 last_escape_glyph_face_id
= it
->face_id
;
6683 last_escape_glyph_merged_face_id
= face_id
;
6686 XSETINT (it
->ctl_chars
[0], g
);
6687 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6689 goto display_control
;
6692 /* Handle non-ascii space in the mode where it only gets
6695 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6697 /* Merge `nobreak-space' into the current face. */
6698 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6700 XSETINT (it
->ctl_chars
[0], ' ');
6702 goto display_control
;
6705 /* Handle sequences that start with the "escape glyph". */
6707 /* the default escape glyph is \. */
6708 escape_glyph
= '\\';
6711 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6713 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6714 lface_id
= GLYPH_CODE_FACE (gc
);
6718 /* The display table specified a face.
6719 Merge it into face_id and also into escape_glyph. */
6720 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6723 else if (it
->f
== last_escape_glyph_frame
6724 && it
->face_id
== last_escape_glyph_face_id
)
6726 face_id
= last_escape_glyph_merged_face_id
;
6730 /* Merge the escape-glyph face into the current face. */
6731 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6733 last_escape_glyph_frame
= it
->f
;
6734 last_escape_glyph_face_id
= it
->face_id
;
6735 last_escape_glyph_merged_face_id
= face_id
;
6738 /* Draw non-ASCII hyphen with just highlighting: */
6740 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6742 XSETINT (it
->ctl_chars
[0], '-');
6744 goto display_control
;
6747 /* Draw non-ASCII space/hyphen with escape glyph: */
6749 if (nonascii_space_p
|| nonascii_hyphen_p
)
6751 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6752 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6754 goto display_control
;
6761 if (CHAR_BYTE8_P (c
))
6762 /* Display \200 instead of \17777600. */
6763 c
= CHAR_TO_BYTE8 (c
);
6764 len
= sprintf (str
, "%03o", c
);
6766 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6767 for (i
= 0; i
< len
; i
++)
6768 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6773 /* Set up IT->dpvec and return first character from it. */
6774 it
->dpvec_char_len
= it
->len
;
6775 it
->dpvec
= it
->ctl_chars
;
6776 it
->dpend
= it
->dpvec
+ ctl_len
;
6777 it
->current
.dpvec_index
= 0;
6778 it
->dpvec_face_id
= face_id
;
6779 it
->saved_face_id
= it
->face_id
;
6780 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6784 it
->char_to_display
= c
;
6788 it
->char_to_display
= it
->c
;
6792 /* Adjust face id for a multibyte character. There are no multibyte
6793 character in unibyte text. */
6794 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6797 && FRAME_WINDOW_P (it
->f
))
6799 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6801 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6803 /* Automatic composition with glyph-string. */
6804 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6806 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6810 ptrdiff_t pos
= (it
->s
? -1
6811 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6812 : IT_CHARPOS (*it
));
6815 if (it
->what
== IT_CHARACTER
)
6816 c
= it
->char_to_display
;
6819 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6823 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6824 /* TAB in a composition means display glyphs with
6825 padding space on the left or right. */
6826 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6829 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6834 /* Is this character the last one of a run of characters with
6835 box? If yes, set IT->end_of_box_run_p to 1. */
6839 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6841 int face_id
= underlying_face_id (it
);
6842 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6846 if (face
->box
== FACE_NO_BOX
)
6848 /* If the box comes from face properties in a
6849 display string, check faces in that string. */
6850 int string_face_id
= face_after_it_pos (it
);
6851 it
->end_of_box_run_p
6852 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6855 /* Otherwise, the box comes from the underlying face.
6856 If this is the last string character displayed, check
6857 the next buffer location. */
6858 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6859 && (it
->current
.overlay_string_index
6860 == it
->n_overlay_strings
- 1))
6864 struct text_pos pos
= it
->current
.pos
;
6865 INC_TEXT_POS (pos
, it
->multibyte_p
);
6867 next_face_id
= face_at_buffer_position
6868 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6869 it
->region_end_charpos
, &ignore
,
6870 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6872 it
->end_of_box_run_p
6873 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6880 int face_id
= face_after_it_pos (it
);
6881 it
->end_of_box_run_p
6882 = (face_id
!= it
->face_id
6883 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6886 /* If we reached the end of the object we've been iterating (e.g., a
6887 display string or an overlay string), and there's something on
6888 IT->stack, proceed with what's on the stack. It doesn't make
6889 sense to return zero if there's unprocessed stuff on the stack,
6890 because otherwise that stuff will never be displayed. */
6891 if (!success_p
&& it
->sp
> 0)
6893 set_iterator_to_next (it
, 0);
6894 success_p
= get_next_display_element (it
);
6897 /* Value is 0 if end of buffer or string reached. */
6902 /* Move IT to the next display element.
6904 RESEAT_P non-zero means if called on a newline in buffer text,
6905 skip to the next visible line start.
6907 Functions get_next_display_element and set_iterator_to_next are
6908 separate because I find this arrangement easier to handle than a
6909 get_next_display_element function that also increments IT's
6910 position. The way it is we can first look at an iterator's current
6911 display element, decide whether it fits on a line, and if it does,
6912 increment the iterator position. The other way around we probably
6913 would either need a flag indicating whether the iterator has to be
6914 incremented the next time, or we would have to implement a
6915 decrement position function which would not be easy to write. */
6918 set_iterator_to_next (struct it
*it
, int reseat_p
)
6920 /* Reset flags indicating start and end of a sequence of characters
6921 with box. Reset them at the start of this function because
6922 moving the iterator to a new position might set them. */
6923 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6927 case GET_FROM_BUFFER
:
6928 /* The current display element of IT is a character from
6929 current_buffer. Advance in the buffer, and maybe skip over
6930 invisible lines that are so because of selective display. */
6931 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6932 reseat_at_next_visible_line_start (it
, 0);
6933 else if (it
->cmp_it
.id
>= 0)
6935 /* We are currently getting glyphs from a composition. */
6940 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6941 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6942 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6944 it
->cmp_it
.from
= it
->cmp_it
.to
;
6949 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6951 it
->end_charpos
, Qnil
);
6954 else if (! it
->cmp_it
.reversed_p
)
6956 /* Composition created while scanning forward. */
6957 /* Update IT's char/byte positions to point to the first
6958 character of the next grapheme cluster, or to the
6959 character visually after the current composition. */
6960 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6961 bidi_move_to_visually_next (&it
->bidi_it
);
6962 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6963 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6965 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6967 /* Proceed to the next grapheme cluster. */
6968 it
->cmp_it
.from
= it
->cmp_it
.to
;
6972 /* No more grapheme clusters in this composition.
6973 Find the next stop position. */
6974 ptrdiff_t stop
= it
->end_charpos
;
6975 if (it
->bidi_it
.scan_dir
< 0)
6976 /* Now we are scanning backward and don't know
6979 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6980 IT_BYTEPOS (*it
), stop
, Qnil
);
6985 /* Composition created while scanning backward. */
6986 /* Update IT's char/byte positions to point to the last
6987 character of the previous grapheme cluster, or the
6988 character visually after the current composition. */
6989 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6990 bidi_move_to_visually_next (&it
->bidi_it
);
6991 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6992 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6993 if (it
->cmp_it
.from
> 0)
6995 /* Proceed to the previous grapheme cluster. */
6996 it
->cmp_it
.to
= it
->cmp_it
.from
;
7000 /* No more grapheme clusters in this composition.
7001 Find the next stop position. */
7002 ptrdiff_t stop
= it
->end_charpos
;
7003 if (it
->bidi_it
.scan_dir
< 0)
7004 /* Now we are scanning backward and don't know
7007 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7008 IT_BYTEPOS (*it
), stop
, Qnil
);
7014 eassert (it
->len
!= 0);
7018 IT_BYTEPOS (*it
) += it
->len
;
7019 IT_CHARPOS (*it
) += 1;
7023 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7024 /* If this is a new paragraph, determine its base
7025 direction (a.k.a. its base embedding level). */
7026 if (it
->bidi_it
.new_paragraph
)
7027 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7028 bidi_move_to_visually_next (&it
->bidi_it
);
7029 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7030 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7031 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7033 /* As the scan direction was changed, we must
7034 re-compute the stop position for composition. */
7035 ptrdiff_t stop
= it
->end_charpos
;
7036 if (it
->bidi_it
.scan_dir
< 0)
7038 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7039 IT_BYTEPOS (*it
), stop
, Qnil
);
7042 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7046 case GET_FROM_C_STRING
:
7047 /* Current display element of IT is from a C string. */
7049 /* If the string position is beyond string's end, it means
7050 next_element_from_c_string is padding the string with
7051 blanks, in which case we bypass the bidi iterator,
7052 because it cannot deal with such virtual characters. */
7053 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7055 IT_BYTEPOS (*it
) += it
->len
;
7056 IT_CHARPOS (*it
) += 1;
7060 bidi_move_to_visually_next (&it
->bidi_it
);
7061 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7062 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7066 case GET_FROM_DISPLAY_VECTOR
:
7067 /* Current display element of IT is from a display table entry.
7068 Advance in the display table definition. Reset it to null if
7069 end reached, and continue with characters from buffers/
7071 ++it
->current
.dpvec_index
;
7073 /* Restore face of the iterator to what they were before the
7074 display vector entry (these entries may contain faces). */
7075 it
->face_id
= it
->saved_face_id
;
7077 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7079 int recheck_faces
= it
->ellipsis_p
;
7082 it
->method
= GET_FROM_C_STRING
;
7083 else if (STRINGP (it
->string
))
7084 it
->method
= GET_FROM_STRING
;
7087 it
->method
= GET_FROM_BUFFER
;
7088 it
->object
= WVAR (it
->w
, buffer
);
7092 it
->current
.dpvec_index
= -1;
7094 /* Skip over characters which were displayed via IT->dpvec. */
7095 if (it
->dpvec_char_len
< 0)
7096 reseat_at_next_visible_line_start (it
, 1);
7097 else if (it
->dpvec_char_len
> 0)
7099 if (it
->method
== GET_FROM_STRING
7100 && it
->n_overlay_strings
> 0)
7101 it
->ignore_overlay_strings_at_pos_p
= 1;
7102 it
->len
= it
->dpvec_char_len
;
7103 set_iterator_to_next (it
, reseat_p
);
7106 /* Maybe recheck faces after display vector */
7108 it
->stop_charpos
= IT_CHARPOS (*it
);
7112 case GET_FROM_STRING
:
7113 /* Current display element is a character from a Lisp string. */
7114 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7115 /* Don't advance past string end. These conditions are true
7116 when set_iterator_to_next is called at the end of
7117 get_next_display_element, in which case the Lisp string is
7118 already exhausted, and all we want is pop the iterator
7120 if (it
->current
.overlay_string_index
>= 0)
7122 /* This is an overlay string, so there's no padding with
7123 spaces, and the number of characters in the string is
7124 where the string ends. */
7125 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7126 goto consider_string_end
;
7130 /* Not an overlay string. There could be padding, so test
7131 against it->end_charpos . */
7132 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7133 goto consider_string_end
;
7135 if (it
->cmp_it
.id
>= 0)
7141 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7142 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7143 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7144 it
->cmp_it
.from
= it
->cmp_it
.to
;
7148 composition_compute_stop_pos (&it
->cmp_it
,
7149 IT_STRING_CHARPOS (*it
),
7150 IT_STRING_BYTEPOS (*it
),
7151 it
->end_charpos
, it
->string
);
7154 else if (! it
->cmp_it
.reversed_p
)
7156 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7157 bidi_move_to_visually_next (&it
->bidi_it
);
7158 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7159 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7161 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7162 it
->cmp_it
.from
= it
->cmp_it
.to
;
7165 ptrdiff_t stop
= it
->end_charpos
;
7166 if (it
->bidi_it
.scan_dir
< 0)
7168 composition_compute_stop_pos (&it
->cmp_it
,
7169 IT_STRING_CHARPOS (*it
),
7170 IT_STRING_BYTEPOS (*it
), stop
,
7176 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7177 bidi_move_to_visually_next (&it
->bidi_it
);
7178 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7179 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7180 if (it
->cmp_it
.from
> 0)
7181 it
->cmp_it
.to
= it
->cmp_it
.from
;
7184 ptrdiff_t stop
= it
->end_charpos
;
7185 if (it
->bidi_it
.scan_dir
< 0)
7187 composition_compute_stop_pos (&it
->cmp_it
,
7188 IT_STRING_CHARPOS (*it
),
7189 IT_STRING_BYTEPOS (*it
), stop
,
7197 /* If the string position is beyond string's end, it
7198 means next_element_from_string is padding the string
7199 with blanks, in which case we bypass the bidi
7200 iterator, because it cannot deal with such virtual
7202 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7204 IT_STRING_BYTEPOS (*it
) += it
->len
;
7205 IT_STRING_CHARPOS (*it
) += 1;
7209 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7211 bidi_move_to_visually_next (&it
->bidi_it
);
7212 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7213 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7214 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7216 ptrdiff_t stop
= it
->end_charpos
;
7218 if (it
->bidi_it
.scan_dir
< 0)
7220 composition_compute_stop_pos (&it
->cmp_it
,
7221 IT_STRING_CHARPOS (*it
),
7222 IT_STRING_BYTEPOS (*it
), stop
,
7228 consider_string_end
:
7230 if (it
->current
.overlay_string_index
>= 0)
7232 /* IT->string is an overlay string. Advance to the
7233 next, if there is one. */
7234 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7237 next_overlay_string (it
);
7239 setup_for_ellipsis (it
, 0);
7244 /* IT->string is not an overlay string. If we reached
7245 its end, and there is something on IT->stack, proceed
7246 with what is on the stack. This can be either another
7247 string, this time an overlay string, or a buffer. */
7248 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7252 if (it
->method
== GET_FROM_STRING
)
7253 goto consider_string_end
;
7258 case GET_FROM_IMAGE
:
7259 case GET_FROM_STRETCH
:
7260 /* The position etc with which we have to proceed are on
7261 the stack. The position may be at the end of a string,
7262 if the `display' property takes up the whole string. */
7263 eassert (it
->sp
> 0);
7265 if (it
->method
== GET_FROM_STRING
)
7266 goto consider_string_end
;
7270 /* There are no other methods defined, so this should be a bug. */
7274 eassert (it
->method
!= GET_FROM_STRING
7275 || (STRINGP (it
->string
)
7276 && IT_STRING_CHARPOS (*it
) >= 0));
7279 /* Load IT's display element fields with information about the next
7280 display element which comes from a display table entry or from the
7281 result of translating a control character to one of the forms `^C'
7284 IT->dpvec holds the glyphs to return as characters.
7285 IT->saved_face_id holds the face id before the display vector--it
7286 is restored into IT->face_id in set_iterator_to_next. */
7289 next_element_from_display_vector (struct it
*it
)
7294 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7296 it
->face_id
= it
->saved_face_id
;
7298 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7299 That seemed totally bogus - so I changed it... */
7300 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7302 if (GLYPH_CODE_P (gc
))
7304 it
->c
= GLYPH_CODE_CHAR (gc
);
7305 it
->len
= CHAR_BYTES (it
->c
);
7307 /* The entry may contain a face id to use. Such a face id is
7308 the id of a Lisp face, not a realized face. A face id of
7309 zero means no face is specified. */
7310 if (it
->dpvec_face_id
>= 0)
7311 it
->face_id
= it
->dpvec_face_id
;
7314 int lface_id
= GLYPH_CODE_FACE (gc
);
7316 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7321 /* Display table entry is invalid. Return a space. */
7322 it
->c
= ' ', it
->len
= 1;
7324 /* Don't change position and object of the iterator here. They are
7325 still the values of the character that had this display table
7326 entry or was translated, and that's what we want. */
7327 it
->what
= IT_CHARACTER
;
7331 /* Get the first element of string/buffer in the visual order, after
7332 being reseated to a new position in a string or a buffer. */
7334 get_visually_first_element (struct it
*it
)
7336 int string_p
= STRINGP (it
->string
) || it
->s
;
7337 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7338 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7340 if (STRINGP (it
->string
))
7342 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7343 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7347 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7348 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7351 if (it
->bidi_it
.charpos
== eob
)
7353 /* Nothing to do, but reset the FIRST_ELT flag, like
7354 bidi_paragraph_init does, because we are not going to
7356 it
->bidi_it
.first_elt
= 0;
7358 else if (it
->bidi_it
.charpos
== bob
7360 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7361 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7363 /* If we are at the beginning of a line/string, we can produce
7364 the next element right away. */
7365 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7366 bidi_move_to_visually_next (&it
->bidi_it
);
7370 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7372 /* We need to prime the bidi iterator starting at the line's or
7373 string's beginning, before we will be able to produce the
7376 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7379 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7381 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7383 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7386 /* Now return to buffer/string position where we were asked
7387 to get the next display element, and produce that. */
7388 bidi_move_to_visually_next (&it
->bidi_it
);
7390 while (it
->bidi_it
.bytepos
!= orig_bytepos
7391 && it
->bidi_it
.charpos
< eob
);
7394 /* Adjust IT's position information to where we ended up. */
7395 if (STRINGP (it
->string
))
7397 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7398 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7402 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7403 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7406 if (STRINGP (it
->string
) || !it
->s
)
7408 ptrdiff_t stop
, charpos
, bytepos
;
7410 if (STRINGP (it
->string
))
7413 stop
= SCHARS (it
->string
);
7414 if (stop
> it
->end_charpos
)
7415 stop
= it
->end_charpos
;
7416 charpos
= IT_STRING_CHARPOS (*it
);
7417 bytepos
= IT_STRING_BYTEPOS (*it
);
7421 stop
= it
->end_charpos
;
7422 charpos
= IT_CHARPOS (*it
);
7423 bytepos
= IT_BYTEPOS (*it
);
7425 if (it
->bidi_it
.scan_dir
< 0)
7427 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7432 /* Load IT with the next display element from Lisp string IT->string.
7433 IT->current.string_pos is the current position within the string.
7434 If IT->current.overlay_string_index >= 0, the Lisp string is an
7438 next_element_from_string (struct it
*it
)
7440 struct text_pos position
;
7442 eassert (STRINGP (it
->string
));
7443 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7444 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7445 position
= it
->current
.string_pos
;
7447 /* With bidi reordering, the character to display might not be the
7448 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7449 that we were reseat()ed to a new string, whose paragraph
7450 direction is not known. */
7451 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7453 get_visually_first_element (it
);
7454 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7457 /* Time to check for invisible text? */
7458 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7460 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7463 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7464 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7466 /* With bidi non-linear iteration, we could find
7467 ourselves far beyond the last computed stop_charpos,
7468 with several other stop positions in between that we
7469 missed. Scan them all now, in buffer's logical
7470 order, until we find and handle the last stop_charpos
7471 that precedes our current position. */
7472 handle_stop_backwards (it
, it
->stop_charpos
);
7473 return GET_NEXT_DISPLAY_ELEMENT (it
);
7479 /* Take note of the stop position we just moved
7480 across, for when we will move back across it. */
7481 it
->prev_stop
= it
->stop_charpos
;
7482 /* If we are at base paragraph embedding level, take
7483 note of the last stop position seen at this
7485 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7486 it
->base_level_stop
= it
->stop_charpos
;
7490 /* Since a handler may have changed IT->method, we must
7492 return GET_NEXT_DISPLAY_ELEMENT (it
);
7496 /* If we are before prev_stop, we may have overstepped
7497 on our way backwards a stop_pos, and if so, we need
7498 to handle that stop_pos. */
7499 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7500 /* We can sometimes back up for reasons that have nothing
7501 to do with bidi reordering. E.g., compositions. The
7502 code below is only needed when we are above the base
7503 embedding level, so test for that explicitly. */
7504 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7506 /* If we lost track of base_level_stop, we have no better
7507 place for handle_stop_backwards to start from than string
7508 beginning. This happens, e.g., when we were reseated to
7509 the previous screenful of text by vertical-motion. */
7510 if (it
->base_level_stop
<= 0
7511 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7512 it
->base_level_stop
= 0;
7513 handle_stop_backwards (it
, it
->base_level_stop
);
7514 return GET_NEXT_DISPLAY_ELEMENT (it
);
7518 if (it
->current
.overlay_string_index
>= 0)
7520 /* Get the next character from an overlay string. In overlay
7521 strings, there is no field width or padding with spaces to
7523 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7528 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7529 IT_STRING_BYTEPOS (*it
),
7530 it
->bidi_it
.scan_dir
< 0
7532 : SCHARS (it
->string
))
7533 && next_element_from_composition (it
))
7537 else if (STRING_MULTIBYTE (it
->string
))
7539 const unsigned char *s
= (SDATA (it
->string
)
7540 + IT_STRING_BYTEPOS (*it
));
7541 it
->c
= string_char_and_length (s
, &it
->len
);
7545 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7551 /* Get the next character from a Lisp string that is not an
7552 overlay string. Such strings come from the mode line, for
7553 example. We may have to pad with spaces, or truncate the
7554 string. See also next_element_from_c_string. */
7555 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7560 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7562 /* Pad with spaces. */
7563 it
->c
= ' ', it
->len
= 1;
7564 CHARPOS (position
) = BYTEPOS (position
) = -1;
7566 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7567 IT_STRING_BYTEPOS (*it
),
7568 it
->bidi_it
.scan_dir
< 0
7570 : it
->string_nchars
)
7571 && next_element_from_composition (it
))
7575 else if (STRING_MULTIBYTE (it
->string
))
7577 const unsigned char *s
= (SDATA (it
->string
)
7578 + IT_STRING_BYTEPOS (*it
));
7579 it
->c
= string_char_and_length (s
, &it
->len
);
7583 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7588 /* Record what we have and where it came from. */
7589 it
->what
= IT_CHARACTER
;
7590 it
->object
= it
->string
;
7591 it
->position
= position
;
7596 /* Load IT with next display element from C string IT->s.
7597 IT->string_nchars is the maximum number of characters to return
7598 from the string. IT->end_charpos may be greater than
7599 IT->string_nchars when this function is called, in which case we
7600 may have to return padding spaces. Value is zero if end of string
7601 reached, including padding spaces. */
7604 next_element_from_c_string (struct it
*it
)
7609 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7610 it
->what
= IT_CHARACTER
;
7611 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7614 /* With bidi reordering, the character to display might not be the
7615 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7616 we were reseated to a new string, whose paragraph direction is
7618 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7619 get_visually_first_element (it
);
7621 /* IT's position can be greater than IT->string_nchars in case a
7622 field width or precision has been specified when the iterator was
7624 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7626 /* End of the game. */
7630 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7632 /* Pad with spaces. */
7633 it
->c
= ' ', it
->len
= 1;
7634 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7636 else if (it
->multibyte_p
)
7637 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7639 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7645 /* Set up IT to return characters from an ellipsis, if appropriate.
7646 The definition of the ellipsis glyphs may come from a display table
7647 entry. This function fills IT with the first glyph from the
7648 ellipsis if an ellipsis is to be displayed. */
7651 next_element_from_ellipsis (struct it
*it
)
7653 if (it
->selective_display_ellipsis_p
)
7654 setup_for_ellipsis (it
, it
->len
);
7657 /* The face at the current position may be different from the
7658 face we find after the invisible text. Remember what it
7659 was in IT->saved_face_id, and signal that it's there by
7660 setting face_before_selective_p. */
7661 it
->saved_face_id
= it
->face_id
;
7662 it
->method
= GET_FROM_BUFFER
;
7663 it
->object
= WVAR (it
->w
, buffer
);
7664 reseat_at_next_visible_line_start (it
, 1);
7665 it
->face_before_selective_p
= 1;
7668 return GET_NEXT_DISPLAY_ELEMENT (it
);
7672 /* Deliver an image display element. The iterator IT is already
7673 filled with image information (done in handle_display_prop). Value
7678 next_element_from_image (struct it
*it
)
7680 it
->what
= IT_IMAGE
;
7681 it
->ignore_overlay_strings_at_pos_p
= 0;
7686 /* Fill iterator IT with next display element from a stretch glyph
7687 property. IT->object is the value of the text property. Value is
7691 next_element_from_stretch (struct it
*it
)
7693 it
->what
= IT_STRETCH
;
7697 /* Scan backwards from IT's current position until we find a stop
7698 position, or until BEGV. This is called when we find ourself
7699 before both the last known prev_stop and base_level_stop while
7700 reordering bidirectional text. */
7703 compute_stop_pos_backwards (struct it
*it
)
7705 const int SCAN_BACK_LIMIT
= 1000;
7706 struct text_pos pos
;
7707 struct display_pos save_current
= it
->current
;
7708 struct text_pos save_position
= it
->position
;
7709 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7710 ptrdiff_t where_we_are
= charpos
;
7711 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7712 ptrdiff_t save_end_pos
= it
->end_charpos
;
7714 eassert (NILP (it
->string
) && !it
->s
);
7715 eassert (it
->bidi_p
);
7719 it
->end_charpos
= min (charpos
+ 1, ZV
);
7720 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7721 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7722 reseat_1 (it
, pos
, 0);
7723 compute_stop_pos (it
);
7724 /* We must advance forward, right? */
7725 if (it
->stop_charpos
<= charpos
)
7728 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7730 if (it
->stop_charpos
<= where_we_are
)
7731 it
->prev_stop
= it
->stop_charpos
;
7733 it
->prev_stop
= BEGV
;
7735 it
->current
= save_current
;
7736 it
->position
= save_position
;
7737 it
->stop_charpos
= save_stop_pos
;
7738 it
->end_charpos
= save_end_pos
;
7741 /* Scan forward from CHARPOS in the current buffer/string, until we
7742 find a stop position > current IT's position. Then handle the stop
7743 position before that. This is called when we bump into a stop
7744 position while reordering bidirectional text. CHARPOS should be
7745 the last previously processed stop_pos (or BEGV/0, if none were
7746 processed yet) whose position is less that IT's current
7750 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7752 int bufp
= !STRINGP (it
->string
);
7753 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7754 struct display_pos save_current
= it
->current
;
7755 struct text_pos save_position
= it
->position
;
7756 struct text_pos pos1
;
7757 ptrdiff_t next_stop
;
7759 /* Scan in strict logical order. */
7760 eassert (it
->bidi_p
);
7764 it
->prev_stop
= charpos
;
7767 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7768 reseat_1 (it
, pos1
, 0);
7771 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7772 compute_stop_pos (it
);
7773 /* We must advance forward, right? */
7774 if (it
->stop_charpos
<= it
->prev_stop
)
7776 charpos
= it
->stop_charpos
;
7778 while (charpos
<= where_we_are
);
7781 it
->current
= save_current
;
7782 it
->position
= save_position
;
7783 next_stop
= it
->stop_charpos
;
7784 it
->stop_charpos
= it
->prev_stop
;
7786 it
->stop_charpos
= next_stop
;
7789 /* Load IT with the next display element from current_buffer. Value
7790 is zero if end of buffer reached. IT->stop_charpos is the next
7791 position at which to stop and check for text properties or buffer
7795 next_element_from_buffer (struct it
*it
)
7799 eassert (IT_CHARPOS (*it
) >= BEGV
);
7800 eassert (NILP (it
->string
) && !it
->s
);
7801 eassert (!it
->bidi_p
7802 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7803 && it
->bidi_it
.string
.s
== NULL
));
7805 /* With bidi reordering, the character to display might not be the
7806 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7807 we were reseat()ed to a new buffer position, which is potentially
7808 a different paragraph. */
7809 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7811 get_visually_first_element (it
);
7812 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7815 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7817 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7819 int overlay_strings_follow_p
;
7821 /* End of the game, except when overlay strings follow that
7822 haven't been returned yet. */
7823 if (it
->overlay_strings_at_end_processed_p
)
7824 overlay_strings_follow_p
= 0;
7827 it
->overlay_strings_at_end_processed_p
= 1;
7828 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7831 if (overlay_strings_follow_p
)
7832 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7836 it
->position
= it
->current
.pos
;
7840 else if (!(!it
->bidi_p
7841 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7842 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7844 /* With bidi non-linear iteration, we could find ourselves
7845 far beyond the last computed stop_charpos, with several
7846 other stop positions in between that we missed. Scan
7847 them all now, in buffer's logical order, until we find
7848 and handle the last stop_charpos that precedes our
7849 current position. */
7850 handle_stop_backwards (it
, it
->stop_charpos
);
7851 return GET_NEXT_DISPLAY_ELEMENT (it
);
7857 /* Take note of the stop position we just moved across,
7858 for when we will move back across it. */
7859 it
->prev_stop
= it
->stop_charpos
;
7860 /* If we are at base paragraph embedding level, take
7861 note of the last stop position seen at this
7863 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7864 it
->base_level_stop
= it
->stop_charpos
;
7867 return GET_NEXT_DISPLAY_ELEMENT (it
);
7871 /* If we are before prev_stop, we may have overstepped on
7872 our way backwards a stop_pos, and if so, we need to
7873 handle that stop_pos. */
7874 && IT_CHARPOS (*it
) < it
->prev_stop
7875 /* We can sometimes back up for reasons that have nothing
7876 to do with bidi reordering. E.g., compositions. The
7877 code below is only needed when we are above the base
7878 embedding level, so test for that explicitly. */
7879 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7881 if (it
->base_level_stop
<= 0
7882 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7884 /* If we lost track of base_level_stop, we need to find
7885 prev_stop by looking backwards. This happens, e.g., when
7886 we were reseated to the previous screenful of text by
7888 it
->base_level_stop
= BEGV
;
7889 compute_stop_pos_backwards (it
);
7890 handle_stop_backwards (it
, it
->prev_stop
);
7893 handle_stop_backwards (it
, it
->base_level_stop
);
7894 return GET_NEXT_DISPLAY_ELEMENT (it
);
7898 /* No face changes, overlays etc. in sight, so just return a
7899 character from current_buffer. */
7903 /* Maybe run the redisplay end trigger hook. Performance note:
7904 This doesn't seem to cost measurable time. */
7905 if (it
->redisplay_end_trigger_charpos
7907 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7908 run_redisplay_end_trigger_hook (it
);
7910 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7911 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7913 && next_element_from_composition (it
))
7918 /* Get the next character, maybe multibyte. */
7919 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7920 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7921 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7923 it
->c
= *p
, it
->len
= 1;
7925 /* Record what we have and where it came from. */
7926 it
->what
= IT_CHARACTER
;
7927 it
->object
= WVAR (it
->w
, buffer
);
7928 it
->position
= it
->current
.pos
;
7930 /* Normally we return the character found above, except when we
7931 really want to return an ellipsis for selective display. */
7936 /* A value of selective > 0 means hide lines indented more
7937 than that number of columns. */
7938 if (it
->selective
> 0
7939 && IT_CHARPOS (*it
) + 1 < ZV
7940 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7941 IT_BYTEPOS (*it
) + 1,
7944 success_p
= next_element_from_ellipsis (it
);
7945 it
->dpvec_char_len
= -1;
7948 else if (it
->c
== '\r' && it
->selective
== -1)
7950 /* A value of selective == -1 means that everything from the
7951 CR to the end of the line is invisible, with maybe an
7952 ellipsis displayed for it. */
7953 success_p
= next_element_from_ellipsis (it
);
7954 it
->dpvec_char_len
= -1;
7959 /* Value is zero if end of buffer reached. */
7960 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7965 /* Run the redisplay end trigger hook for IT. */
7968 run_redisplay_end_trigger_hook (struct it
*it
)
7970 Lisp_Object args
[3];
7972 /* IT->glyph_row should be non-null, i.e. we should be actually
7973 displaying something, or otherwise we should not run the hook. */
7974 eassert (it
->glyph_row
);
7976 /* Set up hook arguments. */
7977 args
[0] = Qredisplay_end_trigger_functions
;
7978 args
[1] = it
->window
;
7979 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7980 it
->redisplay_end_trigger_charpos
= 0;
7982 /* Since we are *trying* to run these functions, don't try to run
7983 them again, even if they get an error. */
7984 WVAR (it
->w
, redisplay_end_trigger
) = Qnil
;
7985 Frun_hook_with_args (3, args
);
7987 /* Notice if it changed the face of the character we are on. */
7988 handle_face_prop (it
);
7992 /* Deliver a composition display element. Unlike the other
7993 next_element_from_XXX, this function is not registered in the array
7994 get_next_element[]. It is called from next_element_from_buffer and
7995 next_element_from_string when necessary. */
7998 next_element_from_composition (struct it
*it
)
8000 it
->what
= IT_COMPOSITION
;
8001 it
->len
= it
->cmp_it
.nbytes
;
8002 if (STRINGP (it
->string
))
8006 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8007 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8010 it
->position
= it
->current
.string_pos
;
8011 it
->object
= it
->string
;
8012 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8013 IT_STRING_BYTEPOS (*it
), it
->string
);
8019 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8020 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8023 if (it
->bidi_it
.new_paragraph
)
8024 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8025 /* Resync the bidi iterator with IT's new position.
8026 FIXME: this doesn't support bidirectional text. */
8027 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8028 bidi_move_to_visually_next (&it
->bidi_it
);
8032 it
->position
= it
->current
.pos
;
8033 it
->object
= WVAR (it
->w
, buffer
);
8034 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8035 IT_BYTEPOS (*it
), Qnil
);
8042 /***********************************************************************
8043 Moving an iterator without producing glyphs
8044 ***********************************************************************/
8046 /* Check if iterator is at a position corresponding to a valid buffer
8047 position after some move_it_ call. */
8049 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8050 ((it)->method == GET_FROM_STRING \
8051 ? IT_STRING_CHARPOS (*it) == 0 \
8055 /* Move iterator IT to a specified buffer or X position within one
8056 line on the display without producing glyphs.
8058 OP should be a bit mask including some or all of these bits:
8059 MOVE_TO_X: Stop upon reaching x-position TO_X.
8060 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8061 Regardless of OP's value, stop upon reaching the end of the display line.
8063 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8064 This means, in particular, that TO_X includes window's horizontal
8067 The return value has several possible values that
8068 say what condition caused the scan to stop:
8070 MOVE_POS_MATCH_OR_ZV
8071 - when TO_POS or ZV was reached.
8074 -when TO_X was reached before TO_POS or ZV were reached.
8077 - when we reached the end of the display area and the line must
8081 - when we reached the end of the display area and the line is
8085 - when we stopped at a line end, i.e. a newline or a CR and selective
8088 static enum move_it_result
8089 move_it_in_display_line_to (struct it
*it
,
8090 ptrdiff_t to_charpos
, int to_x
,
8091 enum move_operation_enum op
)
8093 enum move_it_result result
= MOVE_UNDEFINED
;
8094 struct glyph_row
*saved_glyph_row
;
8095 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8096 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8097 void *ppos_data
= NULL
;
8099 enum it_method prev_method
= it
->method
;
8100 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8101 int saw_smaller_pos
= prev_pos
< to_charpos
;
8103 /* Don't produce glyphs in produce_glyphs. */
8104 saved_glyph_row
= it
->glyph_row
;
8105 it
->glyph_row
= NULL
;
8107 /* Use wrap_it to save a copy of IT wherever a word wrap could
8108 occur. Use atpos_it to save a copy of IT at the desired buffer
8109 position, if found, so that we can scan ahead and check if the
8110 word later overshoots the window edge. Use atx_it similarly, for
8116 /* Use ppos_it under bidi reordering to save a copy of IT for the
8117 position > CHARPOS that is the closest to CHARPOS. We restore
8118 that position in IT when we have scanned the entire display line
8119 without finding a match for CHARPOS and all the character
8120 positions are greater than CHARPOS. */
8123 SAVE_IT (ppos_it
, *it
, ppos_data
);
8124 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8125 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8126 SAVE_IT (ppos_it
, *it
, ppos_data
);
8129 #define BUFFER_POS_REACHED_P() \
8130 ((op & MOVE_TO_POS) != 0 \
8131 && BUFFERP (it->object) \
8132 && (IT_CHARPOS (*it) == to_charpos \
8134 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8135 && IT_CHARPOS (*it) > to_charpos) \
8136 || (it->what == IT_COMPOSITION \
8137 && ((IT_CHARPOS (*it) > to_charpos \
8138 && to_charpos >= it->cmp_it.charpos) \
8139 || (IT_CHARPOS (*it) < to_charpos \
8140 && to_charpos <= it->cmp_it.charpos)))) \
8141 && (it->method == GET_FROM_BUFFER \
8142 || (it->method == GET_FROM_DISPLAY_VECTOR \
8143 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8145 /* If there's a line-/wrap-prefix, handle it. */
8146 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8147 && it
->current_y
< it
->last_visible_y
)
8148 handle_line_prefix (it
);
8150 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8151 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8155 int x
, i
, ascent
= 0, descent
= 0;
8157 /* Utility macro to reset an iterator with x, ascent, and descent. */
8158 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8159 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8160 (IT)->max_descent = descent)
8162 /* Stop if we move beyond TO_CHARPOS (after an image or a
8163 display string or stretch glyph). */
8164 if ((op
& MOVE_TO_POS
) != 0
8165 && BUFFERP (it
->object
)
8166 && it
->method
== GET_FROM_BUFFER
8168 /* When the iterator is at base embedding level, we
8169 are guaranteed that characters are delivered for
8170 display in strictly increasing order of their
8171 buffer positions. */
8172 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8173 && IT_CHARPOS (*it
) > to_charpos
)
8175 && (prev_method
== GET_FROM_IMAGE
8176 || prev_method
== GET_FROM_STRETCH
8177 || prev_method
== GET_FROM_STRING
)
8178 /* Passed TO_CHARPOS from left to right. */
8179 && ((prev_pos
< to_charpos
8180 && IT_CHARPOS (*it
) > to_charpos
)
8181 /* Passed TO_CHARPOS from right to left. */
8182 || (prev_pos
> to_charpos
8183 && IT_CHARPOS (*it
) < to_charpos
)))))
8185 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8187 result
= MOVE_POS_MATCH_OR_ZV
;
8190 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8191 /* If wrap_it is valid, the current position might be in a
8192 word that is wrapped. So, save the iterator in
8193 atpos_it and continue to see if wrapping happens. */
8194 SAVE_IT (atpos_it
, *it
, atpos_data
);
8197 /* Stop when ZV reached.
8198 We used to stop here when TO_CHARPOS reached as well, but that is
8199 too soon if this glyph does not fit on this line. So we handle it
8200 explicitly below. */
8201 if (!get_next_display_element (it
))
8203 result
= MOVE_POS_MATCH_OR_ZV
;
8207 if (it
->line_wrap
== TRUNCATE
)
8209 if (BUFFER_POS_REACHED_P ())
8211 result
= MOVE_POS_MATCH_OR_ZV
;
8217 if (it
->line_wrap
== WORD_WRAP
)
8219 if (IT_DISPLAYING_WHITESPACE (it
))
8223 /* We have reached a glyph that follows one or more
8224 whitespace characters. If the position is
8225 already found, we are done. */
8226 if (atpos_it
.sp
>= 0)
8228 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8229 result
= MOVE_POS_MATCH_OR_ZV
;
8234 RESTORE_IT (it
, &atx_it
, atx_data
);
8235 result
= MOVE_X_REACHED
;
8238 /* Otherwise, we can wrap here. */
8239 SAVE_IT (wrap_it
, *it
, wrap_data
);
8245 /* Remember the line height for the current line, in case
8246 the next element doesn't fit on the line. */
8247 ascent
= it
->max_ascent
;
8248 descent
= it
->max_descent
;
8250 /* The call to produce_glyphs will get the metrics of the
8251 display element IT is loaded with. Record the x-position
8252 before this display element, in case it doesn't fit on the
8256 PRODUCE_GLYPHS (it
);
8258 if (it
->area
!= TEXT_AREA
)
8260 prev_method
= it
->method
;
8261 if (it
->method
== GET_FROM_BUFFER
)
8262 prev_pos
= IT_CHARPOS (*it
);
8263 set_iterator_to_next (it
, 1);
8264 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8265 SET_TEXT_POS (this_line_min_pos
,
8266 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8268 && (op
& MOVE_TO_POS
)
8269 && IT_CHARPOS (*it
) > to_charpos
8270 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8271 SAVE_IT (ppos_it
, *it
, ppos_data
);
8275 /* The number of glyphs we get back in IT->nglyphs will normally
8276 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8277 character on a terminal frame, or (iii) a line end. For the
8278 second case, IT->nglyphs - 1 padding glyphs will be present.
8279 (On X frames, there is only one glyph produced for a
8280 composite character.)
8282 The behavior implemented below means, for continuation lines,
8283 that as many spaces of a TAB as fit on the current line are
8284 displayed there. For terminal frames, as many glyphs of a
8285 multi-glyph character are displayed in the current line, too.
8286 This is what the old redisplay code did, and we keep it that
8287 way. Under X, the whole shape of a complex character must
8288 fit on the line or it will be completely displayed in the
8291 Note that both for tabs and padding glyphs, all glyphs have
8295 /* More than one glyph or glyph doesn't fit on line. All
8296 glyphs have the same width. */
8297 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8299 int x_before_this_char
= x
;
8300 int hpos_before_this_char
= it
->hpos
;
8302 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8304 new_x
= x
+ single_glyph_width
;
8306 /* We want to leave anything reaching TO_X to the caller. */
8307 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8309 if (BUFFER_POS_REACHED_P ())
8311 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8312 goto buffer_pos_reached
;
8313 if (atpos_it
.sp
< 0)
8315 SAVE_IT (atpos_it
, *it
, atpos_data
);
8316 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8321 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8324 result
= MOVE_X_REACHED
;
8329 SAVE_IT (atx_it
, *it
, atx_data
);
8330 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8335 if (/* Lines are continued. */
8336 it
->line_wrap
!= TRUNCATE
8337 && (/* And glyph doesn't fit on the line. */
8338 new_x
> it
->last_visible_x
8339 /* Or it fits exactly and we're on a window
8341 || (new_x
== it
->last_visible_x
8342 && FRAME_WINDOW_P (it
->f
)
8343 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8344 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8345 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8347 if (/* IT->hpos == 0 means the very first glyph
8348 doesn't fit on the line, e.g. a wide image. */
8350 || (new_x
== it
->last_visible_x
8351 && FRAME_WINDOW_P (it
->f
)))
8354 it
->current_x
= new_x
;
8356 /* The character's last glyph just barely fits
8358 if (i
== it
->nglyphs
- 1)
8360 /* If this is the destination position,
8361 return a position *before* it in this row,
8362 now that we know it fits in this row. */
8363 if (BUFFER_POS_REACHED_P ())
8365 if (it
->line_wrap
!= WORD_WRAP
8368 it
->hpos
= hpos_before_this_char
;
8369 it
->current_x
= x_before_this_char
;
8370 result
= MOVE_POS_MATCH_OR_ZV
;
8373 if (it
->line_wrap
== WORD_WRAP
8376 SAVE_IT (atpos_it
, *it
, atpos_data
);
8377 atpos_it
.current_x
= x_before_this_char
;
8378 atpos_it
.hpos
= hpos_before_this_char
;
8382 prev_method
= it
->method
;
8383 if (it
->method
== GET_FROM_BUFFER
)
8384 prev_pos
= IT_CHARPOS (*it
);
8385 set_iterator_to_next (it
, 1);
8386 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8387 SET_TEXT_POS (this_line_min_pos
,
8388 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8389 /* On graphical terminals, newlines may
8390 "overflow" into the fringe if
8391 overflow-newline-into-fringe is non-nil.
8392 On text terminals, and on graphical
8393 terminals with no right margin, newlines
8394 may overflow into the last glyph on the
8396 if (!FRAME_WINDOW_P (it
->f
)
8398 && it
->bidi_it
.paragraph_dir
== R2L
)
8399 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8400 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8401 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8403 if (!get_next_display_element (it
))
8405 result
= MOVE_POS_MATCH_OR_ZV
;
8408 if (BUFFER_POS_REACHED_P ())
8410 if (ITERATOR_AT_END_OF_LINE_P (it
))
8411 result
= MOVE_POS_MATCH_OR_ZV
;
8413 result
= MOVE_LINE_CONTINUED
;
8416 if (ITERATOR_AT_END_OF_LINE_P (it
))
8418 result
= MOVE_NEWLINE_OR_CR
;
8425 IT_RESET_X_ASCENT_DESCENT (it
);
8427 if (wrap_it
.sp
>= 0)
8429 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8434 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8436 result
= MOVE_LINE_CONTINUED
;
8440 if (BUFFER_POS_REACHED_P ())
8442 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8443 goto buffer_pos_reached
;
8444 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8446 SAVE_IT (atpos_it
, *it
, atpos_data
);
8447 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8451 if (new_x
> it
->first_visible_x
)
8453 /* Glyph is visible. Increment number of glyphs that
8454 would be displayed. */
8459 if (result
!= MOVE_UNDEFINED
)
8462 else if (BUFFER_POS_REACHED_P ())
8465 IT_RESET_X_ASCENT_DESCENT (it
);
8466 result
= MOVE_POS_MATCH_OR_ZV
;
8469 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8471 /* Stop when TO_X specified and reached. This check is
8472 necessary here because of lines consisting of a line end,
8473 only. The line end will not produce any glyphs and we
8474 would never get MOVE_X_REACHED. */
8475 eassert (it
->nglyphs
== 0);
8476 result
= MOVE_X_REACHED
;
8480 /* Is this a line end? If yes, we're done. */
8481 if (ITERATOR_AT_END_OF_LINE_P (it
))
8483 /* If we are past TO_CHARPOS, but never saw any character
8484 positions smaller than TO_CHARPOS, return
8485 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8487 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8489 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8491 if (IT_CHARPOS (ppos_it
) < ZV
)
8493 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8494 result
= MOVE_POS_MATCH_OR_ZV
;
8497 goto buffer_pos_reached
;
8499 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8500 && IT_CHARPOS (*it
) > to_charpos
)
8501 goto buffer_pos_reached
;
8503 result
= MOVE_NEWLINE_OR_CR
;
8506 result
= MOVE_NEWLINE_OR_CR
;
8510 prev_method
= it
->method
;
8511 if (it
->method
== GET_FROM_BUFFER
)
8512 prev_pos
= IT_CHARPOS (*it
);
8513 /* The current display element has been consumed. Advance
8515 set_iterator_to_next (it
, 1);
8516 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8517 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8518 if (IT_CHARPOS (*it
) < to_charpos
)
8519 saw_smaller_pos
= 1;
8521 && (op
& MOVE_TO_POS
)
8522 && IT_CHARPOS (*it
) >= to_charpos
8523 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8524 SAVE_IT (ppos_it
, *it
, ppos_data
);
8526 /* Stop if lines are truncated and IT's current x-position is
8527 past the right edge of the window now. */
8528 if (it
->line_wrap
== TRUNCATE
8529 && it
->current_x
>= it
->last_visible_x
)
8531 if (!FRAME_WINDOW_P (it
->f
)
8532 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8533 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8534 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8535 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8539 if ((at_eob_p
= !get_next_display_element (it
))
8540 || BUFFER_POS_REACHED_P ()
8541 /* If we are past TO_CHARPOS, but never saw any
8542 character positions smaller than TO_CHARPOS,
8543 return MOVE_POS_MATCH_OR_ZV, like the
8544 unidirectional display did. */
8545 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8547 && IT_CHARPOS (*it
) > to_charpos
))
8550 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8551 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8552 result
= MOVE_POS_MATCH_OR_ZV
;
8555 if (ITERATOR_AT_END_OF_LINE_P (it
))
8557 result
= MOVE_NEWLINE_OR_CR
;
8561 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8563 && IT_CHARPOS (*it
) > to_charpos
)
8565 if (IT_CHARPOS (ppos_it
) < ZV
)
8566 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8567 result
= MOVE_POS_MATCH_OR_ZV
;
8570 result
= MOVE_LINE_TRUNCATED
;
8573 #undef IT_RESET_X_ASCENT_DESCENT
8576 #undef BUFFER_POS_REACHED_P
8578 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8579 restore the saved iterator. */
8580 if (atpos_it
.sp
>= 0)
8581 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8582 else if (atx_it
.sp
>= 0)
8583 RESTORE_IT (it
, &atx_it
, atx_data
);
8588 bidi_unshelve_cache (atpos_data
, 1);
8590 bidi_unshelve_cache (atx_data
, 1);
8592 bidi_unshelve_cache (wrap_data
, 1);
8594 bidi_unshelve_cache (ppos_data
, 1);
8596 /* Restore the iterator settings altered at the beginning of this
8598 it
->glyph_row
= saved_glyph_row
;
8602 /* For external use. */
8604 move_it_in_display_line (struct it
*it
,
8605 ptrdiff_t to_charpos
, int to_x
,
8606 enum move_operation_enum op
)
8608 if (it
->line_wrap
== WORD_WRAP
8609 && (op
& MOVE_TO_X
))
8612 void *save_data
= NULL
;
8615 SAVE_IT (save_it
, *it
, save_data
);
8616 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8617 /* When word-wrap is on, TO_X may lie past the end
8618 of a wrapped line. Then it->current is the
8619 character on the next line, so backtrack to the
8620 space before the wrap point. */
8621 if (skip
== MOVE_LINE_CONTINUED
)
8623 int prev_x
= max (it
->current_x
- 1, 0);
8624 RESTORE_IT (it
, &save_it
, save_data
);
8625 move_it_in_display_line_to
8626 (it
, -1, prev_x
, MOVE_TO_X
);
8629 bidi_unshelve_cache (save_data
, 1);
8632 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8636 /* Move IT forward until it satisfies one or more of the criteria in
8637 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8639 OP is a bit-mask that specifies where to stop, and in particular,
8640 which of those four position arguments makes a difference. See the
8641 description of enum move_operation_enum.
8643 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8644 screen line, this function will set IT to the next position that is
8645 displayed to the right of TO_CHARPOS on the screen. */
8648 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8650 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8651 int line_height
, line_start_x
= 0, reached
= 0;
8652 void *backup_data
= NULL
;
8656 if (op
& MOVE_TO_VPOS
)
8658 /* If no TO_CHARPOS and no TO_X specified, stop at the
8659 start of the line TO_VPOS. */
8660 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8662 if (it
->vpos
== to_vpos
)
8668 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8672 /* TO_VPOS >= 0 means stop at TO_X in the line at
8673 TO_VPOS, or at TO_POS, whichever comes first. */
8674 if (it
->vpos
== to_vpos
)
8680 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8682 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8687 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8689 /* We have reached TO_X but not in the line we want. */
8690 skip
= move_it_in_display_line_to (it
, to_charpos
,
8692 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8700 else if (op
& MOVE_TO_Y
)
8702 struct it it_backup
;
8704 if (it
->line_wrap
== WORD_WRAP
)
8705 SAVE_IT (it_backup
, *it
, backup_data
);
8707 /* TO_Y specified means stop at TO_X in the line containing
8708 TO_Y---or at TO_CHARPOS if this is reached first. The
8709 problem is that we can't really tell whether the line
8710 contains TO_Y before we have completely scanned it, and
8711 this may skip past TO_X. What we do is to first scan to
8714 If TO_X is not specified, use a TO_X of zero. The reason
8715 is to make the outcome of this function more predictable.
8716 If we didn't use TO_X == 0, we would stop at the end of
8717 the line which is probably not what a caller would expect
8719 skip
= move_it_in_display_line_to
8720 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8721 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8723 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8724 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8726 else if (skip
== MOVE_X_REACHED
)
8728 /* If TO_X was reached, we want to know whether TO_Y is
8729 in the line. We know this is the case if the already
8730 scanned glyphs make the line tall enough. Otherwise,
8731 we must check by scanning the rest of the line. */
8732 line_height
= it
->max_ascent
+ it
->max_descent
;
8733 if (to_y
>= it
->current_y
8734 && to_y
< it
->current_y
+ line_height
)
8739 SAVE_IT (it_backup
, *it
, backup_data
);
8740 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8741 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8743 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8744 line_height
= it
->max_ascent
+ it
->max_descent
;
8745 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8747 if (to_y
>= it
->current_y
8748 && to_y
< it
->current_y
+ line_height
)
8750 /* If TO_Y is in this line and TO_X was reached
8751 above, we scanned too far. We have to restore
8752 IT's settings to the ones before skipping. But
8753 keep the more accurate values of max_ascent and
8754 max_descent we've found while skipping the rest
8755 of the line, for the sake of callers, such as
8756 pos_visible_p, that need to know the line
8758 int max_ascent
= it
->max_ascent
;
8759 int max_descent
= it
->max_descent
;
8761 RESTORE_IT (it
, &it_backup
, backup_data
);
8762 it
->max_ascent
= max_ascent
;
8763 it
->max_descent
= max_descent
;
8769 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8775 /* Check whether TO_Y is in this line. */
8776 line_height
= it
->max_ascent
+ it
->max_descent
;
8777 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8779 if (to_y
>= it
->current_y
8780 && to_y
< it
->current_y
+ line_height
)
8782 /* When word-wrap is on, TO_X may lie past the end
8783 of a wrapped line. Then it->current is the
8784 character on the next line, so backtrack to the
8785 space before the wrap point. */
8786 if (skip
== MOVE_LINE_CONTINUED
8787 && it
->line_wrap
== WORD_WRAP
)
8789 int prev_x
= max (it
->current_x
- 1, 0);
8790 RESTORE_IT (it
, &it_backup
, backup_data
);
8791 skip
= move_it_in_display_line_to
8792 (it
, -1, prev_x
, MOVE_TO_X
);
8801 else if (BUFFERP (it
->object
)
8802 && (it
->method
== GET_FROM_BUFFER
8803 || it
->method
== GET_FROM_STRETCH
)
8804 && IT_CHARPOS (*it
) >= to_charpos
8805 /* Under bidi iteration, a call to set_iterator_to_next
8806 can scan far beyond to_charpos if the initial
8807 portion of the next line needs to be reordered. In
8808 that case, give move_it_in_display_line_to another
8811 && it
->bidi_it
.scan_dir
== -1))
8812 skip
= MOVE_POS_MATCH_OR_ZV
;
8814 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8818 case MOVE_POS_MATCH_OR_ZV
:
8822 case MOVE_NEWLINE_OR_CR
:
8823 set_iterator_to_next (it
, 1);
8824 it
->continuation_lines_width
= 0;
8827 case MOVE_LINE_TRUNCATED
:
8828 it
->continuation_lines_width
= 0;
8829 reseat_at_next_visible_line_start (it
, 0);
8830 if ((op
& MOVE_TO_POS
) != 0
8831 && IT_CHARPOS (*it
) > to_charpos
)
8838 case MOVE_LINE_CONTINUED
:
8839 /* For continued lines ending in a tab, some of the glyphs
8840 associated with the tab are displayed on the current
8841 line. Since it->current_x does not include these glyphs,
8842 we use it->last_visible_x instead. */
8845 it
->continuation_lines_width
+= it
->last_visible_x
;
8846 /* When moving by vpos, ensure that the iterator really
8847 advances to the next line (bug#847, bug#969). Fixme:
8848 do we need to do this in other circumstances? */
8849 if (it
->current_x
!= it
->last_visible_x
8850 && (op
& MOVE_TO_VPOS
)
8851 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8853 line_start_x
= it
->current_x
+ it
->pixel_width
8854 - it
->last_visible_x
;
8855 set_iterator_to_next (it
, 0);
8859 it
->continuation_lines_width
+= it
->current_x
;
8866 /* Reset/increment for the next run. */
8867 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8868 it
->current_x
= line_start_x
;
8871 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8873 last_height
= it
->max_ascent
+ it
->max_descent
;
8874 last_max_ascent
= it
->max_ascent
;
8875 it
->max_ascent
= it
->max_descent
= 0;
8880 /* On text terminals, we may stop at the end of a line in the middle
8881 of a multi-character glyph. If the glyph itself is continued,
8882 i.e. it is actually displayed on the next line, don't treat this
8883 stopping point as valid; move to the next line instead (unless
8884 that brings us offscreen). */
8885 if (!FRAME_WINDOW_P (it
->f
)
8887 && IT_CHARPOS (*it
) == to_charpos
8888 && it
->what
== IT_CHARACTER
8890 && it
->line_wrap
== WINDOW_WRAP
8891 && it
->current_x
== it
->last_visible_x
- 1
8894 && it
->vpos
< XFASTINT (WVAR (it
->w
, window_end_vpos
)))
8896 it
->continuation_lines_width
+= it
->current_x
;
8897 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8898 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8900 last_height
= it
->max_ascent
+ it
->max_descent
;
8901 last_max_ascent
= it
->max_ascent
;
8905 bidi_unshelve_cache (backup_data
, 1);
8907 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8911 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8913 If DY > 0, move IT backward at least that many pixels. DY = 0
8914 means move IT backward to the preceding line start or BEGV. This
8915 function may move over more than DY pixels if IT->current_y - DY
8916 ends up in the middle of a line; in this case IT->current_y will be
8917 set to the top of the line moved to. */
8920 move_it_vertically_backward (struct it
*it
, int dy
)
8924 void *it2data
= NULL
, *it3data
= NULL
;
8925 ptrdiff_t start_pos
;
8930 start_pos
= IT_CHARPOS (*it
);
8932 /* Estimate how many newlines we must move back. */
8933 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8935 /* Set the iterator's position that many lines back. */
8936 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8937 back_to_previous_visible_line_start (it
);
8939 /* Reseat the iterator here. When moving backward, we don't want
8940 reseat to skip forward over invisible text, set up the iterator
8941 to deliver from overlay strings at the new position etc. So,
8942 use reseat_1 here. */
8943 reseat_1 (it
, it
->current
.pos
, 1);
8945 /* We are now surely at a line start. */
8946 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8947 reordering is in effect. */
8948 it
->continuation_lines_width
= 0;
8950 /* Move forward and see what y-distance we moved. First move to the
8951 start of the next line so that we get its height. We need this
8952 height to be able to tell whether we reached the specified
8954 SAVE_IT (it2
, *it
, it2data
);
8955 it2
.max_ascent
= it2
.max_descent
= 0;
8958 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8959 MOVE_TO_POS
| MOVE_TO_VPOS
);
8961 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8962 /* If we are in a display string which starts at START_POS,
8963 and that display string includes a newline, and we are
8964 right after that newline (i.e. at the beginning of a
8965 display line), exit the loop, because otherwise we will
8966 infloop, since move_it_to will see that it is already at
8967 START_POS and will not move. */
8968 || (it2
.method
== GET_FROM_STRING
8969 && IT_CHARPOS (it2
) == start_pos
8970 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8971 eassert (IT_CHARPOS (*it
) >= BEGV
);
8972 SAVE_IT (it3
, it2
, it3data
);
8974 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8975 eassert (IT_CHARPOS (*it
) >= BEGV
);
8976 /* H is the actual vertical distance from the position in *IT
8977 and the starting position. */
8978 h
= it2
.current_y
- it
->current_y
;
8979 /* NLINES is the distance in number of lines. */
8980 nlines
= it2
.vpos
- it
->vpos
;
8982 /* Correct IT's y and vpos position
8983 so that they are relative to the starting point. */
8989 /* DY == 0 means move to the start of the screen line. The
8990 value of nlines is > 0 if continuation lines were involved,
8991 or if the original IT position was at start of a line. */
8992 RESTORE_IT (it
, it
, it2data
);
8994 move_it_by_lines (it
, nlines
);
8995 /* The above code moves us to some position NLINES down,
8996 usually to its first glyph (leftmost in an L2R line), but
8997 that's not necessarily the start of the line, under bidi
8998 reordering. We want to get to the character position
8999 that is immediately after the newline of the previous
9002 && !it
->continuation_lines_width
9003 && !STRINGP (it
->string
)
9004 && IT_CHARPOS (*it
) > BEGV
9005 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9008 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
9010 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
9012 bidi_unshelve_cache (it3data
, 1);
9016 /* The y-position we try to reach, relative to *IT.
9017 Note that H has been subtracted in front of the if-statement. */
9018 int target_y
= it
->current_y
+ h
- dy
;
9019 int y0
= it3
.current_y
;
9023 RESTORE_IT (&it3
, &it3
, it3data
);
9024 y1
= line_bottom_y (&it3
);
9025 line_height
= y1
- y0
;
9026 RESTORE_IT (it
, it
, it2data
);
9027 /* If we did not reach target_y, try to move further backward if
9028 we can. If we moved too far backward, try to move forward. */
9029 if (target_y
< it
->current_y
9030 /* This is heuristic. In a window that's 3 lines high, with
9031 a line height of 13 pixels each, recentering with point
9032 on the bottom line will try to move -39/2 = 19 pixels
9033 backward. Try to avoid moving into the first line. */
9034 && (it
->current_y
- target_y
9035 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9036 && IT_CHARPOS (*it
) > BEGV
)
9038 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9039 target_y
- it
->current_y
));
9040 dy
= it
->current_y
- target_y
;
9041 goto move_further_back
;
9043 else if (target_y
>= it
->current_y
+ line_height
9044 && IT_CHARPOS (*it
) < ZV
)
9046 /* Should move forward by at least one line, maybe more.
9048 Note: Calling move_it_by_lines can be expensive on
9049 terminal frames, where compute_motion is used (via
9050 vmotion) to do the job, when there are very long lines
9051 and truncate-lines is nil. That's the reason for
9052 treating terminal frames specially here. */
9054 if (!FRAME_WINDOW_P (it
->f
))
9055 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9060 move_it_by_lines (it
, 1);
9062 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9069 /* Move IT by a specified amount of pixel lines DY. DY negative means
9070 move backwards. DY = 0 means move to start of screen line. At the
9071 end, IT will be on the start of a screen line. */
9074 move_it_vertically (struct it
*it
, int dy
)
9077 move_it_vertically_backward (it
, -dy
);
9080 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9081 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9082 MOVE_TO_POS
| MOVE_TO_Y
);
9083 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9085 /* If buffer ends in ZV without a newline, move to the start of
9086 the line to satisfy the post-condition. */
9087 if (IT_CHARPOS (*it
) == ZV
9089 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9090 move_it_by_lines (it
, 0);
9095 /* Move iterator IT past the end of the text line it is in. */
9098 move_it_past_eol (struct it
*it
)
9100 enum move_it_result rc
;
9102 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9103 if (rc
== MOVE_NEWLINE_OR_CR
)
9104 set_iterator_to_next (it
, 0);
9108 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9109 negative means move up. DVPOS == 0 means move to the start of the
9112 Optimization idea: If we would know that IT->f doesn't use
9113 a face with proportional font, we could be faster for
9114 truncate-lines nil. */
9117 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9120 /* The commented-out optimization uses vmotion on terminals. This
9121 gives bad results, because elements like it->what, on which
9122 callers such as pos_visible_p rely, aren't updated. */
9123 /* struct position pos;
9124 if (!FRAME_WINDOW_P (it->f))
9126 struct text_pos textpos;
9128 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9129 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9130 reseat (it, textpos, 1);
9131 it->vpos += pos.vpos;
9132 it->current_y += pos.vpos;
9138 /* DVPOS == 0 means move to the start of the screen line. */
9139 move_it_vertically_backward (it
, 0);
9140 /* Let next call to line_bottom_y calculate real line height */
9145 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9146 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9148 /* Only move to the next buffer position if we ended up in a
9149 string from display property, not in an overlay string
9150 (before-string or after-string). That is because the
9151 latter don't conceal the underlying buffer position, so
9152 we can ask to move the iterator to the exact position we
9153 are interested in. Note that, even if we are already at
9154 IT_CHARPOS (*it), the call below is not a no-op, as it
9155 will detect that we are at the end of the string, pop the
9156 iterator, and compute it->current_x and it->hpos
9158 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9159 -1, -1, -1, MOVE_TO_POS
);
9165 void *it2data
= NULL
;
9166 ptrdiff_t start_charpos
, i
;
9168 /* Start at the beginning of the screen line containing IT's
9169 position. This may actually move vertically backwards,
9170 in case of overlays, so adjust dvpos accordingly. */
9172 move_it_vertically_backward (it
, 0);
9175 /* Go back -DVPOS visible lines and reseat the iterator there. */
9176 start_charpos
= IT_CHARPOS (*it
);
9177 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9178 back_to_previous_visible_line_start (it
);
9179 reseat (it
, it
->current
.pos
, 1);
9181 /* Move further back if we end up in a string or an image. */
9182 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9184 /* First try to move to start of display line. */
9186 move_it_vertically_backward (it
, 0);
9188 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9190 /* If start of line is still in string or image,
9191 move further back. */
9192 back_to_previous_visible_line_start (it
);
9193 reseat (it
, it
->current
.pos
, 1);
9197 it
->current_x
= it
->hpos
= 0;
9199 /* Above call may have moved too far if continuation lines
9200 are involved. Scan forward and see if it did. */
9201 SAVE_IT (it2
, *it
, it2data
);
9202 it2
.vpos
= it2
.current_y
= 0;
9203 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9204 it
->vpos
-= it2
.vpos
;
9205 it
->current_y
-= it2
.current_y
;
9206 it
->current_x
= it
->hpos
= 0;
9208 /* If we moved too far back, move IT some lines forward. */
9209 if (it2
.vpos
> -dvpos
)
9211 int delta
= it2
.vpos
+ dvpos
;
9213 RESTORE_IT (&it2
, &it2
, it2data
);
9214 SAVE_IT (it2
, *it
, it2data
);
9215 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9216 /* Move back again if we got too far ahead. */
9217 if (IT_CHARPOS (*it
) >= start_charpos
)
9218 RESTORE_IT (it
, &it2
, it2data
);
9220 bidi_unshelve_cache (it2data
, 1);
9223 RESTORE_IT (it
, it
, it2data
);
9227 /* Return 1 if IT points into the middle of a display vector. */
9230 in_display_vector_p (struct it
*it
)
9232 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9233 && it
->current
.dpvec_index
> 0
9234 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9238 /***********************************************************************
9240 ***********************************************************************/
9243 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9247 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9249 Lisp_Object args
[3];
9250 Lisp_Object msg
, fmt
;
9253 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9256 /* Do nothing if called asynchronously. Inserting text into
9257 a buffer may call after-change-functions and alike and
9258 that would means running Lisp asynchronously. */
9259 if (handling_signal
)
9263 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9265 args
[0] = fmt
= build_string (format
);
9268 msg
= Fformat (3, args
);
9270 len
= SBYTES (msg
) + 1;
9271 SAFE_ALLOCA (buffer
, char *, len
);
9272 memcpy (buffer
, SDATA (msg
), len
);
9274 message_dolog (buffer
, len
- 1, 1, 0);
9281 /* Output a newline in the *Messages* buffer if "needs" one. */
9284 message_log_maybe_newline (void)
9286 if (message_log_need_newline
)
9287 message_dolog ("", 0, 1, 0);
9291 /* Add a string M of length NBYTES to the message log, optionally
9292 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9293 nonzero, means interpret the contents of M as multibyte. This
9294 function calls low-level routines in order to bypass text property
9295 hooks, etc. which might not be safe to run.
9297 This may GC (insert may run before/after change hooks),
9298 so the buffer M must NOT point to a Lisp string. */
9301 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9303 const unsigned char *msg
= (const unsigned char *) m
;
9305 if (!NILP (Vmemory_full
))
9308 if (!NILP (Vmessage_log_max
))
9310 struct buffer
*oldbuf
;
9311 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9312 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9313 ptrdiff_t point_at_end
= 0;
9314 ptrdiff_t zv_at_end
= 0;
9315 Lisp_Object old_deactivate_mark
, tem
;
9316 struct gcpro gcpro1
;
9318 old_deactivate_mark
= Vdeactivate_mark
;
9319 oldbuf
= current_buffer
;
9320 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9321 BVAR (current_buffer
, undo_list
) = Qt
;
9323 oldpoint
= message_dolog_marker1
;
9324 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9325 oldbegv
= message_dolog_marker2
;
9326 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9327 oldzv
= message_dolog_marker3
;
9328 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9329 GCPRO1 (old_deactivate_mark
);
9337 BEGV_BYTE
= BEG_BYTE
;
9340 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9342 /* Insert the string--maybe converting multibyte to single byte
9343 or vice versa, so that all the text fits the buffer. */
9345 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9351 /* Convert a multibyte string to single-byte
9352 for the *Message* buffer. */
9353 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9355 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9356 work
[0] = (ASCII_CHAR_P (c
)
9358 : multibyte_char_to_unibyte (c
));
9359 insert_1_both (work
, 1, 1, 1, 0, 0);
9362 else if (! multibyte
9363 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9367 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9368 /* Convert a single-byte string to multibyte
9369 for the *Message* buffer. */
9370 for (i
= 0; i
< nbytes
; i
++)
9373 MAKE_CHAR_MULTIBYTE (c
);
9374 char_bytes
= CHAR_STRING (c
, str
);
9375 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9379 insert_1 (m
, nbytes
, 1, 0, 0);
9383 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9385 insert_1 ("\n", 1, 1, 0, 0);
9387 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9389 this_bol_byte
= PT_BYTE
;
9391 /* See if this line duplicates the previous one.
9392 If so, combine duplicates. */
9395 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9397 prev_bol_byte
= PT_BYTE
;
9399 dups
= message_log_check_duplicate (prev_bol_byte
,
9403 del_range_both (prev_bol
, prev_bol_byte
,
9404 this_bol
, this_bol_byte
, 0);
9407 char dupstr
[sizeof " [ times]"
9408 + INT_STRLEN_BOUND (printmax_t
)];
9410 /* If you change this format, don't forget to also
9411 change message_log_check_duplicate. */
9412 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9413 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9414 insert_1 (dupstr
, duplen
, 1, 0, 1);
9419 /* If we have more than the desired maximum number of lines
9420 in the *Messages* buffer now, delete the oldest ones.
9421 This is safe because we don't have undo in this buffer. */
9423 if (NATNUMP (Vmessage_log_max
))
9425 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9426 -XFASTINT (Vmessage_log_max
) - 1, 0);
9427 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9430 BEGV
= XMARKER (oldbegv
)->charpos
;
9431 BEGV_BYTE
= marker_byte_position (oldbegv
);
9440 ZV
= XMARKER (oldzv
)->charpos
;
9441 ZV_BYTE
= marker_byte_position (oldzv
);
9445 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9447 /* We can't do Fgoto_char (oldpoint) because it will run some
9449 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9450 XMARKER (oldpoint
)->bytepos
);
9453 unchain_marker (XMARKER (oldpoint
));
9454 unchain_marker (XMARKER (oldbegv
));
9455 unchain_marker (XMARKER (oldzv
));
9457 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9458 set_buffer_internal (oldbuf
);
9460 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9461 message_log_need_newline
= !nlflag
;
9462 Vdeactivate_mark
= old_deactivate_mark
;
9467 /* We are at the end of the buffer after just having inserted a newline.
9468 (Note: We depend on the fact we won't be crossing the gap.)
9469 Check to see if the most recent message looks a lot like the previous one.
9470 Return 0 if different, 1 if the new one should just replace it, or a
9471 value N > 1 if we should also append " [N times]". */
9474 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9477 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9479 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9480 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9482 for (i
= 0; i
< len
; i
++)
9484 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9492 if (*p1
++ == ' ' && *p1
++ == '[')
9495 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9496 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9503 /* Display an echo area message M with a specified length of NBYTES
9504 bytes. The string may include null characters. If M is 0, clear
9505 out any existing message, and let the mini-buffer text show
9508 This may GC, so the buffer M must NOT point to a Lisp string. */
9511 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9513 /* First flush out any partial line written with print. */
9514 message_log_maybe_newline ();
9516 message_dolog (m
, nbytes
, 1, multibyte
);
9517 message2_nolog (m
, nbytes
, multibyte
);
9521 /* The non-logging counterpart of message2. */
9524 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9526 struct frame
*sf
= SELECTED_FRAME ();
9527 message_enable_multibyte
= multibyte
;
9529 if (FRAME_INITIAL_P (sf
))
9531 if (noninteractive_need_newline
)
9532 putc ('\n', stderr
);
9533 noninteractive_need_newline
= 0;
9535 fwrite (m
, nbytes
, 1, stderr
);
9536 if (cursor_in_echo_area
== 0)
9537 fprintf (stderr
, "\n");
9540 /* A null message buffer means that the frame hasn't really been
9541 initialized yet. Error messages get reported properly by
9542 cmd_error, so this must be just an informative message; toss it. */
9543 else if (INTERACTIVE
9544 && sf
->glyphs_initialized_p
9545 && FRAME_MESSAGE_BUF (sf
))
9547 Lisp_Object mini_window
;
9550 /* Get the frame containing the mini-buffer
9551 that the selected frame is using. */
9552 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9553 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9555 FRAME_SAMPLE_VISIBILITY (f
);
9556 if (FRAME_VISIBLE_P (sf
)
9557 && ! FRAME_VISIBLE_P (f
))
9558 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9562 set_message (m
, Qnil
, nbytes
, multibyte
);
9563 if (minibuffer_auto_raise
)
9564 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9567 clear_message (1, 1);
9569 do_pending_window_change (0);
9570 echo_area_display (1);
9571 do_pending_window_change (0);
9572 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9573 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9578 /* Display an echo area message M with a specified length of NBYTES
9579 bytes. The string may include null characters. If M is not a
9580 string, clear out any existing message, and let the mini-buffer
9583 This function cancels echoing. */
9586 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9588 struct gcpro gcpro1
;
9591 clear_message (1,1);
9594 /* First flush out any partial line written with print. */
9595 message_log_maybe_newline ();
9601 SAFE_ALLOCA (buffer
, char *, nbytes
);
9602 memcpy (buffer
, SDATA (m
), nbytes
);
9603 message_dolog (buffer
, nbytes
, 1, multibyte
);
9606 message3_nolog (m
, nbytes
, multibyte
);
9612 /* The non-logging version of message3.
9613 This does not cancel echoing, because it is used for echoing.
9614 Perhaps we need to make a separate function for echoing
9615 and make this cancel echoing. */
9618 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9620 struct frame
*sf
= SELECTED_FRAME ();
9621 message_enable_multibyte
= multibyte
;
9623 if (FRAME_INITIAL_P (sf
))
9625 if (noninteractive_need_newline
)
9626 putc ('\n', stderr
);
9627 noninteractive_need_newline
= 0;
9629 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9630 if (cursor_in_echo_area
== 0)
9631 fprintf (stderr
, "\n");
9634 /* A null message buffer means that the frame hasn't really been
9635 initialized yet. Error messages get reported properly by
9636 cmd_error, so this must be just an informative message; toss it. */
9637 else if (INTERACTIVE
9638 && sf
->glyphs_initialized_p
9639 && FRAME_MESSAGE_BUF (sf
))
9641 Lisp_Object mini_window
;
9645 /* Get the frame containing the mini-buffer
9646 that the selected frame is using. */
9647 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9648 frame
= WVAR (XWINDOW (mini_window
), frame
);
9651 FRAME_SAMPLE_VISIBILITY (f
);
9652 if (FRAME_VISIBLE_P (sf
)
9653 && !FRAME_VISIBLE_P (f
))
9654 Fmake_frame_visible (frame
);
9656 if (STRINGP (m
) && SCHARS (m
) > 0)
9658 set_message (NULL
, m
, nbytes
, multibyte
);
9659 if (minibuffer_auto_raise
)
9660 Fraise_frame (frame
);
9661 /* Assume we are not echoing.
9662 (If we are, echo_now will override this.) */
9663 echo_message_buffer
= Qnil
;
9666 clear_message (1, 1);
9668 do_pending_window_change (0);
9669 echo_area_display (1);
9670 do_pending_window_change (0);
9671 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9672 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9677 /* Display a null-terminated echo area message M. If M is 0, clear
9678 out any existing message, and let the mini-buffer text show through.
9680 The buffer M must continue to exist until after the echo area gets
9681 cleared or some other message gets displayed there. Do not pass
9682 text that is stored in a Lisp string. Do not pass text in a buffer
9683 that was alloca'd. */
9686 message1 (const char *m
)
9688 message2 (m
, (m
? strlen (m
) : 0), 0);
9692 /* The non-logging counterpart of message1. */
9695 message1_nolog (const char *m
)
9697 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9700 /* Display a message M which contains a single %s
9701 which gets replaced with STRING. */
9704 message_with_string (const char *m
, Lisp_Object string
, int log
)
9706 CHECK_STRING (string
);
9712 if (noninteractive_need_newline
)
9713 putc ('\n', stderr
);
9714 noninteractive_need_newline
= 0;
9715 fprintf (stderr
, m
, SDATA (string
));
9716 if (!cursor_in_echo_area
)
9717 fprintf (stderr
, "\n");
9721 else if (INTERACTIVE
)
9723 /* The frame whose minibuffer we're going to display the message on.
9724 It may be larger than the selected frame, so we need
9725 to use its buffer, not the selected frame's buffer. */
9726 Lisp_Object mini_window
;
9727 struct frame
*f
, *sf
= SELECTED_FRAME ();
9729 /* Get the frame containing the minibuffer
9730 that the selected frame is using. */
9731 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9732 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9734 /* A null message buffer means that the frame hasn't really been
9735 initialized yet. Error messages get reported properly by
9736 cmd_error, so this must be just an informative message; toss it. */
9737 if (FRAME_MESSAGE_BUF (f
))
9739 Lisp_Object args
[2], msg
;
9740 struct gcpro gcpro1
, gcpro2
;
9742 args
[0] = build_string (m
);
9743 args
[1] = msg
= string
;
9744 GCPRO2 (args
[0], msg
);
9747 msg
= Fformat (2, args
);
9750 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9752 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9756 /* Print should start at the beginning of the message
9757 buffer next time. */
9758 message_buf_print
= 0;
9764 /* Dump an informative message to the minibuf. If M is 0, clear out
9765 any existing message, and let the mini-buffer text show through. */
9768 vmessage (const char *m
, va_list ap
)
9774 if (noninteractive_need_newline
)
9775 putc ('\n', stderr
);
9776 noninteractive_need_newline
= 0;
9777 vfprintf (stderr
, m
, ap
);
9778 if (cursor_in_echo_area
== 0)
9779 fprintf (stderr
, "\n");
9783 else if (INTERACTIVE
)
9785 /* The frame whose mini-buffer we're going to display the message
9786 on. It may be larger than the selected frame, so we need to
9787 use its buffer, not the selected frame's buffer. */
9788 Lisp_Object mini_window
;
9789 struct frame
*f
, *sf
= SELECTED_FRAME ();
9791 /* Get the frame containing the mini-buffer
9792 that the selected frame is using. */
9793 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9794 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9796 /* A null message buffer means that the frame hasn't really been
9797 initialized yet. Error messages get reported properly by
9798 cmd_error, so this must be just an informative message; toss
9800 if (FRAME_MESSAGE_BUF (f
))
9806 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9807 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9809 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9814 /* Print should start at the beginning of the message
9815 buffer next time. */
9816 message_buf_print
= 0;
9822 message (const char *m
, ...)
9832 /* The non-logging version of message. */
9835 message_nolog (const char *m
, ...)
9837 Lisp_Object old_log_max
;
9840 old_log_max
= Vmessage_log_max
;
9841 Vmessage_log_max
= Qnil
;
9843 Vmessage_log_max
= old_log_max
;
9849 /* Display the current message in the current mini-buffer. This is
9850 only called from error handlers in process.c, and is not time
9854 update_echo_area (void)
9856 if (!NILP (echo_area_buffer
[0]))
9859 string
= Fcurrent_message ();
9860 message3 (string
, SBYTES (string
),
9861 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9866 /* Make sure echo area buffers in `echo_buffers' are live.
9867 If they aren't, make new ones. */
9870 ensure_echo_area_buffers (void)
9874 for (i
= 0; i
< 2; ++i
)
9875 if (!BUFFERP (echo_buffer
[i
])
9876 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9879 Lisp_Object old_buffer
;
9882 old_buffer
= echo_buffer
[i
];
9883 echo_buffer
[i
] = Fget_buffer_create
9884 (make_formatted_string (name
, " *Echo Area %d*", i
));
9885 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9886 /* to force word wrap in echo area -
9887 it was decided to postpone this*/
9888 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9890 for (j
= 0; j
< 2; ++j
)
9891 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9892 echo_area_buffer
[j
] = echo_buffer
[i
];
9897 /* Call FN with args A1..A4 with either the current or last displayed
9898 echo_area_buffer as current buffer.
9900 WHICH zero means use the current message buffer
9901 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9902 from echo_buffer[] and clear it.
9904 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9905 suitable buffer from echo_buffer[] and clear it.
9907 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9908 that the current message becomes the last displayed one, make
9909 choose a suitable buffer for echo_area_buffer[0], and clear it.
9911 Value is what FN returns. */
9914 with_echo_area_buffer (struct window
*w
, int which
,
9915 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9916 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9919 int this_one
, the_other
, clear_buffer_p
, rc
;
9920 ptrdiff_t count
= SPECPDL_INDEX ();
9922 /* If buffers aren't live, make new ones. */
9923 ensure_echo_area_buffers ();
9928 this_one
= 0, the_other
= 1;
9930 this_one
= 1, the_other
= 0;
9933 this_one
= 0, the_other
= 1;
9936 /* We need a fresh one in case the current echo buffer equals
9937 the one containing the last displayed echo area message. */
9938 if (!NILP (echo_area_buffer
[this_one
])
9939 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9940 echo_area_buffer
[this_one
] = Qnil
;
9943 /* Choose a suitable buffer from echo_buffer[] is we don't
9945 if (NILP (echo_area_buffer
[this_one
]))
9947 echo_area_buffer
[this_one
]
9948 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9949 ? echo_buffer
[the_other
]
9950 : echo_buffer
[this_one
]);
9954 buffer
= echo_area_buffer
[this_one
];
9956 /* Don't get confused by reusing the buffer used for echoing
9957 for a different purpose. */
9958 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9961 record_unwind_protect (unwind_with_echo_area_buffer
,
9962 with_echo_area_buffer_unwind_data (w
));
9964 /* Make the echo area buffer current. Note that for display
9965 purposes, it is not necessary that the displayed window's buffer
9966 == current_buffer, except for text property lookup. So, let's
9967 only set that buffer temporarily here without doing a full
9968 Fset_window_buffer. We must also change w->pointm, though,
9969 because otherwise an assertions in unshow_buffer fails, and Emacs
9971 set_buffer_internal_1 (XBUFFER (buffer
));
9974 WVAR (w
, buffer
) = buffer
;
9975 set_marker_both (WVAR (w
, pointm
), buffer
, BEG
, BEG_BYTE
);
9978 BVAR (current_buffer
, undo_list
) = Qt
;
9979 BVAR (current_buffer
, read_only
) = Qnil
;
9980 specbind (Qinhibit_read_only
, Qt
);
9981 specbind (Qinhibit_modification_hooks
, Qt
);
9983 if (clear_buffer_p
&& Z
> BEG
)
9986 eassert (BEGV
>= BEG
);
9987 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9989 rc
= fn (a1
, a2
, a3
, a4
);
9991 eassert (BEGV
>= BEG
);
9992 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9994 unbind_to (count
, Qnil
);
9999 /* Save state that should be preserved around the call to the function
10000 FN called in with_echo_area_buffer. */
10003 with_echo_area_buffer_unwind_data (struct window
*w
)
10006 Lisp_Object vector
, tmp
;
10008 /* Reduce consing by keeping one vector in
10009 Vwith_echo_area_save_vector. */
10010 vector
= Vwith_echo_area_save_vector
;
10011 Vwith_echo_area_save_vector
= Qnil
;
10014 vector
= Fmake_vector (make_number (7), Qnil
);
10016 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10017 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10018 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10022 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10023 ASET (vector
, i
, WVAR (w
, buffer
)); ++i
;
10024 ASET (vector
, i
, make_number (XMARKER (WVAR (w
, pointm
))->charpos
)); ++i
;
10025 ASET (vector
, i
, make_number (XMARKER (WVAR (w
, pointm
))->bytepos
)); ++i
;
10030 for (; i
< end
; ++i
)
10031 ASET (vector
, i
, Qnil
);
10034 eassert (i
== ASIZE (vector
));
10039 /* Restore global state from VECTOR which was created by
10040 with_echo_area_buffer_unwind_data. */
10043 unwind_with_echo_area_buffer (Lisp_Object vector
)
10045 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10046 Vdeactivate_mark
= AREF (vector
, 1);
10047 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10049 if (WINDOWP (AREF (vector
, 3)))
10052 Lisp_Object buffer
, charpos
, bytepos
;
10054 w
= XWINDOW (AREF (vector
, 3));
10055 buffer
= AREF (vector
, 4);
10056 charpos
= AREF (vector
, 5);
10057 bytepos
= AREF (vector
, 6);
10059 WVAR (w
, buffer
) = buffer
;
10060 set_marker_both (WVAR (w
, pointm
), buffer
,
10061 XFASTINT (charpos
), XFASTINT (bytepos
));
10064 Vwith_echo_area_save_vector
= vector
;
10069 /* Set up the echo area for use by print functions. MULTIBYTE_P
10070 non-zero means we will print multibyte. */
10073 setup_echo_area_for_printing (int multibyte_p
)
10075 /* If we can't find an echo area any more, exit. */
10076 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10077 Fkill_emacs (Qnil
);
10079 ensure_echo_area_buffers ();
10081 if (!message_buf_print
)
10083 /* A message has been output since the last time we printed.
10084 Choose a fresh echo area buffer. */
10085 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10086 echo_area_buffer
[0] = echo_buffer
[1];
10088 echo_area_buffer
[0] = echo_buffer
[0];
10090 /* Switch to that buffer and clear it. */
10091 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10092 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10096 ptrdiff_t count
= SPECPDL_INDEX ();
10097 specbind (Qinhibit_read_only
, Qt
);
10098 /* Note that undo recording is always disabled. */
10099 del_range (BEG
, Z
);
10100 unbind_to (count
, Qnil
);
10102 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10104 /* Set up the buffer for the multibyteness we need. */
10106 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10107 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10109 /* Raise the frame containing the echo area. */
10110 if (minibuffer_auto_raise
)
10112 struct frame
*sf
= SELECTED_FRAME ();
10113 Lisp_Object mini_window
;
10114 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10115 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10118 message_log_maybe_newline ();
10119 message_buf_print
= 1;
10123 if (NILP (echo_area_buffer
[0]))
10125 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10126 echo_area_buffer
[0] = echo_buffer
[1];
10128 echo_area_buffer
[0] = echo_buffer
[0];
10131 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10133 /* Someone switched buffers between print requests. */
10134 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10135 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10141 /* Display an echo area message in window W. Value is non-zero if W's
10142 height is changed. If display_last_displayed_message_p is
10143 non-zero, display the message that was last displayed, otherwise
10144 display the current message. */
10147 display_echo_area (struct window
*w
)
10149 int i
, no_message_p
, window_height_changed_p
;
10151 /* Temporarily disable garbage collections while displaying the echo
10152 area. This is done because a GC can print a message itself.
10153 That message would modify the echo area buffer's contents while a
10154 redisplay of the buffer is going on, and seriously confuse
10156 ptrdiff_t count
= inhibit_garbage_collection ();
10158 /* If there is no message, we must call display_echo_area_1
10159 nevertheless because it resizes the window. But we will have to
10160 reset the echo_area_buffer in question to nil at the end because
10161 with_echo_area_buffer will sets it to an empty buffer. */
10162 i
= display_last_displayed_message_p
? 1 : 0;
10163 no_message_p
= NILP (echo_area_buffer
[i
]);
10165 window_height_changed_p
10166 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10167 display_echo_area_1
,
10168 (intptr_t) w
, Qnil
, 0, 0);
10171 echo_area_buffer
[i
] = Qnil
;
10173 unbind_to (count
, Qnil
);
10174 return window_height_changed_p
;
10178 /* Helper for display_echo_area. Display the current buffer which
10179 contains the current echo area message in window W, a mini-window,
10180 a pointer to which is passed in A1. A2..A4 are currently not used.
10181 Change the height of W so that all of the message is displayed.
10182 Value is non-zero if height of W was changed. */
10185 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10188 struct window
*w
= (struct window
*) i1
;
10189 Lisp_Object window
;
10190 struct text_pos start
;
10191 int window_height_changed_p
= 0;
10193 /* Do this before displaying, so that we have a large enough glyph
10194 matrix for the display. If we can't get enough space for the
10195 whole text, display the last N lines. That works by setting w->start. */
10196 window_height_changed_p
= resize_mini_window (w
, 0);
10198 /* Use the starting position chosen by resize_mini_window. */
10199 SET_TEXT_POS_FROM_MARKER (start
, WVAR (w
, start
));
10202 clear_glyph_matrix (w
->desired_matrix
);
10203 XSETWINDOW (window
, w
);
10204 try_window (window
, start
, 0);
10206 return window_height_changed_p
;
10210 /* Resize the echo area window to exactly the size needed for the
10211 currently displayed message, if there is one. If a mini-buffer
10212 is active, don't shrink it. */
10215 resize_echo_area_exactly (void)
10217 if (BUFFERP (echo_area_buffer
[0])
10218 && WINDOWP (echo_area_window
))
10220 struct window
*w
= XWINDOW (echo_area_window
);
10222 Lisp_Object resize_exactly
;
10224 if (minibuf_level
== 0)
10225 resize_exactly
= Qt
;
10227 resize_exactly
= Qnil
;
10229 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10230 (intptr_t) w
, resize_exactly
,
10234 ++windows_or_buffers_changed
;
10235 ++update_mode_lines
;
10236 redisplay_internal ();
10242 /* Callback function for with_echo_area_buffer, when used from
10243 resize_echo_area_exactly. A1 contains a pointer to the window to
10244 resize, EXACTLY non-nil means resize the mini-window exactly to the
10245 size of the text displayed. A3 and A4 are not used. Value is what
10246 resize_mini_window returns. */
10249 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10252 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10256 /* Resize mini-window W to fit the size of its contents. EXACT_P
10257 means size the window exactly to the size needed. Otherwise, it's
10258 only enlarged until W's buffer is empty.
10260 Set W->start to the right place to begin display. If the whole
10261 contents fit, start at the beginning. Otherwise, start so as
10262 to make the end of the contents appear. This is particularly
10263 important for y-or-n-p, but seems desirable generally.
10265 Value is non-zero if the window height has been changed. */
10268 resize_mini_window (struct window
*w
, int exact_p
)
10270 struct frame
*f
= XFRAME (WVAR (w
, frame
));
10271 int window_height_changed_p
= 0;
10273 eassert (MINI_WINDOW_P (w
));
10275 /* By default, start display at the beginning. */
10276 set_marker_both (WVAR (w
, start
), WVAR (w
, buffer
),
10277 BUF_BEGV (XBUFFER (WVAR (w
, buffer
))),
10278 BUF_BEGV_BYTE (XBUFFER (WVAR (w
, buffer
))));
10280 /* Don't resize windows while redisplaying a window; it would
10281 confuse redisplay functions when the size of the window they are
10282 displaying changes from under them. Such a resizing can happen,
10283 for instance, when which-func prints a long message while
10284 we are running fontification-functions. We're running these
10285 functions with safe_call which binds inhibit-redisplay to t. */
10286 if (!NILP (Vinhibit_redisplay
))
10289 /* Nil means don't try to resize. */
10290 if (NILP (Vresize_mini_windows
)
10291 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10294 if (!FRAME_MINIBUF_ONLY_P (f
))
10297 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10298 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10300 EMACS_INT max_height
;
10301 int unit
= FRAME_LINE_HEIGHT (f
);
10302 struct text_pos start
;
10303 struct buffer
*old_current_buffer
= NULL
;
10305 if (current_buffer
!= XBUFFER (WVAR (w
, buffer
)))
10307 old_current_buffer
= current_buffer
;
10308 set_buffer_internal (XBUFFER (WVAR (w
, buffer
)));
10311 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10313 /* Compute the max. number of lines specified by the user. */
10314 if (FLOATP (Vmax_mini_window_height
))
10315 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10316 else if (INTEGERP (Vmax_mini_window_height
))
10317 max_height
= XINT (Vmax_mini_window_height
);
10319 max_height
= total_height
/ 4;
10321 /* Correct that max. height if it's bogus. */
10322 max_height
= max (1, max_height
);
10323 max_height
= min (total_height
, max_height
);
10325 /* Find out the height of the text in the window. */
10326 if (it
.line_wrap
== TRUNCATE
)
10331 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10332 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10333 height
= it
.current_y
+ last_height
;
10335 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10336 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10337 height
= (height
+ unit
- 1) / unit
;
10340 /* Compute a suitable window start. */
10341 if (height
> max_height
)
10343 height
= max_height
;
10344 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10345 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10346 start
= it
.current
.pos
;
10349 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10350 SET_MARKER_FROM_TEXT_POS (WVAR (w
, start
), start
);
10352 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10354 /* Let it grow only, until we display an empty message, in which
10355 case the window shrinks again. */
10356 if (height
> WINDOW_TOTAL_LINES (w
))
10358 int old_height
= WINDOW_TOTAL_LINES (w
);
10359 freeze_window_starts (f
, 1);
10360 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10361 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10363 else if (height
< WINDOW_TOTAL_LINES (w
)
10364 && (exact_p
|| BEGV
== ZV
))
10366 int old_height
= WINDOW_TOTAL_LINES (w
);
10367 freeze_window_starts (f
, 0);
10368 shrink_mini_window (w
);
10369 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10374 /* Always resize to exact size needed. */
10375 if (height
> WINDOW_TOTAL_LINES (w
))
10377 int old_height
= WINDOW_TOTAL_LINES (w
);
10378 freeze_window_starts (f
, 1);
10379 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10380 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10382 else if (height
< WINDOW_TOTAL_LINES (w
))
10384 int old_height
= WINDOW_TOTAL_LINES (w
);
10385 freeze_window_starts (f
, 0);
10386 shrink_mini_window (w
);
10390 freeze_window_starts (f
, 1);
10391 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10394 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10398 if (old_current_buffer
)
10399 set_buffer_internal (old_current_buffer
);
10402 return window_height_changed_p
;
10406 /* Value is the current message, a string, or nil if there is no
10407 current message. */
10410 current_message (void)
10414 if (!BUFFERP (echo_area_buffer
[0]))
10418 with_echo_area_buffer (0, 0, current_message_1
,
10419 (intptr_t) &msg
, Qnil
, 0, 0);
10421 echo_area_buffer
[0] = Qnil
;
10429 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10432 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10435 *msg
= make_buffer_string (BEG
, Z
, 1);
10442 /* Push the current message on Vmessage_stack for later restoration
10443 by restore_message. Value is non-zero if the current message isn't
10444 empty. This is a relatively infrequent operation, so it's not
10445 worth optimizing. */
10448 push_message (void)
10451 msg
= current_message ();
10452 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10453 return STRINGP (msg
);
10457 /* Restore message display from the top of Vmessage_stack. */
10460 restore_message (void)
10464 eassert (CONSP (Vmessage_stack
));
10465 msg
= XCAR (Vmessage_stack
);
10467 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10469 message3_nolog (msg
, 0, 0);
10473 /* Handler for record_unwind_protect calling pop_message. */
10476 pop_message_unwind (Lisp_Object dummy
)
10482 /* Pop the top-most entry off Vmessage_stack. */
10487 eassert (CONSP (Vmessage_stack
));
10488 Vmessage_stack
= XCDR (Vmessage_stack
);
10492 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10493 exits. If the stack is not empty, we have a missing pop_message
10497 check_message_stack (void)
10499 if (!NILP (Vmessage_stack
))
10504 /* Truncate to NCHARS what will be displayed in the echo area the next
10505 time we display it---but don't redisplay it now. */
10508 truncate_echo_area (ptrdiff_t nchars
)
10511 echo_area_buffer
[0] = Qnil
;
10512 /* A null message buffer means that the frame hasn't really been
10513 initialized yet. Error messages get reported properly by
10514 cmd_error, so this must be just an informative message; toss it. */
10515 else if (!noninteractive
10517 && !NILP (echo_area_buffer
[0]))
10519 struct frame
*sf
= SELECTED_FRAME ();
10520 if (FRAME_MESSAGE_BUF (sf
))
10521 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10526 /* Helper function for truncate_echo_area. Truncate the current
10527 message to at most NCHARS characters. */
10530 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10532 if (BEG
+ nchars
< Z
)
10533 del_range (BEG
+ nchars
, Z
);
10535 echo_area_buffer
[0] = Qnil
;
10540 /* Set the current message to a substring of S or STRING.
10542 If STRING is a Lisp string, set the message to the first NBYTES
10543 bytes from STRING. NBYTES zero means use the whole string. If
10544 STRING is multibyte, the message will be displayed multibyte.
10546 If S is not null, set the message to the first LEN bytes of S. LEN
10547 zero means use the whole string. MULTIBYTE_P non-zero means S is
10548 multibyte. Display the message multibyte in that case.
10550 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10551 to t before calling set_message_1 (which calls insert).
10555 set_message (const char *s
, Lisp_Object string
,
10556 ptrdiff_t nbytes
, int multibyte_p
)
10558 message_enable_multibyte
10559 = ((s
&& multibyte_p
)
10560 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10562 with_echo_area_buffer (0, -1, set_message_1
,
10563 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10564 message_buf_print
= 0;
10565 help_echo_showing_p
= 0;
10569 /* Helper function for set_message. Arguments have the same meaning
10570 as there, with A1 corresponding to S and A2 corresponding to STRING
10571 This function is called with the echo area buffer being
10575 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10578 const char *s
= (const char *) i1
;
10579 const unsigned char *msg
= (const unsigned char *) s
;
10580 Lisp_Object string
= a2
;
10582 /* Change multibyteness of the echo buffer appropriately. */
10583 if (message_enable_multibyte
10584 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10585 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10587 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10588 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10589 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10591 /* Insert new message at BEG. */
10592 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10594 if (STRINGP (string
))
10599 nbytes
= SBYTES (string
);
10600 nchars
= string_byte_to_char (string
, nbytes
);
10602 /* This function takes care of single/multibyte conversion. We
10603 just have to ensure that the echo area buffer has the right
10604 setting of enable_multibyte_characters. */
10605 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10610 nbytes
= strlen (s
);
10612 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10614 /* Convert from multi-byte to single-byte. */
10619 /* Convert a multibyte string to single-byte. */
10620 for (i
= 0; i
< nbytes
; i
+= n
)
10622 c
= string_char_and_length (msg
+ i
, &n
);
10623 work
[0] = (ASCII_CHAR_P (c
)
10625 : multibyte_char_to_unibyte (c
));
10626 insert_1_both (work
, 1, 1, 1, 0, 0);
10629 else if (!multibyte_p
10630 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10632 /* Convert from single-byte to multi-byte. */
10635 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10637 /* Convert a single-byte string to multibyte. */
10638 for (i
= 0; i
< nbytes
; i
++)
10641 MAKE_CHAR_MULTIBYTE (c
);
10642 n
= CHAR_STRING (c
, str
);
10643 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10647 insert_1 (s
, nbytes
, 1, 0, 0);
10654 /* Clear messages. CURRENT_P non-zero means clear the current
10655 message. LAST_DISPLAYED_P non-zero means clear the message
10659 clear_message (int current_p
, int last_displayed_p
)
10663 echo_area_buffer
[0] = Qnil
;
10664 message_cleared_p
= 1;
10667 if (last_displayed_p
)
10668 echo_area_buffer
[1] = Qnil
;
10670 message_buf_print
= 0;
10673 /* Clear garbaged frames.
10675 This function is used where the old redisplay called
10676 redraw_garbaged_frames which in turn called redraw_frame which in
10677 turn called clear_frame. The call to clear_frame was a source of
10678 flickering. I believe a clear_frame is not necessary. It should
10679 suffice in the new redisplay to invalidate all current matrices,
10680 and ensure a complete redisplay of all windows. */
10683 clear_garbaged_frames (void)
10685 if (frame_garbaged
)
10687 Lisp_Object tail
, frame
;
10688 int changed_count
= 0;
10690 FOR_EACH_FRAME (tail
, frame
)
10692 struct frame
*f
= XFRAME (frame
);
10694 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10698 Fredraw_frame (frame
);
10699 f
->force_flush_display_p
= 1;
10701 clear_current_matrices (f
);
10708 frame_garbaged
= 0;
10710 ++windows_or_buffers_changed
;
10715 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10716 is non-zero update selected_frame. Value is non-zero if the
10717 mini-windows height has been changed. */
10720 echo_area_display (int update_frame_p
)
10722 Lisp_Object mini_window
;
10725 int window_height_changed_p
= 0;
10726 struct frame
*sf
= SELECTED_FRAME ();
10728 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10729 w
= XWINDOW (mini_window
);
10730 f
= XFRAME (WINDOW_FRAME (w
));
10732 /* Don't display if frame is invisible or not yet initialized. */
10733 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10736 #ifdef HAVE_WINDOW_SYSTEM
10737 /* When Emacs starts, selected_frame may be the initial terminal
10738 frame. If we let this through, a message would be displayed on
10740 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10742 #endif /* HAVE_WINDOW_SYSTEM */
10744 /* Redraw garbaged frames. */
10745 if (frame_garbaged
)
10746 clear_garbaged_frames ();
10748 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10750 echo_area_window
= mini_window
;
10751 window_height_changed_p
= display_echo_area (w
);
10752 w
->must_be_updated_p
= 1;
10754 /* Update the display, unless called from redisplay_internal.
10755 Also don't update the screen during redisplay itself. The
10756 update will happen at the end of redisplay, and an update
10757 here could cause confusion. */
10758 if (update_frame_p
&& !redisplaying_p
)
10762 /* If the display update has been interrupted by pending
10763 input, update mode lines in the frame. Due to the
10764 pending input, it might have been that redisplay hasn't
10765 been called, so that mode lines above the echo area are
10766 garbaged. This looks odd, so we prevent it here. */
10767 if (!display_completed
)
10768 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10770 if (window_height_changed_p
10771 /* Don't do this if Emacs is shutting down. Redisplay
10772 needs to run hooks. */
10773 && !NILP (Vrun_hooks
))
10775 /* Must update other windows. Likewise as in other
10776 cases, don't let this update be interrupted by
10778 ptrdiff_t count
= SPECPDL_INDEX ();
10779 specbind (Qredisplay_dont_pause
, Qt
);
10780 windows_or_buffers_changed
= 1;
10781 redisplay_internal ();
10782 unbind_to (count
, Qnil
);
10784 else if (FRAME_WINDOW_P (f
) && n
== 0)
10786 /* Window configuration is the same as before.
10787 Can do with a display update of the echo area,
10788 unless we displayed some mode lines. */
10789 update_single_window (w
, 1);
10790 FRAME_RIF (f
)->flush_display (f
);
10793 update_frame (f
, 1, 1);
10795 /* If cursor is in the echo area, make sure that the next
10796 redisplay displays the minibuffer, so that the cursor will
10797 be replaced with what the minibuffer wants. */
10798 if (cursor_in_echo_area
)
10799 ++windows_or_buffers_changed
;
10802 else if (!EQ (mini_window
, selected_window
))
10803 windows_or_buffers_changed
++;
10805 /* Last displayed message is now the current message. */
10806 echo_area_buffer
[1] = echo_area_buffer
[0];
10807 /* Inform read_char that we're not echoing. */
10808 echo_message_buffer
= Qnil
;
10810 /* Prevent redisplay optimization in redisplay_internal by resetting
10811 this_line_start_pos. This is done because the mini-buffer now
10812 displays the message instead of its buffer text. */
10813 if (EQ (mini_window
, selected_window
))
10814 CHARPOS (this_line_start_pos
) = 0;
10816 return window_height_changed_p
;
10821 /***********************************************************************
10822 Mode Lines and Frame Titles
10823 ***********************************************************************/
10825 /* A buffer for constructing non-propertized mode-line strings and
10826 frame titles in it; allocated from the heap in init_xdisp and
10827 resized as needed in store_mode_line_noprop_char. */
10829 static char *mode_line_noprop_buf
;
10831 /* The buffer's end, and a current output position in it. */
10833 static char *mode_line_noprop_buf_end
;
10834 static char *mode_line_noprop_ptr
;
10836 #define MODE_LINE_NOPROP_LEN(start) \
10837 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10840 MODE_LINE_DISPLAY
= 0,
10844 } mode_line_target
;
10846 /* Alist that caches the results of :propertize.
10847 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10848 static Lisp_Object mode_line_proptrans_alist
;
10850 /* List of strings making up the mode-line. */
10851 static Lisp_Object mode_line_string_list
;
10853 /* Base face property when building propertized mode line string. */
10854 static Lisp_Object mode_line_string_face
;
10855 static Lisp_Object mode_line_string_face_prop
;
10858 /* Unwind data for mode line strings */
10860 static Lisp_Object Vmode_line_unwind_vector
;
10863 format_mode_line_unwind_data (struct frame
*target_frame
,
10864 struct buffer
*obuf
,
10866 int save_proptrans
)
10868 Lisp_Object vector
, tmp
;
10870 /* Reduce consing by keeping one vector in
10871 Vwith_echo_area_save_vector. */
10872 vector
= Vmode_line_unwind_vector
;
10873 Vmode_line_unwind_vector
= Qnil
;
10876 vector
= Fmake_vector (make_number (10), Qnil
);
10878 ASET (vector
, 0, make_number (mode_line_target
));
10879 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10880 ASET (vector
, 2, mode_line_string_list
);
10881 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10882 ASET (vector
, 4, mode_line_string_face
);
10883 ASET (vector
, 5, mode_line_string_face_prop
);
10886 XSETBUFFER (tmp
, obuf
);
10889 ASET (vector
, 6, tmp
);
10890 ASET (vector
, 7, owin
);
10893 /* Similarly to `with-selected-window', if the operation selects
10894 a window on another frame, we must restore that frame's
10895 selected window, and (for a tty) the top-frame. */
10896 ASET (vector
, 8, FVAR (target_frame
, selected_window
));
10897 if (FRAME_TERMCAP_P (target_frame
))
10898 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10905 unwind_format_mode_line (Lisp_Object vector
)
10907 Lisp_Object old_window
= AREF (vector
, 7);
10908 Lisp_Object target_frame_window
= AREF (vector
, 8);
10909 Lisp_Object old_top_frame
= AREF (vector
, 9);
10911 mode_line_target
= XINT (AREF (vector
, 0));
10912 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10913 mode_line_string_list
= AREF (vector
, 2);
10914 if (! EQ (AREF (vector
, 3), Qt
))
10915 mode_line_proptrans_alist
= AREF (vector
, 3);
10916 mode_line_string_face
= AREF (vector
, 4);
10917 mode_line_string_face_prop
= AREF (vector
, 5);
10919 /* Select window before buffer, since it may change the buffer. */
10920 if (!NILP (old_window
))
10922 /* If the operation that we are unwinding had selected a window
10923 on a different frame, reset its frame-selected-window. For a
10924 text terminal, reset its top-frame if necessary. */
10925 if (!NILP (target_frame_window
))
10928 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10930 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10931 Fselect_window (target_frame_window
, Qt
);
10933 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10934 Fselect_frame (old_top_frame
, Qt
);
10937 Fselect_window (old_window
, Qt
);
10940 if (!NILP (AREF (vector
, 6)))
10942 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10943 ASET (vector
, 6, Qnil
);
10946 Vmode_line_unwind_vector
= vector
;
10951 /* Store a single character C for the frame title in mode_line_noprop_buf.
10952 Re-allocate mode_line_noprop_buf if necessary. */
10955 store_mode_line_noprop_char (char c
)
10957 /* If output position has reached the end of the allocated buffer,
10958 increase the buffer's size. */
10959 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10961 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10962 ptrdiff_t size
= len
;
10963 mode_line_noprop_buf
=
10964 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10965 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10966 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10969 *mode_line_noprop_ptr
++ = c
;
10973 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10974 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10975 characters that yield more columns than PRECISION; PRECISION <= 0
10976 means copy the whole string. Pad with spaces until FIELD_WIDTH
10977 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10978 pad. Called from display_mode_element when it is used to build a
10982 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10984 const unsigned char *str
= (const unsigned char *) string
;
10986 ptrdiff_t dummy
, nbytes
;
10988 /* Copy at most PRECISION chars from STR. */
10989 nbytes
= strlen (string
);
10990 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10992 store_mode_line_noprop_char (*str
++);
10994 /* Fill up with spaces until FIELD_WIDTH reached. */
10995 while (field_width
> 0
10996 && n
< field_width
)
10998 store_mode_line_noprop_char (' ');
11005 /***********************************************************************
11007 ***********************************************************************/
11009 #ifdef HAVE_WINDOW_SYSTEM
11011 /* Set the title of FRAME, if it has changed. The title format is
11012 Vicon_title_format if FRAME is iconified, otherwise it is
11013 frame_title_format. */
11016 x_consider_frame_title (Lisp_Object frame
)
11018 struct frame
*f
= XFRAME (frame
);
11020 if (FRAME_WINDOW_P (f
)
11021 || FRAME_MINIBUF_ONLY_P (f
)
11022 || f
->explicit_name
)
11024 /* Do we have more than one visible frame on this X display? */
11027 ptrdiff_t title_start
;
11031 ptrdiff_t count
= SPECPDL_INDEX ();
11033 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
11035 Lisp_Object other_frame
= XCAR (tail
);
11036 struct frame
*tf
= XFRAME (other_frame
);
11039 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11040 && !FRAME_MINIBUF_ONLY_P (tf
)
11041 && !EQ (other_frame
, tip_frame
)
11042 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11046 /* Set global variable indicating that multiple frames exist. */
11047 multiple_frames
= CONSP (tail
);
11049 /* Switch to the buffer of selected window of the frame. Set up
11050 mode_line_target so that display_mode_element will output into
11051 mode_line_noprop_buf; then display the title. */
11052 record_unwind_protect (unwind_format_mode_line
,
11053 format_mode_line_unwind_data
11054 (f
, current_buffer
, selected_window
, 0));
11056 Fselect_window (FVAR (f
, selected_window
), Qt
);
11057 set_buffer_internal_1
11058 (XBUFFER (WVAR (XWINDOW (FVAR (f
, selected_window
)), buffer
)));
11059 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11061 mode_line_target
= MODE_LINE_TITLE
;
11062 title_start
= MODE_LINE_NOPROP_LEN (0);
11063 init_iterator (&it
, XWINDOW (FVAR (f
, selected_window
)), -1, -1,
11064 NULL
, DEFAULT_FACE_ID
);
11065 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11066 len
= MODE_LINE_NOPROP_LEN (title_start
);
11067 title
= mode_line_noprop_buf
+ title_start
;
11068 unbind_to (count
, Qnil
);
11070 /* Set the title only if it's changed. This avoids consing in
11071 the common case where it hasn't. (If it turns out that we've
11072 already wasted too much time by walking through the list with
11073 display_mode_element, then we might need to optimize at a
11074 higher level than this.) */
11075 if (! STRINGP (FVAR (f
, name
))
11076 || SBYTES (FVAR (f
, name
)) != len
11077 || memcmp (title
, SDATA (FVAR (f
, name
)), len
) != 0)
11078 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11082 #endif /* not HAVE_WINDOW_SYSTEM */
11085 /***********************************************************************
11087 ***********************************************************************/
11090 /* Prepare for redisplay by updating menu-bar item lists when
11091 appropriate. This can call eval. */
11094 prepare_menu_bars (void)
11097 struct gcpro gcpro1
, gcpro2
;
11099 Lisp_Object tooltip_frame
;
11101 #ifdef HAVE_WINDOW_SYSTEM
11102 tooltip_frame
= tip_frame
;
11104 tooltip_frame
= Qnil
;
11107 /* Update all frame titles based on their buffer names, etc. We do
11108 this before the menu bars so that the buffer-menu will show the
11109 up-to-date frame titles. */
11110 #ifdef HAVE_WINDOW_SYSTEM
11111 if (windows_or_buffers_changed
|| update_mode_lines
)
11113 Lisp_Object tail
, frame
;
11115 FOR_EACH_FRAME (tail
, frame
)
11117 f
= XFRAME (frame
);
11118 if (!EQ (frame
, tooltip_frame
)
11119 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11120 x_consider_frame_title (frame
);
11123 #endif /* HAVE_WINDOW_SYSTEM */
11125 /* Update the menu bar item lists, if appropriate. This has to be
11126 done before any actual redisplay or generation of display lines. */
11127 all_windows
= (update_mode_lines
11128 || buffer_shared
> 1
11129 || windows_or_buffers_changed
);
11132 Lisp_Object tail
, frame
;
11133 ptrdiff_t count
= SPECPDL_INDEX ();
11134 /* 1 means that update_menu_bar has run its hooks
11135 so any further calls to update_menu_bar shouldn't do so again. */
11136 int menu_bar_hooks_run
= 0;
11138 record_unwind_save_match_data ();
11140 FOR_EACH_FRAME (tail
, frame
)
11142 f
= XFRAME (frame
);
11144 /* Ignore tooltip frame. */
11145 if (EQ (frame
, tooltip_frame
))
11148 /* If a window on this frame changed size, report that to
11149 the user and clear the size-change flag. */
11150 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11152 Lisp_Object functions
;
11154 /* Clear flag first in case we get an error below. */
11155 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11156 functions
= Vwindow_size_change_functions
;
11157 GCPRO2 (tail
, functions
);
11159 while (CONSP (functions
))
11161 if (!EQ (XCAR (functions
), Qt
))
11162 call1 (XCAR (functions
), frame
);
11163 functions
= XCDR (functions
);
11169 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11170 #ifdef HAVE_WINDOW_SYSTEM
11171 update_tool_bar (f
, 0);
11174 if (windows_or_buffers_changed
11177 (f
, Fbuffer_modified_p
11178 (WVAR (XWINDOW (FVAR (f
, selected_window
)), buffer
)));
11183 unbind_to (count
, Qnil
);
11187 struct frame
*sf
= SELECTED_FRAME ();
11188 update_menu_bar (sf
, 1, 0);
11189 #ifdef HAVE_WINDOW_SYSTEM
11190 update_tool_bar (sf
, 1);
11196 /* Update the menu bar item list for frame F. This has to be done
11197 before we start to fill in any display lines, because it can call
11200 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11202 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11203 already ran the menu bar hooks for this redisplay, so there
11204 is no need to run them again. The return value is the
11205 updated value of this flag, to pass to the next call. */
11208 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11210 Lisp_Object window
;
11211 register struct window
*w
;
11213 /* If called recursively during a menu update, do nothing. This can
11214 happen when, for instance, an activate-menubar-hook causes a
11216 if (inhibit_menubar_update
)
11219 window
= FRAME_SELECTED_WINDOW (f
);
11220 w
= XWINDOW (window
);
11222 if (FRAME_WINDOW_P (f
)
11224 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11225 || defined (HAVE_NS) || defined (USE_GTK)
11226 FRAME_EXTERNAL_MENU_BAR (f
)
11228 FRAME_MENU_BAR_LINES (f
) > 0
11230 : FRAME_MENU_BAR_LINES (f
) > 0)
11232 /* If the user has switched buffers or windows, we need to
11233 recompute to reflect the new bindings. But we'll
11234 recompute when update_mode_lines is set too; that means
11235 that people can use force-mode-line-update to request
11236 that the menu bar be recomputed. The adverse effect on
11237 the rest of the redisplay algorithm is about the same as
11238 windows_or_buffers_changed anyway. */
11239 if (windows_or_buffers_changed
11240 /* This used to test w->update_mode_line, but we believe
11241 there is no need to recompute the menu in that case. */
11242 || update_mode_lines
11243 || ((BUF_SAVE_MODIFF (XBUFFER (WVAR (w
, buffer
)))
11244 < BUF_MODIFF (XBUFFER (WVAR (w
, buffer
))))
11245 != w
->last_had_star
)
11246 || ((!NILP (Vtransient_mark_mode
)
11247 && !NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), mark_active
)))
11248 != !NILP (WVAR (w
, region_showing
))))
11250 struct buffer
*prev
= current_buffer
;
11251 ptrdiff_t count
= SPECPDL_INDEX ();
11253 specbind (Qinhibit_menubar_update
, Qt
);
11255 set_buffer_internal_1 (XBUFFER (WVAR (w
, buffer
)));
11256 if (save_match_data
)
11257 record_unwind_save_match_data ();
11258 if (NILP (Voverriding_local_map_menu_flag
))
11260 specbind (Qoverriding_terminal_local_map
, Qnil
);
11261 specbind (Qoverriding_local_map
, Qnil
);
11266 /* Run the Lucid hook. */
11267 safe_run_hooks (Qactivate_menubar_hook
);
11269 /* If it has changed current-menubar from previous value,
11270 really recompute the menu-bar from the value. */
11271 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11272 call0 (Qrecompute_lucid_menubar
);
11274 safe_run_hooks (Qmenu_bar_update_hook
);
11279 XSETFRAME (Vmenu_updating_frame
, f
);
11280 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11282 /* Redisplay the menu bar in case we changed it. */
11283 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11284 || defined (HAVE_NS) || defined (USE_GTK)
11285 if (FRAME_WINDOW_P (f
))
11287 #if defined (HAVE_NS)
11288 /* All frames on Mac OS share the same menubar. So only
11289 the selected frame should be allowed to set it. */
11290 if (f
== SELECTED_FRAME ())
11292 set_frame_menubar (f
, 0, 0);
11295 /* On a terminal screen, the menu bar is an ordinary screen
11296 line, and this makes it get updated. */
11297 w
->update_mode_line
= 1;
11298 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11299 /* In the non-toolkit version, the menu bar is an ordinary screen
11300 line, and this makes it get updated. */
11301 w
->update_mode_line
= 1;
11302 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11304 unbind_to (count
, Qnil
);
11305 set_buffer_internal_1 (prev
);
11314 /***********************************************************************
11316 ***********************************************************************/
11318 #ifdef HAVE_WINDOW_SYSTEM
11321 Nominal cursor position -- where to draw output.
11322 HPOS and VPOS are window relative glyph matrix coordinates.
11323 X and Y are window relative pixel coordinates. */
11325 struct cursor_pos output_cursor
;
11329 Set the global variable output_cursor to CURSOR. All cursor
11330 positions are relative to updated_window. */
11333 set_output_cursor (struct cursor_pos
*cursor
)
11335 output_cursor
.hpos
= cursor
->hpos
;
11336 output_cursor
.vpos
= cursor
->vpos
;
11337 output_cursor
.x
= cursor
->x
;
11338 output_cursor
.y
= cursor
->y
;
11343 Set a nominal cursor position.
11345 HPOS and VPOS are column/row positions in a window glyph matrix. X
11346 and Y are window text area relative pixel positions.
11348 If this is done during an update, updated_window will contain the
11349 window that is being updated and the position is the future output
11350 cursor position for that window. If updated_window is null, use
11351 selected_window and display the cursor at the given position. */
11354 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11358 /* If updated_window is not set, work on selected_window. */
11359 if (updated_window
)
11360 w
= updated_window
;
11362 w
= XWINDOW (selected_window
);
11364 /* Set the output cursor. */
11365 output_cursor
.hpos
= hpos
;
11366 output_cursor
.vpos
= vpos
;
11367 output_cursor
.x
= x
;
11368 output_cursor
.y
= y
;
11370 /* If not called as part of an update, really display the cursor.
11371 This will also set the cursor position of W. */
11372 if (updated_window
== NULL
)
11375 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11376 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11377 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11382 #endif /* HAVE_WINDOW_SYSTEM */
11385 /***********************************************************************
11387 ***********************************************************************/
11389 #ifdef HAVE_WINDOW_SYSTEM
11391 /* Where the mouse was last time we reported a mouse event. */
11393 FRAME_PTR last_mouse_frame
;
11395 /* Tool-bar item index of the item on which a mouse button was pressed
11398 int last_tool_bar_item
;
11402 update_tool_bar_unwind (Lisp_Object frame
)
11404 selected_frame
= frame
;
11408 /* Update the tool-bar item list for frame F. This has to be done
11409 before we start to fill in any display lines. Called from
11410 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11411 and restore it here. */
11414 update_tool_bar (struct frame
*f
, int save_match_data
)
11416 #if defined (USE_GTK) || defined (HAVE_NS)
11417 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11419 int do_update
= WINDOWP (FVAR (f
, tool_bar_window
))
11420 && WINDOW_TOTAL_LINES (XWINDOW (FVAR (f
, tool_bar_window
))) > 0;
11425 Lisp_Object window
;
11428 window
= FRAME_SELECTED_WINDOW (f
);
11429 w
= XWINDOW (window
);
11431 /* If the user has switched buffers or windows, we need to
11432 recompute to reflect the new bindings. But we'll
11433 recompute when update_mode_lines is set too; that means
11434 that people can use force-mode-line-update to request
11435 that the menu bar be recomputed. The adverse effect on
11436 the rest of the redisplay algorithm is about the same as
11437 windows_or_buffers_changed anyway. */
11438 if (windows_or_buffers_changed
11439 || w
->update_mode_line
11440 || update_mode_lines
11441 || ((BUF_SAVE_MODIFF (XBUFFER (WVAR (w
, buffer
)))
11442 < BUF_MODIFF (XBUFFER (WVAR (w
, buffer
))))
11443 != w
->last_had_star
)
11444 || ((!NILP (Vtransient_mark_mode
)
11445 && !NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), mark_active
)))
11446 != !NILP (WVAR (w
, region_showing
))))
11448 struct buffer
*prev
= current_buffer
;
11449 ptrdiff_t count
= SPECPDL_INDEX ();
11450 Lisp_Object frame
, new_tool_bar
;
11451 int new_n_tool_bar
;
11452 struct gcpro gcpro1
;
11454 /* Set current_buffer to the buffer of the selected
11455 window of the frame, so that we get the right local
11457 set_buffer_internal_1 (XBUFFER (WVAR (w
, buffer
)));
11459 /* Save match data, if we must. */
11460 if (save_match_data
)
11461 record_unwind_save_match_data ();
11463 /* Make sure that we don't accidentally use bogus keymaps. */
11464 if (NILP (Voverriding_local_map_menu_flag
))
11466 specbind (Qoverriding_terminal_local_map
, Qnil
);
11467 specbind (Qoverriding_local_map
, Qnil
);
11470 GCPRO1 (new_tool_bar
);
11472 /* We must temporarily set the selected frame to this frame
11473 before calling tool_bar_items, because the calculation of
11474 the tool-bar keymap uses the selected frame (see
11475 `tool-bar-make-keymap' in tool-bar.el). */
11476 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11477 XSETFRAME (frame
, f
);
11478 selected_frame
= frame
;
11480 /* Build desired tool-bar items from keymaps. */
11481 new_tool_bar
= tool_bar_items
11482 (Fcopy_sequence (FVAR (f
, tool_bar_items
)), &new_n_tool_bar
);
11484 /* Redisplay the tool-bar if we changed it. */
11485 if (new_n_tool_bar
!= f
->n_tool_bar_items
11486 || NILP (Fequal (new_tool_bar
, FVAR (f
, tool_bar_items
))))
11488 /* Redisplay that happens asynchronously due to an expose event
11489 may access f->tool_bar_items. Make sure we update both
11490 variables within BLOCK_INPUT so no such event interrupts. */
11492 FVAR (f
, tool_bar_items
) = new_tool_bar
;
11493 f
->n_tool_bar_items
= new_n_tool_bar
;
11494 w
->update_mode_line
= 1;
11500 unbind_to (count
, Qnil
);
11501 set_buffer_internal_1 (prev
);
11507 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11508 F's desired tool-bar contents. F->tool_bar_items must have
11509 been set up previously by calling prepare_menu_bars. */
11512 build_desired_tool_bar_string (struct frame
*f
)
11514 int i
, size
, size_needed
;
11515 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11516 Lisp_Object image
, plist
, props
;
11518 image
= plist
= props
= Qnil
;
11519 GCPRO3 (image
, plist
, props
);
11521 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11522 Otherwise, make a new string. */
11524 /* The size of the string we might be able to reuse. */
11525 size
= (STRINGP (FVAR (f
, desired_tool_bar_string
))
11526 ? SCHARS (FVAR (f
, desired_tool_bar_string
))
11529 /* We need one space in the string for each image. */
11530 size_needed
= f
->n_tool_bar_items
;
11532 /* Reuse f->desired_tool_bar_string, if possible. */
11533 if (size
< size_needed
|| NILP (FVAR (f
, desired_tool_bar_string
)))
11534 FVAR (f
, desired_tool_bar_string
)
11535 = Fmake_string (make_number (size_needed
), make_number (' '));
11538 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11539 Fremove_text_properties (make_number (0), make_number (size
),
11540 props
, FVAR (f
, desired_tool_bar_string
));
11543 /* Put a `display' property on the string for the images to display,
11544 put a `menu_item' property on tool-bar items with a value that
11545 is the index of the item in F's tool-bar item vector. */
11546 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11548 #define PROP(IDX) \
11549 AREF (FVAR (f, tool_bar_items), i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11551 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11552 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11553 int hmargin
, vmargin
, relief
, idx
, end
;
11555 /* If image is a vector, choose the image according to the
11557 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11558 if (VECTORP (image
))
11562 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11563 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11566 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11567 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11569 eassert (ASIZE (image
) >= idx
);
11570 image
= AREF (image
, idx
);
11575 /* Ignore invalid image specifications. */
11576 if (!valid_image_p (image
))
11579 /* Display the tool-bar button pressed, or depressed. */
11580 plist
= Fcopy_sequence (XCDR (image
));
11582 /* Compute margin and relief to draw. */
11583 relief
= (tool_bar_button_relief
>= 0
11584 ? tool_bar_button_relief
11585 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11586 hmargin
= vmargin
= relief
;
11588 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11589 INT_MAX
- max (hmargin
, vmargin
)))
11591 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11592 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11594 else if (CONSP (Vtool_bar_button_margin
))
11596 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11597 INT_MAX
- hmargin
))
11598 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11600 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11601 INT_MAX
- vmargin
))
11602 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11605 if (auto_raise_tool_bar_buttons_p
)
11607 /* Add a `:relief' property to the image spec if the item is
11611 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11618 /* If image is selected, display it pressed, i.e. with a
11619 negative relief. If it's not selected, display it with a
11621 plist
= Fplist_put (plist
, QCrelief
,
11623 ? make_number (-relief
)
11624 : make_number (relief
)));
11629 /* Put a margin around the image. */
11630 if (hmargin
|| vmargin
)
11632 if (hmargin
== vmargin
)
11633 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11635 plist
= Fplist_put (plist
, QCmargin
,
11636 Fcons (make_number (hmargin
),
11637 make_number (vmargin
)));
11640 /* If button is not enabled, and we don't have special images
11641 for the disabled state, make the image appear disabled by
11642 applying an appropriate algorithm to it. */
11643 if (!enabled_p
&& idx
< 0)
11644 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11646 /* Put a `display' text property on the string for the image to
11647 display. Put a `menu-item' property on the string that gives
11648 the start of this item's properties in the tool-bar items
11650 image
= Fcons (Qimage
, plist
);
11651 props
= list4 (Qdisplay
, image
,
11652 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11654 /* Let the last image hide all remaining spaces in the tool bar
11655 string. The string can be longer than needed when we reuse a
11656 previous string. */
11657 if (i
+ 1 == f
->n_tool_bar_items
)
11658 end
= SCHARS (FVAR (f
, desired_tool_bar_string
));
11661 Fadd_text_properties (make_number (i
), make_number (end
),
11662 props
, FVAR (f
, desired_tool_bar_string
));
11670 /* Display one line of the tool-bar of frame IT->f.
11672 HEIGHT specifies the desired height of the tool-bar line.
11673 If the actual height of the glyph row is less than HEIGHT, the
11674 row's height is increased to HEIGHT, and the icons are centered
11675 vertically in the new height.
11677 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11678 count a final empty row in case the tool-bar width exactly matches
11683 display_tool_bar_line (struct it
*it
, int height
)
11685 struct glyph_row
*row
= it
->glyph_row
;
11686 int max_x
= it
->last_visible_x
;
11687 struct glyph
*last
;
11689 prepare_desired_row (row
);
11690 row
->y
= it
->current_y
;
11692 /* Note that this isn't made use of if the face hasn't a box,
11693 so there's no need to check the face here. */
11694 it
->start_of_box_run_p
= 1;
11696 while (it
->current_x
< max_x
)
11698 int x
, n_glyphs_before
, i
, nglyphs
;
11699 struct it it_before
;
11701 /* Get the next display element. */
11702 if (!get_next_display_element (it
))
11704 /* Don't count empty row if we are counting needed tool-bar lines. */
11705 if (height
< 0 && !it
->hpos
)
11710 /* Produce glyphs. */
11711 n_glyphs_before
= row
->used
[TEXT_AREA
];
11714 PRODUCE_GLYPHS (it
);
11716 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11718 x
= it_before
.current_x
;
11719 while (i
< nglyphs
)
11721 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11723 if (x
+ glyph
->pixel_width
> max_x
)
11725 /* Glyph doesn't fit on line. Backtrack. */
11726 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11728 /* If this is the only glyph on this line, it will never fit on the
11729 tool-bar, so skip it. But ensure there is at least one glyph,
11730 so we don't accidentally disable the tool-bar. */
11731 if (n_glyphs_before
== 0
11732 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11738 x
+= glyph
->pixel_width
;
11742 /* Stop at line end. */
11743 if (ITERATOR_AT_END_OF_LINE_P (it
))
11746 set_iterator_to_next (it
, 1);
11751 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11753 /* Use default face for the border below the tool bar.
11755 FIXME: When auto-resize-tool-bars is grow-only, there is
11756 no additional border below the possibly empty tool-bar lines.
11757 So to make the extra empty lines look "normal", we have to
11758 use the tool-bar face for the border too. */
11759 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11760 it
->face_id
= DEFAULT_FACE_ID
;
11762 extend_face_to_end_of_line (it
);
11763 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11764 last
->right_box_line_p
= 1;
11765 if (last
== row
->glyphs
[TEXT_AREA
])
11766 last
->left_box_line_p
= 1;
11768 /* Make line the desired height and center it vertically. */
11769 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11771 /* Don't add more than one line height. */
11772 height
%= FRAME_LINE_HEIGHT (it
->f
);
11773 it
->max_ascent
+= height
/ 2;
11774 it
->max_descent
+= (height
+ 1) / 2;
11777 compute_line_metrics (it
);
11779 /* If line is empty, make it occupy the rest of the tool-bar. */
11780 if (!row
->displays_text_p
)
11782 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11783 row
->visible_height
= row
->height
;
11784 row
->ascent
= row
->phys_ascent
= 0;
11785 row
->extra_line_spacing
= 0;
11788 row
->full_width_p
= 1;
11789 row
->continued_p
= 0;
11790 row
->truncated_on_left_p
= 0;
11791 row
->truncated_on_right_p
= 0;
11793 it
->current_x
= it
->hpos
= 0;
11794 it
->current_y
+= row
->height
;
11800 /* Max tool-bar height. */
11802 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11803 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11805 /* Value is the number of screen lines needed to make all tool-bar
11806 items of frame F visible. The number of actual rows needed is
11807 returned in *N_ROWS if non-NULL. */
11810 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11812 struct window
*w
= XWINDOW (FVAR (f
, tool_bar_window
));
11814 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11815 the desired matrix, so use (unused) mode-line row as temporary row to
11816 avoid destroying the first tool-bar row. */
11817 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11819 /* Initialize an iterator for iteration over
11820 F->desired_tool_bar_string in the tool-bar window of frame F. */
11821 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11822 it
.first_visible_x
= 0;
11823 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11824 reseat_to_string (&it
, NULL
, FVAR (f
, desired_tool_bar_string
), 0, 0, 0, -1);
11825 it
.paragraph_embedding
= L2R
;
11827 while (!ITERATOR_AT_END_P (&it
))
11829 clear_glyph_row (temp_row
);
11830 it
.glyph_row
= temp_row
;
11831 display_tool_bar_line (&it
, -1);
11833 clear_glyph_row (temp_row
);
11835 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11837 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11839 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11843 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11845 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11846 (Lisp_Object frame
)
11853 frame
= selected_frame
;
11855 CHECK_FRAME (frame
);
11856 f
= XFRAME (frame
);
11858 if (WINDOWP (FVAR (f
, tool_bar_window
))
11859 && (w
= XWINDOW (FVAR (f
, tool_bar_window
)),
11860 WINDOW_TOTAL_LINES (w
) > 0))
11862 update_tool_bar (f
, 1);
11863 if (f
->n_tool_bar_items
)
11865 build_desired_tool_bar_string (f
);
11866 nlines
= tool_bar_lines_needed (f
, NULL
);
11870 return make_number (nlines
);
11874 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11875 height should be changed. */
11878 redisplay_tool_bar (struct frame
*f
)
11882 struct glyph_row
*row
;
11884 #if defined (USE_GTK) || defined (HAVE_NS)
11885 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11886 update_frame_tool_bar (f
);
11890 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11891 do anything. This means you must start with tool-bar-lines
11892 non-zero to get the auto-sizing effect. Or in other words, you
11893 can turn off tool-bars by specifying tool-bar-lines zero. */
11894 if (!WINDOWP (FVAR (f
, tool_bar_window
))
11895 || (w
= XWINDOW (FVAR (f
, tool_bar_window
)),
11896 WINDOW_TOTAL_LINES (w
) == 0))
11899 /* Set up an iterator for the tool-bar window. */
11900 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11901 it
.first_visible_x
= 0;
11902 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11903 row
= it
.glyph_row
;
11905 /* Build a string that represents the contents of the tool-bar. */
11906 build_desired_tool_bar_string (f
);
11907 reseat_to_string (&it
, NULL
, FVAR (f
, desired_tool_bar_string
), 0, 0, 0, -1);
11908 /* FIXME: This should be controlled by a user option. But it
11909 doesn't make sense to have an R2L tool bar if the menu bar cannot
11910 be drawn also R2L, and making the menu bar R2L is tricky due
11911 toolkit-specific code that implements it. If an R2L tool bar is
11912 ever supported, display_tool_bar_line should also be augmented to
11913 call unproduce_glyphs like display_line and display_string
11915 it
.paragraph_embedding
= L2R
;
11917 if (f
->n_tool_bar_rows
== 0)
11921 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11922 nlines
!= WINDOW_TOTAL_LINES (w
)))
11925 int old_height
= WINDOW_TOTAL_LINES (w
);
11927 XSETFRAME (frame
, f
);
11928 Fmodify_frame_parameters (frame
,
11929 Fcons (Fcons (Qtool_bar_lines
,
11930 make_number (nlines
)),
11932 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11934 clear_glyph_matrix (w
->desired_matrix
);
11935 fonts_changed_p
= 1;
11941 /* Display as many lines as needed to display all tool-bar items. */
11943 if (f
->n_tool_bar_rows
> 0)
11945 int border
, rows
, height
, extra
;
11947 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11948 border
= XINT (Vtool_bar_border
);
11949 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11950 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11951 else if (EQ (Vtool_bar_border
, Qborder_width
))
11952 border
= f
->border_width
;
11958 rows
= f
->n_tool_bar_rows
;
11959 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11960 extra
= it
.last_visible_y
- border
- height
* rows
;
11962 while (it
.current_y
< it
.last_visible_y
)
11965 if (extra
> 0 && rows
-- > 0)
11967 h
= (extra
+ rows
- 1) / rows
;
11970 display_tool_bar_line (&it
, height
+ h
);
11975 while (it
.current_y
< it
.last_visible_y
)
11976 display_tool_bar_line (&it
, 0);
11979 /* It doesn't make much sense to try scrolling in the tool-bar
11980 window, so don't do it. */
11981 w
->desired_matrix
->no_scrolling_p
= 1;
11982 w
->must_be_updated_p
= 1;
11984 if (!NILP (Vauto_resize_tool_bars
))
11986 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11987 int change_height_p
= 0;
11989 /* If we couldn't display everything, change the tool-bar's
11990 height if there is room for more. */
11991 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11992 && it
.current_y
< max_tool_bar_height
)
11993 change_height_p
= 1;
11995 row
= it
.glyph_row
- 1;
11997 /* If there are blank lines at the end, except for a partially
11998 visible blank line at the end that is smaller than
11999 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12000 if (!row
->displays_text_p
12001 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12002 change_height_p
= 1;
12004 /* If row displays tool-bar items, but is partially visible,
12005 change the tool-bar's height. */
12006 if (row
->displays_text_p
12007 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12008 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12009 change_height_p
= 1;
12011 /* Resize windows as needed by changing the `tool-bar-lines'
12012 frame parameter. */
12013 if (change_height_p
)
12016 int old_height
= WINDOW_TOTAL_LINES (w
);
12018 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12020 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12021 && !f
->minimize_tool_bar_window_p
)
12022 ? (nlines
> old_height
)
12023 : (nlines
!= old_height
));
12024 f
->minimize_tool_bar_window_p
= 0;
12026 if (change_height_p
)
12028 XSETFRAME (frame
, f
);
12029 Fmodify_frame_parameters (frame
,
12030 Fcons (Fcons (Qtool_bar_lines
,
12031 make_number (nlines
)),
12033 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12035 clear_glyph_matrix (w
->desired_matrix
);
12036 f
->n_tool_bar_rows
= nrows
;
12037 fonts_changed_p
= 1;
12044 f
->minimize_tool_bar_window_p
= 0;
12049 /* Get information about the tool-bar item which is displayed in GLYPH
12050 on frame F. Return in *PROP_IDX the index where tool-bar item
12051 properties start in F->tool_bar_items. Value is zero if
12052 GLYPH doesn't display a tool-bar item. */
12055 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12061 /* This function can be called asynchronously, which means we must
12062 exclude any possibility that Fget_text_property signals an
12064 charpos
= min (SCHARS (FVAR (f
, current_tool_bar_string
)), glyph
->charpos
);
12065 charpos
= max (0, charpos
);
12067 /* Get the text property `menu-item' at pos. The value of that
12068 property is the start index of this item's properties in
12069 F->tool_bar_items. */
12070 prop
= Fget_text_property (make_number (charpos
),
12071 Qmenu_item
, FVAR (f
, current_tool_bar_string
));
12072 if (INTEGERP (prop
))
12074 *prop_idx
= XINT (prop
);
12084 /* Get information about the tool-bar item at position X/Y on frame F.
12085 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12086 the current matrix of the tool-bar window of F, or NULL if not
12087 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12088 item in F->tool_bar_items. Value is
12090 -1 if X/Y is not on a tool-bar item
12091 0 if X/Y is on the same item that was highlighted before.
12095 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12096 int *hpos
, int *vpos
, int *prop_idx
)
12098 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12099 struct window
*w
= XWINDOW (FVAR (f
, tool_bar_window
));
12102 /* Find the glyph under X/Y. */
12103 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12104 if (*glyph
== NULL
)
12107 /* Get the start of this tool-bar item's properties in
12108 f->tool_bar_items. */
12109 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12112 /* Is mouse on the highlighted item? */
12113 if (EQ (FVAR (f
, tool_bar_window
), hlinfo
->mouse_face_window
)
12114 && *vpos
>= hlinfo
->mouse_face_beg_row
12115 && *vpos
<= hlinfo
->mouse_face_end_row
12116 && (*vpos
> hlinfo
->mouse_face_beg_row
12117 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12118 && (*vpos
< hlinfo
->mouse_face_end_row
12119 || *hpos
< hlinfo
->mouse_face_end_col
12120 || hlinfo
->mouse_face_past_end
))
12128 Handle mouse button event on the tool-bar of frame F, at
12129 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12130 0 for button release. MODIFIERS is event modifiers for button
12134 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12137 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12138 struct window
*w
= XWINDOW (FVAR (f
, tool_bar_window
));
12139 int hpos
, vpos
, prop_idx
;
12140 struct glyph
*glyph
;
12141 Lisp_Object enabled_p
;
12143 /* If not on the highlighted tool-bar item, return. */
12144 frame_to_window_pixel_xy (w
, &x
, &y
);
12145 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12148 /* If item is disabled, do nothing. */
12149 enabled_p
= AREF (FVAR (f
, tool_bar_items
), prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12150 if (NILP (enabled_p
))
12155 /* Show item in pressed state. */
12156 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12157 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12158 last_tool_bar_item
= prop_idx
;
12162 Lisp_Object key
, frame
;
12163 struct input_event event
;
12164 EVENT_INIT (event
);
12166 /* Show item in released state. */
12167 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12168 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12170 key
= AREF (FVAR (f
, tool_bar_items
), prop_idx
+ TOOL_BAR_ITEM_KEY
);
12172 XSETFRAME (frame
, f
);
12173 event
.kind
= TOOL_BAR_EVENT
;
12174 event
.frame_or_window
= frame
;
12176 kbd_buffer_store_event (&event
);
12178 event
.kind
= TOOL_BAR_EVENT
;
12179 event
.frame_or_window
= frame
;
12181 event
.modifiers
= modifiers
;
12182 kbd_buffer_store_event (&event
);
12183 last_tool_bar_item
= -1;
12188 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12189 tool-bar window-relative coordinates X/Y. Called from
12190 note_mouse_highlight. */
12193 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12195 Lisp_Object window
= FVAR (f
, tool_bar_window
);
12196 struct window
*w
= XWINDOW (window
);
12197 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12198 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12200 struct glyph
*glyph
;
12201 struct glyph_row
*row
;
12203 Lisp_Object enabled_p
;
12205 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12206 int mouse_down_p
, rc
;
12208 /* Function note_mouse_highlight is called with negative X/Y
12209 values when mouse moves outside of the frame. */
12210 if (x
<= 0 || y
<= 0)
12212 clear_mouse_face (hlinfo
);
12216 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12219 /* Not on tool-bar item. */
12220 clear_mouse_face (hlinfo
);
12224 /* On same tool-bar item as before. */
12225 goto set_help_echo
;
12227 clear_mouse_face (hlinfo
);
12229 /* Mouse is down, but on different tool-bar item? */
12230 mouse_down_p
= (dpyinfo
->grabbed
12231 && f
== last_mouse_frame
12232 && FRAME_LIVE_P (f
));
12234 && last_tool_bar_item
!= prop_idx
)
12237 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12238 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12240 /* If tool-bar item is not enabled, don't highlight it. */
12241 enabled_p
= AREF (FVAR (f
, tool_bar_items
), prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12242 if (!NILP (enabled_p
))
12244 /* Compute the x-position of the glyph. In front and past the
12245 image is a space. We include this in the highlighted area. */
12246 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12247 for (i
= x
= 0; i
< hpos
; ++i
)
12248 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12250 /* Record this as the current active region. */
12251 hlinfo
->mouse_face_beg_col
= hpos
;
12252 hlinfo
->mouse_face_beg_row
= vpos
;
12253 hlinfo
->mouse_face_beg_x
= x
;
12254 hlinfo
->mouse_face_beg_y
= row
->y
;
12255 hlinfo
->mouse_face_past_end
= 0;
12257 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12258 hlinfo
->mouse_face_end_row
= vpos
;
12259 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12260 hlinfo
->mouse_face_end_y
= row
->y
;
12261 hlinfo
->mouse_face_window
= window
;
12262 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12264 /* Display it as active. */
12265 show_mouse_face (hlinfo
, draw
);
12266 hlinfo
->mouse_face_image_state
= draw
;
12271 /* Set help_echo_string to a help string to display for this tool-bar item.
12272 XTread_socket does the rest. */
12273 help_echo_object
= help_echo_window
= Qnil
;
12274 help_echo_pos
= -1;
12275 help_echo_string
= AREF (FVAR (f
, tool_bar_items
), prop_idx
+ TOOL_BAR_ITEM_HELP
);
12276 if (NILP (help_echo_string
))
12277 help_echo_string
= AREF (FVAR (f
, tool_bar_items
), prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12280 #endif /* HAVE_WINDOW_SYSTEM */
12284 /************************************************************************
12285 Horizontal scrolling
12286 ************************************************************************/
12288 static int hscroll_window_tree (Lisp_Object
);
12289 static int hscroll_windows (Lisp_Object
);
12291 /* For all leaf windows in the window tree rooted at WINDOW, set their
12292 hscroll value so that PT is (i) visible in the window, and (ii) so
12293 that it is not within a certain margin at the window's left and
12294 right border. Value is non-zero if any window's hscroll has been
12298 hscroll_window_tree (Lisp_Object window
)
12300 int hscrolled_p
= 0;
12301 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12302 int hscroll_step_abs
= 0;
12303 double hscroll_step_rel
= 0;
12305 if (hscroll_relative_p
)
12307 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12308 if (hscroll_step_rel
< 0)
12310 hscroll_relative_p
= 0;
12311 hscroll_step_abs
= 0;
12314 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12316 hscroll_step_abs
= XINT (Vhscroll_step
);
12317 if (hscroll_step_abs
< 0)
12318 hscroll_step_abs
= 0;
12321 hscroll_step_abs
= 0;
12323 while (WINDOWP (window
))
12325 struct window
*w
= XWINDOW (window
);
12327 if (WINDOWP (WVAR (w
, hchild
)))
12328 hscrolled_p
|= hscroll_window_tree (WVAR (w
, hchild
));
12329 else if (WINDOWP (WVAR (w
, vchild
)))
12330 hscrolled_p
|= hscroll_window_tree (WVAR (w
, vchild
));
12331 else if (w
->cursor
.vpos
>= 0)
12334 int text_area_width
;
12335 struct glyph_row
*current_cursor_row
12336 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12337 struct glyph_row
*desired_cursor_row
12338 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12339 struct glyph_row
*cursor_row
12340 = (desired_cursor_row
->enabled_p
12341 ? desired_cursor_row
12342 : current_cursor_row
);
12343 int row_r2l_p
= cursor_row
->reversed_p
;
12345 text_area_width
= window_box_width (w
, TEXT_AREA
);
12347 /* Scroll when cursor is inside this scroll margin. */
12348 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12350 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, WVAR (w
, buffer
)))
12351 /* For left-to-right rows, hscroll when cursor is either
12352 (i) inside the right hscroll margin, or (ii) if it is
12353 inside the left margin and the window is already
12357 && w
->cursor
.x
<= h_margin
)
12358 || (cursor_row
->enabled_p
12359 && cursor_row
->truncated_on_right_p
12360 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12361 /* For right-to-left rows, the logic is similar,
12362 except that rules for scrolling to left and right
12363 are reversed. E.g., if cursor.x <= h_margin, we
12364 need to hscroll "to the right" unconditionally,
12365 and that will scroll the screen to the left so as
12366 to reveal the next portion of the row. */
12368 && ((cursor_row
->enabled_p
12369 /* FIXME: It is confusing to set the
12370 truncated_on_right_p flag when R2L rows
12371 are actually truncated on the left. */
12372 && cursor_row
->truncated_on_right_p
12373 && w
->cursor
.x
<= h_margin
)
12375 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12379 struct buffer
*saved_current_buffer
;
12383 /* Find point in a display of infinite width. */
12384 saved_current_buffer
= current_buffer
;
12385 current_buffer
= XBUFFER (WVAR (w
, buffer
));
12387 if (w
== XWINDOW (selected_window
))
12391 pt
= marker_position (WVAR (w
, pointm
));
12392 pt
= max (BEGV
, pt
);
12396 /* Move iterator to pt starting at cursor_row->start in
12397 a line with infinite width. */
12398 init_to_row_start (&it
, w
, cursor_row
);
12399 it
.last_visible_x
= INFINITY
;
12400 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12401 current_buffer
= saved_current_buffer
;
12403 /* Position cursor in window. */
12404 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12405 hscroll
= max (0, (it
.current_x
12406 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12407 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12408 : (text_area_width
/ 2))))
12409 / FRAME_COLUMN_WIDTH (it
.f
);
12410 else if ((!row_r2l_p
12411 && w
->cursor
.x
>= text_area_width
- h_margin
)
12412 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12414 if (hscroll_relative_p
)
12415 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12418 wanted_x
= text_area_width
12419 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12422 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12426 if (hscroll_relative_p
)
12427 wanted_x
= text_area_width
* hscroll_step_rel
12430 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12433 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12435 hscroll
= max (hscroll
, w
->min_hscroll
);
12437 /* Don't prevent redisplay optimizations if hscroll
12438 hasn't changed, as it will unnecessarily slow down
12440 if (w
->hscroll
!= hscroll
)
12442 XBUFFER (WVAR (w
, buffer
))->prevent_redisplay_optimizations_p
= 1;
12443 w
->hscroll
= hscroll
;
12449 window
= WVAR (w
, next
);
12452 /* Value is non-zero if hscroll of any leaf window has been changed. */
12453 return hscrolled_p
;
12457 /* Set hscroll so that cursor is visible and not inside horizontal
12458 scroll margins for all windows in the tree rooted at WINDOW. See
12459 also hscroll_window_tree above. Value is non-zero if any window's
12460 hscroll has been changed. If it has, desired matrices on the frame
12461 of WINDOW are cleared. */
12464 hscroll_windows (Lisp_Object window
)
12466 int hscrolled_p
= hscroll_window_tree (window
);
12468 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12469 return hscrolled_p
;
12474 /************************************************************************
12476 ************************************************************************/
12478 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12479 to a non-zero value. This is sometimes handy to have in a debugger
12484 /* First and last unchanged row for try_window_id. */
12486 static int debug_first_unchanged_at_end_vpos
;
12487 static int debug_last_unchanged_at_beg_vpos
;
12489 /* Delta vpos and y. */
12491 static int debug_dvpos
, debug_dy
;
12493 /* Delta in characters and bytes for try_window_id. */
12495 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12497 /* Values of window_end_pos and window_end_vpos at the end of
12500 static ptrdiff_t debug_end_vpos
;
12502 /* Append a string to W->desired_matrix->method. FMT is a printf
12503 format string. If trace_redisplay_p is non-zero also printf the
12504 resulting string to stderr. */
12506 static void debug_method_add (struct window
*, char const *, ...)
12507 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12510 debug_method_add (struct window
*w
, char const *fmt
, ...)
12512 char *method
= w
->desired_matrix
->method
;
12513 int len
= strlen (method
);
12514 int size
= sizeof w
->desired_matrix
->method
;
12515 int remaining
= size
- len
- 1;
12518 if (len
&& remaining
)
12521 --remaining
, ++len
;
12524 va_start (ap
, fmt
);
12525 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12528 if (trace_redisplay_p
)
12529 fprintf (stderr
, "%p (%s): %s\n",
12531 ((BUFFERP (WVAR (w
, buffer
))
12532 && STRINGP (BVAR (XBUFFER (WVAR (w
, buffer
)), name
)))
12533 ? SSDATA (BVAR (XBUFFER (WVAR (w
, buffer
)), name
))
12538 #endif /* GLYPH_DEBUG */
12541 /* Value is non-zero if all changes in window W, which displays
12542 current_buffer, are in the text between START and END. START is a
12543 buffer position, END is given as a distance from Z. Used in
12544 redisplay_internal for display optimization. */
12547 text_outside_line_unchanged_p (struct window
*w
,
12548 ptrdiff_t start
, ptrdiff_t end
)
12550 int unchanged_p
= 1;
12552 /* If text or overlays have changed, see where. */
12553 if (w
->last_modified
< MODIFF
12554 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
12556 /* Gap in the line? */
12557 if (GPT
< start
|| Z
- GPT
< end
)
12560 /* Changes start in front of the line, or end after it? */
12562 && (BEG_UNCHANGED
< start
- 1
12563 || END_UNCHANGED
< end
))
12566 /* If selective display, can't optimize if changes start at the
12567 beginning of the line. */
12569 && INTEGERP (BVAR (current_buffer
, selective_display
))
12570 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12571 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12574 /* If there are overlays at the start or end of the line, these
12575 may have overlay strings with newlines in them. A change at
12576 START, for instance, may actually concern the display of such
12577 overlay strings as well, and they are displayed on different
12578 lines. So, quickly rule out this case. (For the future, it
12579 might be desirable to implement something more telling than
12580 just BEG/END_UNCHANGED.) */
12583 if (BEG
+ BEG_UNCHANGED
== start
12584 && overlay_touches_p (start
))
12586 if (END_UNCHANGED
== end
12587 && overlay_touches_p (Z
- end
))
12591 /* Under bidi reordering, adding or deleting a character in the
12592 beginning of a paragraph, before the first strong directional
12593 character, can change the base direction of the paragraph (unless
12594 the buffer specifies a fixed paragraph direction), which will
12595 require to redisplay the whole paragraph. It might be worthwhile
12596 to find the paragraph limits and widen the range of redisplayed
12597 lines to that, but for now just give up this optimization. */
12598 if (!NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_display_reordering
))
12599 && NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_paragraph_direction
)))
12603 return unchanged_p
;
12607 /* Do a frame update, taking possible shortcuts into account. This is
12608 the main external entry point for redisplay.
12610 If the last redisplay displayed an echo area message and that message
12611 is no longer requested, we clear the echo area or bring back the
12612 mini-buffer if that is in use. */
12617 redisplay_internal ();
12622 overlay_arrow_string_or_property (Lisp_Object var
)
12626 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12629 return Voverlay_arrow_string
;
12632 /* Return 1 if there are any overlay-arrows in current_buffer. */
12634 overlay_arrow_in_current_buffer_p (void)
12638 for (vlist
= Voverlay_arrow_variable_list
;
12640 vlist
= XCDR (vlist
))
12642 Lisp_Object var
= XCAR (vlist
);
12645 if (!SYMBOLP (var
))
12647 val
= find_symbol_value (var
);
12649 && current_buffer
== XMARKER (val
)->buffer
)
12656 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12660 overlay_arrows_changed_p (void)
12664 for (vlist
= Voverlay_arrow_variable_list
;
12666 vlist
= XCDR (vlist
))
12668 Lisp_Object var
= XCAR (vlist
);
12669 Lisp_Object val
, pstr
;
12671 if (!SYMBOLP (var
))
12673 val
= find_symbol_value (var
);
12674 if (!MARKERP (val
))
12676 if (! EQ (COERCE_MARKER (val
),
12677 Fget (var
, Qlast_arrow_position
))
12678 || ! (pstr
= overlay_arrow_string_or_property (var
),
12679 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12685 /* Mark overlay arrows to be updated on next redisplay. */
12688 update_overlay_arrows (int up_to_date
)
12692 for (vlist
= Voverlay_arrow_variable_list
;
12694 vlist
= XCDR (vlist
))
12696 Lisp_Object var
= XCAR (vlist
);
12698 if (!SYMBOLP (var
))
12701 if (up_to_date
> 0)
12703 Lisp_Object val
= find_symbol_value (var
);
12704 Fput (var
, Qlast_arrow_position
,
12705 COERCE_MARKER (val
));
12706 Fput (var
, Qlast_arrow_string
,
12707 overlay_arrow_string_or_property (var
));
12709 else if (up_to_date
< 0
12710 || !NILP (Fget (var
, Qlast_arrow_position
)))
12712 Fput (var
, Qlast_arrow_position
, Qt
);
12713 Fput (var
, Qlast_arrow_string
, Qt
);
12719 /* Return overlay arrow string to display at row.
12720 Return integer (bitmap number) for arrow bitmap in left fringe.
12721 Return nil if no overlay arrow. */
12724 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12728 for (vlist
= Voverlay_arrow_variable_list
;
12730 vlist
= XCDR (vlist
))
12732 Lisp_Object var
= XCAR (vlist
);
12735 if (!SYMBOLP (var
))
12738 val
= find_symbol_value (var
);
12741 && current_buffer
== XMARKER (val
)->buffer
12742 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12744 if (FRAME_WINDOW_P (it
->f
)
12745 /* FIXME: if ROW->reversed_p is set, this should test
12746 the right fringe, not the left one. */
12747 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12749 #ifdef HAVE_WINDOW_SYSTEM
12750 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12753 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12754 return make_number (fringe_bitmap
);
12757 return make_number (-1); /* Use default arrow bitmap */
12759 return overlay_arrow_string_or_property (var
);
12766 /* Return 1 if point moved out of or into a composition. Otherwise
12767 return 0. PREV_BUF and PREV_PT are the last point buffer and
12768 position. BUF and PT are the current point buffer and position. */
12771 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12772 struct buffer
*buf
, ptrdiff_t pt
)
12774 ptrdiff_t start
, end
;
12776 Lisp_Object buffer
;
12778 XSETBUFFER (buffer
, buf
);
12779 /* Check a composition at the last point if point moved within the
12781 if (prev_buf
== buf
)
12784 /* Point didn't move. */
12787 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12788 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12789 && COMPOSITION_VALID_P (start
, end
, prop
)
12790 && start
< prev_pt
&& end
> prev_pt
)
12791 /* The last point was within the composition. Return 1 iff
12792 point moved out of the composition. */
12793 return (pt
<= start
|| pt
>= end
);
12796 /* Check a composition at the current point. */
12797 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12798 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12799 && COMPOSITION_VALID_P (start
, end
, prop
)
12800 && start
< pt
&& end
> pt
);
12804 /* Reconsider the setting of B->clip_changed which is displayed
12808 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12810 if (b
->clip_changed
12811 && !NILP (WVAR (w
, window_end_valid
))
12812 && w
->current_matrix
->buffer
== b
12813 && w
->current_matrix
->zv
== BUF_ZV (b
)
12814 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12815 b
->clip_changed
= 0;
12817 /* If display wasn't paused, and W is not a tool bar window, see if
12818 point has been moved into or out of a composition. In that case,
12819 we set b->clip_changed to 1 to force updating the screen. If
12820 b->clip_changed has already been set to 1, we can skip this
12822 if (!b
->clip_changed
12823 && BUFFERP (WVAR (w
, buffer
)) && !NILP (WVAR (w
, window_end_valid
)))
12827 if (w
== XWINDOW (selected_window
))
12830 pt
= marker_position (WVAR (w
, pointm
));
12832 if ((w
->current_matrix
->buffer
!= XBUFFER (WVAR (w
, buffer
))
12833 || pt
!= w
->last_point
)
12834 && check_point_in_composition (w
->current_matrix
->buffer
,
12836 XBUFFER (WVAR (w
, buffer
)), pt
))
12837 b
->clip_changed
= 1;
12842 /* Select FRAME to forward the values of frame-local variables into C
12843 variables so that the redisplay routines can access those values
12847 select_frame_for_redisplay (Lisp_Object frame
)
12849 Lisp_Object tail
, tem
;
12850 Lisp_Object old
= selected_frame
;
12851 struct Lisp_Symbol
*sym
;
12853 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12855 selected_frame
= frame
;
12858 for (tail
= FVAR (XFRAME (frame
), param_alist
);
12859 CONSP (tail
); tail
= XCDR (tail
))
12860 if (CONSP (XCAR (tail
))
12861 && (tem
= XCAR (XCAR (tail
)),
12863 && (sym
= indirect_variable (XSYMBOL (tem
)),
12864 sym
->redirect
== SYMBOL_LOCALIZED
)
12865 && sym
->val
.blv
->frame_local
)
12866 /* Use find_symbol_value rather than Fsymbol_value
12867 to avoid an error if it is void. */
12868 find_symbol_value (tem
);
12869 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12873 #define STOP_POLLING \
12874 do { if (! polling_stopped_here) stop_polling (); \
12875 polling_stopped_here = 1; } while (0)
12877 #define RESUME_POLLING \
12878 do { if (polling_stopped_here) start_polling (); \
12879 polling_stopped_here = 0; } while (0)
12882 /* Perhaps in the future avoid recentering windows if it
12883 is not necessary; currently that causes some problems. */
12886 redisplay_internal (void)
12888 struct window
*w
= XWINDOW (selected_window
);
12892 int must_finish
= 0;
12893 struct text_pos tlbufpos
, tlendpos
;
12894 int number_of_visible_frames
;
12895 ptrdiff_t count
, count1
;
12897 int polling_stopped_here
= 0;
12898 Lisp_Object old_frame
= selected_frame
;
12900 /* Non-zero means redisplay has to consider all windows on all
12901 frames. Zero means, only selected_window is considered. */
12902 int consider_all_windows_p
;
12904 /* Non-zero means redisplay has to redisplay the miniwindow */
12905 int update_miniwindow_p
= 0;
12907 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12909 /* No redisplay if running in batch mode or frame is not yet fully
12910 initialized, or redisplay is explicitly turned off by setting
12911 Vinhibit_redisplay. */
12912 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12913 || !NILP (Vinhibit_redisplay
))
12916 /* Don't examine these until after testing Vinhibit_redisplay.
12917 When Emacs is shutting down, perhaps because its connection to
12918 X has dropped, we should not look at them at all. */
12919 fr
= XFRAME (WVAR (w
, frame
));
12920 sf
= SELECTED_FRAME ();
12922 if (!fr
->glyphs_initialized_p
)
12925 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12926 if (popup_activated ())
12930 /* I don't think this happens but let's be paranoid. */
12931 if (redisplaying_p
)
12934 /* Record a function that resets redisplaying_p to its old value
12935 when we leave this function. */
12936 count
= SPECPDL_INDEX ();
12937 record_unwind_protect (unwind_redisplay
,
12938 Fcons (make_number (redisplaying_p
), selected_frame
));
12940 specbind (Qinhibit_free_realized_faces
, Qnil
);
12943 Lisp_Object tail
, frame
;
12945 FOR_EACH_FRAME (tail
, frame
)
12947 struct frame
*f
= XFRAME (frame
);
12948 f
->already_hscrolled_p
= 0;
12953 /* Remember the currently selected window. */
12956 if (!EQ (old_frame
, selected_frame
)
12957 && FRAME_LIVE_P (XFRAME (old_frame
)))
12958 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12959 selected_frame and selected_window to be temporarily out-of-sync so
12960 when we come back here via `goto retry', we need to resync because we
12961 may need to run Elisp code (via prepare_menu_bars). */
12962 select_frame_for_redisplay (old_frame
);
12965 reconsider_clip_changes (w
, current_buffer
);
12966 last_escape_glyph_frame
= NULL
;
12967 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12968 last_glyphless_glyph_frame
= NULL
;
12969 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12971 /* If new fonts have been loaded that make a glyph matrix adjustment
12972 necessary, do it. */
12973 if (fonts_changed_p
)
12975 adjust_glyphs (NULL
);
12976 ++windows_or_buffers_changed
;
12977 fonts_changed_p
= 0;
12980 /* If face_change_count is non-zero, init_iterator will free all
12981 realized faces, which includes the faces referenced from current
12982 matrices. So, we can't reuse current matrices in this case. */
12983 if (face_change_count
)
12984 ++windows_or_buffers_changed
;
12986 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12987 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12989 /* Since frames on a single ASCII terminal share the same
12990 display area, displaying a different frame means redisplay
12991 the whole thing. */
12992 windows_or_buffers_changed
++;
12993 SET_FRAME_GARBAGED (sf
);
12995 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12997 FRAME_TTY (sf
)->previous_frame
= sf
;
13000 /* Set the visible flags for all frames. Do this before checking
13001 for resized or garbaged frames; they want to know if their frames
13002 are visible. See the comment in frame.h for
13003 FRAME_SAMPLE_VISIBILITY. */
13005 Lisp_Object tail
, frame
;
13007 number_of_visible_frames
= 0;
13009 FOR_EACH_FRAME (tail
, frame
)
13011 struct frame
*f
= XFRAME (frame
);
13013 FRAME_SAMPLE_VISIBILITY (f
);
13014 if (FRAME_VISIBLE_P (f
))
13015 ++number_of_visible_frames
;
13016 clear_desired_matrices (f
);
13020 /* Notice any pending interrupt request to change frame size. */
13021 do_pending_window_change (1);
13023 /* do_pending_window_change could change the selected_window due to
13024 frame resizing which makes the selected window too small. */
13025 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13028 reconsider_clip_changes (w
, current_buffer
);
13031 /* Clear frames marked as garbaged. */
13032 if (frame_garbaged
)
13033 clear_garbaged_frames ();
13035 /* Build menubar and tool-bar items. */
13036 if (NILP (Vmemory_full
))
13037 prepare_menu_bars ();
13039 if (windows_or_buffers_changed
)
13040 update_mode_lines
++;
13042 /* Detect case that we need to write or remove a star in the mode line. */
13043 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13045 w
->update_mode_line
= 1;
13046 if (buffer_shared
> 1)
13047 update_mode_lines
++;
13050 /* Avoid invocation of point motion hooks by `current_column' below. */
13051 count1
= SPECPDL_INDEX ();
13052 specbind (Qinhibit_point_motion_hooks
, Qt
);
13054 /* If %c is in the mode line, update it if needed. */
13055 if (!NILP (WVAR (w
, column_number_displayed
))
13056 /* This alternative quickly identifies a common case
13057 where no change is needed. */
13058 && !(PT
== w
->last_point
13059 && w
->last_modified
>= MODIFF
13060 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
13061 && (XFASTINT (WVAR (w
, column_number_displayed
)) != current_column ()))
13062 w
->update_mode_line
= 1;
13064 unbind_to (count1
, Qnil
);
13066 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (WVAR (w
, frame
))) = -1;
13068 /* The variable buffer_shared is set in redisplay_window and
13069 indicates that we redisplay a buffer in different windows. See
13071 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
13072 || cursor_type_changed
);
13074 /* If specs for an arrow have changed, do thorough redisplay
13075 to ensure we remove any arrow that should no longer exist. */
13076 if (overlay_arrows_changed_p ())
13077 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13079 /* Normally the message* functions will have already displayed and
13080 updated the echo area, but the frame may have been trashed, or
13081 the update may have been preempted, so display the echo area
13082 again here. Checking message_cleared_p captures the case that
13083 the echo area should be cleared. */
13084 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13085 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13086 || (message_cleared_p
13087 && minibuf_level
== 0
13088 /* If the mini-window is currently selected, this means the
13089 echo-area doesn't show through. */
13090 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13092 int window_height_changed_p
= echo_area_display (0);
13094 if (message_cleared_p
)
13095 update_miniwindow_p
= 1;
13099 /* If we don't display the current message, don't clear the
13100 message_cleared_p flag, because, if we did, we wouldn't clear
13101 the echo area in the next redisplay which doesn't preserve
13103 if (!display_last_displayed_message_p
)
13104 message_cleared_p
= 0;
13106 if (fonts_changed_p
)
13108 else if (window_height_changed_p
)
13110 consider_all_windows_p
= 1;
13111 ++update_mode_lines
;
13112 ++windows_or_buffers_changed
;
13114 /* If window configuration was changed, frames may have been
13115 marked garbaged. Clear them or we will experience
13116 surprises wrt scrolling. */
13117 if (frame_garbaged
)
13118 clear_garbaged_frames ();
13121 else if (EQ (selected_window
, minibuf_window
)
13122 && (current_buffer
->clip_changed
13123 || w
->last_modified
< MODIFF
13124 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
13125 && resize_mini_window (w
, 0))
13127 /* Resized active mini-window to fit the size of what it is
13128 showing if its contents might have changed. */
13130 /* FIXME: this causes all frames to be updated, which seems unnecessary
13131 since only the current frame needs to be considered. This function needs
13132 to be rewritten with two variables, consider_all_windows and
13133 consider_all_frames. */
13134 consider_all_windows_p
= 1;
13135 ++windows_or_buffers_changed
;
13136 ++update_mode_lines
;
13138 /* If window configuration was changed, frames may have been
13139 marked garbaged. Clear them or we will experience
13140 surprises wrt scrolling. */
13141 if (frame_garbaged
)
13142 clear_garbaged_frames ();
13146 /* If showing the region, and mark has changed, we must redisplay
13147 the whole window. The assignment to this_line_start_pos prevents
13148 the optimization directly below this if-statement. */
13149 if (((!NILP (Vtransient_mark_mode
)
13150 && !NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), mark_active
)))
13151 != !NILP (WVAR (w
, region_showing
)))
13152 || (!NILP (WVAR (w
, region_showing
))
13153 && !EQ (WVAR (w
, region_showing
),
13154 Fmarker_position (BVAR (XBUFFER (WVAR (w
, buffer
)), mark
)))))
13155 CHARPOS (this_line_start_pos
) = 0;
13157 /* Optimize the case that only the line containing the cursor in the
13158 selected window has changed. Variables starting with this_ are
13159 set in display_line and record information about the line
13160 containing the cursor. */
13161 tlbufpos
= this_line_start_pos
;
13162 tlendpos
= this_line_end_pos
;
13163 if (!consider_all_windows_p
13164 && CHARPOS (tlbufpos
) > 0
13165 && !w
->update_mode_line
13166 && !current_buffer
->clip_changed
13167 && !current_buffer
->prevent_redisplay_optimizations_p
13168 && FRAME_VISIBLE_P (XFRAME (WVAR (w
, frame
)))
13169 && !FRAME_OBSCURED_P (XFRAME (WVAR (w
, frame
)))
13170 /* Make sure recorded data applies to current buffer, etc. */
13171 && this_line_buffer
== current_buffer
13172 && current_buffer
== XBUFFER (WVAR (w
, buffer
))
13174 && !w
->optional_new_start
13175 /* Point must be on the line that we have info recorded about. */
13176 && PT
>= CHARPOS (tlbufpos
)
13177 && PT
<= Z
- CHARPOS (tlendpos
)
13178 /* All text outside that line, including its final newline,
13179 must be unchanged. */
13180 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13181 CHARPOS (tlendpos
)))
13183 if (CHARPOS (tlbufpos
) > BEGV
13184 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13185 && (CHARPOS (tlbufpos
) == ZV
13186 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13187 /* Former continuation line has disappeared by becoming empty. */
13189 else if (w
->last_modified
< MODIFF
13190 || w
->last_overlay_modified
< OVERLAY_MODIFF
13191 || MINI_WINDOW_P (w
))
13193 /* We have to handle the case of continuation around a
13194 wide-column character (see the comment in indent.c around
13197 For instance, in the following case:
13199 -------- Insert --------
13200 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13201 J_I_ ==> J_I_ `^^' are cursors.
13205 As we have to redraw the line above, we cannot use this
13209 int line_height_before
= this_line_pixel_height
;
13211 /* Note that start_display will handle the case that the
13212 line starting at tlbufpos is a continuation line. */
13213 start_display (&it
, w
, tlbufpos
);
13215 /* Implementation note: It this still necessary? */
13216 if (it
.current_x
!= this_line_start_x
)
13219 TRACE ((stderr
, "trying display optimization 1\n"));
13220 w
->cursor
.vpos
= -1;
13221 overlay_arrow_seen
= 0;
13222 it
.vpos
= this_line_vpos
;
13223 it
.current_y
= this_line_y
;
13224 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13225 display_line (&it
);
13227 /* If line contains point, is not continued,
13228 and ends at same distance from eob as before, we win. */
13229 if (w
->cursor
.vpos
>= 0
13230 /* Line is not continued, otherwise this_line_start_pos
13231 would have been set to 0 in display_line. */
13232 && CHARPOS (this_line_start_pos
)
13233 /* Line ends as before. */
13234 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13235 /* Line has same height as before. Otherwise other lines
13236 would have to be shifted up or down. */
13237 && this_line_pixel_height
== line_height_before
)
13239 /* If this is not the window's last line, we must adjust
13240 the charstarts of the lines below. */
13241 if (it
.current_y
< it
.last_visible_y
)
13243 struct glyph_row
*row
13244 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13245 ptrdiff_t delta
, delta_bytes
;
13247 /* We used to distinguish between two cases here,
13248 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13249 when the line ends in a newline or the end of the
13250 buffer's accessible portion. But both cases did
13251 the same, so they were collapsed. */
13253 - CHARPOS (tlendpos
)
13254 - MATRIX_ROW_START_CHARPOS (row
));
13255 delta_bytes
= (Z_BYTE
13256 - BYTEPOS (tlendpos
)
13257 - MATRIX_ROW_START_BYTEPOS (row
));
13259 increment_matrix_positions (w
->current_matrix
,
13260 this_line_vpos
+ 1,
13261 w
->current_matrix
->nrows
,
13262 delta
, delta_bytes
);
13265 /* If this row displays text now but previously didn't,
13266 or vice versa, w->window_end_vpos may have to be
13268 if ((it
.glyph_row
- 1)->displays_text_p
)
13270 if (XFASTINT (WVAR (w
, window_end_vpos
)) < this_line_vpos
)
13271 XSETINT (WVAR (w
, window_end_vpos
), this_line_vpos
);
13273 else if (XFASTINT (WVAR (w
, window_end_vpos
)) == this_line_vpos
13274 && this_line_vpos
> 0)
13275 XSETINT (WVAR (w
, window_end_vpos
), this_line_vpos
- 1);
13276 WVAR (w
, window_end_valid
) = Qnil
;
13278 /* Update hint: No need to try to scroll in update_window. */
13279 w
->desired_matrix
->no_scrolling_p
= 1;
13282 *w
->desired_matrix
->method
= 0;
13283 debug_method_add (w
, "optimization 1");
13285 #ifdef HAVE_WINDOW_SYSTEM
13286 update_window_fringes (w
, 0);
13293 else if (/* Cursor position hasn't changed. */
13294 PT
== w
->last_point
13295 /* Make sure the cursor was last displayed
13296 in this window. Otherwise we have to reposition it. */
13297 && 0 <= w
->cursor
.vpos
13298 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13302 do_pending_window_change (1);
13303 /* If selected_window changed, redisplay again. */
13304 if (WINDOWP (selected_window
)
13305 && (w
= XWINDOW (selected_window
)) != sw
)
13308 /* We used to always goto end_of_redisplay here, but this
13309 isn't enough if we have a blinking cursor. */
13310 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13311 goto end_of_redisplay
;
13315 /* If highlighting the region, or if the cursor is in the echo area,
13316 then we can't just move the cursor. */
13317 else if (! (!NILP (Vtransient_mark_mode
)
13318 && !NILP (BVAR (current_buffer
, mark_active
)))
13319 && (EQ (selected_window
,
13320 BVAR (current_buffer
, last_selected_window
))
13321 || highlight_nonselected_windows
)
13322 && NILP (WVAR (w
, region_showing
))
13323 && NILP (Vshow_trailing_whitespace
)
13324 && !cursor_in_echo_area
)
13327 struct glyph_row
*row
;
13329 /* Skip from tlbufpos to PT and see where it is. Note that
13330 PT may be in invisible text. If so, we will end at the
13331 next visible position. */
13332 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13333 NULL
, DEFAULT_FACE_ID
);
13334 it
.current_x
= this_line_start_x
;
13335 it
.current_y
= this_line_y
;
13336 it
.vpos
= this_line_vpos
;
13338 /* The call to move_it_to stops in front of PT, but
13339 moves over before-strings. */
13340 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13342 if (it
.vpos
== this_line_vpos
13343 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13346 eassert (this_line_vpos
== it
.vpos
);
13347 eassert (this_line_y
== it
.current_y
);
13348 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13350 *w
->desired_matrix
->method
= 0;
13351 debug_method_add (w
, "optimization 3");
13360 /* Text changed drastically or point moved off of line. */
13361 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13364 CHARPOS (this_line_start_pos
) = 0;
13365 consider_all_windows_p
|= buffer_shared
> 1;
13366 ++clear_face_cache_count
;
13367 #ifdef HAVE_WINDOW_SYSTEM
13368 ++clear_image_cache_count
;
13371 /* Build desired matrices, and update the display. If
13372 consider_all_windows_p is non-zero, do it for all windows on all
13373 frames. Otherwise do it for selected_window, only. */
13375 if (consider_all_windows_p
)
13377 Lisp_Object tail
, frame
;
13379 FOR_EACH_FRAME (tail
, frame
)
13380 XFRAME (frame
)->updated_p
= 0;
13382 /* Recompute # windows showing selected buffer. This will be
13383 incremented each time such a window is displayed. */
13386 FOR_EACH_FRAME (tail
, frame
)
13388 struct frame
*f
= XFRAME (frame
);
13390 /* We don't have to do anything for unselected terminal
13392 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13393 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13396 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13398 if (! EQ (frame
, selected_frame
))
13399 /* Select the frame, for the sake of frame-local
13401 select_frame_for_redisplay (frame
);
13403 /* Mark all the scroll bars to be removed; we'll redeem
13404 the ones we want when we redisplay their windows. */
13405 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13406 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13408 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13409 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13411 /* The X error handler may have deleted that frame. */
13412 if (!FRAME_LIVE_P (f
))
13415 /* Any scroll bars which redisplay_windows should have
13416 nuked should now go away. */
13417 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13418 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13420 /* If fonts changed, display again. */
13421 /* ??? rms: I suspect it is a mistake to jump all the way
13422 back to retry here. It should just retry this frame. */
13423 if (fonts_changed_p
)
13426 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13428 /* See if we have to hscroll. */
13429 if (!f
->already_hscrolled_p
)
13431 f
->already_hscrolled_p
= 1;
13432 if (hscroll_windows (FVAR (f
, root_window
)))
13436 /* Prevent various kinds of signals during display
13437 update. stdio is not robust about handling
13438 signals, which can cause an apparent I/O
13440 if (interrupt_input
)
13441 unrequest_sigio ();
13444 /* Update the display. */
13445 set_window_update_flags (XWINDOW (FVAR (f
, root_window
)), 1);
13446 pending
|= update_frame (f
, 0, 0);
13452 if (!EQ (old_frame
, selected_frame
)
13453 && FRAME_LIVE_P (XFRAME (old_frame
)))
13454 /* We played a bit fast-and-loose above and allowed selected_frame
13455 and selected_window to be temporarily out-of-sync but let's make
13456 sure this stays contained. */
13457 select_frame_for_redisplay (old_frame
);
13458 eassert (EQ (FVAR (XFRAME (selected_frame
), selected_window
),
13463 /* Do the mark_window_display_accurate after all windows have
13464 been redisplayed because this call resets flags in buffers
13465 which are needed for proper redisplay. */
13466 FOR_EACH_FRAME (tail
, frame
)
13468 struct frame
*f
= XFRAME (frame
);
13471 mark_window_display_accurate (FVAR (f
, root_window
), 1);
13472 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13473 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13478 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13480 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13481 struct frame
*mini_frame
;
13483 displayed_buffer
= XBUFFER (WVAR (XWINDOW (selected_window
), buffer
));
13484 /* Use list_of_error, not Qerror, so that
13485 we catch only errors and don't run the debugger. */
13486 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13488 redisplay_window_error
);
13489 if (update_miniwindow_p
)
13490 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13492 redisplay_window_error
);
13494 /* Compare desired and current matrices, perform output. */
13497 /* If fonts changed, display again. */
13498 if (fonts_changed_p
)
13501 /* Prevent various kinds of signals during display update.
13502 stdio is not robust about handling signals,
13503 which can cause an apparent I/O error. */
13504 if (interrupt_input
)
13505 unrequest_sigio ();
13508 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13510 if (hscroll_windows (selected_window
))
13513 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13514 pending
= update_frame (sf
, 0, 0);
13517 /* We may have called echo_area_display at the top of this
13518 function. If the echo area is on another frame, that may
13519 have put text on a frame other than the selected one, so the
13520 above call to update_frame would not have caught it. Catch
13522 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13523 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13525 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13527 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13528 pending
|= update_frame (mini_frame
, 0, 0);
13529 if (!pending
&& hscroll_windows (mini_window
))
13534 /* If display was paused because of pending input, make sure we do a
13535 thorough update the next time. */
13538 /* Prevent the optimization at the beginning of
13539 redisplay_internal that tries a single-line update of the
13540 line containing the cursor in the selected window. */
13541 CHARPOS (this_line_start_pos
) = 0;
13543 /* Let the overlay arrow be updated the next time. */
13544 update_overlay_arrows (0);
13546 /* If we pause after scrolling, some rows in the current
13547 matrices of some windows are not valid. */
13548 if (!WINDOW_FULL_WIDTH_P (w
)
13549 && !FRAME_WINDOW_P (XFRAME (WVAR (w
, frame
))))
13550 update_mode_lines
= 1;
13554 if (!consider_all_windows_p
)
13556 /* This has already been done above if
13557 consider_all_windows_p is set. */
13558 mark_window_display_accurate_1 (w
, 1);
13560 /* Say overlay arrows are up to date. */
13561 update_overlay_arrows (1);
13563 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13564 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13567 update_mode_lines
= 0;
13568 windows_or_buffers_changed
= 0;
13569 cursor_type_changed
= 0;
13572 /* Start SIGIO interrupts coming again. Having them off during the
13573 code above makes it less likely one will discard output, but not
13574 impossible, since there might be stuff in the system buffer here.
13575 But it is much hairier to try to do anything about that. */
13576 if (interrupt_input
)
13580 /* If a frame has become visible which was not before, redisplay
13581 again, so that we display it. Expose events for such a frame
13582 (which it gets when becoming visible) don't call the parts of
13583 redisplay constructing glyphs, so simply exposing a frame won't
13584 display anything in this case. So, we have to display these
13585 frames here explicitly. */
13588 Lisp_Object tail
, frame
;
13591 FOR_EACH_FRAME (tail
, frame
)
13593 int this_is_visible
= 0;
13595 if (XFRAME (frame
)->visible
)
13596 this_is_visible
= 1;
13597 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13598 if (XFRAME (frame
)->visible
)
13599 this_is_visible
= 1;
13601 if (this_is_visible
)
13605 if (new_count
!= number_of_visible_frames
)
13606 windows_or_buffers_changed
++;
13609 /* Change frame size now if a change is pending. */
13610 do_pending_window_change (1);
13612 /* If we just did a pending size change, or have additional
13613 visible frames, or selected_window changed, redisplay again. */
13614 if ((windows_or_buffers_changed
&& !pending
)
13615 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13618 /* Clear the face and image caches.
13620 We used to do this only if consider_all_windows_p. But the cache
13621 needs to be cleared if a timer creates images in the current
13622 buffer (e.g. the test case in Bug#6230). */
13624 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13626 clear_face_cache (0);
13627 clear_face_cache_count
= 0;
13630 #ifdef HAVE_WINDOW_SYSTEM
13631 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13633 clear_image_caches (Qnil
);
13634 clear_image_cache_count
= 0;
13636 #endif /* HAVE_WINDOW_SYSTEM */
13639 unbind_to (count
, Qnil
);
13644 /* Redisplay, but leave alone any recent echo area message unless
13645 another message has been requested in its place.
13647 This is useful in situations where you need to redisplay but no
13648 user action has occurred, making it inappropriate for the message
13649 area to be cleared. See tracking_off and
13650 wait_reading_process_output for examples of these situations.
13652 FROM_WHERE is an integer saying from where this function was
13653 called. This is useful for debugging. */
13656 redisplay_preserve_echo_area (int from_where
)
13658 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13660 if (!NILP (echo_area_buffer
[1]))
13662 /* We have a previously displayed message, but no current
13663 message. Redisplay the previous message. */
13664 display_last_displayed_message_p
= 1;
13665 redisplay_internal ();
13666 display_last_displayed_message_p
= 0;
13669 redisplay_internal ();
13671 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13672 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13673 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13677 /* Function registered with record_unwind_protect in
13678 redisplay_internal. Reset redisplaying_p to the value it had
13679 before redisplay_internal was called, and clear
13680 prevent_freeing_realized_faces_p. It also selects the previously
13681 selected frame, unless it has been deleted (by an X connection
13682 failure during redisplay, for example). */
13685 unwind_redisplay (Lisp_Object val
)
13687 Lisp_Object old_redisplaying_p
, old_frame
;
13689 old_redisplaying_p
= XCAR (val
);
13690 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13691 old_frame
= XCDR (val
);
13692 if (! EQ (old_frame
, selected_frame
)
13693 && FRAME_LIVE_P (XFRAME (old_frame
)))
13694 select_frame_for_redisplay (old_frame
);
13699 /* Mark the display of window W as accurate or inaccurate. If
13700 ACCURATE_P is non-zero mark display of W as accurate. If
13701 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13702 redisplay_internal is called. */
13705 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13707 if (BUFFERP (WVAR (w
, buffer
)))
13709 struct buffer
*b
= XBUFFER (WVAR (w
, buffer
));
13711 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13712 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13714 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13718 b
->clip_changed
= 0;
13719 b
->prevent_redisplay_optimizations_p
= 0;
13721 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13722 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13723 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13724 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13726 w
->current_matrix
->buffer
= b
;
13727 w
->current_matrix
->begv
= BUF_BEGV (b
);
13728 w
->current_matrix
->zv
= BUF_ZV (b
);
13730 w
->last_cursor
= w
->cursor
;
13731 w
->last_cursor_off_p
= w
->cursor_off_p
;
13733 if (w
== XWINDOW (selected_window
))
13734 w
->last_point
= BUF_PT (b
);
13736 w
->last_point
= XMARKER (WVAR (w
, pointm
))->charpos
;
13742 WVAR (w
, window_end_valid
) = WVAR (w
, buffer
);
13743 w
->update_mode_line
= 0;
13748 /* Mark the display of windows in the window tree rooted at WINDOW as
13749 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13750 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13751 be redisplayed the next time redisplay_internal is called. */
13754 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13758 for (; !NILP (window
); window
= WVAR (w
, next
))
13760 w
= XWINDOW (window
);
13761 mark_window_display_accurate_1 (w
, accurate_p
);
13763 if (!NILP (WVAR (w
, vchild
)))
13764 mark_window_display_accurate (WVAR (w
, vchild
), accurate_p
);
13765 if (!NILP (WVAR (w
, hchild
)))
13766 mark_window_display_accurate (WVAR (w
, hchild
), accurate_p
);
13771 update_overlay_arrows (1);
13775 /* Force a thorough redisplay the next time by setting
13776 last_arrow_position and last_arrow_string to t, which is
13777 unequal to any useful value of Voverlay_arrow_... */
13778 update_overlay_arrows (-1);
13783 /* Return value in display table DP (Lisp_Char_Table *) for character
13784 C. Since a display table doesn't have any parent, we don't have to
13785 follow parent. Do not call this function directly but use the
13786 macro DISP_CHAR_VECTOR. */
13789 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13793 if (ASCII_CHAR_P (c
))
13796 if (SUB_CHAR_TABLE_P (val
))
13797 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13803 XSETCHAR_TABLE (table
, dp
);
13804 val
= char_table_ref (table
, c
);
13813 /***********************************************************************
13815 ***********************************************************************/
13817 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13820 redisplay_windows (Lisp_Object window
)
13822 while (!NILP (window
))
13824 struct window
*w
= XWINDOW (window
);
13826 if (!NILP (WVAR (w
, hchild
)))
13827 redisplay_windows (WVAR (w
, hchild
));
13828 else if (!NILP (WVAR (w
, vchild
)))
13829 redisplay_windows (WVAR (w
, vchild
));
13830 else if (!NILP (WVAR (w
, buffer
)))
13832 displayed_buffer
= XBUFFER (WVAR (w
, buffer
));
13833 /* Use list_of_error, not Qerror, so that
13834 we catch only errors and don't run the debugger. */
13835 internal_condition_case_1 (redisplay_window_0
, window
,
13837 redisplay_window_error
);
13840 window
= WVAR (w
, next
);
13845 redisplay_window_error (Lisp_Object ignore
)
13847 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13852 redisplay_window_0 (Lisp_Object window
)
13854 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13855 redisplay_window (window
, 0);
13860 redisplay_window_1 (Lisp_Object window
)
13862 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13863 redisplay_window (window
, 1);
13868 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13869 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13870 which positions recorded in ROW differ from current buffer
13873 Return 0 if cursor is not on this row, 1 otherwise. */
13876 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13877 struct glyph_matrix
*matrix
,
13878 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13881 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13882 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13883 struct glyph
*cursor
= NULL
;
13884 /* The last known character position in row. */
13885 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13887 ptrdiff_t pt_old
= PT
- delta
;
13888 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13889 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13890 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13891 /* A glyph beyond the edge of TEXT_AREA which we should never
13893 struct glyph
*glyphs_end
= end
;
13894 /* Non-zero means we've found a match for cursor position, but that
13895 glyph has the avoid_cursor_p flag set. */
13896 int match_with_avoid_cursor
= 0;
13897 /* Non-zero means we've seen at least one glyph that came from a
13899 int string_seen
= 0;
13900 /* Largest and smallest buffer positions seen so far during scan of
13902 ptrdiff_t bpos_max
= pos_before
;
13903 ptrdiff_t bpos_min
= pos_after
;
13904 /* Last buffer position covered by an overlay string with an integer
13905 `cursor' property. */
13906 ptrdiff_t bpos_covered
= 0;
13907 /* Non-zero means the display string on which to display the cursor
13908 comes from a text property, not from an overlay. */
13909 int string_from_text_prop
= 0;
13911 /* Don't even try doing anything if called for a mode-line or
13912 header-line row, since the rest of the code isn't prepared to
13913 deal with such calamities. */
13914 eassert (!row
->mode_line_p
);
13915 if (row
->mode_line_p
)
13918 /* Skip over glyphs not having an object at the start and the end of
13919 the row. These are special glyphs like truncation marks on
13920 terminal frames. */
13921 if (row
->displays_text_p
)
13923 if (!row
->reversed_p
)
13926 && INTEGERP (glyph
->object
)
13927 && glyph
->charpos
< 0)
13929 x
+= glyph
->pixel_width
;
13933 && INTEGERP ((end
- 1)->object
)
13934 /* CHARPOS is zero for blanks and stretch glyphs
13935 inserted by extend_face_to_end_of_line. */
13936 && (end
- 1)->charpos
<= 0)
13938 glyph_before
= glyph
- 1;
13945 /* If the glyph row is reversed, we need to process it from back
13946 to front, so swap the edge pointers. */
13947 glyphs_end
= end
= glyph
- 1;
13948 glyph
+= row
->used
[TEXT_AREA
] - 1;
13950 while (glyph
> end
+ 1
13951 && INTEGERP (glyph
->object
)
13952 && glyph
->charpos
< 0)
13955 x
-= glyph
->pixel_width
;
13957 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13959 /* By default, in reversed rows we put the cursor on the
13960 rightmost (first in the reading order) glyph. */
13961 for (g
= end
+ 1; g
< glyph
; g
++)
13962 x
+= g
->pixel_width
;
13964 && INTEGERP ((end
+ 1)->object
)
13965 && (end
+ 1)->charpos
<= 0)
13967 glyph_before
= glyph
+ 1;
13971 else if (row
->reversed_p
)
13973 /* In R2L rows that don't display text, put the cursor on the
13974 rightmost glyph. Case in point: an empty last line that is
13975 part of an R2L paragraph. */
13977 /* Avoid placing the cursor on the last glyph of the row, where
13978 on terminal frames we hold the vertical border between
13979 adjacent windows. */
13980 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13981 && !WINDOW_RIGHTMOST_P (w
)
13982 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13984 x
= -1; /* will be computed below, at label compute_x */
13987 /* Step 1: Try to find the glyph whose character position
13988 corresponds to point. If that's not possible, find 2 glyphs
13989 whose character positions are the closest to point, one before
13990 point, the other after it. */
13991 if (!row
->reversed_p
)
13992 while (/* not marched to end of glyph row */
13994 /* glyph was not inserted by redisplay for internal purposes */
13995 && !INTEGERP (glyph
->object
))
13997 if (BUFFERP (glyph
->object
))
13999 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14001 if (glyph
->charpos
> bpos_max
)
14002 bpos_max
= glyph
->charpos
;
14003 if (glyph
->charpos
< bpos_min
)
14004 bpos_min
= glyph
->charpos
;
14005 if (!glyph
->avoid_cursor_p
)
14007 /* If we hit point, we've found the glyph on which to
14008 display the cursor. */
14011 match_with_avoid_cursor
= 0;
14014 /* See if we've found a better approximation to
14015 POS_BEFORE or to POS_AFTER. */
14016 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14018 pos_before
= glyph
->charpos
;
14019 glyph_before
= glyph
;
14021 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14023 pos_after
= glyph
->charpos
;
14024 glyph_after
= glyph
;
14027 else if (dpos
== 0)
14028 match_with_avoid_cursor
= 1;
14030 else if (STRINGP (glyph
->object
))
14032 Lisp_Object chprop
;
14033 ptrdiff_t glyph_pos
= glyph
->charpos
;
14035 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14037 if (!NILP (chprop
))
14039 /* If the string came from a `display' text property,
14040 look up the buffer position of that property and
14041 use that position to update bpos_max, as if we
14042 actually saw such a position in one of the row's
14043 glyphs. This helps with supporting integer values
14044 of `cursor' property on the display string in
14045 situations where most or all of the row's buffer
14046 text is completely covered by display properties,
14047 so that no glyph with valid buffer positions is
14048 ever seen in the row. */
14049 ptrdiff_t prop_pos
=
14050 string_buffer_position_lim (glyph
->object
, pos_before
,
14053 if (prop_pos
>= pos_before
)
14054 bpos_max
= prop_pos
- 1;
14056 if (INTEGERP (chprop
))
14058 bpos_covered
= bpos_max
+ XINT (chprop
);
14059 /* If the `cursor' property covers buffer positions up
14060 to and including point, we should display cursor on
14061 this glyph. Note that, if a `cursor' property on one
14062 of the string's characters has an integer value, we
14063 will break out of the loop below _before_ we get to
14064 the position match above. IOW, integer values of
14065 the `cursor' property override the "exact match for
14066 point" strategy of positioning the cursor. */
14067 /* Implementation note: bpos_max == pt_old when, e.g.,
14068 we are in an empty line, where bpos_max is set to
14069 MATRIX_ROW_START_CHARPOS, see above. */
14070 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14079 x
+= glyph
->pixel_width
;
14082 else if (glyph
> end
) /* row is reversed */
14083 while (!INTEGERP (glyph
->object
))
14085 if (BUFFERP (glyph
->object
))
14087 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14089 if (glyph
->charpos
> bpos_max
)
14090 bpos_max
= glyph
->charpos
;
14091 if (glyph
->charpos
< bpos_min
)
14092 bpos_min
= glyph
->charpos
;
14093 if (!glyph
->avoid_cursor_p
)
14097 match_with_avoid_cursor
= 0;
14100 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14102 pos_before
= glyph
->charpos
;
14103 glyph_before
= glyph
;
14105 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14107 pos_after
= glyph
->charpos
;
14108 glyph_after
= glyph
;
14111 else if (dpos
== 0)
14112 match_with_avoid_cursor
= 1;
14114 else if (STRINGP (glyph
->object
))
14116 Lisp_Object chprop
;
14117 ptrdiff_t glyph_pos
= glyph
->charpos
;
14119 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14121 if (!NILP (chprop
))
14123 ptrdiff_t prop_pos
=
14124 string_buffer_position_lim (glyph
->object
, pos_before
,
14127 if (prop_pos
>= pos_before
)
14128 bpos_max
= prop_pos
- 1;
14130 if (INTEGERP (chprop
))
14132 bpos_covered
= bpos_max
+ XINT (chprop
);
14133 /* If the `cursor' property covers buffer positions up
14134 to and including point, we should display cursor on
14136 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14145 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14147 x
--; /* can't use any pixel_width */
14150 x
-= glyph
->pixel_width
;
14153 /* Step 2: If we didn't find an exact match for point, we need to
14154 look for a proper place to put the cursor among glyphs between
14155 GLYPH_BEFORE and GLYPH_AFTER. */
14156 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14157 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14158 && bpos_covered
< pt_old
)
14160 /* An empty line has a single glyph whose OBJECT is zero and
14161 whose CHARPOS is the position of a newline on that line.
14162 Note that on a TTY, there are more glyphs after that, which
14163 were produced by extend_face_to_end_of_line, but their
14164 CHARPOS is zero or negative. */
14166 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14167 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14169 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14171 ptrdiff_t ellipsis_pos
;
14173 /* Scan back over the ellipsis glyphs. */
14174 if (!row
->reversed_p
)
14176 ellipsis_pos
= (glyph
- 1)->charpos
;
14177 while (glyph
> row
->glyphs
[TEXT_AREA
]
14178 && (glyph
- 1)->charpos
== ellipsis_pos
)
14179 glyph
--, x
-= glyph
->pixel_width
;
14180 /* That loop always goes one position too far, including
14181 the glyph before the ellipsis. So scan forward over
14183 x
+= glyph
->pixel_width
;
14186 else /* row is reversed */
14188 ellipsis_pos
= (glyph
+ 1)->charpos
;
14189 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14190 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14191 glyph
++, x
+= glyph
->pixel_width
;
14192 x
-= glyph
->pixel_width
;
14196 else if (match_with_avoid_cursor
)
14198 cursor
= glyph_after
;
14201 else if (string_seen
)
14203 int incr
= row
->reversed_p
? -1 : +1;
14205 /* Need to find the glyph that came out of a string which is
14206 present at point. That glyph is somewhere between
14207 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14208 positioned between POS_BEFORE and POS_AFTER in the
14210 struct glyph
*start
, *stop
;
14211 ptrdiff_t pos
= pos_before
;
14215 /* If the row ends in a newline from a display string,
14216 reordering could have moved the glyphs belonging to the
14217 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14218 in this case we extend the search to the last glyph in
14219 the row that was not inserted by redisplay. */
14220 if (row
->ends_in_newline_from_string_p
)
14223 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14226 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14227 correspond to POS_BEFORE and POS_AFTER, respectively. We
14228 need START and STOP in the order that corresponds to the
14229 row's direction as given by its reversed_p flag. If the
14230 directionality of characters between POS_BEFORE and
14231 POS_AFTER is the opposite of the row's base direction,
14232 these characters will have been reordered for display,
14233 and we need to reverse START and STOP. */
14234 if (!row
->reversed_p
)
14236 start
= min (glyph_before
, glyph_after
);
14237 stop
= max (glyph_before
, glyph_after
);
14241 start
= max (glyph_before
, glyph_after
);
14242 stop
= min (glyph_before
, glyph_after
);
14244 for (glyph
= start
+ incr
;
14245 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14248 /* Any glyphs that come from the buffer are here because
14249 of bidi reordering. Skip them, and only pay
14250 attention to glyphs that came from some string. */
14251 if (STRINGP (glyph
->object
))
14255 /* If the display property covers the newline, we
14256 need to search for it one position farther. */
14257 ptrdiff_t lim
= pos_after
14258 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14260 string_from_text_prop
= 0;
14261 str
= glyph
->object
;
14262 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14263 if (tem
== 0 /* from overlay */
14266 /* If the string from which this glyph came is
14267 found in the buffer at point, or at position
14268 that is closer to point than pos_after, then
14269 we've found the glyph we've been looking for.
14270 If it comes from an overlay (tem == 0), and
14271 it has the `cursor' property on one of its
14272 glyphs, record that glyph as a candidate for
14273 displaying the cursor. (As in the
14274 unidirectional version, we will display the
14275 cursor on the last candidate we find.) */
14278 || (tem
- pt_old
> 0 && tem
< pos_after
))
14280 /* The glyphs from this string could have
14281 been reordered. Find the one with the
14282 smallest string position. Or there could
14283 be a character in the string with the
14284 `cursor' property, which means display
14285 cursor on that character's glyph. */
14286 ptrdiff_t strpos
= glyph
->charpos
;
14291 string_from_text_prop
= 1;
14294 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14295 && EQ (glyph
->object
, str
);
14299 ptrdiff_t gpos
= glyph
->charpos
;
14301 cprop
= Fget_char_property (make_number (gpos
),
14309 if (tem
&& glyph
->charpos
< strpos
)
14311 strpos
= glyph
->charpos
;
14317 || (tem
- pt_old
> 0 && tem
< pos_after
))
14321 pos
= tem
+ 1; /* don't find previous instances */
14323 /* This string is not what we want; skip all of the
14324 glyphs that came from it. */
14325 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14326 && EQ (glyph
->object
, str
))
14333 /* If we reached the end of the line, and END was from a string,
14334 the cursor is not on this line. */
14336 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14337 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14338 && STRINGP (end
->object
)
14339 && row
->continued_p
)
14342 /* A truncated row may not include PT among its character positions.
14343 Setting the cursor inside the scroll margin will trigger
14344 recalculation of hscroll in hscroll_window_tree. But if a
14345 display string covers point, defer to the string-handling
14346 code below to figure this out. */
14347 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14349 cursor
= glyph_before
;
14352 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14353 /* Zero-width characters produce no glyphs. */
14355 && (row
->reversed_p
14356 ? glyph_after
> glyphs_end
14357 : glyph_after
< glyphs_end
)))
14359 cursor
= glyph_after
;
14365 if (cursor
!= NULL
)
14367 else if (glyph
== glyphs_end
14368 && pos_before
== pos_after
14369 && STRINGP ((row
->reversed_p
14370 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14371 : row
->glyphs
[TEXT_AREA
])->object
))
14373 /* If all the glyphs of this row came from strings, put the
14374 cursor on the first glyph of the row. This avoids having the
14375 cursor outside of the text area in this very rare and hard
14379 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14380 : row
->glyphs
[TEXT_AREA
];
14386 /* Need to compute x that corresponds to GLYPH. */
14387 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14389 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14391 x
+= g
->pixel_width
;
14395 /* ROW could be part of a continued line, which, under bidi
14396 reordering, might have other rows whose start and end charpos
14397 occlude point. Only set w->cursor if we found a better
14398 approximation to the cursor position than we have from previously
14399 examined candidate rows belonging to the same continued line. */
14400 if (/* we already have a candidate row */
14401 w
->cursor
.vpos
>= 0
14402 /* that candidate is not the row we are processing */
14403 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14404 /* Make sure cursor.vpos specifies a row whose start and end
14405 charpos occlude point, and it is valid candidate for being a
14406 cursor-row. This is because some callers of this function
14407 leave cursor.vpos at the row where the cursor was displayed
14408 during the last redisplay cycle. */
14409 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14410 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14411 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14414 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14416 /* Don't consider glyphs that are outside TEXT_AREA. */
14417 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14419 /* Keep the candidate whose buffer position is the closest to
14420 point or has the `cursor' property. */
14421 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14422 w
->cursor
.hpos
>= 0
14423 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14424 && ((BUFFERP (g1
->object
)
14425 && (g1
->charpos
== pt_old
/* an exact match always wins */
14426 || (BUFFERP (glyph
->object
)
14427 && eabs (g1
->charpos
- pt_old
)
14428 < eabs (glyph
->charpos
- pt_old
))))
14429 /* previous candidate is a glyph from a string that has
14430 a non-nil `cursor' property */
14431 || (STRINGP (g1
->object
)
14432 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14433 Qcursor
, g1
->object
))
14434 /* previous candidate is from the same display
14435 string as this one, and the display string
14436 came from a text property */
14437 || (EQ (g1
->object
, glyph
->object
)
14438 && string_from_text_prop
)
14439 /* this candidate is from newline and its
14440 position is not an exact match */
14441 || (INTEGERP (glyph
->object
)
14442 && glyph
->charpos
!= pt_old
)))))
14444 /* If this candidate gives an exact match, use that. */
14445 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14446 /* If this candidate is a glyph created for the
14447 terminating newline of a line, and point is on that
14448 newline, it wins because it's an exact match. */
14449 || (!row
->continued_p
14450 && INTEGERP (glyph
->object
)
14451 && glyph
->charpos
== 0
14452 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14453 /* Otherwise, keep the candidate that comes from a row
14454 spanning less buffer positions. This may win when one or
14455 both candidate positions are on glyphs that came from
14456 display strings, for which we cannot compare buffer
14458 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14459 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14460 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14463 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14465 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14466 w
->cursor
.y
= row
->y
+ dy
;
14468 if (w
== XWINDOW (selected_window
))
14470 if (!row
->continued_p
14471 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14474 this_line_buffer
= XBUFFER (WVAR (w
, buffer
));
14476 CHARPOS (this_line_start_pos
)
14477 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14478 BYTEPOS (this_line_start_pos
)
14479 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14481 CHARPOS (this_line_end_pos
)
14482 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14483 BYTEPOS (this_line_end_pos
)
14484 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14486 this_line_y
= w
->cursor
.y
;
14487 this_line_pixel_height
= row
->height
;
14488 this_line_vpos
= w
->cursor
.vpos
;
14489 this_line_start_x
= row
->x
;
14492 CHARPOS (this_line_start_pos
) = 0;
14499 /* Run window scroll functions, if any, for WINDOW with new window
14500 start STARTP. Sets the window start of WINDOW to that position.
14502 We assume that the window's buffer is really current. */
14504 static inline struct text_pos
14505 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14507 struct window
*w
= XWINDOW (window
);
14508 SET_MARKER_FROM_TEXT_POS (WVAR (w
, start
), startp
);
14510 if (current_buffer
!= XBUFFER (WVAR (w
, buffer
)))
14513 if (!NILP (Vwindow_scroll_functions
))
14515 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14516 make_number (CHARPOS (startp
)));
14517 SET_TEXT_POS_FROM_MARKER (startp
, WVAR (w
, start
));
14518 /* In case the hook functions switch buffers. */
14519 if (current_buffer
!= XBUFFER (WVAR (w
, buffer
)))
14520 set_buffer_internal_1 (XBUFFER (WVAR (w
, buffer
)));
14527 /* Make sure the line containing the cursor is fully visible.
14528 A value of 1 means there is nothing to be done.
14529 (Either the line is fully visible, or it cannot be made so,
14530 or we cannot tell.)
14532 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14533 is higher than window.
14535 A value of 0 means the caller should do scrolling
14536 as if point had gone off the screen. */
14539 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14541 struct glyph_matrix
*matrix
;
14542 struct glyph_row
*row
;
14545 if (!make_cursor_line_fully_visible_p
)
14548 /* It's not always possible to find the cursor, e.g, when a window
14549 is full of overlay strings. Don't do anything in that case. */
14550 if (w
->cursor
.vpos
< 0)
14553 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14554 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14556 /* If the cursor row is not partially visible, there's nothing to do. */
14557 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14560 /* If the row the cursor is in is taller than the window's height,
14561 it's not clear what to do, so do nothing. */
14562 window_height
= window_box_height (w
);
14563 if (row
->height
>= window_height
)
14565 if (!force_p
|| MINI_WINDOW_P (w
)
14566 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14573 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14574 non-zero means only WINDOW is redisplayed in redisplay_internal.
14575 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14576 in redisplay_window to bring a partially visible line into view in
14577 the case that only the cursor has moved.
14579 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14580 last screen line's vertical height extends past the end of the screen.
14584 1 if scrolling succeeded
14586 0 if scrolling didn't find point.
14588 -1 if new fonts have been loaded so that we must interrupt
14589 redisplay, adjust glyph matrices, and try again. */
14595 SCROLLING_NEED_LARGER_MATRICES
14598 /* If scroll-conservatively is more than this, never recenter.
14600 If you change this, don't forget to update the doc string of
14601 `scroll-conservatively' and the Emacs manual. */
14602 #define SCROLL_LIMIT 100
14605 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14606 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14607 int temp_scroll_step
, int last_line_misfit
)
14609 struct window
*w
= XWINDOW (window
);
14610 struct frame
*f
= XFRAME (WVAR (w
, frame
));
14611 struct text_pos pos
, startp
;
14613 int this_scroll_margin
, scroll_max
, rc
, height
;
14614 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14615 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14616 Lisp_Object aggressive
;
14617 /* We will never try scrolling more than this number of lines. */
14618 int scroll_limit
= SCROLL_LIMIT
;
14621 debug_method_add (w
, "try_scrolling");
14624 SET_TEXT_POS_FROM_MARKER (startp
, WVAR (w
, start
));
14626 /* Compute scroll margin height in pixels. We scroll when point is
14627 within this distance from the top or bottom of the window. */
14628 if (scroll_margin
> 0)
14629 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14630 * FRAME_LINE_HEIGHT (f
);
14632 this_scroll_margin
= 0;
14634 /* Force arg_scroll_conservatively to have a reasonable value, to
14635 avoid scrolling too far away with slow move_it_* functions. Note
14636 that the user can supply scroll-conservatively equal to
14637 `most-positive-fixnum', which can be larger than INT_MAX. */
14638 if (arg_scroll_conservatively
> scroll_limit
)
14640 arg_scroll_conservatively
= scroll_limit
+ 1;
14641 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14643 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14644 /* Compute how much we should try to scroll maximally to bring
14645 point into view. */
14646 scroll_max
= (max (scroll_step
,
14647 max (arg_scroll_conservatively
, temp_scroll_step
))
14648 * FRAME_LINE_HEIGHT (f
));
14649 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14650 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14651 /* We're trying to scroll because of aggressive scrolling but no
14652 scroll_step is set. Choose an arbitrary one. */
14653 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14659 /* Decide whether to scroll down. */
14660 if (PT
> CHARPOS (startp
))
14662 int scroll_margin_y
;
14664 /* Compute the pixel ypos of the scroll margin, then move IT to
14665 either that ypos or PT, whichever comes first. */
14666 start_display (&it
, w
, startp
);
14667 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14668 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14669 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14670 (MOVE_TO_POS
| MOVE_TO_Y
));
14672 if (PT
> CHARPOS (it
.current
.pos
))
14674 int y0
= line_bottom_y (&it
);
14675 /* Compute how many pixels below window bottom to stop searching
14676 for PT. This avoids costly search for PT that is far away if
14677 the user limited scrolling by a small number of lines, but
14678 always finds PT if scroll_conservatively is set to a large
14679 number, such as most-positive-fixnum. */
14680 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14681 int y_to_move
= it
.last_visible_y
+ slack
;
14683 /* Compute the distance from the scroll margin to PT or to
14684 the scroll limit, whichever comes first. This should
14685 include the height of the cursor line, to make that line
14687 move_it_to (&it
, PT
, -1, y_to_move
,
14688 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14689 dy
= line_bottom_y (&it
) - y0
;
14691 if (dy
> scroll_max
)
14692 return SCROLLING_FAILED
;
14701 /* Point is in or below the bottom scroll margin, so move the
14702 window start down. If scrolling conservatively, move it just
14703 enough down to make point visible. If scroll_step is set,
14704 move it down by scroll_step. */
14705 if (arg_scroll_conservatively
)
14707 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14708 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14709 else if (scroll_step
|| temp_scroll_step
)
14710 amount_to_scroll
= scroll_max
;
14713 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14714 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14715 if (NUMBERP (aggressive
))
14717 double float_amount
= XFLOATINT (aggressive
) * height
;
14718 amount_to_scroll
= float_amount
;
14719 if (amount_to_scroll
== 0 && float_amount
> 0)
14720 amount_to_scroll
= 1;
14721 /* Don't let point enter the scroll margin near top of
14723 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14724 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14728 if (amount_to_scroll
<= 0)
14729 return SCROLLING_FAILED
;
14731 start_display (&it
, w
, startp
);
14732 if (arg_scroll_conservatively
<= scroll_limit
)
14733 move_it_vertically (&it
, amount_to_scroll
);
14736 /* Extra precision for users who set scroll-conservatively
14737 to a large number: make sure the amount we scroll
14738 the window start is never less than amount_to_scroll,
14739 which was computed as distance from window bottom to
14740 point. This matters when lines at window top and lines
14741 below window bottom have different height. */
14743 void *it1data
= NULL
;
14744 /* We use a temporary it1 because line_bottom_y can modify
14745 its argument, if it moves one line down; see there. */
14748 SAVE_IT (it1
, it
, it1data
);
14749 start_y
= line_bottom_y (&it1
);
14751 RESTORE_IT (&it
, &it
, it1data
);
14752 move_it_by_lines (&it
, 1);
14753 SAVE_IT (it1
, it
, it1data
);
14754 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14757 /* If STARTP is unchanged, move it down another screen line. */
14758 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14759 move_it_by_lines (&it
, 1);
14760 startp
= it
.current
.pos
;
14764 struct text_pos scroll_margin_pos
= startp
;
14766 /* See if point is inside the scroll margin at the top of the
14768 if (this_scroll_margin
)
14770 start_display (&it
, w
, startp
);
14771 move_it_vertically (&it
, this_scroll_margin
);
14772 scroll_margin_pos
= it
.current
.pos
;
14775 if (PT
< CHARPOS (scroll_margin_pos
))
14777 /* Point is in the scroll margin at the top of the window or
14778 above what is displayed in the window. */
14781 /* Compute the vertical distance from PT to the scroll
14782 margin position. Move as far as scroll_max allows, or
14783 one screenful, or 10 screen lines, whichever is largest.
14784 Give up if distance is greater than scroll_max. */
14785 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14786 start_display (&it
, w
, pos
);
14788 y_to_move
= max (it
.last_visible_y
,
14789 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14790 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14792 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14793 dy
= it
.current_y
- y0
;
14794 if (dy
> scroll_max
)
14795 return SCROLLING_FAILED
;
14797 /* Compute new window start. */
14798 start_display (&it
, w
, startp
);
14800 if (arg_scroll_conservatively
)
14801 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14802 max (scroll_step
, temp_scroll_step
));
14803 else if (scroll_step
|| temp_scroll_step
)
14804 amount_to_scroll
= scroll_max
;
14807 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14808 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14809 if (NUMBERP (aggressive
))
14811 double float_amount
= XFLOATINT (aggressive
) * height
;
14812 amount_to_scroll
= float_amount
;
14813 if (amount_to_scroll
== 0 && float_amount
> 0)
14814 amount_to_scroll
= 1;
14815 amount_to_scroll
-=
14816 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14817 /* Don't let point enter the scroll margin near
14818 bottom of the window. */
14819 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14820 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14824 if (amount_to_scroll
<= 0)
14825 return SCROLLING_FAILED
;
14827 move_it_vertically_backward (&it
, amount_to_scroll
);
14828 startp
= it
.current
.pos
;
14832 /* Run window scroll functions. */
14833 startp
= run_window_scroll_functions (window
, startp
);
14835 /* Display the window. Give up if new fonts are loaded, or if point
14837 if (!try_window (window
, startp
, 0))
14838 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14839 else if (w
->cursor
.vpos
< 0)
14841 clear_glyph_matrix (w
->desired_matrix
);
14842 rc
= SCROLLING_FAILED
;
14846 /* Maybe forget recorded base line for line number display. */
14847 if (!just_this_one_p
14848 || current_buffer
->clip_changed
14849 || BEG_UNCHANGED
< CHARPOS (startp
))
14850 WVAR (w
, base_line_number
) = Qnil
;
14852 /* If cursor ends up on a partially visible line,
14853 treat that as being off the bottom of the screen. */
14854 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14855 /* It's possible that the cursor is on the first line of the
14856 buffer, which is partially obscured due to a vscroll
14857 (Bug#7537). In that case, avoid looping forever . */
14858 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14860 clear_glyph_matrix (w
->desired_matrix
);
14861 ++extra_scroll_margin_lines
;
14864 rc
= SCROLLING_SUCCESS
;
14871 /* Compute a suitable window start for window W if display of W starts
14872 on a continuation line. Value is non-zero if a new window start
14875 The new window start will be computed, based on W's width, starting
14876 from the start of the continued line. It is the start of the
14877 screen line with the minimum distance from the old start W->start. */
14880 compute_window_start_on_continuation_line (struct window
*w
)
14882 struct text_pos pos
, start_pos
;
14883 int window_start_changed_p
= 0;
14885 SET_TEXT_POS_FROM_MARKER (start_pos
, WVAR (w
, start
));
14887 /* If window start is on a continuation line... Window start may be
14888 < BEGV in case there's invisible text at the start of the
14889 buffer (M-x rmail, for example). */
14890 if (CHARPOS (start_pos
) > BEGV
14891 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14894 struct glyph_row
*row
;
14896 /* Handle the case that the window start is out of range. */
14897 if (CHARPOS (start_pos
) < BEGV
)
14898 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14899 else if (CHARPOS (start_pos
) > ZV
)
14900 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14902 /* Find the start of the continued line. This should be fast
14903 because scan_buffer is fast (newline cache). */
14904 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14905 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14906 row
, DEFAULT_FACE_ID
);
14907 reseat_at_previous_visible_line_start (&it
);
14909 /* If the line start is "too far" away from the window start,
14910 say it takes too much time to compute a new window start. */
14911 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14912 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14914 int min_distance
, distance
;
14916 /* Move forward by display lines to find the new window
14917 start. If window width was enlarged, the new start can
14918 be expected to be > the old start. If window width was
14919 decreased, the new window start will be < the old start.
14920 So, we're looking for the display line start with the
14921 minimum distance from the old window start. */
14922 pos
= it
.current
.pos
;
14923 min_distance
= INFINITY
;
14924 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14925 distance
< min_distance
)
14927 min_distance
= distance
;
14928 pos
= it
.current
.pos
;
14929 move_it_by_lines (&it
, 1);
14932 /* Set the window start there. */
14933 SET_MARKER_FROM_TEXT_POS (WVAR (w
, start
), pos
);
14934 window_start_changed_p
= 1;
14938 return window_start_changed_p
;
14942 /* Try cursor movement in case text has not changed in window WINDOW,
14943 with window start STARTP. Value is
14945 CURSOR_MOVEMENT_SUCCESS if successful
14947 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14949 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14950 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14951 we want to scroll as if scroll-step were set to 1. See the code.
14953 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14954 which case we have to abort this redisplay, and adjust matrices
14959 CURSOR_MOVEMENT_SUCCESS
,
14960 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14961 CURSOR_MOVEMENT_MUST_SCROLL
,
14962 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14966 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14968 struct window
*w
= XWINDOW (window
);
14969 struct frame
*f
= XFRAME (WVAR (w
, frame
));
14970 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14973 if (inhibit_try_cursor_movement
)
14977 /* Previously, there was a check for Lisp integer in the
14978 if-statement below. Now, this field is converted to
14979 ptrdiff_t, thus zero means invalid position in a buffer. */
14980 eassert (w
->last_point
> 0);
14982 /* Handle case where text has not changed, only point, and it has
14983 not moved off the frame. */
14984 if (/* Point may be in this window. */
14985 PT
>= CHARPOS (startp
)
14986 /* Selective display hasn't changed. */
14987 && !current_buffer
->clip_changed
14988 /* Function force-mode-line-update is used to force a thorough
14989 redisplay. It sets either windows_or_buffers_changed or
14990 update_mode_lines. So don't take a shortcut here for these
14992 && !update_mode_lines
14993 && !windows_or_buffers_changed
14994 && !cursor_type_changed
14995 /* Can't use this case if highlighting a region. When a
14996 region exists, cursor movement has to do more than just
14998 && !(!NILP (Vtransient_mark_mode
)
14999 && !NILP (BVAR (current_buffer
, mark_active
)))
15000 && NILP (WVAR (w
, region_showing
))
15001 && NILP (Vshow_trailing_whitespace
)
15002 /* This code is not used for mini-buffer for the sake of the case
15003 of redisplaying to replace an echo area message; since in
15004 that case the mini-buffer contents per se are usually
15005 unchanged. This code is of no real use in the mini-buffer
15006 since the handling of this_line_start_pos, etc., in redisplay
15007 handles the same cases. */
15008 && !EQ (window
, minibuf_window
)
15009 /* When splitting windows or for new windows, it happens that
15010 redisplay is called with a nil window_end_vpos or one being
15011 larger than the window. This should really be fixed in
15012 window.c. I don't have this on my list, now, so we do
15013 approximately the same as the old redisplay code. --gerd. */
15014 && INTEGERP (WVAR (w
, window_end_vpos
))
15015 && XFASTINT (WVAR (w
, window_end_vpos
)) < w
->current_matrix
->nrows
15016 && (FRAME_WINDOW_P (f
)
15017 || !overlay_arrow_in_current_buffer_p ()))
15019 int this_scroll_margin
, top_scroll_margin
;
15020 struct glyph_row
*row
= NULL
;
15023 debug_method_add (w
, "cursor movement");
15026 /* Scroll if point within this distance from the top or bottom
15027 of the window. This is a pixel value. */
15028 if (scroll_margin
> 0)
15030 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15031 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15034 this_scroll_margin
= 0;
15036 top_scroll_margin
= this_scroll_margin
;
15037 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15038 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15040 /* Start with the row the cursor was displayed during the last
15041 not paused redisplay. Give up if that row is not valid. */
15042 if (w
->last_cursor
.vpos
< 0
15043 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15044 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15047 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15048 if (row
->mode_line_p
)
15050 if (!row
->enabled_p
)
15051 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15054 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15056 int scroll_p
= 0, must_scroll
= 0;
15057 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15059 if (PT
> w
->last_point
)
15061 /* Point has moved forward. */
15062 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15063 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15065 eassert (row
->enabled_p
);
15069 /* If the end position of a row equals the start
15070 position of the next row, and PT is at that position,
15071 we would rather display cursor in the next line. */
15072 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15073 && MATRIX_ROW_END_CHARPOS (row
) == PT
15074 && row
< w
->current_matrix
->rows
15075 + w
->current_matrix
->nrows
- 1
15076 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15077 && !cursor_row_p (row
))
15080 /* If within the scroll margin, scroll. Note that
15081 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15082 the next line would be drawn, and that
15083 this_scroll_margin can be zero. */
15084 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15085 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15086 /* Line is completely visible last line in window
15087 and PT is to be set in the next line. */
15088 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15089 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15090 && !row
->ends_at_zv_p
15091 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15094 else if (PT
< w
->last_point
)
15096 /* Cursor has to be moved backward. Note that PT >=
15097 CHARPOS (startp) because of the outer if-statement. */
15098 while (!row
->mode_line_p
15099 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15100 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15101 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15102 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15103 row
> w
->current_matrix
->rows
15104 && (row
-1)->ends_in_newline_from_string_p
))))
15105 && (row
->y
> top_scroll_margin
15106 || CHARPOS (startp
) == BEGV
))
15108 eassert (row
->enabled_p
);
15112 /* Consider the following case: Window starts at BEGV,
15113 there is invisible, intangible text at BEGV, so that
15114 display starts at some point START > BEGV. It can
15115 happen that we are called with PT somewhere between
15116 BEGV and START. Try to handle that case. */
15117 if (row
< w
->current_matrix
->rows
15118 || row
->mode_line_p
)
15120 row
= w
->current_matrix
->rows
;
15121 if (row
->mode_line_p
)
15125 /* Due to newlines in overlay strings, we may have to
15126 skip forward over overlay strings. */
15127 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15128 && MATRIX_ROW_END_CHARPOS (row
) == PT
15129 && !cursor_row_p (row
))
15132 /* If within the scroll margin, scroll. */
15133 if (row
->y
< top_scroll_margin
15134 && CHARPOS (startp
) != BEGV
)
15139 /* Cursor did not move. So don't scroll even if cursor line
15140 is partially visible, as it was so before. */
15141 rc
= CURSOR_MOVEMENT_SUCCESS
;
15144 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15145 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15147 /* if PT is not in the glyph row, give up. */
15148 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15151 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15152 && !NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_display_reordering
)))
15154 struct glyph_row
*row1
;
15156 /* If rows are bidi-reordered and point moved, back up
15157 until we find a row that does not belong to a
15158 continuation line. This is because we must consider
15159 all rows of a continued line as candidates for the
15160 new cursor positioning, since row start and end
15161 positions change non-linearly with vertical position
15163 /* FIXME: Revisit this when glyph ``spilling'' in
15164 continuation lines' rows is implemented for
15165 bidi-reordered rows. */
15166 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15167 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15170 /* If we hit the beginning of the displayed portion
15171 without finding the first row of a continued
15175 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15178 eassert (row
->enabled_p
);
15183 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15184 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15185 /* Make sure this isn't a header line by any chance, since
15186 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15187 && !row
->mode_line_p
15188 && make_cursor_line_fully_visible_p
)
15190 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15191 && !row
->ends_at_zv_p
15192 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15193 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15194 else if (row
->height
> window_box_height (w
))
15196 /* If we end up in a partially visible line, let's
15197 make it fully visible, except when it's taller
15198 than the window, in which case we can't do much
15201 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15205 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15206 if (!cursor_row_fully_visible_p (w
, 0, 1))
15207 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15209 rc
= CURSOR_MOVEMENT_SUCCESS
;
15213 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15214 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15215 && !NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_display_reordering
)))
15217 /* With bidi-reordered rows, there could be more than
15218 one candidate row whose start and end positions
15219 occlude point. We need to let set_cursor_from_row
15220 find the best candidate. */
15221 /* FIXME: Revisit this when glyph ``spilling'' in
15222 continuation lines' rows is implemented for
15223 bidi-reordered rows. */
15228 int at_zv_p
= 0, exact_match_p
= 0;
15230 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15231 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15232 && cursor_row_p (row
))
15233 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15235 /* As soon as we've found the exact match for point,
15236 or the first suitable row whose ends_at_zv_p flag
15237 is set, we are done. */
15239 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15241 && w
->cursor
.hpos
>= 0
15242 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15245 struct glyph_row
*candidate
=
15246 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15248 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15249 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15252 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15253 || (INTEGERP (g
->object
)
15254 && (g
->charpos
== PT
15255 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15257 if (rv
&& (at_zv_p
|| exact_match_p
))
15259 rc
= CURSOR_MOVEMENT_SUCCESS
;
15262 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15266 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15267 || row
->continued_p
)
15268 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15269 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15270 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15271 /* If we didn't find any candidate rows, or exited the
15272 loop before all the candidates were examined, signal
15273 to the caller that this method failed. */
15274 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15276 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15277 && !row
->continued_p
))
15278 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15280 rc
= CURSOR_MOVEMENT_SUCCESS
;
15286 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15288 rc
= CURSOR_MOVEMENT_SUCCESS
;
15293 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15294 && MATRIX_ROW_START_CHARPOS (row
) == PT
15295 && cursor_row_p (row
));
15303 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15307 set_vertical_scroll_bar (struct window
*w
)
15309 ptrdiff_t start
, end
, whole
;
15311 /* Calculate the start and end positions for the current window.
15312 At some point, it would be nice to choose between scrollbars
15313 which reflect the whole buffer size, with special markers
15314 indicating narrowing, and scrollbars which reflect only the
15317 Note that mini-buffers sometimes aren't displaying any text. */
15318 if (!MINI_WINDOW_P (w
)
15319 || (w
== XWINDOW (minibuf_window
)
15320 && NILP (echo_area_buffer
[0])))
15322 struct buffer
*buf
= XBUFFER (WVAR (w
, buffer
));
15323 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15324 start
= marker_position (WVAR (w
, start
)) - BUF_BEGV (buf
);
15325 /* I don't think this is guaranteed to be right. For the
15326 moment, we'll pretend it is. */
15327 end
= BUF_Z (buf
) - XFASTINT (WVAR (w
, window_end_pos
)) - BUF_BEGV (buf
);
15331 if (whole
< (end
- start
))
15332 whole
= end
- start
;
15335 start
= end
= whole
= 0;
15337 /* Indicate what this scroll bar ought to be displaying now. */
15338 if (FRAME_TERMINAL (XFRAME (WVAR (w
, frame
)))->set_vertical_scroll_bar_hook
)
15339 (*FRAME_TERMINAL (XFRAME (WVAR (w
, frame
)))->set_vertical_scroll_bar_hook
)
15340 (w
, end
- start
, whole
, start
);
15344 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15345 selected_window is redisplayed.
15347 We can return without actually redisplaying the window if
15348 fonts_changed_p is nonzero. In that case, redisplay_internal will
15352 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15354 struct window
*w
= XWINDOW (window
);
15355 struct frame
*f
= XFRAME (WVAR (w
, frame
));
15356 struct buffer
*buffer
= XBUFFER (WVAR (w
, buffer
));
15357 struct buffer
*old
= current_buffer
;
15358 struct text_pos lpoint
, opoint
, startp
;
15359 int update_mode_line
;
15362 /* Record it now because it's overwritten. */
15363 int current_matrix_up_to_date_p
= 0;
15364 int used_current_matrix_p
= 0;
15365 /* This is less strict than current_matrix_up_to_date_p.
15366 It indicates that the buffer contents and narrowing are unchanged. */
15367 int buffer_unchanged_p
= 0;
15368 int temp_scroll_step
= 0;
15369 ptrdiff_t count
= SPECPDL_INDEX ();
15371 int centering_position
= -1;
15372 int last_line_misfit
= 0;
15373 ptrdiff_t beg_unchanged
, end_unchanged
;
15375 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15378 /* W must be a leaf window here. */
15379 eassert (!NILP (WVAR (w
, buffer
)));
15381 *w
->desired_matrix
->method
= 0;
15385 reconsider_clip_changes (w
, buffer
);
15387 /* Has the mode line to be updated? */
15388 update_mode_line
= (w
->update_mode_line
15389 || update_mode_lines
15390 || buffer
->clip_changed
15391 || buffer
->prevent_redisplay_optimizations_p
);
15393 if (MINI_WINDOW_P (w
))
15395 if (w
== XWINDOW (echo_area_window
)
15396 && !NILP (echo_area_buffer
[0]))
15398 if (update_mode_line
)
15399 /* We may have to update a tty frame's menu bar or a
15400 tool-bar. Example `M-x C-h C-h C-g'. */
15401 goto finish_menu_bars
;
15403 /* We've already displayed the echo area glyphs in this window. */
15404 goto finish_scroll_bars
;
15406 else if ((w
!= XWINDOW (minibuf_window
)
15407 || minibuf_level
== 0)
15408 /* When buffer is nonempty, redisplay window normally. */
15409 && BUF_Z (XBUFFER (WVAR (w
, buffer
))) == BUF_BEG (XBUFFER (WVAR (w
, buffer
)))
15410 /* Quail displays non-mini buffers in minibuffer window.
15411 In that case, redisplay the window normally. */
15412 && !NILP (Fmemq (WVAR (w
, buffer
), Vminibuffer_list
)))
15414 /* W is a mini-buffer window, but it's not active, so clear
15416 int yb
= window_text_bottom_y (w
);
15417 struct glyph_row
*row
;
15420 for (y
= 0, row
= w
->desired_matrix
->rows
;
15422 y
+= row
->height
, ++row
)
15423 blank_row (w
, row
, y
);
15424 goto finish_scroll_bars
;
15427 clear_glyph_matrix (w
->desired_matrix
);
15430 /* Otherwise set up data on this window; select its buffer and point
15432 /* Really select the buffer, for the sake of buffer-local
15434 set_buffer_internal_1 (XBUFFER (WVAR (w
, buffer
)));
15436 current_matrix_up_to_date_p
15437 = (!NILP (WVAR (w
, window_end_valid
))
15438 && !current_buffer
->clip_changed
15439 && !current_buffer
->prevent_redisplay_optimizations_p
15440 && w
->last_modified
>= MODIFF
15441 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15443 /* Run the window-bottom-change-functions
15444 if it is possible that the text on the screen has changed
15445 (either due to modification of the text, or any other reason). */
15446 if (!current_matrix_up_to_date_p
15447 && !NILP (Vwindow_text_change_functions
))
15449 safe_run_hooks (Qwindow_text_change_functions
);
15453 beg_unchanged
= BEG_UNCHANGED
;
15454 end_unchanged
= END_UNCHANGED
;
15456 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15458 specbind (Qinhibit_point_motion_hooks
, Qt
);
15461 = (!NILP (WVAR (w
, window_end_valid
))
15462 && !current_buffer
->clip_changed
15463 && w
->last_modified
>= MODIFF
15464 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15466 /* When windows_or_buffers_changed is non-zero, we can't rely on
15467 the window end being valid, so set it to nil there. */
15468 if (windows_or_buffers_changed
)
15470 /* If window starts on a continuation line, maybe adjust the
15471 window start in case the window's width changed. */
15472 if (XMARKER (WVAR (w
, start
))->buffer
== current_buffer
)
15473 compute_window_start_on_continuation_line (w
);
15475 WVAR (w
, window_end_valid
) = Qnil
;
15478 /* Some sanity checks. */
15479 CHECK_WINDOW_END (w
);
15480 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15482 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15485 /* If %c is in mode line, update it if needed. */
15486 if (!NILP (WVAR (w
, column_number_displayed
))
15487 /* This alternative quickly identifies a common case
15488 where no change is needed. */
15489 && !(PT
== w
->last_point
15490 && w
->last_modified
>= MODIFF
15491 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
15492 && (XFASTINT (WVAR (w
, column_number_displayed
)) != current_column ()))
15493 update_mode_line
= 1;
15495 /* Count number of windows showing the selected buffer. An indirect
15496 buffer counts as its base buffer. */
15497 if (!just_this_one_p
)
15499 struct buffer
*current_base
, *window_base
;
15500 current_base
= current_buffer
;
15501 window_base
= XBUFFER (WVAR (XWINDOW (selected_window
), buffer
));
15502 if (current_base
->base_buffer
)
15503 current_base
= current_base
->base_buffer
;
15504 if (window_base
->base_buffer
)
15505 window_base
= window_base
->base_buffer
;
15506 if (current_base
== window_base
)
15510 /* Point refers normally to the selected window. For any other
15511 window, set up appropriate value. */
15512 if (!EQ (window
, selected_window
))
15514 ptrdiff_t new_pt
= XMARKER (WVAR (w
, pointm
))->charpos
;
15515 ptrdiff_t new_pt_byte
= marker_byte_position (WVAR (w
, pointm
));
15519 new_pt_byte
= BEGV_BYTE
;
15520 set_marker_both (WVAR (w
, pointm
), Qnil
, BEGV
, BEGV_BYTE
);
15522 else if (new_pt
> (ZV
- 1))
15525 new_pt_byte
= ZV_BYTE
;
15526 set_marker_both (WVAR (w
, pointm
), Qnil
, ZV
, ZV_BYTE
);
15529 /* We don't use SET_PT so that the point-motion hooks don't run. */
15530 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15533 /* If any of the character widths specified in the display table
15534 have changed, invalidate the width run cache. It's true that
15535 this may be a bit late to catch such changes, but the rest of
15536 redisplay goes (non-fatally) haywire when the display table is
15537 changed, so why should we worry about doing any better? */
15538 if (current_buffer
->width_run_cache
)
15540 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15542 if (! disptab_matches_widthtab
15543 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15545 invalidate_region_cache (current_buffer
,
15546 current_buffer
->width_run_cache
,
15548 recompute_width_table (current_buffer
, disptab
);
15552 /* If window-start is screwed up, choose a new one. */
15553 if (XMARKER (WVAR (w
, start
))->buffer
!= current_buffer
)
15556 SET_TEXT_POS_FROM_MARKER (startp
, WVAR (w
, start
));
15558 /* If someone specified a new starting point but did not insist,
15559 check whether it can be used. */
15560 if (w
->optional_new_start
15561 && CHARPOS (startp
) >= BEGV
15562 && CHARPOS (startp
) <= ZV
)
15564 w
->optional_new_start
= 0;
15565 start_display (&it
, w
, startp
);
15566 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15567 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15568 if (IT_CHARPOS (it
) == PT
)
15569 w
->force_start
= 1;
15570 /* IT may overshoot PT if text at PT is invisible. */
15571 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15572 w
->force_start
= 1;
15577 /* Handle case where place to start displaying has been specified,
15578 unless the specified location is outside the accessible range. */
15579 if (w
->force_start
|| w
->frozen_window_start_p
)
15581 /* We set this later on if we have to adjust point. */
15584 w
->force_start
= 0;
15586 WVAR (w
, window_end_valid
) = Qnil
;
15588 /* Forget any recorded base line for line number display. */
15589 if (!buffer_unchanged_p
)
15590 WVAR (w
, base_line_number
) = Qnil
;
15592 /* Redisplay the mode line. Select the buffer properly for that.
15593 Also, run the hook window-scroll-functions
15594 because we have scrolled. */
15595 /* Note, we do this after clearing force_start because
15596 if there's an error, it is better to forget about force_start
15597 than to get into an infinite loop calling the hook functions
15598 and having them get more errors. */
15599 if (!update_mode_line
15600 || ! NILP (Vwindow_scroll_functions
))
15602 update_mode_line
= 1;
15603 w
->update_mode_line
= 1;
15604 startp
= run_window_scroll_functions (window
, startp
);
15607 w
->last_modified
= 0;
15608 w
->last_overlay_modified
= 0;
15609 if (CHARPOS (startp
) < BEGV
)
15610 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15611 else if (CHARPOS (startp
) > ZV
)
15612 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15614 /* Redisplay, then check if cursor has been set during the
15615 redisplay. Give up if new fonts were loaded. */
15616 /* We used to issue a CHECK_MARGINS argument to try_window here,
15617 but this causes scrolling to fail when point begins inside
15618 the scroll margin (bug#148) -- cyd */
15619 if (!try_window (window
, startp
, 0))
15621 w
->force_start
= 1;
15622 clear_glyph_matrix (w
->desired_matrix
);
15623 goto need_larger_matrices
;
15626 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15628 /* If point does not appear, try to move point so it does
15629 appear. The desired matrix has been built above, so we
15630 can use it here. */
15631 new_vpos
= window_box_height (w
) / 2;
15634 if (!cursor_row_fully_visible_p (w
, 0, 0))
15636 /* Point does appear, but on a line partly visible at end of window.
15637 Move it back to a fully-visible line. */
15638 new_vpos
= window_box_height (w
);
15641 /* If we need to move point for either of the above reasons,
15642 now actually do it. */
15645 struct glyph_row
*row
;
15647 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15648 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15651 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15652 MATRIX_ROW_START_BYTEPOS (row
));
15654 if (w
!= XWINDOW (selected_window
))
15655 set_marker_both (WVAR (w
, pointm
), Qnil
, PT
, PT_BYTE
);
15656 else if (current_buffer
== old
)
15657 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15659 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15661 /* If we are highlighting the region, then we just changed
15662 the region, so redisplay to show it. */
15663 if (!NILP (Vtransient_mark_mode
)
15664 && !NILP (BVAR (current_buffer
, mark_active
)))
15666 clear_glyph_matrix (w
->desired_matrix
);
15667 if (!try_window (window
, startp
, 0))
15668 goto need_larger_matrices
;
15673 debug_method_add (w
, "forced window start");
15678 /* Handle case where text has not changed, only point, and it has
15679 not moved off the frame, and we are not retrying after hscroll.
15680 (current_matrix_up_to_date_p is nonzero when retrying.) */
15681 if (current_matrix_up_to_date_p
15682 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15683 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15687 case CURSOR_MOVEMENT_SUCCESS
:
15688 used_current_matrix_p
= 1;
15691 case CURSOR_MOVEMENT_MUST_SCROLL
:
15692 goto try_to_scroll
;
15698 /* If current starting point was originally the beginning of a line
15699 but no longer is, find a new starting point. */
15700 else if (w
->start_at_line_beg
15701 && !(CHARPOS (startp
) <= BEGV
15702 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15705 debug_method_add (w
, "recenter 1");
15710 /* Try scrolling with try_window_id. Value is > 0 if update has
15711 been done, it is -1 if we know that the same window start will
15712 not work. It is 0 if unsuccessful for some other reason. */
15713 else if ((tem
= try_window_id (w
)) != 0)
15716 debug_method_add (w
, "try_window_id %d", tem
);
15719 if (fonts_changed_p
)
15720 goto need_larger_matrices
;
15724 /* Otherwise try_window_id has returned -1 which means that we
15725 don't want the alternative below this comment to execute. */
15727 else if (CHARPOS (startp
) >= BEGV
15728 && CHARPOS (startp
) <= ZV
15729 && PT
>= CHARPOS (startp
)
15730 && (CHARPOS (startp
) < ZV
15731 /* Avoid starting at end of buffer. */
15732 || CHARPOS (startp
) == BEGV
15733 || (w
->last_modified
>= MODIFF
15734 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)))
15736 int d1
, d2
, d3
, d4
, d5
, d6
;
15738 /* If first window line is a continuation line, and window start
15739 is inside the modified region, but the first change is before
15740 current window start, we must select a new window start.
15742 However, if this is the result of a down-mouse event (e.g. by
15743 extending the mouse-drag-overlay), we don't want to select a
15744 new window start, since that would change the position under
15745 the mouse, resulting in an unwanted mouse-movement rather
15746 than a simple mouse-click. */
15747 if (!w
->start_at_line_beg
15748 && NILP (do_mouse_tracking
)
15749 && CHARPOS (startp
) > BEGV
15750 && CHARPOS (startp
) > BEG
+ beg_unchanged
15751 && CHARPOS (startp
) <= Z
- end_unchanged
15752 /* Even if w->start_at_line_beg is nil, a new window may
15753 start at a line_beg, since that's how set_buffer_window
15754 sets it. So, we need to check the return value of
15755 compute_window_start_on_continuation_line. (See also
15757 && XMARKER (WVAR (w
, start
))->buffer
== current_buffer
15758 && compute_window_start_on_continuation_line (w
)
15759 /* It doesn't make sense to force the window start like we
15760 do at label force_start if it is already known that point
15761 will not be visible in the resulting window, because
15762 doing so will move point from its correct position
15763 instead of scrolling the window to bring point into view.
15765 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15767 w
->force_start
= 1;
15768 SET_TEXT_POS_FROM_MARKER (startp
, WVAR (w
, start
));
15773 debug_method_add (w
, "same window start");
15776 /* Try to redisplay starting at same place as before.
15777 If point has not moved off frame, accept the results. */
15778 if (!current_matrix_up_to_date_p
15779 /* Don't use try_window_reusing_current_matrix in this case
15780 because a window scroll function can have changed the
15782 || !NILP (Vwindow_scroll_functions
)
15783 || MINI_WINDOW_P (w
)
15784 || !(used_current_matrix_p
15785 = try_window_reusing_current_matrix (w
)))
15787 IF_DEBUG (debug_method_add (w
, "1"));
15788 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15789 /* -1 means we need to scroll.
15790 0 means we need new matrices, but fonts_changed_p
15791 is set in that case, so we will detect it below. */
15792 goto try_to_scroll
;
15795 if (fonts_changed_p
)
15796 goto need_larger_matrices
;
15798 if (w
->cursor
.vpos
>= 0)
15800 if (!just_this_one_p
15801 || current_buffer
->clip_changed
15802 || BEG_UNCHANGED
< CHARPOS (startp
))
15803 /* Forget any recorded base line for line number display. */
15804 WVAR (w
, base_line_number
) = Qnil
;
15806 if (!cursor_row_fully_visible_p (w
, 1, 0))
15808 clear_glyph_matrix (w
->desired_matrix
);
15809 last_line_misfit
= 1;
15811 /* Drop through and scroll. */
15816 clear_glyph_matrix (w
->desired_matrix
);
15821 w
->last_modified
= 0;
15822 w
->last_overlay_modified
= 0;
15824 /* Redisplay the mode line. Select the buffer properly for that. */
15825 if (!update_mode_line
)
15827 update_mode_line
= 1;
15828 w
->update_mode_line
= 1;
15831 /* Try to scroll by specified few lines. */
15832 if ((scroll_conservatively
15833 || emacs_scroll_step
15834 || temp_scroll_step
15835 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15836 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15837 && CHARPOS (startp
) >= BEGV
15838 && CHARPOS (startp
) <= ZV
)
15840 /* The function returns -1 if new fonts were loaded, 1 if
15841 successful, 0 if not successful. */
15842 int ss
= try_scrolling (window
, just_this_one_p
,
15843 scroll_conservatively
,
15845 temp_scroll_step
, last_line_misfit
);
15848 case SCROLLING_SUCCESS
:
15851 case SCROLLING_NEED_LARGER_MATRICES
:
15852 goto need_larger_matrices
;
15854 case SCROLLING_FAILED
:
15862 /* Finally, just choose a place to start which positions point
15863 according to user preferences. */
15868 debug_method_add (w
, "recenter");
15871 /* w->vscroll = 0; */
15873 /* Forget any previously recorded base line for line number display. */
15874 if (!buffer_unchanged_p
)
15875 WVAR (w
, base_line_number
) = Qnil
;
15877 /* Determine the window start relative to point. */
15878 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15879 it
.current_y
= it
.last_visible_y
;
15880 if (centering_position
< 0)
15884 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15886 ptrdiff_t margin_pos
= CHARPOS (startp
);
15887 Lisp_Object aggressive
;
15890 /* If there is a scroll margin at the top of the window, find
15891 its character position. */
15893 /* Cannot call start_display if startp is not in the
15894 accessible region of the buffer. This can happen when we
15895 have just switched to a different buffer and/or changed
15896 its restriction. In that case, startp is initialized to
15897 the character position 1 (BEGV) because we did not yet
15898 have chance to display the buffer even once. */
15899 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15902 void *it1data
= NULL
;
15904 SAVE_IT (it1
, it
, it1data
);
15905 start_display (&it1
, w
, startp
);
15906 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15907 margin_pos
= IT_CHARPOS (it1
);
15908 RESTORE_IT (&it
, &it
, it1data
);
15910 scrolling_up
= PT
> margin_pos
;
15913 ? BVAR (current_buffer
, scroll_up_aggressively
)
15914 : BVAR (current_buffer
, scroll_down_aggressively
);
15916 if (!MINI_WINDOW_P (w
)
15917 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15921 /* Setting scroll-conservatively overrides
15922 scroll-*-aggressively. */
15923 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15925 double float_amount
= XFLOATINT (aggressive
);
15927 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15928 if (pt_offset
== 0 && float_amount
> 0)
15930 if (pt_offset
&& margin
> 0)
15933 /* Compute how much to move the window start backward from
15934 point so that point will be displayed where the user
15938 centering_position
= it
.last_visible_y
;
15940 centering_position
-= pt_offset
;
15941 centering_position
-=
15942 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15943 + WINDOW_HEADER_LINE_HEIGHT (w
);
15944 /* Don't let point enter the scroll margin near top of
15946 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15947 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15950 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15953 /* Set the window start half the height of the window backward
15955 centering_position
= window_box_height (w
) / 2;
15957 move_it_vertically_backward (&it
, centering_position
);
15959 eassert (IT_CHARPOS (it
) >= BEGV
);
15961 /* The function move_it_vertically_backward may move over more
15962 than the specified y-distance. If it->w is small, e.g. a
15963 mini-buffer window, we may end up in front of the window's
15964 display area. Start displaying at the start of the line
15965 containing PT in this case. */
15966 if (it
.current_y
<= 0)
15968 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15969 move_it_vertically_backward (&it
, 0);
15973 it
.current_x
= it
.hpos
= 0;
15975 /* Set the window start position here explicitly, to avoid an
15976 infinite loop in case the functions in window-scroll-functions
15978 set_marker_both (WVAR (w
, start
), Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15980 /* Run scroll hooks. */
15981 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15983 /* Redisplay the window. */
15984 if (!current_matrix_up_to_date_p
15985 || windows_or_buffers_changed
15986 || cursor_type_changed
15987 /* Don't use try_window_reusing_current_matrix in this case
15988 because it can have changed the buffer. */
15989 || !NILP (Vwindow_scroll_functions
)
15990 || !just_this_one_p
15991 || MINI_WINDOW_P (w
)
15992 || !(used_current_matrix_p
15993 = try_window_reusing_current_matrix (w
)))
15994 try_window (window
, startp
, 0);
15996 /* If new fonts have been loaded (due to fontsets), give up. We
15997 have to start a new redisplay since we need to re-adjust glyph
15999 if (fonts_changed_p
)
16000 goto need_larger_matrices
;
16002 /* If cursor did not appear assume that the middle of the window is
16003 in the first line of the window. Do it again with the next line.
16004 (Imagine a window of height 100, displaying two lines of height
16005 60. Moving back 50 from it->last_visible_y will end in the first
16007 if (w
->cursor
.vpos
< 0)
16009 if (!NILP (WVAR (w
, window_end_valid
))
16010 && PT
>= Z
- XFASTINT (WVAR (w
, window_end_pos
)))
16012 clear_glyph_matrix (w
->desired_matrix
);
16013 move_it_by_lines (&it
, 1);
16014 try_window (window
, it
.current
.pos
, 0);
16016 else if (PT
< IT_CHARPOS (it
))
16018 clear_glyph_matrix (w
->desired_matrix
);
16019 move_it_by_lines (&it
, -1);
16020 try_window (window
, it
.current
.pos
, 0);
16024 /* Not much we can do about it. */
16028 /* Consider the following case: Window starts at BEGV, there is
16029 invisible, intangible text at BEGV, so that display starts at
16030 some point START > BEGV. It can happen that we are called with
16031 PT somewhere between BEGV and START. Try to handle that case. */
16032 if (w
->cursor
.vpos
< 0)
16034 struct glyph_row
*row
= w
->current_matrix
->rows
;
16035 if (row
->mode_line_p
)
16037 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16040 if (!cursor_row_fully_visible_p (w
, 0, 0))
16042 /* If vscroll is enabled, disable it and try again. */
16046 clear_glyph_matrix (w
->desired_matrix
);
16050 /* Users who set scroll-conservatively to a large number want
16051 point just above/below the scroll margin. If we ended up
16052 with point's row partially visible, move the window start to
16053 make that row fully visible and out of the margin. */
16054 if (scroll_conservatively
> SCROLL_LIMIT
)
16058 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16060 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16062 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16063 clear_glyph_matrix (w
->desired_matrix
);
16064 if (1 == try_window (window
, it
.current
.pos
,
16065 TRY_WINDOW_CHECK_MARGINS
))
16069 /* If centering point failed to make the whole line visible,
16070 put point at the top instead. That has to make the whole line
16071 visible, if it can be done. */
16072 if (centering_position
== 0)
16075 clear_glyph_matrix (w
->desired_matrix
);
16076 centering_position
= 0;
16082 SET_TEXT_POS_FROM_MARKER (startp
, WVAR (w
, start
));
16083 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16084 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16086 /* Display the mode line, if we must. */
16087 if ((update_mode_line
16088 /* If window not full width, must redo its mode line
16089 if (a) the window to its side is being redone and
16090 (b) we do a frame-based redisplay. This is a consequence
16091 of how inverted lines are drawn in frame-based redisplay. */
16092 || (!just_this_one_p
16093 && !FRAME_WINDOW_P (f
)
16094 && !WINDOW_FULL_WIDTH_P (w
))
16095 /* Line number to display. */
16096 || INTEGERP (WVAR (w
, base_line_pos
))
16097 /* Column number is displayed and different from the one displayed. */
16098 || (!NILP (WVAR (w
, column_number_displayed
))
16099 && (XFASTINT (WVAR (w
, column_number_displayed
)) != current_column ())))
16100 /* This means that the window has a mode line. */
16101 && (WINDOW_WANTS_MODELINE_P (w
)
16102 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16104 display_mode_lines (w
);
16106 /* If mode line height has changed, arrange for a thorough
16107 immediate redisplay using the correct mode line height. */
16108 if (WINDOW_WANTS_MODELINE_P (w
)
16109 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16111 fonts_changed_p
= 1;
16112 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16113 = DESIRED_MODE_LINE_HEIGHT (w
);
16116 /* If header line height has changed, arrange for a thorough
16117 immediate redisplay using the correct header line height. */
16118 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16119 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16121 fonts_changed_p
= 1;
16122 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16123 = DESIRED_HEADER_LINE_HEIGHT (w
);
16126 if (fonts_changed_p
)
16127 goto need_larger_matrices
;
16130 if (!line_number_displayed
16131 && !BUFFERP (WVAR (w
, base_line_pos
)))
16133 WVAR (w
, base_line_pos
) = Qnil
;
16134 WVAR (w
, base_line_number
) = Qnil
;
16139 /* When we reach a frame's selected window, redo the frame's menu bar. */
16140 if (update_mode_line
16141 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16143 int redisplay_menu_p
= 0;
16145 if (FRAME_WINDOW_P (f
))
16147 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16148 || defined (HAVE_NS) || defined (USE_GTK)
16149 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16151 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16155 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16157 if (redisplay_menu_p
)
16158 display_menu_bar (w
);
16160 #ifdef HAVE_WINDOW_SYSTEM
16161 if (FRAME_WINDOW_P (f
))
16163 #if defined (USE_GTK) || defined (HAVE_NS)
16164 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16165 redisplay_tool_bar (f
);
16167 if (WINDOWP (FVAR (f
, tool_bar_window
))
16168 && (FRAME_TOOL_BAR_LINES (f
) > 0
16169 || !NILP (Vauto_resize_tool_bars
))
16170 && redisplay_tool_bar (f
))
16171 ignore_mouse_drag_p
= 1;
16177 #ifdef HAVE_WINDOW_SYSTEM
16178 if (FRAME_WINDOW_P (f
)
16179 && update_window_fringes (w
, (just_this_one_p
16180 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16181 || w
->pseudo_window_p
)))
16185 if (draw_window_fringes (w
, 1))
16186 x_draw_vertical_border (w
);
16190 #endif /* HAVE_WINDOW_SYSTEM */
16192 /* We go to this label, with fonts_changed_p nonzero,
16193 if it is necessary to try again using larger glyph matrices.
16194 We have to redeem the scroll bar even in this case,
16195 because the loop in redisplay_internal expects that. */
16196 need_larger_matrices
:
16198 finish_scroll_bars
:
16200 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16202 /* Set the thumb's position and size. */
16203 set_vertical_scroll_bar (w
);
16205 /* Note that we actually used the scroll bar attached to this
16206 window, so it shouldn't be deleted at the end of redisplay. */
16207 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16208 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16211 /* Restore current_buffer and value of point in it. The window
16212 update may have changed the buffer, so first make sure `opoint'
16213 is still valid (Bug#6177). */
16214 if (CHARPOS (opoint
) < BEGV
)
16215 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16216 else if (CHARPOS (opoint
) > ZV
)
16217 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16219 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16221 set_buffer_internal_1 (old
);
16222 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16223 shorter. This can be caused by log truncation in *Messages*. */
16224 if (CHARPOS (lpoint
) <= ZV
)
16225 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16227 unbind_to (count
, Qnil
);
16231 /* Build the complete desired matrix of WINDOW with a window start
16232 buffer position POS.
16234 Value is 1 if successful. It is zero if fonts were loaded during
16235 redisplay which makes re-adjusting glyph matrices necessary, and -1
16236 if point would appear in the scroll margins.
16237 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16238 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16242 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16244 struct window
*w
= XWINDOW (window
);
16246 struct glyph_row
*last_text_row
= NULL
;
16247 struct frame
*f
= XFRAME (WVAR (w
, frame
));
16249 /* Make POS the new window start. */
16250 set_marker_both (WVAR (w
, start
), Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16252 /* Mark cursor position as unknown. No overlay arrow seen. */
16253 w
->cursor
.vpos
= -1;
16254 overlay_arrow_seen
= 0;
16256 /* Initialize iterator and info to start at POS. */
16257 start_display (&it
, w
, pos
);
16259 /* Display all lines of W. */
16260 while (it
.current_y
< it
.last_visible_y
)
16262 if (display_line (&it
))
16263 last_text_row
= it
.glyph_row
- 1;
16264 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16268 /* Don't let the cursor end in the scroll margins. */
16269 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16270 && !MINI_WINDOW_P (w
))
16272 int this_scroll_margin
;
16274 if (scroll_margin
> 0)
16276 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16277 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16280 this_scroll_margin
= 0;
16282 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16283 && w
->cursor
.y
< this_scroll_margin
16284 && CHARPOS (pos
) > BEGV
16285 && IT_CHARPOS (it
) < ZV
)
16286 /* rms: considering make_cursor_line_fully_visible_p here
16287 seems to give wrong results. We don't want to recenter
16288 when the last line is partly visible, we want to allow
16289 that case to be handled in the usual way. */
16290 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16292 w
->cursor
.vpos
= -1;
16293 clear_glyph_matrix (w
->desired_matrix
);
16298 /* If bottom moved off end of frame, change mode line percentage. */
16299 if (XFASTINT (WVAR (w
, window_end_pos
)) <= 0
16300 && Z
!= IT_CHARPOS (it
))
16301 w
->update_mode_line
= 1;
16303 /* Set window_end_pos to the offset of the last character displayed
16304 on the window from the end of current_buffer. Set
16305 window_end_vpos to its row number. */
16308 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16309 w
->window_end_bytepos
16310 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16311 WVAR (w
, window_end_pos
)
16312 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16313 WVAR (w
, window_end_vpos
)
16314 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16316 (MATRIX_ROW (w
->desired_matrix
,
16317 XFASTINT (WVAR (w
, window_end_vpos
)))->displays_text_p
);
16321 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16322 WVAR (w
, window_end_pos
) = make_number (Z
- ZV
);
16323 WVAR (w
, window_end_vpos
) = make_number (0);
16326 /* But that is not valid info until redisplay finishes. */
16327 WVAR (w
, window_end_valid
) = Qnil
;
16333 /************************************************************************
16334 Window redisplay reusing current matrix when buffer has not changed
16335 ************************************************************************/
16337 /* Try redisplay of window W showing an unchanged buffer with a
16338 different window start than the last time it was displayed by
16339 reusing its current matrix. Value is non-zero if successful.
16340 W->start is the new window start. */
16343 try_window_reusing_current_matrix (struct window
*w
)
16345 struct frame
*f
= XFRAME (WVAR (w
, frame
));
16346 struct glyph_row
*bottom_row
;
16349 struct text_pos start
, new_start
;
16350 int nrows_scrolled
, i
;
16351 struct glyph_row
*last_text_row
;
16352 struct glyph_row
*last_reused_text_row
;
16353 struct glyph_row
*start_row
;
16354 int start_vpos
, min_y
, max_y
;
16357 if (inhibit_try_window_reusing
)
16361 if (/* This function doesn't handle terminal frames. */
16362 !FRAME_WINDOW_P (f
)
16363 /* Don't try to reuse the display if windows have been split
16365 || windows_or_buffers_changed
16366 || cursor_type_changed
)
16369 /* Can't do this if region may have changed. */
16370 if ((!NILP (Vtransient_mark_mode
)
16371 && !NILP (BVAR (current_buffer
, mark_active
)))
16372 || !NILP (WVAR (w
, region_showing
))
16373 || !NILP (Vshow_trailing_whitespace
))
16376 /* If top-line visibility has changed, give up. */
16377 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16378 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16381 /* Give up if old or new display is scrolled vertically. We could
16382 make this function handle this, but right now it doesn't. */
16383 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16384 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16387 /* The variable new_start now holds the new window start. The old
16388 start `start' can be determined from the current matrix. */
16389 SET_TEXT_POS_FROM_MARKER (new_start
, WVAR (w
, start
));
16390 start
= start_row
->minpos
;
16391 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16393 /* Clear the desired matrix for the display below. */
16394 clear_glyph_matrix (w
->desired_matrix
);
16396 if (CHARPOS (new_start
) <= CHARPOS (start
))
16398 /* Don't use this method if the display starts with an ellipsis
16399 displayed for invisible text. It's not easy to handle that case
16400 below, and it's certainly not worth the effort since this is
16401 not a frequent case. */
16402 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16405 IF_DEBUG (debug_method_add (w
, "twu1"));
16407 /* Display up to a row that can be reused. The variable
16408 last_text_row is set to the last row displayed that displays
16409 text. Note that it.vpos == 0 if or if not there is a
16410 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16411 start_display (&it
, w
, new_start
);
16412 w
->cursor
.vpos
= -1;
16413 last_text_row
= last_reused_text_row
= NULL
;
16415 while (it
.current_y
< it
.last_visible_y
16416 && !fonts_changed_p
)
16418 /* If we have reached into the characters in the START row,
16419 that means the line boundaries have changed. So we
16420 can't start copying with the row START. Maybe it will
16421 work to start copying with the following row. */
16422 while (IT_CHARPOS (it
) > CHARPOS (start
))
16424 /* Advance to the next row as the "start". */
16426 start
= start_row
->minpos
;
16427 /* If there are no more rows to try, or just one, give up. */
16428 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16429 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16430 || CHARPOS (start
) == ZV
)
16432 clear_glyph_matrix (w
->desired_matrix
);
16436 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16438 /* If we have reached alignment, we can copy the rest of the
16440 if (IT_CHARPOS (it
) == CHARPOS (start
)
16441 /* Don't accept "alignment" inside a display vector,
16442 since start_row could have started in the middle of
16443 that same display vector (thus their character
16444 positions match), and we have no way of telling if
16445 that is the case. */
16446 && it
.current
.dpvec_index
< 0)
16449 if (display_line (&it
))
16450 last_text_row
= it
.glyph_row
- 1;
16454 /* A value of current_y < last_visible_y means that we stopped
16455 at the previous window start, which in turn means that we
16456 have at least one reusable row. */
16457 if (it
.current_y
< it
.last_visible_y
)
16459 struct glyph_row
*row
;
16461 /* IT.vpos always starts from 0; it counts text lines. */
16462 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16464 /* Find PT if not already found in the lines displayed. */
16465 if (w
->cursor
.vpos
< 0)
16467 int dy
= it
.current_y
- start_row
->y
;
16469 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16470 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16472 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16473 dy
, nrows_scrolled
);
16476 clear_glyph_matrix (w
->desired_matrix
);
16481 /* Scroll the display. Do it before the current matrix is
16482 changed. The problem here is that update has not yet
16483 run, i.e. part of the current matrix is not up to date.
16484 scroll_run_hook will clear the cursor, and use the
16485 current matrix to get the height of the row the cursor is
16487 run
.current_y
= start_row
->y
;
16488 run
.desired_y
= it
.current_y
;
16489 run
.height
= it
.last_visible_y
- it
.current_y
;
16491 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16494 FRAME_RIF (f
)->update_window_begin_hook (w
);
16495 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16496 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16497 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16501 /* Shift current matrix down by nrows_scrolled lines. */
16502 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16503 rotate_matrix (w
->current_matrix
,
16505 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16508 /* Disable lines that must be updated. */
16509 for (i
= 0; i
< nrows_scrolled
; ++i
)
16510 (start_row
+ i
)->enabled_p
= 0;
16512 /* Re-compute Y positions. */
16513 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16514 max_y
= it
.last_visible_y
;
16515 for (row
= start_row
+ nrows_scrolled
;
16519 row
->y
= it
.current_y
;
16520 row
->visible_height
= row
->height
;
16522 if (row
->y
< min_y
)
16523 row
->visible_height
-= min_y
- row
->y
;
16524 if (row
->y
+ row
->height
> max_y
)
16525 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16526 if (row
->fringe_bitmap_periodic_p
)
16527 row
->redraw_fringe_bitmaps_p
= 1;
16529 it
.current_y
+= row
->height
;
16531 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16532 last_reused_text_row
= row
;
16533 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16537 /* Disable lines in the current matrix which are now
16538 below the window. */
16539 for (++row
; row
< bottom_row
; ++row
)
16540 row
->enabled_p
= row
->mode_line_p
= 0;
16543 /* Update window_end_pos etc.; last_reused_text_row is the last
16544 reused row from the current matrix containing text, if any.
16545 The value of last_text_row is the last displayed line
16546 containing text. */
16547 if (last_reused_text_row
)
16549 w
->window_end_bytepos
16550 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16551 WVAR (w
, window_end_pos
)
16552 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16553 WVAR (w
, window_end_vpos
)
16554 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16555 w
->current_matrix
));
16557 else if (last_text_row
)
16559 w
->window_end_bytepos
16560 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16561 WVAR (w
, window_end_pos
)
16562 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16563 WVAR (w
, window_end_vpos
)
16564 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16568 /* This window must be completely empty. */
16569 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16570 WVAR (w
, window_end_pos
) = make_number (Z
- ZV
);
16571 WVAR (w
, window_end_vpos
) = make_number (0);
16573 WVAR (w
, window_end_valid
) = Qnil
;
16575 /* Update hint: don't try scrolling again in update_window. */
16576 w
->desired_matrix
->no_scrolling_p
= 1;
16579 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16583 else if (CHARPOS (new_start
) > CHARPOS (start
))
16585 struct glyph_row
*pt_row
, *row
;
16586 struct glyph_row
*first_reusable_row
;
16587 struct glyph_row
*first_row_to_display
;
16589 int yb
= window_text_bottom_y (w
);
16591 /* Find the row starting at new_start, if there is one. Don't
16592 reuse a partially visible line at the end. */
16593 first_reusable_row
= start_row
;
16594 while (first_reusable_row
->enabled_p
16595 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16596 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16597 < CHARPOS (new_start
)))
16598 ++first_reusable_row
;
16600 /* Give up if there is no row to reuse. */
16601 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16602 || !first_reusable_row
->enabled_p
16603 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16604 != CHARPOS (new_start
)))
16607 /* We can reuse fully visible rows beginning with
16608 first_reusable_row to the end of the window. Set
16609 first_row_to_display to the first row that cannot be reused.
16610 Set pt_row to the row containing point, if there is any. */
16612 for (first_row_to_display
= first_reusable_row
;
16613 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16614 ++first_row_to_display
)
16616 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16617 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16618 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16619 && first_row_to_display
->ends_at_zv_p
16620 && pt_row
== NULL
)))
16621 pt_row
= first_row_to_display
;
16624 /* Start displaying at the start of first_row_to_display. */
16625 eassert (first_row_to_display
->y
< yb
);
16626 init_to_row_start (&it
, w
, first_row_to_display
);
16628 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16630 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16632 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16633 + WINDOW_HEADER_LINE_HEIGHT (w
));
16635 /* Display lines beginning with first_row_to_display in the
16636 desired matrix. Set last_text_row to the last row displayed
16637 that displays text. */
16638 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16639 if (pt_row
== NULL
)
16640 w
->cursor
.vpos
= -1;
16641 last_text_row
= NULL
;
16642 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16643 if (display_line (&it
))
16644 last_text_row
= it
.glyph_row
- 1;
16646 /* If point is in a reused row, adjust y and vpos of the cursor
16650 w
->cursor
.vpos
-= nrows_scrolled
;
16651 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16654 /* Give up if point isn't in a row displayed or reused. (This
16655 also handles the case where w->cursor.vpos < nrows_scrolled
16656 after the calls to display_line, which can happen with scroll
16657 margins. See bug#1295.) */
16658 if (w
->cursor
.vpos
< 0)
16660 clear_glyph_matrix (w
->desired_matrix
);
16664 /* Scroll the display. */
16665 run
.current_y
= first_reusable_row
->y
;
16666 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16667 run
.height
= it
.last_visible_y
- run
.current_y
;
16668 dy
= run
.current_y
- run
.desired_y
;
16673 FRAME_RIF (f
)->update_window_begin_hook (w
);
16674 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16675 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16676 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16680 /* Adjust Y positions of reused rows. */
16681 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16682 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16683 max_y
= it
.last_visible_y
;
16684 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16687 row
->visible_height
= row
->height
;
16688 if (row
->y
< min_y
)
16689 row
->visible_height
-= min_y
- row
->y
;
16690 if (row
->y
+ row
->height
> max_y
)
16691 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16692 if (row
->fringe_bitmap_periodic_p
)
16693 row
->redraw_fringe_bitmaps_p
= 1;
16696 /* Scroll the current matrix. */
16697 eassert (nrows_scrolled
> 0);
16698 rotate_matrix (w
->current_matrix
,
16700 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16703 /* Disable rows not reused. */
16704 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16705 row
->enabled_p
= 0;
16707 /* Point may have moved to a different line, so we cannot assume that
16708 the previous cursor position is valid; locate the correct row. */
16711 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16713 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16714 && !row
->ends_at_zv_p
;
16718 w
->cursor
.y
= row
->y
;
16720 if (row
< bottom_row
)
16722 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16723 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16725 /* Can't use this optimization with bidi-reordered glyph
16726 rows, unless cursor is already at point. */
16727 if (!NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_display_reordering
)))
16729 if (!(w
->cursor
.hpos
>= 0
16730 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16731 && BUFFERP (glyph
->object
)
16732 && glyph
->charpos
== PT
))
16737 && (!BUFFERP (glyph
->object
)
16738 || glyph
->charpos
< PT
);
16742 w
->cursor
.x
+= glyph
->pixel_width
;
16747 /* Adjust window end. A null value of last_text_row means that
16748 the window end is in reused rows which in turn means that
16749 only its vpos can have changed. */
16752 w
->window_end_bytepos
16753 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16754 WVAR (w
, window_end_pos
)
16755 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16756 WVAR (w
, window_end_vpos
)
16757 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16761 WVAR (w
, window_end_vpos
)
16762 = make_number (XFASTINT (WVAR (w
, window_end_vpos
)) - nrows_scrolled
);
16765 WVAR (w
, window_end_valid
) = Qnil
;
16766 w
->desired_matrix
->no_scrolling_p
= 1;
16769 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16779 /************************************************************************
16780 Window redisplay reusing current matrix when buffer has changed
16781 ************************************************************************/
16783 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16784 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16785 ptrdiff_t *, ptrdiff_t *);
16786 static struct glyph_row
*
16787 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16788 struct glyph_row
*);
16791 /* Return the last row in MATRIX displaying text. If row START is
16792 non-null, start searching with that row. IT gives the dimensions
16793 of the display. Value is null if matrix is empty; otherwise it is
16794 a pointer to the row found. */
16796 static struct glyph_row
*
16797 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16798 struct glyph_row
*start
)
16800 struct glyph_row
*row
, *row_found
;
16802 /* Set row_found to the last row in IT->w's current matrix
16803 displaying text. The loop looks funny but think of partially
16806 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16807 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16809 eassert (row
->enabled_p
);
16811 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16820 /* Return the last row in the current matrix of W that is not affected
16821 by changes at the start of current_buffer that occurred since W's
16822 current matrix was built. Value is null if no such row exists.
16824 BEG_UNCHANGED us the number of characters unchanged at the start of
16825 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16826 first changed character in current_buffer. Characters at positions <
16827 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16828 when the current matrix was built. */
16830 static struct glyph_row
*
16831 find_last_unchanged_at_beg_row (struct window
*w
)
16833 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16834 struct glyph_row
*row
;
16835 struct glyph_row
*row_found
= NULL
;
16836 int yb
= window_text_bottom_y (w
);
16838 /* Find the last row displaying unchanged text. */
16839 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16840 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16841 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16844 if (/* If row ends before first_changed_pos, it is unchanged,
16845 except in some case. */
16846 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16847 /* When row ends in ZV and we write at ZV it is not
16849 && !row
->ends_at_zv_p
16850 /* When first_changed_pos is the end of a continued line,
16851 row is not unchanged because it may be no longer
16853 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16854 && (row
->continued_p
16855 || row
->exact_window_width_line_p
))
16856 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16857 needs to be recomputed, so don't consider this row as
16858 unchanged. This happens when the last line was
16859 bidi-reordered and was killed immediately before this
16860 redisplay cycle. In that case, ROW->end stores the
16861 buffer position of the first visual-order character of
16862 the killed text, which is now beyond ZV. */
16863 && CHARPOS (row
->end
.pos
) <= ZV
)
16866 /* Stop if last visible row. */
16867 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16875 /* Find the first glyph row in the current matrix of W that is not
16876 affected by changes at the end of current_buffer since the
16877 time W's current matrix was built.
16879 Return in *DELTA the number of chars by which buffer positions in
16880 unchanged text at the end of current_buffer must be adjusted.
16882 Return in *DELTA_BYTES the corresponding number of bytes.
16884 Value is null if no such row exists, i.e. all rows are affected by
16887 static struct glyph_row
*
16888 find_first_unchanged_at_end_row (struct window
*w
,
16889 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16891 struct glyph_row
*row
;
16892 struct glyph_row
*row_found
= NULL
;
16894 *delta
= *delta_bytes
= 0;
16896 /* Display must not have been paused, otherwise the current matrix
16897 is not up to date. */
16898 eassert (!NILP (WVAR (w
, window_end_valid
)));
16900 /* A value of window_end_pos >= END_UNCHANGED means that the window
16901 end is in the range of changed text. If so, there is no
16902 unchanged row at the end of W's current matrix. */
16903 if (XFASTINT (WVAR (w
, window_end_pos
)) >= END_UNCHANGED
)
16906 /* Set row to the last row in W's current matrix displaying text. */
16907 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (WVAR (w
, window_end_vpos
)));
16909 /* If matrix is entirely empty, no unchanged row exists. */
16910 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16912 /* The value of row is the last glyph row in the matrix having a
16913 meaningful buffer position in it. The end position of row
16914 corresponds to window_end_pos. This allows us to translate
16915 buffer positions in the current matrix to current buffer
16916 positions for characters not in changed text. */
16918 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (WVAR (w
, window_end_pos
));
16919 ptrdiff_t Z_BYTE_old
=
16920 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16921 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16922 struct glyph_row
*first_text_row
16923 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16925 *delta
= Z
- Z_old
;
16926 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16928 /* Set last_unchanged_pos to the buffer position of the last
16929 character in the buffer that has not been changed. Z is the
16930 index + 1 of the last character in current_buffer, i.e. by
16931 subtracting END_UNCHANGED we get the index of the last
16932 unchanged character, and we have to add BEG to get its buffer
16934 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16935 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16937 /* Search backward from ROW for a row displaying a line that
16938 starts at a minimum position >= last_unchanged_pos_old. */
16939 for (; row
> first_text_row
; --row
)
16941 /* This used to abort, but it can happen.
16942 It is ok to just stop the search instead here. KFS. */
16943 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16946 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16951 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16957 /* Make sure that glyph rows in the current matrix of window W
16958 reference the same glyph memory as corresponding rows in the
16959 frame's frame matrix. This function is called after scrolling W's
16960 current matrix on a terminal frame in try_window_id and
16961 try_window_reusing_current_matrix. */
16964 sync_frame_with_window_matrix_rows (struct window
*w
)
16966 struct frame
*f
= XFRAME (WVAR (w
, frame
));
16967 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16969 /* Preconditions: W must be a leaf window and full-width. Its frame
16970 must have a frame matrix. */
16971 eassert (NILP (WVAR (w
, hchild
)) && NILP (WVAR (w
, vchild
)));
16972 eassert (WINDOW_FULL_WIDTH_P (w
));
16973 eassert (!FRAME_WINDOW_P (f
));
16975 /* If W is a full-width window, glyph pointers in W's current matrix
16976 have, by definition, to be the same as glyph pointers in the
16977 corresponding frame matrix. Note that frame matrices have no
16978 marginal areas (see build_frame_matrix). */
16979 window_row
= w
->current_matrix
->rows
;
16980 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16981 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16982 while (window_row
< window_row_end
)
16984 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16985 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16987 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16988 frame_row
->glyphs
[TEXT_AREA
] = start
;
16989 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16990 frame_row
->glyphs
[LAST_AREA
] = end
;
16992 /* Disable frame rows whose corresponding window rows have
16993 been disabled in try_window_id. */
16994 if (!window_row
->enabled_p
)
16995 frame_row
->enabled_p
= 0;
16997 ++window_row
, ++frame_row
;
17002 /* Find the glyph row in window W containing CHARPOS. Consider all
17003 rows between START and END (not inclusive). END null means search
17004 all rows to the end of the display area of W. Value is the row
17005 containing CHARPOS or null. */
17008 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17009 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17011 struct glyph_row
*row
= start
;
17012 struct glyph_row
*best_row
= NULL
;
17013 ptrdiff_t mindif
= BUF_ZV (XBUFFER (WVAR (w
, buffer
))) + 1;
17016 /* If we happen to start on a header-line, skip that. */
17017 if (row
->mode_line_p
)
17020 if ((end
&& row
>= end
) || !row
->enabled_p
)
17023 last_y
= window_text_bottom_y (w
) - dy
;
17027 /* Give up if we have gone too far. */
17028 if (end
&& row
>= end
)
17030 /* This formerly returned if they were equal.
17031 I think that both quantities are of a "last plus one" type;
17032 if so, when they are equal, the row is within the screen. -- rms. */
17033 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17036 /* If it is in this row, return this row. */
17037 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17038 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17039 /* The end position of a row equals the start
17040 position of the next row. If CHARPOS is there, we
17041 would rather display it in the next line, except
17042 when this line ends in ZV. */
17043 && !row
->ends_at_zv_p
17044 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17045 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17049 if (NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_display_reordering
))
17050 || (!best_row
&& !row
->continued_p
))
17052 /* In bidi-reordered rows, there could be several rows
17053 occluding point, all of them belonging to the same
17054 continued line. We need to find the row which fits
17055 CHARPOS the best. */
17056 for (g
= row
->glyphs
[TEXT_AREA
];
17057 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17060 if (!STRINGP (g
->object
))
17062 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17064 mindif
= eabs (g
->charpos
- charpos
);
17066 /* Exact match always wins. */
17073 else if (best_row
&& !row
->continued_p
)
17080 /* Try to redisplay window W by reusing its existing display. W's
17081 current matrix must be up to date when this function is called,
17082 i.e. window_end_valid must not be nil.
17086 1 if display has been updated
17087 0 if otherwise unsuccessful
17088 -1 if redisplay with same window start is known not to succeed
17090 The following steps are performed:
17092 1. Find the last row in the current matrix of W that is not
17093 affected by changes at the start of current_buffer. If no such row
17096 2. Find the first row in W's current matrix that is not affected by
17097 changes at the end of current_buffer. Maybe there is no such row.
17099 3. Display lines beginning with the row + 1 found in step 1 to the
17100 row found in step 2 or, if step 2 didn't find a row, to the end of
17103 4. If cursor is not known to appear on the window, give up.
17105 5. If display stopped at the row found in step 2, scroll the
17106 display and current matrix as needed.
17108 6. Maybe display some lines at the end of W, if we must. This can
17109 happen under various circumstances, like a partially visible line
17110 becoming fully visible, or because newly displayed lines are displayed
17111 in smaller font sizes.
17113 7. Update W's window end information. */
17116 try_window_id (struct window
*w
)
17118 struct frame
*f
= XFRAME (WVAR (w
, frame
));
17119 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17120 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17121 struct glyph_row
*last_unchanged_at_beg_row
;
17122 struct glyph_row
*first_unchanged_at_end_row
;
17123 struct glyph_row
*row
;
17124 struct glyph_row
*bottom_row
;
17127 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17129 struct text_pos start_pos
;
17131 int first_unchanged_at_end_vpos
= 0;
17132 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17133 struct text_pos start
;
17134 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17137 if (inhibit_try_window_id
)
17141 /* This is handy for debugging. */
17143 #define GIVE_UP(X) \
17145 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17149 #define GIVE_UP(X) return 0
17152 SET_TEXT_POS_FROM_MARKER (start
, WVAR (w
, start
));
17154 /* Don't use this for mini-windows because these can show
17155 messages and mini-buffers, and we don't handle that here. */
17156 if (MINI_WINDOW_P (w
))
17159 /* This flag is used to prevent redisplay optimizations. */
17160 if (windows_or_buffers_changed
|| cursor_type_changed
)
17163 /* Verify that narrowing has not changed.
17164 Also verify that we were not told to prevent redisplay optimizations.
17165 It would be nice to further
17166 reduce the number of cases where this prevents try_window_id. */
17167 if (current_buffer
->clip_changed
17168 || current_buffer
->prevent_redisplay_optimizations_p
)
17171 /* Window must either use window-based redisplay or be full width. */
17172 if (!FRAME_WINDOW_P (f
)
17173 && (!FRAME_LINE_INS_DEL_OK (f
)
17174 || !WINDOW_FULL_WIDTH_P (w
)))
17177 /* Give up if point is known NOT to appear in W. */
17178 if (PT
< CHARPOS (start
))
17181 /* Another way to prevent redisplay optimizations. */
17182 if (w
->last_modified
== 0)
17185 /* Verify that window is not hscrolled. */
17186 if (w
->hscroll
!= 0)
17189 /* Verify that display wasn't paused. */
17190 if (NILP (WVAR (w
, window_end_valid
)))
17193 /* Can't use this if highlighting a region because a cursor movement
17194 will do more than just set the cursor. */
17195 if (!NILP (Vtransient_mark_mode
)
17196 && !NILP (BVAR (current_buffer
, mark_active
)))
17199 /* Likewise if highlighting trailing whitespace. */
17200 if (!NILP (Vshow_trailing_whitespace
))
17203 /* Likewise if showing a region. */
17204 if (!NILP (WVAR (w
, region_showing
)))
17207 /* Can't use this if overlay arrow position and/or string have
17209 if (overlay_arrows_changed_p ())
17212 /* When word-wrap is on, adding a space to the first word of a
17213 wrapped line can change the wrap position, altering the line
17214 above it. It might be worthwhile to handle this more
17215 intelligently, but for now just redisplay from scratch. */
17216 if (!NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), word_wrap
)))
17219 /* Under bidi reordering, adding or deleting a character in the
17220 beginning of a paragraph, before the first strong directional
17221 character, can change the base direction of the paragraph (unless
17222 the buffer specifies a fixed paragraph direction), which will
17223 require to redisplay the whole paragraph. It might be worthwhile
17224 to find the paragraph limits and widen the range of redisplayed
17225 lines to that, but for now just give up this optimization and
17226 redisplay from scratch. */
17227 if (!NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_display_reordering
))
17228 && NILP (BVAR (XBUFFER (WVAR (w
, buffer
)), bidi_paragraph_direction
)))
17231 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17232 only if buffer has really changed. The reason is that the gap is
17233 initially at Z for freshly visited files. The code below would
17234 set end_unchanged to 0 in that case. */
17235 if (MODIFF
> SAVE_MODIFF
17236 /* This seems to happen sometimes after saving a buffer. */
17237 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17239 if (GPT
- BEG
< BEG_UNCHANGED
)
17240 BEG_UNCHANGED
= GPT
- BEG
;
17241 if (Z
- GPT
< END_UNCHANGED
)
17242 END_UNCHANGED
= Z
- GPT
;
17245 /* The position of the first and last character that has been changed. */
17246 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17247 last_changed_charpos
= Z
- END_UNCHANGED
;
17249 /* If window starts after a line end, and the last change is in
17250 front of that newline, then changes don't affect the display.
17251 This case happens with stealth-fontification. Note that although
17252 the display is unchanged, glyph positions in the matrix have to
17253 be adjusted, of course. */
17254 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (WVAR (w
, window_end_vpos
)));
17255 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17256 && ((last_changed_charpos
< CHARPOS (start
)
17257 && CHARPOS (start
) == BEGV
)
17258 || (last_changed_charpos
< CHARPOS (start
) - 1
17259 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17261 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17262 struct glyph_row
*r0
;
17264 /* Compute how many chars/bytes have been added to or removed
17265 from the buffer. */
17266 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (WVAR (w
, window_end_pos
));
17267 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17268 Z_delta
= Z
- Z_old
;
17269 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17271 /* Give up if PT is not in the window. Note that it already has
17272 been checked at the start of try_window_id that PT is not in
17273 front of the window start. */
17274 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17277 /* If window start is unchanged, we can reuse the whole matrix
17278 as is, after adjusting glyph positions. No need to compute
17279 the window end again, since its offset from Z hasn't changed. */
17280 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17281 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17282 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17283 /* PT must not be in a partially visible line. */
17284 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17285 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17287 /* Adjust positions in the glyph matrix. */
17288 if (Z_delta
|| Z_delta_bytes
)
17290 struct glyph_row
*r1
17291 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17292 increment_matrix_positions (w
->current_matrix
,
17293 MATRIX_ROW_VPOS (r0
, current_matrix
),
17294 MATRIX_ROW_VPOS (r1
, current_matrix
),
17295 Z_delta
, Z_delta_bytes
);
17298 /* Set the cursor. */
17299 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17301 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17308 /* Handle the case that changes are all below what is displayed in
17309 the window, and that PT is in the window. This shortcut cannot
17310 be taken if ZV is visible in the window, and text has been added
17311 there that is visible in the window. */
17312 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17313 /* ZV is not visible in the window, or there are no
17314 changes at ZV, actually. */
17315 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17316 || first_changed_charpos
== last_changed_charpos
))
17318 struct glyph_row
*r0
;
17320 /* Give up if PT is not in the window. Note that it already has
17321 been checked at the start of try_window_id that PT is not in
17322 front of the window start. */
17323 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17326 /* If window start is unchanged, we can reuse the whole matrix
17327 as is, without changing glyph positions since no text has
17328 been added/removed in front of the window end. */
17329 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17330 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17331 /* PT must not be in a partially visible line. */
17332 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17333 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17335 /* We have to compute the window end anew since text
17336 could have been added/removed after it. */
17337 WVAR (w
, window_end_pos
)
17338 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17339 w
->window_end_bytepos
17340 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17342 /* Set the cursor. */
17343 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17345 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17352 /* Give up if window start is in the changed area.
17354 The condition used to read
17356 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17358 but why that was tested escapes me at the moment. */
17359 if (CHARPOS (start
) >= first_changed_charpos
17360 && CHARPOS (start
) <= last_changed_charpos
)
17363 /* Check that window start agrees with the start of the first glyph
17364 row in its current matrix. Check this after we know the window
17365 start is not in changed text, otherwise positions would not be
17367 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17368 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17371 /* Give up if the window ends in strings. Overlay strings
17372 at the end are difficult to handle, so don't try. */
17373 row
= MATRIX_ROW (current_matrix
, XFASTINT (WVAR (w
, window_end_vpos
)));
17374 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17377 /* Compute the position at which we have to start displaying new
17378 lines. Some of the lines at the top of the window might be
17379 reusable because they are not displaying changed text. Find the
17380 last row in W's current matrix not affected by changes at the
17381 start of current_buffer. Value is null if changes start in the
17382 first line of window. */
17383 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17384 if (last_unchanged_at_beg_row
)
17386 /* Avoid starting to display in the middle of a character, a TAB
17387 for instance. This is easier than to set up the iterator
17388 exactly, and it's not a frequent case, so the additional
17389 effort wouldn't really pay off. */
17390 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17391 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17392 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17393 --last_unchanged_at_beg_row
;
17395 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17398 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17400 start_pos
= it
.current
.pos
;
17402 /* Start displaying new lines in the desired matrix at the same
17403 vpos we would use in the current matrix, i.e. below
17404 last_unchanged_at_beg_row. */
17405 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17407 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17408 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17410 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17414 /* There are no reusable lines at the start of the window.
17415 Start displaying in the first text line. */
17416 start_display (&it
, w
, start
);
17417 it
.vpos
= it
.first_vpos
;
17418 start_pos
= it
.current
.pos
;
17421 /* Find the first row that is not affected by changes at the end of
17422 the buffer. Value will be null if there is no unchanged row, in
17423 which case we must redisplay to the end of the window. delta
17424 will be set to the value by which buffer positions beginning with
17425 first_unchanged_at_end_row have to be adjusted due to text
17427 first_unchanged_at_end_row
17428 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17429 IF_DEBUG (debug_delta
= delta
);
17430 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17432 /* Set stop_pos to the buffer position up to which we will have to
17433 display new lines. If first_unchanged_at_end_row != NULL, this
17434 is the buffer position of the start of the line displayed in that
17435 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17436 that we don't stop at a buffer position. */
17438 if (first_unchanged_at_end_row
)
17440 eassert (last_unchanged_at_beg_row
== NULL
17441 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17443 /* If this is a continuation line, move forward to the next one
17444 that isn't. Changes in lines above affect this line.
17445 Caution: this may move first_unchanged_at_end_row to a row
17446 not displaying text. */
17447 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17448 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17449 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17450 < it
.last_visible_y
))
17451 ++first_unchanged_at_end_row
;
17453 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17454 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17455 >= it
.last_visible_y
))
17456 first_unchanged_at_end_row
= NULL
;
17459 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17461 first_unchanged_at_end_vpos
17462 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17463 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17466 else if (last_unchanged_at_beg_row
== NULL
)
17472 /* Either there is no unchanged row at the end, or the one we have
17473 now displays text. This is a necessary condition for the window
17474 end pos calculation at the end of this function. */
17475 eassert (first_unchanged_at_end_row
== NULL
17476 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17478 debug_last_unchanged_at_beg_vpos
17479 = (last_unchanged_at_beg_row
17480 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17482 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17484 #endif /* GLYPH_DEBUG */
17487 /* Display new lines. Set last_text_row to the last new line
17488 displayed which has text on it, i.e. might end up as being the
17489 line where the window_end_vpos is. */
17490 w
->cursor
.vpos
= -1;
17491 last_text_row
= NULL
;
17492 overlay_arrow_seen
= 0;
17493 while (it
.current_y
< it
.last_visible_y
17494 && !fonts_changed_p
17495 && (first_unchanged_at_end_row
== NULL
17496 || IT_CHARPOS (it
) < stop_pos
))
17498 if (display_line (&it
))
17499 last_text_row
= it
.glyph_row
- 1;
17502 if (fonts_changed_p
)
17506 /* Compute differences in buffer positions, y-positions etc. for
17507 lines reused at the bottom of the window. Compute what we can
17509 if (first_unchanged_at_end_row
17510 /* No lines reused because we displayed everything up to the
17511 bottom of the window. */
17512 && it
.current_y
< it
.last_visible_y
)
17515 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17517 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17518 run
.current_y
= first_unchanged_at_end_row
->y
;
17519 run
.desired_y
= run
.current_y
+ dy
;
17520 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17524 delta
= delta_bytes
= dvpos
= dy
17525 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17526 first_unchanged_at_end_row
= NULL
;
17528 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17531 /* Find the cursor if not already found. We have to decide whether
17532 PT will appear on this window (it sometimes doesn't, but this is
17533 not a very frequent case.) This decision has to be made before
17534 the current matrix is altered. A value of cursor.vpos < 0 means
17535 that PT is either in one of the lines beginning at
17536 first_unchanged_at_end_row or below the window. Don't care for
17537 lines that might be displayed later at the window end; as
17538 mentioned, this is not a frequent case. */
17539 if (w
->cursor
.vpos
< 0)
17541 /* Cursor in unchanged rows at the top? */
17542 if (PT
< CHARPOS (start_pos
)
17543 && last_unchanged_at_beg_row
)
17545 row
= row_containing_pos (w
, PT
,
17546 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17547 last_unchanged_at_beg_row
+ 1, 0);
17549 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17552 /* Start from first_unchanged_at_end_row looking for PT. */
17553 else if (first_unchanged_at_end_row
)
17555 row
= row_containing_pos (w
, PT
- delta
,
17556 first_unchanged_at_end_row
, NULL
, 0);
17558 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17559 delta_bytes
, dy
, dvpos
);
17562 /* Give up if cursor was not found. */
17563 if (w
->cursor
.vpos
< 0)
17565 clear_glyph_matrix (w
->desired_matrix
);
17570 /* Don't let the cursor end in the scroll margins. */
17572 int this_scroll_margin
, cursor_height
;
17574 this_scroll_margin
=
17575 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17576 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17577 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17579 if ((w
->cursor
.y
< this_scroll_margin
17580 && CHARPOS (start
) > BEGV
)
17581 /* Old redisplay didn't take scroll margin into account at the bottom,
17582 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17583 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17584 ? cursor_height
+ this_scroll_margin
17585 : 1)) > it
.last_visible_y
)
17587 w
->cursor
.vpos
= -1;
17588 clear_glyph_matrix (w
->desired_matrix
);
17593 /* Scroll the display. Do it before changing the current matrix so
17594 that xterm.c doesn't get confused about where the cursor glyph is
17596 if (dy
&& run
.height
)
17600 if (FRAME_WINDOW_P (f
))
17602 FRAME_RIF (f
)->update_window_begin_hook (w
);
17603 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17604 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17605 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17609 /* Terminal frame. In this case, dvpos gives the number of
17610 lines to scroll by; dvpos < 0 means scroll up. */
17612 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17613 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17614 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17615 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17616 + window_internal_height (w
));
17618 #if defined (HAVE_GPM) || defined (MSDOS)
17619 x_clear_window_mouse_face (w
);
17621 /* Perform the operation on the screen. */
17624 /* Scroll last_unchanged_at_beg_row to the end of the
17625 window down dvpos lines. */
17626 set_terminal_window (f
, end
);
17628 /* On dumb terminals delete dvpos lines at the end
17629 before inserting dvpos empty lines. */
17630 if (!FRAME_SCROLL_REGION_OK (f
))
17631 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17633 /* Insert dvpos empty lines in front of
17634 last_unchanged_at_beg_row. */
17635 ins_del_lines (f
, from
, dvpos
);
17637 else if (dvpos
< 0)
17639 /* Scroll up last_unchanged_at_beg_vpos to the end of
17640 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17641 set_terminal_window (f
, end
);
17643 /* Delete dvpos lines in front of
17644 last_unchanged_at_beg_vpos. ins_del_lines will set
17645 the cursor to the given vpos and emit |dvpos| delete
17647 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17649 /* On a dumb terminal insert dvpos empty lines at the
17651 if (!FRAME_SCROLL_REGION_OK (f
))
17652 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17655 set_terminal_window (f
, 0);
17661 /* Shift reused rows of the current matrix to the right position.
17662 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17664 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17665 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17668 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17669 bottom_vpos
, dvpos
);
17670 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17673 else if (dvpos
> 0)
17675 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17676 bottom_vpos
, dvpos
);
17677 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17678 first_unchanged_at_end_vpos
+ dvpos
, 0);
17681 /* For frame-based redisplay, make sure that current frame and window
17682 matrix are in sync with respect to glyph memory. */
17683 if (!FRAME_WINDOW_P (f
))
17684 sync_frame_with_window_matrix_rows (w
);
17686 /* Adjust buffer positions in reused rows. */
17687 if (delta
|| delta_bytes
)
17688 increment_matrix_positions (current_matrix
,
17689 first_unchanged_at_end_vpos
+ dvpos
,
17690 bottom_vpos
, delta
, delta_bytes
);
17692 /* Adjust Y positions. */
17694 shift_glyph_matrix (w
, current_matrix
,
17695 first_unchanged_at_end_vpos
+ dvpos
,
17698 if (first_unchanged_at_end_row
)
17700 first_unchanged_at_end_row
+= dvpos
;
17701 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17702 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17703 first_unchanged_at_end_row
= NULL
;
17706 /* If scrolling up, there may be some lines to display at the end of
17708 last_text_row_at_end
= NULL
;
17711 /* Scrolling up can leave for example a partially visible line
17712 at the end of the window to be redisplayed. */
17713 /* Set last_row to the glyph row in the current matrix where the
17714 window end line is found. It has been moved up or down in
17715 the matrix by dvpos. */
17716 int last_vpos
= XFASTINT (WVAR (w
, window_end_vpos
)) + dvpos
;
17717 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17719 /* If last_row is the window end line, it should display text. */
17720 eassert (last_row
->displays_text_p
);
17722 /* If window end line was partially visible before, begin
17723 displaying at that line. Otherwise begin displaying with the
17724 line following it. */
17725 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17727 init_to_row_start (&it
, w
, last_row
);
17728 it
.vpos
= last_vpos
;
17729 it
.current_y
= last_row
->y
;
17733 init_to_row_end (&it
, w
, last_row
);
17734 it
.vpos
= 1 + last_vpos
;
17735 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17739 /* We may start in a continuation line. If so, we have to
17740 get the right continuation_lines_width and current_x. */
17741 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17742 it
.hpos
= it
.current_x
= 0;
17744 /* Display the rest of the lines at the window end. */
17745 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17746 while (it
.current_y
< it
.last_visible_y
17747 && !fonts_changed_p
)
17749 /* Is it always sure that the display agrees with lines in
17750 the current matrix? I don't think so, so we mark rows
17751 displayed invalid in the current matrix by setting their
17752 enabled_p flag to zero. */
17753 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17754 if (display_line (&it
))
17755 last_text_row_at_end
= it
.glyph_row
- 1;
17759 /* Update window_end_pos and window_end_vpos. */
17760 if (first_unchanged_at_end_row
17761 && !last_text_row_at_end
)
17763 /* Window end line if one of the preserved rows from the current
17764 matrix. Set row to the last row displaying text in current
17765 matrix starting at first_unchanged_at_end_row, after
17767 eassert (first_unchanged_at_end_row
->displays_text_p
);
17768 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17769 first_unchanged_at_end_row
);
17770 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17772 WVAR (w
, window_end_pos
) = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17773 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17774 WVAR (w
, window_end_vpos
)
17775 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17776 eassert (w
->window_end_bytepos
>= 0);
17777 IF_DEBUG (debug_method_add (w
, "A"));
17779 else if (last_text_row_at_end
)
17781 WVAR (w
, window_end_pos
)
17782 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17783 w
->window_end_bytepos
17784 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17785 WVAR (w
, window_end_vpos
)
17786 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17787 eassert (w
->window_end_bytepos
>= 0);
17788 IF_DEBUG (debug_method_add (w
, "B"));
17790 else if (last_text_row
)
17792 /* We have displayed either to the end of the window or at the
17793 end of the window, i.e. the last row with text is to be found
17794 in the desired matrix. */
17795 WVAR (w
, window_end_pos
)
17796 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17797 w
->window_end_bytepos
17798 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17799 WVAR (w
, window_end_vpos
)
17800 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17801 eassert (w
->window_end_bytepos
>= 0);
17803 else if (first_unchanged_at_end_row
== NULL
17804 && last_text_row
== NULL
17805 && last_text_row_at_end
== NULL
)
17807 /* Displayed to end of window, but no line containing text was
17808 displayed. Lines were deleted at the end of the window. */
17809 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17810 int vpos
= XFASTINT (WVAR (w
, window_end_vpos
));
17811 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17812 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17815 row
== NULL
&& vpos
>= first_vpos
;
17816 --vpos
, --current_row
, --desired_row
)
17818 if (desired_row
->enabled_p
)
17820 if (desired_row
->displays_text_p
)
17823 else if (current_row
->displays_text_p
)
17827 eassert (row
!= NULL
);
17828 WVAR (w
, window_end_vpos
) = make_number (vpos
+ 1);
17829 WVAR (w
, window_end_pos
) = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17830 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17831 eassert (w
->window_end_bytepos
>= 0);
17832 IF_DEBUG (debug_method_add (w
, "C"));
17837 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17838 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17840 /* Record that display has not been completed. */
17841 WVAR (w
, window_end_valid
) = Qnil
;
17842 w
->desired_matrix
->no_scrolling_p
= 1;
17850 /***********************************************************************
17851 More debugging support
17852 ***********************************************************************/
17856 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17857 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17858 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17861 /* Dump the contents of glyph matrix MATRIX on stderr.
17863 GLYPHS 0 means don't show glyph contents.
17864 GLYPHS 1 means show glyphs in short form
17865 GLYPHS > 1 means show glyphs in long form. */
17868 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17871 for (i
= 0; i
< matrix
->nrows
; ++i
)
17872 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17876 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17877 the glyph row and area where the glyph comes from. */
17880 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17882 if (glyph
->type
== CHAR_GLYPH
)
17885 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17886 glyph
- row
->glyphs
[TEXT_AREA
],
17889 (BUFFERP (glyph
->object
)
17891 : (STRINGP (glyph
->object
)
17894 glyph
->pixel_width
,
17896 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17900 glyph
->left_box_line_p
,
17901 glyph
->right_box_line_p
);
17903 else if (glyph
->type
== STRETCH_GLYPH
)
17906 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17907 glyph
- row
->glyphs
[TEXT_AREA
],
17910 (BUFFERP (glyph
->object
)
17912 : (STRINGP (glyph
->object
)
17915 glyph
->pixel_width
,
17919 glyph
->left_box_line_p
,
17920 glyph
->right_box_line_p
);
17922 else if (glyph
->type
== IMAGE_GLYPH
)
17925 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17926 glyph
- row
->glyphs
[TEXT_AREA
],
17929 (BUFFERP (glyph
->object
)
17931 : (STRINGP (glyph
->object
)
17934 glyph
->pixel_width
,
17938 glyph
->left_box_line_p
,
17939 glyph
->right_box_line_p
);
17941 else if (glyph
->type
== COMPOSITE_GLYPH
)
17944 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17945 glyph
- row
->glyphs
[TEXT_AREA
],
17948 (BUFFERP (glyph
->object
)
17950 : (STRINGP (glyph
->object
)
17953 glyph
->pixel_width
,
17955 if (glyph
->u
.cmp
.automatic
)
17958 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17959 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17961 glyph
->left_box_line_p
,
17962 glyph
->right_box_line_p
);
17967 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17968 GLYPHS 0 means don't show glyph contents.
17969 GLYPHS 1 means show glyphs in short form
17970 GLYPHS > 1 means show glyphs in long form. */
17973 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17977 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17978 fprintf (stderr
, "======================================================================\n");
17980 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17981 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17983 MATRIX_ROW_START_CHARPOS (row
),
17984 MATRIX_ROW_END_CHARPOS (row
),
17985 row
->used
[TEXT_AREA
],
17986 row
->contains_overlapping_glyphs_p
,
17988 row
->truncated_on_left_p
,
17989 row
->truncated_on_right_p
,
17991 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17992 row
->displays_text_p
,
17995 row
->ends_in_middle_of_char_p
,
17996 row
->starts_in_middle_of_char_p
,
18002 row
->visible_height
,
18005 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18006 row
->end
.overlay_string_index
,
18007 row
->continuation_lines_width
);
18008 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
18009 CHARPOS (row
->start
.string_pos
),
18010 CHARPOS (row
->end
.string_pos
));
18011 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
18012 row
->end
.dpvec_index
);
18019 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18021 struct glyph
*glyph
= row
->glyphs
[area
];
18022 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18024 /* Glyph for a line end in text. */
18025 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18028 if (glyph
< glyph_end
)
18029 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18031 for (; glyph
< glyph_end
; ++glyph
)
18032 dump_glyph (row
, glyph
, area
);
18035 else if (glyphs
== 1)
18039 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18041 char *s
= alloca (row
->used
[area
] + 1);
18044 for (i
= 0; i
< row
->used
[area
]; ++i
)
18046 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18047 if (glyph
->type
== CHAR_GLYPH
18048 && glyph
->u
.ch
< 0x80
18049 && glyph
->u
.ch
>= ' ')
18050 s
[i
] = glyph
->u
.ch
;
18056 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18062 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18063 Sdump_glyph_matrix
, 0, 1, "p",
18064 doc
: /* Dump the current matrix of the selected window to stderr.
18065 Shows contents of glyph row structures. With non-nil
18066 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18067 glyphs in short form, otherwise show glyphs in long form. */)
18068 (Lisp_Object glyphs
)
18070 struct window
*w
= XWINDOW (selected_window
);
18071 struct buffer
*buffer
= XBUFFER (WVAR (w
, buffer
));
18073 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18074 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18075 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18076 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18077 fprintf (stderr
, "=============================================\n");
18078 dump_glyph_matrix (w
->current_matrix
,
18079 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18084 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18085 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18088 struct frame
*f
= XFRAME (selected_frame
);
18089 dump_glyph_matrix (f
->current_matrix
, 1);
18094 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18095 doc
: /* Dump glyph row ROW to stderr.
18096 GLYPH 0 means don't dump glyphs.
18097 GLYPH 1 means dump glyphs in short form.
18098 GLYPH > 1 or omitted means dump glyphs in long form. */)
18099 (Lisp_Object row
, Lisp_Object glyphs
)
18101 struct glyph_matrix
*matrix
;
18104 CHECK_NUMBER (row
);
18105 matrix
= XWINDOW (selected_window
)->current_matrix
;
18107 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18108 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18110 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18115 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18116 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18117 GLYPH 0 means don't dump glyphs.
18118 GLYPH 1 means dump glyphs in short form.
18119 GLYPH > 1 or omitted means dump glyphs in long form. */)
18120 (Lisp_Object row
, Lisp_Object glyphs
)
18122 struct frame
*sf
= SELECTED_FRAME ();
18123 struct glyph_matrix
*m
= XWINDOW (FVAR (sf
, tool_bar_window
))->current_matrix
;
18126 CHECK_NUMBER (row
);
18128 if (vpos
>= 0 && vpos
< m
->nrows
)
18129 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18130 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18135 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18136 doc
: /* Toggle tracing of redisplay.
18137 With ARG, turn tracing on if and only if ARG is positive. */)
18141 trace_redisplay_p
= !trace_redisplay_p
;
18144 arg
= Fprefix_numeric_value (arg
);
18145 trace_redisplay_p
= XINT (arg
) > 0;
18152 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18153 doc
: /* Like `format', but print result to stderr.
18154 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18155 (ptrdiff_t nargs
, Lisp_Object
*args
)
18157 Lisp_Object s
= Fformat (nargs
, args
);
18158 fprintf (stderr
, "%s", SDATA (s
));
18162 #endif /* GLYPH_DEBUG */
18166 /***********************************************************************
18167 Building Desired Matrix Rows
18168 ***********************************************************************/
18170 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18171 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18173 static struct glyph_row
*
18174 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18176 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18177 struct buffer
*buffer
= XBUFFER (WVAR (w
, buffer
));
18178 struct buffer
*old
= current_buffer
;
18179 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18180 int arrow_len
= SCHARS (overlay_arrow_string
);
18181 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18182 const unsigned char *p
;
18185 int n_glyphs_before
;
18187 set_buffer_temp (buffer
);
18188 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18189 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18190 SET_TEXT_POS (it
.position
, 0, 0);
18192 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18194 while (p
< arrow_end
)
18196 Lisp_Object face
, ilisp
;
18198 /* Get the next character. */
18200 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18203 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18204 if (! ASCII_CHAR_P (it
.c
))
18205 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18209 /* Get its face. */
18210 ilisp
= make_number (p
- arrow_string
);
18211 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18212 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18214 /* Compute its width, get its glyphs. */
18215 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18216 SET_TEXT_POS (it
.position
, -1, -1);
18217 PRODUCE_GLYPHS (&it
);
18219 /* If this character doesn't fit any more in the line, we have
18220 to remove some glyphs. */
18221 if (it
.current_x
> it
.last_visible_x
)
18223 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18228 set_buffer_temp (old
);
18229 return it
.glyph_row
;
18233 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18234 glyphs to insert is determined by produce_special_glyphs. */
18237 insert_left_trunc_glyphs (struct it
*it
)
18239 struct it truncate_it
;
18240 struct glyph
*from
, *end
, *to
, *toend
;
18242 eassert (!FRAME_WINDOW_P (it
->f
)
18243 || (!it
->glyph_row
->reversed_p
18244 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18245 || (it
->glyph_row
->reversed_p
18246 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18248 /* Get the truncation glyphs. */
18250 truncate_it
.current_x
= 0;
18251 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18252 truncate_it
.glyph_row
= &scratch_glyph_row
;
18253 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18254 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18255 truncate_it
.object
= make_number (0);
18256 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18258 /* Overwrite glyphs from IT with truncation glyphs. */
18259 if (!it
->glyph_row
->reversed_p
)
18261 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18263 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18264 end
= from
+ tused
;
18265 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18266 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18267 if (FRAME_WINDOW_P (it
->f
))
18269 /* On GUI frames, when variable-size fonts are displayed,
18270 the truncation glyphs may need more pixels than the row's
18271 glyphs they overwrite. We overwrite more glyphs to free
18272 enough screen real estate, and enlarge the stretch glyph
18273 on the right (see display_line), if there is one, to
18274 preserve the screen position of the truncation glyphs on
18277 struct glyph
*g
= to
;
18280 /* The first glyph could be partially visible, in which case
18281 it->glyph_row->x will be negative. But we want the left
18282 truncation glyphs to be aligned at the left margin of the
18283 window, so we override the x coordinate at which the row
18285 it
->glyph_row
->x
= 0;
18286 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18288 w
+= g
->pixel_width
;
18291 if (g
- to
- tused
> 0)
18293 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18294 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18296 used
= it
->glyph_row
->used
[TEXT_AREA
];
18297 if (it
->glyph_row
->truncated_on_right_p
18298 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18299 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18302 int extra
= w
- it
->truncation_pixel_width
;
18304 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18311 /* There may be padding glyphs left over. Overwrite them too. */
18312 if (!FRAME_WINDOW_P (it
->f
))
18314 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18316 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18323 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18327 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18329 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18330 that back to front. */
18331 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18332 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18333 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18334 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18335 if (FRAME_WINDOW_P (it
->f
))
18338 struct glyph
*g
= to
;
18340 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18342 w
+= g
->pixel_width
;
18345 if (to
- g
- tused
> 0)
18347 if (it
->glyph_row
->truncated_on_right_p
18348 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18349 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18351 int extra
= w
- it
->truncation_pixel_width
;
18353 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18357 while (from
>= end
&& to
>= toend
)
18359 if (!FRAME_WINDOW_P (it
->f
))
18361 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18364 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18365 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18366 while (from
>= end
&& to
>= toend
)
18372 /* Need to free some room before prepending additional
18374 int move_by
= from
- end
+ 1;
18375 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18376 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18378 for ( ; g
>= g0
; g
--)
18380 while (from
>= end
)
18382 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18387 /* Compute the hash code for ROW. */
18389 row_hash (struct glyph_row
*row
)
18392 unsigned hashval
= 0;
18394 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18395 for (k
= 0; k
< row
->used
[area
]; ++k
)
18396 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18397 + row
->glyphs
[area
][k
].u
.val
18398 + row
->glyphs
[area
][k
].face_id
18399 + row
->glyphs
[area
][k
].padding_p
18400 + (row
->glyphs
[area
][k
].type
<< 2));
18405 /* Compute the pixel height and width of IT->glyph_row.
18407 Most of the time, ascent and height of a display line will be equal
18408 to the max_ascent and max_height values of the display iterator
18409 structure. This is not the case if
18411 1. We hit ZV without displaying anything. In this case, max_ascent
18412 and max_height will be zero.
18414 2. We have some glyphs that don't contribute to the line height.
18415 (The glyph row flag contributes_to_line_height_p is for future
18416 pixmap extensions).
18418 The first case is easily covered by using default values because in
18419 these cases, the line height does not really matter, except that it
18420 must not be zero. */
18423 compute_line_metrics (struct it
*it
)
18425 struct glyph_row
*row
= it
->glyph_row
;
18427 if (FRAME_WINDOW_P (it
->f
))
18429 int i
, min_y
, max_y
;
18431 /* The line may consist of one space only, that was added to
18432 place the cursor on it. If so, the row's height hasn't been
18434 if (row
->height
== 0)
18436 if (it
->max_ascent
+ it
->max_descent
== 0)
18437 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18438 row
->ascent
= it
->max_ascent
;
18439 row
->height
= it
->max_ascent
+ it
->max_descent
;
18440 row
->phys_ascent
= it
->max_phys_ascent
;
18441 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18442 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18445 /* Compute the width of this line. */
18446 row
->pixel_width
= row
->x
;
18447 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18448 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18450 eassert (row
->pixel_width
>= 0);
18451 eassert (row
->ascent
>= 0 && row
->height
> 0);
18453 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18454 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18456 /* If first line's physical ascent is larger than its logical
18457 ascent, use the physical ascent, and make the row taller.
18458 This makes accented characters fully visible. */
18459 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18460 && row
->phys_ascent
> row
->ascent
)
18462 row
->height
+= row
->phys_ascent
- row
->ascent
;
18463 row
->ascent
= row
->phys_ascent
;
18466 /* Compute how much of the line is visible. */
18467 row
->visible_height
= row
->height
;
18469 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18470 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18472 if (row
->y
< min_y
)
18473 row
->visible_height
-= min_y
- row
->y
;
18474 if (row
->y
+ row
->height
> max_y
)
18475 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18479 row
->pixel_width
= row
->used
[TEXT_AREA
];
18480 if (row
->continued_p
)
18481 row
->pixel_width
-= it
->continuation_pixel_width
;
18482 else if (row
->truncated_on_right_p
)
18483 row
->pixel_width
-= it
->truncation_pixel_width
;
18484 row
->ascent
= row
->phys_ascent
= 0;
18485 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18486 row
->extra_line_spacing
= 0;
18489 /* Compute a hash code for this row. */
18490 row
->hash
= row_hash (row
);
18492 it
->max_ascent
= it
->max_descent
= 0;
18493 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18497 /* Append one space to the glyph row of iterator IT if doing a
18498 window-based redisplay. The space has the same face as
18499 IT->face_id. Value is non-zero if a space was added.
18501 This function is called to make sure that there is always one glyph
18502 at the end of a glyph row that the cursor can be set on under
18503 window-systems. (If there weren't such a glyph we would not know
18504 how wide and tall a box cursor should be displayed).
18506 At the same time this space let's a nicely handle clearing to the
18507 end of the line if the row ends in italic text. */
18510 append_space_for_newline (struct it
*it
, int default_face_p
)
18512 if (FRAME_WINDOW_P (it
->f
))
18514 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18516 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18517 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18519 /* Save some values that must not be changed.
18520 Must save IT->c and IT->len because otherwise
18521 ITERATOR_AT_END_P wouldn't work anymore after
18522 append_space_for_newline has been called. */
18523 enum display_element_type saved_what
= it
->what
;
18524 int saved_c
= it
->c
, saved_len
= it
->len
;
18525 int saved_char_to_display
= it
->char_to_display
;
18526 int saved_x
= it
->current_x
;
18527 int saved_face_id
= it
->face_id
;
18528 struct text_pos saved_pos
;
18529 Lisp_Object saved_object
;
18532 saved_object
= it
->object
;
18533 saved_pos
= it
->position
;
18535 it
->what
= IT_CHARACTER
;
18536 memset (&it
->position
, 0, sizeof it
->position
);
18537 it
->object
= make_number (0);
18538 it
->c
= it
->char_to_display
= ' ';
18541 /* If the default face was remapped, be sure to use the
18542 remapped face for the appended newline. */
18543 if (default_face_p
)
18544 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18545 else if (it
->face_before_selective_p
)
18546 it
->face_id
= it
->saved_face_id
;
18547 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18548 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18550 PRODUCE_GLYPHS (it
);
18552 it
->override_ascent
= -1;
18553 it
->constrain_row_ascent_descent_p
= 0;
18554 it
->current_x
= saved_x
;
18555 it
->object
= saved_object
;
18556 it
->position
= saved_pos
;
18557 it
->what
= saved_what
;
18558 it
->face_id
= saved_face_id
;
18559 it
->len
= saved_len
;
18561 it
->char_to_display
= saved_char_to_display
;
18570 /* Extend the face of the last glyph in the text area of IT->glyph_row
18571 to the end of the display line. Called from display_line. If the
18572 glyph row is empty, add a space glyph to it so that we know the
18573 face to draw. Set the glyph row flag fill_line_p. If the glyph
18574 row is R2L, prepend a stretch glyph to cover the empty space to the
18575 left of the leftmost glyph. */
18578 extend_face_to_end_of_line (struct it
*it
)
18580 struct face
*face
, *default_face
;
18581 struct frame
*f
= it
->f
;
18583 /* If line is already filled, do nothing. Non window-system frames
18584 get a grace of one more ``pixel'' because their characters are
18585 1-``pixel'' wide, so they hit the equality too early. This grace
18586 is needed only for R2L rows that are not continued, to produce
18587 one extra blank where we could display the cursor. */
18588 if (it
->current_x
>= it
->last_visible_x
18589 + (!FRAME_WINDOW_P (f
)
18590 && it
->glyph_row
->reversed_p
18591 && !it
->glyph_row
->continued_p
))
18594 /* The default face, possibly remapped. */
18595 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18597 /* Face extension extends the background and box of IT->face_id
18598 to the end of the line. If the background equals the background
18599 of the frame, we don't have to do anything. */
18600 if (it
->face_before_selective_p
)
18601 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18603 face
= FACE_FROM_ID (f
, it
->face_id
);
18605 if (FRAME_WINDOW_P (f
)
18606 && it
->glyph_row
->displays_text_p
18607 && face
->box
== FACE_NO_BOX
18608 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18610 && !it
->glyph_row
->reversed_p
)
18613 /* Set the glyph row flag indicating that the face of the last glyph
18614 in the text area has to be drawn to the end of the text area. */
18615 it
->glyph_row
->fill_line_p
= 1;
18617 /* If current character of IT is not ASCII, make sure we have the
18618 ASCII face. This will be automatically undone the next time
18619 get_next_display_element returns a multibyte character. Note
18620 that the character will always be single byte in unibyte
18622 if (!ASCII_CHAR_P (it
->c
))
18624 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18627 if (FRAME_WINDOW_P (f
))
18629 /* If the row is empty, add a space with the current face of IT,
18630 so that we know which face to draw. */
18631 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18633 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18634 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18635 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18637 #ifdef HAVE_WINDOW_SYSTEM
18638 if (it
->glyph_row
->reversed_p
)
18640 /* Prepend a stretch glyph to the row, such that the
18641 rightmost glyph will be drawn flushed all the way to the
18642 right margin of the window. The stretch glyph that will
18643 occupy the empty space, if any, to the left of the
18645 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18646 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18647 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18649 int row_width
, stretch_ascent
, stretch_width
;
18650 struct text_pos saved_pos
;
18651 int saved_face_id
, saved_avoid_cursor
;
18653 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18654 row_width
+= g
->pixel_width
;
18655 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18656 if (stretch_width
> 0)
18659 (((it
->ascent
+ it
->descent
)
18660 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18661 saved_pos
= it
->position
;
18662 memset (&it
->position
, 0, sizeof it
->position
);
18663 saved_avoid_cursor
= it
->avoid_cursor_p
;
18664 it
->avoid_cursor_p
= 1;
18665 saved_face_id
= it
->face_id
;
18666 /* The last row's stretch glyph should get the default
18667 face, to avoid painting the rest of the window with
18668 the region face, if the region ends at ZV. */
18669 if (it
->glyph_row
->ends_at_zv_p
)
18670 it
->face_id
= default_face
->id
;
18672 it
->face_id
= face
->id
;
18673 append_stretch_glyph (it
, make_number (0), stretch_width
,
18674 it
->ascent
+ it
->descent
, stretch_ascent
);
18675 it
->position
= saved_pos
;
18676 it
->avoid_cursor_p
= saved_avoid_cursor
;
18677 it
->face_id
= saved_face_id
;
18680 #endif /* HAVE_WINDOW_SYSTEM */
18684 /* Save some values that must not be changed. */
18685 int saved_x
= it
->current_x
;
18686 struct text_pos saved_pos
;
18687 Lisp_Object saved_object
;
18688 enum display_element_type saved_what
= it
->what
;
18689 int saved_face_id
= it
->face_id
;
18691 saved_object
= it
->object
;
18692 saved_pos
= it
->position
;
18694 it
->what
= IT_CHARACTER
;
18695 memset (&it
->position
, 0, sizeof it
->position
);
18696 it
->object
= make_number (0);
18697 it
->c
= it
->char_to_display
= ' ';
18699 /* The last row's blank glyphs should get the default face, to
18700 avoid painting the rest of the window with the region face,
18701 if the region ends at ZV. */
18702 if (it
->glyph_row
->ends_at_zv_p
)
18703 it
->face_id
= default_face
->id
;
18705 it
->face_id
= face
->id
;
18707 PRODUCE_GLYPHS (it
);
18709 while (it
->current_x
<= it
->last_visible_x
)
18710 PRODUCE_GLYPHS (it
);
18712 /* Don't count these blanks really. It would let us insert a left
18713 truncation glyph below and make us set the cursor on them, maybe. */
18714 it
->current_x
= saved_x
;
18715 it
->object
= saved_object
;
18716 it
->position
= saved_pos
;
18717 it
->what
= saved_what
;
18718 it
->face_id
= saved_face_id
;
18723 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18724 trailing whitespace. */
18727 trailing_whitespace_p (ptrdiff_t charpos
)
18729 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18732 while (bytepos
< ZV_BYTE
18733 && (c
= FETCH_CHAR (bytepos
),
18734 c
== ' ' || c
== '\t'))
18737 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18739 if (bytepos
!= PT_BYTE
)
18746 /* Highlight trailing whitespace, if any, in ROW. */
18749 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18751 int used
= row
->used
[TEXT_AREA
];
18755 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18756 struct glyph
*glyph
= start
+ used
- 1;
18758 if (row
->reversed_p
)
18760 /* Right-to-left rows need to be processed in the opposite
18761 direction, so swap the edge pointers. */
18763 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18766 /* Skip over glyphs inserted to display the cursor at the
18767 end of a line, for extending the face of the last glyph
18768 to the end of the line on terminals, and for truncation
18769 and continuation glyphs. */
18770 if (!row
->reversed_p
)
18772 while (glyph
>= start
18773 && glyph
->type
== CHAR_GLYPH
18774 && INTEGERP (glyph
->object
))
18779 while (glyph
<= start
18780 && glyph
->type
== CHAR_GLYPH
18781 && INTEGERP (glyph
->object
))
18785 /* If last glyph is a space or stretch, and it's trailing
18786 whitespace, set the face of all trailing whitespace glyphs in
18787 IT->glyph_row to `trailing-whitespace'. */
18788 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18789 && BUFFERP (glyph
->object
)
18790 && (glyph
->type
== STRETCH_GLYPH
18791 || (glyph
->type
== CHAR_GLYPH
18792 && glyph
->u
.ch
== ' '))
18793 && trailing_whitespace_p (glyph
->charpos
))
18795 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18799 if (!row
->reversed_p
)
18801 while (glyph
>= start
18802 && BUFFERP (glyph
->object
)
18803 && (glyph
->type
== STRETCH_GLYPH
18804 || (glyph
->type
== CHAR_GLYPH
18805 && glyph
->u
.ch
== ' ')))
18806 (glyph
--)->face_id
= face_id
;
18810 while (glyph
<= start
18811 && BUFFERP (glyph
->object
)
18812 && (glyph
->type
== STRETCH_GLYPH
18813 || (glyph
->type
== CHAR_GLYPH
18814 && glyph
->u
.ch
== ' ')))
18815 (glyph
++)->face_id
= face_id
;
18822 /* Value is non-zero if glyph row ROW should be
18823 used to hold the cursor. */
18826 cursor_row_p (struct glyph_row
*row
)
18830 if (PT
== CHARPOS (row
->end
.pos
)
18831 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18833 /* Suppose the row ends on a string.
18834 Unless the row is continued, that means it ends on a newline
18835 in the string. If it's anything other than a display string
18836 (e.g., a before-string from an overlay), we don't want the
18837 cursor there. (This heuristic seems to give the optimal
18838 behavior for the various types of multi-line strings.)
18839 One exception: if the string has `cursor' property on one of
18840 its characters, we _do_ want the cursor there. */
18841 if (CHARPOS (row
->end
.string_pos
) >= 0)
18843 if (row
->continued_p
)
18847 /* Check for `display' property. */
18848 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18849 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18850 struct glyph
*glyph
;
18853 for (glyph
= end
; glyph
>= beg
; --glyph
)
18854 if (STRINGP (glyph
->object
))
18857 = Fget_char_property (make_number (PT
),
18861 && display_prop_string_p (prop
, glyph
->object
));
18862 /* If there's a `cursor' property on one of the
18863 string's characters, this row is a cursor row,
18864 even though this is not a display string. */
18867 Lisp_Object s
= glyph
->object
;
18869 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18871 ptrdiff_t gpos
= glyph
->charpos
;
18873 if (!NILP (Fget_char_property (make_number (gpos
),
18885 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18887 /* If the row ends in middle of a real character,
18888 and the line is continued, we want the cursor here.
18889 That's because CHARPOS (ROW->end.pos) would equal
18890 PT if PT is before the character. */
18891 if (!row
->ends_in_ellipsis_p
)
18892 result
= row
->continued_p
;
18894 /* If the row ends in an ellipsis, then
18895 CHARPOS (ROW->end.pos) will equal point after the
18896 invisible text. We want that position to be displayed
18897 after the ellipsis. */
18900 /* If the row ends at ZV, display the cursor at the end of that
18901 row instead of at the start of the row below. */
18902 else if (row
->ends_at_zv_p
)
18913 /* Push the property PROP so that it will be rendered at the current
18914 position in IT. Return 1 if PROP was successfully pushed, 0
18915 otherwise. Called from handle_line_prefix to handle the
18916 `line-prefix' and `wrap-prefix' properties. */
18919 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18921 struct text_pos pos
=
18922 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18924 eassert (it
->method
== GET_FROM_BUFFER
18925 || it
->method
== GET_FROM_DISPLAY_VECTOR
18926 || it
->method
== GET_FROM_STRING
);
18928 /* We need to save the current buffer/string position, so it will be
18929 restored by pop_it, because iterate_out_of_display_property
18930 depends on that being set correctly, but some situations leave
18931 it->position not yet set when this function is called. */
18932 push_it (it
, &pos
);
18934 if (STRINGP (prop
))
18936 if (SCHARS (prop
) == 0)
18943 it
->string_from_prefix_prop_p
= 1;
18944 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18945 it
->current
.overlay_string_index
= -1;
18946 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18947 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18948 it
->method
= GET_FROM_STRING
;
18949 it
->stop_charpos
= 0;
18951 it
->base_level_stop
= 0;
18953 /* Force paragraph direction to be that of the parent
18955 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18956 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18958 it
->paragraph_embedding
= L2R
;
18960 /* Set up the bidi iterator for this display string. */
18963 it
->bidi_it
.string
.lstring
= it
->string
;
18964 it
->bidi_it
.string
.s
= NULL
;
18965 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18966 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18967 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18968 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18969 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18972 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18974 it
->method
= GET_FROM_STRETCH
;
18977 #ifdef HAVE_WINDOW_SYSTEM
18978 else if (IMAGEP (prop
))
18980 it
->what
= IT_IMAGE
;
18981 it
->image_id
= lookup_image (it
->f
, prop
);
18982 it
->method
= GET_FROM_IMAGE
;
18984 #endif /* HAVE_WINDOW_SYSTEM */
18987 pop_it (it
); /* bogus display property, give up */
18994 /* Return the character-property PROP at the current position in IT. */
18997 get_it_property (struct it
*it
, Lisp_Object prop
)
18999 Lisp_Object position
;
19001 if (STRINGP (it
->object
))
19002 position
= make_number (IT_STRING_CHARPOS (*it
));
19003 else if (BUFFERP (it
->object
))
19004 position
= make_number (IT_CHARPOS (*it
));
19008 return Fget_char_property (position
, prop
, it
->object
);
19011 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19014 handle_line_prefix (struct it
*it
)
19016 Lisp_Object prefix
;
19018 if (it
->continuation_lines_width
> 0)
19020 prefix
= get_it_property (it
, Qwrap_prefix
);
19022 prefix
= Vwrap_prefix
;
19026 prefix
= get_it_property (it
, Qline_prefix
);
19028 prefix
= Vline_prefix
;
19030 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19032 /* If the prefix is wider than the window, and we try to wrap
19033 it, it would acquire its own wrap prefix, and so on till the
19034 iterator stack overflows. So, don't wrap the prefix. */
19035 it
->line_wrap
= TRUNCATE
;
19036 it
->avoid_cursor_p
= 1;
19042 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19043 only for R2L lines from display_line and display_string, when they
19044 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19045 the line/string needs to be continued on the next glyph row. */
19047 unproduce_glyphs (struct it
*it
, int n
)
19049 struct glyph
*glyph
, *end
;
19051 eassert (it
->glyph_row
);
19052 eassert (it
->glyph_row
->reversed_p
);
19053 eassert (it
->area
== TEXT_AREA
);
19054 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19056 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19057 n
= it
->glyph_row
->used
[TEXT_AREA
];
19058 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19059 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19060 for ( ; glyph
< end
; glyph
++)
19061 glyph
[-n
] = *glyph
;
19064 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19065 and ROW->maxpos. */
19067 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19068 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19069 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19071 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19072 lines' rows is implemented for bidi-reordered rows. */
19074 /* ROW->minpos is the value of min_pos, the minimal buffer position
19075 we have in ROW, or ROW->start.pos if that is smaller. */
19076 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19077 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19079 /* We didn't find buffer positions smaller than ROW->start, or
19080 didn't find _any_ valid buffer positions in any of the glyphs,
19081 so we must trust the iterator's computed positions. */
19082 row
->minpos
= row
->start
.pos
;
19085 max_pos
= CHARPOS (it
->current
.pos
);
19086 max_bpos
= BYTEPOS (it
->current
.pos
);
19089 /* Here are the various use-cases for ending the row, and the
19090 corresponding values for ROW->maxpos:
19092 Line ends in a newline from buffer eol_pos + 1
19093 Line is continued from buffer max_pos + 1
19094 Line is truncated on right it->current.pos
19095 Line ends in a newline from string max_pos + 1(*)
19096 (*) + 1 only when line ends in a forward scan
19097 Line is continued from string max_pos
19098 Line is continued from display vector max_pos
19099 Line is entirely from a string min_pos == max_pos
19100 Line is entirely from a display vector min_pos == max_pos
19101 Line that ends at ZV ZV
19103 If you discover other use-cases, please add them here as
19105 if (row
->ends_at_zv_p
)
19106 row
->maxpos
= it
->current
.pos
;
19107 else if (row
->used
[TEXT_AREA
])
19109 int seen_this_string
= 0;
19110 struct glyph_row
*r1
= row
- 1;
19112 /* Did we see the same display string on the previous row? */
19113 if (STRINGP (it
->object
)
19114 /* this is not the first row */
19115 && row
> it
->w
->desired_matrix
->rows
19116 /* previous row is not the header line */
19117 && !r1
->mode_line_p
19118 /* previous row also ends in a newline from a string */
19119 && r1
->ends_in_newline_from_string_p
)
19121 struct glyph
*start
, *end
;
19123 /* Search for the last glyph of the previous row that came
19124 from buffer or string. Depending on whether the row is
19125 L2R or R2L, we need to process it front to back or the
19126 other way round. */
19127 if (!r1
->reversed_p
)
19129 start
= r1
->glyphs
[TEXT_AREA
];
19130 end
= start
+ r1
->used
[TEXT_AREA
];
19131 /* Glyphs inserted by redisplay have an integer (zero)
19132 as their object. */
19134 && INTEGERP ((end
- 1)->object
)
19135 && (end
- 1)->charpos
<= 0)
19139 if (EQ ((end
- 1)->object
, it
->object
))
19140 seen_this_string
= 1;
19143 /* If all the glyphs of the previous row were inserted
19144 by redisplay, it means the previous row was
19145 produced from a single newline, which is only
19146 possible if that newline came from the same string
19147 as the one which produced this ROW. */
19148 seen_this_string
= 1;
19152 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19153 start
= end
+ r1
->used
[TEXT_AREA
];
19155 && INTEGERP ((end
+ 1)->object
)
19156 && (end
+ 1)->charpos
<= 0)
19160 if (EQ ((end
+ 1)->object
, it
->object
))
19161 seen_this_string
= 1;
19164 seen_this_string
= 1;
19167 /* Take note of each display string that covers a newline only
19168 once, the first time we see it. This is for when a display
19169 string includes more than one newline in it. */
19170 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19172 /* If we were scanning the buffer forward when we displayed
19173 the string, we want to account for at least one buffer
19174 position that belongs to this row (position covered by
19175 the display string), so that cursor positioning will
19176 consider this row as a candidate when point is at the end
19177 of the visual line represented by this row. This is not
19178 required when scanning back, because max_pos will already
19179 have a much larger value. */
19180 if (CHARPOS (row
->end
.pos
) > max_pos
)
19181 INC_BOTH (max_pos
, max_bpos
);
19182 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19184 else if (CHARPOS (it
->eol_pos
) > 0)
19185 SET_TEXT_POS (row
->maxpos
,
19186 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19187 else if (row
->continued_p
)
19189 /* If max_pos is different from IT's current position, it
19190 means IT->method does not belong to the display element
19191 at max_pos. However, it also means that the display
19192 element at max_pos was displayed in its entirety on this
19193 line, which is equivalent to saying that the next line
19194 starts at the next buffer position. */
19195 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19196 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19199 INC_BOTH (max_pos
, max_bpos
);
19200 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19203 else if (row
->truncated_on_right_p
)
19204 /* display_line already called reseat_at_next_visible_line_start,
19205 which puts the iterator at the beginning of the next line, in
19206 the logical order. */
19207 row
->maxpos
= it
->current
.pos
;
19208 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19209 /* A line that is entirely from a string/image/stretch... */
19210 row
->maxpos
= row
->minpos
;
19215 row
->maxpos
= it
->current
.pos
;
19218 /* Construct the glyph row IT->glyph_row in the desired matrix of
19219 IT->w from text at the current position of IT. See dispextern.h
19220 for an overview of struct it. Value is non-zero if
19221 IT->glyph_row displays text, as opposed to a line displaying ZV
19225 display_line (struct it
*it
)
19227 struct glyph_row
*row
= it
->glyph_row
;
19228 Lisp_Object overlay_arrow_string
;
19230 void *wrap_data
= NULL
;
19231 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19232 int wrap_row_used
= -1;
19233 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19234 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19235 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19236 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19237 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19239 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19240 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19242 /* We always start displaying at hpos zero even if hscrolled. */
19243 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19245 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19246 >= it
->w
->desired_matrix
->nrows
)
19248 it
->w
->nrows_scale_factor
++;
19249 fonts_changed_p
= 1;
19253 /* Is IT->w showing the region? */
19254 WVAR (it
->w
, region_showing
) = it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
19256 /* Clear the result glyph row and enable it. */
19257 prepare_desired_row (row
);
19259 row
->y
= it
->current_y
;
19260 row
->start
= it
->start
;
19261 row
->continuation_lines_width
= it
->continuation_lines_width
;
19262 row
->displays_text_p
= 1;
19263 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19264 it
->starts_in_middle_of_char_p
= 0;
19266 /* Arrange the overlays nicely for our purposes. Usually, we call
19267 display_line on only one line at a time, in which case this
19268 can't really hurt too much, or we call it on lines which appear
19269 one after another in the buffer, in which case all calls to
19270 recenter_overlay_lists but the first will be pretty cheap. */
19271 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19273 /* Move over display elements that are not visible because we are
19274 hscrolled. This may stop at an x-position < IT->first_visible_x
19275 if the first glyph is partially visible or if we hit a line end. */
19276 if (it
->current_x
< it
->first_visible_x
)
19278 enum move_it_result move_result
;
19280 this_line_min_pos
= row
->start
.pos
;
19281 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19282 MOVE_TO_POS
| MOVE_TO_X
);
19283 /* If we are under a large hscroll, move_it_in_display_line_to
19284 could hit the end of the line without reaching
19285 it->first_visible_x. Pretend that we did reach it. This is
19286 especially important on a TTY, where we will call
19287 extend_face_to_end_of_line, which needs to know how many
19288 blank glyphs to produce. */
19289 if (it
->current_x
< it
->first_visible_x
19290 && (move_result
== MOVE_NEWLINE_OR_CR
19291 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19292 it
->current_x
= it
->first_visible_x
;
19294 /* Record the smallest positions seen while we moved over
19295 display elements that are not visible. This is needed by
19296 redisplay_internal for optimizing the case where the cursor
19297 stays inside the same line. The rest of this function only
19298 considers positions that are actually displayed, so
19299 RECORD_MAX_MIN_POS will not otherwise record positions that
19300 are hscrolled to the left of the left edge of the window. */
19301 min_pos
= CHARPOS (this_line_min_pos
);
19302 min_bpos
= BYTEPOS (this_line_min_pos
);
19306 /* We only do this when not calling `move_it_in_display_line_to'
19307 above, because move_it_in_display_line_to calls
19308 handle_line_prefix itself. */
19309 handle_line_prefix (it
);
19312 /* Get the initial row height. This is either the height of the
19313 text hscrolled, if there is any, or zero. */
19314 row
->ascent
= it
->max_ascent
;
19315 row
->height
= it
->max_ascent
+ it
->max_descent
;
19316 row
->phys_ascent
= it
->max_phys_ascent
;
19317 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19318 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19320 /* Utility macro to record max and min buffer positions seen until now. */
19321 #define RECORD_MAX_MIN_POS(IT) \
19324 int composition_p = !STRINGP ((IT)->string) \
19325 && ((IT)->what == IT_COMPOSITION); \
19326 ptrdiff_t current_pos = \
19327 composition_p ? (IT)->cmp_it.charpos \
19328 : IT_CHARPOS (*(IT)); \
19329 ptrdiff_t current_bpos = \
19330 composition_p ? CHAR_TO_BYTE (current_pos) \
19331 : IT_BYTEPOS (*(IT)); \
19332 if (current_pos < min_pos) \
19334 min_pos = current_pos; \
19335 min_bpos = current_bpos; \
19337 if (IT_CHARPOS (*it) > max_pos) \
19339 max_pos = IT_CHARPOS (*it); \
19340 max_bpos = IT_BYTEPOS (*it); \
19345 /* Loop generating characters. The loop is left with IT on the next
19346 character to display. */
19349 int n_glyphs_before
, hpos_before
, x_before
;
19351 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19353 /* Retrieve the next thing to display. Value is zero if end of
19355 if (!get_next_display_element (it
))
19357 /* Maybe add a space at the end of this line that is used to
19358 display the cursor there under X. Set the charpos of the
19359 first glyph of blank lines not corresponding to any text
19361 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19362 row
->exact_window_width_line_p
= 1;
19363 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19364 || row
->used
[TEXT_AREA
] == 0)
19366 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19367 row
->displays_text_p
= 0;
19369 if (!NILP (BVAR (XBUFFER (WVAR (it
->w
, buffer
)), indicate_empty_lines
))
19370 && (!MINI_WINDOW_P (it
->w
)
19371 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19372 row
->indicate_empty_line_p
= 1;
19375 it
->continuation_lines_width
= 0;
19376 row
->ends_at_zv_p
= 1;
19377 /* A row that displays right-to-left text must always have
19378 its last face extended all the way to the end of line,
19379 even if this row ends in ZV, because we still write to
19380 the screen left to right. We also need to extend the
19381 last face if the default face is remapped to some
19382 different face, otherwise the functions that clear
19383 portions of the screen will clear with the default face's
19384 background color. */
19385 if (row
->reversed_p
19386 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19387 extend_face_to_end_of_line (it
);
19391 /* Now, get the metrics of what we want to display. This also
19392 generates glyphs in `row' (which is IT->glyph_row). */
19393 n_glyphs_before
= row
->used
[TEXT_AREA
];
19396 /* Remember the line height so far in case the next element doesn't
19397 fit on the line. */
19398 if (it
->line_wrap
!= TRUNCATE
)
19400 ascent
= it
->max_ascent
;
19401 descent
= it
->max_descent
;
19402 phys_ascent
= it
->max_phys_ascent
;
19403 phys_descent
= it
->max_phys_descent
;
19405 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19407 if (IT_DISPLAYING_WHITESPACE (it
))
19411 SAVE_IT (wrap_it
, *it
, wrap_data
);
19413 wrap_row_used
= row
->used
[TEXT_AREA
];
19414 wrap_row_ascent
= row
->ascent
;
19415 wrap_row_height
= row
->height
;
19416 wrap_row_phys_ascent
= row
->phys_ascent
;
19417 wrap_row_phys_height
= row
->phys_height
;
19418 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19419 wrap_row_min_pos
= min_pos
;
19420 wrap_row_min_bpos
= min_bpos
;
19421 wrap_row_max_pos
= max_pos
;
19422 wrap_row_max_bpos
= max_bpos
;
19428 PRODUCE_GLYPHS (it
);
19430 /* If this display element was in marginal areas, continue with
19432 if (it
->area
!= TEXT_AREA
)
19434 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19435 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19436 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19437 row
->phys_height
= max (row
->phys_height
,
19438 it
->max_phys_ascent
+ it
->max_phys_descent
);
19439 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19440 it
->max_extra_line_spacing
);
19441 set_iterator_to_next (it
, 1);
19445 /* Does the display element fit on the line? If we truncate
19446 lines, we should draw past the right edge of the window. If
19447 we don't truncate, we want to stop so that we can display the
19448 continuation glyph before the right margin. If lines are
19449 continued, there are two possible strategies for characters
19450 resulting in more than 1 glyph (e.g. tabs): Display as many
19451 glyphs as possible in this line and leave the rest for the
19452 continuation line, or display the whole element in the next
19453 line. Original redisplay did the former, so we do it also. */
19454 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19455 hpos_before
= it
->hpos
;
19458 if (/* Not a newline. */
19460 /* Glyphs produced fit entirely in the line. */
19461 && it
->current_x
< it
->last_visible_x
)
19463 it
->hpos
+= nglyphs
;
19464 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19465 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19466 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19467 row
->phys_height
= max (row
->phys_height
,
19468 it
->max_phys_ascent
+ it
->max_phys_descent
);
19469 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19470 it
->max_extra_line_spacing
);
19471 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19472 row
->x
= x
- it
->first_visible_x
;
19473 /* Record the maximum and minimum buffer positions seen so
19474 far in glyphs that will be displayed by this row. */
19476 RECORD_MAX_MIN_POS (it
);
19481 struct glyph
*glyph
;
19483 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19485 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19486 new_x
= x
+ glyph
->pixel_width
;
19488 if (/* Lines are continued. */
19489 it
->line_wrap
!= TRUNCATE
19490 && (/* Glyph doesn't fit on the line. */
19491 new_x
> it
->last_visible_x
19492 /* Or it fits exactly on a window system frame. */
19493 || (new_x
== it
->last_visible_x
19494 && FRAME_WINDOW_P (it
->f
)
19495 && (row
->reversed_p
19496 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19497 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19499 /* End of a continued line. */
19502 || (new_x
== it
->last_visible_x
19503 && FRAME_WINDOW_P (it
->f
)
19504 && (row
->reversed_p
19505 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19506 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19508 /* Current glyph is the only one on the line or
19509 fits exactly on the line. We must continue
19510 the line because we can't draw the cursor
19511 after the glyph. */
19512 row
->continued_p
= 1;
19513 it
->current_x
= new_x
;
19514 it
->continuation_lines_width
+= new_x
;
19516 if (i
== nglyphs
- 1)
19518 /* If line-wrap is on, check if a previous
19519 wrap point was found. */
19520 if (wrap_row_used
> 0
19521 /* Even if there is a previous wrap
19522 point, continue the line here as
19523 usual, if (i) the previous character
19524 was a space or tab AND (ii) the
19525 current character is not. */
19527 || IT_DISPLAYING_WHITESPACE (it
)))
19530 /* Record the maximum and minimum buffer
19531 positions seen so far in glyphs that will be
19532 displayed by this row. */
19534 RECORD_MAX_MIN_POS (it
);
19535 set_iterator_to_next (it
, 1);
19536 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19538 if (!get_next_display_element (it
))
19540 row
->exact_window_width_line_p
= 1;
19541 it
->continuation_lines_width
= 0;
19542 row
->continued_p
= 0;
19543 row
->ends_at_zv_p
= 1;
19545 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19547 row
->continued_p
= 0;
19548 row
->exact_window_width_line_p
= 1;
19552 else if (it
->bidi_p
)
19553 RECORD_MAX_MIN_POS (it
);
19555 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19556 && !FRAME_WINDOW_P (it
->f
))
19558 /* A padding glyph that doesn't fit on this line.
19559 This means the whole character doesn't fit
19561 if (row
->reversed_p
)
19562 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19563 - n_glyphs_before
);
19564 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19566 /* Fill the rest of the row with continuation
19567 glyphs like in 20.x. */
19568 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19569 < row
->glyphs
[1 + TEXT_AREA
])
19570 produce_special_glyphs (it
, IT_CONTINUATION
);
19572 row
->continued_p
= 1;
19573 it
->current_x
= x_before
;
19574 it
->continuation_lines_width
+= x_before
;
19576 /* Restore the height to what it was before the
19577 element not fitting on the line. */
19578 it
->max_ascent
= ascent
;
19579 it
->max_descent
= descent
;
19580 it
->max_phys_ascent
= phys_ascent
;
19581 it
->max_phys_descent
= phys_descent
;
19583 else if (wrap_row_used
> 0)
19586 if (row
->reversed_p
)
19587 unproduce_glyphs (it
,
19588 row
->used
[TEXT_AREA
] - wrap_row_used
);
19589 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19590 it
->continuation_lines_width
+= wrap_x
;
19591 row
->used
[TEXT_AREA
] = wrap_row_used
;
19592 row
->ascent
= wrap_row_ascent
;
19593 row
->height
= wrap_row_height
;
19594 row
->phys_ascent
= wrap_row_phys_ascent
;
19595 row
->phys_height
= wrap_row_phys_height
;
19596 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19597 min_pos
= wrap_row_min_pos
;
19598 min_bpos
= wrap_row_min_bpos
;
19599 max_pos
= wrap_row_max_pos
;
19600 max_bpos
= wrap_row_max_bpos
;
19601 row
->continued_p
= 1;
19602 row
->ends_at_zv_p
= 0;
19603 row
->exact_window_width_line_p
= 0;
19604 it
->continuation_lines_width
+= x
;
19606 /* Make sure that a non-default face is extended
19607 up to the right margin of the window. */
19608 extend_face_to_end_of_line (it
);
19610 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19612 /* A TAB that extends past the right edge of the
19613 window. This produces a single glyph on
19614 window system frames. We leave the glyph in
19615 this row and let it fill the row, but don't
19616 consume the TAB. */
19617 if ((row
->reversed_p
19618 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19619 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19620 produce_special_glyphs (it
, IT_CONTINUATION
);
19621 it
->continuation_lines_width
+= it
->last_visible_x
;
19622 row
->ends_in_middle_of_char_p
= 1;
19623 row
->continued_p
= 1;
19624 glyph
->pixel_width
= it
->last_visible_x
- x
;
19625 it
->starts_in_middle_of_char_p
= 1;
19629 /* Something other than a TAB that draws past
19630 the right edge of the window. Restore
19631 positions to values before the element. */
19632 if (row
->reversed_p
)
19633 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19634 - (n_glyphs_before
+ i
));
19635 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19637 /* Display continuation glyphs. */
19638 it
->current_x
= x_before
;
19639 it
->continuation_lines_width
+= x
;
19640 if (!FRAME_WINDOW_P (it
->f
)
19641 || (row
->reversed_p
19642 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19643 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19644 produce_special_glyphs (it
, IT_CONTINUATION
);
19645 row
->continued_p
= 1;
19647 extend_face_to_end_of_line (it
);
19649 if (nglyphs
> 1 && i
> 0)
19651 row
->ends_in_middle_of_char_p
= 1;
19652 it
->starts_in_middle_of_char_p
= 1;
19655 /* Restore the height to what it was before the
19656 element not fitting on the line. */
19657 it
->max_ascent
= ascent
;
19658 it
->max_descent
= descent
;
19659 it
->max_phys_ascent
= phys_ascent
;
19660 it
->max_phys_descent
= phys_descent
;
19665 else if (new_x
> it
->first_visible_x
)
19667 /* Increment number of glyphs actually displayed. */
19670 /* Record the maximum and minimum buffer positions
19671 seen so far in glyphs that will be displayed by
19674 RECORD_MAX_MIN_POS (it
);
19676 if (x
< it
->first_visible_x
)
19677 /* Glyph is partially visible, i.e. row starts at
19678 negative X position. */
19679 row
->x
= x
- it
->first_visible_x
;
19683 /* Glyph is completely off the left margin of the
19684 window. This should not happen because of the
19685 move_it_in_display_line at the start of this
19686 function, unless the text display area of the
19687 window is empty. */
19688 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19691 /* Even if this display element produced no glyphs at all,
19692 we want to record its position. */
19693 if (it
->bidi_p
&& nglyphs
== 0)
19694 RECORD_MAX_MIN_POS (it
);
19696 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19697 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19698 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19699 row
->phys_height
= max (row
->phys_height
,
19700 it
->max_phys_ascent
+ it
->max_phys_descent
);
19701 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19702 it
->max_extra_line_spacing
);
19704 /* End of this display line if row is continued. */
19705 if (row
->continued_p
|| row
->ends_at_zv_p
)
19710 /* Is this a line end? If yes, we're also done, after making
19711 sure that a non-default face is extended up to the right
19712 margin of the window. */
19713 if (ITERATOR_AT_END_OF_LINE_P (it
))
19715 int used_before
= row
->used
[TEXT_AREA
];
19717 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19719 /* Add a space at the end of the line that is used to
19720 display the cursor there. */
19721 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19722 append_space_for_newline (it
, 0);
19724 /* Extend the face to the end of the line. */
19725 extend_face_to_end_of_line (it
);
19727 /* Make sure we have the position. */
19728 if (used_before
== 0)
19729 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19731 /* Record the position of the newline, for use in
19733 it
->eol_pos
= it
->current
.pos
;
19735 /* Consume the line end. This skips over invisible lines. */
19736 set_iterator_to_next (it
, 1);
19737 it
->continuation_lines_width
= 0;
19741 /* Proceed with next display element. Note that this skips
19742 over lines invisible because of selective display. */
19743 set_iterator_to_next (it
, 1);
19745 /* If we truncate lines, we are done when the last displayed
19746 glyphs reach past the right margin of the window. */
19747 if (it
->line_wrap
== TRUNCATE
19748 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19749 ? (it
->current_x
>= it
->last_visible_x
)
19750 : (it
->current_x
> it
->last_visible_x
)))
19752 /* Maybe add truncation glyphs. */
19753 if (!FRAME_WINDOW_P (it
->f
)
19754 || (row
->reversed_p
19755 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19756 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19760 if (!row
->reversed_p
)
19762 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19763 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19768 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19769 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19771 /* Remove any padding glyphs at the front of ROW, to
19772 make room for the truncation glyphs we will be
19773 adding below. The loop below always inserts at
19774 least one truncation glyph, so also remove the
19775 last glyph added to ROW. */
19776 unproduce_glyphs (it
, i
+ 1);
19777 /* Adjust i for the loop below. */
19778 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19781 it
->current_x
= x_before
;
19782 if (!FRAME_WINDOW_P (it
->f
))
19784 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19786 row
->used
[TEXT_AREA
] = i
;
19787 produce_special_glyphs (it
, IT_TRUNCATION
);
19792 row
->used
[TEXT_AREA
] = i
;
19793 produce_special_glyphs (it
, IT_TRUNCATION
);
19796 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19798 /* Don't truncate if we can overflow newline into fringe. */
19799 if (!get_next_display_element (it
))
19801 it
->continuation_lines_width
= 0;
19802 row
->ends_at_zv_p
= 1;
19803 row
->exact_window_width_line_p
= 1;
19806 if (ITERATOR_AT_END_OF_LINE_P (it
))
19808 row
->exact_window_width_line_p
= 1;
19809 goto at_end_of_line
;
19811 it
->current_x
= x_before
;
19814 row
->truncated_on_right_p
= 1;
19815 it
->continuation_lines_width
= 0;
19816 reseat_at_next_visible_line_start (it
, 0);
19817 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19818 it
->hpos
= hpos_before
;
19824 bidi_unshelve_cache (wrap_data
, 1);
19826 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19827 at the left window margin. */
19828 if (it
->first_visible_x
19829 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19831 if (!FRAME_WINDOW_P (it
->f
)
19832 || (row
->reversed_p
19833 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19834 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19835 insert_left_trunc_glyphs (it
);
19836 row
->truncated_on_left_p
= 1;
19839 /* Remember the position at which this line ends.
19841 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19842 cannot be before the call to find_row_edges below, since that is
19843 where these positions are determined. */
19844 row
->end
= it
->current
;
19847 row
->minpos
= row
->start
.pos
;
19848 row
->maxpos
= row
->end
.pos
;
19852 /* ROW->minpos and ROW->maxpos must be the smallest and
19853 `1 + the largest' buffer positions in ROW. But if ROW was
19854 bidi-reordered, these two positions can be anywhere in the
19855 row, so we must determine them now. */
19856 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19859 /* If the start of this line is the overlay arrow-position, then
19860 mark this glyph row as the one containing the overlay arrow.
19861 This is clearly a mess with variable size fonts. It would be
19862 better to let it be displayed like cursors under X. */
19863 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19864 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19865 !NILP (overlay_arrow_string
)))
19867 /* Overlay arrow in window redisplay is a fringe bitmap. */
19868 if (STRINGP (overlay_arrow_string
))
19870 struct glyph_row
*arrow_row
19871 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19872 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19873 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19874 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19875 struct glyph
*p2
, *end
;
19877 /* Copy the arrow glyphs. */
19878 while (glyph
< arrow_end
)
19881 /* Throw away padding glyphs. */
19883 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19884 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19890 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19895 eassert (INTEGERP (overlay_arrow_string
));
19896 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19898 overlay_arrow_seen
= 1;
19901 /* Highlight trailing whitespace. */
19902 if (!NILP (Vshow_trailing_whitespace
))
19903 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19905 /* Compute pixel dimensions of this line. */
19906 compute_line_metrics (it
);
19908 /* Implementation note: No changes in the glyphs of ROW or in their
19909 faces can be done past this point, because compute_line_metrics
19910 computes ROW's hash value and stores it within the glyph_row
19913 /* Record whether this row ends inside an ellipsis. */
19914 row
->ends_in_ellipsis_p
19915 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19916 && it
->ellipsis_p
);
19918 /* Save fringe bitmaps in this row. */
19919 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19920 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19921 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19922 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19924 it
->left_user_fringe_bitmap
= 0;
19925 it
->left_user_fringe_face_id
= 0;
19926 it
->right_user_fringe_bitmap
= 0;
19927 it
->right_user_fringe_face_id
= 0;
19929 /* Maybe set the cursor. */
19930 cvpos
= it
->w
->cursor
.vpos
;
19932 /* In bidi-reordered rows, keep checking for proper cursor
19933 position even if one has been found already, because buffer
19934 positions in such rows change non-linearly with ROW->VPOS,
19935 when a line is continued. One exception: when we are at ZV,
19936 display cursor on the first suitable glyph row, since all
19937 the empty rows after that also have their position set to ZV. */
19938 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19939 lines' rows is implemented for bidi-reordered rows. */
19941 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19942 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19943 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19944 && cursor_row_p (row
))
19945 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19947 /* Prepare for the next line. This line starts horizontally at (X
19948 HPOS) = (0 0). Vertical positions are incremented. As a
19949 convenience for the caller, IT->glyph_row is set to the next
19951 it
->current_x
= it
->hpos
= 0;
19952 it
->current_y
+= row
->height
;
19953 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19956 /* The next row should by default use the same value of the
19957 reversed_p flag as this one. set_iterator_to_next decides when
19958 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19959 the flag accordingly. */
19960 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19961 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19962 it
->start
= row
->end
;
19963 return row
->displays_text_p
;
19965 #undef RECORD_MAX_MIN_POS
19968 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19969 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19970 doc
: /* Return paragraph direction at point in BUFFER.
19971 Value is either `left-to-right' or `right-to-left'.
19972 If BUFFER is omitted or nil, it defaults to the current buffer.
19974 Paragraph direction determines how the text in the paragraph is displayed.
19975 In left-to-right paragraphs, text begins at the left margin of the window
19976 and the reading direction is generally left to right. In right-to-left
19977 paragraphs, text begins at the right margin and is read from right to left.
19979 See also `bidi-paragraph-direction'. */)
19980 (Lisp_Object buffer
)
19982 struct buffer
*buf
= current_buffer
;
19983 struct buffer
*old
= buf
;
19985 if (! NILP (buffer
))
19987 CHECK_BUFFER (buffer
);
19988 buf
= XBUFFER (buffer
);
19991 if (NILP (BVAR (buf
, bidi_display_reordering
))
19992 || NILP (BVAR (buf
, enable_multibyte_characters
))
19993 /* When we are loading loadup.el, the character property tables
19994 needed for bidi iteration are not yet available. */
19995 || !NILP (Vpurify_flag
))
19996 return Qleft_to_right
;
19997 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19998 return BVAR (buf
, bidi_paragraph_direction
);
20001 /* Determine the direction from buffer text. We could try to
20002 use current_matrix if it is up to date, but this seems fast
20003 enough as it is. */
20004 struct bidi_it itb
;
20005 ptrdiff_t pos
= BUF_PT (buf
);
20006 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20008 void *itb_data
= bidi_shelve_cache ();
20010 set_buffer_temp (buf
);
20011 /* bidi_paragraph_init finds the base direction of the paragraph
20012 by searching forward from paragraph start. We need the base
20013 direction of the current or _previous_ paragraph, so we need
20014 to make sure we are within that paragraph. To that end, find
20015 the previous non-empty line. */
20016 if (pos
>= ZV
&& pos
> BEGV
)
20019 bytepos
= CHAR_TO_BYTE (pos
);
20021 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20022 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20024 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20025 || c
== ' ' || c
== '\t' || c
== '\f')
20027 if (bytepos
<= BEGV_BYTE
)
20032 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20035 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20036 itb
.paragraph_dir
= NEUTRAL_DIR
;
20037 itb
.string
.s
= NULL
;
20038 itb
.string
.lstring
= Qnil
;
20039 itb
.string
.bufpos
= 0;
20040 itb
.string
.unibyte
= 0;
20041 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20042 bidi_unshelve_cache (itb_data
, 0);
20043 set_buffer_temp (old
);
20044 switch (itb
.paragraph_dir
)
20047 return Qleft_to_right
;
20050 return Qright_to_left
;
20060 /***********************************************************************
20062 ***********************************************************************/
20064 /* Redisplay the menu bar in the frame for window W.
20066 The menu bar of X frames that don't have X toolkit support is
20067 displayed in a special window W->frame->menu_bar_window.
20069 The menu bar of terminal frames is treated specially as far as
20070 glyph matrices are concerned. Menu bar lines are not part of
20071 windows, so the update is done directly on the frame matrix rows
20072 for the menu bar. */
20075 display_menu_bar (struct window
*w
)
20077 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20082 /* Don't do all this for graphical frames. */
20084 if (FRAME_W32_P (f
))
20087 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20093 if (FRAME_NS_P (f
))
20095 #endif /* HAVE_NS */
20097 #ifdef USE_X_TOOLKIT
20098 eassert (!FRAME_WINDOW_P (f
));
20099 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20100 it
.first_visible_x
= 0;
20101 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20102 #else /* not USE_X_TOOLKIT */
20103 if (FRAME_WINDOW_P (f
))
20105 /* Menu bar lines are displayed in the desired matrix of the
20106 dummy window menu_bar_window. */
20107 struct window
*menu_w
;
20108 eassert (WINDOWP (FVAR (f
, menu_bar_window
)));
20109 menu_w
= XWINDOW (FVAR (f
, menu_bar_window
));
20110 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20112 it
.first_visible_x
= 0;
20113 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20117 /* This is a TTY frame, i.e. character hpos/vpos are used as
20119 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20121 it
.first_visible_x
= 0;
20122 it
.last_visible_x
= FRAME_COLS (f
);
20124 #endif /* not USE_X_TOOLKIT */
20126 /* FIXME: This should be controlled by a user option. See the
20127 comments in redisplay_tool_bar and display_mode_line about
20129 it
.paragraph_embedding
= L2R
;
20131 if (! mode_line_inverse_video
)
20132 /* Force the menu-bar to be displayed in the default face. */
20133 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20135 /* Clear all rows of the menu bar. */
20136 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20138 struct glyph_row
*row
= it
.glyph_row
+ i
;
20139 clear_glyph_row (row
);
20140 row
->enabled_p
= 1;
20141 row
->full_width_p
= 1;
20144 /* Display all items of the menu bar. */
20145 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20146 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20148 Lisp_Object string
;
20150 /* Stop at nil string. */
20151 string
= AREF (items
, i
+ 1);
20155 /* Remember where item was displayed. */
20156 ASET (items
, i
+ 3, make_number (it
.hpos
));
20158 /* Display the item, pad with one space. */
20159 if (it
.current_x
< it
.last_visible_x
)
20160 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20161 SCHARS (string
) + 1, 0, 0, -1);
20164 /* Fill out the line with spaces. */
20165 if (it
.current_x
< it
.last_visible_x
)
20166 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20168 /* Compute the total height of the lines. */
20169 compute_line_metrics (&it
);
20174 /***********************************************************************
20176 ***********************************************************************/
20178 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20179 FORCE is non-zero, redisplay mode lines unconditionally.
20180 Otherwise, redisplay only mode lines that are garbaged. Value is
20181 the number of windows whose mode lines were redisplayed. */
20184 redisplay_mode_lines (Lisp_Object window
, int force
)
20188 while (!NILP (window
))
20190 struct window
*w
= XWINDOW (window
);
20192 if (WINDOWP (WVAR (w
, hchild
)))
20193 nwindows
+= redisplay_mode_lines (WVAR (w
, hchild
), force
);
20194 else if (WINDOWP (WVAR (w
, vchild
)))
20195 nwindows
+= redisplay_mode_lines (WVAR (w
, vchild
), force
);
20197 || FRAME_GARBAGED_P (XFRAME (WVAR (w
, frame
)))
20198 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20200 struct text_pos lpoint
;
20201 struct buffer
*old
= current_buffer
;
20203 /* Set the window's buffer for the mode line display. */
20204 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20205 set_buffer_internal_1 (XBUFFER (WVAR (w
, buffer
)));
20207 /* Point refers normally to the selected window. For any
20208 other window, set up appropriate value. */
20209 if (!EQ (window
, selected_window
))
20211 struct text_pos pt
;
20213 SET_TEXT_POS_FROM_MARKER (pt
, WVAR (w
, pointm
));
20214 if (CHARPOS (pt
) < BEGV
)
20215 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20216 else if (CHARPOS (pt
) > (ZV
- 1))
20217 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20219 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20222 /* Display mode lines. */
20223 clear_glyph_matrix (w
->desired_matrix
);
20224 if (display_mode_lines (w
))
20227 w
->must_be_updated_p
= 1;
20230 /* Restore old settings. */
20231 set_buffer_internal_1 (old
);
20232 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20235 window
= WVAR (w
, next
);
20242 /* Display the mode and/or header line of window W. Value is the
20243 sum number of mode lines and header lines displayed. */
20246 display_mode_lines (struct window
*w
)
20248 Lisp_Object old_selected_window
, old_selected_frame
;
20251 old_selected_frame
= selected_frame
;
20252 selected_frame
= WVAR (w
, frame
);
20253 old_selected_window
= selected_window
;
20254 XSETWINDOW (selected_window
, w
);
20256 /* These will be set while the mode line specs are processed. */
20257 line_number_displayed
= 0;
20258 WVAR (w
, column_number_displayed
) = Qnil
;
20260 if (WINDOW_WANTS_MODELINE_P (w
))
20262 struct window
*sel_w
= XWINDOW (old_selected_window
);
20264 /* Select mode line face based on the real selected window. */
20265 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20266 BVAR (current_buffer
, mode_line_format
));
20270 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20272 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20273 BVAR (current_buffer
, header_line_format
));
20277 selected_frame
= old_selected_frame
;
20278 selected_window
= old_selected_window
;
20283 /* Display mode or header line of window W. FACE_ID specifies which
20284 line to display; it is either MODE_LINE_FACE_ID or
20285 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20286 display. Value is the pixel height of the mode/header line
20290 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20294 ptrdiff_t count
= SPECPDL_INDEX ();
20296 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20297 /* Don't extend on a previously drawn mode-line.
20298 This may happen if called from pos_visible_p. */
20299 it
.glyph_row
->enabled_p
= 0;
20300 prepare_desired_row (it
.glyph_row
);
20302 it
.glyph_row
->mode_line_p
= 1;
20304 if (! mode_line_inverse_video
)
20305 /* Force the mode-line to be displayed in the default face. */
20306 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20308 /* FIXME: This should be controlled by a user option. But
20309 supporting such an option is not trivial, since the mode line is
20310 made up of many separate strings. */
20311 it
.paragraph_embedding
= L2R
;
20313 record_unwind_protect (unwind_format_mode_line
,
20314 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20316 mode_line_target
= MODE_LINE_DISPLAY
;
20318 /* Temporarily make frame's keyboard the current kboard so that
20319 kboard-local variables in the mode_line_format will get the right
20321 push_kboard (FRAME_KBOARD (it
.f
));
20322 record_unwind_save_match_data ();
20323 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20326 unbind_to (count
, Qnil
);
20328 /* Fill up with spaces. */
20329 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20331 compute_line_metrics (&it
);
20332 it
.glyph_row
->full_width_p
= 1;
20333 it
.glyph_row
->continued_p
= 0;
20334 it
.glyph_row
->truncated_on_left_p
= 0;
20335 it
.glyph_row
->truncated_on_right_p
= 0;
20337 /* Make a 3D mode-line have a shadow at its right end. */
20338 face
= FACE_FROM_ID (it
.f
, face_id
);
20339 extend_face_to_end_of_line (&it
);
20340 if (face
->box
!= FACE_NO_BOX
)
20342 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20343 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20344 last
->right_box_line_p
= 1;
20347 return it
.glyph_row
->height
;
20350 /* Move element ELT in LIST to the front of LIST.
20351 Return the updated list. */
20354 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20356 register Lisp_Object tail
, prev
;
20357 register Lisp_Object tem
;
20361 while (CONSP (tail
))
20367 /* Splice out the link TAIL. */
20369 list
= XCDR (tail
);
20371 Fsetcdr (prev
, XCDR (tail
));
20373 /* Now make it the first. */
20374 Fsetcdr (tail
, list
);
20379 tail
= XCDR (tail
);
20383 /* Not found--return unchanged LIST. */
20387 /* Contribute ELT to the mode line for window IT->w. How it
20388 translates into text depends on its data type.
20390 IT describes the display environment in which we display, as usual.
20392 DEPTH is the depth in recursion. It is used to prevent
20393 infinite recursion here.
20395 FIELD_WIDTH is the number of characters the display of ELT should
20396 occupy in the mode line, and PRECISION is the maximum number of
20397 characters to display from ELT's representation. See
20398 display_string for details.
20400 Returns the hpos of the end of the text generated by ELT.
20402 PROPS is a property list to add to any string we encounter.
20404 If RISKY is nonzero, remove (disregard) any properties in any string
20405 we encounter, and ignore :eval and :propertize.
20407 The global variable `mode_line_target' determines whether the
20408 output is passed to `store_mode_line_noprop',
20409 `store_mode_line_string', or `display_string'. */
20412 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20413 Lisp_Object elt
, Lisp_Object props
, int risky
)
20415 int n
= 0, field
, prec
;
20420 elt
= build_string ("*too-deep*");
20424 switch (XTYPE (elt
))
20428 /* A string: output it and check for %-constructs within it. */
20430 ptrdiff_t offset
= 0;
20432 if (SCHARS (elt
) > 0
20433 && (!NILP (props
) || risky
))
20435 Lisp_Object oprops
, aelt
;
20436 oprops
= Ftext_properties_at (make_number (0), elt
);
20438 /* If the starting string's properties are not what
20439 we want, translate the string. Also, if the string
20440 is risky, do that anyway. */
20442 if (NILP (Fequal (props
, oprops
)) || risky
)
20444 /* If the starting string has properties,
20445 merge the specified ones onto the existing ones. */
20446 if (! NILP (oprops
) && !risky
)
20450 oprops
= Fcopy_sequence (oprops
);
20452 while (CONSP (tem
))
20454 oprops
= Fplist_put (oprops
, XCAR (tem
),
20455 XCAR (XCDR (tem
)));
20456 tem
= XCDR (XCDR (tem
));
20461 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20462 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20464 /* AELT is what we want. Move it to the front
20465 without consing. */
20467 mode_line_proptrans_alist
20468 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20474 /* If AELT has the wrong props, it is useless.
20475 so get rid of it. */
20477 mode_line_proptrans_alist
20478 = Fdelq (aelt
, mode_line_proptrans_alist
);
20480 elt
= Fcopy_sequence (elt
);
20481 Fset_text_properties (make_number (0), Flength (elt
),
20483 /* Add this item to mode_line_proptrans_alist. */
20484 mode_line_proptrans_alist
20485 = Fcons (Fcons (elt
, props
),
20486 mode_line_proptrans_alist
);
20487 /* Truncate mode_line_proptrans_alist
20488 to at most 50 elements. */
20489 tem
= Fnthcdr (make_number (50),
20490 mode_line_proptrans_alist
);
20492 XSETCDR (tem
, Qnil
);
20501 prec
= precision
- n
;
20502 switch (mode_line_target
)
20504 case MODE_LINE_NOPROP
:
20505 case MODE_LINE_TITLE
:
20506 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20508 case MODE_LINE_STRING
:
20509 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20511 case MODE_LINE_DISPLAY
:
20512 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20513 0, prec
, 0, STRING_MULTIBYTE (elt
));
20520 /* Handle the non-literal case. */
20522 while ((precision
<= 0 || n
< precision
)
20523 && SREF (elt
, offset
) != 0
20524 && (mode_line_target
!= MODE_LINE_DISPLAY
20525 || it
->current_x
< it
->last_visible_x
))
20527 ptrdiff_t last_offset
= offset
;
20529 /* Advance to end of string or next format specifier. */
20530 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20533 if (offset
- 1 != last_offset
)
20535 ptrdiff_t nchars
, nbytes
;
20537 /* Output to end of string or up to '%'. Field width
20538 is length of string. Don't output more than
20539 PRECISION allows us. */
20542 prec
= c_string_width (SDATA (elt
) + last_offset
,
20543 offset
- last_offset
, precision
- n
,
20546 switch (mode_line_target
)
20548 case MODE_LINE_NOPROP
:
20549 case MODE_LINE_TITLE
:
20550 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20552 case MODE_LINE_STRING
:
20554 ptrdiff_t bytepos
= last_offset
;
20555 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20556 ptrdiff_t endpos
= (precision
<= 0
20557 ? string_byte_to_char (elt
, offset
)
20558 : charpos
+ nchars
);
20560 n
+= store_mode_line_string (NULL
,
20561 Fsubstring (elt
, make_number (charpos
),
20562 make_number (endpos
)),
20566 case MODE_LINE_DISPLAY
:
20568 ptrdiff_t bytepos
= last_offset
;
20569 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20571 if (precision
<= 0)
20572 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20573 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20575 STRING_MULTIBYTE (elt
));
20580 else /* c == '%' */
20582 ptrdiff_t percent_position
= offset
;
20584 /* Get the specified minimum width. Zero means
20587 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20588 field
= field
* 10 + c
- '0';
20590 /* Don't pad beyond the total padding allowed. */
20591 if (field_width
- n
> 0 && field
> field_width
- n
)
20592 field
= field_width
- n
;
20594 /* Note that either PRECISION <= 0 or N < PRECISION. */
20595 prec
= precision
- n
;
20598 n
+= display_mode_element (it
, depth
, field
, prec
,
20599 Vglobal_mode_string
, props
,
20604 ptrdiff_t bytepos
, charpos
;
20606 Lisp_Object string
;
20608 bytepos
= percent_position
;
20609 charpos
= (STRING_MULTIBYTE (elt
)
20610 ? string_byte_to_char (elt
, bytepos
)
20612 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20613 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20615 switch (mode_line_target
)
20617 case MODE_LINE_NOPROP
:
20618 case MODE_LINE_TITLE
:
20619 n
+= store_mode_line_noprop (spec
, field
, prec
);
20621 case MODE_LINE_STRING
:
20623 Lisp_Object tem
= build_string (spec
);
20624 props
= Ftext_properties_at (make_number (charpos
), elt
);
20625 /* Should only keep face property in props */
20626 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20629 case MODE_LINE_DISPLAY
:
20631 int nglyphs_before
, nwritten
;
20633 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20634 nwritten
= display_string (spec
, string
, elt
,
20639 /* Assign to the glyphs written above the
20640 string where the `%x' came from, position
20644 struct glyph
*glyph
20645 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20649 for (i
= 0; i
< nwritten
; ++i
)
20651 glyph
[i
].object
= elt
;
20652 glyph
[i
].charpos
= charpos
;
20669 /* A symbol: process the value of the symbol recursively
20670 as if it appeared here directly. Avoid error if symbol void.
20671 Special case: if value of symbol is a string, output the string
20674 register Lisp_Object tem
;
20676 /* If the variable is not marked as risky to set
20677 then its contents are risky to use. */
20678 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20681 tem
= Fboundp (elt
);
20684 tem
= Fsymbol_value (elt
);
20685 /* If value is a string, output that string literally:
20686 don't check for % within it. */
20690 if (!EQ (tem
, elt
))
20692 /* Give up right away for nil or t. */
20702 register Lisp_Object car
, tem
;
20704 /* A cons cell: five distinct cases.
20705 If first element is :eval or :propertize, do something special.
20706 If first element is a string or a cons, process all the elements
20707 and effectively concatenate them.
20708 If first element is a negative number, truncate displaying cdr to
20709 at most that many characters. If positive, pad (with spaces)
20710 to at least that many characters.
20711 If first element is a symbol, process the cadr or caddr recursively
20712 according to whether the symbol's value is non-nil or nil. */
20714 if (EQ (car
, QCeval
))
20716 /* An element of the form (:eval FORM) means evaluate FORM
20717 and use the result as mode line elements. */
20722 if (CONSP (XCDR (elt
)))
20725 spec
= safe_eval (XCAR (XCDR (elt
)));
20726 n
+= display_mode_element (it
, depth
, field_width
- n
,
20727 precision
- n
, spec
, props
,
20731 else if (EQ (car
, QCpropertize
))
20733 /* An element of the form (:propertize ELT PROPS...)
20734 means display ELT but applying properties PROPS. */
20739 if (CONSP (XCDR (elt
)))
20740 n
+= display_mode_element (it
, depth
, field_width
- n
,
20741 precision
- n
, XCAR (XCDR (elt
)),
20742 XCDR (XCDR (elt
)), risky
);
20744 else if (SYMBOLP (car
))
20746 tem
= Fboundp (car
);
20750 /* elt is now the cdr, and we know it is a cons cell.
20751 Use its car if CAR has a non-nil value. */
20754 tem
= Fsymbol_value (car
);
20761 /* Symbol's value is nil (or symbol is unbound)
20762 Get the cddr of the original list
20763 and if possible find the caddr and use that. */
20767 else if (!CONSP (elt
))
20772 else if (INTEGERP (car
))
20774 register int lim
= XINT (car
);
20778 /* Negative int means reduce maximum width. */
20779 if (precision
<= 0)
20782 precision
= min (precision
, -lim
);
20786 /* Padding specified. Don't let it be more than
20787 current maximum. */
20789 lim
= min (precision
, lim
);
20791 /* If that's more padding than already wanted, queue it.
20792 But don't reduce padding already specified even if
20793 that is beyond the current truncation point. */
20794 field_width
= max (lim
, field_width
);
20798 else if (STRINGP (car
) || CONSP (car
))
20800 Lisp_Object halftail
= elt
;
20804 && (precision
<= 0 || n
< precision
))
20806 n
+= display_mode_element (it
, depth
,
20807 /* Do padding only after the last
20808 element in the list. */
20809 (! CONSP (XCDR (elt
))
20812 precision
- n
, XCAR (elt
),
20816 if ((len
& 1) == 0)
20817 halftail
= XCDR (halftail
);
20818 /* Check for cycle. */
20819 if (EQ (halftail
, elt
))
20828 elt
= build_string ("*invalid*");
20832 /* Pad to FIELD_WIDTH. */
20833 if (field_width
> 0 && n
< field_width
)
20835 switch (mode_line_target
)
20837 case MODE_LINE_NOPROP
:
20838 case MODE_LINE_TITLE
:
20839 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20841 case MODE_LINE_STRING
:
20842 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20844 case MODE_LINE_DISPLAY
:
20845 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20854 /* Store a mode-line string element in mode_line_string_list.
20856 If STRING is non-null, display that C string. Otherwise, the Lisp
20857 string LISP_STRING is displayed.
20859 FIELD_WIDTH is the minimum number of output glyphs to produce.
20860 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20861 with spaces. FIELD_WIDTH <= 0 means don't pad.
20863 PRECISION is the maximum number of characters to output from
20864 STRING. PRECISION <= 0 means don't truncate the string.
20866 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20867 properties to the string.
20869 PROPS are the properties to add to the string.
20870 The mode_line_string_face face property is always added to the string.
20874 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20875 int field_width
, int precision
, Lisp_Object props
)
20880 if (string
!= NULL
)
20882 len
= strlen (string
);
20883 if (precision
> 0 && len
> precision
)
20885 lisp_string
= make_string (string
, len
);
20887 props
= mode_line_string_face_prop
;
20888 else if (!NILP (mode_line_string_face
))
20890 Lisp_Object face
= Fplist_get (props
, Qface
);
20891 props
= Fcopy_sequence (props
);
20893 face
= mode_line_string_face
;
20895 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20896 props
= Fplist_put (props
, Qface
, face
);
20898 Fadd_text_properties (make_number (0), make_number (len
),
20899 props
, lisp_string
);
20903 len
= XFASTINT (Flength (lisp_string
));
20904 if (precision
> 0 && len
> precision
)
20907 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20910 if (!NILP (mode_line_string_face
))
20914 props
= Ftext_properties_at (make_number (0), lisp_string
);
20915 face
= Fplist_get (props
, Qface
);
20917 face
= mode_line_string_face
;
20919 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20920 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20922 lisp_string
= Fcopy_sequence (lisp_string
);
20925 Fadd_text_properties (make_number (0), make_number (len
),
20926 props
, lisp_string
);
20931 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20935 if (field_width
> len
)
20937 field_width
-= len
;
20938 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20940 Fadd_text_properties (make_number (0), make_number (field_width
),
20941 props
, lisp_string
);
20942 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20950 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20952 doc
: /* Format a string out of a mode line format specification.
20953 First arg FORMAT specifies the mode line format (see `mode-line-format'
20954 for details) to use.
20956 By default, the format is evaluated for the currently selected window.
20958 Optional second arg FACE specifies the face property to put on all
20959 characters for which no face is specified. The value nil means the
20960 default face. The value t means whatever face the window's mode line
20961 currently uses (either `mode-line' or `mode-line-inactive',
20962 depending on whether the window is the selected window or not).
20963 An integer value means the value string has no text
20966 Optional third and fourth args WINDOW and BUFFER specify the window
20967 and buffer to use as the context for the formatting (defaults
20968 are the selected window and the WINDOW's buffer). */)
20969 (Lisp_Object format
, Lisp_Object face
,
20970 Lisp_Object window
, Lisp_Object buffer
)
20975 struct buffer
*old_buffer
= NULL
;
20977 int no_props
= INTEGERP (face
);
20978 ptrdiff_t count
= SPECPDL_INDEX ();
20980 int string_start
= 0;
20983 window
= selected_window
;
20984 CHECK_WINDOW (window
);
20985 w
= XWINDOW (window
);
20988 buffer
= WVAR (w
, buffer
);
20989 CHECK_BUFFER (buffer
);
20991 /* Make formatting the modeline a non-op when noninteractive, otherwise
20992 there will be problems later caused by a partially initialized frame. */
20993 if (NILP (format
) || noninteractive
)
20994 return empty_unibyte_string
;
20999 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21000 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21001 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21002 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21003 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21004 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21005 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21008 if (XBUFFER (buffer
) != current_buffer
)
21009 old_buffer
= current_buffer
;
21011 /* Save things including mode_line_proptrans_alist,
21012 and set that to nil so that we don't alter the outer value. */
21013 record_unwind_protect (unwind_format_mode_line
,
21014 format_mode_line_unwind_data
21015 (XFRAME (WINDOW_FRAME (XWINDOW (window
))),
21016 old_buffer
, selected_window
, 1));
21017 mode_line_proptrans_alist
= Qnil
;
21019 Fselect_window (window
, Qt
);
21021 set_buffer_internal_1 (XBUFFER (buffer
));
21023 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21027 mode_line_target
= MODE_LINE_NOPROP
;
21028 mode_line_string_face_prop
= Qnil
;
21029 mode_line_string_list
= Qnil
;
21030 string_start
= MODE_LINE_NOPROP_LEN (0);
21034 mode_line_target
= MODE_LINE_STRING
;
21035 mode_line_string_list
= Qnil
;
21036 mode_line_string_face
= face
;
21037 mode_line_string_face_prop
21038 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21041 push_kboard (FRAME_KBOARD (it
.f
));
21042 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21047 len
= MODE_LINE_NOPROP_LEN (string_start
);
21048 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21052 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21053 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21054 empty_unibyte_string
);
21057 unbind_to (count
, Qnil
);
21061 /* Write a null-terminated, right justified decimal representation of
21062 the positive integer D to BUF using a minimal field width WIDTH. */
21065 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21067 register char *p
= buf
;
21075 *p
++ = d
% 10 + '0';
21080 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21091 /* Write a null-terminated, right justified decimal and "human
21092 readable" representation of the nonnegative integer D to BUF using
21093 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21095 static const char power_letter
[] =
21109 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21111 /* We aim to represent the nonnegative integer D as
21112 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21113 ptrdiff_t quotient
= d
;
21115 /* -1 means: do not use TENTHS. */
21119 /* Length of QUOTIENT.TENTHS as a string. */
21125 if (1000 <= quotient
)
21127 /* Scale to the appropriate EXPONENT. */
21130 remainder
= quotient
% 1000;
21134 while (1000 <= quotient
);
21136 /* Round to nearest and decide whether to use TENTHS or not. */
21139 tenths
= remainder
/ 100;
21140 if (50 <= remainder
% 100)
21147 if (quotient
== 10)
21155 if (500 <= remainder
)
21157 if (quotient
< 999)
21168 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21169 if (tenths
== -1 && quotient
<= 99)
21176 p
= psuffix
= buf
+ max (width
, length
);
21178 /* Print EXPONENT. */
21179 *psuffix
++ = power_letter
[exponent
];
21182 /* Print TENTHS. */
21185 *--p
= '0' + tenths
;
21189 /* Print QUOTIENT. */
21192 int digit
= quotient
% 10;
21193 *--p
= '0' + digit
;
21195 while ((quotient
/= 10) != 0);
21197 /* Print leading spaces. */
21202 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21203 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21204 type of CODING_SYSTEM. Return updated pointer into BUF. */
21206 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21209 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21212 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21213 const unsigned char *eol_str
;
21215 /* The EOL conversion we are using. */
21216 Lisp_Object eoltype
;
21218 val
= CODING_SYSTEM_SPEC (coding_system
);
21221 if (!VECTORP (val
)) /* Not yet decided. */
21223 *buf
++ = multibyte
? '-' : ' ';
21225 eoltype
= eol_mnemonic_undecided
;
21226 /* Don't mention EOL conversion if it isn't decided. */
21231 Lisp_Object eolvalue
;
21233 attrs
= AREF (val
, 0);
21234 eolvalue
= AREF (val
, 2);
21237 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21242 /* The EOL conversion that is normal on this system. */
21244 if (NILP (eolvalue
)) /* Not yet decided. */
21245 eoltype
= eol_mnemonic_undecided
;
21246 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21247 eoltype
= eol_mnemonic_undecided
;
21248 else /* eolvalue is Qunix, Qdos, or Qmac. */
21249 eoltype
= (EQ (eolvalue
, Qunix
)
21250 ? eol_mnemonic_unix
21251 : (EQ (eolvalue
, Qdos
) == 1
21252 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21258 /* Mention the EOL conversion if it is not the usual one. */
21259 if (STRINGP (eoltype
))
21261 eol_str
= SDATA (eoltype
);
21262 eol_str_len
= SBYTES (eoltype
);
21264 else if (CHARACTERP (eoltype
))
21266 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21267 int c
= XFASTINT (eoltype
);
21268 eol_str_len
= CHAR_STRING (c
, tmp
);
21273 eol_str
= invalid_eol_type
;
21274 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21276 memcpy (buf
, eol_str
, eol_str_len
);
21277 buf
+= eol_str_len
;
21283 /* Return a string for the output of a mode line %-spec for window W,
21284 generated by character C. FIELD_WIDTH > 0 means pad the string
21285 returned with spaces to that value. Return a Lisp string in
21286 *STRING if the resulting string is taken from that Lisp string.
21288 Note we operate on the current buffer for most purposes,
21289 the exception being w->base_line_pos. */
21291 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21293 static const char *
21294 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21295 Lisp_Object
*string
)
21298 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21299 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21300 struct buffer
*b
= current_buffer
;
21308 if (!NILP (BVAR (b
, read_only
)))
21310 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21315 /* This differs from %* only for a modified read-only buffer. */
21316 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21318 if (!NILP (BVAR (b
, read_only
)))
21323 /* This differs from %* in ignoring read-only-ness. */
21324 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21336 if (command_loop_level
> 5)
21338 p
= decode_mode_spec_buf
;
21339 for (i
= 0; i
< command_loop_level
; i
++)
21342 return decode_mode_spec_buf
;
21350 if (command_loop_level
> 5)
21352 p
= decode_mode_spec_buf
;
21353 for (i
= 0; i
< command_loop_level
; i
++)
21356 return decode_mode_spec_buf
;
21363 /* Let lots_of_dashes be a string of infinite length. */
21364 if (mode_line_target
== MODE_LINE_NOPROP
||
21365 mode_line_target
== MODE_LINE_STRING
)
21367 if (field_width
<= 0
21368 || field_width
> sizeof (lots_of_dashes
))
21370 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21371 decode_mode_spec_buf
[i
] = '-';
21372 decode_mode_spec_buf
[i
] = '\0';
21373 return decode_mode_spec_buf
;
21376 return lots_of_dashes
;
21380 obj
= BVAR (b
, name
);
21384 /* %c and %l are ignored in `frame-title-format'.
21385 (In redisplay_internal, the frame title is drawn _before_ the
21386 windows are updated, so the stuff which depends on actual
21387 window contents (such as %l) may fail to render properly, or
21388 even crash emacs.) */
21389 if (mode_line_target
== MODE_LINE_TITLE
)
21393 ptrdiff_t col
= current_column ();
21394 WVAR (w
, column_number_displayed
) = make_number (col
);
21395 pint2str (decode_mode_spec_buf
, field_width
, col
);
21396 return decode_mode_spec_buf
;
21400 #ifndef SYSTEM_MALLOC
21402 if (NILP (Vmemory_full
))
21405 return "!MEM FULL! ";
21412 /* %F displays the frame name. */
21413 if (!NILP (FVAR (f
, title
)))
21414 return SSDATA (FVAR (f
, title
));
21415 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21416 return SSDATA (FVAR (f
, name
));
21420 obj
= BVAR (b
, filename
);
21425 ptrdiff_t size
= ZV
- BEGV
;
21426 pint2str (decode_mode_spec_buf
, field_width
, size
);
21427 return decode_mode_spec_buf
;
21432 ptrdiff_t size
= ZV
- BEGV
;
21433 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21434 return decode_mode_spec_buf
;
21439 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21440 ptrdiff_t topline
, nlines
, height
;
21443 /* %c and %l are ignored in `frame-title-format'. */
21444 if (mode_line_target
== MODE_LINE_TITLE
)
21447 startpos
= XMARKER (WVAR (w
, start
))->charpos
;
21448 startpos_byte
= marker_byte_position (WVAR (w
, start
));
21449 height
= WINDOW_TOTAL_LINES (w
);
21451 /* If we decided that this buffer isn't suitable for line numbers,
21452 don't forget that too fast. */
21453 if (EQ (WVAR (w
, base_line_pos
), WVAR (w
, buffer
)))
21455 /* But do forget it, if the window shows a different buffer now. */
21456 else if (BUFFERP (WVAR (w
, base_line_pos
)))
21457 WVAR (w
, base_line_pos
) = Qnil
;
21459 /* If the buffer is very big, don't waste time. */
21460 if (INTEGERP (Vline_number_display_limit
)
21461 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21463 WVAR (w
, base_line_pos
) = Qnil
;
21464 WVAR (w
, base_line_number
) = Qnil
;
21468 if (INTEGERP (WVAR (w
, base_line_number
))
21469 && INTEGERP (WVAR (w
, base_line_pos
))
21470 && XFASTINT (WVAR (w
, base_line_pos
)) <= startpos
)
21472 line
= XFASTINT (WVAR (w
, base_line_number
));
21473 linepos
= XFASTINT (WVAR (w
, base_line_pos
));
21474 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21479 linepos
= BUF_BEGV (b
);
21480 linepos_byte
= BUF_BEGV_BYTE (b
);
21483 /* Count lines from base line to window start position. */
21484 nlines
= display_count_lines (linepos_byte
,
21488 topline
= nlines
+ line
;
21490 /* Determine a new base line, if the old one is too close
21491 or too far away, or if we did not have one.
21492 "Too close" means it's plausible a scroll-down would
21493 go back past it. */
21494 if (startpos
== BUF_BEGV (b
))
21496 WVAR (w
, base_line_number
) = make_number (topline
);
21497 WVAR (w
, base_line_pos
) = make_number (BUF_BEGV (b
));
21499 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21500 || linepos
== BUF_BEGV (b
))
21502 ptrdiff_t limit
= BUF_BEGV (b
);
21503 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21504 ptrdiff_t position
;
21505 ptrdiff_t distance
=
21506 (height
* 2 + 30) * line_number_display_limit_width
;
21508 if (startpos
- distance
> limit
)
21510 limit
= startpos
- distance
;
21511 limit_byte
= CHAR_TO_BYTE (limit
);
21514 nlines
= display_count_lines (startpos_byte
,
21516 - (height
* 2 + 30),
21518 /* If we couldn't find the lines we wanted within
21519 line_number_display_limit_width chars per line,
21520 give up on line numbers for this window. */
21521 if (position
== limit_byte
&& limit
== startpos
- distance
)
21523 WVAR (w
, base_line_pos
) = WVAR (w
, buffer
);
21524 WVAR (w
, base_line_number
) = Qnil
;
21528 WVAR (w
, base_line_number
) = make_number (topline
- nlines
);
21529 WVAR (w
, base_line_pos
) = make_number (BYTE_TO_CHAR (position
));
21532 /* Now count lines from the start pos to point. */
21533 nlines
= display_count_lines (startpos_byte
,
21534 PT_BYTE
, PT
, &junk
);
21536 /* Record that we did display the line number. */
21537 line_number_displayed
= 1;
21539 /* Make the string to show. */
21540 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21541 return decode_mode_spec_buf
;
21544 char* p
= decode_mode_spec_buf
;
21545 int pad
= field_width
- 2;
21551 return decode_mode_spec_buf
;
21557 obj
= BVAR (b
, mode_name
);
21561 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21567 ptrdiff_t pos
= marker_position (WVAR (w
, start
));
21568 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21570 if (XFASTINT (WVAR (w
, window_end_pos
)) <= BUF_Z (b
) - BUF_ZV (b
))
21572 if (pos
<= BUF_BEGV (b
))
21577 else if (pos
<= BUF_BEGV (b
))
21581 if (total
> 1000000)
21582 /* Do it differently for a large value, to avoid overflow. */
21583 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21585 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21586 /* We can't normally display a 3-digit number,
21587 so get us a 2-digit number that is close. */
21590 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21591 return decode_mode_spec_buf
;
21595 /* Display percentage of size above the bottom of the screen. */
21598 ptrdiff_t toppos
= marker_position (WVAR (w
, start
));
21599 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (WVAR (w
, window_end_pos
));
21600 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21602 if (botpos
>= BUF_ZV (b
))
21604 if (toppos
<= BUF_BEGV (b
))
21611 if (total
> 1000000)
21612 /* Do it differently for a large value, to avoid overflow. */
21613 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21615 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21616 /* We can't normally display a 3-digit number,
21617 so get us a 2-digit number that is close. */
21620 if (toppos
<= BUF_BEGV (b
))
21621 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21623 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21624 return decode_mode_spec_buf
;
21629 /* status of process */
21630 obj
= Fget_buffer_process (Fcurrent_buffer ());
21632 return "no process";
21634 obj
= Fsymbol_name (Fprocess_status (obj
));
21640 ptrdiff_t count
= inhibit_garbage_collection ();
21641 Lisp_Object val
= call1 (intern ("file-remote-p"),
21642 BVAR (current_buffer
, directory
));
21643 unbind_to (count
, Qnil
);
21651 case 't': /* indicate TEXT or BINARY */
21655 /* coding-system (not including end-of-line format) */
21657 /* coding-system (including end-of-line type) */
21659 int eol_flag
= (c
== 'Z');
21660 char *p
= decode_mode_spec_buf
;
21662 if (! FRAME_WINDOW_P (f
))
21664 /* No need to mention EOL here--the terminal never needs
21665 to do EOL conversion. */
21666 p
= decode_mode_spec_coding (CODING_ID_NAME
21667 (FRAME_KEYBOARD_CODING (f
)->id
),
21669 p
= decode_mode_spec_coding (CODING_ID_NAME
21670 (FRAME_TERMINAL_CODING (f
)->id
),
21673 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21676 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21677 #ifdef subprocesses
21678 obj
= Fget_buffer_process (Fcurrent_buffer ());
21679 if (PROCESSP (obj
))
21681 p
= decode_mode_spec_coding
21682 (PVAR (XPROCESS (obj
), decode_coding_system
), p
, eol_flag
);
21683 p
= decode_mode_spec_coding
21684 (PVAR (XPROCESS (obj
), encode_coding_system
), p
, eol_flag
);
21686 #endif /* subprocesses */
21689 return decode_mode_spec_buf
;
21696 return SSDATA (obj
);
21703 /* Count up to COUNT lines starting from START_BYTE.
21704 But don't go beyond LIMIT_BYTE.
21705 Return the number of lines thus found (always nonnegative).
21707 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21710 display_count_lines (ptrdiff_t start_byte
,
21711 ptrdiff_t limit_byte
, ptrdiff_t count
,
21712 ptrdiff_t *byte_pos_ptr
)
21714 register unsigned char *cursor
;
21715 unsigned char *base
;
21717 register ptrdiff_t ceiling
;
21718 register unsigned char *ceiling_addr
;
21719 ptrdiff_t orig_count
= count
;
21721 /* If we are not in selective display mode,
21722 check only for newlines. */
21723 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21724 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21728 while (start_byte
< limit_byte
)
21730 ceiling
= BUFFER_CEILING_OF (start_byte
);
21731 ceiling
= min (limit_byte
- 1, ceiling
);
21732 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21733 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21736 if (selective_display
)
21737 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21740 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21743 if (cursor
!= ceiling_addr
)
21747 start_byte
+= cursor
- base
+ 1;
21748 *byte_pos_ptr
= start_byte
;
21752 if (++cursor
== ceiling_addr
)
21758 start_byte
+= cursor
- base
;
21763 while (start_byte
> limit_byte
)
21765 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21766 ceiling
= max (limit_byte
, ceiling
);
21767 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21768 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21771 if (selective_display
)
21772 while (--cursor
!= ceiling_addr
21773 && *cursor
!= '\n' && *cursor
!= 015)
21776 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21779 if (cursor
!= ceiling_addr
)
21783 start_byte
+= cursor
- base
+ 1;
21784 *byte_pos_ptr
= start_byte
;
21785 /* When scanning backwards, we should
21786 not count the newline posterior to which we stop. */
21787 return - orig_count
- 1;
21793 /* Here we add 1 to compensate for the last decrement
21794 of CURSOR, which took it past the valid range. */
21795 start_byte
+= cursor
- base
+ 1;
21799 *byte_pos_ptr
= limit_byte
;
21802 return - orig_count
+ count
;
21803 return orig_count
- count
;
21809 /***********************************************************************
21811 ***********************************************************************/
21813 /* Display a NUL-terminated string, starting with index START.
21815 If STRING is non-null, display that C string. Otherwise, the Lisp
21816 string LISP_STRING is displayed. There's a case that STRING is
21817 non-null and LISP_STRING is not nil. It means STRING is a string
21818 data of LISP_STRING. In that case, we display LISP_STRING while
21819 ignoring its text properties.
21821 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21822 FACE_STRING. Display STRING or LISP_STRING with the face at
21823 FACE_STRING_POS in FACE_STRING:
21825 Display the string in the environment given by IT, but use the
21826 standard display table, temporarily.
21828 FIELD_WIDTH is the minimum number of output glyphs to produce.
21829 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21830 with spaces. If STRING has more characters, more than FIELD_WIDTH
21831 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21833 PRECISION is the maximum number of characters to output from
21834 STRING. PRECISION < 0 means don't truncate the string.
21836 This is roughly equivalent to printf format specifiers:
21838 FIELD_WIDTH PRECISION PRINTF
21839 ----------------------------------------
21845 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21846 display them, and < 0 means obey the current buffer's value of
21847 enable_multibyte_characters.
21849 Value is the number of columns displayed. */
21852 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21853 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21854 int field_width
, int precision
, int max_x
, int multibyte
)
21856 int hpos_at_start
= it
->hpos
;
21857 int saved_face_id
= it
->face_id
;
21858 struct glyph_row
*row
= it
->glyph_row
;
21859 ptrdiff_t it_charpos
;
21861 /* Initialize the iterator IT for iteration over STRING beginning
21862 with index START. */
21863 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21864 precision
, field_width
, multibyte
);
21865 if (string
&& STRINGP (lisp_string
))
21866 /* LISP_STRING is the one returned by decode_mode_spec. We should
21867 ignore its text properties. */
21868 it
->stop_charpos
= it
->end_charpos
;
21870 /* If displaying STRING, set up the face of the iterator from
21871 FACE_STRING, if that's given. */
21872 if (STRINGP (face_string
))
21878 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21879 0, it
->region_beg_charpos
,
21880 it
->region_end_charpos
,
21881 &endptr
, it
->base_face_id
, 0);
21882 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21883 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21886 /* Set max_x to the maximum allowed X position. Don't let it go
21887 beyond the right edge of the window. */
21889 max_x
= it
->last_visible_x
;
21891 max_x
= min (max_x
, it
->last_visible_x
);
21893 /* Skip over display elements that are not visible. because IT->w is
21895 if (it
->current_x
< it
->first_visible_x
)
21896 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21897 MOVE_TO_POS
| MOVE_TO_X
);
21899 row
->ascent
= it
->max_ascent
;
21900 row
->height
= it
->max_ascent
+ it
->max_descent
;
21901 row
->phys_ascent
= it
->max_phys_ascent
;
21902 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21903 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21905 if (STRINGP (it
->string
))
21906 it_charpos
= IT_STRING_CHARPOS (*it
);
21908 it_charpos
= IT_CHARPOS (*it
);
21910 /* This condition is for the case that we are called with current_x
21911 past last_visible_x. */
21912 while (it
->current_x
< max_x
)
21914 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21916 /* Get the next display element. */
21917 if (!get_next_display_element (it
))
21920 /* Produce glyphs. */
21921 x_before
= it
->current_x
;
21922 n_glyphs_before
= row
->used
[TEXT_AREA
];
21923 PRODUCE_GLYPHS (it
);
21925 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21928 while (i
< nglyphs
)
21930 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21932 if (it
->line_wrap
!= TRUNCATE
21933 && x
+ glyph
->pixel_width
> max_x
)
21935 /* End of continued line or max_x reached. */
21936 if (CHAR_GLYPH_PADDING_P (*glyph
))
21938 /* A wide character is unbreakable. */
21939 if (row
->reversed_p
)
21940 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21941 - n_glyphs_before
);
21942 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21943 it
->current_x
= x_before
;
21947 if (row
->reversed_p
)
21948 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21949 - (n_glyphs_before
+ i
));
21950 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21955 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21957 /* Glyph is at least partially visible. */
21959 if (x
< it
->first_visible_x
)
21960 row
->x
= x
- it
->first_visible_x
;
21964 /* Glyph is off the left margin of the display area.
21965 Should not happen. */
21969 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21970 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21971 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21972 row
->phys_height
= max (row
->phys_height
,
21973 it
->max_phys_ascent
+ it
->max_phys_descent
);
21974 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21975 it
->max_extra_line_spacing
);
21976 x
+= glyph
->pixel_width
;
21980 /* Stop if max_x reached. */
21984 /* Stop at line ends. */
21985 if (ITERATOR_AT_END_OF_LINE_P (it
))
21987 it
->continuation_lines_width
= 0;
21991 set_iterator_to_next (it
, 1);
21992 if (STRINGP (it
->string
))
21993 it_charpos
= IT_STRING_CHARPOS (*it
);
21995 it_charpos
= IT_CHARPOS (*it
);
21997 /* Stop if truncating at the right edge. */
21998 if (it
->line_wrap
== TRUNCATE
21999 && it
->current_x
>= it
->last_visible_x
)
22001 /* Add truncation mark, but don't do it if the line is
22002 truncated at a padding space. */
22003 if (it_charpos
< it
->string_nchars
)
22005 if (!FRAME_WINDOW_P (it
->f
))
22009 if (it
->current_x
> it
->last_visible_x
)
22011 if (!row
->reversed_p
)
22013 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22014 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22019 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22020 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22022 unproduce_glyphs (it
, ii
+ 1);
22023 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22025 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22027 row
->used
[TEXT_AREA
] = ii
;
22028 produce_special_glyphs (it
, IT_TRUNCATION
);
22031 produce_special_glyphs (it
, IT_TRUNCATION
);
22033 row
->truncated_on_right_p
= 1;
22039 /* Maybe insert a truncation at the left. */
22040 if (it
->first_visible_x
22043 if (!FRAME_WINDOW_P (it
->f
)
22044 || (row
->reversed_p
22045 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22046 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22047 insert_left_trunc_glyphs (it
);
22048 row
->truncated_on_left_p
= 1;
22051 it
->face_id
= saved_face_id
;
22053 /* Value is number of columns displayed. */
22054 return it
->hpos
- hpos_at_start
;
22059 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22060 appears as an element of LIST or as the car of an element of LIST.
22061 If PROPVAL is a list, compare each element against LIST in that
22062 way, and return 1/2 if any element of PROPVAL is found in LIST.
22063 Otherwise return 0. This function cannot quit.
22064 The return value is 2 if the text is invisible but with an ellipsis
22065 and 1 if it's invisible and without an ellipsis. */
22068 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22070 register Lisp_Object tail
, proptail
;
22072 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22074 register Lisp_Object tem
;
22076 if (EQ (propval
, tem
))
22078 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22079 return NILP (XCDR (tem
)) ? 1 : 2;
22082 if (CONSP (propval
))
22084 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22086 Lisp_Object propelt
;
22087 propelt
= XCAR (proptail
);
22088 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22090 register Lisp_Object tem
;
22092 if (EQ (propelt
, tem
))
22094 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22095 return NILP (XCDR (tem
)) ? 1 : 2;
22103 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22104 doc
: /* Non-nil if the property makes the text invisible.
22105 POS-OR-PROP can be a marker or number, in which case it is taken to be
22106 a position in the current buffer and the value of the `invisible' property
22107 is checked; or it can be some other value, which is then presumed to be the
22108 value of the `invisible' property of the text of interest.
22109 The non-nil value returned can be t for truly invisible text or something
22110 else if the text is replaced by an ellipsis. */)
22111 (Lisp_Object pos_or_prop
)
22114 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22115 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22117 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22118 return (invis
== 0 ? Qnil
22120 : make_number (invis
));
22123 /* Calculate a width or height in pixels from a specification using
22124 the following elements:
22127 NUM - a (fractional) multiple of the default font width/height
22128 (NUM) - specifies exactly NUM pixels
22129 UNIT - a fixed number of pixels, see below.
22130 ELEMENT - size of a display element in pixels, see below.
22131 (NUM . SPEC) - equals NUM * SPEC
22132 (+ SPEC SPEC ...) - add pixel values
22133 (- SPEC SPEC ...) - subtract pixel values
22134 (- SPEC) - negate pixel value
22137 INT or FLOAT - a number constant
22138 SYMBOL - use symbol's (buffer local) variable binding.
22141 in - pixels per inch *)
22142 mm - pixels per 1/1000 meter *)
22143 cm - pixels per 1/100 meter *)
22144 width - width of current font in pixels.
22145 height - height of current font in pixels.
22147 *) using the ratio(s) defined in display-pixels-per-inch.
22151 left-fringe - left fringe width in pixels
22152 right-fringe - right fringe width in pixels
22154 left-margin - left margin width in pixels
22155 right-margin - right margin width in pixels
22157 scroll-bar - scroll-bar area width in pixels
22161 Pixels corresponding to 5 inches:
22164 Total width of non-text areas on left side of window (if scroll-bar is on left):
22165 '(space :width (+ left-fringe left-margin scroll-bar))
22167 Align to first text column (in header line):
22168 '(space :align-to 0)
22170 Align to middle of text area minus half the width of variable `my-image'
22171 containing a loaded image:
22172 '(space :align-to (0.5 . (- text my-image)))
22174 Width of left margin minus width of 1 character in the default font:
22175 '(space :width (- left-margin 1))
22177 Width of left margin minus width of 2 characters in the current font:
22178 '(space :width (- left-margin (2 . width)))
22180 Center 1 character over left-margin (in header line):
22181 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22183 Different ways to express width of left fringe plus left margin minus one pixel:
22184 '(space :width (- (+ left-fringe left-margin) (1)))
22185 '(space :width (+ left-fringe left-margin (- (1))))
22186 '(space :width (+ left-fringe left-margin (-1)))
22190 #define NUMVAL(X) \
22191 ((INTEGERP (X) || FLOATP (X)) \
22196 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22197 struct font
*font
, int width_p
, int *align_to
)
22201 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22202 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22205 return OK_PIXELS (0);
22207 eassert (FRAME_LIVE_P (it
->f
));
22209 if (SYMBOLP (prop
))
22211 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22213 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22215 if (unit
[0] == 'i' && unit
[1] == 'n')
22217 else if (unit
[0] == 'm' && unit
[1] == 'm')
22219 else if (unit
[0] == 'c' && unit
[1] == 'm')
22226 #ifdef HAVE_WINDOW_SYSTEM
22227 if (FRAME_WINDOW_P (it
->f
)
22229 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22230 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22232 return OK_PIXELS (ppi
/ pixels
);
22235 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22236 || (CONSP (Vdisplay_pixels_per_inch
)
22238 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22239 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22241 return OK_PIXELS (ppi
/ pixels
);
22247 #ifdef HAVE_WINDOW_SYSTEM
22248 if (EQ (prop
, Qheight
))
22249 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22250 if (EQ (prop
, Qwidth
))
22251 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22253 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22254 return OK_PIXELS (1);
22257 if (EQ (prop
, Qtext
))
22258 return OK_PIXELS (width_p
22259 ? window_box_width (it
->w
, TEXT_AREA
)
22260 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22262 if (align_to
&& *align_to
< 0)
22265 if (EQ (prop
, Qleft
))
22266 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22267 if (EQ (prop
, Qright
))
22268 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22269 if (EQ (prop
, Qcenter
))
22270 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22271 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22272 if (EQ (prop
, Qleft_fringe
))
22273 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22274 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22275 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22276 if (EQ (prop
, Qright_fringe
))
22277 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22278 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22279 : window_box_right_offset (it
->w
, TEXT_AREA
));
22280 if (EQ (prop
, Qleft_margin
))
22281 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22282 if (EQ (prop
, Qright_margin
))
22283 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22284 if (EQ (prop
, Qscroll_bar
))
22285 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22287 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22288 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22289 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22294 if (EQ (prop
, Qleft_fringe
))
22295 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22296 if (EQ (prop
, Qright_fringe
))
22297 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22298 if (EQ (prop
, Qleft_margin
))
22299 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22300 if (EQ (prop
, Qright_margin
))
22301 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22302 if (EQ (prop
, Qscroll_bar
))
22303 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22306 prop
= buffer_local_value_1 (prop
, WVAR (it
->w
, buffer
));
22307 if (EQ (prop
, Qunbound
))
22311 if (INTEGERP (prop
) || FLOATP (prop
))
22313 int base_unit
= (width_p
22314 ? FRAME_COLUMN_WIDTH (it
->f
)
22315 : FRAME_LINE_HEIGHT (it
->f
));
22316 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22321 Lisp_Object car
= XCAR (prop
);
22322 Lisp_Object cdr
= XCDR (prop
);
22326 #ifdef HAVE_WINDOW_SYSTEM
22327 if (FRAME_WINDOW_P (it
->f
)
22328 && valid_image_p (prop
))
22330 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22331 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22333 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22336 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22342 while (CONSP (cdr
))
22344 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22345 font
, width_p
, align_to
))
22348 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22353 if (EQ (car
, Qminus
))
22355 return OK_PIXELS (pixels
);
22358 car
= buffer_local_value_1 (car
, WVAR (it
->w
, buffer
));
22359 if (EQ (car
, Qunbound
))
22363 if (INTEGERP (car
) || FLOATP (car
))
22366 pixels
= XFLOATINT (car
);
22368 return OK_PIXELS (pixels
);
22369 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22370 font
, width_p
, align_to
))
22371 return OK_PIXELS (pixels
* fact
);
22382 /***********************************************************************
22384 ***********************************************************************/
22386 #ifdef HAVE_WINDOW_SYSTEM
22391 dump_glyph_string (struct glyph_string
*s
)
22393 fprintf (stderr
, "glyph string\n");
22394 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22395 s
->x
, s
->y
, s
->width
, s
->height
);
22396 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22397 fprintf (stderr
, " hl = %d\n", s
->hl
);
22398 fprintf (stderr
, " left overhang = %d, right = %d\n",
22399 s
->left_overhang
, s
->right_overhang
);
22400 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22401 fprintf (stderr
, " extends to end of line = %d\n",
22402 s
->extends_to_end_of_line_p
);
22403 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22404 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22407 #endif /* GLYPH_DEBUG */
22409 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22410 of XChar2b structures for S; it can't be allocated in
22411 init_glyph_string because it must be allocated via `alloca'. W
22412 is the window on which S is drawn. ROW and AREA are the glyph row
22413 and area within the row from which S is constructed. START is the
22414 index of the first glyph structure covered by S. HL is a
22415 face-override for drawing S. */
22418 #define OPTIONAL_HDC(hdc) HDC hdc,
22419 #define DECLARE_HDC(hdc) HDC hdc;
22420 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22421 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22424 #ifndef OPTIONAL_HDC
22425 #define OPTIONAL_HDC(hdc)
22426 #define DECLARE_HDC(hdc)
22427 #define ALLOCATE_HDC(hdc, f)
22428 #define RELEASE_HDC(hdc, f)
22432 init_glyph_string (struct glyph_string
*s
,
22434 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22435 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22437 memset (s
, 0, sizeof *s
);
22439 s
->f
= XFRAME (WVAR (w
, frame
));
22443 s
->display
= FRAME_X_DISPLAY (s
->f
);
22444 s
->window
= FRAME_X_WINDOW (s
->f
);
22445 s
->char2b
= char2b
;
22449 s
->first_glyph
= row
->glyphs
[area
] + start
;
22450 s
->height
= row
->height
;
22451 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22452 s
->ybase
= s
->y
+ row
->ascent
;
22456 /* Append the list of glyph strings with head H and tail T to the list
22457 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22460 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22461 struct glyph_string
*h
, struct glyph_string
*t
)
22475 /* Prepend the list of glyph strings with head H and tail T to the
22476 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22480 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22481 struct glyph_string
*h
, struct glyph_string
*t
)
22495 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22496 Set *HEAD and *TAIL to the resulting list. */
22499 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22500 struct glyph_string
*s
)
22502 s
->next
= s
->prev
= NULL
;
22503 append_glyph_string_lists (head
, tail
, s
, s
);
22507 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22508 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22509 make sure that X resources for the face returned are allocated.
22510 Value is a pointer to a realized face that is ready for display if
22511 DISPLAY_P is non-zero. */
22513 static inline struct face
*
22514 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22515 XChar2b
*char2b
, int display_p
)
22517 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22521 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22523 if (code
!= FONT_INVALID_CODE
)
22524 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22526 STORE_XCHAR2B (char2b
, 0, 0);
22529 /* Make sure X resources of the face are allocated. */
22530 #ifdef HAVE_X_WINDOWS
22534 eassert (face
!= NULL
);
22535 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22542 /* Get face and two-byte form of character glyph GLYPH on frame F.
22543 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22544 a pointer to a realized face that is ready for display. */
22546 static inline struct face
*
22547 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22548 XChar2b
*char2b
, int *two_byte_p
)
22552 eassert (glyph
->type
== CHAR_GLYPH
);
22553 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22562 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22563 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22565 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22567 if (code
!= FONT_INVALID_CODE
)
22568 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22570 STORE_XCHAR2B (char2b
, 0, 0);
22573 /* Make sure X resources of the face are allocated. */
22574 eassert (face
!= NULL
);
22575 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22580 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22581 Return 1 if FONT has a glyph for C, otherwise return 0. */
22584 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22588 if (CHAR_BYTE8_P (c
))
22589 code
= CHAR_TO_BYTE8 (c
);
22591 code
= font
->driver
->encode_char (font
, c
);
22593 if (code
== FONT_INVALID_CODE
)
22595 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22600 /* Fill glyph string S with composition components specified by S->cmp.
22602 BASE_FACE is the base face of the composition.
22603 S->cmp_from is the index of the first component for S.
22605 OVERLAPS non-zero means S should draw the foreground only, and use
22606 its physical height for clipping. See also draw_glyphs.
22608 Value is the index of a component not in S. */
22611 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22615 /* For all glyphs of this composition, starting at the offset
22616 S->cmp_from, until we reach the end of the definition or encounter a
22617 glyph that requires the different face, add it to S. */
22622 s
->for_overlaps
= overlaps
;
22625 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22627 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22629 /* TAB in a composition means display glyphs with padding space
22630 on the left or right. */
22633 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22636 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22643 s
->font
= s
->face
->font
;
22645 else if (s
->face
!= face
)
22653 if (s
->face
== NULL
)
22655 s
->face
= base_face
->ascii_face
;
22656 s
->font
= s
->face
->font
;
22659 /* All glyph strings for the same composition has the same width,
22660 i.e. the width set for the first component of the composition. */
22661 s
->width
= s
->first_glyph
->pixel_width
;
22663 /* If the specified font could not be loaded, use the frame's
22664 default font, but record the fact that we couldn't load it in
22665 the glyph string so that we can draw rectangles for the
22666 characters of the glyph string. */
22667 if (s
->font
== NULL
)
22669 s
->font_not_found_p
= 1;
22670 s
->font
= FRAME_FONT (s
->f
);
22673 /* Adjust base line for subscript/superscript text. */
22674 s
->ybase
+= s
->first_glyph
->voffset
;
22676 /* This glyph string must always be drawn with 16-bit functions. */
22683 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22684 int start
, int end
, int overlaps
)
22686 struct glyph
*glyph
, *last
;
22687 Lisp_Object lgstring
;
22690 s
->for_overlaps
= overlaps
;
22691 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22692 last
= s
->row
->glyphs
[s
->area
] + end
;
22693 s
->cmp_id
= glyph
->u
.cmp
.id
;
22694 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22695 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22696 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22697 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22698 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22700 while (glyph
< last
22701 && glyph
->u
.cmp
.automatic
22702 && glyph
->u
.cmp
.id
== s
->cmp_id
22703 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22704 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22706 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22708 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22709 unsigned code
= LGLYPH_CODE (lglyph
);
22711 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22713 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22714 return glyph
- s
->row
->glyphs
[s
->area
];
22718 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22719 See the comment of fill_glyph_string for arguments.
22720 Value is the index of the first glyph not in S. */
22724 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22725 int start
, int end
, int overlaps
)
22727 struct glyph
*glyph
, *last
;
22730 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22731 s
->for_overlaps
= overlaps
;
22732 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22733 last
= s
->row
->glyphs
[s
->area
] + end
;
22734 voffset
= glyph
->voffset
;
22735 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22736 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22738 s
->width
= glyph
->pixel_width
;
22740 while (glyph
< last
22741 && glyph
->type
== GLYPHLESS_GLYPH
22742 && glyph
->voffset
== voffset
22743 && glyph
->face_id
== face_id
)
22746 s
->width
+= glyph
->pixel_width
;
22749 s
->ybase
+= voffset
;
22750 return glyph
- s
->row
->glyphs
[s
->area
];
22754 /* Fill glyph string S from a sequence of character glyphs.
22756 FACE_ID is the face id of the string. START is the index of the
22757 first glyph to consider, END is the index of the last + 1.
22758 OVERLAPS non-zero means S should draw the foreground only, and use
22759 its physical height for clipping. See also draw_glyphs.
22761 Value is the index of the first glyph not in S. */
22764 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22765 int start
, int end
, int overlaps
)
22767 struct glyph
*glyph
, *last
;
22769 int glyph_not_available_p
;
22771 eassert (s
->f
== XFRAME (WVAR (s
->w
, frame
)));
22772 eassert (s
->nchars
== 0);
22773 eassert (start
>= 0 && end
> start
);
22775 s
->for_overlaps
= overlaps
;
22776 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22777 last
= s
->row
->glyphs
[s
->area
] + end
;
22778 voffset
= glyph
->voffset
;
22779 s
->padding_p
= glyph
->padding_p
;
22780 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22782 while (glyph
< last
22783 && glyph
->type
== CHAR_GLYPH
22784 && glyph
->voffset
== voffset
22785 /* Same face id implies same font, nowadays. */
22786 && glyph
->face_id
== face_id
22787 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22791 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22792 s
->char2b
+ s
->nchars
,
22794 s
->two_byte_p
= two_byte_p
;
22796 eassert (s
->nchars
<= end
- start
);
22797 s
->width
+= glyph
->pixel_width
;
22798 if (glyph
++->padding_p
!= s
->padding_p
)
22802 s
->font
= s
->face
->font
;
22804 /* If the specified font could not be loaded, use the frame's font,
22805 but record the fact that we couldn't load it in
22806 S->font_not_found_p so that we can draw rectangles for the
22807 characters of the glyph string. */
22808 if (s
->font
== NULL
|| glyph_not_available_p
)
22810 s
->font_not_found_p
= 1;
22811 s
->font
= FRAME_FONT (s
->f
);
22814 /* Adjust base line for subscript/superscript text. */
22815 s
->ybase
+= voffset
;
22817 eassert (s
->face
&& s
->face
->gc
);
22818 return glyph
- s
->row
->glyphs
[s
->area
];
22822 /* Fill glyph string S from image glyph S->first_glyph. */
22825 fill_image_glyph_string (struct glyph_string
*s
)
22827 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22828 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22830 s
->slice
= s
->first_glyph
->slice
.img
;
22831 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22832 s
->font
= s
->face
->font
;
22833 s
->width
= s
->first_glyph
->pixel_width
;
22835 /* Adjust base line for subscript/superscript text. */
22836 s
->ybase
+= s
->first_glyph
->voffset
;
22840 /* Fill glyph string S from a sequence of stretch glyphs.
22842 START is the index of the first glyph to consider,
22843 END is the index of the last + 1.
22845 Value is the index of the first glyph not in S. */
22848 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22850 struct glyph
*glyph
, *last
;
22851 int voffset
, face_id
;
22853 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22855 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22856 last
= s
->row
->glyphs
[s
->area
] + end
;
22857 face_id
= glyph
->face_id
;
22858 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22859 s
->font
= s
->face
->font
;
22860 s
->width
= glyph
->pixel_width
;
22862 voffset
= glyph
->voffset
;
22866 && glyph
->type
== STRETCH_GLYPH
22867 && glyph
->voffset
== voffset
22868 && glyph
->face_id
== face_id
);
22870 s
->width
+= glyph
->pixel_width
;
22872 /* Adjust base line for subscript/superscript text. */
22873 s
->ybase
+= voffset
;
22875 /* The case that face->gc == 0 is handled when drawing the glyph
22876 string by calling PREPARE_FACE_FOR_DISPLAY. */
22878 return glyph
- s
->row
->glyphs
[s
->area
];
22881 static struct font_metrics
*
22882 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22884 static struct font_metrics metrics
;
22885 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22887 if (! font
|| code
== FONT_INVALID_CODE
)
22889 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22894 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22895 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22896 assumed to be zero. */
22899 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22901 *left
= *right
= 0;
22903 if (glyph
->type
== CHAR_GLYPH
)
22907 struct font_metrics
*pcm
;
22909 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22910 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22912 if (pcm
->rbearing
> pcm
->width
)
22913 *right
= pcm
->rbearing
- pcm
->width
;
22914 if (pcm
->lbearing
< 0)
22915 *left
= -pcm
->lbearing
;
22918 else if (glyph
->type
== COMPOSITE_GLYPH
)
22920 if (! glyph
->u
.cmp
.automatic
)
22922 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22924 if (cmp
->rbearing
> cmp
->pixel_width
)
22925 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22926 if (cmp
->lbearing
< 0)
22927 *left
= - cmp
->lbearing
;
22931 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22932 struct font_metrics metrics
;
22934 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22935 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22936 if (metrics
.rbearing
> metrics
.width
)
22937 *right
= metrics
.rbearing
- metrics
.width
;
22938 if (metrics
.lbearing
< 0)
22939 *left
= - metrics
.lbearing
;
22945 /* Return the index of the first glyph preceding glyph string S that
22946 is overwritten by S because of S's left overhang. Value is -1
22947 if no glyphs are overwritten. */
22950 left_overwritten (struct glyph_string
*s
)
22954 if (s
->left_overhang
)
22957 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22958 int first
= s
->first_glyph
- glyphs
;
22960 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22961 x
-= glyphs
[i
].pixel_width
;
22972 /* Return the index of the first glyph preceding glyph string S that
22973 is overwriting S because of its right overhang. Value is -1 if no
22974 glyph in front of S overwrites S. */
22977 left_overwriting (struct glyph_string
*s
)
22980 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22981 int first
= s
->first_glyph
- glyphs
;
22985 for (i
= first
- 1; i
>= 0; --i
)
22988 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22991 x
-= glyphs
[i
].pixel_width
;
22998 /* Return the index of the last glyph following glyph string S that is
22999 overwritten by S because of S's right overhang. Value is -1 if
23000 no such glyph is found. */
23003 right_overwritten (struct glyph_string
*s
)
23007 if (s
->right_overhang
)
23010 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23011 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
23012 int end
= s
->row
->used
[s
->area
];
23014 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23015 x
+= glyphs
[i
].pixel_width
;
23024 /* Return the index of the last glyph following glyph string S that
23025 overwrites S because of its left overhang. Value is negative
23026 if no such glyph is found. */
23029 right_overwriting (struct glyph_string
*s
)
23032 int end
= s
->row
->used
[s
->area
];
23033 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23034 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
23038 for (i
= first
; i
< end
; ++i
)
23041 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23044 x
+= glyphs
[i
].pixel_width
;
23051 /* Set background width of glyph string S. START is the index of the
23052 first glyph following S. LAST_X is the right-most x-position + 1
23053 in the drawing area. */
23056 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23058 /* If the face of this glyph string has to be drawn to the end of
23059 the drawing area, set S->extends_to_end_of_line_p. */
23061 if (start
== s
->row
->used
[s
->area
]
23062 && s
->area
== TEXT_AREA
23063 && ((s
->row
->fill_line_p
23064 && (s
->hl
== DRAW_NORMAL_TEXT
23065 || s
->hl
== DRAW_IMAGE_RAISED
23066 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23067 || s
->hl
== DRAW_MOUSE_FACE
))
23068 s
->extends_to_end_of_line_p
= 1;
23070 /* If S extends its face to the end of the line, set its
23071 background_width to the distance to the right edge of the drawing
23073 if (s
->extends_to_end_of_line_p
)
23074 s
->background_width
= last_x
- s
->x
+ 1;
23076 s
->background_width
= s
->width
;
23080 /* Compute overhangs and x-positions for glyph string S and its
23081 predecessors, or successors. X is the starting x-position for S.
23082 BACKWARD_P non-zero means process predecessors. */
23085 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23091 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23092 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23102 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23103 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23113 /* The following macros are only called from draw_glyphs below.
23114 They reference the following parameters of that function directly:
23115 `w', `row', `area', and `overlap_p'
23116 as well as the following local variables:
23117 `s', `f', and `hdc' (in W32) */
23120 /* On W32, silently add local `hdc' variable to argument list of
23121 init_glyph_string. */
23122 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23123 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23125 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23126 init_glyph_string (s, char2b, w, row, area, start, hl)
23129 /* Add a glyph string for a stretch glyph to the list of strings
23130 between HEAD and TAIL. START is the index of the stretch glyph in
23131 row area AREA of glyph row ROW. END is the index of the last glyph
23132 in that glyph row area. X is the current output position assigned
23133 to the new glyph string constructed. HL overrides that face of the
23134 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23135 is the right-most x-position of the drawing area. */
23137 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23138 and below -- keep them on one line. */
23139 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23142 s = alloca (sizeof *s); \
23143 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23144 START = fill_stretch_glyph_string (s, START, END); \
23145 append_glyph_string (&HEAD, &TAIL, s); \
23151 /* Add a glyph string for an image glyph to the list of strings
23152 between HEAD and TAIL. START is the index of the image glyph in
23153 row area AREA of glyph row ROW. END is the index of the last glyph
23154 in that glyph row area. X is the current output position assigned
23155 to the new glyph string constructed. HL overrides that face of the
23156 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23157 is the right-most x-position of the drawing area. */
23159 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23162 s = alloca (sizeof *s); \
23163 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23164 fill_image_glyph_string (s); \
23165 append_glyph_string (&HEAD, &TAIL, s); \
23172 /* Add a glyph string for a sequence of character glyphs to the list
23173 of strings between HEAD and TAIL. START is the index of the first
23174 glyph in row area AREA of glyph row ROW that is part of the new
23175 glyph string. END is the index of the last glyph in that glyph row
23176 area. X is the current output position assigned to the new glyph
23177 string constructed. HL overrides that face of the glyph; e.g. it
23178 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23179 right-most x-position of the drawing area. */
23181 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23187 face_id = (row)->glyphs[area][START].face_id; \
23189 s = alloca (sizeof *s); \
23190 char2b = alloca ((END - START) * sizeof *char2b); \
23191 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23192 append_glyph_string (&HEAD, &TAIL, s); \
23194 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23199 /* Add a glyph string for a composite sequence to the list of strings
23200 between HEAD and TAIL. START is the index of the first glyph in
23201 row area AREA of glyph row ROW that is part of the new glyph
23202 string. END is the index of the last glyph in that glyph row area.
23203 X is the current output position assigned to the new glyph string
23204 constructed. HL overrides that face of the glyph; e.g. it is
23205 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23206 x-position of the drawing area. */
23208 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23210 int face_id = (row)->glyphs[area][START].face_id; \
23211 struct face *base_face = FACE_FROM_ID (f, face_id); \
23212 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23213 struct composition *cmp = composition_table[cmp_id]; \
23215 struct glyph_string *first_s = NULL; \
23218 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23220 /* Make glyph_strings for each glyph sequence that is drawable by \
23221 the same face, and append them to HEAD/TAIL. */ \
23222 for (n = 0; n < cmp->glyph_len;) \
23224 s = alloca (sizeof *s); \
23225 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23226 append_glyph_string (&(HEAD), &(TAIL), s); \
23232 n = fill_composite_glyph_string (s, base_face, overlaps); \
23240 /* Add a glyph string for a glyph-string sequence to the list of strings
23241 between HEAD and TAIL. */
23243 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23247 Lisp_Object gstring; \
23249 face_id = (row)->glyphs[area][START].face_id; \
23250 gstring = (composition_gstring_from_id \
23251 ((row)->glyphs[area][START].u.cmp.id)); \
23252 s = alloca (sizeof *s); \
23253 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23254 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23255 append_glyph_string (&(HEAD), &(TAIL), s); \
23257 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23261 /* Add a glyph string for a sequence of glyphless character's glyphs
23262 to the list of strings between HEAD and TAIL. The meanings of
23263 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23265 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23270 face_id = (row)->glyphs[area][START].face_id; \
23272 s = alloca (sizeof *s); \
23273 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23274 append_glyph_string (&HEAD, &TAIL, s); \
23276 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23282 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23283 of AREA of glyph row ROW on window W between indices START and END.
23284 HL overrides the face for drawing glyph strings, e.g. it is
23285 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23286 x-positions of the drawing area.
23288 This is an ugly monster macro construct because we must use alloca
23289 to allocate glyph strings (because draw_glyphs can be called
23290 asynchronously). */
23292 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23295 HEAD = TAIL = NULL; \
23296 while (START < END) \
23298 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23299 switch (first_glyph->type) \
23302 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23306 case COMPOSITE_GLYPH: \
23307 if (first_glyph->u.cmp.automatic) \
23308 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23311 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23315 case STRETCH_GLYPH: \
23316 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23320 case IMAGE_GLYPH: \
23321 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23325 case GLYPHLESS_GLYPH: \
23326 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23336 set_glyph_string_background_width (s, START, LAST_X); \
23343 /* Draw glyphs between START and END in AREA of ROW on window W,
23344 starting at x-position X. X is relative to AREA in W. HL is a
23345 face-override with the following meaning:
23347 DRAW_NORMAL_TEXT draw normally
23348 DRAW_CURSOR draw in cursor face
23349 DRAW_MOUSE_FACE draw in mouse face.
23350 DRAW_INVERSE_VIDEO draw in mode line face
23351 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23352 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23354 If OVERLAPS is non-zero, draw only the foreground of characters and
23355 clip to the physical height of ROW. Non-zero value also defines
23356 the overlapping part to be drawn:
23358 OVERLAPS_PRED overlap with preceding rows
23359 OVERLAPS_SUCC overlap with succeeding rows
23360 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23361 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23363 Value is the x-position reached, relative to AREA of W. */
23366 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23367 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23368 enum draw_glyphs_face hl
, int overlaps
)
23370 struct glyph_string
*head
, *tail
;
23371 struct glyph_string
*s
;
23372 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23373 int i
, j
, x_reached
, last_x
, area_left
= 0;
23374 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23377 ALLOCATE_HDC (hdc
, f
);
23379 /* Let's rather be paranoid than getting a SEGV. */
23380 end
= min (end
, row
->used
[area
]);
23381 start
= max (0, start
);
23382 start
= min (end
, start
);
23384 /* Translate X to frame coordinates. Set last_x to the right
23385 end of the drawing area. */
23386 if (row
->full_width_p
)
23388 /* X is relative to the left edge of W, without scroll bars
23390 area_left
= WINDOW_LEFT_EDGE_X (w
);
23391 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23395 area_left
= window_box_left (w
, area
);
23396 last_x
= area_left
+ window_box_width (w
, area
);
23400 /* Build a doubly-linked list of glyph_string structures between
23401 head and tail from what we have to draw. Note that the macro
23402 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23403 the reason we use a separate variable `i'. */
23405 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23407 x_reached
= tail
->x
+ tail
->background_width
;
23411 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23412 the row, redraw some glyphs in front or following the glyph
23413 strings built above. */
23414 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23416 struct glyph_string
*h
, *t
;
23417 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23418 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23419 int check_mouse_face
= 0;
23422 /* If mouse highlighting is on, we may need to draw adjacent
23423 glyphs using mouse-face highlighting. */
23424 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23426 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23428 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23429 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23431 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23433 check_mouse_face
= 1;
23434 mouse_beg_col
= (row
== mouse_beg_row
)
23435 ? hlinfo
->mouse_face_beg_col
: 0;
23436 mouse_end_col
= (row
== mouse_end_row
)
23437 ? hlinfo
->mouse_face_end_col
23438 : row
->used
[TEXT_AREA
];
23442 /* Compute overhangs for all glyph strings. */
23443 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23444 for (s
= head
; s
; s
= s
->next
)
23445 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23447 /* Prepend glyph strings for glyphs in front of the first glyph
23448 string that are overwritten because of the first glyph
23449 string's left overhang. The background of all strings
23450 prepended must be drawn because the first glyph string
23452 i
= left_overwritten (head
);
23455 enum draw_glyphs_face overlap_hl
;
23457 /* If this row contains mouse highlighting, attempt to draw
23458 the overlapped glyphs with the correct highlight. This
23459 code fails if the overlap encompasses more than one glyph
23460 and mouse-highlight spans only some of these glyphs.
23461 However, making it work perfectly involves a lot more
23462 code, and I don't know if the pathological case occurs in
23463 practice, so we'll stick to this for now. --- cyd */
23464 if (check_mouse_face
23465 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23466 overlap_hl
= DRAW_MOUSE_FACE
;
23468 overlap_hl
= DRAW_NORMAL_TEXT
;
23471 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23472 overlap_hl
, dummy_x
, last_x
);
23474 compute_overhangs_and_x (t
, head
->x
, 1);
23475 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23479 /* Prepend glyph strings for glyphs in front of the first glyph
23480 string that overwrite that glyph string because of their
23481 right overhang. For these strings, only the foreground must
23482 be drawn, because it draws over the glyph string at `head'.
23483 The background must not be drawn because this would overwrite
23484 right overhangs of preceding glyphs for which no glyph
23486 i
= left_overwriting (head
);
23489 enum draw_glyphs_face overlap_hl
;
23491 if (check_mouse_face
23492 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23493 overlap_hl
= DRAW_MOUSE_FACE
;
23495 overlap_hl
= DRAW_NORMAL_TEXT
;
23498 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23499 overlap_hl
, dummy_x
, last_x
);
23500 for (s
= h
; s
; s
= s
->next
)
23501 s
->background_filled_p
= 1;
23502 compute_overhangs_and_x (t
, head
->x
, 1);
23503 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23506 /* Append glyphs strings for glyphs following the last glyph
23507 string tail that are overwritten by tail. The background of
23508 these strings has to be drawn because tail's foreground draws
23510 i
= right_overwritten (tail
);
23513 enum draw_glyphs_face overlap_hl
;
23515 if (check_mouse_face
23516 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23517 overlap_hl
= DRAW_MOUSE_FACE
;
23519 overlap_hl
= DRAW_NORMAL_TEXT
;
23521 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23522 overlap_hl
, x
, last_x
);
23523 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23524 we don't have `end = i;' here. */
23525 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23526 append_glyph_string_lists (&head
, &tail
, h
, t
);
23530 /* Append glyph strings for glyphs following the last glyph
23531 string tail that overwrite tail. The foreground of such
23532 glyphs has to be drawn because it writes into the background
23533 of tail. The background must not be drawn because it could
23534 paint over the foreground of following glyphs. */
23535 i
= right_overwriting (tail
);
23538 enum draw_glyphs_face overlap_hl
;
23539 if (check_mouse_face
23540 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23541 overlap_hl
= DRAW_MOUSE_FACE
;
23543 overlap_hl
= DRAW_NORMAL_TEXT
;
23546 i
++; /* We must include the Ith glyph. */
23547 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23548 overlap_hl
, x
, last_x
);
23549 for (s
= h
; s
; s
= s
->next
)
23550 s
->background_filled_p
= 1;
23551 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23552 append_glyph_string_lists (&head
, &tail
, h
, t
);
23554 if (clip_head
|| clip_tail
)
23555 for (s
= head
; s
; s
= s
->next
)
23557 s
->clip_head
= clip_head
;
23558 s
->clip_tail
= clip_tail
;
23562 /* Draw all strings. */
23563 for (s
= head
; s
; s
= s
->next
)
23564 FRAME_RIF (f
)->draw_glyph_string (s
);
23567 /* When focus a sole frame and move horizontally, this sets on_p to 0
23568 causing a failure to erase prev cursor position. */
23569 if (area
== TEXT_AREA
23570 && !row
->full_width_p
23571 /* When drawing overlapping rows, only the glyph strings'
23572 foreground is drawn, which doesn't erase a cursor
23576 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23577 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23578 : (tail
? tail
->x
+ tail
->background_width
: x
));
23582 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23583 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23587 /* Value is the x-position up to which drawn, relative to AREA of W.
23588 This doesn't include parts drawn because of overhangs. */
23589 if (row
->full_width_p
)
23590 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23592 x_reached
-= area_left
;
23594 RELEASE_HDC (hdc
, f
);
23599 /* Expand row matrix if too narrow. Don't expand if area
23602 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23604 if (!fonts_changed_p \
23605 && (it->glyph_row->glyphs[area] \
23606 < it->glyph_row->glyphs[area + 1])) \
23608 it->w->ncols_scale_factor++; \
23609 fonts_changed_p = 1; \
23613 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23614 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23617 append_glyph (struct it
*it
)
23619 struct glyph
*glyph
;
23620 enum glyph_row_area area
= it
->area
;
23622 eassert (it
->glyph_row
);
23623 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23625 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23626 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23628 /* If the glyph row is reversed, we need to prepend the glyph
23629 rather than append it. */
23630 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23634 /* Make room for the additional glyph. */
23635 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23637 glyph
= it
->glyph_row
->glyphs
[area
];
23639 glyph
->charpos
= CHARPOS (it
->position
);
23640 glyph
->object
= it
->object
;
23641 if (it
->pixel_width
> 0)
23643 glyph
->pixel_width
= it
->pixel_width
;
23644 glyph
->padding_p
= 0;
23648 /* Assure at least 1-pixel width. Otherwise, cursor can't
23649 be displayed correctly. */
23650 glyph
->pixel_width
= 1;
23651 glyph
->padding_p
= 1;
23653 glyph
->ascent
= it
->ascent
;
23654 glyph
->descent
= it
->descent
;
23655 glyph
->voffset
= it
->voffset
;
23656 glyph
->type
= CHAR_GLYPH
;
23657 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23658 glyph
->multibyte_p
= it
->multibyte_p
;
23659 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23660 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23661 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23662 || it
->phys_descent
> it
->descent
);
23663 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23664 glyph
->face_id
= it
->face_id
;
23665 glyph
->u
.ch
= it
->char_to_display
;
23666 glyph
->slice
.img
= null_glyph_slice
;
23667 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23670 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23671 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23673 glyph
->bidi_type
= it
->bidi_it
.type
;
23677 glyph
->resolved_level
= 0;
23678 glyph
->bidi_type
= UNKNOWN_BT
;
23680 ++it
->glyph_row
->used
[area
];
23683 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23686 /* Store one glyph for the composition IT->cmp_it.id in
23687 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23691 append_composite_glyph (struct it
*it
)
23693 struct glyph
*glyph
;
23694 enum glyph_row_area area
= it
->area
;
23696 eassert (it
->glyph_row
);
23698 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23699 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23701 /* If the glyph row is reversed, we need to prepend the glyph
23702 rather than append it. */
23703 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23707 /* Make room for the new glyph. */
23708 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23710 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23712 glyph
->charpos
= it
->cmp_it
.charpos
;
23713 glyph
->object
= it
->object
;
23714 glyph
->pixel_width
= it
->pixel_width
;
23715 glyph
->ascent
= it
->ascent
;
23716 glyph
->descent
= it
->descent
;
23717 glyph
->voffset
= it
->voffset
;
23718 glyph
->type
= COMPOSITE_GLYPH
;
23719 if (it
->cmp_it
.ch
< 0)
23721 glyph
->u
.cmp
.automatic
= 0;
23722 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23723 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23727 glyph
->u
.cmp
.automatic
= 1;
23728 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23729 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23730 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23732 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23733 glyph
->multibyte_p
= it
->multibyte_p
;
23734 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23735 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23736 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23737 || it
->phys_descent
> it
->descent
);
23738 glyph
->padding_p
= 0;
23739 glyph
->glyph_not_available_p
= 0;
23740 glyph
->face_id
= it
->face_id
;
23741 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23744 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23745 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23747 glyph
->bidi_type
= it
->bidi_it
.type
;
23749 ++it
->glyph_row
->used
[area
];
23752 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23756 /* Change IT->ascent and IT->height according to the setting of
23760 take_vertical_position_into_account (struct it
*it
)
23764 if (it
->voffset
< 0)
23765 /* Increase the ascent so that we can display the text higher
23767 it
->ascent
-= it
->voffset
;
23769 /* Increase the descent so that we can display the text lower
23771 it
->descent
+= it
->voffset
;
23776 /* Produce glyphs/get display metrics for the image IT is loaded with.
23777 See the description of struct display_iterator in dispextern.h for
23778 an overview of struct display_iterator. */
23781 produce_image_glyph (struct it
*it
)
23785 int glyph_ascent
, crop
;
23786 struct glyph_slice slice
;
23788 eassert (it
->what
== IT_IMAGE
);
23790 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23792 /* Make sure X resources of the face is loaded. */
23793 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23795 if (it
->image_id
< 0)
23797 /* Fringe bitmap. */
23798 it
->ascent
= it
->phys_ascent
= 0;
23799 it
->descent
= it
->phys_descent
= 0;
23800 it
->pixel_width
= 0;
23805 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23807 /* Make sure X resources of the image is loaded. */
23808 prepare_image_for_display (it
->f
, img
);
23810 slice
.x
= slice
.y
= 0;
23811 slice
.width
= img
->width
;
23812 slice
.height
= img
->height
;
23814 if (INTEGERP (it
->slice
.x
))
23815 slice
.x
= XINT (it
->slice
.x
);
23816 else if (FLOATP (it
->slice
.x
))
23817 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23819 if (INTEGERP (it
->slice
.y
))
23820 slice
.y
= XINT (it
->slice
.y
);
23821 else if (FLOATP (it
->slice
.y
))
23822 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23824 if (INTEGERP (it
->slice
.width
))
23825 slice
.width
= XINT (it
->slice
.width
);
23826 else if (FLOATP (it
->slice
.width
))
23827 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23829 if (INTEGERP (it
->slice
.height
))
23830 slice
.height
= XINT (it
->slice
.height
);
23831 else if (FLOATP (it
->slice
.height
))
23832 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23834 if (slice
.x
>= img
->width
)
23835 slice
.x
= img
->width
;
23836 if (slice
.y
>= img
->height
)
23837 slice
.y
= img
->height
;
23838 if (slice
.x
+ slice
.width
>= img
->width
)
23839 slice
.width
= img
->width
- slice
.x
;
23840 if (slice
.y
+ slice
.height
> img
->height
)
23841 slice
.height
= img
->height
- slice
.y
;
23843 if (slice
.width
== 0 || slice
.height
== 0)
23846 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23848 it
->descent
= slice
.height
- glyph_ascent
;
23850 it
->descent
+= img
->vmargin
;
23851 if (slice
.y
+ slice
.height
== img
->height
)
23852 it
->descent
+= img
->vmargin
;
23853 it
->phys_descent
= it
->descent
;
23855 it
->pixel_width
= slice
.width
;
23857 it
->pixel_width
+= img
->hmargin
;
23858 if (slice
.x
+ slice
.width
== img
->width
)
23859 it
->pixel_width
+= img
->hmargin
;
23861 /* It's quite possible for images to have an ascent greater than
23862 their height, so don't get confused in that case. */
23863 if (it
->descent
< 0)
23868 if (face
->box
!= FACE_NO_BOX
)
23870 if (face
->box_line_width
> 0)
23873 it
->ascent
+= face
->box_line_width
;
23874 if (slice
.y
+ slice
.height
== img
->height
)
23875 it
->descent
+= face
->box_line_width
;
23878 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23879 it
->pixel_width
+= eabs (face
->box_line_width
);
23880 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23881 it
->pixel_width
+= eabs (face
->box_line_width
);
23884 take_vertical_position_into_account (it
);
23886 /* Automatically crop wide image glyphs at right edge so we can
23887 draw the cursor on same display row. */
23888 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23889 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23891 it
->pixel_width
-= crop
;
23892 slice
.width
-= crop
;
23897 struct glyph
*glyph
;
23898 enum glyph_row_area area
= it
->area
;
23900 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23901 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23903 glyph
->charpos
= CHARPOS (it
->position
);
23904 glyph
->object
= it
->object
;
23905 glyph
->pixel_width
= it
->pixel_width
;
23906 glyph
->ascent
= glyph_ascent
;
23907 glyph
->descent
= it
->descent
;
23908 glyph
->voffset
= it
->voffset
;
23909 glyph
->type
= IMAGE_GLYPH
;
23910 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23911 glyph
->multibyte_p
= it
->multibyte_p
;
23912 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23913 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23914 glyph
->overlaps_vertically_p
= 0;
23915 glyph
->padding_p
= 0;
23916 glyph
->glyph_not_available_p
= 0;
23917 glyph
->face_id
= it
->face_id
;
23918 glyph
->u
.img_id
= img
->id
;
23919 glyph
->slice
.img
= slice
;
23920 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23923 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23924 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23926 glyph
->bidi_type
= it
->bidi_it
.type
;
23928 ++it
->glyph_row
->used
[area
];
23931 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23936 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23937 of the glyph, WIDTH and HEIGHT are the width and height of the
23938 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23941 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23942 int width
, int height
, int ascent
)
23944 struct glyph
*glyph
;
23945 enum glyph_row_area area
= it
->area
;
23947 eassert (ascent
>= 0 && ascent
<= height
);
23949 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23950 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23952 /* If the glyph row is reversed, we need to prepend the glyph
23953 rather than append it. */
23954 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23958 /* Make room for the additional glyph. */
23959 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23961 glyph
= it
->glyph_row
->glyphs
[area
];
23963 glyph
->charpos
= CHARPOS (it
->position
);
23964 glyph
->object
= object
;
23965 glyph
->pixel_width
= width
;
23966 glyph
->ascent
= ascent
;
23967 glyph
->descent
= height
- ascent
;
23968 glyph
->voffset
= it
->voffset
;
23969 glyph
->type
= STRETCH_GLYPH
;
23970 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23971 glyph
->multibyte_p
= it
->multibyte_p
;
23972 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23973 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23974 glyph
->overlaps_vertically_p
= 0;
23975 glyph
->padding_p
= 0;
23976 glyph
->glyph_not_available_p
= 0;
23977 glyph
->face_id
= it
->face_id
;
23978 glyph
->u
.stretch
.ascent
= ascent
;
23979 glyph
->u
.stretch
.height
= height
;
23980 glyph
->slice
.img
= null_glyph_slice
;
23981 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23984 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23985 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23987 glyph
->bidi_type
= it
->bidi_it
.type
;
23991 glyph
->resolved_level
= 0;
23992 glyph
->bidi_type
= UNKNOWN_BT
;
23994 ++it
->glyph_row
->used
[area
];
23997 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24000 #endif /* HAVE_WINDOW_SYSTEM */
24002 /* Produce a stretch glyph for iterator IT. IT->object is the value
24003 of the glyph property displayed. The value must be a list
24004 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24007 1. `:width WIDTH' specifies that the space should be WIDTH *
24008 canonical char width wide. WIDTH may be an integer or floating
24011 2. `:relative-width FACTOR' specifies that the width of the stretch
24012 should be computed from the width of the first character having the
24013 `glyph' property, and should be FACTOR times that width.
24015 3. `:align-to HPOS' specifies that the space should be wide enough
24016 to reach HPOS, a value in canonical character units.
24018 Exactly one of the above pairs must be present.
24020 4. `:height HEIGHT' specifies that the height of the stretch produced
24021 should be HEIGHT, measured in canonical character units.
24023 5. `:relative-height FACTOR' specifies that the height of the
24024 stretch should be FACTOR times the height of the characters having
24025 the glyph property.
24027 Either none or exactly one of 4 or 5 must be present.
24029 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24030 of the stretch should be used for the ascent of the stretch.
24031 ASCENT must be in the range 0 <= ASCENT <= 100. */
24034 produce_stretch_glyph (struct it
*it
)
24036 /* (space :width WIDTH :height HEIGHT ...) */
24037 Lisp_Object prop
, plist
;
24038 int width
= 0, height
= 0, align_to
= -1;
24039 int zero_width_ok_p
= 0;
24042 struct face
*face
= NULL
;
24043 struct font
*font
= NULL
;
24045 #ifdef HAVE_WINDOW_SYSTEM
24046 int zero_height_ok_p
= 0;
24048 if (FRAME_WINDOW_P (it
->f
))
24050 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24051 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24052 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24056 /* List should start with `space'. */
24057 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24058 plist
= XCDR (it
->object
);
24060 /* Compute the width of the stretch. */
24061 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24062 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24064 /* Absolute width `:width WIDTH' specified and valid. */
24065 zero_width_ok_p
= 1;
24068 #ifdef HAVE_WINDOW_SYSTEM
24069 else if (FRAME_WINDOW_P (it
->f
)
24070 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24072 /* Relative width `:relative-width FACTOR' specified and valid.
24073 Compute the width of the characters having the `glyph'
24076 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24079 if (it
->multibyte_p
)
24080 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24083 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24084 if (! ASCII_CHAR_P (it2
.c
))
24085 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24088 it2
.glyph_row
= NULL
;
24089 it2
.what
= IT_CHARACTER
;
24090 x_produce_glyphs (&it2
);
24091 width
= NUMVAL (prop
) * it2
.pixel_width
;
24093 #endif /* HAVE_WINDOW_SYSTEM */
24094 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24095 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24097 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24098 align_to
= (align_to
< 0
24100 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24101 else if (align_to
< 0)
24102 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24103 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24104 zero_width_ok_p
= 1;
24107 /* Nothing specified -> width defaults to canonical char width. */
24108 width
= FRAME_COLUMN_WIDTH (it
->f
);
24110 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24113 #ifdef HAVE_WINDOW_SYSTEM
24114 /* Compute height. */
24115 if (FRAME_WINDOW_P (it
->f
))
24117 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24118 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24121 zero_height_ok_p
= 1;
24123 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24125 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24127 height
= FONT_HEIGHT (font
);
24129 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24132 /* Compute percentage of height used for ascent. If
24133 `:ascent ASCENT' is present and valid, use that. Otherwise,
24134 derive the ascent from the font in use. */
24135 if (prop
= Fplist_get (plist
, QCascent
),
24136 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24137 ascent
= height
* NUMVAL (prop
) / 100.0;
24138 else if (!NILP (prop
)
24139 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24140 ascent
= min (max (0, (int)tem
), height
);
24142 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24145 #endif /* HAVE_WINDOW_SYSTEM */
24148 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24149 && it
->current_x
+ width
> it
->last_visible_x
)
24151 width
= it
->last_visible_x
- it
->current_x
;
24152 #ifdef HAVE_WINDOW_SYSTEM
24153 /* Subtract one more pixel from the stretch width, but only on
24154 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24155 width
-= FRAME_WINDOW_P (it
->f
);
24159 if (width
> 0 && height
> 0 && it
->glyph_row
)
24161 Lisp_Object o_object
= it
->object
;
24162 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24165 if (!STRINGP (object
))
24166 object
= WVAR (it
->w
, buffer
);
24167 #ifdef HAVE_WINDOW_SYSTEM
24168 if (FRAME_WINDOW_P (it
->f
))
24169 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24173 it
->object
= object
;
24174 it
->char_to_display
= ' ';
24175 it
->pixel_width
= it
->len
= 1;
24177 tty_append_glyph (it
);
24178 it
->object
= o_object
;
24182 it
->pixel_width
= width
;
24183 #ifdef HAVE_WINDOW_SYSTEM
24184 if (FRAME_WINDOW_P (it
->f
))
24186 it
->ascent
= it
->phys_ascent
= ascent
;
24187 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24188 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24189 take_vertical_position_into_account (it
);
24193 it
->nglyphs
= width
;
24196 /* Get information about special display element WHAT in an
24197 environment described by IT. WHAT is one of IT_TRUNCATION or
24198 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24199 non-null glyph_row member. This function ensures that fields like
24200 face_id, c, len of IT are left untouched. */
24203 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24210 temp_it
.object
= make_number (0);
24211 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24213 if (what
== IT_CONTINUATION
)
24215 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24216 if (it
->bidi_it
.paragraph_dir
== R2L
)
24217 SET_GLYPH_FROM_CHAR (glyph
, '/');
24219 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24221 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24223 /* FIXME: Should we mirror GC for R2L lines? */
24224 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24225 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24228 else if (what
== IT_TRUNCATION
)
24230 /* Truncation glyph. */
24231 SET_GLYPH_FROM_CHAR (glyph
, '$');
24233 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24235 /* FIXME: Should we mirror GC for R2L lines? */
24236 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24237 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24243 #ifdef HAVE_WINDOW_SYSTEM
24244 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24245 is turned off, we precede the truncation/continuation glyphs by a
24246 stretch glyph whose width is computed such that these special
24247 glyphs are aligned at the window margin, even when very different
24248 fonts are used in different glyph rows. */
24249 if (FRAME_WINDOW_P (temp_it
.f
)
24250 /* init_iterator calls this with it->glyph_row == NULL, and it
24251 wants only the pixel width of the truncation/continuation
24253 && temp_it
.glyph_row
24254 /* insert_left_trunc_glyphs calls us at the beginning of the
24255 row, and it has its own calculation of the stretch glyph
24257 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24258 && (temp_it
.glyph_row
->reversed_p
24259 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24260 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24262 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24264 if (stretch_width
> 0)
24266 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24267 struct font
*font
=
24268 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24269 int stretch_ascent
=
24270 (((temp_it
.ascent
+ temp_it
.descent
)
24271 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24273 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24274 temp_it
.ascent
+ temp_it
.descent
,
24281 temp_it
.what
= IT_CHARACTER
;
24283 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24284 temp_it
.face_id
= GLYPH_FACE (glyph
);
24285 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24287 PRODUCE_GLYPHS (&temp_it
);
24288 it
->pixel_width
= temp_it
.pixel_width
;
24289 it
->nglyphs
= temp_it
.pixel_width
;
24292 #ifdef HAVE_WINDOW_SYSTEM
24294 /* Calculate line-height and line-spacing properties.
24295 An integer value specifies explicit pixel value.
24296 A float value specifies relative value to current face height.
24297 A cons (float . face-name) specifies relative value to
24298 height of specified face font.
24300 Returns height in pixels, or nil. */
24304 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24305 int boff
, int override
)
24307 Lisp_Object face_name
= Qnil
;
24308 int ascent
, descent
, height
;
24310 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24315 face_name
= XCAR (val
);
24317 if (!NUMBERP (val
))
24318 val
= make_number (1);
24319 if (NILP (face_name
))
24321 height
= it
->ascent
+ it
->descent
;
24326 if (NILP (face_name
))
24328 font
= FRAME_FONT (it
->f
);
24329 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24331 else if (EQ (face_name
, Qt
))
24340 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24342 return make_number (-1);
24344 face
= FACE_FROM_ID (it
->f
, face_id
);
24347 return make_number (-1);
24348 boff
= font
->baseline_offset
;
24349 if (font
->vertical_centering
)
24350 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24353 ascent
= FONT_BASE (font
) + boff
;
24354 descent
= FONT_DESCENT (font
) - boff
;
24358 it
->override_ascent
= ascent
;
24359 it
->override_descent
= descent
;
24360 it
->override_boff
= boff
;
24363 height
= ascent
+ descent
;
24367 height
= (int)(XFLOAT_DATA (val
) * height
);
24368 else if (INTEGERP (val
))
24369 height
*= XINT (val
);
24371 return make_number (height
);
24375 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24376 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24377 and only if this is for a character for which no font was found.
24379 If the display method (it->glyphless_method) is
24380 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24381 length of the acronym or the hexadecimal string, UPPER_XOFF and
24382 UPPER_YOFF are pixel offsets for the upper part of the string,
24383 LOWER_XOFF and LOWER_YOFF are for the lower part.
24385 For the other display methods, LEN through LOWER_YOFF are zero. */
24388 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24389 short upper_xoff
, short upper_yoff
,
24390 short lower_xoff
, short lower_yoff
)
24392 struct glyph
*glyph
;
24393 enum glyph_row_area area
= it
->area
;
24395 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24396 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24398 /* If the glyph row is reversed, we need to prepend the glyph
24399 rather than append it. */
24400 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24404 /* Make room for the additional glyph. */
24405 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24407 glyph
= it
->glyph_row
->glyphs
[area
];
24409 glyph
->charpos
= CHARPOS (it
->position
);
24410 glyph
->object
= it
->object
;
24411 glyph
->pixel_width
= it
->pixel_width
;
24412 glyph
->ascent
= it
->ascent
;
24413 glyph
->descent
= it
->descent
;
24414 glyph
->voffset
= it
->voffset
;
24415 glyph
->type
= GLYPHLESS_GLYPH
;
24416 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24417 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24418 glyph
->u
.glyphless
.len
= len
;
24419 glyph
->u
.glyphless
.ch
= it
->c
;
24420 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24421 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24422 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24423 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24424 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24425 glyph
->multibyte_p
= it
->multibyte_p
;
24426 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24427 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24428 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24429 || it
->phys_descent
> it
->descent
);
24430 glyph
->padding_p
= 0;
24431 glyph
->glyph_not_available_p
= 0;
24432 glyph
->face_id
= face_id
;
24433 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24436 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24437 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24439 glyph
->bidi_type
= it
->bidi_it
.type
;
24441 ++it
->glyph_row
->used
[area
];
24444 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24448 /* Produce a glyph for a glyphless character for iterator IT.
24449 IT->glyphless_method specifies which method to use for displaying
24450 the character. See the description of enum
24451 glyphless_display_method in dispextern.h for the detail.
24453 FOR_NO_FONT is nonzero if and only if this is for a character for
24454 which no font was found. ACRONYM, if non-nil, is an acronym string
24455 for the character. */
24458 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24463 int base_width
, base_height
, width
, height
;
24464 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24467 /* Get the metrics of the base font. We always refer to the current
24469 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24470 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24471 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24472 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24473 base_height
= it
->ascent
+ it
->descent
;
24474 base_width
= font
->average_width
;
24476 /* Get a face ID for the glyph by utilizing a cache (the same way as
24477 done for `escape-glyph' in get_next_display_element). */
24478 if (it
->f
== last_glyphless_glyph_frame
24479 && it
->face_id
== last_glyphless_glyph_face_id
)
24481 face_id
= last_glyphless_glyph_merged_face_id
;
24485 /* Merge the `glyphless-char' face into the current face. */
24486 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24487 last_glyphless_glyph_frame
= it
->f
;
24488 last_glyphless_glyph_face_id
= it
->face_id
;
24489 last_glyphless_glyph_merged_face_id
= face_id
;
24492 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24494 it
->pixel_width
= THIN_SPACE_WIDTH
;
24496 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24498 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24500 width
= CHAR_WIDTH (it
->c
);
24503 else if (width
> 4)
24505 it
->pixel_width
= base_width
* width
;
24507 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24513 unsigned int code
[6];
24515 int ascent
, descent
;
24516 struct font_metrics metrics_upper
, metrics_lower
;
24518 face
= FACE_FROM_ID (it
->f
, face_id
);
24519 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24520 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24522 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24524 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24525 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24526 if (CONSP (acronym
))
24527 acronym
= XCAR (acronym
);
24528 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24532 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24533 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24536 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24537 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24538 upper_len
= (len
+ 1) / 2;
24539 font
->driver
->text_extents (font
, code
, upper_len
,
24541 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24546 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24547 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24548 upper_xoff
= upper_yoff
= 2; /* the typical case */
24549 if (base_width
>= width
)
24551 /* Align the upper to the left, the lower to the right. */
24552 it
->pixel_width
= base_width
;
24553 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24557 /* Center the shorter one. */
24558 it
->pixel_width
= width
;
24559 if (metrics_upper
.width
>= metrics_lower
.width
)
24560 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24563 /* FIXME: This code doesn't look right. It formerly was
24564 missing the "lower_xoff = 0;", which couldn't have
24565 been right since it left lower_xoff uninitialized. */
24567 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24571 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24572 top, bottom, and between upper and lower strings. */
24573 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24574 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24575 /* Center vertically.
24576 H:base_height, D:base_descent
24577 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24579 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24580 descent = D - H/2 + h/2;
24581 lower_yoff = descent - 2 - ld;
24582 upper_yoff = lower_yoff - la - 1 - ud; */
24583 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24584 descent
= it
->descent
- (base_height
- height
) / 2;
24585 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24586 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24587 - metrics_upper
.descent
);
24588 /* Don't make the height shorter than the base height. */
24589 if (height
> base_height
)
24591 it
->ascent
= ascent
;
24592 it
->descent
= descent
;
24596 it
->phys_ascent
= it
->ascent
;
24597 it
->phys_descent
= it
->descent
;
24599 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24600 upper_xoff
, upper_yoff
,
24601 lower_xoff
, lower_yoff
);
24603 take_vertical_position_into_account (it
);
24608 Produce glyphs/get display metrics for the display element IT is
24609 loaded with. See the description of struct it in dispextern.h
24610 for an overview of struct it. */
24613 x_produce_glyphs (struct it
*it
)
24615 int extra_line_spacing
= it
->extra_line_spacing
;
24617 it
->glyph_not_available_p
= 0;
24619 if (it
->what
== IT_CHARACTER
)
24622 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24623 struct font
*font
= face
->font
;
24624 struct font_metrics
*pcm
= NULL
;
24625 int boff
; /* baseline offset */
24629 /* When no suitable font is found, display this character by
24630 the method specified in the first extra slot of
24631 Vglyphless_char_display. */
24632 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24634 eassert (it
->what
== IT_GLYPHLESS
);
24635 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24639 boff
= font
->baseline_offset
;
24640 if (font
->vertical_centering
)
24641 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24643 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24649 if (it
->override_ascent
>= 0)
24651 it
->ascent
= it
->override_ascent
;
24652 it
->descent
= it
->override_descent
;
24653 boff
= it
->override_boff
;
24657 it
->ascent
= FONT_BASE (font
) + boff
;
24658 it
->descent
= FONT_DESCENT (font
) - boff
;
24661 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24663 pcm
= get_per_char_metric (font
, &char2b
);
24664 if (pcm
->width
== 0
24665 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24671 it
->phys_ascent
= pcm
->ascent
+ boff
;
24672 it
->phys_descent
= pcm
->descent
- boff
;
24673 it
->pixel_width
= pcm
->width
;
24677 it
->glyph_not_available_p
= 1;
24678 it
->phys_ascent
= it
->ascent
;
24679 it
->phys_descent
= it
->descent
;
24680 it
->pixel_width
= font
->space_width
;
24683 if (it
->constrain_row_ascent_descent_p
)
24685 if (it
->descent
> it
->max_descent
)
24687 it
->ascent
+= it
->descent
- it
->max_descent
;
24688 it
->descent
= it
->max_descent
;
24690 if (it
->ascent
> it
->max_ascent
)
24692 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24693 it
->ascent
= it
->max_ascent
;
24695 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24696 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24697 extra_line_spacing
= 0;
24700 /* If this is a space inside a region of text with
24701 `space-width' property, change its width. */
24702 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24704 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24706 /* If face has a box, add the box thickness to the character
24707 height. If character has a box line to the left and/or
24708 right, add the box line width to the character's width. */
24709 if (face
->box
!= FACE_NO_BOX
)
24711 int thick
= face
->box_line_width
;
24715 it
->ascent
+= thick
;
24716 it
->descent
+= thick
;
24721 if (it
->start_of_box_run_p
)
24722 it
->pixel_width
+= thick
;
24723 if (it
->end_of_box_run_p
)
24724 it
->pixel_width
+= thick
;
24727 /* If face has an overline, add the height of the overline
24728 (1 pixel) and a 1 pixel margin to the character height. */
24729 if (face
->overline_p
)
24730 it
->ascent
+= overline_margin
;
24732 if (it
->constrain_row_ascent_descent_p
)
24734 if (it
->ascent
> it
->max_ascent
)
24735 it
->ascent
= it
->max_ascent
;
24736 if (it
->descent
> it
->max_descent
)
24737 it
->descent
= it
->max_descent
;
24740 take_vertical_position_into_account (it
);
24742 /* If we have to actually produce glyphs, do it. */
24747 /* Translate a space with a `space-width' property
24748 into a stretch glyph. */
24749 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24750 / FONT_HEIGHT (font
));
24751 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24752 it
->ascent
+ it
->descent
, ascent
);
24757 /* If characters with lbearing or rbearing are displayed
24758 in this line, record that fact in a flag of the
24759 glyph row. This is used to optimize X output code. */
24760 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24761 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24763 if (! stretched_p
&& it
->pixel_width
== 0)
24764 /* We assure that all visible glyphs have at least 1-pixel
24766 it
->pixel_width
= 1;
24768 else if (it
->char_to_display
== '\n')
24770 /* A newline has no width, but we need the height of the
24771 line. But if previous part of the line sets a height,
24772 don't increase that height */
24774 Lisp_Object height
;
24775 Lisp_Object total_height
= Qnil
;
24777 it
->override_ascent
= -1;
24778 it
->pixel_width
= 0;
24781 height
= get_it_property (it
, Qline_height
);
24782 /* Split (line-height total-height) list */
24784 && CONSP (XCDR (height
))
24785 && NILP (XCDR (XCDR (height
))))
24787 total_height
= XCAR (XCDR (height
));
24788 height
= XCAR (height
);
24790 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24792 if (it
->override_ascent
>= 0)
24794 it
->ascent
= it
->override_ascent
;
24795 it
->descent
= it
->override_descent
;
24796 boff
= it
->override_boff
;
24800 it
->ascent
= FONT_BASE (font
) + boff
;
24801 it
->descent
= FONT_DESCENT (font
) - boff
;
24804 if (EQ (height
, Qt
))
24806 if (it
->descent
> it
->max_descent
)
24808 it
->ascent
+= it
->descent
- it
->max_descent
;
24809 it
->descent
= it
->max_descent
;
24811 if (it
->ascent
> it
->max_ascent
)
24813 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24814 it
->ascent
= it
->max_ascent
;
24816 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24817 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24818 it
->constrain_row_ascent_descent_p
= 1;
24819 extra_line_spacing
= 0;
24823 Lisp_Object spacing
;
24825 it
->phys_ascent
= it
->ascent
;
24826 it
->phys_descent
= it
->descent
;
24828 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24829 && face
->box
!= FACE_NO_BOX
24830 && face
->box_line_width
> 0)
24832 it
->ascent
+= face
->box_line_width
;
24833 it
->descent
+= face
->box_line_width
;
24836 && XINT (height
) > it
->ascent
+ it
->descent
)
24837 it
->ascent
= XINT (height
) - it
->descent
;
24839 if (!NILP (total_height
))
24840 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24843 spacing
= get_it_property (it
, Qline_spacing
);
24844 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24846 if (INTEGERP (spacing
))
24848 extra_line_spacing
= XINT (spacing
);
24849 if (!NILP (total_height
))
24850 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24854 else /* i.e. (it->char_to_display == '\t') */
24856 if (font
->space_width
> 0)
24858 int tab_width
= it
->tab_width
* font
->space_width
;
24859 int x
= it
->current_x
+ it
->continuation_lines_width
;
24860 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24862 /* If the distance from the current position to the next tab
24863 stop is less than a space character width, use the
24864 tab stop after that. */
24865 if (next_tab_x
- x
< font
->space_width
)
24866 next_tab_x
+= tab_width
;
24868 it
->pixel_width
= next_tab_x
- x
;
24870 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24871 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24875 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24876 it
->ascent
+ it
->descent
, it
->ascent
);
24881 it
->pixel_width
= 0;
24886 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24888 /* A static composition.
24890 Note: A composition is represented as one glyph in the
24891 glyph matrix. There are no padding glyphs.
24893 Important note: pixel_width, ascent, and descent are the
24894 values of what is drawn by draw_glyphs (i.e. the values of
24895 the overall glyphs composed). */
24896 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24897 int boff
; /* baseline offset */
24898 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24899 int glyph_len
= cmp
->glyph_len
;
24900 struct font
*font
= face
->font
;
24904 /* If we have not yet calculated pixel size data of glyphs of
24905 the composition for the current face font, calculate them
24906 now. Theoretically, we have to check all fonts for the
24907 glyphs, but that requires much time and memory space. So,
24908 here we check only the font of the first glyph. This may
24909 lead to incorrect display, but it's very rare, and C-l
24910 (recenter-top-bottom) can correct the display anyway. */
24911 if (! cmp
->font
|| cmp
->font
!= font
)
24913 /* Ascent and descent of the font of the first character
24914 of this composition (adjusted by baseline offset).
24915 Ascent and descent of overall glyphs should not be less
24916 than these, respectively. */
24917 int font_ascent
, font_descent
, font_height
;
24918 /* Bounding box of the overall glyphs. */
24919 int leftmost
, rightmost
, lowest
, highest
;
24920 int lbearing
, rbearing
;
24921 int i
, width
, ascent
, descent
;
24922 int left_padded
= 0, right_padded
= 0;
24923 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24925 struct font_metrics
*pcm
;
24926 int font_not_found_p
;
24929 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24930 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24932 if (glyph_len
< cmp
->glyph_len
)
24934 for (i
= 0; i
< glyph_len
; i
++)
24936 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24938 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24943 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24944 : IT_CHARPOS (*it
));
24945 /* If no suitable font is found, use the default font. */
24946 font_not_found_p
= font
== NULL
;
24947 if (font_not_found_p
)
24949 face
= face
->ascii_face
;
24952 boff
= font
->baseline_offset
;
24953 if (font
->vertical_centering
)
24954 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24955 font_ascent
= FONT_BASE (font
) + boff
;
24956 font_descent
= FONT_DESCENT (font
) - boff
;
24957 font_height
= FONT_HEIGHT (font
);
24959 cmp
->font
= (void *) font
;
24962 if (! font_not_found_p
)
24964 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24966 pcm
= get_per_char_metric (font
, &char2b
);
24969 /* Initialize the bounding box. */
24972 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24973 ascent
= pcm
->ascent
;
24974 descent
= pcm
->descent
;
24975 lbearing
= pcm
->lbearing
;
24976 rbearing
= pcm
->rbearing
;
24980 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24981 ascent
= FONT_BASE (font
);
24982 descent
= FONT_DESCENT (font
);
24989 lowest
= - descent
+ boff
;
24990 highest
= ascent
+ boff
;
24992 if (! font_not_found_p
24993 && font
->default_ascent
24994 && CHAR_TABLE_P (Vuse_default_ascent
)
24995 && !NILP (Faref (Vuse_default_ascent
,
24996 make_number (it
->char_to_display
))))
24997 highest
= font
->default_ascent
+ boff
;
24999 /* Draw the first glyph at the normal position. It may be
25000 shifted to right later if some other glyphs are drawn
25002 cmp
->offsets
[i
* 2] = 0;
25003 cmp
->offsets
[i
* 2 + 1] = boff
;
25004 cmp
->lbearing
= lbearing
;
25005 cmp
->rbearing
= rbearing
;
25007 /* Set cmp->offsets for the remaining glyphs. */
25008 for (i
++; i
< glyph_len
; i
++)
25010 int left
, right
, btm
, top
;
25011 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25013 struct face
*this_face
;
25017 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25018 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25019 font
= this_face
->font
;
25025 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25027 pcm
= get_per_char_metric (font
, &char2b
);
25030 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25033 width
= pcm
->width
;
25034 ascent
= pcm
->ascent
;
25035 descent
= pcm
->descent
;
25036 lbearing
= pcm
->lbearing
;
25037 rbearing
= pcm
->rbearing
;
25038 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25040 /* Relative composition with or without
25041 alternate chars. */
25042 left
= (leftmost
+ rightmost
- width
) / 2;
25043 btm
= - descent
+ boff
;
25044 if (font
->relative_compose
25045 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25046 || NILP (Faref (Vignore_relative_composition
,
25047 make_number (ch
)))))
25050 if (- descent
>= font
->relative_compose
)
25051 /* One extra pixel between two glyphs. */
25053 else if (ascent
<= 0)
25054 /* One extra pixel between two glyphs. */
25055 btm
= lowest
- 1 - ascent
- descent
;
25060 /* A composition rule is specified by an integer
25061 value that encodes global and new reference
25062 points (GREF and NREF). GREF and NREF are
25063 specified by numbers as below:
25065 0---1---2 -- ascent
25069 9--10--11 -- center
25071 ---3---4---5--- baseline
25073 6---7---8 -- descent
25075 int rule
= COMPOSITION_RULE (cmp
, i
);
25076 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25078 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25079 grefx
= gref
% 3, nrefx
= nref
% 3;
25080 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25082 xoff
= font_height
* (xoff
- 128) / 256;
25084 yoff
= font_height
* (yoff
- 128) / 256;
25087 + grefx
* (rightmost
- leftmost
) / 2
25088 - nrefx
* width
/ 2
25091 btm
= ((grefy
== 0 ? highest
25093 : grefy
== 2 ? lowest
25094 : (highest
+ lowest
) / 2)
25095 - (nrefy
== 0 ? ascent
+ descent
25096 : nrefy
== 1 ? descent
- boff
25098 : (ascent
+ descent
) / 2)
25102 cmp
->offsets
[i
* 2] = left
;
25103 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25105 /* Update the bounding box of the overall glyphs. */
25108 right
= left
+ width
;
25109 if (left
< leftmost
)
25111 if (right
> rightmost
)
25114 top
= btm
+ descent
+ ascent
;
25120 if (cmp
->lbearing
> left
+ lbearing
)
25121 cmp
->lbearing
= left
+ lbearing
;
25122 if (cmp
->rbearing
< left
+ rbearing
)
25123 cmp
->rbearing
= left
+ rbearing
;
25127 /* If there are glyphs whose x-offsets are negative,
25128 shift all glyphs to the right and make all x-offsets
25132 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25133 cmp
->offsets
[i
* 2] -= leftmost
;
25134 rightmost
-= leftmost
;
25135 cmp
->lbearing
-= leftmost
;
25136 cmp
->rbearing
-= leftmost
;
25139 if (left_padded
&& cmp
->lbearing
< 0)
25141 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25142 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25143 rightmost
-= cmp
->lbearing
;
25144 cmp
->rbearing
-= cmp
->lbearing
;
25147 if (right_padded
&& rightmost
< cmp
->rbearing
)
25149 rightmost
= cmp
->rbearing
;
25152 cmp
->pixel_width
= rightmost
;
25153 cmp
->ascent
= highest
;
25154 cmp
->descent
= - lowest
;
25155 if (cmp
->ascent
< font_ascent
)
25156 cmp
->ascent
= font_ascent
;
25157 if (cmp
->descent
< font_descent
)
25158 cmp
->descent
= font_descent
;
25162 && (cmp
->lbearing
< 0
25163 || cmp
->rbearing
> cmp
->pixel_width
))
25164 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25166 it
->pixel_width
= cmp
->pixel_width
;
25167 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25168 it
->descent
= it
->phys_descent
= cmp
->descent
;
25169 if (face
->box
!= FACE_NO_BOX
)
25171 int thick
= face
->box_line_width
;
25175 it
->ascent
+= thick
;
25176 it
->descent
+= thick
;
25181 if (it
->start_of_box_run_p
)
25182 it
->pixel_width
+= thick
;
25183 if (it
->end_of_box_run_p
)
25184 it
->pixel_width
+= thick
;
25187 /* If face has an overline, add the height of the overline
25188 (1 pixel) and a 1 pixel margin to the character height. */
25189 if (face
->overline_p
)
25190 it
->ascent
+= overline_margin
;
25192 take_vertical_position_into_account (it
);
25193 if (it
->ascent
< 0)
25195 if (it
->descent
< 0)
25198 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25199 append_composite_glyph (it
);
25201 else if (it
->what
== IT_COMPOSITION
)
25203 /* A dynamic (automatic) composition. */
25204 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25205 Lisp_Object gstring
;
25206 struct font_metrics metrics
;
25210 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25212 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25215 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25216 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25217 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25218 it
->descent
= it
->phys_descent
= metrics
.descent
;
25219 if (face
->box
!= FACE_NO_BOX
)
25221 int thick
= face
->box_line_width
;
25225 it
->ascent
+= thick
;
25226 it
->descent
+= thick
;
25231 if (it
->start_of_box_run_p
)
25232 it
->pixel_width
+= thick
;
25233 if (it
->end_of_box_run_p
)
25234 it
->pixel_width
+= thick
;
25236 /* If face has an overline, add the height of the overline
25237 (1 pixel) and a 1 pixel margin to the character height. */
25238 if (face
->overline_p
)
25239 it
->ascent
+= overline_margin
;
25240 take_vertical_position_into_account (it
);
25241 if (it
->ascent
< 0)
25243 if (it
->descent
< 0)
25247 append_composite_glyph (it
);
25249 else if (it
->what
== IT_GLYPHLESS
)
25250 produce_glyphless_glyph (it
, 0, Qnil
);
25251 else if (it
->what
== IT_IMAGE
)
25252 produce_image_glyph (it
);
25253 else if (it
->what
== IT_STRETCH
)
25254 produce_stretch_glyph (it
);
25257 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25258 because this isn't true for images with `:ascent 100'. */
25259 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25260 if (it
->area
== TEXT_AREA
)
25261 it
->current_x
+= it
->pixel_width
;
25263 if (extra_line_spacing
> 0)
25265 it
->descent
+= extra_line_spacing
;
25266 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25267 it
->max_extra_line_spacing
= extra_line_spacing
;
25270 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25271 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25272 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25273 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25277 Output LEN glyphs starting at START at the nominal cursor position.
25278 Advance the nominal cursor over the text. The global variable
25279 updated_window contains the window being updated, updated_row is
25280 the glyph row being updated, and updated_area is the area of that
25281 row being updated. */
25284 x_write_glyphs (struct glyph
*start
, int len
)
25286 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25288 eassert (updated_window
&& updated_row
);
25289 /* When the window is hscrolled, cursor hpos can legitimately be out
25290 of bounds, but we draw the cursor at the corresponding window
25291 margin in that case. */
25292 if (!updated_row
->reversed_p
&& chpos
< 0)
25294 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25295 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25299 /* Write glyphs. */
25301 hpos
= start
- updated_row
->glyphs
[updated_area
];
25302 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25303 updated_row
, updated_area
,
25305 DRAW_NORMAL_TEXT
, 0);
25307 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25308 if (updated_area
== TEXT_AREA
25309 && updated_window
->phys_cursor_on_p
25310 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25312 && chpos
< hpos
+ len
)
25313 updated_window
->phys_cursor_on_p
= 0;
25317 /* Advance the output cursor. */
25318 output_cursor
.hpos
+= len
;
25319 output_cursor
.x
= x
;
25324 Insert LEN glyphs from START at the nominal cursor position. */
25327 x_insert_glyphs (struct glyph
*start
, int len
)
25331 int line_height
, shift_by_width
, shifted_region_width
;
25332 struct glyph_row
*row
;
25333 struct glyph
*glyph
;
25334 int frame_x
, frame_y
;
25337 eassert (updated_window
&& updated_row
);
25339 w
= updated_window
;
25340 f
= XFRAME (WINDOW_FRAME (w
));
25342 /* Get the height of the line we are in. */
25344 line_height
= row
->height
;
25346 /* Get the width of the glyphs to insert. */
25347 shift_by_width
= 0;
25348 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25349 shift_by_width
+= glyph
->pixel_width
;
25351 /* Get the width of the region to shift right. */
25352 shifted_region_width
= (window_box_width (w
, updated_area
)
25357 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25358 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25360 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25361 line_height
, shift_by_width
);
25363 /* Write the glyphs. */
25364 hpos
= start
- row
->glyphs
[updated_area
];
25365 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25367 DRAW_NORMAL_TEXT
, 0);
25369 /* Advance the output cursor. */
25370 output_cursor
.hpos
+= len
;
25371 output_cursor
.x
+= shift_by_width
;
25377 Erase the current text line from the nominal cursor position
25378 (inclusive) to pixel column TO_X (exclusive). The idea is that
25379 everything from TO_X onward is already erased.
25381 TO_X is a pixel position relative to updated_area of
25382 updated_window. TO_X == -1 means clear to the end of this area. */
25385 x_clear_end_of_line (int to_x
)
25388 struct window
*w
= updated_window
;
25389 int max_x
, min_y
, max_y
;
25390 int from_x
, from_y
, to_y
;
25392 eassert (updated_window
&& updated_row
);
25393 f
= XFRAME (WVAR (w
, frame
));
25395 if (updated_row
->full_width_p
)
25396 max_x
= WINDOW_TOTAL_WIDTH (w
);
25398 max_x
= window_box_width (w
, updated_area
);
25399 max_y
= window_text_bottom_y (w
);
25401 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25402 of window. For TO_X > 0, truncate to end of drawing area. */
25408 to_x
= min (to_x
, max_x
);
25410 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25412 /* Notice if the cursor will be cleared by this operation. */
25413 if (!updated_row
->full_width_p
)
25414 notice_overwritten_cursor (w
, updated_area
,
25415 output_cursor
.x
, -1,
25417 MATRIX_ROW_BOTTOM_Y (updated_row
));
25419 from_x
= output_cursor
.x
;
25421 /* Translate to frame coordinates. */
25422 if (updated_row
->full_width_p
)
25424 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25425 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25429 int area_left
= window_box_left (w
, updated_area
);
25430 from_x
+= area_left
;
25434 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25435 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25436 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25438 /* Prevent inadvertently clearing to end of the X window. */
25439 if (to_x
> from_x
&& to_y
> from_y
)
25442 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25443 to_x
- from_x
, to_y
- from_y
);
25448 #endif /* HAVE_WINDOW_SYSTEM */
25452 /***********************************************************************
25454 ***********************************************************************/
25456 /* Value is the internal representation of the specified cursor type
25457 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25458 of the bar cursor. */
25460 static enum text_cursor_kinds
25461 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25463 enum text_cursor_kinds type
;
25468 if (EQ (arg
, Qbox
))
25469 return FILLED_BOX_CURSOR
;
25471 if (EQ (arg
, Qhollow
))
25472 return HOLLOW_BOX_CURSOR
;
25474 if (EQ (arg
, Qbar
))
25481 && EQ (XCAR (arg
), Qbar
)
25482 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25484 *width
= XINT (XCDR (arg
));
25488 if (EQ (arg
, Qhbar
))
25491 return HBAR_CURSOR
;
25495 && EQ (XCAR (arg
), Qhbar
)
25496 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25498 *width
= XINT (XCDR (arg
));
25499 return HBAR_CURSOR
;
25502 /* Treat anything unknown as "hollow box cursor".
25503 It was bad to signal an error; people have trouble fixing
25504 .Xdefaults with Emacs, when it has something bad in it. */
25505 type
= HOLLOW_BOX_CURSOR
;
25510 /* Set the default cursor types for specified frame. */
25512 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25517 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25518 FRAME_CURSOR_WIDTH (f
) = width
;
25520 /* By default, set up the blink-off state depending on the on-state. */
25522 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25525 FRAME_BLINK_OFF_CURSOR (f
)
25526 = get_specified_cursor_type (XCDR (tem
), &width
);
25527 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25530 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25534 #ifdef HAVE_WINDOW_SYSTEM
25536 /* Return the cursor we want to be displayed in window W. Return
25537 width of bar/hbar cursor through WIDTH arg. Return with
25538 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25539 (i.e. if the `system caret' should track this cursor).
25541 In a mini-buffer window, we want the cursor only to appear if we
25542 are reading input from this window. For the selected window, we
25543 want the cursor type given by the frame parameter or buffer local
25544 setting of cursor-type. If explicitly marked off, draw no cursor.
25545 In all other cases, we want a hollow box cursor. */
25547 static enum text_cursor_kinds
25548 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25549 int *active_cursor
)
25551 struct frame
*f
= XFRAME (WVAR (w
, frame
));
25552 struct buffer
*b
= XBUFFER (WVAR (w
, buffer
));
25553 int cursor_type
= DEFAULT_CURSOR
;
25554 Lisp_Object alt_cursor
;
25555 int non_selected
= 0;
25557 *active_cursor
= 1;
25560 if (cursor_in_echo_area
25561 && FRAME_HAS_MINIBUF_P (f
)
25562 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25564 if (w
== XWINDOW (echo_area_window
))
25566 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25568 *width
= FRAME_CURSOR_WIDTH (f
);
25569 return FRAME_DESIRED_CURSOR (f
);
25572 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25575 *active_cursor
= 0;
25579 /* Detect a nonselected window or nonselected frame. */
25580 else if (w
!= XWINDOW (FVAR (f
, selected_window
))
25581 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25583 *active_cursor
= 0;
25585 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25591 /* Never display a cursor in a window in which cursor-type is nil. */
25592 if (NILP (BVAR (b
, cursor_type
)))
25595 /* Get the normal cursor type for this window. */
25596 if (EQ (BVAR (b
, cursor_type
), Qt
))
25598 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25599 *width
= FRAME_CURSOR_WIDTH (f
);
25602 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25604 /* Use cursor-in-non-selected-windows instead
25605 for non-selected window or frame. */
25608 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25609 if (!EQ (Qt
, alt_cursor
))
25610 return get_specified_cursor_type (alt_cursor
, width
);
25611 /* t means modify the normal cursor type. */
25612 if (cursor_type
== FILLED_BOX_CURSOR
)
25613 cursor_type
= HOLLOW_BOX_CURSOR
;
25614 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25616 return cursor_type
;
25619 /* Use normal cursor if not blinked off. */
25620 if (!w
->cursor_off_p
)
25622 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25624 if (cursor_type
== FILLED_BOX_CURSOR
)
25626 /* Using a block cursor on large images can be very annoying.
25627 So use a hollow cursor for "large" images.
25628 If image is not transparent (no mask), also use hollow cursor. */
25629 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25630 if (img
!= NULL
&& IMAGEP (img
->spec
))
25632 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25633 where N = size of default frame font size.
25634 This should cover most of the "tiny" icons people may use. */
25636 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25637 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25638 cursor_type
= HOLLOW_BOX_CURSOR
;
25641 else if (cursor_type
!= NO_CURSOR
)
25643 /* Display current only supports BOX and HOLLOW cursors for images.
25644 So for now, unconditionally use a HOLLOW cursor when cursor is
25645 not a solid box cursor. */
25646 cursor_type
= HOLLOW_BOX_CURSOR
;
25649 return cursor_type
;
25652 /* Cursor is blinked off, so determine how to "toggle" it. */
25654 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25655 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25656 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25658 /* Then see if frame has specified a specific blink off cursor type. */
25659 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25661 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25662 return FRAME_BLINK_OFF_CURSOR (f
);
25666 /* Some people liked having a permanently visible blinking cursor,
25667 while others had very strong opinions against it. So it was
25668 decided to remove it. KFS 2003-09-03 */
25670 /* Finally perform built-in cursor blinking:
25671 filled box <-> hollow box
25672 wide [h]bar <-> narrow [h]bar
25673 narrow [h]bar <-> no cursor
25674 other type <-> no cursor */
25676 if (cursor_type
== FILLED_BOX_CURSOR
)
25677 return HOLLOW_BOX_CURSOR
;
25679 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25682 return cursor_type
;
25690 /* Notice when the text cursor of window W has been completely
25691 overwritten by a drawing operation that outputs glyphs in AREA
25692 starting at X0 and ending at X1 in the line starting at Y0 and
25693 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25694 the rest of the line after X0 has been written. Y coordinates
25695 are window-relative. */
25698 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25699 int x0
, int x1
, int y0
, int y1
)
25701 int cx0
, cx1
, cy0
, cy1
;
25702 struct glyph_row
*row
;
25704 if (!w
->phys_cursor_on_p
)
25706 if (area
!= TEXT_AREA
)
25709 if (w
->phys_cursor
.vpos
< 0
25710 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25711 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25712 !(row
->enabled_p
&& row
->displays_text_p
)))
25715 if (row
->cursor_in_fringe_p
)
25717 row
->cursor_in_fringe_p
= 0;
25718 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25719 w
->phys_cursor_on_p
= 0;
25723 cx0
= w
->phys_cursor
.x
;
25724 cx1
= cx0
+ w
->phys_cursor_width
;
25725 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25728 /* The cursor image will be completely removed from the
25729 screen if the output area intersects the cursor area in
25730 y-direction. When we draw in [y0 y1[, and some part of
25731 the cursor is at y < y0, that part must have been drawn
25732 before. When scrolling, the cursor is erased before
25733 actually scrolling, so we don't come here. When not
25734 scrolling, the rows above the old cursor row must have
25735 changed, and in this case these rows must have written
25736 over the cursor image.
25738 Likewise if part of the cursor is below y1, with the
25739 exception of the cursor being in the first blank row at
25740 the buffer and window end because update_text_area
25741 doesn't draw that row. (Except when it does, but
25742 that's handled in update_text_area.) */
25744 cy0
= w
->phys_cursor
.y
;
25745 cy1
= cy0
+ w
->phys_cursor_height
;
25746 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25749 w
->phys_cursor_on_p
= 0;
25752 #endif /* HAVE_WINDOW_SYSTEM */
25755 /************************************************************************
25757 ************************************************************************/
25759 #ifdef HAVE_WINDOW_SYSTEM
25762 Fix the display of area AREA of overlapping row ROW in window W
25763 with respect to the overlapping part OVERLAPS. */
25766 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25767 enum glyph_row_area area
, int overlaps
)
25774 for (i
= 0; i
< row
->used
[area
];)
25776 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25778 int start
= i
, start_x
= x
;
25782 x
+= row
->glyphs
[area
][i
].pixel_width
;
25785 while (i
< row
->used
[area
]
25786 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25788 draw_glyphs (w
, start_x
, row
, area
,
25790 DRAW_NORMAL_TEXT
, overlaps
);
25794 x
+= row
->glyphs
[area
][i
].pixel_width
;
25804 Draw the cursor glyph of window W in glyph row ROW. See the
25805 comment of draw_glyphs for the meaning of HL. */
25808 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25809 enum draw_glyphs_face hl
)
25811 /* If cursor hpos is out of bounds, don't draw garbage. This can
25812 happen in mini-buffer windows when switching between echo area
25813 glyphs and mini-buffer. */
25814 if ((row
->reversed_p
25815 ? (w
->phys_cursor
.hpos
>= 0)
25816 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25818 int on_p
= w
->phys_cursor_on_p
;
25820 int hpos
= w
->phys_cursor
.hpos
;
25822 /* When the window is hscrolled, cursor hpos can legitimately be
25823 out of bounds, but we draw the cursor at the corresponding
25824 window margin in that case. */
25825 if (!row
->reversed_p
&& hpos
< 0)
25827 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25828 hpos
= row
->used
[TEXT_AREA
] - 1;
25830 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25832 w
->phys_cursor_on_p
= on_p
;
25834 if (hl
== DRAW_CURSOR
)
25835 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25836 /* When we erase the cursor, and ROW is overlapped by other
25837 rows, make sure that these overlapping parts of other rows
25839 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25841 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25843 if (row
> w
->current_matrix
->rows
25844 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25845 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25846 OVERLAPS_ERASED_CURSOR
);
25848 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25849 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25850 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25851 OVERLAPS_ERASED_CURSOR
);
25858 Erase the image of a cursor of window W from the screen. */
25861 erase_phys_cursor (struct window
*w
)
25863 struct frame
*f
= XFRAME (WVAR (w
, frame
));
25864 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25865 int hpos
= w
->phys_cursor
.hpos
;
25866 int vpos
= w
->phys_cursor
.vpos
;
25867 int mouse_face_here_p
= 0;
25868 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25869 struct glyph_row
*cursor_row
;
25870 struct glyph
*cursor_glyph
;
25871 enum draw_glyphs_face hl
;
25873 /* No cursor displayed or row invalidated => nothing to do on the
25875 if (w
->phys_cursor_type
== NO_CURSOR
)
25876 goto mark_cursor_off
;
25878 /* VPOS >= active_glyphs->nrows means that window has been resized.
25879 Don't bother to erase the cursor. */
25880 if (vpos
>= active_glyphs
->nrows
)
25881 goto mark_cursor_off
;
25883 /* If row containing cursor is marked invalid, there is nothing we
25885 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25886 if (!cursor_row
->enabled_p
)
25887 goto mark_cursor_off
;
25889 /* If line spacing is > 0, old cursor may only be partially visible in
25890 window after split-window. So adjust visible height. */
25891 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25892 window_text_bottom_y (w
) - cursor_row
->y
);
25894 /* If row is completely invisible, don't attempt to delete a cursor which
25895 isn't there. This can happen if cursor is at top of a window, and
25896 we switch to a buffer with a header line in that window. */
25897 if (cursor_row
->visible_height
<= 0)
25898 goto mark_cursor_off
;
25900 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25901 if (cursor_row
->cursor_in_fringe_p
)
25903 cursor_row
->cursor_in_fringe_p
= 0;
25904 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25905 goto mark_cursor_off
;
25908 /* This can happen when the new row is shorter than the old one.
25909 In this case, either draw_glyphs or clear_end_of_line
25910 should have cleared the cursor. Note that we wouldn't be
25911 able to erase the cursor in this case because we don't have a
25912 cursor glyph at hand. */
25913 if ((cursor_row
->reversed_p
25914 ? (w
->phys_cursor
.hpos
< 0)
25915 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25916 goto mark_cursor_off
;
25918 /* When the window is hscrolled, cursor hpos can legitimately be out
25919 of bounds, but we draw the cursor at the corresponding window
25920 margin in that case. */
25921 if (!cursor_row
->reversed_p
&& hpos
< 0)
25923 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25924 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25926 /* If the cursor is in the mouse face area, redisplay that when
25927 we clear the cursor. */
25928 if (! NILP (hlinfo
->mouse_face_window
)
25929 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25930 /* Don't redraw the cursor's spot in mouse face if it is at the
25931 end of a line (on a newline). The cursor appears there, but
25932 mouse highlighting does not. */
25933 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25934 mouse_face_here_p
= 1;
25936 /* Maybe clear the display under the cursor. */
25937 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25940 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25943 cursor_glyph
= get_phys_cursor_glyph (w
);
25944 if (cursor_glyph
== NULL
)
25945 goto mark_cursor_off
;
25947 width
= cursor_glyph
->pixel_width
;
25948 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25949 x
= w
->phys_cursor
.x
;
25951 width
-= left_x
- x
;
25952 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25953 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25954 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25957 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25960 /* Erase the cursor by redrawing the character underneath it. */
25961 if (mouse_face_here_p
)
25962 hl
= DRAW_MOUSE_FACE
;
25964 hl
= DRAW_NORMAL_TEXT
;
25965 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25968 w
->phys_cursor_on_p
= 0;
25969 w
->phys_cursor_type
= NO_CURSOR
;
25974 Display or clear cursor of window W. If ON is zero, clear the
25975 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25976 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25979 display_and_set_cursor (struct window
*w
, int on
,
25980 int hpos
, int vpos
, int x
, int y
)
25982 struct frame
*f
= XFRAME (WVAR (w
, frame
));
25983 int new_cursor_type
;
25984 int new_cursor_width
;
25986 struct glyph_row
*glyph_row
;
25987 struct glyph
*glyph
;
25989 /* This is pointless on invisible frames, and dangerous on garbaged
25990 windows and frames; in the latter case, the frame or window may
25991 be in the midst of changing its size, and x and y may be off the
25993 if (! FRAME_VISIBLE_P (f
)
25994 || FRAME_GARBAGED_P (f
)
25995 || vpos
>= w
->current_matrix
->nrows
25996 || hpos
>= w
->current_matrix
->matrix_w
)
25999 /* If cursor is off and we want it off, return quickly. */
26000 if (!on
&& !w
->phys_cursor_on_p
)
26003 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26004 /* If cursor row is not enabled, we don't really know where to
26005 display the cursor. */
26006 if (!glyph_row
->enabled_p
)
26008 w
->phys_cursor_on_p
= 0;
26013 if (!glyph_row
->exact_window_width_line_p
26014 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26015 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26017 eassert (interrupt_input_blocked
);
26019 /* Set new_cursor_type to the cursor we want to be displayed. */
26020 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26021 &new_cursor_width
, &active_cursor
);
26023 /* If cursor is currently being shown and we don't want it to be or
26024 it is in the wrong place, or the cursor type is not what we want,
26026 if (w
->phys_cursor_on_p
26028 || w
->phys_cursor
.x
!= x
26029 || w
->phys_cursor
.y
!= y
26030 || new_cursor_type
!= w
->phys_cursor_type
26031 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26032 && new_cursor_width
!= w
->phys_cursor_width
)))
26033 erase_phys_cursor (w
);
26035 /* Don't check phys_cursor_on_p here because that flag is only set
26036 to zero in some cases where we know that the cursor has been
26037 completely erased, to avoid the extra work of erasing the cursor
26038 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26039 still not be visible, or it has only been partly erased. */
26042 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26043 w
->phys_cursor_height
= glyph_row
->height
;
26045 /* Set phys_cursor_.* before x_draw_.* is called because some
26046 of them may need the information. */
26047 w
->phys_cursor
.x
= x
;
26048 w
->phys_cursor
.y
= glyph_row
->y
;
26049 w
->phys_cursor
.hpos
= hpos
;
26050 w
->phys_cursor
.vpos
= vpos
;
26053 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26054 new_cursor_type
, new_cursor_width
,
26055 on
, active_cursor
);
26059 /* Switch the display of W's cursor on or off, according to the value
26063 update_window_cursor (struct window
*w
, int on
)
26065 /* Don't update cursor in windows whose frame is in the process
26066 of being deleted. */
26067 if (w
->current_matrix
)
26069 int hpos
= w
->phys_cursor
.hpos
;
26070 int vpos
= w
->phys_cursor
.vpos
;
26071 struct glyph_row
*row
;
26073 if (vpos
>= w
->current_matrix
->nrows
26074 || hpos
>= w
->current_matrix
->matrix_w
)
26077 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26079 /* When the window is hscrolled, cursor hpos can legitimately be
26080 out of bounds, but we draw the cursor at the corresponding
26081 window margin in that case. */
26082 if (!row
->reversed_p
&& hpos
< 0)
26084 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26085 hpos
= row
->used
[TEXT_AREA
] - 1;
26088 display_and_set_cursor (w
, on
, hpos
, vpos
,
26089 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26095 /* Call update_window_cursor with parameter ON_P on all leaf windows
26096 in the window tree rooted at W. */
26099 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26103 if (!NILP (WVAR (w
, hchild
)))
26104 update_cursor_in_window_tree (XWINDOW (WVAR (w
, hchild
)), on_p
);
26105 else if (!NILP (WVAR (w
, vchild
)))
26106 update_cursor_in_window_tree (XWINDOW (WVAR (w
, vchild
)), on_p
);
26108 update_window_cursor (w
, on_p
);
26110 w
= NILP (WVAR (w
, next
)) ? 0 : XWINDOW (WVAR (w
, next
));
26116 Display the cursor on window W, or clear it, according to ON_P.
26117 Don't change the cursor's position. */
26120 x_update_cursor (struct frame
*f
, int on_p
)
26122 update_cursor_in_window_tree (XWINDOW (FVAR (f
, root_window
)), on_p
);
26127 Clear the cursor of window W to background color, and mark the
26128 cursor as not shown. This is used when the text where the cursor
26129 is about to be rewritten. */
26132 x_clear_cursor (struct window
*w
)
26134 if (FRAME_VISIBLE_P (XFRAME (WVAR (w
, frame
))) && w
->phys_cursor_on_p
)
26135 update_window_cursor (w
, 0);
26138 #endif /* HAVE_WINDOW_SYSTEM */
26140 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26143 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26144 int start_hpos
, int end_hpos
,
26145 enum draw_glyphs_face draw
)
26147 #ifdef HAVE_WINDOW_SYSTEM
26148 if (FRAME_WINDOW_P (XFRAME (WVAR (w
, frame
))))
26150 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26154 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26155 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26159 /* Display the active region described by mouse_face_* according to DRAW. */
26162 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26164 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26165 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26167 if (/* If window is in the process of being destroyed, don't bother
26169 w
->current_matrix
!= NULL
26170 /* Don't update mouse highlight if hidden */
26171 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26172 /* Recognize when we are called to operate on rows that don't exist
26173 anymore. This can happen when a window is split. */
26174 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26176 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26177 struct glyph_row
*row
, *first
, *last
;
26179 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26180 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26182 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26184 int start_hpos
, end_hpos
, start_x
;
26186 /* For all but the first row, the highlight starts at column 0. */
26189 /* R2L rows have BEG and END in reversed order, but the
26190 screen drawing geometry is always left to right. So
26191 we need to mirror the beginning and end of the
26192 highlighted area in R2L rows. */
26193 if (!row
->reversed_p
)
26195 start_hpos
= hlinfo
->mouse_face_beg_col
;
26196 start_x
= hlinfo
->mouse_face_beg_x
;
26198 else if (row
== last
)
26200 start_hpos
= hlinfo
->mouse_face_end_col
;
26201 start_x
= hlinfo
->mouse_face_end_x
;
26209 else if (row
->reversed_p
&& row
== last
)
26211 start_hpos
= hlinfo
->mouse_face_end_col
;
26212 start_x
= hlinfo
->mouse_face_end_x
;
26222 if (!row
->reversed_p
)
26223 end_hpos
= hlinfo
->mouse_face_end_col
;
26224 else if (row
== first
)
26225 end_hpos
= hlinfo
->mouse_face_beg_col
;
26228 end_hpos
= row
->used
[TEXT_AREA
];
26229 if (draw
== DRAW_NORMAL_TEXT
)
26230 row
->fill_line_p
= 1; /* Clear to end of line */
26233 else if (row
->reversed_p
&& row
== first
)
26234 end_hpos
= hlinfo
->mouse_face_beg_col
;
26237 end_hpos
= row
->used
[TEXT_AREA
];
26238 if (draw
== DRAW_NORMAL_TEXT
)
26239 row
->fill_line_p
= 1; /* Clear to end of line */
26242 if (end_hpos
> start_hpos
)
26244 draw_row_with_mouse_face (w
, start_x
, row
,
26245 start_hpos
, end_hpos
, draw
);
26248 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26252 #ifdef HAVE_WINDOW_SYSTEM
26253 /* When we've written over the cursor, arrange for it to
26254 be displayed again. */
26255 if (FRAME_WINDOW_P (f
)
26256 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26258 int hpos
= w
->phys_cursor
.hpos
;
26260 /* When the window is hscrolled, cursor hpos can legitimately be
26261 out of bounds, but we draw the cursor at the corresponding
26262 window margin in that case. */
26263 if (!row
->reversed_p
&& hpos
< 0)
26265 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26266 hpos
= row
->used
[TEXT_AREA
] - 1;
26269 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26270 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26273 #endif /* HAVE_WINDOW_SYSTEM */
26276 #ifdef HAVE_WINDOW_SYSTEM
26277 /* Change the mouse cursor. */
26278 if (FRAME_WINDOW_P (f
))
26280 if (draw
== DRAW_NORMAL_TEXT
26281 && !EQ (hlinfo
->mouse_face_window
, FVAR (f
, tool_bar_window
)))
26282 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26283 else if (draw
== DRAW_MOUSE_FACE
)
26284 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26286 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26288 #endif /* HAVE_WINDOW_SYSTEM */
26292 Clear out the mouse-highlighted active region.
26293 Redraw it un-highlighted first. Value is non-zero if mouse
26294 face was actually drawn unhighlighted. */
26297 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26301 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26303 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26307 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26308 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26309 hlinfo
->mouse_face_window
= Qnil
;
26310 hlinfo
->mouse_face_overlay
= Qnil
;
26314 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26315 within the mouse face on that window. */
26317 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26319 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (WVAR (w
, frame
)));
26321 /* Quickly resolve the easy cases. */
26322 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26323 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26325 if (vpos
< hlinfo
->mouse_face_beg_row
26326 || vpos
> hlinfo
->mouse_face_end_row
)
26328 if (vpos
> hlinfo
->mouse_face_beg_row
26329 && vpos
< hlinfo
->mouse_face_end_row
)
26332 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26334 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26336 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26339 else if ((vpos
== hlinfo
->mouse_face_beg_row
26340 && hpos
>= hlinfo
->mouse_face_beg_col
)
26341 || (vpos
== hlinfo
->mouse_face_end_row
26342 && hpos
< hlinfo
->mouse_face_end_col
))
26347 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26349 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26352 else if ((vpos
== hlinfo
->mouse_face_beg_row
26353 && hpos
<= hlinfo
->mouse_face_beg_col
)
26354 || (vpos
== hlinfo
->mouse_face_end_row
26355 && hpos
> hlinfo
->mouse_face_end_col
))
26363 Non-zero if physical cursor of window W is within mouse face. */
26366 cursor_in_mouse_face_p (struct window
*w
)
26368 int hpos
= w
->phys_cursor
.hpos
;
26369 int vpos
= w
->phys_cursor
.vpos
;
26370 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26372 /* When the window is hscrolled, cursor hpos can legitimately be out
26373 of bounds, but we draw the cursor at the corresponding window
26374 margin in that case. */
26375 if (!row
->reversed_p
&& hpos
< 0)
26377 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26378 hpos
= row
->used
[TEXT_AREA
] - 1;
26380 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26385 /* Find the glyph rows START_ROW and END_ROW of window W that display
26386 characters between buffer positions START_CHARPOS and END_CHARPOS
26387 (excluding END_CHARPOS). DISP_STRING is a display string that
26388 covers these buffer positions. This is similar to
26389 row_containing_pos, but is more accurate when bidi reordering makes
26390 buffer positions change non-linearly with glyph rows. */
26392 rows_from_pos_range (struct window
*w
,
26393 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26394 Lisp_Object disp_string
,
26395 struct glyph_row
**start
, struct glyph_row
**end
)
26397 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26398 int last_y
= window_text_bottom_y (w
);
26399 struct glyph_row
*row
;
26404 while (!first
->enabled_p
26405 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26408 /* Find the START row. */
26410 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26413 /* A row can potentially be the START row if the range of the
26414 characters it displays intersects the range
26415 [START_CHARPOS..END_CHARPOS). */
26416 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26417 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26418 /* See the commentary in row_containing_pos, for the
26419 explanation of the complicated way to check whether
26420 some position is beyond the end of the characters
26421 displayed by a row. */
26422 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26423 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26424 && !row
->ends_at_zv_p
26425 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26426 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26427 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26428 && !row
->ends_at_zv_p
26429 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26431 /* Found a candidate row. Now make sure at least one of the
26432 glyphs it displays has a charpos from the range
26433 [START_CHARPOS..END_CHARPOS).
26435 This is not obvious because bidi reordering could make
26436 buffer positions of a row be 1,2,3,102,101,100, and if we
26437 want to highlight characters in [50..60), we don't want
26438 this row, even though [50..60) does intersect [1..103),
26439 the range of character positions given by the row's start
26440 and end positions. */
26441 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26442 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26446 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26447 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26448 /* A glyph that comes from DISP_STRING is by
26449 definition to be highlighted. */
26450 || EQ (g
->object
, disp_string
))
26459 /* Find the END row. */
26461 /* If the last row is partially visible, start looking for END
26462 from that row, instead of starting from FIRST. */
26463 && !(row
->enabled_p
26464 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26466 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26468 struct glyph_row
*next
= row
+ 1;
26469 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26471 if (!next
->enabled_p
26472 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26473 /* The first row >= START whose range of displayed characters
26474 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26475 is the row END + 1. */
26476 || (start_charpos
< next_start
26477 && end_charpos
< next_start
)
26478 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26479 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26480 && !next
->ends_at_zv_p
26481 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26482 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26483 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26484 && !next
->ends_at_zv_p
26485 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26492 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26493 but none of the characters it displays are in the range, it is
26495 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26496 struct glyph
*s
= g
;
26497 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26501 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26502 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26503 /* If the buffer position of the first glyph in
26504 the row is equal to END_CHARPOS, it means
26505 the last character to be highlighted is the
26506 newline of ROW, and we must consider NEXT as
26508 || (((!next
->reversed_p
&& g
== s
)
26509 || (next
->reversed_p
&& g
== e
- 1))
26510 && (g
->charpos
== end_charpos
26511 /* Special case for when NEXT is an
26512 empty line at ZV. */
26513 || (g
->charpos
== -1
26514 && !row
->ends_at_zv_p
26515 && next_start
== end_charpos
)))))
26516 /* A glyph that comes from DISP_STRING is by
26517 definition to be highlighted. */
26518 || EQ (g
->object
, disp_string
))
26527 /* The first row that ends at ZV must be the last to be
26529 else if (next
->ends_at_zv_p
)
26538 /* This function sets the mouse_face_* elements of HLINFO, assuming
26539 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26540 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26541 for the overlay or run of text properties specifying the mouse
26542 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26543 before-string and after-string that must also be highlighted.
26544 DISP_STRING, if non-nil, is a display string that may cover some
26545 or all of the highlighted text. */
26548 mouse_face_from_buffer_pos (Lisp_Object window
,
26549 Mouse_HLInfo
*hlinfo
,
26550 ptrdiff_t mouse_charpos
,
26551 ptrdiff_t start_charpos
,
26552 ptrdiff_t end_charpos
,
26553 Lisp_Object before_string
,
26554 Lisp_Object after_string
,
26555 Lisp_Object disp_string
)
26557 struct window
*w
= XWINDOW (window
);
26558 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26559 struct glyph_row
*r1
, *r2
;
26560 struct glyph
*glyph
, *end
;
26561 ptrdiff_t ignore
, pos
;
26564 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26565 eassert (NILP (before_string
) || STRINGP (before_string
));
26566 eassert (NILP (after_string
) || STRINGP (after_string
));
26568 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26569 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26571 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (WVAR (w
, window_end_vpos
)));
26572 /* If the before-string or display-string contains newlines,
26573 rows_from_pos_range skips to its last row. Move back. */
26574 if (!NILP (before_string
) || !NILP (disp_string
))
26576 struct glyph_row
*prev
;
26577 while ((prev
= r1
- 1, prev
>= first
)
26578 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26579 && prev
->used
[TEXT_AREA
] > 0)
26581 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26582 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26583 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26585 || !(EQ (glyph
->object
, before_string
)
26586 || EQ (glyph
->object
, disp_string
)))
26593 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (WVAR (w
, window_end_vpos
)));
26594 hlinfo
->mouse_face_past_end
= 1;
26596 else if (!NILP (after_string
))
26598 /* If the after-string has newlines, advance to its last row. */
26599 struct glyph_row
*next
;
26600 struct glyph_row
*last
26601 = MATRIX_ROW (w
->current_matrix
, XFASTINT (WVAR (w
, window_end_vpos
)));
26603 for (next
= r2
+ 1;
26605 && next
->used
[TEXT_AREA
] > 0
26606 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26610 /* The rest of the display engine assumes that mouse_face_beg_row is
26611 either above mouse_face_end_row or identical to it. But with
26612 bidi-reordered continued lines, the row for START_CHARPOS could
26613 be below the row for END_CHARPOS. If so, swap the rows and store
26614 them in correct order. */
26617 struct glyph_row
*tem
= r2
;
26623 hlinfo
->mouse_face_beg_y
= r1
->y
;
26624 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26625 hlinfo
->mouse_face_end_y
= r2
->y
;
26626 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26628 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26629 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26630 could be anywhere in the row and in any order. The strategy
26631 below is to find the leftmost and the rightmost glyph that
26632 belongs to either of these 3 strings, or whose position is
26633 between START_CHARPOS and END_CHARPOS, and highlight all the
26634 glyphs between those two. This may cover more than just the text
26635 between START_CHARPOS and END_CHARPOS if the range of characters
26636 strides the bidi level boundary, e.g. if the beginning is in R2L
26637 text while the end is in L2R text or vice versa. */
26638 if (!r1
->reversed_p
)
26640 /* This row is in a left to right paragraph. Scan it left to
26642 glyph
= r1
->glyphs
[TEXT_AREA
];
26643 end
= glyph
+ r1
->used
[TEXT_AREA
];
26646 /* Skip truncation glyphs at the start of the glyph row. */
26647 if (r1
->displays_text_p
)
26649 && INTEGERP (glyph
->object
)
26650 && glyph
->charpos
< 0;
26652 x
+= glyph
->pixel_width
;
26654 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26655 or DISP_STRING, and the first glyph from buffer whose
26656 position is between START_CHARPOS and END_CHARPOS. */
26658 && !INTEGERP (glyph
->object
)
26659 && !EQ (glyph
->object
, disp_string
)
26660 && !(BUFFERP (glyph
->object
)
26661 && (glyph
->charpos
>= start_charpos
26662 && glyph
->charpos
< end_charpos
));
26665 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26666 are present at buffer positions between START_CHARPOS and
26667 END_CHARPOS, or if they come from an overlay. */
26668 if (EQ (glyph
->object
, before_string
))
26670 pos
= string_buffer_position (before_string
,
26672 /* If pos == 0, it means before_string came from an
26673 overlay, not from a buffer position. */
26674 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26677 else if (EQ (glyph
->object
, after_string
))
26679 pos
= string_buffer_position (after_string
, end_charpos
);
26680 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26683 x
+= glyph
->pixel_width
;
26685 hlinfo
->mouse_face_beg_x
= x
;
26686 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26690 /* This row is in a right to left paragraph. Scan it right to
26694 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26695 glyph
= end
+ r1
->used
[TEXT_AREA
];
26697 /* Skip truncation glyphs at the start of the glyph row. */
26698 if (r1
->displays_text_p
)
26700 && INTEGERP (glyph
->object
)
26701 && glyph
->charpos
< 0;
26705 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26706 or DISP_STRING, and the first glyph from buffer whose
26707 position is between START_CHARPOS and END_CHARPOS. */
26709 && !INTEGERP (glyph
->object
)
26710 && !EQ (glyph
->object
, disp_string
)
26711 && !(BUFFERP (glyph
->object
)
26712 && (glyph
->charpos
>= start_charpos
26713 && glyph
->charpos
< end_charpos
));
26716 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26717 are present at buffer positions between START_CHARPOS and
26718 END_CHARPOS, or if they come from an overlay. */
26719 if (EQ (glyph
->object
, before_string
))
26721 pos
= string_buffer_position (before_string
, start_charpos
);
26722 /* If pos == 0, it means before_string came from an
26723 overlay, not from a buffer position. */
26724 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26727 else if (EQ (glyph
->object
, after_string
))
26729 pos
= string_buffer_position (after_string
, end_charpos
);
26730 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26735 glyph
++; /* first glyph to the right of the highlighted area */
26736 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26737 x
+= g
->pixel_width
;
26738 hlinfo
->mouse_face_beg_x
= x
;
26739 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26742 /* If the highlight ends in a different row, compute GLYPH and END
26743 for the end row. Otherwise, reuse the values computed above for
26744 the row where the highlight begins. */
26747 if (!r2
->reversed_p
)
26749 glyph
= r2
->glyphs
[TEXT_AREA
];
26750 end
= glyph
+ r2
->used
[TEXT_AREA
];
26755 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26756 glyph
= end
+ r2
->used
[TEXT_AREA
];
26760 if (!r2
->reversed_p
)
26762 /* Skip truncation and continuation glyphs near the end of the
26763 row, and also blanks and stretch glyphs inserted by
26764 extend_face_to_end_of_line. */
26766 && INTEGERP ((end
- 1)->object
))
26768 /* Scan the rest of the glyph row from the end, looking for the
26769 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26770 DISP_STRING, or whose position is between START_CHARPOS
26774 && !INTEGERP (end
->object
)
26775 && !EQ (end
->object
, disp_string
)
26776 && !(BUFFERP (end
->object
)
26777 && (end
->charpos
>= start_charpos
26778 && end
->charpos
< end_charpos
));
26781 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26782 are present at buffer positions between START_CHARPOS and
26783 END_CHARPOS, or if they come from an overlay. */
26784 if (EQ (end
->object
, before_string
))
26786 pos
= string_buffer_position (before_string
, start_charpos
);
26787 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26790 else if (EQ (end
->object
, after_string
))
26792 pos
= string_buffer_position (after_string
, end_charpos
);
26793 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26797 /* Find the X coordinate of the last glyph to be highlighted. */
26798 for (; glyph
<= end
; ++glyph
)
26799 x
+= glyph
->pixel_width
;
26801 hlinfo
->mouse_face_end_x
= x
;
26802 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26806 /* Skip truncation and continuation glyphs near the end of the
26807 row, and also blanks and stretch glyphs inserted by
26808 extend_face_to_end_of_line. */
26812 && INTEGERP (end
->object
))
26814 x
+= end
->pixel_width
;
26817 /* Scan the rest of the glyph row from the end, looking for the
26818 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26819 DISP_STRING, or whose position is between START_CHARPOS
26823 && !INTEGERP (end
->object
)
26824 && !EQ (end
->object
, disp_string
)
26825 && !(BUFFERP (end
->object
)
26826 && (end
->charpos
>= start_charpos
26827 && end
->charpos
< end_charpos
));
26830 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26831 are present at buffer positions between START_CHARPOS and
26832 END_CHARPOS, or if they come from an overlay. */
26833 if (EQ (end
->object
, before_string
))
26835 pos
= string_buffer_position (before_string
, start_charpos
);
26836 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26839 else if (EQ (end
->object
, after_string
))
26841 pos
= string_buffer_position (after_string
, end_charpos
);
26842 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26845 x
+= end
->pixel_width
;
26847 /* If we exited the above loop because we arrived at the last
26848 glyph of the row, and its buffer position is still not in
26849 range, it means the last character in range is the preceding
26850 newline. Bump the end column and x values to get past the
26853 && BUFFERP (end
->object
)
26854 && (end
->charpos
< start_charpos
26855 || end
->charpos
>= end_charpos
))
26857 x
+= end
->pixel_width
;
26860 hlinfo
->mouse_face_end_x
= x
;
26861 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26864 hlinfo
->mouse_face_window
= window
;
26865 hlinfo
->mouse_face_face_id
26866 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26868 !hlinfo
->mouse_face_hidden
, -1);
26869 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26872 /* The following function is not used anymore (replaced with
26873 mouse_face_from_string_pos), but I leave it here for the time
26874 being, in case someone would. */
26876 #if 0 /* not used */
26878 /* Find the position of the glyph for position POS in OBJECT in
26879 window W's current matrix, and return in *X, *Y the pixel
26880 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26882 RIGHT_P non-zero means return the position of the right edge of the
26883 glyph, RIGHT_P zero means return the left edge position.
26885 If no glyph for POS exists in the matrix, return the position of
26886 the glyph with the next smaller position that is in the matrix, if
26887 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26888 exists in the matrix, return the position of the glyph with the
26889 next larger position in OBJECT.
26891 Value is non-zero if a glyph was found. */
26894 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26895 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26897 int yb
= window_text_bottom_y (w
);
26898 struct glyph_row
*r
;
26899 struct glyph
*best_glyph
= NULL
;
26900 struct glyph_row
*best_row
= NULL
;
26903 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26904 r
->enabled_p
&& r
->y
< yb
;
26907 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26908 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26911 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26912 if (EQ (g
->object
, object
))
26914 if (g
->charpos
== pos
)
26921 else if (best_glyph
== NULL
26922 || ((eabs (g
->charpos
- pos
)
26923 < eabs (best_glyph
->charpos
- pos
))
26926 : g
->charpos
> pos
)))
26940 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26944 *x
+= best_glyph
->pixel_width
;
26949 *vpos
= best_row
- w
->current_matrix
->rows
;
26952 return best_glyph
!= NULL
;
26954 #endif /* not used */
26956 /* Find the positions of the first and the last glyphs in window W's
26957 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26958 (assumed to be a string), and return in HLINFO's mouse_face_*
26959 members the pixel and column/row coordinates of those glyphs. */
26962 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26963 Lisp_Object object
,
26964 ptrdiff_t startpos
, ptrdiff_t endpos
)
26966 int yb
= window_text_bottom_y (w
);
26967 struct glyph_row
*r
;
26968 struct glyph
*g
, *e
;
26972 /* Find the glyph row with at least one position in the range
26973 [STARTPOS..ENDPOS], and the first glyph in that row whose
26974 position belongs to that range. */
26975 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26976 r
->enabled_p
&& r
->y
< yb
;
26979 if (!r
->reversed_p
)
26981 g
= r
->glyphs
[TEXT_AREA
];
26982 e
= g
+ r
->used
[TEXT_AREA
];
26983 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26984 if (EQ (g
->object
, object
)
26985 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26987 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26988 hlinfo
->mouse_face_beg_y
= r
->y
;
26989 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26990 hlinfo
->mouse_face_beg_x
= gx
;
26999 e
= r
->glyphs
[TEXT_AREA
];
27000 g
= e
+ r
->used
[TEXT_AREA
];
27001 for ( ; g
> e
; --g
)
27002 if (EQ ((g
-1)->object
, object
)
27003 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27005 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27006 hlinfo
->mouse_face_beg_y
= r
->y
;
27007 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27008 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27009 gx
+= g1
->pixel_width
;
27010 hlinfo
->mouse_face_beg_x
= gx
;
27022 /* Starting with the next row, look for the first row which does NOT
27023 include any glyphs whose positions are in the range. */
27024 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27026 g
= r
->glyphs
[TEXT_AREA
];
27027 e
= g
+ r
->used
[TEXT_AREA
];
27029 for ( ; g
< e
; ++g
)
27030 if (EQ (g
->object
, object
)
27031 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27040 /* The highlighted region ends on the previous row. */
27043 /* Set the end row and its vertical pixel coordinate. */
27044 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27045 hlinfo
->mouse_face_end_y
= r
->y
;
27047 /* Compute and set the end column and the end column's horizontal
27048 pixel coordinate. */
27049 if (!r
->reversed_p
)
27051 g
= r
->glyphs
[TEXT_AREA
];
27052 e
= g
+ r
->used
[TEXT_AREA
];
27053 for ( ; e
> g
; --e
)
27054 if (EQ ((e
-1)->object
, object
)
27055 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27057 hlinfo
->mouse_face_end_col
= e
- g
;
27059 for (gx
= r
->x
; g
< e
; ++g
)
27060 gx
+= g
->pixel_width
;
27061 hlinfo
->mouse_face_end_x
= gx
;
27065 e
= r
->glyphs
[TEXT_AREA
];
27066 g
= e
+ r
->used
[TEXT_AREA
];
27067 for (gx
= r
->x
; e
< g
; ++e
)
27069 if (EQ (e
->object
, object
)
27070 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27072 gx
+= e
->pixel_width
;
27074 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27075 hlinfo
->mouse_face_end_x
= gx
;
27079 #ifdef HAVE_WINDOW_SYSTEM
27081 /* See if position X, Y is within a hot-spot of an image. */
27084 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27086 if (!CONSP (hot_spot
))
27089 if (EQ (XCAR (hot_spot
), Qrect
))
27091 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27092 Lisp_Object rect
= XCDR (hot_spot
);
27096 if (!CONSP (XCAR (rect
)))
27098 if (!CONSP (XCDR (rect
)))
27100 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27102 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27104 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27106 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27110 else if (EQ (XCAR (hot_spot
), Qcircle
))
27112 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27113 Lisp_Object circ
= XCDR (hot_spot
);
27114 Lisp_Object lr
, lx0
, ly0
;
27116 && CONSP (XCAR (circ
))
27117 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27118 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27119 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27121 double r
= XFLOATINT (lr
);
27122 double dx
= XINT (lx0
) - x
;
27123 double dy
= XINT (ly0
) - y
;
27124 return (dx
* dx
+ dy
* dy
<= r
* r
);
27127 else if (EQ (XCAR (hot_spot
), Qpoly
))
27129 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27130 if (VECTORP (XCDR (hot_spot
)))
27132 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27133 Lisp_Object
*poly
= v
->contents
;
27134 ptrdiff_t n
= v
->header
.size
;
27137 Lisp_Object lx
, ly
;
27140 /* Need an even number of coordinates, and at least 3 edges. */
27141 if (n
< 6 || n
& 1)
27144 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27145 If count is odd, we are inside polygon. Pixels on edges
27146 may or may not be included depending on actual geometry of the
27148 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27149 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27151 x0
= XINT (lx
), y0
= XINT (ly
);
27152 for (i
= 0; i
< n
; i
+= 2)
27154 int x1
= x0
, y1
= y0
;
27155 if ((lx
= poly
[i
], !INTEGERP (lx
))
27156 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27158 x0
= XINT (lx
), y0
= XINT (ly
);
27160 /* Does this segment cross the X line? */
27168 if (y
> y0
&& y
> y1
)
27170 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27180 find_hot_spot (Lisp_Object map
, int x
, int y
)
27182 while (CONSP (map
))
27184 if (CONSP (XCAR (map
))
27185 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27193 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27195 doc
: /* Lookup in image map MAP coordinates X and Y.
27196 An image map is an alist where each element has the format (AREA ID PLIST).
27197 An AREA is specified as either a rectangle, a circle, or a polygon:
27198 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27199 pixel coordinates of the upper left and bottom right corners.
27200 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27201 and the radius of the circle; r may be a float or integer.
27202 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27203 vector describes one corner in the polygon.
27204 Returns the alist element for the first matching AREA in MAP. */)
27205 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27213 return find_hot_spot (map
,
27214 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27215 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27219 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27221 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27223 /* Do not change cursor shape while dragging mouse. */
27224 if (!NILP (do_mouse_tracking
))
27227 if (!NILP (pointer
))
27229 if (EQ (pointer
, Qarrow
))
27230 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27231 else if (EQ (pointer
, Qhand
))
27232 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27233 else if (EQ (pointer
, Qtext
))
27234 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27235 else if (EQ (pointer
, intern ("hdrag")))
27236 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27237 #ifdef HAVE_X_WINDOWS
27238 else if (EQ (pointer
, intern ("vdrag")))
27239 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27241 else if (EQ (pointer
, intern ("hourglass")))
27242 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27243 else if (EQ (pointer
, Qmodeline
))
27244 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27246 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27249 if (cursor
!= No_Cursor
)
27250 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27253 #endif /* HAVE_WINDOW_SYSTEM */
27255 /* Take proper action when mouse has moved to the mode or header line
27256 or marginal area AREA of window W, x-position X and y-position Y.
27257 X is relative to the start of the text display area of W, so the
27258 width of bitmap areas and scroll bars must be subtracted to get a
27259 position relative to the start of the mode line. */
27262 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27263 enum window_part area
)
27265 struct window
*w
= XWINDOW (window
);
27266 struct frame
*f
= XFRAME (WVAR (w
, frame
));
27267 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27268 #ifdef HAVE_WINDOW_SYSTEM
27269 Display_Info
*dpyinfo
;
27271 Cursor cursor
= No_Cursor
;
27272 Lisp_Object pointer
= Qnil
;
27273 int dx
, dy
, width
, height
;
27275 Lisp_Object string
, object
= Qnil
;
27276 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27278 Lisp_Object mouse_face
;
27279 int original_x_pixel
= x
;
27280 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27281 struct glyph_row
*row
IF_LINT (= 0);
27283 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27288 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27289 returns them in row/column units! */
27290 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27291 &object
, &dx
, &dy
, &width
, &height
);
27293 row
= (area
== ON_MODE_LINE
27294 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27295 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27297 /* Find the glyph under the mouse pointer. */
27298 if (row
->mode_line_p
&& row
->enabled_p
)
27300 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27301 end
= glyph
+ row
->used
[TEXT_AREA
];
27303 for (x0
= original_x_pixel
;
27304 glyph
< end
&& x0
>= glyph
->pixel_width
;
27306 x0
-= glyph
->pixel_width
;
27314 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27315 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27316 returns them in row/column units! */
27317 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27318 &object
, &dx
, &dy
, &width
, &height
);
27323 #ifdef HAVE_WINDOW_SYSTEM
27324 if (IMAGEP (object
))
27326 Lisp_Object image_map
, hotspot
;
27327 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27329 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27331 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27335 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27336 If so, we could look for mouse-enter, mouse-leave
27337 properties in PLIST (and do something...). */
27338 hotspot
= XCDR (hotspot
);
27339 if (CONSP (hotspot
)
27340 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27342 pointer
= Fplist_get (plist
, Qpointer
);
27343 if (NILP (pointer
))
27345 help
= Fplist_get (plist
, Qhelp_echo
);
27348 help_echo_string
= help
;
27349 XSETWINDOW (help_echo_window
, w
);
27350 help_echo_object
= WVAR (w
, buffer
);
27351 help_echo_pos
= charpos
;
27355 if (NILP (pointer
))
27356 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27358 #endif /* HAVE_WINDOW_SYSTEM */
27360 if (STRINGP (string
))
27361 pos
= make_number (charpos
);
27363 /* Set the help text and mouse pointer. If the mouse is on a part
27364 of the mode line without any text (e.g. past the right edge of
27365 the mode line text), use the default help text and pointer. */
27366 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27368 /* Arrange to display the help by setting the global variables
27369 help_echo_string, help_echo_object, and help_echo_pos. */
27372 if (STRINGP (string
))
27373 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27377 help_echo_string
= help
;
27378 XSETWINDOW (help_echo_window
, w
);
27379 help_echo_object
= string
;
27380 help_echo_pos
= charpos
;
27382 else if (area
== ON_MODE_LINE
)
27384 Lisp_Object default_help
27385 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27388 if (STRINGP (default_help
))
27390 help_echo_string
= default_help
;
27391 XSETWINDOW (help_echo_window
, w
);
27392 help_echo_object
= Qnil
;
27393 help_echo_pos
= -1;
27398 #ifdef HAVE_WINDOW_SYSTEM
27399 /* Change the mouse pointer according to what is under it. */
27400 if (FRAME_WINDOW_P (f
))
27402 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27403 if (STRINGP (string
))
27405 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27407 if (NILP (pointer
))
27408 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27410 /* Change the mouse pointer according to what is under X/Y. */
27412 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27415 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27416 if (!KEYMAPP (map
))
27417 map
= Fget_text_property (pos
, Qkeymap
, string
);
27418 if (!KEYMAPP (map
))
27419 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27423 /* Default mode-line pointer. */
27424 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27429 /* Change the mouse face according to what is under X/Y. */
27430 if (STRINGP (string
))
27432 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27433 if (!NILP (mouse_face
)
27434 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27439 struct glyph
* tmp_glyph
;
27443 int total_pixel_width
;
27444 ptrdiff_t begpos
, endpos
, ignore
;
27448 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27449 Qmouse_face
, string
, Qnil
);
27455 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27457 endpos
= SCHARS (string
);
27461 /* Calculate the glyph position GPOS of GLYPH in the
27462 displayed string, relative to the beginning of the
27463 highlighted part of the string.
27465 Note: GPOS is different from CHARPOS. CHARPOS is the
27466 position of GLYPH in the internal string object. A mode
27467 line string format has structures which are converted to
27468 a flattened string by the Emacs Lisp interpreter. The
27469 internal string is an element of those structures. The
27470 displayed string is the flattened string. */
27471 tmp_glyph
= row_start_glyph
;
27472 while (tmp_glyph
< glyph
27473 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27474 && begpos
<= tmp_glyph
->charpos
27475 && tmp_glyph
->charpos
< endpos
)))
27477 gpos
= glyph
- tmp_glyph
;
27479 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27480 the highlighted part of the displayed string to which
27481 GLYPH belongs. Note: GSEQ_LENGTH is different from
27482 SCHARS (STRING), because the latter returns the length of
27483 the internal string. */
27484 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27486 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27487 && begpos
<= tmp_glyph
->charpos
27488 && tmp_glyph
->charpos
< endpos
));
27491 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27493 /* Calculate the total pixel width of all the glyphs between
27494 the beginning of the highlighted area and GLYPH. */
27495 total_pixel_width
= 0;
27496 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27497 total_pixel_width
+= tmp_glyph
->pixel_width
;
27499 /* Pre calculation of re-rendering position. Note: X is in
27500 column units here, after the call to mode_line_string or
27501 marginal_area_string. */
27503 vpos
= (area
== ON_MODE_LINE
27504 ? (w
->current_matrix
)->nrows
- 1
27507 /* If GLYPH's position is included in the region that is
27508 already drawn in mouse face, we have nothing to do. */
27509 if ( EQ (window
, hlinfo
->mouse_face_window
)
27510 && (!row
->reversed_p
27511 ? (hlinfo
->mouse_face_beg_col
<= hpos
27512 && hpos
< hlinfo
->mouse_face_end_col
)
27513 /* In R2L rows we swap BEG and END, see below. */
27514 : (hlinfo
->mouse_face_end_col
<= hpos
27515 && hpos
< hlinfo
->mouse_face_beg_col
))
27516 && hlinfo
->mouse_face_beg_row
== vpos
)
27519 if (clear_mouse_face (hlinfo
))
27520 cursor
= No_Cursor
;
27522 if (!row
->reversed_p
)
27524 hlinfo
->mouse_face_beg_col
= hpos
;
27525 hlinfo
->mouse_face_beg_x
= original_x_pixel
27526 - (total_pixel_width
+ dx
);
27527 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27528 hlinfo
->mouse_face_end_x
= 0;
27532 /* In R2L rows, show_mouse_face expects BEG and END
27533 coordinates to be swapped. */
27534 hlinfo
->mouse_face_end_col
= hpos
;
27535 hlinfo
->mouse_face_end_x
= original_x_pixel
27536 - (total_pixel_width
+ dx
);
27537 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27538 hlinfo
->mouse_face_beg_x
= 0;
27541 hlinfo
->mouse_face_beg_row
= vpos
;
27542 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27543 hlinfo
->mouse_face_beg_y
= 0;
27544 hlinfo
->mouse_face_end_y
= 0;
27545 hlinfo
->mouse_face_past_end
= 0;
27546 hlinfo
->mouse_face_window
= window
;
27548 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27554 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27556 if (NILP (pointer
))
27559 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27560 clear_mouse_face (hlinfo
);
27562 #ifdef HAVE_WINDOW_SYSTEM
27563 if (FRAME_WINDOW_P (f
))
27564 define_frame_cursor1 (f
, cursor
, pointer
);
27570 Take proper action when the mouse has moved to position X, Y on
27571 frame F as regards highlighting characters that have mouse-face
27572 properties. Also de-highlighting chars where the mouse was before.
27573 X and Y can be negative or out of range. */
27576 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27578 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27579 enum window_part part
= ON_NOTHING
;
27580 Lisp_Object window
;
27582 Cursor cursor
= No_Cursor
;
27583 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27586 /* When a menu is active, don't highlight because this looks odd. */
27587 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27588 if (popup_activated ())
27592 if (NILP (Vmouse_highlight
)
27593 || !f
->glyphs_initialized_p
27594 || f
->pointer_invisible
)
27597 hlinfo
->mouse_face_mouse_x
= x
;
27598 hlinfo
->mouse_face_mouse_y
= y
;
27599 hlinfo
->mouse_face_mouse_frame
= f
;
27601 if (hlinfo
->mouse_face_defer
)
27604 if (gc_in_progress
)
27606 hlinfo
->mouse_face_deferred_gc
= 1;
27610 /* Which window is that in? */
27611 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27613 /* If displaying active text in another window, clear that. */
27614 if (! EQ (window
, hlinfo
->mouse_face_window
)
27615 /* Also clear if we move out of text area in same window. */
27616 || (!NILP (hlinfo
->mouse_face_window
)
27619 && part
!= ON_MODE_LINE
27620 && part
!= ON_HEADER_LINE
))
27621 clear_mouse_face (hlinfo
);
27623 /* Not on a window -> return. */
27624 if (!WINDOWP (window
))
27627 /* Reset help_echo_string. It will get recomputed below. */
27628 help_echo_string
= Qnil
;
27630 /* Convert to window-relative pixel coordinates. */
27631 w
= XWINDOW (window
);
27632 frame_to_window_pixel_xy (w
, &x
, &y
);
27634 #ifdef HAVE_WINDOW_SYSTEM
27635 /* Handle tool-bar window differently since it doesn't display a
27637 if (EQ (window
, FVAR (f
, tool_bar_window
)))
27639 note_tool_bar_highlight (f
, x
, y
);
27644 /* Mouse is on the mode, header line or margin? */
27645 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27646 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27648 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27652 #ifdef HAVE_WINDOW_SYSTEM
27653 if (part
== ON_VERTICAL_BORDER
)
27655 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27656 help_echo_string
= build_string ("drag-mouse-1: resize");
27658 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27659 || part
== ON_SCROLL_BAR
)
27660 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27662 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27665 /* Are we in a window whose display is up to date?
27666 And verify the buffer's text has not changed. */
27667 b
= XBUFFER (WVAR (w
, buffer
));
27668 if (part
== ON_TEXT
27669 && EQ (WVAR (w
, window_end_valid
), WVAR (w
, buffer
))
27670 && w
->last_modified
== BUF_MODIFF (b
)
27671 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27673 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27675 struct glyph
*glyph
;
27676 Lisp_Object object
;
27677 Lisp_Object mouse_face
= Qnil
, position
;
27678 Lisp_Object
*overlay_vec
= NULL
;
27679 ptrdiff_t i
, noverlays
;
27680 struct buffer
*obuf
;
27681 ptrdiff_t obegv
, ozv
;
27684 /* Find the glyph under X/Y. */
27685 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27687 #ifdef HAVE_WINDOW_SYSTEM
27688 /* Look for :pointer property on image. */
27689 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27691 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27692 if (img
!= NULL
&& IMAGEP (img
->spec
))
27694 Lisp_Object image_map
, hotspot
;
27695 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27697 && (hotspot
= find_hot_spot (image_map
,
27698 glyph
->slice
.img
.x
+ dx
,
27699 glyph
->slice
.img
.y
+ dy
),
27701 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27705 /* Could check XCAR (hotspot) to see if we enter/leave
27707 If so, we could look for mouse-enter, mouse-leave
27708 properties in PLIST (and do something...). */
27709 hotspot
= XCDR (hotspot
);
27710 if (CONSP (hotspot
)
27711 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27713 pointer
= Fplist_get (plist
, Qpointer
);
27714 if (NILP (pointer
))
27716 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27717 if (!NILP (help_echo_string
))
27719 help_echo_window
= window
;
27720 help_echo_object
= glyph
->object
;
27721 help_echo_pos
= glyph
->charpos
;
27725 if (NILP (pointer
))
27726 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27729 #endif /* HAVE_WINDOW_SYSTEM */
27731 /* Clear mouse face if X/Y not over text. */
27733 || area
!= TEXT_AREA
27734 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27735 /* Glyph's OBJECT is an integer for glyphs inserted by the
27736 display engine for its internal purposes, like truncation
27737 and continuation glyphs and blanks beyond the end of
27738 line's text on text terminals. If we are over such a
27739 glyph, we are not over any text. */
27740 || INTEGERP (glyph
->object
)
27741 /* R2L rows have a stretch glyph at their front, which
27742 stands for no text, whereas L2R rows have no glyphs at
27743 all beyond the end of text. Treat such stretch glyphs
27744 like we do with NULL glyphs in L2R rows. */
27745 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27746 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27747 && glyph
->type
== STRETCH_GLYPH
27748 && glyph
->avoid_cursor_p
))
27750 if (clear_mouse_face (hlinfo
))
27751 cursor
= No_Cursor
;
27752 #ifdef HAVE_WINDOW_SYSTEM
27753 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27755 if (area
!= TEXT_AREA
)
27756 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27758 pointer
= Vvoid_text_area_pointer
;
27764 pos
= glyph
->charpos
;
27765 object
= glyph
->object
;
27766 if (!STRINGP (object
) && !BUFFERP (object
))
27769 /* If we get an out-of-range value, return now; avoid an error. */
27770 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27773 /* Make the window's buffer temporarily current for
27774 overlays_at and compute_char_face. */
27775 obuf
= current_buffer
;
27776 current_buffer
= b
;
27782 /* Is this char mouse-active or does it have help-echo? */
27783 position
= make_number (pos
);
27785 if (BUFFERP (object
))
27787 /* Put all the overlays we want in a vector in overlay_vec. */
27788 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27789 /* Sort overlays into increasing priority order. */
27790 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27795 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27798 cursor
= No_Cursor
;
27800 /* Check mouse-face highlighting. */
27802 /* If there exists an overlay with mouse-face overlapping
27803 the one we are currently highlighting, we have to
27804 check if we enter the overlapping overlay, and then
27805 highlight only that. */
27806 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27807 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27809 /* Find the highest priority overlay with a mouse-face. */
27810 Lisp_Object overlay
= Qnil
;
27811 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27813 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27814 if (!NILP (mouse_face
))
27815 overlay
= overlay_vec
[i
];
27818 /* If we're highlighting the same overlay as before, there's
27819 no need to do that again. */
27820 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27821 goto check_help_echo
;
27822 hlinfo
->mouse_face_overlay
= overlay
;
27824 /* Clear the display of the old active region, if any. */
27825 if (clear_mouse_face (hlinfo
))
27826 cursor
= No_Cursor
;
27828 /* If no overlay applies, get a text property. */
27829 if (NILP (overlay
))
27830 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27832 /* Next, compute the bounds of the mouse highlighting and
27834 if (!NILP (mouse_face
) && STRINGP (object
))
27836 /* The mouse-highlighting comes from a display string
27837 with a mouse-face. */
27841 s
= Fprevious_single_property_change
27842 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27843 e
= Fnext_single_property_change
27844 (position
, Qmouse_face
, object
, Qnil
);
27846 s
= make_number (0);
27848 e
= make_number (SCHARS (object
) - 1);
27849 mouse_face_from_string_pos (w
, hlinfo
, object
,
27850 XINT (s
), XINT (e
));
27851 hlinfo
->mouse_face_past_end
= 0;
27852 hlinfo
->mouse_face_window
= window
;
27853 hlinfo
->mouse_face_face_id
27854 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27855 glyph
->face_id
, 1);
27856 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27857 cursor
= No_Cursor
;
27861 /* The mouse-highlighting, if any, comes from an overlay
27862 or text property in the buffer. */
27863 Lisp_Object buffer
IF_LINT (= Qnil
);
27864 Lisp_Object disp_string
IF_LINT (= Qnil
);
27866 if (STRINGP (object
))
27868 /* If we are on a display string with no mouse-face,
27869 check if the text under it has one. */
27870 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27871 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27872 pos
= string_buffer_position (object
, start
);
27875 mouse_face
= get_char_property_and_overlay
27876 (make_number (pos
), Qmouse_face
, WVAR (w
, buffer
), &overlay
);
27877 buffer
= WVAR (w
, buffer
);
27878 disp_string
= object
;
27884 disp_string
= Qnil
;
27887 if (!NILP (mouse_face
))
27889 Lisp_Object before
, after
;
27890 Lisp_Object before_string
, after_string
;
27891 /* To correctly find the limits of mouse highlight
27892 in a bidi-reordered buffer, we must not use the
27893 optimization of limiting the search in
27894 previous-single-property-change and
27895 next-single-property-change, because
27896 rows_from_pos_range needs the real start and end
27897 positions to DTRT in this case. That's because
27898 the first row visible in a window does not
27899 necessarily display the character whose position
27900 is the smallest. */
27902 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27903 ? Fmarker_position (WVAR (w
, start
))
27906 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27907 ? make_number (BUF_Z (XBUFFER (buffer
))
27908 - XFASTINT (WVAR (w
, window_end_pos
)))
27911 if (NILP (overlay
))
27913 /* Handle the text property case. */
27914 before
= Fprevious_single_property_change
27915 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27916 after
= Fnext_single_property_change
27917 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27918 before_string
= after_string
= Qnil
;
27922 /* Handle the overlay case. */
27923 before
= Foverlay_start (overlay
);
27924 after
= Foverlay_end (overlay
);
27925 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27926 after_string
= Foverlay_get (overlay
, Qafter_string
);
27928 if (!STRINGP (before_string
)) before_string
= Qnil
;
27929 if (!STRINGP (after_string
)) after_string
= Qnil
;
27932 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27935 : XFASTINT (before
),
27937 ? BUF_Z (XBUFFER (buffer
))
27938 : XFASTINT (after
),
27939 before_string
, after_string
,
27941 cursor
= No_Cursor
;
27948 /* Look for a `help-echo' property. */
27949 if (NILP (help_echo_string
)) {
27950 Lisp_Object help
, overlay
;
27952 /* Check overlays first. */
27953 help
= overlay
= Qnil
;
27954 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27956 overlay
= overlay_vec
[i
];
27957 help
= Foverlay_get (overlay
, Qhelp_echo
);
27962 help_echo_string
= help
;
27963 help_echo_window
= window
;
27964 help_echo_object
= overlay
;
27965 help_echo_pos
= pos
;
27969 Lisp_Object obj
= glyph
->object
;
27970 ptrdiff_t charpos
= glyph
->charpos
;
27972 /* Try text properties. */
27975 && charpos
< SCHARS (obj
))
27977 help
= Fget_text_property (make_number (charpos
),
27981 /* If the string itself doesn't specify a help-echo,
27982 see if the buffer text ``under'' it does. */
27983 struct glyph_row
*r
27984 = MATRIX_ROW (w
->current_matrix
, vpos
);
27985 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27986 ptrdiff_t p
= string_buffer_position (obj
, start
);
27989 help
= Fget_char_property (make_number (p
),
27990 Qhelp_echo
, WVAR (w
, buffer
));
27994 obj
= WVAR (w
, buffer
);
27999 else if (BUFFERP (obj
)
28002 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28007 help_echo_string
= help
;
28008 help_echo_window
= window
;
28009 help_echo_object
= obj
;
28010 help_echo_pos
= charpos
;
28015 #ifdef HAVE_WINDOW_SYSTEM
28016 /* Look for a `pointer' property. */
28017 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28019 /* Check overlays first. */
28020 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28021 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28023 if (NILP (pointer
))
28025 Lisp_Object obj
= glyph
->object
;
28026 ptrdiff_t charpos
= glyph
->charpos
;
28028 /* Try text properties. */
28031 && charpos
< SCHARS (obj
))
28033 pointer
= Fget_text_property (make_number (charpos
),
28035 if (NILP (pointer
))
28037 /* If the string itself doesn't specify a pointer,
28038 see if the buffer text ``under'' it does. */
28039 struct glyph_row
*r
28040 = MATRIX_ROW (w
->current_matrix
, vpos
);
28041 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28042 ptrdiff_t p
= string_buffer_position (obj
, start
);
28044 pointer
= Fget_char_property (make_number (p
),
28045 Qpointer
, WVAR (w
, buffer
));
28048 else if (BUFFERP (obj
)
28051 pointer
= Fget_text_property (make_number (charpos
),
28055 #endif /* HAVE_WINDOW_SYSTEM */
28059 current_buffer
= obuf
;
28064 #ifdef HAVE_WINDOW_SYSTEM
28065 if (FRAME_WINDOW_P (f
))
28066 define_frame_cursor1 (f
, cursor
, pointer
);
28068 /* This is here to prevent a compiler error, about "label at end of
28069 compound statement". */
28076 Clear any mouse-face on window W. This function is part of the
28077 redisplay interface, and is called from try_window_id and similar
28078 functions to ensure the mouse-highlight is off. */
28081 x_clear_window_mouse_face (struct window
*w
)
28083 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (WVAR (w
, frame
)));
28084 Lisp_Object window
;
28087 XSETWINDOW (window
, w
);
28088 if (EQ (window
, hlinfo
->mouse_face_window
))
28089 clear_mouse_face (hlinfo
);
28095 Just discard the mouse face information for frame F, if any.
28096 This is used when the size of F is changed. */
28099 cancel_mouse_face (struct frame
*f
)
28101 Lisp_Object window
;
28102 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28104 window
= hlinfo
->mouse_face_window
;
28105 if (! NILP (window
) && XFRAME (WVAR (XWINDOW (window
), frame
)) == f
)
28107 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28108 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28109 hlinfo
->mouse_face_window
= Qnil
;
28115 /***********************************************************************
28117 ***********************************************************************/
28119 #ifdef HAVE_WINDOW_SYSTEM
28121 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28122 which intersects rectangle R. R is in window-relative coordinates. */
28125 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28126 enum glyph_row_area area
)
28128 struct glyph
*first
= row
->glyphs
[area
];
28129 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28130 struct glyph
*last
;
28131 int first_x
, start_x
, x
;
28133 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28134 /* If row extends face to end of line write the whole line. */
28135 draw_glyphs (w
, 0, row
, area
,
28136 0, row
->used
[area
],
28137 DRAW_NORMAL_TEXT
, 0);
28140 /* Set START_X to the window-relative start position for drawing glyphs of
28141 AREA. The first glyph of the text area can be partially visible.
28142 The first glyphs of other areas cannot. */
28143 start_x
= window_box_left_offset (w
, area
);
28145 if (area
== TEXT_AREA
)
28148 /* Find the first glyph that must be redrawn. */
28150 && x
+ first
->pixel_width
< r
->x
)
28152 x
+= first
->pixel_width
;
28156 /* Find the last one. */
28160 && x
< r
->x
+ r
->width
)
28162 x
+= last
->pixel_width
;
28168 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28169 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28170 DRAW_NORMAL_TEXT
, 0);
28175 /* Redraw the parts of the glyph row ROW on window W intersecting
28176 rectangle R. R is in window-relative coordinates. Value is
28177 non-zero if mouse-face was overwritten. */
28180 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28182 eassert (row
->enabled_p
);
28184 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28185 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28186 0, row
->used
[TEXT_AREA
],
28187 DRAW_NORMAL_TEXT
, 0);
28190 if (row
->used
[LEFT_MARGIN_AREA
])
28191 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28192 if (row
->used
[TEXT_AREA
])
28193 expose_area (w
, row
, r
, TEXT_AREA
);
28194 if (row
->used
[RIGHT_MARGIN_AREA
])
28195 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28196 draw_row_fringe_bitmaps (w
, row
);
28199 return row
->mouse_face_p
;
28203 /* Redraw those parts of glyphs rows during expose event handling that
28204 overlap other rows. Redrawing of an exposed line writes over parts
28205 of lines overlapping that exposed line; this function fixes that.
28207 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28208 row in W's current matrix that is exposed and overlaps other rows.
28209 LAST_OVERLAPPING_ROW is the last such row. */
28212 expose_overlaps (struct window
*w
,
28213 struct glyph_row
*first_overlapping_row
,
28214 struct glyph_row
*last_overlapping_row
,
28217 struct glyph_row
*row
;
28219 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28220 if (row
->overlapping_p
)
28222 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28225 if (row
->used
[LEFT_MARGIN_AREA
])
28226 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28228 if (row
->used
[TEXT_AREA
])
28229 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28231 if (row
->used
[RIGHT_MARGIN_AREA
])
28232 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28238 /* Return non-zero if W's cursor intersects rectangle R. */
28241 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28243 XRectangle cr
, result
;
28244 struct glyph
*cursor_glyph
;
28245 struct glyph_row
*row
;
28247 if (w
->phys_cursor
.vpos
>= 0
28248 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28249 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28251 && row
->cursor_in_fringe_p
)
28253 /* Cursor is in the fringe. */
28254 cr
.x
= window_box_right_offset (w
,
28255 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28256 ? RIGHT_MARGIN_AREA
28259 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28260 cr
.height
= row
->height
;
28261 return x_intersect_rectangles (&cr
, r
, &result
);
28264 cursor_glyph
= get_phys_cursor_glyph (w
);
28267 /* r is relative to W's box, but w->phys_cursor.x is relative
28268 to left edge of W's TEXT area. Adjust it. */
28269 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28270 cr
.y
= w
->phys_cursor
.y
;
28271 cr
.width
= cursor_glyph
->pixel_width
;
28272 cr
.height
= w
->phys_cursor_height
;
28273 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28274 I assume the effect is the same -- and this is portable. */
28275 return x_intersect_rectangles (&cr
, r
, &result
);
28277 /* If we don't understand the format, pretend we're not in the hot-spot. */
28283 Draw a vertical window border to the right of window W if W doesn't
28284 have vertical scroll bars. */
28287 x_draw_vertical_border (struct window
*w
)
28289 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28291 /* We could do better, if we knew what type of scroll-bar the adjacent
28292 windows (on either side) have... But we don't :-(
28293 However, I think this works ok. ++KFS 2003-04-25 */
28295 /* Redraw borders between horizontally adjacent windows. Don't
28296 do it for frames with vertical scroll bars because either the
28297 right scroll bar of a window, or the left scroll bar of its
28298 neighbor will suffice as a border. */
28299 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (WVAR (w
, frame
))))
28302 if (!WINDOW_RIGHTMOST_P (w
)
28303 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28305 int x0
, x1
, y0
, y1
;
28307 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28310 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28313 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28315 else if (!WINDOW_LEFTMOST_P (w
)
28316 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28318 int x0
, x1
, y0
, y1
;
28320 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28323 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28326 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28331 /* Redraw the part of window W intersection rectangle FR. Pixel
28332 coordinates in FR are frame-relative. Call this function with
28333 input blocked. Value is non-zero if the exposure overwrites
28337 expose_window (struct window
*w
, XRectangle
*fr
)
28339 struct frame
*f
= XFRAME (WVAR (w
, frame
));
28341 int mouse_face_overwritten_p
= 0;
28343 /* If window is not yet fully initialized, do nothing. This can
28344 happen when toolkit scroll bars are used and a window is split.
28345 Reconfiguring the scroll bar will generate an expose for a newly
28347 if (w
->current_matrix
== NULL
)
28350 /* When we're currently updating the window, display and current
28351 matrix usually don't agree. Arrange for a thorough display
28353 if (w
== updated_window
)
28355 SET_FRAME_GARBAGED (f
);
28359 /* Frame-relative pixel rectangle of W. */
28360 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28361 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28362 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28363 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28365 if (x_intersect_rectangles (fr
, &wr
, &r
))
28367 int yb
= window_text_bottom_y (w
);
28368 struct glyph_row
*row
;
28369 int cursor_cleared_p
, phys_cursor_on_p
;
28370 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28372 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28373 r
.x
, r
.y
, r
.width
, r
.height
));
28375 /* Convert to window coordinates. */
28376 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28377 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28379 /* Turn off the cursor. */
28380 if (!w
->pseudo_window_p
28381 && phys_cursor_in_rect_p (w
, &r
))
28383 x_clear_cursor (w
);
28384 cursor_cleared_p
= 1;
28387 cursor_cleared_p
= 0;
28389 /* If the row containing the cursor extends face to end of line,
28390 then expose_area might overwrite the cursor outside the
28391 rectangle and thus notice_overwritten_cursor might clear
28392 w->phys_cursor_on_p. We remember the original value and
28393 check later if it is changed. */
28394 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28396 /* Update lines intersecting rectangle R. */
28397 first_overlapping_row
= last_overlapping_row
= NULL
;
28398 for (row
= w
->current_matrix
->rows
;
28403 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28405 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28406 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28407 || (r
.y
>= y0
&& r
.y
< y1
)
28408 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28410 /* A header line may be overlapping, but there is no need
28411 to fix overlapping areas for them. KFS 2005-02-12 */
28412 if (row
->overlapping_p
&& !row
->mode_line_p
)
28414 if (first_overlapping_row
== NULL
)
28415 first_overlapping_row
= row
;
28416 last_overlapping_row
= row
;
28420 if (expose_line (w
, row
, &r
))
28421 mouse_face_overwritten_p
= 1;
28424 else if (row
->overlapping_p
)
28426 /* We must redraw a row overlapping the exposed area. */
28428 ? y0
+ row
->phys_height
> r
.y
28429 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28431 if (first_overlapping_row
== NULL
)
28432 first_overlapping_row
= row
;
28433 last_overlapping_row
= row
;
28441 /* Display the mode line if there is one. */
28442 if (WINDOW_WANTS_MODELINE_P (w
)
28443 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28445 && row
->y
< r
.y
+ r
.height
)
28447 if (expose_line (w
, row
, &r
))
28448 mouse_face_overwritten_p
= 1;
28451 if (!w
->pseudo_window_p
)
28453 /* Fix the display of overlapping rows. */
28454 if (first_overlapping_row
)
28455 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28458 /* Draw border between windows. */
28459 x_draw_vertical_border (w
);
28461 /* Turn the cursor on again. */
28462 if (cursor_cleared_p
28463 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28464 update_window_cursor (w
, 1);
28468 return mouse_face_overwritten_p
;
28473 /* Redraw (parts) of all windows in the window tree rooted at W that
28474 intersect R. R contains frame pixel coordinates. Value is
28475 non-zero if the exposure overwrites mouse-face. */
28478 expose_window_tree (struct window
*w
, XRectangle
*r
)
28480 struct frame
*f
= XFRAME (WVAR (w
, frame
));
28481 int mouse_face_overwritten_p
= 0;
28483 while (w
&& !FRAME_GARBAGED_P (f
))
28485 if (!NILP (WVAR (w
, hchild
)))
28486 mouse_face_overwritten_p
28487 |= expose_window_tree (XWINDOW (WVAR (w
, hchild
)), r
);
28488 else if (!NILP (WVAR (w
, vchild
)))
28489 mouse_face_overwritten_p
28490 |= expose_window_tree (XWINDOW (WVAR (w
, vchild
)), r
);
28492 mouse_face_overwritten_p
|= expose_window (w
, r
);
28494 w
= NILP (WVAR (w
, next
)) ? NULL
: XWINDOW (WVAR (w
, next
));
28497 return mouse_face_overwritten_p
;
28502 Redisplay an exposed area of frame F. X and Y are the upper-left
28503 corner of the exposed rectangle. W and H are width and height of
28504 the exposed area. All are pixel values. W or H zero means redraw
28505 the entire frame. */
28508 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28511 int mouse_face_overwritten_p
= 0;
28513 TRACE ((stderr
, "expose_frame "));
28515 /* No need to redraw if frame will be redrawn soon. */
28516 if (FRAME_GARBAGED_P (f
))
28518 TRACE ((stderr
, " garbaged\n"));
28522 /* If basic faces haven't been realized yet, there is no point in
28523 trying to redraw anything. This can happen when we get an expose
28524 event while Emacs is starting, e.g. by moving another window. */
28525 if (FRAME_FACE_CACHE (f
) == NULL
28526 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28528 TRACE ((stderr
, " no faces\n"));
28532 if (w
== 0 || h
== 0)
28535 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28536 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28546 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28547 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (FVAR (f
, root_window
)), &r
);
28549 if (WINDOWP (FVAR (f
, tool_bar_window
)))
28550 mouse_face_overwritten_p
28551 |= expose_window (XWINDOW (FVAR (f
, tool_bar_window
)), &r
);
28553 #ifdef HAVE_X_WINDOWS
28555 #ifndef USE_X_TOOLKIT
28556 if (WINDOWP (FVAR (f
, menu_bar_window
)))
28557 mouse_face_overwritten_p
28558 |= expose_window (XWINDOW (FVAR (f
, menu_bar_window
)), &r
);
28559 #endif /* not USE_X_TOOLKIT */
28563 /* Some window managers support a focus-follows-mouse style with
28564 delayed raising of frames. Imagine a partially obscured frame,
28565 and moving the mouse into partially obscured mouse-face on that
28566 frame. The visible part of the mouse-face will be highlighted,
28567 then the WM raises the obscured frame. With at least one WM, KDE
28568 2.1, Emacs is not getting any event for the raising of the frame
28569 (even tried with SubstructureRedirectMask), only Expose events.
28570 These expose events will draw text normally, i.e. not
28571 highlighted. Which means we must redo the highlight here.
28572 Subsume it under ``we love X''. --gerd 2001-08-15 */
28573 /* Included in Windows version because Windows most likely does not
28574 do the right thing if any third party tool offers
28575 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28576 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28578 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28579 if (f
== hlinfo
->mouse_face_mouse_frame
)
28581 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28582 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28583 clear_mouse_face (hlinfo
);
28584 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28591 Determine the intersection of two rectangles R1 and R2. Return
28592 the intersection in *RESULT. Value is non-zero if RESULT is not
28596 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28598 XRectangle
*left
, *right
;
28599 XRectangle
*upper
, *lower
;
28600 int intersection_p
= 0;
28602 /* Rearrange so that R1 is the left-most rectangle. */
28604 left
= r1
, right
= r2
;
28606 left
= r2
, right
= r1
;
28608 /* X0 of the intersection is right.x0, if this is inside R1,
28609 otherwise there is no intersection. */
28610 if (right
->x
<= left
->x
+ left
->width
)
28612 result
->x
= right
->x
;
28614 /* The right end of the intersection is the minimum of
28615 the right ends of left and right. */
28616 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28619 /* Same game for Y. */
28621 upper
= r1
, lower
= r2
;
28623 upper
= r2
, lower
= r1
;
28625 /* The upper end of the intersection is lower.y0, if this is inside
28626 of upper. Otherwise, there is no intersection. */
28627 if (lower
->y
<= upper
->y
+ upper
->height
)
28629 result
->y
= lower
->y
;
28631 /* The lower end of the intersection is the minimum of the lower
28632 ends of upper and lower. */
28633 result
->height
= (min (lower
->y
+ lower
->height
,
28634 upper
->y
+ upper
->height
)
28636 intersection_p
= 1;
28640 return intersection_p
;
28643 #endif /* HAVE_WINDOW_SYSTEM */
28646 /***********************************************************************
28648 ***********************************************************************/
28651 syms_of_xdisp (void)
28653 Vwith_echo_area_save_vector
= Qnil
;
28654 staticpro (&Vwith_echo_area_save_vector
);
28656 Vmessage_stack
= Qnil
;
28657 staticpro (&Vmessage_stack
);
28659 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28661 message_dolog_marker1
= Fmake_marker ();
28662 staticpro (&message_dolog_marker1
);
28663 message_dolog_marker2
= Fmake_marker ();
28664 staticpro (&message_dolog_marker2
);
28665 message_dolog_marker3
= Fmake_marker ();
28666 staticpro (&message_dolog_marker3
);
28669 defsubr (&Sdump_frame_glyph_matrix
);
28670 defsubr (&Sdump_glyph_matrix
);
28671 defsubr (&Sdump_glyph_row
);
28672 defsubr (&Sdump_tool_bar_row
);
28673 defsubr (&Strace_redisplay
);
28674 defsubr (&Strace_to_stderr
);
28676 #ifdef HAVE_WINDOW_SYSTEM
28677 defsubr (&Stool_bar_lines_needed
);
28678 defsubr (&Slookup_image_map
);
28680 defsubr (&Sformat_mode_line
);
28681 defsubr (&Sinvisible_p
);
28682 defsubr (&Scurrent_bidi_paragraph_direction
);
28684 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28685 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28686 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28687 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28688 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28689 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28690 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28691 DEFSYM (Qeval
, "eval");
28692 DEFSYM (QCdata
, ":data");
28693 DEFSYM (Qdisplay
, "display");
28694 DEFSYM (Qspace_width
, "space-width");
28695 DEFSYM (Qraise
, "raise");
28696 DEFSYM (Qslice
, "slice");
28697 DEFSYM (Qspace
, "space");
28698 DEFSYM (Qmargin
, "margin");
28699 DEFSYM (Qpointer
, "pointer");
28700 DEFSYM (Qleft_margin
, "left-margin");
28701 DEFSYM (Qright_margin
, "right-margin");
28702 DEFSYM (Qcenter
, "center");
28703 DEFSYM (Qline_height
, "line-height");
28704 DEFSYM (QCalign_to
, ":align-to");
28705 DEFSYM (QCrelative_width
, ":relative-width");
28706 DEFSYM (QCrelative_height
, ":relative-height");
28707 DEFSYM (QCeval
, ":eval");
28708 DEFSYM (QCpropertize
, ":propertize");
28709 DEFSYM (QCfile
, ":file");
28710 DEFSYM (Qfontified
, "fontified");
28711 DEFSYM (Qfontification_functions
, "fontification-functions");
28712 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28713 DEFSYM (Qescape_glyph
, "escape-glyph");
28714 DEFSYM (Qnobreak_space
, "nobreak-space");
28715 DEFSYM (Qimage
, "image");
28716 DEFSYM (Qtext
, "text");
28717 DEFSYM (Qboth
, "both");
28718 DEFSYM (Qboth_horiz
, "both-horiz");
28719 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28720 DEFSYM (QCmap
, ":map");
28721 DEFSYM (QCpointer
, ":pointer");
28722 DEFSYM (Qrect
, "rect");
28723 DEFSYM (Qcircle
, "circle");
28724 DEFSYM (Qpoly
, "poly");
28725 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28726 DEFSYM (Qgrow_only
, "grow-only");
28727 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28728 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28729 DEFSYM (Qposition
, "position");
28730 DEFSYM (Qbuffer_position
, "buffer-position");
28731 DEFSYM (Qobject
, "object");
28732 DEFSYM (Qbar
, "bar");
28733 DEFSYM (Qhbar
, "hbar");
28734 DEFSYM (Qbox
, "box");
28735 DEFSYM (Qhollow
, "hollow");
28736 DEFSYM (Qhand
, "hand");
28737 DEFSYM (Qarrow
, "arrow");
28738 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28740 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28741 Fcons (intern_c_string ("void-variable"), Qnil
)),
28743 staticpro (&list_of_error
);
28745 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28746 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28747 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28748 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28750 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28751 staticpro (&echo_buffer
[0]);
28752 staticpro (&echo_buffer
[1]);
28754 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28755 staticpro (&echo_area_buffer
[0]);
28756 staticpro (&echo_area_buffer
[1]);
28758 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28759 staticpro (&Vmessages_buffer_name
);
28761 mode_line_proptrans_alist
= Qnil
;
28762 staticpro (&mode_line_proptrans_alist
);
28763 mode_line_string_list
= Qnil
;
28764 staticpro (&mode_line_string_list
);
28765 mode_line_string_face
= Qnil
;
28766 staticpro (&mode_line_string_face
);
28767 mode_line_string_face_prop
= Qnil
;
28768 staticpro (&mode_line_string_face_prop
);
28769 Vmode_line_unwind_vector
= Qnil
;
28770 staticpro (&Vmode_line_unwind_vector
);
28772 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28774 help_echo_string
= Qnil
;
28775 staticpro (&help_echo_string
);
28776 help_echo_object
= Qnil
;
28777 staticpro (&help_echo_object
);
28778 help_echo_window
= Qnil
;
28779 staticpro (&help_echo_window
);
28780 previous_help_echo_string
= Qnil
;
28781 staticpro (&previous_help_echo_string
);
28782 help_echo_pos
= -1;
28784 DEFSYM (Qright_to_left
, "right-to-left");
28785 DEFSYM (Qleft_to_right
, "left-to-right");
28787 #ifdef HAVE_WINDOW_SYSTEM
28788 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28789 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28790 For example, if a block cursor is over a tab, it will be drawn as
28791 wide as that tab on the display. */);
28792 x_stretch_cursor_p
= 0;
28795 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28796 doc
: /* Non-nil means highlight trailing whitespace.
28797 The face used for trailing whitespace is `trailing-whitespace'. */);
28798 Vshow_trailing_whitespace
= Qnil
;
28800 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28801 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28802 If the value is t, Emacs highlights non-ASCII chars which have the
28803 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28804 or `escape-glyph' face respectively.
28806 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28807 U+2011 (non-breaking hyphen) are affected.
28809 Any other non-nil value means to display these characters as a escape
28810 glyph followed by an ordinary space or hyphen.
28812 A value of nil means no special handling of these characters. */);
28813 Vnobreak_char_display
= Qt
;
28815 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28816 doc
: /* The pointer shape to show in void text areas.
28817 A value of nil means to show the text pointer. Other options are `arrow',
28818 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28819 Vvoid_text_area_pointer
= Qarrow
;
28821 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28822 doc
: /* Non-nil means don't actually do any redisplay.
28823 This is used for internal purposes. */);
28824 Vinhibit_redisplay
= Qnil
;
28826 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28827 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28828 Vglobal_mode_string
= Qnil
;
28830 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28831 doc
: /* Marker for where to display an arrow on top of the buffer text.
28832 This must be the beginning of a line in order to work.
28833 See also `overlay-arrow-string'. */);
28834 Voverlay_arrow_position
= Qnil
;
28836 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28837 doc
: /* String to display as an arrow in non-window frames.
28838 See also `overlay-arrow-position'. */);
28839 Voverlay_arrow_string
= build_pure_c_string ("=>");
28841 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28842 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28843 The symbols on this list are examined during redisplay to determine
28844 where to display overlay arrows. */);
28845 Voverlay_arrow_variable_list
28846 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28848 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28849 doc
: /* The number of lines to try scrolling a window by when point moves out.
28850 If that fails to bring point back on frame, point is centered instead.
28851 If this is zero, point is always centered after it moves off frame.
28852 If you want scrolling to always be a line at a time, you should set
28853 `scroll-conservatively' to a large value rather than set this to 1. */);
28855 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28856 doc
: /* Scroll up to this many lines, to bring point back on screen.
28857 If point moves off-screen, redisplay will scroll by up to
28858 `scroll-conservatively' lines in order to bring point just barely
28859 onto the screen again. If that cannot be done, then redisplay
28860 recenters point as usual.
28862 If the value is greater than 100, redisplay will never recenter point,
28863 but will always scroll just enough text to bring point into view, even
28864 if you move far away.
28866 A value of zero means always recenter point if it moves off screen. */);
28867 scroll_conservatively
= 0;
28869 DEFVAR_INT ("scroll-margin", scroll_margin
,
28870 doc
: /* Number of lines of margin at the top and bottom of a window.
28871 Recenter the window whenever point gets within this many lines
28872 of the top or bottom of the window. */);
28875 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28876 doc
: /* Pixels per inch value for non-window system displays.
28877 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28878 Vdisplay_pixels_per_inch
= make_float (72.0);
28881 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28884 DEFVAR_LISP ("truncate-partial-width-windows",
28885 Vtruncate_partial_width_windows
,
28886 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28887 For an integer value, truncate lines in each window narrower than the
28888 full frame width, provided the window width is less than that integer;
28889 otherwise, respect the value of `truncate-lines'.
28891 For any other non-nil value, truncate lines in all windows that do
28892 not span the full frame width.
28894 A value of nil means to respect the value of `truncate-lines'.
28896 If `word-wrap' is enabled, you might want to reduce this. */);
28897 Vtruncate_partial_width_windows
= make_number (50);
28899 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28900 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28901 Any other value means to use the appropriate face, `mode-line',
28902 `header-line', or `menu' respectively. */);
28903 mode_line_inverse_video
= 1;
28905 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28906 doc
: /* Maximum buffer size for which line number should be displayed.
28907 If the buffer is bigger than this, the line number does not appear
28908 in the mode line. A value of nil means no limit. */);
28909 Vline_number_display_limit
= Qnil
;
28911 DEFVAR_INT ("line-number-display-limit-width",
28912 line_number_display_limit_width
,
28913 doc
: /* Maximum line width (in characters) for line number display.
28914 If the average length of the lines near point is bigger than this, then the
28915 line number may be omitted from the mode line. */);
28916 line_number_display_limit_width
= 200;
28918 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28919 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28920 highlight_nonselected_windows
= 0;
28922 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28923 doc
: /* Non-nil if more than one frame is visible on this display.
28924 Minibuffer-only frames don't count, but iconified frames do.
28925 This variable is not guaranteed to be accurate except while processing
28926 `frame-title-format' and `icon-title-format'. */);
28928 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28929 doc
: /* Template for displaying the title bar of visible frames.
28930 \(Assuming the window manager supports this feature.)
28932 This variable has the same structure as `mode-line-format', except that
28933 the %c and %l constructs are ignored. It is used only on frames for
28934 which no explicit name has been set \(see `modify-frame-parameters'). */);
28936 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28937 doc
: /* Template for displaying the title bar of an iconified frame.
28938 \(Assuming the window manager supports this feature.)
28939 This variable has the same structure as `mode-line-format' (which see),
28940 and is used only on frames for which no explicit name has been set
28941 \(see `modify-frame-parameters'). */);
28943 = Vframe_title_format
28944 = listn (CONSTYPE_PURE
, 3,
28945 intern_c_string ("multiple-frames"),
28946 build_pure_c_string ("%b"),
28947 listn (CONSTYPE_PURE
, 4,
28948 empty_unibyte_string
,
28949 intern_c_string ("invocation-name"),
28950 build_pure_c_string ("@"),
28951 intern_c_string ("system-name")));
28953 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28954 doc
: /* Maximum number of lines to keep in the message log buffer.
28955 If nil, disable message logging. If t, log messages but don't truncate
28956 the buffer when it becomes large. */);
28957 Vmessage_log_max
= make_number (100);
28959 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28960 doc
: /* Functions called before redisplay, if window sizes have changed.
28961 The value should be a list of functions that take one argument.
28962 Just before redisplay, for each frame, if any of its windows have changed
28963 size since the last redisplay, or have been split or deleted,
28964 all the functions in the list are called, with the frame as argument. */);
28965 Vwindow_size_change_functions
= Qnil
;
28967 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28968 doc
: /* List of functions to call before redisplaying a window with scrolling.
28969 Each function is called with two arguments, the window and its new
28970 display-start position. Note that these functions are also called by
28971 `set-window-buffer'. Also note that the value of `window-end' is not
28972 valid when these functions are called.
28974 Warning: Do not use this feature to alter the way the window
28975 is scrolled. It is not designed for that, and such use probably won't
28977 Vwindow_scroll_functions
= Qnil
;
28979 DEFVAR_LISP ("window-text-change-functions",
28980 Vwindow_text_change_functions
,
28981 doc
: /* Functions to call in redisplay when text in the window might change. */);
28982 Vwindow_text_change_functions
= Qnil
;
28984 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28985 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28986 Each function is called with two arguments, the window and the end trigger value.
28987 See `set-window-redisplay-end-trigger'. */);
28988 Vredisplay_end_trigger_functions
= Qnil
;
28990 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28991 doc
: /* Non-nil means autoselect window with mouse pointer.
28992 If nil, do not autoselect windows.
28993 A positive number means delay autoselection by that many seconds: a
28994 window is autoselected only after the mouse has remained in that
28995 window for the duration of the delay.
28996 A negative number has a similar effect, but causes windows to be
28997 autoselected only after the mouse has stopped moving. \(Because of
28998 the way Emacs compares mouse events, you will occasionally wait twice
28999 that time before the window gets selected.\)
29000 Any other value means to autoselect window instantaneously when the
29001 mouse pointer enters it.
29003 Autoselection selects the minibuffer only if it is active, and never
29004 unselects the minibuffer if it is active.
29006 When customizing this variable make sure that the actual value of
29007 `focus-follows-mouse' matches the behavior of your window manager. */);
29008 Vmouse_autoselect_window
= Qnil
;
29010 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29011 doc
: /* Non-nil means automatically resize tool-bars.
29012 This dynamically changes the tool-bar's height to the minimum height
29013 that is needed to make all tool-bar items visible.
29014 If value is `grow-only', the tool-bar's height is only increased
29015 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29016 Vauto_resize_tool_bars
= Qt
;
29018 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29019 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29020 auto_raise_tool_bar_buttons_p
= 1;
29022 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29023 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29024 make_cursor_line_fully_visible_p
= 1;
29026 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29027 doc
: /* Border below tool-bar in pixels.
29028 If an integer, use it as the height of the border.
29029 If it is one of `internal-border-width' or `border-width', use the
29030 value of the corresponding frame parameter.
29031 Otherwise, no border is added below the tool-bar. */);
29032 Vtool_bar_border
= Qinternal_border_width
;
29034 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29035 doc
: /* Margin around tool-bar buttons in pixels.
29036 If an integer, use that for both horizontal and vertical margins.
29037 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29038 HORZ specifying the horizontal margin, and VERT specifying the
29039 vertical margin. */);
29040 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29042 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29043 doc
: /* Relief thickness of tool-bar buttons. */);
29044 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29046 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29047 doc
: /* Tool bar style to use.
29049 image - show images only
29050 text - show text only
29051 both - show both, text below image
29052 both-horiz - show text to the right of the image
29053 text-image-horiz - show text to the left of the image
29054 any other - use system default or image if no system default.
29056 This variable only affects the GTK+ toolkit version of Emacs. */);
29057 Vtool_bar_style
= Qnil
;
29059 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29060 doc
: /* Maximum number of characters a label can have to be shown.
29061 The tool bar style must also show labels for this to have any effect, see
29062 `tool-bar-style'. */);
29063 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29065 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29066 doc
: /* List of functions to call to fontify regions of text.
29067 Each function is called with one argument POS. Functions must
29068 fontify a region starting at POS in the current buffer, and give
29069 fontified regions the property `fontified'. */);
29070 Vfontification_functions
= Qnil
;
29071 Fmake_variable_buffer_local (Qfontification_functions
);
29073 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29074 unibyte_display_via_language_environment
,
29075 doc
: /* Non-nil means display unibyte text according to language environment.
29076 Specifically, this means that raw bytes in the range 160-255 decimal
29077 are displayed by converting them to the equivalent multibyte characters
29078 according to the current language environment. As a result, they are
29079 displayed according to the current fontset.
29081 Note that this variable affects only how these bytes are displayed,
29082 but does not change the fact they are interpreted as raw bytes. */);
29083 unibyte_display_via_language_environment
= 0;
29085 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29086 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29087 If a float, it specifies a fraction of the mini-window frame's height.
29088 If an integer, it specifies a number of lines. */);
29089 Vmax_mini_window_height
= make_float (0.25);
29091 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29092 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29093 A value of nil means don't automatically resize mini-windows.
29094 A value of t means resize them to fit the text displayed in them.
29095 A value of `grow-only', the default, means let mini-windows grow only;
29096 they return to their normal size when the minibuffer is closed, or the
29097 echo area becomes empty. */);
29098 Vresize_mini_windows
= Qgrow_only
;
29100 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29101 doc
: /* Alist specifying how to blink the cursor off.
29102 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29103 `cursor-type' frame-parameter or variable equals ON-STATE,
29104 comparing using `equal', Emacs uses OFF-STATE to specify
29105 how to blink it off. ON-STATE and OFF-STATE are values for
29106 the `cursor-type' frame parameter.
29108 If a frame's ON-STATE has no entry in this list,
29109 the frame's other specifications determine how to blink the cursor off. */);
29110 Vblink_cursor_alist
= Qnil
;
29112 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29113 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29114 If non-nil, windows are automatically scrolled horizontally to make
29115 point visible. */);
29116 automatic_hscrolling_p
= 1;
29117 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29119 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29120 doc
: /* How many columns away from the window edge point is allowed to get
29121 before automatic hscrolling will horizontally scroll the window. */);
29122 hscroll_margin
= 5;
29124 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29125 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29126 When point is less than `hscroll-margin' columns from the window
29127 edge, automatic hscrolling will scroll the window by the amount of columns
29128 determined by this variable. If its value is a positive integer, scroll that
29129 many columns. If it's a positive floating-point number, it specifies the
29130 fraction of the window's width to scroll. If it's nil or zero, point will be
29131 centered horizontally after the scroll. Any other value, including negative
29132 numbers, are treated as if the value were zero.
29134 Automatic hscrolling always moves point outside the scroll margin, so if
29135 point was more than scroll step columns inside the margin, the window will
29136 scroll more than the value given by the scroll step.
29138 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29139 and `scroll-right' overrides this variable's effect. */);
29140 Vhscroll_step
= make_number (0);
29142 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29143 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29144 Bind this around calls to `message' to let it take effect. */);
29145 message_truncate_lines
= 0;
29147 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29148 doc
: /* Normal hook run to update the menu bar definitions.
29149 Redisplay runs this hook before it redisplays the menu bar.
29150 This is used to update submenus such as Buffers,
29151 whose contents depend on various data. */);
29152 Vmenu_bar_update_hook
= Qnil
;
29154 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29155 doc
: /* Frame for which we are updating a menu.
29156 The enable predicate for a menu binding should check this variable. */);
29157 Vmenu_updating_frame
= Qnil
;
29159 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29160 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29161 inhibit_menubar_update
= 0;
29163 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29164 doc
: /* Prefix prepended to all continuation lines at display time.
29165 The value may be a string, an image, or a stretch-glyph; it is
29166 interpreted in the same way as the value of a `display' text property.
29168 This variable is overridden by any `wrap-prefix' text or overlay
29171 To add a prefix to non-continuation lines, use `line-prefix'. */);
29172 Vwrap_prefix
= Qnil
;
29173 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29174 Fmake_variable_buffer_local (Qwrap_prefix
);
29176 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29177 doc
: /* Prefix prepended to all non-continuation lines at display time.
29178 The value may be a string, an image, or a stretch-glyph; it is
29179 interpreted in the same way as the value of a `display' text property.
29181 This variable is overridden by any `line-prefix' text or overlay
29184 To add a prefix to continuation lines, use `wrap-prefix'. */);
29185 Vline_prefix
= Qnil
;
29186 DEFSYM (Qline_prefix
, "line-prefix");
29187 Fmake_variable_buffer_local (Qline_prefix
);
29189 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29190 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29191 inhibit_eval_during_redisplay
= 0;
29193 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29194 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29195 inhibit_free_realized_faces
= 0;
29198 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29199 doc
: /* Inhibit try_window_id display optimization. */);
29200 inhibit_try_window_id
= 0;
29202 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29203 doc
: /* Inhibit try_window_reusing display optimization. */);
29204 inhibit_try_window_reusing
= 0;
29206 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29207 doc
: /* Inhibit try_cursor_movement display optimization. */);
29208 inhibit_try_cursor_movement
= 0;
29209 #endif /* GLYPH_DEBUG */
29211 DEFVAR_INT ("overline-margin", overline_margin
,
29212 doc
: /* Space between overline and text, in pixels.
29213 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29214 margin to the character height. */);
29215 overline_margin
= 2;
29217 DEFVAR_INT ("underline-minimum-offset",
29218 underline_minimum_offset
,
29219 doc
: /* Minimum distance between baseline and underline.
29220 This can improve legibility of underlined text at small font sizes,
29221 particularly when using variable `x-use-underline-position-properties'
29222 with fonts that specify an UNDERLINE_POSITION relatively close to the
29223 baseline. The default value is 1. */);
29224 underline_minimum_offset
= 1;
29226 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29227 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29228 This feature only works when on a window system that can change
29229 cursor shapes. */);
29230 display_hourglass_p
= 1;
29232 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29233 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29234 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29236 hourglass_atimer
= NULL
;
29237 hourglass_shown_p
= 0;
29239 DEFSYM (Qglyphless_char
, "glyphless-char");
29240 DEFSYM (Qhex_code
, "hex-code");
29241 DEFSYM (Qempty_box
, "empty-box");
29242 DEFSYM (Qthin_space
, "thin-space");
29243 DEFSYM (Qzero_width
, "zero-width");
29245 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29246 /* Intern this now in case it isn't already done.
29247 Setting this variable twice is harmless.
29248 But don't staticpro it here--that is done in alloc.c. */
29249 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29250 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29252 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29253 doc
: /* Char-table defining glyphless characters.
29254 Each element, if non-nil, should be one of the following:
29255 an ASCII acronym string: display this string in a box
29256 `hex-code': display the hexadecimal code of a character in a box
29257 `empty-box': display as an empty box
29258 `thin-space': display as 1-pixel width space
29259 `zero-width': don't display
29260 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29261 display method for graphical terminals and text terminals respectively.
29262 GRAPHICAL and TEXT should each have one of the values listed above.
29264 The char-table has one extra slot to control the display of a character for
29265 which no font is found. This slot only takes effect on graphical terminals.
29266 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29267 `thin-space'. The default is `empty-box'. */);
29268 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29269 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29274 /* Initialize this module when Emacs starts. */
29279 current_header_line_height
= current_mode_line_height
= -1;
29281 CHARPOS (this_line_start_pos
) = 0;
29283 if (!noninteractive
)
29285 struct window
*m
= XWINDOW (minibuf_window
);
29286 Lisp_Object frame
= WVAR (m
, frame
);
29287 struct frame
*f
= XFRAME (frame
);
29288 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29289 struct window
*r
= XWINDOW (root
);
29292 echo_area_window
= minibuf_window
;
29294 XSETFASTINT (WVAR (r
, top_line
), FRAME_TOP_MARGIN (f
));
29295 XSETFASTINT (WVAR (r
, total_lines
), FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
29296 XSETFASTINT (WVAR (r
, total_cols
), FRAME_COLS (f
));
29297 XSETFASTINT (WVAR (m
, top_line
), FRAME_LINES (f
) - 1);
29298 XSETFASTINT (WVAR (m
, total_lines
), 1);
29299 XSETFASTINT (WVAR (m
, total_cols
), FRAME_COLS (f
));
29301 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29302 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29303 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29305 /* The default ellipsis glyphs `...'. */
29306 for (i
= 0; i
< 3; ++i
)
29307 default_invis_vector
[i
] = make_number ('.');
29311 /* Allocate the buffer for frame titles.
29312 Also used for `format-mode-line'. */
29314 mode_line_noprop_buf
= xmalloc (size
);
29315 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29316 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29317 mode_line_target
= MODE_LINE_DISPLAY
;
29320 help_echo_showing_p
= 0;
29323 /* Since w32 does not support atimers, it defines its own implementation of
29324 the following three functions in w32fns.c. */
29327 /* Platform-independent portion of hourglass implementation. */
29329 /* Cancel a currently active hourglass timer, and start a new one. */
29331 start_hourglass (void)
29333 #if defined (HAVE_WINDOW_SYSTEM)
29336 cancel_hourglass ();
29338 if (INTEGERP (Vhourglass_delay
)
29339 && XINT (Vhourglass_delay
) > 0)
29340 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29341 TYPE_MAXIMUM (time_t)),
29343 else if (FLOATP (Vhourglass_delay
)
29344 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29345 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29347 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29349 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29350 show_hourglass
, NULL
);
29355 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29358 cancel_hourglass (void)
29360 #if defined (HAVE_WINDOW_SYSTEM)
29361 if (hourglass_atimer
)
29363 cancel_atimer (hourglass_atimer
);
29364 hourglass_atimer
= NULL
;
29367 if (hourglass_shown_p
)
29371 #endif /* ! WINDOWSNT */