1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
285 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT, or the underlying buffer
387 or string character, is a space or a TAB character. This is used
388 to determine where word wrapping can occur. */
390 #define IT_DISPLAYING_WHITESPACE(it) \
391 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
392 || ((STRINGP (it->string) \
393 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
394 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
396 && (it->s[IT_BYTEPOS (*it)] == ' ' \
397 || it->s[IT_BYTEPOS (*it)] == '\t')) \
398 || (IT_BYTEPOS (*it) < ZV_BYTE \
399 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
400 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
402 /* Name of the face used to highlight trailing whitespace. */
404 static Lisp_Object Qtrailing_whitespace
;
406 /* Name and number of the face used to highlight escape glyphs. */
408 static Lisp_Object Qescape_glyph
;
410 /* Name and number of the face used to highlight non-breaking spaces. */
412 static Lisp_Object Qnobreak_space
;
414 /* The symbol `image' which is the car of the lists used to represent
415 images in Lisp. Also a tool bar style. */
419 /* The image map types. */
421 static Lisp_Object QCpointer
;
422 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
424 /* Tool bar styles */
425 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
427 /* Non-zero means print newline to stdout before next mini-buffer
430 int noninteractive_need_newline
;
432 /* Non-zero means print newline to message log before next message. */
434 static int message_log_need_newline
;
436 /* Three markers that message_dolog uses.
437 It could allocate them itself, but that causes trouble
438 in handling memory-full errors. */
439 static Lisp_Object message_dolog_marker1
;
440 static Lisp_Object message_dolog_marker2
;
441 static Lisp_Object message_dolog_marker3
;
443 /* The buffer position of the first character appearing entirely or
444 partially on the line of the selected window which contains the
445 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
446 redisplay optimization in redisplay_internal. */
448 static struct text_pos this_line_start_pos
;
450 /* Number of characters past the end of the line above, including the
451 terminating newline. */
453 static struct text_pos this_line_end_pos
;
455 /* The vertical positions and the height of this line. */
457 static int this_line_vpos
;
458 static int this_line_y
;
459 static int this_line_pixel_height
;
461 /* X position at which this display line starts. Usually zero;
462 negative if first character is partially visible. */
464 static int this_line_start_x
;
466 /* The smallest character position seen by move_it_* functions as they
467 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
468 hscrolled lines, see display_line. */
470 static struct text_pos this_line_min_pos
;
472 /* Buffer that this_line_.* variables are referring to. */
474 static struct buffer
*this_line_buffer
;
477 /* Values of those variables at last redisplay are stored as
478 properties on `overlay-arrow-position' symbol. However, if
479 Voverlay_arrow_position is a marker, last-arrow-position is its
480 numerical position. */
482 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
484 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
485 properties on a symbol in overlay-arrow-variable-list. */
487 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
489 Lisp_Object Qmenu_bar_update_hook
;
491 /* Nonzero if an overlay arrow has been displayed in this window. */
493 static int overlay_arrow_seen
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* This is the window where the echo area message was displayed. It
506 is always a mini-buffer window, but it may not be the same window
507 currently active as a mini-buffer. */
509 Lisp_Object echo_area_window
;
511 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
512 pushes the current message and the value of
513 message_enable_multibyte on the stack, the function restore_message
514 pops the stack and displays MESSAGE again. */
516 static Lisp_Object Vmessage_stack
;
518 /* Nonzero means multibyte characters were enabled when the echo area
519 message was specified. */
521 static int message_enable_multibyte
;
523 /* Nonzero if we should redraw the mode lines on the next redisplay. */
525 int update_mode_lines
;
527 /* Nonzero if window sizes or contents have changed since last
528 redisplay that finished. */
530 int windows_or_buffers_changed
;
532 /* Nonzero means a frame's cursor type has been changed. */
534 int cursor_type_changed
;
536 /* Nonzero after display_mode_line if %l was used and it displayed a
539 static int line_number_displayed
;
541 /* The name of the *Messages* buffer, a string. */
543 static Lisp_Object Vmessages_buffer_name
;
545 /* Current, index 0, and last displayed echo area message. Either
546 buffers from echo_buffers, or nil to indicate no message. */
548 Lisp_Object echo_area_buffer
[2];
550 /* The buffers referenced from echo_area_buffer. */
552 static Lisp_Object echo_buffer
[2];
554 /* A vector saved used in with_area_buffer to reduce consing. */
556 static Lisp_Object Vwith_echo_area_save_vector
;
558 /* Non-zero means display_echo_area should display the last echo area
559 message again. Set by redisplay_preserve_echo_area. */
561 static int display_last_displayed_message_p
;
563 /* Nonzero if echo area is being used by print; zero if being used by
566 static int message_buf_print
;
568 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
570 static Lisp_Object Qinhibit_menubar_update
;
571 static Lisp_Object Qmessage_truncate_lines
;
573 /* Set to 1 in clear_message to make redisplay_internal aware
574 of an emptied echo area. */
576 static int message_cleared_p
;
578 /* A scratch glyph row with contents used for generating truncation
579 glyphs. Also used in direct_output_for_insert. */
581 #define MAX_SCRATCH_GLYPHS 100
582 static struct glyph_row scratch_glyph_row
;
583 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
585 /* Ascent and height of the last line processed by move_it_to. */
587 static int last_max_ascent
, last_height
;
589 /* Non-zero if there's a help-echo in the echo area. */
591 int help_echo_showing_p
;
593 /* If >= 0, computed, exact values of mode-line and header-line height
594 to use in the macros CURRENT_MODE_LINE_HEIGHT and
595 CURRENT_HEADER_LINE_HEIGHT. */
597 int current_mode_line_height
, current_header_line_height
;
599 /* The maximum distance to look ahead for text properties. Values
600 that are too small let us call compute_char_face and similar
601 functions too often which is expensive. Values that are too large
602 let us call compute_char_face and alike too often because we
603 might not be interested in text properties that far away. */
605 #define TEXT_PROP_DISTANCE_LIMIT 100
607 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
608 iterator state and later restore it. This is needed because the
609 bidi iterator on bidi.c keeps a stacked cache of its states, which
610 is really a singleton. When we use scratch iterator objects to
611 move around the buffer, we can cause the bidi cache to be pushed or
612 popped, and therefore we need to restore the cache state when we
613 return to the original iterator. */
614 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
617 bidi_unshelve_cache (CACHE, 1); \
619 CACHE = bidi_shelve_cache (); \
622 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
624 if (pITORIG != pITCOPY) \
625 *(pITORIG) = *(pITCOPY); \
626 bidi_unshelve_cache (CACHE, 0); \
632 /* Non-zero means print traces of redisplay if compiled with
635 int trace_redisplay_p
;
637 #endif /* GLYPH_DEBUG */
639 #ifdef DEBUG_TRACE_MOVE
640 /* Non-zero means trace with TRACE_MOVE to stderr. */
643 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
645 #define TRACE_MOVE(x) (void) 0
648 static Lisp_Object Qauto_hscroll_mode
;
650 /* Buffer being redisplayed -- for redisplay_window_error. */
652 static struct buffer
*displayed_buffer
;
654 /* Value returned from text property handlers (see below). */
659 HANDLED_RECOMPUTE_PROPS
,
660 HANDLED_OVERLAY_STRING_CONSUMED
,
664 /* A description of text properties that redisplay is interested
669 /* The name of the property. */
672 /* A unique index for the property. */
675 /* A handler function called to set up iterator IT from the property
676 at IT's current position. Value is used to steer handle_stop. */
677 enum prop_handled (*handler
) (struct it
*it
);
680 static enum prop_handled
handle_face_prop (struct it
*);
681 static enum prop_handled
handle_invisible_prop (struct it
*);
682 static enum prop_handled
handle_display_prop (struct it
*);
683 static enum prop_handled
handle_composition_prop (struct it
*);
684 static enum prop_handled
handle_overlay_change (struct it
*);
685 static enum prop_handled
handle_fontified_prop (struct it
*);
687 /* Properties handled by iterators. */
689 static struct props it_props
[] =
691 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
692 /* Handle `face' before `display' because some sub-properties of
693 `display' need to know the face. */
694 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
695 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
696 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
697 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
701 /* Value is the position described by X. If X is a marker, value is
702 the marker_position of X. Otherwise, value is X. */
704 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
706 /* Enumeration returned by some move_it_.* functions internally. */
710 /* Not used. Undefined value. */
713 /* Move ended at the requested buffer position or ZV. */
714 MOVE_POS_MATCH_OR_ZV
,
716 /* Move ended at the requested X pixel position. */
719 /* Move within a line ended at the end of a line that must be
723 /* Move within a line ended at the end of a line that would
724 be displayed truncated. */
727 /* Move within a line ended at a line end. */
731 /* This counter is used to clear the face cache every once in a while
732 in redisplay_internal. It is incremented for each redisplay.
733 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
736 #define CLEAR_FACE_CACHE_COUNT 500
737 static int clear_face_cache_count
;
739 /* Similarly for the image cache. */
741 #ifdef HAVE_WINDOW_SYSTEM
742 #define CLEAR_IMAGE_CACHE_COUNT 101
743 static int clear_image_cache_count
;
745 /* Null glyph slice */
746 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
749 /* Non-zero while redisplay_internal is in progress. */
753 static Lisp_Object Qinhibit_free_realized_faces
;
755 /* If a string, XTread_socket generates an event to display that string.
756 (The display is done in read_char.) */
758 Lisp_Object help_echo_string
;
759 Lisp_Object help_echo_window
;
760 Lisp_Object help_echo_object
;
761 ptrdiff_t help_echo_pos
;
763 /* Temporary variable for XTread_socket. */
765 Lisp_Object previous_help_echo_string
;
767 /* Platform-independent portion of hourglass implementation. */
769 /* Non-zero means an hourglass cursor is currently shown. */
770 int hourglass_shown_p
;
772 /* If non-null, an asynchronous timer that, when it expires, displays
773 an hourglass cursor on all frames. */
774 struct atimer
*hourglass_atimer
;
776 /* Name of the face used to display glyphless characters. */
777 Lisp_Object Qglyphless_char
;
779 /* Symbol for the purpose of Vglyphless_char_display. */
780 static Lisp_Object Qglyphless_char_display
;
782 /* Method symbols for Vglyphless_char_display. */
783 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
785 /* Default pixel width of `thin-space' display method. */
786 #define THIN_SPACE_WIDTH 1
788 /* Default number of seconds to wait before displaying an hourglass
790 #define DEFAULT_HOURGLASS_DELAY 1
793 /* Function prototypes. */
795 static void setup_for_ellipsis (struct it
*, int);
796 static void set_iterator_to_next (struct it
*, int);
797 static void mark_window_display_accurate_1 (struct window
*, int);
798 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
799 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
800 static int cursor_row_p (struct glyph_row
*);
801 static int redisplay_mode_lines (Lisp_Object
, int);
802 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
804 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
806 static void handle_line_prefix (struct it
*);
808 static void pint2str (char *, int, ptrdiff_t);
809 static void pint2hrstr (char *, int, ptrdiff_t);
810 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
812 static void reconsider_clip_changes (struct window
*, struct buffer
*);
813 static int text_outside_line_unchanged_p (struct window
*,
814 ptrdiff_t, ptrdiff_t);
815 static void store_mode_line_noprop_char (char);
816 static int store_mode_line_noprop (const char *, int, int);
817 static void handle_stop (struct it
*);
818 static void handle_stop_backwards (struct it
*, ptrdiff_t);
819 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
820 static void ensure_echo_area_buffers (void);
821 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
822 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
823 static int with_echo_area_buffer (struct window
*, int,
824 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
825 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
826 static void clear_garbaged_frames (void);
827 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
828 static void pop_message (void);
829 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
830 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
831 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
832 static int display_echo_area (struct window
*);
833 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
834 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
835 static Lisp_Object
unwind_redisplay (Lisp_Object
);
836 static int string_char_and_length (const unsigned char *, int *);
837 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
839 static int compute_window_start_on_continuation_line (struct window
*);
840 static Lisp_Object
safe_eval_handler (Lisp_Object
);
841 static void insert_left_trunc_glyphs (struct it
*);
842 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
844 static void extend_face_to_end_of_line (struct it
*);
845 static int append_space_for_newline (struct it
*, int);
846 static int cursor_row_fully_visible_p (struct window
*, int, int);
847 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
848 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
849 static int trailing_whitespace_p (ptrdiff_t);
850 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
851 static void push_it (struct it
*, struct text_pos
*);
852 static void iterate_out_of_display_property (struct it
*);
853 static void pop_it (struct it
*);
854 static void sync_frame_with_window_matrix_rows (struct window
*);
855 static void select_frame_for_redisplay (Lisp_Object
);
856 static void redisplay_internal (void);
857 static int echo_area_display (int);
858 static void redisplay_windows (Lisp_Object
);
859 static void redisplay_window (Lisp_Object
, int);
860 static Lisp_Object
redisplay_window_error (Lisp_Object
);
861 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
862 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
863 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
864 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
866 static int update_menu_bar (struct frame
*, int, int);
867 static int try_window_reusing_current_matrix (struct window
*);
868 static int try_window_id (struct window
*);
869 static int display_line (struct it
*);
870 static int display_mode_lines (struct window
*);
871 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
872 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
873 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
874 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
875 static void display_menu_bar (struct window
*);
876 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
878 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
879 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
880 static void compute_line_metrics (struct it
*);
881 static void run_redisplay_end_trigger_hook (struct it
*);
882 static int get_overlay_strings (struct it
*, ptrdiff_t);
883 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
884 static void next_overlay_string (struct it
*);
885 static void reseat (struct it
*, struct text_pos
, int);
886 static void reseat_1 (struct it
*, struct text_pos
, int);
887 static void back_to_previous_visible_line_start (struct it
*);
888 void reseat_at_previous_visible_line_start (struct it
*);
889 static void reseat_at_next_visible_line_start (struct it
*, int);
890 static int next_element_from_ellipsis (struct it
*);
891 static int next_element_from_display_vector (struct it
*);
892 static int next_element_from_string (struct it
*);
893 static int next_element_from_c_string (struct it
*);
894 static int next_element_from_buffer (struct it
*);
895 static int next_element_from_composition (struct it
*);
896 static int next_element_from_image (struct it
*);
897 static int next_element_from_stretch (struct it
*);
898 static void load_overlay_strings (struct it
*, ptrdiff_t);
899 static int init_from_display_pos (struct it
*, struct window
*,
900 struct display_pos
*);
901 static void reseat_to_string (struct it
*, const char *,
902 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
903 static int get_next_display_element (struct it
*);
904 static enum move_it_result
905 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
906 enum move_operation_enum
);
907 void move_it_vertically_backward (struct it
*, int);
908 static void init_to_row_start (struct it
*, struct window
*,
910 static int init_to_row_end (struct it
*, struct window
*,
912 static void back_to_previous_line_start (struct it
*);
913 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
914 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
915 Lisp_Object
, ptrdiff_t);
916 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
917 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
918 static ptrdiff_t number_of_chars (const char *, int);
919 static void compute_stop_pos (struct it
*);
920 static void compute_string_pos (struct text_pos
*, struct text_pos
,
922 static int face_before_or_after_it_pos (struct it
*, int);
923 static ptrdiff_t next_overlay_change (ptrdiff_t);
924 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
925 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
926 static int handle_single_display_spec (struct it
*, Lisp_Object
,
927 Lisp_Object
, Lisp_Object
,
928 struct text_pos
*, ptrdiff_t, int, int);
929 static int underlying_face_id (struct it
*);
930 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
933 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
934 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
936 #ifdef HAVE_WINDOW_SYSTEM
938 static void x_consider_frame_title (Lisp_Object
);
939 static int tool_bar_lines_needed (struct frame
*, int *);
940 static void update_tool_bar (struct frame
*, int);
941 static void build_desired_tool_bar_string (struct frame
*f
);
942 static int redisplay_tool_bar (struct frame
*);
943 static void display_tool_bar_line (struct it
*, int);
944 static void notice_overwritten_cursor (struct window
*,
947 static void append_stretch_glyph (struct it
*, Lisp_Object
,
951 #endif /* HAVE_WINDOW_SYSTEM */
953 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
954 static int coords_in_mouse_face_p (struct window
*, int, int);
958 /***********************************************************************
959 Window display dimensions
960 ***********************************************************************/
962 /* Return the bottom boundary y-position for text lines in window W.
963 This is the first y position at which a line cannot start.
964 It is relative to the top of the window.
966 This is the height of W minus the height of a mode line, if any. */
969 window_text_bottom_y (struct window
*w
)
971 int height
= WINDOW_TOTAL_HEIGHT (w
);
973 if (WINDOW_WANTS_MODELINE_P (w
))
974 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
978 /* Return the pixel width of display area AREA of window W. AREA < 0
979 means return the total width of W, not including fringes to
980 the left and right of the window. */
983 window_box_width (struct window
*w
, int area
)
985 int cols
= XFASTINT (w
->total_cols
);
988 if (!w
->pseudo_window_p
)
990 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
992 if (area
== TEXT_AREA
)
994 if (INTEGERP (w
->left_margin_cols
))
995 cols
-= XFASTINT (w
->left_margin_cols
);
996 if (INTEGERP (w
->right_margin_cols
))
997 cols
-= XFASTINT (w
->right_margin_cols
);
998 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1000 else if (area
== LEFT_MARGIN_AREA
)
1002 cols
= (INTEGERP (w
->left_margin_cols
)
1003 ? XFASTINT (w
->left_margin_cols
) : 0);
1006 else if (area
== RIGHT_MARGIN_AREA
)
1008 cols
= (INTEGERP (w
->right_margin_cols
)
1009 ? XFASTINT (w
->right_margin_cols
) : 0);
1014 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1018 /* Return the pixel height of the display area of window W, not
1019 including mode lines of W, if any. */
1022 window_box_height (struct window
*w
)
1024 struct frame
*f
= XFRAME (w
->frame
);
1025 int height
= WINDOW_TOTAL_HEIGHT (w
);
1027 xassert (height
>= 0);
1029 /* Note: the code below that determines the mode-line/header-line
1030 height is essentially the same as that contained in the macro
1031 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1032 the appropriate glyph row has its `mode_line_p' flag set,
1033 and if it doesn't, uses estimate_mode_line_height instead. */
1035 if (WINDOW_WANTS_MODELINE_P (w
))
1037 struct glyph_row
*ml_row
1038 = (w
->current_matrix
&& w
->current_matrix
->rows
1039 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1041 if (ml_row
&& ml_row
->mode_line_p
)
1042 height
-= ml_row
->height
;
1044 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1047 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1049 struct glyph_row
*hl_row
1050 = (w
->current_matrix
&& w
->current_matrix
->rows
1051 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1053 if (hl_row
&& hl_row
->mode_line_p
)
1054 height
-= hl_row
->height
;
1056 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1059 /* With a very small font and a mode-line that's taller than
1060 default, we might end up with a negative height. */
1061 return max (0, height
);
1064 /* Return the window-relative coordinate of the left edge of display
1065 area AREA of window W. AREA < 0 means return the left edge of the
1066 whole window, to the right of the left fringe of W. */
1069 window_box_left_offset (struct window
*w
, int area
)
1073 if (w
->pseudo_window_p
)
1076 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1078 if (area
== TEXT_AREA
)
1079 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1080 + window_box_width (w
, LEFT_MARGIN_AREA
));
1081 else if (area
== RIGHT_MARGIN_AREA
)
1082 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1083 + window_box_width (w
, LEFT_MARGIN_AREA
)
1084 + window_box_width (w
, TEXT_AREA
)
1085 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1087 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1088 else if (area
== LEFT_MARGIN_AREA
1089 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1090 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1096 /* Return the window-relative coordinate of the right edge of display
1097 area AREA of window W. AREA < 0 means return the right edge of the
1098 whole window, to the left of the right fringe of W. */
1101 window_box_right_offset (struct window
*w
, int area
)
1103 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1106 /* Return the frame-relative coordinate of the left edge of display
1107 area AREA of window W. AREA < 0 means return the left edge of the
1108 whole window, to the right of the left fringe of W. */
1111 window_box_left (struct window
*w
, int area
)
1113 struct frame
*f
= XFRAME (w
->frame
);
1116 if (w
->pseudo_window_p
)
1117 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1119 x
= (WINDOW_LEFT_EDGE_X (w
)
1120 + window_box_left_offset (w
, area
));
1126 /* Return the frame-relative coordinate of the right edge of display
1127 area AREA of window W. AREA < 0 means return the right edge of the
1128 whole window, to the left of the right fringe of W. */
1131 window_box_right (struct window
*w
, int area
)
1133 return window_box_left (w
, area
) + window_box_width (w
, area
);
1136 /* Get the bounding box of the display area AREA of window W, without
1137 mode lines, in frame-relative coordinates. AREA < 0 means the
1138 whole window, not including the left and right fringes of
1139 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1140 coordinates of the upper-left corner of the box. Return in
1141 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1144 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1145 int *box_width
, int *box_height
)
1148 *box_width
= window_box_width (w
, area
);
1150 *box_height
= window_box_height (w
);
1152 *box_x
= window_box_left (w
, area
);
1155 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1156 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1157 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1162 /* Get the bounding box of the display area AREA of window W, without
1163 mode lines. AREA < 0 means the whole window, not including the
1164 left and right fringe of the window. Return in *TOP_LEFT_X
1165 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1166 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1167 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1171 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1172 int *bottom_right_x
, int *bottom_right_y
)
1174 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1176 *bottom_right_x
+= *top_left_x
;
1177 *bottom_right_y
+= *top_left_y
;
1182 /***********************************************************************
1184 ***********************************************************************/
1186 /* Return the bottom y-position of the line the iterator IT is in.
1187 This can modify IT's settings. */
1190 line_bottom_y (struct it
*it
)
1192 int line_height
= it
->max_ascent
+ it
->max_descent
;
1193 int line_top_y
= it
->current_y
;
1195 if (line_height
== 0)
1198 line_height
= last_height
;
1199 else if (IT_CHARPOS (*it
) < ZV
)
1201 move_it_by_lines (it
, 1);
1202 line_height
= (it
->max_ascent
|| it
->max_descent
1203 ? it
->max_ascent
+ it
->max_descent
1208 struct glyph_row
*row
= it
->glyph_row
;
1210 /* Use the default character height. */
1211 it
->glyph_row
= NULL
;
1212 it
->what
= IT_CHARACTER
;
1215 PRODUCE_GLYPHS (it
);
1216 line_height
= it
->ascent
+ it
->descent
;
1217 it
->glyph_row
= row
;
1221 return line_top_y
+ line_height
;
1224 /* Subroutine of pos_visible_p below. Extracts a display string, if
1225 any, from the display spec given as its argument. */
1227 string_from_display_spec (Lisp_Object spec
)
1231 while (CONSP (spec
))
1233 if (STRINGP (XCAR (spec
)))
1238 else if (VECTORP (spec
))
1242 for (i
= 0; i
< ASIZE (spec
); i
++)
1244 if (STRINGP (AREF (spec
, i
)))
1245 return AREF (spec
, i
);
1253 /* Return 1 if position CHARPOS is visible in window W.
1254 CHARPOS < 0 means return info about WINDOW_END position.
1255 If visible, set *X and *Y to pixel coordinates of top left corner.
1256 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1257 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1260 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1261 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1264 void *itdata
= bidi_shelve_cache ();
1265 struct text_pos top
;
1267 struct buffer
*old_buffer
= NULL
;
1269 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1272 if (XBUFFER (w
->buffer
) != current_buffer
)
1274 old_buffer
= current_buffer
;
1275 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1278 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1279 /* Scrolling a minibuffer window via scroll bar when the echo area
1280 shows long text sometimes resets the minibuffer contents behind
1282 if (CHARPOS (top
) > ZV
)
1283 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1285 /* Compute exact mode line heights. */
1286 if (WINDOW_WANTS_MODELINE_P (w
))
1287 current_mode_line_height
1288 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1289 BVAR (current_buffer
, mode_line_format
));
1291 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1292 current_header_line_height
1293 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1294 BVAR (current_buffer
, header_line_format
));
1296 start_display (&it
, w
, top
);
1297 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1298 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1301 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1302 && IT_CHARPOS (it
) >= charpos
)
1303 /* When scanning backwards under bidi iteration, move_it_to
1304 stops at or _before_ CHARPOS, because it stops at or to
1305 the _right_ of the character at CHARPOS. */
1306 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1307 && IT_CHARPOS (it
) <= charpos
)))
1309 /* We have reached CHARPOS, or passed it. How the call to
1310 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1311 or covered by a display property, move_it_to stops at the end
1312 of the invisible text, to the right of CHARPOS. (ii) If
1313 CHARPOS is in a display vector, move_it_to stops on its last
1315 int top_x
= it
.current_x
;
1316 int top_y
= it
.current_y
;
1317 /* Calling line_bottom_y may change it.method, it.position, etc. */
1318 enum it_method it_method
= it
.method
;
1319 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1320 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1322 if (top_y
< window_top_y
)
1323 visible_p
= bottom_y
> window_top_y
;
1324 else if (top_y
< it
.last_visible_y
)
1326 if (bottom_y
>= it
.last_visible_y
1327 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1328 && IT_CHARPOS (it
) < charpos
)
1330 /* When the last line of the window is scanned backwards
1331 under bidi iteration, we could be duped into thinking
1332 that we have passed CHARPOS, when in fact move_it_to
1333 simply stopped short of CHARPOS because it reached
1334 last_visible_y. To see if that's what happened, we call
1335 move_it_to again with a slightly larger vertical limit,
1336 and see if it actually moved vertically; if it did, we
1337 didn't really reach CHARPOS, which is beyond window end. */
1338 struct it save_it
= it
;
1339 /* Why 10? because we don't know how many canonical lines
1340 will the height of the next line(s) be. So we guess. */
1341 int ten_more_lines
=
1342 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1344 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1345 MOVE_TO_POS
| MOVE_TO_Y
);
1346 if (it
.current_y
> top_y
)
1353 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1355 /* We stopped on the last glyph of a display vector.
1356 Try and recompute. Hack alert! */
1357 if (charpos
< 2 || top
.charpos
>= charpos
)
1358 top_x
= it
.glyph_row
->x
;
1362 start_display (&it2
, w
, top
);
1363 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1364 get_next_display_element (&it2
);
1365 PRODUCE_GLYPHS (&it2
);
1366 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1367 || it2
.current_x
> it2
.last_visible_x
)
1368 top_x
= it
.glyph_row
->x
;
1371 top_x
= it2
.current_x
;
1372 top_y
= it2
.current_y
;
1376 else if (IT_CHARPOS (it
) != charpos
)
1378 Lisp_Object cpos
= make_number (charpos
);
1379 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1380 Lisp_Object string
= string_from_display_spec (spec
);
1381 int newline_in_string
= 0;
1383 if (STRINGP (string
))
1385 const char *s
= SSDATA (string
);
1386 const char *e
= s
+ SBYTES (string
);
1391 newline_in_string
= 1;
1396 /* The tricky code below is needed because there's a
1397 discrepancy between move_it_to and how we set cursor
1398 when the display line ends in a newline from a
1399 display string. move_it_to will stop _after_ such
1400 display strings, whereas set_cursor_from_row
1401 conspires with cursor_row_p to place the cursor on
1402 the first glyph produced from the display string. */
1404 /* We have overshoot PT because it is covered by a
1405 display property whose value is a string. If the
1406 string includes embedded newlines, we are also in the
1407 wrong display line. Backtrack to the correct line,
1408 where the display string begins. */
1409 if (newline_in_string
)
1411 Lisp_Object startpos
, endpos
;
1412 EMACS_INT start
, end
;
1416 /* Find the first and the last buffer positions
1417 covered by the display string. */
1419 Fnext_single_char_property_change (cpos
, Qdisplay
,
1422 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1424 start
= XFASTINT (startpos
);
1425 end
= XFASTINT (endpos
);
1426 /* Move to the last buffer position before the
1427 display property. */
1428 start_display (&it3
, w
, top
);
1429 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1430 /* Move forward one more line if the position before
1431 the display string is a newline or if it is the
1432 rightmost character on a line that is
1433 continued or word-wrapped. */
1434 if (it3
.method
== GET_FROM_BUFFER
1436 move_it_by_lines (&it3
, 1);
1437 else if (move_it_in_display_line_to (&it3
, -1,
1441 == MOVE_LINE_CONTINUED
)
1443 move_it_by_lines (&it3
, 1);
1444 /* When we are under word-wrap, the #$@%!
1445 move_it_by_lines moves 2 lines, so we need to
1447 if (it3
.line_wrap
== WORD_WRAP
)
1448 move_it_by_lines (&it3
, -1);
1451 /* Record the vertical coordinate of the display
1452 line where we wound up. */
1453 top_y
= it3
.current_y
;
1456 /* When characters are reordered for display,
1457 the character displayed to the left of the
1458 display string could be _after_ the display
1459 property in the logical order. Use the
1460 smallest vertical position of these two. */
1461 start_display (&it3
, w
, top
);
1462 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1463 if (it3
.current_y
< top_y
)
1464 top_y
= it3
.current_y
;
1466 /* Move from the top of the window to the beginning
1467 of the display line where the display string
1469 start_display (&it3
, w
, top
);
1470 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1471 /* If it3_moved stays zero after the 'while' loop
1472 below, that means we already were at a newline
1473 before the loop (e.g., the display string begins
1474 with a newline), so we don't need to (and cannot)
1475 inspect the glyphs of it3.glyph_row, because
1476 PRODUCE_GLYPHS will not produce anything for a
1477 newline, and thus it3.glyph_row stays at its
1478 stale content it got at top of the window. */
1480 /* Finally, advance the iterator until we hit the
1481 first display element whose character position is
1482 CHARPOS, or until the first newline from the
1483 display string, which signals the end of the
1485 while (get_next_display_element (&it3
))
1487 PRODUCE_GLYPHS (&it3
);
1488 if (IT_CHARPOS (it3
) == charpos
1489 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1492 set_iterator_to_next (&it3
, 0);
1494 top_x
= it3
.current_x
- it3
.pixel_width
;
1495 /* Normally, we would exit the above loop because we
1496 found the display element whose character
1497 position is CHARPOS. For the contingency that we
1498 didn't, and stopped at the first newline from the
1499 display string, move back over the glyphs
1500 produced from the string, until we find the
1501 rightmost glyph not from the string. */
1503 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1505 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1506 + it3
.glyph_row
->used
[TEXT_AREA
];
1508 while (EQ ((g
- 1)->object
, string
))
1511 top_x
-= g
->pixel_width
;
1513 xassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1514 + it3
.glyph_row
->used
[TEXT_AREA
]);
1520 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1521 *rtop
= max (0, window_top_y
- top_y
);
1522 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1523 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1524 - max (top_y
, window_top_y
)));
1530 /* We were asked to provide info about WINDOW_END. */
1532 void *it2data
= NULL
;
1534 SAVE_IT (it2
, it
, it2data
);
1535 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1536 move_it_by_lines (&it
, 1);
1537 if (charpos
< IT_CHARPOS (it
)
1538 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1541 RESTORE_IT (&it2
, &it2
, it2data
);
1542 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1544 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1545 *rtop
= max (0, -it2
.current_y
);
1546 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1547 - it
.last_visible_y
));
1548 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1550 - max (it2
.current_y
,
1551 WINDOW_HEADER_LINE_HEIGHT (w
))));
1555 bidi_unshelve_cache (it2data
, 1);
1557 bidi_unshelve_cache (itdata
, 0);
1560 set_buffer_internal_1 (old_buffer
);
1562 current_header_line_height
= current_mode_line_height
= -1;
1564 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1565 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1568 /* Debugging code. */
1570 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1571 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1573 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1580 /* Return the next character from STR. Return in *LEN the length of
1581 the character. This is like STRING_CHAR_AND_LENGTH but never
1582 returns an invalid character. If we find one, we return a `?', but
1583 with the length of the invalid character. */
1586 string_char_and_length (const unsigned char *str
, int *len
)
1590 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1591 if (!CHAR_VALID_P (c
))
1592 /* We may not change the length here because other places in Emacs
1593 don't use this function, i.e. they silently accept invalid
1602 /* Given a position POS containing a valid character and byte position
1603 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1605 static struct text_pos
1606 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1608 xassert (STRINGP (string
) && nchars
>= 0);
1610 if (STRING_MULTIBYTE (string
))
1612 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1617 string_char_and_length (p
, &len
);
1620 BYTEPOS (pos
) += len
;
1624 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1630 /* Value is the text position, i.e. character and byte position,
1631 for character position CHARPOS in STRING. */
1633 static inline struct text_pos
1634 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1636 struct text_pos pos
;
1637 xassert (STRINGP (string
));
1638 xassert (charpos
>= 0);
1639 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1644 /* Value is a text position, i.e. character and byte position, for
1645 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1646 means recognize multibyte characters. */
1648 static struct text_pos
1649 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1651 struct text_pos pos
;
1653 xassert (s
!= NULL
);
1654 xassert (charpos
>= 0);
1660 SET_TEXT_POS (pos
, 0, 0);
1663 string_char_and_length ((const unsigned char *) s
, &len
);
1666 BYTEPOS (pos
) += len
;
1670 SET_TEXT_POS (pos
, charpos
, charpos
);
1676 /* Value is the number of characters in C string S. MULTIBYTE_P
1677 non-zero means recognize multibyte characters. */
1680 number_of_chars (const char *s
, int multibyte_p
)
1686 ptrdiff_t rest
= strlen (s
);
1688 const unsigned char *p
= (const unsigned char *) s
;
1690 for (nchars
= 0; rest
> 0; ++nchars
)
1692 string_char_and_length (p
, &len
);
1693 rest
-= len
, p
+= len
;
1697 nchars
= strlen (s
);
1703 /* Compute byte position NEWPOS->bytepos corresponding to
1704 NEWPOS->charpos. POS is a known position in string STRING.
1705 NEWPOS->charpos must be >= POS.charpos. */
1708 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1710 xassert (STRINGP (string
));
1711 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1713 if (STRING_MULTIBYTE (string
))
1714 *newpos
= string_pos_nchars_ahead (pos
, string
,
1715 CHARPOS (*newpos
) - CHARPOS (pos
));
1717 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1721 Return an estimation of the pixel height of mode or header lines on
1722 frame F. FACE_ID specifies what line's height to estimate. */
1725 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1727 #ifdef HAVE_WINDOW_SYSTEM
1728 if (FRAME_WINDOW_P (f
))
1730 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1732 /* This function is called so early when Emacs starts that the face
1733 cache and mode line face are not yet initialized. */
1734 if (FRAME_FACE_CACHE (f
))
1736 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1740 height
= FONT_HEIGHT (face
->font
);
1741 if (face
->box_line_width
> 0)
1742 height
+= 2 * face
->box_line_width
;
1753 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1754 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1755 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1756 not force the value into range. */
1759 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1760 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1763 #ifdef HAVE_WINDOW_SYSTEM
1764 if (FRAME_WINDOW_P (f
))
1766 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1767 even for negative values. */
1769 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1771 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1773 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1774 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1777 STORE_NATIVE_RECT (*bounds
,
1778 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1779 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1780 FRAME_COLUMN_WIDTH (f
) - 1,
1781 FRAME_LINE_HEIGHT (f
) - 1);
1787 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1788 pix_x
= FRAME_TOTAL_COLS (f
);
1792 else if (pix_y
> FRAME_LINES (f
))
1793 pix_y
= FRAME_LINES (f
);
1803 /* Find the glyph under window-relative coordinates X/Y in window W.
1804 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1805 strings. Return in *HPOS and *VPOS the row and column number of
1806 the glyph found. Return in *AREA the glyph area containing X.
1807 Value is a pointer to the glyph found or null if X/Y is not on
1808 text, or we can't tell because W's current matrix is not up to
1813 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1814 int *dx
, int *dy
, int *area
)
1816 struct glyph
*glyph
, *end
;
1817 struct glyph_row
*row
= NULL
;
1820 /* Find row containing Y. Give up if some row is not enabled. */
1821 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1823 row
= MATRIX_ROW (w
->current_matrix
, i
);
1824 if (!row
->enabled_p
)
1826 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1833 /* Give up if Y is not in the window. */
1834 if (i
== w
->current_matrix
->nrows
)
1837 /* Get the glyph area containing X. */
1838 if (w
->pseudo_window_p
)
1845 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1847 *area
= LEFT_MARGIN_AREA
;
1848 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1850 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1853 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1857 *area
= RIGHT_MARGIN_AREA
;
1858 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1862 /* Find glyph containing X. */
1863 glyph
= row
->glyphs
[*area
];
1864 end
= glyph
+ row
->used
[*area
];
1866 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1868 x
-= glyph
->pixel_width
;
1878 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1881 *hpos
= glyph
- row
->glyphs
[*area
];
1885 /* Convert frame-relative x/y to coordinates relative to window W.
1886 Takes pseudo-windows into account. */
1889 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1891 if (w
->pseudo_window_p
)
1893 /* A pseudo-window is always full-width, and starts at the
1894 left edge of the frame, plus a frame border. */
1895 struct frame
*f
= XFRAME (w
->frame
);
1896 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1897 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1901 *x
-= WINDOW_LEFT_EDGE_X (w
);
1902 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1906 #ifdef HAVE_WINDOW_SYSTEM
1909 Return in RECTS[] at most N clipping rectangles for glyph string S.
1910 Return the number of stored rectangles. */
1913 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1920 if (s
->row
->full_width_p
)
1922 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1923 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1924 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1926 /* Unless displaying a mode or menu bar line, which are always
1927 fully visible, clip to the visible part of the row. */
1928 if (s
->w
->pseudo_window_p
)
1929 r
.height
= s
->row
->visible_height
;
1931 r
.height
= s
->height
;
1935 /* This is a text line that may be partially visible. */
1936 r
.x
= window_box_left (s
->w
, s
->area
);
1937 r
.width
= window_box_width (s
->w
, s
->area
);
1938 r
.height
= s
->row
->visible_height
;
1942 if (r
.x
< s
->clip_head
->x
)
1944 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1945 r
.width
-= s
->clip_head
->x
- r
.x
;
1948 r
.x
= s
->clip_head
->x
;
1951 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1953 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1954 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1959 /* If S draws overlapping rows, it's sufficient to use the top and
1960 bottom of the window for clipping because this glyph string
1961 intentionally draws over other lines. */
1962 if (s
->for_overlaps
)
1964 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1965 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1967 /* Alas, the above simple strategy does not work for the
1968 environments with anti-aliased text: if the same text is
1969 drawn onto the same place multiple times, it gets thicker.
1970 If the overlap we are processing is for the erased cursor, we
1971 take the intersection with the rectangle of the cursor. */
1972 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1974 XRectangle rc
, r_save
= r
;
1976 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1977 rc
.y
= s
->w
->phys_cursor
.y
;
1978 rc
.width
= s
->w
->phys_cursor_width
;
1979 rc
.height
= s
->w
->phys_cursor_height
;
1981 x_intersect_rectangles (&r_save
, &rc
, &r
);
1986 /* Don't use S->y for clipping because it doesn't take partially
1987 visible lines into account. For example, it can be negative for
1988 partially visible lines at the top of a window. */
1989 if (!s
->row
->full_width_p
1990 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1991 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1993 r
.y
= max (0, s
->row
->y
);
1996 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1998 /* If drawing the cursor, don't let glyph draw outside its
1999 advertised boundaries. Cleartype does this under some circumstances. */
2000 if (s
->hl
== DRAW_CURSOR
)
2002 struct glyph
*glyph
= s
->first_glyph
;
2007 r
.width
-= s
->x
- r
.x
;
2010 r
.width
= min (r
.width
, glyph
->pixel_width
);
2012 /* If r.y is below window bottom, ensure that we still see a cursor. */
2013 height
= min (glyph
->ascent
+ glyph
->descent
,
2014 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2015 max_y
= window_text_bottom_y (s
->w
) - height
;
2016 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2017 if (s
->ybase
- glyph
->ascent
> max_y
)
2024 /* Don't draw cursor glyph taller than our actual glyph. */
2025 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2026 if (height
< r
.height
)
2028 max_y
= r
.y
+ r
.height
;
2029 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2030 r
.height
= min (max_y
- r
.y
, height
);
2037 XRectangle r_save
= r
;
2039 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2043 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2044 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2046 #ifdef CONVERT_FROM_XRECT
2047 CONVERT_FROM_XRECT (r
, *rects
);
2055 /* If we are processing overlapping and allowed to return
2056 multiple clipping rectangles, we exclude the row of the glyph
2057 string from the clipping rectangle. This is to avoid drawing
2058 the same text on the environment with anti-aliasing. */
2059 #ifdef CONVERT_FROM_XRECT
2062 XRectangle
*rs
= rects
;
2064 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2066 if (s
->for_overlaps
& OVERLAPS_PRED
)
2069 if (r
.y
+ r
.height
> row_y
)
2072 rs
[i
].height
= row_y
- r
.y
;
2078 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2081 if (r
.y
< row_y
+ s
->row
->visible_height
)
2083 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2085 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2086 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2095 #ifdef CONVERT_FROM_XRECT
2096 for (i
= 0; i
< n
; i
++)
2097 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2104 Return in *NR the clipping rectangle for glyph string S. */
2107 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2109 get_glyph_string_clip_rects (s
, nr
, 1);
2114 Return the position and height of the phys cursor in window W.
2115 Set w->phys_cursor_width to width of phys cursor.
2119 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2120 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2122 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2123 int x
, y
, wd
, h
, h0
, y0
;
2125 /* Compute the width of the rectangle to draw. If on a stretch
2126 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2127 rectangle as wide as the glyph, but use a canonical character
2129 wd
= glyph
->pixel_width
- 1;
2130 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2134 x
= w
->phys_cursor
.x
;
2141 if (glyph
->type
== STRETCH_GLYPH
2142 && !x_stretch_cursor_p
)
2143 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2144 w
->phys_cursor_width
= wd
;
2146 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2148 /* If y is below window bottom, ensure that we still see a cursor. */
2149 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2151 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2152 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2154 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2157 h
= max (h
- (y0
- y
) + 1, h0
);
2162 y0
= window_text_bottom_y (w
) - h0
;
2170 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2171 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2176 * Remember which glyph the mouse is over.
2180 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2184 struct glyph_row
*r
, *gr
, *end_row
;
2185 enum window_part part
;
2186 enum glyph_row_area area
;
2187 int x
, y
, width
, height
;
2189 /* Try to determine frame pixel position and size of the glyph under
2190 frame pixel coordinates X/Y on frame F. */
2192 if (!f
->glyphs_initialized_p
2193 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2196 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2197 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2201 w
= XWINDOW (window
);
2202 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2203 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2205 x
= window_relative_x_coord (w
, part
, gx
);
2206 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2208 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2209 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2211 if (w
->pseudo_window_p
)
2214 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2220 case ON_LEFT_MARGIN
:
2221 area
= LEFT_MARGIN_AREA
;
2224 case ON_RIGHT_MARGIN
:
2225 area
= RIGHT_MARGIN_AREA
;
2228 case ON_HEADER_LINE
:
2230 gr
= (part
== ON_HEADER_LINE
2231 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2232 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2235 goto text_glyph_row_found
;
2242 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2243 if (r
->y
+ r
->height
> y
)
2249 text_glyph_row_found
:
2252 struct glyph
*g
= gr
->glyphs
[area
];
2253 struct glyph
*end
= g
+ gr
->used
[area
];
2255 height
= gr
->height
;
2256 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2257 if (gx
+ g
->pixel_width
> x
)
2262 if (g
->type
== IMAGE_GLYPH
)
2264 /* Don't remember when mouse is over image, as
2265 image may have hot-spots. */
2266 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2269 width
= g
->pixel_width
;
2273 /* Use nominal char spacing at end of line. */
2275 gx
+= (x
/ width
) * width
;
2278 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2279 gx
+= window_box_left_offset (w
, area
);
2283 /* Use nominal line height at end of window. */
2284 gx
= (x
/ width
) * width
;
2286 gy
+= (y
/ height
) * height
;
2290 case ON_LEFT_FRINGE
:
2291 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2292 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2293 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2294 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2297 case ON_RIGHT_FRINGE
:
2298 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2299 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2300 : window_box_right_offset (w
, TEXT_AREA
));
2301 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2305 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2307 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2308 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2309 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2311 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2315 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2316 if (r
->y
+ r
->height
> y
)
2323 height
= gr
->height
;
2326 /* Use nominal line height at end of window. */
2328 gy
+= (y
/ height
) * height
;
2335 /* If there is no glyph under the mouse, then we divide the screen
2336 into a grid of the smallest glyph in the frame, and use that
2339 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2340 round down even for negative values. */
2346 gx
= (gx
/ width
) * width
;
2347 gy
= (gy
/ height
) * height
;
2352 gx
+= WINDOW_LEFT_EDGE_X (w
);
2353 gy
+= WINDOW_TOP_EDGE_Y (w
);
2356 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2358 /* Visible feedback for debugging. */
2361 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2362 f
->output_data
.x
->normal_gc
,
2363 gx
, gy
, width
, height
);
2369 #endif /* HAVE_WINDOW_SYSTEM */
2372 /***********************************************************************
2373 Lisp form evaluation
2374 ***********************************************************************/
2376 /* Error handler for safe_eval and safe_call. */
2379 safe_eval_handler (Lisp_Object arg
)
2381 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2386 /* Evaluate SEXPR and return the result, or nil if something went
2387 wrong. Prevent redisplay during the evaluation. */
2389 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2390 Return the result, or nil if something went wrong. Prevent
2391 redisplay during the evaluation. */
2394 safe_call (ptrdiff_t nargs
, Lisp_Object
*args
)
2398 if (inhibit_eval_during_redisplay
)
2402 ptrdiff_t count
= SPECPDL_INDEX ();
2403 struct gcpro gcpro1
;
2406 gcpro1
.nvars
= nargs
;
2407 specbind (Qinhibit_redisplay
, Qt
);
2408 /* Use Qt to ensure debugger does not run,
2409 so there is no possibility of wanting to redisplay. */
2410 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2413 val
= unbind_to (count
, val
);
2420 /* Call function FN with one argument ARG.
2421 Return the result, or nil if something went wrong. */
2424 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2426 Lisp_Object args
[2];
2429 return safe_call (2, args
);
2432 static Lisp_Object Qeval
;
2435 safe_eval (Lisp_Object sexpr
)
2437 return safe_call1 (Qeval
, sexpr
);
2440 /* Call function FN with one argument ARG.
2441 Return the result, or nil if something went wrong. */
2444 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2446 Lisp_Object args
[3];
2450 return safe_call (3, args
);
2455 /***********************************************************************
2457 ***********************************************************************/
2461 /* Define CHECK_IT to perform sanity checks on iterators.
2462 This is for debugging. It is too slow to do unconditionally. */
2465 check_it (struct it
*it
)
2467 if (it
->method
== GET_FROM_STRING
)
2469 xassert (STRINGP (it
->string
));
2470 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2474 xassert (IT_STRING_CHARPOS (*it
) < 0);
2475 if (it
->method
== GET_FROM_BUFFER
)
2477 /* Check that character and byte positions agree. */
2478 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2483 xassert (it
->current
.dpvec_index
>= 0);
2485 xassert (it
->current
.dpvec_index
< 0);
2488 #define CHECK_IT(IT) check_it ((IT))
2492 #define CHECK_IT(IT) (void) 0
2497 #if GLYPH_DEBUG && XASSERTS
2499 /* Check that the window end of window W is what we expect it
2500 to be---the last row in the current matrix displaying text. */
2503 check_window_end (struct window
*w
)
2505 if (!MINI_WINDOW_P (w
)
2506 && !NILP (w
->window_end_valid
))
2508 struct glyph_row
*row
;
2509 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2510 XFASTINT (w
->window_end_vpos
)),
2512 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2513 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2517 #define CHECK_WINDOW_END(W) check_window_end ((W))
2521 #define CHECK_WINDOW_END(W) (void) 0
2527 /***********************************************************************
2528 Iterator initialization
2529 ***********************************************************************/
2531 /* Initialize IT for displaying current_buffer in window W, starting
2532 at character position CHARPOS. CHARPOS < 0 means that no buffer
2533 position is specified which is useful when the iterator is assigned
2534 a position later. BYTEPOS is the byte position corresponding to
2535 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2537 If ROW is not null, calls to produce_glyphs with IT as parameter
2538 will produce glyphs in that row.
2540 BASE_FACE_ID is the id of a base face to use. It must be one of
2541 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2542 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2543 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2545 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2546 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2547 will be initialized to use the corresponding mode line glyph row of
2548 the desired matrix of W. */
2551 init_iterator (struct it
*it
, struct window
*w
,
2552 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2553 struct glyph_row
*row
, enum face_id base_face_id
)
2555 int highlight_region_p
;
2556 enum face_id remapped_base_face_id
= base_face_id
;
2558 /* Some precondition checks. */
2559 xassert (w
!= NULL
&& it
!= NULL
);
2560 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2563 /* If face attributes have been changed since the last redisplay,
2564 free realized faces now because they depend on face definitions
2565 that might have changed. Don't free faces while there might be
2566 desired matrices pending which reference these faces. */
2567 if (face_change_count
&& !inhibit_free_realized_faces
)
2569 face_change_count
= 0;
2570 free_all_realized_faces (Qnil
);
2573 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2574 if (! NILP (Vface_remapping_alist
))
2575 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2577 /* Use one of the mode line rows of W's desired matrix if
2581 if (base_face_id
== MODE_LINE_FACE_ID
2582 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2583 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2584 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2585 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2589 memset (it
, 0, sizeof *it
);
2590 it
->current
.overlay_string_index
= -1;
2591 it
->current
.dpvec_index
= -1;
2592 it
->base_face_id
= remapped_base_face_id
;
2594 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2595 it
->paragraph_embedding
= L2R
;
2596 it
->bidi_it
.string
.lstring
= Qnil
;
2597 it
->bidi_it
.string
.s
= NULL
;
2598 it
->bidi_it
.string
.bufpos
= 0;
2600 /* The window in which we iterate over current_buffer: */
2601 XSETWINDOW (it
->window
, w
);
2603 it
->f
= XFRAME (w
->frame
);
2607 /* Extra space between lines (on window systems only). */
2608 if (base_face_id
== DEFAULT_FACE_ID
2609 && FRAME_WINDOW_P (it
->f
))
2611 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2612 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2613 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2614 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2615 * FRAME_LINE_HEIGHT (it
->f
));
2616 else if (it
->f
->extra_line_spacing
> 0)
2617 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2618 it
->max_extra_line_spacing
= 0;
2621 /* If realized faces have been removed, e.g. because of face
2622 attribute changes of named faces, recompute them. When running
2623 in batch mode, the face cache of the initial frame is null. If
2624 we happen to get called, make a dummy face cache. */
2625 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2626 init_frame_faces (it
->f
);
2627 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2628 recompute_basic_faces (it
->f
);
2630 /* Current value of the `slice', `space-width', and 'height' properties. */
2631 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2632 it
->space_width
= Qnil
;
2633 it
->font_height
= Qnil
;
2634 it
->override_ascent
= -1;
2636 /* Are control characters displayed as `^C'? */
2637 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2639 /* -1 means everything between a CR and the following line end
2640 is invisible. >0 means lines indented more than this value are
2642 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2643 ? clip_to_bounds (-1, XINT (BVAR (current_buffer
,
2644 selective_display
)),
2646 : (!NILP (BVAR (current_buffer
, selective_display
))
2648 it
->selective_display_ellipsis_p
2649 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2651 /* Display table to use. */
2652 it
->dp
= window_display_table (w
);
2654 /* Are multibyte characters enabled in current_buffer? */
2655 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2657 /* Non-zero if we should highlight the region. */
2659 = (!NILP (Vtransient_mark_mode
)
2660 && !NILP (BVAR (current_buffer
, mark_active
))
2661 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2663 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2664 start and end of a visible region in window IT->w. Set both to
2665 -1 to indicate no region. */
2666 if (highlight_region_p
2667 /* Maybe highlight only in selected window. */
2668 && (/* Either show region everywhere. */
2669 highlight_nonselected_windows
2670 /* Or show region in the selected window. */
2671 || w
== XWINDOW (selected_window
)
2672 /* Or show the region if we are in the mini-buffer and W is
2673 the window the mini-buffer refers to. */
2674 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2675 && WINDOWP (minibuf_selected_window
)
2676 && w
== XWINDOW (minibuf_selected_window
))))
2678 ptrdiff_t markpos
= marker_position (BVAR (current_buffer
, mark
));
2679 it
->region_beg_charpos
= min (PT
, markpos
);
2680 it
->region_end_charpos
= max (PT
, markpos
);
2683 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2685 /* Get the position at which the redisplay_end_trigger hook should
2686 be run, if it is to be run at all. */
2687 if (MARKERP (w
->redisplay_end_trigger
)
2688 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2689 it
->redisplay_end_trigger_charpos
2690 = marker_position (w
->redisplay_end_trigger
);
2691 else if (INTEGERP (w
->redisplay_end_trigger
))
2692 it
->redisplay_end_trigger_charpos
=
2693 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2695 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2697 /* Are lines in the display truncated? */
2698 if (base_face_id
!= DEFAULT_FACE_ID
2699 || XINT (it
->w
->hscroll
)
2700 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2701 && ((!NILP (Vtruncate_partial_width_windows
)
2702 && !INTEGERP (Vtruncate_partial_width_windows
))
2703 || (INTEGERP (Vtruncate_partial_width_windows
)
2704 && (WINDOW_TOTAL_COLS (it
->w
)
2705 < XINT (Vtruncate_partial_width_windows
))))))
2706 it
->line_wrap
= TRUNCATE
;
2707 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2708 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2709 ? WINDOW_WRAP
: WORD_WRAP
;
2711 it
->line_wrap
= TRUNCATE
;
2713 /* Get dimensions of truncation and continuation glyphs. These are
2714 displayed as fringe bitmaps under X, so we don't need them for such
2716 if (!FRAME_WINDOW_P (it
->f
))
2718 if (it
->line_wrap
== TRUNCATE
)
2720 /* We will need the truncation glyph. */
2721 xassert (it
->glyph_row
== NULL
);
2722 produce_special_glyphs (it
, IT_TRUNCATION
);
2723 it
->truncation_pixel_width
= it
->pixel_width
;
2727 /* We will need the continuation glyph. */
2728 xassert (it
->glyph_row
== NULL
);
2729 produce_special_glyphs (it
, IT_CONTINUATION
);
2730 it
->continuation_pixel_width
= it
->pixel_width
;
2733 /* Reset these values to zero because the produce_special_glyphs
2734 above has changed them. */
2735 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2736 it
->phys_ascent
= it
->phys_descent
= 0;
2739 /* Set this after getting the dimensions of truncation and
2740 continuation glyphs, so that we don't produce glyphs when calling
2741 produce_special_glyphs, above. */
2742 it
->glyph_row
= row
;
2743 it
->area
= TEXT_AREA
;
2745 /* Forget any previous info about this row being reversed. */
2747 it
->glyph_row
->reversed_p
= 0;
2749 /* Get the dimensions of the display area. The display area
2750 consists of the visible window area plus a horizontally scrolled
2751 part to the left of the window. All x-values are relative to the
2752 start of this total display area. */
2753 if (base_face_id
!= DEFAULT_FACE_ID
)
2755 /* Mode lines, menu bar in terminal frames. */
2756 it
->first_visible_x
= 0;
2757 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2762 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2763 it
->last_visible_x
= (it
->first_visible_x
2764 + window_box_width (w
, TEXT_AREA
));
2766 /* If we truncate lines, leave room for the truncator glyph(s) at
2767 the right margin. Otherwise, leave room for the continuation
2768 glyph(s). Truncation and continuation glyphs are not inserted
2769 for window-based redisplay. */
2770 if (!FRAME_WINDOW_P (it
->f
))
2772 if (it
->line_wrap
== TRUNCATE
)
2773 it
->last_visible_x
-= it
->truncation_pixel_width
;
2775 it
->last_visible_x
-= it
->continuation_pixel_width
;
2778 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2779 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2782 /* Leave room for a border glyph. */
2783 if (!FRAME_WINDOW_P (it
->f
)
2784 && !WINDOW_RIGHTMOST_P (it
->w
))
2785 it
->last_visible_x
-= 1;
2787 it
->last_visible_y
= window_text_bottom_y (w
);
2789 /* For mode lines and alike, arrange for the first glyph having a
2790 left box line if the face specifies a box. */
2791 if (base_face_id
!= DEFAULT_FACE_ID
)
2795 it
->face_id
= remapped_base_face_id
;
2797 /* If we have a boxed mode line, make the first character appear
2798 with a left box line. */
2799 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2800 if (face
->box
!= FACE_NO_BOX
)
2801 it
->start_of_box_run_p
= 1;
2804 /* If a buffer position was specified, set the iterator there,
2805 getting overlays and face properties from that position. */
2806 if (charpos
>= BUF_BEG (current_buffer
))
2808 it
->end_charpos
= ZV
;
2809 IT_CHARPOS (*it
) = charpos
;
2811 /* We will rely on `reseat' to set this up properly, via
2812 handle_face_prop. */
2813 it
->face_id
= it
->base_face_id
;
2815 /* Compute byte position if not specified. */
2816 if (bytepos
< charpos
)
2817 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2819 IT_BYTEPOS (*it
) = bytepos
;
2821 it
->start
= it
->current
;
2822 /* Do we need to reorder bidirectional text? Not if this is a
2823 unibyte buffer: by definition, none of the single-byte
2824 characters are strong R2L, so no reordering is needed. And
2825 bidi.c doesn't support unibyte buffers anyway. Also, don't
2826 reorder while we are loading loadup.el, since the tables of
2827 character properties needed for reordering are not yet
2831 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2834 /* If we are to reorder bidirectional text, init the bidi
2838 /* Note the paragraph direction that this buffer wants to
2840 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2842 it
->paragraph_embedding
= L2R
;
2843 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2845 it
->paragraph_embedding
= R2L
;
2847 it
->paragraph_embedding
= NEUTRAL_DIR
;
2848 bidi_unshelve_cache (NULL
, 0);
2849 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2853 /* Compute faces etc. */
2854 reseat (it
, it
->current
.pos
, 1);
2861 /* Initialize IT for the display of window W with window start POS. */
2864 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2866 struct glyph_row
*row
;
2867 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2869 row
= w
->desired_matrix
->rows
+ first_vpos
;
2870 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2871 it
->first_vpos
= first_vpos
;
2873 /* Don't reseat to previous visible line start if current start
2874 position is in a string or image. */
2875 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2877 int start_at_line_beg_p
;
2878 int first_y
= it
->current_y
;
2880 /* If window start is not at a line start, skip forward to POS to
2881 get the correct continuation lines width. */
2882 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2883 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2884 if (!start_at_line_beg_p
)
2888 reseat_at_previous_visible_line_start (it
);
2889 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2891 new_x
= it
->current_x
+ it
->pixel_width
;
2893 /* If lines are continued, this line may end in the middle
2894 of a multi-glyph character (e.g. a control character
2895 displayed as \003, or in the middle of an overlay
2896 string). In this case move_it_to above will not have
2897 taken us to the start of the continuation line but to the
2898 end of the continued line. */
2899 if (it
->current_x
> 0
2900 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2901 && (/* And glyph doesn't fit on the line. */
2902 new_x
> it
->last_visible_x
2903 /* Or it fits exactly and we're on a window
2905 || (new_x
== it
->last_visible_x
2906 && FRAME_WINDOW_P (it
->f
))))
2908 if ((it
->current
.dpvec_index
>= 0
2909 || it
->current
.overlay_string_index
>= 0)
2910 /* If we are on a newline from a display vector or
2911 overlay string, then we are already at the end of
2912 a screen line; no need to go to the next line in
2913 that case, as this line is not really continued.
2914 (If we do go to the next line, C-e will not DTRT.) */
2917 set_iterator_to_next (it
, 1);
2918 move_it_in_display_line_to (it
, -1, -1, 0);
2921 it
->continuation_lines_width
+= it
->current_x
;
2923 /* If the character at POS is displayed via a display
2924 vector, move_it_to above stops at the final glyph of
2925 IT->dpvec. To make the caller redisplay that character
2926 again (a.k.a. start at POS), we need to reset the
2927 dpvec_index to the beginning of IT->dpvec. */
2928 else if (it
->current
.dpvec_index
>= 0)
2929 it
->current
.dpvec_index
= 0;
2931 /* We're starting a new display line, not affected by the
2932 height of the continued line, so clear the appropriate
2933 fields in the iterator structure. */
2934 it
->max_ascent
= it
->max_descent
= 0;
2935 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2937 it
->current_y
= first_y
;
2939 it
->current_x
= it
->hpos
= 0;
2945 /* Return 1 if POS is a position in ellipses displayed for invisible
2946 text. W is the window we display, for text property lookup. */
2949 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2951 Lisp_Object prop
, window
;
2953 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2955 /* If POS specifies a position in a display vector, this might
2956 be for an ellipsis displayed for invisible text. We won't
2957 get the iterator set up for delivering that ellipsis unless
2958 we make sure that it gets aware of the invisible text. */
2959 if (pos
->dpvec_index
>= 0
2960 && pos
->overlay_string_index
< 0
2961 && CHARPOS (pos
->string_pos
) < 0
2963 && (XSETWINDOW (window
, w
),
2964 prop
= Fget_char_property (make_number (charpos
),
2965 Qinvisible
, window
),
2966 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2968 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2970 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2977 /* Initialize IT for stepping through current_buffer in window W,
2978 starting at position POS that includes overlay string and display
2979 vector/ control character translation position information. Value
2980 is zero if there are overlay strings with newlines at POS. */
2983 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2985 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2986 int i
, overlay_strings_with_newlines
= 0;
2988 /* If POS specifies a position in a display vector, this might
2989 be for an ellipsis displayed for invisible text. We won't
2990 get the iterator set up for delivering that ellipsis unless
2991 we make sure that it gets aware of the invisible text. */
2992 if (in_ellipses_for_invisible_text_p (pos
, w
))
2998 /* Keep in mind: the call to reseat in init_iterator skips invisible
2999 text, so we might end up at a position different from POS. This
3000 is only a problem when POS is a row start after a newline and an
3001 overlay starts there with an after-string, and the overlay has an
3002 invisible property. Since we don't skip invisible text in
3003 display_line and elsewhere immediately after consuming the
3004 newline before the row start, such a POS will not be in a string,
3005 but the call to init_iterator below will move us to the
3007 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3009 /* This only scans the current chunk -- it should scan all chunks.
3010 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3011 to 16 in 22.1 to make this a lesser problem. */
3012 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3014 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3015 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3017 while (s
< e
&& *s
!= '\n')
3022 overlay_strings_with_newlines
= 1;
3027 /* If position is within an overlay string, set up IT to the right
3029 if (pos
->overlay_string_index
>= 0)
3033 /* If the first overlay string happens to have a `display'
3034 property for an image, the iterator will be set up for that
3035 image, and we have to undo that setup first before we can
3036 correct the overlay string index. */
3037 if (it
->method
== GET_FROM_IMAGE
)
3040 /* We already have the first chunk of overlay strings in
3041 IT->overlay_strings. Load more until the one for
3042 pos->overlay_string_index is in IT->overlay_strings. */
3043 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3045 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3046 it
->current
.overlay_string_index
= 0;
3049 load_overlay_strings (it
, 0);
3050 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3054 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3055 relative_index
= (it
->current
.overlay_string_index
3056 % OVERLAY_STRING_CHUNK_SIZE
);
3057 it
->string
= it
->overlay_strings
[relative_index
];
3058 xassert (STRINGP (it
->string
));
3059 it
->current
.string_pos
= pos
->string_pos
;
3060 it
->method
= GET_FROM_STRING
;
3063 if (CHARPOS (pos
->string_pos
) >= 0)
3065 /* Recorded position is not in an overlay string, but in another
3066 string. This can only be a string from a `display' property.
3067 IT should already be filled with that string. */
3068 it
->current
.string_pos
= pos
->string_pos
;
3069 xassert (STRINGP (it
->string
));
3072 /* Restore position in display vector translations, control
3073 character translations or ellipses. */
3074 if (pos
->dpvec_index
>= 0)
3076 if (it
->dpvec
== NULL
)
3077 get_next_display_element (it
);
3078 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3079 it
->current
.dpvec_index
= pos
->dpvec_index
;
3083 return !overlay_strings_with_newlines
;
3087 /* Initialize IT for stepping through current_buffer in window W
3088 starting at ROW->start. */
3091 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3093 init_from_display_pos (it
, w
, &row
->start
);
3094 it
->start
= row
->start
;
3095 it
->continuation_lines_width
= row
->continuation_lines_width
;
3100 /* Initialize IT for stepping through current_buffer in window W
3101 starting in the line following ROW, i.e. starting at ROW->end.
3102 Value is zero if there are overlay strings with newlines at ROW's
3106 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3110 if (init_from_display_pos (it
, w
, &row
->end
))
3112 if (row
->continued_p
)
3113 it
->continuation_lines_width
3114 = row
->continuation_lines_width
+ row
->pixel_width
;
3125 /***********************************************************************
3127 ***********************************************************************/
3129 /* Called when IT reaches IT->stop_charpos. Handle text property and
3130 overlay changes. Set IT->stop_charpos to the next position where
3134 handle_stop (struct it
*it
)
3136 enum prop_handled handled
;
3137 int handle_overlay_change_p
;
3141 it
->current
.dpvec_index
= -1;
3142 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3143 it
->ignore_overlay_strings_at_pos_p
= 0;
3146 /* Use face of preceding text for ellipsis (if invisible) */
3147 if (it
->selective_display_ellipsis_p
)
3148 it
->saved_face_id
= it
->face_id
;
3152 handled
= HANDLED_NORMALLY
;
3154 /* Call text property handlers. */
3155 for (p
= it_props
; p
->handler
; ++p
)
3157 handled
= p
->handler (it
);
3159 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3161 else if (handled
== HANDLED_RETURN
)
3163 /* We still want to show before and after strings from
3164 overlays even if the actual buffer text is replaced. */
3165 if (!handle_overlay_change_p
3167 /* Don't call get_overlay_strings_1 if we already
3168 have overlay strings loaded, because doing so
3169 will load them again and push the iterator state
3170 onto the stack one more time, which is not
3171 expected by the rest of the code that processes
3173 || (it
->current
.overlay_string_index
< 0
3174 ? !get_overlay_strings_1 (it
, 0, 0)
3178 setup_for_ellipsis (it
, 0);
3179 /* When handling a display spec, we might load an
3180 empty string. In that case, discard it here. We
3181 used to discard it in handle_single_display_spec,
3182 but that causes get_overlay_strings_1, above, to
3183 ignore overlay strings that we must check. */
3184 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3188 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3192 it
->ignore_overlay_strings_at_pos_p
= 1;
3193 it
->string_from_display_prop_p
= 0;
3194 it
->from_disp_prop_p
= 0;
3195 handle_overlay_change_p
= 0;
3197 handled
= HANDLED_RECOMPUTE_PROPS
;
3200 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3201 handle_overlay_change_p
= 0;
3204 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3206 /* Don't check for overlay strings below when set to deliver
3207 characters from a display vector. */
3208 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3209 handle_overlay_change_p
= 0;
3211 /* Handle overlay changes.
3212 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3213 if it finds overlays. */
3214 if (handle_overlay_change_p
)
3215 handled
= handle_overlay_change (it
);
3220 setup_for_ellipsis (it
, 0);
3224 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3226 /* Determine where to stop next. */
3227 if (handled
== HANDLED_NORMALLY
)
3228 compute_stop_pos (it
);
3232 /* Compute IT->stop_charpos from text property and overlay change
3233 information for IT's current position. */
3236 compute_stop_pos (struct it
*it
)
3238 register INTERVAL iv
, next_iv
;
3239 Lisp_Object object
, limit
, position
;
3240 ptrdiff_t charpos
, bytepos
;
3242 if (STRINGP (it
->string
))
3244 /* Strings are usually short, so don't limit the search for
3246 it
->stop_charpos
= it
->end_charpos
;
3247 object
= it
->string
;
3249 charpos
= IT_STRING_CHARPOS (*it
);
3250 bytepos
= IT_STRING_BYTEPOS (*it
);
3256 /* If end_charpos is out of range for some reason, such as a
3257 misbehaving display function, rationalize it (Bug#5984). */
3258 if (it
->end_charpos
> ZV
)
3259 it
->end_charpos
= ZV
;
3260 it
->stop_charpos
= it
->end_charpos
;
3262 /* If next overlay change is in front of the current stop pos
3263 (which is IT->end_charpos), stop there. Note: value of
3264 next_overlay_change is point-max if no overlay change
3266 charpos
= IT_CHARPOS (*it
);
3267 bytepos
= IT_BYTEPOS (*it
);
3268 pos
= next_overlay_change (charpos
);
3269 if (pos
< it
->stop_charpos
)
3270 it
->stop_charpos
= pos
;
3272 /* If showing the region, we have to stop at the region
3273 start or end because the face might change there. */
3274 if (it
->region_beg_charpos
> 0)
3276 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3277 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3278 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3279 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3282 /* Set up variables for computing the stop position from text
3283 property changes. */
3284 XSETBUFFER (object
, current_buffer
);
3285 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3288 /* Get the interval containing IT's position. Value is a null
3289 interval if there isn't such an interval. */
3290 position
= make_number (charpos
);
3291 iv
= validate_interval_range (object
, &position
, &position
, 0);
3292 if (!NULL_INTERVAL_P (iv
))
3294 Lisp_Object values_here
[LAST_PROP_IDX
];
3297 /* Get properties here. */
3298 for (p
= it_props
; p
->handler
; ++p
)
3299 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3301 /* Look for an interval following iv that has different
3303 for (next_iv
= next_interval (iv
);
3304 (!NULL_INTERVAL_P (next_iv
)
3306 || XFASTINT (limit
) > next_iv
->position
));
3307 next_iv
= next_interval (next_iv
))
3309 for (p
= it_props
; p
->handler
; ++p
)
3311 Lisp_Object new_value
;
3313 new_value
= textget (next_iv
->plist
, *p
->name
);
3314 if (!EQ (values_here
[p
->idx
], new_value
))
3322 if (!NULL_INTERVAL_P (next_iv
))
3324 if (INTEGERP (limit
)
3325 && next_iv
->position
>= XFASTINT (limit
))
3326 /* No text property change up to limit. */
3327 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3329 /* Text properties change in next_iv. */
3330 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3334 if (it
->cmp_it
.id
< 0)
3336 ptrdiff_t stoppos
= it
->end_charpos
;
3338 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3340 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3341 stoppos
, it
->string
);
3344 xassert (STRINGP (it
->string
)
3345 || (it
->stop_charpos
>= BEGV
3346 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3350 /* Return the position of the next overlay change after POS in
3351 current_buffer. Value is point-max if no overlay change
3352 follows. This is like `next-overlay-change' but doesn't use
3356 next_overlay_change (ptrdiff_t pos
)
3358 ptrdiff_t i
, noverlays
;
3360 Lisp_Object
*overlays
;
3362 /* Get all overlays at the given position. */
3363 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3365 /* If any of these overlays ends before endpos,
3366 use its ending point instead. */
3367 for (i
= 0; i
< noverlays
; ++i
)
3372 oend
= OVERLAY_END (overlays
[i
]);
3373 oendpos
= OVERLAY_POSITION (oend
);
3374 endpos
= min (endpos
, oendpos
);
3380 /* How many characters forward to search for a display property or
3381 display string. Searching too far forward makes the bidi display
3382 sluggish, especially in small windows. */
3383 #define MAX_DISP_SCAN 250
3385 /* Return the character position of a display string at or after
3386 position specified by POSITION. If no display string exists at or
3387 after POSITION, return ZV. A display string is either an overlay
3388 with `display' property whose value is a string, or a `display'
3389 text property whose value is a string. STRING is data about the
3390 string to iterate; if STRING->lstring is nil, we are iterating a
3391 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3392 on a GUI frame. DISP_PROP is set to zero if we searched
3393 MAX_DISP_SCAN characters forward without finding any display
3394 strings, non-zero otherwise. It is set to 2 if the display string
3395 uses any kind of `(space ...)' spec that will produce a stretch of
3396 white space in the text area. */
3398 compute_display_string_pos (struct text_pos
*position
,
3399 struct bidi_string_data
*string
,
3400 int frame_window_p
, int *disp_prop
)
3402 /* OBJECT = nil means current buffer. */
3403 Lisp_Object object
=
3404 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3405 Lisp_Object pos
, spec
, limpos
;
3406 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3407 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3408 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3409 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3411 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3412 struct text_pos tpos
;
3418 /* We don't support display properties whose values are strings
3419 that have display string properties. */
3420 || string
->from_disp_str
3421 /* C strings cannot have display properties. */
3422 || (string
->s
&& !STRINGP (object
)))
3428 /* If the character at CHARPOS is where the display string begins,
3430 pos
= make_number (charpos
);
3431 if (STRINGP (object
))
3432 bufpos
= string
->bufpos
;
3436 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3438 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3441 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3449 /* Look forward for the first character with a `display' property
3450 that will replace the underlying text when displayed. */
3451 limpos
= make_number (lim
);
3453 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3454 CHARPOS (tpos
) = XFASTINT (pos
);
3455 if (CHARPOS (tpos
) >= lim
)
3460 if (STRINGP (object
))
3461 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3463 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3464 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3465 if (!STRINGP (object
))
3466 bufpos
= CHARPOS (tpos
);
3467 } while (NILP (spec
)
3468 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3469 bufpos
, frame_window_p
)));
3473 return CHARPOS (tpos
);
3476 /* Return the character position of the end of the display string that
3477 started at CHARPOS. If there's no display string at CHARPOS,
3478 return -1. A display string is either an overlay with `display'
3479 property whose value is a string or a `display' text property whose
3480 value is a string. */
3482 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3484 /* OBJECT = nil means current buffer. */
3485 Lisp_Object object
=
3486 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3487 Lisp_Object pos
= make_number (charpos
);
3489 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3491 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3494 /* It could happen that the display property or overlay was removed
3495 since we found it in compute_display_string_pos above. One way
3496 this can happen is if JIT font-lock was called (through
3497 handle_fontified_prop), and jit-lock-functions remove text
3498 properties or overlays from the portion of buffer that includes
3499 CHARPOS. Muse mode is known to do that, for example. In this
3500 case, we return -1 to the caller, to signal that no display
3501 string is actually present at CHARPOS. See bidi_fetch_char for
3502 how this is handled.
3504 An alternative would be to never look for display properties past
3505 it->stop_charpos. But neither compute_display_string_pos nor
3506 bidi_fetch_char that calls it know or care where the next
3508 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3511 /* Look forward for the first character where the `display' property
3513 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3515 return XFASTINT (pos
);
3520 /***********************************************************************
3522 ***********************************************************************/
3524 /* Handle changes in the `fontified' property of the current buffer by
3525 calling hook functions from Qfontification_functions to fontify
3528 static enum prop_handled
3529 handle_fontified_prop (struct it
*it
)
3531 Lisp_Object prop
, pos
;
3532 enum prop_handled handled
= HANDLED_NORMALLY
;
3534 if (!NILP (Vmemory_full
))
3537 /* Get the value of the `fontified' property at IT's current buffer
3538 position. (The `fontified' property doesn't have a special
3539 meaning in strings.) If the value is nil, call functions from
3540 Qfontification_functions. */
3541 if (!STRINGP (it
->string
)
3543 && !NILP (Vfontification_functions
)
3544 && !NILP (Vrun_hooks
)
3545 && (pos
= make_number (IT_CHARPOS (*it
)),
3546 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3547 /* Ignore the special cased nil value always present at EOB since
3548 no amount of fontifying will be able to change it. */
3549 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3551 ptrdiff_t count
= SPECPDL_INDEX ();
3553 struct buffer
*obuf
= current_buffer
;
3554 int begv
= BEGV
, zv
= ZV
;
3555 int old_clip_changed
= current_buffer
->clip_changed
;
3557 val
= Vfontification_functions
;
3558 specbind (Qfontification_functions
, Qnil
);
3560 xassert (it
->end_charpos
== ZV
);
3562 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3563 safe_call1 (val
, pos
);
3566 Lisp_Object fns
, fn
;
3567 struct gcpro gcpro1
, gcpro2
;
3572 for (; CONSP (val
); val
= XCDR (val
))
3578 /* A value of t indicates this hook has a local
3579 binding; it means to run the global binding too.
3580 In a global value, t should not occur. If it
3581 does, we must ignore it to avoid an endless
3583 for (fns
= Fdefault_value (Qfontification_functions
);
3589 safe_call1 (fn
, pos
);
3593 safe_call1 (fn
, pos
);
3599 unbind_to (count
, Qnil
);
3601 /* Fontification functions routinely call `save-restriction'.
3602 Normally, this tags clip_changed, which can confuse redisplay
3603 (see discussion in Bug#6671). Since we don't perform any
3604 special handling of fontification changes in the case where
3605 `save-restriction' isn't called, there's no point doing so in
3606 this case either. So, if the buffer's restrictions are
3607 actually left unchanged, reset clip_changed. */
3608 if (obuf
== current_buffer
)
3610 if (begv
== BEGV
&& zv
== ZV
)
3611 current_buffer
->clip_changed
= old_clip_changed
;
3613 /* There isn't much we can reasonably do to protect against
3614 misbehaving fontification, but here's a fig leaf. */
3615 else if (!NILP (BVAR (obuf
, name
)))
3616 set_buffer_internal_1 (obuf
);
3618 /* The fontification code may have added/removed text.
3619 It could do even a lot worse, but let's at least protect against
3620 the most obvious case where only the text past `pos' gets changed',
3621 as is/was done in grep.el where some escapes sequences are turned
3622 into face properties (bug#7876). */
3623 it
->end_charpos
= ZV
;
3625 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3626 something. This avoids an endless loop if they failed to
3627 fontify the text for which reason ever. */
3628 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3629 handled
= HANDLED_RECOMPUTE_PROPS
;
3637 /***********************************************************************
3639 ***********************************************************************/
3641 /* Set up iterator IT from face properties at its current position.
3642 Called from handle_stop. */
3644 static enum prop_handled
3645 handle_face_prop (struct it
*it
)
3648 ptrdiff_t next_stop
;
3650 if (!STRINGP (it
->string
))
3653 = face_at_buffer_position (it
->w
,
3655 it
->region_beg_charpos
,
3656 it
->region_end_charpos
,
3659 + TEXT_PROP_DISTANCE_LIMIT
),
3660 0, it
->base_face_id
);
3662 /* Is this a start of a run of characters with box face?
3663 Caveat: this can be called for a freshly initialized
3664 iterator; face_id is -1 in this case. We know that the new
3665 face will not change until limit, i.e. if the new face has a
3666 box, all characters up to limit will have one. But, as
3667 usual, we don't know whether limit is really the end. */
3668 if (new_face_id
!= it
->face_id
)
3670 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3672 /* If new face has a box but old face has not, this is
3673 the start of a run of characters with box, i.e. it has
3674 a shadow on the left side. The value of face_id of the
3675 iterator will be -1 if this is the initial call that gets
3676 the face. In this case, we have to look in front of IT's
3677 position and see whether there is a face != new_face_id. */
3678 it
->start_of_box_run_p
3679 = (new_face
->box
!= FACE_NO_BOX
3680 && (it
->face_id
>= 0
3681 || IT_CHARPOS (*it
) == BEG
3682 || new_face_id
!= face_before_it_pos (it
)));
3683 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3691 Lisp_Object from_overlay
3692 = (it
->current
.overlay_string_index
>= 0
3693 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3696 /* See if we got to this string directly or indirectly from
3697 an overlay property. That includes the before-string or
3698 after-string of an overlay, strings in display properties
3699 provided by an overlay, their text properties, etc.
3701 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3702 if (! NILP (from_overlay
))
3703 for (i
= it
->sp
- 1; i
>= 0; i
--)
3705 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3707 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3708 else if (! NILP (it
->stack
[i
].from_overlay
))
3709 from_overlay
= it
->stack
[i
].from_overlay
;
3711 if (!NILP (from_overlay
))
3715 if (! NILP (from_overlay
))
3717 bufpos
= IT_CHARPOS (*it
);
3718 /* For a string from an overlay, the base face depends
3719 only on text properties and ignores overlays. */
3721 = face_for_overlay_string (it
->w
,
3723 it
->region_beg_charpos
,
3724 it
->region_end_charpos
,
3727 + TEXT_PROP_DISTANCE_LIMIT
),
3735 /* For strings from a `display' property, use the face at
3736 IT's current buffer position as the base face to merge
3737 with, so that overlay strings appear in the same face as
3738 surrounding text, unless they specify their own
3740 base_face_id
= it
->string_from_prefix_prop_p
3742 : underlying_face_id (it
);
3745 new_face_id
= face_at_string_position (it
->w
,
3747 IT_STRING_CHARPOS (*it
),
3749 it
->region_beg_charpos
,
3750 it
->region_end_charpos
,
3754 /* Is this a start of a run of characters with box? Caveat:
3755 this can be called for a freshly allocated iterator; face_id
3756 is -1 is this case. We know that the new face will not
3757 change until the next check pos, i.e. if the new face has a
3758 box, all characters up to that position will have a
3759 box. But, as usual, we don't know whether that position
3760 is really the end. */
3761 if (new_face_id
!= it
->face_id
)
3763 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3764 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3766 /* If new face has a box but old face hasn't, this is the
3767 start of a run of characters with box, i.e. it has a
3768 shadow on the left side. */
3769 it
->start_of_box_run_p
3770 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3771 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3775 it
->face_id
= new_face_id
;
3776 return HANDLED_NORMALLY
;
3780 /* Return the ID of the face ``underlying'' IT's current position,
3781 which is in a string. If the iterator is associated with a
3782 buffer, return the face at IT's current buffer position.
3783 Otherwise, use the iterator's base_face_id. */
3786 underlying_face_id (struct it
*it
)
3788 int face_id
= it
->base_face_id
, i
;
3790 xassert (STRINGP (it
->string
));
3792 for (i
= it
->sp
- 1; i
>= 0; --i
)
3793 if (NILP (it
->stack
[i
].string
))
3794 face_id
= it
->stack
[i
].face_id
;
3800 /* Compute the face one character before or after the current position
3801 of IT, in the visual order. BEFORE_P non-zero means get the face
3802 in front (to the left in L2R paragraphs, to the right in R2L
3803 paragraphs) of IT's screen position. Value is the ID of the face. */
3806 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3809 ptrdiff_t next_check_charpos
;
3811 void *it_copy_data
= NULL
;
3813 xassert (it
->s
== NULL
);
3815 if (STRINGP (it
->string
))
3817 ptrdiff_t bufpos
, charpos
;
3820 /* No face change past the end of the string (for the case
3821 we are padding with spaces). No face change before the
3823 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3824 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3829 /* Set charpos to the position before or after IT's current
3830 position, in the logical order, which in the non-bidi
3831 case is the same as the visual order. */
3833 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3834 else if (it
->what
== IT_COMPOSITION
)
3835 /* For composition, we must check the character after the
3837 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3839 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3845 /* With bidi iteration, the character before the current
3846 in the visual order cannot be found by simple
3847 iteration, because "reverse" reordering is not
3848 supported. Instead, we need to use the move_it_*
3849 family of functions. */
3850 /* Ignore face changes before the first visible
3851 character on this display line. */
3852 if (it
->current_x
<= it
->first_visible_x
)
3854 SAVE_IT (it_copy
, *it
, it_copy_data
);
3855 /* Implementation note: Since move_it_in_display_line
3856 works in the iterator geometry, and thinks the first
3857 character is always the leftmost, even in R2L lines,
3858 we don't need to distinguish between the R2L and L2R
3860 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3861 it_copy
.current_x
- 1, MOVE_TO_X
);
3862 charpos
= IT_STRING_CHARPOS (it_copy
);
3863 RESTORE_IT (it
, it
, it_copy_data
);
3867 /* Set charpos to the string position of the character
3868 that comes after IT's current position in the visual
3870 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3874 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3876 charpos
= it_copy
.bidi_it
.charpos
;
3879 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3881 if (it
->current
.overlay_string_index
>= 0)
3882 bufpos
= IT_CHARPOS (*it
);
3886 base_face_id
= underlying_face_id (it
);
3888 /* Get the face for ASCII, or unibyte. */
3889 face_id
= face_at_string_position (it
->w
,
3893 it
->region_beg_charpos
,
3894 it
->region_end_charpos
,
3895 &next_check_charpos
,
3898 /* Correct the face for charsets different from ASCII. Do it
3899 for the multibyte case only. The face returned above is
3900 suitable for unibyte text if IT->string is unibyte. */
3901 if (STRING_MULTIBYTE (it
->string
))
3903 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3904 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3906 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3908 c
= string_char_and_length (p
, &len
);
3909 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3914 struct text_pos pos
;
3916 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3917 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3920 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3921 pos
= it
->current
.pos
;
3926 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3929 if (it
->what
== IT_COMPOSITION
)
3931 /* For composition, we must check the position after
3933 pos
.charpos
+= it
->cmp_it
.nchars
;
3934 pos
.bytepos
+= it
->len
;
3937 INC_TEXT_POS (pos
, it
->multibyte_p
);
3944 /* With bidi iteration, the character before the current
3945 in the visual order cannot be found by simple
3946 iteration, because "reverse" reordering is not
3947 supported. Instead, we need to use the move_it_*
3948 family of functions. */
3949 /* Ignore face changes before the first visible
3950 character on this display line. */
3951 if (it
->current_x
<= it
->first_visible_x
)
3953 SAVE_IT (it_copy
, *it
, it_copy_data
);
3954 /* Implementation note: Since move_it_in_display_line
3955 works in the iterator geometry, and thinks the first
3956 character is always the leftmost, even in R2L lines,
3957 we don't need to distinguish between the R2L and L2R
3959 move_it_in_display_line (&it_copy
, ZV
,
3960 it_copy
.current_x
- 1, MOVE_TO_X
);
3961 pos
= it_copy
.current
.pos
;
3962 RESTORE_IT (it
, it
, it_copy_data
);
3966 /* Set charpos to the buffer position of the character
3967 that comes after IT's current position in the visual
3969 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3973 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3976 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3979 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3981 /* Determine face for CHARSET_ASCII, or unibyte. */
3982 face_id
= face_at_buffer_position (it
->w
,
3984 it
->region_beg_charpos
,
3985 it
->region_end_charpos
,
3986 &next_check_charpos
,
3989 /* Correct the face for charsets different from ASCII. Do it
3990 for the multibyte case only. The face returned above is
3991 suitable for unibyte text if current_buffer is unibyte. */
3992 if (it
->multibyte_p
)
3994 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3995 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3996 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4005 /***********************************************************************
4007 ***********************************************************************/
4009 /* Set up iterator IT from invisible properties at its current
4010 position. Called from handle_stop. */
4012 static enum prop_handled
4013 handle_invisible_prop (struct it
*it
)
4015 enum prop_handled handled
= HANDLED_NORMALLY
;
4017 if (STRINGP (it
->string
))
4019 Lisp_Object prop
, end_charpos
, limit
, charpos
;
4021 /* Get the value of the invisible text property at the
4022 current position. Value will be nil if there is no such
4024 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4025 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4028 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4032 handled
= HANDLED_RECOMPUTE_PROPS
;
4034 /* Get the position at which the next change of the
4035 invisible text property can be found in IT->string.
4036 Value will be nil if the property value is the same for
4037 all the rest of IT->string. */
4038 XSETINT (limit
, SCHARS (it
->string
));
4039 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4042 /* Text at current position is invisible. The next
4043 change in the property is at position end_charpos.
4044 Move IT's current position to that position. */
4045 if (INTEGERP (end_charpos
)
4046 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
4048 struct text_pos old
;
4051 old
= it
->current
.string_pos
;
4052 oldpos
= CHARPOS (old
);
4055 if (it
->bidi_it
.first_elt
4056 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4057 bidi_paragraph_init (it
->paragraph_embedding
,
4059 /* Bidi-iterate out of the invisible text. */
4062 bidi_move_to_visually_next (&it
->bidi_it
);
4064 while (oldpos
<= it
->bidi_it
.charpos
4065 && it
->bidi_it
.charpos
< endpos
);
4067 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4068 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4069 if (IT_CHARPOS (*it
) >= endpos
)
4070 it
->prev_stop
= endpos
;
4074 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4075 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4080 /* The rest of the string is invisible. If this is an
4081 overlay string, proceed with the next overlay string
4082 or whatever comes and return a character from there. */
4083 if (it
->current
.overlay_string_index
>= 0)
4085 next_overlay_string (it
);
4086 /* Don't check for overlay strings when we just
4087 finished processing them. */
4088 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4092 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4093 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4101 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4102 Lisp_Object pos
, prop
, overlay
;
4104 /* First of all, is there invisible text at this position? */
4105 tem
= start_charpos
= IT_CHARPOS (*it
);
4106 pos
= make_number (tem
);
4107 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4109 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4111 /* If we are on invisible text, skip over it. */
4112 if (invis_p
&& start_charpos
< it
->end_charpos
)
4114 /* Record whether we have to display an ellipsis for the
4116 int display_ellipsis_p
= invis_p
== 2;
4118 handled
= HANDLED_RECOMPUTE_PROPS
;
4120 /* Loop skipping over invisible text. The loop is left at
4121 ZV or with IT on the first char being visible again. */
4124 /* Try to skip some invisible text. Return value is the
4125 position reached which can be equal to where we start
4126 if there is nothing invisible there. This skips both
4127 over invisible text properties and overlays with
4128 invisible property. */
4129 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4131 /* If we skipped nothing at all we weren't at invisible
4132 text in the first place. If everything to the end of
4133 the buffer was skipped, end the loop. */
4134 if (newpos
== tem
|| newpos
>= ZV
)
4138 /* We skipped some characters but not necessarily
4139 all there are. Check if we ended up on visible
4140 text. Fget_char_property returns the property of
4141 the char before the given position, i.e. if we
4142 get invis_p = 0, this means that the char at
4143 newpos is visible. */
4144 pos
= make_number (newpos
);
4145 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4146 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4149 /* If we ended up on invisible text, proceed to
4150 skip starting with next_stop. */
4154 /* If there are adjacent invisible texts, don't lose the
4155 second one's ellipsis. */
4157 display_ellipsis_p
= 1;
4161 /* The position newpos is now either ZV or on visible text. */
4164 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4166 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4168 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4170 /* If the invisible text ends on a newline or on a
4171 character after a newline, we can avoid the costly,
4172 character by character, bidi iteration to NEWPOS, and
4173 instead simply reseat the iterator there. That's
4174 because all bidi reordering information is tossed at
4175 the newline. This is a big win for modes that hide
4176 complete lines, like Outline, Org, etc. */
4177 if (on_newline
|| after_newline
)
4179 struct text_pos tpos
;
4180 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4182 SET_TEXT_POS (tpos
, newpos
, bpos
);
4183 reseat_1 (it
, tpos
, 0);
4184 /* If we reseat on a newline/ZV, we need to prep the
4185 bidi iterator for advancing to the next character
4186 after the newline/EOB, keeping the current paragraph
4187 direction (so that PRODUCE_GLYPHS does TRT wrt
4188 prepending/appending glyphs to a glyph row). */
4191 it
->bidi_it
.first_elt
= 0;
4192 it
->bidi_it
.paragraph_dir
= pdir
;
4193 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4194 it
->bidi_it
.nchars
= 1;
4195 it
->bidi_it
.ch_len
= 1;
4198 else /* Must use the slow method. */
4200 /* With bidi iteration, the region of invisible text
4201 could start and/or end in the middle of a
4202 non-base embedding level. Therefore, we need to
4203 skip invisible text using the bidi iterator,
4204 starting at IT's current position, until we find
4205 ourselves outside of the invisible text.
4206 Skipping invisible text _after_ bidi iteration
4207 avoids affecting the visual order of the
4208 displayed text when invisible properties are
4209 added or removed. */
4210 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4212 /* If we were `reseat'ed to a new paragraph,
4213 determine the paragraph base direction. We
4214 need to do it now because
4215 next_element_from_buffer may not have a
4216 chance to do it, if we are going to skip any
4217 text at the beginning, which resets the
4219 bidi_paragraph_init (it
->paragraph_embedding
,
4224 bidi_move_to_visually_next (&it
->bidi_it
);
4226 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4227 && it
->bidi_it
.charpos
< newpos
);
4228 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4229 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4230 /* If we overstepped NEWPOS, record its position in
4231 the iterator, so that we skip invisible text if
4232 later the bidi iteration lands us in the
4233 invisible region again. */
4234 if (IT_CHARPOS (*it
) >= newpos
)
4235 it
->prev_stop
= newpos
;
4240 IT_CHARPOS (*it
) = newpos
;
4241 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4244 /* If there are before-strings at the start of invisible
4245 text, and the text is invisible because of a text
4246 property, arrange to show before-strings because 20.x did
4247 it that way. (If the text is invisible because of an
4248 overlay property instead of a text property, this is
4249 already handled in the overlay code.) */
4251 && get_overlay_strings (it
, it
->stop_charpos
))
4253 handled
= HANDLED_RECOMPUTE_PROPS
;
4254 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4256 else if (display_ellipsis_p
)
4258 /* Make sure that the glyphs of the ellipsis will get
4259 correct `charpos' values. If we would not update
4260 it->position here, the glyphs would belong to the
4261 last visible character _before_ the invisible
4262 text, which confuses `set_cursor_from_row'.
4264 We use the last invisible position instead of the
4265 first because this way the cursor is always drawn on
4266 the first "." of the ellipsis, whenever PT is inside
4267 the invisible text. Otherwise the cursor would be
4268 placed _after_ the ellipsis when the point is after the
4269 first invisible character. */
4270 if (!STRINGP (it
->object
))
4272 it
->position
.charpos
= newpos
- 1;
4273 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4276 /* Let the ellipsis display before
4277 considering any properties of the following char.
4278 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4279 handled
= HANDLED_RETURN
;
4288 /* Make iterator IT return `...' next.
4289 Replaces LEN characters from buffer. */
4292 setup_for_ellipsis (struct it
*it
, int len
)
4294 /* Use the display table definition for `...'. Invalid glyphs
4295 will be handled by the method returning elements from dpvec. */
4296 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4298 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4299 it
->dpvec
= v
->contents
;
4300 it
->dpend
= v
->contents
+ v
->header
.size
;
4304 /* Default `...'. */
4305 it
->dpvec
= default_invis_vector
;
4306 it
->dpend
= default_invis_vector
+ 3;
4309 it
->dpvec_char_len
= len
;
4310 it
->current
.dpvec_index
= 0;
4311 it
->dpvec_face_id
= -1;
4313 /* Remember the current face id in case glyphs specify faces.
4314 IT's face is restored in set_iterator_to_next.
4315 saved_face_id was set to preceding char's face in handle_stop. */
4316 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4317 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4319 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4325 /***********************************************************************
4327 ***********************************************************************/
4329 /* Set up iterator IT from `display' property at its current position.
4330 Called from handle_stop.
4331 We return HANDLED_RETURN if some part of the display property
4332 overrides the display of the buffer text itself.
4333 Otherwise we return HANDLED_NORMALLY. */
4335 static enum prop_handled
4336 handle_display_prop (struct it
*it
)
4338 Lisp_Object propval
, object
, overlay
;
4339 struct text_pos
*position
;
4341 /* Nonzero if some property replaces the display of the text itself. */
4342 int display_replaced_p
= 0;
4344 if (STRINGP (it
->string
))
4346 object
= it
->string
;
4347 position
= &it
->current
.string_pos
;
4348 bufpos
= CHARPOS (it
->current
.pos
);
4352 XSETWINDOW (object
, it
->w
);
4353 position
= &it
->current
.pos
;
4354 bufpos
= CHARPOS (*position
);
4357 /* Reset those iterator values set from display property values. */
4358 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4359 it
->space_width
= Qnil
;
4360 it
->font_height
= Qnil
;
4363 /* We don't support recursive `display' properties, i.e. string
4364 values that have a string `display' property, that have a string
4365 `display' property etc. */
4366 if (!it
->string_from_display_prop_p
)
4367 it
->area
= TEXT_AREA
;
4369 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4370 Qdisplay
, object
, &overlay
);
4372 return HANDLED_NORMALLY
;
4373 /* Now OVERLAY is the overlay that gave us this property, or nil
4374 if it was a text property. */
4376 if (!STRINGP (it
->string
))
4377 object
= it
->w
->buffer
;
4379 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4381 FRAME_WINDOW_P (it
->f
));
4383 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4386 /* Subroutine of handle_display_prop. Returns non-zero if the display
4387 specification in SPEC is a replacing specification, i.e. it would
4388 replace the text covered by `display' property with something else,
4389 such as an image or a display string. If SPEC includes any kind or
4390 `(space ...) specification, the value is 2; this is used by
4391 compute_display_string_pos, which see.
4393 See handle_single_display_spec for documentation of arguments.
4394 frame_window_p is non-zero if the window being redisplayed is on a
4395 GUI frame; this argument is used only if IT is NULL, see below.
4397 IT can be NULL, if this is called by the bidi reordering code
4398 through compute_display_string_pos, which see. In that case, this
4399 function only examines SPEC, but does not otherwise "handle" it, in
4400 the sense that it doesn't set up members of IT from the display
4403 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4404 Lisp_Object overlay
, struct text_pos
*position
,
4405 ptrdiff_t bufpos
, int frame_window_p
)
4407 int replacing_p
= 0;
4411 /* Simple specifications. */
4412 && !EQ (XCAR (spec
), Qimage
)
4413 && !EQ (XCAR (spec
), Qspace
)
4414 && !EQ (XCAR (spec
), Qwhen
)
4415 && !EQ (XCAR (spec
), Qslice
)
4416 && !EQ (XCAR (spec
), Qspace_width
)
4417 && !EQ (XCAR (spec
), Qheight
)
4418 && !EQ (XCAR (spec
), Qraise
)
4419 /* Marginal area specifications. */
4420 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4421 && !EQ (XCAR (spec
), Qleft_fringe
)
4422 && !EQ (XCAR (spec
), Qright_fringe
)
4423 && !NILP (XCAR (spec
)))
4425 for (; CONSP (spec
); spec
= XCDR (spec
))
4427 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4428 overlay
, position
, bufpos
,
4429 replacing_p
, frame_window_p
)))
4432 /* If some text in a string is replaced, `position' no
4433 longer points to the position of `object'. */
4434 if (!it
|| STRINGP (object
))
4439 else if (VECTORP (spec
))
4442 for (i
= 0; i
< ASIZE (spec
); ++i
)
4443 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4444 overlay
, position
, bufpos
,
4445 replacing_p
, frame_window_p
)))
4448 /* If some text in a string is replaced, `position' no
4449 longer points to the position of `object'. */
4450 if (!it
|| STRINGP (object
))
4456 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4457 position
, bufpos
, 0,
4465 /* Value is the position of the end of the `display' property starting
4466 at START_POS in OBJECT. */
4468 static struct text_pos
4469 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4472 struct text_pos end_pos
;
4474 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4475 Qdisplay
, object
, Qnil
);
4476 CHARPOS (end_pos
) = XFASTINT (end
);
4477 if (STRINGP (object
))
4478 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4480 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4486 /* Set up IT from a single `display' property specification SPEC. OBJECT
4487 is the object in which the `display' property was found. *POSITION
4488 is the position in OBJECT at which the `display' property was found.
4489 BUFPOS is the buffer position of OBJECT (different from POSITION if
4490 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4491 previously saw a display specification which already replaced text
4492 display with something else, for example an image; we ignore such
4493 properties after the first one has been processed.
4495 OVERLAY is the overlay this `display' property came from,
4496 or nil if it was a text property.
4498 If SPEC is a `space' or `image' specification, and in some other
4499 cases too, set *POSITION to the position where the `display'
4502 If IT is NULL, only examine the property specification in SPEC, but
4503 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4504 is intended to be displayed in a window on a GUI frame.
4506 Value is non-zero if something was found which replaces the display
4507 of buffer or string text. */
4510 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4511 Lisp_Object overlay
, struct text_pos
*position
,
4512 ptrdiff_t bufpos
, int display_replaced_p
,
4516 Lisp_Object location
, value
;
4517 struct text_pos start_pos
= *position
;
4520 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4521 If the result is non-nil, use VALUE instead of SPEC. */
4523 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4532 if (!NILP (form
) && !EQ (form
, Qt
))
4534 ptrdiff_t count
= SPECPDL_INDEX ();
4535 struct gcpro gcpro1
;
4537 /* Bind `object' to the object having the `display' property, a
4538 buffer or string. Bind `position' to the position in the
4539 object where the property was found, and `buffer-position'
4540 to the current position in the buffer. */
4543 XSETBUFFER (object
, current_buffer
);
4544 specbind (Qobject
, object
);
4545 specbind (Qposition
, make_number (CHARPOS (*position
)));
4546 specbind (Qbuffer_position
, make_number (bufpos
));
4548 form
= safe_eval (form
);
4550 unbind_to (count
, Qnil
);
4556 /* Handle `(height HEIGHT)' specifications. */
4558 && EQ (XCAR (spec
), Qheight
)
4559 && CONSP (XCDR (spec
)))
4563 if (!FRAME_WINDOW_P (it
->f
))
4566 it
->font_height
= XCAR (XCDR (spec
));
4567 if (!NILP (it
->font_height
))
4569 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4570 int new_height
= -1;
4572 if (CONSP (it
->font_height
)
4573 && (EQ (XCAR (it
->font_height
), Qplus
)
4574 || EQ (XCAR (it
->font_height
), Qminus
))
4575 && CONSP (XCDR (it
->font_height
))
4576 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4578 /* `(+ N)' or `(- N)' where N is an integer. */
4579 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4580 if (EQ (XCAR (it
->font_height
), Qplus
))
4582 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4584 else if (FUNCTIONP (it
->font_height
))
4586 /* Call function with current height as argument.
4587 Value is the new height. */
4589 height
= safe_call1 (it
->font_height
,
4590 face
->lface
[LFACE_HEIGHT_INDEX
]);
4591 if (NUMBERP (height
))
4592 new_height
= XFLOATINT (height
);
4594 else if (NUMBERP (it
->font_height
))
4596 /* Value is a multiple of the canonical char height. */
4599 f
= FACE_FROM_ID (it
->f
,
4600 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4601 new_height
= (XFLOATINT (it
->font_height
)
4602 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4606 /* Evaluate IT->font_height with `height' bound to the
4607 current specified height to get the new height. */
4608 ptrdiff_t count
= SPECPDL_INDEX ();
4610 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4611 value
= safe_eval (it
->font_height
);
4612 unbind_to (count
, Qnil
);
4614 if (NUMBERP (value
))
4615 new_height
= XFLOATINT (value
);
4619 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4626 /* Handle `(space-width WIDTH)'. */
4628 && EQ (XCAR (spec
), Qspace_width
)
4629 && CONSP (XCDR (spec
)))
4633 if (!FRAME_WINDOW_P (it
->f
))
4636 value
= XCAR (XCDR (spec
));
4637 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4638 it
->space_width
= value
;
4644 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4646 && EQ (XCAR (spec
), Qslice
))
4652 if (!FRAME_WINDOW_P (it
->f
))
4655 if (tem
= XCDR (spec
), CONSP (tem
))
4657 it
->slice
.x
= XCAR (tem
);
4658 if (tem
= XCDR (tem
), CONSP (tem
))
4660 it
->slice
.y
= XCAR (tem
);
4661 if (tem
= XCDR (tem
), CONSP (tem
))
4663 it
->slice
.width
= XCAR (tem
);
4664 if (tem
= XCDR (tem
), CONSP (tem
))
4665 it
->slice
.height
= XCAR (tem
);
4674 /* Handle `(raise FACTOR)'. */
4676 && EQ (XCAR (spec
), Qraise
)
4677 && CONSP (XCDR (spec
)))
4681 if (!FRAME_WINDOW_P (it
->f
))
4684 #ifdef HAVE_WINDOW_SYSTEM
4685 value
= XCAR (XCDR (spec
));
4686 if (NUMBERP (value
))
4688 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4689 it
->voffset
= - (XFLOATINT (value
)
4690 * (FONT_HEIGHT (face
->font
)));
4692 #endif /* HAVE_WINDOW_SYSTEM */
4698 /* Don't handle the other kinds of display specifications
4699 inside a string that we got from a `display' property. */
4700 if (it
&& it
->string_from_display_prop_p
)
4703 /* Characters having this form of property are not displayed, so
4704 we have to find the end of the property. */
4707 start_pos
= *position
;
4708 *position
= display_prop_end (it
, object
, start_pos
);
4712 /* Stop the scan at that end position--we assume that all
4713 text properties change there. */
4715 it
->stop_charpos
= position
->charpos
;
4717 /* Handle `(left-fringe BITMAP [FACE])'
4718 and `(right-fringe BITMAP [FACE])'. */
4720 && (EQ (XCAR (spec
), Qleft_fringe
)
4721 || EQ (XCAR (spec
), Qright_fringe
))
4722 && CONSP (XCDR (spec
)))
4728 if (!FRAME_WINDOW_P (it
->f
))
4729 /* If we return here, POSITION has been advanced
4730 across the text with this property. */
4732 /* Synchronize the bidi iterator with POSITION. This is
4733 needed because we are not going to push the iterator
4734 on behalf of this display property, so there will be
4735 no pop_it call to do this synchronization for us. */
4738 it
->position
= *position
;
4739 iterate_out_of_display_property (it
);
4740 *position
= it
->position
;
4745 else if (!frame_window_p
)
4748 #ifdef HAVE_WINDOW_SYSTEM
4749 value
= XCAR (XCDR (spec
));
4750 if (!SYMBOLP (value
)
4751 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4752 /* If we return here, POSITION has been advanced
4753 across the text with this property. */
4755 if (it
&& it
->bidi_p
)
4757 it
->position
= *position
;
4758 iterate_out_of_display_property (it
);
4759 *position
= it
->position
;
4766 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4768 if (CONSP (XCDR (XCDR (spec
))))
4770 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4771 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4777 /* Save current settings of IT so that we can restore them
4778 when we are finished with the glyph property value. */
4779 push_it (it
, position
);
4781 it
->area
= TEXT_AREA
;
4782 it
->what
= IT_IMAGE
;
4783 it
->image_id
= -1; /* no image */
4784 it
->position
= start_pos
;
4785 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4786 it
->method
= GET_FROM_IMAGE
;
4787 it
->from_overlay
= Qnil
;
4788 it
->face_id
= face_id
;
4789 it
->from_disp_prop_p
= 1;
4791 /* Say that we haven't consumed the characters with
4792 `display' property yet. The call to pop_it in
4793 set_iterator_to_next will clean this up. */
4794 *position
= start_pos
;
4796 if (EQ (XCAR (spec
), Qleft_fringe
))
4798 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4799 it
->left_user_fringe_face_id
= face_id
;
4803 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4804 it
->right_user_fringe_face_id
= face_id
;
4807 #endif /* HAVE_WINDOW_SYSTEM */
4811 /* Prepare to handle `((margin left-margin) ...)',
4812 `((margin right-margin) ...)' and `((margin nil) ...)'
4813 prefixes for display specifications. */
4814 location
= Qunbound
;
4815 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4819 value
= XCDR (spec
);
4821 value
= XCAR (value
);
4824 if (EQ (XCAR (tem
), Qmargin
)
4825 && (tem
= XCDR (tem
),
4826 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4828 || EQ (tem
, Qleft_margin
)
4829 || EQ (tem
, Qright_margin
))))
4833 if (EQ (location
, Qunbound
))
4839 /* After this point, VALUE is the property after any
4840 margin prefix has been stripped. It must be a string,
4841 an image specification, or `(space ...)'.
4843 LOCATION specifies where to display: `left-margin',
4844 `right-margin' or nil. */
4846 valid_p
= (STRINGP (value
)
4847 #ifdef HAVE_WINDOW_SYSTEM
4848 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4849 && valid_image_p (value
))
4850 #endif /* not HAVE_WINDOW_SYSTEM */
4851 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4853 if (valid_p
&& !display_replaced_p
)
4859 /* Callers need to know whether the display spec is any kind
4860 of `(space ...)' spec that is about to affect text-area
4862 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4867 /* Save current settings of IT so that we can restore them
4868 when we are finished with the glyph property value. */
4869 push_it (it
, position
);
4870 it
->from_overlay
= overlay
;
4871 it
->from_disp_prop_p
= 1;
4873 if (NILP (location
))
4874 it
->area
= TEXT_AREA
;
4875 else if (EQ (location
, Qleft_margin
))
4876 it
->area
= LEFT_MARGIN_AREA
;
4878 it
->area
= RIGHT_MARGIN_AREA
;
4880 if (STRINGP (value
))
4883 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4884 it
->current
.overlay_string_index
= -1;
4885 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4886 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4887 it
->method
= GET_FROM_STRING
;
4888 it
->stop_charpos
= 0;
4890 it
->base_level_stop
= 0;
4891 it
->string_from_display_prop_p
= 1;
4892 /* Say that we haven't consumed the characters with
4893 `display' property yet. The call to pop_it in
4894 set_iterator_to_next will clean this up. */
4895 if (BUFFERP (object
))
4896 *position
= start_pos
;
4898 /* Force paragraph direction to be that of the parent
4899 object. If the parent object's paragraph direction is
4900 not yet determined, default to L2R. */
4901 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4902 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4904 it
->paragraph_embedding
= L2R
;
4906 /* Set up the bidi iterator for this display string. */
4909 it
->bidi_it
.string
.lstring
= it
->string
;
4910 it
->bidi_it
.string
.s
= NULL
;
4911 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4912 it
->bidi_it
.string
.bufpos
= bufpos
;
4913 it
->bidi_it
.string
.from_disp_str
= 1;
4914 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4915 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4918 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4920 it
->method
= GET_FROM_STRETCH
;
4922 *position
= it
->position
= start_pos
;
4923 retval
= 1 + (it
->area
== TEXT_AREA
);
4925 #ifdef HAVE_WINDOW_SYSTEM
4928 it
->what
= IT_IMAGE
;
4929 it
->image_id
= lookup_image (it
->f
, value
);
4930 it
->position
= start_pos
;
4931 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4932 it
->method
= GET_FROM_IMAGE
;
4934 /* Say that we haven't consumed the characters with
4935 `display' property yet. The call to pop_it in
4936 set_iterator_to_next will clean this up. */
4937 *position
= start_pos
;
4939 #endif /* HAVE_WINDOW_SYSTEM */
4944 /* Invalid property or property not supported. Restore
4945 POSITION to what it was before. */
4946 *position
= start_pos
;
4950 /* Check if PROP is a display property value whose text should be
4951 treated as intangible. OVERLAY is the overlay from which PROP
4952 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4953 specify the buffer position covered by PROP. */
4956 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4957 ptrdiff_t charpos
, ptrdiff_t bytepos
)
4959 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4960 struct text_pos position
;
4962 SET_TEXT_POS (position
, charpos
, bytepos
);
4963 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4964 &position
, charpos
, frame_window_p
);
4968 /* Return 1 if PROP is a display sub-property value containing STRING.
4970 Implementation note: this and the following function are really
4971 special cases of handle_display_spec and
4972 handle_single_display_spec, and should ideally use the same code.
4973 Until they do, these two pairs must be consistent and must be
4974 modified in sync. */
4977 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4979 if (EQ (string
, prop
))
4982 /* Skip over `when FORM'. */
4983 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4988 /* Actually, the condition following `when' should be eval'ed,
4989 like handle_single_display_spec does, and we should return
4990 zero if it evaluates to nil. However, this function is
4991 called only when the buffer was already displayed and some
4992 glyph in the glyph matrix was found to come from a display
4993 string. Therefore, the condition was already evaluated, and
4994 the result was non-nil, otherwise the display string wouldn't
4995 have been displayed and we would have never been called for
4996 this property. Thus, we can skip the evaluation and assume
4997 its result is non-nil. */
5002 /* Skip over `margin LOCATION'. */
5003 if (EQ (XCAR (prop
), Qmargin
))
5014 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5018 /* Return 1 if STRING appears in the `display' property PROP. */
5021 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5024 && !EQ (XCAR (prop
), Qwhen
)
5025 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5027 /* A list of sub-properties. */
5028 while (CONSP (prop
))
5030 if (single_display_spec_string_p (XCAR (prop
), string
))
5035 else if (VECTORP (prop
))
5037 /* A vector of sub-properties. */
5039 for (i
= 0; i
< ASIZE (prop
); ++i
)
5040 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5044 return single_display_spec_string_p (prop
, string
);
5049 /* Look for STRING in overlays and text properties in the current
5050 buffer, between character positions FROM and TO (excluding TO).
5051 BACK_P non-zero means look back (in this case, TO is supposed to be
5053 Value is the first character position where STRING was found, or
5054 zero if it wasn't found before hitting TO.
5056 This function may only use code that doesn't eval because it is
5057 called asynchronously from note_mouse_highlight. */
5060 string_buffer_position_lim (Lisp_Object string
,
5061 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5063 Lisp_Object limit
, prop
, pos
;
5066 pos
= make_number (max (from
, BEGV
));
5068 if (!back_p
) /* looking forward */
5070 limit
= make_number (min (to
, ZV
));
5071 while (!found
&& !EQ (pos
, limit
))
5073 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5074 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5077 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5081 else /* looking back */
5083 limit
= make_number (max (to
, BEGV
));
5084 while (!found
&& !EQ (pos
, limit
))
5086 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5087 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5090 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5095 return found
? XINT (pos
) : 0;
5098 /* Determine which buffer position in current buffer STRING comes from.
5099 AROUND_CHARPOS is an approximate position where it could come from.
5100 Value is the buffer position or 0 if it couldn't be determined.
5102 This function is necessary because we don't record buffer positions
5103 in glyphs generated from strings (to keep struct glyph small).
5104 This function may only use code that doesn't eval because it is
5105 called asynchronously from note_mouse_highlight. */
5108 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5110 const int MAX_DISTANCE
= 1000;
5111 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5112 around_charpos
+ MAX_DISTANCE
,
5116 found
= string_buffer_position_lim (string
, around_charpos
,
5117 around_charpos
- MAX_DISTANCE
, 1);
5123 /***********************************************************************
5124 `composition' property
5125 ***********************************************************************/
5127 /* Set up iterator IT from `composition' property at its current
5128 position. Called from handle_stop. */
5130 static enum prop_handled
5131 handle_composition_prop (struct it
*it
)
5133 Lisp_Object prop
, string
;
5134 ptrdiff_t pos
, pos_byte
, start
, end
;
5136 if (STRINGP (it
->string
))
5140 pos
= IT_STRING_CHARPOS (*it
);
5141 pos_byte
= IT_STRING_BYTEPOS (*it
);
5142 string
= it
->string
;
5143 s
= SDATA (string
) + pos_byte
;
5144 it
->c
= STRING_CHAR (s
);
5148 pos
= IT_CHARPOS (*it
);
5149 pos_byte
= IT_BYTEPOS (*it
);
5151 it
->c
= FETCH_CHAR (pos_byte
);
5154 /* If there's a valid composition and point is not inside of the
5155 composition (in the case that the composition is from the current
5156 buffer), draw a glyph composed from the composition components. */
5157 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5158 && COMPOSITION_VALID_P (start
, end
, prop
)
5159 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5162 /* As we can't handle this situation (perhaps font-lock added
5163 a new composition), we just return here hoping that next
5164 redisplay will detect this composition much earlier. */
5165 return HANDLED_NORMALLY
;
5168 if (STRINGP (it
->string
))
5169 pos_byte
= string_char_to_byte (it
->string
, start
);
5171 pos_byte
= CHAR_TO_BYTE (start
);
5173 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5176 if (it
->cmp_it
.id
>= 0)
5179 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5180 it
->cmp_it
.nglyphs
= -1;
5184 return HANDLED_NORMALLY
;
5189 /***********************************************************************
5191 ***********************************************************************/
5193 /* The following structure is used to record overlay strings for
5194 later sorting in load_overlay_strings. */
5196 struct overlay_entry
5198 Lisp_Object overlay
;
5205 /* Set up iterator IT from overlay strings at its current position.
5206 Called from handle_stop. */
5208 static enum prop_handled
5209 handle_overlay_change (struct it
*it
)
5211 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5212 return HANDLED_RECOMPUTE_PROPS
;
5214 return HANDLED_NORMALLY
;
5218 /* Set up the next overlay string for delivery by IT, if there is an
5219 overlay string to deliver. Called by set_iterator_to_next when the
5220 end of the current overlay string is reached. If there are more
5221 overlay strings to display, IT->string and
5222 IT->current.overlay_string_index are set appropriately here.
5223 Otherwise IT->string is set to nil. */
5226 next_overlay_string (struct it
*it
)
5228 ++it
->current
.overlay_string_index
;
5229 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5231 /* No more overlay strings. Restore IT's settings to what
5232 they were before overlay strings were processed, and
5233 continue to deliver from current_buffer. */
5235 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5238 || (NILP (it
->string
)
5239 && it
->method
== GET_FROM_BUFFER
5240 && it
->stop_charpos
>= BEGV
5241 && it
->stop_charpos
<= it
->end_charpos
));
5242 it
->current
.overlay_string_index
= -1;
5243 it
->n_overlay_strings
= 0;
5244 it
->overlay_strings_charpos
= -1;
5245 /* If there's an empty display string on the stack, pop the
5246 stack, to resync the bidi iterator with IT's position. Such
5247 empty strings are pushed onto the stack in
5248 get_overlay_strings_1. */
5249 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5252 /* If we're at the end of the buffer, record that we have
5253 processed the overlay strings there already, so that
5254 next_element_from_buffer doesn't try it again. */
5255 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5256 it
->overlay_strings_at_end_processed_p
= 1;
5260 /* There are more overlay strings to process. If
5261 IT->current.overlay_string_index has advanced to a position
5262 where we must load IT->overlay_strings with more strings, do
5263 it. We must load at the IT->overlay_strings_charpos where
5264 IT->n_overlay_strings was originally computed; when invisible
5265 text is present, this might not be IT_CHARPOS (Bug#7016). */
5266 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5268 if (it
->current
.overlay_string_index
&& i
== 0)
5269 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5271 /* Initialize IT to deliver display elements from the overlay
5273 it
->string
= it
->overlay_strings
[i
];
5274 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5275 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5276 it
->method
= GET_FROM_STRING
;
5277 it
->stop_charpos
= 0;
5278 if (it
->cmp_it
.stop_pos
>= 0)
5279 it
->cmp_it
.stop_pos
= 0;
5281 it
->base_level_stop
= 0;
5283 /* Set up the bidi iterator for this overlay string. */
5286 it
->bidi_it
.string
.lstring
= it
->string
;
5287 it
->bidi_it
.string
.s
= NULL
;
5288 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5289 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5290 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5291 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5292 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5300 /* Compare two overlay_entry structures E1 and E2. Used as a
5301 comparison function for qsort in load_overlay_strings. Overlay
5302 strings for the same position are sorted so that
5304 1. All after-strings come in front of before-strings, except
5305 when they come from the same overlay.
5307 2. Within after-strings, strings are sorted so that overlay strings
5308 from overlays with higher priorities come first.
5310 2. Within before-strings, strings are sorted so that overlay
5311 strings from overlays with higher priorities come last.
5313 Value is analogous to strcmp. */
5317 compare_overlay_entries (const void *e1
, const void *e2
)
5319 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5320 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5323 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5325 /* Let after-strings appear in front of before-strings if
5326 they come from different overlays. */
5327 if (EQ (entry1
->overlay
, entry2
->overlay
))
5328 result
= entry1
->after_string_p
? 1 : -1;
5330 result
= entry1
->after_string_p
? -1 : 1;
5332 else if (entry1
->priority
!= entry2
->priority
)
5334 if (entry1
->after_string_p
)
5335 /* After-strings sorted in order of decreasing priority. */
5336 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5338 /* Before-strings sorted in order of increasing priority. */
5339 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5348 /* Load the vector IT->overlay_strings with overlay strings from IT's
5349 current buffer position, or from CHARPOS if that is > 0. Set
5350 IT->n_overlays to the total number of overlay strings found.
5352 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5353 a time. On entry into load_overlay_strings,
5354 IT->current.overlay_string_index gives the number of overlay
5355 strings that have already been loaded by previous calls to this
5358 IT->add_overlay_start contains an additional overlay start
5359 position to consider for taking overlay strings from, if non-zero.
5360 This position comes into play when the overlay has an `invisible'
5361 property, and both before and after-strings. When we've skipped to
5362 the end of the overlay, because of its `invisible' property, we
5363 nevertheless want its before-string to appear.
5364 IT->add_overlay_start will contain the overlay start position
5367 Overlay strings are sorted so that after-string strings come in
5368 front of before-string strings. Within before and after-strings,
5369 strings are sorted by overlay priority. See also function
5370 compare_overlay_entries. */
5373 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5375 Lisp_Object overlay
, window
, str
, invisible
;
5376 struct Lisp_Overlay
*ov
;
5377 ptrdiff_t start
, end
;
5378 ptrdiff_t size
= 20;
5379 ptrdiff_t n
= 0, i
, j
;
5381 struct overlay_entry
*entries
5382 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5386 charpos
= IT_CHARPOS (*it
);
5388 /* Append the overlay string STRING of overlay OVERLAY to vector
5389 `entries' which has size `size' and currently contains `n'
5390 elements. AFTER_P non-zero means STRING is an after-string of
5392 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5395 Lisp_Object priority; \
5399 struct overlay_entry *old = entries; \
5400 SAFE_NALLOCA (entries, 2, size); \
5401 memcpy (entries, old, size * sizeof *entries); \
5405 entries[n].string = (STRING); \
5406 entries[n].overlay = (OVERLAY); \
5407 priority = Foverlay_get ((OVERLAY), Qpriority); \
5408 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5409 entries[n].after_string_p = (AFTER_P); \
5414 /* Process overlay before the overlay center. */
5415 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5417 XSETMISC (overlay
, ov
);
5418 xassert (OVERLAYP (overlay
));
5419 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5420 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5425 /* Skip this overlay if it doesn't start or end at IT's current
5427 if (end
!= charpos
&& start
!= charpos
)
5430 /* Skip this overlay if it doesn't apply to IT->w. */
5431 window
= Foverlay_get (overlay
, Qwindow
);
5432 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5435 /* If the text ``under'' the overlay is invisible, both before-
5436 and after-strings from this overlay are visible; start and
5437 end position are indistinguishable. */
5438 invisible
= Foverlay_get (overlay
, Qinvisible
);
5439 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5441 /* If overlay has a non-empty before-string, record it. */
5442 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5443 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5445 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5447 /* If overlay has a non-empty after-string, record it. */
5448 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5449 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5451 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5454 /* Process overlays after the overlay center. */
5455 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5457 XSETMISC (overlay
, ov
);
5458 xassert (OVERLAYP (overlay
));
5459 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5460 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5462 if (start
> charpos
)
5465 /* Skip this overlay if it doesn't start or end at IT's current
5467 if (end
!= charpos
&& start
!= charpos
)
5470 /* Skip this overlay if it doesn't apply to IT->w. */
5471 window
= Foverlay_get (overlay
, Qwindow
);
5472 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5475 /* If the text ``under'' the overlay is invisible, it has a zero
5476 dimension, and both before- and after-strings apply. */
5477 invisible
= Foverlay_get (overlay
, Qinvisible
);
5478 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5480 /* If overlay has a non-empty before-string, record it. */
5481 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5482 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5484 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5486 /* If overlay has a non-empty after-string, record it. */
5487 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5488 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5490 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5493 #undef RECORD_OVERLAY_STRING
5497 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5499 /* Record number of overlay strings, and where we computed it. */
5500 it
->n_overlay_strings
= n
;
5501 it
->overlay_strings_charpos
= charpos
;
5503 /* IT->current.overlay_string_index is the number of overlay strings
5504 that have already been consumed by IT. Copy some of the
5505 remaining overlay strings to IT->overlay_strings. */
5507 j
= it
->current
.overlay_string_index
;
5508 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5510 it
->overlay_strings
[i
] = entries
[j
].string
;
5511 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5519 /* Get the first chunk of overlay strings at IT's current buffer
5520 position, or at CHARPOS if that is > 0. Value is non-zero if at
5521 least one overlay string was found. */
5524 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5526 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5527 process. This fills IT->overlay_strings with strings, and sets
5528 IT->n_overlay_strings to the total number of strings to process.
5529 IT->pos.overlay_string_index has to be set temporarily to zero
5530 because load_overlay_strings needs this; it must be set to -1
5531 when no overlay strings are found because a zero value would
5532 indicate a position in the first overlay string. */
5533 it
->current
.overlay_string_index
= 0;
5534 load_overlay_strings (it
, charpos
);
5536 /* If we found overlay strings, set up IT to deliver display
5537 elements from the first one. Otherwise set up IT to deliver
5538 from current_buffer. */
5539 if (it
->n_overlay_strings
)
5541 /* Make sure we know settings in current_buffer, so that we can
5542 restore meaningful values when we're done with the overlay
5545 compute_stop_pos (it
);
5546 xassert (it
->face_id
>= 0);
5548 /* Save IT's settings. They are restored after all overlay
5549 strings have been processed. */
5550 xassert (!compute_stop_p
|| it
->sp
== 0);
5552 /* When called from handle_stop, there might be an empty display
5553 string loaded. In that case, don't bother saving it. But
5554 don't use this optimization with the bidi iterator, since we
5555 need the corresponding pop_it call to resync the bidi
5556 iterator's position with IT's position, after we are done
5557 with the overlay strings. (The corresponding call to pop_it
5558 in case of an empty display string is in
5559 next_overlay_string.) */
5561 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5564 /* Set up IT to deliver display elements from the first overlay
5566 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5567 it
->string
= it
->overlay_strings
[0];
5568 it
->from_overlay
= Qnil
;
5569 it
->stop_charpos
= 0;
5570 xassert (STRINGP (it
->string
));
5571 it
->end_charpos
= SCHARS (it
->string
);
5573 it
->base_level_stop
= 0;
5574 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5575 it
->method
= GET_FROM_STRING
;
5576 it
->from_disp_prop_p
= 0;
5578 /* Force paragraph direction to be that of the parent
5580 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5581 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5583 it
->paragraph_embedding
= L2R
;
5585 /* Set up the bidi iterator for this overlay string. */
5588 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5590 it
->bidi_it
.string
.lstring
= it
->string
;
5591 it
->bidi_it
.string
.s
= NULL
;
5592 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5593 it
->bidi_it
.string
.bufpos
= pos
;
5594 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5595 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5596 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5601 it
->current
.overlay_string_index
= -1;
5606 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5609 it
->method
= GET_FROM_BUFFER
;
5611 (void) get_overlay_strings_1 (it
, charpos
, 1);
5615 /* Value is non-zero if we found at least one overlay string. */
5616 return STRINGP (it
->string
);
5621 /***********************************************************************
5622 Saving and restoring state
5623 ***********************************************************************/
5625 /* Save current settings of IT on IT->stack. Called, for example,
5626 before setting up IT for an overlay string, to be able to restore
5627 IT's settings to what they were after the overlay string has been
5628 processed. If POSITION is non-NULL, it is the position to save on
5629 the stack instead of IT->position. */
5632 push_it (struct it
*it
, struct text_pos
*position
)
5634 struct iterator_stack_entry
*p
;
5636 xassert (it
->sp
< IT_STACK_SIZE
);
5637 p
= it
->stack
+ it
->sp
;
5639 p
->stop_charpos
= it
->stop_charpos
;
5640 p
->prev_stop
= it
->prev_stop
;
5641 p
->base_level_stop
= it
->base_level_stop
;
5642 p
->cmp_it
= it
->cmp_it
;
5643 xassert (it
->face_id
>= 0);
5644 p
->face_id
= it
->face_id
;
5645 p
->string
= it
->string
;
5646 p
->method
= it
->method
;
5647 p
->from_overlay
= it
->from_overlay
;
5650 case GET_FROM_IMAGE
:
5651 p
->u
.image
.object
= it
->object
;
5652 p
->u
.image
.image_id
= it
->image_id
;
5653 p
->u
.image
.slice
= it
->slice
;
5655 case GET_FROM_STRETCH
:
5656 p
->u
.stretch
.object
= it
->object
;
5659 p
->position
= position
? *position
: it
->position
;
5660 p
->current
= it
->current
;
5661 p
->end_charpos
= it
->end_charpos
;
5662 p
->string_nchars
= it
->string_nchars
;
5664 p
->multibyte_p
= it
->multibyte_p
;
5665 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5666 p
->space_width
= it
->space_width
;
5667 p
->font_height
= it
->font_height
;
5668 p
->voffset
= it
->voffset
;
5669 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5670 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5671 p
->display_ellipsis_p
= 0;
5672 p
->line_wrap
= it
->line_wrap
;
5673 p
->bidi_p
= it
->bidi_p
;
5674 p
->paragraph_embedding
= it
->paragraph_embedding
;
5675 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5678 /* Save the state of the bidi iterator as well. */
5680 bidi_push_it (&it
->bidi_it
);
5684 iterate_out_of_display_property (struct it
*it
)
5686 int buffer_p
= !STRINGP (it
->string
);
5687 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5688 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5690 xassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5692 /* Maybe initialize paragraph direction. If we are at the beginning
5693 of a new paragraph, next_element_from_buffer may not have a
5694 chance to do that. */
5695 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5696 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5697 /* prev_stop can be zero, so check against BEGV as well. */
5698 while (it
->bidi_it
.charpos
>= bob
5699 && it
->prev_stop
<= it
->bidi_it
.charpos
5700 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5701 && it
->bidi_it
.charpos
< eob
)
5702 bidi_move_to_visually_next (&it
->bidi_it
);
5703 /* Record the stop_pos we just crossed, for when we cross it
5705 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5706 it
->prev_stop
= CHARPOS (it
->position
);
5707 /* If we ended up not where pop_it put us, resync IT's
5708 positional members with the bidi iterator. */
5709 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5710 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5712 it
->current
.pos
= it
->position
;
5714 it
->current
.string_pos
= it
->position
;
5717 /* Restore IT's settings from IT->stack. Called, for example, when no
5718 more overlay strings must be processed, and we return to delivering
5719 display elements from a buffer, or when the end of a string from a
5720 `display' property is reached and we return to delivering display
5721 elements from an overlay string, or from a buffer. */
5724 pop_it (struct it
*it
)
5726 struct iterator_stack_entry
*p
;
5727 int from_display_prop
= it
->from_disp_prop_p
;
5729 xassert (it
->sp
> 0);
5731 p
= it
->stack
+ it
->sp
;
5732 it
->stop_charpos
= p
->stop_charpos
;
5733 it
->prev_stop
= p
->prev_stop
;
5734 it
->base_level_stop
= p
->base_level_stop
;
5735 it
->cmp_it
= p
->cmp_it
;
5736 it
->face_id
= p
->face_id
;
5737 it
->current
= p
->current
;
5738 it
->position
= p
->position
;
5739 it
->string
= p
->string
;
5740 it
->from_overlay
= p
->from_overlay
;
5741 if (NILP (it
->string
))
5742 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5743 it
->method
= p
->method
;
5746 case GET_FROM_IMAGE
:
5747 it
->image_id
= p
->u
.image
.image_id
;
5748 it
->object
= p
->u
.image
.object
;
5749 it
->slice
= p
->u
.image
.slice
;
5751 case GET_FROM_STRETCH
:
5752 it
->object
= p
->u
.stretch
.object
;
5754 case GET_FROM_BUFFER
:
5755 it
->object
= it
->w
->buffer
;
5757 case GET_FROM_STRING
:
5758 it
->object
= it
->string
;
5760 case GET_FROM_DISPLAY_VECTOR
:
5762 it
->method
= GET_FROM_C_STRING
;
5763 else if (STRINGP (it
->string
))
5764 it
->method
= GET_FROM_STRING
;
5767 it
->method
= GET_FROM_BUFFER
;
5768 it
->object
= it
->w
->buffer
;
5771 it
->end_charpos
= p
->end_charpos
;
5772 it
->string_nchars
= p
->string_nchars
;
5774 it
->multibyte_p
= p
->multibyte_p
;
5775 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5776 it
->space_width
= p
->space_width
;
5777 it
->font_height
= p
->font_height
;
5778 it
->voffset
= p
->voffset
;
5779 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5780 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5781 it
->line_wrap
= p
->line_wrap
;
5782 it
->bidi_p
= p
->bidi_p
;
5783 it
->paragraph_embedding
= p
->paragraph_embedding
;
5784 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5787 bidi_pop_it (&it
->bidi_it
);
5788 /* Bidi-iterate until we get out of the portion of text, if any,
5789 covered by a `display' text property or by an overlay with
5790 `display' property. (We cannot just jump there, because the
5791 internal coherency of the bidi iterator state can not be
5792 preserved across such jumps.) We also must determine the
5793 paragraph base direction if the overlay we just processed is
5794 at the beginning of a new paragraph. */
5795 if (from_display_prop
5796 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5797 iterate_out_of_display_property (it
);
5799 xassert ((BUFFERP (it
->object
)
5800 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5801 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5802 || (STRINGP (it
->object
)
5803 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5804 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5805 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5811 /***********************************************************************
5813 ***********************************************************************/
5815 /* Set IT's current position to the previous line start. */
5818 back_to_previous_line_start (struct it
*it
)
5820 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5821 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5825 /* Move IT to the next line start.
5827 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5828 we skipped over part of the text (as opposed to moving the iterator
5829 continuously over the text). Otherwise, don't change the value
5832 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5833 iterator on the newline, if it was found.
5835 Newlines may come from buffer text, overlay strings, or strings
5836 displayed via the `display' property. That's the reason we can't
5837 simply use find_next_newline_no_quit.
5839 Note that this function may not skip over invisible text that is so
5840 because of text properties and immediately follows a newline. If
5841 it would, function reseat_at_next_visible_line_start, when called
5842 from set_iterator_to_next, would effectively make invisible
5843 characters following a newline part of the wrong glyph row, which
5844 leads to wrong cursor motion. */
5847 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5848 struct bidi_it
*bidi_it_prev
)
5850 ptrdiff_t old_selective
;
5851 int newline_found_p
, n
;
5852 const int MAX_NEWLINE_DISTANCE
= 500;
5854 /* If already on a newline, just consume it to avoid unintended
5855 skipping over invisible text below. */
5856 if (it
->what
== IT_CHARACTER
5858 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5860 if (it
->bidi_p
&& bidi_it_prev
)
5861 *bidi_it_prev
= it
->bidi_it
;
5862 set_iterator_to_next (it
, 0);
5867 /* Don't handle selective display in the following. It's (a)
5868 unnecessary because it's done by the caller, and (b) leads to an
5869 infinite recursion because next_element_from_ellipsis indirectly
5870 calls this function. */
5871 old_selective
= it
->selective
;
5874 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5875 from buffer text. */
5876 for (n
= newline_found_p
= 0;
5877 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5878 n
+= STRINGP (it
->string
) ? 0 : 1)
5880 if (!get_next_display_element (it
))
5882 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5883 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5884 *bidi_it_prev
= it
->bidi_it
;
5885 set_iterator_to_next (it
, 0);
5888 /* If we didn't find a newline near enough, see if we can use a
5890 if (!newline_found_p
)
5892 ptrdiff_t start
= IT_CHARPOS (*it
);
5893 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5896 xassert (!STRINGP (it
->string
));
5898 /* If there isn't any `display' property in sight, and no
5899 overlays, we can just use the position of the newline in
5901 if (it
->stop_charpos
>= limit
5902 || ((pos
= Fnext_single_property_change (make_number (start
),
5904 make_number (limit
)),
5906 && next_overlay_change (start
) == ZV
))
5910 IT_CHARPOS (*it
) = limit
;
5911 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5915 struct bidi_it bprev
;
5917 /* Help bidi.c avoid expensive searches for display
5918 properties and overlays, by telling it that there are
5919 none up to `limit'. */
5920 if (it
->bidi_it
.disp_pos
< limit
)
5922 it
->bidi_it
.disp_pos
= limit
;
5923 it
->bidi_it
.disp_prop
= 0;
5926 bprev
= it
->bidi_it
;
5927 bidi_move_to_visually_next (&it
->bidi_it
);
5928 } while (it
->bidi_it
.charpos
!= limit
);
5929 IT_CHARPOS (*it
) = limit
;
5930 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5932 *bidi_it_prev
= bprev
;
5934 *skipped_p
= newline_found_p
= 1;
5938 while (get_next_display_element (it
)
5939 && !newline_found_p
)
5941 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5942 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5943 *bidi_it_prev
= it
->bidi_it
;
5944 set_iterator_to_next (it
, 0);
5949 it
->selective
= old_selective
;
5950 return newline_found_p
;
5954 /* Set IT's current position to the previous visible line start. Skip
5955 invisible text that is so either due to text properties or due to
5956 selective display. Caution: this does not change IT->current_x and
5960 back_to_previous_visible_line_start (struct it
*it
)
5962 while (IT_CHARPOS (*it
) > BEGV
)
5964 back_to_previous_line_start (it
);
5966 if (IT_CHARPOS (*it
) <= BEGV
)
5969 /* If selective > 0, then lines indented more than its value are
5971 if (it
->selective
> 0
5972 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5976 /* Check the newline before point for invisibility. */
5979 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5980 Qinvisible
, it
->window
);
5981 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5985 if (IT_CHARPOS (*it
) <= BEGV
)
5990 void *it2data
= NULL
;
5993 Lisp_Object val
, overlay
;
5995 SAVE_IT (it2
, *it
, it2data
);
5997 /* If newline is part of a composition, continue from start of composition */
5998 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5999 && beg
< IT_CHARPOS (*it
))
6002 /* If newline is replaced by a display property, find start of overlay
6003 or interval and continue search from that point. */
6004 pos
= --IT_CHARPOS (it2
);
6007 bidi_unshelve_cache (NULL
, 0);
6008 it2
.string_from_display_prop_p
= 0;
6009 it2
.from_disp_prop_p
= 0;
6010 if (handle_display_prop (&it2
) == HANDLED_RETURN
6011 && !NILP (val
= get_char_property_and_overlay
6012 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6013 && (OVERLAYP (overlay
)
6014 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6015 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6017 RESTORE_IT (it
, it
, it2data
);
6021 /* Newline is not replaced by anything -- so we are done. */
6022 RESTORE_IT (it
, it
, it2data
);
6028 IT_CHARPOS (*it
) = beg
;
6029 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6033 it
->continuation_lines_width
= 0;
6035 xassert (IT_CHARPOS (*it
) >= BEGV
);
6036 xassert (IT_CHARPOS (*it
) == BEGV
6037 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6042 /* Reseat iterator IT at the previous visible line start. Skip
6043 invisible text that is so either due to text properties or due to
6044 selective display. At the end, update IT's overlay information,
6045 face information etc. */
6048 reseat_at_previous_visible_line_start (struct it
*it
)
6050 back_to_previous_visible_line_start (it
);
6051 reseat (it
, it
->current
.pos
, 1);
6056 /* Reseat iterator IT on the next visible line start in the current
6057 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6058 preceding the line start. Skip over invisible text that is so
6059 because of selective display. Compute faces, overlays etc at the
6060 new position. Note that this function does not skip over text that
6061 is invisible because of text properties. */
6064 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6066 int newline_found_p
, skipped_p
= 0;
6067 struct bidi_it bidi_it_prev
;
6069 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6071 /* Skip over lines that are invisible because they are indented
6072 more than the value of IT->selective. */
6073 if (it
->selective
> 0)
6074 while (IT_CHARPOS (*it
) < ZV
6075 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6078 xassert (IT_BYTEPOS (*it
) == BEGV
6079 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6081 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6084 /* Position on the newline if that's what's requested. */
6085 if (on_newline_p
&& newline_found_p
)
6087 if (STRINGP (it
->string
))
6089 if (IT_STRING_CHARPOS (*it
) > 0)
6093 --IT_STRING_CHARPOS (*it
);
6094 --IT_STRING_BYTEPOS (*it
);
6098 /* We need to restore the bidi iterator to the state
6099 it had on the newline, and resync the IT's
6100 position with that. */
6101 it
->bidi_it
= bidi_it_prev
;
6102 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6103 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6107 else if (IT_CHARPOS (*it
) > BEGV
)
6116 /* We need to restore the bidi iterator to the state it
6117 had on the newline and resync IT with that. */
6118 it
->bidi_it
= bidi_it_prev
;
6119 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6120 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6122 reseat (it
, it
->current
.pos
, 0);
6126 reseat (it
, it
->current
.pos
, 0);
6133 /***********************************************************************
6134 Changing an iterator's position
6135 ***********************************************************************/
6137 /* Change IT's current position to POS in current_buffer. If FORCE_P
6138 is non-zero, always check for text properties at the new position.
6139 Otherwise, text properties are only looked up if POS >=
6140 IT->check_charpos of a property. */
6143 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6145 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6147 reseat_1 (it
, pos
, 0);
6149 /* Determine where to check text properties. Avoid doing it
6150 where possible because text property lookup is very expensive. */
6152 || CHARPOS (pos
) > it
->stop_charpos
6153 || CHARPOS (pos
) < original_pos
)
6157 /* For bidi iteration, we need to prime prev_stop and
6158 base_level_stop with our best estimations. */
6159 /* Implementation note: Of course, POS is not necessarily a
6160 stop position, so assigning prev_pos to it is a lie; we
6161 should have called compute_stop_backwards. However, if
6162 the current buffer does not include any R2L characters,
6163 that call would be a waste of cycles, because the
6164 iterator will never move back, and thus never cross this
6165 "fake" stop position. So we delay that backward search
6166 until the time we really need it, in next_element_from_buffer. */
6167 if (CHARPOS (pos
) != it
->prev_stop
)
6168 it
->prev_stop
= CHARPOS (pos
);
6169 if (CHARPOS (pos
) < it
->base_level_stop
)
6170 it
->base_level_stop
= 0; /* meaning it's unknown */
6176 it
->prev_stop
= it
->base_level_stop
= 0;
6185 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6186 IT->stop_pos to POS, also. */
6189 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6191 /* Don't call this function when scanning a C string. */
6192 xassert (it
->s
== NULL
);
6194 /* POS must be a reasonable value. */
6195 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6197 it
->current
.pos
= it
->position
= pos
;
6198 it
->end_charpos
= ZV
;
6200 it
->current
.dpvec_index
= -1;
6201 it
->current
.overlay_string_index
= -1;
6202 IT_STRING_CHARPOS (*it
) = -1;
6203 IT_STRING_BYTEPOS (*it
) = -1;
6205 it
->method
= GET_FROM_BUFFER
;
6206 it
->object
= it
->w
->buffer
;
6207 it
->area
= TEXT_AREA
;
6208 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6210 it
->string_from_display_prop_p
= 0;
6211 it
->string_from_prefix_prop_p
= 0;
6213 it
->from_disp_prop_p
= 0;
6214 it
->face_before_selective_p
= 0;
6217 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6219 bidi_unshelve_cache (NULL
, 0);
6220 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6221 it
->bidi_it
.string
.s
= NULL
;
6222 it
->bidi_it
.string
.lstring
= Qnil
;
6223 it
->bidi_it
.string
.bufpos
= 0;
6224 it
->bidi_it
.string
.unibyte
= 0;
6229 it
->stop_charpos
= CHARPOS (pos
);
6230 it
->base_level_stop
= CHARPOS (pos
);
6235 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6236 If S is non-null, it is a C string to iterate over. Otherwise,
6237 STRING gives a Lisp string to iterate over.
6239 If PRECISION > 0, don't return more then PRECISION number of
6240 characters from the string.
6242 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6243 characters have been returned. FIELD_WIDTH < 0 means an infinite
6246 MULTIBYTE = 0 means disable processing of multibyte characters,
6247 MULTIBYTE > 0 means enable it,
6248 MULTIBYTE < 0 means use IT->multibyte_p.
6250 IT must be initialized via a prior call to init_iterator before
6251 calling this function. */
6254 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6255 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6258 /* No region in strings. */
6259 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6261 /* No text property checks performed by default, but see below. */
6262 it
->stop_charpos
= -1;
6264 /* Set iterator position and end position. */
6265 memset (&it
->current
, 0, sizeof it
->current
);
6266 it
->current
.overlay_string_index
= -1;
6267 it
->current
.dpvec_index
= -1;
6268 xassert (charpos
>= 0);
6270 /* If STRING is specified, use its multibyteness, otherwise use the
6271 setting of MULTIBYTE, if specified. */
6273 it
->multibyte_p
= multibyte
> 0;
6275 /* Bidirectional reordering of strings is controlled by the default
6276 value of bidi-display-reordering. Don't try to reorder while
6277 loading loadup.el, as the necessary character property tables are
6278 not yet available. */
6281 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6285 xassert (STRINGP (string
));
6286 it
->string
= string
;
6288 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6289 it
->method
= GET_FROM_STRING
;
6290 it
->current
.string_pos
= string_pos (charpos
, string
);
6294 it
->bidi_it
.string
.lstring
= string
;
6295 it
->bidi_it
.string
.s
= NULL
;
6296 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6297 it
->bidi_it
.string
.bufpos
= 0;
6298 it
->bidi_it
.string
.from_disp_str
= 0;
6299 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6300 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6301 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6306 it
->s
= (const unsigned char *) s
;
6309 /* Note that we use IT->current.pos, not it->current.string_pos,
6310 for displaying C strings. */
6311 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6312 if (it
->multibyte_p
)
6314 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6315 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6319 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6320 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6325 it
->bidi_it
.string
.lstring
= Qnil
;
6326 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6327 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6328 it
->bidi_it
.string
.bufpos
= 0;
6329 it
->bidi_it
.string
.from_disp_str
= 0;
6330 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6331 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6334 it
->method
= GET_FROM_C_STRING
;
6337 /* PRECISION > 0 means don't return more than PRECISION characters
6339 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6341 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6343 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6346 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6347 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6348 FIELD_WIDTH < 0 means infinite field width. This is useful for
6349 padding with `-' at the end of a mode line. */
6350 if (field_width
< 0)
6351 field_width
= INFINITY
;
6352 /* Implementation note: We deliberately don't enlarge
6353 it->bidi_it.string.schars here to fit it->end_charpos, because
6354 the bidi iterator cannot produce characters out of thin air. */
6355 if (field_width
> it
->end_charpos
- charpos
)
6356 it
->end_charpos
= charpos
+ field_width
;
6358 /* Use the standard display table for displaying strings. */
6359 if (DISP_TABLE_P (Vstandard_display_table
))
6360 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6362 it
->stop_charpos
= charpos
;
6363 it
->prev_stop
= charpos
;
6364 it
->base_level_stop
= 0;
6367 it
->bidi_it
.first_elt
= 1;
6368 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6369 it
->bidi_it
.disp_pos
= -1;
6371 if (s
== NULL
&& it
->multibyte_p
)
6373 ptrdiff_t endpos
= SCHARS (it
->string
);
6374 if (endpos
> it
->end_charpos
)
6375 endpos
= it
->end_charpos
;
6376 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6384 /***********************************************************************
6386 ***********************************************************************/
6388 /* Map enum it_method value to corresponding next_element_from_* function. */
6390 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6392 next_element_from_buffer
,
6393 next_element_from_display_vector
,
6394 next_element_from_string
,
6395 next_element_from_c_string
,
6396 next_element_from_image
,
6397 next_element_from_stretch
6400 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6403 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6404 (possibly with the following characters). */
6406 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6407 ((IT)->cmp_it.id >= 0 \
6408 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6409 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6410 END_CHARPOS, (IT)->w, \
6411 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6415 /* Lookup the char-table Vglyphless_char_display for character C (-1
6416 if we want information for no-font case), and return the display
6417 method symbol. By side-effect, update it->what and
6418 it->glyphless_method. This function is called from
6419 get_next_display_element for each character element, and from
6420 x_produce_glyphs when no suitable font was found. */
6423 lookup_glyphless_char_display (int c
, struct it
*it
)
6425 Lisp_Object glyphless_method
= Qnil
;
6427 if (CHAR_TABLE_P (Vglyphless_char_display
)
6428 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6432 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6433 if (CONSP (glyphless_method
))
6434 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6435 ? XCAR (glyphless_method
)
6436 : XCDR (glyphless_method
);
6439 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6443 if (NILP (glyphless_method
))
6446 /* The default is to display the character by a proper font. */
6448 /* The default for the no-font case is to display an empty box. */
6449 glyphless_method
= Qempty_box
;
6451 if (EQ (glyphless_method
, Qzero_width
))
6454 return glyphless_method
;
6455 /* This method can't be used for the no-font case. */
6456 glyphless_method
= Qempty_box
;
6458 if (EQ (glyphless_method
, Qthin_space
))
6459 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6460 else if (EQ (glyphless_method
, Qempty_box
))
6461 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6462 else if (EQ (glyphless_method
, Qhex_code
))
6463 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6464 else if (STRINGP (glyphless_method
))
6465 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6468 /* Invalid value. We use the default method. */
6469 glyphless_method
= Qnil
;
6472 it
->what
= IT_GLYPHLESS
;
6473 return glyphless_method
;
6476 /* Load IT's display element fields with information about the next
6477 display element from the current position of IT. Value is zero if
6478 end of buffer (or C string) is reached. */
6480 static struct frame
*last_escape_glyph_frame
= NULL
;
6481 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6482 static int last_escape_glyph_merged_face_id
= 0;
6484 struct frame
*last_glyphless_glyph_frame
= NULL
;
6485 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6486 int last_glyphless_glyph_merged_face_id
= 0;
6489 get_next_display_element (struct it
*it
)
6491 /* Non-zero means that we found a display element. Zero means that
6492 we hit the end of what we iterate over. Performance note: the
6493 function pointer `method' used here turns out to be faster than
6494 using a sequence of if-statements. */
6498 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6500 if (it
->what
== IT_CHARACTER
)
6502 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6503 and only if (a) the resolved directionality of that character
6505 /* FIXME: Do we need an exception for characters from display
6507 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6508 it
->c
= bidi_mirror_char (it
->c
);
6509 /* Map via display table or translate control characters.
6510 IT->c, IT->len etc. have been set to the next character by
6511 the function call above. If we have a display table, and it
6512 contains an entry for IT->c, translate it. Don't do this if
6513 IT->c itself comes from a display table, otherwise we could
6514 end up in an infinite recursion. (An alternative could be to
6515 count the recursion depth of this function and signal an
6516 error when a certain maximum depth is reached.) Is it worth
6518 if (success_p
&& it
->dpvec
== NULL
)
6521 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6522 int nonascii_space_p
= 0;
6523 int nonascii_hyphen_p
= 0;
6524 int c
= it
->c
; /* This is the character to display. */
6526 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6528 xassert (SINGLE_BYTE_CHAR_P (c
));
6529 if (unibyte_display_via_language_environment
)
6531 c
= DECODE_CHAR (unibyte
, c
);
6533 c
= BYTE8_TO_CHAR (it
->c
);
6536 c
= BYTE8_TO_CHAR (it
->c
);
6540 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6543 struct Lisp_Vector
*v
= XVECTOR (dv
);
6545 /* Return the first character from the display table
6546 entry, if not empty. If empty, don't display the
6547 current character. */
6550 it
->dpvec_char_len
= it
->len
;
6551 it
->dpvec
= v
->contents
;
6552 it
->dpend
= v
->contents
+ v
->header
.size
;
6553 it
->current
.dpvec_index
= 0;
6554 it
->dpvec_face_id
= -1;
6555 it
->saved_face_id
= it
->face_id
;
6556 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6561 set_iterator_to_next (it
, 0);
6566 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6568 if (it
->what
== IT_GLYPHLESS
)
6570 /* Don't display this character. */
6571 set_iterator_to_next (it
, 0);
6575 /* If `nobreak-char-display' is non-nil, we display
6576 non-ASCII spaces and hyphens specially. */
6577 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6580 nonascii_space_p
= 1;
6581 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6582 nonascii_hyphen_p
= 1;
6585 /* Translate control characters into `\003' or `^C' form.
6586 Control characters coming from a display table entry are
6587 currently not translated because we use IT->dpvec to hold
6588 the translation. This could easily be changed but I
6589 don't believe that it is worth doing.
6591 The characters handled by `nobreak-char-display' must be
6594 Non-printable characters and raw-byte characters are also
6595 translated to octal form. */
6596 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6597 ? (it
->area
!= TEXT_AREA
6598 /* In mode line, treat \n, \t like other crl chars. */
6601 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6602 || (c
!= '\n' && c
!= '\t'))
6604 || nonascii_hyphen_p
6606 || ! CHAR_PRINTABLE_P (c
))))
6608 /* C is a control character, non-ASCII space/hyphen,
6609 raw-byte, or a non-printable character which must be
6610 displayed either as '\003' or as `^C' where the '\\'
6611 and '^' can be defined in the display table. Fill
6612 IT->ctl_chars with glyphs for what we have to
6613 display. Then, set IT->dpvec to these glyphs. */
6620 /* Handle control characters with ^. */
6622 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6626 g
= '^'; /* default glyph for Control */
6627 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6629 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6631 g
= GLYPH_CODE_CHAR (gc
);
6632 lface_id
= GLYPH_CODE_FACE (gc
);
6636 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6638 else if (it
->f
== last_escape_glyph_frame
6639 && it
->face_id
== last_escape_glyph_face_id
)
6641 face_id
= last_escape_glyph_merged_face_id
;
6645 /* Merge the escape-glyph face into the current face. */
6646 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6648 last_escape_glyph_frame
= it
->f
;
6649 last_escape_glyph_face_id
= it
->face_id
;
6650 last_escape_glyph_merged_face_id
= face_id
;
6653 XSETINT (it
->ctl_chars
[0], g
);
6654 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6656 goto display_control
;
6659 /* Handle non-ascii space in the mode where it only gets
6662 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6664 /* Merge `nobreak-space' into the current face. */
6665 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6667 XSETINT (it
->ctl_chars
[0], ' ');
6669 goto display_control
;
6672 /* Handle sequences that start with the "escape glyph". */
6674 /* the default escape glyph is \. */
6675 escape_glyph
= '\\';
6678 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6680 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6681 lface_id
= GLYPH_CODE_FACE (gc
);
6685 /* The display table specified a face.
6686 Merge it into face_id and also into escape_glyph. */
6687 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6690 else if (it
->f
== last_escape_glyph_frame
6691 && it
->face_id
== last_escape_glyph_face_id
)
6693 face_id
= last_escape_glyph_merged_face_id
;
6697 /* Merge the escape-glyph face into the current face. */
6698 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6700 last_escape_glyph_frame
= it
->f
;
6701 last_escape_glyph_face_id
= it
->face_id
;
6702 last_escape_glyph_merged_face_id
= face_id
;
6705 /* Draw non-ASCII hyphen with just highlighting: */
6707 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6709 XSETINT (it
->ctl_chars
[0], '-');
6711 goto display_control
;
6714 /* Draw non-ASCII space/hyphen with escape glyph: */
6716 if (nonascii_space_p
|| nonascii_hyphen_p
)
6718 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6719 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6721 goto display_control
;
6728 if (CHAR_BYTE8_P (c
))
6729 /* Display \200 instead of \17777600. */
6730 c
= CHAR_TO_BYTE8 (c
);
6731 len
= sprintf (str
, "%03o", c
);
6733 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6734 for (i
= 0; i
< len
; i
++)
6735 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6740 /* Set up IT->dpvec and return first character from it. */
6741 it
->dpvec_char_len
= it
->len
;
6742 it
->dpvec
= it
->ctl_chars
;
6743 it
->dpend
= it
->dpvec
+ ctl_len
;
6744 it
->current
.dpvec_index
= 0;
6745 it
->dpvec_face_id
= face_id
;
6746 it
->saved_face_id
= it
->face_id
;
6747 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6751 it
->char_to_display
= c
;
6755 it
->char_to_display
= it
->c
;
6759 /* Adjust face id for a multibyte character. There are no multibyte
6760 character in unibyte text. */
6761 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6764 && FRAME_WINDOW_P (it
->f
))
6766 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6768 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6770 /* Automatic composition with glyph-string. */
6771 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6773 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6777 ptrdiff_t pos
= (it
->s
? -1
6778 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6779 : IT_CHARPOS (*it
));
6782 if (it
->what
== IT_CHARACTER
)
6783 c
= it
->char_to_display
;
6786 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6790 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6791 /* TAB in a composition means display glyphs with
6792 padding space on the left or right. */
6793 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6796 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6801 /* Is this character the last one of a run of characters with
6802 box? If yes, set IT->end_of_box_run_p to 1. */
6806 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6808 int face_id
= underlying_face_id (it
);
6809 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6813 if (face
->box
== FACE_NO_BOX
)
6815 /* If the box comes from face properties in a
6816 display string, check faces in that string. */
6817 int string_face_id
= face_after_it_pos (it
);
6818 it
->end_of_box_run_p
6819 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6822 /* Otherwise, the box comes from the underlying face.
6823 If this is the last string character displayed, check
6824 the next buffer location. */
6825 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6826 && (it
->current
.overlay_string_index
6827 == it
->n_overlay_strings
- 1))
6831 struct text_pos pos
= it
->current
.pos
;
6832 INC_TEXT_POS (pos
, it
->multibyte_p
);
6834 next_face_id
= face_at_buffer_position
6835 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6836 it
->region_end_charpos
, &ignore
,
6837 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6839 it
->end_of_box_run_p
6840 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6847 int face_id
= face_after_it_pos (it
);
6848 it
->end_of_box_run_p
6849 = (face_id
!= it
->face_id
6850 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6853 /* If we reached the end of the object we've been iterating (e.g., a
6854 display string or an overlay string), and there's something on
6855 IT->stack, proceed with what's on the stack. It doesn't make
6856 sense to return zero if there's unprocessed stuff on the stack,
6857 because otherwise that stuff will never be displayed. */
6858 if (!success_p
&& it
->sp
> 0)
6860 set_iterator_to_next (it
, 0);
6861 success_p
= get_next_display_element (it
);
6864 /* Value is 0 if end of buffer or string reached. */
6869 /* Move IT to the next display element.
6871 RESEAT_P non-zero means if called on a newline in buffer text,
6872 skip to the next visible line start.
6874 Functions get_next_display_element and set_iterator_to_next are
6875 separate because I find this arrangement easier to handle than a
6876 get_next_display_element function that also increments IT's
6877 position. The way it is we can first look at an iterator's current
6878 display element, decide whether it fits on a line, and if it does,
6879 increment the iterator position. The other way around we probably
6880 would either need a flag indicating whether the iterator has to be
6881 incremented the next time, or we would have to implement a
6882 decrement position function which would not be easy to write. */
6885 set_iterator_to_next (struct it
*it
, int reseat_p
)
6887 /* Reset flags indicating start and end of a sequence of characters
6888 with box. Reset them at the start of this function because
6889 moving the iterator to a new position might set them. */
6890 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6894 case GET_FROM_BUFFER
:
6895 /* The current display element of IT is a character from
6896 current_buffer. Advance in the buffer, and maybe skip over
6897 invisible lines that are so because of selective display. */
6898 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6899 reseat_at_next_visible_line_start (it
, 0);
6900 else if (it
->cmp_it
.id
>= 0)
6902 /* We are currently getting glyphs from a composition. */
6907 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6908 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6909 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6911 it
->cmp_it
.from
= it
->cmp_it
.to
;
6916 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6918 it
->end_charpos
, Qnil
);
6921 else if (! it
->cmp_it
.reversed_p
)
6923 /* Composition created while scanning forward. */
6924 /* Update IT's char/byte positions to point to the first
6925 character of the next grapheme cluster, or to the
6926 character visually after the current composition. */
6927 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6928 bidi_move_to_visually_next (&it
->bidi_it
);
6929 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6930 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6932 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6934 /* Proceed to the next grapheme cluster. */
6935 it
->cmp_it
.from
= it
->cmp_it
.to
;
6939 /* No more grapheme clusters in this composition.
6940 Find the next stop position. */
6941 ptrdiff_t stop
= it
->end_charpos
;
6942 if (it
->bidi_it
.scan_dir
< 0)
6943 /* Now we are scanning backward and don't know
6946 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6947 IT_BYTEPOS (*it
), stop
, Qnil
);
6952 /* Composition created while scanning backward. */
6953 /* Update IT's char/byte positions to point to the last
6954 character of the previous grapheme cluster, or the
6955 character visually after the current composition. */
6956 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6957 bidi_move_to_visually_next (&it
->bidi_it
);
6958 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6959 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6960 if (it
->cmp_it
.from
> 0)
6962 /* Proceed to the previous grapheme cluster. */
6963 it
->cmp_it
.to
= it
->cmp_it
.from
;
6967 /* No more grapheme clusters in this composition.
6968 Find the next stop position. */
6969 ptrdiff_t stop
= it
->end_charpos
;
6970 if (it
->bidi_it
.scan_dir
< 0)
6971 /* Now we are scanning backward and don't know
6974 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6975 IT_BYTEPOS (*it
), stop
, Qnil
);
6981 xassert (it
->len
!= 0);
6985 IT_BYTEPOS (*it
) += it
->len
;
6986 IT_CHARPOS (*it
) += 1;
6990 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6991 /* If this is a new paragraph, determine its base
6992 direction (a.k.a. its base embedding level). */
6993 if (it
->bidi_it
.new_paragraph
)
6994 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6995 bidi_move_to_visually_next (&it
->bidi_it
);
6996 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6997 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6998 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7000 /* As the scan direction was changed, we must
7001 re-compute the stop position for composition. */
7002 ptrdiff_t stop
= it
->end_charpos
;
7003 if (it
->bidi_it
.scan_dir
< 0)
7005 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7006 IT_BYTEPOS (*it
), stop
, Qnil
);
7009 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7013 case GET_FROM_C_STRING
:
7014 /* Current display element of IT is from a C string. */
7016 /* If the string position is beyond string's end, it means
7017 next_element_from_c_string is padding the string with
7018 blanks, in which case we bypass the bidi iterator,
7019 because it cannot deal with such virtual characters. */
7020 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7022 IT_BYTEPOS (*it
) += it
->len
;
7023 IT_CHARPOS (*it
) += 1;
7027 bidi_move_to_visually_next (&it
->bidi_it
);
7028 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7029 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7033 case GET_FROM_DISPLAY_VECTOR
:
7034 /* Current display element of IT is from a display table entry.
7035 Advance in the display table definition. Reset it to null if
7036 end reached, and continue with characters from buffers/
7038 ++it
->current
.dpvec_index
;
7040 /* Restore face of the iterator to what they were before the
7041 display vector entry (these entries may contain faces). */
7042 it
->face_id
= it
->saved_face_id
;
7044 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7046 int recheck_faces
= it
->ellipsis_p
;
7049 it
->method
= GET_FROM_C_STRING
;
7050 else if (STRINGP (it
->string
))
7051 it
->method
= GET_FROM_STRING
;
7054 it
->method
= GET_FROM_BUFFER
;
7055 it
->object
= it
->w
->buffer
;
7059 it
->current
.dpvec_index
= -1;
7061 /* Skip over characters which were displayed via IT->dpvec. */
7062 if (it
->dpvec_char_len
< 0)
7063 reseat_at_next_visible_line_start (it
, 1);
7064 else if (it
->dpvec_char_len
> 0)
7066 if (it
->method
== GET_FROM_STRING
7067 && it
->n_overlay_strings
> 0)
7068 it
->ignore_overlay_strings_at_pos_p
= 1;
7069 it
->len
= it
->dpvec_char_len
;
7070 set_iterator_to_next (it
, reseat_p
);
7073 /* Maybe recheck faces after display vector */
7075 it
->stop_charpos
= IT_CHARPOS (*it
);
7079 case GET_FROM_STRING
:
7080 /* Current display element is a character from a Lisp string. */
7081 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
7082 /* Don't advance past string end. These conditions are true
7083 when set_iterator_to_next is called at the end of
7084 get_next_display_element, in which case the Lisp string is
7085 already exhausted, and all we want is pop the iterator
7087 if (it
->current
.overlay_string_index
>= 0)
7089 /* This is an overlay string, so there's no padding with
7090 spaces, and the number of characters in the string is
7091 where the string ends. */
7092 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7093 goto consider_string_end
;
7097 /* Not an overlay string. There could be padding, so test
7098 against it->end_charpos . */
7099 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7100 goto consider_string_end
;
7102 if (it
->cmp_it
.id
>= 0)
7108 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7109 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7110 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7111 it
->cmp_it
.from
= it
->cmp_it
.to
;
7115 composition_compute_stop_pos (&it
->cmp_it
,
7116 IT_STRING_CHARPOS (*it
),
7117 IT_STRING_BYTEPOS (*it
),
7118 it
->end_charpos
, it
->string
);
7121 else if (! it
->cmp_it
.reversed_p
)
7123 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7124 bidi_move_to_visually_next (&it
->bidi_it
);
7125 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7126 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7128 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7129 it
->cmp_it
.from
= it
->cmp_it
.to
;
7132 ptrdiff_t stop
= it
->end_charpos
;
7133 if (it
->bidi_it
.scan_dir
< 0)
7135 composition_compute_stop_pos (&it
->cmp_it
,
7136 IT_STRING_CHARPOS (*it
),
7137 IT_STRING_BYTEPOS (*it
), stop
,
7143 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7144 bidi_move_to_visually_next (&it
->bidi_it
);
7145 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7146 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7147 if (it
->cmp_it
.from
> 0)
7148 it
->cmp_it
.to
= it
->cmp_it
.from
;
7151 ptrdiff_t stop
= it
->end_charpos
;
7152 if (it
->bidi_it
.scan_dir
< 0)
7154 composition_compute_stop_pos (&it
->cmp_it
,
7155 IT_STRING_CHARPOS (*it
),
7156 IT_STRING_BYTEPOS (*it
), stop
,
7164 /* If the string position is beyond string's end, it
7165 means next_element_from_string is padding the string
7166 with blanks, in which case we bypass the bidi
7167 iterator, because it cannot deal with such virtual
7169 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7171 IT_STRING_BYTEPOS (*it
) += it
->len
;
7172 IT_STRING_CHARPOS (*it
) += 1;
7176 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7178 bidi_move_to_visually_next (&it
->bidi_it
);
7179 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7180 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7181 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7183 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
,
7195 consider_string_end
:
7197 if (it
->current
.overlay_string_index
>= 0)
7199 /* IT->string is an overlay string. Advance to the
7200 next, if there is one. */
7201 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7204 next_overlay_string (it
);
7206 setup_for_ellipsis (it
, 0);
7211 /* IT->string is not an overlay string. If we reached
7212 its end, and there is something on IT->stack, proceed
7213 with what is on the stack. This can be either another
7214 string, this time an overlay string, or a buffer. */
7215 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7219 if (it
->method
== GET_FROM_STRING
)
7220 goto consider_string_end
;
7225 case GET_FROM_IMAGE
:
7226 case GET_FROM_STRETCH
:
7227 /* The position etc with which we have to proceed are on
7228 the stack. The position may be at the end of a string,
7229 if the `display' property takes up the whole string. */
7230 xassert (it
->sp
> 0);
7232 if (it
->method
== GET_FROM_STRING
)
7233 goto consider_string_end
;
7237 /* There are no other methods defined, so this should be a bug. */
7241 xassert (it
->method
!= GET_FROM_STRING
7242 || (STRINGP (it
->string
)
7243 && IT_STRING_CHARPOS (*it
) >= 0));
7246 /* Load IT's display element fields with information about the next
7247 display element which comes from a display table entry or from the
7248 result of translating a control character to one of the forms `^C'
7251 IT->dpvec holds the glyphs to return as characters.
7252 IT->saved_face_id holds the face id before the display vector--it
7253 is restored into IT->face_id in set_iterator_to_next. */
7256 next_element_from_display_vector (struct it
*it
)
7261 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7263 it
->face_id
= it
->saved_face_id
;
7265 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7266 That seemed totally bogus - so I changed it... */
7267 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7269 if (GLYPH_CODE_P (gc
))
7271 it
->c
= GLYPH_CODE_CHAR (gc
);
7272 it
->len
= CHAR_BYTES (it
->c
);
7274 /* The entry may contain a face id to use. Such a face id is
7275 the id of a Lisp face, not a realized face. A face id of
7276 zero means no face is specified. */
7277 if (it
->dpvec_face_id
>= 0)
7278 it
->face_id
= it
->dpvec_face_id
;
7281 int lface_id
= GLYPH_CODE_FACE (gc
);
7283 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7288 /* Display table entry is invalid. Return a space. */
7289 it
->c
= ' ', it
->len
= 1;
7291 /* Don't change position and object of the iterator here. They are
7292 still the values of the character that had this display table
7293 entry or was translated, and that's what we want. */
7294 it
->what
= IT_CHARACTER
;
7298 /* Get the first element of string/buffer in the visual order, after
7299 being reseated to a new position in a string or a buffer. */
7301 get_visually_first_element (struct it
*it
)
7303 int string_p
= STRINGP (it
->string
) || it
->s
;
7304 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7305 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7307 if (STRINGP (it
->string
))
7309 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7310 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7314 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7315 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7318 if (it
->bidi_it
.charpos
== eob
)
7320 /* Nothing to do, but reset the FIRST_ELT flag, like
7321 bidi_paragraph_init does, because we are not going to
7323 it
->bidi_it
.first_elt
= 0;
7325 else if (it
->bidi_it
.charpos
== bob
7327 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7328 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7330 /* If we are at the beginning of a line/string, we can produce
7331 the next element right away. */
7332 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7333 bidi_move_to_visually_next (&it
->bidi_it
);
7337 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7339 /* We need to prime the bidi iterator starting at the line's or
7340 string's beginning, before we will be able to produce the
7343 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7346 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7348 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7350 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7353 /* Now return to buffer/string position where we were asked
7354 to get the next display element, and produce that. */
7355 bidi_move_to_visually_next (&it
->bidi_it
);
7357 while (it
->bidi_it
.bytepos
!= orig_bytepos
7358 && it
->bidi_it
.charpos
< eob
);
7361 /* Adjust IT's position information to where we ended up. */
7362 if (STRINGP (it
->string
))
7364 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7365 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7369 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7370 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7373 if (STRINGP (it
->string
) || !it
->s
)
7375 ptrdiff_t stop
, charpos
, bytepos
;
7377 if (STRINGP (it
->string
))
7380 stop
= SCHARS (it
->string
);
7381 if (stop
> it
->end_charpos
)
7382 stop
= it
->end_charpos
;
7383 charpos
= IT_STRING_CHARPOS (*it
);
7384 bytepos
= IT_STRING_BYTEPOS (*it
);
7388 stop
= it
->end_charpos
;
7389 charpos
= IT_CHARPOS (*it
);
7390 bytepos
= IT_BYTEPOS (*it
);
7392 if (it
->bidi_it
.scan_dir
< 0)
7394 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7399 /* Load IT with the next display element from Lisp string IT->string.
7400 IT->current.string_pos is the current position within the string.
7401 If IT->current.overlay_string_index >= 0, the Lisp string is an
7405 next_element_from_string (struct it
*it
)
7407 struct text_pos position
;
7409 xassert (STRINGP (it
->string
));
7410 xassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7411 xassert (IT_STRING_CHARPOS (*it
) >= 0);
7412 position
= it
->current
.string_pos
;
7414 /* With bidi reordering, the character to display might not be the
7415 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7416 that we were reseat()ed to a new string, whose paragraph
7417 direction is not known. */
7418 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7420 get_visually_first_element (it
);
7421 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7424 /* Time to check for invisible text? */
7425 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7427 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7430 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7431 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7433 /* With bidi non-linear iteration, we could find
7434 ourselves far beyond the last computed stop_charpos,
7435 with several other stop positions in between that we
7436 missed. Scan them all now, in buffer's logical
7437 order, until we find and handle the last stop_charpos
7438 that precedes our current position. */
7439 handle_stop_backwards (it
, it
->stop_charpos
);
7440 return GET_NEXT_DISPLAY_ELEMENT (it
);
7446 /* Take note of the stop position we just moved
7447 across, for when we will move back across it. */
7448 it
->prev_stop
= it
->stop_charpos
;
7449 /* If we are at base paragraph embedding level, take
7450 note of the last stop position seen at this
7452 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7453 it
->base_level_stop
= it
->stop_charpos
;
7457 /* Since a handler may have changed IT->method, we must
7459 return GET_NEXT_DISPLAY_ELEMENT (it
);
7463 /* If we are before prev_stop, we may have overstepped
7464 on our way backwards a stop_pos, and if so, we need
7465 to handle that stop_pos. */
7466 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7467 /* We can sometimes back up for reasons that have nothing
7468 to do with bidi reordering. E.g., compositions. The
7469 code below is only needed when we are above the base
7470 embedding level, so test for that explicitly. */
7471 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7473 /* If we lost track of base_level_stop, we have no better
7474 place for handle_stop_backwards to start from than string
7475 beginning. This happens, e.g., when we were reseated to
7476 the previous screenful of text by vertical-motion. */
7477 if (it
->base_level_stop
<= 0
7478 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7479 it
->base_level_stop
= 0;
7480 handle_stop_backwards (it
, it
->base_level_stop
);
7481 return GET_NEXT_DISPLAY_ELEMENT (it
);
7485 if (it
->current
.overlay_string_index
>= 0)
7487 /* Get the next character from an overlay string. In overlay
7488 strings, there is no field width or padding with spaces to
7490 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7495 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7496 IT_STRING_BYTEPOS (*it
),
7497 it
->bidi_it
.scan_dir
< 0
7499 : SCHARS (it
->string
))
7500 && next_element_from_composition (it
))
7504 else if (STRING_MULTIBYTE (it
->string
))
7506 const unsigned char *s
= (SDATA (it
->string
)
7507 + IT_STRING_BYTEPOS (*it
));
7508 it
->c
= string_char_and_length (s
, &it
->len
);
7512 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7518 /* Get the next character from a Lisp string that is not an
7519 overlay string. Such strings come from the mode line, for
7520 example. We may have to pad with spaces, or truncate the
7521 string. See also next_element_from_c_string. */
7522 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7527 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7529 /* Pad with spaces. */
7530 it
->c
= ' ', it
->len
= 1;
7531 CHARPOS (position
) = BYTEPOS (position
) = -1;
7533 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7534 IT_STRING_BYTEPOS (*it
),
7535 it
->bidi_it
.scan_dir
< 0
7537 : it
->string_nchars
)
7538 && next_element_from_composition (it
))
7542 else if (STRING_MULTIBYTE (it
->string
))
7544 const unsigned char *s
= (SDATA (it
->string
)
7545 + IT_STRING_BYTEPOS (*it
));
7546 it
->c
= string_char_and_length (s
, &it
->len
);
7550 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7555 /* Record what we have and where it came from. */
7556 it
->what
= IT_CHARACTER
;
7557 it
->object
= it
->string
;
7558 it
->position
= position
;
7563 /* Load IT with next display element from C string IT->s.
7564 IT->string_nchars is the maximum number of characters to return
7565 from the string. IT->end_charpos may be greater than
7566 IT->string_nchars when this function is called, in which case we
7567 may have to return padding spaces. Value is zero if end of string
7568 reached, including padding spaces. */
7571 next_element_from_c_string (struct it
*it
)
7576 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7577 it
->what
= IT_CHARACTER
;
7578 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7581 /* With bidi reordering, the character to display might not be the
7582 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7583 we were reseated to a new string, whose paragraph direction is
7585 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7586 get_visually_first_element (it
);
7588 /* IT's position can be greater than IT->string_nchars in case a
7589 field width or precision has been specified when the iterator was
7591 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7593 /* End of the game. */
7597 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7599 /* Pad with spaces. */
7600 it
->c
= ' ', it
->len
= 1;
7601 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7603 else if (it
->multibyte_p
)
7604 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7606 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7612 /* Set up IT to return characters from an ellipsis, if appropriate.
7613 The definition of the ellipsis glyphs may come from a display table
7614 entry. This function fills IT with the first glyph from the
7615 ellipsis if an ellipsis is to be displayed. */
7618 next_element_from_ellipsis (struct it
*it
)
7620 if (it
->selective_display_ellipsis_p
)
7621 setup_for_ellipsis (it
, it
->len
);
7624 /* The face at the current position may be different from the
7625 face we find after the invisible text. Remember what it
7626 was in IT->saved_face_id, and signal that it's there by
7627 setting face_before_selective_p. */
7628 it
->saved_face_id
= it
->face_id
;
7629 it
->method
= GET_FROM_BUFFER
;
7630 it
->object
= it
->w
->buffer
;
7631 reseat_at_next_visible_line_start (it
, 1);
7632 it
->face_before_selective_p
= 1;
7635 return GET_NEXT_DISPLAY_ELEMENT (it
);
7639 /* Deliver an image display element. The iterator IT is already
7640 filled with image information (done in handle_display_prop). Value
7645 next_element_from_image (struct it
*it
)
7647 it
->what
= IT_IMAGE
;
7648 it
->ignore_overlay_strings_at_pos_p
= 0;
7653 /* Fill iterator IT with next display element from a stretch glyph
7654 property. IT->object is the value of the text property. Value is
7658 next_element_from_stretch (struct it
*it
)
7660 it
->what
= IT_STRETCH
;
7664 /* Scan backwards from IT's current position until we find a stop
7665 position, or until BEGV. This is called when we find ourself
7666 before both the last known prev_stop and base_level_stop while
7667 reordering bidirectional text. */
7670 compute_stop_pos_backwards (struct it
*it
)
7672 const int SCAN_BACK_LIMIT
= 1000;
7673 struct text_pos pos
;
7674 struct display_pos save_current
= it
->current
;
7675 struct text_pos save_position
= it
->position
;
7676 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7677 ptrdiff_t where_we_are
= charpos
;
7678 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7679 ptrdiff_t save_end_pos
= it
->end_charpos
;
7681 xassert (NILP (it
->string
) && !it
->s
);
7682 xassert (it
->bidi_p
);
7686 it
->end_charpos
= min (charpos
+ 1, ZV
);
7687 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7688 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7689 reseat_1 (it
, pos
, 0);
7690 compute_stop_pos (it
);
7691 /* We must advance forward, right? */
7692 if (it
->stop_charpos
<= charpos
)
7695 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7697 if (it
->stop_charpos
<= where_we_are
)
7698 it
->prev_stop
= it
->stop_charpos
;
7700 it
->prev_stop
= BEGV
;
7702 it
->current
= save_current
;
7703 it
->position
= save_position
;
7704 it
->stop_charpos
= save_stop_pos
;
7705 it
->end_charpos
= save_end_pos
;
7708 /* Scan forward from CHARPOS in the current buffer/string, until we
7709 find a stop position > current IT's position. Then handle the stop
7710 position before that. This is called when we bump into a stop
7711 position while reordering bidirectional text. CHARPOS should be
7712 the last previously processed stop_pos (or BEGV/0, if none were
7713 processed yet) whose position is less that IT's current
7717 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7719 int bufp
= !STRINGP (it
->string
);
7720 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7721 struct display_pos save_current
= it
->current
;
7722 struct text_pos save_position
= it
->position
;
7723 struct text_pos pos1
;
7724 ptrdiff_t next_stop
;
7726 /* Scan in strict logical order. */
7727 xassert (it
->bidi_p
);
7731 it
->prev_stop
= charpos
;
7734 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7735 reseat_1 (it
, pos1
, 0);
7738 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7739 compute_stop_pos (it
);
7740 /* We must advance forward, right? */
7741 if (it
->stop_charpos
<= it
->prev_stop
)
7743 charpos
= it
->stop_charpos
;
7745 while (charpos
<= where_we_are
);
7748 it
->current
= save_current
;
7749 it
->position
= save_position
;
7750 next_stop
= it
->stop_charpos
;
7751 it
->stop_charpos
= it
->prev_stop
;
7753 it
->stop_charpos
= next_stop
;
7756 /* Load IT with the next display element from current_buffer. Value
7757 is zero if end of buffer reached. IT->stop_charpos is the next
7758 position at which to stop and check for text properties or buffer
7762 next_element_from_buffer (struct it
*it
)
7766 xassert (IT_CHARPOS (*it
) >= BEGV
);
7767 xassert (NILP (it
->string
) && !it
->s
);
7768 xassert (!it
->bidi_p
7769 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7770 && it
->bidi_it
.string
.s
== NULL
));
7772 /* With bidi reordering, the character to display might not be the
7773 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7774 we were reseat()ed to a new buffer position, which is potentially
7775 a different paragraph. */
7776 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7778 get_visually_first_element (it
);
7779 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7782 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7784 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7786 int overlay_strings_follow_p
;
7788 /* End of the game, except when overlay strings follow that
7789 haven't been returned yet. */
7790 if (it
->overlay_strings_at_end_processed_p
)
7791 overlay_strings_follow_p
= 0;
7794 it
->overlay_strings_at_end_processed_p
= 1;
7795 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7798 if (overlay_strings_follow_p
)
7799 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7803 it
->position
= it
->current
.pos
;
7807 else if (!(!it
->bidi_p
7808 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7809 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7811 /* With bidi non-linear iteration, we could find ourselves
7812 far beyond the last computed stop_charpos, with several
7813 other stop positions in between that we missed. Scan
7814 them all now, in buffer's logical order, until we find
7815 and handle the last stop_charpos that precedes our
7816 current position. */
7817 handle_stop_backwards (it
, it
->stop_charpos
);
7818 return GET_NEXT_DISPLAY_ELEMENT (it
);
7824 /* Take note of the stop position we just moved across,
7825 for when we will move back across it. */
7826 it
->prev_stop
= it
->stop_charpos
;
7827 /* If we are at base paragraph embedding level, take
7828 note of the last stop position seen at this
7830 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7831 it
->base_level_stop
= it
->stop_charpos
;
7834 return GET_NEXT_DISPLAY_ELEMENT (it
);
7838 /* If we are before prev_stop, we may have overstepped on
7839 our way backwards a stop_pos, and if so, we need to
7840 handle that stop_pos. */
7841 && IT_CHARPOS (*it
) < it
->prev_stop
7842 /* We can sometimes back up for reasons that have nothing
7843 to do with bidi reordering. E.g., compositions. The
7844 code below is only needed when we are above the base
7845 embedding level, so test for that explicitly. */
7846 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7848 if (it
->base_level_stop
<= 0
7849 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7851 /* If we lost track of base_level_stop, we need to find
7852 prev_stop by looking backwards. This happens, e.g., when
7853 we were reseated to the previous screenful of text by
7855 it
->base_level_stop
= BEGV
;
7856 compute_stop_pos_backwards (it
);
7857 handle_stop_backwards (it
, it
->prev_stop
);
7860 handle_stop_backwards (it
, it
->base_level_stop
);
7861 return GET_NEXT_DISPLAY_ELEMENT (it
);
7865 /* No face changes, overlays etc. in sight, so just return a
7866 character from current_buffer. */
7870 /* Maybe run the redisplay end trigger hook. Performance note:
7871 This doesn't seem to cost measurable time. */
7872 if (it
->redisplay_end_trigger_charpos
7874 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7875 run_redisplay_end_trigger_hook (it
);
7877 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7878 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7880 && next_element_from_composition (it
))
7885 /* Get the next character, maybe multibyte. */
7886 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7887 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7888 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7890 it
->c
= *p
, it
->len
= 1;
7892 /* Record what we have and where it came from. */
7893 it
->what
= IT_CHARACTER
;
7894 it
->object
= it
->w
->buffer
;
7895 it
->position
= it
->current
.pos
;
7897 /* Normally we return the character found above, except when we
7898 really want to return an ellipsis for selective display. */
7903 /* A value of selective > 0 means hide lines indented more
7904 than that number of columns. */
7905 if (it
->selective
> 0
7906 && IT_CHARPOS (*it
) + 1 < ZV
7907 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7908 IT_BYTEPOS (*it
) + 1,
7911 success_p
= next_element_from_ellipsis (it
);
7912 it
->dpvec_char_len
= -1;
7915 else if (it
->c
== '\r' && it
->selective
== -1)
7917 /* A value of selective == -1 means that everything from the
7918 CR to the end of the line is invisible, with maybe an
7919 ellipsis displayed for it. */
7920 success_p
= next_element_from_ellipsis (it
);
7921 it
->dpvec_char_len
= -1;
7926 /* Value is zero if end of buffer reached. */
7927 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7932 /* Run the redisplay end trigger hook for IT. */
7935 run_redisplay_end_trigger_hook (struct it
*it
)
7937 Lisp_Object args
[3];
7939 /* IT->glyph_row should be non-null, i.e. we should be actually
7940 displaying something, or otherwise we should not run the hook. */
7941 xassert (it
->glyph_row
);
7943 /* Set up hook arguments. */
7944 args
[0] = Qredisplay_end_trigger_functions
;
7945 args
[1] = it
->window
;
7946 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7947 it
->redisplay_end_trigger_charpos
= 0;
7949 /* Since we are *trying* to run these functions, don't try to run
7950 them again, even if they get an error. */
7951 it
->w
->redisplay_end_trigger
= Qnil
;
7952 Frun_hook_with_args (3, args
);
7954 /* Notice if it changed the face of the character we are on. */
7955 handle_face_prop (it
);
7959 /* Deliver a composition display element. Unlike the other
7960 next_element_from_XXX, this function is not registered in the array
7961 get_next_element[]. It is called from next_element_from_buffer and
7962 next_element_from_string when necessary. */
7965 next_element_from_composition (struct it
*it
)
7967 it
->what
= IT_COMPOSITION
;
7968 it
->len
= it
->cmp_it
.nbytes
;
7969 if (STRINGP (it
->string
))
7973 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7974 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7977 it
->position
= it
->current
.string_pos
;
7978 it
->object
= it
->string
;
7979 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7980 IT_STRING_BYTEPOS (*it
), it
->string
);
7986 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7987 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7990 if (it
->bidi_it
.new_paragraph
)
7991 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7992 /* Resync the bidi iterator with IT's new position.
7993 FIXME: this doesn't support bidirectional text. */
7994 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7995 bidi_move_to_visually_next (&it
->bidi_it
);
7999 it
->position
= it
->current
.pos
;
8000 it
->object
= it
->w
->buffer
;
8001 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8002 IT_BYTEPOS (*it
), Qnil
);
8009 /***********************************************************************
8010 Moving an iterator without producing glyphs
8011 ***********************************************************************/
8013 /* Check if iterator is at a position corresponding to a valid buffer
8014 position after some move_it_ call. */
8016 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8017 ((it)->method == GET_FROM_STRING \
8018 ? IT_STRING_CHARPOS (*it) == 0 \
8022 /* Move iterator IT to a specified buffer or X position within one
8023 line on the display without producing glyphs.
8025 OP should be a bit mask including some or all of these bits:
8026 MOVE_TO_X: Stop upon reaching x-position TO_X.
8027 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8028 Regardless of OP's value, stop upon reaching the end of the display line.
8030 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8031 This means, in particular, that TO_X includes window's horizontal
8034 The return value has several possible values that
8035 say what condition caused the scan to stop:
8037 MOVE_POS_MATCH_OR_ZV
8038 - when TO_POS or ZV was reached.
8041 -when TO_X was reached before TO_POS or ZV were reached.
8044 - when we reached the end of the display area and the line must
8048 - when we reached the end of the display area and the line is
8052 - when we stopped at a line end, i.e. a newline or a CR and selective
8055 static enum move_it_result
8056 move_it_in_display_line_to (struct it
*it
,
8057 ptrdiff_t to_charpos
, int to_x
,
8058 enum move_operation_enum op
)
8060 enum move_it_result result
= MOVE_UNDEFINED
;
8061 struct glyph_row
*saved_glyph_row
;
8062 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8063 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8064 void *ppos_data
= NULL
;
8066 enum it_method prev_method
= it
->method
;
8067 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8068 int saw_smaller_pos
= prev_pos
< to_charpos
;
8070 /* Don't produce glyphs in produce_glyphs. */
8071 saved_glyph_row
= it
->glyph_row
;
8072 it
->glyph_row
= NULL
;
8074 /* Use wrap_it to save a copy of IT wherever a word wrap could
8075 occur. Use atpos_it to save a copy of IT at the desired buffer
8076 position, if found, so that we can scan ahead and check if the
8077 word later overshoots the window edge. Use atx_it similarly, for
8083 /* Use ppos_it under bidi reordering to save a copy of IT for the
8084 position > CHARPOS that is the closest to CHARPOS. We restore
8085 that position in IT when we have scanned the entire display line
8086 without finding a match for CHARPOS and all the character
8087 positions are greater than CHARPOS. */
8090 SAVE_IT (ppos_it
, *it
, ppos_data
);
8091 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8092 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8093 SAVE_IT (ppos_it
, *it
, ppos_data
);
8096 #define BUFFER_POS_REACHED_P() \
8097 ((op & MOVE_TO_POS) != 0 \
8098 && BUFFERP (it->object) \
8099 && (IT_CHARPOS (*it) == to_charpos \
8101 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8102 && IT_CHARPOS (*it) > to_charpos) \
8103 || (it->what == IT_COMPOSITION \
8104 && ((IT_CHARPOS (*it) > to_charpos \
8105 && to_charpos >= it->cmp_it.charpos) \
8106 || (IT_CHARPOS (*it) < to_charpos \
8107 && to_charpos <= it->cmp_it.charpos)))) \
8108 && (it->method == GET_FROM_BUFFER \
8109 || (it->method == GET_FROM_DISPLAY_VECTOR \
8110 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8112 /* If there's a line-/wrap-prefix, handle it. */
8113 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8114 && it
->current_y
< it
->last_visible_y
)
8115 handle_line_prefix (it
);
8117 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8118 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8122 int x
, i
, ascent
= 0, descent
= 0;
8124 /* Utility macro to reset an iterator with x, ascent, and descent. */
8125 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8126 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8127 (IT)->max_descent = descent)
8129 /* Stop if we move beyond TO_CHARPOS (after an image or a
8130 display string or stretch glyph). */
8131 if ((op
& MOVE_TO_POS
) != 0
8132 && BUFFERP (it
->object
)
8133 && it
->method
== GET_FROM_BUFFER
8135 /* When the iterator is at base embedding level, we
8136 are guaranteed that characters are delivered for
8137 display in strictly increasing order of their
8138 buffer positions. */
8139 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8140 && IT_CHARPOS (*it
) > to_charpos
)
8142 && (prev_method
== GET_FROM_IMAGE
8143 || prev_method
== GET_FROM_STRETCH
8144 || prev_method
== GET_FROM_STRING
)
8145 /* Passed TO_CHARPOS from left to right. */
8146 && ((prev_pos
< to_charpos
8147 && IT_CHARPOS (*it
) > to_charpos
)
8148 /* Passed TO_CHARPOS from right to left. */
8149 || (prev_pos
> to_charpos
8150 && IT_CHARPOS (*it
) < to_charpos
)))))
8152 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8154 result
= MOVE_POS_MATCH_OR_ZV
;
8157 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8158 /* If wrap_it is valid, the current position might be in a
8159 word that is wrapped. So, save the iterator in
8160 atpos_it and continue to see if wrapping happens. */
8161 SAVE_IT (atpos_it
, *it
, atpos_data
);
8164 /* Stop when ZV reached.
8165 We used to stop here when TO_CHARPOS reached as well, but that is
8166 too soon if this glyph does not fit on this line. So we handle it
8167 explicitly below. */
8168 if (!get_next_display_element (it
))
8170 result
= MOVE_POS_MATCH_OR_ZV
;
8174 if (it
->line_wrap
== TRUNCATE
)
8176 if (BUFFER_POS_REACHED_P ())
8178 result
= MOVE_POS_MATCH_OR_ZV
;
8184 if (it
->line_wrap
== WORD_WRAP
)
8186 if (IT_DISPLAYING_WHITESPACE (it
))
8190 /* We have reached a glyph that follows one or more
8191 whitespace characters. If the position is
8192 already found, we are done. */
8193 if (atpos_it
.sp
>= 0)
8195 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8196 result
= MOVE_POS_MATCH_OR_ZV
;
8201 RESTORE_IT (it
, &atx_it
, atx_data
);
8202 result
= MOVE_X_REACHED
;
8205 /* Otherwise, we can wrap here. */
8206 SAVE_IT (wrap_it
, *it
, wrap_data
);
8212 /* Remember the line height for the current line, in case
8213 the next element doesn't fit on the line. */
8214 ascent
= it
->max_ascent
;
8215 descent
= it
->max_descent
;
8217 /* The call to produce_glyphs will get the metrics of the
8218 display element IT is loaded with. Record the x-position
8219 before this display element, in case it doesn't fit on the
8223 PRODUCE_GLYPHS (it
);
8225 if (it
->area
!= TEXT_AREA
)
8227 prev_method
= it
->method
;
8228 if (it
->method
== GET_FROM_BUFFER
)
8229 prev_pos
= IT_CHARPOS (*it
);
8230 set_iterator_to_next (it
, 1);
8231 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8232 SET_TEXT_POS (this_line_min_pos
,
8233 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8235 && (op
& MOVE_TO_POS
)
8236 && IT_CHARPOS (*it
) > to_charpos
8237 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8238 SAVE_IT (ppos_it
, *it
, ppos_data
);
8242 /* The number of glyphs we get back in IT->nglyphs will normally
8243 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8244 character on a terminal frame, or (iii) a line end. For the
8245 second case, IT->nglyphs - 1 padding glyphs will be present.
8246 (On X frames, there is only one glyph produced for a
8247 composite character.)
8249 The behavior implemented below means, for continuation lines,
8250 that as many spaces of a TAB as fit on the current line are
8251 displayed there. For terminal frames, as many glyphs of a
8252 multi-glyph character are displayed in the current line, too.
8253 This is what the old redisplay code did, and we keep it that
8254 way. Under X, the whole shape of a complex character must
8255 fit on the line or it will be completely displayed in the
8258 Note that both for tabs and padding glyphs, all glyphs have
8262 /* More than one glyph or glyph doesn't fit on line. All
8263 glyphs have the same width. */
8264 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8266 int x_before_this_char
= x
;
8267 int hpos_before_this_char
= it
->hpos
;
8269 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8271 new_x
= x
+ single_glyph_width
;
8273 /* We want to leave anything reaching TO_X to the caller. */
8274 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8276 if (BUFFER_POS_REACHED_P ())
8278 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8279 goto buffer_pos_reached
;
8280 if (atpos_it
.sp
< 0)
8282 SAVE_IT (atpos_it
, *it
, atpos_data
);
8283 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8288 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8291 result
= MOVE_X_REACHED
;
8296 SAVE_IT (atx_it
, *it
, atx_data
);
8297 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8302 if (/* Lines are continued. */
8303 it
->line_wrap
!= TRUNCATE
8304 && (/* And glyph doesn't fit on the line. */
8305 new_x
> it
->last_visible_x
8306 /* Or it fits exactly and we're on a window
8308 || (new_x
== it
->last_visible_x
8309 && FRAME_WINDOW_P (it
->f
))))
8311 if (/* IT->hpos == 0 means the very first glyph
8312 doesn't fit on the line, e.g. a wide image. */
8314 || (new_x
== it
->last_visible_x
8315 && FRAME_WINDOW_P (it
->f
)))
8318 it
->current_x
= new_x
;
8320 /* The character's last glyph just barely fits
8322 if (i
== it
->nglyphs
- 1)
8324 /* If this is the destination position,
8325 return a position *before* it in this row,
8326 now that we know it fits in this row. */
8327 if (BUFFER_POS_REACHED_P ())
8329 if (it
->line_wrap
!= WORD_WRAP
8332 it
->hpos
= hpos_before_this_char
;
8333 it
->current_x
= x_before_this_char
;
8334 result
= MOVE_POS_MATCH_OR_ZV
;
8337 if (it
->line_wrap
== WORD_WRAP
8340 SAVE_IT (atpos_it
, *it
, atpos_data
);
8341 atpos_it
.current_x
= x_before_this_char
;
8342 atpos_it
.hpos
= hpos_before_this_char
;
8346 prev_method
= it
->method
;
8347 if (it
->method
== GET_FROM_BUFFER
)
8348 prev_pos
= IT_CHARPOS (*it
);
8349 set_iterator_to_next (it
, 1);
8350 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8351 SET_TEXT_POS (this_line_min_pos
,
8352 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8353 /* On graphical terminals, newlines may
8354 "overflow" into the fringe if
8355 overflow-newline-into-fringe is non-nil.
8356 On text-only terminals, newlines may
8357 overflow into the last glyph on the
8359 if (!FRAME_WINDOW_P (it
->f
)
8360 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8362 if (!get_next_display_element (it
))
8364 result
= MOVE_POS_MATCH_OR_ZV
;
8367 if (BUFFER_POS_REACHED_P ())
8369 if (ITERATOR_AT_END_OF_LINE_P (it
))
8370 result
= MOVE_POS_MATCH_OR_ZV
;
8372 result
= MOVE_LINE_CONTINUED
;
8375 if (ITERATOR_AT_END_OF_LINE_P (it
))
8377 result
= MOVE_NEWLINE_OR_CR
;
8384 IT_RESET_X_ASCENT_DESCENT (it
);
8386 if (wrap_it
.sp
>= 0)
8388 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8393 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8395 result
= MOVE_LINE_CONTINUED
;
8399 if (BUFFER_POS_REACHED_P ())
8401 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8402 goto buffer_pos_reached
;
8403 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8405 SAVE_IT (atpos_it
, *it
, atpos_data
);
8406 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8410 if (new_x
> it
->first_visible_x
)
8412 /* Glyph is visible. Increment number of glyphs that
8413 would be displayed. */
8418 if (result
!= MOVE_UNDEFINED
)
8421 else if (BUFFER_POS_REACHED_P ())
8424 IT_RESET_X_ASCENT_DESCENT (it
);
8425 result
= MOVE_POS_MATCH_OR_ZV
;
8428 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8430 /* Stop when TO_X specified and reached. This check is
8431 necessary here because of lines consisting of a line end,
8432 only. The line end will not produce any glyphs and we
8433 would never get MOVE_X_REACHED. */
8434 xassert (it
->nglyphs
== 0);
8435 result
= MOVE_X_REACHED
;
8439 /* Is this a line end? If yes, we're done. */
8440 if (ITERATOR_AT_END_OF_LINE_P (it
))
8442 /* If we are past TO_CHARPOS, but never saw any character
8443 positions smaller than TO_CHARPOS, return
8444 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8446 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8448 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8450 if (IT_CHARPOS (ppos_it
) < ZV
)
8452 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8453 result
= MOVE_POS_MATCH_OR_ZV
;
8456 goto buffer_pos_reached
;
8458 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8459 && IT_CHARPOS (*it
) > to_charpos
)
8460 goto buffer_pos_reached
;
8462 result
= MOVE_NEWLINE_OR_CR
;
8465 result
= MOVE_NEWLINE_OR_CR
;
8469 prev_method
= it
->method
;
8470 if (it
->method
== GET_FROM_BUFFER
)
8471 prev_pos
= IT_CHARPOS (*it
);
8472 /* The current display element has been consumed. Advance
8474 set_iterator_to_next (it
, 1);
8475 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8476 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8477 if (IT_CHARPOS (*it
) < to_charpos
)
8478 saw_smaller_pos
= 1;
8480 && (op
& MOVE_TO_POS
)
8481 && IT_CHARPOS (*it
) >= to_charpos
8482 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8483 SAVE_IT (ppos_it
, *it
, ppos_data
);
8485 /* Stop if lines are truncated and IT's current x-position is
8486 past the right edge of the window now. */
8487 if (it
->line_wrap
== TRUNCATE
8488 && it
->current_x
>= it
->last_visible_x
)
8490 if (!FRAME_WINDOW_P (it
->f
)
8491 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8495 if ((at_eob_p
= !get_next_display_element (it
))
8496 || BUFFER_POS_REACHED_P ()
8497 /* If we are past TO_CHARPOS, but never saw any
8498 character positions smaller than TO_CHARPOS,
8499 return MOVE_POS_MATCH_OR_ZV, like the
8500 unidirectional display did. */
8501 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8503 && IT_CHARPOS (*it
) > to_charpos
))
8506 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8507 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8508 result
= MOVE_POS_MATCH_OR_ZV
;
8511 if (ITERATOR_AT_END_OF_LINE_P (it
))
8513 result
= MOVE_NEWLINE_OR_CR
;
8517 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8519 && IT_CHARPOS (*it
) > to_charpos
)
8521 if (IT_CHARPOS (ppos_it
) < ZV
)
8522 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8523 result
= MOVE_POS_MATCH_OR_ZV
;
8526 result
= MOVE_LINE_TRUNCATED
;
8529 #undef IT_RESET_X_ASCENT_DESCENT
8532 #undef BUFFER_POS_REACHED_P
8534 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8535 restore the saved iterator. */
8536 if (atpos_it
.sp
>= 0)
8537 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8538 else if (atx_it
.sp
>= 0)
8539 RESTORE_IT (it
, &atx_it
, atx_data
);
8544 bidi_unshelve_cache (atpos_data
, 1);
8546 bidi_unshelve_cache (atx_data
, 1);
8548 bidi_unshelve_cache (wrap_data
, 1);
8550 bidi_unshelve_cache (ppos_data
, 1);
8552 /* Restore the iterator settings altered at the beginning of this
8554 it
->glyph_row
= saved_glyph_row
;
8558 /* For external use. */
8560 move_it_in_display_line (struct it
*it
,
8561 ptrdiff_t to_charpos
, int to_x
,
8562 enum move_operation_enum op
)
8564 if (it
->line_wrap
== WORD_WRAP
8565 && (op
& MOVE_TO_X
))
8568 void *save_data
= NULL
;
8571 SAVE_IT (save_it
, *it
, save_data
);
8572 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8573 /* When word-wrap is on, TO_X may lie past the end
8574 of a wrapped line. Then it->current is the
8575 character on the next line, so backtrack to the
8576 space before the wrap point. */
8577 if (skip
== MOVE_LINE_CONTINUED
)
8579 int prev_x
= max (it
->current_x
- 1, 0);
8580 RESTORE_IT (it
, &save_it
, save_data
);
8581 move_it_in_display_line_to
8582 (it
, -1, prev_x
, MOVE_TO_X
);
8585 bidi_unshelve_cache (save_data
, 1);
8588 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8592 /* Move IT forward until it satisfies one or more of the criteria in
8593 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8595 OP is a bit-mask that specifies where to stop, and in particular,
8596 which of those four position arguments makes a difference. See the
8597 description of enum move_operation_enum.
8599 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8600 screen line, this function will set IT to the next position that is
8601 displayed to the right of TO_CHARPOS on the screen. */
8604 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8606 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8607 int line_height
, line_start_x
= 0, reached
= 0;
8608 void *backup_data
= NULL
;
8612 if (op
& MOVE_TO_VPOS
)
8614 /* If no TO_CHARPOS and no TO_X specified, stop at the
8615 start of the line TO_VPOS. */
8616 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8618 if (it
->vpos
== to_vpos
)
8624 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8628 /* TO_VPOS >= 0 means stop at TO_X in the line at
8629 TO_VPOS, or at TO_POS, whichever comes first. */
8630 if (it
->vpos
== to_vpos
)
8636 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8638 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8643 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8645 /* We have reached TO_X but not in the line we want. */
8646 skip
= move_it_in_display_line_to (it
, to_charpos
,
8648 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8656 else if (op
& MOVE_TO_Y
)
8658 struct it it_backup
;
8660 if (it
->line_wrap
== WORD_WRAP
)
8661 SAVE_IT (it_backup
, *it
, backup_data
);
8663 /* TO_Y specified means stop at TO_X in the line containing
8664 TO_Y---or at TO_CHARPOS if this is reached first. The
8665 problem is that we can't really tell whether the line
8666 contains TO_Y before we have completely scanned it, and
8667 this may skip past TO_X. What we do is to first scan to
8670 If TO_X is not specified, use a TO_X of zero. The reason
8671 is to make the outcome of this function more predictable.
8672 If we didn't use TO_X == 0, we would stop at the end of
8673 the line which is probably not what a caller would expect
8675 skip
= move_it_in_display_line_to
8676 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8677 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8679 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8680 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8682 else if (skip
== MOVE_X_REACHED
)
8684 /* If TO_X was reached, we want to know whether TO_Y is
8685 in the line. We know this is the case if the already
8686 scanned glyphs make the line tall enough. Otherwise,
8687 we must check by scanning the rest of the line. */
8688 line_height
= it
->max_ascent
+ it
->max_descent
;
8689 if (to_y
>= it
->current_y
8690 && to_y
< it
->current_y
+ line_height
)
8695 SAVE_IT (it_backup
, *it
, backup_data
);
8696 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8697 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8699 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8700 line_height
= it
->max_ascent
+ it
->max_descent
;
8701 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8703 if (to_y
>= it
->current_y
8704 && to_y
< it
->current_y
+ line_height
)
8706 /* If TO_Y is in this line and TO_X was reached
8707 above, we scanned too far. We have to restore
8708 IT's settings to the ones before skipping. But
8709 keep the more accurate values of max_ascent and
8710 max_descent we've found while skipping the rest
8711 of the line, for the sake of callers, such as
8712 pos_visible_p, that need to know the line
8714 int max_ascent
= it
->max_ascent
;
8715 int max_descent
= it
->max_descent
;
8717 RESTORE_IT (it
, &it_backup
, backup_data
);
8718 it
->max_ascent
= max_ascent
;
8719 it
->max_descent
= max_descent
;
8725 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8731 /* Check whether TO_Y is in this line. */
8732 line_height
= it
->max_ascent
+ it
->max_descent
;
8733 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8735 if (to_y
>= it
->current_y
8736 && to_y
< it
->current_y
+ line_height
)
8738 /* When word-wrap is on, TO_X may lie past the end
8739 of a wrapped line. Then it->current is the
8740 character on the next line, so backtrack to the
8741 space before the wrap point. */
8742 if (skip
== MOVE_LINE_CONTINUED
8743 && it
->line_wrap
== WORD_WRAP
)
8745 int prev_x
= max (it
->current_x
- 1, 0);
8746 RESTORE_IT (it
, &it_backup
, backup_data
);
8747 skip
= move_it_in_display_line_to
8748 (it
, -1, prev_x
, MOVE_TO_X
);
8757 else if (BUFFERP (it
->object
)
8758 && (it
->method
== GET_FROM_BUFFER
8759 || it
->method
== GET_FROM_STRETCH
)
8760 && IT_CHARPOS (*it
) >= to_charpos
8761 /* Under bidi iteration, a call to set_iterator_to_next
8762 can scan far beyond to_charpos if the initial
8763 portion of the next line needs to be reordered. In
8764 that case, give move_it_in_display_line_to another
8767 && it
->bidi_it
.scan_dir
== -1))
8768 skip
= MOVE_POS_MATCH_OR_ZV
;
8770 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8774 case MOVE_POS_MATCH_OR_ZV
:
8778 case MOVE_NEWLINE_OR_CR
:
8779 set_iterator_to_next (it
, 1);
8780 it
->continuation_lines_width
= 0;
8783 case MOVE_LINE_TRUNCATED
:
8784 it
->continuation_lines_width
= 0;
8785 reseat_at_next_visible_line_start (it
, 0);
8786 if ((op
& MOVE_TO_POS
) != 0
8787 && IT_CHARPOS (*it
) > to_charpos
)
8794 case MOVE_LINE_CONTINUED
:
8795 /* For continued lines ending in a tab, some of the glyphs
8796 associated with the tab are displayed on the current
8797 line. Since it->current_x does not include these glyphs,
8798 we use it->last_visible_x instead. */
8801 it
->continuation_lines_width
+= it
->last_visible_x
;
8802 /* When moving by vpos, ensure that the iterator really
8803 advances to the next line (bug#847, bug#969). Fixme:
8804 do we need to do this in other circumstances? */
8805 if (it
->current_x
!= it
->last_visible_x
8806 && (op
& MOVE_TO_VPOS
)
8807 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8809 line_start_x
= it
->current_x
+ it
->pixel_width
8810 - it
->last_visible_x
;
8811 set_iterator_to_next (it
, 0);
8815 it
->continuation_lines_width
+= it
->current_x
;
8822 /* Reset/increment for the next run. */
8823 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8824 it
->current_x
= line_start_x
;
8827 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8829 last_height
= it
->max_ascent
+ it
->max_descent
;
8830 last_max_ascent
= it
->max_ascent
;
8831 it
->max_ascent
= it
->max_descent
= 0;
8836 /* On text terminals, we may stop at the end of a line in the middle
8837 of a multi-character glyph. If the glyph itself is continued,
8838 i.e. it is actually displayed on the next line, don't treat this
8839 stopping point as valid; move to the next line instead (unless
8840 that brings us offscreen). */
8841 if (!FRAME_WINDOW_P (it
->f
)
8843 && IT_CHARPOS (*it
) == to_charpos
8844 && it
->what
== IT_CHARACTER
8846 && it
->line_wrap
== WINDOW_WRAP
8847 && it
->current_x
== it
->last_visible_x
- 1
8850 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8852 it
->continuation_lines_width
+= it
->current_x
;
8853 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8854 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8856 last_height
= it
->max_ascent
+ it
->max_descent
;
8857 last_max_ascent
= it
->max_ascent
;
8861 bidi_unshelve_cache (backup_data
, 1);
8863 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8867 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8869 If DY > 0, move IT backward at least that many pixels. DY = 0
8870 means move IT backward to the preceding line start or BEGV. This
8871 function may move over more than DY pixels if IT->current_y - DY
8872 ends up in the middle of a line; in this case IT->current_y will be
8873 set to the top of the line moved to. */
8876 move_it_vertically_backward (struct it
*it
, int dy
)
8880 void *it2data
= NULL
, *it3data
= NULL
;
8881 ptrdiff_t start_pos
;
8886 start_pos
= IT_CHARPOS (*it
);
8888 /* Estimate how many newlines we must move back. */
8889 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8891 /* Set the iterator's position that many lines back. */
8892 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8893 back_to_previous_visible_line_start (it
);
8895 /* Reseat the iterator here. When moving backward, we don't want
8896 reseat to skip forward over invisible text, set up the iterator
8897 to deliver from overlay strings at the new position etc. So,
8898 use reseat_1 here. */
8899 reseat_1 (it
, it
->current
.pos
, 1);
8901 /* We are now surely at a line start. */
8902 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8903 reordering is in effect. */
8904 it
->continuation_lines_width
= 0;
8906 /* Move forward and see what y-distance we moved. First move to the
8907 start of the next line so that we get its height. We need this
8908 height to be able to tell whether we reached the specified
8910 SAVE_IT (it2
, *it
, it2data
);
8911 it2
.max_ascent
= it2
.max_descent
= 0;
8914 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8915 MOVE_TO_POS
| MOVE_TO_VPOS
);
8917 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8918 /* If we are in a display string which starts at START_POS,
8919 and that display string includes a newline, and we are
8920 right after that newline (i.e. at the beginning of a
8921 display line), exit the loop, because otherwise we will
8922 infloop, since move_it_to will see that it is already at
8923 START_POS and will not move. */
8924 || (it2
.method
== GET_FROM_STRING
8925 && IT_CHARPOS (it2
) == start_pos
8926 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8927 xassert (IT_CHARPOS (*it
) >= BEGV
);
8928 SAVE_IT (it3
, it2
, it3data
);
8930 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8931 xassert (IT_CHARPOS (*it
) >= BEGV
);
8932 /* H is the actual vertical distance from the position in *IT
8933 and the starting position. */
8934 h
= it2
.current_y
- it
->current_y
;
8935 /* NLINES is the distance in number of lines. */
8936 nlines
= it2
.vpos
- it
->vpos
;
8938 /* Correct IT's y and vpos position
8939 so that they are relative to the starting point. */
8945 /* DY == 0 means move to the start of the screen line. The
8946 value of nlines is > 0 if continuation lines were involved,
8947 or if the original IT position was at start of a line. */
8948 RESTORE_IT (it
, it
, it2data
);
8950 move_it_by_lines (it
, nlines
);
8951 /* The above code moves us to some position NLINES down,
8952 usually to its first glyph (leftmost in an L2R line), but
8953 that's not necessarily the start of the line, under bidi
8954 reordering. We want to get to the character position
8955 that is immediately after the newline of the previous
8958 && !it
->continuation_lines_width
8959 && !STRINGP (it
->string
)
8960 && IT_CHARPOS (*it
) > BEGV
8961 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8964 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8966 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8968 bidi_unshelve_cache (it3data
, 1);
8972 /* The y-position we try to reach, relative to *IT.
8973 Note that H has been subtracted in front of the if-statement. */
8974 int target_y
= it
->current_y
+ h
- dy
;
8975 int y0
= it3
.current_y
;
8979 RESTORE_IT (&it3
, &it3
, it3data
);
8980 y1
= line_bottom_y (&it3
);
8981 line_height
= y1
- y0
;
8982 RESTORE_IT (it
, it
, it2data
);
8983 /* If we did not reach target_y, try to move further backward if
8984 we can. If we moved too far backward, try to move forward. */
8985 if (target_y
< it
->current_y
8986 /* This is heuristic. In a window that's 3 lines high, with
8987 a line height of 13 pixels each, recentering with point
8988 on the bottom line will try to move -39/2 = 19 pixels
8989 backward. Try to avoid moving into the first line. */
8990 && (it
->current_y
- target_y
8991 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8992 && IT_CHARPOS (*it
) > BEGV
)
8994 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8995 target_y
- it
->current_y
));
8996 dy
= it
->current_y
- target_y
;
8997 goto move_further_back
;
8999 else if (target_y
>= it
->current_y
+ line_height
9000 && IT_CHARPOS (*it
) < ZV
)
9002 /* Should move forward by at least one line, maybe more.
9004 Note: Calling move_it_by_lines can be expensive on
9005 terminal frames, where compute_motion is used (via
9006 vmotion) to do the job, when there are very long lines
9007 and truncate-lines is nil. That's the reason for
9008 treating terminal frames specially here. */
9010 if (!FRAME_WINDOW_P (it
->f
))
9011 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9016 move_it_by_lines (it
, 1);
9018 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9025 /* Move IT by a specified amount of pixel lines DY. DY negative means
9026 move backwards. DY = 0 means move to start of screen line. At the
9027 end, IT will be on the start of a screen line. */
9030 move_it_vertically (struct it
*it
, int dy
)
9033 move_it_vertically_backward (it
, -dy
);
9036 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9037 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9038 MOVE_TO_POS
| MOVE_TO_Y
);
9039 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9041 /* If buffer ends in ZV without a newline, move to the start of
9042 the line to satisfy the post-condition. */
9043 if (IT_CHARPOS (*it
) == ZV
9045 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9046 move_it_by_lines (it
, 0);
9051 /* Move iterator IT past the end of the text line it is in. */
9054 move_it_past_eol (struct it
*it
)
9056 enum move_it_result rc
;
9058 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9059 if (rc
== MOVE_NEWLINE_OR_CR
)
9060 set_iterator_to_next (it
, 0);
9064 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9065 negative means move up. DVPOS == 0 means move to the start of the
9068 Optimization idea: If we would know that IT->f doesn't use
9069 a face with proportional font, we could be faster for
9070 truncate-lines nil. */
9073 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9076 /* The commented-out optimization uses vmotion on terminals. This
9077 gives bad results, because elements like it->what, on which
9078 callers such as pos_visible_p rely, aren't updated. */
9079 /* struct position pos;
9080 if (!FRAME_WINDOW_P (it->f))
9082 struct text_pos textpos;
9084 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9085 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9086 reseat (it, textpos, 1);
9087 it->vpos += pos.vpos;
9088 it->current_y += pos.vpos;
9094 /* DVPOS == 0 means move to the start of the screen line. */
9095 move_it_vertically_backward (it
, 0);
9096 /* Let next call to line_bottom_y calculate real line height */
9101 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9102 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9104 /* Only move to the next buffer position if we ended up in a
9105 string from display property, not in an overlay string
9106 (before-string or after-string). That is because the
9107 latter don't conceal the underlying buffer position, so
9108 we can ask to move the iterator to the exact position we
9109 are interested in. Note that, even if we are already at
9110 IT_CHARPOS (*it), the call below is not a no-op, as it
9111 will detect that we are at the end of the string, pop the
9112 iterator, and compute it->current_x and it->hpos
9114 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9115 -1, -1, -1, MOVE_TO_POS
);
9121 void *it2data
= NULL
;
9122 ptrdiff_t start_charpos
, i
;
9124 /* Start at the beginning of the screen line containing IT's
9125 position. This may actually move vertically backwards,
9126 in case of overlays, so adjust dvpos accordingly. */
9128 move_it_vertically_backward (it
, 0);
9131 /* Go back -DVPOS visible lines and reseat the iterator there. */
9132 start_charpos
= IT_CHARPOS (*it
);
9133 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9134 back_to_previous_visible_line_start (it
);
9135 reseat (it
, it
->current
.pos
, 1);
9137 /* Move further back if we end up in a string or an image. */
9138 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9140 /* First try to move to start of display line. */
9142 move_it_vertically_backward (it
, 0);
9144 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9146 /* If start of line is still in string or image,
9147 move further back. */
9148 back_to_previous_visible_line_start (it
);
9149 reseat (it
, it
->current
.pos
, 1);
9153 it
->current_x
= it
->hpos
= 0;
9155 /* Above call may have moved too far if continuation lines
9156 are involved. Scan forward and see if it did. */
9157 SAVE_IT (it2
, *it
, it2data
);
9158 it2
.vpos
= it2
.current_y
= 0;
9159 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9160 it
->vpos
-= it2
.vpos
;
9161 it
->current_y
-= it2
.current_y
;
9162 it
->current_x
= it
->hpos
= 0;
9164 /* If we moved too far back, move IT some lines forward. */
9165 if (it2
.vpos
> -dvpos
)
9167 int delta
= it2
.vpos
+ dvpos
;
9169 RESTORE_IT (&it2
, &it2
, it2data
);
9170 SAVE_IT (it2
, *it
, it2data
);
9171 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9172 /* Move back again if we got too far ahead. */
9173 if (IT_CHARPOS (*it
) >= start_charpos
)
9174 RESTORE_IT (it
, &it2
, it2data
);
9176 bidi_unshelve_cache (it2data
, 1);
9179 RESTORE_IT (it
, it
, it2data
);
9183 /* Return 1 if IT points into the middle of a display vector. */
9186 in_display_vector_p (struct it
*it
)
9188 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9189 && it
->current
.dpvec_index
> 0
9190 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9194 /***********************************************************************
9196 ***********************************************************************/
9199 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9203 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9205 Lisp_Object args
[3];
9206 Lisp_Object msg
, fmt
;
9209 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9212 /* Do nothing if called asynchronously. Inserting text into
9213 a buffer may call after-change-functions and alike and
9214 that would means running Lisp asynchronously. */
9215 if (handling_signal
)
9219 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9221 args
[0] = fmt
= build_string (format
);
9224 msg
= Fformat (3, args
);
9226 len
= SBYTES (msg
) + 1;
9227 SAFE_ALLOCA (buffer
, char *, len
);
9228 memcpy (buffer
, SDATA (msg
), len
);
9230 message_dolog (buffer
, len
- 1, 1, 0);
9237 /* Output a newline in the *Messages* buffer if "needs" one. */
9240 message_log_maybe_newline (void)
9242 if (message_log_need_newline
)
9243 message_dolog ("", 0, 1, 0);
9247 /* Add a string M of length NBYTES to the message log, optionally
9248 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9249 nonzero, means interpret the contents of M as multibyte. This
9250 function calls low-level routines in order to bypass text property
9251 hooks, etc. which might not be safe to run.
9253 This may GC (insert may run before/after change hooks),
9254 so the buffer M must NOT point to a Lisp string. */
9257 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9259 const unsigned char *msg
= (const unsigned char *) m
;
9261 if (!NILP (Vmemory_full
))
9264 if (!NILP (Vmessage_log_max
))
9266 struct buffer
*oldbuf
;
9267 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9268 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9269 ptrdiff_t point_at_end
= 0;
9270 ptrdiff_t zv_at_end
= 0;
9271 Lisp_Object old_deactivate_mark
, tem
;
9272 struct gcpro gcpro1
;
9274 old_deactivate_mark
= Vdeactivate_mark
;
9275 oldbuf
= current_buffer
;
9276 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9277 BVAR (current_buffer
, undo_list
) = Qt
;
9279 oldpoint
= message_dolog_marker1
;
9280 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9281 oldbegv
= message_dolog_marker2
;
9282 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9283 oldzv
= message_dolog_marker3
;
9284 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9285 GCPRO1 (old_deactivate_mark
);
9293 BEGV_BYTE
= BEG_BYTE
;
9296 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9298 /* Insert the string--maybe converting multibyte to single byte
9299 or vice versa, so that all the text fits the buffer. */
9301 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9307 /* Convert a multibyte string to single-byte
9308 for the *Message* buffer. */
9309 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9311 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9312 work
[0] = (ASCII_CHAR_P (c
)
9314 : multibyte_char_to_unibyte (c
));
9315 insert_1_both (work
, 1, 1, 1, 0, 0);
9318 else if (! multibyte
9319 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9323 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9324 /* Convert a single-byte string to multibyte
9325 for the *Message* buffer. */
9326 for (i
= 0; i
< nbytes
; i
++)
9329 MAKE_CHAR_MULTIBYTE (c
);
9330 char_bytes
= CHAR_STRING (c
, str
);
9331 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9335 insert_1 (m
, nbytes
, 1, 0, 0);
9339 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9341 insert_1 ("\n", 1, 1, 0, 0);
9343 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9345 this_bol_byte
= PT_BYTE
;
9347 /* See if this line duplicates the previous one.
9348 If so, combine duplicates. */
9351 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9353 prev_bol_byte
= PT_BYTE
;
9355 dups
= message_log_check_duplicate (prev_bol_byte
,
9359 del_range_both (prev_bol
, prev_bol_byte
,
9360 this_bol
, this_bol_byte
, 0);
9363 char dupstr
[sizeof " [ times]"
9364 + INT_STRLEN_BOUND (printmax_t
)];
9367 /* If you change this format, don't forget to also
9368 change message_log_check_duplicate. */
9369 sprintf (dupstr
, " [%"pMd
" times]", dups
);
9370 duplen
= strlen (dupstr
);
9371 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9372 insert_1 (dupstr
, duplen
, 1, 0, 1);
9377 /* If we have more than the desired maximum number of lines
9378 in the *Messages* buffer now, delete the oldest ones.
9379 This is safe because we don't have undo in this buffer. */
9381 if (NATNUMP (Vmessage_log_max
))
9383 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9384 -XFASTINT (Vmessage_log_max
) - 1, 0);
9385 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9388 BEGV
= XMARKER (oldbegv
)->charpos
;
9389 BEGV_BYTE
= marker_byte_position (oldbegv
);
9398 ZV
= XMARKER (oldzv
)->charpos
;
9399 ZV_BYTE
= marker_byte_position (oldzv
);
9403 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9405 /* We can't do Fgoto_char (oldpoint) because it will run some
9407 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9408 XMARKER (oldpoint
)->bytepos
);
9411 unchain_marker (XMARKER (oldpoint
));
9412 unchain_marker (XMARKER (oldbegv
));
9413 unchain_marker (XMARKER (oldzv
));
9415 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9416 set_buffer_internal (oldbuf
);
9418 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9419 message_log_need_newline
= !nlflag
;
9420 Vdeactivate_mark
= old_deactivate_mark
;
9425 /* We are at the end of the buffer after just having inserted a newline.
9426 (Note: We depend on the fact we won't be crossing the gap.)
9427 Check to see if the most recent message looks a lot like the previous one.
9428 Return 0 if different, 1 if the new one should just replace it, or a
9429 value N > 1 if we should also append " [N times]". */
9432 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9435 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9437 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9438 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9440 for (i
= 0; i
< len
; i
++)
9442 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9450 if (*p1
++ == ' ' && *p1
++ == '[')
9453 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9454 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9461 /* Display an echo area message M with a specified length of NBYTES
9462 bytes. The string may include null characters. If M is 0, clear
9463 out any existing message, and let the mini-buffer text show
9466 This may GC, so the buffer M must NOT point to a Lisp string. */
9469 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9471 /* First flush out any partial line written with print. */
9472 message_log_maybe_newline ();
9474 message_dolog (m
, nbytes
, 1, multibyte
);
9475 message2_nolog (m
, nbytes
, multibyte
);
9479 /* The non-logging counterpart of message2. */
9482 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9484 struct frame
*sf
= SELECTED_FRAME ();
9485 message_enable_multibyte
= multibyte
;
9487 if (FRAME_INITIAL_P (sf
))
9489 if (noninteractive_need_newline
)
9490 putc ('\n', stderr
);
9491 noninteractive_need_newline
= 0;
9493 fwrite (m
, nbytes
, 1, stderr
);
9494 if (cursor_in_echo_area
== 0)
9495 fprintf (stderr
, "\n");
9498 /* A null message buffer means that the frame hasn't really been
9499 initialized yet. Error messages get reported properly by
9500 cmd_error, so this must be just an informative message; toss it. */
9501 else if (INTERACTIVE
9502 && sf
->glyphs_initialized_p
9503 && FRAME_MESSAGE_BUF (sf
))
9505 Lisp_Object mini_window
;
9508 /* Get the frame containing the mini-buffer
9509 that the selected frame is using. */
9510 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9511 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9513 FRAME_SAMPLE_VISIBILITY (f
);
9514 if (FRAME_VISIBLE_P (sf
)
9515 && ! FRAME_VISIBLE_P (f
))
9516 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9520 set_message (m
, Qnil
, nbytes
, multibyte
);
9521 if (minibuffer_auto_raise
)
9522 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9525 clear_message (1, 1);
9527 do_pending_window_change (0);
9528 echo_area_display (1);
9529 do_pending_window_change (0);
9530 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9531 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9536 /* Display an echo area message M with a specified length of NBYTES
9537 bytes. The string may include null characters. If M is not a
9538 string, clear out any existing message, and let the mini-buffer
9541 This function cancels echoing. */
9544 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9546 struct gcpro gcpro1
;
9549 clear_message (1,1);
9552 /* First flush out any partial line written with print. */
9553 message_log_maybe_newline ();
9559 SAFE_ALLOCA (buffer
, char *, nbytes
);
9560 memcpy (buffer
, SDATA (m
), nbytes
);
9561 message_dolog (buffer
, nbytes
, 1, multibyte
);
9564 message3_nolog (m
, nbytes
, multibyte
);
9570 /* The non-logging version of message3.
9571 This does not cancel echoing, because it is used for echoing.
9572 Perhaps we need to make a separate function for echoing
9573 and make this cancel echoing. */
9576 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9578 struct frame
*sf
= SELECTED_FRAME ();
9579 message_enable_multibyte
= multibyte
;
9581 if (FRAME_INITIAL_P (sf
))
9583 if (noninteractive_need_newline
)
9584 putc ('\n', stderr
);
9585 noninteractive_need_newline
= 0;
9587 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9588 if (cursor_in_echo_area
== 0)
9589 fprintf (stderr
, "\n");
9592 /* A null message buffer means that the frame hasn't really been
9593 initialized yet. Error messages get reported properly by
9594 cmd_error, so this must be just an informative message; toss it. */
9595 else if (INTERACTIVE
9596 && sf
->glyphs_initialized_p
9597 && FRAME_MESSAGE_BUF (sf
))
9599 Lisp_Object mini_window
;
9603 /* Get the frame containing the mini-buffer
9604 that the selected frame is using. */
9605 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9606 frame
= XWINDOW (mini_window
)->frame
;
9609 FRAME_SAMPLE_VISIBILITY (f
);
9610 if (FRAME_VISIBLE_P (sf
)
9611 && !FRAME_VISIBLE_P (f
))
9612 Fmake_frame_visible (frame
);
9614 if (STRINGP (m
) && SCHARS (m
) > 0)
9616 set_message (NULL
, m
, nbytes
, multibyte
);
9617 if (minibuffer_auto_raise
)
9618 Fraise_frame (frame
);
9619 /* Assume we are not echoing.
9620 (If we are, echo_now will override this.) */
9621 echo_message_buffer
= Qnil
;
9624 clear_message (1, 1);
9626 do_pending_window_change (0);
9627 echo_area_display (1);
9628 do_pending_window_change (0);
9629 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9630 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9635 /* Display a null-terminated echo area message M. If M is 0, clear
9636 out any existing message, and let the mini-buffer text show through.
9638 The buffer M must continue to exist until after the echo area gets
9639 cleared or some other message gets displayed there. Do not pass
9640 text that is stored in a Lisp string. Do not pass text in a buffer
9641 that was alloca'd. */
9644 message1 (const char *m
)
9646 message2 (m
, (m
? strlen (m
) : 0), 0);
9650 /* The non-logging counterpart of message1. */
9653 message1_nolog (const char *m
)
9655 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9658 /* Display a message M which contains a single %s
9659 which gets replaced with STRING. */
9662 message_with_string (const char *m
, Lisp_Object string
, int log
)
9664 CHECK_STRING (string
);
9670 if (noninteractive_need_newline
)
9671 putc ('\n', stderr
);
9672 noninteractive_need_newline
= 0;
9673 fprintf (stderr
, m
, SDATA (string
));
9674 if (!cursor_in_echo_area
)
9675 fprintf (stderr
, "\n");
9679 else if (INTERACTIVE
)
9681 /* The frame whose minibuffer we're going to display the message on.
9682 It may be larger than the selected frame, so we need
9683 to use its buffer, not the selected frame's buffer. */
9684 Lisp_Object mini_window
;
9685 struct frame
*f
, *sf
= SELECTED_FRAME ();
9687 /* Get the frame containing the minibuffer
9688 that the selected frame is using. */
9689 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9690 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9692 /* A null message buffer means that the frame hasn't really been
9693 initialized yet. Error messages get reported properly by
9694 cmd_error, so this must be just an informative message; toss it. */
9695 if (FRAME_MESSAGE_BUF (f
))
9697 Lisp_Object args
[2], msg
;
9698 struct gcpro gcpro1
, gcpro2
;
9700 args
[0] = build_string (m
);
9701 args
[1] = msg
= string
;
9702 GCPRO2 (args
[0], msg
);
9705 msg
= Fformat (2, args
);
9708 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9710 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9714 /* Print should start at the beginning of the message
9715 buffer next time. */
9716 message_buf_print
= 0;
9722 /* Dump an informative message to the minibuf. If M is 0, clear out
9723 any existing message, and let the mini-buffer text show through. */
9726 vmessage (const char *m
, va_list ap
)
9732 if (noninteractive_need_newline
)
9733 putc ('\n', stderr
);
9734 noninteractive_need_newline
= 0;
9735 vfprintf (stderr
, m
, ap
);
9736 if (cursor_in_echo_area
== 0)
9737 fprintf (stderr
, "\n");
9741 else if (INTERACTIVE
)
9743 /* The frame whose mini-buffer we're going to display the message
9744 on. It may be larger than the selected frame, so we need to
9745 use its buffer, not the selected frame's buffer. */
9746 Lisp_Object mini_window
;
9747 struct frame
*f
, *sf
= SELECTED_FRAME ();
9749 /* Get the frame containing the mini-buffer
9750 that the selected frame is using. */
9751 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9752 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9754 /* A null message buffer means that the frame hasn't really been
9755 initialized yet. Error messages get reported properly by
9756 cmd_error, so this must be just an informative message; toss
9758 if (FRAME_MESSAGE_BUF (f
))
9764 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9765 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9767 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9772 /* Print should start at the beginning of the message
9773 buffer next time. */
9774 message_buf_print
= 0;
9780 message (const char *m
, ...)
9790 /* The non-logging version of message. */
9793 message_nolog (const char *m
, ...)
9795 Lisp_Object old_log_max
;
9798 old_log_max
= Vmessage_log_max
;
9799 Vmessage_log_max
= Qnil
;
9801 Vmessage_log_max
= old_log_max
;
9807 /* Display the current message in the current mini-buffer. This is
9808 only called from error handlers in process.c, and is not time
9812 update_echo_area (void)
9814 if (!NILP (echo_area_buffer
[0]))
9817 string
= Fcurrent_message ();
9818 message3 (string
, SBYTES (string
),
9819 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9824 /* Make sure echo area buffers in `echo_buffers' are live.
9825 If they aren't, make new ones. */
9828 ensure_echo_area_buffers (void)
9832 for (i
= 0; i
< 2; ++i
)
9833 if (!BUFFERP (echo_buffer
[i
])
9834 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9837 Lisp_Object old_buffer
;
9840 old_buffer
= echo_buffer
[i
];
9841 sprintf (name
, " *Echo Area %d*", i
);
9842 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9843 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9844 /* to force word wrap in echo area -
9845 it was decided to postpone this*/
9846 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9848 for (j
= 0; j
< 2; ++j
)
9849 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9850 echo_area_buffer
[j
] = echo_buffer
[i
];
9855 /* Call FN with args A1..A4 with either the current or last displayed
9856 echo_area_buffer as current buffer.
9858 WHICH zero means use the current message buffer
9859 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9860 from echo_buffer[] and clear it.
9862 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9863 suitable buffer from echo_buffer[] and clear it.
9865 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9866 that the current message becomes the last displayed one, make
9867 choose a suitable buffer for echo_area_buffer[0], and clear it.
9869 Value is what FN returns. */
9872 with_echo_area_buffer (struct window
*w
, int which
,
9873 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9874 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9877 int this_one
, the_other
, clear_buffer_p
, rc
;
9878 ptrdiff_t count
= SPECPDL_INDEX ();
9880 /* If buffers aren't live, make new ones. */
9881 ensure_echo_area_buffers ();
9886 this_one
= 0, the_other
= 1;
9888 this_one
= 1, the_other
= 0;
9891 this_one
= 0, the_other
= 1;
9894 /* We need a fresh one in case the current echo buffer equals
9895 the one containing the last displayed echo area message. */
9896 if (!NILP (echo_area_buffer
[this_one
])
9897 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9898 echo_area_buffer
[this_one
] = Qnil
;
9901 /* Choose a suitable buffer from echo_buffer[] is we don't
9903 if (NILP (echo_area_buffer
[this_one
]))
9905 echo_area_buffer
[this_one
]
9906 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9907 ? echo_buffer
[the_other
]
9908 : echo_buffer
[this_one
]);
9912 buffer
= echo_area_buffer
[this_one
];
9914 /* Don't get confused by reusing the buffer used for echoing
9915 for a different purpose. */
9916 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9919 record_unwind_protect (unwind_with_echo_area_buffer
,
9920 with_echo_area_buffer_unwind_data (w
));
9922 /* Make the echo area buffer current. Note that for display
9923 purposes, it is not necessary that the displayed window's buffer
9924 == current_buffer, except for text property lookup. So, let's
9925 only set that buffer temporarily here without doing a full
9926 Fset_window_buffer. We must also change w->pointm, though,
9927 because otherwise an assertions in unshow_buffer fails, and Emacs
9929 set_buffer_internal_1 (XBUFFER (buffer
));
9933 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9936 BVAR (current_buffer
, undo_list
) = Qt
;
9937 BVAR (current_buffer
, read_only
) = Qnil
;
9938 specbind (Qinhibit_read_only
, Qt
);
9939 specbind (Qinhibit_modification_hooks
, Qt
);
9941 if (clear_buffer_p
&& Z
> BEG
)
9944 xassert (BEGV
>= BEG
);
9945 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9947 rc
= fn (a1
, a2
, a3
, a4
);
9949 xassert (BEGV
>= BEG
);
9950 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9952 unbind_to (count
, Qnil
);
9957 /* Save state that should be preserved around the call to the function
9958 FN called in with_echo_area_buffer. */
9961 with_echo_area_buffer_unwind_data (struct window
*w
)
9964 Lisp_Object vector
, tmp
;
9966 /* Reduce consing by keeping one vector in
9967 Vwith_echo_area_save_vector. */
9968 vector
= Vwith_echo_area_save_vector
;
9969 Vwith_echo_area_save_vector
= Qnil
;
9972 vector
= Fmake_vector (make_number (7), Qnil
);
9974 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9975 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9976 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9980 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9981 ASET (vector
, i
, w
->buffer
); ++i
;
9982 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9983 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9988 for (; i
< end
; ++i
)
9989 ASET (vector
, i
, Qnil
);
9992 xassert (i
== ASIZE (vector
));
9997 /* Restore global state from VECTOR which was created by
9998 with_echo_area_buffer_unwind_data. */
10001 unwind_with_echo_area_buffer (Lisp_Object vector
)
10003 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10004 Vdeactivate_mark
= AREF (vector
, 1);
10005 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10007 if (WINDOWP (AREF (vector
, 3)))
10010 Lisp_Object buffer
, charpos
, bytepos
;
10012 w
= XWINDOW (AREF (vector
, 3));
10013 buffer
= AREF (vector
, 4);
10014 charpos
= AREF (vector
, 5);
10015 bytepos
= AREF (vector
, 6);
10017 w
->buffer
= buffer
;
10018 set_marker_both (w
->pointm
, buffer
,
10019 XFASTINT (charpos
), XFASTINT (bytepos
));
10022 Vwith_echo_area_save_vector
= vector
;
10027 /* Set up the echo area for use by print functions. MULTIBYTE_P
10028 non-zero means we will print multibyte. */
10031 setup_echo_area_for_printing (int multibyte_p
)
10033 /* If we can't find an echo area any more, exit. */
10034 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10035 Fkill_emacs (Qnil
);
10037 ensure_echo_area_buffers ();
10039 if (!message_buf_print
)
10041 /* A message has been output since the last time we printed.
10042 Choose a fresh echo area buffer. */
10043 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10044 echo_area_buffer
[0] = echo_buffer
[1];
10046 echo_area_buffer
[0] = echo_buffer
[0];
10048 /* Switch to that buffer and clear it. */
10049 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10050 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10054 ptrdiff_t count
= SPECPDL_INDEX ();
10055 specbind (Qinhibit_read_only
, Qt
);
10056 /* Note that undo recording is always disabled. */
10057 del_range (BEG
, Z
);
10058 unbind_to (count
, Qnil
);
10060 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10062 /* Set up the buffer for the multibyteness we need. */
10064 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10065 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10067 /* Raise the frame containing the echo area. */
10068 if (minibuffer_auto_raise
)
10070 struct frame
*sf
= SELECTED_FRAME ();
10071 Lisp_Object mini_window
;
10072 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10073 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10076 message_log_maybe_newline ();
10077 message_buf_print
= 1;
10081 if (NILP (echo_area_buffer
[0]))
10083 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10084 echo_area_buffer
[0] = echo_buffer
[1];
10086 echo_area_buffer
[0] = echo_buffer
[0];
10089 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10091 /* Someone switched buffers between print requests. */
10092 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10093 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10099 /* Display an echo area message in window W. Value is non-zero if W's
10100 height is changed. If display_last_displayed_message_p is
10101 non-zero, display the message that was last displayed, otherwise
10102 display the current message. */
10105 display_echo_area (struct window
*w
)
10107 int i
, no_message_p
, window_height_changed_p
;
10109 /* Temporarily disable garbage collections while displaying the echo
10110 area. This is done because a GC can print a message itself.
10111 That message would modify the echo area buffer's contents while a
10112 redisplay of the buffer is going on, and seriously confuse
10114 ptrdiff_t count
= inhibit_garbage_collection ();
10116 /* If there is no message, we must call display_echo_area_1
10117 nevertheless because it resizes the window. But we will have to
10118 reset the echo_area_buffer in question to nil at the end because
10119 with_echo_area_buffer will sets it to an empty buffer. */
10120 i
= display_last_displayed_message_p
? 1 : 0;
10121 no_message_p
= NILP (echo_area_buffer
[i
]);
10123 window_height_changed_p
10124 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10125 display_echo_area_1
,
10126 (intptr_t) w
, Qnil
, 0, 0);
10129 echo_area_buffer
[i
] = Qnil
;
10131 unbind_to (count
, Qnil
);
10132 return window_height_changed_p
;
10136 /* Helper for display_echo_area. Display the current buffer which
10137 contains the current echo area message in window W, a mini-window,
10138 a pointer to which is passed in A1. A2..A4 are currently not used.
10139 Change the height of W so that all of the message is displayed.
10140 Value is non-zero if height of W was changed. */
10143 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10146 struct window
*w
= (struct window
*) i1
;
10147 Lisp_Object window
;
10148 struct text_pos start
;
10149 int window_height_changed_p
= 0;
10151 /* Do this before displaying, so that we have a large enough glyph
10152 matrix for the display. If we can't get enough space for the
10153 whole text, display the last N lines. That works by setting w->start. */
10154 window_height_changed_p
= resize_mini_window (w
, 0);
10156 /* Use the starting position chosen by resize_mini_window. */
10157 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10160 clear_glyph_matrix (w
->desired_matrix
);
10161 XSETWINDOW (window
, w
);
10162 try_window (window
, start
, 0);
10164 return window_height_changed_p
;
10168 /* Resize the echo area window to exactly the size needed for the
10169 currently displayed message, if there is one. If a mini-buffer
10170 is active, don't shrink it. */
10173 resize_echo_area_exactly (void)
10175 if (BUFFERP (echo_area_buffer
[0])
10176 && WINDOWP (echo_area_window
))
10178 struct window
*w
= XWINDOW (echo_area_window
);
10180 Lisp_Object resize_exactly
;
10182 if (minibuf_level
== 0)
10183 resize_exactly
= Qt
;
10185 resize_exactly
= Qnil
;
10187 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10188 (intptr_t) w
, resize_exactly
,
10192 ++windows_or_buffers_changed
;
10193 ++update_mode_lines
;
10194 redisplay_internal ();
10200 /* Callback function for with_echo_area_buffer, when used from
10201 resize_echo_area_exactly. A1 contains a pointer to the window to
10202 resize, EXACTLY non-nil means resize the mini-window exactly to the
10203 size of the text displayed. A3 and A4 are not used. Value is what
10204 resize_mini_window returns. */
10207 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10210 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10214 /* Resize mini-window W to fit the size of its contents. EXACT_P
10215 means size the window exactly to the size needed. Otherwise, it's
10216 only enlarged until W's buffer is empty.
10218 Set W->start to the right place to begin display. If the whole
10219 contents fit, start at the beginning. Otherwise, start so as
10220 to make the end of the contents appear. This is particularly
10221 important for y-or-n-p, but seems desirable generally.
10223 Value is non-zero if the window height has been changed. */
10226 resize_mini_window (struct window
*w
, int exact_p
)
10228 struct frame
*f
= XFRAME (w
->frame
);
10229 int window_height_changed_p
= 0;
10231 xassert (MINI_WINDOW_P (w
));
10233 /* By default, start display at the beginning. */
10234 set_marker_both (w
->start
, w
->buffer
,
10235 BUF_BEGV (XBUFFER (w
->buffer
)),
10236 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10238 /* Don't resize windows while redisplaying a window; it would
10239 confuse redisplay functions when the size of the window they are
10240 displaying changes from under them. Such a resizing can happen,
10241 for instance, when which-func prints a long message while
10242 we are running fontification-functions. We're running these
10243 functions with safe_call which binds inhibit-redisplay to t. */
10244 if (!NILP (Vinhibit_redisplay
))
10247 /* Nil means don't try to resize. */
10248 if (NILP (Vresize_mini_windows
)
10249 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10252 if (!FRAME_MINIBUF_ONLY_P (f
))
10255 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10256 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10258 EMACS_INT max_height
;
10259 int unit
= FRAME_LINE_HEIGHT (f
);
10260 struct text_pos start
;
10261 struct buffer
*old_current_buffer
= NULL
;
10263 if (current_buffer
!= XBUFFER (w
->buffer
))
10265 old_current_buffer
= current_buffer
;
10266 set_buffer_internal (XBUFFER (w
->buffer
));
10269 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10271 /* Compute the max. number of lines specified by the user. */
10272 if (FLOATP (Vmax_mini_window_height
))
10273 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10274 else if (INTEGERP (Vmax_mini_window_height
))
10275 max_height
= XINT (Vmax_mini_window_height
);
10277 max_height
= total_height
/ 4;
10279 /* Correct that max. height if it's bogus. */
10280 max_height
= max (1, max_height
);
10281 max_height
= min (total_height
, max_height
);
10283 /* Find out the height of the text in the window. */
10284 if (it
.line_wrap
== TRUNCATE
)
10289 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10290 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10291 height
= it
.current_y
+ last_height
;
10293 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10294 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10295 height
= (height
+ unit
- 1) / unit
;
10298 /* Compute a suitable window start. */
10299 if (height
> max_height
)
10301 height
= max_height
;
10302 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10303 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10304 start
= it
.current
.pos
;
10307 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10308 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10310 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10312 /* Let it grow only, until we display an empty message, in which
10313 case the window shrinks again. */
10314 if (height
> WINDOW_TOTAL_LINES (w
))
10316 int old_height
= WINDOW_TOTAL_LINES (w
);
10317 freeze_window_starts (f
, 1);
10318 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10319 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10321 else if (height
< WINDOW_TOTAL_LINES (w
)
10322 && (exact_p
|| BEGV
== ZV
))
10324 int old_height
= WINDOW_TOTAL_LINES (w
);
10325 freeze_window_starts (f
, 0);
10326 shrink_mini_window (w
);
10327 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10332 /* Always resize to exact size needed. */
10333 if (height
> WINDOW_TOTAL_LINES (w
))
10335 int old_height
= WINDOW_TOTAL_LINES (w
);
10336 freeze_window_starts (f
, 1);
10337 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10338 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10340 else if (height
< WINDOW_TOTAL_LINES (w
))
10342 int old_height
= WINDOW_TOTAL_LINES (w
);
10343 freeze_window_starts (f
, 0);
10344 shrink_mini_window (w
);
10348 freeze_window_starts (f
, 1);
10349 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10352 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10356 if (old_current_buffer
)
10357 set_buffer_internal (old_current_buffer
);
10360 return window_height_changed_p
;
10364 /* Value is the current message, a string, or nil if there is no
10365 current message. */
10368 current_message (void)
10372 if (!BUFFERP (echo_area_buffer
[0]))
10376 with_echo_area_buffer (0, 0, current_message_1
,
10377 (intptr_t) &msg
, Qnil
, 0, 0);
10379 echo_area_buffer
[0] = Qnil
;
10387 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10390 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10393 *msg
= make_buffer_string (BEG
, Z
, 1);
10400 /* Push the current message on Vmessage_stack for later restoration
10401 by restore_message. Value is non-zero if the current message isn't
10402 empty. This is a relatively infrequent operation, so it's not
10403 worth optimizing. */
10406 push_message (void)
10409 msg
= current_message ();
10410 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10411 return STRINGP (msg
);
10415 /* Restore message display from the top of Vmessage_stack. */
10418 restore_message (void)
10422 xassert (CONSP (Vmessage_stack
));
10423 msg
= XCAR (Vmessage_stack
);
10425 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10427 message3_nolog (msg
, 0, 0);
10431 /* Handler for record_unwind_protect calling pop_message. */
10434 pop_message_unwind (Lisp_Object dummy
)
10440 /* Pop the top-most entry off Vmessage_stack. */
10445 xassert (CONSP (Vmessage_stack
));
10446 Vmessage_stack
= XCDR (Vmessage_stack
);
10450 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10451 exits. If the stack is not empty, we have a missing pop_message
10455 check_message_stack (void)
10457 if (!NILP (Vmessage_stack
))
10462 /* Truncate to NCHARS what will be displayed in the echo area the next
10463 time we display it---but don't redisplay it now. */
10466 truncate_echo_area (ptrdiff_t nchars
)
10469 echo_area_buffer
[0] = Qnil
;
10470 /* A null message buffer means that the frame hasn't really been
10471 initialized yet. Error messages get reported properly by
10472 cmd_error, so this must be just an informative message; toss it. */
10473 else if (!noninteractive
10475 && !NILP (echo_area_buffer
[0]))
10477 struct frame
*sf
= SELECTED_FRAME ();
10478 if (FRAME_MESSAGE_BUF (sf
))
10479 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10484 /* Helper function for truncate_echo_area. Truncate the current
10485 message to at most NCHARS characters. */
10488 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10490 if (BEG
+ nchars
< Z
)
10491 del_range (BEG
+ nchars
, Z
);
10493 echo_area_buffer
[0] = Qnil
;
10498 /* Set the current message to a substring of S or STRING.
10500 If STRING is a Lisp string, set the message to the first NBYTES
10501 bytes from STRING. NBYTES zero means use the whole string. If
10502 STRING is multibyte, the message will be displayed multibyte.
10504 If S is not null, set the message to the first LEN bytes of S. LEN
10505 zero means use the whole string. MULTIBYTE_P non-zero means S is
10506 multibyte. Display the message multibyte in that case.
10508 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10509 to t before calling set_message_1 (which calls insert).
10513 set_message (const char *s
, Lisp_Object string
,
10514 ptrdiff_t nbytes
, int multibyte_p
)
10516 message_enable_multibyte
10517 = ((s
&& multibyte_p
)
10518 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10520 with_echo_area_buffer (0, -1, set_message_1
,
10521 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10522 message_buf_print
= 0;
10523 help_echo_showing_p
= 0;
10527 /* Helper function for set_message. Arguments have the same meaning
10528 as there, with A1 corresponding to S and A2 corresponding to STRING
10529 This function is called with the echo area buffer being
10533 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10536 const char *s
= (const char *) i1
;
10537 const unsigned char *msg
= (const unsigned char *) s
;
10538 Lisp_Object string
= a2
;
10540 /* Change multibyteness of the echo buffer appropriately. */
10541 if (message_enable_multibyte
10542 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10543 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10545 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10546 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10547 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10549 /* Insert new message at BEG. */
10550 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10552 if (STRINGP (string
))
10557 nbytes
= SBYTES (string
);
10558 nchars
= string_byte_to_char (string
, nbytes
);
10560 /* This function takes care of single/multibyte conversion. We
10561 just have to ensure that the echo area buffer has the right
10562 setting of enable_multibyte_characters. */
10563 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10568 nbytes
= strlen (s
);
10570 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10572 /* Convert from multi-byte to single-byte. */
10577 /* Convert a multibyte string to single-byte. */
10578 for (i
= 0; i
< nbytes
; i
+= n
)
10580 c
= string_char_and_length (msg
+ i
, &n
);
10581 work
[0] = (ASCII_CHAR_P (c
)
10583 : multibyte_char_to_unibyte (c
));
10584 insert_1_both (work
, 1, 1, 1, 0, 0);
10587 else if (!multibyte_p
10588 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10590 /* Convert from single-byte to multi-byte. */
10593 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10595 /* Convert a single-byte string to multibyte. */
10596 for (i
= 0; i
< nbytes
; i
++)
10599 MAKE_CHAR_MULTIBYTE (c
);
10600 n
= CHAR_STRING (c
, str
);
10601 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10605 insert_1 (s
, nbytes
, 1, 0, 0);
10612 /* Clear messages. CURRENT_P non-zero means clear the current
10613 message. LAST_DISPLAYED_P non-zero means clear the message
10617 clear_message (int current_p
, int last_displayed_p
)
10621 echo_area_buffer
[0] = Qnil
;
10622 message_cleared_p
= 1;
10625 if (last_displayed_p
)
10626 echo_area_buffer
[1] = Qnil
;
10628 message_buf_print
= 0;
10631 /* Clear garbaged frames.
10633 This function is used where the old redisplay called
10634 redraw_garbaged_frames which in turn called redraw_frame which in
10635 turn called clear_frame. The call to clear_frame was a source of
10636 flickering. I believe a clear_frame is not necessary. It should
10637 suffice in the new redisplay to invalidate all current matrices,
10638 and ensure a complete redisplay of all windows. */
10641 clear_garbaged_frames (void)
10643 if (frame_garbaged
)
10645 Lisp_Object tail
, frame
;
10646 int changed_count
= 0;
10648 FOR_EACH_FRAME (tail
, frame
)
10650 struct frame
*f
= XFRAME (frame
);
10652 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10656 Fredraw_frame (frame
);
10657 f
->force_flush_display_p
= 1;
10659 clear_current_matrices (f
);
10666 frame_garbaged
= 0;
10668 ++windows_or_buffers_changed
;
10673 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10674 is non-zero update selected_frame. Value is non-zero if the
10675 mini-windows height has been changed. */
10678 echo_area_display (int update_frame_p
)
10680 Lisp_Object mini_window
;
10683 int window_height_changed_p
= 0;
10684 struct frame
*sf
= SELECTED_FRAME ();
10686 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10687 w
= XWINDOW (mini_window
);
10688 f
= XFRAME (WINDOW_FRAME (w
));
10690 /* Don't display if frame is invisible or not yet initialized. */
10691 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10694 #ifdef HAVE_WINDOW_SYSTEM
10695 /* When Emacs starts, selected_frame may be the initial terminal
10696 frame. If we let this through, a message would be displayed on
10698 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10700 #endif /* HAVE_WINDOW_SYSTEM */
10702 /* Redraw garbaged frames. */
10703 if (frame_garbaged
)
10704 clear_garbaged_frames ();
10706 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10708 echo_area_window
= mini_window
;
10709 window_height_changed_p
= display_echo_area (w
);
10710 w
->must_be_updated_p
= 1;
10712 /* Update the display, unless called from redisplay_internal.
10713 Also don't update the screen during redisplay itself. The
10714 update will happen at the end of redisplay, and an update
10715 here could cause confusion. */
10716 if (update_frame_p
&& !redisplaying_p
)
10720 /* If the display update has been interrupted by pending
10721 input, update mode lines in the frame. Due to the
10722 pending input, it might have been that redisplay hasn't
10723 been called, so that mode lines above the echo area are
10724 garbaged. This looks odd, so we prevent it here. */
10725 if (!display_completed
)
10726 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10728 if (window_height_changed_p
10729 /* Don't do this if Emacs is shutting down. Redisplay
10730 needs to run hooks. */
10731 && !NILP (Vrun_hooks
))
10733 /* Must update other windows. Likewise as in other
10734 cases, don't let this update be interrupted by
10736 ptrdiff_t count
= SPECPDL_INDEX ();
10737 specbind (Qredisplay_dont_pause
, Qt
);
10738 windows_or_buffers_changed
= 1;
10739 redisplay_internal ();
10740 unbind_to (count
, Qnil
);
10742 else if (FRAME_WINDOW_P (f
) && n
== 0)
10744 /* Window configuration is the same as before.
10745 Can do with a display update of the echo area,
10746 unless we displayed some mode lines. */
10747 update_single_window (w
, 1);
10748 FRAME_RIF (f
)->flush_display (f
);
10751 update_frame (f
, 1, 1);
10753 /* If cursor is in the echo area, make sure that the next
10754 redisplay displays the minibuffer, so that the cursor will
10755 be replaced with what the minibuffer wants. */
10756 if (cursor_in_echo_area
)
10757 ++windows_or_buffers_changed
;
10760 else if (!EQ (mini_window
, selected_window
))
10761 windows_or_buffers_changed
++;
10763 /* Last displayed message is now the current message. */
10764 echo_area_buffer
[1] = echo_area_buffer
[0];
10765 /* Inform read_char that we're not echoing. */
10766 echo_message_buffer
= Qnil
;
10768 /* Prevent redisplay optimization in redisplay_internal by resetting
10769 this_line_start_pos. This is done because the mini-buffer now
10770 displays the message instead of its buffer text. */
10771 if (EQ (mini_window
, selected_window
))
10772 CHARPOS (this_line_start_pos
) = 0;
10774 return window_height_changed_p
;
10779 /***********************************************************************
10780 Mode Lines and Frame Titles
10781 ***********************************************************************/
10783 /* A buffer for constructing non-propertized mode-line strings and
10784 frame titles in it; allocated from the heap in init_xdisp and
10785 resized as needed in store_mode_line_noprop_char. */
10787 static char *mode_line_noprop_buf
;
10789 /* The buffer's end, and a current output position in it. */
10791 static char *mode_line_noprop_buf_end
;
10792 static char *mode_line_noprop_ptr
;
10794 #define MODE_LINE_NOPROP_LEN(start) \
10795 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10798 MODE_LINE_DISPLAY
= 0,
10802 } mode_line_target
;
10804 /* Alist that caches the results of :propertize.
10805 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10806 static Lisp_Object mode_line_proptrans_alist
;
10808 /* List of strings making up the mode-line. */
10809 static Lisp_Object mode_line_string_list
;
10811 /* Base face property when building propertized mode line string. */
10812 static Lisp_Object mode_line_string_face
;
10813 static Lisp_Object mode_line_string_face_prop
;
10816 /* Unwind data for mode line strings */
10818 static Lisp_Object Vmode_line_unwind_vector
;
10821 format_mode_line_unwind_data (struct buffer
*obuf
,
10823 int save_proptrans
)
10825 Lisp_Object vector
, tmp
;
10827 /* Reduce consing by keeping one vector in
10828 Vwith_echo_area_save_vector. */
10829 vector
= Vmode_line_unwind_vector
;
10830 Vmode_line_unwind_vector
= Qnil
;
10833 vector
= Fmake_vector (make_number (8), Qnil
);
10835 ASET (vector
, 0, make_number (mode_line_target
));
10836 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10837 ASET (vector
, 2, mode_line_string_list
);
10838 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10839 ASET (vector
, 4, mode_line_string_face
);
10840 ASET (vector
, 5, mode_line_string_face_prop
);
10843 XSETBUFFER (tmp
, obuf
);
10846 ASET (vector
, 6, tmp
);
10847 ASET (vector
, 7, owin
);
10853 unwind_format_mode_line (Lisp_Object vector
)
10855 mode_line_target
= XINT (AREF (vector
, 0));
10856 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10857 mode_line_string_list
= AREF (vector
, 2);
10858 if (! EQ (AREF (vector
, 3), Qt
))
10859 mode_line_proptrans_alist
= AREF (vector
, 3);
10860 mode_line_string_face
= AREF (vector
, 4);
10861 mode_line_string_face_prop
= AREF (vector
, 5);
10863 if (!NILP (AREF (vector
, 7)))
10864 /* Select window before buffer, since it may change the buffer. */
10865 Fselect_window (AREF (vector
, 7), Qt
);
10867 if (!NILP (AREF (vector
, 6)))
10869 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10870 ASET (vector
, 6, Qnil
);
10873 Vmode_line_unwind_vector
= vector
;
10878 /* Store a single character C for the frame title in mode_line_noprop_buf.
10879 Re-allocate mode_line_noprop_buf if necessary. */
10882 store_mode_line_noprop_char (char c
)
10884 /* If output position has reached the end of the allocated buffer,
10885 increase the buffer's size. */
10886 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10888 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10889 ptrdiff_t size
= len
;
10890 mode_line_noprop_buf
=
10891 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10892 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10893 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10896 *mode_line_noprop_ptr
++ = c
;
10900 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10901 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10902 characters that yield more columns than PRECISION; PRECISION <= 0
10903 means copy the whole string. Pad with spaces until FIELD_WIDTH
10904 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10905 pad. Called from display_mode_element when it is used to build a
10909 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10911 const unsigned char *str
= (const unsigned char *) string
;
10913 ptrdiff_t dummy
, nbytes
;
10915 /* Copy at most PRECISION chars from STR. */
10916 nbytes
= strlen (string
);
10917 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10919 store_mode_line_noprop_char (*str
++);
10921 /* Fill up with spaces until FIELD_WIDTH reached. */
10922 while (field_width
> 0
10923 && n
< field_width
)
10925 store_mode_line_noprop_char (' ');
10932 /***********************************************************************
10934 ***********************************************************************/
10936 #ifdef HAVE_WINDOW_SYSTEM
10938 /* Set the title of FRAME, if it has changed. The title format is
10939 Vicon_title_format if FRAME is iconified, otherwise it is
10940 frame_title_format. */
10943 x_consider_frame_title (Lisp_Object frame
)
10945 struct frame
*f
= XFRAME (frame
);
10947 if (FRAME_WINDOW_P (f
)
10948 || FRAME_MINIBUF_ONLY_P (f
)
10949 || f
->explicit_name
)
10951 /* Do we have more than one visible frame on this X display? */
10954 ptrdiff_t title_start
;
10958 ptrdiff_t count
= SPECPDL_INDEX ();
10960 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10962 Lisp_Object other_frame
= XCAR (tail
);
10963 struct frame
*tf
= XFRAME (other_frame
);
10966 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10967 && !FRAME_MINIBUF_ONLY_P (tf
)
10968 && !EQ (other_frame
, tip_frame
)
10969 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10973 /* Set global variable indicating that multiple frames exist. */
10974 multiple_frames
= CONSP (tail
);
10976 /* Switch to the buffer of selected window of the frame. Set up
10977 mode_line_target so that display_mode_element will output into
10978 mode_line_noprop_buf; then display the title. */
10979 record_unwind_protect (unwind_format_mode_line
,
10980 format_mode_line_unwind_data
10981 (current_buffer
, selected_window
, 0));
10983 Fselect_window (f
->selected_window
, Qt
);
10984 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10985 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10987 mode_line_target
= MODE_LINE_TITLE
;
10988 title_start
= MODE_LINE_NOPROP_LEN (0);
10989 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10990 NULL
, DEFAULT_FACE_ID
);
10991 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10992 len
= MODE_LINE_NOPROP_LEN (title_start
);
10993 title
= mode_line_noprop_buf
+ title_start
;
10994 unbind_to (count
, Qnil
);
10996 /* Set the title only if it's changed. This avoids consing in
10997 the common case where it hasn't. (If it turns out that we've
10998 already wasted too much time by walking through the list with
10999 display_mode_element, then we might need to optimize at a
11000 higher level than this.) */
11001 if (! STRINGP (f
->name
)
11002 || SBYTES (f
->name
) != len
11003 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11004 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11008 #endif /* not HAVE_WINDOW_SYSTEM */
11013 /***********************************************************************
11015 ***********************************************************************/
11018 /* Prepare for redisplay by updating menu-bar item lists when
11019 appropriate. This can call eval. */
11022 prepare_menu_bars (void)
11025 struct gcpro gcpro1
, gcpro2
;
11027 Lisp_Object tooltip_frame
;
11029 #ifdef HAVE_WINDOW_SYSTEM
11030 tooltip_frame
= tip_frame
;
11032 tooltip_frame
= Qnil
;
11035 /* Update all frame titles based on their buffer names, etc. We do
11036 this before the menu bars so that the buffer-menu will show the
11037 up-to-date frame titles. */
11038 #ifdef HAVE_WINDOW_SYSTEM
11039 if (windows_or_buffers_changed
|| update_mode_lines
)
11041 Lisp_Object tail
, frame
;
11043 FOR_EACH_FRAME (tail
, frame
)
11045 f
= XFRAME (frame
);
11046 if (!EQ (frame
, tooltip_frame
)
11047 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11048 x_consider_frame_title (frame
);
11051 #endif /* HAVE_WINDOW_SYSTEM */
11053 /* Update the menu bar item lists, if appropriate. This has to be
11054 done before any actual redisplay or generation of display lines. */
11055 all_windows
= (update_mode_lines
11056 || buffer_shared
> 1
11057 || windows_or_buffers_changed
);
11060 Lisp_Object tail
, frame
;
11061 ptrdiff_t count
= SPECPDL_INDEX ();
11062 /* 1 means that update_menu_bar has run its hooks
11063 so any further calls to update_menu_bar shouldn't do so again. */
11064 int menu_bar_hooks_run
= 0;
11066 record_unwind_save_match_data ();
11068 FOR_EACH_FRAME (tail
, frame
)
11070 f
= XFRAME (frame
);
11072 /* Ignore tooltip frame. */
11073 if (EQ (frame
, tooltip_frame
))
11076 /* If a window on this frame changed size, report that to
11077 the user and clear the size-change flag. */
11078 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11080 Lisp_Object functions
;
11082 /* Clear flag first in case we get an error below. */
11083 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11084 functions
= Vwindow_size_change_functions
;
11085 GCPRO2 (tail
, functions
);
11087 while (CONSP (functions
))
11089 if (!EQ (XCAR (functions
), Qt
))
11090 call1 (XCAR (functions
), frame
);
11091 functions
= XCDR (functions
);
11097 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11098 #ifdef HAVE_WINDOW_SYSTEM
11099 update_tool_bar (f
, 0);
11102 if (windows_or_buffers_changed
11104 ns_set_doc_edited (f
, Fbuffer_modified_p
11105 (XWINDOW (f
->selected_window
)->buffer
));
11110 unbind_to (count
, Qnil
);
11114 struct frame
*sf
= SELECTED_FRAME ();
11115 update_menu_bar (sf
, 1, 0);
11116 #ifdef HAVE_WINDOW_SYSTEM
11117 update_tool_bar (sf
, 1);
11123 /* Update the menu bar item list for frame F. This has to be done
11124 before we start to fill in any display lines, because it can call
11127 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11129 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11130 already ran the menu bar hooks for this redisplay, so there
11131 is no need to run them again. The return value is the
11132 updated value of this flag, to pass to the next call. */
11135 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11137 Lisp_Object window
;
11138 register struct window
*w
;
11140 /* If called recursively during a menu update, do nothing. This can
11141 happen when, for instance, an activate-menubar-hook causes a
11143 if (inhibit_menubar_update
)
11146 window
= FRAME_SELECTED_WINDOW (f
);
11147 w
= XWINDOW (window
);
11149 if (FRAME_WINDOW_P (f
)
11151 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11152 || defined (HAVE_NS) || defined (USE_GTK)
11153 FRAME_EXTERNAL_MENU_BAR (f
)
11155 FRAME_MENU_BAR_LINES (f
) > 0
11157 : FRAME_MENU_BAR_LINES (f
) > 0)
11159 /* If the user has switched buffers or windows, we need to
11160 recompute to reflect the new bindings. But we'll
11161 recompute when update_mode_lines is set too; that means
11162 that people can use force-mode-line-update to request
11163 that the menu bar be recomputed. The adverse effect on
11164 the rest of the redisplay algorithm is about the same as
11165 windows_or_buffers_changed anyway. */
11166 if (windows_or_buffers_changed
11167 /* This used to test w->update_mode_line, but we believe
11168 there is no need to recompute the menu in that case. */
11169 || update_mode_lines
11170 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11171 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11172 != !NILP (w
->last_had_star
))
11173 || ((!NILP (Vtransient_mark_mode
)
11174 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11175 != !NILP (w
->region_showing
)))
11177 struct buffer
*prev
= current_buffer
;
11178 ptrdiff_t count
= SPECPDL_INDEX ();
11180 specbind (Qinhibit_menubar_update
, Qt
);
11182 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11183 if (save_match_data
)
11184 record_unwind_save_match_data ();
11185 if (NILP (Voverriding_local_map_menu_flag
))
11187 specbind (Qoverriding_terminal_local_map
, Qnil
);
11188 specbind (Qoverriding_local_map
, Qnil
);
11193 /* Run the Lucid hook. */
11194 safe_run_hooks (Qactivate_menubar_hook
);
11196 /* If it has changed current-menubar from previous value,
11197 really recompute the menu-bar from the value. */
11198 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11199 call0 (Qrecompute_lucid_menubar
);
11201 safe_run_hooks (Qmenu_bar_update_hook
);
11206 XSETFRAME (Vmenu_updating_frame
, f
);
11207 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11209 /* Redisplay the menu bar in case we changed it. */
11210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11211 || defined (HAVE_NS) || defined (USE_GTK)
11212 if (FRAME_WINDOW_P (f
))
11214 #if defined (HAVE_NS)
11215 /* All frames on Mac OS share the same menubar. So only
11216 the selected frame should be allowed to set it. */
11217 if (f
== SELECTED_FRAME ())
11219 set_frame_menubar (f
, 0, 0);
11222 /* On a terminal screen, the menu bar is an ordinary screen
11223 line, and this makes it get updated. */
11224 w
->update_mode_line
= Qt
;
11225 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11226 /* In the non-toolkit version, the menu bar is an ordinary screen
11227 line, and this makes it get updated. */
11228 w
->update_mode_line
= Qt
;
11229 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11231 unbind_to (count
, Qnil
);
11232 set_buffer_internal_1 (prev
);
11241 /***********************************************************************
11243 ***********************************************************************/
11245 #ifdef HAVE_WINDOW_SYSTEM
11248 Nominal cursor position -- where to draw output.
11249 HPOS and VPOS are window relative glyph matrix coordinates.
11250 X and Y are window relative pixel coordinates. */
11252 struct cursor_pos output_cursor
;
11256 Set the global variable output_cursor to CURSOR. All cursor
11257 positions are relative to updated_window. */
11260 set_output_cursor (struct cursor_pos
*cursor
)
11262 output_cursor
.hpos
= cursor
->hpos
;
11263 output_cursor
.vpos
= cursor
->vpos
;
11264 output_cursor
.x
= cursor
->x
;
11265 output_cursor
.y
= cursor
->y
;
11270 Set a nominal cursor position.
11272 HPOS and VPOS are column/row positions in a window glyph matrix. X
11273 and Y are window text area relative pixel positions.
11275 If this is done during an update, updated_window will contain the
11276 window that is being updated and the position is the future output
11277 cursor position for that window. If updated_window is null, use
11278 selected_window and display the cursor at the given position. */
11281 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11285 /* If updated_window is not set, work on selected_window. */
11286 if (updated_window
)
11287 w
= updated_window
;
11289 w
= XWINDOW (selected_window
);
11291 /* Set the output cursor. */
11292 output_cursor
.hpos
= hpos
;
11293 output_cursor
.vpos
= vpos
;
11294 output_cursor
.x
= x
;
11295 output_cursor
.y
= y
;
11297 /* If not called as part of an update, really display the cursor.
11298 This will also set the cursor position of W. */
11299 if (updated_window
== NULL
)
11302 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11303 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11304 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11309 #endif /* HAVE_WINDOW_SYSTEM */
11312 /***********************************************************************
11314 ***********************************************************************/
11316 #ifdef HAVE_WINDOW_SYSTEM
11318 /* Where the mouse was last time we reported a mouse event. */
11320 FRAME_PTR last_mouse_frame
;
11322 /* Tool-bar item index of the item on which a mouse button was pressed
11325 int last_tool_bar_item
;
11329 update_tool_bar_unwind (Lisp_Object frame
)
11331 selected_frame
= frame
;
11335 /* Update the tool-bar item list for frame F. This has to be done
11336 before we start to fill in any display lines. Called from
11337 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11338 and restore it here. */
11341 update_tool_bar (struct frame
*f
, int save_match_data
)
11343 #if defined (USE_GTK) || defined (HAVE_NS)
11344 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11346 int do_update
= WINDOWP (f
->tool_bar_window
)
11347 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11352 Lisp_Object window
;
11355 window
= FRAME_SELECTED_WINDOW (f
);
11356 w
= XWINDOW (window
);
11358 /* If the user has switched buffers or windows, we need to
11359 recompute to reflect the new bindings. But we'll
11360 recompute when update_mode_lines is set too; that means
11361 that people can use force-mode-line-update to request
11362 that the menu bar be recomputed. The adverse effect on
11363 the rest of the redisplay algorithm is about the same as
11364 windows_or_buffers_changed anyway. */
11365 if (windows_or_buffers_changed
11366 || !NILP (w
->update_mode_line
)
11367 || update_mode_lines
11368 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11369 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11370 != !NILP (w
->last_had_star
))
11371 || ((!NILP (Vtransient_mark_mode
)
11372 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11373 != !NILP (w
->region_showing
)))
11375 struct buffer
*prev
= current_buffer
;
11376 ptrdiff_t count
= SPECPDL_INDEX ();
11377 Lisp_Object frame
, new_tool_bar
;
11378 int new_n_tool_bar
;
11379 struct gcpro gcpro1
;
11381 /* Set current_buffer to the buffer of the selected
11382 window of the frame, so that we get the right local
11384 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11386 /* Save match data, if we must. */
11387 if (save_match_data
)
11388 record_unwind_save_match_data ();
11390 /* Make sure that we don't accidentally use bogus keymaps. */
11391 if (NILP (Voverriding_local_map_menu_flag
))
11393 specbind (Qoverriding_terminal_local_map
, Qnil
);
11394 specbind (Qoverriding_local_map
, Qnil
);
11397 GCPRO1 (new_tool_bar
);
11399 /* We must temporarily set the selected frame to this frame
11400 before calling tool_bar_items, because the calculation of
11401 the tool-bar keymap uses the selected frame (see
11402 `tool-bar-make-keymap' in tool-bar.el). */
11403 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11404 XSETFRAME (frame
, f
);
11405 selected_frame
= frame
;
11407 /* Build desired tool-bar items from keymaps. */
11408 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11411 /* Redisplay the tool-bar if we changed it. */
11412 if (new_n_tool_bar
!= f
->n_tool_bar_items
11413 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11415 /* Redisplay that happens asynchronously due to an expose event
11416 may access f->tool_bar_items. Make sure we update both
11417 variables within BLOCK_INPUT so no such event interrupts. */
11419 f
->tool_bar_items
= new_tool_bar
;
11420 f
->n_tool_bar_items
= new_n_tool_bar
;
11421 w
->update_mode_line
= Qt
;
11427 unbind_to (count
, Qnil
);
11428 set_buffer_internal_1 (prev
);
11434 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11435 F's desired tool-bar contents. F->tool_bar_items must have
11436 been set up previously by calling prepare_menu_bars. */
11439 build_desired_tool_bar_string (struct frame
*f
)
11441 int i
, size
, size_needed
;
11442 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11443 Lisp_Object image
, plist
, props
;
11445 image
= plist
= props
= Qnil
;
11446 GCPRO3 (image
, plist
, props
);
11448 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11449 Otherwise, make a new string. */
11451 /* The size of the string we might be able to reuse. */
11452 size
= (STRINGP (f
->desired_tool_bar_string
)
11453 ? SCHARS (f
->desired_tool_bar_string
)
11456 /* We need one space in the string for each image. */
11457 size_needed
= f
->n_tool_bar_items
;
11459 /* Reuse f->desired_tool_bar_string, if possible. */
11460 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11461 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11462 make_number (' '));
11465 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11466 Fremove_text_properties (make_number (0), make_number (size
),
11467 props
, f
->desired_tool_bar_string
);
11470 /* Put a `display' property on the string for the images to display,
11471 put a `menu_item' property on tool-bar items with a value that
11472 is the index of the item in F's tool-bar item vector. */
11473 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11475 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11477 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11478 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11479 int hmargin
, vmargin
, relief
, idx
, end
;
11481 /* If image is a vector, choose the image according to the
11483 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11484 if (VECTORP (image
))
11488 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11489 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11492 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11493 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11495 xassert (ASIZE (image
) >= idx
);
11496 image
= AREF (image
, idx
);
11501 /* Ignore invalid image specifications. */
11502 if (!valid_image_p (image
))
11505 /* Display the tool-bar button pressed, or depressed. */
11506 plist
= Fcopy_sequence (XCDR (image
));
11508 /* Compute margin and relief to draw. */
11509 relief
= (tool_bar_button_relief
>= 0
11510 ? tool_bar_button_relief
11511 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11512 hmargin
= vmargin
= relief
;
11514 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11515 INT_MAX
- max (hmargin
, vmargin
)))
11517 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11518 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11520 else if (CONSP (Vtool_bar_button_margin
))
11522 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11523 INT_MAX
- hmargin
))
11524 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11526 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11527 INT_MAX
- vmargin
))
11528 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11531 if (auto_raise_tool_bar_buttons_p
)
11533 /* Add a `:relief' property to the image spec if the item is
11537 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11544 /* If image is selected, display it pressed, i.e. with a
11545 negative relief. If it's not selected, display it with a
11547 plist
= Fplist_put (plist
, QCrelief
,
11549 ? make_number (-relief
)
11550 : make_number (relief
)));
11555 /* Put a margin around the image. */
11556 if (hmargin
|| vmargin
)
11558 if (hmargin
== vmargin
)
11559 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11561 plist
= Fplist_put (plist
, QCmargin
,
11562 Fcons (make_number (hmargin
),
11563 make_number (vmargin
)));
11566 /* If button is not enabled, and we don't have special images
11567 for the disabled state, make the image appear disabled by
11568 applying an appropriate algorithm to it. */
11569 if (!enabled_p
&& idx
< 0)
11570 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11572 /* Put a `display' text property on the string for the image to
11573 display. Put a `menu-item' property on the string that gives
11574 the start of this item's properties in the tool-bar items
11576 image
= Fcons (Qimage
, plist
);
11577 props
= list4 (Qdisplay
, image
,
11578 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11580 /* Let the last image hide all remaining spaces in the tool bar
11581 string. The string can be longer than needed when we reuse a
11582 previous string. */
11583 if (i
+ 1 == f
->n_tool_bar_items
)
11584 end
= SCHARS (f
->desired_tool_bar_string
);
11587 Fadd_text_properties (make_number (i
), make_number (end
),
11588 props
, f
->desired_tool_bar_string
);
11596 /* Display one line of the tool-bar of frame IT->f.
11598 HEIGHT specifies the desired height of the tool-bar line.
11599 If the actual height of the glyph row is less than HEIGHT, the
11600 row's height is increased to HEIGHT, and the icons are centered
11601 vertically in the new height.
11603 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11604 count a final empty row in case the tool-bar width exactly matches
11609 display_tool_bar_line (struct it
*it
, int height
)
11611 struct glyph_row
*row
= it
->glyph_row
;
11612 int max_x
= it
->last_visible_x
;
11613 struct glyph
*last
;
11615 prepare_desired_row (row
);
11616 row
->y
= it
->current_y
;
11618 /* Note that this isn't made use of if the face hasn't a box,
11619 so there's no need to check the face here. */
11620 it
->start_of_box_run_p
= 1;
11622 while (it
->current_x
< max_x
)
11624 int x
, n_glyphs_before
, i
, nglyphs
;
11625 struct it it_before
;
11627 /* Get the next display element. */
11628 if (!get_next_display_element (it
))
11630 /* Don't count empty row if we are counting needed tool-bar lines. */
11631 if (height
< 0 && !it
->hpos
)
11636 /* Produce glyphs. */
11637 n_glyphs_before
= row
->used
[TEXT_AREA
];
11640 PRODUCE_GLYPHS (it
);
11642 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11644 x
= it_before
.current_x
;
11645 while (i
< nglyphs
)
11647 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11649 if (x
+ glyph
->pixel_width
> max_x
)
11651 /* Glyph doesn't fit on line. Backtrack. */
11652 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11654 /* If this is the only glyph on this line, it will never fit on the
11655 tool-bar, so skip it. But ensure there is at least one glyph,
11656 so we don't accidentally disable the tool-bar. */
11657 if (n_glyphs_before
== 0
11658 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11664 x
+= glyph
->pixel_width
;
11668 /* Stop at line end. */
11669 if (ITERATOR_AT_END_OF_LINE_P (it
))
11672 set_iterator_to_next (it
, 1);
11677 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11679 /* Use default face for the border below the tool bar.
11681 FIXME: When auto-resize-tool-bars is grow-only, there is
11682 no additional border below the possibly empty tool-bar lines.
11683 So to make the extra empty lines look "normal", we have to
11684 use the tool-bar face for the border too. */
11685 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11686 it
->face_id
= DEFAULT_FACE_ID
;
11688 extend_face_to_end_of_line (it
);
11689 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11690 last
->right_box_line_p
= 1;
11691 if (last
== row
->glyphs
[TEXT_AREA
])
11692 last
->left_box_line_p
= 1;
11694 /* Make line the desired height and center it vertically. */
11695 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11697 /* Don't add more than one line height. */
11698 height
%= FRAME_LINE_HEIGHT (it
->f
);
11699 it
->max_ascent
+= height
/ 2;
11700 it
->max_descent
+= (height
+ 1) / 2;
11703 compute_line_metrics (it
);
11705 /* If line is empty, make it occupy the rest of the tool-bar. */
11706 if (!row
->displays_text_p
)
11708 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11709 row
->visible_height
= row
->height
;
11710 row
->ascent
= row
->phys_ascent
= 0;
11711 row
->extra_line_spacing
= 0;
11714 row
->full_width_p
= 1;
11715 row
->continued_p
= 0;
11716 row
->truncated_on_left_p
= 0;
11717 row
->truncated_on_right_p
= 0;
11719 it
->current_x
= it
->hpos
= 0;
11720 it
->current_y
+= row
->height
;
11726 /* Max tool-bar height. */
11728 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11729 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11731 /* Value is the number of screen lines needed to make all tool-bar
11732 items of frame F visible. The number of actual rows needed is
11733 returned in *N_ROWS if non-NULL. */
11736 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11738 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11740 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11741 the desired matrix, so use (unused) mode-line row as temporary row to
11742 avoid destroying the first tool-bar row. */
11743 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11745 /* Initialize an iterator for iteration over
11746 F->desired_tool_bar_string in the tool-bar window of frame F. */
11747 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11748 it
.first_visible_x
= 0;
11749 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11750 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11751 it
.paragraph_embedding
= L2R
;
11753 while (!ITERATOR_AT_END_P (&it
))
11755 clear_glyph_row (temp_row
);
11756 it
.glyph_row
= temp_row
;
11757 display_tool_bar_line (&it
, -1);
11759 clear_glyph_row (temp_row
);
11761 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11763 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11765 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11769 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11771 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11772 (Lisp_Object frame
)
11779 frame
= selected_frame
;
11781 CHECK_FRAME (frame
);
11782 f
= XFRAME (frame
);
11784 if (WINDOWP (f
->tool_bar_window
)
11785 && (w
= XWINDOW (f
->tool_bar_window
),
11786 WINDOW_TOTAL_LINES (w
) > 0))
11788 update_tool_bar (f
, 1);
11789 if (f
->n_tool_bar_items
)
11791 build_desired_tool_bar_string (f
);
11792 nlines
= tool_bar_lines_needed (f
, NULL
);
11796 return make_number (nlines
);
11800 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11801 height should be changed. */
11804 redisplay_tool_bar (struct frame
*f
)
11808 struct glyph_row
*row
;
11810 #if defined (USE_GTK) || defined (HAVE_NS)
11811 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11812 update_frame_tool_bar (f
);
11816 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11817 do anything. This means you must start with tool-bar-lines
11818 non-zero to get the auto-sizing effect. Or in other words, you
11819 can turn off tool-bars by specifying tool-bar-lines zero. */
11820 if (!WINDOWP (f
->tool_bar_window
)
11821 || (w
= XWINDOW (f
->tool_bar_window
),
11822 WINDOW_TOTAL_LINES (w
) == 0))
11825 /* Set up an iterator for the tool-bar window. */
11826 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11827 it
.first_visible_x
= 0;
11828 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11829 row
= it
.glyph_row
;
11831 /* Build a string that represents the contents of the tool-bar. */
11832 build_desired_tool_bar_string (f
);
11833 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11834 /* FIXME: This should be controlled by a user option. But it
11835 doesn't make sense to have an R2L tool bar if the menu bar cannot
11836 be drawn also R2L, and making the menu bar R2L is tricky due
11837 toolkit-specific code that implements it. If an R2L tool bar is
11838 ever supported, display_tool_bar_line should also be augmented to
11839 call unproduce_glyphs like display_line and display_string
11841 it
.paragraph_embedding
= L2R
;
11843 if (f
->n_tool_bar_rows
== 0)
11847 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11848 nlines
!= WINDOW_TOTAL_LINES (w
)))
11851 int old_height
= WINDOW_TOTAL_LINES (w
);
11853 XSETFRAME (frame
, f
);
11854 Fmodify_frame_parameters (frame
,
11855 Fcons (Fcons (Qtool_bar_lines
,
11856 make_number (nlines
)),
11858 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11860 clear_glyph_matrix (w
->desired_matrix
);
11861 fonts_changed_p
= 1;
11867 /* Display as many lines as needed to display all tool-bar items. */
11869 if (f
->n_tool_bar_rows
> 0)
11871 int border
, rows
, height
, extra
;
11873 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11874 border
= XINT (Vtool_bar_border
);
11875 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11876 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11877 else if (EQ (Vtool_bar_border
, Qborder_width
))
11878 border
= f
->border_width
;
11884 rows
= f
->n_tool_bar_rows
;
11885 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11886 extra
= it
.last_visible_y
- border
- height
* rows
;
11888 while (it
.current_y
< it
.last_visible_y
)
11891 if (extra
> 0 && rows
-- > 0)
11893 h
= (extra
+ rows
- 1) / rows
;
11896 display_tool_bar_line (&it
, height
+ h
);
11901 while (it
.current_y
< it
.last_visible_y
)
11902 display_tool_bar_line (&it
, 0);
11905 /* It doesn't make much sense to try scrolling in the tool-bar
11906 window, so don't do it. */
11907 w
->desired_matrix
->no_scrolling_p
= 1;
11908 w
->must_be_updated_p
= 1;
11910 if (!NILP (Vauto_resize_tool_bars
))
11912 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11913 int change_height_p
= 0;
11915 /* If we couldn't display everything, change the tool-bar's
11916 height if there is room for more. */
11917 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11918 && it
.current_y
< max_tool_bar_height
)
11919 change_height_p
= 1;
11921 row
= it
.glyph_row
- 1;
11923 /* If there are blank lines at the end, except for a partially
11924 visible blank line at the end that is smaller than
11925 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11926 if (!row
->displays_text_p
11927 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11928 change_height_p
= 1;
11930 /* If row displays tool-bar items, but is partially visible,
11931 change the tool-bar's height. */
11932 if (row
->displays_text_p
11933 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11934 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11935 change_height_p
= 1;
11937 /* Resize windows as needed by changing the `tool-bar-lines'
11938 frame parameter. */
11939 if (change_height_p
)
11942 int old_height
= WINDOW_TOTAL_LINES (w
);
11944 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11946 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11947 && !f
->minimize_tool_bar_window_p
)
11948 ? (nlines
> old_height
)
11949 : (nlines
!= old_height
));
11950 f
->minimize_tool_bar_window_p
= 0;
11952 if (change_height_p
)
11954 XSETFRAME (frame
, f
);
11955 Fmodify_frame_parameters (frame
,
11956 Fcons (Fcons (Qtool_bar_lines
,
11957 make_number (nlines
)),
11959 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11961 clear_glyph_matrix (w
->desired_matrix
);
11962 f
->n_tool_bar_rows
= nrows
;
11963 fonts_changed_p
= 1;
11970 f
->minimize_tool_bar_window_p
= 0;
11975 /* Get information about the tool-bar item which is displayed in GLYPH
11976 on frame F. Return in *PROP_IDX the index where tool-bar item
11977 properties start in F->tool_bar_items. Value is zero if
11978 GLYPH doesn't display a tool-bar item. */
11981 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11987 /* This function can be called asynchronously, which means we must
11988 exclude any possibility that Fget_text_property signals an
11990 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11991 charpos
= max (0, charpos
);
11993 /* Get the text property `menu-item' at pos. The value of that
11994 property is the start index of this item's properties in
11995 F->tool_bar_items. */
11996 prop
= Fget_text_property (make_number (charpos
),
11997 Qmenu_item
, f
->current_tool_bar_string
);
11998 if (INTEGERP (prop
))
12000 *prop_idx
= XINT (prop
);
12010 /* Get information about the tool-bar item at position X/Y on frame F.
12011 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12012 the current matrix of the tool-bar window of F, or NULL if not
12013 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12014 item in F->tool_bar_items. Value is
12016 -1 if X/Y is not on a tool-bar item
12017 0 if X/Y is on the same item that was highlighted before.
12021 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12022 int *hpos
, int *vpos
, int *prop_idx
)
12024 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12025 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12028 /* Find the glyph under X/Y. */
12029 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12030 if (*glyph
== NULL
)
12033 /* Get the start of this tool-bar item's properties in
12034 f->tool_bar_items. */
12035 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12038 /* Is mouse on the highlighted item? */
12039 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12040 && *vpos
>= hlinfo
->mouse_face_beg_row
12041 && *vpos
<= hlinfo
->mouse_face_end_row
12042 && (*vpos
> hlinfo
->mouse_face_beg_row
12043 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12044 && (*vpos
< hlinfo
->mouse_face_end_row
12045 || *hpos
< hlinfo
->mouse_face_end_col
12046 || hlinfo
->mouse_face_past_end
))
12054 Handle mouse button event on the tool-bar of frame F, at
12055 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12056 0 for button release. MODIFIERS is event modifiers for button
12060 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12063 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12064 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12065 int hpos
, vpos
, prop_idx
;
12066 struct glyph
*glyph
;
12067 Lisp_Object enabled_p
;
12069 /* If not on the highlighted tool-bar item, return. */
12070 frame_to_window_pixel_xy (w
, &x
, &y
);
12071 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12074 /* If item is disabled, do nothing. */
12075 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12076 if (NILP (enabled_p
))
12081 /* Show item in pressed state. */
12082 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12083 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12084 last_tool_bar_item
= prop_idx
;
12088 Lisp_Object key
, frame
;
12089 struct input_event event
;
12090 EVENT_INIT (event
);
12092 /* Show item in released state. */
12093 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12094 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12096 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12098 XSETFRAME (frame
, f
);
12099 event
.kind
= TOOL_BAR_EVENT
;
12100 event
.frame_or_window
= frame
;
12102 kbd_buffer_store_event (&event
);
12104 event
.kind
= TOOL_BAR_EVENT
;
12105 event
.frame_or_window
= frame
;
12107 event
.modifiers
= modifiers
;
12108 kbd_buffer_store_event (&event
);
12109 last_tool_bar_item
= -1;
12114 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12115 tool-bar window-relative coordinates X/Y. Called from
12116 note_mouse_highlight. */
12119 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12121 Lisp_Object window
= f
->tool_bar_window
;
12122 struct window
*w
= XWINDOW (window
);
12123 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12124 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12126 struct glyph
*glyph
;
12127 struct glyph_row
*row
;
12129 Lisp_Object enabled_p
;
12131 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12132 int mouse_down_p
, rc
;
12134 /* Function note_mouse_highlight is called with negative X/Y
12135 values when mouse moves outside of the frame. */
12136 if (x
<= 0 || y
<= 0)
12138 clear_mouse_face (hlinfo
);
12142 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12145 /* Not on tool-bar item. */
12146 clear_mouse_face (hlinfo
);
12150 /* On same tool-bar item as before. */
12151 goto set_help_echo
;
12153 clear_mouse_face (hlinfo
);
12155 /* Mouse is down, but on different tool-bar item? */
12156 mouse_down_p
= (dpyinfo
->grabbed
12157 && f
== last_mouse_frame
12158 && FRAME_LIVE_P (f
));
12160 && last_tool_bar_item
!= prop_idx
)
12163 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12164 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12166 /* If tool-bar item is not enabled, don't highlight it. */
12167 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12168 if (!NILP (enabled_p
))
12170 /* Compute the x-position of the glyph. In front and past the
12171 image is a space. We include this in the highlighted area. */
12172 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12173 for (i
= x
= 0; i
< hpos
; ++i
)
12174 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12176 /* Record this as the current active region. */
12177 hlinfo
->mouse_face_beg_col
= hpos
;
12178 hlinfo
->mouse_face_beg_row
= vpos
;
12179 hlinfo
->mouse_face_beg_x
= x
;
12180 hlinfo
->mouse_face_beg_y
= row
->y
;
12181 hlinfo
->mouse_face_past_end
= 0;
12183 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12184 hlinfo
->mouse_face_end_row
= vpos
;
12185 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12186 hlinfo
->mouse_face_end_y
= row
->y
;
12187 hlinfo
->mouse_face_window
= window
;
12188 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12190 /* Display it as active. */
12191 show_mouse_face (hlinfo
, draw
);
12192 hlinfo
->mouse_face_image_state
= draw
;
12197 /* Set help_echo_string to a help string to display for this tool-bar item.
12198 XTread_socket does the rest. */
12199 help_echo_object
= help_echo_window
= Qnil
;
12200 help_echo_pos
= -1;
12201 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12202 if (NILP (help_echo_string
))
12203 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12206 #endif /* HAVE_WINDOW_SYSTEM */
12210 /************************************************************************
12211 Horizontal scrolling
12212 ************************************************************************/
12214 static int hscroll_window_tree (Lisp_Object
);
12215 static int hscroll_windows (Lisp_Object
);
12217 /* For all leaf windows in the window tree rooted at WINDOW, set their
12218 hscroll value so that PT is (i) visible in the window, and (ii) so
12219 that it is not within a certain margin at the window's left and
12220 right border. Value is non-zero if any window's hscroll has been
12224 hscroll_window_tree (Lisp_Object window
)
12226 int hscrolled_p
= 0;
12227 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12228 int hscroll_step_abs
= 0;
12229 double hscroll_step_rel
= 0;
12231 if (hscroll_relative_p
)
12233 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12234 if (hscroll_step_rel
< 0)
12236 hscroll_relative_p
= 0;
12237 hscroll_step_abs
= 0;
12240 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12242 hscroll_step_abs
= XINT (Vhscroll_step
);
12243 if (hscroll_step_abs
< 0)
12244 hscroll_step_abs
= 0;
12247 hscroll_step_abs
= 0;
12249 while (WINDOWP (window
))
12251 struct window
*w
= XWINDOW (window
);
12253 if (WINDOWP (w
->hchild
))
12254 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12255 else if (WINDOWP (w
->vchild
))
12256 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12257 else if (w
->cursor
.vpos
>= 0)
12260 int text_area_width
;
12261 struct glyph_row
*current_cursor_row
12262 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12263 struct glyph_row
*desired_cursor_row
12264 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12265 struct glyph_row
*cursor_row
12266 = (desired_cursor_row
->enabled_p
12267 ? desired_cursor_row
12268 : current_cursor_row
);
12269 int row_r2l_p
= cursor_row
->reversed_p
;
12271 text_area_width
= window_box_width (w
, TEXT_AREA
);
12273 /* Scroll when cursor is inside this scroll margin. */
12274 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12276 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12277 /* For left-to-right rows, hscroll when cursor is either
12278 (i) inside the right hscroll margin, or (ii) if it is
12279 inside the left margin and the window is already
12282 && ((XFASTINT (w
->hscroll
)
12283 && w
->cursor
.x
<= h_margin
)
12284 || (cursor_row
->enabled_p
12285 && cursor_row
->truncated_on_right_p
12286 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12287 /* For right-to-left rows, the logic is similar,
12288 except that rules for scrolling to left and right
12289 are reversed. E.g., if cursor.x <= h_margin, we
12290 need to hscroll "to the right" unconditionally,
12291 and that will scroll the screen to the left so as
12292 to reveal the next portion of the row. */
12294 && ((cursor_row
->enabled_p
12295 /* FIXME: It is confusing to set the
12296 truncated_on_right_p flag when R2L rows
12297 are actually truncated on the left. */
12298 && cursor_row
->truncated_on_right_p
12299 && w
->cursor
.x
<= h_margin
)
12300 || (XFASTINT (w
->hscroll
)
12301 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12305 struct buffer
*saved_current_buffer
;
12309 /* Find point in a display of infinite width. */
12310 saved_current_buffer
= current_buffer
;
12311 current_buffer
= XBUFFER (w
->buffer
);
12313 if (w
== XWINDOW (selected_window
))
12317 pt
= marker_position (w
->pointm
);
12318 pt
= max (BEGV
, pt
);
12322 /* Move iterator to pt starting at cursor_row->start in
12323 a line with infinite width. */
12324 init_to_row_start (&it
, w
, cursor_row
);
12325 it
.last_visible_x
= INFINITY
;
12326 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12327 current_buffer
= saved_current_buffer
;
12329 /* Position cursor in window. */
12330 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12331 hscroll
= max (0, (it
.current_x
12332 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12333 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12334 : (text_area_width
/ 2))))
12335 / FRAME_COLUMN_WIDTH (it
.f
);
12336 else if ((!row_r2l_p
12337 && w
->cursor
.x
>= text_area_width
- h_margin
)
12338 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12340 if (hscroll_relative_p
)
12341 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12344 wanted_x
= text_area_width
12345 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12348 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12352 if (hscroll_relative_p
)
12353 wanted_x
= text_area_width
* hscroll_step_rel
12356 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12359 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12361 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
12363 /* Don't prevent redisplay optimizations if hscroll
12364 hasn't changed, as it will unnecessarily slow down
12366 if (XFASTINT (w
->hscroll
) != hscroll
)
12368 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12369 w
->hscroll
= make_number (hscroll
);
12378 /* Value is non-zero if hscroll of any leaf window has been changed. */
12379 return hscrolled_p
;
12383 /* Set hscroll so that cursor is visible and not inside horizontal
12384 scroll margins for all windows in the tree rooted at WINDOW. See
12385 also hscroll_window_tree above. Value is non-zero if any window's
12386 hscroll has been changed. If it has, desired matrices on the frame
12387 of WINDOW are cleared. */
12390 hscroll_windows (Lisp_Object window
)
12392 int hscrolled_p
= hscroll_window_tree (window
);
12394 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12395 return hscrolled_p
;
12400 /************************************************************************
12402 ************************************************************************/
12404 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12405 to a non-zero value. This is sometimes handy to have in a debugger
12410 /* First and last unchanged row for try_window_id. */
12412 static int debug_first_unchanged_at_end_vpos
;
12413 static int debug_last_unchanged_at_beg_vpos
;
12415 /* Delta vpos and y. */
12417 static int debug_dvpos
, debug_dy
;
12419 /* Delta in characters and bytes for try_window_id. */
12421 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12423 /* Values of window_end_pos and window_end_vpos at the end of
12426 static ptrdiff_t debug_end_vpos
;
12428 /* Append a string to W->desired_matrix->method. FMT is a printf
12429 format string. If trace_redisplay_p is non-zero also printf the
12430 resulting string to stderr. */
12432 static void debug_method_add (struct window
*, char const *, ...)
12433 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12436 debug_method_add (struct window
*w
, char const *fmt
, ...)
12439 char *method
= w
->desired_matrix
->method
;
12440 int len
= strlen (method
);
12441 int size
= sizeof w
->desired_matrix
->method
;
12442 int remaining
= size
- len
- 1;
12445 va_start (ap
, fmt
);
12446 vsprintf (buffer
, fmt
, ap
);
12448 if (len
&& remaining
)
12451 --remaining
, ++len
;
12454 strncpy (method
+ len
, buffer
, remaining
);
12456 if (trace_redisplay_p
)
12457 fprintf (stderr
, "%p (%s): %s\n",
12459 ((BUFFERP (w
->buffer
)
12460 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12461 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12466 #endif /* GLYPH_DEBUG */
12469 /* Value is non-zero if all changes in window W, which displays
12470 current_buffer, are in the text between START and END. START is a
12471 buffer position, END is given as a distance from Z. Used in
12472 redisplay_internal for display optimization. */
12475 text_outside_line_unchanged_p (struct window
*w
,
12476 ptrdiff_t start
, ptrdiff_t end
)
12478 int unchanged_p
= 1;
12480 /* If text or overlays have changed, see where. */
12481 if (XFASTINT (w
->last_modified
) < MODIFF
12482 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12484 /* Gap in the line? */
12485 if (GPT
< start
|| Z
- GPT
< end
)
12488 /* Changes start in front of the line, or end after it? */
12490 && (BEG_UNCHANGED
< start
- 1
12491 || END_UNCHANGED
< end
))
12494 /* If selective display, can't optimize if changes start at the
12495 beginning of the line. */
12497 && INTEGERP (BVAR (current_buffer
, selective_display
))
12498 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12499 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12502 /* If there are overlays at the start or end of the line, these
12503 may have overlay strings with newlines in them. A change at
12504 START, for instance, may actually concern the display of such
12505 overlay strings as well, and they are displayed on different
12506 lines. So, quickly rule out this case. (For the future, it
12507 might be desirable to implement something more telling than
12508 just BEG/END_UNCHANGED.) */
12511 if (BEG
+ BEG_UNCHANGED
== start
12512 && overlay_touches_p (start
))
12514 if (END_UNCHANGED
== end
12515 && overlay_touches_p (Z
- end
))
12519 /* Under bidi reordering, adding or deleting a character in the
12520 beginning of a paragraph, before the first strong directional
12521 character, can change the base direction of the paragraph (unless
12522 the buffer specifies a fixed paragraph direction), which will
12523 require to redisplay the whole paragraph. It might be worthwhile
12524 to find the paragraph limits and widen the range of redisplayed
12525 lines to that, but for now just give up this optimization. */
12526 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12527 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12531 return unchanged_p
;
12535 /* Do a frame update, taking possible shortcuts into account. This is
12536 the main external entry point for redisplay.
12538 If the last redisplay displayed an echo area message and that message
12539 is no longer requested, we clear the echo area or bring back the
12540 mini-buffer if that is in use. */
12545 redisplay_internal ();
12550 overlay_arrow_string_or_property (Lisp_Object var
)
12554 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12557 return Voverlay_arrow_string
;
12560 /* Return 1 if there are any overlay-arrows in current_buffer. */
12562 overlay_arrow_in_current_buffer_p (void)
12566 for (vlist
= Voverlay_arrow_variable_list
;
12568 vlist
= XCDR (vlist
))
12570 Lisp_Object var
= XCAR (vlist
);
12573 if (!SYMBOLP (var
))
12575 val
= find_symbol_value (var
);
12577 && current_buffer
== XMARKER (val
)->buffer
)
12584 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12588 overlay_arrows_changed_p (void)
12592 for (vlist
= Voverlay_arrow_variable_list
;
12594 vlist
= XCDR (vlist
))
12596 Lisp_Object var
= XCAR (vlist
);
12597 Lisp_Object val
, pstr
;
12599 if (!SYMBOLP (var
))
12601 val
= find_symbol_value (var
);
12602 if (!MARKERP (val
))
12604 if (! EQ (COERCE_MARKER (val
),
12605 Fget (var
, Qlast_arrow_position
))
12606 || ! (pstr
= overlay_arrow_string_or_property (var
),
12607 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12613 /* Mark overlay arrows to be updated on next redisplay. */
12616 update_overlay_arrows (int up_to_date
)
12620 for (vlist
= Voverlay_arrow_variable_list
;
12622 vlist
= XCDR (vlist
))
12624 Lisp_Object var
= XCAR (vlist
);
12626 if (!SYMBOLP (var
))
12629 if (up_to_date
> 0)
12631 Lisp_Object val
= find_symbol_value (var
);
12632 Fput (var
, Qlast_arrow_position
,
12633 COERCE_MARKER (val
));
12634 Fput (var
, Qlast_arrow_string
,
12635 overlay_arrow_string_or_property (var
));
12637 else if (up_to_date
< 0
12638 || !NILP (Fget (var
, Qlast_arrow_position
)))
12640 Fput (var
, Qlast_arrow_position
, Qt
);
12641 Fput (var
, Qlast_arrow_string
, Qt
);
12647 /* Return overlay arrow string to display at row.
12648 Return integer (bitmap number) for arrow bitmap in left fringe.
12649 Return nil if no overlay arrow. */
12652 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12656 for (vlist
= Voverlay_arrow_variable_list
;
12658 vlist
= XCDR (vlist
))
12660 Lisp_Object var
= XCAR (vlist
);
12663 if (!SYMBOLP (var
))
12666 val
= find_symbol_value (var
);
12669 && current_buffer
== XMARKER (val
)->buffer
12670 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12672 if (FRAME_WINDOW_P (it
->f
)
12673 /* FIXME: if ROW->reversed_p is set, this should test
12674 the right fringe, not the left one. */
12675 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12677 #ifdef HAVE_WINDOW_SYSTEM
12678 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12681 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12682 return make_number (fringe_bitmap
);
12685 return make_number (-1); /* Use default arrow bitmap */
12687 return overlay_arrow_string_or_property (var
);
12694 /* Return 1 if point moved out of or into a composition. Otherwise
12695 return 0. PREV_BUF and PREV_PT are the last point buffer and
12696 position. BUF and PT are the current point buffer and position. */
12699 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12700 struct buffer
*buf
, ptrdiff_t pt
)
12702 ptrdiff_t start
, end
;
12704 Lisp_Object buffer
;
12706 XSETBUFFER (buffer
, buf
);
12707 /* Check a composition at the last point if point moved within the
12709 if (prev_buf
== buf
)
12712 /* Point didn't move. */
12715 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12716 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12717 && COMPOSITION_VALID_P (start
, end
, prop
)
12718 && start
< prev_pt
&& end
> prev_pt
)
12719 /* The last point was within the composition. Return 1 iff
12720 point moved out of the composition. */
12721 return (pt
<= start
|| pt
>= end
);
12724 /* Check a composition at the current point. */
12725 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12726 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12727 && COMPOSITION_VALID_P (start
, end
, prop
)
12728 && start
< pt
&& end
> pt
);
12732 /* Reconsider the setting of B->clip_changed which is displayed
12736 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12738 if (b
->clip_changed
12739 && !NILP (w
->window_end_valid
)
12740 && w
->current_matrix
->buffer
== b
12741 && w
->current_matrix
->zv
== BUF_ZV (b
)
12742 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12743 b
->clip_changed
= 0;
12745 /* If display wasn't paused, and W is not a tool bar window, see if
12746 point has been moved into or out of a composition. In that case,
12747 we set b->clip_changed to 1 to force updating the screen. If
12748 b->clip_changed has already been set to 1, we can skip this
12750 if (!b
->clip_changed
12751 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12755 if (w
== XWINDOW (selected_window
))
12758 pt
= marker_position (w
->pointm
);
12760 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12761 || pt
!= XINT (w
->last_point
))
12762 && check_point_in_composition (w
->current_matrix
->buffer
,
12763 XINT (w
->last_point
),
12764 XBUFFER (w
->buffer
), pt
))
12765 b
->clip_changed
= 1;
12770 /* Select FRAME to forward the values of frame-local variables into C
12771 variables so that the redisplay routines can access those values
12775 select_frame_for_redisplay (Lisp_Object frame
)
12777 Lisp_Object tail
, tem
;
12778 Lisp_Object old
= selected_frame
;
12779 struct Lisp_Symbol
*sym
;
12781 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12783 selected_frame
= frame
;
12786 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12787 if (CONSP (XCAR (tail
))
12788 && (tem
= XCAR (XCAR (tail
)),
12790 && (sym
= indirect_variable (XSYMBOL (tem
)),
12791 sym
->redirect
== SYMBOL_LOCALIZED
)
12792 && sym
->val
.blv
->frame_local
)
12793 /* Use find_symbol_value rather than Fsymbol_value
12794 to avoid an error if it is void. */
12795 find_symbol_value (tem
);
12796 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12800 #define STOP_POLLING \
12801 do { if (! polling_stopped_here) stop_polling (); \
12802 polling_stopped_here = 1; } while (0)
12804 #define RESUME_POLLING \
12805 do { if (polling_stopped_here) start_polling (); \
12806 polling_stopped_here = 0; } while (0)
12809 /* Perhaps in the future avoid recentering windows if it
12810 is not necessary; currently that causes some problems. */
12813 redisplay_internal (void)
12815 struct window
*w
= XWINDOW (selected_window
);
12819 int must_finish
= 0;
12820 struct text_pos tlbufpos
, tlendpos
;
12821 int number_of_visible_frames
;
12822 ptrdiff_t count
, count1
;
12824 int polling_stopped_here
= 0;
12825 Lisp_Object old_frame
= selected_frame
;
12827 /* Non-zero means redisplay has to consider all windows on all
12828 frames. Zero means, only selected_window is considered. */
12829 int consider_all_windows_p
;
12831 /* Non-zero means redisplay has to redisplay the miniwindow */
12832 int update_miniwindow_p
= 0;
12834 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12836 /* No redisplay if running in batch mode or frame is not yet fully
12837 initialized, or redisplay is explicitly turned off by setting
12838 Vinhibit_redisplay. */
12839 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12840 || !NILP (Vinhibit_redisplay
))
12843 /* Don't examine these until after testing Vinhibit_redisplay.
12844 When Emacs is shutting down, perhaps because its connection to
12845 X has dropped, we should not look at them at all. */
12846 fr
= XFRAME (w
->frame
);
12847 sf
= SELECTED_FRAME ();
12849 if (!fr
->glyphs_initialized_p
)
12852 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12853 if (popup_activated ())
12857 /* I don't think this happens but let's be paranoid. */
12858 if (redisplaying_p
)
12861 /* Record a function that resets redisplaying_p to its old value
12862 when we leave this function. */
12863 count
= SPECPDL_INDEX ();
12864 record_unwind_protect (unwind_redisplay
,
12865 Fcons (make_number (redisplaying_p
), selected_frame
));
12867 specbind (Qinhibit_free_realized_faces
, Qnil
);
12870 Lisp_Object tail
, frame
;
12872 FOR_EACH_FRAME (tail
, frame
)
12874 struct frame
*f
= XFRAME (frame
);
12875 f
->already_hscrolled_p
= 0;
12880 /* Remember the currently selected window. */
12883 if (!EQ (old_frame
, selected_frame
)
12884 && FRAME_LIVE_P (XFRAME (old_frame
)))
12885 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12886 selected_frame and selected_window to be temporarily out-of-sync so
12887 when we come back here via `goto retry', we need to resync because we
12888 may need to run Elisp code (via prepare_menu_bars). */
12889 select_frame_for_redisplay (old_frame
);
12892 reconsider_clip_changes (w
, current_buffer
);
12893 last_escape_glyph_frame
= NULL
;
12894 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12895 last_glyphless_glyph_frame
= NULL
;
12896 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12898 /* If new fonts have been loaded that make a glyph matrix adjustment
12899 necessary, do it. */
12900 if (fonts_changed_p
)
12902 adjust_glyphs (NULL
);
12903 ++windows_or_buffers_changed
;
12904 fonts_changed_p
= 0;
12907 /* If face_change_count is non-zero, init_iterator will free all
12908 realized faces, which includes the faces referenced from current
12909 matrices. So, we can't reuse current matrices in this case. */
12910 if (face_change_count
)
12911 ++windows_or_buffers_changed
;
12913 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12914 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12916 /* Since frames on a single ASCII terminal share the same
12917 display area, displaying a different frame means redisplay
12918 the whole thing. */
12919 windows_or_buffers_changed
++;
12920 SET_FRAME_GARBAGED (sf
);
12922 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12924 FRAME_TTY (sf
)->previous_frame
= sf
;
12927 /* Set the visible flags for all frames. Do this before checking
12928 for resized or garbaged frames; they want to know if their frames
12929 are visible. See the comment in frame.h for
12930 FRAME_SAMPLE_VISIBILITY. */
12932 Lisp_Object tail
, frame
;
12934 number_of_visible_frames
= 0;
12936 FOR_EACH_FRAME (tail
, frame
)
12938 struct frame
*f
= XFRAME (frame
);
12940 FRAME_SAMPLE_VISIBILITY (f
);
12941 if (FRAME_VISIBLE_P (f
))
12942 ++number_of_visible_frames
;
12943 clear_desired_matrices (f
);
12947 /* Notice any pending interrupt request to change frame size. */
12948 do_pending_window_change (1);
12950 /* do_pending_window_change could change the selected_window due to
12951 frame resizing which makes the selected window too small. */
12952 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12955 reconsider_clip_changes (w
, current_buffer
);
12958 /* Clear frames marked as garbaged. */
12959 if (frame_garbaged
)
12960 clear_garbaged_frames ();
12962 /* Build menubar and tool-bar items. */
12963 if (NILP (Vmemory_full
))
12964 prepare_menu_bars ();
12966 if (windows_or_buffers_changed
)
12967 update_mode_lines
++;
12969 /* Detect case that we need to write or remove a star in the mode line. */
12970 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12972 w
->update_mode_line
= Qt
;
12973 if (buffer_shared
> 1)
12974 update_mode_lines
++;
12977 /* Avoid invocation of point motion hooks by `current_column' below. */
12978 count1
= SPECPDL_INDEX ();
12979 specbind (Qinhibit_point_motion_hooks
, Qt
);
12981 /* If %c is in the mode line, update it if needed. */
12982 if (!NILP (w
->column_number_displayed
)
12983 /* This alternative quickly identifies a common case
12984 where no change is needed. */
12985 && !(PT
== XFASTINT (w
->last_point
)
12986 && XFASTINT (w
->last_modified
) >= MODIFF
12987 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12988 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12989 w
->update_mode_line
= Qt
;
12991 unbind_to (count1
, Qnil
);
12993 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12995 /* The variable buffer_shared is set in redisplay_window and
12996 indicates that we redisplay a buffer in different windows. See
12998 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12999 || cursor_type_changed
);
13001 /* If specs for an arrow have changed, do thorough redisplay
13002 to ensure we remove any arrow that should no longer exist. */
13003 if (overlay_arrows_changed_p ())
13004 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13006 /* Normally the message* functions will have already displayed and
13007 updated the echo area, but the frame may have been trashed, or
13008 the update may have been preempted, so display the echo area
13009 again here. Checking message_cleared_p captures the case that
13010 the echo area should be cleared. */
13011 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13012 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13013 || (message_cleared_p
13014 && minibuf_level
== 0
13015 /* If the mini-window is currently selected, this means the
13016 echo-area doesn't show through. */
13017 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13019 int window_height_changed_p
= echo_area_display (0);
13021 if (message_cleared_p
)
13022 update_miniwindow_p
= 1;
13026 /* If we don't display the current message, don't clear the
13027 message_cleared_p flag, because, if we did, we wouldn't clear
13028 the echo area in the next redisplay which doesn't preserve
13030 if (!display_last_displayed_message_p
)
13031 message_cleared_p
= 0;
13033 if (fonts_changed_p
)
13035 else if (window_height_changed_p
)
13037 consider_all_windows_p
= 1;
13038 ++update_mode_lines
;
13039 ++windows_or_buffers_changed
;
13041 /* If window configuration was changed, frames may have been
13042 marked garbaged. Clear them or we will experience
13043 surprises wrt scrolling. */
13044 if (frame_garbaged
)
13045 clear_garbaged_frames ();
13048 else if (EQ (selected_window
, minibuf_window
)
13049 && (current_buffer
->clip_changed
13050 || XFASTINT (w
->last_modified
) < MODIFF
13051 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
13052 && resize_mini_window (w
, 0))
13054 /* Resized active mini-window to fit the size of what it is
13055 showing if its contents might have changed. */
13057 /* FIXME: this causes all frames to be updated, which seems unnecessary
13058 since only the current frame needs to be considered. This function needs
13059 to be rewritten with two variables, consider_all_windows and
13060 consider_all_frames. */
13061 consider_all_windows_p
= 1;
13062 ++windows_or_buffers_changed
;
13063 ++update_mode_lines
;
13065 /* If window configuration was changed, frames may have been
13066 marked garbaged. Clear them or we will experience
13067 surprises wrt scrolling. */
13068 if (frame_garbaged
)
13069 clear_garbaged_frames ();
13073 /* If showing the region, and mark has changed, we must redisplay
13074 the whole window. The assignment to this_line_start_pos prevents
13075 the optimization directly below this if-statement. */
13076 if (((!NILP (Vtransient_mark_mode
)
13077 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13078 != !NILP (w
->region_showing
))
13079 || (!NILP (w
->region_showing
)
13080 && !EQ (w
->region_showing
,
13081 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13082 CHARPOS (this_line_start_pos
) = 0;
13084 /* Optimize the case that only the line containing the cursor in the
13085 selected window has changed. Variables starting with this_ are
13086 set in display_line and record information about the line
13087 containing the cursor. */
13088 tlbufpos
= this_line_start_pos
;
13089 tlendpos
= this_line_end_pos
;
13090 if (!consider_all_windows_p
13091 && CHARPOS (tlbufpos
) > 0
13092 && NILP (w
->update_mode_line
)
13093 && !current_buffer
->clip_changed
13094 && !current_buffer
->prevent_redisplay_optimizations_p
13095 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13096 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13097 /* Make sure recorded data applies to current buffer, etc. */
13098 && this_line_buffer
== current_buffer
13099 && current_buffer
== XBUFFER (w
->buffer
)
13100 && NILP (w
->force_start
)
13101 && NILP (w
->optional_new_start
)
13102 /* Point must be on the line that we have info recorded about. */
13103 && PT
>= CHARPOS (tlbufpos
)
13104 && PT
<= Z
- CHARPOS (tlendpos
)
13105 /* All text outside that line, including its final newline,
13106 must be unchanged. */
13107 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13108 CHARPOS (tlendpos
)))
13110 if (CHARPOS (tlbufpos
) > BEGV
13111 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13112 && (CHARPOS (tlbufpos
) == ZV
13113 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13114 /* Former continuation line has disappeared by becoming empty. */
13116 else if (XFASTINT (w
->last_modified
) < MODIFF
13117 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
13118 || MINI_WINDOW_P (w
))
13120 /* We have to handle the case of continuation around a
13121 wide-column character (see the comment in indent.c around
13124 For instance, in the following case:
13126 -------- Insert --------
13127 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13128 J_I_ ==> J_I_ `^^' are cursors.
13132 As we have to redraw the line above, we cannot use this
13136 int line_height_before
= this_line_pixel_height
;
13138 /* Note that start_display will handle the case that the
13139 line starting at tlbufpos is a continuation line. */
13140 start_display (&it
, w
, tlbufpos
);
13142 /* Implementation note: It this still necessary? */
13143 if (it
.current_x
!= this_line_start_x
)
13146 TRACE ((stderr
, "trying display optimization 1\n"));
13147 w
->cursor
.vpos
= -1;
13148 overlay_arrow_seen
= 0;
13149 it
.vpos
= this_line_vpos
;
13150 it
.current_y
= this_line_y
;
13151 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13152 display_line (&it
);
13154 /* If line contains point, is not continued,
13155 and ends at same distance from eob as before, we win. */
13156 if (w
->cursor
.vpos
>= 0
13157 /* Line is not continued, otherwise this_line_start_pos
13158 would have been set to 0 in display_line. */
13159 && CHARPOS (this_line_start_pos
)
13160 /* Line ends as before. */
13161 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13162 /* Line has same height as before. Otherwise other lines
13163 would have to be shifted up or down. */
13164 && this_line_pixel_height
== line_height_before
)
13166 /* If this is not the window's last line, we must adjust
13167 the charstarts of the lines below. */
13168 if (it
.current_y
< it
.last_visible_y
)
13170 struct glyph_row
*row
13171 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13172 ptrdiff_t delta
, delta_bytes
;
13174 /* We used to distinguish between two cases here,
13175 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13176 when the line ends in a newline or the end of the
13177 buffer's accessible portion. But both cases did
13178 the same, so they were collapsed. */
13180 - CHARPOS (tlendpos
)
13181 - MATRIX_ROW_START_CHARPOS (row
));
13182 delta_bytes
= (Z_BYTE
13183 - BYTEPOS (tlendpos
)
13184 - MATRIX_ROW_START_BYTEPOS (row
));
13186 increment_matrix_positions (w
->current_matrix
,
13187 this_line_vpos
+ 1,
13188 w
->current_matrix
->nrows
,
13189 delta
, delta_bytes
);
13192 /* If this row displays text now but previously didn't,
13193 or vice versa, w->window_end_vpos may have to be
13195 if ((it
.glyph_row
- 1)->displays_text_p
)
13197 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13198 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13200 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13201 && this_line_vpos
> 0)
13202 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13203 w
->window_end_valid
= Qnil
;
13205 /* Update hint: No need to try to scroll in update_window. */
13206 w
->desired_matrix
->no_scrolling_p
= 1;
13209 *w
->desired_matrix
->method
= 0;
13210 debug_method_add (w
, "optimization 1");
13212 #ifdef HAVE_WINDOW_SYSTEM
13213 update_window_fringes (w
, 0);
13220 else if (/* Cursor position hasn't changed. */
13221 PT
== XFASTINT (w
->last_point
)
13222 /* Make sure the cursor was last displayed
13223 in this window. Otherwise we have to reposition it. */
13224 && 0 <= w
->cursor
.vpos
13225 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13229 do_pending_window_change (1);
13230 /* If selected_window changed, redisplay again. */
13231 if (WINDOWP (selected_window
)
13232 && (w
= XWINDOW (selected_window
)) != sw
)
13235 /* We used to always goto end_of_redisplay here, but this
13236 isn't enough if we have a blinking cursor. */
13237 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13238 goto end_of_redisplay
;
13242 /* If highlighting the region, or if the cursor is in the echo area,
13243 then we can't just move the cursor. */
13244 else if (! (!NILP (Vtransient_mark_mode
)
13245 && !NILP (BVAR (current_buffer
, mark_active
)))
13246 && (EQ (selected_window
,
13247 BVAR (current_buffer
, last_selected_window
))
13248 || highlight_nonselected_windows
)
13249 && NILP (w
->region_showing
)
13250 && NILP (Vshow_trailing_whitespace
)
13251 && !cursor_in_echo_area
)
13254 struct glyph_row
*row
;
13256 /* Skip from tlbufpos to PT and see where it is. Note that
13257 PT may be in invisible text. If so, we will end at the
13258 next visible position. */
13259 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13260 NULL
, DEFAULT_FACE_ID
);
13261 it
.current_x
= this_line_start_x
;
13262 it
.current_y
= this_line_y
;
13263 it
.vpos
= this_line_vpos
;
13265 /* The call to move_it_to stops in front of PT, but
13266 moves over before-strings. */
13267 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13269 if (it
.vpos
== this_line_vpos
13270 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13273 xassert (this_line_vpos
== it
.vpos
);
13274 xassert (this_line_y
== it
.current_y
);
13275 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13277 *w
->desired_matrix
->method
= 0;
13278 debug_method_add (w
, "optimization 3");
13287 /* Text changed drastically or point moved off of line. */
13288 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13291 CHARPOS (this_line_start_pos
) = 0;
13292 consider_all_windows_p
|= buffer_shared
> 1;
13293 ++clear_face_cache_count
;
13294 #ifdef HAVE_WINDOW_SYSTEM
13295 ++clear_image_cache_count
;
13298 /* Build desired matrices, and update the display. If
13299 consider_all_windows_p is non-zero, do it for all windows on all
13300 frames. Otherwise do it for selected_window, only. */
13302 if (consider_all_windows_p
)
13304 Lisp_Object tail
, frame
;
13306 FOR_EACH_FRAME (tail
, frame
)
13307 XFRAME (frame
)->updated_p
= 0;
13309 /* Recompute # windows showing selected buffer. This will be
13310 incremented each time such a window is displayed. */
13313 FOR_EACH_FRAME (tail
, frame
)
13315 struct frame
*f
= XFRAME (frame
);
13317 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13319 if (! EQ (frame
, selected_frame
))
13320 /* Select the frame, for the sake of frame-local
13322 select_frame_for_redisplay (frame
);
13324 /* Mark all the scroll bars to be removed; we'll redeem
13325 the ones we want when we redisplay their windows. */
13326 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13327 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13329 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13330 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13332 /* The X error handler may have deleted that frame. */
13333 if (!FRAME_LIVE_P (f
))
13336 /* Any scroll bars which redisplay_windows should have
13337 nuked should now go away. */
13338 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13339 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13341 /* If fonts changed, display again. */
13342 /* ??? rms: I suspect it is a mistake to jump all the way
13343 back to retry here. It should just retry this frame. */
13344 if (fonts_changed_p
)
13347 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13349 /* See if we have to hscroll. */
13350 if (!f
->already_hscrolled_p
)
13352 f
->already_hscrolled_p
= 1;
13353 if (hscroll_windows (f
->root_window
))
13357 /* Prevent various kinds of signals during display
13358 update. stdio is not robust about handling
13359 signals, which can cause an apparent I/O
13361 if (interrupt_input
)
13362 unrequest_sigio ();
13365 /* Update the display. */
13366 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13367 pending
|= update_frame (f
, 0, 0);
13373 if (!EQ (old_frame
, selected_frame
)
13374 && FRAME_LIVE_P (XFRAME (old_frame
)))
13375 /* We played a bit fast-and-loose above and allowed selected_frame
13376 and selected_window to be temporarily out-of-sync but let's make
13377 sure this stays contained. */
13378 select_frame_for_redisplay (old_frame
);
13379 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13383 /* Do the mark_window_display_accurate after all windows have
13384 been redisplayed because this call resets flags in buffers
13385 which are needed for proper redisplay. */
13386 FOR_EACH_FRAME (tail
, frame
)
13388 struct frame
*f
= XFRAME (frame
);
13391 mark_window_display_accurate (f
->root_window
, 1);
13392 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13393 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13398 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13400 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13401 struct frame
*mini_frame
;
13403 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13404 /* Use list_of_error, not Qerror, so that
13405 we catch only errors and don't run the debugger. */
13406 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13408 redisplay_window_error
);
13409 if (update_miniwindow_p
)
13410 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13412 redisplay_window_error
);
13414 /* Compare desired and current matrices, perform output. */
13417 /* If fonts changed, display again. */
13418 if (fonts_changed_p
)
13421 /* Prevent various kinds of signals during display update.
13422 stdio is not robust about handling signals,
13423 which can cause an apparent I/O error. */
13424 if (interrupt_input
)
13425 unrequest_sigio ();
13428 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13430 if (hscroll_windows (selected_window
))
13433 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13434 pending
= update_frame (sf
, 0, 0);
13437 /* We may have called echo_area_display at the top of this
13438 function. If the echo area is on another frame, that may
13439 have put text on a frame other than the selected one, so the
13440 above call to update_frame would not have caught it. Catch
13442 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13443 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13445 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13447 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13448 pending
|= update_frame (mini_frame
, 0, 0);
13449 if (!pending
&& hscroll_windows (mini_window
))
13454 /* If display was paused because of pending input, make sure we do a
13455 thorough update the next time. */
13458 /* Prevent the optimization at the beginning of
13459 redisplay_internal that tries a single-line update of the
13460 line containing the cursor in the selected window. */
13461 CHARPOS (this_line_start_pos
) = 0;
13463 /* Let the overlay arrow be updated the next time. */
13464 update_overlay_arrows (0);
13466 /* If we pause after scrolling, some rows in the current
13467 matrices of some windows are not valid. */
13468 if (!WINDOW_FULL_WIDTH_P (w
)
13469 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13470 update_mode_lines
= 1;
13474 if (!consider_all_windows_p
)
13476 /* This has already been done above if
13477 consider_all_windows_p is set. */
13478 mark_window_display_accurate_1 (w
, 1);
13480 /* Say overlay arrows are up to date. */
13481 update_overlay_arrows (1);
13483 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13484 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13487 update_mode_lines
= 0;
13488 windows_or_buffers_changed
= 0;
13489 cursor_type_changed
= 0;
13492 /* Start SIGIO interrupts coming again. Having them off during the
13493 code above makes it less likely one will discard output, but not
13494 impossible, since there might be stuff in the system buffer here.
13495 But it is much hairier to try to do anything about that. */
13496 if (interrupt_input
)
13500 /* If a frame has become visible which was not before, redisplay
13501 again, so that we display it. Expose events for such a frame
13502 (which it gets when becoming visible) don't call the parts of
13503 redisplay constructing glyphs, so simply exposing a frame won't
13504 display anything in this case. So, we have to display these
13505 frames here explicitly. */
13508 Lisp_Object tail
, frame
;
13511 FOR_EACH_FRAME (tail
, frame
)
13513 int this_is_visible
= 0;
13515 if (XFRAME (frame
)->visible
)
13516 this_is_visible
= 1;
13517 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13518 if (XFRAME (frame
)->visible
)
13519 this_is_visible
= 1;
13521 if (this_is_visible
)
13525 if (new_count
!= number_of_visible_frames
)
13526 windows_or_buffers_changed
++;
13529 /* Change frame size now if a change is pending. */
13530 do_pending_window_change (1);
13532 /* If we just did a pending size change, or have additional
13533 visible frames, or selected_window changed, redisplay again. */
13534 if ((windows_or_buffers_changed
&& !pending
)
13535 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13538 /* Clear the face and image caches.
13540 We used to do this only if consider_all_windows_p. But the cache
13541 needs to be cleared if a timer creates images in the current
13542 buffer (e.g. the test case in Bug#6230). */
13544 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13546 clear_face_cache (0);
13547 clear_face_cache_count
= 0;
13550 #ifdef HAVE_WINDOW_SYSTEM
13551 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13553 clear_image_caches (Qnil
);
13554 clear_image_cache_count
= 0;
13556 #endif /* HAVE_WINDOW_SYSTEM */
13559 unbind_to (count
, Qnil
);
13564 /* Redisplay, but leave alone any recent echo area message unless
13565 another message has been requested in its place.
13567 This is useful in situations where you need to redisplay but no
13568 user action has occurred, making it inappropriate for the message
13569 area to be cleared. See tracking_off and
13570 wait_reading_process_output for examples of these situations.
13572 FROM_WHERE is an integer saying from where this function was
13573 called. This is useful for debugging. */
13576 redisplay_preserve_echo_area (int from_where
)
13578 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13580 if (!NILP (echo_area_buffer
[1]))
13582 /* We have a previously displayed message, but no current
13583 message. Redisplay the previous message. */
13584 display_last_displayed_message_p
= 1;
13585 redisplay_internal ();
13586 display_last_displayed_message_p
= 0;
13589 redisplay_internal ();
13591 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13592 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13593 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13597 /* Function registered with record_unwind_protect in
13598 redisplay_internal. Reset redisplaying_p to the value it had
13599 before redisplay_internal was called, and clear
13600 prevent_freeing_realized_faces_p. It also selects the previously
13601 selected frame, unless it has been deleted (by an X connection
13602 failure during redisplay, for example). */
13605 unwind_redisplay (Lisp_Object val
)
13607 Lisp_Object old_redisplaying_p
, old_frame
;
13609 old_redisplaying_p
= XCAR (val
);
13610 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13611 old_frame
= XCDR (val
);
13612 if (! EQ (old_frame
, selected_frame
)
13613 && FRAME_LIVE_P (XFRAME (old_frame
)))
13614 select_frame_for_redisplay (old_frame
);
13619 /* Mark the display of window W as accurate or inaccurate. If
13620 ACCURATE_P is non-zero mark display of W as accurate. If
13621 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13622 redisplay_internal is called. */
13625 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13627 if (BUFFERP (w
->buffer
))
13629 struct buffer
*b
= XBUFFER (w
->buffer
);
13632 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
13633 w
->last_overlay_modified
13634 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
13636 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
13640 b
->clip_changed
= 0;
13641 b
->prevent_redisplay_optimizations_p
= 0;
13643 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13644 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13645 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13646 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13648 w
->current_matrix
->buffer
= b
;
13649 w
->current_matrix
->begv
= BUF_BEGV (b
);
13650 w
->current_matrix
->zv
= BUF_ZV (b
);
13652 w
->last_cursor
= w
->cursor
;
13653 w
->last_cursor_off_p
= w
->cursor_off_p
;
13655 if (w
== XWINDOW (selected_window
))
13656 w
->last_point
= make_number (BUF_PT (b
));
13658 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
13664 w
->window_end_valid
= w
->buffer
;
13665 w
->update_mode_line
= Qnil
;
13670 /* Mark the display of windows in the window tree rooted at WINDOW as
13671 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13672 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13673 be redisplayed the next time redisplay_internal is called. */
13676 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13680 for (; !NILP (window
); window
= w
->next
)
13682 w
= XWINDOW (window
);
13683 mark_window_display_accurate_1 (w
, accurate_p
);
13685 if (!NILP (w
->vchild
))
13686 mark_window_display_accurate (w
->vchild
, accurate_p
);
13687 if (!NILP (w
->hchild
))
13688 mark_window_display_accurate (w
->hchild
, accurate_p
);
13693 update_overlay_arrows (1);
13697 /* Force a thorough redisplay the next time by setting
13698 last_arrow_position and last_arrow_string to t, which is
13699 unequal to any useful value of Voverlay_arrow_... */
13700 update_overlay_arrows (-1);
13705 /* Return value in display table DP (Lisp_Char_Table *) for character
13706 C. Since a display table doesn't have any parent, we don't have to
13707 follow parent. Do not call this function directly but use the
13708 macro DISP_CHAR_VECTOR. */
13711 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13715 if (ASCII_CHAR_P (c
))
13718 if (SUB_CHAR_TABLE_P (val
))
13719 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13725 XSETCHAR_TABLE (table
, dp
);
13726 val
= char_table_ref (table
, c
);
13735 /***********************************************************************
13737 ***********************************************************************/
13739 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13742 redisplay_windows (Lisp_Object window
)
13744 while (!NILP (window
))
13746 struct window
*w
= XWINDOW (window
);
13748 if (!NILP (w
->hchild
))
13749 redisplay_windows (w
->hchild
);
13750 else if (!NILP (w
->vchild
))
13751 redisplay_windows (w
->vchild
);
13752 else if (!NILP (w
->buffer
))
13754 displayed_buffer
= XBUFFER (w
->buffer
);
13755 /* Use list_of_error, not Qerror, so that
13756 we catch only errors and don't run the debugger. */
13757 internal_condition_case_1 (redisplay_window_0
, window
,
13759 redisplay_window_error
);
13767 redisplay_window_error (Lisp_Object ignore
)
13769 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13774 redisplay_window_0 (Lisp_Object window
)
13776 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13777 redisplay_window (window
, 0);
13782 redisplay_window_1 (Lisp_Object window
)
13784 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13785 redisplay_window (window
, 1);
13790 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13791 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13792 which positions recorded in ROW differ from current buffer
13795 Return 0 if cursor is not on this row, 1 otherwise. */
13798 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13799 struct glyph_matrix
*matrix
,
13800 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13803 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13804 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13805 struct glyph
*cursor
= NULL
;
13806 /* The last known character position in row. */
13807 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13809 ptrdiff_t pt_old
= PT
- delta
;
13810 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13811 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13812 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13813 /* A glyph beyond the edge of TEXT_AREA which we should never
13815 struct glyph
*glyphs_end
= end
;
13816 /* Non-zero means we've found a match for cursor position, but that
13817 glyph has the avoid_cursor_p flag set. */
13818 int match_with_avoid_cursor
= 0;
13819 /* Non-zero means we've seen at least one glyph that came from a
13821 int string_seen
= 0;
13822 /* Largest and smallest buffer positions seen so far during scan of
13824 ptrdiff_t bpos_max
= pos_before
;
13825 ptrdiff_t bpos_min
= pos_after
;
13826 /* Last buffer position covered by an overlay string with an integer
13827 `cursor' property. */
13828 ptrdiff_t bpos_covered
= 0;
13829 /* Non-zero means the display string on which to display the cursor
13830 comes from a text property, not from an overlay. */
13831 int string_from_text_prop
= 0;
13833 /* Don't even try doing anything if called for a mode-line or
13834 header-line row, since the rest of the code isn't prepared to
13835 deal with such calamities. */
13836 xassert (!row
->mode_line_p
);
13837 if (row
->mode_line_p
)
13840 /* Skip over glyphs not having an object at the start and the end of
13841 the row. These are special glyphs like truncation marks on
13842 terminal frames. */
13843 if (row
->displays_text_p
)
13845 if (!row
->reversed_p
)
13848 && INTEGERP (glyph
->object
)
13849 && glyph
->charpos
< 0)
13851 x
+= glyph
->pixel_width
;
13855 && INTEGERP ((end
- 1)->object
)
13856 /* CHARPOS is zero for blanks and stretch glyphs
13857 inserted by extend_face_to_end_of_line. */
13858 && (end
- 1)->charpos
<= 0)
13860 glyph_before
= glyph
- 1;
13867 /* If the glyph row is reversed, we need to process it from back
13868 to front, so swap the edge pointers. */
13869 glyphs_end
= end
= glyph
- 1;
13870 glyph
+= row
->used
[TEXT_AREA
] - 1;
13872 while (glyph
> end
+ 1
13873 && INTEGERP (glyph
->object
)
13874 && glyph
->charpos
< 0)
13877 x
-= glyph
->pixel_width
;
13879 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13881 /* By default, in reversed rows we put the cursor on the
13882 rightmost (first in the reading order) glyph. */
13883 for (g
= end
+ 1; g
< glyph
; g
++)
13884 x
+= g
->pixel_width
;
13886 && INTEGERP ((end
+ 1)->object
)
13887 && (end
+ 1)->charpos
<= 0)
13889 glyph_before
= glyph
+ 1;
13893 else if (row
->reversed_p
)
13895 /* In R2L rows that don't display text, put the cursor on the
13896 rightmost glyph. Case in point: an empty last line that is
13897 part of an R2L paragraph. */
13899 /* Avoid placing the cursor on the last glyph of the row, where
13900 on terminal frames we hold the vertical border between
13901 adjacent windows. */
13902 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13903 && !WINDOW_RIGHTMOST_P (w
)
13904 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13906 x
= -1; /* will be computed below, at label compute_x */
13909 /* Step 1: Try to find the glyph whose character position
13910 corresponds to point. If that's not possible, find 2 glyphs
13911 whose character positions are the closest to point, one before
13912 point, the other after it. */
13913 if (!row
->reversed_p
)
13914 while (/* not marched to end of glyph row */
13916 /* glyph was not inserted by redisplay for internal purposes */
13917 && !INTEGERP (glyph
->object
))
13919 if (BUFFERP (glyph
->object
))
13921 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13923 if (glyph
->charpos
> bpos_max
)
13924 bpos_max
= glyph
->charpos
;
13925 if (glyph
->charpos
< bpos_min
)
13926 bpos_min
= glyph
->charpos
;
13927 if (!glyph
->avoid_cursor_p
)
13929 /* If we hit point, we've found the glyph on which to
13930 display the cursor. */
13933 match_with_avoid_cursor
= 0;
13936 /* See if we've found a better approximation to
13937 POS_BEFORE or to POS_AFTER. Note that we want the
13938 first (leftmost) glyph of all those that are the
13939 closest from below, and the last (rightmost) of all
13940 those from above. */
13941 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13943 pos_before
= glyph
->charpos
;
13944 glyph_before
= glyph
;
13946 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13948 pos_after
= glyph
->charpos
;
13949 glyph_after
= glyph
;
13952 else if (dpos
== 0)
13953 match_with_avoid_cursor
= 1;
13955 else if (STRINGP (glyph
->object
))
13957 Lisp_Object chprop
;
13958 ptrdiff_t glyph_pos
= glyph
->charpos
;
13960 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13962 if (!NILP (chprop
))
13964 /* If the string came from a `display' text property,
13965 look up the buffer position of that property and
13966 use that position to update bpos_max, as if we
13967 actually saw such a position in one of the row's
13968 glyphs. This helps with supporting integer values
13969 of `cursor' property on the display string in
13970 situations where most or all of the row's buffer
13971 text is completely covered by display properties,
13972 so that no glyph with valid buffer positions is
13973 ever seen in the row. */
13974 ptrdiff_t prop_pos
=
13975 string_buffer_position_lim (glyph
->object
, pos_before
,
13978 if (prop_pos
>= pos_before
)
13979 bpos_max
= prop_pos
- 1;
13981 if (INTEGERP (chprop
))
13983 bpos_covered
= bpos_max
+ XINT (chprop
);
13984 /* If the `cursor' property covers buffer positions up
13985 to and including point, we should display cursor on
13986 this glyph. Note that, if a `cursor' property on one
13987 of the string's characters has an integer value, we
13988 will break out of the loop below _before_ we get to
13989 the position match above. IOW, integer values of
13990 the `cursor' property override the "exact match for
13991 point" strategy of positioning the cursor. */
13992 /* Implementation note: bpos_max == pt_old when, e.g.,
13993 we are in an empty line, where bpos_max is set to
13994 MATRIX_ROW_START_CHARPOS, see above. */
13995 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14004 x
+= glyph
->pixel_width
;
14007 else if (glyph
> end
) /* row is reversed */
14008 while (!INTEGERP (glyph
->object
))
14010 if (BUFFERP (glyph
->object
))
14012 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14014 if (glyph
->charpos
> bpos_max
)
14015 bpos_max
= glyph
->charpos
;
14016 if (glyph
->charpos
< bpos_min
)
14017 bpos_min
= glyph
->charpos
;
14018 if (!glyph
->avoid_cursor_p
)
14022 match_with_avoid_cursor
= 0;
14025 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14027 pos_before
= glyph
->charpos
;
14028 glyph_before
= glyph
;
14030 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
14032 pos_after
= glyph
->charpos
;
14033 glyph_after
= glyph
;
14036 else if (dpos
== 0)
14037 match_with_avoid_cursor
= 1;
14039 else if (STRINGP (glyph
->object
))
14041 Lisp_Object chprop
;
14042 ptrdiff_t glyph_pos
= glyph
->charpos
;
14044 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14046 if (!NILP (chprop
))
14048 ptrdiff_t prop_pos
=
14049 string_buffer_position_lim (glyph
->object
, pos_before
,
14052 if (prop_pos
>= pos_before
)
14053 bpos_max
= prop_pos
- 1;
14055 if (INTEGERP (chprop
))
14057 bpos_covered
= bpos_max
+ XINT (chprop
);
14058 /* If the `cursor' property covers buffer positions up
14059 to and including point, we should display cursor on
14061 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14070 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14072 x
--; /* can't use any pixel_width */
14075 x
-= glyph
->pixel_width
;
14078 /* Step 2: If we didn't find an exact match for point, we need to
14079 look for a proper place to put the cursor among glyphs between
14080 GLYPH_BEFORE and GLYPH_AFTER. */
14081 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14082 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14083 && bpos_covered
< pt_old
)
14085 /* An empty line has a single glyph whose OBJECT is zero and
14086 whose CHARPOS is the position of a newline on that line.
14087 Note that on a TTY, there are more glyphs after that, which
14088 were produced by extend_face_to_end_of_line, but their
14089 CHARPOS is zero or negative. */
14091 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14092 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14094 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14096 ptrdiff_t ellipsis_pos
;
14098 /* Scan back over the ellipsis glyphs. */
14099 if (!row
->reversed_p
)
14101 ellipsis_pos
= (glyph
- 1)->charpos
;
14102 while (glyph
> row
->glyphs
[TEXT_AREA
]
14103 && (glyph
- 1)->charpos
== ellipsis_pos
)
14104 glyph
--, x
-= glyph
->pixel_width
;
14105 /* That loop always goes one position too far, including
14106 the glyph before the ellipsis. So scan forward over
14108 x
+= glyph
->pixel_width
;
14111 else /* row is reversed */
14113 ellipsis_pos
= (glyph
+ 1)->charpos
;
14114 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14115 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14116 glyph
++, x
+= glyph
->pixel_width
;
14117 x
-= glyph
->pixel_width
;
14121 else if (match_with_avoid_cursor
)
14123 cursor
= glyph_after
;
14126 else if (string_seen
)
14128 int incr
= row
->reversed_p
? -1 : +1;
14130 /* Need to find the glyph that came out of a string which is
14131 present at point. That glyph is somewhere between
14132 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14133 positioned between POS_BEFORE and POS_AFTER in the
14135 struct glyph
*start
, *stop
;
14136 ptrdiff_t pos
= pos_before
;
14140 /* If the row ends in a newline from a display string,
14141 reordering could have moved the glyphs belonging to the
14142 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14143 in this case we extend the search to the last glyph in
14144 the row that was not inserted by redisplay. */
14145 if (row
->ends_in_newline_from_string_p
)
14148 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14151 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14152 correspond to POS_BEFORE and POS_AFTER, respectively. We
14153 need START and STOP in the order that corresponds to the
14154 row's direction as given by its reversed_p flag. If the
14155 directionality of characters between POS_BEFORE and
14156 POS_AFTER is the opposite of the row's base direction,
14157 these characters will have been reordered for display,
14158 and we need to reverse START and STOP. */
14159 if (!row
->reversed_p
)
14161 start
= min (glyph_before
, glyph_after
);
14162 stop
= max (glyph_before
, glyph_after
);
14166 start
= max (glyph_before
, glyph_after
);
14167 stop
= min (glyph_before
, glyph_after
);
14169 for (glyph
= start
+ incr
;
14170 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14173 /* Any glyphs that come from the buffer are here because
14174 of bidi reordering. Skip them, and only pay
14175 attention to glyphs that came from some string. */
14176 if (STRINGP (glyph
->object
))
14180 /* If the display property covers the newline, we
14181 need to search for it one position farther. */
14182 ptrdiff_t lim
= pos_after
14183 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14185 string_from_text_prop
= 0;
14186 str
= glyph
->object
;
14187 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14188 if (tem
== 0 /* from overlay */
14191 /* If the string from which this glyph came is
14192 found in the buffer at point, or at position
14193 that is closer to point than pos_after, then
14194 we've found the glyph we've been looking for.
14195 If it comes from an overlay (tem == 0), and
14196 it has the `cursor' property on one of its
14197 glyphs, record that glyph as a candidate for
14198 displaying the cursor. (As in the
14199 unidirectional version, we will display the
14200 cursor on the last candidate we find.) */
14203 || (tem
- pt_old
> 0 && tem
< pos_after
))
14205 /* The glyphs from this string could have
14206 been reordered. Find the one with the
14207 smallest string position. Or there could
14208 be a character in the string with the
14209 `cursor' property, which means display
14210 cursor on that character's glyph. */
14211 ptrdiff_t strpos
= glyph
->charpos
;
14216 string_from_text_prop
= 1;
14219 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14220 && EQ (glyph
->object
, str
);
14224 ptrdiff_t gpos
= glyph
->charpos
;
14226 cprop
= Fget_char_property (make_number (gpos
),
14234 if (tem
&& glyph
->charpos
< strpos
)
14236 strpos
= glyph
->charpos
;
14242 || (tem
- pt_old
> 0 && tem
< pos_after
))
14246 pos
= tem
+ 1; /* don't find previous instances */
14248 /* This string is not what we want; skip all of the
14249 glyphs that came from it. */
14250 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14251 && EQ (glyph
->object
, str
))
14258 /* If we reached the end of the line, and END was from a string,
14259 the cursor is not on this line. */
14261 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14262 && STRINGP (end
->object
)
14263 && row
->continued_p
)
14266 /* A truncated row may not include PT among its character positions.
14267 Setting the cursor inside the scroll margin will trigger
14268 recalculation of hscroll in hscroll_window_tree. But if a
14269 display string covers point, defer to the string-handling
14270 code below to figure this out. */
14271 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14273 cursor
= glyph_before
;
14276 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14277 /* Zero-width characters produce no glyphs. */
14279 && (row
->reversed_p
14280 ? glyph_after
> glyphs_end
14281 : glyph_after
< glyphs_end
)))
14283 cursor
= glyph_after
;
14289 if (cursor
!= NULL
)
14295 /* Need to compute x that corresponds to GLYPH. */
14296 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14298 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14300 x
+= g
->pixel_width
;
14304 /* ROW could be part of a continued line, which, under bidi
14305 reordering, might have other rows whose start and end charpos
14306 occlude point. Only set w->cursor if we found a better
14307 approximation to the cursor position than we have from previously
14308 examined candidate rows belonging to the same continued line. */
14309 if (/* we already have a candidate row */
14310 w
->cursor
.vpos
>= 0
14311 /* that candidate is not the row we are processing */
14312 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14313 /* Make sure cursor.vpos specifies a row whose start and end
14314 charpos occlude point, and it is valid candidate for being a
14315 cursor-row. This is because some callers of this function
14316 leave cursor.vpos at the row where the cursor was displayed
14317 during the last redisplay cycle. */
14318 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14319 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14320 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14323 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14325 /* Don't consider glyphs that are outside TEXT_AREA. */
14326 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14328 /* Keep the candidate whose buffer position is the closest to
14329 point or has the `cursor' property. */
14330 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14331 w
->cursor
.hpos
>= 0
14332 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14333 && ((BUFFERP (g1
->object
)
14334 && (g1
->charpos
== pt_old
/* an exact match always wins */
14335 || (BUFFERP (glyph
->object
)
14336 && eabs (g1
->charpos
- pt_old
)
14337 < eabs (glyph
->charpos
- pt_old
))))
14338 /* previous candidate is a glyph from a string that has
14339 a non-nil `cursor' property */
14340 || (STRINGP (g1
->object
)
14341 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14342 Qcursor
, g1
->object
))
14343 /* previous candidate is from the same display
14344 string as this one, and the display string
14345 came from a text property */
14346 || (EQ (g1
->object
, glyph
->object
)
14347 && string_from_text_prop
)
14348 /* this candidate is from newline and its
14349 position is not an exact match */
14350 || (INTEGERP (glyph
->object
)
14351 && glyph
->charpos
!= pt_old
)))))
14353 /* If this candidate gives an exact match, use that. */
14354 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14355 /* If this candidate is a glyph created for the
14356 terminating newline of a line, and point is on that
14357 newline, it wins because it's an exact match. */
14358 || (!row
->continued_p
14359 && INTEGERP (glyph
->object
)
14360 && glyph
->charpos
== 0
14361 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14362 /* Otherwise, keep the candidate that comes from a row
14363 spanning less buffer positions. This may win when one or
14364 both candidate positions are on glyphs that came from
14365 display strings, for which we cannot compare buffer
14367 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14368 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14369 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14372 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14374 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14375 w
->cursor
.y
= row
->y
+ dy
;
14377 if (w
== XWINDOW (selected_window
))
14379 if (!row
->continued_p
14380 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14383 this_line_buffer
= XBUFFER (w
->buffer
);
14385 CHARPOS (this_line_start_pos
)
14386 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14387 BYTEPOS (this_line_start_pos
)
14388 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14390 CHARPOS (this_line_end_pos
)
14391 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14392 BYTEPOS (this_line_end_pos
)
14393 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14395 this_line_y
= w
->cursor
.y
;
14396 this_line_pixel_height
= row
->height
;
14397 this_line_vpos
= w
->cursor
.vpos
;
14398 this_line_start_x
= row
->x
;
14401 CHARPOS (this_line_start_pos
) = 0;
14408 /* Run window scroll functions, if any, for WINDOW with new window
14409 start STARTP. Sets the window start of WINDOW to that position.
14411 We assume that the window's buffer is really current. */
14413 static inline struct text_pos
14414 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14416 struct window
*w
= XWINDOW (window
);
14417 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14419 if (current_buffer
!= XBUFFER (w
->buffer
))
14422 if (!NILP (Vwindow_scroll_functions
))
14424 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14425 make_number (CHARPOS (startp
)));
14426 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14427 /* In case the hook functions switch buffers. */
14428 if (current_buffer
!= XBUFFER (w
->buffer
))
14429 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14436 /* Make sure the line containing the cursor is fully visible.
14437 A value of 1 means there is nothing to be done.
14438 (Either the line is fully visible, or it cannot be made so,
14439 or we cannot tell.)
14441 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14442 is higher than window.
14444 A value of 0 means the caller should do scrolling
14445 as if point had gone off the screen. */
14448 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14450 struct glyph_matrix
*matrix
;
14451 struct glyph_row
*row
;
14454 if (!make_cursor_line_fully_visible_p
)
14457 /* It's not always possible to find the cursor, e.g, when a window
14458 is full of overlay strings. Don't do anything in that case. */
14459 if (w
->cursor
.vpos
< 0)
14462 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14463 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14465 /* If the cursor row is not partially visible, there's nothing to do. */
14466 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14469 /* If the row the cursor is in is taller than the window's height,
14470 it's not clear what to do, so do nothing. */
14471 window_height
= window_box_height (w
);
14472 if (row
->height
>= window_height
)
14474 if (!force_p
|| MINI_WINDOW_P (w
)
14475 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14482 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14483 non-zero means only WINDOW is redisplayed in redisplay_internal.
14484 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14485 in redisplay_window to bring a partially visible line into view in
14486 the case that only the cursor has moved.
14488 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14489 last screen line's vertical height extends past the end of the screen.
14493 1 if scrolling succeeded
14495 0 if scrolling didn't find point.
14497 -1 if new fonts have been loaded so that we must interrupt
14498 redisplay, adjust glyph matrices, and try again. */
14504 SCROLLING_NEED_LARGER_MATRICES
14507 /* If scroll-conservatively is more than this, never recenter.
14509 If you change this, don't forget to update the doc string of
14510 `scroll-conservatively' and the Emacs manual. */
14511 #define SCROLL_LIMIT 100
14514 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14515 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14516 int temp_scroll_step
, int last_line_misfit
)
14518 struct window
*w
= XWINDOW (window
);
14519 struct frame
*f
= XFRAME (w
->frame
);
14520 struct text_pos pos
, startp
;
14522 int this_scroll_margin
, scroll_max
, rc
, height
;
14523 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14524 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14525 Lisp_Object aggressive
;
14526 /* We will never try scrolling more than this number of lines. */
14527 int scroll_limit
= SCROLL_LIMIT
;
14530 debug_method_add (w
, "try_scrolling");
14533 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14535 /* Compute scroll margin height in pixels. We scroll when point is
14536 within this distance from the top or bottom of the window. */
14537 if (scroll_margin
> 0)
14538 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14539 * FRAME_LINE_HEIGHT (f
);
14541 this_scroll_margin
= 0;
14543 /* Force arg_scroll_conservatively to have a reasonable value, to
14544 avoid scrolling too far away with slow move_it_* functions. Note
14545 that the user can supply scroll-conservatively equal to
14546 `most-positive-fixnum', which can be larger than INT_MAX. */
14547 if (arg_scroll_conservatively
> scroll_limit
)
14549 arg_scroll_conservatively
= scroll_limit
+ 1;
14550 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14552 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14553 /* Compute how much we should try to scroll maximally to bring
14554 point into view. */
14555 scroll_max
= (max (scroll_step
,
14556 max (arg_scroll_conservatively
, temp_scroll_step
))
14557 * FRAME_LINE_HEIGHT (f
));
14558 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14559 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14560 /* We're trying to scroll because of aggressive scrolling but no
14561 scroll_step is set. Choose an arbitrary one. */
14562 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14568 /* Decide whether to scroll down. */
14569 if (PT
> CHARPOS (startp
))
14571 int scroll_margin_y
;
14573 /* Compute the pixel ypos of the scroll margin, then move IT to
14574 either that ypos or PT, whichever comes first. */
14575 start_display (&it
, w
, startp
);
14576 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14577 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14578 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14579 (MOVE_TO_POS
| MOVE_TO_Y
));
14581 if (PT
> CHARPOS (it
.current
.pos
))
14583 int y0
= line_bottom_y (&it
);
14584 /* Compute how many pixels below window bottom to stop searching
14585 for PT. This avoids costly search for PT that is far away if
14586 the user limited scrolling by a small number of lines, but
14587 always finds PT if scroll_conservatively is set to a large
14588 number, such as most-positive-fixnum. */
14589 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14590 int y_to_move
= it
.last_visible_y
+ slack
;
14592 /* Compute the distance from the scroll margin to PT or to
14593 the scroll limit, whichever comes first. This should
14594 include the height of the cursor line, to make that line
14596 move_it_to (&it
, PT
, -1, y_to_move
,
14597 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14598 dy
= line_bottom_y (&it
) - y0
;
14600 if (dy
> scroll_max
)
14601 return SCROLLING_FAILED
;
14610 /* Point is in or below the bottom scroll margin, so move the
14611 window start down. If scrolling conservatively, move it just
14612 enough down to make point visible. If scroll_step is set,
14613 move it down by scroll_step. */
14614 if (arg_scroll_conservatively
)
14616 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14617 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14618 else if (scroll_step
|| temp_scroll_step
)
14619 amount_to_scroll
= scroll_max
;
14622 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14623 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14624 if (NUMBERP (aggressive
))
14626 double float_amount
= XFLOATINT (aggressive
) * height
;
14627 amount_to_scroll
= float_amount
;
14628 if (amount_to_scroll
== 0 && float_amount
> 0)
14629 amount_to_scroll
= 1;
14630 /* Don't let point enter the scroll margin near top of
14632 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14633 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14637 if (amount_to_scroll
<= 0)
14638 return SCROLLING_FAILED
;
14640 start_display (&it
, w
, startp
);
14641 if (arg_scroll_conservatively
<= scroll_limit
)
14642 move_it_vertically (&it
, amount_to_scroll
);
14645 /* Extra precision for users who set scroll-conservatively
14646 to a large number: make sure the amount we scroll
14647 the window start is never less than amount_to_scroll,
14648 which was computed as distance from window bottom to
14649 point. This matters when lines at window top and lines
14650 below window bottom have different height. */
14652 void *it1data
= NULL
;
14653 /* We use a temporary it1 because line_bottom_y can modify
14654 its argument, if it moves one line down; see there. */
14657 SAVE_IT (it1
, it
, it1data
);
14658 start_y
= line_bottom_y (&it1
);
14660 RESTORE_IT (&it
, &it
, it1data
);
14661 move_it_by_lines (&it
, 1);
14662 SAVE_IT (it1
, it
, it1data
);
14663 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14666 /* If STARTP is unchanged, move it down another screen line. */
14667 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14668 move_it_by_lines (&it
, 1);
14669 startp
= it
.current
.pos
;
14673 struct text_pos scroll_margin_pos
= startp
;
14675 /* See if point is inside the scroll margin at the top of the
14677 if (this_scroll_margin
)
14679 start_display (&it
, w
, startp
);
14680 move_it_vertically (&it
, this_scroll_margin
);
14681 scroll_margin_pos
= it
.current
.pos
;
14684 if (PT
< CHARPOS (scroll_margin_pos
))
14686 /* Point is in the scroll margin at the top of the window or
14687 above what is displayed in the window. */
14690 /* Compute the vertical distance from PT to the scroll
14691 margin position. Move as far as scroll_max allows, or
14692 one screenful, or 10 screen lines, whichever is largest.
14693 Give up if distance is greater than scroll_max. */
14694 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14695 start_display (&it
, w
, pos
);
14697 y_to_move
= max (it
.last_visible_y
,
14698 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14699 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14701 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14702 dy
= it
.current_y
- y0
;
14703 if (dy
> scroll_max
)
14704 return SCROLLING_FAILED
;
14706 /* Compute new window start. */
14707 start_display (&it
, w
, startp
);
14709 if (arg_scroll_conservatively
)
14710 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14711 max (scroll_step
, temp_scroll_step
));
14712 else if (scroll_step
|| temp_scroll_step
)
14713 amount_to_scroll
= scroll_max
;
14716 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14717 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14718 if (NUMBERP (aggressive
))
14720 double float_amount
= XFLOATINT (aggressive
) * height
;
14721 amount_to_scroll
= float_amount
;
14722 if (amount_to_scroll
== 0 && float_amount
> 0)
14723 amount_to_scroll
= 1;
14724 amount_to_scroll
-=
14725 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14726 /* Don't let point enter the scroll margin near
14727 bottom of the window. */
14728 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14729 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14733 if (amount_to_scroll
<= 0)
14734 return SCROLLING_FAILED
;
14736 move_it_vertically_backward (&it
, amount_to_scroll
);
14737 startp
= it
.current
.pos
;
14741 /* Run window scroll functions. */
14742 startp
= run_window_scroll_functions (window
, startp
);
14744 /* Display the window. Give up if new fonts are loaded, or if point
14746 if (!try_window (window
, startp
, 0))
14747 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14748 else if (w
->cursor
.vpos
< 0)
14750 clear_glyph_matrix (w
->desired_matrix
);
14751 rc
= SCROLLING_FAILED
;
14755 /* Maybe forget recorded base line for line number display. */
14756 if (!just_this_one_p
14757 || current_buffer
->clip_changed
14758 || BEG_UNCHANGED
< CHARPOS (startp
))
14759 w
->base_line_number
= Qnil
;
14761 /* If cursor ends up on a partially visible line,
14762 treat that as being off the bottom of the screen. */
14763 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14764 /* It's possible that the cursor is on the first line of the
14765 buffer, which is partially obscured due to a vscroll
14766 (Bug#7537). In that case, avoid looping forever . */
14767 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14769 clear_glyph_matrix (w
->desired_matrix
);
14770 ++extra_scroll_margin_lines
;
14773 rc
= SCROLLING_SUCCESS
;
14780 /* Compute a suitable window start for window W if display of W starts
14781 on a continuation line. Value is non-zero if a new window start
14784 The new window start will be computed, based on W's width, starting
14785 from the start of the continued line. It is the start of the
14786 screen line with the minimum distance from the old start W->start. */
14789 compute_window_start_on_continuation_line (struct window
*w
)
14791 struct text_pos pos
, start_pos
;
14792 int window_start_changed_p
= 0;
14794 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14796 /* If window start is on a continuation line... Window start may be
14797 < BEGV in case there's invisible text at the start of the
14798 buffer (M-x rmail, for example). */
14799 if (CHARPOS (start_pos
) > BEGV
14800 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14803 struct glyph_row
*row
;
14805 /* Handle the case that the window start is out of range. */
14806 if (CHARPOS (start_pos
) < BEGV
)
14807 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14808 else if (CHARPOS (start_pos
) > ZV
)
14809 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14811 /* Find the start of the continued line. This should be fast
14812 because scan_buffer is fast (newline cache). */
14813 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14814 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14815 row
, DEFAULT_FACE_ID
);
14816 reseat_at_previous_visible_line_start (&it
);
14818 /* If the line start is "too far" away from the window start,
14819 say it takes too much time to compute a new window start. */
14820 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14821 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14823 int min_distance
, distance
;
14825 /* Move forward by display lines to find the new window
14826 start. If window width was enlarged, the new start can
14827 be expected to be > the old start. If window width was
14828 decreased, the new window start will be < the old start.
14829 So, we're looking for the display line start with the
14830 minimum distance from the old window start. */
14831 pos
= it
.current
.pos
;
14832 min_distance
= INFINITY
;
14833 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14834 distance
< min_distance
)
14836 min_distance
= distance
;
14837 pos
= it
.current
.pos
;
14838 move_it_by_lines (&it
, 1);
14841 /* Set the window start there. */
14842 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14843 window_start_changed_p
= 1;
14847 return window_start_changed_p
;
14851 /* Try cursor movement in case text has not changed in window WINDOW,
14852 with window start STARTP. Value is
14854 CURSOR_MOVEMENT_SUCCESS if successful
14856 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14858 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14859 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14860 we want to scroll as if scroll-step were set to 1. See the code.
14862 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14863 which case we have to abort this redisplay, and adjust matrices
14868 CURSOR_MOVEMENT_SUCCESS
,
14869 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14870 CURSOR_MOVEMENT_MUST_SCROLL
,
14871 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14875 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14877 struct window
*w
= XWINDOW (window
);
14878 struct frame
*f
= XFRAME (w
->frame
);
14879 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14882 if (inhibit_try_cursor_movement
)
14886 /* Handle case where text has not changed, only point, and it has
14887 not moved off the frame. */
14888 if (/* Point may be in this window. */
14889 PT
>= CHARPOS (startp
)
14890 /* Selective display hasn't changed. */
14891 && !current_buffer
->clip_changed
14892 /* Function force-mode-line-update is used to force a thorough
14893 redisplay. It sets either windows_or_buffers_changed or
14894 update_mode_lines. So don't take a shortcut here for these
14896 && !update_mode_lines
14897 && !windows_or_buffers_changed
14898 && !cursor_type_changed
14899 /* Can't use this case if highlighting a region. When a
14900 region exists, cursor movement has to do more than just
14902 && !(!NILP (Vtransient_mark_mode
)
14903 && !NILP (BVAR (current_buffer
, mark_active
)))
14904 && NILP (w
->region_showing
)
14905 && NILP (Vshow_trailing_whitespace
)
14906 /* Right after splitting windows, last_point may be nil. */
14907 && INTEGERP (w
->last_point
)
14908 /* This code is not used for mini-buffer for the sake of the case
14909 of redisplaying to replace an echo area message; since in
14910 that case the mini-buffer contents per se are usually
14911 unchanged. This code is of no real use in the mini-buffer
14912 since the handling of this_line_start_pos, etc., in redisplay
14913 handles the same cases. */
14914 && !EQ (window
, minibuf_window
)
14915 /* When splitting windows or for new windows, it happens that
14916 redisplay is called with a nil window_end_vpos or one being
14917 larger than the window. This should really be fixed in
14918 window.c. I don't have this on my list, now, so we do
14919 approximately the same as the old redisplay code. --gerd. */
14920 && INTEGERP (w
->window_end_vpos
)
14921 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14922 && (FRAME_WINDOW_P (f
)
14923 || !overlay_arrow_in_current_buffer_p ()))
14925 int this_scroll_margin
, top_scroll_margin
;
14926 struct glyph_row
*row
= NULL
;
14929 debug_method_add (w
, "cursor movement");
14932 /* Scroll if point within this distance from the top or bottom
14933 of the window. This is a pixel value. */
14934 if (scroll_margin
> 0)
14936 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14937 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14940 this_scroll_margin
= 0;
14942 top_scroll_margin
= this_scroll_margin
;
14943 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14944 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14946 /* Start with the row the cursor was displayed during the last
14947 not paused redisplay. Give up if that row is not valid. */
14948 if (w
->last_cursor
.vpos
< 0
14949 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14950 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14953 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14954 if (row
->mode_line_p
)
14956 if (!row
->enabled_p
)
14957 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14960 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14962 int scroll_p
= 0, must_scroll
= 0;
14963 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14965 if (PT
> XFASTINT (w
->last_point
))
14967 /* Point has moved forward. */
14968 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14969 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14971 xassert (row
->enabled_p
);
14975 /* If the end position of a row equals the start
14976 position of the next row, and PT is at that position,
14977 we would rather display cursor in the next line. */
14978 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14979 && MATRIX_ROW_END_CHARPOS (row
) == PT
14980 && row
< w
->current_matrix
->rows
14981 + w
->current_matrix
->nrows
- 1
14982 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14983 && !cursor_row_p (row
))
14986 /* If within the scroll margin, scroll. Note that
14987 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14988 the next line would be drawn, and that
14989 this_scroll_margin can be zero. */
14990 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14991 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14992 /* Line is completely visible last line in window
14993 and PT is to be set in the next line. */
14994 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14995 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14996 && !row
->ends_at_zv_p
14997 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15000 else if (PT
< XFASTINT (w
->last_point
))
15002 /* Cursor has to be moved backward. Note that PT >=
15003 CHARPOS (startp) because of the outer if-statement. */
15004 while (!row
->mode_line_p
15005 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15006 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15007 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15008 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15009 row
> w
->current_matrix
->rows
15010 && (row
-1)->ends_in_newline_from_string_p
))))
15011 && (row
->y
> top_scroll_margin
15012 || CHARPOS (startp
) == BEGV
))
15014 xassert (row
->enabled_p
);
15018 /* Consider the following case: Window starts at BEGV,
15019 there is invisible, intangible text at BEGV, so that
15020 display starts at some point START > BEGV. It can
15021 happen that we are called with PT somewhere between
15022 BEGV and START. Try to handle that case. */
15023 if (row
< w
->current_matrix
->rows
15024 || row
->mode_line_p
)
15026 row
= w
->current_matrix
->rows
;
15027 if (row
->mode_line_p
)
15031 /* Due to newlines in overlay strings, we may have to
15032 skip forward over overlay strings. */
15033 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15034 && MATRIX_ROW_END_CHARPOS (row
) == PT
15035 && !cursor_row_p (row
))
15038 /* If within the scroll margin, scroll. */
15039 if (row
->y
< top_scroll_margin
15040 && CHARPOS (startp
) != BEGV
)
15045 /* Cursor did not move. So don't scroll even if cursor line
15046 is partially visible, as it was so before. */
15047 rc
= CURSOR_MOVEMENT_SUCCESS
;
15050 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15051 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15053 /* if PT is not in the glyph row, give up. */
15054 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15057 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15058 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15060 struct glyph_row
*row1
;
15062 /* If rows are bidi-reordered and point moved, back up
15063 until we find a row that does not belong to a
15064 continuation line. This is because we must consider
15065 all rows of a continued line as candidates for the
15066 new cursor positioning, since row start and end
15067 positions change non-linearly with vertical position
15069 /* FIXME: Revisit this when glyph ``spilling'' in
15070 continuation lines' rows is implemented for
15071 bidi-reordered rows. */
15072 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15073 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15076 /* If we hit the beginning of the displayed portion
15077 without finding the first row of a continued
15081 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15084 xassert (row
->enabled_p
);
15089 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15090 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15091 /* Make sure this isn't a header line by any chance, since
15092 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15093 && !row
->mode_line_p
15094 && make_cursor_line_fully_visible_p
)
15096 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15097 && !row
->ends_at_zv_p
15098 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15099 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15100 else if (row
->height
> window_box_height (w
))
15102 /* If we end up in a partially visible line, let's
15103 make it fully visible, except when it's taller
15104 than the window, in which case we can't do much
15107 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15111 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15112 if (!cursor_row_fully_visible_p (w
, 0, 1))
15113 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15115 rc
= CURSOR_MOVEMENT_SUCCESS
;
15119 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15120 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15121 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15123 /* With bidi-reordered rows, there could be more than
15124 one candidate row whose start and end positions
15125 occlude point. We need to let set_cursor_from_row
15126 find the best candidate. */
15127 /* FIXME: Revisit this when glyph ``spilling'' in
15128 continuation lines' rows is implemented for
15129 bidi-reordered rows. */
15134 int at_zv_p
= 0, exact_match_p
= 0;
15136 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15137 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15138 && cursor_row_p (row
))
15139 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15141 /* As soon as we've found the exact match for point,
15142 or the first suitable row whose ends_at_zv_p flag
15143 is set, we are done. */
15145 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15147 && w
->cursor
.hpos
>= 0
15148 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15151 struct glyph_row
*candidate
=
15152 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15154 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15155 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15158 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15159 || (INTEGERP (g
->object
)
15160 && (g
->charpos
== PT
15161 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15163 if (rv
&& (at_zv_p
|| exact_match_p
))
15165 rc
= CURSOR_MOVEMENT_SUCCESS
;
15168 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15172 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15173 || row
->continued_p
)
15174 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15175 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15176 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15177 /* If we didn't find any candidate rows, or exited the
15178 loop before all the candidates were examined, signal
15179 to the caller that this method failed. */
15180 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15182 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15183 && !row
->continued_p
))
15184 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15186 rc
= CURSOR_MOVEMENT_SUCCESS
;
15192 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15194 rc
= CURSOR_MOVEMENT_SUCCESS
;
15199 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15200 && MATRIX_ROW_START_CHARPOS (row
) == PT
15201 && cursor_row_p (row
));
15209 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15213 set_vertical_scroll_bar (struct window
*w
)
15215 ptrdiff_t start
, end
, whole
;
15217 /* Calculate the start and end positions for the current window.
15218 At some point, it would be nice to choose between scrollbars
15219 which reflect the whole buffer size, with special markers
15220 indicating narrowing, and scrollbars which reflect only the
15223 Note that mini-buffers sometimes aren't displaying any text. */
15224 if (!MINI_WINDOW_P (w
)
15225 || (w
== XWINDOW (minibuf_window
)
15226 && NILP (echo_area_buffer
[0])))
15228 struct buffer
*buf
= XBUFFER (w
->buffer
);
15229 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15230 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15231 /* I don't think this is guaranteed to be right. For the
15232 moment, we'll pretend it is. */
15233 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15237 if (whole
< (end
- start
))
15238 whole
= end
- start
;
15241 start
= end
= whole
= 0;
15243 /* Indicate what this scroll bar ought to be displaying now. */
15244 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15245 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15246 (w
, end
- start
, whole
, start
);
15250 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15251 selected_window is redisplayed.
15253 We can return without actually redisplaying the window if
15254 fonts_changed_p is nonzero. In that case, redisplay_internal will
15258 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15260 struct window
*w
= XWINDOW (window
);
15261 struct frame
*f
= XFRAME (w
->frame
);
15262 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15263 struct buffer
*old
= current_buffer
;
15264 struct text_pos lpoint
, opoint
, startp
;
15265 int update_mode_line
;
15268 /* Record it now because it's overwritten. */
15269 int current_matrix_up_to_date_p
= 0;
15270 int used_current_matrix_p
= 0;
15271 /* This is less strict than current_matrix_up_to_date_p.
15272 It indicates that the buffer contents and narrowing are unchanged. */
15273 int buffer_unchanged_p
= 0;
15274 int temp_scroll_step
= 0;
15275 ptrdiff_t count
= SPECPDL_INDEX ();
15277 int centering_position
= -1;
15278 int last_line_misfit
= 0;
15279 ptrdiff_t beg_unchanged
, end_unchanged
;
15281 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15284 /* W must be a leaf window here. */
15285 xassert (!NILP (w
->buffer
));
15287 *w
->desired_matrix
->method
= 0;
15291 reconsider_clip_changes (w
, buffer
);
15293 /* Has the mode line to be updated? */
15294 update_mode_line
= (!NILP (w
->update_mode_line
)
15295 || update_mode_lines
15296 || buffer
->clip_changed
15297 || buffer
->prevent_redisplay_optimizations_p
);
15299 if (MINI_WINDOW_P (w
))
15301 if (w
== XWINDOW (echo_area_window
)
15302 && !NILP (echo_area_buffer
[0]))
15304 if (update_mode_line
)
15305 /* We may have to update a tty frame's menu bar or a
15306 tool-bar. Example `M-x C-h C-h C-g'. */
15307 goto finish_menu_bars
;
15309 /* We've already displayed the echo area glyphs in this window. */
15310 goto finish_scroll_bars
;
15312 else if ((w
!= XWINDOW (minibuf_window
)
15313 || minibuf_level
== 0)
15314 /* When buffer is nonempty, redisplay window normally. */
15315 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15316 /* Quail displays non-mini buffers in minibuffer window.
15317 In that case, redisplay the window normally. */
15318 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15320 /* W is a mini-buffer window, but it's not active, so clear
15322 int yb
= window_text_bottom_y (w
);
15323 struct glyph_row
*row
;
15326 for (y
= 0, row
= w
->desired_matrix
->rows
;
15328 y
+= row
->height
, ++row
)
15329 blank_row (w
, row
, y
);
15330 goto finish_scroll_bars
;
15333 clear_glyph_matrix (w
->desired_matrix
);
15336 /* Otherwise set up data on this window; select its buffer and point
15338 /* Really select the buffer, for the sake of buffer-local
15340 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15342 current_matrix_up_to_date_p
15343 = (!NILP (w
->window_end_valid
)
15344 && !current_buffer
->clip_changed
15345 && !current_buffer
->prevent_redisplay_optimizations_p
15346 && XFASTINT (w
->last_modified
) >= MODIFF
15347 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15349 /* Run the window-bottom-change-functions
15350 if it is possible that the text on the screen has changed
15351 (either due to modification of the text, or any other reason). */
15352 if (!current_matrix_up_to_date_p
15353 && !NILP (Vwindow_text_change_functions
))
15355 safe_run_hooks (Qwindow_text_change_functions
);
15359 beg_unchanged
= BEG_UNCHANGED
;
15360 end_unchanged
= END_UNCHANGED
;
15362 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15364 specbind (Qinhibit_point_motion_hooks
, Qt
);
15367 = (!NILP (w
->window_end_valid
)
15368 && !current_buffer
->clip_changed
15369 && XFASTINT (w
->last_modified
) >= MODIFF
15370 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15372 /* When windows_or_buffers_changed is non-zero, we can't rely on
15373 the window end being valid, so set it to nil there. */
15374 if (windows_or_buffers_changed
)
15376 /* If window starts on a continuation line, maybe adjust the
15377 window start in case the window's width changed. */
15378 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15379 compute_window_start_on_continuation_line (w
);
15381 w
->window_end_valid
= Qnil
;
15384 /* Some sanity checks. */
15385 CHECK_WINDOW_END (w
);
15386 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15388 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15391 /* If %c is in mode line, update it if needed. */
15392 if (!NILP (w
->column_number_displayed
)
15393 /* This alternative quickly identifies a common case
15394 where no change is needed. */
15395 && !(PT
== XFASTINT (w
->last_point
)
15396 && XFASTINT (w
->last_modified
) >= MODIFF
15397 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
15398 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15399 update_mode_line
= 1;
15401 /* Count number of windows showing the selected buffer. An indirect
15402 buffer counts as its base buffer. */
15403 if (!just_this_one_p
)
15405 struct buffer
*current_base
, *window_base
;
15406 current_base
= current_buffer
;
15407 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15408 if (current_base
->base_buffer
)
15409 current_base
= current_base
->base_buffer
;
15410 if (window_base
->base_buffer
)
15411 window_base
= window_base
->base_buffer
;
15412 if (current_base
== window_base
)
15416 /* Point refers normally to the selected window. For any other
15417 window, set up appropriate value. */
15418 if (!EQ (window
, selected_window
))
15420 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15421 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15425 new_pt_byte
= BEGV_BYTE
;
15426 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15428 else if (new_pt
> (ZV
- 1))
15431 new_pt_byte
= ZV_BYTE
;
15432 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15435 /* We don't use SET_PT so that the point-motion hooks don't run. */
15436 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15439 /* If any of the character widths specified in the display table
15440 have changed, invalidate the width run cache. It's true that
15441 this may be a bit late to catch such changes, but the rest of
15442 redisplay goes (non-fatally) haywire when the display table is
15443 changed, so why should we worry about doing any better? */
15444 if (current_buffer
->width_run_cache
)
15446 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15448 if (! disptab_matches_widthtab (disptab
,
15449 XVECTOR (BVAR (current_buffer
, width_table
))))
15451 invalidate_region_cache (current_buffer
,
15452 current_buffer
->width_run_cache
,
15454 recompute_width_table (current_buffer
, disptab
);
15458 /* If window-start is screwed up, choose a new one. */
15459 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15462 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15464 /* If someone specified a new starting point but did not insist,
15465 check whether it can be used. */
15466 if (!NILP (w
->optional_new_start
)
15467 && CHARPOS (startp
) >= BEGV
15468 && CHARPOS (startp
) <= ZV
)
15470 w
->optional_new_start
= Qnil
;
15471 start_display (&it
, w
, startp
);
15472 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15473 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15474 if (IT_CHARPOS (it
) == PT
)
15475 w
->force_start
= Qt
;
15476 /* IT may overshoot PT if text at PT is invisible. */
15477 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15478 w
->force_start
= Qt
;
15483 /* Handle case where place to start displaying has been specified,
15484 unless the specified location is outside the accessible range. */
15485 if (!NILP (w
->force_start
)
15486 || w
->frozen_window_start_p
)
15488 /* We set this later on if we have to adjust point. */
15491 w
->force_start
= Qnil
;
15493 w
->window_end_valid
= Qnil
;
15495 /* Forget any recorded base line for line number display. */
15496 if (!buffer_unchanged_p
)
15497 w
->base_line_number
= Qnil
;
15499 /* Redisplay the mode line. Select the buffer properly for that.
15500 Also, run the hook window-scroll-functions
15501 because we have scrolled. */
15502 /* Note, we do this after clearing force_start because
15503 if there's an error, it is better to forget about force_start
15504 than to get into an infinite loop calling the hook functions
15505 and having them get more errors. */
15506 if (!update_mode_line
15507 || ! NILP (Vwindow_scroll_functions
))
15509 update_mode_line
= 1;
15510 w
->update_mode_line
= Qt
;
15511 startp
= run_window_scroll_functions (window
, startp
);
15514 w
->last_modified
= make_number (0);
15515 w
->last_overlay_modified
= make_number (0);
15516 if (CHARPOS (startp
) < BEGV
)
15517 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15518 else if (CHARPOS (startp
) > ZV
)
15519 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15521 /* Redisplay, then check if cursor has been set during the
15522 redisplay. Give up if new fonts were loaded. */
15523 /* We used to issue a CHECK_MARGINS argument to try_window here,
15524 but this causes scrolling to fail when point begins inside
15525 the scroll margin (bug#148) -- cyd */
15526 if (!try_window (window
, startp
, 0))
15528 w
->force_start
= Qt
;
15529 clear_glyph_matrix (w
->desired_matrix
);
15530 goto need_larger_matrices
;
15533 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15535 /* If point does not appear, try to move point so it does
15536 appear. The desired matrix has been built above, so we
15537 can use it here. */
15538 new_vpos
= window_box_height (w
) / 2;
15541 if (!cursor_row_fully_visible_p (w
, 0, 0))
15543 /* Point does appear, but on a line partly visible at end of window.
15544 Move it back to a fully-visible line. */
15545 new_vpos
= window_box_height (w
);
15548 /* If we need to move point for either of the above reasons,
15549 now actually do it. */
15552 struct glyph_row
*row
;
15554 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15555 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15558 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15559 MATRIX_ROW_START_BYTEPOS (row
));
15561 if (w
!= XWINDOW (selected_window
))
15562 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15563 else if (current_buffer
== old
)
15564 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15566 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15568 /* If we are highlighting the region, then we just changed
15569 the region, so redisplay to show it. */
15570 if (!NILP (Vtransient_mark_mode
)
15571 && !NILP (BVAR (current_buffer
, mark_active
)))
15573 clear_glyph_matrix (w
->desired_matrix
);
15574 if (!try_window (window
, startp
, 0))
15575 goto need_larger_matrices
;
15580 debug_method_add (w
, "forced window start");
15585 /* Handle case where text has not changed, only point, and it has
15586 not moved off the frame, and we are not retrying after hscroll.
15587 (current_matrix_up_to_date_p is nonzero when retrying.) */
15588 if (current_matrix_up_to_date_p
15589 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15590 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15594 case CURSOR_MOVEMENT_SUCCESS
:
15595 used_current_matrix_p
= 1;
15598 case CURSOR_MOVEMENT_MUST_SCROLL
:
15599 goto try_to_scroll
;
15605 /* If current starting point was originally the beginning of a line
15606 but no longer is, find a new starting point. */
15607 else if (!NILP (w
->start_at_line_beg
)
15608 && !(CHARPOS (startp
) <= BEGV
15609 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15612 debug_method_add (w
, "recenter 1");
15617 /* Try scrolling with try_window_id. Value is > 0 if update has
15618 been done, it is -1 if we know that the same window start will
15619 not work. It is 0 if unsuccessful for some other reason. */
15620 else if ((tem
= try_window_id (w
)) != 0)
15623 debug_method_add (w
, "try_window_id %d", tem
);
15626 if (fonts_changed_p
)
15627 goto need_larger_matrices
;
15631 /* Otherwise try_window_id has returned -1 which means that we
15632 don't want the alternative below this comment to execute. */
15634 else if (CHARPOS (startp
) >= BEGV
15635 && CHARPOS (startp
) <= ZV
15636 && PT
>= CHARPOS (startp
)
15637 && (CHARPOS (startp
) < ZV
15638 /* Avoid starting at end of buffer. */
15639 || CHARPOS (startp
) == BEGV
15640 || (XFASTINT (w
->last_modified
) >= MODIFF
15641 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
15643 int d1
, d2
, d3
, d4
, d5
, d6
;
15645 /* If first window line is a continuation line, and window start
15646 is inside the modified region, but the first change is before
15647 current window start, we must select a new window start.
15649 However, if this is the result of a down-mouse event (e.g. by
15650 extending the mouse-drag-overlay), we don't want to select a
15651 new window start, since that would change the position under
15652 the mouse, resulting in an unwanted mouse-movement rather
15653 than a simple mouse-click. */
15654 if (NILP (w
->start_at_line_beg
)
15655 && NILP (do_mouse_tracking
)
15656 && CHARPOS (startp
) > BEGV
15657 && CHARPOS (startp
) > BEG
+ beg_unchanged
15658 && CHARPOS (startp
) <= Z
- end_unchanged
15659 /* Even if w->start_at_line_beg is nil, a new window may
15660 start at a line_beg, since that's how set_buffer_window
15661 sets it. So, we need to check the return value of
15662 compute_window_start_on_continuation_line. (See also
15664 && XMARKER (w
->start
)->buffer
== current_buffer
15665 && compute_window_start_on_continuation_line (w
)
15666 /* It doesn't make sense to force the window start like we
15667 do at label force_start if it is already known that point
15668 will not be visible in the resulting window, because
15669 doing so will move point from its correct position
15670 instead of scrolling the window to bring point into view.
15672 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15674 w
->force_start
= Qt
;
15675 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15680 debug_method_add (w
, "same window start");
15683 /* Try to redisplay starting at same place as before.
15684 If point has not moved off frame, accept the results. */
15685 if (!current_matrix_up_to_date_p
15686 /* Don't use try_window_reusing_current_matrix in this case
15687 because a window scroll function can have changed the
15689 || !NILP (Vwindow_scroll_functions
)
15690 || MINI_WINDOW_P (w
)
15691 || !(used_current_matrix_p
15692 = try_window_reusing_current_matrix (w
)))
15694 IF_DEBUG (debug_method_add (w
, "1"));
15695 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15696 /* -1 means we need to scroll.
15697 0 means we need new matrices, but fonts_changed_p
15698 is set in that case, so we will detect it below. */
15699 goto try_to_scroll
;
15702 if (fonts_changed_p
)
15703 goto need_larger_matrices
;
15705 if (w
->cursor
.vpos
>= 0)
15707 if (!just_this_one_p
15708 || current_buffer
->clip_changed
15709 || BEG_UNCHANGED
< CHARPOS (startp
))
15710 /* Forget any recorded base line for line number display. */
15711 w
->base_line_number
= Qnil
;
15713 if (!cursor_row_fully_visible_p (w
, 1, 0))
15715 clear_glyph_matrix (w
->desired_matrix
);
15716 last_line_misfit
= 1;
15718 /* Drop through and scroll. */
15723 clear_glyph_matrix (w
->desired_matrix
);
15728 w
->last_modified
= make_number (0);
15729 w
->last_overlay_modified
= make_number (0);
15731 /* Redisplay the mode line. Select the buffer properly for that. */
15732 if (!update_mode_line
)
15734 update_mode_line
= 1;
15735 w
->update_mode_line
= Qt
;
15738 /* Try to scroll by specified few lines. */
15739 if ((scroll_conservatively
15740 || emacs_scroll_step
15741 || temp_scroll_step
15742 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15743 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15744 && CHARPOS (startp
) >= BEGV
15745 && CHARPOS (startp
) <= ZV
)
15747 /* The function returns -1 if new fonts were loaded, 1 if
15748 successful, 0 if not successful. */
15749 int ss
= try_scrolling (window
, just_this_one_p
,
15750 scroll_conservatively
,
15752 temp_scroll_step
, last_line_misfit
);
15755 case SCROLLING_SUCCESS
:
15758 case SCROLLING_NEED_LARGER_MATRICES
:
15759 goto need_larger_matrices
;
15761 case SCROLLING_FAILED
:
15769 /* Finally, just choose a place to start which positions point
15770 according to user preferences. */
15775 debug_method_add (w
, "recenter");
15778 /* w->vscroll = 0; */
15780 /* Forget any previously recorded base line for line number display. */
15781 if (!buffer_unchanged_p
)
15782 w
->base_line_number
= Qnil
;
15784 /* Determine the window start relative to point. */
15785 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15786 it
.current_y
= it
.last_visible_y
;
15787 if (centering_position
< 0)
15791 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15793 ptrdiff_t margin_pos
= CHARPOS (startp
);
15794 Lisp_Object aggressive
;
15797 /* If there is a scroll margin at the top of the window, find
15798 its character position. */
15800 /* Cannot call start_display if startp is not in the
15801 accessible region of the buffer. This can happen when we
15802 have just switched to a different buffer and/or changed
15803 its restriction. In that case, startp is initialized to
15804 the character position 1 (BEGV) because we did not yet
15805 have chance to display the buffer even once. */
15806 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15809 void *it1data
= NULL
;
15811 SAVE_IT (it1
, it
, it1data
);
15812 start_display (&it1
, w
, startp
);
15813 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15814 margin_pos
= IT_CHARPOS (it1
);
15815 RESTORE_IT (&it
, &it
, it1data
);
15817 scrolling_up
= PT
> margin_pos
;
15820 ? BVAR (current_buffer
, scroll_up_aggressively
)
15821 : BVAR (current_buffer
, scroll_down_aggressively
);
15823 if (!MINI_WINDOW_P (w
)
15824 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15828 /* Setting scroll-conservatively overrides
15829 scroll-*-aggressively. */
15830 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15832 double float_amount
= XFLOATINT (aggressive
);
15834 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15835 if (pt_offset
== 0 && float_amount
> 0)
15837 if (pt_offset
&& margin
> 0)
15840 /* Compute how much to move the window start backward from
15841 point so that point will be displayed where the user
15845 centering_position
= it
.last_visible_y
;
15847 centering_position
-= pt_offset
;
15848 centering_position
-=
15849 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15850 + WINDOW_HEADER_LINE_HEIGHT (w
);
15851 /* Don't let point enter the scroll margin near top of
15853 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15854 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15857 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15860 /* Set the window start half the height of the window backward
15862 centering_position
= window_box_height (w
) / 2;
15864 move_it_vertically_backward (&it
, centering_position
);
15866 xassert (IT_CHARPOS (it
) >= BEGV
);
15868 /* The function move_it_vertically_backward may move over more
15869 than the specified y-distance. If it->w is small, e.g. a
15870 mini-buffer window, we may end up in front of the window's
15871 display area. Start displaying at the start of the line
15872 containing PT in this case. */
15873 if (it
.current_y
<= 0)
15875 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15876 move_it_vertically_backward (&it
, 0);
15880 it
.current_x
= it
.hpos
= 0;
15882 /* Set the window start position here explicitly, to avoid an
15883 infinite loop in case the functions in window-scroll-functions
15885 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15887 /* Run scroll hooks. */
15888 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15890 /* Redisplay the window. */
15891 if (!current_matrix_up_to_date_p
15892 || windows_or_buffers_changed
15893 || cursor_type_changed
15894 /* Don't use try_window_reusing_current_matrix in this case
15895 because it can have changed the buffer. */
15896 || !NILP (Vwindow_scroll_functions
)
15897 || !just_this_one_p
15898 || MINI_WINDOW_P (w
)
15899 || !(used_current_matrix_p
15900 = try_window_reusing_current_matrix (w
)))
15901 try_window (window
, startp
, 0);
15903 /* If new fonts have been loaded (due to fontsets), give up. We
15904 have to start a new redisplay since we need to re-adjust glyph
15906 if (fonts_changed_p
)
15907 goto need_larger_matrices
;
15909 /* If cursor did not appear assume that the middle of the window is
15910 in the first line of the window. Do it again with the next line.
15911 (Imagine a window of height 100, displaying two lines of height
15912 60. Moving back 50 from it->last_visible_y will end in the first
15914 if (w
->cursor
.vpos
< 0)
15916 if (!NILP (w
->window_end_valid
)
15917 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15919 clear_glyph_matrix (w
->desired_matrix
);
15920 move_it_by_lines (&it
, 1);
15921 try_window (window
, it
.current
.pos
, 0);
15923 else if (PT
< IT_CHARPOS (it
))
15925 clear_glyph_matrix (w
->desired_matrix
);
15926 move_it_by_lines (&it
, -1);
15927 try_window (window
, it
.current
.pos
, 0);
15931 /* Not much we can do about it. */
15935 /* Consider the following case: Window starts at BEGV, there is
15936 invisible, intangible text at BEGV, so that display starts at
15937 some point START > BEGV. It can happen that we are called with
15938 PT somewhere between BEGV and START. Try to handle that case. */
15939 if (w
->cursor
.vpos
< 0)
15941 struct glyph_row
*row
= w
->current_matrix
->rows
;
15942 if (row
->mode_line_p
)
15944 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15947 if (!cursor_row_fully_visible_p (w
, 0, 0))
15949 /* If vscroll is enabled, disable it and try again. */
15953 clear_glyph_matrix (w
->desired_matrix
);
15957 /* Users who set scroll-conservatively to a large number want
15958 point just above/below the scroll margin. If we ended up
15959 with point's row partially visible, move the window start to
15960 make that row fully visible and out of the margin. */
15961 if (scroll_conservatively
> SCROLL_LIMIT
)
15965 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15967 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15969 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15970 clear_glyph_matrix (w
->desired_matrix
);
15971 if (1 == try_window (window
, it
.current
.pos
,
15972 TRY_WINDOW_CHECK_MARGINS
))
15976 /* If centering point failed to make the whole line visible,
15977 put point at the top instead. That has to make the whole line
15978 visible, if it can be done. */
15979 if (centering_position
== 0)
15982 clear_glyph_matrix (w
->desired_matrix
);
15983 centering_position
= 0;
15989 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15990 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15991 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15994 /* Display the mode line, if we must. */
15995 if ((update_mode_line
15996 /* If window not full width, must redo its mode line
15997 if (a) the window to its side is being redone and
15998 (b) we do a frame-based redisplay. This is a consequence
15999 of how inverted lines are drawn in frame-based redisplay. */
16000 || (!just_this_one_p
16001 && !FRAME_WINDOW_P (f
)
16002 && !WINDOW_FULL_WIDTH_P (w
))
16003 /* Line number to display. */
16004 || INTEGERP (w
->base_line_pos
)
16005 /* Column number is displayed and different from the one displayed. */
16006 || (!NILP (w
->column_number_displayed
)
16007 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16008 /* This means that the window has a mode line. */
16009 && (WINDOW_WANTS_MODELINE_P (w
)
16010 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16012 display_mode_lines (w
);
16014 /* If mode line height has changed, arrange for a thorough
16015 immediate redisplay using the correct mode line height. */
16016 if (WINDOW_WANTS_MODELINE_P (w
)
16017 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16019 fonts_changed_p
= 1;
16020 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16021 = DESIRED_MODE_LINE_HEIGHT (w
);
16024 /* If header line height has changed, arrange for a thorough
16025 immediate redisplay using the correct header line height. */
16026 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16027 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16029 fonts_changed_p
= 1;
16030 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16031 = DESIRED_HEADER_LINE_HEIGHT (w
);
16034 if (fonts_changed_p
)
16035 goto need_larger_matrices
;
16038 if (!line_number_displayed
16039 && !BUFFERP (w
->base_line_pos
))
16041 w
->base_line_pos
= Qnil
;
16042 w
->base_line_number
= Qnil
;
16047 /* When we reach a frame's selected window, redo the frame's menu bar. */
16048 if (update_mode_line
16049 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16051 int redisplay_menu_p
= 0;
16053 if (FRAME_WINDOW_P (f
))
16055 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16056 || defined (HAVE_NS) || defined (USE_GTK)
16057 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16059 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16063 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16065 if (redisplay_menu_p
)
16066 display_menu_bar (w
);
16068 #ifdef HAVE_WINDOW_SYSTEM
16069 if (FRAME_WINDOW_P (f
))
16071 #if defined (USE_GTK) || defined (HAVE_NS)
16072 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16073 redisplay_tool_bar (f
);
16075 if (WINDOWP (f
->tool_bar_window
)
16076 && (FRAME_TOOL_BAR_LINES (f
) > 0
16077 || !NILP (Vauto_resize_tool_bars
))
16078 && redisplay_tool_bar (f
))
16079 ignore_mouse_drag_p
= 1;
16085 #ifdef HAVE_WINDOW_SYSTEM
16086 if (FRAME_WINDOW_P (f
)
16087 && update_window_fringes (w
, (just_this_one_p
16088 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16089 || w
->pseudo_window_p
)))
16093 if (draw_window_fringes (w
, 1))
16094 x_draw_vertical_border (w
);
16098 #endif /* HAVE_WINDOW_SYSTEM */
16100 /* We go to this label, with fonts_changed_p nonzero,
16101 if it is necessary to try again using larger glyph matrices.
16102 We have to redeem the scroll bar even in this case,
16103 because the loop in redisplay_internal expects that. */
16104 need_larger_matrices
:
16106 finish_scroll_bars
:
16108 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16110 /* Set the thumb's position and size. */
16111 set_vertical_scroll_bar (w
);
16113 /* Note that we actually used the scroll bar attached to this
16114 window, so it shouldn't be deleted at the end of redisplay. */
16115 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16116 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16119 /* Restore current_buffer and value of point in it. The window
16120 update may have changed the buffer, so first make sure `opoint'
16121 is still valid (Bug#6177). */
16122 if (CHARPOS (opoint
) < BEGV
)
16123 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16124 else if (CHARPOS (opoint
) > ZV
)
16125 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16127 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16129 set_buffer_internal_1 (old
);
16130 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16131 shorter. This can be caused by log truncation in *Messages*. */
16132 if (CHARPOS (lpoint
) <= ZV
)
16133 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16135 unbind_to (count
, Qnil
);
16139 /* Build the complete desired matrix of WINDOW with a window start
16140 buffer position POS.
16142 Value is 1 if successful. It is zero if fonts were loaded during
16143 redisplay which makes re-adjusting glyph matrices necessary, and -1
16144 if point would appear in the scroll margins.
16145 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16146 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16150 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16152 struct window
*w
= XWINDOW (window
);
16154 struct glyph_row
*last_text_row
= NULL
;
16155 struct frame
*f
= XFRAME (w
->frame
);
16157 /* Make POS the new window start. */
16158 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16160 /* Mark cursor position as unknown. No overlay arrow seen. */
16161 w
->cursor
.vpos
= -1;
16162 overlay_arrow_seen
= 0;
16164 /* Initialize iterator and info to start at POS. */
16165 start_display (&it
, w
, pos
);
16167 /* Display all lines of W. */
16168 while (it
.current_y
< it
.last_visible_y
)
16170 if (display_line (&it
))
16171 last_text_row
= it
.glyph_row
- 1;
16172 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16176 /* Don't let the cursor end in the scroll margins. */
16177 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16178 && !MINI_WINDOW_P (w
))
16180 int this_scroll_margin
;
16182 if (scroll_margin
> 0)
16184 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16185 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16188 this_scroll_margin
= 0;
16190 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16191 && w
->cursor
.y
< this_scroll_margin
16192 && CHARPOS (pos
) > BEGV
16193 && IT_CHARPOS (it
) < ZV
)
16194 /* rms: considering make_cursor_line_fully_visible_p here
16195 seems to give wrong results. We don't want to recenter
16196 when the last line is partly visible, we want to allow
16197 that case to be handled in the usual way. */
16198 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16200 w
->cursor
.vpos
= -1;
16201 clear_glyph_matrix (w
->desired_matrix
);
16206 /* If bottom moved off end of frame, change mode line percentage. */
16207 if (XFASTINT (w
->window_end_pos
) <= 0
16208 && Z
!= IT_CHARPOS (it
))
16209 w
->update_mode_line
= Qt
;
16211 /* Set window_end_pos to the offset of the last character displayed
16212 on the window from the end of current_buffer. Set
16213 window_end_vpos to its row number. */
16216 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16217 w
->window_end_bytepos
16218 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16220 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16222 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16223 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16224 ->displays_text_p
);
16228 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16229 w
->window_end_pos
= make_number (Z
- ZV
);
16230 w
->window_end_vpos
= make_number (0);
16233 /* But that is not valid info until redisplay finishes. */
16234 w
->window_end_valid
= Qnil
;
16240 /************************************************************************
16241 Window redisplay reusing current matrix when buffer has not changed
16242 ************************************************************************/
16244 /* Try redisplay of window W showing an unchanged buffer with a
16245 different window start than the last time it was displayed by
16246 reusing its current matrix. Value is non-zero if successful.
16247 W->start is the new window start. */
16250 try_window_reusing_current_matrix (struct window
*w
)
16252 struct frame
*f
= XFRAME (w
->frame
);
16253 struct glyph_row
*bottom_row
;
16256 struct text_pos start
, new_start
;
16257 int nrows_scrolled
, i
;
16258 struct glyph_row
*last_text_row
;
16259 struct glyph_row
*last_reused_text_row
;
16260 struct glyph_row
*start_row
;
16261 int start_vpos
, min_y
, max_y
;
16264 if (inhibit_try_window_reusing
)
16268 if (/* This function doesn't handle terminal frames. */
16269 !FRAME_WINDOW_P (f
)
16270 /* Don't try to reuse the display if windows have been split
16272 || windows_or_buffers_changed
16273 || cursor_type_changed
)
16276 /* Can't do this if region may have changed. */
16277 if ((!NILP (Vtransient_mark_mode
)
16278 && !NILP (BVAR (current_buffer
, mark_active
)))
16279 || !NILP (w
->region_showing
)
16280 || !NILP (Vshow_trailing_whitespace
))
16283 /* If top-line visibility has changed, give up. */
16284 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16285 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16288 /* Give up if old or new display is scrolled vertically. We could
16289 make this function handle this, but right now it doesn't. */
16290 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16291 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16294 /* The variable new_start now holds the new window start. The old
16295 start `start' can be determined from the current matrix. */
16296 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16297 start
= start_row
->minpos
;
16298 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16300 /* Clear the desired matrix for the display below. */
16301 clear_glyph_matrix (w
->desired_matrix
);
16303 if (CHARPOS (new_start
) <= CHARPOS (start
))
16305 /* Don't use this method if the display starts with an ellipsis
16306 displayed for invisible text. It's not easy to handle that case
16307 below, and it's certainly not worth the effort since this is
16308 not a frequent case. */
16309 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16312 IF_DEBUG (debug_method_add (w
, "twu1"));
16314 /* Display up to a row that can be reused. The variable
16315 last_text_row is set to the last row displayed that displays
16316 text. Note that it.vpos == 0 if or if not there is a
16317 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16318 start_display (&it
, w
, new_start
);
16319 w
->cursor
.vpos
= -1;
16320 last_text_row
= last_reused_text_row
= NULL
;
16322 while (it
.current_y
< it
.last_visible_y
16323 && !fonts_changed_p
)
16325 /* If we have reached into the characters in the START row,
16326 that means the line boundaries have changed. So we
16327 can't start copying with the row START. Maybe it will
16328 work to start copying with the following row. */
16329 while (IT_CHARPOS (it
) > CHARPOS (start
))
16331 /* Advance to the next row as the "start". */
16333 start
= start_row
->minpos
;
16334 /* If there are no more rows to try, or just one, give up. */
16335 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16336 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16337 || CHARPOS (start
) == ZV
)
16339 clear_glyph_matrix (w
->desired_matrix
);
16343 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16345 /* If we have reached alignment, we can copy the rest of the
16347 if (IT_CHARPOS (it
) == CHARPOS (start
)
16348 /* Don't accept "alignment" inside a display vector,
16349 since start_row could have started in the middle of
16350 that same display vector (thus their character
16351 positions match), and we have no way of telling if
16352 that is the case. */
16353 && it
.current
.dpvec_index
< 0)
16356 if (display_line (&it
))
16357 last_text_row
= it
.glyph_row
- 1;
16361 /* A value of current_y < last_visible_y means that we stopped
16362 at the previous window start, which in turn means that we
16363 have at least one reusable row. */
16364 if (it
.current_y
< it
.last_visible_y
)
16366 struct glyph_row
*row
;
16368 /* IT.vpos always starts from 0; it counts text lines. */
16369 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16371 /* Find PT if not already found in the lines displayed. */
16372 if (w
->cursor
.vpos
< 0)
16374 int dy
= it
.current_y
- start_row
->y
;
16376 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16377 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16379 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16380 dy
, nrows_scrolled
);
16383 clear_glyph_matrix (w
->desired_matrix
);
16388 /* Scroll the display. Do it before the current matrix is
16389 changed. The problem here is that update has not yet
16390 run, i.e. part of the current matrix is not up to date.
16391 scroll_run_hook will clear the cursor, and use the
16392 current matrix to get the height of the row the cursor is
16394 run
.current_y
= start_row
->y
;
16395 run
.desired_y
= it
.current_y
;
16396 run
.height
= it
.last_visible_y
- it
.current_y
;
16398 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16401 FRAME_RIF (f
)->update_window_begin_hook (w
);
16402 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16403 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16404 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16408 /* Shift current matrix down by nrows_scrolled lines. */
16409 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16410 rotate_matrix (w
->current_matrix
,
16412 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16415 /* Disable lines that must be updated. */
16416 for (i
= 0; i
< nrows_scrolled
; ++i
)
16417 (start_row
+ i
)->enabled_p
= 0;
16419 /* Re-compute Y positions. */
16420 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16421 max_y
= it
.last_visible_y
;
16422 for (row
= start_row
+ nrows_scrolled
;
16426 row
->y
= it
.current_y
;
16427 row
->visible_height
= row
->height
;
16429 if (row
->y
< min_y
)
16430 row
->visible_height
-= min_y
- row
->y
;
16431 if (row
->y
+ row
->height
> max_y
)
16432 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16433 if (row
->fringe_bitmap_periodic_p
)
16434 row
->redraw_fringe_bitmaps_p
= 1;
16436 it
.current_y
+= row
->height
;
16438 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16439 last_reused_text_row
= row
;
16440 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16444 /* Disable lines in the current matrix which are now
16445 below the window. */
16446 for (++row
; row
< bottom_row
; ++row
)
16447 row
->enabled_p
= row
->mode_line_p
= 0;
16450 /* Update window_end_pos etc.; last_reused_text_row is the last
16451 reused row from the current matrix containing text, if any.
16452 The value of last_text_row is the last displayed line
16453 containing text. */
16454 if (last_reused_text_row
)
16456 w
->window_end_bytepos
16457 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16459 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16461 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16462 w
->current_matrix
));
16464 else if (last_text_row
)
16466 w
->window_end_bytepos
16467 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16469 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16471 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16475 /* This window must be completely empty. */
16476 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16477 w
->window_end_pos
= make_number (Z
- ZV
);
16478 w
->window_end_vpos
= make_number (0);
16480 w
->window_end_valid
= Qnil
;
16482 /* Update hint: don't try scrolling again in update_window. */
16483 w
->desired_matrix
->no_scrolling_p
= 1;
16486 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16490 else if (CHARPOS (new_start
) > CHARPOS (start
))
16492 struct glyph_row
*pt_row
, *row
;
16493 struct glyph_row
*first_reusable_row
;
16494 struct glyph_row
*first_row_to_display
;
16496 int yb
= window_text_bottom_y (w
);
16498 /* Find the row starting at new_start, if there is one. Don't
16499 reuse a partially visible line at the end. */
16500 first_reusable_row
= start_row
;
16501 while (first_reusable_row
->enabled_p
16502 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16503 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16504 < CHARPOS (new_start
)))
16505 ++first_reusable_row
;
16507 /* Give up if there is no row to reuse. */
16508 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16509 || !first_reusable_row
->enabled_p
16510 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16511 != CHARPOS (new_start
)))
16514 /* We can reuse fully visible rows beginning with
16515 first_reusable_row to the end of the window. Set
16516 first_row_to_display to the first row that cannot be reused.
16517 Set pt_row to the row containing point, if there is any. */
16519 for (first_row_to_display
= first_reusable_row
;
16520 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16521 ++first_row_to_display
)
16523 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16524 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16525 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16526 && first_row_to_display
->ends_at_zv_p
16527 && pt_row
== NULL
)))
16528 pt_row
= first_row_to_display
;
16531 /* Start displaying at the start of first_row_to_display. */
16532 xassert (first_row_to_display
->y
< yb
);
16533 init_to_row_start (&it
, w
, first_row_to_display
);
16535 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16537 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16539 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16540 + WINDOW_HEADER_LINE_HEIGHT (w
));
16542 /* Display lines beginning with first_row_to_display in the
16543 desired matrix. Set last_text_row to the last row displayed
16544 that displays text. */
16545 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16546 if (pt_row
== NULL
)
16547 w
->cursor
.vpos
= -1;
16548 last_text_row
= NULL
;
16549 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16550 if (display_line (&it
))
16551 last_text_row
= it
.glyph_row
- 1;
16553 /* If point is in a reused row, adjust y and vpos of the cursor
16557 w
->cursor
.vpos
-= nrows_scrolled
;
16558 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16561 /* Give up if point isn't in a row displayed or reused. (This
16562 also handles the case where w->cursor.vpos < nrows_scrolled
16563 after the calls to display_line, which can happen with scroll
16564 margins. See bug#1295.) */
16565 if (w
->cursor
.vpos
< 0)
16567 clear_glyph_matrix (w
->desired_matrix
);
16571 /* Scroll the display. */
16572 run
.current_y
= first_reusable_row
->y
;
16573 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16574 run
.height
= it
.last_visible_y
- run
.current_y
;
16575 dy
= run
.current_y
- run
.desired_y
;
16580 FRAME_RIF (f
)->update_window_begin_hook (w
);
16581 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16582 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16583 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16587 /* Adjust Y positions of reused rows. */
16588 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16589 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16590 max_y
= it
.last_visible_y
;
16591 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16594 row
->visible_height
= row
->height
;
16595 if (row
->y
< min_y
)
16596 row
->visible_height
-= min_y
- row
->y
;
16597 if (row
->y
+ row
->height
> max_y
)
16598 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16599 if (row
->fringe_bitmap_periodic_p
)
16600 row
->redraw_fringe_bitmaps_p
= 1;
16603 /* Scroll the current matrix. */
16604 xassert (nrows_scrolled
> 0);
16605 rotate_matrix (w
->current_matrix
,
16607 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16610 /* Disable rows not reused. */
16611 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16612 row
->enabled_p
= 0;
16614 /* Point may have moved to a different line, so we cannot assume that
16615 the previous cursor position is valid; locate the correct row. */
16618 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16620 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16621 && !row
->ends_at_zv_p
;
16625 w
->cursor
.y
= row
->y
;
16627 if (row
< bottom_row
)
16629 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16630 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16632 /* Can't use this optimization with bidi-reordered glyph
16633 rows, unless cursor is already at point. */
16634 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16636 if (!(w
->cursor
.hpos
>= 0
16637 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16638 && BUFFERP (glyph
->object
)
16639 && glyph
->charpos
== PT
))
16644 && (!BUFFERP (glyph
->object
)
16645 || glyph
->charpos
< PT
);
16649 w
->cursor
.x
+= glyph
->pixel_width
;
16654 /* Adjust window end. A null value of last_text_row means that
16655 the window end is in reused rows which in turn means that
16656 only its vpos can have changed. */
16659 w
->window_end_bytepos
16660 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16662 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16664 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16669 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16672 w
->window_end_valid
= Qnil
;
16673 w
->desired_matrix
->no_scrolling_p
= 1;
16676 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16686 /************************************************************************
16687 Window redisplay reusing current matrix when buffer has changed
16688 ************************************************************************/
16690 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16691 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16692 ptrdiff_t *, ptrdiff_t *);
16693 static struct glyph_row
*
16694 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16695 struct glyph_row
*);
16698 /* Return the last row in MATRIX displaying text. If row START is
16699 non-null, start searching with that row. IT gives the dimensions
16700 of the display. Value is null if matrix is empty; otherwise it is
16701 a pointer to the row found. */
16703 static struct glyph_row
*
16704 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16705 struct glyph_row
*start
)
16707 struct glyph_row
*row
, *row_found
;
16709 /* Set row_found to the last row in IT->w's current matrix
16710 displaying text. The loop looks funny but think of partially
16713 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16714 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16716 xassert (row
->enabled_p
);
16718 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16727 /* Return the last row in the current matrix of W that is not affected
16728 by changes at the start of current_buffer that occurred since W's
16729 current matrix was built. Value is null if no such row exists.
16731 BEG_UNCHANGED us the number of characters unchanged at the start of
16732 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16733 first changed character in current_buffer. Characters at positions <
16734 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16735 when the current matrix was built. */
16737 static struct glyph_row
*
16738 find_last_unchanged_at_beg_row (struct window
*w
)
16740 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16741 struct glyph_row
*row
;
16742 struct glyph_row
*row_found
= NULL
;
16743 int yb
= window_text_bottom_y (w
);
16745 /* Find the last row displaying unchanged text. */
16746 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16747 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16748 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16751 if (/* If row ends before first_changed_pos, it is unchanged,
16752 except in some case. */
16753 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16754 /* When row ends in ZV and we write at ZV it is not
16756 && !row
->ends_at_zv_p
16757 /* When first_changed_pos is the end of a continued line,
16758 row is not unchanged because it may be no longer
16760 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16761 && (row
->continued_p
16762 || row
->exact_window_width_line_p
))
16763 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16764 needs to be recomputed, so don't consider this row as
16765 unchanged. This happens when the last line was
16766 bidi-reordered and was killed immediately before this
16767 redisplay cycle. In that case, ROW->end stores the
16768 buffer position of the first visual-order character of
16769 the killed text, which is now beyond ZV. */
16770 && CHARPOS (row
->end
.pos
) <= ZV
)
16773 /* Stop if last visible row. */
16774 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16782 /* Find the first glyph row in the current matrix of W that is not
16783 affected by changes at the end of current_buffer since the
16784 time W's current matrix was built.
16786 Return in *DELTA the number of chars by which buffer positions in
16787 unchanged text at the end of current_buffer must be adjusted.
16789 Return in *DELTA_BYTES the corresponding number of bytes.
16791 Value is null if no such row exists, i.e. all rows are affected by
16794 static struct glyph_row
*
16795 find_first_unchanged_at_end_row (struct window
*w
,
16796 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16798 struct glyph_row
*row
;
16799 struct glyph_row
*row_found
= NULL
;
16801 *delta
= *delta_bytes
= 0;
16803 /* Display must not have been paused, otherwise the current matrix
16804 is not up to date. */
16805 eassert (!NILP (w
->window_end_valid
));
16807 /* A value of window_end_pos >= END_UNCHANGED means that the window
16808 end is in the range of changed text. If so, there is no
16809 unchanged row at the end of W's current matrix. */
16810 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16813 /* Set row to the last row in W's current matrix displaying text. */
16814 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16816 /* If matrix is entirely empty, no unchanged row exists. */
16817 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16819 /* The value of row is the last glyph row in the matrix having a
16820 meaningful buffer position in it. The end position of row
16821 corresponds to window_end_pos. This allows us to translate
16822 buffer positions in the current matrix to current buffer
16823 positions for characters not in changed text. */
16825 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16826 ptrdiff_t Z_BYTE_old
=
16827 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16828 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16829 struct glyph_row
*first_text_row
16830 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16832 *delta
= Z
- Z_old
;
16833 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16835 /* Set last_unchanged_pos to the buffer position of the last
16836 character in the buffer that has not been changed. Z is the
16837 index + 1 of the last character in current_buffer, i.e. by
16838 subtracting END_UNCHANGED we get the index of the last
16839 unchanged character, and we have to add BEG to get its buffer
16841 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16842 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16844 /* Search backward from ROW for a row displaying a line that
16845 starts at a minimum position >= last_unchanged_pos_old. */
16846 for (; row
> first_text_row
; --row
)
16848 /* This used to abort, but it can happen.
16849 It is ok to just stop the search instead here. KFS. */
16850 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16853 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16858 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16864 /* Make sure that glyph rows in the current matrix of window W
16865 reference the same glyph memory as corresponding rows in the
16866 frame's frame matrix. This function is called after scrolling W's
16867 current matrix on a terminal frame in try_window_id and
16868 try_window_reusing_current_matrix. */
16871 sync_frame_with_window_matrix_rows (struct window
*w
)
16873 struct frame
*f
= XFRAME (w
->frame
);
16874 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16876 /* Preconditions: W must be a leaf window and full-width. Its frame
16877 must have a frame matrix. */
16878 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16879 xassert (WINDOW_FULL_WIDTH_P (w
));
16880 xassert (!FRAME_WINDOW_P (f
));
16882 /* If W is a full-width window, glyph pointers in W's current matrix
16883 have, by definition, to be the same as glyph pointers in the
16884 corresponding frame matrix. Note that frame matrices have no
16885 marginal areas (see build_frame_matrix). */
16886 window_row
= w
->current_matrix
->rows
;
16887 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16888 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16889 while (window_row
< window_row_end
)
16891 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16892 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16894 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16895 frame_row
->glyphs
[TEXT_AREA
] = start
;
16896 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16897 frame_row
->glyphs
[LAST_AREA
] = end
;
16899 /* Disable frame rows whose corresponding window rows have
16900 been disabled in try_window_id. */
16901 if (!window_row
->enabled_p
)
16902 frame_row
->enabled_p
= 0;
16904 ++window_row
, ++frame_row
;
16909 /* Find the glyph row in window W containing CHARPOS. Consider all
16910 rows between START and END (not inclusive). END null means search
16911 all rows to the end of the display area of W. Value is the row
16912 containing CHARPOS or null. */
16915 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16916 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16918 struct glyph_row
*row
= start
;
16919 struct glyph_row
*best_row
= NULL
;
16920 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16923 /* If we happen to start on a header-line, skip that. */
16924 if (row
->mode_line_p
)
16927 if ((end
&& row
>= end
) || !row
->enabled_p
)
16930 last_y
= window_text_bottom_y (w
) - dy
;
16934 /* Give up if we have gone too far. */
16935 if (end
&& row
>= end
)
16937 /* This formerly returned if they were equal.
16938 I think that both quantities are of a "last plus one" type;
16939 if so, when they are equal, the row is within the screen. -- rms. */
16940 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16943 /* If it is in this row, return this row. */
16944 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16945 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16946 /* The end position of a row equals the start
16947 position of the next row. If CHARPOS is there, we
16948 would rather display it in the next line, except
16949 when this line ends in ZV. */
16950 && !row
->ends_at_zv_p
16951 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16952 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16956 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16957 || (!best_row
&& !row
->continued_p
))
16959 /* In bidi-reordered rows, there could be several rows
16960 occluding point, all of them belonging to the same
16961 continued line. We need to find the row which fits
16962 CHARPOS the best. */
16963 for (g
= row
->glyphs
[TEXT_AREA
];
16964 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16967 if (!STRINGP (g
->object
))
16969 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16971 mindif
= eabs (g
->charpos
- charpos
);
16973 /* Exact match always wins. */
16980 else if (best_row
&& !row
->continued_p
)
16987 /* Try to redisplay window W by reusing its existing display. W's
16988 current matrix must be up to date when this function is called,
16989 i.e. window_end_valid must not be nil.
16993 1 if display has been updated
16994 0 if otherwise unsuccessful
16995 -1 if redisplay with same window start is known not to succeed
16997 The following steps are performed:
16999 1. Find the last row in the current matrix of W that is not
17000 affected by changes at the start of current_buffer. If no such row
17003 2. Find the first row in W's current matrix that is not affected by
17004 changes at the end of current_buffer. Maybe there is no such row.
17006 3. Display lines beginning with the row + 1 found in step 1 to the
17007 row found in step 2 or, if step 2 didn't find a row, to the end of
17010 4. If cursor is not known to appear on the window, give up.
17012 5. If display stopped at the row found in step 2, scroll the
17013 display and current matrix as needed.
17015 6. Maybe display some lines at the end of W, if we must. This can
17016 happen under various circumstances, like a partially visible line
17017 becoming fully visible, or because newly displayed lines are displayed
17018 in smaller font sizes.
17020 7. Update W's window end information. */
17023 try_window_id (struct window
*w
)
17025 struct frame
*f
= XFRAME (w
->frame
);
17026 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17027 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17028 struct glyph_row
*last_unchanged_at_beg_row
;
17029 struct glyph_row
*first_unchanged_at_end_row
;
17030 struct glyph_row
*row
;
17031 struct glyph_row
*bottom_row
;
17034 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17036 struct text_pos start_pos
;
17038 int first_unchanged_at_end_vpos
= 0;
17039 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17040 struct text_pos start
;
17041 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17044 if (inhibit_try_window_id
)
17048 /* This is handy for debugging. */
17050 #define GIVE_UP(X) \
17052 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17056 #define GIVE_UP(X) return 0
17059 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17061 /* Don't use this for mini-windows because these can show
17062 messages and mini-buffers, and we don't handle that here. */
17063 if (MINI_WINDOW_P (w
))
17066 /* This flag is used to prevent redisplay optimizations. */
17067 if (windows_or_buffers_changed
|| cursor_type_changed
)
17070 /* Verify that narrowing has not changed.
17071 Also verify that we were not told to prevent redisplay optimizations.
17072 It would be nice to further
17073 reduce the number of cases where this prevents try_window_id. */
17074 if (current_buffer
->clip_changed
17075 || current_buffer
->prevent_redisplay_optimizations_p
)
17078 /* Window must either use window-based redisplay or be full width. */
17079 if (!FRAME_WINDOW_P (f
)
17080 && (!FRAME_LINE_INS_DEL_OK (f
)
17081 || !WINDOW_FULL_WIDTH_P (w
)))
17084 /* Give up if point is known NOT to appear in W. */
17085 if (PT
< CHARPOS (start
))
17088 /* Another way to prevent redisplay optimizations. */
17089 if (XFASTINT (w
->last_modified
) == 0)
17092 /* Verify that window is not hscrolled. */
17093 if (XFASTINT (w
->hscroll
) != 0)
17096 /* Verify that display wasn't paused. */
17097 if (NILP (w
->window_end_valid
))
17100 /* Can't use this if highlighting a region because a cursor movement
17101 will do more than just set the cursor. */
17102 if (!NILP (Vtransient_mark_mode
)
17103 && !NILP (BVAR (current_buffer
, mark_active
)))
17106 /* Likewise if highlighting trailing whitespace. */
17107 if (!NILP (Vshow_trailing_whitespace
))
17110 /* Likewise if showing a region. */
17111 if (!NILP (w
->region_showing
))
17114 /* Can't use this if overlay arrow position and/or string have
17116 if (overlay_arrows_changed_p ())
17119 /* When word-wrap is on, adding a space to the first word of a
17120 wrapped line can change the wrap position, altering the line
17121 above it. It might be worthwhile to handle this more
17122 intelligently, but for now just redisplay from scratch. */
17123 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17126 /* Under bidi reordering, adding or deleting a character in the
17127 beginning of a paragraph, before the first strong directional
17128 character, can change the base direction of the paragraph (unless
17129 the buffer specifies a fixed paragraph direction), which will
17130 require to redisplay the whole paragraph. It might be worthwhile
17131 to find the paragraph limits and widen the range of redisplayed
17132 lines to that, but for now just give up this optimization and
17133 redisplay from scratch. */
17134 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17135 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17138 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17139 only if buffer has really changed. The reason is that the gap is
17140 initially at Z for freshly visited files. The code below would
17141 set end_unchanged to 0 in that case. */
17142 if (MODIFF
> SAVE_MODIFF
17143 /* This seems to happen sometimes after saving a buffer. */
17144 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17146 if (GPT
- BEG
< BEG_UNCHANGED
)
17147 BEG_UNCHANGED
= GPT
- BEG
;
17148 if (Z
- GPT
< END_UNCHANGED
)
17149 END_UNCHANGED
= Z
- GPT
;
17152 /* The position of the first and last character that has been changed. */
17153 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17154 last_changed_charpos
= Z
- END_UNCHANGED
;
17156 /* If window starts after a line end, and the last change is in
17157 front of that newline, then changes don't affect the display.
17158 This case happens with stealth-fontification. Note that although
17159 the display is unchanged, glyph positions in the matrix have to
17160 be adjusted, of course. */
17161 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17162 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17163 && ((last_changed_charpos
< CHARPOS (start
)
17164 && CHARPOS (start
) == BEGV
)
17165 || (last_changed_charpos
< CHARPOS (start
) - 1
17166 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17168 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17169 struct glyph_row
*r0
;
17171 /* Compute how many chars/bytes have been added to or removed
17172 from the buffer. */
17173 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17174 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17175 Z_delta
= Z
- Z_old
;
17176 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17178 /* Give up if PT is not in the window. Note that it already has
17179 been checked at the start of try_window_id that PT is not in
17180 front of the window start. */
17181 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17184 /* If window start is unchanged, we can reuse the whole matrix
17185 as is, after adjusting glyph positions. No need to compute
17186 the window end again, since its offset from Z hasn't changed. */
17187 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17188 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17189 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17190 /* PT must not be in a partially visible line. */
17191 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17192 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17194 /* Adjust positions in the glyph matrix. */
17195 if (Z_delta
|| Z_delta_bytes
)
17197 struct glyph_row
*r1
17198 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17199 increment_matrix_positions (w
->current_matrix
,
17200 MATRIX_ROW_VPOS (r0
, current_matrix
),
17201 MATRIX_ROW_VPOS (r1
, current_matrix
),
17202 Z_delta
, Z_delta_bytes
);
17205 /* Set the cursor. */
17206 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17208 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17215 /* Handle the case that changes are all below what is displayed in
17216 the window, and that PT is in the window. This shortcut cannot
17217 be taken if ZV is visible in the window, and text has been added
17218 there that is visible in the window. */
17219 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17220 /* ZV is not visible in the window, or there are no
17221 changes at ZV, actually. */
17222 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17223 || first_changed_charpos
== last_changed_charpos
))
17225 struct glyph_row
*r0
;
17227 /* Give up if PT is not in the window. Note that it already has
17228 been checked at the start of try_window_id that PT is not in
17229 front of the window start. */
17230 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17233 /* If window start is unchanged, we can reuse the whole matrix
17234 as is, without changing glyph positions since no text has
17235 been added/removed in front of the window end. */
17236 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17237 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17238 /* PT must not be in a partially visible line. */
17239 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17240 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17242 /* We have to compute the window end anew since text
17243 could have been added/removed after it. */
17245 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17246 w
->window_end_bytepos
17247 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17249 /* Set the cursor. */
17250 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17252 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17259 /* Give up if window start is in the changed area.
17261 The condition used to read
17263 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17265 but why that was tested escapes me at the moment. */
17266 if (CHARPOS (start
) >= first_changed_charpos
17267 && CHARPOS (start
) <= last_changed_charpos
)
17270 /* Check that window start agrees with the start of the first glyph
17271 row in its current matrix. Check this after we know the window
17272 start is not in changed text, otherwise positions would not be
17274 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17275 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17278 /* Give up if the window ends in strings. Overlay strings
17279 at the end are difficult to handle, so don't try. */
17280 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17281 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17284 /* Compute the position at which we have to start displaying new
17285 lines. Some of the lines at the top of the window might be
17286 reusable because they are not displaying changed text. Find the
17287 last row in W's current matrix not affected by changes at the
17288 start of current_buffer. Value is null if changes start in the
17289 first line of window. */
17290 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17291 if (last_unchanged_at_beg_row
)
17293 /* Avoid starting to display in the middle of a character, a TAB
17294 for instance. This is easier than to set up the iterator
17295 exactly, and it's not a frequent case, so the additional
17296 effort wouldn't really pay off. */
17297 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17298 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17299 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17300 --last_unchanged_at_beg_row
;
17302 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17305 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17307 start_pos
= it
.current
.pos
;
17309 /* Start displaying new lines in the desired matrix at the same
17310 vpos we would use in the current matrix, i.e. below
17311 last_unchanged_at_beg_row. */
17312 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17314 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17315 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17317 xassert (it
.hpos
== 0 && it
.current_x
== 0);
17321 /* There are no reusable lines at the start of the window.
17322 Start displaying in the first text line. */
17323 start_display (&it
, w
, start
);
17324 it
.vpos
= it
.first_vpos
;
17325 start_pos
= it
.current
.pos
;
17328 /* Find the first row that is not affected by changes at the end of
17329 the buffer. Value will be null if there is no unchanged row, in
17330 which case we must redisplay to the end of the window. delta
17331 will be set to the value by which buffer positions beginning with
17332 first_unchanged_at_end_row have to be adjusted due to text
17334 first_unchanged_at_end_row
17335 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17336 IF_DEBUG (debug_delta
= delta
);
17337 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17339 /* Set stop_pos to the buffer position up to which we will have to
17340 display new lines. If first_unchanged_at_end_row != NULL, this
17341 is the buffer position of the start of the line displayed in that
17342 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17343 that we don't stop at a buffer position. */
17345 if (first_unchanged_at_end_row
)
17347 xassert (last_unchanged_at_beg_row
== NULL
17348 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17350 /* If this is a continuation line, move forward to the next one
17351 that isn't. Changes in lines above affect this line.
17352 Caution: this may move first_unchanged_at_end_row to a row
17353 not displaying text. */
17354 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17355 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17356 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17357 < it
.last_visible_y
))
17358 ++first_unchanged_at_end_row
;
17360 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17361 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17362 >= it
.last_visible_y
))
17363 first_unchanged_at_end_row
= NULL
;
17366 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17368 first_unchanged_at_end_vpos
17369 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17370 xassert (stop_pos
>= Z
- END_UNCHANGED
);
17373 else if (last_unchanged_at_beg_row
== NULL
)
17379 /* Either there is no unchanged row at the end, or the one we have
17380 now displays text. This is a necessary condition for the window
17381 end pos calculation at the end of this function. */
17382 xassert (first_unchanged_at_end_row
== NULL
17383 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17385 debug_last_unchanged_at_beg_vpos
17386 = (last_unchanged_at_beg_row
17387 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17389 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17391 #endif /* GLYPH_DEBUG != 0 */
17394 /* Display new lines. Set last_text_row to the last new line
17395 displayed which has text on it, i.e. might end up as being the
17396 line where the window_end_vpos is. */
17397 w
->cursor
.vpos
= -1;
17398 last_text_row
= NULL
;
17399 overlay_arrow_seen
= 0;
17400 while (it
.current_y
< it
.last_visible_y
17401 && !fonts_changed_p
17402 && (first_unchanged_at_end_row
== NULL
17403 || IT_CHARPOS (it
) < stop_pos
))
17405 if (display_line (&it
))
17406 last_text_row
= it
.glyph_row
- 1;
17409 if (fonts_changed_p
)
17413 /* Compute differences in buffer positions, y-positions etc. for
17414 lines reused at the bottom of the window. Compute what we can
17416 if (first_unchanged_at_end_row
17417 /* No lines reused because we displayed everything up to the
17418 bottom of the window. */
17419 && it
.current_y
< it
.last_visible_y
)
17422 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17424 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17425 run
.current_y
= first_unchanged_at_end_row
->y
;
17426 run
.desired_y
= run
.current_y
+ dy
;
17427 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17431 delta
= delta_bytes
= dvpos
= dy
17432 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17433 first_unchanged_at_end_row
= NULL
;
17435 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17438 /* Find the cursor if not already found. We have to decide whether
17439 PT will appear on this window (it sometimes doesn't, but this is
17440 not a very frequent case.) This decision has to be made before
17441 the current matrix is altered. A value of cursor.vpos < 0 means
17442 that PT is either in one of the lines beginning at
17443 first_unchanged_at_end_row or below the window. Don't care for
17444 lines that might be displayed later at the window end; as
17445 mentioned, this is not a frequent case. */
17446 if (w
->cursor
.vpos
< 0)
17448 /* Cursor in unchanged rows at the top? */
17449 if (PT
< CHARPOS (start_pos
)
17450 && last_unchanged_at_beg_row
)
17452 row
= row_containing_pos (w
, PT
,
17453 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17454 last_unchanged_at_beg_row
+ 1, 0);
17456 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17459 /* Start from first_unchanged_at_end_row looking for PT. */
17460 else if (first_unchanged_at_end_row
)
17462 row
= row_containing_pos (w
, PT
- delta
,
17463 first_unchanged_at_end_row
, NULL
, 0);
17465 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17466 delta_bytes
, dy
, dvpos
);
17469 /* Give up if cursor was not found. */
17470 if (w
->cursor
.vpos
< 0)
17472 clear_glyph_matrix (w
->desired_matrix
);
17477 /* Don't let the cursor end in the scroll margins. */
17479 int this_scroll_margin
, cursor_height
;
17481 this_scroll_margin
=
17482 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17483 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17484 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17486 if ((w
->cursor
.y
< this_scroll_margin
17487 && CHARPOS (start
) > BEGV
)
17488 /* Old redisplay didn't take scroll margin into account at the bottom,
17489 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17490 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17491 ? cursor_height
+ this_scroll_margin
17492 : 1)) > it
.last_visible_y
)
17494 w
->cursor
.vpos
= -1;
17495 clear_glyph_matrix (w
->desired_matrix
);
17500 /* Scroll the display. Do it before changing the current matrix so
17501 that xterm.c doesn't get confused about where the cursor glyph is
17503 if (dy
&& run
.height
)
17507 if (FRAME_WINDOW_P (f
))
17509 FRAME_RIF (f
)->update_window_begin_hook (w
);
17510 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17511 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17512 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17516 /* Terminal frame. In this case, dvpos gives the number of
17517 lines to scroll by; dvpos < 0 means scroll up. */
17519 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17520 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17521 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17522 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17523 + window_internal_height (w
));
17525 #if defined (HAVE_GPM) || defined (MSDOS)
17526 x_clear_window_mouse_face (w
);
17528 /* Perform the operation on the screen. */
17531 /* Scroll last_unchanged_at_beg_row to the end of the
17532 window down dvpos lines. */
17533 set_terminal_window (f
, end
);
17535 /* On dumb terminals delete dvpos lines at the end
17536 before inserting dvpos empty lines. */
17537 if (!FRAME_SCROLL_REGION_OK (f
))
17538 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17540 /* Insert dvpos empty lines in front of
17541 last_unchanged_at_beg_row. */
17542 ins_del_lines (f
, from
, dvpos
);
17544 else if (dvpos
< 0)
17546 /* Scroll up last_unchanged_at_beg_vpos to the end of
17547 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17548 set_terminal_window (f
, end
);
17550 /* Delete dvpos lines in front of
17551 last_unchanged_at_beg_vpos. ins_del_lines will set
17552 the cursor to the given vpos and emit |dvpos| delete
17554 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17556 /* On a dumb terminal insert dvpos empty lines at the
17558 if (!FRAME_SCROLL_REGION_OK (f
))
17559 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17562 set_terminal_window (f
, 0);
17568 /* Shift reused rows of the current matrix to the right position.
17569 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17571 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17572 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17575 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17576 bottom_vpos
, dvpos
);
17577 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17580 else if (dvpos
> 0)
17582 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17583 bottom_vpos
, dvpos
);
17584 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17585 first_unchanged_at_end_vpos
+ dvpos
, 0);
17588 /* For frame-based redisplay, make sure that current frame and window
17589 matrix are in sync with respect to glyph memory. */
17590 if (!FRAME_WINDOW_P (f
))
17591 sync_frame_with_window_matrix_rows (w
);
17593 /* Adjust buffer positions in reused rows. */
17594 if (delta
|| delta_bytes
)
17595 increment_matrix_positions (current_matrix
,
17596 first_unchanged_at_end_vpos
+ dvpos
,
17597 bottom_vpos
, delta
, delta_bytes
);
17599 /* Adjust Y positions. */
17601 shift_glyph_matrix (w
, current_matrix
,
17602 first_unchanged_at_end_vpos
+ dvpos
,
17605 if (first_unchanged_at_end_row
)
17607 first_unchanged_at_end_row
+= dvpos
;
17608 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17609 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17610 first_unchanged_at_end_row
= NULL
;
17613 /* If scrolling up, there may be some lines to display at the end of
17615 last_text_row_at_end
= NULL
;
17618 /* Scrolling up can leave for example a partially visible line
17619 at the end of the window to be redisplayed. */
17620 /* Set last_row to the glyph row in the current matrix where the
17621 window end line is found. It has been moved up or down in
17622 the matrix by dvpos. */
17623 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17624 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17626 /* If last_row is the window end line, it should display text. */
17627 xassert (last_row
->displays_text_p
);
17629 /* If window end line was partially visible before, begin
17630 displaying at that line. Otherwise begin displaying with the
17631 line following it. */
17632 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17634 init_to_row_start (&it
, w
, last_row
);
17635 it
.vpos
= last_vpos
;
17636 it
.current_y
= last_row
->y
;
17640 init_to_row_end (&it
, w
, last_row
);
17641 it
.vpos
= 1 + last_vpos
;
17642 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17646 /* We may start in a continuation line. If so, we have to
17647 get the right continuation_lines_width and current_x. */
17648 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17649 it
.hpos
= it
.current_x
= 0;
17651 /* Display the rest of the lines at the window end. */
17652 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17653 while (it
.current_y
< it
.last_visible_y
17654 && !fonts_changed_p
)
17656 /* Is it always sure that the display agrees with lines in
17657 the current matrix? I don't think so, so we mark rows
17658 displayed invalid in the current matrix by setting their
17659 enabled_p flag to zero. */
17660 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17661 if (display_line (&it
))
17662 last_text_row_at_end
= it
.glyph_row
- 1;
17666 /* Update window_end_pos and window_end_vpos. */
17667 if (first_unchanged_at_end_row
17668 && !last_text_row_at_end
)
17670 /* Window end line if one of the preserved rows from the current
17671 matrix. Set row to the last row displaying text in current
17672 matrix starting at first_unchanged_at_end_row, after
17674 xassert (first_unchanged_at_end_row
->displays_text_p
);
17675 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17676 first_unchanged_at_end_row
);
17677 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17679 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17680 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17682 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17683 xassert (w
->window_end_bytepos
>= 0);
17684 IF_DEBUG (debug_method_add (w
, "A"));
17686 else if (last_text_row_at_end
)
17689 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17690 w
->window_end_bytepos
17691 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17693 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17694 xassert (w
->window_end_bytepos
>= 0);
17695 IF_DEBUG (debug_method_add (w
, "B"));
17697 else if (last_text_row
)
17699 /* We have displayed either to the end of the window or at the
17700 end of the window, i.e. the last row with text is to be found
17701 in the desired matrix. */
17703 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17704 w
->window_end_bytepos
17705 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17707 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17708 xassert (w
->window_end_bytepos
>= 0);
17710 else if (first_unchanged_at_end_row
== NULL
17711 && last_text_row
== NULL
17712 && last_text_row_at_end
== NULL
)
17714 /* Displayed to end of window, but no line containing text was
17715 displayed. Lines were deleted at the end of the window. */
17716 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17717 int vpos
= XFASTINT (w
->window_end_vpos
);
17718 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17719 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17722 row
== NULL
&& vpos
>= first_vpos
;
17723 --vpos
, --current_row
, --desired_row
)
17725 if (desired_row
->enabled_p
)
17727 if (desired_row
->displays_text_p
)
17730 else if (current_row
->displays_text_p
)
17734 xassert (row
!= NULL
);
17735 w
->window_end_vpos
= make_number (vpos
+ 1);
17736 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17737 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17738 xassert (w
->window_end_bytepos
>= 0);
17739 IF_DEBUG (debug_method_add (w
, "C"));
17744 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17745 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17747 /* Record that display has not been completed. */
17748 w
->window_end_valid
= Qnil
;
17749 w
->desired_matrix
->no_scrolling_p
= 1;
17757 /***********************************************************************
17758 More debugging support
17759 ***********************************************************************/
17763 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17764 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17765 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17768 /* Dump the contents of glyph matrix MATRIX on stderr.
17770 GLYPHS 0 means don't show glyph contents.
17771 GLYPHS 1 means show glyphs in short form
17772 GLYPHS > 1 means show glyphs in long form. */
17775 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17778 for (i
= 0; i
< matrix
->nrows
; ++i
)
17779 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17783 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17784 the glyph row and area where the glyph comes from. */
17787 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17789 if (glyph
->type
== CHAR_GLYPH
)
17792 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17793 glyph
- row
->glyphs
[TEXT_AREA
],
17796 (BUFFERP (glyph
->object
)
17798 : (STRINGP (glyph
->object
)
17801 glyph
->pixel_width
,
17803 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17807 glyph
->left_box_line_p
,
17808 glyph
->right_box_line_p
);
17810 else if (glyph
->type
== STRETCH_GLYPH
)
17813 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17814 glyph
- row
->glyphs
[TEXT_AREA
],
17817 (BUFFERP (glyph
->object
)
17819 : (STRINGP (glyph
->object
)
17822 glyph
->pixel_width
,
17826 glyph
->left_box_line_p
,
17827 glyph
->right_box_line_p
);
17829 else if (glyph
->type
== IMAGE_GLYPH
)
17832 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17833 glyph
- row
->glyphs
[TEXT_AREA
],
17836 (BUFFERP (glyph
->object
)
17838 : (STRINGP (glyph
->object
)
17841 glyph
->pixel_width
,
17845 glyph
->left_box_line_p
,
17846 glyph
->right_box_line_p
);
17848 else if (glyph
->type
== COMPOSITE_GLYPH
)
17851 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17852 glyph
- row
->glyphs
[TEXT_AREA
],
17855 (BUFFERP (glyph
->object
)
17857 : (STRINGP (glyph
->object
)
17860 glyph
->pixel_width
,
17862 if (glyph
->u
.cmp
.automatic
)
17865 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17866 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17868 glyph
->left_box_line_p
,
17869 glyph
->right_box_line_p
);
17874 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17875 GLYPHS 0 means don't show glyph contents.
17876 GLYPHS 1 means show glyphs in short form
17877 GLYPHS > 1 means show glyphs in long form. */
17880 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17884 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17885 fprintf (stderr
, "======================================================================\n");
17887 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17888 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17890 MATRIX_ROW_START_CHARPOS (row
),
17891 MATRIX_ROW_END_CHARPOS (row
),
17892 row
->used
[TEXT_AREA
],
17893 row
->contains_overlapping_glyphs_p
,
17895 row
->truncated_on_left_p
,
17896 row
->truncated_on_right_p
,
17898 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17899 row
->displays_text_p
,
17902 row
->ends_in_middle_of_char_p
,
17903 row
->starts_in_middle_of_char_p
,
17909 row
->visible_height
,
17912 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17913 row
->end
.overlay_string_index
,
17914 row
->continuation_lines_width
);
17915 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17916 CHARPOS (row
->start
.string_pos
),
17917 CHARPOS (row
->end
.string_pos
));
17918 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17919 row
->end
.dpvec_index
);
17926 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17928 struct glyph
*glyph
= row
->glyphs
[area
];
17929 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17931 /* Glyph for a line end in text. */
17932 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17935 if (glyph
< glyph_end
)
17936 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
17938 for (; glyph
< glyph_end
; ++glyph
)
17939 dump_glyph (row
, glyph
, area
);
17942 else if (glyphs
== 1)
17946 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17948 char *s
= (char *) alloca (row
->used
[area
] + 1);
17951 for (i
= 0; i
< row
->used
[area
]; ++i
)
17953 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17954 if (glyph
->type
== CHAR_GLYPH
17955 && glyph
->u
.ch
< 0x80
17956 && glyph
->u
.ch
>= ' ')
17957 s
[i
] = glyph
->u
.ch
;
17963 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17969 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17970 Sdump_glyph_matrix
, 0, 1, "p",
17971 doc
: /* Dump the current matrix of the selected window to stderr.
17972 Shows contents of glyph row structures. With non-nil
17973 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17974 glyphs in short form, otherwise show glyphs in long form. */)
17975 (Lisp_Object glyphs
)
17977 struct window
*w
= XWINDOW (selected_window
);
17978 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17980 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17981 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17982 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17983 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17984 fprintf (stderr
, "=============================================\n");
17985 dump_glyph_matrix (w
->current_matrix
,
17986 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17991 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17992 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17995 struct frame
*f
= XFRAME (selected_frame
);
17996 dump_glyph_matrix (f
->current_matrix
, 1);
18001 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18002 doc
: /* Dump glyph row ROW to stderr.
18003 GLYPH 0 means don't dump glyphs.
18004 GLYPH 1 means dump glyphs in short form.
18005 GLYPH > 1 or omitted means dump glyphs in long form. */)
18006 (Lisp_Object row
, Lisp_Object glyphs
)
18008 struct glyph_matrix
*matrix
;
18011 CHECK_NUMBER (row
);
18012 matrix
= XWINDOW (selected_window
)->current_matrix
;
18014 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18015 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18017 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18022 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18023 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18024 GLYPH 0 means don't dump glyphs.
18025 GLYPH 1 means dump glyphs in short form.
18026 GLYPH > 1 or omitted means dump glyphs in long form. */)
18027 (Lisp_Object row
, Lisp_Object glyphs
)
18029 struct frame
*sf
= SELECTED_FRAME ();
18030 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18033 CHECK_NUMBER (row
);
18035 if (vpos
>= 0 && vpos
< m
->nrows
)
18036 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18037 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18042 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18043 doc
: /* Toggle tracing of redisplay.
18044 With ARG, turn tracing on if and only if ARG is positive. */)
18048 trace_redisplay_p
= !trace_redisplay_p
;
18051 arg
= Fprefix_numeric_value (arg
);
18052 trace_redisplay_p
= XINT (arg
) > 0;
18059 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18060 doc
: /* Like `format', but print result to stderr.
18061 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18062 (ptrdiff_t nargs
, Lisp_Object
*args
)
18064 Lisp_Object s
= Fformat (nargs
, args
);
18065 fprintf (stderr
, "%s", SDATA (s
));
18069 #endif /* GLYPH_DEBUG */
18073 /***********************************************************************
18074 Building Desired Matrix Rows
18075 ***********************************************************************/
18077 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18078 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18080 static struct glyph_row
*
18081 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18083 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18084 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18085 struct buffer
*old
= current_buffer
;
18086 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18087 int arrow_len
= SCHARS (overlay_arrow_string
);
18088 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18089 const unsigned char *p
;
18092 int n_glyphs_before
;
18094 set_buffer_temp (buffer
);
18095 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18096 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18097 SET_TEXT_POS (it
.position
, 0, 0);
18099 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18101 while (p
< arrow_end
)
18103 Lisp_Object face
, ilisp
;
18105 /* Get the next character. */
18107 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18110 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18111 if (! ASCII_CHAR_P (it
.c
))
18112 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18116 /* Get its face. */
18117 ilisp
= make_number (p
- arrow_string
);
18118 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18119 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18121 /* Compute its width, get its glyphs. */
18122 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18123 SET_TEXT_POS (it
.position
, -1, -1);
18124 PRODUCE_GLYPHS (&it
);
18126 /* If this character doesn't fit any more in the line, we have
18127 to remove some glyphs. */
18128 if (it
.current_x
> it
.last_visible_x
)
18130 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18135 set_buffer_temp (old
);
18136 return it
.glyph_row
;
18140 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
18141 glyphs are only inserted for terminal frames since we can't really
18142 win with truncation glyphs when partially visible glyphs are
18143 involved. Which glyphs to insert is determined by
18144 produce_special_glyphs. */
18147 insert_left_trunc_glyphs (struct it
*it
)
18149 struct it truncate_it
;
18150 struct glyph
*from
, *end
, *to
, *toend
;
18152 xassert (!FRAME_WINDOW_P (it
->f
));
18154 /* Get the truncation glyphs. */
18156 truncate_it
.current_x
= 0;
18157 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18158 truncate_it
.glyph_row
= &scratch_glyph_row
;
18159 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18160 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18161 truncate_it
.object
= make_number (0);
18162 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18164 /* Overwrite glyphs from IT with truncation glyphs. */
18165 if (!it
->glyph_row
->reversed_p
)
18167 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18168 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
18169 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18170 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18175 /* There may be padding glyphs left over. Overwrite them too. */
18176 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18178 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18184 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18188 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18189 that back to front. */
18190 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18191 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18192 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18193 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18195 while (from
>= end
&& to
>= toend
)
18197 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18200 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18201 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18202 while (from
>= end
&& to
>= toend
)
18207 /* Need to free some room before prepending additional
18209 int move_by
= from
- end
+ 1;
18210 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18211 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18213 for ( ; g
>= g0
; g
--)
18215 while (from
>= end
)
18217 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18222 /* Compute the hash code for ROW. */
18224 row_hash (struct glyph_row
*row
)
18227 unsigned hashval
= 0;
18229 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18230 for (k
= 0; k
< row
->used
[area
]; ++k
)
18231 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18232 + row
->glyphs
[area
][k
].u
.val
18233 + row
->glyphs
[area
][k
].face_id
18234 + row
->glyphs
[area
][k
].padding_p
18235 + (row
->glyphs
[area
][k
].type
<< 2));
18240 /* Compute the pixel height and width of IT->glyph_row.
18242 Most of the time, ascent and height of a display line will be equal
18243 to the max_ascent and max_height values of the display iterator
18244 structure. This is not the case if
18246 1. We hit ZV without displaying anything. In this case, max_ascent
18247 and max_height will be zero.
18249 2. We have some glyphs that don't contribute to the line height.
18250 (The glyph row flag contributes_to_line_height_p is for future
18251 pixmap extensions).
18253 The first case is easily covered by using default values because in
18254 these cases, the line height does not really matter, except that it
18255 must not be zero. */
18258 compute_line_metrics (struct it
*it
)
18260 struct glyph_row
*row
= it
->glyph_row
;
18262 if (FRAME_WINDOW_P (it
->f
))
18264 int i
, min_y
, max_y
;
18266 /* The line may consist of one space only, that was added to
18267 place the cursor on it. If so, the row's height hasn't been
18269 if (row
->height
== 0)
18271 if (it
->max_ascent
+ it
->max_descent
== 0)
18272 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18273 row
->ascent
= it
->max_ascent
;
18274 row
->height
= it
->max_ascent
+ it
->max_descent
;
18275 row
->phys_ascent
= it
->max_phys_ascent
;
18276 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18277 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18280 /* Compute the width of this line. */
18281 row
->pixel_width
= row
->x
;
18282 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18283 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18285 xassert (row
->pixel_width
>= 0);
18286 xassert (row
->ascent
>= 0 && row
->height
> 0);
18288 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18289 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18291 /* If first line's physical ascent is larger than its logical
18292 ascent, use the physical ascent, and make the row taller.
18293 This makes accented characters fully visible. */
18294 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18295 && row
->phys_ascent
> row
->ascent
)
18297 row
->height
+= row
->phys_ascent
- row
->ascent
;
18298 row
->ascent
= row
->phys_ascent
;
18301 /* Compute how much of the line is visible. */
18302 row
->visible_height
= row
->height
;
18304 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18305 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18307 if (row
->y
< min_y
)
18308 row
->visible_height
-= min_y
- row
->y
;
18309 if (row
->y
+ row
->height
> max_y
)
18310 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18314 row
->pixel_width
= row
->used
[TEXT_AREA
];
18315 if (row
->continued_p
)
18316 row
->pixel_width
-= it
->continuation_pixel_width
;
18317 else if (row
->truncated_on_right_p
)
18318 row
->pixel_width
-= it
->truncation_pixel_width
;
18319 row
->ascent
= row
->phys_ascent
= 0;
18320 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18321 row
->extra_line_spacing
= 0;
18324 /* Compute a hash code for this row. */
18325 row
->hash
= row_hash (row
);
18327 it
->max_ascent
= it
->max_descent
= 0;
18328 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18332 /* Append one space to the glyph row of iterator IT if doing a
18333 window-based redisplay. The space has the same face as
18334 IT->face_id. Value is non-zero if a space was added.
18336 This function is called to make sure that there is always one glyph
18337 at the end of a glyph row that the cursor can be set on under
18338 window-systems. (If there weren't such a glyph we would not know
18339 how wide and tall a box cursor should be displayed).
18341 At the same time this space let's a nicely handle clearing to the
18342 end of the line if the row ends in italic text. */
18345 append_space_for_newline (struct it
*it
, int default_face_p
)
18347 if (FRAME_WINDOW_P (it
->f
))
18349 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18351 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18352 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18354 /* Save some values that must not be changed.
18355 Must save IT->c and IT->len because otherwise
18356 ITERATOR_AT_END_P wouldn't work anymore after
18357 append_space_for_newline has been called. */
18358 enum display_element_type saved_what
= it
->what
;
18359 int saved_c
= it
->c
, saved_len
= it
->len
;
18360 int saved_char_to_display
= it
->char_to_display
;
18361 int saved_x
= it
->current_x
;
18362 int saved_face_id
= it
->face_id
;
18363 struct text_pos saved_pos
;
18364 Lisp_Object saved_object
;
18367 saved_object
= it
->object
;
18368 saved_pos
= it
->position
;
18370 it
->what
= IT_CHARACTER
;
18371 memset (&it
->position
, 0, sizeof it
->position
);
18372 it
->object
= make_number (0);
18373 it
->c
= it
->char_to_display
= ' ';
18376 /* If the default face was remapped, be sure to use the
18377 remapped face for the appended newline. */
18378 if (default_face_p
)
18379 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18380 else if (it
->face_before_selective_p
)
18381 it
->face_id
= it
->saved_face_id
;
18382 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18383 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18385 PRODUCE_GLYPHS (it
);
18387 it
->override_ascent
= -1;
18388 it
->constrain_row_ascent_descent_p
= 0;
18389 it
->current_x
= saved_x
;
18390 it
->object
= saved_object
;
18391 it
->position
= saved_pos
;
18392 it
->what
= saved_what
;
18393 it
->face_id
= saved_face_id
;
18394 it
->len
= saved_len
;
18396 it
->char_to_display
= saved_char_to_display
;
18405 /* Extend the face of the last glyph in the text area of IT->glyph_row
18406 to the end of the display line. Called from display_line. If the
18407 glyph row is empty, add a space glyph to it so that we know the
18408 face to draw. Set the glyph row flag fill_line_p. If the glyph
18409 row is R2L, prepend a stretch glyph to cover the empty space to the
18410 left of the leftmost glyph. */
18413 extend_face_to_end_of_line (struct it
*it
)
18415 struct face
*face
, *default_face
;
18416 struct frame
*f
= it
->f
;
18418 /* If line is already filled, do nothing. Non window-system frames
18419 get a grace of one more ``pixel'' because their characters are
18420 1-``pixel'' wide, so they hit the equality too early. This grace
18421 is needed only for R2L rows that are not continued, to produce
18422 one extra blank where we could display the cursor. */
18423 if (it
->current_x
>= it
->last_visible_x
18424 + (!FRAME_WINDOW_P (f
)
18425 && it
->glyph_row
->reversed_p
18426 && !it
->glyph_row
->continued_p
))
18429 /* The default face, possibly remapped. */
18430 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18432 /* Face extension extends the background and box of IT->face_id
18433 to the end of the line. If the background equals the background
18434 of the frame, we don't have to do anything. */
18435 if (it
->face_before_selective_p
)
18436 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18438 face
= FACE_FROM_ID (f
, it
->face_id
);
18440 if (FRAME_WINDOW_P (f
)
18441 && it
->glyph_row
->displays_text_p
18442 && face
->box
== FACE_NO_BOX
18443 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18445 && !it
->glyph_row
->reversed_p
)
18448 /* Set the glyph row flag indicating that the face of the last glyph
18449 in the text area has to be drawn to the end of the text area. */
18450 it
->glyph_row
->fill_line_p
= 1;
18452 /* If current character of IT is not ASCII, make sure we have the
18453 ASCII face. This will be automatically undone the next time
18454 get_next_display_element returns a multibyte character. Note
18455 that the character will always be single byte in unibyte
18457 if (!ASCII_CHAR_P (it
->c
))
18459 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18462 if (FRAME_WINDOW_P (f
))
18464 /* If the row is empty, add a space with the current face of IT,
18465 so that we know which face to draw. */
18466 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18468 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18469 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18470 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18472 #ifdef HAVE_WINDOW_SYSTEM
18473 if (it
->glyph_row
->reversed_p
)
18475 /* Prepend a stretch glyph to the row, such that the
18476 rightmost glyph will be drawn flushed all the way to the
18477 right margin of the window. The stretch glyph that will
18478 occupy the empty space, if any, to the left of the
18480 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18481 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18482 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18484 int row_width
, stretch_ascent
, stretch_width
;
18485 struct text_pos saved_pos
;
18486 int saved_face_id
, saved_avoid_cursor
;
18488 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18489 row_width
+= g
->pixel_width
;
18490 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18491 if (stretch_width
> 0)
18494 (((it
->ascent
+ it
->descent
)
18495 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18496 saved_pos
= it
->position
;
18497 memset (&it
->position
, 0, sizeof it
->position
);
18498 saved_avoid_cursor
= it
->avoid_cursor_p
;
18499 it
->avoid_cursor_p
= 1;
18500 saved_face_id
= it
->face_id
;
18501 /* The last row's stretch glyph should get the default
18502 face, to avoid painting the rest of the window with
18503 the region face, if the region ends at ZV. */
18504 if (it
->glyph_row
->ends_at_zv_p
)
18505 it
->face_id
= default_face
->id
;
18507 it
->face_id
= face
->id
;
18508 append_stretch_glyph (it
, make_number (0), stretch_width
,
18509 it
->ascent
+ it
->descent
, stretch_ascent
);
18510 it
->position
= saved_pos
;
18511 it
->avoid_cursor_p
= saved_avoid_cursor
;
18512 it
->face_id
= saved_face_id
;
18515 #endif /* HAVE_WINDOW_SYSTEM */
18519 /* Save some values that must not be changed. */
18520 int saved_x
= it
->current_x
;
18521 struct text_pos saved_pos
;
18522 Lisp_Object saved_object
;
18523 enum display_element_type saved_what
= it
->what
;
18524 int saved_face_id
= it
->face_id
;
18526 saved_object
= it
->object
;
18527 saved_pos
= it
->position
;
18529 it
->what
= IT_CHARACTER
;
18530 memset (&it
->position
, 0, sizeof it
->position
);
18531 it
->object
= make_number (0);
18532 it
->c
= it
->char_to_display
= ' ';
18534 /* The last row's blank glyphs should get the default face, to
18535 avoid painting the rest of the window with the region face,
18536 if the region ends at ZV. */
18537 if (it
->glyph_row
->ends_at_zv_p
)
18538 it
->face_id
= default_face
->id
;
18540 it
->face_id
= face
->id
;
18542 PRODUCE_GLYPHS (it
);
18544 while (it
->current_x
<= it
->last_visible_x
)
18545 PRODUCE_GLYPHS (it
);
18547 /* Don't count these blanks really. It would let us insert a left
18548 truncation glyph below and make us set the cursor on them, maybe. */
18549 it
->current_x
= saved_x
;
18550 it
->object
= saved_object
;
18551 it
->position
= saved_pos
;
18552 it
->what
= saved_what
;
18553 it
->face_id
= saved_face_id
;
18558 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18559 trailing whitespace. */
18562 trailing_whitespace_p (ptrdiff_t charpos
)
18564 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18567 while (bytepos
< ZV_BYTE
18568 && (c
= FETCH_CHAR (bytepos
),
18569 c
== ' ' || c
== '\t'))
18572 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18574 if (bytepos
!= PT_BYTE
)
18581 /* Highlight trailing whitespace, if any, in ROW. */
18584 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18586 int used
= row
->used
[TEXT_AREA
];
18590 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18591 struct glyph
*glyph
= start
+ used
- 1;
18593 if (row
->reversed_p
)
18595 /* Right-to-left rows need to be processed in the opposite
18596 direction, so swap the edge pointers. */
18598 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18601 /* Skip over glyphs inserted to display the cursor at the
18602 end of a line, for extending the face of the last glyph
18603 to the end of the line on terminals, and for truncation
18604 and continuation glyphs. */
18605 if (!row
->reversed_p
)
18607 while (glyph
>= start
18608 && glyph
->type
== CHAR_GLYPH
18609 && INTEGERP (glyph
->object
))
18614 while (glyph
<= start
18615 && glyph
->type
== CHAR_GLYPH
18616 && INTEGERP (glyph
->object
))
18620 /* If last glyph is a space or stretch, and it's trailing
18621 whitespace, set the face of all trailing whitespace glyphs in
18622 IT->glyph_row to `trailing-whitespace'. */
18623 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18624 && BUFFERP (glyph
->object
)
18625 && (glyph
->type
== STRETCH_GLYPH
18626 || (glyph
->type
== CHAR_GLYPH
18627 && glyph
->u
.ch
== ' '))
18628 && trailing_whitespace_p (glyph
->charpos
))
18630 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18634 if (!row
->reversed_p
)
18636 while (glyph
>= start
18637 && BUFFERP (glyph
->object
)
18638 && (glyph
->type
== STRETCH_GLYPH
18639 || (glyph
->type
== CHAR_GLYPH
18640 && glyph
->u
.ch
== ' ')))
18641 (glyph
--)->face_id
= face_id
;
18645 while (glyph
<= start
18646 && BUFFERP (glyph
->object
)
18647 && (glyph
->type
== STRETCH_GLYPH
18648 || (glyph
->type
== CHAR_GLYPH
18649 && glyph
->u
.ch
== ' ')))
18650 (glyph
++)->face_id
= face_id
;
18657 /* Value is non-zero if glyph row ROW should be
18658 used to hold the cursor. */
18661 cursor_row_p (struct glyph_row
*row
)
18665 if (PT
== CHARPOS (row
->end
.pos
)
18666 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18668 /* Suppose the row ends on a string.
18669 Unless the row is continued, that means it ends on a newline
18670 in the string. If it's anything other than a display string
18671 (e.g., a before-string from an overlay), we don't want the
18672 cursor there. (This heuristic seems to give the optimal
18673 behavior for the various types of multi-line strings.)
18674 One exception: if the string has `cursor' property on one of
18675 its characters, we _do_ want the cursor there. */
18676 if (CHARPOS (row
->end
.string_pos
) >= 0)
18678 if (row
->continued_p
)
18682 /* Check for `display' property. */
18683 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18684 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18685 struct glyph
*glyph
;
18688 for (glyph
= end
; glyph
>= beg
; --glyph
)
18689 if (STRINGP (glyph
->object
))
18692 = Fget_char_property (make_number (PT
),
18696 && display_prop_string_p (prop
, glyph
->object
));
18697 /* If there's a `cursor' property on one of the
18698 string's characters, this row is a cursor row,
18699 even though this is not a display string. */
18702 Lisp_Object s
= glyph
->object
;
18704 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18706 ptrdiff_t gpos
= glyph
->charpos
;
18708 if (!NILP (Fget_char_property (make_number (gpos
),
18720 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18722 /* If the row ends in middle of a real character,
18723 and the line is continued, we want the cursor here.
18724 That's because CHARPOS (ROW->end.pos) would equal
18725 PT if PT is before the character. */
18726 if (!row
->ends_in_ellipsis_p
)
18727 result
= row
->continued_p
;
18729 /* If the row ends in an ellipsis, then
18730 CHARPOS (ROW->end.pos) will equal point after the
18731 invisible text. We want that position to be displayed
18732 after the ellipsis. */
18735 /* If the row ends at ZV, display the cursor at the end of that
18736 row instead of at the start of the row below. */
18737 else if (row
->ends_at_zv_p
)
18748 /* Push the property PROP so that it will be rendered at the current
18749 position in IT. Return 1 if PROP was successfully pushed, 0
18750 otherwise. Called from handle_line_prefix to handle the
18751 `line-prefix' and `wrap-prefix' properties. */
18754 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18756 struct text_pos pos
=
18757 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18759 xassert (it
->method
== GET_FROM_BUFFER
18760 || it
->method
== GET_FROM_DISPLAY_VECTOR
18761 || it
->method
== GET_FROM_STRING
);
18763 /* We need to save the current buffer/string position, so it will be
18764 restored by pop_it, because iterate_out_of_display_property
18765 depends on that being set correctly, but some situations leave
18766 it->position not yet set when this function is called. */
18767 push_it (it
, &pos
);
18769 if (STRINGP (prop
))
18771 if (SCHARS (prop
) == 0)
18778 it
->string_from_prefix_prop_p
= 1;
18779 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18780 it
->current
.overlay_string_index
= -1;
18781 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18782 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18783 it
->method
= GET_FROM_STRING
;
18784 it
->stop_charpos
= 0;
18786 it
->base_level_stop
= 0;
18788 /* Force paragraph direction to be that of the parent
18790 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18791 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18793 it
->paragraph_embedding
= L2R
;
18795 /* Set up the bidi iterator for this display string. */
18798 it
->bidi_it
.string
.lstring
= it
->string
;
18799 it
->bidi_it
.string
.s
= NULL
;
18800 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18801 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18802 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18803 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18804 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18807 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18809 it
->method
= GET_FROM_STRETCH
;
18812 #ifdef HAVE_WINDOW_SYSTEM
18813 else if (IMAGEP (prop
))
18815 it
->what
= IT_IMAGE
;
18816 it
->image_id
= lookup_image (it
->f
, prop
);
18817 it
->method
= GET_FROM_IMAGE
;
18819 #endif /* HAVE_WINDOW_SYSTEM */
18822 pop_it (it
); /* bogus display property, give up */
18829 /* Return the character-property PROP at the current position in IT. */
18832 get_it_property (struct it
*it
, Lisp_Object prop
)
18834 Lisp_Object position
;
18836 if (STRINGP (it
->object
))
18837 position
= make_number (IT_STRING_CHARPOS (*it
));
18838 else if (BUFFERP (it
->object
))
18839 position
= make_number (IT_CHARPOS (*it
));
18843 return Fget_char_property (position
, prop
, it
->object
);
18846 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18849 handle_line_prefix (struct it
*it
)
18851 Lisp_Object prefix
;
18853 if (it
->continuation_lines_width
> 0)
18855 prefix
= get_it_property (it
, Qwrap_prefix
);
18857 prefix
= Vwrap_prefix
;
18861 prefix
= get_it_property (it
, Qline_prefix
);
18863 prefix
= Vline_prefix
;
18865 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18867 /* If the prefix is wider than the window, and we try to wrap
18868 it, it would acquire its own wrap prefix, and so on till the
18869 iterator stack overflows. So, don't wrap the prefix. */
18870 it
->line_wrap
= TRUNCATE
;
18871 it
->avoid_cursor_p
= 1;
18877 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18878 only for R2L lines from display_line and display_string, when they
18879 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18880 the line/string needs to be continued on the next glyph row. */
18882 unproduce_glyphs (struct it
*it
, int n
)
18884 struct glyph
*glyph
, *end
;
18886 xassert (it
->glyph_row
);
18887 xassert (it
->glyph_row
->reversed_p
);
18888 xassert (it
->area
== TEXT_AREA
);
18889 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18891 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18892 n
= it
->glyph_row
->used
[TEXT_AREA
];
18893 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18894 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18895 for ( ; glyph
< end
; glyph
++)
18896 glyph
[-n
] = *glyph
;
18899 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18900 and ROW->maxpos. */
18902 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18903 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18904 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18906 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18907 lines' rows is implemented for bidi-reordered rows. */
18909 /* ROW->minpos is the value of min_pos, the minimal buffer position
18910 we have in ROW, or ROW->start.pos if that is smaller. */
18911 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18912 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18914 /* We didn't find buffer positions smaller than ROW->start, or
18915 didn't find _any_ valid buffer positions in any of the glyphs,
18916 so we must trust the iterator's computed positions. */
18917 row
->minpos
= row
->start
.pos
;
18920 max_pos
= CHARPOS (it
->current
.pos
);
18921 max_bpos
= BYTEPOS (it
->current
.pos
);
18924 /* Here are the various use-cases for ending the row, and the
18925 corresponding values for ROW->maxpos:
18927 Line ends in a newline from buffer eol_pos + 1
18928 Line is continued from buffer max_pos + 1
18929 Line is truncated on right it->current.pos
18930 Line ends in a newline from string max_pos + 1(*)
18931 (*) + 1 only when line ends in a forward scan
18932 Line is continued from string max_pos
18933 Line is continued from display vector max_pos
18934 Line is entirely from a string min_pos == max_pos
18935 Line is entirely from a display vector min_pos == max_pos
18936 Line that ends at ZV ZV
18938 If you discover other use-cases, please add them here as
18940 if (row
->ends_at_zv_p
)
18941 row
->maxpos
= it
->current
.pos
;
18942 else if (row
->used
[TEXT_AREA
])
18944 int seen_this_string
= 0;
18945 struct glyph_row
*r1
= row
- 1;
18947 /* Did we see the same display string on the previous row? */
18948 if (STRINGP (it
->object
)
18949 /* this is not the first row */
18950 && row
> it
->w
->desired_matrix
->rows
18951 /* previous row is not the header line */
18952 && !r1
->mode_line_p
18953 /* previous row also ends in a newline from a string */
18954 && r1
->ends_in_newline_from_string_p
)
18956 struct glyph
*start
, *end
;
18958 /* Search for the last glyph of the previous row that came
18959 from buffer or string. Depending on whether the row is
18960 L2R or R2L, we need to process it front to back or the
18961 other way round. */
18962 if (!r1
->reversed_p
)
18964 start
= r1
->glyphs
[TEXT_AREA
];
18965 end
= start
+ r1
->used
[TEXT_AREA
];
18966 /* Glyphs inserted by redisplay have an integer (zero)
18967 as their object. */
18969 && INTEGERP ((end
- 1)->object
)
18970 && (end
- 1)->charpos
<= 0)
18974 if (EQ ((end
- 1)->object
, it
->object
))
18975 seen_this_string
= 1;
18978 /* If all the glyphs of the previous row were inserted
18979 by redisplay, it means the previous row was
18980 produced from a single newline, which is only
18981 possible if that newline came from the same string
18982 as the one which produced this ROW. */
18983 seen_this_string
= 1;
18987 end
= r1
->glyphs
[TEXT_AREA
] - 1;
18988 start
= end
+ r1
->used
[TEXT_AREA
];
18990 && INTEGERP ((end
+ 1)->object
)
18991 && (end
+ 1)->charpos
<= 0)
18995 if (EQ ((end
+ 1)->object
, it
->object
))
18996 seen_this_string
= 1;
18999 seen_this_string
= 1;
19002 /* Take note of each display string that covers a newline only
19003 once, the first time we see it. This is for when a display
19004 string includes more than one newline in it. */
19005 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19007 /* If we were scanning the buffer forward when we displayed
19008 the string, we want to account for at least one buffer
19009 position that belongs to this row (position covered by
19010 the display string), so that cursor positioning will
19011 consider this row as a candidate when point is at the end
19012 of the visual line represented by this row. This is not
19013 required when scanning back, because max_pos will already
19014 have a much larger value. */
19015 if (CHARPOS (row
->end
.pos
) > max_pos
)
19016 INC_BOTH (max_pos
, max_bpos
);
19017 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19019 else if (CHARPOS (it
->eol_pos
) > 0)
19020 SET_TEXT_POS (row
->maxpos
,
19021 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19022 else if (row
->continued_p
)
19024 /* If max_pos is different from IT's current position, it
19025 means IT->method does not belong to the display element
19026 at max_pos. However, it also means that the display
19027 element at max_pos was displayed in its entirety on this
19028 line, which is equivalent to saying that the next line
19029 starts at the next buffer position. */
19030 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19031 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19034 INC_BOTH (max_pos
, max_bpos
);
19035 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19038 else if (row
->truncated_on_right_p
)
19039 /* display_line already called reseat_at_next_visible_line_start,
19040 which puts the iterator at the beginning of the next line, in
19041 the logical order. */
19042 row
->maxpos
= it
->current
.pos
;
19043 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19044 /* A line that is entirely from a string/image/stretch... */
19045 row
->maxpos
= row
->minpos
;
19050 row
->maxpos
= it
->current
.pos
;
19053 /* Construct the glyph row IT->glyph_row in the desired matrix of
19054 IT->w from text at the current position of IT. See dispextern.h
19055 for an overview of struct it. Value is non-zero if
19056 IT->glyph_row displays text, as opposed to a line displaying ZV
19060 display_line (struct it
*it
)
19062 struct glyph_row
*row
= it
->glyph_row
;
19063 Lisp_Object overlay_arrow_string
;
19065 void *wrap_data
= NULL
;
19066 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19067 int wrap_row_used
= -1;
19068 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19069 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19070 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19071 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19072 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19074 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19075 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19077 /* We always start displaying at hpos zero even if hscrolled. */
19078 xassert (it
->hpos
== 0 && it
->current_x
== 0);
19080 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19081 >= it
->w
->desired_matrix
->nrows
)
19083 it
->w
->nrows_scale_factor
++;
19084 fonts_changed_p
= 1;
19088 /* Is IT->w showing the region? */
19089 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
19091 /* Clear the result glyph row and enable it. */
19092 prepare_desired_row (row
);
19094 row
->y
= it
->current_y
;
19095 row
->start
= it
->start
;
19096 row
->continuation_lines_width
= it
->continuation_lines_width
;
19097 row
->displays_text_p
= 1;
19098 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19099 it
->starts_in_middle_of_char_p
= 0;
19101 /* Arrange the overlays nicely for our purposes. Usually, we call
19102 display_line on only one line at a time, in which case this
19103 can't really hurt too much, or we call it on lines which appear
19104 one after another in the buffer, in which case all calls to
19105 recenter_overlay_lists but the first will be pretty cheap. */
19106 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19108 /* Move over display elements that are not visible because we are
19109 hscrolled. This may stop at an x-position < IT->first_visible_x
19110 if the first glyph is partially visible or if we hit a line end. */
19111 if (it
->current_x
< it
->first_visible_x
)
19113 this_line_min_pos
= row
->start
.pos
;
19114 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19115 MOVE_TO_POS
| MOVE_TO_X
);
19116 /* Record the smallest positions seen while we moved over
19117 display elements that are not visible. This is needed by
19118 redisplay_internal for optimizing the case where the cursor
19119 stays inside the same line. The rest of this function only
19120 considers positions that are actually displayed, so
19121 RECORD_MAX_MIN_POS will not otherwise record positions that
19122 are hscrolled to the left of the left edge of the window. */
19123 min_pos
= CHARPOS (this_line_min_pos
);
19124 min_bpos
= BYTEPOS (this_line_min_pos
);
19128 /* We only do this when not calling `move_it_in_display_line_to'
19129 above, because move_it_in_display_line_to calls
19130 handle_line_prefix itself. */
19131 handle_line_prefix (it
);
19134 /* Get the initial row height. This is either the height of the
19135 text hscrolled, if there is any, or zero. */
19136 row
->ascent
= it
->max_ascent
;
19137 row
->height
= it
->max_ascent
+ it
->max_descent
;
19138 row
->phys_ascent
= it
->max_phys_ascent
;
19139 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19140 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19142 /* Utility macro to record max and min buffer positions seen until now. */
19143 #define RECORD_MAX_MIN_POS(IT) \
19146 int composition_p = !STRINGP ((IT)->string) \
19147 && ((IT)->what == IT_COMPOSITION); \
19148 ptrdiff_t current_pos = \
19149 composition_p ? (IT)->cmp_it.charpos \
19150 : IT_CHARPOS (*(IT)); \
19151 ptrdiff_t current_bpos = \
19152 composition_p ? CHAR_TO_BYTE (current_pos) \
19153 : IT_BYTEPOS (*(IT)); \
19154 if (current_pos < min_pos) \
19156 min_pos = current_pos; \
19157 min_bpos = current_bpos; \
19159 if (IT_CHARPOS (*it) > max_pos) \
19161 max_pos = IT_CHARPOS (*it); \
19162 max_bpos = IT_BYTEPOS (*it); \
19167 /* Loop generating characters. The loop is left with IT on the next
19168 character to display. */
19171 int n_glyphs_before
, hpos_before
, x_before
;
19173 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19175 /* Retrieve the next thing to display. Value is zero if end of
19177 if (!get_next_display_element (it
))
19179 /* Maybe add a space at the end of this line that is used to
19180 display the cursor there under X. Set the charpos of the
19181 first glyph of blank lines not corresponding to any text
19183 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19184 row
->exact_window_width_line_p
= 1;
19185 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19186 || row
->used
[TEXT_AREA
] == 0)
19188 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19189 row
->displays_text_p
= 0;
19191 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19192 && (!MINI_WINDOW_P (it
->w
)
19193 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19194 row
->indicate_empty_line_p
= 1;
19197 it
->continuation_lines_width
= 0;
19198 row
->ends_at_zv_p
= 1;
19199 /* A row that displays right-to-left text must always have
19200 its last face extended all the way to the end of line,
19201 even if this row ends in ZV, because we still write to
19202 the screen left to right. We also need to extend the
19203 last face if the default face is remapped to some
19204 different face, otherwise the functions that clear
19205 portions of the screen will clear with the default face's
19206 background color. */
19207 if (row
->reversed_p
19208 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19209 extend_face_to_end_of_line (it
);
19213 /* Now, get the metrics of what we want to display. This also
19214 generates glyphs in `row' (which is IT->glyph_row). */
19215 n_glyphs_before
= row
->used
[TEXT_AREA
];
19218 /* Remember the line height so far in case the next element doesn't
19219 fit on the line. */
19220 if (it
->line_wrap
!= TRUNCATE
)
19222 ascent
= it
->max_ascent
;
19223 descent
= it
->max_descent
;
19224 phys_ascent
= it
->max_phys_ascent
;
19225 phys_descent
= it
->max_phys_descent
;
19227 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19229 if (IT_DISPLAYING_WHITESPACE (it
))
19233 SAVE_IT (wrap_it
, *it
, wrap_data
);
19235 wrap_row_used
= row
->used
[TEXT_AREA
];
19236 wrap_row_ascent
= row
->ascent
;
19237 wrap_row_height
= row
->height
;
19238 wrap_row_phys_ascent
= row
->phys_ascent
;
19239 wrap_row_phys_height
= row
->phys_height
;
19240 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19241 wrap_row_min_pos
= min_pos
;
19242 wrap_row_min_bpos
= min_bpos
;
19243 wrap_row_max_pos
= max_pos
;
19244 wrap_row_max_bpos
= max_bpos
;
19250 PRODUCE_GLYPHS (it
);
19252 /* If this display element was in marginal areas, continue with
19254 if (it
->area
!= TEXT_AREA
)
19256 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19257 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19258 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19259 row
->phys_height
= max (row
->phys_height
,
19260 it
->max_phys_ascent
+ it
->max_phys_descent
);
19261 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19262 it
->max_extra_line_spacing
);
19263 set_iterator_to_next (it
, 1);
19267 /* Does the display element fit on the line? If we truncate
19268 lines, we should draw past the right edge of the window. If
19269 we don't truncate, we want to stop so that we can display the
19270 continuation glyph before the right margin. If lines are
19271 continued, there are two possible strategies for characters
19272 resulting in more than 1 glyph (e.g. tabs): Display as many
19273 glyphs as possible in this line and leave the rest for the
19274 continuation line, or display the whole element in the next
19275 line. Original redisplay did the former, so we do it also. */
19276 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19277 hpos_before
= it
->hpos
;
19280 if (/* Not a newline. */
19282 /* Glyphs produced fit entirely in the line. */
19283 && it
->current_x
< it
->last_visible_x
)
19285 it
->hpos
+= nglyphs
;
19286 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19287 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19288 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19289 row
->phys_height
= max (row
->phys_height
,
19290 it
->max_phys_ascent
+ it
->max_phys_descent
);
19291 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19292 it
->max_extra_line_spacing
);
19293 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19294 row
->x
= x
- it
->first_visible_x
;
19295 /* Record the maximum and minimum buffer positions seen so
19296 far in glyphs that will be displayed by this row. */
19298 RECORD_MAX_MIN_POS (it
);
19303 struct glyph
*glyph
;
19305 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19307 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19308 new_x
= x
+ glyph
->pixel_width
;
19310 if (/* Lines are continued. */
19311 it
->line_wrap
!= TRUNCATE
19312 && (/* Glyph doesn't fit on the line. */
19313 new_x
> it
->last_visible_x
19314 /* Or it fits exactly on a window system frame. */
19315 || (new_x
== it
->last_visible_x
19316 && FRAME_WINDOW_P (it
->f
))))
19318 /* End of a continued line. */
19321 || (new_x
== it
->last_visible_x
19322 && FRAME_WINDOW_P (it
->f
)))
19324 /* Current glyph is the only one on the line or
19325 fits exactly on the line. We must continue
19326 the line because we can't draw the cursor
19327 after the glyph. */
19328 row
->continued_p
= 1;
19329 it
->current_x
= new_x
;
19330 it
->continuation_lines_width
+= new_x
;
19332 if (i
== nglyphs
- 1)
19334 /* If line-wrap is on, check if a previous
19335 wrap point was found. */
19336 if (wrap_row_used
> 0
19337 /* Even if there is a previous wrap
19338 point, continue the line here as
19339 usual, if (i) the previous character
19340 was a space or tab AND (ii) the
19341 current character is not. */
19343 || IT_DISPLAYING_WHITESPACE (it
)))
19346 /* Record the maximum and minimum buffer
19347 positions seen so far in glyphs that will be
19348 displayed by this row. */
19350 RECORD_MAX_MIN_POS (it
);
19351 set_iterator_to_next (it
, 1);
19352 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19354 if (!get_next_display_element (it
))
19356 row
->exact_window_width_line_p
= 1;
19357 it
->continuation_lines_width
= 0;
19358 row
->continued_p
= 0;
19359 row
->ends_at_zv_p
= 1;
19361 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19363 row
->continued_p
= 0;
19364 row
->exact_window_width_line_p
= 1;
19368 else if (it
->bidi_p
)
19369 RECORD_MAX_MIN_POS (it
);
19371 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19372 && !FRAME_WINDOW_P (it
->f
))
19374 /* A padding glyph that doesn't fit on this line.
19375 This means the whole character doesn't fit
19377 if (row
->reversed_p
)
19378 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19379 - n_glyphs_before
);
19380 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19382 /* Fill the rest of the row with continuation
19383 glyphs like in 20.x. */
19384 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19385 < row
->glyphs
[1 + TEXT_AREA
])
19386 produce_special_glyphs (it
, IT_CONTINUATION
);
19388 row
->continued_p
= 1;
19389 it
->current_x
= x_before
;
19390 it
->continuation_lines_width
+= x_before
;
19392 /* Restore the height to what it was before the
19393 element not fitting on the line. */
19394 it
->max_ascent
= ascent
;
19395 it
->max_descent
= descent
;
19396 it
->max_phys_ascent
= phys_ascent
;
19397 it
->max_phys_descent
= phys_descent
;
19399 else if (wrap_row_used
> 0)
19402 if (row
->reversed_p
)
19403 unproduce_glyphs (it
,
19404 row
->used
[TEXT_AREA
] - wrap_row_used
);
19405 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19406 it
->continuation_lines_width
+= wrap_x
;
19407 row
->used
[TEXT_AREA
] = wrap_row_used
;
19408 row
->ascent
= wrap_row_ascent
;
19409 row
->height
= wrap_row_height
;
19410 row
->phys_ascent
= wrap_row_phys_ascent
;
19411 row
->phys_height
= wrap_row_phys_height
;
19412 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19413 min_pos
= wrap_row_min_pos
;
19414 min_bpos
= wrap_row_min_bpos
;
19415 max_pos
= wrap_row_max_pos
;
19416 max_bpos
= wrap_row_max_bpos
;
19417 row
->continued_p
= 1;
19418 row
->ends_at_zv_p
= 0;
19419 row
->exact_window_width_line_p
= 0;
19420 it
->continuation_lines_width
+= x
;
19422 /* Make sure that a non-default face is extended
19423 up to the right margin of the window. */
19424 extend_face_to_end_of_line (it
);
19426 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19428 /* A TAB that extends past the right edge of the
19429 window. This produces a single glyph on
19430 window system frames. We leave the glyph in
19431 this row and let it fill the row, but don't
19432 consume the TAB. */
19433 it
->continuation_lines_width
+= it
->last_visible_x
;
19434 row
->ends_in_middle_of_char_p
= 1;
19435 row
->continued_p
= 1;
19436 glyph
->pixel_width
= it
->last_visible_x
- x
;
19437 it
->starts_in_middle_of_char_p
= 1;
19441 /* Something other than a TAB that draws past
19442 the right edge of the window. Restore
19443 positions to values before the element. */
19444 if (row
->reversed_p
)
19445 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19446 - (n_glyphs_before
+ i
));
19447 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19449 /* Display continuation glyphs. */
19450 if (!FRAME_WINDOW_P (it
->f
))
19451 produce_special_glyphs (it
, IT_CONTINUATION
);
19452 row
->continued_p
= 1;
19454 it
->current_x
= x_before
;
19455 it
->continuation_lines_width
+= x
;
19456 extend_face_to_end_of_line (it
);
19458 if (nglyphs
> 1 && i
> 0)
19460 row
->ends_in_middle_of_char_p
= 1;
19461 it
->starts_in_middle_of_char_p
= 1;
19464 /* Restore the height to what it was before the
19465 element not fitting on the line. */
19466 it
->max_ascent
= ascent
;
19467 it
->max_descent
= descent
;
19468 it
->max_phys_ascent
= phys_ascent
;
19469 it
->max_phys_descent
= phys_descent
;
19474 else if (new_x
> it
->first_visible_x
)
19476 /* Increment number of glyphs actually displayed. */
19479 /* Record the maximum and minimum buffer positions
19480 seen so far in glyphs that will be displayed by
19483 RECORD_MAX_MIN_POS (it
);
19485 if (x
< it
->first_visible_x
)
19486 /* Glyph is partially visible, i.e. row starts at
19487 negative X position. */
19488 row
->x
= x
- it
->first_visible_x
;
19492 /* Glyph is completely off the left margin of the
19493 window. This should not happen because of the
19494 move_it_in_display_line at the start of this
19495 function, unless the text display area of the
19496 window is empty. */
19497 xassert (it
->first_visible_x
<= it
->last_visible_x
);
19500 /* Even if this display element produced no glyphs at all,
19501 we want to record its position. */
19502 if (it
->bidi_p
&& nglyphs
== 0)
19503 RECORD_MAX_MIN_POS (it
);
19505 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19506 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19507 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19508 row
->phys_height
= max (row
->phys_height
,
19509 it
->max_phys_ascent
+ it
->max_phys_descent
);
19510 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19511 it
->max_extra_line_spacing
);
19513 /* End of this display line if row is continued. */
19514 if (row
->continued_p
|| row
->ends_at_zv_p
)
19519 /* Is this a line end? If yes, we're also done, after making
19520 sure that a non-default face is extended up to the right
19521 margin of the window. */
19522 if (ITERATOR_AT_END_OF_LINE_P (it
))
19524 int used_before
= row
->used
[TEXT_AREA
];
19526 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19528 /* Add a space at the end of the line that is used to
19529 display the cursor there. */
19530 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19531 append_space_for_newline (it
, 0);
19533 /* Extend the face to the end of the line. */
19534 extend_face_to_end_of_line (it
);
19536 /* Make sure we have the position. */
19537 if (used_before
== 0)
19538 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19540 /* Record the position of the newline, for use in
19542 it
->eol_pos
= it
->current
.pos
;
19544 /* Consume the line end. This skips over invisible lines. */
19545 set_iterator_to_next (it
, 1);
19546 it
->continuation_lines_width
= 0;
19550 /* Proceed with next display element. Note that this skips
19551 over lines invisible because of selective display. */
19552 set_iterator_to_next (it
, 1);
19554 /* If we truncate lines, we are done when the last displayed
19555 glyphs reach past the right margin of the window. */
19556 if (it
->line_wrap
== TRUNCATE
19557 && (FRAME_WINDOW_P (it
->f
)
19558 ? (it
->current_x
>= it
->last_visible_x
)
19559 : (it
->current_x
> it
->last_visible_x
)))
19561 /* Maybe add truncation glyphs. */
19562 if (!FRAME_WINDOW_P (it
->f
))
19566 if (!row
->reversed_p
)
19568 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19569 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19574 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19575 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19577 /* Remove any padding glyphs at the front of ROW, to
19578 make room for the truncation glyphs we will be
19579 adding below. The loop below always inserts at
19580 least one truncation glyph, so also remove the
19581 last glyph added to ROW. */
19582 unproduce_glyphs (it
, i
+ 1);
19583 /* Adjust i for the loop below. */
19584 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19587 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19589 row
->used
[TEXT_AREA
] = i
;
19590 produce_special_glyphs (it
, IT_TRUNCATION
);
19593 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19595 /* Don't truncate if we can overflow newline into fringe. */
19596 if (!get_next_display_element (it
))
19598 it
->continuation_lines_width
= 0;
19599 row
->ends_at_zv_p
= 1;
19600 row
->exact_window_width_line_p
= 1;
19603 if (ITERATOR_AT_END_OF_LINE_P (it
))
19605 row
->exact_window_width_line_p
= 1;
19606 goto at_end_of_line
;
19610 row
->truncated_on_right_p
= 1;
19611 it
->continuation_lines_width
= 0;
19612 reseat_at_next_visible_line_start (it
, 0);
19613 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19614 it
->hpos
= hpos_before
;
19615 it
->current_x
= x_before
;
19621 bidi_unshelve_cache (wrap_data
, 1);
19623 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19624 at the left window margin. */
19625 if (it
->first_visible_x
19626 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19628 if (!FRAME_WINDOW_P (it
->f
))
19629 insert_left_trunc_glyphs (it
);
19630 row
->truncated_on_left_p
= 1;
19633 /* Remember the position at which this line ends.
19635 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19636 cannot be before the call to find_row_edges below, since that is
19637 where these positions are determined. */
19638 row
->end
= it
->current
;
19641 row
->minpos
= row
->start
.pos
;
19642 row
->maxpos
= row
->end
.pos
;
19646 /* ROW->minpos and ROW->maxpos must be the smallest and
19647 `1 + the largest' buffer positions in ROW. But if ROW was
19648 bidi-reordered, these two positions can be anywhere in the
19649 row, so we must determine them now. */
19650 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19653 /* If the start of this line is the overlay arrow-position, then
19654 mark this glyph row as the one containing the overlay arrow.
19655 This is clearly a mess with variable size fonts. It would be
19656 better to let it be displayed like cursors under X. */
19657 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19658 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19659 !NILP (overlay_arrow_string
)))
19661 /* Overlay arrow in window redisplay is a fringe bitmap. */
19662 if (STRINGP (overlay_arrow_string
))
19664 struct glyph_row
*arrow_row
19665 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19666 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19667 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19668 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19669 struct glyph
*p2
, *end
;
19671 /* Copy the arrow glyphs. */
19672 while (glyph
< arrow_end
)
19675 /* Throw away padding glyphs. */
19677 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19678 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19684 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19689 xassert (INTEGERP (overlay_arrow_string
));
19690 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19692 overlay_arrow_seen
= 1;
19695 /* Highlight trailing whitespace. */
19696 if (!NILP (Vshow_trailing_whitespace
))
19697 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19699 /* Compute pixel dimensions of this line. */
19700 compute_line_metrics (it
);
19702 /* Implementation note: No changes in the glyphs of ROW or in their
19703 faces can be done past this point, because compute_line_metrics
19704 computes ROW's hash value and stores it within the glyph_row
19707 /* Record whether this row ends inside an ellipsis. */
19708 row
->ends_in_ellipsis_p
19709 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19710 && it
->ellipsis_p
);
19712 /* Save fringe bitmaps in this row. */
19713 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19714 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19715 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19716 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19718 it
->left_user_fringe_bitmap
= 0;
19719 it
->left_user_fringe_face_id
= 0;
19720 it
->right_user_fringe_bitmap
= 0;
19721 it
->right_user_fringe_face_id
= 0;
19723 /* Maybe set the cursor. */
19724 cvpos
= it
->w
->cursor
.vpos
;
19726 /* In bidi-reordered rows, keep checking for proper cursor
19727 position even if one has been found already, because buffer
19728 positions in such rows change non-linearly with ROW->VPOS,
19729 when a line is continued. One exception: when we are at ZV,
19730 display cursor on the first suitable glyph row, since all
19731 the empty rows after that also have their position set to ZV. */
19732 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19733 lines' rows is implemented for bidi-reordered rows. */
19735 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19736 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19737 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19738 && cursor_row_p (row
))
19739 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19741 /* Prepare for the next line. This line starts horizontally at (X
19742 HPOS) = (0 0). Vertical positions are incremented. As a
19743 convenience for the caller, IT->glyph_row is set to the next
19745 it
->current_x
= it
->hpos
= 0;
19746 it
->current_y
+= row
->height
;
19747 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19750 /* The next row should by default use the same value of the
19751 reversed_p flag as this one. set_iterator_to_next decides when
19752 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19753 the flag accordingly. */
19754 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19755 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19756 it
->start
= row
->end
;
19757 return row
->displays_text_p
;
19759 #undef RECORD_MAX_MIN_POS
19762 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19763 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19764 doc
: /* Return paragraph direction at point in BUFFER.
19765 Value is either `left-to-right' or `right-to-left'.
19766 If BUFFER is omitted or nil, it defaults to the current buffer.
19768 Paragraph direction determines how the text in the paragraph is displayed.
19769 In left-to-right paragraphs, text begins at the left margin of the window
19770 and the reading direction is generally left to right. In right-to-left
19771 paragraphs, text begins at the right margin and is read from right to left.
19773 See also `bidi-paragraph-direction'. */)
19774 (Lisp_Object buffer
)
19776 struct buffer
*buf
= current_buffer
;
19777 struct buffer
*old
= buf
;
19779 if (! NILP (buffer
))
19781 CHECK_BUFFER (buffer
);
19782 buf
= XBUFFER (buffer
);
19785 if (NILP (BVAR (buf
, bidi_display_reordering
))
19786 || NILP (BVAR (buf
, enable_multibyte_characters
))
19787 /* When we are loading loadup.el, the character property tables
19788 needed for bidi iteration are not yet available. */
19789 || !NILP (Vpurify_flag
))
19790 return Qleft_to_right
;
19791 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19792 return BVAR (buf
, bidi_paragraph_direction
);
19795 /* Determine the direction from buffer text. We could try to
19796 use current_matrix if it is up to date, but this seems fast
19797 enough as it is. */
19798 struct bidi_it itb
;
19799 ptrdiff_t pos
= BUF_PT (buf
);
19800 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19802 void *itb_data
= bidi_shelve_cache ();
19804 set_buffer_temp (buf
);
19805 /* bidi_paragraph_init finds the base direction of the paragraph
19806 by searching forward from paragraph start. We need the base
19807 direction of the current or _previous_ paragraph, so we need
19808 to make sure we are within that paragraph. To that end, find
19809 the previous non-empty line. */
19810 if (pos
>= ZV
&& pos
> BEGV
)
19813 bytepos
= CHAR_TO_BYTE (pos
);
19815 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19816 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19818 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19819 || c
== ' ' || c
== '\t' || c
== '\f')
19821 if (bytepos
<= BEGV_BYTE
)
19826 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19829 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19830 itb
.paragraph_dir
= NEUTRAL_DIR
;
19831 itb
.string
.s
= NULL
;
19832 itb
.string
.lstring
= Qnil
;
19833 itb
.string
.bufpos
= 0;
19834 itb
.string
.unibyte
= 0;
19835 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19836 bidi_unshelve_cache (itb_data
, 0);
19837 set_buffer_temp (old
);
19838 switch (itb
.paragraph_dir
)
19841 return Qleft_to_right
;
19844 return Qright_to_left
;
19854 /***********************************************************************
19856 ***********************************************************************/
19858 /* Redisplay the menu bar in the frame for window W.
19860 The menu bar of X frames that don't have X toolkit support is
19861 displayed in a special window W->frame->menu_bar_window.
19863 The menu bar of terminal frames is treated specially as far as
19864 glyph matrices are concerned. Menu bar lines are not part of
19865 windows, so the update is done directly on the frame matrix rows
19866 for the menu bar. */
19869 display_menu_bar (struct window
*w
)
19871 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19876 /* Don't do all this for graphical frames. */
19878 if (FRAME_W32_P (f
))
19881 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19887 if (FRAME_NS_P (f
))
19889 #endif /* HAVE_NS */
19891 #ifdef USE_X_TOOLKIT
19892 xassert (!FRAME_WINDOW_P (f
));
19893 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19894 it
.first_visible_x
= 0;
19895 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19896 #else /* not USE_X_TOOLKIT */
19897 if (FRAME_WINDOW_P (f
))
19899 /* Menu bar lines are displayed in the desired matrix of the
19900 dummy window menu_bar_window. */
19901 struct window
*menu_w
;
19902 xassert (WINDOWP (f
->menu_bar_window
));
19903 menu_w
= XWINDOW (f
->menu_bar_window
);
19904 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19906 it
.first_visible_x
= 0;
19907 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19911 /* This is a TTY frame, i.e. character hpos/vpos are used as
19913 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19915 it
.first_visible_x
= 0;
19916 it
.last_visible_x
= FRAME_COLS (f
);
19918 #endif /* not USE_X_TOOLKIT */
19920 /* FIXME: This should be controlled by a user option. See the
19921 comments in redisplay_tool_bar and display_mode_line about
19923 it
.paragraph_embedding
= L2R
;
19925 if (! mode_line_inverse_video
)
19926 /* Force the menu-bar to be displayed in the default face. */
19927 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19929 /* Clear all rows of the menu bar. */
19930 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
19932 struct glyph_row
*row
= it
.glyph_row
+ i
;
19933 clear_glyph_row (row
);
19934 row
->enabled_p
= 1;
19935 row
->full_width_p
= 1;
19938 /* Display all items of the menu bar. */
19939 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
19940 for (i
= 0; i
< ASIZE (items
); i
+= 4)
19942 Lisp_Object string
;
19944 /* Stop at nil string. */
19945 string
= AREF (items
, i
+ 1);
19949 /* Remember where item was displayed. */
19950 ASET (items
, i
+ 3, make_number (it
.hpos
));
19952 /* Display the item, pad with one space. */
19953 if (it
.current_x
< it
.last_visible_x
)
19954 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
19955 SCHARS (string
) + 1, 0, 0, -1);
19958 /* Fill out the line with spaces. */
19959 if (it
.current_x
< it
.last_visible_x
)
19960 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
19962 /* Compute the total height of the lines. */
19963 compute_line_metrics (&it
);
19968 /***********************************************************************
19970 ***********************************************************************/
19972 /* Redisplay mode lines in the window tree whose root is WINDOW. If
19973 FORCE is non-zero, redisplay mode lines unconditionally.
19974 Otherwise, redisplay only mode lines that are garbaged. Value is
19975 the number of windows whose mode lines were redisplayed. */
19978 redisplay_mode_lines (Lisp_Object window
, int force
)
19982 while (!NILP (window
))
19984 struct window
*w
= XWINDOW (window
);
19986 if (WINDOWP (w
->hchild
))
19987 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
19988 else if (WINDOWP (w
->vchild
))
19989 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
19991 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
19992 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
19994 struct text_pos lpoint
;
19995 struct buffer
*old
= current_buffer
;
19997 /* Set the window's buffer for the mode line display. */
19998 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
19999 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20001 /* Point refers normally to the selected window. For any
20002 other window, set up appropriate value. */
20003 if (!EQ (window
, selected_window
))
20005 struct text_pos pt
;
20007 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20008 if (CHARPOS (pt
) < BEGV
)
20009 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20010 else if (CHARPOS (pt
) > (ZV
- 1))
20011 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20013 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20016 /* Display mode lines. */
20017 clear_glyph_matrix (w
->desired_matrix
);
20018 if (display_mode_lines (w
))
20021 w
->must_be_updated_p
= 1;
20024 /* Restore old settings. */
20025 set_buffer_internal_1 (old
);
20026 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20036 /* Display the mode and/or header line of window W. Value is the
20037 sum number of mode lines and header lines displayed. */
20040 display_mode_lines (struct window
*w
)
20042 Lisp_Object old_selected_window
, old_selected_frame
;
20045 old_selected_frame
= selected_frame
;
20046 selected_frame
= w
->frame
;
20047 old_selected_window
= selected_window
;
20048 XSETWINDOW (selected_window
, w
);
20050 /* These will be set while the mode line specs are processed. */
20051 line_number_displayed
= 0;
20052 w
->column_number_displayed
= Qnil
;
20054 if (WINDOW_WANTS_MODELINE_P (w
))
20056 struct window
*sel_w
= XWINDOW (old_selected_window
);
20058 /* Select mode line face based on the real selected window. */
20059 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20060 BVAR (current_buffer
, mode_line_format
));
20064 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20066 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20067 BVAR (current_buffer
, header_line_format
));
20071 selected_frame
= old_selected_frame
;
20072 selected_window
= old_selected_window
;
20077 /* Display mode or header line of window W. FACE_ID specifies which
20078 line to display; it is either MODE_LINE_FACE_ID or
20079 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20080 display. Value is the pixel height of the mode/header line
20084 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20088 ptrdiff_t count
= SPECPDL_INDEX ();
20090 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20091 /* Don't extend on a previously drawn mode-line.
20092 This may happen if called from pos_visible_p. */
20093 it
.glyph_row
->enabled_p
= 0;
20094 prepare_desired_row (it
.glyph_row
);
20096 it
.glyph_row
->mode_line_p
= 1;
20098 if (! mode_line_inverse_video
)
20099 /* Force the mode-line to be displayed in the default face. */
20100 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20102 /* FIXME: This should be controlled by a user option. But
20103 supporting such an option is not trivial, since the mode line is
20104 made up of many separate strings. */
20105 it
.paragraph_embedding
= L2R
;
20107 record_unwind_protect (unwind_format_mode_line
,
20108 format_mode_line_unwind_data (NULL
, Qnil
, 0));
20110 mode_line_target
= MODE_LINE_DISPLAY
;
20112 /* Temporarily make frame's keyboard the current kboard so that
20113 kboard-local variables in the mode_line_format will get the right
20115 push_kboard (FRAME_KBOARD (it
.f
));
20116 record_unwind_save_match_data ();
20117 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20120 unbind_to (count
, Qnil
);
20122 /* Fill up with spaces. */
20123 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20125 compute_line_metrics (&it
);
20126 it
.glyph_row
->full_width_p
= 1;
20127 it
.glyph_row
->continued_p
= 0;
20128 it
.glyph_row
->truncated_on_left_p
= 0;
20129 it
.glyph_row
->truncated_on_right_p
= 0;
20131 /* Make a 3D mode-line have a shadow at its right end. */
20132 face
= FACE_FROM_ID (it
.f
, face_id
);
20133 extend_face_to_end_of_line (&it
);
20134 if (face
->box
!= FACE_NO_BOX
)
20136 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20137 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20138 last
->right_box_line_p
= 1;
20141 return it
.glyph_row
->height
;
20144 /* Move element ELT in LIST to the front of LIST.
20145 Return the updated list. */
20148 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20150 register Lisp_Object tail
, prev
;
20151 register Lisp_Object tem
;
20155 while (CONSP (tail
))
20161 /* Splice out the link TAIL. */
20163 list
= XCDR (tail
);
20165 Fsetcdr (prev
, XCDR (tail
));
20167 /* Now make it the first. */
20168 Fsetcdr (tail
, list
);
20173 tail
= XCDR (tail
);
20177 /* Not found--return unchanged LIST. */
20181 /* Contribute ELT to the mode line for window IT->w. How it
20182 translates into text depends on its data type.
20184 IT describes the display environment in which we display, as usual.
20186 DEPTH is the depth in recursion. It is used to prevent
20187 infinite recursion here.
20189 FIELD_WIDTH is the number of characters the display of ELT should
20190 occupy in the mode line, and PRECISION is the maximum number of
20191 characters to display from ELT's representation. See
20192 display_string for details.
20194 Returns the hpos of the end of the text generated by ELT.
20196 PROPS is a property list to add to any string we encounter.
20198 If RISKY is nonzero, remove (disregard) any properties in any string
20199 we encounter, and ignore :eval and :propertize.
20201 The global variable `mode_line_target' determines whether the
20202 output is passed to `store_mode_line_noprop',
20203 `store_mode_line_string', or `display_string'. */
20206 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20207 Lisp_Object elt
, Lisp_Object props
, int risky
)
20209 int n
= 0, field
, prec
;
20214 elt
= build_string ("*too-deep*");
20218 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
20222 /* A string: output it and check for %-constructs within it. */
20224 ptrdiff_t offset
= 0;
20226 if (SCHARS (elt
) > 0
20227 && (!NILP (props
) || risky
))
20229 Lisp_Object oprops
, aelt
;
20230 oprops
= Ftext_properties_at (make_number (0), elt
);
20232 /* If the starting string's properties are not what
20233 we want, translate the string. Also, if the string
20234 is risky, do that anyway. */
20236 if (NILP (Fequal (props
, oprops
)) || risky
)
20238 /* If the starting string has properties,
20239 merge the specified ones onto the existing ones. */
20240 if (! NILP (oprops
) && !risky
)
20244 oprops
= Fcopy_sequence (oprops
);
20246 while (CONSP (tem
))
20248 oprops
= Fplist_put (oprops
, XCAR (tem
),
20249 XCAR (XCDR (tem
)));
20250 tem
= XCDR (XCDR (tem
));
20255 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20256 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20258 /* AELT is what we want. Move it to the front
20259 without consing. */
20261 mode_line_proptrans_alist
20262 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20268 /* If AELT has the wrong props, it is useless.
20269 so get rid of it. */
20271 mode_line_proptrans_alist
20272 = Fdelq (aelt
, mode_line_proptrans_alist
);
20274 elt
= Fcopy_sequence (elt
);
20275 Fset_text_properties (make_number (0), Flength (elt
),
20277 /* Add this item to mode_line_proptrans_alist. */
20278 mode_line_proptrans_alist
20279 = Fcons (Fcons (elt
, props
),
20280 mode_line_proptrans_alist
);
20281 /* Truncate mode_line_proptrans_alist
20282 to at most 50 elements. */
20283 tem
= Fnthcdr (make_number (50),
20284 mode_line_proptrans_alist
);
20286 XSETCDR (tem
, Qnil
);
20295 prec
= precision
- n
;
20296 switch (mode_line_target
)
20298 case MODE_LINE_NOPROP
:
20299 case MODE_LINE_TITLE
:
20300 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20302 case MODE_LINE_STRING
:
20303 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20305 case MODE_LINE_DISPLAY
:
20306 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20307 0, prec
, 0, STRING_MULTIBYTE (elt
));
20314 /* Handle the non-literal case. */
20316 while ((precision
<= 0 || n
< precision
)
20317 && SREF (elt
, offset
) != 0
20318 && (mode_line_target
!= MODE_LINE_DISPLAY
20319 || it
->current_x
< it
->last_visible_x
))
20321 ptrdiff_t last_offset
= offset
;
20323 /* Advance to end of string or next format specifier. */
20324 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20327 if (offset
- 1 != last_offset
)
20329 ptrdiff_t nchars
, nbytes
;
20331 /* Output to end of string or up to '%'. Field width
20332 is length of string. Don't output more than
20333 PRECISION allows us. */
20336 prec
= c_string_width (SDATA (elt
) + last_offset
,
20337 offset
- last_offset
, precision
- n
,
20340 switch (mode_line_target
)
20342 case MODE_LINE_NOPROP
:
20343 case MODE_LINE_TITLE
:
20344 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20346 case MODE_LINE_STRING
:
20348 ptrdiff_t bytepos
= last_offset
;
20349 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20350 ptrdiff_t endpos
= (precision
<= 0
20351 ? string_byte_to_char (elt
, offset
)
20352 : charpos
+ nchars
);
20354 n
+= store_mode_line_string (NULL
,
20355 Fsubstring (elt
, make_number (charpos
),
20356 make_number (endpos
)),
20360 case MODE_LINE_DISPLAY
:
20362 ptrdiff_t bytepos
= last_offset
;
20363 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20365 if (precision
<= 0)
20366 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20367 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20369 STRING_MULTIBYTE (elt
));
20374 else /* c == '%' */
20376 ptrdiff_t percent_position
= offset
;
20378 /* Get the specified minimum width. Zero means
20381 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20382 field
= field
* 10 + c
- '0';
20384 /* Don't pad beyond the total padding allowed. */
20385 if (field_width
- n
> 0 && field
> field_width
- n
)
20386 field
= field_width
- n
;
20388 /* Note that either PRECISION <= 0 or N < PRECISION. */
20389 prec
= precision
- n
;
20392 n
+= display_mode_element (it
, depth
, field
, prec
,
20393 Vglobal_mode_string
, props
,
20398 ptrdiff_t bytepos
, charpos
;
20400 Lisp_Object string
;
20402 bytepos
= percent_position
;
20403 charpos
= (STRING_MULTIBYTE (elt
)
20404 ? string_byte_to_char (elt
, bytepos
)
20406 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20407 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20409 switch (mode_line_target
)
20411 case MODE_LINE_NOPROP
:
20412 case MODE_LINE_TITLE
:
20413 n
+= store_mode_line_noprop (spec
, field
, prec
);
20415 case MODE_LINE_STRING
:
20417 Lisp_Object tem
= build_string (spec
);
20418 props
= Ftext_properties_at (make_number (charpos
), elt
);
20419 /* Should only keep face property in props */
20420 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20423 case MODE_LINE_DISPLAY
:
20425 int nglyphs_before
, nwritten
;
20427 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20428 nwritten
= display_string (spec
, string
, elt
,
20433 /* Assign to the glyphs written above the
20434 string where the `%x' came from, position
20438 struct glyph
*glyph
20439 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20443 for (i
= 0; i
< nwritten
; ++i
)
20445 glyph
[i
].object
= elt
;
20446 glyph
[i
].charpos
= charpos
;
20463 /* A symbol: process the value of the symbol recursively
20464 as if it appeared here directly. Avoid error if symbol void.
20465 Special case: if value of symbol is a string, output the string
20468 register Lisp_Object tem
;
20470 /* If the variable is not marked as risky to set
20471 then its contents are risky to use. */
20472 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20475 tem
= Fboundp (elt
);
20478 tem
= Fsymbol_value (elt
);
20479 /* If value is a string, output that string literally:
20480 don't check for % within it. */
20484 if (!EQ (tem
, elt
))
20486 /* Give up right away for nil or t. */
20496 register Lisp_Object car
, tem
;
20498 /* A cons cell: five distinct cases.
20499 If first element is :eval or :propertize, do something special.
20500 If first element is a string or a cons, process all the elements
20501 and effectively concatenate them.
20502 If first element is a negative number, truncate displaying cdr to
20503 at most that many characters. If positive, pad (with spaces)
20504 to at least that many characters.
20505 If first element is a symbol, process the cadr or caddr recursively
20506 according to whether the symbol's value is non-nil or nil. */
20508 if (EQ (car
, QCeval
))
20510 /* An element of the form (:eval FORM) means evaluate FORM
20511 and use the result as mode line elements. */
20516 if (CONSP (XCDR (elt
)))
20519 spec
= safe_eval (XCAR (XCDR (elt
)));
20520 n
+= display_mode_element (it
, depth
, field_width
- n
,
20521 precision
- n
, spec
, props
,
20525 else if (EQ (car
, QCpropertize
))
20527 /* An element of the form (:propertize ELT PROPS...)
20528 means display ELT but applying properties PROPS. */
20533 if (CONSP (XCDR (elt
)))
20534 n
+= display_mode_element (it
, depth
, field_width
- n
,
20535 precision
- n
, XCAR (XCDR (elt
)),
20536 XCDR (XCDR (elt
)), risky
);
20538 else if (SYMBOLP (car
))
20540 tem
= Fboundp (car
);
20544 /* elt is now the cdr, and we know it is a cons cell.
20545 Use its car if CAR has a non-nil value. */
20548 tem
= Fsymbol_value (car
);
20555 /* Symbol's value is nil (or symbol is unbound)
20556 Get the cddr of the original list
20557 and if possible find the caddr and use that. */
20561 else if (!CONSP (elt
))
20566 else if (INTEGERP (car
))
20568 register int lim
= XINT (car
);
20572 /* Negative int means reduce maximum width. */
20573 if (precision
<= 0)
20576 precision
= min (precision
, -lim
);
20580 /* Padding specified. Don't let it be more than
20581 current maximum. */
20583 lim
= min (precision
, lim
);
20585 /* If that's more padding than already wanted, queue it.
20586 But don't reduce padding already specified even if
20587 that is beyond the current truncation point. */
20588 field_width
= max (lim
, field_width
);
20592 else if (STRINGP (car
) || CONSP (car
))
20594 Lisp_Object halftail
= elt
;
20598 && (precision
<= 0 || n
< precision
))
20600 n
+= display_mode_element (it
, depth
,
20601 /* Do padding only after the last
20602 element in the list. */
20603 (! CONSP (XCDR (elt
))
20606 precision
- n
, XCAR (elt
),
20610 if ((len
& 1) == 0)
20611 halftail
= XCDR (halftail
);
20612 /* Check for cycle. */
20613 if (EQ (halftail
, elt
))
20622 elt
= build_string ("*invalid*");
20626 /* Pad to FIELD_WIDTH. */
20627 if (field_width
> 0 && n
< field_width
)
20629 switch (mode_line_target
)
20631 case MODE_LINE_NOPROP
:
20632 case MODE_LINE_TITLE
:
20633 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20635 case MODE_LINE_STRING
:
20636 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20638 case MODE_LINE_DISPLAY
:
20639 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20648 /* Store a mode-line string element in mode_line_string_list.
20650 If STRING is non-null, display that C string. Otherwise, the Lisp
20651 string LISP_STRING is displayed.
20653 FIELD_WIDTH is the minimum number of output glyphs to produce.
20654 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20655 with spaces. FIELD_WIDTH <= 0 means don't pad.
20657 PRECISION is the maximum number of characters to output from
20658 STRING. PRECISION <= 0 means don't truncate the string.
20660 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20661 properties to the string.
20663 PROPS are the properties to add to the string.
20664 The mode_line_string_face face property is always added to the string.
20668 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20669 int field_width
, int precision
, Lisp_Object props
)
20674 if (string
!= NULL
)
20676 len
= strlen (string
);
20677 if (precision
> 0 && len
> precision
)
20679 lisp_string
= make_string (string
, len
);
20681 props
= mode_line_string_face_prop
;
20682 else if (!NILP (mode_line_string_face
))
20684 Lisp_Object face
= Fplist_get (props
, Qface
);
20685 props
= Fcopy_sequence (props
);
20687 face
= mode_line_string_face
;
20689 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20690 props
= Fplist_put (props
, Qface
, face
);
20692 Fadd_text_properties (make_number (0), make_number (len
),
20693 props
, lisp_string
);
20697 len
= XFASTINT (Flength (lisp_string
));
20698 if (precision
> 0 && len
> precision
)
20701 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20704 if (!NILP (mode_line_string_face
))
20708 props
= Ftext_properties_at (make_number (0), lisp_string
);
20709 face
= Fplist_get (props
, Qface
);
20711 face
= mode_line_string_face
;
20713 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20714 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20716 lisp_string
= Fcopy_sequence (lisp_string
);
20719 Fadd_text_properties (make_number (0), make_number (len
),
20720 props
, lisp_string
);
20725 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20729 if (field_width
> len
)
20731 field_width
-= len
;
20732 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20734 Fadd_text_properties (make_number (0), make_number (field_width
),
20735 props
, lisp_string
);
20736 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20744 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20746 doc
: /* Format a string out of a mode line format specification.
20747 First arg FORMAT specifies the mode line format (see `mode-line-format'
20748 for details) to use.
20750 By default, the format is evaluated for the currently selected window.
20752 Optional second arg FACE specifies the face property to put on all
20753 characters for which no face is specified. The value nil means the
20754 default face. The value t means whatever face the window's mode line
20755 currently uses (either `mode-line' or `mode-line-inactive',
20756 depending on whether the window is the selected window or not).
20757 An integer value means the value string has no text
20760 Optional third and fourth args WINDOW and BUFFER specify the window
20761 and buffer to use as the context for the formatting (defaults
20762 are the selected window and the WINDOW's buffer). */)
20763 (Lisp_Object format
, Lisp_Object face
,
20764 Lisp_Object window
, Lisp_Object buffer
)
20769 struct buffer
*old_buffer
= NULL
;
20771 int no_props
= INTEGERP (face
);
20772 ptrdiff_t count
= SPECPDL_INDEX ();
20774 int string_start
= 0;
20777 window
= selected_window
;
20778 CHECK_WINDOW (window
);
20779 w
= XWINDOW (window
);
20782 buffer
= w
->buffer
;
20783 CHECK_BUFFER (buffer
);
20785 /* Make formatting the modeline a non-op when noninteractive, otherwise
20786 there will be problems later caused by a partially initialized frame. */
20787 if (NILP (format
) || noninteractive
)
20788 return empty_unibyte_string
;
20793 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20794 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20795 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20796 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20797 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20798 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20799 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20802 if (XBUFFER (buffer
) != current_buffer
)
20803 old_buffer
= current_buffer
;
20805 /* Save things including mode_line_proptrans_alist,
20806 and set that to nil so that we don't alter the outer value. */
20807 record_unwind_protect (unwind_format_mode_line
,
20808 format_mode_line_unwind_data
20809 (old_buffer
, selected_window
, 1));
20810 mode_line_proptrans_alist
= Qnil
;
20812 Fselect_window (window
, Qt
);
20814 set_buffer_internal_1 (XBUFFER (buffer
));
20816 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20820 mode_line_target
= MODE_LINE_NOPROP
;
20821 mode_line_string_face_prop
= Qnil
;
20822 mode_line_string_list
= Qnil
;
20823 string_start
= MODE_LINE_NOPROP_LEN (0);
20827 mode_line_target
= MODE_LINE_STRING
;
20828 mode_line_string_list
= Qnil
;
20829 mode_line_string_face
= face
;
20830 mode_line_string_face_prop
20831 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20834 push_kboard (FRAME_KBOARD (it
.f
));
20835 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20840 len
= MODE_LINE_NOPROP_LEN (string_start
);
20841 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20845 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20846 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20847 empty_unibyte_string
);
20850 unbind_to (count
, Qnil
);
20854 /* Write a null-terminated, right justified decimal representation of
20855 the positive integer D to BUF using a minimal field width WIDTH. */
20858 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20860 register char *p
= buf
;
20868 *p
++ = d
% 10 + '0';
20873 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20884 /* Write a null-terminated, right justified decimal and "human
20885 readable" representation of the nonnegative integer D to BUF using
20886 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20888 static const char power_letter
[] =
20902 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20904 /* We aim to represent the nonnegative integer D as
20905 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20906 ptrdiff_t quotient
= d
;
20908 /* -1 means: do not use TENTHS. */
20912 /* Length of QUOTIENT.TENTHS as a string. */
20918 if (1000 <= quotient
)
20920 /* Scale to the appropriate EXPONENT. */
20923 remainder
= quotient
% 1000;
20927 while (1000 <= quotient
);
20929 /* Round to nearest and decide whether to use TENTHS or not. */
20932 tenths
= remainder
/ 100;
20933 if (50 <= remainder
% 100)
20940 if (quotient
== 10)
20948 if (500 <= remainder
)
20950 if (quotient
< 999)
20961 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
20962 if (tenths
== -1 && quotient
<= 99)
20969 p
= psuffix
= buf
+ max (width
, length
);
20971 /* Print EXPONENT. */
20972 *psuffix
++ = power_letter
[exponent
];
20975 /* Print TENTHS. */
20978 *--p
= '0' + tenths
;
20982 /* Print QUOTIENT. */
20985 int digit
= quotient
% 10;
20986 *--p
= '0' + digit
;
20988 while ((quotient
/= 10) != 0);
20990 /* Print leading spaces. */
20995 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
20996 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
20997 type of CODING_SYSTEM. Return updated pointer into BUF. */
20999 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21002 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21005 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21006 const unsigned char *eol_str
;
21008 /* The EOL conversion we are using. */
21009 Lisp_Object eoltype
;
21011 val
= CODING_SYSTEM_SPEC (coding_system
);
21014 if (!VECTORP (val
)) /* Not yet decided. */
21019 eoltype
= eol_mnemonic_undecided
;
21020 /* Don't mention EOL conversion if it isn't decided. */
21025 Lisp_Object eolvalue
;
21027 attrs
= AREF (val
, 0);
21028 eolvalue
= AREF (val
, 2);
21031 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
21035 /* The EOL conversion that is normal on this system. */
21037 if (NILP (eolvalue
)) /* Not yet decided. */
21038 eoltype
= eol_mnemonic_undecided
;
21039 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21040 eoltype
= eol_mnemonic_undecided
;
21041 else /* eolvalue is Qunix, Qdos, or Qmac. */
21042 eoltype
= (EQ (eolvalue
, Qunix
)
21043 ? eol_mnemonic_unix
21044 : (EQ (eolvalue
, Qdos
) == 1
21045 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21051 /* Mention the EOL conversion if it is not the usual one. */
21052 if (STRINGP (eoltype
))
21054 eol_str
= SDATA (eoltype
);
21055 eol_str_len
= SBYTES (eoltype
);
21057 else if (CHARACTERP (eoltype
))
21059 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
21060 int c
= XFASTINT (eoltype
);
21061 eol_str_len
= CHAR_STRING (c
, tmp
);
21066 eol_str
= invalid_eol_type
;
21067 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21069 memcpy (buf
, eol_str
, eol_str_len
);
21070 buf
+= eol_str_len
;
21076 /* Return a string for the output of a mode line %-spec for window W,
21077 generated by character C. FIELD_WIDTH > 0 means pad the string
21078 returned with spaces to that value. Return a Lisp string in
21079 *STRING if the resulting string is taken from that Lisp string.
21081 Note we operate on the current buffer for most purposes,
21082 the exception being w->base_line_pos. */
21084 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21086 static const char *
21087 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21088 Lisp_Object
*string
)
21091 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21092 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21093 struct buffer
*b
= current_buffer
;
21101 if (!NILP (BVAR (b
, read_only
)))
21103 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21108 /* This differs from %* only for a modified read-only buffer. */
21109 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21111 if (!NILP (BVAR (b
, read_only
)))
21116 /* This differs from %* in ignoring read-only-ness. */
21117 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21129 if (command_loop_level
> 5)
21131 p
= decode_mode_spec_buf
;
21132 for (i
= 0; i
< command_loop_level
; i
++)
21135 return decode_mode_spec_buf
;
21143 if (command_loop_level
> 5)
21145 p
= decode_mode_spec_buf
;
21146 for (i
= 0; i
< command_loop_level
; i
++)
21149 return decode_mode_spec_buf
;
21156 /* Let lots_of_dashes be a string of infinite length. */
21157 if (mode_line_target
== MODE_LINE_NOPROP
||
21158 mode_line_target
== MODE_LINE_STRING
)
21160 if (field_width
<= 0
21161 || field_width
> sizeof (lots_of_dashes
))
21163 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21164 decode_mode_spec_buf
[i
] = '-';
21165 decode_mode_spec_buf
[i
] = '\0';
21166 return decode_mode_spec_buf
;
21169 return lots_of_dashes
;
21173 obj
= BVAR (b
, name
);
21177 /* %c and %l are ignored in `frame-title-format'.
21178 (In redisplay_internal, the frame title is drawn _before_ the
21179 windows are updated, so the stuff which depends on actual
21180 window contents (such as %l) may fail to render properly, or
21181 even crash emacs.) */
21182 if (mode_line_target
== MODE_LINE_TITLE
)
21186 ptrdiff_t col
= current_column ();
21187 w
->column_number_displayed
= make_number (col
);
21188 pint2str (decode_mode_spec_buf
, field_width
, col
);
21189 return decode_mode_spec_buf
;
21193 #ifndef SYSTEM_MALLOC
21195 if (NILP (Vmemory_full
))
21198 return "!MEM FULL! ";
21205 /* %F displays the frame name. */
21206 if (!NILP (f
->title
))
21207 return SSDATA (f
->title
);
21208 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21209 return SSDATA (f
->name
);
21213 obj
= BVAR (b
, filename
);
21218 ptrdiff_t size
= ZV
- BEGV
;
21219 pint2str (decode_mode_spec_buf
, field_width
, size
);
21220 return decode_mode_spec_buf
;
21225 ptrdiff_t size
= ZV
- BEGV
;
21226 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21227 return decode_mode_spec_buf
;
21232 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21233 ptrdiff_t topline
, nlines
, height
;
21236 /* %c and %l are ignored in `frame-title-format'. */
21237 if (mode_line_target
== MODE_LINE_TITLE
)
21240 startpos
= XMARKER (w
->start
)->charpos
;
21241 startpos_byte
= marker_byte_position (w
->start
);
21242 height
= WINDOW_TOTAL_LINES (w
);
21244 /* If we decided that this buffer isn't suitable for line numbers,
21245 don't forget that too fast. */
21246 if (EQ (w
->base_line_pos
, w
->buffer
))
21248 /* But do forget it, if the window shows a different buffer now. */
21249 else if (BUFFERP (w
->base_line_pos
))
21250 w
->base_line_pos
= Qnil
;
21252 /* If the buffer is very big, don't waste time. */
21253 if (INTEGERP (Vline_number_display_limit
)
21254 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21256 w
->base_line_pos
= Qnil
;
21257 w
->base_line_number
= Qnil
;
21261 if (INTEGERP (w
->base_line_number
)
21262 && INTEGERP (w
->base_line_pos
)
21263 && XFASTINT (w
->base_line_pos
) <= startpos
)
21265 line
= XFASTINT (w
->base_line_number
);
21266 linepos
= XFASTINT (w
->base_line_pos
);
21267 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21272 linepos
= BUF_BEGV (b
);
21273 linepos_byte
= BUF_BEGV_BYTE (b
);
21276 /* Count lines from base line to window start position. */
21277 nlines
= display_count_lines (linepos_byte
,
21281 topline
= nlines
+ line
;
21283 /* Determine a new base line, if the old one is too close
21284 or too far away, or if we did not have one.
21285 "Too close" means it's plausible a scroll-down would
21286 go back past it. */
21287 if (startpos
== BUF_BEGV (b
))
21289 w
->base_line_number
= make_number (topline
);
21290 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21292 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21293 || linepos
== BUF_BEGV (b
))
21295 ptrdiff_t limit
= BUF_BEGV (b
);
21296 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21297 ptrdiff_t position
;
21298 ptrdiff_t distance
=
21299 (height
* 2 + 30) * line_number_display_limit_width
;
21301 if (startpos
- distance
> limit
)
21303 limit
= startpos
- distance
;
21304 limit_byte
= CHAR_TO_BYTE (limit
);
21307 nlines
= display_count_lines (startpos_byte
,
21309 - (height
* 2 + 30),
21311 /* If we couldn't find the lines we wanted within
21312 line_number_display_limit_width chars per line,
21313 give up on line numbers for this window. */
21314 if (position
== limit_byte
&& limit
== startpos
- distance
)
21316 w
->base_line_pos
= w
->buffer
;
21317 w
->base_line_number
= Qnil
;
21321 w
->base_line_number
= make_number (topline
- nlines
);
21322 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21325 /* Now count lines from the start pos to point. */
21326 nlines
= display_count_lines (startpos_byte
,
21327 PT_BYTE
, PT
, &junk
);
21329 /* Record that we did display the line number. */
21330 line_number_displayed
= 1;
21332 /* Make the string to show. */
21333 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21334 return decode_mode_spec_buf
;
21337 char* p
= decode_mode_spec_buf
;
21338 int pad
= field_width
- 2;
21344 return decode_mode_spec_buf
;
21350 obj
= BVAR (b
, mode_name
);
21354 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21360 ptrdiff_t pos
= marker_position (w
->start
);
21361 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21363 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21365 if (pos
<= BUF_BEGV (b
))
21370 else if (pos
<= BUF_BEGV (b
))
21374 if (total
> 1000000)
21375 /* Do it differently for a large value, to avoid overflow. */
21376 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21378 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21379 /* We can't normally display a 3-digit number,
21380 so get us a 2-digit number that is close. */
21383 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21384 return decode_mode_spec_buf
;
21388 /* Display percentage of size above the bottom of the screen. */
21391 ptrdiff_t toppos
= marker_position (w
->start
);
21392 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21393 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21395 if (botpos
>= BUF_ZV (b
))
21397 if (toppos
<= BUF_BEGV (b
))
21404 if (total
> 1000000)
21405 /* Do it differently for a large value, to avoid overflow. */
21406 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21408 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21409 /* We can't normally display a 3-digit number,
21410 so get us a 2-digit number that is close. */
21413 if (toppos
<= BUF_BEGV (b
))
21414 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21416 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21417 return decode_mode_spec_buf
;
21422 /* status of process */
21423 obj
= Fget_buffer_process (Fcurrent_buffer ());
21425 return "no process";
21427 obj
= Fsymbol_name (Fprocess_status (obj
));
21433 ptrdiff_t count
= inhibit_garbage_collection ();
21434 Lisp_Object val
= call1 (intern ("file-remote-p"),
21435 BVAR (current_buffer
, directory
));
21436 unbind_to (count
, Qnil
);
21444 case 't': /* indicate TEXT or BINARY */
21448 /* coding-system (not including end-of-line format) */
21450 /* coding-system (including end-of-line type) */
21452 int eol_flag
= (c
== 'Z');
21453 char *p
= decode_mode_spec_buf
;
21455 if (! FRAME_WINDOW_P (f
))
21457 /* No need to mention EOL here--the terminal never needs
21458 to do EOL conversion. */
21459 p
= decode_mode_spec_coding (CODING_ID_NAME
21460 (FRAME_KEYBOARD_CODING (f
)->id
),
21462 p
= decode_mode_spec_coding (CODING_ID_NAME
21463 (FRAME_TERMINAL_CODING (f
)->id
),
21466 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21469 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21470 #ifdef subprocesses
21471 obj
= Fget_buffer_process (Fcurrent_buffer ());
21472 if (PROCESSP (obj
))
21474 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21476 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21479 #endif /* subprocesses */
21482 return decode_mode_spec_buf
;
21489 return SSDATA (obj
);
21496 /* Count up to COUNT lines starting from START_BYTE.
21497 But don't go beyond LIMIT_BYTE.
21498 Return the number of lines thus found (always nonnegative).
21500 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21503 display_count_lines (ptrdiff_t start_byte
,
21504 ptrdiff_t limit_byte
, ptrdiff_t count
,
21505 ptrdiff_t *byte_pos_ptr
)
21507 register unsigned char *cursor
;
21508 unsigned char *base
;
21510 register ptrdiff_t ceiling
;
21511 register unsigned char *ceiling_addr
;
21512 ptrdiff_t orig_count
= count
;
21514 /* If we are not in selective display mode,
21515 check only for newlines. */
21516 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21517 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21521 while (start_byte
< limit_byte
)
21523 ceiling
= BUFFER_CEILING_OF (start_byte
);
21524 ceiling
= min (limit_byte
- 1, ceiling
);
21525 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21526 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21529 if (selective_display
)
21530 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21533 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21536 if (cursor
!= ceiling_addr
)
21540 start_byte
+= cursor
- base
+ 1;
21541 *byte_pos_ptr
= start_byte
;
21545 if (++cursor
== ceiling_addr
)
21551 start_byte
+= cursor
- base
;
21556 while (start_byte
> limit_byte
)
21558 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21559 ceiling
= max (limit_byte
, ceiling
);
21560 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21561 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21564 if (selective_display
)
21565 while (--cursor
!= ceiling_addr
21566 && *cursor
!= '\n' && *cursor
!= 015)
21569 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21572 if (cursor
!= ceiling_addr
)
21576 start_byte
+= cursor
- base
+ 1;
21577 *byte_pos_ptr
= start_byte
;
21578 /* When scanning backwards, we should
21579 not count the newline posterior to which we stop. */
21580 return - orig_count
- 1;
21586 /* Here we add 1 to compensate for the last decrement
21587 of CURSOR, which took it past the valid range. */
21588 start_byte
+= cursor
- base
+ 1;
21592 *byte_pos_ptr
= limit_byte
;
21595 return - orig_count
+ count
;
21596 return orig_count
- count
;
21602 /***********************************************************************
21604 ***********************************************************************/
21606 /* Display a NUL-terminated string, starting with index START.
21608 If STRING is non-null, display that C string. Otherwise, the Lisp
21609 string LISP_STRING is displayed. There's a case that STRING is
21610 non-null and LISP_STRING is not nil. It means STRING is a string
21611 data of LISP_STRING. In that case, we display LISP_STRING while
21612 ignoring its text properties.
21614 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21615 FACE_STRING. Display STRING or LISP_STRING with the face at
21616 FACE_STRING_POS in FACE_STRING:
21618 Display the string in the environment given by IT, but use the
21619 standard display table, temporarily.
21621 FIELD_WIDTH is the minimum number of output glyphs to produce.
21622 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21623 with spaces. If STRING has more characters, more than FIELD_WIDTH
21624 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21626 PRECISION is the maximum number of characters to output from
21627 STRING. PRECISION < 0 means don't truncate the string.
21629 This is roughly equivalent to printf format specifiers:
21631 FIELD_WIDTH PRECISION PRINTF
21632 ----------------------------------------
21638 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21639 display them, and < 0 means obey the current buffer's value of
21640 enable_multibyte_characters.
21642 Value is the number of columns displayed. */
21645 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21646 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21647 int field_width
, int precision
, int max_x
, int multibyte
)
21649 int hpos_at_start
= it
->hpos
;
21650 int saved_face_id
= it
->face_id
;
21651 struct glyph_row
*row
= it
->glyph_row
;
21652 ptrdiff_t it_charpos
;
21654 /* Initialize the iterator IT for iteration over STRING beginning
21655 with index START. */
21656 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21657 precision
, field_width
, multibyte
);
21658 if (string
&& STRINGP (lisp_string
))
21659 /* LISP_STRING is the one returned by decode_mode_spec. We should
21660 ignore its text properties. */
21661 it
->stop_charpos
= it
->end_charpos
;
21663 /* If displaying STRING, set up the face of the iterator from
21664 FACE_STRING, if that's given. */
21665 if (STRINGP (face_string
))
21671 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21672 0, it
->region_beg_charpos
,
21673 it
->region_end_charpos
,
21674 &endptr
, it
->base_face_id
, 0);
21675 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21676 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21679 /* Set max_x to the maximum allowed X position. Don't let it go
21680 beyond the right edge of the window. */
21682 max_x
= it
->last_visible_x
;
21684 max_x
= min (max_x
, it
->last_visible_x
);
21686 /* Skip over display elements that are not visible. because IT->w is
21688 if (it
->current_x
< it
->first_visible_x
)
21689 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21690 MOVE_TO_POS
| MOVE_TO_X
);
21692 row
->ascent
= it
->max_ascent
;
21693 row
->height
= it
->max_ascent
+ it
->max_descent
;
21694 row
->phys_ascent
= it
->max_phys_ascent
;
21695 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21696 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21698 if (STRINGP (it
->string
))
21699 it_charpos
= IT_STRING_CHARPOS (*it
);
21701 it_charpos
= IT_CHARPOS (*it
);
21703 /* This condition is for the case that we are called with current_x
21704 past last_visible_x. */
21705 while (it
->current_x
< max_x
)
21707 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21709 /* Get the next display element. */
21710 if (!get_next_display_element (it
))
21713 /* Produce glyphs. */
21714 x_before
= it
->current_x
;
21715 n_glyphs_before
= row
->used
[TEXT_AREA
];
21716 PRODUCE_GLYPHS (it
);
21718 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21721 while (i
< nglyphs
)
21723 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21725 if (it
->line_wrap
!= TRUNCATE
21726 && x
+ glyph
->pixel_width
> max_x
)
21728 /* End of continued line or max_x reached. */
21729 if (CHAR_GLYPH_PADDING_P (*glyph
))
21731 /* A wide character is unbreakable. */
21732 if (row
->reversed_p
)
21733 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21734 - n_glyphs_before
);
21735 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21736 it
->current_x
= x_before
;
21740 if (row
->reversed_p
)
21741 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21742 - (n_glyphs_before
+ i
));
21743 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21748 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21750 /* Glyph is at least partially visible. */
21752 if (x
< it
->first_visible_x
)
21753 row
->x
= x
- it
->first_visible_x
;
21757 /* Glyph is off the left margin of the display area.
21758 Should not happen. */
21762 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21763 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21764 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21765 row
->phys_height
= max (row
->phys_height
,
21766 it
->max_phys_ascent
+ it
->max_phys_descent
);
21767 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21768 it
->max_extra_line_spacing
);
21769 x
+= glyph
->pixel_width
;
21773 /* Stop if max_x reached. */
21777 /* Stop at line ends. */
21778 if (ITERATOR_AT_END_OF_LINE_P (it
))
21780 it
->continuation_lines_width
= 0;
21784 set_iterator_to_next (it
, 1);
21785 if (STRINGP (it
->string
))
21786 it_charpos
= IT_STRING_CHARPOS (*it
);
21788 it_charpos
= IT_CHARPOS (*it
);
21790 /* Stop if truncating at the right edge. */
21791 if (it
->line_wrap
== TRUNCATE
21792 && it
->current_x
>= it
->last_visible_x
)
21794 /* Add truncation mark, but don't do it if the line is
21795 truncated at a padding space. */
21796 if (it_charpos
< it
->string_nchars
)
21798 if (!FRAME_WINDOW_P (it
->f
))
21802 if (it
->current_x
> it
->last_visible_x
)
21804 if (!row
->reversed_p
)
21806 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21807 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21812 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21813 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21815 unproduce_glyphs (it
, ii
+ 1);
21816 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21818 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21820 row
->used
[TEXT_AREA
] = ii
;
21821 produce_special_glyphs (it
, IT_TRUNCATION
);
21824 produce_special_glyphs (it
, IT_TRUNCATION
);
21826 row
->truncated_on_right_p
= 1;
21832 /* Maybe insert a truncation at the left. */
21833 if (it
->first_visible_x
21836 if (!FRAME_WINDOW_P (it
->f
))
21837 insert_left_trunc_glyphs (it
);
21838 row
->truncated_on_left_p
= 1;
21841 it
->face_id
= saved_face_id
;
21843 /* Value is number of columns displayed. */
21844 return it
->hpos
- hpos_at_start
;
21849 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21850 appears as an element of LIST or as the car of an element of LIST.
21851 If PROPVAL is a list, compare each element against LIST in that
21852 way, and return 1/2 if any element of PROPVAL is found in LIST.
21853 Otherwise return 0. This function cannot quit.
21854 The return value is 2 if the text is invisible but with an ellipsis
21855 and 1 if it's invisible and without an ellipsis. */
21858 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21860 register Lisp_Object tail
, proptail
;
21862 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21864 register Lisp_Object tem
;
21866 if (EQ (propval
, tem
))
21868 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21869 return NILP (XCDR (tem
)) ? 1 : 2;
21872 if (CONSP (propval
))
21874 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21876 Lisp_Object propelt
;
21877 propelt
= XCAR (proptail
);
21878 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21880 register Lisp_Object tem
;
21882 if (EQ (propelt
, tem
))
21884 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21885 return NILP (XCDR (tem
)) ? 1 : 2;
21893 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21894 doc
: /* Non-nil if the property makes the text invisible.
21895 POS-OR-PROP can be a marker or number, in which case it is taken to be
21896 a position in the current buffer and the value of the `invisible' property
21897 is checked; or it can be some other value, which is then presumed to be the
21898 value of the `invisible' property of the text of interest.
21899 The non-nil value returned can be t for truly invisible text or something
21900 else if the text is replaced by an ellipsis. */)
21901 (Lisp_Object pos_or_prop
)
21904 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21905 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21907 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21908 return (invis
== 0 ? Qnil
21910 : make_number (invis
));
21913 /* Calculate a width or height in pixels from a specification using
21914 the following elements:
21917 NUM - a (fractional) multiple of the default font width/height
21918 (NUM) - specifies exactly NUM pixels
21919 UNIT - a fixed number of pixels, see below.
21920 ELEMENT - size of a display element in pixels, see below.
21921 (NUM . SPEC) - equals NUM * SPEC
21922 (+ SPEC SPEC ...) - add pixel values
21923 (- SPEC SPEC ...) - subtract pixel values
21924 (- SPEC) - negate pixel value
21927 INT or FLOAT - a number constant
21928 SYMBOL - use symbol's (buffer local) variable binding.
21931 in - pixels per inch *)
21932 mm - pixels per 1/1000 meter *)
21933 cm - pixels per 1/100 meter *)
21934 width - width of current font in pixels.
21935 height - height of current font in pixels.
21937 *) using the ratio(s) defined in display-pixels-per-inch.
21941 left-fringe - left fringe width in pixels
21942 right-fringe - right fringe width in pixels
21944 left-margin - left margin width in pixels
21945 right-margin - right margin width in pixels
21947 scroll-bar - scroll-bar area width in pixels
21951 Pixels corresponding to 5 inches:
21954 Total width of non-text areas on left side of window (if scroll-bar is on left):
21955 '(space :width (+ left-fringe left-margin scroll-bar))
21957 Align to first text column (in header line):
21958 '(space :align-to 0)
21960 Align to middle of text area minus half the width of variable `my-image'
21961 containing a loaded image:
21962 '(space :align-to (0.5 . (- text my-image)))
21964 Width of left margin minus width of 1 character in the default font:
21965 '(space :width (- left-margin 1))
21967 Width of left margin minus width of 2 characters in the current font:
21968 '(space :width (- left-margin (2 . width)))
21970 Center 1 character over left-margin (in header line):
21971 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
21973 Different ways to express width of left fringe plus left margin minus one pixel:
21974 '(space :width (- (+ left-fringe left-margin) (1)))
21975 '(space :width (+ left-fringe left-margin (- (1))))
21976 '(space :width (+ left-fringe left-margin (-1)))
21980 #define NUMVAL(X) \
21981 ((INTEGERP (X) || FLOATP (X)) \
21986 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
21987 struct font
*font
, int width_p
, int *align_to
)
21991 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
21992 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
21995 return OK_PIXELS (0);
21997 xassert (FRAME_LIVE_P (it
->f
));
21999 if (SYMBOLP (prop
))
22001 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22003 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22005 if (unit
[0] == 'i' && unit
[1] == 'n')
22007 else if (unit
[0] == 'm' && unit
[1] == 'm')
22009 else if (unit
[0] == 'c' && unit
[1] == 'm')
22016 #ifdef HAVE_WINDOW_SYSTEM
22017 if (FRAME_WINDOW_P (it
->f
)
22019 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22020 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22022 return OK_PIXELS (ppi
/ pixels
);
22025 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22026 || (CONSP (Vdisplay_pixels_per_inch
)
22028 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22029 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22031 return OK_PIXELS (ppi
/ pixels
);
22037 #ifdef HAVE_WINDOW_SYSTEM
22038 if (EQ (prop
, Qheight
))
22039 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22040 if (EQ (prop
, Qwidth
))
22041 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22043 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22044 return OK_PIXELS (1);
22047 if (EQ (prop
, Qtext
))
22048 return OK_PIXELS (width_p
22049 ? window_box_width (it
->w
, TEXT_AREA
)
22050 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22052 if (align_to
&& *align_to
< 0)
22055 if (EQ (prop
, Qleft
))
22056 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22057 if (EQ (prop
, Qright
))
22058 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22059 if (EQ (prop
, Qcenter
))
22060 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22061 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22062 if (EQ (prop
, Qleft_fringe
))
22063 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22064 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22065 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22066 if (EQ (prop
, Qright_fringe
))
22067 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22068 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22069 : window_box_right_offset (it
->w
, TEXT_AREA
));
22070 if (EQ (prop
, Qleft_margin
))
22071 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22072 if (EQ (prop
, Qright_margin
))
22073 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22074 if (EQ (prop
, Qscroll_bar
))
22075 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22077 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22078 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22079 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22084 if (EQ (prop
, Qleft_fringe
))
22085 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22086 if (EQ (prop
, Qright_fringe
))
22087 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22088 if (EQ (prop
, Qleft_margin
))
22089 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22090 if (EQ (prop
, Qright_margin
))
22091 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22092 if (EQ (prop
, Qscroll_bar
))
22093 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22096 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
22099 if (INTEGERP (prop
) || FLOATP (prop
))
22101 int base_unit
= (width_p
22102 ? FRAME_COLUMN_WIDTH (it
->f
)
22103 : FRAME_LINE_HEIGHT (it
->f
));
22104 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22109 Lisp_Object car
= XCAR (prop
);
22110 Lisp_Object cdr
= XCDR (prop
);
22114 #ifdef HAVE_WINDOW_SYSTEM
22115 if (FRAME_WINDOW_P (it
->f
)
22116 && valid_image_p (prop
))
22118 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22119 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22121 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22124 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22130 while (CONSP (cdr
))
22132 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22133 font
, width_p
, align_to
))
22136 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22141 if (EQ (car
, Qminus
))
22143 return OK_PIXELS (pixels
);
22146 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
22149 if (INTEGERP (car
) || FLOATP (car
))
22152 pixels
= XFLOATINT (car
);
22154 return OK_PIXELS (pixels
);
22155 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22156 font
, width_p
, align_to
))
22157 return OK_PIXELS (pixels
* fact
);
22168 /***********************************************************************
22170 ***********************************************************************/
22172 #ifdef HAVE_WINDOW_SYSTEM
22177 dump_glyph_string (struct glyph_string
*s
)
22179 fprintf (stderr
, "glyph string\n");
22180 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22181 s
->x
, s
->y
, s
->width
, s
->height
);
22182 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22183 fprintf (stderr
, " hl = %d\n", s
->hl
);
22184 fprintf (stderr
, " left overhang = %d, right = %d\n",
22185 s
->left_overhang
, s
->right_overhang
);
22186 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22187 fprintf (stderr
, " extends to end of line = %d\n",
22188 s
->extends_to_end_of_line_p
);
22189 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22190 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22193 #endif /* GLYPH_DEBUG */
22195 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22196 of XChar2b structures for S; it can't be allocated in
22197 init_glyph_string because it must be allocated via `alloca'. W
22198 is the window on which S is drawn. ROW and AREA are the glyph row
22199 and area within the row from which S is constructed. START is the
22200 index of the first glyph structure covered by S. HL is a
22201 face-override for drawing S. */
22204 #define OPTIONAL_HDC(hdc) HDC hdc,
22205 #define DECLARE_HDC(hdc) HDC hdc;
22206 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22207 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22210 #ifndef OPTIONAL_HDC
22211 #define OPTIONAL_HDC(hdc)
22212 #define DECLARE_HDC(hdc)
22213 #define ALLOCATE_HDC(hdc, f)
22214 #define RELEASE_HDC(hdc, f)
22218 init_glyph_string (struct glyph_string
*s
,
22220 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22221 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22223 memset (s
, 0, sizeof *s
);
22225 s
->f
= XFRAME (w
->frame
);
22229 s
->display
= FRAME_X_DISPLAY (s
->f
);
22230 s
->window
= FRAME_X_WINDOW (s
->f
);
22231 s
->char2b
= char2b
;
22235 s
->first_glyph
= row
->glyphs
[area
] + start
;
22236 s
->height
= row
->height
;
22237 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22238 s
->ybase
= s
->y
+ row
->ascent
;
22242 /* Append the list of glyph strings with head H and tail T to the list
22243 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22246 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22247 struct glyph_string
*h
, struct glyph_string
*t
)
22261 /* Prepend the list of glyph strings with head H and tail T to the
22262 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22266 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22267 struct glyph_string
*h
, struct glyph_string
*t
)
22281 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22282 Set *HEAD and *TAIL to the resulting list. */
22285 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22286 struct glyph_string
*s
)
22288 s
->next
= s
->prev
= NULL
;
22289 append_glyph_string_lists (head
, tail
, s
, s
);
22293 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22294 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22295 make sure that X resources for the face returned are allocated.
22296 Value is a pointer to a realized face that is ready for display if
22297 DISPLAY_P is non-zero. */
22299 static inline struct face
*
22300 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22301 XChar2b
*char2b
, int display_p
)
22303 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22307 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22309 if (code
!= FONT_INVALID_CODE
)
22310 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22312 STORE_XCHAR2B (char2b
, 0, 0);
22315 /* Make sure X resources of the face are allocated. */
22316 #ifdef HAVE_X_WINDOWS
22320 xassert (face
!= NULL
);
22321 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22328 /* Get face and two-byte form of character glyph GLYPH on frame F.
22329 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22330 a pointer to a realized face that is ready for display. */
22332 static inline struct face
*
22333 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22334 XChar2b
*char2b
, int *two_byte_p
)
22338 xassert (glyph
->type
== CHAR_GLYPH
);
22339 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22348 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22349 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22351 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22353 if (code
!= FONT_INVALID_CODE
)
22354 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22356 STORE_XCHAR2B (char2b
, 0, 0);
22359 /* Make sure X resources of the face are allocated. */
22360 xassert (face
!= NULL
);
22361 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22366 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22367 Return 1 if FONT has a glyph for C, otherwise return 0. */
22370 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22374 if (CHAR_BYTE8_P (c
))
22375 code
= CHAR_TO_BYTE8 (c
);
22377 code
= font
->driver
->encode_char (font
, c
);
22379 if (code
== FONT_INVALID_CODE
)
22381 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22386 /* Fill glyph string S with composition components specified by S->cmp.
22388 BASE_FACE is the base face of the composition.
22389 S->cmp_from is the index of the first component for S.
22391 OVERLAPS non-zero means S should draw the foreground only, and use
22392 its physical height for clipping. See also draw_glyphs.
22394 Value is the index of a component not in S. */
22397 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22401 /* For all glyphs of this composition, starting at the offset
22402 S->cmp_from, until we reach the end of the definition or encounter a
22403 glyph that requires the different face, add it to S. */
22408 s
->for_overlaps
= overlaps
;
22411 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22413 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22415 /* TAB in a composition means display glyphs with padding space
22416 on the left or right. */
22419 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22422 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22429 s
->font
= s
->face
->font
;
22431 else if (s
->face
!= face
)
22439 if (s
->face
== NULL
)
22441 s
->face
= base_face
->ascii_face
;
22442 s
->font
= s
->face
->font
;
22445 /* All glyph strings for the same composition has the same width,
22446 i.e. the width set for the first component of the composition. */
22447 s
->width
= s
->first_glyph
->pixel_width
;
22449 /* If the specified font could not be loaded, use the frame's
22450 default font, but record the fact that we couldn't load it in
22451 the glyph string so that we can draw rectangles for the
22452 characters of the glyph string. */
22453 if (s
->font
== NULL
)
22455 s
->font_not_found_p
= 1;
22456 s
->font
= FRAME_FONT (s
->f
);
22459 /* Adjust base line for subscript/superscript text. */
22460 s
->ybase
+= s
->first_glyph
->voffset
;
22462 /* This glyph string must always be drawn with 16-bit functions. */
22469 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22470 int start
, int end
, int overlaps
)
22472 struct glyph
*glyph
, *last
;
22473 Lisp_Object lgstring
;
22476 s
->for_overlaps
= overlaps
;
22477 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22478 last
= s
->row
->glyphs
[s
->area
] + end
;
22479 s
->cmp_id
= glyph
->u
.cmp
.id
;
22480 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22481 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22482 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22483 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22484 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22486 while (glyph
< last
22487 && glyph
->u
.cmp
.automatic
22488 && glyph
->u
.cmp
.id
== s
->cmp_id
22489 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22490 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22492 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22494 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22495 unsigned code
= LGLYPH_CODE (lglyph
);
22497 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22499 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22500 return glyph
- s
->row
->glyphs
[s
->area
];
22504 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22505 See the comment of fill_glyph_string for arguments.
22506 Value is the index of the first glyph not in S. */
22510 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22511 int start
, int end
, int overlaps
)
22513 struct glyph
*glyph
, *last
;
22516 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22517 s
->for_overlaps
= overlaps
;
22518 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22519 last
= s
->row
->glyphs
[s
->area
] + end
;
22520 voffset
= glyph
->voffset
;
22521 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22522 s
->font
= s
->face
->font
;
22524 s
->width
= glyph
->pixel_width
;
22526 while (glyph
< last
22527 && glyph
->type
== GLYPHLESS_GLYPH
22528 && glyph
->voffset
== voffset
22529 && glyph
->face_id
== face_id
)
22532 s
->width
+= glyph
->pixel_width
;
22535 s
->ybase
+= voffset
;
22536 return glyph
- s
->row
->glyphs
[s
->area
];
22540 /* Fill glyph string S from a sequence of character glyphs.
22542 FACE_ID is the face id of the string. START is the index of the
22543 first glyph to consider, END is the index of the last + 1.
22544 OVERLAPS non-zero means S should draw the foreground only, and use
22545 its physical height for clipping. See also draw_glyphs.
22547 Value is the index of the first glyph not in S. */
22550 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22551 int start
, int end
, int overlaps
)
22553 struct glyph
*glyph
, *last
;
22555 int glyph_not_available_p
;
22557 xassert (s
->f
== XFRAME (s
->w
->frame
));
22558 xassert (s
->nchars
== 0);
22559 xassert (start
>= 0 && end
> start
);
22561 s
->for_overlaps
= overlaps
;
22562 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22563 last
= s
->row
->glyphs
[s
->area
] + end
;
22564 voffset
= glyph
->voffset
;
22565 s
->padding_p
= glyph
->padding_p
;
22566 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22568 while (glyph
< last
22569 && glyph
->type
== CHAR_GLYPH
22570 && glyph
->voffset
== voffset
22571 /* Same face id implies same font, nowadays. */
22572 && glyph
->face_id
== face_id
22573 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22577 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22578 s
->char2b
+ s
->nchars
,
22580 s
->two_byte_p
= two_byte_p
;
22582 xassert (s
->nchars
<= end
- start
);
22583 s
->width
+= glyph
->pixel_width
;
22584 if (glyph
++->padding_p
!= s
->padding_p
)
22588 s
->font
= s
->face
->font
;
22590 /* If the specified font could not be loaded, use the frame's font,
22591 but record the fact that we couldn't load it in
22592 S->font_not_found_p so that we can draw rectangles for the
22593 characters of the glyph string. */
22594 if (s
->font
== NULL
|| glyph_not_available_p
)
22596 s
->font_not_found_p
= 1;
22597 s
->font
= FRAME_FONT (s
->f
);
22600 /* Adjust base line for subscript/superscript text. */
22601 s
->ybase
+= voffset
;
22603 xassert (s
->face
&& s
->face
->gc
);
22604 return glyph
- s
->row
->glyphs
[s
->area
];
22608 /* Fill glyph string S from image glyph S->first_glyph. */
22611 fill_image_glyph_string (struct glyph_string
*s
)
22613 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22614 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22616 s
->slice
= s
->first_glyph
->slice
.img
;
22617 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22618 s
->font
= s
->face
->font
;
22619 s
->width
= s
->first_glyph
->pixel_width
;
22621 /* Adjust base line for subscript/superscript text. */
22622 s
->ybase
+= s
->first_glyph
->voffset
;
22626 /* Fill glyph string S from a sequence of stretch glyphs.
22628 START is the index of the first glyph to consider,
22629 END is the index of the last + 1.
22631 Value is the index of the first glyph not in S. */
22634 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22636 struct glyph
*glyph
, *last
;
22637 int voffset
, face_id
;
22639 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22641 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22642 last
= s
->row
->glyphs
[s
->area
] + end
;
22643 face_id
= glyph
->face_id
;
22644 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22645 s
->font
= s
->face
->font
;
22646 s
->width
= glyph
->pixel_width
;
22648 voffset
= glyph
->voffset
;
22652 && glyph
->type
== STRETCH_GLYPH
22653 && glyph
->voffset
== voffset
22654 && glyph
->face_id
== face_id
);
22656 s
->width
+= glyph
->pixel_width
;
22658 /* Adjust base line for subscript/superscript text. */
22659 s
->ybase
+= voffset
;
22661 /* The case that face->gc == 0 is handled when drawing the glyph
22662 string by calling PREPARE_FACE_FOR_DISPLAY. */
22664 return glyph
- s
->row
->glyphs
[s
->area
];
22667 static struct font_metrics
*
22668 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22670 static struct font_metrics metrics
;
22671 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22673 if (! font
|| code
== FONT_INVALID_CODE
)
22675 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22680 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22681 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22682 assumed to be zero. */
22685 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22687 *left
= *right
= 0;
22689 if (glyph
->type
== CHAR_GLYPH
)
22693 struct font_metrics
*pcm
;
22695 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22696 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22698 if (pcm
->rbearing
> pcm
->width
)
22699 *right
= pcm
->rbearing
- pcm
->width
;
22700 if (pcm
->lbearing
< 0)
22701 *left
= -pcm
->lbearing
;
22704 else if (glyph
->type
== COMPOSITE_GLYPH
)
22706 if (! glyph
->u
.cmp
.automatic
)
22708 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22710 if (cmp
->rbearing
> cmp
->pixel_width
)
22711 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22712 if (cmp
->lbearing
< 0)
22713 *left
= - cmp
->lbearing
;
22717 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22718 struct font_metrics metrics
;
22720 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22721 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22722 if (metrics
.rbearing
> metrics
.width
)
22723 *right
= metrics
.rbearing
- metrics
.width
;
22724 if (metrics
.lbearing
< 0)
22725 *left
= - metrics
.lbearing
;
22731 /* Return the index of the first glyph preceding glyph string S that
22732 is overwritten by S because of S's left overhang. Value is -1
22733 if no glyphs are overwritten. */
22736 left_overwritten (struct glyph_string
*s
)
22740 if (s
->left_overhang
)
22743 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22744 int first
= s
->first_glyph
- glyphs
;
22746 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22747 x
-= glyphs
[i
].pixel_width
;
22758 /* Return the index of the first glyph preceding glyph string S that
22759 is overwriting S because of its right overhang. Value is -1 if no
22760 glyph in front of S overwrites S. */
22763 left_overwriting (struct glyph_string
*s
)
22766 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22767 int first
= s
->first_glyph
- glyphs
;
22771 for (i
= first
- 1; i
>= 0; --i
)
22774 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22777 x
-= glyphs
[i
].pixel_width
;
22784 /* Return the index of the last glyph following glyph string S that is
22785 overwritten by S because of S's right overhang. Value is -1 if
22786 no such glyph is found. */
22789 right_overwritten (struct glyph_string
*s
)
22793 if (s
->right_overhang
)
22796 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22797 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22798 int end
= s
->row
->used
[s
->area
];
22800 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22801 x
+= glyphs
[i
].pixel_width
;
22810 /* Return the index of the last glyph following glyph string S that
22811 overwrites S because of its left overhang. Value is negative
22812 if no such glyph is found. */
22815 right_overwriting (struct glyph_string
*s
)
22818 int end
= s
->row
->used
[s
->area
];
22819 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22820 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22824 for (i
= first
; i
< end
; ++i
)
22827 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22830 x
+= glyphs
[i
].pixel_width
;
22837 /* Set background width of glyph string S. START is the index of the
22838 first glyph following S. LAST_X is the right-most x-position + 1
22839 in the drawing area. */
22842 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22844 /* If the face of this glyph string has to be drawn to the end of
22845 the drawing area, set S->extends_to_end_of_line_p. */
22847 if (start
== s
->row
->used
[s
->area
]
22848 && s
->area
== TEXT_AREA
22849 && ((s
->row
->fill_line_p
22850 && (s
->hl
== DRAW_NORMAL_TEXT
22851 || s
->hl
== DRAW_IMAGE_RAISED
22852 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22853 || s
->hl
== DRAW_MOUSE_FACE
))
22854 s
->extends_to_end_of_line_p
= 1;
22856 /* If S extends its face to the end of the line, set its
22857 background_width to the distance to the right edge of the drawing
22859 if (s
->extends_to_end_of_line_p
)
22860 s
->background_width
= last_x
- s
->x
+ 1;
22862 s
->background_width
= s
->width
;
22866 /* Compute overhangs and x-positions for glyph string S and its
22867 predecessors, or successors. X is the starting x-position for S.
22868 BACKWARD_P non-zero means process predecessors. */
22871 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22877 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22878 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22888 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22889 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22899 /* The following macros are only called from draw_glyphs below.
22900 They reference the following parameters of that function directly:
22901 `w', `row', `area', and `overlap_p'
22902 as well as the following local variables:
22903 `s', `f', and `hdc' (in W32) */
22906 /* On W32, silently add local `hdc' variable to argument list of
22907 init_glyph_string. */
22908 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22909 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22911 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22912 init_glyph_string (s, char2b, w, row, area, start, hl)
22915 /* Add a glyph string for a stretch glyph to the list of strings
22916 between HEAD and TAIL. START is the index of the stretch glyph in
22917 row area AREA of glyph row ROW. END is the index of the last glyph
22918 in that glyph row area. X is the current output position assigned
22919 to the new glyph string constructed. HL overrides that face of the
22920 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22921 is the right-most x-position of the drawing area. */
22923 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
22924 and below -- keep them on one line. */
22925 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22928 s = (struct glyph_string *) alloca (sizeof *s); \
22929 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22930 START = fill_stretch_glyph_string (s, START, END); \
22931 append_glyph_string (&HEAD, &TAIL, s); \
22937 /* Add a glyph string for an image glyph to the list of strings
22938 between HEAD and TAIL. START is the index of the image glyph in
22939 row area AREA of glyph row ROW. END is the index of the last glyph
22940 in that glyph row area. X is the current output position assigned
22941 to the new glyph string constructed. HL overrides that face of the
22942 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22943 is the right-most x-position of the drawing area. */
22945 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22948 s = (struct glyph_string *) alloca (sizeof *s); \
22949 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22950 fill_image_glyph_string (s); \
22951 append_glyph_string (&HEAD, &TAIL, s); \
22958 /* Add a glyph string for a sequence of character glyphs to the list
22959 of strings between HEAD and TAIL. START is the index of the first
22960 glyph in row area AREA of glyph row ROW that is part of the new
22961 glyph string. END is the index of the last glyph in that glyph row
22962 area. X is the current output position assigned to the new glyph
22963 string constructed. HL overrides that face of the glyph; e.g. it
22964 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
22965 right-most x-position of the drawing area. */
22967 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22973 face_id = (row)->glyphs[area][START].face_id; \
22975 s = (struct glyph_string *) alloca (sizeof *s); \
22976 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
22977 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22978 append_glyph_string (&HEAD, &TAIL, s); \
22980 START = fill_glyph_string (s, face_id, START, END, overlaps); \
22985 /* Add a glyph string for a composite sequence to the list of strings
22986 between HEAD and TAIL. START is the index of the first glyph in
22987 row area AREA of glyph row ROW that is part of the new glyph
22988 string. END is the index of the last glyph in that glyph row area.
22989 X is the current output position assigned to the new glyph string
22990 constructed. HL overrides that face of the glyph; e.g. it is
22991 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
22992 x-position of the drawing area. */
22994 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22996 int face_id = (row)->glyphs[area][START].face_id; \
22997 struct face *base_face = FACE_FROM_ID (f, face_id); \
22998 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
22999 struct composition *cmp = composition_table[cmp_id]; \
23001 struct glyph_string *first_s = NULL; \
23004 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
23006 /* Make glyph_strings for each glyph sequence that is drawable by \
23007 the same face, and append them to HEAD/TAIL. */ \
23008 for (n = 0; n < cmp->glyph_len;) \
23010 s = (struct glyph_string *) alloca (sizeof *s); \
23011 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23012 append_glyph_string (&(HEAD), &(TAIL), s); \
23018 n = fill_composite_glyph_string (s, base_face, overlaps); \
23026 /* Add a glyph string for a glyph-string sequence to the list of strings
23027 between HEAD and TAIL. */
23029 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23033 Lisp_Object gstring; \
23035 face_id = (row)->glyphs[area][START].face_id; \
23036 gstring = (composition_gstring_from_id \
23037 ((row)->glyphs[area][START].u.cmp.id)); \
23038 s = (struct glyph_string *) alloca (sizeof *s); \
23039 char2b = (XChar2b *) alloca ((sizeof *char2b) \
23040 * LGSTRING_GLYPH_LEN (gstring)); \
23041 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23042 append_glyph_string (&(HEAD), &(TAIL), s); \
23044 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23048 /* Add a glyph string for a sequence of glyphless character's glyphs
23049 to the list of strings between HEAD and TAIL. The meanings of
23050 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23052 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23057 face_id = (row)->glyphs[area][START].face_id; \
23059 s = (struct glyph_string *) alloca (sizeof *s); \
23060 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23061 append_glyph_string (&HEAD, &TAIL, s); \
23063 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23069 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23070 of AREA of glyph row ROW on window W between indices START and END.
23071 HL overrides the face for drawing glyph strings, e.g. it is
23072 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23073 x-positions of the drawing area.
23075 This is an ugly monster macro construct because we must use alloca
23076 to allocate glyph strings (because draw_glyphs can be called
23077 asynchronously). */
23079 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23082 HEAD = TAIL = NULL; \
23083 while (START < END) \
23085 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23086 switch (first_glyph->type) \
23089 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23093 case COMPOSITE_GLYPH: \
23094 if (first_glyph->u.cmp.automatic) \
23095 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23098 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23102 case STRETCH_GLYPH: \
23103 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23107 case IMAGE_GLYPH: \
23108 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23112 case GLYPHLESS_GLYPH: \
23113 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23123 set_glyph_string_background_width (s, START, LAST_X); \
23130 /* Draw glyphs between START and END in AREA of ROW on window W,
23131 starting at x-position X. X is relative to AREA in W. HL is a
23132 face-override with the following meaning:
23134 DRAW_NORMAL_TEXT draw normally
23135 DRAW_CURSOR draw in cursor face
23136 DRAW_MOUSE_FACE draw in mouse face.
23137 DRAW_INVERSE_VIDEO draw in mode line face
23138 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23139 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23141 If OVERLAPS is non-zero, draw only the foreground of characters and
23142 clip to the physical height of ROW. Non-zero value also defines
23143 the overlapping part to be drawn:
23145 OVERLAPS_PRED overlap with preceding rows
23146 OVERLAPS_SUCC overlap with succeeding rows
23147 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23148 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23150 Value is the x-position reached, relative to AREA of W. */
23153 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23154 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23155 enum draw_glyphs_face hl
, int overlaps
)
23157 struct glyph_string
*head
, *tail
;
23158 struct glyph_string
*s
;
23159 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23160 int i
, j
, x_reached
, last_x
, area_left
= 0;
23161 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23164 ALLOCATE_HDC (hdc
, f
);
23166 /* Let's rather be paranoid than getting a SEGV. */
23167 end
= min (end
, row
->used
[area
]);
23168 start
= max (0, start
);
23169 start
= min (end
, start
);
23171 /* Translate X to frame coordinates. Set last_x to the right
23172 end of the drawing area. */
23173 if (row
->full_width_p
)
23175 /* X is relative to the left edge of W, without scroll bars
23177 area_left
= WINDOW_LEFT_EDGE_X (w
);
23178 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23182 area_left
= window_box_left (w
, area
);
23183 last_x
= area_left
+ window_box_width (w
, area
);
23187 /* Build a doubly-linked list of glyph_string structures between
23188 head and tail from what we have to draw. Note that the macro
23189 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23190 the reason we use a separate variable `i'. */
23192 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23194 x_reached
= tail
->x
+ tail
->background_width
;
23198 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23199 the row, redraw some glyphs in front or following the glyph
23200 strings built above. */
23201 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23203 struct glyph_string
*h
, *t
;
23204 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23205 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23206 int check_mouse_face
= 0;
23209 /* If mouse highlighting is on, we may need to draw adjacent
23210 glyphs using mouse-face highlighting. */
23211 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23213 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23215 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23216 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23218 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23220 check_mouse_face
= 1;
23221 mouse_beg_col
= (row
== mouse_beg_row
)
23222 ? hlinfo
->mouse_face_beg_col
: 0;
23223 mouse_end_col
= (row
== mouse_end_row
)
23224 ? hlinfo
->mouse_face_end_col
23225 : row
->used
[TEXT_AREA
];
23229 /* Compute overhangs for all glyph strings. */
23230 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23231 for (s
= head
; s
; s
= s
->next
)
23232 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23234 /* Prepend glyph strings for glyphs in front of the first glyph
23235 string that are overwritten because of the first glyph
23236 string's left overhang. The background of all strings
23237 prepended must be drawn because the first glyph string
23239 i
= left_overwritten (head
);
23242 enum draw_glyphs_face overlap_hl
;
23244 /* If this row contains mouse highlighting, attempt to draw
23245 the overlapped glyphs with the correct highlight. This
23246 code fails if the overlap encompasses more than one glyph
23247 and mouse-highlight spans only some of these glyphs.
23248 However, making it work perfectly involves a lot more
23249 code, and I don't know if the pathological case occurs in
23250 practice, so we'll stick to this for now. --- cyd */
23251 if (check_mouse_face
23252 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23253 overlap_hl
= DRAW_MOUSE_FACE
;
23255 overlap_hl
= DRAW_NORMAL_TEXT
;
23258 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23259 overlap_hl
, dummy_x
, last_x
);
23261 compute_overhangs_and_x (t
, head
->x
, 1);
23262 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23266 /* Prepend glyph strings for glyphs in front of the first glyph
23267 string that overwrite that glyph string because of their
23268 right overhang. For these strings, only the foreground must
23269 be drawn, because it draws over the glyph string at `head'.
23270 The background must not be drawn because this would overwrite
23271 right overhangs of preceding glyphs for which no glyph
23273 i
= left_overwriting (head
);
23276 enum draw_glyphs_face overlap_hl
;
23278 if (check_mouse_face
23279 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23280 overlap_hl
= DRAW_MOUSE_FACE
;
23282 overlap_hl
= DRAW_NORMAL_TEXT
;
23285 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23286 overlap_hl
, dummy_x
, last_x
);
23287 for (s
= h
; s
; s
= s
->next
)
23288 s
->background_filled_p
= 1;
23289 compute_overhangs_and_x (t
, head
->x
, 1);
23290 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23293 /* Append glyphs strings for glyphs following the last glyph
23294 string tail that are overwritten by tail. The background of
23295 these strings has to be drawn because tail's foreground draws
23297 i
= right_overwritten (tail
);
23300 enum draw_glyphs_face overlap_hl
;
23302 if (check_mouse_face
23303 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23304 overlap_hl
= DRAW_MOUSE_FACE
;
23306 overlap_hl
= DRAW_NORMAL_TEXT
;
23308 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23309 overlap_hl
, x
, last_x
);
23310 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23311 we don't have `end = i;' here. */
23312 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23313 append_glyph_string_lists (&head
, &tail
, h
, t
);
23317 /* Append glyph strings for glyphs following the last glyph
23318 string tail that overwrite tail. The foreground of such
23319 glyphs has to be drawn because it writes into the background
23320 of tail. The background must not be drawn because it could
23321 paint over the foreground of following glyphs. */
23322 i
= right_overwriting (tail
);
23325 enum draw_glyphs_face overlap_hl
;
23326 if (check_mouse_face
23327 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23328 overlap_hl
= DRAW_MOUSE_FACE
;
23330 overlap_hl
= DRAW_NORMAL_TEXT
;
23333 i
++; /* We must include the Ith glyph. */
23334 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23335 overlap_hl
, x
, last_x
);
23336 for (s
= h
; s
; s
= s
->next
)
23337 s
->background_filled_p
= 1;
23338 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23339 append_glyph_string_lists (&head
, &tail
, h
, t
);
23341 if (clip_head
|| clip_tail
)
23342 for (s
= head
; s
; s
= s
->next
)
23344 s
->clip_head
= clip_head
;
23345 s
->clip_tail
= clip_tail
;
23349 /* Draw all strings. */
23350 for (s
= head
; s
; s
= s
->next
)
23351 FRAME_RIF (f
)->draw_glyph_string (s
);
23354 /* When focus a sole frame and move horizontally, this sets on_p to 0
23355 causing a failure to erase prev cursor position. */
23356 if (area
== TEXT_AREA
23357 && !row
->full_width_p
23358 /* When drawing overlapping rows, only the glyph strings'
23359 foreground is drawn, which doesn't erase a cursor
23363 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23364 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23365 : (tail
? tail
->x
+ tail
->background_width
: x
));
23369 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23370 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23374 /* Value is the x-position up to which drawn, relative to AREA of W.
23375 This doesn't include parts drawn because of overhangs. */
23376 if (row
->full_width_p
)
23377 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23379 x_reached
-= area_left
;
23381 RELEASE_HDC (hdc
, f
);
23386 /* Expand row matrix if too narrow. Don't expand if area
23389 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23391 if (!fonts_changed_p \
23392 && (it->glyph_row->glyphs[area] \
23393 < it->glyph_row->glyphs[area + 1])) \
23395 it->w->ncols_scale_factor++; \
23396 fonts_changed_p = 1; \
23400 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23401 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23404 append_glyph (struct it
*it
)
23406 struct glyph
*glyph
;
23407 enum glyph_row_area area
= it
->area
;
23409 xassert (it
->glyph_row
);
23410 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23412 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23413 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23415 /* If the glyph row is reversed, we need to prepend the glyph
23416 rather than append it. */
23417 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23421 /* Make room for the additional glyph. */
23422 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23424 glyph
= it
->glyph_row
->glyphs
[area
];
23426 glyph
->charpos
= CHARPOS (it
->position
);
23427 glyph
->object
= it
->object
;
23428 if (it
->pixel_width
> 0)
23430 glyph
->pixel_width
= it
->pixel_width
;
23431 glyph
->padding_p
= 0;
23435 /* Assure at least 1-pixel width. Otherwise, cursor can't
23436 be displayed correctly. */
23437 glyph
->pixel_width
= 1;
23438 glyph
->padding_p
= 1;
23440 glyph
->ascent
= it
->ascent
;
23441 glyph
->descent
= it
->descent
;
23442 glyph
->voffset
= it
->voffset
;
23443 glyph
->type
= CHAR_GLYPH
;
23444 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23445 glyph
->multibyte_p
= it
->multibyte_p
;
23446 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23447 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23448 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23449 || it
->phys_descent
> it
->descent
);
23450 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23451 glyph
->face_id
= it
->face_id
;
23452 glyph
->u
.ch
= it
->char_to_display
;
23453 glyph
->slice
.img
= null_glyph_slice
;
23454 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23457 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23458 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23460 glyph
->bidi_type
= it
->bidi_it
.type
;
23464 glyph
->resolved_level
= 0;
23465 glyph
->bidi_type
= UNKNOWN_BT
;
23467 ++it
->glyph_row
->used
[area
];
23470 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23473 /* Store one glyph for the composition IT->cmp_it.id in
23474 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23478 append_composite_glyph (struct it
*it
)
23480 struct glyph
*glyph
;
23481 enum glyph_row_area area
= it
->area
;
23483 xassert (it
->glyph_row
);
23485 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23486 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23488 /* If the glyph row is reversed, we need to prepend the glyph
23489 rather than append it. */
23490 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23494 /* Make room for the new glyph. */
23495 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23497 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23499 glyph
->charpos
= it
->cmp_it
.charpos
;
23500 glyph
->object
= it
->object
;
23501 glyph
->pixel_width
= it
->pixel_width
;
23502 glyph
->ascent
= it
->ascent
;
23503 glyph
->descent
= it
->descent
;
23504 glyph
->voffset
= it
->voffset
;
23505 glyph
->type
= COMPOSITE_GLYPH
;
23506 if (it
->cmp_it
.ch
< 0)
23508 glyph
->u
.cmp
.automatic
= 0;
23509 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23510 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23514 glyph
->u
.cmp
.automatic
= 1;
23515 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23516 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23517 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23519 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23520 glyph
->multibyte_p
= it
->multibyte_p
;
23521 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23522 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23523 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23524 || it
->phys_descent
> it
->descent
);
23525 glyph
->padding_p
= 0;
23526 glyph
->glyph_not_available_p
= 0;
23527 glyph
->face_id
= it
->face_id
;
23528 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23531 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23532 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23534 glyph
->bidi_type
= it
->bidi_it
.type
;
23536 ++it
->glyph_row
->used
[area
];
23539 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23543 /* Change IT->ascent and IT->height according to the setting of
23547 take_vertical_position_into_account (struct it
*it
)
23551 if (it
->voffset
< 0)
23552 /* Increase the ascent so that we can display the text higher
23554 it
->ascent
-= it
->voffset
;
23556 /* Increase the descent so that we can display the text lower
23558 it
->descent
+= it
->voffset
;
23563 /* Produce glyphs/get display metrics for the image IT is loaded with.
23564 See the description of struct display_iterator in dispextern.h for
23565 an overview of struct display_iterator. */
23568 produce_image_glyph (struct it
*it
)
23572 int glyph_ascent
, crop
;
23573 struct glyph_slice slice
;
23575 xassert (it
->what
== IT_IMAGE
);
23577 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23579 /* Make sure X resources of the face is loaded. */
23580 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23582 if (it
->image_id
< 0)
23584 /* Fringe bitmap. */
23585 it
->ascent
= it
->phys_ascent
= 0;
23586 it
->descent
= it
->phys_descent
= 0;
23587 it
->pixel_width
= 0;
23592 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23594 /* Make sure X resources of the image is loaded. */
23595 prepare_image_for_display (it
->f
, img
);
23597 slice
.x
= slice
.y
= 0;
23598 slice
.width
= img
->width
;
23599 slice
.height
= img
->height
;
23601 if (INTEGERP (it
->slice
.x
))
23602 slice
.x
= XINT (it
->slice
.x
);
23603 else if (FLOATP (it
->slice
.x
))
23604 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23606 if (INTEGERP (it
->slice
.y
))
23607 slice
.y
= XINT (it
->slice
.y
);
23608 else if (FLOATP (it
->slice
.y
))
23609 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23611 if (INTEGERP (it
->slice
.width
))
23612 slice
.width
= XINT (it
->slice
.width
);
23613 else if (FLOATP (it
->slice
.width
))
23614 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23616 if (INTEGERP (it
->slice
.height
))
23617 slice
.height
= XINT (it
->slice
.height
);
23618 else if (FLOATP (it
->slice
.height
))
23619 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23621 if (slice
.x
>= img
->width
)
23622 slice
.x
= img
->width
;
23623 if (slice
.y
>= img
->height
)
23624 slice
.y
= img
->height
;
23625 if (slice
.x
+ slice
.width
>= img
->width
)
23626 slice
.width
= img
->width
- slice
.x
;
23627 if (slice
.y
+ slice
.height
> img
->height
)
23628 slice
.height
= img
->height
- slice
.y
;
23630 if (slice
.width
== 0 || slice
.height
== 0)
23633 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23635 it
->descent
= slice
.height
- glyph_ascent
;
23637 it
->descent
+= img
->vmargin
;
23638 if (slice
.y
+ slice
.height
== img
->height
)
23639 it
->descent
+= img
->vmargin
;
23640 it
->phys_descent
= it
->descent
;
23642 it
->pixel_width
= slice
.width
;
23644 it
->pixel_width
+= img
->hmargin
;
23645 if (slice
.x
+ slice
.width
== img
->width
)
23646 it
->pixel_width
+= img
->hmargin
;
23648 /* It's quite possible for images to have an ascent greater than
23649 their height, so don't get confused in that case. */
23650 if (it
->descent
< 0)
23655 if (face
->box
!= FACE_NO_BOX
)
23657 if (face
->box_line_width
> 0)
23660 it
->ascent
+= face
->box_line_width
;
23661 if (slice
.y
+ slice
.height
== img
->height
)
23662 it
->descent
+= face
->box_line_width
;
23665 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23666 it
->pixel_width
+= eabs (face
->box_line_width
);
23667 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23668 it
->pixel_width
+= eabs (face
->box_line_width
);
23671 take_vertical_position_into_account (it
);
23673 /* Automatically crop wide image glyphs at right edge so we can
23674 draw the cursor on same display row. */
23675 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23676 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23678 it
->pixel_width
-= crop
;
23679 slice
.width
-= crop
;
23684 struct glyph
*glyph
;
23685 enum glyph_row_area area
= it
->area
;
23687 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23688 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23690 glyph
->charpos
= CHARPOS (it
->position
);
23691 glyph
->object
= it
->object
;
23692 glyph
->pixel_width
= it
->pixel_width
;
23693 glyph
->ascent
= glyph_ascent
;
23694 glyph
->descent
= it
->descent
;
23695 glyph
->voffset
= it
->voffset
;
23696 glyph
->type
= IMAGE_GLYPH
;
23697 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23698 glyph
->multibyte_p
= it
->multibyte_p
;
23699 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23700 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23701 glyph
->overlaps_vertically_p
= 0;
23702 glyph
->padding_p
= 0;
23703 glyph
->glyph_not_available_p
= 0;
23704 glyph
->face_id
= it
->face_id
;
23705 glyph
->u
.img_id
= img
->id
;
23706 glyph
->slice
.img
= slice
;
23707 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23710 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23711 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23713 glyph
->bidi_type
= it
->bidi_it
.type
;
23715 ++it
->glyph_row
->used
[area
];
23718 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23723 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23724 of the glyph, WIDTH and HEIGHT are the width and height of the
23725 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23728 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23729 int width
, int height
, int ascent
)
23731 struct glyph
*glyph
;
23732 enum glyph_row_area area
= it
->area
;
23734 xassert (ascent
>= 0 && ascent
<= height
);
23736 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23737 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23739 /* If the glyph row is reversed, we need to prepend the glyph
23740 rather than append it. */
23741 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23745 /* Make room for the additional glyph. */
23746 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23748 glyph
= it
->glyph_row
->glyphs
[area
];
23750 glyph
->charpos
= CHARPOS (it
->position
);
23751 glyph
->object
= object
;
23752 glyph
->pixel_width
= width
;
23753 glyph
->ascent
= ascent
;
23754 glyph
->descent
= height
- ascent
;
23755 glyph
->voffset
= it
->voffset
;
23756 glyph
->type
= STRETCH_GLYPH
;
23757 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23758 glyph
->multibyte_p
= it
->multibyte_p
;
23759 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23760 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23761 glyph
->overlaps_vertically_p
= 0;
23762 glyph
->padding_p
= 0;
23763 glyph
->glyph_not_available_p
= 0;
23764 glyph
->face_id
= it
->face_id
;
23765 glyph
->u
.stretch
.ascent
= ascent
;
23766 glyph
->u
.stretch
.height
= height
;
23767 glyph
->slice
.img
= null_glyph_slice
;
23768 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23771 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23772 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23774 glyph
->bidi_type
= it
->bidi_it
.type
;
23778 glyph
->resolved_level
= 0;
23779 glyph
->bidi_type
= UNKNOWN_BT
;
23781 ++it
->glyph_row
->used
[area
];
23784 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23787 #endif /* HAVE_WINDOW_SYSTEM */
23789 /* Produce a stretch glyph for iterator IT. IT->object is the value
23790 of the glyph property displayed. The value must be a list
23791 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23794 1. `:width WIDTH' specifies that the space should be WIDTH *
23795 canonical char width wide. WIDTH may be an integer or floating
23798 2. `:relative-width FACTOR' specifies that the width of the stretch
23799 should be computed from the width of the first character having the
23800 `glyph' property, and should be FACTOR times that width.
23802 3. `:align-to HPOS' specifies that the space should be wide enough
23803 to reach HPOS, a value in canonical character units.
23805 Exactly one of the above pairs must be present.
23807 4. `:height HEIGHT' specifies that the height of the stretch produced
23808 should be HEIGHT, measured in canonical character units.
23810 5. `:relative-height FACTOR' specifies that the height of the
23811 stretch should be FACTOR times the height of the characters having
23812 the glyph property.
23814 Either none or exactly one of 4 or 5 must be present.
23816 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23817 of the stretch should be used for the ascent of the stretch.
23818 ASCENT must be in the range 0 <= ASCENT <= 100. */
23821 produce_stretch_glyph (struct it
*it
)
23823 /* (space :width WIDTH :height HEIGHT ...) */
23824 Lisp_Object prop
, plist
;
23825 int width
= 0, height
= 0, align_to
= -1;
23826 int zero_width_ok_p
= 0;
23829 struct face
*face
= NULL
;
23830 struct font
*font
= NULL
;
23832 #ifdef HAVE_WINDOW_SYSTEM
23833 int zero_height_ok_p
= 0;
23835 if (FRAME_WINDOW_P (it
->f
))
23837 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23838 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23839 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23843 /* List should start with `space'. */
23844 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23845 plist
= XCDR (it
->object
);
23847 /* Compute the width of the stretch. */
23848 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23849 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23851 /* Absolute width `:width WIDTH' specified and valid. */
23852 zero_width_ok_p
= 1;
23855 #ifdef HAVE_WINDOW_SYSTEM
23856 else if (FRAME_WINDOW_P (it
->f
)
23857 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23859 /* Relative width `:relative-width FACTOR' specified and valid.
23860 Compute the width of the characters having the `glyph'
23863 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23866 if (it
->multibyte_p
)
23867 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23870 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23871 if (! ASCII_CHAR_P (it2
.c
))
23872 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23875 it2
.glyph_row
= NULL
;
23876 it2
.what
= IT_CHARACTER
;
23877 x_produce_glyphs (&it2
);
23878 width
= NUMVAL (prop
) * it2
.pixel_width
;
23880 #endif /* HAVE_WINDOW_SYSTEM */
23881 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23882 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23884 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23885 align_to
= (align_to
< 0
23887 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23888 else if (align_to
< 0)
23889 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23890 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23891 zero_width_ok_p
= 1;
23894 /* Nothing specified -> width defaults to canonical char width. */
23895 width
= FRAME_COLUMN_WIDTH (it
->f
);
23897 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23900 #ifdef HAVE_WINDOW_SYSTEM
23901 /* Compute height. */
23902 if (FRAME_WINDOW_P (it
->f
))
23904 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23905 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23908 zero_height_ok_p
= 1;
23910 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23912 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23914 height
= FONT_HEIGHT (font
);
23916 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
23919 /* Compute percentage of height used for ascent. If
23920 `:ascent ASCENT' is present and valid, use that. Otherwise,
23921 derive the ascent from the font in use. */
23922 if (prop
= Fplist_get (plist
, QCascent
),
23923 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
23924 ascent
= height
* NUMVAL (prop
) / 100.0;
23925 else if (!NILP (prop
)
23926 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23927 ascent
= min (max (0, (int)tem
), height
);
23929 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
23932 #endif /* HAVE_WINDOW_SYSTEM */
23935 if (width
> 0 && it
->line_wrap
!= TRUNCATE
23936 && it
->current_x
+ width
> it
->last_visible_x
)
23938 width
= it
->last_visible_x
- it
->current_x
;
23939 #ifdef HAVE_WINDOW_SYSTEM
23940 /* Subtract one more pixel from the stretch width, but only on
23941 GUI frames, since on a TTY each glyph is one "pixel" wide. */
23942 width
-= FRAME_WINDOW_P (it
->f
);
23946 if (width
> 0 && height
> 0 && it
->glyph_row
)
23948 Lisp_Object o_object
= it
->object
;
23949 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
23952 if (!STRINGP (object
))
23953 object
= it
->w
->buffer
;
23954 #ifdef HAVE_WINDOW_SYSTEM
23955 if (FRAME_WINDOW_P (it
->f
))
23956 append_stretch_glyph (it
, object
, width
, height
, ascent
);
23960 it
->object
= object
;
23961 it
->char_to_display
= ' ';
23962 it
->pixel_width
= it
->len
= 1;
23964 tty_append_glyph (it
);
23965 it
->object
= o_object
;
23969 it
->pixel_width
= width
;
23970 #ifdef HAVE_WINDOW_SYSTEM
23971 if (FRAME_WINDOW_P (it
->f
))
23973 it
->ascent
= it
->phys_ascent
= ascent
;
23974 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
23975 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
23976 take_vertical_position_into_account (it
);
23980 it
->nglyphs
= width
;
23983 #ifdef HAVE_WINDOW_SYSTEM
23985 /* Calculate line-height and line-spacing properties.
23986 An integer value specifies explicit pixel value.
23987 A float value specifies relative value to current face height.
23988 A cons (float . face-name) specifies relative value to
23989 height of specified face font.
23991 Returns height in pixels, or nil. */
23995 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
23996 int boff
, int override
)
23998 Lisp_Object face_name
= Qnil
;
23999 int ascent
, descent
, height
;
24001 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24006 face_name
= XCAR (val
);
24008 if (!NUMBERP (val
))
24009 val
= make_number (1);
24010 if (NILP (face_name
))
24012 height
= it
->ascent
+ it
->descent
;
24017 if (NILP (face_name
))
24019 font
= FRAME_FONT (it
->f
);
24020 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24022 else if (EQ (face_name
, Qt
))
24031 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24033 return make_number (-1);
24035 face
= FACE_FROM_ID (it
->f
, face_id
);
24038 return make_number (-1);
24039 boff
= font
->baseline_offset
;
24040 if (font
->vertical_centering
)
24041 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24044 ascent
= FONT_BASE (font
) + boff
;
24045 descent
= FONT_DESCENT (font
) - boff
;
24049 it
->override_ascent
= ascent
;
24050 it
->override_descent
= descent
;
24051 it
->override_boff
= boff
;
24054 height
= ascent
+ descent
;
24058 height
= (int)(XFLOAT_DATA (val
) * height
);
24059 else if (INTEGERP (val
))
24060 height
*= XINT (val
);
24062 return make_number (height
);
24066 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24067 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24068 and only if this is for a character for which no font was found.
24070 If the display method (it->glyphless_method) is
24071 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24072 length of the acronym or the hexadecimal string, UPPER_XOFF and
24073 UPPER_YOFF are pixel offsets for the upper part of the string,
24074 LOWER_XOFF and LOWER_YOFF are for the lower part.
24076 For the other display methods, LEN through LOWER_YOFF are zero. */
24079 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24080 short upper_xoff
, short upper_yoff
,
24081 short lower_xoff
, short lower_yoff
)
24083 struct glyph
*glyph
;
24084 enum glyph_row_area area
= it
->area
;
24086 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24087 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24089 /* If the glyph row is reversed, we need to prepend the glyph
24090 rather than append it. */
24091 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24095 /* Make room for the additional glyph. */
24096 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24098 glyph
= it
->glyph_row
->glyphs
[area
];
24100 glyph
->charpos
= CHARPOS (it
->position
);
24101 glyph
->object
= it
->object
;
24102 glyph
->pixel_width
= it
->pixel_width
;
24103 glyph
->ascent
= it
->ascent
;
24104 glyph
->descent
= it
->descent
;
24105 glyph
->voffset
= it
->voffset
;
24106 glyph
->type
= GLYPHLESS_GLYPH
;
24107 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24108 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24109 glyph
->u
.glyphless
.len
= len
;
24110 glyph
->u
.glyphless
.ch
= it
->c
;
24111 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24112 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24113 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24114 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24115 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24116 glyph
->multibyte_p
= it
->multibyte_p
;
24117 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24118 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24119 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24120 || it
->phys_descent
> it
->descent
);
24121 glyph
->padding_p
= 0;
24122 glyph
->glyph_not_available_p
= 0;
24123 glyph
->face_id
= face_id
;
24124 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24127 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24128 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24130 glyph
->bidi_type
= it
->bidi_it
.type
;
24132 ++it
->glyph_row
->used
[area
];
24135 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24139 /* Produce a glyph for a glyphless character for iterator IT.
24140 IT->glyphless_method specifies which method to use for displaying
24141 the character. See the description of enum
24142 glyphless_display_method in dispextern.h for the detail.
24144 FOR_NO_FONT is nonzero if and only if this is for a character for
24145 which no font was found. ACRONYM, if non-nil, is an acronym string
24146 for the character. */
24149 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24154 int base_width
, base_height
, width
, height
;
24155 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24158 /* Get the metrics of the base font. We always refer to the current
24160 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24161 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24162 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24163 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24164 base_height
= it
->ascent
+ it
->descent
;
24165 base_width
= font
->average_width
;
24167 /* Get a face ID for the glyph by utilizing a cache (the same way as
24168 done for `escape-glyph' in get_next_display_element). */
24169 if (it
->f
== last_glyphless_glyph_frame
24170 && it
->face_id
== last_glyphless_glyph_face_id
)
24172 face_id
= last_glyphless_glyph_merged_face_id
;
24176 /* Merge the `glyphless-char' face into the current face. */
24177 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24178 last_glyphless_glyph_frame
= it
->f
;
24179 last_glyphless_glyph_face_id
= it
->face_id
;
24180 last_glyphless_glyph_merged_face_id
= face_id
;
24183 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24185 it
->pixel_width
= THIN_SPACE_WIDTH
;
24187 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24189 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24191 width
= CHAR_WIDTH (it
->c
);
24194 else if (width
> 4)
24196 it
->pixel_width
= base_width
* width
;
24198 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24204 unsigned int code
[6];
24206 int ascent
, descent
;
24207 struct font_metrics metrics_upper
, metrics_lower
;
24209 face
= FACE_FROM_ID (it
->f
, face_id
);
24210 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24211 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24213 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24215 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24216 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24217 if (CONSP (acronym
))
24218 acronym
= XCAR (acronym
);
24219 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24223 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24224 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24227 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24228 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24229 upper_len
= (len
+ 1) / 2;
24230 font
->driver
->text_extents (font
, code
, upper_len
,
24232 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24237 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24238 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24239 upper_xoff
= upper_yoff
= 2; /* the typical case */
24240 if (base_width
>= width
)
24242 /* Align the upper to the left, the lower to the right. */
24243 it
->pixel_width
= base_width
;
24244 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24248 /* Center the shorter one. */
24249 it
->pixel_width
= width
;
24250 if (metrics_upper
.width
>= metrics_lower
.width
)
24251 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24254 /* FIXME: This code doesn't look right. It formerly was
24255 missing the "lower_xoff = 0;", which couldn't have
24256 been right since it left lower_xoff uninitialized. */
24258 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24262 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24263 top, bottom, and between upper and lower strings. */
24264 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24265 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24266 /* Center vertically.
24267 H:base_height, D:base_descent
24268 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24270 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24271 descent = D - H/2 + h/2;
24272 lower_yoff = descent - 2 - ld;
24273 upper_yoff = lower_yoff - la - 1 - ud; */
24274 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24275 descent
= it
->descent
- (base_height
- height
) / 2;
24276 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24277 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24278 - metrics_upper
.descent
);
24279 /* Don't make the height shorter than the base height. */
24280 if (height
> base_height
)
24282 it
->ascent
= ascent
;
24283 it
->descent
= descent
;
24287 it
->phys_ascent
= it
->ascent
;
24288 it
->phys_descent
= it
->descent
;
24290 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24291 upper_xoff
, upper_yoff
,
24292 lower_xoff
, lower_yoff
);
24294 take_vertical_position_into_account (it
);
24299 Produce glyphs/get display metrics for the display element IT is
24300 loaded with. See the description of struct it in dispextern.h
24301 for an overview of struct it. */
24304 x_produce_glyphs (struct it
*it
)
24306 int extra_line_spacing
= it
->extra_line_spacing
;
24308 it
->glyph_not_available_p
= 0;
24310 if (it
->what
== IT_CHARACTER
)
24313 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24314 struct font
*font
= face
->font
;
24315 struct font_metrics
*pcm
= NULL
;
24316 int boff
; /* baseline offset */
24320 /* When no suitable font is found, display this character by
24321 the method specified in the first extra slot of
24322 Vglyphless_char_display. */
24323 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24325 xassert (it
->what
== IT_GLYPHLESS
);
24326 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24330 boff
= font
->baseline_offset
;
24331 if (font
->vertical_centering
)
24332 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24334 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24340 if (it
->override_ascent
>= 0)
24342 it
->ascent
= it
->override_ascent
;
24343 it
->descent
= it
->override_descent
;
24344 boff
= it
->override_boff
;
24348 it
->ascent
= FONT_BASE (font
) + boff
;
24349 it
->descent
= FONT_DESCENT (font
) - boff
;
24352 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24354 pcm
= get_per_char_metric (font
, &char2b
);
24355 if (pcm
->width
== 0
24356 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24362 it
->phys_ascent
= pcm
->ascent
+ boff
;
24363 it
->phys_descent
= pcm
->descent
- boff
;
24364 it
->pixel_width
= pcm
->width
;
24368 it
->glyph_not_available_p
= 1;
24369 it
->phys_ascent
= it
->ascent
;
24370 it
->phys_descent
= it
->descent
;
24371 it
->pixel_width
= font
->space_width
;
24374 if (it
->constrain_row_ascent_descent_p
)
24376 if (it
->descent
> it
->max_descent
)
24378 it
->ascent
+= it
->descent
- it
->max_descent
;
24379 it
->descent
= it
->max_descent
;
24381 if (it
->ascent
> it
->max_ascent
)
24383 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24384 it
->ascent
= it
->max_ascent
;
24386 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24387 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24388 extra_line_spacing
= 0;
24391 /* If this is a space inside a region of text with
24392 `space-width' property, change its width. */
24393 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24395 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24397 /* If face has a box, add the box thickness to the character
24398 height. If character has a box line to the left and/or
24399 right, add the box line width to the character's width. */
24400 if (face
->box
!= FACE_NO_BOX
)
24402 int thick
= face
->box_line_width
;
24406 it
->ascent
+= thick
;
24407 it
->descent
+= thick
;
24412 if (it
->start_of_box_run_p
)
24413 it
->pixel_width
+= thick
;
24414 if (it
->end_of_box_run_p
)
24415 it
->pixel_width
+= thick
;
24418 /* If face has an overline, add the height of the overline
24419 (1 pixel) and a 1 pixel margin to the character height. */
24420 if (face
->overline_p
)
24421 it
->ascent
+= overline_margin
;
24423 if (it
->constrain_row_ascent_descent_p
)
24425 if (it
->ascent
> it
->max_ascent
)
24426 it
->ascent
= it
->max_ascent
;
24427 if (it
->descent
> it
->max_descent
)
24428 it
->descent
= it
->max_descent
;
24431 take_vertical_position_into_account (it
);
24433 /* If we have to actually produce glyphs, do it. */
24438 /* Translate a space with a `space-width' property
24439 into a stretch glyph. */
24440 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24441 / FONT_HEIGHT (font
));
24442 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24443 it
->ascent
+ it
->descent
, ascent
);
24448 /* If characters with lbearing or rbearing are displayed
24449 in this line, record that fact in a flag of the
24450 glyph row. This is used to optimize X output code. */
24451 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24452 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24454 if (! stretched_p
&& it
->pixel_width
== 0)
24455 /* We assure that all visible glyphs have at least 1-pixel
24457 it
->pixel_width
= 1;
24459 else if (it
->char_to_display
== '\n')
24461 /* A newline has no width, but we need the height of the
24462 line. But if previous part of the line sets a height,
24463 don't increase that height */
24465 Lisp_Object height
;
24466 Lisp_Object total_height
= Qnil
;
24468 it
->override_ascent
= -1;
24469 it
->pixel_width
= 0;
24472 height
= get_it_property (it
, Qline_height
);
24473 /* Split (line-height total-height) list */
24475 && CONSP (XCDR (height
))
24476 && NILP (XCDR (XCDR (height
))))
24478 total_height
= XCAR (XCDR (height
));
24479 height
= XCAR (height
);
24481 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24483 if (it
->override_ascent
>= 0)
24485 it
->ascent
= it
->override_ascent
;
24486 it
->descent
= it
->override_descent
;
24487 boff
= it
->override_boff
;
24491 it
->ascent
= FONT_BASE (font
) + boff
;
24492 it
->descent
= FONT_DESCENT (font
) - boff
;
24495 if (EQ (height
, Qt
))
24497 if (it
->descent
> it
->max_descent
)
24499 it
->ascent
+= it
->descent
- it
->max_descent
;
24500 it
->descent
= it
->max_descent
;
24502 if (it
->ascent
> it
->max_ascent
)
24504 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24505 it
->ascent
= it
->max_ascent
;
24507 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24508 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24509 it
->constrain_row_ascent_descent_p
= 1;
24510 extra_line_spacing
= 0;
24514 Lisp_Object spacing
;
24516 it
->phys_ascent
= it
->ascent
;
24517 it
->phys_descent
= it
->descent
;
24519 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24520 && face
->box
!= FACE_NO_BOX
24521 && face
->box_line_width
> 0)
24523 it
->ascent
+= face
->box_line_width
;
24524 it
->descent
+= face
->box_line_width
;
24527 && XINT (height
) > it
->ascent
+ it
->descent
)
24528 it
->ascent
= XINT (height
) - it
->descent
;
24530 if (!NILP (total_height
))
24531 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24534 spacing
= get_it_property (it
, Qline_spacing
);
24535 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24537 if (INTEGERP (spacing
))
24539 extra_line_spacing
= XINT (spacing
);
24540 if (!NILP (total_height
))
24541 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24545 else /* i.e. (it->char_to_display == '\t') */
24547 if (font
->space_width
> 0)
24549 int tab_width
= it
->tab_width
* font
->space_width
;
24550 int x
= it
->current_x
+ it
->continuation_lines_width
;
24551 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24553 /* If the distance from the current position to the next tab
24554 stop is less than a space character width, use the
24555 tab stop after that. */
24556 if (next_tab_x
- x
< font
->space_width
)
24557 next_tab_x
+= tab_width
;
24559 it
->pixel_width
= next_tab_x
- x
;
24561 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24562 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24566 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24567 it
->ascent
+ it
->descent
, it
->ascent
);
24572 it
->pixel_width
= 0;
24577 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24579 /* A static composition.
24581 Note: A composition is represented as one glyph in the
24582 glyph matrix. There are no padding glyphs.
24584 Important note: pixel_width, ascent, and descent are the
24585 values of what is drawn by draw_glyphs (i.e. the values of
24586 the overall glyphs composed). */
24587 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24588 int boff
; /* baseline offset */
24589 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24590 int glyph_len
= cmp
->glyph_len
;
24591 struct font
*font
= face
->font
;
24595 /* If we have not yet calculated pixel size data of glyphs of
24596 the composition for the current face font, calculate them
24597 now. Theoretically, we have to check all fonts for the
24598 glyphs, but that requires much time and memory space. So,
24599 here we check only the font of the first glyph. This may
24600 lead to incorrect display, but it's very rare, and C-l
24601 (recenter-top-bottom) can correct the display anyway. */
24602 if (! cmp
->font
|| cmp
->font
!= font
)
24604 /* Ascent and descent of the font of the first character
24605 of this composition (adjusted by baseline offset).
24606 Ascent and descent of overall glyphs should not be less
24607 than these, respectively. */
24608 int font_ascent
, font_descent
, font_height
;
24609 /* Bounding box of the overall glyphs. */
24610 int leftmost
, rightmost
, lowest
, highest
;
24611 int lbearing
, rbearing
;
24612 int i
, width
, ascent
, descent
;
24613 int left_padded
= 0, right_padded
= 0;
24614 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24616 struct font_metrics
*pcm
;
24617 int font_not_found_p
;
24620 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24621 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24623 if (glyph_len
< cmp
->glyph_len
)
24625 for (i
= 0; i
< glyph_len
; i
++)
24627 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24629 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24634 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24635 : IT_CHARPOS (*it
));
24636 /* If no suitable font is found, use the default font. */
24637 font_not_found_p
= font
== NULL
;
24638 if (font_not_found_p
)
24640 face
= face
->ascii_face
;
24643 boff
= font
->baseline_offset
;
24644 if (font
->vertical_centering
)
24645 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24646 font_ascent
= FONT_BASE (font
) + boff
;
24647 font_descent
= FONT_DESCENT (font
) - boff
;
24648 font_height
= FONT_HEIGHT (font
);
24650 cmp
->font
= (void *) font
;
24653 if (! font_not_found_p
)
24655 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24657 pcm
= get_per_char_metric (font
, &char2b
);
24660 /* Initialize the bounding box. */
24663 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24664 ascent
= pcm
->ascent
;
24665 descent
= pcm
->descent
;
24666 lbearing
= pcm
->lbearing
;
24667 rbearing
= pcm
->rbearing
;
24671 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24672 ascent
= FONT_BASE (font
);
24673 descent
= FONT_DESCENT (font
);
24680 lowest
= - descent
+ boff
;
24681 highest
= ascent
+ boff
;
24683 if (! font_not_found_p
24684 && font
->default_ascent
24685 && CHAR_TABLE_P (Vuse_default_ascent
)
24686 && !NILP (Faref (Vuse_default_ascent
,
24687 make_number (it
->char_to_display
))))
24688 highest
= font
->default_ascent
+ boff
;
24690 /* Draw the first glyph at the normal position. It may be
24691 shifted to right later if some other glyphs are drawn
24693 cmp
->offsets
[i
* 2] = 0;
24694 cmp
->offsets
[i
* 2 + 1] = boff
;
24695 cmp
->lbearing
= lbearing
;
24696 cmp
->rbearing
= rbearing
;
24698 /* Set cmp->offsets for the remaining glyphs. */
24699 for (i
++; i
< glyph_len
; i
++)
24701 int left
, right
, btm
, top
;
24702 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24704 struct face
*this_face
;
24708 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24709 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24710 font
= this_face
->font
;
24716 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24718 pcm
= get_per_char_metric (font
, &char2b
);
24721 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24724 width
= pcm
->width
;
24725 ascent
= pcm
->ascent
;
24726 descent
= pcm
->descent
;
24727 lbearing
= pcm
->lbearing
;
24728 rbearing
= pcm
->rbearing
;
24729 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24731 /* Relative composition with or without
24732 alternate chars. */
24733 left
= (leftmost
+ rightmost
- width
) / 2;
24734 btm
= - descent
+ boff
;
24735 if (font
->relative_compose
24736 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24737 || NILP (Faref (Vignore_relative_composition
,
24738 make_number (ch
)))))
24741 if (- descent
>= font
->relative_compose
)
24742 /* One extra pixel between two glyphs. */
24744 else if (ascent
<= 0)
24745 /* One extra pixel between two glyphs. */
24746 btm
= lowest
- 1 - ascent
- descent
;
24751 /* A composition rule is specified by an integer
24752 value that encodes global and new reference
24753 points (GREF and NREF). GREF and NREF are
24754 specified by numbers as below:
24756 0---1---2 -- ascent
24760 9--10--11 -- center
24762 ---3---4---5--- baseline
24764 6---7---8 -- descent
24766 int rule
= COMPOSITION_RULE (cmp
, i
);
24767 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24769 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24770 grefx
= gref
% 3, nrefx
= nref
% 3;
24771 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24773 xoff
= font_height
* (xoff
- 128) / 256;
24775 yoff
= font_height
* (yoff
- 128) / 256;
24778 + grefx
* (rightmost
- leftmost
) / 2
24779 - nrefx
* width
/ 2
24782 btm
= ((grefy
== 0 ? highest
24784 : grefy
== 2 ? lowest
24785 : (highest
+ lowest
) / 2)
24786 - (nrefy
== 0 ? ascent
+ descent
24787 : nrefy
== 1 ? descent
- boff
24789 : (ascent
+ descent
) / 2)
24793 cmp
->offsets
[i
* 2] = left
;
24794 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24796 /* Update the bounding box of the overall glyphs. */
24799 right
= left
+ width
;
24800 if (left
< leftmost
)
24802 if (right
> rightmost
)
24805 top
= btm
+ descent
+ ascent
;
24811 if (cmp
->lbearing
> left
+ lbearing
)
24812 cmp
->lbearing
= left
+ lbearing
;
24813 if (cmp
->rbearing
< left
+ rbearing
)
24814 cmp
->rbearing
= left
+ rbearing
;
24818 /* If there are glyphs whose x-offsets are negative,
24819 shift all glyphs to the right and make all x-offsets
24823 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24824 cmp
->offsets
[i
* 2] -= leftmost
;
24825 rightmost
-= leftmost
;
24826 cmp
->lbearing
-= leftmost
;
24827 cmp
->rbearing
-= leftmost
;
24830 if (left_padded
&& cmp
->lbearing
< 0)
24832 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24833 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24834 rightmost
-= cmp
->lbearing
;
24835 cmp
->rbearing
-= cmp
->lbearing
;
24838 if (right_padded
&& rightmost
< cmp
->rbearing
)
24840 rightmost
= cmp
->rbearing
;
24843 cmp
->pixel_width
= rightmost
;
24844 cmp
->ascent
= highest
;
24845 cmp
->descent
= - lowest
;
24846 if (cmp
->ascent
< font_ascent
)
24847 cmp
->ascent
= font_ascent
;
24848 if (cmp
->descent
< font_descent
)
24849 cmp
->descent
= font_descent
;
24853 && (cmp
->lbearing
< 0
24854 || cmp
->rbearing
> cmp
->pixel_width
))
24855 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24857 it
->pixel_width
= cmp
->pixel_width
;
24858 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24859 it
->descent
= it
->phys_descent
= cmp
->descent
;
24860 if (face
->box
!= FACE_NO_BOX
)
24862 int thick
= face
->box_line_width
;
24866 it
->ascent
+= thick
;
24867 it
->descent
+= thick
;
24872 if (it
->start_of_box_run_p
)
24873 it
->pixel_width
+= thick
;
24874 if (it
->end_of_box_run_p
)
24875 it
->pixel_width
+= thick
;
24878 /* If face has an overline, add the height of the overline
24879 (1 pixel) and a 1 pixel margin to the character height. */
24880 if (face
->overline_p
)
24881 it
->ascent
+= overline_margin
;
24883 take_vertical_position_into_account (it
);
24884 if (it
->ascent
< 0)
24886 if (it
->descent
< 0)
24889 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24890 append_composite_glyph (it
);
24892 else if (it
->what
== IT_COMPOSITION
)
24894 /* A dynamic (automatic) composition. */
24895 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24896 Lisp_Object gstring
;
24897 struct font_metrics metrics
;
24901 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24903 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24906 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24907 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24908 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24909 it
->descent
= it
->phys_descent
= metrics
.descent
;
24910 if (face
->box
!= FACE_NO_BOX
)
24912 int thick
= face
->box_line_width
;
24916 it
->ascent
+= thick
;
24917 it
->descent
+= thick
;
24922 if (it
->start_of_box_run_p
)
24923 it
->pixel_width
+= thick
;
24924 if (it
->end_of_box_run_p
)
24925 it
->pixel_width
+= thick
;
24927 /* If face has an overline, add the height of the overline
24928 (1 pixel) and a 1 pixel margin to the character height. */
24929 if (face
->overline_p
)
24930 it
->ascent
+= overline_margin
;
24931 take_vertical_position_into_account (it
);
24932 if (it
->ascent
< 0)
24934 if (it
->descent
< 0)
24938 append_composite_glyph (it
);
24940 else if (it
->what
== IT_GLYPHLESS
)
24941 produce_glyphless_glyph (it
, 0, Qnil
);
24942 else if (it
->what
== IT_IMAGE
)
24943 produce_image_glyph (it
);
24944 else if (it
->what
== IT_STRETCH
)
24945 produce_stretch_glyph (it
);
24948 /* Accumulate dimensions. Note: can't assume that it->descent > 0
24949 because this isn't true for images with `:ascent 100'. */
24950 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
24951 if (it
->area
== TEXT_AREA
)
24952 it
->current_x
+= it
->pixel_width
;
24954 if (extra_line_spacing
> 0)
24956 it
->descent
+= extra_line_spacing
;
24957 if (extra_line_spacing
> it
->max_extra_line_spacing
)
24958 it
->max_extra_line_spacing
= extra_line_spacing
;
24961 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
24962 it
->max_descent
= max (it
->max_descent
, it
->descent
);
24963 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
24964 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
24968 Output LEN glyphs starting at START at the nominal cursor position.
24969 Advance the nominal cursor over the text. The global variable
24970 updated_window contains the window being updated, updated_row is
24971 the glyph row being updated, and updated_area is the area of that
24972 row being updated. */
24975 x_write_glyphs (struct glyph
*start
, int len
)
24977 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
24979 xassert (updated_window
&& updated_row
);
24980 /* When the window is hscrolled, cursor hpos can legitimately be out
24981 of bounds, but we draw the cursor at the corresponding window
24982 margin in that case. */
24983 if (!updated_row
->reversed_p
&& chpos
< 0)
24985 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
24986 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
24990 /* Write glyphs. */
24992 hpos
= start
- updated_row
->glyphs
[updated_area
];
24993 x
= draw_glyphs (updated_window
, output_cursor
.x
,
24994 updated_row
, updated_area
,
24996 DRAW_NORMAL_TEXT
, 0);
24998 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
24999 if (updated_area
== TEXT_AREA
25000 && updated_window
->phys_cursor_on_p
25001 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25003 && chpos
< hpos
+ len
)
25004 updated_window
->phys_cursor_on_p
= 0;
25008 /* Advance the output cursor. */
25009 output_cursor
.hpos
+= len
;
25010 output_cursor
.x
= x
;
25015 Insert LEN glyphs from START at the nominal cursor position. */
25018 x_insert_glyphs (struct glyph
*start
, int len
)
25022 int line_height
, shift_by_width
, shifted_region_width
;
25023 struct glyph_row
*row
;
25024 struct glyph
*glyph
;
25025 int frame_x
, frame_y
;
25028 xassert (updated_window
&& updated_row
);
25030 w
= updated_window
;
25031 f
= XFRAME (WINDOW_FRAME (w
));
25033 /* Get the height of the line we are in. */
25035 line_height
= row
->height
;
25037 /* Get the width of the glyphs to insert. */
25038 shift_by_width
= 0;
25039 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25040 shift_by_width
+= glyph
->pixel_width
;
25042 /* Get the width of the region to shift right. */
25043 shifted_region_width
= (window_box_width (w
, updated_area
)
25048 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25049 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25051 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25052 line_height
, shift_by_width
);
25054 /* Write the glyphs. */
25055 hpos
= start
- row
->glyphs
[updated_area
];
25056 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25058 DRAW_NORMAL_TEXT
, 0);
25060 /* Advance the output cursor. */
25061 output_cursor
.hpos
+= len
;
25062 output_cursor
.x
+= shift_by_width
;
25068 Erase the current text line from the nominal cursor position
25069 (inclusive) to pixel column TO_X (exclusive). The idea is that
25070 everything from TO_X onward is already erased.
25072 TO_X is a pixel position relative to updated_area of
25073 updated_window. TO_X == -1 means clear to the end of this area. */
25076 x_clear_end_of_line (int to_x
)
25079 struct window
*w
= updated_window
;
25080 int max_x
, min_y
, max_y
;
25081 int from_x
, from_y
, to_y
;
25083 xassert (updated_window
&& updated_row
);
25084 f
= XFRAME (w
->frame
);
25086 if (updated_row
->full_width_p
)
25087 max_x
= WINDOW_TOTAL_WIDTH (w
);
25089 max_x
= window_box_width (w
, updated_area
);
25090 max_y
= window_text_bottom_y (w
);
25092 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25093 of window. For TO_X > 0, truncate to end of drawing area. */
25099 to_x
= min (to_x
, max_x
);
25101 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25103 /* Notice if the cursor will be cleared by this operation. */
25104 if (!updated_row
->full_width_p
)
25105 notice_overwritten_cursor (w
, updated_area
,
25106 output_cursor
.x
, -1,
25108 MATRIX_ROW_BOTTOM_Y (updated_row
));
25110 from_x
= output_cursor
.x
;
25112 /* Translate to frame coordinates. */
25113 if (updated_row
->full_width_p
)
25115 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25116 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25120 int area_left
= window_box_left (w
, updated_area
);
25121 from_x
+= area_left
;
25125 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25126 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25127 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25129 /* Prevent inadvertently clearing to end of the X window. */
25130 if (to_x
> from_x
&& to_y
> from_y
)
25133 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25134 to_x
- from_x
, to_y
- from_y
);
25139 #endif /* HAVE_WINDOW_SYSTEM */
25143 /***********************************************************************
25145 ***********************************************************************/
25147 /* Value is the internal representation of the specified cursor type
25148 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25149 of the bar cursor. */
25151 static enum text_cursor_kinds
25152 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25154 enum text_cursor_kinds type
;
25159 if (EQ (arg
, Qbox
))
25160 return FILLED_BOX_CURSOR
;
25162 if (EQ (arg
, Qhollow
))
25163 return HOLLOW_BOX_CURSOR
;
25165 if (EQ (arg
, Qbar
))
25172 && EQ (XCAR (arg
), Qbar
)
25173 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25175 *width
= XINT (XCDR (arg
));
25179 if (EQ (arg
, Qhbar
))
25182 return HBAR_CURSOR
;
25186 && EQ (XCAR (arg
), Qhbar
)
25187 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25189 *width
= XINT (XCDR (arg
));
25190 return HBAR_CURSOR
;
25193 /* Treat anything unknown as "hollow box cursor".
25194 It was bad to signal an error; people have trouble fixing
25195 .Xdefaults with Emacs, when it has something bad in it. */
25196 type
= HOLLOW_BOX_CURSOR
;
25201 /* Set the default cursor types for specified frame. */
25203 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25208 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25209 FRAME_CURSOR_WIDTH (f
) = width
;
25211 /* By default, set up the blink-off state depending on the on-state. */
25213 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25216 FRAME_BLINK_OFF_CURSOR (f
)
25217 = get_specified_cursor_type (XCDR (tem
), &width
);
25218 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25221 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25225 #ifdef HAVE_WINDOW_SYSTEM
25227 /* Return the cursor we want to be displayed in window W. Return
25228 width of bar/hbar cursor through WIDTH arg. Return with
25229 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25230 (i.e. if the `system caret' should track this cursor).
25232 In a mini-buffer window, we want the cursor only to appear if we
25233 are reading input from this window. For the selected window, we
25234 want the cursor type given by the frame parameter or buffer local
25235 setting of cursor-type. If explicitly marked off, draw no cursor.
25236 In all other cases, we want a hollow box cursor. */
25238 static enum text_cursor_kinds
25239 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25240 int *active_cursor
)
25242 struct frame
*f
= XFRAME (w
->frame
);
25243 struct buffer
*b
= XBUFFER (w
->buffer
);
25244 int cursor_type
= DEFAULT_CURSOR
;
25245 Lisp_Object alt_cursor
;
25246 int non_selected
= 0;
25248 *active_cursor
= 1;
25251 if (cursor_in_echo_area
25252 && FRAME_HAS_MINIBUF_P (f
)
25253 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25255 if (w
== XWINDOW (echo_area_window
))
25257 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25259 *width
= FRAME_CURSOR_WIDTH (f
);
25260 return FRAME_DESIRED_CURSOR (f
);
25263 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25266 *active_cursor
= 0;
25270 /* Detect a nonselected window or nonselected frame. */
25271 else if (w
!= XWINDOW (f
->selected_window
)
25272 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25274 *active_cursor
= 0;
25276 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25282 /* Never display a cursor in a window in which cursor-type is nil. */
25283 if (NILP (BVAR (b
, cursor_type
)))
25286 /* Get the normal cursor type for this window. */
25287 if (EQ (BVAR (b
, cursor_type
), Qt
))
25289 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25290 *width
= FRAME_CURSOR_WIDTH (f
);
25293 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25295 /* Use cursor-in-non-selected-windows instead
25296 for non-selected window or frame. */
25299 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25300 if (!EQ (Qt
, alt_cursor
))
25301 return get_specified_cursor_type (alt_cursor
, width
);
25302 /* t means modify the normal cursor type. */
25303 if (cursor_type
== FILLED_BOX_CURSOR
)
25304 cursor_type
= HOLLOW_BOX_CURSOR
;
25305 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25307 return cursor_type
;
25310 /* Use normal cursor if not blinked off. */
25311 if (!w
->cursor_off_p
)
25313 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25315 if (cursor_type
== FILLED_BOX_CURSOR
)
25317 /* Using a block cursor on large images can be very annoying.
25318 So use a hollow cursor for "large" images.
25319 If image is not transparent (no mask), also use hollow cursor. */
25320 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25321 if (img
!= NULL
&& IMAGEP (img
->spec
))
25323 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25324 where N = size of default frame font size.
25325 This should cover most of the "tiny" icons people may use. */
25327 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25328 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25329 cursor_type
= HOLLOW_BOX_CURSOR
;
25332 else if (cursor_type
!= NO_CURSOR
)
25334 /* Display current only supports BOX and HOLLOW cursors for images.
25335 So for now, unconditionally use a HOLLOW cursor when cursor is
25336 not a solid box cursor. */
25337 cursor_type
= HOLLOW_BOX_CURSOR
;
25340 return cursor_type
;
25343 /* Cursor is blinked off, so determine how to "toggle" it. */
25345 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25346 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25347 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25349 /* Then see if frame has specified a specific blink off cursor type. */
25350 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25352 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25353 return FRAME_BLINK_OFF_CURSOR (f
);
25357 /* Some people liked having a permanently visible blinking cursor,
25358 while others had very strong opinions against it. So it was
25359 decided to remove it. KFS 2003-09-03 */
25361 /* Finally perform built-in cursor blinking:
25362 filled box <-> hollow box
25363 wide [h]bar <-> narrow [h]bar
25364 narrow [h]bar <-> no cursor
25365 other type <-> no cursor */
25367 if (cursor_type
== FILLED_BOX_CURSOR
)
25368 return HOLLOW_BOX_CURSOR
;
25370 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25373 return cursor_type
;
25381 /* Notice when the text cursor of window W has been completely
25382 overwritten by a drawing operation that outputs glyphs in AREA
25383 starting at X0 and ending at X1 in the line starting at Y0 and
25384 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25385 the rest of the line after X0 has been written. Y coordinates
25386 are window-relative. */
25389 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25390 int x0
, int x1
, int y0
, int y1
)
25392 int cx0
, cx1
, cy0
, cy1
;
25393 struct glyph_row
*row
;
25395 if (!w
->phys_cursor_on_p
)
25397 if (area
!= TEXT_AREA
)
25400 if (w
->phys_cursor
.vpos
< 0
25401 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25402 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25403 !(row
->enabled_p
&& row
->displays_text_p
)))
25406 if (row
->cursor_in_fringe_p
)
25408 row
->cursor_in_fringe_p
= 0;
25409 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25410 w
->phys_cursor_on_p
= 0;
25414 cx0
= w
->phys_cursor
.x
;
25415 cx1
= cx0
+ w
->phys_cursor_width
;
25416 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25419 /* The cursor image will be completely removed from the
25420 screen if the output area intersects the cursor area in
25421 y-direction. When we draw in [y0 y1[, and some part of
25422 the cursor is at y < y0, that part must have been drawn
25423 before. When scrolling, the cursor is erased before
25424 actually scrolling, so we don't come here. When not
25425 scrolling, the rows above the old cursor row must have
25426 changed, and in this case these rows must have written
25427 over the cursor image.
25429 Likewise if part of the cursor is below y1, with the
25430 exception of the cursor being in the first blank row at
25431 the buffer and window end because update_text_area
25432 doesn't draw that row. (Except when it does, but
25433 that's handled in update_text_area.) */
25435 cy0
= w
->phys_cursor
.y
;
25436 cy1
= cy0
+ w
->phys_cursor_height
;
25437 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25440 w
->phys_cursor_on_p
= 0;
25443 #endif /* HAVE_WINDOW_SYSTEM */
25446 /************************************************************************
25448 ************************************************************************/
25450 #ifdef HAVE_WINDOW_SYSTEM
25453 Fix the display of area AREA of overlapping row ROW in window W
25454 with respect to the overlapping part OVERLAPS. */
25457 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25458 enum glyph_row_area area
, int overlaps
)
25465 for (i
= 0; i
< row
->used
[area
];)
25467 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25469 int start
= i
, start_x
= x
;
25473 x
+= row
->glyphs
[area
][i
].pixel_width
;
25476 while (i
< row
->used
[area
]
25477 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25479 draw_glyphs (w
, start_x
, row
, area
,
25481 DRAW_NORMAL_TEXT
, overlaps
);
25485 x
+= row
->glyphs
[area
][i
].pixel_width
;
25495 Draw the cursor glyph of window W in glyph row ROW. See the
25496 comment of draw_glyphs for the meaning of HL. */
25499 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25500 enum draw_glyphs_face hl
)
25502 /* If cursor hpos is out of bounds, don't draw garbage. This can
25503 happen in mini-buffer windows when switching between echo area
25504 glyphs and mini-buffer. */
25505 if ((row
->reversed_p
25506 ? (w
->phys_cursor
.hpos
>= 0)
25507 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25509 int on_p
= w
->phys_cursor_on_p
;
25511 int hpos
= w
->phys_cursor
.hpos
;
25513 /* When the window is hscrolled, cursor hpos can legitimately be
25514 out of bounds, but we draw the cursor at the corresponding
25515 window margin in that case. */
25516 if (!row
->reversed_p
&& hpos
< 0)
25518 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25519 hpos
= row
->used
[TEXT_AREA
] - 1;
25521 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25523 w
->phys_cursor_on_p
= on_p
;
25525 if (hl
== DRAW_CURSOR
)
25526 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25527 /* When we erase the cursor, and ROW is overlapped by other
25528 rows, make sure that these overlapping parts of other rows
25530 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25532 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25534 if (row
> w
->current_matrix
->rows
25535 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25536 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25537 OVERLAPS_ERASED_CURSOR
);
25539 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25540 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25541 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25542 OVERLAPS_ERASED_CURSOR
);
25549 Erase the image of a cursor of window W from the screen. */
25552 erase_phys_cursor (struct window
*w
)
25554 struct frame
*f
= XFRAME (w
->frame
);
25555 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25556 int hpos
= w
->phys_cursor
.hpos
;
25557 int vpos
= w
->phys_cursor
.vpos
;
25558 int mouse_face_here_p
= 0;
25559 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25560 struct glyph_row
*cursor_row
;
25561 struct glyph
*cursor_glyph
;
25562 enum draw_glyphs_face hl
;
25564 /* No cursor displayed or row invalidated => nothing to do on the
25566 if (w
->phys_cursor_type
== NO_CURSOR
)
25567 goto mark_cursor_off
;
25569 /* VPOS >= active_glyphs->nrows means that window has been resized.
25570 Don't bother to erase the cursor. */
25571 if (vpos
>= active_glyphs
->nrows
)
25572 goto mark_cursor_off
;
25574 /* If row containing cursor is marked invalid, there is nothing we
25576 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25577 if (!cursor_row
->enabled_p
)
25578 goto mark_cursor_off
;
25580 /* If line spacing is > 0, old cursor may only be partially visible in
25581 window after split-window. So adjust visible height. */
25582 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25583 window_text_bottom_y (w
) - cursor_row
->y
);
25585 /* If row is completely invisible, don't attempt to delete a cursor which
25586 isn't there. This can happen if cursor is at top of a window, and
25587 we switch to a buffer with a header line in that window. */
25588 if (cursor_row
->visible_height
<= 0)
25589 goto mark_cursor_off
;
25591 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25592 if (cursor_row
->cursor_in_fringe_p
)
25594 cursor_row
->cursor_in_fringe_p
= 0;
25595 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25596 goto mark_cursor_off
;
25599 /* This can happen when the new row is shorter than the old one.
25600 In this case, either draw_glyphs or clear_end_of_line
25601 should have cleared the cursor. Note that we wouldn't be
25602 able to erase the cursor in this case because we don't have a
25603 cursor glyph at hand. */
25604 if ((cursor_row
->reversed_p
25605 ? (w
->phys_cursor
.hpos
< 0)
25606 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25607 goto mark_cursor_off
;
25609 /* When the window is hscrolled, cursor hpos can legitimately be out
25610 of bounds, but we draw the cursor at the corresponding window
25611 margin in that case. */
25612 if (!cursor_row
->reversed_p
&& hpos
< 0)
25614 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25615 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25617 /* If the cursor is in the mouse face area, redisplay that when
25618 we clear the cursor. */
25619 if (! NILP (hlinfo
->mouse_face_window
)
25620 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25621 /* Don't redraw the cursor's spot in mouse face if it is at the
25622 end of a line (on a newline). The cursor appears there, but
25623 mouse highlighting does not. */
25624 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25625 mouse_face_here_p
= 1;
25627 /* Maybe clear the display under the cursor. */
25628 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25631 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25634 cursor_glyph
= get_phys_cursor_glyph (w
);
25635 if (cursor_glyph
== NULL
)
25636 goto mark_cursor_off
;
25638 width
= cursor_glyph
->pixel_width
;
25639 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25640 x
= w
->phys_cursor
.x
;
25642 width
-= left_x
- x
;
25643 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25644 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25645 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25648 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25651 /* Erase the cursor by redrawing the character underneath it. */
25652 if (mouse_face_here_p
)
25653 hl
= DRAW_MOUSE_FACE
;
25655 hl
= DRAW_NORMAL_TEXT
;
25656 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25659 w
->phys_cursor_on_p
= 0;
25660 w
->phys_cursor_type
= NO_CURSOR
;
25665 Display or clear cursor of window W. If ON is zero, clear the
25666 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25667 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25670 display_and_set_cursor (struct window
*w
, int on
,
25671 int hpos
, int vpos
, int x
, int y
)
25673 struct frame
*f
= XFRAME (w
->frame
);
25674 int new_cursor_type
;
25675 int new_cursor_width
;
25677 struct glyph_row
*glyph_row
;
25678 struct glyph
*glyph
;
25680 /* This is pointless on invisible frames, and dangerous on garbaged
25681 windows and frames; in the latter case, the frame or window may
25682 be in the midst of changing its size, and x and y may be off the
25684 if (! FRAME_VISIBLE_P (f
)
25685 || FRAME_GARBAGED_P (f
)
25686 || vpos
>= w
->current_matrix
->nrows
25687 || hpos
>= w
->current_matrix
->matrix_w
)
25690 /* If cursor is off and we want it off, return quickly. */
25691 if (!on
&& !w
->phys_cursor_on_p
)
25694 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25695 /* If cursor row is not enabled, we don't really know where to
25696 display the cursor. */
25697 if (!glyph_row
->enabled_p
)
25699 w
->phys_cursor_on_p
= 0;
25704 if (!glyph_row
->exact_window_width_line_p
25705 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25706 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25708 xassert (interrupt_input_blocked
);
25710 /* Set new_cursor_type to the cursor we want to be displayed. */
25711 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25712 &new_cursor_width
, &active_cursor
);
25714 /* If cursor is currently being shown and we don't want it to be or
25715 it is in the wrong place, or the cursor type is not what we want,
25717 if (w
->phys_cursor_on_p
25719 || w
->phys_cursor
.x
!= x
25720 || w
->phys_cursor
.y
!= y
25721 || new_cursor_type
!= w
->phys_cursor_type
25722 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25723 && new_cursor_width
!= w
->phys_cursor_width
)))
25724 erase_phys_cursor (w
);
25726 /* Don't check phys_cursor_on_p here because that flag is only set
25727 to zero in some cases where we know that the cursor has been
25728 completely erased, to avoid the extra work of erasing the cursor
25729 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25730 still not be visible, or it has only been partly erased. */
25733 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25734 w
->phys_cursor_height
= glyph_row
->height
;
25736 /* Set phys_cursor_.* before x_draw_.* is called because some
25737 of them may need the information. */
25738 w
->phys_cursor
.x
= x
;
25739 w
->phys_cursor
.y
= glyph_row
->y
;
25740 w
->phys_cursor
.hpos
= hpos
;
25741 w
->phys_cursor
.vpos
= vpos
;
25744 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25745 new_cursor_type
, new_cursor_width
,
25746 on
, active_cursor
);
25750 /* Switch the display of W's cursor on or off, according to the value
25754 update_window_cursor (struct window
*w
, int on
)
25756 /* Don't update cursor in windows whose frame is in the process
25757 of being deleted. */
25758 if (w
->current_matrix
)
25760 int hpos
= w
->phys_cursor
.hpos
;
25761 int vpos
= w
->phys_cursor
.vpos
;
25762 struct glyph_row
*row
;
25764 if (vpos
>= w
->current_matrix
->nrows
25765 || hpos
>= w
->current_matrix
->matrix_w
)
25768 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25770 /* When the window is hscrolled, cursor hpos can legitimately be
25771 out of bounds, but we draw the cursor at the corresponding
25772 window margin in that case. */
25773 if (!row
->reversed_p
&& hpos
< 0)
25775 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25776 hpos
= row
->used
[TEXT_AREA
] - 1;
25779 display_and_set_cursor (w
, on
, hpos
, vpos
,
25780 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25786 /* Call update_window_cursor with parameter ON_P on all leaf windows
25787 in the window tree rooted at W. */
25790 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25794 if (!NILP (w
->hchild
))
25795 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25796 else if (!NILP (w
->vchild
))
25797 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25799 update_window_cursor (w
, on_p
);
25801 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25807 Display the cursor on window W, or clear it, according to ON_P.
25808 Don't change the cursor's position. */
25811 x_update_cursor (struct frame
*f
, int on_p
)
25813 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25818 Clear the cursor of window W to background color, and mark the
25819 cursor as not shown. This is used when the text where the cursor
25820 is about to be rewritten. */
25823 x_clear_cursor (struct window
*w
)
25825 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25826 update_window_cursor (w
, 0);
25829 #endif /* HAVE_WINDOW_SYSTEM */
25831 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25834 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25835 int start_hpos
, int end_hpos
,
25836 enum draw_glyphs_face draw
)
25838 #ifdef HAVE_WINDOW_SYSTEM
25839 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25841 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25845 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
25846 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25850 /* Display the active region described by mouse_face_* according to DRAW. */
25853 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25855 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25856 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25858 if (/* If window is in the process of being destroyed, don't bother
25860 w
->current_matrix
!= NULL
25861 /* Don't update mouse highlight if hidden */
25862 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25863 /* Recognize when we are called to operate on rows that don't exist
25864 anymore. This can happen when a window is split. */
25865 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25867 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25868 struct glyph_row
*row
, *first
, *last
;
25870 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25871 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25873 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25875 int start_hpos
, end_hpos
, start_x
;
25877 /* For all but the first row, the highlight starts at column 0. */
25880 /* R2L rows have BEG and END in reversed order, but the
25881 screen drawing geometry is always left to right. So
25882 we need to mirror the beginning and end of the
25883 highlighted area in R2L rows. */
25884 if (!row
->reversed_p
)
25886 start_hpos
= hlinfo
->mouse_face_beg_col
;
25887 start_x
= hlinfo
->mouse_face_beg_x
;
25889 else if (row
== last
)
25891 start_hpos
= hlinfo
->mouse_face_end_col
;
25892 start_x
= hlinfo
->mouse_face_end_x
;
25900 else if (row
->reversed_p
&& row
== last
)
25902 start_hpos
= hlinfo
->mouse_face_end_col
;
25903 start_x
= hlinfo
->mouse_face_end_x
;
25913 if (!row
->reversed_p
)
25914 end_hpos
= hlinfo
->mouse_face_end_col
;
25915 else if (row
== first
)
25916 end_hpos
= hlinfo
->mouse_face_beg_col
;
25919 end_hpos
= row
->used
[TEXT_AREA
];
25920 if (draw
== DRAW_NORMAL_TEXT
)
25921 row
->fill_line_p
= 1; /* Clear to end of line */
25924 else if (row
->reversed_p
&& row
== first
)
25925 end_hpos
= hlinfo
->mouse_face_beg_col
;
25928 end_hpos
= row
->used
[TEXT_AREA
];
25929 if (draw
== DRAW_NORMAL_TEXT
)
25930 row
->fill_line_p
= 1; /* Clear to end of line */
25933 if (end_hpos
> start_hpos
)
25935 draw_row_with_mouse_face (w
, start_x
, row
,
25936 start_hpos
, end_hpos
, draw
);
25939 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
25943 #ifdef HAVE_WINDOW_SYSTEM
25944 /* When we've written over the cursor, arrange for it to
25945 be displayed again. */
25946 if (FRAME_WINDOW_P (f
)
25947 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
25949 int hpos
= w
->phys_cursor
.hpos
;
25951 /* When the window is hscrolled, cursor hpos can legitimately be
25952 out of bounds, but we draw the cursor at the corresponding
25953 window margin in that case. */
25954 if (!row
->reversed_p
&& hpos
< 0)
25956 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25957 hpos
= row
->used
[TEXT_AREA
] - 1;
25960 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
25961 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25964 #endif /* HAVE_WINDOW_SYSTEM */
25967 #ifdef HAVE_WINDOW_SYSTEM
25968 /* Change the mouse cursor. */
25969 if (FRAME_WINDOW_P (f
))
25971 if (draw
== DRAW_NORMAL_TEXT
25972 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
25973 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
25974 else if (draw
== DRAW_MOUSE_FACE
)
25975 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
25977 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
25979 #endif /* HAVE_WINDOW_SYSTEM */
25983 Clear out the mouse-highlighted active region.
25984 Redraw it un-highlighted first. Value is non-zero if mouse
25985 face was actually drawn unhighlighted. */
25988 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
25992 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
25994 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
25998 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25999 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26000 hlinfo
->mouse_face_window
= Qnil
;
26001 hlinfo
->mouse_face_overlay
= Qnil
;
26005 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26006 within the mouse face on that window. */
26008 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26010 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26012 /* Quickly resolve the easy cases. */
26013 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26014 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26016 if (vpos
< hlinfo
->mouse_face_beg_row
26017 || vpos
> hlinfo
->mouse_face_end_row
)
26019 if (vpos
> hlinfo
->mouse_face_beg_row
26020 && vpos
< hlinfo
->mouse_face_end_row
)
26023 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26025 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26027 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26030 else if ((vpos
== hlinfo
->mouse_face_beg_row
26031 && hpos
>= hlinfo
->mouse_face_beg_col
)
26032 || (vpos
== hlinfo
->mouse_face_end_row
26033 && hpos
< hlinfo
->mouse_face_end_col
))
26038 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26040 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26043 else if ((vpos
== hlinfo
->mouse_face_beg_row
26044 && hpos
<= hlinfo
->mouse_face_beg_col
)
26045 || (vpos
== hlinfo
->mouse_face_end_row
26046 && hpos
> hlinfo
->mouse_face_end_col
))
26054 Non-zero if physical cursor of window W is within mouse face. */
26057 cursor_in_mouse_face_p (struct window
*w
)
26059 int hpos
= w
->phys_cursor
.hpos
;
26060 int vpos
= w
->phys_cursor
.vpos
;
26061 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26063 /* When the window is hscrolled, cursor hpos can legitimately be out
26064 of bounds, but we draw the cursor at the corresponding window
26065 margin in that case. */
26066 if (!row
->reversed_p
&& hpos
< 0)
26068 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26069 hpos
= row
->used
[TEXT_AREA
] - 1;
26071 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26076 /* Find the glyph rows START_ROW and END_ROW of window W that display
26077 characters between buffer positions START_CHARPOS and END_CHARPOS
26078 (excluding END_CHARPOS). DISP_STRING is a display string that
26079 covers these buffer positions. This is similar to
26080 row_containing_pos, but is more accurate when bidi reordering makes
26081 buffer positions change non-linearly with glyph rows. */
26083 rows_from_pos_range (struct window
*w
,
26084 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26085 Lisp_Object disp_string
,
26086 struct glyph_row
**start
, struct glyph_row
**end
)
26088 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26089 int last_y
= window_text_bottom_y (w
);
26090 struct glyph_row
*row
;
26095 while (!first
->enabled_p
26096 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26099 /* Find the START row. */
26101 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26104 /* A row can potentially be the START row if the range of the
26105 characters it displays intersects the range
26106 [START_CHARPOS..END_CHARPOS). */
26107 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26108 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26109 /* See the commentary in row_containing_pos, for the
26110 explanation of the complicated way to check whether
26111 some position is beyond the end of the characters
26112 displayed by a row. */
26113 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26114 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26115 && !row
->ends_at_zv_p
26116 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26117 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26118 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26119 && !row
->ends_at_zv_p
26120 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26122 /* Found a candidate row. Now make sure at least one of the
26123 glyphs it displays has a charpos from the range
26124 [START_CHARPOS..END_CHARPOS).
26126 This is not obvious because bidi reordering could make
26127 buffer positions of a row be 1,2,3,102,101,100, and if we
26128 want to highlight characters in [50..60), we don't want
26129 this row, even though [50..60) does intersect [1..103),
26130 the range of character positions given by the row's start
26131 and end positions. */
26132 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26133 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26137 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26138 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26139 /* A glyph that comes from DISP_STRING is by
26140 definition to be highlighted. */
26141 || EQ (g
->object
, disp_string
))
26150 /* Find the END row. */
26152 /* If the last row is partially visible, start looking for END
26153 from that row, instead of starting from FIRST. */
26154 && !(row
->enabled_p
26155 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26157 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26159 struct glyph_row
*next
= row
+ 1;
26160 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26162 if (!next
->enabled_p
26163 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26164 /* The first row >= START whose range of displayed characters
26165 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26166 is the row END + 1. */
26167 || (start_charpos
< next_start
26168 && end_charpos
< next_start
)
26169 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26170 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26171 && !next
->ends_at_zv_p
26172 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26173 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26174 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26175 && !next
->ends_at_zv_p
26176 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26183 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26184 but none of the characters it displays are in the range, it is
26186 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26187 struct glyph
*s
= g
;
26188 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26192 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26193 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26194 /* If the buffer position of the first glyph in
26195 the row is equal to END_CHARPOS, it means
26196 the last character to be highlighted is the
26197 newline of ROW, and we must consider NEXT as
26199 || (((!next
->reversed_p
&& g
== s
)
26200 || (next
->reversed_p
&& g
== e
- 1))
26201 && (g
->charpos
== end_charpos
26202 /* Special case for when NEXT is an
26203 empty line at ZV. */
26204 || (g
->charpos
== -1
26205 && !row
->ends_at_zv_p
26206 && next_start
== end_charpos
)))))
26207 /* A glyph that comes from DISP_STRING is by
26208 definition to be highlighted. */
26209 || EQ (g
->object
, disp_string
))
26218 /* The first row that ends at ZV must be the last to be
26220 else if (next
->ends_at_zv_p
)
26229 /* This function sets the mouse_face_* elements of HLINFO, assuming
26230 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26231 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26232 for the overlay or run of text properties specifying the mouse
26233 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26234 before-string and after-string that must also be highlighted.
26235 DISP_STRING, if non-nil, is a display string that may cover some
26236 or all of the highlighted text. */
26239 mouse_face_from_buffer_pos (Lisp_Object window
,
26240 Mouse_HLInfo
*hlinfo
,
26241 ptrdiff_t mouse_charpos
,
26242 ptrdiff_t start_charpos
,
26243 ptrdiff_t end_charpos
,
26244 Lisp_Object before_string
,
26245 Lisp_Object after_string
,
26246 Lisp_Object disp_string
)
26248 struct window
*w
= XWINDOW (window
);
26249 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26250 struct glyph_row
*r1
, *r2
;
26251 struct glyph
*glyph
, *end
;
26252 ptrdiff_t ignore
, pos
;
26255 xassert (NILP (disp_string
) || STRINGP (disp_string
));
26256 xassert (NILP (before_string
) || STRINGP (before_string
));
26257 xassert (NILP (after_string
) || STRINGP (after_string
));
26259 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26260 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26262 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26263 /* If the before-string or display-string contains newlines,
26264 rows_from_pos_range skips to its last row. Move back. */
26265 if (!NILP (before_string
) || !NILP (disp_string
))
26267 struct glyph_row
*prev
;
26268 while ((prev
= r1
- 1, prev
>= first
)
26269 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26270 && prev
->used
[TEXT_AREA
] > 0)
26272 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26273 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26274 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26276 || !(EQ (glyph
->object
, before_string
)
26277 || EQ (glyph
->object
, disp_string
)))
26284 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26285 hlinfo
->mouse_face_past_end
= 1;
26287 else if (!NILP (after_string
))
26289 /* If the after-string has newlines, advance to its last row. */
26290 struct glyph_row
*next
;
26291 struct glyph_row
*last
26292 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26294 for (next
= r2
+ 1;
26296 && next
->used
[TEXT_AREA
] > 0
26297 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26301 /* The rest of the display engine assumes that mouse_face_beg_row is
26302 either above mouse_face_end_row or identical to it. But with
26303 bidi-reordered continued lines, the row for START_CHARPOS could
26304 be below the row for END_CHARPOS. If so, swap the rows and store
26305 them in correct order. */
26308 struct glyph_row
*tem
= r2
;
26314 hlinfo
->mouse_face_beg_y
= r1
->y
;
26315 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26316 hlinfo
->mouse_face_end_y
= r2
->y
;
26317 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26319 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26320 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26321 could be anywhere in the row and in any order. The strategy
26322 below is to find the leftmost and the rightmost glyph that
26323 belongs to either of these 3 strings, or whose position is
26324 between START_CHARPOS and END_CHARPOS, and highlight all the
26325 glyphs between those two. This may cover more than just the text
26326 between START_CHARPOS and END_CHARPOS if the range of characters
26327 strides the bidi level boundary, e.g. if the beginning is in R2L
26328 text while the end is in L2R text or vice versa. */
26329 if (!r1
->reversed_p
)
26331 /* This row is in a left to right paragraph. Scan it left to
26333 glyph
= r1
->glyphs
[TEXT_AREA
];
26334 end
= glyph
+ r1
->used
[TEXT_AREA
];
26337 /* Skip truncation glyphs at the start of the glyph row. */
26338 if (r1
->displays_text_p
)
26340 && INTEGERP (glyph
->object
)
26341 && glyph
->charpos
< 0;
26343 x
+= glyph
->pixel_width
;
26345 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26346 or DISP_STRING, and the first glyph from buffer whose
26347 position is between START_CHARPOS and END_CHARPOS. */
26349 && !INTEGERP (glyph
->object
)
26350 && !EQ (glyph
->object
, disp_string
)
26351 && !(BUFFERP (glyph
->object
)
26352 && (glyph
->charpos
>= start_charpos
26353 && glyph
->charpos
< end_charpos
));
26356 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26357 are present at buffer positions between START_CHARPOS and
26358 END_CHARPOS, or if they come from an overlay. */
26359 if (EQ (glyph
->object
, before_string
))
26361 pos
= string_buffer_position (before_string
,
26363 /* If pos == 0, it means before_string came from an
26364 overlay, not from a buffer position. */
26365 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26368 else if (EQ (glyph
->object
, after_string
))
26370 pos
= string_buffer_position (after_string
, end_charpos
);
26371 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26374 x
+= glyph
->pixel_width
;
26376 hlinfo
->mouse_face_beg_x
= x
;
26377 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26381 /* This row is in a right to left paragraph. Scan it right to
26385 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26386 glyph
= end
+ r1
->used
[TEXT_AREA
];
26388 /* Skip truncation glyphs at the start of the glyph row. */
26389 if (r1
->displays_text_p
)
26391 && INTEGERP (glyph
->object
)
26392 && glyph
->charpos
< 0;
26396 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26397 or DISP_STRING, and the first glyph from buffer whose
26398 position is between START_CHARPOS and END_CHARPOS. */
26400 && !INTEGERP (glyph
->object
)
26401 && !EQ (glyph
->object
, disp_string
)
26402 && !(BUFFERP (glyph
->object
)
26403 && (glyph
->charpos
>= start_charpos
26404 && glyph
->charpos
< end_charpos
));
26407 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26408 are present at buffer positions between START_CHARPOS and
26409 END_CHARPOS, or if they come from an overlay. */
26410 if (EQ (glyph
->object
, before_string
))
26412 pos
= string_buffer_position (before_string
, start_charpos
);
26413 /* If pos == 0, it means before_string came from an
26414 overlay, not from a buffer position. */
26415 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26418 else if (EQ (glyph
->object
, after_string
))
26420 pos
= string_buffer_position (after_string
, end_charpos
);
26421 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26426 glyph
++; /* first glyph to the right of the highlighted area */
26427 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26428 x
+= g
->pixel_width
;
26429 hlinfo
->mouse_face_beg_x
= x
;
26430 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26433 /* If the highlight ends in a different row, compute GLYPH and END
26434 for the end row. Otherwise, reuse the values computed above for
26435 the row where the highlight begins. */
26438 if (!r2
->reversed_p
)
26440 glyph
= r2
->glyphs
[TEXT_AREA
];
26441 end
= glyph
+ r2
->used
[TEXT_AREA
];
26446 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26447 glyph
= end
+ r2
->used
[TEXT_AREA
];
26451 if (!r2
->reversed_p
)
26453 /* Skip truncation and continuation glyphs near the end of the
26454 row, and also blanks and stretch glyphs inserted by
26455 extend_face_to_end_of_line. */
26457 && INTEGERP ((end
- 1)->object
))
26459 /* Scan the rest of the glyph row from the end, looking for the
26460 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26461 DISP_STRING, or whose position is between START_CHARPOS
26465 && !INTEGERP (end
->object
)
26466 && !EQ (end
->object
, disp_string
)
26467 && !(BUFFERP (end
->object
)
26468 && (end
->charpos
>= start_charpos
26469 && end
->charpos
< end_charpos
));
26472 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26473 are present at buffer positions between START_CHARPOS and
26474 END_CHARPOS, or if they come from an overlay. */
26475 if (EQ (end
->object
, before_string
))
26477 pos
= string_buffer_position (before_string
, start_charpos
);
26478 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26481 else if (EQ (end
->object
, after_string
))
26483 pos
= string_buffer_position (after_string
, end_charpos
);
26484 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26488 /* Find the X coordinate of the last glyph to be highlighted. */
26489 for (; glyph
<= end
; ++glyph
)
26490 x
+= glyph
->pixel_width
;
26492 hlinfo
->mouse_face_end_x
= x
;
26493 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26497 /* Skip truncation and continuation glyphs near the end of the
26498 row, and also blanks and stretch glyphs inserted by
26499 extend_face_to_end_of_line. */
26503 && INTEGERP (end
->object
))
26505 x
+= end
->pixel_width
;
26508 /* Scan the rest of the glyph row from the end, looking for the
26509 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26510 DISP_STRING, or whose position is between START_CHARPOS
26514 && !INTEGERP (end
->object
)
26515 && !EQ (end
->object
, disp_string
)
26516 && !(BUFFERP (end
->object
)
26517 && (end
->charpos
>= start_charpos
26518 && end
->charpos
< end_charpos
));
26521 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26522 are present at buffer positions between START_CHARPOS and
26523 END_CHARPOS, or if they come from an overlay. */
26524 if (EQ (end
->object
, before_string
))
26526 pos
= string_buffer_position (before_string
, start_charpos
);
26527 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26530 else if (EQ (end
->object
, after_string
))
26532 pos
= string_buffer_position (after_string
, end_charpos
);
26533 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26536 x
+= end
->pixel_width
;
26538 /* If we exited the above loop because we arrived at the last
26539 glyph of the row, and its buffer position is still not in
26540 range, it means the last character in range is the preceding
26541 newline. Bump the end column and x values to get past the
26544 && BUFFERP (end
->object
)
26545 && (end
->charpos
< start_charpos
26546 || end
->charpos
>= end_charpos
))
26548 x
+= end
->pixel_width
;
26551 hlinfo
->mouse_face_end_x
= x
;
26552 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26555 hlinfo
->mouse_face_window
= window
;
26556 hlinfo
->mouse_face_face_id
26557 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26559 !hlinfo
->mouse_face_hidden
, -1);
26560 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26563 /* The following function is not used anymore (replaced with
26564 mouse_face_from_string_pos), but I leave it here for the time
26565 being, in case someone would. */
26567 #if 0 /* not used */
26569 /* Find the position of the glyph for position POS in OBJECT in
26570 window W's current matrix, and return in *X, *Y the pixel
26571 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26573 RIGHT_P non-zero means return the position of the right edge of the
26574 glyph, RIGHT_P zero means return the left edge position.
26576 If no glyph for POS exists in the matrix, return the position of
26577 the glyph with the next smaller position that is in the matrix, if
26578 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26579 exists in the matrix, return the position of the glyph with the
26580 next larger position in OBJECT.
26582 Value is non-zero if a glyph was found. */
26585 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26586 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26588 int yb
= window_text_bottom_y (w
);
26589 struct glyph_row
*r
;
26590 struct glyph
*best_glyph
= NULL
;
26591 struct glyph_row
*best_row
= NULL
;
26594 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26595 r
->enabled_p
&& r
->y
< yb
;
26598 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26599 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26602 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26603 if (EQ (g
->object
, object
))
26605 if (g
->charpos
== pos
)
26612 else if (best_glyph
== NULL
26613 || ((eabs (g
->charpos
- pos
)
26614 < eabs (best_glyph
->charpos
- pos
))
26617 : g
->charpos
> pos
)))
26631 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26635 *x
+= best_glyph
->pixel_width
;
26640 *vpos
= best_row
- w
->current_matrix
->rows
;
26643 return best_glyph
!= NULL
;
26645 #endif /* not used */
26647 /* Find the positions of the first and the last glyphs in window W's
26648 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26649 (assumed to be a string), and return in HLINFO's mouse_face_*
26650 members the pixel and column/row coordinates of those glyphs. */
26653 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26654 Lisp_Object object
,
26655 ptrdiff_t startpos
, ptrdiff_t endpos
)
26657 int yb
= window_text_bottom_y (w
);
26658 struct glyph_row
*r
;
26659 struct glyph
*g
, *e
;
26663 /* Find the glyph row with at least one position in the range
26664 [STARTPOS..ENDPOS], and the first glyph in that row whose
26665 position belongs to that range. */
26666 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26667 r
->enabled_p
&& r
->y
< yb
;
26670 if (!r
->reversed_p
)
26672 g
= r
->glyphs
[TEXT_AREA
];
26673 e
= g
+ r
->used
[TEXT_AREA
];
26674 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26675 if (EQ (g
->object
, object
)
26676 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26678 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26679 hlinfo
->mouse_face_beg_y
= r
->y
;
26680 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26681 hlinfo
->mouse_face_beg_x
= gx
;
26690 e
= r
->glyphs
[TEXT_AREA
];
26691 g
= e
+ r
->used
[TEXT_AREA
];
26692 for ( ; g
> e
; --g
)
26693 if (EQ ((g
-1)->object
, object
)
26694 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26696 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26697 hlinfo
->mouse_face_beg_y
= r
->y
;
26698 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26699 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26700 gx
+= g1
->pixel_width
;
26701 hlinfo
->mouse_face_beg_x
= gx
;
26713 /* Starting with the next row, look for the first row which does NOT
26714 include any glyphs whose positions are in the range. */
26715 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26717 g
= r
->glyphs
[TEXT_AREA
];
26718 e
= g
+ r
->used
[TEXT_AREA
];
26720 for ( ; g
< e
; ++g
)
26721 if (EQ (g
->object
, object
)
26722 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26731 /* The highlighted region ends on the previous row. */
26734 /* Set the end row and its vertical pixel coordinate. */
26735 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26736 hlinfo
->mouse_face_end_y
= r
->y
;
26738 /* Compute and set the end column and the end column's horizontal
26739 pixel coordinate. */
26740 if (!r
->reversed_p
)
26742 g
= r
->glyphs
[TEXT_AREA
];
26743 e
= g
+ r
->used
[TEXT_AREA
];
26744 for ( ; e
> g
; --e
)
26745 if (EQ ((e
-1)->object
, object
)
26746 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26748 hlinfo
->mouse_face_end_col
= e
- g
;
26750 for (gx
= r
->x
; g
< e
; ++g
)
26751 gx
+= g
->pixel_width
;
26752 hlinfo
->mouse_face_end_x
= gx
;
26756 e
= r
->glyphs
[TEXT_AREA
];
26757 g
= e
+ r
->used
[TEXT_AREA
];
26758 for (gx
= r
->x
; e
< g
; ++e
)
26760 if (EQ (e
->object
, object
)
26761 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26763 gx
+= e
->pixel_width
;
26765 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26766 hlinfo
->mouse_face_end_x
= gx
;
26770 #ifdef HAVE_WINDOW_SYSTEM
26772 /* See if position X, Y is within a hot-spot of an image. */
26775 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26777 if (!CONSP (hot_spot
))
26780 if (EQ (XCAR (hot_spot
), Qrect
))
26782 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26783 Lisp_Object rect
= XCDR (hot_spot
);
26787 if (!CONSP (XCAR (rect
)))
26789 if (!CONSP (XCDR (rect
)))
26791 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26793 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26795 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26797 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26801 else if (EQ (XCAR (hot_spot
), Qcircle
))
26803 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26804 Lisp_Object circ
= XCDR (hot_spot
);
26805 Lisp_Object lr
, lx0
, ly0
;
26807 && CONSP (XCAR (circ
))
26808 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26809 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26810 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26812 double r
= XFLOATINT (lr
);
26813 double dx
= XINT (lx0
) - x
;
26814 double dy
= XINT (ly0
) - y
;
26815 return (dx
* dx
+ dy
* dy
<= r
* r
);
26818 else if (EQ (XCAR (hot_spot
), Qpoly
))
26820 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26821 if (VECTORP (XCDR (hot_spot
)))
26823 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26824 Lisp_Object
*poly
= v
->contents
;
26825 ptrdiff_t n
= v
->header
.size
;
26828 Lisp_Object lx
, ly
;
26831 /* Need an even number of coordinates, and at least 3 edges. */
26832 if (n
< 6 || n
& 1)
26835 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26836 If count is odd, we are inside polygon. Pixels on edges
26837 may or may not be included depending on actual geometry of the
26839 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26840 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26842 x0
= XINT (lx
), y0
= XINT (ly
);
26843 for (i
= 0; i
< n
; i
+= 2)
26845 int x1
= x0
, y1
= y0
;
26846 if ((lx
= poly
[i
], !INTEGERP (lx
))
26847 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26849 x0
= XINT (lx
), y0
= XINT (ly
);
26851 /* Does this segment cross the X line? */
26859 if (y
> y0
&& y
> y1
)
26861 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26871 find_hot_spot (Lisp_Object map
, int x
, int y
)
26873 while (CONSP (map
))
26875 if (CONSP (XCAR (map
))
26876 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26884 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26886 doc
: /* Lookup in image map MAP coordinates X and Y.
26887 An image map is an alist where each element has the format (AREA ID PLIST).
26888 An AREA is specified as either a rectangle, a circle, or a polygon:
26889 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26890 pixel coordinates of the upper left and bottom right corners.
26891 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26892 and the radius of the circle; r may be a float or integer.
26893 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26894 vector describes one corner in the polygon.
26895 Returns the alist element for the first matching AREA in MAP. */)
26896 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26904 return find_hot_spot (map
,
26905 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
26906 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
26910 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26912 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26914 /* Do not change cursor shape while dragging mouse. */
26915 if (!NILP (do_mouse_tracking
))
26918 if (!NILP (pointer
))
26920 if (EQ (pointer
, Qarrow
))
26921 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26922 else if (EQ (pointer
, Qhand
))
26923 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
26924 else if (EQ (pointer
, Qtext
))
26925 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26926 else if (EQ (pointer
, intern ("hdrag")))
26927 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26928 #ifdef HAVE_X_WINDOWS
26929 else if (EQ (pointer
, intern ("vdrag")))
26930 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
26932 else if (EQ (pointer
, intern ("hourglass")))
26933 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
26934 else if (EQ (pointer
, Qmodeline
))
26935 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
26937 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26940 if (cursor
!= No_Cursor
)
26941 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
26944 #endif /* HAVE_WINDOW_SYSTEM */
26946 /* Take proper action when mouse has moved to the mode or header line
26947 or marginal area AREA of window W, x-position X and y-position Y.
26948 X is relative to the start of the text display area of W, so the
26949 width of bitmap areas and scroll bars must be subtracted to get a
26950 position relative to the start of the mode line. */
26953 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
26954 enum window_part area
)
26956 struct window
*w
= XWINDOW (window
);
26957 struct frame
*f
= XFRAME (w
->frame
);
26958 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26959 #ifdef HAVE_WINDOW_SYSTEM
26960 Display_Info
*dpyinfo
;
26962 Cursor cursor
= No_Cursor
;
26963 Lisp_Object pointer
= Qnil
;
26964 int dx
, dy
, width
, height
;
26966 Lisp_Object string
, object
= Qnil
;
26967 Lisp_Object pos
, help
;
26969 Lisp_Object mouse_face
;
26970 int original_x_pixel
= x
;
26971 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
26972 struct glyph_row
*row
;
26974 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
26979 /* Kludge alert: mode_line_string takes X/Y in pixels, but
26980 returns them in row/column units! */
26981 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
26982 &object
, &dx
, &dy
, &width
, &height
);
26984 row
= (area
== ON_MODE_LINE
26985 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
26986 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
26988 /* Find the glyph under the mouse pointer. */
26989 if (row
->mode_line_p
&& row
->enabled_p
)
26991 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
26992 end
= glyph
+ row
->used
[TEXT_AREA
];
26994 for (x0
= original_x_pixel
;
26995 glyph
< end
&& x0
>= glyph
->pixel_width
;
26997 x0
-= glyph
->pixel_width
;
27005 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27006 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27007 returns them in row/column units! */
27008 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27009 &object
, &dx
, &dy
, &width
, &height
);
27014 #ifdef HAVE_WINDOW_SYSTEM
27015 if (IMAGEP (object
))
27017 Lisp_Object image_map
, hotspot
;
27018 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27020 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27022 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27026 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27027 If so, we could look for mouse-enter, mouse-leave
27028 properties in PLIST (and do something...). */
27029 hotspot
= XCDR (hotspot
);
27030 if (CONSP (hotspot
)
27031 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27033 pointer
= Fplist_get (plist
, Qpointer
);
27034 if (NILP (pointer
))
27036 help
= Fplist_get (plist
, Qhelp_echo
);
27039 help_echo_string
= help
;
27040 /* Is this correct? ++kfs */
27041 XSETWINDOW (help_echo_window
, w
);
27042 help_echo_object
= w
->buffer
;
27043 help_echo_pos
= charpos
;
27047 if (NILP (pointer
))
27048 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27050 #endif /* HAVE_WINDOW_SYSTEM */
27052 if (STRINGP (string
))
27054 pos
= make_number (charpos
);
27055 /* If we're on a string with `help-echo' text property, arrange
27056 for the help to be displayed. This is done by setting the
27057 global variable help_echo_string to the help string. */
27060 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27063 help_echo_string
= help
;
27064 XSETWINDOW (help_echo_window
, w
);
27065 help_echo_object
= string
;
27066 help_echo_pos
= charpos
;
27070 #ifdef HAVE_WINDOW_SYSTEM
27071 if (FRAME_WINDOW_P (f
))
27073 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27074 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27075 if (NILP (pointer
))
27076 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27078 /* Change the mouse pointer according to what is under X/Y. */
27080 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27083 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27084 if (!KEYMAPP (map
))
27085 map
= Fget_text_property (pos
, Qkeymap
, string
);
27086 if (!KEYMAPP (map
))
27087 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27092 /* Change the mouse face according to what is under X/Y. */
27093 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27094 if (!NILP (mouse_face
)
27095 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27100 struct glyph
* tmp_glyph
;
27104 int total_pixel_width
;
27105 ptrdiff_t begpos
, endpos
, ignore
;
27109 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27110 Qmouse_face
, string
, Qnil
);
27116 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27118 endpos
= SCHARS (string
);
27122 /* Calculate the glyph position GPOS of GLYPH in the
27123 displayed string, relative to the beginning of the
27124 highlighted part of the string.
27126 Note: GPOS is different from CHARPOS. CHARPOS is the
27127 position of GLYPH in the internal string object. A mode
27128 line string format has structures which are converted to
27129 a flattened string by the Emacs Lisp interpreter. The
27130 internal string is an element of those structures. The
27131 displayed string is the flattened string. */
27132 tmp_glyph
= row_start_glyph
;
27133 while (tmp_glyph
< glyph
27134 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27135 && begpos
<= tmp_glyph
->charpos
27136 && tmp_glyph
->charpos
< endpos
)))
27138 gpos
= glyph
- tmp_glyph
;
27140 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27141 the highlighted part of the displayed string to which
27142 GLYPH belongs. Note: GSEQ_LENGTH is different from
27143 SCHARS (STRING), because the latter returns the length of
27144 the internal string. */
27145 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27147 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27148 && begpos
<= tmp_glyph
->charpos
27149 && tmp_glyph
->charpos
< endpos
));
27152 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27154 /* Calculate the total pixel width of all the glyphs between
27155 the beginning of the highlighted area and GLYPH. */
27156 total_pixel_width
= 0;
27157 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27158 total_pixel_width
+= tmp_glyph
->pixel_width
;
27160 /* Pre calculation of re-rendering position. Note: X is in
27161 column units here, after the call to mode_line_string or
27162 marginal_area_string. */
27164 vpos
= (area
== ON_MODE_LINE
27165 ? (w
->current_matrix
)->nrows
- 1
27168 /* If GLYPH's position is included in the region that is
27169 already drawn in mouse face, we have nothing to do. */
27170 if ( EQ (window
, hlinfo
->mouse_face_window
)
27171 && (!row
->reversed_p
27172 ? (hlinfo
->mouse_face_beg_col
<= hpos
27173 && hpos
< hlinfo
->mouse_face_end_col
)
27174 /* In R2L rows we swap BEG and END, see below. */
27175 : (hlinfo
->mouse_face_end_col
<= hpos
27176 && hpos
< hlinfo
->mouse_face_beg_col
))
27177 && hlinfo
->mouse_face_beg_row
== vpos
)
27180 if (clear_mouse_face (hlinfo
))
27181 cursor
= No_Cursor
;
27183 if (!row
->reversed_p
)
27185 hlinfo
->mouse_face_beg_col
= hpos
;
27186 hlinfo
->mouse_face_beg_x
= original_x_pixel
27187 - (total_pixel_width
+ dx
);
27188 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27189 hlinfo
->mouse_face_end_x
= 0;
27193 /* In R2L rows, show_mouse_face expects BEG and END
27194 coordinates to be swapped. */
27195 hlinfo
->mouse_face_end_col
= hpos
;
27196 hlinfo
->mouse_face_end_x
= original_x_pixel
27197 - (total_pixel_width
+ dx
);
27198 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27199 hlinfo
->mouse_face_beg_x
= 0;
27202 hlinfo
->mouse_face_beg_row
= vpos
;
27203 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27204 hlinfo
->mouse_face_beg_y
= 0;
27205 hlinfo
->mouse_face_end_y
= 0;
27206 hlinfo
->mouse_face_past_end
= 0;
27207 hlinfo
->mouse_face_window
= window
;
27209 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27215 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27217 if (NILP (pointer
))
27220 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27221 clear_mouse_face (hlinfo
);
27223 #ifdef HAVE_WINDOW_SYSTEM
27224 if (FRAME_WINDOW_P (f
))
27225 define_frame_cursor1 (f
, cursor
, pointer
);
27231 Take proper action when the mouse has moved to position X, Y on
27232 frame F as regards highlighting characters that have mouse-face
27233 properties. Also de-highlighting chars where the mouse was before.
27234 X and Y can be negative or out of range. */
27237 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27239 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27240 enum window_part part
= ON_NOTHING
;
27241 Lisp_Object window
;
27243 Cursor cursor
= No_Cursor
;
27244 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27247 /* When a menu is active, don't highlight because this looks odd. */
27248 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27249 if (popup_activated ())
27253 if (NILP (Vmouse_highlight
)
27254 || !f
->glyphs_initialized_p
27255 || f
->pointer_invisible
)
27258 hlinfo
->mouse_face_mouse_x
= x
;
27259 hlinfo
->mouse_face_mouse_y
= y
;
27260 hlinfo
->mouse_face_mouse_frame
= f
;
27262 if (hlinfo
->mouse_face_defer
)
27265 if (gc_in_progress
)
27267 hlinfo
->mouse_face_deferred_gc
= 1;
27271 /* Which window is that in? */
27272 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27274 /* If displaying active text in another window, clear that. */
27275 if (! EQ (window
, hlinfo
->mouse_face_window
)
27276 /* Also clear if we move out of text area in same window. */
27277 || (!NILP (hlinfo
->mouse_face_window
)
27280 && part
!= ON_MODE_LINE
27281 && part
!= ON_HEADER_LINE
))
27282 clear_mouse_face (hlinfo
);
27284 /* Not on a window -> return. */
27285 if (!WINDOWP (window
))
27288 /* Reset help_echo_string. It will get recomputed below. */
27289 help_echo_string
= Qnil
;
27291 /* Convert to window-relative pixel coordinates. */
27292 w
= XWINDOW (window
);
27293 frame_to_window_pixel_xy (w
, &x
, &y
);
27295 #ifdef HAVE_WINDOW_SYSTEM
27296 /* Handle tool-bar window differently since it doesn't display a
27298 if (EQ (window
, f
->tool_bar_window
))
27300 note_tool_bar_highlight (f
, x
, y
);
27305 /* Mouse is on the mode, header line or margin? */
27306 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27307 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27309 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27313 #ifdef HAVE_WINDOW_SYSTEM
27314 if (part
== ON_VERTICAL_BORDER
)
27316 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27317 help_echo_string
= build_string ("drag-mouse-1: resize");
27319 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27320 || part
== ON_SCROLL_BAR
)
27321 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27323 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27326 /* Are we in a window whose display is up to date?
27327 And verify the buffer's text has not changed. */
27328 b
= XBUFFER (w
->buffer
);
27329 if (part
== ON_TEXT
27330 && EQ (w
->window_end_valid
, w
->buffer
)
27331 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
27332 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
27334 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27336 struct glyph
*glyph
;
27337 Lisp_Object object
;
27338 Lisp_Object mouse_face
= Qnil
, position
;
27339 Lisp_Object
*overlay_vec
= NULL
;
27340 ptrdiff_t i
, noverlays
;
27341 struct buffer
*obuf
;
27342 ptrdiff_t obegv
, ozv
;
27345 /* Find the glyph under X/Y. */
27346 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27348 #ifdef HAVE_WINDOW_SYSTEM
27349 /* Look for :pointer property on image. */
27350 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27352 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27353 if (img
!= NULL
&& IMAGEP (img
->spec
))
27355 Lisp_Object image_map
, hotspot
;
27356 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27358 && (hotspot
= find_hot_spot (image_map
,
27359 glyph
->slice
.img
.x
+ dx
,
27360 glyph
->slice
.img
.y
+ dy
),
27362 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27366 /* Could check XCAR (hotspot) to see if we enter/leave
27368 If so, we could look for mouse-enter, mouse-leave
27369 properties in PLIST (and do something...). */
27370 hotspot
= XCDR (hotspot
);
27371 if (CONSP (hotspot
)
27372 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27374 pointer
= Fplist_get (plist
, Qpointer
);
27375 if (NILP (pointer
))
27377 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27378 if (!NILP (help_echo_string
))
27380 help_echo_window
= window
;
27381 help_echo_object
= glyph
->object
;
27382 help_echo_pos
= glyph
->charpos
;
27386 if (NILP (pointer
))
27387 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27390 #endif /* HAVE_WINDOW_SYSTEM */
27392 /* Clear mouse face if X/Y not over text. */
27394 || area
!= TEXT_AREA
27395 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27396 /* Glyph's OBJECT is an integer for glyphs inserted by the
27397 display engine for its internal purposes, like truncation
27398 and continuation glyphs and blanks beyond the end of
27399 line's text on text terminals. If we are over such a
27400 glyph, we are not over any text. */
27401 || INTEGERP (glyph
->object
)
27402 /* R2L rows have a stretch glyph at their front, which
27403 stands for no text, whereas L2R rows have no glyphs at
27404 all beyond the end of text. Treat such stretch glyphs
27405 like we do with NULL glyphs in L2R rows. */
27406 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27407 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27408 && glyph
->type
== STRETCH_GLYPH
27409 && glyph
->avoid_cursor_p
))
27411 if (clear_mouse_face (hlinfo
))
27412 cursor
= No_Cursor
;
27413 #ifdef HAVE_WINDOW_SYSTEM
27414 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27416 if (area
!= TEXT_AREA
)
27417 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27419 pointer
= Vvoid_text_area_pointer
;
27425 pos
= glyph
->charpos
;
27426 object
= glyph
->object
;
27427 if (!STRINGP (object
) && !BUFFERP (object
))
27430 /* If we get an out-of-range value, return now; avoid an error. */
27431 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27434 /* Make the window's buffer temporarily current for
27435 overlays_at and compute_char_face. */
27436 obuf
= current_buffer
;
27437 current_buffer
= b
;
27443 /* Is this char mouse-active or does it have help-echo? */
27444 position
= make_number (pos
);
27446 if (BUFFERP (object
))
27448 /* Put all the overlays we want in a vector in overlay_vec. */
27449 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27450 /* Sort overlays into increasing priority order. */
27451 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27456 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27459 cursor
= No_Cursor
;
27461 /* Check mouse-face highlighting. */
27463 /* If there exists an overlay with mouse-face overlapping
27464 the one we are currently highlighting, we have to
27465 check if we enter the overlapping overlay, and then
27466 highlight only that. */
27467 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27468 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27470 /* Find the highest priority overlay with a mouse-face. */
27471 Lisp_Object overlay
= Qnil
;
27472 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27474 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27475 if (!NILP (mouse_face
))
27476 overlay
= overlay_vec
[i
];
27479 /* If we're highlighting the same overlay as before, there's
27480 no need to do that again. */
27481 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27482 goto check_help_echo
;
27483 hlinfo
->mouse_face_overlay
= overlay
;
27485 /* Clear the display of the old active region, if any. */
27486 if (clear_mouse_face (hlinfo
))
27487 cursor
= No_Cursor
;
27489 /* If no overlay applies, get a text property. */
27490 if (NILP (overlay
))
27491 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27493 /* Next, compute the bounds of the mouse highlighting and
27495 if (!NILP (mouse_face
) && STRINGP (object
))
27497 /* The mouse-highlighting comes from a display string
27498 with a mouse-face. */
27502 s
= Fprevious_single_property_change
27503 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27504 e
= Fnext_single_property_change
27505 (position
, Qmouse_face
, object
, Qnil
);
27507 s
= make_number (0);
27509 e
= make_number (SCHARS (object
) - 1);
27510 mouse_face_from_string_pos (w
, hlinfo
, object
,
27511 XINT (s
), XINT (e
));
27512 hlinfo
->mouse_face_past_end
= 0;
27513 hlinfo
->mouse_face_window
= window
;
27514 hlinfo
->mouse_face_face_id
27515 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27516 glyph
->face_id
, 1);
27517 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27518 cursor
= No_Cursor
;
27522 /* The mouse-highlighting, if any, comes from an overlay
27523 or text property in the buffer. */
27524 Lisp_Object buffer
IF_LINT (= Qnil
);
27525 Lisp_Object disp_string
IF_LINT (= Qnil
);
27527 if (STRINGP (object
))
27529 /* If we are on a display string with no mouse-face,
27530 check if the text under it has one. */
27531 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27532 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27533 pos
= string_buffer_position (object
, start
);
27536 mouse_face
= get_char_property_and_overlay
27537 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27538 buffer
= w
->buffer
;
27539 disp_string
= object
;
27545 disp_string
= Qnil
;
27548 if (!NILP (mouse_face
))
27550 Lisp_Object before
, after
;
27551 Lisp_Object before_string
, after_string
;
27552 /* To correctly find the limits of mouse highlight
27553 in a bidi-reordered buffer, we must not use the
27554 optimization of limiting the search in
27555 previous-single-property-change and
27556 next-single-property-change, because
27557 rows_from_pos_range needs the real start and end
27558 positions to DTRT in this case. That's because
27559 the first row visible in a window does not
27560 necessarily display the character whose position
27561 is the smallest. */
27563 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27564 ? Fmarker_position (w
->start
)
27567 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27568 ? make_number (BUF_Z (XBUFFER (buffer
))
27569 - XFASTINT (w
->window_end_pos
))
27572 if (NILP (overlay
))
27574 /* Handle the text property case. */
27575 before
= Fprevious_single_property_change
27576 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27577 after
= Fnext_single_property_change
27578 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27579 before_string
= after_string
= Qnil
;
27583 /* Handle the overlay case. */
27584 before
= Foverlay_start (overlay
);
27585 after
= Foverlay_end (overlay
);
27586 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27587 after_string
= Foverlay_get (overlay
, Qafter_string
);
27589 if (!STRINGP (before_string
)) before_string
= Qnil
;
27590 if (!STRINGP (after_string
)) after_string
= Qnil
;
27593 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27596 : XFASTINT (before
),
27598 ? BUF_Z (XBUFFER (buffer
))
27599 : XFASTINT (after
),
27600 before_string
, after_string
,
27602 cursor
= No_Cursor
;
27609 /* Look for a `help-echo' property. */
27610 if (NILP (help_echo_string
)) {
27611 Lisp_Object help
, overlay
;
27613 /* Check overlays first. */
27614 help
= overlay
= Qnil
;
27615 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27617 overlay
= overlay_vec
[i
];
27618 help
= Foverlay_get (overlay
, Qhelp_echo
);
27623 help_echo_string
= help
;
27624 help_echo_window
= window
;
27625 help_echo_object
= overlay
;
27626 help_echo_pos
= pos
;
27630 Lisp_Object obj
= glyph
->object
;
27631 ptrdiff_t charpos
= glyph
->charpos
;
27633 /* Try text properties. */
27636 && charpos
< SCHARS (obj
))
27638 help
= Fget_text_property (make_number (charpos
),
27642 /* If the string itself doesn't specify a help-echo,
27643 see if the buffer text ``under'' it does. */
27644 struct glyph_row
*r
27645 = MATRIX_ROW (w
->current_matrix
, vpos
);
27646 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27647 ptrdiff_t p
= string_buffer_position (obj
, start
);
27650 help
= Fget_char_property (make_number (p
),
27651 Qhelp_echo
, w
->buffer
);
27660 else if (BUFFERP (obj
)
27663 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27668 help_echo_string
= help
;
27669 help_echo_window
= window
;
27670 help_echo_object
= obj
;
27671 help_echo_pos
= charpos
;
27676 #ifdef HAVE_WINDOW_SYSTEM
27677 /* Look for a `pointer' property. */
27678 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27680 /* Check overlays first. */
27681 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27682 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27684 if (NILP (pointer
))
27686 Lisp_Object obj
= glyph
->object
;
27687 ptrdiff_t charpos
= glyph
->charpos
;
27689 /* Try text properties. */
27692 && charpos
< SCHARS (obj
))
27694 pointer
= Fget_text_property (make_number (charpos
),
27696 if (NILP (pointer
))
27698 /* If the string itself doesn't specify a pointer,
27699 see if the buffer text ``under'' it does. */
27700 struct glyph_row
*r
27701 = MATRIX_ROW (w
->current_matrix
, vpos
);
27702 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27703 ptrdiff_t p
= string_buffer_position (obj
, start
);
27705 pointer
= Fget_char_property (make_number (p
),
27706 Qpointer
, w
->buffer
);
27709 else if (BUFFERP (obj
)
27712 pointer
= Fget_text_property (make_number (charpos
),
27716 #endif /* HAVE_WINDOW_SYSTEM */
27720 current_buffer
= obuf
;
27725 #ifdef HAVE_WINDOW_SYSTEM
27726 if (FRAME_WINDOW_P (f
))
27727 define_frame_cursor1 (f
, cursor
, pointer
);
27729 /* This is here to prevent a compiler error, about "label at end of
27730 compound statement". */
27737 Clear any mouse-face on window W. This function is part of the
27738 redisplay interface, and is called from try_window_id and similar
27739 functions to ensure the mouse-highlight is off. */
27742 x_clear_window_mouse_face (struct window
*w
)
27744 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27745 Lisp_Object window
;
27748 XSETWINDOW (window
, w
);
27749 if (EQ (window
, hlinfo
->mouse_face_window
))
27750 clear_mouse_face (hlinfo
);
27756 Just discard the mouse face information for frame F, if any.
27757 This is used when the size of F is changed. */
27760 cancel_mouse_face (struct frame
*f
)
27762 Lisp_Object window
;
27763 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27765 window
= hlinfo
->mouse_face_window
;
27766 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27768 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27769 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27770 hlinfo
->mouse_face_window
= Qnil
;
27776 /***********************************************************************
27778 ***********************************************************************/
27780 #ifdef HAVE_WINDOW_SYSTEM
27782 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27783 which intersects rectangle R. R is in window-relative coordinates. */
27786 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27787 enum glyph_row_area area
)
27789 struct glyph
*first
= row
->glyphs
[area
];
27790 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27791 struct glyph
*last
;
27792 int first_x
, start_x
, x
;
27794 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27795 /* If row extends face to end of line write the whole line. */
27796 draw_glyphs (w
, 0, row
, area
,
27797 0, row
->used
[area
],
27798 DRAW_NORMAL_TEXT
, 0);
27801 /* Set START_X to the window-relative start position for drawing glyphs of
27802 AREA. The first glyph of the text area can be partially visible.
27803 The first glyphs of other areas cannot. */
27804 start_x
= window_box_left_offset (w
, area
);
27806 if (area
== TEXT_AREA
)
27809 /* Find the first glyph that must be redrawn. */
27811 && x
+ first
->pixel_width
< r
->x
)
27813 x
+= first
->pixel_width
;
27817 /* Find the last one. */
27821 && x
< r
->x
+ r
->width
)
27823 x
+= last
->pixel_width
;
27829 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27830 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27831 DRAW_NORMAL_TEXT
, 0);
27836 /* Redraw the parts of the glyph row ROW on window W intersecting
27837 rectangle R. R is in window-relative coordinates. Value is
27838 non-zero if mouse-face was overwritten. */
27841 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27843 xassert (row
->enabled_p
);
27845 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27846 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27847 0, row
->used
[TEXT_AREA
],
27848 DRAW_NORMAL_TEXT
, 0);
27851 if (row
->used
[LEFT_MARGIN_AREA
])
27852 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27853 if (row
->used
[TEXT_AREA
])
27854 expose_area (w
, row
, r
, TEXT_AREA
);
27855 if (row
->used
[RIGHT_MARGIN_AREA
])
27856 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27857 draw_row_fringe_bitmaps (w
, row
);
27860 return row
->mouse_face_p
;
27864 /* Redraw those parts of glyphs rows during expose event handling that
27865 overlap other rows. Redrawing of an exposed line writes over parts
27866 of lines overlapping that exposed line; this function fixes that.
27868 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27869 row in W's current matrix that is exposed and overlaps other rows.
27870 LAST_OVERLAPPING_ROW is the last such row. */
27873 expose_overlaps (struct window
*w
,
27874 struct glyph_row
*first_overlapping_row
,
27875 struct glyph_row
*last_overlapping_row
,
27878 struct glyph_row
*row
;
27880 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27881 if (row
->overlapping_p
)
27883 xassert (row
->enabled_p
&& !row
->mode_line_p
);
27886 if (row
->used
[LEFT_MARGIN_AREA
])
27887 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
27889 if (row
->used
[TEXT_AREA
])
27890 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
27892 if (row
->used
[RIGHT_MARGIN_AREA
])
27893 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
27899 /* Return non-zero if W's cursor intersects rectangle R. */
27902 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
27904 XRectangle cr
, result
;
27905 struct glyph
*cursor_glyph
;
27906 struct glyph_row
*row
;
27908 if (w
->phys_cursor
.vpos
>= 0
27909 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
27910 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
27912 && row
->cursor_in_fringe_p
)
27914 /* Cursor is in the fringe. */
27915 cr
.x
= window_box_right_offset (w
,
27916 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
27917 ? RIGHT_MARGIN_AREA
27920 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
27921 cr
.height
= row
->height
;
27922 return x_intersect_rectangles (&cr
, r
, &result
);
27925 cursor_glyph
= get_phys_cursor_glyph (w
);
27928 /* r is relative to W's box, but w->phys_cursor.x is relative
27929 to left edge of W's TEXT area. Adjust it. */
27930 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
27931 cr
.y
= w
->phys_cursor
.y
;
27932 cr
.width
= cursor_glyph
->pixel_width
;
27933 cr
.height
= w
->phys_cursor_height
;
27934 /* ++KFS: W32 version used W32-specific IntersectRect here, but
27935 I assume the effect is the same -- and this is portable. */
27936 return x_intersect_rectangles (&cr
, r
, &result
);
27938 /* If we don't understand the format, pretend we're not in the hot-spot. */
27944 Draw a vertical window border to the right of window W if W doesn't
27945 have vertical scroll bars. */
27948 x_draw_vertical_border (struct window
*w
)
27950 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27952 /* We could do better, if we knew what type of scroll-bar the adjacent
27953 windows (on either side) have... But we don't :-(
27954 However, I think this works ok. ++KFS 2003-04-25 */
27956 /* Redraw borders between horizontally adjacent windows. Don't
27957 do it for frames with vertical scroll bars because either the
27958 right scroll bar of a window, or the left scroll bar of its
27959 neighbor will suffice as a border. */
27960 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
27963 if (!WINDOW_RIGHTMOST_P (w
)
27964 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
27966 int x0
, x1
, y0
, y1
;
27968 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27971 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27974 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
27976 else if (!WINDOW_LEFTMOST_P (w
)
27977 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
27979 int x0
, x1
, y0
, y1
;
27981 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27984 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27987 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
27992 /* Redraw the part of window W intersection rectangle FR. Pixel
27993 coordinates in FR are frame-relative. Call this function with
27994 input blocked. Value is non-zero if the exposure overwrites
27998 expose_window (struct window
*w
, XRectangle
*fr
)
28000 struct frame
*f
= XFRAME (w
->frame
);
28002 int mouse_face_overwritten_p
= 0;
28004 /* If window is not yet fully initialized, do nothing. This can
28005 happen when toolkit scroll bars are used and a window is split.
28006 Reconfiguring the scroll bar will generate an expose for a newly
28008 if (w
->current_matrix
== NULL
)
28011 /* When we're currently updating the window, display and current
28012 matrix usually don't agree. Arrange for a thorough display
28014 if (w
== updated_window
)
28016 SET_FRAME_GARBAGED (f
);
28020 /* Frame-relative pixel rectangle of W. */
28021 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28022 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28023 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28024 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28026 if (x_intersect_rectangles (fr
, &wr
, &r
))
28028 int yb
= window_text_bottom_y (w
);
28029 struct glyph_row
*row
;
28030 int cursor_cleared_p
, phys_cursor_on_p
;
28031 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28033 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28034 r
.x
, r
.y
, r
.width
, r
.height
));
28036 /* Convert to window coordinates. */
28037 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28038 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28040 /* Turn off the cursor. */
28041 if (!w
->pseudo_window_p
28042 && phys_cursor_in_rect_p (w
, &r
))
28044 x_clear_cursor (w
);
28045 cursor_cleared_p
= 1;
28048 cursor_cleared_p
= 0;
28050 /* If the row containing the cursor extends face to end of line,
28051 then expose_area might overwrite the cursor outside the
28052 rectangle and thus notice_overwritten_cursor might clear
28053 w->phys_cursor_on_p. We remember the original value and
28054 check later if it is changed. */
28055 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28057 /* Update lines intersecting rectangle R. */
28058 first_overlapping_row
= last_overlapping_row
= NULL
;
28059 for (row
= w
->current_matrix
->rows
;
28064 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28066 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28067 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28068 || (r
.y
>= y0
&& r
.y
< y1
)
28069 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28071 /* A header line may be overlapping, but there is no need
28072 to fix overlapping areas for them. KFS 2005-02-12 */
28073 if (row
->overlapping_p
&& !row
->mode_line_p
)
28075 if (first_overlapping_row
== NULL
)
28076 first_overlapping_row
= row
;
28077 last_overlapping_row
= row
;
28081 if (expose_line (w
, row
, &r
))
28082 mouse_face_overwritten_p
= 1;
28085 else if (row
->overlapping_p
)
28087 /* We must redraw a row overlapping the exposed area. */
28089 ? y0
+ row
->phys_height
> r
.y
28090 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28092 if (first_overlapping_row
== NULL
)
28093 first_overlapping_row
= row
;
28094 last_overlapping_row
= row
;
28102 /* Display the mode line if there is one. */
28103 if (WINDOW_WANTS_MODELINE_P (w
)
28104 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28106 && row
->y
< r
.y
+ r
.height
)
28108 if (expose_line (w
, row
, &r
))
28109 mouse_face_overwritten_p
= 1;
28112 if (!w
->pseudo_window_p
)
28114 /* Fix the display of overlapping rows. */
28115 if (first_overlapping_row
)
28116 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28119 /* Draw border between windows. */
28120 x_draw_vertical_border (w
);
28122 /* Turn the cursor on again. */
28123 if (cursor_cleared_p
28124 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28125 update_window_cursor (w
, 1);
28129 return mouse_face_overwritten_p
;
28134 /* Redraw (parts) of all windows in the window tree rooted at W that
28135 intersect R. R contains frame pixel coordinates. Value is
28136 non-zero if the exposure overwrites mouse-face. */
28139 expose_window_tree (struct window
*w
, XRectangle
*r
)
28141 struct frame
*f
= XFRAME (w
->frame
);
28142 int mouse_face_overwritten_p
= 0;
28144 while (w
&& !FRAME_GARBAGED_P (f
))
28146 if (!NILP (w
->hchild
))
28147 mouse_face_overwritten_p
28148 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28149 else if (!NILP (w
->vchild
))
28150 mouse_face_overwritten_p
28151 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28153 mouse_face_overwritten_p
|= expose_window (w
, r
);
28155 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28158 return mouse_face_overwritten_p
;
28163 Redisplay an exposed area of frame F. X and Y are the upper-left
28164 corner of the exposed rectangle. W and H are width and height of
28165 the exposed area. All are pixel values. W or H zero means redraw
28166 the entire frame. */
28169 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28172 int mouse_face_overwritten_p
= 0;
28174 TRACE ((stderr
, "expose_frame "));
28176 /* No need to redraw if frame will be redrawn soon. */
28177 if (FRAME_GARBAGED_P (f
))
28179 TRACE ((stderr
, " garbaged\n"));
28183 /* If basic faces haven't been realized yet, there is no point in
28184 trying to redraw anything. This can happen when we get an expose
28185 event while Emacs is starting, e.g. by moving another window. */
28186 if (FRAME_FACE_CACHE (f
) == NULL
28187 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28189 TRACE ((stderr
, " no faces\n"));
28193 if (w
== 0 || h
== 0)
28196 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28197 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28207 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28208 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28210 if (WINDOWP (f
->tool_bar_window
))
28211 mouse_face_overwritten_p
28212 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28214 #ifdef HAVE_X_WINDOWS
28216 #ifndef USE_X_TOOLKIT
28217 if (WINDOWP (f
->menu_bar_window
))
28218 mouse_face_overwritten_p
28219 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28220 #endif /* not USE_X_TOOLKIT */
28224 /* Some window managers support a focus-follows-mouse style with
28225 delayed raising of frames. Imagine a partially obscured frame,
28226 and moving the mouse into partially obscured mouse-face on that
28227 frame. The visible part of the mouse-face will be highlighted,
28228 then the WM raises the obscured frame. With at least one WM, KDE
28229 2.1, Emacs is not getting any event for the raising of the frame
28230 (even tried with SubstructureRedirectMask), only Expose events.
28231 These expose events will draw text normally, i.e. not
28232 highlighted. Which means we must redo the highlight here.
28233 Subsume it under ``we love X''. --gerd 2001-08-15 */
28234 /* Included in Windows version because Windows most likely does not
28235 do the right thing if any third party tool offers
28236 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28237 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28239 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28240 if (f
== hlinfo
->mouse_face_mouse_frame
)
28242 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28243 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28244 clear_mouse_face (hlinfo
);
28245 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28252 Determine the intersection of two rectangles R1 and R2. Return
28253 the intersection in *RESULT. Value is non-zero if RESULT is not
28257 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28259 XRectangle
*left
, *right
;
28260 XRectangle
*upper
, *lower
;
28261 int intersection_p
= 0;
28263 /* Rearrange so that R1 is the left-most rectangle. */
28265 left
= r1
, right
= r2
;
28267 left
= r2
, right
= r1
;
28269 /* X0 of the intersection is right.x0, if this is inside R1,
28270 otherwise there is no intersection. */
28271 if (right
->x
<= left
->x
+ left
->width
)
28273 result
->x
= right
->x
;
28275 /* The right end of the intersection is the minimum of
28276 the right ends of left and right. */
28277 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28280 /* Same game for Y. */
28282 upper
= r1
, lower
= r2
;
28284 upper
= r2
, lower
= r1
;
28286 /* The upper end of the intersection is lower.y0, if this is inside
28287 of upper. Otherwise, there is no intersection. */
28288 if (lower
->y
<= upper
->y
+ upper
->height
)
28290 result
->y
= lower
->y
;
28292 /* The lower end of the intersection is the minimum of the lower
28293 ends of upper and lower. */
28294 result
->height
= (min (lower
->y
+ lower
->height
,
28295 upper
->y
+ upper
->height
)
28297 intersection_p
= 1;
28301 return intersection_p
;
28304 #endif /* HAVE_WINDOW_SYSTEM */
28307 /***********************************************************************
28309 ***********************************************************************/
28312 syms_of_xdisp (void)
28314 Vwith_echo_area_save_vector
= Qnil
;
28315 staticpro (&Vwith_echo_area_save_vector
);
28317 Vmessage_stack
= Qnil
;
28318 staticpro (&Vmessage_stack
);
28320 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28322 message_dolog_marker1
= Fmake_marker ();
28323 staticpro (&message_dolog_marker1
);
28324 message_dolog_marker2
= Fmake_marker ();
28325 staticpro (&message_dolog_marker2
);
28326 message_dolog_marker3
= Fmake_marker ();
28327 staticpro (&message_dolog_marker3
);
28330 defsubr (&Sdump_frame_glyph_matrix
);
28331 defsubr (&Sdump_glyph_matrix
);
28332 defsubr (&Sdump_glyph_row
);
28333 defsubr (&Sdump_tool_bar_row
);
28334 defsubr (&Strace_redisplay
);
28335 defsubr (&Strace_to_stderr
);
28337 #ifdef HAVE_WINDOW_SYSTEM
28338 defsubr (&Stool_bar_lines_needed
);
28339 defsubr (&Slookup_image_map
);
28341 defsubr (&Sformat_mode_line
);
28342 defsubr (&Sinvisible_p
);
28343 defsubr (&Scurrent_bidi_paragraph_direction
);
28345 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28346 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28347 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28348 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28349 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28350 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28351 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28352 DEFSYM (Qeval
, "eval");
28353 DEFSYM (QCdata
, ":data");
28354 DEFSYM (Qdisplay
, "display");
28355 DEFSYM (Qspace_width
, "space-width");
28356 DEFSYM (Qraise
, "raise");
28357 DEFSYM (Qslice
, "slice");
28358 DEFSYM (Qspace
, "space");
28359 DEFSYM (Qmargin
, "margin");
28360 DEFSYM (Qpointer
, "pointer");
28361 DEFSYM (Qleft_margin
, "left-margin");
28362 DEFSYM (Qright_margin
, "right-margin");
28363 DEFSYM (Qcenter
, "center");
28364 DEFSYM (Qline_height
, "line-height");
28365 DEFSYM (QCalign_to
, ":align-to");
28366 DEFSYM (QCrelative_width
, ":relative-width");
28367 DEFSYM (QCrelative_height
, ":relative-height");
28368 DEFSYM (QCeval
, ":eval");
28369 DEFSYM (QCpropertize
, ":propertize");
28370 DEFSYM (QCfile
, ":file");
28371 DEFSYM (Qfontified
, "fontified");
28372 DEFSYM (Qfontification_functions
, "fontification-functions");
28373 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28374 DEFSYM (Qescape_glyph
, "escape-glyph");
28375 DEFSYM (Qnobreak_space
, "nobreak-space");
28376 DEFSYM (Qimage
, "image");
28377 DEFSYM (Qtext
, "text");
28378 DEFSYM (Qboth
, "both");
28379 DEFSYM (Qboth_horiz
, "both-horiz");
28380 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28381 DEFSYM (QCmap
, ":map");
28382 DEFSYM (QCpointer
, ":pointer");
28383 DEFSYM (Qrect
, "rect");
28384 DEFSYM (Qcircle
, "circle");
28385 DEFSYM (Qpoly
, "poly");
28386 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28387 DEFSYM (Qgrow_only
, "grow-only");
28388 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28389 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28390 DEFSYM (Qposition
, "position");
28391 DEFSYM (Qbuffer_position
, "buffer-position");
28392 DEFSYM (Qobject
, "object");
28393 DEFSYM (Qbar
, "bar");
28394 DEFSYM (Qhbar
, "hbar");
28395 DEFSYM (Qbox
, "box");
28396 DEFSYM (Qhollow
, "hollow");
28397 DEFSYM (Qhand
, "hand");
28398 DEFSYM (Qarrow
, "arrow");
28399 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28401 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28402 Fcons (intern_c_string ("void-variable"), Qnil
)),
28404 staticpro (&list_of_error
);
28406 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28407 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28408 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28409 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28411 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28412 staticpro (&echo_buffer
[0]);
28413 staticpro (&echo_buffer
[1]);
28415 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28416 staticpro (&echo_area_buffer
[0]);
28417 staticpro (&echo_area_buffer
[1]);
28419 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28420 staticpro (&Vmessages_buffer_name
);
28422 mode_line_proptrans_alist
= Qnil
;
28423 staticpro (&mode_line_proptrans_alist
);
28424 mode_line_string_list
= Qnil
;
28425 staticpro (&mode_line_string_list
);
28426 mode_line_string_face
= Qnil
;
28427 staticpro (&mode_line_string_face
);
28428 mode_line_string_face_prop
= Qnil
;
28429 staticpro (&mode_line_string_face_prop
);
28430 Vmode_line_unwind_vector
= Qnil
;
28431 staticpro (&Vmode_line_unwind_vector
);
28433 help_echo_string
= Qnil
;
28434 staticpro (&help_echo_string
);
28435 help_echo_object
= Qnil
;
28436 staticpro (&help_echo_object
);
28437 help_echo_window
= Qnil
;
28438 staticpro (&help_echo_window
);
28439 previous_help_echo_string
= Qnil
;
28440 staticpro (&previous_help_echo_string
);
28441 help_echo_pos
= -1;
28443 DEFSYM (Qright_to_left
, "right-to-left");
28444 DEFSYM (Qleft_to_right
, "left-to-right");
28446 #ifdef HAVE_WINDOW_SYSTEM
28447 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28448 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28449 For example, if a block cursor is over a tab, it will be drawn as
28450 wide as that tab on the display. */);
28451 x_stretch_cursor_p
= 0;
28454 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28455 doc
: /* Non-nil means highlight trailing whitespace.
28456 The face used for trailing whitespace is `trailing-whitespace'. */);
28457 Vshow_trailing_whitespace
= Qnil
;
28459 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28460 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28461 If the value is t, Emacs highlights non-ASCII chars which have the
28462 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28463 or `escape-glyph' face respectively.
28465 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28466 U+2011 (non-breaking hyphen) are affected.
28468 Any other non-nil value means to display these characters as a escape
28469 glyph followed by an ordinary space or hyphen.
28471 A value of nil means no special handling of these characters. */);
28472 Vnobreak_char_display
= Qt
;
28474 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28475 doc
: /* The pointer shape to show in void text areas.
28476 A value of nil means to show the text pointer. Other options are `arrow',
28477 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28478 Vvoid_text_area_pointer
= Qarrow
;
28480 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28481 doc
: /* Non-nil means don't actually do any redisplay.
28482 This is used for internal purposes. */);
28483 Vinhibit_redisplay
= Qnil
;
28485 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28486 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28487 Vglobal_mode_string
= Qnil
;
28489 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28490 doc
: /* Marker for where to display an arrow on top of the buffer text.
28491 This must be the beginning of a line in order to work.
28492 See also `overlay-arrow-string'. */);
28493 Voverlay_arrow_position
= Qnil
;
28495 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28496 doc
: /* String to display as an arrow in non-window frames.
28497 See also `overlay-arrow-position'. */);
28498 Voverlay_arrow_string
= make_pure_c_string ("=>");
28500 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28501 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28502 The symbols on this list are examined during redisplay to determine
28503 where to display overlay arrows. */);
28504 Voverlay_arrow_variable_list
28505 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28507 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28508 doc
: /* The number of lines to try scrolling a window by when point moves out.
28509 If that fails to bring point back on frame, point is centered instead.
28510 If this is zero, point is always centered after it moves off frame.
28511 If you want scrolling to always be a line at a time, you should set
28512 `scroll-conservatively' to a large value rather than set this to 1. */);
28514 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28515 doc
: /* Scroll up to this many lines, to bring point back on screen.
28516 If point moves off-screen, redisplay will scroll by up to
28517 `scroll-conservatively' lines in order to bring point just barely
28518 onto the screen again. If that cannot be done, then redisplay
28519 recenters point as usual.
28521 If the value is greater than 100, redisplay will never recenter point,
28522 but will always scroll just enough text to bring point into view, even
28523 if you move far away.
28525 A value of zero means always recenter point if it moves off screen. */);
28526 scroll_conservatively
= 0;
28528 DEFVAR_INT ("scroll-margin", scroll_margin
,
28529 doc
: /* Number of lines of margin at the top and bottom of a window.
28530 Recenter the window whenever point gets within this many lines
28531 of the top or bottom of the window. */);
28534 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28535 doc
: /* Pixels per inch value for non-window system displays.
28536 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28537 Vdisplay_pixels_per_inch
= make_float (72.0);
28540 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28543 DEFVAR_LISP ("truncate-partial-width-windows",
28544 Vtruncate_partial_width_windows
,
28545 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28546 For an integer value, truncate lines in each window narrower than the
28547 full frame width, provided the window width is less than that integer;
28548 otherwise, respect the value of `truncate-lines'.
28550 For any other non-nil value, truncate lines in all windows that do
28551 not span the full frame width.
28553 A value of nil means to respect the value of `truncate-lines'.
28555 If `word-wrap' is enabled, you might want to reduce this. */);
28556 Vtruncate_partial_width_windows
= make_number (50);
28558 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28559 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28560 Any other value means to use the appropriate face, `mode-line',
28561 `header-line', or `menu' respectively. */);
28562 mode_line_inverse_video
= 1;
28564 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28565 doc
: /* Maximum buffer size for which line number should be displayed.
28566 If the buffer is bigger than this, the line number does not appear
28567 in the mode line. A value of nil means no limit. */);
28568 Vline_number_display_limit
= Qnil
;
28570 DEFVAR_INT ("line-number-display-limit-width",
28571 line_number_display_limit_width
,
28572 doc
: /* Maximum line width (in characters) for line number display.
28573 If the average length of the lines near point is bigger than this, then the
28574 line number may be omitted from the mode line. */);
28575 line_number_display_limit_width
= 200;
28577 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28578 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28579 highlight_nonselected_windows
= 0;
28581 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28582 doc
: /* Non-nil if more than one frame is visible on this display.
28583 Minibuffer-only frames don't count, but iconified frames do.
28584 This variable is not guaranteed to be accurate except while processing
28585 `frame-title-format' and `icon-title-format'. */);
28587 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28588 doc
: /* Template for displaying the title bar of visible frames.
28589 \(Assuming the window manager supports this feature.)
28591 This variable has the same structure as `mode-line-format', except that
28592 the %c and %l constructs are ignored. It is used only on frames for
28593 which no explicit name has been set \(see `modify-frame-parameters'). */);
28595 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28596 doc
: /* Template for displaying the title bar of an iconified frame.
28597 \(Assuming the window manager supports this feature.)
28598 This variable has the same structure as `mode-line-format' (which see),
28599 and is used only on frames for which no explicit name has been set
28600 \(see `modify-frame-parameters'). */);
28602 = Vframe_title_format
28603 = pure_cons (intern_c_string ("multiple-frames"),
28604 pure_cons (make_pure_c_string ("%b"),
28605 pure_cons (pure_cons (empty_unibyte_string
,
28606 pure_cons (intern_c_string ("invocation-name"),
28607 pure_cons (make_pure_c_string ("@"),
28608 pure_cons (intern_c_string ("system-name"),
28612 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28613 doc
: /* Maximum number of lines to keep in the message log buffer.
28614 If nil, disable message logging. If t, log messages but don't truncate
28615 the buffer when it becomes large. */);
28616 Vmessage_log_max
= make_number (100);
28618 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28619 doc
: /* Functions called before redisplay, if window sizes have changed.
28620 The value should be a list of functions that take one argument.
28621 Just before redisplay, for each frame, if any of its windows have changed
28622 size since the last redisplay, or have been split or deleted,
28623 all the functions in the list are called, with the frame as argument. */);
28624 Vwindow_size_change_functions
= Qnil
;
28626 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28627 doc
: /* List of functions to call before redisplaying a window with scrolling.
28628 Each function is called with two arguments, the window and its new
28629 display-start position. Note that these functions are also called by
28630 `set-window-buffer'. Also note that the value of `window-end' is not
28631 valid when these functions are called.
28633 Warning: Do not use this feature to alter the way the window
28634 is scrolled. It is not designed for that, and such use probably won't
28636 Vwindow_scroll_functions
= Qnil
;
28638 DEFVAR_LISP ("window-text-change-functions",
28639 Vwindow_text_change_functions
,
28640 doc
: /* Functions to call in redisplay when text in the window might change. */);
28641 Vwindow_text_change_functions
= Qnil
;
28643 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28644 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28645 Each function is called with two arguments, the window and the end trigger value.
28646 See `set-window-redisplay-end-trigger'. */);
28647 Vredisplay_end_trigger_functions
= Qnil
;
28649 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28650 doc
: /* Non-nil means autoselect window with mouse pointer.
28651 If nil, do not autoselect windows.
28652 A positive number means delay autoselection by that many seconds: a
28653 window is autoselected only after the mouse has remained in that
28654 window for the duration of the delay.
28655 A negative number has a similar effect, but causes windows to be
28656 autoselected only after the mouse has stopped moving. \(Because of
28657 the way Emacs compares mouse events, you will occasionally wait twice
28658 that time before the window gets selected.\)
28659 Any other value means to autoselect window instantaneously when the
28660 mouse pointer enters it.
28662 Autoselection selects the minibuffer only if it is active, and never
28663 unselects the minibuffer if it is active.
28665 When customizing this variable make sure that the actual value of
28666 `focus-follows-mouse' matches the behavior of your window manager. */);
28667 Vmouse_autoselect_window
= Qnil
;
28669 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28670 doc
: /* Non-nil means automatically resize tool-bars.
28671 This dynamically changes the tool-bar's height to the minimum height
28672 that is needed to make all tool-bar items visible.
28673 If value is `grow-only', the tool-bar's height is only increased
28674 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28675 Vauto_resize_tool_bars
= Qt
;
28677 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28678 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28679 auto_raise_tool_bar_buttons_p
= 1;
28681 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28682 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28683 make_cursor_line_fully_visible_p
= 1;
28685 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28686 doc
: /* Border below tool-bar in pixels.
28687 If an integer, use it as the height of the border.
28688 If it is one of `internal-border-width' or `border-width', use the
28689 value of the corresponding frame parameter.
28690 Otherwise, no border is added below the tool-bar. */);
28691 Vtool_bar_border
= Qinternal_border_width
;
28693 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28694 doc
: /* Margin around tool-bar buttons in pixels.
28695 If an integer, use that for both horizontal and vertical margins.
28696 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28697 HORZ specifying the horizontal margin, and VERT specifying the
28698 vertical margin. */);
28699 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28701 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28702 doc
: /* Relief thickness of tool-bar buttons. */);
28703 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28705 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28706 doc
: /* Tool bar style to use.
28708 image - show images only
28709 text - show text only
28710 both - show both, text below image
28711 both-horiz - show text to the right of the image
28712 text-image-horiz - show text to the left of the image
28713 any other - use system default or image if no system default. */);
28714 Vtool_bar_style
= Qnil
;
28716 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28717 doc
: /* Maximum number of characters a label can have to be shown.
28718 The tool bar style must also show labels for this to have any effect, see
28719 `tool-bar-style'. */);
28720 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28722 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28723 doc
: /* List of functions to call to fontify regions of text.
28724 Each function is called with one argument POS. Functions must
28725 fontify a region starting at POS in the current buffer, and give
28726 fontified regions the property `fontified'. */);
28727 Vfontification_functions
= Qnil
;
28728 Fmake_variable_buffer_local (Qfontification_functions
);
28730 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28731 unibyte_display_via_language_environment
,
28732 doc
: /* Non-nil means display unibyte text according to language environment.
28733 Specifically, this means that raw bytes in the range 160-255 decimal
28734 are displayed by converting them to the equivalent multibyte characters
28735 according to the current language environment. As a result, they are
28736 displayed according to the current fontset.
28738 Note that this variable affects only how these bytes are displayed,
28739 but does not change the fact they are interpreted as raw bytes. */);
28740 unibyte_display_via_language_environment
= 0;
28742 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28743 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
28744 If a float, it specifies a fraction of the mini-window frame's height.
28745 If an integer, it specifies a number of lines. */);
28746 Vmax_mini_window_height
= make_float (0.25);
28748 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28749 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28750 A value of nil means don't automatically resize mini-windows.
28751 A value of t means resize them to fit the text displayed in them.
28752 A value of `grow-only', the default, means let mini-windows grow only;
28753 they return to their normal size when the minibuffer is closed, or the
28754 echo area becomes empty. */);
28755 Vresize_mini_windows
= Qgrow_only
;
28757 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28758 doc
: /* Alist specifying how to blink the cursor off.
28759 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28760 `cursor-type' frame-parameter or variable equals ON-STATE,
28761 comparing using `equal', Emacs uses OFF-STATE to specify
28762 how to blink it off. ON-STATE and OFF-STATE are values for
28763 the `cursor-type' frame parameter.
28765 If a frame's ON-STATE has no entry in this list,
28766 the frame's other specifications determine how to blink the cursor off. */);
28767 Vblink_cursor_alist
= Qnil
;
28769 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28770 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28771 If non-nil, windows are automatically scrolled horizontally to make
28772 point visible. */);
28773 automatic_hscrolling_p
= 1;
28774 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28776 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28777 doc
: /* How many columns away from the window edge point is allowed to get
28778 before automatic hscrolling will horizontally scroll the window. */);
28779 hscroll_margin
= 5;
28781 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28782 doc
: /* How many columns to scroll the window when point gets too close to the edge.
28783 When point is less than `hscroll-margin' columns from the window
28784 edge, automatic hscrolling will scroll the window by the amount of columns
28785 determined by this variable. If its value is a positive integer, scroll that
28786 many columns. If it's a positive floating-point number, it specifies the
28787 fraction of the window's width to scroll. If it's nil or zero, point will be
28788 centered horizontally after the scroll. Any other value, including negative
28789 numbers, are treated as if the value were zero.
28791 Automatic hscrolling always moves point outside the scroll margin, so if
28792 point was more than scroll step columns inside the margin, the window will
28793 scroll more than the value given by the scroll step.
28795 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28796 and `scroll-right' overrides this variable's effect. */);
28797 Vhscroll_step
= make_number (0);
28799 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28800 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28801 Bind this around calls to `message' to let it take effect. */);
28802 message_truncate_lines
= 0;
28804 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28805 doc
: /* Normal hook run to update the menu bar definitions.
28806 Redisplay runs this hook before it redisplays the menu bar.
28807 This is used to update submenus such as Buffers,
28808 whose contents depend on various data. */);
28809 Vmenu_bar_update_hook
= Qnil
;
28811 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28812 doc
: /* Frame for which we are updating a menu.
28813 The enable predicate for a menu binding should check this variable. */);
28814 Vmenu_updating_frame
= Qnil
;
28816 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28817 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28818 inhibit_menubar_update
= 0;
28820 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28821 doc
: /* Prefix prepended to all continuation lines at display time.
28822 The value may be a string, an image, or a stretch-glyph; it is
28823 interpreted in the same way as the value of a `display' text property.
28825 This variable is overridden by any `wrap-prefix' text or overlay
28828 To add a prefix to non-continuation lines, use `line-prefix'. */);
28829 Vwrap_prefix
= Qnil
;
28830 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28831 Fmake_variable_buffer_local (Qwrap_prefix
);
28833 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28834 doc
: /* Prefix prepended to all non-continuation lines at display time.
28835 The value may be a string, an image, or a stretch-glyph; it is
28836 interpreted in the same way as the value of a `display' text property.
28838 This variable is overridden by any `line-prefix' text or overlay
28841 To add a prefix to continuation lines, use `wrap-prefix'. */);
28842 Vline_prefix
= Qnil
;
28843 DEFSYM (Qline_prefix
, "line-prefix");
28844 Fmake_variable_buffer_local (Qline_prefix
);
28846 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28847 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28848 inhibit_eval_during_redisplay
= 0;
28850 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28851 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28852 inhibit_free_realized_faces
= 0;
28855 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28856 doc
: /* Inhibit try_window_id display optimization. */);
28857 inhibit_try_window_id
= 0;
28859 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28860 doc
: /* Inhibit try_window_reusing display optimization. */);
28861 inhibit_try_window_reusing
= 0;
28863 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28864 doc
: /* Inhibit try_cursor_movement display optimization. */);
28865 inhibit_try_cursor_movement
= 0;
28866 #endif /* GLYPH_DEBUG */
28868 DEFVAR_INT ("overline-margin", overline_margin
,
28869 doc
: /* Space between overline and text, in pixels.
28870 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28871 margin to the character height. */);
28872 overline_margin
= 2;
28874 DEFVAR_INT ("underline-minimum-offset",
28875 underline_minimum_offset
,
28876 doc
: /* Minimum distance between baseline and underline.
28877 This can improve legibility of underlined text at small font sizes,
28878 particularly when using variable `x-use-underline-position-properties'
28879 with fonts that specify an UNDERLINE_POSITION relatively close to the
28880 baseline. The default value is 1. */);
28881 underline_minimum_offset
= 1;
28883 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
28884 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
28885 This feature only works when on a window system that can change
28886 cursor shapes. */);
28887 display_hourglass_p
= 1;
28889 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
28890 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
28891 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
28893 hourglass_atimer
= NULL
;
28894 hourglass_shown_p
= 0;
28896 DEFSYM (Qglyphless_char
, "glyphless-char");
28897 DEFSYM (Qhex_code
, "hex-code");
28898 DEFSYM (Qempty_box
, "empty-box");
28899 DEFSYM (Qthin_space
, "thin-space");
28900 DEFSYM (Qzero_width
, "zero-width");
28902 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
28903 /* Intern this now in case it isn't already done.
28904 Setting this variable twice is harmless.
28905 But don't staticpro it here--that is done in alloc.c. */
28906 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
28907 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
28909 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
28910 doc
: /* Char-table defining glyphless characters.
28911 Each element, if non-nil, should be one of the following:
28912 an ASCII acronym string: display this string in a box
28913 `hex-code': display the hexadecimal code of a character in a box
28914 `empty-box': display as an empty box
28915 `thin-space': display as 1-pixel width space
28916 `zero-width': don't display
28917 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
28918 display method for graphical terminals and text terminals respectively.
28919 GRAPHICAL and TEXT should each have one of the values listed above.
28921 The char-table has one extra slot to control the display of a character for
28922 which no font is found. This slot only takes effect on graphical terminals.
28923 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
28924 `thin-space'. The default is `empty-box'. */);
28925 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
28926 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
28931 /* Initialize this module when Emacs starts. */
28936 current_header_line_height
= current_mode_line_height
= -1;
28938 CHARPOS (this_line_start_pos
) = 0;
28940 if (!noninteractive
)
28942 struct window
*m
= XWINDOW (minibuf_window
);
28943 Lisp_Object frame
= m
->frame
;
28944 struct frame
*f
= XFRAME (frame
);
28945 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
28946 struct window
*r
= XWINDOW (root
);
28949 echo_area_window
= minibuf_window
;
28951 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
28952 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
28953 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
28954 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
28955 XSETFASTINT (m
->total_lines
, 1);
28956 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
28958 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
28959 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
28960 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
28962 /* The default ellipsis glyphs `...'. */
28963 for (i
= 0; i
< 3; ++i
)
28964 default_invis_vector
[i
] = make_number ('.');
28968 /* Allocate the buffer for frame titles.
28969 Also used for `format-mode-line'. */
28971 mode_line_noprop_buf
= (char *) xmalloc (size
);
28972 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
28973 mode_line_noprop_ptr
= mode_line_noprop_buf
;
28974 mode_line_target
= MODE_LINE_DISPLAY
;
28977 help_echo_showing_p
= 0;
28980 /* Since w32 does not support atimers, it defines its own implementation of
28981 the following three functions in w32fns.c. */
28984 /* Platform-independent portion of hourglass implementation. */
28986 /* Cancel a currently active hourglass timer, and start a new one. */
28988 start_hourglass (void)
28990 #if defined (HAVE_WINDOW_SYSTEM)
28992 int secs
= DEFAULT_HOURGLASS_DELAY
, usecs
= 0;
28994 cancel_hourglass ();
28996 if (NUMBERP (Vhourglass_delay
))
28998 double duration
= extract_float (Vhourglass_delay
);
29000 duration_to_sec_usec (duration
, &secs
, &usecs
);
29003 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
29004 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29005 show_hourglass
, NULL
);
29010 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29013 cancel_hourglass (void)
29015 #if defined (HAVE_WINDOW_SYSTEM)
29016 if (hourglass_atimer
)
29018 cancel_atimer (hourglass_atimer
);
29019 hourglass_atimer
= NULL
;
29022 if (hourglass_shown_p
)
29026 #endif /* ! WINDOWSNT */