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
5404 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5408 charpos
= IT_CHARPOS (*it
);
5410 /* Append the overlay string STRING of overlay OVERLAY to vector
5411 `entries' which has size `size' and currently contains `n'
5412 elements. AFTER_P non-zero means STRING is an after-string of
5414 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5417 Lisp_Object priority; \
5421 struct overlay_entry *old = entries; \
5422 SAFE_NALLOCA (entries, 2, size); \
5423 memcpy (entries, old, size * sizeof *entries); \
5427 entries[n].string = (STRING); \
5428 entries[n].overlay = (OVERLAY); \
5429 priority = Foverlay_get ((OVERLAY), Qpriority); \
5430 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5431 entries[n].after_string_p = (AFTER_P); \
5436 /* Process overlay before the overlay center. */
5437 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5439 XSETMISC (overlay
, ov
);
5440 eassert (OVERLAYP (overlay
));
5441 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5442 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5447 /* Skip this overlay if it doesn't start or end at IT's current
5449 if (end
!= charpos
&& start
!= charpos
)
5452 /* Skip this overlay if it doesn't apply to IT->w. */
5453 window
= Foverlay_get (overlay
, Qwindow
);
5454 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5457 /* If the text ``under'' the overlay is invisible, both before-
5458 and after-strings from this overlay are visible; start and
5459 end position are indistinguishable. */
5460 invisible
= Foverlay_get (overlay
, Qinvisible
);
5461 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5463 /* If overlay has a non-empty before-string, record it. */
5464 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5465 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5467 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5469 /* If overlay has a non-empty after-string, record it. */
5470 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5471 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5473 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5476 /* Process overlays after the overlay center. */
5477 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5479 XSETMISC (overlay
, ov
);
5480 eassert (OVERLAYP (overlay
));
5481 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5482 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5484 if (start
> charpos
)
5487 /* Skip this overlay if it doesn't start or end at IT's current
5489 if (end
!= charpos
&& start
!= charpos
)
5492 /* Skip this overlay if it doesn't apply to IT->w. */
5493 window
= Foverlay_get (overlay
, Qwindow
);
5494 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5497 /* If the text ``under'' the overlay is invisible, it has a zero
5498 dimension, and both before- and after-strings apply. */
5499 invisible
= Foverlay_get (overlay
, Qinvisible
);
5500 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5502 /* If overlay has a non-empty before-string, record it. */
5503 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5504 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5506 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5508 /* If overlay has a non-empty after-string, record it. */
5509 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5510 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5512 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5515 #undef RECORD_OVERLAY_STRING
5519 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5521 /* Record number of overlay strings, and where we computed it. */
5522 it
->n_overlay_strings
= n
;
5523 it
->overlay_strings_charpos
= charpos
;
5525 /* IT->current.overlay_string_index is the number of overlay strings
5526 that have already been consumed by IT. Copy some of the
5527 remaining overlay strings to IT->overlay_strings. */
5529 j
= it
->current
.overlay_string_index
;
5530 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5532 it
->overlay_strings
[i
] = entries
[j
].string
;
5533 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5541 /* Get the first chunk of overlay strings at IT's current buffer
5542 position, or at CHARPOS if that is > 0. Value is non-zero if at
5543 least one overlay string was found. */
5546 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5548 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5549 process. This fills IT->overlay_strings with strings, and sets
5550 IT->n_overlay_strings to the total number of strings to process.
5551 IT->pos.overlay_string_index has to be set temporarily to zero
5552 because load_overlay_strings needs this; it must be set to -1
5553 when no overlay strings are found because a zero value would
5554 indicate a position in the first overlay string. */
5555 it
->current
.overlay_string_index
= 0;
5556 load_overlay_strings (it
, charpos
);
5558 /* If we found overlay strings, set up IT to deliver display
5559 elements from the first one. Otherwise set up IT to deliver
5560 from current_buffer. */
5561 if (it
->n_overlay_strings
)
5563 /* Make sure we know settings in current_buffer, so that we can
5564 restore meaningful values when we're done with the overlay
5567 compute_stop_pos (it
);
5568 eassert (it
->face_id
>= 0);
5570 /* Save IT's settings. They are restored after all overlay
5571 strings have been processed. */
5572 eassert (!compute_stop_p
|| it
->sp
== 0);
5574 /* When called from handle_stop, there might be an empty display
5575 string loaded. In that case, don't bother saving it. But
5576 don't use this optimization with the bidi iterator, since we
5577 need the corresponding pop_it call to resync the bidi
5578 iterator's position with IT's position, after we are done
5579 with the overlay strings. (The corresponding call to pop_it
5580 in case of an empty display string is in
5581 next_overlay_string.) */
5583 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5586 /* Set up IT to deliver display elements from the first overlay
5588 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5589 it
->string
= it
->overlay_strings
[0];
5590 it
->from_overlay
= Qnil
;
5591 it
->stop_charpos
= 0;
5592 eassert (STRINGP (it
->string
));
5593 it
->end_charpos
= SCHARS (it
->string
);
5595 it
->base_level_stop
= 0;
5596 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5597 it
->method
= GET_FROM_STRING
;
5598 it
->from_disp_prop_p
= 0;
5600 /* Force paragraph direction to be that of the parent
5602 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5603 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5605 it
->paragraph_embedding
= L2R
;
5607 /* Set up the bidi iterator for this overlay string. */
5610 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5612 it
->bidi_it
.string
.lstring
= it
->string
;
5613 it
->bidi_it
.string
.s
= NULL
;
5614 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5615 it
->bidi_it
.string
.bufpos
= pos
;
5616 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5617 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5618 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5623 it
->current
.overlay_string_index
= -1;
5628 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5631 it
->method
= GET_FROM_BUFFER
;
5633 (void) get_overlay_strings_1 (it
, charpos
, 1);
5637 /* Value is non-zero if we found at least one overlay string. */
5638 return STRINGP (it
->string
);
5643 /***********************************************************************
5644 Saving and restoring state
5645 ***********************************************************************/
5647 /* Save current settings of IT on IT->stack. Called, for example,
5648 before setting up IT for an overlay string, to be able to restore
5649 IT's settings to what they were after the overlay string has been
5650 processed. If POSITION is non-NULL, it is the position to save on
5651 the stack instead of IT->position. */
5654 push_it (struct it
*it
, struct text_pos
*position
)
5656 struct iterator_stack_entry
*p
;
5658 eassert (it
->sp
< IT_STACK_SIZE
);
5659 p
= it
->stack
+ it
->sp
;
5661 p
->stop_charpos
= it
->stop_charpos
;
5662 p
->prev_stop
= it
->prev_stop
;
5663 p
->base_level_stop
= it
->base_level_stop
;
5664 p
->cmp_it
= it
->cmp_it
;
5665 eassert (it
->face_id
>= 0);
5666 p
->face_id
= it
->face_id
;
5667 p
->string
= it
->string
;
5668 p
->method
= it
->method
;
5669 p
->from_overlay
= it
->from_overlay
;
5672 case GET_FROM_IMAGE
:
5673 p
->u
.image
.object
= it
->object
;
5674 p
->u
.image
.image_id
= it
->image_id
;
5675 p
->u
.image
.slice
= it
->slice
;
5677 case GET_FROM_STRETCH
:
5678 p
->u
.stretch
.object
= it
->object
;
5681 p
->position
= position
? *position
: it
->position
;
5682 p
->current
= it
->current
;
5683 p
->end_charpos
= it
->end_charpos
;
5684 p
->string_nchars
= it
->string_nchars
;
5686 p
->multibyte_p
= it
->multibyte_p
;
5687 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5688 p
->space_width
= it
->space_width
;
5689 p
->font_height
= it
->font_height
;
5690 p
->voffset
= it
->voffset
;
5691 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5692 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5693 p
->display_ellipsis_p
= 0;
5694 p
->line_wrap
= it
->line_wrap
;
5695 p
->bidi_p
= it
->bidi_p
;
5696 p
->paragraph_embedding
= it
->paragraph_embedding
;
5697 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5700 /* Save the state of the bidi iterator as well. */
5702 bidi_push_it (&it
->bidi_it
);
5706 iterate_out_of_display_property (struct it
*it
)
5708 int buffer_p
= !STRINGP (it
->string
);
5709 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5710 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5712 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5714 /* Maybe initialize paragraph direction. If we are at the beginning
5715 of a new paragraph, next_element_from_buffer may not have a
5716 chance to do that. */
5717 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5718 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5719 /* prev_stop can be zero, so check against BEGV as well. */
5720 while (it
->bidi_it
.charpos
>= bob
5721 && it
->prev_stop
<= it
->bidi_it
.charpos
5722 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5723 && it
->bidi_it
.charpos
< eob
)
5724 bidi_move_to_visually_next (&it
->bidi_it
);
5725 /* Record the stop_pos we just crossed, for when we cross it
5727 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5728 it
->prev_stop
= CHARPOS (it
->position
);
5729 /* If we ended up not where pop_it put us, resync IT's
5730 positional members with the bidi iterator. */
5731 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5732 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5734 it
->current
.pos
= it
->position
;
5736 it
->current
.string_pos
= it
->position
;
5739 /* Restore IT's settings from IT->stack. Called, for example, when no
5740 more overlay strings must be processed, and we return to delivering
5741 display elements from a buffer, or when the end of a string from a
5742 `display' property is reached and we return to delivering display
5743 elements from an overlay string, or from a buffer. */
5746 pop_it (struct it
*it
)
5748 struct iterator_stack_entry
*p
;
5749 int from_display_prop
= it
->from_disp_prop_p
;
5751 eassert (it
->sp
> 0);
5753 p
= it
->stack
+ it
->sp
;
5754 it
->stop_charpos
= p
->stop_charpos
;
5755 it
->prev_stop
= p
->prev_stop
;
5756 it
->base_level_stop
= p
->base_level_stop
;
5757 it
->cmp_it
= p
->cmp_it
;
5758 it
->face_id
= p
->face_id
;
5759 it
->current
= p
->current
;
5760 it
->position
= p
->position
;
5761 it
->string
= p
->string
;
5762 it
->from_overlay
= p
->from_overlay
;
5763 if (NILP (it
->string
))
5764 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5765 it
->method
= p
->method
;
5768 case GET_FROM_IMAGE
:
5769 it
->image_id
= p
->u
.image
.image_id
;
5770 it
->object
= p
->u
.image
.object
;
5771 it
->slice
= p
->u
.image
.slice
;
5773 case GET_FROM_STRETCH
:
5774 it
->object
= p
->u
.stretch
.object
;
5776 case GET_FROM_BUFFER
:
5777 it
->object
= it
->w
->buffer
;
5779 case GET_FROM_STRING
:
5780 it
->object
= it
->string
;
5782 case GET_FROM_DISPLAY_VECTOR
:
5784 it
->method
= GET_FROM_C_STRING
;
5785 else if (STRINGP (it
->string
))
5786 it
->method
= GET_FROM_STRING
;
5789 it
->method
= GET_FROM_BUFFER
;
5790 it
->object
= it
->w
->buffer
;
5793 it
->end_charpos
= p
->end_charpos
;
5794 it
->string_nchars
= p
->string_nchars
;
5796 it
->multibyte_p
= p
->multibyte_p
;
5797 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5798 it
->space_width
= p
->space_width
;
5799 it
->font_height
= p
->font_height
;
5800 it
->voffset
= p
->voffset
;
5801 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5802 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5803 it
->line_wrap
= p
->line_wrap
;
5804 it
->bidi_p
= p
->bidi_p
;
5805 it
->paragraph_embedding
= p
->paragraph_embedding
;
5806 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5809 bidi_pop_it (&it
->bidi_it
);
5810 /* Bidi-iterate until we get out of the portion of text, if any,
5811 covered by a `display' text property or by an overlay with
5812 `display' property. (We cannot just jump there, because the
5813 internal coherency of the bidi iterator state can not be
5814 preserved across such jumps.) We also must determine the
5815 paragraph base direction if the overlay we just processed is
5816 at the beginning of a new paragraph. */
5817 if (from_display_prop
5818 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5819 iterate_out_of_display_property (it
);
5821 eassert ((BUFFERP (it
->object
)
5822 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5823 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5824 || (STRINGP (it
->object
)
5825 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5826 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5827 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5833 /***********************************************************************
5835 ***********************************************************************/
5837 /* Set IT's current position to the previous line start. */
5840 back_to_previous_line_start (struct it
*it
)
5842 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5843 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5847 /* Move IT to the next line start.
5849 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5850 we skipped over part of the text (as opposed to moving the iterator
5851 continuously over the text). Otherwise, don't change the value
5854 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5855 iterator on the newline, if it was found.
5857 Newlines may come from buffer text, overlay strings, or strings
5858 displayed via the `display' property. That's the reason we can't
5859 simply use find_next_newline_no_quit.
5861 Note that this function may not skip over invisible text that is so
5862 because of text properties and immediately follows a newline. If
5863 it would, function reseat_at_next_visible_line_start, when called
5864 from set_iterator_to_next, would effectively make invisible
5865 characters following a newline part of the wrong glyph row, which
5866 leads to wrong cursor motion. */
5869 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5870 struct bidi_it
*bidi_it_prev
)
5872 ptrdiff_t old_selective
;
5873 int newline_found_p
, n
;
5874 const int MAX_NEWLINE_DISTANCE
= 500;
5876 /* If already on a newline, just consume it to avoid unintended
5877 skipping over invisible text below. */
5878 if (it
->what
== IT_CHARACTER
5880 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5882 if (it
->bidi_p
&& bidi_it_prev
)
5883 *bidi_it_prev
= it
->bidi_it
;
5884 set_iterator_to_next (it
, 0);
5889 /* Don't handle selective display in the following. It's (a)
5890 unnecessary because it's done by the caller, and (b) leads to an
5891 infinite recursion because next_element_from_ellipsis indirectly
5892 calls this function. */
5893 old_selective
= it
->selective
;
5896 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5897 from buffer text. */
5898 for (n
= newline_found_p
= 0;
5899 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5900 n
+= STRINGP (it
->string
) ? 0 : 1)
5902 if (!get_next_display_element (it
))
5904 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5905 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5906 *bidi_it_prev
= it
->bidi_it
;
5907 set_iterator_to_next (it
, 0);
5910 /* If we didn't find a newline near enough, see if we can use a
5912 if (!newline_found_p
)
5914 ptrdiff_t start
= IT_CHARPOS (*it
);
5915 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5918 eassert (!STRINGP (it
->string
));
5920 /* If there isn't any `display' property in sight, and no
5921 overlays, we can just use the position of the newline in
5923 if (it
->stop_charpos
>= limit
5924 || ((pos
= Fnext_single_property_change (make_number (start
),
5926 make_number (limit
)),
5928 && next_overlay_change (start
) == ZV
))
5932 IT_CHARPOS (*it
) = limit
;
5933 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5937 struct bidi_it bprev
;
5939 /* Help bidi.c avoid expensive searches for display
5940 properties and overlays, by telling it that there are
5941 none up to `limit'. */
5942 if (it
->bidi_it
.disp_pos
< limit
)
5944 it
->bidi_it
.disp_pos
= limit
;
5945 it
->bidi_it
.disp_prop
= 0;
5948 bprev
= it
->bidi_it
;
5949 bidi_move_to_visually_next (&it
->bidi_it
);
5950 } while (it
->bidi_it
.charpos
!= limit
);
5951 IT_CHARPOS (*it
) = limit
;
5952 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5954 *bidi_it_prev
= bprev
;
5956 *skipped_p
= newline_found_p
= 1;
5960 while (get_next_display_element (it
)
5961 && !newline_found_p
)
5963 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5964 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5965 *bidi_it_prev
= it
->bidi_it
;
5966 set_iterator_to_next (it
, 0);
5971 it
->selective
= old_selective
;
5972 return newline_found_p
;
5976 /* Set IT's current position to the previous visible line start. Skip
5977 invisible text that is so either due to text properties or due to
5978 selective display. Caution: this does not change IT->current_x and
5982 back_to_previous_visible_line_start (struct it
*it
)
5984 while (IT_CHARPOS (*it
) > BEGV
)
5986 back_to_previous_line_start (it
);
5988 if (IT_CHARPOS (*it
) <= BEGV
)
5991 /* If selective > 0, then lines indented more than its value are
5993 if (it
->selective
> 0
5994 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5998 /* Check the newline before point for invisibility. */
6001 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6002 Qinvisible
, it
->window
);
6003 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6007 if (IT_CHARPOS (*it
) <= BEGV
)
6012 void *it2data
= NULL
;
6015 Lisp_Object val
, overlay
;
6017 SAVE_IT (it2
, *it
, it2data
);
6019 /* If newline is part of a composition, continue from start of composition */
6020 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6021 && beg
< IT_CHARPOS (*it
))
6024 /* If newline is replaced by a display property, find start of overlay
6025 or interval and continue search from that point. */
6026 pos
= --IT_CHARPOS (it2
);
6029 bidi_unshelve_cache (NULL
, 0);
6030 it2
.string_from_display_prop_p
= 0;
6031 it2
.from_disp_prop_p
= 0;
6032 if (handle_display_prop (&it2
) == HANDLED_RETURN
6033 && !NILP (val
= get_char_property_and_overlay
6034 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6035 && (OVERLAYP (overlay
)
6036 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6037 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6039 RESTORE_IT (it
, it
, it2data
);
6043 /* Newline is not replaced by anything -- so we are done. */
6044 RESTORE_IT (it
, it
, it2data
);
6050 IT_CHARPOS (*it
) = beg
;
6051 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6055 it
->continuation_lines_width
= 0;
6057 eassert (IT_CHARPOS (*it
) >= BEGV
);
6058 eassert (IT_CHARPOS (*it
) == BEGV
6059 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6064 /* Reseat iterator IT at the previous visible line start. Skip
6065 invisible text that is so either due to text properties or due to
6066 selective display. At the end, update IT's overlay information,
6067 face information etc. */
6070 reseat_at_previous_visible_line_start (struct it
*it
)
6072 back_to_previous_visible_line_start (it
);
6073 reseat (it
, it
->current
.pos
, 1);
6078 /* Reseat iterator IT on the next visible line start in the current
6079 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6080 preceding the line start. Skip over invisible text that is so
6081 because of selective display. Compute faces, overlays etc at the
6082 new position. Note that this function does not skip over text that
6083 is invisible because of text properties. */
6086 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6088 int newline_found_p
, skipped_p
= 0;
6089 struct bidi_it bidi_it_prev
;
6091 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6093 /* Skip over lines that are invisible because they are indented
6094 more than the value of IT->selective. */
6095 if (it
->selective
> 0)
6096 while (IT_CHARPOS (*it
) < ZV
6097 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6100 eassert (IT_BYTEPOS (*it
) == BEGV
6101 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6103 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6106 /* Position on the newline if that's what's requested. */
6107 if (on_newline_p
&& newline_found_p
)
6109 if (STRINGP (it
->string
))
6111 if (IT_STRING_CHARPOS (*it
) > 0)
6115 --IT_STRING_CHARPOS (*it
);
6116 --IT_STRING_BYTEPOS (*it
);
6120 /* We need to restore the bidi iterator to the state
6121 it had on the newline, and resync the IT's
6122 position with that. */
6123 it
->bidi_it
= bidi_it_prev
;
6124 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6125 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6129 else if (IT_CHARPOS (*it
) > BEGV
)
6138 /* We need to restore the bidi iterator to the state it
6139 had on the newline and resync IT with that. */
6140 it
->bidi_it
= bidi_it_prev
;
6141 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6142 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6144 reseat (it
, it
->current
.pos
, 0);
6148 reseat (it
, it
->current
.pos
, 0);
6155 /***********************************************************************
6156 Changing an iterator's position
6157 ***********************************************************************/
6159 /* Change IT's current position to POS in current_buffer. If FORCE_P
6160 is non-zero, always check for text properties at the new position.
6161 Otherwise, text properties are only looked up if POS >=
6162 IT->check_charpos of a property. */
6165 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6167 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6169 reseat_1 (it
, pos
, 0);
6171 /* Determine where to check text properties. Avoid doing it
6172 where possible because text property lookup is very expensive. */
6174 || CHARPOS (pos
) > it
->stop_charpos
6175 || CHARPOS (pos
) < original_pos
)
6179 /* For bidi iteration, we need to prime prev_stop and
6180 base_level_stop with our best estimations. */
6181 /* Implementation note: Of course, POS is not necessarily a
6182 stop position, so assigning prev_pos to it is a lie; we
6183 should have called compute_stop_backwards. However, if
6184 the current buffer does not include any R2L characters,
6185 that call would be a waste of cycles, because the
6186 iterator will never move back, and thus never cross this
6187 "fake" stop position. So we delay that backward search
6188 until the time we really need it, in next_element_from_buffer. */
6189 if (CHARPOS (pos
) != it
->prev_stop
)
6190 it
->prev_stop
= CHARPOS (pos
);
6191 if (CHARPOS (pos
) < it
->base_level_stop
)
6192 it
->base_level_stop
= 0; /* meaning it's unknown */
6198 it
->prev_stop
= it
->base_level_stop
= 0;
6207 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6208 IT->stop_pos to POS, also. */
6211 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6213 /* Don't call this function when scanning a C string. */
6214 eassert (it
->s
== NULL
);
6216 /* POS must be a reasonable value. */
6217 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6219 it
->current
.pos
= it
->position
= pos
;
6220 it
->end_charpos
= ZV
;
6222 it
->current
.dpvec_index
= -1;
6223 it
->current
.overlay_string_index
= -1;
6224 IT_STRING_CHARPOS (*it
) = -1;
6225 IT_STRING_BYTEPOS (*it
) = -1;
6227 it
->method
= GET_FROM_BUFFER
;
6228 it
->object
= it
->w
->buffer
;
6229 it
->area
= TEXT_AREA
;
6230 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6232 it
->string_from_display_prop_p
= 0;
6233 it
->string_from_prefix_prop_p
= 0;
6235 it
->from_disp_prop_p
= 0;
6236 it
->face_before_selective_p
= 0;
6239 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6241 bidi_unshelve_cache (NULL
, 0);
6242 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6243 it
->bidi_it
.string
.s
= NULL
;
6244 it
->bidi_it
.string
.lstring
= Qnil
;
6245 it
->bidi_it
.string
.bufpos
= 0;
6246 it
->bidi_it
.string
.unibyte
= 0;
6251 it
->stop_charpos
= CHARPOS (pos
);
6252 it
->base_level_stop
= CHARPOS (pos
);
6257 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6258 If S is non-null, it is a C string to iterate over. Otherwise,
6259 STRING gives a Lisp string to iterate over.
6261 If PRECISION > 0, don't return more then PRECISION number of
6262 characters from the string.
6264 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6265 characters have been returned. FIELD_WIDTH < 0 means an infinite
6268 MULTIBYTE = 0 means disable processing of multibyte characters,
6269 MULTIBYTE > 0 means enable it,
6270 MULTIBYTE < 0 means use IT->multibyte_p.
6272 IT must be initialized via a prior call to init_iterator before
6273 calling this function. */
6276 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6277 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6280 /* No region in strings. */
6281 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6283 /* No text property checks performed by default, but see below. */
6284 it
->stop_charpos
= -1;
6286 /* Set iterator position and end position. */
6287 memset (&it
->current
, 0, sizeof it
->current
);
6288 it
->current
.overlay_string_index
= -1;
6289 it
->current
.dpvec_index
= -1;
6290 eassert (charpos
>= 0);
6292 /* If STRING is specified, use its multibyteness, otherwise use the
6293 setting of MULTIBYTE, if specified. */
6295 it
->multibyte_p
= multibyte
> 0;
6297 /* Bidirectional reordering of strings is controlled by the default
6298 value of bidi-display-reordering. Don't try to reorder while
6299 loading loadup.el, as the necessary character property tables are
6300 not yet available. */
6303 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6307 eassert (STRINGP (string
));
6308 it
->string
= string
;
6310 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6311 it
->method
= GET_FROM_STRING
;
6312 it
->current
.string_pos
= string_pos (charpos
, string
);
6316 it
->bidi_it
.string
.lstring
= string
;
6317 it
->bidi_it
.string
.s
= NULL
;
6318 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6319 it
->bidi_it
.string
.bufpos
= 0;
6320 it
->bidi_it
.string
.from_disp_str
= 0;
6321 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6322 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6323 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6328 it
->s
= (const unsigned char *) s
;
6331 /* Note that we use IT->current.pos, not it->current.string_pos,
6332 for displaying C strings. */
6333 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6334 if (it
->multibyte_p
)
6336 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6337 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6341 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6342 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6347 it
->bidi_it
.string
.lstring
= Qnil
;
6348 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6349 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6350 it
->bidi_it
.string
.bufpos
= 0;
6351 it
->bidi_it
.string
.from_disp_str
= 0;
6352 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6353 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6356 it
->method
= GET_FROM_C_STRING
;
6359 /* PRECISION > 0 means don't return more than PRECISION characters
6361 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6363 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6365 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6368 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6369 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6370 FIELD_WIDTH < 0 means infinite field width. This is useful for
6371 padding with `-' at the end of a mode line. */
6372 if (field_width
< 0)
6373 field_width
= INFINITY
;
6374 /* Implementation note: We deliberately don't enlarge
6375 it->bidi_it.string.schars here to fit it->end_charpos, because
6376 the bidi iterator cannot produce characters out of thin air. */
6377 if (field_width
> it
->end_charpos
- charpos
)
6378 it
->end_charpos
= charpos
+ field_width
;
6380 /* Use the standard display table for displaying strings. */
6381 if (DISP_TABLE_P (Vstandard_display_table
))
6382 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6384 it
->stop_charpos
= charpos
;
6385 it
->prev_stop
= charpos
;
6386 it
->base_level_stop
= 0;
6389 it
->bidi_it
.first_elt
= 1;
6390 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6391 it
->bidi_it
.disp_pos
= -1;
6393 if (s
== NULL
&& it
->multibyte_p
)
6395 ptrdiff_t endpos
= SCHARS (it
->string
);
6396 if (endpos
> it
->end_charpos
)
6397 endpos
= it
->end_charpos
;
6398 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6406 /***********************************************************************
6408 ***********************************************************************/
6410 /* Map enum it_method value to corresponding next_element_from_* function. */
6412 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6414 next_element_from_buffer
,
6415 next_element_from_display_vector
,
6416 next_element_from_string
,
6417 next_element_from_c_string
,
6418 next_element_from_image
,
6419 next_element_from_stretch
6422 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6425 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6426 (possibly with the following characters). */
6428 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6429 ((IT)->cmp_it.id >= 0 \
6430 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6431 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6432 END_CHARPOS, (IT)->w, \
6433 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6437 /* Lookup the char-table Vglyphless_char_display for character C (-1
6438 if we want information for no-font case), and return the display
6439 method symbol. By side-effect, update it->what and
6440 it->glyphless_method. This function is called from
6441 get_next_display_element for each character element, and from
6442 x_produce_glyphs when no suitable font was found. */
6445 lookup_glyphless_char_display (int c
, struct it
*it
)
6447 Lisp_Object glyphless_method
= Qnil
;
6449 if (CHAR_TABLE_P (Vglyphless_char_display
)
6450 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6454 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6455 if (CONSP (glyphless_method
))
6456 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6457 ? XCAR (glyphless_method
)
6458 : XCDR (glyphless_method
);
6461 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6465 if (NILP (glyphless_method
))
6468 /* The default is to display the character by a proper font. */
6470 /* The default for the no-font case is to display an empty box. */
6471 glyphless_method
= Qempty_box
;
6473 if (EQ (glyphless_method
, Qzero_width
))
6476 return glyphless_method
;
6477 /* This method can't be used for the no-font case. */
6478 glyphless_method
= Qempty_box
;
6480 if (EQ (glyphless_method
, Qthin_space
))
6481 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6482 else if (EQ (glyphless_method
, Qempty_box
))
6483 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6484 else if (EQ (glyphless_method
, Qhex_code
))
6485 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6486 else if (STRINGP (glyphless_method
))
6487 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6490 /* Invalid value. We use the default method. */
6491 glyphless_method
= Qnil
;
6494 it
->what
= IT_GLYPHLESS
;
6495 return glyphless_method
;
6498 /* Load IT's display element fields with information about the next
6499 display element from the current position of IT. Value is zero if
6500 end of buffer (or C string) is reached. */
6502 static struct frame
*last_escape_glyph_frame
= NULL
;
6503 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6504 static int last_escape_glyph_merged_face_id
= 0;
6506 struct frame
*last_glyphless_glyph_frame
= NULL
;
6507 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6508 int last_glyphless_glyph_merged_face_id
= 0;
6511 get_next_display_element (struct it
*it
)
6513 /* Non-zero means that we found a display element. Zero means that
6514 we hit the end of what we iterate over. Performance note: the
6515 function pointer `method' used here turns out to be faster than
6516 using a sequence of if-statements. */
6520 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6522 if (it
->what
== IT_CHARACTER
)
6524 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6525 and only if (a) the resolved directionality of that character
6527 /* FIXME: Do we need an exception for characters from display
6529 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6530 it
->c
= bidi_mirror_char (it
->c
);
6531 /* Map via display table or translate control characters.
6532 IT->c, IT->len etc. have been set to the next character by
6533 the function call above. If we have a display table, and it
6534 contains an entry for IT->c, translate it. Don't do this if
6535 IT->c itself comes from a display table, otherwise we could
6536 end up in an infinite recursion. (An alternative could be to
6537 count the recursion depth of this function and signal an
6538 error when a certain maximum depth is reached.) Is it worth
6540 if (success_p
&& it
->dpvec
== NULL
)
6543 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6544 int nonascii_space_p
= 0;
6545 int nonascii_hyphen_p
= 0;
6546 int c
= it
->c
; /* This is the character to display. */
6548 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6550 eassert (SINGLE_BYTE_CHAR_P (c
));
6551 if (unibyte_display_via_language_environment
)
6553 c
= DECODE_CHAR (unibyte
, c
);
6555 c
= BYTE8_TO_CHAR (it
->c
);
6558 c
= BYTE8_TO_CHAR (it
->c
);
6562 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6565 struct Lisp_Vector
*v
= XVECTOR (dv
);
6567 /* Return the first character from the display table
6568 entry, if not empty. If empty, don't display the
6569 current character. */
6572 it
->dpvec_char_len
= it
->len
;
6573 it
->dpvec
= v
->contents
;
6574 it
->dpend
= v
->contents
+ v
->header
.size
;
6575 it
->current
.dpvec_index
= 0;
6576 it
->dpvec_face_id
= -1;
6577 it
->saved_face_id
= it
->face_id
;
6578 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6583 set_iterator_to_next (it
, 0);
6588 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6590 if (it
->what
== IT_GLYPHLESS
)
6592 /* Don't display this character. */
6593 set_iterator_to_next (it
, 0);
6597 /* If `nobreak-char-display' is non-nil, we display
6598 non-ASCII spaces and hyphens specially. */
6599 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6602 nonascii_space_p
= 1;
6603 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6604 nonascii_hyphen_p
= 1;
6607 /* Translate control characters into `\003' or `^C' form.
6608 Control characters coming from a display table entry are
6609 currently not translated because we use IT->dpvec to hold
6610 the translation. This could easily be changed but I
6611 don't believe that it is worth doing.
6613 The characters handled by `nobreak-char-display' must be
6616 Non-printable characters and raw-byte characters are also
6617 translated to octal form. */
6618 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6619 ? (it
->area
!= TEXT_AREA
6620 /* In mode line, treat \n, \t like other crl chars. */
6623 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6624 || (c
!= '\n' && c
!= '\t'))
6626 || nonascii_hyphen_p
6628 || ! CHAR_PRINTABLE_P (c
))))
6630 /* C is a control character, non-ASCII space/hyphen,
6631 raw-byte, or a non-printable character which must be
6632 displayed either as '\003' or as `^C' where the '\\'
6633 and '^' can be defined in the display table. Fill
6634 IT->ctl_chars with glyphs for what we have to
6635 display. Then, set IT->dpvec to these glyphs. */
6642 /* Handle control characters with ^. */
6644 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6648 g
= '^'; /* default glyph for Control */
6649 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6651 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6653 g
= GLYPH_CODE_CHAR (gc
);
6654 lface_id
= GLYPH_CODE_FACE (gc
);
6658 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6660 else if (it
->f
== last_escape_glyph_frame
6661 && it
->face_id
== last_escape_glyph_face_id
)
6663 face_id
= last_escape_glyph_merged_face_id
;
6667 /* Merge the escape-glyph face into the current face. */
6668 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6670 last_escape_glyph_frame
= it
->f
;
6671 last_escape_glyph_face_id
= it
->face_id
;
6672 last_escape_glyph_merged_face_id
= face_id
;
6675 XSETINT (it
->ctl_chars
[0], g
);
6676 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6678 goto display_control
;
6681 /* Handle non-ascii space in the mode where it only gets
6684 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6686 /* Merge `nobreak-space' into the current face. */
6687 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6689 XSETINT (it
->ctl_chars
[0], ' ');
6691 goto display_control
;
6694 /* Handle sequences that start with the "escape glyph". */
6696 /* the default escape glyph is \. */
6697 escape_glyph
= '\\';
6700 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6702 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6703 lface_id
= GLYPH_CODE_FACE (gc
);
6707 /* The display table specified a face.
6708 Merge it into face_id and also into escape_glyph. */
6709 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6712 else if (it
->f
== last_escape_glyph_frame
6713 && it
->face_id
== last_escape_glyph_face_id
)
6715 face_id
= last_escape_glyph_merged_face_id
;
6719 /* Merge the escape-glyph face into the current face. */
6720 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6722 last_escape_glyph_frame
= it
->f
;
6723 last_escape_glyph_face_id
= it
->face_id
;
6724 last_escape_glyph_merged_face_id
= face_id
;
6727 /* Draw non-ASCII hyphen with just highlighting: */
6729 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6731 XSETINT (it
->ctl_chars
[0], '-');
6733 goto display_control
;
6736 /* Draw non-ASCII space/hyphen with escape glyph: */
6738 if (nonascii_space_p
|| nonascii_hyphen_p
)
6740 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6741 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6743 goto display_control
;
6750 if (CHAR_BYTE8_P (c
))
6751 /* Display \200 instead of \17777600. */
6752 c
= CHAR_TO_BYTE8 (c
);
6753 len
= sprintf (str
, "%03o", c
);
6755 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6756 for (i
= 0; i
< len
; i
++)
6757 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6762 /* Set up IT->dpvec and return first character from it. */
6763 it
->dpvec_char_len
= it
->len
;
6764 it
->dpvec
= it
->ctl_chars
;
6765 it
->dpend
= it
->dpvec
+ ctl_len
;
6766 it
->current
.dpvec_index
= 0;
6767 it
->dpvec_face_id
= face_id
;
6768 it
->saved_face_id
= it
->face_id
;
6769 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6773 it
->char_to_display
= c
;
6777 it
->char_to_display
= it
->c
;
6781 /* Adjust face id for a multibyte character. There are no multibyte
6782 character in unibyte text. */
6783 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6786 && FRAME_WINDOW_P (it
->f
))
6788 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6790 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6792 /* Automatic composition with glyph-string. */
6793 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6795 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6799 ptrdiff_t pos
= (it
->s
? -1
6800 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6801 : IT_CHARPOS (*it
));
6804 if (it
->what
== IT_CHARACTER
)
6805 c
= it
->char_to_display
;
6808 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6812 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6813 /* TAB in a composition means display glyphs with
6814 padding space on the left or right. */
6815 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6818 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6823 /* Is this character the last one of a run of characters with
6824 box? If yes, set IT->end_of_box_run_p to 1. */
6828 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6830 int face_id
= underlying_face_id (it
);
6831 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6835 if (face
->box
== FACE_NO_BOX
)
6837 /* If the box comes from face properties in a
6838 display string, check faces in that string. */
6839 int string_face_id
= face_after_it_pos (it
);
6840 it
->end_of_box_run_p
6841 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6844 /* Otherwise, the box comes from the underlying face.
6845 If this is the last string character displayed, check
6846 the next buffer location. */
6847 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6848 && (it
->current
.overlay_string_index
6849 == it
->n_overlay_strings
- 1))
6853 struct text_pos pos
= it
->current
.pos
;
6854 INC_TEXT_POS (pos
, it
->multibyte_p
);
6856 next_face_id
= face_at_buffer_position
6857 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6858 it
->region_end_charpos
, &ignore
,
6859 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6861 it
->end_of_box_run_p
6862 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6869 int face_id
= face_after_it_pos (it
);
6870 it
->end_of_box_run_p
6871 = (face_id
!= it
->face_id
6872 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6875 /* If we reached the end of the object we've been iterating (e.g., a
6876 display string or an overlay string), and there's something on
6877 IT->stack, proceed with what's on the stack. It doesn't make
6878 sense to return zero if there's unprocessed stuff on the stack,
6879 because otherwise that stuff will never be displayed. */
6880 if (!success_p
&& it
->sp
> 0)
6882 set_iterator_to_next (it
, 0);
6883 success_p
= get_next_display_element (it
);
6886 /* Value is 0 if end of buffer or string reached. */
6891 /* Move IT to the next display element.
6893 RESEAT_P non-zero means if called on a newline in buffer text,
6894 skip to the next visible line start.
6896 Functions get_next_display_element and set_iterator_to_next are
6897 separate because I find this arrangement easier to handle than a
6898 get_next_display_element function that also increments IT's
6899 position. The way it is we can first look at an iterator's current
6900 display element, decide whether it fits on a line, and if it does,
6901 increment the iterator position. The other way around we probably
6902 would either need a flag indicating whether the iterator has to be
6903 incremented the next time, or we would have to implement a
6904 decrement position function which would not be easy to write. */
6907 set_iterator_to_next (struct it
*it
, int reseat_p
)
6909 /* Reset flags indicating start and end of a sequence of characters
6910 with box. Reset them at the start of this function because
6911 moving the iterator to a new position might set them. */
6912 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6916 case GET_FROM_BUFFER
:
6917 /* The current display element of IT is a character from
6918 current_buffer. Advance in the buffer, and maybe skip over
6919 invisible lines that are so because of selective display. */
6920 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6921 reseat_at_next_visible_line_start (it
, 0);
6922 else if (it
->cmp_it
.id
>= 0)
6924 /* We are currently getting glyphs from a composition. */
6929 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6930 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6931 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6933 it
->cmp_it
.from
= it
->cmp_it
.to
;
6938 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6940 it
->end_charpos
, Qnil
);
6943 else if (! it
->cmp_it
.reversed_p
)
6945 /* Composition created while scanning forward. */
6946 /* Update IT's char/byte positions to point to the first
6947 character of the next grapheme cluster, or to the
6948 character visually after the current composition. */
6949 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6950 bidi_move_to_visually_next (&it
->bidi_it
);
6951 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6952 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6954 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6956 /* Proceed to the next grapheme cluster. */
6957 it
->cmp_it
.from
= it
->cmp_it
.to
;
6961 /* No more grapheme clusters in this composition.
6962 Find the next stop position. */
6963 ptrdiff_t stop
= it
->end_charpos
;
6964 if (it
->bidi_it
.scan_dir
< 0)
6965 /* Now we are scanning backward and don't know
6968 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6969 IT_BYTEPOS (*it
), stop
, Qnil
);
6974 /* Composition created while scanning backward. */
6975 /* Update IT's char/byte positions to point to the last
6976 character of the previous grapheme cluster, or the
6977 character visually after the current composition. */
6978 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6979 bidi_move_to_visually_next (&it
->bidi_it
);
6980 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6981 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6982 if (it
->cmp_it
.from
> 0)
6984 /* Proceed to the previous grapheme cluster. */
6985 it
->cmp_it
.to
= it
->cmp_it
.from
;
6989 /* No more grapheme clusters in this composition.
6990 Find the next stop position. */
6991 ptrdiff_t stop
= it
->end_charpos
;
6992 if (it
->bidi_it
.scan_dir
< 0)
6993 /* Now we are scanning backward and don't know
6996 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6997 IT_BYTEPOS (*it
), stop
, Qnil
);
7003 eassert (it
->len
!= 0);
7007 IT_BYTEPOS (*it
) += it
->len
;
7008 IT_CHARPOS (*it
) += 1;
7012 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7013 /* If this is a new paragraph, determine its base
7014 direction (a.k.a. its base embedding level). */
7015 if (it
->bidi_it
.new_paragraph
)
7016 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7017 bidi_move_to_visually_next (&it
->bidi_it
);
7018 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7019 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7020 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7022 /* As the scan direction was changed, we must
7023 re-compute the stop position for composition. */
7024 ptrdiff_t stop
= it
->end_charpos
;
7025 if (it
->bidi_it
.scan_dir
< 0)
7027 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7028 IT_BYTEPOS (*it
), stop
, Qnil
);
7031 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7035 case GET_FROM_C_STRING
:
7036 /* Current display element of IT is from a C string. */
7038 /* If the string position is beyond string's end, it means
7039 next_element_from_c_string is padding the string with
7040 blanks, in which case we bypass the bidi iterator,
7041 because it cannot deal with such virtual characters. */
7042 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7044 IT_BYTEPOS (*it
) += it
->len
;
7045 IT_CHARPOS (*it
) += 1;
7049 bidi_move_to_visually_next (&it
->bidi_it
);
7050 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7051 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7055 case GET_FROM_DISPLAY_VECTOR
:
7056 /* Current display element of IT is from a display table entry.
7057 Advance in the display table definition. Reset it to null if
7058 end reached, and continue with characters from buffers/
7060 ++it
->current
.dpvec_index
;
7062 /* Restore face of the iterator to what they were before the
7063 display vector entry (these entries may contain faces). */
7064 it
->face_id
= it
->saved_face_id
;
7066 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7068 int recheck_faces
= it
->ellipsis_p
;
7071 it
->method
= GET_FROM_C_STRING
;
7072 else if (STRINGP (it
->string
))
7073 it
->method
= GET_FROM_STRING
;
7076 it
->method
= GET_FROM_BUFFER
;
7077 it
->object
= it
->w
->buffer
;
7081 it
->current
.dpvec_index
= -1;
7083 /* Skip over characters which were displayed via IT->dpvec. */
7084 if (it
->dpvec_char_len
< 0)
7085 reseat_at_next_visible_line_start (it
, 1);
7086 else if (it
->dpvec_char_len
> 0)
7088 if (it
->method
== GET_FROM_STRING
7089 && it
->n_overlay_strings
> 0)
7090 it
->ignore_overlay_strings_at_pos_p
= 1;
7091 it
->len
= it
->dpvec_char_len
;
7092 set_iterator_to_next (it
, reseat_p
);
7095 /* Maybe recheck faces after display vector */
7097 it
->stop_charpos
= IT_CHARPOS (*it
);
7101 case GET_FROM_STRING
:
7102 /* Current display element is a character from a Lisp string. */
7103 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7104 /* Don't advance past string end. These conditions are true
7105 when set_iterator_to_next is called at the end of
7106 get_next_display_element, in which case the Lisp string is
7107 already exhausted, and all we want is pop the iterator
7109 if (it
->current
.overlay_string_index
>= 0)
7111 /* This is an overlay string, so there's no padding with
7112 spaces, and the number of characters in the string is
7113 where the string ends. */
7114 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7115 goto consider_string_end
;
7119 /* Not an overlay string. There could be padding, so test
7120 against it->end_charpos . */
7121 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7122 goto consider_string_end
;
7124 if (it
->cmp_it
.id
>= 0)
7130 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7131 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7132 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7133 it
->cmp_it
.from
= it
->cmp_it
.to
;
7137 composition_compute_stop_pos (&it
->cmp_it
,
7138 IT_STRING_CHARPOS (*it
),
7139 IT_STRING_BYTEPOS (*it
),
7140 it
->end_charpos
, it
->string
);
7143 else if (! it
->cmp_it
.reversed_p
)
7145 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7146 bidi_move_to_visually_next (&it
->bidi_it
);
7147 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7148 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7150 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7151 it
->cmp_it
.from
= it
->cmp_it
.to
;
7154 ptrdiff_t stop
= it
->end_charpos
;
7155 if (it
->bidi_it
.scan_dir
< 0)
7157 composition_compute_stop_pos (&it
->cmp_it
,
7158 IT_STRING_CHARPOS (*it
),
7159 IT_STRING_BYTEPOS (*it
), stop
,
7165 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7166 bidi_move_to_visually_next (&it
->bidi_it
);
7167 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7168 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7169 if (it
->cmp_it
.from
> 0)
7170 it
->cmp_it
.to
= it
->cmp_it
.from
;
7173 ptrdiff_t stop
= it
->end_charpos
;
7174 if (it
->bidi_it
.scan_dir
< 0)
7176 composition_compute_stop_pos (&it
->cmp_it
,
7177 IT_STRING_CHARPOS (*it
),
7178 IT_STRING_BYTEPOS (*it
), stop
,
7186 /* If the string position is beyond string's end, it
7187 means next_element_from_string is padding the string
7188 with blanks, in which case we bypass the bidi
7189 iterator, because it cannot deal with such virtual
7191 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7193 IT_STRING_BYTEPOS (*it
) += it
->len
;
7194 IT_STRING_CHARPOS (*it
) += 1;
7198 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7200 bidi_move_to_visually_next (&it
->bidi_it
);
7201 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7202 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7203 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7205 ptrdiff_t stop
= it
->end_charpos
;
7207 if (it
->bidi_it
.scan_dir
< 0)
7209 composition_compute_stop_pos (&it
->cmp_it
,
7210 IT_STRING_CHARPOS (*it
),
7211 IT_STRING_BYTEPOS (*it
), stop
,
7217 consider_string_end
:
7219 if (it
->current
.overlay_string_index
>= 0)
7221 /* IT->string is an overlay string. Advance to the
7222 next, if there is one. */
7223 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7226 next_overlay_string (it
);
7228 setup_for_ellipsis (it
, 0);
7233 /* IT->string is not an overlay string. If we reached
7234 its end, and there is something on IT->stack, proceed
7235 with what is on the stack. This can be either another
7236 string, this time an overlay string, or a buffer. */
7237 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7241 if (it
->method
== GET_FROM_STRING
)
7242 goto consider_string_end
;
7247 case GET_FROM_IMAGE
:
7248 case GET_FROM_STRETCH
:
7249 /* The position etc with which we have to proceed are on
7250 the stack. The position may be at the end of a string,
7251 if the `display' property takes up the whole string. */
7252 eassert (it
->sp
> 0);
7254 if (it
->method
== GET_FROM_STRING
)
7255 goto consider_string_end
;
7259 /* There are no other methods defined, so this should be a bug. */
7263 eassert (it
->method
!= GET_FROM_STRING
7264 || (STRINGP (it
->string
)
7265 && IT_STRING_CHARPOS (*it
) >= 0));
7268 /* Load IT's display element fields with information about the next
7269 display element which comes from a display table entry or from the
7270 result of translating a control character to one of the forms `^C'
7273 IT->dpvec holds the glyphs to return as characters.
7274 IT->saved_face_id holds the face id before the display vector--it
7275 is restored into IT->face_id in set_iterator_to_next. */
7278 next_element_from_display_vector (struct it
*it
)
7283 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7285 it
->face_id
= it
->saved_face_id
;
7287 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7288 That seemed totally bogus - so I changed it... */
7289 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7291 if (GLYPH_CODE_P (gc
))
7293 it
->c
= GLYPH_CODE_CHAR (gc
);
7294 it
->len
= CHAR_BYTES (it
->c
);
7296 /* The entry may contain a face id to use. Such a face id is
7297 the id of a Lisp face, not a realized face. A face id of
7298 zero means no face is specified. */
7299 if (it
->dpvec_face_id
>= 0)
7300 it
->face_id
= it
->dpvec_face_id
;
7303 int lface_id
= GLYPH_CODE_FACE (gc
);
7305 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7310 /* Display table entry is invalid. Return a space. */
7311 it
->c
= ' ', it
->len
= 1;
7313 /* Don't change position and object of the iterator here. They are
7314 still the values of the character that had this display table
7315 entry or was translated, and that's what we want. */
7316 it
->what
= IT_CHARACTER
;
7320 /* Get the first element of string/buffer in the visual order, after
7321 being reseated to a new position in a string or a buffer. */
7323 get_visually_first_element (struct it
*it
)
7325 int string_p
= STRINGP (it
->string
) || it
->s
;
7326 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7327 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7329 if (STRINGP (it
->string
))
7331 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7332 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7336 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7337 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7340 if (it
->bidi_it
.charpos
== eob
)
7342 /* Nothing to do, but reset the FIRST_ELT flag, like
7343 bidi_paragraph_init does, because we are not going to
7345 it
->bidi_it
.first_elt
= 0;
7347 else if (it
->bidi_it
.charpos
== bob
7349 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7350 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7352 /* If we are at the beginning of a line/string, we can produce
7353 the next element right away. */
7354 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7355 bidi_move_to_visually_next (&it
->bidi_it
);
7359 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7361 /* We need to prime the bidi iterator starting at the line's or
7362 string's beginning, before we will be able to produce the
7365 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7368 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7370 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7372 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7375 /* Now return to buffer/string position where we were asked
7376 to get the next display element, and produce that. */
7377 bidi_move_to_visually_next (&it
->bidi_it
);
7379 while (it
->bidi_it
.bytepos
!= orig_bytepos
7380 && it
->bidi_it
.charpos
< eob
);
7383 /* Adjust IT's position information to where we ended up. */
7384 if (STRINGP (it
->string
))
7386 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7387 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7391 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7392 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7395 if (STRINGP (it
->string
) || !it
->s
)
7397 ptrdiff_t stop
, charpos
, bytepos
;
7399 if (STRINGP (it
->string
))
7402 stop
= SCHARS (it
->string
);
7403 if (stop
> it
->end_charpos
)
7404 stop
= it
->end_charpos
;
7405 charpos
= IT_STRING_CHARPOS (*it
);
7406 bytepos
= IT_STRING_BYTEPOS (*it
);
7410 stop
= it
->end_charpos
;
7411 charpos
= IT_CHARPOS (*it
);
7412 bytepos
= IT_BYTEPOS (*it
);
7414 if (it
->bidi_it
.scan_dir
< 0)
7416 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7421 /* Load IT with the next display element from Lisp string IT->string.
7422 IT->current.string_pos is the current position within the string.
7423 If IT->current.overlay_string_index >= 0, the Lisp string is an
7427 next_element_from_string (struct it
*it
)
7429 struct text_pos position
;
7431 eassert (STRINGP (it
->string
));
7432 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7433 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7434 position
= it
->current
.string_pos
;
7436 /* With bidi reordering, the character to display might not be the
7437 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7438 that we were reseat()ed to a new string, whose paragraph
7439 direction is not known. */
7440 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7442 get_visually_first_element (it
);
7443 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7446 /* Time to check for invisible text? */
7447 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7449 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7452 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7453 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7455 /* With bidi non-linear iteration, we could find
7456 ourselves far beyond the last computed stop_charpos,
7457 with several other stop positions in between that we
7458 missed. Scan them all now, in buffer's logical
7459 order, until we find and handle the last stop_charpos
7460 that precedes our current position. */
7461 handle_stop_backwards (it
, it
->stop_charpos
);
7462 return GET_NEXT_DISPLAY_ELEMENT (it
);
7468 /* Take note of the stop position we just moved
7469 across, for when we will move back across it. */
7470 it
->prev_stop
= it
->stop_charpos
;
7471 /* If we are at base paragraph embedding level, take
7472 note of the last stop position seen at this
7474 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7475 it
->base_level_stop
= it
->stop_charpos
;
7479 /* Since a handler may have changed IT->method, we must
7481 return GET_NEXT_DISPLAY_ELEMENT (it
);
7485 /* If we are before prev_stop, we may have overstepped
7486 on our way backwards a stop_pos, and if so, we need
7487 to handle that stop_pos. */
7488 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7489 /* We can sometimes back up for reasons that have nothing
7490 to do with bidi reordering. E.g., compositions. The
7491 code below is only needed when we are above the base
7492 embedding level, so test for that explicitly. */
7493 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7495 /* If we lost track of base_level_stop, we have no better
7496 place for handle_stop_backwards to start from than string
7497 beginning. This happens, e.g., when we were reseated to
7498 the previous screenful of text by vertical-motion. */
7499 if (it
->base_level_stop
<= 0
7500 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7501 it
->base_level_stop
= 0;
7502 handle_stop_backwards (it
, it
->base_level_stop
);
7503 return GET_NEXT_DISPLAY_ELEMENT (it
);
7507 if (it
->current
.overlay_string_index
>= 0)
7509 /* Get the next character from an overlay string. In overlay
7510 strings, there is no field width or padding with spaces to
7512 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7517 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7518 IT_STRING_BYTEPOS (*it
),
7519 it
->bidi_it
.scan_dir
< 0
7521 : SCHARS (it
->string
))
7522 && next_element_from_composition (it
))
7526 else if (STRING_MULTIBYTE (it
->string
))
7528 const unsigned char *s
= (SDATA (it
->string
)
7529 + IT_STRING_BYTEPOS (*it
));
7530 it
->c
= string_char_and_length (s
, &it
->len
);
7534 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7540 /* Get the next character from a Lisp string that is not an
7541 overlay string. Such strings come from the mode line, for
7542 example. We may have to pad with spaces, or truncate the
7543 string. See also next_element_from_c_string. */
7544 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7549 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7551 /* Pad with spaces. */
7552 it
->c
= ' ', it
->len
= 1;
7553 CHARPOS (position
) = BYTEPOS (position
) = -1;
7555 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7556 IT_STRING_BYTEPOS (*it
),
7557 it
->bidi_it
.scan_dir
< 0
7559 : it
->string_nchars
)
7560 && next_element_from_composition (it
))
7564 else if (STRING_MULTIBYTE (it
->string
))
7566 const unsigned char *s
= (SDATA (it
->string
)
7567 + IT_STRING_BYTEPOS (*it
));
7568 it
->c
= string_char_and_length (s
, &it
->len
);
7572 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7577 /* Record what we have and where it came from. */
7578 it
->what
= IT_CHARACTER
;
7579 it
->object
= it
->string
;
7580 it
->position
= position
;
7585 /* Load IT with next display element from C string IT->s.
7586 IT->string_nchars is the maximum number of characters to return
7587 from the string. IT->end_charpos may be greater than
7588 IT->string_nchars when this function is called, in which case we
7589 may have to return padding spaces. Value is zero if end of string
7590 reached, including padding spaces. */
7593 next_element_from_c_string (struct it
*it
)
7598 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7599 it
->what
= IT_CHARACTER
;
7600 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7603 /* With bidi reordering, the character to display might not be the
7604 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7605 we were reseated to a new string, whose paragraph direction is
7607 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7608 get_visually_first_element (it
);
7610 /* IT's position can be greater than IT->string_nchars in case a
7611 field width or precision has been specified when the iterator was
7613 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7615 /* End of the game. */
7619 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7621 /* Pad with spaces. */
7622 it
->c
= ' ', it
->len
= 1;
7623 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7625 else if (it
->multibyte_p
)
7626 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7628 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7634 /* Set up IT to return characters from an ellipsis, if appropriate.
7635 The definition of the ellipsis glyphs may come from a display table
7636 entry. This function fills IT with the first glyph from the
7637 ellipsis if an ellipsis is to be displayed. */
7640 next_element_from_ellipsis (struct it
*it
)
7642 if (it
->selective_display_ellipsis_p
)
7643 setup_for_ellipsis (it
, it
->len
);
7646 /* The face at the current position may be different from the
7647 face we find after the invisible text. Remember what it
7648 was in IT->saved_face_id, and signal that it's there by
7649 setting face_before_selective_p. */
7650 it
->saved_face_id
= it
->face_id
;
7651 it
->method
= GET_FROM_BUFFER
;
7652 it
->object
= it
->w
->buffer
;
7653 reseat_at_next_visible_line_start (it
, 1);
7654 it
->face_before_selective_p
= 1;
7657 return GET_NEXT_DISPLAY_ELEMENT (it
);
7661 /* Deliver an image display element. The iterator IT is already
7662 filled with image information (done in handle_display_prop). Value
7667 next_element_from_image (struct it
*it
)
7669 it
->what
= IT_IMAGE
;
7670 it
->ignore_overlay_strings_at_pos_p
= 0;
7675 /* Fill iterator IT with next display element from a stretch glyph
7676 property. IT->object is the value of the text property. Value is
7680 next_element_from_stretch (struct it
*it
)
7682 it
->what
= IT_STRETCH
;
7686 /* Scan backwards from IT's current position until we find a stop
7687 position, or until BEGV. This is called when we find ourself
7688 before both the last known prev_stop and base_level_stop while
7689 reordering bidirectional text. */
7692 compute_stop_pos_backwards (struct it
*it
)
7694 const int SCAN_BACK_LIMIT
= 1000;
7695 struct text_pos pos
;
7696 struct display_pos save_current
= it
->current
;
7697 struct text_pos save_position
= it
->position
;
7698 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7699 ptrdiff_t where_we_are
= charpos
;
7700 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7701 ptrdiff_t save_end_pos
= it
->end_charpos
;
7703 eassert (NILP (it
->string
) && !it
->s
);
7704 eassert (it
->bidi_p
);
7708 it
->end_charpos
= min (charpos
+ 1, ZV
);
7709 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7710 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7711 reseat_1 (it
, pos
, 0);
7712 compute_stop_pos (it
);
7713 /* We must advance forward, right? */
7714 if (it
->stop_charpos
<= charpos
)
7717 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7719 if (it
->stop_charpos
<= where_we_are
)
7720 it
->prev_stop
= it
->stop_charpos
;
7722 it
->prev_stop
= BEGV
;
7724 it
->current
= save_current
;
7725 it
->position
= save_position
;
7726 it
->stop_charpos
= save_stop_pos
;
7727 it
->end_charpos
= save_end_pos
;
7730 /* Scan forward from CHARPOS in the current buffer/string, until we
7731 find a stop position > current IT's position. Then handle the stop
7732 position before that. This is called when we bump into a stop
7733 position while reordering bidirectional text. CHARPOS should be
7734 the last previously processed stop_pos (or BEGV/0, if none were
7735 processed yet) whose position is less that IT's current
7739 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7741 int bufp
= !STRINGP (it
->string
);
7742 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7743 struct display_pos save_current
= it
->current
;
7744 struct text_pos save_position
= it
->position
;
7745 struct text_pos pos1
;
7746 ptrdiff_t next_stop
;
7748 /* Scan in strict logical order. */
7749 eassert (it
->bidi_p
);
7753 it
->prev_stop
= charpos
;
7756 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7757 reseat_1 (it
, pos1
, 0);
7760 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7761 compute_stop_pos (it
);
7762 /* We must advance forward, right? */
7763 if (it
->stop_charpos
<= it
->prev_stop
)
7765 charpos
= it
->stop_charpos
;
7767 while (charpos
<= where_we_are
);
7770 it
->current
= save_current
;
7771 it
->position
= save_position
;
7772 next_stop
= it
->stop_charpos
;
7773 it
->stop_charpos
= it
->prev_stop
;
7775 it
->stop_charpos
= next_stop
;
7778 /* Load IT with the next display element from current_buffer. Value
7779 is zero if end of buffer reached. IT->stop_charpos is the next
7780 position at which to stop and check for text properties or buffer
7784 next_element_from_buffer (struct it
*it
)
7788 eassert (IT_CHARPOS (*it
) >= BEGV
);
7789 eassert (NILP (it
->string
) && !it
->s
);
7790 eassert (!it
->bidi_p
7791 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7792 && it
->bidi_it
.string
.s
== NULL
));
7794 /* With bidi reordering, the character to display might not be the
7795 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7796 we were reseat()ed to a new buffer position, which is potentially
7797 a different paragraph. */
7798 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7800 get_visually_first_element (it
);
7801 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7804 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7806 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7808 int overlay_strings_follow_p
;
7810 /* End of the game, except when overlay strings follow that
7811 haven't been returned yet. */
7812 if (it
->overlay_strings_at_end_processed_p
)
7813 overlay_strings_follow_p
= 0;
7816 it
->overlay_strings_at_end_processed_p
= 1;
7817 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7820 if (overlay_strings_follow_p
)
7821 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7825 it
->position
= it
->current
.pos
;
7829 else if (!(!it
->bidi_p
7830 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7831 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7833 /* With bidi non-linear iteration, we could find ourselves
7834 far beyond the last computed stop_charpos, with several
7835 other stop positions in between that we missed. Scan
7836 them all now, in buffer's logical order, until we find
7837 and handle the last stop_charpos that precedes our
7838 current position. */
7839 handle_stop_backwards (it
, it
->stop_charpos
);
7840 return GET_NEXT_DISPLAY_ELEMENT (it
);
7846 /* Take note of the stop position we just moved across,
7847 for when we will move back across it. */
7848 it
->prev_stop
= it
->stop_charpos
;
7849 /* If we are at base paragraph embedding level, take
7850 note of the last stop position seen at this
7852 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7853 it
->base_level_stop
= it
->stop_charpos
;
7856 return GET_NEXT_DISPLAY_ELEMENT (it
);
7860 /* If we are before prev_stop, we may have overstepped on
7861 our way backwards a stop_pos, and if so, we need to
7862 handle that stop_pos. */
7863 && IT_CHARPOS (*it
) < it
->prev_stop
7864 /* We can sometimes back up for reasons that have nothing
7865 to do with bidi reordering. E.g., compositions. The
7866 code below is only needed when we are above the base
7867 embedding level, so test for that explicitly. */
7868 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7870 if (it
->base_level_stop
<= 0
7871 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7873 /* If we lost track of base_level_stop, we need to find
7874 prev_stop by looking backwards. This happens, e.g., when
7875 we were reseated to the previous screenful of text by
7877 it
->base_level_stop
= BEGV
;
7878 compute_stop_pos_backwards (it
);
7879 handle_stop_backwards (it
, it
->prev_stop
);
7882 handle_stop_backwards (it
, it
->base_level_stop
);
7883 return GET_NEXT_DISPLAY_ELEMENT (it
);
7887 /* No face changes, overlays etc. in sight, so just return a
7888 character from current_buffer. */
7892 /* Maybe run the redisplay end trigger hook. Performance note:
7893 This doesn't seem to cost measurable time. */
7894 if (it
->redisplay_end_trigger_charpos
7896 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7897 run_redisplay_end_trigger_hook (it
);
7899 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7900 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7902 && next_element_from_composition (it
))
7907 /* Get the next character, maybe multibyte. */
7908 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7909 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7910 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7912 it
->c
= *p
, it
->len
= 1;
7914 /* Record what we have and where it came from. */
7915 it
->what
= IT_CHARACTER
;
7916 it
->object
= it
->w
->buffer
;
7917 it
->position
= it
->current
.pos
;
7919 /* Normally we return the character found above, except when we
7920 really want to return an ellipsis for selective display. */
7925 /* A value of selective > 0 means hide lines indented more
7926 than that number of columns. */
7927 if (it
->selective
> 0
7928 && IT_CHARPOS (*it
) + 1 < ZV
7929 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7930 IT_BYTEPOS (*it
) + 1,
7933 success_p
= next_element_from_ellipsis (it
);
7934 it
->dpvec_char_len
= -1;
7937 else if (it
->c
== '\r' && it
->selective
== -1)
7939 /* A value of selective == -1 means that everything from the
7940 CR to the end of the line is invisible, with maybe an
7941 ellipsis displayed for it. */
7942 success_p
= next_element_from_ellipsis (it
);
7943 it
->dpvec_char_len
= -1;
7948 /* Value is zero if end of buffer reached. */
7949 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7954 /* Run the redisplay end trigger hook for IT. */
7957 run_redisplay_end_trigger_hook (struct it
*it
)
7959 Lisp_Object args
[3];
7961 /* IT->glyph_row should be non-null, i.e. we should be actually
7962 displaying something, or otherwise we should not run the hook. */
7963 eassert (it
->glyph_row
);
7965 /* Set up hook arguments. */
7966 args
[0] = Qredisplay_end_trigger_functions
;
7967 args
[1] = it
->window
;
7968 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7969 it
->redisplay_end_trigger_charpos
= 0;
7971 /* Since we are *trying* to run these functions, don't try to run
7972 them again, even if they get an error. */
7973 it
->w
->redisplay_end_trigger
= Qnil
;
7974 Frun_hook_with_args (3, args
);
7976 /* Notice if it changed the face of the character we are on. */
7977 handle_face_prop (it
);
7981 /* Deliver a composition display element. Unlike the other
7982 next_element_from_XXX, this function is not registered in the array
7983 get_next_element[]. It is called from next_element_from_buffer and
7984 next_element_from_string when necessary. */
7987 next_element_from_composition (struct it
*it
)
7989 it
->what
= IT_COMPOSITION
;
7990 it
->len
= it
->cmp_it
.nbytes
;
7991 if (STRINGP (it
->string
))
7995 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7996 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7999 it
->position
= it
->current
.string_pos
;
8000 it
->object
= it
->string
;
8001 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8002 IT_STRING_BYTEPOS (*it
), it
->string
);
8008 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8009 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8012 if (it
->bidi_it
.new_paragraph
)
8013 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8014 /* Resync the bidi iterator with IT's new position.
8015 FIXME: this doesn't support bidirectional text. */
8016 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8017 bidi_move_to_visually_next (&it
->bidi_it
);
8021 it
->position
= it
->current
.pos
;
8022 it
->object
= it
->w
->buffer
;
8023 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8024 IT_BYTEPOS (*it
), Qnil
);
8031 /***********************************************************************
8032 Moving an iterator without producing glyphs
8033 ***********************************************************************/
8035 /* Check if iterator is at a position corresponding to a valid buffer
8036 position after some move_it_ call. */
8038 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8039 ((it)->method == GET_FROM_STRING \
8040 ? IT_STRING_CHARPOS (*it) == 0 \
8044 /* Move iterator IT to a specified buffer or X position within one
8045 line on the display without producing glyphs.
8047 OP should be a bit mask including some or all of these bits:
8048 MOVE_TO_X: Stop upon reaching x-position TO_X.
8049 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8050 Regardless of OP's value, stop upon reaching the end of the display line.
8052 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8053 This means, in particular, that TO_X includes window's horizontal
8056 The return value has several possible values that
8057 say what condition caused the scan to stop:
8059 MOVE_POS_MATCH_OR_ZV
8060 - when TO_POS or ZV was reached.
8063 -when TO_X was reached before TO_POS or ZV were reached.
8066 - when we reached the end of the display area and the line must
8070 - when we reached the end of the display area and the line is
8074 - when we stopped at a line end, i.e. a newline or a CR and selective
8077 static enum move_it_result
8078 move_it_in_display_line_to (struct it
*it
,
8079 ptrdiff_t to_charpos
, int to_x
,
8080 enum move_operation_enum op
)
8082 enum move_it_result result
= MOVE_UNDEFINED
;
8083 struct glyph_row
*saved_glyph_row
;
8084 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8085 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8086 void *ppos_data
= NULL
;
8088 enum it_method prev_method
= it
->method
;
8089 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8090 int saw_smaller_pos
= prev_pos
< to_charpos
;
8092 /* Don't produce glyphs in produce_glyphs. */
8093 saved_glyph_row
= it
->glyph_row
;
8094 it
->glyph_row
= NULL
;
8096 /* Use wrap_it to save a copy of IT wherever a word wrap could
8097 occur. Use atpos_it to save a copy of IT at the desired buffer
8098 position, if found, so that we can scan ahead and check if the
8099 word later overshoots the window edge. Use atx_it similarly, for
8105 /* Use ppos_it under bidi reordering to save a copy of IT for the
8106 position > CHARPOS that is the closest to CHARPOS. We restore
8107 that position in IT when we have scanned the entire display line
8108 without finding a match for CHARPOS and all the character
8109 positions are greater than CHARPOS. */
8112 SAVE_IT (ppos_it
, *it
, ppos_data
);
8113 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8114 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8115 SAVE_IT (ppos_it
, *it
, ppos_data
);
8118 #define BUFFER_POS_REACHED_P() \
8119 ((op & MOVE_TO_POS) != 0 \
8120 && BUFFERP (it->object) \
8121 && (IT_CHARPOS (*it) == to_charpos \
8123 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8124 && IT_CHARPOS (*it) > to_charpos) \
8125 || (it->what == IT_COMPOSITION \
8126 && ((IT_CHARPOS (*it) > to_charpos \
8127 && to_charpos >= it->cmp_it.charpos) \
8128 || (IT_CHARPOS (*it) < to_charpos \
8129 && to_charpos <= it->cmp_it.charpos)))) \
8130 && (it->method == GET_FROM_BUFFER \
8131 || (it->method == GET_FROM_DISPLAY_VECTOR \
8132 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8134 /* If there's a line-/wrap-prefix, handle it. */
8135 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8136 && it
->current_y
< it
->last_visible_y
)
8137 handle_line_prefix (it
);
8139 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8140 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8144 int x
, i
, ascent
= 0, descent
= 0;
8146 /* Utility macro to reset an iterator with x, ascent, and descent. */
8147 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8148 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8149 (IT)->max_descent = descent)
8151 /* Stop if we move beyond TO_CHARPOS (after an image or a
8152 display string or stretch glyph). */
8153 if ((op
& MOVE_TO_POS
) != 0
8154 && BUFFERP (it
->object
)
8155 && it
->method
== GET_FROM_BUFFER
8157 /* When the iterator is at base embedding level, we
8158 are guaranteed that characters are delivered for
8159 display in strictly increasing order of their
8160 buffer positions. */
8161 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8162 && IT_CHARPOS (*it
) > to_charpos
)
8164 && (prev_method
== GET_FROM_IMAGE
8165 || prev_method
== GET_FROM_STRETCH
8166 || prev_method
== GET_FROM_STRING
)
8167 /* Passed TO_CHARPOS from left to right. */
8168 && ((prev_pos
< to_charpos
8169 && IT_CHARPOS (*it
) > to_charpos
)
8170 /* Passed TO_CHARPOS from right to left. */
8171 || (prev_pos
> to_charpos
8172 && IT_CHARPOS (*it
) < to_charpos
)))))
8174 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8176 result
= MOVE_POS_MATCH_OR_ZV
;
8179 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8180 /* If wrap_it is valid, the current position might be in a
8181 word that is wrapped. So, save the iterator in
8182 atpos_it and continue to see if wrapping happens. */
8183 SAVE_IT (atpos_it
, *it
, atpos_data
);
8186 /* Stop when ZV reached.
8187 We used to stop here when TO_CHARPOS reached as well, but that is
8188 too soon if this glyph does not fit on this line. So we handle it
8189 explicitly below. */
8190 if (!get_next_display_element (it
))
8192 result
= MOVE_POS_MATCH_OR_ZV
;
8196 if (it
->line_wrap
== TRUNCATE
)
8198 if (BUFFER_POS_REACHED_P ())
8200 result
= MOVE_POS_MATCH_OR_ZV
;
8206 if (it
->line_wrap
== WORD_WRAP
)
8208 if (IT_DISPLAYING_WHITESPACE (it
))
8212 /* We have reached a glyph that follows one or more
8213 whitespace characters. If the position is
8214 already found, we are done. */
8215 if (atpos_it
.sp
>= 0)
8217 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8218 result
= MOVE_POS_MATCH_OR_ZV
;
8223 RESTORE_IT (it
, &atx_it
, atx_data
);
8224 result
= MOVE_X_REACHED
;
8227 /* Otherwise, we can wrap here. */
8228 SAVE_IT (wrap_it
, *it
, wrap_data
);
8234 /* Remember the line height for the current line, in case
8235 the next element doesn't fit on the line. */
8236 ascent
= it
->max_ascent
;
8237 descent
= it
->max_descent
;
8239 /* The call to produce_glyphs will get the metrics of the
8240 display element IT is loaded with. Record the x-position
8241 before this display element, in case it doesn't fit on the
8245 PRODUCE_GLYPHS (it
);
8247 if (it
->area
!= TEXT_AREA
)
8249 prev_method
= it
->method
;
8250 if (it
->method
== GET_FROM_BUFFER
)
8251 prev_pos
= IT_CHARPOS (*it
);
8252 set_iterator_to_next (it
, 1);
8253 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8254 SET_TEXT_POS (this_line_min_pos
,
8255 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8257 && (op
& MOVE_TO_POS
)
8258 && IT_CHARPOS (*it
) > to_charpos
8259 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8260 SAVE_IT (ppos_it
, *it
, ppos_data
);
8264 /* The number of glyphs we get back in IT->nglyphs will normally
8265 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8266 character on a terminal frame, or (iii) a line end. For the
8267 second case, IT->nglyphs - 1 padding glyphs will be present.
8268 (On X frames, there is only one glyph produced for a
8269 composite character.)
8271 The behavior implemented below means, for continuation lines,
8272 that as many spaces of a TAB as fit on the current line are
8273 displayed there. For terminal frames, as many glyphs of a
8274 multi-glyph character are displayed in the current line, too.
8275 This is what the old redisplay code did, and we keep it that
8276 way. Under X, the whole shape of a complex character must
8277 fit on the line or it will be completely displayed in the
8280 Note that both for tabs and padding glyphs, all glyphs have
8284 /* More than one glyph or glyph doesn't fit on line. All
8285 glyphs have the same width. */
8286 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8288 int x_before_this_char
= x
;
8289 int hpos_before_this_char
= it
->hpos
;
8291 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8293 new_x
= x
+ single_glyph_width
;
8295 /* We want to leave anything reaching TO_X to the caller. */
8296 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8298 if (BUFFER_POS_REACHED_P ())
8300 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8301 goto buffer_pos_reached
;
8302 if (atpos_it
.sp
< 0)
8304 SAVE_IT (atpos_it
, *it
, atpos_data
);
8305 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8310 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8313 result
= MOVE_X_REACHED
;
8318 SAVE_IT (atx_it
, *it
, atx_data
);
8319 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8324 if (/* Lines are continued. */
8325 it
->line_wrap
!= TRUNCATE
8326 && (/* And glyph doesn't fit on the line. */
8327 new_x
> it
->last_visible_x
8328 /* Or it fits exactly and we're on a window
8330 || (new_x
== it
->last_visible_x
8331 && FRAME_WINDOW_P (it
->f
))))
8333 if (/* IT->hpos == 0 means the very first glyph
8334 doesn't fit on the line, e.g. a wide image. */
8336 || (new_x
== it
->last_visible_x
8337 && FRAME_WINDOW_P (it
->f
)))
8340 it
->current_x
= new_x
;
8342 /* The character's last glyph just barely fits
8344 if (i
== it
->nglyphs
- 1)
8346 /* If this is the destination position,
8347 return a position *before* it in this row,
8348 now that we know it fits in this row. */
8349 if (BUFFER_POS_REACHED_P ())
8351 if (it
->line_wrap
!= WORD_WRAP
8354 it
->hpos
= hpos_before_this_char
;
8355 it
->current_x
= x_before_this_char
;
8356 result
= MOVE_POS_MATCH_OR_ZV
;
8359 if (it
->line_wrap
== WORD_WRAP
8362 SAVE_IT (atpos_it
, *it
, atpos_data
);
8363 atpos_it
.current_x
= x_before_this_char
;
8364 atpos_it
.hpos
= hpos_before_this_char
;
8368 prev_method
= it
->method
;
8369 if (it
->method
== GET_FROM_BUFFER
)
8370 prev_pos
= IT_CHARPOS (*it
);
8371 set_iterator_to_next (it
, 1);
8372 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8373 SET_TEXT_POS (this_line_min_pos
,
8374 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8375 /* On graphical terminals, newlines may
8376 "overflow" into the fringe if
8377 overflow-newline-into-fringe is non-nil.
8378 On text terminals, newlines may overflow
8379 into the last glyph on the display
8381 if (!FRAME_WINDOW_P (it
->f
)
8382 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8384 if (!get_next_display_element (it
))
8386 result
= MOVE_POS_MATCH_OR_ZV
;
8389 if (BUFFER_POS_REACHED_P ())
8391 if (ITERATOR_AT_END_OF_LINE_P (it
))
8392 result
= MOVE_POS_MATCH_OR_ZV
;
8394 result
= MOVE_LINE_CONTINUED
;
8397 if (ITERATOR_AT_END_OF_LINE_P (it
))
8399 result
= MOVE_NEWLINE_OR_CR
;
8406 IT_RESET_X_ASCENT_DESCENT (it
);
8408 if (wrap_it
.sp
>= 0)
8410 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8415 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8417 result
= MOVE_LINE_CONTINUED
;
8421 if (BUFFER_POS_REACHED_P ())
8423 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8424 goto buffer_pos_reached
;
8425 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8427 SAVE_IT (atpos_it
, *it
, atpos_data
);
8428 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8432 if (new_x
> it
->first_visible_x
)
8434 /* Glyph is visible. Increment number of glyphs that
8435 would be displayed. */
8440 if (result
!= MOVE_UNDEFINED
)
8443 else if (BUFFER_POS_REACHED_P ())
8446 IT_RESET_X_ASCENT_DESCENT (it
);
8447 result
= MOVE_POS_MATCH_OR_ZV
;
8450 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8452 /* Stop when TO_X specified and reached. This check is
8453 necessary here because of lines consisting of a line end,
8454 only. The line end will not produce any glyphs and we
8455 would never get MOVE_X_REACHED. */
8456 eassert (it
->nglyphs
== 0);
8457 result
= MOVE_X_REACHED
;
8461 /* Is this a line end? If yes, we're done. */
8462 if (ITERATOR_AT_END_OF_LINE_P (it
))
8464 /* If we are past TO_CHARPOS, but never saw any character
8465 positions smaller than TO_CHARPOS, return
8466 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8468 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8470 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8472 if (IT_CHARPOS (ppos_it
) < ZV
)
8474 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8475 result
= MOVE_POS_MATCH_OR_ZV
;
8478 goto buffer_pos_reached
;
8480 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8481 && IT_CHARPOS (*it
) > to_charpos
)
8482 goto buffer_pos_reached
;
8484 result
= MOVE_NEWLINE_OR_CR
;
8487 result
= MOVE_NEWLINE_OR_CR
;
8491 prev_method
= it
->method
;
8492 if (it
->method
== GET_FROM_BUFFER
)
8493 prev_pos
= IT_CHARPOS (*it
);
8494 /* The current display element has been consumed. Advance
8496 set_iterator_to_next (it
, 1);
8497 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8498 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8499 if (IT_CHARPOS (*it
) < to_charpos
)
8500 saw_smaller_pos
= 1;
8502 && (op
& MOVE_TO_POS
)
8503 && IT_CHARPOS (*it
) >= to_charpos
8504 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8505 SAVE_IT (ppos_it
, *it
, ppos_data
);
8507 /* Stop if lines are truncated and IT's current x-position is
8508 past the right edge of the window now. */
8509 if (it
->line_wrap
== TRUNCATE
8510 && it
->current_x
>= it
->last_visible_x
)
8512 if (!FRAME_WINDOW_P (it
->f
)
8513 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8517 if ((at_eob_p
= !get_next_display_element (it
))
8518 || BUFFER_POS_REACHED_P ()
8519 /* If we are past TO_CHARPOS, but never saw any
8520 character positions smaller than TO_CHARPOS,
8521 return MOVE_POS_MATCH_OR_ZV, like the
8522 unidirectional display did. */
8523 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8525 && IT_CHARPOS (*it
) > to_charpos
))
8528 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8529 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8530 result
= MOVE_POS_MATCH_OR_ZV
;
8533 if (ITERATOR_AT_END_OF_LINE_P (it
))
8535 result
= MOVE_NEWLINE_OR_CR
;
8539 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8541 && IT_CHARPOS (*it
) > to_charpos
)
8543 if (IT_CHARPOS (ppos_it
) < ZV
)
8544 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8545 result
= MOVE_POS_MATCH_OR_ZV
;
8548 result
= MOVE_LINE_TRUNCATED
;
8551 #undef IT_RESET_X_ASCENT_DESCENT
8554 #undef BUFFER_POS_REACHED_P
8556 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8557 restore the saved iterator. */
8558 if (atpos_it
.sp
>= 0)
8559 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8560 else if (atx_it
.sp
>= 0)
8561 RESTORE_IT (it
, &atx_it
, atx_data
);
8566 bidi_unshelve_cache (atpos_data
, 1);
8568 bidi_unshelve_cache (atx_data
, 1);
8570 bidi_unshelve_cache (wrap_data
, 1);
8572 bidi_unshelve_cache (ppos_data
, 1);
8574 /* Restore the iterator settings altered at the beginning of this
8576 it
->glyph_row
= saved_glyph_row
;
8580 /* For external use. */
8582 move_it_in_display_line (struct it
*it
,
8583 ptrdiff_t to_charpos
, int to_x
,
8584 enum move_operation_enum op
)
8586 if (it
->line_wrap
== WORD_WRAP
8587 && (op
& MOVE_TO_X
))
8590 void *save_data
= NULL
;
8593 SAVE_IT (save_it
, *it
, save_data
);
8594 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8595 /* When word-wrap is on, TO_X may lie past the end
8596 of a wrapped line. Then it->current is the
8597 character on the next line, so backtrack to the
8598 space before the wrap point. */
8599 if (skip
== MOVE_LINE_CONTINUED
)
8601 int prev_x
= max (it
->current_x
- 1, 0);
8602 RESTORE_IT (it
, &save_it
, save_data
);
8603 move_it_in_display_line_to
8604 (it
, -1, prev_x
, MOVE_TO_X
);
8607 bidi_unshelve_cache (save_data
, 1);
8610 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8614 /* Move IT forward until it satisfies one or more of the criteria in
8615 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8617 OP is a bit-mask that specifies where to stop, and in particular,
8618 which of those four position arguments makes a difference. See the
8619 description of enum move_operation_enum.
8621 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8622 screen line, this function will set IT to the next position that is
8623 displayed to the right of TO_CHARPOS on the screen. */
8626 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8628 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8629 int line_height
, line_start_x
= 0, reached
= 0;
8630 void *backup_data
= NULL
;
8634 if (op
& MOVE_TO_VPOS
)
8636 /* If no TO_CHARPOS and no TO_X specified, stop at the
8637 start of the line TO_VPOS. */
8638 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8640 if (it
->vpos
== to_vpos
)
8646 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8650 /* TO_VPOS >= 0 means stop at TO_X in the line at
8651 TO_VPOS, or at TO_POS, whichever comes first. */
8652 if (it
->vpos
== to_vpos
)
8658 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8660 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8665 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8667 /* We have reached TO_X but not in the line we want. */
8668 skip
= move_it_in_display_line_to (it
, to_charpos
,
8670 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8678 else if (op
& MOVE_TO_Y
)
8680 struct it it_backup
;
8682 if (it
->line_wrap
== WORD_WRAP
)
8683 SAVE_IT (it_backup
, *it
, backup_data
);
8685 /* TO_Y specified means stop at TO_X in the line containing
8686 TO_Y---or at TO_CHARPOS if this is reached first. The
8687 problem is that we can't really tell whether the line
8688 contains TO_Y before we have completely scanned it, and
8689 this may skip past TO_X. What we do is to first scan to
8692 If TO_X is not specified, use a TO_X of zero. The reason
8693 is to make the outcome of this function more predictable.
8694 If we didn't use TO_X == 0, we would stop at the end of
8695 the line which is probably not what a caller would expect
8697 skip
= move_it_in_display_line_to
8698 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8699 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8701 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8702 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8704 else if (skip
== MOVE_X_REACHED
)
8706 /* If TO_X was reached, we want to know whether TO_Y is
8707 in the line. We know this is the case if the already
8708 scanned glyphs make the line tall enough. Otherwise,
8709 we must check by scanning the rest of the line. */
8710 line_height
= it
->max_ascent
+ it
->max_descent
;
8711 if (to_y
>= it
->current_y
8712 && to_y
< it
->current_y
+ line_height
)
8717 SAVE_IT (it_backup
, *it
, backup_data
);
8718 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8719 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8721 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8722 line_height
= it
->max_ascent
+ it
->max_descent
;
8723 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8725 if (to_y
>= it
->current_y
8726 && to_y
< it
->current_y
+ line_height
)
8728 /* If TO_Y is in this line and TO_X was reached
8729 above, we scanned too far. We have to restore
8730 IT's settings to the ones before skipping. But
8731 keep the more accurate values of max_ascent and
8732 max_descent we've found while skipping the rest
8733 of the line, for the sake of callers, such as
8734 pos_visible_p, that need to know the line
8736 int max_ascent
= it
->max_ascent
;
8737 int max_descent
= it
->max_descent
;
8739 RESTORE_IT (it
, &it_backup
, backup_data
);
8740 it
->max_ascent
= max_ascent
;
8741 it
->max_descent
= max_descent
;
8747 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8753 /* Check whether TO_Y is in this line. */
8754 line_height
= it
->max_ascent
+ it
->max_descent
;
8755 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8757 if (to_y
>= it
->current_y
8758 && to_y
< it
->current_y
+ line_height
)
8760 /* When word-wrap is on, TO_X may lie past the end
8761 of a wrapped line. Then it->current is the
8762 character on the next line, so backtrack to the
8763 space before the wrap point. */
8764 if (skip
== MOVE_LINE_CONTINUED
8765 && it
->line_wrap
== WORD_WRAP
)
8767 int prev_x
= max (it
->current_x
- 1, 0);
8768 RESTORE_IT (it
, &it_backup
, backup_data
);
8769 skip
= move_it_in_display_line_to
8770 (it
, -1, prev_x
, MOVE_TO_X
);
8779 else if (BUFFERP (it
->object
)
8780 && (it
->method
== GET_FROM_BUFFER
8781 || it
->method
== GET_FROM_STRETCH
)
8782 && IT_CHARPOS (*it
) >= to_charpos
8783 /* Under bidi iteration, a call to set_iterator_to_next
8784 can scan far beyond to_charpos if the initial
8785 portion of the next line needs to be reordered. In
8786 that case, give move_it_in_display_line_to another
8789 && it
->bidi_it
.scan_dir
== -1))
8790 skip
= MOVE_POS_MATCH_OR_ZV
;
8792 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8796 case MOVE_POS_MATCH_OR_ZV
:
8800 case MOVE_NEWLINE_OR_CR
:
8801 set_iterator_to_next (it
, 1);
8802 it
->continuation_lines_width
= 0;
8805 case MOVE_LINE_TRUNCATED
:
8806 it
->continuation_lines_width
= 0;
8807 reseat_at_next_visible_line_start (it
, 0);
8808 if ((op
& MOVE_TO_POS
) != 0
8809 && IT_CHARPOS (*it
) > to_charpos
)
8816 case MOVE_LINE_CONTINUED
:
8817 /* For continued lines ending in a tab, some of the glyphs
8818 associated with the tab are displayed on the current
8819 line. Since it->current_x does not include these glyphs,
8820 we use it->last_visible_x instead. */
8823 it
->continuation_lines_width
+= it
->last_visible_x
;
8824 /* When moving by vpos, ensure that the iterator really
8825 advances to the next line (bug#847, bug#969). Fixme:
8826 do we need to do this in other circumstances? */
8827 if (it
->current_x
!= it
->last_visible_x
8828 && (op
& MOVE_TO_VPOS
)
8829 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8831 line_start_x
= it
->current_x
+ it
->pixel_width
8832 - it
->last_visible_x
;
8833 set_iterator_to_next (it
, 0);
8837 it
->continuation_lines_width
+= it
->current_x
;
8844 /* Reset/increment for the next run. */
8845 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8846 it
->current_x
= line_start_x
;
8849 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8851 last_height
= it
->max_ascent
+ it
->max_descent
;
8852 last_max_ascent
= it
->max_ascent
;
8853 it
->max_ascent
= it
->max_descent
= 0;
8858 /* On text terminals, we may stop at the end of a line in the middle
8859 of a multi-character glyph. If the glyph itself is continued,
8860 i.e. it is actually displayed on the next line, don't treat this
8861 stopping point as valid; move to the next line instead (unless
8862 that brings us offscreen). */
8863 if (!FRAME_WINDOW_P (it
->f
)
8865 && IT_CHARPOS (*it
) == to_charpos
8866 && it
->what
== IT_CHARACTER
8868 && it
->line_wrap
== WINDOW_WRAP
8869 && it
->current_x
== it
->last_visible_x
- 1
8872 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8874 it
->continuation_lines_width
+= it
->current_x
;
8875 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8876 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8878 last_height
= it
->max_ascent
+ it
->max_descent
;
8879 last_max_ascent
= it
->max_ascent
;
8883 bidi_unshelve_cache (backup_data
, 1);
8885 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8889 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8891 If DY > 0, move IT backward at least that many pixels. DY = 0
8892 means move IT backward to the preceding line start or BEGV. This
8893 function may move over more than DY pixels if IT->current_y - DY
8894 ends up in the middle of a line; in this case IT->current_y will be
8895 set to the top of the line moved to. */
8898 move_it_vertically_backward (struct it
*it
, int dy
)
8902 void *it2data
= NULL
, *it3data
= NULL
;
8903 ptrdiff_t start_pos
;
8908 start_pos
= IT_CHARPOS (*it
);
8910 /* Estimate how many newlines we must move back. */
8911 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8913 /* Set the iterator's position that many lines back. */
8914 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8915 back_to_previous_visible_line_start (it
);
8917 /* Reseat the iterator here. When moving backward, we don't want
8918 reseat to skip forward over invisible text, set up the iterator
8919 to deliver from overlay strings at the new position etc. So,
8920 use reseat_1 here. */
8921 reseat_1 (it
, it
->current
.pos
, 1);
8923 /* We are now surely at a line start. */
8924 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8925 reordering is in effect. */
8926 it
->continuation_lines_width
= 0;
8928 /* Move forward and see what y-distance we moved. First move to the
8929 start of the next line so that we get its height. We need this
8930 height to be able to tell whether we reached the specified
8932 SAVE_IT (it2
, *it
, it2data
);
8933 it2
.max_ascent
= it2
.max_descent
= 0;
8936 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8937 MOVE_TO_POS
| MOVE_TO_VPOS
);
8939 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8940 /* If we are in a display string which starts at START_POS,
8941 and that display string includes a newline, and we are
8942 right after that newline (i.e. at the beginning of a
8943 display line), exit the loop, because otherwise we will
8944 infloop, since move_it_to will see that it is already at
8945 START_POS and will not move. */
8946 || (it2
.method
== GET_FROM_STRING
8947 && IT_CHARPOS (it2
) == start_pos
8948 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8949 eassert (IT_CHARPOS (*it
) >= BEGV
);
8950 SAVE_IT (it3
, it2
, it3data
);
8952 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8953 eassert (IT_CHARPOS (*it
) >= BEGV
);
8954 /* H is the actual vertical distance from the position in *IT
8955 and the starting position. */
8956 h
= it2
.current_y
- it
->current_y
;
8957 /* NLINES is the distance in number of lines. */
8958 nlines
= it2
.vpos
- it
->vpos
;
8960 /* Correct IT's y and vpos position
8961 so that they are relative to the starting point. */
8967 /* DY == 0 means move to the start of the screen line. The
8968 value of nlines is > 0 if continuation lines were involved,
8969 or if the original IT position was at start of a line. */
8970 RESTORE_IT (it
, it
, it2data
);
8972 move_it_by_lines (it
, nlines
);
8973 /* The above code moves us to some position NLINES down,
8974 usually to its first glyph (leftmost in an L2R line), but
8975 that's not necessarily the start of the line, under bidi
8976 reordering. We want to get to the character position
8977 that is immediately after the newline of the previous
8980 && !it
->continuation_lines_width
8981 && !STRINGP (it
->string
)
8982 && IT_CHARPOS (*it
) > BEGV
8983 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8986 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8988 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8990 bidi_unshelve_cache (it3data
, 1);
8994 /* The y-position we try to reach, relative to *IT.
8995 Note that H has been subtracted in front of the if-statement. */
8996 int target_y
= it
->current_y
+ h
- dy
;
8997 int y0
= it3
.current_y
;
9001 RESTORE_IT (&it3
, &it3
, it3data
);
9002 y1
= line_bottom_y (&it3
);
9003 line_height
= y1
- y0
;
9004 RESTORE_IT (it
, it
, it2data
);
9005 /* If we did not reach target_y, try to move further backward if
9006 we can. If we moved too far backward, try to move forward. */
9007 if (target_y
< it
->current_y
9008 /* This is heuristic. In a window that's 3 lines high, with
9009 a line height of 13 pixels each, recentering with point
9010 on the bottom line will try to move -39/2 = 19 pixels
9011 backward. Try to avoid moving into the first line. */
9012 && (it
->current_y
- target_y
9013 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9014 && IT_CHARPOS (*it
) > BEGV
)
9016 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9017 target_y
- it
->current_y
));
9018 dy
= it
->current_y
- target_y
;
9019 goto move_further_back
;
9021 else if (target_y
>= it
->current_y
+ line_height
9022 && IT_CHARPOS (*it
) < ZV
)
9024 /* Should move forward by at least one line, maybe more.
9026 Note: Calling move_it_by_lines can be expensive on
9027 terminal frames, where compute_motion is used (via
9028 vmotion) to do the job, when there are very long lines
9029 and truncate-lines is nil. That's the reason for
9030 treating terminal frames specially here. */
9032 if (!FRAME_WINDOW_P (it
->f
))
9033 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9038 move_it_by_lines (it
, 1);
9040 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9047 /* Move IT by a specified amount of pixel lines DY. DY negative means
9048 move backwards. DY = 0 means move to start of screen line. At the
9049 end, IT will be on the start of a screen line. */
9052 move_it_vertically (struct it
*it
, int dy
)
9055 move_it_vertically_backward (it
, -dy
);
9058 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9059 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9060 MOVE_TO_POS
| MOVE_TO_Y
);
9061 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9063 /* If buffer ends in ZV without a newline, move to the start of
9064 the line to satisfy the post-condition. */
9065 if (IT_CHARPOS (*it
) == ZV
9067 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9068 move_it_by_lines (it
, 0);
9073 /* Move iterator IT past the end of the text line it is in. */
9076 move_it_past_eol (struct it
*it
)
9078 enum move_it_result rc
;
9080 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9081 if (rc
== MOVE_NEWLINE_OR_CR
)
9082 set_iterator_to_next (it
, 0);
9086 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9087 negative means move up. DVPOS == 0 means move to the start of the
9090 Optimization idea: If we would know that IT->f doesn't use
9091 a face with proportional font, we could be faster for
9092 truncate-lines nil. */
9095 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9098 /* The commented-out optimization uses vmotion on terminals. This
9099 gives bad results, because elements like it->what, on which
9100 callers such as pos_visible_p rely, aren't updated. */
9101 /* struct position pos;
9102 if (!FRAME_WINDOW_P (it->f))
9104 struct text_pos textpos;
9106 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9107 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9108 reseat (it, textpos, 1);
9109 it->vpos += pos.vpos;
9110 it->current_y += pos.vpos;
9116 /* DVPOS == 0 means move to the start of the screen line. */
9117 move_it_vertically_backward (it
, 0);
9118 /* Let next call to line_bottom_y calculate real line height */
9123 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9124 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9126 /* Only move to the next buffer position if we ended up in a
9127 string from display property, not in an overlay string
9128 (before-string or after-string). That is because the
9129 latter don't conceal the underlying buffer position, so
9130 we can ask to move the iterator to the exact position we
9131 are interested in. Note that, even if we are already at
9132 IT_CHARPOS (*it), the call below is not a no-op, as it
9133 will detect that we are at the end of the string, pop the
9134 iterator, and compute it->current_x and it->hpos
9136 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9137 -1, -1, -1, MOVE_TO_POS
);
9143 void *it2data
= NULL
;
9144 ptrdiff_t start_charpos
, i
;
9146 /* Start at the beginning of the screen line containing IT's
9147 position. This may actually move vertically backwards,
9148 in case of overlays, so adjust dvpos accordingly. */
9150 move_it_vertically_backward (it
, 0);
9153 /* Go back -DVPOS visible lines and reseat the iterator there. */
9154 start_charpos
= IT_CHARPOS (*it
);
9155 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9156 back_to_previous_visible_line_start (it
);
9157 reseat (it
, it
->current
.pos
, 1);
9159 /* Move further back if we end up in a string or an image. */
9160 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9162 /* First try to move to start of display line. */
9164 move_it_vertically_backward (it
, 0);
9166 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9168 /* If start of line is still in string or image,
9169 move further back. */
9170 back_to_previous_visible_line_start (it
);
9171 reseat (it
, it
->current
.pos
, 1);
9175 it
->current_x
= it
->hpos
= 0;
9177 /* Above call may have moved too far if continuation lines
9178 are involved. Scan forward and see if it did. */
9179 SAVE_IT (it2
, *it
, it2data
);
9180 it2
.vpos
= it2
.current_y
= 0;
9181 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9182 it
->vpos
-= it2
.vpos
;
9183 it
->current_y
-= it2
.current_y
;
9184 it
->current_x
= it
->hpos
= 0;
9186 /* If we moved too far back, move IT some lines forward. */
9187 if (it2
.vpos
> -dvpos
)
9189 int delta
= it2
.vpos
+ dvpos
;
9191 RESTORE_IT (&it2
, &it2
, it2data
);
9192 SAVE_IT (it2
, *it
, it2data
);
9193 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9194 /* Move back again if we got too far ahead. */
9195 if (IT_CHARPOS (*it
) >= start_charpos
)
9196 RESTORE_IT (it
, &it2
, it2data
);
9198 bidi_unshelve_cache (it2data
, 1);
9201 RESTORE_IT (it
, it
, it2data
);
9205 /* Return 1 if IT points into the middle of a display vector. */
9208 in_display_vector_p (struct it
*it
)
9210 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9211 && it
->current
.dpvec_index
> 0
9212 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9216 /***********************************************************************
9218 ***********************************************************************/
9221 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9225 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9227 Lisp_Object args
[3];
9228 Lisp_Object msg
, fmt
;
9231 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9234 /* Do nothing if called asynchronously. Inserting text into
9235 a buffer may call after-change-functions and alike and
9236 that would means running Lisp asynchronously. */
9237 if (handling_signal
)
9241 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9243 args
[0] = fmt
= build_string (format
);
9246 msg
= Fformat (3, args
);
9248 len
= SBYTES (msg
) + 1;
9249 SAFE_ALLOCA (buffer
, char *, len
);
9250 memcpy (buffer
, SDATA (msg
), len
);
9252 message_dolog (buffer
, len
- 1, 1, 0);
9259 /* Output a newline in the *Messages* buffer if "needs" one. */
9262 message_log_maybe_newline (void)
9264 if (message_log_need_newline
)
9265 message_dolog ("", 0, 1, 0);
9269 /* Add a string M of length NBYTES to the message log, optionally
9270 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9271 nonzero, means interpret the contents of M as multibyte. This
9272 function calls low-level routines in order to bypass text property
9273 hooks, etc. which might not be safe to run.
9275 This may GC (insert may run before/after change hooks),
9276 so the buffer M must NOT point to a Lisp string. */
9279 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9281 const unsigned char *msg
= (const unsigned char *) m
;
9283 if (!NILP (Vmemory_full
))
9286 if (!NILP (Vmessage_log_max
))
9288 struct buffer
*oldbuf
;
9289 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9290 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9291 ptrdiff_t point_at_end
= 0;
9292 ptrdiff_t zv_at_end
= 0;
9293 Lisp_Object old_deactivate_mark
, tem
;
9294 struct gcpro gcpro1
;
9296 old_deactivate_mark
= Vdeactivate_mark
;
9297 oldbuf
= current_buffer
;
9298 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9299 BVAR (current_buffer
, undo_list
) = Qt
;
9301 oldpoint
= message_dolog_marker1
;
9302 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9303 oldbegv
= message_dolog_marker2
;
9304 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9305 oldzv
= message_dolog_marker3
;
9306 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9307 GCPRO1 (old_deactivate_mark
);
9315 BEGV_BYTE
= BEG_BYTE
;
9318 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9320 /* Insert the string--maybe converting multibyte to single byte
9321 or vice versa, so that all the text fits the buffer. */
9323 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9329 /* Convert a multibyte string to single-byte
9330 for the *Message* buffer. */
9331 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9333 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9334 work
[0] = (ASCII_CHAR_P (c
)
9336 : multibyte_char_to_unibyte (c
));
9337 insert_1_both (work
, 1, 1, 1, 0, 0);
9340 else if (! multibyte
9341 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9345 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9346 /* Convert a single-byte string to multibyte
9347 for the *Message* buffer. */
9348 for (i
= 0; i
< nbytes
; i
++)
9351 MAKE_CHAR_MULTIBYTE (c
);
9352 char_bytes
= CHAR_STRING (c
, str
);
9353 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9357 insert_1 (m
, nbytes
, 1, 0, 0);
9361 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9363 insert_1 ("\n", 1, 1, 0, 0);
9365 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9367 this_bol_byte
= PT_BYTE
;
9369 /* See if this line duplicates the previous one.
9370 If so, combine duplicates. */
9373 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9375 prev_bol_byte
= PT_BYTE
;
9377 dups
= message_log_check_duplicate (prev_bol_byte
,
9381 del_range_both (prev_bol
, prev_bol_byte
,
9382 this_bol
, this_bol_byte
, 0);
9385 char dupstr
[sizeof " [ times]"
9386 + INT_STRLEN_BOUND (printmax_t
)];
9388 /* If you change this format, don't forget to also
9389 change message_log_check_duplicate. */
9390 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9391 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9392 insert_1 (dupstr
, duplen
, 1, 0, 1);
9397 /* If we have more than the desired maximum number of lines
9398 in the *Messages* buffer now, delete the oldest ones.
9399 This is safe because we don't have undo in this buffer. */
9401 if (NATNUMP (Vmessage_log_max
))
9403 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9404 -XFASTINT (Vmessage_log_max
) - 1, 0);
9405 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9408 BEGV
= XMARKER (oldbegv
)->charpos
;
9409 BEGV_BYTE
= marker_byte_position (oldbegv
);
9418 ZV
= XMARKER (oldzv
)->charpos
;
9419 ZV_BYTE
= marker_byte_position (oldzv
);
9423 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9425 /* We can't do Fgoto_char (oldpoint) because it will run some
9427 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9428 XMARKER (oldpoint
)->bytepos
);
9431 unchain_marker (XMARKER (oldpoint
));
9432 unchain_marker (XMARKER (oldbegv
));
9433 unchain_marker (XMARKER (oldzv
));
9435 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9436 set_buffer_internal (oldbuf
);
9438 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9439 message_log_need_newline
= !nlflag
;
9440 Vdeactivate_mark
= old_deactivate_mark
;
9445 /* We are at the end of the buffer after just having inserted a newline.
9446 (Note: We depend on the fact we won't be crossing the gap.)
9447 Check to see if the most recent message looks a lot like the previous one.
9448 Return 0 if different, 1 if the new one should just replace it, or a
9449 value N > 1 if we should also append " [N times]". */
9452 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9455 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9457 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9458 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9460 for (i
= 0; i
< len
; i
++)
9462 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9470 if (*p1
++ == ' ' && *p1
++ == '[')
9473 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9474 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9481 /* Display an echo area message M with a specified length of NBYTES
9482 bytes. The string may include null characters. If M is 0, clear
9483 out any existing message, and let the mini-buffer text show
9486 This may GC, so the buffer M must NOT point to a Lisp string. */
9489 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9491 /* First flush out any partial line written with print. */
9492 message_log_maybe_newline ();
9494 message_dolog (m
, nbytes
, 1, multibyte
);
9495 message2_nolog (m
, nbytes
, multibyte
);
9499 /* The non-logging counterpart of message2. */
9502 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9504 struct frame
*sf
= SELECTED_FRAME ();
9505 message_enable_multibyte
= multibyte
;
9507 if (FRAME_INITIAL_P (sf
))
9509 if (noninteractive_need_newline
)
9510 putc ('\n', stderr
);
9511 noninteractive_need_newline
= 0;
9513 fwrite (m
, nbytes
, 1, stderr
);
9514 if (cursor_in_echo_area
== 0)
9515 fprintf (stderr
, "\n");
9518 /* A null message buffer means that the frame hasn't really been
9519 initialized yet. Error messages get reported properly by
9520 cmd_error, so this must be just an informative message; toss it. */
9521 else if (INTERACTIVE
9522 && sf
->glyphs_initialized_p
9523 && FRAME_MESSAGE_BUF (sf
))
9525 Lisp_Object mini_window
;
9528 /* Get the frame containing the mini-buffer
9529 that the selected frame is using. */
9530 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9531 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9533 FRAME_SAMPLE_VISIBILITY (f
);
9534 if (FRAME_VISIBLE_P (sf
)
9535 && ! FRAME_VISIBLE_P (f
))
9536 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9540 set_message (m
, Qnil
, nbytes
, multibyte
);
9541 if (minibuffer_auto_raise
)
9542 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9545 clear_message (1, 1);
9547 do_pending_window_change (0);
9548 echo_area_display (1);
9549 do_pending_window_change (0);
9550 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9551 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9556 /* Display an echo area message M with a specified length of NBYTES
9557 bytes. The string may include null characters. If M is not a
9558 string, clear out any existing message, and let the mini-buffer
9561 This function cancels echoing. */
9564 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9566 struct gcpro gcpro1
;
9569 clear_message (1,1);
9572 /* First flush out any partial line written with print. */
9573 message_log_maybe_newline ();
9579 SAFE_ALLOCA (buffer
, char *, nbytes
);
9580 memcpy (buffer
, SDATA (m
), nbytes
);
9581 message_dolog (buffer
, nbytes
, 1, multibyte
);
9584 message3_nolog (m
, nbytes
, multibyte
);
9590 /* The non-logging version of message3.
9591 This does not cancel echoing, because it is used for echoing.
9592 Perhaps we need to make a separate function for echoing
9593 and make this cancel echoing. */
9596 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9598 struct frame
*sf
= SELECTED_FRAME ();
9599 message_enable_multibyte
= multibyte
;
9601 if (FRAME_INITIAL_P (sf
))
9603 if (noninteractive_need_newline
)
9604 putc ('\n', stderr
);
9605 noninteractive_need_newline
= 0;
9607 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9608 if (cursor_in_echo_area
== 0)
9609 fprintf (stderr
, "\n");
9612 /* A null message buffer means that the frame hasn't really been
9613 initialized yet. Error messages get reported properly by
9614 cmd_error, so this must be just an informative message; toss it. */
9615 else if (INTERACTIVE
9616 && sf
->glyphs_initialized_p
9617 && FRAME_MESSAGE_BUF (sf
))
9619 Lisp_Object mini_window
;
9623 /* Get the frame containing the mini-buffer
9624 that the selected frame is using. */
9625 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9626 frame
= XWINDOW (mini_window
)->frame
;
9629 FRAME_SAMPLE_VISIBILITY (f
);
9630 if (FRAME_VISIBLE_P (sf
)
9631 && !FRAME_VISIBLE_P (f
))
9632 Fmake_frame_visible (frame
);
9634 if (STRINGP (m
) && SCHARS (m
) > 0)
9636 set_message (NULL
, m
, nbytes
, multibyte
);
9637 if (minibuffer_auto_raise
)
9638 Fraise_frame (frame
);
9639 /* Assume we are not echoing.
9640 (If we are, echo_now will override this.) */
9641 echo_message_buffer
= Qnil
;
9644 clear_message (1, 1);
9646 do_pending_window_change (0);
9647 echo_area_display (1);
9648 do_pending_window_change (0);
9649 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9650 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9655 /* Display a null-terminated echo area message M. If M is 0, clear
9656 out any existing message, and let the mini-buffer text show through.
9658 The buffer M must continue to exist until after the echo area gets
9659 cleared or some other message gets displayed there. Do not pass
9660 text that is stored in a Lisp string. Do not pass text in a buffer
9661 that was alloca'd. */
9664 message1 (const char *m
)
9666 message2 (m
, (m
? strlen (m
) : 0), 0);
9670 /* The non-logging counterpart of message1. */
9673 message1_nolog (const char *m
)
9675 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9678 /* Display a message M which contains a single %s
9679 which gets replaced with STRING. */
9682 message_with_string (const char *m
, Lisp_Object string
, int log
)
9684 CHECK_STRING (string
);
9690 if (noninteractive_need_newline
)
9691 putc ('\n', stderr
);
9692 noninteractive_need_newline
= 0;
9693 fprintf (stderr
, m
, SDATA (string
));
9694 if (!cursor_in_echo_area
)
9695 fprintf (stderr
, "\n");
9699 else if (INTERACTIVE
)
9701 /* The frame whose minibuffer we're going to display the message on.
9702 It may be larger than the selected frame, so we need
9703 to use its buffer, not the selected frame's buffer. */
9704 Lisp_Object mini_window
;
9705 struct frame
*f
, *sf
= SELECTED_FRAME ();
9707 /* Get the frame containing the minibuffer
9708 that the selected frame is using. */
9709 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9710 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9712 /* A null message buffer means that the frame hasn't really been
9713 initialized yet. Error messages get reported properly by
9714 cmd_error, so this must be just an informative message; toss it. */
9715 if (FRAME_MESSAGE_BUF (f
))
9717 Lisp_Object args
[2], msg
;
9718 struct gcpro gcpro1
, gcpro2
;
9720 args
[0] = build_string (m
);
9721 args
[1] = msg
= string
;
9722 GCPRO2 (args
[0], msg
);
9725 msg
= Fformat (2, args
);
9728 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9730 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9734 /* Print should start at the beginning of the message
9735 buffer next time. */
9736 message_buf_print
= 0;
9742 /* Dump an informative message to the minibuf. If M is 0, clear out
9743 any existing message, and let the mini-buffer text show through. */
9746 vmessage (const char *m
, va_list ap
)
9752 if (noninteractive_need_newline
)
9753 putc ('\n', stderr
);
9754 noninteractive_need_newline
= 0;
9755 vfprintf (stderr
, m
, ap
);
9756 if (cursor_in_echo_area
== 0)
9757 fprintf (stderr
, "\n");
9761 else if (INTERACTIVE
)
9763 /* The frame whose mini-buffer we're going to display the message
9764 on. It may be larger than the selected frame, so we need to
9765 use its buffer, not the selected frame's buffer. */
9766 Lisp_Object mini_window
;
9767 struct frame
*f
, *sf
= SELECTED_FRAME ();
9769 /* Get the frame containing the mini-buffer
9770 that the selected frame is using. */
9771 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9772 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9774 /* A null message buffer means that the frame hasn't really been
9775 initialized yet. Error messages get reported properly by
9776 cmd_error, so this must be just an informative message; toss
9778 if (FRAME_MESSAGE_BUF (f
))
9784 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9785 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9787 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9792 /* Print should start at the beginning of the message
9793 buffer next time. */
9794 message_buf_print
= 0;
9800 message (const char *m
, ...)
9810 /* The non-logging version of message. */
9813 message_nolog (const char *m
, ...)
9815 Lisp_Object old_log_max
;
9818 old_log_max
= Vmessage_log_max
;
9819 Vmessage_log_max
= Qnil
;
9821 Vmessage_log_max
= old_log_max
;
9827 /* Display the current message in the current mini-buffer. This is
9828 only called from error handlers in process.c, and is not time
9832 update_echo_area (void)
9834 if (!NILP (echo_area_buffer
[0]))
9837 string
= Fcurrent_message ();
9838 message3 (string
, SBYTES (string
),
9839 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9844 /* Make sure echo area buffers in `echo_buffers' are live.
9845 If they aren't, make new ones. */
9848 ensure_echo_area_buffers (void)
9852 for (i
= 0; i
< 2; ++i
)
9853 if (!BUFFERP (echo_buffer
[i
])
9854 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9857 Lisp_Object old_buffer
;
9860 old_buffer
= echo_buffer
[i
];
9861 sprintf (name
, " *Echo Area %d*", i
);
9862 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9863 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9864 /* to force word wrap in echo area -
9865 it was decided to postpone this*/
9866 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9868 for (j
= 0; j
< 2; ++j
)
9869 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9870 echo_area_buffer
[j
] = echo_buffer
[i
];
9875 /* Call FN with args A1..A4 with either the current or last displayed
9876 echo_area_buffer as current buffer.
9878 WHICH zero means use the current message buffer
9879 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9880 from echo_buffer[] and clear it.
9882 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9883 suitable buffer from echo_buffer[] and clear it.
9885 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9886 that the current message becomes the last displayed one, make
9887 choose a suitable buffer for echo_area_buffer[0], and clear it.
9889 Value is what FN returns. */
9892 with_echo_area_buffer (struct window
*w
, int which
,
9893 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9894 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9897 int this_one
, the_other
, clear_buffer_p
, rc
;
9898 ptrdiff_t count
= SPECPDL_INDEX ();
9900 /* If buffers aren't live, make new ones. */
9901 ensure_echo_area_buffers ();
9906 this_one
= 0, the_other
= 1;
9908 this_one
= 1, the_other
= 0;
9911 this_one
= 0, the_other
= 1;
9914 /* We need a fresh one in case the current echo buffer equals
9915 the one containing the last displayed echo area message. */
9916 if (!NILP (echo_area_buffer
[this_one
])
9917 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9918 echo_area_buffer
[this_one
] = Qnil
;
9921 /* Choose a suitable buffer from echo_buffer[] is we don't
9923 if (NILP (echo_area_buffer
[this_one
]))
9925 echo_area_buffer
[this_one
]
9926 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9927 ? echo_buffer
[the_other
]
9928 : echo_buffer
[this_one
]);
9932 buffer
= echo_area_buffer
[this_one
];
9934 /* Don't get confused by reusing the buffer used for echoing
9935 for a different purpose. */
9936 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9939 record_unwind_protect (unwind_with_echo_area_buffer
,
9940 with_echo_area_buffer_unwind_data (w
));
9942 /* Make the echo area buffer current. Note that for display
9943 purposes, it is not necessary that the displayed window's buffer
9944 == current_buffer, except for text property lookup. So, let's
9945 only set that buffer temporarily here without doing a full
9946 Fset_window_buffer. We must also change w->pointm, though,
9947 because otherwise an assertions in unshow_buffer fails, and Emacs
9949 set_buffer_internal_1 (XBUFFER (buffer
));
9953 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9956 BVAR (current_buffer
, undo_list
) = Qt
;
9957 BVAR (current_buffer
, read_only
) = Qnil
;
9958 specbind (Qinhibit_read_only
, Qt
);
9959 specbind (Qinhibit_modification_hooks
, Qt
);
9961 if (clear_buffer_p
&& Z
> BEG
)
9964 eassert (BEGV
>= BEG
);
9965 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9967 rc
= fn (a1
, a2
, a3
, a4
);
9969 eassert (BEGV
>= BEG
);
9970 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9972 unbind_to (count
, Qnil
);
9977 /* Save state that should be preserved around the call to the function
9978 FN called in with_echo_area_buffer. */
9981 with_echo_area_buffer_unwind_data (struct window
*w
)
9984 Lisp_Object vector
, tmp
;
9986 /* Reduce consing by keeping one vector in
9987 Vwith_echo_area_save_vector. */
9988 vector
= Vwith_echo_area_save_vector
;
9989 Vwith_echo_area_save_vector
= Qnil
;
9992 vector
= Fmake_vector (make_number (7), Qnil
);
9994 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9995 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9996 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10000 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10001 ASET (vector
, i
, w
->buffer
); ++i
;
10002 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
10003 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
10008 for (; i
< end
; ++i
)
10009 ASET (vector
, i
, Qnil
);
10012 eassert (i
== ASIZE (vector
));
10017 /* Restore global state from VECTOR which was created by
10018 with_echo_area_buffer_unwind_data. */
10021 unwind_with_echo_area_buffer (Lisp_Object vector
)
10023 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10024 Vdeactivate_mark
= AREF (vector
, 1);
10025 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10027 if (WINDOWP (AREF (vector
, 3)))
10030 Lisp_Object buffer
, charpos
, bytepos
;
10032 w
= XWINDOW (AREF (vector
, 3));
10033 buffer
= AREF (vector
, 4);
10034 charpos
= AREF (vector
, 5);
10035 bytepos
= AREF (vector
, 6);
10037 w
->buffer
= buffer
;
10038 set_marker_both (w
->pointm
, buffer
,
10039 XFASTINT (charpos
), XFASTINT (bytepos
));
10042 Vwith_echo_area_save_vector
= vector
;
10047 /* Set up the echo area for use by print functions. MULTIBYTE_P
10048 non-zero means we will print multibyte. */
10051 setup_echo_area_for_printing (int multibyte_p
)
10053 /* If we can't find an echo area any more, exit. */
10054 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10055 Fkill_emacs (Qnil
);
10057 ensure_echo_area_buffers ();
10059 if (!message_buf_print
)
10061 /* A message has been output since the last time we printed.
10062 Choose a fresh echo area buffer. */
10063 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10064 echo_area_buffer
[0] = echo_buffer
[1];
10066 echo_area_buffer
[0] = echo_buffer
[0];
10068 /* Switch to that buffer and clear it. */
10069 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10070 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10074 ptrdiff_t count
= SPECPDL_INDEX ();
10075 specbind (Qinhibit_read_only
, Qt
);
10076 /* Note that undo recording is always disabled. */
10077 del_range (BEG
, Z
);
10078 unbind_to (count
, Qnil
);
10080 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10082 /* Set up the buffer for the multibyteness we need. */
10084 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10085 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10087 /* Raise the frame containing the echo area. */
10088 if (minibuffer_auto_raise
)
10090 struct frame
*sf
= SELECTED_FRAME ();
10091 Lisp_Object mini_window
;
10092 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10093 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10096 message_log_maybe_newline ();
10097 message_buf_print
= 1;
10101 if (NILP (echo_area_buffer
[0]))
10103 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10104 echo_area_buffer
[0] = echo_buffer
[1];
10106 echo_area_buffer
[0] = echo_buffer
[0];
10109 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10111 /* Someone switched buffers between print requests. */
10112 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10113 BVAR (current_buffer
, truncate_lines
) = Qnil
;
10119 /* Display an echo area message in window W. Value is non-zero if W's
10120 height is changed. If display_last_displayed_message_p is
10121 non-zero, display the message that was last displayed, otherwise
10122 display the current message. */
10125 display_echo_area (struct window
*w
)
10127 int i
, no_message_p
, window_height_changed_p
;
10129 /* Temporarily disable garbage collections while displaying the echo
10130 area. This is done because a GC can print a message itself.
10131 That message would modify the echo area buffer's contents while a
10132 redisplay of the buffer is going on, and seriously confuse
10134 ptrdiff_t count
= inhibit_garbage_collection ();
10136 /* If there is no message, we must call display_echo_area_1
10137 nevertheless because it resizes the window. But we will have to
10138 reset the echo_area_buffer in question to nil at the end because
10139 with_echo_area_buffer will sets it to an empty buffer. */
10140 i
= display_last_displayed_message_p
? 1 : 0;
10141 no_message_p
= NILP (echo_area_buffer
[i
]);
10143 window_height_changed_p
10144 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10145 display_echo_area_1
,
10146 (intptr_t) w
, Qnil
, 0, 0);
10149 echo_area_buffer
[i
] = Qnil
;
10151 unbind_to (count
, Qnil
);
10152 return window_height_changed_p
;
10156 /* Helper for display_echo_area. Display the current buffer which
10157 contains the current echo area message in window W, a mini-window,
10158 a pointer to which is passed in A1. A2..A4 are currently not used.
10159 Change the height of W so that all of the message is displayed.
10160 Value is non-zero if height of W was changed. */
10163 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10166 struct window
*w
= (struct window
*) i1
;
10167 Lisp_Object window
;
10168 struct text_pos start
;
10169 int window_height_changed_p
= 0;
10171 /* Do this before displaying, so that we have a large enough glyph
10172 matrix for the display. If we can't get enough space for the
10173 whole text, display the last N lines. That works by setting w->start. */
10174 window_height_changed_p
= resize_mini_window (w
, 0);
10176 /* Use the starting position chosen by resize_mini_window. */
10177 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10180 clear_glyph_matrix (w
->desired_matrix
);
10181 XSETWINDOW (window
, w
);
10182 try_window (window
, start
, 0);
10184 return window_height_changed_p
;
10188 /* Resize the echo area window to exactly the size needed for the
10189 currently displayed message, if there is one. If a mini-buffer
10190 is active, don't shrink it. */
10193 resize_echo_area_exactly (void)
10195 if (BUFFERP (echo_area_buffer
[0])
10196 && WINDOWP (echo_area_window
))
10198 struct window
*w
= XWINDOW (echo_area_window
);
10200 Lisp_Object resize_exactly
;
10202 if (minibuf_level
== 0)
10203 resize_exactly
= Qt
;
10205 resize_exactly
= Qnil
;
10207 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10208 (intptr_t) w
, resize_exactly
,
10212 ++windows_or_buffers_changed
;
10213 ++update_mode_lines
;
10214 redisplay_internal ();
10220 /* Callback function for with_echo_area_buffer, when used from
10221 resize_echo_area_exactly. A1 contains a pointer to the window to
10222 resize, EXACTLY non-nil means resize the mini-window exactly to the
10223 size of the text displayed. A3 and A4 are not used. Value is what
10224 resize_mini_window returns. */
10227 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10230 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10234 /* Resize mini-window W to fit the size of its contents. EXACT_P
10235 means size the window exactly to the size needed. Otherwise, it's
10236 only enlarged until W's buffer is empty.
10238 Set W->start to the right place to begin display. If the whole
10239 contents fit, start at the beginning. Otherwise, start so as
10240 to make the end of the contents appear. This is particularly
10241 important for y-or-n-p, but seems desirable generally.
10243 Value is non-zero if the window height has been changed. */
10246 resize_mini_window (struct window
*w
, int exact_p
)
10248 struct frame
*f
= XFRAME (w
->frame
);
10249 int window_height_changed_p
= 0;
10251 eassert (MINI_WINDOW_P (w
));
10253 /* By default, start display at the beginning. */
10254 set_marker_both (w
->start
, w
->buffer
,
10255 BUF_BEGV (XBUFFER (w
->buffer
)),
10256 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10258 /* Don't resize windows while redisplaying a window; it would
10259 confuse redisplay functions when the size of the window they are
10260 displaying changes from under them. Such a resizing can happen,
10261 for instance, when which-func prints a long message while
10262 we are running fontification-functions. We're running these
10263 functions with safe_call which binds inhibit-redisplay to t. */
10264 if (!NILP (Vinhibit_redisplay
))
10267 /* Nil means don't try to resize. */
10268 if (NILP (Vresize_mini_windows
)
10269 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10272 if (!FRAME_MINIBUF_ONLY_P (f
))
10275 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10276 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10278 EMACS_INT max_height
;
10279 int unit
= FRAME_LINE_HEIGHT (f
);
10280 struct text_pos start
;
10281 struct buffer
*old_current_buffer
= NULL
;
10283 if (current_buffer
!= XBUFFER (w
->buffer
))
10285 old_current_buffer
= current_buffer
;
10286 set_buffer_internal (XBUFFER (w
->buffer
));
10289 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10291 /* Compute the max. number of lines specified by the user. */
10292 if (FLOATP (Vmax_mini_window_height
))
10293 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10294 else if (INTEGERP (Vmax_mini_window_height
))
10295 max_height
= XINT (Vmax_mini_window_height
);
10297 max_height
= total_height
/ 4;
10299 /* Correct that max. height if it's bogus. */
10300 max_height
= max (1, max_height
);
10301 max_height
= min (total_height
, max_height
);
10303 /* Find out the height of the text in the window. */
10304 if (it
.line_wrap
== TRUNCATE
)
10309 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10310 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10311 height
= it
.current_y
+ last_height
;
10313 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10314 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10315 height
= (height
+ unit
- 1) / unit
;
10318 /* Compute a suitable window start. */
10319 if (height
> max_height
)
10321 height
= max_height
;
10322 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10323 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10324 start
= it
.current
.pos
;
10327 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10328 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10330 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10332 /* Let it grow only, until we display an empty message, in which
10333 case the window shrinks again. */
10334 if (height
> WINDOW_TOTAL_LINES (w
))
10336 int old_height
= WINDOW_TOTAL_LINES (w
);
10337 freeze_window_starts (f
, 1);
10338 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10339 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10341 else if (height
< WINDOW_TOTAL_LINES (w
)
10342 && (exact_p
|| BEGV
== ZV
))
10344 int old_height
= WINDOW_TOTAL_LINES (w
);
10345 freeze_window_starts (f
, 0);
10346 shrink_mini_window (w
);
10347 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10352 /* Always resize to exact size needed. */
10353 if (height
> WINDOW_TOTAL_LINES (w
))
10355 int old_height
= WINDOW_TOTAL_LINES (w
);
10356 freeze_window_starts (f
, 1);
10357 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10358 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10360 else if (height
< WINDOW_TOTAL_LINES (w
))
10362 int old_height
= WINDOW_TOTAL_LINES (w
);
10363 freeze_window_starts (f
, 0);
10364 shrink_mini_window (w
);
10368 freeze_window_starts (f
, 1);
10369 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10372 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10376 if (old_current_buffer
)
10377 set_buffer_internal (old_current_buffer
);
10380 return window_height_changed_p
;
10384 /* Value is the current message, a string, or nil if there is no
10385 current message. */
10388 current_message (void)
10392 if (!BUFFERP (echo_area_buffer
[0]))
10396 with_echo_area_buffer (0, 0, current_message_1
,
10397 (intptr_t) &msg
, Qnil
, 0, 0);
10399 echo_area_buffer
[0] = Qnil
;
10407 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10410 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10413 *msg
= make_buffer_string (BEG
, Z
, 1);
10420 /* Push the current message on Vmessage_stack for later restoration
10421 by restore_message. Value is non-zero if the current message isn't
10422 empty. This is a relatively infrequent operation, so it's not
10423 worth optimizing. */
10426 push_message (void)
10429 msg
= current_message ();
10430 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10431 return STRINGP (msg
);
10435 /* Restore message display from the top of Vmessage_stack. */
10438 restore_message (void)
10442 eassert (CONSP (Vmessage_stack
));
10443 msg
= XCAR (Vmessage_stack
);
10445 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10447 message3_nolog (msg
, 0, 0);
10451 /* Handler for record_unwind_protect calling pop_message. */
10454 pop_message_unwind (Lisp_Object dummy
)
10460 /* Pop the top-most entry off Vmessage_stack. */
10465 eassert (CONSP (Vmessage_stack
));
10466 Vmessage_stack
= XCDR (Vmessage_stack
);
10470 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10471 exits. If the stack is not empty, we have a missing pop_message
10475 check_message_stack (void)
10477 if (!NILP (Vmessage_stack
))
10482 /* Truncate to NCHARS what will be displayed in the echo area the next
10483 time we display it---but don't redisplay it now. */
10486 truncate_echo_area (ptrdiff_t nchars
)
10489 echo_area_buffer
[0] = Qnil
;
10490 /* A null message buffer means that the frame hasn't really been
10491 initialized yet. Error messages get reported properly by
10492 cmd_error, so this must be just an informative message; toss it. */
10493 else if (!noninteractive
10495 && !NILP (echo_area_buffer
[0]))
10497 struct frame
*sf
= SELECTED_FRAME ();
10498 if (FRAME_MESSAGE_BUF (sf
))
10499 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10504 /* Helper function for truncate_echo_area. Truncate the current
10505 message to at most NCHARS characters. */
10508 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10510 if (BEG
+ nchars
< Z
)
10511 del_range (BEG
+ nchars
, Z
);
10513 echo_area_buffer
[0] = Qnil
;
10518 /* Set the current message to a substring of S or STRING.
10520 If STRING is a Lisp string, set the message to the first NBYTES
10521 bytes from STRING. NBYTES zero means use the whole string. If
10522 STRING is multibyte, the message will be displayed multibyte.
10524 If S is not null, set the message to the first LEN bytes of S. LEN
10525 zero means use the whole string. MULTIBYTE_P non-zero means S is
10526 multibyte. Display the message multibyte in that case.
10528 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10529 to t before calling set_message_1 (which calls insert).
10533 set_message (const char *s
, Lisp_Object string
,
10534 ptrdiff_t nbytes
, int multibyte_p
)
10536 message_enable_multibyte
10537 = ((s
&& multibyte_p
)
10538 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10540 with_echo_area_buffer (0, -1, set_message_1
,
10541 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10542 message_buf_print
= 0;
10543 help_echo_showing_p
= 0;
10547 /* Helper function for set_message. Arguments have the same meaning
10548 as there, with A1 corresponding to S and A2 corresponding to STRING
10549 This function is called with the echo area buffer being
10553 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10556 const char *s
= (const char *) i1
;
10557 const unsigned char *msg
= (const unsigned char *) s
;
10558 Lisp_Object string
= a2
;
10560 /* Change multibyteness of the echo buffer appropriately. */
10561 if (message_enable_multibyte
10562 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10563 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10565 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10566 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10567 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10569 /* Insert new message at BEG. */
10570 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10572 if (STRINGP (string
))
10577 nbytes
= SBYTES (string
);
10578 nchars
= string_byte_to_char (string
, nbytes
);
10580 /* This function takes care of single/multibyte conversion. We
10581 just have to ensure that the echo area buffer has the right
10582 setting of enable_multibyte_characters. */
10583 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10588 nbytes
= strlen (s
);
10590 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10592 /* Convert from multi-byte to single-byte. */
10597 /* Convert a multibyte string to single-byte. */
10598 for (i
= 0; i
< nbytes
; i
+= n
)
10600 c
= string_char_and_length (msg
+ i
, &n
);
10601 work
[0] = (ASCII_CHAR_P (c
)
10603 : multibyte_char_to_unibyte (c
));
10604 insert_1_both (work
, 1, 1, 1, 0, 0);
10607 else if (!multibyte_p
10608 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10610 /* Convert from single-byte to multi-byte. */
10613 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10615 /* Convert a single-byte string to multibyte. */
10616 for (i
= 0; i
< nbytes
; i
++)
10619 MAKE_CHAR_MULTIBYTE (c
);
10620 n
= CHAR_STRING (c
, str
);
10621 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10625 insert_1 (s
, nbytes
, 1, 0, 0);
10632 /* Clear messages. CURRENT_P non-zero means clear the current
10633 message. LAST_DISPLAYED_P non-zero means clear the message
10637 clear_message (int current_p
, int last_displayed_p
)
10641 echo_area_buffer
[0] = Qnil
;
10642 message_cleared_p
= 1;
10645 if (last_displayed_p
)
10646 echo_area_buffer
[1] = Qnil
;
10648 message_buf_print
= 0;
10651 /* Clear garbaged frames.
10653 This function is used where the old redisplay called
10654 redraw_garbaged_frames which in turn called redraw_frame which in
10655 turn called clear_frame. The call to clear_frame was a source of
10656 flickering. I believe a clear_frame is not necessary. It should
10657 suffice in the new redisplay to invalidate all current matrices,
10658 and ensure a complete redisplay of all windows. */
10661 clear_garbaged_frames (void)
10663 if (frame_garbaged
)
10665 Lisp_Object tail
, frame
;
10666 int changed_count
= 0;
10668 FOR_EACH_FRAME (tail
, frame
)
10670 struct frame
*f
= XFRAME (frame
);
10672 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10676 Fredraw_frame (frame
);
10677 f
->force_flush_display_p
= 1;
10679 clear_current_matrices (f
);
10686 frame_garbaged
= 0;
10688 ++windows_or_buffers_changed
;
10693 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10694 is non-zero update selected_frame. Value is non-zero if the
10695 mini-windows height has been changed. */
10698 echo_area_display (int update_frame_p
)
10700 Lisp_Object mini_window
;
10703 int window_height_changed_p
= 0;
10704 struct frame
*sf
= SELECTED_FRAME ();
10706 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10707 w
= XWINDOW (mini_window
);
10708 f
= XFRAME (WINDOW_FRAME (w
));
10710 /* Don't display if frame is invisible or not yet initialized. */
10711 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10714 #ifdef HAVE_WINDOW_SYSTEM
10715 /* When Emacs starts, selected_frame may be the initial terminal
10716 frame. If we let this through, a message would be displayed on
10718 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10720 #endif /* HAVE_WINDOW_SYSTEM */
10722 /* Redraw garbaged frames. */
10723 if (frame_garbaged
)
10724 clear_garbaged_frames ();
10726 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10728 echo_area_window
= mini_window
;
10729 window_height_changed_p
= display_echo_area (w
);
10730 w
->must_be_updated_p
= 1;
10732 /* Update the display, unless called from redisplay_internal.
10733 Also don't update the screen during redisplay itself. The
10734 update will happen at the end of redisplay, and an update
10735 here could cause confusion. */
10736 if (update_frame_p
&& !redisplaying_p
)
10740 /* If the display update has been interrupted by pending
10741 input, update mode lines in the frame. Due to the
10742 pending input, it might have been that redisplay hasn't
10743 been called, so that mode lines above the echo area are
10744 garbaged. This looks odd, so we prevent it here. */
10745 if (!display_completed
)
10746 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10748 if (window_height_changed_p
10749 /* Don't do this if Emacs is shutting down. Redisplay
10750 needs to run hooks. */
10751 && !NILP (Vrun_hooks
))
10753 /* Must update other windows. Likewise as in other
10754 cases, don't let this update be interrupted by
10756 ptrdiff_t count
= SPECPDL_INDEX ();
10757 specbind (Qredisplay_dont_pause
, Qt
);
10758 windows_or_buffers_changed
= 1;
10759 redisplay_internal ();
10760 unbind_to (count
, Qnil
);
10762 else if (FRAME_WINDOW_P (f
) && n
== 0)
10764 /* Window configuration is the same as before.
10765 Can do with a display update of the echo area,
10766 unless we displayed some mode lines. */
10767 update_single_window (w
, 1);
10768 FRAME_RIF (f
)->flush_display (f
);
10771 update_frame (f
, 1, 1);
10773 /* If cursor is in the echo area, make sure that the next
10774 redisplay displays the minibuffer, so that the cursor will
10775 be replaced with what the minibuffer wants. */
10776 if (cursor_in_echo_area
)
10777 ++windows_or_buffers_changed
;
10780 else if (!EQ (mini_window
, selected_window
))
10781 windows_or_buffers_changed
++;
10783 /* Last displayed message is now the current message. */
10784 echo_area_buffer
[1] = echo_area_buffer
[0];
10785 /* Inform read_char that we're not echoing. */
10786 echo_message_buffer
= Qnil
;
10788 /* Prevent redisplay optimization in redisplay_internal by resetting
10789 this_line_start_pos. This is done because the mini-buffer now
10790 displays the message instead of its buffer text. */
10791 if (EQ (mini_window
, selected_window
))
10792 CHARPOS (this_line_start_pos
) = 0;
10794 return window_height_changed_p
;
10799 /***********************************************************************
10800 Mode Lines and Frame Titles
10801 ***********************************************************************/
10803 /* A buffer for constructing non-propertized mode-line strings and
10804 frame titles in it; allocated from the heap in init_xdisp and
10805 resized as needed in store_mode_line_noprop_char. */
10807 static char *mode_line_noprop_buf
;
10809 /* The buffer's end, and a current output position in it. */
10811 static char *mode_line_noprop_buf_end
;
10812 static char *mode_line_noprop_ptr
;
10814 #define MODE_LINE_NOPROP_LEN(start) \
10815 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10818 MODE_LINE_DISPLAY
= 0,
10822 } mode_line_target
;
10824 /* Alist that caches the results of :propertize.
10825 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10826 static Lisp_Object mode_line_proptrans_alist
;
10828 /* List of strings making up the mode-line. */
10829 static Lisp_Object mode_line_string_list
;
10831 /* Base face property when building propertized mode line string. */
10832 static Lisp_Object mode_line_string_face
;
10833 static Lisp_Object mode_line_string_face_prop
;
10836 /* Unwind data for mode line strings */
10838 static Lisp_Object Vmode_line_unwind_vector
;
10841 format_mode_line_unwind_data (struct frame
*target_frame
,
10842 struct buffer
*obuf
,
10844 int save_proptrans
)
10846 Lisp_Object vector
, tmp
;
10848 /* Reduce consing by keeping one vector in
10849 Vwith_echo_area_save_vector. */
10850 vector
= Vmode_line_unwind_vector
;
10851 Vmode_line_unwind_vector
= Qnil
;
10854 vector
= Fmake_vector (make_number (10), Qnil
);
10856 ASET (vector
, 0, make_number (mode_line_target
));
10857 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10858 ASET (vector
, 2, mode_line_string_list
);
10859 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10860 ASET (vector
, 4, mode_line_string_face
);
10861 ASET (vector
, 5, mode_line_string_face_prop
);
10864 XSETBUFFER (tmp
, obuf
);
10867 ASET (vector
, 6, tmp
);
10868 ASET (vector
, 7, owin
);
10871 /* Similarly to `with-selected-window', if the operation selects
10872 a window on another frame, we must restore that frame's
10873 selected window, and (for a tty) the top-frame. */
10874 ASET (vector
, 8, target_frame
->selected_window
);
10875 if (FRAME_TERMCAP_P (target_frame
))
10876 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10883 unwind_format_mode_line (Lisp_Object vector
)
10885 Lisp_Object old_window
= AREF (vector
, 7);
10886 Lisp_Object target_frame_window
= AREF (vector
, 8);
10887 Lisp_Object old_top_frame
= AREF (vector
, 9);
10889 mode_line_target
= XINT (AREF (vector
, 0));
10890 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10891 mode_line_string_list
= AREF (vector
, 2);
10892 if (! EQ (AREF (vector
, 3), Qt
))
10893 mode_line_proptrans_alist
= AREF (vector
, 3);
10894 mode_line_string_face
= AREF (vector
, 4);
10895 mode_line_string_face_prop
= AREF (vector
, 5);
10897 /* Select window before buffer, since it may change the buffer. */
10898 if (!NILP (old_window
))
10900 /* If the operation that we are unwinding had selected a window
10901 on a different frame, reset its frame-selected-window. For a
10902 text terminal, reset its top-frame if necessary. */
10903 if (!NILP (target_frame_window
))
10906 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10908 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10909 Fselect_window (target_frame_window
, Qt
);
10911 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10912 Fselect_frame (old_top_frame
, Qt
);
10915 Fselect_window (old_window
, Qt
);
10918 if (!NILP (AREF (vector
, 6)))
10920 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10921 ASET (vector
, 6, Qnil
);
10924 Vmode_line_unwind_vector
= vector
;
10929 /* Store a single character C for the frame title in mode_line_noprop_buf.
10930 Re-allocate mode_line_noprop_buf if necessary. */
10933 store_mode_line_noprop_char (char c
)
10935 /* If output position has reached the end of the allocated buffer,
10936 increase the buffer's size. */
10937 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10939 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10940 ptrdiff_t size
= len
;
10941 mode_line_noprop_buf
=
10942 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10943 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10944 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10947 *mode_line_noprop_ptr
++ = c
;
10951 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10952 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10953 characters that yield more columns than PRECISION; PRECISION <= 0
10954 means copy the whole string. Pad with spaces until FIELD_WIDTH
10955 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10956 pad. Called from display_mode_element when it is used to build a
10960 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10962 const unsigned char *str
= (const unsigned char *) string
;
10964 ptrdiff_t dummy
, nbytes
;
10966 /* Copy at most PRECISION chars from STR. */
10967 nbytes
= strlen (string
);
10968 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10970 store_mode_line_noprop_char (*str
++);
10972 /* Fill up with spaces until FIELD_WIDTH reached. */
10973 while (field_width
> 0
10974 && n
< field_width
)
10976 store_mode_line_noprop_char (' ');
10983 /***********************************************************************
10985 ***********************************************************************/
10987 #ifdef HAVE_WINDOW_SYSTEM
10989 /* Set the title of FRAME, if it has changed. The title format is
10990 Vicon_title_format if FRAME is iconified, otherwise it is
10991 frame_title_format. */
10994 x_consider_frame_title (Lisp_Object frame
)
10996 struct frame
*f
= XFRAME (frame
);
10998 if (FRAME_WINDOW_P (f
)
10999 || FRAME_MINIBUF_ONLY_P (f
)
11000 || f
->explicit_name
)
11002 /* Do we have more than one visible frame on this X display? */
11005 ptrdiff_t title_start
;
11009 ptrdiff_t count
= SPECPDL_INDEX ();
11011 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
11013 Lisp_Object other_frame
= XCAR (tail
);
11014 struct frame
*tf
= XFRAME (other_frame
);
11017 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11018 && !FRAME_MINIBUF_ONLY_P (tf
)
11019 && !EQ (other_frame
, tip_frame
)
11020 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11024 /* Set global variable indicating that multiple frames exist. */
11025 multiple_frames
= CONSP (tail
);
11027 /* Switch to the buffer of selected window of the frame. Set up
11028 mode_line_target so that display_mode_element will output into
11029 mode_line_noprop_buf; then display the title. */
11030 record_unwind_protect (unwind_format_mode_line
,
11031 format_mode_line_unwind_data
11032 (f
, current_buffer
, selected_window
, 0));
11034 Fselect_window (f
->selected_window
, Qt
);
11035 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11036 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11038 mode_line_target
= MODE_LINE_TITLE
;
11039 title_start
= MODE_LINE_NOPROP_LEN (0);
11040 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11041 NULL
, DEFAULT_FACE_ID
);
11042 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11043 len
= MODE_LINE_NOPROP_LEN (title_start
);
11044 title
= mode_line_noprop_buf
+ title_start
;
11045 unbind_to (count
, Qnil
);
11047 /* Set the title only if it's changed. This avoids consing in
11048 the common case where it hasn't. (If it turns out that we've
11049 already wasted too much time by walking through the list with
11050 display_mode_element, then we might need to optimize at a
11051 higher level than this.) */
11052 if (! STRINGP (f
->name
)
11053 || SBYTES (f
->name
) != len
11054 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11055 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11059 #endif /* not HAVE_WINDOW_SYSTEM */
11062 /***********************************************************************
11064 ***********************************************************************/
11067 /* Prepare for redisplay by updating menu-bar item lists when
11068 appropriate. This can call eval. */
11071 prepare_menu_bars (void)
11074 struct gcpro gcpro1
, gcpro2
;
11076 Lisp_Object tooltip_frame
;
11078 #ifdef HAVE_WINDOW_SYSTEM
11079 tooltip_frame
= tip_frame
;
11081 tooltip_frame
= Qnil
;
11084 /* Update all frame titles based on their buffer names, etc. We do
11085 this before the menu bars so that the buffer-menu will show the
11086 up-to-date frame titles. */
11087 #ifdef HAVE_WINDOW_SYSTEM
11088 if (windows_or_buffers_changed
|| update_mode_lines
)
11090 Lisp_Object tail
, frame
;
11092 FOR_EACH_FRAME (tail
, frame
)
11094 f
= XFRAME (frame
);
11095 if (!EQ (frame
, tooltip_frame
)
11096 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11097 x_consider_frame_title (frame
);
11100 #endif /* HAVE_WINDOW_SYSTEM */
11102 /* Update the menu bar item lists, if appropriate. This has to be
11103 done before any actual redisplay or generation of display lines. */
11104 all_windows
= (update_mode_lines
11105 || buffer_shared
> 1
11106 || windows_or_buffers_changed
);
11109 Lisp_Object tail
, frame
;
11110 ptrdiff_t count
= SPECPDL_INDEX ();
11111 /* 1 means that update_menu_bar has run its hooks
11112 so any further calls to update_menu_bar shouldn't do so again. */
11113 int menu_bar_hooks_run
= 0;
11115 record_unwind_save_match_data ();
11117 FOR_EACH_FRAME (tail
, frame
)
11119 f
= XFRAME (frame
);
11121 /* Ignore tooltip frame. */
11122 if (EQ (frame
, tooltip_frame
))
11125 /* If a window on this frame changed size, report that to
11126 the user and clear the size-change flag. */
11127 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11129 Lisp_Object functions
;
11131 /* Clear flag first in case we get an error below. */
11132 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11133 functions
= Vwindow_size_change_functions
;
11134 GCPRO2 (tail
, functions
);
11136 while (CONSP (functions
))
11138 if (!EQ (XCAR (functions
), Qt
))
11139 call1 (XCAR (functions
), frame
);
11140 functions
= XCDR (functions
);
11146 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11147 #ifdef HAVE_WINDOW_SYSTEM
11148 update_tool_bar (f
, 0);
11151 if (windows_or_buffers_changed
11153 ns_set_doc_edited (f
, Fbuffer_modified_p
11154 (XWINDOW (f
->selected_window
)->buffer
));
11159 unbind_to (count
, Qnil
);
11163 struct frame
*sf
= SELECTED_FRAME ();
11164 update_menu_bar (sf
, 1, 0);
11165 #ifdef HAVE_WINDOW_SYSTEM
11166 update_tool_bar (sf
, 1);
11172 /* Update the menu bar item list for frame F. This has to be done
11173 before we start to fill in any display lines, because it can call
11176 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11178 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11179 already ran the menu bar hooks for this redisplay, so there
11180 is no need to run them again. The return value is the
11181 updated value of this flag, to pass to the next call. */
11184 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11186 Lisp_Object window
;
11187 register struct window
*w
;
11189 /* If called recursively during a menu update, do nothing. This can
11190 happen when, for instance, an activate-menubar-hook causes a
11192 if (inhibit_menubar_update
)
11195 window
= FRAME_SELECTED_WINDOW (f
);
11196 w
= XWINDOW (window
);
11198 if (FRAME_WINDOW_P (f
)
11200 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11201 || defined (HAVE_NS) || defined (USE_GTK)
11202 FRAME_EXTERNAL_MENU_BAR (f
)
11204 FRAME_MENU_BAR_LINES (f
) > 0
11206 : FRAME_MENU_BAR_LINES (f
) > 0)
11208 /* If the user has switched buffers or windows, we need to
11209 recompute to reflect the new bindings. But we'll
11210 recompute when update_mode_lines is set too; that means
11211 that people can use force-mode-line-update to request
11212 that the menu bar be recomputed. The adverse effect on
11213 the rest of the redisplay algorithm is about the same as
11214 windows_or_buffers_changed anyway. */
11215 if (windows_or_buffers_changed
11216 /* This used to test w->update_mode_line, but we believe
11217 there is no need to recompute the menu in that case. */
11218 || update_mode_lines
11219 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11220 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11221 != w
->last_had_star
)
11222 || ((!NILP (Vtransient_mark_mode
)
11223 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11224 != !NILP (w
->region_showing
)))
11226 struct buffer
*prev
= current_buffer
;
11227 ptrdiff_t count
= SPECPDL_INDEX ();
11229 specbind (Qinhibit_menubar_update
, Qt
);
11231 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11232 if (save_match_data
)
11233 record_unwind_save_match_data ();
11234 if (NILP (Voverriding_local_map_menu_flag
))
11236 specbind (Qoverriding_terminal_local_map
, Qnil
);
11237 specbind (Qoverriding_local_map
, Qnil
);
11242 /* Run the Lucid hook. */
11243 safe_run_hooks (Qactivate_menubar_hook
);
11245 /* If it has changed current-menubar from previous value,
11246 really recompute the menu-bar from the value. */
11247 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11248 call0 (Qrecompute_lucid_menubar
);
11250 safe_run_hooks (Qmenu_bar_update_hook
);
11255 XSETFRAME (Vmenu_updating_frame
, f
);
11256 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11258 /* Redisplay the menu bar in case we changed it. */
11259 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11260 || defined (HAVE_NS) || defined (USE_GTK)
11261 if (FRAME_WINDOW_P (f
))
11263 #if defined (HAVE_NS)
11264 /* All frames on Mac OS share the same menubar. So only
11265 the selected frame should be allowed to set it. */
11266 if (f
== SELECTED_FRAME ())
11268 set_frame_menubar (f
, 0, 0);
11271 /* On a terminal screen, the menu bar is an ordinary screen
11272 line, and this makes it get updated. */
11273 w
->update_mode_line
= 1;
11274 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11275 /* In the non-toolkit version, the menu bar is an ordinary screen
11276 line, and this makes it get updated. */
11277 w
->update_mode_line
= 1;
11278 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11280 unbind_to (count
, Qnil
);
11281 set_buffer_internal_1 (prev
);
11290 /***********************************************************************
11292 ***********************************************************************/
11294 #ifdef HAVE_WINDOW_SYSTEM
11297 Nominal cursor position -- where to draw output.
11298 HPOS and VPOS are window relative glyph matrix coordinates.
11299 X and Y are window relative pixel coordinates. */
11301 struct cursor_pos output_cursor
;
11305 Set the global variable output_cursor to CURSOR. All cursor
11306 positions are relative to updated_window. */
11309 set_output_cursor (struct cursor_pos
*cursor
)
11311 output_cursor
.hpos
= cursor
->hpos
;
11312 output_cursor
.vpos
= cursor
->vpos
;
11313 output_cursor
.x
= cursor
->x
;
11314 output_cursor
.y
= cursor
->y
;
11319 Set a nominal cursor position.
11321 HPOS and VPOS are column/row positions in a window glyph matrix. X
11322 and Y are window text area relative pixel positions.
11324 If this is done during an update, updated_window will contain the
11325 window that is being updated and the position is the future output
11326 cursor position for that window. If updated_window is null, use
11327 selected_window and display the cursor at the given position. */
11330 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11334 /* If updated_window is not set, work on selected_window. */
11335 if (updated_window
)
11336 w
= updated_window
;
11338 w
= XWINDOW (selected_window
);
11340 /* Set the output cursor. */
11341 output_cursor
.hpos
= hpos
;
11342 output_cursor
.vpos
= vpos
;
11343 output_cursor
.x
= x
;
11344 output_cursor
.y
= y
;
11346 /* If not called as part of an update, really display the cursor.
11347 This will also set the cursor position of W. */
11348 if (updated_window
== NULL
)
11351 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11352 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11353 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11358 #endif /* HAVE_WINDOW_SYSTEM */
11361 /***********************************************************************
11363 ***********************************************************************/
11365 #ifdef HAVE_WINDOW_SYSTEM
11367 /* Where the mouse was last time we reported a mouse event. */
11369 FRAME_PTR last_mouse_frame
;
11371 /* Tool-bar item index of the item on which a mouse button was pressed
11374 int last_tool_bar_item
;
11378 update_tool_bar_unwind (Lisp_Object frame
)
11380 selected_frame
= frame
;
11384 /* Update the tool-bar item list for frame F. This has to be done
11385 before we start to fill in any display lines. Called from
11386 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11387 and restore it here. */
11390 update_tool_bar (struct frame
*f
, int save_match_data
)
11392 #if defined (USE_GTK) || defined (HAVE_NS)
11393 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11395 int do_update
= WINDOWP (f
->tool_bar_window
)
11396 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11401 Lisp_Object window
;
11404 window
= FRAME_SELECTED_WINDOW (f
);
11405 w
= XWINDOW (window
);
11407 /* If the user has switched buffers or windows, we need to
11408 recompute to reflect the new bindings. But we'll
11409 recompute when update_mode_lines is set too; that means
11410 that people can use force-mode-line-update to request
11411 that the menu bar be recomputed. The adverse effect on
11412 the rest of the redisplay algorithm is about the same as
11413 windows_or_buffers_changed anyway. */
11414 if (windows_or_buffers_changed
11415 || w
->update_mode_line
11416 || update_mode_lines
11417 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11418 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11419 != w
->last_had_star
)
11420 || ((!NILP (Vtransient_mark_mode
)
11421 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11422 != !NILP (w
->region_showing
)))
11424 struct buffer
*prev
= current_buffer
;
11425 ptrdiff_t count
= SPECPDL_INDEX ();
11426 Lisp_Object frame
, new_tool_bar
;
11427 int new_n_tool_bar
;
11428 struct gcpro gcpro1
;
11430 /* Set current_buffer to the buffer of the selected
11431 window of the frame, so that we get the right local
11433 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11435 /* Save match data, if we must. */
11436 if (save_match_data
)
11437 record_unwind_save_match_data ();
11439 /* Make sure that we don't accidentally use bogus keymaps. */
11440 if (NILP (Voverriding_local_map_menu_flag
))
11442 specbind (Qoverriding_terminal_local_map
, Qnil
);
11443 specbind (Qoverriding_local_map
, Qnil
);
11446 GCPRO1 (new_tool_bar
);
11448 /* We must temporarily set the selected frame to this frame
11449 before calling tool_bar_items, because the calculation of
11450 the tool-bar keymap uses the selected frame (see
11451 `tool-bar-make-keymap' in tool-bar.el). */
11452 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11453 XSETFRAME (frame
, f
);
11454 selected_frame
= frame
;
11456 /* Build desired tool-bar items from keymaps. */
11457 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11460 /* Redisplay the tool-bar if we changed it. */
11461 if (new_n_tool_bar
!= f
->n_tool_bar_items
11462 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11464 /* Redisplay that happens asynchronously due to an expose event
11465 may access f->tool_bar_items. Make sure we update both
11466 variables within BLOCK_INPUT so no such event interrupts. */
11468 f
->tool_bar_items
= new_tool_bar
;
11469 f
->n_tool_bar_items
= new_n_tool_bar
;
11470 w
->update_mode_line
= 1;
11476 unbind_to (count
, Qnil
);
11477 set_buffer_internal_1 (prev
);
11483 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11484 F's desired tool-bar contents. F->tool_bar_items must have
11485 been set up previously by calling prepare_menu_bars. */
11488 build_desired_tool_bar_string (struct frame
*f
)
11490 int i
, size
, size_needed
;
11491 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11492 Lisp_Object image
, plist
, props
;
11494 image
= plist
= props
= Qnil
;
11495 GCPRO3 (image
, plist
, props
);
11497 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11498 Otherwise, make a new string. */
11500 /* The size of the string we might be able to reuse. */
11501 size
= (STRINGP (f
->desired_tool_bar_string
)
11502 ? SCHARS (f
->desired_tool_bar_string
)
11505 /* We need one space in the string for each image. */
11506 size_needed
= f
->n_tool_bar_items
;
11508 /* Reuse f->desired_tool_bar_string, if possible. */
11509 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11510 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11511 make_number (' '));
11514 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11515 Fremove_text_properties (make_number (0), make_number (size
),
11516 props
, f
->desired_tool_bar_string
);
11519 /* Put a `display' property on the string for the images to display,
11520 put a `menu_item' property on tool-bar items with a value that
11521 is the index of the item in F's tool-bar item vector. */
11522 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11524 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11526 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11527 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11528 int hmargin
, vmargin
, relief
, idx
, end
;
11530 /* If image is a vector, choose the image according to the
11532 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11533 if (VECTORP (image
))
11537 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11538 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11541 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11542 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11544 eassert (ASIZE (image
) >= idx
);
11545 image
= AREF (image
, idx
);
11550 /* Ignore invalid image specifications. */
11551 if (!valid_image_p (image
))
11554 /* Display the tool-bar button pressed, or depressed. */
11555 plist
= Fcopy_sequence (XCDR (image
));
11557 /* Compute margin and relief to draw. */
11558 relief
= (tool_bar_button_relief
>= 0
11559 ? tool_bar_button_relief
11560 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11561 hmargin
= vmargin
= relief
;
11563 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11564 INT_MAX
- max (hmargin
, vmargin
)))
11566 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11567 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11569 else if (CONSP (Vtool_bar_button_margin
))
11571 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11572 INT_MAX
- hmargin
))
11573 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11575 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11576 INT_MAX
- vmargin
))
11577 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11580 if (auto_raise_tool_bar_buttons_p
)
11582 /* Add a `:relief' property to the image spec if the item is
11586 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11593 /* If image is selected, display it pressed, i.e. with a
11594 negative relief. If it's not selected, display it with a
11596 plist
= Fplist_put (plist
, QCrelief
,
11598 ? make_number (-relief
)
11599 : make_number (relief
)));
11604 /* Put a margin around the image. */
11605 if (hmargin
|| vmargin
)
11607 if (hmargin
== vmargin
)
11608 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11610 plist
= Fplist_put (plist
, QCmargin
,
11611 Fcons (make_number (hmargin
),
11612 make_number (vmargin
)));
11615 /* If button is not enabled, and we don't have special images
11616 for the disabled state, make the image appear disabled by
11617 applying an appropriate algorithm to it. */
11618 if (!enabled_p
&& idx
< 0)
11619 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11621 /* Put a `display' text property on the string for the image to
11622 display. Put a `menu-item' property on the string that gives
11623 the start of this item's properties in the tool-bar items
11625 image
= Fcons (Qimage
, plist
);
11626 props
= list4 (Qdisplay
, image
,
11627 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11629 /* Let the last image hide all remaining spaces in the tool bar
11630 string. The string can be longer than needed when we reuse a
11631 previous string. */
11632 if (i
+ 1 == f
->n_tool_bar_items
)
11633 end
= SCHARS (f
->desired_tool_bar_string
);
11636 Fadd_text_properties (make_number (i
), make_number (end
),
11637 props
, f
->desired_tool_bar_string
);
11645 /* Display one line of the tool-bar of frame IT->f.
11647 HEIGHT specifies the desired height of the tool-bar line.
11648 If the actual height of the glyph row is less than HEIGHT, the
11649 row's height is increased to HEIGHT, and the icons are centered
11650 vertically in the new height.
11652 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11653 count a final empty row in case the tool-bar width exactly matches
11658 display_tool_bar_line (struct it
*it
, int height
)
11660 struct glyph_row
*row
= it
->glyph_row
;
11661 int max_x
= it
->last_visible_x
;
11662 struct glyph
*last
;
11664 prepare_desired_row (row
);
11665 row
->y
= it
->current_y
;
11667 /* Note that this isn't made use of if the face hasn't a box,
11668 so there's no need to check the face here. */
11669 it
->start_of_box_run_p
= 1;
11671 while (it
->current_x
< max_x
)
11673 int x
, n_glyphs_before
, i
, nglyphs
;
11674 struct it it_before
;
11676 /* Get the next display element. */
11677 if (!get_next_display_element (it
))
11679 /* Don't count empty row if we are counting needed tool-bar lines. */
11680 if (height
< 0 && !it
->hpos
)
11685 /* Produce glyphs. */
11686 n_glyphs_before
= row
->used
[TEXT_AREA
];
11689 PRODUCE_GLYPHS (it
);
11691 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11693 x
= it_before
.current_x
;
11694 while (i
< nglyphs
)
11696 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11698 if (x
+ glyph
->pixel_width
> max_x
)
11700 /* Glyph doesn't fit on line. Backtrack. */
11701 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11703 /* If this is the only glyph on this line, it will never fit on the
11704 tool-bar, so skip it. But ensure there is at least one glyph,
11705 so we don't accidentally disable the tool-bar. */
11706 if (n_glyphs_before
== 0
11707 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11713 x
+= glyph
->pixel_width
;
11717 /* Stop at line end. */
11718 if (ITERATOR_AT_END_OF_LINE_P (it
))
11721 set_iterator_to_next (it
, 1);
11726 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11728 /* Use default face for the border below the tool bar.
11730 FIXME: When auto-resize-tool-bars is grow-only, there is
11731 no additional border below the possibly empty tool-bar lines.
11732 So to make the extra empty lines look "normal", we have to
11733 use the tool-bar face for the border too. */
11734 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11735 it
->face_id
= DEFAULT_FACE_ID
;
11737 extend_face_to_end_of_line (it
);
11738 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11739 last
->right_box_line_p
= 1;
11740 if (last
== row
->glyphs
[TEXT_AREA
])
11741 last
->left_box_line_p
= 1;
11743 /* Make line the desired height and center it vertically. */
11744 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11746 /* Don't add more than one line height. */
11747 height
%= FRAME_LINE_HEIGHT (it
->f
);
11748 it
->max_ascent
+= height
/ 2;
11749 it
->max_descent
+= (height
+ 1) / 2;
11752 compute_line_metrics (it
);
11754 /* If line is empty, make it occupy the rest of the tool-bar. */
11755 if (!row
->displays_text_p
)
11757 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11758 row
->visible_height
= row
->height
;
11759 row
->ascent
= row
->phys_ascent
= 0;
11760 row
->extra_line_spacing
= 0;
11763 row
->full_width_p
= 1;
11764 row
->continued_p
= 0;
11765 row
->truncated_on_left_p
= 0;
11766 row
->truncated_on_right_p
= 0;
11768 it
->current_x
= it
->hpos
= 0;
11769 it
->current_y
+= row
->height
;
11775 /* Max tool-bar height. */
11777 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11778 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11780 /* Value is the number of screen lines needed to make all tool-bar
11781 items of frame F visible. The number of actual rows needed is
11782 returned in *N_ROWS if non-NULL. */
11785 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11787 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11789 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11790 the desired matrix, so use (unused) mode-line row as temporary row to
11791 avoid destroying the first tool-bar row. */
11792 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11794 /* Initialize an iterator for iteration over
11795 F->desired_tool_bar_string in the tool-bar window of frame F. */
11796 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11797 it
.first_visible_x
= 0;
11798 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11799 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11800 it
.paragraph_embedding
= L2R
;
11802 while (!ITERATOR_AT_END_P (&it
))
11804 clear_glyph_row (temp_row
);
11805 it
.glyph_row
= temp_row
;
11806 display_tool_bar_line (&it
, -1);
11808 clear_glyph_row (temp_row
);
11810 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11812 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11814 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11818 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11820 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11821 (Lisp_Object frame
)
11828 frame
= selected_frame
;
11830 CHECK_FRAME (frame
);
11831 f
= XFRAME (frame
);
11833 if (WINDOWP (f
->tool_bar_window
)
11834 && (w
= XWINDOW (f
->tool_bar_window
),
11835 WINDOW_TOTAL_LINES (w
) > 0))
11837 update_tool_bar (f
, 1);
11838 if (f
->n_tool_bar_items
)
11840 build_desired_tool_bar_string (f
);
11841 nlines
= tool_bar_lines_needed (f
, NULL
);
11845 return make_number (nlines
);
11849 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11850 height should be changed. */
11853 redisplay_tool_bar (struct frame
*f
)
11857 struct glyph_row
*row
;
11859 #if defined (USE_GTK) || defined (HAVE_NS)
11860 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11861 update_frame_tool_bar (f
);
11865 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11866 do anything. This means you must start with tool-bar-lines
11867 non-zero to get the auto-sizing effect. Or in other words, you
11868 can turn off tool-bars by specifying tool-bar-lines zero. */
11869 if (!WINDOWP (f
->tool_bar_window
)
11870 || (w
= XWINDOW (f
->tool_bar_window
),
11871 WINDOW_TOTAL_LINES (w
) == 0))
11874 /* Set up an iterator for the tool-bar window. */
11875 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11876 it
.first_visible_x
= 0;
11877 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11878 row
= it
.glyph_row
;
11880 /* Build a string that represents the contents of the tool-bar. */
11881 build_desired_tool_bar_string (f
);
11882 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11883 /* FIXME: This should be controlled by a user option. But it
11884 doesn't make sense to have an R2L tool bar if the menu bar cannot
11885 be drawn also R2L, and making the menu bar R2L is tricky due
11886 toolkit-specific code that implements it. If an R2L tool bar is
11887 ever supported, display_tool_bar_line should also be augmented to
11888 call unproduce_glyphs like display_line and display_string
11890 it
.paragraph_embedding
= L2R
;
11892 if (f
->n_tool_bar_rows
== 0)
11896 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11897 nlines
!= WINDOW_TOTAL_LINES (w
)))
11900 int old_height
= WINDOW_TOTAL_LINES (w
);
11902 XSETFRAME (frame
, f
);
11903 Fmodify_frame_parameters (frame
,
11904 Fcons (Fcons (Qtool_bar_lines
,
11905 make_number (nlines
)),
11907 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11909 clear_glyph_matrix (w
->desired_matrix
);
11910 fonts_changed_p
= 1;
11916 /* Display as many lines as needed to display all tool-bar items. */
11918 if (f
->n_tool_bar_rows
> 0)
11920 int border
, rows
, height
, extra
;
11922 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11923 border
= XINT (Vtool_bar_border
);
11924 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11925 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11926 else if (EQ (Vtool_bar_border
, Qborder_width
))
11927 border
= f
->border_width
;
11933 rows
= f
->n_tool_bar_rows
;
11934 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11935 extra
= it
.last_visible_y
- border
- height
* rows
;
11937 while (it
.current_y
< it
.last_visible_y
)
11940 if (extra
> 0 && rows
-- > 0)
11942 h
= (extra
+ rows
- 1) / rows
;
11945 display_tool_bar_line (&it
, height
+ h
);
11950 while (it
.current_y
< it
.last_visible_y
)
11951 display_tool_bar_line (&it
, 0);
11954 /* It doesn't make much sense to try scrolling in the tool-bar
11955 window, so don't do it. */
11956 w
->desired_matrix
->no_scrolling_p
= 1;
11957 w
->must_be_updated_p
= 1;
11959 if (!NILP (Vauto_resize_tool_bars
))
11961 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11962 int change_height_p
= 0;
11964 /* If we couldn't display everything, change the tool-bar's
11965 height if there is room for more. */
11966 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11967 && it
.current_y
< max_tool_bar_height
)
11968 change_height_p
= 1;
11970 row
= it
.glyph_row
- 1;
11972 /* If there are blank lines at the end, except for a partially
11973 visible blank line at the end that is smaller than
11974 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11975 if (!row
->displays_text_p
11976 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11977 change_height_p
= 1;
11979 /* If row displays tool-bar items, but is partially visible,
11980 change the tool-bar's height. */
11981 if (row
->displays_text_p
11982 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11983 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11984 change_height_p
= 1;
11986 /* Resize windows as needed by changing the `tool-bar-lines'
11987 frame parameter. */
11988 if (change_height_p
)
11991 int old_height
= WINDOW_TOTAL_LINES (w
);
11993 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11995 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11996 && !f
->minimize_tool_bar_window_p
)
11997 ? (nlines
> old_height
)
11998 : (nlines
!= old_height
));
11999 f
->minimize_tool_bar_window_p
= 0;
12001 if (change_height_p
)
12003 XSETFRAME (frame
, f
);
12004 Fmodify_frame_parameters (frame
,
12005 Fcons (Fcons (Qtool_bar_lines
,
12006 make_number (nlines
)),
12008 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12010 clear_glyph_matrix (w
->desired_matrix
);
12011 f
->n_tool_bar_rows
= nrows
;
12012 fonts_changed_p
= 1;
12019 f
->minimize_tool_bar_window_p
= 0;
12024 /* Get information about the tool-bar item which is displayed in GLYPH
12025 on frame F. Return in *PROP_IDX the index where tool-bar item
12026 properties start in F->tool_bar_items. Value is zero if
12027 GLYPH doesn't display a tool-bar item. */
12030 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12036 /* This function can be called asynchronously, which means we must
12037 exclude any possibility that Fget_text_property signals an
12039 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12040 charpos
= max (0, charpos
);
12042 /* Get the text property `menu-item' at pos. The value of that
12043 property is the start index of this item's properties in
12044 F->tool_bar_items. */
12045 prop
= Fget_text_property (make_number (charpos
),
12046 Qmenu_item
, f
->current_tool_bar_string
);
12047 if (INTEGERP (prop
))
12049 *prop_idx
= XINT (prop
);
12059 /* Get information about the tool-bar item at position X/Y on frame F.
12060 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12061 the current matrix of the tool-bar window of F, or NULL if not
12062 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12063 item in F->tool_bar_items. Value is
12065 -1 if X/Y is not on a tool-bar item
12066 0 if X/Y is on the same item that was highlighted before.
12070 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12071 int *hpos
, int *vpos
, int *prop_idx
)
12073 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12074 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12077 /* Find the glyph under X/Y. */
12078 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12079 if (*glyph
== NULL
)
12082 /* Get the start of this tool-bar item's properties in
12083 f->tool_bar_items. */
12084 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12087 /* Is mouse on the highlighted item? */
12088 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12089 && *vpos
>= hlinfo
->mouse_face_beg_row
12090 && *vpos
<= hlinfo
->mouse_face_end_row
12091 && (*vpos
> hlinfo
->mouse_face_beg_row
12092 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12093 && (*vpos
< hlinfo
->mouse_face_end_row
12094 || *hpos
< hlinfo
->mouse_face_end_col
12095 || hlinfo
->mouse_face_past_end
))
12103 Handle mouse button event on the tool-bar of frame F, at
12104 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12105 0 for button release. MODIFIERS is event modifiers for button
12109 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12112 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12113 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12114 int hpos
, vpos
, prop_idx
;
12115 struct glyph
*glyph
;
12116 Lisp_Object enabled_p
;
12118 /* If not on the highlighted tool-bar item, return. */
12119 frame_to_window_pixel_xy (w
, &x
, &y
);
12120 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12123 /* If item is disabled, do nothing. */
12124 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12125 if (NILP (enabled_p
))
12130 /* Show item in pressed state. */
12131 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12132 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12133 last_tool_bar_item
= prop_idx
;
12137 Lisp_Object key
, frame
;
12138 struct input_event event
;
12139 EVENT_INIT (event
);
12141 /* Show item in released state. */
12142 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12143 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12145 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12147 XSETFRAME (frame
, f
);
12148 event
.kind
= TOOL_BAR_EVENT
;
12149 event
.frame_or_window
= frame
;
12151 kbd_buffer_store_event (&event
);
12153 event
.kind
= TOOL_BAR_EVENT
;
12154 event
.frame_or_window
= frame
;
12156 event
.modifiers
= modifiers
;
12157 kbd_buffer_store_event (&event
);
12158 last_tool_bar_item
= -1;
12163 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12164 tool-bar window-relative coordinates X/Y. Called from
12165 note_mouse_highlight. */
12168 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12170 Lisp_Object window
= f
->tool_bar_window
;
12171 struct window
*w
= XWINDOW (window
);
12172 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12173 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12175 struct glyph
*glyph
;
12176 struct glyph_row
*row
;
12178 Lisp_Object enabled_p
;
12180 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12181 int mouse_down_p
, rc
;
12183 /* Function note_mouse_highlight is called with negative X/Y
12184 values when mouse moves outside of the frame. */
12185 if (x
<= 0 || y
<= 0)
12187 clear_mouse_face (hlinfo
);
12191 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12194 /* Not on tool-bar item. */
12195 clear_mouse_face (hlinfo
);
12199 /* On same tool-bar item as before. */
12200 goto set_help_echo
;
12202 clear_mouse_face (hlinfo
);
12204 /* Mouse is down, but on different tool-bar item? */
12205 mouse_down_p
= (dpyinfo
->grabbed
12206 && f
== last_mouse_frame
12207 && FRAME_LIVE_P (f
));
12209 && last_tool_bar_item
!= prop_idx
)
12212 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12213 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12215 /* If tool-bar item is not enabled, don't highlight it. */
12216 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12217 if (!NILP (enabled_p
))
12219 /* Compute the x-position of the glyph. In front and past the
12220 image is a space. We include this in the highlighted area. */
12221 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12222 for (i
= x
= 0; i
< hpos
; ++i
)
12223 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12225 /* Record this as the current active region. */
12226 hlinfo
->mouse_face_beg_col
= hpos
;
12227 hlinfo
->mouse_face_beg_row
= vpos
;
12228 hlinfo
->mouse_face_beg_x
= x
;
12229 hlinfo
->mouse_face_beg_y
= row
->y
;
12230 hlinfo
->mouse_face_past_end
= 0;
12232 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12233 hlinfo
->mouse_face_end_row
= vpos
;
12234 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12235 hlinfo
->mouse_face_end_y
= row
->y
;
12236 hlinfo
->mouse_face_window
= window
;
12237 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12239 /* Display it as active. */
12240 show_mouse_face (hlinfo
, draw
);
12241 hlinfo
->mouse_face_image_state
= draw
;
12246 /* Set help_echo_string to a help string to display for this tool-bar item.
12247 XTread_socket does the rest. */
12248 help_echo_object
= help_echo_window
= Qnil
;
12249 help_echo_pos
= -1;
12250 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12251 if (NILP (help_echo_string
))
12252 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12255 #endif /* HAVE_WINDOW_SYSTEM */
12259 /************************************************************************
12260 Horizontal scrolling
12261 ************************************************************************/
12263 static int hscroll_window_tree (Lisp_Object
);
12264 static int hscroll_windows (Lisp_Object
);
12266 /* For all leaf windows in the window tree rooted at WINDOW, set their
12267 hscroll value so that PT is (i) visible in the window, and (ii) so
12268 that it is not within a certain margin at the window's left and
12269 right border. Value is non-zero if any window's hscroll has been
12273 hscroll_window_tree (Lisp_Object window
)
12275 int hscrolled_p
= 0;
12276 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12277 int hscroll_step_abs
= 0;
12278 double hscroll_step_rel
= 0;
12280 if (hscroll_relative_p
)
12282 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12283 if (hscroll_step_rel
< 0)
12285 hscroll_relative_p
= 0;
12286 hscroll_step_abs
= 0;
12289 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12291 hscroll_step_abs
= XINT (Vhscroll_step
);
12292 if (hscroll_step_abs
< 0)
12293 hscroll_step_abs
= 0;
12296 hscroll_step_abs
= 0;
12298 while (WINDOWP (window
))
12300 struct window
*w
= XWINDOW (window
);
12302 if (WINDOWP (w
->hchild
))
12303 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12304 else if (WINDOWP (w
->vchild
))
12305 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12306 else if (w
->cursor
.vpos
>= 0)
12309 int text_area_width
;
12310 struct glyph_row
*current_cursor_row
12311 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12312 struct glyph_row
*desired_cursor_row
12313 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12314 struct glyph_row
*cursor_row
12315 = (desired_cursor_row
->enabled_p
12316 ? desired_cursor_row
12317 : current_cursor_row
);
12318 int row_r2l_p
= cursor_row
->reversed_p
;
12320 text_area_width
= window_box_width (w
, TEXT_AREA
);
12322 /* Scroll when cursor is inside this scroll margin. */
12323 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12325 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12326 /* For left-to-right rows, hscroll when cursor is either
12327 (i) inside the right hscroll margin, or (ii) if it is
12328 inside the left margin and the window is already
12332 && w
->cursor
.x
<= h_margin
)
12333 || (cursor_row
->enabled_p
12334 && cursor_row
->truncated_on_right_p
12335 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12336 /* For right-to-left rows, the logic is similar,
12337 except that rules for scrolling to left and right
12338 are reversed. E.g., if cursor.x <= h_margin, we
12339 need to hscroll "to the right" unconditionally,
12340 and that will scroll the screen to the left so as
12341 to reveal the next portion of the row. */
12343 && ((cursor_row
->enabled_p
12344 /* FIXME: It is confusing to set the
12345 truncated_on_right_p flag when R2L rows
12346 are actually truncated on the left. */
12347 && cursor_row
->truncated_on_right_p
12348 && w
->cursor
.x
<= h_margin
)
12350 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12354 struct buffer
*saved_current_buffer
;
12358 /* Find point in a display of infinite width. */
12359 saved_current_buffer
= current_buffer
;
12360 current_buffer
= XBUFFER (w
->buffer
);
12362 if (w
== XWINDOW (selected_window
))
12366 pt
= marker_position (w
->pointm
);
12367 pt
= max (BEGV
, pt
);
12371 /* Move iterator to pt starting at cursor_row->start in
12372 a line with infinite width. */
12373 init_to_row_start (&it
, w
, cursor_row
);
12374 it
.last_visible_x
= INFINITY
;
12375 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12376 current_buffer
= saved_current_buffer
;
12378 /* Position cursor in window. */
12379 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12380 hscroll
= max (0, (it
.current_x
12381 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12382 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12383 : (text_area_width
/ 2))))
12384 / FRAME_COLUMN_WIDTH (it
.f
);
12385 else if ((!row_r2l_p
12386 && w
->cursor
.x
>= text_area_width
- h_margin
)
12387 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12389 if (hscroll_relative_p
)
12390 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12393 wanted_x
= text_area_width
12394 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12397 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12401 if (hscroll_relative_p
)
12402 wanted_x
= text_area_width
* hscroll_step_rel
12405 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12408 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12410 hscroll
= max (hscroll
, w
->min_hscroll
);
12412 /* Don't prevent redisplay optimizations if hscroll
12413 hasn't changed, as it will unnecessarily slow down
12415 if (w
->hscroll
!= hscroll
)
12417 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12418 w
->hscroll
= hscroll
;
12427 /* Value is non-zero if hscroll of any leaf window has been changed. */
12428 return hscrolled_p
;
12432 /* Set hscroll so that cursor is visible and not inside horizontal
12433 scroll margins for all windows in the tree rooted at WINDOW. See
12434 also hscroll_window_tree above. Value is non-zero if any window's
12435 hscroll has been changed. If it has, desired matrices on the frame
12436 of WINDOW are cleared. */
12439 hscroll_windows (Lisp_Object window
)
12441 int hscrolled_p
= hscroll_window_tree (window
);
12443 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12444 return hscrolled_p
;
12449 /************************************************************************
12451 ************************************************************************/
12453 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12454 to a non-zero value. This is sometimes handy to have in a debugger
12459 /* First and last unchanged row for try_window_id. */
12461 static int debug_first_unchanged_at_end_vpos
;
12462 static int debug_last_unchanged_at_beg_vpos
;
12464 /* Delta vpos and y. */
12466 static int debug_dvpos
, debug_dy
;
12468 /* Delta in characters and bytes for try_window_id. */
12470 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12472 /* Values of window_end_pos and window_end_vpos at the end of
12475 static ptrdiff_t debug_end_vpos
;
12477 /* Append a string to W->desired_matrix->method. FMT is a printf
12478 format string. If trace_redisplay_p is non-zero also printf the
12479 resulting string to stderr. */
12481 static void debug_method_add (struct window
*, char const *, ...)
12482 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12485 debug_method_add (struct window
*w
, char const *fmt
, ...)
12488 char *method
= w
->desired_matrix
->method
;
12489 int len
= strlen (method
);
12490 int size
= sizeof w
->desired_matrix
->method
;
12491 int remaining
= size
- len
- 1;
12494 va_start (ap
, fmt
);
12495 vsprintf (buffer
, fmt
, ap
);
12497 if (len
&& remaining
)
12500 --remaining
, ++len
;
12503 strncpy (method
+ len
, buffer
, remaining
);
12505 if (trace_redisplay_p
)
12506 fprintf (stderr
, "%p (%s): %s\n",
12508 ((BUFFERP (w
->buffer
)
12509 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12510 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12515 #endif /* GLYPH_DEBUG */
12518 /* Value is non-zero if all changes in window W, which displays
12519 current_buffer, are in the text between START and END. START is a
12520 buffer position, END is given as a distance from Z. Used in
12521 redisplay_internal for display optimization. */
12524 text_outside_line_unchanged_p (struct window
*w
,
12525 ptrdiff_t start
, ptrdiff_t end
)
12527 int unchanged_p
= 1;
12529 /* If text or overlays have changed, see where. */
12530 if (w
->last_modified
< MODIFF
12531 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
12533 /* Gap in the line? */
12534 if (GPT
< start
|| Z
- GPT
< end
)
12537 /* Changes start in front of the line, or end after it? */
12539 && (BEG_UNCHANGED
< start
- 1
12540 || END_UNCHANGED
< end
))
12543 /* If selective display, can't optimize if changes start at the
12544 beginning of the line. */
12546 && INTEGERP (BVAR (current_buffer
, selective_display
))
12547 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12548 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12551 /* If there are overlays at the start or end of the line, these
12552 may have overlay strings with newlines in them. A change at
12553 START, for instance, may actually concern the display of such
12554 overlay strings as well, and they are displayed on different
12555 lines. So, quickly rule out this case. (For the future, it
12556 might be desirable to implement something more telling than
12557 just BEG/END_UNCHANGED.) */
12560 if (BEG
+ BEG_UNCHANGED
== start
12561 && overlay_touches_p (start
))
12563 if (END_UNCHANGED
== end
12564 && overlay_touches_p (Z
- end
))
12568 /* Under bidi reordering, adding or deleting a character in the
12569 beginning of a paragraph, before the first strong directional
12570 character, can change the base direction of the paragraph (unless
12571 the buffer specifies a fixed paragraph direction), which will
12572 require to redisplay the whole paragraph. It might be worthwhile
12573 to find the paragraph limits and widen the range of redisplayed
12574 lines to that, but for now just give up this optimization. */
12575 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12576 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12580 return unchanged_p
;
12584 /* Do a frame update, taking possible shortcuts into account. This is
12585 the main external entry point for redisplay.
12587 If the last redisplay displayed an echo area message and that message
12588 is no longer requested, we clear the echo area or bring back the
12589 mini-buffer if that is in use. */
12594 redisplay_internal ();
12599 overlay_arrow_string_or_property (Lisp_Object var
)
12603 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12606 return Voverlay_arrow_string
;
12609 /* Return 1 if there are any overlay-arrows in current_buffer. */
12611 overlay_arrow_in_current_buffer_p (void)
12615 for (vlist
= Voverlay_arrow_variable_list
;
12617 vlist
= XCDR (vlist
))
12619 Lisp_Object var
= XCAR (vlist
);
12622 if (!SYMBOLP (var
))
12624 val
= find_symbol_value (var
);
12626 && current_buffer
== XMARKER (val
)->buffer
)
12633 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12637 overlay_arrows_changed_p (void)
12641 for (vlist
= Voverlay_arrow_variable_list
;
12643 vlist
= XCDR (vlist
))
12645 Lisp_Object var
= XCAR (vlist
);
12646 Lisp_Object val
, pstr
;
12648 if (!SYMBOLP (var
))
12650 val
= find_symbol_value (var
);
12651 if (!MARKERP (val
))
12653 if (! EQ (COERCE_MARKER (val
),
12654 Fget (var
, Qlast_arrow_position
))
12655 || ! (pstr
= overlay_arrow_string_or_property (var
),
12656 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12662 /* Mark overlay arrows to be updated on next redisplay. */
12665 update_overlay_arrows (int up_to_date
)
12669 for (vlist
= Voverlay_arrow_variable_list
;
12671 vlist
= XCDR (vlist
))
12673 Lisp_Object var
= XCAR (vlist
);
12675 if (!SYMBOLP (var
))
12678 if (up_to_date
> 0)
12680 Lisp_Object val
= find_symbol_value (var
);
12681 Fput (var
, Qlast_arrow_position
,
12682 COERCE_MARKER (val
));
12683 Fput (var
, Qlast_arrow_string
,
12684 overlay_arrow_string_or_property (var
));
12686 else if (up_to_date
< 0
12687 || !NILP (Fget (var
, Qlast_arrow_position
)))
12689 Fput (var
, Qlast_arrow_position
, Qt
);
12690 Fput (var
, Qlast_arrow_string
, Qt
);
12696 /* Return overlay arrow string to display at row.
12697 Return integer (bitmap number) for arrow bitmap in left fringe.
12698 Return nil if no overlay arrow. */
12701 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12705 for (vlist
= Voverlay_arrow_variable_list
;
12707 vlist
= XCDR (vlist
))
12709 Lisp_Object var
= XCAR (vlist
);
12712 if (!SYMBOLP (var
))
12715 val
= find_symbol_value (var
);
12718 && current_buffer
== XMARKER (val
)->buffer
12719 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12721 if (FRAME_WINDOW_P (it
->f
)
12722 /* FIXME: if ROW->reversed_p is set, this should test
12723 the right fringe, not the left one. */
12724 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12726 #ifdef HAVE_WINDOW_SYSTEM
12727 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12730 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12731 return make_number (fringe_bitmap
);
12734 return make_number (-1); /* Use default arrow bitmap */
12736 return overlay_arrow_string_or_property (var
);
12743 /* Return 1 if point moved out of or into a composition. Otherwise
12744 return 0. PREV_BUF and PREV_PT are the last point buffer and
12745 position. BUF and PT are the current point buffer and position. */
12748 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12749 struct buffer
*buf
, ptrdiff_t pt
)
12751 ptrdiff_t start
, end
;
12753 Lisp_Object buffer
;
12755 XSETBUFFER (buffer
, buf
);
12756 /* Check a composition at the last point if point moved within the
12758 if (prev_buf
== buf
)
12761 /* Point didn't move. */
12764 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12765 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12766 && COMPOSITION_VALID_P (start
, end
, prop
)
12767 && start
< prev_pt
&& end
> prev_pt
)
12768 /* The last point was within the composition. Return 1 iff
12769 point moved out of the composition. */
12770 return (pt
<= start
|| pt
>= end
);
12773 /* Check a composition at the current point. */
12774 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12775 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12776 && COMPOSITION_VALID_P (start
, end
, prop
)
12777 && start
< pt
&& end
> pt
);
12781 /* Reconsider the setting of B->clip_changed which is displayed
12785 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12787 if (b
->clip_changed
12788 && !NILP (w
->window_end_valid
)
12789 && w
->current_matrix
->buffer
== b
12790 && w
->current_matrix
->zv
== BUF_ZV (b
)
12791 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12792 b
->clip_changed
= 0;
12794 /* If display wasn't paused, and W is not a tool bar window, see if
12795 point has been moved into or out of a composition. In that case,
12796 we set b->clip_changed to 1 to force updating the screen. If
12797 b->clip_changed has already been set to 1, we can skip this
12799 if (!b
->clip_changed
12800 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12804 if (w
== XWINDOW (selected_window
))
12807 pt
= marker_position (w
->pointm
);
12809 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12810 || pt
!= w
->last_point
)
12811 && check_point_in_composition (w
->current_matrix
->buffer
,
12813 XBUFFER (w
->buffer
), pt
))
12814 b
->clip_changed
= 1;
12819 /* Select FRAME to forward the values of frame-local variables into C
12820 variables so that the redisplay routines can access those values
12824 select_frame_for_redisplay (Lisp_Object frame
)
12826 Lisp_Object tail
, tem
;
12827 Lisp_Object old
= selected_frame
;
12828 struct Lisp_Symbol
*sym
;
12830 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12832 selected_frame
= frame
;
12835 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12836 if (CONSP (XCAR (tail
))
12837 && (tem
= XCAR (XCAR (tail
)),
12839 && (sym
= indirect_variable (XSYMBOL (tem
)),
12840 sym
->redirect
== SYMBOL_LOCALIZED
)
12841 && sym
->val
.blv
->frame_local
)
12842 /* Use find_symbol_value rather than Fsymbol_value
12843 to avoid an error if it is void. */
12844 find_symbol_value (tem
);
12845 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12849 #define STOP_POLLING \
12850 do { if (! polling_stopped_here) stop_polling (); \
12851 polling_stopped_here = 1; } while (0)
12853 #define RESUME_POLLING \
12854 do { if (polling_stopped_here) start_polling (); \
12855 polling_stopped_here = 0; } while (0)
12858 /* Perhaps in the future avoid recentering windows if it
12859 is not necessary; currently that causes some problems. */
12862 redisplay_internal (void)
12864 struct window
*w
= XWINDOW (selected_window
);
12868 int must_finish
= 0;
12869 struct text_pos tlbufpos
, tlendpos
;
12870 int number_of_visible_frames
;
12871 ptrdiff_t count
, count1
;
12873 int polling_stopped_here
= 0;
12874 Lisp_Object old_frame
= selected_frame
;
12876 /* Non-zero means redisplay has to consider all windows on all
12877 frames. Zero means, only selected_window is considered. */
12878 int consider_all_windows_p
;
12880 /* Non-zero means redisplay has to redisplay the miniwindow */
12881 int update_miniwindow_p
= 0;
12883 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12885 /* No redisplay if running in batch mode or frame is not yet fully
12886 initialized, or redisplay is explicitly turned off by setting
12887 Vinhibit_redisplay. */
12888 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12889 || !NILP (Vinhibit_redisplay
))
12892 /* Don't examine these until after testing Vinhibit_redisplay.
12893 When Emacs is shutting down, perhaps because its connection to
12894 X has dropped, we should not look at them at all. */
12895 fr
= XFRAME (w
->frame
);
12896 sf
= SELECTED_FRAME ();
12898 if (!fr
->glyphs_initialized_p
)
12901 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12902 if (popup_activated ())
12906 /* I don't think this happens but let's be paranoid. */
12907 if (redisplaying_p
)
12910 /* Record a function that resets redisplaying_p to its old value
12911 when we leave this function. */
12912 count
= SPECPDL_INDEX ();
12913 record_unwind_protect (unwind_redisplay
,
12914 Fcons (make_number (redisplaying_p
), selected_frame
));
12916 specbind (Qinhibit_free_realized_faces
, Qnil
);
12919 Lisp_Object tail
, frame
;
12921 FOR_EACH_FRAME (tail
, frame
)
12923 struct frame
*f
= XFRAME (frame
);
12924 f
->already_hscrolled_p
= 0;
12929 /* Remember the currently selected window. */
12932 if (!EQ (old_frame
, selected_frame
)
12933 && FRAME_LIVE_P (XFRAME (old_frame
)))
12934 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12935 selected_frame and selected_window to be temporarily out-of-sync so
12936 when we come back here via `goto retry', we need to resync because we
12937 may need to run Elisp code (via prepare_menu_bars). */
12938 select_frame_for_redisplay (old_frame
);
12941 reconsider_clip_changes (w
, current_buffer
);
12942 last_escape_glyph_frame
= NULL
;
12943 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12944 last_glyphless_glyph_frame
= NULL
;
12945 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12947 /* If new fonts have been loaded that make a glyph matrix adjustment
12948 necessary, do it. */
12949 if (fonts_changed_p
)
12951 adjust_glyphs (NULL
);
12952 ++windows_or_buffers_changed
;
12953 fonts_changed_p
= 0;
12956 /* If face_change_count is non-zero, init_iterator will free all
12957 realized faces, which includes the faces referenced from current
12958 matrices. So, we can't reuse current matrices in this case. */
12959 if (face_change_count
)
12960 ++windows_or_buffers_changed
;
12962 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12963 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12965 /* Since frames on a single ASCII terminal share the same
12966 display area, displaying a different frame means redisplay
12967 the whole thing. */
12968 windows_or_buffers_changed
++;
12969 SET_FRAME_GARBAGED (sf
);
12971 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12973 FRAME_TTY (sf
)->previous_frame
= sf
;
12976 /* Set the visible flags for all frames. Do this before checking
12977 for resized or garbaged frames; they want to know if their frames
12978 are visible. See the comment in frame.h for
12979 FRAME_SAMPLE_VISIBILITY. */
12981 Lisp_Object tail
, frame
;
12983 number_of_visible_frames
= 0;
12985 FOR_EACH_FRAME (tail
, frame
)
12987 struct frame
*f
= XFRAME (frame
);
12989 FRAME_SAMPLE_VISIBILITY (f
);
12990 if (FRAME_VISIBLE_P (f
))
12991 ++number_of_visible_frames
;
12992 clear_desired_matrices (f
);
12996 /* Notice any pending interrupt request to change frame size. */
12997 do_pending_window_change (1);
12999 /* do_pending_window_change could change the selected_window due to
13000 frame resizing which makes the selected window too small. */
13001 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13004 reconsider_clip_changes (w
, current_buffer
);
13007 /* Clear frames marked as garbaged. */
13008 if (frame_garbaged
)
13009 clear_garbaged_frames ();
13011 /* Build menubar and tool-bar items. */
13012 if (NILP (Vmemory_full
))
13013 prepare_menu_bars ();
13015 if (windows_or_buffers_changed
)
13016 update_mode_lines
++;
13018 /* Detect case that we need to write or remove a star in the mode line. */
13019 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13021 w
->update_mode_line
= 1;
13022 if (buffer_shared
> 1)
13023 update_mode_lines
++;
13026 /* Avoid invocation of point motion hooks by `current_column' below. */
13027 count1
= SPECPDL_INDEX ();
13028 specbind (Qinhibit_point_motion_hooks
, Qt
);
13030 /* If %c is in the mode line, update it if needed. */
13031 if (!NILP (w
->column_number_displayed
)
13032 /* This alternative quickly identifies a common case
13033 where no change is needed. */
13034 && !(PT
== w
->last_point
13035 && w
->last_modified
>= MODIFF
13036 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
13037 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13038 w
->update_mode_line
= 1;
13040 unbind_to (count1
, Qnil
);
13042 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13044 /* The variable buffer_shared is set in redisplay_window and
13045 indicates that we redisplay a buffer in different windows. See
13047 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
13048 || cursor_type_changed
);
13050 /* If specs for an arrow have changed, do thorough redisplay
13051 to ensure we remove any arrow that should no longer exist. */
13052 if (overlay_arrows_changed_p ())
13053 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13055 /* Normally the message* functions will have already displayed and
13056 updated the echo area, but the frame may have been trashed, or
13057 the update may have been preempted, so display the echo area
13058 again here. Checking message_cleared_p captures the case that
13059 the echo area should be cleared. */
13060 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13061 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13062 || (message_cleared_p
13063 && minibuf_level
== 0
13064 /* If the mini-window is currently selected, this means the
13065 echo-area doesn't show through. */
13066 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13068 int window_height_changed_p
= echo_area_display (0);
13070 if (message_cleared_p
)
13071 update_miniwindow_p
= 1;
13075 /* If we don't display the current message, don't clear the
13076 message_cleared_p flag, because, if we did, we wouldn't clear
13077 the echo area in the next redisplay which doesn't preserve
13079 if (!display_last_displayed_message_p
)
13080 message_cleared_p
= 0;
13082 if (fonts_changed_p
)
13084 else if (window_height_changed_p
)
13086 consider_all_windows_p
= 1;
13087 ++update_mode_lines
;
13088 ++windows_or_buffers_changed
;
13090 /* If window configuration was changed, frames may have been
13091 marked garbaged. Clear them or we will experience
13092 surprises wrt scrolling. */
13093 if (frame_garbaged
)
13094 clear_garbaged_frames ();
13097 else if (EQ (selected_window
, minibuf_window
)
13098 && (current_buffer
->clip_changed
13099 || w
->last_modified
< MODIFF
13100 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
13101 && resize_mini_window (w
, 0))
13103 /* Resized active mini-window to fit the size of what it is
13104 showing if its contents might have changed. */
13106 /* FIXME: this causes all frames to be updated, which seems unnecessary
13107 since only the current frame needs to be considered. This function needs
13108 to be rewritten with two variables, consider_all_windows and
13109 consider_all_frames. */
13110 consider_all_windows_p
= 1;
13111 ++windows_or_buffers_changed
;
13112 ++update_mode_lines
;
13114 /* If window configuration was changed, frames may have been
13115 marked garbaged. Clear them or we will experience
13116 surprises wrt scrolling. */
13117 if (frame_garbaged
)
13118 clear_garbaged_frames ();
13122 /* If showing the region, and mark has changed, we must redisplay
13123 the whole window. The assignment to this_line_start_pos prevents
13124 the optimization directly below this if-statement. */
13125 if (((!NILP (Vtransient_mark_mode
)
13126 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13127 != !NILP (w
->region_showing
))
13128 || (!NILP (w
->region_showing
)
13129 && !EQ (w
->region_showing
,
13130 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13131 CHARPOS (this_line_start_pos
) = 0;
13133 /* Optimize the case that only the line containing the cursor in the
13134 selected window has changed. Variables starting with this_ are
13135 set in display_line and record information about the line
13136 containing the cursor. */
13137 tlbufpos
= this_line_start_pos
;
13138 tlendpos
= this_line_end_pos
;
13139 if (!consider_all_windows_p
13140 && CHARPOS (tlbufpos
) > 0
13141 && !w
->update_mode_line
13142 && !current_buffer
->clip_changed
13143 && !current_buffer
->prevent_redisplay_optimizations_p
13144 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13145 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13146 /* Make sure recorded data applies to current buffer, etc. */
13147 && this_line_buffer
== current_buffer
13148 && current_buffer
== XBUFFER (w
->buffer
)
13150 && !w
->optional_new_start
13151 /* Point must be on the line that we have info recorded about. */
13152 && PT
>= CHARPOS (tlbufpos
)
13153 && PT
<= Z
- CHARPOS (tlendpos
)
13154 /* All text outside that line, including its final newline,
13155 must be unchanged. */
13156 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13157 CHARPOS (tlendpos
)))
13159 if (CHARPOS (tlbufpos
) > BEGV
13160 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13161 && (CHARPOS (tlbufpos
) == ZV
13162 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13163 /* Former continuation line has disappeared by becoming empty. */
13165 else if (w
->last_modified
< MODIFF
13166 || w
->last_overlay_modified
< OVERLAY_MODIFF
13167 || MINI_WINDOW_P (w
))
13169 /* We have to handle the case of continuation around a
13170 wide-column character (see the comment in indent.c around
13173 For instance, in the following case:
13175 -------- Insert --------
13176 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13177 J_I_ ==> J_I_ `^^' are cursors.
13181 As we have to redraw the line above, we cannot use this
13185 int line_height_before
= this_line_pixel_height
;
13187 /* Note that start_display will handle the case that the
13188 line starting at tlbufpos is a continuation line. */
13189 start_display (&it
, w
, tlbufpos
);
13191 /* Implementation note: It this still necessary? */
13192 if (it
.current_x
!= this_line_start_x
)
13195 TRACE ((stderr
, "trying display optimization 1\n"));
13196 w
->cursor
.vpos
= -1;
13197 overlay_arrow_seen
= 0;
13198 it
.vpos
= this_line_vpos
;
13199 it
.current_y
= this_line_y
;
13200 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13201 display_line (&it
);
13203 /* If line contains point, is not continued,
13204 and ends at same distance from eob as before, we win. */
13205 if (w
->cursor
.vpos
>= 0
13206 /* Line is not continued, otherwise this_line_start_pos
13207 would have been set to 0 in display_line. */
13208 && CHARPOS (this_line_start_pos
)
13209 /* Line ends as before. */
13210 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13211 /* Line has same height as before. Otherwise other lines
13212 would have to be shifted up or down. */
13213 && this_line_pixel_height
== line_height_before
)
13215 /* If this is not the window's last line, we must adjust
13216 the charstarts of the lines below. */
13217 if (it
.current_y
< it
.last_visible_y
)
13219 struct glyph_row
*row
13220 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13221 ptrdiff_t delta
, delta_bytes
;
13223 /* We used to distinguish between two cases here,
13224 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13225 when the line ends in a newline or the end of the
13226 buffer's accessible portion. But both cases did
13227 the same, so they were collapsed. */
13229 - CHARPOS (tlendpos
)
13230 - MATRIX_ROW_START_CHARPOS (row
));
13231 delta_bytes
= (Z_BYTE
13232 - BYTEPOS (tlendpos
)
13233 - MATRIX_ROW_START_BYTEPOS (row
));
13235 increment_matrix_positions (w
->current_matrix
,
13236 this_line_vpos
+ 1,
13237 w
->current_matrix
->nrows
,
13238 delta
, delta_bytes
);
13241 /* If this row displays text now but previously didn't,
13242 or vice versa, w->window_end_vpos may have to be
13244 if ((it
.glyph_row
- 1)->displays_text_p
)
13246 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13247 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13249 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13250 && this_line_vpos
> 0)
13251 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13252 w
->window_end_valid
= Qnil
;
13254 /* Update hint: No need to try to scroll in update_window. */
13255 w
->desired_matrix
->no_scrolling_p
= 1;
13258 *w
->desired_matrix
->method
= 0;
13259 debug_method_add (w
, "optimization 1");
13261 #ifdef HAVE_WINDOW_SYSTEM
13262 update_window_fringes (w
, 0);
13269 else if (/* Cursor position hasn't changed. */
13270 PT
== w
->last_point
13271 /* Make sure the cursor was last displayed
13272 in this window. Otherwise we have to reposition it. */
13273 && 0 <= w
->cursor
.vpos
13274 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13278 do_pending_window_change (1);
13279 /* If selected_window changed, redisplay again. */
13280 if (WINDOWP (selected_window
)
13281 && (w
= XWINDOW (selected_window
)) != sw
)
13284 /* We used to always goto end_of_redisplay here, but this
13285 isn't enough if we have a blinking cursor. */
13286 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13287 goto end_of_redisplay
;
13291 /* If highlighting the region, or if the cursor is in the echo area,
13292 then we can't just move the cursor. */
13293 else if (! (!NILP (Vtransient_mark_mode
)
13294 && !NILP (BVAR (current_buffer
, mark_active
)))
13295 && (EQ (selected_window
,
13296 BVAR (current_buffer
, last_selected_window
))
13297 || highlight_nonselected_windows
)
13298 && NILP (w
->region_showing
)
13299 && NILP (Vshow_trailing_whitespace
)
13300 && !cursor_in_echo_area
)
13303 struct glyph_row
*row
;
13305 /* Skip from tlbufpos to PT and see where it is. Note that
13306 PT may be in invisible text. If so, we will end at the
13307 next visible position. */
13308 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13309 NULL
, DEFAULT_FACE_ID
);
13310 it
.current_x
= this_line_start_x
;
13311 it
.current_y
= this_line_y
;
13312 it
.vpos
= this_line_vpos
;
13314 /* The call to move_it_to stops in front of PT, but
13315 moves over before-strings. */
13316 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13318 if (it
.vpos
== this_line_vpos
13319 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13322 eassert (this_line_vpos
== it
.vpos
);
13323 eassert (this_line_y
== it
.current_y
);
13324 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13326 *w
->desired_matrix
->method
= 0;
13327 debug_method_add (w
, "optimization 3");
13336 /* Text changed drastically or point moved off of line. */
13337 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13340 CHARPOS (this_line_start_pos
) = 0;
13341 consider_all_windows_p
|= buffer_shared
> 1;
13342 ++clear_face_cache_count
;
13343 #ifdef HAVE_WINDOW_SYSTEM
13344 ++clear_image_cache_count
;
13347 /* Build desired matrices, and update the display. If
13348 consider_all_windows_p is non-zero, do it for all windows on all
13349 frames. Otherwise do it for selected_window, only. */
13351 if (consider_all_windows_p
)
13353 Lisp_Object tail
, frame
;
13355 FOR_EACH_FRAME (tail
, frame
)
13356 XFRAME (frame
)->updated_p
= 0;
13358 /* Recompute # windows showing selected buffer. This will be
13359 incremented each time such a window is displayed. */
13362 FOR_EACH_FRAME (tail
, frame
)
13364 struct frame
*f
= XFRAME (frame
);
13366 /* We don't have to do anything for unselected terminal
13368 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13369 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13372 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13374 if (! EQ (frame
, selected_frame
))
13375 /* Select the frame, for the sake of frame-local
13377 select_frame_for_redisplay (frame
);
13379 /* Mark all the scroll bars to be removed; we'll redeem
13380 the ones we want when we redisplay their windows. */
13381 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13382 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13384 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13385 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13387 /* The X error handler may have deleted that frame. */
13388 if (!FRAME_LIVE_P (f
))
13391 /* Any scroll bars which redisplay_windows should have
13392 nuked should now go away. */
13393 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13394 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13396 /* If fonts changed, display again. */
13397 /* ??? rms: I suspect it is a mistake to jump all the way
13398 back to retry here. It should just retry this frame. */
13399 if (fonts_changed_p
)
13402 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13404 /* See if we have to hscroll. */
13405 if (!f
->already_hscrolled_p
)
13407 f
->already_hscrolled_p
= 1;
13408 if (hscroll_windows (f
->root_window
))
13412 /* Prevent various kinds of signals during display
13413 update. stdio is not robust about handling
13414 signals, which can cause an apparent I/O
13416 if (interrupt_input
)
13417 unrequest_sigio ();
13420 /* Update the display. */
13421 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13422 pending
|= update_frame (f
, 0, 0);
13428 if (!EQ (old_frame
, selected_frame
)
13429 && FRAME_LIVE_P (XFRAME (old_frame
)))
13430 /* We played a bit fast-and-loose above and allowed selected_frame
13431 and selected_window to be temporarily out-of-sync but let's make
13432 sure this stays contained. */
13433 select_frame_for_redisplay (old_frame
);
13434 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13438 /* Do the mark_window_display_accurate after all windows have
13439 been redisplayed because this call resets flags in buffers
13440 which are needed for proper redisplay. */
13441 FOR_EACH_FRAME (tail
, frame
)
13443 struct frame
*f
= XFRAME (frame
);
13446 mark_window_display_accurate (f
->root_window
, 1);
13447 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13448 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13453 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13455 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13456 struct frame
*mini_frame
;
13458 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13459 /* Use list_of_error, not Qerror, so that
13460 we catch only errors and don't run the debugger. */
13461 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13463 redisplay_window_error
);
13464 if (update_miniwindow_p
)
13465 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13467 redisplay_window_error
);
13469 /* Compare desired and current matrices, perform output. */
13472 /* If fonts changed, display again. */
13473 if (fonts_changed_p
)
13476 /* Prevent various kinds of signals during display update.
13477 stdio is not robust about handling signals,
13478 which can cause an apparent I/O error. */
13479 if (interrupt_input
)
13480 unrequest_sigio ();
13483 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13485 if (hscroll_windows (selected_window
))
13488 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13489 pending
= update_frame (sf
, 0, 0);
13492 /* We may have called echo_area_display at the top of this
13493 function. If the echo area is on another frame, that may
13494 have put text on a frame other than the selected one, so the
13495 above call to update_frame would not have caught it. Catch
13497 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13498 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13500 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13502 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13503 pending
|= update_frame (mini_frame
, 0, 0);
13504 if (!pending
&& hscroll_windows (mini_window
))
13509 /* If display was paused because of pending input, make sure we do a
13510 thorough update the next time. */
13513 /* Prevent the optimization at the beginning of
13514 redisplay_internal that tries a single-line update of the
13515 line containing the cursor in the selected window. */
13516 CHARPOS (this_line_start_pos
) = 0;
13518 /* Let the overlay arrow be updated the next time. */
13519 update_overlay_arrows (0);
13521 /* If we pause after scrolling, some rows in the current
13522 matrices of some windows are not valid. */
13523 if (!WINDOW_FULL_WIDTH_P (w
)
13524 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13525 update_mode_lines
= 1;
13529 if (!consider_all_windows_p
)
13531 /* This has already been done above if
13532 consider_all_windows_p is set. */
13533 mark_window_display_accurate_1 (w
, 1);
13535 /* Say overlay arrows are up to date. */
13536 update_overlay_arrows (1);
13538 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13539 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13542 update_mode_lines
= 0;
13543 windows_or_buffers_changed
= 0;
13544 cursor_type_changed
= 0;
13547 /* Start SIGIO interrupts coming again. Having them off during the
13548 code above makes it less likely one will discard output, but not
13549 impossible, since there might be stuff in the system buffer here.
13550 But it is much hairier to try to do anything about that. */
13551 if (interrupt_input
)
13555 /* If a frame has become visible which was not before, redisplay
13556 again, so that we display it. Expose events for such a frame
13557 (which it gets when becoming visible) don't call the parts of
13558 redisplay constructing glyphs, so simply exposing a frame won't
13559 display anything in this case. So, we have to display these
13560 frames here explicitly. */
13563 Lisp_Object tail
, frame
;
13566 FOR_EACH_FRAME (tail
, frame
)
13568 int this_is_visible
= 0;
13570 if (XFRAME (frame
)->visible
)
13571 this_is_visible
= 1;
13572 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13573 if (XFRAME (frame
)->visible
)
13574 this_is_visible
= 1;
13576 if (this_is_visible
)
13580 if (new_count
!= number_of_visible_frames
)
13581 windows_or_buffers_changed
++;
13584 /* Change frame size now if a change is pending. */
13585 do_pending_window_change (1);
13587 /* If we just did a pending size change, or have additional
13588 visible frames, or selected_window changed, redisplay again. */
13589 if ((windows_or_buffers_changed
&& !pending
)
13590 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13593 /* Clear the face and image caches.
13595 We used to do this only if consider_all_windows_p. But the cache
13596 needs to be cleared if a timer creates images in the current
13597 buffer (e.g. the test case in Bug#6230). */
13599 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13601 clear_face_cache (0);
13602 clear_face_cache_count
= 0;
13605 #ifdef HAVE_WINDOW_SYSTEM
13606 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13608 clear_image_caches (Qnil
);
13609 clear_image_cache_count
= 0;
13611 #endif /* HAVE_WINDOW_SYSTEM */
13614 unbind_to (count
, Qnil
);
13619 /* Redisplay, but leave alone any recent echo area message unless
13620 another message has been requested in its place.
13622 This is useful in situations where you need to redisplay but no
13623 user action has occurred, making it inappropriate for the message
13624 area to be cleared. See tracking_off and
13625 wait_reading_process_output for examples of these situations.
13627 FROM_WHERE is an integer saying from where this function was
13628 called. This is useful for debugging. */
13631 redisplay_preserve_echo_area (int from_where
)
13633 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13635 if (!NILP (echo_area_buffer
[1]))
13637 /* We have a previously displayed message, but no current
13638 message. Redisplay the previous message. */
13639 display_last_displayed_message_p
= 1;
13640 redisplay_internal ();
13641 display_last_displayed_message_p
= 0;
13644 redisplay_internal ();
13646 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13647 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13648 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13652 /* Function registered with record_unwind_protect in
13653 redisplay_internal. Reset redisplaying_p to the value it had
13654 before redisplay_internal was called, and clear
13655 prevent_freeing_realized_faces_p. It also selects the previously
13656 selected frame, unless it has been deleted (by an X connection
13657 failure during redisplay, for example). */
13660 unwind_redisplay (Lisp_Object val
)
13662 Lisp_Object old_redisplaying_p
, old_frame
;
13664 old_redisplaying_p
= XCAR (val
);
13665 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13666 old_frame
= XCDR (val
);
13667 if (! EQ (old_frame
, selected_frame
)
13668 && FRAME_LIVE_P (XFRAME (old_frame
)))
13669 select_frame_for_redisplay (old_frame
);
13674 /* Mark the display of window W as accurate or inaccurate. If
13675 ACCURATE_P is non-zero mark display of W as accurate. If
13676 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13677 redisplay_internal is called. */
13680 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13682 if (BUFFERP (w
->buffer
))
13684 struct buffer
*b
= XBUFFER (w
->buffer
);
13686 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13687 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13689 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13693 b
->clip_changed
= 0;
13694 b
->prevent_redisplay_optimizations_p
= 0;
13696 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13697 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13698 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13699 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13701 w
->current_matrix
->buffer
= b
;
13702 w
->current_matrix
->begv
= BUF_BEGV (b
);
13703 w
->current_matrix
->zv
= BUF_ZV (b
);
13705 w
->last_cursor
= w
->cursor
;
13706 w
->last_cursor_off_p
= w
->cursor_off_p
;
13708 if (w
== XWINDOW (selected_window
))
13709 w
->last_point
= BUF_PT (b
);
13711 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
13717 w
->window_end_valid
= w
->buffer
;
13718 w
->update_mode_line
= 0;
13723 /* Mark the display of windows in the window tree rooted at WINDOW as
13724 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13725 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13726 be redisplayed the next time redisplay_internal is called. */
13729 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13733 for (; !NILP (window
); window
= w
->next
)
13735 w
= XWINDOW (window
);
13736 mark_window_display_accurate_1 (w
, accurate_p
);
13738 if (!NILP (w
->vchild
))
13739 mark_window_display_accurate (w
->vchild
, accurate_p
);
13740 if (!NILP (w
->hchild
))
13741 mark_window_display_accurate (w
->hchild
, accurate_p
);
13746 update_overlay_arrows (1);
13750 /* Force a thorough redisplay the next time by setting
13751 last_arrow_position and last_arrow_string to t, which is
13752 unequal to any useful value of Voverlay_arrow_... */
13753 update_overlay_arrows (-1);
13758 /* Return value in display table DP (Lisp_Char_Table *) for character
13759 C. Since a display table doesn't have any parent, we don't have to
13760 follow parent. Do not call this function directly but use the
13761 macro DISP_CHAR_VECTOR. */
13764 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13768 if (ASCII_CHAR_P (c
))
13771 if (SUB_CHAR_TABLE_P (val
))
13772 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13778 XSETCHAR_TABLE (table
, dp
);
13779 val
= char_table_ref (table
, c
);
13788 /***********************************************************************
13790 ***********************************************************************/
13792 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13795 redisplay_windows (Lisp_Object window
)
13797 while (!NILP (window
))
13799 struct window
*w
= XWINDOW (window
);
13801 if (!NILP (w
->hchild
))
13802 redisplay_windows (w
->hchild
);
13803 else if (!NILP (w
->vchild
))
13804 redisplay_windows (w
->vchild
);
13805 else if (!NILP (w
->buffer
))
13807 displayed_buffer
= XBUFFER (w
->buffer
);
13808 /* Use list_of_error, not Qerror, so that
13809 we catch only errors and don't run the debugger. */
13810 internal_condition_case_1 (redisplay_window_0
, window
,
13812 redisplay_window_error
);
13820 redisplay_window_error (Lisp_Object ignore
)
13822 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13827 redisplay_window_0 (Lisp_Object window
)
13829 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13830 redisplay_window (window
, 0);
13835 redisplay_window_1 (Lisp_Object window
)
13837 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13838 redisplay_window (window
, 1);
13843 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13844 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13845 which positions recorded in ROW differ from current buffer
13848 Return 0 if cursor is not on this row, 1 otherwise. */
13851 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13852 struct glyph_matrix
*matrix
,
13853 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13856 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13857 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13858 struct glyph
*cursor
= NULL
;
13859 /* The last known character position in row. */
13860 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13862 ptrdiff_t pt_old
= PT
- delta
;
13863 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13864 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13865 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13866 /* A glyph beyond the edge of TEXT_AREA which we should never
13868 struct glyph
*glyphs_end
= end
;
13869 /* Non-zero means we've found a match for cursor position, but that
13870 glyph has the avoid_cursor_p flag set. */
13871 int match_with_avoid_cursor
= 0;
13872 /* Non-zero means we've seen at least one glyph that came from a
13874 int string_seen
= 0;
13875 /* Largest and smallest buffer positions seen so far during scan of
13877 ptrdiff_t bpos_max
= pos_before
;
13878 ptrdiff_t bpos_min
= pos_after
;
13879 /* Last buffer position covered by an overlay string with an integer
13880 `cursor' property. */
13881 ptrdiff_t bpos_covered
= 0;
13882 /* Non-zero means the display string on which to display the cursor
13883 comes from a text property, not from an overlay. */
13884 int string_from_text_prop
= 0;
13886 /* Don't even try doing anything if called for a mode-line or
13887 header-line row, since the rest of the code isn't prepared to
13888 deal with such calamities. */
13889 eassert (!row
->mode_line_p
);
13890 if (row
->mode_line_p
)
13893 /* Skip over glyphs not having an object at the start and the end of
13894 the row. These are special glyphs like truncation marks on
13895 terminal frames. */
13896 if (row
->displays_text_p
)
13898 if (!row
->reversed_p
)
13901 && INTEGERP (glyph
->object
)
13902 && glyph
->charpos
< 0)
13904 x
+= glyph
->pixel_width
;
13908 && INTEGERP ((end
- 1)->object
)
13909 /* CHARPOS is zero for blanks and stretch glyphs
13910 inserted by extend_face_to_end_of_line. */
13911 && (end
- 1)->charpos
<= 0)
13913 glyph_before
= glyph
- 1;
13920 /* If the glyph row is reversed, we need to process it from back
13921 to front, so swap the edge pointers. */
13922 glyphs_end
= end
= glyph
- 1;
13923 glyph
+= row
->used
[TEXT_AREA
] - 1;
13925 while (glyph
> end
+ 1
13926 && INTEGERP (glyph
->object
)
13927 && glyph
->charpos
< 0)
13930 x
-= glyph
->pixel_width
;
13932 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13934 /* By default, in reversed rows we put the cursor on the
13935 rightmost (first in the reading order) glyph. */
13936 for (g
= end
+ 1; g
< glyph
; g
++)
13937 x
+= g
->pixel_width
;
13939 && INTEGERP ((end
+ 1)->object
)
13940 && (end
+ 1)->charpos
<= 0)
13942 glyph_before
= glyph
+ 1;
13946 else if (row
->reversed_p
)
13948 /* In R2L rows that don't display text, put the cursor on the
13949 rightmost glyph. Case in point: an empty last line that is
13950 part of an R2L paragraph. */
13952 /* Avoid placing the cursor on the last glyph of the row, where
13953 on terminal frames we hold the vertical border between
13954 adjacent windows. */
13955 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13956 && !WINDOW_RIGHTMOST_P (w
)
13957 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13959 x
= -1; /* will be computed below, at label compute_x */
13962 /* Step 1: Try to find the glyph whose character position
13963 corresponds to point. If that's not possible, find 2 glyphs
13964 whose character positions are the closest to point, one before
13965 point, the other after it. */
13966 if (!row
->reversed_p
)
13967 while (/* not marched to end of glyph row */
13969 /* glyph was not inserted by redisplay for internal purposes */
13970 && !INTEGERP (glyph
->object
))
13972 if (BUFFERP (glyph
->object
))
13974 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13976 if (glyph
->charpos
> bpos_max
)
13977 bpos_max
= glyph
->charpos
;
13978 if (glyph
->charpos
< bpos_min
)
13979 bpos_min
= glyph
->charpos
;
13980 if (!glyph
->avoid_cursor_p
)
13982 /* If we hit point, we've found the glyph on which to
13983 display the cursor. */
13986 match_with_avoid_cursor
= 0;
13989 /* See if we've found a better approximation to
13990 POS_BEFORE or to POS_AFTER. */
13991 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13993 pos_before
= glyph
->charpos
;
13994 glyph_before
= glyph
;
13996 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13998 pos_after
= glyph
->charpos
;
13999 glyph_after
= glyph
;
14002 else if (dpos
== 0)
14003 match_with_avoid_cursor
= 1;
14005 else if (STRINGP (glyph
->object
))
14007 Lisp_Object chprop
;
14008 ptrdiff_t glyph_pos
= glyph
->charpos
;
14010 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14012 if (!NILP (chprop
))
14014 /* If the string came from a `display' text property,
14015 look up the buffer position of that property and
14016 use that position to update bpos_max, as if we
14017 actually saw such a position in one of the row's
14018 glyphs. This helps with supporting integer values
14019 of `cursor' property on the display string in
14020 situations where most or all of the row's buffer
14021 text is completely covered by display properties,
14022 so that no glyph with valid buffer positions is
14023 ever seen in the row. */
14024 ptrdiff_t prop_pos
=
14025 string_buffer_position_lim (glyph
->object
, pos_before
,
14028 if (prop_pos
>= pos_before
)
14029 bpos_max
= prop_pos
- 1;
14031 if (INTEGERP (chprop
))
14033 bpos_covered
= bpos_max
+ XINT (chprop
);
14034 /* If the `cursor' property covers buffer positions up
14035 to and including point, we should display cursor on
14036 this glyph. Note that, if a `cursor' property on one
14037 of the string's characters has an integer value, we
14038 will break out of the loop below _before_ we get to
14039 the position match above. IOW, integer values of
14040 the `cursor' property override the "exact match for
14041 point" strategy of positioning the cursor. */
14042 /* Implementation note: bpos_max == pt_old when, e.g.,
14043 we are in an empty line, where bpos_max is set to
14044 MATRIX_ROW_START_CHARPOS, see above. */
14045 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14054 x
+= glyph
->pixel_width
;
14057 else if (glyph
> end
) /* row is reversed */
14058 while (!INTEGERP (glyph
->object
))
14060 if (BUFFERP (glyph
->object
))
14062 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14064 if (glyph
->charpos
> bpos_max
)
14065 bpos_max
= glyph
->charpos
;
14066 if (glyph
->charpos
< bpos_min
)
14067 bpos_min
= glyph
->charpos
;
14068 if (!glyph
->avoid_cursor_p
)
14072 match_with_avoid_cursor
= 0;
14075 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14077 pos_before
= glyph
->charpos
;
14078 glyph_before
= glyph
;
14080 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14082 pos_after
= glyph
->charpos
;
14083 glyph_after
= glyph
;
14086 else if (dpos
== 0)
14087 match_with_avoid_cursor
= 1;
14089 else if (STRINGP (glyph
->object
))
14091 Lisp_Object chprop
;
14092 ptrdiff_t glyph_pos
= glyph
->charpos
;
14094 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14096 if (!NILP (chprop
))
14098 ptrdiff_t prop_pos
=
14099 string_buffer_position_lim (glyph
->object
, pos_before
,
14102 if (prop_pos
>= pos_before
)
14103 bpos_max
= prop_pos
- 1;
14105 if (INTEGERP (chprop
))
14107 bpos_covered
= bpos_max
+ XINT (chprop
);
14108 /* If the `cursor' property covers buffer positions up
14109 to and including point, we should display cursor on
14111 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14120 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14122 x
--; /* can't use any pixel_width */
14125 x
-= glyph
->pixel_width
;
14128 /* Step 2: If we didn't find an exact match for point, we need to
14129 look for a proper place to put the cursor among glyphs between
14130 GLYPH_BEFORE and GLYPH_AFTER. */
14131 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14132 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14133 && bpos_covered
< pt_old
)
14135 /* An empty line has a single glyph whose OBJECT is zero and
14136 whose CHARPOS is the position of a newline on that line.
14137 Note that on a TTY, there are more glyphs after that, which
14138 were produced by extend_face_to_end_of_line, but their
14139 CHARPOS is zero or negative. */
14141 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14142 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14144 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14146 ptrdiff_t ellipsis_pos
;
14148 /* Scan back over the ellipsis glyphs. */
14149 if (!row
->reversed_p
)
14151 ellipsis_pos
= (glyph
- 1)->charpos
;
14152 while (glyph
> row
->glyphs
[TEXT_AREA
]
14153 && (glyph
- 1)->charpos
== ellipsis_pos
)
14154 glyph
--, x
-= glyph
->pixel_width
;
14155 /* That loop always goes one position too far, including
14156 the glyph before the ellipsis. So scan forward over
14158 x
+= glyph
->pixel_width
;
14161 else /* row is reversed */
14163 ellipsis_pos
= (glyph
+ 1)->charpos
;
14164 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14165 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14166 glyph
++, x
+= glyph
->pixel_width
;
14167 x
-= glyph
->pixel_width
;
14171 else if (match_with_avoid_cursor
)
14173 cursor
= glyph_after
;
14176 else if (string_seen
)
14178 int incr
= row
->reversed_p
? -1 : +1;
14180 /* Need to find the glyph that came out of a string which is
14181 present at point. That glyph is somewhere between
14182 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14183 positioned between POS_BEFORE and POS_AFTER in the
14185 struct glyph
*start
, *stop
;
14186 ptrdiff_t pos
= pos_before
;
14190 /* If the row ends in a newline from a display string,
14191 reordering could have moved the glyphs belonging to the
14192 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14193 in this case we extend the search to the last glyph in
14194 the row that was not inserted by redisplay. */
14195 if (row
->ends_in_newline_from_string_p
)
14198 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14201 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14202 correspond to POS_BEFORE and POS_AFTER, respectively. We
14203 need START and STOP in the order that corresponds to the
14204 row's direction as given by its reversed_p flag. If the
14205 directionality of characters between POS_BEFORE and
14206 POS_AFTER is the opposite of the row's base direction,
14207 these characters will have been reordered for display,
14208 and we need to reverse START and STOP. */
14209 if (!row
->reversed_p
)
14211 start
= min (glyph_before
, glyph_after
);
14212 stop
= max (glyph_before
, glyph_after
);
14216 start
= max (glyph_before
, glyph_after
);
14217 stop
= min (glyph_before
, glyph_after
);
14219 for (glyph
= start
+ incr
;
14220 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14223 /* Any glyphs that come from the buffer are here because
14224 of bidi reordering. Skip them, and only pay
14225 attention to glyphs that came from some string. */
14226 if (STRINGP (glyph
->object
))
14230 /* If the display property covers the newline, we
14231 need to search for it one position farther. */
14232 ptrdiff_t lim
= pos_after
14233 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14235 string_from_text_prop
= 0;
14236 str
= glyph
->object
;
14237 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14238 if (tem
== 0 /* from overlay */
14241 /* If the string from which this glyph came is
14242 found in the buffer at point, or at position
14243 that is closer to point than pos_after, then
14244 we've found the glyph we've been looking for.
14245 If it comes from an overlay (tem == 0), and
14246 it has the `cursor' property on one of its
14247 glyphs, record that glyph as a candidate for
14248 displaying the cursor. (As in the
14249 unidirectional version, we will display the
14250 cursor on the last candidate we find.) */
14253 || (tem
- pt_old
> 0 && tem
< pos_after
))
14255 /* The glyphs from this string could have
14256 been reordered. Find the one with the
14257 smallest string position. Or there could
14258 be a character in the string with the
14259 `cursor' property, which means display
14260 cursor on that character's glyph. */
14261 ptrdiff_t strpos
= glyph
->charpos
;
14266 string_from_text_prop
= 1;
14269 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14270 && EQ (glyph
->object
, str
);
14274 ptrdiff_t gpos
= glyph
->charpos
;
14276 cprop
= Fget_char_property (make_number (gpos
),
14284 if (tem
&& glyph
->charpos
< strpos
)
14286 strpos
= glyph
->charpos
;
14292 || (tem
- pt_old
> 0 && tem
< pos_after
))
14296 pos
= tem
+ 1; /* don't find previous instances */
14298 /* This string is not what we want; skip all of the
14299 glyphs that came from it. */
14300 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14301 && EQ (glyph
->object
, str
))
14308 /* If we reached the end of the line, and END was from a string,
14309 the cursor is not on this line. */
14311 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14312 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14313 && STRINGP (end
->object
)
14314 && row
->continued_p
)
14317 /* A truncated row may not include PT among its character positions.
14318 Setting the cursor inside the scroll margin will trigger
14319 recalculation of hscroll in hscroll_window_tree. But if a
14320 display string covers point, defer to the string-handling
14321 code below to figure this out. */
14322 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14324 cursor
= glyph_before
;
14327 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14328 /* Zero-width characters produce no glyphs. */
14330 && (row
->reversed_p
14331 ? glyph_after
> glyphs_end
14332 : glyph_after
< glyphs_end
)))
14334 cursor
= glyph_after
;
14340 if (cursor
!= NULL
)
14342 else if (glyph
== glyphs_end
14343 && pos_before
== pos_after
14344 && STRINGP ((row
->reversed_p
14345 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14346 : row
->glyphs
[TEXT_AREA
])->object
))
14348 /* If all the glyphs of this row came from strings, put the
14349 cursor on the first glyph of the row. This avoids having the
14350 cursor outside of the text area in this very rare and hard
14354 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14355 : row
->glyphs
[TEXT_AREA
];
14361 /* Need to compute x that corresponds to GLYPH. */
14362 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14364 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14366 x
+= g
->pixel_width
;
14370 /* ROW could be part of a continued line, which, under bidi
14371 reordering, might have other rows whose start and end charpos
14372 occlude point. Only set w->cursor if we found a better
14373 approximation to the cursor position than we have from previously
14374 examined candidate rows belonging to the same continued line. */
14375 if (/* we already have a candidate row */
14376 w
->cursor
.vpos
>= 0
14377 /* that candidate is not the row we are processing */
14378 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14379 /* Make sure cursor.vpos specifies a row whose start and end
14380 charpos occlude point, and it is valid candidate for being a
14381 cursor-row. This is because some callers of this function
14382 leave cursor.vpos at the row where the cursor was displayed
14383 during the last redisplay cycle. */
14384 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14385 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14386 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14389 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14391 /* Don't consider glyphs that are outside TEXT_AREA. */
14392 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14394 /* Keep the candidate whose buffer position is the closest to
14395 point or has the `cursor' property. */
14396 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14397 w
->cursor
.hpos
>= 0
14398 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14399 && ((BUFFERP (g1
->object
)
14400 && (g1
->charpos
== pt_old
/* an exact match always wins */
14401 || (BUFFERP (glyph
->object
)
14402 && eabs (g1
->charpos
- pt_old
)
14403 < eabs (glyph
->charpos
- pt_old
))))
14404 /* previous candidate is a glyph from a string that has
14405 a non-nil `cursor' property */
14406 || (STRINGP (g1
->object
)
14407 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14408 Qcursor
, g1
->object
))
14409 /* previous candidate is from the same display
14410 string as this one, and the display string
14411 came from a text property */
14412 || (EQ (g1
->object
, glyph
->object
)
14413 && string_from_text_prop
)
14414 /* this candidate is from newline and its
14415 position is not an exact match */
14416 || (INTEGERP (glyph
->object
)
14417 && glyph
->charpos
!= pt_old
)))))
14419 /* If this candidate gives an exact match, use that. */
14420 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14421 /* If this candidate is a glyph created for the
14422 terminating newline of a line, and point is on that
14423 newline, it wins because it's an exact match. */
14424 || (!row
->continued_p
14425 && INTEGERP (glyph
->object
)
14426 && glyph
->charpos
== 0
14427 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14428 /* Otherwise, keep the candidate that comes from a row
14429 spanning less buffer positions. This may win when one or
14430 both candidate positions are on glyphs that came from
14431 display strings, for which we cannot compare buffer
14433 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14434 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14435 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14438 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14440 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14441 w
->cursor
.y
= row
->y
+ dy
;
14443 if (w
== XWINDOW (selected_window
))
14445 if (!row
->continued_p
14446 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14449 this_line_buffer
= XBUFFER (w
->buffer
);
14451 CHARPOS (this_line_start_pos
)
14452 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14453 BYTEPOS (this_line_start_pos
)
14454 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14456 CHARPOS (this_line_end_pos
)
14457 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14458 BYTEPOS (this_line_end_pos
)
14459 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14461 this_line_y
= w
->cursor
.y
;
14462 this_line_pixel_height
= row
->height
;
14463 this_line_vpos
= w
->cursor
.vpos
;
14464 this_line_start_x
= row
->x
;
14467 CHARPOS (this_line_start_pos
) = 0;
14474 /* Run window scroll functions, if any, for WINDOW with new window
14475 start STARTP. Sets the window start of WINDOW to that position.
14477 We assume that the window's buffer is really current. */
14479 static inline struct text_pos
14480 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14482 struct window
*w
= XWINDOW (window
);
14483 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14485 if (current_buffer
!= XBUFFER (w
->buffer
))
14488 if (!NILP (Vwindow_scroll_functions
))
14490 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14491 make_number (CHARPOS (startp
)));
14492 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14493 /* In case the hook functions switch buffers. */
14494 if (current_buffer
!= XBUFFER (w
->buffer
))
14495 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14502 /* Make sure the line containing the cursor is fully visible.
14503 A value of 1 means there is nothing to be done.
14504 (Either the line is fully visible, or it cannot be made so,
14505 or we cannot tell.)
14507 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14508 is higher than window.
14510 A value of 0 means the caller should do scrolling
14511 as if point had gone off the screen. */
14514 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14516 struct glyph_matrix
*matrix
;
14517 struct glyph_row
*row
;
14520 if (!make_cursor_line_fully_visible_p
)
14523 /* It's not always possible to find the cursor, e.g, when a window
14524 is full of overlay strings. Don't do anything in that case. */
14525 if (w
->cursor
.vpos
< 0)
14528 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14529 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14531 /* If the cursor row is not partially visible, there's nothing to do. */
14532 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14535 /* If the row the cursor is in is taller than the window's height,
14536 it's not clear what to do, so do nothing. */
14537 window_height
= window_box_height (w
);
14538 if (row
->height
>= window_height
)
14540 if (!force_p
|| MINI_WINDOW_P (w
)
14541 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14548 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14549 non-zero means only WINDOW is redisplayed in redisplay_internal.
14550 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14551 in redisplay_window to bring a partially visible line into view in
14552 the case that only the cursor has moved.
14554 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14555 last screen line's vertical height extends past the end of the screen.
14559 1 if scrolling succeeded
14561 0 if scrolling didn't find point.
14563 -1 if new fonts have been loaded so that we must interrupt
14564 redisplay, adjust glyph matrices, and try again. */
14570 SCROLLING_NEED_LARGER_MATRICES
14573 /* If scroll-conservatively is more than this, never recenter.
14575 If you change this, don't forget to update the doc string of
14576 `scroll-conservatively' and the Emacs manual. */
14577 #define SCROLL_LIMIT 100
14580 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14581 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14582 int temp_scroll_step
, int last_line_misfit
)
14584 struct window
*w
= XWINDOW (window
);
14585 struct frame
*f
= XFRAME (w
->frame
);
14586 struct text_pos pos
, startp
;
14588 int this_scroll_margin
, scroll_max
, rc
, height
;
14589 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14590 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14591 Lisp_Object aggressive
;
14592 /* We will never try scrolling more than this number of lines. */
14593 int scroll_limit
= SCROLL_LIMIT
;
14596 debug_method_add (w
, "try_scrolling");
14599 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14601 /* Compute scroll margin height in pixels. We scroll when point is
14602 within this distance from the top or bottom of the window. */
14603 if (scroll_margin
> 0)
14604 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14605 * FRAME_LINE_HEIGHT (f
);
14607 this_scroll_margin
= 0;
14609 /* Force arg_scroll_conservatively to have a reasonable value, to
14610 avoid scrolling too far away with slow move_it_* functions. Note
14611 that the user can supply scroll-conservatively equal to
14612 `most-positive-fixnum', which can be larger than INT_MAX. */
14613 if (arg_scroll_conservatively
> scroll_limit
)
14615 arg_scroll_conservatively
= scroll_limit
+ 1;
14616 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14618 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14619 /* Compute how much we should try to scroll maximally to bring
14620 point into view. */
14621 scroll_max
= (max (scroll_step
,
14622 max (arg_scroll_conservatively
, temp_scroll_step
))
14623 * FRAME_LINE_HEIGHT (f
));
14624 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14625 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14626 /* We're trying to scroll because of aggressive scrolling but no
14627 scroll_step is set. Choose an arbitrary one. */
14628 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14634 /* Decide whether to scroll down. */
14635 if (PT
> CHARPOS (startp
))
14637 int scroll_margin_y
;
14639 /* Compute the pixel ypos of the scroll margin, then move IT to
14640 either that ypos or PT, whichever comes first. */
14641 start_display (&it
, w
, startp
);
14642 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14643 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14644 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14645 (MOVE_TO_POS
| MOVE_TO_Y
));
14647 if (PT
> CHARPOS (it
.current
.pos
))
14649 int y0
= line_bottom_y (&it
);
14650 /* Compute how many pixels below window bottom to stop searching
14651 for PT. This avoids costly search for PT that is far away if
14652 the user limited scrolling by a small number of lines, but
14653 always finds PT if scroll_conservatively is set to a large
14654 number, such as most-positive-fixnum. */
14655 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14656 int y_to_move
= it
.last_visible_y
+ slack
;
14658 /* Compute the distance from the scroll margin to PT or to
14659 the scroll limit, whichever comes first. This should
14660 include the height of the cursor line, to make that line
14662 move_it_to (&it
, PT
, -1, y_to_move
,
14663 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14664 dy
= line_bottom_y (&it
) - y0
;
14666 if (dy
> scroll_max
)
14667 return SCROLLING_FAILED
;
14676 /* Point is in or below the bottom scroll margin, so move the
14677 window start down. If scrolling conservatively, move it just
14678 enough down to make point visible. If scroll_step is set,
14679 move it down by scroll_step. */
14680 if (arg_scroll_conservatively
)
14682 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14683 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14684 else if (scroll_step
|| temp_scroll_step
)
14685 amount_to_scroll
= scroll_max
;
14688 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14689 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14690 if (NUMBERP (aggressive
))
14692 double float_amount
= XFLOATINT (aggressive
) * height
;
14693 amount_to_scroll
= float_amount
;
14694 if (amount_to_scroll
== 0 && float_amount
> 0)
14695 amount_to_scroll
= 1;
14696 /* Don't let point enter the scroll margin near top of
14698 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14699 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14703 if (amount_to_scroll
<= 0)
14704 return SCROLLING_FAILED
;
14706 start_display (&it
, w
, startp
);
14707 if (arg_scroll_conservatively
<= scroll_limit
)
14708 move_it_vertically (&it
, amount_to_scroll
);
14711 /* Extra precision for users who set scroll-conservatively
14712 to a large number: make sure the amount we scroll
14713 the window start is never less than amount_to_scroll,
14714 which was computed as distance from window bottom to
14715 point. This matters when lines at window top and lines
14716 below window bottom have different height. */
14718 void *it1data
= NULL
;
14719 /* We use a temporary it1 because line_bottom_y can modify
14720 its argument, if it moves one line down; see there. */
14723 SAVE_IT (it1
, it
, it1data
);
14724 start_y
= line_bottom_y (&it1
);
14726 RESTORE_IT (&it
, &it
, it1data
);
14727 move_it_by_lines (&it
, 1);
14728 SAVE_IT (it1
, it
, it1data
);
14729 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14732 /* If STARTP is unchanged, move it down another screen line. */
14733 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14734 move_it_by_lines (&it
, 1);
14735 startp
= it
.current
.pos
;
14739 struct text_pos scroll_margin_pos
= startp
;
14741 /* See if point is inside the scroll margin at the top of the
14743 if (this_scroll_margin
)
14745 start_display (&it
, w
, startp
);
14746 move_it_vertically (&it
, this_scroll_margin
);
14747 scroll_margin_pos
= it
.current
.pos
;
14750 if (PT
< CHARPOS (scroll_margin_pos
))
14752 /* Point is in the scroll margin at the top of the window or
14753 above what is displayed in the window. */
14756 /* Compute the vertical distance from PT to the scroll
14757 margin position. Move as far as scroll_max allows, or
14758 one screenful, or 10 screen lines, whichever is largest.
14759 Give up if distance is greater than scroll_max. */
14760 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14761 start_display (&it
, w
, pos
);
14763 y_to_move
= max (it
.last_visible_y
,
14764 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14765 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14767 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14768 dy
= it
.current_y
- y0
;
14769 if (dy
> scroll_max
)
14770 return SCROLLING_FAILED
;
14772 /* Compute new window start. */
14773 start_display (&it
, w
, startp
);
14775 if (arg_scroll_conservatively
)
14776 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14777 max (scroll_step
, temp_scroll_step
));
14778 else if (scroll_step
|| temp_scroll_step
)
14779 amount_to_scroll
= scroll_max
;
14782 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14783 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14784 if (NUMBERP (aggressive
))
14786 double float_amount
= XFLOATINT (aggressive
) * height
;
14787 amount_to_scroll
= float_amount
;
14788 if (amount_to_scroll
== 0 && float_amount
> 0)
14789 amount_to_scroll
= 1;
14790 amount_to_scroll
-=
14791 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14792 /* Don't let point enter the scroll margin near
14793 bottom of the window. */
14794 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14795 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14799 if (amount_to_scroll
<= 0)
14800 return SCROLLING_FAILED
;
14802 move_it_vertically_backward (&it
, amount_to_scroll
);
14803 startp
= it
.current
.pos
;
14807 /* Run window scroll functions. */
14808 startp
= run_window_scroll_functions (window
, startp
);
14810 /* Display the window. Give up if new fonts are loaded, or if point
14812 if (!try_window (window
, startp
, 0))
14813 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14814 else if (w
->cursor
.vpos
< 0)
14816 clear_glyph_matrix (w
->desired_matrix
);
14817 rc
= SCROLLING_FAILED
;
14821 /* Maybe forget recorded base line for line number display. */
14822 if (!just_this_one_p
14823 || current_buffer
->clip_changed
14824 || BEG_UNCHANGED
< CHARPOS (startp
))
14825 w
->base_line_number
= Qnil
;
14827 /* If cursor ends up on a partially visible line,
14828 treat that as being off the bottom of the screen. */
14829 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14830 /* It's possible that the cursor is on the first line of the
14831 buffer, which is partially obscured due to a vscroll
14832 (Bug#7537). In that case, avoid looping forever . */
14833 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14835 clear_glyph_matrix (w
->desired_matrix
);
14836 ++extra_scroll_margin_lines
;
14839 rc
= SCROLLING_SUCCESS
;
14846 /* Compute a suitable window start for window W if display of W starts
14847 on a continuation line. Value is non-zero if a new window start
14850 The new window start will be computed, based on W's width, starting
14851 from the start of the continued line. It is the start of the
14852 screen line with the minimum distance from the old start W->start. */
14855 compute_window_start_on_continuation_line (struct window
*w
)
14857 struct text_pos pos
, start_pos
;
14858 int window_start_changed_p
= 0;
14860 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14862 /* If window start is on a continuation line... Window start may be
14863 < BEGV in case there's invisible text at the start of the
14864 buffer (M-x rmail, for example). */
14865 if (CHARPOS (start_pos
) > BEGV
14866 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14869 struct glyph_row
*row
;
14871 /* Handle the case that the window start is out of range. */
14872 if (CHARPOS (start_pos
) < BEGV
)
14873 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14874 else if (CHARPOS (start_pos
) > ZV
)
14875 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14877 /* Find the start of the continued line. This should be fast
14878 because scan_buffer is fast (newline cache). */
14879 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14880 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14881 row
, DEFAULT_FACE_ID
);
14882 reseat_at_previous_visible_line_start (&it
);
14884 /* If the line start is "too far" away from the window start,
14885 say it takes too much time to compute a new window start. */
14886 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14887 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14889 int min_distance
, distance
;
14891 /* Move forward by display lines to find the new window
14892 start. If window width was enlarged, the new start can
14893 be expected to be > the old start. If window width was
14894 decreased, the new window start will be < the old start.
14895 So, we're looking for the display line start with the
14896 minimum distance from the old window start. */
14897 pos
= it
.current
.pos
;
14898 min_distance
= INFINITY
;
14899 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14900 distance
< min_distance
)
14902 min_distance
= distance
;
14903 pos
= it
.current
.pos
;
14904 move_it_by_lines (&it
, 1);
14907 /* Set the window start there. */
14908 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14909 window_start_changed_p
= 1;
14913 return window_start_changed_p
;
14917 /* Try cursor movement in case text has not changed in window WINDOW,
14918 with window start STARTP. Value is
14920 CURSOR_MOVEMENT_SUCCESS if successful
14922 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14924 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14925 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14926 we want to scroll as if scroll-step were set to 1. See the code.
14928 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14929 which case we have to abort this redisplay, and adjust matrices
14934 CURSOR_MOVEMENT_SUCCESS
,
14935 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14936 CURSOR_MOVEMENT_MUST_SCROLL
,
14937 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14941 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14943 struct window
*w
= XWINDOW (window
);
14944 struct frame
*f
= XFRAME (w
->frame
);
14945 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14948 if (inhibit_try_cursor_movement
)
14952 /* Previously, there was a check for Lisp integer in the
14953 if-statement below. Now, this field is converted to
14954 ptrdiff_t, thus zero means invalid position in a buffer. */
14955 eassert (w
->last_point
> 0);
14957 /* Handle case where text has not changed, only point, and it has
14958 not moved off the frame. */
14959 if (/* Point may be in this window. */
14960 PT
>= CHARPOS (startp
)
14961 /* Selective display hasn't changed. */
14962 && !current_buffer
->clip_changed
14963 /* Function force-mode-line-update is used to force a thorough
14964 redisplay. It sets either windows_or_buffers_changed or
14965 update_mode_lines. So don't take a shortcut here for these
14967 && !update_mode_lines
14968 && !windows_or_buffers_changed
14969 && !cursor_type_changed
14970 /* Can't use this case if highlighting a region. When a
14971 region exists, cursor movement has to do more than just
14973 && !(!NILP (Vtransient_mark_mode
)
14974 && !NILP (BVAR (current_buffer
, mark_active
)))
14975 && NILP (w
->region_showing
)
14976 && NILP (Vshow_trailing_whitespace
)
14977 /* This code is not used for mini-buffer for the sake of the case
14978 of redisplaying to replace an echo area message; since in
14979 that case the mini-buffer contents per se are usually
14980 unchanged. This code is of no real use in the mini-buffer
14981 since the handling of this_line_start_pos, etc., in redisplay
14982 handles the same cases. */
14983 && !EQ (window
, minibuf_window
)
14984 /* When splitting windows or for new windows, it happens that
14985 redisplay is called with a nil window_end_vpos or one being
14986 larger than the window. This should really be fixed in
14987 window.c. I don't have this on my list, now, so we do
14988 approximately the same as the old redisplay code. --gerd. */
14989 && INTEGERP (w
->window_end_vpos
)
14990 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14991 && (FRAME_WINDOW_P (f
)
14992 || !overlay_arrow_in_current_buffer_p ()))
14994 int this_scroll_margin
, top_scroll_margin
;
14995 struct glyph_row
*row
= NULL
;
14998 debug_method_add (w
, "cursor movement");
15001 /* Scroll if point within this distance from the top or bottom
15002 of the window. This is a pixel value. */
15003 if (scroll_margin
> 0)
15005 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15006 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15009 this_scroll_margin
= 0;
15011 top_scroll_margin
= this_scroll_margin
;
15012 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15013 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15015 /* Start with the row the cursor was displayed during the last
15016 not paused redisplay. Give up if that row is not valid. */
15017 if (w
->last_cursor
.vpos
< 0
15018 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15019 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15022 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15023 if (row
->mode_line_p
)
15025 if (!row
->enabled_p
)
15026 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15029 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15031 int scroll_p
= 0, must_scroll
= 0;
15032 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15034 if (PT
> w
->last_point
)
15036 /* Point has moved forward. */
15037 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15038 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15040 eassert (row
->enabled_p
);
15044 /* If the end position of a row equals the start
15045 position of the next row, and PT is at that position,
15046 we would rather display cursor in the next line. */
15047 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15048 && MATRIX_ROW_END_CHARPOS (row
) == PT
15049 && row
< w
->current_matrix
->rows
15050 + w
->current_matrix
->nrows
- 1
15051 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15052 && !cursor_row_p (row
))
15055 /* If within the scroll margin, scroll. Note that
15056 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15057 the next line would be drawn, and that
15058 this_scroll_margin can be zero. */
15059 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15060 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15061 /* Line is completely visible last line in window
15062 and PT is to be set in the next line. */
15063 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15064 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15065 && !row
->ends_at_zv_p
15066 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15069 else if (PT
< w
->last_point
)
15071 /* Cursor has to be moved backward. Note that PT >=
15072 CHARPOS (startp) because of the outer if-statement. */
15073 while (!row
->mode_line_p
15074 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15075 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15076 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15077 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15078 row
> w
->current_matrix
->rows
15079 && (row
-1)->ends_in_newline_from_string_p
))))
15080 && (row
->y
> top_scroll_margin
15081 || CHARPOS (startp
) == BEGV
))
15083 eassert (row
->enabled_p
);
15087 /* Consider the following case: Window starts at BEGV,
15088 there is invisible, intangible text at BEGV, so that
15089 display starts at some point START > BEGV. It can
15090 happen that we are called with PT somewhere between
15091 BEGV and START. Try to handle that case. */
15092 if (row
< w
->current_matrix
->rows
15093 || row
->mode_line_p
)
15095 row
= w
->current_matrix
->rows
;
15096 if (row
->mode_line_p
)
15100 /* Due to newlines in overlay strings, we may have to
15101 skip forward over overlay strings. */
15102 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15103 && MATRIX_ROW_END_CHARPOS (row
) == PT
15104 && !cursor_row_p (row
))
15107 /* If within the scroll margin, scroll. */
15108 if (row
->y
< top_scroll_margin
15109 && CHARPOS (startp
) != BEGV
)
15114 /* Cursor did not move. So don't scroll even if cursor line
15115 is partially visible, as it was so before. */
15116 rc
= CURSOR_MOVEMENT_SUCCESS
;
15119 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15120 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15122 /* if PT is not in the glyph row, give up. */
15123 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15126 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15127 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15129 struct glyph_row
*row1
;
15131 /* If rows are bidi-reordered and point moved, back up
15132 until we find a row that does not belong to a
15133 continuation line. This is because we must consider
15134 all rows of a continued line as candidates for the
15135 new cursor positioning, since row start and end
15136 positions change non-linearly with vertical position
15138 /* FIXME: Revisit this when glyph ``spilling'' in
15139 continuation lines' rows is implemented for
15140 bidi-reordered rows. */
15141 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15142 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15145 /* If we hit the beginning of the displayed portion
15146 without finding the first row of a continued
15150 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15153 eassert (row
->enabled_p
);
15158 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15159 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15160 /* Make sure this isn't a header line by any chance, since
15161 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15162 && !row
->mode_line_p
15163 && make_cursor_line_fully_visible_p
)
15165 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15166 && !row
->ends_at_zv_p
15167 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15168 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15169 else if (row
->height
> window_box_height (w
))
15171 /* If we end up in a partially visible line, let's
15172 make it fully visible, except when it's taller
15173 than the window, in which case we can't do much
15176 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15180 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15181 if (!cursor_row_fully_visible_p (w
, 0, 1))
15182 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15184 rc
= CURSOR_MOVEMENT_SUCCESS
;
15188 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15189 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15190 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15192 /* With bidi-reordered rows, there could be more than
15193 one candidate row whose start and end positions
15194 occlude point. We need to let set_cursor_from_row
15195 find the best candidate. */
15196 /* FIXME: Revisit this when glyph ``spilling'' in
15197 continuation lines' rows is implemented for
15198 bidi-reordered rows. */
15203 int at_zv_p
= 0, exact_match_p
= 0;
15205 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15206 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15207 && cursor_row_p (row
))
15208 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15210 /* As soon as we've found the exact match for point,
15211 or the first suitable row whose ends_at_zv_p flag
15212 is set, we are done. */
15214 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15216 && w
->cursor
.hpos
>= 0
15217 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15220 struct glyph_row
*candidate
=
15221 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15223 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15224 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15227 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15228 || (INTEGERP (g
->object
)
15229 && (g
->charpos
== PT
15230 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15232 if (rv
&& (at_zv_p
|| exact_match_p
))
15234 rc
= CURSOR_MOVEMENT_SUCCESS
;
15237 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15241 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15242 || row
->continued_p
)
15243 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15244 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15245 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15246 /* If we didn't find any candidate rows, or exited the
15247 loop before all the candidates were examined, signal
15248 to the caller that this method failed. */
15249 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15251 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15252 && !row
->continued_p
))
15253 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15255 rc
= CURSOR_MOVEMENT_SUCCESS
;
15261 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15263 rc
= CURSOR_MOVEMENT_SUCCESS
;
15268 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15269 && MATRIX_ROW_START_CHARPOS (row
) == PT
15270 && cursor_row_p (row
));
15278 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15282 set_vertical_scroll_bar (struct window
*w
)
15284 ptrdiff_t start
, end
, whole
;
15286 /* Calculate the start and end positions for the current window.
15287 At some point, it would be nice to choose between scrollbars
15288 which reflect the whole buffer size, with special markers
15289 indicating narrowing, and scrollbars which reflect only the
15292 Note that mini-buffers sometimes aren't displaying any text. */
15293 if (!MINI_WINDOW_P (w
)
15294 || (w
== XWINDOW (minibuf_window
)
15295 && NILP (echo_area_buffer
[0])))
15297 struct buffer
*buf
= XBUFFER (w
->buffer
);
15298 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15299 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15300 /* I don't think this is guaranteed to be right. For the
15301 moment, we'll pretend it is. */
15302 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15306 if (whole
< (end
- start
))
15307 whole
= end
- start
;
15310 start
= end
= whole
= 0;
15312 /* Indicate what this scroll bar ought to be displaying now. */
15313 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15314 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15315 (w
, end
- start
, whole
, start
);
15319 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15320 selected_window is redisplayed.
15322 We can return without actually redisplaying the window if
15323 fonts_changed_p is nonzero. In that case, redisplay_internal will
15327 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15329 struct window
*w
= XWINDOW (window
);
15330 struct frame
*f
= XFRAME (w
->frame
);
15331 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15332 struct buffer
*old
= current_buffer
;
15333 struct text_pos lpoint
, opoint
, startp
;
15334 int update_mode_line
;
15337 /* Record it now because it's overwritten. */
15338 int current_matrix_up_to_date_p
= 0;
15339 int used_current_matrix_p
= 0;
15340 /* This is less strict than current_matrix_up_to_date_p.
15341 It indicates that the buffer contents and narrowing are unchanged. */
15342 int buffer_unchanged_p
= 0;
15343 int temp_scroll_step
= 0;
15344 ptrdiff_t count
= SPECPDL_INDEX ();
15346 int centering_position
= -1;
15347 int last_line_misfit
= 0;
15348 ptrdiff_t beg_unchanged
, end_unchanged
;
15350 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15353 /* W must be a leaf window here. */
15354 eassert (!NILP (w
->buffer
));
15356 *w
->desired_matrix
->method
= 0;
15360 reconsider_clip_changes (w
, buffer
);
15362 /* Has the mode line to be updated? */
15363 update_mode_line
= (w
->update_mode_line
15364 || update_mode_lines
15365 || buffer
->clip_changed
15366 || buffer
->prevent_redisplay_optimizations_p
);
15368 if (MINI_WINDOW_P (w
))
15370 if (w
== XWINDOW (echo_area_window
)
15371 && !NILP (echo_area_buffer
[0]))
15373 if (update_mode_line
)
15374 /* We may have to update a tty frame's menu bar or a
15375 tool-bar. Example `M-x C-h C-h C-g'. */
15376 goto finish_menu_bars
;
15378 /* We've already displayed the echo area glyphs in this window. */
15379 goto finish_scroll_bars
;
15381 else if ((w
!= XWINDOW (minibuf_window
)
15382 || minibuf_level
== 0)
15383 /* When buffer is nonempty, redisplay window normally. */
15384 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15385 /* Quail displays non-mini buffers in minibuffer window.
15386 In that case, redisplay the window normally. */
15387 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15389 /* W is a mini-buffer window, but it's not active, so clear
15391 int yb
= window_text_bottom_y (w
);
15392 struct glyph_row
*row
;
15395 for (y
= 0, row
= w
->desired_matrix
->rows
;
15397 y
+= row
->height
, ++row
)
15398 blank_row (w
, row
, y
);
15399 goto finish_scroll_bars
;
15402 clear_glyph_matrix (w
->desired_matrix
);
15405 /* Otherwise set up data on this window; select its buffer and point
15407 /* Really select the buffer, for the sake of buffer-local
15409 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15411 current_matrix_up_to_date_p
15412 = (!NILP (w
->window_end_valid
)
15413 && !current_buffer
->clip_changed
15414 && !current_buffer
->prevent_redisplay_optimizations_p
15415 && w
->last_modified
>= MODIFF
15416 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15418 /* Run the window-bottom-change-functions
15419 if it is possible that the text on the screen has changed
15420 (either due to modification of the text, or any other reason). */
15421 if (!current_matrix_up_to_date_p
15422 && !NILP (Vwindow_text_change_functions
))
15424 safe_run_hooks (Qwindow_text_change_functions
);
15428 beg_unchanged
= BEG_UNCHANGED
;
15429 end_unchanged
= END_UNCHANGED
;
15431 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15433 specbind (Qinhibit_point_motion_hooks
, Qt
);
15436 = (!NILP (w
->window_end_valid
)
15437 && !current_buffer
->clip_changed
15438 && w
->last_modified
>= MODIFF
15439 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15441 /* When windows_or_buffers_changed is non-zero, we can't rely on
15442 the window end being valid, so set it to nil there. */
15443 if (windows_or_buffers_changed
)
15445 /* If window starts on a continuation line, maybe adjust the
15446 window start in case the window's width changed. */
15447 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15448 compute_window_start_on_continuation_line (w
);
15450 w
->window_end_valid
= Qnil
;
15453 /* Some sanity checks. */
15454 CHECK_WINDOW_END (w
);
15455 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15457 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15460 /* If %c is in mode line, update it if needed. */
15461 if (!NILP (w
->column_number_displayed
)
15462 /* This alternative quickly identifies a common case
15463 where no change is needed. */
15464 && !(PT
== w
->last_point
15465 && w
->last_modified
>= MODIFF
15466 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
15467 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15468 update_mode_line
= 1;
15470 /* Count number of windows showing the selected buffer. An indirect
15471 buffer counts as its base buffer. */
15472 if (!just_this_one_p
)
15474 struct buffer
*current_base
, *window_base
;
15475 current_base
= current_buffer
;
15476 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15477 if (current_base
->base_buffer
)
15478 current_base
= current_base
->base_buffer
;
15479 if (window_base
->base_buffer
)
15480 window_base
= window_base
->base_buffer
;
15481 if (current_base
== window_base
)
15485 /* Point refers normally to the selected window. For any other
15486 window, set up appropriate value. */
15487 if (!EQ (window
, selected_window
))
15489 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15490 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15494 new_pt_byte
= BEGV_BYTE
;
15495 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15497 else if (new_pt
> (ZV
- 1))
15500 new_pt_byte
= ZV_BYTE
;
15501 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15504 /* We don't use SET_PT so that the point-motion hooks don't run. */
15505 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15508 /* If any of the character widths specified in the display table
15509 have changed, invalidate the width run cache. It's true that
15510 this may be a bit late to catch such changes, but the rest of
15511 redisplay goes (non-fatally) haywire when the display table is
15512 changed, so why should we worry about doing any better? */
15513 if (current_buffer
->width_run_cache
)
15515 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15517 if (! disptab_matches_widthtab (disptab
,
15518 XVECTOR (BVAR (current_buffer
, width_table
))))
15520 invalidate_region_cache (current_buffer
,
15521 current_buffer
->width_run_cache
,
15523 recompute_width_table (current_buffer
, disptab
);
15527 /* If window-start is screwed up, choose a new one. */
15528 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15531 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15533 /* If someone specified a new starting point but did not insist,
15534 check whether it can be used. */
15535 if (w
->optional_new_start
15536 && CHARPOS (startp
) >= BEGV
15537 && CHARPOS (startp
) <= ZV
)
15539 w
->optional_new_start
= 0;
15540 start_display (&it
, w
, startp
);
15541 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15542 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15543 if (IT_CHARPOS (it
) == PT
)
15544 w
->force_start
= 1;
15545 /* IT may overshoot PT if text at PT is invisible. */
15546 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15547 w
->force_start
= 1;
15552 /* Handle case where place to start displaying has been specified,
15553 unless the specified location is outside the accessible range. */
15554 if (w
->force_start
|| w
->frozen_window_start_p
)
15556 /* We set this later on if we have to adjust point. */
15559 w
->force_start
= 0;
15561 w
->window_end_valid
= Qnil
;
15563 /* Forget any recorded base line for line number display. */
15564 if (!buffer_unchanged_p
)
15565 w
->base_line_number
= Qnil
;
15567 /* Redisplay the mode line. Select the buffer properly for that.
15568 Also, run the hook window-scroll-functions
15569 because we have scrolled. */
15570 /* Note, we do this after clearing force_start because
15571 if there's an error, it is better to forget about force_start
15572 than to get into an infinite loop calling the hook functions
15573 and having them get more errors. */
15574 if (!update_mode_line
15575 || ! NILP (Vwindow_scroll_functions
))
15577 update_mode_line
= 1;
15578 w
->update_mode_line
= 1;
15579 startp
= run_window_scroll_functions (window
, startp
);
15582 w
->last_modified
= 0;
15583 w
->last_overlay_modified
= 0;
15584 if (CHARPOS (startp
) < BEGV
)
15585 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15586 else if (CHARPOS (startp
) > ZV
)
15587 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15589 /* Redisplay, then check if cursor has been set during the
15590 redisplay. Give up if new fonts were loaded. */
15591 /* We used to issue a CHECK_MARGINS argument to try_window here,
15592 but this causes scrolling to fail when point begins inside
15593 the scroll margin (bug#148) -- cyd */
15594 if (!try_window (window
, startp
, 0))
15596 w
->force_start
= 1;
15597 clear_glyph_matrix (w
->desired_matrix
);
15598 goto need_larger_matrices
;
15601 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15603 /* If point does not appear, try to move point so it does
15604 appear. The desired matrix has been built above, so we
15605 can use it here. */
15606 new_vpos
= window_box_height (w
) / 2;
15609 if (!cursor_row_fully_visible_p (w
, 0, 0))
15611 /* Point does appear, but on a line partly visible at end of window.
15612 Move it back to a fully-visible line. */
15613 new_vpos
= window_box_height (w
);
15616 /* If we need to move point for either of the above reasons,
15617 now actually do it. */
15620 struct glyph_row
*row
;
15622 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15623 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15626 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15627 MATRIX_ROW_START_BYTEPOS (row
));
15629 if (w
!= XWINDOW (selected_window
))
15630 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15631 else if (current_buffer
== old
)
15632 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15634 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15636 /* If we are highlighting the region, then we just changed
15637 the region, so redisplay to show it. */
15638 if (!NILP (Vtransient_mark_mode
)
15639 && !NILP (BVAR (current_buffer
, mark_active
)))
15641 clear_glyph_matrix (w
->desired_matrix
);
15642 if (!try_window (window
, startp
, 0))
15643 goto need_larger_matrices
;
15648 debug_method_add (w
, "forced window start");
15653 /* Handle case where text has not changed, only point, and it has
15654 not moved off the frame, and we are not retrying after hscroll.
15655 (current_matrix_up_to_date_p is nonzero when retrying.) */
15656 if (current_matrix_up_to_date_p
15657 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15658 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15662 case CURSOR_MOVEMENT_SUCCESS
:
15663 used_current_matrix_p
= 1;
15666 case CURSOR_MOVEMENT_MUST_SCROLL
:
15667 goto try_to_scroll
;
15673 /* If current starting point was originally the beginning of a line
15674 but no longer is, find a new starting point. */
15675 else if (w
->start_at_line_beg
15676 && !(CHARPOS (startp
) <= BEGV
15677 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15680 debug_method_add (w
, "recenter 1");
15685 /* Try scrolling with try_window_id. Value is > 0 if update has
15686 been done, it is -1 if we know that the same window start will
15687 not work. It is 0 if unsuccessful for some other reason. */
15688 else if ((tem
= try_window_id (w
)) != 0)
15691 debug_method_add (w
, "try_window_id %d", tem
);
15694 if (fonts_changed_p
)
15695 goto need_larger_matrices
;
15699 /* Otherwise try_window_id has returned -1 which means that we
15700 don't want the alternative below this comment to execute. */
15702 else if (CHARPOS (startp
) >= BEGV
15703 && CHARPOS (startp
) <= ZV
15704 && PT
>= CHARPOS (startp
)
15705 && (CHARPOS (startp
) < ZV
15706 /* Avoid starting at end of buffer. */
15707 || CHARPOS (startp
) == BEGV
15708 || (w
->last_modified
>= MODIFF
15709 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)))
15711 int d1
, d2
, d3
, d4
, d5
, d6
;
15713 /* If first window line is a continuation line, and window start
15714 is inside the modified region, but the first change is before
15715 current window start, we must select a new window start.
15717 However, if this is the result of a down-mouse event (e.g. by
15718 extending the mouse-drag-overlay), we don't want to select a
15719 new window start, since that would change the position under
15720 the mouse, resulting in an unwanted mouse-movement rather
15721 than a simple mouse-click. */
15722 if (!w
->start_at_line_beg
15723 && NILP (do_mouse_tracking
)
15724 && CHARPOS (startp
) > BEGV
15725 && CHARPOS (startp
) > BEG
+ beg_unchanged
15726 && CHARPOS (startp
) <= Z
- end_unchanged
15727 /* Even if w->start_at_line_beg is nil, a new window may
15728 start at a line_beg, since that's how set_buffer_window
15729 sets it. So, we need to check the return value of
15730 compute_window_start_on_continuation_line. (See also
15732 && XMARKER (w
->start
)->buffer
== current_buffer
15733 && compute_window_start_on_continuation_line (w
)
15734 /* It doesn't make sense to force the window start like we
15735 do at label force_start if it is already known that point
15736 will not be visible in the resulting window, because
15737 doing so will move point from its correct position
15738 instead of scrolling the window to bring point into view.
15740 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15742 w
->force_start
= 1;
15743 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15748 debug_method_add (w
, "same window start");
15751 /* Try to redisplay starting at same place as before.
15752 If point has not moved off frame, accept the results. */
15753 if (!current_matrix_up_to_date_p
15754 /* Don't use try_window_reusing_current_matrix in this case
15755 because a window scroll function can have changed the
15757 || !NILP (Vwindow_scroll_functions
)
15758 || MINI_WINDOW_P (w
)
15759 || !(used_current_matrix_p
15760 = try_window_reusing_current_matrix (w
)))
15762 IF_DEBUG (debug_method_add (w
, "1"));
15763 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15764 /* -1 means we need to scroll.
15765 0 means we need new matrices, but fonts_changed_p
15766 is set in that case, so we will detect it below. */
15767 goto try_to_scroll
;
15770 if (fonts_changed_p
)
15771 goto need_larger_matrices
;
15773 if (w
->cursor
.vpos
>= 0)
15775 if (!just_this_one_p
15776 || current_buffer
->clip_changed
15777 || BEG_UNCHANGED
< CHARPOS (startp
))
15778 /* Forget any recorded base line for line number display. */
15779 w
->base_line_number
= Qnil
;
15781 if (!cursor_row_fully_visible_p (w
, 1, 0))
15783 clear_glyph_matrix (w
->desired_matrix
);
15784 last_line_misfit
= 1;
15786 /* Drop through and scroll. */
15791 clear_glyph_matrix (w
->desired_matrix
);
15796 w
->last_modified
= 0;
15797 w
->last_overlay_modified
= 0;
15799 /* Redisplay the mode line. Select the buffer properly for that. */
15800 if (!update_mode_line
)
15802 update_mode_line
= 1;
15803 w
->update_mode_line
= 1;
15806 /* Try to scroll by specified few lines. */
15807 if ((scroll_conservatively
15808 || emacs_scroll_step
15809 || temp_scroll_step
15810 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15811 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15812 && CHARPOS (startp
) >= BEGV
15813 && CHARPOS (startp
) <= ZV
)
15815 /* The function returns -1 if new fonts were loaded, 1 if
15816 successful, 0 if not successful. */
15817 int ss
= try_scrolling (window
, just_this_one_p
,
15818 scroll_conservatively
,
15820 temp_scroll_step
, last_line_misfit
);
15823 case SCROLLING_SUCCESS
:
15826 case SCROLLING_NEED_LARGER_MATRICES
:
15827 goto need_larger_matrices
;
15829 case SCROLLING_FAILED
:
15837 /* Finally, just choose a place to start which positions point
15838 according to user preferences. */
15843 debug_method_add (w
, "recenter");
15846 /* w->vscroll = 0; */
15848 /* Forget any previously recorded base line for line number display. */
15849 if (!buffer_unchanged_p
)
15850 w
->base_line_number
= Qnil
;
15852 /* Determine the window start relative to point. */
15853 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15854 it
.current_y
= it
.last_visible_y
;
15855 if (centering_position
< 0)
15859 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15861 ptrdiff_t margin_pos
= CHARPOS (startp
);
15862 Lisp_Object aggressive
;
15865 /* If there is a scroll margin at the top of the window, find
15866 its character position. */
15868 /* Cannot call start_display if startp is not in the
15869 accessible region of the buffer. This can happen when we
15870 have just switched to a different buffer and/or changed
15871 its restriction. In that case, startp is initialized to
15872 the character position 1 (BEGV) because we did not yet
15873 have chance to display the buffer even once. */
15874 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15877 void *it1data
= NULL
;
15879 SAVE_IT (it1
, it
, it1data
);
15880 start_display (&it1
, w
, startp
);
15881 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15882 margin_pos
= IT_CHARPOS (it1
);
15883 RESTORE_IT (&it
, &it
, it1data
);
15885 scrolling_up
= PT
> margin_pos
;
15888 ? BVAR (current_buffer
, scroll_up_aggressively
)
15889 : BVAR (current_buffer
, scroll_down_aggressively
);
15891 if (!MINI_WINDOW_P (w
)
15892 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15896 /* Setting scroll-conservatively overrides
15897 scroll-*-aggressively. */
15898 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15900 double float_amount
= XFLOATINT (aggressive
);
15902 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15903 if (pt_offset
== 0 && float_amount
> 0)
15905 if (pt_offset
&& margin
> 0)
15908 /* Compute how much to move the window start backward from
15909 point so that point will be displayed where the user
15913 centering_position
= it
.last_visible_y
;
15915 centering_position
-= pt_offset
;
15916 centering_position
-=
15917 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15918 + WINDOW_HEADER_LINE_HEIGHT (w
);
15919 /* Don't let point enter the scroll margin near top of
15921 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15922 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15925 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15928 /* Set the window start half the height of the window backward
15930 centering_position
= window_box_height (w
) / 2;
15932 move_it_vertically_backward (&it
, centering_position
);
15934 eassert (IT_CHARPOS (it
) >= BEGV
);
15936 /* The function move_it_vertically_backward may move over more
15937 than the specified y-distance. If it->w is small, e.g. a
15938 mini-buffer window, we may end up in front of the window's
15939 display area. Start displaying at the start of the line
15940 containing PT in this case. */
15941 if (it
.current_y
<= 0)
15943 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15944 move_it_vertically_backward (&it
, 0);
15948 it
.current_x
= it
.hpos
= 0;
15950 /* Set the window start position here explicitly, to avoid an
15951 infinite loop in case the functions in window-scroll-functions
15953 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15955 /* Run scroll hooks. */
15956 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15958 /* Redisplay the window. */
15959 if (!current_matrix_up_to_date_p
15960 || windows_or_buffers_changed
15961 || cursor_type_changed
15962 /* Don't use try_window_reusing_current_matrix in this case
15963 because it can have changed the buffer. */
15964 || !NILP (Vwindow_scroll_functions
)
15965 || !just_this_one_p
15966 || MINI_WINDOW_P (w
)
15967 || !(used_current_matrix_p
15968 = try_window_reusing_current_matrix (w
)))
15969 try_window (window
, startp
, 0);
15971 /* If new fonts have been loaded (due to fontsets), give up. We
15972 have to start a new redisplay since we need to re-adjust glyph
15974 if (fonts_changed_p
)
15975 goto need_larger_matrices
;
15977 /* If cursor did not appear assume that the middle of the window is
15978 in the first line of the window. Do it again with the next line.
15979 (Imagine a window of height 100, displaying two lines of height
15980 60. Moving back 50 from it->last_visible_y will end in the first
15982 if (w
->cursor
.vpos
< 0)
15984 if (!NILP (w
->window_end_valid
)
15985 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15987 clear_glyph_matrix (w
->desired_matrix
);
15988 move_it_by_lines (&it
, 1);
15989 try_window (window
, it
.current
.pos
, 0);
15991 else if (PT
< IT_CHARPOS (it
))
15993 clear_glyph_matrix (w
->desired_matrix
);
15994 move_it_by_lines (&it
, -1);
15995 try_window (window
, it
.current
.pos
, 0);
15999 /* Not much we can do about it. */
16003 /* Consider the following case: Window starts at BEGV, there is
16004 invisible, intangible text at BEGV, so that display starts at
16005 some point START > BEGV. It can happen that we are called with
16006 PT somewhere between BEGV and START. Try to handle that case. */
16007 if (w
->cursor
.vpos
< 0)
16009 struct glyph_row
*row
= w
->current_matrix
->rows
;
16010 if (row
->mode_line_p
)
16012 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16015 if (!cursor_row_fully_visible_p (w
, 0, 0))
16017 /* If vscroll is enabled, disable it and try again. */
16021 clear_glyph_matrix (w
->desired_matrix
);
16025 /* Users who set scroll-conservatively to a large number want
16026 point just above/below the scroll margin. If we ended up
16027 with point's row partially visible, move the window start to
16028 make that row fully visible and out of the margin. */
16029 if (scroll_conservatively
> SCROLL_LIMIT
)
16033 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16035 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16037 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16038 clear_glyph_matrix (w
->desired_matrix
);
16039 if (1 == try_window (window
, it
.current
.pos
,
16040 TRY_WINDOW_CHECK_MARGINS
))
16044 /* If centering point failed to make the whole line visible,
16045 put point at the top instead. That has to make the whole line
16046 visible, if it can be done. */
16047 if (centering_position
== 0)
16050 clear_glyph_matrix (w
->desired_matrix
);
16051 centering_position
= 0;
16057 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16058 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16059 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16061 /* Display the mode line, if we must. */
16062 if ((update_mode_line
16063 /* If window not full width, must redo its mode line
16064 if (a) the window to its side is being redone and
16065 (b) we do a frame-based redisplay. This is a consequence
16066 of how inverted lines are drawn in frame-based redisplay. */
16067 || (!just_this_one_p
16068 && !FRAME_WINDOW_P (f
)
16069 && !WINDOW_FULL_WIDTH_P (w
))
16070 /* Line number to display. */
16071 || INTEGERP (w
->base_line_pos
)
16072 /* Column number is displayed and different from the one displayed. */
16073 || (!NILP (w
->column_number_displayed
)
16074 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16075 /* This means that the window has a mode line. */
16076 && (WINDOW_WANTS_MODELINE_P (w
)
16077 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16079 display_mode_lines (w
);
16081 /* If mode line height has changed, arrange for a thorough
16082 immediate redisplay using the correct mode line height. */
16083 if (WINDOW_WANTS_MODELINE_P (w
)
16084 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16086 fonts_changed_p
= 1;
16087 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16088 = DESIRED_MODE_LINE_HEIGHT (w
);
16091 /* If header line height has changed, arrange for a thorough
16092 immediate redisplay using the correct header line height. */
16093 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16094 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16096 fonts_changed_p
= 1;
16097 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16098 = DESIRED_HEADER_LINE_HEIGHT (w
);
16101 if (fonts_changed_p
)
16102 goto need_larger_matrices
;
16105 if (!line_number_displayed
16106 && !BUFFERP (w
->base_line_pos
))
16108 w
->base_line_pos
= Qnil
;
16109 w
->base_line_number
= Qnil
;
16114 /* When we reach a frame's selected window, redo the frame's menu bar. */
16115 if (update_mode_line
16116 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16118 int redisplay_menu_p
= 0;
16120 if (FRAME_WINDOW_P (f
))
16122 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16123 || defined (HAVE_NS) || defined (USE_GTK)
16124 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16126 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16130 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16132 if (redisplay_menu_p
)
16133 display_menu_bar (w
);
16135 #ifdef HAVE_WINDOW_SYSTEM
16136 if (FRAME_WINDOW_P (f
))
16138 #if defined (USE_GTK) || defined (HAVE_NS)
16139 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16140 redisplay_tool_bar (f
);
16142 if (WINDOWP (f
->tool_bar_window
)
16143 && (FRAME_TOOL_BAR_LINES (f
) > 0
16144 || !NILP (Vauto_resize_tool_bars
))
16145 && redisplay_tool_bar (f
))
16146 ignore_mouse_drag_p
= 1;
16152 #ifdef HAVE_WINDOW_SYSTEM
16153 if (FRAME_WINDOW_P (f
)
16154 && update_window_fringes (w
, (just_this_one_p
16155 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16156 || w
->pseudo_window_p
)))
16160 if (draw_window_fringes (w
, 1))
16161 x_draw_vertical_border (w
);
16165 #endif /* HAVE_WINDOW_SYSTEM */
16167 /* We go to this label, with fonts_changed_p nonzero,
16168 if it is necessary to try again using larger glyph matrices.
16169 We have to redeem the scroll bar even in this case,
16170 because the loop in redisplay_internal expects that. */
16171 need_larger_matrices
:
16173 finish_scroll_bars
:
16175 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16177 /* Set the thumb's position and size. */
16178 set_vertical_scroll_bar (w
);
16180 /* Note that we actually used the scroll bar attached to this
16181 window, so it shouldn't be deleted at the end of redisplay. */
16182 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16183 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16186 /* Restore current_buffer and value of point in it. The window
16187 update may have changed the buffer, so first make sure `opoint'
16188 is still valid (Bug#6177). */
16189 if (CHARPOS (opoint
) < BEGV
)
16190 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16191 else if (CHARPOS (opoint
) > ZV
)
16192 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16194 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16196 set_buffer_internal_1 (old
);
16197 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16198 shorter. This can be caused by log truncation in *Messages*. */
16199 if (CHARPOS (lpoint
) <= ZV
)
16200 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16202 unbind_to (count
, Qnil
);
16206 /* Build the complete desired matrix of WINDOW with a window start
16207 buffer position POS.
16209 Value is 1 if successful. It is zero if fonts were loaded during
16210 redisplay which makes re-adjusting glyph matrices necessary, and -1
16211 if point would appear in the scroll margins.
16212 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16213 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16217 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16219 struct window
*w
= XWINDOW (window
);
16221 struct glyph_row
*last_text_row
= NULL
;
16222 struct frame
*f
= XFRAME (w
->frame
);
16224 /* Make POS the new window start. */
16225 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16227 /* Mark cursor position as unknown. No overlay arrow seen. */
16228 w
->cursor
.vpos
= -1;
16229 overlay_arrow_seen
= 0;
16231 /* Initialize iterator and info to start at POS. */
16232 start_display (&it
, w
, pos
);
16234 /* Display all lines of W. */
16235 while (it
.current_y
< it
.last_visible_y
)
16237 if (display_line (&it
))
16238 last_text_row
= it
.glyph_row
- 1;
16239 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16243 /* Don't let the cursor end in the scroll margins. */
16244 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16245 && !MINI_WINDOW_P (w
))
16247 int this_scroll_margin
;
16249 if (scroll_margin
> 0)
16251 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16252 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16255 this_scroll_margin
= 0;
16257 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16258 && w
->cursor
.y
< this_scroll_margin
16259 && CHARPOS (pos
) > BEGV
16260 && IT_CHARPOS (it
) < ZV
)
16261 /* rms: considering make_cursor_line_fully_visible_p here
16262 seems to give wrong results. We don't want to recenter
16263 when the last line is partly visible, we want to allow
16264 that case to be handled in the usual way. */
16265 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16267 w
->cursor
.vpos
= -1;
16268 clear_glyph_matrix (w
->desired_matrix
);
16273 /* If bottom moved off end of frame, change mode line percentage. */
16274 if (XFASTINT (w
->window_end_pos
) <= 0
16275 && Z
!= IT_CHARPOS (it
))
16276 w
->update_mode_line
= 1;
16278 /* Set window_end_pos to the offset of the last character displayed
16279 on the window from the end of current_buffer. Set
16280 window_end_vpos to its row number. */
16283 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16284 w
->window_end_bytepos
16285 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16287 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16289 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16290 eassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16291 ->displays_text_p
);
16295 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16296 w
->window_end_pos
= make_number (Z
- ZV
);
16297 w
->window_end_vpos
= make_number (0);
16300 /* But that is not valid info until redisplay finishes. */
16301 w
->window_end_valid
= Qnil
;
16307 /************************************************************************
16308 Window redisplay reusing current matrix when buffer has not changed
16309 ************************************************************************/
16311 /* Try redisplay of window W showing an unchanged buffer with a
16312 different window start than the last time it was displayed by
16313 reusing its current matrix. Value is non-zero if successful.
16314 W->start is the new window start. */
16317 try_window_reusing_current_matrix (struct window
*w
)
16319 struct frame
*f
= XFRAME (w
->frame
);
16320 struct glyph_row
*bottom_row
;
16323 struct text_pos start
, new_start
;
16324 int nrows_scrolled
, i
;
16325 struct glyph_row
*last_text_row
;
16326 struct glyph_row
*last_reused_text_row
;
16327 struct glyph_row
*start_row
;
16328 int start_vpos
, min_y
, max_y
;
16331 if (inhibit_try_window_reusing
)
16335 if (/* This function doesn't handle terminal frames. */
16336 !FRAME_WINDOW_P (f
)
16337 /* Don't try to reuse the display if windows have been split
16339 || windows_or_buffers_changed
16340 || cursor_type_changed
)
16343 /* Can't do this if region may have changed. */
16344 if ((!NILP (Vtransient_mark_mode
)
16345 && !NILP (BVAR (current_buffer
, mark_active
)))
16346 || !NILP (w
->region_showing
)
16347 || !NILP (Vshow_trailing_whitespace
))
16350 /* If top-line visibility has changed, give up. */
16351 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16352 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16355 /* Give up if old or new display is scrolled vertically. We could
16356 make this function handle this, but right now it doesn't. */
16357 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16358 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16361 /* The variable new_start now holds the new window start. The old
16362 start `start' can be determined from the current matrix. */
16363 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16364 start
= start_row
->minpos
;
16365 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16367 /* Clear the desired matrix for the display below. */
16368 clear_glyph_matrix (w
->desired_matrix
);
16370 if (CHARPOS (new_start
) <= CHARPOS (start
))
16372 /* Don't use this method if the display starts with an ellipsis
16373 displayed for invisible text. It's not easy to handle that case
16374 below, and it's certainly not worth the effort since this is
16375 not a frequent case. */
16376 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16379 IF_DEBUG (debug_method_add (w
, "twu1"));
16381 /* Display up to a row that can be reused. The variable
16382 last_text_row is set to the last row displayed that displays
16383 text. Note that it.vpos == 0 if or if not there is a
16384 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16385 start_display (&it
, w
, new_start
);
16386 w
->cursor
.vpos
= -1;
16387 last_text_row
= last_reused_text_row
= NULL
;
16389 while (it
.current_y
< it
.last_visible_y
16390 && !fonts_changed_p
)
16392 /* If we have reached into the characters in the START row,
16393 that means the line boundaries have changed. So we
16394 can't start copying with the row START. Maybe it will
16395 work to start copying with the following row. */
16396 while (IT_CHARPOS (it
) > CHARPOS (start
))
16398 /* Advance to the next row as the "start". */
16400 start
= start_row
->minpos
;
16401 /* If there are no more rows to try, or just one, give up. */
16402 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16403 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16404 || CHARPOS (start
) == ZV
)
16406 clear_glyph_matrix (w
->desired_matrix
);
16410 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16412 /* If we have reached alignment, we can copy the rest of the
16414 if (IT_CHARPOS (it
) == CHARPOS (start
)
16415 /* Don't accept "alignment" inside a display vector,
16416 since start_row could have started in the middle of
16417 that same display vector (thus their character
16418 positions match), and we have no way of telling if
16419 that is the case. */
16420 && it
.current
.dpvec_index
< 0)
16423 if (display_line (&it
))
16424 last_text_row
= it
.glyph_row
- 1;
16428 /* A value of current_y < last_visible_y means that we stopped
16429 at the previous window start, which in turn means that we
16430 have at least one reusable row. */
16431 if (it
.current_y
< it
.last_visible_y
)
16433 struct glyph_row
*row
;
16435 /* IT.vpos always starts from 0; it counts text lines. */
16436 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16438 /* Find PT if not already found in the lines displayed. */
16439 if (w
->cursor
.vpos
< 0)
16441 int dy
= it
.current_y
- start_row
->y
;
16443 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16444 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16446 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16447 dy
, nrows_scrolled
);
16450 clear_glyph_matrix (w
->desired_matrix
);
16455 /* Scroll the display. Do it before the current matrix is
16456 changed. The problem here is that update has not yet
16457 run, i.e. part of the current matrix is not up to date.
16458 scroll_run_hook will clear the cursor, and use the
16459 current matrix to get the height of the row the cursor is
16461 run
.current_y
= start_row
->y
;
16462 run
.desired_y
= it
.current_y
;
16463 run
.height
= it
.last_visible_y
- it
.current_y
;
16465 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16468 FRAME_RIF (f
)->update_window_begin_hook (w
);
16469 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16470 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16471 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16475 /* Shift current matrix down by nrows_scrolled lines. */
16476 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16477 rotate_matrix (w
->current_matrix
,
16479 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16482 /* Disable lines that must be updated. */
16483 for (i
= 0; i
< nrows_scrolled
; ++i
)
16484 (start_row
+ i
)->enabled_p
= 0;
16486 /* Re-compute Y positions. */
16487 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16488 max_y
= it
.last_visible_y
;
16489 for (row
= start_row
+ nrows_scrolled
;
16493 row
->y
= it
.current_y
;
16494 row
->visible_height
= row
->height
;
16496 if (row
->y
< min_y
)
16497 row
->visible_height
-= min_y
- row
->y
;
16498 if (row
->y
+ row
->height
> max_y
)
16499 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16500 if (row
->fringe_bitmap_periodic_p
)
16501 row
->redraw_fringe_bitmaps_p
= 1;
16503 it
.current_y
+= row
->height
;
16505 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16506 last_reused_text_row
= row
;
16507 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16511 /* Disable lines in the current matrix which are now
16512 below the window. */
16513 for (++row
; row
< bottom_row
; ++row
)
16514 row
->enabled_p
= row
->mode_line_p
= 0;
16517 /* Update window_end_pos etc.; last_reused_text_row is the last
16518 reused row from the current matrix containing text, if any.
16519 The value of last_text_row is the last displayed line
16520 containing text. */
16521 if (last_reused_text_row
)
16523 w
->window_end_bytepos
16524 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16526 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16528 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16529 w
->current_matrix
));
16531 else if (last_text_row
)
16533 w
->window_end_bytepos
16534 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16536 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16538 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16542 /* This window must be completely empty. */
16543 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16544 w
->window_end_pos
= make_number (Z
- ZV
);
16545 w
->window_end_vpos
= make_number (0);
16547 w
->window_end_valid
= Qnil
;
16549 /* Update hint: don't try scrolling again in update_window. */
16550 w
->desired_matrix
->no_scrolling_p
= 1;
16553 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16557 else if (CHARPOS (new_start
) > CHARPOS (start
))
16559 struct glyph_row
*pt_row
, *row
;
16560 struct glyph_row
*first_reusable_row
;
16561 struct glyph_row
*first_row_to_display
;
16563 int yb
= window_text_bottom_y (w
);
16565 /* Find the row starting at new_start, if there is one. Don't
16566 reuse a partially visible line at the end. */
16567 first_reusable_row
= start_row
;
16568 while (first_reusable_row
->enabled_p
16569 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16570 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16571 < CHARPOS (new_start
)))
16572 ++first_reusable_row
;
16574 /* Give up if there is no row to reuse. */
16575 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16576 || !first_reusable_row
->enabled_p
16577 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16578 != CHARPOS (new_start
)))
16581 /* We can reuse fully visible rows beginning with
16582 first_reusable_row to the end of the window. Set
16583 first_row_to_display to the first row that cannot be reused.
16584 Set pt_row to the row containing point, if there is any. */
16586 for (first_row_to_display
= first_reusable_row
;
16587 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16588 ++first_row_to_display
)
16590 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16591 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16592 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16593 && first_row_to_display
->ends_at_zv_p
16594 && pt_row
== NULL
)))
16595 pt_row
= first_row_to_display
;
16598 /* Start displaying at the start of first_row_to_display. */
16599 eassert (first_row_to_display
->y
< yb
);
16600 init_to_row_start (&it
, w
, first_row_to_display
);
16602 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16604 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16606 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16607 + WINDOW_HEADER_LINE_HEIGHT (w
));
16609 /* Display lines beginning with first_row_to_display in the
16610 desired matrix. Set last_text_row to the last row displayed
16611 that displays text. */
16612 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16613 if (pt_row
== NULL
)
16614 w
->cursor
.vpos
= -1;
16615 last_text_row
= NULL
;
16616 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16617 if (display_line (&it
))
16618 last_text_row
= it
.glyph_row
- 1;
16620 /* If point is in a reused row, adjust y and vpos of the cursor
16624 w
->cursor
.vpos
-= nrows_scrolled
;
16625 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16628 /* Give up if point isn't in a row displayed or reused. (This
16629 also handles the case where w->cursor.vpos < nrows_scrolled
16630 after the calls to display_line, which can happen with scroll
16631 margins. See bug#1295.) */
16632 if (w
->cursor
.vpos
< 0)
16634 clear_glyph_matrix (w
->desired_matrix
);
16638 /* Scroll the display. */
16639 run
.current_y
= first_reusable_row
->y
;
16640 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16641 run
.height
= it
.last_visible_y
- run
.current_y
;
16642 dy
= run
.current_y
- run
.desired_y
;
16647 FRAME_RIF (f
)->update_window_begin_hook (w
);
16648 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16649 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16650 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16654 /* Adjust Y positions of reused rows. */
16655 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16656 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16657 max_y
= it
.last_visible_y
;
16658 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16661 row
->visible_height
= row
->height
;
16662 if (row
->y
< min_y
)
16663 row
->visible_height
-= min_y
- row
->y
;
16664 if (row
->y
+ row
->height
> max_y
)
16665 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16666 if (row
->fringe_bitmap_periodic_p
)
16667 row
->redraw_fringe_bitmaps_p
= 1;
16670 /* Scroll the current matrix. */
16671 eassert (nrows_scrolled
> 0);
16672 rotate_matrix (w
->current_matrix
,
16674 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16677 /* Disable rows not reused. */
16678 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16679 row
->enabled_p
= 0;
16681 /* Point may have moved to a different line, so we cannot assume that
16682 the previous cursor position is valid; locate the correct row. */
16685 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16687 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16688 && !row
->ends_at_zv_p
;
16692 w
->cursor
.y
= row
->y
;
16694 if (row
< bottom_row
)
16696 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16697 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16699 /* Can't use this optimization with bidi-reordered glyph
16700 rows, unless cursor is already at point. */
16701 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16703 if (!(w
->cursor
.hpos
>= 0
16704 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16705 && BUFFERP (glyph
->object
)
16706 && glyph
->charpos
== PT
))
16711 && (!BUFFERP (glyph
->object
)
16712 || glyph
->charpos
< PT
);
16716 w
->cursor
.x
+= glyph
->pixel_width
;
16721 /* Adjust window end. A null value of last_text_row means that
16722 the window end is in reused rows which in turn means that
16723 only its vpos can have changed. */
16726 w
->window_end_bytepos
16727 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16729 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16731 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16736 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16739 w
->window_end_valid
= Qnil
;
16740 w
->desired_matrix
->no_scrolling_p
= 1;
16743 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16753 /************************************************************************
16754 Window redisplay reusing current matrix when buffer has changed
16755 ************************************************************************/
16757 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16758 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16759 ptrdiff_t *, ptrdiff_t *);
16760 static struct glyph_row
*
16761 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16762 struct glyph_row
*);
16765 /* Return the last row in MATRIX displaying text. If row START is
16766 non-null, start searching with that row. IT gives the dimensions
16767 of the display. Value is null if matrix is empty; otherwise it is
16768 a pointer to the row found. */
16770 static struct glyph_row
*
16771 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16772 struct glyph_row
*start
)
16774 struct glyph_row
*row
, *row_found
;
16776 /* Set row_found to the last row in IT->w's current matrix
16777 displaying text. The loop looks funny but think of partially
16780 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16781 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16783 eassert (row
->enabled_p
);
16785 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16794 /* Return the last row in the current matrix of W that is not affected
16795 by changes at the start of current_buffer that occurred since W's
16796 current matrix was built. Value is null if no such row exists.
16798 BEG_UNCHANGED us the number of characters unchanged at the start of
16799 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16800 first changed character in current_buffer. Characters at positions <
16801 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16802 when the current matrix was built. */
16804 static struct glyph_row
*
16805 find_last_unchanged_at_beg_row (struct window
*w
)
16807 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16808 struct glyph_row
*row
;
16809 struct glyph_row
*row_found
= NULL
;
16810 int yb
= window_text_bottom_y (w
);
16812 /* Find the last row displaying unchanged text. */
16813 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16814 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16815 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16818 if (/* If row ends before first_changed_pos, it is unchanged,
16819 except in some case. */
16820 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16821 /* When row ends in ZV and we write at ZV it is not
16823 && !row
->ends_at_zv_p
16824 /* When first_changed_pos is the end of a continued line,
16825 row is not unchanged because it may be no longer
16827 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16828 && (row
->continued_p
16829 || row
->exact_window_width_line_p
))
16830 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16831 needs to be recomputed, so don't consider this row as
16832 unchanged. This happens when the last line was
16833 bidi-reordered and was killed immediately before this
16834 redisplay cycle. In that case, ROW->end stores the
16835 buffer position of the first visual-order character of
16836 the killed text, which is now beyond ZV. */
16837 && CHARPOS (row
->end
.pos
) <= ZV
)
16840 /* Stop if last visible row. */
16841 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16849 /* Find the first glyph row in the current matrix of W that is not
16850 affected by changes at the end of current_buffer since the
16851 time W's current matrix was built.
16853 Return in *DELTA the number of chars by which buffer positions in
16854 unchanged text at the end of current_buffer must be adjusted.
16856 Return in *DELTA_BYTES the corresponding number of bytes.
16858 Value is null if no such row exists, i.e. all rows are affected by
16861 static struct glyph_row
*
16862 find_first_unchanged_at_end_row (struct window
*w
,
16863 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16865 struct glyph_row
*row
;
16866 struct glyph_row
*row_found
= NULL
;
16868 *delta
= *delta_bytes
= 0;
16870 /* Display must not have been paused, otherwise the current matrix
16871 is not up to date. */
16872 eassert (!NILP (w
->window_end_valid
));
16874 /* A value of window_end_pos >= END_UNCHANGED means that the window
16875 end is in the range of changed text. If so, there is no
16876 unchanged row at the end of W's current matrix. */
16877 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16880 /* Set row to the last row in W's current matrix displaying text. */
16881 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16883 /* If matrix is entirely empty, no unchanged row exists. */
16884 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16886 /* The value of row is the last glyph row in the matrix having a
16887 meaningful buffer position in it. The end position of row
16888 corresponds to window_end_pos. This allows us to translate
16889 buffer positions in the current matrix to current buffer
16890 positions for characters not in changed text. */
16892 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16893 ptrdiff_t Z_BYTE_old
=
16894 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16895 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16896 struct glyph_row
*first_text_row
16897 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16899 *delta
= Z
- Z_old
;
16900 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16902 /* Set last_unchanged_pos to the buffer position of the last
16903 character in the buffer that has not been changed. Z is the
16904 index + 1 of the last character in current_buffer, i.e. by
16905 subtracting END_UNCHANGED we get the index of the last
16906 unchanged character, and we have to add BEG to get its buffer
16908 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16909 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16911 /* Search backward from ROW for a row displaying a line that
16912 starts at a minimum position >= last_unchanged_pos_old. */
16913 for (; row
> first_text_row
; --row
)
16915 /* This used to abort, but it can happen.
16916 It is ok to just stop the search instead here. KFS. */
16917 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16920 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16925 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16931 /* Make sure that glyph rows in the current matrix of window W
16932 reference the same glyph memory as corresponding rows in the
16933 frame's frame matrix. This function is called after scrolling W's
16934 current matrix on a terminal frame in try_window_id and
16935 try_window_reusing_current_matrix. */
16938 sync_frame_with_window_matrix_rows (struct window
*w
)
16940 struct frame
*f
= XFRAME (w
->frame
);
16941 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16943 /* Preconditions: W must be a leaf window and full-width. Its frame
16944 must have a frame matrix. */
16945 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16946 eassert (WINDOW_FULL_WIDTH_P (w
));
16947 eassert (!FRAME_WINDOW_P (f
));
16949 /* If W is a full-width window, glyph pointers in W's current matrix
16950 have, by definition, to be the same as glyph pointers in the
16951 corresponding frame matrix. Note that frame matrices have no
16952 marginal areas (see build_frame_matrix). */
16953 window_row
= w
->current_matrix
->rows
;
16954 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16955 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16956 while (window_row
< window_row_end
)
16958 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16959 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16961 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16962 frame_row
->glyphs
[TEXT_AREA
] = start
;
16963 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16964 frame_row
->glyphs
[LAST_AREA
] = end
;
16966 /* Disable frame rows whose corresponding window rows have
16967 been disabled in try_window_id. */
16968 if (!window_row
->enabled_p
)
16969 frame_row
->enabled_p
= 0;
16971 ++window_row
, ++frame_row
;
16976 /* Find the glyph row in window W containing CHARPOS. Consider all
16977 rows between START and END (not inclusive). END null means search
16978 all rows to the end of the display area of W. Value is the row
16979 containing CHARPOS or null. */
16982 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16983 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16985 struct glyph_row
*row
= start
;
16986 struct glyph_row
*best_row
= NULL
;
16987 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16990 /* If we happen to start on a header-line, skip that. */
16991 if (row
->mode_line_p
)
16994 if ((end
&& row
>= end
) || !row
->enabled_p
)
16997 last_y
= window_text_bottom_y (w
) - dy
;
17001 /* Give up if we have gone too far. */
17002 if (end
&& row
>= end
)
17004 /* This formerly returned if they were equal.
17005 I think that both quantities are of a "last plus one" type;
17006 if so, when they are equal, the row is within the screen. -- rms. */
17007 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17010 /* If it is in this row, return this row. */
17011 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17012 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17013 /* The end position of a row equals the start
17014 position of the next row. If CHARPOS is there, we
17015 would rather display it in the next line, except
17016 when this line ends in ZV. */
17017 && !row
->ends_at_zv_p
17018 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17019 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17023 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17024 || (!best_row
&& !row
->continued_p
))
17026 /* In bidi-reordered rows, there could be several rows
17027 occluding point, all of them belonging to the same
17028 continued line. We need to find the row which fits
17029 CHARPOS the best. */
17030 for (g
= row
->glyphs
[TEXT_AREA
];
17031 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17034 if (!STRINGP (g
->object
))
17036 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17038 mindif
= eabs (g
->charpos
- charpos
);
17040 /* Exact match always wins. */
17047 else if (best_row
&& !row
->continued_p
)
17054 /* Try to redisplay window W by reusing its existing display. W's
17055 current matrix must be up to date when this function is called,
17056 i.e. window_end_valid must not be nil.
17060 1 if display has been updated
17061 0 if otherwise unsuccessful
17062 -1 if redisplay with same window start is known not to succeed
17064 The following steps are performed:
17066 1. Find the last row in the current matrix of W that is not
17067 affected by changes at the start of current_buffer. If no such row
17070 2. Find the first row in W's current matrix that is not affected by
17071 changes at the end of current_buffer. Maybe there is no such row.
17073 3. Display lines beginning with the row + 1 found in step 1 to the
17074 row found in step 2 or, if step 2 didn't find a row, to the end of
17077 4. If cursor is not known to appear on the window, give up.
17079 5. If display stopped at the row found in step 2, scroll the
17080 display and current matrix as needed.
17082 6. Maybe display some lines at the end of W, if we must. This can
17083 happen under various circumstances, like a partially visible line
17084 becoming fully visible, or because newly displayed lines are displayed
17085 in smaller font sizes.
17087 7. Update W's window end information. */
17090 try_window_id (struct window
*w
)
17092 struct frame
*f
= XFRAME (w
->frame
);
17093 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17094 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17095 struct glyph_row
*last_unchanged_at_beg_row
;
17096 struct glyph_row
*first_unchanged_at_end_row
;
17097 struct glyph_row
*row
;
17098 struct glyph_row
*bottom_row
;
17101 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17103 struct text_pos start_pos
;
17105 int first_unchanged_at_end_vpos
= 0;
17106 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17107 struct text_pos start
;
17108 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17111 if (inhibit_try_window_id
)
17115 /* This is handy for debugging. */
17117 #define GIVE_UP(X) \
17119 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17123 #define GIVE_UP(X) return 0
17126 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17128 /* Don't use this for mini-windows because these can show
17129 messages and mini-buffers, and we don't handle that here. */
17130 if (MINI_WINDOW_P (w
))
17133 /* This flag is used to prevent redisplay optimizations. */
17134 if (windows_or_buffers_changed
|| cursor_type_changed
)
17137 /* Verify that narrowing has not changed.
17138 Also verify that we were not told to prevent redisplay optimizations.
17139 It would be nice to further
17140 reduce the number of cases where this prevents try_window_id. */
17141 if (current_buffer
->clip_changed
17142 || current_buffer
->prevent_redisplay_optimizations_p
)
17145 /* Window must either use window-based redisplay or be full width. */
17146 if (!FRAME_WINDOW_P (f
)
17147 && (!FRAME_LINE_INS_DEL_OK (f
)
17148 || !WINDOW_FULL_WIDTH_P (w
)))
17151 /* Give up if point is known NOT to appear in W. */
17152 if (PT
< CHARPOS (start
))
17155 /* Another way to prevent redisplay optimizations. */
17156 if (w
->last_modified
== 0)
17159 /* Verify that window is not hscrolled. */
17160 if (w
->hscroll
!= 0)
17163 /* Verify that display wasn't paused. */
17164 if (NILP (w
->window_end_valid
))
17167 /* Can't use this if highlighting a region because a cursor movement
17168 will do more than just set the cursor. */
17169 if (!NILP (Vtransient_mark_mode
)
17170 && !NILP (BVAR (current_buffer
, mark_active
)))
17173 /* Likewise if highlighting trailing whitespace. */
17174 if (!NILP (Vshow_trailing_whitespace
))
17177 /* Likewise if showing a region. */
17178 if (!NILP (w
->region_showing
))
17181 /* Can't use this if overlay arrow position and/or string have
17183 if (overlay_arrows_changed_p ())
17186 /* When word-wrap is on, adding a space to the first word of a
17187 wrapped line can change the wrap position, altering the line
17188 above it. It might be worthwhile to handle this more
17189 intelligently, but for now just redisplay from scratch. */
17190 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17193 /* Under bidi reordering, adding or deleting a character in the
17194 beginning of a paragraph, before the first strong directional
17195 character, can change the base direction of the paragraph (unless
17196 the buffer specifies a fixed paragraph direction), which will
17197 require to redisplay the whole paragraph. It might be worthwhile
17198 to find the paragraph limits and widen the range of redisplayed
17199 lines to that, but for now just give up this optimization and
17200 redisplay from scratch. */
17201 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17202 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17205 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17206 only if buffer has really changed. The reason is that the gap is
17207 initially at Z for freshly visited files. The code below would
17208 set end_unchanged to 0 in that case. */
17209 if (MODIFF
> SAVE_MODIFF
17210 /* This seems to happen sometimes after saving a buffer. */
17211 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17213 if (GPT
- BEG
< BEG_UNCHANGED
)
17214 BEG_UNCHANGED
= GPT
- BEG
;
17215 if (Z
- GPT
< END_UNCHANGED
)
17216 END_UNCHANGED
= Z
- GPT
;
17219 /* The position of the first and last character that has been changed. */
17220 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17221 last_changed_charpos
= Z
- END_UNCHANGED
;
17223 /* If window starts after a line end, and the last change is in
17224 front of that newline, then changes don't affect the display.
17225 This case happens with stealth-fontification. Note that although
17226 the display is unchanged, glyph positions in the matrix have to
17227 be adjusted, of course. */
17228 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17229 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17230 && ((last_changed_charpos
< CHARPOS (start
)
17231 && CHARPOS (start
) == BEGV
)
17232 || (last_changed_charpos
< CHARPOS (start
) - 1
17233 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17235 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17236 struct glyph_row
*r0
;
17238 /* Compute how many chars/bytes have been added to or removed
17239 from the buffer. */
17240 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17241 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17242 Z_delta
= Z
- Z_old
;
17243 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17245 /* Give up if PT is not in the window. Note that it already has
17246 been checked at the start of try_window_id that PT is not in
17247 front of the window start. */
17248 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17251 /* If window start is unchanged, we can reuse the whole matrix
17252 as is, after adjusting glyph positions. No need to compute
17253 the window end again, since its offset from Z hasn't changed. */
17254 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17255 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17256 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17257 /* PT must not be in a partially visible line. */
17258 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17259 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17261 /* Adjust positions in the glyph matrix. */
17262 if (Z_delta
|| Z_delta_bytes
)
17264 struct glyph_row
*r1
17265 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17266 increment_matrix_positions (w
->current_matrix
,
17267 MATRIX_ROW_VPOS (r0
, current_matrix
),
17268 MATRIX_ROW_VPOS (r1
, current_matrix
),
17269 Z_delta
, Z_delta_bytes
);
17272 /* Set the cursor. */
17273 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17275 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17282 /* Handle the case that changes are all below what is displayed in
17283 the window, and that PT is in the window. This shortcut cannot
17284 be taken if ZV is visible in the window, and text has been added
17285 there that is visible in the window. */
17286 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17287 /* ZV is not visible in the window, or there are no
17288 changes at ZV, actually. */
17289 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17290 || first_changed_charpos
== last_changed_charpos
))
17292 struct glyph_row
*r0
;
17294 /* Give up if PT is not in the window. Note that it already has
17295 been checked at the start of try_window_id that PT is not in
17296 front of the window start. */
17297 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17300 /* If window start is unchanged, we can reuse the whole matrix
17301 as is, without changing glyph positions since no text has
17302 been added/removed in front of the window end. */
17303 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17304 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17305 /* PT must not be in a partially visible line. */
17306 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17307 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17309 /* We have to compute the window end anew since text
17310 could have been added/removed after it. */
17312 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17313 w
->window_end_bytepos
17314 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17316 /* Set the cursor. */
17317 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17319 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17326 /* Give up if window start is in the changed area.
17328 The condition used to read
17330 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17332 but why that was tested escapes me at the moment. */
17333 if (CHARPOS (start
) >= first_changed_charpos
17334 && CHARPOS (start
) <= last_changed_charpos
)
17337 /* Check that window start agrees with the start of the first glyph
17338 row in its current matrix. Check this after we know the window
17339 start is not in changed text, otherwise positions would not be
17341 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17342 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17345 /* Give up if the window ends in strings. Overlay strings
17346 at the end are difficult to handle, so don't try. */
17347 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17348 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17351 /* Compute the position at which we have to start displaying new
17352 lines. Some of the lines at the top of the window might be
17353 reusable because they are not displaying changed text. Find the
17354 last row in W's current matrix not affected by changes at the
17355 start of current_buffer. Value is null if changes start in the
17356 first line of window. */
17357 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17358 if (last_unchanged_at_beg_row
)
17360 /* Avoid starting to display in the middle of a character, a TAB
17361 for instance. This is easier than to set up the iterator
17362 exactly, and it's not a frequent case, so the additional
17363 effort wouldn't really pay off. */
17364 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17365 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17366 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17367 --last_unchanged_at_beg_row
;
17369 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17372 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17374 start_pos
= it
.current
.pos
;
17376 /* Start displaying new lines in the desired matrix at the same
17377 vpos we would use in the current matrix, i.e. below
17378 last_unchanged_at_beg_row. */
17379 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17381 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17382 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17384 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17388 /* There are no reusable lines at the start of the window.
17389 Start displaying in the first text line. */
17390 start_display (&it
, w
, start
);
17391 it
.vpos
= it
.first_vpos
;
17392 start_pos
= it
.current
.pos
;
17395 /* Find the first row that is not affected by changes at the end of
17396 the buffer. Value will be null if there is no unchanged row, in
17397 which case we must redisplay to the end of the window. delta
17398 will be set to the value by which buffer positions beginning with
17399 first_unchanged_at_end_row have to be adjusted due to text
17401 first_unchanged_at_end_row
17402 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17403 IF_DEBUG (debug_delta
= delta
);
17404 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17406 /* Set stop_pos to the buffer position up to which we will have to
17407 display new lines. If first_unchanged_at_end_row != NULL, this
17408 is the buffer position of the start of the line displayed in that
17409 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17410 that we don't stop at a buffer position. */
17412 if (first_unchanged_at_end_row
)
17414 eassert (last_unchanged_at_beg_row
== NULL
17415 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17417 /* If this is a continuation line, move forward to the next one
17418 that isn't. Changes in lines above affect this line.
17419 Caution: this may move first_unchanged_at_end_row to a row
17420 not displaying text. */
17421 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17422 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17423 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17424 < it
.last_visible_y
))
17425 ++first_unchanged_at_end_row
;
17427 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17428 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17429 >= it
.last_visible_y
))
17430 first_unchanged_at_end_row
= NULL
;
17433 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17435 first_unchanged_at_end_vpos
17436 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17437 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17440 else if (last_unchanged_at_beg_row
== NULL
)
17446 /* Either there is no unchanged row at the end, or the one we have
17447 now displays text. This is a necessary condition for the window
17448 end pos calculation at the end of this function. */
17449 eassert (first_unchanged_at_end_row
== NULL
17450 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17452 debug_last_unchanged_at_beg_vpos
17453 = (last_unchanged_at_beg_row
17454 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17456 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17458 #endif /* GLYPH_DEBUG */
17461 /* Display new lines. Set last_text_row to the last new line
17462 displayed which has text on it, i.e. might end up as being the
17463 line where the window_end_vpos is. */
17464 w
->cursor
.vpos
= -1;
17465 last_text_row
= NULL
;
17466 overlay_arrow_seen
= 0;
17467 while (it
.current_y
< it
.last_visible_y
17468 && !fonts_changed_p
17469 && (first_unchanged_at_end_row
== NULL
17470 || IT_CHARPOS (it
) < stop_pos
))
17472 if (display_line (&it
))
17473 last_text_row
= it
.glyph_row
- 1;
17476 if (fonts_changed_p
)
17480 /* Compute differences in buffer positions, y-positions etc. for
17481 lines reused at the bottom of the window. Compute what we can
17483 if (first_unchanged_at_end_row
17484 /* No lines reused because we displayed everything up to the
17485 bottom of the window. */
17486 && it
.current_y
< it
.last_visible_y
)
17489 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17491 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17492 run
.current_y
= first_unchanged_at_end_row
->y
;
17493 run
.desired_y
= run
.current_y
+ dy
;
17494 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17498 delta
= delta_bytes
= dvpos
= dy
17499 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17500 first_unchanged_at_end_row
= NULL
;
17502 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17505 /* Find the cursor if not already found. We have to decide whether
17506 PT will appear on this window (it sometimes doesn't, but this is
17507 not a very frequent case.) This decision has to be made before
17508 the current matrix is altered. A value of cursor.vpos < 0 means
17509 that PT is either in one of the lines beginning at
17510 first_unchanged_at_end_row or below the window. Don't care for
17511 lines that might be displayed later at the window end; as
17512 mentioned, this is not a frequent case. */
17513 if (w
->cursor
.vpos
< 0)
17515 /* Cursor in unchanged rows at the top? */
17516 if (PT
< CHARPOS (start_pos
)
17517 && last_unchanged_at_beg_row
)
17519 row
= row_containing_pos (w
, PT
,
17520 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17521 last_unchanged_at_beg_row
+ 1, 0);
17523 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17526 /* Start from first_unchanged_at_end_row looking for PT. */
17527 else if (first_unchanged_at_end_row
)
17529 row
= row_containing_pos (w
, PT
- delta
,
17530 first_unchanged_at_end_row
, NULL
, 0);
17532 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17533 delta_bytes
, dy
, dvpos
);
17536 /* Give up if cursor was not found. */
17537 if (w
->cursor
.vpos
< 0)
17539 clear_glyph_matrix (w
->desired_matrix
);
17544 /* Don't let the cursor end in the scroll margins. */
17546 int this_scroll_margin
, cursor_height
;
17548 this_scroll_margin
=
17549 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17550 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17551 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17553 if ((w
->cursor
.y
< this_scroll_margin
17554 && CHARPOS (start
) > BEGV
)
17555 /* Old redisplay didn't take scroll margin into account at the bottom,
17556 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17557 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17558 ? cursor_height
+ this_scroll_margin
17559 : 1)) > it
.last_visible_y
)
17561 w
->cursor
.vpos
= -1;
17562 clear_glyph_matrix (w
->desired_matrix
);
17567 /* Scroll the display. Do it before changing the current matrix so
17568 that xterm.c doesn't get confused about where the cursor glyph is
17570 if (dy
&& run
.height
)
17574 if (FRAME_WINDOW_P (f
))
17576 FRAME_RIF (f
)->update_window_begin_hook (w
);
17577 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17578 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17579 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17583 /* Terminal frame. In this case, dvpos gives the number of
17584 lines to scroll by; dvpos < 0 means scroll up. */
17586 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17587 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17588 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17589 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17590 + window_internal_height (w
));
17592 #if defined (HAVE_GPM) || defined (MSDOS)
17593 x_clear_window_mouse_face (w
);
17595 /* Perform the operation on the screen. */
17598 /* Scroll last_unchanged_at_beg_row to the end of the
17599 window down dvpos lines. */
17600 set_terminal_window (f
, end
);
17602 /* On dumb terminals delete dvpos lines at the end
17603 before inserting dvpos empty lines. */
17604 if (!FRAME_SCROLL_REGION_OK (f
))
17605 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17607 /* Insert dvpos empty lines in front of
17608 last_unchanged_at_beg_row. */
17609 ins_del_lines (f
, from
, dvpos
);
17611 else if (dvpos
< 0)
17613 /* Scroll up last_unchanged_at_beg_vpos to the end of
17614 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17615 set_terminal_window (f
, end
);
17617 /* Delete dvpos lines in front of
17618 last_unchanged_at_beg_vpos. ins_del_lines will set
17619 the cursor to the given vpos and emit |dvpos| delete
17621 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17623 /* On a dumb terminal insert dvpos empty lines at the
17625 if (!FRAME_SCROLL_REGION_OK (f
))
17626 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17629 set_terminal_window (f
, 0);
17635 /* Shift reused rows of the current matrix to the right position.
17636 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17638 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17639 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17642 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17643 bottom_vpos
, dvpos
);
17644 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17647 else if (dvpos
> 0)
17649 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17650 bottom_vpos
, dvpos
);
17651 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17652 first_unchanged_at_end_vpos
+ dvpos
, 0);
17655 /* For frame-based redisplay, make sure that current frame and window
17656 matrix are in sync with respect to glyph memory. */
17657 if (!FRAME_WINDOW_P (f
))
17658 sync_frame_with_window_matrix_rows (w
);
17660 /* Adjust buffer positions in reused rows. */
17661 if (delta
|| delta_bytes
)
17662 increment_matrix_positions (current_matrix
,
17663 first_unchanged_at_end_vpos
+ dvpos
,
17664 bottom_vpos
, delta
, delta_bytes
);
17666 /* Adjust Y positions. */
17668 shift_glyph_matrix (w
, current_matrix
,
17669 first_unchanged_at_end_vpos
+ dvpos
,
17672 if (first_unchanged_at_end_row
)
17674 first_unchanged_at_end_row
+= dvpos
;
17675 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17676 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17677 first_unchanged_at_end_row
= NULL
;
17680 /* If scrolling up, there may be some lines to display at the end of
17682 last_text_row_at_end
= NULL
;
17685 /* Scrolling up can leave for example a partially visible line
17686 at the end of the window to be redisplayed. */
17687 /* Set last_row to the glyph row in the current matrix where the
17688 window end line is found. It has been moved up or down in
17689 the matrix by dvpos. */
17690 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17691 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17693 /* If last_row is the window end line, it should display text. */
17694 eassert (last_row
->displays_text_p
);
17696 /* If window end line was partially visible before, begin
17697 displaying at that line. Otherwise begin displaying with the
17698 line following it. */
17699 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17701 init_to_row_start (&it
, w
, last_row
);
17702 it
.vpos
= last_vpos
;
17703 it
.current_y
= last_row
->y
;
17707 init_to_row_end (&it
, w
, last_row
);
17708 it
.vpos
= 1 + last_vpos
;
17709 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17713 /* We may start in a continuation line. If so, we have to
17714 get the right continuation_lines_width and current_x. */
17715 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17716 it
.hpos
= it
.current_x
= 0;
17718 /* Display the rest of the lines at the window end. */
17719 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17720 while (it
.current_y
< it
.last_visible_y
17721 && !fonts_changed_p
)
17723 /* Is it always sure that the display agrees with lines in
17724 the current matrix? I don't think so, so we mark rows
17725 displayed invalid in the current matrix by setting their
17726 enabled_p flag to zero. */
17727 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17728 if (display_line (&it
))
17729 last_text_row_at_end
= it
.glyph_row
- 1;
17733 /* Update window_end_pos and window_end_vpos. */
17734 if (first_unchanged_at_end_row
17735 && !last_text_row_at_end
)
17737 /* Window end line if one of the preserved rows from the current
17738 matrix. Set row to the last row displaying text in current
17739 matrix starting at first_unchanged_at_end_row, after
17741 eassert (first_unchanged_at_end_row
->displays_text_p
);
17742 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17743 first_unchanged_at_end_row
);
17744 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17746 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17747 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17749 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17750 eassert (w
->window_end_bytepos
>= 0);
17751 IF_DEBUG (debug_method_add (w
, "A"));
17753 else if (last_text_row_at_end
)
17756 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17757 w
->window_end_bytepos
17758 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17760 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17761 eassert (w
->window_end_bytepos
>= 0);
17762 IF_DEBUG (debug_method_add (w
, "B"));
17764 else if (last_text_row
)
17766 /* We have displayed either to the end of the window or at the
17767 end of the window, i.e. the last row with text is to be found
17768 in the desired matrix. */
17770 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17771 w
->window_end_bytepos
17772 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17774 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17775 eassert (w
->window_end_bytepos
>= 0);
17777 else if (first_unchanged_at_end_row
== NULL
17778 && last_text_row
== NULL
17779 && last_text_row_at_end
== NULL
)
17781 /* Displayed to end of window, but no line containing text was
17782 displayed. Lines were deleted at the end of the window. */
17783 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17784 int vpos
= XFASTINT (w
->window_end_vpos
);
17785 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17786 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17789 row
== NULL
&& vpos
>= first_vpos
;
17790 --vpos
, --current_row
, --desired_row
)
17792 if (desired_row
->enabled_p
)
17794 if (desired_row
->displays_text_p
)
17797 else if (current_row
->displays_text_p
)
17801 eassert (row
!= NULL
);
17802 w
->window_end_vpos
= make_number (vpos
+ 1);
17803 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17804 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17805 eassert (w
->window_end_bytepos
>= 0);
17806 IF_DEBUG (debug_method_add (w
, "C"));
17811 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17812 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17814 /* Record that display has not been completed. */
17815 w
->window_end_valid
= Qnil
;
17816 w
->desired_matrix
->no_scrolling_p
= 1;
17824 /***********************************************************************
17825 More debugging support
17826 ***********************************************************************/
17830 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17831 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17832 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17835 /* Dump the contents of glyph matrix MATRIX on stderr.
17837 GLYPHS 0 means don't show glyph contents.
17838 GLYPHS 1 means show glyphs in short form
17839 GLYPHS > 1 means show glyphs in long form. */
17842 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17845 for (i
= 0; i
< matrix
->nrows
; ++i
)
17846 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17850 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17851 the glyph row and area where the glyph comes from. */
17854 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17856 if (glyph
->type
== CHAR_GLYPH
)
17859 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17860 glyph
- row
->glyphs
[TEXT_AREA
],
17863 (BUFFERP (glyph
->object
)
17865 : (STRINGP (glyph
->object
)
17868 glyph
->pixel_width
,
17870 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17874 glyph
->left_box_line_p
,
17875 glyph
->right_box_line_p
);
17877 else if (glyph
->type
== STRETCH_GLYPH
)
17880 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17881 glyph
- row
->glyphs
[TEXT_AREA
],
17884 (BUFFERP (glyph
->object
)
17886 : (STRINGP (glyph
->object
)
17889 glyph
->pixel_width
,
17893 glyph
->left_box_line_p
,
17894 glyph
->right_box_line_p
);
17896 else if (glyph
->type
== IMAGE_GLYPH
)
17899 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17900 glyph
- row
->glyphs
[TEXT_AREA
],
17903 (BUFFERP (glyph
->object
)
17905 : (STRINGP (glyph
->object
)
17908 glyph
->pixel_width
,
17912 glyph
->left_box_line_p
,
17913 glyph
->right_box_line_p
);
17915 else if (glyph
->type
== COMPOSITE_GLYPH
)
17918 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17919 glyph
- row
->glyphs
[TEXT_AREA
],
17922 (BUFFERP (glyph
->object
)
17924 : (STRINGP (glyph
->object
)
17927 glyph
->pixel_width
,
17929 if (glyph
->u
.cmp
.automatic
)
17932 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17933 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17935 glyph
->left_box_line_p
,
17936 glyph
->right_box_line_p
);
17941 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17942 GLYPHS 0 means don't show glyph contents.
17943 GLYPHS 1 means show glyphs in short form
17944 GLYPHS > 1 means show glyphs in long form. */
17947 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17951 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17952 fprintf (stderr
, "======================================================================\n");
17954 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17955 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17957 MATRIX_ROW_START_CHARPOS (row
),
17958 MATRIX_ROW_END_CHARPOS (row
),
17959 row
->used
[TEXT_AREA
],
17960 row
->contains_overlapping_glyphs_p
,
17962 row
->truncated_on_left_p
,
17963 row
->truncated_on_right_p
,
17965 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17966 row
->displays_text_p
,
17969 row
->ends_in_middle_of_char_p
,
17970 row
->starts_in_middle_of_char_p
,
17976 row
->visible_height
,
17979 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17980 row
->end
.overlay_string_index
,
17981 row
->continuation_lines_width
);
17982 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17983 CHARPOS (row
->start
.string_pos
),
17984 CHARPOS (row
->end
.string_pos
));
17985 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17986 row
->end
.dpvec_index
);
17993 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17995 struct glyph
*glyph
= row
->glyphs
[area
];
17996 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17998 /* Glyph for a line end in text. */
17999 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18002 if (glyph
< glyph_end
)
18003 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18005 for (; glyph
< glyph_end
; ++glyph
)
18006 dump_glyph (row
, glyph
, area
);
18009 else if (glyphs
== 1)
18013 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18015 char *s
= (char *) alloca (row
->used
[area
] + 1);
18018 for (i
= 0; i
< row
->used
[area
]; ++i
)
18020 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18021 if (glyph
->type
== CHAR_GLYPH
18022 && glyph
->u
.ch
< 0x80
18023 && glyph
->u
.ch
>= ' ')
18024 s
[i
] = glyph
->u
.ch
;
18030 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18036 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18037 Sdump_glyph_matrix
, 0, 1, "p",
18038 doc
: /* Dump the current matrix of the selected window to stderr.
18039 Shows contents of glyph row structures. With non-nil
18040 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18041 glyphs in short form, otherwise show glyphs in long form. */)
18042 (Lisp_Object glyphs
)
18044 struct window
*w
= XWINDOW (selected_window
);
18045 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18047 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18048 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18049 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18050 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18051 fprintf (stderr
, "=============================================\n");
18052 dump_glyph_matrix (w
->current_matrix
,
18053 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18058 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18059 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18062 struct frame
*f
= XFRAME (selected_frame
);
18063 dump_glyph_matrix (f
->current_matrix
, 1);
18068 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18069 doc
: /* Dump glyph row ROW to stderr.
18070 GLYPH 0 means don't dump glyphs.
18071 GLYPH 1 means dump glyphs in short form.
18072 GLYPH > 1 or omitted means dump glyphs in long form. */)
18073 (Lisp_Object row
, Lisp_Object glyphs
)
18075 struct glyph_matrix
*matrix
;
18078 CHECK_NUMBER (row
);
18079 matrix
= XWINDOW (selected_window
)->current_matrix
;
18081 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18082 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18084 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18089 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18090 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18091 GLYPH 0 means don't dump glyphs.
18092 GLYPH 1 means dump glyphs in short form.
18093 GLYPH > 1 or omitted means dump glyphs in long form. */)
18094 (Lisp_Object row
, Lisp_Object glyphs
)
18096 struct frame
*sf
= SELECTED_FRAME ();
18097 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18100 CHECK_NUMBER (row
);
18102 if (vpos
>= 0 && vpos
< m
->nrows
)
18103 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18104 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18109 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18110 doc
: /* Toggle tracing of redisplay.
18111 With ARG, turn tracing on if and only if ARG is positive. */)
18115 trace_redisplay_p
= !trace_redisplay_p
;
18118 arg
= Fprefix_numeric_value (arg
);
18119 trace_redisplay_p
= XINT (arg
) > 0;
18126 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18127 doc
: /* Like `format', but print result to stderr.
18128 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18129 (ptrdiff_t nargs
, Lisp_Object
*args
)
18131 Lisp_Object s
= Fformat (nargs
, args
);
18132 fprintf (stderr
, "%s", SDATA (s
));
18136 #endif /* GLYPH_DEBUG */
18140 /***********************************************************************
18141 Building Desired Matrix Rows
18142 ***********************************************************************/
18144 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18145 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18147 static struct glyph_row
*
18148 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18150 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18151 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18152 struct buffer
*old
= current_buffer
;
18153 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18154 int arrow_len
= SCHARS (overlay_arrow_string
);
18155 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18156 const unsigned char *p
;
18159 int n_glyphs_before
;
18161 set_buffer_temp (buffer
);
18162 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18163 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18164 SET_TEXT_POS (it
.position
, 0, 0);
18166 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18168 while (p
< arrow_end
)
18170 Lisp_Object face
, ilisp
;
18172 /* Get the next character. */
18174 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18177 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18178 if (! ASCII_CHAR_P (it
.c
))
18179 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18183 /* Get its face. */
18184 ilisp
= make_number (p
- arrow_string
);
18185 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18186 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18188 /* Compute its width, get its glyphs. */
18189 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18190 SET_TEXT_POS (it
.position
, -1, -1);
18191 PRODUCE_GLYPHS (&it
);
18193 /* If this character doesn't fit any more in the line, we have
18194 to remove some glyphs. */
18195 if (it
.current_x
> it
.last_visible_x
)
18197 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18202 set_buffer_temp (old
);
18203 return it
.glyph_row
;
18207 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
18208 glyphs are only inserted for terminal frames since we can't really
18209 win with truncation glyphs when partially visible glyphs are
18210 involved. Which glyphs to insert is determined by
18211 produce_special_glyphs. */
18214 insert_left_trunc_glyphs (struct it
*it
)
18216 struct it truncate_it
;
18217 struct glyph
*from
, *end
, *to
, *toend
;
18219 eassert (!FRAME_WINDOW_P (it
->f
));
18221 /* Get the truncation glyphs. */
18223 truncate_it
.current_x
= 0;
18224 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18225 truncate_it
.glyph_row
= &scratch_glyph_row
;
18226 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18227 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18228 truncate_it
.object
= make_number (0);
18229 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18231 /* Overwrite glyphs from IT with truncation glyphs. */
18232 if (!it
->glyph_row
->reversed_p
)
18234 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18235 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
18236 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18237 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18242 /* There may be padding glyphs left over. Overwrite them too. */
18243 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18245 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18251 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18255 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18256 that back to front. */
18257 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18258 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18259 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18260 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18262 while (from
>= end
&& to
>= toend
)
18264 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18267 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18268 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18269 while (from
>= end
&& to
>= toend
)
18274 /* Need to free some room before prepending additional
18276 int move_by
= from
- end
+ 1;
18277 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18278 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18280 for ( ; g
>= g0
; g
--)
18282 while (from
>= end
)
18284 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18289 /* Compute the hash code for ROW. */
18291 row_hash (struct glyph_row
*row
)
18294 unsigned hashval
= 0;
18296 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18297 for (k
= 0; k
< row
->used
[area
]; ++k
)
18298 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18299 + row
->glyphs
[area
][k
].u
.val
18300 + row
->glyphs
[area
][k
].face_id
18301 + row
->glyphs
[area
][k
].padding_p
18302 + (row
->glyphs
[area
][k
].type
<< 2));
18307 /* Compute the pixel height and width of IT->glyph_row.
18309 Most of the time, ascent and height of a display line will be equal
18310 to the max_ascent and max_height values of the display iterator
18311 structure. This is not the case if
18313 1. We hit ZV without displaying anything. In this case, max_ascent
18314 and max_height will be zero.
18316 2. We have some glyphs that don't contribute to the line height.
18317 (The glyph row flag contributes_to_line_height_p is for future
18318 pixmap extensions).
18320 The first case is easily covered by using default values because in
18321 these cases, the line height does not really matter, except that it
18322 must not be zero. */
18325 compute_line_metrics (struct it
*it
)
18327 struct glyph_row
*row
= it
->glyph_row
;
18329 if (FRAME_WINDOW_P (it
->f
))
18331 int i
, min_y
, max_y
;
18333 /* The line may consist of one space only, that was added to
18334 place the cursor on it. If so, the row's height hasn't been
18336 if (row
->height
== 0)
18338 if (it
->max_ascent
+ it
->max_descent
== 0)
18339 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18340 row
->ascent
= it
->max_ascent
;
18341 row
->height
= it
->max_ascent
+ it
->max_descent
;
18342 row
->phys_ascent
= it
->max_phys_ascent
;
18343 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18344 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18347 /* Compute the width of this line. */
18348 row
->pixel_width
= row
->x
;
18349 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18350 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18352 eassert (row
->pixel_width
>= 0);
18353 eassert (row
->ascent
>= 0 && row
->height
> 0);
18355 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18356 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18358 /* If first line's physical ascent is larger than its logical
18359 ascent, use the physical ascent, and make the row taller.
18360 This makes accented characters fully visible. */
18361 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18362 && row
->phys_ascent
> row
->ascent
)
18364 row
->height
+= row
->phys_ascent
- row
->ascent
;
18365 row
->ascent
= row
->phys_ascent
;
18368 /* Compute how much of the line is visible. */
18369 row
->visible_height
= row
->height
;
18371 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18372 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18374 if (row
->y
< min_y
)
18375 row
->visible_height
-= min_y
- row
->y
;
18376 if (row
->y
+ row
->height
> max_y
)
18377 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18381 row
->pixel_width
= row
->used
[TEXT_AREA
];
18382 if (row
->continued_p
)
18383 row
->pixel_width
-= it
->continuation_pixel_width
;
18384 else if (row
->truncated_on_right_p
)
18385 row
->pixel_width
-= it
->truncation_pixel_width
;
18386 row
->ascent
= row
->phys_ascent
= 0;
18387 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18388 row
->extra_line_spacing
= 0;
18391 /* Compute a hash code for this row. */
18392 row
->hash
= row_hash (row
);
18394 it
->max_ascent
= it
->max_descent
= 0;
18395 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18399 /* Append one space to the glyph row of iterator IT if doing a
18400 window-based redisplay. The space has the same face as
18401 IT->face_id. Value is non-zero if a space was added.
18403 This function is called to make sure that there is always one glyph
18404 at the end of a glyph row that the cursor can be set on under
18405 window-systems. (If there weren't such a glyph we would not know
18406 how wide and tall a box cursor should be displayed).
18408 At the same time this space let's a nicely handle clearing to the
18409 end of the line if the row ends in italic text. */
18412 append_space_for_newline (struct it
*it
, int default_face_p
)
18414 if (FRAME_WINDOW_P (it
->f
))
18416 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18418 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18419 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18421 /* Save some values that must not be changed.
18422 Must save IT->c and IT->len because otherwise
18423 ITERATOR_AT_END_P wouldn't work anymore after
18424 append_space_for_newline has been called. */
18425 enum display_element_type saved_what
= it
->what
;
18426 int saved_c
= it
->c
, saved_len
= it
->len
;
18427 int saved_char_to_display
= it
->char_to_display
;
18428 int saved_x
= it
->current_x
;
18429 int saved_face_id
= it
->face_id
;
18430 struct text_pos saved_pos
;
18431 Lisp_Object saved_object
;
18434 saved_object
= it
->object
;
18435 saved_pos
= it
->position
;
18437 it
->what
= IT_CHARACTER
;
18438 memset (&it
->position
, 0, sizeof it
->position
);
18439 it
->object
= make_number (0);
18440 it
->c
= it
->char_to_display
= ' ';
18443 /* If the default face was remapped, be sure to use the
18444 remapped face for the appended newline. */
18445 if (default_face_p
)
18446 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18447 else if (it
->face_before_selective_p
)
18448 it
->face_id
= it
->saved_face_id
;
18449 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18450 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18452 PRODUCE_GLYPHS (it
);
18454 it
->override_ascent
= -1;
18455 it
->constrain_row_ascent_descent_p
= 0;
18456 it
->current_x
= saved_x
;
18457 it
->object
= saved_object
;
18458 it
->position
= saved_pos
;
18459 it
->what
= saved_what
;
18460 it
->face_id
= saved_face_id
;
18461 it
->len
= saved_len
;
18463 it
->char_to_display
= saved_char_to_display
;
18472 /* Extend the face of the last glyph in the text area of IT->glyph_row
18473 to the end of the display line. Called from display_line. If the
18474 glyph row is empty, add a space glyph to it so that we know the
18475 face to draw. Set the glyph row flag fill_line_p. If the glyph
18476 row is R2L, prepend a stretch glyph to cover the empty space to the
18477 left of the leftmost glyph. */
18480 extend_face_to_end_of_line (struct it
*it
)
18482 struct face
*face
, *default_face
;
18483 struct frame
*f
= it
->f
;
18485 /* If line is already filled, do nothing. Non window-system frames
18486 get a grace of one more ``pixel'' because their characters are
18487 1-``pixel'' wide, so they hit the equality too early. This grace
18488 is needed only for R2L rows that are not continued, to produce
18489 one extra blank where we could display the cursor. */
18490 if (it
->current_x
>= it
->last_visible_x
18491 + (!FRAME_WINDOW_P (f
)
18492 && it
->glyph_row
->reversed_p
18493 && !it
->glyph_row
->continued_p
))
18496 /* The default face, possibly remapped. */
18497 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18499 /* Face extension extends the background and box of IT->face_id
18500 to the end of the line. If the background equals the background
18501 of the frame, we don't have to do anything. */
18502 if (it
->face_before_selective_p
)
18503 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18505 face
= FACE_FROM_ID (f
, it
->face_id
);
18507 if (FRAME_WINDOW_P (f
)
18508 && it
->glyph_row
->displays_text_p
18509 && face
->box
== FACE_NO_BOX
18510 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18512 && !it
->glyph_row
->reversed_p
)
18515 /* Set the glyph row flag indicating that the face of the last glyph
18516 in the text area has to be drawn to the end of the text area. */
18517 it
->glyph_row
->fill_line_p
= 1;
18519 /* If current character of IT is not ASCII, make sure we have the
18520 ASCII face. This will be automatically undone the next time
18521 get_next_display_element returns a multibyte character. Note
18522 that the character will always be single byte in unibyte
18524 if (!ASCII_CHAR_P (it
->c
))
18526 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18529 if (FRAME_WINDOW_P (f
))
18531 /* If the row is empty, add a space with the current face of IT,
18532 so that we know which face to draw. */
18533 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18535 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18536 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18537 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18539 #ifdef HAVE_WINDOW_SYSTEM
18540 if (it
->glyph_row
->reversed_p
)
18542 /* Prepend a stretch glyph to the row, such that the
18543 rightmost glyph will be drawn flushed all the way to the
18544 right margin of the window. The stretch glyph that will
18545 occupy the empty space, if any, to the left of the
18547 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18548 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18549 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18551 int row_width
, stretch_ascent
, stretch_width
;
18552 struct text_pos saved_pos
;
18553 int saved_face_id
, saved_avoid_cursor
;
18555 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18556 row_width
+= g
->pixel_width
;
18557 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18558 if (stretch_width
> 0)
18561 (((it
->ascent
+ it
->descent
)
18562 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18563 saved_pos
= it
->position
;
18564 memset (&it
->position
, 0, sizeof it
->position
);
18565 saved_avoid_cursor
= it
->avoid_cursor_p
;
18566 it
->avoid_cursor_p
= 1;
18567 saved_face_id
= it
->face_id
;
18568 /* The last row's stretch glyph should get the default
18569 face, to avoid painting the rest of the window with
18570 the region face, if the region ends at ZV. */
18571 if (it
->glyph_row
->ends_at_zv_p
)
18572 it
->face_id
= default_face
->id
;
18574 it
->face_id
= face
->id
;
18575 append_stretch_glyph (it
, make_number (0), stretch_width
,
18576 it
->ascent
+ it
->descent
, stretch_ascent
);
18577 it
->position
= saved_pos
;
18578 it
->avoid_cursor_p
= saved_avoid_cursor
;
18579 it
->face_id
= saved_face_id
;
18582 #endif /* HAVE_WINDOW_SYSTEM */
18586 /* Save some values that must not be changed. */
18587 int saved_x
= it
->current_x
;
18588 struct text_pos saved_pos
;
18589 Lisp_Object saved_object
;
18590 enum display_element_type saved_what
= it
->what
;
18591 int saved_face_id
= it
->face_id
;
18593 saved_object
= it
->object
;
18594 saved_pos
= it
->position
;
18596 it
->what
= IT_CHARACTER
;
18597 memset (&it
->position
, 0, sizeof it
->position
);
18598 it
->object
= make_number (0);
18599 it
->c
= it
->char_to_display
= ' ';
18601 /* The last row's blank glyphs should get the default face, to
18602 avoid painting the rest of the window with the region face,
18603 if the region ends at ZV. */
18604 if (it
->glyph_row
->ends_at_zv_p
)
18605 it
->face_id
= default_face
->id
;
18607 it
->face_id
= face
->id
;
18609 PRODUCE_GLYPHS (it
);
18611 while (it
->current_x
<= it
->last_visible_x
)
18612 PRODUCE_GLYPHS (it
);
18614 /* Don't count these blanks really. It would let us insert a left
18615 truncation glyph below and make us set the cursor on them, maybe. */
18616 it
->current_x
= saved_x
;
18617 it
->object
= saved_object
;
18618 it
->position
= saved_pos
;
18619 it
->what
= saved_what
;
18620 it
->face_id
= saved_face_id
;
18625 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18626 trailing whitespace. */
18629 trailing_whitespace_p (ptrdiff_t charpos
)
18631 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18634 while (bytepos
< ZV_BYTE
18635 && (c
= FETCH_CHAR (bytepos
),
18636 c
== ' ' || c
== '\t'))
18639 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18641 if (bytepos
!= PT_BYTE
)
18648 /* Highlight trailing whitespace, if any, in ROW. */
18651 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18653 int used
= row
->used
[TEXT_AREA
];
18657 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18658 struct glyph
*glyph
= start
+ used
- 1;
18660 if (row
->reversed_p
)
18662 /* Right-to-left rows need to be processed in the opposite
18663 direction, so swap the edge pointers. */
18665 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18668 /* Skip over glyphs inserted to display the cursor at the
18669 end of a line, for extending the face of the last glyph
18670 to the end of the line on terminals, and for truncation
18671 and continuation glyphs. */
18672 if (!row
->reversed_p
)
18674 while (glyph
>= start
18675 && glyph
->type
== CHAR_GLYPH
18676 && INTEGERP (glyph
->object
))
18681 while (glyph
<= start
18682 && glyph
->type
== CHAR_GLYPH
18683 && INTEGERP (glyph
->object
))
18687 /* If last glyph is a space or stretch, and it's trailing
18688 whitespace, set the face of all trailing whitespace glyphs in
18689 IT->glyph_row to `trailing-whitespace'. */
18690 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18691 && BUFFERP (glyph
->object
)
18692 && (glyph
->type
== STRETCH_GLYPH
18693 || (glyph
->type
== CHAR_GLYPH
18694 && glyph
->u
.ch
== ' '))
18695 && trailing_whitespace_p (glyph
->charpos
))
18697 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18701 if (!row
->reversed_p
)
18703 while (glyph
>= start
18704 && BUFFERP (glyph
->object
)
18705 && (glyph
->type
== STRETCH_GLYPH
18706 || (glyph
->type
== CHAR_GLYPH
18707 && glyph
->u
.ch
== ' ')))
18708 (glyph
--)->face_id
= face_id
;
18712 while (glyph
<= start
18713 && BUFFERP (glyph
->object
)
18714 && (glyph
->type
== STRETCH_GLYPH
18715 || (glyph
->type
== CHAR_GLYPH
18716 && glyph
->u
.ch
== ' ')))
18717 (glyph
++)->face_id
= face_id
;
18724 /* Value is non-zero if glyph row ROW should be
18725 used to hold the cursor. */
18728 cursor_row_p (struct glyph_row
*row
)
18732 if (PT
== CHARPOS (row
->end
.pos
)
18733 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18735 /* Suppose the row ends on a string.
18736 Unless the row is continued, that means it ends on a newline
18737 in the string. If it's anything other than a display string
18738 (e.g., a before-string from an overlay), we don't want the
18739 cursor there. (This heuristic seems to give the optimal
18740 behavior for the various types of multi-line strings.)
18741 One exception: if the string has `cursor' property on one of
18742 its characters, we _do_ want the cursor there. */
18743 if (CHARPOS (row
->end
.string_pos
) >= 0)
18745 if (row
->continued_p
)
18749 /* Check for `display' property. */
18750 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18751 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18752 struct glyph
*glyph
;
18755 for (glyph
= end
; glyph
>= beg
; --glyph
)
18756 if (STRINGP (glyph
->object
))
18759 = Fget_char_property (make_number (PT
),
18763 && display_prop_string_p (prop
, glyph
->object
));
18764 /* If there's a `cursor' property on one of the
18765 string's characters, this row is a cursor row,
18766 even though this is not a display string. */
18769 Lisp_Object s
= glyph
->object
;
18771 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18773 ptrdiff_t gpos
= glyph
->charpos
;
18775 if (!NILP (Fget_char_property (make_number (gpos
),
18787 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18789 /* If the row ends in middle of a real character,
18790 and the line is continued, we want the cursor here.
18791 That's because CHARPOS (ROW->end.pos) would equal
18792 PT if PT is before the character. */
18793 if (!row
->ends_in_ellipsis_p
)
18794 result
= row
->continued_p
;
18796 /* If the row ends in an ellipsis, then
18797 CHARPOS (ROW->end.pos) will equal point after the
18798 invisible text. We want that position to be displayed
18799 after the ellipsis. */
18802 /* If the row ends at ZV, display the cursor at the end of that
18803 row instead of at the start of the row below. */
18804 else if (row
->ends_at_zv_p
)
18815 /* Push the property PROP so that it will be rendered at the current
18816 position in IT. Return 1 if PROP was successfully pushed, 0
18817 otherwise. Called from handle_line_prefix to handle the
18818 `line-prefix' and `wrap-prefix' properties. */
18821 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18823 struct text_pos pos
=
18824 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18826 eassert (it
->method
== GET_FROM_BUFFER
18827 || it
->method
== GET_FROM_DISPLAY_VECTOR
18828 || it
->method
== GET_FROM_STRING
);
18830 /* We need to save the current buffer/string position, so it will be
18831 restored by pop_it, because iterate_out_of_display_property
18832 depends on that being set correctly, but some situations leave
18833 it->position not yet set when this function is called. */
18834 push_it (it
, &pos
);
18836 if (STRINGP (prop
))
18838 if (SCHARS (prop
) == 0)
18845 it
->string_from_prefix_prop_p
= 1;
18846 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18847 it
->current
.overlay_string_index
= -1;
18848 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18849 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18850 it
->method
= GET_FROM_STRING
;
18851 it
->stop_charpos
= 0;
18853 it
->base_level_stop
= 0;
18855 /* Force paragraph direction to be that of the parent
18857 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18858 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18860 it
->paragraph_embedding
= L2R
;
18862 /* Set up the bidi iterator for this display string. */
18865 it
->bidi_it
.string
.lstring
= it
->string
;
18866 it
->bidi_it
.string
.s
= NULL
;
18867 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18868 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18869 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18870 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18871 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18874 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18876 it
->method
= GET_FROM_STRETCH
;
18879 #ifdef HAVE_WINDOW_SYSTEM
18880 else if (IMAGEP (prop
))
18882 it
->what
= IT_IMAGE
;
18883 it
->image_id
= lookup_image (it
->f
, prop
);
18884 it
->method
= GET_FROM_IMAGE
;
18886 #endif /* HAVE_WINDOW_SYSTEM */
18889 pop_it (it
); /* bogus display property, give up */
18896 /* Return the character-property PROP at the current position in IT. */
18899 get_it_property (struct it
*it
, Lisp_Object prop
)
18901 Lisp_Object position
;
18903 if (STRINGP (it
->object
))
18904 position
= make_number (IT_STRING_CHARPOS (*it
));
18905 else if (BUFFERP (it
->object
))
18906 position
= make_number (IT_CHARPOS (*it
));
18910 return Fget_char_property (position
, prop
, it
->object
);
18913 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18916 handle_line_prefix (struct it
*it
)
18918 Lisp_Object prefix
;
18920 if (it
->continuation_lines_width
> 0)
18922 prefix
= get_it_property (it
, Qwrap_prefix
);
18924 prefix
= Vwrap_prefix
;
18928 prefix
= get_it_property (it
, Qline_prefix
);
18930 prefix
= Vline_prefix
;
18932 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18934 /* If the prefix is wider than the window, and we try to wrap
18935 it, it would acquire its own wrap prefix, and so on till the
18936 iterator stack overflows. So, don't wrap the prefix. */
18937 it
->line_wrap
= TRUNCATE
;
18938 it
->avoid_cursor_p
= 1;
18944 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18945 only for R2L lines from display_line and display_string, when they
18946 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18947 the line/string needs to be continued on the next glyph row. */
18949 unproduce_glyphs (struct it
*it
, int n
)
18951 struct glyph
*glyph
, *end
;
18953 eassert (it
->glyph_row
);
18954 eassert (it
->glyph_row
->reversed_p
);
18955 eassert (it
->area
== TEXT_AREA
);
18956 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18958 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18959 n
= it
->glyph_row
->used
[TEXT_AREA
];
18960 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18961 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18962 for ( ; glyph
< end
; glyph
++)
18963 glyph
[-n
] = *glyph
;
18966 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18967 and ROW->maxpos. */
18969 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18970 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18971 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18973 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18974 lines' rows is implemented for bidi-reordered rows. */
18976 /* ROW->minpos is the value of min_pos, the minimal buffer position
18977 we have in ROW, or ROW->start.pos if that is smaller. */
18978 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18979 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18981 /* We didn't find buffer positions smaller than ROW->start, or
18982 didn't find _any_ valid buffer positions in any of the glyphs,
18983 so we must trust the iterator's computed positions. */
18984 row
->minpos
= row
->start
.pos
;
18987 max_pos
= CHARPOS (it
->current
.pos
);
18988 max_bpos
= BYTEPOS (it
->current
.pos
);
18991 /* Here are the various use-cases for ending the row, and the
18992 corresponding values for ROW->maxpos:
18994 Line ends in a newline from buffer eol_pos + 1
18995 Line is continued from buffer max_pos + 1
18996 Line is truncated on right it->current.pos
18997 Line ends in a newline from string max_pos + 1(*)
18998 (*) + 1 only when line ends in a forward scan
18999 Line is continued from string max_pos
19000 Line is continued from display vector max_pos
19001 Line is entirely from a string min_pos == max_pos
19002 Line is entirely from a display vector min_pos == max_pos
19003 Line that ends at ZV ZV
19005 If you discover other use-cases, please add them here as
19007 if (row
->ends_at_zv_p
)
19008 row
->maxpos
= it
->current
.pos
;
19009 else if (row
->used
[TEXT_AREA
])
19011 int seen_this_string
= 0;
19012 struct glyph_row
*r1
= row
- 1;
19014 /* Did we see the same display string on the previous row? */
19015 if (STRINGP (it
->object
)
19016 /* this is not the first row */
19017 && row
> it
->w
->desired_matrix
->rows
19018 /* previous row is not the header line */
19019 && !r1
->mode_line_p
19020 /* previous row also ends in a newline from a string */
19021 && r1
->ends_in_newline_from_string_p
)
19023 struct glyph
*start
, *end
;
19025 /* Search for the last glyph of the previous row that came
19026 from buffer or string. Depending on whether the row is
19027 L2R or R2L, we need to process it front to back or the
19028 other way round. */
19029 if (!r1
->reversed_p
)
19031 start
= r1
->glyphs
[TEXT_AREA
];
19032 end
= start
+ r1
->used
[TEXT_AREA
];
19033 /* Glyphs inserted by redisplay have an integer (zero)
19034 as their object. */
19036 && INTEGERP ((end
- 1)->object
)
19037 && (end
- 1)->charpos
<= 0)
19041 if (EQ ((end
- 1)->object
, it
->object
))
19042 seen_this_string
= 1;
19045 /* If all the glyphs of the previous row were inserted
19046 by redisplay, it means the previous row was
19047 produced from a single newline, which is only
19048 possible if that newline came from the same string
19049 as the one which produced this ROW. */
19050 seen_this_string
= 1;
19054 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19055 start
= end
+ r1
->used
[TEXT_AREA
];
19057 && INTEGERP ((end
+ 1)->object
)
19058 && (end
+ 1)->charpos
<= 0)
19062 if (EQ ((end
+ 1)->object
, it
->object
))
19063 seen_this_string
= 1;
19066 seen_this_string
= 1;
19069 /* Take note of each display string that covers a newline only
19070 once, the first time we see it. This is for when a display
19071 string includes more than one newline in it. */
19072 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19074 /* If we were scanning the buffer forward when we displayed
19075 the string, we want to account for at least one buffer
19076 position that belongs to this row (position covered by
19077 the display string), so that cursor positioning will
19078 consider this row as a candidate when point is at the end
19079 of the visual line represented by this row. This is not
19080 required when scanning back, because max_pos will already
19081 have a much larger value. */
19082 if (CHARPOS (row
->end
.pos
) > max_pos
)
19083 INC_BOTH (max_pos
, max_bpos
);
19084 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19086 else if (CHARPOS (it
->eol_pos
) > 0)
19087 SET_TEXT_POS (row
->maxpos
,
19088 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19089 else if (row
->continued_p
)
19091 /* If max_pos is different from IT's current position, it
19092 means IT->method does not belong to the display element
19093 at max_pos. However, it also means that the display
19094 element at max_pos was displayed in its entirety on this
19095 line, which is equivalent to saying that the next line
19096 starts at the next buffer position. */
19097 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19098 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19101 INC_BOTH (max_pos
, max_bpos
);
19102 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19105 else if (row
->truncated_on_right_p
)
19106 /* display_line already called reseat_at_next_visible_line_start,
19107 which puts the iterator at the beginning of the next line, in
19108 the logical order. */
19109 row
->maxpos
= it
->current
.pos
;
19110 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19111 /* A line that is entirely from a string/image/stretch... */
19112 row
->maxpos
= row
->minpos
;
19117 row
->maxpos
= it
->current
.pos
;
19120 /* Construct the glyph row IT->glyph_row in the desired matrix of
19121 IT->w from text at the current position of IT. See dispextern.h
19122 for an overview of struct it. Value is non-zero if
19123 IT->glyph_row displays text, as opposed to a line displaying ZV
19127 display_line (struct it
*it
)
19129 struct glyph_row
*row
= it
->glyph_row
;
19130 Lisp_Object overlay_arrow_string
;
19132 void *wrap_data
= NULL
;
19133 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19134 int wrap_row_used
= -1;
19135 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19136 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19137 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19138 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19139 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19141 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19142 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19144 /* We always start displaying at hpos zero even if hscrolled. */
19145 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19147 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19148 >= it
->w
->desired_matrix
->nrows
)
19150 it
->w
->nrows_scale_factor
++;
19151 fonts_changed_p
= 1;
19155 /* Is IT->w showing the region? */
19156 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
19158 /* Clear the result glyph row and enable it. */
19159 prepare_desired_row (row
);
19161 row
->y
= it
->current_y
;
19162 row
->start
= it
->start
;
19163 row
->continuation_lines_width
= it
->continuation_lines_width
;
19164 row
->displays_text_p
= 1;
19165 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19166 it
->starts_in_middle_of_char_p
= 0;
19168 /* Arrange the overlays nicely for our purposes. Usually, we call
19169 display_line on only one line at a time, in which case this
19170 can't really hurt too much, or we call it on lines which appear
19171 one after another in the buffer, in which case all calls to
19172 recenter_overlay_lists but the first will be pretty cheap. */
19173 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19175 /* Move over display elements that are not visible because we are
19176 hscrolled. This may stop at an x-position < IT->first_visible_x
19177 if the first glyph is partially visible or if we hit a line end. */
19178 if (it
->current_x
< it
->first_visible_x
)
19180 enum move_it_result move_result
;
19182 this_line_min_pos
= row
->start
.pos
;
19183 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19184 MOVE_TO_POS
| MOVE_TO_X
);
19185 /* If we are under a large hscroll, move_it_in_display_line_to
19186 could hit the end of the line without reaching
19187 it->first_visible_x. Pretend that we did reach it. This is
19188 especially important on a TTY, where we will call
19189 extend_face_to_end_of_line, which needs to know how many
19190 blank glyphs to produce. */
19191 if (it
->current_x
< it
->first_visible_x
19192 && (move_result
== MOVE_NEWLINE_OR_CR
19193 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19194 it
->current_x
= it
->first_visible_x
;
19196 /* Record the smallest positions seen while we moved over
19197 display elements that are not visible. This is needed by
19198 redisplay_internal for optimizing the case where the cursor
19199 stays inside the same line. The rest of this function only
19200 considers positions that are actually displayed, so
19201 RECORD_MAX_MIN_POS will not otherwise record positions that
19202 are hscrolled to the left of the left edge of the window. */
19203 min_pos
= CHARPOS (this_line_min_pos
);
19204 min_bpos
= BYTEPOS (this_line_min_pos
);
19208 /* We only do this when not calling `move_it_in_display_line_to'
19209 above, because move_it_in_display_line_to calls
19210 handle_line_prefix itself. */
19211 handle_line_prefix (it
);
19214 /* Get the initial row height. This is either the height of the
19215 text hscrolled, if there is any, or zero. */
19216 row
->ascent
= it
->max_ascent
;
19217 row
->height
= it
->max_ascent
+ it
->max_descent
;
19218 row
->phys_ascent
= it
->max_phys_ascent
;
19219 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19220 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19222 /* Utility macro to record max and min buffer positions seen until now. */
19223 #define RECORD_MAX_MIN_POS(IT) \
19226 int composition_p = !STRINGP ((IT)->string) \
19227 && ((IT)->what == IT_COMPOSITION); \
19228 ptrdiff_t current_pos = \
19229 composition_p ? (IT)->cmp_it.charpos \
19230 : IT_CHARPOS (*(IT)); \
19231 ptrdiff_t current_bpos = \
19232 composition_p ? CHAR_TO_BYTE (current_pos) \
19233 : IT_BYTEPOS (*(IT)); \
19234 if (current_pos < min_pos) \
19236 min_pos = current_pos; \
19237 min_bpos = current_bpos; \
19239 if (IT_CHARPOS (*it) > max_pos) \
19241 max_pos = IT_CHARPOS (*it); \
19242 max_bpos = IT_BYTEPOS (*it); \
19247 /* Loop generating characters. The loop is left with IT on the next
19248 character to display. */
19251 int n_glyphs_before
, hpos_before
, x_before
;
19253 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19255 /* Retrieve the next thing to display. Value is zero if end of
19257 if (!get_next_display_element (it
))
19259 /* Maybe add a space at the end of this line that is used to
19260 display the cursor there under X. Set the charpos of the
19261 first glyph of blank lines not corresponding to any text
19263 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19264 row
->exact_window_width_line_p
= 1;
19265 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19266 || row
->used
[TEXT_AREA
] == 0)
19268 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19269 row
->displays_text_p
= 0;
19271 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19272 && (!MINI_WINDOW_P (it
->w
)
19273 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19274 row
->indicate_empty_line_p
= 1;
19277 it
->continuation_lines_width
= 0;
19278 row
->ends_at_zv_p
= 1;
19279 /* A row that displays right-to-left text must always have
19280 its last face extended all the way to the end of line,
19281 even if this row ends in ZV, because we still write to
19282 the screen left to right. We also need to extend the
19283 last face if the default face is remapped to some
19284 different face, otherwise the functions that clear
19285 portions of the screen will clear with the default face's
19286 background color. */
19287 if (row
->reversed_p
19288 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19289 extend_face_to_end_of_line (it
);
19293 /* Now, get the metrics of what we want to display. This also
19294 generates glyphs in `row' (which is IT->glyph_row). */
19295 n_glyphs_before
= row
->used
[TEXT_AREA
];
19298 /* Remember the line height so far in case the next element doesn't
19299 fit on the line. */
19300 if (it
->line_wrap
!= TRUNCATE
)
19302 ascent
= it
->max_ascent
;
19303 descent
= it
->max_descent
;
19304 phys_ascent
= it
->max_phys_ascent
;
19305 phys_descent
= it
->max_phys_descent
;
19307 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19309 if (IT_DISPLAYING_WHITESPACE (it
))
19313 SAVE_IT (wrap_it
, *it
, wrap_data
);
19315 wrap_row_used
= row
->used
[TEXT_AREA
];
19316 wrap_row_ascent
= row
->ascent
;
19317 wrap_row_height
= row
->height
;
19318 wrap_row_phys_ascent
= row
->phys_ascent
;
19319 wrap_row_phys_height
= row
->phys_height
;
19320 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19321 wrap_row_min_pos
= min_pos
;
19322 wrap_row_min_bpos
= min_bpos
;
19323 wrap_row_max_pos
= max_pos
;
19324 wrap_row_max_bpos
= max_bpos
;
19330 PRODUCE_GLYPHS (it
);
19332 /* If this display element was in marginal areas, continue with
19334 if (it
->area
!= TEXT_AREA
)
19336 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19337 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19338 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19339 row
->phys_height
= max (row
->phys_height
,
19340 it
->max_phys_ascent
+ it
->max_phys_descent
);
19341 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19342 it
->max_extra_line_spacing
);
19343 set_iterator_to_next (it
, 1);
19347 /* Does the display element fit on the line? If we truncate
19348 lines, we should draw past the right edge of the window. If
19349 we don't truncate, we want to stop so that we can display the
19350 continuation glyph before the right margin. If lines are
19351 continued, there are two possible strategies for characters
19352 resulting in more than 1 glyph (e.g. tabs): Display as many
19353 glyphs as possible in this line and leave the rest for the
19354 continuation line, or display the whole element in the next
19355 line. Original redisplay did the former, so we do it also. */
19356 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19357 hpos_before
= it
->hpos
;
19360 if (/* Not a newline. */
19362 /* Glyphs produced fit entirely in the line. */
19363 && it
->current_x
< it
->last_visible_x
)
19365 it
->hpos
+= nglyphs
;
19366 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19367 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19368 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19369 row
->phys_height
= max (row
->phys_height
,
19370 it
->max_phys_ascent
+ it
->max_phys_descent
);
19371 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19372 it
->max_extra_line_spacing
);
19373 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19374 row
->x
= x
- it
->first_visible_x
;
19375 /* Record the maximum and minimum buffer positions seen so
19376 far in glyphs that will be displayed by this row. */
19378 RECORD_MAX_MIN_POS (it
);
19383 struct glyph
*glyph
;
19385 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19387 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19388 new_x
= x
+ glyph
->pixel_width
;
19390 if (/* Lines are continued. */
19391 it
->line_wrap
!= TRUNCATE
19392 && (/* Glyph doesn't fit on the line. */
19393 new_x
> it
->last_visible_x
19394 /* Or it fits exactly on a window system frame. */
19395 || (new_x
== it
->last_visible_x
19396 && FRAME_WINDOW_P (it
->f
))))
19398 /* End of a continued line. */
19401 || (new_x
== it
->last_visible_x
19402 && FRAME_WINDOW_P (it
->f
)))
19404 /* Current glyph is the only one on the line or
19405 fits exactly on the line. We must continue
19406 the line because we can't draw the cursor
19407 after the glyph. */
19408 row
->continued_p
= 1;
19409 it
->current_x
= new_x
;
19410 it
->continuation_lines_width
+= new_x
;
19412 if (i
== nglyphs
- 1)
19414 /* If line-wrap is on, check if a previous
19415 wrap point was found. */
19416 if (wrap_row_used
> 0
19417 /* Even if there is a previous wrap
19418 point, continue the line here as
19419 usual, if (i) the previous character
19420 was a space or tab AND (ii) the
19421 current character is not. */
19423 || IT_DISPLAYING_WHITESPACE (it
)))
19426 /* Record the maximum and minimum buffer
19427 positions seen so far in glyphs that will be
19428 displayed by this row. */
19430 RECORD_MAX_MIN_POS (it
);
19431 set_iterator_to_next (it
, 1);
19432 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19434 if (!get_next_display_element (it
))
19436 row
->exact_window_width_line_p
= 1;
19437 it
->continuation_lines_width
= 0;
19438 row
->continued_p
= 0;
19439 row
->ends_at_zv_p
= 1;
19441 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19443 row
->continued_p
= 0;
19444 row
->exact_window_width_line_p
= 1;
19448 else if (it
->bidi_p
)
19449 RECORD_MAX_MIN_POS (it
);
19451 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19452 && !FRAME_WINDOW_P (it
->f
))
19454 /* A padding glyph that doesn't fit on this line.
19455 This means the whole character doesn't fit
19457 if (row
->reversed_p
)
19458 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19459 - n_glyphs_before
);
19460 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19462 /* Fill the rest of the row with continuation
19463 glyphs like in 20.x. */
19464 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19465 < row
->glyphs
[1 + TEXT_AREA
])
19466 produce_special_glyphs (it
, IT_CONTINUATION
);
19468 row
->continued_p
= 1;
19469 it
->current_x
= x_before
;
19470 it
->continuation_lines_width
+= x_before
;
19472 /* Restore the height to what it was before the
19473 element not fitting on the line. */
19474 it
->max_ascent
= ascent
;
19475 it
->max_descent
= descent
;
19476 it
->max_phys_ascent
= phys_ascent
;
19477 it
->max_phys_descent
= phys_descent
;
19479 else if (wrap_row_used
> 0)
19482 if (row
->reversed_p
)
19483 unproduce_glyphs (it
,
19484 row
->used
[TEXT_AREA
] - wrap_row_used
);
19485 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19486 it
->continuation_lines_width
+= wrap_x
;
19487 row
->used
[TEXT_AREA
] = wrap_row_used
;
19488 row
->ascent
= wrap_row_ascent
;
19489 row
->height
= wrap_row_height
;
19490 row
->phys_ascent
= wrap_row_phys_ascent
;
19491 row
->phys_height
= wrap_row_phys_height
;
19492 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19493 min_pos
= wrap_row_min_pos
;
19494 min_bpos
= wrap_row_min_bpos
;
19495 max_pos
= wrap_row_max_pos
;
19496 max_bpos
= wrap_row_max_bpos
;
19497 row
->continued_p
= 1;
19498 row
->ends_at_zv_p
= 0;
19499 row
->exact_window_width_line_p
= 0;
19500 it
->continuation_lines_width
+= x
;
19502 /* Make sure that a non-default face is extended
19503 up to the right margin of the window. */
19504 extend_face_to_end_of_line (it
);
19506 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19508 /* A TAB that extends past the right edge of the
19509 window. This produces a single glyph on
19510 window system frames. We leave the glyph in
19511 this row and let it fill the row, but don't
19512 consume the TAB. */
19513 it
->continuation_lines_width
+= it
->last_visible_x
;
19514 row
->ends_in_middle_of_char_p
= 1;
19515 row
->continued_p
= 1;
19516 glyph
->pixel_width
= it
->last_visible_x
- x
;
19517 it
->starts_in_middle_of_char_p
= 1;
19521 /* Something other than a TAB that draws past
19522 the right edge of the window. Restore
19523 positions to values before the element. */
19524 if (row
->reversed_p
)
19525 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19526 - (n_glyphs_before
+ i
));
19527 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19529 /* Display continuation glyphs. */
19530 if (!FRAME_WINDOW_P (it
->f
))
19531 produce_special_glyphs (it
, IT_CONTINUATION
);
19532 row
->continued_p
= 1;
19534 it
->current_x
= x_before
;
19535 it
->continuation_lines_width
+= x
;
19536 extend_face_to_end_of_line (it
);
19538 if (nglyphs
> 1 && i
> 0)
19540 row
->ends_in_middle_of_char_p
= 1;
19541 it
->starts_in_middle_of_char_p
= 1;
19544 /* Restore the height to what it was before the
19545 element not fitting on the line. */
19546 it
->max_ascent
= ascent
;
19547 it
->max_descent
= descent
;
19548 it
->max_phys_ascent
= phys_ascent
;
19549 it
->max_phys_descent
= phys_descent
;
19554 else if (new_x
> it
->first_visible_x
)
19556 /* Increment number of glyphs actually displayed. */
19559 /* Record the maximum and minimum buffer positions
19560 seen so far in glyphs that will be displayed by
19563 RECORD_MAX_MIN_POS (it
);
19565 if (x
< it
->first_visible_x
)
19566 /* Glyph is partially visible, i.e. row starts at
19567 negative X position. */
19568 row
->x
= x
- it
->first_visible_x
;
19572 /* Glyph is completely off the left margin of the
19573 window. This should not happen because of the
19574 move_it_in_display_line at the start of this
19575 function, unless the text display area of the
19576 window is empty. */
19577 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19580 /* Even if this display element produced no glyphs at all,
19581 we want to record its position. */
19582 if (it
->bidi_p
&& nglyphs
== 0)
19583 RECORD_MAX_MIN_POS (it
);
19585 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19586 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19587 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19588 row
->phys_height
= max (row
->phys_height
,
19589 it
->max_phys_ascent
+ it
->max_phys_descent
);
19590 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19591 it
->max_extra_line_spacing
);
19593 /* End of this display line if row is continued. */
19594 if (row
->continued_p
|| row
->ends_at_zv_p
)
19599 /* Is this a line end? If yes, we're also done, after making
19600 sure that a non-default face is extended up to the right
19601 margin of the window. */
19602 if (ITERATOR_AT_END_OF_LINE_P (it
))
19604 int used_before
= row
->used
[TEXT_AREA
];
19606 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19608 /* Add a space at the end of the line that is used to
19609 display the cursor there. */
19610 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19611 append_space_for_newline (it
, 0);
19613 /* Extend the face to the end of the line. */
19614 extend_face_to_end_of_line (it
);
19616 /* Make sure we have the position. */
19617 if (used_before
== 0)
19618 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19620 /* Record the position of the newline, for use in
19622 it
->eol_pos
= it
->current
.pos
;
19624 /* Consume the line end. This skips over invisible lines. */
19625 set_iterator_to_next (it
, 1);
19626 it
->continuation_lines_width
= 0;
19630 /* Proceed with next display element. Note that this skips
19631 over lines invisible because of selective display. */
19632 set_iterator_to_next (it
, 1);
19634 /* If we truncate lines, we are done when the last displayed
19635 glyphs reach past the right margin of the window. */
19636 if (it
->line_wrap
== TRUNCATE
19637 && (FRAME_WINDOW_P (it
->f
)
19638 ? (it
->current_x
>= it
->last_visible_x
)
19639 : (it
->current_x
> it
->last_visible_x
)))
19641 /* Maybe add truncation glyphs. */
19642 if (!FRAME_WINDOW_P (it
->f
))
19646 if (!row
->reversed_p
)
19648 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19649 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19654 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19655 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19657 /* Remove any padding glyphs at the front of ROW, to
19658 make room for the truncation glyphs we will be
19659 adding below. The loop below always inserts at
19660 least one truncation glyph, so also remove the
19661 last glyph added to ROW. */
19662 unproduce_glyphs (it
, i
+ 1);
19663 /* Adjust i for the loop below. */
19664 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19667 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19669 row
->used
[TEXT_AREA
] = i
;
19670 produce_special_glyphs (it
, IT_TRUNCATION
);
19673 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19675 /* Don't truncate if we can overflow newline into fringe. */
19676 if (!get_next_display_element (it
))
19678 it
->continuation_lines_width
= 0;
19679 row
->ends_at_zv_p
= 1;
19680 row
->exact_window_width_line_p
= 1;
19683 if (ITERATOR_AT_END_OF_LINE_P (it
))
19685 row
->exact_window_width_line_p
= 1;
19686 goto at_end_of_line
;
19690 row
->truncated_on_right_p
= 1;
19691 it
->continuation_lines_width
= 0;
19692 reseat_at_next_visible_line_start (it
, 0);
19693 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19694 it
->hpos
= hpos_before
;
19695 it
->current_x
= x_before
;
19701 bidi_unshelve_cache (wrap_data
, 1);
19703 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19704 at the left window margin. */
19705 if (it
->first_visible_x
19706 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19708 if (!FRAME_WINDOW_P (it
->f
))
19709 insert_left_trunc_glyphs (it
);
19710 row
->truncated_on_left_p
= 1;
19713 /* Remember the position at which this line ends.
19715 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19716 cannot be before the call to find_row_edges below, since that is
19717 where these positions are determined. */
19718 row
->end
= it
->current
;
19721 row
->minpos
= row
->start
.pos
;
19722 row
->maxpos
= row
->end
.pos
;
19726 /* ROW->minpos and ROW->maxpos must be the smallest and
19727 `1 + the largest' buffer positions in ROW. But if ROW was
19728 bidi-reordered, these two positions can be anywhere in the
19729 row, so we must determine them now. */
19730 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19733 /* If the start of this line is the overlay arrow-position, then
19734 mark this glyph row as the one containing the overlay arrow.
19735 This is clearly a mess with variable size fonts. It would be
19736 better to let it be displayed like cursors under X. */
19737 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19738 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19739 !NILP (overlay_arrow_string
)))
19741 /* Overlay arrow in window redisplay is a fringe bitmap. */
19742 if (STRINGP (overlay_arrow_string
))
19744 struct glyph_row
*arrow_row
19745 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19746 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19747 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19748 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19749 struct glyph
*p2
, *end
;
19751 /* Copy the arrow glyphs. */
19752 while (glyph
< arrow_end
)
19755 /* Throw away padding glyphs. */
19757 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19758 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19764 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19769 eassert (INTEGERP (overlay_arrow_string
));
19770 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19772 overlay_arrow_seen
= 1;
19775 /* Highlight trailing whitespace. */
19776 if (!NILP (Vshow_trailing_whitespace
))
19777 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19779 /* Compute pixel dimensions of this line. */
19780 compute_line_metrics (it
);
19782 /* Implementation note: No changes in the glyphs of ROW or in their
19783 faces can be done past this point, because compute_line_metrics
19784 computes ROW's hash value and stores it within the glyph_row
19787 /* Record whether this row ends inside an ellipsis. */
19788 row
->ends_in_ellipsis_p
19789 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19790 && it
->ellipsis_p
);
19792 /* Save fringe bitmaps in this row. */
19793 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19794 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19795 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19796 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19798 it
->left_user_fringe_bitmap
= 0;
19799 it
->left_user_fringe_face_id
= 0;
19800 it
->right_user_fringe_bitmap
= 0;
19801 it
->right_user_fringe_face_id
= 0;
19803 /* Maybe set the cursor. */
19804 cvpos
= it
->w
->cursor
.vpos
;
19806 /* In bidi-reordered rows, keep checking for proper cursor
19807 position even if one has been found already, because buffer
19808 positions in such rows change non-linearly with ROW->VPOS,
19809 when a line is continued. One exception: when we are at ZV,
19810 display cursor on the first suitable glyph row, since all
19811 the empty rows after that also have their position set to ZV. */
19812 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19813 lines' rows is implemented for bidi-reordered rows. */
19815 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19816 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19817 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19818 && cursor_row_p (row
))
19819 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19821 /* Prepare for the next line. This line starts horizontally at (X
19822 HPOS) = (0 0). Vertical positions are incremented. As a
19823 convenience for the caller, IT->glyph_row is set to the next
19825 it
->current_x
= it
->hpos
= 0;
19826 it
->current_y
+= row
->height
;
19827 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19830 /* The next row should by default use the same value of the
19831 reversed_p flag as this one. set_iterator_to_next decides when
19832 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19833 the flag accordingly. */
19834 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19835 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19836 it
->start
= row
->end
;
19837 return row
->displays_text_p
;
19839 #undef RECORD_MAX_MIN_POS
19842 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19843 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19844 doc
: /* Return paragraph direction at point in BUFFER.
19845 Value is either `left-to-right' or `right-to-left'.
19846 If BUFFER is omitted or nil, it defaults to the current buffer.
19848 Paragraph direction determines how the text in the paragraph is displayed.
19849 In left-to-right paragraphs, text begins at the left margin of the window
19850 and the reading direction is generally left to right. In right-to-left
19851 paragraphs, text begins at the right margin and is read from right to left.
19853 See also `bidi-paragraph-direction'. */)
19854 (Lisp_Object buffer
)
19856 struct buffer
*buf
= current_buffer
;
19857 struct buffer
*old
= buf
;
19859 if (! NILP (buffer
))
19861 CHECK_BUFFER (buffer
);
19862 buf
= XBUFFER (buffer
);
19865 if (NILP (BVAR (buf
, bidi_display_reordering
))
19866 || NILP (BVAR (buf
, enable_multibyte_characters
))
19867 /* When we are loading loadup.el, the character property tables
19868 needed for bidi iteration are not yet available. */
19869 || !NILP (Vpurify_flag
))
19870 return Qleft_to_right
;
19871 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19872 return BVAR (buf
, bidi_paragraph_direction
);
19875 /* Determine the direction from buffer text. We could try to
19876 use current_matrix if it is up to date, but this seems fast
19877 enough as it is. */
19878 struct bidi_it itb
;
19879 ptrdiff_t pos
= BUF_PT (buf
);
19880 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19882 void *itb_data
= bidi_shelve_cache ();
19884 set_buffer_temp (buf
);
19885 /* bidi_paragraph_init finds the base direction of the paragraph
19886 by searching forward from paragraph start. We need the base
19887 direction of the current or _previous_ paragraph, so we need
19888 to make sure we are within that paragraph. To that end, find
19889 the previous non-empty line. */
19890 if (pos
>= ZV
&& pos
> BEGV
)
19893 bytepos
= CHAR_TO_BYTE (pos
);
19895 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19896 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19898 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19899 || c
== ' ' || c
== '\t' || c
== '\f')
19901 if (bytepos
<= BEGV_BYTE
)
19906 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19909 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19910 itb
.paragraph_dir
= NEUTRAL_DIR
;
19911 itb
.string
.s
= NULL
;
19912 itb
.string
.lstring
= Qnil
;
19913 itb
.string
.bufpos
= 0;
19914 itb
.string
.unibyte
= 0;
19915 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19916 bidi_unshelve_cache (itb_data
, 0);
19917 set_buffer_temp (old
);
19918 switch (itb
.paragraph_dir
)
19921 return Qleft_to_right
;
19924 return Qright_to_left
;
19934 /***********************************************************************
19936 ***********************************************************************/
19938 /* Redisplay the menu bar in the frame for window W.
19940 The menu bar of X frames that don't have X toolkit support is
19941 displayed in a special window W->frame->menu_bar_window.
19943 The menu bar of terminal frames is treated specially as far as
19944 glyph matrices are concerned. Menu bar lines are not part of
19945 windows, so the update is done directly on the frame matrix rows
19946 for the menu bar. */
19949 display_menu_bar (struct window
*w
)
19951 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19956 /* Don't do all this for graphical frames. */
19958 if (FRAME_W32_P (f
))
19961 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19967 if (FRAME_NS_P (f
))
19969 #endif /* HAVE_NS */
19971 #ifdef USE_X_TOOLKIT
19972 eassert (!FRAME_WINDOW_P (f
));
19973 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19974 it
.first_visible_x
= 0;
19975 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19976 #else /* not USE_X_TOOLKIT */
19977 if (FRAME_WINDOW_P (f
))
19979 /* Menu bar lines are displayed in the desired matrix of the
19980 dummy window menu_bar_window. */
19981 struct window
*menu_w
;
19982 eassert (WINDOWP (f
->menu_bar_window
));
19983 menu_w
= XWINDOW (f
->menu_bar_window
);
19984 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19986 it
.first_visible_x
= 0;
19987 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19991 /* This is a TTY frame, i.e. character hpos/vpos are used as
19993 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19995 it
.first_visible_x
= 0;
19996 it
.last_visible_x
= FRAME_COLS (f
);
19998 #endif /* not USE_X_TOOLKIT */
20000 /* FIXME: This should be controlled by a user option. See the
20001 comments in redisplay_tool_bar and display_mode_line about
20003 it
.paragraph_embedding
= L2R
;
20005 if (! mode_line_inverse_video
)
20006 /* Force the menu-bar to be displayed in the default face. */
20007 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20009 /* Clear all rows of the menu bar. */
20010 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20012 struct glyph_row
*row
= it
.glyph_row
+ i
;
20013 clear_glyph_row (row
);
20014 row
->enabled_p
= 1;
20015 row
->full_width_p
= 1;
20018 /* Display all items of the menu bar. */
20019 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20020 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20022 Lisp_Object string
;
20024 /* Stop at nil string. */
20025 string
= AREF (items
, i
+ 1);
20029 /* Remember where item was displayed. */
20030 ASET (items
, i
+ 3, make_number (it
.hpos
));
20032 /* Display the item, pad with one space. */
20033 if (it
.current_x
< it
.last_visible_x
)
20034 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20035 SCHARS (string
) + 1, 0, 0, -1);
20038 /* Fill out the line with spaces. */
20039 if (it
.current_x
< it
.last_visible_x
)
20040 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20042 /* Compute the total height of the lines. */
20043 compute_line_metrics (&it
);
20048 /***********************************************************************
20050 ***********************************************************************/
20052 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20053 FORCE is non-zero, redisplay mode lines unconditionally.
20054 Otherwise, redisplay only mode lines that are garbaged. Value is
20055 the number of windows whose mode lines were redisplayed. */
20058 redisplay_mode_lines (Lisp_Object window
, int force
)
20062 while (!NILP (window
))
20064 struct window
*w
= XWINDOW (window
);
20066 if (WINDOWP (w
->hchild
))
20067 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20068 else if (WINDOWP (w
->vchild
))
20069 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20071 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20072 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20074 struct text_pos lpoint
;
20075 struct buffer
*old
= current_buffer
;
20077 /* Set the window's buffer for the mode line display. */
20078 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20079 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20081 /* Point refers normally to the selected window. For any
20082 other window, set up appropriate value. */
20083 if (!EQ (window
, selected_window
))
20085 struct text_pos pt
;
20087 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20088 if (CHARPOS (pt
) < BEGV
)
20089 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20090 else if (CHARPOS (pt
) > (ZV
- 1))
20091 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20093 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20096 /* Display mode lines. */
20097 clear_glyph_matrix (w
->desired_matrix
);
20098 if (display_mode_lines (w
))
20101 w
->must_be_updated_p
= 1;
20104 /* Restore old settings. */
20105 set_buffer_internal_1 (old
);
20106 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20116 /* Display the mode and/or header line of window W. Value is the
20117 sum number of mode lines and header lines displayed. */
20120 display_mode_lines (struct window
*w
)
20122 Lisp_Object old_selected_window
, old_selected_frame
;
20125 old_selected_frame
= selected_frame
;
20126 selected_frame
= w
->frame
;
20127 old_selected_window
= selected_window
;
20128 XSETWINDOW (selected_window
, w
);
20130 /* These will be set while the mode line specs are processed. */
20131 line_number_displayed
= 0;
20132 w
->column_number_displayed
= Qnil
;
20134 if (WINDOW_WANTS_MODELINE_P (w
))
20136 struct window
*sel_w
= XWINDOW (old_selected_window
);
20138 /* Select mode line face based on the real selected window. */
20139 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20140 BVAR (current_buffer
, mode_line_format
));
20144 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20146 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20147 BVAR (current_buffer
, header_line_format
));
20151 selected_frame
= old_selected_frame
;
20152 selected_window
= old_selected_window
;
20157 /* Display mode or header line of window W. FACE_ID specifies which
20158 line to display; it is either MODE_LINE_FACE_ID or
20159 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20160 display. Value is the pixel height of the mode/header line
20164 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20168 ptrdiff_t count
= SPECPDL_INDEX ();
20170 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20171 /* Don't extend on a previously drawn mode-line.
20172 This may happen if called from pos_visible_p. */
20173 it
.glyph_row
->enabled_p
= 0;
20174 prepare_desired_row (it
.glyph_row
);
20176 it
.glyph_row
->mode_line_p
= 1;
20178 if (! mode_line_inverse_video
)
20179 /* Force the mode-line to be displayed in the default face. */
20180 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20182 /* FIXME: This should be controlled by a user option. But
20183 supporting such an option is not trivial, since the mode line is
20184 made up of many separate strings. */
20185 it
.paragraph_embedding
= L2R
;
20187 record_unwind_protect (unwind_format_mode_line
,
20188 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20190 mode_line_target
= MODE_LINE_DISPLAY
;
20192 /* Temporarily make frame's keyboard the current kboard so that
20193 kboard-local variables in the mode_line_format will get the right
20195 push_kboard (FRAME_KBOARD (it
.f
));
20196 record_unwind_save_match_data ();
20197 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20200 unbind_to (count
, Qnil
);
20202 /* Fill up with spaces. */
20203 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20205 compute_line_metrics (&it
);
20206 it
.glyph_row
->full_width_p
= 1;
20207 it
.glyph_row
->continued_p
= 0;
20208 it
.glyph_row
->truncated_on_left_p
= 0;
20209 it
.glyph_row
->truncated_on_right_p
= 0;
20211 /* Make a 3D mode-line have a shadow at its right end. */
20212 face
= FACE_FROM_ID (it
.f
, face_id
);
20213 extend_face_to_end_of_line (&it
);
20214 if (face
->box
!= FACE_NO_BOX
)
20216 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20217 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20218 last
->right_box_line_p
= 1;
20221 return it
.glyph_row
->height
;
20224 /* Move element ELT in LIST to the front of LIST.
20225 Return the updated list. */
20228 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20230 register Lisp_Object tail
, prev
;
20231 register Lisp_Object tem
;
20235 while (CONSP (tail
))
20241 /* Splice out the link TAIL. */
20243 list
= XCDR (tail
);
20245 Fsetcdr (prev
, XCDR (tail
));
20247 /* Now make it the first. */
20248 Fsetcdr (tail
, list
);
20253 tail
= XCDR (tail
);
20257 /* Not found--return unchanged LIST. */
20261 /* Contribute ELT to the mode line for window IT->w. How it
20262 translates into text depends on its data type.
20264 IT describes the display environment in which we display, as usual.
20266 DEPTH is the depth in recursion. It is used to prevent
20267 infinite recursion here.
20269 FIELD_WIDTH is the number of characters the display of ELT should
20270 occupy in the mode line, and PRECISION is the maximum number of
20271 characters to display from ELT's representation. See
20272 display_string for details.
20274 Returns the hpos of the end of the text generated by ELT.
20276 PROPS is a property list to add to any string we encounter.
20278 If RISKY is nonzero, remove (disregard) any properties in any string
20279 we encounter, and ignore :eval and :propertize.
20281 The global variable `mode_line_target' determines whether the
20282 output is passed to `store_mode_line_noprop',
20283 `store_mode_line_string', or `display_string'. */
20286 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20287 Lisp_Object elt
, Lisp_Object props
, int risky
)
20289 int n
= 0, field
, prec
;
20294 elt
= build_string ("*too-deep*");
20298 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
20302 /* A string: output it and check for %-constructs within it. */
20304 ptrdiff_t offset
= 0;
20306 if (SCHARS (elt
) > 0
20307 && (!NILP (props
) || risky
))
20309 Lisp_Object oprops
, aelt
;
20310 oprops
= Ftext_properties_at (make_number (0), elt
);
20312 /* If the starting string's properties are not what
20313 we want, translate the string. Also, if the string
20314 is risky, do that anyway. */
20316 if (NILP (Fequal (props
, oprops
)) || risky
)
20318 /* If the starting string has properties,
20319 merge the specified ones onto the existing ones. */
20320 if (! NILP (oprops
) && !risky
)
20324 oprops
= Fcopy_sequence (oprops
);
20326 while (CONSP (tem
))
20328 oprops
= Fplist_put (oprops
, XCAR (tem
),
20329 XCAR (XCDR (tem
)));
20330 tem
= XCDR (XCDR (tem
));
20335 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20336 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20338 /* AELT is what we want. Move it to the front
20339 without consing. */
20341 mode_line_proptrans_alist
20342 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20348 /* If AELT has the wrong props, it is useless.
20349 so get rid of it. */
20351 mode_line_proptrans_alist
20352 = Fdelq (aelt
, mode_line_proptrans_alist
);
20354 elt
= Fcopy_sequence (elt
);
20355 Fset_text_properties (make_number (0), Flength (elt
),
20357 /* Add this item to mode_line_proptrans_alist. */
20358 mode_line_proptrans_alist
20359 = Fcons (Fcons (elt
, props
),
20360 mode_line_proptrans_alist
);
20361 /* Truncate mode_line_proptrans_alist
20362 to at most 50 elements. */
20363 tem
= Fnthcdr (make_number (50),
20364 mode_line_proptrans_alist
);
20366 XSETCDR (tem
, Qnil
);
20375 prec
= precision
- n
;
20376 switch (mode_line_target
)
20378 case MODE_LINE_NOPROP
:
20379 case MODE_LINE_TITLE
:
20380 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20382 case MODE_LINE_STRING
:
20383 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20385 case MODE_LINE_DISPLAY
:
20386 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20387 0, prec
, 0, STRING_MULTIBYTE (elt
));
20394 /* Handle the non-literal case. */
20396 while ((precision
<= 0 || n
< precision
)
20397 && SREF (elt
, offset
) != 0
20398 && (mode_line_target
!= MODE_LINE_DISPLAY
20399 || it
->current_x
< it
->last_visible_x
))
20401 ptrdiff_t last_offset
= offset
;
20403 /* Advance to end of string or next format specifier. */
20404 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20407 if (offset
- 1 != last_offset
)
20409 ptrdiff_t nchars
, nbytes
;
20411 /* Output to end of string or up to '%'. Field width
20412 is length of string. Don't output more than
20413 PRECISION allows us. */
20416 prec
= c_string_width (SDATA (elt
) + last_offset
,
20417 offset
- last_offset
, precision
- n
,
20420 switch (mode_line_target
)
20422 case MODE_LINE_NOPROP
:
20423 case MODE_LINE_TITLE
:
20424 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20426 case MODE_LINE_STRING
:
20428 ptrdiff_t bytepos
= last_offset
;
20429 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20430 ptrdiff_t endpos
= (precision
<= 0
20431 ? string_byte_to_char (elt
, offset
)
20432 : charpos
+ nchars
);
20434 n
+= store_mode_line_string (NULL
,
20435 Fsubstring (elt
, make_number (charpos
),
20436 make_number (endpos
)),
20440 case MODE_LINE_DISPLAY
:
20442 ptrdiff_t bytepos
= last_offset
;
20443 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20445 if (precision
<= 0)
20446 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20447 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20449 STRING_MULTIBYTE (elt
));
20454 else /* c == '%' */
20456 ptrdiff_t percent_position
= offset
;
20458 /* Get the specified minimum width. Zero means
20461 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20462 field
= field
* 10 + c
- '0';
20464 /* Don't pad beyond the total padding allowed. */
20465 if (field_width
- n
> 0 && field
> field_width
- n
)
20466 field
= field_width
- n
;
20468 /* Note that either PRECISION <= 0 or N < PRECISION. */
20469 prec
= precision
- n
;
20472 n
+= display_mode_element (it
, depth
, field
, prec
,
20473 Vglobal_mode_string
, props
,
20478 ptrdiff_t bytepos
, charpos
;
20480 Lisp_Object string
;
20482 bytepos
= percent_position
;
20483 charpos
= (STRING_MULTIBYTE (elt
)
20484 ? string_byte_to_char (elt
, bytepos
)
20486 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20487 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20489 switch (mode_line_target
)
20491 case MODE_LINE_NOPROP
:
20492 case MODE_LINE_TITLE
:
20493 n
+= store_mode_line_noprop (spec
, field
, prec
);
20495 case MODE_LINE_STRING
:
20497 Lisp_Object tem
= build_string (spec
);
20498 props
= Ftext_properties_at (make_number (charpos
), elt
);
20499 /* Should only keep face property in props */
20500 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20503 case MODE_LINE_DISPLAY
:
20505 int nglyphs_before
, nwritten
;
20507 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20508 nwritten
= display_string (spec
, string
, elt
,
20513 /* Assign to the glyphs written above the
20514 string where the `%x' came from, position
20518 struct glyph
*glyph
20519 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20523 for (i
= 0; i
< nwritten
; ++i
)
20525 glyph
[i
].object
= elt
;
20526 glyph
[i
].charpos
= charpos
;
20543 /* A symbol: process the value of the symbol recursively
20544 as if it appeared here directly. Avoid error if symbol void.
20545 Special case: if value of symbol is a string, output the string
20548 register Lisp_Object tem
;
20550 /* If the variable is not marked as risky to set
20551 then its contents are risky to use. */
20552 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20555 tem
= Fboundp (elt
);
20558 tem
= Fsymbol_value (elt
);
20559 /* If value is a string, output that string literally:
20560 don't check for % within it. */
20564 if (!EQ (tem
, elt
))
20566 /* Give up right away for nil or t. */
20576 register Lisp_Object car
, tem
;
20578 /* A cons cell: five distinct cases.
20579 If first element is :eval or :propertize, do something special.
20580 If first element is a string or a cons, process all the elements
20581 and effectively concatenate them.
20582 If first element is a negative number, truncate displaying cdr to
20583 at most that many characters. If positive, pad (with spaces)
20584 to at least that many characters.
20585 If first element is a symbol, process the cadr or caddr recursively
20586 according to whether the symbol's value is non-nil or nil. */
20588 if (EQ (car
, QCeval
))
20590 /* An element of the form (:eval FORM) means evaluate FORM
20591 and use the result as mode line elements. */
20596 if (CONSP (XCDR (elt
)))
20599 spec
= safe_eval (XCAR (XCDR (elt
)));
20600 n
+= display_mode_element (it
, depth
, field_width
- n
,
20601 precision
- n
, spec
, props
,
20605 else if (EQ (car
, QCpropertize
))
20607 /* An element of the form (:propertize ELT PROPS...)
20608 means display ELT but applying properties PROPS. */
20613 if (CONSP (XCDR (elt
)))
20614 n
+= display_mode_element (it
, depth
, field_width
- n
,
20615 precision
- n
, XCAR (XCDR (elt
)),
20616 XCDR (XCDR (elt
)), risky
);
20618 else if (SYMBOLP (car
))
20620 tem
= Fboundp (car
);
20624 /* elt is now the cdr, and we know it is a cons cell.
20625 Use its car if CAR has a non-nil value. */
20628 tem
= Fsymbol_value (car
);
20635 /* Symbol's value is nil (or symbol is unbound)
20636 Get the cddr of the original list
20637 and if possible find the caddr and use that. */
20641 else if (!CONSP (elt
))
20646 else if (INTEGERP (car
))
20648 register int lim
= XINT (car
);
20652 /* Negative int means reduce maximum width. */
20653 if (precision
<= 0)
20656 precision
= min (precision
, -lim
);
20660 /* Padding specified. Don't let it be more than
20661 current maximum. */
20663 lim
= min (precision
, lim
);
20665 /* If that's more padding than already wanted, queue it.
20666 But don't reduce padding already specified even if
20667 that is beyond the current truncation point. */
20668 field_width
= max (lim
, field_width
);
20672 else if (STRINGP (car
) || CONSP (car
))
20674 Lisp_Object halftail
= elt
;
20678 && (precision
<= 0 || n
< precision
))
20680 n
+= display_mode_element (it
, depth
,
20681 /* Do padding only after the last
20682 element in the list. */
20683 (! CONSP (XCDR (elt
))
20686 precision
- n
, XCAR (elt
),
20690 if ((len
& 1) == 0)
20691 halftail
= XCDR (halftail
);
20692 /* Check for cycle. */
20693 if (EQ (halftail
, elt
))
20702 elt
= build_string ("*invalid*");
20706 /* Pad to FIELD_WIDTH. */
20707 if (field_width
> 0 && n
< field_width
)
20709 switch (mode_line_target
)
20711 case MODE_LINE_NOPROP
:
20712 case MODE_LINE_TITLE
:
20713 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20715 case MODE_LINE_STRING
:
20716 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20718 case MODE_LINE_DISPLAY
:
20719 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20728 /* Store a mode-line string element in mode_line_string_list.
20730 If STRING is non-null, display that C string. Otherwise, the Lisp
20731 string LISP_STRING is displayed.
20733 FIELD_WIDTH is the minimum number of output glyphs to produce.
20734 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20735 with spaces. FIELD_WIDTH <= 0 means don't pad.
20737 PRECISION is the maximum number of characters to output from
20738 STRING. PRECISION <= 0 means don't truncate the string.
20740 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20741 properties to the string.
20743 PROPS are the properties to add to the string.
20744 The mode_line_string_face face property is always added to the string.
20748 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20749 int field_width
, int precision
, Lisp_Object props
)
20754 if (string
!= NULL
)
20756 len
= strlen (string
);
20757 if (precision
> 0 && len
> precision
)
20759 lisp_string
= make_string (string
, len
);
20761 props
= mode_line_string_face_prop
;
20762 else if (!NILP (mode_line_string_face
))
20764 Lisp_Object face
= Fplist_get (props
, Qface
);
20765 props
= Fcopy_sequence (props
);
20767 face
= mode_line_string_face
;
20769 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20770 props
= Fplist_put (props
, Qface
, face
);
20772 Fadd_text_properties (make_number (0), make_number (len
),
20773 props
, lisp_string
);
20777 len
= XFASTINT (Flength (lisp_string
));
20778 if (precision
> 0 && len
> precision
)
20781 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20784 if (!NILP (mode_line_string_face
))
20788 props
= Ftext_properties_at (make_number (0), lisp_string
);
20789 face
= Fplist_get (props
, Qface
);
20791 face
= mode_line_string_face
;
20793 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20794 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20796 lisp_string
= Fcopy_sequence (lisp_string
);
20799 Fadd_text_properties (make_number (0), make_number (len
),
20800 props
, lisp_string
);
20805 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20809 if (field_width
> len
)
20811 field_width
-= len
;
20812 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20814 Fadd_text_properties (make_number (0), make_number (field_width
),
20815 props
, lisp_string
);
20816 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20824 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20826 doc
: /* Format a string out of a mode line format specification.
20827 First arg FORMAT specifies the mode line format (see `mode-line-format'
20828 for details) to use.
20830 By default, the format is evaluated for the currently selected window.
20832 Optional second arg FACE specifies the face property to put on all
20833 characters for which no face is specified. The value nil means the
20834 default face. The value t means whatever face the window's mode line
20835 currently uses (either `mode-line' or `mode-line-inactive',
20836 depending on whether the window is the selected window or not).
20837 An integer value means the value string has no text
20840 Optional third and fourth args WINDOW and BUFFER specify the window
20841 and buffer to use as the context for the formatting (defaults
20842 are the selected window and the WINDOW's buffer). */)
20843 (Lisp_Object format
, Lisp_Object face
,
20844 Lisp_Object window
, Lisp_Object buffer
)
20849 struct buffer
*old_buffer
= NULL
;
20851 int no_props
= INTEGERP (face
);
20852 ptrdiff_t count
= SPECPDL_INDEX ();
20854 int string_start
= 0;
20857 window
= selected_window
;
20858 CHECK_WINDOW (window
);
20859 w
= XWINDOW (window
);
20862 buffer
= w
->buffer
;
20863 CHECK_BUFFER (buffer
);
20865 /* Make formatting the modeline a non-op when noninteractive, otherwise
20866 there will be problems later caused by a partially initialized frame. */
20867 if (NILP (format
) || noninteractive
)
20868 return empty_unibyte_string
;
20873 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20874 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20875 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20876 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20877 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20878 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20879 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20882 if (XBUFFER (buffer
) != current_buffer
)
20883 old_buffer
= current_buffer
;
20885 /* Save things including mode_line_proptrans_alist,
20886 and set that to nil so that we don't alter the outer value. */
20887 record_unwind_protect (unwind_format_mode_line
,
20888 format_mode_line_unwind_data
20889 (XFRAME (WINDOW_FRAME (XWINDOW (window
))),
20890 old_buffer
, selected_window
, 1));
20891 mode_line_proptrans_alist
= Qnil
;
20893 Fselect_window (window
, Qt
);
20895 set_buffer_internal_1 (XBUFFER (buffer
));
20897 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20901 mode_line_target
= MODE_LINE_NOPROP
;
20902 mode_line_string_face_prop
= Qnil
;
20903 mode_line_string_list
= Qnil
;
20904 string_start
= MODE_LINE_NOPROP_LEN (0);
20908 mode_line_target
= MODE_LINE_STRING
;
20909 mode_line_string_list
= Qnil
;
20910 mode_line_string_face
= face
;
20911 mode_line_string_face_prop
20912 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20915 push_kboard (FRAME_KBOARD (it
.f
));
20916 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20921 len
= MODE_LINE_NOPROP_LEN (string_start
);
20922 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20926 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20927 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20928 empty_unibyte_string
);
20931 unbind_to (count
, Qnil
);
20935 /* Write a null-terminated, right justified decimal representation of
20936 the positive integer D to BUF using a minimal field width WIDTH. */
20939 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20941 register char *p
= buf
;
20949 *p
++ = d
% 10 + '0';
20954 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20965 /* Write a null-terminated, right justified decimal and "human
20966 readable" representation of the nonnegative integer D to BUF using
20967 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20969 static const char power_letter
[] =
20983 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20985 /* We aim to represent the nonnegative integer D as
20986 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20987 ptrdiff_t quotient
= d
;
20989 /* -1 means: do not use TENTHS. */
20993 /* Length of QUOTIENT.TENTHS as a string. */
20999 if (1000 <= quotient
)
21001 /* Scale to the appropriate EXPONENT. */
21004 remainder
= quotient
% 1000;
21008 while (1000 <= quotient
);
21010 /* Round to nearest and decide whether to use TENTHS or not. */
21013 tenths
= remainder
/ 100;
21014 if (50 <= remainder
% 100)
21021 if (quotient
== 10)
21029 if (500 <= remainder
)
21031 if (quotient
< 999)
21042 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21043 if (tenths
== -1 && quotient
<= 99)
21050 p
= psuffix
= buf
+ max (width
, length
);
21052 /* Print EXPONENT. */
21053 *psuffix
++ = power_letter
[exponent
];
21056 /* Print TENTHS. */
21059 *--p
= '0' + tenths
;
21063 /* Print QUOTIENT. */
21066 int digit
= quotient
% 10;
21067 *--p
= '0' + digit
;
21069 while ((quotient
/= 10) != 0);
21071 /* Print leading spaces. */
21076 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21077 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21078 type of CODING_SYSTEM. Return updated pointer into BUF. */
21080 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21083 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21086 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21087 const unsigned char *eol_str
;
21089 /* The EOL conversion we are using. */
21090 Lisp_Object eoltype
;
21092 val
= CODING_SYSTEM_SPEC (coding_system
);
21095 if (!VECTORP (val
)) /* Not yet decided. */
21097 *buf
++ = multibyte
? '-' : ' ';
21099 eoltype
= eol_mnemonic_undecided
;
21100 /* Don't mention EOL conversion if it isn't decided. */
21105 Lisp_Object eolvalue
;
21107 attrs
= AREF (val
, 0);
21108 eolvalue
= AREF (val
, 2);
21111 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21116 /* The EOL conversion that is normal on this system. */
21118 if (NILP (eolvalue
)) /* Not yet decided. */
21119 eoltype
= eol_mnemonic_undecided
;
21120 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21121 eoltype
= eol_mnemonic_undecided
;
21122 else /* eolvalue is Qunix, Qdos, or Qmac. */
21123 eoltype
= (EQ (eolvalue
, Qunix
)
21124 ? eol_mnemonic_unix
21125 : (EQ (eolvalue
, Qdos
) == 1
21126 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21132 /* Mention the EOL conversion if it is not the usual one. */
21133 if (STRINGP (eoltype
))
21135 eol_str
= SDATA (eoltype
);
21136 eol_str_len
= SBYTES (eoltype
);
21138 else if (CHARACTERP (eoltype
))
21140 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
21141 int c
= XFASTINT (eoltype
);
21142 eol_str_len
= CHAR_STRING (c
, tmp
);
21147 eol_str
= invalid_eol_type
;
21148 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21150 memcpy (buf
, eol_str
, eol_str_len
);
21151 buf
+= eol_str_len
;
21157 /* Return a string for the output of a mode line %-spec for window W,
21158 generated by character C. FIELD_WIDTH > 0 means pad the string
21159 returned with spaces to that value. Return a Lisp string in
21160 *STRING if the resulting string is taken from that Lisp string.
21162 Note we operate on the current buffer for most purposes,
21163 the exception being w->base_line_pos. */
21165 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21167 static const char *
21168 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21169 Lisp_Object
*string
)
21172 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21173 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21174 struct buffer
*b
= current_buffer
;
21182 if (!NILP (BVAR (b
, read_only
)))
21184 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21189 /* This differs from %* only for a modified read-only buffer. */
21190 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21192 if (!NILP (BVAR (b
, read_only
)))
21197 /* This differs from %* in ignoring read-only-ness. */
21198 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21210 if (command_loop_level
> 5)
21212 p
= decode_mode_spec_buf
;
21213 for (i
= 0; i
< command_loop_level
; i
++)
21216 return decode_mode_spec_buf
;
21224 if (command_loop_level
> 5)
21226 p
= decode_mode_spec_buf
;
21227 for (i
= 0; i
< command_loop_level
; i
++)
21230 return decode_mode_spec_buf
;
21237 /* Let lots_of_dashes be a string of infinite length. */
21238 if (mode_line_target
== MODE_LINE_NOPROP
||
21239 mode_line_target
== MODE_LINE_STRING
)
21241 if (field_width
<= 0
21242 || field_width
> sizeof (lots_of_dashes
))
21244 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21245 decode_mode_spec_buf
[i
] = '-';
21246 decode_mode_spec_buf
[i
] = '\0';
21247 return decode_mode_spec_buf
;
21250 return lots_of_dashes
;
21254 obj
= BVAR (b
, name
);
21258 /* %c and %l are ignored in `frame-title-format'.
21259 (In redisplay_internal, the frame title is drawn _before_ the
21260 windows are updated, so the stuff which depends on actual
21261 window contents (such as %l) may fail to render properly, or
21262 even crash emacs.) */
21263 if (mode_line_target
== MODE_LINE_TITLE
)
21267 ptrdiff_t col
= current_column ();
21268 w
->column_number_displayed
= make_number (col
);
21269 pint2str (decode_mode_spec_buf
, field_width
, col
);
21270 return decode_mode_spec_buf
;
21274 #ifndef SYSTEM_MALLOC
21276 if (NILP (Vmemory_full
))
21279 return "!MEM FULL! ";
21286 /* %F displays the frame name. */
21287 if (!NILP (f
->title
))
21288 return SSDATA (f
->title
);
21289 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21290 return SSDATA (f
->name
);
21294 obj
= BVAR (b
, filename
);
21299 ptrdiff_t size
= ZV
- BEGV
;
21300 pint2str (decode_mode_spec_buf
, field_width
, size
);
21301 return decode_mode_spec_buf
;
21306 ptrdiff_t size
= ZV
- BEGV
;
21307 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21308 return decode_mode_spec_buf
;
21313 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21314 ptrdiff_t topline
, nlines
, height
;
21317 /* %c and %l are ignored in `frame-title-format'. */
21318 if (mode_line_target
== MODE_LINE_TITLE
)
21321 startpos
= XMARKER (w
->start
)->charpos
;
21322 startpos_byte
= marker_byte_position (w
->start
);
21323 height
= WINDOW_TOTAL_LINES (w
);
21325 /* If we decided that this buffer isn't suitable for line numbers,
21326 don't forget that too fast. */
21327 if (EQ (w
->base_line_pos
, w
->buffer
))
21329 /* But do forget it, if the window shows a different buffer now. */
21330 else if (BUFFERP (w
->base_line_pos
))
21331 w
->base_line_pos
= Qnil
;
21333 /* If the buffer is very big, don't waste time. */
21334 if (INTEGERP (Vline_number_display_limit
)
21335 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21337 w
->base_line_pos
= Qnil
;
21338 w
->base_line_number
= Qnil
;
21342 if (INTEGERP (w
->base_line_number
)
21343 && INTEGERP (w
->base_line_pos
)
21344 && XFASTINT (w
->base_line_pos
) <= startpos
)
21346 line
= XFASTINT (w
->base_line_number
);
21347 linepos
= XFASTINT (w
->base_line_pos
);
21348 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21353 linepos
= BUF_BEGV (b
);
21354 linepos_byte
= BUF_BEGV_BYTE (b
);
21357 /* Count lines from base line to window start position. */
21358 nlines
= display_count_lines (linepos_byte
,
21362 topline
= nlines
+ line
;
21364 /* Determine a new base line, if the old one is too close
21365 or too far away, or if we did not have one.
21366 "Too close" means it's plausible a scroll-down would
21367 go back past it. */
21368 if (startpos
== BUF_BEGV (b
))
21370 w
->base_line_number
= make_number (topline
);
21371 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21373 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21374 || linepos
== BUF_BEGV (b
))
21376 ptrdiff_t limit
= BUF_BEGV (b
);
21377 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21378 ptrdiff_t position
;
21379 ptrdiff_t distance
=
21380 (height
* 2 + 30) * line_number_display_limit_width
;
21382 if (startpos
- distance
> limit
)
21384 limit
= startpos
- distance
;
21385 limit_byte
= CHAR_TO_BYTE (limit
);
21388 nlines
= display_count_lines (startpos_byte
,
21390 - (height
* 2 + 30),
21392 /* If we couldn't find the lines we wanted within
21393 line_number_display_limit_width chars per line,
21394 give up on line numbers for this window. */
21395 if (position
== limit_byte
&& limit
== startpos
- distance
)
21397 w
->base_line_pos
= w
->buffer
;
21398 w
->base_line_number
= Qnil
;
21402 w
->base_line_number
= make_number (topline
- nlines
);
21403 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21406 /* Now count lines from the start pos to point. */
21407 nlines
= display_count_lines (startpos_byte
,
21408 PT_BYTE
, PT
, &junk
);
21410 /* Record that we did display the line number. */
21411 line_number_displayed
= 1;
21413 /* Make the string to show. */
21414 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21415 return decode_mode_spec_buf
;
21418 char* p
= decode_mode_spec_buf
;
21419 int pad
= field_width
- 2;
21425 return decode_mode_spec_buf
;
21431 obj
= BVAR (b
, mode_name
);
21435 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21441 ptrdiff_t pos
= marker_position (w
->start
);
21442 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21444 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21446 if (pos
<= BUF_BEGV (b
))
21451 else if (pos
<= BUF_BEGV (b
))
21455 if (total
> 1000000)
21456 /* Do it differently for a large value, to avoid overflow. */
21457 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21459 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21460 /* We can't normally display a 3-digit number,
21461 so get us a 2-digit number that is close. */
21464 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21465 return decode_mode_spec_buf
;
21469 /* Display percentage of size above the bottom of the screen. */
21472 ptrdiff_t toppos
= marker_position (w
->start
);
21473 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21474 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21476 if (botpos
>= BUF_ZV (b
))
21478 if (toppos
<= BUF_BEGV (b
))
21485 if (total
> 1000000)
21486 /* Do it differently for a large value, to avoid overflow. */
21487 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21489 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21490 /* We can't normally display a 3-digit number,
21491 so get us a 2-digit number that is close. */
21494 if (toppos
<= BUF_BEGV (b
))
21495 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21497 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21498 return decode_mode_spec_buf
;
21503 /* status of process */
21504 obj
= Fget_buffer_process (Fcurrent_buffer ());
21506 return "no process";
21508 obj
= Fsymbol_name (Fprocess_status (obj
));
21514 ptrdiff_t count
= inhibit_garbage_collection ();
21515 Lisp_Object val
= call1 (intern ("file-remote-p"),
21516 BVAR (current_buffer
, directory
));
21517 unbind_to (count
, Qnil
);
21525 case 't': /* indicate TEXT or BINARY */
21529 /* coding-system (not including end-of-line format) */
21531 /* coding-system (including end-of-line type) */
21533 int eol_flag
= (c
== 'Z');
21534 char *p
= decode_mode_spec_buf
;
21536 if (! FRAME_WINDOW_P (f
))
21538 /* No need to mention EOL here--the terminal never needs
21539 to do EOL conversion. */
21540 p
= decode_mode_spec_coding (CODING_ID_NAME
21541 (FRAME_KEYBOARD_CODING (f
)->id
),
21543 p
= decode_mode_spec_coding (CODING_ID_NAME
21544 (FRAME_TERMINAL_CODING (f
)->id
),
21547 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21550 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21551 #ifdef subprocesses
21552 obj
= Fget_buffer_process (Fcurrent_buffer ());
21553 if (PROCESSP (obj
))
21555 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21557 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21560 #endif /* subprocesses */
21563 return decode_mode_spec_buf
;
21570 return SSDATA (obj
);
21577 /* Count up to COUNT lines starting from START_BYTE.
21578 But don't go beyond LIMIT_BYTE.
21579 Return the number of lines thus found (always nonnegative).
21581 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21584 display_count_lines (ptrdiff_t start_byte
,
21585 ptrdiff_t limit_byte
, ptrdiff_t count
,
21586 ptrdiff_t *byte_pos_ptr
)
21588 register unsigned char *cursor
;
21589 unsigned char *base
;
21591 register ptrdiff_t ceiling
;
21592 register unsigned char *ceiling_addr
;
21593 ptrdiff_t orig_count
= count
;
21595 /* If we are not in selective display mode,
21596 check only for newlines. */
21597 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21598 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21602 while (start_byte
< limit_byte
)
21604 ceiling
= BUFFER_CEILING_OF (start_byte
);
21605 ceiling
= min (limit_byte
- 1, ceiling
);
21606 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21607 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21610 if (selective_display
)
21611 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21614 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21617 if (cursor
!= ceiling_addr
)
21621 start_byte
+= cursor
- base
+ 1;
21622 *byte_pos_ptr
= start_byte
;
21626 if (++cursor
== ceiling_addr
)
21632 start_byte
+= cursor
- base
;
21637 while (start_byte
> limit_byte
)
21639 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21640 ceiling
= max (limit_byte
, ceiling
);
21641 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21642 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21645 if (selective_display
)
21646 while (--cursor
!= ceiling_addr
21647 && *cursor
!= '\n' && *cursor
!= 015)
21650 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21653 if (cursor
!= ceiling_addr
)
21657 start_byte
+= cursor
- base
+ 1;
21658 *byte_pos_ptr
= start_byte
;
21659 /* When scanning backwards, we should
21660 not count the newline posterior to which we stop. */
21661 return - orig_count
- 1;
21667 /* Here we add 1 to compensate for the last decrement
21668 of CURSOR, which took it past the valid range. */
21669 start_byte
+= cursor
- base
+ 1;
21673 *byte_pos_ptr
= limit_byte
;
21676 return - orig_count
+ count
;
21677 return orig_count
- count
;
21683 /***********************************************************************
21685 ***********************************************************************/
21687 /* Display a NUL-terminated string, starting with index START.
21689 If STRING is non-null, display that C string. Otherwise, the Lisp
21690 string LISP_STRING is displayed. There's a case that STRING is
21691 non-null and LISP_STRING is not nil. It means STRING is a string
21692 data of LISP_STRING. In that case, we display LISP_STRING while
21693 ignoring its text properties.
21695 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21696 FACE_STRING. Display STRING or LISP_STRING with the face at
21697 FACE_STRING_POS in FACE_STRING:
21699 Display the string in the environment given by IT, but use the
21700 standard display table, temporarily.
21702 FIELD_WIDTH is the minimum number of output glyphs to produce.
21703 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21704 with spaces. If STRING has more characters, more than FIELD_WIDTH
21705 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21707 PRECISION is the maximum number of characters to output from
21708 STRING. PRECISION < 0 means don't truncate the string.
21710 This is roughly equivalent to printf format specifiers:
21712 FIELD_WIDTH PRECISION PRINTF
21713 ----------------------------------------
21719 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21720 display them, and < 0 means obey the current buffer's value of
21721 enable_multibyte_characters.
21723 Value is the number of columns displayed. */
21726 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21727 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21728 int field_width
, int precision
, int max_x
, int multibyte
)
21730 int hpos_at_start
= it
->hpos
;
21731 int saved_face_id
= it
->face_id
;
21732 struct glyph_row
*row
= it
->glyph_row
;
21733 ptrdiff_t it_charpos
;
21735 /* Initialize the iterator IT for iteration over STRING beginning
21736 with index START. */
21737 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21738 precision
, field_width
, multibyte
);
21739 if (string
&& STRINGP (lisp_string
))
21740 /* LISP_STRING is the one returned by decode_mode_spec. We should
21741 ignore its text properties. */
21742 it
->stop_charpos
= it
->end_charpos
;
21744 /* If displaying STRING, set up the face of the iterator from
21745 FACE_STRING, if that's given. */
21746 if (STRINGP (face_string
))
21752 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21753 0, it
->region_beg_charpos
,
21754 it
->region_end_charpos
,
21755 &endptr
, it
->base_face_id
, 0);
21756 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21757 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21760 /* Set max_x to the maximum allowed X position. Don't let it go
21761 beyond the right edge of the window. */
21763 max_x
= it
->last_visible_x
;
21765 max_x
= min (max_x
, it
->last_visible_x
);
21767 /* Skip over display elements that are not visible. because IT->w is
21769 if (it
->current_x
< it
->first_visible_x
)
21770 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21771 MOVE_TO_POS
| MOVE_TO_X
);
21773 row
->ascent
= it
->max_ascent
;
21774 row
->height
= it
->max_ascent
+ it
->max_descent
;
21775 row
->phys_ascent
= it
->max_phys_ascent
;
21776 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21777 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21779 if (STRINGP (it
->string
))
21780 it_charpos
= IT_STRING_CHARPOS (*it
);
21782 it_charpos
= IT_CHARPOS (*it
);
21784 /* This condition is for the case that we are called with current_x
21785 past last_visible_x. */
21786 while (it
->current_x
< max_x
)
21788 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21790 /* Get the next display element. */
21791 if (!get_next_display_element (it
))
21794 /* Produce glyphs. */
21795 x_before
= it
->current_x
;
21796 n_glyphs_before
= row
->used
[TEXT_AREA
];
21797 PRODUCE_GLYPHS (it
);
21799 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21802 while (i
< nglyphs
)
21804 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21806 if (it
->line_wrap
!= TRUNCATE
21807 && x
+ glyph
->pixel_width
> max_x
)
21809 /* End of continued line or max_x reached. */
21810 if (CHAR_GLYPH_PADDING_P (*glyph
))
21812 /* A wide character is unbreakable. */
21813 if (row
->reversed_p
)
21814 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21815 - n_glyphs_before
);
21816 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21817 it
->current_x
= x_before
;
21821 if (row
->reversed_p
)
21822 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21823 - (n_glyphs_before
+ i
));
21824 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21829 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21831 /* Glyph is at least partially visible. */
21833 if (x
< it
->first_visible_x
)
21834 row
->x
= x
- it
->first_visible_x
;
21838 /* Glyph is off the left margin of the display area.
21839 Should not happen. */
21843 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21844 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21845 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21846 row
->phys_height
= max (row
->phys_height
,
21847 it
->max_phys_ascent
+ it
->max_phys_descent
);
21848 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21849 it
->max_extra_line_spacing
);
21850 x
+= glyph
->pixel_width
;
21854 /* Stop if max_x reached. */
21858 /* Stop at line ends. */
21859 if (ITERATOR_AT_END_OF_LINE_P (it
))
21861 it
->continuation_lines_width
= 0;
21865 set_iterator_to_next (it
, 1);
21866 if (STRINGP (it
->string
))
21867 it_charpos
= IT_STRING_CHARPOS (*it
);
21869 it_charpos
= IT_CHARPOS (*it
);
21871 /* Stop if truncating at the right edge. */
21872 if (it
->line_wrap
== TRUNCATE
21873 && it
->current_x
>= it
->last_visible_x
)
21875 /* Add truncation mark, but don't do it if the line is
21876 truncated at a padding space. */
21877 if (it_charpos
< it
->string_nchars
)
21879 if (!FRAME_WINDOW_P (it
->f
))
21883 if (it
->current_x
> it
->last_visible_x
)
21885 if (!row
->reversed_p
)
21887 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21888 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21893 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21894 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21896 unproduce_glyphs (it
, ii
+ 1);
21897 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21899 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21901 row
->used
[TEXT_AREA
] = ii
;
21902 produce_special_glyphs (it
, IT_TRUNCATION
);
21905 produce_special_glyphs (it
, IT_TRUNCATION
);
21907 row
->truncated_on_right_p
= 1;
21913 /* Maybe insert a truncation at the left. */
21914 if (it
->first_visible_x
21917 if (!FRAME_WINDOW_P (it
->f
))
21918 insert_left_trunc_glyphs (it
);
21919 row
->truncated_on_left_p
= 1;
21922 it
->face_id
= saved_face_id
;
21924 /* Value is number of columns displayed. */
21925 return it
->hpos
- hpos_at_start
;
21930 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21931 appears as an element of LIST or as the car of an element of LIST.
21932 If PROPVAL is a list, compare each element against LIST in that
21933 way, and return 1/2 if any element of PROPVAL is found in LIST.
21934 Otherwise return 0. This function cannot quit.
21935 The return value is 2 if the text is invisible but with an ellipsis
21936 and 1 if it's invisible and without an ellipsis. */
21939 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21941 register Lisp_Object tail
, proptail
;
21943 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21945 register Lisp_Object tem
;
21947 if (EQ (propval
, tem
))
21949 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21950 return NILP (XCDR (tem
)) ? 1 : 2;
21953 if (CONSP (propval
))
21955 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21957 Lisp_Object propelt
;
21958 propelt
= XCAR (proptail
);
21959 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21961 register Lisp_Object tem
;
21963 if (EQ (propelt
, tem
))
21965 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21966 return NILP (XCDR (tem
)) ? 1 : 2;
21974 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21975 doc
: /* Non-nil if the property makes the text invisible.
21976 POS-OR-PROP can be a marker or number, in which case it is taken to be
21977 a position in the current buffer and the value of the `invisible' property
21978 is checked; or it can be some other value, which is then presumed to be the
21979 value of the `invisible' property of the text of interest.
21980 The non-nil value returned can be t for truly invisible text or something
21981 else if the text is replaced by an ellipsis. */)
21982 (Lisp_Object pos_or_prop
)
21985 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21986 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21988 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21989 return (invis
== 0 ? Qnil
21991 : make_number (invis
));
21994 /* Calculate a width or height in pixels from a specification using
21995 the following elements:
21998 NUM - a (fractional) multiple of the default font width/height
21999 (NUM) - specifies exactly NUM pixels
22000 UNIT - a fixed number of pixels, see below.
22001 ELEMENT - size of a display element in pixels, see below.
22002 (NUM . SPEC) - equals NUM * SPEC
22003 (+ SPEC SPEC ...) - add pixel values
22004 (- SPEC SPEC ...) - subtract pixel values
22005 (- SPEC) - negate pixel value
22008 INT or FLOAT - a number constant
22009 SYMBOL - use symbol's (buffer local) variable binding.
22012 in - pixels per inch *)
22013 mm - pixels per 1/1000 meter *)
22014 cm - pixels per 1/100 meter *)
22015 width - width of current font in pixels.
22016 height - height of current font in pixels.
22018 *) using the ratio(s) defined in display-pixels-per-inch.
22022 left-fringe - left fringe width in pixels
22023 right-fringe - right fringe width in pixels
22025 left-margin - left margin width in pixels
22026 right-margin - right margin width in pixels
22028 scroll-bar - scroll-bar area width in pixels
22032 Pixels corresponding to 5 inches:
22035 Total width of non-text areas on left side of window (if scroll-bar is on left):
22036 '(space :width (+ left-fringe left-margin scroll-bar))
22038 Align to first text column (in header line):
22039 '(space :align-to 0)
22041 Align to middle of text area minus half the width of variable `my-image'
22042 containing a loaded image:
22043 '(space :align-to (0.5 . (- text my-image)))
22045 Width of left margin minus width of 1 character in the default font:
22046 '(space :width (- left-margin 1))
22048 Width of left margin minus width of 2 characters in the current font:
22049 '(space :width (- left-margin (2 . width)))
22051 Center 1 character over left-margin (in header line):
22052 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22054 Different ways to express width of left fringe plus left margin minus one pixel:
22055 '(space :width (- (+ left-fringe left-margin) (1)))
22056 '(space :width (+ left-fringe left-margin (- (1))))
22057 '(space :width (+ left-fringe left-margin (-1)))
22061 #define NUMVAL(X) \
22062 ((INTEGERP (X) || FLOATP (X)) \
22067 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22068 struct font
*font
, int width_p
, int *align_to
)
22072 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22073 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22076 return OK_PIXELS (0);
22078 eassert (FRAME_LIVE_P (it
->f
));
22080 if (SYMBOLP (prop
))
22082 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22084 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22086 if (unit
[0] == 'i' && unit
[1] == 'n')
22088 else if (unit
[0] == 'm' && unit
[1] == 'm')
22090 else if (unit
[0] == 'c' && unit
[1] == 'm')
22097 #ifdef HAVE_WINDOW_SYSTEM
22098 if (FRAME_WINDOW_P (it
->f
)
22100 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22101 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22103 return OK_PIXELS (ppi
/ pixels
);
22106 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22107 || (CONSP (Vdisplay_pixels_per_inch
)
22109 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22110 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22112 return OK_PIXELS (ppi
/ pixels
);
22118 #ifdef HAVE_WINDOW_SYSTEM
22119 if (EQ (prop
, Qheight
))
22120 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22121 if (EQ (prop
, Qwidth
))
22122 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22124 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22125 return OK_PIXELS (1);
22128 if (EQ (prop
, Qtext
))
22129 return OK_PIXELS (width_p
22130 ? window_box_width (it
->w
, TEXT_AREA
)
22131 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22133 if (align_to
&& *align_to
< 0)
22136 if (EQ (prop
, Qleft
))
22137 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22138 if (EQ (prop
, Qright
))
22139 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22140 if (EQ (prop
, Qcenter
))
22141 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22142 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22143 if (EQ (prop
, Qleft_fringe
))
22144 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22145 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22146 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22147 if (EQ (prop
, Qright_fringe
))
22148 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22149 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22150 : window_box_right_offset (it
->w
, TEXT_AREA
));
22151 if (EQ (prop
, Qleft_margin
))
22152 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22153 if (EQ (prop
, Qright_margin
))
22154 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22155 if (EQ (prop
, Qscroll_bar
))
22156 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22158 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22159 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22160 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22165 if (EQ (prop
, Qleft_fringe
))
22166 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22167 if (EQ (prop
, Qright_fringe
))
22168 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22169 if (EQ (prop
, Qleft_margin
))
22170 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22171 if (EQ (prop
, Qright_margin
))
22172 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22173 if (EQ (prop
, Qscroll_bar
))
22174 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22177 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22178 if (EQ (prop
, Qunbound
))
22182 if (INTEGERP (prop
) || FLOATP (prop
))
22184 int base_unit
= (width_p
22185 ? FRAME_COLUMN_WIDTH (it
->f
)
22186 : FRAME_LINE_HEIGHT (it
->f
));
22187 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22192 Lisp_Object car
= XCAR (prop
);
22193 Lisp_Object cdr
= XCDR (prop
);
22197 #ifdef HAVE_WINDOW_SYSTEM
22198 if (FRAME_WINDOW_P (it
->f
)
22199 && valid_image_p (prop
))
22201 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22202 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22204 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22207 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22213 while (CONSP (cdr
))
22215 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22216 font
, width_p
, align_to
))
22219 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22224 if (EQ (car
, Qminus
))
22226 return OK_PIXELS (pixels
);
22229 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22230 if (EQ (car
, Qunbound
))
22234 if (INTEGERP (car
) || FLOATP (car
))
22237 pixels
= XFLOATINT (car
);
22239 return OK_PIXELS (pixels
);
22240 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22241 font
, width_p
, align_to
))
22242 return OK_PIXELS (pixels
* fact
);
22253 /***********************************************************************
22255 ***********************************************************************/
22257 #ifdef HAVE_WINDOW_SYSTEM
22262 dump_glyph_string (struct glyph_string
*s
)
22264 fprintf (stderr
, "glyph string\n");
22265 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22266 s
->x
, s
->y
, s
->width
, s
->height
);
22267 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22268 fprintf (stderr
, " hl = %d\n", s
->hl
);
22269 fprintf (stderr
, " left overhang = %d, right = %d\n",
22270 s
->left_overhang
, s
->right_overhang
);
22271 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22272 fprintf (stderr
, " extends to end of line = %d\n",
22273 s
->extends_to_end_of_line_p
);
22274 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22275 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22278 #endif /* GLYPH_DEBUG */
22280 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22281 of XChar2b structures for S; it can't be allocated in
22282 init_glyph_string because it must be allocated via `alloca'. W
22283 is the window on which S is drawn. ROW and AREA are the glyph row
22284 and area within the row from which S is constructed. START is the
22285 index of the first glyph structure covered by S. HL is a
22286 face-override for drawing S. */
22289 #define OPTIONAL_HDC(hdc) HDC hdc,
22290 #define DECLARE_HDC(hdc) HDC hdc;
22291 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22292 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22295 #ifndef OPTIONAL_HDC
22296 #define OPTIONAL_HDC(hdc)
22297 #define DECLARE_HDC(hdc)
22298 #define ALLOCATE_HDC(hdc, f)
22299 #define RELEASE_HDC(hdc, f)
22303 init_glyph_string (struct glyph_string
*s
,
22305 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22306 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22308 memset (s
, 0, sizeof *s
);
22310 s
->f
= XFRAME (w
->frame
);
22314 s
->display
= FRAME_X_DISPLAY (s
->f
);
22315 s
->window
= FRAME_X_WINDOW (s
->f
);
22316 s
->char2b
= char2b
;
22320 s
->first_glyph
= row
->glyphs
[area
] + start
;
22321 s
->height
= row
->height
;
22322 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22323 s
->ybase
= s
->y
+ row
->ascent
;
22327 /* Append the list of glyph strings with head H and tail T to the list
22328 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22331 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22332 struct glyph_string
*h
, struct glyph_string
*t
)
22346 /* Prepend the list of glyph strings with head H and tail T to the
22347 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22351 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22352 struct glyph_string
*h
, struct glyph_string
*t
)
22366 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22367 Set *HEAD and *TAIL to the resulting list. */
22370 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22371 struct glyph_string
*s
)
22373 s
->next
= s
->prev
= NULL
;
22374 append_glyph_string_lists (head
, tail
, s
, s
);
22378 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22379 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22380 make sure that X resources for the face returned are allocated.
22381 Value is a pointer to a realized face that is ready for display if
22382 DISPLAY_P is non-zero. */
22384 static inline struct face
*
22385 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22386 XChar2b
*char2b
, int display_p
)
22388 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22392 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22394 if (code
!= FONT_INVALID_CODE
)
22395 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22397 STORE_XCHAR2B (char2b
, 0, 0);
22400 /* Make sure X resources of the face are allocated. */
22401 #ifdef HAVE_X_WINDOWS
22405 eassert (face
!= NULL
);
22406 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22413 /* Get face and two-byte form of character glyph GLYPH on frame F.
22414 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22415 a pointer to a realized face that is ready for display. */
22417 static inline struct face
*
22418 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22419 XChar2b
*char2b
, int *two_byte_p
)
22423 eassert (glyph
->type
== CHAR_GLYPH
);
22424 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22433 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22434 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22436 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22438 if (code
!= FONT_INVALID_CODE
)
22439 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22441 STORE_XCHAR2B (char2b
, 0, 0);
22444 /* Make sure X resources of the face are allocated. */
22445 eassert (face
!= NULL
);
22446 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22451 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22452 Return 1 if FONT has a glyph for C, otherwise return 0. */
22455 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22459 if (CHAR_BYTE8_P (c
))
22460 code
= CHAR_TO_BYTE8 (c
);
22462 code
= font
->driver
->encode_char (font
, c
);
22464 if (code
== FONT_INVALID_CODE
)
22466 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22471 /* Fill glyph string S with composition components specified by S->cmp.
22473 BASE_FACE is the base face of the composition.
22474 S->cmp_from is the index of the first component for S.
22476 OVERLAPS non-zero means S should draw the foreground only, and use
22477 its physical height for clipping. See also draw_glyphs.
22479 Value is the index of a component not in S. */
22482 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22486 /* For all glyphs of this composition, starting at the offset
22487 S->cmp_from, until we reach the end of the definition or encounter a
22488 glyph that requires the different face, add it to S. */
22493 s
->for_overlaps
= overlaps
;
22496 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22498 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22500 /* TAB in a composition means display glyphs with padding space
22501 on the left or right. */
22504 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22507 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22514 s
->font
= s
->face
->font
;
22516 else if (s
->face
!= face
)
22524 if (s
->face
== NULL
)
22526 s
->face
= base_face
->ascii_face
;
22527 s
->font
= s
->face
->font
;
22530 /* All glyph strings for the same composition has the same width,
22531 i.e. the width set for the first component of the composition. */
22532 s
->width
= s
->first_glyph
->pixel_width
;
22534 /* If the specified font could not be loaded, use the frame's
22535 default font, but record the fact that we couldn't load it in
22536 the glyph string so that we can draw rectangles for the
22537 characters of the glyph string. */
22538 if (s
->font
== NULL
)
22540 s
->font_not_found_p
= 1;
22541 s
->font
= FRAME_FONT (s
->f
);
22544 /* Adjust base line for subscript/superscript text. */
22545 s
->ybase
+= s
->first_glyph
->voffset
;
22547 /* This glyph string must always be drawn with 16-bit functions. */
22554 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22555 int start
, int end
, int overlaps
)
22557 struct glyph
*glyph
, *last
;
22558 Lisp_Object lgstring
;
22561 s
->for_overlaps
= overlaps
;
22562 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22563 last
= s
->row
->glyphs
[s
->area
] + end
;
22564 s
->cmp_id
= glyph
->u
.cmp
.id
;
22565 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22566 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22567 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22568 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22569 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22571 while (glyph
< last
22572 && glyph
->u
.cmp
.automatic
22573 && glyph
->u
.cmp
.id
== s
->cmp_id
22574 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22575 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22577 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22579 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22580 unsigned code
= LGLYPH_CODE (lglyph
);
22582 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22584 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22585 return glyph
- s
->row
->glyphs
[s
->area
];
22589 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22590 See the comment of fill_glyph_string for arguments.
22591 Value is the index of the first glyph not in S. */
22595 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22596 int start
, int end
, int overlaps
)
22598 struct glyph
*glyph
, *last
;
22601 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22602 s
->for_overlaps
= overlaps
;
22603 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22604 last
= s
->row
->glyphs
[s
->area
] + end
;
22605 voffset
= glyph
->voffset
;
22606 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22607 s
->font
= s
->face
->font
;
22609 s
->width
= glyph
->pixel_width
;
22611 while (glyph
< last
22612 && glyph
->type
== GLYPHLESS_GLYPH
22613 && glyph
->voffset
== voffset
22614 && glyph
->face_id
== face_id
)
22617 s
->width
+= glyph
->pixel_width
;
22620 s
->ybase
+= voffset
;
22621 return glyph
- s
->row
->glyphs
[s
->area
];
22625 /* Fill glyph string S from a sequence of character glyphs.
22627 FACE_ID is the face id of the string. START is the index of the
22628 first glyph to consider, END is the index of the last + 1.
22629 OVERLAPS non-zero means S should draw the foreground only, and use
22630 its physical height for clipping. See also draw_glyphs.
22632 Value is the index of the first glyph not in S. */
22635 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22636 int start
, int end
, int overlaps
)
22638 struct glyph
*glyph
, *last
;
22640 int glyph_not_available_p
;
22642 eassert (s
->f
== XFRAME (s
->w
->frame
));
22643 eassert (s
->nchars
== 0);
22644 eassert (start
>= 0 && end
> start
);
22646 s
->for_overlaps
= overlaps
;
22647 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22648 last
= s
->row
->glyphs
[s
->area
] + end
;
22649 voffset
= glyph
->voffset
;
22650 s
->padding_p
= glyph
->padding_p
;
22651 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22653 while (glyph
< last
22654 && glyph
->type
== CHAR_GLYPH
22655 && glyph
->voffset
== voffset
22656 /* Same face id implies same font, nowadays. */
22657 && glyph
->face_id
== face_id
22658 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22662 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22663 s
->char2b
+ s
->nchars
,
22665 s
->two_byte_p
= two_byte_p
;
22667 eassert (s
->nchars
<= end
- start
);
22668 s
->width
+= glyph
->pixel_width
;
22669 if (glyph
++->padding_p
!= s
->padding_p
)
22673 s
->font
= s
->face
->font
;
22675 /* If the specified font could not be loaded, use the frame's font,
22676 but record the fact that we couldn't load it in
22677 S->font_not_found_p so that we can draw rectangles for the
22678 characters of the glyph string. */
22679 if (s
->font
== NULL
|| glyph_not_available_p
)
22681 s
->font_not_found_p
= 1;
22682 s
->font
= FRAME_FONT (s
->f
);
22685 /* Adjust base line for subscript/superscript text. */
22686 s
->ybase
+= voffset
;
22688 eassert (s
->face
&& s
->face
->gc
);
22689 return glyph
- s
->row
->glyphs
[s
->area
];
22693 /* Fill glyph string S from image glyph S->first_glyph. */
22696 fill_image_glyph_string (struct glyph_string
*s
)
22698 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22699 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22701 s
->slice
= s
->first_glyph
->slice
.img
;
22702 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22703 s
->font
= s
->face
->font
;
22704 s
->width
= s
->first_glyph
->pixel_width
;
22706 /* Adjust base line for subscript/superscript text. */
22707 s
->ybase
+= s
->first_glyph
->voffset
;
22711 /* Fill glyph string S from a sequence of stretch glyphs.
22713 START is the index of the first glyph to consider,
22714 END is the index of the last + 1.
22716 Value is the index of the first glyph not in S. */
22719 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22721 struct glyph
*glyph
, *last
;
22722 int voffset
, face_id
;
22724 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22726 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22727 last
= s
->row
->glyphs
[s
->area
] + end
;
22728 face_id
= glyph
->face_id
;
22729 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22730 s
->font
= s
->face
->font
;
22731 s
->width
= glyph
->pixel_width
;
22733 voffset
= glyph
->voffset
;
22737 && glyph
->type
== STRETCH_GLYPH
22738 && glyph
->voffset
== voffset
22739 && glyph
->face_id
== face_id
);
22741 s
->width
+= glyph
->pixel_width
;
22743 /* Adjust base line for subscript/superscript text. */
22744 s
->ybase
+= voffset
;
22746 /* The case that face->gc == 0 is handled when drawing the glyph
22747 string by calling PREPARE_FACE_FOR_DISPLAY. */
22749 return glyph
- s
->row
->glyphs
[s
->area
];
22752 static struct font_metrics
*
22753 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22755 static struct font_metrics metrics
;
22756 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22758 if (! font
|| code
== FONT_INVALID_CODE
)
22760 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22765 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22766 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22767 assumed to be zero. */
22770 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22772 *left
= *right
= 0;
22774 if (glyph
->type
== CHAR_GLYPH
)
22778 struct font_metrics
*pcm
;
22780 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22781 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22783 if (pcm
->rbearing
> pcm
->width
)
22784 *right
= pcm
->rbearing
- pcm
->width
;
22785 if (pcm
->lbearing
< 0)
22786 *left
= -pcm
->lbearing
;
22789 else if (glyph
->type
== COMPOSITE_GLYPH
)
22791 if (! glyph
->u
.cmp
.automatic
)
22793 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22795 if (cmp
->rbearing
> cmp
->pixel_width
)
22796 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22797 if (cmp
->lbearing
< 0)
22798 *left
= - cmp
->lbearing
;
22802 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22803 struct font_metrics metrics
;
22805 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22806 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22807 if (metrics
.rbearing
> metrics
.width
)
22808 *right
= metrics
.rbearing
- metrics
.width
;
22809 if (metrics
.lbearing
< 0)
22810 *left
= - metrics
.lbearing
;
22816 /* Return the index of the first glyph preceding glyph string S that
22817 is overwritten by S because of S's left overhang. Value is -1
22818 if no glyphs are overwritten. */
22821 left_overwritten (struct glyph_string
*s
)
22825 if (s
->left_overhang
)
22828 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22829 int first
= s
->first_glyph
- glyphs
;
22831 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22832 x
-= glyphs
[i
].pixel_width
;
22843 /* Return the index of the first glyph preceding glyph string S that
22844 is overwriting S because of its right overhang. Value is -1 if no
22845 glyph in front of S overwrites S. */
22848 left_overwriting (struct glyph_string
*s
)
22851 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22852 int first
= s
->first_glyph
- glyphs
;
22856 for (i
= first
- 1; i
>= 0; --i
)
22859 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22862 x
-= glyphs
[i
].pixel_width
;
22869 /* Return the index of the last glyph following glyph string S that is
22870 overwritten by S because of S's right overhang. Value is -1 if
22871 no such glyph is found. */
22874 right_overwritten (struct glyph_string
*s
)
22878 if (s
->right_overhang
)
22881 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22882 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22883 int end
= s
->row
->used
[s
->area
];
22885 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22886 x
+= glyphs
[i
].pixel_width
;
22895 /* Return the index of the last glyph following glyph string S that
22896 overwrites S because of its left overhang. Value is negative
22897 if no such glyph is found. */
22900 right_overwriting (struct glyph_string
*s
)
22903 int end
= s
->row
->used
[s
->area
];
22904 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22905 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22909 for (i
= first
; i
< end
; ++i
)
22912 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22915 x
+= glyphs
[i
].pixel_width
;
22922 /* Set background width of glyph string S. START is the index of the
22923 first glyph following S. LAST_X is the right-most x-position + 1
22924 in the drawing area. */
22927 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22929 /* If the face of this glyph string has to be drawn to the end of
22930 the drawing area, set S->extends_to_end_of_line_p. */
22932 if (start
== s
->row
->used
[s
->area
]
22933 && s
->area
== TEXT_AREA
22934 && ((s
->row
->fill_line_p
22935 && (s
->hl
== DRAW_NORMAL_TEXT
22936 || s
->hl
== DRAW_IMAGE_RAISED
22937 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22938 || s
->hl
== DRAW_MOUSE_FACE
))
22939 s
->extends_to_end_of_line_p
= 1;
22941 /* If S extends its face to the end of the line, set its
22942 background_width to the distance to the right edge of the drawing
22944 if (s
->extends_to_end_of_line_p
)
22945 s
->background_width
= last_x
- s
->x
+ 1;
22947 s
->background_width
= s
->width
;
22951 /* Compute overhangs and x-positions for glyph string S and its
22952 predecessors, or successors. X is the starting x-position for S.
22953 BACKWARD_P non-zero means process predecessors. */
22956 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22962 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22963 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22973 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22974 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22984 /* The following macros are only called from draw_glyphs below.
22985 They reference the following parameters of that function directly:
22986 `w', `row', `area', and `overlap_p'
22987 as well as the following local variables:
22988 `s', `f', and `hdc' (in W32) */
22991 /* On W32, silently add local `hdc' variable to argument list of
22992 init_glyph_string. */
22993 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22994 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22996 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22997 init_glyph_string (s, char2b, w, row, area, start, hl)
23000 /* Add a glyph string for a stretch glyph to the list of strings
23001 between HEAD and TAIL. START is the index of the stretch glyph in
23002 row area AREA of glyph row ROW. END is the index of the last glyph
23003 in that glyph row area. X is the current output position assigned
23004 to the new glyph string constructed. HL overrides that face of the
23005 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23006 is the right-most x-position of the drawing area. */
23008 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23009 and below -- keep them on one line. */
23010 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23013 s = (struct glyph_string *) alloca (sizeof *s); \
23014 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23015 START = fill_stretch_glyph_string (s, START, END); \
23016 append_glyph_string (&HEAD, &TAIL, s); \
23022 /* Add a glyph string for an image glyph to the list of strings
23023 between HEAD and TAIL. START is the index of the image glyph in
23024 row area AREA of glyph row ROW. END is the index of the last glyph
23025 in that glyph row area. X is the current output position assigned
23026 to the new glyph string constructed. HL overrides that face of the
23027 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23028 is the right-most x-position of the drawing area. */
23030 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23033 s = (struct glyph_string *) alloca (sizeof *s); \
23034 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23035 fill_image_glyph_string (s); \
23036 append_glyph_string (&HEAD, &TAIL, s); \
23043 /* Add a glyph string for a sequence of character glyphs to the list
23044 of strings between HEAD and TAIL. START is the index of the first
23045 glyph in row area AREA of glyph row ROW that is part of the new
23046 glyph string. END is the index of the last glyph in that glyph row
23047 area. X is the current output position assigned to the new glyph
23048 string constructed. HL overrides that face of the glyph; e.g. it
23049 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23050 right-most x-position of the drawing area. */
23052 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23058 face_id = (row)->glyphs[area][START].face_id; \
23060 s = (struct glyph_string *) alloca (sizeof *s); \
23061 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
23062 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23063 append_glyph_string (&HEAD, &TAIL, s); \
23065 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23070 /* Add a glyph string for a composite sequence to the list of strings
23071 between HEAD and TAIL. START is the index of the first glyph in
23072 row area AREA of glyph row ROW that is part of the new glyph
23073 string. END is the index of the last glyph in that glyph row area.
23074 X is the current output position assigned to the new glyph string
23075 constructed. HL overrides that face of the glyph; e.g. it is
23076 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23077 x-position of the drawing area. */
23079 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23081 int face_id = (row)->glyphs[area][START].face_id; \
23082 struct face *base_face = FACE_FROM_ID (f, face_id); \
23083 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23084 struct composition *cmp = composition_table[cmp_id]; \
23086 struct glyph_string *first_s = NULL; \
23089 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
23091 /* Make glyph_strings for each glyph sequence that is drawable by \
23092 the same face, and append them to HEAD/TAIL. */ \
23093 for (n = 0; n < cmp->glyph_len;) \
23095 s = (struct glyph_string *) alloca (sizeof *s); \
23096 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23097 append_glyph_string (&(HEAD), &(TAIL), s); \
23103 n = fill_composite_glyph_string (s, base_face, overlaps); \
23111 /* Add a glyph string for a glyph-string sequence to the list of strings
23112 between HEAD and TAIL. */
23114 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23118 Lisp_Object gstring; \
23120 face_id = (row)->glyphs[area][START].face_id; \
23121 gstring = (composition_gstring_from_id \
23122 ((row)->glyphs[area][START].u.cmp.id)); \
23123 s = (struct glyph_string *) alloca (sizeof *s); \
23124 char2b = (XChar2b *) alloca ((sizeof *char2b) \
23125 * LGSTRING_GLYPH_LEN (gstring)); \
23126 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23127 append_glyph_string (&(HEAD), &(TAIL), s); \
23129 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23133 /* Add a glyph string for a sequence of glyphless character's glyphs
23134 to the list of strings between HEAD and TAIL. The meanings of
23135 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23137 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23142 face_id = (row)->glyphs[area][START].face_id; \
23144 s = (struct glyph_string *) alloca (sizeof *s); \
23145 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23146 append_glyph_string (&HEAD, &TAIL, s); \
23148 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23154 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23155 of AREA of glyph row ROW on window W between indices START and END.
23156 HL overrides the face for drawing glyph strings, e.g. it is
23157 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23158 x-positions of the drawing area.
23160 This is an ugly monster macro construct because we must use alloca
23161 to allocate glyph strings (because draw_glyphs can be called
23162 asynchronously). */
23164 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23167 HEAD = TAIL = NULL; \
23168 while (START < END) \
23170 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23171 switch (first_glyph->type) \
23174 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23178 case COMPOSITE_GLYPH: \
23179 if (first_glyph->u.cmp.automatic) \
23180 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23183 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23187 case STRETCH_GLYPH: \
23188 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23192 case IMAGE_GLYPH: \
23193 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23197 case GLYPHLESS_GLYPH: \
23198 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23208 set_glyph_string_background_width (s, START, LAST_X); \
23215 /* Draw glyphs between START and END in AREA of ROW on window W,
23216 starting at x-position X. X is relative to AREA in W. HL is a
23217 face-override with the following meaning:
23219 DRAW_NORMAL_TEXT draw normally
23220 DRAW_CURSOR draw in cursor face
23221 DRAW_MOUSE_FACE draw in mouse face.
23222 DRAW_INVERSE_VIDEO draw in mode line face
23223 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23224 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23226 If OVERLAPS is non-zero, draw only the foreground of characters and
23227 clip to the physical height of ROW. Non-zero value also defines
23228 the overlapping part to be drawn:
23230 OVERLAPS_PRED overlap with preceding rows
23231 OVERLAPS_SUCC overlap with succeeding rows
23232 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23233 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23235 Value is the x-position reached, relative to AREA of W. */
23238 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23239 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23240 enum draw_glyphs_face hl
, int overlaps
)
23242 struct glyph_string
*head
, *tail
;
23243 struct glyph_string
*s
;
23244 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23245 int i
, j
, x_reached
, last_x
, area_left
= 0;
23246 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23249 ALLOCATE_HDC (hdc
, f
);
23251 /* Let's rather be paranoid than getting a SEGV. */
23252 end
= min (end
, row
->used
[area
]);
23253 start
= max (0, start
);
23254 start
= min (end
, start
);
23256 /* Translate X to frame coordinates. Set last_x to the right
23257 end of the drawing area. */
23258 if (row
->full_width_p
)
23260 /* X is relative to the left edge of W, without scroll bars
23262 area_left
= WINDOW_LEFT_EDGE_X (w
);
23263 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23267 area_left
= window_box_left (w
, area
);
23268 last_x
= area_left
+ window_box_width (w
, area
);
23272 /* Build a doubly-linked list of glyph_string structures between
23273 head and tail from what we have to draw. Note that the macro
23274 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23275 the reason we use a separate variable `i'. */
23277 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23279 x_reached
= tail
->x
+ tail
->background_width
;
23283 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23284 the row, redraw some glyphs in front or following the glyph
23285 strings built above. */
23286 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23288 struct glyph_string
*h
, *t
;
23289 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23290 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23291 int check_mouse_face
= 0;
23294 /* If mouse highlighting is on, we may need to draw adjacent
23295 glyphs using mouse-face highlighting. */
23296 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23298 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23300 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23301 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23303 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23305 check_mouse_face
= 1;
23306 mouse_beg_col
= (row
== mouse_beg_row
)
23307 ? hlinfo
->mouse_face_beg_col
: 0;
23308 mouse_end_col
= (row
== mouse_end_row
)
23309 ? hlinfo
->mouse_face_end_col
23310 : row
->used
[TEXT_AREA
];
23314 /* Compute overhangs for all glyph strings. */
23315 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23316 for (s
= head
; s
; s
= s
->next
)
23317 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23319 /* Prepend glyph strings for glyphs in front of the first glyph
23320 string that are overwritten because of the first glyph
23321 string's left overhang. The background of all strings
23322 prepended must be drawn because the first glyph string
23324 i
= left_overwritten (head
);
23327 enum draw_glyphs_face overlap_hl
;
23329 /* If this row contains mouse highlighting, attempt to draw
23330 the overlapped glyphs with the correct highlight. This
23331 code fails if the overlap encompasses more than one glyph
23332 and mouse-highlight spans only some of these glyphs.
23333 However, making it work perfectly involves a lot more
23334 code, and I don't know if the pathological case occurs in
23335 practice, so we'll stick to this for now. --- cyd */
23336 if (check_mouse_face
23337 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23338 overlap_hl
= DRAW_MOUSE_FACE
;
23340 overlap_hl
= DRAW_NORMAL_TEXT
;
23343 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23344 overlap_hl
, dummy_x
, last_x
);
23346 compute_overhangs_and_x (t
, head
->x
, 1);
23347 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23351 /* Prepend glyph strings for glyphs in front of the first glyph
23352 string that overwrite that glyph string because of their
23353 right overhang. For these strings, only the foreground must
23354 be drawn, because it draws over the glyph string at `head'.
23355 The background must not be drawn because this would overwrite
23356 right overhangs of preceding glyphs for which no glyph
23358 i
= left_overwriting (head
);
23361 enum draw_glyphs_face overlap_hl
;
23363 if (check_mouse_face
23364 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23365 overlap_hl
= DRAW_MOUSE_FACE
;
23367 overlap_hl
= DRAW_NORMAL_TEXT
;
23370 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23371 overlap_hl
, dummy_x
, last_x
);
23372 for (s
= h
; s
; s
= s
->next
)
23373 s
->background_filled_p
= 1;
23374 compute_overhangs_and_x (t
, head
->x
, 1);
23375 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23378 /* Append glyphs strings for glyphs following the last glyph
23379 string tail that are overwritten by tail. The background of
23380 these strings has to be drawn because tail's foreground draws
23382 i
= right_overwritten (tail
);
23385 enum draw_glyphs_face overlap_hl
;
23387 if (check_mouse_face
23388 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23389 overlap_hl
= DRAW_MOUSE_FACE
;
23391 overlap_hl
= DRAW_NORMAL_TEXT
;
23393 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23394 overlap_hl
, x
, last_x
);
23395 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23396 we don't have `end = i;' here. */
23397 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23398 append_glyph_string_lists (&head
, &tail
, h
, t
);
23402 /* Append glyph strings for glyphs following the last glyph
23403 string tail that overwrite tail. The foreground of such
23404 glyphs has to be drawn because it writes into the background
23405 of tail. The background must not be drawn because it could
23406 paint over the foreground of following glyphs. */
23407 i
= right_overwriting (tail
);
23410 enum draw_glyphs_face overlap_hl
;
23411 if (check_mouse_face
23412 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23413 overlap_hl
= DRAW_MOUSE_FACE
;
23415 overlap_hl
= DRAW_NORMAL_TEXT
;
23418 i
++; /* We must include the Ith glyph. */
23419 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23420 overlap_hl
, x
, last_x
);
23421 for (s
= h
; s
; s
= s
->next
)
23422 s
->background_filled_p
= 1;
23423 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23424 append_glyph_string_lists (&head
, &tail
, h
, t
);
23426 if (clip_head
|| clip_tail
)
23427 for (s
= head
; s
; s
= s
->next
)
23429 s
->clip_head
= clip_head
;
23430 s
->clip_tail
= clip_tail
;
23434 /* Draw all strings. */
23435 for (s
= head
; s
; s
= s
->next
)
23436 FRAME_RIF (f
)->draw_glyph_string (s
);
23439 /* When focus a sole frame and move horizontally, this sets on_p to 0
23440 causing a failure to erase prev cursor position. */
23441 if (area
== TEXT_AREA
23442 && !row
->full_width_p
23443 /* When drawing overlapping rows, only the glyph strings'
23444 foreground is drawn, which doesn't erase a cursor
23448 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23449 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23450 : (tail
? tail
->x
+ tail
->background_width
: x
));
23454 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23455 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23459 /* Value is the x-position up to which drawn, relative to AREA of W.
23460 This doesn't include parts drawn because of overhangs. */
23461 if (row
->full_width_p
)
23462 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23464 x_reached
-= area_left
;
23466 RELEASE_HDC (hdc
, f
);
23471 /* Expand row matrix if too narrow. Don't expand if area
23474 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23476 if (!fonts_changed_p \
23477 && (it->glyph_row->glyphs[area] \
23478 < it->glyph_row->glyphs[area + 1])) \
23480 it->w->ncols_scale_factor++; \
23481 fonts_changed_p = 1; \
23485 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23486 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23489 append_glyph (struct it
*it
)
23491 struct glyph
*glyph
;
23492 enum glyph_row_area area
= it
->area
;
23494 eassert (it
->glyph_row
);
23495 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23497 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23498 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23500 /* If the glyph row is reversed, we need to prepend the glyph
23501 rather than append it. */
23502 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23506 /* Make room for the additional glyph. */
23507 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23509 glyph
= it
->glyph_row
->glyphs
[area
];
23511 glyph
->charpos
= CHARPOS (it
->position
);
23512 glyph
->object
= it
->object
;
23513 if (it
->pixel_width
> 0)
23515 glyph
->pixel_width
= it
->pixel_width
;
23516 glyph
->padding_p
= 0;
23520 /* Assure at least 1-pixel width. Otherwise, cursor can't
23521 be displayed correctly. */
23522 glyph
->pixel_width
= 1;
23523 glyph
->padding_p
= 1;
23525 glyph
->ascent
= it
->ascent
;
23526 glyph
->descent
= it
->descent
;
23527 glyph
->voffset
= it
->voffset
;
23528 glyph
->type
= CHAR_GLYPH
;
23529 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23530 glyph
->multibyte_p
= it
->multibyte_p
;
23531 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23532 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23533 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23534 || it
->phys_descent
> it
->descent
);
23535 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23536 glyph
->face_id
= it
->face_id
;
23537 glyph
->u
.ch
= it
->char_to_display
;
23538 glyph
->slice
.img
= null_glyph_slice
;
23539 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23542 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23543 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23545 glyph
->bidi_type
= it
->bidi_it
.type
;
23549 glyph
->resolved_level
= 0;
23550 glyph
->bidi_type
= UNKNOWN_BT
;
23552 ++it
->glyph_row
->used
[area
];
23555 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23558 /* Store one glyph for the composition IT->cmp_it.id in
23559 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23563 append_composite_glyph (struct it
*it
)
23565 struct glyph
*glyph
;
23566 enum glyph_row_area area
= it
->area
;
23568 eassert (it
->glyph_row
);
23570 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23571 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23573 /* If the glyph row is reversed, we need to prepend the glyph
23574 rather than append it. */
23575 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23579 /* Make room for the new glyph. */
23580 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23582 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23584 glyph
->charpos
= it
->cmp_it
.charpos
;
23585 glyph
->object
= it
->object
;
23586 glyph
->pixel_width
= it
->pixel_width
;
23587 glyph
->ascent
= it
->ascent
;
23588 glyph
->descent
= it
->descent
;
23589 glyph
->voffset
= it
->voffset
;
23590 glyph
->type
= COMPOSITE_GLYPH
;
23591 if (it
->cmp_it
.ch
< 0)
23593 glyph
->u
.cmp
.automatic
= 0;
23594 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23595 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23599 glyph
->u
.cmp
.automatic
= 1;
23600 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23601 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23602 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23604 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23605 glyph
->multibyte_p
= it
->multibyte_p
;
23606 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23607 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23608 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23609 || it
->phys_descent
> it
->descent
);
23610 glyph
->padding_p
= 0;
23611 glyph
->glyph_not_available_p
= 0;
23612 glyph
->face_id
= it
->face_id
;
23613 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23616 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23617 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23619 glyph
->bidi_type
= it
->bidi_it
.type
;
23621 ++it
->glyph_row
->used
[area
];
23624 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23628 /* Change IT->ascent and IT->height according to the setting of
23632 take_vertical_position_into_account (struct it
*it
)
23636 if (it
->voffset
< 0)
23637 /* Increase the ascent so that we can display the text higher
23639 it
->ascent
-= it
->voffset
;
23641 /* Increase the descent so that we can display the text lower
23643 it
->descent
+= it
->voffset
;
23648 /* Produce glyphs/get display metrics for the image IT is loaded with.
23649 See the description of struct display_iterator in dispextern.h for
23650 an overview of struct display_iterator. */
23653 produce_image_glyph (struct it
*it
)
23657 int glyph_ascent
, crop
;
23658 struct glyph_slice slice
;
23660 eassert (it
->what
== IT_IMAGE
);
23662 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23664 /* Make sure X resources of the face is loaded. */
23665 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23667 if (it
->image_id
< 0)
23669 /* Fringe bitmap. */
23670 it
->ascent
= it
->phys_ascent
= 0;
23671 it
->descent
= it
->phys_descent
= 0;
23672 it
->pixel_width
= 0;
23677 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23679 /* Make sure X resources of the image is loaded. */
23680 prepare_image_for_display (it
->f
, img
);
23682 slice
.x
= slice
.y
= 0;
23683 slice
.width
= img
->width
;
23684 slice
.height
= img
->height
;
23686 if (INTEGERP (it
->slice
.x
))
23687 slice
.x
= XINT (it
->slice
.x
);
23688 else if (FLOATP (it
->slice
.x
))
23689 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23691 if (INTEGERP (it
->slice
.y
))
23692 slice
.y
= XINT (it
->slice
.y
);
23693 else if (FLOATP (it
->slice
.y
))
23694 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23696 if (INTEGERP (it
->slice
.width
))
23697 slice
.width
= XINT (it
->slice
.width
);
23698 else if (FLOATP (it
->slice
.width
))
23699 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23701 if (INTEGERP (it
->slice
.height
))
23702 slice
.height
= XINT (it
->slice
.height
);
23703 else if (FLOATP (it
->slice
.height
))
23704 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23706 if (slice
.x
>= img
->width
)
23707 slice
.x
= img
->width
;
23708 if (slice
.y
>= img
->height
)
23709 slice
.y
= img
->height
;
23710 if (slice
.x
+ slice
.width
>= img
->width
)
23711 slice
.width
= img
->width
- slice
.x
;
23712 if (slice
.y
+ slice
.height
> img
->height
)
23713 slice
.height
= img
->height
- slice
.y
;
23715 if (slice
.width
== 0 || slice
.height
== 0)
23718 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23720 it
->descent
= slice
.height
- glyph_ascent
;
23722 it
->descent
+= img
->vmargin
;
23723 if (slice
.y
+ slice
.height
== img
->height
)
23724 it
->descent
+= img
->vmargin
;
23725 it
->phys_descent
= it
->descent
;
23727 it
->pixel_width
= slice
.width
;
23729 it
->pixel_width
+= img
->hmargin
;
23730 if (slice
.x
+ slice
.width
== img
->width
)
23731 it
->pixel_width
+= img
->hmargin
;
23733 /* It's quite possible for images to have an ascent greater than
23734 their height, so don't get confused in that case. */
23735 if (it
->descent
< 0)
23740 if (face
->box
!= FACE_NO_BOX
)
23742 if (face
->box_line_width
> 0)
23745 it
->ascent
+= face
->box_line_width
;
23746 if (slice
.y
+ slice
.height
== img
->height
)
23747 it
->descent
+= face
->box_line_width
;
23750 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23751 it
->pixel_width
+= eabs (face
->box_line_width
);
23752 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23753 it
->pixel_width
+= eabs (face
->box_line_width
);
23756 take_vertical_position_into_account (it
);
23758 /* Automatically crop wide image glyphs at right edge so we can
23759 draw the cursor on same display row. */
23760 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23761 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23763 it
->pixel_width
-= crop
;
23764 slice
.width
-= crop
;
23769 struct glyph
*glyph
;
23770 enum glyph_row_area area
= it
->area
;
23772 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23773 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23775 glyph
->charpos
= CHARPOS (it
->position
);
23776 glyph
->object
= it
->object
;
23777 glyph
->pixel_width
= it
->pixel_width
;
23778 glyph
->ascent
= glyph_ascent
;
23779 glyph
->descent
= it
->descent
;
23780 glyph
->voffset
= it
->voffset
;
23781 glyph
->type
= IMAGE_GLYPH
;
23782 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23783 glyph
->multibyte_p
= it
->multibyte_p
;
23784 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23785 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23786 glyph
->overlaps_vertically_p
= 0;
23787 glyph
->padding_p
= 0;
23788 glyph
->glyph_not_available_p
= 0;
23789 glyph
->face_id
= it
->face_id
;
23790 glyph
->u
.img_id
= img
->id
;
23791 glyph
->slice
.img
= slice
;
23792 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23795 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23796 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23798 glyph
->bidi_type
= it
->bidi_it
.type
;
23800 ++it
->glyph_row
->used
[area
];
23803 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23808 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23809 of the glyph, WIDTH and HEIGHT are the width and height of the
23810 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23813 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23814 int width
, int height
, int ascent
)
23816 struct glyph
*glyph
;
23817 enum glyph_row_area area
= it
->area
;
23819 eassert (ascent
>= 0 && ascent
<= height
);
23821 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23822 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23824 /* If the glyph row is reversed, we need to prepend the glyph
23825 rather than append it. */
23826 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23830 /* Make room for the additional glyph. */
23831 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23833 glyph
= it
->glyph_row
->glyphs
[area
];
23835 glyph
->charpos
= CHARPOS (it
->position
);
23836 glyph
->object
= object
;
23837 glyph
->pixel_width
= width
;
23838 glyph
->ascent
= ascent
;
23839 glyph
->descent
= height
- ascent
;
23840 glyph
->voffset
= it
->voffset
;
23841 glyph
->type
= STRETCH_GLYPH
;
23842 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23843 glyph
->multibyte_p
= it
->multibyte_p
;
23844 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23845 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23846 glyph
->overlaps_vertically_p
= 0;
23847 glyph
->padding_p
= 0;
23848 glyph
->glyph_not_available_p
= 0;
23849 glyph
->face_id
= it
->face_id
;
23850 glyph
->u
.stretch
.ascent
= ascent
;
23851 glyph
->u
.stretch
.height
= height
;
23852 glyph
->slice
.img
= null_glyph_slice
;
23853 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23856 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23857 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23859 glyph
->bidi_type
= it
->bidi_it
.type
;
23863 glyph
->resolved_level
= 0;
23864 glyph
->bidi_type
= UNKNOWN_BT
;
23866 ++it
->glyph_row
->used
[area
];
23869 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23872 #endif /* HAVE_WINDOW_SYSTEM */
23874 /* Produce a stretch glyph for iterator IT. IT->object is the value
23875 of the glyph property displayed. The value must be a list
23876 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23879 1. `:width WIDTH' specifies that the space should be WIDTH *
23880 canonical char width wide. WIDTH may be an integer or floating
23883 2. `:relative-width FACTOR' specifies that the width of the stretch
23884 should be computed from the width of the first character having the
23885 `glyph' property, and should be FACTOR times that width.
23887 3. `:align-to HPOS' specifies that the space should be wide enough
23888 to reach HPOS, a value in canonical character units.
23890 Exactly one of the above pairs must be present.
23892 4. `:height HEIGHT' specifies that the height of the stretch produced
23893 should be HEIGHT, measured in canonical character units.
23895 5. `:relative-height FACTOR' specifies that the height of the
23896 stretch should be FACTOR times the height of the characters having
23897 the glyph property.
23899 Either none or exactly one of 4 or 5 must be present.
23901 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23902 of the stretch should be used for the ascent of the stretch.
23903 ASCENT must be in the range 0 <= ASCENT <= 100. */
23906 produce_stretch_glyph (struct it
*it
)
23908 /* (space :width WIDTH :height HEIGHT ...) */
23909 Lisp_Object prop
, plist
;
23910 int width
= 0, height
= 0, align_to
= -1;
23911 int zero_width_ok_p
= 0;
23914 struct face
*face
= NULL
;
23915 struct font
*font
= NULL
;
23917 #ifdef HAVE_WINDOW_SYSTEM
23918 int zero_height_ok_p
= 0;
23920 if (FRAME_WINDOW_P (it
->f
))
23922 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23923 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23924 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23928 /* List should start with `space'. */
23929 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23930 plist
= XCDR (it
->object
);
23932 /* Compute the width of the stretch. */
23933 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23934 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23936 /* Absolute width `:width WIDTH' specified and valid. */
23937 zero_width_ok_p
= 1;
23940 #ifdef HAVE_WINDOW_SYSTEM
23941 else if (FRAME_WINDOW_P (it
->f
)
23942 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23944 /* Relative width `:relative-width FACTOR' specified and valid.
23945 Compute the width of the characters having the `glyph'
23948 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23951 if (it
->multibyte_p
)
23952 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23955 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23956 if (! ASCII_CHAR_P (it2
.c
))
23957 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23960 it2
.glyph_row
= NULL
;
23961 it2
.what
= IT_CHARACTER
;
23962 x_produce_glyphs (&it2
);
23963 width
= NUMVAL (prop
) * it2
.pixel_width
;
23965 #endif /* HAVE_WINDOW_SYSTEM */
23966 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23967 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23969 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23970 align_to
= (align_to
< 0
23972 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23973 else if (align_to
< 0)
23974 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23975 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23976 zero_width_ok_p
= 1;
23979 /* Nothing specified -> width defaults to canonical char width. */
23980 width
= FRAME_COLUMN_WIDTH (it
->f
);
23982 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23985 #ifdef HAVE_WINDOW_SYSTEM
23986 /* Compute height. */
23987 if (FRAME_WINDOW_P (it
->f
))
23989 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23990 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23993 zero_height_ok_p
= 1;
23995 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23997 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23999 height
= FONT_HEIGHT (font
);
24001 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24004 /* Compute percentage of height used for ascent. If
24005 `:ascent ASCENT' is present and valid, use that. Otherwise,
24006 derive the ascent from the font in use. */
24007 if (prop
= Fplist_get (plist
, QCascent
),
24008 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24009 ascent
= height
* NUMVAL (prop
) / 100.0;
24010 else if (!NILP (prop
)
24011 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24012 ascent
= min (max (0, (int)tem
), height
);
24014 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24017 #endif /* HAVE_WINDOW_SYSTEM */
24020 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24021 && it
->current_x
+ width
> it
->last_visible_x
)
24023 width
= it
->last_visible_x
- it
->current_x
;
24024 #ifdef HAVE_WINDOW_SYSTEM
24025 /* Subtract one more pixel from the stretch width, but only on
24026 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24027 width
-= FRAME_WINDOW_P (it
->f
);
24031 if (width
> 0 && height
> 0 && it
->glyph_row
)
24033 Lisp_Object o_object
= it
->object
;
24034 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24037 if (!STRINGP (object
))
24038 object
= it
->w
->buffer
;
24039 #ifdef HAVE_WINDOW_SYSTEM
24040 if (FRAME_WINDOW_P (it
->f
))
24041 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24045 it
->object
= object
;
24046 it
->char_to_display
= ' ';
24047 it
->pixel_width
= it
->len
= 1;
24049 tty_append_glyph (it
);
24050 it
->object
= o_object
;
24054 it
->pixel_width
= width
;
24055 #ifdef HAVE_WINDOW_SYSTEM
24056 if (FRAME_WINDOW_P (it
->f
))
24058 it
->ascent
= it
->phys_ascent
= ascent
;
24059 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24060 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24061 take_vertical_position_into_account (it
);
24065 it
->nglyphs
= width
;
24068 #ifdef HAVE_WINDOW_SYSTEM
24070 /* Calculate line-height and line-spacing properties.
24071 An integer value specifies explicit pixel value.
24072 A float value specifies relative value to current face height.
24073 A cons (float . face-name) specifies relative value to
24074 height of specified face font.
24076 Returns height in pixels, or nil. */
24080 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24081 int boff
, int override
)
24083 Lisp_Object face_name
= Qnil
;
24084 int ascent
, descent
, height
;
24086 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24091 face_name
= XCAR (val
);
24093 if (!NUMBERP (val
))
24094 val
= make_number (1);
24095 if (NILP (face_name
))
24097 height
= it
->ascent
+ it
->descent
;
24102 if (NILP (face_name
))
24104 font
= FRAME_FONT (it
->f
);
24105 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24107 else if (EQ (face_name
, Qt
))
24116 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24118 return make_number (-1);
24120 face
= FACE_FROM_ID (it
->f
, face_id
);
24123 return make_number (-1);
24124 boff
= font
->baseline_offset
;
24125 if (font
->vertical_centering
)
24126 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24129 ascent
= FONT_BASE (font
) + boff
;
24130 descent
= FONT_DESCENT (font
) - boff
;
24134 it
->override_ascent
= ascent
;
24135 it
->override_descent
= descent
;
24136 it
->override_boff
= boff
;
24139 height
= ascent
+ descent
;
24143 height
= (int)(XFLOAT_DATA (val
) * height
);
24144 else if (INTEGERP (val
))
24145 height
*= XINT (val
);
24147 return make_number (height
);
24151 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24152 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24153 and only if this is for a character for which no font was found.
24155 If the display method (it->glyphless_method) is
24156 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24157 length of the acronym or the hexadecimal string, UPPER_XOFF and
24158 UPPER_YOFF are pixel offsets for the upper part of the string,
24159 LOWER_XOFF and LOWER_YOFF are for the lower part.
24161 For the other display methods, LEN through LOWER_YOFF are zero. */
24164 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24165 short upper_xoff
, short upper_yoff
,
24166 short lower_xoff
, short lower_yoff
)
24168 struct glyph
*glyph
;
24169 enum glyph_row_area area
= it
->area
;
24171 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24172 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24174 /* If the glyph row is reversed, we need to prepend the glyph
24175 rather than append it. */
24176 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24180 /* Make room for the additional glyph. */
24181 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24183 glyph
= it
->glyph_row
->glyphs
[area
];
24185 glyph
->charpos
= CHARPOS (it
->position
);
24186 glyph
->object
= it
->object
;
24187 glyph
->pixel_width
= it
->pixel_width
;
24188 glyph
->ascent
= it
->ascent
;
24189 glyph
->descent
= it
->descent
;
24190 glyph
->voffset
= it
->voffset
;
24191 glyph
->type
= GLYPHLESS_GLYPH
;
24192 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24193 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24194 glyph
->u
.glyphless
.len
= len
;
24195 glyph
->u
.glyphless
.ch
= it
->c
;
24196 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24197 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24198 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24199 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24200 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24201 glyph
->multibyte_p
= it
->multibyte_p
;
24202 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24203 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24204 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24205 || it
->phys_descent
> it
->descent
);
24206 glyph
->padding_p
= 0;
24207 glyph
->glyph_not_available_p
= 0;
24208 glyph
->face_id
= face_id
;
24209 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24212 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24213 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24215 glyph
->bidi_type
= it
->bidi_it
.type
;
24217 ++it
->glyph_row
->used
[area
];
24220 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24224 /* Produce a glyph for a glyphless character for iterator IT.
24225 IT->glyphless_method specifies which method to use for displaying
24226 the character. See the description of enum
24227 glyphless_display_method in dispextern.h for the detail.
24229 FOR_NO_FONT is nonzero if and only if this is for a character for
24230 which no font was found. ACRONYM, if non-nil, is an acronym string
24231 for the character. */
24234 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24239 int base_width
, base_height
, width
, height
;
24240 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24243 /* Get the metrics of the base font. We always refer to the current
24245 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24246 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24247 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24248 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24249 base_height
= it
->ascent
+ it
->descent
;
24250 base_width
= font
->average_width
;
24252 /* Get a face ID for the glyph by utilizing a cache (the same way as
24253 done for `escape-glyph' in get_next_display_element). */
24254 if (it
->f
== last_glyphless_glyph_frame
24255 && it
->face_id
== last_glyphless_glyph_face_id
)
24257 face_id
= last_glyphless_glyph_merged_face_id
;
24261 /* Merge the `glyphless-char' face into the current face. */
24262 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24263 last_glyphless_glyph_frame
= it
->f
;
24264 last_glyphless_glyph_face_id
= it
->face_id
;
24265 last_glyphless_glyph_merged_face_id
= face_id
;
24268 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24270 it
->pixel_width
= THIN_SPACE_WIDTH
;
24272 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24274 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24276 width
= CHAR_WIDTH (it
->c
);
24279 else if (width
> 4)
24281 it
->pixel_width
= base_width
* width
;
24283 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24289 unsigned int code
[6];
24291 int ascent
, descent
;
24292 struct font_metrics metrics_upper
, metrics_lower
;
24294 face
= FACE_FROM_ID (it
->f
, face_id
);
24295 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24296 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24298 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24300 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24301 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24302 if (CONSP (acronym
))
24303 acronym
= XCAR (acronym
);
24304 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24308 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24309 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24312 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24313 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24314 upper_len
= (len
+ 1) / 2;
24315 font
->driver
->text_extents (font
, code
, upper_len
,
24317 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24322 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24323 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24324 upper_xoff
= upper_yoff
= 2; /* the typical case */
24325 if (base_width
>= width
)
24327 /* Align the upper to the left, the lower to the right. */
24328 it
->pixel_width
= base_width
;
24329 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24333 /* Center the shorter one. */
24334 it
->pixel_width
= width
;
24335 if (metrics_upper
.width
>= metrics_lower
.width
)
24336 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24339 /* FIXME: This code doesn't look right. It formerly was
24340 missing the "lower_xoff = 0;", which couldn't have
24341 been right since it left lower_xoff uninitialized. */
24343 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24347 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24348 top, bottom, and between upper and lower strings. */
24349 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24350 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24351 /* Center vertically.
24352 H:base_height, D:base_descent
24353 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24355 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24356 descent = D - H/2 + h/2;
24357 lower_yoff = descent - 2 - ld;
24358 upper_yoff = lower_yoff - la - 1 - ud; */
24359 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24360 descent
= it
->descent
- (base_height
- height
) / 2;
24361 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24362 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24363 - metrics_upper
.descent
);
24364 /* Don't make the height shorter than the base height. */
24365 if (height
> base_height
)
24367 it
->ascent
= ascent
;
24368 it
->descent
= descent
;
24372 it
->phys_ascent
= it
->ascent
;
24373 it
->phys_descent
= it
->descent
;
24375 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24376 upper_xoff
, upper_yoff
,
24377 lower_xoff
, lower_yoff
);
24379 take_vertical_position_into_account (it
);
24384 Produce glyphs/get display metrics for the display element IT is
24385 loaded with. See the description of struct it in dispextern.h
24386 for an overview of struct it. */
24389 x_produce_glyphs (struct it
*it
)
24391 int extra_line_spacing
= it
->extra_line_spacing
;
24393 it
->glyph_not_available_p
= 0;
24395 if (it
->what
== IT_CHARACTER
)
24398 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24399 struct font
*font
= face
->font
;
24400 struct font_metrics
*pcm
= NULL
;
24401 int boff
; /* baseline offset */
24405 /* When no suitable font is found, display this character by
24406 the method specified in the first extra slot of
24407 Vglyphless_char_display. */
24408 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24410 eassert (it
->what
== IT_GLYPHLESS
);
24411 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24415 boff
= font
->baseline_offset
;
24416 if (font
->vertical_centering
)
24417 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24419 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24425 if (it
->override_ascent
>= 0)
24427 it
->ascent
= it
->override_ascent
;
24428 it
->descent
= it
->override_descent
;
24429 boff
= it
->override_boff
;
24433 it
->ascent
= FONT_BASE (font
) + boff
;
24434 it
->descent
= FONT_DESCENT (font
) - boff
;
24437 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24439 pcm
= get_per_char_metric (font
, &char2b
);
24440 if (pcm
->width
== 0
24441 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24447 it
->phys_ascent
= pcm
->ascent
+ boff
;
24448 it
->phys_descent
= pcm
->descent
- boff
;
24449 it
->pixel_width
= pcm
->width
;
24453 it
->glyph_not_available_p
= 1;
24454 it
->phys_ascent
= it
->ascent
;
24455 it
->phys_descent
= it
->descent
;
24456 it
->pixel_width
= font
->space_width
;
24459 if (it
->constrain_row_ascent_descent_p
)
24461 if (it
->descent
> it
->max_descent
)
24463 it
->ascent
+= it
->descent
- it
->max_descent
;
24464 it
->descent
= it
->max_descent
;
24466 if (it
->ascent
> it
->max_ascent
)
24468 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24469 it
->ascent
= it
->max_ascent
;
24471 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24472 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24473 extra_line_spacing
= 0;
24476 /* If this is a space inside a region of text with
24477 `space-width' property, change its width. */
24478 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24480 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24482 /* If face has a box, add the box thickness to the character
24483 height. If character has a box line to the left and/or
24484 right, add the box line width to the character's width. */
24485 if (face
->box
!= FACE_NO_BOX
)
24487 int thick
= face
->box_line_width
;
24491 it
->ascent
+= thick
;
24492 it
->descent
+= thick
;
24497 if (it
->start_of_box_run_p
)
24498 it
->pixel_width
+= thick
;
24499 if (it
->end_of_box_run_p
)
24500 it
->pixel_width
+= thick
;
24503 /* If face has an overline, add the height of the overline
24504 (1 pixel) and a 1 pixel margin to the character height. */
24505 if (face
->overline_p
)
24506 it
->ascent
+= overline_margin
;
24508 if (it
->constrain_row_ascent_descent_p
)
24510 if (it
->ascent
> it
->max_ascent
)
24511 it
->ascent
= it
->max_ascent
;
24512 if (it
->descent
> it
->max_descent
)
24513 it
->descent
= it
->max_descent
;
24516 take_vertical_position_into_account (it
);
24518 /* If we have to actually produce glyphs, do it. */
24523 /* Translate a space with a `space-width' property
24524 into a stretch glyph. */
24525 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24526 / FONT_HEIGHT (font
));
24527 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24528 it
->ascent
+ it
->descent
, ascent
);
24533 /* If characters with lbearing or rbearing are displayed
24534 in this line, record that fact in a flag of the
24535 glyph row. This is used to optimize X output code. */
24536 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24537 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24539 if (! stretched_p
&& it
->pixel_width
== 0)
24540 /* We assure that all visible glyphs have at least 1-pixel
24542 it
->pixel_width
= 1;
24544 else if (it
->char_to_display
== '\n')
24546 /* A newline has no width, but we need the height of the
24547 line. But if previous part of the line sets a height,
24548 don't increase that height */
24550 Lisp_Object height
;
24551 Lisp_Object total_height
= Qnil
;
24553 it
->override_ascent
= -1;
24554 it
->pixel_width
= 0;
24557 height
= get_it_property (it
, Qline_height
);
24558 /* Split (line-height total-height) list */
24560 && CONSP (XCDR (height
))
24561 && NILP (XCDR (XCDR (height
))))
24563 total_height
= XCAR (XCDR (height
));
24564 height
= XCAR (height
);
24566 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24568 if (it
->override_ascent
>= 0)
24570 it
->ascent
= it
->override_ascent
;
24571 it
->descent
= it
->override_descent
;
24572 boff
= it
->override_boff
;
24576 it
->ascent
= FONT_BASE (font
) + boff
;
24577 it
->descent
= FONT_DESCENT (font
) - boff
;
24580 if (EQ (height
, Qt
))
24582 if (it
->descent
> it
->max_descent
)
24584 it
->ascent
+= it
->descent
- it
->max_descent
;
24585 it
->descent
= it
->max_descent
;
24587 if (it
->ascent
> it
->max_ascent
)
24589 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24590 it
->ascent
= it
->max_ascent
;
24592 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24593 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24594 it
->constrain_row_ascent_descent_p
= 1;
24595 extra_line_spacing
= 0;
24599 Lisp_Object spacing
;
24601 it
->phys_ascent
= it
->ascent
;
24602 it
->phys_descent
= it
->descent
;
24604 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24605 && face
->box
!= FACE_NO_BOX
24606 && face
->box_line_width
> 0)
24608 it
->ascent
+= face
->box_line_width
;
24609 it
->descent
+= face
->box_line_width
;
24612 && XINT (height
) > it
->ascent
+ it
->descent
)
24613 it
->ascent
= XINT (height
) - it
->descent
;
24615 if (!NILP (total_height
))
24616 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24619 spacing
= get_it_property (it
, Qline_spacing
);
24620 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24622 if (INTEGERP (spacing
))
24624 extra_line_spacing
= XINT (spacing
);
24625 if (!NILP (total_height
))
24626 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24630 else /* i.e. (it->char_to_display == '\t') */
24632 if (font
->space_width
> 0)
24634 int tab_width
= it
->tab_width
* font
->space_width
;
24635 int x
= it
->current_x
+ it
->continuation_lines_width
;
24636 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24638 /* If the distance from the current position to the next tab
24639 stop is less than a space character width, use the
24640 tab stop after that. */
24641 if (next_tab_x
- x
< font
->space_width
)
24642 next_tab_x
+= tab_width
;
24644 it
->pixel_width
= next_tab_x
- x
;
24646 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24647 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24651 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24652 it
->ascent
+ it
->descent
, it
->ascent
);
24657 it
->pixel_width
= 0;
24662 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24664 /* A static composition.
24666 Note: A composition is represented as one glyph in the
24667 glyph matrix. There are no padding glyphs.
24669 Important note: pixel_width, ascent, and descent are the
24670 values of what is drawn by draw_glyphs (i.e. the values of
24671 the overall glyphs composed). */
24672 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24673 int boff
; /* baseline offset */
24674 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24675 int glyph_len
= cmp
->glyph_len
;
24676 struct font
*font
= face
->font
;
24680 /* If we have not yet calculated pixel size data of glyphs of
24681 the composition for the current face font, calculate them
24682 now. Theoretically, we have to check all fonts for the
24683 glyphs, but that requires much time and memory space. So,
24684 here we check only the font of the first glyph. This may
24685 lead to incorrect display, but it's very rare, and C-l
24686 (recenter-top-bottom) can correct the display anyway. */
24687 if (! cmp
->font
|| cmp
->font
!= font
)
24689 /* Ascent and descent of the font of the first character
24690 of this composition (adjusted by baseline offset).
24691 Ascent and descent of overall glyphs should not be less
24692 than these, respectively. */
24693 int font_ascent
, font_descent
, font_height
;
24694 /* Bounding box of the overall glyphs. */
24695 int leftmost
, rightmost
, lowest
, highest
;
24696 int lbearing
, rbearing
;
24697 int i
, width
, ascent
, descent
;
24698 int left_padded
= 0, right_padded
= 0;
24699 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24701 struct font_metrics
*pcm
;
24702 int font_not_found_p
;
24705 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24706 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24708 if (glyph_len
< cmp
->glyph_len
)
24710 for (i
= 0; i
< glyph_len
; i
++)
24712 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24714 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24719 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24720 : IT_CHARPOS (*it
));
24721 /* If no suitable font is found, use the default font. */
24722 font_not_found_p
= font
== NULL
;
24723 if (font_not_found_p
)
24725 face
= face
->ascii_face
;
24728 boff
= font
->baseline_offset
;
24729 if (font
->vertical_centering
)
24730 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24731 font_ascent
= FONT_BASE (font
) + boff
;
24732 font_descent
= FONT_DESCENT (font
) - boff
;
24733 font_height
= FONT_HEIGHT (font
);
24735 cmp
->font
= (void *) font
;
24738 if (! font_not_found_p
)
24740 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24742 pcm
= get_per_char_metric (font
, &char2b
);
24745 /* Initialize the bounding box. */
24748 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24749 ascent
= pcm
->ascent
;
24750 descent
= pcm
->descent
;
24751 lbearing
= pcm
->lbearing
;
24752 rbearing
= pcm
->rbearing
;
24756 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24757 ascent
= FONT_BASE (font
);
24758 descent
= FONT_DESCENT (font
);
24765 lowest
= - descent
+ boff
;
24766 highest
= ascent
+ boff
;
24768 if (! font_not_found_p
24769 && font
->default_ascent
24770 && CHAR_TABLE_P (Vuse_default_ascent
)
24771 && !NILP (Faref (Vuse_default_ascent
,
24772 make_number (it
->char_to_display
))))
24773 highest
= font
->default_ascent
+ boff
;
24775 /* Draw the first glyph at the normal position. It may be
24776 shifted to right later if some other glyphs are drawn
24778 cmp
->offsets
[i
* 2] = 0;
24779 cmp
->offsets
[i
* 2 + 1] = boff
;
24780 cmp
->lbearing
= lbearing
;
24781 cmp
->rbearing
= rbearing
;
24783 /* Set cmp->offsets for the remaining glyphs. */
24784 for (i
++; i
< glyph_len
; i
++)
24786 int left
, right
, btm
, top
;
24787 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24789 struct face
*this_face
;
24793 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24794 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24795 font
= this_face
->font
;
24801 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24803 pcm
= get_per_char_metric (font
, &char2b
);
24806 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24809 width
= pcm
->width
;
24810 ascent
= pcm
->ascent
;
24811 descent
= pcm
->descent
;
24812 lbearing
= pcm
->lbearing
;
24813 rbearing
= pcm
->rbearing
;
24814 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24816 /* Relative composition with or without
24817 alternate chars. */
24818 left
= (leftmost
+ rightmost
- width
) / 2;
24819 btm
= - descent
+ boff
;
24820 if (font
->relative_compose
24821 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24822 || NILP (Faref (Vignore_relative_composition
,
24823 make_number (ch
)))))
24826 if (- descent
>= font
->relative_compose
)
24827 /* One extra pixel between two glyphs. */
24829 else if (ascent
<= 0)
24830 /* One extra pixel between two glyphs. */
24831 btm
= lowest
- 1 - ascent
- descent
;
24836 /* A composition rule is specified by an integer
24837 value that encodes global and new reference
24838 points (GREF and NREF). GREF and NREF are
24839 specified by numbers as below:
24841 0---1---2 -- ascent
24845 9--10--11 -- center
24847 ---3---4---5--- baseline
24849 6---7---8 -- descent
24851 int rule
= COMPOSITION_RULE (cmp
, i
);
24852 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24854 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24855 grefx
= gref
% 3, nrefx
= nref
% 3;
24856 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24858 xoff
= font_height
* (xoff
- 128) / 256;
24860 yoff
= font_height
* (yoff
- 128) / 256;
24863 + grefx
* (rightmost
- leftmost
) / 2
24864 - nrefx
* width
/ 2
24867 btm
= ((grefy
== 0 ? highest
24869 : grefy
== 2 ? lowest
24870 : (highest
+ lowest
) / 2)
24871 - (nrefy
== 0 ? ascent
+ descent
24872 : nrefy
== 1 ? descent
- boff
24874 : (ascent
+ descent
) / 2)
24878 cmp
->offsets
[i
* 2] = left
;
24879 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24881 /* Update the bounding box of the overall glyphs. */
24884 right
= left
+ width
;
24885 if (left
< leftmost
)
24887 if (right
> rightmost
)
24890 top
= btm
+ descent
+ ascent
;
24896 if (cmp
->lbearing
> left
+ lbearing
)
24897 cmp
->lbearing
= left
+ lbearing
;
24898 if (cmp
->rbearing
< left
+ rbearing
)
24899 cmp
->rbearing
= left
+ rbearing
;
24903 /* If there are glyphs whose x-offsets are negative,
24904 shift all glyphs to the right and make all x-offsets
24908 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24909 cmp
->offsets
[i
* 2] -= leftmost
;
24910 rightmost
-= leftmost
;
24911 cmp
->lbearing
-= leftmost
;
24912 cmp
->rbearing
-= leftmost
;
24915 if (left_padded
&& cmp
->lbearing
< 0)
24917 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24918 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24919 rightmost
-= cmp
->lbearing
;
24920 cmp
->rbearing
-= cmp
->lbearing
;
24923 if (right_padded
&& rightmost
< cmp
->rbearing
)
24925 rightmost
= cmp
->rbearing
;
24928 cmp
->pixel_width
= rightmost
;
24929 cmp
->ascent
= highest
;
24930 cmp
->descent
= - lowest
;
24931 if (cmp
->ascent
< font_ascent
)
24932 cmp
->ascent
= font_ascent
;
24933 if (cmp
->descent
< font_descent
)
24934 cmp
->descent
= font_descent
;
24938 && (cmp
->lbearing
< 0
24939 || cmp
->rbearing
> cmp
->pixel_width
))
24940 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24942 it
->pixel_width
= cmp
->pixel_width
;
24943 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24944 it
->descent
= it
->phys_descent
= cmp
->descent
;
24945 if (face
->box
!= FACE_NO_BOX
)
24947 int thick
= face
->box_line_width
;
24951 it
->ascent
+= thick
;
24952 it
->descent
+= thick
;
24957 if (it
->start_of_box_run_p
)
24958 it
->pixel_width
+= thick
;
24959 if (it
->end_of_box_run_p
)
24960 it
->pixel_width
+= thick
;
24963 /* If face has an overline, add the height of the overline
24964 (1 pixel) and a 1 pixel margin to the character height. */
24965 if (face
->overline_p
)
24966 it
->ascent
+= overline_margin
;
24968 take_vertical_position_into_account (it
);
24969 if (it
->ascent
< 0)
24971 if (it
->descent
< 0)
24974 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24975 append_composite_glyph (it
);
24977 else if (it
->what
== IT_COMPOSITION
)
24979 /* A dynamic (automatic) composition. */
24980 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24981 Lisp_Object gstring
;
24982 struct font_metrics metrics
;
24986 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24988 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24991 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24992 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24993 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24994 it
->descent
= it
->phys_descent
= metrics
.descent
;
24995 if (face
->box
!= FACE_NO_BOX
)
24997 int thick
= face
->box_line_width
;
25001 it
->ascent
+= thick
;
25002 it
->descent
+= thick
;
25007 if (it
->start_of_box_run_p
)
25008 it
->pixel_width
+= thick
;
25009 if (it
->end_of_box_run_p
)
25010 it
->pixel_width
+= thick
;
25012 /* If face has an overline, add the height of the overline
25013 (1 pixel) and a 1 pixel margin to the character height. */
25014 if (face
->overline_p
)
25015 it
->ascent
+= overline_margin
;
25016 take_vertical_position_into_account (it
);
25017 if (it
->ascent
< 0)
25019 if (it
->descent
< 0)
25023 append_composite_glyph (it
);
25025 else if (it
->what
== IT_GLYPHLESS
)
25026 produce_glyphless_glyph (it
, 0, Qnil
);
25027 else if (it
->what
== IT_IMAGE
)
25028 produce_image_glyph (it
);
25029 else if (it
->what
== IT_STRETCH
)
25030 produce_stretch_glyph (it
);
25033 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25034 because this isn't true for images with `:ascent 100'. */
25035 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25036 if (it
->area
== TEXT_AREA
)
25037 it
->current_x
+= it
->pixel_width
;
25039 if (extra_line_spacing
> 0)
25041 it
->descent
+= extra_line_spacing
;
25042 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25043 it
->max_extra_line_spacing
= extra_line_spacing
;
25046 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25047 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25048 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25049 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25053 Output LEN glyphs starting at START at the nominal cursor position.
25054 Advance the nominal cursor over the text. The global variable
25055 updated_window contains the window being updated, updated_row is
25056 the glyph row being updated, and updated_area is the area of that
25057 row being updated. */
25060 x_write_glyphs (struct glyph
*start
, int len
)
25062 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25064 eassert (updated_window
&& updated_row
);
25065 /* When the window is hscrolled, cursor hpos can legitimately be out
25066 of bounds, but we draw the cursor at the corresponding window
25067 margin in that case. */
25068 if (!updated_row
->reversed_p
&& chpos
< 0)
25070 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25071 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25075 /* Write glyphs. */
25077 hpos
= start
- updated_row
->glyphs
[updated_area
];
25078 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25079 updated_row
, updated_area
,
25081 DRAW_NORMAL_TEXT
, 0);
25083 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25084 if (updated_area
== TEXT_AREA
25085 && updated_window
->phys_cursor_on_p
25086 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25088 && chpos
< hpos
+ len
)
25089 updated_window
->phys_cursor_on_p
= 0;
25093 /* Advance the output cursor. */
25094 output_cursor
.hpos
+= len
;
25095 output_cursor
.x
= x
;
25100 Insert LEN glyphs from START at the nominal cursor position. */
25103 x_insert_glyphs (struct glyph
*start
, int len
)
25107 int line_height
, shift_by_width
, shifted_region_width
;
25108 struct glyph_row
*row
;
25109 struct glyph
*glyph
;
25110 int frame_x
, frame_y
;
25113 eassert (updated_window
&& updated_row
);
25115 w
= updated_window
;
25116 f
= XFRAME (WINDOW_FRAME (w
));
25118 /* Get the height of the line we are in. */
25120 line_height
= row
->height
;
25122 /* Get the width of the glyphs to insert. */
25123 shift_by_width
= 0;
25124 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25125 shift_by_width
+= glyph
->pixel_width
;
25127 /* Get the width of the region to shift right. */
25128 shifted_region_width
= (window_box_width (w
, updated_area
)
25133 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25134 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25136 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25137 line_height
, shift_by_width
);
25139 /* Write the glyphs. */
25140 hpos
= start
- row
->glyphs
[updated_area
];
25141 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25143 DRAW_NORMAL_TEXT
, 0);
25145 /* Advance the output cursor. */
25146 output_cursor
.hpos
+= len
;
25147 output_cursor
.x
+= shift_by_width
;
25153 Erase the current text line from the nominal cursor position
25154 (inclusive) to pixel column TO_X (exclusive). The idea is that
25155 everything from TO_X onward is already erased.
25157 TO_X is a pixel position relative to updated_area of
25158 updated_window. TO_X == -1 means clear to the end of this area. */
25161 x_clear_end_of_line (int to_x
)
25164 struct window
*w
= updated_window
;
25165 int max_x
, min_y
, max_y
;
25166 int from_x
, from_y
, to_y
;
25168 eassert (updated_window
&& updated_row
);
25169 f
= XFRAME (w
->frame
);
25171 if (updated_row
->full_width_p
)
25172 max_x
= WINDOW_TOTAL_WIDTH (w
);
25174 max_x
= window_box_width (w
, updated_area
);
25175 max_y
= window_text_bottom_y (w
);
25177 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25178 of window. For TO_X > 0, truncate to end of drawing area. */
25184 to_x
= min (to_x
, max_x
);
25186 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25188 /* Notice if the cursor will be cleared by this operation. */
25189 if (!updated_row
->full_width_p
)
25190 notice_overwritten_cursor (w
, updated_area
,
25191 output_cursor
.x
, -1,
25193 MATRIX_ROW_BOTTOM_Y (updated_row
));
25195 from_x
= output_cursor
.x
;
25197 /* Translate to frame coordinates. */
25198 if (updated_row
->full_width_p
)
25200 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25201 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25205 int area_left
= window_box_left (w
, updated_area
);
25206 from_x
+= area_left
;
25210 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25211 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25212 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25214 /* Prevent inadvertently clearing to end of the X window. */
25215 if (to_x
> from_x
&& to_y
> from_y
)
25218 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25219 to_x
- from_x
, to_y
- from_y
);
25224 #endif /* HAVE_WINDOW_SYSTEM */
25228 /***********************************************************************
25230 ***********************************************************************/
25232 /* Value is the internal representation of the specified cursor type
25233 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25234 of the bar cursor. */
25236 static enum text_cursor_kinds
25237 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25239 enum text_cursor_kinds type
;
25244 if (EQ (arg
, Qbox
))
25245 return FILLED_BOX_CURSOR
;
25247 if (EQ (arg
, Qhollow
))
25248 return HOLLOW_BOX_CURSOR
;
25250 if (EQ (arg
, Qbar
))
25257 && EQ (XCAR (arg
), Qbar
)
25258 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25260 *width
= XINT (XCDR (arg
));
25264 if (EQ (arg
, Qhbar
))
25267 return HBAR_CURSOR
;
25271 && EQ (XCAR (arg
), Qhbar
)
25272 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25274 *width
= XINT (XCDR (arg
));
25275 return HBAR_CURSOR
;
25278 /* Treat anything unknown as "hollow box cursor".
25279 It was bad to signal an error; people have trouble fixing
25280 .Xdefaults with Emacs, when it has something bad in it. */
25281 type
= HOLLOW_BOX_CURSOR
;
25286 /* Set the default cursor types for specified frame. */
25288 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25293 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25294 FRAME_CURSOR_WIDTH (f
) = width
;
25296 /* By default, set up the blink-off state depending on the on-state. */
25298 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25301 FRAME_BLINK_OFF_CURSOR (f
)
25302 = get_specified_cursor_type (XCDR (tem
), &width
);
25303 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25306 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25310 #ifdef HAVE_WINDOW_SYSTEM
25312 /* Return the cursor we want to be displayed in window W. Return
25313 width of bar/hbar cursor through WIDTH arg. Return with
25314 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25315 (i.e. if the `system caret' should track this cursor).
25317 In a mini-buffer window, we want the cursor only to appear if we
25318 are reading input from this window. For the selected window, we
25319 want the cursor type given by the frame parameter or buffer local
25320 setting of cursor-type. If explicitly marked off, draw no cursor.
25321 In all other cases, we want a hollow box cursor. */
25323 static enum text_cursor_kinds
25324 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25325 int *active_cursor
)
25327 struct frame
*f
= XFRAME (w
->frame
);
25328 struct buffer
*b
= XBUFFER (w
->buffer
);
25329 int cursor_type
= DEFAULT_CURSOR
;
25330 Lisp_Object alt_cursor
;
25331 int non_selected
= 0;
25333 *active_cursor
= 1;
25336 if (cursor_in_echo_area
25337 && FRAME_HAS_MINIBUF_P (f
)
25338 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25340 if (w
== XWINDOW (echo_area_window
))
25342 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25344 *width
= FRAME_CURSOR_WIDTH (f
);
25345 return FRAME_DESIRED_CURSOR (f
);
25348 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25351 *active_cursor
= 0;
25355 /* Detect a nonselected window or nonselected frame. */
25356 else if (w
!= XWINDOW (f
->selected_window
)
25357 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25359 *active_cursor
= 0;
25361 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25367 /* Never display a cursor in a window in which cursor-type is nil. */
25368 if (NILP (BVAR (b
, cursor_type
)))
25371 /* Get the normal cursor type for this window. */
25372 if (EQ (BVAR (b
, cursor_type
), Qt
))
25374 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25375 *width
= FRAME_CURSOR_WIDTH (f
);
25378 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25380 /* Use cursor-in-non-selected-windows instead
25381 for non-selected window or frame. */
25384 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25385 if (!EQ (Qt
, alt_cursor
))
25386 return get_specified_cursor_type (alt_cursor
, width
);
25387 /* t means modify the normal cursor type. */
25388 if (cursor_type
== FILLED_BOX_CURSOR
)
25389 cursor_type
= HOLLOW_BOX_CURSOR
;
25390 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25392 return cursor_type
;
25395 /* Use normal cursor if not blinked off. */
25396 if (!w
->cursor_off_p
)
25398 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25400 if (cursor_type
== FILLED_BOX_CURSOR
)
25402 /* Using a block cursor on large images can be very annoying.
25403 So use a hollow cursor for "large" images.
25404 If image is not transparent (no mask), also use hollow cursor. */
25405 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25406 if (img
!= NULL
&& IMAGEP (img
->spec
))
25408 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25409 where N = size of default frame font size.
25410 This should cover most of the "tiny" icons people may use. */
25412 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25413 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25414 cursor_type
= HOLLOW_BOX_CURSOR
;
25417 else if (cursor_type
!= NO_CURSOR
)
25419 /* Display current only supports BOX and HOLLOW cursors for images.
25420 So for now, unconditionally use a HOLLOW cursor when cursor is
25421 not a solid box cursor. */
25422 cursor_type
= HOLLOW_BOX_CURSOR
;
25425 return cursor_type
;
25428 /* Cursor is blinked off, so determine how to "toggle" it. */
25430 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25431 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25432 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25434 /* Then see if frame has specified a specific blink off cursor type. */
25435 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25437 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25438 return FRAME_BLINK_OFF_CURSOR (f
);
25442 /* Some people liked having a permanently visible blinking cursor,
25443 while others had very strong opinions against it. So it was
25444 decided to remove it. KFS 2003-09-03 */
25446 /* Finally perform built-in cursor blinking:
25447 filled box <-> hollow box
25448 wide [h]bar <-> narrow [h]bar
25449 narrow [h]bar <-> no cursor
25450 other type <-> no cursor */
25452 if (cursor_type
== FILLED_BOX_CURSOR
)
25453 return HOLLOW_BOX_CURSOR
;
25455 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25458 return cursor_type
;
25466 /* Notice when the text cursor of window W has been completely
25467 overwritten by a drawing operation that outputs glyphs in AREA
25468 starting at X0 and ending at X1 in the line starting at Y0 and
25469 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25470 the rest of the line after X0 has been written. Y coordinates
25471 are window-relative. */
25474 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25475 int x0
, int x1
, int y0
, int y1
)
25477 int cx0
, cx1
, cy0
, cy1
;
25478 struct glyph_row
*row
;
25480 if (!w
->phys_cursor_on_p
)
25482 if (area
!= TEXT_AREA
)
25485 if (w
->phys_cursor
.vpos
< 0
25486 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25487 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25488 !(row
->enabled_p
&& row
->displays_text_p
)))
25491 if (row
->cursor_in_fringe_p
)
25493 row
->cursor_in_fringe_p
= 0;
25494 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25495 w
->phys_cursor_on_p
= 0;
25499 cx0
= w
->phys_cursor
.x
;
25500 cx1
= cx0
+ w
->phys_cursor_width
;
25501 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25504 /* The cursor image will be completely removed from the
25505 screen if the output area intersects the cursor area in
25506 y-direction. When we draw in [y0 y1[, and some part of
25507 the cursor is at y < y0, that part must have been drawn
25508 before. When scrolling, the cursor is erased before
25509 actually scrolling, so we don't come here. When not
25510 scrolling, the rows above the old cursor row must have
25511 changed, and in this case these rows must have written
25512 over the cursor image.
25514 Likewise if part of the cursor is below y1, with the
25515 exception of the cursor being in the first blank row at
25516 the buffer and window end because update_text_area
25517 doesn't draw that row. (Except when it does, but
25518 that's handled in update_text_area.) */
25520 cy0
= w
->phys_cursor
.y
;
25521 cy1
= cy0
+ w
->phys_cursor_height
;
25522 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25525 w
->phys_cursor_on_p
= 0;
25528 #endif /* HAVE_WINDOW_SYSTEM */
25531 /************************************************************************
25533 ************************************************************************/
25535 #ifdef HAVE_WINDOW_SYSTEM
25538 Fix the display of area AREA of overlapping row ROW in window W
25539 with respect to the overlapping part OVERLAPS. */
25542 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25543 enum glyph_row_area area
, int overlaps
)
25550 for (i
= 0; i
< row
->used
[area
];)
25552 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25554 int start
= i
, start_x
= x
;
25558 x
+= row
->glyphs
[area
][i
].pixel_width
;
25561 while (i
< row
->used
[area
]
25562 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25564 draw_glyphs (w
, start_x
, row
, area
,
25566 DRAW_NORMAL_TEXT
, overlaps
);
25570 x
+= row
->glyphs
[area
][i
].pixel_width
;
25580 Draw the cursor glyph of window W in glyph row ROW. See the
25581 comment of draw_glyphs for the meaning of HL. */
25584 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25585 enum draw_glyphs_face hl
)
25587 /* If cursor hpos is out of bounds, don't draw garbage. This can
25588 happen in mini-buffer windows when switching between echo area
25589 glyphs and mini-buffer. */
25590 if ((row
->reversed_p
25591 ? (w
->phys_cursor
.hpos
>= 0)
25592 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25594 int on_p
= w
->phys_cursor_on_p
;
25596 int hpos
= w
->phys_cursor
.hpos
;
25598 /* When the window is hscrolled, cursor hpos can legitimately be
25599 out of bounds, but we draw the cursor at the corresponding
25600 window margin in that case. */
25601 if (!row
->reversed_p
&& hpos
< 0)
25603 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25604 hpos
= row
->used
[TEXT_AREA
] - 1;
25606 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25608 w
->phys_cursor_on_p
= on_p
;
25610 if (hl
== DRAW_CURSOR
)
25611 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25612 /* When we erase the cursor, and ROW is overlapped by other
25613 rows, make sure that these overlapping parts of other rows
25615 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25617 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25619 if (row
> w
->current_matrix
->rows
25620 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25621 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25622 OVERLAPS_ERASED_CURSOR
);
25624 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25625 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25626 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25627 OVERLAPS_ERASED_CURSOR
);
25634 Erase the image of a cursor of window W from the screen. */
25637 erase_phys_cursor (struct window
*w
)
25639 struct frame
*f
= XFRAME (w
->frame
);
25640 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25641 int hpos
= w
->phys_cursor
.hpos
;
25642 int vpos
= w
->phys_cursor
.vpos
;
25643 int mouse_face_here_p
= 0;
25644 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25645 struct glyph_row
*cursor_row
;
25646 struct glyph
*cursor_glyph
;
25647 enum draw_glyphs_face hl
;
25649 /* No cursor displayed or row invalidated => nothing to do on the
25651 if (w
->phys_cursor_type
== NO_CURSOR
)
25652 goto mark_cursor_off
;
25654 /* VPOS >= active_glyphs->nrows means that window has been resized.
25655 Don't bother to erase the cursor. */
25656 if (vpos
>= active_glyphs
->nrows
)
25657 goto mark_cursor_off
;
25659 /* If row containing cursor is marked invalid, there is nothing we
25661 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25662 if (!cursor_row
->enabled_p
)
25663 goto mark_cursor_off
;
25665 /* If line spacing is > 0, old cursor may only be partially visible in
25666 window after split-window. So adjust visible height. */
25667 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25668 window_text_bottom_y (w
) - cursor_row
->y
);
25670 /* If row is completely invisible, don't attempt to delete a cursor which
25671 isn't there. This can happen if cursor is at top of a window, and
25672 we switch to a buffer with a header line in that window. */
25673 if (cursor_row
->visible_height
<= 0)
25674 goto mark_cursor_off
;
25676 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25677 if (cursor_row
->cursor_in_fringe_p
)
25679 cursor_row
->cursor_in_fringe_p
= 0;
25680 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25681 goto mark_cursor_off
;
25684 /* This can happen when the new row is shorter than the old one.
25685 In this case, either draw_glyphs or clear_end_of_line
25686 should have cleared the cursor. Note that we wouldn't be
25687 able to erase the cursor in this case because we don't have a
25688 cursor glyph at hand. */
25689 if ((cursor_row
->reversed_p
25690 ? (w
->phys_cursor
.hpos
< 0)
25691 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25692 goto mark_cursor_off
;
25694 /* When the window is hscrolled, cursor hpos can legitimately be out
25695 of bounds, but we draw the cursor at the corresponding window
25696 margin in that case. */
25697 if (!cursor_row
->reversed_p
&& hpos
< 0)
25699 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25700 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25702 /* If the cursor is in the mouse face area, redisplay that when
25703 we clear the cursor. */
25704 if (! NILP (hlinfo
->mouse_face_window
)
25705 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25706 /* Don't redraw the cursor's spot in mouse face if it is at the
25707 end of a line (on a newline). The cursor appears there, but
25708 mouse highlighting does not. */
25709 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25710 mouse_face_here_p
= 1;
25712 /* Maybe clear the display under the cursor. */
25713 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25716 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25719 cursor_glyph
= get_phys_cursor_glyph (w
);
25720 if (cursor_glyph
== NULL
)
25721 goto mark_cursor_off
;
25723 width
= cursor_glyph
->pixel_width
;
25724 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25725 x
= w
->phys_cursor
.x
;
25727 width
-= left_x
- x
;
25728 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25729 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25730 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25733 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25736 /* Erase the cursor by redrawing the character underneath it. */
25737 if (mouse_face_here_p
)
25738 hl
= DRAW_MOUSE_FACE
;
25740 hl
= DRAW_NORMAL_TEXT
;
25741 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25744 w
->phys_cursor_on_p
= 0;
25745 w
->phys_cursor_type
= NO_CURSOR
;
25750 Display or clear cursor of window W. If ON is zero, clear the
25751 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25752 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25755 display_and_set_cursor (struct window
*w
, int on
,
25756 int hpos
, int vpos
, int x
, int y
)
25758 struct frame
*f
= XFRAME (w
->frame
);
25759 int new_cursor_type
;
25760 int new_cursor_width
;
25762 struct glyph_row
*glyph_row
;
25763 struct glyph
*glyph
;
25765 /* This is pointless on invisible frames, and dangerous on garbaged
25766 windows and frames; in the latter case, the frame or window may
25767 be in the midst of changing its size, and x and y may be off the
25769 if (! FRAME_VISIBLE_P (f
)
25770 || FRAME_GARBAGED_P (f
)
25771 || vpos
>= w
->current_matrix
->nrows
25772 || hpos
>= w
->current_matrix
->matrix_w
)
25775 /* If cursor is off and we want it off, return quickly. */
25776 if (!on
&& !w
->phys_cursor_on_p
)
25779 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25780 /* If cursor row is not enabled, we don't really know where to
25781 display the cursor. */
25782 if (!glyph_row
->enabled_p
)
25784 w
->phys_cursor_on_p
= 0;
25789 if (!glyph_row
->exact_window_width_line_p
25790 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25791 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25793 eassert (interrupt_input_blocked
);
25795 /* Set new_cursor_type to the cursor we want to be displayed. */
25796 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25797 &new_cursor_width
, &active_cursor
);
25799 /* If cursor is currently being shown and we don't want it to be or
25800 it is in the wrong place, or the cursor type is not what we want,
25802 if (w
->phys_cursor_on_p
25804 || w
->phys_cursor
.x
!= x
25805 || w
->phys_cursor
.y
!= y
25806 || new_cursor_type
!= w
->phys_cursor_type
25807 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25808 && new_cursor_width
!= w
->phys_cursor_width
)))
25809 erase_phys_cursor (w
);
25811 /* Don't check phys_cursor_on_p here because that flag is only set
25812 to zero in some cases where we know that the cursor has been
25813 completely erased, to avoid the extra work of erasing the cursor
25814 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25815 still not be visible, or it has only been partly erased. */
25818 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25819 w
->phys_cursor_height
= glyph_row
->height
;
25821 /* Set phys_cursor_.* before x_draw_.* is called because some
25822 of them may need the information. */
25823 w
->phys_cursor
.x
= x
;
25824 w
->phys_cursor
.y
= glyph_row
->y
;
25825 w
->phys_cursor
.hpos
= hpos
;
25826 w
->phys_cursor
.vpos
= vpos
;
25829 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25830 new_cursor_type
, new_cursor_width
,
25831 on
, active_cursor
);
25835 /* Switch the display of W's cursor on or off, according to the value
25839 update_window_cursor (struct window
*w
, int on
)
25841 /* Don't update cursor in windows whose frame is in the process
25842 of being deleted. */
25843 if (w
->current_matrix
)
25845 int hpos
= w
->phys_cursor
.hpos
;
25846 int vpos
= w
->phys_cursor
.vpos
;
25847 struct glyph_row
*row
;
25849 if (vpos
>= w
->current_matrix
->nrows
25850 || hpos
>= w
->current_matrix
->matrix_w
)
25853 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25855 /* When the window is hscrolled, cursor hpos can legitimately be
25856 out of bounds, but we draw the cursor at the corresponding
25857 window margin in that case. */
25858 if (!row
->reversed_p
&& hpos
< 0)
25860 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25861 hpos
= row
->used
[TEXT_AREA
] - 1;
25864 display_and_set_cursor (w
, on
, hpos
, vpos
,
25865 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25871 /* Call update_window_cursor with parameter ON_P on all leaf windows
25872 in the window tree rooted at W. */
25875 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25879 if (!NILP (w
->hchild
))
25880 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25881 else if (!NILP (w
->vchild
))
25882 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25884 update_window_cursor (w
, on_p
);
25886 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25892 Display the cursor on window W, or clear it, according to ON_P.
25893 Don't change the cursor's position. */
25896 x_update_cursor (struct frame
*f
, int on_p
)
25898 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25903 Clear the cursor of window W to background color, and mark the
25904 cursor as not shown. This is used when the text where the cursor
25905 is about to be rewritten. */
25908 x_clear_cursor (struct window
*w
)
25910 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25911 update_window_cursor (w
, 0);
25914 #endif /* HAVE_WINDOW_SYSTEM */
25916 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25919 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25920 int start_hpos
, int end_hpos
,
25921 enum draw_glyphs_face draw
)
25923 #ifdef HAVE_WINDOW_SYSTEM
25924 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25926 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25930 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
25931 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25935 /* Display the active region described by mouse_face_* according to DRAW. */
25938 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25940 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25941 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25943 if (/* If window is in the process of being destroyed, don't bother
25945 w
->current_matrix
!= NULL
25946 /* Don't update mouse highlight if hidden */
25947 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25948 /* Recognize when we are called to operate on rows that don't exist
25949 anymore. This can happen when a window is split. */
25950 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25952 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25953 struct glyph_row
*row
, *first
, *last
;
25955 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25956 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25958 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25960 int start_hpos
, end_hpos
, start_x
;
25962 /* For all but the first row, the highlight starts at column 0. */
25965 /* R2L rows have BEG and END in reversed order, but the
25966 screen drawing geometry is always left to right. So
25967 we need to mirror the beginning and end of the
25968 highlighted area in R2L rows. */
25969 if (!row
->reversed_p
)
25971 start_hpos
= hlinfo
->mouse_face_beg_col
;
25972 start_x
= hlinfo
->mouse_face_beg_x
;
25974 else if (row
== last
)
25976 start_hpos
= hlinfo
->mouse_face_end_col
;
25977 start_x
= hlinfo
->mouse_face_end_x
;
25985 else if (row
->reversed_p
&& row
== last
)
25987 start_hpos
= hlinfo
->mouse_face_end_col
;
25988 start_x
= hlinfo
->mouse_face_end_x
;
25998 if (!row
->reversed_p
)
25999 end_hpos
= hlinfo
->mouse_face_end_col
;
26000 else if (row
== first
)
26001 end_hpos
= hlinfo
->mouse_face_beg_col
;
26004 end_hpos
= row
->used
[TEXT_AREA
];
26005 if (draw
== DRAW_NORMAL_TEXT
)
26006 row
->fill_line_p
= 1; /* Clear to end of line */
26009 else if (row
->reversed_p
&& row
== first
)
26010 end_hpos
= hlinfo
->mouse_face_beg_col
;
26013 end_hpos
= row
->used
[TEXT_AREA
];
26014 if (draw
== DRAW_NORMAL_TEXT
)
26015 row
->fill_line_p
= 1; /* Clear to end of line */
26018 if (end_hpos
> start_hpos
)
26020 draw_row_with_mouse_face (w
, start_x
, row
,
26021 start_hpos
, end_hpos
, draw
);
26024 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26028 #ifdef HAVE_WINDOW_SYSTEM
26029 /* When we've written over the cursor, arrange for it to
26030 be displayed again. */
26031 if (FRAME_WINDOW_P (f
)
26032 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26034 int hpos
= w
->phys_cursor
.hpos
;
26036 /* When the window is hscrolled, cursor hpos can legitimately be
26037 out of bounds, but we draw the cursor at the corresponding
26038 window margin in that case. */
26039 if (!row
->reversed_p
&& hpos
< 0)
26041 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26042 hpos
= row
->used
[TEXT_AREA
] - 1;
26045 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26046 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26049 #endif /* HAVE_WINDOW_SYSTEM */
26052 #ifdef HAVE_WINDOW_SYSTEM
26053 /* Change the mouse cursor. */
26054 if (FRAME_WINDOW_P (f
))
26056 if (draw
== DRAW_NORMAL_TEXT
26057 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26058 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26059 else if (draw
== DRAW_MOUSE_FACE
)
26060 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26062 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26064 #endif /* HAVE_WINDOW_SYSTEM */
26068 Clear out the mouse-highlighted active region.
26069 Redraw it un-highlighted first. Value is non-zero if mouse
26070 face was actually drawn unhighlighted. */
26073 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26077 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26079 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26083 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26084 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26085 hlinfo
->mouse_face_window
= Qnil
;
26086 hlinfo
->mouse_face_overlay
= Qnil
;
26090 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26091 within the mouse face on that window. */
26093 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26095 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26097 /* Quickly resolve the easy cases. */
26098 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26099 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26101 if (vpos
< hlinfo
->mouse_face_beg_row
26102 || vpos
> hlinfo
->mouse_face_end_row
)
26104 if (vpos
> hlinfo
->mouse_face_beg_row
26105 && vpos
< hlinfo
->mouse_face_end_row
)
26108 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26110 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26112 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26115 else if ((vpos
== hlinfo
->mouse_face_beg_row
26116 && hpos
>= hlinfo
->mouse_face_beg_col
)
26117 || (vpos
== hlinfo
->mouse_face_end_row
26118 && hpos
< hlinfo
->mouse_face_end_col
))
26123 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26125 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26128 else if ((vpos
== hlinfo
->mouse_face_beg_row
26129 && hpos
<= hlinfo
->mouse_face_beg_col
)
26130 || (vpos
== hlinfo
->mouse_face_end_row
26131 && hpos
> hlinfo
->mouse_face_end_col
))
26139 Non-zero if physical cursor of window W is within mouse face. */
26142 cursor_in_mouse_face_p (struct window
*w
)
26144 int hpos
= w
->phys_cursor
.hpos
;
26145 int vpos
= w
->phys_cursor
.vpos
;
26146 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26148 /* When the window is hscrolled, cursor hpos can legitimately be out
26149 of bounds, but we draw the cursor at the corresponding window
26150 margin in that case. */
26151 if (!row
->reversed_p
&& hpos
< 0)
26153 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26154 hpos
= row
->used
[TEXT_AREA
] - 1;
26156 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26161 /* Find the glyph rows START_ROW and END_ROW of window W that display
26162 characters between buffer positions START_CHARPOS and END_CHARPOS
26163 (excluding END_CHARPOS). DISP_STRING is a display string that
26164 covers these buffer positions. This is similar to
26165 row_containing_pos, but is more accurate when bidi reordering makes
26166 buffer positions change non-linearly with glyph rows. */
26168 rows_from_pos_range (struct window
*w
,
26169 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26170 Lisp_Object disp_string
,
26171 struct glyph_row
**start
, struct glyph_row
**end
)
26173 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26174 int last_y
= window_text_bottom_y (w
);
26175 struct glyph_row
*row
;
26180 while (!first
->enabled_p
26181 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26184 /* Find the START row. */
26186 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26189 /* A row can potentially be the START row if the range of the
26190 characters it displays intersects the range
26191 [START_CHARPOS..END_CHARPOS). */
26192 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26193 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26194 /* See the commentary in row_containing_pos, for the
26195 explanation of the complicated way to check whether
26196 some position is beyond the end of the characters
26197 displayed by a row. */
26198 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26199 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26200 && !row
->ends_at_zv_p
26201 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26202 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26203 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26204 && !row
->ends_at_zv_p
26205 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26207 /* Found a candidate row. Now make sure at least one of the
26208 glyphs it displays has a charpos from the range
26209 [START_CHARPOS..END_CHARPOS).
26211 This is not obvious because bidi reordering could make
26212 buffer positions of a row be 1,2,3,102,101,100, and if we
26213 want to highlight characters in [50..60), we don't want
26214 this row, even though [50..60) does intersect [1..103),
26215 the range of character positions given by the row's start
26216 and end positions. */
26217 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26218 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26222 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26223 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26224 /* A glyph that comes from DISP_STRING is by
26225 definition to be highlighted. */
26226 || EQ (g
->object
, disp_string
))
26235 /* Find the END row. */
26237 /* If the last row is partially visible, start looking for END
26238 from that row, instead of starting from FIRST. */
26239 && !(row
->enabled_p
26240 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26242 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26244 struct glyph_row
*next
= row
+ 1;
26245 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26247 if (!next
->enabled_p
26248 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26249 /* The first row >= START whose range of displayed characters
26250 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26251 is the row END + 1. */
26252 || (start_charpos
< next_start
26253 && end_charpos
< next_start
)
26254 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26255 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26256 && !next
->ends_at_zv_p
26257 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26258 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26259 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26260 && !next
->ends_at_zv_p
26261 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26268 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26269 but none of the characters it displays are in the range, it is
26271 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26272 struct glyph
*s
= g
;
26273 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26277 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26278 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26279 /* If the buffer position of the first glyph in
26280 the row is equal to END_CHARPOS, it means
26281 the last character to be highlighted is the
26282 newline of ROW, and we must consider NEXT as
26284 || (((!next
->reversed_p
&& g
== s
)
26285 || (next
->reversed_p
&& g
== e
- 1))
26286 && (g
->charpos
== end_charpos
26287 /* Special case for when NEXT is an
26288 empty line at ZV. */
26289 || (g
->charpos
== -1
26290 && !row
->ends_at_zv_p
26291 && next_start
== end_charpos
)))))
26292 /* A glyph that comes from DISP_STRING is by
26293 definition to be highlighted. */
26294 || EQ (g
->object
, disp_string
))
26303 /* The first row that ends at ZV must be the last to be
26305 else if (next
->ends_at_zv_p
)
26314 /* This function sets the mouse_face_* elements of HLINFO, assuming
26315 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26316 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26317 for the overlay or run of text properties specifying the mouse
26318 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26319 before-string and after-string that must also be highlighted.
26320 DISP_STRING, if non-nil, is a display string that may cover some
26321 or all of the highlighted text. */
26324 mouse_face_from_buffer_pos (Lisp_Object window
,
26325 Mouse_HLInfo
*hlinfo
,
26326 ptrdiff_t mouse_charpos
,
26327 ptrdiff_t start_charpos
,
26328 ptrdiff_t end_charpos
,
26329 Lisp_Object before_string
,
26330 Lisp_Object after_string
,
26331 Lisp_Object disp_string
)
26333 struct window
*w
= XWINDOW (window
);
26334 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26335 struct glyph_row
*r1
, *r2
;
26336 struct glyph
*glyph
, *end
;
26337 ptrdiff_t ignore
, pos
;
26340 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26341 eassert (NILP (before_string
) || STRINGP (before_string
));
26342 eassert (NILP (after_string
) || STRINGP (after_string
));
26344 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26345 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26347 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26348 /* If the before-string or display-string contains newlines,
26349 rows_from_pos_range skips to its last row. Move back. */
26350 if (!NILP (before_string
) || !NILP (disp_string
))
26352 struct glyph_row
*prev
;
26353 while ((prev
= r1
- 1, prev
>= first
)
26354 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26355 && prev
->used
[TEXT_AREA
] > 0)
26357 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26358 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26359 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26361 || !(EQ (glyph
->object
, before_string
)
26362 || EQ (glyph
->object
, disp_string
)))
26369 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26370 hlinfo
->mouse_face_past_end
= 1;
26372 else if (!NILP (after_string
))
26374 /* If the after-string has newlines, advance to its last row. */
26375 struct glyph_row
*next
;
26376 struct glyph_row
*last
26377 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26379 for (next
= r2
+ 1;
26381 && next
->used
[TEXT_AREA
] > 0
26382 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26386 /* The rest of the display engine assumes that mouse_face_beg_row is
26387 either above mouse_face_end_row or identical to it. But with
26388 bidi-reordered continued lines, the row for START_CHARPOS could
26389 be below the row for END_CHARPOS. If so, swap the rows and store
26390 them in correct order. */
26393 struct glyph_row
*tem
= r2
;
26399 hlinfo
->mouse_face_beg_y
= r1
->y
;
26400 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26401 hlinfo
->mouse_face_end_y
= r2
->y
;
26402 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26404 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26405 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26406 could be anywhere in the row and in any order. The strategy
26407 below is to find the leftmost and the rightmost glyph that
26408 belongs to either of these 3 strings, or whose position is
26409 between START_CHARPOS and END_CHARPOS, and highlight all the
26410 glyphs between those two. This may cover more than just the text
26411 between START_CHARPOS and END_CHARPOS if the range of characters
26412 strides the bidi level boundary, e.g. if the beginning is in R2L
26413 text while the end is in L2R text or vice versa. */
26414 if (!r1
->reversed_p
)
26416 /* This row is in a left to right paragraph. Scan it left to
26418 glyph
= r1
->glyphs
[TEXT_AREA
];
26419 end
= glyph
+ r1
->used
[TEXT_AREA
];
26422 /* Skip truncation glyphs at the start of the glyph row. */
26423 if (r1
->displays_text_p
)
26425 && INTEGERP (glyph
->object
)
26426 && glyph
->charpos
< 0;
26428 x
+= glyph
->pixel_width
;
26430 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26431 or DISP_STRING, and the first glyph from buffer whose
26432 position is between START_CHARPOS and END_CHARPOS. */
26434 && !INTEGERP (glyph
->object
)
26435 && !EQ (glyph
->object
, disp_string
)
26436 && !(BUFFERP (glyph
->object
)
26437 && (glyph
->charpos
>= start_charpos
26438 && glyph
->charpos
< end_charpos
));
26441 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26442 are present at buffer positions between START_CHARPOS and
26443 END_CHARPOS, or if they come from an overlay. */
26444 if (EQ (glyph
->object
, before_string
))
26446 pos
= string_buffer_position (before_string
,
26448 /* If pos == 0, it means before_string came from an
26449 overlay, not from a buffer position. */
26450 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26453 else if (EQ (glyph
->object
, after_string
))
26455 pos
= string_buffer_position (after_string
, end_charpos
);
26456 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26459 x
+= glyph
->pixel_width
;
26461 hlinfo
->mouse_face_beg_x
= x
;
26462 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26466 /* This row is in a right to left paragraph. Scan it right to
26470 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26471 glyph
= end
+ r1
->used
[TEXT_AREA
];
26473 /* Skip truncation glyphs at the start of the glyph row. */
26474 if (r1
->displays_text_p
)
26476 && INTEGERP (glyph
->object
)
26477 && glyph
->charpos
< 0;
26481 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26482 or DISP_STRING, and the first glyph from buffer whose
26483 position is between START_CHARPOS and END_CHARPOS. */
26485 && !INTEGERP (glyph
->object
)
26486 && !EQ (glyph
->object
, disp_string
)
26487 && !(BUFFERP (glyph
->object
)
26488 && (glyph
->charpos
>= start_charpos
26489 && glyph
->charpos
< end_charpos
));
26492 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26493 are present at buffer positions between START_CHARPOS and
26494 END_CHARPOS, or if they come from an overlay. */
26495 if (EQ (glyph
->object
, before_string
))
26497 pos
= string_buffer_position (before_string
, start_charpos
);
26498 /* If pos == 0, it means before_string came from an
26499 overlay, not from a buffer position. */
26500 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26503 else if (EQ (glyph
->object
, after_string
))
26505 pos
= string_buffer_position (after_string
, end_charpos
);
26506 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26511 glyph
++; /* first glyph to the right of the highlighted area */
26512 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26513 x
+= g
->pixel_width
;
26514 hlinfo
->mouse_face_beg_x
= x
;
26515 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26518 /* If the highlight ends in a different row, compute GLYPH and END
26519 for the end row. Otherwise, reuse the values computed above for
26520 the row where the highlight begins. */
26523 if (!r2
->reversed_p
)
26525 glyph
= r2
->glyphs
[TEXT_AREA
];
26526 end
= glyph
+ r2
->used
[TEXT_AREA
];
26531 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26532 glyph
= end
+ r2
->used
[TEXT_AREA
];
26536 if (!r2
->reversed_p
)
26538 /* Skip truncation and continuation glyphs near the end of the
26539 row, and also blanks and stretch glyphs inserted by
26540 extend_face_to_end_of_line. */
26542 && INTEGERP ((end
- 1)->object
))
26544 /* Scan the rest of the glyph row from the end, looking for the
26545 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26546 DISP_STRING, or whose position is between START_CHARPOS
26550 && !INTEGERP (end
->object
)
26551 && !EQ (end
->object
, disp_string
)
26552 && !(BUFFERP (end
->object
)
26553 && (end
->charpos
>= start_charpos
26554 && end
->charpos
< end_charpos
));
26557 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26558 are present at buffer positions between START_CHARPOS and
26559 END_CHARPOS, or if they come from an overlay. */
26560 if (EQ (end
->object
, before_string
))
26562 pos
= string_buffer_position (before_string
, start_charpos
);
26563 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26566 else if (EQ (end
->object
, after_string
))
26568 pos
= string_buffer_position (after_string
, end_charpos
);
26569 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26573 /* Find the X coordinate of the last glyph to be highlighted. */
26574 for (; glyph
<= end
; ++glyph
)
26575 x
+= glyph
->pixel_width
;
26577 hlinfo
->mouse_face_end_x
= x
;
26578 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26582 /* Skip truncation and continuation glyphs near the end of the
26583 row, and also blanks and stretch glyphs inserted by
26584 extend_face_to_end_of_line. */
26588 && INTEGERP (end
->object
))
26590 x
+= end
->pixel_width
;
26593 /* Scan the rest of the glyph row from the end, looking for the
26594 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26595 DISP_STRING, or whose position is between START_CHARPOS
26599 && !INTEGERP (end
->object
)
26600 && !EQ (end
->object
, disp_string
)
26601 && !(BUFFERP (end
->object
)
26602 && (end
->charpos
>= start_charpos
26603 && end
->charpos
< end_charpos
));
26606 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26607 are present at buffer positions between START_CHARPOS and
26608 END_CHARPOS, or if they come from an overlay. */
26609 if (EQ (end
->object
, before_string
))
26611 pos
= string_buffer_position (before_string
, start_charpos
);
26612 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26615 else if (EQ (end
->object
, after_string
))
26617 pos
= string_buffer_position (after_string
, end_charpos
);
26618 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26621 x
+= end
->pixel_width
;
26623 /* If we exited the above loop because we arrived at the last
26624 glyph of the row, and its buffer position is still not in
26625 range, it means the last character in range is the preceding
26626 newline. Bump the end column and x values to get past the
26629 && BUFFERP (end
->object
)
26630 && (end
->charpos
< start_charpos
26631 || end
->charpos
>= end_charpos
))
26633 x
+= end
->pixel_width
;
26636 hlinfo
->mouse_face_end_x
= x
;
26637 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26640 hlinfo
->mouse_face_window
= window
;
26641 hlinfo
->mouse_face_face_id
26642 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26644 !hlinfo
->mouse_face_hidden
, -1);
26645 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26648 /* The following function is not used anymore (replaced with
26649 mouse_face_from_string_pos), but I leave it here for the time
26650 being, in case someone would. */
26652 #if 0 /* not used */
26654 /* Find the position of the glyph for position POS in OBJECT in
26655 window W's current matrix, and return in *X, *Y the pixel
26656 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26658 RIGHT_P non-zero means return the position of the right edge of the
26659 glyph, RIGHT_P zero means return the left edge position.
26661 If no glyph for POS exists in the matrix, return the position of
26662 the glyph with the next smaller position that is in the matrix, if
26663 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26664 exists in the matrix, return the position of the glyph with the
26665 next larger position in OBJECT.
26667 Value is non-zero if a glyph was found. */
26670 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26671 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26673 int yb
= window_text_bottom_y (w
);
26674 struct glyph_row
*r
;
26675 struct glyph
*best_glyph
= NULL
;
26676 struct glyph_row
*best_row
= NULL
;
26679 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26680 r
->enabled_p
&& r
->y
< yb
;
26683 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26684 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26687 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26688 if (EQ (g
->object
, object
))
26690 if (g
->charpos
== pos
)
26697 else if (best_glyph
== NULL
26698 || ((eabs (g
->charpos
- pos
)
26699 < eabs (best_glyph
->charpos
- pos
))
26702 : g
->charpos
> pos
)))
26716 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26720 *x
+= best_glyph
->pixel_width
;
26725 *vpos
= best_row
- w
->current_matrix
->rows
;
26728 return best_glyph
!= NULL
;
26730 #endif /* not used */
26732 /* Find the positions of the first and the last glyphs in window W's
26733 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26734 (assumed to be a string), and return in HLINFO's mouse_face_*
26735 members the pixel and column/row coordinates of those glyphs. */
26738 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26739 Lisp_Object object
,
26740 ptrdiff_t startpos
, ptrdiff_t endpos
)
26742 int yb
= window_text_bottom_y (w
);
26743 struct glyph_row
*r
;
26744 struct glyph
*g
, *e
;
26748 /* Find the glyph row with at least one position in the range
26749 [STARTPOS..ENDPOS], and the first glyph in that row whose
26750 position belongs to that range. */
26751 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26752 r
->enabled_p
&& r
->y
< yb
;
26755 if (!r
->reversed_p
)
26757 g
= r
->glyphs
[TEXT_AREA
];
26758 e
= g
+ r
->used
[TEXT_AREA
];
26759 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26760 if (EQ (g
->object
, object
)
26761 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26763 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26764 hlinfo
->mouse_face_beg_y
= r
->y
;
26765 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26766 hlinfo
->mouse_face_beg_x
= gx
;
26775 e
= r
->glyphs
[TEXT_AREA
];
26776 g
= e
+ r
->used
[TEXT_AREA
];
26777 for ( ; g
> e
; --g
)
26778 if (EQ ((g
-1)->object
, object
)
26779 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26781 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26782 hlinfo
->mouse_face_beg_y
= r
->y
;
26783 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26784 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26785 gx
+= g1
->pixel_width
;
26786 hlinfo
->mouse_face_beg_x
= gx
;
26798 /* Starting with the next row, look for the first row which does NOT
26799 include any glyphs whose positions are in the range. */
26800 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26802 g
= r
->glyphs
[TEXT_AREA
];
26803 e
= g
+ r
->used
[TEXT_AREA
];
26805 for ( ; g
< e
; ++g
)
26806 if (EQ (g
->object
, object
)
26807 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26816 /* The highlighted region ends on the previous row. */
26819 /* Set the end row and its vertical pixel coordinate. */
26820 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26821 hlinfo
->mouse_face_end_y
= r
->y
;
26823 /* Compute and set the end column and the end column's horizontal
26824 pixel coordinate. */
26825 if (!r
->reversed_p
)
26827 g
= r
->glyphs
[TEXT_AREA
];
26828 e
= g
+ r
->used
[TEXT_AREA
];
26829 for ( ; e
> g
; --e
)
26830 if (EQ ((e
-1)->object
, object
)
26831 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26833 hlinfo
->mouse_face_end_col
= e
- g
;
26835 for (gx
= r
->x
; g
< e
; ++g
)
26836 gx
+= g
->pixel_width
;
26837 hlinfo
->mouse_face_end_x
= gx
;
26841 e
= r
->glyphs
[TEXT_AREA
];
26842 g
= e
+ r
->used
[TEXT_AREA
];
26843 for (gx
= r
->x
; e
< g
; ++e
)
26845 if (EQ (e
->object
, object
)
26846 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26848 gx
+= e
->pixel_width
;
26850 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26851 hlinfo
->mouse_face_end_x
= gx
;
26855 #ifdef HAVE_WINDOW_SYSTEM
26857 /* See if position X, Y is within a hot-spot of an image. */
26860 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26862 if (!CONSP (hot_spot
))
26865 if (EQ (XCAR (hot_spot
), Qrect
))
26867 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26868 Lisp_Object rect
= XCDR (hot_spot
);
26872 if (!CONSP (XCAR (rect
)))
26874 if (!CONSP (XCDR (rect
)))
26876 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26878 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26880 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26882 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26886 else if (EQ (XCAR (hot_spot
), Qcircle
))
26888 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26889 Lisp_Object circ
= XCDR (hot_spot
);
26890 Lisp_Object lr
, lx0
, ly0
;
26892 && CONSP (XCAR (circ
))
26893 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26894 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26895 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26897 double r
= XFLOATINT (lr
);
26898 double dx
= XINT (lx0
) - x
;
26899 double dy
= XINT (ly0
) - y
;
26900 return (dx
* dx
+ dy
* dy
<= r
* r
);
26903 else if (EQ (XCAR (hot_spot
), Qpoly
))
26905 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26906 if (VECTORP (XCDR (hot_spot
)))
26908 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26909 Lisp_Object
*poly
= v
->contents
;
26910 ptrdiff_t n
= v
->header
.size
;
26913 Lisp_Object lx
, ly
;
26916 /* Need an even number of coordinates, and at least 3 edges. */
26917 if (n
< 6 || n
& 1)
26920 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26921 If count is odd, we are inside polygon. Pixels on edges
26922 may or may not be included depending on actual geometry of the
26924 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26925 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26927 x0
= XINT (lx
), y0
= XINT (ly
);
26928 for (i
= 0; i
< n
; i
+= 2)
26930 int x1
= x0
, y1
= y0
;
26931 if ((lx
= poly
[i
], !INTEGERP (lx
))
26932 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26934 x0
= XINT (lx
), y0
= XINT (ly
);
26936 /* Does this segment cross the X line? */
26944 if (y
> y0
&& y
> y1
)
26946 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26956 find_hot_spot (Lisp_Object map
, int x
, int y
)
26958 while (CONSP (map
))
26960 if (CONSP (XCAR (map
))
26961 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26969 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26971 doc
: /* Lookup in image map MAP coordinates X and Y.
26972 An image map is an alist where each element has the format (AREA ID PLIST).
26973 An AREA is specified as either a rectangle, a circle, or a polygon:
26974 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26975 pixel coordinates of the upper left and bottom right corners.
26976 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26977 and the radius of the circle; r may be a float or integer.
26978 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26979 vector describes one corner in the polygon.
26980 Returns the alist element for the first matching AREA in MAP. */)
26981 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26989 return find_hot_spot (map
,
26990 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
26991 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
26995 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26997 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26999 /* Do not change cursor shape while dragging mouse. */
27000 if (!NILP (do_mouse_tracking
))
27003 if (!NILP (pointer
))
27005 if (EQ (pointer
, Qarrow
))
27006 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27007 else if (EQ (pointer
, Qhand
))
27008 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27009 else if (EQ (pointer
, Qtext
))
27010 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27011 else if (EQ (pointer
, intern ("hdrag")))
27012 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27013 #ifdef HAVE_X_WINDOWS
27014 else if (EQ (pointer
, intern ("vdrag")))
27015 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27017 else if (EQ (pointer
, intern ("hourglass")))
27018 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27019 else if (EQ (pointer
, Qmodeline
))
27020 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27022 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27025 if (cursor
!= No_Cursor
)
27026 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27029 #endif /* HAVE_WINDOW_SYSTEM */
27031 /* Take proper action when mouse has moved to the mode or header line
27032 or marginal area AREA of window W, x-position X and y-position Y.
27033 X is relative to the start of the text display area of W, so the
27034 width of bitmap areas and scroll bars must be subtracted to get a
27035 position relative to the start of the mode line. */
27038 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27039 enum window_part area
)
27041 struct window
*w
= XWINDOW (window
);
27042 struct frame
*f
= XFRAME (w
->frame
);
27043 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27044 #ifdef HAVE_WINDOW_SYSTEM
27045 Display_Info
*dpyinfo
;
27047 Cursor cursor
= No_Cursor
;
27048 Lisp_Object pointer
= Qnil
;
27049 int dx
, dy
, width
, height
;
27051 Lisp_Object string
, object
= Qnil
;
27052 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27054 Lisp_Object mouse_face
;
27055 int original_x_pixel
= x
;
27056 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27057 struct glyph_row
*row
IF_LINT (= 0);
27059 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27064 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27065 returns them in row/column units! */
27066 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27067 &object
, &dx
, &dy
, &width
, &height
);
27069 row
= (area
== ON_MODE_LINE
27070 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27071 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27073 /* Find the glyph under the mouse pointer. */
27074 if (row
->mode_line_p
&& row
->enabled_p
)
27076 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27077 end
= glyph
+ row
->used
[TEXT_AREA
];
27079 for (x0
= original_x_pixel
;
27080 glyph
< end
&& x0
>= glyph
->pixel_width
;
27082 x0
-= glyph
->pixel_width
;
27090 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27091 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27092 returns them in row/column units! */
27093 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27094 &object
, &dx
, &dy
, &width
, &height
);
27099 #ifdef HAVE_WINDOW_SYSTEM
27100 if (IMAGEP (object
))
27102 Lisp_Object image_map
, hotspot
;
27103 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27105 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27107 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27111 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27112 If so, we could look for mouse-enter, mouse-leave
27113 properties in PLIST (and do something...). */
27114 hotspot
= XCDR (hotspot
);
27115 if (CONSP (hotspot
)
27116 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27118 pointer
= Fplist_get (plist
, Qpointer
);
27119 if (NILP (pointer
))
27121 help
= Fplist_get (plist
, Qhelp_echo
);
27124 help_echo_string
= help
;
27125 XSETWINDOW (help_echo_window
, w
);
27126 help_echo_object
= w
->buffer
;
27127 help_echo_pos
= charpos
;
27131 if (NILP (pointer
))
27132 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27134 #endif /* HAVE_WINDOW_SYSTEM */
27136 if (STRINGP (string
))
27137 pos
= make_number (charpos
);
27139 /* Set the help text and mouse pointer. If the mouse is on a part
27140 of the mode line without any text (e.g. past the right edge of
27141 the mode line text), use the default help text and pointer. */
27142 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27144 /* Arrange to display the help by setting the global variables
27145 help_echo_string, help_echo_object, and help_echo_pos. */
27148 if (STRINGP (string
))
27149 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27153 help_echo_string
= help
;
27154 XSETWINDOW (help_echo_window
, w
);
27155 help_echo_object
= string
;
27156 help_echo_pos
= charpos
;
27158 else if (area
== ON_MODE_LINE
)
27160 Lisp_Object default_help
27161 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27164 if (STRINGP (default_help
))
27166 help_echo_string
= default_help
;
27167 XSETWINDOW (help_echo_window
, w
);
27168 help_echo_object
= Qnil
;
27169 help_echo_pos
= -1;
27174 #ifdef HAVE_WINDOW_SYSTEM
27175 /* Change the mouse pointer according to what is under it. */
27176 if (FRAME_WINDOW_P (f
))
27178 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27179 if (STRINGP (string
))
27181 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27183 if (NILP (pointer
))
27184 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27186 /* Change the mouse pointer according to what is under X/Y. */
27188 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27191 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27192 if (!KEYMAPP (map
))
27193 map
= Fget_text_property (pos
, Qkeymap
, string
);
27194 if (!KEYMAPP (map
))
27195 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27199 /* Default mode-line pointer. */
27200 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27205 /* Change the mouse face according to what is under X/Y. */
27206 if (STRINGP (string
))
27208 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27209 if (!NILP (mouse_face
)
27210 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27215 struct glyph
* tmp_glyph
;
27219 int total_pixel_width
;
27220 ptrdiff_t begpos
, endpos
, ignore
;
27224 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27225 Qmouse_face
, string
, Qnil
);
27231 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27233 endpos
= SCHARS (string
);
27237 /* Calculate the glyph position GPOS of GLYPH in the
27238 displayed string, relative to the beginning of the
27239 highlighted part of the string.
27241 Note: GPOS is different from CHARPOS. CHARPOS is the
27242 position of GLYPH in the internal string object. A mode
27243 line string format has structures which are converted to
27244 a flattened string by the Emacs Lisp interpreter. The
27245 internal string is an element of those structures. The
27246 displayed string is the flattened string. */
27247 tmp_glyph
= row_start_glyph
;
27248 while (tmp_glyph
< glyph
27249 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27250 && begpos
<= tmp_glyph
->charpos
27251 && tmp_glyph
->charpos
< endpos
)))
27253 gpos
= glyph
- tmp_glyph
;
27255 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27256 the highlighted part of the displayed string to which
27257 GLYPH belongs. Note: GSEQ_LENGTH is different from
27258 SCHARS (STRING), because the latter returns the length of
27259 the internal string. */
27260 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27262 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27263 && begpos
<= tmp_glyph
->charpos
27264 && tmp_glyph
->charpos
< endpos
));
27267 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27269 /* Calculate the total pixel width of all the glyphs between
27270 the beginning of the highlighted area and GLYPH. */
27271 total_pixel_width
= 0;
27272 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27273 total_pixel_width
+= tmp_glyph
->pixel_width
;
27275 /* Pre calculation of re-rendering position. Note: X is in
27276 column units here, after the call to mode_line_string or
27277 marginal_area_string. */
27279 vpos
= (area
== ON_MODE_LINE
27280 ? (w
->current_matrix
)->nrows
- 1
27283 /* If GLYPH's position is included in the region that is
27284 already drawn in mouse face, we have nothing to do. */
27285 if ( EQ (window
, hlinfo
->mouse_face_window
)
27286 && (!row
->reversed_p
27287 ? (hlinfo
->mouse_face_beg_col
<= hpos
27288 && hpos
< hlinfo
->mouse_face_end_col
)
27289 /* In R2L rows we swap BEG and END, see below. */
27290 : (hlinfo
->mouse_face_end_col
<= hpos
27291 && hpos
< hlinfo
->mouse_face_beg_col
))
27292 && hlinfo
->mouse_face_beg_row
== vpos
)
27295 if (clear_mouse_face (hlinfo
))
27296 cursor
= No_Cursor
;
27298 if (!row
->reversed_p
)
27300 hlinfo
->mouse_face_beg_col
= hpos
;
27301 hlinfo
->mouse_face_beg_x
= original_x_pixel
27302 - (total_pixel_width
+ dx
);
27303 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27304 hlinfo
->mouse_face_end_x
= 0;
27308 /* In R2L rows, show_mouse_face expects BEG and END
27309 coordinates to be swapped. */
27310 hlinfo
->mouse_face_end_col
= hpos
;
27311 hlinfo
->mouse_face_end_x
= original_x_pixel
27312 - (total_pixel_width
+ dx
);
27313 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27314 hlinfo
->mouse_face_beg_x
= 0;
27317 hlinfo
->mouse_face_beg_row
= vpos
;
27318 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27319 hlinfo
->mouse_face_beg_y
= 0;
27320 hlinfo
->mouse_face_end_y
= 0;
27321 hlinfo
->mouse_face_past_end
= 0;
27322 hlinfo
->mouse_face_window
= window
;
27324 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27330 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27332 if (NILP (pointer
))
27335 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27336 clear_mouse_face (hlinfo
);
27338 #ifdef HAVE_WINDOW_SYSTEM
27339 if (FRAME_WINDOW_P (f
))
27340 define_frame_cursor1 (f
, cursor
, pointer
);
27346 Take proper action when the mouse has moved to position X, Y on
27347 frame F as regards highlighting characters that have mouse-face
27348 properties. Also de-highlighting chars where the mouse was before.
27349 X and Y can be negative or out of range. */
27352 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27354 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27355 enum window_part part
= ON_NOTHING
;
27356 Lisp_Object window
;
27358 Cursor cursor
= No_Cursor
;
27359 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27362 /* When a menu is active, don't highlight because this looks odd. */
27363 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27364 if (popup_activated ())
27368 if (NILP (Vmouse_highlight
)
27369 || !f
->glyphs_initialized_p
27370 || f
->pointer_invisible
)
27373 hlinfo
->mouse_face_mouse_x
= x
;
27374 hlinfo
->mouse_face_mouse_y
= y
;
27375 hlinfo
->mouse_face_mouse_frame
= f
;
27377 if (hlinfo
->mouse_face_defer
)
27380 if (gc_in_progress
)
27382 hlinfo
->mouse_face_deferred_gc
= 1;
27386 /* Which window is that in? */
27387 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27389 /* If displaying active text in another window, clear that. */
27390 if (! EQ (window
, hlinfo
->mouse_face_window
)
27391 /* Also clear if we move out of text area in same window. */
27392 || (!NILP (hlinfo
->mouse_face_window
)
27395 && part
!= ON_MODE_LINE
27396 && part
!= ON_HEADER_LINE
))
27397 clear_mouse_face (hlinfo
);
27399 /* Not on a window -> return. */
27400 if (!WINDOWP (window
))
27403 /* Reset help_echo_string. It will get recomputed below. */
27404 help_echo_string
= Qnil
;
27406 /* Convert to window-relative pixel coordinates. */
27407 w
= XWINDOW (window
);
27408 frame_to_window_pixel_xy (w
, &x
, &y
);
27410 #ifdef HAVE_WINDOW_SYSTEM
27411 /* Handle tool-bar window differently since it doesn't display a
27413 if (EQ (window
, f
->tool_bar_window
))
27415 note_tool_bar_highlight (f
, x
, y
);
27420 /* Mouse is on the mode, header line or margin? */
27421 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27422 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27424 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27428 #ifdef HAVE_WINDOW_SYSTEM
27429 if (part
== ON_VERTICAL_BORDER
)
27431 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27432 help_echo_string
= build_string ("drag-mouse-1: resize");
27434 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27435 || part
== ON_SCROLL_BAR
)
27436 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27438 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27441 /* Are we in a window whose display is up to date?
27442 And verify the buffer's text has not changed. */
27443 b
= XBUFFER (w
->buffer
);
27444 if (part
== ON_TEXT
27445 && EQ (w
->window_end_valid
, w
->buffer
)
27446 && w
->last_modified
== BUF_MODIFF (b
)
27447 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27449 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27451 struct glyph
*glyph
;
27452 Lisp_Object object
;
27453 Lisp_Object mouse_face
= Qnil
, position
;
27454 Lisp_Object
*overlay_vec
= NULL
;
27455 ptrdiff_t i
, noverlays
;
27456 struct buffer
*obuf
;
27457 ptrdiff_t obegv
, ozv
;
27460 /* Find the glyph under X/Y. */
27461 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27463 #ifdef HAVE_WINDOW_SYSTEM
27464 /* Look for :pointer property on image. */
27465 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27467 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27468 if (img
!= NULL
&& IMAGEP (img
->spec
))
27470 Lisp_Object image_map
, hotspot
;
27471 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27473 && (hotspot
= find_hot_spot (image_map
,
27474 glyph
->slice
.img
.x
+ dx
,
27475 glyph
->slice
.img
.y
+ dy
),
27477 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27481 /* Could check XCAR (hotspot) to see if we enter/leave
27483 If so, we could look for mouse-enter, mouse-leave
27484 properties in PLIST (and do something...). */
27485 hotspot
= XCDR (hotspot
);
27486 if (CONSP (hotspot
)
27487 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27489 pointer
= Fplist_get (plist
, Qpointer
);
27490 if (NILP (pointer
))
27492 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27493 if (!NILP (help_echo_string
))
27495 help_echo_window
= window
;
27496 help_echo_object
= glyph
->object
;
27497 help_echo_pos
= glyph
->charpos
;
27501 if (NILP (pointer
))
27502 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27505 #endif /* HAVE_WINDOW_SYSTEM */
27507 /* Clear mouse face if X/Y not over text. */
27509 || area
!= TEXT_AREA
27510 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27511 /* Glyph's OBJECT is an integer for glyphs inserted by the
27512 display engine for its internal purposes, like truncation
27513 and continuation glyphs and blanks beyond the end of
27514 line's text on text terminals. If we are over such a
27515 glyph, we are not over any text. */
27516 || INTEGERP (glyph
->object
)
27517 /* R2L rows have a stretch glyph at their front, which
27518 stands for no text, whereas L2R rows have no glyphs at
27519 all beyond the end of text. Treat such stretch glyphs
27520 like we do with NULL glyphs in L2R rows. */
27521 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27522 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27523 && glyph
->type
== STRETCH_GLYPH
27524 && glyph
->avoid_cursor_p
))
27526 if (clear_mouse_face (hlinfo
))
27527 cursor
= No_Cursor
;
27528 #ifdef HAVE_WINDOW_SYSTEM
27529 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27531 if (area
!= TEXT_AREA
)
27532 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27534 pointer
= Vvoid_text_area_pointer
;
27540 pos
= glyph
->charpos
;
27541 object
= glyph
->object
;
27542 if (!STRINGP (object
) && !BUFFERP (object
))
27545 /* If we get an out-of-range value, return now; avoid an error. */
27546 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27549 /* Make the window's buffer temporarily current for
27550 overlays_at and compute_char_face. */
27551 obuf
= current_buffer
;
27552 current_buffer
= b
;
27558 /* Is this char mouse-active or does it have help-echo? */
27559 position
= make_number (pos
);
27561 if (BUFFERP (object
))
27563 /* Put all the overlays we want in a vector in overlay_vec. */
27564 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27565 /* Sort overlays into increasing priority order. */
27566 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27571 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27574 cursor
= No_Cursor
;
27576 /* Check mouse-face highlighting. */
27578 /* If there exists an overlay with mouse-face overlapping
27579 the one we are currently highlighting, we have to
27580 check if we enter the overlapping overlay, and then
27581 highlight only that. */
27582 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27583 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27585 /* Find the highest priority overlay with a mouse-face. */
27586 Lisp_Object overlay
= Qnil
;
27587 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27589 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27590 if (!NILP (mouse_face
))
27591 overlay
= overlay_vec
[i
];
27594 /* If we're highlighting the same overlay as before, there's
27595 no need to do that again. */
27596 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27597 goto check_help_echo
;
27598 hlinfo
->mouse_face_overlay
= overlay
;
27600 /* Clear the display of the old active region, if any. */
27601 if (clear_mouse_face (hlinfo
))
27602 cursor
= No_Cursor
;
27604 /* If no overlay applies, get a text property. */
27605 if (NILP (overlay
))
27606 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27608 /* Next, compute the bounds of the mouse highlighting and
27610 if (!NILP (mouse_face
) && STRINGP (object
))
27612 /* The mouse-highlighting comes from a display string
27613 with a mouse-face. */
27617 s
= Fprevious_single_property_change
27618 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27619 e
= Fnext_single_property_change
27620 (position
, Qmouse_face
, object
, Qnil
);
27622 s
= make_number (0);
27624 e
= make_number (SCHARS (object
) - 1);
27625 mouse_face_from_string_pos (w
, hlinfo
, object
,
27626 XINT (s
), XINT (e
));
27627 hlinfo
->mouse_face_past_end
= 0;
27628 hlinfo
->mouse_face_window
= window
;
27629 hlinfo
->mouse_face_face_id
27630 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27631 glyph
->face_id
, 1);
27632 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27633 cursor
= No_Cursor
;
27637 /* The mouse-highlighting, if any, comes from an overlay
27638 or text property in the buffer. */
27639 Lisp_Object buffer
IF_LINT (= Qnil
);
27640 Lisp_Object disp_string
IF_LINT (= Qnil
);
27642 if (STRINGP (object
))
27644 /* If we are on a display string with no mouse-face,
27645 check if the text under it has one. */
27646 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27647 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27648 pos
= string_buffer_position (object
, start
);
27651 mouse_face
= get_char_property_and_overlay
27652 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27653 buffer
= w
->buffer
;
27654 disp_string
= object
;
27660 disp_string
= Qnil
;
27663 if (!NILP (mouse_face
))
27665 Lisp_Object before
, after
;
27666 Lisp_Object before_string
, after_string
;
27667 /* To correctly find the limits of mouse highlight
27668 in a bidi-reordered buffer, we must not use the
27669 optimization of limiting the search in
27670 previous-single-property-change and
27671 next-single-property-change, because
27672 rows_from_pos_range needs the real start and end
27673 positions to DTRT in this case. That's because
27674 the first row visible in a window does not
27675 necessarily display the character whose position
27676 is the smallest. */
27678 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27679 ? Fmarker_position (w
->start
)
27682 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27683 ? make_number (BUF_Z (XBUFFER (buffer
))
27684 - XFASTINT (w
->window_end_pos
))
27687 if (NILP (overlay
))
27689 /* Handle the text property case. */
27690 before
= Fprevious_single_property_change
27691 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27692 after
= Fnext_single_property_change
27693 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27694 before_string
= after_string
= Qnil
;
27698 /* Handle the overlay case. */
27699 before
= Foverlay_start (overlay
);
27700 after
= Foverlay_end (overlay
);
27701 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27702 after_string
= Foverlay_get (overlay
, Qafter_string
);
27704 if (!STRINGP (before_string
)) before_string
= Qnil
;
27705 if (!STRINGP (after_string
)) after_string
= Qnil
;
27708 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27711 : XFASTINT (before
),
27713 ? BUF_Z (XBUFFER (buffer
))
27714 : XFASTINT (after
),
27715 before_string
, after_string
,
27717 cursor
= No_Cursor
;
27724 /* Look for a `help-echo' property. */
27725 if (NILP (help_echo_string
)) {
27726 Lisp_Object help
, overlay
;
27728 /* Check overlays first. */
27729 help
= overlay
= Qnil
;
27730 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27732 overlay
= overlay_vec
[i
];
27733 help
= Foverlay_get (overlay
, Qhelp_echo
);
27738 help_echo_string
= help
;
27739 help_echo_window
= window
;
27740 help_echo_object
= overlay
;
27741 help_echo_pos
= pos
;
27745 Lisp_Object obj
= glyph
->object
;
27746 ptrdiff_t charpos
= glyph
->charpos
;
27748 /* Try text properties. */
27751 && charpos
< SCHARS (obj
))
27753 help
= Fget_text_property (make_number (charpos
),
27757 /* If the string itself doesn't specify a help-echo,
27758 see if the buffer text ``under'' it does. */
27759 struct glyph_row
*r
27760 = MATRIX_ROW (w
->current_matrix
, vpos
);
27761 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27762 ptrdiff_t p
= string_buffer_position (obj
, start
);
27765 help
= Fget_char_property (make_number (p
),
27766 Qhelp_echo
, w
->buffer
);
27775 else if (BUFFERP (obj
)
27778 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27783 help_echo_string
= help
;
27784 help_echo_window
= window
;
27785 help_echo_object
= obj
;
27786 help_echo_pos
= charpos
;
27791 #ifdef HAVE_WINDOW_SYSTEM
27792 /* Look for a `pointer' property. */
27793 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27795 /* Check overlays first. */
27796 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27797 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27799 if (NILP (pointer
))
27801 Lisp_Object obj
= glyph
->object
;
27802 ptrdiff_t charpos
= glyph
->charpos
;
27804 /* Try text properties. */
27807 && charpos
< SCHARS (obj
))
27809 pointer
= Fget_text_property (make_number (charpos
),
27811 if (NILP (pointer
))
27813 /* If the string itself doesn't specify a pointer,
27814 see if the buffer text ``under'' it does. */
27815 struct glyph_row
*r
27816 = MATRIX_ROW (w
->current_matrix
, vpos
);
27817 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27818 ptrdiff_t p
= string_buffer_position (obj
, start
);
27820 pointer
= Fget_char_property (make_number (p
),
27821 Qpointer
, w
->buffer
);
27824 else if (BUFFERP (obj
)
27827 pointer
= Fget_text_property (make_number (charpos
),
27831 #endif /* HAVE_WINDOW_SYSTEM */
27835 current_buffer
= obuf
;
27840 #ifdef HAVE_WINDOW_SYSTEM
27841 if (FRAME_WINDOW_P (f
))
27842 define_frame_cursor1 (f
, cursor
, pointer
);
27844 /* This is here to prevent a compiler error, about "label at end of
27845 compound statement". */
27852 Clear any mouse-face on window W. This function is part of the
27853 redisplay interface, and is called from try_window_id and similar
27854 functions to ensure the mouse-highlight is off. */
27857 x_clear_window_mouse_face (struct window
*w
)
27859 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27860 Lisp_Object window
;
27863 XSETWINDOW (window
, w
);
27864 if (EQ (window
, hlinfo
->mouse_face_window
))
27865 clear_mouse_face (hlinfo
);
27871 Just discard the mouse face information for frame F, if any.
27872 This is used when the size of F is changed. */
27875 cancel_mouse_face (struct frame
*f
)
27877 Lisp_Object window
;
27878 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27880 window
= hlinfo
->mouse_face_window
;
27881 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27883 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27884 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27885 hlinfo
->mouse_face_window
= Qnil
;
27891 /***********************************************************************
27893 ***********************************************************************/
27895 #ifdef HAVE_WINDOW_SYSTEM
27897 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27898 which intersects rectangle R. R is in window-relative coordinates. */
27901 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27902 enum glyph_row_area area
)
27904 struct glyph
*first
= row
->glyphs
[area
];
27905 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27906 struct glyph
*last
;
27907 int first_x
, start_x
, x
;
27909 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27910 /* If row extends face to end of line write the whole line. */
27911 draw_glyphs (w
, 0, row
, area
,
27912 0, row
->used
[area
],
27913 DRAW_NORMAL_TEXT
, 0);
27916 /* Set START_X to the window-relative start position for drawing glyphs of
27917 AREA. The first glyph of the text area can be partially visible.
27918 The first glyphs of other areas cannot. */
27919 start_x
= window_box_left_offset (w
, area
);
27921 if (area
== TEXT_AREA
)
27924 /* Find the first glyph that must be redrawn. */
27926 && x
+ first
->pixel_width
< r
->x
)
27928 x
+= first
->pixel_width
;
27932 /* Find the last one. */
27936 && x
< r
->x
+ r
->width
)
27938 x
+= last
->pixel_width
;
27944 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27945 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27946 DRAW_NORMAL_TEXT
, 0);
27951 /* Redraw the parts of the glyph row ROW on window W intersecting
27952 rectangle R. R is in window-relative coordinates. Value is
27953 non-zero if mouse-face was overwritten. */
27956 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27958 eassert (row
->enabled_p
);
27960 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27961 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27962 0, row
->used
[TEXT_AREA
],
27963 DRAW_NORMAL_TEXT
, 0);
27966 if (row
->used
[LEFT_MARGIN_AREA
])
27967 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27968 if (row
->used
[TEXT_AREA
])
27969 expose_area (w
, row
, r
, TEXT_AREA
);
27970 if (row
->used
[RIGHT_MARGIN_AREA
])
27971 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27972 draw_row_fringe_bitmaps (w
, row
);
27975 return row
->mouse_face_p
;
27979 /* Redraw those parts of glyphs rows during expose event handling that
27980 overlap other rows. Redrawing of an exposed line writes over parts
27981 of lines overlapping that exposed line; this function fixes that.
27983 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27984 row in W's current matrix that is exposed and overlaps other rows.
27985 LAST_OVERLAPPING_ROW is the last such row. */
27988 expose_overlaps (struct window
*w
,
27989 struct glyph_row
*first_overlapping_row
,
27990 struct glyph_row
*last_overlapping_row
,
27993 struct glyph_row
*row
;
27995 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27996 if (row
->overlapping_p
)
27998 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28001 if (row
->used
[LEFT_MARGIN_AREA
])
28002 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28004 if (row
->used
[TEXT_AREA
])
28005 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28007 if (row
->used
[RIGHT_MARGIN_AREA
])
28008 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28014 /* Return non-zero if W's cursor intersects rectangle R. */
28017 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28019 XRectangle cr
, result
;
28020 struct glyph
*cursor_glyph
;
28021 struct glyph_row
*row
;
28023 if (w
->phys_cursor
.vpos
>= 0
28024 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28025 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28027 && row
->cursor_in_fringe_p
)
28029 /* Cursor is in the fringe. */
28030 cr
.x
= window_box_right_offset (w
,
28031 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28032 ? RIGHT_MARGIN_AREA
28035 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28036 cr
.height
= row
->height
;
28037 return x_intersect_rectangles (&cr
, r
, &result
);
28040 cursor_glyph
= get_phys_cursor_glyph (w
);
28043 /* r is relative to W's box, but w->phys_cursor.x is relative
28044 to left edge of W's TEXT area. Adjust it. */
28045 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28046 cr
.y
= w
->phys_cursor
.y
;
28047 cr
.width
= cursor_glyph
->pixel_width
;
28048 cr
.height
= w
->phys_cursor_height
;
28049 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28050 I assume the effect is the same -- and this is portable. */
28051 return x_intersect_rectangles (&cr
, r
, &result
);
28053 /* If we don't understand the format, pretend we're not in the hot-spot. */
28059 Draw a vertical window border to the right of window W if W doesn't
28060 have vertical scroll bars. */
28063 x_draw_vertical_border (struct window
*w
)
28065 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28067 /* We could do better, if we knew what type of scroll-bar the adjacent
28068 windows (on either side) have... But we don't :-(
28069 However, I think this works ok. ++KFS 2003-04-25 */
28071 /* Redraw borders between horizontally adjacent windows. Don't
28072 do it for frames with vertical scroll bars because either the
28073 right scroll bar of a window, or the left scroll bar of its
28074 neighbor will suffice as a border. */
28075 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28078 if (!WINDOW_RIGHTMOST_P (w
)
28079 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28081 int x0
, x1
, y0
, y1
;
28083 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28086 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28089 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28091 else if (!WINDOW_LEFTMOST_P (w
)
28092 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28094 int x0
, x1
, y0
, y1
;
28096 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28099 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28102 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28107 /* Redraw the part of window W intersection rectangle FR. Pixel
28108 coordinates in FR are frame-relative. Call this function with
28109 input blocked. Value is non-zero if the exposure overwrites
28113 expose_window (struct window
*w
, XRectangle
*fr
)
28115 struct frame
*f
= XFRAME (w
->frame
);
28117 int mouse_face_overwritten_p
= 0;
28119 /* If window is not yet fully initialized, do nothing. This can
28120 happen when toolkit scroll bars are used and a window is split.
28121 Reconfiguring the scroll bar will generate an expose for a newly
28123 if (w
->current_matrix
== NULL
)
28126 /* When we're currently updating the window, display and current
28127 matrix usually don't agree. Arrange for a thorough display
28129 if (w
== updated_window
)
28131 SET_FRAME_GARBAGED (f
);
28135 /* Frame-relative pixel rectangle of W. */
28136 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28137 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28138 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28139 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28141 if (x_intersect_rectangles (fr
, &wr
, &r
))
28143 int yb
= window_text_bottom_y (w
);
28144 struct glyph_row
*row
;
28145 int cursor_cleared_p
, phys_cursor_on_p
;
28146 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28148 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28149 r
.x
, r
.y
, r
.width
, r
.height
));
28151 /* Convert to window coordinates. */
28152 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28153 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28155 /* Turn off the cursor. */
28156 if (!w
->pseudo_window_p
28157 && phys_cursor_in_rect_p (w
, &r
))
28159 x_clear_cursor (w
);
28160 cursor_cleared_p
= 1;
28163 cursor_cleared_p
= 0;
28165 /* If the row containing the cursor extends face to end of line,
28166 then expose_area might overwrite the cursor outside the
28167 rectangle and thus notice_overwritten_cursor might clear
28168 w->phys_cursor_on_p. We remember the original value and
28169 check later if it is changed. */
28170 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28172 /* Update lines intersecting rectangle R. */
28173 first_overlapping_row
= last_overlapping_row
= NULL
;
28174 for (row
= w
->current_matrix
->rows
;
28179 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28181 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28182 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28183 || (r
.y
>= y0
&& r
.y
< y1
)
28184 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28186 /* A header line may be overlapping, but there is no need
28187 to fix overlapping areas for them. KFS 2005-02-12 */
28188 if (row
->overlapping_p
&& !row
->mode_line_p
)
28190 if (first_overlapping_row
== NULL
)
28191 first_overlapping_row
= row
;
28192 last_overlapping_row
= row
;
28196 if (expose_line (w
, row
, &r
))
28197 mouse_face_overwritten_p
= 1;
28200 else if (row
->overlapping_p
)
28202 /* We must redraw a row overlapping the exposed area. */
28204 ? y0
+ row
->phys_height
> r
.y
28205 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28207 if (first_overlapping_row
== NULL
)
28208 first_overlapping_row
= row
;
28209 last_overlapping_row
= row
;
28217 /* Display the mode line if there is one. */
28218 if (WINDOW_WANTS_MODELINE_P (w
)
28219 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28221 && row
->y
< r
.y
+ r
.height
)
28223 if (expose_line (w
, row
, &r
))
28224 mouse_face_overwritten_p
= 1;
28227 if (!w
->pseudo_window_p
)
28229 /* Fix the display of overlapping rows. */
28230 if (first_overlapping_row
)
28231 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28234 /* Draw border between windows. */
28235 x_draw_vertical_border (w
);
28237 /* Turn the cursor on again. */
28238 if (cursor_cleared_p
28239 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28240 update_window_cursor (w
, 1);
28244 return mouse_face_overwritten_p
;
28249 /* Redraw (parts) of all windows in the window tree rooted at W that
28250 intersect R. R contains frame pixel coordinates. Value is
28251 non-zero if the exposure overwrites mouse-face. */
28254 expose_window_tree (struct window
*w
, XRectangle
*r
)
28256 struct frame
*f
= XFRAME (w
->frame
);
28257 int mouse_face_overwritten_p
= 0;
28259 while (w
&& !FRAME_GARBAGED_P (f
))
28261 if (!NILP (w
->hchild
))
28262 mouse_face_overwritten_p
28263 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28264 else if (!NILP (w
->vchild
))
28265 mouse_face_overwritten_p
28266 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28268 mouse_face_overwritten_p
|= expose_window (w
, r
);
28270 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28273 return mouse_face_overwritten_p
;
28278 Redisplay an exposed area of frame F. X and Y are the upper-left
28279 corner of the exposed rectangle. W and H are width and height of
28280 the exposed area. All are pixel values. W or H zero means redraw
28281 the entire frame. */
28284 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28287 int mouse_face_overwritten_p
= 0;
28289 TRACE ((stderr
, "expose_frame "));
28291 /* No need to redraw if frame will be redrawn soon. */
28292 if (FRAME_GARBAGED_P (f
))
28294 TRACE ((stderr
, " garbaged\n"));
28298 /* If basic faces haven't been realized yet, there is no point in
28299 trying to redraw anything. This can happen when we get an expose
28300 event while Emacs is starting, e.g. by moving another window. */
28301 if (FRAME_FACE_CACHE (f
) == NULL
28302 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28304 TRACE ((stderr
, " no faces\n"));
28308 if (w
== 0 || h
== 0)
28311 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28312 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28322 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28323 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28325 if (WINDOWP (f
->tool_bar_window
))
28326 mouse_face_overwritten_p
28327 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28329 #ifdef HAVE_X_WINDOWS
28331 #ifndef USE_X_TOOLKIT
28332 if (WINDOWP (f
->menu_bar_window
))
28333 mouse_face_overwritten_p
28334 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28335 #endif /* not USE_X_TOOLKIT */
28339 /* Some window managers support a focus-follows-mouse style with
28340 delayed raising of frames. Imagine a partially obscured frame,
28341 and moving the mouse into partially obscured mouse-face on that
28342 frame. The visible part of the mouse-face will be highlighted,
28343 then the WM raises the obscured frame. With at least one WM, KDE
28344 2.1, Emacs is not getting any event for the raising of the frame
28345 (even tried with SubstructureRedirectMask), only Expose events.
28346 These expose events will draw text normally, i.e. not
28347 highlighted. Which means we must redo the highlight here.
28348 Subsume it under ``we love X''. --gerd 2001-08-15 */
28349 /* Included in Windows version because Windows most likely does not
28350 do the right thing if any third party tool offers
28351 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28352 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28354 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28355 if (f
== hlinfo
->mouse_face_mouse_frame
)
28357 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28358 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28359 clear_mouse_face (hlinfo
);
28360 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28367 Determine the intersection of two rectangles R1 and R2. Return
28368 the intersection in *RESULT. Value is non-zero if RESULT is not
28372 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28374 XRectangle
*left
, *right
;
28375 XRectangle
*upper
, *lower
;
28376 int intersection_p
= 0;
28378 /* Rearrange so that R1 is the left-most rectangle. */
28380 left
= r1
, right
= r2
;
28382 left
= r2
, right
= r1
;
28384 /* X0 of the intersection is right.x0, if this is inside R1,
28385 otherwise there is no intersection. */
28386 if (right
->x
<= left
->x
+ left
->width
)
28388 result
->x
= right
->x
;
28390 /* The right end of the intersection is the minimum of
28391 the right ends of left and right. */
28392 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28395 /* Same game for Y. */
28397 upper
= r1
, lower
= r2
;
28399 upper
= r2
, lower
= r1
;
28401 /* The upper end of the intersection is lower.y0, if this is inside
28402 of upper. Otherwise, there is no intersection. */
28403 if (lower
->y
<= upper
->y
+ upper
->height
)
28405 result
->y
= lower
->y
;
28407 /* The lower end of the intersection is the minimum of the lower
28408 ends of upper and lower. */
28409 result
->height
= (min (lower
->y
+ lower
->height
,
28410 upper
->y
+ upper
->height
)
28412 intersection_p
= 1;
28416 return intersection_p
;
28419 #endif /* HAVE_WINDOW_SYSTEM */
28422 /***********************************************************************
28424 ***********************************************************************/
28427 syms_of_xdisp (void)
28429 Vwith_echo_area_save_vector
= Qnil
;
28430 staticpro (&Vwith_echo_area_save_vector
);
28432 Vmessage_stack
= Qnil
;
28433 staticpro (&Vmessage_stack
);
28435 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28437 message_dolog_marker1
= Fmake_marker ();
28438 staticpro (&message_dolog_marker1
);
28439 message_dolog_marker2
= Fmake_marker ();
28440 staticpro (&message_dolog_marker2
);
28441 message_dolog_marker3
= Fmake_marker ();
28442 staticpro (&message_dolog_marker3
);
28445 defsubr (&Sdump_frame_glyph_matrix
);
28446 defsubr (&Sdump_glyph_matrix
);
28447 defsubr (&Sdump_glyph_row
);
28448 defsubr (&Sdump_tool_bar_row
);
28449 defsubr (&Strace_redisplay
);
28450 defsubr (&Strace_to_stderr
);
28452 #ifdef HAVE_WINDOW_SYSTEM
28453 defsubr (&Stool_bar_lines_needed
);
28454 defsubr (&Slookup_image_map
);
28456 defsubr (&Sformat_mode_line
);
28457 defsubr (&Sinvisible_p
);
28458 defsubr (&Scurrent_bidi_paragraph_direction
);
28460 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28461 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28462 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28463 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28464 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28465 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28466 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28467 DEFSYM (Qeval
, "eval");
28468 DEFSYM (QCdata
, ":data");
28469 DEFSYM (Qdisplay
, "display");
28470 DEFSYM (Qspace_width
, "space-width");
28471 DEFSYM (Qraise
, "raise");
28472 DEFSYM (Qslice
, "slice");
28473 DEFSYM (Qspace
, "space");
28474 DEFSYM (Qmargin
, "margin");
28475 DEFSYM (Qpointer
, "pointer");
28476 DEFSYM (Qleft_margin
, "left-margin");
28477 DEFSYM (Qright_margin
, "right-margin");
28478 DEFSYM (Qcenter
, "center");
28479 DEFSYM (Qline_height
, "line-height");
28480 DEFSYM (QCalign_to
, ":align-to");
28481 DEFSYM (QCrelative_width
, ":relative-width");
28482 DEFSYM (QCrelative_height
, ":relative-height");
28483 DEFSYM (QCeval
, ":eval");
28484 DEFSYM (QCpropertize
, ":propertize");
28485 DEFSYM (QCfile
, ":file");
28486 DEFSYM (Qfontified
, "fontified");
28487 DEFSYM (Qfontification_functions
, "fontification-functions");
28488 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28489 DEFSYM (Qescape_glyph
, "escape-glyph");
28490 DEFSYM (Qnobreak_space
, "nobreak-space");
28491 DEFSYM (Qimage
, "image");
28492 DEFSYM (Qtext
, "text");
28493 DEFSYM (Qboth
, "both");
28494 DEFSYM (Qboth_horiz
, "both-horiz");
28495 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28496 DEFSYM (QCmap
, ":map");
28497 DEFSYM (QCpointer
, ":pointer");
28498 DEFSYM (Qrect
, "rect");
28499 DEFSYM (Qcircle
, "circle");
28500 DEFSYM (Qpoly
, "poly");
28501 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28502 DEFSYM (Qgrow_only
, "grow-only");
28503 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28504 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28505 DEFSYM (Qposition
, "position");
28506 DEFSYM (Qbuffer_position
, "buffer-position");
28507 DEFSYM (Qobject
, "object");
28508 DEFSYM (Qbar
, "bar");
28509 DEFSYM (Qhbar
, "hbar");
28510 DEFSYM (Qbox
, "box");
28511 DEFSYM (Qhollow
, "hollow");
28512 DEFSYM (Qhand
, "hand");
28513 DEFSYM (Qarrow
, "arrow");
28514 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28516 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28517 Fcons (intern_c_string ("void-variable"), Qnil
)),
28519 staticpro (&list_of_error
);
28521 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28522 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28523 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28524 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28526 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28527 staticpro (&echo_buffer
[0]);
28528 staticpro (&echo_buffer
[1]);
28530 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28531 staticpro (&echo_area_buffer
[0]);
28532 staticpro (&echo_area_buffer
[1]);
28534 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28535 staticpro (&Vmessages_buffer_name
);
28537 mode_line_proptrans_alist
= Qnil
;
28538 staticpro (&mode_line_proptrans_alist
);
28539 mode_line_string_list
= Qnil
;
28540 staticpro (&mode_line_string_list
);
28541 mode_line_string_face
= Qnil
;
28542 staticpro (&mode_line_string_face
);
28543 mode_line_string_face_prop
= Qnil
;
28544 staticpro (&mode_line_string_face_prop
);
28545 Vmode_line_unwind_vector
= Qnil
;
28546 staticpro (&Vmode_line_unwind_vector
);
28548 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28550 help_echo_string
= Qnil
;
28551 staticpro (&help_echo_string
);
28552 help_echo_object
= Qnil
;
28553 staticpro (&help_echo_object
);
28554 help_echo_window
= Qnil
;
28555 staticpro (&help_echo_window
);
28556 previous_help_echo_string
= Qnil
;
28557 staticpro (&previous_help_echo_string
);
28558 help_echo_pos
= -1;
28560 DEFSYM (Qright_to_left
, "right-to-left");
28561 DEFSYM (Qleft_to_right
, "left-to-right");
28563 #ifdef HAVE_WINDOW_SYSTEM
28564 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28565 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28566 For example, if a block cursor is over a tab, it will be drawn as
28567 wide as that tab on the display. */);
28568 x_stretch_cursor_p
= 0;
28571 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28572 doc
: /* Non-nil means highlight trailing whitespace.
28573 The face used for trailing whitespace is `trailing-whitespace'. */);
28574 Vshow_trailing_whitespace
= Qnil
;
28576 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28577 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28578 If the value is t, Emacs highlights non-ASCII chars which have the
28579 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28580 or `escape-glyph' face respectively.
28582 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28583 U+2011 (non-breaking hyphen) are affected.
28585 Any other non-nil value means to display these characters as a escape
28586 glyph followed by an ordinary space or hyphen.
28588 A value of nil means no special handling of these characters. */);
28589 Vnobreak_char_display
= Qt
;
28591 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28592 doc
: /* The pointer shape to show in void text areas.
28593 A value of nil means to show the text pointer. Other options are `arrow',
28594 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28595 Vvoid_text_area_pointer
= Qarrow
;
28597 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28598 doc
: /* Non-nil means don't actually do any redisplay.
28599 This is used for internal purposes. */);
28600 Vinhibit_redisplay
= Qnil
;
28602 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28603 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28604 Vglobal_mode_string
= Qnil
;
28606 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28607 doc
: /* Marker for where to display an arrow on top of the buffer text.
28608 This must be the beginning of a line in order to work.
28609 See also `overlay-arrow-string'. */);
28610 Voverlay_arrow_position
= Qnil
;
28612 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28613 doc
: /* String to display as an arrow in non-window frames.
28614 See also `overlay-arrow-position'. */);
28615 Voverlay_arrow_string
= make_pure_c_string ("=>");
28617 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28618 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28619 The symbols on this list are examined during redisplay to determine
28620 where to display overlay arrows. */);
28621 Voverlay_arrow_variable_list
28622 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28624 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28625 doc
: /* The number of lines to try scrolling a window by when point moves out.
28626 If that fails to bring point back on frame, point is centered instead.
28627 If this is zero, point is always centered after it moves off frame.
28628 If you want scrolling to always be a line at a time, you should set
28629 `scroll-conservatively' to a large value rather than set this to 1. */);
28631 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28632 doc
: /* Scroll up to this many lines, to bring point back on screen.
28633 If point moves off-screen, redisplay will scroll by up to
28634 `scroll-conservatively' lines in order to bring point just barely
28635 onto the screen again. If that cannot be done, then redisplay
28636 recenters point as usual.
28638 If the value is greater than 100, redisplay will never recenter point,
28639 but will always scroll just enough text to bring point into view, even
28640 if you move far away.
28642 A value of zero means always recenter point if it moves off screen. */);
28643 scroll_conservatively
= 0;
28645 DEFVAR_INT ("scroll-margin", scroll_margin
,
28646 doc
: /* Number of lines of margin at the top and bottom of a window.
28647 Recenter the window whenever point gets within this many lines
28648 of the top or bottom of the window. */);
28651 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28652 doc
: /* Pixels per inch value for non-window system displays.
28653 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28654 Vdisplay_pixels_per_inch
= make_float (72.0);
28657 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28660 DEFVAR_LISP ("truncate-partial-width-windows",
28661 Vtruncate_partial_width_windows
,
28662 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28663 For an integer value, truncate lines in each window narrower than the
28664 full frame width, provided the window width is less than that integer;
28665 otherwise, respect the value of `truncate-lines'.
28667 For any other non-nil value, truncate lines in all windows that do
28668 not span the full frame width.
28670 A value of nil means to respect the value of `truncate-lines'.
28672 If `word-wrap' is enabled, you might want to reduce this. */);
28673 Vtruncate_partial_width_windows
= make_number (50);
28675 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28676 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28677 Any other value means to use the appropriate face, `mode-line',
28678 `header-line', or `menu' respectively. */);
28679 mode_line_inverse_video
= 1;
28681 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28682 doc
: /* Maximum buffer size for which line number should be displayed.
28683 If the buffer is bigger than this, the line number does not appear
28684 in the mode line. A value of nil means no limit. */);
28685 Vline_number_display_limit
= Qnil
;
28687 DEFVAR_INT ("line-number-display-limit-width",
28688 line_number_display_limit_width
,
28689 doc
: /* Maximum line width (in characters) for line number display.
28690 If the average length of the lines near point is bigger than this, then the
28691 line number may be omitted from the mode line. */);
28692 line_number_display_limit_width
= 200;
28694 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28695 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28696 highlight_nonselected_windows
= 0;
28698 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28699 doc
: /* Non-nil if more than one frame is visible on this display.
28700 Minibuffer-only frames don't count, but iconified frames do.
28701 This variable is not guaranteed to be accurate except while processing
28702 `frame-title-format' and `icon-title-format'. */);
28704 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28705 doc
: /* Template for displaying the title bar of visible frames.
28706 \(Assuming the window manager supports this feature.)
28708 This variable has the same structure as `mode-line-format', except that
28709 the %c and %l constructs are ignored. It is used only on frames for
28710 which no explicit name has been set \(see `modify-frame-parameters'). */);
28712 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28713 doc
: /* Template for displaying the title bar of an iconified frame.
28714 \(Assuming the window manager supports this feature.)
28715 This variable has the same structure as `mode-line-format' (which see),
28716 and is used only on frames for which no explicit name has been set
28717 \(see `modify-frame-parameters'). */);
28719 = Vframe_title_format
28720 = pure_cons (intern_c_string ("multiple-frames"),
28721 pure_cons (make_pure_c_string ("%b"),
28722 pure_cons (pure_cons (empty_unibyte_string
,
28723 pure_cons (intern_c_string ("invocation-name"),
28724 pure_cons (make_pure_c_string ("@"),
28725 pure_cons (intern_c_string ("system-name"),
28729 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28730 doc
: /* Maximum number of lines to keep in the message log buffer.
28731 If nil, disable message logging. If t, log messages but don't truncate
28732 the buffer when it becomes large. */);
28733 Vmessage_log_max
= make_number (100);
28735 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28736 doc
: /* Functions called before redisplay, if window sizes have changed.
28737 The value should be a list of functions that take one argument.
28738 Just before redisplay, for each frame, if any of its windows have changed
28739 size since the last redisplay, or have been split or deleted,
28740 all the functions in the list are called, with the frame as argument. */);
28741 Vwindow_size_change_functions
= Qnil
;
28743 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28744 doc
: /* List of functions to call before redisplaying a window with scrolling.
28745 Each function is called with two arguments, the window and its new
28746 display-start position. Note that these functions are also called by
28747 `set-window-buffer'. Also note that the value of `window-end' is not
28748 valid when these functions are called.
28750 Warning: Do not use this feature to alter the way the window
28751 is scrolled. It is not designed for that, and such use probably won't
28753 Vwindow_scroll_functions
= Qnil
;
28755 DEFVAR_LISP ("window-text-change-functions",
28756 Vwindow_text_change_functions
,
28757 doc
: /* Functions to call in redisplay when text in the window might change. */);
28758 Vwindow_text_change_functions
= Qnil
;
28760 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28761 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28762 Each function is called with two arguments, the window and the end trigger value.
28763 See `set-window-redisplay-end-trigger'. */);
28764 Vredisplay_end_trigger_functions
= Qnil
;
28766 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28767 doc
: /* Non-nil means autoselect window with mouse pointer.
28768 If nil, do not autoselect windows.
28769 A positive number means delay autoselection by that many seconds: a
28770 window is autoselected only after the mouse has remained in that
28771 window for the duration of the delay.
28772 A negative number has a similar effect, but causes windows to be
28773 autoselected only after the mouse has stopped moving. \(Because of
28774 the way Emacs compares mouse events, you will occasionally wait twice
28775 that time before the window gets selected.\)
28776 Any other value means to autoselect window instantaneously when the
28777 mouse pointer enters it.
28779 Autoselection selects the minibuffer only if it is active, and never
28780 unselects the minibuffer if it is active.
28782 When customizing this variable make sure that the actual value of
28783 `focus-follows-mouse' matches the behavior of your window manager. */);
28784 Vmouse_autoselect_window
= Qnil
;
28786 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28787 doc
: /* Non-nil means automatically resize tool-bars.
28788 This dynamically changes the tool-bar's height to the minimum height
28789 that is needed to make all tool-bar items visible.
28790 If value is `grow-only', the tool-bar's height is only increased
28791 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28792 Vauto_resize_tool_bars
= Qt
;
28794 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28795 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28796 auto_raise_tool_bar_buttons_p
= 1;
28798 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28799 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28800 make_cursor_line_fully_visible_p
= 1;
28802 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28803 doc
: /* Border below tool-bar in pixels.
28804 If an integer, use it as the height of the border.
28805 If it is one of `internal-border-width' or `border-width', use the
28806 value of the corresponding frame parameter.
28807 Otherwise, no border is added below the tool-bar. */);
28808 Vtool_bar_border
= Qinternal_border_width
;
28810 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28811 doc
: /* Margin around tool-bar buttons in pixels.
28812 If an integer, use that for both horizontal and vertical margins.
28813 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28814 HORZ specifying the horizontal margin, and VERT specifying the
28815 vertical margin. */);
28816 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28818 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28819 doc
: /* Relief thickness of tool-bar buttons. */);
28820 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28822 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28823 doc
: /* Tool bar style to use.
28825 image - show images only
28826 text - show text only
28827 both - show both, text below image
28828 both-horiz - show text to the right of the image
28829 text-image-horiz - show text to the left of the image
28830 any other - use system default or image if no system default.
28832 This variable only affects the GTK+ toolkit version of Emacs. */);
28833 Vtool_bar_style
= Qnil
;
28835 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28836 doc
: /* Maximum number of characters a label can have to be shown.
28837 The tool bar style must also show labels for this to have any effect, see
28838 `tool-bar-style'. */);
28839 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28841 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28842 doc
: /* List of functions to call to fontify regions of text.
28843 Each function is called with one argument POS. Functions must
28844 fontify a region starting at POS in the current buffer, and give
28845 fontified regions the property `fontified'. */);
28846 Vfontification_functions
= Qnil
;
28847 Fmake_variable_buffer_local (Qfontification_functions
);
28849 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28850 unibyte_display_via_language_environment
,
28851 doc
: /* Non-nil means display unibyte text according to language environment.
28852 Specifically, this means that raw bytes in the range 160-255 decimal
28853 are displayed by converting them to the equivalent multibyte characters
28854 according to the current language environment. As a result, they are
28855 displayed according to the current fontset.
28857 Note that this variable affects only how these bytes are displayed,
28858 but does not change the fact they are interpreted as raw bytes. */);
28859 unibyte_display_via_language_environment
= 0;
28861 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28862 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
28863 If a float, it specifies a fraction of the mini-window frame's height.
28864 If an integer, it specifies a number of lines. */);
28865 Vmax_mini_window_height
= make_float (0.25);
28867 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28868 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28869 A value of nil means don't automatically resize mini-windows.
28870 A value of t means resize them to fit the text displayed in them.
28871 A value of `grow-only', the default, means let mini-windows grow only;
28872 they return to their normal size when the minibuffer is closed, or the
28873 echo area becomes empty. */);
28874 Vresize_mini_windows
= Qgrow_only
;
28876 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28877 doc
: /* Alist specifying how to blink the cursor off.
28878 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28879 `cursor-type' frame-parameter or variable equals ON-STATE,
28880 comparing using `equal', Emacs uses OFF-STATE to specify
28881 how to blink it off. ON-STATE and OFF-STATE are values for
28882 the `cursor-type' frame parameter.
28884 If a frame's ON-STATE has no entry in this list,
28885 the frame's other specifications determine how to blink the cursor off. */);
28886 Vblink_cursor_alist
= Qnil
;
28888 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28889 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28890 If non-nil, windows are automatically scrolled horizontally to make
28891 point visible. */);
28892 automatic_hscrolling_p
= 1;
28893 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28895 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28896 doc
: /* How many columns away from the window edge point is allowed to get
28897 before automatic hscrolling will horizontally scroll the window. */);
28898 hscroll_margin
= 5;
28900 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28901 doc
: /* How many columns to scroll the window when point gets too close to the edge.
28902 When point is less than `hscroll-margin' columns from the window
28903 edge, automatic hscrolling will scroll the window by the amount of columns
28904 determined by this variable. If its value is a positive integer, scroll that
28905 many columns. If it's a positive floating-point number, it specifies the
28906 fraction of the window's width to scroll. If it's nil or zero, point will be
28907 centered horizontally after the scroll. Any other value, including negative
28908 numbers, are treated as if the value were zero.
28910 Automatic hscrolling always moves point outside the scroll margin, so if
28911 point was more than scroll step columns inside the margin, the window will
28912 scroll more than the value given by the scroll step.
28914 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28915 and `scroll-right' overrides this variable's effect. */);
28916 Vhscroll_step
= make_number (0);
28918 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28919 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28920 Bind this around calls to `message' to let it take effect. */);
28921 message_truncate_lines
= 0;
28923 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28924 doc
: /* Normal hook run to update the menu bar definitions.
28925 Redisplay runs this hook before it redisplays the menu bar.
28926 This is used to update submenus such as Buffers,
28927 whose contents depend on various data. */);
28928 Vmenu_bar_update_hook
= Qnil
;
28930 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28931 doc
: /* Frame for which we are updating a menu.
28932 The enable predicate for a menu binding should check this variable. */);
28933 Vmenu_updating_frame
= Qnil
;
28935 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28936 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28937 inhibit_menubar_update
= 0;
28939 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28940 doc
: /* Prefix prepended to all continuation lines at display time.
28941 The value may be a string, an image, or a stretch-glyph; it is
28942 interpreted in the same way as the value of a `display' text property.
28944 This variable is overridden by any `wrap-prefix' text or overlay
28947 To add a prefix to non-continuation lines, use `line-prefix'. */);
28948 Vwrap_prefix
= Qnil
;
28949 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28950 Fmake_variable_buffer_local (Qwrap_prefix
);
28952 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28953 doc
: /* Prefix prepended to all non-continuation lines at display time.
28954 The value may be a string, an image, or a stretch-glyph; it is
28955 interpreted in the same way as the value of a `display' text property.
28957 This variable is overridden by any `line-prefix' text or overlay
28960 To add a prefix to continuation lines, use `wrap-prefix'. */);
28961 Vline_prefix
= Qnil
;
28962 DEFSYM (Qline_prefix
, "line-prefix");
28963 Fmake_variable_buffer_local (Qline_prefix
);
28965 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28966 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28967 inhibit_eval_during_redisplay
= 0;
28969 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28970 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28971 inhibit_free_realized_faces
= 0;
28974 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28975 doc
: /* Inhibit try_window_id display optimization. */);
28976 inhibit_try_window_id
= 0;
28978 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28979 doc
: /* Inhibit try_window_reusing display optimization. */);
28980 inhibit_try_window_reusing
= 0;
28982 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28983 doc
: /* Inhibit try_cursor_movement display optimization. */);
28984 inhibit_try_cursor_movement
= 0;
28985 #endif /* GLYPH_DEBUG */
28987 DEFVAR_INT ("overline-margin", overline_margin
,
28988 doc
: /* Space between overline and text, in pixels.
28989 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28990 margin to the character height. */);
28991 overline_margin
= 2;
28993 DEFVAR_INT ("underline-minimum-offset",
28994 underline_minimum_offset
,
28995 doc
: /* Minimum distance between baseline and underline.
28996 This can improve legibility of underlined text at small font sizes,
28997 particularly when using variable `x-use-underline-position-properties'
28998 with fonts that specify an UNDERLINE_POSITION relatively close to the
28999 baseline. The default value is 1. */);
29000 underline_minimum_offset
= 1;
29002 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29003 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29004 This feature only works when on a window system that can change
29005 cursor shapes. */);
29006 display_hourglass_p
= 1;
29008 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29009 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29010 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29012 hourglass_atimer
= NULL
;
29013 hourglass_shown_p
= 0;
29015 DEFSYM (Qglyphless_char
, "glyphless-char");
29016 DEFSYM (Qhex_code
, "hex-code");
29017 DEFSYM (Qempty_box
, "empty-box");
29018 DEFSYM (Qthin_space
, "thin-space");
29019 DEFSYM (Qzero_width
, "zero-width");
29021 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29022 /* Intern this now in case it isn't already done.
29023 Setting this variable twice is harmless.
29024 But don't staticpro it here--that is done in alloc.c. */
29025 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29026 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29028 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29029 doc
: /* Char-table defining glyphless characters.
29030 Each element, if non-nil, should be one of the following:
29031 an ASCII acronym string: display this string in a box
29032 `hex-code': display the hexadecimal code of a character in a box
29033 `empty-box': display as an empty box
29034 `thin-space': display as 1-pixel width space
29035 `zero-width': don't display
29036 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29037 display method for graphical terminals and text terminals respectively.
29038 GRAPHICAL and TEXT should each have one of the values listed above.
29040 The char-table has one extra slot to control the display of a character for
29041 which no font is found. This slot only takes effect on graphical terminals.
29042 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29043 `thin-space'. The default is `empty-box'. */);
29044 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29045 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29050 /* Initialize this module when Emacs starts. */
29055 current_header_line_height
= current_mode_line_height
= -1;
29057 CHARPOS (this_line_start_pos
) = 0;
29059 if (!noninteractive
)
29061 struct window
*m
= XWINDOW (minibuf_window
);
29062 Lisp_Object frame
= m
->frame
;
29063 struct frame
*f
= XFRAME (frame
);
29064 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29065 struct window
*r
= XWINDOW (root
);
29068 echo_area_window
= minibuf_window
;
29070 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
29071 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
29072 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
29073 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
29074 XSETFASTINT (m
->total_lines
, 1);
29075 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
29077 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29078 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29079 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29081 /* The default ellipsis glyphs `...'. */
29082 for (i
= 0; i
< 3; ++i
)
29083 default_invis_vector
[i
] = make_number ('.');
29087 /* Allocate the buffer for frame titles.
29088 Also used for `format-mode-line'. */
29090 mode_line_noprop_buf
= xmalloc (size
);
29091 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29092 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29093 mode_line_target
= MODE_LINE_DISPLAY
;
29096 help_echo_showing_p
= 0;
29099 /* Since w32 does not support atimers, it defines its own implementation of
29100 the following three functions in w32fns.c. */
29103 /* Platform-independent portion of hourglass implementation. */
29105 /* Cancel a currently active hourglass timer, and start a new one. */
29107 start_hourglass (void)
29109 #if defined (HAVE_WINDOW_SYSTEM)
29112 cancel_hourglass ();
29114 if (INTEGERP (Vhourglass_delay
)
29115 && XINT (Vhourglass_delay
) > 0)
29116 EMACS_SET_SECS_NSECS (delay
,
29117 min (XINT (Vhourglass_delay
), TYPE_MAXIMUM (time_t)),
29119 else if (FLOATP (Vhourglass_delay
)
29120 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29121 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29123 EMACS_SET_SECS_NSECS (delay
, DEFAULT_HOURGLASS_DELAY
, 0);
29125 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29126 show_hourglass
, NULL
);
29131 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29134 cancel_hourglass (void)
29136 #if defined (HAVE_WINDOW_SYSTEM)
29137 if (hourglass_atimer
)
29139 cancel_atimer (hourglass_atimer
);
29140 hourglass_atimer
= NULL
;
29143 if (hourglass_shown_p
)
29147 #endif /* ! WINDOWSNT */