1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
284 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT, or the underlying buffer
387 or string character, is a space or a TAB character. This is used
388 to determine where word wrapping can occur. */
390 #define IT_DISPLAYING_WHITESPACE(it) \
391 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
392 || ((STRINGP (it->string) \
393 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
394 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
396 && (it->s[IT_BYTEPOS (*it)] == ' ' \
397 || it->s[IT_BYTEPOS (*it)] == '\t')) \
398 || (IT_BYTEPOS (*it) < ZV_BYTE \
399 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
400 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
402 /* Name of the face used to highlight trailing whitespace. */
404 static Lisp_Object Qtrailing_whitespace
;
406 /* Name and number of the face used to highlight escape glyphs. */
408 static Lisp_Object Qescape_glyph
;
410 /* Name and number of the face used to highlight non-breaking spaces. */
412 static Lisp_Object Qnobreak_space
;
414 /* The symbol `image' which is the car of the lists used to represent
415 images in Lisp. Also a tool bar style. */
419 /* The image map types. */
421 static Lisp_Object QCpointer
;
422 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
424 /* Tool bar styles */
425 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
427 /* Non-zero means print newline to stdout before next mini-buffer
430 int noninteractive_need_newline
;
432 /* Non-zero means print newline to message log before next message. */
434 static int message_log_need_newline
;
436 /* Three markers that message_dolog uses.
437 It could allocate them itself, but that causes trouble
438 in handling memory-full errors. */
439 static Lisp_Object message_dolog_marker1
;
440 static Lisp_Object message_dolog_marker2
;
441 static Lisp_Object message_dolog_marker3
;
443 /* The buffer position of the first character appearing entirely or
444 partially on the line of the selected window which contains the
445 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
446 redisplay optimization in redisplay_internal. */
448 static struct text_pos this_line_start_pos
;
450 /* Number of characters past the end of the line above, including the
451 terminating newline. */
453 static struct text_pos this_line_end_pos
;
455 /* The vertical positions and the height of this line. */
457 static int this_line_vpos
;
458 static int this_line_y
;
459 static int this_line_pixel_height
;
461 /* X position at which this display line starts. Usually zero;
462 negative if first character is partially visible. */
464 static int this_line_start_x
;
466 /* The smallest character position seen by move_it_* functions as they
467 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
468 hscrolled lines, see display_line. */
470 static struct text_pos this_line_min_pos
;
472 /* Buffer that this_line_.* variables are referring to. */
474 static struct buffer
*this_line_buffer
;
477 /* Values of those variables at last redisplay are stored as
478 properties on `overlay-arrow-position' symbol. However, if
479 Voverlay_arrow_position is a marker, last-arrow-position is its
480 numerical position. */
482 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
484 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
485 properties on a symbol in overlay-arrow-variable-list. */
487 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
489 Lisp_Object Qmenu_bar_update_hook
;
491 /* Nonzero if an overlay arrow has been displayed in this window. */
493 static int overlay_arrow_seen
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* This is the window where the echo area message was displayed. It
506 is always a mini-buffer window, but it may not be the same window
507 currently active as a mini-buffer. */
509 Lisp_Object echo_area_window
;
511 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
512 pushes the current message and the value of
513 message_enable_multibyte on the stack, the function restore_message
514 pops the stack and displays MESSAGE again. */
516 static Lisp_Object Vmessage_stack
;
518 /* Nonzero means multibyte characters were enabled when the echo area
519 message was specified. */
521 static int message_enable_multibyte
;
523 /* Nonzero if we should redraw the mode lines on the next redisplay. */
525 int update_mode_lines
;
527 /* Nonzero if window sizes or contents have changed since last
528 redisplay that finished. */
530 int windows_or_buffers_changed
;
532 /* Nonzero means a frame's cursor type has been changed. */
534 int cursor_type_changed
;
536 /* Nonzero after display_mode_line if %l was used and it displayed a
539 static int line_number_displayed
;
541 /* The name of the *Messages* buffer, a string. */
543 static Lisp_Object Vmessages_buffer_name
;
545 /* Current, index 0, and last displayed echo area message. Either
546 buffers from echo_buffers, or nil to indicate no message. */
548 Lisp_Object echo_area_buffer
[2];
550 /* The buffers referenced from echo_area_buffer. */
552 static Lisp_Object echo_buffer
[2];
554 /* A vector saved used in with_area_buffer to reduce consing. */
556 static Lisp_Object Vwith_echo_area_save_vector
;
558 /* Non-zero means display_echo_area should display the last echo area
559 message again. Set by redisplay_preserve_echo_area. */
561 static int display_last_displayed_message_p
;
563 /* Nonzero if echo area is being used by print; zero if being used by
566 static int message_buf_print
;
568 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
570 static Lisp_Object Qinhibit_menubar_update
;
571 static Lisp_Object Qmessage_truncate_lines
;
573 /* Set to 1 in clear_message to make redisplay_internal aware
574 of an emptied echo area. */
576 static int message_cleared_p
;
578 /* A scratch glyph row with contents used for generating truncation
579 glyphs. Also used in direct_output_for_insert. */
581 #define MAX_SCRATCH_GLYPHS 100
582 static struct glyph_row scratch_glyph_row
;
583 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
585 /* Ascent and height of the last line processed by move_it_to. */
587 static int last_max_ascent
, last_height
;
589 /* Non-zero if there's a help-echo in the echo area. */
591 int help_echo_showing_p
;
593 /* If >= 0, computed, exact values of mode-line and header-line height
594 to use in the macros CURRENT_MODE_LINE_HEIGHT and
595 CURRENT_HEADER_LINE_HEIGHT. */
597 int current_mode_line_height
, current_header_line_height
;
599 /* The maximum distance to look ahead for text properties. Values
600 that are too small let us call compute_char_face and similar
601 functions too often which is expensive. Values that are too large
602 let us call compute_char_face and alike too often because we
603 might not be interested in text properties that far away. */
605 #define TEXT_PROP_DISTANCE_LIMIT 100
607 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
608 iterator state and later restore it. This is needed because the
609 bidi iterator on bidi.c keeps a stacked cache of its states, which
610 is really a singleton. When we use scratch iterator objects to
611 move around the buffer, we can cause the bidi cache to be pushed or
612 popped, and therefore we need to restore the cache state when we
613 return to the original iterator. */
614 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
617 bidi_unshelve_cache (CACHE, 1); \
619 CACHE = bidi_shelve_cache (); \
622 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
624 if (pITORIG != pITCOPY) \
625 *(pITORIG) = *(pITCOPY); \
626 bidi_unshelve_cache (CACHE, 0); \
632 /* Non-zero means print traces of redisplay if compiled with
633 GLYPH_DEBUG defined. */
635 int trace_redisplay_p
;
637 #endif /* GLYPH_DEBUG */
639 #ifdef DEBUG_TRACE_MOVE
640 /* Non-zero means trace with TRACE_MOVE to stderr. */
643 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
645 #define TRACE_MOVE(x) (void) 0
648 static Lisp_Object Qauto_hscroll_mode
;
650 /* Buffer being redisplayed -- for redisplay_window_error. */
652 static struct buffer
*displayed_buffer
;
654 /* Value returned from text property handlers (see below). */
659 HANDLED_RECOMPUTE_PROPS
,
660 HANDLED_OVERLAY_STRING_CONSUMED
,
664 /* A description of text properties that redisplay is interested
669 /* The name of the property. */
672 /* A unique index for the property. */
675 /* A handler function called to set up iterator IT from the property
676 at IT's current position. Value is used to steer handle_stop. */
677 enum prop_handled (*handler
) (struct it
*it
);
680 static enum prop_handled
handle_face_prop (struct it
*);
681 static enum prop_handled
handle_invisible_prop (struct it
*);
682 static enum prop_handled
handle_display_prop (struct it
*);
683 static enum prop_handled
handle_composition_prop (struct it
*);
684 static enum prop_handled
handle_overlay_change (struct it
*);
685 static enum prop_handled
handle_fontified_prop (struct it
*);
687 /* Properties handled by iterators. */
689 static struct props it_props
[] =
691 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
692 /* Handle `face' before `display' because some sub-properties of
693 `display' need to know the face. */
694 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
695 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
696 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
697 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
701 /* Value is the position described by X. If X is a marker, value is
702 the marker_position of X. Otherwise, value is X. */
704 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
706 /* Enumeration returned by some move_it_.* functions internally. */
710 /* Not used. Undefined value. */
713 /* Move ended at the requested buffer position or ZV. */
714 MOVE_POS_MATCH_OR_ZV
,
716 /* Move ended at the requested X pixel position. */
719 /* Move within a line ended at the end of a line that must be
723 /* Move within a line ended at the end of a line that would
724 be displayed truncated. */
727 /* Move within a line ended at a line end. */
731 /* This counter is used to clear the face cache every once in a while
732 in redisplay_internal. It is incremented for each redisplay.
733 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
736 #define CLEAR_FACE_CACHE_COUNT 500
737 static int clear_face_cache_count
;
739 /* Similarly for the image cache. */
741 #ifdef HAVE_WINDOW_SYSTEM
742 #define CLEAR_IMAGE_CACHE_COUNT 101
743 static int clear_image_cache_count
;
745 /* Null glyph slice */
746 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
749 /* Non-zero while redisplay_internal is in progress. */
753 static Lisp_Object Qinhibit_free_realized_faces
;
754 static Lisp_Object Qmode_line_default_help_echo
;
756 /* If a string, XTread_socket generates an event to display that string.
757 (The display is done in read_char.) */
759 Lisp_Object help_echo_string
;
760 Lisp_Object help_echo_window
;
761 Lisp_Object help_echo_object
;
762 ptrdiff_t help_echo_pos
;
764 /* Temporary variable for XTread_socket. */
766 Lisp_Object previous_help_echo_string
;
768 /* Platform-independent portion of hourglass implementation. */
770 /* Non-zero means an hourglass cursor is currently shown. */
771 int hourglass_shown_p
;
773 /* If non-null, an asynchronous timer that, when it expires, displays
774 an hourglass cursor on all frames. */
775 struct atimer
*hourglass_atimer
;
777 /* Name of the face used to display glyphless characters. */
778 Lisp_Object Qglyphless_char
;
780 /* Symbol for the purpose of Vglyphless_char_display. */
781 static Lisp_Object Qglyphless_char_display
;
783 /* Method symbols for Vglyphless_char_display. */
784 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
786 /* Default pixel width of `thin-space' display method. */
787 #define THIN_SPACE_WIDTH 1
789 /* Default number of seconds to wait before displaying an hourglass
791 #define DEFAULT_HOURGLASS_DELAY 1
794 /* Function prototypes. */
796 static void setup_for_ellipsis (struct it
*, int);
797 static void set_iterator_to_next (struct it
*, int);
798 static void mark_window_display_accurate_1 (struct window
*, int);
799 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
800 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
801 static int cursor_row_p (struct glyph_row
*);
802 static int redisplay_mode_lines (Lisp_Object
, int);
803 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
805 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
807 static void handle_line_prefix (struct it
*);
809 static void pint2str (char *, int, ptrdiff_t);
810 static void pint2hrstr (char *, int, ptrdiff_t);
811 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
813 static void reconsider_clip_changes (struct window
*, struct buffer
*);
814 static int text_outside_line_unchanged_p (struct window
*,
815 ptrdiff_t, ptrdiff_t);
816 static void store_mode_line_noprop_char (char);
817 static int store_mode_line_noprop (const char *, int, int);
818 static void handle_stop (struct it
*);
819 static void handle_stop_backwards (struct it
*, ptrdiff_t);
820 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
821 static void ensure_echo_area_buffers (void);
822 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
823 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
824 static int with_echo_area_buffer (struct window
*, int,
825 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
826 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
827 static void clear_garbaged_frames (void);
828 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
829 static void pop_message (void);
830 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
831 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
832 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
833 static int display_echo_area (struct window
*);
834 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
835 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
836 static Lisp_Object
unwind_redisplay (Lisp_Object
);
837 static int string_char_and_length (const unsigned char *, int *);
838 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
840 static int compute_window_start_on_continuation_line (struct window
*);
841 static Lisp_Object
safe_eval_handler (Lisp_Object
);
842 static void insert_left_trunc_glyphs (struct it
*);
843 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
845 static void extend_face_to_end_of_line (struct it
*);
846 static int append_space_for_newline (struct it
*, int);
847 static int cursor_row_fully_visible_p (struct window
*, int, int);
848 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
849 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
850 static int trailing_whitespace_p (ptrdiff_t);
851 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
852 static void push_it (struct it
*, struct text_pos
*);
853 static void iterate_out_of_display_property (struct it
*);
854 static void pop_it (struct it
*);
855 static void sync_frame_with_window_matrix_rows (struct window
*);
856 static void select_frame_for_redisplay (Lisp_Object
);
857 static void redisplay_internal (void);
858 static int echo_area_display (int);
859 static void redisplay_windows (Lisp_Object
);
860 static void redisplay_window (Lisp_Object
, int);
861 static Lisp_Object
redisplay_window_error (Lisp_Object
);
862 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
863 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
864 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
865 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
867 static int update_menu_bar (struct frame
*, int, int);
868 static int try_window_reusing_current_matrix (struct window
*);
869 static int try_window_id (struct window
*);
870 static int display_line (struct it
*);
871 static int display_mode_lines (struct window
*);
872 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
873 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
874 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
875 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
876 static void display_menu_bar (struct window
*);
877 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
879 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
880 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
881 static void compute_line_metrics (struct it
*);
882 static void run_redisplay_end_trigger_hook (struct it
*);
883 static int get_overlay_strings (struct it
*, ptrdiff_t);
884 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
885 static void next_overlay_string (struct it
*);
886 static void reseat (struct it
*, struct text_pos
, int);
887 static void reseat_1 (struct it
*, struct text_pos
, int);
888 static void back_to_previous_visible_line_start (struct it
*);
889 void reseat_at_previous_visible_line_start (struct it
*);
890 static void reseat_at_next_visible_line_start (struct it
*, int);
891 static int next_element_from_ellipsis (struct it
*);
892 static int next_element_from_display_vector (struct it
*);
893 static int next_element_from_string (struct it
*);
894 static int next_element_from_c_string (struct it
*);
895 static int next_element_from_buffer (struct it
*);
896 static int next_element_from_composition (struct it
*);
897 static int next_element_from_image (struct it
*);
898 static int next_element_from_stretch (struct it
*);
899 static void load_overlay_strings (struct it
*, ptrdiff_t);
900 static int init_from_display_pos (struct it
*, struct window
*,
901 struct display_pos
*);
902 static void reseat_to_string (struct it
*, const char *,
903 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
904 static int get_next_display_element (struct it
*);
905 static enum move_it_result
906 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
907 enum move_operation_enum
);
908 void move_it_vertically_backward (struct it
*, int);
909 static void init_to_row_start (struct it
*, struct window
*,
911 static int init_to_row_end (struct it
*, struct window
*,
913 static void back_to_previous_line_start (struct it
*);
914 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
915 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
916 Lisp_Object
, ptrdiff_t);
917 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
918 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
919 static ptrdiff_t number_of_chars (const char *, int);
920 static void compute_stop_pos (struct it
*);
921 static void compute_string_pos (struct text_pos
*, struct text_pos
,
923 static int face_before_or_after_it_pos (struct it
*, int);
924 static ptrdiff_t next_overlay_change (ptrdiff_t);
925 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
926 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
927 static int handle_single_display_spec (struct it
*, Lisp_Object
,
928 Lisp_Object
, Lisp_Object
,
929 struct text_pos
*, ptrdiff_t, int, int);
930 static int underlying_face_id (struct it
*);
931 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
934 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
935 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
937 #ifdef HAVE_WINDOW_SYSTEM
939 static void x_consider_frame_title (Lisp_Object
);
940 static int tool_bar_lines_needed (struct frame
*, int *);
941 static void update_tool_bar (struct frame
*, int);
942 static void build_desired_tool_bar_string (struct frame
*f
);
943 static int redisplay_tool_bar (struct frame
*);
944 static void display_tool_bar_line (struct it
*, int);
945 static void notice_overwritten_cursor (struct window
*,
948 static void append_stretch_glyph (struct it
*, Lisp_Object
,
952 #endif /* HAVE_WINDOW_SYSTEM */
954 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
955 static int coords_in_mouse_face_p (struct window
*, int, int);
959 /***********************************************************************
960 Window display dimensions
961 ***********************************************************************/
963 /* Return the bottom boundary y-position for text lines in window W.
964 This is the first y position at which a line cannot start.
965 It is relative to the top of the window.
967 This is the height of W minus the height of a mode line, if any. */
970 window_text_bottom_y (struct window
*w
)
972 int height
= WINDOW_TOTAL_HEIGHT (w
);
974 if (WINDOW_WANTS_MODELINE_P (w
))
975 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
979 /* Return the pixel width of display area AREA of window W. AREA < 0
980 means return the total width of W, not including fringes to
981 the left and right of the window. */
984 window_box_width (struct window
*w
, int area
)
986 int cols
= XFASTINT (w
->total_cols
);
989 if (!w
->pseudo_window_p
)
991 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
993 if (area
== TEXT_AREA
)
995 if (INTEGERP (w
->left_margin_cols
))
996 cols
-= XFASTINT (w
->left_margin_cols
);
997 if (INTEGERP (w
->right_margin_cols
))
998 cols
-= XFASTINT (w
->right_margin_cols
);
999 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1001 else if (area
== LEFT_MARGIN_AREA
)
1003 cols
= (INTEGERP (w
->left_margin_cols
)
1004 ? XFASTINT (w
->left_margin_cols
) : 0);
1007 else if (area
== RIGHT_MARGIN_AREA
)
1009 cols
= (INTEGERP (w
->right_margin_cols
)
1010 ? XFASTINT (w
->right_margin_cols
) : 0);
1015 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1019 /* Return the pixel height of the display area of window W, not
1020 including mode lines of W, if any. */
1023 window_box_height (struct window
*w
)
1025 struct frame
*f
= XFRAME (w
->frame
);
1026 int height
= WINDOW_TOTAL_HEIGHT (w
);
1028 eassert (height
>= 0);
1030 /* Note: the code below that determines the mode-line/header-line
1031 height is essentially the same as that contained in the macro
1032 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1033 the appropriate glyph row has its `mode_line_p' flag set,
1034 and if it doesn't, uses estimate_mode_line_height instead. */
1036 if (WINDOW_WANTS_MODELINE_P (w
))
1038 struct glyph_row
*ml_row
1039 = (w
->current_matrix
&& w
->current_matrix
->rows
1040 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1042 if (ml_row
&& ml_row
->mode_line_p
)
1043 height
-= ml_row
->height
;
1045 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1048 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1050 struct glyph_row
*hl_row
1051 = (w
->current_matrix
&& w
->current_matrix
->rows
1052 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1054 if (hl_row
&& hl_row
->mode_line_p
)
1055 height
-= hl_row
->height
;
1057 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1060 /* With a very small font and a mode-line that's taller than
1061 default, we might end up with a negative height. */
1062 return max (0, height
);
1065 /* Return the window-relative coordinate of the left edge of display
1066 area AREA of window W. AREA < 0 means return the left edge of the
1067 whole window, to the right of the left fringe of W. */
1070 window_box_left_offset (struct window
*w
, int area
)
1074 if (w
->pseudo_window_p
)
1077 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1079 if (area
== TEXT_AREA
)
1080 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1081 + window_box_width (w
, LEFT_MARGIN_AREA
));
1082 else if (area
== RIGHT_MARGIN_AREA
)
1083 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1084 + window_box_width (w
, LEFT_MARGIN_AREA
)
1085 + window_box_width (w
, TEXT_AREA
)
1086 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1088 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1089 else if (area
== LEFT_MARGIN_AREA
1090 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1091 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1097 /* Return the window-relative coordinate of the right edge of display
1098 area AREA of window W. AREA < 0 means return the right edge of the
1099 whole window, to the left of the right fringe of W. */
1102 window_box_right_offset (struct window
*w
, int area
)
1104 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1107 /* Return the frame-relative coordinate of the left edge of display
1108 area AREA of window W. AREA < 0 means return the left edge of the
1109 whole window, to the right of the left fringe of W. */
1112 window_box_left (struct window
*w
, int area
)
1114 struct frame
*f
= XFRAME (w
->frame
);
1117 if (w
->pseudo_window_p
)
1118 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1120 x
= (WINDOW_LEFT_EDGE_X (w
)
1121 + window_box_left_offset (w
, area
));
1127 /* Return the frame-relative coordinate of the right edge of display
1128 area AREA of window W. AREA < 0 means return the right edge of the
1129 whole window, to the left of the right fringe of W. */
1132 window_box_right (struct window
*w
, int area
)
1134 return window_box_left (w
, area
) + window_box_width (w
, area
);
1137 /* Get the bounding box of the display area AREA of window W, without
1138 mode lines, in frame-relative coordinates. AREA < 0 means the
1139 whole window, not including the left and right fringes of
1140 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1141 coordinates of the upper-left corner of the box. Return in
1142 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1145 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1146 int *box_width
, int *box_height
)
1149 *box_width
= window_box_width (w
, area
);
1151 *box_height
= window_box_height (w
);
1153 *box_x
= window_box_left (w
, area
);
1156 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1157 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1158 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1163 /* Get the bounding box of the display area AREA of window W, without
1164 mode lines. AREA < 0 means the whole window, not including the
1165 left and right fringe of the window. Return in *TOP_LEFT_X
1166 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1167 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1168 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1172 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1173 int *bottom_right_x
, int *bottom_right_y
)
1175 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1177 *bottom_right_x
+= *top_left_x
;
1178 *bottom_right_y
+= *top_left_y
;
1183 /***********************************************************************
1185 ***********************************************************************/
1187 /* Return the bottom y-position of the line the iterator IT is in.
1188 This can modify IT's settings. */
1191 line_bottom_y (struct it
*it
)
1193 int line_height
= it
->max_ascent
+ it
->max_descent
;
1194 int line_top_y
= it
->current_y
;
1196 if (line_height
== 0)
1199 line_height
= last_height
;
1200 else if (IT_CHARPOS (*it
) < ZV
)
1202 move_it_by_lines (it
, 1);
1203 line_height
= (it
->max_ascent
|| it
->max_descent
1204 ? it
->max_ascent
+ it
->max_descent
1209 struct glyph_row
*row
= it
->glyph_row
;
1211 /* Use the default character height. */
1212 it
->glyph_row
= NULL
;
1213 it
->what
= IT_CHARACTER
;
1216 PRODUCE_GLYPHS (it
);
1217 line_height
= it
->ascent
+ it
->descent
;
1218 it
->glyph_row
= row
;
1222 return line_top_y
+ line_height
;
1225 /* Subroutine of pos_visible_p below. Extracts a display string, if
1226 any, from the display spec given as its argument. */
1228 string_from_display_spec (Lisp_Object spec
)
1232 while (CONSP (spec
))
1234 if (STRINGP (XCAR (spec
)))
1239 else if (VECTORP (spec
))
1243 for (i
= 0; i
< ASIZE (spec
); i
++)
1245 if (STRINGP (AREF (spec
, i
)))
1246 return AREF (spec
, i
);
1255 /* Limit insanely large values of W->hscroll on frame F to the largest
1256 value that will still prevent first_visible_x and last_visible_x of
1257 'struct it' from overflowing an int. */
1259 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1261 ptrdiff_t window_hscroll
= w
->hscroll
;
1262 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1263 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1265 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1266 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1268 return window_hscroll
;
1271 /* Return 1 if position CHARPOS is visible in window W.
1272 CHARPOS < 0 means return info about WINDOW_END position.
1273 If visible, set *X and *Y to pixel coordinates of top left corner.
1274 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1275 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1278 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1279 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1282 void *itdata
= bidi_shelve_cache ();
1283 struct text_pos top
;
1285 struct buffer
*old_buffer
= NULL
;
1287 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1290 if (XBUFFER (w
->buffer
) != current_buffer
)
1292 old_buffer
= current_buffer
;
1293 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1296 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1297 /* Scrolling a minibuffer window via scroll bar when the echo area
1298 shows long text sometimes resets the minibuffer contents behind
1300 if (CHARPOS (top
) > ZV
)
1301 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1303 /* Compute exact mode line heights. */
1304 if (WINDOW_WANTS_MODELINE_P (w
))
1305 current_mode_line_height
1306 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1307 BVAR (current_buffer
, mode_line_format
));
1309 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1310 current_header_line_height
1311 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1312 BVAR (current_buffer
, header_line_format
));
1314 start_display (&it
, w
, top
);
1315 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1316 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1319 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1320 && IT_CHARPOS (it
) >= charpos
)
1321 /* When scanning backwards under bidi iteration, move_it_to
1322 stops at or _before_ CHARPOS, because it stops at or to
1323 the _right_ of the character at CHARPOS. */
1324 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1325 && IT_CHARPOS (it
) <= charpos
)))
1327 /* We have reached CHARPOS, or passed it. How the call to
1328 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1329 or covered by a display property, move_it_to stops at the end
1330 of the invisible text, to the right of CHARPOS. (ii) If
1331 CHARPOS is in a display vector, move_it_to stops on its last
1333 int top_x
= it
.current_x
;
1334 int top_y
= it
.current_y
;
1335 /* Calling line_bottom_y may change it.method, it.position, etc. */
1336 enum it_method it_method
= it
.method
;
1337 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1338 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1340 if (top_y
< window_top_y
)
1341 visible_p
= bottom_y
> window_top_y
;
1342 else if (top_y
< it
.last_visible_y
)
1344 if (bottom_y
>= it
.last_visible_y
1345 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1346 && IT_CHARPOS (it
) < charpos
)
1348 /* When the last line of the window is scanned backwards
1349 under bidi iteration, we could be duped into thinking
1350 that we have passed CHARPOS, when in fact move_it_to
1351 simply stopped short of CHARPOS because it reached
1352 last_visible_y. To see if that's what happened, we call
1353 move_it_to again with a slightly larger vertical limit,
1354 and see if it actually moved vertically; if it did, we
1355 didn't really reach CHARPOS, which is beyond window end. */
1356 struct it save_it
= it
;
1357 /* Why 10? because we don't know how many canonical lines
1358 will the height of the next line(s) be. So we guess. */
1359 int ten_more_lines
=
1360 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1362 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1363 MOVE_TO_POS
| MOVE_TO_Y
);
1364 if (it
.current_y
> top_y
)
1371 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1373 /* We stopped on the last glyph of a display vector.
1374 Try and recompute. Hack alert! */
1375 if (charpos
< 2 || top
.charpos
>= charpos
)
1376 top_x
= it
.glyph_row
->x
;
1380 start_display (&it2
, w
, top
);
1381 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1382 get_next_display_element (&it2
);
1383 PRODUCE_GLYPHS (&it2
);
1384 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1385 || it2
.current_x
> it2
.last_visible_x
)
1386 top_x
= it
.glyph_row
->x
;
1389 top_x
= it2
.current_x
;
1390 top_y
= it2
.current_y
;
1394 else if (IT_CHARPOS (it
) != charpos
)
1396 Lisp_Object cpos
= make_number (charpos
);
1397 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1398 Lisp_Object string
= string_from_display_spec (spec
);
1399 int newline_in_string
= 0;
1401 if (STRINGP (string
))
1403 const char *s
= SSDATA (string
);
1404 const char *e
= s
+ SBYTES (string
);
1409 newline_in_string
= 1;
1414 /* The tricky code below is needed because there's a
1415 discrepancy between move_it_to and how we set cursor
1416 when the display line ends in a newline from a
1417 display string. move_it_to will stop _after_ such
1418 display strings, whereas set_cursor_from_row
1419 conspires with cursor_row_p to place the cursor on
1420 the first glyph produced from the display string. */
1422 /* We have overshoot PT because it is covered by a
1423 display property whose value is a string. If the
1424 string includes embedded newlines, we are also in the
1425 wrong display line. Backtrack to the correct line,
1426 where the display string begins. */
1427 if (newline_in_string
)
1429 Lisp_Object startpos
, endpos
;
1430 EMACS_INT start
, end
;
1434 /* Find the first and the last buffer positions
1435 covered by the display string. */
1437 Fnext_single_char_property_change (cpos
, Qdisplay
,
1440 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1442 start
= XFASTINT (startpos
);
1443 end
= XFASTINT (endpos
);
1444 /* Move to the last buffer position before the
1445 display property. */
1446 start_display (&it3
, w
, top
);
1447 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1448 /* Move forward one more line if the position before
1449 the display string is a newline or if it is the
1450 rightmost character on a line that is
1451 continued or word-wrapped. */
1452 if (it3
.method
== GET_FROM_BUFFER
1454 move_it_by_lines (&it3
, 1);
1455 else if (move_it_in_display_line_to (&it3
, -1,
1459 == MOVE_LINE_CONTINUED
)
1461 move_it_by_lines (&it3
, 1);
1462 /* When we are under word-wrap, the #$@%!
1463 move_it_by_lines moves 2 lines, so we need to
1465 if (it3
.line_wrap
== WORD_WRAP
)
1466 move_it_by_lines (&it3
, -1);
1469 /* Record the vertical coordinate of the display
1470 line where we wound up. */
1471 top_y
= it3
.current_y
;
1474 /* When characters are reordered for display,
1475 the character displayed to the left of the
1476 display string could be _after_ the display
1477 property in the logical order. Use the
1478 smallest vertical position of these two. */
1479 start_display (&it3
, w
, top
);
1480 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1481 if (it3
.current_y
< top_y
)
1482 top_y
= it3
.current_y
;
1484 /* Move from the top of the window to the beginning
1485 of the display line where the display string
1487 start_display (&it3
, w
, top
);
1488 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1489 /* If it3_moved stays zero after the 'while' loop
1490 below, that means we already were at a newline
1491 before the loop (e.g., the display string begins
1492 with a newline), so we don't need to (and cannot)
1493 inspect the glyphs of it3.glyph_row, because
1494 PRODUCE_GLYPHS will not produce anything for a
1495 newline, and thus it3.glyph_row stays at its
1496 stale content it got at top of the window. */
1498 /* Finally, advance the iterator until we hit the
1499 first display element whose character position is
1500 CHARPOS, or until the first newline from the
1501 display string, which signals the end of the
1503 while (get_next_display_element (&it3
))
1505 PRODUCE_GLYPHS (&it3
);
1506 if (IT_CHARPOS (it3
) == charpos
1507 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1510 set_iterator_to_next (&it3
, 0);
1512 top_x
= it3
.current_x
- it3
.pixel_width
;
1513 /* Normally, we would exit the above loop because we
1514 found the display element whose character
1515 position is CHARPOS. For the contingency that we
1516 didn't, and stopped at the first newline from the
1517 display string, move back over the glyphs
1518 produced from the string, until we find the
1519 rightmost glyph not from the string. */
1521 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1523 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1524 + it3
.glyph_row
->used
[TEXT_AREA
];
1526 while (EQ ((g
- 1)->object
, string
))
1529 top_x
-= g
->pixel_width
;
1531 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1532 + it3
.glyph_row
->used
[TEXT_AREA
]);
1538 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1539 *rtop
= max (0, window_top_y
- top_y
);
1540 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1541 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1542 - max (top_y
, window_top_y
)));
1548 /* We were asked to provide info about WINDOW_END. */
1550 void *it2data
= NULL
;
1552 SAVE_IT (it2
, it
, it2data
);
1553 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1554 move_it_by_lines (&it
, 1);
1555 if (charpos
< IT_CHARPOS (it
)
1556 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1559 RESTORE_IT (&it2
, &it2
, it2data
);
1560 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1562 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1563 *rtop
= max (0, -it2
.current_y
);
1564 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1565 - it
.last_visible_y
));
1566 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1568 - max (it2
.current_y
,
1569 WINDOW_HEADER_LINE_HEIGHT (w
))));
1573 bidi_unshelve_cache (it2data
, 1);
1575 bidi_unshelve_cache (itdata
, 0);
1578 set_buffer_internal_1 (old_buffer
);
1580 current_header_line_height
= current_mode_line_height
= -1;
1582 if (visible_p
&& w
->hscroll
> 0)
1584 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1585 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1588 /* Debugging code. */
1590 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1591 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1593 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1600 /* Return the next character from STR. Return in *LEN the length of
1601 the character. This is like STRING_CHAR_AND_LENGTH but never
1602 returns an invalid character. If we find one, we return a `?', but
1603 with the length of the invalid character. */
1606 string_char_and_length (const unsigned char *str
, int *len
)
1610 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1611 if (!CHAR_VALID_P (c
))
1612 /* We may not change the length here because other places in Emacs
1613 don't use this function, i.e. they silently accept invalid
1622 /* Given a position POS containing a valid character and byte position
1623 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1625 static struct text_pos
1626 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1628 eassert (STRINGP (string
) && nchars
>= 0);
1630 if (STRING_MULTIBYTE (string
))
1632 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1637 string_char_and_length (p
, &len
);
1640 BYTEPOS (pos
) += len
;
1644 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1650 /* Value is the text position, i.e. character and byte position,
1651 for character position CHARPOS in STRING. */
1653 static inline struct text_pos
1654 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1656 struct text_pos pos
;
1657 eassert (STRINGP (string
));
1658 eassert (charpos
>= 0);
1659 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1664 /* Value is a text position, i.e. character and byte position, for
1665 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1666 means recognize multibyte characters. */
1668 static struct text_pos
1669 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1671 struct text_pos pos
;
1673 eassert (s
!= NULL
);
1674 eassert (charpos
>= 0);
1680 SET_TEXT_POS (pos
, 0, 0);
1683 string_char_and_length ((const unsigned char *) s
, &len
);
1686 BYTEPOS (pos
) += len
;
1690 SET_TEXT_POS (pos
, charpos
, charpos
);
1696 /* Value is the number of characters in C string S. MULTIBYTE_P
1697 non-zero means recognize multibyte characters. */
1700 number_of_chars (const char *s
, int multibyte_p
)
1706 ptrdiff_t rest
= strlen (s
);
1708 const unsigned char *p
= (const unsigned char *) s
;
1710 for (nchars
= 0; rest
> 0; ++nchars
)
1712 string_char_and_length (p
, &len
);
1713 rest
-= len
, p
+= len
;
1717 nchars
= strlen (s
);
1723 /* Compute byte position NEWPOS->bytepos corresponding to
1724 NEWPOS->charpos. POS is a known position in string STRING.
1725 NEWPOS->charpos must be >= POS.charpos. */
1728 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1730 eassert (STRINGP (string
));
1731 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1733 if (STRING_MULTIBYTE (string
))
1734 *newpos
= string_pos_nchars_ahead (pos
, string
,
1735 CHARPOS (*newpos
) - CHARPOS (pos
));
1737 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1741 Return an estimation of the pixel height of mode or header lines on
1742 frame F. FACE_ID specifies what line's height to estimate. */
1745 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1747 #ifdef HAVE_WINDOW_SYSTEM
1748 if (FRAME_WINDOW_P (f
))
1750 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1752 /* This function is called so early when Emacs starts that the face
1753 cache and mode line face are not yet initialized. */
1754 if (FRAME_FACE_CACHE (f
))
1756 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1760 height
= FONT_HEIGHT (face
->font
);
1761 if (face
->box_line_width
> 0)
1762 height
+= 2 * face
->box_line_width
;
1773 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1774 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1775 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1776 not force the value into range. */
1779 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1780 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1783 #ifdef HAVE_WINDOW_SYSTEM
1784 if (FRAME_WINDOW_P (f
))
1786 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1787 even for negative values. */
1789 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1791 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1793 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1794 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1797 STORE_NATIVE_RECT (*bounds
,
1798 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1799 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1800 FRAME_COLUMN_WIDTH (f
) - 1,
1801 FRAME_LINE_HEIGHT (f
) - 1);
1807 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1808 pix_x
= FRAME_TOTAL_COLS (f
);
1812 else if (pix_y
> FRAME_LINES (f
))
1813 pix_y
= FRAME_LINES (f
);
1823 /* Find the glyph under window-relative coordinates X/Y in window W.
1824 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1825 strings. Return in *HPOS and *VPOS the row and column number of
1826 the glyph found. Return in *AREA the glyph area containing X.
1827 Value is a pointer to the glyph found or null if X/Y is not on
1828 text, or we can't tell because W's current matrix is not up to
1833 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1834 int *dx
, int *dy
, int *area
)
1836 struct glyph
*glyph
, *end
;
1837 struct glyph_row
*row
= NULL
;
1840 /* Find row containing Y. Give up if some row is not enabled. */
1841 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1843 row
= MATRIX_ROW (w
->current_matrix
, i
);
1844 if (!row
->enabled_p
)
1846 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1853 /* Give up if Y is not in the window. */
1854 if (i
== w
->current_matrix
->nrows
)
1857 /* Get the glyph area containing X. */
1858 if (w
->pseudo_window_p
)
1865 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1867 *area
= LEFT_MARGIN_AREA
;
1868 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1870 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1873 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1877 *area
= RIGHT_MARGIN_AREA
;
1878 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1882 /* Find glyph containing X. */
1883 glyph
= row
->glyphs
[*area
];
1884 end
= glyph
+ row
->used
[*area
];
1886 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1888 x
-= glyph
->pixel_width
;
1898 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1901 *hpos
= glyph
- row
->glyphs
[*area
];
1905 /* Convert frame-relative x/y to coordinates relative to window W.
1906 Takes pseudo-windows into account. */
1909 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1911 if (w
->pseudo_window_p
)
1913 /* A pseudo-window is always full-width, and starts at the
1914 left edge of the frame, plus a frame border. */
1915 struct frame
*f
= XFRAME (w
->frame
);
1916 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1917 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1921 *x
-= WINDOW_LEFT_EDGE_X (w
);
1922 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1926 #ifdef HAVE_WINDOW_SYSTEM
1929 Return in RECTS[] at most N clipping rectangles for glyph string S.
1930 Return the number of stored rectangles. */
1933 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1940 if (s
->row
->full_width_p
)
1942 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1943 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1944 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1946 /* Unless displaying a mode or menu bar line, which are always
1947 fully visible, clip to the visible part of the row. */
1948 if (s
->w
->pseudo_window_p
)
1949 r
.height
= s
->row
->visible_height
;
1951 r
.height
= s
->height
;
1955 /* This is a text line that may be partially visible. */
1956 r
.x
= window_box_left (s
->w
, s
->area
);
1957 r
.width
= window_box_width (s
->w
, s
->area
);
1958 r
.height
= s
->row
->visible_height
;
1962 if (r
.x
< s
->clip_head
->x
)
1964 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1965 r
.width
-= s
->clip_head
->x
- r
.x
;
1968 r
.x
= s
->clip_head
->x
;
1971 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1973 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1974 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1979 /* If S draws overlapping rows, it's sufficient to use the top and
1980 bottom of the window for clipping because this glyph string
1981 intentionally draws over other lines. */
1982 if (s
->for_overlaps
)
1984 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1985 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1987 /* Alas, the above simple strategy does not work for the
1988 environments with anti-aliased text: if the same text is
1989 drawn onto the same place multiple times, it gets thicker.
1990 If the overlap we are processing is for the erased cursor, we
1991 take the intersection with the rectangle of the cursor. */
1992 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1994 XRectangle rc
, r_save
= r
;
1996 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1997 rc
.y
= s
->w
->phys_cursor
.y
;
1998 rc
.width
= s
->w
->phys_cursor_width
;
1999 rc
.height
= s
->w
->phys_cursor_height
;
2001 x_intersect_rectangles (&r_save
, &rc
, &r
);
2006 /* Don't use S->y for clipping because it doesn't take partially
2007 visible lines into account. For example, it can be negative for
2008 partially visible lines at the top of a window. */
2009 if (!s
->row
->full_width_p
2010 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2011 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2013 r
.y
= max (0, s
->row
->y
);
2016 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2018 /* If drawing the cursor, don't let glyph draw outside its
2019 advertised boundaries. Cleartype does this under some circumstances. */
2020 if (s
->hl
== DRAW_CURSOR
)
2022 struct glyph
*glyph
= s
->first_glyph
;
2027 r
.width
-= s
->x
- r
.x
;
2030 r
.width
= min (r
.width
, glyph
->pixel_width
);
2032 /* If r.y is below window bottom, ensure that we still see a cursor. */
2033 height
= min (glyph
->ascent
+ glyph
->descent
,
2034 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2035 max_y
= window_text_bottom_y (s
->w
) - height
;
2036 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2037 if (s
->ybase
- glyph
->ascent
> max_y
)
2044 /* Don't draw cursor glyph taller than our actual glyph. */
2045 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2046 if (height
< r
.height
)
2048 max_y
= r
.y
+ r
.height
;
2049 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2050 r
.height
= min (max_y
- r
.y
, height
);
2057 XRectangle r_save
= r
;
2059 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2063 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2064 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2066 #ifdef CONVERT_FROM_XRECT
2067 CONVERT_FROM_XRECT (r
, *rects
);
2075 /* If we are processing overlapping and allowed to return
2076 multiple clipping rectangles, we exclude the row of the glyph
2077 string from the clipping rectangle. This is to avoid drawing
2078 the same text on the environment with anti-aliasing. */
2079 #ifdef CONVERT_FROM_XRECT
2082 XRectangle
*rs
= rects
;
2084 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2086 if (s
->for_overlaps
& OVERLAPS_PRED
)
2089 if (r
.y
+ r
.height
> row_y
)
2092 rs
[i
].height
= row_y
- r
.y
;
2098 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2101 if (r
.y
< row_y
+ s
->row
->visible_height
)
2103 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2105 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2106 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2115 #ifdef CONVERT_FROM_XRECT
2116 for (i
= 0; i
< n
; i
++)
2117 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2124 Return in *NR the clipping rectangle for glyph string S. */
2127 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2129 get_glyph_string_clip_rects (s
, nr
, 1);
2134 Return the position and height of the phys cursor in window W.
2135 Set w->phys_cursor_width to width of phys cursor.
2139 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2140 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2142 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2143 int x
, y
, wd
, h
, h0
, y0
;
2145 /* Compute the width of the rectangle to draw. If on a stretch
2146 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2147 rectangle as wide as the glyph, but use a canonical character
2149 wd
= glyph
->pixel_width
- 1;
2150 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2154 x
= w
->phys_cursor
.x
;
2161 if (glyph
->type
== STRETCH_GLYPH
2162 && !x_stretch_cursor_p
)
2163 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2164 w
->phys_cursor_width
= wd
;
2166 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2168 /* If y is below window bottom, ensure that we still see a cursor. */
2169 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2171 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2172 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2174 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2177 h
= max (h
- (y0
- y
) + 1, h0
);
2182 y0
= window_text_bottom_y (w
) - h0
;
2190 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2191 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2196 * Remember which glyph the mouse is over.
2200 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2204 struct glyph_row
*r
, *gr
, *end_row
;
2205 enum window_part part
;
2206 enum glyph_row_area area
;
2207 int x
, y
, width
, height
;
2209 /* Try to determine frame pixel position and size of the glyph under
2210 frame pixel coordinates X/Y on frame F. */
2212 if (!f
->glyphs_initialized_p
2213 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2216 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2217 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2221 w
= XWINDOW (window
);
2222 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2223 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2225 x
= window_relative_x_coord (w
, part
, gx
);
2226 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2228 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2229 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2231 if (w
->pseudo_window_p
)
2234 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2240 case ON_LEFT_MARGIN
:
2241 area
= LEFT_MARGIN_AREA
;
2244 case ON_RIGHT_MARGIN
:
2245 area
= RIGHT_MARGIN_AREA
;
2248 case ON_HEADER_LINE
:
2250 gr
= (part
== ON_HEADER_LINE
2251 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2252 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2255 goto text_glyph_row_found
;
2262 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2263 if (r
->y
+ r
->height
> y
)
2269 text_glyph_row_found
:
2272 struct glyph
*g
= gr
->glyphs
[area
];
2273 struct glyph
*end
= g
+ gr
->used
[area
];
2275 height
= gr
->height
;
2276 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2277 if (gx
+ g
->pixel_width
> x
)
2282 if (g
->type
== IMAGE_GLYPH
)
2284 /* Don't remember when mouse is over image, as
2285 image may have hot-spots. */
2286 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2289 width
= g
->pixel_width
;
2293 /* Use nominal char spacing at end of line. */
2295 gx
+= (x
/ width
) * width
;
2298 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2299 gx
+= window_box_left_offset (w
, area
);
2303 /* Use nominal line height at end of window. */
2304 gx
= (x
/ width
) * width
;
2306 gy
+= (y
/ height
) * height
;
2310 case ON_LEFT_FRINGE
:
2311 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2312 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2313 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2314 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2317 case ON_RIGHT_FRINGE
:
2318 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2319 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2320 : window_box_right_offset (w
, TEXT_AREA
));
2321 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2325 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2327 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2328 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2329 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2331 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2335 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2336 if (r
->y
+ r
->height
> y
)
2343 height
= gr
->height
;
2346 /* Use nominal line height at end of window. */
2348 gy
+= (y
/ height
) * height
;
2355 /* If there is no glyph under the mouse, then we divide the screen
2356 into a grid of the smallest glyph in the frame, and use that
2359 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2360 round down even for negative values. */
2366 gx
= (gx
/ width
) * width
;
2367 gy
= (gy
/ height
) * height
;
2372 gx
+= WINDOW_LEFT_EDGE_X (w
);
2373 gy
+= WINDOW_TOP_EDGE_Y (w
);
2376 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2378 /* Visible feedback for debugging. */
2381 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2382 f
->output_data
.x
->normal_gc
,
2383 gx
, gy
, width
, height
);
2389 #endif /* HAVE_WINDOW_SYSTEM */
2392 /***********************************************************************
2393 Lisp form evaluation
2394 ***********************************************************************/
2396 /* Error handler for safe_eval and safe_call. */
2399 safe_eval_handler (Lisp_Object arg
)
2401 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2406 /* Evaluate SEXPR and return the result, or nil if something went
2407 wrong. Prevent redisplay during the evaluation. */
2409 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2410 Return the result, or nil if something went wrong. Prevent
2411 redisplay during the evaluation. */
2414 safe_call (ptrdiff_t nargs
, Lisp_Object
*args
)
2418 if (inhibit_eval_during_redisplay
)
2422 ptrdiff_t count
= SPECPDL_INDEX ();
2423 struct gcpro gcpro1
;
2426 gcpro1
.nvars
= nargs
;
2427 specbind (Qinhibit_redisplay
, Qt
);
2428 /* Use Qt to ensure debugger does not run,
2429 so there is no possibility of wanting to redisplay. */
2430 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2433 val
= unbind_to (count
, val
);
2440 /* Call function FN with one argument ARG.
2441 Return the result, or nil if something went wrong. */
2444 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2446 Lisp_Object args
[2];
2449 return safe_call (2, args
);
2452 static Lisp_Object Qeval
;
2455 safe_eval (Lisp_Object sexpr
)
2457 return safe_call1 (Qeval
, sexpr
);
2460 /* Call function FN with one argument ARG.
2461 Return the result, or nil if something went wrong. */
2464 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2466 Lisp_Object args
[3];
2470 return safe_call (3, args
);
2475 /***********************************************************************
2477 ***********************************************************************/
2481 /* Define CHECK_IT to perform sanity checks on iterators.
2482 This is for debugging. It is too slow to do unconditionally. */
2485 check_it (struct it
*it
)
2487 if (it
->method
== GET_FROM_STRING
)
2489 eassert (STRINGP (it
->string
));
2490 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2494 eassert (IT_STRING_CHARPOS (*it
) < 0);
2495 if (it
->method
== GET_FROM_BUFFER
)
2497 /* Check that character and byte positions agree. */
2498 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2503 eassert (it
->current
.dpvec_index
>= 0);
2505 eassert (it
->current
.dpvec_index
< 0);
2508 #define CHECK_IT(IT) check_it ((IT))
2512 #define CHECK_IT(IT) (void) 0
2517 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2519 /* Check that the window end of window W is what we expect it
2520 to be---the last row in the current matrix displaying text. */
2523 check_window_end (struct window
*w
)
2525 if (!MINI_WINDOW_P (w
)
2526 && !NILP (w
->window_end_valid
))
2528 struct glyph_row
*row
;
2529 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2530 XFASTINT (w
->window_end_vpos
)),
2532 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2533 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2537 #define CHECK_WINDOW_END(W) check_window_end ((W))
2541 #define CHECK_WINDOW_END(W) (void) 0
2543 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2547 /***********************************************************************
2548 Iterator initialization
2549 ***********************************************************************/
2551 /* Initialize IT for displaying current_buffer in window W, starting
2552 at character position CHARPOS. CHARPOS < 0 means that no buffer
2553 position is specified which is useful when the iterator is assigned
2554 a position later. BYTEPOS is the byte position corresponding to
2555 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2557 If ROW is not null, calls to produce_glyphs with IT as parameter
2558 will produce glyphs in that row.
2560 BASE_FACE_ID is the id of a base face to use. It must be one of
2561 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2562 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2563 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2565 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2566 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2567 will be initialized to use the corresponding mode line glyph row of
2568 the desired matrix of W. */
2571 init_iterator (struct it
*it
, struct window
*w
,
2572 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2573 struct glyph_row
*row
, enum face_id base_face_id
)
2575 int highlight_region_p
;
2576 enum face_id remapped_base_face_id
= base_face_id
;
2578 /* Some precondition checks. */
2579 eassert (w
!= NULL
&& it
!= NULL
);
2580 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2583 /* If face attributes have been changed since the last redisplay,
2584 free realized faces now because they depend on face definitions
2585 that might have changed. Don't free faces while there might be
2586 desired matrices pending which reference these faces. */
2587 if (face_change_count
&& !inhibit_free_realized_faces
)
2589 face_change_count
= 0;
2590 free_all_realized_faces (Qnil
);
2593 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2594 if (! NILP (Vface_remapping_alist
))
2595 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2597 /* Use one of the mode line rows of W's desired matrix if
2601 if (base_face_id
== MODE_LINE_FACE_ID
2602 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2603 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2604 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2605 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2609 memset (it
, 0, sizeof *it
);
2610 it
->current
.overlay_string_index
= -1;
2611 it
->current
.dpvec_index
= -1;
2612 it
->base_face_id
= remapped_base_face_id
;
2614 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2615 it
->paragraph_embedding
= L2R
;
2616 it
->bidi_it
.string
.lstring
= Qnil
;
2617 it
->bidi_it
.string
.s
= NULL
;
2618 it
->bidi_it
.string
.bufpos
= 0;
2620 /* The window in which we iterate over current_buffer: */
2621 XSETWINDOW (it
->window
, w
);
2623 it
->f
= XFRAME (w
->frame
);
2627 /* Extra space between lines (on window systems only). */
2628 if (base_face_id
== DEFAULT_FACE_ID
2629 && FRAME_WINDOW_P (it
->f
))
2631 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2632 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2633 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2634 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2635 * FRAME_LINE_HEIGHT (it
->f
));
2636 else if (it
->f
->extra_line_spacing
> 0)
2637 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2638 it
->max_extra_line_spacing
= 0;
2641 /* If realized faces have been removed, e.g. because of face
2642 attribute changes of named faces, recompute them. When running
2643 in batch mode, the face cache of the initial frame is null. If
2644 we happen to get called, make a dummy face cache. */
2645 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2646 init_frame_faces (it
->f
);
2647 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2648 recompute_basic_faces (it
->f
);
2650 /* Current value of the `slice', `space-width', and 'height' properties. */
2651 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2652 it
->space_width
= Qnil
;
2653 it
->font_height
= Qnil
;
2654 it
->override_ascent
= -1;
2656 /* Are control characters displayed as `^C'? */
2657 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2659 /* -1 means everything between a CR and the following line end
2660 is invisible. >0 means lines indented more than this value are
2662 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2663 ? clip_to_bounds (-1, XINT (BVAR (current_buffer
,
2664 selective_display
)),
2666 : (!NILP (BVAR (current_buffer
, selective_display
))
2668 it
->selective_display_ellipsis_p
2669 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2671 /* Display table to use. */
2672 it
->dp
= window_display_table (w
);
2674 /* Are multibyte characters enabled in current_buffer? */
2675 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2677 /* Non-zero if we should highlight the region. */
2679 = (!NILP (Vtransient_mark_mode
)
2680 && !NILP (BVAR (current_buffer
, mark_active
))
2681 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2683 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2684 start and end of a visible region in window IT->w. Set both to
2685 -1 to indicate no region. */
2686 if (highlight_region_p
2687 /* Maybe highlight only in selected window. */
2688 && (/* Either show region everywhere. */
2689 highlight_nonselected_windows
2690 /* Or show region in the selected window. */
2691 || w
== XWINDOW (selected_window
)
2692 /* Or show the region if we are in the mini-buffer and W is
2693 the window the mini-buffer refers to. */
2694 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2695 && WINDOWP (minibuf_selected_window
)
2696 && w
== XWINDOW (minibuf_selected_window
))))
2698 ptrdiff_t markpos
= marker_position (BVAR (current_buffer
, mark
));
2699 it
->region_beg_charpos
= min (PT
, markpos
);
2700 it
->region_end_charpos
= max (PT
, markpos
);
2703 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2705 /* Get the position at which the redisplay_end_trigger hook should
2706 be run, if it is to be run at all. */
2707 if (MARKERP (w
->redisplay_end_trigger
)
2708 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2709 it
->redisplay_end_trigger_charpos
2710 = marker_position (w
->redisplay_end_trigger
);
2711 else if (INTEGERP (w
->redisplay_end_trigger
))
2712 it
->redisplay_end_trigger_charpos
=
2713 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2715 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2717 /* Are lines in the display truncated? */
2718 if (base_face_id
!= DEFAULT_FACE_ID
2720 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2721 && ((!NILP (Vtruncate_partial_width_windows
)
2722 && !INTEGERP (Vtruncate_partial_width_windows
))
2723 || (INTEGERP (Vtruncate_partial_width_windows
)
2724 && (WINDOW_TOTAL_COLS (it
->w
)
2725 < XINT (Vtruncate_partial_width_windows
))))))
2726 it
->line_wrap
= TRUNCATE
;
2727 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2728 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2729 ? WINDOW_WRAP
: WORD_WRAP
;
2731 it
->line_wrap
= TRUNCATE
;
2733 /* Get dimensions of truncation and continuation glyphs. These are
2734 displayed as fringe bitmaps under X, so we don't need them for such
2736 if (!FRAME_WINDOW_P (it
->f
))
2738 if (it
->line_wrap
== TRUNCATE
)
2740 /* We will need the truncation glyph. */
2741 eassert (it
->glyph_row
== NULL
);
2742 produce_special_glyphs (it
, IT_TRUNCATION
);
2743 it
->truncation_pixel_width
= it
->pixel_width
;
2747 /* We will need the continuation glyph. */
2748 eassert (it
->glyph_row
== NULL
);
2749 produce_special_glyphs (it
, IT_CONTINUATION
);
2750 it
->continuation_pixel_width
= it
->pixel_width
;
2753 /* Reset these values to zero because the produce_special_glyphs
2754 above has changed them. */
2755 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2756 it
->phys_ascent
= it
->phys_descent
= 0;
2759 /* Set this after getting the dimensions of truncation and
2760 continuation glyphs, so that we don't produce glyphs when calling
2761 produce_special_glyphs, above. */
2762 it
->glyph_row
= row
;
2763 it
->area
= TEXT_AREA
;
2765 /* Forget any previous info about this row being reversed. */
2767 it
->glyph_row
->reversed_p
= 0;
2769 /* Get the dimensions of the display area. The display area
2770 consists of the visible window area plus a horizontally scrolled
2771 part to the left of the window. All x-values are relative to the
2772 start of this total display area. */
2773 if (base_face_id
!= DEFAULT_FACE_ID
)
2775 /* Mode lines, menu bar in terminal frames. */
2776 it
->first_visible_x
= 0;
2777 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2781 it
->first_visible_x
=
2782 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2783 it
->last_visible_x
= (it
->first_visible_x
2784 + window_box_width (w
, TEXT_AREA
));
2786 /* If we truncate lines, leave room for the truncator glyph(s) at
2787 the right margin. Otherwise, leave room for the continuation
2788 glyph(s). Truncation and continuation glyphs are not inserted
2789 for window-based redisplay. */
2790 if (!FRAME_WINDOW_P (it
->f
))
2792 if (it
->line_wrap
== TRUNCATE
)
2793 it
->last_visible_x
-= it
->truncation_pixel_width
;
2795 it
->last_visible_x
-= it
->continuation_pixel_width
;
2798 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2799 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2802 /* Leave room for a border glyph. */
2803 if (!FRAME_WINDOW_P (it
->f
)
2804 && !WINDOW_RIGHTMOST_P (it
->w
))
2805 it
->last_visible_x
-= 1;
2807 it
->last_visible_y
= window_text_bottom_y (w
);
2809 /* For mode lines and alike, arrange for the first glyph having a
2810 left box line if the face specifies a box. */
2811 if (base_face_id
!= DEFAULT_FACE_ID
)
2815 it
->face_id
= remapped_base_face_id
;
2817 /* If we have a boxed mode line, make the first character appear
2818 with a left box line. */
2819 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2820 if (face
->box
!= FACE_NO_BOX
)
2821 it
->start_of_box_run_p
= 1;
2824 /* If a buffer position was specified, set the iterator there,
2825 getting overlays and face properties from that position. */
2826 if (charpos
>= BUF_BEG (current_buffer
))
2828 it
->end_charpos
= ZV
;
2829 IT_CHARPOS (*it
) = charpos
;
2831 /* We will rely on `reseat' to set this up properly, via
2832 handle_face_prop. */
2833 it
->face_id
= it
->base_face_id
;
2835 /* Compute byte position if not specified. */
2836 if (bytepos
< charpos
)
2837 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2839 IT_BYTEPOS (*it
) = bytepos
;
2841 it
->start
= it
->current
;
2842 /* Do we need to reorder bidirectional text? Not if this is a
2843 unibyte buffer: by definition, none of the single-byte
2844 characters are strong R2L, so no reordering is needed. And
2845 bidi.c doesn't support unibyte buffers anyway. Also, don't
2846 reorder while we are loading loadup.el, since the tables of
2847 character properties needed for reordering are not yet
2851 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2854 /* If we are to reorder bidirectional text, init the bidi
2858 /* Note the paragraph direction that this buffer wants to
2860 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2862 it
->paragraph_embedding
= L2R
;
2863 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2865 it
->paragraph_embedding
= R2L
;
2867 it
->paragraph_embedding
= NEUTRAL_DIR
;
2868 bidi_unshelve_cache (NULL
, 0);
2869 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2873 /* Compute faces etc. */
2874 reseat (it
, it
->current
.pos
, 1);
2881 /* Initialize IT for the display of window W with window start POS. */
2884 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2886 struct glyph_row
*row
;
2887 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2889 row
= w
->desired_matrix
->rows
+ first_vpos
;
2890 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2891 it
->first_vpos
= first_vpos
;
2893 /* Don't reseat to previous visible line start if current start
2894 position is in a string or image. */
2895 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2897 int start_at_line_beg_p
;
2898 int first_y
= it
->current_y
;
2900 /* If window start is not at a line start, skip forward to POS to
2901 get the correct continuation lines width. */
2902 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2903 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2904 if (!start_at_line_beg_p
)
2908 reseat_at_previous_visible_line_start (it
);
2909 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2911 new_x
= it
->current_x
+ it
->pixel_width
;
2913 /* If lines are continued, this line may end in the middle
2914 of a multi-glyph character (e.g. a control character
2915 displayed as \003, or in the middle of an overlay
2916 string). In this case move_it_to above will not have
2917 taken us to the start of the continuation line but to the
2918 end of the continued line. */
2919 if (it
->current_x
> 0
2920 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2921 && (/* And glyph doesn't fit on the line. */
2922 new_x
> it
->last_visible_x
2923 /* Or it fits exactly and we're on a window
2925 || (new_x
== it
->last_visible_x
2926 && FRAME_WINDOW_P (it
->f
))))
2928 if ((it
->current
.dpvec_index
>= 0
2929 || it
->current
.overlay_string_index
>= 0)
2930 /* If we are on a newline from a display vector or
2931 overlay string, then we are already at the end of
2932 a screen line; no need to go to the next line in
2933 that case, as this line is not really continued.
2934 (If we do go to the next line, C-e will not DTRT.) */
2937 set_iterator_to_next (it
, 1);
2938 move_it_in_display_line_to (it
, -1, -1, 0);
2941 it
->continuation_lines_width
+= it
->current_x
;
2943 /* If the character at POS is displayed via a display
2944 vector, move_it_to above stops at the final glyph of
2945 IT->dpvec. To make the caller redisplay that character
2946 again (a.k.a. start at POS), we need to reset the
2947 dpvec_index to the beginning of IT->dpvec. */
2948 else if (it
->current
.dpvec_index
>= 0)
2949 it
->current
.dpvec_index
= 0;
2951 /* We're starting a new display line, not affected by the
2952 height of the continued line, so clear the appropriate
2953 fields in the iterator structure. */
2954 it
->max_ascent
= it
->max_descent
= 0;
2955 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2957 it
->current_y
= first_y
;
2959 it
->current_x
= it
->hpos
= 0;
2965 /* Return 1 if POS is a position in ellipses displayed for invisible
2966 text. W is the window we display, for text property lookup. */
2969 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2971 Lisp_Object prop
, window
;
2973 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2975 /* If POS specifies a position in a display vector, this might
2976 be for an ellipsis displayed for invisible text. We won't
2977 get the iterator set up for delivering that ellipsis unless
2978 we make sure that it gets aware of the invisible text. */
2979 if (pos
->dpvec_index
>= 0
2980 && pos
->overlay_string_index
< 0
2981 && CHARPOS (pos
->string_pos
) < 0
2983 && (XSETWINDOW (window
, w
),
2984 prop
= Fget_char_property (make_number (charpos
),
2985 Qinvisible
, window
),
2986 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2988 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2990 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2997 /* Initialize IT for stepping through current_buffer in window W,
2998 starting at position POS that includes overlay string and display
2999 vector/ control character translation position information. Value
3000 is zero if there are overlay strings with newlines at POS. */
3003 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3005 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3006 int i
, overlay_strings_with_newlines
= 0;
3008 /* If POS specifies a position in a display vector, this might
3009 be for an ellipsis displayed for invisible text. We won't
3010 get the iterator set up for delivering that ellipsis unless
3011 we make sure that it gets aware of the invisible text. */
3012 if (in_ellipses_for_invisible_text_p (pos
, w
))
3018 /* Keep in mind: the call to reseat in init_iterator skips invisible
3019 text, so we might end up at a position different from POS. This
3020 is only a problem when POS is a row start after a newline and an
3021 overlay starts there with an after-string, and the overlay has an
3022 invisible property. Since we don't skip invisible text in
3023 display_line and elsewhere immediately after consuming the
3024 newline before the row start, such a POS will not be in a string,
3025 but the call to init_iterator below will move us to the
3027 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3029 /* This only scans the current chunk -- it should scan all chunks.
3030 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3031 to 16 in 22.1 to make this a lesser problem. */
3032 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3034 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3035 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3037 while (s
< e
&& *s
!= '\n')
3042 overlay_strings_with_newlines
= 1;
3047 /* If position is within an overlay string, set up IT to the right
3049 if (pos
->overlay_string_index
>= 0)
3053 /* If the first overlay string happens to have a `display'
3054 property for an image, the iterator will be set up for that
3055 image, and we have to undo that setup first before we can
3056 correct the overlay string index. */
3057 if (it
->method
== GET_FROM_IMAGE
)
3060 /* We already have the first chunk of overlay strings in
3061 IT->overlay_strings. Load more until the one for
3062 pos->overlay_string_index is in IT->overlay_strings. */
3063 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3065 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3066 it
->current
.overlay_string_index
= 0;
3069 load_overlay_strings (it
, 0);
3070 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3074 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3075 relative_index
= (it
->current
.overlay_string_index
3076 % OVERLAY_STRING_CHUNK_SIZE
);
3077 it
->string
= it
->overlay_strings
[relative_index
];
3078 eassert (STRINGP (it
->string
));
3079 it
->current
.string_pos
= pos
->string_pos
;
3080 it
->method
= GET_FROM_STRING
;
3083 if (CHARPOS (pos
->string_pos
) >= 0)
3085 /* Recorded position is not in an overlay string, but in another
3086 string. This can only be a string from a `display' property.
3087 IT should already be filled with that string. */
3088 it
->current
.string_pos
= pos
->string_pos
;
3089 eassert (STRINGP (it
->string
));
3092 /* Restore position in display vector translations, control
3093 character translations or ellipses. */
3094 if (pos
->dpvec_index
>= 0)
3096 if (it
->dpvec
== NULL
)
3097 get_next_display_element (it
);
3098 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3099 it
->current
.dpvec_index
= pos
->dpvec_index
;
3103 return !overlay_strings_with_newlines
;
3107 /* Initialize IT for stepping through current_buffer in window W
3108 starting at ROW->start. */
3111 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3113 init_from_display_pos (it
, w
, &row
->start
);
3114 it
->start
= row
->start
;
3115 it
->continuation_lines_width
= row
->continuation_lines_width
;
3120 /* Initialize IT for stepping through current_buffer in window W
3121 starting in the line following ROW, i.e. starting at ROW->end.
3122 Value is zero if there are overlay strings with newlines at ROW's
3126 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3130 if (init_from_display_pos (it
, w
, &row
->end
))
3132 if (row
->continued_p
)
3133 it
->continuation_lines_width
3134 = row
->continuation_lines_width
+ row
->pixel_width
;
3145 /***********************************************************************
3147 ***********************************************************************/
3149 /* Called when IT reaches IT->stop_charpos. Handle text property and
3150 overlay changes. Set IT->stop_charpos to the next position where
3154 handle_stop (struct it
*it
)
3156 enum prop_handled handled
;
3157 int handle_overlay_change_p
;
3161 it
->current
.dpvec_index
= -1;
3162 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3163 it
->ignore_overlay_strings_at_pos_p
= 0;
3166 /* Use face of preceding text for ellipsis (if invisible) */
3167 if (it
->selective_display_ellipsis_p
)
3168 it
->saved_face_id
= it
->face_id
;
3172 handled
= HANDLED_NORMALLY
;
3174 /* Call text property handlers. */
3175 for (p
= it_props
; p
->handler
; ++p
)
3177 handled
= p
->handler (it
);
3179 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3181 else if (handled
== HANDLED_RETURN
)
3183 /* We still want to show before and after strings from
3184 overlays even if the actual buffer text is replaced. */
3185 if (!handle_overlay_change_p
3187 /* Don't call get_overlay_strings_1 if we already
3188 have overlay strings loaded, because doing so
3189 will load them again and push the iterator state
3190 onto the stack one more time, which is not
3191 expected by the rest of the code that processes
3193 || (it
->current
.overlay_string_index
< 0
3194 ? !get_overlay_strings_1 (it
, 0, 0)
3198 setup_for_ellipsis (it
, 0);
3199 /* When handling a display spec, we might load an
3200 empty string. In that case, discard it here. We
3201 used to discard it in handle_single_display_spec,
3202 but that causes get_overlay_strings_1, above, to
3203 ignore overlay strings that we must check. */
3204 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3208 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3212 it
->ignore_overlay_strings_at_pos_p
= 1;
3213 it
->string_from_display_prop_p
= 0;
3214 it
->from_disp_prop_p
= 0;
3215 handle_overlay_change_p
= 0;
3217 handled
= HANDLED_RECOMPUTE_PROPS
;
3220 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3221 handle_overlay_change_p
= 0;
3224 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3226 /* Don't check for overlay strings below when set to deliver
3227 characters from a display vector. */
3228 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3229 handle_overlay_change_p
= 0;
3231 /* Handle overlay changes.
3232 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3233 if it finds overlays. */
3234 if (handle_overlay_change_p
)
3235 handled
= handle_overlay_change (it
);
3240 setup_for_ellipsis (it
, 0);
3244 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3246 /* Determine where to stop next. */
3247 if (handled
== HANDLED_NORMALLY
)
3248 compute_stop_pos (it
);
3252 /* Compute IT->stop_charpos from text property and overlay change
3253 information for IT's current position. */
3256 compute_stop_pos (struct it
*it
)
3258 register INTERVAL iv
, next_iv
;
3259 Lisp_Object object
, limit
, position
;
3260 ptrdiff_t charpos
, bytepos
;
3262 if (STRINGP (it
->string
))
3264 /* Strings are usually short, so don't limit the search for
3266 it
->stop_charpos
= it
->end_charpos
;
3267 object
= it
->string
;
3269 charpos
= IT_STRING_CHARPOS (*it
);
3270 bytepos
= IT_STRING_BYTEPOS (*it
);
3276 /* If end_charpos is out of range for some reason, such as a
3277 misbehaving display function, rationalize it (Bug#5984). */
3278 if (it
->end_charpos
> ZV
)
3279 it
->end_charpos
= ZV
;
3280 it
->stop_charpos
= it
->end_charpos
;
3282 /* If next overlay change is in front of the current stop pos
3283 (which is IT->end_charpos), stop there. Note: value of
3284 next_overlay_change is point-max if no overlay change
3286 charpos
= IT_CHARPOS (*it
);
3287 bytepos
= IT_BYTEPOS (*it
);
3288 pos
= next_overlay_change (charpos
);
3289 if (pos
< it
->stop_charpos
)
3290 it
->stop_charpos
= pos
;
3292 /* If showing the region, we have to stop at the region
3293 start or end because the face might change there. */
3294 if (it
->region_beg_charpos
> 0)
3296 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3297 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3298 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3299 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3302 /* Set up variables for computing the stop position from text
3303 property changes. */
3304 XSETBUFFER (object
, current_buffer
);
3305 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3308 /* Get the interval containing IT's position. Value is a null
3309 interval if there isn't such an interval. */
3310 position
= make_number (charpos
);
3311 iv
= validate_interval_range (object
, &position
, &position
, 0);
3312 if (!NULL_INTERVAL_P (iv
))
3314 Lisp_Object values_here
[LAST_PROP_IDX
];
3317 /* Get properties here. */
3318 for (p
= it_props
; p
->handler
; ++p
)
3319 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3321 /* Look for an interval following iv that has different
3323 for (next_iv
= next_interval (iv
);
3324 (!NULL_INTERVAL_P (next_iv
)
3326 || XFASTINT (limit
) > next_iv
->position
));
3327 next_iv
= next_interval (next_iv
))
3329 for (p
= it_props
; p
->handler
; ++p
)
3331 Lisp_Object new_value
;
3333 new_value
= textget (next_iv
->plist
, *p
->name
);
3334 if (!EQ (values_here
[p
->idx
], new_value
))
3342 if (!NULL_INTERVAL_P (next_iv
))
3344 if (INTEGERP (limit
)
3345 && next_iv
->position
>= XFASTINT (limit
))
3346 /* No text property change up to limit. */
3347 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3349 /* Text properties change in next_iv. */
3350 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3354 if (it
->cmp_it
.id
< 0)
3356 ptrdiff_t stoppos
= it
->end_charpos
;
3358 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3360 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3361 stoppos
, it
->string
);
3364 eassert (STRINGP (it
->string
)
3365 || (it
->stop_charpos
>= BEGV
3366 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3370 /* Return the position of the next overlay change after POS in
3371 current_buffer. Value is point-max if no overlay change
3372 follows. This is like `next-overlay-change' but doesn't use
3376 next_overlay_change (ptrdiff_t pos
)
3378 ptrdiff_t i
, noverlays
;
3380 Lisp_Object
*overlays
;
3382 /* Get all overlays at the given position. */
3383 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3385 /* If any of these overlays ends before endpos,
3386 use its ending point instead. */
3387 for (i
= 0; i
< noverlays
; ++i
)
3392 oend
= OVERLAY_END (overlays
[i
]);
3393 oendpos
= OVERLAY_POSITION (oend
);
3394 endpos
= min (endpos
, oendpos
);
3400 /* How many characters forward to search for a display property or
3401 display string. Searching too far forward makes the bidi display
3402 sluggish, especially in small windows. */
3403 #define MAX_DISP_SCAN 250
3405 /* Return the character position of a display string at or after
3406 position specified by POSITION. If no display string exists at or
3407 after POSITION, return ZV. A display string is either an overlay
3408 with `display' property whose value is a string, or a `display'
3409 text property whose value is a string. STRING is data about the
3410 string to iterate; if STRING->lstring is nil, we are iterating a
3411 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3412 on a GUI frame. DISP_PROP is set to zero if we searched
3413 MAX_DISP_SCAN characters forward without finding any display
3414 strings, non-zero otherwise. It is set to 2 if the display string
3415 uses any kind of `(space ...)' spec that will produce a stretch of
3416 white space in the text area. */
3418 compute_display_string_pos (struct text_pos
*position
,
3419 struct bidi_string_data
*string
,
3420 int frame_window_p
, int *disp_prop
)
3422 /* OBJECT = nil means current buffer. */
3423 Lisp_Object object
=
3424 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3425 Lisp_Object pos
, spec
, limpos
;
3426 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3427 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3428 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3429 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3431 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3432 struct text_pos tpos
;
3438 /* We don't support display properties whose values are strings
3439 that have display string properties. */
3440 || string
->from_disp_str
3441 /* C strings cannot have display properties. */
3442 || (string
->s
&& !STRINGP (object
)))
3448 /* If the character at CHARPOS is where the display string begins,
3450 pos
= make_number (charpos
);
3451 if (STRINGP (object
))
3452 bufpos
= string
->bufpos
;
3456 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3458 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3461 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3469 /* Look forward for the first character with a `display' property
3470 that will replace the underlying text when displayed. */
3471 limpos
= make_number (lim
);
3473 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3474 CHARPOS (tpos
) = XFASTINT (pos
);
3475 if (CHARPOS (tpos
) >= lim
)
3480 if (STRINGP (object
))
3481 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3483 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3484 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3485 if (!STRINGP (object
))
3486 bufpos
= CHARPOS (tpos
);
3487 } while (NILP (spec
)
3488 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3489 bufpos
, frame_window_p
)));
3493 return CHARPOS (tpos
);
3496 /* Return the character position of the end of the display string that
3497 started at CHARPOS. If there's no display string at CHARPOS,
3498 return -1. A display string is either an overlay with `display'
3499 property whose value is a string or a `display' text property whose
3500 value is a string. */
3502 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3504 /* OBJECT = nil means current buffer. */
3505 Lisp_Object object
=
3506 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3507 Lisp_Object pos
= make_number (charpos
);
3509 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3511 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3514 /* It could happen that the display property or overlay was removed
3515 since we found it in compute_display_string_pos above. One way
3516 this can happen is if JIT font-lock was called (through
3517 handle_fontified_prop), and jit-lock-functions remove text
3518 properties or overlays from the portion of buffer that includes
3519 CHARPOS. Muse mode is known to do that, for example. In this
3520 case, we return -1 to the caller, to signal that no display
3521 string is actually present at CHARPOS. See bidi_fetch_char for
3522 how this is handled.
3524 An alternative would be to never look for display properties past
3525 it->stop_charpos. But neither compute_display_string_pos nor
3526 bidi_fetch_char that calls it know or care where the next
3528 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3531 /* Look forward for the first character where the `display' property
3533 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3535 return XFASTINT (pos
);
3540 /***********************************************************************
3542 ***********************************************************************/
3544 /* Handle changes in the `fontified' property of the current buffer by
3545 calling hook functions from Qfontification_functions to fontify
3548 static enum prop_handled
3549 handle_fontified_prop (struct it
*it
)
3551 Lisp_Object prop
, pos
;
3552 enum prop_handled handled
= HANDLED_NORMALLY
;
3554 if (!NILP (Vmemory_full
))
3557 /* Get the value of the `fontified' property at IT's current buffer
3558 position. (The `fontified' property doesn't have a special
3559 meaning in strings.) If the value is nil, call functions from
3560 Qfontification_functions. */
3561 if (!STRINGP (it
->string
)
3563 && !NILP (Vfontification_functions
)
3564 && !NILP (Vrun_hooks
)
3565 && (pos
= make_number (IT_CHARPOS (*it
)),
3566 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3567 /* Ignore the special cased nil value always present at EOB since
3568 no amount of fontifying will be able to change it. */
3569 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3571 ptrdiff_t count
= SPECPDL_INDEX ();
3573 struct buffer
*obuf
= current_buffer
;
3574 int begv
= BEGV
, zv
= ZV
;
3575 int old_clip_changed
= current_buffer
->clip_changed
;
3577 val
= Vfontification_functions
;
3578 specbind (Qfontification_functions
, Qnil
);
3580 eassert (it
->end_charpos
== ZV
);
3582 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3583 safe_call1 (val
, pos
);
3586 Lisp_Object fns
, fn
;
3587 struct gcpro gcpro1
, gcpro2
;
3592 for (; CONSP (val
); val
= XCDR (val
))
3598 /* A value of t indicates this hook has a local
3599 binding; it means to run the global binding too.
3600 In a global value, t should not occur. If it
3601 does, we must ignore it to avoid an endless
3603 for (fns
= Fdefault_value (Qfontification_functions
);
3609 safe_call1 (fn
, pos
);
3613 safe_call1 (fn
, pos
);
3619 unbind_to (count
, Qnil
);
3621 /* Fontification functions routinely call `save-restriction'.
3622 Normally, this tags clip_changed, which can confuse redisplay
3623 (see discussion in Bug#6671). Since we don't perform any
3624 special handling of fontification changes in the case where
3625 `save-restriction' isn't called, there's no point doing so in
3626 this case either. So, if the buffer's restrictions are
3627 actually left unchanged, reset clip_changed. */
3628 if (obuf
== current_buffer
)
3630 if (begv
== BEGV
&& zv
== ZV
)
3631 current_buffer
->clip_changed
= old_clip_changed
;
3633 /* There isn't much we can reasonably do to protect against
3634 misbehaving fontification, but here's a fig leaf. */
3635 else if (!NILP (BVAR (obuf
, name
)))
3636 set_buffer_internal_1 (obuf
);
3638 /* The fontification code may have added/removed text.
3639 It could do even a lot worse, but let's at least protect against
3640 the most obvious case where only the text past `pos' gets changed',
3641 as is/was done in grep.el where some escapes sequences are turned
3642 into face properties (bug#7876). */
3643 it
->end_charpos
= ZV
;
3645 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3646 something. This avoids an endless loop if they failed to
3647 fontify the text for which reason ever. */
3648 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3649 handled
= HANDLED_RECOMPUTE_PROPS
;
3657 /***********************************************************************
3659 ***********************************************************************/
3661 /* Set up iterator IT from face properties at its current position.
3662 Called from handle_stop. */
3664 static enum prop_handled
3665 handle_face_prop (struct it
*it
)
3668 ptrdiff_t next_stop
;
3670 if (!STRINGP (it
->string
))
3673 = face_at_buffer_position (it
->w
,
3675 it
->region_beg_charpos
,
3676 it
->region_end_charpos
,
3679 + TEXT_PROP_DISTANCE_LIMIT
),
3680 0, it
->base_face_id
);
3682 /* Is this a start of a run of characters with box face?
3683 Caveat: this can be called for a freshly initialized
3684 iterator; face_id is -1 in this case. We know that the new
3685 face will not change until limit, i.e. if the new face has a
3686 box, all characters up to limit will have one. But, as
3687 usual, we don't know whether limit is really the end. */
3688 if (new_face_id
!= it
->face_id
)
3690 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3692 /* If new face has a box but old face has not, this is
3693 the start of a run of characters with box, i.e. it has
3694 a shadow on the left side. The value of face_id of the
3695 iterator will be -1 if this is the initial call that gets
3696 the face. In this case, we have to look in front of IT's
3697 position and see whether there is a face != new_face_id. */
3698 it
->start_of_box_run_p
3699 = (new_face
->box
!= FACE_NO_BOX
3700 && (it
->face_id
>= 0
3701 || IT_CHARPOS (*it
) == BEG
3702 || new_face_id
!= face_before_it_pos (it
)));
3703 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3711 Lisp_Object from_overlay
3712 = (it
->current
.overlay_string_index
>= 0
3713 ? it
->string_overlays
[it
->current
.overlay_string_index
3714 % OVERLAY_STRING_CHUNK_SIZE
]
3717 /* See if we got to this string directly or indirectly from
3718 an overlay property. That includes the before-string or
3719 after-string of an overlay, strings in display properties
3720 provided by an overlay, their text properties, etc.
3722 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3723 if (! NILP (from_overlay
))
3724 for (i
= it
->sp
- 1; i
>= 0; i
--)
3726 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3728 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3729 % OVERLAY_STRING_CHUNK_SIZE
];
3730 else if (! NILP (it
->stack
[i
].from_overlay
))
3731 from_overlay
= it
->stack
[i
].from_overlay
;
3733 if (!NILP (from_overlay
))
3737 if (! NILP (from_overlay
))
3739 bufpos
= IT_CHARPOS (*it
);
3740 /* For a string from an overlay, the base face depends
3741 only on text properties and ignores overlays. */
3743 = face_for_overlay_string (it
->w
,
3745 it
->region_beg_charpos
,
3746 it
->region_end_charpos
,
3749 + TEXT_PROP_DISTANCE_LIMIT
),
3757 /* For strings from a `display' property, use the face at
3758 IT's current buffer position as the base face to merge
3759 with, so that overlay strings appear in the same face as
3760 surrounding text, unless they specify their own
3762 base_face_id
= it
->string_from_prefix_prop_p
3764 : underlying_face_id (it
);
3767 new_face_id
= face_at_string_position (it
->w
,
3769 IT_STRING_CHARPOS (*it
),
3771 it
->region_beg_charpos
,
3772 it
->region_end_charpos
,
3776 /* Is this a start of a run of characters with box? Caveat:
3777 this can be called for a freshly allocated iterator; face_id
3778 is -1 is this case. We know that the new face will not
3779 change until the next check pos, i.e. if the new face has a
3780 box, all characters up to that position will have a
3781 box. But, as usual, we don't know whether that position
3782 is really the end. */
3783 if (new_face_id
!= it
->face_id
)
3785 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3786 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3788 /* If new face has a box but old face hasn't, this is the
3789 start of a run of characters with box, i.e. it has a
3790 shadow on the left side. */
3791 it
->start_of_box_run_p
3792 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3793 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3797 it
->face_id
= new_face_id
;
3798 return HANDLED_NORMALLY
;
3802 /* Return the ID of the face ``underlying'' IT's current position,
3803 which is in a string. If the iterator is associated with a
3804 buffer, return the face at IT's current buffer position.
3805 Otherwise, use the iterator's base_face_id. */
3808 underlying_face_id (struct it
*it
)
3810 int face_id
= it
->base_face_id
, i
;
3812 eassert (STRINGP (it
->string
));
3814 for (i
= it
->sp
- 1; i
>= 0; --i
)
3815 if (NILP (it
->stack
[i
].string
))
3816 face_id
= it
->stack
[i
].face_id
;
3822 /* Compute the face one character before or after the current position
3823 of IT, in the visual order. BEFORE_P non-zero means get the face
3824 in front (to the left in L2R paragraphs, to the right in R2L
3825 paragraphs) of IT's screen position. Value is the ID of the face. */
3828 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3831 ptrdiff_t next_check_charpos
;
3833 void *it_copy_data
= NULL
;
3835 eassert (it
->s
== NULL
);
3837 if (STRINGP (it
->string
))
3839 ptrdiff_t bufpos
, charpos
;
3842 /* No face change past the end of the string (for the case
3843 we are padding with spaces). No face change before the
3845 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3846 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3851 /* Set charpos to the position before or after IT's current
3852 position, in the logical order, which in the non-bidi
3853 case is the same as the visual order. */
3855 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3856 else if (it
->what
== IT_COMPOSITION
)
3857 /* For composition, we must check the character after the
3859 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3861 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3867 /* With bidi iteration, the character before the current
3868 in the visual order cannot be found by simple
3869 iteration, because "reverse" reordering is not
3870 supported. Instead, we need to use the move_it_*
3871 family of functions. */
3872 /* Ignore face changes before the first visible
3873 character on this display line. */
3874 if (it
->current_x
<= it
->first_visible_x
)
3876 SAVE_IT (it_copy
, *it
, it_copy_data
);
3877 /* Implementation note: Since move_it_in_display_line
3878 works in the iterator geometry, and thinks the first
3879 character is always the leftmost, even in R2L lines,
3880 we don't need to distinguish between the R2L and L2R
3882 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3883 it_copy
.current_x
- 1, MOVE_TO_X
);
3884 charpos
= IT_STRING_CHARPOS (it_copy
);
3885 RESTORE_IT (it
, it
, it_copy_data
);
3889 /* Set charpos to the string position of the character
3890 that comes after IT's current position in the visual
3892 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3896 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3898 charpos
= it_copy
.bidi_it
.charpos
;
3901 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3903 if (it
->current
.overlay_string_index
>= 0)
3904 bufpos
= IT_CHARPOS (*it
);
3908 base_face_id
= underlying_face_id (it
);
3910 /* Get the face for ASCII, or unibyte. */
3911 face_id
= face_at_string_position (it
->w
,
3915 it
->region_beg_charpos
,
3916 it
->region_end_charpos
,
3917 &next_check_charpos
,
3920 /* Correct the face for charsets different from ASCII. Do it
3921 for the multibyte case only. The face returned above is
3922 suitable for unibyte text if IT->string is unibyte. */
3923 if (STRING_MULTIBYTE (it
->string
))
3925 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3926 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3928 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3930 c
= string_char_and_length (p
, &len
);
3931 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3936 struct text_pos pos
;
3938 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3939 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3942 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3943 pos
= it
->current
.pos
;
3948 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3951 if (it
->what
== IT_COMPOSITION
)
3953 /* For composition, we must check the position after
3955 pos
.charpos
+= it
->cmp_it
.nchars
;
3956 pos
.bytepos
+= it
->len
;
3959 INC_TEXT_POS (pos
, it
->multibyte_p
);
3966 /* With bidi iteration, the character before the current
3967 in the visual order cannot be found by simple
3968 iteration, because "reverse" reordering is not
3969 supported. Instead, we need to use the move_it_*
3970 family of functions. */
3971 /* Ignore face changes before the first visible
3972 character on this display line. */
3973 if (it
->current_x
<= it
->first_visible_x
)
3975 SAVE_IT (it_copy
, *it
, it_copy_data
);
3976 /* Implementation note: Since move_it_in_display_line
3977 works in the iterator geometry, and thinks the first
3978 character is always the leftmost, even in R2L lines,
3979 we don't need to distinguish between the R2L and L2R
3981 move_it_in_display_line (&it_copy
, ZV
,
3982 it_copy
.current_x
- 1, MOVE_TO_X
);
3983 pos
= it_copy
.current
.pos
;
3984 RESTORE_IT (it
, it
, it_copy_data
);
3988 /* Set charpos to the buffer position of the character
3989 that comes after IT's current position in the visual
3991 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3995 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3998 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4001 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4003 /* Determine face for CHARSET_ASCII, or unibyte. */
4004 face_id
= face_at_buffer_position (it
->w
,
4006 it
->region_beg_charpos
,
4007 it
->region_end_charpos
,
4008 &next_check_charpos
,
4011 /* Correct the face for charsets different from ASCII. Do it
4012 for the multibyte case only. The face returned above is
4013 suitable for unibyte text if current_buffer is unibyte. */
4014 if (it
->multibyte_p
)
4016 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4017 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4018 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4027 /***********************************************************************
4029 ***********************************************************************/
4031 /* Set up iterator IT from invisible properties at its current
4032 position. Called from handle_stop. */
4034 static enum prop_handled
4035 handle_invisible_prop (struct it
*it
)
4037 enum prop_handled handled
= HANDLED_NORMALLY
;
4039 if (STRINGP (it
->string
))
4041 Lisp_Object prop
, end_charpos
, limit
, charpos
;
4043 /* Get the value of the invisible text property at the
4044 current position. Value will be nil if there is no such
4046 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4047 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4050 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4054 handled
= HANDLED_RECOMPUTE_PROPS
;
4056 /* Get the position at which the next change of the
4057 invisible text property can be found in IT->string.
4058 Value will be nil if the property value is the same for
4059 all the rest of IT->string. */
4060 XSETINT (limit
, SCHARS (it
->string
));
4061 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4064 /* Text at current position is invisible. The next
4065 change in the property is at position end_charpos.
4066 Move IT's current position to that position. */
4067 if (INTEGERP (end_charpos
)
4068 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
4070 struct text_pos old
;
4073 old
= it
->current
.string_pos
;
4074 oldpos
= CHARPOS (old
);
4077 if (it
->bidi_it
.first_elt
4078 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4079 bidi_paragraph_init (it
->paragraph_embedding
,
4081 /* Bidi-iterate out of the invisible text. */
4084 bidi_move_to_visually_next (&it
->bidi_it
);
4086 while (oldpos
<= it
->bidi_it
.charpos
4087 && it
->bidi_it
.charpos
< endpos
);
4089 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4090 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4091 if (IT_CHARPOS (*it
) >= endpos
)
4092 it
->prev_stop
= endpos
;
4096 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4097 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4102 /* The rest of the string is invisible. If this is an
4103 overlay string, proceed with the next overlay string
4104 or whatever comes and return a character from there. */
4105 if (it
->current
.overlay_string_index
>= 0)
4107 next_overlay_string (it
);
4108 /* Don't check for overlay strings when we just
4109 finished processing them. */
4110 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4114 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4115 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4123 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4124 Lisp_Object pos
, prop
, overlay
;
4126 /* First of all, is there invisible text at this position? */
4127 tem
= start_charpos
= IT_CHARPOS (*it
);
4128 pos
= make_number (tem
);
4129 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4131 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4133 /* If we are on invisible text, skip over it. */
4134 if (invis_p
&& start_charpos
< it
->end_charpos
)
4136 /* Record whether we have to display an ellipsis for the
4138 int display_ellipsis_p
= invis_p
== 2;
4140 handled
= HANDLED_RECOMPUTE_PROPS
;
4142 /* Loop skipping over invisible text. The loop is left at
4143 ZV or with IT on the first char being visible again. */
4146 /* Try to skip some invisible text. Return value is the
4147 position reached which can be equal to where we start
4148 if there is nothing invisible there. This skips both
4149 over invisible text properties and overlays with
4150 invisible property. */
4151 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4153 /* If we skipped nothing at all we weren't at invisible
4154 text in the first place. If everything to the end of
4155 the buffer was skipped, end the loop. */
4156 if (newpos
== tem
|| newpos
>= ZV
)
4160 /* We skipped some characters but not necessarily
4161 all there are. Check if we ended up on visible
4162 text. Fget_char_property returns the property of
4163 the char before the given position, i.e. if we
4164 get invis_p = 0, this means that the char at
4165 newpos is visible. */
4166 pos
= make_number (newpos
);
4167 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4168 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4171 /* If we ended up on invisible text, proceed to
4172 skip starting with next_stop. */
4176 /* If there are adjacent invisible texts, don't lose the
4177 second one's ellipsis. */
4179 display_ellipsis_p
= 1;
4183 /* The position newpos is now either ZV or on visible text. */
4186 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4188 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4190 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4192 /* If the invisible text ends on a newline or on a
4193 character after a newline, we can avoid the costly,
4194 character by character, bidi iteration to NEWPOS, and
4195 instead simply reseat the iterator there. That's
4196 because all bidi reordering information is tossed at
4197 the newline. This is a big win for modes that hide
4198 complete lines, like Outline, Org, etc. */
4199 if (on_newline
|| after_newline
)
4201 struct text_pos tpos
;
4202 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4204 SET_TEXT_POS (tpos
, newpos
, bpos
);
4205 reseat_1 (it
, tpos
, 0);
4206 /* If we reseat on a newline/ZV, we need to prep the
4207 bidi iterator for advancing to the next character
4208 after the newline/EOB, keeping the current paragraph
4209 direction (so that PRODUCE_GLYPHS does TRT wrt
4210 prepending/appending glyphs to a glyph row). */
4213 it
->bidi_it
.first_elt
= 0;
4214 it
->bidi_it
.paragraph_dir
= pdir
;
4215 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4216 it
->bidi_it
.nchars
= 1;
4217 it
->bidi_it
.ch_len
= 1;
4220 else /* Must use the slow method. */
4222 /* With bidi iteration, the region of invisible text
4223 could start and/or end in the middle of a
4224 non-base embedding level. Therefore, we need to
4225 skip invisible text using the bidi iterator,
4226 starting at IT's current position, until we find
4227 ourselves outside of the invisible text.
4228 Skipping invisible text _after_ bidi iteration
4229 avoids affecting the visual order of the
4230 displayed text when invisible properties are
4231 added or removed. */
4232 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4234 /* If we were `reseat'ed to a new paragraph,
4235 determine the paragraph base direction. We
4236 need to do it now because
4237 next_element_from_buffer may not have a
4238 chance to do it, if we are going to skip any
4239 text at the beginning, which resets the
4241 bidi_paragraph_init (it
->paragraph_embedding
,
4246 bidi_move_to_visually_next (&it
->bidi_it
);
4248 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4249 && it
->bidi_it
.charpos
< newpos
);
4250 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4251 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4252 /* If we overstepped NEWPOS, record its position in
4253 the iterator, so that we skip invisible text if
4254 later the bidi iteration lands us in the
4255 invisible region again. */
4256 if (IT_CHARPOS (*it
) >= newpos
)
4257 it
->prev_stop
= newpos
;
4262 IT_CHARPOS (*it
) = newpos
;
4263 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4266 /* If there are before-strings at the start of invisible
4267 text, and the text is invisible because of a text
4268 property, arrange to show before-strings because 20.x did
4269 it that way. (If the text is invisible because of an
4270 overlay property instead of a text property, this is
4271 already handled in the overlay code.) */
4273 && get_overlay_strings (it
, it
->stop_charpos
))
4275 handled
= HANDLED_RECOMPUTE_PROPS
;
4276 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4278 else if (display_ellipsis_p
)
4280 /* Make sure that the glyphs of the ellipsis will get
4281 correct `charpos' values. If we would not update
4282 it->position here, the glyphs would belong to the
4283 last visible character _before_ the invisible
4284 text, which confuses `set_cursor_from_row'.
4286 We use the last invisible position instead of the
4287 first because this way the cursor is always drawn on
4288 the first "." of the ellipsis, whenever PT is inside
4289 the invisible text. Otherwise the cursor would be
4290 placed _after_ the ellipsis when the point is after the
4291 first invisible character. */
4292 if (!STRINGP (it
->object
))
4294 it
->position
.charpos
= newpos
- 1;
4295 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4298 /* Let the ellipsis display before
4299 considering any properties of the following char.
4300 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4301 handled
= HANDLED_RETURN
;
4310 /* Make iterator IT return `...' next.
4311 Replaces LEN characters from buffer. */
4314 setup_for_ellipsis (struct it
*it
, int len
)
4316 /* Use the display table definition for `...'. Invalid glyphs
4317 will be handled by the method returning elements from dpvec. */
4318 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4320 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4321 it
->dpvec
= v
->contents
;
4322 it
->dpend
= v
->contents
+ v
->header
.size
;
4326 /* Default `...'. */
4327 it
->dpvec
= default_invis_vector
;
4328 it
->dpend
= default_invis_vector
+ 3;
4331 it
->dpvec_char_len
= len
;
4332 it
->current
.dpvec_index
= 0;
4333 it
->dpvec_face_id
= -1;
4335 /* Remember the current face id in case glyphs specify faces.
4336 IT's face is restored in set_iterator_to_next.
4337 saved_face_id was set to preceding char's face in handle_stop. */
4338 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4339 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4341 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4347 /***********************************************************************
4349 ***********************************************************************/
4351 /* Set up iterator IT from `display' property at its current position.
4352 Called from handle_stop.
4353 We return HANDLED_RETURN if some part of the display property
4354 overrides the display of the buffer text itself.
4355 Otherwise we return HANDLED_NORMALLY. */
4357 static enum prop_handled
4358 handle_display_prop (struct it
*it
)
4360 Lisp_Object propval
, object
, overlay
;
4361 struct text_pos
*position
;
4363 /* Nonzero if some property replaces the display of the text itself. */
4364 int display_replaced_p
= 0;
4366 if (STRINGP (it
->string
))
4368 object
= it
->string
;
4369 position
= &it
->current
.string_pos
;
4370 bufpos
= CHARPOS (it
->current
.pos
);
4374 XSETWINDOW (object
, it
->w
);
4375 position
= &it
->current
.pos
;
4376 bufpos
= CHARPOS (*position
);
4379 /* Reset those iterator values set from display property values. */
4380 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4381 it
->space_width
= Qnil
;
4382 it
->font_height
= Qnil
;
4385 /* We don't support recursive `display' properties, i.e. string
4386 values that have a string `display' property, that have a string
4387 `display' property etc. */
4388 if (!it
->string_from_display_prop_p
)
4389 it
->area
= TEXT_AREA
;
4391 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4392 Qdisplay
, object
, &overlay
);
4394 return HANDLED_NORMALLY
;
4395 /* Now OVERLAY is the overlay that gave us this property, or nil
4396 if it was a text property. */
4398 if (!STRINGP (it
->string
))
4399 object
= it
->w
->buffer
;
4401 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4403 FRAME_WINDOW_P (it
->f
));
4405 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4408 /* Subroutine of handle_display_prop. Returns non-zero if the display
4409 specification in SPEC is a replacing specification, i.e. it would
4410 replace the text covered by `display' property with something else,
4411 such as an image or a display string. If SPEC includes any kind or
4412 `(space ...) specification, the value is 2; this is used by
4413 compute_display_string_pos, which see.
4415 See handle_single_display_spec for documentation of arguments.
4416 frame_window_p is non-zero if the window being redisplayed is on a
4417 GUI frame; this argument is used only if IT is NULL, see below.
4419 IT can be NULL, if this is called by the bidi reordering code
4420 through compute_display_string_pos, which see. In that case, this
4421 function only examines SPEC, but does not otherwise "handle" it, in
4422 the sense that it doesn't set up members of IT from the display
4425 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4426 Lisp_Object overlay
, struct text_pos
*position
,
4427 ptrdiff_t bufpos
, int frame_window_p
)
4429 int replacing_p
= 0;
4433 /* Simple specifications. */
4434 && !EQ (XCAR (spec
), Qimage
)
4435 && !EQ (XCAR (spec
), Qspace
)
4436 && !EQ (XCAR (spec
), Qwhen
)
4437 && !EQ (XCAR (spec
), Qslice
)
4438 && !EQ (XCAR (spec
), Qspace_width
)
4439 && !EQ (XCAR (spec
), Qheight
)
4440 && !EQ (XCAR (spec
), Qraise
)
4441 /* Marginal area specifications. */
4442 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4443 && !EQ (XCAR (spec
), Qleft_fringe
)
4444 && !EQ (XCAR (spec
), Qright_fringe
)
4445 && !NILP (XCAR (spec
)))
4447 for (; CONSP (spec
); spec
= XCDR (spec
))
4449 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4450 overlay
, position
, bufpos
,
4451 replacing_p
, frame_window_p
)))
4454 /* If some text in a string is replaced, `position' no
4455 longer points to the position of `object'. */
4456 if (!it
|| STRINGP (object
))
4461 else if (VECTORP (spec
))
4464 for (i
= 0; i
< ASIZE (spec
); ++i
)
4465 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4466 overlay
, position
, bufpos
,
4467 replacing_p
, frame_window_p
)))
4470 /* If some text in a string is replaced, `position' no
4471 longer points to the position of `object'. */
4472 if (!it
|| STRINGP (object
))
4478 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4479 position
, bufpos
, 0,
4487 /* Value is the position of the end of the `display' property starting
4488 at START_POS in OBJECT. */
4490 static struct text_pos
4491 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4494 struct text_pos end_pos
;
4496 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4497 Qdisplay
, object
, Qnil
);
4498 CHARPOS (end_pos
) = XFASTINT (end
);
4499 if (STRINGP (object
))
4500 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4502 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4508 /* Set up IT from a single `display' property specification SPEC. OBJECT
4509 is the object in which the `display' property was found. *POSITION
4510 is the position in OBJECT at which the `display' property was found.
4511 BUFPOS is the buffer position of OBJECT (different from POSITION if
4512 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4513 previously saw a display specification which already replaced text
4514 display with something else, for example an image; we ignore such
4515 properties after the first one has been processed.
4517 OVERLAY is the overlay this `display' property came from,
4518 or nil if it was a text property.
4520 If SPEC is a `space' or `image' specification, and in some other
4521 cases too, set *POSITION to the position where the `display'
4524 If IT is NULL, only examine the property specification in SPEC, but
4525 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4526 is intended to be displayed in a window on a GUI frame.
4528 Value is non-zero if something was found which replaces the display
4529 of buffer or string text. */
4532 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4533 Lisp_Object overlay
, struct text_pos
*position
,
4534 ptrdiff_t bufpos
, int display_replaced_p
,
4538 Lisp_Object location
, value
;
4539 struct text_pos start_pos
= *position
;
4542 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4543 If the result is non-nil, use VALUE instead of SPEC. */
4545 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4554 if (!NILP (form
) && !EQ (form
, Qt
))
4556 ptrdiff_t count
= SPECPDL_INDEX ();
4557 struct gcpro gcpro1
;
4559 /* Bind `object' to the object having the `display' property, a
4560 buffer or string. Bind `position' to the position in the
4561 object where the property was found, and `buffer-position'
4562 to the current position in the buffer. */
4565 XSETBUFFER (object
, current_buffer
);
4566 specbind (Qobject
, object
);
4567 specbind (Qposition
, make_number (CHARPOS (*position
)));
4568 specbind (Qbuffer_position
, make_number (bufpos
));
4570 form
= safe_eval (form
);
4572 unbind_to (count
, Qnil
);
4578 /* Handle `(height HEIGHT)' specifications. */
4580 && EQ (XCAR (spec
), Qheight
)
4581 && CONSP (XCDR (spec
)))
4585 if (!FRAME_WINDOW_P (it
->f
))
4588 it
->font_height
= XCAR (XCDR (spec
));
4589 if (!NILP (it
->font_height
))
4591 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4592 int new_height
= -1;
4594 if (CONSP (it
->font_height
)
4595 && (EQ (XCAR (it
->font_height
), Qplus
)
4596 || EQ (XCAR (it
->font_height
), Qminus
))
4597 && CONSP (XCDR (it
->font_height
))
4598 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4600 /* `(+ N)' or `(- N)' where N is an integer. */
4601 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4602 if (EQ (XCAR (it
->font_height
), Qplus
))
4604 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4606 else if (FUNCTIONP (it
->font_height
))
4608 /* Call function with current height as argument.
4609 Value is the new height. */
4611 height
= safe_call1 (it
->font_height
,
4612 face
->lface
[LFACE_HEIGHT_INDEX
]);
4613 if (NUMBERP (height
))
4614 new_height
= XFLOATINT (height
);
4616 else if (NUMBERP (it
->font_height
))
4618 /* Value is a multiple of the canonical char height. */
4621 f
= FACE_FROM_ID (it
->f
,
4622 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4623 new_height
= (XFLOATINT (it
->font_height
)
4624 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4628 /* Evaluate IT->font_height with `height' bound to the
4629 current specified height to get the new height. */
4630 ptrdiff_t count
= SPECPDL_INDEX ();
4632 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4633 value
= safe_eval (it
->font_height
);
4634 unbind_to (count
, Qnil
);
4636 if (NUMBERP (value
))
4637 new_height
= XFLOATINT (value
);
4641 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4648 /* Handle `(space-width WIDTH)'. */
4650 && EQ (XCAR (spec
), Qspace_width
)
4651 && CONSP (XCDR (spec
)))
4655 if (!FRAME_WINDOW_P (it
->f
))
4658 value
= XCAR (XCDR (spec
));
4659 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4660 it
->space_width
= value
;
4666 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4668 && EQ (XCAR (spec
), Qslice
))
4674 if (!FRAME_WINDOW_P (it
->f
))
4677 if (tem
= XCDR (spec
), CONSP (tem
))
4679 it
->slice
.x
= XCAR (tem
);
4680 if (tem
= XCDR (tem
), CONSP (tem
))
4682 it
->slice
.y
= XCAR (tem
);
4683 if (tem
= XCDR (tem
), CONSP (tem
))
4685 it
->slice
.width
= XCAR (tem
);
4686 if (tem
= XCDR (tem
), CONSP (tem
))
4687 it
->slice
.height
= XCAR (tem
);
4696 /* Handle `(raise FACTOR)'. */
4698 && EQ (XCAR (spec
), Qraise
)
4699 && CONSP (XCDR (spec
)))
4703 if (!FRAME_WINDOW_P (it
->f
))
4706 #ifdef HAVE_WINDOW_SYSTEM
4707 value
= XCAR (XCDR (spec
));
4708 if (NUMBERP (value
))
4710 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4711 it
->voffset
= - (XFLOATINT (value
)
4712 * (FONT_HEIGHT (face
->font
)));
4714 #endif /* HAVE_WINDOW_SYSTEM */
4720 /* Don't handle the other kinds of display specifications
4721 inside a string that we got from a `display' property. */
4722 if (it
&& it
->string_from_display_prop_p
)
4725 /* Characters having this form of property are not displayed, so
4726 we have to find the end of the property. */
4729 start_pos
= *position
;
4730 *position
= display_prop_end (it
, object
, start_pos
);
4734 /* Stop the scan at that end position--we assume that all
4735 text properties change there. */
4737 it
->stop_charpos
= position
->charpos
;
4739 /* Handle `(left-fringe BITMAP [FACE])'
4740 and `(right-fringe BITMAP [FACE])'. */
4742 && (EQ (XCAR (spec
), Qleft_fringe
)
4743 || EQ (XCAR (spec
), Qright_fringe
))
4744 && CONSP (XCDR (spec
)))
4750 if (!FRAME_WINDOW_P (it
->f
))
4751 /* If we return here, POSITION has been advanced
4752 across the text with this property. */
4754 /* Synchronize the bidi iterator with POSITION. This is
4755 needed because we are not going to push the iterator
4756 on behalf of this display property, so there will be
4757 no pop_it call to do this synchronization for us. */
4760 it
->position
= *position
;
4761 iterate_out_of_display_property (it
);
4762 *position
= it
->position
;
4767 else if (!frame_window_p
)
4770 #ifdef HAVE_WINDOW_SYSTEM
4771 value
= XCAR (XCDR (spec
));
4772 if (!SYMBOLP (value
)
4773 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4774 /* If we return here, POSITION has been advanced
4775 across the text with this property. */
4777 if (it
&& it
->bidi_p
)
4779 it
->position
= *position
;
4780 iterate_out_of_display_property (it
);
4781 *position
= it
->position
;
4788 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4790 if (CONSP (XCDR (XCDR (spec
))))
4792 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4793 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4799 /* Save current settings of IT so that we can restore them
4800 when we are finished with the glyph property value. */
4801 push_it (it
, position
);
4803 it
->area
= TEXT_AREA
;
4804 it
->what
= IT_IMAGE
;
4805 it
->image_id
= -1; /* no image */
4806 it
->position
= start_pos
;
4807 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4808 it
->method
= GET_FROM_IMAGE
;
4809 it
->from_overlay
= Qnil
;
4810 it
->face_id
= face_id
;
4811 it
->from_disp_prop_p
= 1;
4813 /* Say that we haven't consumed the characters with
4814 `display' property yet. The call to pop_it in
4815 set_iterator_to_next will clean this up. */
4816 *position
= start_pos
;
4818 if (EQ (XCAR (spec
), Qleft_fringe
))
4820 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4821 it
->left_user_fringe_face_id
= face_id
;
4825 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4826 it
->right_user_fringe_face_id
= face_id
;
4829 #endif /* HAVE_WINDOW_SYSTEM */
4833 /* Prepare to handle `((margin left-margin) ...)',
4834 `((margin right-margin) ...)' and `((margin nil) ...)'
4835 prefixes for display specifications. */
4836 location
= Qunbound
;
4837 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4841 value
= XCDR (spec
);
4843 value
= XCAR (value
);
4846 if (EQ (XCAR (tem
), Qmargin
)
4847 && (tem
= XCDR (tem
),
4848 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4850 || EQ (tem
, Qleft_margin
)
4851 || EQ (tem
, Qright_margin
))))
4855 if (EQ (location
, Qunbound
))
4861 /* After this point, VALUE is the property after any
4862 margin prefix has been stripped. It must be a string,
4863 an image specification, or `(space ...)'.
4865 LOCATION specifies where to display: `left-margin',
4866 `right-margin' or nil. */
4868 valid_p
= (STRINGP (value
)
4869 #ifdef HAVE_WINDOW_SYSTEM
4870 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4871 && valid_image_p (value
))
4872 #endif /* not HAVE_WINDOW_SYSTEM */
4873 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4875 if (valid_p
&& !display_replaced_p
)
4881 /* Callers need to know whether the display spec is any kind
4882 of `(space ...)' spec that is about to affect text-area
4884 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4889 /* Save current settings of IT so that we can restore them
4890 when we are finished with the glyph property value. */
4891 push_it (it
, position
);
4892 it
->from_overlay
= overlay
;
4893 it
->from_disp_prop_p
= 1;
4895 if (NILP (location
))
4896 it
->area
= TEXT_AREA
;
4897 else if (EQ (location
, Qleft_margin
))
4898 it
->area
= LEFT_MARGIN_AREA
;
4900 it
->area
= RIGHT_MARGIN_AREA
;
4902 if (STRINGP (value
))
4905 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4906 it
->current
.overlay_string_index
= -1;
4907 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4908 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4909 it
->method
= GET_FROM_STRING
;
4910 it
->stop_charpos
= 0;
4912 it
->base_level_stop
= 0;
4913 it
->string_from_display_prop_p
= 1;
4914 /* Say that we haven't consumed the characters with
4915 `display' property yet. The call to pop_it in
4916 set_iterator_to_next will clean this up. */
4917 if (BUFFERP (object
))
4918 *position
= start_pos
;
4920 /* Force paragraph direction to be that of the parent
4921 object. If the parent object's paragraph direction is
4922 not yet determined, default to L2R. */
4923 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4924 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4926 it
->paragraph_embedding
= L2R
;
4928 /* Set up the bidi iterator for this display string. */
4931 it
->bidi_it
.string
.lstring
= it
->string
;
4932 it
->bidi_it
.string
.s
= NULL
;
4933 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4934 it
->bidi_it
.string
.bufpos
= bufpos
;
4935 it
->bidi_it
.string
.from_disp_str
= 1;
4936 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4937 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4940 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4942 it
->method
= GET_FROM_STRETCH
;
4944 *position
= it
->position
= start_pos
;
4945 retval
= 1 + (it
->area
== TEXT_AREA
);
4947 #ifdef HAVE_WINDOW_SYSTEM
4950 it
->what
= IT_IMAGE
;
4951 it
->image_id
= lookup_image (it
->f
, value
);
4952 it
->position
= start_pos
;
4953 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4954 it
->method
= GET_FROM_IMAGE
;
4956 /* Say that we haven't consumed the characters with
4957 `display' property yet. The call to pop_it in
4958 set_iterator_to_next will clean this up. */
4959 *position
= start_pos
;
4961 #endif /* HAVE_WINDOW_SYSTEM */
4966 /* Invalid property or property not supported. Restore
4967 POSITION to what it was before. */
4968 *position
= start_pos
;
4972 /* Check if PROP is a display property value whose text should be
4973 treated as intangible. OVERLAY is the overlay from which PROP
4974 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4975 specify the buffer position covered by PROP. */
4978 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4979 ptrdiff_t charpos
, ptrdiff_t bytepos
)
4981 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4982 struct text_pos position
;
4984 SET_TEXT_POS (position
, charpos
, bytepos
);
4985 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4986 &position
, charpos
, frame_window_p
);
4990 /* Return 1 if PROP is a display sub-property value containing STRING.
4992 Implementation note: this and the following function are really
4993 special cases of handle_display_spec and
4994 handle_single_display_spec, and should ideally use the same code.
4995 Until they do, these two pairs must be consistent and must be
4996 modified in sync. */
4999 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5001 if (EQ (string
, prop
))
5004 /* Skip over `when FORM'. */
5005 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5010 /* Actually, the condition following `when' should be eval'ed,
5011 like handle_single_display_spec does, and we should return
5012 zero if it evaluates to nil. However, this function is
5013 called only when the buffer was already displayed and some
5014 glyph in the glyph matrix was found to come from a display
5015 string. Therefore, the condition was already evaluated, and
5016 the result was non-nil, otherwise the display string wouldn't
5017 have been displayed and we would have never been called for
5018 this property. Thus, we can skip the evaluation and assume
5019 its result is non-nil. */
5024 /* Skip over `margin LOCATION'. */
5025 if (EQ (XCAR (prop
), Qmargin
))
5036 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5040 /* Return 1 if STRING appears in the `display' property PROP. */
5043 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5046 && !EQ (XCAR (prop
), Qwhen
)
5047 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5049 /* A list of sub-properties. */
5050 while (CONSP (prop
))
5052 if (single_display_spec_string_p (XCAR (prop
), string
))
5057 else if (VECTORP (prop
))
5059 /* A vector of sub-properties. */
5061 for (i
= 0; i
< ASIZE (prop
); ++i
)
5062 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5066 return single_display_spec_string_p (prop
, string
);
5071 /* Look for STRING in overlays and text properties in the current
5072 buffer, between character positions FROM and TO (excluding TO).
5073 BACK_P non-zero means look back (in this case, TO is supposed to be
5075 Value is the first character position where STRING was found, or
5076 zero if it wasn't found before hitting TO.
5078 This function may only use code that doesn't eval because it is
5079 called asynchronously from note_mouse_highlight. */
5082 string_buffer_position_lim (Lisp_Object string
,
5083 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5085 Lisp_Object limit
, prop
, pos
;
5088 pos
= make_number (max (from
, BEGV
));
5090 if (!back_p
) /* looking forward */
5092 limit
= make_number (min (to
, ZV
));
5093 while (!found
&& !EQ (pos
, limit
))
5095 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5096 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5099 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5103 else /* looking back */
5105 limit
= make_number (max (to
, BEGV
));
5106 while (!found
&& !EQ (pos
, limit
))
5108 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5109 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5112 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5117 return found
? XINT (pos
) : 0;
5120 /* Determine which buffer position in current buffer STRING comes from.
5121 AROUND_CHARPOS is an approximate position where it could come from.
5122 Value is the buffer position or 0 if it couldn't be determined.
5124 This function is necessary because we don't record buffer positions
5125 in glyphs generated from strings (to keep struct glyph small).
5126 This function may only use code that doesn't eval because it is
5127 called asynchronously from note_mouse_highlight. */
5130 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5132 const int MAX_DISTANCE
= 1000;
5133 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5134 around_charpos
+ MAX_DISTANCE
,
5138 found
= string_buffer_position_lim (string
, around_charpos
,
5139 around_charpos
- MAX_DISTANCE
, 1);
5145 /***********************************************************************
5146 `composition' property
5147 ***********************************************************************/
5149 /* Set up iterator IT from `composition' property at its current
5150 position. Called from handle_stop. */
5152 static enum prop_handled
5153 handle_composition_prop (struct it
*it
)
5155 Lisp_Object prop
, string
;
5156 ptrdiff_t pos
, pos_byte
, start
, end
;
5158 if (STRINGP (it
->string
))
5162 pos
= IT_STRING_CHARPOS (*it
);
5163 pos_byte
= IT_STRING_BYTEPOS (*it
);
5164 string
= it
->string
;
5165 s
= SDATA (string
) + pos_byte
;
5166 it
->c
= STRING_CHAR (s
);
5170 pos
= IT_CHARPOS (*it
);
5171 pos_byte
= IT_BYTEPOS (*it
);
5173 it
->c
= FETCH_CHAR (pos_byte
);
5176 /* If there's a valid composition and point is not inside of the
5177 composition (in the case that the composition is from the current
5178 buffer), draw a glyph composed from the composition components. */
5179 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5180 && COMPOSITION_VALID_P (start
, end
, prop
)
5181 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5184 /* As we can't handle this situation (perhaps font-lock added
5185 a new composition), we just return here hoping that next
5186 redisplay will detect this composition much earlier. */
5187 return HANDLED_NORMALLY
;
5190 if (STRINGP (it
->string
))
5191 pos_byte
= string_char_to_byte (it
->string
, start
);
5193 pos_byte
= CHAR_TO_BYTE (start
);
5195 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5198 if (it
->cmp_it
.id
>= 0)
5201 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5202 it
->cmp_it
.nglyphs
= -1;
5206 return HANDLED_NORMALLY
;
5211 /***********************************************************************
5213 ***********************************************************************/
5215 /* The following structure is used to record overlay strings for
5216 later sorting in load_overlay_strings. */
5218 struct overlay_entry
5220 Lisp_Object overlay
;
5227 /* Set up iterator IT from overlay strings at its current position.
5228 Called from handle_stop. */
5230 static enum prop_handled
5231 handle_overlay_change (struct it
*it
)
5233 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5234 return HANDLED_RECOMPUTE_PROPS
;
5236 return HANDLED_NORMALLY
;
5240 /* Set up the next overlay string for delivery by IT, if there is an
5241 overlay string to deliver. Called by set_iterator_to_next when the
5242 end of the current overlay string is reached. If there are more
5243 overlay strings to display, IT->string and
5244 IT->current.overlay_string_index are set appropriately here.
5245 Otherwise IT->string is set to nil. */
5248 next_overlay_string (struct it
*it
)
5250 ++it
->current
.overlay_string_index
;
5251 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5253 /* No more overlay strings. Restore IT's settings to what
5254 they were before overlay strings were processed, and
5255 continue to deliver from current_buffer. */
5257 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5260 || (NILP (it
->string
)
5261 && it
->method
== GET_FROM_BUFFER
5262 && it
->stop_charpos
>= BEGV
5263 && it
->stop_charpos
<= it
->end_charpos
));
5264 it
->current
.overlay_string_index
= -1;
5265 it
->n_overlay_strings
= 0;
5266 it
->overlay_strings_charpos
= -1;
5267 /* If there's an empty display string on the stack, pop the
5268 stack, to resync the bidi iterator with IT's position. Such
5269 empty strings are pushed onto the stack in
5270 get_overlay_strings_1. */
5271 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5274 /* If we're at the end of the buffer, record that we have
5275 processed the overlay strings there already, so that
5276 next_element_from_buffer doesn't try it again. */
5277 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5278 it
->overlay_strings_at_end_processed_p
= 1;
5282 /* There are more overlay strings to process. If
5283 IT->current.overlay_string_index has advanced to a position
5284 where we must load IT->overlay_strings with more strings, do
5285 it. We must load at the IT->overlay_strings_charpos where
5286 IT->n_overlay_strings was originally computed; when invisible
5287 text is present, this might not be IT_CHARPOS (Bug#7016). */
5288 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5290 if (it
->current
.overlay_string_index
&& i
== 0)
5291 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5293 /* Initialize IT to deliver display elements from the overlay
5295 it
->string
= it
->overlay_strings
[i
];
5296 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5297 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5298 it
->method
= GET_FROM_STRING
;
5299 it
->stop_charpos
= 0;
5300 if (it
->cmp_it
.stop_pos
>= 0)
5301 it
->cmp_it
.stop_pos
= 0;
5303 it
->base_level_stop
= 0;
5305 /* Set up the bidi iterator for this overlay string. */
5308 it
->bidi_it
.string
.lstring
= it
->string
;
5309 it
->bidi_it
.string
.s
= NULL
;
5310 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5311 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5312 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5313 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5314 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5322 /* Compare two overlay_entry structures E1 and E2. Used as a
5323 comparison function for qsort in load_overlay_strings. Overlay
5324 strings for the same position are sorted so that
5326 1. All after-strings come in front of before-strings, except
5327 when they come from the same overlay.
5329 2. Within after-strings, strings are sorted so that overlay strings
5330 from overlays with higher priorities come first.
5332 2. Within before-strings, strings are sorted so that overlay
5333 strings from overlays with higher priorities come last.
5335 Value is analogous to strcmp. */
5339 compare_overlay_entries (const void *e1
, const void *e2
)
5341 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5342 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5345 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5347 /* Let after-strings appear in front of before-strings if
5348 they come from different overlays. */
5349 if (EQ (entry1
->overlay
, entry2
->overlay
))
5350 result
= entry1
->after_string_p
? 1 : -1;
5352 result
= entry1
->after_string_p
? -1 : 1;
5354 else if (entry1
->priority
!= entry2
->priority
)
5356 if (entry1
->after_string_p
)
5357 /* After-strings sorted in order of decreasing priority. */
5358 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5360 /* Before-strings sorted in order of increasing priority. */
5361 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5370 /* Load the vector IT->overlay_strings with overlay strings from IT's
5371 current buffer position, or from CHARPOS if that is > 0. Set
5372 IT->n_overlays to the total number of overlay strings found.
5374 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5375 a time. On entry into load_overlay_strings,
5376 IT->current.overlay_string_index gives the number of overlay
5377 strings that have already been loaded by previous calls to this
5380 IT->add_overlay_start contains an additional overlay start
5381 position to consider for taking overlay strings from, if non-zero.
5382 This position comes into play when the overlay has an `invisible'
5383 property, and both before and after-strings. When we've skipped to
5384 the end of the overlay, because of its `invisible' property, we
5385 nevertheless want its before-string to appear.
5386 IT->add_overlay_start will contain the overlay start position
5389 Overlay strings are sorted so that after-string strings come in
5390 front of before-string strings. Within before and after-strings,
5391 strings are sorted by overlay priority. See also function
5392 compare_overlay_entries. */
5395 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5397 Lisp_Object overlay
, window
, str
, invisible
;
5398 struct Lisp_Overlay
*ov
;
5399 ptrdiff_t start
, end
;
5400 ptrdiff_t size
= 20;
5401 ptrdiff_t n
= 0, i
, j
;
5403 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5407 charpos
= IT_CHARPOS (*it
);
5409 /* Append the overlay string STRING of overlay OVERLAY to vector
5410 `entries' which has size `size' and currently contains `n'
5411 elements. AFTER_P non-zero means STRING is an after-string of
5413 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5416 Lisp_Object priority; \
5420 struct overlay_entry *old = entries; \
5421 SAFE_NALLOCA (entries, 2, size); \
5422 memcpy (entries, old, size * sizeof *entries); \
5426 entries[n].string = (STRING); \
5427 entries[n].overlay = (OVERLAY); \
5428 priority = Foverlay_get ((OVERLAY), Qpriority); \
5429 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5430 entries[n].after_string_p = (AFTER_P); \
5435 /* Process overlay before the overlay center. */
5436 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5438 XSETMISC (overlay
, ov
);
5439 eassert (OVERLAYP (overlay
));
5440 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5441 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5446 /* Skip this overlay if it doesn't start or end at IT's current
5448 if (end
!= charpos
&& start
!= charpos
)
5451 /* Skip this overlay if it doesn't apply to IT->w. */
5452 window
= Foverlay_get (overlay
, Qwindow
);
5453 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5456 /* If the text ``under'' the overlay is invisible, both before-
5457 and after-strings from this overlay are visible; start and
5458 end position are indistinguishable. */
5459 invisible
= Foverlay_get (overlay
, Qinvisible
);
5460 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5462 /* If overlay has a non-empty before-string, record it. */
5463 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5464 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5466 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5468 /* If overlay has a non-empty after-string, record it. */
5469 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5470 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5472 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5475 /* Process overlays after the overlay center. */
5476 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5478 XSETMISC (overlay
, ov
);
5479 eassert (OVERLAYP (overlay
));
5480 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5481 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5483 if (start
> charpos
)
5486 /* Skip this overlay if it doesn't start or end at IT's current
5488 if (end
!= charpos
&& start
!= charpos
)
5491 /* Skip this overlay if it doesn't apply to IT->w. */
5492 window
= Foverlay_get (overlay
, Qwindow
);
5493 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5496 /* If the text ``under'' the overlay is invisible, it has a zero
5497 dimension, and both before- and after-strings apply. */
5498 invisible
= Foverlay_get (overlay
, Qinvisible
);
5499 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5501 /* If overlay has a non-empty before-string, record it. */
5502 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5503 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5505 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5507 /* If overlay has a non-empty after-string, record it. */
5508 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5509 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5511 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5514 #undef RECORD_OVERLAY_STRING
5518 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5520 /* Record number of overlay strings, and where we computed it. */
5521 it
->n_overlay_strings
= n
;
5522 it
->overlay_strings_charpos
= charpos
;
5524 /* IT->current.overlay_string_index is the number of overlay strings
5525 that have already been consumed by IT. Copy some of the
5526 remaining overlay strings to IT->overlay_strings. */
5528 j
= it
->current
.overlay_string_index
;
5529 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5531 it
->overlay_strings
[i
] = entries
[j
].string
;
5532 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5540 /* Get the first chunk of overlay strings at IT's current buffer
5541 position, or at CHARPOS if that is > 0. Value is non-zero if at
5542 least one overlay string was found. */
5545 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5547 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5548 process. This fills IT->overlay_strings with strings, and sets
5549 IT->n_overlay_strings to the total number of strings to process.
5550 IT->pos.overlay_string_index has to be set temporarily to zero
5551 because load_overlay_strings needs this; it must be set to -1
5552 when no overlay strings are found because a zero value would
5553 indicate a position in the first overlay string. */
5554 it
->current
.overlay_string_index
= 0;
5555 load_overlay_strings (it
, charpos
);
5557 /* If we found overlay strings, set up IT to deliver display
5558 elements from the first one. Otherwise set up IT to deliver
5559 from current_buffer. */
5560 if (it
->n_overlay_strings
)
5562 /* Make sure we know settings in current_buffer, so that we can
5563 restore meaningful values when we're done with the overlay
5566 compute_stop_pos (it
);
5567 eassert (it
->face_id
>= 0);
5569 /* Save IT's settings. They are restored after all overlay
5570 strings have been processed. */
5571 eassert (!compute_stop_p
|| it
->sp
== 0);
5573 /* When called from handle_stop, there might be an empty display
5574 string loaded. In that case, don't bother saving it. But
5575 don't use this optimization with the bidi iterator, since we
5576 need the corresponding pop_it call to resync the bidi
5577 iterator's position with IT's position, after we are done
5578 with the overlay strings. (The corresponding call to pop_it
5579 in case of an empty display string is in
5580 next_overlay_string.) */
5582 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5585 /* Set up IT to deliver display elements from the first overlay
5587 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5588 it
->string
= it
->overlay_strings
[0];
5589 it
->from_overlay
= Qnil
;
5590 it
->stop_charpos
= 0;
5591 eassert (STRINGP (it
->string
));
5592 it
->end_charpos
= SCHARS (it
->string
);
5594 it
->base_level_stop
= 0;
5595 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5596 it
->method
= GET_FROM_STRING
;
5597 it
->from_disp_prop_p
= 0;
5599 /* Force paragraph direction to be that of the parent
5601 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5602 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5604 it
->paragraph_embedding
= L2R
;
5606 /* Set up the bidi iterator for this overlay string. */
5609 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5611 it
->bidi_it
.string
.lstring
= it
->string
;
5612 it
->bidi_it
.string
.s
= NULL
;
5613 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5614 it
->bidi_it
.string
.bufpos
= pos
;
5615 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5616 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5617 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5622 it
->current
.overlay_string_index
= -1;
5627 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5630 it
->method
= GET_FROM_BUFFER
;
5632 (void) get_overlay_strings_1 (it
, charpos
, 1);
5636 /* Value is non-zero if we found at least one overlay string. */
5637 return STRINGP (it
->string
);
5642 /***********************************************************************
5643 Saving and restoring state
5644 ***********************************************************************/
5646 /* Save current settings of IT on IT->stack. Called, for example,
5647 before setting up IT for an overlay string, to be able to restore
5648 IT's settings to what they were after the overlay string has been
5649 processed. If POSITION is non-NULL, it is the position to save on
5650 the stack instead of IT->position. */
5653 push_it (struct it
*it
, struct text_pos
*position
)
5655 struct iterator_stack_entry
*p
;
5657 eassert (it
->sp
< IT_STACK_SIZE
);
5658 p
= it
->stack
+ it
->sp
;
5660 p
->stop_charpos
= it
->stop_charpos
;
5661 p
->prev_stop
= it
->prev_stop
;
5662 p
->base_level_stop
= it
->base_level_stop
;
5663 p
->cmp_it
= it
->cmp_it
;
5664 eassert (it
->face_id
>= 0);
5665 p
->face_id
= it
->face_id
;
5666 p
->string
= it
->string
;
5667 p
->method
= it
->method
;
5668 p
->from_overlay
= it
->from_overlay
;
5671 case GET_FROM_IMAGE
:
5672 p
->u
.image
.object
= it
->object
;
5673 p
->u
.image
.image_id
= it
->image_id
;
5674 p
->u
.image
.slice
= it
->slice
;
5676 case GET_FROM_STRETCH
:
5677 p
->u
.stretch
.object
= it
->object
;
5680 p
->position
= position
? *position
: it
->position
;
5681 p
->current
= it
->current
;
5682 p
->end_charpos
= it
->end_charpos
;
5683 p
->string_nchars
= it
->string_nchars
;
5685 p
->multibyte_p
= it
->multibyte_p
;
5686 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5687 p
->space_width
= it
->space_width
;
5688 p
->font_height
= it
->font_height
;
5689 p
->voffset
= it
->voffset
;
5690 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5691 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5692 p
->display_ellipsis_p
= 0;
5693 p
->line_wrap
= it
->line_wrap
;
5694 p
->bidi_p
= it
->bidi_p
;
5695 p
->paragraph_embedding
= it
->paragraph_embedding
;
5696 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5699 /* Save the state of the bidi iterator as well. */
5701 bidi_push_it (&it
->bidi_it
);
5705 iterate_out_of_display_property (struct it
*it
)
5707 int buffer_p
= !STRINGP (it
->string
);
5708 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5709 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5711 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5713 /* Maybe initialize paragraph direction. If we are at the beginning
5714 of a new paragraph, next_element_from_buffer may not have a
5715 chance to do that. */
5716 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5717 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5718 /* prev_stop can be zero, so check against BEGV as well. */
5719 while (it
->bidi_it
.charpos
>= bob
5720 && it
->prev_stop
<= it
->bidi_it
.charpos
5721 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5722 && it
->bidi_it
.charpos
< eob
)
5723 bidi_move_to_visually_next (&it
->bidi_it
);
5724 /* Record the stop_pos we just crossed, for when we cross it
5726 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5727 it
->prev_stop
= CHARPOS (it
->position
);
5728 /* If we ended up not where pop_it put us, resync IT's
5729 positional members with the bidi iterator. */
5730 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5731 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5733 it
->current
.pos
= it
->position
;
5735 it
->current
.string_pos
= it
->position
;
5738 /* Restore IT's settings from IT->stack. Called, for example, when no
5739 more overlay strings must be processed, and we return to delivering
5740 display elements from a buffer, or when the end of a string from a
5741 `display' property is reached and we return to delivering display
5742 elements from an overlay string, or from a buffer. */
5745 pop_it (struct it
*it
)
5747 struct iterator_stack_entry
*p
;
5748 int from_display_prop
= it
->from_disp_prop_p
;
5750 eassert (it
->sp
> 0);
5752 p
= it
->stack
+ it
->sp
;
5753 it
->stop_charpos
= p
->stop_charpos
;
5754 it
->prev_stop
= p
->prev_stop
;
5755 it
->base_level_stop
= p
->base_level_stop
;
5756 it
->cmp_it
= p
->cmp_it
;
5757 it
->face_id
= p
->face_id
;
5758 it
->current
= p
->current
;
5759 it
->position
= p
->position
;
5760 it
->string
= p
->string
;
5761 it
->from_overlay
= p
->from_overlay
;
5762 if (NILP (it
->string
))
5763 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5764 it
->method
= p
->method
;
5767 case GET_FROM_IMAGE
:
5768 it
->image_id
= p
->u
.image
.image_id
;
5769 it
->object
= p
->u
.image
.object
;
5770 it
->slice
= p
->u
.image
.slice
;
5772 case GET_FROM_STRETCH
:
5773 it
->object
= p
->u
.stretch
.object
;
5775 case GET_FROM_BUFFER
:
5776 it
->object
= it
->w
->buffer
;
5778 case GET_FROM_STRING
:
5779 it
->object
= it
->string
;
5781 case GET_FROM_DISPLAY_VECTOR
:
5783 it
->method
= GET_FROM_C_STRING
;
5784 else if (STRINGP (it
->string
))
5785 it
->method
= GET_FROM_STRING
;
5788 it
->method
= GET_FROM_BUFFER
;
5789 it
->object
= it
->w
->buffer
;
5792 it
->end_charpos
= p
->end_charpos
;
5793 it
->string_nchars
= p
->string_nchars
;
5795 it
->multibyte_p
= p
->multibyte_p
;
5796 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5797 it
->space_width
= p
->space_width
;
5798 it
->font_height
= p
->font_height
;
5799 it
->voffset
= p
->voffset
;
5800 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5801 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5802 it
->line_wrap
= p
->line_wrap
;
5803 it
->bidi_p
= p
->bidi_p
;
5804 it
->paragraph_embedding
= p
->paragraph_embedding
;
5805 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5808 bidi_pop_it (&it
->bidi_it
);
5809 /* Bidi-iterate until we get out of the portion of text, if any,
5810 covered by a `display' text property or by an overlay with
5811 `display' property. (We cannot just jump there, because the
5812 internal coherency of the bidi iterator state can not be
5813 preserved across such jumps.) We also must determine the
5814 paragraph base direction if the overlay we just processed is
5815 at the beginning of a new paragraph. */
5816 if (from_display_prop
5817 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5818 iterate_out_of_display_property (it
);
5820 eassert ((BUFFERP (it
->object
)
5821 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5822 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5823 || (STRINGP (it
->object
)
5824 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5825 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5826 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5832 /***********************************************************************
5834 ***********************************************************************/
5836 /* Set IT's current position to the previous line start. */
5839 back_to_previous_line_start (struct it
*it
)
5841 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5842 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5846 /* Move IT to the next line start.
5848 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5849 we skipped over part of the text (as opposed to moving the iterator
5850 continuously over the text). Otherwise, don't change the value
5853 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5854 iterator on the newline, if it was found.
5856 Newlines may come from buffer text, overlay strings, or strings
5857 displayed via the `display' property. That's the reason we can't
5858 simply use find_next_newline_no_quit.
5860 Note that this function may not skip over invisible text that is so
5861 because of text properties and immediately follows a newline. If
5862 it would, function reseat_at_next_visible_line_start, when called
5863 from set_iterator_to_next, would effectively make invisible
5864 characters following a newline part of the wrong glyph row, which
5865 leads to wrong cursor motion. */
5868 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5869 struct bidi_it
*bidi_it_prev
)
5871 ptrdiff_t old_selective
;
5872 int newline_found_p
, n
;
5873 const int MAX_NEWLINE_DISTANCE
= 500;
5875 /* If already on a newline, just consume it to avoid unintended
5876 skipping over invisible text below. */
5877 if (it
->what
== IT_CHARACTER
5879 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5881 if (it
->bidi_p
&& bidi_it_prev
)
5882 *bidi_it_prev
= it
->bidi_it
;
5883 set_iterator_to_next (it
, 0);
5888 /* Don't handle selective display in the following. It's (a)
5889 unnecessary because it's done by the caller, and (b) leads to an
5890 infinite recursion because next_element_from_ellipsis indirectly
5891 calls this function. */
5892 old_selective
= it
->selective
;
5895 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5896 from buffer text. */
5897 for (n
= newline_found_p
= 0;
5898 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5899 n
+= STRINGP (it
->string
) ? 0 : 1)
5901 if (!get_next_display_element (it
))
5903 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5904 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5905 *bidi_it_prev
= it
->bidi_it
;
5906 set_iterator_to_next (it
, 0);
5909 /* If we didn't find a newline near enough, see if we can use a
5911 if (!newline_found_p
)
5913 ptrdiff_t start
= IT_CHARPOS (*it
);
5914 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5917 eassert (!STRINGP (it
->string
));
5919 /* If there isn't any `display' property in sight, and no
5920 overlays, we can just use the position of the newline in
5922 if (it
->stop_charpos
>= limit
5923 || ((pos
= Fnext_single_property_change (make_number (start
),
5925 make_number (limit
)),
5927 && next_overlay_change (start
) == ZV
))
5931 IT_CHARPOS (*it
) = limit
;
5932 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5936 struct bidi_it bprev
;
5938 /* Help bidi.c avoid expensive searches for display
5939 properties and overlays, by telling it that there are
5940 none up to `limit'. */
5941 if (it
->bidi_it
.disp_pos
< limit
)
5943 it
->bidi_it
.disp_pos
= limit
;
5944 it
->bidi_it
.disp_prop
= 0;
5947 bprev
= it
->bidi_it
;
5948 bidi_move_to_visually_next (&it
->bidi_it
);
5949 } while (it
->bidi_it
.charpos
!= limit
);
5950 IT_CHARPOS (*it
) = limit
;
5951 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5953 *bidi_it_prev
= bprev
;
5955 *skipped_p
= newline_found_p
= 1;
5959 while (get_next_display_element (it
)
5960 && !newline_found_p
)
5962 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5963 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5964 *bidi_it_prev
= it
->bidi_it
;
5965 set_iterator_to_next (it
, 0);
5970 it
->selective
= old_selective
;
5971 return newline_found_p
;
5975 /* Set IT's current position to the previous visible line start. Skip
5976 invisible text that is so either due to text properties or due to
5977 selective display. Caution: this does not change IT->current_x and
5981 back_to_previous_visible_line_start (struct it
*it
)
5983 while (IT_CHARPOS (*it
) > BEGV
)
5985 back_to_previous_line_start (it
);
5987 if (IT_CHARPOS (*it
) <= BEGV
)
5990 /* If selective > 0, then lines indented more than its value are
5992 if (it
->selective
> 0
5993 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5997 /* Check the newline before point for invisibility. */
6000 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6001 Qinvisible
, it
->window
);
6002 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6006 if (IT_CHARPOS (*it
) <= BEGV
)
6011 void *it2data
= NULL
;
6014 Lisp_Object val
, overlay
;
6016 SAVE_IT (it2
, *it
, it2data
);
6018 /* If newline is part of a composition, continue from start of composition */
6019 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6020 && beg
< IT_CHARPOS (*it
))
6023 /* If newline is replaced by a display property, find start of overlay
6024 or interval and continue search from that point. */
6025 pos
= --IT_CHARPOS (it2
);
6028 bidi_unshelve_cache (NULL
, 0);
6029 it2
.string_from_display_prop_p
= 0;
6030 it2
.from_disp_prop_p
= 0;
6031 if (handle_display_prop (&it2
) == HANDLED_RETURN
6032 && !NILP (val
= get_char_property_and_overlay
6033 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6034 && (OVERLAYP (overlay
)
6035 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6036 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6038 RESTORE_IT (it
, it
, it2data
);
6042 /* Newline is not replaced by anything -- so we are done. */
6043 RESTORE_IT (it
, it
, it2data
);
6049 IT_CHARPOS (*it
) = beg
;
6050 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6054 it
->continuation_lines_width
= 0;
6056 eassert (IT_CHARPOS (*it
) >= BEGV
);
6057 eassert (IT_CHARPOS (*it
) == BEGV
6058 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6063 /* Reseat iterator IT at the previous visible line start. Skip
6064 invisible text that is so either due to text properties or due to
6065 selective display. At the end, update IT's overlay information,
6066 face information etc. */
6069 reseat_at_previous_visible_line_start (struct it
*it
)
6071 back_to_previous_visible_line_start (it
);
6072 reseat (it
, it
->current
.pos
, 1);
6077 /* Reseat iterator IT on the next visible line start in the current
6078 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6079 preceding the line start. Skip over invisible text that is so
6080 because of selective display. Compute faces, overlays etc at the
6081 new position. Note that this function does not skip over text that
6082 is invisible because of text properties. */
6085 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6087 int newline_found_p
, skipped_p
= 0;
6088 struct bidi_it bidi_it_prev
;
6090 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6092 /* Skip over lines that are invisible because they are indented
6093 more than the value of IT->selective. */
6094 if (it
->selective
> 0)
6095 while (IT_CHARPOS (*it
) < ZV
6096 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6099 eassert (IT_BYTEPOS (*it
) == BEGV
6100 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6102 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6105 /* Position on the newline if that's what's requested. */
6106 if (on_newline_p
&& newline_found_p
)
6108 if (STRINGP (it
->string
))
6110 if (IT_STRING_CHARPOS (*it
) > 0)
6114 --IT_STRING_CHARPOS (*it
);
6115 --IT_STRING_BYTEPOS (*it
);
6119 /* We need to restore the bidi iterator to the state
6120 it had on the newline, and resync the IT's
6121 position with that. */
6122 it
->bidi_it
= bidi_it_prev
;
6123 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6124 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6128 else if (IT_CHARPOS (*it
) > BEGV
)
6137 /* We need to restore the bidi iterator to the state it
6138 had on the newline and resync IT with that. */
6139 it
->bidi_it
= bidi_it_prev
;
6140 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6141 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6143 reseat (it
, it
->current
.pos
, 0);
6147 reseat (it
, it
->current
.pos
, 0);
6154 /***********************************************************************
6155 Changing an iterator's position
6156 ***********************************************************************/
6158 /* Change IT's current position to POS in current_buffer. If FORCE_P
6159 is non-zero, always check for text properties at the new position.
6160 Otherwise, text properties are only looked up if POS >=
6161 IT->check_charpos of a property. */
6164 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6166 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6168 reseat_1 (it
, pos
, 0);
6170 /* Determine where to check text properties. Avoid doing it
6171 where possible because text property lookup is very expensive. */
6173 || CHARPOS (pos
) > it
->stop_charpos
6174 || CHARPOS (pos
) < original_pos
)
6178 /* For bidi iteration, we need to prime prev_stop and
6179 base_level_stop with our best estimations. */
6180 /* Implementation note: Of course, POS is not necessarily a
6181 stop position, so assigning prev_pos to it is a lie; we
6182 should have called compute_stop_backwards. However, if
6183 the current buffer does not include any R2L characters,
6184 that call would be a waste of cycles, because the
6185 iterator will never move back, and thus never cross this
6186 "fake" stop position. So we delay that backward search
6187 until the time we really need it, in next_element_from_buffer. */
6188 if (CHARPOS (pos
) != it
->prev_stop
)
6189 it
->prev_stop
= CHARPOS (pos
);
6190 if (CHARPOS (pos
) < it
->base_level_stop
)
6191 it
->base_level_stop
= 0; /* meaning it's unknown */
6197 it
->prev_stop
= it
->base_level_stop
= 0;
6206 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6207 IT->stop_pos to POS, also. */
6210 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6212 /* Don't call this function when scanning a C string. */
6213 eassert (it
->s
== NULL
);
6215 /* POS must be a reasonable value. */
6216 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6218 it
->current
.pos
= it
->position
= pos
;
6219 it
->end_charpos
= ZV
;
6221 it
->current
.dpvec_index
= -1;
6222 it
->current
.overlay_string_index
= -1;
6223 IT_STRING_CHARPOS (*it
) = -1;
6224 IT_STRING_BYTEPOS (*it
) = -1;
6226 it
->method
= GET_FROM_BUFFER
;
6227 it
->object
= it
->w
->buffer
;
6228 it
->area
= TEXT_AREA
;
6229 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6231 it
->string_from_display_prop_p
= 0;
6232 it
->string_from_prefix_prop_p
= 0;
6234 it
->from_disp_prop_p
= 0;
6235 it
->face_before_selective_p
= 0;
6238 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6240 bidi_unshelve_cache (NULL
, 0);
6241 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6242 it
->bidi_it
.string
.s
= NULL
;
6243 it
->bidi_it
.string
.lstring
= Qnil
;
6244 it
->bidi_it
.string
.bufpos
= 0;
6245 it
->bidi_it
.string
.unibyte
= 0;
6250 it
->stop_charpos
= CHARPOS (pos
);
6251 it
->base_level_stop
= CHARPOS (pos
);
6256 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6257 If S is non-null, it is a C string to iterate over. Otherwise,
6258 STRING gives a Lisp string to iterate over.
6260 If PRECISION > 0, don't return more then PRECISION number of
6261 characters from the string.
6263 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6264 characters have been returned. FIELD_WIDTH < 0 means an infinite
6267 MULTIBYTE = 0 means disable processing of multibyte characters,
6268 MULTIBYTE > 0 means enable it,
6269 MULTIBYTE < 0 means use IT->multibyte_p.
6271 IT must be initialized via a prior call to init_iterator before
6272 calling this function. */
6275 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6276 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6279 /* No region in strings. */
6280 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6282 /* No text property checks performed by default, but see below. */
6283 it
->stop_charpos
= -1;
6285 /* Set iterator position and end position. */
6286 memset (&it
->current
, 0, sizeof it
->current
);
6287 it
->current
.overlay_string_index
= -1;
6288 it
->current
.dpvec_index
= -1;
6289 eassert (charpos
>= 0);
6291 /* If STRING is specified, use its multibyteness, otherwise use the
6292 setting of MULTIBYTE, if specified. */
6294 it
->multibyte_p
= multibyte
> 0;
6296 /* Bidirectional reordering of strings is controlled by the default
6297 value of bidi-display-reordering. Don't try to reorder while
6298 loading loadup.el, as the necessary character property tables are
6299 not yet available. */
6302 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6306 eassert (STRINGP (string
));
6307 it
->string
= string
;
6309 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6310 it
->method
= GET_FROM_STRING
;
6311 it
->current
.string_pos
= string_pos (charpos
, string
);
6315 it
->bidi_it
.string
.lstring
= string
;
6316 it
->bidi_it
.string
.s
= NULL
;
6317 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6318 it
->bidi_it
.string
.bufpos
= 0;
6319 it
->bidi_it
.string
.from_disp_str
= 0;
6320 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6321 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6322 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6327 it
->s
= (const unsigned char *) s
;
6330 /* Note that we use IT->current.pos, not it->current.string_pos,
6331 for displaying C strings. */
6332 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6333 if (it
->multibyte_p
)
6335 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6336 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6340 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6341 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6346 it
->bidi_it
.string
.lstring
= Qnil
;
6347 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6348 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6349 it
->bidi_it
.string
.bufpos
= 0;
6350 it
->bidi_it
.string
.from_disp_str
= 0;
6351 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6352 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6355 it
->method
= GET_FROM_C_STRING
;
6358 /* PRECISION > 0 means don't return more than PRECISION characters
6360 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6362 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6364 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6367 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6368 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6369 FIELD_WIDTH < 0 means infinite field width. This is useful for
6370 padding with `-' at the end of a mode line. */
6371 if (field_width
< 0)
6372 field_width
= INFINITY
;
6373 /* Implementation note: We deliberately don't enlarge
6374 it->bidi_it.string.schars here to fit it->end_charpos, because
6375 the bidi iterator cannot produce characters out of thin air. */
6376 if (field_width
> it
->end_charpos
- charpos
)
6377 it
->end_charpos
= charpos
+ field_width
;
6379 /* Use the standard display table for displaying strings. */
6380 if (DISP_TABLE_P (Vstandard_display_table
))
6381 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6383 it
->stop_charpos
= charpos
;
6384 it
->prev_stop
= charpos
;
6385 it
->base_level_stop
= 0;
6388 it
->bidi_it
.first_elt
= 1;
6389 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6390 it
->bidi_it
.disp_pos
= -1;
6392 if (s
== NULL
&& it
->multibyte_p
)
6394 ptrdiff_t endpos
= SCHARS (it
->string
);
6395 if (endpos
> it
->end_charpos
)
6396 endpos
= it
->end_charpos
;
6397 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6405 /***********************************************************************
6407 ***********************************************************************/
6409 /* Map enum it_method value to corresponding next_element_from_* function. */
6411 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6413 next_element_from_buffer
,
6414 next_element_from_display_vector
,
6415 next_element_from_string
,
6416 next_element_from_c_string
,
6417 next_element_from_image
,
6418 next_element_from_stretch
6421 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6424 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6425 (possibly with the following characters). */
6427 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6428 ((IT)->cmp_it.id >= 0 \
6429 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6430 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6431 END_CHARPOS, (IT)->w, \
6432 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6436 /* Lookup the char-table Vglyphless_char_display for character C (-1
6437 if we want information for no-font case), and return the display
6438 method symbol. By side-effect, update it->what and
6439 it->glyphless_method. This function is called from
6440 get_next_display_element for each character element, and from
6441 x_produce_glyphs when no suitable font was found. */
6444 lookup_glyphless_char_display (int c
, struct it
*it
)
6446 Lisp_Object glyphless_method
= Qnil
;
6448 if (CHAR_TABLE_P (Vglyphless_char_display
)
6449 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6453 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6454 if (CONSP (glyphless_method
))
6455 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6456 ? XCAR (glyphless_method
)
6457 : XCDR (glyphless_method
);
6460 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6464 if (NILP (glyphless_method
))
6467 /* The default is to display the character by a proper font. */
6469 /* The default for the no-font case is to display an empty box. */
6470 glyphless_method
= Qempty_box
;
6472 if (EQ (glyphless_method
, Qzero_width
))
6475 return glyphless_method
;
6476 /* This method can't be used for the no-font case. */
6477 glyphless_method
= Qempty_box
;
6479 if (EQ (glyphless_method
, Qthin_space
))
6480 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6481 else if (EQ (glyphless_method
, Qempty_box
))
6482 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6483 else if (EQ (glyphless_method
, Qhex_code
))
6484 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6485 else if (STRINGP (glyphless_method
))
6486 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6489 /* Invalid value. We use the default method. */
6490 glyphless_method
= Qnil
;
6493 it
->what
= IT_GLYPHLESS
;
6494 return glyphless_method
;
6497 /* Load IT's display element fields with information about the next
6498 display element from the current position of IT. Value is zero if
6499 end of buffer (or C string) is reached. */
6501 static struct frame
*last_escape_glyph_frame
= NULL
;
6502 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6503 static int last_escape_glyph_merged_face_id
= 0;
6505 struct frame
*last_glyphless_glyph_frame
= NULL
;
6506 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6507 int last_glyphless_glyph_merged_face_id
= 0;
6510 get_next_display_element (struct it
*it
)
6512 /* Non-zero means that we found a display element. Zero means that
6513 we hit the end of what we iterate over. Performance note: the
6514 function pointer `method' used here turns out to be faster than
6515 using a sequence of if-statements. */
6519 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6521 if (it
->what
== IT_CHARACTER
)
6523 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6524 and only if (a) the resolved directionality of that character
6526 /* FIXME: Do we need an exception for characters from display
6528 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6529 it
->c
= bidi_mirror_char (it
->c
);
6530 /* Map via display table or translate control characters.
6531 IT->c, IT->len etc. have been set to the next character by
6532 the function call above. If we have a display table, and it
6533 contains an entry for IT->c, translate it. Don't do this if
6534 IT->c itself comes from a display table, otherwise we could
6535 end up in an infinite recursion. (An alternative could be to
6536 count the recursion depth of this function and signal an
6537 error when a certain maximum depth is reached.) Is it worth
6539 if (success_p
&& it
->dpvec
== NULL
)
6542 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6543 int nonascii_space_p
= 0;
6544 int nonascii_hyphen_p
= 0;
6545 int c
= it
->c
; /* This is the character to display. */
6547 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6549 eassert (SINGLE_BYTE_CHAR_P (c
));
6550 if (unibyte_display_via_language_environment
)
6552 c
= DECODE_CHAR (unibyte
, c
);
6554 c
= BYTE8_TO_CHAR (it
->c
);
6557 c
= BYTE8_TO_CHAR (it
->c
);
6561 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6564 struct Lisp_Vector
*v
= XVECTOR (dv
);
6566 /* Return the first character from the display table
6567 entry, if not empty. If empty, don't display the
6568 current character. */
6571 it
->dpvec_char_len
= it
->len
;
6572 it
->dpvec
= v
->contents
;
6573 it
->dpend
= v
->contents
+ v
->header
.size
;
6574 it
->current
.dpvec_index
= 0;
6575 it
->dpvec_face_id
= -1;
6576 it
->saved_face_id
= it
->face_id
;
6577 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6582 set_iterator_to_next (it
, 0);
6587 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6589 if (it
->what
== IT_GLYPHLESS
)
6591 /* Don't display this character. */
6592 set_iterator_to_next (it
, 0);
6596 /* If `nobreak-char-display' is non-nil, we display
6597 non-ASCII spaces and hyphens specially. */
6598 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6601 nonascii_space_p
= 1;
6602 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6603 nonascii_hyphen_p
= 1;
6606 /* Translate control characters into `\003' or `^C' form.
6607 Control characters coming from a display table entry are
6608 currently not translated because we use IT->dpvec to hold
6609 the translation. This could easily be changed but I
6610 don't believe that it is worth doing.
6612 The characters handled by `nobreak-char-display' must be
6615 Non-printable characters and raw-byte characters are also
6616 translated to octal form. */
6617 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6618 ? (it
->area
!= TEXT_AREA
6619 /* In mode line, treat \n, \t like other crl chars. */
6622 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6623 || (c
!= '\n' && c
!= '\t'))
6625 || nonascii_hyphen_p
6627 || ! CHAR_PRINTABLE_P (c
))))
6629 /* C is a control character, non-ASCII space/hyphen,
6630 raw-byte, or a non-printable character which must be
6631 displayed either as '\003' or as `^C' where the '\\'
6632 and '^' can be defined in the display table. Fill
6633 IT->ctl_chars with glyphs for what we have to
6634 display. Then, set IT->dpvec to these glyphs. */
6641 /* Handle control characters with ^. */
6643 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6647 g
= '^'; /* default glyph for Control */
6648 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6650 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6652 g
= GLYPH_CODE_CHAR (gc
);
6653 lface_id
= GLYPH_CODE_FACE (gc
);
6657 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6659 else if (it
->f
== last_escape_glyph_frame
6660 && it
->face_id
== last_escape_glyph_face_id
)
6662 face_id
= last_escape_glyph_merged_face_id
;
6666 /* Merge the escape-glyph face into the current face. */
6667 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6669 last_escape_glyph_frame
= it
->f
;
6670 last_escape_glyph_face_id
= it
->face_id
;
6671 last_escape_glyph_merged_face_id
= face_id
;
6674 XSETINT (it
->ctl_chars
[0], g
);
6675 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6677 goto display_control
;
6680 /* Handle non-ascii space in the mode where it only gets
6683 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6685 /* Merge `nobreak-space' into the current face. */
6686 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6688 XSETINT (it
->ctl_chars
[0], ' ');
6690 goto display_control
;
6693 /* Handle sequences that start with the "escape glyph". */
6695 /* the default escape glyph is \. */
6696 escape_glyph
= '\\';
6699 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6701 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6702 lface_id
= GLYPH_CODE_FACE (gc
);
6706 /* The display table specified a face.
6707 Merge it into face_id and also into escape_glyph. */
6708 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6711 else if (it
->f
== last_escape_glyph_frame
6712 && it
->face_id
== last_escape_glyph_face_id
)
6714 face_id
= last_escape_glyph_merged_face_id
;
6718 /* Merge the escape-glyph face into the current face. */
6719 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6721 last_escape_glyph_frame
= it
->f
;
6722 last_escape_glyph_face_id
= it
->face_id
;
6723 last_escape_glyph_merged_face_id
= face_id
;
6726 /* Draw non-ASCII hyphen with just highlighting: */
6728 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6730 XSETINT (it
->ctl_chars
[0], '-');
6732 goto display_control
;
6735 /* Draw non-ASCII space/hyphen with escape glyph: */
6737 if (nonascii_space_p
|| nonascii_hyphen_p
)
6739 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6740 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6742 goto display_control
;
6749 if (CHAR_BYTE8_P (c
))
6750 /* Display \200 instead of \17777600. */
6751 c
= CHAR_TO_BYTE8 (c
);
6752 len
= sprintf (str
, "%03o", c
);
6754 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6755 for (i
= 0; i
< len
; i
++)
6756 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6761 /* Set up IT->dpvec and return first character from it. */
6762 it
->dpvec_char_len
= it
->len
;
6763 it
->dpvec
= it
->ctl_chars
;
6764 it
->dpend
= it
->dpvec
+ ctl_len
;
6765 it
->current
.dpvec_index
= 0;
6766 it
->dpvec_face_id
= face_id
;
6767 it
->saved_face_id
= it
->face_id
;
6768 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6772 it
->char_to_display
= c
;
6776 it
->char_to_display
= it
->c
;
6780 /* Adjust face id for a multibyte character. There are no multibyte
6781 character in unibyte text. */
6782 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6785 && FRAME_WINDOW_P (it
->f
))
6787 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6789 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6791 /* Automatic composition with glyph-string. */
6792 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6794 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6798 ptrdiff_t pos
= (it
->s
? -1
6799 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6800 : IT_CHARPOS (*it
));
6803 if (it
->what
== IT_CHARACTER
)
6804 c
= it
->char_to_display
;
6807 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6811 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6812 /* TAB in a composition means display glyphs with
6813 padding space on the left or right. */
6814 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6817 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6822 /* Is this character the last one of a run of characters with
6823 box? If yes, set IT->end_of_box_run_p to 1. */
6827 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6829 int face_id
= underlying_face_id (it
);
6830 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6834 if (face
->box
== FACE_NO_BOX
)
6836 /* If the box comes from face properties in a
6837 display string, check faces in that string. */
6838 int string_face_id
= face_after_it_pos (it
);
6839 it
->end_of_box_run_p
6840 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6843 /* Otherwise, the box comes from the underlying face.
6844 If this is the last string character displayed, check
6845 the next buffer location. */
6846 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6847 && (it
->current
.overlay_string_index
6848 == it
->n_overlay_strings
- 1))
6852 struct text_pos pos
= it
->current
.pos
;
6853 INC_TEXT_POS (pos
, it
->multibyte_p
);
6855 next_face_id
= face_at_buffer_position
6856 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6857 it
->region_end_charpos
, &ignore
,
6858 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6860 it
->end_of_box_run_p
6861 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6868 int face_id
= face_after_it_pos (it
);
6869 it
->end_of_box_run_p
6870 = (face_id
!= it
->face_id
6871 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6874 /* If we reached the end of the object we've been iterating (e.g., a
6875 display string or an overlay string), and there's something on
6876 IT->stack, proceed with what's on the stack. It doesn't make
6877 sense to return zero if there's unprocessed stuff on the stack,
6878 because otherwise that stuff will never be displayed. */
6879 if (!success_p
&& it
->sp
> 0)
6881 set_iterator_to_next (it
, 0);
6882 success_p
= get_next_display_element (it
);
6885 /* Value is 0 if end of buffer or string reached. */
6890 /* Move IT to the next display element.
6892 RESEAT_P non-zero means if called on a newline in buffer text,
6893 skip to the next visible line start.
6895 Functions get_next_display_element and set_iterator_to_next are
6896 separate because I find this arrangement easier to handle than a
6897 get_next_display_element function that also increments IT's
6898 position. The way it is we can first look at an iterator's current
6899 display element, decide whether it fits on a line, and if it does,
6900 increment the iterator position. The other way around we probably
6901 would either need a flag indicating whether the iterator has to be
6902 incremented the next time, or we would have to implement a
6903 decrement position function which would not be easy to write. */
6906 set_iterator_to_next (struct it
*it
, int reseat_p
)
6908 /* Reset flags indicating start and end of a sequence of characters
6909 with box. Reset them at the start of this function because
6910 moving the iterator to a new position might set them. */
6911 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6915 case GET_FROM_BUFFER
:
6916 /* The current display element of IT is a character from
6917 current_buffer. Advance in the buffer, and maybe skip over
6918 invisible lines that are so because of selective display. */
6919 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6920 reseat_at_next_visible_line_start (it
, 0);
6921 else if (it
->cmp_it
.id
>= 0)
6923 /* We are currently getting glyphs from a composition. */
6928 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6929 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6930 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6932 it
->cmp_it
.from
= it
->cmp_it
.to
;
6937 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6939 it
->end_charpos
, Qnil
);
6942 else if (! it
->cmp_it
.reversed_p
)
6944 /* Composition created while scanning forward. */
6945 /* Update IT's char/byte positions to point to the first
6946 character of the next grapheme cluster, or to the
6947 character visually after the current composition. */
6948 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6949 bidi_move_to_visually_next (&it
->bidi_it
);
6950 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6951 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6953 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6955 /* Proceed to the next grapheme cluster. */
6956 it
->cmp_it
.from
= it
->cmp_it
.to
;
6960 /* No more grapheme clusters in this composition.
6961 Find the next stop position. */
6962 ptrdiff_t stop
= it
->end_charpos
;
6963 if (it
->bidi_it
.scan_dir
< 0)
6964 /* Now we are scanning backward and don't know
6967 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6968 IT_BYTEPOS (*it
), stop
, Qnil
);
6973 /* Composition created while scanning backward. */
6974 /* Update IT's char/byte positions to point to the last
6975 character of the previous grapheme cluster, or the
6976 character visually after the current composition. */
6977 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6978 bidi_move_to_visually_next (&it
->bidi_it
);
6979 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6980 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6981 if (it
->cmp_it
.from
> 0)
6983 /* Proceed to the previous grapheme cluster. */
6984 it
->cmp_it
.to
= it
->cmp_it
.from
;
6988 /* No more grapheme clusters in this composition.
6989 Find the next stop position. */
6990 ptrdiff_t stop
= it
->end_charpos
;
6991 if (it
->bidi_it
.scan_dir
< 0)
6992 /* Now we are scanning backward and don't know
6995 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6996 IT_BYTEPOS (*it
), stop
, Qnil
);
7002 eassert (it
->len
!= 0);
7006 IT_BYTEPOS (*it
) += it
->len
;
7007 IT_CHARPOS (*it
) += 1;
7011 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7012 /* If this is a new paragraph, determine its base
7013 direction (a.k.a. its base embedding level). */
7014 if (it
->bidi_it
.new_paragraph
)
7015 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7016 bidi_move_to_visually_next (&it
->bidi_it
);
7017 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7018 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7019 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7021 /* As the scan direction was changed, we must
7022 re-compute the stop position for composition. */
7023 ptrdiff_t stop
= it
->end_charpos
;
7024 if (it
->bidi_it
.scan_dir
< 0)
7026 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7027 IT_BYTEPOS (*it
), stop
, Qnil
);
7030 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7034 case GET_FROM_C_STRING
:
7035 /* Current display element of IT is from a C string. */
7037 /* If the string position is beyond string's end, it means
7038 next_element_from_c_string is padding the string with
7039 blanks, in which case we bypass the bidi iterator,
7040 because it cannot deal with such virtual characters. */
7041 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7043 IT_BYTEPOS (*it
) += it
->len
;
7044 IT_CHARPOS (*it
) += 1;
7048 bidi_move_to_visually_next (&it
->bidi_it
);
7049 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7050 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7054 case GET_FROM_DISPLAY_VECTOR
:
7055 /* Current display element of IT is from a display table entry.
7056 Advance in the display table definition. Reset it to null if
7057 end reached, and continue with characters from buffers/
7059 ++it
->current
.dpvec_index
;
7061 /* Restore face of the iterator to what they were before the
7062 display vector entry (these entries may contain faces). */
7063 it
->face_id
= it
->saved_face_id
;
7065 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7067 int recheck_faces
= it
->ellipsis_p
;
7070 it
->method
= GET_FROM_C_STRING
;
7071 else if (STRINGP (it
->string
))
7072 it
->method
= GET_FROM_STRING
;
7075 it
->method
= GET_FROM_BUFFER
;
7076 it
->object
= it
->w
->buffer
;
7080 it
->current
.dpvec_index
= -1;
7082 /* Skip over characters which were displayed via IT->dpvec. */
7083 if (it
->dpvec_char_len
< 0)
7084 reseat_at_next_visible_line_start (it
, 1);
7085 else if (it
->dpvec_char_len
> 0)
7087 if (it
->method
== GET_FROM_STRING
7088 && it
->n_overlay_strings
> 0)
7089 it
->ignore_overlay_strings_at_pos_p
= 1;
7090 it
->len
= it
->dpvec_char_len
;
7091 set_iterator_to_next (it
, reseat_p
);
7094 /* Maybe recheck faces after display vector */
7096 it
->stop_charpos
= IT_CHARPOS (*it
);
7100 case GET_FROM_STRING
:
7101 /* Current display element is a character from a Lisp string. */
7102 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7103 /* Don't advance past string end. These conditions are true
7104 when set_iterator_to_next is called at the end of
7105 get_next_display_element, in which case the Lisp string is
7106 already exhausted, and all we want is pop the iterator
7108 if (it
->current
.overlay_string_index
>= 0)
7110 /* This is an overlay string, so there's no padding with
7111 spaces, and the number of characters in the string is
7112 where the string ends. */
7113 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7114 goto consider_string_end
;
7118 /* Not an overlay string. There could be padding, so test
7119 against it->end_charpos . */
7120 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7121 goto consider_string_end
;
7123 if (it
->cmp_it
.id
>= 0)
7129 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7130 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7131 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7132 it
->cmp_it
.from
= it
->cmp_it
.to
;
7136 composition_compute_stop_pos (&it
->cmp_it
,
7137 IT_STRING_CHARPOS (*it
),
7138 IT_STRING_BYTEPOS (*it
),
7139 it
->end_charpos
, it
->string
);
7142 else if (! it
->cmp_it
.reversed_p
)
7144 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7145 bidi_move_to_visually_next (&it
->bidi_it
);
7146 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7147 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7149 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7150 it
->cmp_it
.from
= it
->cmp_it
.to
;
7153 ptrdiff_t stop
= it
->end_charpos
;
7154 if (it
->bidi_it
.scan_dir
< 0)
7156 composition_compute_stop_pos (&it
->cmp_it
,
7157 IT_STRING_CHARPOS (*it
),
7158 IT_STRING_BYTEPOS (*it
), stop
,
7164 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7165 bidi_move_to_visually_next (&it
->bidi_it
);
7166 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7167 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7168 if (it
->cmp_it
.from
> 0)
7169 it
->cmp_it
.to
= it
->cmp_it
.from
;
7172 ptrdiff_t stop
= it
->end_charpos
;
7173 if (it
->bidi_it
.scan_dir
< 0)
7175 composition_compute_stop_pos (&it
->cmp_it
,
7176 IT_STRING_CHARPOS (*it
),
7177 IT_STRING_BYTEPOS (*it
), stop
,
7185 /* If the string position is beyond string's end, it
7186 means next_element_from_string is padding the string
7187 with blanks, in which case we bypass the bidi
7188 iterator, because it cannot deal with such virtual
7190 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7192 IT_STRING_BYTEPOS (*it
) += it
->len
;
7193 IT_STRING_CHARPOS (*it
) += 1;
7197 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7199 bidi_move_to_visually_next (&it
->bidi_it
);
7200 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7201 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7202 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7204 ptrdiff_t stop
= it
->end_charpos
;
7206 if (it
->bidi_it
.scan_dir
< 0)
7208 composition_compute_stop_pos (&it
->cmp_it
,
7209 IT_STRING_CHARPOS (*it
),
7210 IT_STRING_BYTEPOS (*it
), stop
,
7216 consider_string_end
:
7218 if (it
->current
.overlay_string_index
>= 0)
7220 /* IT->string is an overlay string. Advance to the
7221 next, if there is one. */
7222 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7225 next_overlay_string (it
);
7227 setup_for_ellipsis (it
, 0);
7232 /* IT->string is not an overlay string. If we reached
7233 its end, and there is something on IT->stack, proceed
7234 with what is on the stack. This can be either another
7235 string, this time an overlay string, or a buffer. */
7236 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7240 if (it
->method
== GET_FROM_STRING
)
7241 goto consider_string_end
;
7246 case GET_FROM_IMAGE
:
7247 case GET_FROM_STRETCH
:
7248 /* The position etc with which we have to proceed are on
7249 the stack. The position may be at the end of a string,
7250 if the `display' property takes up the whole string. */
7251 eassert (it
->sp
> 0);
7253 if (it
->method
== GET_FROM_STRING
)
7254 goto consider_string_end
;
7258 /* There are no other methods defined, so this should be a bug. */
7262 eassert (it
->method
!= GET_FROM_STRING
7263 || (STRINGP (it
->string
)
7264 && IT_STRING_CHARPOS (*it
) >= 0));
7267 /* Load IT's display element fields with information about the next
7268 display element which comes from a display table entry or from the
7269 result of translating a control character to one of the forms `^C'
7272 IT->dpvec holds the glyphs to return as characters.
7273 IT->saved_face_id holds the face id before the display vector--it
7274 is restored into IT->face_id in set_iterator_to_next. */
7277 next_element_from_display_vector (struct it
*it
)
7282 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7284 it
->face_id
= it
->saved_face_id
;
7286 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7287 That seemed totally bogus - so I changed it... */
7288 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7290 if (GLYPH_CODE_P (gc
))
7292 it
->c
= GLYPH_CODE_CHAR (gc
);
7293 it
->len
= CHAR_BYTES (it
->c
);
7295 /* The entry may contain a face id to use. Such a face id is
7296 the id of a Lisp face, not a realized face. A face id of
7297 zero means no face is specified. */
7298 if (it
->dpvec_face_id
>= 0)
7299 it
->face_id
= it
->dpvec_face_id
;
7302 int lface_id
= GLYPH_CODE_FACE (gc
);
7304 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7309 /* Display table entry is invalid. Return a space. */
7310 it
->c
= ' ', it
->len
= 1;
7312 /* Don't change position and object of the iterator here. They are
7313 still the values of the character that had this display table
7314 entry or was translated, and that's what we want. */
7315 it
->what
= IT_CHARACTER
;
7319 /* Get the first element of string/buffer in the visual order, after
7320 being reseated to a new position in a string or a buffer. */
7322 get_visually_first_element (struct it
*it
)
7324 int string_p
= STRINGP (it
->string
) || it
->s
;
7325 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7326 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7328 if (STRINGP (it
->string
))
7330 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7331 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7335 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7336 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7339 if (it
->bidi_it
.charpos
== eob
)
7341 /* Nothing to do, but reset the FIRST_ELT flag, like
7342 bidi_paragraph_init does, because we are not going to
7344 it
->bidi_it
.first_elt
= 0;
7346 else if (it
->bidi_it
.charpos
== bob
7348 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7349 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7351 /* If we are at the beginning of a line/string, we can produce
7352 the next element right away. */
7353 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7354 bidi_move_to_visually_next (&it
->bidi_it
);
7358 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7360 /* We need to prime the bidi iterator starting at the line's or
7361 string's beginning, before we will be able to produce the
7364 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7367 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7369 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7371 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7374 /* Now return to buffer/string position where we were asked
7375 to get the next display element, and produce that. */
7376 bidi_move_to_visually_next (&it
->bidi_it
);
7378 while (it
->bidi_it
.bytepos
!= orig_bytepos
7379 && it
->bidi_it
.charpos
< eob
);
7382 /* Adjust IT's position information to where we ended up. */
7383 if (STRINGP (it
->string
))
7385 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7386 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7390 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7391 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7394 if (STRINGP (it
->string
) || !it
->s
)
7396 ptrdiff_t stop
, charpos
, bytepos
;
7398 if (STRINGP (it
->string
))
7401 stop
= SCHARS (it
->string
);
7402 if (stop
> it
->end_charpos
)
7403 stop
= it
->end_charpos
;
7404 charpos
= IT_STRING_CHARPOS (*it
);
7405 bytepos
= IT_STRING_BYTEPOS (*it
);
7409 stop
= it
->end_charpos
;
7410 charpos
= IT_CHARPOS (*it
);
7411 bytepos
= IT_BYTEPOS (*it
);
7413 if (it
->bidi_it
.scan_dir
< 0)
7415 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7420 /* Load IT with the next display element from Lisp string IT->string.
7421 IT->current.string_pos is the current position within the string.
7422 If IT->current.overlay_string_index >= 0, the Lisp string is an
7426 next_element_from_string (struct it
*it
)
7428 struct text_pos position
;
7430 eassert (STRINGP (it
->string
));
7431 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7432 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7433 position
= it
->current
.string_pos
;
7435 /* With bidi reordering, the character to display might not be the
7436 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7437 that we were reseat()ed to a new string, whose paragraph
7438 direction is not known. */
7439 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7441 get_visually_first_element (it
);
7442 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7445 /* Time to check for invisible text? */
7446 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7448 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7451 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7452 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7454 /* With bidi non-linear iteration, we could find
7455 ourselves far beyond the last computed stop_charpos,
7456 with several other stop positions in between that we
7457 missed. Scan them all now, in buffer's logical
7458 order, until we find and handle the last stop_charpos
7459 that precedes our current position. */
7460 handle_stop_backwards (it
, it
->stop_charpos
);
7461 return GET_NEXT_DISPLAY_ELEMENT (it
);
7467 /* Take note of the stop position we just moved
7468 across, for when we will move back across it. */
7469 it
->prev_stop
= it
->stop_charpos
;
7470 /* If we are at base paragraph embedding level, take
7471 note of the last stop position seen at this
7473 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7474 it
->base_level_stop
= it
->stop_charpos
;
7478 /* Since a handler may have changed IT->method, we must
7480 return GET_NEXT_DISPLAY_ELEMENT (it
);
7484 /* If we are before prev_stop, we may have overstepped
7485 on our way backwards a stop_pos, and if so, we need
7486 to handle that stop_pos. */
7487 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7488 /* We can sometimes back up for reasons that have nothing
7489 to do with bidi reordering. E.g., compositions. The
7490 code below is only needed when we are above the base
7491 embedding level, so test for that explicitly. */
7492 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7494 /* If we lost track of base_level_stop, we have no better
7495 place for handle_stop_backwards to start from than string
7496 beginning. This happens, e.g., when we were reseated to
7497 the previous screenful of text by vertical-motion. */
7498 if (it
->base_level_stop
<= 0
7499 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7500 it
->base_level_stop
= 0;
7501 handle_stop_backwards (it
, it
->base_level_stop
);
7502 return GET_NEXT_DISPLAY_ELEMENT (it
);
7506 if (it
->current
.overlay_string_index
>= 0)
7508 /* Get the next character from an overlay string. In overlay
7509 strings, there is no field width or padding with spaces to
7511 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7516 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7517 IT_STRING_BYTEPOS (*it
),
7518 it
->bidi_it
.scan_dir
< 0
7520 : SCHARS (it
->string
))
7521 && next_element_from_composition (it
))
7525 else if (STRING_MULTIBYTE (it
->string
))
7527 const unsigned char *s
= (SDATA (it
->string
)
7528 + IT_STRING_BYTEPOS (*it
));
7529 it
->c
= string_char_and_length (s
, &it
->len
);
7533 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7539 /* Get the next character from a Lisp string that is not an
7540 overlay string. Such strings come from the mode line, for
7541 example. We may have to pad with spaces, or truncate the
7542 string. See also next_element_from_c_string. */
7543 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7548 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7550 /* Pad with spaces. */
7551 it
->c
= ' ', it
->len
= 1;
7552 CHARPOS (position
) = BYTEPOS (position
) = -1;
7554 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7555 IT_STRING_BYTEPOS (*it
),
7556 it
->bidi_it
.scan_dir
< 0
7558 : it
->string_nchars
)
7559 && next_element_from_composition (it
))
7563 else if (STRING_MULTIBYTE (it
->string
))
7565 const unsigned char *s
= (SDATA (it
->string
)
7566 + IT_STRING_BYTEPOS (*it
));
7567 it
->c
= string_char_and_length (s
, &it
->len
);
7571 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7576 /* Record what we have and where it came from. */
7577 it
->what
= IT_CHARACTER
;
7578 it
->object
= it
->string
;
7579 it
->position
= position
;
7584 /* Load IT with next display element from C string IT->s.
7585 IT->string_nchars is the maximum number of characters to return
7586 from the string. IT->end_charpos may be greater than
7587 IT->string_nchars when this function is called, in which case we
7588 may have to return padding spaces. Value is zero if end of string
7589 reached, including padding spaces. */
7592 next_element_from_c_string (struct it
*it
)
7597 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7598 it
->what
= IT_CHARACTER
;
7599 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7602 /* With bidi reordering, the character to display might not be the
7603 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7604 we were reseated to a new string, whose paragraph direction is
7606 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7607 get_visually_first_element (it
);
7609 /* IT's position can be greater than IT->string_nchars in case a
7610 field width or precision has been specified when the iterator was
7612 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7614 /* End of the game. */
7618 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7620 /* Pad with spaces. */
7621 it
->c
= ' ', it
->len
= 1;
7622 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7624 else if (it
->multibyte_p
)
7625 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7627 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7633 /* Set up IT to return characters from an ellipsis, if appropriate.
7634 The definition of the ellipsis glyphs may come from a display table
7635 entry. This function fills IT with the first glyph from the
7636 ellipsis if an ellipsis is to be displayed. */
7639 next_element_from_ellipsis (struct it
*it
)
7641 if (it
->selective_display_ellipsis_p
)
7642 setup_for_ellipsis (it
, it
->len
);
7645 /* The face at the current position may be different from the
7646 face we find after the invisible text. Remember what it
7647 was in IT->saved_face_id, and signal that it's there by
7648 setting face_before_selective_p. */
7649 it
->saved_face_id
= it
->face_id
;
7650 it
->method
= GET_FROM_BUFFER
;
7651 it
->object
= it
->w
->buffer
;
7652 reseat_at_next_visible_line_start (it
, 1);
7653 it
->face_before_selective_p
= 1;
7656 return GET_NEXT_DISPLAY_ELEMENT (it
);
7660 /* Deliver an image display element. The iterator IT is already
7661 filled with image information (done in handle_display_prop). Value
7666 next_element_from_image (struct it
*it
)
7668 it
->what
= IT_IMAGE
;
7669 it
->ignore_overlay_strings_at_pos_p
= 0;
7674 /* Fill iterator IT with next display element from a stretch glyph
7675 property. IT->object is the value of the text property. Value is
7679 next_element_from_stretch (struct it
*it
)
7681 it
->what
= IT_STRETCH
;
7685 /* Scan backwards from IT's current position until we find a stop
7686 position, or until BEGV. This is called when we find ourself
7687 before both the last known prev_stop and base_level_stop while
7688 reordering bidirectional text. */
7691 compute_stop_pos_backwards (struct it
*it
)
7693 const int SCAN_BACK_LIMIT
= 1000;
7694 struct text_pos pos
;
7695 struct display_pos save_current
= it
->current
;
7696 struct text_pos save_position
= it
->position
;
7697 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7698 ptrdiff_t where_we_are
= charpos
;
7699 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7700 ptrdiff_t save_end_pos
= it
->end_charpos
;
7702 eassert (NILP (it
->string
) && !it
->s
);
7703 eassert (it
->bidi_p
);
7707 it
->end_charpos
= min (charpos
+ 1, ZV
);
7708 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7709 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7710 reseat_1 (it
, pos
, 0);
7711 compute_stop_pos (it
);
7712 /* We must advance forward, right? */
7713 if (it
->stop_charpos
<= charpos
)
7716 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7718 if (it
->stop_charpos
<= where_we_are
)
7719 it
->prev_stop
= it
->stop_charpos
;
7721 it
->prev_stop
= BEGV
;
7723 it
->current
= save_current
;
7724 it
->position
= save_position
;
7725 it
->stop_charpos
= save_stop_pos
;
7726 it
->end_charpos
= save_end_pos
;
7729 /* Scan forward from CHARPOS in the current buffer/string, until we
7730 find a stop position > current IT's position. Then handle the stop
7731 position before that. This is called when we bump into a stop
7732 position while reordering bidirectional text. CHARPOS should be
7733 the last previously processed stop_pos (or BEGV/0, if none were
7734 processed yet) whose position is less that IT's current
7738 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7740 int bufp
= !STRINGP (it
->string
);
7741 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7742 struct display_pos save_current
= it
->current
;
7743 struct text_pos save_position
= it
->position
;
7744 struct text_pos pos1
;
7745 ptrdiff_t next_stop
;
7747 /* Scan in strict logical order. */
7748 eassert (it
->bidi_p
);
7752 it
->prev_stop
= charpos
;
7755 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7756 reseat_1 (it
, pos1
, 0);
7759 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7760 compute_stop_pos (it
);
7761 /* We must advance forward, right? */
7762 if (it
->stop_charpos
<= it
->prev_stop
)
7764 charpos
= it
->stop_charpos
;
7766 while (charpos
<= where_we_are
);
7769 it
->current
= save_current
;
7770 it
->position
= save_position
;
7771 next_stop
= it
->stop_charpos
;
7772 it
->stop_charpos
= it
->prev_stop
;
7774 it
->stop_charpos
= next_stop
;
7777 /* Load IT with the next display element from current_buffer. Value
7778 is zero if end of buffer reached. IT->stop_charpos is the next
7779 position at which to stop and check for text properties or buffer
7783 next_element_from_buffer (struct it
*it
)
7787 eassert (IT_CHARPOS (*it
) >= BEGV
);
7788 eassert (NILP (it
->string
) && !it
->s
);
7789 eassert (!it
->bidi_p
7790 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7791 && it
->bidi_it
.string
.s
== NULL
));
7793 /* With bidi reordering, the character to display might not be the
7794 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7795 we were reseat()ed to a new buffer position, which is potentially
7796 a different paragraph. */
7797 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7799 get_visually_first_element (it
);
7800 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7803 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7805 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7807 int overlay_strings_follow_p
;
7809 /* End of the game, except when overlay strings follow that
7810 haven't been returned yet. */
7811 if (it
->overlay_strings_at_end_processed_p
)
7812 overlay_strings_follow_p
= 0;
7815 it
->overlay_strings_at_end_processed_p
= 1;
7816 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7819 if (overlay_strings_follow_p
)
7820 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7824 it
->position
= it
->current
.pos
;
7828 else if (!(!it
->bidi_p
7829 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7830 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7832 /* With bidi non-linear iteration, we could find ourselves
7833 far beyond the last computed stop_charpos, with several
7834 other stop positions in between that we missed. Scan
7835 them all now, in buffer's logical order, until we find
7836 and handle the last stop_charpos that precedes our
7837 current position. */
7838 handle_stop_backwards (it
, it
->stop_charpos
);
7839 return GET_NEXT_DISPLAY_ELEMENT (it
);
7845 /* Take note of the stop position we just moved across,
7846 for when we will move back across it. */
7847 it
->prev_stop
= it
->stop_charpos
;
7848 /* If we are at base paragraph embedding level, take
7849 note of the last stop position seen at this
7851 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7852 it
->base_level_stop
= it
->stop_charpos
;
7855 return GET_NEXT_DISPLAY_ELEMENT (it
);
7859 /* If we are before prev_stop, we may have overstepped on
7860 our way backwards a stop_pos, and if so, we need to
7861 handle that stop_pos. */
7862 && IT_CHARPOS (*it
) < it
->prev_stop
7863 /* We can sometimes back up for reasons that have nothing
7864 to do with bidi reordering. E.g., compositions. The
7865 code below is only needed when we are above the base
7866 embedding level, so test for that explicitly. */
7867 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7869 if (it
->base_level_stop
<= 0
7870 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7872 /* If we lost track of base_level_stop, we need to find
7873 prev_stop by looking backwards. This happens, e.g., when
7874 we were reseated to the previous screenful of text by
7876 it
->base_level_stop
= BEGV
;
7877 compute_stop_pos_backwards (it
);
7878 handle_stop_backwards (it
, it
->prev_stop
);
7881 handle_stop_backwards (it
, it
->base_level_stop
);
7882 return GET_NEXT_DISPLAY_ELEMENT (it
);
7886 /* No face changes, overlays etc. in sight, so just return a
7887 character from current_buffer. */
7891 /* Maybe run the redisplay end trigger hook. Performance note:
7892 This doesn't seem to cost measurable time. */
7893 if (it
->redisplay_end_trigger_charpos
7895 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7896 run_redisplay_end_trigger_hook (it
);
7898 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7899 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7901 && next_element_from_composition (it
))
7906 /* Get the next character, maybe multibyte. */
7907 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7908 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7909 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7911 it
->c
= *p
, it
->len
= 1;
7913 /* Record what we have and where it came from. */
7914 it
->what
= IT_CHARACTER
;
7915 it
->object
= it
->w
->buffer
;
7916 it
->position
= it
->current
.pos
;
7918 /* Normally we return the character found above, except when we
7919 really want to return an ellipsis for selective display. */
7924 /* A value of selective > 0 means hide lines indented more
7925 than that number of columns. */
7926 if (it
->selective
> 0
7927 && IT_CHARPOS (*it
) + 1 < ZV
7928 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7929 IT_BYTEPOS (*it
) + 1,
7932 success_p
= next_element_from_ellipsis (it
);
7933 it
->dpvec_char_len
= -1;
7936 else if (it
->c
== '\r' && it
->selective
== -1)
7938 /* A value of selective == -1 means that everything from the
7939 CR to the end of the line is invisible, with maybe an
7940 ellipsis displayed for it. */
7941 success_p
= next_element_from_ellipsis (it
);
7942 it
->dpvec_char_len
= -1;
7947 /* Value is zero if end of buffer reached. */
7948 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7953 /* Run the redisplay end trigger hook for IT. */
7956 run_redisplay_end_trigger_hook (struct it
*it
)
7958 Lisp_Object args
[3];
7960 /* IT->glyph_row should be non-null, i.e. we should be actually
7961 displaying something, or otherwise we should not run the hook. */
7962 eassert (it
->glyph_row
);
7964 /* Set up hook arguments. */
7965 args
[0] = Qredisplay_end_trigger_functions
;
7966 args
[1] = it
->window
;
7967 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7968 it
->redisplay_end_trigger_charpos
= 0;
7970 /* Since we are *trying* to run these functions, don't try to run
7971 them again, even if they get an error. */
7972 it
->w
->redisplay_end_trigger
= Qnil
;
7973 Frun_hook_with_args (3, args
);
7975 /* Notice if it changed the face of the character we are on. */
7976 handle_face_prop (it
);
7980 /* Deliver a composition display element. Unlike the other
7981 next_element_from_XXX, this function is not registered in the array
7982 get_next_element[]. It is called from next_element_from_buffer and
7983 next_element_from_string when necessary. */
7986 next_element_from_composition (struct it
*it
)
7988 it
->what
= IT_COMPOSITION
;
7989 it
->len
= it
->cmp_it
.nbytes
;
7990 if (STRINGP (it
->string
))
7994 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7995 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7998 it
->position
= it
->current
.string_pos
;
7999 it
->object
= it
->string
;
8000 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8001 IT_STRING_BYTEPOS (*it
), it
->string
);
8007 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8008 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8011 if (it
->bidi_it
.new_paragraph
)
8012 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8013 /* Resync the bidi iterator with IT's new position.
8014 FIXME: this doesn't support bidirectional text. */
8015 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8016 bidi_move_to_visually_next (&it
->bidi_it
);
8020 it
->position
= it
->current
.pos
;
8021 it
->object
= it
->w
->buffer
;
8022 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8023 IT_BYTEPOS (*it
), Qnil
);
8030 /***********************************************************************
8031 Moving an iterator without producing glyphs
8032 ***********************************************************************/
8034 /* Check if iterator is at a position corresponding to a valid buffer
8035 position after some move_it_ call. */
8037 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8038 ((it)->method == GET_FROM_STRING \
8039 ? IT_STRING_CHARPOS (*it) == 0 \
8043 /* Move iterator IT to a specified buffer or X position within one
8044 line on the display without producing glyphs.
8046 OP should be a bit mask including some or all of these bits:
8047 MOVE_TO_X: Stop upon reaching x-position TO_X.
8048 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8049 Regardless of OP's value, stop upon reaching the end of the display line.
8051 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8052 This means, in particular, that TO_X includes window's horizontal
8055 The return value has several possible values that
8056 say what condition caused the scan to stop:
8058 MOVE_POS_MATCH_OR_ZV
8059 - when TO_POS or ZV was reached.
8062 -when TO_X was reached before TO_POS or ZV were reached.
8065 - when we reached the end of the display area and the line must
8069 - when we reached the end of the display area and the line is
8073 - when we stopped at a line end, i.e. a newline or a CR and selective
8076 static enum move_it_result
8077 move_it_in_display_line_to (struct it
*it
,
8078 ptrdiff_t to_charpos
, int to_x
,
8079 enum move_operation_enum op
)
8081 enum move_it_result result
= MOVE_UNDEFINED
;
8082 struct glyph_row
*saved_glyph_row
;
8083 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8084 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8085 void *ppos_data
= NULL
;
8087 enum it_method prev_method
= it
->method
;
8088 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8089 int saw_smaller_pos
= prev_pos
< to_charpos
;
8091 /* Don't produce glyphs in produce_glyphs. */
8092 saved_glyph_row
= it
->glyph_row
;
8093 it
->glyph_row
= NULL
;
8095 /* Use wrap_it to save a copy of IT wherever a word wrap could
8096 occur. Use atpos_it to save a copy of IT at the desired buffer
8097 position, if found, so that we can scan ahead and check if the
8098 word later overshoots the window edge. Use atx_it similarly, for
8104 /* Use ppos_it under bidi reordering to save a copy of IT for the
8105 position > CHARPOS that is the closest to CHARPOS. We restore
8106 that position in IT when we have scanned the entire display line
8107 without finding a match for CHARPOS and all the character
8108 positions are greater than CHARPOS. */
8111 SAVE_IT (ppos_it
, *it
, ppos_data
);
8112 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8113 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8114 SAVE_IT (ppos_it
, *it
, ppos_data
);
8117 #define BUFFER_POS_REACHED_P() \
8118 ((op & MOVE_TO_POS) != 0 \
8119 && BUFFERP (it->object) \
8120 && (IT_CHARPOS (*it) == to_charpos \
8122 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8123 && IT_CHARPOS (*it) > to_charpos) \
8124 || (it->what == IT_COMPOSITION \
8125 && ((IT_CHARPOS (*it) > to_charpos \
8126 && to_charpos >= it->cmp_it.charpos) \
8127 || (IT_CHARPOS (*it) < to_charpos \
8128 && to_charpos <= it->cmp_it.charpos)))) \
8129 && (it->method == GET_FROM_BUFFER \
8130 || (it->method == GET_FROM_DISPLAY_VECTOR \
8131 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8133 /* If there's a line-/wrap-prefix, handle it. */
8134 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8135 && it
->current_y
< it
->last_visible_y
)
8136 handle_line_prefix (it
);
8138 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8139 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8143 int x
, i
, ascent
= 0, descent
= 0;
8145 /* Utility macro to reset an iterator with x, ascent, and descent. */
8146 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8147 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8148 (IT)->max_descent = descent)
8150 /* Stop if we move beyond TO_CHARPOS (after an image or a
8151 display string or stretch glyph). */
8152 if ((op
& MOVE_TO_POS
) != 0
8153 && BUFFERP (it
->object
)
8154 && it
->method
== GET_FROM_BUFFER
8156 /* When the iterator is at base embedding level, we
8157 are guaranteed that characters are delivered for
8158 display in strictly increasing order of their
8159 buffer positions. */
8160 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8161 && IT_CHARPOS (*it
) > to_charpos
)
8163 && (prev_method
== GET_FROM_IMAGE
8164 || prev_method
== GET_FROM_STRETCH
8165 || prev_method
== GET_FROM_STRING
)
8166 /* Passed TO_CHARPOS from left to right. */
8167 && ((prev_pos
< to_charpos
8168 && IT_CHARPOS (*it
) > to_charpos
)
8169 /* Passed TO_CHARPOS from right to left. */
8170 || (prev_pos
> to_charpos
8171 && IT_CHARPOS (*it
) < to_charpos
)))))
8173 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8175 result
= MOVE_POS_MATCH_OR_ZV
;
8178 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8179 /* If wrap_it is valid, the current position might be in a
8180 word that is wrapped. So, save the iterator in
8181 atpos_it and continue to see if wrapping happens. */
8182 SAVE_IT (atpos_it
, *it
, atpos_data
);
8185 /* Stop when ZV reached.
8186 We used to stop here when TO_CHARPOS reached as well, but that is
8187 too soon if this glyph does not fit on this line. So we handle it
8188 explicitly below. */
8189 if (!get_next_display_element (it
))
8191 result
= MOVE_POS_MATCH_OR_ZV
;
8195 if (it
->line_wrap
== TRUNCATE
)
8197 if (BUFFER_POS_REACHED_P ())
8199 result
= MOVE_POS_MATCH_OR_ZV
;
8205 if (it
->line_wrap
== WORD_WRAP
)
8207 if (IT_DISPLAYING_WHITESPACE (it
))
8211 /* We have reached a glyph that follows one or more
8212 whitespace characters. If the position is
8213 already found, we are done. */
8214 if (atpos_it
.sp
>= 0)
8216 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8217 result
= MOVE_POS_MATCH_OR_ZV
;
8222 RESTORE_IT (it
, &atx_it
, atx_data
);
8223 result
= MOVE_X_REACHED
;
8226 /* Otherwise, we can wrap here. */
8227 SAVE_IT (wrap_it
, *it
, wrap_data
);
8233 /* Remember the line height for the current line, in case
8234 the next element doesn't fit on the line. */
8235 ascent
= it
->max_ascent
;
8236 descent
= it
->max_descent
;
8238 /* The call to produce_glyphs will get the metrics of the
8239 display element IT is loaded with. Record the x-position
8240 before this display element, in case it doesn't fit on the
8244 PRODUCE_GLYPHS (it
);
8246 if (it
->area
!= TEXT_AREA
)
8248 prev_method
= it
->method
;
8249 if (it
->method
== GET_FROM_BUFFER
)
8250 prev_pos
= IT_CHARPOS (*it
);
8251 set_iterator_to_next (it
, 1);
8252 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8253 SET_TEXT_POS (this_line_min_pos
,
8254 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8256 && (op
& MOVE_TO_POS
)
8257 && IT_CHARPOS (*it
) > to_charpos
8258 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8259 SAVE_IT (ppos_it
, *it
, ppos_data
);
8263 /* The number of glyphs we get back in IT->nglyphs will normally
8264 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8265 character on a terminal frame, or (iii) a line end. For the
8266 second case, IT->nglyphs - 1 padding glyphs will be present.
8267 (On X frames, there is only one glyph produced for a
8268 composite character.)
8270 The behavior implemented below means, for continuation lines,
8271 that as many spaces of a TAB as fit on the current line are
8272 displayed there. For terminal frames, as many glyphs of a
8273 multi-glyph character are displayed in the current line, too.
8274 This is what the old redisplay code did, and we keep it that
8275 way. Under X, the whole shape of a complex character must
8276 fit on the line or it will be completely displayed in the
8279 Note that both for tabs and padding glyphs, all glyphs have
8283 /* More than one glyph or glyph doesn't fit on line. All
8284 glyphs have the same width. */
8285 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8287 int x_before_this_char
= x
;
8288 int hpos_before_this_char
= it
->hpos
;
8290 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8292 new_x
= x
+ single_glyph_width
;
8294 /* We want to leave anything reaching TO_X to the caller. */
8295 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8297 if (BUFFER_POS_REACHED_P ())
8299 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8300 goto buffer_pos_reached
;
8301 if (atpos_it
.sp
< 0)
8303 SAVE_IT (atpos_it
, *it
, atpos_data
);
8304 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8309 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8312 result
= MOVE_X_REACHED
;
8317 SAVE_IT (atx_it
, *it
, atx_data
);
8318 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8323 if (/* Lines are continued. */
8324 it
->line_wrap
!= TRUNCATE
8325 && (/* And glyph doesn't fit on the line. */
8326 new_x
> it
->last_visible_x
8327 /* Or it fits exactly and we're on a window
8329 || (new_x
== it
->last_visible_x
8330 && FRAME_WINDOW_P (it
->f
))))
8332 if (/* IT->hpos == 0 means the very first glyph
8333 doesn't fit on the line, e.g. a wide image. */
8335 || (new_x
== it
->last_visible_x
8336 && FRAME_WINDOW_P (it
->f
)))
8339 it
->current_x
= new_x
;
8341 /* The character's last glyph just barely fits
8343 if (i
== it
->nglyphs
- 1)
8345 /* If this is the destination position,
8346 return a position *before* it in this row,
8347 now that we know it fits in this row. */
8348 if (BUFFER_POS_REACHED_P ())
8350 if (it
->line_wrap
!= WORD_WRAP
8353 it
->hpos
= hpos_before_this_char
;
8354 it
->current_x
= x_before_this_char
;
8355 result
= MOVE_POS_MATCH_OR_ZV
;
8358 if (it
->line_wrap
== WORD_WRAP
8361 SAVE_IT (atpos_it
, *it
, atpos_data
);
8362 atpos_it
.current_x
= x_before_this_char
;
8363 atpos_it
.hpos
= hpos_before_this_char
;
8367 prev_method
= it
->method
;
8368 if (it
->method
== GET_FROM_BUFFER
)
8369 prev_pos
= IT_CHARPOS (*it
);
8370 set_iterator_to_next (it
, 1);
8371 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8372 SET_TEXT_POS (this_line_min_pos
,
8373 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8374 /* On graphical terminals, newlines may
8375 "overflow" into the fringe if
8376 overflow-newline-into-fringe is non-nil.
8377 On text terminals, newlines may overflow
8378 into the last glyph on the display
8380 if (!FRAME_WINDOW_P (it
->f
)
8381 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8383 if (!get_next_display_element (it
))
8385 result
= MOVE_POS_MATCH_OR_ZV
;
8388 if (BUFFER_POS_REACHED_P ())
8390 if (ITERATOR_AT_END_OF_LINE_P (it
))
8391 result
= MOVE_POS_MATCH_OR_ZV
;
8393 result
= MOVE_LINE_CONTINUED
;
8396 if (ITERATOR_AT_END_OF_LINE_P (it
))
8398 result
= MOVE_NEWLINE_OR_CR
;
8405 IT_RESET_X_ASCENT_DESCENT (it
);
8407 if (wrap_it
.sp
>= 0)
8409 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8414 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8416 result
= MOVE_LINE_CONTINUED
;
8420 if (BUFFER_POS_REACHED_P ())
8422 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8423 goto buffer_pos_reached
;
8424 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8426 SAVE_IT (atpos_it
, *it
, atpos_data
);
8427 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8431 if (new_x
> it
->first_visible_x
)
8433 /* Glyph is visible. Increment number of glyphs that
8434 would be displayed. */
8439 if (result
!= MOVE_UNDEFINED
)
8442 else if (BUFFER_POS_REACHED_P ())
8445 IT_RESET_X_ASCENT_DESCENT (it
);
8446 result
= MOVE_POS_MATCH_OR_ZV
;
8449 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8451 /* Stop when TO_X specified and reached. This check is
8452 necessary here because of lines consisting of a line end,
8453 only. The line end will not produce any glyphs and we
8454 would never get MOVE_X_REACHED. */
8455 eassert (it
->nglyphs
== 0);
8456 result
= MOVE_X_REACHED
;
8460 /* Is this a line end? If yes, we're done. */
8461 if (ITERATOR_AT_END_OF_LINE_P (it
))
8463 /* If we are past TO_CHARPOS, but never saw any character
8464 positions smaller than TO_CHARPOS, return
8465 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8467 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8469 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8471 if (IT_CHARPOS (ppos_it
) < ZV
)
8473 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8474 result
= MOVE_POS_MATCH_OR_ZV
;
8477 goto buffer_pos_reached
;
8479 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8480 && IT_CHARPOS (*it
) > to_charpos
)
8481 goto buffer_pos_reached
;
8483 result
= MOVE_NEWLINE_OR_CR
;
8486 result
= MOVE_NEWLINE_OR_CR
;
8490 prev_method
= it
->method
;
8491 if (it
->method
== GET_FROM_BUFFER
)
8492 prev_pos
= IT_CHARPOS (*it
);
8493 /* The current display element has been consumed. Advance
8495 set_iterator_to_next (it
, 1);
8496 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8497 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8498 if (IT_CHARPOS (*it
) < to_charpos
)
8499 saw_smaller_pos
= 1;
8501 && (op
& MOVE_TO_POS
)
8502 && IT_CHARPOS (*it
) >= to_charpos
8503 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8504 SAVE_IT (ppos_it
, *it
, ppos_data
);
8506 /* Stop if lines are truncated and IT's current x-position is
8507 past the right edge of the window now. */
8508 if (it
->line_wrap
== TRUNCATE
8509 && it
->current_x
>= it
->last_visible_x
)
8511 if (!FRAME_WINDOW_P (it
->f
)
8512 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8516 if ((at_eob_p
= !get_next_display_element (it
))
8517 || BUFFER_POS_REACHED_P ()
8518 /* If we are past TO_CHARPOS, but never saw any
8519 character positions smaller than TO_CHARPOS,
8520 return MOVE_POS_MATCH_OR_ZV, like the
8521 unidirectional display did. */
8522 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8524 && IT_CHARPOS (*it
) > to_charpos
))
8527 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8528 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8529 result
= MOVE_POS_MATCH_OR_ZV
;
8532 if (ITERATOR_AT_END_OF_LINE_P (it
))
8534 result
= MOVE_NEWLINE_OR_CR
;
8538 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8540 && IT_CHARPOS (*it
) > to_charpos
)
8542 if (IT_CHARPOS (ppos_it
) < ZV
)
8543 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8544 result
= MOVE_POS_MATCH_OR_ZV
;
8547 result
= MOVE_LINE_TRUNCATED
;
8550 #undef IT_RESET_X_ASCENT_DESCENT
8553 #undef BUFFER_POS_REACHED_P
8555 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8556 restore the saved iterator. */
8557 if (atpos_it
.sp
>= 0)
8558 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8559 else if (atx_it
.sp
>= 0)
8560 RESTORE_IT (it
, &atx_it
, atx_data
);
8565 bidi_unshelve_cache (atpos_data
, 1);
8567 bidi_unshelve_cache (atx_data
, 1);
8569 bidi_unshelve_cache (wrap_data
, 1);
8571 bidi_unshelve_cache (ppos_data
, 1);
8573 /* Restore the iterator settings altered at the beginning of this
8575 it
->glyph_row
= saved_glyph_row
;
8579 /* For external use. */
8581 move_it_in_display_line (struct it
*it
,
8582 ptrdiff_t to_charpos
, int to_x
,
8583 enum move_operation_enum op
)
8585 if (it
->line_wrap
== WORD_WRAP
8586 && (op
& MOVE_TO_X
))
8589 void *save_data
= NULL
;
8592 SAVE_IT (save_it
, *it
, save_data
);
8593 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8594 /* When word-wrap is on, TO_X may lie past the end
8595 of a wrapped line. Then it->current is the
8596 character on the next line, so backtrack to the
8597 space before the wrap point. */
8598 if (skip
== MOVE_LINE_CONTINUED
)
8600 int prev_x
= max (it
->current_x
- 1, 0);
8601 RESTORE_IT (it
, &save_it
, save_data
);
8602 move_it_in_display_line_to
8603 (it
, -1, prev_x
, MOVE_TO_X
);
8606 bidi_unshelve_cache (save_data
, 1);
8609 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8613 /* Move IT forward until it satisfies one or more of the criteria in
8614 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8616 OP is a bit-mask that specifies where to stop, and in particular,
8617 which of those four position arguments makes a difference. See the
8618 description of enum move_operation_enum.
8620 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8621 screen line, this function will set IT to the next position that is
8622 displayed to the right of TO_CHARPOS on the screen. */
8625 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8627 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8628 int line_height
, line_start_x
= 0, reached
= 0;
8629 void *backup_data
= NULL
;
8633 if (op
& MOVE_TO_VPOS
)
8635 /* If no TO_CHARPOS and no TO_X specified, stop at the
8636 start of the line TO_VPOS. */
8637 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8639 if (it
->vpos
== to_vpos
)
8645 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8649 /* TO_VPOS >= 0 means stop at TO_X in the line at
8650 TO_VPOS, or at TO_POS, whichever comes first. */
8651 if (it
->vpos
== to_vpos
)
8657 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8659 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8664 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8666 /* We have reached TO_X but not in the line we want. */
8667 skip
= move_it_in_display_line_to (it
, to_charpos
,
8669 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8677 else if (op
& MOVE_TO_Y
)
8679 struct it it_backup
;
8681 if (it
->line_wrap
== WORD_WRAP
)
8682 SAVE_IT (it_backup
, *it
, backup_data
);
8684 /* TO_Y specified means stop at TO_X in the line containing
8685 TO_Y---or at TO_CHARPOS if this is reached first. The
8686 problem is that we can't really tell whether the line
8687 contains TO_Y before we have completely scanned it, and
8688 this may skip past TO_X. What we do is to first scan to
8691 If TO_X is not specified, use a TO_X of zero. The reason
8692 is to make the outcome of this function more predictable.
8693 If we didn't use TO_X == 0, we would stop at the end of
8694 the line which is probably not what a caller would expect
8696 skip
= move_it_in_display_line_to
8697 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8698 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8700 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8701 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8703 else if (skip
== MOVE_X_REACHED
)
8705 /* If TO_X was reached, we want to know whether TO_Y is
8706 in the line. We know this is the case if the already
8707 scanned glyphs make the line tall enough. Otherwise,
8708 we must check by scanning the rest of the line. */
8709 line_height
= it
->max_ascent
+ it
->max_descent
;
8710 if (to_y
>= it
->current_y
8711 && to_y
< it
->current_y
+ line_height
)
8716 SAVE_IT (it_backup
, *it
, backup_data
);
8717 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8718 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8720 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8721 line_height
= it
->max_ascent
+ it
->max_descent
;
8722 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8724 if (to_y
>= it
->current_y
8725 && to_y
< it
->current_y
+ line_height
)
8727 /* If TO_Y is in this line and TO_X was reached
8728 above, we scanned too far. We have to restore
8729 IT's settings to the ones before skipping. But
8730 keep the more accurate values of max_ascent and
8731 max_descent we've found while skipping the rest
8732 of the line, for the sake of callers, such as
8733 pos_visible_p, that need to know the line
8735 int max_ascent
= it
->max_ascent
;
8736 int max_descent
= it
->max_descent
;
8738 RESTORE_IT (it
, &it_backup
, backup_data
);
8739 it
->max_ascent
= max_ascent
;
8740 it
->max_descent
= max_descent
;
8746 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8752 /* Check whether TO_Y is in this line. */
8753 line_height
= it
->max_ascent
+ it
->max_descent
;
8754 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8756 if (to_y
>= it
->current_y
8757 && to_y
< it
->current_y
+ line_height
)
8759 /* When word-wrap is on, TO_X may lie past the end
8760 of a wrapped line. Then it->current is the
8761 character on the next line, so backtrack to the
8762 space before the wrap point. */
8763 if (skip
== MOVE_LINE_CONTINUED
8764 && it
->line_wrap
== WORD_WRAP
)
8766 int prev_x
= max (it
->current_x
- 1, 0);
8767 RESTORE_IT (it
, &it_backup
, backup_data
);
8768 skip
= move_it_in_display_line_to
8769 (it
, -1, prev_x
, MOVE_TO_X
);
8778 else if (BUFFERP (it
->object
)
8779 && (it
->method
== GET_FROM_BUFFER
8780 || it
->method
== GET_FROM_STRETCH
)
8781 && IT_CHARPOS (*it
) >= to_charpos
8782 /* Under bidi iteration, a call to set_iterator_to_next
8783 can scan far beyond to_charpos if the initial
8784 portion of the next line needs to be reordered. In
8785 that case, give move_it_in_display_line_to another
8788 && it
->bidi_it
.scan_dir
== -1))
8789 skip
= MOVE_POS_MATCH_OR_ZV
;
8791 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8795 case MOVE_POS_MATCH_OR_ZV
:
8799 case MOVE_NEWLINE_OR_CR
:
8800 set_iterator_to_next (it
, 1);
8801 it
->continuation_lines_width
= 0;
8804 case MOVE_LINE_TRUNCATED
:
8805 it
->continuation_lines_width
= 0;
8806 reseat_at_next_visible_line_start (it
, 0);
8807 if ((op
& MOVE_TO_POS
) != 0
8808 && IT_CHARPOS (*it
) > to_charpos
)
8815 case MOVE_LINE_CONTINUED
:
8816 /* For continued lines ending in a tab, some of the glyphs
8817 associated with the tab are displayed on the current
8818 line. Since it->current_x does not include these glyphs,
8819 we use it->last_visible_x instead. */
8822 it
->continuation_lines_width
+= it
->last_visible_x
;
8823 /* When moving by vpos, ensure that the iterator really
8824 advances to the next line (bug#847, bug#969). Fixme:
8825 do we need to do this in other circumstances? */
8826 if (it
->current_x
!= it
->last_visible_x
8827 && (op
& MOVE_TO_VPOS
)
8828 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8830 line_start_x
= it
->current_x
+ it
->pixel_width
8831 - it
->last_visible_x
;
8832 set_iterator_to_next (it
, 0);
8836 it
->continuation_lines_width
+= it
->current_x
;
8843 /* Reset/increment for the next run. */
8844 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8845 it
->current_x
= line_start_x
;
8848 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8850 last_height
= it
->max_ascent
+ it
->max_descent
;
8851 last_max_ascent
= it
->max_ascent
;
8852 it
->max_ascent
= it
->max_descent
= 0;
8857 /* On text terminals, we may stop at the end of a line in the middle
8858 of a multi-character glyph. If the glyph itself is continued,
8859 i.e. it is actually displayed on the next line, don't treat this
8860 stopping point as valid; move to the next line instead (unless
8861 that brings us offscreen). */
8862 if (!FRAME_WINDOW_P (it
->f
)
8864 && IT_CHARPOS (*it
) == to_charpos
8865 && it
->what
== IT_CHARACTER
8867 && it
->line_wrap
== WINDOW_WRAP
8868 && it
->current_x
== it
->last_visible_x
- 1
8871 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8873 it
->continuation_lines_width
+= it
->current_x
;
8874 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8875 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8877 last_height
= it
->max_ascent
+ it
->max_descent
;
8878 last_max_ascent
= it
->max_ascent
;
8882 bidi_unshelve_cache (backup_data
, 1);
8884 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8888 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8890 If DY > 0, move IT backward at least that many pixels. DY = 0
8891 means move IT backward to the preceding line start or BEGV. This
8892 function may move over more than DY pixels if IT->current_y - DY
8893 ends up in the middle of a line; in this case IT->current_y will be
8894 set to the top of the line moved to. */
8897 move_it_vertically_backward (struct it
*it
, int dy
)
8901 void *it2data
= NULL
, *it3data
= NULL
;
8902 ptrdiff_t start_pos
;
8907 start_pos
= IT_CHARPOS (*it
);
8909 /* Estimate how many newlines we must move back. */
8910 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8912 /* Set the iterator's position that many lines back. */
8913 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8914 back_to_previous_visible_line_start (it
);
8916 /* Reseat the iterator here. When moving backward, we don't want
8917 reseat to skip forward over invisible text, set up the iterator
8918 to deliver from overlay strings at the new position etc. So,
8919 use reseat_1 here. */
8920 reseat_1 (it
, it
->current
.pos
, 1);
8922 /* We are now surely at a line start. */
8923 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8924 reordering is in effect. */
8925 it
->continuation_lines_width
= 0;
8927 /* Move forward and see what y-distance we moved. First move to the
8928 start of the next line so that we get its height. We need this
8929 height to be able to tell whether we reached the specified
8931 SAVE_IT (it2
, *it
, it2data
);
8932 it2
.max_ascent
= it2
.max_descent
= 0;
8935 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8936 MOVE_TO_POS
| MOVE_TO_VPOS
);
8938 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8939 /* If we are in a display string which starts at START_POS,
8940 and that display string includes a newline, and we are
8941 right after that newline (i.e. at the beginning of a
8942 display line), exit the loop, because otherwise we will
8943 infloop, since move_it_to will see that it is already at
8944 START_POS and will not move. */
8945 || (it2
.method
== GET_FROM_STRING
8946 && IT_CHARPOS (it2
) == start_pos
8947 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8948 eassert (IT_CHARPOS (*it
) >= BEGV
);
8949 SAVE_IT (it3
, it2
, it3data
);
8951 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8952 eassert (IT_CHARPOS (*it
) >= BEGV
);
8953 /* H is the actual vertical distance from the position in *IT
8954 and the starting position. */
8955 h
= it2
.current_y
- it
->current_y
;
8956 /* NLINES is the distance in number of lines. */
8957 nlines
= it2
.vpos
- it
->vpos
;
8959 /* Correct IT's y and vpos position
8960 so that they are relative to the starting point. */
8966 /* DY == 0 means move to the start of the screen line. The
8967 value of nlines is > 0 if continuation lines were involved,
8968 or if the original IT position was at start of a line. */
8969 RESTORE_IT (it
, it
, it2data
);
8971 move_it_by_lines (it
, nlines
);
8972 /* The above code moves us to some position NLINES down,
8973 usually to its first glyph (leftmost in an L2R line), but
8974 that's not necessarily the start of the line, under bidi
8975 reordering. We want to get to the character position
8976 that is immediately after the newline of the previous
8979 && !it
->continuation_lines_width
8980 && !STRINGP (it
->string
)
8981 && IT_CHARPOS (*it
) > BEGV
8982 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8985 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8987 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8989 bidi_unshelve_cache (it3data
, 1);
8993 /* The y-position we try to reach, relative to *IT.
8994 Note that H has been subtracted in front of the if-statement. */
8995 int target_y
= it
->current_y
+ h
- dy
;
8996 int y0
= it3
.current_y
;
9000 RESTORE_IT (&it3
, &it3
, it3data
);
9001 y1
= line_bottom_y (&it3
);
9002 line_height
= y1
- y0
;
9003 RESTORE_IT (it
, it
, it2data
);
9004 /* If we did not reach target_y, try to move further backward if
9005 we can. If we moved too far backward, try to move forward. */
9006 if (target_y
< it
->current_y
9007 /* This is heuristic. In a window that's 3 lines high, with
9008 a line height of 13 pixels each, recentering with point
9009 on the bottom line will try to move -39/2 = 19 pixels
9010 backward. Try to avoid moving into the first line. */
9011 && (it
->current_y
- target_y
9012 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9013 && IT_CHARPOS (*it
) > BEGV
)
9015 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9016 target_y
- it
->current_y
));
9017 dy
= it
->current_y
- target_y
;
9018 goto move_further_back
;
9020 else if (target_y
>= it
->current_y
+ line_height
9021 && IT_CHARPOS (*it
) < ZV
)
9023 /* Should move forward by at least one line, maybe more.
9025 Note: Calling move_it_by_lines can be expensive on
9026 terminal frames, where compute_motion is used (via
9027 vmotion) to do the job, when there are very long lines
9028 and truncate-lines is nil. That's the reason for
9029 treating terminal frames specially here. */
9031 if (!FRAME_WINDOW_P (it
->f
))
9032 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9037 move_it_by_lines (it
, 1);
9039 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9046 /* Move IT by a specified amount of pixel lines DY. DY negative means
9047 move backwards. DY = 0 means move to start of screen line. At the
9048 end, IT will be on the start of a screen line. */
9051 move_it_vertically (struct it
*it
, int dy
)
9054 move_it_vertically_backward (it
, -dy
);
9057 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9058 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9059 MOVE_TO_POS
| MOVE_TO_Y
);
9060 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9062 /* If buffer ends in ZV without a newline, move to the start of
9063 the line to satisfy the post-condition. */
9064 if (IT_CHARPOS (*it
) == ZV
9066 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9067 move_it_by_lines (it
, 0);
9072 /* Move iterator IT past the end of the text line it is in. */
9075 move_it_past_eol (struct it
*it
)
9077 enum move_it_result rc
;
9079 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9080 if (rc
== MOVE_NEWLINE_OR_CR
)
9081 set_iterator_to_next (it
, 0);
9085 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9086 negative means move up. DVPOS == 0 means move to the start of the
9089 Optimization idea: If we would know that IT->f doesn't use
9090 a face with proportional font, we could be faster for
9091 truncate-lines nil. */
9094 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9097 /* The commented-out optimization uses vmotion on terminals. This
9098 gives bad results, because elements like it->what, on which
9099 callers such as pos_visible_p rely, aren't updated. */
9100 /* struct position pos;
9101 if (!FRAME_WINDOW_P (it->f))
9103 struct text_pos textpos;
9105 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9106 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9107 reseat (it, textpos, 1);
9108 it->vpos += pos.vpos;
9109 it->current_y += pos.vpos;
9115 /* DVPOS == 0 means move to the start of the screen line. */
9116 move_it_vertically_backward (it
, 0);
9117 /* Let next call to line_bottom_y calculate real line height */
9122 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9123 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9125 /* Only move to the next buffer position if we ended up in a
9126 string from display property, not in an overlay string
9127 (before-string or after-string). That is because the
9128 latter don't conceal the underlying buffer position, so
9129 we can ask to move the iterator to the exact position we
9130 are interested in. Note that, even if we are already at
9131 IT_CHARPOS (*it), the call below is not a no-op, as it
9132 will detect that we are at the end of the string, pop the
9133 iterator, and compute it->current_x and it->hpos
9135 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9136 -1, -1, -1, MOVE_TO_POS
);
9142 void *it2data
= NULL
;
9143 ptrdiff_t start_charpos
, i
;
9145 /* Start at the beginning of the screen line containing IT's
9146 position. This may actually move vertically backwards,
9147 in case of overlays, so adjust dvpos accordingly. */
9149 move_it_vertically_backward (it
, 0);
9152 /* Go back -DVPOS visible lines and reseat the iterator there. */
9153 start_charpos
= IT_CHARPOS (*it
);
9154 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9155 back_to_previous_visible_line_start (it
);
9156 reseat (it
, it
->current
.pos
, 1);
9158 /* Move further back if we end up in a string or an image. */
9159 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9161 /* First try to move to start of display line. */
9163 move_it_vertically_backward (it
, 0);
9165 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9167 /* If start of line is still in string or image,
9168 move further back. */
9169 back_to_previous_visible_line_start (it
);
9170 reseat (it
, it
->current
.pos
, 1);
9174 it
->current_x
= it
->hpos
= 0;
9176 /* Above call may have moved too far if continuation lines
9177 are involved. Scan forward and see if it did. */
9178 SAVE_IT (it2
, *it
, it2data
);
9179 it2
.vpos
= it2
.current_y
= 0;
9180 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9181 it
->vpos
-= it2
.vpos
;
9182 it
->current_y
-= it2
.current_y
;
9183 it
->current_x
= it
->hpos
= 0;
9185 /* If we moved too far back, move IT some lines forward. */
9186 if (it2
.vpos
> -dvpos
)
9188 int delta
= it2
.vpos
+ dvpos
;
9190 RESTORE_IT (&it2
, &it2
, it2data
);
9191 SAVE_IT (it2
, *it
, it2data
);
9192 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9193 /* Move back again if we got too far ahead. */
9194 if (IT_CHARPOS (*it
) >= start_charpos
)
9195 RESTORE_IT (it
, &it2
, it2data
);
9197 bidi_unshelve_cache (it2data
, 1);
9200 RESTORE_IT (it
, it
, it2data
);
9204 /* Return 1 if IT points into the middle of a display vector. */
9207 in_display_vector_p (struct it
*it
)
9209 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9210 && it
->current
.dpvec_index
> 0
9211 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9215 /***********************************************************************
9217 ***********************************************************************/
9220 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9224 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9226 Lisp_Object args
[3];
9227 Lisp_Object msg
, fmt
;
9230 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9233 /* Do nothing if called asynchronously. Inserting text into
9234 a buffer may call after-change-functions and alike and
9235 that would means running Lisp asynchronously. */
9236 if (handling_signal
)
9240 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9242 args
[0] = fmt
= build_string (format
);
9245 msg
= Fformat (3, args
);
9247 len
= SBYTES (msg
) + 1;
9248 SAFE_ALLOCA (buffer
, char *, len
);
9249 memcpy (buffer
, SDATA (msg
), len
);
9251 message_dolog (buffer
, len
- 1, 1, 0);
9258 /* Output a newline in the *Messages* buffer if "needs" one. */
9261 message_log_maybe_newline (void)
9263 if (message_log_need_newline
)
9264 message_dolog ("", 0, 1, 0);
9268 /* Add a string M of length NBYTES to the message log, optionally
9269 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9270 nonzero, means interpret the contents of M as multibyte. This
9271 function calls low-level routines in order to bypass text property
9272 hooks, etc. which might not be safe to run.
9274 This may GC (insert may run before/after change hooks),
9275 so the buffer M must NOT point to a Lisp string. */
9278 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9280 const unsigned char *msg
= (const unsigned char *) m
;
9282 if (!NILP (Vmemory_full
))
9285 if (!NILP (Vmessage_log_max
))
9287 struct buffer
*oldbuf
;
9288 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9289 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9290 ptrdiff_t point_at_end
= 0;
9291 ptrdiff_t zv_at_end
= 0;
9292 Lisp_Object old_deactivate_mark
, tem
;
9293 struct gcpro gcpro1
;
9295 old_deactivate_mark
= Vdeactivate_mark
;
9296 oldbuf
= current_buffer
;
9297 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9298 BVAR (current_buffer
, undo_list
) = Qt
;
9300 oldpoint
= message_dolog_marker1
;
9301 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9302 oldbegv
= message_dolog_marker2
;
9303 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9304 oldzv
= message_dolog_marker3
;
9305 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9306 GCPRO1 (old_deactivate_mark
);
9314 BEGV_BYTE
= BEG_BYTE
;
9317 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9319 /* Insert the string--maybe converting multibyte to single byte
9320 or vice versa, so that all the text fits the buffer. */
9322 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9328 /* Convert a multibyte string to single-byte
9329 for the *Message* buffer. */
9330 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9332 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9333 work
[0] = (ASCII_CHAR_P (c
)
9335 : multibyte_char_to_unibyte (c
));
9336 insert_1_both (work
, 1, 1, 1, 0, 0);
9339 else if (! multibyte
9340 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9344 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9345 /* Convert a single-byte string to multibyte
9346 for the *Message* buffer. */
9347 for (i
= 0; i
< nbytes
; i
++)
9350 MAKE_CHAR_MULTIBYTE (c
);
9351 char_bytes
= CHAR_STRING (c
, str
);
9352 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9356 insert_1 (m
, nbytes
, 1, 0, 0);
9360 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9362 insert_1 ("\n", 1, 1, 0, 0);
9364 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9366 this_bol_byte
= PT_BYTE
;
9368 /* See if this line duplicates the previous one.
9369 If so, combine duplicates. */
9372 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9374 prev_bol_byte
= PT_BYTE
;
9376 dups
= message_log_check_duplicate (prev_bol_byte
,
9380 del_range_both (prev_bol
, prev_bol_byte
,
9381 this_bol
, this_bol_byte
, 0);
9384 char dupstr
[sizeof " [ times]"
9385 + INT_STRLEN_BOUND (printmax_t
)];
9387 /* If you change this format, don't forget to also
9388 change message_log_check_duplicate. */
9389 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9390 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9391 insert_1 (dupstr
, duplen
, 1, 0, 1);
9396 /* If we have more than the desired maximum number of lines
9397 in the *Messages* buffer now, delete the oldest ones.
9398 This is safe because we don't have undo in this buffer. */
9400 if (NATNUMP (Vmessage_log_max
))
9402 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9403 -XFASTINT (Vmessage_log_max
) - 1, 0);
9404 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9407 BEGV
= XMARKER (oldbegv
)->charpos
;
9408 BEGV_BYTE
= marker_byte_position (oldbegv
);
9417 ZV
= XMARKER (oldzv
)->charpos
;
9418 ZV_BYTE
= marker_byte_position (oldzv
);
9422 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9424 /* We can't do Fgoto_char (oldpoint) because it will run some
9426 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9427 XMARKER (oldpoint
)->bytepos
);
9430 unchain_marker (XMARKER (oldpoint
));
9431 unchain_marker (XMARKER (oldbegv
));
9432 unchain_marker (XMARKER (oldzv
));
9434 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9435 set_buffer_internal (oldbuf
);
9437 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9438 message_log_need_newline
= !nlflag
;
9439 Vdeactivate_mark
= old_deactivate_mark
;
9444 /* We are at the end of the buffer after just having inserted a newline.
9445 (Note: We depend on the fact we won't be crossing the gap.)
9446 Check to see if the most recent message looks a lot like the previous one.
9447 Return 0 if different, 1 if the new one should just replace it, or a
9448 value N > 1 if we should also append " [N times]". */
9451 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9454 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9456 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9457 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9459 for (i
= 0; i
< len
; i
++)
9461 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9469 if (*p1
++ == ' ' && *p1
++ == '[')
9472 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9473 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9480 /* Display an echo area message M with a specified length of NBYTES
9481 bytes. The string may include null characters. If M is 0, clear
9482 out any existing message, and let the mini-buffer text show
9485 This may GC, so the buffer M must NOT point to a Lisp string. */
9488 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9490 /* First flush out any partial line written with print. */
9491 message_log_maybe_newline ();
9493 message_dolog (m
, nbytes
, 1, multibyte
);
9494 message2_nolog (m
, nbytes
, multibyte
);
9498 /* The non-logging counterpart of message2. */
9501 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9503 struct frame
*sf
= SELECTED_FRAME ();
9504 message_enable_multibyte
= multibyte
;
9506 if (FRAME_INITIAL_P (sf
))
9508 if (noninteractive_need_newline
)
9509 putc ('\n', stderr
);
9510 noninteractive_need_newline
= 0;
9512 fwrite (m
, nbytes
, 1, stderr
);
9513 if (cursor_in_echo_area
== 0)
9514 fprintf (stderr
, "\n");
9517 /* A null message buffer means that the frame hasn't really been
9518 initialized yet. Error messages get reported properly by
9519 cmd_error, so this must be just an informative message; toss it. */
9520 else if (INTERACTIVE
9521 && sf
->glyphs_initialized_p
9522 && FRAME_MESSAGE_BUF (sf
))
9524 Lisp_Object mini_window
;
9527 /* Get the frame containing the mini-buffer
9528 that the selected frame is using. */
9529 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9530 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9532 FRAME_SAMPLE_VISIBILITY (f
);
9533 if (FRAME_VISIBLE_P (sf
)
9534 && ! FRAME_VISIBLE_P (f
))
9535 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9539 set_message (m
, Qnil
, nbytes
, multibyte
);
9540 if (minibuffer_auto_raise
)
9541 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9544 clear_message (1, 1);
9546 do_pending_window_change (0);
9547 echo_area_display (1);
9548 do_pending_window_change (0);
9549 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9550 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9555 /* Display an echo area message M with a specified length of NBYTES
9556 bytes. The string may include null characters. If M is not a
9557 string, clear out any existing message, and let the mini-buffer
9560 This function cancels echoing. */
9563 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9565 struct gcpro gcpro1
;
9568 clear_message (1,1);
9571 /* First flush out any partial line written with print. */
9572 message_log_maybe_newline ();
9578 SAFE_ALLOCA (buffer
, char *, nbytes
);
9579 memcpy (buffer
, SDATA (m
), nbytes
);
9580 message_dolog (buffer
, nbytes
, 1, multibyte
);
9583 message3_nolog (m
, nbytes
, multibyte
);
9589 /* The non-logging version of message3.
9590 This does not cancel echoing, because it is used for echoing.
9591 Perhaps we need to make a separate function for echoing
9592 and make this cancel echoing. */
9595 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9597 struct frame
*sf
= SELECTED_FRAME ();
9598 message_enable_multibyte
= multibyte
;
9600 if (FRAME_INITIAL_P (sf
))
9602 if (noninteractive_need_newline
)
9603 putc ('\n', stderr
);
9604 noninteractive_need_newline
= 0;
9606 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9607 if (cursor_in_echo_area
== 0)
9608 fprintf (stderr
, "\n");
9611 /* A null message buffer means that the frame hasn't really been
9612 initialized yet. Error messages get reported properly by
9613 cmd_error, so this must be just an informative message; toss it. */
9614 else if (INTERACTIVE
9615 && sf
->glyphs_initialized_p
9616 && FRAME_MESSAGE_BUF (sf
))
9618 Lisp_Object mini_window
;
9622 /* Get the frame containing the mini-buffer
9623 that the selected frame is using. */
9624 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9625 frame
= XWINDOW (mini_window
)->frame
;
9628 FRAME_SAMPLE_VISIBILITY (f
);
9629 if (FRAME_VISIBLE_P (sf
)
9630 && !FRAME_VISIBLE_P (f
))
9631 Fmake_frame_visible (frame
);
9633 if (STRINGP (m
) && SCHARS (m
) > 0)
9635 set_message (NULL
, m
, nbytes
, multibyte
);
9636 if (minibuffer_auto_raise
)
9637 Fraise_frame (frame
);
9638 /* Assume we are not echoing.
9639 (If we are, echo_now will override this.) */
9640 echo_message_buffer
= Qnil
;
9643 clear_message (1, 1);
9645 do_pending_window_change (0);
9646 echo_area_display (1);
9647 do_pending_window_change (0);
9648 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9649 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9654 /* Display a null-terminated echo area message M. If M is 0, clear
9655 out any existing message, and let the mini-buffer text show through.
9657 The buffer M must continue to exist until after the echo area gets
9658 cleared or some other message gets displayed there. Do not pass
9659 text that is stored in a Lisp string. Do not pass text in a buffer
9660 that was alloca'd. */
9663 message1 (const char *m
)
9665 message2 (m
, (m
? strlen (m
) : 0), 0);
9669 /* The non-logging counterpart of message1. */
9672 message1_nolog (const char *m
)
9674 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9677 /* Display a message M which contains a single %s
9678 which gets replaced with STRING. */
9681 message_with_string (const char *m
, Lisp_Object string
, int log
)
9683 CHECK_STRING (string
);
9689 if (noninteractive_need_newline
)
9690 putc ('\n', stderr
);
9691 noninteractive_need_newline
= 0;
9692 fprintf (stderr
, m
, SDATA (string
));
9693 if (!cursor_in_echo_area
)
9694 fprintf (stderr
, "\n");
9698 else if (INTERACTIVE
)
9700 /* The frame whose minibuffer we're going to display the message on.
9701 It may be larger than the selected frame, so we need
9702 to use its buffer, not the selected frame's buffer. */
9703 Lisp_Object mini_window
;
9704 struct frame
*f
, *sf
= SELECTED_FRAME ();
9706 /* Get the frame containing the minibuffer
9707 that the selected frame is using. */
9708 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9709 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9711 /* A null message buffer means that the frame hasn't really been
9712 initialized yet. Error messages get reported properly by
9713 cmd_error, so this must be just an informative message; toss it. */
9714 if (FRAME_MESSAGE_BUF (f
))
9716 Lisp_Object args
[2], msg
;
9717 struct gcpro gcpro1
, gcpro2
;
9719 args
[0] = build_string (m
);
9720 args
[1] = msg
= string
;
9721 GCPRO2 (args
[0], msg
);
9724 msg
= Fformat (2, args
);
9727 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9729 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9733 /* Print should start at the beginning of the message
9734 buffer next time. */
9735 message_buf_print
= 0;
9741 /* Dump an informative message to the minibuf. If M is 0, clear out
9742 any existing message, and let the mini-buffer text show through. */
9745 vmessage (const char *m
, va_list ap
)
9751 if (noninteractive_need_newline
)
9752 putc ('\n', stderr
);
9753 noninteractive_need_newline
= 0;
9754 vfprintf (stderr
, m
, ap
);
9755 if (cursor_in_echo_area
== 0)
9756 fprintf (stderr
, "\n");
9760 else if (INTERACTIVE
)
9762 /* The frame whose mini-buffer we're going to display the message
9763 on. It may be larger than the selected frame, so we need to
9764 use its buffer, not the selected frame's buffer. */
9765 Lisp_Object mini_window
;
9766 struct frame
*f
, *sf
= SELECTED_FRAME ();
9768 /* Get the frame containing the mini-buffer
9769 that the selected frame is using. */
9770 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9771 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9773 /* A null message buffer means that the frame hasn't really been
9774 initialized yet. Error messages get reported properly by
9775 cmd_error, so this must be just an informative message; toss
9777 if (FRAME_MESSAGE_BUF (f
))
9783 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9784 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9786 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9791 /* Print should start at the beginning of the message
9792 buffer next time. */
9793 message_buf_print
= 0;
9799 message (const char *m
, ...)
9809 /* The non-logging version of message. */
9812 message_nolog (const char *m
, ...)
9814 Lisp_Object old_log_max
;
9817 old_log_max
= Vmessage_log_max
;
9818 Vmessage_log_max
= Qnil
;
9820 Vmessage_log_max
= old_log_max
;
9826 /* Display the current message in the current mini-buffer. This is
9827 only called from error handlers in process.c, and is not time
9831 update_echo_area (void)
9833 if (!NILP (echo_area_buffer
[0]))
9836 string
= Fcurrent_message ();
9837 message3 (string
, SBYTES (string
),
9838 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9843 /* Make sure echo area buffers in `echo_buffers' are live.
9844 If they aren't, make new ones. */
9847 ensure_echo_area_buffers (void)
9851 for (i
= 0; i
< 2; ++i
)
9852 if (!BUFFERP (echo_buffer
[i
])
9853 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9856 Lisp_Object old_buffer
;
9859 old_buffer
= echo_buffer
[i
];
9860 sprintf (name
, " *Echo Area %d*", i
);
9861 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9862 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9863 /* to force word wrap in echo area -
9864 it was decided to postpone this*/
9865 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9867 for (j
= 0; j
< 2; ++j
)
9868 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9869 echo_area_buffer
[j
] = echo_buffer
[i
];
9874 /* Call FN with args A1..A4 with either the current or last displayed
9875 echo_area_buffer as current buffer.
9877 WHICH zero means use the current message buffer
9878 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9879 from echo_buffer[] and clear it.
9881 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9882 suitable buffer from echo_buffer[] and clear it.
9884 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9885 that the current message becomes the last displayed one, make
9886 choose a suitable buffer for echo_area_buffer[0], and clear it.
9888 Value is what FN returns. */
9891 with_echo_area_buffer (struct window
*w
, int which
,
9892 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9893 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9896 int this_one
, the_other
, clear_buffer_p
, rc
;
9897 ptrdiff_t count
= SPECPDL_INDEX ();
9899 /* If buffers aren't live, make new ones. */
9900 ensure_echo_area_buffers ();
9905 this_one
= 0, the_other
= 1;
9907 this_one
= 1, the_other
= 0;
9910 this_one
= 0, the_other
= 1;
9913 /* We need a fresh one in case the current echo buffer equals
9914 the one containing the last displayed echo area message. */
9915 if (!NILP (echo_area_buffer
[this_one
])
9916 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9917 echo_area_buffer
[this_one
] = Qnil
;
9920 /* Choose a suitable buffer from echo_buffer[] is we don't
9922 if (NILP (echo_area_buffer
[this_one
]))
9924 echo_area_buffer
[this_one
]
9925 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9926 ? echo_buffer
[the_other
]
9927 : echo_buffer
[this_one
]);
9931 buffer
= echo_area_buffer
[this_one
];
9933 /* Don't get confused by reusing the buffer used for echoing
9934 for a different purpose. */
9935 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9938 record_unwind_protect (unwind_with_echo_area_buffer
,
9939 with_echo_area_buffer_unwind_data (w
));
9941 /* Make the echo area buffer current. Note that for display
9942 purposes, it is not necessary that the displayed window's buffer
9943 == current_buffer, except for text property lookup. So, let's
9944 only set that buffer temporarily here without doing a full
9945 Fset_window_buffer. We must also change w->pointm, though,
9946 because otherwise an assertions in unshow_buffer fails, and Emacs
9948 set_buffer_internal_1 (XBUFFER (buffer
));
9952 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9955 BVAR (current_buffer
, undo_list
) = Qt
;
9956 BVAR (current_buffer
, read_only
) = Qnil
;
9957 specbind (Qinhibit_read_only
, Qt
);
9958 specbind (Qinhibit_modification_hooks
, Qt
);
9960 if (clear_buffer_p
&& Z
> BEG
)
9963 eassert (BEGV
>= BEG
);
9964 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9966 rc
= fn (a1
, a2
, a3
, a4
);
9968 eassert (BEGV
>= BEG
);
9969 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9971 unbind_to (count
, Qnil
);
9976 /* Save state that should be preserved around the call to the function
9977 FN called in with_echo_area_buffer. */
9980 with_echo_area_buffer_unwind_data (struct window
*w
)
9983 Lisp_Object vector
, tmp
;
9985 /* Reduce consing by keeping one vector in
9986 Vwith_echo_area_save_vector. */
9987 vector
= Vwith_echo_area_save_vector
;
9988 Vwith_echo_area_save_vector
= Qnil
;
9991 vector
= Fmake_vector (make_number (7), Qnil
);
9993 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9994 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9995 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9999 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10000 ASET (vector
, i
, w
->buffer
); ++i
;
10001 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
10002 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
10007 for (; i
< end
; ++i
)
10008 ASET (vector
, i
, Qnil
);
10011 eassert (i
== ASIZE (vector
));
10016 /* Restore global state from VECTOR which was created by
10017 with_echo_area_buffer_unwind_data. */
10020 unwind_with_echo_area_buffer (Lisp_Object vector
)
10022 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10023 Vdeactivate_mark
= AREF (vector
, 1);
10024 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10026 if (WINDOWP (AREF (vector
, 3)))
10029 Lisp_Object buffer
, charpos
, bytepos
;
10031 w
= XWINDOW (AREF (vector
, 3));
10032 buffer
= AREF (vector
, 4);
10033 charpos
= AREF (vector
, 5);
10034 bytepos
= AREF (vector
, 6);
10036 w
->buffer
= buffer
;
10037 set_marker_both (w
->pointm
, buffer
,
10038 XFASTINT (charpos
), XFASTINT (bytepos
));
10041 Vwith_echo_area_save_vector
= vector
;
10046 /* Set up the echo area for use by print functions. MULTIBYTE_P
10047 non-zero means we will print multibyte. */
10050 setup_echo_area_for_printing (int multibyte_p
)
10052 /* If we can't find an echo area any more, exit. */
10053 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10054 Fkill_emacs (Qnil
);
10056 ensure_echo_area_buffers ();
10058 if (!message_buf_print
)
10060 /* A message has been output since the last time we printed.
10061 Choose a fresh echo area buffer. */
10062 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10063 echo_area_buffer
[0] = echo_buffer
[1];
10065 echo_area_buffer
[0] = echo_buffer
[0];
10067 /* Switch to that buffer and clear it. */
10068 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10069 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10073 ptrdiff_t count
= SPECPDL_INDEX ();
10074 specbind (Qinhibit_read_only
, Qt
);
10075 /* Note that undo recording is always disabled. */
10076 del_range (BEG
, Z
);
10077 unbind_to (count
, Qnil
);
10079 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10081 /* Set up the buffer for the multibyteness we need. */
10083 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10084 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10086 /* Raise the frame containing the echo area. */
10087 if (minibuffer_auto_raise
)
10089 struct frame
*sf
= SELECTED_FRAME ();
10090 Lisp_Object mini_window
;
10091 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10092 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10095 message_log_maybe_newline ();
10096 message_buf_print
= 1;
10100 if (NILP (echo_area_buffer
[0]))
10102 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10103 echo_area_buffer
[0] = echo_buffer
[1];
10105 echo_area_buffer
[0] = echo_buffer
[0];
10108 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10110 /* Someone switched buffers between print requests. */
10111 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10112 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10118 /* Display an echo area message in window W. Value is non-zero if W's
10119 height is changed. If display_last_displayed_message_p is
10120 non-zero, display the message that was last displayed, otherwise
10121 display the current message. */
10124 display_echo_area (struct window
*w
)
10126 int i
, no_message_p
, window_height_changed_p
;
10128 /* Temporarily disable garbage collections while displaying the echo
10129 area. This is done because a GC can print a message itself.
10130 That message would modify the echo area buffer's contents while a
10131 redisplay of the buffer is going on, and seriously confuse
10133 ptrdiff_t count
= inhibit_garbage_collection ();
10135 /* If there is no message, we must call display_echo_area_1
10136 nevertheless because it resizes the window. But we will have to
10137 reset the echo_area_buffer in question to nil at the end because
10138 with_echo_area_buffer will sets it to an empty buffer. */
10139 i
= display_last_displayed_message_p
? 1 : 0;
10140 no_message_p
= NILP (echo_area_buffer
[i
]);
10142 window_height_changed_p
10143 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10144 display_echo_area_1
,
10145 (intptr_t) w
, Qnil
, 0, 0);
10148 echo_area_buffer
[i
] = Qnil
;
10150 unbind_to (count
, Qnil
);
10151 return window_height_changed_p
;
10155 /* Helper for display_echo_area. Display the current buffer which
10156 contains the current echo area message in window W, a mini-window,
10157 a pointer to which is passed in A1. A2..A4 are currently not used.
10158 Change the height of W so that all of the message is displayed.
10159 Value is non-zero if height of W was changed. */
10162 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10165 struct window
*w
= (struct window
*) i1
;
10166 Lisp_Object window
;
10167 struct text_pos start
;
10168 int window_height_changed_p
= 0;
10170 /* Do this before displaying, so that we have a large enough glyph
10171 matrix for the display. If we can't get enough space for the
10172 whole text, display the last N lines. That works by setting w->start. */
10173 window_height_changed_p
= resize_mini_window (w
, 0);
10175 /* Use the starting position chosen by resize_mini_window. */
10176 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10179 clear_glyph_matrix (w
->desired_matrix
);
10180 XSETWINDOW (window
, w
);
10181 try_window (window
, start
, 0);
10183 return window_height_changed_p
;
10187 /* Resize the echo area window to exactly the size needed for the
10188 currently displayed message, if there is one. If a mini-buffer
10189 is active, don't shrink it. */
10192 resize_echo_area_exactly (void)
10194 if (BUFFERP (echo_area_buffer
[0])
10195 && WINDOWP (echo_area_window
))
10197 struct window
*w
= XWINDOW (echo_area_window
);
10199 Lisp_Object resize_exactly
;
10201 if (minibuf_level
== 0)
10202 resize_exactly
= Qt
;
10204 resize_exactly
= Qnil
;
10206 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10207 (intptr_t) w
, resize_exactly
,
10211 ++windows_or_buffers_changed
;
10212 ++update_mode_lines
;
10213 redisplay_internal ();
10219 /* Callback function for with_echo_area_buffer, when used from
10220 resize_echo_area_exactly. A1 contains a pointer to the window to
10221 resize, EXACTLY non-nil means resize the mini-window exactly to the
10222 size of the text displayed. A3 and A4 are not used. Value is what
10223 resize_mini_window returns. */
10226 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10229 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10233 /* Resize mini-window W to fit the size of its contents. EXACT_P
10234 means size the window exactly to the size needed. Otherwise, it's
10235 only enlarged until W's buffer is empty.
10237 Set W->start to the right place to begin display. If the whole
10238 contents fit, start at the beginning. Otherwise, start so as
10239 to make the end of the contents appear. This is particularly
10240 important for y-or-n-p, but seems desirable generally.
10242 Value is non-zero if the window height has been changed. */
10245 resize_mini_window (struct window
*w
, int exact_p
)
10247 struct frame
*f
= XFRAME (w
->frame
);
10248 int window_height_changed_p
= 0;
10250 eassert (MINI_WINDOW_P (w
));
10252 /* By default, start display at the beginning. */
10253 set_marker_both (w
->start
, w
->buffer
,
10254 BUF_BEGV (XBUFFER (w
->buffer
)),
10255 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10257 /* Don't resize windows while redisplaying a window; it would
10258 confuse redisplay functions when the size of the window they are
10259 displaying changes from under them. Such a resizing can happen,
10260 for instance, when which-func prints a long message while
10261 we are running fontification-functions. We're running these
10262 functions with safe_call which binds inhibit-redisplay to t. */
10263 if (!NILP (Vinhibit_redisplay
))
10266 /* Nil means don't try to resize. */
10267 if (NILP (Vresize_mini_windows
)
10268 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10271 if (!FRAME_MINIBUF_ONLY_P (f
))
10274 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10275 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10277 EMACS_INT max_height
;
10278 int unit
= FRAME_LINE_HEIGHT (f
);
10279 struct text_pos start
;
10280 struct buffer
*old_current_buffer
= NULL
;
10282 if (current_buffer
!= XBUFFER (w
->buffer
))
10284 old_current_buffer
= current_buffer
;
10285 set_buffer_internal (XBUFFER (w
->buffer
));
10288 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10290 /* Compute the max. number of lines specified by the user. */
10291 if (FLOATP (Vmax_mini_window_height
))
10292 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10293 else if (INTEGERP (Vmax_mini_window_height
))
10294 max_height
= XINT (Vmax_mini_window_height
);
10296 max_height
= total_height
/ 4;
10298 /* Correct that max. height if it's bogus. */
10299 max_height
= max (1, max_height
);
10300 max_height
= min (total_height
, max_height
);
10302 /* Find out the height of the text in the window. */
10303 if (it
.line_wrap
== TRUNCATE
)
10308 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10309 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10310 height
= it
.current_y
+ last_height
;
10312 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10313 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10314 height
= (height
+ unit
- 1) / unit
;
10317 /* Compute a suitable window start. */
10318 if (height
> max_height
)
10320 height
= max_height
;
10321 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10322 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10323 start
= it
.current
.pos
;
10326 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10327 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10329 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10331 /* Let it grow only, until we display an empty message, in which
10332 case the window shrinks again. */
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
)
10341 && (exact_p
|| BEGV
== ZV
))
10343 int old_height
= WINDOW_TOTAL_LINES (w
);
10344 freeze_window_starts (f
, 0);
10345 shrink_mini_window (w
);
10346 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10351 /* Always resize to exact size needed. */
10352 if (height
> WINDOW_TOTAL_LINES (w
))
10354 int old_height
= WINDOW_TOTAL_LINES (w
);
10355 freeze_window_starts (f
, 1);
10356 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10357 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10359 else if (height
< WINDOW_TOTAL_LINES (w
))
10361 int old_height
= WINDOW_TOTAL_LINES (w
);
10362 freeze_window_starts (f
, 0);
10363 shrink_mini_window (w
);
10367 freeze_window_starts (f
, 1);
10368 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10371 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10375 if (old_current_buffer
)
10376 set_buffer_internal (old_current_buffer
);
10379 return window_height_changed_p
;
10383 /* Value is the current message, a string, or nil if there is no
10384 current message. */
10387 current_message (void)
10391 if (!BUFFERP (echo_area_buffer
[0]))
10395 with_echo_area_buffer (0, 0, current_message_1
,
10396 (intptr_t) &msg
, Qnil
, 0, 0);
10398 echo_area_buffer
[0] = Qnil
;
10406 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10409 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10412 *msg
= make_buffer_string (BEG
, Z
, 1);
10419 /* Push the current message on Vmessage_stack for later restoration
10420 by restore_message. Value is non-zero if the current message isn't
10421 empty. This is a relatively infrequent operation, so it's not
10422 worth optimizing. */
10425 push_message (void)
10428 msg
= current_message ();
10429 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10430 return STRINGP (msg
);
10434 /* Restore message display from the top of Vmessage_stack. */
10437 restore_message (void)
10441 eassert (CONSP (Vmessage_stack
));
10442 msg
= XCAR (Vmessage_stack
);
10444 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10446 message3_nolog (msg
, 0, 0);
10450 /* Handler for record_unwind_protect calling pop_message. */
10453 pop_message_unwind (Lisp_Object dummy
)
10459 /* Pop the top-most entry off Vmessage_stack. */
10464 eassert (CONSP (Vmessage_stack
));
10465 Vmessage_stack
= XCDR (Vmessage_stack
);
10469 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10470 exits. If the stack is not empty, we have a missing pop_message
10474 check_message_stack (void)
10476 if (!NILP (Vmessage_stack
))
10481 /* Truncate to NCHARS what will be displayed in the echo area the next
10482 time we display it---but don't redisplay it now. */
10485 truncate_echo_area (ptrdiff_t nchars
)
10488 echo_area_buffer
[0] = Qnil
;
10489 /* A null message buffer means that the frame hasn't really been
10490 initialized yet. Error messages get reported properly by
10491 cmd_error, so this must be just an informative message; toss it. */
10492 else if (!noninteractive
10494 && !NILP (echo_area_buffer
[0]))
10496 struct frame
*sf
= SELECTED_FRAME ();
10497 if (FRAME_MESSAGE_BUF (sf
))
10498 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10503 /* Helper function for truncate_echo_area. Truncate the current
10504 message to at most NCHARS characters. */
10507 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10509 if (BEG
+ nchars
< Z
)
10510 del_range (BEG
+ nchars
, Z
);
10512 echo_area_buffer
[0] = Qnil
;
10517 /* Set the current message to a substring of S or STRING.
10519 If STRING is a Lisp string, set the message to the first NBYTES
10520 bytes from STRING. NBYTES zero means use the whole string. If
10521 STRING is multibyte, the message will be displayed multibyte.
10523 If S is not null, set the message to the first LEN bytes of S. LEN
10524 zero means use the whole string. MULTIBYTE_P non-zero means S is
10525 multibyte. Display the message multibyte in that case.
10527 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10528 to t before calling set_message_1 (which calls insert).
10532 set_message (const char *s
, Lisp_Object string
,
10533 ptrdiff_t nbytes
, int multibyte_p
)
10535 message_enable_multibyte
10536 = ((s
&& multibyte_p
)
10537 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10539 with_echo_area_buffer (0, -1, set_message_1
,
10540 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10541 message_buf_print
= 0;
10542 help_echo_showing_p
= 0;
10546 /* Helper function for set_message. Arguments have the same meaning
10547 as there, with A1 corresponding to S and A2 corresponding to STRING
10548 This function is called with the echo area buffer being
10552 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10555 const char *s
= (const char *) i1
;
10556 const unsigned char *msg
= (const unsigned char *) s
;
10557 Lisp_Object string
= a2
;
10559 /* Change multibyteness of the echo buffer appropriately. */
10560 if (message_enable_multibyte
10561 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10562 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10564 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10565 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10566 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10568 /* Insert new message at BEG. */
10569 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10571 if (STRINGP (string
))
10576 nbytes
= SBYTES (string
);
10577 nchars
= string_byte_to_char (string
, nbytes
);
10579 /* This function takes care of single/multibyte conversion. We
10580 just have to ensure that the echo area buffer has the right
10581 setting of enable_multibyte_characters. */
10582 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10587 nbytes
= strlen (s
);
10589 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10591 /* Convert from multi-byte to single-byte. */
10596 /* Convert a multibyte string to single-byte. */
10597 for (i
= 0; i
< nbytes
; i
+= n
)
10599 c
= string_char_and_length (msg
+ i
, &n
);
10600 work
[0] = (ASCII_CHAR_P (c
)
10602 : multibyte_char_to_unibyte (c
));
10603 insert_1_both (work
, 1, 1, 1, 0, 0);
10606 else if (!multibyte_p
10607 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10609 /* Convert from single-byte to multi-byte. */
10612 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10614 /* Convert a single-byte string to multibyte. */
10615 for (i
= 0; i
< nbytes
; i
++)
10618 MAKE_CHAR_MULTIBYTE (c
);
10619 n
= CHAR_STRING (c
, str
);
10620 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10624 insert_1 (s
, nbytes
, 1, 0, 0);
10631 /* Clear messages. CURRENT_P non-zero means clear the current
10632 message. LAST_DISPLAYED_P non-zero means clear the message
10636 clear_message (int current_p
, int last_displayed_p
)
10640 echo_area_buffer
[0] = Qnil
;
10641 message_cleared_p
= 1;
10644 if (last_displayed_p
)
10645 echo_area_buffer
[1] = Qnil
;
10647 message_buf_print
= 0;
10650 /* Clear garbaged frames.
10652 This function is used where the old redisplay called
10653 redraw_garbaged_frames which in turn called redraw_frame which in
10654 turn called clear_frame. The call to clear_frame was a source of
10655 flickering. I believe a clear_frame is not necessary. It should
10656 suffice in the new redisplay to invalidate all current matrices,
10657 and ensure a complete redisplay of all windows. */
10660 clear_garbaged_frames (void)
10662 if (frame_garbaged
)
10664 Lisp_Object tail
, frame
;
10665 int changed_count
= 0;
10667 FOR_EACH_FRAME (tail
, frame
)
10669 struct frame
*f
= XFRAME (frame
);
10671 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10675 Fredraw_frame (frame
);
10676 f
->force_flush_display_p
= 1;
10678 clear_current_matrices (f
);
10685 frame_garbaged
= 0;
10687 ++windows_or_buffers_changed
;
10692 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10693 is non-zero update selected_frame. Value is non-zero if the
10694 mini-windows height has been changed. */
10697 echo_area_display (int update_frame_p
)
10699 Lisp_Object mini_window
;
10702 int window_height_changed_p
= 0;
10703 struct frame
*sf
= SELECTED_FRAME ();
10705 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10706 w
= XWINDOW (mini_window
);
10707 f
= XFRAME (WINDOW_FRAME (w
));
10709 /* Don't display if frame is invisible or not yet initialized. */
10710 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10713 #ifdef HAVE_WINDOW_SYSTEM
10714 /* When Emacs starts, selected_frame may be the initial terminal
10715 frame. If we let this through, a message would be displayed on
10717 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10719 #endif /* HAVE_WINDOW_SYSTEM */
10721 /* Redraw garbaged frames. */
10722 if (frame_garbaged
)
10723 clear_garbaged_frames ();
10725 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10727 echo_area_window
= mini_window
;
10728 window_height_changed_p
= display_echo_area (w
);
10729 w
->must_be_updated_p
= 1;
10731 /* Update the display, unless called from redisplay_internal.
10732 Also don't update the screen during redisplay itself. The
10733 update will happen at the end of redisplay, and an update
10734 here could cause confusion. */
10735 if (update_frame_p
&& !redisplaying_p
)
10739 /* If the display update has been interrupted by pending
10740 input, update mode lines in the frame. Due to the
10741 pending input, it might have been that redisplay hasn't
10742 been called, so that mode lines above the echo area are
10743 garbaged. This looks odd, so we prevent it here. */
10744 if (!display_completed
)
10745 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10747 if (window_height_changed_p
10748 /* Don't do this if Emacs is shutting down. Redisplay
10749 needs to run hooks. */
10750 && !NILP (Vrun_hooks
))
10752 /* Must update other windows. Likewise as in other
10753 cases, don't let this update be interrupted by
10755 ptrdiff_t count
= SPECPDL_INDEX ();
10756 specbind (Qredisplay_dont_pause
, Qt
);
10757 windows_or_buffers_changed
= 1;
10758 redisplay_internal ();
10759 unbind_to (count
, Qnil
);
10761 else if (FRAME_WINDOW_P (f
) && n
== 0)
10763 /* Window configuration is the same as before.
10764 Can do with a display update of the echo area,
10765 unless we displayed some mode lines. */
10766 update_single_window (w
, 1);
10767 FRAME_RIF (f
)->flush_display (f
);
10770 update_frame (f
, 1, 1);
10772 /* If cursor is in the echo area, make sure that the next
10773 redisplay displays the minibuffer, so that the cursor will
10774 be replaced with what the minibuffer wants. */
10775 if (cursor_in_echo_area
)
10776 ++windows_or_buffers_changed
;
10779 else if (!EQ (mini_window
, selected_window
))
10780 windows_or_buffers_changed
++;
10782 /* Last displayed message is now the current message. */
10783 echo_area_buffer
[1] = echo_area_buffer
[0];
10784 /* Inform read_char that we're not echoing. */
10785 echo_message_buffer
= Qnil
;
10787 /* Prevent redisplay optimization in redisplay_internal by resetting
10788 this_line_start_pos. This is done because the mini-buffer now
10789 displays the message instead of its buffer text. */
10790 if (EQ (mini_window
, selected_window
))
10791 CHARPOS (this_line_start_pos
) = 0;
10793 return window_height_changed_p
;
10798 /***********************************************************************
10799 Mode Lines and Frame Titles
10800 ***********************************************************************/
10802 /* A buffer for constructing non-propertized mode-line strings and
10803 frame titles in it; allocated from the heap in init_xdisp and
10804 resized as needed in store_mode_line_noprop_char. */
10806 static char *mode_line_noprop_buf
;
10808 /* The buffer's end, and a current output position in it. */
10810 static char *mode_line_noprop_buf_end
;
10811 static char *mode_line_noprop_ptr
;
10813 #define MODE_LINE_NOPROP_LEN(start) \
10814 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10817 MODE_LINE_DISPLAY
= 0,
10821 } mode_line_target
;
10823 /* Alist that caches the results of :propertize.
10824 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10825 static Lisp_Object mode_line_proptrans_alist
;
10827 /* List of strings making up the mode-line. */
10828 static Lisp_Object mode_line_string_list
;
10830 /* Base face property when building propertized mode line string. */
10831 static Lisp_Object mode_line_string_face
;
10832 static Lisp_Object mode_line_string_face_prop
;
10835 /* Unwind data for mode line strings */
10837 static Lisp_Object Vmode_line_unwind_vector
;
10840 format_mode_line_unwind_data (struct frame
*target_frame
,
10841 struct buffer
*obuf
,
10843 int save_proptrans
)
10845 Lisp_Object vector
, tmp
;
10847 /* Reduce consing by keeping one vector in
10848 Vwith_echo_area_save_vector. */
10849 vector
= Vmode_line_unwind_vector
;
10850 Vmode_line_unwind_vector
= Qnil
;
10853 vector
= Fmake_vector (make_number (10), Qnil
);
10855 ASET (vector
, 0, make_number (mode_line_target
));
10856 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10857 ASET (vector
, 2, mode_line_string_list
);
10858 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10859 ASET (vector
, 4, mode_line_string_face
);
10860 ASET (vector
, 5, mode_line_string_face_prop
);
10863 XSETBUFFER (tmp
, obuf
);
10866 ASET (vector
, 6, tmp
);
10867 ASET (vector
, 7, owin
);
10870 /* Similarly to `with-selected-window', if the operation selects
10871 a window on another frame, we must restore that frame's
10872 selected window, and (for a tty) the top-frame. */
10873 ASET (vector
, 8, target_frame
->selected_window
);
10874 if (FRAME_TERMCAP_P (target_frame
))
10875 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10882 unwind_format_mode_line (Lisp_Object vector
)
10884 Lisp_Object old_window
= AREF (vector
, 7);
10885 Lisp_Object target_frame_window
= AREF (vector
, 8);
10886 Lisp_Object old_top_frame
= AREF (vector
, 9);
10888 mode_line_target
= XINT (AREF (vector
, 0));
10889 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10890 mode_line_string_list
= AREF (vector
, 2);
10891 if (! EQ (AREF (vector
, 3), Qt
))
10892 mode_line_proptrans_alist
= AREF (vector
, 3);
10893 mode_line_string_face
= AREF (vector
, 4);
10894 mode_line_string_face_prop
= AREF (vector
, 5);
10896 /* Select window before buffer, since it may change the buffer. */
10897 if (!NILP (old_window
))
10899 /* If the operation that we are unwinding had selected a window
10900 on a different frame, reset its frame-selected-window. For a
10901 text terminal, reset its top-frame if necessary. */
10902 if (!NILP (target_frame_window
))
10905 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10907 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10908 Fselect_window (target_frame_window
, Qt
);
10910 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10911 Fselect_frame (old_top_frame
, Qt
);
10914 Fselect_window (old_window
, Qt
);
10917 if (!NILP (AREF (vector
, 6)))
10919 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10920 ASET (vector
, 6, Qnil
);
10923 Vmode_line_unwind_vector
= vector
;
10928 /* Store a single character C for the frame title in mode_line_noprop_buf.
10929 Re-allocate mode_line_noprop_buf if necessary. */
10932 store_mode_line_noprop_char (char c
)
10934 /* If output position has reached the end of the allocated buffer,
10935 increase the buffer's size. */
10936 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10938 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10939 ptrdiff_t size
= len
;
10940 mode_line_noprop_buf
=
10941 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10942 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10943 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10946 *mode_line_noprop_ptr
++ = c
;
10950 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10951 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10952 characters that yield more columns than PRECISION; PRECISION <= 0
10953 means copy the whole string. Pad with spaces until FIELD_WIDTH
10954 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10955 pad. Called from display_mode_element when it is used to build a
10959 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10961 const unsigned char *str
= (const unsigned char *) string
;
10963 ptrdiff_t dummy
, nbytes
;
10965 /* Copy at most PRECISION chars from STR. */
10966 nbytes
= strlen (string
);
10967 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10969 store_mode_line_noprop_char (*str
++);
10971 /* Fill up with spaces until FIELD_WIDTH reached. */
10972 while (field_width
> 0
10973 && n
< field_width
)
10975 store_mode_line_noprop_char (' ');
10982 /***********************************************************************
10984 ***********************************************************************/
10986 #ifdef HAVE_WINDOW_SYSTEM
10988 /* Set the title of FRAME, if it has changed. The title format is
10989 Vicon_title_format if FRAME is iconified, otherwise it is
10990 frame_title_format. */
10993 x_consider_frame_title (Lisp_Object frame
)
10995 struct frame
*f
= XFRAME (frame
);
10997 if (FRAME_WINDOW_P (f
)
10998 || FRAME_MINIBUF_ONLY_P (f
)
10999 || f
->explicit_name
)
11001 /* Do we have more than one visible frame on this X display? */
11004 ptrdiff_t title_start
;
11008 ptrdiff_t count
= SPECPDL_INDEX ();
11010 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
11012 Lisp_Object other_frame
= XCAR (tail
);
11013 struct frame
*tf
= XFRAME (other_frame
);
11016 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11017 && !FRAME_MINIBUF_ONLY_P (tf
)
11018 && !EQ (other_frame
, tip_frame
)
11019 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11023 /* Set global variable indicating that multiple frames exist. */
11024 multiple_frames
= CONSP (tail
);
11026 /* Switch to the buffer of selected window of the frame. Set up
11027 mode_line_target so that display_mode_element will output into
11028 mode_line_noprop_buf; then display the title. */
11029 record_unwind_protect (unwind_format_mode_line
,
11030 format_mode_line_unwind_data
11031 (f
, current_buffer
, selected_window
, 0));
11033 Fselect_window (f
->selected_window
, Qt
);
11034 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11035 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11037 mode_line_target
= MODE_LINE_TITLE
;
11038 title_start
= MODE_LINE_NOPROP_LEN (0);
11039 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11040 NULL
, DEFAULT_FACE_ID
);
11041 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11042 len
= MODE_LINE_NOPROP_LEN (title_start
);
11043 title
= mode_line_noprop_buf
+ title_start
;
11044 unbind_to (count
, Qnil
);
11046 /* Set the title only if it's changed. This avoids consing in
11047 the common case where it hasn't. (If it turns out that we've
11048 already wasted too much time by walking through the list with
11049 display_mode_element, then we might need to optimize at a
11050 higher level than this.) */
11051 if (! STRINGP (f
->name
)
11052 || SBYTES (f
->name
) != len
11053 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11054 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11058 #endif /* not HAVE_WINDOW_SYSTEM */
11061 /***********************************************************************
11063 ***********************************************************************/
11066 /* Prepare for redisplay by updating menu-bar item lists when
11067 appropriate. This can call eval. */
11070 prepare_menu_bars (void)
11073 struct gcpro gcpro1
, gcpro2
;
11075 Lisp_Object tooltip_frame
;
11077 #ifdef HAVE_WINDOW_SYSTEM
11078 tooltip_frame
= tip_frame
;
11080 tooltip_frame
= Qnil
;
11083 /* Update all frame titles based on their buffer names, etc. We do
11084 this before the menu bars so that the buffer-menu will show the
11085 up-to-date frame titles. */
11086 #ifdef HAVE_WINDOW_SYSTEM
11087 if (windows_or_buffers_changed
|| update_mode_lines
)
11089 Lisp_Object tail
, frame
;
11091 FOR_EACH_FRAME (tail
, frame
)
11093 f
= XFRAME (frame
);
11094 if (!EQ (frame
, tooltip_frame
)
11095 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11096 x_consider_frame_title (frame
);
11099 #endif /* HAVE_WINDOW_SYSTEM */
11101 /* Update the menu bar item lists, if appropriate. This has to be
11102 done before any actual redisplay or generation of display lines. */
11103 all_windows
= (update_mode_lines
11104 || buffer_shared
> 1
11105 || windows_or_buffers_changed
);
11108 Lisp_Object tail
, frame
;
11109 ptrdiff_t count
= SPECPDL_INDEX ();
11110 /* 1 means that update_menu_bar has run its hooks
11111 so any further calls to update_menu_bar shouldn't do so again. */
11112 int menu_bar_hooks_run
= 0;
11114 record_unwind_save_match_data ();
11116 FOR_EACH_FRAME (tail
, frame
)
11118 f
= XFRAME (frame
);
11120 /* Ignore tooltip frame. */
11121 if (EQ (frame
, tooltip_frame
))
11124 /* If a window on this frame changed size, report that to
11125 the user and clear the size-change flag. */
11126 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11128 Lisp_Object functions
;
11130 /* Clear flag first in case we get an error below. */
11131 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11132 functions
= Vwindow_size_change_functions
;
11133 GCPRO2 (tail
, functions
);
11135 while (CONSP (functions
))
11137 if (!EQ (XCAR (functions
), Qt
))
11138 call1 (XCAR (functions
), frame
);
11139 functions
= XCDR (functions
);
11145 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11146 #ifdef HAVE_WINDOW_SYSTEM
11147 update_tool_bar (f
, 0);
11150 if (windows_or_buffers_changed
11152 ns_set_doc_edited (f
, Fbuffer_modified_p
11153 (XWINDOW (f
->selected_window
)->buffer
));
11158 unbind_to (count
, Qnil
);
11162 struct frame
*sf
= SELECTED_FRAME ();
11163 update_menu_bar (sf
, 1, 0);
11164 #ifdef HAVE_WINDOW_SYSTEM
11165 update_tool_bar (sf
, 1);
11171 /* Update the menu bar item list for frame F. This has to be done
11172 before we start to fill in any display lines, because it can call
11175 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11177 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11178 already ran the menu bar hooks for this redisplay, so there
11179 is no need to run them again. The return value is the
11180 updated value of this flag, to pass to the next call. */
11183 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11185 Lisp_Object window
;
11186 register struct window
*w
;
11188 /* If called recursively during a menu update, do nothing. This can
11189 happen when, for instance, an activate-menubar-hook causes a
11191 if (inhibit_menubar_update
)
11194 window
= FRAME_SELECTED_WINDOW (f
);
11195 w
= XWINDOW (window
);
11197 if (FRAME_WINDOW_P (f
)
11199 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11200 || defined (HAVE_NS) || defined (USE_GTK)
11201 FRAME_EXTERNAL_MENU_BAR (f
)
11203 FRAME_MENU_BAR_LINES (f
) > 0
11205 : FRAME_MENU_BAR_LINES (f
) > 0)
11207 /* If the user has switched buffers or windows, we need to
11208 recompute to reflect the new bindings. But we'll
11209 recompute when update_mode_lines is set too; that means
11210 that people can use force-mode-line-update to request
11211 that the menu bar be recomputed. The adverse effect on
11212 the rest of the redisplay algorithm is about the same as
11213 windows_or_buffers_changed anyway. */
11214 if (windows_or_buffers_changed
11215 /* This used to test w->update_mode_line, but we believe
11216 there is no need to recompute the menu in that case. */
11217 || update_mode_lines
11218 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11219 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11220 != w
->last_had_star
)
11221 || ((!NILP (Vtransient_mark_mode
)
11222 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11223 != !NILP (w
->region_showing
)))
11225 struct buffer
*prev
= current_buffer
;
11226 ptrdiff_t count
= SPECPDL_INDEX ();
11228 specbind (Qinhibit_menubar_update
, Qt
);
11230 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11231 if (save_match_data
)
11232 record_unwind_save_match_data ();
11233 if (NILP (Voverriding_local_map_menu_flag
))
11235 specbind (Qoverriding_terminal_local_map
, Qnil
);
11236 specbind (Qoverriding_local_map
, Qnil
);
11241 /* Run the Lucid hook. */
11242 safe_run_hooks (Qactivate_menubar_hook
);
11244 /* If it has changed current-menubar from previous value,
11245 really recompute the menu-bar from the value. */
11246 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11247 call0 (Qrecompute_lucid_menubar
);
11249 safe_run_hooks (Qmenu_bar_update_hook
);
11254 XSETFRAME (Vmenu_updating_frame
, f
);
11255 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11257 /* Redisplay the menu bar in case we changed it. */
11258 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11259 || defined (HAVE_NS) || defined (USE_GTK)
11260 if (FRAME_WINDOW_P (f
))
11262 #if defined (HAVE_NS)
11263 /* All frames on Mac OS share the same menubar. So only
11264 the selected frame should be allowed to set it. */
11265 if (f
== SELECTED_FRAME ())
11267 set_frame_menubar (f
, 0, 0);
11270 /* On a terminal screen, the menu bar is an ordinary screen
11271 line, and this makes it get updated. */
11272 w
->update_mode_line
= 1;
11273 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11274 /* In the non-toolkit version, the menu bar is an ordinary screen
11275 line, and this makes it get updated. */
11276 w
->update_mode_line
= 1;
11277 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11279 unbind_to (count
, Qnil
);
11280 set_buffer_internal_1 (prev
);
11289 /***********************************************************************
11291 ***********************************************************************/
11293 #ifdef HAVE_WINDOW_SYSTEM
11296 Nominal cursor position -- where to draw output.
11297 HPOS and VPOS are window relative glyph matrix coordinates.
11298 X and Y are window relative pixel coordinates. */
11300 struct cursor_pos output_cursor
;
11304 Set the global variable output_cursor to CURSOR. All cursor
11305 positions are relative to updated_window. */
11308 set_output_cursor (struct cursor_pos
*cursor
)
11310 output_cursor
.hpos
= cursor
->hpos
;
11311 output_cursor
.vpos
= cursor
->vpos
;
11312 output_cursor
.x
= cursor
->x
;
11313 output_cursor
.y
= cursor
->y
;
11318 Set a nominal cursor position.
11320 HPOS and VPOS are column/row positions in a window glyph matrix. X
11321 and Y are window text area relative pixel positions.
11323 If this is done during an update, updated_window will contain the
11324 window that is being updated and the position is the future output
11325 cursor position for that window. If updated_window is null, use
11326 selected_window and display the cursor at the given position. */
11329 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11333 /* If updated_window is not set, work on selected_window. */
11334 if (updated_window
)
11335 w
= updated_window
;
11337 w
= XWINDOW (selected_window
);
11339 /* Set the output cursor. */
11340 output_cursor
.hpos
= hpos
;
11341 output_cursor
.vpos
= vpos
;
11342 output_cursor
.x
= x
;
11343 output_cursor
.y
= y
;
11345 /* If not called as part of an update, really display the cursor.
11346 This will also set the cursor position of W. */
11347 if (updated_window
== NULL
)
11350 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11351 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11352 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11357 #endif /* HAVE_WINDOW_SYSTEM */
11360 /***********************************************************************
11362 ***********************************************************************/
11364 #ifdef HAVE_WINDOW_SYSTEM
11366 /* Where the mouse was last time we reported a mouse event. */
11368 FRAME_PTR last_mouse_frame
;
11370 /* Tool-bar item index of the item on which a mouse button was pressed
11373 int last_tool_bar_item
;
11377 update_tool_bar_unwind (Lisp_Object frame
)
11379 selected_frame
= frame
;
11383 /* Update the tool-bar item list for frame F. This has to be done
11384 before we start to fill in any display lines. Called from
11385 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11386 and restore it here. */
11389 update_tool_bar (struct frame
*f
, int save_match_data
)
11391 #if defined (USE_GTK) || defined (HAVE_NS)
11392 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11394 int do_update
= WINDOWP (f
->tool_bar_window
)
11395 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11400 Lisp_Object window
;
11403 window
= FRAME_SELECTED_WINDOW (f
);
11404 w
= XWINDOW (window
);
11406 /* If the user has switched buffers or windows, we need to
11407 recompute to reflect the new bindings. But we'll
11408 recompute when update_mode_lines is set too; that means
11409 that people can use force-mode-line-update to request
11410 that the menu bar be recomputed. The adverse effect on
11411 the rest of the redisplay algorithm is about the same as
11412 windows_or_buffers_changed anyway. */
11413 if (windows_or_buffers_changed
11414 || w
->update_mode_line
11415 || update_mode_lines
11416 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11417 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11418 != w
->last_had_star
)
11419 || ((!NILP (Vtransient_mark_mode
)
11420 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11421 != !NILP (w
->region_showing
)))
11423 struct buffer
*prev
= current_buffer
;
11424 ptrdiff_t count
= SPECPDL_INDEX ();
11425 Lisp_Object frame
, new_tool_bar
;
11426 int new_n_tool_bar
;
11427 struct gcpro gcpro1
;
11429 /* Set current_buffer to the buffer of the selected
11430 window of the frame, so that we get the right local
11432 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11434 /* Save match data, if we must. */
11435 if (save_match_data
)
11436 record_unwind_save_match_data ();
11438 /* Make sure that we don't accidentally use bogus keymaps. */
11439 if (NILP (Voverriding_local_map_menu_flag
))
11441 specbind (Qoverriding_terminal_local_map
, Qnil
);
11442 specbind (Qoverriding_local_map
, Qnil
);
11445 GCPRO1 (new_tool_bar
);
11447 /* We must temporarily set the selected frame to this frame
11448 before calling tool_bar_items, because the calculation of
11449 the tool-bar keymap uses the selected frame (see
11450 `tool-bar-make-keymap' in tool-bar.el). */
11451 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11452 XSETFRAME (frame
, f
);
11453 selected_frame
= frame
;
11455 /* Build desired tool-bar items from keymaps. */
11456 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11459 /* Redisplay the tool-bar if we changed it. */
11460 if (new_n_tool_bar
!= f
->n_tool_bar_items
11461 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11463 /* Redisplay that happens asynchronously due to an expose event
11464 may access f->tool_bar_items. Make sure we update both
11465 variables within BLOCK_INPUT so no such event interrupts. */
11467 f
->tool_bar_items
= new_tool_bar
;
11468 f
->n_tool_bar_items
= new_n_tool_bar
;
11469 w
->update_mode_line
= 1;
11475 unbind_to (count
, Qnil
);
11476 set_buffer_internal_1 (prev
);
11482 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11483 F's desired tool-bar contents. F->tool_bar_items must have
11484 been set up previously by calling prepare_menu_bars. */
11487 build_desired_tool_bar_string (struct frame
*f
)
11489 int i
, size
, size_needed
;
11490 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11491 Lisp_Object image
, plist
, props
;
11493 image
= plist
= props
= Qnil
;
11494 GCPRO3 (image
, plist
, props
);
11496 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11497 Otherwise, make a new string. */
11499 /* The size of the string we might be able to reuse. */
11500 size
= (STRINGP (f
->desired_tool_bar_string
)
11501 ? SCHARS (f
->desired_tool_bar_string
)
11504 /* We need one space in the string for each image. */
11505 size_needed
= f
->n_tool_bar_items
;
11507 /* Reuse f->desired_tool_bar_string, if possible. */
11508 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11509 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11510 make_number (' '));
11513 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11514 Fremove_text_properties (make_number (0), make_number (size
),
11515 props
, f
->desired_tool_bar_string
);
11518 /* Put a `display' property on the string for the images to display,
11519 put a `menu_item' property on tool-bar items with a value that
11520 is the index of the item in F's tool-bar item vector. */
11521 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11523 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11525 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11526 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11527 int hmargin
, vmargin
, relief
, idx
, end
;
11529 /* If image is a vector, choose the image according to the
11531 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11532 if (VECTORP (image
))
11536 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11537 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11540 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11541 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11543 eassert (ASIZE (image
) >= idx
);
11544 image
= AREF (image
, idx
);
11549 /* Ignore invalid image specifications. */
11550 if (!valid_image_p (image
))
11553 /* Display the tool-bar button pressed, or depressed. */
11554 plist
= Fcopy_sequence (XCDR (image
));
11556 /* Compute margin and relief to draw. */
11557 relief
= (tool_bar_button_relief
>= 0
11558 ? tool_bar_button_relief
11559 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11560 hmargin
= vmargin
= relief
;
11562 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11563 INT_MAX
- max (hmargin
, vmargin
)))
11565 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11566 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11568 else if (CONSP (Vtool_bar_button_margin
))
11570 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11571 INT_MAX
- hmargin
))
11572 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11574 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11575 INT_MAX
- vmargin
))
11576 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11579 if (auto_raise_tool_bar_buttons_p
)
11581 /* Add a `:relief' property to the image spec if the item is
11585 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11592 /* If image is selected, display it pressed, i.e. with a
11593 negative relief. If it's not selected, display it with a
11595 plist
= Fplist_put (plist
, QCrelief
,
11597 ? make_number (-relief
)
11598 : make_number (relief
)));
11603 /* Put a margin around the image. */
11604 if (hmargin
|| vmargin
)
11606 if (hmargin
== vmargin
)
11607 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11609 plist
= Fplist_put (plist
, QCmargin
,
11610 Fcons (make_number (hmargin
),
11611 make_number (vmargin
)));
11614 /* If button is not enabled, and we don't have special images
11615 for the disabled state, make the image appear disabled by
11616 applying an appropriate algorithm to it. */
11617 if (!enabled_p
&& idx
< 0)
11618 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11620 /* Put a `display' text property on the string for the image to
11621 display. Put a `menu-item' property on the string that gives
11622 the start of this item's properties in the tool-bar items
11624 image
= Fcons (Qimage
, plist
);
11625 props
= list4 (Qdisplay
, image
,
11626 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11628 /* Let the last image hide all remaining spaces in the tool bar
11629 string. The string can be longer than needed when we reuse a
11630 previous string. */
11631 if (i
+ 1 == f
->n_tool_bar_items
)
11632 end
= SCHARS (f
->desired_tool_bar_string
);
11635 Fadd_text_properties (make_number (i
), make_number (end
),
11636 props
, f
->desired_tool_bar_string
);
11644 /* Display one line of the tool-bar of frame IT->f.
11646 HEIGHT specifies the desired height of the tool-bar line.
11647 If the actual height of the glyph row is less than HEIGHT, the
11648 row's height is increased to HEIGHT, and the icons are centered
11649 vertically in the new height.
11651 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11652 count a final empty row in case the tool-bar width exactly matches
11657 display_tool_bar_line (struct it
*it
, int height
)
11659 struct glyph_row
*row
= it
->glyph_row
;
11660 int max_x
= it
->last_visible_x
;
11661 struct glyph
*last
;
11663 prepare_desired_row (row
);
11664 row
->y
= it
->current_y
;
11666 /* Note that this isn't made use of if the face hasn't a box,
11667 so there's no need to check the face here. */
11668 it
->start_of_box_run_p
= 1;
11670 while (it
->current_x
< max_x
)
11672 int x
, n_glyphs_before
, i
, nglyphs
;
11673 struct it it_before
;
11675 /* Get the next display element. */
11676 if (!get_next_display_element (it
))
11678 /* Don't count empty row if we are counting needed tool-bar lines. */
11679 if (height
< 0 && !it
->hpos
)
11684 /* Produce glyphs. */
11685 n_glyphs_before
= row
->used
[TEXT_AREA
];
11688 PRODUCE_GLYPHS (it
);
11690 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11692 x
= it_before
.current_x
;
11693 while (i
< nglyphs
)
11695 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11697 if (x
+ glyph
->pixel_width
> max_x
)
11699 /* Glyph doesn't fit on line. Backtrack. */
11700 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11702 /* If this is the only glyph on this line, it will never fit on the
11703 tool-bar, so skip it. But ensure there is at least one glyph,
11704 so we don't accidentally disable the tool-bar. */
11705 if (n_glyphs_before
== 0
11706 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11712 x
+= glyph
->pixel_width
;
11716 /* Stop at line end. */
11717 if (ITERATOR_AT_END_OF_LINE_P (it
))
11720 set_iterator_to_next (it
, 1);
11725 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11727 /* Use default face for the border below the tool bar.
11729 FIXME: When auto-resize-tool-bars is grow-only, there is
11730 no additional border below the possibly empty tool-bar lines.
11731 So to make the extra empty lines look "normal", we have to
11732 use the tool-bar face for the border too. */
11733 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11734 it
->face_id
= DEFAULT_FACE_ID
;
11736 extend_face_to_end_of_line (it
);
11737 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11738 last
->right_box_line_p
= 1;
11739 if (last
== row
->glyphs
[TEXT_AREA
])
11740 last
->left_box_line_p
= 1;
11742 /* Make line the desired height and center it vertically. */
11743 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11745 /* Don't add more than one line height. */
11746 height
%= FRAME_LINE_HEIGHT (it
->f
);
11747 it
->max_ascent
+= height
/ 2;
11748 it
->max_descent
+= (height
+ 1) / 2;
11751 compute_line_metrics (it
);
11753 /* If line is empty, make it occupy the rest of the tool-bar. */
11754 if (!row
->displays_text_p
)
11756 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11757 row
->visible_height
= row
->height
;
11758 row
->ascent
= row
->phys_ascent
= 0;
11759 row
->extra_line_spacing
= 0;
11762 row
->full_width_p
= 1;
11763 row
->continued_p
= 0;
11764 row
->truncated_on_left_p
= 0;
11765 row
->truncated_on_right_p
= 0;
11767 it
->current_x
= it
->hpos
= 0;
11768 it
->current_y
+= row
->height
;
11774 /* Max tool-bar height. */
11776 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11777 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11779 /* Value is the number of screen lines needed to make all tool-bar
11780 items of frame F visible. The number of actual rows needed is
11781 returned in *N_ROWS if non-NULL. */
11784 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11786 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11788 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11789 the desired matrix, so use (unused) mode-line row as temporary row to
11790 avoid destroying the first tool-bar row. */
11791 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11793 /* Initialize an iterator for iteration over
11794 F->desired_tool_bar_string in the tool-bar window of frame F. */
11795 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11796 it
.first_visible_x
= 0;
11797 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11798 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11799 it
.paragraph_embedding
= L2R
;
11801 while (!ITERATOR_AT_END_P (&it
))
11803 clear_glyph_row (temp_row
);
11804 it
.glyph_row
= temp_row
;
11805 display_tool_bar_line (&it
, -1);
11807 clear_glyph_row (temp_row
);
11809 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11811 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11813 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11817 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11819 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11820 (Lisp_Object frame
)
11827 frame
= selected_frame
;
11829 CHECK_FRAME (frame
);
11830 f
= XFRAME (frame
);
11832 if (WINDOWP (f
->tool_bar_window
)
11833 && (w
= XWINDOW (f
->tool_bar_window
),
11834 WINDOW_TOTAL_LINES (w
) > 0))
11836 update_tool_bar (f
, 1);
11837 if (f
->n_tool_bar_items
)
11839 build_desired_tool_bar_string (f
);
11840 nlines
= tool_bar_lines_needed (f
, NULL
);
11844 return make_number (nlines
);
11848 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11849 height should be changed. */
11852 redisplay_tool_bar (struct frame
*f
)
11856 struct glyph_row
*row
;
11858 #if defined (USE_GTK) || defined (HAVE_NS)
11859 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11860 update_frame_tool_bar (f
);
11864 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11865 do anything. This means you must start with tool-bar-lines
11866 non-zero to get the auto-sizing effect. Or in other words, you
11867 can turn off tool-bars by specifying tool-bar-lines zero. */
11868 if (!WINDOWP (f
->tool_bar_window
)
11869 || (w
= XWINDOW (f
->tool_bar_window
),
11870 WINDOW_TOTAL_LINES (w
) == 0))
11873 /* Set up an iterator for the tool-bar window. */
11874 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11875 it
.first_visible_x
= 0;
11876 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11877 row
= it
.glyph_row
;
11879 /* Build a string that represents the contents of the tool-bar. */
11880 build_desired_tool_bar_string (f
);
11881 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11882 /* FIXME: This should be controlled by a user option. But it
11883 doesn't make sense to have an R2L tool bar if the menu bar cannot
11884 be drawn also R2L, and making the menu bar R2L is tricky due
11885 toolkit-specific code that implements it. If an R2L tool bar is
11886 ever supported, display_tool_bar_line should also be augmented to
11887 call unproduce_glyphs like display_line and display_string
11889 it
.paragraph_embedding
= L2R
;
11891 if (f
->n_tool_bar_rows
== 0)
11895 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11896 nlines
!= WINDOW_TOTAL_LINES (w
)))
11899 int old_height
= WINDOW_TOTAL_LINES (w
);
11901 XSETFRAME (frame
, f
);
11902 Fmodify_frame_parameters (frame
,
11903 Fcons (Fcons (Qtool_bar_lines
,
11904 make_number (nlines
)),
11906 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11908 clear_glyph_matrix (w
->desired_matrix
);
11909 fonts_changed_p
= 1;
11915 /* Display as many lines as needed to display all tool-bar items. */
11917 if (f
->n_tool_bar_rows
> 0)
11919 int border
, rows
, height
, extra
;
11921 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11922 border
= XINT (Vtool_bar_border
);
11923 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11924 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11925 else if (EQ (Vtool_bar_border
, Qborder_width
))
11926 border
= f
->border_width
;
11932 rows
= f
->n_tool_bar_rows
;
11933 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11934 extra
= it
.last_visible_y
- border
- height
* rows
;
11936 while (it
.current_y
< it
.last_visible_y
)
11939 if (extra
> 0 && rows
-- > 0)
11941 h
= (extra
+ rows
- 1) / rows
;
11944 display_tool_bar_line (&it
, height
+ h
);
11949 while (it
.current_y
< it
.last_visible_y
)
11950 display_tool_bar_line (&it
, 0);
11953 /* It doesn't make much sense to try scrolling in the tool-bar
11954 window, so don't do it. */
11955 w
->desired_matrix
->no_scrolling_p
= 1;
11956 w
->must_be_updated_p
= 1;
11958 if (!NILP (Vauto_resize_tool_bars
))
11960 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11961 int change_height_p
= 0;
11963 /* If we couldn't display everything, change the tool-bar's
11964 height if there is room for more. */
11965 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11966 && it
.current_y
< max_tool_bar_height
)
11967 change_height_p
= 1;
11969 row
= it
.glyph_row
- 1;
11971 /* If there are blank lines at the end, except for a partially
11972 visible blank line at the end that is smaller than
11973 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11974 if (!row
->displays_text_p
11975 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11976 change_height_p
= 1;
11978 /* If row displays tool-bar items, but is partially visible,
11979 change the tool-bar's height. */
11980 if (row
->displays_text_p
11981 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11982 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11983 change_height_p
= 1;
11985 /* Resize windows as needed by changing the `tool-bar-lines'
11986 frame parameter. */
11987 if (change_height_p
)
11990 int old_height
= WINDOW_TOTAL_LINES (w
);
11992 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11994 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11995 && !f
->minimize_tool_bar_window_p
)
11996 ? (nlines
> old_height
)
11997 : (nlines
!= old_height
));
11998 f
->minimize_tool_bar_window_p
= 0;
12000 if (change_height_p
)
12002 XSETFRAME (frame
, f
);
12003 Fmodify_frame_parameters (frame
,
12004 Fcons (Fcons (Qtool_bar_lines
,
12005 make_number (nlines
)),
12007 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12009 clear_glyph_matrix (w
->desired_matrix
);
12010 f
->n_tool_bar_rows
= nrows
;
12011 fonts_changed_p
= 1;
12018 f
->minimize_tool_bar_window_p
= 0;
12023 /* Get information about the tool-bar item which is displayed in GLYPH
12024 on frame F. Return in *PROP_IDX the index where tool-bar item
12025 properties start in F->tool_bar_items. Value is zero if
12026 GLYPH doesn't display a tool-bar item. */
12029 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12035 /* This function can be called asynchronously, which means we must
12036 exclude any possibility that Fget_text_property signals an
12038 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12039 charpos
= max (0, charpos
);
12041 /* Get the text property `menu-item' at pos. The value of that
12042 property is the start index of this item's properties in
12043 F->tool_bar_items. */
12044 prop
= Fget_text_property (make_number (charpos
),
12045 Qmenu_item
, f
->current_tool_bar_string
);
12046 if (INTEGERP (prop
))
12048 *prop_idx
= XINT (prop
);
12058 /* Get information about the tool-bar item at position X/Y on frame F.
12059 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12060 the current matrix of the tool-bar window of F, or NULL if not
12061 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12062 item in F->tool_bar_items. Value is
12064 -1 if X/Y is not on a tool-bar item
12065 0 if X/Y is on the same item that was highlighted before.
12069 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12070 int *hpos
, int *vpos
, int *prop_idx
)
12072 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12073 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12076 /* Find the glyph under X/Y. */
12077 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12078 if (*glyph
== NULL
)
12081 /* Get the start of this tool-bar item's properties in
12082 f->tool_bar_items. */
12083 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12086 /* Is mouse on the highlighted item? */
12087 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12088 && *vpos
>= hlinfo
->mouse_face_beg_row
12089 && *vpos
<= hlinfo
->mouse_face_end_row
12090 && (*vpos
> hlinfo
->mouse_face_beg_row
12091 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12092 && (*vpos
< hlinfo
->mouse_face_end_row
12093 || *hpos
< hlinfo
->mouse_face_end_col
12094 || hlinfo
->mouse_face_past_end
))
12102 Handle mouse button event on the tool-bar of frame F, at
12103 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12104 0 for button release. MODIFIERS is event modifiers for button
12108 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12111 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12112 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12113 int hpos
, vpos
, prop_idx
;
12114 struct glyph
*glyph
;
12115 Lisp_Object enabled_p
;
12117 /* If not on the highlighted tool-bar item, return. */
12118 frame_to_window_pixel_xy (w
, &x
, &y
);
12119 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12122 /* If item is disabled, do nothing. */
12123 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12124 if (NILP (enabled_p
))
12129 /* Show item in pressed state. */
12130 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12131 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12132 last_tool_bar_item
= prop_idx
;
12136 Lisp_Object key
, frame
;
12137 struct input_event event
;
12138 EVENT_INIT (event
);
12140 /* Show item in released state. */
12141 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12142 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12144 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12146 XSETFRAME (frame
, f
);
12147 event
.kind
= TOOL_BAR_EVENT
;
12148 event
.frame_or_window
= frame
;
12150 kbd_buffer_store_event (&event
);
12152 event
.kind
= TOOL_BAR_EVENT
;
12153 event
.frame_or_window
= frame
;
12155 event
.modifiers
= modifiers
;
12156 kbd_buffer_store_event (&event
);
12157 last_tool_bar_item
= -1;
12162 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12163 tool-bar window-relative coordinates X/Y. Called from
12164 note_mouse_highlight. */
12167 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12169 Lisp_Object window
= f
->tool_bar_window
;
12170 struct window
*w
= XWINDOW (window
);
12171 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12172 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12174 struct glyph
*glyph
;
12175 struct glyph_row
*row
;
12177 Lisp_Object enabled_p
;
12179 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12180 int mouse_down_p
, rc
;
12182 /* Function note_mouse_highlight is called with negative X/Y
12183 values when mouse moves outside of the frame. */
12184 if (x
<= 0 || y
<= 0)
12186 clear_mouse_face (hlinfo
);
12190 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12193 /* Not on tool-bar item. */
12194 clear_mouse_face (hlinfo
);
12198 /* On same tool-bar item as before. */
12199 goto set_help_echo
;
12201 clear_mouse_face (hlinfo
);
12203 /* Mouse is down, but on different tool-bar item? */
12204 mouse_down_p
= (dpyinfo
->grabbed
12205 && f
== last_mouse_frame
12206 && FRAME_LIVE_P (f
));
12208 && last_tool_bar_item
!= prop_idx
)
12211 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12212 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12214 /* If tool-bar item is not enabled, don't highlight it. */
12215 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12216 if (!NILP (enabled_p
))
12218 /* Compute the x-position of the glyph. In front and past the
12219 image is a space. We include this in the highlighted area. */
12220 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12221 for (i
= x
= 0; i
< hpos
; ++i
)
12222 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12224 /* Record this as the current active region. */
12225 hlinfo
->mouse_face_beg_col
= hpos
;
12226 hlinfo
->mouse_face_beg_row
= vpos
;
12227 hlinfo
->mouse_face_beg_x
= x
;
12228 hlinfo
->mouse_face_beg_y
= row
->y
;
12229 hlinfo
->mouse_face_past_end
= 0;
12231 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12232 hlinfo
->mouse_face_end_row
= vpos
;
12233 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12234 hlinfo
->mouse_face_end_y
= row
->y
;
12235 hlinfo
->mouse_face_window
= window
;
12236 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12238 /* Display it as active. */
12239 show_mouse_face (hlinfo
, draw
);
12240 hlinfo
->mouse_face_image_state
= draw
;
12245 /* Set help_echo_string to a help string to display for this tool-bar item.
12246 XTread_socket does the rest. */
12247 help_echo_object
= help_echo_window
= Qnil
;
12248 help_echo_pos
= -1;
12249 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12250 if (NILP (help_echo_string
))
12251 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12254 #endif /* HAVE_WINDOW_SYSTEM */
12258 /************************************************************************
12259 Horizontal scrolling
12260 ************************************************************************/
12262 static int hscroll_window_tree (Lisp_Object
);
12263 static int hscroll_windows (Lisp_Object
);
12265 /* For all leaf windows in the window tree rooted at WINDOW, set their
12266 hscroll value so that PT is (i) visible in the window, and (ii) so
12267 that it is not within a certain margin at the window's left and
12268 right border. Value is non-zero if any window's hscroll has been
12272 hscroll_window_tree (Lisp_Object window
)
12274 int hscrolled_p
= 0;
12275 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12276 int hscroll_step_abs
= 0;
12277 double hscroll_step_rel
= 0;
12279 if (hscroll_relative_p
)
12281 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12282 if (hscroll_step_rel
< 0)
12284 hscroll_relative_p
= 0;
12285 hscroll_step_abs
= 0;
12288 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12290 hscroll_step_abs
= XINT (Vhscroll_step
);
12291 if (hscroll_step_abs
< 0)
12292 hscroll_step_abs
= 0;
12295 hscroll_step_abs
= 0;
12297 while (WINDOWP (window
))
12299 struct window
*w
= XWINDOW (window
);
12301 if (WINDOWP (w
->hchild
))
12302 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12303 else if (WINDOWP (w
->vchild
))
12304 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12305 else if (w
->cursor
.vpos
>= 0)
12308 int text_area_width
;
12309 struct glyph_row
*current_cursor_row
12310 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12311 struct glyph_row
*desired_cursor_row
12312 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12313 struct glyph_row
*cursor_row
12314 = (desired_cursor_row
->enabled_p
12315 ? desired_cursor_row
12316 : current_cursor_row
);
12317 int row_r2l_p
= cursor_row
->reversed_p
;
12319 text_area_width
= window_box_width (w
, TEXT_AREA
);
12321 /* Scroll when cursor is inside this scroll margin. */
12322 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12324 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12325 /* For left-to-right rows, hscroll when cursor is either
12326 (i) inside the right hscroll margin, or (ii) if it is
12327 inside the left margin and the window is already
12331 && w
->cursor
.x
<= h_margin
)
12332 || (cursor_row
->enabled_p
12333 && cursor_row
->truncated_on_right_p
12334 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12335 /* For right-to-left rows, the logic is similar,
12336 except that rules for scrolling to left and right
12337 are reversed. E.g., if cursor.x <= h_margin, we
12338 need to hscroll "to the right" unconditionally,
12339 and that will scroll the screen to the left so as
12340 to reveal the next portion of the row. */
12342 && ((cursor_row
->enabled_p
12343 /* FIXME: It is confusing to set the
12344 truncated_on_right_p flag when R2L rows
12345 are actually truncated on the left. */
12346 && cursor_row
->truncated_on_right_p
12347 && w
->cursor
.x
<= h_margin
)
12349 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12353 struct buffer
*saved_current_buffer
;
12357 /* Find point in a display of infinite width. */
12358 saved_current_buffer
= current_buffer
;
12359 current_buffer
= XBUFFER (w
->buffer
);
12361 if (w
== XWINDOW (selected_window
))
12365 pt
= marker_position (w
->pointm
);
12366 pt
= max (BEGV
, pt
);
12370 /* Move iterator to pt starting at cursor_row->start in
12371 a line with infinite width. */
12372 init_to_row_start (&it
, w
, cursor_row
);
12373 it
.last_visible_x
= INFINITY
;
12374 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12375 current_buffer
= saved_current_buffer
;
12377 /* Position cursor in window. */
12378 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12379 hscroll
= max (0, (it
.current_x
12380 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12381 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12382 : (text_area_width
/ 2))))
12383 / FRAME_COLUMN_WIDTH (it
.f
);
12384 else if ((!row_r2l_p
12385 && w
->cursor
.x
>= text_area_width
- h_margin
)
12386 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12388 if (hscroll_relative_p
)
12389 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12392 wanted_x
= text_area_width
12393 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12396 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12400 if (hscroll_relative_p
)
12401 wanted_x
= text_area_width
* hscroll_step_rel
12404 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12407 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12409 hscroll
= max (hscroll
, w
->min_hscroll
);
12411 /* Don't prevent redisplay optimizations if hscroll
12412 hasn't changed, as it will unnecessarily slow down
12414 if (w
->hscroll
!= hscroll
)
12416 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12417 w
->hscroll
= hscroll
;
12426 /* Value is non-zero if hscroll of any leaf window has been changed. */
12427 return hscrolled_p
;
12431 /* Set hscroll so that cursor is visible and not inside horizontal
12432 scroll margins for all windows in the tree rooted at WINDOW. See
12433 also hscroll_window_tree above. Value is non-zero if any window's
12434 hscroll has been changed. If it has, desired matrices on the frame
12435 of WINDOW are cleared. */
12438 hscroll_windows (Lisp_Object window
)
12440 int hscrolled_p
= hscroll_window_tree (window
);
12442 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12443 return hscrolled_p
;
12448 /************************************************************************
12450 ************************************************************************/
12452 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12453 to a non-zero value. This is sometimes handy to have in a debugger
12458 /* First and last unchanged row for try_window_id. */
12460 static int debug_first_unchanged_at_end_vpos
;
12461 static int debug_last_unchanged_at_beg_vpos
;
12463 /* Delta vpos and y. */
12465 static int debug_dvpos
, debug_dy
;
12467 /* Delta in characters and bytes for try_window_id. */
12469 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12471 /* Values of window_end_pos and window_end_vpos at the end of
12474 static ptrdiff_t debug_end_vpos
;
12476 /* Append a string to W->desired_matrix->method. FMT is a printf
12477 format string. If trace_redisplay_p is non-zero also printf the
12478 resulting string to stderr. */
12480 static void debug_method_add (struct window
*, char const *, ...)
12481 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12484 debug_method_add (struct window
*w
, char const *fmt
, ...)
12487 char *method
= w
->desired_matrix
->method
;
12488 int len
= strlen (method
);
12489 int size
= sizeof w
->desired_matrix
->method
;
12490 int remaining
= size
- len
- 1;
12493 va_start (ap
, fmt
);
12494 vsprintf (buffer
, fmt
, ap
);
12496 if (len
&& remaining
)
12499 --remaining
, ++len
;
12502 strncpy (method
+ len
, buffer
, remaining
);
12504 if (trace_redisplay_p
)
12505 fprintf (stderr
, "%p (%s): %s\n",
12507 ((BUFFERP (w
->buffer
)
12508 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12509 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12514 #endif /* GLYPH_DEBUG */
12517 /* Value is non-zero if all changes in window W, which displays
12518 current_buffer, are in the text between START and END. START is a
12519 buffer position, END is given as a distance from Z. Used in
12520 redisplay_internal for display optimization. */
12523 text_outside_line_unchanged_p (struct window
*w
,
12524 ptrdiff_t start
, ptrdiff_t end
)
12526 int unchanged_p
= 1;
12528 /* If text or overlays have changed, see where. */
12529 if (w
->last_modified
< MODIFF
12530 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
12532 /* Gap in the line? */
12533 if (GPT
< start
|| Z
- GPT
< end
)
12536 /* Changes start in front of the line, or end after it? */
12538 && (BEG_UNCHANGED
< start
- 1
12539 || END_UNCHANGED
< end
))
12542 /* If selective display, can't optimize if changes start at the
12543 beginning of the line. */
12545 && INTEGERP (BVAR (current_buffer
, selective_display
))
12546 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12547 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12550 /* If there are overlays at the start or end of the line, these
12551 may have overlay strings with newlines in them. A change at
12552 START, for instance, may actually concern the display of such
12553 overlay strings as well, and they are displayed on different
12554 lines. So, quickly rule out this case. (For the future, it
12555 might be desirable to implement something more telling than
12556 just BEG/END_UNCHANGED.) */
12559 if (BEG
+ BEG_UNCHANGED
== start
12560 && overlay_touches_p (start
))
12562 if (END_UNCHANGED
== end
12563 && overlay_touches_p (Z
- end
))
12567 /* Under bidi reordering, adding or deleting a character in the
12568 beginning of a paragraph, before the first strong directional
12569 character, can change the base direction of the paragraph (unless
12570 the buffer specifies a fixed paragraph direction), which will
12571 require to redisplay the whole paragraph. It might be worthwhile
12572 to find the paragraph limits and widen the range of redisplayed
12573 lines to that, but for now just give up this optimization. */
12574 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12575 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12579 return unchanged_p
;
12583 /* Do a frame update, taking possible shortcuts into account. This is
12584 the main external entry point for redisplay.
12586 If the last redisplay displayed an echo area message and that message
12587 is no longer requested, we clear the echo area or bring back the
12588 mini-buffer if that is in use. */
12593 redisplay_internal ();
12598 overlay_arrow_string_or_property (Lisp_Object var
)
12602 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12605 return Voverlay_arrow_string
;
12608 /* Return 1 if there are any overlay-arrows in current_buffer. */
12610 overlay_arrow_in_current_buffer_p (void)
12614 for (vlist
= Voverlay_arrow_variable_list
;
12616 vlist
= XCDR (vlist
))
12618 Lisp_Object var
= XCAR (vlist
);
12621 if (!SYMBOLP (var
))
12623 val
= find_symbol_value (var
);
12625 && current_buffer
== XMARKER (val
)->buffer
)
12632 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12636 overlay_arrows_changed_p (void)
12640 for (vlist
= Voverlay_arrow_variable_list
;
12642 vlist
= XCDR (vlist
))
12644 Lisp_Object var
= XCAR (vlist
);
12645 Lisp_Object val
, pstr
;
12647 if (!SYMBOLP (var
))
12649 val
= find_symbol_value (var
);
12650 if (!MARKERP (val
))
12652 if (! EQ (COERCE_MARKER (val
),
12653 Fget (var
, Qlast_arrow_position
))
12654 || ! (pstr
= overlay_arrow_string_or_property (var
),
12655 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12661 /* Mark overlay arrows to be updated on next redisplay. */
12664 update_overlay_arrows (int up_to_date
)
12668 for (vlist
= Voverlay_arrow_variable_list
;
12670 vlist
= XCDR (vlist
))
12672 Lisp_Object var
= XCAR (vlist
);
12674 if (!SYMBOLP (var
))
12677 if (up_to_date
> 0)
12679 Lisp_Object val
= find_symbol_value (var
);
12680 Fput (var
, Qlast_arrow_position
,
12681 COERCE_MARKER (val
));
12682 Fput (var
, Qlast_arrow_string
,
12683 overlay_arrow_string_or_property (var
));
12685 else if (up_to_date
< 0
12686 || !NILP (Fget (var
, Qlast_arrow_position
)))
12688 Fput (var
, Qlast_arrow_position
, Qt
);
12689 Fput (var
, Qlast_arrow_string
, Qt
);
12695 /* Return overlay arrow string to display at row.
12696 Return integer (bitmap number) for arrow bitmap in left fringe.
12697 Return nil if no overlay arrow. */
12700 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12704 for (vlist
= Voverlay_arrow_variable_list
;
12706 vlist
= XCDR (vlist
))
12708 Lisp_Object var
= XCAR (vlist
);
12711 if (!SYMBOLP (var
))
12714 val
= find_symbol_value (var
);
12717 && current_buffer
== XMARKER (val
)->buffer
12718 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12720 if (FRAME_WINDOW_P (it
->f
)
12721 /* FIXME: if ROW->reversed_p is set, this should test
12722 the right fringe, not the left one. */
12723 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12725 #ifdef HAVE_WINDOW_SYSTEM
12726 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12729 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12730 return make_number (fringe_bitmap
);
12733 return make_number (-1); /* Use default arrow bitmap */
12735 return overlay_arrow_string_or_property (var
);
12742 /* Return 1 if point moved out of or into a composition. Otherwise
12743 return 0. PREV_BUF and PREV_PT are the last point buffer and
12744 position. BUF and PT are the current point buffer and position. */
12747 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12748 struct buffer
*buf
, ptrdiff_t pt
)
12750 ptrdiff_t start
, end
;
12752 Lisp_Object buffer
;
12754 XSETBUFFER (buffer
, buf
);
12755 /* Check a composition at the last point if point moved within the
12757 if (prev_buf
== buf
)
12760 /* Point didn't move. */
12763 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12764 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12765 && COMPOSITION_VALID_P (start
, end
, prop
)
12766 && start
< prev_pt
&& end
> prev_pt
)
12767 /* The last point was within the composition. Return 1 iff
12768 point moved out of the composition. */
12769 return (pt
<= start
|| pt
>= end
);
12772 /* Check a composition at the current point. */
12773 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12774 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12775 && COMPOSITION_VALID_P (start
, end
, prop
)
12776 && start
< pt
&& end
> pt
);
12780 /* Reconsider the setting of B->clip_changed which is displayed
12784 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12786 if (b
->clip_changed
12787 && !NILP (w
->window_end_valid
)
12788 && w
->current_matrix
->buffer
== b
12789 && w
->current_matrix
->zv
== BUF_ZV (b
)
12790 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12791 b
->clip_changed
= 0;
12793 /* If display wasn't paused, and W is not a tool bar window, see if
12794 point has been moved into or out of a composition. In that case,
12795 we set b->clip_changed to 1 to force updating the screen. If
12796 b->clip_changed has already been set to 1, we can skip this
12798 if (!b
->clip_changed
12799 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12803 if (w
== XWINDOW (selected_window
))
12806 pt
= marker_position (w
->pointm
);
12808 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12809 || pt
!= w
->last_point
)
12810 && check_point_in_composition (w
->current_matrix
->buffer
,
12812 XBUFFER (w
->buffer
), pt
))
12813 b
->clip_changed
= 1;
12818 /* Select FRAME to forward the values of frame-local variables into C
12819 variables so that the redisplay routines can access those values
12823 select_frame_for_redisplay (Lisp_Object frame
)
12825 Lisp_Object tail
, tem
;
12826 Lisp_Object old
= selected_frame
;
12827 struct Lisp_Symbol
*sym
;
12829 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12831 selected_frame
= frame
;
12834 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12835 if (CONSP (XCAR (tail
))
12836 && (tem
= XCAR (XCAR (tail
)),
12838 && (sym
= indirect_variable (XSYMBOL (tem
)),
12839 sym
->redirect
== SYMBOL_LOCALIZED
)
12840 && sym
->val
.blv
->frame_local
)
12841 /* Use find_symbol_value rather than Fsymbol_value
12842 to avoid an error if it is void. */
12843 find_symbol_value (tem
);
12844 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12848 #define STOP_POLLING \
12849 do { if (! polling_stopped_here) stop_polling (); \
12850 polling_stopped_here = 1; } while (0)
12852 #define RESUME_POLLING \
12853 do { if (polling_stopped_here) start_polling (); \
12854 polling_stopped_here = 0; } while (0)
12857 /* Perhaps in the future avoid recentering windows if it
12858 is not necessary; currently that causes some problems. */
12861 redisplay_internal (void)
12863 struct window
*w
= XWINDOW (selected_window
);
12867 int must_finish
= 0;
12868 struct text_pos tlbufpos
, tlendpos
;
12869 int number_of_visible_frames
;
12870 ptrdiff_t count
, count1
;
12872 int polling_stopped_here
= 0;
12873 Lisp_Object old_frame
= selected_frame
;
12875 /* Non-zero means redisplay has to consider all windows on all
12876 frames. Zero means, only selected_window is considered. */
12877 int consider_all_windows_p
;
12879 /* Non-zero means redisplay has to redisplay the miniwindow */
12880 int update_miniwindow_p
= 0;
12882 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12884 /* No redisplay if running in batch mode or frame is not yet fully
12885 initialized, or redisplay is explicitly turned off by setting
12886 Vinhibit_redisplay. */
12887 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12888 || !NILP (Vinhibit_redisplay
))
12891 /* Don't examine these until after testing Vinhibit_redisplay.
12892 When Emacs is shutting down, perhaps because its connection to
12893 X has dropped, we should not look at them at all. */
12894 fr
= XFRAME (w
->frame
);
12895 sf
= SELECTED_FRAME ();
12897 if (!fr
->glyphs_initialized_p
)
12900 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12901 if (popup_activated ())
12905 /* I don't think this happens but let's be paranoid. */
12906 if (redisplaying_p
)
12909 /* Record a function that resets redisplaying_p to its old value
12910 when we leave this function. */
12911 count
= SPECPDL_INDEX ();
12912 record_unwind_protect (unwind_redisplay
,
12913 Fcons (make_number (redisplaying_p
), selected_frame
));
12915 specbind (Qinhibit_free_realized_faces
, Qnil
);
12918 Lisp_Object tail
, frame
;
12920 FOR_EACH_FRAME (tail
, frame
)
12922 struct frame
*f
= XFRAME (frame
);
12923 f
->already_hscrolled_p
= 0;
12928 /* Remember the currently selected window. */
12931 if (!EQ (old_frame
, selected_frame
)
12932 && FRAME_LIVE_P (XFRAME (old_frame
)))
12933 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12934 selected_frame and selected_window to be temporarily out-of-sync so
12935 when we come back here via `goto retry', we need to resync because we
12936 may need to run Elisp code (via prepare_menu_bars). */
12937 select_frame_for_redisplay (old_frame
);
12940 reconsider_clip_changes (w
, current_buffer
);
12941 last_escape_glyph_frame
= NULL
;
12942 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12943 last_glyphless_glyph_frame
= NULL
;
12944 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12946 /* If new fonts have been loaded that make a glyph matrix adjustment
12947 necessary, do it. */
12948 if (fonts_changed_p
)
12950 adjust_glyphs (NULL
);
12951 ++windows_or_buffers_changed
;
12952 fonts_changed_p
= 0;
12955 /* If face_change_count is non-zero, init_iterator will free all
12956 realized faces, which includes the faces referenced from current
12957 matrices. So, we can't reuse current matrices in this case. */
12958 if (face_change_count
)
12959 ++windows_or_buffers_changed
;
12961 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12962 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12964 /* Since frames on a single ASCII terminal share the same
12965 display area, displaying a different frame means redisplay
12966 the whole thing. */
12967 windows_or_buffers_changed
++;
12968 SET_FRAME_GARBAGED (sf
);
12970 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12972 FRAME_TTY (sf
)->previous_frame
= sf
;
12975 /* Set the visible flags for all frames. Do this before checking
12976 for resized or garbaged frames; they want to know if their frames
12977 are visible. See the comment in frame.h for
12978 FRAME_SAMPLE_VISIBILITY. */
12980 Lisp_Object tail
, frame
;
12982 number_of_visible_frames
= 0;
12984 FOR_EACH_FRAME (tail
, frame
)
12986 struct frame
*f
= XFRAME (frame
);
12988 FRAME_SAMPLE_VISIBILITY (f
);
12989 if (FRAME_VISIBLE_P (f
))
12990 ++number_of_visible_frames
;
12991 clear_desired_matrices (f
);
12995 /* Notice any pending interrupt request to change frame size. */
12996 do_pending_window_change (1);
12998 /* do_pending_window_change could change the selected_window due to
12999 frame resizing which makes the selected window too small. */
13000 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13003 reconsider_clip_changes (w
, current_buffer
);
13006 /* Clear frames marked as garbaged. */
13007 if (frame_garbaged
)
13008 clear_garbaged_frames ();
13010 /* Build menubar and tool-bar items. */
13011 if (NILP (Vmemory_full
))
13012 prepare_menu_bars ();
13014 if (windows_or_buffers_changed
)
13015 update_mode_lines
++;
13017 /* Detect case that we need to write or remove a star in the mode line. */
13018 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13020 w
->update_mode_line
= 1;
13021 if (buffer_shared
> 1)
13022 update_mode_lines
++;
13025 /* Avoid invocation of point motion hooks by `current_column' below. */
13026 count1
= SPECPDL_INDEX ();
13027 specbind (Qinhibit_point_motion_hooks
, Qt
);
13029 /* If %c is in the mode line, update it if needed. */
13030 if (!NILP (w
->column_number_displayed
)
13031 /* This alternative quickly identifies a common case
13032 where no change is needed. */
13033 && !(PT
== w
->last_point
13034 && w
->last_modified
>= MODIFF
13035 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
13036 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13037 w
->update_mode_line
= 1;
13039 unbind_to (count1
, Qnil
);
13041 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13043 /* The variable buffer_shared is set in redisplay_window and
13044 indicates that we redisplay a buffer in different windows. See
13046 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
13047 || cursor_type_changed
);
13049 /* If specs for an arrow have changed, do thorough redisplay
13050 to ensure we remove any arrow that should no longer exist. */
13051 if (overlay_arrows_changed_p ())
13052 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13054 /* Normally the message* functions will have already displayed and
13055 updated the echo area, but the frame may have been trashed, or
13056 the update may have been preempted, so display the echo area
13057 again here. Checking message_cleared_p captures the case that
13058 the echo area should be cleared. */
13059 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13060 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13061 || (message_cleared_p
13062 && minibuf_level
== 0
13063 /* If the mini-window is currently selected, this means the
13064 echo-area doesn't show through. */
13065 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13067 int window_height_changed_p
= echo_area_display (0);
13069 if (message_cleared_p
)
13070 update_miniwindow_p
= 1;
13074 /* If we don't display the current message, don't clear the
13075 message_cleared_p flag, because, if we did, we wouldn't clear
13076 the echo area in the next redisplay which doesn't preserve
13078 if (!display_last_displayed_message_p
)
13079 message_cleared_p
= 0;
13081 if (fonts_changed_p
)
13083 else if (window_height_changed_p
)
13085 consider_all_windows_p
= 1;
13086 ++update_mode_lines
;
13087 ++windows_or_buffers_changed
;
13089 /* If window configuration was changed, frames may have been
13090 marked garbaged. Clear them or we will experience
13091 surprises wrt scrolling. */
13092 if (frame_garbaged
)
13093 clear_garbaged_frames ();
13096 else if (EQ (selected_window
, minibuf_window
)
13097 && (current_buffer
->clip_changed
13098 || w
->last_modified
< MODIFF
13099 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
13100 && resize_mini_window (w
, 0))
13102 /* Resized active mini-window to fit the size of what it is
13103 showing if its contents might have changed. */
13105 /* FIXME: this causes all frames to be updated, which seems unnecessary
13106 since only the current frame needs to be considered. This function needs
13107 to be rewritten with two variables, consider_all_windows and
13108 consider_all_frames. */
13109 consider_all_windows_p
= 1;
13110 ++windows_or_buffers_changed
;
13111 ++update_mode_lines
;
13113 /* If window configuration was changed, frames may have been
13114 marked garbaged. Clear them or we will experience
13115 surprises wrt scrolling. */
13116 if (frame_garbaged
)
13117 clear_garbaged_frames ();
13121 /* If showing the region, and mark has changed, we must redisplay
13122 the whole window. The assignment to this_line_start_pos prevents
13123 the optimization directly below this if-statement. */
13124 if (((!NILP (Vtransient_mark_mode
)
13125 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13126 != !NILP (w
->region_showing
))
13127 || (!NILP (w
->region_showing
)
13128 && !EQ (w
->region_showing
,
13129 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13130 CHARPOS (this_line_start_pos
) = 0;
13132 /* Optimize the case that only the line containing the cursor in the
13133 selected window has changed. Variables starting with this_ are
13134 set in display_line and record information about the line
13135 containing the cursor. */
13136 tlbufpos
= this_line_start_pos
;
13137 tlendpos
= this_line_end_pos
;
13138 if (!consider_all_windows_p
13139 && CHARPOS (tlbufpos
) > 0
13140 && !w
->update_mode_line
13141 && !current_buffer
->clip_changed
13142 && !current_buffer
->prevent_redisplay_optimizations_p
13143 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13144 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13145 /* Make sure recorded data applies to current buffer, etc. */
13146 && this_line_buffer
== current_buffer
13147 && current_buffer
== XBUFFER (w
->buffer
)
13149 && !w
->optional_new_start
13150 /* Point must be on the line that we have info recorded about. */
13151 && PT
>= CHARPOS (tlbufpos
)
13152 && PT
<= Z
- CHARPOS (tlendpos
)
13153 /* All text outside that line, including its final newline,
13154 must be unchanged. */
13155 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13156 CHARPOS (tlendpos
)))
13158 if (CHARPOS (tlbufpos
) > BEGV
13159 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13160 && (CHARPOS (tlbufpos
) == ZV
13161 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13162 /* Former continuation line has disappeared by becoming empty. */
13164 else if (w
->last_modified
< MODIFF
13165 || w
->last_overlay_modified
< OVERLAY_MODIFF
13166 || MINI_WINDOW_P (w
))
13168 /* We have to handle the case of continuation around a
13169 wide-column character (see the comment in indent.c around
13172 For instance, in the following case:
13174 -------- Insert --------
13175 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13176 J_I_ ==> J_I_ `^^' are cursors.
13180 As we have to redraw the line above, we cannot use this
13184 int line_height_before
= this_line_pixel_height
;
13186 /* Note that start_display will handle the case that the
13187 line starting at tlbufpos is a continuation line. */
13188 start_display (&it
, w
, tlbufpos
);
13190 /* Implementation note: It this still necessary? */
13191 if (it
.current_x
!= this_line_start_x
)
13194 TRACE ((stderr
, "trying display optimization 1\n"));
13195 w
->cursor
.vpos
= -1;
13196 overlay_arrow_seen
= 0;
13197 it
.vpos
= this_line_vpos
;
13198 it
.current_y
= this_line_y
;
13199 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13200 display_line (&it
);
13202 /* If line contains point, is not continued,
13203 and ends at same distance from eob as before, we win. */
13204 if (w
->cursor
.vpos
>= 0
13205 /* Line is not continued, otherwise this_line_start_pos
13206 would have been set to 0 in display_line. */
13207 && CHARPOS (this_line_start_pos
)
13208 /* Line ends as before. */
13209 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13210 /* Line has same height as before. Otherwise other lines
13211 would have to be shifted up or down. */
13212 && this_line_pixel_height
== line_height_before
)
13214 /* If this is not the window's last line, we must adjust
13215 the charstarts of the lines below. */
13216 if (it
.current_y
< it
.last_visible_y
)
13218 struct glyph_row
*row
13219 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13220 ptrdiff_t delta
, delta_bytes
;
13222 /* We used to distinguish between two cases here,
13223 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13224 when the line ends in a newline or the end of the
13225 buffer's accessible portion. But both cases did
13226 the same, so they were collapsed. */
13228 - CHARPOS (tlendpos
)
13229 - MATRIX_ROW_START_CHARPOS (row
));
13230 delta_bytes
= (Z_BYTE
13231 - BYTEPOS (tlendpos
)
13232 - MATRIX_ROW_START_BYTEPOS (row
));
13234 increment_matrix_positions (w
->current_matrix
,
13235 this_line_vpos
+ 1,
13236 w
->current_matrix
->nrows
,
13237 delta
, delta_bytes
);
13240 /* If this row displays text now but previously didn't,
13241 or vice versa, w->window_end_vpos may have to be
13243 if ((it
.glyph_row
- 1)->displays_text_p
)
13245 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13246 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13248 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13249 && this_line_vpos
> 0)
13250 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13251 w
->window_end_valid
= Qnil
;
13253 /* Update hint: No need to try to scroll in update_window. */
13254 w
->desired_matrix
->no_scrolling_p
= 1;
13257 *w
->desired_matrix
->method
= 0;
13258 debug_method_add (w
, "optimization 1");
13260 #ifdef HAVE_WINDOW_SYSTEM
13261 update_window_fringes (w
, 0);
13268 else if (/* Cursor position hasn't changed. */
13269 PT
== w
->last_point
13270 /* Make sure the cursor was last displayed
13271 in this window. Otherwise we have to reposition it. */
13272 && 0 <= w
->cursor
.vpos
13273 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13277 do_pending_window_change (1);
13278 /* If selected_window changed, redisplay again. */
13279 if (WINDOWP (selected_window
)
13280 && (w
= XWINDOW (selected_window
)) != sw
)
13283 /* We used to always goto end_of_redisplay here, but this
13284 isn't enough if we have a blinking cursor. */
13285 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13286 goto end_of_redisplay
;
13290 /* If highlighting the region, or if the cursor is in the echo area,
13291 then we can't just move the cursor. */
13292 else if (! (!NILP (Vtransient_mark_mode
)
13293 && !NILP (BVAR (current_buffer
, mark_active
)))
13294 && (EQ (selected_window
,
13295 BVAR (current_buffer
, last_selected_window
))
13296 || highlight_nonselected_windows
)
13297 && NILP (w
->region_showing
)
13298 && NILP (Vshow_trailing_whitespace
)
13299 && !cursor_in_echo_area
)
13302 struct glyph_row
*row
;
13304 /* Skip from tlbufpos to PT and see where it is. Note that
13305 PT may be in invisible text. If so, we will end at the
13306 next visible position. */
13307 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13308 NULL
, DEFAULT_FACE_ID
);
13309 it
.current_x
= this_line_start_x
;
13310 it
.current_y
= this_line_y
;
13311 it
.vpos
= this_line_vpos
;
13313 /* The call to move_it_to stops in front of PT, but
13314 moves over before-strings. */
13315 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13317 if (it
.vpos
== this_line_vpos
13318 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13321 eassert (this_line_vpos
== it
.vpos
);
13322 eassert (this_line_y
== it
.current_y
);
13323 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13325 *w
->desired_matrix
->method
= 0;
13326 debug_method_add (w
, "optimization 3");
13335 /* Text changed drastically or point moved off of line. */
13336 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13339 CHARPOS (this_line_start_pos
) = 0;
13340 consider_all_windows_p
|= buffer_shared
> 1;
13341 ++clear_face_cache_count
;
13342 #ifdef HAVE_WINDOW_SYSTEM
13343 ++clear_image_cache_count
;
13346 /* Build desired matrices, and update the display. If
13347 consider_all_windows_p is non-zero, do it for all windows on all
13348 frames. Otherwise do it for selected_window, only. */
13350 if (consider_all_windows_p
)
13352 Lisp_Object tail
, frame
;
13354 FOR_EACH_FRAME (tail
, frame
)
13355 XFRAME (frame
)->updated_p
= 0;
13357 /* Recompute # windows showing selected buffer. This will be
13358 incremented each time such a window is displayed. */
13361 FOR_EACH_FRAME (tail
, frame
)
13363 struct frame
*f
= XFRAME (frame
);
13365 /* We don't have to do anything for unselected terminal
13367 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13368 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13371 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13373 if (! EQ (frame
, selected_frame
))
13374 /* Select the frame, for the sake of frame-local
13376 select_frame_for_redisplay (frame
);
13378 /* Mark all the scroll bars to be removed; we'll redeem
13379 the ones we want when we redisplay their windows. */
13380 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13381 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13383 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13384 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13386 /* The X error handler may have deleted that frame. */
13387 if (!FRAME_LIVE_P (f
))
13390 /* Any scroll bars which redisplay_windows should have
13391 nuked should now go away. */
13392 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13393 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13395 /* If fonts changed, display again. */
13396 /* ??? rms: I suspect it is a mistake to jump all the way
13397 back to retry here. It should just retry this frame. */
13398 if (fonts_changed_p
)
13401 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13403 /* See if we have to hscroll. */
13404 if (!f
->already_hscrolled_p
)
13406 f
->already_hscrolled_p
= 1;
13407 if (hscroll_windows (f
->root_window
))
13411 /* Prevent various kinds of signals during display
13412 update. stdio is not robust about handling
13413 signals, which can cause an apparent I/O
13415 if (interrupt_input
)
13416 unrequest_sigio ();
13419 /* Update the display. */
13420 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13421 pending
|= update_frame (f
, 0, 0);
13427 if (!EQ (old_frame
, selected_frame
)
13428 && FRAME_LIVE_P (XFRAME (old_frame
)))
13429 /* We played a bit fast-and-loose above and allowed selected_frame
13430 and selected_window to be temporarily out-of-sync but let's make
13431 sure this stays contained. */
13432 select_frame_for_redisplay (old_frame
);
13433 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13437 /* Do the mark_window_display_accurate after all windows have
13438 been redisplayed because this call resets flags in buffers
13439 which are needed for proper redisplay. */
13440 FOR_EACH_FRAME (tail
, frame
)
13442 struct frame
*f
= XFRAME (frame
);
13445 mark_window_display_accurate (f
->root_window
, 1);
13446 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13447 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13452 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13454 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13455 struct frame
*mini_frame
;
13457 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13458 /* Use list_of_error, not Qerror, so that
13459 we catch only errors and don't run the debugger. */
13460 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13462 redisplay_window_error
);
13463 if (update_miniwindow_p
)
13464 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13466 redisplay_window_error
);
13468 /* Compare desired and current matrices, perform output. */
13471 /* If fonts changed, display again. */
13472 if (fonts_changed_p
)
13475 /* Prevent various kinds of signals during display update.
13476 stdio is not robust about handling signals,
13477 which can cause an apparent I/O error. */
13478 if (interrupt_input
)
13479 unrequest_sigio ();
13482 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13484 if (hscroll_windows (selected_window
))
13487 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13488 pending
= update_frame (sf
, 0, 0);
13491 /* We may have called echo_area_display at the top of this
13492 function. If the echo area is on another frame, that may
13493 have put text on a frame other than the selected one, so the
13494 above call to update_frame would not have caught it. Catch
13496 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13497 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13499 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13501 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13502 pending
|= update_frame (mini_frame
, 0, 0);
13503 if (!pending
&& hscroll_windows (mini_window
))
13508 /* If display was paused because of pending input, make sure we do a
13509 thorough update the next time. */
13512 /* Prevent the optimization at the beginning of
13513 redisplay_internal that tries a single-line update of the
13514 line containing the cursor in the selected window. */
13515 CHARPOS (this_line_start_pos
) = 0;
13517 /* Let the overlay arrow be updated the next time. */
13518 update_overlay_arrows (0);
13520 /* If we pause after scrolling, some rows in the current
13521 matrices of some windows are not valid. */
13522 if (!WINDOW_FULL_WIDTH_P (w
)
13523 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13524 update_mode_lines
= 1;
13528 if (!consider_all_windows_p
)
13530 /* This has already been done above if
13531 consider_all_windows_p is set. */
13532 mark_window_display_accurate_1 (w
, 1);
13534 /* Say overlay arrows are up to date. */
13535 update_overlay_arrows (1);
13537 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13538 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13541 update_mode_lines
= 0;
13542 windows_or_buffers_changed
= 0;
13543 cursor_type_changed
= 0;
13546 /* Start SIGIO interrupts coming again. Having them off during the
13547 code above makes it less likely one will discard output, but not
13548 impossible, since there might be stuff in the system buffer here.
13549 But it is much hairier to try to do anything about that. */
13550 if (interrupt_input
)
13554 /* If a frame has become visible which was not before, redisplay
13555 again, so that we display it. Expose events for such a frame
13556 (which it gets when becoming visible) don't call the parts of
13557 redisplay constructing glyphs, so simply exposing a frame won't
13558 display anything in this case. So, we have to display these
13559 frames here explicitly. */
13562 Lisp_Object tail
, frame
;
13565 FOR_EACH_FRAME (tail
, frame
)
13567 int this_is_visible
= 0;
13569 if (XFRAME (frame
)->visible
)
13570 this_is_visible
= 1;
13571 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13572 if (XFRAME (frame
)->visible
)
13573 this_is_visible
= 1;
13575 if (this_is_visible
)
13579 if (new_count
!= number_of_visible_frames
)
13580 windows_or_buffers_changed
++;
13583 /* Change frame size now if a change is pending. */
13584 do_pending_window_change (1);
13586 /* If we just did a pending size change, or have additional
13587 visible frames, or selected_window changed, redisplay again. */
13588 if ((windows_or_buffers_changed
&& !pending
)
13589 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13592 /* Clear the face and image caches.
13594 We used to do this only if consider_all_windows_p. But the cache
13595 needs to be cleared if a timer creates images in the current
13596 buffer (e.g. the test case in Bug#6230). */
13598 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13600 clear_face_cache (0);
13601 clear_face_cache_count
= 0;
13604 #ifdef HAVE_WINDOW_SYSTEM
13605 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13607 clear_image_caches (Qnil
);
13608 clear_image_cache_count
= 0;
13610 #endif /* HAVE_WINDOW_SYSTEM */
13613 unbind_to (count
, Qnil
);
13618 /* Redisplay, but leave alone any recent echo area message unless
13619 another message has been requested in its place.
13621 This is useful in situations where you need to redisplay but no
13622 user action has occurred, making it inappropriate for the message
13623 area to be cleared. See tracking_off and
13624 wait_reading_process_output for examples of these situations.
13626 FROM_WHERE is an integer saying from where this function was
13627 called. This is useful for debugging. */
13630 redisplay_preserve_echo_area (int from_where
)
13632 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13634 if (!NILP (echo_area_buffer
[1]))
13636 /* We have a previously displayed message, but no current
13637 message. Redisplay the previous message. */
13638 display_last_displayed_message_p
= 1;
13639 redisplay_internal ();
13640 display_last_displayed_message_p
= 0;
13643 redisplay_internal ();
13645 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13646 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13647 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13651 /* Function registered with record_unwind_protect in
13652 redisplay_internal. Reset redisplaying_p to the value it had
13653 before redisplay_internal was called, and clear
13654 prevent_freeing_realized_faces_p. It also selects the previously
13655 selected frame, unless it has been deleted (by an X connection
13656 failure during redisplay, for example). */
13659 unwind_redisplay (Lisp_Object val
)
13661 Lisp_Object old_redisplaying_p
, old_frame
;
13663 old_redisplaying_p
= XCAR (val
);
13664 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13665 old_frame
= XCDR (val
);
13666 if (! EQ (old_frame
, selected_frame
)
13667 && FRAME_LIVE_P (XFRAME (old_frame
)))
13668 select_frame_for_redisplay (old_frame
);
13673 /* Mark the display of window W as accurate or inaccurate. If
13674 ACCURATE_P is non-zero mark display of W as accurate. If
13675 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13676 redisplay_internal is called. */
13679 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13681 if (BUFFERP (w
->buffer
))
13683 struct buffer
*b
= XBUFFER (w
->buffer
);
13685 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13686 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13688 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13692 b
->clip_changed
= 0;
13693 b
->prevent_redisplay_optimizations_p
= 0;
13695 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13696 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13697 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13698 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13700 w
->current_matrix
->buffer
= b
;
13701 w
->current_matrix
->begv
= BUF_BEGV (b
);
13702 w
->current_matrix
->zv
= BUF_ZV (b
);
13704 w
->last_cursor
= w
->cursor
;
13705 w
->last_cursor_off_p
= w
->cursor_off_p
;
13707 if (w
== XWINDOW (selected_window
))
13708 w
->last_point
= BUF_PT (b
);
13710 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
13716 w
->window_end_valid
= w
->buffer
;
13717 w
->update_mode_line
= 0;
13722 /* Mark the display of windows in the window tree rooted at WINDOW as
13723 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13724 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13725 be redisplayed the next time redisplay_internal is called. */
13728 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13732 for (; !NILP (window
); window
= w
->next
)
13734 w
= XWINDOW (window
);
13735 mark_window_display_accurate_1 (w
, accurate_p
);
13737 if (!NILP (w
->vchild
))
13738 mark_window_display_accurate (w
->vchild
, accurate_p
);
13739 if (!NILP (w
->hchild
))
13740 mark_window_display_accurate (w
->hchild
, accurate_p
);
13745 update_overlay_arrows (1);
13749 /* Force a thorough redisplay the next time by setting
13750 last_arrow_position and last_arrow_string to t, which is
13751 unequal to any useful value of Voverlay_arrow_... */
13752 update_overlay_arrows (-1);
13757 /* Return value in display table DP (Lisp_Char_Table *) for character
13758 C. Since a display table doesn't have any parent, we don't have to
13759 follow parent. Do not call this function directly but use the
13760 macro DISP_CHAR_VECTOR. */
13763 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13767 if (ASCII_CHAR_P (c
))
13770 if (SUB_CHAR_TABLE_P (val
))
13771 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13777 XSETCHAR_TABLE (table
, dp
);
13778 val
= char_table_ref (table
, c
);
13787 /***********************************************************************
13789 ***********************************************************************/
13791 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13794 redisplay_windows (Lisp_Object window
)
13796 while (!NILP (window
))
13798 struct window
*w
= XWINDOW (window
);
13800 if (!NILP (w
->hchild
))
13801 redisplay_windows (w
->hchild
);
13802 else if (!NILP (w
->vchild
))
13803 redisplay_windows (w
->vchild
);
13804 else if (!NILP (w
->buffer
))
13806 displayed_buffer
= XBUFFER (w
->buffer
);
13807 /* Use list_of_error, not Qerror, so that
13808 we catch only errors and don't run the debugger. */
13809 internal_condition_case_1 (redisplay_window_0
, window
,
13811 redisplay_window_error
);
13819 redisplay_window_error (Lisp_Object ignore
)
13821 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13826 redisplay_window_0 (Lisp_Object window
)
13828 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13829 redisplay_window (window
, 0);
13834 redisplay_window_1 (Lisp_Object window
)
13836 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13837 redisplay_window (window
, 1);
13842 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13843 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13844 which positions recorded in ROW differ from current buffer
13847 Return 0 if cursor is not on this row, 1 otherwise. */
13850 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13851 struct glyph_matrix
*matrix
,
13852 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13855 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13856 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13857 struct glyph
*cursor
= NULL
;
13858 /* The last known character position in row. */
13859 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13861 ptrdiff_t pt_old
= PT
- delta
;
13862 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13863 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13864 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13865 /* A glyph beyond the edge of TEXT_AREA which we should never
13867 struct glyph
*glyphs_end
= end
;
13868 /* Non-zero means we've found a match for cursor position, but that
13869 glyph has the avoid_cursor_p flag set. */
13870 int match_with_avoid_cursor
= 0;
13871 /* Non-zero means we've seen at least one glyph that came from a
13873 int string_seen
= 0;
13874 /* Largest and smallest buffer positions seen so far during scan of
13876 ptrdiff_t bpos_max
= pos_before
;
13877 ptrdiff_t bpos_min
= pos_after
;
13878 /* Last buffer position covered by an overlay string with an integer
13879 `cursor' property. */
13880 ptrdiff_t bpos_covered
= 0;
13881 /* Non-zero means the display string on which to display the cursor
13882 comes from a text property, not from an overlay. */
13883 int string_from_text_prop
= 0;
13885 /* Don't even try doing anything if called for a mode-line or
13886 header-line row, since the rest of the code isn't prepared to
13887 deal with such calamities. */
13888 eassert (!row
->mode_line_p
);
13889 if (row
->mode_line_p
)
13892 /* Skip over glyphs not having an object at the start and the end of
13893 the row. These are special glyphs like truncation marks on
13894 terminal frames. */
13895 if (row
->displays_text_p
)
13897 if (!row
->reversed_p
)
13900 && INTEGERP (glyph
->object
)
13901 && glyph
->charpos
< 0)
13903 x
+= glyph
->pixel_width
;
13907 && INTEGERP ((end
- 1)->object
)
13908 /* CHARPOS is zero for blanks and stretch glyphs
13909 inserted by extend_face_to_end_of_line. */
13910 && (end
- 1)->charpos
<= 0)
13912 glyph_before
= glyph
- 1;
13919 /* If the glyph row is reversed, we need to process it from back
13920 to front, so swap the edge pointers. */
13921 glyphs_end
= end
= glyph
- 1;
13922 glyph
+= row
->used
[TEXT_AREA
] - 1;
13924 while (glyph
> end
+ 1
13925 && INTEGERP (glyph
->object
)
13926 && glyph
->charpos
< 0)
13929 x
-= glyph
->pixel_width
;
13931 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13933 /* By default, in reversed rows we put the cursor on the
13934 rightmost (first in the reading order) glyph. */
13935 for (g
= end
+ 1; g
< glyph
; g
++)
13936 x
+= g
->pixel_width
;
13938 && INTEGERP ((end
+ 1)->object
)
13939 && (end
+ 1)->charpos
<= 0)
13941 glyph_before
= glyph
+ 1;
13945 else if (row
->reversed_p
)
13947 /* In R2L rows that don't display text, put the cursor on the
13948 rightmost glyph. Case in point: an empty last line that is
13949 part of an R2L paragraph. */
13951 /* Avoid placing the cursor on the last glyph of the row, where
13952 on terminal frames we hold the vertical border between
13953 adjacent windows. */
13954 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13955 && !WINDOW_RIGHTMOST_P (w
)
13956 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13958 x
= -1; /* will be computed below, at label compute_x */
13961 /* Step 1: Try to find the glyph whose character position
13962 corresponds to point. If that's not possible, find 2 glyphs
13963 whose character positions are the closest to point, one before
13964 point, the other after it. */
13965 if (!row
->reversed_p
)
13966 while (/* not marched to end of glyph row */
13968 /* glyph was not inserted by redisplay for internal purposes */
13969 && !INTEGERP (glyph
->object
))
13971 if (BUFFERP (glyph
->object
))
13973 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13975 if (glyph
->charpos
> bpos_max
)
13976 bpos_max
= glyph
->charpos
;
13977 if (glyph
->charpos
< bpos_min
)
13978 bpos_min
= glyph
->charpos
;
13979 if (!glyph
->avoid_cursor_p
)
13981 /* If we hit point, we've found the glyph on which to
13982 display the cursor. */
13985 match_with_avoid_cursor
= 0;
13988 /* See if we've found a better approximation to
13989 POS_BEFORE or to POS_AFTER. */
13990 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13992 pos_before
= glyph
->charpos
;
13993 glyph_before
= glyph
;
13995 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13997 pos_after
= glyph
->charpos
;
13998 glyph_after
= glyph
;
14001 else if (dpos
== 0)
14002 match_with_avoid_cursor
= 1;
14004 else if (STRINGP (glyph
->object
))
14006 Lisp_Object chprop
;
14007 ptrdiff_t glyph_pos
= glyph
->charpos
;
14009 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14011 if (!NILP (chprop
))
14013 /* If the string came from a `display' text property,
14014 look up the buffer position of that property and
14015 use that position to update bpos_max, as if we
14016 actually saw such a position in one of the row's
14017 glyphs. This helps with supporting integer values
14018 of `cursor' property on the display string in
14019 situations where most or all of the row's buffer
14020 text is completely covered by display properties,
14021 so that no glyph with valid buffer positions is
14022 ever seen in the row. */
14023 ptrdiff_t prop_pos
=
14024 string_buffer_position_lim (glyph
->object
, pos_before
,
14027 if (prop_pos
>= pos_before
)
14028 bpos_max
= prop_pos
- 1;
14030 if (INTEGERP (chprop
))
14032 bpos_covered
= bpos_max
+ XINT (chprop
);
14033 /* If the `cursor' property covers buffer positions up
14034 to and including point, we should display cursor on
14035 this glyph. Note that, if a `cursor' property on one
14036 of the string's characters has an integer value, we
14037 will break out of the loop below _before_ we get to
14038 the position match above. IOW, integer values of
14039 the `cursor' property override the "exact match for
14040 point" strategy of positioning the cursor. */
14041 /* Implementation note: bpos_max == pt_old when, e.g.,
14042 we are in an empty line, where bpos_max is set to
14043 MATRIX_ROW_START_CHARPOS, see above. */
14044 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14053 x
+= glyph
->pixel_width
;
14056 else if (glyph
> end
) /* row is reversed */
14057 while (!INTEGERP (glyph
->object
))
14059 if (BUFFERP (glyph
->object
))
14061 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14063 if (glyph
->charpos
> bpos_max
)
14064 bpos_max
= glyph
->charpos
;
14065 if (glyph
->charpos
< bpos_min
)
14066 bpos_min
= glyph
->charpos
;
14067 if (!glyph
->avoid_cursor_p
)
14071 match_with_avoid_cursor
= 0;
14074 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14076 pos_before
= glyph
->charpos
;
14077 glyph_before
= glyph
;
14079 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14081 pos_after
= glyph
->charpos
;
14082 glyph_after
= glyph
;
14085 else if (dpos
== 0)
14086 match_with_avoid_cursor
= 1;
14088 else if (STRINGP (glyph
->object
))
14090 Lisp_Object chprop
;
14091 ptrdiff_t glyph_pos
= glyph
->charpos
;
14093 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14095 if (!NILP (chprop
))
14097 ptrdiff_t prop_pos
=
14098 string_buffer_position_lim (glyph
->object
, pos_before
,
14101 if (prop_pos
>= pos_before
)
14102 bpos_max
= prop_pos
- 1;
14104 if (INTEGERP (chprop
))
14106 bpos_covered
= bpos_max
+ XINT (chprop
);
14107 /* If the `cursor' property covers buffer positions up
14108 to and including point, we should display cursor on
14110 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14119 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14121 x
--; /* can't use any pixel_width */
14124 x
-= glyph
->pixel_width
;
14127 /* Step 2: If we didn't find an exact match for point, we need to
14128 look for a proper place to put the cursor among glyphs between
14129 GLYPH_BEFORE and GLYPH_AFTER. */
14130 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14131 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14132 && bpos_covered
< pt_old
)
14134 /* An empty line has a single glyph whose OBJECT is zero and
14135 whose CHARPOS is the position of a newline on that line.
14136 Note that on a TTY, there are more glyphs after that, which
14137 were produced by extend_face_to_end_of_line, but their
14138 CHARPOS is zero or negative. */
14140 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14141 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14143 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14145 ptrdiff_t ellipsis_pos
;
14147 /* Scan back over the ellipsis glyphs. */
14148 if (!row
->reversed_p
)
14150 ellipsis_pos
= (glyph
- 1)->charpos
;
14151 while (glyph
> row
->glyphs
[TEXT_AREA
]
14152 && (glyph
- 1)->charpos
== ellipsis_pos
)
14153 glyph
--, x
-= glyph
->pixel_width
;
14154 /* That loop always goes one position too far, including
14155 the glyph before the ellipsis. So scan forward over
14157 x
+= glyph
->pixel_width
;
14160 else /* row is reversed */
14162 ellipsis_pos
= (glyph
+ 1)->charpos
;
14163 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14164 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14165 glyph
++, x
+= glyph
->pixel_width
;
14166 x
-= glyph
->pixel_width
;
14170 else if (match_with_avoid_cursor
)
14172 cursor
= glyph_after
;
14175 else if (string_seen
)
14177 int incr
= row
->reversed_p
? -1 : +1;
14179 /* Need to find the glyph that came out of a string which is
14180 present at point. That glyph is somewhere between
14181 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14182 positioned between POS_BEFORE and POS_AFTER in the
14184 struct glyph
*start
, *stop
;
14185 ptrdiff_t pos
= pos_before
;
14189 /* If the row ends in a newline from a display string,
14190 reordering could have moved the glyphs belonging to the
14191 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14192 in this case we extend the search to the last glyph in
14193 the row that was not inserted by redisplay. */
14194 if (row
->ends_in_newline_from_string_p
)
14197 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14200 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14201 correspond to POS_BEFORE and POS_AFTER, respectively. We
14202 need START and STOP in the order that corresponds to the
14203 row's direction as given by its reversed_p flag. If the
14204 directionality of characters between POS_BEFORE and
14205 POS_AFTER is the opposite of the row's base direction,
14206 these characters will have been reordered for display,
14207 and we need to reverse START and STOP. */
14208 if (!row
->reversed_p
)
14210 start
= min (glyph_before
, glyph_after
);
14211 stop
= max (glyph_before
, glyph_after
);
14215 start
= max (glyph_before
, glyph_after
);
14216 stop
= min (glyph_before
, glyph_after
);
14218 for (glyph
= start
+ incr
;
14219 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14222 /* Any glyphs that come from the buffer are here because
14223 of bidi reordering. Skip them, and only pay
14224 attention to glyphs that came from some string. */
14225 if (STRINGP (glyph
->object
))
14229 /* If the display property covers the newline, we
14230 need to search for it one position farther. */
14231 ptrdiff_t lim
= pos_after
14232 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14234 string_from_text_prop
= 0;
14235 str
= glyph
->object
;
14236 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14237 if (tem
== 0 /* from overlay */
14240 /* If the string from which this glyph came is
14241 found in the buffer at point, or at position
14242 that is closer to point than pos_after, then
14243 we've found the glyph we've been looking for.
14244 If it comes from an overlay (tem == 0), and
14245 it has the `cursor' property on one of its
14246 glyphs, record that glyph as a candidate for
14247 displaying the cursor. (As in the
14248 unidirectional version, we will display the
14249 cursor on the last candidate we find.) */
14252 || (tem
- pt_old
> 0 && tem
< pos_after
))
14254 /* The glyphs from this string could have
14255 been reordered. Find the one with the
14256 smallest string position. Or there could
14257 be a character in the string with the
14258 `cursor' property, which means display
14259 cursor on that character's glyph. */
14260 ptrdiff_t strpos
= glyph
->charpos
;
14265 string_from_text_prop
= 1;
14268 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14269 && EQ (glyph
->object
, str
);
14273 ptrdiff_t gpos
= glyph
->charpos
;
14275 cprop
= Fget_char_property (make_number (gpos
),
14283 if (tem
&& glyph
->charpos
< strpos
)
14285 strpos
= glyph
->charpos
;
14291 || (tem
- pt_old
> 0 && tem
< pos_after
))
14295 pos
= tem
+ 1; /* don't find previous instances */
14297 /* This string is not what we want; skip all of the
14298 glyphs that came from it. */
14299 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14300 && EQ (glyph
->object
, str
))
14307 /* If we reached the end of the line, and END was from a string,
14308 the cursor is not on this line. */
14310 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14311 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14312 && STRINGP (end
->object
)
14313 && row
->continued_p
)
14316 /* A truncated row may not include PT among its character positions.
14317 Setting the cursor inside the scroll margin will trigger
14318 recalculation of hscroll in hscroll_window_tree. But if a
14319 display string covers point, defer to the string-handling
14320 code below to figure this out. */
14321 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14323 cursor
= glyph_before
;
14326 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14327 /* Zero-width characters produce no glyphs. */
14329 && (row
->reversed_p
14330 ? glyph_after
> glyphs_end
14331 : glyph_after
< glyphs_end
)))
14333 cursor
= glyph_after
;
14339 if (cursor
!= NULL
)
14341 else if (glyph
== glyphs_end
14342 && pos_before
== pos_after
14343 && STRINGP ((row
->reversed_p
14344 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14345 : row
->glyphs
[TEXT_AREA
])->object
))
14347 /* If all the glyphs of this row came from strings, put the
14348 cursor on the first glyph of the row. This avoids having the
14349 cursor outside of the text area in this very rare and hard
14353 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14354 : row
->glyphs
[TEXT_AREA
];
14360 /* Need to compute x that corresponds to GLYPH. */
14361 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14363 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14365 x
+= g
->pixel_width
;
14369 /* ROW could be part of a continued line, which, under bidi
14370 reordering, might have other rows whose start and end charpos
14371 occlude point. Only set w->cursor if we found a better
14372 approximation to the cursor position than we have from previously
14373 examined candidate rows belonging to the same continued line. */
14374 if (/* we already have a candidate row */
14375 w
->cursor
.vpos
>= 0
14376 /* that candidate is not the row we are processing */
14377 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14378 /* Make sure cursor.vpos specifies a row whose start and end
14379 charpos occlude point, and it is valid candidate for being a
14380 cursor-row. This is because some callers of this function
14381 leave cursor.vpos at the row where the cursor was displayed
14382 during the last redisplay cycle. */
14383 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14384 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14385 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14388 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14390 /* Don't consider glyphs that are outside TEXT_AREA. */
14391 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14393 /* Keep the candidate whose buffer position is the closest to
14394 point or has the `cursor' property. */
14395 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14396 w
->cursor
.hpos
>= 0
14397 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14398 && ((BUFFERP (g1
->object
)
14399 && (g1
->charpos
== pt_old
/* an exact match always wins */
14400 || (BUFFERP (glyph
->object
)
14401 && eabs (g1
->charpos
- pt_old
)
14402 < eabs (glyph
->charpos
- pt_old
))))
14403 /* previous candidate is a glyph from a string that has
14404 a non-nil `cursor' property */
14405 || (STRINGP (g1
->object
)
14406 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14407 Qcursor
, g1
->object
))
14408 /* previous candidate is from the same display
14409 string as this one, and the display string
14410 came from a text property */
14411 || (EQ (g1
->object
, glyph
->object
)
14412 && string_from_text_prop
)
14413 /* this candidate is from newline and its
14414 position is not an exact match */
14415 || (INTEGERP (glyph
->object
)
14416 && glyph
->charpos
!= pt_old
)))))
14418 /* If this candidate gives an exact match, use that. */
14419 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14420 /* If this candidate is a glyph created for the
14421 terminating newline of a line, and point is on that
14422 newline, it wins because it's an exact match. */
14423 || (!row
->continued_p
14424 && INTEGERP (glyph
->object
)
14425 && glyph
->charpos
== 0
14426 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14427 /* Otherwise, keep the candidate that comes from a row
14428 spanning less buffer positions. This may win when one or
14429 both candidate positions are on glyphs that came from
14430 display strings, for which we cannot compare buffer
14432 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14433 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14434 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14437 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14439 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14440 w
->cursor
.y
= row
->y
+ dy
;
14442 if (w
== XWINDOW (selected_window
))
14444 if (!row
->continued_p
14445 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14448 this_line_buffer
= XBUFFER (w
->buffer
);
14450 CHARPOS (this_line_start_pos
)
14451 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14452 BYTEPOS (this_line_start_pos
)
14453 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14455 CHARPOS (this_line_end_pos
)
14456 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14457 BYTEPOS (this_line_end_pos
)
14458 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14460 this_line_y
= w
->cursor
.y
;
14461 this_line_pixel_height
= row
->height
;
14462 this_line_vpos
= w
->cursor
.vpos
;
14463 this_line_start_x
= row
->x
;
14466 CHARPOS (this_line_start_pos
) = 0;
14473 /* Run window scroll functions, if any, for WINDOW with new window
14474 start STARTP. Sets the window start of WINDOW to that position.
14476 We assume that the window's buffer is really current. */
14478 static inline struct text_pos
14479 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14481 struct window
*w
= XWINDOW (window
);
14482 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14484 if (current_buffer
!= XBUFFER (w
->buffer
))
14487 if (!NILP (Vwindow_scroll_functions
))
14489 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14490 make_number (CHARPOS (startp
)));
14491 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14492 /* In case the hook functions switch buffers. */
14493 if (current_buffer
!= XBUFFER (w
->buffer
))
14494 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14501 /* Make sure the line containing the cursor is fully visible.
14502 A value of 1 means there is nothing to be done.
14503 (Either the line is fully visible, or it cannot be made so,
14504 or we cannot tell.)
14506 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14507 is higher than window.
14509 A value of 0 means the caller should do scrolling
14510 as if point had gone off the screen. */
14513 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14515 struct glyph_matrix
*matrix
;
14516 struct glyph_row
*row
;
14519 if (!make_cursor_line_fully_visible_p
)
14522 /* It's not always possible to find the cursor, e.g, when a window
14523 is full of overlay strings. Don't do anything in that case. */
14524 if (w
->cursor
.vpos
< 0)
14527 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14528 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14530 /* If the cursor row is not partially visible, there's nothing to do. */
14531 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14534 /* If the row the cursor is in is taller than the window's height,
14535 it's not clear what to do, so do nothing. */
14536 window_height
= window_box_height (w
);
14537 if (row
->height
>= window_height
)
14539 if (!force_p
|| MINI_WINDOW_P (w
)
14540 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14547 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14548 non-zero means only WINDOW is redisplayed in redisplay_internal.
14549 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14550 in redisplay_window to bring a partially visible line into view in
14551 the case that only the cursor has moved.
14553 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14554 last screen line's vertical height extends past the end of the screen.
14558 1 if scrolling succeeded
14560 0 if scrolling didn't find point.
14562 -1 if new fonts have been loaded so that we must interrupt
14563 redisplay, adjust glyph matrices, and try again. */
14569 SCROLLING_NEED_LARGER_MATRICES
14572 /* If scroll-conservatively is more than this, never recenter.
14574 If you change this, don't forget to update the doc string of
14575 `scroll-conservatively' and the Emacs manual. */
14576 #define SCROLL_LIMIT 100
14579 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14580 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14581 int temp_scroll_step
, int last_line_misfit
)
14583 struct window
*w
= XWINDOW (window
);
14584 struct frame
*f
= XFRAME (w
->frame
);
14585 struct text_pos pos
, startp
;
14587 int this_scroll_margin
, scroll_max
, rc
, height
;
14588 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14589 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14590 Lisp_Object aggressive
;
14591 /* We will never try scrolling more than this number of lines. */
14592 int scroll_limit
= SCROLL_LIMIT
;
14595 debug_method_add (w
, "try_scrolling");
14598 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14600 /* Compute scroll margin height in pixels. We scroll when point is
14601 within this distance from the top or bottom of the window. */
14602 if (scroll_margin
> 0)
14603 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14604 * FRAME_LINE_HEIGHT (f
);
14606 this_scroll_margin
= 0;
14608 /* Force arg_scroll_conservatively to have a reasonable value, to
14609 avoid scrolling too far away with slow move_it_* functions. Note
14610 that the user can supply scroll-conservatively equal to
14611 `most-positive-fixnum', which can be larger than INT_MAX. */
14612 if (arg_scroll_conservatively
> scroll_limit
)
14614 arg_scroll_conservatively
= scroll_limit
+ 1;
14615 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14617 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14618 /* Compute how much we should try to scroll maximally to bring
14619 point into view. */
14620 scroll_max
= (max (scroll_step
,
14621 max (arg_scroll_conservatively
, temp_scroll_step
))
14622 * FRAME_LINE_HEIGHT (f
));
14623 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14624 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14625 /* We're trying to scroll because of aggressive scrolling but no
14626 scroll_step is set. Choose an arbitrary one. */
14627 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14633 /* Decide whether to scroll down. */
14634 if (PT
> CHARPOS (startp
))
14636 int scroll_margin_y
;
14638 /* Compute the pixel ypos of the scroll margin, then move IT to
14639 either that ypos or PT, whichever comes first. */
14640 start_display (&it
, w
, startp
);
14641 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14642 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14643 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14644 (MOVE_TO_POS
| MOVE_TO_Y
));
14646 if (PT
> CHARPOS (it
.current
.pos
))
14648 int y0
= line_bottom_y (&it
);
14649 /* Compute how many pixels below window bottom to stop searching
14650 for PT. This avoids costly search for PT that is far away if
14651 the user limited scrolling by a small number of lines, but
14652 always finds PT if scroll_conservatively is set to a large
14653 number, such as most-positive-fixnum. */
14654 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14655 int y_to_move
= it
.last_visible_y
+ slack
;
14657 /* Compute the distance from the scroll margin to PT or to
14658 the scroll limit, whichever comes first. This should
14659 include the height of the cursor line, to make that line
14661 move_it_to (&it
, PT
, -1, y_to_move
,
14662 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14663 dy
= line_bottom_y (&it
) - y0
;
14665 if (dy
> scroll_max
)
14666 return SCROLLING_FAILED
;
14675 /* Point is in or below the bottom scroll margin, so move the
14676 window start down. If scrolling conservatively, move it just
14677 enough down to make point visible. If scroll_step is set,
14678 move it down by scroll_step. */
14679 if (arg_scroll_conservatively
)
14681 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14682 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14683 else if (scroll_step
|| temp_scroll_step
)
14684 amount_to_scroll
= scroll_max
;
14687 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14688 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14689 if (NUMBERP (aggressive
))
14691 double float_amount
= XFLOATINT (aggressive
) * height
;
14692 amount_to_scroll
= float_amount
;
14693 if (amount_to_scroll
== 0 && float_amount
> 0)
14694 amount_to_scroll
= 1;
14695 /* Don't let point enter the scroll margin near top of
14697 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14698 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14702 if (amount_to_scroll
<= 0)
14703 return SCROLLING_FAILED
;
14705 start_display (&it
, w
, startp
);
14706 if (arg_scroll_conservatively
<= scroll_limit
)
14707 move_it_vertically (&it
, amount_to_scroll
);
14710 /* Extra precision for users who set scroll-conservatively
14711 to a large number: make sure the amount we scroll
14712 the window start is never less than amount_to_scroll,
14713 which was computed as distance from window bottom to
14714 point. This matters when lines at window top and lines
14715 below window bottom have different height. */
14717 void *it1data
= NULL
;
14718 /* We use a temporary it1 because line_bottom_y can modify
14719 its argument, if it moves one line down; see there. */
14722 SAVE_IT (it1
, it
, it1data
);
14723 start_y
= line_bottom_y (&it1
);
14725 RESTORE_IT (&it
, &it
, it1data
);
14726 move_it_by_lines (&it
, 1);
14727 SAVE_IT (it1
, it
, it1data
);
14728 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14731 /* If STARTP is unchanged, move it down another screen line. */
14732 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14733 move_it_by_lines (&it
, 1);
14734 startp
= it
.current
.pos
;
14738 struct text_pos scroll_margin_pos
= startp
;
14740 /* See if point is inside the scroll margin at the top of the
14742 if (this_scroll_margin
)
14744 start_display (&it
, w
, startp
);
14745 move_it_vertically (&it
, this_scroll_margin
);
14746 scroll_margin_pos
= it
.current
.pos
;
14749 if (PT
< CHARPOS (scroll_margin_pos
))
14751 /* Point is in the scroll margin at the top of the window or
14752 above what is displayed in the window. */
14755 /* Compute the vertical distance from PT to the scroll
14756 margin position. Move as far as scroll_max allows, or
14757 one screenful, or 10 screen lines, whichever is largest.
14758 Give up if distance is greater than scroll_max. */
14759 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14760 start_display (&it
, w
, pos
);
14762 y_to_move
= max (it
.last_visible_y
,
14763 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14764 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14766 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14767 dy
= it
.current_y
- y0
;
14768 if (dy
> scroll_max
)
14769 return SCROLLING_FAILED
;
14771 /* Compute new window start. */
14772 start_display (&it
, w
, startp
);
14774 if (arg_scroll_conservatively
)
14775 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14776 max (scroll_step
, temp_scroll_step
));
14777 else if (scroll_step
|| temp_scroll_step
)
14778 amount_to_scroll
= scroll_max
;
14781 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14782 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14783 if (NUMBERP (aggressive
))
14785 double float_amount
= XFLOATINT (aggressive
) * height
;
14786 amount_to_scroll
= float_amount
;
14787 if (amount_to_scroll
== 0 && float_amount
> 0)
14788 amount_to_scroll
= 1;
14789 amount_to_scroll
-=
14790 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14791 /* Don't let point enter the scroll margin near
14792 bottom of the window. */
14793 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14794 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14798 if (amount_to_scroll
<= 0)
14799 return SCROLLING_FAILED
;
14801 move_it_vertically_backward (&it
, amount_to_scroll
);
14802 startp
= it
.current
.pos
;
14806 /* Run window scroll functions. */
14807 startp
= run_window_scroll_functions (window
, startp
);
14809 /* Display the window. Give up if new fonts are loaded, or if point
14811 if (!try_window (window
, startp
, 0))
14812 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14813 else if (w
->cursor
.vpos
< 0)
14815 clear_glyph_matrix (w
->desired_matrix
);
14816 rc
= SCROLLING_FAILED
;
14820 /* Maybe forget recorded base line for line number display. */
14821 if (!just_this_one_p
14822 || current_buffer
->clip_changed
14823 || BEG_UNCHANGED
< CHARPOS (startp
))
14824 w
->base_line_number
= Qnil
;
14826 /* If cursor ends up on a partially visible line,
14827 treat that as being off the bottom of the screen. */
14828 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14829 /* It's possible that the cursor is on the first line of the
14830 buffer, which is partially obscured due to a vscroll
14831 (Bug#7537). In that case, avoid looping forever . */
14832 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14834 clear_glyph_matrix (w
->desired_matrix
);
14835 ++extra_scroll_margin_lines
;
14838 rc
= SCROLLING_SUCCESS
;
14845 /* Compute a suitable window start for window W if display of W starts
14846 on a continuation line. Value is non-zero if a new window start
14849 The new window start will be computed, based on W's width, starting
14850 from the start of the continued line. It is the start of the
14851 screen line with the minimum distance from the old start W->start. */
14854 compute_window_start_on_continuation_line (struct window
*w
)
14856 struct text_pos pos
, start_pos
;
14857 int window_start_changed_p
= 0;
14859 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14861 /* If window start is on a continuation line... Window start may be
14862 < BEGV in case there's invisible text at the start of the
14863 buffer (M-x rmail, for example). */
14864 if (CHARPOS (start_pos
) > BEGV
14865 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14868 struct glyph_row
*row
;
14870 /* Handle the case that the window start is out of range. */
14871 if (CHARPOS (start_pos
) < BEGV
)
14872 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14873 else if (CHARPOS (start_pos
) > ZV
)
14874 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14876 /* Find the start of the continued line. This should be fast
14877 because scan_buffer is fast (newline cache). */
14878 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14879 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14880 row
, DEFAULT_FACE_ID
);
14881 reseat_at_previous_visible_line_start (&it
);
14883 /* If the line start is "too far" away from the window start,
14884 say it takes too much time to compute a new window start. */
14885 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14886 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14888 int min_distance
, distance
;
14890 /* Move forward by display lines to find the new window
14891 start. If window width was enlarged, the new start can
14892 be expected to be > the old start. If window width was
14893 decreased, the new window start will be < the old start.
14894 So, we're looking for the display line start with the
14895 minimum distance from the old window start. */
14896 pos
= it
.current
.pos
;
14897 min_distance
= INFINITY
;
14898 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14899 distance
< min_distance
)
14901 min_distance
= distance
;
14902 pos
= it
.current
.pos
;
14903 move_it_by_lines (&it
, 1);
14906 /* Set the window start there. */
14907 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14908 window_start_changed_p
= 1;
14912 return window_start_changed_p
;
14916 /* Try cursor movement in case text has not changed in window WINDOW,
14917 with window start STARTP. Value is
14919 CURSOR_MOVEMENT_SUCCESS if successful
14921 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14923 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14924 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14925 we want to scroll as if scroll-step were set to 1. See the code.
14927 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14928 which case we have to abort this redisplay, and adjust matrices
14933 CURSOR_MOVEMENT_SUCCESS
,
14934 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14935 CURSOR_MOVEMENT_MUST_SCROLL
,
14936 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14940 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14942 struct window
*w
= XWINDOW (window
);
14943 struct frame
*f
= XFRAME (w
->frame
);
14944 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14947 if (inhibit_try_cursor_movement
)
14951 /* Previously, there was a check for Lisp integer in the
14952 if-statement below. Now, this field is converted to
14953 ptrdiff_t, thus zero means invalid position in a buffer. */
14954 eassert (w
->last_point
> 0);
14956 /* Handle case where text has not changed, only point, and it has
14957 not moved off the frame. */
14958 if (/* Point may be in this window. */
14959 PT
>= CHARPOS (startp
)
14960 /* Selective display hasn't changed. */
14961 && !current_buffer
->clip_changed
14962 /* Function force-mode-line-update is used to force a thorough
14963 redisplay. It sets either windows_or_buffers_changed or
14964 update_mode_lines. So don't take a shortcut here for these
14966 && !update_mode_lines
14967 && !windows_or_buffers_changed
14968 && !cursor_type_changed
14969 /* Can't use this case if highlighting a region. When a
14970 region exists, cursor movement has to do more than just
14972 && !(!NILP (Vtransient_mark_mode
)
14973 && !NILP (BVAR (current_buffer
, mark_active
)))
14974 && NILP (w
->region_showing
)
14975 && NILP (Vshow_trailing_whitespace
)
14976 /* This code is not used for mini-buffer for the sake of the case
14977 of redisplaying to replace an echo area message; since in
14978 that case the mini-buffer contents per se are usually
14979 unchanged. This code is of no real use in the mini-buffer
14980 since the handling of this_line_start_pos, etc., in redisplay
14981 handles the same cases. */
14982 && !EQ (window
, minibuf_window
)
14983 /* When splitting windows or for new windows, it happens that
14984 redisplay is called with a nil window_end_vpos or one being
14985 larger than the window. This should really be fixed in
14986 window.c. I don't have this on my list, now, so we do
14987 approximately the same as the old redisplay code. --gerd. */
14988 && INTEGERP (w
->window_end_vpos
)
14989 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14990 && (FRAME_WINDOW_P (f
)
14991 || !overlay_arrow_in_current_buffer_p ()))
14993 int this_scroll_margin
, top_scroll_margin
;
14994 struct glyph_row
*row
= NULL
;
14997 debug_method_add (w
, "cursor movement");
15000 /* Scroll if point within this distance from the top or bottom
15001 of the window. This is a pixel value. */
15002 if (scroll_margin
> 0)
15004 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15005 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15008 this_scroll_margin
= 0;
15010 top_scroll_margin
= this_scroll_margin
;
15011 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15012 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15014 /* Start with the row the cursor was displayed during the last
15015 not paused redisplay. Give up if that row is not valid. */
15016 if (w
->last_cursor
.vpos
< 0
15017 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15018 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15021 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15022 if (row
->mode_line_p
)
15024 if (!row
->enabled_p
)
15025 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15028 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15030 int scroll_p
= 0, must_scroll
= 0;
15031 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15033 if (PT
> w
->last_point
)
15035 /* Point has moved forward. */
15036 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15037 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15039 eassert (row
->enabled_p
);
15043 /* If the end position of a row equals the start
15044 position of the next row, and PT is at that position,
15045 we would rather display cursor in the next line. */
15046 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15047 && MATRIX_ROW_END_CHARPOS (row
) == PT
15048 && row
< w
->current_matrix
->rows
15049 + w
->current_matrix
->nrows
- 1
15050 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15051 && !cursor_row_p (row
))
15054 /* If within the scroll margin, scroll. Note that
15055 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15056 the next line would be drawn, and that
15057 this_scroll_margin can be zero. */
15058 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15059 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15060 /* Line is completely visible last line in window
15061 and PT is to be set in the next line. */
15062 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15063 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15064 && !row
->ends_at_zv_p
15065 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15068 else if (PT
< w
->last_point
)
15070 /* Cursor has to be moved backward. Note that PT >=
15071 CHARPOS (startp) because of the outer if-statement. */
15072 while (!row
->mode_line_p
15073 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15074 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15075 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15076 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15077 row
> w
->current_matrix
->rows
15078 && (row
-1)->ends_in_newline_from_string_p
))))
15079 && (row
->y
> top_scroll_margin
15080 || CHARPOS (startp
) == BEGV
))
15082 eassert (row
->enabled_p
);
15086 /* Consider the following case: Window starts at BEGV,
15087 there is invisible, intangible text at BEGV, so that
15088 display starts at some point START > BEGV. It can
15089 happen that we are called with PT somewhere between
15090 BEGV and START. Try to handle that case. */
15091 if (row
< w
->current_matrix
->rows
15092 || row
->mode_line_p
)
15094 row
= w
->current_matrix
->rows
;
15095 if (row
->mode_line_p
)
15099 /* Due to newlines in overlay strings, we may have to
15100 skip forward over overlay strings. */
15101 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15102 && MATRIX_ROW_END_CHARPOS (row
) == PT
15103 && !cursor_row_p (row
))
15106 /* If within the scroll margin, scroll. */
15107 if (row
->y
< top_scroll_margin
15108 && CHARPOS (startp
) != BEGV
)
15113 /* Cursor did not move. So don't scroll even if cursor line
15114 is partially visible, as it was so before. */
15115 rc
= CURSOR_MOVEMENT_SUCCESS
;
15118 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15119 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15121 /* if PT is not in the glyph row, give up. */
15122 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15125 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15126 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15128 struct glyph_row
*row1
;
15130 /* If rows are bidi-reordered and point moved, back up
15131 until we find a row that does not belong to a
15132 continuation line. This is because we must consider
15133 all rows of a continued line as candidates for the
15134 new cursor positioning, since row start and end
15135 positions change non-linearly with vertical position
15137 /* FIXME: Revisit this when glyph ``spilling'' in
15138 continuation lines' rows is implemented for
15139 bidi-reordered rows. */
15140 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15141 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15144 /* If we hit the beginning of the displayed portion
15145 without finding the first row of a continued
15149 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15152 eassert (row
->enabled_p
);
15157 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15158 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15159 /* Make sure this isn't a header line by any chance, since
15160 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15161 && !row
->mode_line_p
15162 && make_cursor_line_fully_visible_p
)
15164 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15165 && !row
->ends_at_zv_p
15166 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15167 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15168 else if (row
->height
> window_box_height (w
))
15170 /* If we end up in a partially visible line, let's
15171 make it fully visible, except when it's taller
15172 than the window, in which case we can't do much
15175 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15179 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15180 if (!cursor_row_fully_visible_p (w
, 0, 1))
15181 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15183 rc
= CURSOR_MOVEMENT_SUCCESS
;
15187 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15188 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15189 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15191 /* With bidi-reordered rows, there could be more than
15192 one candidate row whose start and end positions
15193 occlude point. We need to let set_cursor_from_row
15194 find the best candidate. */
15195 /* FIXME: Revisit this when glyph ``spilling'' in
15196 continuation lines' rows is implemented for
15197 bidi-reordered rows. */
15202 int at_zv_p
= 0, exact_match_p
= 0;
15204 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15205 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15206 && cursor_row_p (row
))
15207 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15209 /* As soon as we've found the exact match for point,
15210 or the first suitable row whose ends_at_zv_p flag
15211 is set, we are done. */
15213 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15215 && w
->cursor
.hpos
>= 0
15216 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15219 struct glyph_row
*candidate
=
15220 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15222 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15223 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15226 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15227 || (INTEGERP (g
->object
)
15228 && (g
->charpos
== PT
15229 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15231 if (rv
&& (at_zv_p
|| exact_match_p
))
15233 rc
= CURSOR_MOVEMENT_SUCCESS
;
15236 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15240 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15241 || row
->continued_p
)
15242 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15243 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15244 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15245 /* If we didn't find any candidate rows, or exited the
15246 loop before all the candidates were examined, signal
15247 to the caller that this method failed. */
15248 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15250 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15251 && !row
->continued_p
))
15252 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15254 rc
= CURSOR_MOVEMENT_SUCCESS
;
15260 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15262 rc
= CURSOR_MOVEMENT_SUCCESS
;
15267 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15268 && MATRIX_ROW_START_CHARPOS (row
) == PT
15269 && cursor_row_p (row
));
15277 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15281 set_vertical_scroll_bar (struct window
*w
)
15283 ptrdiff_t start
, end
, whole
;
15285 /* Calculate the start and end positions for the current window.
15286 At some point, it would be nice to choose between scrollbars
15287 which reflect the whole buffer size, with special markers
15288 indicating narrowing, and scrollbars which reflect only the
15291 Note that mini-buffers sometimes aren't displaying any text. */
15292 if (!MINI_WINDOW_P (w
)
15293 || (w
== XWINDOW (minibuf_window
)
15294 && NILP (echo_area_buffer
[0])))
15296 struct buffer
*buf
= XBUFFER (w
->buffer
);
15297 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15298 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15299 /* I don't think this is guaranteed to be right. For the
15300 moment, we'll pretend it is. */
15301 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15305 if (whole
< (end
- start
))
15306 whole
= end
- start
;
15309 start
= end
= whole
= 0;
15311 /* Indicate what this scroll bar ought to be displaying now. */
15312 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15313 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15314 (w
, end
- start
, whole
, start
);
15318 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15319 selected_window is redisplayed.
15321 We can return without actually redisplaying the window if
15322 fonts_changed_p is nonzero. In that case, redisplay_internal will
15326 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15328 struct window
*w
= XWINDOW (window
);
15329 struct frame
*f
= XFRAME (w
->frame
);
15330 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15331 struct buffer
*old
= current_buffer
;
15332 struct text_pos lpoint
, opoint
, startp
;
15333 int update_mode_line
;
15336 /* Record it now because it's overwritten. */
15337 int current_matrix_up_to_date_p
= 0;
15338 int used_current_matrix_p
= 0;
15339 /* This is less strict than current_matrix_up_to_date_p.
15340 It indicates that the buffer contents and narrowing are unchanged. */
15341 int buffer_unchanged_p
= 0;
15342 int temp_scroll_step
= 0;
15343 ptrdiff_t count
= SPECPDL_INDEX ();
15345 int centering_position
= -1;
15346 int last_line_misfit
= 0;
15347 ptrdiff_t beg_unchanged
, end_unchanged
;
15349 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15352 /* W must be a leaf window here. */
15353 eassert (!NILP (w
->buffer
));
15355 *w
->desired_matrix
->method
= 0;
15359 reconsider_clip_changes (w
, buffer
);
15361 /* Has the mode line to be updated? */
15362 update_mode_line
= (w
->update_mode_line
15363 || update_mode_lines
15364 || buffer
->clip_changed
15365 || buffer
->prevent_redisplay_optimizations_p
);
15367 if (MINI_WINDOW_P (w
))
15369 if (w
== XWINDOW (echo_area_window
)
15370 && !NILP (echo_area_buffer
[0]))
15372 if (update_mode_line
)
15373 /* We may have to update a tty frame's menu bar or a
15374 tool-bar. Example `M-x C-h C-h C-g'. */
15375 goto finish_menu_bars
;
15377 /* We've already displayed the echo area glyphs in this window. */
15378 goto finish_scroll_bars
;
15380 else if ((w
!= XWINDOW (minibuf_window
)
15381 || minibuf_level
== 0)
15382 /* When buffer is nonempty, redisplay window normally. */
15383 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15384 /* Quail displays non-mini buffers in minibuffer window.
15385 In that case, redisplay the window normally. */
15386 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15388 /* W is a mini-buffer window, but it's not active, so clear
15390 int yb
= window_text_bottom_y (w
);
15391 struct glyph_row
*row
;
15394 for (y
= 0, row
= w
->desired_matrix
->rows
;
15396 y
+= row
->height
, ++row
)
15397 blank_row (w
, row
, y
);
15398 goto finish_scroll_bars
;
15401 clear_glyph_matrix (w
->desired_matrix
);
15404 /* Otherwise set up data on this window; select its buffer and point
15406 /* Really select the buffer, for the sake of buffer-local
15408 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15410 current_matrix_up_to_date_p
15411 = (!NILP (w
->window_end_valid
)
15412 && !current_buffer
->clip_changed
15413 && !current_buffer
->prevent_redisplay_optimizations_p
15414 && w
->last_modified
>= MODIFF
15415 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15417 /* Run the window-bottom-change-functions
15418 if it is possible that the text on the screen has changed
15419 (either due to modification of the text, or any other reason). */
15420 if (!current_matrix_up_to_date_p
15421 && !NILP (Vwindow_text_change_functions
))
15423 safe_run_hooks (Qwindow_text_change_functions
);
15427 beg_unchanged
= BEG_UNCHANGED
;
15428 end_unchanged
= END_UNCHANGED
;
15430 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15432 specbind (Qinhibit_point_motion_hooks
, Qt
);
15435 = (!NILP (w
->window_end_valid
)
15436 && !current_buffer
->clip_changed
15437 && w
->last_modified
>= MODIFF
15438 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15440 /* When windows_or_buffers_changed is non-zero, we can't rely on
15441 the window end being valid, so set it to nil there. */
15442 if (windows_or_buffers_changed
)
15444 /* If window starts on a continuation line, maybe adjust the
15445 window start in case the window's width changed. */
15446 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15447 compute_window_start_on_continuation_line (w
);
15449 w
->window_end_valid
= Qnil
;
15452 /* Some sanity checks. */
15453 CHECK_WINDOW_END (w
);
15454 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15456 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15459 /* If %c is in mode line, update it if needed. */
15460 if (!NILP (w
->column_number_displayed
)
15461 /* This alternative quickly identifies a common case
15462 where no change is needed. */
15463 && !(PT
== w
->last_point
15464 && w
->last_modified
>= MODIFF
15465 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
15466 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15467 update_mode_line
= 1;
15469 /* Count number of windows showing the selected buffer. An indirect
15470 buffer counts as its base buffer. */
15471 if (!just_this_one_p
)
15473 struct buffer
*current_base
, *window_base
;
15474 current_base
= current_buffer
;
15475 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15476 if (current_base
->base_buffer
)
15477 current_base
= current_base
->base_buffer
;
15478 if (window_base
->base_buffer
)
15479 window_base
= window_base
->base_buffer
;
15480 if (current_base
== window_base
)
15484 /* Point refers normally to the selected window. For any other
15485 window, set up appropriate value. */
15486 if (!EQ (window
, selected_window
))
15488 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15489 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15493 new_pt_byte
= BEGV_BYTE
;
15494 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15496 else if (new_pt
> (ZV
- 1))
15499 new_pt_byte
= ZV_BYTE
;
15500 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15503 /* We don't use SET_PT so that the point-motion hooks don't run. */
15504 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15507 /* If any of the character widths specified in the display table
15508 have changed, invalidate the width run cache. It's true that
15509 this may be a bit late to catch such changes, but the rest of
15510 redisplay goes (non-fatally) haywire when the display table is
15511 changed, so why should we worry about doing any better? */
15512 if (current_buffer
->width_run_cache
)
15514 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15516 if (! disptab_matches_widthtab (disptab
,
15517 XVECTOR (BVAR (current_buffer
, width_table
))))
15519 invalidate_region_cache (current_buffer
,
15520 current_buffer
->width_run_cache
,
15522 recompute_width_table (current_buffer
, disptab
);
15526 /* If window-start is screwed up, choose a new one. */
15527 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15530 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15532 /* If someone specified a new starting point but did not insist,
15533 check whether it can be used. */
15534 if (w
->optional_new_start
15535 && CHARPOS (startp
) >= BEGV
15536 && CHARPOS (startp
) <= ZV
)
15538 w
->optional_new_start
= 0;
15539 start_display (&it
, w
, startp
);
15540 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15541 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15542 if (IT_CHARPOS (it
) == PT
)
15543 w
->force_start
= 1;
15544 /* IT may overshoot PT if text at PT is invisible. */
15545 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15546 w
->force_start
= 1;
15551 /* Handle case where place to start displaying has been specified,
15552 unless the specified location is outside the accessible range. */
15553 if (w
->force_start
|| w
->frozen_window_start_p
)
15555 /* We set this later on if we have to adjust point. */
15558 w
->force_start
= 0;
15560 w
->window_end_valid
= Qnil
;
15562 /* Forget any recorded base line for line number display. */
15563 if (!buffer_unchanged_p
)
15564 w
->base_line_number
= Qnil
;
15566 /* Redisplay the mode line. Select the buffer properly for that.
15567 Also, run the hook window-scroll-functions
15568 because we have scrolled. */
15569 /* Note, we do this after clearing force_start because
15570 if there's an error, it is better to forget about force_start
15571 than to get into an infinite loop calling the hook functions
15572 and having them get more errors. */
15573 if (!update_mode_line
15574 || ! NILP (Vwindow_scroll_functions
))
15576 update_mode_line
= 1;
15577 w
->update_mode_line
= 1;
15578 startp
= run_window_scroll_functions (window
, startp
);
15581 w
->last_modified
= 0;
15582 w
->last_overlay_modified
= 0;
15583 if (CHARPOS (startp
) < BEGV
)
15584 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15585 else if (CHARPOS (startp
) > ZV
)
15586 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15588 /* Redisplay, then check if cursor has been set during the
15589 redisplay. Give up if new fonts were loaded. */
15590 /* We used to issue a CHECK_MARGINS argument to try_window here,
15591 but this causes scrolling to fail when point begins inside
15592 the scroll margin (bug#148) -- cyd */
15593 if (!try_window (window
, startp
, 0))
15595 w
->force_start
= 1;
15596 clear_glyph_matrix (w
->desired_matrix
);
15597 goto need_larger_matrices
;
15600 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15602 /* If point does not appear, try to move point so it does
15603 appear. The desired matrix has been built above, so we
15604 can use it here. */
15605 new_vpos
= window_box_height (w
) / 2;
15608 if (!cursor_row_fully_visible_p (w
, 0, 0))
15610 /* Point does appear, but on a line partly visible at end of window.
15611 Move it back to a fully-visible line. */
15612 new_vpos
= window_box_height (w
);
15615 /* If we need to move point for either of the above reasons,
15616 now actually do it. */
15619 struct glyph_row
*row
;
15621 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15622 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15625 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15626 MATRIX_ROW_START_BYTEPOS (row
));
15628 if (w
!= XWINDOW (selected_window
))
15629 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15630 else if (current_buffer
== old
)
15631 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15633 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15635 /* If we are highlighting the region, then we just changed
15636 the region, so redisplay to show it. */
15637 if (!NILP (Vtransient_mark_mode
)
15638 && !NILP (BVAR (current_buffer
, mark_active
)))
15640 clear_glyph_matrix (w
->desired_matrix
);
15641 if (!try_window (window
, startp
, 0))
15642 goto need_larger_matrices
;
15647 debug_method_add (w
, "forced window start");
15652 /* Handle case where text has not changed, only point, and it has
15653 not moved off the frame, and we are not retrying after hscroll.
15654 (current_matrix_up_to_date_p is nonzero when retrying.) */
15655 if (current_matrix_up_to_date_p
15656 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15657 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15661 case CURSOR_MOVEMENT_SUCCESS
:
15662 used_current_matrix_p
= 1;
15665 case CURSOR_MOVEMENT_MUST_SCROLL
:
15666 goto try_to_scroll
;
15672 /* If current starting point was originally the beginning of a line
15673 but no longer is, find a new starting point. */
15674 else if (w
->start_at_line_beg
15675 && !(CHARPOS (startp
) <= BEGV
15676 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15679 debug_method_add (w
, "recenter 1");
15684 /* Try scrolling with try_window_id. Value is > 0 if update has
15685 been done, it is -1 if we know that the same window start will
15686 not work. It is 0 if unsuccessful for some other reason. */
15687 else if ((tem
= try_window_id (w
)) != 0)
15690 debug_method_add (w
, "try_window_id %d", tem
);
15693 if (fonts_changed_p
)
15694 goto need_larger_matrices
;
15698 /* Otherwise try_window_id has returned -1 which means that we
15699 don't want the alternative below this comment to execute. */
15701 else if (CHARPOS (startp
) >= BEGV
15702 && CHARPOS (startp
) <= ZV
15703 && PT
>= CHARPOS (startp
)
15704 && (CHARPOS (startp
) < ZV
15705 /* Avoid starting at end of buffer. */
15706 || CHARPOS (startp
) == BEGV
15707 || (w
->last_modified
>= MODIFF
15708 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)))
15710 int d1
, d2
, d3
, d4
, d5
, d6
;
15712 /* If first window line is a continuation line, and window start
15713 is inside the modified region, but the first change is before
15714 current window start, we must select a new window start.
15716 However, if this is the result of a down-mouse event (e.g. by
15717 extending the mouse-drag-overlay), we don't want to select a
15718 new window start, since that would change the position under
15719 the mouse, resulting in an unwanted mouse-movement rather
15720 than a simple mouse-click. */
15721 if (!w
->start_at_line_beg
15722 && NILP (do_mouse_tracking
)
15723 && CHARPOS (startp
) > BEGV
15724 && CHARPOS (startp
) > BEG
+ beg_unchanged
15725 && CHARPOS (startp
) <= Z
- end_unchanged
15726 /* Even if w->start_at_line_beg is nil, a new window may
15727 start at a line_beg, since that's how set_buffer_window
15728 sets it. So, we need to check the return value of
15729 compute_window_start_on_continuation_line. (See also
15731 && XMARKER (w
->start
)->buffer
== current_buffer
15732 && compute_window_start_on_continuation_line (w
)
15733 /* It doesn't make sense to force the window start like we
15734 do at label force_start if it is already known that point
15735 will not be visible in the resulting window, because
15736 doing so will move point from its correct position
15737 instead of scrolling the window to bring point into view.
15739 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15741 w
->force_start
= 1;
15742 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15747 debug_method_add (w
, "same window start");
15750 /* Try to redisplay starting at same place as before.
15751 If point has not moved off frame, accept the results. */
15752 if (!current_matrix_up_to_date_p
15753 /* Don't use try_window_reusing_current_matrix in this case
15754 because a window scroll function can have changed the
15756 || !NILP (Vwindow_scroll_functions
)
15757 || MINI_WINDOW_P (w
)
15758 || !(used_current_matrix_p
15759 = try_window_reusing_current_matrix (w
)))
15761 IF_DEBUG (debug_method_add (w
, "1"));
15762 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15763 /* -1 means we need to scroll.
15764 0 means we need new matrices, but fonts_changed_p
15765 is set in that case, so we will detect it below. */
15766 goto try_to_scroll
;
15769 if (fonts_changed_p
)
15770 goto need_larger_matrices
;
15772 if (w
->cursor
.vpos
>= 0)
15774 if (!just_this_one_p
15775 || current_buffer
->clip_changed
15776 || BEG_UNCHANGED
< CHARPOS (startp
))
15777 /* Forget any recorded base line for line number display. */
15778 w
->base_line_number
= Qnil
;
15780 if (!cursor_row_fully_visible_p (w
, 1, 0))
15782 clear_glyph_matrix (w
->desired_matrix
);
15783 last_line_misfit
= 1;
15785 /* Drop through and scroll. */
15790 clear_glyph_matrix (w
->desired_matrix
);
15795 w
->last_modified
= 0;
15796 w
->last_overlay_modified
= 0;
15798 /* Redisplay the mode line. Select the buffer properly for that. */
15799 if (!update_mode_line
)
15801 update_mode_line
= 1;
15802 w
->update_mode_line
= 1;
15805 /* Try to scroll by specified few lines. */
15806 if ((scroll_conservatively
15807 || emacs_scroll_step
15808 || temp_scroll_step
15809 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15810 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15811 && CHARPOS (startp
) >= BEGV
15812 && CHARPOS (startp
) <= ZV
)
15814 /* The function returns -1 if new fonts were loaded, 1 if
15815 successful, 0 if not successful. */
15816 int ss
= try_scrolling (window
, just_this_one_p
,
15817 scroll_conservatively
,
15819 temp_scroll_step
, last_line_misfit
);
15822 case SCROLLING_SUCCESS
:
15825 case SCROLLING_NEED_LARGER_MATRICES
:
15826 goto need_larger_matrices
;
15828 case SCROLLING_FAILED
:
15836 /* Finally, just choose a place to start which positions point
15837 according to user preferences. */
15842 debug_method_add (w
, "recenter");
15845 /* w->vscroll = 0; */
15847 /* Forget any previously recorded base line for line number display. */
15848 if (!buffer_unchanged_p
)
15849 w
->base_line_number
= Qnil
;
15851 /* Determine the window start relative to point. */
15852 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15853 it
.current_y
= it
.last_visible_y
;
15854 if (centering_position
< 0)
15858 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15860 ptrdiff_t margin_pos
= CHARPOS (startp
);
15861 Lisp_Object aggressive
;
15864 /* If there is a scroll margin at the top of the window, find
15865 its character position. */
15867 /* Cannot call start_display if startp is not in the
15868 accessible region of the buffer. This can happen when we
15869 have just switched to a different buffer and/or changed
15870 its restriction. In that case, startp is initialized to
15871 the character position 1 (BEGV) because we did not yet
15872 have chance to display the buffer even once. */
15873 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15876 void *it1data
= NULL
;
15878 SAVE_IT (it1
, it
, it1data
);
15879 start_display (&it1
, w
, startp
);
15880 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15881 margin_pos
= IT_CHARPOS (it1
);
15882 RESTORE_IT (&it
, &it
, it1data
);
15884 scrolling_up
= PT
> margin_pos
;
15887 ? BVAR (current_buffer
, scroll_up_aggressively
)
15888 : BVAR (current_buffer
, scroll_down_aggressively
);
15890 if (!MINI_WINDOW_P (w
)
15891 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15895 /* Setting scroll-conservatively overrides
15896 scroll-*-aggressively. */
15897 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15899 double float_amount
= XFLOATINT (aggressive
);
15901 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15902 if (pt_offset
== 0 && float_amount
> 0)
15904 if (pt_offset
&& margin
> 0)
15907 /* Compute how much to move the window start backward from
15908 point so that point will be displayed where the user
15912 centering_position
= it
.last_visible_y
;
15914 centering_position
-= pt_offset
;
15915 centering_position
-=
15916 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15917 + WINDOW_HEADER_LINE_HEIGHT (w
);
15918 /* Don't let point enter the scroll margin near top of
15920 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15921 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15924 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15927 /* Set the window start half the height of the window backward
15929 centering_position
= window_box_height (w
) / 2;
15931 move_it_vertically_backward (&it
, centering_position
);
15933 eassert (IT_CHARPOS (it
) >= BEGV
);
15935 /* The function move_it_vertically_backward may move over more
15936 than the specified y-distance. If it->w is small, e.g. a
15937 mini-buffer window, we may end up in front of the window's
15938 display area. Start displaying at the start of the line
15939 containing PT in this case. */
15940 if (it
.current_y
<= 0)
15942 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15943 move_it_vertically_backward (&it
, 0);
15947 it
.current_x
= it
.hpos
= 0;
15949 /* Set the window start position here explicitly, to avoid an
15950 infinite loop in case the functions in window-scroll-functions
15952 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15954 /* Run scroll hooks. */
15955 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15957 /* Redisplay the window. */
15958 if (!current_matrix_up_to_date_p
15959 || windows_or_buffers_changed
15960 || cursor_type_changed
15961 /* Don't use try_window_reusing_current_matrix in this case
15962 because it can have changed the buffer. */
15963 || !NILP (Vwindow_scroll_functions
)
15964 || !just_this_one_p
15965 || MINI_WINDOW_P (w
)
15966 || !(used_current_matrix_p
15967 = try_window_reusing_current_matrix (w
)))
15968 try_window (window
, startp
, 0);
15970 /* If new fonts have been loaded (due to fontsets), give up. We
15971 have to start a new redisplay since we need to re-adjust glyph
15973 if (fonts_changed_p
)
15974 goto need_larger_matrices
;
15976 /* If cursor did not appear assume that the middle of the window is
15977 in the first line of the window. Do it again with the next line.
15978 (Imagine a window of height 100, displaying two lines of height
15979 60. Moving back 50 from it->last_visible_y will end in the first
15981 if (w
->cursor
.vpos
< 0)
15983 if (!NILP (w
->window_end_valid
)
15984 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15986 clear_glyph_matrix (w
->desired_matrix
);
15987 move_it_by_lines (&it
, 1);
15988 try_window (window
, it
.current
.pos
, 0);
15990 else if (PT
< IT_CHARPOS (it
))
15992 clear_glyph_matrix (w
->desired_matrix
);
15993 move_it_by_lines (&it
, -1);
15994 try_window (window
, it
.current
.pos
, 0);
15998 /* Not much we can do about it. */
16002 /* Consider the following case: Window starts at BEGV, there is
16003 invisible, intangible text at BEGV, so that display starts at
16004 some point START > BEGV. It can happen that we are called with
16005 PT somewhere between BEGV and START. Try to handle that case. */
16006 if (w
->cursor
.vpos
< 0)
16008 struct glyph_row
*row
= w
->current_matrix
->rows
;
16009 if (row
->mode_line_p
)
16011 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16014 if (!cursor_row_fully_visible_p (w
, 0, 0))
16016 /* If vscroll is enabled, disable it and try again. */
16020 clear_glyph_matrix (w
->desired_matrix
);
16024 /* Users who set scroll-conservatively to a large number want
16025 point just above/below the scroll margin. If we ended up
16026 with point's row partially visible, move the window start to
16027 make that row fully visible and out of the margin. */
16028 if (scroll_conservatively
> SCROLL_LIMIT
)
16032 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16034 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16036 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16037 clear_glyph_matrix (w
->desired_matrix
);
16038 if (1 == try_window (window
, it
.current
.pos
,
16039 TRY_WINDOW_CHECK_MARGINS
))
16043 /* If centering point failed to make the whole line visible,
16044 put point at the top instead. That has to make the whole line
16045 visible, if it can be done. */
16046 if (centering_position
== 0)
16049 clear_glyph_matrix (w
->desired_matrix
);
16050 centering_position
= 0;
16056 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16057 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16058 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16060 /* Display the mode line, if we must. */
16061 if ((update_mode_line
16062 /* If window not full width, must redo its mode line
16063 if (a) the window to its side is being redone and
16064 (b) we do a frame-based redisplay. This is a consequence
16065 of how inverted lines are drawn in frame-based redisplay. */
16066 || (!just_this_one_p
16067 && !FRAME_WINDOW_P (f
)
16068 && !WINDOW_FULL_WIDTH_P (w
))
16069 /* Line number to display. */
16070 || INTEGERP (w
->base_line_pos
)
16071 /* Column number is displayed and different from the one displayed. */
16072 || (!NILP (w
->column_number_displayed
)
16073 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16074 /* This means that the window has a mode line. */
16075 && (WINDOW_WANTS_MODELINE_P (w
)
16076 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16078 display_mode_lines (w
);
16080 /* If mode line height has changed, arrange for a thorough
16081 immediate redisplay using the correct mode line height. */
16082 if (WINDOW_WANTS_MODELINE_P (w
)
16083 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16085 fonts_changed_p
= 1;
16086 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16087 = DESIRED_MODE_LINE_HEIGHT (w
);
16090 /* If header line height has changed, arrange for a thorough
16091 immediate redisplay using the correct header line height. */
16092 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16093 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16095 fonts_changed_p
= 1;
16096 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16097 = DESIRED_HEADER_LINE_HEIGHT (w
);
16100 if (fonts_changed_p
)
16101 goto need_larger_matrices
;
16104 if (!line_number_displayed
16105 && !BUFFERP (w
->base_line_pos
))
16107 w
->base_line_pos
= Qnil
;
16108 w
->base_line_number
= Qnil
;
16113 /* When we reach a frame's selected window, redo the frame's menu bar. */
16114 if (update_mode_line
16115 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16117 int redisplay_menu_p
= 0;
16119 if (FRAME_WINDOW_P (f
))
16121 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16122 || defined (HAVE_NS) || defined (USE_GTK)
16123 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16125 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16129 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16131 if (redisplay_menu_p
)
16132 display_menu_bar (w
);
16134 #ifdef HAVE_WINDOW_SYSTEM
16135 if (FRAME_WINDOW_P (f
))
16137 #if defined (USE_GTK) || defined (HAVE_NS)
16138 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16139 redisplay_tool_bar (f
);
16141 if (WINDOWP (f
->tool_bar_window
)
16142 && (FRAME_TOOL_BAR_LINES (f
) > 0
16143 || !NILP (Vauto_resize_tool_bars
))
16144 && redisplay_tool_bar (f
))
16145 ignore_mouse_drag_p
= 1;
16151 #ifdef HAVE_WINDOW_SYSTEM
16152 if (FRAME_WINDOW_P (f
)
16153 && update_window_fringes (w
, (just_this_one_p
16154 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16155 || w
->pseudo_window_p
)))
16159 if (draw_window_fringes (w
, 1))
16160 x_draw_vertical_border (w
);
16164 #endif /* HAVE_WINDOW_SYSTEM */
16166 /* We go to this label, with fonts_changed_p nonzero,
16167 if it is necessary to try again using larger glyph matrices.
16168 We have to redeem the scroll bar even in this case,
16169 because the loop in redisplay_internal expects that. */
16170 need_larger_matrices
:
16172 finish_scroll_bars
:
16174 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16176 /* Set the thumb's position and size. */
16177 set_vertical_scroll_bar (w
);
16179 /* Note that we actually used the scroll bar attached to this
16180 window, so it shouldn't be deleted at the end of redisplay. */
16181 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16182 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16185 /* Restore current_buffer and value of point in it. The window
16186 update may have changed the buffer, so first make sure `opoint'
16187 is still valid (Bug#6177). */
16188 if (CHARPOS (opoint
) < BEGV
)
16189 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16190 else if (CHARPOS (opoint
) > ZV
)
16191 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16193 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16195 set_buffer_internal_1 (old
);
16196 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16197 shorter. This can be caused by log truncation in *Messages*. */
16198 if (CHARPOS (lpoint
) <= ZV
)
16199 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16201 unbind_to (count
, Qnil
);
16205 /* Build the complete desired matrix of WINDOW with a window start
16206 buffer position POS.
16208 Value is 1 if successful. It is zero if fonts were loaded during
16209 redisplay which makes re-adjusting glyph matrices necessary, and -1
16210 if point would appear in the scroll margins.
16211 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16212 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16216 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16218 struct window
*w
= XWINDOW (window
);
16220 struct glyph_row
*last_text_row
= NULL
;
16221 struct frame
*f
= XFRAME (w
->frame
);
16223 /* Make POS the new window start. */
16224 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16226 /* Mark cursor position as unknown. No overlay arrow seen. */
16227 w
->cursor
.vpos
= -1;
16228 overlay_arrow_seen
= 0;
16230 /* Initialize iterator and info to start at POS. */
16231 start_display (&it
, w
, pos
);
16233 /* Display all lines of W. */
16234 while (it
.current_y
< it
.last_visible_y
)
16236 if (display_line (&it
))
16237 last_text_row
= it
.glyph_row
- 1;
16238 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16242 /* Don't let the cursor end in the scroll margins. */
16243 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16244 && !MINI_WINDOW_P (w
))
16246 int this_scroll_margin
;
16248 if (scroll_margin
> 0)
16250 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16251 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16254 this_scroll_margin
= 0;
16256 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16257 && w
->cursor
.y
< this_scroll_margin
16258 && CHARPOS (pos
) > BEGV
16259 && IT_CHARPOS (it
) < ZV
)
16260 /* rms: considering make_cursor_line_fully_visible_p here
16261 seems to give wrong results. We don't want to recenter
16262 when the last line is partly visible, we want to allow
16263 that case to be handled in the usual way. */
16264 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16266 w
->cursor
.vpos
= -1;
16267 clear_glyph_matrix (w
->desired_matrix
);
16272 /* If bottom moved off end of frame, change mode line percentage. */
16273 if (XFASTINT (w
->window_end_pos
) <= 0
16274 && Z
!= IT_CHARPOS (it
))
16275 w
->update_mode_line
= 1;
16277 /* Set window_end_pos to the offset of the last character displayed
16278 on the window from the end of current_buffer. Set
16279 window_end_vpos to its row number. */
16282 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16283 w
->window_end_bytepos
16284 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16286 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16288 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16289 eassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16290 ->displays_text_p
);
16294 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16295 w
->window_end_pos
= make_number (Z
- ZV
);
16296 w
->window_end_vpos
= make_number (0);
16299 /* But that is not valid info until redisplay finishes. */
16300 w
->window_end_valid
= Qnil
;
16306 /************************************************************************
16307 Window redisplay reusing current matrix when buffer has not changed
16308 ************************************************************************/
16310 /* Try redisplay of window W showing an unchanged buffer with a
16311 different window start than the last time it was displayed by
16312 reusing its current matrix. Value is non-zero if successful.
16313 W->start is the new window start. */
16316 try_window_reusing_current_matrix (struct window
*w
)
16318 struct frame
*f
= XFRAME (w
->frame
);
16319 struct glyph_row
*bottom_row
;
16322 struct text_pos start
, new_start
;
16323 int nrows_scrolled
, i
;
16324 struct glyph_row
*last_text_row
;
16325 struct glyph_row
*last_reused_text_row
;
16326 struct glyph_row
*start_row
;
16327 int start_vpos
, min_y
, max_y
;
16330 if (inhibit_try_window_reusing
)
16334 if (/* This function doesn't handle terminal frames. */
16335 !FRAME_WINDOW_P (f
)
16336 /* Don't try to reuse the display if windows have been split
16338 || windows_or_buffers_changed
16339 || cursor_type_changed
)
16342 /* Can't do this if region may have changed. */
16343 if ((!NILP (Vtransient_mark_mode
)
16344 && !NILP (BVAR (current_buffer
, mark_active
)))
16345 || !NILP (w
->region_showing
)
16346 || !NILP (Vshow_trailing_whitespace
))
16349 /* If top-line visibility has changed, give up. */
16350 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16351 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16354 /* Give up if old or new display is scrolled vertically. We could
16355 make this function handle this, but right now it doesn't. */
16356 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16357 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16360 /* The variable new_start now holds the new window start. The old
16361 start `start' can be determined from the current matrix. */
16362 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16363 start
= start_row
->minpos
;
16364 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16366 /* Clear the desired matrix for the display below. */
16367 clear_glyph_matrix (w
->desired_matrix
);
16369 if (CHARPOS (new_start
) <= CHARPOS (start
))
16371 /* Don't use this method if the display starts with an ellipsis
16372 displayed for invisible text. It's not easy to handle that case
16373 below, and it's certainly not worth the effort since this is
16374 not a frequent case. */
16375 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16378 IF_DEBUG (debug_method_add (w
, "twu1"));
16380 /* Display up to a row that can be reused. The variable
16381 last_text_row is set to the last row displayed that displays
16382 text. Note that it.vpos == 0 if or if not there is a
16383 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16384 start_display (&it
, w
, new_start
);
16385 w
->cursor
.vpos
= -1;
16386 last_text_row
= last_reused_text_row
= NULL
;
16388 while (it
.current_y
< it
.last_visible_y
16389 && !fonts_changed_p
)
16391 /* If we have reached into the characters in the START row,
16392 that means the line boundaries have changed. So we
16393 can't start copying with the row START. Maybe it will
16394 work to start copying with the following row. */
16395 while (IT_CHARPOS (it
) > CHARPOS (start
))
16397 /* Advance to the next row as the "start". */
16399 start
= start_row
->minpos
;
16400 /* If there are no more rows to try, or just one, give up. */
16401 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16402 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16403 || CHARPOS (start
) == ZV
)
16405 clear_glyph_matrix (w
->desired_matrix
);
16409 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16411 /* If we have reached alignment, we can copy the rest of the
16413 if (IT_CHARPOS (it
) == CHARPOS (start
)
16414 /* Don't accept "alignment" inside a display vector,
16415 since start_row could have started in the middle of
16416 that same display vector (thus their character
16417 positions match), and we have no way of telling if
16418 that is the case. */
16419 && it
.current
.dpvec_index
< 0)
16422 if (display_line (&it
))
16423 last_text_row
= it
.glyph_row
- 1;
16427 /* A value of current_y < last_visible_y means that we stopped
16428 at the previous window start, which in turn means that we
16429 have at least one reusable row. */
16430 if (it
.current_y
< it
.last_visible_y
)
16432 struct glyph_row
*row
;
16434 /* IT.vpos always starts from 0; it counts text lines. */
16435 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16437 /* Find PT if not already found in the lines displayed. */
16438 if (w
->cursor
.vpos
< 0)
16440 int dy
= it
.current_y
- start_row
->y
;
16442 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16443 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16445 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16446 dy
, nrows_scrolled
);
16449 clear_glyph_matrix (w
->desired_matrix
);
16454 /* Scroll the display. Do it before the current matrix is
16455 changed. The problem here is that update has not yet
16456 run, i.e. part of the current matrix is not up to date.
16457 scroll_run_hook will clear the cursor, and use the
16458 current matrix to get the height of the row the cursor is
16460 run
.current_y
= start_row
->y
;
16461 run
.desired_y
= it
.current_y
;
16462 run
.height
= it
.last_visible_y
- it
.current_y
;
16464 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16467 FRAME_RIF (f
)->update_window_begin_hook (w
);
16468 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16469 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16470 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16474 /* Shift current matrix down by nrows_scrolled lines. */
16475 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16476 rotate_matrix (w
->current_matrix
,
16478 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16481 /* Disable lines that must be updated. */
16482 for (i
= 0; i
< nrows_scrolled
; ++i
)
16483 (start_row
+ i
)->enabled_p
= 0;
16485 /* Re-compute Y positions. */
16486 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16487 max_y
= it
.last_visible_y
;
16488 for (row
= start_row
+ nrows_scrolled
;
16492 row
->y
= it
.current_y
;
16493 row
->visible_height
= row
->height
;
16495 if (row
->y
< min_y
)
16496 row
->visible_height
-= min_y
- row
->y
;
16497 if (row
->y
+ row
->height
> max_y
)
16498 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16499 if (row
->fringe_bitmap_periodic_p
)
16500 row
->redraw_fringe_bitmaps_p
= 1;
16502 it
.current_y
+= row
->height
;
16504 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16505 last_reused_text_row
= row
;
16506 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16510 /* Disable lines in the current matrix which are now
16511 below the window. */
16512 for (++row
; row
< bottom_row
; ++row
)
16513 row
->enabled_p
= row
->mode_line_p
= 0;
16516 /* Update window_end_pos etc.; last_reused_text_row is the last
16517 reused row from the current matrix containing text, if any.
16518 The value of last_text_row is the last displayed line
16519 containing text. */
16520 if (last_reused_text_row
)
16522 w
->window_end_bytepos
16523 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16525 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16527 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16528 w
->current_matrix
));
16530 else if (last_text_row
)
16532 w
->window_end_bytepos
16533 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16535 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16537 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16541 /* This window must be completely empty. */
16542 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16543 w
->window_end_pos
= make_number (Z
- ZV
);
16544 w
->window_end_vpos
= make_number (0);
16546 w
->window_end_valid
= Qnil
;
16548 /* Update hint: don't try scrolling again in update_window. */
16549 w
->desired_matrix
->no_scrolling_p
= 1;
16552 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16556 else if (CHARPOS (new_start
) > CHARPOS (start
))
16558 struct glyph_row
*pt_row
, *row
;
16559 struct glyph_row
*first_reusable_row
;
16560 struct glyph_row
*first_row_to_display
;
16562 int yb
= window_text_bottom_y (w
);
16564 /* Find the row starting at new_start, if there is one. Don't
16565 reuse a partially visible line at the end. */
16566 first_reusable_row
= start_row
;
16567 while (first_reusable_row
->enabled_p
16568 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16569 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16570 < CHARPOS (new_start
)))
16571 ++first_reusable_row
;
16573 /* Give up if there is no row to reuse. */
16574 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16575 || !first_reusable_row
->enabled_p
16576 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16577 != CHARPOS (new_start
)))
16580 /* We can reuse fully visible rows beginning with
16581 first_reusable_row to the end of the window. Set
16582 first_row_to_display to the first row that cannot be reused.
16583 Set pt_row to the row containing point, if there is any. */
16585 for (first_row_to_display
= first_reusable_row
;
16586 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16587 ++first_row_to_display
)
16589 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16590 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16591 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16592 && first_row_to_display
->ends_at_zv_p
16593 && pt_row
== NULL
)))
16594 pt_row
= first_row_to_display
;
16597 /* Start displaying at the start of first_row_to_display. */
16598 eassert (first_row_to_display
->y
< yb
);
16599 init_to_row_start (&it
, w
, first_row_to_display
);
16601 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16603 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16605 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16606 + WINDOW_HEADER_LINE_HEIGHT (w
));
16608 /* Display lines beginning with first_row_to_display in the
16609 desired matrix. Set last_text_row to the last row displayed
16610 that displays text. */
16611 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16612 if (pt_row
== NULL
)
16613 w
->cursor
.vpos
= -1;
16614 last_text_row
= NULL
;
16615 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16616 if (display_line (&it
))
16617 last_text_row
= it
.glyph_row
- 1;
16619 /* If point is in a reused row, adjust y and vpos of the cursor
16623 w
->cursor
.vpos
-= nrows_scrolled
;
16624 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16627 /* Give up if point isn't in a row displayed or reused. (This
16628 also handles the case where w->cursor.vpos < nrows_scrolled
16629 after the calls to display_line, which can happen with scroll
16630 margins. See bug#1295.) */
16631 if (w
->cursor
.vpos
< 0)
16633 clear_glyph_matrix (w
->desired_matrix
);
16637 /* Scroll the display. */
16638 run
.current_y
= first_reusable_row
->y
;
16639 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16640 run
.height
= it
.last_visible_y
- run
.current_y
;
16641 dy
= run
.current_y
- run
.desired_y
;
16646 FRAME_RIF (f
)->update_window_begin_hook (w
);
16647 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16648 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16649 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16653 /* Adjust Y positions of reused rows. */
16654 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16655 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16656 max_y
= it
.last_visible_y
;
16657 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16660 row
->visible_height
= row
->height
;
16661 if (row
->y
< min_y
)
16662 row
->visible_height
-= min_y
- row
->y
;
16663 if (row
->y
+ row
->height
> max_y
)
16664 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16665 if (row
->fringe_bitmap_periodic_p
)
16666 row
->redraw_fringe_bitmaps_p
= 1;
16669 /* Scroll the current matrix. */
16670 eassert (nrows_scrolled
> 0);
16671 rotate_matrix (w
->current_matrix
,
16673 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16676 /* Disable rows not reused. */
16677 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16678 row
->enabled_p
= 0;
16680 /* Point may have moved to a different line, so we cannot assume that
16681 the previous cursor position is valid; locate the correct row. */
16684 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16686 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16687 && !row
->ends_at_zv_p
;
16691 w
->cursor
.y
= row
->y
;
16693 if (row
< bottom_row
)
16695 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16696 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16698 /* Can't use this optimization with bidi-reordered glyph
16699 rows, unless cursor is already at point. */
16700 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16702 if (!(w
->cursor
.hpos
>= 0
16703 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16704 && BUFFERP (glyph
->object
)
16705 && glyph
->charpos
== PT
))
16710 && (!BUFFERP (glyph
->object
)
16711 || glyph
->charpos
< PT
);
16715 w
->cursor
.x
+= glyph
->pixel_width
;
16720 /* Adjust window end. A null value of last_text_row means that
16721 the window end is in reused rows which in turn means that
16722 only its vpos can have changed. */
16725 w
->window_end_bytepos
16726 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16728 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16730 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16735 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16738 w
->window_end_valid
= Qnil
;
16739 w
->desired_matrix
->no_scrolling_p
= 1;
16742 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16752 /************************************************************************
16753 Window redisplay reusing current matrix when buffer has changed
16754 ************************************************************************/
16756 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16757 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16758 ptrdiff_t *, ptrdiff_t *);
16759 static struct glyph_row
*
16760 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16761 struct glyph_row
*);
16764 /* Return the last row in MATRIX displaying text. If row START is
16765 non-null, start searching with that row. IT gives the dimensions
16766 of the display. Value is null if matrix is empty; otherwise it is
16767 a pointer to the row found. */
16769 static struct glyph_row
*
16770 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16771 struct glyph_row
*start
)
16773 struct glyph_row
*row
, *row_found
;
16775 /* Set row_found to the last row in IT->w's current matrix
16776 displaying text. The loop looks funny but think of partially
16779 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16780 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16782 eassert (row
->enabled_p
);
16784 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16793 /* Return the last row in the current matrix of W that is not affected
16794 by changes at the start of current_buffer that occurred since W's
16795 current matrix was built. Value is null if no such row exists.
16797 BEG_UNCHANGED us the number of characters unchanged at the start of
16798 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16799 first changed character in current_buffer. Characters at positions <
16800 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16801 when the current matrix was built. */
16803 static struct glyph_row
*
16804 find_last_unchanged_at_beg_row (struct window
*w
)
16806 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16807 struct glyph_row
*row
;
16808 struct glyph_row
*row_found
= NULL
;
16809 int yb
= window_text_bottom_y (w
);
16811 /* Find the last row displaying unchanged text. */
16812 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16813 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16814 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16817 if (/* If row ends before first_changed_pos, it is unchanged,
16818 except in some case. */
16819 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16820 /* When row ends in ZV and we write at ZV it is not
16822 && !row
->ends_at_zv_p
16823 /* When first_changed_pos is the end of a continued line,
16824 row is not unchanged because it may be no longer
16826 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16827 && (row
->continued_p
16828 || row
->exact_window_width_line_p
))
16829 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16830 needs to be recomputed, so don't consider this row as
16831 unchanged. This happens when the last line was
16832 bidi-reordered and was killed immediately before this
16833 redisplay cycle. In that case, ROW->end stores the
16834 buffer position of the first visual-order character of
16835 the killed text, which is now beyond ZV. */
16836 && CHARPOS (row
->end
.pos
) <= ZV
)
16839 /* Stop if last visible row. */
16840 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16848 /* Find the first glyph row in the current matrix of W that is not
16849 affected by changes at the end of current_buffer since the
16850 time W's current matrix was built.
16852 Return in *DELTA the number of chars by which buffer positions in
16853 unchanged text at the end of current_buffer must be adjusted.
16855 Return in *DELTA_BYTES the corresponding number of bytes.
16857 Value is null if no such row exists, i.e. all rows are affected by
16860 static struct glyph_row
*
16861 find_first_unchanged_at_end_row (struct window
*w
,
16862 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16864 struct glyph_row
*row
;
16865 struct glyph_row
*row_found
= NULL
;
16867 *delta
= *delta_bytes
= 0;
16869 /* Display must not have been paused, otherwise the current matrix
16870 is not up to date. */
16871 eassert (!NILP (w
->window_end_valid
));
16873 /* A value of window_end_pos >= END_UNCHANGED means that the window
16874 end is in the range of changed text. If so, there is no
16875 unchanged row at the end of W's current matrix. */
16876 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16879 /* Set row to the last row in W's current matrix displaying text. */
16880 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16882 /* If matrix is entirely empty, no unchanged row exists. */
16883 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16885 /* The value of row is the last glyph row in the matrix having a
16886 meaningful buffer position in it. The end position of row
16887 corresponds to window_end_pos. This allows us to translate
16888 buffer positions in the current matrix to current buffer
16889 positions for characters not in changed text. */
16891 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16892 ptrdiff_t Z_BYTE_old
=
16893 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16894 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16895 struct glyph_row
*first_text_row
16896 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16898 *delta
= Z
- Z_old
;
16899 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16901 /* Set last_unchanged_pos to the buffer position of the last
16902 character in the buffer that has not been changed. Z is the
16903 index + 1 of the last character in current_buffer, i.e. by
16904 subtracting END_UNCHANGED we get the index of the last
16905 unchanged character, and we have to add BEG to get its buffer
16907 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16908 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16910 /* Search backward from ROW for a row displaying a line that
16911 starts at a minimum position >= last_unchanged_pos_old. */
16912 for (; row
> first_text_row
; --row
)
16914 /* This used to abort, but it can happen.
16915 It is ok to just stop the search instead here. KFS. */
16916 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16919 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16924 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16930 /* Make sure that glyph rows in the current matrix of window W
16931 reference the same glyph memory as corresponding rows in the
16932 frame's frame matrix. This function is called after scrolling W's
16933 current matrix on a terminal frame in try_window_id and
16934 try_window_reusing_current_matrix. */
16937 sync_frame_with_window_matrix_rows (struct window
*w
)
16939 struct frame
*f
= XFRAME (w
->frame
);
16940 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16942 /* Preconditions: W must be a leaf window and full-width. Its frame
16943 must have a frame matrix. */
16944 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16945 eassert (WINDOW_FULL_WIDTH_P (w
));
16946 eassert (!FRAME_WINDOW_P (f
));
16948 /* If W is a full-width window, glyph pointers in W's current matrix
16949 have, by definition, to be the same as glyph pointers in the
16950 corresponding frame matrix. Note that frame matrices have no
16951 marginal areas (see build_frame_matrix). */
16952 window_row
= w
->current_matrix
->rows
;
16953 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16954 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16955 while (window_row
< window_row_end
)
16957 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16958 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16960 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16961 frame_row
->glyphs
[TEXT_AREA
] = start
;
16962 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16963 frame_row
->glyphs
[LAST_AREA
] = end
;
16965 /* Disable frame rows whose corresponding window rows have
16966 been disabled in try_window_id. */
16967 if (!window_row
->enabled_p
)
16968 frame_row
->enabled_p
= 0;
16970 ++window_row
, ++frame_row
;
16975 /* Find the glyph row in window W containing CHARPOS. Consider all
16976 rows between START and END (not inclusive). END null means search
16977 all rows to the end of the display area of W. Value is the row
16978 containing CHARPOS or null. */
16981 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16982 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16984 struct glyph_row
*row
= start
;
16985 struct glyph_row
*best_row
= NULL
;
16986 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16989 /* If we happen to start on a header-line, skip that. */
16990 if (row
->mode_line_p
)
16993 if ((end
&& row
>= end
) || !row
->enabled_p
)
16996 last_y
= window_text_bottom_y (w
) - dy
;
17000 /* Give up if we have gone too far. */
17001 if (end
&& row
>= end
)
17003 /* This formerly returned if they were equal.
17004 I think that both quantities are of a "last plus one" type;
17005 if so, when they are equal, the row is within the screen. -- rms. */
17006 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17009 /* If it is in this row, return this row. */
17010 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17011 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17012 /* The end position of a row equals the start
17013 position of the next row. If CHARPOS is there, we
17014 would rather display it in the next line, except
17015 when this line ends in ZV. */
17016 && !row
->ends_at_zv_p
17017 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17018 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17022 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17023 || (!best_row
&& !row
->continued_p
))
17025 /* In bidi-reordered rows, there could be several rows
17026 occluding point, all of them belonging to the same
17027 continued line. We need to find the row which fits
17028 CHARPOS the best. */
17029 for (g
= row
->glyphs
[TEXT_AREA
];
17030 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17033 if (!STRINGP (g
->object
))
17035 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17037 mindif
= eabs (g
->charpos
- charpos
);
17039 /* Exact match always wins. */
17046 else if (best_row
&& !row
->continued_p
)
17053 /* Try to redisplay window W by reusing its existing display. W's
17054 current matrix must be up to date when this function is called,
17055 i.e. window_end_valid must not be nil.
17059 1 if display has been updated
17060 0 if otherwise unsuccessful
17061 -1 if redisplay with same window start is known not to succeed
17063 The following steps are performed:
17065 1. Find the last row in the current matrix of W that is not
17066 affected by changes at the start of current_buffer. If no such row
17069 2. Find the first row in W's current matrix that is not affected by
17070 changes at the end of current_buffer. Maybe there is no such row.
17072 3. Display lines beginning with the row + 1 found in step 1 to the
17073 row found in step 2 or, if step 2 didn't find a row, to the end of
17076 4. If cursor is not known to appear on the window, give up.
17078 5. If display stopped at the row found in step 2, scroll the
17079 display and current matrix as needed.
17081 6. Maybe display some lines at the end of W, if we must. This can
17082 happen under various circumstances, like a partially visible line
17083 becoming fully visible, or because newly displayed lines are displayed
17084 in smaller font sizes.
17086 7. Update W's window end information. */
17089 try_window_id (struct window
*w
)
17091 struct frame
*f
= XFRAME (w
->frame
);
17092 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17093 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17094 struct glyph_row
*last_unchanged_at_beg_row
;
17095 struct glyph_row
*first_unchanged_at_end_row
;
17096 struct glyph_row
*row
;
17097 struct glyph_row
*bottom_row
;
17100 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17102 struct text_pos start_pos
;
17104 int first_unchanged_at_end_vpos
= 0;
17105 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17106 struct text_pos start
;
17107 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17110 if (inhibit_try_window_id
)
17114 /* This is handy for debugging. */
17116 #define GIVE_UP(X) \
17118 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17122 #define GIVE_UP(X) return 0
17125 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17127 /* Don't use this for mini-windows because these can show
17128 messages and mini-buffers, and we don't handle that here. */
17129 if (MINI_WINDOW_P (w
))
17132 /* This flag is used to prevent redisplay optimizations. */
17133 if (windows_or_buffers_changed
|| cursor_type_changed
)
17136 /* Verify that narrowing has not changed.
17137 Also verify that we were not told to prevent redisplay optimizations.
17138 It would be nice to further
17139 reduce the number of cases where this prevents try_window_id. */
17140 if (current_buffer
->clip_changed
17141 || current_buffer
->prevent_redisplay_optimizations_p
)
17144 /* Window must either use window-based redisplay or be full width. */
17145 if (!FRAME_WINDOW_P (f
)
17146 && (!FRAME_LINE_INS_DEL_OK (f
)
17147 || !WINDOW_FULL_WIDTH_P (w
)))
17150 /* Give up if point is known NOT to appear in W. */
17151 if (PT
< CHARPOS (start
))
17154 /* Another way to prevent redisplay optimizations. */
17155 if (w
->last_modified
== 0)
17158 /* Verify that window is not hscrolled. */
17159 if (w
->hscroll
!= 0)
17162 /* Verify that display wasn't paused. */
17163 if (NILP (w
->window_end_valid
))
17166 /* Can't use this if highlighting a region because a cursor movement
17167 will do more than just set the cursor. */
17168 if (!NILP (Vtransient_mark_mode
)
17169 && !NILP (BVAR (current_buffer
, mark_active
)))
17172 /* Likewise if highlighting trailing whitespace. */
17173 if (!NILP (Vshow_trailing_whitespace
))
17176 /* Likewise if showing a region. */
17177 if (!NILP (w
->region_showing
))
17180 /* Can't use this if overlay arrow position and/or string have
17182 if (overlay_arrows_changed_p ())
17185 /* When word-wrap is on, adding a space to the first word of a
17186 wrapped line can change the wrap position, altering the line
17187 above it. It might be worthwhile to handle this more
17188 intelligently, but for now just redisplay from scratch. */
17189 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17192 /* Under bidi reordering, adding or deleting a character in the
17193 beginning of a paragraph, before the first strong directional
17194 character, can change the base direction of the paragraph (unless
17195 the buffer specifies a fixed paragraph direction), which will
17196 require to redisplay the whole paragraph. It might be worthwhile
17197 to find the paragraph limits and widen the range of redisplayed
17198 lines to that, but for now just give up this optimization and
17199 redisplay from scratch. */
17200 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17201 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17204 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17205 only if buffer has really changed. The reason is that the gap is
17206 initially at Z for freshly visited files. The code below would
17207 set end_unchanged to 0 in that case. */
17208 if (MODIFF
> SAVE_MODIFF
17209 /* This seems to happen sometimes after saving a buffer. */
17210 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17212 if (GPT
- BEG
< BEG_UNCHANGED
)
17213 BEG_UNCHANGED
= GPT
- BEG
;
17214 if (Z
- GPT
< END_UNCHANGED
)
17215 END_UNCHANGED
= Z
- GPT
;
17218 /* The position of the first and last character that has been changed. */
17219 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17220 last_changed_charpos
= Z
- END_UNCHANGED
;
17222 /* If window starts after a line end, and the last change is in
17223 front of that newline, then changes don't affect the display.
17224 This case happens with stealth-fontification. Note that although
17225 the display is unchanged, glyph positions in the matrix have to
17226 be adjusted, of course. */
17227 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17228 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17229 && ((last_changed_charpos
< CHARPOS (start
)
17230 && CHARPOS (start
) == BEGV
)
17231 || (last_changed_charpos
< CHARPOS (start
) - 1
17232 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17234 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17235 struct glyph_row
*r0
;
17237 /* Compute how many chars/bytes have been added to or removed
17238 from the buffer. */
17239 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17240 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17241 Z_delta
= Z
- Z_old
;
17242 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17244 /* Give up if PT is not in the window. Note that it already has
17245 been checked at the start of try_window_id that PT is not in
17246 front of the window start. */
17247 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17250 /* If window start is unchanged, we can reuse the whole matrix
17251 as is, after adjusting glyph positions. No need to compute
17252 the window end again, since its offset from Z hasn't changed. */
17253 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17254 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17255 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17256 /* PT must not be in a partially visible line. */
17257 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17258 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17260 /* Adjust positions in the glyph matrix. */
17261 if (Z_delta
|| Z_delta_bytes
)
17263 struct glyph_row
*r1
17264 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17265 increment_matrix_positions (w
->current_matrix
,
17266 MATRIX_ROW_VPOS (r0
, current_matrix
),
17267 MATRIX_ROW_VPOS (r1
, current_matrix
),
17268 Z_delta
, Z_delta_bytes
);
17271 /* Set the cursor. */
17272 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17274 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17281 /* Handle the case that changes are all below what is displayed in
17282 the window, and that PT is in the window. This shortcut cannot
17283 be taken if ZV is visible in the window, and text has been added
17284 there that is visible in the window. */
17285 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17286 /* ZV is not visible in the window, or there are no
17287 changes at ZV, actually. */
17288 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17289 || first_changed_charpos
== last_changed_charpos
))
17291 struct glyph_row
*r0
;
17293 /* Give up if PT is not in the window. Note that it already has
17294 been checked at the start of try_window_id that PT is not in
17295 front of the window start. */
17296 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17299 /* If window start is unchanged, we can reuse the whole matrix
17300 as is, without changing glyph positions since no text has
17301 been added/removed in front of the window end. */
17302 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17303 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17304 /* PT must not be in a partially visible line. */
17305 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17306 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17308 /* We have to compute the window end anew since text
17309 could have been added/removed after it. */
17311 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17312 w
->window_end_bytepos
17313 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17315 /* Set the cursor. */
17316 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17318 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17325 /* Give up if window start is in the changed area.
17327 The condition used to read
17329 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17331 but why that was tested escapes me at the moment. */
17332 if (CHARPOS (start
) >= first_changed_charpos
17333 && CHARPOS (start
) <= last_changed_charpos
)
17336 /* Check that window start agrees with the start of the first glyph
17337 row in its current matrix. Check this after we know the window
17338 start is not in changed text, otherwise positions would not be
17340 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17341 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17344 /* Give up if the window ends in strings. Overlay strings
17345 at the end are difficult to handle, so don't try. */
17346 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17347 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17350 /* Compute the position at which we have to start displaying new
17351 lines. Some of the lines at the top of the window might be
17352 reusable because they are not displaying changed text. Find the
17353 last row in W's current matrix not affected by changes at the
17354 start of current_buffer. Value is null if changes start in the
17355 first line of window. */
17356 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17357 if (last_unchanged_at_beg_row
)
17359 /* Avoid starting to display in the middle of a character, a TAB
17360 for instance. This is easier than to set up the iterator
17361 exactly, and it's not a frequent case, so the additional
17362 effort wouldn't really pay off. */
17363 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17364 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17365 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17366 --last_unchanged_at_beg_row
;
17368 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17371 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17373 start_pos
= it
.current
.pos
;
17375 /* Start displaying new lines in the desired matrix at the same
17376 vpos we would use in the current matrix, i.e. below
17377 last_unchanged_at_beg_row. */
17378 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17380 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17381 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17383 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17387 /* There are no reusable lines at the start of the window.
17388 Start displaying in the first text line. */
17389 start_display (&it
, w
, start
);
17390 it
.vpos
= it
.first_vpos
;
17391 start_pos
= it
.current
.pos
;
17394 /* Find the first row that is not affected by changes at the end of
17395 the buffer. Value will be null if there is no unchanged row, in
17396 which case we must redisplay to the end of the window. delta
17397 will be set to the value by which buffer positions beginning with
17398 first_unchanged_at_end_row have to be adjusted due to text
17400 first_unchanged_at_end_row
17401 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17402 IF_DEBUG (debug_delta
= delta
);
17403 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17405 /* Set stop_pos to the buffer position up to which we will have to
17406 display new lines. If first_unchanged_at_end_row != NULL, this
17407 is the buffer position of the start of the line displayed in that
17408 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17409 that we don't stop at a buffer position. */
17411 if (first_unchanged_at_end_row
)
17413 eassert (last_unchanged_at_beg_row
== NULL
17414 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17416 /* If this is a continuation line, move forward to the next one
17417 that isn't. Changes in lines above affect this line.
17418 Caution: this may move first_unchanged_at_end_row to a row
17419 not displaying text. */
17420 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17421 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17422 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17423 < it
.last_visible_y
))
17424 ++first_unchanged_at_end_row
;
17426 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17427 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17428 >= it
.last_visible_y
))
17429 first_unchanged_at_end_row
= NULL
;
17432 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17434 first_unchanged_at_end_vpos
17435 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17436 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17439 else if (last_unchanged_at_beg_row
== NULL
)
17445 /* Either there is no unchanged row at the end, or the one we have
17446 now displays text. This is a necessary condition for the window
17447 end pos calculation at the end of this function. */
17448 eassert (first_unchanged_at_end_row
== NULL
17449 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17451 debug_last_unchanged_at_beg_vpos
17452 = (last_unchanged_at_beg_row
17453 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17455 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17457 #endif /* GLYPH_DEBUG */
17460 /* Display new lines. Set last_text_row to the last new line
17461 displayed which has text on it, i.e. might end up as being the
17462 line where the window_end_vpos is. */
17463 w
->cursor
.vpos
= -1;
17464 last_text_row
= NULL
;
17465 overlay_arrow_seen
= 0;
17466 while (it
.current_y
< it
.last_visible_y
17467 && !fonts_changed_p
17468 && (first_unchanged_at_end_row
== NULL
17469 || IT_CHARPOS (it
) < stop_pos
))
17471 if (display_line (&it
))
17472 last_text_row
= it
.glyph_row
- 1;
17475 if (fonts_changed_p
)
17479 /* Compute differences in buffer positions, y-positions etc. for
17480 lines reused at the bottom of the window. Compute what we can
17482 if (first_unchanged_at_end_row
17483 /* No lines reused because we displayed everything up to the
17484 bottom of the window. */
17485 && it
.current_y
< it
.last_visible_y
)
17488 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17490 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17491 run
.current_y
= first_unchanged_at_end_row
->y
;
17492 run
.desired_y
= run
.current_y
+ dy
;
17493 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17497 delta
= delta_bytes
= dvpos
= dy
17498 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17499 first_unchanged_at_end_row
= NULL
;
17501 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17504 /* Find the cursor if not already found. We have to decide whether
17505 PT will appear on this window (it sometimes doesn't, but this is
17506 not a very frequent case.) This decision has to be made before
17507 the current matrix is altered. A value of cursor.vpos < 0 means
17508 that PT is either in one of the lines beginning at
17509 first_unchanged_at_end_row or below the window. Don't care for
17510 lines that might be displayed later at the window end; as
17511 mentioned, this is not a frequent case. */
17512 if (w
->cursor
.vpos
< 0)
17514 /* Cursor in unchanged rows at the top? */
17515 if (PT
< CHARPOS (start_pos
)
17516 && last_unchanged_at_beg_row
)
17518 row
= row_containing_pos (w
, PT
,
17519 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17520 last_unchanged_at_beg_row
+ 1, 0);
17522 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17525 /* Start from first_unchanged_at_end_row looking for PT. */
17526 else if (first_unchanged_at_end_row
)
17528 row
= row_containing_pos (w
, PT
- delta
,
17529 first_unchanged_at_end_row
, NULL
, 0);
17531 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17532 delta_bytes
, dy
, dvpos
);
17535 /* Give up if cursor was not found. */
17536 if (w
->cursor
.vpos
< 0)
17538 clear_glyph_matrix (w
->desired_matrix
);
17543 /* Don't let the cursor end in the scroll margins. */
17545 int this_scroll_margin
, cursor_height
;
17547 this_scroll_margin
=
17548 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17549 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17550 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17552 if ((w
->cursor
.y
< this_scroll_margin
17553 && CHARPOS (start
) > BEGV
)
17554 /* Old redisplay didn't take scroll margin into account at the bottom,
17555 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17556 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17557 ? cursor_height
+ this_scroll_margin
17558 : 1)) > it
.last_visible_y
)
17560 w
->cursor
.vpos
= -1;
17561 clear_glyph_matrix (w
->desired_matrix
);
17566 /* Scroll the display. Do it before changing the current matrix so
17567 that xterm.c doesn't get confused about where the cursor glyph is
17569 if (dy
&& run
.height
)
17573 if (FRAME_WINDOW_P (f
))
17575 FRAME_RIF (f
)->update_window_begin_hook (w
);
17576 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17577 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17578 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17582 /* Terminal frame. In this case, dvpos gives the number of
17583 lines to scroll by; dvpos < 0 means scroll up. */
17585 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17586 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17587 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17588 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17589 + window_internal_height (w
));
17591 #if defined (HAVE_GPM) || defined (MSDOS)
17592 x_clear_window_mouse_face (w
);
17594 /* Perform the operation on the screen. */
17597 /* Scroll last_unchanged_at_beg_row to the end of the
17598 window down dvpos lines. */
17599 set_terminal_window (f
, end
);
17601 /* On dumb terminals delete dvpos lines at the end
17602 before inserting dvpos empty lines. */
17603 if (!FRAME_SCROLL_REGION_OK (f
))
17604 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17606 /* Insert dvpos empty lines in front of
17607 last_unchanged_at_beg_row. */
17608 ins_del_lines (f
, from
, dvpos
);
17610 else if (dvpos
< 0)
17612 /* Scroll up last_unchanged_at_beg_vpos to the end of
17613 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17614 set_terminal_window (f
, end
);
17616 /* Delete dvpos lines in front of
17617 last_unchanged_at_beg_vpos. ins_del_lines will set
17618 the cursor to the given vpos and emit |dvpos| delete
17620 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17622 /* On a dumb terminal insert dvpos empty lines at the
17624 if (!FRAME_SCROLL_REGION_OK (f
))
17625 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17628 set_terminal_window (f
, 0);
17634 /* Shift reused rows of the current matrix to the right position.
17635 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17637 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17638 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17641 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17642 bottom_vpos
, dvpos
);
17643 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17646 else if (dvpos
> 0)
17648 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17649 bottom_vpos
, dvpos
);
17650 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17651 first_unchanged_at_end_vpos
+ dvpos
, 0);
17654 /* For frame-based redisplay, make sure that current frame and window
17655 matrix are in sync with respect to glyph memory. */
17656 if (!FRAME_WINDOW_P (f
))
17657 sync_frame_with_window_matrix_rows (w
);
17659 /* Adjust buffer positions in reused rows. */
17660 if (delta
|| delta_bytes
)
17661 increment_matrix_positions (current_matrix
,
17662 first_unchanged_at_end_vpos
+ dvpos
,
17663 bottom_vpos
, delta
, delta_bytes
);
17665 /* Adjust Y positions. */
17667 shift_glyph_matrix (w
, current_matrix
,
17668 first_unchanged_at_end_vpos
+ dvpos
,
17671 if (first_unchanged_at_end_row
)
17673 first_unchanged_at_end_row
+= dvpos
;
17674 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17675 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17676 first_unchanged_at_end_row
= NULL
;
17679 /* If scrolling up, there may be some lines to display at the end of
17681 last_text_row_at_end
= NULL
;
17684 /* Scrolling up can leave for example a partially visible line
17685 at the end of the window to be redisplayed. */
17686 /* Set last_row to the glyph row in the current matrix where the
17687 window end line is found. It has been moved up or down in
17688 the matrix by dvpos. */
17689 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17690 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17692 /* If last_row is the window end line, it should display text. */
17693 eassert (last_row
->displays_text_p
);
17695 /* If window end line was partially visible before, begin
17696 displaying at that line. Otherwise begin displaying with the
17697 line following it. */
17698 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17700 init_to_row_start (&it
, w
, last_row
);
17701 it
.vpos
= last_vpos
;
17702 it
.current_y
= last_row
->y
;
17706 init_to_row_end (&it
, w
, last_row
);
17707 it
.vpos
= 1 + last_vpos
;
17708 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17712 /* We may start in a continuation line. If so, we have to
17713 get the right continuation_lines_width and current_x. */
17714 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17715 it
.hpos
= it
.current_x
= 0;
17717 /* Display the rest of the lines at the window end. */
17718 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17719 while (it
.current_y
< it
.last_visible_y
17720 && !fonts_changed_p
)
17722 /* Is it always sure that the display agrees with lines in
17723 the current matrix? I don't think so, so we mark rows
17724 displayed invalid in the current matrix by setting their
17725 enabled_p flag to zero. */
17726 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17727 if (display_line (&it
))
17728 last_text_row_at_end
= it
.glyph_row
- 1;
17732 /* Update window_end_pos and window_end_vpos. */
17733 if (first_unchanged_at_end_row
17734 && !last_text_row_at_end
)
17736 /* Window end line if one of the preserved rows from the current
17737 matrix. Set row to the last row displaying text in current
17738 matrix starting at first_unchanged_at_end_row, after
17740 eassert (first_unchanged_at_end_row
->displays_text_p
);
17741 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17742 first_unchanged_at_end_row
);
17743 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17745 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17746 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17748 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17749 eassert (w
->window_end_bytepos
>= 0);
17750 IF_DEBUG (debug_method_add (w
, "A"));
17752 else if (last_text_row_at_end
)
17755 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17756 w
->window_end_bytepos
17757 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17759 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17760 eassert (w
->window_end_bytepos
>= 0);
17761 IF_DEBUG (debug_method_add (w
, "B"));
17763 else if (last_text_row
)
17765 /* We have displayed either to the end of the window or at the
17766 end of the window, i.e. the last row with text is to be found
17767 in the desired matrix. */
17769 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17770 w
->window_end_bytepos
17771 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17773 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17774 eassert (w
->window_end_bytepos
>= 0);
17776 else if (first_unchanged_at_end_row
== NULL
17777 && last_text_row
== NULL
17778 && last_text_row_at_end
== NULL
)
17780 /* Displayed to end of window, but no line containing text was
17781 displayed. Lines were deleted at the end of the window. */
17782 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17783 int vpos
= XFASTINT (w
->window_end_vpos
);
17784 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17785 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17788 row
== NULL
&& vpos
>= first_vpos
;
17789 --vpos
, --current_row
, --desired_row
)
17791 if (desired_row
->enabled_p
)
17793 if (desired_row
->displays_text_p
)
17796 else if (current_row
->displays_text_p
)
17800 eassert (row
!= NULL
);
17801 w
->window_end_vpos
= make_number (vpos
+ 1);
17802 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17803 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17804 eassert (w
->window_end_bytepos
>= 0);
17805 IF_DEBUG (debug_method_add (w
, "C"));
17810 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17811 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17813 /* Record that display has not been completed. */
17814 w
->window_end_valid
= Qnil
;
17815 w
->desired_matrix
->no_scrolling_p
= 1;
17823 /***********************************************************************
17824 More debugging support
17825 ***********************************************************************/
17829 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17830 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17831 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17834 /* Dump the contents of glyph matrix MATRIX on stderr.
17836 GLYPHS 0 means don't show glyph contents.
17837 GLYPHS 1 means show glyphs in short form
17838 GLYPHS > 1 means show glyphs in long form. */
17841 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17844 for (i
= 0; i
< matrix
->nrows
; ++i
)
17845 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17849 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17850 the glyph row and area where the glyph comes from. */
17853 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17855 if (glyph
->type
== CHAR_GLYPH
)
17858 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17859 glyph
- row
->glyphs
[TEXT_AREA
],
17862 (BUFFERP (glyph
->object
)
17864 : (STRINGP (glyph
->object
)
17867 glyph
->pixel_width
,
17869 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17873 glyph
->left_box_line_p
,
17874 glyph
->right_box_line_p
);
17876 else if (glyph
->type
== STRETCH_GLYPH
)
17879 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17880 glyph
- row
->glyphs
[TEXT_AREA
],
17883 (BUFFERP (glyph
->object
)
17885 : (STRINGP (glyph
->object
)
17888 glyph
->pixel_width
,
17892 glyph
->left_box_line_p
,
17893 glyph
->right_box_line_p
);
17895 else if (glyph
->type
== IMAGE_GLYPH
)
17898 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17899 glyph
- row
->glyphs
[TEXT_AREA
],
17902 (BUFFERP (glyph
->object
)
17904 : (STRINGP (glyph
->object
)
17907 glyph
->pixel_width
,
17911 glyph
->left_box_line_p
,
17912 glyph
->right_box_line_p
);
17914 else if (glyph
->type
== COMPOSITE_GLYPH
)
17917 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17918 glyph
- row
->glyphs
[TEXT_AREA
],
17921 (BUFFERP (glyph
->object
)
17923 : (STRINGP (glyph
->object
)
17926 glyph
->pixel_width
,
17928 if (glyph
->u
.cmp
.automatic
)
17931 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17932 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17934 glyph
->left_box_line_p
,
17935 glyph
->right_box_line_p
);
17940 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17941 GLYPHS 0 means don't show glyph contents.
17942 GLYPHS 1 means show glyphs in short form
17943 GLYPHS > 1 means show glyphs in long form. */
17946 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17950 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17951 fprintf (stderr
, "======================================================================\n");
17953 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17954 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17956 MATRIX_ROW_START_CHARPOS (row
),
17957 MATRIX_ROW_END_CHARPOS (row
),
17958 row
->used
[TEXT_AREA
],
17959 row
->contains_overlapping_glyphs_p
,
17961 row
->truncated_on_left_p
,
17962 row
->truncated_on_right_p
,
17964 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17965 row
->displays_text_p
,
17968 row
->ends_in_middle_of_char_p
,
17969 row
->starts_in_middle_of_char_p
,
17975 row
->visible_height
,
17978 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17979 row
->end
.overlay_string_index
,
17980 row
->continuation_lines_width
);
17981 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17982 CHARPOS (row
->start
.string_pos
),
17983 CHARPOS (row
->end
.string_pos
));
17984 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17985 row
->end
.dpvec_index
);
17992 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17994 struct glyph
*glyph
= row
->glyphs
[area
];
17995 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17997 /* Glyph for a line end in text. */
17998 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18001 if (glyph
< glyph_end
)
18002 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18004 for (; glyph
< glyph_end
; ++glyph
)
18005 dump_glyph (row
, glyph
, area
);
18008 else if (glyphs
== 1)
18012 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18014 char *s
= alloca (row
->used
[area
] + 1);
18017 for (i
= 0; i
< row
->used
[area
]; ++i
)
18019 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18020 if (glyph
->type
== CHAR_GLYPH
18021 && glyph
->u
.ch
< 0x80
18022 && glyph
->u
.ch
>= ' ')
18023 s
[i
] = glyph
->u
.ch
;
18029 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18035 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18036 Sdump_glyph_matrix
, 0, 1, "p",
18037 doc
: /* Dump the current matrix of the selected window to stderr.
18038 Shows contents of glyph row structures. With non-nil
18039 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18040 glyphs in short form, otherwise show glyphs in long form. */)
18041 (Lisp_Object glyphs
)
18043 struct window
*w
= XWINDOW (selected_window
);
18044 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18046 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18047 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18048 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18049 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18050 fprintf (stderr
, "=============================================\n");
18051 dump_glyph_matrix (w
->current_matrix
,
18052 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18057 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18058 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18061 struct frame
*f
= XFRAME (selected_frame
);
18062 dump_glyph_matrix (f
->current_matrix
, 1);
18067 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18068 doc
: /* Dump glyph row ROW to stderr.
18069 GLYPH 0 means don't dump glyphs.
18070 GLYPH 1 means dump glyphs in short form.
18071 GLYPH > 1 or omitted means dump glyphs in long form. */)
18072 (Lisp_Object row
, Lisp_Object glyphs
)
18074 struct glyph_matrix
*matrix
;
18077 CHECK_NUMBER (row
);
18078 matrix
= XWINDOW (selected_window
)->current_matrix
;
18080 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18081 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18083 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18088 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18089 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18090 GLYPH 0 means don't dump glyphs.
18091 GLYPH 1 means dump glyphs in short form.
18092 GLYPH > 1 or omitted means dump glyphs in long form. */)
18093 (Lisp_Object row
, Lisp_Object glyphs
)
18095 struct frame
*sf
= SELECTED_FRAME ();
18096 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18099 CHECK_NUMBER (row
);
18101 if (vpos
>= 0 && vpos
< m
->nrows
)
18102 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18103 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18108 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18109 doc
: /* Toggle tracing of redisplay.
18110 With ARG, turn tracing on if and only if ARG is positive. */)
18114 trace_redisplay_p
= !trace_redisplay_p
;
18117 arg
= Fprefix_numeric_value (arg
);
18118 trace_redisplay_p
= XINT (arg
) > 0;
18125 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18126 doc
: /* Like `format', but print result to stderr.
18127 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18128 (ptrdiff_t nargs
, Lisp_Object
*args
)
18130 Lisp_Object s
= Fformat (nargs
, args
);
18131 fprintf (stderr
, "%s", SDATA (s
));
18135 #endif /* GLYPH_DEBUG */
18139 /***********************************************************************
18140 Building Desired Matrix Rows
18141 ***********************************************************************/
18143 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18144 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18146 static struct glyph_row
*
18147 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18149 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18150 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18151 struct buffer
*old
= current_buffer
;
18152 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18153 int arrow_len
= SCHARS (overlay_arrow_string
);
18154 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18155 const unsigned char *p
;
18158 int n_glyphs_before
;
18160 set_buffer_temp (buffer
);
18161 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18162 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18163 SET_TEXT_POS (it
.position
, 0, 0);
18165 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18167 while (p
< arrow_end
)
18169 Lisp_Object face
, ilisp
;
18171 /* Get the next character. */
18173 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18176 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18177 if (! ASCII_CHAR_P (it
.c
))
18178 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18182 /* Get its face. */
18183 ilisp
= make_number (p
- arrow_string
);
18184 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18185 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18187 /* Compute its width, get its glyphs. */
18188 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18189 SET_TEXT_POS (it
.position
, -1, -1);
18190 PRODUCE_GLYPHS (&it
);
18192 /* If this character doesn't fit any more in the line, we have
18193 to remove some glyphs. */
18194 if (it
.current_x
> it
.last_visible_x
)
18196 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18201 set_buffer_temp (old
);
18202 return it
.glyph_row
;
18206 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
18207 glyphs are only inserted for terminal frames since we can't really
18208 win with truncation glyphs when partially visible glyphs are
18209 involved. Which glyphs to insert is determined by
18210 produce_special_glyphs. */
18213 insert_left_trunc_glyphs (struct it
*it
)
18215 struct it truncate_it
;
18216 struct glyph
*from
, *end
, *to
, *toend
;
18218 eassert (!FRAME_WINDOW_P (it
->f
));
18220 /* Get the truncation glyphs. */
18222 truncate_it
.current_x
= 0;
18223 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18224 truncate_it
.glyph_row
= &scratch_glyph_row
;
18225 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18226 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18227 truncate_it
.object
= make_number (0);
18228 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18230 /* Overwrite glyphs from IT with truncation glyphs. */
18231 if (!it
->glyph_row
->reversed_p
)
18233 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18234 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
18235 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18236 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18241 /* There may be padding glyphs left over. Overwrite them too. */
18242 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18244 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18250 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18254 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18255 that back to front. */
18256 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18257 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18258 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18259 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18261 while (from
>= end
&& to
>= toend
)
18263 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18266 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18267 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18268 while (from
>= end
&& to
>= toend
)
18273 /* Need to free some room before prepending additional
18275 int move_by
= from
- end
+ 1;
18276 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18277 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18279 for ( ; g
>= g0
; g
--)
18281 while (from
>= end
)
18283 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18288 /* Compute the hash code for ROW. */
18290 row_hash (struct glyph_row
*row
)
18293 unsigned hashval
= 0;
18295 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18296 for (k
= 0; k
< row
->used
[area
]; ++k
)
18297 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18298 + row
->glyphs
[area
][k
].u
.val
18299 + row
->glyphs
[area
][k
].face_id
18300 + row
->glyphs
[area
][k
].padding_p
18301 + (row
->glyphs
[area
][k
].type
<< 2));
18306 /* Compute the pixel height and width of IT->glyph_row.
18308 Most of the time, ascent and height of a display line will be equal
18309 to the max_ascent and max_height values of the display iterator
18310 structure. This is not the case if
18312 1. We hit ZV without displaying anything. In this case, max_ascent
18313 and max_height will be zero.
18315 2. We have some glyphs that don't contribute to the line height.
18316 (The glyph row flag contributes_to_line_height_p is for future
18317 pixmap extensions).
18319 The first case is easily covered by using default values because in
18320 these cases, the line height does not really matter, except that it
18321 must not be zero. */
18324 compute_line_metrics (struct it
*it
)
18326 struct glyph_row
*row
= it
->glyph_row
;
18328 if (FRAME_WINDOW_P (it
->f
))
18330 int i
, min_y
, max_y
;
18332 /* The line may consist of one space only, that was added to
18333 place the cursor on it. If so, the row's height hasn't been
18335 if (row
->height
== 0)
18337 if (it
->max_ascent
+ it
->max_descent
== 0)
18338 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18339 row
->ascent
= it
->max_ascent
;
18340 row
->height
= it
->max_ascent
+ it
->max_descent
;
18341 row
->phys_ascent
= it
->max_phys_ascent
;
18342 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18343 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18346 /* Compute the width of this line. */
18347 row
->pixel_width
= row
->x
;
18348 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18349 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18351 eassert (row
->pixel_width
>= 0);
18352 eassert (row
->ascent
>= 0 && row
->height
> 0);
18354 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18355 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18357 /* If first line's physical ascent is larger than its logical
18358 ascent, use the physical ascent, and make the row taller.
18359 This makes accented characters fully visible. */
18360 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18361 && row
->phys_ascent
> row
->ascent
)
18363 row
->height
+= row
->phys_ascent
- row
->ascent
;
18364 row
->ascent
= row
->phys_ascent
;
18367 /* Compute how much of the line is visible. */
18368 row
->visible_height
= row
->height
;
18370 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18371 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18373 if (row
->y
< min_y
)
18374 row
->visible_height
-= min_y
- row
->y
;
18375 if (row
->y
+ row
->height
> max_y
)
18376 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18380 row
->pixel_width
= row
->used
[TEXT_AREA
];
18381 if (row
->continued_p
)
18382 row
->pixel_width
-= it
->continuation_pixel_width
;
18383 else if (row
->truncated_on_right_p
)
18384 row
->pixel_width
-= it
->truncation_pixel_width
;
18385 row
->ascent
= row
->phys_ascent
= 0;
18386 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18387 row
->extra_line_spacing
= 0;
18390 /* Compute a hash code for this row. */
18391 row
->hash
= row_hash (row
);
18393 it
->max_ascent
= it
->max_descent
= 0;
18394 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18398 /* Append one space to the glyph row of iterator IT if doing a
18399 window-based redisplay. The space has the same face as
18400 IT->face_id. Value is non-zero if a space was added.
18402 This function is called to make sure that there is always one glyph
18403 at the end of a glyph row that the cursor can be set on under
18404 window-systems. (If there weren't such a glyph we would not know
18405 how wide and tall a box cursor should be displayed).
18407 At the same time this space let's a nicely handle clearing to the
18408 end of the line if the row ends in italic text. */
18411 append_space_for_newline (struct it
*it
, int default_face_p
)
18413 if (FRAME_WINDOW_P (it
->f
))
18415 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18417 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18418 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18420 /* Save some values that must not be changed.
18421 Must save IT->c and IT->len because otherwise
18422 ITERATOR_AT_END_P wouldn't work anymore after
18423 append_space_for_newline has been called. */
18424 enum display_element_type saved_what
= it
->what
;
18425 int saved_c
= it
->c
, saved_len
= it
->len
;
18426 int saved_char_to_display
= it
->char_to_display
;
18427 int saved_x
= it
->current_x
;
18428 int saved_face_id
= it
->face_id
;
18429 struct text_pos saved_pos
;
18430 Lisp_Object saved_object
;
18433 saved_object
= it
->object
;
18434 saved_pos
= it
->position
;
18436 it
->what
= IT_CHARACTER
;
18437 memset (&it
->position
, 0, sizeof it
->position
);
18438 it
->object
= make_number (0);
18439 it
->c
= it
->char_to_display
= ' ';
18442 /* If the default face was remapped, be sure to use the
18443 remapped face for the appended newline. */
18444 if (default_face_p
)
18445 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18446 else if (it
->face_before_selective_p
)
18447 it
->face_id
= it
->saved_face_id
;
18448 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18449 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18451 PRODUCE_GLYPHS (it
);
18453 it
->override_ascent
= -1;
18454 it
->constrain_row_ascent_descent_p
= 0;
18455 it
->current_x
= saved_x
;
18456 it
->object
= saved_object
;
18457 it
->position
= saved_pos
;
18458 it
->what
= saved_what
;
18459 it
->face_id
= saved_face_id
;
18460 it
->len
= saved_len
;
18462 it
->char_to_display
= saved_char_to_display
;
18471 /* Extend the face of the last glyph in the text area of IT->glyph_row
18472 to the end of the display line. Called from display_line. If the
18473 glyph row is empty, add a space glyph to it so that we know the
18474 face to draw. Set the glyph row flag fill_line_p. If the glyph
18475 row is R2L, prepend a stretch glyph to cover the empty space to the
18476 left of the leftmost glyph. */
18479 extend_face_to_end_of_line (struct it
*it
)
18481 struct face
*face
, *default_face
;
18482 struct frame
*f
= it
->f
;
18484 /* If line is already filled, do nothing. Non window-system frames
18485 get a grace of one more ``pixel'' because their characters are
18486 1-``pixel'' wide, so they hit the equality too early. This grace
18487 is needed only for R2L rows that are not continued, to produce
18488 one extra blank where we could display the cursor. */
18489 if (it
->current_x
>= it
->last_visible_x
18490 + (!FRAME_WINDOW_P (f
)
18491 && it
->glyph_row
->reversed_p
18492 && !it
->glyph_row
->continued_p
))
18495 /* The default face, possibly remapped. */
18496 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18498 /* Face extension extends the background and box of IT->face_id
18499 to the end of the line. If the background equals the background
18500 of the frame, we don't have to do anything. */
18501 if (it
->face_before_selective_p
)
18502 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18504 face
= FACE_FROM_ID (f
, it
->face_id
);
18506 if (FRAME_WINDOW_P (f
)
18507 && it
->glyph_row
->displays_text_p
18508 && face
->box
== FACE_NO_BOX
18509 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18511 && !it
->glyph_row
->reversed_p
)
18514 /* Set the glyph row flag indicating that the face of the last glyph
18515 in the text area has to be drawn to the end of the text area. */
18516 it
->glyph_row
->fill_line_p
= 1;
18518 /* If current character of IT is not ASCII, make sure we have the
18519 ASCII face. This will be automatically undone the next time
18520 get_next_display_element returns a multibyte character. Note
18521 that the character will always be single byte in unibyte
18523 if (!ASCII_CHAR_P (it
->c
))
18525 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18528 if (FRAME_WINDOW_P (f
))
18530 /* If the row is empty, add a space with the current face of IT,
18531 so that we know which face to draw. */
18532 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18534 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18535 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18536 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18538 #ifdef HAVE_WINDOW_SYSTEM
18539 if (it
->glyph_row
->reversed_p
)
18541 /* Prepend a stretch glyph to the row, such that the
18542 rightmost glyph will be drawn flushed all the way to the
18543 right margin of the window. The stretch glyph that will
18544 occupy the empty space, if any, to the left of the
18546 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18547 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18548 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18550 int row_width
, stretch_ascent
, stretch_width
;
18551 struct text_pos saved_pos
;
18552 int saved_face_id
, saved_avoid_cursor
;
18554 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18555 row_width
+= g
->pixel_width
;
18556 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18557 if (stretch_width
> 0)
18560 (((it
->ascent
+ it
->descent
)
18561 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18562 saved_pos
= it
->position
;
18563 memset (&it
->position
, 0, sizeof it
->position
);
18564 saved_avoid_cursor
= it
->avoid_cursor_p
;
18565 it
->avoid_cursor_p
= 1;
18566 saved_face_id
= it
->face_id
;
18567 /* The last row's stretch glyph should get the default
18568 face, to avoid painting the rest of the window with
18569 the region face, if the region ends at ZV. */
18570 if (it
->glyph_row
->ends_at_zv_p
)
18571 it
->face_id
= default_face
->id
;
18573 it
->face_id
= face
->id
;
18574 append_stretch_glyph (it
, make_number (0), stretch_width
,
18575 it
->ascent
+ it
->descent
, stretch_ascent
);
18576 it
->position
= saved_pos
;
18577 it
->avoid_cursor_p
= saved_avoid_cursor
;
18578 it
->face_id
= saved_face_id
;
18581 #endif /* HAVE_WINDOW_SYSTEM */
18585 /* Save some values that must not be changed. */
18586 int saved_x
= it
->current_x
;
18587 struct text_pos saved_pos
;
18588 Lisp_Object saved_object
;
18589 enum display_element_type saved_what
= it
->what
;
18590 int saved_face_id
= it
->face_id
;
18592 saved_object
= it
->object
;
18593 saved_pos
= it
->position
;
18595 it
->what
= IT_CHARACTER
;
18596 memset (&it
->position
, 0, sizeof it
->position
);
18597 it
->object
= make_number (0);
18598 it
->c
= it
->char_to_display
= ' ';
18600 /* The last row's blank glyphs should get the default face, to
18601 avoid painting the rest of the window with the region face,
18602 if the region ends at ZV. */
18603 if (it
->glyph_row
->ends_at_zv_p
)
18604 it
->face_id
= default_face
->id
;
18606 it
->face_id
= face
->id
;
18608 PRODUCE_GLYPHS (it
);
18610 while (it
->current_x
<= it
->last_visible_x
)
18611 PRODUCE_GLYPHS (it
);
18613 /* Don't count these blanks really. It would let us insert a left
18614 truncation glyph below and make us set the cursor on them, maybe. */
18615 it
->current_x
= saved_x
;
18616 it
->object
= saved_object
;
18617 it
->position
= saved_pos
;
18618 it
->what
= saved_what
;
18619 it
->face_id
= saved_face_id
;
18624 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18625 trailing whitespace. */
18628 trailing_whitespace_p (ptrdiff_t charpos
)
18630 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18633 while (bytepos
< ZV_BYTE
18634 && (c
= FETCH_CHAR (bytepos
),
18635 c
== ' ' || c
== '\t'))
18638 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18640 if (bytepos
!= PT_BYTE
)
18647 /* Highlight trailing whitespace, if any, in ROW. */
18650 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18652 int used
= row
->used
[TEXT_AREA
];
18656 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18657 struct glyph
*glyph
= start
+ used
- 1;
18659 if (row
->reversed_p
)
18661 /* Right-to-left rows need to be processed in the opposite
18662 direction, so swap the edge pointers. */
18664 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18667 /* Skip over glyphs inserted to display the cursor at the
18668 end of a line, for extending the face of the last glyph
18669 to the end of the line on terminals, and for truncation
18670 and continuation glyphs. */
18671 if (!row
->reversed_p
)
18673 while (glyph
>= start
18674 && glyph
->type
== CHAR_GLYPH
18675 && INTEGERP (glyph
->object
))
18680 while (glyph
<= start
18681 && glyph
->type
== CHAR_GLYPH
18682 && INTEGERP (glyph
->object
))
18686 /* If last glyph is a space or stretch, and it's trailing
18687 whitespace, set the face of all trailing whitespace glyphs in
18688 IT->glyph_row to `trailing-whitespace'. */
18689 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18690 && BUFFERP (glyph
->object
)
18691 && (glyph
->type
== STRETCH_GLYPH
18692 || (glyph
->type
== CHAR_GLYPH
18693 && glyph
->u
.ch
== ' '))
18694 && trailing_whitespace_p (glyph
->charpos
))
18696 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18700 if (!row
->reversed_p
)
18702 while (glyph
>= start
18703 && BUFFERP (glyph
->object
)
18704 && (glyph
->type
== STRETCH_GLYPH
18705 || (glyph
->type
== CHAR_GLYPH
18706 && glyph
->u
.ch
== ' ')))
18707 (glyph
--)->face_id
= face_id
;
18711 while (glyph
<= start
18712 && BUFFERP (glyph
->object
)
18713 && (glyph
->type
== STRETCH_GLYPH
18714 || (glyph
->type
== CHAR_GLYPH
18715 && glyph
->u
.ch
== ' ')))
18716 (glyph
++)->face_id
= face_id
;
18723 /* Value is non-zero if glyph row ROW should be
18724 used to hold the cursor. */
18727 cursor_row_p (struct glyph_row
*row
)
18731 if (PT
== CHARPOS (row
->end
.pos
)
18732 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18734 /* Suppose the row ends on a string.
18735 Unless the row is continued, that means it ends on a newline
18736 in the string. If it's anything other than a display string
18737 (e.g., a before-string from an overlay), we don't want the
18738 cursor there. (This heuristic seems to give the optimal
18739 behavior for the various types of multi-line strings.)
18740 One exception: if the string has `cursor' property on one of
18741 its characters, we _do_ want the cursor there. */
18742 if (CHARPOS (row
->end
.string_pos
) >= 0)
18744 if (row
->continued_p
)
18748 /* Check for `display' property. */
18749 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18750 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18751 struct glyph
*glyph
;
18754 for (glyph
= end
; glyph
>= beg
; --glyph
)
18755 if (STRINGP (glyph
->object
))
18758 = Fget_char_property (make_number (PT
),
18762 && display_prop_string_p (prop
, glyph
->object
));
18763 /* If there's a `cursor' property on one of the
18764 string's characters, this row is a cursor row,
18765 even though this is not a display string. */
18768 Lisp_Object s
= glyph
->object
;
18770 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18772 ptrdiff_t gpos
= glyph
->charpos
;
18774 if (!NILP (Fget_char_property (make_number (gpos
),
18786 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18788 /* If the row ends in middle of a real character,
18789 and the line is continued, we want the cursor here.
18790 That's because CHARPOS (ROW->end.pos) would equal
18791 PT if PT is before the character. */
18792 if (!row
->ends_in_ellipsis_p
)
18793 result
= row
->continued_p
;
18795 /* If the row ends in an ellipsis, then
18796 CHARPOS (ROW->end.pos) will equal point after the
18797 invisible text. We want that position to be displayed
18798 after the ellipsis. */
18801 /* If the row ends at ZV, display the cursor at the end of that
18802 row instead of at the start of the row below. */
18803 else if (row
->ends_at_zv_p
)
18814 /* Push the property PROP so that it will be rendered at the current
18815 position in IT. Return 1 if PROP was successfully pushed, 0
18816 otherwise. Called from handle_line_prefix to handle the
18817 `line-prefix' and `wrap-prefix' properties. */
18820 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18822 struct text_pos pos
=
18823 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18825 eassert (it
->method
== GET_FROM_BUFFER
18826 || it
->method
== GET_FROM_DISPLAY_VECTOR
18827 || it
->method
== GET_FROM_STRING
);
18829 /* We need to save the current buffer/string position, so it will be
18830 restored by pop_it, because iterate_out_of_display_property
18831 depends on that being set correctly, but some situations leave
18832 it->position not yet set when this function is called. */
18833 push_it (it
, &pos
);
18835 if (STRINGP (prop
))
18837 if (SCHARS (prop
) == 0)
18844 it
->string_from_prefix_prop_p
= 1;
18845 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18846 it
->current
.overlay_string_index
= -1;
18847 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18848 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18849 it
->method
= GET_FROM_STRING
;
18850 it
->stop_charpos
= 0;
18852 it
->base_level_stop
= 0;
18854 /* Force paragraph direction to be that of the parent
18856 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18857 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18859 it
->paragraph_embedding
= L2R
;
18861 /* Set up the bidi iterator for this display string. */
18864 it
->bidi_it
.string
.lstring
= it
->string
;
18865 it
->bidi_it
.string
.s
= NULL
;
18866 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18867 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18868 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18869 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18870 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18873 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18875 it
->method
= GET_FROM_STRETCH
;
18878 #ifdef HAVE_WINDOW_SYSTEM
18879 else if (IMAGEP (prop
))
18881 it
->what
= IT_IMAGE
;
18882 it
->image_id
= lookup_image (it
->f
, prop
);
18883 it
->method
= GET_FROM_IMAGE
;
18885 #endif /* HAVE_WINDOW_SYSTEM */
18888 pop_it (it
); /* bogus display property, give up */
18895 /* Return the character-property PROP at the current position in IT. */
18898 get_it_property (struct it
*it
, Lisp_Object prop
)
18900 Lisp_Object position
;
18902 if (STRINGP (it
->object
))
18903 position
= make_number (IT_STRING_CHARPOS (*it
));
18904 else if (BUFFERP (it
->object
))
18905 position
= make_number (IT_CHARPOS (*it
));
18909 return Fget_char_property (position
, prop
, it
->object
);
18912 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18915 handle_line_prefix (struct it
*it
)
18917 Lisp_Object prefix
;
18919 if (it
->continuation_lines_width
> 0)
18921 prefix
= get_it_property (it
, Qwrap_prefix
);
18923 prefix
= Vwrap_prefix
;
18927 prefix
= get_it_property (it
, Qline_prefix
);
18929 prefix
= Vline_prefix
;
18931 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18933 /* If the prefix is wider than the window, and we try to wrap
18934 it, it would acquire its own wrap prefix, and so on till the
18935 iterator stack overflows. So, don't wrap the prefix. */
18936 it
->line_wrap
= TRUNCATE
;
18937 it
->avoid_cursor_p
= 1;
18943 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18944 only for R2L lines from display_line and display_string, when they
18945 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18946 the line/string needs to be continued on the next glyph row. */
18948 unproduce_glyphs (struct it
*it
, int n
)
18950 struct glyph
*glyph
, *end
;
18952 eassert (it
->glyph_row
);
18953 eassert (it
->glyph_row
->reversed_p
);
18954 eassert (it
->area
== TEXT_AREA
);
18955 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18957 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18958 n
= it
->glyph_row
->used
[TEXT_AREA
];
18959 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18960 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18961 for ( ; glyph
< end
; glyph
++)
18962 glyph
[-n
] = *glyph
;
18965 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18966 and ROW->maxpos. */
18968 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18969 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18970 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18972 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18973 lines' rows is implemented for bidi-reordered rows. */
18975 /* ROW->minpos is the value of min_pos, the minimal buffer position
18976 we have in ROW, or ROW->start.pos if that is smaller. */
18977 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18978 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18980 /* We didn't find buffer positions smaller than ROW->start, or
18981 didn't find _any_ valid buffer positions in any of the glyphs,
18982 so we must trust the iterator's computed positions. */
18983 row
->minpos
= row
->start
.pos
;
18986 max_pos
= CHARPOS (it
->current
.pos
);
18987 max_bpos
= BYTEPOS (it
->current
.pos
);
18990 /* Here are the various use-cases for ending the row, and the
18991 corresponding values for ROW->maxpos:
18993 Line ends in a newline from buffer eol_pos + 1
18994 Line is continued from buffer max_pos + 1
18995 Line is truncated on right it->current.pos
18996 Line ends in a newline from string max_pos + 1(*)
18997 (*) + 1 only when line ends in a forward scan
18998 Line is continued from string max_pos
18999 Line is continued from display vector max_pos
19000 Line is entirely from a string min_pos == max_pos
19001 Line is entirely from a display vector min_pos == max_pos
19002 Line that ends at ZV ZV
19004 If you discover other use-cases, please add them here as
19006 if (row
->ends_at_zv_p
)
19007 row
->maxpos
= it
->current
.pos
;
19008 else if (row
->used
[TEXT_AREA
])
19010 int seen_this_string
= 0;
19011 struct glyph_row
*r1
= row
- 1;
19013 /* Did we see the same display string on the previous row? */
19014 if (STRINGP (it
->object
)
19015 /* this is not the first row */
19016 && row
> it
->w
->desired_matrix
->rows
19017 /* previous row is not the header line */
19018 && !r1
->mode_line_p
19019 /* previous row also ends in a newline from a string */
19020 && r1
->ends_in_newline_from_string_p
)
19022 struct glyph
*start
, *end
;
19024 /* Search for the last glyph of the previous row that came
19025 from buffer or string. Depending on whether the row is
19026 L2R or R2L, we need to process it front to back or the
19027 other way round. */
19028 if (!r1
->reversed_p
)
19030 start
= r1
->glyphs
[TEXT_AREA
];
19031 end
= start
+ r1
->used
[TEXT_AREA
];
19032 /* Glyphs inserted by redisplay have an integer (zero)
19033 as their object. */
19035 && INTEGERP ((end
- 1)->object
)
19036 && (end
- 1)->charpos
<= 0)
19040 if (EQ ((end
- 1)->object
, it
->object
))
19041 seen_this_string
= 1;
19044 /* If all the glyphs of the previous row were inserted
19045 by redisplay, it means the previous row was
19046 produced from a single newline, which is only
19047 possible if that newline came from the same string
19048 as the one which produced this ROW. */
19049 seen_this_string
= 1;
19053 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19054 start
= end
+ r1
->used
[TEXT_AREA
];
19056 && INTEGERP ((end
+ 1)->object
)
19057 && (end
+ 1)->charpos
<= 0)
19061 if (EQ ((end
+ 1)->object
, it
->object
))
19062 seen_this_string
= 1;
19065 seen_this_string
= 1;
19068 /* Take note of each display string that covers a newline only
19069 once, the first time we see it. This is for when a display
19070 string includes more than one newline in it. */
19071 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19073 /* If we were scanning the buffer forward when we displayed
19074 the string, we want to account for at least one buffer
19075 position that belongs to this row (position covered by
19076 the display string), so that cursor positioning will
19077 consider this row as a candidate when point is at the end
19078 of the visual line represented by this row. This is not
19079 required when scanning back, because max_pos will already
19080 have a much larger value. */
19081 if (CHARPOS (row
->end
.pos
) > max_pos
)
19082 INC_BOTH (max_pos
, max_bpos
);
19083 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19085 else if (CHARPOS (it
->eol_pos
) > 0)
19086 SET_TEXT_POS (row
->maxpos
,
19087 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19088 else if (row
->continued_p
)
19090 /* If max_pos is different from IT's current position, it
19091 means IT->method does not belong to the display element
19092 at max_pos. However, it also means that the display
19093 element at max_pos was displayed in its entirety on this
19094 line, which is equivalent to saying that the next line
19095 starts at the next buffer position. */
19096 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19097 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19100 INC_BOTH (max_pos
, max_bpos
);
19101 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19104 else if (row
->truncated_on_right_p
)
19105 /* display_line already called reseat_at_next_visible_line_start,
19106 which puts the iterator at the beginning of the next line, in
19107 the logical order. */
19108 row
->maxpos
= it
->current
.pos
;
19109 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19110 /* A line that is entirely from a string/image/stretch... */
19111 row
->maxpos
= row
->minpos
;
19116 row
->maxpos
= it
->current
.pos
;
19119 /* Construct the glyph row IT->glyph_row in the desired matrix of
19120 IT->w from text at the current position of IT. See dispextern.h
19121 for an overview of struct it. Value is non-zero if
19122 IT->glyph_row displays text, as opposed to a line displaying ZV
19126 display_line (struct it
*it
)
19128 struct glyph_row
*row
= it
->glyph_row
;
19129 Lisp_Object overlay_arrow_string
;
19131 void *wrap_data
= NULL
;
19132 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19133 int wrap_row_used
= -1;
19134 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19135 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19136 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19137 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19138 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19140 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19141 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19143 /* We always start displaying at hpos zero even if hscrolled. */
19144 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19146 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19147 >= it
->w
->desired_matrix
->nrows
)
19149 it
->w
->nrows_scale_factor
++;
19150 fonts_changed_p
= 1;
19154 /* Is IT->w showing the region? */
19155 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
19157 /* Clear the result glyph row and enable it. */
19158 prepare_desired_row (row
);
19160 row
->y
= it
->current_y
;
19161 row
->start
= it
->start
;
19162 row
->continuation_lines_width
= it
->continuation_lines_width
;
19163 row
->displays_text_p
= 1;
19164 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19165 it
->starts_in_middle_of_char_p
= 0;
19167 /* Arrange the overlays nicely for our purposes. Usually, we call
19168 display_line on only one line at a time, in which case this
19169 can't really hurt too much, or we call it on lines which appear
19170 one after another in the buffer, in which case all calls to
19171 recenter_overlay_lists but the first will be pretty cheap. */
19172 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19174 /* Move over display elements that are not visible because we are
19175 hscrolled. This may stop at an x-position < IT->first_visible_x
19176 if the first glyph is partially visible or if we hit a line end. */
19177 if (it
->current_x
< it
->first_visible_x
)
19179 enum move_it_result move_result
;
19181 this_line_min_pos
= row
->start
.pos
;
19182 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19183 MOVE_TO_POS
| MOVE_TO_X
);
19184 /* If we are under a large hscroll, move_it_in_display_line_to
19185 could hit the end of the line without reaching
19186 it->first_visible_x. Pretend that we did reach it. This is
19187 especially important on a TTY, where we will call
19188 extend_face_to_end_of_line, which needs to know how many
19189 blank glyphs to produce. */
19190 if (it
->current_x
< it
->first_visible_x
19191 && (move_result
== MOVE_NEWLINE_OR_CR
19192 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19193 it
->current_x
= it
->first_visible_x
;
19195 /* Record the smallest positions seen while we moved over
19196 display elements that are not visible. This is needed by
19197 redisplay_internal for optimizing the case where the cursor
19198 stays inside the same line. The rest of this function only
19199 considers positions that are actually displayed, so
19200 RECORD_MAX_MIN_POS will not otherwise record positions that
19201 are hscrolled to the left of the left edge of the window. */
19202 min_pos
= CHARPOS (this_line_min_pos
);
19203 min_bpos
= BYTEPOS (this_line_min_pos
);
19207 /* We only do this when not calling `move_it_in_display_line_to'
19208 above, because move_it_in_display_line_to calls
19209 handle_line_prefix itself. */
19210 handle_line_prefix (it
);
19213 /* Get the initial row height. This is either the height of the
19214 text hscrolled, if there is any, or zero. */
19215 row
->ascent
= it
->max_ascent
;
19216 row
->height
= it
->max_ascent
+ it
->max_descent
;
19217 row
->phys_ascent
= it
->max_phys_ascent
;
19218 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19219 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19221 /* Utility macro to record max and min buffer positions seen until now. */
19222 #define RECORD_MAX_MIN_POS(IT) \
19225 int composition_p = !STRINGP ((IT)->string) \
19226 && ((IT)->what == IT_COMPOSITION); \
19227 ptrdiff_t current_pos = \
19228 composition_p ? (IT)->cmp_it.charpos \
19229 : IT_CHARPOS (*(IT)); \
19230 ptrdiff_t current_bpos = \
19231 composition_p ? CHAR_TO_BYTE (current_pos) \
19232 : IT_BYTEPOS (*(IT)); \
19233 if (current_pos < min_pos) \
19235 min_pos = current_pos; \
19236 min_bpos = current_bpos; \
19238 if (IT_CHARPOS (*it) > max_pos) \
19240 max_pos = IT_CHARPOS (*it); \
19241 max_bpos = IT_BYTEPOS (*it); \
19246 /* Loop generating characters. The loop is left with IT on the next
19247 character to display. */
19250 int n_glyphs_before
, hpos_before
, x_before
;
19252 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19254 /* Retrieve the next thing to display. Value is zero if end of
19256 if (!get_next_display_element (it
))
19258 /* Maybe add a space at the end of this line that is used to
19259 display the cursor there under X. Set the charpos of the
19260 first glyph of blank lines not corresponding to any text
19262 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19263 row
->exact_window_width_line_p
= 1;
19264 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19265 || row
->used
[TEXT_AREA
] == 0)
19267 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19268 row
->displays_text_p
= 0;
19270 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19271 && (!MINI_WINDOW_P (it
->w
)
19272 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19273 row
->indicate_empty_line_p
= 1;
19276 it
->continuation_lines_width
= 0;
19277 row
->ends_at_zv_p
= 1;
19278 /* A row that displays right-to-left text must always have
19279 its last face extended all the way to the end of line,
19280 even if this row ends in ZV, because we still write to
19281 the screen left to right. We also need to extend the
19282 last face if the default face is remapped to some
19283 different face, otherwise the functions that clear
19284 portions of the screen will clear with the default face's
19285 background color. */
19286 if (row
->reversed_p
19287 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19288 extend_face_to_end_of_line (it
);
19292 /* Now, get the metrics of what we want to display. This also
19293 generates glyphs in `row' (which is IT->glyph_row). */
19294 n_glyphs_before
= row
->used
[TEXT_AREA
];
19297 /* Remember the line height so far in case the next element doesn't
19298 fit on the line. */
19299 if (it
->line_wrap
!= TRUNCATE
)
19301 ascent
= it
->max_ascent
;
19302 descent
= it
->max_descent
;
19303 phys_ascent
= it
->max_phys_ascent
;
19304 phys_descent
= it
->max_phys_descent
;
19306 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19308 if (IT_DISPLAYING_WHITESPACE (it
))
19312 SAVE_IT (wrap_it
, *it
, wrap_data
);
19314 wrap_row_used
= row
->used
[TEXT_AREA
];
19315 wrap_row_ascent
= row
->ascent
;
19316 wrap_row_height
= row
->height
;
19317 wrap_row_phys_ascent
= row
->phys_ascent
;
19318 wrap_row_phys_height
= row
->phys_height
;
19319 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19320 wrap_row_min_pos
= min_pos
;
19321 wrap_row_min_bpos
= min_bpos
;
19322 wrap_row_max_pos
= max_pos
;
19323 wrap_row_max_bpos
= max_bpos
;
19329 PRODUCE_GLYPHS (it
);
19331 /* If this display element was in marginal areas, continue with
19333 if (it
->area
!= TEXT_AREA
)
19335 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19336 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19337 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19338 row
->phys_height
= max (row
->phys_height
,
19339 it
->max_phys_ascent
+ it
->max_phys_descent
);
19340 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19341 it
->max_extra_line_spacing
);
19342 set_iterator_to_next (it
, 1);
19346 /* Does the display element fit on the line? If we truncate
19347 lines, we should draw past the right edge of the window. If
19348 we don't truncate, we want to stop so that we can display the
19349 continuation glyph before the right margin. If lines are
19350 continued, there are two possible strategies for characters
19351 resulting in more than 1 glyph (e.g. tabs): Display as many
19352 glyphs as possible in this line and leave the rest for the
19353 continuation line, or display the whole element in the next
19354 line. Original redisplay did the former, so we do it also. */
19355 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19356 hpos_before
= it
->hpos
;
19359 if (/* Not a newline. */
19361 /* Glyphs produced fit entirely in the line. */
19362 && it
->current_x
< it
->last_visible_x
)
19364 it
->hpos
+= nglyphs
;
19365 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19366 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19367 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19368 row
->phys_height
= max (row
->phys_height
,
19369 it
->max_phys_ascent
+ it
->max_phys_descent
);
19370 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19371 it
->max_extra_line_spacing
);
19372 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19373 row
->x
= x
- it
->first_visible_x
;
19374 /* Record the maximum and minimum buffer positions seen so
19375 far in glyphs that will be displayed by this row. */
19377 RECORD_MAX_MIN_POS (it
);
19382 struct glyph
*glyph
;
19384 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19386 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19387 new_x
= x
+ glyph
->pixel_width
;
19389 if (/* Lines are continued. */
19390 it
->line_wrap
!= TRUNCATE
19391 && (/* Glyph doesn't fit on the line. */
19392 new_x
> it
->last_visible_x
19393 /* Or it fits exactly on a window system frame. */
19394 || (new_x
== it
->last_visible_x
19395 && FRAME_WINDOW_P (it
->f
))))
19397 /* End of a continued line. */
19400 || (new_x
== it
->last_visible_x
19401 && FRAME_WINDOW_P (it
->f
)))
19403 /* Current glyph is the only one on the line or
19404 fits exactly on the line. We must continue
19405 the line because we can't draw the cursor
19406 after the glyph. */
19407 row
->continued_p
= 1;
19408 it
->current_x
= new_x
;
19409 it
->continuation_lines_width
+= new_x
;
19411 if (i
== nglyphs
- 1)
19413 /* If line-wrap is on, check if a previous
19414 wrap point was found. */
19415 if (wrap_row_used
> 0
19416 /* Even if there is a previous wrap
19417 point, continue the line here as
19418 usual, if (i) the previous character
19419 was a space or tab AND (ii) the
19420 current character is not. */
19422 || IT_DISPLAYING_WHITESPACE (it
)))
19425 /* Record the maximum and minimum buffer
19426 positions seen so far in glyphs that will be
19427 displayed by this row. */
19429 RECORD_MAX_MIN_POS (it
);
19430 set_iterator_to_next (it
, 1);
19431 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19433 if (!get_next_display_element (it
))
19435 row
->exact_window_width_line_p
= 1;
19436 it
->continuation_lines_width
= 0;
19437 row
->continued_p
= 0;
19438 row
->ends_at_zv_p
= 1;
19440 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19442 row
->continued_p
= 0;
19443 row
->exact_window_width_line_p
= 1;
19447 else if (it
->bidi_p
)
19448 RECORD_MAX_MIN_POS (it
);
19450 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19451 && !FRAME_WINDOW_P (it
->f
))
19453 /* A padding glyph that doesn't fit on this line.
19454 This means the whole character doesn't fit
19456 if (row
->reversed_p
)
19457 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19458 - n_glyphs_before
);
19459 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19461 /* Fill the rest of the row with continuation
19462 glyphs like in 20.x. */
19463 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19464 < row
->glyphs
[1 + TEXT_AREA
])
19465 produce_special_glyphs (it
, IT_CONTINUATION
);
19467 row
->continued_p
= 1;
19468 it
->current_x
= x_before
;
19469 it
->continuation_lines_width
+= x_before
;
19471 /* Restore the height to what it was before the
19472 element not fitting on the line. */
19473 it
->max_ascent
= ascent
;
19474 it
->max_descent
= descent
;
19475 it
->max_phys_ascent
= phys_ascent
;
19476 it
->max_phys_descent
= phys_descent
;
19478 else if (wrap_row_used
> 0)
19481 if (row
->reversed_p
)
19482 unproduce_glyphs (it
,
19483 row
->used
[TEXT_AREA
] - wrap_row_used
);
19484 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19485 it
->continuation_lines_width
+= wrap_x
;
19486 row
->used
[TEXT_AREA
] = wrap_row_used
;
19487 row
->ascent
= wrap_row_ascent
;
19488 row
->height
= wrap_row_height
;
19489 row
->phys_ascent
= wrap_row_phys_ascent
;
19490 row
->phys_height
= wrap_row_phys_height
;
19491 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19492 min_pos
= wrap_row_min_pos
;
19493 min_bpos
= wrap_row_min_bpos
;
19494 max_pos
= wrap_row_max_pos
;
19495 max_bpos
= wrap_row_max_bpos
;
19496 row
->continued_p
= 1;
19497 row
->ends_at_zv_p
= 0;
19498 row
->exact_window_width_line_p
= 0;
19499 it
->continuation_lines_width
+= x
;
19501 /* Make sure that a non-default face is extended
19502 up to the right margin of the window. */
19503 extend_face_to_end_of_line (it
);
19505 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19507 /* A TAB that extends past the right edge of the
19508 window. This produces a single glyph on
19509 window system frames. We leave the glyph in
19510 this row and let it fill the row, but don't
19511 consume the TAB. */
19512 it
->continuation_lines_width
+= it
->last_visible_x
;
19513 row
->ends_in_middle_of_char_p
= 1;
19514 row
->continued_p
= 1;
19515 glyph
->pixel_width
= it
->last_visible_x
- x
;
19516 it
->starts_in_middle_of_char_p
= 1;
19520 /* Something other than a TAB that draws past
19521 the right edge of the window. Restore
19522 positions to values before the element. */
19523 if (row
->reversed_p
)
19524 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19525 - (n_glyphs_before
+ i
));
19526 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19528 /* Display continuation glyphs. */
19529 if (!FRAME_WINDOW_P (it
->f
))
19530 produce_special_glyphs (it
, IT_CONTINUATION
);
19531 row
->continued_p
= 1;
19533 it
->current_x
= x_before
;
19534 it
->continuation_lines_width
+= x
;
19535 extend_face_to_end_of_line (it
);
19537 if (nglyphs
> 1 && i
> 0)
19539 row
->ends_in_middle_of_char_p
= 1;
19540 it
->starts_in_middle_of_char_p
= 1;
19543 /* Restore the height to what it was before the
19544 element not fitting on the line. */
19545 it
->max_ascent
= ascent
;
19546 it
->max_descent
= descent
;
19547 it
->max_phys_ascent
= phys_ascent
;
19548 it
->max_phys_descent
= phys_descent
;
19553 else if (new_x
> it
->first_visible_x
)
19555 /* Increment number of glyphs actually displayed. */
19558 /* Record the maximum and minimum buffer positions
19559 seen so far in glyphs that will be displayed by
19562 RECORD_MAX_MIN_POS (it
);
19564 if (x
< it
->first_visible_x
)
19565 /* Glyph is partially visible, i.e. row starts at
19566 negative X position. */
19567 row
->x
= x
- it
->first_visible_x
;
19571 /* Glyph is completely off the left margin of the
19572 window. This should not happen because of the
19573 move_it_in_display_line at the start of this
19574 function, unless the text display area of the
19575 window is empty. */
19576 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19579 /* Even if this display element produced no glyphs at all,
19580 we want to record its position. */
19581 if (it
->bidi_p
&& nglyphs
== 0)
19582 RECORD_MAX_MIN_POS (it
);
19584 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19585 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19586 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19587 row
->phys_height
= max (row
->phys_height
,
19588 it
->max_phys_ascent
+ it
->max_phys_descent
);
19589 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19590 it
->max_extra_line_spacing
);
19592 /* End of this display line if row is continued. */
19593 if (row
->continued_p
|| row
->ends_at_zv_p
)
19598 /* Is this a line end? If yes, we're also done, after making
19599 sure that a non-default face is extended up to the right
19600 margin of the window. */
19601 if (ITERATOR_AT_END_OF_LINE_P (it
))
19603 int used_before
= row
->used
[TEXT_AREA
];
19605 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19607 /* Add a space at the end of the line that is used to
19608 display the cursor there. */
19609 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19610 append_space_for_newline (it
, 0);
19612 /* Extend the face to the end of the line. */
19613 extend_face_to_end_of_line (it
);
19615 /* Make sure we have the position. */
19616 if (used_before
== 0)
19617 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19619 /* Record the position of the newline, for use in
19621 it
->eol_pos
= it
->current
.pos
;
19623 /* Consume the line end. This skips over invisible lines. */
19624 set_iterator_to_next (it
, 1);
19625 it
->continuation_lines_width
= 0;
19629 /* Proceed with next display element. Note that this skips
19630 over lines invisible because of selective display. */
19631 set_iterator_to_next (it
, 1);
19633 /* If we truncate lines, we are done when the last displayed
19634 glyphs reach past the right margin of the window. */
19635 if (it
->line_wrap
== TRUNCATE
19636 && (FRAME_WINDOW_P (it
->f
)
19637 ? (it
->current_x
>= it
->last_visible_x
)
19638 : (it
->current_x
> it
->last_visible_x
)))
19640 /* Maybe add truncation glyphs. */
19641 if (!FRAME_WINDOW_P (it
->f
))
19645 if (!row
->reversed_p
)
19647 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19648 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19653 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19654 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19656 /* Remove any padding glyphs at the front of ROW, to
19657 make room for the truncation glyphs we will be
19658 adding below. The loop below always inserts at
19659 least one truncation glyph, so also remove the
19660 last glyph added to ROW. */
19661 unproduce_glyphs (it
, i
+ 1);
19662 /* Adjust i for the loop below. */
19663 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19666 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19668 row
->used
[TEXT_AREA
] = i
;
19669 produce_special_glyphs (it
, IT_TRUNCATION
);
19672 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19674 /* Don't truncate if we can overflow newline into fringe. */
19675 if (!get_next_display_element (it
))
19677 it
->continuation_lines_width
= 0;
19678 row
->ends_at_zv_p
= 1;
19679 row
->exact_window_width_line_p
= 1;
19682 if (ITERATOR_AT_END_OF_LINE_P (it
))
19684 row
->exact_window_width_line_p
= 1;
19685 goto at_end_of_line
;
19689 row
->truncated_on_right_p
= 1;
19690 it
->continuation_lines_width
= 0;
19691 reseat_at_next_visible_line_start (it
, 0);
19692 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19693 it
->hpos
= hpos_before
;
19694 it
->current_x
= x_before
;
19700 bidi_unshelve_cache (wrap_data
, 1);
19702 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19703 at the left window margin. */
19704 if (it
->first_visible_x
19705 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19707 if (!FRAME_WINDOW_P (it
->f
))
19708 insert_left_trunc_glyphs (it
);
19709 row
->truncated_on_left_p
= 1;
19712 /* Remember the position at which this line ends.
19714 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19715 cannot be before the call to find_row_edges below, since that is
19716 where these positions are determined. */
19717 row
->end
= it
->current
;
19720 row
->minpos
= row
->start
.pos
;
19721 row
->maxpos
= row
->end
.pos
;
19725 /* ROW->minpos and ROW->maxpos must be the smallest and
19726 `1 + the largest' buffer positions in ROW. But if ROW was
19727 bidi-reordered, these two positions can be anywhere in the
19728 row, so we must determine them now. */
19729 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19732 /* If the start of this line is the overlay arrow-position, then
19733 mark this glyph row as the one containing the overlay arrow.
19734 This is clearly a mess with variable size fonts. It would be
19735 better to let it be displayed like cursors under X. */
19736 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19737 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19738 !NILP (overlay_arrow_string
)))
19740 /* Overlay arrow in window redisplay is a fringe bitmap. */
19741 if (STRINGP (overlay_arrow_string
))
19743 struct glyph_row
*arrow_row
19744 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19745 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19746 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19747 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19748 struct glyph
*p2
, *end
;
19750 /* Copy the arrow glyphs. */
19751 while (glyph
< arrow_end
)
19754 /* Throw away padding glyphs. */
19756 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19757 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19763 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19768 eassert (INTEGERP (overlay_arrow_string
));
19769 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19771 overlay_arrow_seen
= 1;
19774 /* Highlight trailing whitespace. */
19775 if (!NILP (Vshow_trailing_whitespace
))
19776 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19778 /* Compute pixel dimensions of this line. */
19779 compute_line_metrics (it
);
19781 /* Implementation note: No changes in the glyphs of ROW or in their
19782 faces can be done past this point, because compute_line_metrics
19783 computes ROW's hash value and stores it within the glyph_row
19786 /* Record whether this row ends inside an ellipsis. */
19787 row
->ends_in_ellipsis_p
19788 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19789 && it
->ellipsis_p
);
19791 /* Save fringe bitmaps in this row. */
19792 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19793 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19794 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19795 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19797 it
->left_user_fringe_bitmap
= 0;
19798 it
->left_user_fringe_face_id
= 0;
19799 it
->right_user_fringe_bitmap
= 0;
19800 it
->right_user_fringe_face_id
= 0;
19802 /* Maybe set the cursor. */
19803 cvpos
= it
->w
->cursor
.vpos
;
19805 /* In bidi-reordered rows, keep checking for proper cursor
19806 position even if one has been found already, because buffer
19807 positions in such rows change non-linearly with ROW->VPOS,
19808 when a line is continued. One exception: when we are at ZV,
19809 display cursor on the first suitable glyph row, since all
19810 the empty rows after that also have their position set to ZV. */
19811 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19812 lines' rows is implemented for bidi-reordered rows. */
19814 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19815 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19816 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19817 && cursor_row_p (row
))
19818 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19820 /* Prepare for the next line. This line starts horizontally at (X
19821 HPOS) = (0 0). Vertical positions are incremented. As a
19822 convenience for the caller, IT->glyph_row is set to the next
19824 it
->current_x
= it
->hpos
= 0;
19825 it
->current_y
+= row
->height
;
19826 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19829 /* The next row should by default use the same value of the
19830 reversed_p flag as this one. set_iterator_to_next decides when
19831 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19832 the flag accordingly. */
19833 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19834 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19835 it
->start
= row
->end
;
19836 return row
->displays_text_p
;
19838 #undef RECORD_MAX_MIN_POS
19841 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19842 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19843 doc
: /* Return paragraph direction at point in BUFFER.
19844 Value is either `left-to-right' or `right-to-left'.
19845 If BUFFER is omitted or nil, it defaults to the current buffer.
19847 Paragraph direction determines how the text in the paragraph is displayed.
19848 In left-to-right paragraphs, text begins at the left margin of the window
19849 and the reading direction is generally left to right. In right-to-left
19850 paragraphs, text begins at the right margin and is read from right to left.
19852 See also `bidi-paragraph-direction'. */)
19853 (Lisp_Object buffer
)
19855 struct buffer
*buf
= current_buffer
;
19856 struct buffer
*old
= buf
;
19858 if (! NILP (buffer
))
19860 CHECK_BUFFER (buffer
);
19861 buf
= XBUFFER (buffer
);
19864 if (NILP (BVAR (buf
, bidi_display_reordering
))
19865 || NILP (BVAR (buf
, enable_multibyte_characters
))
19866 /* When we are loading loadup.el, the character property tables
19867 needed for bidi iteration are not yet available. */
19868 || !NILP (Vpurify_flag
))
19869 return Qleft_to_right
;
19870 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19871 return BVAR (buf
, bidi_paragraph_direction
);
19874 /* Determine the direction from buffer text. We could try to
19875 use current_matrix if it is up to date, but this seems fast
19876 enough as it is. */
19877 struct bidi_it itb
;
19878 ptrdiff_t pos
= BUF_PT (buf
);
19879 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19881 void *itb_data
= bidi_shelve_cache ();
19883 set_buffer_temp (buf
);
19884 /* bidi_paragraph_init finds the base direction of the paragraph
19885 by searching forward from paragraph start. We need the base
19886 direction of the current or _previous_ paragraph, so we need
19887 to make sure we are within that paragraph. To that end, find
19888 the previous non-empty line. */
19889 if (pos
>= ZV
&& pos
> BEGV
)
19892 bytepos
= CHAR_TO_BYTE (pos
);
19894 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19895 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19897 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19898 || c
== ' ' || c
== '\t' || c
== '\f')
19900 if (bytepos
<= BEGV_BYTE
)
19905 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19908 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19909 itb
.paragraph_dir
= NEUTRAL_DIR
;
19910 itb
.string
.s
= NULL
;
19911 itb
.string
.lstring
= Qnil
;
19912 itb
.string
.bufpos
= 0;
19913 itb
.string
.unibyte
= 0;
19914 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19915 bidi_unshelve_cache (itb_data
, 0);
19916 set_buffer_temp (old
);
19917 switch (itb
.paragraph_dir
)
19920 return Qleft_to_right
;
19923 return Qright_to_left
;
19933 /***********************************************************************
19935 ***********************************************************************/
19937 /* Redisplay the menu bar in the frame for window W.
19939 The menu bar of X frames that don't have X toolkit support is
19940 displayed in a special window W->frame->menu_bar_window.
19942 The menu bar of terminal frames is treated specially as far as
19943 glyph matrices are concerned. Menu bar lines are not part of
19944 windows, so the update is done directly on the frame matrix rows
19945 for the menu bar. */
19948 display_menu_bar (struct window
*w
)
19950 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19955 /* Don't do all this for graphical frames. */
19957 if (FRAME_W32_P (f
))
19960 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19966 if (FRAME_NS_P (f
))
19968 #endif /* HAVE_NS */
19970 #ifdef USE_X_TOOLKIT
19971 eassert (!FRAME_WINDOW_P (f
));
19972 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19973 it
.first_visible_x
= 0;
19974 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19975 #else /* not USE_X_TOOLKIT */
19976 if (FRAME_WINDOW_P (f
))
19978 /* Menu bar lines are displayed in the desired matrix of the
19979 dummy window menu_bar_window. */
19980 struct window
*menu_w
;
19981 eassert (WINDOWP (f
->menu_bar_window
));
19982 menu_w
= XWINDOW (f
->menu_bar_window
);
19983 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19985 it
.first_visible_x
= 0;
19986 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19990 /* This is a TTY frame, i.e. character hpos/vpos are used as
19992 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19994 it
.first_visible_x
= 0;
19995 it
.last_visible_x
= FRAME_COLS (f
);
19997 #endif /* not USE_X_TOOLKIT */
19999 /* FIXME: This should be controlled by a user option. See the
20000 comments in redisplay_tool_bar and display_mode_line about
20002 it
.paragraph_embedding
= L2R
;
20004 if (! mode_line_inverse_video
)
20005 /* Force the menu-bar to be displayed in the default face. */
20006 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20008 /* Clear all rows of the menu bar. */
20009 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20011 struct glyph_row
*row
= it
.glyph_row
+ i
;
20012 clear_glyph_row (row
);
20013 row
->enabled_p
= 1;
20014 row
->full_width_p
= 1;
20017 /* Display all items of the menu bar. */
20018 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20019 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20021 Lisp_Object string
;
20023 /* Stop at nil string. */
20024 string
= AREF (items
, i
+ 1);
20028 /* Remember where item was displayed. */
20029 ASET (items
, i
+ 3, make_number (it
.hpos
));
20031 /* Display the item, pad with one space. */
20032 if (it
.current_x
< it
.last_visible_x
)
20033 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20034 SCHARS (string
) + 1, 0, 0, -1);
20037 /* Fill out the line with spaces. */
20038 if (it
.current_x
< it
.last_visible_x
)
20039 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20041 /* Compute the total height of the lines. */
20042 compute_line_metrics (&it
);
20047 /***********************************************************************
20049 ***********************************************************************/
20051 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20052 FORCE is non-zero, redisplay mode lines unconditionally.
20053 Otherwise, redisplay only mode lines that are garbaged. Value is
20054 the number of windows whose mode lines were redisplayed. */
20057 redisplay_mode_lines (Lisp_Object window
, int force
)
20061 while (!NILP (window
))
20063 struct window
*w
= XWINDOW (window
);
20065 if (WINDOWP (w
->hchild
))
20066 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20067 else if (WINDOWP (w
->vchild
))
20068 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20070 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20071 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20073 struct text_pos lpoint
;
20074 struct buffer
*old
= current_buffer
;
20076 /* Set the window's buffer for the mode line display. */
20077 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20078 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20080 /* Point refers normally to the selected window. For any
20081 other window, set up appropriate value. */
20082 if (!EQ (window
, selected_window
))
20084 struct text_pos pt
;
20086 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20087 if (CHARPOS (pt
) < BEGV
)
20088 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20089 else if (CHARPOS (pt
) > (ZV
- 1))
20090 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20092 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20095 /* Display mode lines. */
20096 clear_glyph_matrix (w
->desired_matrix
);
20097 if (display_mode_lines (w
))
20100 w
->must_be_updated_p
= 1;
20103 /* Restore old settings. */
20104 set_buffer_internal_1 (old
);
20105 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20115 /* Display the mode and/or header line of window W. Value is the
20116 sum number of mode lines and header lines displayed. */
20119 display_mode_lines (struct window
*w
)
20121 Lisp_Object old_selected_window
, old_selected_frame
;
20124 old_selected_frame
= selected_frame
;
20125 selected_frame
= w
->frame
;
20126 old_selected_window
= selected_window
;
20127 XSETWINDOW (selected_window
, w
);
20129 /* These will be set while the mode line specs are processed. */
20130 line_number_displayed
= 0;
20131 w
->column_number_displayed
= Qnil
;
20133 if (WINDOW_WANTS_MODELINE_P (w
))
20135 struct window
*sel_w
= XWINDOW (old_selected_window
);
20137 /* Select mode line face based on the real selected window. */
20138 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20139 BVAR (current_buffer
, mode_line_format
));
20143 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20145 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20146 BVAR (current_buffer
, header_line_format
));
20150 selected_frame
= old_selected_frame
;
20151 selected_window
= old_selected_window
;
20156 /* Display mode or header line of window W. FACE_ID specifies which
20157 line to display; it is either MODE_LINE_FACE_ID or
20158 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20159 display. Value is the pixel height of the mode/header line
20163 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20167 ptrdiff_t count
= SPECPDL_INDEX ();
20169 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20170 /* Don't extend on a previously drawn mode-line.
20171 This may happen if called from pos_visible_p. */
20172 it
.glyph_row
->enabled_p
= 0;
20173 prepare_desired_row (it
.glyph_row
);
20175 it
.glyph_row
->mode_line_p
= 1;
20177 if (! mode_line_inverse_video
)
20178 /* Force the mode-line to be displayed in the default face. */
20179 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20181 /* FIXME: This should be controlled by a user option. But
20182 supporting such an option is not trivial, since the mode line is
20183 made up of many separate strings. */
20184 it
.paragraph_embedding
= L2R
;
20186 record_unwind_protect (unwind_format_mode_line
,
20187 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20189 mode_line_target
= MODE_LINE_DISPLAY
;
20191 /* Temporarily make frame's keyboard the current kboard so that
20192 kboard-local variables in the mode_line_format will get the right
20194 push_kboard (FRAME_KBOARD (it
.f
));
20195 record_unwind_save_match_data ();
20196 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20199 unbind_to (count
, Qnil
);
20201 /* Fill up with spaces. */
20202 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20204 compute_line_metrics (&it
);
20205 it
.glyph_row
->full_width_p
= 1;
20206 it
.glyph_row
->continued_p
= 0;
20207 it
.glyph_row
->truncated_on_left_p
= 0;
20208 it
.glyph_row
->truncated_on_right_p
= 0;
20210 /* Make a 3D mode-line have a shadow at its right end. */
20211 face
= FACE_FROM_ID (it
.f
, face_id
);
20212 extend_face_to_end_of_line (&it
);
20213 if (face
->box
!= FACE_NO_BOX
)
20215 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20216 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20217 last
->right_box_line_p
= 1;
20220 return it
.glyph_row
->height
;
20223 /* Move element ELT in LIST to the front of LIST.
20224 Return the updated list. */
20227 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20229 register Lisp_Object tail
, prev
;
20230 register Lisp_Object tem
;
20234 while (CONSP (tail
))
20240 /* Splice out the link TAIL. */
20242 list
= XCDR (tail
);
20244 Fsetcdr (prev
, XCDR (tail
));
20246 /* Now make it the first. */
20247 Fsetcdr (tail
, list
);
20252 tail
= XCDR (tail
);
20256 /* Not found--return unchanged LIST. */
20260 /* Contribute ELT to the mode line for window IT->w. How it
20261 translates into text depends on its data type.
20263 IT describes the display environment in which we display, as usual.
20265 DEPTH is the depth in recursion. It is used to prevent
20266 infinite recursion here.
20268 FIELD_WIDTH is the number of characters the display of ELT should
20269 occupy in the mode line, and PRECISION is the maximum number of
20270 characters to display from ELT's representation. See
20271 display_string for details.
20273 Returns the hpos of the end of the text generated by ELT.
20275 PROPS is a property list to add to any string we encounter.
20277 If RISKY is nonzero, remove (disregard) any properties in any string
20278 we encounter, and ignore :eval and :propertize.
20280 The global variable `mode_line_target' determines whether the
20281 output is passed to `store_mode_line_noprop',
20282 `store_mode_line_string', or `display_string'. */
20285 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20286 Lisp_Object elt
, Lisp_Object props
, int risky
)
20288 int n
= 0, field
, prec
;
20293 elt
= build_string ("*too-deep*");
20297 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
20301 /* A string: output it and check for %-constructs within it. */
20303 ptrdiff_t offset
= 0;
20305 if (SCHARS (elt
) > 0
20306 && (!NILP (props
) || risky
))
20308 Lisp_Object oprops
, aelt
;
20309 oprops
= Ftext_properties_at (make_number (0), elt
);
20311 /* If the starting string's properties are not what
20312 we want, translate the string. Also, if the string
20313 is risky, do that anyway. */
20315 if (NILP (Fequal (props
, oprops
)) || risky
)
20317 /* If the starting string has properties,
20318 merge the specified ones onto the existing ones. */
20319 if (! NILP (oprops
) && !risky
)
20323 oprops
= Fcopy_sequence (oprops
);
20325 while (CONSP (tem
))
20327 oprops
= Fplist_put (oprops
, XCAR (tem
),
20328 XCAR (XCDR (tem
)));
20329 tem
= XCDR (XCDR (tem
));
20334 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20335 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20337 /* AELT is what we want. Move it to the front
20338 without consing. */
20340 mode_line_proptrans_alist
20341 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20347 /* If AELT has the wrong props, it is useless.
20348 so get rid of it. */
20350 mode_line_proptrans_alist
20351 = Fdelq (aelt
, mode_line_proptrans_alist
);
20353 elt
= Fcopy_sequence (elt
);
20354 Fset_text_properties (make_number (0), Flength (elt
),
20356 /* Add this item to mode_line_proptrans_alist. */
20357 mode_line_proptrans_alist
20358 = Fcons (Fcons (elt
, props
),
20359 mode_line_proptrans_alist
);
20360 /* Truncate mode_line_proptrans_alist
20361 to at most 50 elements. */
20362 tem
= Fnthcdr (make_number (50),
20363 mode_line_proptrans_alist
);
20365 XSETCDR (tem
, Qnil
);
20374 prec
= precision
- n
;
20375 switch (mode_line_target
)
20377 case MODE_LINE_NOPROP
:
20378 case MODE_LINE_TITLE
:
20379 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20381 case MODE_LINE_STRING
:
20382 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20384 case MODE_LINE_DISPLAY
:
20385 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20386 0, prec
, 0, STRING_MULTIBYTE (elt
));
20393 /* Handle the non-literal case. */
20395 while ((precision
<= 0 || n
< precision
)
20396 && SREF (elt
, offset
) != 0
20397 && (mode_line_target
!= MODE_LINE_DISPLAY
20398 || it
->current_x
< it
->last_visible_x
))
20400 ptrdiff_t last_offset
= offset
;
20402 /* Advance to end of string or next format specifier. */
20403 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20406 if (offset
- 1 != last_offset
)
20408 ptrdiff_t nchars
, nbytes
;
20410 /* Output to end of string or up to '%'. Field width
20411 is length of string. Don't output more than
20412 PRECISION allows us. */
20415 prec
= c_string_width (SDATA (elt
) + last_offset
,
20416 offset
- last_offset
, precision
- n
,
20419 switch (mode_line_target
)
20421 case MODE_LINE_NOPROP
:
20422 case MODE_LINE_TITLE
:
20423 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20425 case MODE_LINE_STRING
:
20427 ptrdiff_t bytepos
= last_offset
;
20428 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20429 ptrdiff_t endpos
= (precision
<= 0
20430 ? string_byte_to_char (elt
, offset
)
20431 : charpos
+ nchars
);
20433 n
+= store_mode_line_string (NULL
,
20434 Fsubstring (elt
, make_number (charpos
),
20435 make_number (endpos
)),
20439 case MODE_LINE_DISPLAY
:
20441 ptrdiff_t bytepos
= last_offset
;
20442 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20444 if (precision
<= 0)
20445 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20446 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20448 STRING_MULTIBYTE (elt
));
20453 else /* c == '%' */
20455 ptrdiff_t percent_position
= offset
;
20457 /* Get the specified minimum width. Zero means
20460 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20461 field
= field
* 10 + c
- '0';
20463 /* Don't pad beyond the total padding allowed. */
20464 if (field_width
- n
> 0 && field
> field_width
- n
)
20465 field
= field_width
- n
;
20467 /* Note that either PRECISION <= 0 or N < PRECISION. */
20468 prec
= precision
- n
;
20471 n
+= display_mode_element (it
, depth
, field
, prec
,
20472 Vglobal_mode_string
, props
,
20477 ptrdiff_t bytepos
, charpos
;
20479 Lisp_Object string
;
20481 bytepos
= percent_position
;
20482 charpos
= (STRING_MULTIBYTE (elt
)
20483 ? string_byte_to_char (elt
, bytepos
)
20485 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20486 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20488 switch (mode_line_target
)
20490 case MODE_LINE_NOPROP
:
20491 case MODE_LINE_TITLE
:
20492 n
+= store_mode_line_noprop (spec
, field
, prec
);
20494 case MODE_LINE_STRING
:
20496 Lisp_Object tem
= build_string (spec
);
20497 props
= Ftext_properties_at (make_number (charpos
), elt
);
20498 /* Should only keep face property in props */
20499 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20502 case MODE_LINE_DISPLAY
:
20504 int nglyphs_before
, nwritten
;
20506 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20507 nwritten
= display_string (spec
, string
, elt
,
20512 /* Assign to the glyphs written above the
20513 string where the `%x' came from, position
20517 struct glyph
*glyph
20518 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20522 for (i
= 0; i
< nwritten
; ++i
)
20524 glyph
[i
].object
= elt
;
20525 glyph
[i
].charpos
= charpos
;
20542 /* A symbol: process the value of the symbol recursively
20543 as if it appeared here directly. Avoid error if symbol void.
20544 Special case: if value of symbol is a string, output the string
20547 register Lisp_Object tem
;
20549 /* If the variable is not marked as risky to set
20550 then its contents are risky to use. */
20551 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20554 tem
= Fboundp (elt
);
20557 tem
= Fsymbol_value (elt
);
20558 /* If value is a string, output that string literally:
20559 don't check for % within it. */
20563 if (!EQ (tem
, elt
))
20565 /* Give up right away for nil or t. */
20575 register Lisp_Object car
, tem
;
20577 /* A cons cell: five distinct cases.
20578 If first element is :eval or :propertize, do something special.
20579 If first element is a string or a cons, process all the elements
20580 and effectively concatenate them.
20581 If first element is a negative number, truncate displaying cdr to
20582 at most that many characters. If positive, pad (with spaces)
20583 to at least that many characters.
20584 If first element is a symbol, process the cadr or caddr recursively
20585 according to whether the symbol's value is non-nil or nil. */
20587 if (EQ (car
, QCeval
))
20589 /* An element of the form (:eval FORM) means evaluate FORM
20590 and use the result as mode line elements. */
20595 if (CONSP (XCDR (elt
)))
20598 spec
= safe_eval (XCAR (XCDR (elt
)));
20599 n
+= display_mode_element (it
, depth
, field_width
- n
,
20600 precision
- n
, spec
, props
,
20604 else if (EQ (car
, QCpropertize
))
20606 /* An element of the form (:propertize ELT PROPS...)
20607 means display ELT but applying properties PROPS. */
20612 if (CONSP (XCDR (elt
)))
20613 n
+= display_mode_element (it
, depth
, field_width
- n
,
20614 precision
- n
, XCAR (XCDR (elt
)),
20615 XCDR (XCDR (elt
)), risky
);
20617 else if (SYMBOLP (car
))
20619 tem
= Fboundp (car
);
20623 /* elt is now the cdr, and we know it is a cons cell.
20624 Use its car if CAR has a non-nil value. */
20627 tem
= Fsymbol_value (car
);
20634 /* Symbol's value is nil (or symbol is unbound)
20635 Get the cddr of the original list
20636 and if possible find the caddr and use that. */
20640 else if (!CONSP (elt
))
20645 else if (INTEGERP (car
))
20647 register int lim
= XINT (car
);
20651 /* Negative int means reduce maximum width. */
20652 if (precision
<= 0)
20655 precision
= min (precision
, -lim
);
20659 /* Padding specified. Don't let it be more than
20660 current maximum. */
20662 lim
= min (precision
, lim
);
20664 /* If that's more padding than already wanted, queue it.
20665 But don't reduce padding already specified even if
20666 that is beyond the current truncation point. */
20667 field_width
= max (lim
, field_width
);
20671 else if (STRINGP (car
) || CONSP (car
))
20673 Lisp_Object halftail
= elt
;
20677 && (precision
<= 0 || n
< precision
))
20679 n
+= display_mode_element (it
, depth
,
20680 /* Do padding only after the last
20681 element in the list. */
20682 (! CONSP (XCDR (elt
))
20685 precision
- n
, XCAR (elt
),
20689 if ((len
& 1) == 0)
20690 halftail
= XCDR (halftail
);
20691 /* Check for cycle. */
20692 if (EQ (halftail
, elt
))
20701 elt
= build_string ("*invalid*");
20705 /* Pad to FIELD_WIDTH. */
20706 if (field_width
> 0 && n
< field_width
)
20708 switch (mode_line_target
)
20710 case MODE_LINE_NOPROP
:
20711 case MODE_LINE_TITLE
:
20712 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20714 case MODE_LINE_STRING
:
20715 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20717 case MODE_LINE_DISPLAY
:
20718 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20727 /* Store a mode-line string element in mode_line_string_list.
20729 If STRING is non-null, display that C string. Otherwise, the Lisp
20730 string LISP_STRING is displayed.
20732 FIELD_WIDTH is the minimum number of output glyphs to produce.
20733 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20734 with spaces. FIELD_WIDTH <= 0 means don't pad.
20736 PRECISION is the maximum number of characters to output from
20737 STRING. PRECISION <= 0 means don't truncate the string.
20739 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20740 properties to the string.
20742 PROPS are the properties to add to the string.
20743 The mode_line_string_face face property is always added to the string.
20747 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20748 int field_width
, int precision
, Lisp_Object props
)
20753 if (string
!= NULL
)
20755 len
= strlen (string
);
20756 if (precision
> 0 && len
> precision
)
20758 lisp_string
= make_string (string
, len
);
20760 props
= mode_line_string_face_prop
;
20761 else if (!NILP (mode_line_string_face
))
20763 Lisp_Object face
= Fplist_get (props
, Qface
);
20764 props
= Fcopy_sequence (props
);
20766 face
= mode_line_string_face
;
20768 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20769 props
= Fplist_put (props
, Qface
, face
);
20771 Fadd_text_properties (make_number (0), make_number (len
),
20772 props
, lisp_string
);
20776 len
= XFASTINT (Flength (lisp_string
));
20777 if (precision
> 0 && len
> precision
)
20780 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20783 if (!NILP (mode_line_string_face
))
20787 props
= Ftext_properties_at (make_number (0), lisp_string
);
20788 face
= Fplist_get (props
, Qface
);
20790 face
= mode_line_string_face
;
20792 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20793 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20795 lisp_string
= Fcopy_sequence (lisp_string
);
20798 Fadd_text_properties (make_number (0), make_number (len
),
20799 props
, lisp_string
);
20804 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20808 if (field_width
> len
)
20810 field_width
-= len
;
20811 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20813 Fadd_text_properties (make_number (0), make_number (field_width
),
20814 props
, lisp_string
);
20815 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20823 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20825 doc
: /* Format a string out of a mode line format specification.
20826 First arg FORMAT specifies the mode line format (see `mode-line-format'
20827 for details) to use.
20829 By default, the format is evaluated for the currently selected window.
20831 Optional second arg FACE specifies the face property to put on all
20832 characters for which no face is specified. The value nil means the
20833 default face. The value t means whatever face the window's mode line
20834 currently uses (either `mode-line' or `mode-line-inactive',
20835 depending on whether the window is the selected window or not).
20836 An integer value means the value string has no text
20839 Optional third and fourth args WINDOW and BUFFER specify the window
20840 and buffer to use as the context for the formatting (defaults
20841 are the selected window and the WINDOW's buffer). */)
20842 (Lisp_Object format
, Lisp_Object face
,
20843 Lisp_Object window
, Lisp_Object buffer
)
20848 struct buffer
*old_buffer
= NULL
;
20850 int no_props
= INTEGERP (face
);
20851 ptrdiff_t count
= SPECPDL_INDEX ();
20853 int string_start
= 0;
20856 window
= selected_window
;
20857 CHECK_WINDOW (window
);
20858 w
= XWINDOW (window
);
20861 buffer
= w
->buffer
;
20862 CHECK_BUFFER (buffer
);
20864 /* Make formatting the modeline a non-op when noninteractive, otherwise
20865 there will be problems later caused by a partially initialized frame. */
20866 if (NILP (format
) || noninteractive
)
20867 return empty_unibyte_string
;
20872 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20873 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20874 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20875 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20876 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20877 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20878 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20881 if (XBUFFER (buffer
) != current_buffer
)
20882 old_buffer
= current_buffer
;
20884 /* Save things including mode_line_proptrans_alist,
20885 and set that to nil so that we don't alter the outer value. */
20886 record_unwind_protect (unwind_format_mode_line
,
20887 format_mode_line_unwind_data
20888 (XFRAME (WINDOW_FRAME (XWINDOW (window
))),
20889 old_buffer
, selected_window
, 1));
20890 mode_line_proptrans_alist
= Qnil
;
20892 Fselect_window (window
, Qt
);
20894 set_buffer_internal_1 (XBUFFER (buffer
));
20896 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20900 mode_line_target
= MODE_LINE_NOPROP
;
20901 mode_line_string_face_prop
= Qnil
;
20902 mode_line_string_list
= Qnil
;
20903 string_start
= MODE_LINE_NOPROP_LEN (0);
20907 mode_line_target
= MODE_LINE_STRING
;
20908 mode_line_string_list
= Qnil
;
20909 mode_line_string_face
= face
;
20910 mode_line_string_face_prop
20911 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20914 push_kboard (FRAME_KBOARD (it
.f
));
20915 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20920 len
= MODE_LINE_NOPROP_LEN (string_start
);
20921 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20925 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20926 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20927 empty_unibyte_string
);
20930 unbind_to (count
, Qnil
);
20934 /* Write a null-terminated, right justified decimal representation of
20935 the positive integer D to BUF using a minimal field width WIDTH. */
20938 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20940 register char *p
= buf
;
20948 *p
++ = d
% 10 + '0';
20953 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20964 /* Write a null-terminated, right justified decimal and "human
20965 readable" representation of the nonnegative integer D to BUF using
20966 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20968 static const char power_letter
[] =
20982 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20984 /* We aim to represent the nonnegative integer D as
20985 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20986 ptrdiff_t quotient
= d
;
20988 /* -1 means: do not use TENTHS. */
20992 /* Length of QUOTIENT.TENTHS as a string. */
20998 if (1000 <= quotient
)
21000 /* Scale to the appropriate EXPONENT. */
21003 remainder
= quotient
% 1000;
21007 while (1000 <= quotient
);
21009 /* Round to nearest and decide whether to use TENTHS or not. */
21012 tenths
= remainder
/ 100;
21013 if (50 <= remainder
% 100)
21020 if (quotient
== 10)
21028 if (500 <= remainder
)
21030 if (quotient
< 999)
21041 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21042 if (tenths
== -1 && quotient
<= 99)
21049 p
= psuffix
= buf
+ max (width
, length
);
21051 /* Print EXPONENT. */
21052 *psuffix
++ = power_letter
[exponent
];
21055 /* Print TENTHS. */
21058 *--p
= '0' + tenths
;
21062 /* Print QUOTIENT. */
21065 int digit
= quotient
% 10;
21066 *--p
= '0' + digit
;
21068 while ((quotient
/= 10) != 0);
21070 /* Print leading spaces. */
21075 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21076 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21077 type of CODING_SYSTEM. Return updated pointer into BUF. */
21079 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21082 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21085 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21086 const unsigned char *eol_str
;
21088 /* The EOL conversion we are using. */
21089 Lisp_Object eoltype
;
21091 val
= CODING_SYSTEM_SPEC (coding_system
);
21094 if (!VECTORP (val
)) /* Not yet decided. */
21096 *buf
++ = multibyte
? '-' : ' ';
21098 eoltype
= eol_mnemonic_undecided
;
21099 /* Don't mention EOL conversion if it isn't decided. */
21104 Lisp_Object eolvalue
;
21106 attrs
= AREF (val
, 0);
21107 eolvalue
= AREF (val
, 2);
21110 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21115 /* The EOL conversion that is normal on this system. */
21117 if (NILP (eolvalue
)) /* Not yet decided. */
21118 eoltype
= eol_mnemonic_undecided
;
21119 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21120 eoltype
= eol_mnemonic_undecided
;
21121 else /* eolvalue is Qunix, Qdos, or Qmac. */
21122 eoltype
= (EQ (eolvalue
, Qunix
)
21123 ? eol_mnemonic_unix
21124 : (EQ (eolvalue
, Qdos
) == 1
21125 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21131 /* Mention the EOL conversion if it is not the usual one. */
21132 if (STRINGP (eoltype
))
21134 eol_str
= SDATA (eoltype
);
21135 eol_str_len
= SBYTES (eoltype
);
21137 else if (CHARACTERP (eoltype
))
21139 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21140 int c
= XFASTINT (eoltype
);
21141 eol_str_len
= CHAR_STRING (c
, tmp
);
21146 eol_str
= invalid_eol_type
;
21147 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21149 memcpy (buf
, eol_str
, eol_str_len
);
21150 buf
+= eol_str_len
;
21156 /* Return a string for the output of a mode line %-spec for window W,
21157 generated by character C. FIELD_WIDTH > 0 means pad the string
21158 returned with spaces to that value. Return a Lisp string in
21159 *STRING if the resulting string is taken from that Lisp string.
21161 Note we operate on the current buffer for most purposes,
21162 the exception being w->base_line_pos. */
21164 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21166 static const char *
21167 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21168 Lisp_Object
*string
)
21171 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21172 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21173 struct buffer
*b
= current_buffer
;
21181 if (!NILP (BVAR (b
, read_only
)))
21183 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21188 /* This differs from %* only for a modified read-only buffer. */
21189 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21191 if (!NILP (BVAR (b
, read_only
)))
21196 /* This differs from %* in ignoring read-only-ness. */
21197 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21209 if (command_loop_level
> 5)
21211 p
= decode_mode_spec_buf
;
21212 for (i
= 0; i
< command_loop_level
; i
++)
21215 return decode_mode_spec_buf
;
21223 if (command_loop_level
> 5)
21225 p
= decode_mode_spec_buf
;
21226 for (i
= 0; i
< command_loop_level
; i
++)
21229 return decode_mode_spec_buf
;
21236 /* Let lots_of_dashes be a string of infinite length. */
21237 if (mode_line_target
== MODE_LINE_NOPROP
||
21238 mode_line_target
== MODE_LINE_STRING
)
21240 if (field_width
<= 0
21241 || field_width
> sizeof (lots_of_dashes
))
21243 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21244 decode_mode_spec_buf
[i
] = '-';
21245 decode_mode_spec_buf
[i
] = '\0';
21246 return decode_mode_spec_buf
;
21249 return lots_of_dashes
;
21253 obj
= BVAR (b
, name
);
21257 /* %c and %l are ignored in `frame-title-format'.
21258 (In redisplay_internal, the frame title is drawn _before_ the
21259 windows are updated, so the stuff which depends on actual
21260 window contents (such as %l) may fail to render properly, or
21261 even crash emacs.) */
21262 if (mode_line_target
== MODE_LINE_TITLE
)
21266 ptrdiff_t col
= current_column ();
21267 w
->column_number_displayed
= make_number (col
);
21268 pint2str (decode_mode_spec_buf
, field_width
, col
);
21269 return decode_mode_spec_buf
;
21273 #ifndef SYSTEM_MALLOC
21275 if (NILP (Vmemory_full
))
21278 return "!MEM FULL! ";
21285 /* %F displays the frame name. */
21286 if (!NILP (f
->title
))
21287 return SSDATA (f
->title
);
21288 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21289 return SSDATA (f
->name
);
21293 obj
= BVAR (b
, filename
);
21298 ptrdiff_t size
= ZV
- BEGV
;
21299 pint2str (decode_mode_spec_buf
, field_width
, size
);
21300 return decode_mode_spec_buf
;
21305 ptrdiff_t size
= ZV
- BEGV
;
21306 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21307 return decode_mode_spec_buf
;
21312 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21313 ptrdiff_t topline
, nlines
, height
;
21316 /* %c and %l are ignored in `frame-title-format'. */
21317 if (mode_line_target
== MODE_LINE_TITLE
)
21320 startpos
= XMARKER (w
->start
)->charpos
;
21321 startpos_byte
= marker_byte_position (w
->start
);
21322 height
= WINDOW_TOTAL_LINES (w
);
21324 /* If we decided that this buffer isn't suitable for line numbers,
21325 don't forget that too fast. */
21326 if (EQ (w
->base_line_pos
, w
->buffer
))
21328 /* But do forget it, if the window shows a different buffer now. */
21329 else if (BUFFERP (w
->base_line_pos
))
21330 w
->base_line_pos
= Qnil
;
21332 /* If the buffer is very big, don't waste time. */
21333 if (INTEGERP (Vline_number_display_limit
)
21334 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21336 w
->base_line_pos
= Qnil
;
21337 w
->base_line_number
= Qnil
;
21341 if (INTEGERP (w
->base_line_number
)
21342 && INTEGERP (w
->base_line_pos
)
21343 && XFASTINT (w
->base_line_pos
) <= startpos
)
21345 line
= XFASTINT (w
->base_line_number
);
21346 linepos
= XFASTINT (w
->base_line_pos
);
21347 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21352 linepos
= BUF_BEGV (b
);
21353 linepos_byte
= BUF_BEGV_BYTE (b
);
21356 /* Count lines from base line to window start position. */
21357 nlines
= display_count_lines (linepos_byte
,
21361 topline
= nlines
+ line
;
21363 /* Determine a new base line, if the old one is too close
21364 or too far away, or if we did not have one.
21365 "Too close" means it's plausible a scroll-down would
21366 go back past it. */
21367 if (startpos
== BUF_BEGV (b
))
21369 w
->base_line_number
= make_number (topline
);
21370 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21372 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21373 || linepos
== BUF_BEGV (b
))
21375 ptrdiff_t limit
= BUF_BEGV (b
);
21376 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21377 ptrdiff_t position
;
21378 ptrdiff_t distance
=
21379 (height
* 2 + 30) * line_number_display_limit_width
;
21381 if (startpos
- distance
> limit
)
21383 limit
= startpos
- distance
;
21384 limit_byte
= CHAR_TO_BYTE (limit
);
21387 nlines
= display_count_lines (startpos_byte
,
21389 - (height
* 2 + 30),
21391 /* If we couldn't find the lines we wanted within
21392 line_number_display_limit_width chars per line,
21393 give up on line numbers for this window. */
21394 if (position
== limit_byte
&& limit
== startpos
- distance
)
21396 w
->base_line_pos
= w
->buffer
;
21397 w
->base_line_number
= Qnil
;
21401 w
->base_line_number
= make_number (topline
- nlines
);
21402 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21405 /* Now count lines from the start pos to point. */
21406 nlines
= display_count_lines (startpos_byte
,
21407 PT_BYTE
, PT
, &junk
);
21409 /* Record that we did display the line number. */
21410 line_number_displayed
= 1;
21412 /* Make the string to show. */
21413 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21414 return decode_mode_spec_buf
;
21417 char* p
= decode_mode_spec_buf
;
21418 int pad
= field_width
- 2;
21424 return decode_mode_spec_buf
;
21430 obj
= BVAR (b
, mode_name
);
21434 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21440 ptrdiff_t pos
= marker_position (w
->start
);
21441 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21443 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21445 if (pos
<= BUF_BEGV (b
))
21450 else if (pos
<= BUF_BEGV (b
))
21454 if (total
> 1000000)
21455 /* Do it differently for a large value, to avoid overflow. */
21456 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21458 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21459 /* We can't normally display a 3-digit number,
21460 so get us a 2-digit number that is close. */
21463 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21464 return decode_mode_spec_buf
;
21468 /* Display percentage of size above the bottom of the screen. */
21471 ptrdiff_t toppos
= marker_position (w
->start
);
21472 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21473 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21475 if (botpos
>= BUF_ZV (b
))
21477 if (toppos
<= BUF_BEGV (b
))
21484 if (total
> 1000000)
21485 /* Do it differently for a large value, to avoid overflow. */
21486 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21488 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21489 /* We can't normally display a 3-digit number,
21490 so get us a 2-digit number that is close. */
21493 if (toppos
<= BUF_BEGV (b
))
21494 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21496 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21497 return decode_mode_spec_buf
;
21502 /* status of process */
21503 obj
= Fget_buffer_process (Fcurrent_buffer ());
21505 return "no process";
21507 obj
= Fsymbol_name (Fprocess_status (obj
));
21513 ptrdiff_t count
= inhibit_garbage_collection ();
21514 Lisp_Object val
= call1 (intern ("file-remote-p"),
21515 BVAR (current_buffer
, directory
));
21516 unbind_to (count
, Qnil
);
21524 case 't': /* indicate TEXT or BINARY */
21528 /* coding-system (not including end-of-line format) */
21530 /* coding-system (including end-of-line type) */
21532 int eol_flag
= (c
== 'Z');
21533 char *p
= decode_mode_spec_buf
;
21535 if (! FRAME_WINDOW_P (f
))
21537 /* No need to mention EOL here--the terminal never needs
21538 to do EOL conversion. */
21539 p
= decode_mode_spec_coding (CODING_ID_NAME
21540 (FRAME_KEYBOARD_CODING (f
)->id
),
21542 p
= decode_mode_spec_coding (CODING_ID_NAME
21543 (FRAME_TERMINAL_CODING (f
)->id
),
21546 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21549 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21550 #ifdef subprocesses
21551 obj
= Fget_buffer_process (Fcurrent_buffer ());
21552 if (PROCESSP (obj
))
21554 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21556 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21559 #endif /* subprocesses */
21562 return decode_mode_spec_buf
;
21569 return SSDATA (obj
);
21576 /* Count up to COUNT lines starting from START_BYTE.
21577 But don't go beyond LIMIT_BYTE.
21578 Return the number of lines thus found (always nonnegative).
21580 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21583 display_count_lines (ptrdiff_t start_byte
,
21584 ptrdiff_t limit_byte
, ptrdiff_t count
,
21585 ptrdiff_t *byte_pos_ptr
)
21587 register unsigned char *cursor
;
21588 unsigned char *base
;
21590 register ptrdiff_t ceiling
;
21591 register unsigned char *ceiling_addr
;
21592 ptrdiff_t orig_count
= count
;
21594 /* If we are not in selective display mode,
21595 check only for newlines. */
21596 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21597 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21601 while (start_byte
< limit_byte
)
21603 ceiling
= BUFFER_CEILING_OF (start_byte
);
21604 ceiling
= min (limit_byte
- 1, ceiling
);
21605 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21606 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21609 if (selective_display
)
21610 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21613 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21616 if (cursor
!= ceiling_addr
)
21620 start_byte
+= cursor
- base
+ 1;
21621 *byte_pos_ptr
= start_byte
;
21625 if (++cursor
== ceiling_addr
)
21631 start_byte
+= cursor
- base
;
21636 while (start_byte
> limit_byte
)
21638 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21639 ceiling
= max (limit_byte
, ceiling
);
21640 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21641 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21644 if (selective_display
)
21645 while (--cursor
!= ceiling_addr
21646 && *cursor
!= '\n' && *cursor
!= 015)
21649 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21652 if (cursor
!= ceiling_addr
)
21656 start_byte
+= cursor
- base
+ 1;
21657 *byte_pos_ptr
= start_byte
;
21658 /* When scanning backwards, we should
21659 not count the newline posterior to which we stop. */
21660 return - orig_count
- 1;
21666 /* Here we add 1 to compensate for the last decrement
21667 of CURSOR, which took it past the valid range. */
21668 start_byte
+= cursor
- base
+ 1;
21672 *byte_pos_ptr
= limit_byte
;
21675 return - orig_count
+ count
;
21676 return orig_count
- count
;
21682 /***********************************************************************
21684 ***********************************************************************/
21686 /* Display a NUL-terminated string, starting with index START.
21688 If STRING is non-null, display that C string. Otherwise, the Lisp
21689 string LISP_STRING is displayed. There's a case that STRING is
21690 non-null and LISP_STRING is not nil. It means STRING is a string
21691 data of LISP_STRING. In that case, we display LISP_STRING while
21692 ignoring its text properties.
21694 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21695 FACE_STRING. Display STRING or LISP_STRING with the face at
21696 FACE_STRING_POS in FACE_STRING:
21698 Display the string in the environment given by IT, but use the
21699 standard display table, temporarily.
21701 FIELD_WIDTH is the minimum number of output glyphs to produce.
21702 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21703 with spaces. If STRING has more characters, more than FIELD_WIDTH
21704 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21706 PRECISION is the maximum number of characters to output from
21707 STRING. PRECISION < 0 means don't truncate the string.
21709 This is roughly equivalent to printf format specifiers:
21711 FIELD_WIDTH PRECISION PRINTF
21712 ----------------------------------------
21718 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21719 display them, and < 0 means obey the current buffer's value of
21720 enable_multibyte_characters.
21722 Value is the number of columns displayed. */
21725 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21726 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21727 int field_width
, int precision
, int max_x
, int multibyte
)
21729 int hpos_at_start
= it
->hpos
;
21730 int saved_face_id
= it
->face_id
;
21731 struct glyph_row
*row
= it
->glyph_row
;
21732 ptrdiff_t it_charpos
;
21734 /* Initialize the iterator IT for iteration over STRING beginning
21735 with index START. */
21736 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21737 precision
, field_width
, multibyte
);
21738 if (string
&& STRINGP (lisp_string
))
21739 /* LISP_STRING is the one returned by decode_mode_spec. We should
21740 ignore its text properties. */
21741 it
->stop_charpos
= it
->end_charpos
;
21743 /* If displaying STRING, set up the face of the iterator from
21744 FACE_STRING, if that's given. */
21745 if (STRINGP (face_string
))
21751 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21752 0, it
->region_beg_charpos
,
21753 it
->region_end_charpos
,
21754 &endptr
, it
->base_face_id
, 0);
21755 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21756 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21759 /* Set max_x to the maximum allowed X position. Don't let it go
21760 beyond the right edge of the window. */
21762 max_x
= it
->last_visible_x
;
21764 max_x
= min (max_x
, it
->last_visible_x
);
21766 /* Skip over display elements that are not visible. because IT->w is
21768 if (it
->current_x
< it
->first_visible_x
)
21769 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21770 MOVE_TO_POS
| MOVE_TO_X
);
21772 row
->ascent
= it
->max_ascent
;
21773 row
->height
= it
->max_ascent
+ it
->max_descent
;
21774 row
->phys_ascent
= it
->max_phys_ascent
;
21775 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21776 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21778 if (STRINGP (it
->string
))
21779 it_charpos
= IT_STRING_CHARPOS (*it
);
21781 it_charpos
= IT_CHARPOS (*it
);
21783 /* This condition is for the case that we are called with current_x
21784 past last_visible_x. */
21785 while (it
->current_x
< max_x
)
21787 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21789 /* Get the next display element. */
21790 if (!get_next_display_element (it
))
21793 /* Produce glyphs. */
21794 x_before
= it
->current_x
;
21795 n_glyphs_before
= row
->used
[TEXT_AREA
];
21796 PRODUCE_GLYPHS (it
);
21798 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21801 while (i
< nglyphs
)
21803 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21805 if (it
->line_wrap
!= TRUNCATE
21806 && x
+ glyph
->pixel_width
> max_x
)
21808 /* End of continued line or max_x reached. */
21809 if (CHAR_GLYPH_PADDING_P (*glyph
))
21811 /* A wide character is unbreakable. */
21812 if (row
->reversed_p
)
21813 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21814 - n_glyphs_before
);
21815 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21816 it
->current_x
= x_before
;
21820 if (row
->reversed_p
)
21821 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21822 - (n_glyphs_before
+ i
));
21823 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21828 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21830 /* Glyph is at least partially visible. */
21832 if (x
< it
->first_visible_x
)
21833 row
->x
= x
- it
->first_visible_x
;
21837 /* Glyph is off the left margin of the display area.
21838 Should not happen. */
21842 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21843 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21844 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21845 row
->phys_height
= max (row
->phys_height
,
21846 it
->max_phys_ascent
+ it
->max_phys_descent
);
21847 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21848 it
->max_extra_line_spacing
);
21849 x
+= glyph
->pixel_width
;
21853 /* Stop if max_x reached. */
21857 /* Stop at line ends. */
21858 if (ITERATOR_AT_END_OF_LINE_P (it
))
21860 it
->continuation_lines_width
= 0;
21864 set_iterator_to_next (it
, 1);
21865 if (STRINGP (it
->string
))
21866 it_charpos
= IT_STRING_CHARPOS (*it
);
21868 it_charpos
= IT_CHARPOS (*it
);
21870 /* Stop if truncating at the right edge. */
21871 if (it
->line_wrap
== TRUNCATE
21872 && it
->current_x
>= it
->last_visible_x
)
21874 /* Add truncation mark, but don't do it if the line is
21875 truncated at a padding space. */
21876 if (it_charpos
< it
->string_nchars
)
21878 if (!FRAME_WINDOW_P (it
->f
))
21882 if (it
->current_x
> it
->last_visible_x
)
21884 if (!row
->reversed_p
)
21886 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21887 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21892 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21893 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21895 unproduce_glyphs (it
, ii
+ 1);
21896 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21898 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21900 row
->used
[TEXT_AREA
] = ii
;
21901 produce_special_glyphs (it
, IT_TRUNCATION
);
21904 produce_special_glyphs (it
, IT_TRUNCATION
);
21906 row
->truncated_on_right_p
= 1;
21912 /* Maybe insert a truncation at the left. */
21913 if (it
->first_visible_x
21916 if (!FRAME_WINDOW_P (it
->f
))
21917 insert_left_trunc_glyphs (it
);
21918 row
->truncated_on_left_p
= 1;
21921 it
->face_id
= saved_face_id
;
21923 /* Value is number of columns displayed. */
21924 return it
->hpos
- hpos_at_start
;
21929 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21930 appears as an element of LIST or as the car of an element of LIST.
21931 If PROPVAL is a list, compare each element against LIST in that
21932 way, and return 1/2 if any element of PROPVAL is found in LIST.
21933 Otherwise return 0. This function cannot quit.
21934 The return value is 2 if the text is invisible but with an ellipsis
21935 and 1 if it's invisible and without an ellipsis. */
21938 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21940 register Lisp_Object tail
, proptail
;
21942 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21944 register Lisp_Object tem
;
21946 if (EQ (propval
, tem
))
21948 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21949 return NILP (XCDR (tem
)) ? 1 : 2;
21952 if (CONSP (propval
))
21954 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21956 Lisp_Object propelt
;
21957 propelt
= XCAR (proptail
);
21958 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21960 register Lisp_Object tem
;
21962 if (EQ (propelt
, tem
))
21964 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21965 return NILP (XCDR (tem
)) ? 1 : 2;
21973 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21974 doc
: /* Non-nil if the property makes the text invisible.
21975 POS-OR-PROP can be a marker or number, in which case it is taken to be
21976 a position in the current buffer and the value of the `invisible' property
21977 is checked; or it can be some other value, which is then presumed to be the
21978 value of the `invisible' property of the text of interest.
21979 The non-nil value returned can be t for truly invisible text or something
21980 else if the text is replaced by an ellipsis. */)
21981 (Lisp_Object pos_or_prop
)
21984 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21985 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21987 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21988 return (invis
== 0 ? Qnil
21990 : make_number (invis
));
21993 /* Calculate a width or height in pixels from a specification using
21994 the following elements:
21997 NUM - a (fractional) multiple of the default font width/height
21998 (NUM) - specifies exactly NUM pixels
21999 UNIT - a fixed number of pixels, see below.
22000 ELEMENT - size of a display element in pixels, see below.
22001 (NUM . SPEC) - equals NUM * SPEC
22002 (+ SPEC SPEC ...) - add pixel values
22003 (- SPEC SPEC ...) - subtract pixel values
22004 (- SPEC) - negate pixel value
22007 INT or FLOAT - a number constant
22008 SYMBOL - use symbol's (buffer local) variable binding.
22011 in - pixels per inch *)
22012 mm - pixels per 1/1000 meter *)
22013 cm - pixels per 1/100 meter *)
22014 width - width of current font in pixels.
22015 height - height of current font in pixels.
22017 *) using the ratio(s) defined in display-pixels-per-inch.
22021 left-fringe - left fringe width in pixels
22022 right-fringe - right fringe width in pixels
22024 left-margin - left margin width in pixels
22025 right-margin - right margin width in pixels
22027 scroll-bar - scroll-bar area width in pixels
22031 Pixels corresponding to 5 inches:
22034 Total width of non-text areas on left side of window (if scroll-bar is on left):
22035 '(space :width (+ left-fringe left-margin scroll-bar))
22037 Align to first text column (in header line):
22038 '(space :align-to 0)
22040 Align to middle of text area minus half the width of variable `my-image'
22041 containing a loaded image:
22042 '(space :align-to (0.5 . (- text my-image)))
22044 Width of left margin minus width of 1 character in the default font:
22045 '(space :width (- left-margin 1))
22047 Width of left margin minus width of 2 characters in the current font:
22048 '(space :width (- left-margin (2 . width)))
22050 Center 1 character over left-margin (in header line):
22051 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22053 Different ways to express width of left fringe plus left margin minus one pixel:
22054 '(space :width (- (+ left-fringe left-margin) (1)))
22055 '(space :width (+ left-fringe left-margin (- (1))))
22056 '(space :width (+ left-fringe left-margin (-1)))
22060 #define NUMVAL(X) \
22061 ((INTEGERP (X) || FLOATP (X)) \
22066 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22067 struct font
*font
, int width_p
, int *align_to
)
22071 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22072 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22075 return OK_PIXELS (0);
22077 eassert (FRAME_LIVE_P (it
->f
));
22079 if (SYMBOLP (prop
))
22081 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22083 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22085 if (unit
[0] == 'i' && unit
[1] == 'n')
22087 else if (unit
[0] == 'm' && unit
[1] == 'm')
22089 else if (unit
[0] == 'c' && unit
[1] == 'm')
22096 #ifdef HAVE_WINDOW_SYSTEM
22097 if (FRAME_WINDOW_P (it
->f
)
22099 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22100 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22102 return OK_PIXELS (ppi
/ pixels
);
22105 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22106 || (CONSP (Vdisplay_pixels_per_inch
)
22108 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22109 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22111 return OK_PIXELS (ppi
/ pixels
);
22117 #ifdef HAVE_WINDOW_SYSTEM
22118 if (EQ (prop
, Qheight
))
22119 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22120 if (EQ (prop
, Qwidth
))
22121 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22123 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22124 return OK_PIXELS (1);
22127 if (EQ (prop
, Qtext
))
22128 return OK_PIXELS (width_p
22129 ? window_box_width (it
->w
, TEXT_AREA
)
22130 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22132 if (align_to
&& *align_to
< 0)
22135 if (EQ (prop
, Qleft
))
22136 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22137 if (EQ (prop
, Qright
))
22138 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22139 if (EQ (prop
, Qcenter
))
22140 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22141 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22142 if (EQ (prop
, Qleft_fringe
))
22143 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22144 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22145 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22146 if (EQ (prop
, Qright_fringe
))
22147 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22148 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22149 : window_box_right_offset (it
->w
, TEXT_AREA
));
22150 if (EQ (prop
, Qleft_margin
))
22151 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22152 if (EQ (prop
, Qright_margin
))
22153 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22154 if (EQ (prop
, Qscroll_bar
))
22155 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22157 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22158 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22159 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22164 if (EQ (prop
, Qleft_fringe
))
22165 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22166 if (EQ (prop
, Qright_fringe
))
22167 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22168 if (EQ (prop
, Qleft_margin
))
22169 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22170 if (EQ (prop
, Qright_margin
))
22171 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22172 if (EQ (prop
, Qscroll_bar
))
22173 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22176 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22177 if (EQ (prop
, Qunbound
))
22181 if (INTEGERP (prop
) || FLOATP (prop
))
22183 int base_unit
= (width_p
22184 ? FRAME_COLUMN_WIDTH (it
->f
)
22185 : FRAME_LINE_HEIGHT (it
->f
));
22186 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22191 Lisp_Object car
= XCAR (prop
);
22192 Lisp_Object cdr
= XCDR (prop
);
22196 #ifdef HAVE_WINDOW_SYSTEM
22197 if (FRAME_WINDOW_P (it
->f
)
22198 && valid_image_p (prop
))
22200 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22201 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22203 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22206 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22212 while (CONSP (cdr
))
22214 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22215 font
, width_p
, align_to
))
22218 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22223 if (EQ (car
, Qminus
))
22225 return OK_PIXELS (pixels
);
22228 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22229 if (EQ (car
, Qunbound
))
22233 if (INTEGERP (car
) || FLOATP (car
))
22236 pixels
= XFLOATINT (car
);
22238 return OK_PIXELS (pixels
);
22239 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22240 font
, width_p
, align_to
))
22241 return OK_PIXELS (pixels
* fact
);
22252 /***********************************************************************
22254 ***********************************************************************/
22256 #ifdef HAVE_WINDOW_SYSTEM
22261 dump_glyph_string (struct glyph_string
*s
)
22263 fprintf (stderr
, "glyph string\n");
22264 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22265 s
->x
, s
->y
, s
->width
, s
->height
);
22266 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22267 fprintf (stderr
, " hl = %d\n", s
->hl
);
22268 fprintf (stderr
, " left overhang = %d, right = %d\n",
22269 s
->left_overhang
, s
->right_overhang
);
22270 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22271 fprintf (stderr
, " extends to end of line = %d\n",
22272 s
->extends_to_end_of_line_p
);
22273 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22274 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22277 #endif /* GLYPH_DEBUG */
22279 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22280 of XChar2b structures for S; it can't be allocated in
22281 init_glyph_string because it must be allocated via `alloca'. W
22282 is the window on which S is drawn. ROW and AREA are the glyph row
22283 and area within the row from which S is constructed. START is the
22284 index of the first glyph structure covered by S. HL is a
22285 face-override for drawing S. */
22288 #define OPTIONAL_HDC(hdc) HDC hdc,
22289 #define DECLARE_HDC(hdc) HDC hdc;
22290 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22291 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22294 #ifndef OPTIONAL_HDC
22295 #define OPTIONAL_HDC(hdc)
22296 #define DECLARE_HDC(hdc)
22297 #define ALLOCATE_HDC(hdc, f)
22298 #define RELEASE_HDC(hdc, f)
22302 init_glyph_string (struct glyph_string
*s
,
22304 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22305 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22307 memset (s
, 0, sizeof *s
);
22309 s
->f
= XFRAME (w
->frame
);
22313 s
->display
= FRAME_X_DISPLAY (s
->f
);
22314 s
->window
= FRAME_X_WINDOW (s
->f
);
22315 s
->char2b
= char2b
;
22319 s
->first_glyph
= row
->glyphs
[area
] + start
;
22320 s
->height
= row
->height
;
22321 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22322 s
->ybase
= s
->y
+ row
->ascent
;
22326 /* Append the list of glyph strings with head H and tail T to the list
22327 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22330 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22331 struct glyph_string
*h
, struct glyph_string
*t
)
22345 /* Prepend the list of glyph strings with head H and tail T to the
22346 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22350 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22351 struct glyph_string
*h
, struct glyph_string
*t
)
22365 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22366 Set *HEAD and *TAIL to the resulting list. */
22369 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22370 struct glyph_string
*s
)
22372 s
->next
= s
->prev
= NULL
;
22373 append_glyph_string_lists (head
, tail
, s
, s
);
22377 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22378 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22379 make sure that X resources for the face returned are allocated.
22380 Value is a pointer to a realized face that is ready for display if
22381 DISPLAY_P is non-zero. */
22383 static inline struct face
*
22384 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22385 XChar2b
*char2b
, int display_p
)
22387 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22391 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22393 if (code
!= FONT_INVALID_CODE
)
22394 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22396 STORE_XCHAR2B (char2b
, 0, 0);
22399 /* Make sure X resources of the face are allocated. */
22400 #ifdef HAVE_X_WINDOWS
22404 eassert (face
!= NULL
);
22405 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22412 /* Get face and two-byte form of character glyph GLYPH on frame F.
22413 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22414 a pointer to a realized face that is ready for display. */
22416 static inline struct face
*
22417 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22418 XChar2b
*char2b
, int *two_byte_p
)
22422 eassert (glyph
->type
== CHAR_GLYPH
);
22423 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22432 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22433 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22435 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22437 if (code
!= FONT_INVALID_CODE
)
22438 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22440 STORE_XCHAR2B (char2b
, 0, 0);
22443 /* Make sure X resources of the face are allocated. */
22444 eassert (face
!= NULL
);
22445 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22450 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22451 Return 1 if FONT has a glyph for C, otherwise return 0. */
22454 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22458 if (CHAR_BYTE8_P (c
))
22459 code
= CHAR_TO_BYTE8 (c
);
22461 code
= font
->driver
->encode_char (font
, c
);
22463 if (code
== FONT_INVALID_CODE
)
22465 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22470 /* Fill glyph string S with composition components specified by S->cmp.
22472 BASE_FACE is the base face of the composition.
22473 S->cmp_from is the index of the first component for S.
22475 OVERLAPS non-zero means S should draw the foreground only, and use
22476 its physical height for clipping. See also draw_glyphs.
22478 Value is the index of a component not in S. */
22481 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22485 /* For all glyphs of this composition, starting at the offset
22486 S->cmp_from, until we reach the end of the definition or encounter a
22487 glyph that requires the different face, add it to S. */
22492 s
->for_overlaps
= overlaps
;
22495 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22497 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22499 /* TAB in a composition means display glyphs with padding space
22500 on the left or right. */
22503 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22506 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22513 s
->font
= s
->face
->font
;
22515 else if (s
->face
!= face
)
22523 if (s
->face
== NULL
)
22525 s
->face
= base_face
->ascii_face
;
22526 s
->font
= s
->face
->font
;
22529 /* All glyph strings for the same composition has the same width,
22530 i.e. the width set for the first component of the composition. */
22531 s
->width
= s
->first_glyph
->pixel_width
;
22533 /* If the specified font could not be loaded, use the frame's
22534 default font, but record the fact that we couldn't load it in
22535 the glyph string so that we can draw rectangles for the
22536 characters of the glyph string. */
22537 if (s
->font
== NULL
)
22539 s
->font_not_found_p
= 1;
22540 s
->font
= FRAME_FONT (s
->f
);
22543 /* Adjust base line for subscript/superscript text. */
22544 s
->ybase
+= s
->first_glyph
->voffset
;
22546 /* This glyph string must always be drawn with 16-bit functions. */
22553 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22554 int start
, int end
, int overlaps
)
22556 struct glyph
*glyph
, *last
;
22557 Lisp_Object lgstring
;
22560 s
->for_overlaps
= overlaps
;
22561 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22562 last
= s
->row
->glyphs
[s
->area
] + end
;
22563 s
->cmp_id
= glyph
->u
.cmp
.id
;
22564 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22565 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22566 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22567 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22568 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22570 while (glyph
< last
22571 && glyph
->u
.cmp
.automatic
22572 && glyph
->u
.cmp
.id
== s
->cmp_id
22573 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22574 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22576 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22578 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22579 unsigned code
= LGLYPH_CODE (lglyph
);
22581 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22583 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22584 return glyph
- s
->row
->glyphs
[s
->area
];
22588 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22589 See the comment of fill_glyph_string for arguments.
22590 Value is the index of the first glyph not in S. */
22594 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22595 int start
, int end
, int overlaps
)
22597 struct glyph
*glyph
, *last
;
22600 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22601 s
->for_overlaps
= overlaps
;
22602 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22603 last
= s
->row
->glyphs
[s
->area
] + end
;
22604 voffset
= glyph
->voffset
;
22605 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22606 s
->font
= s
->face
->font
;
22608 s
->width
= glyph
->pixel_width
;
22610 while (glyph
< last
22611 && glyph
->type
== GLYPHLESS_GLYPH
22612 && glyph
->voffset
== voffset
22613 && glyph
->face_id
== face_id
)
22616 s
->width
+= glyph
->pixel_width
;
22619 s
->ybase
+= voffset
;
22620 return glyph
- s
->row
->glyphs
[s
->area
];
22624 /* Fill glyph string S from a sequence of character glyphs.
22626 FACE_ID is the face id of the string. START is the index of the
22627 first glyph to consider, END is the index of the last + 1.
22628 OVERLAPS non-zero means S should draw the foreground only, and use
22629 its physical height for clipping. See also draw_glyphs.
22631 Value is the index of the first glyph not in S. */
22634 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22635 int start
, int end
, int overlaps
)
22637 struct glyph
*glyph
, *last
;
22639 int glyph_not_available_p
;
22641 eassert (s
->f
== XFRAME (s
->w
->frame
));
22642 eassert (s
->nchars
== 0);
22643 eassert (start
>= 0 && end
> start
);
22645 s
->for_overlaps
= overlaps
;
22646 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22647 last
= s
->row
->glyphs
[s
->area
] + end
;
22648 voffset
= glyph
->voffset
;
22649 s
->padding_p
= glyph
->padding_p
;
22650 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22652 while (glyph
< last
22653 && glyph
->type
== CHAR_GLYPH
22654 && glyph
->voffset
== voffset
22655 /* Same face id implies same font, nowadays. */
22656 && glyph
->face_id
== face_id
22657 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22661 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22662 s
->char2b
+ s
->nchars
,
22664 s
->two_byte_p
= two_byte_p
;
22666 eassert (s
->nchars
<= end
- start
);
22667 s
->width
+= glyph
->pixel_width
;
22668 if (glyph
++->padding_p
!= s
->padding_p
)
22672 s
->font
= s
->face
->font
;
22674 /* If the specified font could not be loaded, use the frame's font,
22675 but record the fact that we couldn't load it in
22676 S->font_not_found_p so that we can draw rectangles for the
22677 characters of the glyph string. */
22678 if (s
->font
== NULL
|| glyph_not_available_p
)
22680 s
->font_not_found_p
= 1;
22681 s
->font
= FRAME_FONT (s
->f
);
22684 /* Adjust base line for subscript/superscript text. */
22685 s
->ybase
+= voffset
;
22687 eassert (s
->face
&& s
->face
->gc
);
22688 return glyph
- s
->row
->glyphs
[s
->area
];
22692 /* Fill glyph string S from image glyph S->first_glyph. */
22695 fill_image_glyph_string (struct glyph_string
*s
)
22697 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22698 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22700 s
->slice
= s
->first_glyph
->slice
.img
;
22701 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22702 s
->font
= s
->face
->font
;
22703 s
->width
= s
->first_glyph
->pixel_width
;
22705 /* Adjust base line for subscript/superscript text. */
22706 s
->ybase
+= s
->first_glyph
->voffset
;
22710 /* Fill glyph string S from a sequence of stretch glyphs.
22712 START is the index of the first glyph to consider,
22713 END is the index of the last + 1.
22715 Value is the index of the first glyph not in S. */
22718 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22720 struct glyph
*glyph
, *last
;
22721 int voffset
, face_id
;
22723 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22725 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22726 last
= s
->row
->glyphs
[s
->area
] + end
;
22727 face_id
= glyph
->face_id
;
22728 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22729 s
->font
= s
->face
->font
;
22730 s
->width
= glyph
->pixel_width
;
22732 voffset
= glyph
->voffset
;
22736 && glyph
->type
== STRETCH_GLYPH
22737 && glyph
->voffset
== voffset
22738 && glyph
->face_id
== face_id
);
22740 s
->width
+= glyph
->pixel_width
;
22742 /* Adjust base line for subscript/superscript text. */
22743 s
->ybase
+= voffset
;
22745 /* The case that face->gc == 0 is handled when drawing the glyph
22746 string by calling PREPARE_FACE_FOR_DISPLAY. */
22748 return glyph
- s
->row
->glyphs
[s
->area
];
22751 static struct font_metrics
*
22752 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22754 static struct font_metrics metrics
;
22755 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22757 if (! font
|| code
== FONT_INVALID_CODE
)
22759 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22764 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22765 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22766 assumed to be zero. */
22769 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22771 *left
= *right
= 0;
22773 if (glyph
->type
== CHAR_GLYPH
)
22777 struct font_metrics
*pcm
;
22779 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22780 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22782 if (pcm
->rbearing
> pcm
->width
)
22783 *right
= pcm
->rbearing
- pcm
->width
;
22784 if (pcm
->lbearing
< 0)
22785 *left
= -pcm
->lbearing
;
22788 else if (glyph
->type
== COMPOSITE_GLYPH
)
22790 if (! glyph
->u
.cmp
.automatic
)
22792 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22794 if (cmp
->rbearing
> cmp
->pixel_width
)
22795 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22796 if (cmp
->lbearing
< 0)
22797 *left
= - cmp
->lbearing
;
22801 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22802 struct font_metrics metrics
;
22804 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22805 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22806 if (metrics
.rbearing
> metrics
.width
)
22807 *right
= metrics
.rbearing
- metrics
.width
;
22808 if (metrics
.lbearing
< 0)
22809 *left
= - metrics
.lbearing
;
22815 /* Return the index of the first glyph preceding glyph string S that
22816 is overwritten by S because of S's left overhang. Value is -1
22817 if no glyphs are overwritten. */
22820 left_overwritten (struct glyph_string
*s
)
22824 if (s
->left_overhang
)
22827 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22828 int first
= s
->first_glyph
- glyphs
;
22830 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22831 x
-= glyphs
[i
].pixel_width
;
22842 /* Return the index of the first glyph preceding glyph string S that
22843 is overwriting S because of its right overhang. Value is -1 if no
22844 glyph in front of S overwrites S. */
22847 left_overwriting (struct glyph_string
*s
)
22850 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22851 int first
= s
->first_glyph
- glyphs
;
22855 for (i
= first
- 1; i
>= 0; --i
)
22858 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22861 x
-= glyphs
[i
].pixel_width
;
22868 /* Return the index of the last glyph following glyph string S that is
22869 overwritten by S because of S's right overhang. Value is -1 if
22870 no such glyph is found. */
22873 right_overwritten (struct glyph_string
*s
)
22877 if (s
->right_overhang
)
22880 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22881 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22882 int end
= s
->row
->used
[s
->area
];
22884 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22885 x
+= glyphs
[i
].pixel_width
;
22894 /* Return the index of the last glyph following glyph string S that
22895 overwrites S because of its left overhang. Value is negative
22896 if no such glyph is found. */
22899 right_overwriting (struct glyph_string
*s
)
22902 int end
= s
->row
->used
[s
->area
];
22903 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22904 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22908 for (i
= first
; i
< end
; ++i
)
22911 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22914 x
+= glyphs
[i
].pixel_width
;
22921 /* Set background width of glyph string S. START is the index of the
22922 first glyph following S. LAST_X is the right-most x-position + 1
22923 in the drawing area. */
22926 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22928 /* If the face of this glyph string has to be drawn to the end of
22929 the drawing area, set S->extends_to_end_of_line_p. */
22931 if (start
== s
->row
->used
[s
->area
]
22932 && s
->area
== TEXT_AREA
22933 && ((s
->row
->fill_line_p
22934 && (s
->hl
== DRAW_NORMAL_TEXT
22935 || s
->hl
== DRAW_IMAGE_RAISED
22936 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22937 || s
->hl
== DRAW_MOUSE_FACE
))
22938 s
->extends_to_end_of_line_p
= 1;
22940 /* If S extends its face to the end of the line, set its
22941 background_width to the distance to the right edge of the drawing
22943 if (s
->extends_to_end_of_line_p
)
22944 s
->background_width
= last_x
- s
->x
+ 1;
22946 s
->background_width
= s
->width
;
22950 /* Compute overhangs and x-positions for glyph string S and its
22951 predecessors, or successors. X is the starting x-position for S.
22952 BACKWARD_P non-zero means process predecessors. */
22955 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22961 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22962 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22972 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22973 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22983 /* The following macros are only called from draw_glyphs below.
22984 They reference the following parameters of that function directly:
22985 `w', `row', `area', and `overlap_p'
22986 as well as the following local variables:
22987 `s', `f', and `hdc' (in W32) */
22990 /* On W32, silently add local `hdc' variable to argument list of
22991 init_glyph_string. */
22992 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22993 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22995 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22996 init_glyph_string (s, char2b, w, row, area, start, hl)
22999 /* Add a glyph string for a stretch glyph to the list of strings
23000 between HEAD and TAIL. START is the index of the stretch glyph in
23001 row area AREA of glyph row ROW. END is the index of the last glyph
23002 in that glyph row area. X is the current output position assigned
23003 to the new glyph string constructed. HL overrides that face of the
23004 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23005 is the right-most x-position of the drawing area. */
23007 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23008 and below -- keep them on one line. */
23009 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23012 s = alloca (sizeof *s); \
23013 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23014 START = fill_stretch_glyph_string (s, START, END); \
23015 append_glyph_string (&HEAD, &TAIL, s); \
23021 /* Add a glyph string for an image glyph to the list of strings
23022 between HEAD and TAIL. START is the index of the image glyph in
23023 row area AREA of glyph row ROW. END is the index of the last glyph
23024 in that glyph row area. X is the current output position assigned
23025 to the new glyph string constructed. HL overrides that face of the
23026 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23027 is the right-most x-position of the drawing area. */
23029 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23032 s = alloca (sizeof *s); \
23033 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23034 fill_image_glyph_string (s); \
23035 append_glyph_string (&HEAD, &TAIL, s); \
23042 /* Add a glyph string for a sequence of character glyphs to the list
23043 of strings between HEAD and TAIL. START is the index of the first
23044 glyph in row area AREA of glyph row ROW that is part of the new
23045 glyph string. END is the index of the last glyph in that glyph row
23046 area. X is the current output position assigned to the new glyph
23047 string constructed. HL overrides that face of the glyph; e.g. it
23048 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23049 right-most x-position of the drawing area. */
23051 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23057 face_id = (row)->glyphs[area][START].face_id; \
23059 s = alloca (sizeof *s); \
23060 char2b = alloca ((END - START) * sizeof *char2b); \
23061 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23062 append_glyph_string (&HEAD, &TAIL, s); \
23064 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23069 /* Add a glyph string for a composite sequence to the list of strings
23070 between HEAD and TAIL. START is the index of the first glyph in
23071 row area AREA of glyph row ROW that is part of the new glyph
23072 string. END is the index of the last glyph in that glyph row area.
23073 X is the current output position assigned to the new glyph string
23074 constructed. HL overrides that face of the glyph; e.g. it is
23075 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23076 x-position of the drawing area. */
23078 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23080 int face_id = (row)->glyphs[area][START].face_id; \
23081 struct face *base_face = FACE_FROM_ID (f, face_id); \
23082 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23083 struct composition *cmp = composition_table[cmp_id]; \
23085 struct glyph_string *first_s = NULL; \
23088 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23090 /* Make glyph_strings for each glyph sequence that is drawable by \
23091 the same face, and append them to HEAD/TAIL. */ \
23092 for (n = 0; n < cmp->glyph_len;) \
23094 s = alloca (sizeof *s); \
23095 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23096 append_glyph_string (&(HEAD), &(TAIL), s); \
23102 n = fill_composite_glyph_string (s, base_face, overlaps); \
23110 /* Add a glyph string for a glyph-string sequence to the list of strings
23111 between HEAD and TAIL. */
23113 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23117 Lisp_Object gstring; \
23119 face_id = (row)->glyphs[area][START].face_id; \
23120 gstring = (composition_gstring_from_id \
23121 ((row)->glyphs[area][START].u.cmp.id)); \
23122 s = alloca (sizeof *s); \
23123 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23124 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23125 append_glyph_string (&(HEAD), &(TAIL), s); \
23127 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23131 /* Add a glyph string for a sequence of glyphless character's glyphs
23132 to the list of strings between HEAD and TAIL. The meanings of
23133 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23135 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23140 face_id = (row)->glyphs[area][START].face_id; \
23142 s = alloca (sizeof *s); \
23143 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23144 append_glyph_string (&HEAD, &TAIL, s); \
23146 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23152 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23153 of AREA of glyph row ROW on window W between indices START and END.
23154 HL overrides the face for drawing glyph strings, e.g. it is
23155 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23156 x-positions of the drawing area.
23158 This is an ugly monster macro construct because we must use alloca
23159 to allocate glyph strings (because draw_glyphs can be called
23160 asynchronously). */
23162 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23165 HEAD = TAIL = NULL; \
23166 while (START < END) \
23168 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23169 switch (first_glyph->type) \
23172 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23176 case COMPOSITE_GLYPH: \
23177 if (first_glyph->u.cmp.automatic) \
23178 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23181 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23185 case STRETCH_GLYPH: \
23186 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23190 case IMAGE_GLYPH: \
23191 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23195 case GLYPHLESS_GLYPH: \
23196 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23206 set_glyph_string_background_width (s, START, LAST_X); \
23213 /* Draw glyphs between START and END in AREA of ROW on window W,
23214 starting at x-position X. X is relative to AREA in W. HL is a
23215 face-override with the following meaning:
23217 DRAW_NORMAL_TEXT draw normally
23218 DRAW_CURSOR draw in cursor face
23219 DRAW_MOUSE_FACE draw in mouse face.
23220 DRAW_INVERSE_VIDEO draw in mode line face
23221 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23222 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23224 If OVERLAPS is non-zero, draw only the foreground of characters and
23225 clip to the physical height of ROW. Non-zero value also defines
23226 the overlapping part to be drawn:
23228 OVERLAPS_PRED overlap with preceding rows
23229 OVERLAPS_SUCC overlap with succeeding rows
23230 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23231 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23233 Value is the x-position reached, relative to AREA of W. */
23236 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23237 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23238 enum draw_glyphs_face hl
, int overlaps
)
23240 struct glyph_string
*head
, *tail
;
23241 struct glyph_string
*s
;
23242 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23243 int i
, j
, x_reached
, last_x
, area_left
= 0;
23244 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23247 ALLOCATE_HDC (hdc
, f
);
23249 /* Let's rather be paranoid than getting a SEGV. */
23250 end
= min (end
, row
->used
[area
]);
23251 start
= max (0, start
);
23252 start
= min (end
, start
);
23254 /* Translate X to frame coordinates. Set last_x to the right
23255 end of the drawing area. */
23256 if (row
->full_width_p
)
23258 /* X is relative to the left edge of W, without scroll bars
23260 area_left
= WINDOW_LEFT_EDGE_X (w
);
23261 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23265 area_left
= window_box_left (w
, area
);
23266 last_x
= area_left
+ window_box_width (w
, area
);
23270 /* Build a doubly-linked list of glyph_string structures between
23271 head and tail from what we have to draw. Note that the macro
23272 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23273 the reason we use a separate variable `i'. */
23275 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23277 x_reached
= tail
->x
+ tail
->background_width
;
23281 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23282 the row, redraw some glyphs in front or following the glyph
23283 strings built above. */
23284 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23286 struct glyph_string
*h
, *t
;
23287 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23288 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23289 int check_mouse_face
= 0;
23292 /* If mouse highlighting is on, we may need to draw adjacent
23293 glyphs using mouse-face highlighting. */
23294 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23296 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23298 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23299 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23301 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23303 check_mouse_face
= 1;
23304 mouse_beg_col
= (row
== mouse_beg_row
)
23305 ? hlinfo
->mouse_face_beg_col
: 0;
23306 mouse_end_col
= (row
== mouse_end_row
)
23307 ? hlinfo
->mouse_face_end_col
23308 : row
->used
[TEXT_AREA
];
23312 /* Compute overhangs for all glyph strings. */
23313 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23314 for (s
= head
; s
; s
= s
->next
)
23315 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23317 /* Prepend glyph strings for glyphs in front of the first glyph
23318 string that are overwritten because of the first glyph
23319 string's left overhang. The background of all strings
23320 prepended must be drawn because the first glyph string
23322 i
= left_overwritten (head
);
23325 enum draw_glyphs_face overlap_hl
;
23327 /* If this row contains mouse highlighting, attempt to draw
23328 the overlapped glyphs with the correct highlight. This
23329 code fails if the overlap encompasses more than one glyph
23330 and mouse-highlight spans only some of these glyphs.
23331 However, making it work perfectly involves a lot more
23332 code, and I don't know if the pathological case occurs in
23333 practice, so we'll stick to this for now. --- cyd */
23334 if (check_mouse_face
23335 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23336 overlap_hl
= DRAW_MOUSE_FACE
;
23338 overlap_hl
= DRAW_NORMAL_TEXT
;
23341 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23342 overlap_hl
, dummy_x
, last_x
);
23344 compute_overhangs_and_x (t
, head
->x
, 1);
23345 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23349 /* Prepend glyph strings for glyphs in front of the first glyph
23350 string that overwrite that glyph string because of their
23351 right overhang. For these strings, only the foreground must
23352 be drawn, because it draws over the glyph string at `head'.
23353 The background must not be drawn because this would overwrite
23354 right overhangs of preceding glyphs for which no glyph
23356 i
= left_overwriting (head
);
23359 enum draw_glyphs_face overlap_hl
;
23361 if (check_mouse_face
23362 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23363 overlap_hl
= DRAW_MOUSE_FACE
;
23365 overlap_hl
= DRAW_NORMAL_TEXT
;
23368 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23369 overlap_hl
, dummy_x
, last_x
);
23370 for (s
= h
; s
; s
= s
->next
)
23371 s
->background_filled_p
= 1;
23372 compute_overhangs_and_x (t
, head
->x
, 1);
23373 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23376 /* Append glyphs strings for glyphs following the last glyph
23377 string tail that are overwritten by tail. The background of
23378 these strings has to be drawn because tail's foreground draws
23380 i
= right_overwritten (tail
);
23383 enum draw_glyphs_face overlap_hl
;
23385 if (check_mouse_face
23386 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23387 overlap_hl
= DRAW_MOUSE_FACE
;
23389 overlap_hl
= DRAW_NORMAL_TEXT
;
23391 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23392 overlap_hl
, x
, last_x
);
23393 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23394 we don't have `end = i;' here. */
23395 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23396 append_glyph_string_lists (&head
, &tail
, h
, t
);
23400 /* Append glyph strings for glyphs following the last glyph
23401 string tail that overwrite tail. The foreground of such
23402 glyphs has to be drawn because it writes into the background
23403 of tail. The background must not be drawn because it could
23404 paint over the foreground of following glyphs. */
23405 i
= right_overwriting (tail
);
23408 enum draw_glyphs_face overlap_hl
;
23409 if (check_mouse_face
23410 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23411 overlap_hl
= DRAW_MOUSE_FACE
;
23413 overlap_hl
= DRAW_NORMAL_TEXT
;
23416 i
++; /* We must include the Ith glyph. */
23417 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23418 overlap_hl
, x
, last_x
);
23419 for (s
= h
; s
; s
= s
->next
)
23420 s
->background_filled_p
= 1;
23421 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23422 append_glyph_string_lists (&head
, &tail
, h
, t
);
23424 if (clip_head
|| clip_tail
)
23425 for (s
= head
; s
; s
= s
->next
)
23427 s
->clip_head
= clip_head
;
23428 s
->clip_tail
= clip_tail
;
23432 /* Draw all strings. */
23433 for (s
= head
; s
; s
= s
->next
)
23434 FRAME_RIF (f
)->draw_glyph_string (s
);
23437 /* When focus a sole frame and move horizontally, this sets on_p to 0
23438 causing a failure to erase prev cursor position. */
23439 if (area
== TEXT_AREA
23440 && !row
->full_width_p
23441 /* When drawing overlapping rows, only the glyph strings'
23442 foreground is drawn, which doesn't erase a cursor
23446 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23447 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23448 : (tail
? tail
->x
+ tail
->background_width
: x
));
23452 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23453 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23457 /* Value is the x-position up to which drawn, relative to AREA of W.
23458 This doesn't include parts drawn because of overhangs. */
23459 if (row
->full_width_p
)
23460 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23462 x_reached
-= area_left
;
23464 RELEASE_HDC (hdc
, f
);
23469 /* Expand row matrix if too narrow. Don't expand if area
23472 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23474 if (!fonts_changed_p \
23475 && (it->glyph_row->glyphs[area] \
23476 < it->glyph_row->glyphs[area + 1])) \
23478 it->w->ncols_scale_factor++; \
23479 fonts_changed_p = 1; \
23483 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23484 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23487 append_glyph (struct it
*it
)
23489 struct glyph
*glyph
;
23490 enum glyph_row_area area
= it
->area
;
23492 eassert (it
->glyph_row
);
23493 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23495 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23496 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23498 /* If the glyph row is reversed, we need to prepend the glyph
23499 rather than append it. */
23500 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23504 /* Make room for the additional glyph. */
23505 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23507 glyph
= it
->glyph_row
->glyphs
[area
];
23509 glyph
->charpos
= CHARPOS (it
->position
);
23510 glyph
->object
= it
->object
;
23511 if (it
->pixel_width
> 0)
23513 glyph
->pixel_width
= it
->pixel_width
;
23514 glyph
->padding_p
= 0;
23518 /* Assure at least 1-pixel width. Otherwise, cursor can't
23519 be displayed correctly. */
23520 glyph
->pixel_width
= 1;
23521 glyph
->padding_p
= 1;
23523 glyph
->ascent
= it
->ascent
;
23524 glyph
->descent
= it
->descent
;
23525 glyph
->voffset
= it
->voffset
;
23526 glyph
->type
= CHAR_GLYPH
;
23527 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23528 glyph
->multibyte_p
= it
->multibyte_p
;
23529 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23530 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23531 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23532 || it
->phys_descent
> it
->descent
);
23533 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23534 glyph
->face_id
= it
->face_id
;
23535 glyph
->u
.ch
= it
->char_to_display
;
23536 glyph
->slice
.img
= null_glyph_slice
;
23537 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23540 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23541 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23543 glyph
->bidi_type
= it
->bidi_it
.type
;
23547 glyph
->resolved_level
= 0;
23548 glyph
->bidi_type
= UNKNOWN_BT
;
23550 ++it
->glyph_row
->used
[area
];
23553 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23556 /* Store one glyph for the composition IT->cmp_it.id in
23557 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23561 append_composite_glyph (struct it
*it
)
23563 struct glyph
*glyph
;
23564 enum glyph_row_area area
= it
->area
;
23566 eassert (it
->glyph_row
);
23568 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23569 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23571 /* If the glyph row is reversed, we need to prepend the glyph
23572 rather than append it. */
23573 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23577 /* Make room for the new glyph. */
23578 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23580 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23582 glyph
->charpos
= it
->cmp_it
.charpos
;
23583 glyph
->object
= it
->object
;
23584 glyph
->pixel_width
= it
->pixel_width
;
23585 glyph
->ascent
= it
->ascent
;
23586 glyph
->descent
= it
->descent
;
23587 glyph
->voffset
= it
->voffset
;
23588 glyph
->type
= COMPOSITE_GLYPH
;
23589 if (it
->cmp_it
.ch
< 0)
23591 glyph
->u
.cmp
.automatic
= 0;
23592 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23593 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23597 glyph
->u
.cmp
.automatic
= 1;
23598 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23599 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23600 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23602 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23603 glyph
->multibyte_p
= it
->multibyte_p
;
23604 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23605 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23606 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23607 || it
->phys_descent
> it
->descent
);
23608 glyph
->padding_p
= 0;
23609 glyph
->glyph_not_available_p
= 0;
23610 glyph
->face_id
= it
->face_id
;
23611 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23614 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23615 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23617 glyph
->bidi_type
= it
->bidi_it
.type
;
23619 ++it
->glyph_row
->used
[area
];
23622 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23626 /* Change IT->ascent and IT->height according to the setting of
23630 take_vertical_position_into_account (struct it
*it
)
23634 if (it
->voffset
< 0)
23635 /* Increase the ascent so that we can display the text higher
23637 it
->ascent
-= it
->voffset
;
23639 /* Increase the descent so that we can display the text lower
23641 it
->descent
+= it
->voffset
;
23646 /* Produce glyphs/get display metrics for the image IT is loaded with.
23647 See the description of struct display_iterator in dispextern.h for
23648 an overview of struct display_iterator. */
23651 produce_image_glyph (struct it
*it
)
23655 int glyph_ascent
, crop
;
23656 struct glyph_slice slice
;
23658 eassert (it
->what
== IT_IMAGE
);
23660 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23662 /* Make sure X resources of the face is loaded. */
23663 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23665 if (it
->image_id
< 0)
23667 /* Fringe bitmap. */
23668 it
->ascent
= it
->phys_ascent
= 0;
23669 it
->descent
= it
->phys_descent
= 0;
23670 it
->pixel_width
= 0;
23675 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23677 /* Make sure X resources of the image is loaded. */
23678 prepare_image_for_display (it
->f
, img
);
23680 slice
.x
= slice
.y
= 0;
23681 slice
.width
= img
->width
;
23682 slice
.height
= img
->height
;
23684 if (INTEGERP (it
->slice
.x
))
23685 slice
.x
= XINT (it
->slice
.x
);
23686 else if (FLOATP (it
->slice
.x
))
23687 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23689 if (INTEGERP (it
->slice
.y
))
23690 slice
.y
= XINT (it
->slice
.y
);
23691 else if (FLOATP (it
->slice
.y
))
23692 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23694 if (INTEGERP (it
->slice
.width
))
23695 slice
.width
= XINT (it
->slice
.width
);
23696 else if (FLOATP (it
->slice
.width
))
23697 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23699 if (INTEGERP (it
->slice
.height
))
23700 slice
.height
= XINT (it
->slice
.height
);
23701 else if (FLOATP (it
->slice
.height
))
23702 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23704 if (slice
.x
>= img
->width
)
23705 slice
.x
= img
->width
;
23706 if (slice
.y
>= img
->height
)
23707 slice
.y
= img
->height
;
23708 if (slice
.x
+ slice
.width
>= img
->width
)
23709 slice
.width
= img
->width
- slice
.x
;
23710 if (slice
.y
+ slice
.height
> img
->height
)
23711 slice
.height
= img
->height
- slice
.y
;
23713 if (slice
.width
== 0 || slice
.height
== 0)
23716 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23718 it
->descent
= slice
.height
- glyph_ascent
;
23720 it
->descent
+= img
->vmargin
;
23721 if (slice
.y
+ slice
.height
== img
->height
)
23722 it
->descent
+= img
->vmargin
;
23723 it
->phys_descent
= it
->descent
;
23725 it
->pixel_width
= slice
.width
;
23727 it
->pixel_width
+= img
->hmargin
;
23728 if (slice
.x
+ slice
.width
== img
->width
)
23729 it
->pixel_width
+= img
->hmargin
;
23731 /* It's quite possible for images to have an ascent greater than
23732 their height, so don't get confused in that case. */
23733 if (it
->descent
< 0)
23738 if (face
->box
!= FACE_NO_BOX
)
23740 if (face
->box_line_width
> 0)
23743 it
->ascent
+= face
->box_line_width
;
23744 if (slice
.y
+ slice
.height
== img
->height
)
23745 it
->descent
+= face
->box_line_width
;
23748 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23749 it
->pixel_width
+= eabs (face
->box_line_width
);
23750 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23751 it
->pixel_width
+= eabs (face
->box_line_width
);
23754 take_vertical_position_into_account (it
);
23756 /* Automatically crop wide image glyphs at right edge so we can
23757 draw the cursor on same display row. */
23758 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23759 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23761 it
->pixel_width
-= crop
;
23762 slice
.width
-= crop
;
23767 struct glyph
*glyph
;
23768 enum glyph_row_area area
= it
->area
;
23770 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23771 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23773 glyph
->charpos
= CHARPOS (it
->position
);
23774 glyph
->object
= it
->object
;
23775 glyph
->pixel_width
= it
->pixel_width
;
23776 glyph
->ascent
= glyph_ascent
;
23777 glyph
->descent
= it
->descent
;
23778 glyph
->voffset
= it
->voffset
;
23779 glyph
->type
= IMAGE_GLYPH
;
23780 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23781 glyph
->multibyte_p
= it
->multibyte_p
;
23782 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23783 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23784 glyph
->overlaps_vertically_p
= 0;
23785 glyph
->padding_p
= 0;
23786 glyph
->glyph_not_available_p
= 0;
23787 glyph
->face_id
= it
->face_id
;
23788 glyph
->u
.img_id
= img
->id
;
23789 glyph
->slice
.img
= slice
;
23790 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23793 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23794 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23796 glyph
->bidi_type
= it
->bidi_it
.type
;
23798 ++it
->glyph_row
->used
[area
];
23801 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23806 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23807 of the glyph, WIDTH and HEIGHT are the width and height of the
23808 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23811 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23812 int width
, int height
, int ascent
)
23814 struct glyph
*glyph
;
23815 enum glyph_row_area area
= it
->area
;
23817 eassert (ascent
>= 0 && ascent
<= height
);
23819 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23820 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23822 /* If the glyph row is reversed, we need to prepend the glyph
23823 rather than append it. */
23824 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23828 /* Make room for the additional glyph. */
23829 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23831 glyph
= it
->glyph_row
->glyphs
[area
];
23833 glyph
->charpos
= CHARPOS (it
->position
);
23834 glyph
->object
= object
;
23835 glyph
->pixel_width
= width
;
23836 glyph
->ascent
= ascent
;
23837 glyph
->descent
= height
- ascent
;
23838 glyph
->voffset
= it
->voffset
;
23839 glyph
->type
= STRETCH_GLYPH
;
23840 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23841 glyph
->multibyte_p
= it
->multibyte_p
;
23842 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23843 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23844 glyph
->overlaps_vertically_p
= 0;
23845 glyph
->padding_p
= 0;
23846 glyph
->glyph_not_available_p
= 0;
23847 glyph
->face_id
= it
->face_id
;
23848 glyph
->u
.stretch
.ascent
= ascent
;
23849 glyph
->u
.stretch
.height
= height
;
23850 glyph
->slice
.img
= null_glyph_slice
;
23851 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23854 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23855 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23857 glyph
->bidi_type
= it
->bidi_it
.type
;
23861 glyph
->resolved_level
= 0;
23862 glyph
->bidi_type
= UNKNOWN_BT
;
23864 ++it
->glyph_row
->used
[area
];
23867 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23870 #endif /* HAVE_WINDOW_SYSTEM */
23872 /* Produce a stretch glyph for iterator IT. IT->object is the value
23873 of the glyph property displayed. The value must be a list
23874 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23877 1. `:width WIDTH' specifies that the space should be WIDTH *
23878 canonical char width wide. WIDTH may be an integer or floating
23881 2. `:relative-width FACTOR' specifies that the width of the stretch
23882 should be computed from the width of the first character having the
23883 `glyph' property, and should be FACTOR times that width.
23885 3. `:align-to HPOS' specifies that the space should be wide enough
23886 to reach HPOS, a value in canonical character units.
23888 Exactly one of the above pairs must be present.
23890 4. `:height HEIGHT' specifies that the height of the stretch produced
23891 should be HEIGHT, measured in canonical character units.
23893 5. `:relative-height FACTOR' specifies that the height of the
23894 stretch should be FACTOR times the height of the characters having
23895 the glyph property.
23897 Either none or exactly one of 4 or 5 must be present.
23899 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23900 of the stretch should be used for the ascent of the stretch.
23901 ASCENT must be in the range 0 <= ASCENT <= 100. */
23904 produce_stretch_glyph (struct it
*it
)
23906 /* (space :width WIDTH :height HEIGHT ...) */
23907 Lisp_Object prop
, plist
;
23908 int width
= 0, height
= 0, align_to
= -1;
23909 int zero_width_ok_p
= 0;
23912 struct face
*face
= NULL
;
23913 struct font
*font
= NULL
;
23915 #ifdef HAVE_WINDOW_SYSTEM
23916 int zero_height_ok_p
= 0;
23918 if (FRAME_WINDOW_P (it
->f
))
23920 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23921 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23922 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23926 /* List should start with `space'. */
23927 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23928 plist
= XCDR (it
->object
);
23930 /* Compute the width of the stretch. */
23931 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23932 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23934 /* Absolute width `:width WIDTH' specified and valid. */
23935 zero_width_ok_p
= 1;
23938 #ifdef HAVE_WINDOW_SYSTEM
23939 else if (FRAME_WINDOW_P (it
->f
)
23940 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23942 /* Relative width `:relative-width FACTOR' specified and valid.
23943 Compute the width of the characters having the `glyph'
23946 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23949 if (it
->multibyte_p
)
23950 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23953 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23954 if (! ASCII_CHAR_P (it2
.c
))
23955 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23958 it2
.glyph_row
= NULL
;
23959 it2
.what
= IT_CHARACTER
;
23960 x_produce_glyphs (&it2
);
23961 width
= NUMVAL (prop
) * it2
.pixel_width
;
23963 #endif /* HAVE_WINDOW_SYSTEM */
23964 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23965 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23967 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23968 align_to
= (align_to
< 0
23970 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23971 else if (align_to
< 0)
23972 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23973 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23974 zero_width_ok_p
= 1;
23977 /* Nothing specified -> width defaults to canonical char width. */
23978 width
= FRAME_COLUMN_WIDTH (it
->f
);
23980 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23983 #ifdef HAVE_WINDOW_SYSTEM
23984 /* Compute height. */
23985 if (FRAME_WINDOW_P (it
->f
))
23987 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23988 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23991 zero_height_ok_p
= 1;
23993 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23995 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23997 height
= FONT_HEIGHT (font
);
23999 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24002 /* Compute percentage of height used for ascent. If
24003 `:ascent ASCENT' is present and valid, use that. Otherwise,
24004 derive the ascent from the font in use. */
24005 if (prop
= Fplist_get (plist
, QCascent
),
24006 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24007 ascent
= height
* NUMVAL (prop
) / 100.0;
24008 else if (!NILP (prop
)
24009 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24010 ascent
= min (max (0, (int)tem
), height
);
24012 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24015 #endif /* HAVE_WINDOW_SYSTEM */
24018 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24019 && it
->current_x
+ width
> it
->last_visible_x
)
24021 width
= it
->last_visible_x
- it
->current_x
;
24022 #ifdef HAVE_WINDOW_SYSTEM
24023 /* Subtract one more pixel from the stretch width, but only on
24024 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24025 width
-= FRAME_WINDOW_P (it
->f
);
24029 if (width
> 0 && height
> 0 && it
->glyph_row
)
24031 Lisp_Object o_object
= it
->object
;
24032 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24035 if (!STRINGP (object
))
24036 object
= it
->w
->buffer
;
24037 #ifdef HAVE_WINDOW_SYSTEM
24038 if (FRAME_WINDOW_P (it
->f
))
24039 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24043 it
->object
= object
;
24044 it
->char_to_display
= ' ';
24045 it
->pixel_width
= it
->len
= 1;
24047 tty_append_glyph (it
);
24048 it
->object
= o_object
;
24052 it
->pixel_width
= width
;
24053 #ifdef HAVE_WINDOW_SYSTEM
24054 if (FRAME_WINDOW_P (it
->f
))
24056 it
->ascent
= it
->phys_ascent
= ascent
;
24057 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24058 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24059 take_vertical_position_into_account (it
);
24063 it
->nglyphs
= width
;
24066 #ifdef HAVE_WINDOW_SYSTEM
24068 /* Calculate line-height and line-spacing properties.
24069 An integer value specifies explicit pixel value.
24070 A float value specifies relative value to current face height.
24071 A cons (float . face-name) specifies relative value to
24072 height of specified face font.
24074 Returns height in pixels, or nil. */
24078 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24079 int boff
, int override
)
24081 Lisp_Object face_name
= Qnil
;
24082 int ascent
, descent
, height
;
24084 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24089 face_name
= XCAR (val
);
24091 if (!NUMBERP (val
))
24092 val
= make_number (1);
24093 if (NILP (face_name
))
24095 height
= it
->ascent
+ it
->descent
;
24100 if (NILP (face_name
))
24102 font
= FRAME_FONT (it
->f
);
24103 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24105 else if (EQ (face_name
, Qt
))
24114 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24116 return make_number (-1);
24118 face
= FACE_FROM_ID (it
->f
, face_id
);
24121 return make_number (-1);
24122 boff
= font
->baseline_offset
;
24123 if (font
->vertical_centering
)
24124 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24127 ascent
= FONT_BASE (font
) + boff
;
24128 descent
= FONT_DESCENT (font
) - boff
;
24132 it
->override_ascent
= ascent
;
24133 it
->override_descent
= descent
;
24134 it
->override_boff
= boff
;
24137 height
= ascent
+ descent
;
24141 height
= (int)(XFLOAT_DATA (val
) * height
);
24142 else if (INTEGERP (val
))
24143 height
*= XINT (val
);
24145 return make_number (height
);
24149 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24150 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24151 and only if this is for a character for which no font was found.
24153 If the display method (it->glyphless_method) is
24154 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24155 length of the acronym or the hexadecimal string, UPPER_XOFF and
24156 UPPER_YOFF are pixel offsets for the upper part of the string,
24157 LOWER_XOFF and LOWER_YOFF are for the lower part.
24159 For the other display methods, LEN through LOWER_YOFF are zero. */
24162 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24163 short upper_xoff
, short upper_yoff
,
24164 short lower_xoff
, short lower_yoff
)
24166 struct glyph
*glyph
;
24167 enum glyph_row_area area
= it
->area
;
24169 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24170 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24172 /* If the glyph row is reversed, we need to prepend the glyph
24173 rather than append it. */
24174 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24178 /* Make room for the additional glyph. */
24179 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24181 glyph
= it
->glyph_row
->glyphs
[area
];
24183 glyph
->charpos
= CHARPOS (it
->position
);
24184 glyph
->object
= it
->object
;
24185 glyph
->pixel_width
= it
->pixel_width
;
24186 glyph
->ascent
= it
->ascent
;
24187 glyph
->descent
= it
->descent
;
24188 glyph
->voffset
= it
->voffset
;
24189 glyph
->type
= GLYPHLESS_GLYPH
;
24190 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24191 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24192 glyph
->u
.glyphless
.len
= len
;
24193 glyph
->u
.glyphless
.ch
= it
->c
;
24194 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24195 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24196 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24197 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24198 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24199 glyph
->multibyte_p
= it
->multibyte_p
;
24200 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24201 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24202 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24203 || it
->phys_descent
> it
->descent
);
24204 glyph
->padding_p
= 0;
24205 glyph
->glyph_not_available_p
= 0;
24206 glyph
->face_id
= face_id
;
24207 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24210 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24211 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24213 glyph
->bidi_type
= it
->bidi_it
.type
;
24215 ++it
->glyph_row
->used
[area
];
24218 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24222 /* Produce a glyph for a glyphless character for iterator IT.
24223 IT->glyphless_method specifies which method to use for displaying
24224 the character. See the description of enum
24225 glyphless_display_method in dispextern.h for the detail.
24227 FOR_NO_FONT is nonzero if and only if this is for a character for
24228 which no font was found. ACRONYM, if non-nil, is an acronym string
24229 for the character. */
24232 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24237 int base_width
, base_height
, width
, height
;
24238 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24241 /* Get the metrics of the base font. We always refer to the current
24243 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24244 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24245 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24246 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24247 base_height
= it
->ascent
+ it
->descent
;
24248 base_width
= font
->average_width
;
24250 /* Get a face ID for the glyph by utilizing a cache (the same way as
24251 done for `escape-glyph' in get_next_display_element). */
24252 if (it
->f
== last_glyphless_glyph_frame
24253 && it
->face_id
== last_glyphless_glyph_face_id
)
24255 face_id
= last_glyphless_glyph_merged_face_id
;
24259 /* Merge the `glyphless-char' face into the current face. */
24260 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24261 last_glyphless_glyph_frame
= it
->f
;
24262 last_glyphless_glyph_face_id
= it
->face_id
;
24263 last_glyphless_glyph_merged_face_id
= face_id
;
24266 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24268 it
->pixel_width
= THIN_SPACE_WIDTH
;
24270 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24272 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24274 width
= CHAR_WIDTH (it
->c
);
24277 else if (width
> 4)
24279 it
->pixel_width
= base_width
* width
;
24281 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24287 unsigned int code
[6];
24289 int ascent
, descent
;
24290 struct font_metrics metrics_upper
, metrics_lower
;
24292 face
= FACE_FROM_ID (it
->f
, face_id
);
24293 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24294 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24296 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24298 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24299 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24300 if (CONSP (acronym
))
24301 acronym
= XCAR (acronym
);
24302 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24306 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24307 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24310 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24311 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24312 upper_len
= (len
+ 1) / 2;
24313 font
->driver
->text_extents (font
, code
, upper_len
,
24315 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24320 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24321 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24322 upper_xoff
= upper_yoff
= 2; /* the typical case */
24323 if (base_width
>= width
)
24325 /* Align the upper to the left, the lower to the right. */
24326 it
->pixel_width
= base_width
;
24327 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24331 /* Center the shorter one. */
24332 it
->pixel_width
= width
;
24333 if (metrics_upper
.width
>= metrics_lower
.width
)
24334 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24337 /* FIXME: This code doesn't look right. It formerly was
24338 missing the "lower_xoff = 0;", which couldn't have
24339 been right since it left lower_xoff uninitialized. */
24341 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24345 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24346 top, bottom, and between upper and lower strings. */
24347 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24348 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24349 /* Center vertically.
24350 H:base_height, D:base_descent
24351 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24353 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24354 descent = D - H/2 + h/2;
24355 lower_yoff = descent - 2 - ld;
24356 upper_yoff = lower_yoff - la - 1 - ud; */
24357 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24358 descent
= it
->descent
- (base_height
- height
) / 2;
24359 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24360 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24361 - metrics_upper
.descent
);
24362 /* Don't make the height shorter than the base height. */
24363 if (height
> base_height
)
24365 it
->ascent
= ascent
;
24366 it
->descent
= descent
;
24370 it
->phys_ascent
= it
->ascent
;
24371 it
->phys_descent
= it
->descent
;
24373 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24374 upper_xoff
, upper_yoff
,
24375 lower_xoff
, lower_yoff
);
24377 take_vertical_position_into_account (it
);
24382 Produce glyphs/get display metrics for the display element IT is
24383 loaded with. See the description of struct it in dispextern.h
24384 for an overview of struct it. */
24387 x_produce_glyphs (struct it
*it
)
24389 int extra_line_spacing
= it
->extra_line_spacing
;
24391 it
->glyph_not_available_p
= 0;
24393 if (it
->what
== IT_CHARACTER
)
24396 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24397 struct font
*font
= face
->font
;
24398 struct font_metrics
*pcm
= NULL
;
24399 int boff
; /* baseline offset */
24403 /* When no suitable font is found, display this character by
24404 the method specified in the first extra slot of
24405 Vglyphless_char_display. */
24406 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24408 eassert (it
->what
== IT_GLYPHLESS
);
24409 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24413 boff
= font
->baseline_offset
;
24414 if (font
->vertical_centering
)
24415 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24417 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24423 if (it
->override_ascent
>= 0)
24425 it
->ascent
= it
->override_ascent
;
24426 it
->descent
= it
->override_descent
;
24427 boff
= it
->override_boff
;
24431 it
->ascent
= FONT_BASE (font
) + boff
;
24432 it
->descent
= FONT_DESCENT (font
) - boff
;
24435 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24437 pcm
= get_per_char_metric (font
, &char2b
);
24438 if (pcm
->width
== 0
24439 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24445 it
->phys_ascent
= pcm
->ascent
+ boff
;
24446 it
->phys_descent
= pcm
->descent
- boff
;
24447 it
->pixel_width
= pcm
->width
;
24451 it
->glyph_not_available_p
= 1;
24452 it
->phys_ascent
= it
->ascent
;
24453 it
->phys_descent
= it
->descent
;
24454 it
->pixel_width
= font
->space_width
;
24457 if (it
->constrain_row_ascent_descent_p
)
24459 if (it
->descent
> it
->max_descent
)
24461 it
->ascent
+= it
->descent
- it
->max_descent
;
24462 it
->descent
= it
->max_descent
;
24464 if (it
->ascent
> it
->max_ascent
)
24466 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24467 it
->ascent
= it
->max_ascent
;
24469 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24470 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24471 extra_line_spacing
= 0;
24474 /* If this is a space inside a region of text with
24475 `space-width' property, change its width. */
24476 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24478 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24480 /* If face has a box, add the box thickness to the character
24481 height. If character has a box line to the left and/or
24482 right, add the box line width to the character's width. */
24483 if (face
->box
!= FACE_NO_BOX
)
24485 int thick
= face
->box_line_width
;
24489 it
->ascent
+= thick
;
24490 it
->descent
+= thick
;
24495 if (it
->start_of_box_run_p
)
24496 it
->pixel_width
+= thick
;
24497 if (it
->end_of_box_run_p
)
24498 it
->pixel_width
+= thick
;
24501 /* If face has an overline, add the height of the overline
24502 (1 pixel) and a 1 pixel margin to the character height. */
24503 if (face
->overline_p
)
24504 it
->ascent
+= overline_margin
;
24506 if (it
->constrain_row_ascent_descent_p
)
24508 if (it
->ascent
> it
->max_ascent
)
24509 it
->ascent
= it
->max_ascent
;
24510 if (it
->descent
> it
->max_descent
)
24511 it
->descent
= it
->max_descent
;
24514 take_vertical_position_into_account (it
);
24516 /* If we have to actually produce glyphs, do it. */
24521 /* Translate a space with a `space-width' property
24522 into a stretch glyph. */
24523 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24524 / FONT_HEIGHT (font
));
24525 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24526 it
->ascent
+ it
->descent
, ascent
);
24531 /* If characters with lbearing or rbearing are displayed
24532 in this line, record that fact in a flag of the
24533 glyph row. This is used to optimize X output code. */
24534 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24535 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24537 if (! stretched_p
&& it
->pixel_width
== 0)
24538 /* We assure that all visible glyphs have at least 1-pixel
24540 it
->pixel_width
= 1;
24542 else if (it
->char_to_display
== '\n')
24544 /* A newline has no width, but we need the height of the
24545 line. But if previous part of the line sets a height,
24546 don't increase that height */
24548 Lisp_Object height
;
24549 Lisp_Object total_height
= Qnil
;
24551 it
->override_ascent
= -1;
24552 it
->pixel_width
= 0;
24555 height
= get_it_property (it
, Qline_height
);
24556 /* Split (line-height total-height) list */
24558 && CONSP (XCDR (height
))
24559 && NILP (XCDR (XCDR (height
))))
24561 total_height
= XCAR (XCDR (height
));
24562 height
= XCAR (height
);
24564 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24566 if (it
->override_ascent
>= 0)
24568 it
->ascent
= it
->override_ascent
;
24569 it
->descent
= it
->override_descent
;
24570 boff
= it
->override_boff
;
24574 it
->ascent
= FONT_BASE (font
) + boff
;
24575 it
->descent
= FONT_DESCENT (font
) - boff
;
24578 if (EQ (height
, Qt
))
24580 if (it
->descent
> it
->max_descent
)
24582 it
->ascent
+= it
->descent
- it
->max_descent
;
24583 it
->descent
= it
->max_descent
;
24585 if (it
->ascent
> it
->max_ascent
)
24587 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24588 it
->ascent
= it
->max_ascent
;
24590 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24591 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24592 it
->constrain_row_ascent_descent_p
= 1;
24593 extra_line_spacing
= 0;
24597 Lisp_Object spacing
;
24599 it
->phys_ascent
= it
->ascent
;
24600 it
->phys_descent
= it
->descent
;
24602 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24603 && face
->box
!= FACE_NO_BOX
24604 && face
->box_line_width
> 0)
24606 it
->ascent
+= face
->box_line_width
;
24607 it
->descent
+= face
->box_line_width
;
24610 && XINT (height
) > it
->ascent
+ it
->descent
)
24611 it
->ascent
= XINT (height
) - it
->descent
;
24613 if (!NILP (total_height
))
24614 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24617 spacing
= get_it_property (it
, Qline_spacing
);
24618 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24620 if (INTEGERP (spacing
))
24622 extra_line_spacing
= XINT (spacing
);
24623 if (!NILP (total_height
))
24624 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24628 else /* i.e. (it->char_to_display == '\t') */
24630 if (font
->space_width
> 0)
24632 int tab_width
= it
->tab_width
* font
->space_width
;
24633 int x
= it
->current_x
+ it
->continuation_lines_width
;
24634 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24636 /* If the distance from the current position to the next tab
24637 stop is less than a space character width, use the
24638 tab stop after that. */
24639 if (next_tab_x
- x
< font
->space_width
)
24640 next_tab_x
+= tab_width
;
24642 it
->pixel_width
= next_tab_x
- x
;
24644 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24645 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24649 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24650 it
->ascent
+ it
->descent
, it
->ascent
);
24655 it
->pixel_width
= 0;
24660 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24662 /* A static composition.
24664 Note: A composition is represented as one glyph in the
24665 glyph matrix. There are no padding glyphs.
24667 Important note: pixel_width, ascent, and descent are the
24668 values of what is drawn by draw_glyphs (i.e. the values of
24669 the overall glyphs composed). */
24670 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24671 int boff
; /* baseline offset */
24672 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24673 int glyph_len
= cmp
->glyph_len
;
24674 struct font
*font
= face
->font
;
24678 /* If we have not yet calculated pixel size data of glyphs of
24679 the composition for the current face font, calculate them
24680 now. Theoretically, we have to check all fonts for the
24681 glyphs, but that requires much time and memory space. So,
24682 here we check only the font of the first glyph. This may
24683 lead to incorrect display, but it's very rare, and C-l
24684 (recenter-top-bottom) can correct the display anyway. */
24685 if (! cmp
->font
|| cmp
->font
!= font
)
24687 /* Ascent and descent of the font of the first character
24688 of this composition (adjusted by baseline offset).
24689 Ascent and descent of overall glyphs should not be less
24690 than these, respectively. */
24691 int font_ascent
, font_descent
, font_height
;
24692 /* Bounding box of the overall glyphs. */
24693 int leftmost
, rightmost
, lowest
, highest
;
24694 int lbearing
, rbearing
;
24695 int i
, width
, ascent
, descent
;
24696 int left_padded
= 0, right_padded
= 0;
24697 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24699 struct font_metrics
*pcm
;
24700 int font_not_found_p
;
24703 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24704 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24706 if (glyph_len
< cmp
->glyph_len
)
24708 for (i
= 0; i
< glyph_len
; i
++)
24710 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24712 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24717 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24718 : IT_CHARPOS (*it
));
24719 /* If no suitable font is found, use the default font. */
24720 font_not_found_p
= font
== NULL
;
24721 if (font_not_found_p
)
24723 face
= face
->ascii_face
;
24726 boff
= font
->baseline_offset
;
24727 if (font
->vertical_centering
)
24728 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24729 font_ascent
= FONT_BASE (font
) + boff
;
24730 font_descent
= FONT_DESCENT (font
) - boff
;
24731 font_height
= FONT_HEIGHT (font
);
24733 cmp
->font
= (void *) font
;
24736 if (! font_not_found_p
)
24738 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24740 pcm
= get_per_char_metric (font
, &char2b
);
24743 /* Initialize the bounding box. */
24746 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24747 ascent
= pcm
->ascent
;
24748 descent
= pcm
->descent
;
24749 lbearing
= pcm
->lbearing
;
24750 rbearing
= pcm
->rbearing
;
24754 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24755 ascent
= FONT_BASE (font
);
24756 descent
= FONT_DESCENT (font
);
24763 lowest
= - descent
+ boff
;
24764 highest
= ascent
+ boff
;
24766 if (! font_not_found_p
24767 && font
->default_ascent
24768 && CHAR_TABLE_P (Vuse_default_ascent
)
24769 && !NILP (Faref (Vuse_default_ascent
,
24770 make_number (it
->char_to_display
))))
24771 highest
= font
->default_ascent
+ boff
;
24773 /* Draw the first glyph at the normal position. It may be
24774 shifted to right later if some other glyphs are drawn
24776 cmp
->offsets
[i
* 2] = 0;
24777 cmp
->offsets
[i
* 2 + 1] = boff
;
24778 cmp
->lbearing
= lbearing
;
24779 cmp
->rbearing
= rbearing
;
24781 /* Set cmp->offsets for the remaining glyphs. */
24782 for (i
++; i
< glyph_len
; i
++)
24784 int left
, right
, btm
, top
;
24785 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24787 struct face
*this_face
;
24791 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24792 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24793 font
= this_face
->font
;
24799 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24801 pcm
= get_per_char_metric (font
, &char2b
);
24804 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24807 width
= pcm
->width
;
24808 ascent
= pcm
->ascent
;
24809 descent
= pcm
->descent
;
24810 lbearing
= pcm
->lbearing
;
24811 rbearing
= pcm
->rbearing
;
24812 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24814 /* Relative composition with or without
24815 alternate chars. */
24816 left
= (leftmost
+ rightmost
- width
) / 2;
24817 btm
= - descent
+ boff
;
24818 if (font
->relative_compose
24819 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24820 || NILP (Faref (Vignore_relative_composition
,
24821 make_number (ch
)))))
24824 if (- descent
>= font
->relative_compose
)
24825 /* One extra pixel between two glyphs. */
24827 else if (ascent
<= 0)
24828 /* One extra pixel between two glyphs. */
24829 btm
= lowest
- 1 - ascent
- descent
;
24834 /* A composition rule is specified by an integer
24835 value that encodes global and new reference
24836 points (GREF and NREF). GREF and NREF are
24837 specified by numbers as below:
24839 0---1---2 -- ascent
24843 9--10--11 -- center
24845 ---3---4---5--- baseline
24847 6---7---8 -- descent
24849 int rule
= COMPOSITION_RULE (cmp
, i
);
24850 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24852 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24853 grefx
= gref
% 3, nrefx
= nref
% 3;
24854 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24856 xoff
= font_height
* (xoff
- 128) / 256;
24858 yoff
= font_height
* (yoff
- 128) / 256;
24861 + grefx
* (rightmost
- leftmost
) / 2
24862 - nrefx
* width
/ 2
24865 btm
= ((grefy
== 0 ? highest
24867 : grefy
== 2 ? lowest
24868 : (highest
+ lowest
) / 2)
24869 - (nrefy
== 0 ? ascent
+ descent
24870 : nrefy
== 1 ? descent
- boff
24872 : (ascent
+ descent
) / 2)
24876 cmp
->offsets
[i
* 2] = left
;
24877 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24879 /* Update the bounding box of the overall glyphs. */
24882 right
= left
+ width
;
24883 if (left
< leftmost
)
24885 if (right
> rightmost
)
24888 top
= btm
+ descent
+ ascent
;
24894 if (cmp
->lbearing
> left
+ lbearing
)
24895 cmp
->lbearing
= left
+ lbearing
;
24896 if (cmp
->rbearing
< left
+ rbearing
)
24897 cmp
->rbearing
= left
+ rbearing
;
24901 /* If there are glyphs whose x-offsets are negative,
24902 shift all glyphs to the right and make all x-offsets
24906 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24907 cmp
->offsets
[i
* 2] -= leftmost
;
24908 rightmost
-= leftmost
;
24909 cmp
->lbearing
-= leftmost
;
24910 cmp
->rbearing
-= leftmost
;
24913 if (left_padded
&& cmp
->lbearing
< 0)
24915 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24916 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24917 rightmost
-= cmp
->lbearing
;
24918 cmp
->rbearing
-= cmp
->lbearing
;
24921 if (right_padded
&& rightmost
< cmp
->rbearing
)
24923 rightmost
= cmp
->rbearing
;
24926 cmp
->pixel_width
= rightmost
;
24927 cmp
->ascent
= highest
;
24928 cmp
->descent
= - lowest
;
24929 if (cmp
->ascent
< font_ascent
)
24930 cmp
->ascent
= font_ascent
;
24931 if (cmp
->descent
< font_descent
)
24932 cmp
->descent
= font_descent
;
24936 && (cmp
->lbearing
< 0
24937 || cmp
->rbearing
> cmp
->pixel_width
))
24938 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24940 it
->pixel_width
= cmp
->pixel_width
;
24941 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24942 it
->descent
= it
->phys_descent
= cmp
->descent
;
24943 if (face
->box
!= FACE_NO_BOX
)
24945 int thick
= face
->box_line_width
;
24949 it
->ascent
+= thick
;
24950 it
->descent
+= thick
;
24955 if (it
->start_of_box_run_p
)
24956 it
->pixel_width
+= thick
;
24957 if (it
->end_of_box_run_p
)
24958 it
->pixel_width
+= thick
;
24961 /* If face has an overline, add the height of the overline
24962 (1 pixel) and a 1 pixel margin to the character height. */
24963 if (face
->overline_p
)
24964 it
->ascent
+= overline_margin
;
24966 take_vertical_position_into_account (it
);
24967 if (it
->ascent
< 0)
24969 if (it
->descent
< 0)
24972 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24973 append_composite_glyph (it
);
24975 else if (it
->what
== IT_COMPOSITION
)
24977 /* A dynamic (automatic) composition. */
24978 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24979 Lisp_Object gstring
;
24980 struct font_metrics metrics
;
24984 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24986 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24989 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24990 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24991 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24992 it
->descent
= it
->phys_descent
= metrics
.descent
;
24993 if (face
->box
!= FACE_NO_BOX
)
24995 int thick
= face
->box_line_width
;
24999 it
->ascent
+= thick
;
25000 it
->descent
+= thick
;
25005 if (it
->start_of_box_run_p
)
25006 it
->pixel_width
+= thick
;
25007 if (it
->end_of_box_run_p
)
25008 it
->pixel_width
+= thick
;
25010 /* If face has an overline, add the height of the overline
25011 (1 pixel) and a 1 pixel margin to the character height. */
25012 if (face
->overline_p
)
25013 it
->ascent
+= overline_margin
;
25014 take_vertical_position_into_account (it
);
25015 if (it
->ascent
< 0)
25017 if (it
->descent
< 0)
25021 append_composite_glyph (it
);
25023 else if (it
->what
== IT_GLYPHLESS
)
25024 produce_glyphless_glyph (it
, 0, Qnil
);
25025 else if (it
->what
== IT_IMAGE
)
25026 produce_image_glyph (it
);
25027 else if (it
->what
== IT_STRETCH
)
25028 produce_stretch_glyph (it
);
25031 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25032 because this isn't true for images with `:ascent 100'. */
25033 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25034 if (it
->area
== TEXT_AREA
)
25035 it
->current_x
+= it
->pixel_width
;
25037 if (extra_line_spacing
> 0)
25039 it
->descent
+= extra_line_spacing
;
25040 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25041 it
->max_extra_line_spacing
= extra_line_spacing
;
25044 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25045 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25046 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25047 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25051 Output LEN glyphs starting at START at the nominal cursor position.
25052 Advance the nominal cursor over the text. The global variable
25053 updated_window contains the window being updated, updated_row is
25054 the glyph row being updated, and updated_area is the area of that
25055 row being updated. */
25058 x_write_glyphs (struct glyph
*start
, int len
)
25060 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25062 eassert (updated_window
&& updated_row
);
25063 /* When the window is hscrolled, cursor hpos can legitimately be out
25064 of bounds, but we draw the cursor at the corresponding window
25065 margin in that case. */
25066 if (!updated_row
->reversed_p
&& chpos
< 0)
25068 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25069 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25073 /* Write glyphs. */
25075 hpos
= start
- updated_row
->glyphs
[updated_area
];
25076 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25077 updated_row
, updated_area
,
25079 DRAW_NORMAL_TEXT
, 0);
25081 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25082 if (updated_area
== TEXT_AREA
25083 && updated_window
->phys_cursor_on_p
25084 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25086 && chpos
< hpos
+ len
)
25087 updated_window
->phys_cursor_on_p
= 0;
25091 /* Advance the output cursor. */
25092 output_cursor
.hpos
+= len
;
25093 output_cursor
.x
= x
;
25098 Insert LEN glyphs from START at the nominal cursor position. */
25101 x_insert_glyphs (struct glyph
*start
, int len
)
25105 int line_height
, shift_by_width
, shifted_region_width
;
25106 struct glyph_row
*row
;
25107 struct glyph
*glyph
;
25108 int frame_x
, frame_y
;
25111 eassert (updated_window
&& updated_row
);
25113 w
= updated_window
;
25114 f
= XFRAME (WINDOW_FRAME (w
));
25116 /* Get the height of the line we are in. */
25118 line_height
= row
->height
;
25120 /* Get the width of the glyphs to insert. */
25121 shift_by_width
= 0;
25122 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25123 shift_by_width
+= glyph
->pixel_width
;
25125 /* Get the width of the region to shift right. */
25126 shifted_region_width
= (window_box_width (w
, updated_area
)
25131 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25132 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25134 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25135 line_height
, shift_by_width
);
25137 /* Write the glyphs. */
25138 hpos
= start
- row
->glyphs
[updated_area
];
25139 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25141 DRAW_NORMAL_TEXT
, 0);
25143 /* Advance the output cursor. */
25144 output_cursor
.hpos
+= len
;
25145 output_cursor
.x
+= shift_by_width
;
25151 Erase the current text line from the nominal cursor position
25152 (inclusive) to pixel column TO_X (exclusive). The idea is that
25153 everything from TO_X onward is already erased.
25155 TO_X is a pixel position relative to updated_area of
25156 updated_window. TO_X == -1 means clear to the end of this area. */
25159 x_clear_end_of_line (int to_x
)
25162 struct window
*w
= updated_window
;
25163 int max_x
, min_y
, max_y
;
25164 int from_x
, from_y
, to_y
;
25166 eassert (updated_window
&& updated_row
);
25167 f
= XFRAME (w
->frame
);
25169 if (updated_row
->full_width_p
)
25170 max_x
= WINDOW_TOTAL_WIDTH (w
);
25172 max_x
= window_box_width (w
, updated_area
);
25173 max_y
= window_text_bottom_y (w
);
25175 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25176 of window. For TO_X > 0, truncate to end of drawing area. */
25182 to_x
= min (to_x
, max_x
);
25184 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25186 /* Notice if the cursor will be cleared by this operation. */
25187 if (!updated_row
->full_width_p
)
25188 notice_overwritten_cursor (w
, updated_area
,
25189 output_cursor
.x
, -1,
25191 MATRIX_ROW_BOTTOM_Y (updated_row
));
25193 from_x
= output_cursor
.x
;
25195 /* Translate to frame coordinates. */
25196 if (updated_row
->full_width_p
)
25198 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25199 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25203 int area_left
= window_box_left (w
, updated_area
);
25204 from_x
+= area_left
;
25208 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25209 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25210 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25212 /* Prevent inadvertently clearing to end of the X window. */
25213 if (to_x
> from_x
&& to_y
> from_y
)
25216 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25217 to_x
- from_x
, to_y
- from_y
);
25222 #endif /* HAVE_WINDOW_SYSTEM */
25226 /***********************************************************************
25228 ***********************************************************************/
25230 /* Value is the internal representation of the specified cursor type
25231 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25232 of the bar cursor. */
25234 static enum text_cursor_kinds
25235 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25237 enum text_cursor_kinds type
;
25242 if (EQ (arg
, Qbox
))
25243 return FILLED_BOX_CURSOR
;
25245 if (EQ (arg
, Qhollow
))
25246 return HOLLOW_BOX_CURSOR
;
25248 if (EQ (arg
, Qbar
))
25255 && EQ (XCAR (arg
), Qbar
)
25256 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25258 *width
= XINT (XCDR (arg
));
25262 if (EQ (arg
, Qhbar
))
25265 return HBAR_CURSOR
;
25269 && EQ (XCAR (arg
), Qhbar
)
25270 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25272 *width
= XINT (XCDR (arg
));
25273 return HBAR_CURSOR
;
25276 /* Treat anything unknown as "hollow box cursor".
25277 It was bad to signal an error; people have trouble fixing
25278 .Xdefaults with Emacs, when it has something bad in it. */
25279 type
= HOLLOW_BOX_CURSOR
;
25284 /* Set the default cursor types for specified frame. */
25286 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25291 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25292 FRAME_CURSOR_WIDTH (f
) = width
;
25294 /* By default, set up the blink-off state depending on the on-state. */
25296 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25299 FRAME_BLINK_OFF_CURSOR (f
)
25300 = get_specified_cursor_type (XCDR (tem
), &width
);
25301 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25304 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25308 #ifdef HAVE_WINDOW_SYSTEM
25310 /* Return the cursor we want to be displayed in window W. Return
25311 width of bar/hbar cursor through WIDTH arg. Return with
25312 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25313 (i.e. if the `system caret' should track this cursor).
25315 In a mini-buffer window, we want the cursor only to appear if we
25316 are reading input from this window. For the selected window, we
25317 want the cursor type given by the frame parameter or buffer local
25318 setting of cursor-type. If explicitly marked off, draw no cursor.
25319 In all other cases, we want a hollow box cursor. */
25321 static enum text_cursor_kinds
25322 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25323 int *active_cursor
)
25325 struct frame
*f
= XFRAME (w
->frame
);
25326 struct buffer
*b
= XBUFFER (w
->buffer
);
25327 int cursor_type
= DEFAULT_CURSOR
;
25328 Lisp_Object alt_cursor
;
25329 int non_selected
= 0;
25331 *active_cursor
= 1;
25334 if (cursor_in_echo_area
25335 && FRAME_HAS_MINIBUF_P (f
)
25336 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25338 if (w
== XWINDOW (echo_area_window
))
25340 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25342 *width
= FRAME_CURSOR_WIDTH (f
);
25343 return FRAME_DESIRED_CURSOR (f
);
25346 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25349 *active_cursor
= 0;
25353 /* Detect a nonselected window or nonselected frame. */
25354 else if (w
!= XWINDOW (f
->selected_window
)
25355 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25357 *active_cursor
= 0;
25359 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25365 /* Never display a cursor in a window in which cursor-type is nil. */
25366 if (NILP (BVAR (b
, cursor_type
)))
25369 /* Get the normal cursor type for this window. */
25370 if (EQ (BVAR (b
, cursor_type
), Qt
))
25372 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25373 *width
= FRAME_CURSOR_WIDTH (f
);
25376 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25378 /* Use cursor-in-non-selected-windows instead
25379 for non-selected window or frame. */
25382 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25383 if (!EQ (Qt
, alt_cursor
))
25384 return get_specified_cursor_type (alt_cursor
, width
);
25385 /* t means modify the normal cursor type. */
25386 if (cursor_type
== FILLED_BOX_CURSOR
)
25387 cursor_type
= HOLLOW_BOX_CURSOR
;
25388 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25390 return cursor_type
;
25393 /* Use normal cursor if not blinked off. */
25394 if (!w
->cursor_off_p
)
25396 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25398 if (cursor_type
== FILLED_BOX_CURSOR
)
25400 /* Using a block cursor on large images can be very annoying.
25401 So use a hollow cursor for "large" images.
25402 If image is not transparent (no mask), also use hollow cursor. */
25403 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25404 if (img
!= NULL
&& IMAGEP (img
->spec
))
25406 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25407 where N = size of default frame font size.
25408 This should cover most of the "tiny" icons people may use. */
25410 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25411 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25412 cursor_type
= HOLLOW_BOX_CURSOR
;
25415 else if (cursor_type
!= NO_CURSOR
)
25417 /* Display current only supports BOX and HOLLOW cursors for images.
25418 So for now, unconditionally use a HOLLOW cursor when cursor is
25419 not a solid box cursor. */
25420 cursor_type
= HOLLOW_BOX_CURSOR
;
25423 return cursor_type
;
25426 /* Cursor is blinked off, so determine how to "toggle" it. */
25428 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25429 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25430 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25432 /* Then see if frame has specified a specific blink off cursor type. */
25433 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25435 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25436 return FRAME_BLINK_OFF_CURSOR (f
);
25440 /* Some people liked having a permanently visible blinking cursor,
25441 while others had very strong opinions against it. So it was
25442 decided to remove it. KFS 2003-09-03 */
25444 /* Finally perform built-in cursor blinking:
25445 filled box <-> hollow box
25446 wide [h]bar <-> narrow [h]bar
25447 narrow [h]bar <-> no cursor
25448 other type <-> no cursor */
25450 if (cursor_type
== FILLED_BOX_CURSOR
)
25451 return HOLLOW_BOX_CURSOR
;
25453 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25456 return cursor_type
;
25464 /* Notice when the text cursor of window W has been completely
25465 overwritten by a drawing operation that outputs glyphs in AREA
25466 starting at X0 and ending at X1 in the line starting at Y0 and
25467 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25468 the rest of the line after X0 has been written. Y coordinates
25469 are window-relative. */
25472 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25473 int x0
, int x1
, int y0
, int y1
)
25475 int cx0
, cx1
, cy0
, cy1
;
25476 struct glyph_row
*row
;
25478 if (!w
->phys_cursor_on_p
)
25480 if (area
!= TEXT_AREA
)
25483 if (w
->phys_cursor
.vpos
< 0
25484 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25485 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25486 !(row
->enabled_p
&& row
->displays_text_p
)))
25489 if (row
->cursor_in_fringe_p
)
25491 row
->cursor_in_fringe_p
= 0;
25492 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25493 w
->phys_cursor_on_p
= 0;
25497 cx0
= w
->phys_cursor
.x
;
25498 cx1
= cx0
+ w
->phys_cursor_width
;
25499 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25502 /* The cursor image will be completely removed from the
25503 screen if the output area intersects the cursor area in
25504 y-direction. When we draw in [y0 y1[, and some part of
25505 the cursor is at y < y0, that part must have been drawn
25506 before. When scrolling, the cursor is erased before
25507 actually scrolling, so we don't come here. When not
25508 scrolling, the rows above the old cursor row must have
25509 changed, and in this case these rows must have written
25510 over the cursor image.
25512 Likewise if part of the cursor is below y1, with the
25513 exception of the cursor being in the first blank row at
25514 the buffer and window end because update_text_area
25515 doesn't draw that row. (Except when it does, but
25516 that's handled in update_text_area.) */
25518 cy0
= w
->phys_cursor
.y
;
25519 cy1
= cy0
+ w
->phys_cursor_height
;
25520 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25523 w
->phys_cursor_on_p
= 0;
25526 #endif /* HAVE_WINDOW_SYSTEM */
25529 /************************************************************************
25531 ************************************************************************/
25533 #ifdef HAVE_WINDOW_SYSTEM
25536 Fix the display of area AREA of overlapping row ROW in window W
25537 with respect to the overlapping part OVERLAPS. */
25540 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25541 enum glyph_row_area area
, int overlaps
)
25548 for (i
= 0; i
< row
->used
[area
];)
25550 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25552 int start
= i
, start_x
= x
;
25556 x
+= row
->glyphs
[area
][i
].pixel_width
;
25559 while (i
< row
->used
[area
]
25560 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25562 draw_glyphs (w
, start_x
, row
, area
,
25564 DRAW_NORMAL_TEXT
, overlaps
);
25568 x
+= row
->glyphs
[area
][i
].pixel_width
;
25578 Draw the cursor glyph of window W in glyph row ROW. See the
25579 comment of draw_glyphs for the meaning of HL. */
25582 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25583 enum draw_glyphs_face hl
)
25585 /* If cursor hpos is out of bounds, don't draw garbage. This can
25586 happen in mini-buffer windows when switching between echo area
25587 glyphs and mini-buffer. */
25588 if ((row
->reversed_p
25589 ? (w
->phys_cursor
.hpos
>= 0)
25590 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25592 int on_p
= w
->phys_cursor_on_p
;
25594 int hpos
= w
->phys_cursor
.hpos
;
25596 /* When the window is hscrolled, cursor hpos can legitimately be
25597 out of bounds, but we draw the cursor at the corresponding
25598 window margin in that case. */
25599 if (!row
->reversed_p
&& hpos
< 0)
25601 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25602 hpos
= row
->used
[TEXT_AREA
] - 1;
25604 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25606 w
->phys_cursor_on_p
= on_p
;
25608 if (hl
== DRAW_CURSOR
)
25609 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25610 /* When we erase the cursor, and ROW is overlapped by other
25611 rows, make sure that these overlapping parts of other rows
25613 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25615 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25617 if (row
> w
->current_matrix
->rows
25618 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25619 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25620 OVERLAPS_ERASED_CURSOR
);
25622 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25623 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25624 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25625 OVERLAPS_ERASED_CURSOR
);
25632 Erase the image of a cursor of window W from the screen. */
25635 erase_phys_cursor (struct window
*w
)
25637 struct frame
*f
= XFRAME (w
->frame
);
25638 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25639 int hpos
= w
->phys_cursor
.hpos
;
25640 int vpos
= w
->phys_cursor
.vpos
;
25641 int mouse_face_here_p
= 0;
25642 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25643 struct glyph_row
*cursor_row
;
25644 struct glyph
*cursor_glyph
;
25645 enum draw_glyphs_face hl
;
25647 /* No cursor displayed or row invalidated => nothing to do on the
25649 if (w
->phys_cursor_type
== NO_CURSOR
)
25650 goto mark_cursor_off
;
25652 /* VPOS >= active_glyphs->nrows means that window has been resized.
25653 Don't bother to erase the cursor. */
25654 if (vpos
>= active_glyphs
->nrows
)
25655 goto mark_cursor_off
;
25657 /* If row containing cursor is marked invalid, there is nothing we
25659 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25660 if (!cursor_row
->enabled_p
)
25661 goto mark_cursor_off
;
25663 /* If line spacing is > 0, old cursor may only be partially visible in
25664 window after split-window. So adjust visible height. */
25665 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25666 window_text_bottom_y (w
) - cursor_row
->y
);
25668 /* If row is completely invisible, don't attempt to delete a cursor which
25669 isn't there. This can happen if cursor is at top of a window, and
25670 we switch to a buffer with a header line in that window. */
25671 if (cursor_row
->visible_height
<= 0)
25672 goto mark_cursor_off
;
25674 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25675 if (cursor_row
->cursor_in_fringe_p
)
25677 cursor_row
->cursor_in_fringe_p
= 0;
25678 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25679 goto mark_cursor_off
;
25682 /* This can happen when the new row is shorter than the old one.
25683 In this case, either draw_glyphs or clear_end_of_line
25684 should have cleared the cursor. Note that we wouldn't be
25685 able to erase the cursor in this case because we don't have a
25686 cursor glyph at hand. */
25687 if ((cursor_row
->reversed_p
25688 ? (w
->phys_cursor
.hpos
< 0)
25689 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25690 goto mark_cursor_off
;
25692 /* When the window is hscrolled, cursor hpos can legitimately be out
25693 of bounds, but we draw the cursor at the corresponding window
25694 margin in that case. */
25695 if (!cursor_row
->reversed_p
&& hpos
< 0)
25697 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25698 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25700 /* If the cursor is in the mouse face area, redisplay that when
25701 we clear the cursor. */
25702 if (! NILP (hlinfo
->mouse_face_window
)
25703 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25704 /* Don't redraw the cursor's spot in mouse face if it is at the
25705 end of a line (on a newline). The cursor appears there, but
25706 mouse highlighting does not. */
25707 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25708 mouse_face_here_p
= 1;
25710 /* Maybe clear the display under the cursor. */
25711 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25714 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25717 cursor_glyph
= get_phys_cursor_glyph (w
);
25718 if (cursor_glyph
== NULL
)
25719 goto mark_cursor_off
;
25721 width
= cursor_glyph
->pixel_width
;
25722 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25723 x
= w
->phys_cursor
.x
;
25725 width
-= left_x
- x
;
25726 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25727 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25728 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25731 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25734 /* Erase the cursor by redrawing the character underneath it. */
25735 if (mouse_face_here_p
)
25736 hl
= DRAW_MOUSE_FACE
;
25738 hl
= DRAW_NORMAL_TEXT
;
25739 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25742 w
->phys_cursor_on_p
= 0;
25743 w
->phys_cursor_type
= NO_CURSOR
;
25748 Display or clear cursor of window W. If ON is zero, clear the
25749 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25750 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25753 display_and_set_cursor (struct window
*w
, int on
,
25754 int hpos
, int vpos
, int x
, int y
)
25756 struct frame
*f
= XFRAME (w
->frame
);
25757 int new_cursor_type
;
25758 int new_cursor_width
;
25760 struct glyph_row
*glyph_row
;
25761 struct glyph
*glyph
;
25763 /* This is pointless on invisible frames, and dangerous on garbaged
25764 windows and frames; in the latter case, the frame or window may
25765 be in the midst of changing its size, and x and y may be off the
25767 if (! FRAME_VISIBLE_P (f
)
25768 || FRAME_GARBAGED_P (f
)
25769 || vpos
>= w
->current_matrix
->nrows
25770 || hpos
>= w
->current_matrix
->matrix_w
)
25773 /* If cursor is off and we want it off, return quickly. */
25774 if (!on
&& !w
->phys_cursor_on_p
)
25777 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25778 /* If cursor row is not enabled, we don't really know where to
25779 display the cursor. */
25780 if (!glyph_row
->enabled_p
)
25782 w
->phys_cursor_on_p
= 0;
25787 if (!glyph_row
->exact_window_width_line_p
25788 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25789 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25791 eassert (interrupt_input_blocked
);
25793 /* Set new_cursor_type to the cursor we want to be displayed. */
25794 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25795 &new_cursor_width
, &active_cursor
);
25797 /* If cursor is currently being shown and we don't want it to be or
25798 it is in the wrong place, or the cursor type is not what we want,
25800 if (w
->phys_cursor_on_p
25802 || w
->phys_cursor
.x
!= x
25803 || w
->phys_cursor
.y
!= y
25804 || new_cursor_type
!= w
->phys_cursor_type
25805 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25806 && new_cursor_width
!= w
->phys_cursor_width
)))
25807 erase_phys_cursor (w
);
25809 /* Don't check phys_cursor_on_p here because that flag is only set
25810 to zero in some cases where we know that the cursor has been
25811 completely erased, to avoid the extra work of erasing the cursor
25812 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25813 still not be visible, or it has only been partly erased. */
25816 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25817 w
->phys_cursor_height
= glyph_row
->height
;
25819 /* Set phys_cursor_.* before x_draw_.* is called because some
25820 of them may need the information. */
25821 w
->phys_cursor
.x
= x
;
25822 w
->phys_cursor
.y
= glyph_row
->y
;
25823 w
->phys_cursor
.hpos
= hpos
;
25824 w
->phys_cursor
.vpos
= vpos
;
25827 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25828 new_cursor_type
, new_cursor_width
,
25829 on
, active_cursor
);
25833 /* Switch the display of W's cursor on or off, according to the value
25837 update_window_cursor (struct window
*w
, int on
)
25839 /* Don't update cursor in windows whose frame is in the process
25840 of being deleted. */
25841 if (w
->current_matrix
)
25843 int hpos
= w
->phys_cursor
.hpos
;
25844 int vpos
= w
->phys_cursor
.vpos
;
25845 struct glyph_row
*row
;
25847 if (vpos
>= w
->current_matrix
->nrows
25848 || hpos
>= w
->current_matrix
->matrix_w
)
25851 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25853 /* When the window is hscrolled, cursor hpos can legitimately be
25854 out of bounds, but we draw the cursor at the corresponding
25855 window margin in that case. */
25856 if (!row
->reversed_p
&& hpos
< 0)
25858 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25859 hpos
= row
->used
[TEXT_AREA
] - 1;
25862 display_and_set_cursor (w
, on
, hpos
, vpos
,
25863 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25869 /* Call update_window_cursor with parameter ON_P on all leaf windows
25870 in the window tree rooted at W. */
25873 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25877 if (!NILP (w
->hchild
))
25878 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25879 else if (!NILP (w
->vchild
))
25880 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25882 update_window_cursor (w
, on_p
);
25884 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25890 Display the cursor on window W, or clear it, according to ON_P.
25891 Don't change the cursor's position. */
25894 x_update_cursor (struct frame
*f
, int on_p
)
25896 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25901 Clear the cursor of window W to background color, and mark the
25902 cursor as not shown. This is used when the text where the cursor
25903 is about to be rewritten. */
25906 x_clear_cursor (struct window
*w
)
25908 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25909 update_window_cursor (w
, 0);
25912 #endif /* HAVE_WINDOW_SYSTEM */
25914 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25917 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25918 int start_hpos
, int end_hpos
,
25919 enum draw_glyphs_face draw
)
25921 #ifdef HAVE_WINDOW_SYSTEM
25922 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25924 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25928 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
25929 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25933 /* Display the active region described by mouse_face_* according to DRAW. */
25936 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25938 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25939 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25941 if (/* If window is in the process of being destroyed, don't bother
25943 w
->current_matrix
!= NULL
25944 /* Don't update mouse highlight if hidden */
25945 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25946 /* Recognize when we are called to operate on rows that don't exist
25947 anymore. This can happen when a window is split. */
25948 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25950 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25951 struct glyph_row
*row
, *first
, *last
;
25953 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25954 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25956 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25958 int start_hpos
, end_hpos
, start_x
;
25960 /* For all but the first row, the highlight starts at column 0. */
25963 /* R2L rows have BEG and END in reversed order, but the
25964 screen drawing geometry is always left to right. So
25965 we need to mirror the beginning and end of the
25966 highlighted area in R2L rows. */
25967 if (!row
->reversed_p
)
25969 start_hpos
= hlinfo
->mouse_face_beg_col
;
25970 start_x
= hlinfo
->mouse_face_beg_x
;
25972 else if (row
== last
)
25974 start_hpos
= hlinfo
->mouse_face_end_col
;
25975 start_x
= hlinfo
->mouse_face_end_x
;
25983 else if (row
->reversed_p
&& row
== last
)
25985 start_hpos
= hlinfo
->mouse_face_end_col
;
25986 start_x
= hlinfo
->mouse_face_end_x
;
25996 if (!row
->reversed_p
)
25997 end_hpos
= hlinfo
->mouse_face_end_col
;
25998 else if (row
== first
)
25999 end_hpos
= hlinfo
->mouse_face_beg_col
;
26002 end_hpos
= row
->used
[TEXT_AREA
];
26003 if (draw
== DRAW_NORMAL_TEXT
)
26004 row
->fill_line_p
= 1; /* Clear to end of line */
26007 else if (row
->reversed_p
&& row
== first
)
26008 end_hpos
= hlinfo
->mouse_face_beg_col
;
26011 end_hpos
= row
->used
[TEXT_AREA
];
26012 if (draw
== DRAW_NORMAL_TEXT
)
26013 row
->fill_line_p
= 1; /* Clear to end of line */
26016 if (end_hpos
> start_hpos
)
26018 draw_row_with_mouse_face (w
, start_x
, row
,
26019 start_hpos
, end_hpos
, draw
);
26022 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26026 #ifdef HAVE_WINDOW_SYSTEM
26027 /* When we've written over the cursor, arrange for it to
26028 be displayed again. */
26029 if (FRAME_WINDOW_P (f
)
26030 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26032 int hpos
= w
->phys_cursor
.hpos
;
26034 /* When the window is hscrolled, cursor hpos can legitimately be
26035 out of bounds, but we draw the cursor at the corresponding
26036 window margin in that case. */
26037 if (!row
->reversed_p
&& hpos
< 0)
26039 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26040 hpos
= row
->used
[TEXT_AREA
] - 1;
26043 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26044 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26047 #endif /* HAVE_WINDOW_SYSTEM */
26050 #ifdef HAVE_WINDOW_SYSTEM
26051 /* Change the mouse cursor. */
26052 if (FRAME_WINDOW_P (f
))
26054 if (draw
== DRAW_NORMAL_TEXT
26055 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26056 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26057 else if (draw
== DRAW_MOUSE_FACE
)
26058 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26060 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26062 #endif /* HAVE_WINDOW_SYSTEM */
26066 Clear out the mouse-highlighted active region.
26067 Redraw it un-highlighted first. Value is non-zero if mouse
26068 face was actually drawn unhighlighted. */
26071 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26075 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26077 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26081 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26082 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26083 hlinfo
->mouse_face_window
= Qnil
;
26084 hlinfo
->mouse_face_overlay
= Qnil
;
26088 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26089 within the mouse face on that window. */
26091 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26093 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26095 /* Quickly resolve the easy cases. */
26096 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26097 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26099 if (vpos
< hlinfo
->mouse_face_beg_row
26100 || vpos
> hlinfo
->mouse_face_end_row
)
26102 if (vpos
> hlinfo
->mouse_face_beg_row
26103 && vpos
< hlinfo
->mouse_face_end_row
)
26106 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26108 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26110 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26113 else if ((vpos
== hlinfo
->mouse_face_beg_row
26114 && hpos
>= hlinfo
->mouse_face_beg_col
)
26115 || (vpos
== hlinfo
->mouse_face_end_row
26116 && hpos
< hlinfo
->mouse_face_end_col
))
26121 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26123 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26126 else if ((vpos
== hlinfo
->mouse_face_beg_row
26127 && hpos
<= hlinfo
->mouse_face_beg_col
)
26128 || (vpos
== hlinfo
->mouse_face_end_row
26129 && hpos
> hlinfo
->mouse_face_end_col
))
26137 Non-zero if physical cursor of window W is within mouse face. */
26140 cursor_in_mouse_face_p (struct window
*w
)
26142 int hpos
= w
->phys_cursor
.hpos
;
26143 int vpos
= w
->phys_cursor
.vpos
;
26144 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26146 /* When the window is hscrolled, cursor hpos can legitimately be out
26147 of bounds, but we draw the cursor at the corresponding window
26148 margin in that case. */
26149 if (!row
->reversed_p
&& hpos
< 0)
26151 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26152 hpos
= row
->used
[TEXT_AREA
] - 1;
26154 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26159 /* Find the glyph rows START_ROW and END_ROW of window W that display
26160 characters between buffer positions START_CHARPOS and END_CHARPOS
26161 (excluding END_CHARPOS). DISP_STRING is a display string that
26162 covers these buffer positions. This is similar to
26163 row_containing_pos, but is more accurate when bidi reordering makes
26164 buffer positions change non-linearly with glyph rows. */
26166 rows_from_pos_range (struct window
*w
,
26167 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26168 Lisp_Object disp_string
,
26169 struct glyph_row
**start
, struct glyph_row
**end
)
26171 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26172 int last_y
= window_text_bottom_y (w
);
26173 struct glyph_row
*row
;
26178 while (!first
->enabled_p
26179 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26182 /* Find the START row. */
26184 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26187 /* A row can potentially be the START row if the range of the
26188 characters it displays intersects the range
26189 [START_CHARPOS..END_CHARPOS). */
26190 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26191 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26192 /* See the commentary in row_containing_pos, for the
26193 explanation of the complicated way to check whether
26194 some position is beyond the end of the characters
26195 displayed by a row. */
26196 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26197 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26198 && !row
->ends_at_zv_p
26199 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26200 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26201 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26202 && !row
->ends_at_zv_p
26203 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26205 /* Found a candidate row. Now make sure at least one of the
26206 glyphs it displays has a charpos from the range
26207 [START_CHARPOS..END_CHARPOS).
26209 This is not obvious because bidi reordering could make
26210 buffer positions of a row be 1,2,3,102,101,100, and if we
26211 want to highlight characters in [50..60), we don't want
26212 this row, even though [50..60) does intersect [1..103),
26213 the range of character positions given by the row's start
26214 and end positions. */
26215 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26216 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26220 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26221 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26222 /* A glyph that comes from DISP_STRING is by
26223 definition to be highlighted. */
26224 || EQ (g
->object
, disp_string
))
26233 /* Find the END row. */
26235 /* If the last row is partially visible, start looking for END
26236 from that row, instead of starting from FIRST. */
26237 && !(row
->enabled_p
26238 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26240 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26242 struct glyph_row
*next
= row
+ 1;
26243 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26245 if (!next
->enabled_p
26246 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26247 /* The first row >= START whose range of displayed characters
26248 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26249 is the row END + 1. */
26250 || (start_charpos
< next_start
26251 && end_charpos
< next_start
)
26252 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26253 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26254 && !next
->ends_at_zv_p
26255 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26256 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26257 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26258 && !next
->ends_at_zv_p
26259 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26266 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26267 but none of the characters it displays are in the range, it is
26269 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26270 struct glyph
*s
= g
;
26271 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26275 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26276 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26277 /* If the buffer position of the first glyph in
26278 the row is equal to END_CHARPOS, it means
26279 the last character to be highlighted is the
26280 newline of ROW, and we must consider NEXT as
26282 || (((!next
->reversed_p
&& g
== s
)
26283 || (next
->reversed_p
&& g
== e
- 1))
26284 && (g
->charpos
== end_charpos
26285 /* Special case for when NEXT is an
26286 empty line at ZV. */
26287 || (g
->charpos
== -1
26288 && !row
->ends_at_zv_p
26289 && next_start
== end_charpos
)))))
26290 /* A glyph that comes from DISP_STRING is by
26291 definition to be highlighted. */
26292 || EQ (g
->object
, disp_string
))
26301 /* The first row that ends at ZV must be the last to be
26303 else if (next
->ends_at_zv_p
)
26312 /* This function sets the mouse_face_* elements of HLINFO, assuming
26313 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26314 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26315 for the overlay or run of text properties specifying the mouse
26316 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26317 before-string and after-string that must also be highlighted.
26318 DISP_STRING, if non-nil, is a display string that may cover some
26319 or all of the highlighted text. */
26322 mouse_face_from_buffer_pos (Lisp_Object window
,
26323 Mouse_HLInfo
*hlinfo
,
26324 ptrdiff_t mouse_charpos
,
26325 ptrdiff_t start_charpos
,
26326 ptrdiff_t end_charpos
,
26327 Lisp_Object before_string
,
26328 Lisp_Object after_string
,
26329 Lisp_Object disp_string
)
26331 struct window
*w
= XWINDOW (window
);
26332 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26333 struct glyph_row
*r1
, *r2
;
26334 struct glyph
*glyph
, *end
;
26335 ptrdiff_t ignore
, pos
;
26338 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26339 eassert (NILP (before_string
) || STRINGP (before_string
));
26340 eassert (NILP (after_string
) || STRINGP (after_string
));
26342 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26343 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26345 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26346 /* If the before-string or display-string contains newlines,
26347 rows_from_pos_range skips to its last row. Move back. */
26348 if (!NILP (before_string
) || !NILP (disp_string
))
26350 struct glyph_row
*prev
;
26351 while ((prev
= r1
- 1, prev
>= first
)
26352 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26353 && prev
->used
[TEXT_AREA
] > 0)
26355 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26356 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26357 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26359 || !(EQ (glyph
->object
, before_string
)
26360 || EQ (glyph
->object
, disp_string
)))
26367 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26368 hlinfo
->mouse_face_past_end
= 1;
26370 else if (!NILP (after_string
))
26372 /* If the after-string has newlines, advance to its last row. */
26373 struct glyph_row
*next
;
26374 struct glyph_row
*last
26375 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26377 for (next
= r2
+ 1;
26379 && next
->used
[TEXT_AREA
] > 0
26380 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26384 /* The rest of the display engine assumes that mouse_face_beg_row is
26385 either above mouse_face_end_row or identical to it. But with
26386 bidi-reordered continued lines, the row for START_CHARPOS could
26387 be below the row for END_CHARPOS. If so, swap the rows and store
26388 them in correct order. */
26391 struct glyph_row
*tem
= r2
;
26397 hlinfo
->mouse_face_beg_y
= r1
->y
;
26398 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26399 hlinfo
->mouse_face_end_y
= r2
->y
;
26400 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26402 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26403 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26404 could be anywhere in the row and in any order. The strategy
26405 below is to find the leftmost and the rightmost glyph that
26406 belongs to either of these 3 strings, or whose position is
26407 between START_CHARPOS and END_CHARPOS, and highlight all the
26408 glyphs between those two. This may cover more than just the text
26409 between START_CHARPOS and END_CHARPOS if the range of characters
26410 strides the bidi level boundary, e.g. if the beginning is in R2L
26411 text while the end is in L2R text or vice versa. */
26412 if (!r1
->reversed_p
)
26414 /* This row is in a left to right paragraph. Scan it left to
26416 glyph
= r1
->glyphs
[TEXT_AREA
];
26417 end
= glyph
+ r1
->used
[TEXT_AREA
];
26420 /* Skip truncation glyphs at the start of the glyph row. */
26421 if (r1
->displays_text_p
)
26423 && INTEGERP (glyph
->object
)
26424 && glyph
->charpos
< 0;
26426 x
+= glyph
->pixel_width
;
26428 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26429 or DISP_STRING, and the first glyph from buffer whose
26430 position is between START_CHARPOS and END_CHARPOS. */
26432 && !INTEGERP (glyph
->object
)
26433 && !EQ (glyph
->object
, disp_string
)
26434 && !(BUFFERP (glyph
->object
)
26435 && (glyph
->charpos
>= start_charpos
26436 && glyph
->charpos
< end_charpos
));
26439 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26440 are present at buffer positions between START_CHARPOS and
26441 END_CHARPOS, or if they come from an overlay. */
26442 if (EQ (glyph
->object
, before_string
))
26444 pos
= string_buffer_position (before_string
,
26446 /* If pos == 0, it means before_string came from an
26447 overlay, not from a buffer position. */
26448 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26451 else if (EQ (glyph
->object
, after_string
))
26453 pos
= string_buffer_position (after_string
, end_charpos
);
26454 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26457 x
+= glyph
->pixel_width
;
26459 hlinfo
->mouse_face_beg_x
= x
;
26460 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26464 /* This row is in a right to left paragraph. Scan it right to
26468 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26469 glyph
= end
+ r1
->used
[TEXT_AREA
];
26471 /* Skip truncation glyphs at the start of the glyph row. */
26472 if (r1
->displays_text_p
)
26474 && INTEGERP (glyph
->object
)
26475 && glyph
->charpos
< 0;
26479 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26480 or DISP_STRING, and the first glyph from buffer whose
26481 position is between START_CHARPOS and END_CHARPOS. */
26483 && !INTEGERP (glyph
->object
)
26484 && !EQ (glyph
->object
, disp_string
)
26485 && !(BUFFERP (glyph
->object
)
26486 && (glyph
->charpos
>= start_charpos
26487 && glyph
->charpos
< end_charpos
));
26490 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26491 are present at buffer positions between START_CHARPOS and
26492 END_CHARPOS, or if they come from an overlay. */
26493 if (EQ (glyph
->object
, before_string
))
26495 pos
= string_buffer_position (before_string
, start_charpos
);
26496 /* If pos == 0, it means before_string came from an
26497 overlay, not from a buffer position. */
26498 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26501 else if (EQ (glyph
->object
, after_string
))
26503 pos
= string_buffer_position (after_string
, end_charpos
);
26504 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26509 glyph
++; /* first glyph to the right of the highlighted area */
26510 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26511 x
+= g
->pixel_width
;
26512 hlinfo
->mouse_face_beg_x
= x
;
26513 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26516 /* If the highlight ends in a different row, compute GLYPH and END
26517 for the end row. Otherwise, reuse the values computed above for
26518 the row where the highlight begins. */
26521 if (!r2
->reversed_p
)
26523 glyph
= r2
->glyphs
[TEXT_AREA
];
26524 end
= glyph
+ r2
->used
[TEXT_AREA
];
26529 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26530 glyph
= end
+ r2
->used
[TEXT_AREA
];
26534 if (!r2
->reversed_p
)
26536 /* Skip truncation and continuation glyphs near the end of the
26537 row, and also blanks and stretch glyphs inserted by
26538 extend_face_to_end_of_line. */
26540 && INTEGERP ((end
- 1)->object
))
26542 /* Scan the rest of the glyph row from the end, looking for the
26543 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26544 DISP_STRING, or whose position is between START_CHARPOS
26548 && !INTEGERP (end
->object
)
26549 && !EQ (end
->object
, disp_string
)
26550 && !(BUFFERP (end
->object
)
26551 && (end
->charpos
>= start_charpos
26552 && end
->charpos
< end_charpos
));
26555 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26556 are present at buffer positions between START_CHARPOS and
26557 END_CHARPOS, or if they come from an overlay. */
26558 if (EQ (end
->object
, before_string
))
26560 pos
= string_buffer_position (before_string
, start_charpos
);
26561 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26564 else if (EQ (end
->object
, after_string
))
26566 pos
= string_buffer_position (after_string
, end_charpos
);
26567 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26571 /* Find the X coordinate of the last glyph to be highlighted. */
26572 for (; glyph
<= end
; ++glyph
)
26573 x
+= glyph
->pixel_width
;
26575 hlinfo
->mouse_face_end_x
= x
;
26576 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26580 /* Skip truncation and continuation glyphs near the end of the
26581 row, and also blanks and stretch glyphs inserted by
26582 extend_face_to_end_of_line. */
26586 && INTEGERP (end
->object
))
26588 x
+= end
->pixel_width
;
26591 /* Scan the rest of the glyph row from the end, looking for the
26592 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26593 DISP_STRING, or whose position is between START_CHARPOS
26597 && !INTEGERP (end
->object
)
26598 && !EQ (end
->object
, disp_string
)
26599 && !(BUFFERP (end
->object
)
26600 && (end
->charpos
>= start_charpos
26601 && end
->charpos
< end_charpos
));
26604 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26605 are present at buffer positions between START_CHARPOS and
26606 END_CHARPOS, or if they come from an overlay. */
26607 if (EQ (end
->object
, before_string
))
26609 pos
= string_buffer_position (before_string
, start_charpos
);
26610 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26613 else if (EQ (end
->object
, after_string
))
26615 pos
= string_buffer_position (after_string
, end_charpos
);
26616 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26619 x
+= end
->pixel_width
;
26621 /* If we exited the above loop because we arrived at the last
26622 glyph of the row, and its buffer position is still not in
26623 range, it means the last character in range is the preceding
26624 newline. Bump the end column and x values to get past the
26627 && BUFFERP (end
->object
)
26628 && (end
->charpos
< start_charpos
26629 || end
->charpos
>= end_charpos
))
26631 x
+= end
->pixel_width
;
26634 hlinfo
->mouse_face_end_x
= x
;
26635 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26638 hlinfo
->mouse_face_window
= window
;
26639 hlinfo
->mouse_face_face_id
26640 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26642 !hlinfo
->mouse_face_hidden
, -1);
26643 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26646 /* The following function is not used anymore (replaced with
26647 mouse_face_from_string_pos), but I leave it here for the time
26648 being, in case someone would. */
26650 #if 0 /* not used */
26652 /* Find the position of the glyph for position POS in OBJECT in
26653 window W's current matrix, and return in *X, *Y the pixel
26654 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26656 RIGHT_P non-zero means return the position of the right edge of the
26657 glyph, RIGHT_P zero means return the left edge position.
26659 If no glyph for POS exists in the matrix, return the position of
26660 the glyph with the next smaller position that is in the matrix, if
26661 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26662 exists in the matrix, return the position of the glyph with the
26663 next larger position in OBJECT.
26665 Value is non-zero if a glyph was found. */
26668 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26669 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26671 int yb
= window_text_bottom_y (w
);
26672 struct glyph_row
*r
;
26673 struct glyph
*best_glyph
= NULL
;
26674 struct glyph_row
*best_row
= NULL
;
26677 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26678 r
->enabled_p
&& r
->y
< yb
;
26681 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26682 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26685 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26686 if (EQ (g
->object
, object
))
26688 if (g
->charpos
== pos
)
26695 else if (best_glyph
== NULL
26696 || ((eabs (g
->charpos
- pos
)
26697 < eabs (best_glyph
->charpos
- pos
))
26700 : g
->charpos
> pos
)))
26714 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26718 *x
+= best_glyph
->pixel_width
;
26723 *vpos
= best_row
- w
->current_matrix
->rows
;
26726 return best_glyph
!= NULL
;
26728 #endif /* not used */
26730 /* Find the positions of the first and the last glyphs in window W's
26731 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26732 (assumed to be a string), and return in HLINFO's mouse_face_*
26733 members the pixel and column/row coordinates of those glyphs. */
26736 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26737 Lisp_Object object
,
26738 ptrdiff_t startpos
, ptrdiff_t endpos
)
26740 int yb
= window_text_bottom_y (w
);
26741 struct glyph_row
*r
;
26742 struct glyph
*g
, *e
;
26746 /* Find the glyph row with at least one position in the range
26747 [STARTPOS..ENDPOS], and the first glyph in that row whose
26748 position belongs to that range. */
26749 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26750 r
->enabled_p
&& r
->y
< yb
;
26753 if (!r
->reversed_p
)
26755 g
= r
->glyphs
[TEXT_AREA
];
26756 e
= g
+ r
->used
[TEXT_AREA
];
26757 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26758 if (EQ (g
->object
, object
)
26759 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26761 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26762 hlinfo
->mouse_face_beg_y
= r
->y
;
26763 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26764 hlinfo
->mouse_face_beg_x
= gx
;
26773 e
= r
->glyphs
[TEXT_AREA
];
26774 g
= e
+ r
->used
[TEXT_AREA
];
26775 for ( ; g
> e
; --g
)
26776 if (EQ ((g
-1)->object
, object
)
26777 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26779 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26780 hlinfo
->mouse_face_beg_y
= r
->y
;
26781 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26782 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26783 gx
+= g1
->pixel_width
;
26784 hlinfo
->mouse_face_beg_x
= gx
;
26796 /* Starting with the next row, look for the first row which does NOT
26797 include any glyphs whose positions are in the range. */
26798 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26800 g
= r
->glyphs
[TEXT_AREA
];
26801 e
= g
+ r
->used
[TEXT_AREA
];
26803 for ( ; g
< e
; ++g
)
26804 if (EQ (g
->object
, object
)
26805 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26814 /* The highlighted region ends on the previous row. */
26817 /* Set the end row and its vertical pixel coordinate. */
26818 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26819 hlinfo
->mouse_face_end_y
= r
->y
;
26821 /* Compute and set the end column and the end column's horizontal
26822 pixel coordinate. */
26823 if (!r
->reversed_p
)
26825 g
= r
->glyphs
[TEXT_AREA
];
26826 e
= g
+ r
->used
[TEXT_AREA
];
26827 for ( ; e
> g
; --e
)
26828 if (EQ ((e
-1)->object
, object
)
26829 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26831 hlinfo
->mouse_face_end_col
= e
- g
;
26833 for (gx
= r
->x
; g
< e
; ++g
)
26834 gx
+= g
->pixel_width
;
26835 hlinfo
->mouse_face_end_x
= gx
;
26839 e
= r
->glyphs
[TEXT_AREA
];
26840 g
= e
+ r
->used
[TEXT_AREA
];
26841 for (gx
= r
->x
; e
< g
; ++e
)
26843 if (EQ (e
->object
, object
)
26844 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26846 gx
+= e
->pixel_width
;
26848 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26849 hlinfo
->mouse_face_end_x
= gx
;
26853 #ifdef HAVE_WINDOW_SYSTEM
26855 /* See if position X, Y is within a hot-spot of an image. */
26858 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26860 if (!CONSP (hot_spot
))
26863 if (EQ (XCAR (hot_spot
), Qrect
))
26865 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26866 Lisp_Object rect
= XCDR (hot_spot
);
26870 if (!CONSP (XCAR (rect
)))
26872 if (!CONSP (XCDR (rect
)))
26874 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26876 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26878 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26880 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26884 else if (EQ (XCAR (hot_spot
), Qcircle
))
26886 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26887 Lisp_Object circ
= XCDR (hot_spot
);
26888 Lisp_Object lr
, lx0
, ly0
;
26890 && CONSP (XCAR (circ
))
26891 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26892 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26893 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26895 double r
= XFLOATINT (lr
);
26896 double dx
= XINT (lx0
) - x
;
26897 double dy
= XINT (ly0
) - y
;
26898 return (dx
* dx
+ dy
* dy
<= r
* r
);
26901 else if (EQ (XCAR (hot_spot
), Qpoly
))
26903 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26904 if (VECTORP (XCDR (hot_spot
)))
26906 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26907 Lisp_Object
*poly
= v
->contents
;
26908 ptrdiff_t n
= v
->header
.size
;
26911 Lisp_Object lx
, ly
;
26914 /* Need an even number of coordinates, and at least 3 edges. */
26915 if (n
< 6 || n
& 1)
26918 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26919 If count is odd, we are inside polygon. Pixels on edges
26920 may or may not be included depending on actual geometry of the
26922 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26923 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26925 x0
= XINT (lx
), y0
= XINT (ly
);
26926 for (i
= 0; i
< n
; i
+= 2)
26928 int x1
= x0
, y1
= y0
;
26929 if ((lx
= poly
[i
], !INTEGERP (lx
))
26930 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26932 x0
= XINT (lx
), y0
= XINT (ly
);
26934 /* Does this segment cross the X line? */
26942 if (y
> y0
&& y
> y1
)
26944 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26954 find_hot_spot (Lisp_Object map
, int x
, int y
)
26956 while (CONSP (map
))
26958 if (CONSP (XCAR (map
))
26959 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26967 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26969 doc
: /* Lookup in image map MAP coordinates X and Y.
26970 An image map is an alist where each element has the format (AREA ID PLIST).
26971 An AREA is specified as either a rectangle, a circle, or a polygon:
26972 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26973 pixel coordinates of the upper left and bottom right corners.
26974 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26975 and the radius of the circle; r may be a float or integer.
26976 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26977 vector describes one corner in the polygon.
26978 Returns the alist element for the first matching AREA in MAP. */)
26979 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26987 return find_hot_spot (map
,
26988 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
26989 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
26993 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26995 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26997 /* Do not change cursor shape while dragging mouse. */
26998 if (!NILP (do_mouse_tracking
))
27001 if (!NILP (pointer
))
27003 if (EQ (pointer
, Qarrow
))
27004 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27005 else if (EQ (pointer
, Qhand
))
27006 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27007 else if (EQ (pointer
, Qtext
))
27008 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27009 else if (EQ (pointer
, intern ("hdrag")))
27010 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27011 #ifdef HAVE_X_WINDOWS
27012 else if (EQ (pointer
, intern ("vdrag")))
27013 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27015 else if (EQ (pointer
, intern ("hourglass")))
27016 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27017 else if (EQ (pointer
, Qmodeline
))
27018 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27020 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27023 if (cursor
!= No_Cursor
)
27024 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27027 #endif /* HAVE_WINDOW_SYSTEM */
27029 /* Take proper action when mouse has moved to the mode or header line
27030 or marginal area AREA of window W, x-position X and y-position Y.
27031 X is relative to the start of the text display area of W, so the
27032 width of bitmap areas and scroll bars must be subtracted to get a
27033 position relative to the start of the mode line. */
27036 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27037 enum window_part area
)
27039 struct window
*w
= XWINDOW (window
);
27040 struct frame
*f
= XFRAME (w
->frame
);
27041 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27042 #ifdef HAVE_WINDOW_SYSTEM
27043 Display_Info
*dpyinfo
;
27045 Cursor cursor
= No_Cursor
;
27046 Lisp_Object pointer
= Qnil
;
27047 int dx
, dy
, width
, height
;
27049 Lisp_Object string
, object
= Qnil
;
27050 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27052 Lisp_Object mouse_face
;
27053 int original_x_pixel
= x
;
27054 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27055 struct glyph_row
*row
IF_LINT (= 0);
27057 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27062 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27063 returns them in row/column units! */
27064 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27065 &object
, &dx
, &dy
, &width
, &height
);
27067 row
= (area
== ON_MODE_LINE
27068 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27069 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27071 /* Find the glyph under the mouse pointer. */
27072 if (row
->mode_line_p
&& row
->enabled_p
)
27074 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27075 end
= glyph
+ row
->used
[TEXT_AREA
];
27077 for (x0
= original_x_pixel
;
27078 glyph
< end
&& x0
>= glyph
->pixel_width
;
27080 x0
-= glyph
->pixel_width
;
27088 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27089 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27090 returns them in row/column units! */
27091 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27092 &object
, &dx
, &dy
, &width
, &height
);
27097 #ifdef HAVE_WINDOW_SYSTEM
27098 if (IMAGEP (object
))
27100 Lisp_Object image_map
, hotspot
;
27101 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27103 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27105 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27109 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27110 If so, we could look for mouse-enter, mouse-leave
27111 properties in PLIST (and do something...). */
27112 hotspot
= XCDR (hotspot
);
27113 if (CONSP (hotspot
)
27114 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27116 pointer
= Fplist_get (plist
, Qpointer
);
27117 if (NILP (pointer
))
27119 help
= Fplist_get (plist
, Qhelp_echo
);
27122 help_echo_string
= help
;
27123 XSETWINDOW (help_echo_window
, w
);
27124 help_echo_object
= w
->buffer
;
27125 help_echo_pos
= charpos
;
27129 if (NILP (pointer
))
27130 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27132 #endif /* HAVE_WINDOW_SYSTEM */
27134 if (STRINGP (string
))
27135 pos
= make_number (charpos
);
27137 /* Set the help text and mouse pointer. If the mouse is on a part
27138 of the mode line without any text (e.g. past the right edge of
27139 the mode line text), use the default help text and pointer. */
27140 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27142 /* Arrange to display the help by setting the global variables
27143 help_echo_string, help_echo_object, and help_echo_pos. */
27146 if (STRINGP (string
))
27147 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27151 help_echo_string
= help
;
27152 XSETWINDOW (help_echo_window
, w
);
27153 help_echo_object
= string
;
27154 help_echo_pos
= charpos
;
27156 else if (area
== ON_MODE_LINE
)
27158 Lisp_Object default_help
27159 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27162 if (STRINGP (default_help
))
27164 help_echo_string
= default_help
;
27165 XSETWINDOW (help_echo_window
, w
);
27166 help_echo_object
= Qnil
;
27167 help_echo_pos
= -1;
27172 #ifdef HAVE_WINDOW_SYSTEM
27173 /* Change the mouse pointer according to what is under it. */
27174 if (FRAME_WINDOW_P (f
))
27176 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27177 if (STRINGP (string
))
27179 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27181 if (NILP (pointer
))
27182 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27184 /* Change the mouse pointer according to what is under X/Y. */
27186 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27189 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27190 if (!KEYMAPP (map
))
27191 map
= Fget_text_property (pos
, Qkeymap
, string
);
27192 if (!KEYMAPP (map
))
27193 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27197 /* Default mode-line pointer. */
27198 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27203 /* Change the mouse face according to what is under X/Y. */
27204 if (STRINGP (string
))
27206 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27207 if (!NILP (mouse_face
)
27208 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27213 struct glyph
* tmp_glyph
;
27217 int total_pixel_width
;
27218 ptrdiff_t begpos
, endpos
, ignore
;
27222 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27223 Qmouse_face
, string
, Qnil
);
27229 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27231 endpos
= SCHARS (string
);
27235 /* Calculate the glyph position GPOS of GLYPH in the
27236 displayed string, relative to the beginning of the
27237 highlighted part of the string.
27239 Note: GPOS is different from CHARPOS. CHARPOS is the
27240 position of GLYPH in the internal string object. A mode
27241 line string format has structures which are converted to
27242 a flattened string by the Emacs Lisp interpreter. The
27243 internal string is an element of those structures. The
27244 displayed string is the flattened string. */
27245 tmp_glyph
= row_start_glyph
;
27246 while (tmp_glyph
< glyph
27247 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27248 && begpos
<= tmp_glyph
->charpos
27249 && tmp_glyph
->charpos
< endpos
)))
27251 gpos
= glyph
- tmp_glyph
;
27253 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27254 the highlighted part of the displayed string to which
27255 GLYPH belongs. Note: GSEQ_LENGTH is different from
27256 SCHARS (STRING), because the latter returns the length of
27257 the internal string. */
27258 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27260 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27261 && begpos
<= tmp_glyph
->charpos
27262 && tmp_glyph
->charpos
< endpos
));
27265 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27267 /* Calculate the total pixel width of all the glyphs between
27268 the beginning of the highlighted area and GLYPH. */
27269 total_pixel_width
= 0;
27270 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27271 total_pixel_width
+= tmp_glyph
->pixel_width
;
27273 /* Pre calculation of re-rendering position. Note: X is in
27274 column units here, after the call to mode_line_string or
27275 marginal_area_string. */
27277 vpos
= (area
== ON_MODE_LINE
27278 ? (w
->current_matrix
)->nrows
- 1
27281 /* If GLYPH's position is included in the region that is
27282 already drawn in mouse face, we have nothing to do. */
27283 if ( EQ (window
, hlinfo
->mouse_face_window
)
27284 && (!row
->reversed_p
27285 ? (hlinfo
->mouse_face_beg_col
<= hpos
27286 && hpos
< hlinfo
->mouse_face_end_col
)
27287 /* In R2L rows we swap BEG and END, see below. */
27288 : (hlinfo
->mouse_face_end_col
<= hpos
27289 && hpos
< hlinfo
->mouse_face_beg_col
))
27290 && hlinfo
->mouse_face_beg_row
== vpos
)
27293 if (clear_mouse_face (hlinfo
))
27294 cursor
= No_Cursor
;
27296 if (!row
->reversed_p
)
27298 hlinfo
->mouse_face_beg_col
= hpos
;
27299 hlinfo
->mouse_face_beg_x
= original_x_pixel
27300 - (total_pixel_width
+ dx
);
27301 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27302 hlinfo
->mouse_face_end_x
= 0;
27306 /* In R2L rows, show_mouse_face expects BEG and END
27307 coordinates to be swapped. */
27308 hlinfo
->mouse_face_end_col
= hpos
;
27309 hlinfo
->mouse_face_end_x
= original_x_pixel
27310 - (total_pixel_width
+ dx
);
27311 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27312 hlinfo
->mouse_face_beg_x
= 0;
27315 hlinfo
->mouse_face_beg_row
= vpos
;
27316 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27317 hlinfo
->mouse_face_beg_y
= 0;
27318 hlinfo
->mouse_face_end_y
= 0;
27319 hlinfo
->mouse_face_past_end
= 0;
27320 hlinfo
->mouse_face_window
= window
;
27322 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27328 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27330 if (NILP (pointer
))
27333 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27334 clear_mouse_face (hlinfo
);
27336 #ifdef HAVE_WINDOW_SYSTEM
27337 if (FRAME_WINDOW_P (f
))
27338 define_frame_cursor1 (f
, cursor
, pointer
);
27344 Take proper action when the mouse has moved to position X, Y on
27345 frame F as regards highlighting characters that have mouse-face
27346 properties. Also de-highlighting chars where the mouse was before.
27347 X and Y can be negative or out of range. */
27350 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27352 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27353 enum window_part part
= ON_NOTHING
;
27354 Lisp_Object window
;
27356 Cursor cursor
= No_Cursor
;
27357 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27360 /* When a menu is active, don't highlight because this looks odd. */
27361 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27362 if (popup_activated ())
27366 if (NILP (Vmouse_highlight
)
27367 || !f
->glyphs_initialized_p
27368 || f
->pointer_invisible
)
27371 hlinfo
->mouse_face_mouse_x
= x
;
27372 hlinfo
->mouse_face_mouse_y
= y
;
27373 hlinfo
->mouse_face_mouse_frame
= f
;
27375 if (hlinfo
->mouse_face_defer
)
27378 if (gc_in_progress
)
27380 hlinfo
->mouse_face_deferred_gc
= 1;
27384 /* Which window is that in? */
27385 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27387 /* If displaying active text in another window, clear that. */
27388 if (! EQ (window
, hlinfo
->mouse_face_window
)
27389 /* Also clear if we move out of text area in same window. */
27390 || (!NILP (hlinfo
->mouse_face_window
)
27393 && part
!= ON_MODE_LINE
27394 && part
!= ON_HEADER_LINE
))
27395 clear_mouse_face (hlinfo
);
27397 /* Not on a window -> return. */
27398 if (!WINDOWP (window
))
27401 /* Reset help_echo_string. It will get recomputed below. */
27402 help_echo_string
= Qnil
;
27404 /* Convert to window-relative pixel coordinates. */
27405 w
= XWINDOW (window
);
27406 frame_to_window_pixel_xy (w
, &x
, &y
);
27408 #ifdef HAVE_WINDOW_SYSTEM
27409 /* Handle tool-bar window differently since it doesn't display a
27411 if (EQ (window
, f
->tool_bar_window
))
27413 note_tool_bar_highlight (f
, x
, y
);
27418 /* Mouse is on the mode, header line or margin? */
27419 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27420 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27422 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27426 #ifdef HAVE_WINDOW_SYSTEM
27427 if (part
== ON_VERTICAL_BORDER
)
27429 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27430 help_echo_string
= build_string ("drag-mouse-1: resize");
27432 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27433 || part
== ON_SCROLL_BAR
)
27434 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27436 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27439 /* Are we in a window whose display is up to date?
27440 And verify the buffer's text has not changed. */
27441 b
= XBUFFER (w
->buffer
);
27442 if (part
== ON_TEXT
27443 && EQ (w
->window_end_valid
, w
->buffer
)
27444 && w
->last_modified
== BUF_MODIFF (b
)
27445 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27447 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27449 struct glyph
*glyph
;
27450 Lisp_Object object
;
27451 Lisp_Object mouse_face
= Qnil
, position
;
27452 Lisp_Object
*overlay_vec
= NULL
;
27453 ptrdiff_t i
, noverlays
;
27454 struct buffer
*obuf
;
27455 ptrdiff_t obegv
, ozv
;
27458 /* Find the glyph under X/Y. */
27459 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27461 #ifdef HAVE_WINDOW_SYSTEM
27462 /* Look for :pointer property on image. */
27463 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27465 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27466 if (img
!= NULL
&& IMAGEP (img
->spec
))
27468 Lisp_Object image_map
, hotspot
;
27469 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27471 && (hotspot
= find_hot_spot (image_map
,
27472 glyph
->slice
.img
.x
+ dx
,
27473 glyph
->slice
.img
.y
+ dy
),
27475 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27479 /* Could check XCAR (hotspot) to see if we enter/leave
27481 If so, we could look for mouse-enter, mouse-leave
27482 properties in PLIST (and do something...). */
27483 hotspot
= XCDR (hotspot
);
27484 if (CONSP (hotspot
)
27485 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27487 pointer
= Fplist_get (plist
, Qpointer
);
27488 if (NILP (pointer
))
27490 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27491 if (!NILP (help_echo_string
))
27493 help_echo_window
= window
;
27494 help_echo_object
= glyph
->object
;
27495 help_echo_pos
= glyph
->charpos
;
27499 if (NILP (pointer
))
27500 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27503 #endif /* HAVE_WINDOW_SYSTEM */
27505 /* Clear mouse face if X/Y not over text. */
27507 || area
!= TEXT_AREA
27508 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27509 /* Glyph's OBJECT is an integer for glyphs inserted by the
27510 display engine for its internal purposes, like truncation
27511 and continuation glyphs and blanks beyond the end of
27512 line's text on text terminals. If we are over such a
27513 glyph, we are not over any text. */
27514 || INTEGERP (glyph
->object
)
27515 /* R2L rows have a stretch glyph at their front, which
27516 stands for no text, whereas L2R rows have no glyphs at
27517 all beyond the end of text. Treat such stretch glyphs
27518 like we do with NULL glyphs in L2R rows. */
27519 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27520 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27521 && glyph
->type
== STRETCH_GLYPH
27522 && glyph
->avoid_cursor_p
))
27524 if (clear_mouse_face (hlinfo
))
27525 cursor
= No_Cursor
;
27526 #ifdef HAVE_WINDOW_SYSTEM
27527 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27529 if (area
!= TEXT_AREA
)
27530 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27532 pointer
= Vvoid_text_area_pointer
;
27538 pos
= glyph
->charpos
;
27539 object
= glyph
->object
;
27540 if (!STRINGP (object
) && !BUFFERP (object
))
27543 /* If we get an out-of-range value, return now; avoid an error. */
27544 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27547 /* Make the window's buffer temporarily current for
27548 overlays_at and compute_char_face. */
27549 obuf
= current_buffer
;
27550 current_buffer
= b
;
27556 /* Is this char mouse-active or does it have help-echo? */
27557 position
= make_number (pos
);
27559 if (BUFFERP (object
))
27561 /* Put all the overlays we want in a vector in overlay_vec. */
27562 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27563 /* Sort overlays into increasing priority order. */
27564 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27569 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27572 cursor
= No_Cursor
;
27574 /* Check mouse-face highlighting. */
27576 /* If there exists an overlay with mouse-face overlapping
27577 the one we are currently highlighting, we have to
27578 check if we enter the overlapping overlay, and then
27579 highlight only that. */
27580 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27581 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27583 /* Find the highest priority overlay with a mouse-face. */
27584 Lisp_Object overlay
= Qnil
;
27585 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27587 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27588 if (!NILP (mouse_face
))
27589 overlay
= overlay_vec
[i
];
27592 /* If we're highlighting the same overlay as before, there's
27593 no need to do that again. */
27594 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27595 goto check_help_echo
;
27596 hlinfo
->mouse_face_overlay
= overlay
;
27598 /* Clear the display of the old active region, if any. */
27599 if (clear_mouse_face (hlinfo
))
27600 cursor
= No_Cursor
;
27602 /* If no overlay applies, get a text property. */
27603 if (NILP (overlay
))
27604 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27606 /* Next, compute the bounds of the mouse highlighting and
27608 if (!NILP (mouse_face
) && STRINGP (object
))
27610 /* The mouse-highlighting comes from a display string
27611 with a mouse-face. */
27615 s
= Fprevious_single_property_change
27616 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27617 e
= Fnext_single_property_change
27618 (position
, Qmouse_face
, object
, Qnil
);
27620 s
= make_number (0);
27622 e
= make_number (SCHARS (object
) - 1);
27623 mouse_face_from_string_pos (w
, hlinfo
, object
,
27624 XINT (s
), XINT (e
));
27625 hlinfo
->mouse_face_past_end
= 0;
27626 hlinfo
->mouse_face_window
= window
;
27627 hlinfo
->mouse_face_face_id
27628 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27629 glyph
->face_id
, 1);
27630 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27631 cursor
= No_Cursor
;
27635 /* The mouse-highlighting, if any, comes from an overlay
27636 or text property in the buffer. */
27637 Lisp_Object buffer
IF_LINT (= Qnil
);
27638 Lisp_Object disp_string
IF_LINT (= Qnil
);
27640 if (STRINGP (object
))
27642 /* If we are on a display string with no mouse-face,
27643 check if the text under it has one. */
27644 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27645 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27646 pos
= string_buffer_position (object
, start
);
27649 mouse_face
= get_char_property_and_overlay
27650 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27651 buffer
= w
->buffer
;
27652 disp_string
= object
;
27658 disp_string
= Qnil
;
27661 if (!NILP (mouse_face
))
27663 Lisp_Object before
, after
;
27664 Lisp_Object before_string
, after_string
;
27665 /* To correctly find the limits of mouse highlight
27666 in a bidi-reordered buffer, we must not use the
27667 optimization of limiting the search in
27668 previous-single-property-change and
27669 next-single-property-change, because
27670 rows_from_pos_range needs the real start and end
27671 positions to DTRT in this case. That's because
27672 the first row visible in a window does not
27673 necessarily display the character whose position
27674 is the smallest. */
27676 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27677 ? Fmarker_position (w
->start
)
27680 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27681 ? make_number (BUF_Z (XBUFFER (buffer
))
27682 - XFASTINT (w
->window_end_pos
))
27685 if (NILP (overlay
))
27687 /* Handle the text property case. */
27688 before
= Fprevious_single_property_change
27689 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27690 after
= Fnext_single_property_change
27691 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27692 before_string
= after_string
= Qnil
;
27696 /* Handle the overlay case. */
27697 before
= Foverlay_start (overlay
);
27698 after
= Foverlay_end (overlay
);
27699 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27700 after_string
= Foverlay_get (overlay
, Qafter_string
);
27702 if (!STRINGP (before_string
)) before_string
= Qnil
;
27703 if (!STRINGP (after_string
)) after_string
= Qnil
;
27706 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27709 : XFASTINT (before
),
27711 ? BUF_Z (XBUFFER (buffer
))
27712 : XFASTINT (after
),
27713 before_string
, after_string
,
27715 cursor
= No_Cursor
;
27722 /* Look for a `help-echo' property. */
27723 if (NILP (help_echo_string
)) {
27724 Lisp_Object help
, overlay
;
27726 /* Check overlays first. */
27727 help
= overlay
= Qnil
;
27728 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27730 overlay
= overlay_vec
[i
];
27731 help
= Foverlay_get (overlay
, Qhelp_echo
);
27736 help_echo_string
= help
;
27737 help_echo_window
= window
;
27738 help_echo_object
= overlay
;
27739 help_echo_pos
= pos
;
27743 Lisp_Object obj
= glyph
->object
;
27744 ptrdiff_t charpos
= glyph
->charpos
;
27746 /* Try text properties. */
27749 && charpos
< SCHARS (obj
))
27751 help
= Fget_text_property (make_number (charpos
),
27755 /* If the string itself doesn't specify a help-echo,
27756 see if the buffer text ``under'' it does. */
27757 struct glyph_row
*r
27758 = MATRIX_ROW (w
->current_matrix
, vpos
);
27759 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27760 ptrdiff_t p
= string_buffer_position (obj
, start
);
27763 help
= Fget_char_property (make_number (p
),
27764 Qhelp_echo
, w
->buffer
);
27773 else if (BUFFERP (obj
)
27776 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27781 help_echo_string
= help
;
27782 help_echo_window
= window
;
27783 help_echo_object
= obj
;
27784 help_echo_pos
= charpos
;
27789 #ifdef HAVE_WINDOW_SYSTEM
27790 /* Look for a `pointer' property. */
27791 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27793 /* Check overlays first. */
27794 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27795 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27797 if (NILP (pointer
))
27799 Lisp_Object obj
= glyph
->object
;
27800 ptrdiff_t charpos
= glyph
->charpos
;
27802 /* Try text properties. */
27805 && charpos
< SCHARS (obj
))
27807 pointer
= Fget_text_property (make_number (charpos
),
27809 if (NILP (pointer
))
27811 /* If the string itself doesn't specify a pointer,
27812 see if the buffer text ``under'' it does. */
27813 struct glyph_row
*r
27814 = MATRIX_ROW (w
->current_matrix
, vpos
);
27815 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27816 ptrdiff_t p
= string_buffer_position (obj
, start
);
27818 pointer
= Fget_char_property (make_number (p
),
27819 Qpointer
, w
->buffer
);
27822 else if (BUFFERP (obj
)
27825 pointer
= Fget_text_property (make_number (charpos
),
27829 #endif /* HAVE_WINDOW_SYSTEM */
27833 current_buffer
= obuf
;
27838 #ifdef HAVE_WINDOW_SYSTEM
27839 if (FRAME_WINDOW_P (f
))
27840 define_frame_cursor1 (f
, cursor
, pointer
);
27842 /* This is here to prevent a compiler error, about "label at end of
27843 compound statement". */
27850 Clear any mouse-face on window W. This function is part of the
27851 redisplay interface, and is called from try_window_id and similar
27852 functions to ensure the mouse-highlight is off. */
27855 x_clear_window_mouse_face (struct window
*w
)
27857 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27858 Lisp_Object window
;
27861 XSETWINDOW (window
, w
);
27862 if (EQ (window
, hlinfo
->mouse_face_window
))
27863 clear_mouse_face (hlinfo
);
27869 Just discard the mouse face information for frame F, if any.
27870 This is used when the size of F is changed. */
27873 cancel_mouse_face (struct frame
*f
)
27875 Lisp_Object window
;
27876 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27878 window
= hlinfo
->mouse_face_window
;
27879 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27881 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27882 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27883 hlinfo
->mouse_face_window
= Qnil
;
27889 /***********************************************************************
27891 ***********************************************************************/
27893 #ifdef HAVE_WINDOW_SYSTEM
27895 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27896 which intersects rectangle R. R is in window-relative coordinates. */
27899 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27900 enum glyph_row_area area
)
27902 struct glyph
*first
= row
->glyphs
[area
];
27903 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27904 struct glyph
*last
;
27905 int first_x
, start_x
, x
;
27907 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27908 /* If row extends face to end of line write the whole line. */
27909 draw_glyphs (w
, 0, row
, area
,
27910 0, row
->used
[area
],
27911 DRAW_NORMAL_TEXT
, 0);
27914 /* Set START_X to the window-relative start position for drawing glyphs of
27915 AREA. The first glyph of the text area can be partially visible.
27916 The first glyphs of other areas cannot. */
27917 start_x
= window_box_left_offset (w
, area
);
27919 if (area
== TEXT_AREA
)
27922 /* Find the first glyph that must be redrawn. */
27924 && x
+ first
->pixel_width
< r
->x
)
27926 x
+= first
->pixel_width
;
27930 /* Find the last one. */
27934 && x
< r
->x
+ r
->width
)
27936 x
+= last
->pixel_width
;
27942 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27943 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27944 DRAW_NORMAL_TEXT
, 0);
27949 /* Redraw the parts of the glyph row ROW on window W intersecting
27950 rectangle R. R is in window-relative coordinates. Value is
27951 non-zero if mouse-face was overwritten. */
27954 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27956 eassert (row
->enabled_p
);
27958 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27959 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27960 0, row
->used
[TEXT_AREA
],
27961 DRAW_NORMAL_TEXT
, 0);
27964 if (row
->used
[LEFT_MARGIN_AREA
])
27965 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27966 if (row
->used
[TEXT_AREA
])
27967 expose_area (w
, row
, r
, TEXT_AREA
);
27968 if (row
->used
[RIGHT_MARGIN_AREA
])
27969 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27970 draw_row_fringe_bitmaps (w
, row
);
27973 return row
->mouse_face_p
;
27977 /* Redraw those parts of glyphs rows during expose event handling that
27978 overlap other rows. Redrawing of an exposed line writes over parts
27979 of lines overlapping that exposed line; this function fixes that.
27981 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27982 row in W's current matrix that is exposed and overlaps other rows.
27983 LAST_OVERLAPPING_ROW is the last such row. */
27986 expose_overlaps (struct window
*w
,
27987 struct glyph_row
*first_overlapping_row
,
27988 struct glyph_row
*last_overlapping_row
,
27991 struct glyph_row
*row
;
27993 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27994 if (row
->overlapping_p
)
27996 eassert (row
->enabled_p
&& !row
->mode_line_p
);
27999 if (row
->used
[LEFT_MARGIN_AREA
])
28000 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28002 if (row
->used
[TEXT_AREA
])
28003 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28005 if (row
->used
[RIGHT_MARGIN_AREA
])
28006 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28012 /* Return non-zero if W's cursor intersects rectangle R. */
28015 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28017 XRectangle cr
, result
;
28018 struct glyph
*cursor_glyph
;
28019 struct glyph_row
*row
;
28021 if (w
->phys_cursor
.vpos
>= 0
28022 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28023 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28025 && row
->cursor_in_fringe_p
)
28027 /* Cursor is in the fringe. */
28028 cr
.x
= window_box_right_offset (w
,
28029 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28030 ? RIGHT_MARGIN_AREA
28033 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28034 cr
.height
= row
->height
;
28035 return x_intersect_rectangles (&cr
, r
, &result
);
28038 cursor_glyph
= get_phys_cursor_glyph (w
);
28041 /* r is relative to W's box, but w->phys_cursor.x is relative
28042 to left edge of W's TEXT area. Adjust it. */
28043 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28044 cr
.y
= w
->phys_cursor
.y
;
28045 cr
.width
= cursor_glyph
->pixel_width
;
28046 cr
.height
= w
->phys_cursor_height
;
28047 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28048 I assume the effect is the same -- and this is portable. */
28049 return x_intersect_rectangles (&cr
, r
, &result
);
28051 /* If we don't understand the format, pretend we're not in the hot-spot. */
28057 Draw a vertical window border to the right of window W if W doesn't
28058 have vertical scroll bars. */
28061 x_draw_vertical_border (struct window
*w
)
28063 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28065 /* We could do better, if we knew what type of scroll-bar the adjacent
28066 windows (on either side) have... But we don't :-(
28067 However, I think this works ok. ++KFS 2003-04-25 */
28069 /* Redraw borders between horizontally adjacent windows. Don't
28070 do it for frames with vertical scroll bars because either the
28071 right scroll bar of a window, or the left scroll bar of its
28072 neighbor will suffice as a border. */
28073 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28076 if (!WINDOW_RIGHTMOST_P (w
)
28077 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28079 int x0
, x1
, y0
, y1
;
28081 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28084 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28087 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28089 else if (!WINDOW_LEFTMOST_P (w
)
28090 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28092 int x0
, x1
, y0
, y1
;
28094 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28097 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28100 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28105 /* Redraw the part of window W intersection rectangle FR. Pixel
28106 coordinates in FR are frame-relative. Call this function with
28107 input blocked. Value is non-zero if the exposure overwrites
28111 expose_window (struct window
*w
, XRectangle
*fr
)
28113 struct frame
*f
= XFRAME (w
->frame
);
28115 int mouse_face_overwritten_p
= 0;
28117 /* If window is not yet fully initialized, do nothing. This can
28118 happen when toolkit scroll bars are used and a window is split.
28119 Reconfiguring the scroll bar will generate an expose for a newly
28121 if (w
->current_matrix
== NULL
)
28124 /* When we're currently updating the window, display and current
28125 matrix usually don't agree. Arrange for a thorough display
28127 if (w
== updated_window
)
28129 SET_FRAME_GARBAGED (f
);
28133 /* Frame-relative pixel rectangle of W. */
28134 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28135 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28136 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28137 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28139 if (x_intersect_rectangles (fr
, &wr
, &r
))
28141 int yb
= window_text_bottom_y (w
);
28142 struct glyph_row
*row
;
28143 int cursor_cleared_p
, phys_cursor_on_p
;
28144 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28146 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28147 r
.x
, r
.y
, r
.width
, r
.height
));
28149 /* Convert to window coordinates. */
28150 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28151 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28153 /* Turn off the cursor. */
28154 if (!w
->pseudo_window_p
28155 && phys_cursor_in_rect_p (w
, &r
))
28157 x_clear_cursor (w
);
28158 cursor_cleared_p
= 1;
28161 cursor_cleared_p
= 0;
28163 /* If the row containing the cursor extends face to end of line,
28164 then expose_area might overwrite the cursor outside the
28165 rectangle and thus notice_overwritten_cursor might clear
28166 w->phys_cursor_on_p. We remember the original value and
28167 check later if it is changed. */
28168 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28170 /* Update lines intersecting rectangle R. */
28171 first_overlapping_row
= last_overlapping_row
= NULL
;
28172 for (row
= w
->current_matrix
->rows
;
28177 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28179 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28180 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28181 || (r
.y
>= y0
&& r
.y
< y1
)
28182 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28184 /* A header line may be overlapping, but there is no need
28185 to fix overlapping areas for them. KFS 2005-02-12 */
28186 if (row
->overlapping_p
&& !row
->mode_line_p
)
28188 if (first_overlapping_row
== NULL
)
28189 first_overlapping_row
= row
;
28190 last_overlapping_row
= row
;
28194 if (expose_line (w
, row
, &r
))
28195 mouse_face_overwritten_p
= 1;
28198 else if (row
->overlapping_p
)
28200 /* We must redraw a row overlapping the exposed area. */
28202 ? y0
+ row
->phys_height
> r
.y
28203 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28205 if (first_overlapping_row
== NULL
)
28206 first_overlapping_row
= row
;
28207 last_overlapping_row
= row
;
28215 /* Display the mode line if there is one. */
28216 if (WINDOW_WANTS_MODELINE_P (w
)
28217 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28219 && row
->y
< r
.y
+ r
.height
)
28221 if (expose_line (w
, row
, &r
))
28222 mouse_face_overwritten_p
= 1;
28225 if (!w
->pseudo_window_p
)
28227 /* Fix the display of overlapping rows. */
28228 if (first_overlapping_row
)
28229 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28232 /* Draw border between windows. */
28233 x_draw_vertical_border (w
);
28235 /* Turn the cursor on again. */
28236 if (cursor_cleared_p
28237 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28238 update_window_cursor (w
, 1);
28242 return mouse_face_overwritten_p
;
28247 /* Redraw (parts) of all windows in the window tree rooted at W that
28248 intersect R. R contains frame pixel coordinates. Value is
28249 non-zero if the exposure overwrites mouse-face. */
28252 expose_window_tree (struct window
*w
, XRectangle
*r
)
28254 struct frame
*f
= XFRAME (w
->frame
);
28255 int mouse_face_overwritten_p
= 0;
28257 while (w
&& !FRAME_GARBAGED_P (f
))
28259 if (!NILP (w
->hchild
))
28260 mouse_face_overwritten_p
28261 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28262 else if (!NILP (w
->vchild
))
28263 mouse_face_overwritten_p
28264 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28266 mouse_face_overwritten_p
|= expose_window (w
, r
);
28268 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28271 return mouse_face_overwritten_p
;
28276 Redisplay an exposed area of frame F. X and Y are the upper-left
28277 corner of the exposed rectangle. W and H are width and height of
28278 the exposed area. All are pixel values. W or H zero means redraw
28279 the entire frame. */
28282 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28285 int mouse_face_overwritten_p
= 0;
28287 TRACE ((stderr
, "expose_frame "));
28289 /* No need to redraw if frame will be redrawn soon. */
28290 if (FRAME_GARBAGED_P (f
))
28292 TRACE ((stderr
, " garbaged\n"));
28296 /* If basic faces haven't been realized yet, there is no point in
28297 trying to redraw anything. This can happen when we get an expose
28298 event while Emacs is starting, e.g. by moving another window. */
28299 if (FRAME_FACE_CACHE (f
) == NULL
28300 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28302 TRACE ((stderr
, " no faces\n"));
28306 if (w
== 0 || h
== 0)
28309 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28310 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28320 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28321 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28323 if (WINDOWP (f
->tool_bar_window
))
28324 mouse_face_overwritten_p
28325 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28327 #ifdef HAVE_X_WINDOWS
28329 #ifndef USE_X_TOOLKIT
28330 if (WINDOWP (f
->menu_bar_window
))
28331 mouse_face_overwritten_p
28332 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28333 #endif /* not USE_X_TOOLKIT */
28337 /* Some window managers support a focus-follows-mouse style with
28338 delayed raising of frames. Imagine a partially obscured frame,
28339 and moving the mouse into partially obscured mouse-face on that
28340 frame. The visible part of the mouse-face will be highlighted,
28341 then the WM raises the obscured frame. With at least one WM, KDE
28342 2.1, Emacs is not getting any event for the raising of the frame
28343 (even tried with SubstructureRedirectMask), only Expose events.
28344 These expose events will draw text normally, i.e. not
28345 highlighted. Which means we must redo the highlight here.
28346 Subsume it under ``we love X''. --gerd 2001-08-15 */
28347 /* Included in Windows version because Windows most likely does not
28348 do the right thing if any third party tool offers
28349 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28350 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28352 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28353 if (f
== hlinfo
->mouse_face_mouse_frame
)
28355 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28356 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28357 clear_mouse_face (hlinfo
);
28358 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28365 Determine the intersection of two rectangles R1 and R2. Return
28366 the intersection in *RESULT. Value is non-zero if RESULT is not
28370 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28372 XRectangle
*left
, *right
;
28373 XRectangle
*upper
, *lower
;
28374 int intersection_p
= 0;
28376 /* Rearrange so that R1 is the left-most rectangle. */
28378 left
= r1
, right
= r2
;
28380 left
= r2
, right
= r1
;
28382 /* X0 of the intersection is right.x0, if this is inside R1,
28383 otherwise there is no intersection. */
28384 if (right
->x
<= left
->x
+ left
->width
)
28386 result
->x
= right
->x
;
28388 /* The right end of the intersection is the minimum of
28389 the right ends of left and right. */
28390 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28393 /* Same game for Y. */
28395 upper
= r1
, lower
= r2
;
28397 upper
= r2
, lower
= r1
;
28399 /* The upper end of the intersection is lower.y0, if this is inside
28400 of upper. Otherwise, there is no intersection. */
28401 if (lower
->y
<= upper
->y
+ upper
->height
)
28403 result
->y
= lower
->y
;
28405 /* The lower end of the intersection is the minimum of the lower
28406 ends of upper and lower. */
28407 result
->height
= (min (lower
->y
+ lower
->height
,
28408 upper
->y
+ upper
->height
)
28410 intersection_p
= 1;
28414 return intersection_p
;
28417 #endif /* HAVE_WINDOW_SYSTEM */
28420 /***********************************************************************
28422 ***********************************************************************/
28425 syms_of_xdisp (void)
28427 Vwith_echo_area_save_vector
= Qnil
;
28428 staticpro (&Vwith_echo_area_save_vector
);
28430 Vmessage_stack
= Qnil
;
28431 staticpro (&Vmessage_stack
);
28433 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28435 message_dolog_marker1
= Fmake_marker ();
28436 staticpro (&message_dolog_marker1
);
28437 message_dolog_marker2
= Fmake_marker ();
28438 staticpro (&message_dolog_marker2
);
28439 message_dolog_marker3
= Fmake_marker ();
28440 staticpro (&message_dolog_marker3
);
28443 defsubr (&Sdump_frame_glyph_matrix
);
28444 defsubr (&Sdump_glyph_matrix
);
28445 defsubr (&Sdump_glyph_row
);
28446 defsubr (&Sdump_tool_bar_row
);
28447 defsubr (&Strace_redisplay
);
28448 defsubr (&Strace_to_stderr
);
28450 #ifdef HAVE_WINDOW_SYSTEM
28451 defsubr (&Stool_bar_lines_needed
);
28452 defsubr (&Slookup_image_map
);
28454 defsubr (&Sformat_mode_line
);
28455 defsubr (&Sinvisible_p
);
28456 defsubr (&Scurrent_bidi_paragraph_direction
);
28458 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28459 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28460 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28461 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28462 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28463 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28464 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28465 DEFSYM (Qeval
, "eval");
28466 DEFSYM (QCdata
, ":data");
28467 DEFSYM (Qdisplay
, "display");
28468 DEFSYM (Qspace_width
, "space-width");
28469 DEFSYM (Qraise
, "raise");
28470 DEFSYM (Qslice
, "slice");
28471 DEFSYM (Qspace
, "space");
28472 DEFSYM (Qmargin
, "margin");
28473 DEFSYM (Qpointer
, "pointer");
28474 DEFSYM (Qleft_margin
, "left-margin");
28475 DEFSYM (Qright_margin
, "right-margin");
28476 DEFSYM (Qcenter
, "center");
28477 DEFSYM (Qline_height
, "line-height");
28478 DEFSYM (QCalign_to
, ":align-to");
28479 DEFSYM (QCrelative_width
, ":relative-width");
28480 DEFSYM (QCrelative_height
, ":relative-height");
28481 DEFSYM (QCeval
, ":eval");
28482 DEFSYM (QCpropertize
, ":propertize");
28483 DEFSYM (QCfile
, ":file");
28484 DEFSYM (Qfontified
, "fontified");
28485 DEFSYM (Qfontification_functions
, "fontification-functions");
28486 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28487 DEFSYM (Qescape_glyph
, "escape-glyph");
28488 DEFSYM (Qnobreak_space
, "nobreak-space");
28489 DEFSYM (Qimage
, "image");
28490 DEFSYM (Qtext
, "text");
28491 DEFSYM (Qboth
, "both");
28492 DEFSYM (Qboth_horiz
, "both-horiz");
28493 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28494 DEFSYM (QCmap
, ":map");
28495 DEFSYM (QCpointer
, ":pointer");
28496 DEFSYM (Qrect
, "rect");
28497 DEFSYM (Qcircle
, "circle");
28498 DEFSYM (Qpoly
, "poly");
28499 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28500 DEFSYM (Qgrow_only
, "grow-only");
28501 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28502 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28503 DEFSYM (Qposition
, "position");
28504 DEFSYM (Qbuffer_position
, "buffer-position");
28505 DEFSYM (Qobject
, "object");
28506 DEFSYM (Qbar
, "bar");
28507 DEFSYM (Qhbar
, "hbar");
28508 DEFSYM (Qbox
, "box");
28509 DEFSYM (Qhollow
, "hollow");
28510 DEFSYM (Qhand
, "hand");
28511 DEFSYM (Qarrow
, "arrow");
28512 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28514 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28515 Fcons (intern_c_string ("void-variable"), Qnil
)),
28517 staticpro (&list_of_error
);
28519 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28520 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28521 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28522 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28524 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28525 staticpro (&echo_buffer
[0]);
28526 staticpro (&echo_buffer
[1]);
28528 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28529 staticpro (&echo_area_buffer
[0]);
28530 staticpro (&echo_area_buffer
[1]);
28532 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28533 staticpro (&Vmessages_buffer_name
);
28535 mode_line_proptrans_alist
= Qnil
;
28536 staticpro (&mode_line_proptrans_alist
);
28537 mode_line_string_list
= Qnil
;
28538 staticpro (&mode_line_string_list
);
28539 mode_line_string_face
= Qnil
;
28540 staticpro (&mode_line_string_face
);
28541 mode_line_string_face_prop
= Qnil
;
28542 staticpro (&mode_line_string_face_prop
);
28543 Vmode_line_unwind_vector
= Qnil
;
28544 staticpro (&Vmode_line_unwind_vector
);
28546 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28548 help_echo_string
= Qnil
;
28549 staticpro (&help_echo_string
);
28550 help_echo_object
= Qnil
;
28551 staticpro (&help_echo_object
);
28552 help_echo_window
= Qnil
;
28553 staticpro (&help_echo_window
);
28554 previous_help_echo_string
= Qnil
;
28555 staticpro (&previous_help_echo_string
);
28556 help_echo_pos
= -1;
28558 DEFSYM (Qright_to_left
, "right-to-left");
28559 DEFSYM (Qleft_to_right
, "left-to-right");
28561 #ifdef HAVE_WINDOW_SYSTEM
28562 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28563 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28564 For example, if a block cursor is over a tab, it will be drawn as
28565 wide as that tab on the display. */);
28566 x_stretch_cursor_p
= 0;
28569 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28570 doc
: /* Non-nil means highlight trailing whitespace.
28571 The face used for trailing whitespace is `trailing-whitespace'. */);
28572 Vshow_trailing_whitespace
= Qnil
;
28574 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28575 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28576 If the value is t, Emacs highlights non-ASCII chars which have the
28577 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28578 or `escape-glyph' face respectively.
28580 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28581 U+2011 (non-breaking hyphen) are affected.
28583 Any other non-nil value means to display these characters as a escape
28584 glyph followed by an ordinary space or hyphen.
28586 A value of nil means no special handling of these characters. */);
28587 Vnobreak_char_display
= Qt
;
28589 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28590 doc
: /* The pointer shape to show in void text areas.
28591 A value of nil means to show the text pointer. Other options are `arrow',
28592 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28593 Vvoid_text_area_pointer
= Qarrow
;
28595 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28596 doc
: /* Non-nil means don't actually do any redisplay.
28597 This is used for internal purposes. */);
28598 Vinhibit_redisplay
= Qnil
;
28600 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28601 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28602 Vglobal_mode_string
= Qnil
;
28604 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28605 doc
: /* Marker for where to display an arrow on top of the buffer text.
28606 This must be the beginning of a line in order to work.
28607 See also `overlay-arrow-string'. */);
28608 Voverlay_arrow_position
= Qnil
;
28610 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28611 doc
: /* String to display as an arrow in non-window frames.
28612 See also `overlay-arrow-position'. */);
28613 Voverlay_arrow_string
= make_pure_c_string ("=>");
28615 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28616 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28617 The symbols on this list are examined during redisplay to determine
28618 where to display overlay arrows. */);
28619 Voverlay_arrow_variable_list
28620 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28622 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28623 doc
: /* The number of lines to try scrolling a window by when point moves out.
28624 If that fails to bring point back on frame, point is centered instead.
28625 If this is zero, point is always centered after it moves off frame.
28626 If you want scrolling to always be a line at a time, you should set
28627 `scroll-conservatively' to a large value rather than set this to 1. */);
28629 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28630 doc
: /* Scroll up to this many lines, to bring point back on screen.
28631 If point moves off-screen, redisplay will scroll by up to
28632 `scroll-conservatively' lines in order to bring point just barely
28633 onto the screen again. If that cannot be done, then redisplay
28634 recenters point as usual.
28636 If the value is greater than 100, redisplay will never recenter point,
28637 but will always scroll just enough text to bring point into view, even
28638 if you move far away.
28640 A value of zero means always recenter point if it moves off screen. */);
28641 scroll_conservatively
= 0;
28643 DEFVAR_INT ("scroll-margin", scroll_margin
,
28644 doc
: /* Number of lines of margin at the top and bottom of a window.
28645 Recenter the window whenever point gets within this many lines
28646 of the top or bottom of the window. */);
28649 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28650 doc
: /* Pixels per inch value for non-window system displays.
28651 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28652 Vdisplay_pixels_per_inch
= make_float (72.0);
28655 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28658 DEFVAR_LISP ("truncate-partial-width-windows",
28659 Vtruncate_partial_width_windows
,
28660 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28661 For an integer value, truncate lines in each window narrower than the
28662 full frame width, provided the window width is less than that integer;
28663 otherwise, respect the value of `truncate-lines'.
28665 For any other non-nil value, truncate lines in all windows that do
28666 not span the full frame width.
28668 A value of nil means to respect the value of `truncate-lines'.
28670 If `word-wrap' is enabled, you might want to reduce this. */);
28671 Vtruncate_partial_width_windows
= make_number (50);
28673 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28674 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28675 Any other value means to use the appropriate face, `mode-line',
28676 `header-line', or `menu' respectively. */);
28677 mode_line_inverse_video
= 1;
28679 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28680 doc
: /* Maximum buffer size for which line number should be displayed.
28681 If the buffer is bigger than this, the line number does not appear
28682 in the mode line. A value of nil means no limit. */);
28683 Vline_number_display_limit
= Qnil
;
28685 DEFVAR_INT ("line-number-display-limit-width",
28686 line_number_display_limit_width
,
28687 doc
: /* Maximum line width (in characters) for line number display.
28688 If the average length of the lines near point is bigger than this, then the
28689 line number may be omitted from the mode line. */);
28690 line_number_display_limit_width
= 200;
28692 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28693 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28694 highlight_nonselected_windows
= 0;
28696 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28697 doc
: /* Non-nil if more than one frame is visible on this display.
28698 Minibuffer-only frames don't count, but iconified frames do.
28699 This variable is not guaranteed to be accurate except while processing
28700 `frame-title-format' and `icon-title-format'. */);
28702 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28703 doc
: /* Template for displaying the title bar of visible frames.
28704 \(Assuming the window manager supports this feature.)
28706 This variable has the same structure as `mode-line-format', except that
28707 the %c and %l constructs are ignored. It is used only on frames for
28708 which no explicit name has been set \(see `modify-frame-parameters'). */);
28710 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28711 doc
: /* Template for displaying the title bar of an iconified frame.
28712 \(Assuming the window manager supports this feature.)
28713 This variable has the same structure as `mode-line-format' (which see),
28714 and is used only on frames for which no explicit name has been set
28715 \(see `modify-frame-parameters'). */);
28717 = Vframe_title_format
28718 = pure_cons (intern_c_string ("multiple-frames"),
28719 pure_cons (make_pure_c_string ("%b"),
28720 pure_cons (pure_cons (empty_unibyte_string
,
28721 pure_cons (intern_c_string ("invocation-name"),
28722 pure_cons (make_pure_c_string ("@"),
28723 pure_cons (intern_c_string ("system-name"),
28727 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28728 doc
: /* Maximum number of lines to keep in the message log buffer.
28729 If nil, disable message logging. If t, log messages but don't truncate
28730 the buffer when it becomes large. */);
28731 Vmessage_log_max
= make_number (100);
28733 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28734 doc
: /* Functions called before redisplay, if window sizes have changed.
28735 The value should be a list of functions that take one argument.
28736 Just before redisplay, for each frame, if any of its windows have changed
28737 size since the last redisplay, or have been split or deleted,
28738 all the functions in the list are called, with the frame as argument. */);
28739 Vwindow_size_change_functions
= Qnil
;
28741 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28742 doc
: /* List of functions to call before redisplaying a window with scrolling.
28743 Each function is called with two arguments, the window and its new
28744 display-start position. Note that these functions are also called by
28745 `set-window-buffer'. Also note that the value of `window-end' is not
28746 valid when these functions are called.
28748 Warning: Do not use this feature to alter the way the window
28749 is scrolled. It is not designed for that, and such use probably won't
28751 Vwindow_scroll_functions
= Qnil
;
28753 DEFVAR_LISP ("window-text-change-functions",
28754 Vwindow_text_change_functions
,
28755 doc
: /* Functions to call in redisplay when text in the window might change. */);
28756 Vwindow_text_change_functions
= Qnil
;
28758 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28759 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28760 Each function is called with two arguments, the window and the end trigger value.
28761 See `set-window-redisplay-end-trigger'. */);
28762 Vredisplay_end_trigger_functions
= Qnil
;
28764 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28765 doc
: /* Non-nil means autoselect window with mouse pointer.
28766 If nil, do not autoselect windows.
28767 A positive number means delay autoselection by that many seconds: a
28768 window is autoselected only after the mouse has remained in that
28769 window for the duration of the delay.
28770 A negative number has a similar effect, but causes windows to be
28771 autoselected only after the mouse has stopped moving. \(Because of
28772 the way Emacs compares mouse events, you will occasionally wait twice
28773 that time before the window gets selected.\)
28774 Any other value means to autoselect window instantaneously when the
28775 mouse pointer enters it.
28777 Autoselection selects the minibuffer only if it is active, and never
28778 unselects the minibuffer if it is active.
28780 When customizing this variable make sure that the actual value of
28781 `focus-follows-mouse' matches the behavior of your window manager. */);
28782 Vmouse_autoselect_window
= Qnil
;
28784 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28785 doc
: /* Non-nil means automatically resize tool-bars.
28786 This dynamically changes the tool-bar's height to the minimum height
28787 that is needed to make all tool-bar items visible.
28788 If value is `grow-only', the tool-bar's height is only increased
28789 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28790 Vauto_resize_tool_bars
= Qt
;
28792 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28793 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28794 auto_raise_tool_bar_buttons_p
= 1;
28796 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28797 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28798 make_cursor_line_fully_visible_p
= 1;
28800 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28801 doc
: /* Border below tool-bar in pixels.
28802 If an integer, use it as the height of the border.
28803 If it is one of `internal-border-width' or `border-width', use the
28804 value of the corresponding frame parameter.
28805 Otherwise, no border is added below the tool-bar. */);
28806 Vtool_bar_border
= Qinternal_border_width
;
28808 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28809 doc
: /* Margin around tool-bar buttons in pixels.
28810 If an integer, use that for both horizontal and vertical margins.
28811 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28812 HORZ specifying the horizontal margin, and VERT specifying the
28813 vertical margin. */);
28814 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28816 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28817 doc
: /* Relief thickness of tool-bar buttons. */);
28818 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28820 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28821 doc
: /* Tool bar style to use.
28823 image - show images only
28824 text - show text only
28825 both - show both, text below image
28826 both-horiz - show text to the right of the image
28827 text-image-horiz - show text to the left of the image
28828 any other - use system default or image if no system default.
28830 This variable only affects the GTK+ toolkit version of Emacs. */);
28831 Vtool_bar_style
= Qnil
;
28833 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28834 doc
: /* Maximum number of characters a label can have to be shown.
28835 The tool bar style must also show labels for this to have any effect, see
28836 `tool-bar-style'. */);
28837 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28839 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28840 doc
: /* List of functions to call to fontify regions of text.
28841 Each function is called with one argument POS. Functions must
28842 fontify a region starting at POS in the current buffer, and give
28843 fontified regions the property `fontified'. */);
28844 Vfontification_functions
= Qnil
;
28845 Fmake_variable_buffer_local (Qfontification_functions
);
28847 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28848 unibyte_display_via_language_environment
,
28849 doc
: /* Non-nil means display unibyte text according to language environment.
28850 Specifically, this means that raw bytes in the range 160-255 decimal
28851 are displayed by converting them to the equivalent multibyte characters
28852 according to the current language environment. As a result, they are
28853 displayed according to the current fontset.
28855 Note that this variable affects only how these bytes are displayed,
28856 but does not change the fact they are interpreted as raw bytes. */);
28857 unibyte_display_via_language_environment
= 0;
28859 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28860 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
28861 If a float, it specifies a fraction of the mini-window frame's height.
28862 If an integer, it specifies a number of lines. */);
28863 Vmax_mini_window_height
= make_float (0.25);
28865 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28866 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28867 A value of nil means don't automatically resize mini-windows.
28868 A value of t means resize them to fit the text displayed in them.
28869 A value of `grow-only', the default, means let mini-windows grow only;
28870 they return to their normal size when the minibuffer is closed, or the
28871 echo area becomes empty. */);
28872 Vresize_mini_windows
= Qgrow_only
;
28874 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28875 doc
: /* Alist specifying how to blink the cursor off.
28876 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28877 `cursor-type' frame-parameter or variable equals ON-STATE,
28878 comparing using `equal', Emacs uses OFF-STATE to specify
28879 how to blink it off. ON-STATE and OFF-STATE are values for
28880 the `cursor-type' frame parameter.
28882 If a frame's ON-STATE has no entry in this list,
28883 the frame's other specifications determine how to blink the cursor off. */);
28884 Vblink_cursor_alist
= Qnil
;
28886 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28887 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28888 If non-nil, windows are automatically scrolled horizontally to make
28889 point visible. */);
28890 automatic_hscrolling_p
= 1;
28891 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28893 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28894 doc
: /* How many columns away from the window edge point is allowed to get
28895 before automatic hscrolling will horizontally scroll the window. */);
28896 hscroll_margin
= 5;
28898 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28899 doc
: /* How many columns to scroll the window when point gets too close to the edge.
28900 When point is less than `hscroll-margin' columns from the window
28901 edge, automatic hscrolling will scroll the window by the amount of columns
28902 determined by this variable. If its value is a positive integer, scroll that
28903 many columns. If it's a positive floating-point number, it specifies the
28904 fraction of the window's width to scroll. If it's nil or zero, point will be
28905 centered horizontally after the scroll. Any other value, including negative
28906 numbers, are treated as if the value were zero.
28908 Automatic hscrolling always moves point outside the scroll margin, so if
28909 point was more than scroll step columns inside the margin, the window will
28910 scroll more than the value given by the scroll step.
28912 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28913 and `scroll-right' overrides this variable's effect. */);
28914 Vhscroll_step
= make_number (0);
28916 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28917 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28918 Bind this around calls to `message' to let it take effect. */);
28919 message_truncate_lines
= 0;
28921 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28922 doc
: /* Normal hook run to update the menu bar definitions.
28923 Redisplay runs this hook before it redisplays the menu bar.
28924 This is used to update submenus such as Buffers,
28925 whose contents depend on various data. */);
28926 Vmenu_bar_update_hook
= Qnil
;
28928 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28929 doc
: /* Frame for which we are updating a menu.
28930 The enable predicate for a menu binding should check this variable. */);
28931 Vmenu_updating_frame
= Qnil
;
28933 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28934 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28935 inhibit_menubar_update
= 0;
28937 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28938 doc
: /* Prefix prepended to all continuation lines at display time.
28939 The value may be a string, an image, or a stretch-glyph; it is
28940 interpreted in the same way as the value of a `display' text property.
28942 This variable is overridden by any `wrap-prefix' text or overlay
28945 To add a prefix to non-continuation lines, use `line-prefix'. */);
28946 Vwrap_prefix
= Qnil
;
28947 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28948 Fmake_variable_buffer_local (Qwrap_prefix
);
28950 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28951 doc
: /* Prefix prepended to all non-continuation lines at display time.
28952 The value may be a string, an image, or a stretch-glyph; it is
28953 interpreted in the same way as the value of a `display' text property.
28955 This variable is overridden by any `line-prefix' text or overlay
28958 To add a prefix to continuation lines, use `wrap-prefix'. */);
28959 Vline_prefix
= Qnil
;
28960 DEFSYM (Qline_prefix
, "line-prefix");
28961 Fmake_variable_buffer_local (Qline_prefix
);
28963 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28964 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28965 inhibit_eval_during_redisplay
= 0;
28967 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28968 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28969 inhibit_free_realized_faces
= 0;
28972 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28973 doc
: /* Inhibit try_window_id display optimization. */);
28974 inhibit_try_window_id
= 0;
28976 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28977 doc
: /* Inhibit try_window_reusing display optimization. */);
28978 inhibit_try_window_reusing
= 0;
28980 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28981 doc
: /* Inhibit try_cursor_movement display optimization. */);
28982 inhibit_try_cursor_movement
= 0;
28983 #endif /* GLYPH_DEBUG */
28985 DEFVAR_INT ("overline-margin", overline_margin
,
28986 doc
: /* Space between overline and text, in pixels.
28987 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28988 margin to the character height. */);
28989 overline_margin
= 2;
28991 DEFVAR_INT ("underline-minimum-offset",
28992 underline_minimum_offset
,
28993 doc
: /* Minimum distance between baseline and underline.
28994 This can improve legibility of underlined text at small font sizes,
28995 particularly when using variable `x-use-underline-position-properties'
28996 with fonts that specify an UNDERLINE_POSITION relatively close to the
28997 baseline. The default value is 1. */);
28998 underline_minimum_offset
= 1;
29000 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29001 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29002 This feature only works when on a window system that can change
29003 cursor shapes. */);
29004 display_hourglass_p
= 1;
29006 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29007 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29008 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29010 hourglass_atimer
= NULL
;
29011 hourglass_shown_p
= 0;
29013 DEFSYM (Qglyphless_char
, "glyphless-char");
29014 DEFSYM (Qhex_code
, "hex-code");
29015 DEFSYM (Qempty_box
, "empty-box");
29016 DEFSYM (Qthin_space
, "thin-space");
29017 DEFSYM (Qzero_width
, "zero-width");
29019 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29020 /* Intern this now in case it isn't already done.
29021 Setting this variable twice is harmless.
29022 But don't staticpro it here--that is done in alloc.c. */
29023 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29024 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29026 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29027 doc
: /* Char-table defining glyphless characters.
29028 Each element, if non-nil, should be one of the following:
29029 an ASCII acronym string: display this string in a box
29030 `hex-code': display the hexadecimal code of a character in a box
29031 `empty-box': display as an empty box
29032 `thin-space': display as 1-pixel width space
29033 `zero-width': don't display
29034 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29035 display method for graphical terminals and text terminals respectively.
29036 GRAPHICAL and TEXT should each have one of the values listed above.
29038 The char-table has one extra slot to control the display of a character for
29039 which no font is found. This slot only takes effect on graphical terminals.
29040 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29041 `thin-space'. The default is `empty-box'. */);
29042 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29043 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29048 /* Initialize this module when Emacs starts. */
29053 current_header_line_height
= current_mode_line_height
= -1;
29055 CHARPOS (this_line_start_pos
) = 0;
29057 if (!noninteractive
)
29059 struct window
*m
= XWINDOW (minibuf_window
);
29060 Lisp_Object frame
= m
->frame
;
29061 struct frame
*f
= XFRAME (frame
);
29062 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29063 struct window
*r
= XWINDOW (root
);
29066 echo_area_window
= minibuf_window
;
29068 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
29069 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
29070 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
29071 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
29072 XSETFASTINT (m
->total_lines
, 1);
29073 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
29075 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29076 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29077 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29079 /* The default ellipsis glyphs `...'. */
29080 for (i
= 0; i
< 3; ++i
)
29081 default_invis_vector
[i
] = make_number ('.');
29085 /* Allocate the buffer for frame titles.
29086 Also used for `format-mode-line'. */
29088 mode_line_noprop_buf
= xmalloc (size
);
29089 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29090 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29091 mode_line_target
= MODE_LINE_DISPLAY
;
29094 help_echo_showing_p
= 0;
29097 /* Since w32 does not support atimers, it defines its own implementation of
29098 the following three functions in w32fns.c. */
29101 /* Platform-independent portion of hourglass implementation. */
29103 /* Cancel a currently active hourglass timer, and start a new one. */
29105 start_hourglass (void)
29107 #if defined (HAVE_WINDOW_SYSTEM)
29110 cancel_hourglass ();
29112 if (INTEGERP (Vhourglass_delay
)
29113 && XINT (Vhourglass_delay
) > 0)
29114 EMACS_SET_SECS_NSECS (delay
,
29115 min (XINT (Vhourglass_delay
), TYPE_MAXIMUM (time_t)),
29117 else if (FLOATP (Vhourglass_delay
)
29118 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29119 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29121 EMACS_SET_SECS_NSECS (delay
, DEFAULT_HOURGLASS_DELAY
, 0);
29123 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29124 show_hourglass
, NULL
);
29129 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29132 cancel_hourglass (void)
29134 #if defined (HAVE_WINDOW_SYSTEM)
29135 if (hourglass_atimer
)
29137 cancel_atimer (hourglass_atimer
);
29138 hourglass_atimer
= NULL
;
29141 if (hourglass_shown_p
)
29145 #endif /* ! WINDOWSNT */