1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
285 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT, or the underlying buffer
387 or string character, is a space or a TAB character. This is used
388 to determine where word wrapping can occur. */
390 #define IT_DISPLAYING_WHITESPACE(it) \
391 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
392 || ((STRINGP (it->string) \
393 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
394 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
396 && (it->s[IT_BYTEPOS (*it)] == ' ' \
397 || it->s[IT_BYTEPOS (*it)] == '\t')) \
398 || (IT_BYTEPOS (*it) < ZV_BYTE \
399 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
400 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
402 /* Name of the face used to highlight trailing whitespace. */
404 static Lisp_Object Qtrailing_whitespace
;
406 /* Name and number of the face used to highlight escape glyphs. */
408 static Lisp_Object Qescape_glyph
;
410 /* Name and number of the face used to highlight non-breaking spaces. */
412 static Lisp_Object Qnobreak_space
;
414 /* The symbol `image' which is the car of the lists used to represent
415 images in Lisp. Also a tool bar style. */
419 /* The image map types. */
421 static Lisp_Object QCpointer
;
422 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
424 /* Tool bar styles */
425 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
427 /* Non-zero means print newline to stdout before next mini-buffer
430 int noninteractive_need_newline
;
432 /* Non-zero means print newline to message log before next message. */
434 static int message_log_need_newline
;
436 /* Three markers that message_dolog uses.
437 It could allocate them itself, but that causes trouble
438 in handling memory-full errors. */
439 static Lisp_Object message_dolog_marker1
;
440 static Lisp_Object message_dolog_marker2
;
441 static Lisp_Object message_dolog_marker3
;
443 /* The buffer position of the first character appearing entirely or
444 partially on the line of the selected window which contains the
445 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
446 redisplay optimization in redisplay_internal. */
448 static struct text_pos this_line_start_pos
;
450 /* Number of characters past the end of the line above, including the
451 terminating newline. */
453 static struct text_pos this_line_end_pos
;
455 /* The vertical positions and the height of this line. */
457 static int this_line_vpos
;
458 static int this_line_y
;
459 static int this_line_pixel_height
;
461 /* X position at which this display line starts. Usually zero;
462 negative if first character is partially visible. */
464 static int this_line_start_x
;
466 /* The smallest character position seen by move_it_* functions as they
467 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
468 hscrolled lines, see display_line. */
470 static struct text_pos this_line_min_pos
;
472 /* Buffer that this_line_.* variables are referring to. */
474 static struct buffer
*this_line_buffer
;
477 /* Values of those variables at last redisplay are stored as
478 properties on `overlay-arrow-position' symbol. However, if
479 Voverlay_arrow_position is a marker, last-arrow-position is its
480 numerical position. */
482 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
484 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
485 properties on a symbol in overlay-arrow-variable-list. */
487 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
489 Lisp_Object Qmenu_bar_update_hook
;
491 /* Nonzero if an overlay arrow has been displayed in this window. */
493 static int overlay_arrow_seen
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* This is the window where the echo area message was displayed. It
506 is always a mini-buffer window, but it may not be the same window
507 currently active as a mini-buffer. */
509 Lisp_Object echo_area_window
;
511 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
512 pushes the current message and the value of
513 message_enable_multibyte on the stack, the function restore_message
514 pops the stack and displays MESSAGE again. */
516 static Lisp_Object Vmessage_stack
;
518 /* Nonzero means multibyte characters were enabled when the echo area
519 message was specified. */
521 static int message_enable_multibyte
;
523 /* Nonzero if we should redraw the mode lines on the next redisplay. */
525 int update_mode_lines
;
527 /* Nonzero if window sizes or contents have changed since last
528 redisplay that finished. */
530 int windows_or_buffers_changed
;
532 /* Nonzero means a frame's cursor type has been changed. */
534 int cursor_type_changed
;
536 /* Nonzero after display_mode_line if %l was used and it displayed a
539 static int line_number_displayed
;
541 /* The name of the *Messages* buffer, a string. */
543 static Lisp_Object Vmessages_buffer_name
;
545 /* Current, index 0, and last displayed echo area message. Either
546 buffers from echo_buffers, or nil to indicate no message. */
548 Lisp_Object echo_area_buffer
[2];
550 /* The buffers referenced from echo_area_buffer. */
552 static Lisp_Object echo_buffer
[2];
554 /* A vector saved used in with_area_buffer to reduce consing. */
556 static Lisp_Object Vwith_echo_area_save_vector
;
558 /* Non-zero means display_echo_area should display the last echo area
559 message again. Set by redisplay_preserve_echo_area. */
561 static int display_last_displayed_message_p
;
563 /* Nonzero if echo area is being used by print; zero if being used by
566 static int message_buf_print
;
568 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
570 static Lisp_Object Qinhibit_menubar_update
;
571 static Lisp_Object Qmessage_truncate_lines
;
573 /* Set to 1 in clear_message to make redisplay_internal aware
574 of an emptied echo area. */
576 static int message_cleared_p
;
578 /* A scratch glyph row with contents used for generating truncation
579 glyphs. Also used in direct_output_for_insert. */
581 #define MAX_SCRATCH_GLYPHS 100
582 static struct glyph_row scratch_glyph_row
;
583 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
585 /* Ascent and height of the last line processed by move_it_to. */
587 static int last_max_ascent
, last_height
;
589 /* Non-zero if there's a help-echo in the echo area. */
591 int help_echo_showing_p
;
593 /* If >= 0, computed, exact values of mode-line and header-line height
594 to use in the macros CURRENT_MODE_LINE_HEIGHT and
595 CURRENT_HEADER_LINE_HEIGHT. */
597 int current_mode_line_height
, current_header_line_height
;
599 /* The maximum distance to look ahead for text properties. Values
600 that are too small let us call compute_char_face and similar
601 functions too often which is expensive. Values that are too large
602 let us call compute_char_face and alike too often because we
603 might not be interested in text properties that far away. */
605 #define TEXT_PROP_DISTANCE_LIMIT 100
607 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
608 iterator state and later restore it. This is needed because the
609 bidi iterator on bidi.c keeps a stacked cache of its states, which
610 is really a singleton. When we use scratch iterator objects to
611 move around the buffer, we can cause the bidi cache to be pushed or
612 popped, and therefore we need to restore the cache state when we
613 return to the original iterator. */
614 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
617 bidi_unshelve_cache (CACHE, 1); \
619 CACHE = bidi_shelve_cache (); \
622 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
624 if (pITORIG != pITCOPY) \
625 *(pITORIG) = *(pITCOPY); \
626 bidi_unshelve_cache (CACHE, 0); \
632 /* Non-zero means print traces of redisplay if compiled with
635 int trace_redisplay_p
;
637 #endif /* GLYPH_DEBUG */
639 #ifdef DEBUG_TRACE_MOVE
640 /* Non-zero means trace with TRACE_MOVE to stderr. */
643 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
645 #define TRACE_MOVE(x) (void) 0
648 static Lisp_Object Qauto_hscroll_mode
;
650 /* Buffer being redisplayed -- for redisplay_window_error. */
652 static struct buffer
*displayed_buffer
;
654 /* Value returned from text property handlers (see below). */
659 HANDLED_RECOMPUTE_PROPS
,
660 HANDLED_OVERLAY_STRING_CONSUMED
,
664 /* A description of text properties that redisplay is interested
669 /* The name of the property. */
672 /* A unique index for the property. */
675 /* A handler function called to set up iterator IT from the property
676 at IT's current position. Value is used to steer handle_stop. */
677 enum prop_handled (*handler
) (struct it
*it
);
680 static enum prop_handled
handle_face_prop (struct it
*);
681 static enum prop_handled
handle_invisible_prop (struct it
*);
682 static enum prop_handled
handle_display_prop (struct it
*);
683 static enum prop_handled
handle_composition_prop (struct it
*);
684 static enum prop_handled
handle_overlay_change (struct it
*);
685 static enum prop_handled
handle_fontified_prop (struct it
*);
687 /* Properties handled by iterators. */
689 static struct props it_props
[] =
691 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
692 /* Handle `face' before `display' because some sub-properties of
693 `display' need to know the face. */
694 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
695 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
696 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
697 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
701 /* Value is the position described by X. If X is a marker, value is
702 the marker_position of X. Otherwise, value is X. */
704 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
706 /* Enumeration returned by some move_it_.* functions internally. */
710 /* Not used. Undefined value. */
713 /* Move ended at the requested buffer position or ZV. */
714 MOVE_POS_MATCH_OR_ZV
,
716 /* Move ended at the requested X pixel position. */
719 /* Move within a line ended at the end of a line that must be
723 /* Move within a line ended at the end of a line that would
724 be displayed truncated. */
727 /* Move within a line ended at a line end. */
731 /* This counter is used to clear the face cache every once in a while
732 in redisplay_internal. It is incremented for each redisplay.
733 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
736 #define CLEAR_FACE_CACHE_COUNT 500
737 static int clear_face_cache_count
;
739 /* Similarly for the image cache. */
741 #ifdef HAVE_WINDOW_SYSTEM
742 #define CLEAR_IMAGE_CACHE_COUNT 101
743 static int clear_image_cache_count
;
745 /* Null glyph slice */
746 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
749 /* Non-zero while redisplay_internal is in progress. */
753 static Lisp_Object Qinhibit_free_realized_faces
;
755 /* If a string, XTread_socket generates an event to display that string.
756 (The display is done in read_char.) */
758 Lisp_Object help_echo_string
;
759 Lisp_Object help_echo_window
;
760 Lisp_Object help_echo_object
;
761 EMACS_INT help_echo_pos
;
763 /* Temporary variable for XTread_socket. */
765 Lisp_Object previous_help_echo_string
;
767 /* Platform-independent portion of hourglass implementation. */
769 /* Non-zero means an hourglass cursor is currently shown. */
770 int hourglass_shown_p
;
772 /* If non-null, an asynchronous timer that, when it expires, displays
773 an hourglass cursor on all frames. */
774 struct atimer
*hourglass_atimer
;
776 /* Name of the face used to display glyphless characters. */
777 Lisp_Object Qglyphless_char
;
779 /* Symbol for the purpose of Vglyphless_char_display. */
780 static Lisp_Object Qglyphless_char_display
;
782 /* Method symbols for Vglyphless_char_display. */
783 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
785 /* Default pixel width of `thin-space' display method. */
786 #define THIN_SPACE_WIDTH 1
788 /* Default number of seconds to wait before displaying an hourglass
790 #define DEFAULT_HOURGLASS_DELAY 1
793 /* Function prototypes. */
795 static void setup_for_ellipsis (struct it
*, int);
796 static void set_iterator_to_next (struct it
*, int);
797 static void mark_window_display_accurate_1 (struct window
*, int);
798 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
799 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
800 static int cursor_row_p (struct glyph_row
*);
801 static int redisplay_mode_lines (Lisp_Object
, int);
802 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
804 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
806 static void handle_line_prefix (struct it
*);
808 static void pint2str (char *, int, EMACS_INT
);
809 static void pint2hrstr (char *, int, EMACS_INT
);
810 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
812 static void reconsider_clip_changes (struct window
*, struct buffer
*);
813 static int text_outside_line_unchanged_p (struct window
*,
814 EMACS_INT
, EMACS_INT
);
815 static void store_mode_line_noprop_char (char);
816 static int store_mode_line_noprop (const char *, int, int);
817 static void handle_stop (struct it
*);
818 static void handle_stop_backwards (struct it
*, EMACS_INT
);
819 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
820 static void ensure_echo_area_buffers (void);
821 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
822 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
823 static int with_echo_area_buffer (struct window
*, int,
824 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
825 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
826 static void clear_garbaged_frames (void);
827 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
828 static void pop_message (void);
829 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
830 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
831 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
832 static int display_echo_area (struct window
*);
833 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
834 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
835 static Lisp_Object
unwind_redisplay (Lisp_Object
);
836 static int string_char_and_length (const unsigned char *, int *);
837 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
839 static int compute_window_start_on_continuation_line (struct window
*);
840 static Lisp_Object
safe_eval_handler (Lisp_Object
);
841 static void insert_left_trunc_glyphs (struct it
*);
842 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
844 static void extend_face_to_end_of_line (struct it
*);
845 static int append_space_for_newline (struct it
*, int);
846 static int cursor_row_fully_visible_p (struct window
*, int, int);
847 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
848 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
849 static int trailing_whitespace_p (EMACS_INT
);
850 static intmax_t message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
851 static void push_it (struct it
*, struct text_pos
*);
852 static void pop_it (struct it
*);
853 static void sync_frame_with_window_matrix_rows (struct window
*);
854 static void select_frame_for_redisplay (Lisp_Object
);
855 static void redisplay_internal (void);
856 static int echo_area_display (int);
857 static void redisplay_windows (Lisp_Object
);
858 static void redisplay_window (Lisp_Object
, int);
859 static Lisp_Object
redisplay_window_error (Lisp_Object
);
860 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
861 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
862 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
863 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
865 static int update_menu_bar (struct frame
*, int, int);
866 static int try_window_reusing_current_matrix (struct window
*);
867 static int try_window_id (struct window
*);
868 static int display_line (struct it
*);
869 static int display_mode_lines (struct window
*);
870 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
871 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
872 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
873 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
874 static void display_menu_bar (struct window
*);
875 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
877 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
878 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
879 static void compute_line_metrics (struct it
*);
880 static void run_redisplay_end_trigger_hook (struct it
*);
881 static int get_overlay_strings (struct it
*, EMACS_INT
);
882 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
883 static void next_overlay_string (struct it
*);
884 static void reseat (struct it
*, struct text_pos
, int);
885 static void reseat_1 (struct it
*, struct text_pos
, int);
886 static void back_to_previous_visible_line_start (struct it
*);
887 void reseat_at_previous_visible_line_start (struct it
*);
888 static void reseat_at_next_visible_line_start (struct it
*, int);
889 static int next_element_from_ellipsis (struct it
*);
890 static int next_element_from_display_vector (struct it
*);
891 static int next_element_from_string (struct it
*);
892 static int next_element_from_c_string (struct it
*);
893 static int next_element_from_buffer (struct it
*);
894 static int next_element_from_composition (struct it
*);
895 static int next_element_from_image (struct it
*);
896 static int next_element_from_stretch (struct it
*);
897 static void load_overlay_strings (struct it
*, EMACS_INT
);
898 static int init_from_display_pos (struct it
*, struct window
*,
899 struct display_pos
*);
900 static void reseat_to_string (struct it
*, const char *,
901 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
902 static int get_next_display_element (struct it
*);
903 static enum move_it_result
904 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
905 enum move_operation_enum
);
906 void move_it_vertically_backward (struct it
*, int);
907 static void init_to_row_start (struct it
*, struct window
*,
909 static int init_to_row_end (struct it
*, struct window
*,
911 static void back_to_previous_line_start (struct it
*);
912 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
913 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
914 Lisp_Object
, EMACS_INT
);
915 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
916 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
917 static EMACS_INT
number_of_chars (const char *, int);
918 static void compute_stop_pos (struct it
*);
919 static void compute_string_pos (struct text_pos
*, struct text_pos
,
921 static int face_before_or_after_it_pos (struct it
*, int);
922 static EMACS_INT
next_overlay_change (EMACS_INT
);
923 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
924 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
925 static int handle_single_display_spec (struct it
*, Lisp_Object
,
926 Lisp_Object
, Lisp_Object
,
927 struct text_pos
*, EMACS_INT
, int, int);
928 static int underlying_face_id (struct it
*);
929 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
932 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
933 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
935 #ifdef HAVE_WINDOW_SYSTEM
937 static void x_consider_frame_title (Lisp_Object
);
938 static int tool_bar_lines_needed (struct frame
*, int *);
939 static void update_tool_bar (struct frame
*, int);
940 static void build_desired_tool_bar_string (struct frame
*f
);
941 static int redisplay_tool_bar (struct frame
*);
942 static void display_tool_bar_line (struct it
*, int);
943 static void notice_overwritten_cursor (struct window
*,
946 static void append_stretch_glyph (struct it
*, Lisp_Object
,
950 #endif /* HAVE_WINDOW_SYSTEM */
952 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
953 static int coords_in_mouse_face_p (struct window
*, int, int);
957 /***********************************************************************
958 Window display dimensions
959 ***********************************************************************/
961 /* Return the bottom boundary y-position for text lines in window W.
962 This is the first y position at which a line cannot start.
963 It is relative to the top of the window.
965 This is the height of W minus the height of a mode line, if any. */
968 window_text_bottom_y (struct window
*w
)
970 int height
= WINDOW_TOTAL_HEIGHT (w
);
972 if (WINDOW_WANTS_MODELINE_P (w
))
973 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
977 /* Return the pixel width of display area AREA of window W. AREA < 0
978 means return the total width of W, not including fringes to
979 the left and right of the window. */
982 window_box_width (struct window
*w
, int area
)
984 int cols
= XFASTINT (w
->total_cols
);
987 if (!w
->pseudo_window_p
)
989 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
991 if (area
== TEXT_AREA
)
993 if (INTEGERP (w
->left_margin_cols
))
994 cols
-= XFASTINT (w
->left_margin_cols
);
995 if (INTEGERP (w
->right_margin_cols
))
996 cols
-= XFASTINT (w
->right_margin_cols
);
997 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
999 else if (area
== LEFT_MARGIN_AREA
)
1001 cols
= (INTEGERP (w
->left_margin_cols
)
1002 ? XFASTINT (w
->left_margin_cols
) : 0);
1005 else if (area
== RIGHT_MARGIN_AREA
)
1007 cols
= (INTEGERP (w
->right_margin_cols
)
1008 ? XFASTINT (w
->right_margin_cols
) : 0);
1013 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1017 /* Return the pixel height of the display area of window W, not
1018 including mode lines of W, if any. */
1021 window_box_height (struct window
*w
)
1023 struct frame
*f
= XFRAME (w
->frame
);
1024 int height
= WINDOW_TOTAL_HEIGHT (w
);
1026 xassert (height
>= 0);
1028 /* Note: the code below that determines the mode-line/header-line
1029 height is essentially the same as that contained in the macro
1030 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1031 the appropriate glyph row has its `mode_line_p' flag set,
1032 and if it doesn't, uses estimate_mode_line_height instead. */
1034 if (WINDOW_WANTS_MODELINE_P (w
))
1036 struct glyph_row
*ml_row
1037 = (w
->current_matrix
&& w
->current_matrix
->rows
1038 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1040 if (ml_row
&& ml_row
->mode_line_p
)
1041 height
-= ml_row
->height
;
1043 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1046 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1048 struct glyph_row
*hl_row
1049 = (w
->current_matrix
&& w
->current_matrix
->rows
1050 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1052 if (hl_row
&& hl_row
->mode_line_p
)
1053 height
-= hl_row
->height
;
1055 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1058 /* With a very small font and a mode-line that's taller than
1059 default, we might end up with a negative height. */
1060 return max (0, height
);
1063 /* Return the window-relative coordinate of the left edge of display
1064 area AREA of window W. AREA < 0 means return the left edge of the
1065 whole window, to the right of the left fringe of W. */
1068 window_box_left_offset (struct window
*w
, int area
)
1072 if (w
->pseudo_window_p
)
1075 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1077 if (area
== TEXT_AREA
)
1078 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1079 + window_box_width (w
, LEFT_MARGIN_AREA
));
1080 else if (area
== RIGHT_MARGIN_AREA
)
1081 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1082 + window_box_width (w
, LEFT_MARGIN_AREA
)
1083 + window_box_width (w
, TEXT_AREA
)
1084 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1086 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1087 else if (area
== LEFT_MARGIN_AREA
1088 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1089 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1095 /* Return the window-relative coordinate of the right edge of display
1096 area AREA of window W. AREA < 0 means return the right edge of the
1097 whole window, to the left of the right fringe of W. */
1100 window_box_right_offset (struct window
*w
, int area
)
1102 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1105 /* Return the frame-relative coordinate of the left edge of display
1106 area AREA of window W. AREA < 0 means return the left edge of the
1107 whole window, to the right of the left fringe of W. */
1110 window_box_left (struct window
*w
, int area
)
1112 struct frame
*f
= XFRAME (w
->frame
);
1115 if (w
->pseudo_window_p
)
1116 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1118 x
= (WINDOW_LEFT_EDGE_X (w
)
1119 + window_box_left_offset (w
, area
));
1125 /* Return the frame-relative coordinate of the right edge of display
1126 area AREA of window W. AREA < 0 means return the right edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right (struct window
*w
, int area
)
1132 return window_box_left (w
, area
) + window_box_width (w
, area
);
1135 /* Get the bounding box of the display area AREA of window W, without
1136 mode lines, in frame-relative coordinates. AREA < 0 means the
1137 whole window, not including the left and right fringes of
1138 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1139 coordinates of the upper-left corner of the box. Return in
1140 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1143 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1144 int *box_width
, int *box_height
)
1147 *box_width
= window_box_width (w
, area
);
1149 *box_height
= window_box_height (w
);
1151 *box_x
= window_box_left (w
, area
);
1154 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1155 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1156 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1161 /* Get the bounding box of the display area AREA of window W, without
1162 mode lines. AREA < 0 means the whole window, not including the
1163 left and right fringe of the window. Return in *TOP_LEFT_X
1164 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1165 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1166 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1170 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1171 int *bottom_right_x
, int *bottom_right_y
)
1173 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1175 *bottom_right_x
+= *top_left_x
;
1176 *bottom_right_y
+= *top_left_y
;
1181 /***********************************************************************
1183 ***********************************************************************/
1185 /* Return the bottom y-position of the line the iterator IT is in.
1186 This can modify IT's settings. */
1189 line_bottom_y (struct it
*it
)
1191 int line_height
= it
->max_ascent
+ it
->max_descent
;
1192 int line_top_y
= it
->current_y
;
1194 if (line_height
== 0)
1197 line_height
= last_height
;
1198 else if (IT_CHARPOS (*it
) < ZV
)
1200 move_it_by_lines (it
, 1);
1201 line_height
= (it
->max_ascent
|| it
->max_descent
1202 ? it
->max_ascent
+ it
->max_descent
1207 struct glyph_row
*row
= it
->glyph_row
;
1209 /* Use the default character height. */
1210 it
->glyph_row
= NULL
;
1211 it
->what
= IT_CHARACTER
;
1214 PRODUCE_GLYPHS (it
);
1215 line_height
= it
->ascent
+ it
->descent
;
1216 it
->glyph_row
= row
;
1220 return line_top_y
+ line_height
;
1223 /* Subroutine of pos_visible_p below. Extracts a display string, if
1224 any, from the display spec given as its argument. */
1226 string_from_display_spec (Lisp_Object spec
)
1230 while (CONSP (spec
))
1232 if (STRINGP (XCAR (spec
)))
1237 else if (VECTORP (spec
))
1241 for (i
= 0; i
< ASIZE (spec
); i
++)
1243 if (STRINGP (AREF (spec
, i
)))
1244 return AREF (spec
, i
);
1252 /* Return 1 if position CHARPOS is visible in window W.
1253 CHARPOS < 0 means return info about WINDOW_END position.
1254 If visible, set *X and *Y to pixel coordinates of top left corner.
1255 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1256 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1259 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1260 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1263 void *itdata
= bidi_shelve_cache ();
1264 struct text_pos top
;
1266 struct buffer
*old_buffer
= NULL
;
1268 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1271 if (XBUFFER (w
->buffer
) != current_buffer
)
1273 old_buffer
= current_buffer
;
1274 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1277 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1278 /* Scrolling a minibuffer window via scroll bar when the echo area
1279 shows long text sometimes resets the minibuffer contents behind
1281 if (CHARPOS (top
) > ZV
)
1282 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1284 /* Compute exact mode line heights. */
1285 if (WINDOW_WANTS_MODELINE_P (w
))
1286 current_mode_line_height
1287 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1288 BVAR (current_buffer
, mode_line_format
));
1290 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1291 current_header_line_height
1292 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1293 BVAR (current_buffer
, header_line_format
));
1295 start_display (&it
, w
, top
);
1296 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1297 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1300 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1301 && IT_CHARPOS (it
) >= charpos
)
1302 /* When scanning backwards under bidi iteration, move_it_to
1303 stops at or _before_ CHARPOS, because it stops at or to
1304 the _right_ of the character at CHARPOS. */
1305 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1306 && IT_CHARPOS (it
) <= charpos
)))
1308 /* We have reached CHARPOS, or passed it. How the call to
1309 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1310 or covered by a display property, move_it_to stops at the end
1311 of the invisible text, to the right of CHARPOS. (ii) If
1312 CHARPOS is in a display vector, move_it_to stops on its last
1314 int top_x
= it
.current_x
;
1315 int top_y
= it
.current_y
;
1316 enum it_method it_method
= it
.method
;
1317 /* Calling line_bottom_y may change it.method, it.position, etc. */
1318 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1319 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1321 if (top_y
< window_top_y
)
1322 visible_p
= bottom_y
> window_top_y
;
1323 else if (top_y
< it
.last_visible_y
)
1327 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1329 /* We stopped on the last glyph of a display vector.
1330 Try and recompute. Hack alert! */
1331 if (charpos
< 2 || top
.charpos
>= charpos
)
1332 top_x
= it
.glyph_row
->x
;
1336 start_display (&it2
, w
, top
);
1337 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1338 get_next_display_element (&it2
);
1339 PRODUCE_GLYPHS (&it2
);
1340 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1341 || it2
.current_x
> it2
.last_visible_x
)
1342 top_x
= it
.glyph_row
->x
;
1345 top_x
= it2
.current_x
;
1346 top_y
= it2
.current_y
;
1350 else if (IT_CHARPOS (it
) != charpos
)
1352 Lisp_Object cpos
= make_number (charpos
);
1353 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1354 Lisp_Object string
= string_from_display_spec (spec
);
1355 int newline_in_string
= 0;
1357 if (STRINGP (string
))
1359 const char *s
= SSDATA (string
);
1360 const char *e
= s
+ SBYTES (string
);
1365 newline_in_string
= 1;
1370 /* The tricky code below is needed because there's a
1371 discrepancy between move_it_to and how we set cursor
1372 when the display line ends in a newline from a
1373 display string. move_it_to will stop _after_ such
1374 display strings, whereas set_cursor_from_row
1375 conspires with cursor_row_p to place the cursor on
1376 the first glyph produced from the display string. */
1378 /* We have overshoot PT because it is covered by a
1379 display property whose value is a string. If the
1380 string includes embedded newlines, we are also in the
1381 wrong display line. Backtrack to the correct line,
1382 where the display string begins. */
1383 if (newline_in_string
)
1385 Lisp_Object startpos
, endpos
;
1386 EMACS_INT start
, end
;
1390 /* Find the first and the last buffer positions
1391 covered by the display string. */
1393 Fnext_single_char_property_change (cpos
, Qdisplay
,
1396 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1398 start
= XFASTINT (startpos
);
1399 end
= XFASTINT (endpos
);
1400 /* Move to the last buffer position before the
1401 display property. */
1402 start_display (&it3
, w
, top
);
1403 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1404 /* Move forward one more line if the position before
1405 the display string is a newline or if it is the
1406 rightmost character on a line that is
1407 continued or word-wrapped. */
1408 if (it3
.method
== GET_FROM_BUFFER
1410 move_it_by_lines (&it3
, 1);
1411 else if (move_it_in_display_line_to (&it3
, -1,
1415 == MOVE_LINE_CONTINUED
)
1417 move_it_by_lines (&it3
, 1);
1418 /* When we are under word-wrap, the #$@%!
1419 move_it_by_lines moves 2 lines, so we need to
1421 if (it3
.line_wrap
== WORD_WRAP
)
1422 move_it_by_lines (&it3
, -1);
1425 /* Record the vertical coordinate of the display
1426 line where we wound up. */
1427 top_y
= it3
.current_y
;
1430 /* When characters are reordered for display,
1431 the character displayed to the left of the
1432 display string could be _after_ the display
1433 property in the logical order. Use the
1434 smallest vertical position of these two. */
1435 start_display (&it3
, w
, top
);
1436 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1437 if (it3
.current_y
< top_y
)
1438 top_y
= it3
.current_y
;
1440 /* Move from the top of the window to the beginning
1441 of the display line where the display string
1443 start_display (&it3
, w
, top
);
1444 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1445 /* If it3_moved stays zero after the 'while' loop
1446 below, that means we already were at a newline
1447 before the loop (e.g., the display string begins
1448 with a newline), so we don't need to (and cannot)
1449 inspect the glyphs of it3.glyph_row, because
1450 PRODUCE_GLYPHS will not produce anything for a
1451 newline, and thus it3.glyph_row stays at its
1452 stale content it got at top of the window. */
1454 /* Finally, advance the iterator until we hit the
1455 first display element whose character position is
1456 CHARPOS, or until the first newline from the
1457 display string, which signals the end of the
1459 while (get_next_display_element (&it3
))
1461 PRODUCE_GLYPHS (&it3
);
1462 if (IT_CHARPOS (it3
) == charpos
1463 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1466 set_iterator_to_next (&it3
, 0);
1468 top_x
= it3
.current_x
- it3
.pixel_width
;
1469 /* Normally, we would exit the above loop because we
1470 found the display element whose character
1471 position is CHARPOS. For the contingency that we
1472 didn't, and stopped at the first newline from the
1473 display string, move back over the glyphs
1474 produced from the string, until we find the
1475 rightmost glyph not from the string. */
1477 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1479 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1480 + it3
.glyph_row
->used
[TEXT_AREA
];
1482 while (EQ ((g
- 1)->object
, string
))
1485 top_x
-= g
->pixel_width
;
1487 xassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1488 + it3
.glyph_row
->used
[TEXT_AREA
]);
1494 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1495 *rtop
= max (0, window_top_y
- top_y
);
1496 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1497 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1498 - max (top_y
, window_top_y
)));
1504 /* We were asked to provide info about WINDOW_END. */
1506 void *it2data
= NULL
;
1508 SAVE_IT (it2
, it
, it2data
);
1509 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1510 move_it_by_lines (&it
, 1);
1511 if (charpos
< IT_CHARPOS (it
)
1512 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1515 RESTORE_IT (&it2
, &it2
, it2data
);
1516 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1518 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1519 *rtop
= max (0, -it2
.current_y
);
1520 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1521 - it
.last_visible_y
));
1522 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1524 - max (it2
.current_y
,
1525 WINDOW_HEADER_LINE_HEIGHT (w
))));
1529 bidi_unshelve_cache (it2data
, 1);
1531 bidi_unshelve_cache (itdata
, 0);
1534 set_buffer_internal_1 (old_buffer
);
1536 current_header_line_height
= current_mode_line_height
= -1;
1538 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1539 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1542 /* Debugging code. */
1544 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1545 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1547 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1554 /* Return the next character from STR. Return in *LEN the length of
1555 the character. This is like STRING_CHAR_AND_LENGTH but never
1556 returns an invalid character. If we find one, we return a `?', but
1557 with the length of the invalid character. */
1560 string_char_and_length (const unsigned char *str
, int *len
)
1564 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1565 if (!CHAR_VALID_P (c
))
1566 /* We may not change the length here because other places in Emacs
1567 don't use this function, i.e. they silently accept invalid
1576 /* Given a position POS containing a valid character and byte position
1577 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1579 static struct text_pos
1580 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1582 xassert (STRINGP (string
) && nchars
>= 0);
1584 if (STRING_MULTIBYTE (string
))
1586 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1591 string_char_and_length (p
, &len
);
1594 BYTEPOS (pos
) += len
;
1598 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1604 /* Value is the text position, i.e. character and byte position,
1605 for character position CHARPOS in STRING. */
1607 static inline struct text_pos
1608 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1610 struct text_pos pos
;
1611 xassert (STRINGP (string
));
1612 xassert (charpos
>= 0);
1613 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1618 /* Value is a text position, i.e. character and byte position, for
1619 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1620 means recognize multibyte characters. */
1622 static struct text_pos
1623 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1625 struct text_pos pos
;
1627 xassert (s
!= NULL
);
1628 xassert (charpos
>= 0);
1634 SET_TEXT_POS (pos
, 0, 0);
1637 string_char_and_length ((const unsigned char *) s
, &len
);
1640 BYTEPOS (pos
) += len
;
1644 SET_TEXT_POS (pos
, charpos
, charpos
);
1650 /* Value is the number of characters in C string S. MULTIBYTE_P
1651 non-zero means recognize multibyte characters. */
1654 number_of_chars (const char *s
, int multibyte_p
)
1660 EMACS_INT rest
= strlen (s
);
1662 const unsigned char *p
= (const unsigned char *) s
;
1664 for (nchars
= 0; rest
> 0; ++nchars
)
1666 string_char_and_length (p
, &len
);
1667 rest
-= len
, p
+= len
;
1671 nchars
= strlen (s
);
1677 /* Compute byte position NEWPOS->bytepos corresponding to
1678 NEWPOS->charpos. POS is a known position in string STRING.
1679 NEWPOS->charpos must be >= POS.charpos. */
1682 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1684 xassert (STRINGP (string
));
1685 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1687 if (STRING_MULTIBYTE (string
))
1688 *newpos
= string_pos_nchars_ahead (pos
, string
,
1689 CHARPOS (*newpos
) - CHARPOS (pos
));
1691 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1695 Return an estimation of the pixel height of mode or header lines on
1696 frame F. FACE_ID specifies what line's height to estimate. */
1699 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1701 #ifdef HAVE_WINDOW_SYSTEM
1702 if (FRAME_WINDOW_P (f
))
1704 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1706 /* This function is called so early when Emacs starts that the face
1707 cache and mode line face are not yet initialized. */
1708 if (FRAME_FACE_CACHE (f
))
1710 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1714 height
= FONT_HEIGHT (face
->font
);
1715 if (face
->box_line_width
> 0)
1716 height
+= 2 * face
->box_line_width
;
1727 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1728 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1729 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1730 not force the value into range. */
1733 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1734 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1737 #ifdef HAVE_WINDOW_SYSTEM
1738 if (FRAME_WINDOW_P (f
))
1740 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1741 even for negative values. */
1743 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1745 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1747 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1748 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1751 STORE_NATIVE_RECT (*bounds
,
1752 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1753 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1754 FRAME_COLUMN_WIDTH (f
) - 1,
1755 FRAME_LINE_HEIGHT (f
) - 1);
1761 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1762 pix_x
= FRAME_TOTAL_COLS (f
);
1766 else if (pix_y
> FRAME_LINES (f
))
1767 pix_y
= FRAME_LINES (f
);
1777 /* Find the glyph under window-relative coordinates X/Y in window W.
1778 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1779 strings. Return in *HPOS and *VPOS the row and column number of
1780 the glyph found. Return in *AREA the glyph area containing X.
1781 Value is a pointer to the glyph found or null if X/Y is not on
1782 text, or we can't tell because W's current matrix is not up to
1787 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1788 int *dx
, int *dy
, int *area
)
1790 struct glyph
*glyph
, *end
;
1791 struct glyph_row
*row
= NULL
;
1794 /* Find row containing Y. Give up if some row is not enabled. */
1795 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1797 row
= MATRIX_ROW (w
->current_matrix
, i
);
1798 if (!row
->enabled_p
)
1800 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1807 /* Give up if Y is not in the window. */
1808 if (i
== w
->current_matrix
->nrows
)
1811 /* Get the glyph area containing X. */
1812 if (w
->pseudo_window_p
)
1819 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1821 *area
= LEFT_MARGIN_AREA
;
1822 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1824 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1827 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1831 *area
= RIGHT_MARGIN_AREA
;
1832 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1836 /* Find glyph containing X. */
1837 glyph
= row
->glyphs
[*area
];
1838 end
= glyph
+ row
->used
[*area
];
1840 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1842 x
-= glyph
->pixel_width
;
1852 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1855 *hpos
= glyph
- row
->glyphs
[*area
];
1859 /* Convert frame-relative x/y to coordinates relative to window W.
1860 Takes pseudo-windows into account. */
1863 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1865 if (w
->pseudo_window_p
)
1867 /* A pseudo-window is always full-width, and starts at the
1868 left edge of the frame, plus a frame border. */
1869 struct frame
*f
= XFRAME (w
->frame
);
1870 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1871 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1875 *x
-= WINDOW_LEFT_EDGE_X (w
);
1876 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1880 #ifdef HAVE_WINDOW_SYSTEM
1883 Return in RECTS[] at most N clipping rectangles for glyph string S.
1884 Return the number of stored rectangles. */
1887 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1894 if (s
->row
->full_width_p
)
1896 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1897 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1898 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1900 /* Unless displaying a mode or menu bar line, which are always
1901 fully visible, clip to the visible part of the row. */
1902 if (s
->w
->pseudo_window_p
)
1903 r
.height
= s
->row
->visible_height
;
1905 r
.height
= s
->height
;
1909 /* This is a text line that may be partially visible. */
1910 r
.x
= window_box_left (s
->w
, s
->area
);
1911 r
.width
= window_box_width (s
->w
, s
->area
);
1912 r
.height
= s
->row
->visible_height
;
1916 if (r
.x
< s
->clip_head
->x
)
1918 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1919 r
.width
-= s
->clip_head
->x
- r
.x
;
1922 r
.x
= s
->clip_head
->x
;
1925 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1927 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1928 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1933 /* If S draws overlapping rows, it's sufficient to use the top and
1934 bottom of the window for clipping because this glyph string
1935 intentionally draws over other lines. */
1936 if (s
->for_overlaps
)
1938 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1939 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1941 /* Alas, the above simple strategy does not work for the
1942 environments with anti-aliased text: if the same text is
1943 drawn onto the same place multiple times, it gets thicker.
1944 If the overlap we are processing is for the erased cursor, we
1945 take the intersection with the rectangle of the cursor. */
1946 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1948 XRectangle rc
, r_save
= r
;
1950 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1951 rc
.y
= s
->w
->phys_cursor
.y
;
1952 rc
.width
= s
->w
->phys_cursor_width
;
1953 rc
.height
= s
->w
->phys_cursor_height
;
1955 x_intersect_rectangles (&r_save
, &rc
, &r
);
1960 /* Don't use S->y for clipping because it doesn't take partially
1961 visible lines into account. For example, it can be negative for
1962 partially visible lines at the top of a window. */
1963 if (!s
->row
->full_width_p
1964 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1965 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1967 r
.y
= max (0, s
->row
->y
);
1970 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1972 /* If drawing the cursor, don't let glyph draw outside its
1973 advertised boundaries. Cleartype does this under some circumstances. */
1974 if (s
->hl
== DRAW_CURSOR
)
1976 struct glyph
*glyph
= s
->first_glyph
;
1981 r
.width
-= s
->x
- r
.x
;
1984 r
.width
= min (r
.width
, glyph
->pixel_width
);
1986 /* If r.y is below window bottom, ensure that we still see a cursor. */
1987 height
= min (glyph
->ascent
+ glyph
->descent
,
1988 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1989 max_y
= window_text_bottom_y (s
->w
) - height
;
1990 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1991 if (s
->ybase
- glyph
->ascent
> max_y
)
1998 /* Don't draw cursor glyph taller than our actual glyph. */
1999 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2000 if (height
< r
.height
)
2002 max_y
= r
.y
+ r
.height
;
2003 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2004 r
.height
= min (max_y
- r
.y
, height
);
2011 XRectangle r_save
= r
;
2013 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2017 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2018 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2020 #ifdef CONVERT_FROM_XRECT
2021 CONVERT_FROM_XRECT (r
, *rects
);
2029 /* If we are processing overlapping and allowed to return
2030 multiple clipping rectangles, we exclude the row of the glyph
2031 string from the clipping rectangle. This is to avoid drawing
2032 the same text on the environment with anti-aliasing. */
2033 #ifdef CONVERT_FROM_XRECT
2036 XRectangle
*rs
= rects
;
2038 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2040 if (s
->for_overlaps
& OVERLAPS_PRED
)
2043 if (r
.y
+ r
.height
> row_y
)
2046 rs
[i
].height
= row_y
- r
.y
;
2052 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2055 if (r
.y
< row_y
+ s
->row
->visible_height
)
2057 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2059 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2060 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2069 #ifdef CONVERT_FROM_XRECT
2070 for (i
= 0; i
< n
; i
++)
2071 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2078 Return in *NR the clipping rectangle for glyph string S. */
2081 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2083 get_glyph_string_clip_rects (s
, nr
, 1);
2088 Return the position and height of the phys cursor in window W.
2089 Set w->phys_cursor_width to width of phys cursor.
2093 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2094 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2096 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2097 int x
, y
, wd
, h
, h0
, y0
;
2099 /* Compute the width of the rectangle to draw. If on a stretch
2100 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2101 rectangle as wide as the glyph, but use a canonical character
2103 wd
= glyph
->pixel_width
- 1;
2104 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2108 x
= w
->phys_cursor
.x
;
2115 if (glyph
->type
== STRETCH_GLYPH
2116 && !x_stretch_cursor_p
)
2117 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2118 w
->phys_cursor_width
= wd
;
2120 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2122 /* If y is below window bottom, ensure that we still see a cursor. */
2123 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2125 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2126 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2128 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2131 h
= max (h
- (y0
- y
) + 1, h0
);
2136 y0
= window_text_bottom_y (w
) - h0
;
2144 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2145 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2150 * Remember which glyph the mouse is over.
2154 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2158 struct glyph_row
*r
, *gr
, *end_row
;
2159 enum window_part part
;
2160 enum glyph_row_area area
;
2161 int x
, y
, width
, height
;
2163 /* Try to determine frame pixel position and size of the glyph under
2164 frame pixel coordinates X/Y on frame F. */
2166 if (!f
->glyphs_initialized_p
2167 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2170 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2171 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2175 w
= XWINDOW (window
);
2176 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2177 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2179 x
= window_relative_x_coord (w
, part
, gx
);
2180 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2182 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2183 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2185 if (w
->pseudo_window_p
)
2188 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2194 case ON_LEFT_MARGIN
:
2195 area
= LEFT_MARGIN_AREA
;
2198 case ON_RIGHT_MARGIN
:
2199 area
= RIGHT_MARGIN_AREA
;
2202 case ON_HEADER_LINE
:
2204 gr
= (part
== ON_HEADER_LINE
2205 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2206 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2209 goto text_glyph_row_found
;
2216 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2217 if (r
->y
+ r
->height
> y
)
2223 text_glyph_row_found
:
2226 struct glyph
*g
= gr
->glyphs
[area
];
2227 struct glyph
*end
= g
+ gr
->used
[area
];
2229 height
= gr
->height
;
2230 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2231 if (gx
+ g
->pixel_width
> x
)
2236 if (g
->type
== IMAGE_GLYPH
)
2238 /* Don't remember when mouse is over image, as
2239 image may have hot-spots. */
2240 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2243 width
= g
->pixel_width
;
2247 /* Use nominal char spacing at end of line. */
2249 gx
+= (x
/ width
) * width
;
2252 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2253 gx
+= window_box_left_offset (w
, area
);
2257 /* Use nominal line height at end of window. */
2258 gx
= (x
/ width
) * width
;
2260 gy
+= (y
/ height
) * height
;
2264 case ON_LEFT_FRINGE
:
2265 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2266 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2267 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2268 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2271 case ON_RIGHT_FRINGE
:
2272 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2273 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2274 : window_box_right_offset (w
, TEXT_AREA
));
2275 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2279 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2281 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2282 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2283 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2285 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2289 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2290 if (r
->y
+ r
->height
> y
)
2297 height
= gr
->height
;
2300 /* Use nominal line height at end of window. */
2302 gy
+= (y
/ height
) * height
;
2309 /* If there is no glyph under the mouse, then we divide the screen
2310 into a grid of the smallest glyph in the frame, and use that
2313 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2314 round down even for negative values. */
2320 gx
= (gx
/ width
) * width
;
2321 gy
= (gy
/ height
) * height
;
2326 gx
+= WINDOW_LEFT_EDGE_X (w
);
2327 gy
+= WINDOW_TOP_EDGE_Y (w
);
2330 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2332 /* Visible feedback for debugging. */
2335 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2336 f
->output_data
.x
->normal_gc
,
2337 gx
, gy
, width
, height
);
2343 #endif /* HAVE_WINDOW_SYSTEM */
2346 /***********************************************************************
2347 Lisp form evaluation
2348 ***********************************************************************/
2350 /* Error handler for safe_eval and safe_call. */
2353 safe_eval_handler (Lisp_Object arg
)
2355 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2360 /* Evaluate SEXPR and return the result, or nil if something went
2361 wrong. Prevent redisplay during the evaluation. */
2363 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2364 Return the result, or nil if something went wrong. Prevent
2365 redisplay during the evaluation. */
2368 safe_call (ptrdiff_t nargs
, Lisp_Object
*args
)
2372 if (inhibit_eval_during_redisplay
)
2376 int count
= SPECPDL_INDEX ();
2377 struct gcpro gcpro1
;
2380 gcpro1
.nvars
= nargs
;
2381 specbind (Qinhibit_redisplay
, Qt
);
2382 /* Use Qt to ensure debugger does not run,
2383 so there is no possibility of wanting to redisplay. */
2384 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2387 val
= unbind_to (count
, val
);
2394 /* Call function FN with one argument ARG.
2395 Return the result, or nil if something went wrong. */
2398 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2400 Lisp_Object args
[2];
2403 return safe_call (2, args
);
2406 static Lisp_Object Qeval
;
2409 safe_eval (Lisp_Object sexpr
)
2411 return safe_call1 (Qeval
, sexpr
);
2414 /* Call function FN with one argument ARG.
2415 Return the result, or nil if something went wrong. */
2418 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2420 Lisp_Object args
[3];
2424 return safe_call (3, args
);
2429 /***********************************************************************
2431 ***********************************************************************/
2435 /* Define CHECK_IT to perform sanity checks on iterators.
2436 This is for debugging. It is too slow to do unconditionally. */
2439 check_it (struct it
*it
)
2441 if (it
->method
== GET_FROM_STRING
)
2443 xassert (STRINGP (it
->string
));
2444 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2448 xassert (IT_STRING_CHARPOS (*it
) < 0);
2449 if (it
->method
== GET_FROM_BUFFER
)
2451 /* Check that character and byte positions agree. */
2452 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2457 xassert (it
->current
.dpvec_index
>= 0);
2459 xassert (it
->current
.dpvec_index
< 0);
2462 #define CHECK_IT(IT) check_it ((IT))
2466 #define CHECK_IT(IT) (void) 0
2471 #if GLYPH_DEBUG && XASSERTS
2473 /* Check that the window end of window W is what we expect it
2474 to be---the last row in the current matrix displaying text. */
2477 check_window_end (struct window
*w
)
2479 if (!MINI_WINDOW_P (w
)
2480 && !NILP (w
->window_end_valid
))
2482 struct glyph_row
*row
;
2483 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2484 XFASTINT (w
->window_end_vpos
)),
2486 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2487 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2491 #define CHECK_WINDOW_END(W) check_window_end ((W))
2495 #define CHECK_WINDOW_END(W) (void) 0
2501 /***********************************************************************
2502 Iterator initialization
2503 ***********************************************************************/
2505 /* Initialize IT for displaying current_buffer in window W, starting
2506 at character position CHARPOS. CHARPOS < 0 means that no buffer
2507 position is specified which is useful when the iterator is assigned
2508 a position later. BYTEPOS is the byte position corresponding to
2509 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2511 If ROW is not null, calls to produce_glyphs with IT as parameter
2512 will produce glyphs in that row.
2514 BASE_FACE_ID is the id of a base face to use. It must be one of
2515 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2516 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2517 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2519 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2520 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2521 will be initialized to use the corresponding mode line glyph row of
2522 the desired matrix of W. */
2525 init_iterator (struct it
*it
, struct window
*w
,
2526 EMACS_INT charpos
, EMACS_INT bytepos
,
2527 struct glyph_row
*row
, enum face_id base_face_id
)
2529 int highlight_region_p
;
2530 enum face_id remapped_base_face_id
= base_face_id
;
2532 /* Some precondition checks. */
2533 xassert (w
!= NULL
&& it
!= NULL
);
2534 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2537 /* If face attributes have been changed since the last redisplay,
2538 free realized faces now because they depend on face definitions
2539 that might have changed. Don't free faces while there might be
2540 desired matrices pending which reference these faces. */
2541 if (face_change_count
&& !inhibit_free_realized_faces
)
2543 face_change_count
= 0;
2544 free_all_realized_faces (Qnil
);
2547 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2548 if (! NILP (Vface_remapping_alist
))
2549 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2551 /* Use one of the mode line rows of W's desired matrix if
2555 if (base_face_id
== MODE_LINE_FACE_ID
2556 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2557 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2558 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2559 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2563 memset (it
, 0, sizeof *it
);
2564 it
->current
.overlay_string_index
= -1;
2565 it
->current
.dpvec_index
= -1;
2566 it
->base_face_id
= remapped_base_face_id
;
2568 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2569 it
->paragraph_embedding
= L2R
;
2570 it
->bidi_it
.string
.lstring
= Qnil
;
2571 it
->bidi_it
.string
.s
= NULL
;
2572 it
->bidi_it
.string
.bufpos
= 0;
2574 /* The window in which we iterate over current_buffer: */
2575 XSETWINDOW (it
->window
, w
);
2577 it
->f
= XFRAME (w
->frame
);
2581 /* Extra space between lines (on window systems only). */
2582 if (base_face_id
== DEFAULT_FACE_ID
2583 && FRAME_WINDOW_P (it
->f
))
2585 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2586 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2587 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2588 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2589 * FRAME_LINE_HEIGHT (it
->f
));
2590 else if (it
->f
->extra_line_spacing
> 0)
2591 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2592 it
->max_extra_line_spacing
= 0;
2595 /* If realized faces have been removed, e.g. because of face
2596 attribute changes of named faces, recompute them. When running
2597 in batch mode, the face cache of the initial frame is null. If
2598 we happen to get called, make a dummy face cache. */
2599 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2600 init_frame_faces (it
->f
);
2601 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2602 recompute_basic_faces (it
->f
);
2604 /* Current value of the `slice', `space-width', and 'height' properties. */
2605 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2606 it
->space_width
= Qnil
;
2607 it
->font_height
= Qnil
;
2608 it
->override_ascent
= -1;
2610 /* Are control characters displayed as `^C'? */
2611 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2613 /* -1 means everything between a CR and the following line end
2614 is invisible. >0 means lines indented more than this value are
2616 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2617 ? XINT (BVAR (current_buffer
, selective_display
))
2618 : (!NILP (BVAR (current_buffer
, selective_display
))
2620 it
->selective_display_ellipsis_p
2621 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2623 /* Display table to use. */
2624 it
->dp
= window_display_table (w
);
2626 /* Are multibyte characters enabled in current_buffer? */
2627 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2629 /* Non-zero if we should highlight the region. */
2631 = (!NILP (Vtransient_mark_mode
)
2632 && !NILP (BVAR (current_buffer
, mark_active
))
2633 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2635 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2636 start and end of a visible region in window IT->w. Set both to
2637 -1 to indicate no region. */
2638 if (highlight_region_p
2639 /* Maybe highlight only in selected window. */
2640 && (/* Either show region everywhere. */
2641 highlight_nonselected_windows
2642 /* Or show region in the selected window. */
2643 || w
== XWINDOW (selected_window
)
2644 /* Or show the region if we are in the mini-buffer and W is
2645 the window the mini-buffer refers to. */
2646 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2647 && WINDOWP (minibuf_selected_window
)
2648 && w
== XWINDOW (minibuf_selected_window
))))
2650 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2651 it
->region_beg_charpos
= min (PT
, markpos
);
2652 it
->region_end_charpos
= max (PT
, markpos
);
2655 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2657 /* Get the position at which the redisplay_end_trigger hook should
2658 be run, if it is to be run at all. */
2659 if (MARKERP (w
->redisplay_end_trigger
)
2660 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2661 it
->redisplay_end_trigger_charpos
2662 = marker_position (w
->redisplay_end_trigger
);
2663 else if (INTEGERP (w
->redisplay_end_trigger
))
2664 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2666 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2668 /* Are lines in the display truncated? */
2669 if (base_face_id
!= DEFAULT_FACE_ID
2670 || XINT (it
->w
->hscroll
)
2671 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2672 && ((!NILP (Vtruncate_partial_width_windows
)
2673 && !INTEGERP (Vtruncate_partial_width_windows
))
2674 || (INTEGERP (Vtruncate_partial_width_windows
)
2675 && (WINDOW_TOTAL_COLS (it
->w
)
2676 < XINT (Vtruncate_partial_width_windows
))))))
2677 it
->line_wrap
= TRUNCATE
;
2678 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2679 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2680 ? WINDOW_WRAP
: WORD_WRAP
;
2682 it
->line_wrap
= TRUNCATE
;
2684 /* Get dimensions of truncation and continuation glyphs. These are
2685 displayed as fringe bitmaps under X, so we don't need them for such
2687 if (!FRAME_WINDOW_P (it
->f
))
2689 if (it
->line_wrap
== TRUNCATE
)
2691 /* We will need the truncation glyph. */
2692 xassert (it
->glyph_row
== NULL
);
2693 produce_special_glyphs (it
, IT_TRUNCATION
);
2694 it
->truncation_pixel_width
= it
->pixel_width
;
2698 /* We will need the continuation glyph. */
2699 xassert (it
->glyph_row
== NULL
);
2700 produce_special_glyphs (it
, IT_CONTINUATION
);
2701 it
->continuation_pixel_width
= it
->pixel_width
;
2704 /* Reset these values to zero because the produce_special_glyphs
2705 above has changed them. */
2706 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2707 it
->phys_ascent
= it
->phys_descent
= 0;
2710 /* Set this after getting the dimensions of truncation and
2711 continuation glyphs, so that we don't produce glyphs when calling
2712 produce_special_glyphs, above. */
2713 it
->glyph_row
= row
;
2714 it
->area
= TEXT_AREA
;
2716 /* Forget any previous info about this row being reversed. */
2718 it
->glyph_row
->reversed_p
= 0;
2720 /* Get the dimensions of the display area. The display area
2721 consists of the visible window area plus a horizontally scrolled
2722 part to the left of the window. All x-values are relative to the
2723 start of this total display area. */
2724 if (base_face_id
!= DEFAULT_FACE_ID
)
2726 /* Mode lines, menu bar in terminal frames. */
2727 it
->first_visible_x
= 0;
2728 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2733 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2734 it
->last_visible_x
= (it
->first_visible_x
2735 + window_box_width (w
, TEXT_AREA
));
2737 /* If we truncate lines, leave room for the truncator glyph(s) at
2738 the right margin. Otherwise, leave room for the continuation
2739 glyph(s). Truncation and continuation glyphs are not inserted
2740 for window-based redisplay. */
2741 if (!FRAME_WINDOW_P (it
->f
))
2743 if (it
->line_wrap
== TRUNCATE
)
2744 it
->last_visible_x
-= it
->truncation_pixel_width
;
2746 it
->last_visible_x
-= it
->continuation_pixel_width
;
2749 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2750 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2753 /* Leave room for a border glyph. */
2754 if (!FRAME_WINDOW_P (it
->f
)
2755 && !WINDOW_RIGHTMOST_P (it
->w
))
2756 it
->last_visible_x
-= 1;
2758 it
->last_visible_y
= window_text_bottom_y (w
);
2760 /* For mode lines and alike, arrange for the first glyph having a
2761 left box line if the face specifies a box. */
2762 if (base_face_id
!= DEFAULT_FACE_ID
)
2766 it
->face_id
= remapped_base_face_id
;
2768 /* If we have a boxed mode line, make the first character appear
2769 with a left box line. */
2770 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2771 if (face
->box
!= FACE_NO_BOX
)
2772 it
->start_of_box_run_p
= 1;
2775 /* If a buffer position was specified, set the iterator there,
2776 getting overlays and face properties from that position. */
2777 if (charpos
>= BUF_BEG (current_buffer
))
2779 it
->end_charpos
= ZV
;
2780 IT_CHARPOS (*it
) = charpos
;
2782 /* We will rely on `reseat' to set this up properly, via
2783 handle_face_prop. */
2784 it
->face_id
= it
->base_face_id
;
2786 /* Compute byte position if not specified. */
2787 if (bytepos
< charpos
)
2788 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2790 IT_BYTEPOS (*it
) = bytepos
;
2792 it
->start
= it
->current
;
2793 /* Do we need to reorder bidirectional text? Not if this is a
2794 unibyte buffer: by definition, none of the single-byte
2795 characters are strong R2L, so no reordering is needed. And
2796 bidi.c doesn't support unibyte buffers anyway. Also, don't
2797 reorder while we are loading loadup.el, since the tables of
2798 character properties needed for reordering are not yet
2802 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2805 /* If we are to reorder bidirectional text, init the bidi
2809 /* Note the paragraph direction that this buffer wants to
2811 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2813 it
->paragraph_embedding
= L2R
;
2814 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2816 it
->paragraph_embedding
= R2L
;
2818 it
->paragraph_embedding
= NEUTRAL_DIR
;
2819 bidi_unshelve_cache (NULL
, 0);
2820 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2824 /* Compute faces etc. */
2825 reseat (it
, it
->current
.pos
, 1);
2832 /* Initialize IT for the display of window W with window start POS. */
2835 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2837 struct glyph_row
*row
;
2838 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2840 row
= w
->desired_matrix
->rows
+ first_vpos
;
2841 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2842 it
->first_vpos
= first_vpos
;
2844 /* Don't reseat to previous visible line start if current start
2845 position is in a string or image. */
2846 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2848 int start_at_line_beg_p
;
2849 int first_y
= it
->current_y
;
2851 /* If window start is not at a line start, skip forward to POS to
2852 get the correct continuation lines width. */
2853 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2854 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2855 if (!start_at_line_beg_p
)
2859 reseat_at_previous_visible_line_start (it
);
2860 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2862 new_x
= it
->current_x
+ it
->pixel_width
;
2864 /* If lines are continued, this line may end in the middle
2865 of a multi-glyph character (e.g. a control character
2866 displayed as \003, or in the middle of an overlay
2867 string). In this case move_it_to above will not have
2868 taken us to the start of the continuation line but to the
2869 end of the continued line. */
2870 if (it
->current_x
> 0
2871 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2872 && (/* And glyph doesn't fit on the line. */
2873 new_x
> it
->last_visible_x
2874 /* Or it fits exactly and we're on a window
2876 || (new_x
== it
->last_visible_x
2877 && FRAME_WINDOW_P (it
->f
))))
2879 if ((it
->current
.dpvec_index
>= 0
2880 || it
->current
.overlay_string_index
>= 0)
2881 /* If we are on a newline from a display vector or
2882 overlay string, then we are already at the end of
2883 a screen line; no need to go to the next line in
2884 that case, as this line is not really continued.
2885 (If we do go to the next line, C-e will not DTRT.) */
2888 set_iterator_to_next (it
, 1);
2889 move_it_in_display_line_to (it
, -1, -1, 0);
2892 it
->continuation_lines_width
+= it
->current_x
;
2894 /* If the character at POS is displayed via a display
2895 vector, move_it_to above stops at the final glyph of
2896 IT->dpvec. To make the caller redisplay that character
2897 again (a.k.a. start at POS), we need to reset the
2898 dpvec_index to the beginning of IT->dpvec. */
2899 else if (it
->current
.dpvec_index
>= 0)
2900 it
->current
.dpvec_index
= 0;
2902 /* We're starting a new display line, not affected by the
2903 height of the continued line, so clear the appropriate
2904 fields in the iterator structure. */
2905 it
->max_ascent
= it
->max_descent
= 0;
2906 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2908 it
->current_y
= first_y
;
2910 it
->current_x
= it
->hpos
= 0;
2916 /* Return 1 if POS is a position in ellipses displayed for invisible
2917 text. W is the window we display, for text property lookup. */
2920 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2922 Lisp_Object prop
, window
;
2924 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2926 /* If POS specifies a position in a display vector, this might
2927 be for an ellipsis displayed for invisible text. We won't
2928 get the iterator set up for delivering that ellipsis unless
2929 we make sure that it gets aware of the invisible text. */
2930 if (pos
->dpvec_index
>= 0
2931 && pos
->overlay_string_index
< 0
2932 && CHARPOS (pos
->string_pos
) < 0
2934 && (XSETWINDOW (window
, w
),
2935 prop
= Fget_char_property (make_number (charpos
),
2936 Qinvisible
, window
),
2937 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2939 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2941 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2948 /* Initialize IT for stepping through current_buffer in window W,
2949 starting at position POS that includes overlay string and display
2950 vector/ control character translation position information. Value
2951 is zero if there are overlay strings with newlines at POS. */
2954 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2956 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2957 int i
, overlay_strings_with_newlines
= 0;
2959 /* If POS specifies a position in a display vector, this might
2960 be for an ellipsis displayed for invisible text. We won't
2961 get the iterator set up for delivering that ellipsis unless
2962 we make sure that it gets aware of the invisible text. */
2963 if (in_ellipses_for_invisible_text_p (pos
, w
))
2969 /* Keep in mind: the call to reseat in init_iterator skips invisible
2970 text, so we might end up at a position different from POS. This
2971 is only a problem when POS is a row start after a newline and an
2972 overlay starts there with an after-string, and the overlay has an
2973 invisible property. Since we don't skip invisible text in
2974 display_line and elsewhere immediately after consuming the
2975 newline before the row start, such a POS will not be in a string,
2976 but the call to init_iterator below will move us to the
2978 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2980 /* This only scans the current chunk -- it should scan all chunks.
2981 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2982 to 16 in 22.1 to make this a lesser problem. */
2983 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2985 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2986 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2988 while (s
< e
&& *s
!= '\n')
2993 overlay_strings_with_newlines
= 1;
2998 /* If position is within an overlay string, set up IT to the right
3000 if (pos
->overlay_string_index
>= 0)
3004 /* If the first overlay string happens to have a `display'
3005 property for an image, the iterator will be set up for that
3006 image, and we have to undo that setup first before we can
3007 correct the overlay string index. */
3008 if (it
->method
== GET_FROM_IMAGE
)
3011 /* We already have the first chunk of overlay strings in
3012 IT->overlay_strings. Load more until the one for
3013 pos->overlay_string_index is in IT->overlay_strings. */
3014 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3016 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3017 it
->current
.overlay_string_index
= 0;
3020 load_overlay_strings (it
, 0);
3021 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3025 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3026 relative_index
= (it
->current
.overlay_string_index
3027 % OVERLAY_STRING_CHUNK_SIZE
);
3028 it
->string
= it
->overlay_strings
[relative_index
];
3029 xassert (STRINGP (it
->string
));
3030 it
->current
.string_pos
= pos
->string_pos
;
3031 it
->method
= GET_FROM_STRING
;
3034 if (CHARPOS (pos
->string_pos
) >= 0)
3036 /* Recorded position is not in an overlay string, but in another
3037 string. This can only be a string from a `display' property.
3038 IT should already be filled with that string. */
3039 it
->current
.string_pos
= pos
->string_pos
;
3040 xassert (STRINGP (it
->string
));
3043 /* Restore position in display vector translations, control
3044 character translations or ellipses. */
3045 if (pos
->dpvec_index
>= 0)
3047 if (it
->dpvec
== NULL
)
3048 get_next_display_element (it
);
3049 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3050 it
->current
.dpvec_index
= pos
->dpvec_index
;
3054 return !overlay_strings_with_newlines
;
3058 /* Initialize IT for stepping through current_buffer in window W
3059 starting at ROW->start. */
3062 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3064 init_from_display_pos (it
, w
, &row
->start
);
3065 it
->start
= row
->start
;
3066 it
->continuation_lines_width
= row
->continuation_lines_width
;
3071 /* Initialize IT for stepping through current_buffer in window W
3072 starting in the line following ROW, i.e. starting at ROW->end.
3073 Value is zero if there are overlay strings with newlines at ROW's
3077 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3081 if (init_from_display_pos (it
, w
, &row
->end
))
3083 if (row
->continued_p
)
3084 it
->continuation_lines_width
3085 = row
->continuation_lines_width
+ row
->pixel_width
;
3096 /***********************************************************************
3098 ***********************************************************************/
3100 /* Called when IT reaches IT->stop_charpos. Handle text property and
3101 overlay changes. Set IT->stop_charpos to the next position where
3105 handle_stop (struct it
*it
)
3107 enum prop_handled handled
;
3108 int handle_overlay_change_p
;
3112 it
->current
.dpvec_index
= -1;
3113 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3114 it
->ignore_overlay_strings_at_pos_p
= 0;
3117 /* Use face of preceding text for ellipsis (if invisible) */
3118 if (it
->selective_display_ellipsis_p
)
3119 it
->saved_face_id
= it
->face_id
;
3123 handled
= HANDLED_NORMALLY
;
3125 /* Call text property handlers. */
3126 for (p
= it_props
; p
->handler
; ++p
)
3128 handled
= p
->handler (it
);
3130 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3132 else if (handled
== HANDLED_RETURN
)
3134 /* We still want to show before and after strings from
3135 overlays even if the actual buffer text is replaced. */
3136 if (!handle_overlay_change_p
3138 || !get_overlay_strings_1 (it
, 0, 0))
3141 setup_for_ellipsis (it
, 0);
3142 /* When handling a display spec, we might load an
3143 empty string. In that case, discard it here. We
3144 used to discard it in handle_single_display_spec,
3145 but that causes get_overlay_strings_1, above, to
3146 ignore overlay strings that we must check. */
3147 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3151 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3155 it
->ignore_overlay_strings_at_pos_p
= 1;
3156 it
->string_from_display_prop_p
= 0;
3157 it
->from_disp_prop_p
= 0;
3158 handle_overlay_change_p
= 0;
3160 handled
= HANDLED_RECOMPUTE_PROPS
;
3163 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3164 handle_overlay_change_p
= 0;
3167 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3169 /* Don't check for overlay strings below when set to deliver
3170 characters from a display vector. */
3171 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3172 handle_overlay_change_p
= 0;
3174 /* Handle overlay changes.
3175 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3176 if it finds overlays. */
3177 if (handle_overlay_change_p
)
3178 handled
= handle_overlay_change (it
);
3183 setup_for_ellipsis (it
, 0);
3187 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3189 /* Determine where to stop next. */
3190 if (handled
== HANDLED_NORMALLY
)
3191 compute_stop_pos (it
);
3195 /* Compute IT->stop_charpos from text property and overlay change
3196 information for IT's current position. */
3199 compute_stop_pos (struct it
*it
)
3201 register INTERVAL iv
, next_iv
;
3202 Lisp_Object object
, limit
, position
;
3203 EMACS_INT charpos
, bytepos
;
3205 if (STRINGP (it
->string
))
3207 /* Strings are usually short, so don't limit the search for
3209 it
->stop_charpos
= it
->end_charpos
;
3210 object
= it
->string
;
3212 charpos
= IT_STRING_CHARPOS (*it
);
3213 bytepos
= IT_STRING_BYTEPOS (*it
);
3219 /* If end_charpos is out of range for some reason, such as a
3220 misbehaving display function, rationalize it (Bug#5984). */
3221 if (it
->end_charpos
> ZV
)
3222 it
->end_charpos
= ZV
;
3223 it
->stop_charpos
= it
->end_charpos
;
3225 /* If next overlay change is in front of the current stop pos
3226 (which is IT->end_charpos), stop there. Note: value of
3227 next_overlay_change is point-max if no overlay change
3229 charpos
= IT_CHARPOS (*it
);
3230 bytepos
= IT_BYTEPOS (*it
);
3231 pos
= next_overlay_change (charpos
);
3232 if (pos
< it
->stop_charpos
)
3233 it
->stop_charpos
= pos
;
3235 /* If showing the region, we have to stop at the region
3236 start or end because the face might change there. */
3237 if (it
->region_beg_charpos
> 0)
3239 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3240 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3241 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3242 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3245 /* Set up variables for computing the stop position from text
3246 property changes. */
3247 XSETBUFFER (object
, current_buffer
);
3248 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3251 /* Get the interval containing IT's position. Value is a null
3252 interval if there isn't such an interval. */
3253 position
= make_number (charpos
);
3254 iv
= validate_interval_range (object
, &position
, &position
, 0);
3255 if (!NULL_INTERVAL_P (iv
))
3257 Lisp_Object values_here
[LAST_PROP_IDX
];
3260 /* Get properties here. */
3261 for (p
= it_props
; p
->handler
; ++p
)
3262 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3264 /* Look for an interval following iv that has different
3266 for (next_iv
= next_interval (iv
);
3267 (!NULL_INTERVAL_P (next_iv
)
3269 || XFASTINT (limit
) > next_iv
->position
));
3270 next_iv
= next_interval (next_iv
))
3272 for (p
= it_props
; p
->handler
; ++p
)
3274 Lisp_Object new_value
;
3276 new_value
= textget (next_iv
->plist
, *p
->name
);
3277 if (!EQ (values_here
[p
->idx
], new_value
))
3285 if (!NULL_INTERVAL_P (next_iv
))
3287 if (INTEGERP (limit
)
3288 && next_iv
->position
>= XFASTINT (limit
))
3289 /* No text property change up to limit. */
3290 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3292 /* Text properties change in next_iv. */
3293 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3297 if (it
->cmp_it
.id
< 0)
3299 EMACS_INT stoppos
= it
->end_charpos
;
3301 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3303 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3304 stoppos
, it
->string
);
3307 xassert (STRINGP (it
->string
)
3308 || (it
->stop_charpos
>= BEGV
3309 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3313 /* Return the position of the next overlay change after POS in
3314 current_buffer. Value is point-max if no overlay change
3315 follows. This is like `next-overlay-change' but doesn't use
3319 next_overlay_change (EMACS_INT pos
)
3321 ptrdiff_t i
, noverlays
;
3323 Lisp_Object
*overlays
;
3325 /* Get all overlays at the given position. */
3326 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3328 /* If any of these overlays ends before endpos,
3329 use its ending point instead. */
3330 for (i
= 0; i
< noverlays
; ++i
)
3335 oend
= OVERLAY_END (overlays
[i
]);
3336 oendpos
= OVERLAY_POSITION (oend
);
3337 endpos
= min (endpos
, oendpos
);
3343 /* How many characters forward to search for a display property or
3344 display string. Searching too far forward makes the bidi display
3345 sluggish, especially in small windows. */
3346 #define MAX_DISP_SCAN 250
3348 /* Return the character position of a display string at or after
3349 position specified by POSITION. If no display string exists at or
3350 after POSITION, return ZV. A display string is either an overlay
3351 with `display' property whose value is a string, or a `display'
3352 text property whose value is a string. STRING is data about the
3353 string to iterate; if STRING->lstring is nil, we are iterating a
3354 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3355 on a GUI frame. DISP_PROP is set to zero if we searched
3356 MAX_DISP_SCAN characters forward without finding any display
3357 strings, non-zero otherwise. It is set to 2 if the display string
3358 uses any kind of `(space ...)' spec that will produce a stretch of
3359 white space in the text area. */
3361 compute_display_string_pos (struct text_pos
*position
,
3362 struct bidi_string_data
*string
,
3363 int frame_window_p
, int *disp_prop
)
3365 /* OBJECT = nil means current buffer. */
3366 Lisp_Object object
=
3367 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3368 Lisp_Object pos
, spec
, limpos
;
3369 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3370 EMACS_INT eob
= string_p
? string
->schars
: ZV
;
3371 EMACS_INT begb
= string_p
? 0 : BEGV
;
3372 EMACS_INT bufpos
, charpos
= CHARPOS (*position
);
3374 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3375 struct text_pos tpos
;
3381 /* We don't support display properties whose values are strings
3382 that have display string properties. */
3383 || string
->from_disp_str
3384 /* C strings cannot have display properties. */
3385 || (string
->s
&& !STRINGP (object
)))
3391 /* If the character at CHARPOS is where the display string begins,
3393 pos
= make_number (charpos
);
3394 if (STRINGP (object
))
3395 bufpos
= string
->bufpos
;
3399 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3401 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3404 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3412 /* Look forward for the first character with a `display' property
3413 that will replace the underlying text when displayed. */
3414 limpos
= make_number (lim
);
3416 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3417 CHARPOS (tpos
) = XFASTINT (pos
);
3418 if (CHARPOS (tpos
) >= lim
)
3423 if (STRINGP (object
))
3424 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3426 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3427 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3428 if (!STRINGP (object
))
3429 bufpos
= CHARPOS (tpos
);
3430 } while (NILP (spec
)
3431 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3432 bufpos
, frame_window_p
)));
3436 return CHARPOS (tpos
);
3439 /* Return the character position of the end of the display string that
3440 started at CHARPOS. If there's no display string at CHARPOS,
3441 return -1. A display string is either an overlay with `display'
3442 property whose value is a string or a `display' text property whose
3443 value is a string. */
3445 compute_display_string_end (EMACS_INT charpos
, struct bidi_string_data
*string
)
3447 /* OBJECT = nil means current buffer. */
3448 Lisp_Object object
=
3449 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3450 Lisp_Object pos
= make_number (charpos
);
3452 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3454 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3457 /* It could happen that the display property or overlay was removed
3458 since we found it in compute_display_string_pos above. One way
3459 this can happen is if JIT font-lock was called (through
3460 handle_fontified_prop), and jit-lock-functions remove text
3461 properties or overlays from the portion of buffer that includes
3462 CHARPOS. Muse mode is known to do that, for example. In this
3463 case, we return -1 to the caller, to signal that no display
3464 string is actually present at CHARPOS. See bidi_fetch_char for
3465 how this is handled.
3467 An alternative would be to never look for display properties past
3468 it->stop_charpos. But neither compute_display_string_pos nor
3469 bidi_fetch_char that calls it know or care where the next
3471 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3474 /* Look forward for the first character where the `display' property
3476 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3478 return XFASTINT (pos
);
3483 /***********************************************************************
3485 ***********************************************************************/
3487 /* Handle changes in the `fontified' property of the current buffer by
3488 calling hook functions from Qfontification_functions to fontify
3491 static enum prop_handled
3492 handle_fontified_prop (struct it
*it
)
3494 Lisp_Object prop
, pos
;
3495 enum prop_handled handled
= HANDLED_NORMALLY
;
3497 if (!NILP (Vmemory_full
))
3500 /* Get the value of the `fontified' property at IT's current buffer
3501 position. (The `fontified' property doesn't have a special
3502 meaning in strings.) If the value is nil, call functions from
3503 Qfontification_functions. */
3504 if (!STRINGP (it
->string
)
3506 && !NILP (Vfontification_functions
)
3507 && !NILP (Vrun_hooks
)
3508 && (pos
= make_number (IT_CHARPOS (*it
)),
3509 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3510 /* Ignore the special cased nil value always present at EOB since
3511 no amount of fontifying will be able to change it. */
3512 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3514 int count
= SPECPDL_INDEX ();
3516 struct buffer
*obuf
= current_buffer
;
3517 int begv
= BEGV
, zv
= ZV
;
3518 int old_clip_changed
= current_buffer
->clip_changed
;
3520 val
= Vfontification_functions
;
3521 specbind (Qfontification_functions
, Qnil
);
3523 xassert (it
->end_charpos
== ZV
);
3525 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3526 safe_call1 (val
, pos
);
3529 Lisp_Object fns
, fn
;
3530 struct gcpro gcpro1
, gcpro2
;
3535 for (; CONSP (val
); val
= XCDR (val
))
3541 /* A value of t indicates this hook has a local
3542 binding; it means to run the global binding too.
3543 In a global value, t should not occur. If it
3544 does, we must ignore it to avoid an endless
3546 for (fns
= Fdefault_value (Qfontification_functions
);
3552 safe_call1 (fn
, pos
);
3556 safe_call1 (fn
, pos
);
3562 unbind_to (count
, Qnil
);
3564 /* Fontification functions routinely call `save-restriction'.
3565 Normally, this tags clip_changed, which can confuse redisplay
3566 (see discussion in Bug#6671). Since we don't perform any
3567 special handling of fontification changes in the case where
3568 `save-restriction' isn't called, there's no point doing so in
3569 this case either. So, if the buffer's restrictions are
3570 actually left unchanged, reset clip_changed. */
3571 if (obuf
== current_buffer
)
3573 if (begv
== BEGV
&& zv
== ZV
)
3574 current_buffer
->clip_changed
= old_clip_changed
;
3576 /* There isn't much we can reasonably do to protect against
3577 misbehaving fontification, but here's a fig leaf. */
3578 else if (!NILP (BVAR (obuf
, name
)))
3579 set_buffer_internal_1 (obuf
);
3581 /* The fontification code may have added/removed text.
3582 It could do even a lot worse, but let's at least protect against
3583 the most obvious case where only the text past `pos' gets changed',
3584 as is/was done in grep.el where some escapes sequences are turned
3585 into face properties (bug#7876). */
3586 it
->end_charpos
= ZV
;
3588 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3589 something. This avoids an endless loop if they failed to
3590 fontify the text for which reason ever. */
3591 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3592 handled
= HANDLED_RECOMPUTE_PROPS
;
3600 /***********************************************************************
3602 ***********************************************************************/
3604 /* Set up iterator IT from face properties at its current position.
3605 Called from handle_stop. */
3607 static enum prop_handled
3608 handle_face_prop (struct it
*it
)
3611 EMACS_INT next_stop
;
3613 if (!STRINGP (it
->string
))
3616 = face_at_buffer_position (it
->w
,
3618 it
->region_beg_charpos
,
3619 it
->region_end_charpos
,
3622 + TEXT_PROP_DISTANCE_LIMIT
),
3623 0, it
->base_face_id
);
3625 /* Is this a start of a run of characters with box face?
3626 Caveat: this can be called for a freshly initialized
3627 iterator; face_id is -1 in this case. We know that the new
3628 face will not change until limit, i.e. if the new face has a
3629 box, all characters up to limit will have one. But, as
3630 usual, we don't know whether limit is really the end. */
3631 if (new_face_id
!= it
->face_id
)
3633 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3635 /* If new face has a box but old face has not, this is
3636 the start of a run of characters with box, i.e. it has
3637 a shadow on the left side. The value of face_id of the
3638 iterator will be -1 if this is the initial call that gets
3639 the face. In this case, we have to look in front of IT's
3640 position and see whether there is a face != new_face_id. */
3641 it
->start_of_box_run_p
3642 = (new_face
->box
!= FACE_NO_BOX
3643 && (it
->face_id
>= 0
3644 || IT_CHARPOS (*it
) == BEG
3645 || new_face_id
!= face_before_it_pos (it
)));
3646 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3654 Lisp_Object from_overlay
3655 = (it
->current
.overlay_string_index
>= 0
3656 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3659 /* See if we got to this string directly or indirectly from
3660 an overlay property. That includes the before-string or
3661 after-string of an overlay, strings in display properties
3662 provided by an overlay, their text properties, etc.
3664 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3665 if (! NILP (from_overlay
))
3666 for (i
= it
->sp
- 1; i
>= 0; i
--)
3668 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3670 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3671 else if (! NILP (it
->stack
[i
].from_overlay
))
3672 from_overlay
= it
->stack
[i
].from_overlay
;
3674 if (!NILP (from_overlay
))
3678 if (! NILP (from_overlay
))
3680 bufpos
= IT_CHARPOS (*it
);
3681 /* For a string from an overlay, the base face depends
3682 only on text properties and ignores overlays. */
3684 = face_for_overlay_string (it
->w
,
3686 it
->region_beg_charpos
,
3687 it
->region_end_charpos
,
3690 + TEXT_PROP_DISTANCE_LIMIT
),
3698 /* For strings from a `display' property, use the face at
3699 IT's current buffer position as the base face to merge
3700 with, so that overlay strings appear in the same face as
3701 surrounding text, unless they specify their own
3703 base_face_id
= it
->string_from_prefix_prop_p
3705 : underlying_face_id (it
);
3708 new_face_id
= face_at_string_position (it
->w
,
3710 IT_STRING_CHARPOS (*it
),
3712 it
->region_beg_charpos
,
3713 it
->region_end_charpos
,
3717 /* Is this a start of a run of characters with box? Caveat:
3718 this can be called for a freshly allocated iterator; face_id
3719 is -1 is this case. We know that the new face will not
3720 change until the next check pos, i.e. if the new face has a
3721 box, all characters up to that position will have a
3722 box. But, as usual, we don't know whether that position
3723 is really the end. */
3724 if (new_face_id
!= it
->face_id
)
3726 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3727 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3729 /* If new face has a box but old face hasn't, this is the
3730 start of a run of characters with box, i.e. it has a
3731 shadow on the left side. */
3732 it
->start_of_box_run_p
3733 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3734 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3738 it
->face_id
= new_face_id
;
3739 return HANDLED_NORMALLY
;
3743 /* Return the ID of the face ``underlying'' IT's current position,
3744 which is in a string. If the iterator is associated with a
3745 buffer, return the face at IT's current buffer position.
3746 Otherwise, use the iterator's base_face_id. */
3749 underlying_face_id (struct it
*it
)
3751 int face_id
= it
->base_face_id
, i
;
3753 xassert (STRINGP (it
->string
));
3755 for (i
= it
->sp
- 1; i
>= 0; --i
)
3756 if (NILP (it
->stack
[i
].string
))
3757 face_id
= it
->stack
[i
].face_id
;
3763 /* Compute the face one character before or after the current position
3764 of IT, in the visual order. BEFORE_P non-zero means get the face
3765 in front (to the left in L2R paragraphs, to the right in R2L
3766 paragraphs) of IT's screen position. Value is the ID of the face. */
3769 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3772 EMACS_INT next_check_charpos
;
3774 void *it_copy_data
= NULL
;
3776 xassert (it
->s
== NULL
);
3778 if (STRINGP (it
->string
))
3780 EMACS_INT bufpos
, charpos
;
3783 /* No face change past the end of the string (for the case
3784 we are padding with spaces). No face change before the
3786 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3787 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3792 /* Set charpos to the position before or after IT's current
3793 position, in the logical order, which in the non-bidi
3794 case is the same as the visual order. */
3796 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3797 else if (it
->what
== IT_COMPOSITION
)
3798 /* For composition, we must check the character after the
3800 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3802 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3808 /* With bidi iteration, the character before the current
3809 in the visual order cannot be found by simple
3810 iteration, because "reverse" reordering is not
3811 supported. Instead, we need to use the move_it_*
3812 family of functions. */
3813 /* Ignore face changes before the first visible
3814 character on this display line. */
3815 if (it
->current_x
<= it
->first_visible_x
)
3817 SAVE_IT (it_copy
, *it
, it_copy_data
);
3818 /* Implementation note: Since move_it_in_display_line
3819 works in the iterator geometry, and thinks the first
3820 character is always the leftmost, even in R2L lines,
3821 we don't need to distinguish between the R2L and L2R
3823 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3824 it_copy
.current_x
- 1, MOVE_TO_X
);
3825 charpos
= IT_STRING_CHARPOS (it_copy
);
3826 RESTORE_IT (it
, it
, it_copy_data
);
3830 /* Set charpos to the string position of the character
3831 that comes after IT's current position in the visual
3833 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3837 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3839 charpos
= it_copy
.bidi_it
.charpos
;
3842 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3844 if (it
->current
.overlay_string_index
>= 0)
3845 bufpos
= IT_CHARPOS (*it
);
3849 base_face_id
= underlying_face_id (it
);
3851 /* Get the face for ASCII, or unibyte. */
3852 face_id
= face_at_string_position (it
->w
,
3856 it
->region_beg_charpos
,
3857 it
->region_end_charpos
,
3858 &next_check_charpos
,
3861 /* Correct the face for charsets different from ASCII. Do it
3862 for the multibyte case only. The face returned above is
3863 suitable for unibyte text if IT->string is unibyte. */
3864 if (STRING_MULTIBYTE (it
->string
))
3866 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3867 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3869 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3871 c
= string_char_and_length (p
, &len
);
3872 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3877 struct text_pos pos
;
3879 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3880 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3883 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3884 pos
= it
->current
.pos
;
3889 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3892 if (it
->what
== IT_COMPOSITION
)
3894 /* For composition, we must check the position after
3896 pos
.charpos
+= it
->cmp_it
.nchars
;
3897 pos
.bytepos
+= it
->len
;
3900 INC_TEXT_POS (pos
, it
->multibyte_p
);
3907 /* With bidi iteration, the character before the current
3908 in the visual order cannot be found by simple
3909 iteration, because "reverse" reordering is not
3910 supported. Instead, we need to use the move_it_*
3911 family of functions. */
3912 /* Ignore face changes before the first visible
3913 character on this display line. */
3914 if (it
->current_x
<= it
->first_visible_x
)
3916 SAVE_IT (it_copy
, *it
, it_copy_data
);
3917 /* Implementation note: Since move_it_in_display_line
3918 works in the iterator geometry, and thinks the first
3919 character is always the leftmost, even in R2L lines,
3920 we don't need to distinguish between the R2L and L2R
3922 move_it_in_display_line (&it_copy
, ZV
,
3923 it_copy
.current_x
- 1, MOVE_TO_X
);
3924 pos
= it_copy
.current
.pos
;
3925 RESTORE_IT (it
, it
, it_copy_data
);
3929 /* Set charpos to the buffer position of the character
3930 that comes after IT's current position in the visual
3932 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3936 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3939 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3942 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3944 /* Determine face for CHARSET_ASCII, or unibyte. */
3945 face_id
= face_at_buffer_position (it
->w
,
3947 it
->region_beg_charpos
,
3948 it
->region_end_charpos
,
3949 &next_check_charpos
,
3952 /* Correct the face for charsets different from ASCII. Do it
3953 for the multibyte case only. The face returned above is
3954 suitable for unibyte text if current_buffer is unibyte. */
3955 if (it
->multibyte_p
)
3957 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3958 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3959 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3968 /***********************************************************************
3970 ***********************************************************************/
3972 /* Set up iterator IT from invisible properties at its current
3973 position. Called from handle_stop. */
3975 static enum prop_handled
3976 handle_invisible_prop (struct it
*it
)
3978 enum prop_handled handled
= HANDLED_NORMALLY
;
3980 if (STRINGP (it
->string
))
3982 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3984 /* Get the value of the invisible text property at the
3985 current position. Value will be nil if there is no such
3987 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3988 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3991 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3995 handled
= HANDLED_RECOMPUTE_PROPS
;
3997 /* Get the position at which the next change of the
3998 invisible text property can be found in IT->string.
3999 Value will be nil if the property value is the same for
4000 all the rest of IT->string. */
4001 XSETINT (limit
, SCHARS (it
->string
));
4002 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4005 /* Text at current position is invisible. The next
4006 change in the property is at position end_charpos.
4007 Move IT's current position to that position. */
4008 if (INTEGERP (end_charpos
)
4009 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
4011 struct text_pos old
;
4014 old
= it
->current
.string_pos
;
4015 oldpos
= CHARPOS (old
);
4018 if (it
->bidi_it
.first_elt
4019 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4020 bidi_paragraph_init (it
->paragraph_embedding
,
4022 /* Bidi-iterate out of the invisible text. */
4025 bidi_move_to_visually_next (&it
->bidi_it
);
4027 while (oldpos
<= it
->bidi_it
.charpos
4028 && it
->bidi_it
.charpos
< endpos
);
4030 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4031 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4032 if (IT_CHARPOS (*it
) >= endpos
)
4033 it
->prev_stop
= endpos
;
4037 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4038 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4043 /* The rest of the string is invisible. If this is an
4044 overlay string, proceed with the next overlay string
4045 or whatever comes and return a character from there. */
4046 if (it
->current
.overlay_string_index
>= 0)
4048 next_overlay_string (it
);
4049 /* Don't check for overlay strings when we just
4050 finished processing them. */
4051 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4055 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4056 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4064 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
4065 Lisp_Object pos
, prop
, overlay
;
4067 /* First of all, is there invisible text at this position? */
4068 tem
= start_charpos
= IT_CHARPOS (*it
);
4069 pos
= make_number (tem
);
4070 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4072 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4074 /* If we are on invisible text, skip over it. */
4075 if (invis_p
&& start_charpos
< it
->end_charpos
)
4077 /* Record whether we have to display an ellipsis for the
4079 int display_ellipsis_p
= invis_p
== 2;
4081 handled
= HANDLED_RECOMPUTE_PROPS
;
4083 /* Loop skipping over invisible text. The loop is left at
4084 ZV or with IT on the first char being visible again. */
4087 /* Try to skip some invisible text. Return value is the
4088 position reached which can be equal to where we start
4089 if there is nothing invisible there. This skips both
4090 over invisible text properties and overlays with
4091 invisible property. */
4092 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4094 /* If we skipped nothing at all we weren't at invisible
4095 text in the first place. If everything to the end of
4096 the buffer was skipped, end the loop. */
4097 if (newpos
== tem
|| newpos
>= ZV
)
4101 /* We skipped some characters but not necessarily
4102 all there are. Check if we ended up on visible
4103 text. Fget_char_property returns the property of
4104 the char before the given position, i.e. if we
4105 get invis_p = 0, this means that the char at
4106 newpos is visible. */
4107 pos
= make_number (newpos
);
4108 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4109 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4112 /* If we ended up on invisible text, proceed to
4113 skip starting with next_stop. */
4117 /* If there are adjacent invisible texts, don't lose the
4118 second one's ellipsis. */
4120 display_ellipsis_p
= 1;
4124 /* The position newpos is now either ZV or on visible text. */
4127 EMACS_INT bpos
= CHAR_TO_BYTE (newpos
);
4129 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4131 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4133 /* If the invisible text ends on a newline or on a
4134 character after a newline, we can avoid the costly,
4135 character by character, bidi iteration to NEWPOS, and
4136 instead simply reseat the iterator there. That's
4137 because all bidi reordering information is tossed at
4138 the newline. This is a big win for modes that hide
4139 complete lines, like Outline, Org, etc. */
4140 if (on_newline
|| after_newline
)
4142 struct text_pos tpos
;
4143 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4145 SET_TEXT_POS (tpos
, newpos
, bpos
);
4146 reseat_1 (it
, tpos
, 0);
4147 /* If we reseat on a newline/ZV, we need to prep the
4148 bidi iterator for advancing to the next character
4149 after the newline/EOB, keeping the current paragraph
4150 direction (so that PRODUCE_GLYPHS does TRT wrt
4151 prepending/appending glyphs to a glyph row). */
4154 it
->bidi_it
.first_elt
= 0;
4155 it
->bidi_it
.paragraph_dir
= pdir
;
4156 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4157 it
->bidi_it
.nchars
= 1;
4158 it
->bidi_it
.ch_len
= 1;
4161 else /* Must use the slow method. */
4163 /* With bidi iteration, the region of invisible text
4164 could start and/or end in the middle of a
4165 non-base embedding level. Therefore, we need to
4166 skip invisible text using the bidi iterator,
4167 starting at IT's current position, until we find
4168 ourselves outside of the invisible text.
4169 Skipping invisible text _after_ bidi iteration
4170 avoids affecting the visual order of the
4171 displayed text when invisible properties are
4172 added or removed. */
4173 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4175 /* If we were `reseat'ed to a new paragraph,
4176 determine the paragraph base direction. We
4177 need to do it now because
4178 next_element_from_buffer may not have a
4179 chance to do it, if we are going to skip any
4180 text at the beginning, which resets the
4182 bidi_paragraph_init (it
->paragraph_embedding
,
4187 bidi_move_to_visually_next (&it
->bidi_it
);
4189 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4190 && it
->bidi_it
.charpos
< newpos
);
4191 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4192 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4193 /* If we overstepped NEWPOS, record its position in
4194 the iterator, so that we skip invisible text if
4195 later the bidi iteration lands us in the
4196 invisible region again. */
4197 if (IT_CHARPOS (*it
) >= newpos
)
4198 it
->prev_stop
= newpos
;
4203 IT_CHARPOS (*it
) = newpos
;
4204 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4207 /* If there are before-strings at the start of invisible
4208 text, and the text is invisible because of a text
4209 property, arrange to show before-strings because 20.x did
4210 it that way. (If the text is invisible because of an
4211 overlay property instead of a text property, this is
4212 already handled in the overlay code.) */
4214 && get_overlay_strings (it
, it
->stop_charpos
))
4216 handled
= HANDLED_RECOMPUTE_PROPS
;
4217 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4219 else if (display_ellipsis_p
)
4221 /* Make sure that the glyphs of the ellipsis will get
4222 correct `charpos' values. If we would not update
4223 it->position here, the glyphs would belong to the
4224 last visible character _before_ the invisible
4225 text, which confuses `set_cursor_from_row'.
4227 We use the last invisible position instead of the
4228 first because this way the cursor is always drawn on
4229 the first "." of the ellipsis, whenever PT is inside
4230 the invisible text. Otherwise the cursor would be
4231 placed _after_ the ellipsis when the point is after the
4232 first invisible character. */
4233 if (!STRINGP (it
->object
))
4235 it
->position
.charpos
= newpos
- 1;
4236 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4239 /* Let the ellipsis display before
4240 considering any properties of the following char.
4241 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4242 handled
= HANDLED_RETURN
;
4251 /* Make iterator IT return `...' next.
4252 Replaces LEN characters from buffer. */
4255 setup_for_ellipsis (struct it
*it
, int len
)
4257 /* Use the display table definition for `...'. Invalid glyphs
4258 will be handled by the method returning elements from dpvec. */
4259 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4261 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4262 it
->dpvec
= v
->contents
;
4263 it
->dpend
= v
->contents
+ v
->header
.size
;
4267 /* Default `...'. */
4268 it
->dpvec
= default_invis_vector
;
4269 it
->dpend
= default_invis_vector
+ 3;
4272 it
->dpvec_char_len
= len
;
4273 it
->current
.dpvec_index
= 0;
4274 it
->dpvec_face_id
= -1;
4276 /* Remember the current face id in case glyphs specify faces.
4277 IT's face is restored in set_iterator_to_next.
4278 saved_face_id was set to preceding char's face in handle_stop. */
4279 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4280 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4282 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4288 /***********************************************************************
4290 ***********************************************************************/
4292 /* Set up iterator IT from `display' property at its current position.
4293 Called from handle_stop.
4294 We return HANDLED_RETURN if some part of the display property
4295 overrides the display of the buffer text itself.
4296 Otherwise we return HANDLED_NORMALLY. */
4298 static enum prop_handled
4299 handle_display_prop (struct it
*it
)
4301 Lisp_Object propval
, object
, overlay
;
4302 struct text_pos
*position
;
4304 /* Nonzero if some property replaces the display of the text itself. */
4305 int display_replaced_p
= 0;
4307 if (STRINGP (it
->string
))
4309 object
= it
->string
;
4310 position
= &it
->current
.string_pos
;
4311 bufpos
= CHARPOS (it
->current
.pos
);
4315 XSETWINDOW (object
, it
->w
);
4316 position
= &it
->current
.pos
;
4317 bufpos
= CHARPOS (*position
);
4320 /* Reset those iterator values set from display property values. */
4321 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4322 it
->space_width
= Qnil
;
4323 it
->font_height
= Qnil
;
4326 /* We don't support recursive `display' properties, i.e. string
4327 values that have a string `display' property, that have a string
4328 `display' property etc. */
4329 if (!it
->string_from_display_prop_p
)
4330 it
->area
= TEXT_AREA
;
4332 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4333 Qdisplay
, object
, &overlay
);
4335 return HANDLED_NORMALLY
;
4336 /* Now OVERLAY is the overlay that gave us this property, or nil
4337 if it was a text property. */
4339 if (!STRINGP (it
->string
))
4340 object
= it
->w
->buffer
;
4342 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4344 FRAME_WINDOW_P (it
->f
));
4346 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4349 /* Subroutine of handle_display_prop. Returns non-zero if the display
4350 specification in SPEC is a replacing specification, i.e. it would
4351 replace the text covered by `display' property with something else,
4352 such as an image or a display string. If SPEC includes any kind or
4353 `(space ...) specification, the value is 2; this is used by
4354 compute_display_string_pos, which see.
4356 See handle_single_display_spec for documentation of arguments.
4357 frame_window_p is non-zero if the window being redisplayed is on a
4358 GUI frame; this argument is used only if IT is NULL, see below.
4360 IT can be NULL, if this is called by the bidi reordering code
4361 through compute_display_string_pos, which see. In that case, this
4362 function only examines SPEC, but does not otherwise "handle" it, in
4363 the sense that it doesn't set up members of IT from the display
4366 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4367 Lisp_Object overlay
, struct text_pos
*position
,
4368 EMACS_INT bufpos
, int frame_window_p
)
4370 int replacing_p
= 0;
4374 /* Simple specifications. */
4375 && !EQ (XCAR (spec
), Qimage
)
4376 && !EQ (XCAR (spec
), Qspace
)
4377 && !EQ (XCAR (spec
), Qwhen
)
4378 && !EQ (XCAR (spec
), Qslice
)
4379 && !EQ (XCAR (spec
), Qspace_width
)
4380 && !EQ (XCAR (spec
), Qheight
)
4381 && !EQ (XCAR (spec
), Qraise
)
4382 /* Marginal area specifications. */
4383 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4384 && !EQ (XCAR (spec
), Qleft_fringe
)
4385 && !EQ (XCAR (spec
), Qright_fringe
)
4386 && !NILP (XCAR (spec
)))
4388 for (; CONSP (spec
); spec
= XCDR (spec
))
4390 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4391 overlay
, position
, bufpos
,
4392 replacing_p
, frame_window_p
)))
4395 /* If some text in a string is replaced, `position' no
4396 longer points to the position of `object'. */
4397 if (!it
|| STRINGP (object
))
4402 else if (VECTORP (spec
))
4405 for (i
= 0; i
< ASIZE (spec
); ++i
)
4406 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4407 overlay
, position
, bufpos
,
4408 replacing_p
, frame_window_p
)))
4411 /* If some text in a string is replaced, `position' no
4412 longer points to the position of `object'. */
4413 if (!it
|| STRINGP (object
))
4419 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4420 position
, bufpos
, 0,
4428 /* Value is the position of the end of the `display' property starting
4429 at START_POS in OBJECT. */
4431 static struct text_pos
4432 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4435 struct text_pos end_pos
;
4437 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4438 Qdisplay
, object
, Qnil
);
4439 CHARPOS (end_pos
) = XFASTINT (end
);
4440 if (STRINGP (object
))
4441 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4443 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4449 /* Set up IT from a single `display' property specification SPEC. OBJECT
4450 is the object in which the `display' property was found. *POSITION
4451 is the position in OBJECT at which the `display' property was found.
4452 BUFPOS is the buffer position of OBJECT (different from POSITION if
4453 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4454 previously saw a display specification which already replaced text
4455 display with something else, for example an image; we ignore such
4456 properties after the first one has been processed.
4458 OVERLAY is the overlay this `display' property came from,
4459 or nil if it was a text property.
4461 If SPEC is a `space' or `image' specification, and in some other
4462 cases too, set *POSITION to the position where the `display'
4465 If IT is NULL, only examine the property specification in SPEC, but
4466 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4467 is intended to be displayed in a window on a GUI frame.
4469 Value is non-zero if something was found which replaces the display
4470 of buffer or string text. */
4473 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4474 Lisp_Object overlay
, struct text_pos
*position
,
4475 EMACS_INT bufpos
, int display_replaced_p
,
4479 Lisp_Object location
, value
;
4480 struct text_pos start_pos
= *position
;
4483 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4484 If the result is non-nil, use VALUE instead of SPEC. */
4486 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4495 if (!NILP (form
) && !EQ (form
, Qt
))
4497 int count
= SPECPDL_INDEX ();
4498 struct gcpro gcpro1
;
4500 /* Bind `object' to the object having the `display' property, a
4501 buffer or string. Bind `position' to the position in the
4502 object where the property was found, and `buffer-position'
4503 to the current position in the buffer. */
4506 XSETBUFFER (object
, current_buffer
);
4507 specbind (Qobject
, object
);
4508 specbind (Qposition
, make_number (CHARPOS (*position
)));
4509 specbind (Qbuffer_position
, make_number (bufpos
));
4511 form
= safe_eval (form
);
4513 unbind_to (count
, Qnil
);
4519 /* Handle `(height HEIGHT)' specifications. */
4521 && EQ (XCAR (spec
), Qheight
)
4522 && CONSP (XCDR (spec
)))
4526 if (!FRAME_WINDOW_P (it
->f
))
4529 it
->font_height
= XCAR (XCDR (spec
));
4530 if (!NILP (it
->font_height
))
4532 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4533 int new_height
= -1;
4535 if (CONSP (it
->font_height
)
4536 && (EQ (XCAR (it
->font_height
), Qplus
)
4537 || EQ (XCAR (it
->font_height
), Qminus
))
4538 && CONSP (XCDR (it
->font_height
))
4539 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4541 /* `(+ N)' or `(- N)' where N is an integer. */
4542 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4543 if (EQ (XCAR (it
->font_height
), Qplus
))
4545 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4547 else if (FUNCTIONP (it
->font_height
))
4549 /* Call function with current height as argument.
4550 Value is the new height. */
4552 height
= safe_call1 (it
->font_height
,
4553 face
->lface
[LFACE_HEIGHT_INDEX
]);
4554 if (NUMBERP (height
))
4555 new_height
= XFLOATINT (height
);
4557 else if (NUMBERP (it
->font_height
))
4559 /* Value is a multiple of the canonical char height. */
4562 f
= FACE_FROM_ID (it
->f
,
4563 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4564 new_height
= (XFLOATINT (it
->font_height
)
4565 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4569 /* Evaluate IT->font_height with `height' bound to the
4570 current specified height to get the new height. */
4571 int count
= SPECPDL_INDEX ();
4573 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4574 value
= safe_eval (it
->font_height
);
4575 unbind_to (count
, Qnil
);
4577 if (NUMBERP (value
))
4578 new_height
= XFLOATINT (value
);
4582 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4589 /* Handle `(space-width WIDTH)'. */
4591 && EQ (XCAR (spec
), Qspace_width
)
4592 && CONSP (XCDR (spec
)))
4596 if (!FRAME_WINDOW_P (it
->f
))
4599 value
= XCAR (XCDR (spec
));
4600 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4601 it
->space_width
= value
;
4607 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4609 && EQ (XCAR (spec
), Qslice
))
4615 if (!FRAME_WINDOW_P (it
->f
))
4618 if (tem
= XCDR (spec
), CONSP (tem
))
4620 it
->slice
.x
= XCAR (tem
);
4621 if (tem
= XCDR (tem
), CONSP (tem
))
4623 it
->slice
.y
= XCAR (tem
);
4624 if (tem
= XCDR (tem
), CONSP (tem
))
4626 it
->slice
.width
= XCAR (tem
);
4627 if (tem
= XCDR (tem
), CONSP (tem
))
4628 it
->slice
.height
= XCAR (tem
);
4637 /* Handle `(raise FACTOR)'. */
4639 && EQ (XCAR (spec
), Qraise
)
4640 && CONSP (XCDR (spec
)))
4644 if (!FRAME_WINDOW_P (it
->f
))
4647 #ifdef HAVE_WINDOW_SYSTEM
4648 value
= XCAR (XCDR (spec
));
4649 if (NUMBERP (value
))
4651 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4652 it
->voffset
= - (XFLOATINT (value
)
4653 * (FONT_HEIGHT (face
->font
)));
4655 #endif /* HAVE_WINDOW_SYSTEM */
4661 /* Don't handle the other kinds of display specifications
4662 inside a string that we got from a `display' property. */
4663 if (it
&& it
->string_from_display_prop_p
)
4666 /* Characters having this form of property are not displayed, so
4667 we have to find the end of the property. */
4670 start_pos
= *position
;
4671 *position
= display_prop_end (it
, object
, start_pos
);
4675 /* Stop the scan at that end position--we assume that all
4676 text properties change there. */
4678 it
->stop_charpos
= position
->charpos
;
4680 /* Handle `(left-fringe BITMAP [FACE])'
4681 and `(right-fringe BITMAP [FACE])'. */
4683 && (EQ (XCAR (spec
), Qleft_fringe
)
4684 || EQ (XCAR (spec
), Qright_fringe
))
4685 && CONSP (XCDR (spec
)))
4691 if (!FRAME_WINDOW_P (it
->f
))
4692 /* If we return here, POSITION has been advanced
4693 across the text with this property. */
4696 else if (!frame_window_p
)
4699 #ifdef HAVE_WINDOW_SYSTEM
4700 value
= XCAR (XCDR (spec
));
4701 if (!SYMBOLP (value
)
4702 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4703 /* If we return here, POSITION has been advanced
4704 across the text with this property. */
4709 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4711 if (CONSP (XCDR (XCDR (spec
))))
4713 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4714 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4720 /* Save current settings of IT so that we can restore them
4721 when we are finished with the glyph property value. */
4722 push_it (it
, position
);
4724 it
->area
= TEXT_AREA
;
4725 it
->what
= IT_IMAGE
;
4726 it
->image_id
= -1; /* no image */
4727 it
->position
= start_pos
;
4728 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4729 it
->method
= GET_FROM_IMAGE
;
4730 it
->from_overlay
= Qnil
;
4731 it
->face_id
= face_id
;
4732 it
->from_disp_prop_p
= 1;
4734 /* Say that we haven't consumed the characters with
4735 `display' property yet. The call to pop_it in
4736 set_iterator_to_next will clean this up. */
4737 *position
= start_pos
;
4739 if (EQ (XCAR (spec
), Qleft_fringe
))
4741 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4742 it
->left_user_fringe_face_id
= face_id
;
4746 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4747 it
->right_user_fringe_face_id
= face_id
;
4750 #endif /* HAVE_WINDOW_SYSTEM */
4754 /* Prepare to handle `((margin left-margin) ...)',
4755 `((margin right-margin) ...)' and `((margin nil) ...)'
4756 prefixes for display specifications. */
4757 location
= Qunbound
;
4758 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4762 value
= XCDR (spec
);
4764 value
= XCAR (value
);
4767 if (EQ (XCAR (tem
), Qmargin
)
4768 && (tem
= XCDR (tem
),
4769 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4771 || EQ (tem
, Qleft_margin
)
4772 || EQ (tem
, Qright_margin
))))
4776 if (EQ (location
, Qunbound
))
4782 /* After this point, VALUE is the property after any
4783 margin prefix has been stripped. It must be a string,
4784 an image specification, or `(space ...)'.
4786 LOCATION specifies where to display: `left-margin',
4787 `right-margin' or nil. */
4789 valid_p
= (STRINGP (value
)
4790 #ifdef HAVE_WINDOW_SYSTEM
4791 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4792 && valid_image_p (value
))
4793 #endif /* not HAVE_WINDOW_SYSTEM */
4794 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4796 if (valid_p
&& !display_replaced_p
)
4802 /* Callers need to know whether the display spec is any kind
4803 of `(space ...)' spec that is about to affect text-area
4805 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4810 /* Save current settings of IT so that we can restore them
4811 when we are finished with the glyph property value. */
4812 push_it (it
, position
);
4813 it
->from_overlay
= overlay
;
4814 it
->from_disp_prop_p
= 1;
4816 if (NILP (location
))
4817 it
->area
= TEXT_AREA
;
4818 else if (EQ (location
, Qleft_margin
))
4819 it
->area
= LEFT_MARGIN_AREA
;
4821 it
->area
= RIGHT_MARGIN_AREA
;
4823 if (STRINGP (value
))
4826 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4827 it
->current
.overlay_string_index
= -1;
4828 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4829 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4830 it
->method
= GET_FROM_STRING
;
4831 it
->stop_charpos
= 0;
4833 it
->base_level_stop
= 0;
4834 it
->string_from_display_prop_p
= 1;
4835 /* Say that we haven't consumed the characters with
4836 `display' property yet. The call to pop_it in
4837 set_iterator_to_next will clean this up. */
4838 if (BUFFERP (object
))
4839 *position
= start_pos
;
4841 /* Force paragraph direction to be that of the parent
4842 object. If the parent object's paragraph direction is
4843 not yet determined, default to L2R. */
4844 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4845 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4847 it
->paragraph_embedding
= L2R
;
4849 /* Set up the bidi iterator for this display string. */
4852 it
->bidi_it
.string
.lstring
= it
->string
;
4853 it
->bidi_it
.string
.s
= NULL
;
4854 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4855 it
->bidi_it
.string
.bufpos
= bufpos
;
4856 it
->bidi_it
.string
.from_disp_str
= 1;
4857 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4858 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4861 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4863 it
->method
= GET_FROM_STRETCH
;
4865 *position
= it
->position
= start_pos
;
4866 retval
= 1 + (it
->area
== TEXT_AREA
);
4868 #ifdef HAVE_WINDOW_SYSTEM
4871 it
->what
= IT_IMAGE
;
4872 it
->image_id
= lookup_image (it
->f
, value
);
4873 it
->position
= start_pos
;
4874 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4875 it
->method
= GET_FROM_IMAGE
;
4877 /* Say that we haven't consumed the characters with
4878 `display' property yet. The call to pop_it in
4879 set_iterator_to_next will clean this up. */
4880 *position
= start_pos
;
4882 #endif /* HAVE_WINDOW_SYSTEM */
4887 /* Invalid property or property not supported. Restore
4888 POSITION to what it was before. */
4889 *position
= start_pos
;
4893 /* Check if PROP is a display property value whose text should be
4894 treated as intangible. OVERLAY is the overlay from which PROP
4895 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4896 specify the buffer position covered by PROP. */
4899 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4900 EMACS_INT charpos
, EMACS_INT bytepos
)
4902 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4903 struct text_pos position
;
4905 SET_TEXT_POS (position
, charpos
, bytepos
);
4906 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4907 &position
, charpos
, frame_window_p
);
4911 /* Return 1 if PROP is a display sub-property value containing STRING.
4913 Implementation note: this and the following function are really
4914 special cases of handle_display_spec and
4915 handle_single_display_spec, and should ideally use the same code.
4916 Until they do, these two pairs must be consistent and must be
4917 modified in sync. */
4920 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4922 if (EQ (string
, prop
))
4925 /* Skip over `when FORM'. */
4926 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4931 /* Actually, the condition following `when' should be eval'ed,
4932 like handle_single_display_spec does, and we should return
4933 zero if it evaluates to nil. However, this function is
4934 called only when the buffer was already displayed and some
4935 glyph in the glyph matrix was found to come from a display
4936 string. Therefore, the condition was already evaluated, and
4937 the result was non-nil, otherwise the display string wouldn't
4938 have been displayed and we would have never been called for
4939 this property. Thus, we can skip the evaluation and assume
4940 its result is non-nil. */
4945 /* Skip over `margin LOCATION'. */
4946 if (EQ (XCAR (prop
), Qmargin
))
4957 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4961 /* Return 1 if STRING appears in the `display' property PROP. */
4964 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4967 && !EQ (XCAR (prop
), Qwhen
)
4968 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4970 /* A list of sub-properties. */
4971 while (CONSP (prop
))
4973 if (single_display_spec_string_p (XCAR (prop
), string
))
4978 else if (VECTORP (prop
))
4980 /* A vector of sub-properties. */
4982 for (i
= 0; i
< ASIZE (prop
); ++i
)
4983 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4987 return single_display_spec_string_p (prop
, string
);
4992 /* Look for STRING in overlays and text properties in the current
4993 buffer, between character positions FROM and TO (excluding TO).
4994 BACK_P non-zero means look back (in this case, TO is supposed to be
4996 Value is the first character position where STRING was found, or
4997 zero if it wasn't found before hitting TO.
4999 This function may only use code that doesn't eval because it is
5000 called asynchronously from note_mouse_highlight. */
5003 string_buffer_position_lim (Lisp_Object string
,
5004 EMACS_INT from
, EMACS_INT to
, int back_p
)
5006 Lisp_Object limit
, prop
, pos
;
5009 pos
= make_number (max (from
, BEGV
));
5011 if (!back_p
) /* looking forward */
5013 limit
= make_number (min (to
, ZV
));
5014 while (!found
&& !EQ (pos
, limit
))
5016 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5017 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5020 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5024 else /* looking back */
5026 limit
= make_number (max (to
, BEGV
));
5027 while (!found
&& !EQ (pos
, limit
))
5029 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5030 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5033 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5038 return found
? XINT (pos
) : 0;
5041 /* Determine which buffer position in current buffer STRING comes from.
5042 AROUND_CHARPOS is an approximate position where it could come from.
5043 Value is the buffer position or 0 if it couldn't be determined.
5045 This function is necessary because we don't record buffer positions
5046 in glyphs generated from strings (to keep struct glyph small).
5047 This function may only use code that doesn't eval because it is
5048 called asynchronously from note_mouse_highlight. */
5051 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
5053 const int MAX_DISTANCE
= 1000;
5054 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
5055 around_charpos
+ MAX_DISTANCE
,
5059 found
= string_buffer_position_lim (string
, around_charpos
,
5060 around_charpos
- MAX_DISTANCE
, 1);
5066 /***********************************************************************
5067 `composition' property
5068 ***********************************************************************/
5070 /* Set up iterator IT from `composition' property at its current
5071 position. Called from handle_stop. */
5073 static enum prop_handled
5074 handle_composition_prop (struct it
*it
)
5076 Lisp_Object prop
, string
;
5077 EMACS_INT pos
, pos_byte
, start
, end
;
5079 if (STRINGP (it
->string
))
5083 pos
= IT_STRING_CHARPOS (*it
);
5084 pos_byte
= IT_STRING_BYTEPOS (*it
);
5085 string
= it
->string
;
5086 s
= SDATA (string
) + pos_byte
;
5087 it
->c
= STRING_CHAR (s
);
5091 pos
= IT_CHARPOS (*it
);
5092 pos_byte
= IT_BYTEPOS (*it
);
5094 it
->c
= FETCH_CHAR (pos_byte
);
5097 /* If there's a valid composition and point is not inside of the
5098 composition (in the case that the composition is from the current
5099 buffer), draw a glyph composed from the composition components. */
5100 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5101 && COMPOSITION_VALID_P (start
, end
, prop
)
5102 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5105 /* As we can't handle this situation (perhaps font-lock added
5106 a new composition), we just return here hoping that next
5107 redisplay will detect this composition much earlier. */
5108 return HANDLED_NORMALLY
;
5111 if (STRINGP (it
->string
))
5112 pos_byte
= string_char_to_byte (it
->string
, start
);
5114 pos_byte
= CHAR_TO_BYTE (start
);
5116 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5119 if (it
->cmp_it
.id
>= 0)
5122 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5123 it
->cmp_it
.nglyphs
= -1;
5127 return HANDLED_NORMALLY
;
5132 /***********************************************************************
5134 ***********************************************************************/
5136 /* The following structure is used to record overlay strings for
5137 later sorting in load_overlay_strings. */
5139 struct overlay_entry
5141 Lisp_Object overlay
;
5148 /* Set up iterator IT from overlay strings at its current position.
5149 Called from handle_stop. */
5151 static enum prop_handled
5152 handle_overlay_change (struct it
*it
)
5154 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5155 return HANDLED_RECOMPUTE_PROPS
;
5157 return HANDLED_NORMALLY
;
5161 /* Set up the next overlay string for delivery by IT, if there is an
5162 overlay string to deliver. Called by set_iterator_to_next when the
5163 end of the current overlay string is reached. If there are more
5164 overlay strings to display, IT->string and
5165 IT->current.overlay_string_index are set appropriately here.
5166 Otherwise IT->string is set to nil. */
5169 next_overlay_string (struct it
*it
)
5171 ++it
->current
.overlay_string_index
;
5172 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5174 /* No more overlay strings. Restore IT's settings to what
5175 they were before overlay strings were processed, and
5176 continue to deliver from current_buffer. */
5178 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5181 || (NILP (it
->string
)
5182 && it
->method
== GET_FROM_BUFFER
5183 && it
->stop_charpos
>= BEGV
5184 && it
->stop_charpos
<= it
->end_charpos
));
5185 it
->current
.overlay_string_index
= -1;
5186 it
->n_overlay_strings
= 0;
5187 it
->overlay_strings_charpos
= -1;
5188 /* If there's an empty display string on the stack, pop the
5189 stack, to resync the bidi iterator with IT's position. Such
5190 empty strings are pushed onto the stack in
5191 get_overlay_strings_1. */
5192 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5195 /* If we're at the end of the buffer, record that we have
5196 processed the overlay strings there already, so that
5197 next_element_from_buffer doesn't try it again. */
5198 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5199 it
->overlay_strings_at_end_processed_p
= 1;
5203 /* There are more overlay strings to process. If
5204 IT->current.overlay_string_index has advanced to a position
5205 where we must load IT->overlay_strings with more strings, do
5206 it. We must load at the IT->overlay_strings_charpos where
5207 IT->n_overlay_strings was originally computed; when invisible
5208 text is present, this might not be IT_CHARPOS (Bug#7016). */
5209 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5211 if (it
->current
.overlay_string_index
&& i
== 0)
5212 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5214 /* Initialize IT to deliver display elements from the overlay
5216 it
->string
= it
->overlay_strings
[i
];
5217 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5218 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5219 it
->method
= GET_FROM_STRING
;
5220 it
->stop_charpos
= 0;
5221 if (it
->cmp_it
.stop_pos
>= 0)
5222 it
->cmp_it
.stop_pos
= 0;
5224 it
->base_level_stop
= 0;
5226 /* Set up the bidi iterator for this overlay string. */
5229 it
->bidi_it
.string
.lstring
= it
->string
;
5230 it
->bidi_it
.string
.s
= NULL
;
5231 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5232 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5233 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5234 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5235 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5243 /* Compare two overlay_entry structures E1 and E2. Used as a
5244 comparison function for qsort in load_overlay_strings. Overlay
5245 strings for the same position are sorted so that
5247 1. All after-strings come in front of before-strings, except
5248 when they come from the same overlay.
5250 2. Within after-strings, strings are sorted so that overlay strings
5251 from overlays with higher priorities come first.
5253 2. Within before-strings, strings are sorted so that overlay
5254 strings from overlays with higher priorities come last.
5256 Value is analogous to strcmp. */
5260 compare_overlay_entries (const void *e1
, const void *e2
)
5262 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5263 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5266 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5268 /* Let after-strings appear in front of before-strings if
5269 they come from different overlays. */
5270 if (EQ (entry1
->overlay
, entry2
->overlay
))
5271 result
= entry1
->after_string_p
? 1 : -1;
5273 result
= entry1
->after_string_p
? -1 : 1;
5275 else if (entry1
->after_string_p
)
5276 /* After-strings sorted in order of decreasing priority. */
5277 result
= entry2
->priority
- entry1
->priority
;
5279 /* Before-strings sorted in order of increasing priority. */
5280 result
= entry1
->priority
- entry2
->priority
;
5286 /* Load the vector IT->overlay_strings with overlay strings from IT's
5287 current buffer position, or from CHARPOS if that is > 0. Set
5288 IT->n_overlays to the total number of overlay strings found.
5290 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5291 a time. On entry into load_overlay_strings,
5292 IT->current.overlay_string_index gives the number of overlay
5293 strings that have already been loaded by previous calls to this
5296 IT->add_overlay_start contains an additional overlay start
5297 position to consider for taking overlay strings from, if non-zero.
5298 This position comes into play when the overlay has an `invisible'
5299 property, and both before and after-strings. When we've skipped to
5300 the end of the overlay, because of its `invisible' property, we
5301 nevertheless want its before-string to appear.
5302 IT->add_overlay_start will contain the overlay start position
5305 Overlay strings are sorted so that after-string strings come in
5306 front of before-string strings. Within before and after-strings,
5307 strings are sorted by overlay priority. See also function
5308 compare_overlay_entries. */
5311 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5313 Lisp_Object overlay
, window
, str
, invisible
;
5314 struct Lisp_Overlay
*ov
;
5315 EMACS_INT start
, end
;
5317 int n
= 0, i
, j
, invis_p
;
5318 struct overlay_entry
*entries
5319 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
5322 charpos
= IT_CHARPOS (*it
);
5324 /* Append the overlay string STRING of overlay OVERLAY to vector
5325 `entries' which has size `size' and currently contains `n'
5326 elements. AFTER_P non-zero means STRING is an after-string of
5328 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5331 Lisp_Object priority; \
5335 int new_size = 2 * size; \
5336 struct overlay_entry *old = entries; \
5338 (struct overlay_entry *) alloca (new_size \
5339 * sizeof *entries); \
5340 memcpy (entries, old, size * sizeof *entries); \
5344 entries[n].string = (STRING); \
5345 entries[n].overlay = (OVERLAY); \
5346 priority = Foverlay_get ((OVERLAY), Qpriority); \
5347 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5348 entries[n].after_string_p = (AFTER_P); \
5353 /* Process overlay before the overlay center. */
5354 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5356 XSETMISC (overlay
, ov
);
5357 xassert (OVERLAYP (overlay
));
5358 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5359 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5364 /* Skip this overlay if it doesn't start or end at IT's current
5366 if (end
!= charpos
&& start
!= charpos
)
5369 /* Skip this overlay if it doesn't apply to IT->w. */
5370 window
= Foverlay_get (overlay
, Qwindow
);
5371 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5374 /* If the text ``under'' the overlay is invisible, both before-
5375 and after-strings from this overlay are visible; start and
5376 end position are indistinguishable. */
5377 invisible
= Foverlay_get (overlay
, Qinvisible
);
5378 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5380 /* If overlay has a non-empty before-string, record it. */
5381 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5382 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5384 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5386 /* If overlay has a non-empty after-string, record it. */
5387 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5388 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5390 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5393 /* Process overlays after the overlay center. */
5394 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5396 XSETMISC (overlay
, ov
);
5397 xassert (OVERLAYP (overlay
));
5398 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5399 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5401 if (start
> charpos
)
5404 /* Skip this overlay if it doesn't start or end at IT's current
5406 if (end
!= charpos
&& start
!= charpos
)
5409 /* Skip this overlay if it doesn't apply to IT->w. */
5410 window
= Foverlay_get (overlay
, Qwindow
);
5411 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5414 /* If the text ``under'' the overlay is invisible, it has a zero
5415 dimension, and both before- and after-strings apply. */
5416 invisible
= Foverlay_get (overlay
, Qinvisible
);
5417 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5419 /* If overlay has a non-empty before-string, record it. */
5420 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5421 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5423 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5425 /* If overlay has a non-empty after-string, record it. */
5426 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5427 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5429 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5432 #undef RECORD_OVERLAY_STRING
5436 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5438 /* Record number of overlay strings, and where we computed it. */
5439 it
->n_overlay_strings
= n
;
5440 it
->overlay_strings_charpos
= charpos
;
5442 /* IT->current.overlay_string_index is the number of overlay strings
5443 that have already been consumed by IT. Copy some of the
5444 remaining overlay strings to IT->overlay_strings. */
5446 j
= it
->current
.overlay_string_index
;
5447 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5449 it
->overlay_strings
[i
] = entries
[j
].string
;
5450 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5457 /* Get the first chunk of overlay strings at IT's current buffer
5458 position, or at CHARPOS if that is > 0. Value is non-zero if at
5459 least one overlay string was found. */
5462 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5464 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5465 process. This fills IT->overlay_strings with strings, and sets
5466 IT->n_overlay_strings to the total number of strings to process.
5467 IT->pos.overlay_string_index has to be set temporarily to zero
5468 because load_overlay_strings needs this; it must be set to -1
5469 when no overlay strings are found because a zero value would
5470 indicate a position in the first overlay string. */
5471 it
->current
.overlay_string_index
= 0;
5472 load_overlay_strings (it
, charpos
);
5474 /* If we found overlay strings, set up IT to deliver display
5475 elements from the first one. Otherwise set up IT to deliver
5476 from current_buffer. */
5477 if (it
->n_overlay_strings
)
5479 /* Make sure we know settings in current_buffer, so that we can
5480 restore meaningful values when we're done with the overlay
5483 compute_stop_pos (it
);
5484 xassert (it
->face_id
>= 0);
5486 /* Save IT's settings. They are restored after all overlay
5487 strings have been processed. */
5488 xassert (!compute_stop_p
|| it
->sp
== 0);
5490 /* When called from handle_stop, there might be an empty display
5491 string loaded. In that case, don't bother saving it. But
5492 don't use this optimization with the bidi iterator, since we
5493 need the corresponding pop_it call to resync the bidi
5494 iterator's position with IT's position, after we are done
5495 with the overlay strings. (The corresponding call to pop_it
5496 in case of an empty display string is in
5497 next_overlay_string.) */
5499 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5502 /* Set up IT to deliver display elements from the first overlay
5504 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5505 it
->string
= it
->overlay_strings
[0];
5506 it
->from_overlay
= Qnil
;
5507 it
->stop_charpos
= 0;
5508 xassert (STRINGP (it
->string
));
5509 it
->end_charpos
= SCHARS (it
->string
);
5511 it
->base_level_stop
= 0;
5512 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5513 it
->method
= GET_FROM_STRING
;
5514 it
->from_disp_prop_p
= 0;
5516 /* Force paragraph direction to be that of the parent
5518 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5519 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5521 it
->paragraph_embedding
= L2R
;
5523 /* Set up the bidi iterator for this overlay string. */
5526 EMACS_INT pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5528 it
->bidi_it
.string
.lstring
= it
->string
;
5529 it
->bidi_it
.string
.s
= NULL
;
5530 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5531 it
->bidi_it
.string
.bufpos
= pos
;
5532 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5533 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5534 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5539 it
->current
.overlay_string_index
= -1;
5544 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5547 it
->method
= GET_FROM_BUFFER
;
5549 (void) get_overlay_strings_1 (it
, charpos
, 1);
5553 /* Value is non-zero if we found at least one overlay string. */
5554 return STRINGP (it
->string
);
5559 /***********************************************************************
5560 Saving and restoring state
5561 ***********************************************************************/
5563 /* Save current settings of IT on IT->stack. Called, for example,
5564 before setting up IT for an overlay string, to be able to restore
5565 IT's settings to what they were after the overlay string has been
5566 processed. If POSITION is non-NULL, it is the position to save on
5567 the stack instead of IT->position. */
5570 push_it (struct it
*it
, struct text_pos
*position
)
5572 struct iterator_stack_entry
*p
;
5574 xassert (it
->sp
< IT_STACK_SIZE
);
5575 p
= it
->stack
+ it
->sp
;
5577 p
->stop_charpos
= it
->stop_charpos
;
5578 p
->prev_stop
= it
->prev_stop
;
5579 p
->base_level_stop
= it
->base_level_stop
;
5580 p
->cmp_it
= it
->cmp_it
;
5581 xassert (it
->face_id
>= 0);
5582 p
->face_id
= it
->face_id
;
5583 p
->string
= it
->string
;
5584 p
->method
= it
->method
;
5585 p
->from_overlay
= it
->from_overlay
;
5588 case GET_FROM_IMAGE
:
5589 p
->u
.image
.object
= it
->object
;
5590 p
->u
.image
.image_id
= it
->image_id
;
5591 p
->u
.image
.slice
= it
->slice
;
5593 case GET_FROM_STRETCH
:
5594 p
->u
.stretch
.object
= it
->object
;
5597 p
->position
= position
? *position
: it
->position
;
5598 p
->current
= it
->current
;
5599 p
->end_charpos
= it
->end_charpos
;
5600 p
->string_nchars
= it
->string_nchars
;
5602 p
->multibyte_p
= it
->multibyte_p
;
5603 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5604 p
->space_width
= it
->space_width
;
5605 p
->font_height
= it
->font_height
;
5606 p
->voffset
= it
->voffset
;
5607 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5608 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5609 p
->display_ellipsis_p
= 0;
5610 p
->line_wrap
= it
->line_wrap
;
5611 p
->bidi_p
= it
->bidi_p
;
5612 p
->paragraph_embedding
= it
->paragraph_embedding
;
5613 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5616 /* Save the state of the bidi iterator as well. */
5618 bidi_push_it (&it
->bidi_it
);
5622 iterate_out_of_display_property (struct it
*it
)
5624 int buffer_p
= BUFFERP (it
->object
);
5625 EMACS_INT eob
= (buffer_p
? ZV
: it
->end_charpos
);
5626 EMACS_INT bob
= (buffer_p
? BEGV
: 0);
5628 xassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5630 /* Maybe initialize paragraph direction. If we are at the beginning
5631 of a new paragraph, next_element_from_buffer may not have a
5632 chance to do that. */
5633 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5634 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5635 /* prev_stop can be zero, so check against BEGV as well. */
5636 while (it
->bidi_it
.charpos
>= bob
5637 && it
->prev_stop
<= it
->bidi_it
.charpos
5638 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5639 && it
->bidi_it
.charpos
< eob
)
5640 bidi_move_to_visually_next (&it
->bidi_it
);
5641 /* Record the stop_pos we just crossed, for when we cross it
5643 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5644 it
->prev_stop
= CHARPOS (it
->position
);
5645 /* If we ended up not where pop_it put us, resync IT's
5646 positional members with the bidi iterator. */
5647 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5648 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5650 it
->current
.pos
= it
->position
;
5652 it
->current
.string_pos
= it
->position
;
5655 /* Restore IT's settings from IT->stack. Called, for example, when no
5656 more overlay strings must be processed, and we return to delivering
5657 display elements from a buffer, or when the end of a string from a
5658 `display' property is reached and we return to delivering display
5659 elements from an overlay string, or from a buffer. */
5662 pop_it (struct it
*it
)
5664 struct iterator_stack_entry
*p
;
5665 int from_display_prop
= it
->from_disp_prop_p
;
5667 xassert (it
->sp
> 0);
5669 p
= it
->stack
+ it
->sp
;
5670 it
->stop_charpos
= p
->stop_charpos
;
5671 it
->prev_stop
= p
->prev_stop
;
5672 it
->base_level_stop
= p
->base_level_stop
;
5673 it
->cmp_it
= p
->cmp_it
;
5674 it
->face_id
= p
->face_id
;
5675 it
->current
= p
->current
;
5676 it
->position
= p
->position
;
5677 it
->string
= p
->string
;
5678 it
->from_overlay
= p
->from_overlay
;
5679 if (NILP (it
->string
))
5680 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5681 it
->method
= p
->method
;
5684 case GET_FROM_IMAGE
:
5685 it
->image_id
= p
->u
.image
.image_id
;
5686 it
->object
= p
->u
.image
.object
;
5687 it
->slice
= p
->u
.image
.slice
;
5689 case GET_FROM_STRETCH
:
5690 it
->object
= p
->u
.stretch
.object
;
5692 case GET_FROM_BUFFER
:
5693 it
->object
= it
->w
->buffer
;
5695 case GET_FROM_STRING
:
5696 it
->object
= it
->string
;
5698 case GET_FROM_DISPLAY_VECTOR
:
5700 it
->method
= GET_FROM_C_STRING
;
5701 else if (STRINGP (it
->string
))
5702 it
->method
= GET_FROM_STRING
;
5705 it
->method
= GET_FROM_BUFFER
;
5706 it
->object
= it
->w
->buffer
;
5709 it
->end_charpos
= p
->end_charpos
;
5710 it
->string_nchars
= p
->string_nchars
;
5712 it
->multibyte_p
= p
->multibyte_p
;
5713 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5714 it
->space_width
= p
->space_width
;
5715 it
->font_height
= p
->font_height
;
5716 it
->voffset
= p
->voffset
;
5717 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5718 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5719 it
->line_wrap
= p
->line_wrap
;
5720 it
->bidi_p
= p
->bidi_p
;
5721 it
->paragraph_embedding
= p
->paragraph_embedding
;
5722 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5725 bidi_pop_it (&it
->bidi_it
);
5726 /* Bidi-iterate until we get out of the portion of text, if any,
5727 covered by a `display' text property or by an overlay with
5728 `display' property. (We cannot just jump there, because the
5729 internal coherency of the bidi iterator state can not be
5730 preserved across such jumps.) We also must determine the
5731 paragraph base direction if the overlay we just processed is
5732 at the beginning of a new paragraph. */
5733 if (from_display_prop
5734 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5735 iterate_out_of_display_property (it
);
5737 xassert ((BUFFERP (it
->object
)
5738 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5739 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5740 || (STRINGP (it
->object
)
5741 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5742 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5743 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5749 /***********************************************************************
5751 ***********************************************************************/
5753 /* Set IT's current position to the previous line start. */
5756 back_to_previous_line_start (struct it
*it
)
5758 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5759 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5763 /* Move IT to the next line start.
5765 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5766 we skipped over part of the text (as opposed to moving the iterator
5767 continuously over the text). Otherwise, don't change the value
5770 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5771 iterator on the newline, if it was found.
5773 Newlines may come from buffer text, overlay strings, or strings
5774 displayed via the `display' property. That's the reason we can't
5775 simply use find_next_newline_no_quit.
5777 Note that this function may not skip over invisible text that is so
5778 because of text properties and immediately follows a newline. If
5779 it would, function reseat_at_next_visible_line_start, when called
5780 from set_iterator_to_next, would effectively make invisible
5781 characters following a newline part of the wrong glyph row, which
5782 leads to wrong cursor motion. */
5785 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5786 struct bidi_it
*bidi_it_prev
)
5788 EMACS_INT old_selective
;
5789 int newline_found_p
, n
;
5790 const int MAX_NEWLINE_DISTANCE
= 500;
5792 /* If already on a newline, just consume it to avoid unintended
5793 skipping over invisible text below. */
5794 if (it
->what
== IT_CHARACTER
5796 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5798 if (it
->bidi_p
&& bidi_it_prev
)
5799 *bidi_it_prev
= it
->bidi_it
;
5800 set_iterator_to_next (it
, 0);
5805 /* Don't handle selective display in the following. It's (a)
5806 unnecessary because it's done by the caller, and (b) leads to an
5807 infinite recursion because next_element_from_ellipsis indirectly
5808 calls this function. */
5809 old_selective
= it
->selective
;
5812 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5813 from buffer text. */
5814 for (n
= newline_found_p
= 0;
5815 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5816 n
+= STRINGP (it
->string
) ? 0 : 1)
5818 if (!get_next_display_element (it
))
5820 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5821 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5822 *bidi_it_prev
= it
->bidi_it
;
5823 set_iterator_to_next (it
, 0);
5826 /* If we didn't find a newline near enough, see if we can use a
5828 if (!newline_found_p
)
5830 EMACS_INT start
= IT_CHARPOS (*it
);
5831 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5834 xassert (!STRINGP (it
->string
));
5836 /* If there isn't any `display' property in sight, and no
5837 overlays, we can just use the position of the newline in
5839 if (it
->stop_charpos
>= limit
5840 || ((pos
= Fnext_single_property_change (make_number (start
),
5842 make_number (limit
)),
5844 && next_overlay_change (start
) == ZV
))
5848 IT_CHARPOS (*it
) = limit
;
5849 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5853 struct bidi_it bprev
;
5855 /* Help bidi.c avoid expensive searches for display
5856 properties and overlays, by telling it that there are
5857 none up to `limit'. */
5858 if (it
->bidi_it
.disp_pos
< limit
)
5860 it
->bidi_it
.disp_pos
= limit
;
5861 it
->bidi_it
.disp_prop
= 0;
5864 bprev
= it
->bidi_it
;
5865 bidi_move_to_visually_next (&it
->bidi_it
);
5866 } while (it
->bidi_it
.charpos
!= limit
);
5867 IT_CHARPOS (*it
) = limit
;
5868 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
5870 *bidi_it_prev
= bprev
;
5872 *skipped_p
= newline_found_p
= 1;
5876 while (get_next_display_element (it
)
5877 && !newline_found_p
)
5879 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5880 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5881 *bidi_it_prev
= it
->bidi_it
;
5882 set_iterator_to_next (it
, 0);
5887 it
->selective
= old_selective
;
5888 return newline_found_p
;
5892 /* Set IT's current position to the previous visible line start. Skip
5893 invisible text that is so either due to text properties or due to
5894 selective display. Caution: this does not change IT->current_x and
5898 back_to_previous_visible_line_start (struct it
*it
)
5900 while (IT_CHARPOS (*it
) > BEGV
)
5902 back_to_previous_line_start (it
);
5904 if (IT_CHARPOS (*it
) <= BEGV
)
5907 /* If selective > 0, then lines indented more than its value are
5909 if (it
->selective
> 0
5910 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5914 /* Check the newline before point for invisibility. */
5917 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5918 Qinvisible
, it
->window
);
5919 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5923 if (IT_CHARPOS (*it
) <= BEGV
)
5928 void *it2data
= NULL
;
5931 Lisp_Object val
, overlay
;
5933 SAVE_IT (it2
, *it
, it2data
);
5935 /* If newline is part of a composition, continue from start of composition */
5936 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5937 && beg
< IT_CHARPOS (*it
))
5940 /* If newline is replaced by a display property, find start of overlay
5941 or interval and continue search from that point. */
5942 pos
= --IT_CHARPOS (it2
);
5945 bidi_unshelve_cache (NULL
, 0);
5946 it2
.string_from_display_prop_p
= 0;
5947 it2
.from_disp_prop_p
= 0;
5948 if (handle_display_prop (&it2
) == HANDLED_RETURN
5949 && !NILP (val
= get_char_property_and_overlay
5950 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5951 && (OVERLAYP (overlay
)
5952 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5953 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5955 RESTORE_IT (it
, it
, it2data
);
5959 /* Newline is not replaced by anything -- so we are done. */
5960 RESTORE_IT (it
, it
, it2data
);
5966 IT_CHARPOS (*it
) = beg
;
5967 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5971 it
->continuation_lines_width
= 0;
5973 xassert (IT_CHARPOS (*it
) >= BEGV
);
5974 xassert (IT_CHARPOS (*it
) == BEGV
5975 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5980 /* Reseat iterator IT at the previous visible line start. Skip
5981 invisible text that is so either due to text properties or due to
5982 selective display. At the end, update IT's overlay information,
5983 face information etc. */
5986 reseat_at_previous_visible_line_start (struct it
*it
)
5988 back_to_previous_visible_line_start (it
);
5989 reseat (it
, it
->current
.pos
, 1);
5994 /* Reseat iterator IT on the next visible line start in the current
5995 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5996 preceding the line start. Skip over invisible text that is so
5997 because of selective display. Compute faces, overlays etc at the
5998 new position. Note that this function does not skip over text that
5999 is invisible because of text properties. */
6002 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6004 int newline_found_p
, skipped_p
= 0;
6005 struct bidi_it bidi_it_prev
;
6007 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6009 /* Skip over lines that are invisible because they are indented
6010 more than the value of IT->selective. */
6011 if (it
->selective
> 0)
6012 while (IT_CHARPOS (*it
) < ZV
6013 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6016 xassert (IT_BYTEPOS (*it
) == BEGV
6017 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6019 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6022 /* Position on the newline if that's what's requested. */
6023 if (on_newline_p
&& newline_found_p
)
6025 if (STRINGP (it
->string
))
6027 if (IT_STRING_CHARPOS (*it
) > 0)
6031 --IT_STRING_CHARPOS (*it
);
6032 --IT_STRING_BYTEPOS (*it
);
6036 /* We need to restore the bidi iterator to the state
6037 it had on the newline, and resync the IT's
6038 position with that. */
6039 it
->bidi_it
= bidi_it_prev
;
6040 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6041 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6045 else if (IT_CHARPOS (*it
) > BEGV
)
6054 /* We need to restore the bidi iterator to the state it
6055 had on the newline and resync IT with that. */
6056 it
->bidi_it
= bidi_it_prev
;
6057 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6058 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6060 reseat (it
, it
->current
.pos
, 0);
6064 reseat (it
, it
->current
.pos
, 0);
6071 /***********************************************************************
6072 Changing an iterator's position
6073 ***********************************************************************/
6075 /* Change IT's current position to POS in current_buffer. If FORCE_P
6076 is non-zero, always check for text properties at the new position.
6077 Otherwise, text properties are only looked up if POS >=
6078 IT->check_charpos of a property. */
6081 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6083 EMACS_INT original_pos
= IT_CHARPOS (*it
);
6085 reseat_1 (it
, pos
, 0);
6087 /* Determine where to check text properties. Avoid doing it
6088 where possible because text property lookup is very expensive. */
6090 || CHARPOS (pos
) > it
->stop_charpos
6091 || CHARPOS (pos
) < original_pos
)
6095 /* For bidi iteration, we need to prime prev_stop and
6096 base_level_stop with our best estimations. */
6097 /* Implementation note: Of course, POS is not necessarily a
6098 stop position, so assigning prev_pos to it is a lie; we
6099 should have called compute_stop_backwards. However, if
6100 the current buffer does not include any R2L characters,
6101 that call would be a waste of cycles, because the
6102 iterator will never move back, and thus never cross this
6103 "fake" stop position. So we delay that backward search
6104 until the time we really need it, in next_element_from_buffer. */
6105 if (CHARPOS (pos
) != it
->prev_stop
)
6106 it
->prev_stop
= CHARPOS (pos
);
6107 if (CHARPOS (pos
) < it
->base_level_stop
)
6108 it
->base_level_stop
= 0; /* meaning it's unknown */
6114 it
->prev_stop
= it
->base_level_stop
= 0;
6123 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6124 IT->stop_pos to POS, also. */
6127 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6129 /* Don't call this function when scanning a C string. */
6130 xassert (it
->s
== NULL
);
6132 /* POS must be a reasonable value. */
6133 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6135 it
->current
.pos
= it
->position
= pos
;
6136 it
->end_charpos
= ZV
;
6138 it
->current
.dpvec_index
= -1;
6139 it
->current
.overlay_string_index
= -1;
6140 IT_STRING_CHARPOS (*it
) = -1;
6141 IT_STRING_BYTEPOS (*it
) = -1;
6143 it
->method
= GET_FROM_BUFFER
;
6144 it
->object
= it
->w
->buffer
;
6145 it
->area
= TEXT_AREA
;
6146 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6148 it
->string_from_display_prop_p
= 0;
6149 it
->string_from_prefix_prop_p
= 0;
6151 it
->from_disp_prop_p
= 0;
6152 it
->face_before_selective_p
= 0;
6155 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6157 bidi_unshelve_cache (NULL
, 0);
6158 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6159 it
->bidi_it
.string
.s
= NULL
;
6160 it
->bidi_it
.string
.lstring
= Qnil
;
6161 it
->bidi_it
.string
.bufpos
= 0;
6162 it
->bidi_it
.string
.unibyte
= 0;
6167 it
->stop_charpos
= CHARPOS (pos
);
6168 it
->base_level_stop
= CHARPOS (pos
);
6173 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6174 If S is non-null, it is a C string to iterate over. Otherwise,
6175 STRING gives a Lisp string to iterate over.
6177 If PRECISION > 0, don't return more then PRECISION number of
6178 characters from the string.
6180 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6181 characters have been returned. FIELD_WIDTH < 0 means an infinite
6184 MULTIBYTE = 0 means disable processing of multibyte characters,
6185 MULTIBYTE > 0 means enable it,
6186 MULTIBYTE < 0 means use IT->multibyte_p.
6188 IT must be initialized via a prior call to init_iterator before
6189 calling this function. */
6192 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6193 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
6196 /* No region in strings. */
6197 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6199 /* No text property checks performed by default, but see below. */
6200 it
->stop_charpos
= -1;
6202 /* Set iterator position and end position. */
6203 memset (&it
->current
, 0, sizeof it
->current
);
6204 it
->current
.overlay_string_index
= -1;
6205 it
->current
.dpvec_index
= -1;
6206 xassert (charpos
>= 0);
6208 /* If STRING is specified, use its multibyteness, otherwise use the
6209 setting of MULTIBYTE, if specified. */
6211 it
->multibyte_p
= multibyte
> 0;
6213 /* Bidirectional reordering of strings is controlled by the default
6214 value of bidi-display-reordering. Don't try to reorder while
6215 loading loadup.el, as the necessary character property tables are
6216 not yet available. */
6219 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6223 xassert (STRINGP (string
));
6224 it
->string
= string
;
6226 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6227 it
->method
= GET_FROM_STRING
;
6228 it
->current
.string_pos
= string_pos (charpos
, string
);
6232 it
->bidi_it
.string
.lstring
= string
;
6233 it
->bidi_it
.string
.s
= NULL
;
6234 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6235 it
->bidi_it
.string
.bufpos
= 0;
6236 it
->bidi_it
.string
.from_disp_str
= 0;
6237 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6238 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6239 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6244 it
->s
= (const unsigned char *) s
;
6247 /* Note that we use IT->current.pos, not it->current.string_pos,
6248 for displaying C strings. */
6249 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6250 if (it
->multibyte_p
)
6252 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6253 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6257 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6258 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6263 it
->bidi_it
.string
.lstring
= Qnil
;
6264 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6265 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6266 it
->bidi_it
.string
.bufpos
= 0;
6267 it
->bidi_it
.string
.from_disp_str
= 0;
6268 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6269 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6272 it
->method
= GET_FROM_C_STRING
;
6275 /* PRECISION > 0 means don't return more than PRECISION characters
6277 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6279 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6281 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6284 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6285 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6286 FIELD_WIDTH < 0 means infinite field width. This is useful for
6287 padding with `-' at the end of a mode line. */
6288 if (field_width
< 0)
6289 field_width
= INFINITY
;
6290 /* Implementation note: We deliberately don't enlarge
6291 it->bidi_it.string.schars here to fit it->end_charpos, because
6292 the bidi iterator cannot produce characters out of thin air. */
6293 if (field_width
> it
->end_charpos
- charpos
)
6294 it
->end_charpos
= charpos
+ field_width
;
6296 /* Use the standard display table for displaying strings. */
6297 if (DISP_TABLE_P (Vstandard_display_table
))
6298 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6300 it
->stop_charpos
= charpos
;
6301 it
->prev_stop
= charpos
;
6302 it
->base_level_stop
= 0;
6305 it
->bidi_it
.first_elt
= 1;
6306 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6307 it
->bidi_it
.disp_pos
= -1;
6309 if (s
== NULL
&& it
->multibyte_p
)
6311 EMACS_INT endpos
= SCHARS (it
->string
);
6312 if (endpos
> it
->end_charpos
)
6313 endpos
= it
->end_charpos
;
6314 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6322 /***********************************************************************
6324 ***********************************************************************/
6326 /* Map enum it_method value to corresponding next_element_from_* function. */
6328 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6330 next_element_from_buffer
,
6331 next_element_from_display_vector
,
6332 next_element_from_string
,
6333 next_element_from_c_string
,
6334 next_element_from_image
,
6335 next_element_from_stretch
6338 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6341 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6342 (possibly with the following characters). */
6344 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6345 ((IT)->cmp_it.id >= 0 \
6346 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6347 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6348 END_CHARPOS, (IT)->w, \
6349 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6353 /* Lookup the char-table Vglyphless_char_display for character C (-1
6354 if we want information for no-font case), and return the display
6355 method symbol. By side-effect, update it->what and
6356 it->glyphless_method. This function is called from
6357 get_next_display_element for each character element, and from
6358 x_produce_glyphs when no suitable font was found. */
6361 lookup_glyphless_char_display (int c
, struct it
*it
)
6363 Lisp_Object glyphless_method
= Qnil
;
6365 if (CHAR_TABLE_P (Vglyphless_char_display
)
6366 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6370 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6371 if (CONSP (glyphless_method
))
6372 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6373 ? XCAR (glyphless_method
)
6374 : XCDR (glyphless_method
);
6377 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6381 if (NILP (glyphless_method
))
6384 /* The default is to display the character by a proper font. */
6386 /* The default for the no-font case is to display an empty box. */
6387 glyphless_method
= Qempty_box
;
6389 if (EQ (glyphless_method
, Qzero_width
))
6392 return glyphless_method
;
6393 /* This method can't be used for the no-font case. */
6394 glyphless_method
= Qempty_box
;
6396 if (EQ (glyphless_method
, Qthin_space
))
6397 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6398 else if (EQ (glyphless_method
, Qempty_box
))
6399 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6400 else if (EQ (glyphless_method
, Qhex_code
))
6401 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6402 else if (STRINGP (glyphless_method
))
6403 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6406 /* Invalid value. We use the default method. */
6407 glyphless_method
= Qnil
;
6410 it
->what
= IT_GLYPHLESS
;
6411 return glyphless_method
;
6414 /* Load IT's display element fields with information about the next
6415 display element from the current position of IT. Value is zero if
6416 end of buffer (or C string) is reached. */
6418 static struct frame
*last_escape_glyph_frame
= NULL
;
6419 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6420 static int last_escape_glyph_merged_face_id
= 0;
6422 struct frame
*last_glyphless_glyph_frame
= NULL
;
6423 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6424 int last_glyphless_glyph_merged_face_id
= 0;
6427 get_next_display_element (struct it
*it
)
6429 /* Non-zero means that we found a display element. Zero means that
6430 we hit the end of what we iterate over. Performance note: the
6431 function pointer `method' used here turns out to be faster than
6432 using a sequence of if-statements. */
6436 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6438 if (it
->what
== IT_CHARACTER
)
6440 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6441 and only if (a) the resolved directionality of that character
6443 /* FIXME: Do we need an exception for characters from display
6445 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6446 it
->c
= bidi_mirror_char (it
->c
);
6447 /* Map via display table or translate control characters.
6448 IT->c, IT->len etc. have been set to the next character by
6449 the function call above. If we have a display table, and it
6450 contains an entry for IT->c, translate it. Don't do this if
6451 IT->c itself comes from a display table, otherwise we could
6452 end up in an infinite recursion. (An alternative could be to
6453 count the recursion depth of this function and signal an
6454 error when a certain maximum depth is reached.) Is it worth
6456 if (success_p
&& it
->dpvec
== NULL
)
6459 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6460 int nonascii_space_p
= 0;
6461 int nonascii_hyphen_p
= 0;
6462 int c
= it
->c
; /* This is the character to display. */
6464 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6466 xassert (SINGLE_BYTE_CHAR_P (c
));
6467 if (unibyte_display_via_language_environment
)
6469 c
= DECODE_CHAR (unibyte
, c
);
6471 c
= BYTE8_TO_CHAR (it
->c
);
6474 c
= BYTE8_TO_CHAR (it
->c
);
6478 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6481 struct Lisp_Vector
*v
= XVECTOR (dv
);
6483 /* Return the first character from the display table
6484 entry, if not empty. If empty, don't display the
6485 current character. */
6488 it
->dpvec_char_len
= it
->len
;
6489 it
->dpvec
= v
->contents
;
6490 it
->dpend
= v
->contents
+ v
->header
.size
;
6491 it
->current
.dpvec_index
= 0;
6492 it
->dpvec_face_id
= -1;
6493 it
->saved_face_id
= it
->face_id
;
6494 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6499 set_iterator_to_next (it
, 0);
6504 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6506 if (it
->what
== IT_GLYPHLESS
)
6508 /* Don't display this character. */
6509 set_iterator_to_next (it
, 0);
6513 /* If `nobreak-char-display' is non-nil, we display
6514 non-ASCII spaces and hyphens specially. */
6515 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6518 nonascii_space_p
= 1;
6519 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6520 nonascii_hyphen_p
= 1;
6523 /* Translate control characters into `\003' or `^C' form.
6524 Control characters coming from a display table entry are
6525 currently not translated because we use IT->dpvec to hold
6526 the translation. This could easily be changed but I
6527 don't believe that it is worth doing.
6529 The characters handled by `nobreak-char-display' must be
6532 Non-printable characters and raw-byte characters are also
6533 translated to octal form. */
6534 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6535 ? (it
->area
!= TEXT_AREA
6536 /* In mode line, treat \n, \t like other crl chars. */
6539 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6540 || (c
!= '\n' && c
!= '\t'))
6542 || nonascii_hyphen_p
6544 || ! CHAR_PRINTABLE_P (c
))))
6546 /* C is a control character, non-ASCII space/hyphen,
6547 raw-byte, or a non-printable character which must be
6548 displayed either as '\003' or as `^C' where the '\\'
6549 and '^' can be defined in the display table. Fill
6550 IT->ctl_chars with glyphs for what we have to
6551 display. Then, set IT->dpvec to these glyphs. */
6555 EMACS_INT lface_id
= 0;
6558 /* Handle control characters with ^. */
6560 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6564 g
= '^'; /* default glyph for Control */
6565 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6567 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6568 && GLYPH_CODE_CHAR_VALID_P (gc
))
6570 g
= GLYPH_CODE_CHAR (gc
);
6571 lface_id
= GLYPH_CODE_FACE (gc
);
6575 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6577 else if (it
->f
== last_escape_glyph_frame
6578 && it
->face_id
== last_escape_glyph_face_id
)
6580 face_id
= last_escape_glyph_merged_face_id
;
6584 /* Merge the escape-glyph face into the current face. */
6585 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6587 last_escape_glyph_frame
= it
->f
;
6588 last_escape_glyph_face_id
= it
->face_id
;
6589 last_escape_glyph_merged_face_id
= face_id
;
6592 XSETINT (it
->ctl_chars
[0], g
);
6593 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6595 goto display_control
;
6598 /* Handle non-ascii space in the mode where it only gets
6601 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6603 /* Merge `nobreak-space' into the current face. */
6604 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6606 XSETINT (it
->ctl_chars
[0], ' ');
6608 goto display_control
;
6611 /* Handle sequences that start with the "escape glyph". */
6613 /* the default escape glyph is \. */
6614 escape_glyph
= '\\';
6617 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6618 && GLYPH_CODE_CHAR_VALID_P (gc
))
6620 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6621 lface_id
= GLYPH_CODE_FACE (gc
);
6625 /* The display table specified a face.
6626 Merge it into face_id and also into escape_glyph. */
6627 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6630 else if (it
->f
== last_escape_glyph_frame
6631 && it
->face_id
== last_escape_glyph_face_id
)
6633 face_id
= last_escape_glyph_merged_face_id
;
6637 /* Merge the escape-glyph face into the current face. */
6638 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6640 last_escape_glyph_frame
= it
->f
;
6641 last_escape_glyph_face_id
= it
->face_id
;
6642 last_escape_glyph_merged_face_id
= face_id
;
6645 /* Draw non-ASCII hyphen with just highlighting: */
6647 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6649 XSETINT (it
->ctl_chars
[0], '-');
6651 goto display_control
;
6654 /* Draw non-ASCII space/hyphen with escape glyph: */
6656 if (nonascii_space_p
|| nonascii_hyphen_p
)
6658 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6659 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6661 goto display_control
;
6668 if (CHAR_BYTE8_P (c
))
6669 /* Display \200 instead of \17777600. */
6670 c
= CHAR_TO_BYTE8 (c
);
6671 len
= sprintf (str
, "%03o", c
);
6673 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6674 for (i
= 0; i
< len
; i
++)
6675 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6680 /* Set up IT->dpvec and return first character from it. */
6681 it
->dpvec_char_len
= it
->len
;
6682 it
->dpvec
= it
->ctl_chars
;
6683 it
->dpend
= it
->dpvec
+ ctl_len
;
6684 it
->current
.dpvec_index
= 0;
6685 it
->dpvec_face_id
= face_id
;
6686 it
->saved_face_id
= it
->face_id
;
6687 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6691 it
->char_to_display
= c
;
6695 it
->char_to_display
= it
->c
;
6699 /* Adjust face id for a multibyte character. There are no multibyte
6700 character in unibyte text. */
6701 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6704 && FRAME_WINDOW_P (it
->f
))
6706 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6708 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6710 /* Automatic composition with glyph-string. */
6711 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6713 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6717 EMACS_INT pos
= (it
->s
? -1
6718 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6719 : IT_CHARPOS (*it
));
6722 if (it
->what
== IT_CHARACTER
)
6723 c
= it
->char_to_display
;
6726 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6730 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6731 /* TAB in a composition means display glyphs with
6732 padding space on the left or right. */
6733 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6736 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6741 /* Is this character the last one of a run of characters with
6742 box? If yes, set IT->end_of_box_run_p to 1. */
6746 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6748 int face_id
= underlying_face_id (it
);
6749 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6753 if (face
->box
== FACE_NO_BOX
)
6755 /* If the box comes from face properties in a
6756 display string, check faces in that string. */
6757 int string_face_id
= face_after_it_pos (it
);
6758 it
->end_of_box_run_p
6759 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6762 /* Otherwise, the box comes from the underlying face.
6763 If this is the last string character displayed, check
6764 the next buffer location. */
6765 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6766 && (it
->current
.overlay_string_index
6767 == it
->n_overlay_strings
- 1))
6771 struct text_pos pos
= it
->current
.pos
;
6772 INC_TEXT_POS (pos
, it
->multibyte_p
);
6774 next_face_id
= face_at_buffer_position
6775 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6776 it
->region_end_charpos
, &ignore
,
6777 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6779 it
->end_of_box_run_p
6780 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6787 int face_id
= face_after_it_pos (it
);
6788 it
->end_of_box_run_p
6789 = (face_id
!= it
->face_id
6790 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6794 /* Value is 0 if end of buffer or string reached. */
6799 /* Move IT to the next display element.
6801 RESEAT_P non-zero means if called on a newline in buffer text,
6802 skip to the next visible line start.
6804 Functions get_next_display_element and set_iterator_to_next are
6805 separate because I find this arrangement easier to handle than a
6806 get_next_display_element function that also increments IT's
6807 position. The way it is we can first look at an iterator's current
6808 display element, decide whether it fits on a line, and if it does,
6809 increment the iterator position. The other way around we probably
6810 would either need a flag indicating whether the iterator has to be
6811 incremented the next time, or we would have to implement a
6812 decrement position function which would not be easy to write. */
6815 set_iterator_to_next (struct it
*it
, int reseat_p
)
6817 /* Reset flags indicating start and end of a sequence of characters
6818 with box. Reset them at the start of this function because
6819 moving the iterator to a new position might set them. */
6820 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6824 case GET_FROM_BUFFER
:
6825 /* The current display element of IT is a character from
6826 current_buffer. Advance in the buffer, and maybe skip over
6827 invisible lines that are so because of selective display. */
6828 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6829 reseat_at_next_visible_line_start (it
, 0);
6830 else if (it
->cmp_it
.id
>= 0)
6832 /* We are currently getting glyphs from a composition. */
6837 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6838 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6839 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6841 it
->cmp_it
.from
= it
->cmp_it
.to
;
6846 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6848 it
->end_charpos
, Qnil
);
6851 else if (! it
->cmp_it
.reversed_p
)
6853 /* Composition created while scanning forward. */
6854 /* Update IT's char/byte positions to point to the first
6855 character of the next grapheme cluster, or to the
6856 character visually after the current composition. */
6857 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6858 bidi_move_to_visually_next (&it
->bidi_it
);
6859 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6860 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6862 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6864 /* Proceed to the next grapheme cluster. */
6865 it
->cmp_it
.from
= it
->cmp_it
.to
;
6869 /* No more grapheme clusters in this composition.
6870 Find the next stop position. */
6871 EMACS_INT stop
= it
->end_charpos
;
6872 if (it
->bidi_it
.scan_dir
< 0)
6873 /* Now we are scanning backward and don't know
6876 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6877 IT_BYTEPOS (*it
), stop
, Qnil
);
6882 /* Composition created while scanning backward. */
6883 /* Update IT's char/byte positions to point to the last
6884 character of the previous grapheme cluster, or the
6885 character visually after the current composition. */
6886 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6887 bidi_move_to_visually_next (&it
->bidi_it
);
6888 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6889 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6890 if (it
->cmp_it
.from
> 0)
6892 /* Proceed to the previous grapheme cluster. */
6893 it
->cmp_it
.to
= it
->cmp_it
.from
;
6897 /* No more grapheme clusters in this composition.
6898 Find the next stop position. */
6899 EMACS_INT stop
= it
->end_charpos
;
6900 if (it
->bidi_it
.scan_dir
< 0)
6901 /* Now we are scanning backward and don't know
6904 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6905 IT_BYTEPOS (*it
), stop
, Qnil
);
6911 xassert (it
->len
!= 0);
6915 IT_BYTEPOS (*it
) += it
->len
;
6916 IT_CHARPOS (*it
) += 1;
6920 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6921 /* If this is a new paragraph, determine its base
6922 direction (a.k.a. its base embedding level). */
6923 if (it
->bidi_it
.new_paragraph
)
6924 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6925 bidi_move_to_visually_next (&it
->bidi_it
);
6926 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6927 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6928 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6930 /* As the scan direction was changed, we must
6931 re-compute the stop position for composition. */
6932 EMACS_INT stop
= it
->end_charpos
;
6933 if (it
->bidi_it
.scan_dir
< 0)
6935 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6936 IT_BYTEPOS (*it
), stop
, Qnil
);
6939 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6943 case GET_FROM_C_STRING
:
6944 /* Current display element of IT is from a C string. */
6946 /* If the string position is beyond string's end, it means
6947 next_element_from_c_string is padding the string with
6948 blanks, in which case we bypass the bidi iterator,
6949 because it cannot deal with such virtual characters. */
6950 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6952 IT_BYTEPOS (*it
) += it
->len
;
6953 IT_CHARPOS (*it
) += 1;
6957 bidi_move_to_visually_next (&it
->bidi_it
);
6958 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6959 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6963 case GET_FROM_DISPLAY_VECTOR
:
6964 /* Current display element of IT is from a display table entry.
6965 Advance in the display table definition. Reset it to null if
6966 end reached, and continue with characters from buffers/
6968 ++it
->current
.dpvec_index
;
6970 /* Restore face of the iterator to what they were before the
6971 display vector entry (these entries may contain faces). */
6972 it
->face_id
= it
->saved_face_id
;
6974 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6976 int recheck_faces
= it
->ellipsis_p
;
6979 it
->method
= GET_FROM_C_STRING
;
6980 else if (STRINGP (it
->string
))
6981 it
->method
= GET_FROM_STRING
;
6984 it
->method
= GET_FROM_BUFFER
;
6985 it
->object
= it
->w
->buffer
;
6989 it
->current
.dpvec_index
= -1;
6991 /* Skip over characters which were displayed via IT->dpvec. */
6992 if (it
->dpvec_char_len
< 0)
6993 reseat_at_next_visible_line_start (it
, 1);
6994 else if (it
->dpvec_char_len
> 0)
6996 if (it
->method
== GET_FROM_STRING
6997 && it
->n_overlay_strings
> 0)
6998 it
->ignore_overlay_strings_at_pos_p
= 1;
6999 it
->len
= it
->dpvec_char_len
;
7000 set_iterator_to_next (it
, reseat_p
);
7003 /* Maybe recheck faces after display vector */
7005 it
->stop_charpos
= IT_CHARPOS (*it
);
7009 case GET_FROM_STRING
:
7010 /* Current display element is a character from a Lisp string. */
7011 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
7012 if (it
->cmp_it
.id
>= 0)
7018 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7019 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7020 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7021 it
->cmp_it
.from
= it
->cmp_it
.to
;
7025 composition_compute_stop_pos (&it
->cmp_it
,
7026 IT_STRING_CHARPOS (*it
),
7027 IT_STRING_BYTEPOS (*it
),
7028 it
->end_charpos
, it
->string
);
7031 else if (! it
->cmp_it
.reversed_p
)
7033 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7034 bidi_move_to_visually_next (&it
->bidi_it
);
7035 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7036 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7038 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7039 it
->cmp_it
.from
= it
->cmp_it
.to
;
7042 EMACS_INT stop
= it
->end_charpos
;
7043 if (it
->bidi_it
.scan_dir
< 0)
7045 composition_compute_stop_pos (&it
->cmp_it
,
7046 IT_STRING_CHARPOS (*it
),
7047 IT_STRING_BYTEPOS (*it
), stop
,
7053 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7054 bidi_move_to_visually_next (&it
->bidi_it
);
7055 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7056 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7057 if (it
->cmp_it
.from
> 0)
7058 it
->cmp_it
.to
= it
->cmp_it
.from
;
7061 EMACS_INT stop
= it
->end_charpos
;
7062 if (it
->bidi_it
.scan_dir
< 0)
7064 composition_compute_stop_pos (&it
->cmp_it
,
7065 IT_STRING_CHARPOS (*it
),
7066 IT_STRING_BYTEPOS (*it
), stop
,
7074 /* If the string position is beyond string's end, it
7075 means next_element_from_string is padding the string
7076 with blanks, in which case we bypass the bidi
7077 iterator, because it cannot deal with such virtual
7079 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7081 IT_STRING_BYTEPOS (*it
) += it
->len
;
7082 IT_STRING_CHARPOS (*it
) += 1;
7086 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7088 bidi_move_to_visually_next (&it
->bidi_it
);
7089 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7090 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7091 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7093 EMACS_INT stop
= it
->end_charpos
;
7095 if (it
->bidi_it
.scan_dir
< 0)
7097 composition_compute_stop_pos (&it
->cmp_it
,
7098 IT_STRING_CHARPOS (*it
),
7099 IT_STRING_BYTEPOS (*it
), stop
,
7105 consider_string_end
:
7107 if (it
->current
.overlay_string_index
>= 0)
7109 /* IT->string is an overlay string. Advance to the
7110 next, if there is one. */
7111 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7114 next_overlay_string (it
);
7116 setup_for_ellipsis (it
, 0);
7121 /* IT->string is not an overlay string. If we reached
7122 its end, and there is something on IT->stack, proceed
7123 with what is on the stack. This can be either another
7124 string, this time an overlay string, or a buffer. */
7125 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7129 if (it
->method
== GET_FROM_STRING
)
7130 goto consider_string_end
;
7135 case GET_FROM_IMAGE
:
7136 case GET_FROM_STRETCH
:
7137 /* The position etc with which we have to proceed are on
7138 the stack. The position may be at the end of a string,
7139 if the `display' property takes up the whole string. */
7140 xassert (it
->sp
> 0);
7142 if (it
->method
== GET_FROM_STRING
)
7143 goto consider_string_end
;
7147 /* There are no other methods defined, so this should be a bug. */
7151 xassert (it
->method
!= GET_FROM_STRING
7152 || (STRINGP (it
->string
)
7153 && IT_STRING_CHARPOS (*it
) >= 0));
7156 /* Load IT's display element fields with information about the next
7157 display element which comes from a display table entry or from the
7158 result of translating a control character to one of the forms `^C'
7161 IT->dpvec holds the glyphs to return as characters.
7162 IT->saved_face_id holds the face id before the display vector--it
7163 is restored into IT->face_id in set_iterator_to_next. */
7166 next_element_from_display_vector (struct it
*it
)
7171 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7173 it
->face_id
= it
->saved_face_id
;
7175 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7176 That seemed totally bogus - so I changed it... */
7177 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7179 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
7181 it
->c
= GLYPH_CODE_CHAR (gc
);
7182 it
->len
= CHAR_BYTES (it
->c
);
7184 /* The entry may contain a face id to use. Such a face id is
7185 the id of a Lisp face, not a realized face. A face id of
7186 zero means no face is specified. */
7187 if (it
->dpvec_face_id
>= 0)
7188 it
->face_id
= it
->dpvec_face_id
;
7191 EMACS_INT lface_id
= GLYPH_CODE_FACE (gc
);
7193 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7198 /* Display table entry is invalid. Return a space. */
7199 it
->c
= ' ', it
->len
= 1;
7201 /* Don't change position and object of the iterator here. They are
7202 still the values of the character that had this display table
7203 entry or was translated, and that's what we want. */
7204 it
->what
= IT_CHARACTER
;
7208 /* Get the first element of string/buffer in the visual order, after
7209 being reseated to a new position in a string or a buffer. */
7211 get_visually_first_element (struct it
*it
)
7213 int string_p
= STRINGP (it
->string
) || it
->s
;
7214 EMACS_INT eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7215 EMACS_INT bob
= (string_p
? 0 : BEGV
);
7217 if (STRINGP (it
->string
))
7219 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7220 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7224 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7225 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7228 if (it
->bidi_it
.charpos
== eob
)
7230 /* Nothing to do, but reset the FIRST_ELT flag, like
7231 bidi_paragraph_init does, because we are not going to
7233 it
->bidi_it
.first_elt
= 0;
7235 else if (it
->bidi_it
.charpos
== bob
7237 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7238 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7240 /* If we are at the beginning of a line/string, we can produce
7241 the next element right away. */
7242 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7243 bidi_move_to_visually_next (&it
->bidi_it
);
7247 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
7249 /* We need to prime the bidi iterator starting at the line's or
7250 string's beginning, before we will be able to produce the
7253 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7256 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7258 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7260 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7263 /* Now return to buffer/string position where we were asked
7264 to get the next display element, and produce that. */
7265 bidi_move_to_visually_next (&it
->bidi_it
);
7267 while (it
->bidi_it
.bytepos
!= orig_bytepos
7268 && it
->bidi_it
.charpos
< eob
);
7271 /* Adjust IT's position information to where we ended up. */
7272 if (STRINGP (it
->string
))
7274 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7275 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7279 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7280 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7283 if (STRINGP (it
->string
) || !it
->s
)
7285 EMACS_INT stop
, charpos
, bytepos
;
7287 if (STRINGP (it
->string
))
7290 stop
= SCHARS (it
->string
);
7291 if (stop
> it
->end_charpos
)
7292 stop
= it
->end_charpos
;
7293 charpos
= IT_STRING_CHARPOS (*it
);
7294 bytepos
= IT_STRING_BYTEPOS (*it
);
7298 stop
= it
->end_charpos
;
7299 charpos
= IT_CHARPOS (*it
);
7300 bytepos
= IT_BYTEPOS (*it
);
7302 if (it
->bidi_it
.scan_dir
< 0)
7304 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7309 /* Load IT with the next display element from Lisp string IT->string.
7310 IT->current.string_pos is the current position within the string.
7311 If IT->current.overlay_string_index >= 0, the Lisp string is an
7315 next_element_from_string (struct it
*it
)
7317 struct text_pos position
;
7319 xassert (STRINGP (it
->string
));
7320 xassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7321 xassert (IT_STRING_CHARPOS (*it
) >= 0);
7322 position
= it
->current
.string_pos
;
7324 /* With bidi reordering, the character to display might not be the
7325 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7326 that we were reseat()ed to a new string, whose paragraph
7327 direction is not known. */
7328 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7330 get_visually_first_element (it
);
7331 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7334 /* Time to check for invisible text? */
7335 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7337 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7340 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7341 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7343 /* With bidi non-linear iteration, we could find
7344 ourselves far beyond the last computed stop_charpos,
7345 with several other stop positions in between that we
7346 missed. Scan them all now, in buffer's logical
7347 order, until we find and handle the last stop_charpos
7348 that precedes our current position. */
7349 handle_stop_backwards (it
, it
->stop_charpos
);
7350 return GET_NEXT_DISPLAY_ELEMENT (it
);
7356 /* Take note of the stop position we just moved
7357 across, for when we will move back across it. */
7358 it
->prev_stop
= it
->stop_charpos
;
7359 /* If we are at base paragraph embedding level, take
7360 note of the last stop position seen at this
7362 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7363 it
->base_level_stop
= it
->stop_charpos
;
7367 /* Since a handler may have changed IT->method, we must
7369 return GET_NEXT_DISPLAY_ELEMENT (it
);
7373 /* If we are before prev_stop, we may have overstepped
7374 on our way backwards a stop_pos, and if so, we need
7375 to handle that stop_pos. */
7376 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7377 /* We can sometimes back up for reasons that have nothing
7378 to do with bidi reordering. E.g., compositions. The
7379 code below is only needed when we are above the base
7380 embedding level, so test for that explicitly. */
7381 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7383 /* If we lost track of base_level_stop, we have no better
7384 place for handle_stop_backwards to start from than string
7385 beginning. This happens, e.g., when we were reseated to
7386 the previous screenful of text by vertical-motion. */
7387 if (it
->base_level_stop
<= 0
7388 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7389 it
->base_level_stop
= 0;
7390 handle_stop_backwards (it
, it
->base_level_stop
);
7391 return GET_NEXT_DISPLAY_ELEMENT (it
);
7395 if (it
->current
.overlay_string_index
>= 0)
7397 /* Get the next character from an overlay string. In overlay
7398 strings, there is no field width or padding with spaces to
7400 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7405 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7406 IT_STRING_BYTEPOS (*it
),
7407 it
->bidi_it
.scan_dir
< 0
7409 : SCHARS (it
->string
))
7410 && next_element_from_composition (it
))
7414 else if (STRING_MULTIBYTE (it
->string
))
7416 const unsigned char *s
= (SDATA (it
->string
)
7417 + IT_STRING_BYTEPOS (*it
));
7418 it
->c
= string_char_and_length (s
, &it
->len
);
7422 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7428 /* Get the next character from a Lisp string that is not an
7429 overlay string. Such strings come from the mode line, for
7430 example. We may have to pad with spaces, or truncate the
7431 string. See also next_element_from_c_string. */
7432 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7437 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7439 /* Pad with spaces. */
7440 it
->c
= ' ', it
->len
= 1;
7441 CHARPOS (position
) = BYTEPOS (position
) = -1;
7443 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7444 IT_STRING_BYTEPOS (*it
),
7445 it
->bidi_it
.scan_dir
< 0
7447 : it
->string_nchars
)
7448 && next_element_from_composition (it
))
7452 else if (STRING_MULTIBYTE (it
->string
))
7454 const unsigned char *s
= (SDATA (it
->string
)
7455 + IT_STRING_BYTEPOS (*it
));
7456 it
->c
= string_char_and_length (s
, &it
->len
);
7460 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7465 /* Record what we have and where it came from. */
7466 it
->what
= IT_CHARACTER
;
7467 it
->object
= it
->string
;
7468 it
->position
= position
;
7473 /* Load IT with next display element from C string IT->s.
7474 IT->string_nchars is the maximum number of characters to return
7475 from the string. IT->end_charpos may be greater than
7476 IT->string_nchars when this function is called, in which case we
7477 may have to return padding spaces. Value is zero if end of string
7478 reached, including padding spaces. */
7481 next_element_from_c_string (struct it
*it
)
7486 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7487 it
->what
= IT_CHARACTER
;
7488 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7491 /* With bidi reordering, the character to display might not be the
7492 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7493 we were reseated to a new string, whose paragraph direction is
7495 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7496 get_visually_first_element (it
);
7498 /* IT's position can be greater than IT->string_nchars in case a
7499 field width or precision has been specified when the iterator was
7501 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7503 /* End of the game. */
7507 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7509 /* Pad with spaces. */
7510 it
->c
= ' ', it
->len
= 1;
7511 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7513 else if (it
->multibyte_p
)
7514 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7516 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7522 /* Set up IT to return characters from an ellipsis, if appropriate.
7523 The definition of the ellipsis glyphs may come from a display table
7524 entry. This function fills IT with the first glyph from the
7525 ellipsis if an ellipsis is to be displayed. */
7528 next_element_from_ellipsis (struct it
*it
)
7530 if (it
->selective_display_ellipsis_p
)
7531 setup_for_ellipsis (it
, it
->len
);
7534 /* The face at the current position may be different from the
7535 face we find after the invisible text. Remember what it
7536 was in IT->saved_face_id, and signal that it's there by
7537 setting face_before_selective_p. */
7538 it
->saved_face_id
= it
->face_id
;
7539 it
->method
= GET_FROM_BUFFER
;
7540 it
->object
= it
->w
->buffer
;
7541 reseat_at_next_visible_line_start (it
, 1);
7542 it
->face_before_selective_p
= 1;
7545 return GET_NEXT_DISPLAY_ELEMENT (it
);
7549 /* Deliver an image display element. The iterator IT is already
7550 filled with image information (done in handle_display_prop). Value
7555 next_element_from_image (struct it
*it
)
7557 it
->what
= IT_IMAGE
;
7558 it
->ignore_overlay_strings_at_pos_p
= 0;
7563 /* Fill iterator IT with next display element from a stretch glyph
7564 property. IT->object is the value of the text property. Value is
7568 next_element_from_stretch (struct it
*it
)
7570 it
->what
= IT_STRETCH
;
7574 /* Scan backwards from IT's current position until we find a stop
7575 position, or until BEGV. This is called when we find ourself
7576 before both the last known prev_stop and base_level_stop while
7577 reordering bidirectional text. */
7580 compute_stop_pos_backwards (struct it
*it
)
7582 const int SCAN_BACK_LIMIT
= 1000;
7583 struct text_pos pos
;
7584 struct display_pos save_current
= it
->current
;
7585 struct text_pos save_position
= it
->position
;
7586 EMACS_INT charpos
= IT_CHARPOS (*it
);
7587 EMACS_INT where_we_are
= charpos
;
7588 EMACS_INT save_stop_pos
= it
->stop_charpos
;
7589 EMACS_INT save_end_pos
= it
->end_charpos
;
7591 xassert (NILP (it
->string
) && !it
->s
);
7592 xassert (it
->bidi_p
);
7596 it
->end_charpos
= min (charpos
+ 1, ZV
);
7597 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7598 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7599 reseat_1 (it
, pos
, 0);
7600 compute_stop_pos (it
);
7601 /* We must advance forward, right? */
7602 if (it
->stop_charpos
<= charpos
)
7605 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7607 if (it
->stop_charpos
<= where_we_are
)
7608 it
->prev_stop
= it
->stop_charpos
;
7610 it
->prev_stop
= BEGV
;
7612 it
->current
= save_current
;
7613 it
->position
= save_position
;
7614 it
->stop_charpos
= save_stop_pos
;
7615 it
->end_charpos
= save_end_pos
;
7618 /* Scan forward from CHARPOS in the current buffer/string, until we
7619 find a stop position > current IT's position. Then handle the stop
7620 position before that. This is called when we bump into a stop
7621 position while reordering bidirectional text. CHARPOS should be
7622 the last previously processed stop_pos (or BEGV/0, if none were
7623 processed yet) whose position is less that IT's current
7627 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7629 int bufp
= !STRINGP (it
->string
);
7630 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7631 struct display_pos save_current
= it
->current
;
7632 struct text_pos save_position
= it
->position
;
7633 struct text_pos pos1
;
7634 EMACS_INT next_stop
;
7636 /* Scan in strict logical order. */
7637 xassert (it
->bidi_p
);
7641 it
->prev_stop
= charpos
;
7644 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7645 reseat_1 (it
, pos1
, 0);
7648 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7649 compute_stop_pos (it
);
7650 /* We must advance forward, right? */
7651 if (it
->stop_charpos
<= it
->prev_stop
)
7653 charpos
= it
->stop_charpos
;
7655 while (charpos
<= where_we_are
);
7658 it
->current
= save_current
;
7659 it
->position
= save_position
;
7660 next_stop
= it
->stop_charpos
;
7661 it
->stop_charpos
= it
->prev_stop
;
7663 it
->stop_charpos
= next_stop
;
7666 /* Load IT with the next display element from current_buffer. Value
7667 is zero if end of buffer reached. IT->stop_charpos is the next
7668 position at which to stop and check for text properties or buffer
7672 next_element_from_buffer (struct it
*it
)
7676 xassert (IT_CHARPOS (*it
) >= BEGV
);
7677 xassert (NILP (it
->string
) && !it
->s
);
7678 xassert (!it
->bidi_p
7679 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7680 && it
->bidi_it
.string
.s
== NULL
));
7682 /* With bidi reordering, the character to display might not be the
7683 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7684 we were reseat()ed to a new buffer position, which is potentially
7685 a different paragraph. */
7686 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7688 get_visually_first_element (it
);
7689 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7692 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7694 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7696 int overlay_strings_follow_p
;
7698 /* End of the game, except when overlay strings follow that
7699 haven't been returned yet. */
7700 if (it
->overlay_strings_at_end_processed_p
)
7701 overlay_strings_follow_p
= 0;
7704 it
->overlay_strings_at_end_processed_p
= 1;
7705 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7708 if (overlay_strings_follow_p
)
7709 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7713 it
->position
= it
->current
.pos
;
7717 else if (!(!it
->bidi_p
7718 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7719 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7721 /* With bidi non-linear iteration, we could find ourselves
7722 far beyond the last computed stop_charpos, with several
7723 other stop positions in between that we missed. Scan
7724 them all now, in buffer's logical order, until we find
7725 and handle the last stop_charpos that precedes our
7726 current position. */
7727 handle_stop_backwards (it
, it
->stop_charpos
);
7728 return GET_NEXT_DISPLAY_ELEMENT (it
);
7734 /* Take note of the stop position we just moved across,
7735 for when we will move back across it. */
7736 it
->prev_stop
= it
->stop_charpos
;
7737 /* If we are at base paragraph embedding level, take
7738 note of the last stop position seen at this
7740 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7741 it
->base_level_stop
= it
->stop_charpos
;
7744 return GET_NEXT_DISPLAY_ELEMENT (it
);
7748 /* If we are before prev_stop, we may have overstepped on
7749 our way backwards a stop_pos, and if so, we need to
7750 handle that stop_pos. */
7751 && IT_CHARPOS (*it
) < it
->prev_stop
7752 /* We can sometimes back up for reasons that have nothing
7753 to do with bidi reordering. E.g., compositions. The
7754 code below is only needed when we are above the base
7755 embedding level, so test for that explicitly. */
7756 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7758 if (it
->base_level_stop
<= 0
7759 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7761 /* If we lost track of base_level_stop, we need to find
7762 prev_stop by looking backwards. This happens, e.g., when
7763 we were reseated to the previous screenful of text by
7765 it
->base_level_stop
= BEGV
;
7766 compute_stop_pos_backwards (it
);
7767 handle_stop_backwards (it
, it
->prev_stop
);
7770 handle_stop_backwards (it
, it
->base_level_stop
);
7771 return GET_NEXT_DISPLAY_ELEMENT (it
);
7775 /* No face changes, overlays etc. in sight, so just return a
7776 character from current_buffer. */
7780 /* Maybe run the redisplay end trigger hook. Performance note:
7781 This doesn't seem to cost measurable time. */
7782 if (it
->redisplay_end_trigger_charpos
7784 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7785 run_redisplay_end_trigger_hook (it
);
7787 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7788 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7790 && next_element_from_composition (it
))
7795 /* Get the next character, maybe multibyte. */
7796 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7797 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7798 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7800 it
->c
= *p
, it
->len
= 1;
7802 /* Record what we have and where it came from. */
7803 it
->what
= IT_CHARACTER
;
7804 it
->object
= it
->w
->buffer
;
7805 it
->position
= it
->current
.pos
;
7807 /* Normally we return the character found above, except when we
7808 really want to return an ellipsis for selective display. */
7813 /* A value of selective > 0 means hide lines indented more
7814 than that number of columns. */
7815 if (it
->selective
> 0
7816 && IT_CHARPOS (*it
) + 1 < ZV
7817 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7818 IT_BYTEPOS (*it
) + 1,
7821 success_p
= next_element_from_ellipsis (it
);
7822 it
->dpvec_char_len
= -1;
7825 else if (it
->c
== '\r' && it
->selective
== -1)
7827 /* A value of selective == -1 means that everything from the
7828 CR to the end of the line is invisible, with maybe an
7829 ellipsis displayed for it. */
7830 success_p
= next_element_from_ellipsis (it
);
7831 it
->dpvec_char_len
= -1;
7836 /* Value is zero if end of buffer reached. */
7837 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7842 /* Run the redisplay end trigger hook for IT. */
7845 run_redisplay_end_trigger_hook (struct it
*it
)
7847 Lisp_Object args
[3];
7849 /* IT->glyph_row should be non-null, i.e. we should be actually
7850 displaying something, or otherwise we should not run the hook. */
7851 xassert (it
->glyph_row
);
7853 /* Set up hook arguments. */
7854 args
[0] = Qredisplay_end_trigger_functions
;
7855 args
[1] = it
->window
;
7856 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7857 it
->redisplay_end_trigger_charpos
= 0;
7859 /* Since we are *trying* to run these functions, don't try to run
7860 them again, even if they get an error. */
7861 it
->w
->redisplay_end_trigger
= Qnil
;
7862 Frun_hook_with_args (3, args
);
7864 /* Notice if it changed the face of the character we are on. */
7865 handle_face_prop (it
);
7869 /* Deliver a composition display element. Unlike the other
7870 next_element_from_XXX, this function is not registered in the array
7871 get_next_element[]. It is called from next_element_from_buffer and
7872 next_element_from_string when necessary. */
7875 next_element_from_composition (struct it
*it
)
7877 it
->what
= IT_COMPOSITION
;
7878 it
->len
= it
->cmp_it
.nbytes
;
7879 if (STRINGP (it
->string
))
7883 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7884 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7887 it
->position
= it
->current
.string_pos
;
7888 it
->object
= it
->string
;
7889 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7890 IT_STRING_BYTEPOS (*it
), it
->string
);
7896 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7897 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7900 if (it
->bidi_it
.new_paragraph
)
7901 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7902 /* Resync the bidi iterator with IT's new position.
7903 FIXME: this doesn't support bidirectional text. */
7904 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7905 bidi_move_to_visually_next (&it
->bidi_it
);
7909 it
->position
= it
->current
.pos
;
7910 it
->object
= it
->w
->buffer
;
7911 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7912 IT_BYTEPOS (*it
), Qnil
);
7919 /***********************************************************************
7920 Moving an iterator without producing glyphs
7921 ***********************************************************************/
7923 /* Check if iterator is at a position corresponding to a valid buffer
7924 position after some move_it_ call. */
7926 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7927 ((it)->method == GET_FROM_STRING \
7928 ? IT_STRING_CHARPOS (*it) == 0 \
7932 /* Move iterator IT to a specified buffer or X position within one
7933 line on the display without producing glyphs.
7935 OP should be a bit mask including some or all of these bits:
7936 MOVE_TO_X: Stop upon reaching x-position TO_X.
7937 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7938 Regardless of OP's value, stop upon reaching the end of the display line.
7940 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7941 This means, in particular, that TO_X includes window's horizontal
7944 The return value has several possible values that
7945 say what condition caused the scan to stop:
7947 MOVE_POS_MATCH_OR_ZV
7948 - when TO_POS or ZV was reached.
7951 -when TO_X was reached before TO_POS or ZV were reached.
7954 - when we reached the end of the display area and the line must
7958 - when we reached the end of the display area and the line is
7962 - when we stopped at a line end, i.e. a newline or a CR and selective
7965 static enum move_it_result
7966 move_it_in_display_line_to (struct it
*it
,
7967 EMACS_INT to_charpos
, int to_x
,
7968 enum move_operation_enum op
)
7970 enum move_it_result result
= MOVE_UNDEFINED
;
7971 struct glyph_row
*saved_glyph_row
;
7972 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
7973 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
7974 void *ppos_data
= NULL
;
7976 enum it_method prev_method
= it
->method
;
7977 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7978 int saw_smaller_pos
= prev_pos
< to_charpos
;
7980 /* Don't produce glyphs in produce_glyphs. */
7981 saved_glyph_row
= it
->glyph_row
;
7982 it
->glyph_row
= NULL
;
7984 /* Use wrap_it to save a copy of IT wherever a word wrap could
7985 occur. Use atpos_it to save a copy of IT at the desired buffer
7986 position, if found, so that we can scan ahead and check if the
7987 word later overshoots the window edge. Use atx_it similarly, for
7993 /* Use ppos_it under bidi reordering to save a copy of IT for the
7994 position > CHARPOS that is the closest to CHARPOS. We restore
7995 that position in IT when we have scanned the entire display line
7996 without finding a match for CHARPOS and all the character
7997 positions are greater than CHARPOS. */
8000 SAVE_IT (ppos_it
, *it
, ppos_data
);
8001 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8002 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8003 SAVE_IT (ppos_it
, *it
, ppos_data
);
8006 #define BUFFER_POS_REACHED_P() \
8007 ((op & MOVE_TO_POS) != 0 \
8008 && BUFFERP (it->object) \
8009 && (IT_CHARPOS (*it) == to_charpos \
8011 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8012 && IT_CHARPOS (*it) > to_charpos) \
8013 || (it->what == IT_COMPOSITION \
8014 && ((IT_CHARPOS (*it) > to_charpos \
8015 && to_charpos >= it->cmp_it.charpos) \
8016 || (IT_CHARPOS (*it) < to_charpos \
8017 && to_charpos <= it->cmp_it.charpos)))) \
8018 && (it->method == GET_FROM_BUFFER \
8019 || (it->method == GET_FROM_DISPLAY_VECTOR \
8020 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8022 /* If there's a line-/wrap-prefix, handle it. */
8023 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8024 && it
->current_y
< it
->last_visible_y
)
8025 handle_line_prefix (it
);
8027 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8028 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8032 int x
, i
, ascent
= 0, descent
= 0;
8034 /* Utility macro to reset an iterator with x, ascent, and descent. */
8035 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8036 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8037 (IT)->max_descent = descent)
8039 /* Stop if we move beyond TO_CHARPOS (after an image or a
8040 display string or stretch glyph). */
8041 if ((op
& MOVE_TO_POS
) != 0
8042 && BUFFERP (it
->object
)
8043 && it
->method
== GET_FROM_BUFFER
8045 /* When the iterator is at base embedding level, we
8046 are guaranteed that characters are delivered for
8047 display in strictly increasing order of their
8048 buffer positions. */
8049 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8050 && IT_CHARPOS (*it
) > to_charpos
)
8052 && (prev_method
== GET_FROM_IMAGE
8053 || prev_method
== GET_FROM_STRETCH
8054 || prev_method
== GET_FROM_STRING
)
8055 /* Passed TO_CHARPOS from left to right. */
8056 && ((prev_pos
< to_charpos
8057 && IT_CHARPOS (*it
) > to_charpos
)
8058 /* Passed TO_CHARPOS from right to left. */
8059 || (prev_pos
> to_charpos
8060 && IT_CHARPOS (*it
) < to_charpos
)))))
8062 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8064 result
= MOVE_POS_MATCH_OR_ZV
;
8067 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8068 /* If wrap_it is valid, the current position might be in a
8069 word that is wrapped. So, save the iterator in
8070 atpos_it and continue to see if wrapping happens. */
8071 SAVE_IT (atpos_it
, *it
, atpos_data
);
8074 /* Stop when ZV reached.
8075 We used to stop here when TO_CHARPOS reached as well, but that is
8076 too soon if this glyph does not fit on this line. So we handle it
8077 explicitly below. */
8078 if (!get_next_display_element (it
))
8080 result
= MOVE_POS_MATCH_OR_ZV
;
8084 if (it
->line_wrap
== TRUNCATE
)
8086 if (BUFFER_POS_REACHED_P ())
8088 result
= MOVE_POS_MATCH_OR_ZV
;
8094 if (it
->line_wrap
== WORD_WRAP
)
8096 if (IT_DISPLAYING_WHITESPACE (it
))
8100 /* We have reached a glyph that follows one or more
8101 whitespace characters. If the position is
8102 already found, we are done. */
8103 if (atpos_it
.sp
>= 0)
8105 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8106 result
= MOVE_POS_MATCH_OR_ZV
;
8111 RESTORE_IT (it
, &atx_it
, atx_data
);
8112 result
= MOVE_X_REACHED
;
8115 /* Otherwise, we can wrap here. */
8116 SAVE_IT (wrap_it
, *it
, wrap_data
);
8122 /* Remember the line height for the current line, in case
8123 the next element doesn't fit on the line. */
8124 ascent
= it
->max_ascent
;
8125 descent
= it
->max_descent
;
8127 /* The call to produce_glyphs will get the metrics of the
8128 display element IT is loaded with. Record the x-position
8129 before this display element, in case it doesn't fit on the
8133 PRODUCE_GLYPHS (it
);
8135 if (it
->area
!= TEXT_AREA
)
8137 prev_method
= it
->method
;
8138 if (it
->method
== GET_FROM_BUFFER
)
8139 prev_pos
= IT_CHARPOS (*it
);
8140 set_iterator_to_next (it
, 1);
8141 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8142 SET_TEXT_POS (this_line_min_pos
,
8143 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8145 && (op
& MOVE_TO_POS
)
8146 && IT_CHARPOS (*it
) > to_charpos
8147 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8148 SAVE_IT (ppos_it
, *it
, ppos_data
);
8152 /* The number of glyphs we get back in IT->nglyphs will normally
8153 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8154 character on a terminal frame, or (iii) a line end. For the
8155 second case, IT->nglyphs - 1 padding glyphs will be present.
8156 (On X frames, there is only one glyph produced for a
8157 composite character.)
8159 The behavior implemented below means, for continuation lines,
8160 that as many spaces of a TAB as fit on the current line are
8161 displayed there. For terminal frames, as many glyphs of a
8162 multi-glyph character are displayed in the current line, too.
8163 This is what the old redisplay code did, and we keep it that
8164 way. Under X, the whole shape of a complex character must
8165 fit on the line or it will be completely displayed in the
8168 Note that both for tabs and padding glyphs, all glyphs have
8172 /* More than one glyph or glyph doesn't fit on line. All
8173 glyphs have the same width. */
8174 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8176 int x_before_this_char
= x
;
8177 int hpos_before_this_char
= it
->hpos
;
8179 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8181 new_x
= x
+ single_glyph_width
;
8183 /* We want to leave anything reaching TO_X to the caller. */
8184 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8186 if (BUFFER_POS_REACHED_P ())
8188 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8189 goto buffer_pos_reached
;
8190 if (atpos_it
.sp
< 0)
8192 SAVE_IT (atpos_it
, *it
, atpos_data
);
8193 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8198 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8201 result
= MOVE_X_REACHED
;
8206 SAVE_IT (atx_it
, *it
, atx_data
);
8207 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8212 if (/* Lines are continued. */
8213 it
->line_wrap
!= TRUNCATE
8214 && (/* And glyph doesn't fit on the line. */
8215 new_x
> it
->last_visible_x
8216 /* Or it fits exactly and we're on a window
8218 || (new_x
== it
->last_visible_x
8219 && FRAME_WINDOW_P (it
->f
))))
8221 if (/* IT->hpos == 0 means the very first glyph
8222 doesn't fit on the line, e.g. a wide image. */
8224 || (new_x
== it
->last_visible_x
8225 && FRAME_WINDOW_P (it
->f
)))
8228 it
->current_x
= new_x
;
8230 /* The character's last glyph just barely fits
8232 if (i
== it
->nglyphs
- 1)
8234 /* If this is the destination position,
8235 return a position *before* it in this row,
8236 now that we know it fits in this row. */
8237 if (BUFFER_POS_REACHED_P ())
8239 if (it
->line_wrap
!= WORD_WRAP
8242 it
->hpos
= hpos_before_this_char
;
8243 it
->current_x
= x_before_this_char
;
8244 result
= MOVE_POS_MATCH_OR_ZV
;
8247 if (it
->line_wrap
== WORD_WRAP
8250 SAVE_IT (atpos_it
, *it
, atpos_data
);
8251 atpos_it
.current_x
= x_before_this_char
;
8252 atpos_it
.hpos
= hpos_before_this_char
;
8256 prev_method
= it
->method
;
8257 if (it
->method
== GET_FROM_BUFFER
)
8258 prev_pos
= IT_CHARPOS (*it
);
8259 set_iterator_to_next (it
, 1);
8260 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8261 SET_TEXT_POS (this_line_min_pos
,
8262 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8263 /* On graphical terminals, newlines may
8264 "overflow" into the fringe if
8265 overflow-newline-into-fringe is non-nil.
8266 On text-only terminals, newlines may
8267 overflow into the last glyph on the
8269 if (!FRAME_WINDOW_P (it
->f
)
8270 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8272 if (!get_next_display_element (it
))
8274 result
= MOVE_POS_MATCH_OR_ZV
;
8277 if (BUFFER_POS_REACHED_P ())
8279 if (ITERATOR_AT_END_OF_LINE_P (it
))
8280 result
= MOVE_POS_MATCH_OR_ZV
;
8282 result
= MOVE_LINE_CONTINUED
;
8285 if (ITERATOR_AT_END_OF_LINE_P (it
))
8287 result
= MOVE_NEWLINE_OR_CR
;
8294 IT_RESET_X_ASCENT_DESCENT (it
);
8296 if (wrap_it
.sp
>= 0)
8298 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8303 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8305 result
= MOVE_LINE_CONTINUED
;
8309 if (BUFFER_POS_REACHED_P ())
8311 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8312 goto buffer_pos_reached
;
8313 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8315 SAVE_IT (atpos_it
, *it
, atpos_data
);
8316 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8320 if (new_x
> it
->first_visible_x
)
8322 /* Glyph is visible. Increment number of glyphs that
8323 would be displayed. */
8328 if (result
!= MOVE_UNDEFINED
)
8331 else if (BUFFER_POS_REACHED_P ())
8334 IT_RESET_X_ASCENT_DESCENT (it
);
8335 result
= MOVE_POS_MATCH_OR_ZV
;
8338 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8340 /* Stop when TO_X specified and reached. This check is
8341 necessary here because of lines consisting of a line end,
8342 only. The line end will not produce any glyphs and we
8343 would never get MOVE_X_REACHED. */
8344 xassert (it
->nglyphs
== 0);
8345 result
= MOVE_X_REACHED
;
8349 /* Is this a line end? If yes, we're done. */
8350 if (ITERATOR_AT_END_OF_LINE_P (it
))
8352 /* If we are past TO_CHARPOS, but never saw any character
8353 positions smaller than TO_CHARPOS, return
8354 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8356 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8358 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8360 if (IT_CHARPOS (ppos_it
) < ZV
)
8362 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8363 result
= MOVE_POS_MATCH_OR_ZV
;
8366 goto buffer_pos_reached
;
8368 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8369 && IT_CHARPOS (*it
) > to_charpos
)
8370 goto buffer_pos_reached
;
8372 result
= MOVE_NEWLINE_OR_CR
;
8375 result
= MOVE_NEWLINE_OR_CR
;
8379 prev_method
= it
->method
;
8380 if (it
->method
== GET_FROM_BUFFER
)
8381 prev_pos
= IT_CHARPOS (*it
);
8382 /* The current display element has been consumed. Advance
8384 set_iterator_to_next (it
, 1);
8385 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8386 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8387 if (IT_CHARPOS (*it
) < to_charpos
)
8388 saw_smaller_pos
= 1;
8390 && (op
& MOVE_TO_POS
)
8391 && IT_CHARPOS (*it
) >= to_charpos
8392 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8393 SAVE_IT (ppos_it
, *it
, ppos_data
);
8395 /* Stop if lines are truncated and IT's current x-position is
8396 past the right edge of the window now. */
8397 if (it
->line_wrap
== TRUNCATE
8398 && it
->current_x
>= it
->last_visible_x
)
8400 if (!FRAME_WINDOW_P (it
->f
)
8401 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8405 if ((at_eob_p
= !get_next_display_element (it
))
8406 || BUFFER_POS_REACHED_P ()
8407 /* If we are past TO_CHARPOS, but never saw any
8408 character positions smaller than TO_CHARPOS,
8409 return MOVE_POS_MATCH_OR_ZV, like the
8410 unidirectional display did. */
8411 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8413 && IT_CHARPOS (*it
) > to_charpos
))
8416 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8417 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8418 result
= MOVE_POS_MATCH_OR_ZV
;
8421 if (ITERATOR_AT_END_OF_LINE_P (it
))
8423 result
= MOVE_NEWLINE_OR_CR
;
8427 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8429 && IT_CHARPOS (*it
) > to_charpos
)
8431 if (IT_CHARPOS (ppos_it
) < ZV
)
8432 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8433 result
= MOVE_POS_MATCH_OR_ZV
;
8436 result
= MOVE_LINE_TRUNCATED
;
8439 #undef IT_RESET_X_ASCENT_DESCENT
8442 #undef BUFFER_POS_REACHED_P
8444 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8445 restore the saved iterator. */
8446 if (atpos_it
.sp
>= 0)
8447 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8448 else if (atx_it
.sp
>= 0)
8449 RESTORE_IT (it
, &atx_it
, atx_data
);
8454 bidi_unshelve_cache (atpos_data
, 1);
8456 bidi_unshelve_cache (atx_data
, 1);
8458 bidi_unshelve_cache (wrap_data
, 1);
8460 bidi_unshelve_cache (ppos_data
, 1);
8462 /* Restore the iterator settings altered at the beginning of this
8464 it
->glyph_row
= saved_glyph_row
;
8468 /* For external use. */
8470 move_it_in_display_line (struct it
*it
,
8471 EMACS_INT to_charpos
, int to_x
,
8472 enum move_operation_enum op
)
8474 if (it
->line_wrap
== WORD_WRAP
8475 && (op
& MOVE_TO_X
))
8478 void *save_data
= NULL
;
8481 SAVE_IT (save_it
, *it
, save_data
);
8482 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8483 /* When word-wrap is on, TO_X may lie past the end
8484 of a wrapped line. Then it->current is the
8485 character on the next line, so backtrack to the
8486 space before the wrap point. */
8487 if (skip
== MOVE_LINE_CONTINUED
)
8489 int prev_x
= max (it
->current_x
- 1, 0);
8490 RESTORE_IT (it
, &save_it
, save_data
);
8491 move_it_in_display_line_to
8492 (it
, -1, prev_x
, MOVE_TO_X
);
8495 bidi_unshelve_cache (save_data
, 1);
8498 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8502 /* Move IT forward until it satisfies one or more of the criteria in
8503 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8505 OP is a bit-mask that specifies where to stop, and in particular,
8506 which of those four position arguments makes a difference. See the
8507 description of enum move_operation_enum.
8509 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8510 screen line, this function will set IT to the next position that is
8511 displayed to the right of TO_CHARPOS on the screen. */
8514 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8516 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8517 int line_height
, line_start_x
= 0, reached
= 0;
8518 void *backup_data
= NULL
;
8522 if (op
& MOVE_TO_VPOS
)
8524 /* If no TO_CHARPOS and no TO_X specified, stop at the
8525 start of the line TO_VPOS. */
8526 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8528 if (it
->vpos
== to_vpos
)
8534 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8538 /* TO_VPOS >= 0 means stop at TO_X in the line at
8539 TO_VPOS, or at TO_POS, whichever comes first. */
8540 if (it
->vpos
== to_vpos
)
8546 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8548 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8553 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8555 /* We have reached TO_X but not in the line we want. */
8556 skip
= move_it_in_display_line_to (it
, to_charpos
,
8558 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8566 else if (op
& MOVE_TO_Y
)
8568 struct it it_backup
;
8570 if (it
->line_wrap
== WORD_WRAP
)
8571 SAVE_IT (it_backup
, *it
, backup_data
);
8573 /* TO_Y specified means stop at TO_X in the line containing
8574 TO_Y---or at TO_CHARPOS if this is reached first. The
8575 problem is that we can't really tell whether the line
8576 contains TO_Y before we have completely scanned it, and
8577 this may skip past TO_X. What we do is to first scan to
8580 If TO_X is not specified, use a TO_X of zero. The reason
8581 is to make the outcome of this function more predictable.
8582 If we didn't use TO_X == 0, we would stop at the end of
8583 the line which is probably not what a caller would expect
8585 skip
= move_it_in_display_line_to
8586 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8587 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8589 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8590 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8592 else if (skip
== MOVE_X_REACHED
)
8594 /* If TO_X was reached, we want to know whether TO_Y is
8595 in the line. We know this is the case if the already
8596 scanned glyphs make the line tall enough. Otherwise,
8597 we must check by scanning the rest of the line. */
8598 line_height
= it
->max_ascent
+ it
->max_descent
;
8599 if (to_y
>= it
->current_y
8600 && to_y
< it
->current_y
+ line_height
)
8605 SAVE_IT (it_backup
, *it
, backup_data
);
8606 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8607 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8609 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8610 line_height
= it
->max_ascent
+ it
->max_descent
;
8611 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8613 if (to_y
>= it
->current_y
8614 && to_y
< it
->current_y
+ line_height
)
8616 /* If TO_Y is in this line and TO_X was reached
8617 above, we scanned too far. We have to restore
8618 IT's settings to the ones before skipping. */
8619 RESTORE_IT (it
, &it_backup
, backup_data
);
8625 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8631 /* Check whether TO_Y is in this line. */
8632 line_height
= it
->max_ascent
+ it
->max_descent
;
8633 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8635 if (to_y
>= it
->current_y
8636 && to_y
< it
->current_y
+ line_height
)
8638 /* When word-wrap is on, TO_X may lie past the end
8639 of a wrapped line. Then it->current is the
8640 character on the next line, so backtrack to the
8641 space before the wrap point. */
8642 if (skip
== MOVE_LINE_CONTINUED
8643 && it
->line_wrap
== WORD_WRAP
)
8645 int prev_x
= max (it
->current_x
- 1, 0);
8646 RESTORE_IT (it
, &it_backup
, backup_data
);
8647 skip
= move_it_in_display_line_to
8648 (it
, -1, prev_x
, MOVE_TO_X
);
8657 else if (BUFFERP (it
->object
)
8658 && (it
->method
== GET_FROM_BUFFER
8659 || it
->method
== GET_FROM_STRETCH
)
8660 && IT_CHARPOS (*it
) >= to_charpos
8661 /* Under bidi iteration, a call to set_iterator_to_next
8662 can scan far beyond to_charpos if the initial
8663 portion of the next line needs to be reordered. In
8664 that case, give move_it_in_display_line_to another
8667 && it
->bidi_it
.scan_dir
== -1))
8668 skip
= MOVE_POS_MATCH_OR_ZV
;
8670 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8674 case MOVE_POS_MATCH_OR_ZV
:
8678 case MOVE_NEWLINE_OR_CR
:
8679 set_iterator_to_next (it
, 1);
8680 it
->continuation_lines_width
= 0;
8683 case MOVE_LINE_TRUNCATED
:
8684 it
->continuation_lines_width
= 0;
8685 reseat_at_next_visible_line_start (it
, 0);
8686 if ((op
& MOVE_TO_POS
) != 0
8687 && IT_CHARPOS (*it
) > to_charpos
)
8694 case MOVE_LINE_CONTINUED
:
8695 /* For continued lines ending in a tab, some of the glyphs
8696 associated with the tab are displayed on the current
8697 line. Since it->current_x does not include these glyphs,
8698 we use it->last_visible_x instead. */
8701 it
->continuation_lines_width
+= it
->last_visible_x
;
8702 /* When moving by vpos, ensure that the iterator really
8703 advances to the next line (bug#847, bug#969). Fixme:
8704 do we need to do this in other circumstances? */
8705 if (it
->current_x
!= it
->last_visible_x
8706 && (op
& MOVE_TO_VPOS
)
8707 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8709 line_start_x
= it
->current_x
+ it
->pixel_width
8710 - it
->last_visible_x
;
8711 set_iterator_to_next (it
, 0);
8715 it
->continuation_lines_width
+= it
->current_x
;
8722 /* Reset/increment for the next run. */
8723 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8724 it
->current_x
= line_start_x
;
8727 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8729 last_height
= it
->max_ascent
+ it
->max_descent
;
8730 last_max_ascent
= it
->max_ascent
;
8731 it
->max_ascent
= it
->max_descent
= 0;
8736 /* On text terminals, we may stop at the end of a line in the middle
8737 of a multi-character glyph. If the glyph itself is continued,
8738 i.e. it is actually displayed on the next line, don't treat this
8739 stopping point as valid; move to the next line instead (unless
8740 that brings us offscreen). */
8741 if (!FRAME_WINDOW_P (it
->f
)
8743 && IT_CHARPOS (*it
) == to_charpos
8744 && it
->what
== IT_CHARACTER
8746 && it
->line_wrap
== WINDOW_WRAP
8747 && it
->current_x
== it
->last_visible_x
- 1
8750 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8752 it
->continuation_lines_width
+= it
->current_x
;
8753 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8754 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8756 last_height
= it
->max_ascent
+ it
->max_descent
;
8757 last_max_ascent
= it
->max_ascent
;
8761 bidi_unshelve_cache (backup_data
, 1);
8763 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8767 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8769 If DY > 0, move IT backward at least that many pixels. DY = 0
8770 means move IT backward to the preceding line start or BEGV. This
8771 function may move over more than DY pixels if IT->current_y - DY
8772 ends up in the middle of a line; in this case IT->current_y will be
8773 set to the top of the line moved to. */
8776 move_it_vertically_backward (struct it
*it
, int dy
)
8780 void *it2data
= NULL
, *it3data
= NULL
;
8781 EMACS_INT start_pos
;
8786 start_pos
= IT_CHARPOS (*it
);
8788 /* Estimate how many newlines we must move back. */
8789 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8791 /* Set the iterator's position that many lines back. */
8792 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8793 back_to_previous_visible_line_start (it
);
8795 /* Reseat the iterator here. When moving backward, we don't want
8796 reseat to skip forward over invisible text, set up the iterator
8797 to deliver from overlay strings at the new position etc. So,
8798 use reseat_1 here. */
8799 reseat_1 (it
, it
->current
.pos
, 1);
8801 /* We are now surely at a line start. */
8802 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8803 reordering is in effect. */
8804 it
->continuation_lines_width
= 0;
8806 /* Move forward and see what y-distance we moved. First move to the
8807 start of the next line so that we get its height. We need this
8808 height to be able to tell whether we reached the specified
8810 SAVE_IT (it2
, *it
, it2data
);
8811 it2
.max_ascent
= it2
.max_descent
= 0;
8814 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8815 MOVE_TO_POS
| MOVE_TO_VPOS
);
8817 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8818 /* If we are in a display string which starts at START_POS,
8819 and that display string includes a newline, and we are
8820 right after that newline (i.e. at the beginning of a
8821 display line), exit the loop, because otherwise we will
8822 infloop, since move_it_to will see that it is already at
8823 START_POS and will not move. */
8824 || (it2
.method
== GET_FROM_STRING
8825 && IT_CHARPOS (it2
) == start_pos
8826 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
8827 xassert (IT_CHARPOS (*it
) >= BEGV
);
8828 SAVE_IT (it3
, it2
, it3data
);
8830 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8831 xassert (IT_CHARPOS (*it
) >= BEGV
);
8832 /* H is the actual vertical distance from the position in *IT
8833 and the starting position. */
8834 h
= it2
.current_y
- it
->current_y
;
8835 /* NLINES is the distance in number of lines. */
8836 nlines
= it2
.vpos
- it
->vpos
;
8838 /* Correct IT's y and vpos position
8839 so that they are relative to the starting point. */
8845 /* DY == 0 means move to the start of the screen line. The
8846 value of nlines is > 0 if continuation lines were involved,
8847 or if the original IT position was at start of a line. */
8848 RESTORE_IT (it
, it
, it2data
);
8850 move_it_by_lines (it
, nlines
);
8851 /* The above code moves us to some position NLINES down,
8852 usually to its first glyph (leftmost in an L2R line), but
8853 that's not necessarily the start of the line, under bidi
8854 reordering. We want to get to the character position
8855 that is immediately after the newline of the previous
8858 && !it
->continuation_lines_width
8859 && !STRINGP (it
->string
)
8860 && IT_CHARPOS (*it
) > BEGV
8861 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8864 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
8866 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
8868 bidi_unshelve_cache (it3data
, 1);
8872 /* The y-position we try to reach, relative to *IT.
8873 Note that H has been subtracted in front of the if-statement. */
8874 int target_y
= it
->current_y
+ h
- dy
;
8875 int y0
= it3
.current_y
;
8879 RESTORE_IT (&it3
, &it3
, it3data
);
8880 y1
= line_bottom_y (&it3
);
8881 line_height
= y1
- y0
;
8882 RESTORE_IT (it
, it
, it2data
);
8883 /* If we did not reach target_y, try to move further backward if
8884 we can. If we moved too far backward, try to move forward. */
8885 if (target_y
< it
->current_y
8886 /* This is heuristic. In a window that's 3 lines high, with
8887 a line height of 13 pixels each, recentering with point
8888 on the bottom line will try to move -39/2 = 19 pixels
8889 backward. Try to avoid moving into the first line. */
8890 && (it
->current_y
- target_y
8891 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8892 && IT_CHARPOS (*it
) > BEGV
)
8894 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8895 target_y
- it
->current_y
));
8896 dy
= it
->current_y
- target_y
;
8897 goto move_further_back
;
8899 else if (target_y
>= it
->current_y
+ line_height
8900 && IT_CHARPOS (*it
) < ZV
)
8902 /* Should move forward by at least one line, maybe more.
8904 Note: Calling move_it_by_lines can be expensive on
8905 terminal frames, where compute_motion is used (via
8906 vmotion) to do the job, when there are very long lines
8907 and truncate-lines is nil. That's the reason for
8908 treating terminal frames specially here. */
8910 if (!FRAME_WINDOW_P (it
->f
))
8911 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8916 move_it_by_lines (it
, 1);
8918 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8925 /* Move IT by a specified amount of pixel lines DY. DY negative means
8926 move backwards. DY = 0 means move to start of screen line. At the
8927 end, IT will be on the start of a screen line. */
8930 move_it_vertically (struct it
*it
, int dy
)
8933 move_it_vertically_backward (it
, -dy
);
8936 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8937 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8938 MOVE_TO_POS
| MOVE_TO_Y
);
8939 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8941 /* If buffer ends in ZV without a newline, move to the start of
8942 the line to satisfy the post-condition. */
8943 if (IT_CHARPOS (*it
) == ZV
8945 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8946 move_it_by_lines (it
, 0);
8951 /* Move iterator IT past the end of the text line it is in. */
8954 move_it_past_eol (struct it
*it
)
8956 enum move_it_result rc
;
8958 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8959 if (rc
== MOVE_NEWLINE_OR_CR
)
8960 set_iterator_to_next (it
, 0);
8964 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8965 negative means move up. DVPOS == 0 means move to the start of the
8968 Optimization idea: If we would know that IT->f doesn't use
8969 a face with proportional font, we could be faster for
8970 truncate-lines nil. */
8973 move_it_by_lines (struct it
*it
, int dvpos
)
8976 /* The commented-out optimization uses vmotion on terminals. This
8977 gives bad results, because elements like it->what, on which
8978 callers such as pos_visible_p rely, aren't updated. */
8979 /* struct position pos;
8980 if (!FRAME_WINDOW_P (it->f))
8982 struct text_pos textpos;
8984 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8985 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8986 reseat (it, textpos, 1);
8987 it->vpos += pos.vpos;
8988 it->current_y += pos.vpos;
8994 /* DVPOS == 0 means move to the start of the screen line. */
8995 move_it_vertically_backward (it
, 0);
8996 /* Let next call to line_bottom_y calculate real line height */
9001 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9002 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9004 /* Only move to the next buffer position if we ended up in a
9005 string from display property, not in an overlay string
9006 (before-string or after-string). That is because the
9007 latter don't conceal the underlying buffer position, so
9008 we can ask to move the iterator to the exact position we
9009 are interested in. Note that, even if we are already at
9010 IT_CHARPOS (*it), the call below is not a no-op, as it
9011 will detect that we are at the end of the string, pop the
9012 iterator, and compute it->current_x and it->hpos
9014 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9015 -1, -1, -1, MOVE_TO_POS
);
9021 void *it2data
= NULL
;
9022 EMACS_INT start_charpos
, i
;
9024 /* Start at the beginning of the screen line containing IT's
9025 position. This may actually move vertically backwards,
9026 in case of overlays, so adjust dvpos accordingly. */
9028 move_it_vertically_backward (it
, 0);
9031 /* Go back -DVPOS visible lines and reseat the iterator there. */
9032 start_charpos
= IT_CHARPOS (*it
);
9033 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9034 back_to_previous_visible_line_start (it
);
9035 reseat (it
, it
->current
.pos
, 1);
9037 /* Move further back if we end up in a string or an image. */
9038 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9040 /* First try to move to start of display line. */
9042 move_it_vertically_backward (it
, 0);
9044 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9046 /* If start of line is still in string or image,
9047 move further back. */
9048 back_to_previous_visible_line_start (it
);
9049 reseat (it
, it
->current
.pos
, 1);
9053 it
->current_x
= it
->hpos
= 0;
9055 /* Above call may have moved too far if continuation lines
9056 are involved. Scan forward and see if it did. */
9057 SAVE_IT (it2
, *it
, it2data
);
9058 it2
.vpos
= it2
.current_y
= 0;
9059 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9060 it
->vpos
-= it2
.vpos
;
9061 it
->current_y
-= it2
.current_y
;
9062 it
->current_x
= it
->hpos
= 0;
9064 /* If we moved too far back, move IT some lines forward. */
9065 if (it2
.vpos
> -dvpos
)
9067 int delta
= it2
.vpos
+ dvpos
;
9069 RESTORE_IT (&it2
, &it2
, it2data
);
9070 SAVE_IT (it2
, *it
, it2data
);
9071 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9072 /* Move back again if we got too far ahead. */
9073 if (IT_CHARPOS (*it
) >= start_charpos
)
9074 RESTORE_IT (it
, &it2
, it2data
);
9076 bidi_unshelve_cache (it2data
, 1);
9079 RESTORE_IT (it
, it
, it2data
);
9083 /* Return 1 if IT points into the middle of a display vector. */
9086 in_display_vector_p (struct it
*it
)
9088 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9089 && it
->current
.dpvec_index
> 0
9090 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9094 /***********************************************************************
9096 ***********************************************************************/
9099 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9103 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9105 Lisp_Object args
[3];
9106 Lisp_Object msg
, fmt
;
9109 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9112 /* Do nothing if called asynchronously. Inserting text into
9113 a buffer may call after-change-functions and alike and
9114 that would means running Lisp asynchronously. */
9115 if (handling_signal
)
9119 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9121 args
[0] = fmt
= build_string (format
);
9124 msg
= Fformat (3, args
);
9126 len
= SBYTES (msg
) + 1;
9127 SAFE_ALLOCA (buffer
, char *, len
);
9128 memcpy (buffer
, SDATA (msg
), len
);
9130 message_dolog (buffer
, len
- 1, 1, 0);
9137 /* Output a newline in the *Messages* buffer if "needs" one. */
9140 message_log_maybe_newline (void)
9142 if (message_log_need_newline
)
9143 message_dolog ("", 0, 1, 0);
9147 /* Add a string M of length NBYTES to the message log, optionally
9148 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9149 nonzero, means interpret the contents of M as multibyte. This
9150 function calls low-level routines in order to bypass text property
9151 hooks, etc. which might not be safe to run.
9153 This may GC (insert may run before/after change hooks),
9154 so the buffer M must NOT point to a Lisp string. */
9157 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
9159 const unsigned char *msg
= (const unsigned char *) m
;
9161 if (!NILP (Vmemory_full
))
9164 if (!NILP (Vmessage_log_max
))
9166 struct buffer
*oldbuf
;
9167 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9168 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9169 EMACS_INT point_at_end
= 0;
9170 EMACS_INT zv_at_end
= 0;
9171 Lisp_Object old_deactivate_mark
, tem
;
9172 struct gcpro gcpro1
;
9174 old_deactivate_mark
= Vdeactivate_mark
;
9175 oldbuf
= current_buffer
;
9176 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9177 BVAR (current_buffer
, undo_list
) = Qt
;
9179 oldpoint
= message_dolog_marker1
;
9180 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9181 oldbegv
= message_dolog_marker2
;
9182 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9183 oldzv
= message_dolog_marker3
;
9184 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9185 GCPRO1 (old_deactivate_mark
);
9193 BEGV_BYTE
= BEG_BYTE
;
9196 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9198 /* Insert the string--maybe converting multibyte to single byte
9199 or vice versa, so that all the text fits the buffer. */
9201 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9207 /* Convert a multibyte string to single-byte
9208 for the *Message* buffer. */
9209 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9211 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9212 work
[0] = (ASCII_CHAR_P (c
)
9214 : multibyte_char_to_unibyte (c
));
9215 insert_1_both (work
, 1, 1, 1, 0, 0);
9218 else if (! multibyte
9219 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9223 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9224 /* Convert a single-byte string to multibyte
9225 for the *Message* buffer. */
9226 for (i
= 0; i
< nbytes
; i
++)
9229 MAKE_CHAR_MULTIBYTE (c
);
9230 char_bytes
= CHAR_STRING (c
, str
);
9231 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9235 insert_1 (m
, nbytes
, 1, 0, 0);
9239 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9241 insert_1 ("\n", 1, 1, 0, 0);
9243 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9245 this_bol_byte
= PT_BYTE
;
9247 /* See if this line duplicates the previous one.
9248 If so, combine duplicates. */
9251 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9253 prev_bol_byte
= PT_BYTE
;
9255 dups
= message_log_check_duplicate (prev_bol_byte
,
9259 del_range_both (prev_bol
, prev_bol_byte
,
9260 this_bol
, this_bol_byte
, 0);
9263 char dupstr
[sizeof " [ times]"
9264 + INT_STRLEN_BOUND (printmax_t
)];
9267 /* If you change this format, don't forget to also
9268 change message_log_check_duplicate. */
9269 sprintf (dupstr
, " [%"pMd
" times]", dups
);
9270 duplen
= strlen (dupstr
);
9271 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9272 insert_1 (dupstr
, duplen
, 1, 0, 1);
9277 /* If we have more than the desired maximum number of lines
9278 in the *Messages* buffer now, delete the oldest ones.
9279 This is safe because we don't have undo in this buffer. */
9281 if (NATNUMP (Vmessage_log_max
))
9283 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9284 -XFASTINT (Vmessage_log_max
) - 1, 0);
9285 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9288 BEGV
= XMARKER (oldbegv
)->charpos
;
9289 BEGV_BYTE
= marker_byte_position (oldbegv
);
9298 ZV
= XMARKER (oldzv
)->charpos
;
9299 ZV_BYTE
= marker_byte_position (oldzv
);
9303 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9305 /* We can't do Fgoto_char (oldpoint) because it will run some
9307 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9308 XMARKER (oldpoint
)->bytepos
);
9311 unchain_marker (XMARKER (oldpoint
));
9312 unchain_marker (XMARKER (oldbegv
));
9313 unchain_marker (XMARKER (oldzv
));
9315 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9316 set_buffer_internal (oldbuf
);
9318 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9319 message_log_need_newline
= !nlflag
;
9320 Vdeactivate_mark
= old_deactivate_mark
;
9325 /* We are at the end of the buffer after just having inserted a newline.
9326 (Note: We depend on the fact we won't be crossing the gap.)
9327 Check to see if the most recent message looks a lot like the previous one.
9328 Return 0 if different, 1 if the new one should just replace it, or a
9329 value N > 1 if we should also append " [N times]". */
9332 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
9335 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
9337 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9338 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9340 for (i
= 0; i
< len
; i
++)
9342 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9350 if (*p1
++ == ' ' && *p1
++ == '[')
9353 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9354 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9361 /* Display an echo area message M with a specified length of NBYTES
9362 bytes. The string may include null characters. If M is 0, clear
9363 out any existing message, and let the mini-buffer text show
9366 This may GC, so the buffer M must NOT point to a Lisp string. */
9369 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
9371 /* First flush out any partial line written with print. */
9372 message_log_maybe_newline ();
9374 message_dolog (m
, nbytes
, 1, multibyte
);
9375 message2_nolog (m
, nbytes
, multibyte
);
9379 /* The non-logging counterpart of message2. */
9382 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
9384 struct frame
*sf
= SELECTED_FRAME ();
9385 message_enable_multibyte
= multibyte
;
9387 if (FRAME_INITIAL_P (sf
))
9389 if (noninteractive_need_newline
)
9390 putc ('\n', stderr
);
9391 noninteractive_need_newline
= 0;
9393 fwrite (m
, nbytes
, 1, stderr
);
9394 if (cursor_in_echo_area
== 0)
9395 fprintf (stderr
, "\n");
9398 /* A null message buffer means that the frame hasn't really been
9399 initialized yet. Error messages get reported properly by
9400 cmd_error, so this must be just an informative message; toss it. */
9401 else if (INTERACTIVE
9402 && sf
->glyphs_initialized_p
9403 && FRAME_MESSAGE_BUF (sf
))
9405 Lisp_Object mini_window
;
9408 /* Get the frame containing the mini-buffer
9409 that the selected frame is using. */
9410 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9411 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9413 FRAME_SAMPLE_VISIBILITY (f
);
9414 if (FRAME_VISIBLE_P (sf
)
9415 && ! FRAME_VISIBLE_P (f
))
9416 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9420 set_message (m
, Qnil
, nbytes
, multibyte
);
9421 if (minibuffer_auto_raise
)
9422 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9425 clear_message (1, 1);
9427 do_pending_window_change (0);
9428 echo_area_display (1);
9429 do_pending_window_change (0);
9430 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9431 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9436 /* Display an echo area message M with a specified length of NBYTES
9437 bytes. The string may include null characters. If M is not a
9438 string, clear out any existing message, and let the mini-buffer
9441 This function cancels echoing. */
9444 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
9446 struct gcpro gcpro1
;
9449 clear_message (1,1);
9452 /* First flush out any partial line written with print. */
9453 message_log_maybe_newline ();
9459 SAFE_ALLOCA (buffer
, char *, nbytes
);
9460 memcpy (buffer
, SDATA (m
), nbytes
);
9461 message_dolog (buffer
, nbytes
, 1, multibyte
);
9464 message3_nolog (m
, nbytes
, multibyte
);
9470 /* The non-logging version of message3.
9471 This does not cancel echoing, because it is used for echoing.
9472 Perhaps we need to make a separate function for echoing
9473 and make this cancel echoing. */
9476 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
9478 struct frame
*sf
= SELECTED_FRAME ();
9479 message_enable_multibyte
= multibyte
;
9481 if (FRAME_INITIAL_P (sf
))
9483 if (noninteractive_need_newline
)
9484 putc ('\n', stderr
);
9485 noninteractive_need_newline
= 0;
9487 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9488 if (cursor_in_echo_area
== 0)
9489 fprintf (stderr
, "\n");
9492 /* A null message buffer means that the frame hasn't really been
9493 initialized yet. Error messages get reported properly by
9494 cmd_error, so this must be just an informative message; toss it. */
9495 else if (INTERACTIVE
9496 && sf
->glyphs_initialized_p
9497 && FRAME_MESSAGE_BUF (sf
))
9499 Lisp_Object mini_window
;
9503 /* Get the frame containing the mini-buffer
9504 that the selected frame is using. */
9505 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9506 frame
= XWINDOW (mini_window
)->frame
;
9509 FRAME_SAMPLE_VISIBILITY (f
);
9510 if (FRAME_VISIBLE_P (sf
)
9511 && !FRAME_VISIBLE_P (f
))
9512 Fmake_frame_visible (frame
);
9514 if (STRINGP (m
) && SCHARS (m
) > 0)
9516 set_message (NULL
, m
, nbytes
, multibyte
);
9517 if (minibuffer_auto_raise
)
9518 Fraise_frame (frame
);
9519 /* Assume we are not echoing.
9520 (If we are, echo_now will override this.) */
9521 echo_message_buffer
= Qnil
;
9524 clear_message (1, 1);
9526 do_pending_window_change (0);
9527 echo_area_display (1);
9528 do_pending_window_change (0);
9529 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9530 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9535 /* Display a null-terminated echo area message M. If M is 0, clear
9536 out any existing message, and let the mini-buffer text show through.
9538 The buffer M must continue to exist until after the echo area gets
9539 cleared or some other message gets displayed there. Do not pass
9540 text that is stored in a Lisp string. Do not pass text in a buffer
9541 that was alloca'd. */
9544 message1 (const char *m
)
9546 message2 (m
, (m
? strlen (m
) : 0), 0);
9550 /* The non-logging counterpart of message1. */
9553 message1_nolog (const char *m
)
9555 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9558 /* Display a message M which contains a single %s
9559 which gets replaced with STRING. */
9562 message_with_string (const char *m
, Lisp_Object string
, int log
)
9564 CHECK_STRING (string
);
9570 if (noninteractive_need_newline
)
9571 putc ('\n', stderr
);
9572 noninteractive_need_newline
= 0;
9573 fprintf (stderr
, m
, SDATA (string
));
9574 if (!cursor_in_echo_area
)
9575 fprintf (stderr
, "\n");
9579 else if (INTERACTIVE
)
9581 /* The frame whose minibuffer we're going to display the message on.
9582 It may be larger than the selected frame, so we need
9583 to use its buffer, not the selected frame's buffer. */
9584 Lisp_Object mini_window
;
9585 struct frame
*f
, *sf
= SELECTED_FRAME ();
9587 /* Get the frame containing the minibuffer
9588 that the selected frame is using. */
9589 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9590 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9592 /* A null message buffer means that the frame hasn't really been
9593 initialized yet. Error messages get reported properly by
9594 cmd_error, so this must be just an informative message; toss it. */
9595 if (FRAME_MESSAGE_BUF (f
))
9597 Lisp_Object args
[2], msg
;
9598 struct gcpro gcpro1
, gcpro2
;
9600 args
[0] = build_string (m
);
9601 args
[1] = msg
= string
;
9602 GCPRO2 (args
[0], msg
);
9605 msg
= Fformat (2, args
);
9608 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9610 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9614 /* Print should start at the beginning of the message
9615 buffer next time. */
9616 message_buf_print
= 0;
9622 /* Dump an informative message to the minibuf. If M is 0, clear out
9623 any existing message, and let the mini-buffer text show through. */
9626 vmessage (const char *m
, va_list ap
)
9632 if (noninteractive_need_newline
)
9633 putc ('\n', stderr
);
9634 noninteractive_need_newline
= 0;
9635 vfprintf (stderr
, m
, ap
);
9636 if (cursor_in_echo_area
== 0)
9637 fprintf (stderr
, "\n");
9641 else if (INTERACTIVE
)
9643 /* The frame whose mini-buffer we're going to display the message
9644 on. It may be larger than the selected frame, so we need to
9645 use its buffer, not the selected frame's buffer. */
9646 Lisp_Object mini_window
;
9647 struct frame
*f
, *sf
= SELECTED_FRAME ();
9649 /* Get the frame containing the mini-buffer
9650 that the selected frame is using. */
9651 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9652 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9654 /* A null message buffer means that the frame hasn't really been
9655 initialized yet. Error messages get reported properly by
9656 cmd_error, so this must be just an informative message; toss
9658 if (FRAME_MESSAGE_BUF (f
))
9664 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9665 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9667 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9672 /* Print should start at the beginning of the message
9673 buffer next time. */
9674 message_buf_print
= 0;
9680 message (const char *m
, ...)
9690 /* The non-logging version of message. */
9693 message_nolog (const char *m
, ...)
9695 Lisp_Object old_log_max
;
9698 old_log_max
= Vmessage_log_max
;
9699 Vmessage_log_max
= Qnil
;
9701 Vmessage_log_max
= old_log_max
;
9707 /* Display the current message in the current mini-buffer. This is
9708 only called from error handlers in process.c, and is not time
9712 update_echo_area (void)
9714 if (!NILP (echo_area_buffer
[0]))
9717 string
= Fcurrent_message ();
9718 message3 (string
, SBYTES (string
),
9719 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9724 /* Make sure echo area buffers in `echo_buffers' are live.
9725 If they aren't, make new ones. */
9728 ensure_echo_area_buffers (void)
9732 for (i
= 0; i
< 2; ++i
)
9733 if (!BUFFERP (echo_buffer
[i
])
9734 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9737 Lisp_Object old_buffer
;
9740 old_buffer
= echo_buffer
[i
];
9741 sprintf (name
, " *Echo Area %d*", i
);
9742 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9743 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9744 /* to force word wrap in echo area -
9745 it was decided to postpone this*/
9746 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9748 for (j
= 0; j
< 2; ++j
)
9749 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9750 echo_area_buffer
[j
] = echo_buffer
[i
];
9755 /* Call FN with args A1..A4 with either the current or last displayed
9756 echo_area_buffer as current buffer.
9758 WHICH zero means use the current message buffer
9759 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9760 from echo_buffer[] and clear it.
9762 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9763 suitable buffer from echo_buffer[] and clear it.
9765 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9766 that the current message becomes the last displayed one, make
9767 choose a suitable buffer for echo_area_buffer[0], and clear it.
9769 Value is what FN returns. */
9772 with_echo_area_buffer (struct window
*w
, int which
,
9773 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9774 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9777 int this_one
, the_other
, clear_buffer_p
, rc
;
9778 int count
= SPECPDL_INDEX ();
9780 /* If buffers aren't live, make new ones. */
9781 ensure_echo_area_buffers ();
9786 this_one
= 0, the_other
= 1;
9788 this_one
= 1, the_other
= 0;
9791 this_one
= 0, the_other
= 1;
9794 /* We need a fresh one in case the current echo buffer equals
9795 the one containing the last displayed echo area message. */
9796 if (!NILP (echo_area_buffer
[this_one
])
9797 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9798 echo_area_buffer
[this_one
] = Qnil
;
9801 /* Choose a suitable buffer from echo_buffer[] is we don't
9803 if (NILP (echo_area_buffer
[this_one
]))
9805 echo_area_buffer
[this_one
]
9806 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9807 ? echo_buffer
[the_other
]
9808 : echo_buffer
[this_one
]);
9812 buffer
= echo_area_buffer
[this_one
];
9814 /* Don't get confused by reusing the buffer used for echoing
9815 for a different purpose. */
9816 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9819 record_unwind_protect (unwind_with_echo_area_buffer
,
9820 with_echo_area_buffer_unwind_data (w
));
9822 /* Make the echo area buffer current. Note that for display
9823 purposes, it is not necessary that the displayed window's buffer
9824 == current_buffer, except for text property lookup. So, let's
9825 only set that buffer temporarily here without doing a full
9826 Fset_window_buffer. We must also change w->pointm, though,
9827 because otherwise an assertions in unshow_buffer fails, and Emacs
9829 set_buffer_internal_1 (XBUFFER (buffer
));
9833 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9836 BVAR (current_buffer
, undo_list
) = Qt
;
9837 BVAR (current_buffer
, read_only
) = Qnil
;
9838 specbind (Qinhibit_read_only
, Qt
);
9839 specbind (Qinhibit_modification_hooks
, Qt
);
9841 if (clear_buffer_p
&& Z
> BEG
)
9844 xassert (BEGV
>= BEG
);
9845 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9847 rc
= fn (a1
, a2
, a3
, a4
);
9849 xassert (BEGV
>= BEG
);
9850 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9852 unbind_to (count
, Qnil
);
9857 /* Save state that should be preserved around the call to the function
9858 FN called in with_echo_area_buffer. */
9861 with_echo_area_buffer_unwind_data (struct window
*w
)
9864 Lisp_Object vector
, tmp
;
9866 /* Reduce consing by keeping one vector in
9867 Vwith_echo_area_save_vector. */
9868 vector
= Vwith_echo_area_save_vector
;
9869 Vwith_echo_area_save_vector
= Qnil
;
9872 vector
= Fmake_vector (make_number (7), Qnil
);
9874 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9875 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9876 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9880 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9881 ASET (vector
, i
, w
->buffer
); ++i
;
9882 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9883 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9888 for (; i
< end
; ++i
)
9889 ASET (vector
, i
, Qnil
);
9892 xassert (i
== ASIZE (vector
));
9897 /* Restore global state from VECTOR which was created by
9898 with_echo_area_buffer_unwind_data. */
9901 unwind_with_echo_area_buffer (Lisp_Object vector
)
9903 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9904 Vdeactivate_mark
= AREF (vector
, 1);
9905 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9907 if (WINDOWP (AREF (vector
, 3)))
9910 Lisp_Object buffer
, charpos
, bytepos
;
9912 w
= XWINDOW (AREF (vector
, 3));
9913 buffer
= AREF (vector
, 4);
9914 charpos
= AREF (vector
, 5);
9915 bytepos
= AREF (vector
, 6);
9918 set_marker_both (w
->pointm
, buffer
,
9919 XFASTINT (charpos
), XFASTINT (bytepos
));
9922 Vwith_echo_area_save_vector
= vector
;
9927 /* Set up the echo area for use by print functions. MULTIBYTE_P
9928 non-zero means we will print multibyte. */
9931 setup_echo_area_for_printing (int multibyte_p
)
9933 /* If we can't find an echo area any more, exit. */
9934 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9937 ensure_echo_area_buffers ();
9939 if (!message_buf_print
)
9941 /* A message has been output since the last time we printed.
9942 Choose a fresh echo area buffer. */
9943 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9944 echo_area_buffer
[0] = echo_buffer
[1];
9946 echo_area_buffer
[0] = echo_buffer
[0];
9948 /* Switch to that buffer and clear it. */
9949 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9950 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9954 int count
= SPECPDL_INDEX ();
9955 specbind (Qinhibit_read_only
, Qt
);
9956 /* Note that undo recording is always disabled. */
9958 unbind_to (count
, Qnil
);
9960 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9962 /* Set up the buffer for the multibyteness we need. */
9964 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9965 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9967 /* Raise the frame containing the echo area. */
9968 if (minibuffer_auto_raise
)
9970 struct frame
*sf
= SELECTED_FRAME ();
9971 Lisp_Object mini_window
;
9972 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9973 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9976 message_log_maybe_newline ();
9977 message_buf_print
= 1;
9981 if (NILP (echo_area_buffer
[0]))
9983 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9984 echo_area_buffer
[0] = echo_buffer
[1];
9986 echo_area_buffer
[0] = echo_buffer
[0];
9989 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9991 /* Someone switched buffers between print requests. */
9992 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9993 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9999 /* Display an echo area message in window W. Value is non-zero if W's
10000 height is changed. If display_last_displayed_message_p is
10001 non-zero, display the message that was last displayed, otherwise
10002 display the current message. */
10005 display_echo_area (struct window
*w
)
10007 int i
, no_message_p
, window_height_changed_p
, count
;
10009 /* Temporarily disable garbage collections while displaying the echo
10010 area. This is done because a GC can print a message itself.
10011 That message would modify the echo area buffer's contents while a
10012 redisplay of the buffer is going on, and seriously confuse
10014 count
= inhibit_garbage_collection ();
10016 /* If there is no message, we must call display_echo_area_1
10017 nevertheless because it resizes the window. But we will have to
10018 reset the echo_area_buffer in question to nil at the end because
10019 with_echo_area_buffer will sets it to an empty buffer. */
10020 i
= display_last_displayed_message_p
? 1 : 0;
10021 no_message_p
= NILP (echo_area_buffer
[i
]);
10023 window_height_changed_p
10024 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10025 display_echo_area_1
,
10026 (intptr_t) w
, Qnil
, 0, 0);
10029 echo_area_buffer
[i
] = Qnil
;
10031 unbind_to (count
, Qnil
);
10032 return window_height_changed_p
;
10036 /* Helper for display_echo_area. Display the current buffer which
10037 contains the current echo area message in window W, a mini-window,
10038 a pointer to which is passed in A1. A2..A4 are currently not used.
10039 Change the height of W so that all of the message is displayed.
10040 Value is non-zero if height of W was changed. */
10043 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
10046 struct window
*w
= (struct window
*) i1
;
10047 Lisp_Object window
;
10048 struct text_pos start
;
10049 int window_height_changed_p
= 0;
10051 /* Do this before displaying, so that we have a large enough glyph
10052 matrix for the display. If we can't get enough space for the
10053 whole text, display the last N lines. That works by setting w->start. */
10054 window_height_changed_p
= resize_mini_window (w
, 0);
10056 /* Use the starting position chosen by resize_mini_window. */
10057 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10060 clear_glyph_matrix (w
->desired_matrix
);
10061 XSETWINDOW (window
, w
);
10062 try_window (window
, start
, 0);
10064 return window_height_changed_p
;
10068 /* Resize the echo area window to exactly the size needed for the
10069 currently displayed message, if there is one. If a mini-buffer
10070 is active, don't shrink it. */
10073 resize_echo_area_exactly (void)
10075 if (BUFFERP (echo_area_buffer
[0])
10076 && WINDOWP (echo_area_window
))
10078 struct window
*w
= XWINDOW (echo_area_window
);
10080 Lisp_Object resize_exactly
;
10082 if (minibuf_level
== 0)
10083 resize_exactly
= Qt
;
10085 resize_exactly
= Qnil
;
10087 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10088 (intptr_t) w
, resize_exactly
,
10092 ++windows_or_buffers_changed
;
10093 ++update_mode_lines
;
10094 redisplay_internal ();
10100 /* Callback function for with_echo_area_buffer, when used from
10101 resize_echo_area_exactly. A1 contains a pointer to the window to
10102 resize, EXACTLY non-nil means resize the mini-window exactly to the
10103 size of the text displayed. A3 and A4 are not used. Value is what
10104 resize_mini_window returns. */
10107 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
10110 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10114 /* Resize mini-window W to fit the size of its contents. EXACT_P
10115 means size the window exactly to the size needed. Otherwise, it's
10116 only enlarged until W's buffer is empty.
10118 Set W->start to the right place to begin display. If the whole
10119 contents fit, start at the beginning. Otherwise, start so as
10120 to make the end of the contents appear. This is particularly
10121 important for y-or-n-p, but seems desirable generally.
10123 Value is non-zero if the window height has been changed. */
10126 resize_mini_window (struct window
*w
, int exact_p
)
10128 struct frame
*f
= XFRAME (w
->frame
);
10129 int window_height_changed_p
= 0;
10131 xassert (MINI_WINDOW_P (w
));
10133 /* By default, start display at the beginning. */
10134 set_marker_both (w
->start
, w
->buffer
,
10135 BUF_BEGV (XBUFFER (w
->buffer
)),
10136 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10138 /* Don't resize windows while redisplaying a window; it would
10139 confuse redisplay functions when the size of the window they are
10140 displaying changes from under them. Such a resizing can happen,
10141 for instance, when which-func prints a long message while
10142 we are running fontification-functions. We're running these
10143 functions with safe_call which binds inhibit-redisplay to t. */
10144 if (!NILP (Vinhibit_redisplay
))
10147 /* Nil means don't try to resize. */
10148 if (NILP (Vresize_mini_windows
)
10149 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10152 if (!FRAME_MINIBUF_ONLY_P (f
))
10155 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10156 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10157 int height
, max_height
;
10158 int unit
= FRAME_LINE_HEIGHT (f
);
10159 struct text_pos start
;
10160 struct buffer
*old_current_buffer
= NULL
;
10162 if (current_buffer
!= XBUFFER (w
->buffer
))
10164 old_current_buffer
= current_buffer
;
10165 set_buffer_internal (XBUFFER (w
->buffer
));
10168 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10170 /* Compute the max. number of lines specified by the user. */
10171 if (FLOATP (Vmax_mini_window_height
))
10172 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10173 else if (INTEGERP (Vmax_mini_window_height
))
10174 max_height
= XINT (Vmax_mini_window_height
);
10176 max_height
= total_height
/ 4;
10178 /* Correct that max. height if it's bogus. */
10179 max_height
= max (1, max_height
);
10180 max_height
= min (total_height
, max_height
);
10182 /* Find out the height of the text in the window. */
10183 if (it
.line_wrap
== TRUNCATE
)
10188 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10189 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10190 height
= it
.current_y
+ last_height
;
10192 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10193 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10194 height
= (height
+ unit
- 1) / unit
;
10197 /* Compute a suitable window start. */
10198 if (height
> max_height
)
10200 height
= max_height
;
10201 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10202 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10203 start
= it
.current
.pos
;
10206 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10207 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10209 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10211 /* Let it grow only, until we display an empty message, in which
10212 case the window shrinks again. */
10213 if (height
> WINDOW_TOTAL_LINES (w
))
10215 int old_height
= WINDOW_TOTAL_LINES (w
);
10216 freeze_window_starts (f
, 1);
10217 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10218 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10220 else if (height
< WINDOW_TOTAL_LINES (w
)
10221 && (exact_p
|| BEGV
== ZV
))
10223 int old_height
= WINDOW_TOTAL_LINES (w
);
10224 freeze_window_starts (f
, 0);
10225 shrink_mini_window (w
);
10226 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10231 /* Always resize to exact size needed. */
10232 if (height
> WINDOW_TOTAL_LINES (w
))
10234 int old_height
= WINDOW_TOTAL_LINES (w
);
10235 freeze_window_starts (f
, 1);
10236 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10237 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10239 else if (height
< WINDOW_TOTAL_LINES (w
))
10241 int old_height
= WINDOW_TOTAL_LINES (w
);
10242 freeze_window_starts (f
, 0);
10243 shrink_mini_window (w
);
10247 freeze_window_starts (f
, 1);
10248 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10251 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10255 if (old_current_buffer
)
10256 set_buffer_internal (old_current_buffer
);
10259 return window_height_changed_p
;
10263 /* Value is the current message, a string, or nil if there is no
10264 current message. */
10267 current_message (void)
10271 if (!BUFFERP (echo_area_buffer
[0]))
10275 with_echo_area_buffer (0, 0, current_message_1
,
10276 (intptr_t) &msg
, Qnil
, 0, 0);
10278 echo_area_buffer
[0] = Qnil
;
10286 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
10289 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10292 *msg
= make_buffer_string (BEG
, Z
, 1);
10299 /* Push the current message on Vmessage_stack for later restoration
10300 by restore_message. Value is non-zero if the current message isn't
10301 empty. This is a relatively infrequent operation, so it's not
10302 worth optimizing. */
10305 push_message (void)
10308 msg
= current_message ();
10309 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10310 return STRINGP (msg
);
10314 /* Restore message display from the top of Vmessage_stack. */
10317 restore_message (void)
10321 xassert (CONSP (Vmessage_stack
));
10322 msg
= XCAR (Vmessage_stack
);
10324 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10326 message3_nolog (msg
, 0, 0);
10330 /* Handler for record_unwind_protect calling pop_message. */
10333 pop_message_unwind (Lisp_Object dummy
)
10339 /* Pop the top-most entry off Vmessage_stack. */
10344 xassert (CONSP (Vmessage_stack
));
10345 Vmessage_stack
= XCDR (Vmessage_stack
);
10349 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10350 exits. If the stack is not empty, we have a missing pop_message
10354 check_message_stack (void)
10356 if (!NILP (Vmessage_stack
))
10361 /* Truncate to NCHARS what will be displayed in the echo area the next
10362 time we display it---but don't redisplay it now. */
10365 truncate_echo_area (EMACS_INT nchars
)
10368 echo_area_buffer
[0] = Qnil
;
10369 /* A null message buffer means that the frame hasn't really been
10370 initialized yet. Error messages get reported properly by
10371 cmd_error, so this must be just an informative message; toss it. */
10372 else if (!noninteractive
10374 && !NILP (echo_area_buffer
[0]))
10376 struct frame
*sf
= SELECTED_FRAME ();
10377 if (FRAME_MESSAGE_BUF (sf
))
10378 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10383 /* Helper function for truncate_echo_area. Truncate the current
10384 message to at most NCHARS characters. */
10387 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
10389 if (BEG
+ nchars
< Z
)
10390 del_range (BEG
+ nchars
, Z
);
10392 echo_area_buffer
[0] = Qnil
;
10397 /* Set the current message to a substring of S or STRING.
10399 If STRING is a Lisp string, set the message to the first NBYTES
10400 bytes from STRING. NBYTES zero means use the whole string. If
10401 STRING is multibyte, the message will be displayed multibyte.
10403 If S is not null, set the message to the first LEN bytes of S. LEN
10404 zero means use the whole string. MULTIBYTE_P non-zero means S is
10405 multibyte. Display the message multibyte in that case.
10407 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10408 to t before calling set_message_1 (which calls insert).
10412 set_message (const char *s
, Lisp_Object string
,
10413 EMACS_INT nbytes
, int multibyte_p
)
10415 message_enable_multibyte
10416 = ((s
&& multibyte_p
)
10417 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10419 with_echo_area_buffer (0, -1, set_message_1
,
10420 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10421 message_buf_print
= 0;
10422 help_echo_showing_p
= 0;
10426 /* Helper function for set_message. Arguments have the same meaning
10427 as there, with A1 corresponding to S and A2 corresponding to STRING
10428 This function is called with the echo area buffer being
10432 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
10435 const char *s
= (const char *) i1
;
10436 const unsigned char *msg
= (const unsigned char *) s
;
10437 Lisp_Object string
= a2
;
10439 /* Change multibyteness of the echo buffer appropriately. */
10440 if (message_enable_multibyte
10441 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10442 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10444 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
10445 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10446 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
10448 /* Insert new message at BEG. */
10449 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10451 if (STRINGP (string
))
10456 nbytes
= SBYTES (string
);
10457 nchars
= string_byte_to_char (string
, nbytes
);
10459 /* This function takes care of single/multibyte conversion. We
10460 just have to ensure that the echo area buffer has the right
10461 setting of enable_multibyte_characters. */
10462 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10467 nbytes
= strlen (s
);
10469 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10471 /* Convert from multi-byte to single-byte. */
10476 /* Convert a multibyte string to single-byte. */
10477 for (i
= 0; i
< nbytes
; i
+= n
)
10479 c
= string_char_and_length (msg
+ i
, &n
);
10480 work
[0] = (ASCII_CHAR_P (c
)
10482 : multibyte_char_to_unibyte (c
));
10483 insert_1_both (work
, 1, 1, 1, 0, 0);
10486 else if (!multibyte_p
10487 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10489 /* Convert from single-byte to multi-byte. */
10492 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10494 /* Convert a single-byte string to multibyte. */
10495 for (i
= 0; i
< nbytes
; i
++)
10498 MAKE_CHAR_MULTIBYTE (c
);
10499 n
= CHAR_STRING (c
, str
);
10500 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10504 insert_1 (s
, nbytes
, 1, 0, 0);
10511 /* Clear messages. CURRENT_P non-zero means clear the current
10512 message. LAST_DISPLAYED_P non-zero means clear the message
10516 clear_message (int current_p
, int last_displayed_p
)
10520 echo_area_buffer
[0] = Qnil
;
10521 message_cleared_p
= 1;
10524 if (last_displayed_p
)
10525 echo_area_buffer
[1] = Qnil
;
10527 message_buf_print
= 0;
10530 /* Clear garbaged frames.
10532 This function is used where the old redisplay called
10533 redraw_garbaged_frames which in turn called redraw_frame which in
10534 turn called clear_frame. The call to clear_frame was a source of
10535 flickering. I believe a clear_frame is not necessary. It should
10536 suffice in the new redisplay to invalidate all current matrices,
10537 and ensure a complete redisplay of all windows. */
10540 clear_garbaged_frames (void)
10542 if (frame_garbaged
)
10544 Lisp_Object tail
, frame
;
10545 int changed_count
= 0;
10547 FOR_EACH_FRAME (tail
, frame
)
10549 struct frame
*f
= XFRAME (frame
);
10551 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10555 Fredraw_frame (frame
);
10556 f
->force_flush_display_p
= 1;
10558 clear_current_matrices (f
);
10565 frame_garbaged
= 0;
10567 ++windows_or_buffers_changed
;
10572 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10573 is non-zero update selected_frame. Value is non-zero if the
10574 mini-windows height has been changed. */
10577 echo_area_display (int update_frame_p
)
10579 Lisp_Object mini_window
;
10582 int window_height_changed_p
= 0;
10583 struct frame
*sf
= SELECTED_FRAME ();
10585 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10586 w
= XWINDOW (mini_window
);
10587 f
= XFRAME (WINDOW_FRAME (w
));
10589 /* Don't display if frame is invisible or not yet initialized. */
10590 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10593 #ifdef HAVE_WINDOW_SYSTEM
10594 /* When Emacs starts, selected_frame may be the initial terminal
10595 frame. If we let this through, a message would be displayed on
10597 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10599 #endif /* HAVE_WINDOW_SYSTEM */
10601 /* Redraw garbaged frames. */
10602 if (frame_garbaged
)
10603 clear_garbaged_frames ();
10605 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10607 echo_area_window
= mini_window
;
10608 window_height_changed_p
= display_echo_area (w
);
10609 w
->must_be_updated_p
= 1;
10611 /* Update the display, unless called from redisplay_internal.
10612 Also don't update the screen during redisplay itself. The
10613 update will happen at the end of redisplay, and an update
10614 here could cause confusion. */
10615 if (update_frame_p
&& !redisplaying_p
)
10619 /* If the display update has been interrupted by pending
10620 input, update mode lines in the frame. Due to the
10621 pending input, it might have been that redisplay hasn't
10622 been called, so that mode lines above the echo area are
10623 garbaged. This looks odd, so we prevent it here. */
10624 if (!display_completed
)
10625 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10627 if (window_height_changed_p
10628 /* Don't do this if Emacs is shutting down. Redisplay
10629 needs to run hooks. */
10630 && !NILP (Vrun_hooks
))
10632 /* Must update other windows. Likewise as in other
10633 cases, don't let this update be interrupted by
10635 int count
= SPECPDL_INDEX ();
10636 specbind (Qredisplay_dont_pause
, Qt
);
10637 windows_or_buffers_changed
= 1;
10638 redisplay_internal ();
10639 unbind_to (count
, Qnil
);
10641 else if (FRAME_WINDOW_P (f
) && n
== 0)
10643 /* Window configuration is the same as before.
10644 Can do with a display update of the echo area,
10645 unless we displayed some mode lines. */
10646 update_single_window (w
, 1);
10647 FRAME_RIF (f
)->flush_display (f
);
10650 update_frame (f
, 1, 1);
10652 /* If cursor is in the echo area, make sure that the next
10653 redisplay displays the minibuffer, so that the cursor will
10654 be replaced with what the minibuffer wants. */
10655 if (cursor_in_echo_area
)
10656 ++windows_or_buffers_changed
;
10659 else if (!EQ (mini_window
, selected_window
))
10660 windows_or_buffers_changed
++;
10662 /* Last displayed message is now the current message. */
10663 echo_area_buffer
[1] = echo_area_buffer
[0];
10664 /* Inform read_char that we're not echoing. */
10665 echo_message_buffer
= Qnil
;
10667 /* Prevent redisplay optimization in redisplay_internal by resetting
10668 this_line_start_pos. This is done because the mini-buffer now
10669 displays the message instead of its buffer text. */
10670 if (EQ (mini_window
, selected_window
))
10671 CHARPOS (this_line_start_pos
) = 0;
10673 return window_height_changed_p
;
10678 /***********************************************************************
10679 Mode Lines and Frame Titles
10680 ***********************************************************************/
10682 /* A buffer for constructing non-propertized mode-line strings and
10683 frame titles in it; allocated from the heap in init_xdisp and
10684 resized as needed in store_mode_line_noprop_char. */
10686 static char *mode_line_noprop_buf
;
10688 /* The buffer's end, and a current output position in it. */
10690 static char *mode_line_noprop_buf_end
;
10691 static char *mode_line_noprop_ptr
;
10693 #define MODE_LINE_NOPROP_LEN(start) \
10694 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10697 MODE_LINE_DISPLAY
= 0,
10701 } mode_line_target
;
10703 /* Alist that caches the results of :propertize.
10704 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10705 static Lisp_Object mode_line_proptrans_alist
;
10707 /* List of strings making up the mode-line. */
10708 static Lisp_Object mode_line_string_list
;
10710 /* Base face property when building propertized mode line string. */
10711 static Lisp_Object mode_line_string_face
;
10712 static Lisp_Object mode_line_string_face_prop
;
10715 /* Unwind data for mode line strings */
10717 static Lisp_Object Vmode_line_unwind_vector
;
10720 format_mode_line_unwind_data (struct buffer
*obuf
,
10722 int save_proptrans
)
10724 Lisp_Object vector
, tmp
;
10726 /* Reduce consing by keeping one vector in
10727 Vwith_echo_area_save_vector. */
10728 vector
= Vmode_line_unwind_vector
;
10729 Vmode_line_unwind_vector
= Qnil
;
10732 vector
= Fmake_vector (make_number (8), Qnil
);
10734 ASET (vector
, 0, make_number (mode_line_target
));
10735 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10736 ASET (vector
, 2, mode_line_string_list
);
10737 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10738 ASET (vector
, 4, mode_line_string_face
);
10739 ASET (vector
, 5, mode_line_string_face_prop
);
10742 XSETBUFFER (tmp
, obuf
);
10745 ASET (vector
, 6, tmp
);
10746 ASET (vector
, 7, owin
);
10752 unwind_format_mode_line (Lisp_Object vector
)
10754 mode_line_target
= XINT (AREF (vector
, 0));
10755 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10756 mode_line_string_list
= AREF (vector
, 2);
10757 if (! EQ (AREF (vector
, 3), Qt
))
10758 mode_line_proptrans_alist
= AREF (vector
, 3);
10759 mode_line_string_face
= AREF (vector
, 4);
10760 mode_line_string_face_prop
= AREF (vector
, 5);
10762 if (!NILP (AREF (vector
, 7)))
10763 /* Select window before buffer, since it may change the buffer. */
10764 Fselect_window (AREF (vector
, 7), Qt
);
10766 if (!NILP (AREF (vector
, 6)))
10768 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10769 ASET (vector
, 6, Qnil
);
10772 Vmode_line_unwind_vector
= vector
;
10777 /* Store a single character C for the frame title in mode_line_noprop_buf.
10778 Re-allocate mode_line_noprop_buf if necessary. */
10781 store_mode_line_noprop_char (char c
)
10783 /* If output position has reached the end of the allocated buffer,
10784 increase the buffer's size. */
10785 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10787 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10788 ptrdiff_t size
= len
;
10789 mode_line_noprop_buf
=
10790 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10791 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10792 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10795 *mode_line_noprop_ptr
++ = c
;
10799 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10800 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10801 characters that yield more columns than PRECISION; PRECISION <= 0
10802 means copy the whole string. Pad with spaces until FIELD_WIDTH
10803 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10804 pad. Called from display_mode_element when it is used to build a
10808 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10810 const unsigned char *str
= (const unsigned char *) string
;
10812 EMACS_INT dummy
, nbytes
;
10814 /* Copy at most PRECISION chars from STR. */
10815 nbytes
= strlen (string
);
10816 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10818 store_mode_line_noprop_char (*str
++);
10820 /* Fill up with spaces until FIELD_WIDTH reached. */
10821 while (field_width
> 0
10822 && n
< field_width
)
10824 store_mode_line_noprop_char (' ');
10831 /***********************************************************************
10833 ***********************************************************************/
10835 #ifdef HAVE_WINDOW_SYSTEM
10837 /* Set the title of FRAME, if it has changed. The title format is
10838 Vicon_title_format if FRAME is iconified, otherwise it is
10839 frame_title_format. */
10842 x_consider_frame_title (Lisp_Object frame
)
10844 struct frame
*f
= XFRAME (frame
);
10846 if (FRAME_WINDOW_P (f
)
10847 || FRAME_MINIBUF_ONLY_P (f
)
10848 || f
->explicit_name
)
10850 /* Do we have more than one visible frame on this X display? */
10853 ptrdiff_t title_start
;
10857 int count
= SPECPDL_INDEX ();
10859 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10861 Lisp_Object other_frame
= XCAR (tail
);
10862 struct frame
*tf
= XFRAME (other_frame
);
10865 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10866 && !FRAME_MINIBUF_ONLY_P (tf
)
10867 && !EQ (other_frame
, tip_frame
)
10868 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10872 /* Set global variable indicating that multiple frames exist. */
10873 multiple_frames
= CONSP (tail
);
10875 /* Switch to the buffer of selected window of the frame. Set up
10876 mode_line_target so that display_mode_element will output into
10877 mode_line_noprop_buf; then display the title. */
10878 record_unwind_protect (unwind_format_mode_line
,
10879 format_mode_line_unwind_data
10880 (current_buffer
, selected_window
, 0));
10882 Fselect_window (f
->selected_window
, Qt
);
10883 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10884 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10886 mode_line_target
= MODE_LINE_TITLE
;
10887 title_start
= MODE_LINE_NOPROP_LEN (0);
10888 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10889 NULL
, DEFAULT_FACE_ID
);
10890 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10891 len
= MODE_LINE_NOPROP_LEN (title_start
);
10892 title
= mode_line_noprop_buf
+ title_start
;
10893 unbind_to (count
, Qnil
);
10895 /* Set the title only if it's changed. This avoids consing in
10896 the common case where it hasn't. (If it turns out that we've
10897 already wasted too much time by walking through the list with
10898 display_mode_element, then we might need to optimize at a
10899 higher level than this.) */
10900 if (! STRINGP (f
->name
)
10901 || SBYTES (f
->name
) != len
10902 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10903 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10907 #endif /* not HAVE_WINDOW_SYSTEM */
10912 /***********************************************************************
10914 ***********************************************************************/
10917 /* Prepare for redisplay by updating menu-bar item lists when
10918 appropriate. This can call eval. */
10921 prepare_menu_bars (void)
10924 struct gcpro gcpro1
, gcpro2
;
10926 Lisp_Object tooltip_frame
;
10928 #ifdef HAVE_WINDOW_SYSTEM
10929 tooltip_frame
= tip_frame
;
10931 tooltip_frame
= Qnil
;
10934 /* Update all frame titles based on their buffer names, etc. We do
10935 this before the menu bars so that the buffer-menu will show the
10936 up-to-date frame titles. */
10937 #ifdef HAVE_WINDOW_SYSTEM
10938 if (windows_or_buffers_changed
|| update_mode_lines
)
10940 Lisp_Object tail
, frame
;
10942 FOR_EACH_FRAME (tail
, frame
)
10944 f
= XFRAME (frame
);
10945 if (!EQ (frame
, tooltip_frame
)
10946 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10947 x_consider_frame_title (frame
);
10950 #endif /* HAVE_WINDOW_SYSTEM */
10952 /* Update the menu bar item lists, if appropriate. This has to be
10953 done before any actual redisplay or generation of display lines. */
10954 all_windows
= (update_mode_lines
10955 || buffer_shared
> 1
10956 || windows_or_buffers_changed
);
10959 Lisp_Object tail
, frame
;
10960 int count
= SPECPDL_INDEX ();
10961 /* 1 means that update_menu_bar has run its hooks
10962 so any further calls to update_menu_bar shouldn't do so again. */
10963 int menu_bar_hooks_run
= 0;
10965 record_unwind_save_match_data ();
10967 FOR_EACH_FRAME (tail
, frame
)
10969 f
= XFRAME (frame
);
10971 /* Ignore tooltip frame. */
10972 if (EQ (frame
, tooltip_frame
))
10975 /* If a window on this frame changed size, report that to
10976 the user and clear the size-change flag. */
10977 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10979 Lisp_Object functions
;
10981 /* Clear flag first in case we get an error below. */
10982 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10983 functions
= Vwindow_size_change_functions
;
10984 GCPRO2 (tail
, functions
);
10986 while (CONSP (functions
))
10988 if (!EQ (XCAR (functions
), Qt
))
10989 call1 (XCAR (functions
), frame
);
10990 functions
= XCDR (functions
);
10996 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10997 #ifdef HAVE_WINDOW_SYSTEM
10998 update_tool_bar (f
, 0);
11001 if (windows_or_buffers_changed
11003 ns_set_doc_edited (f
, Fbuffer_modified_p
11004 (XWINDOW (f
->selected_window
)->buffer
));
11009 unbind_to (count
, Qnil
);
11013 struct frame
*sf
= SELECTED_FRAME ();
11014 update_menu_bar (sf
, 1, 0);
11015 #ifdef HAVE_WINDOW_SYSTEM
11016 update_tool_bar (sf
, 1);
11022 /* Update the menu bar item list for frame F. This has to be done
11023 before we start to fill in any display lines, because it can call
11026 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11028 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11029 already ran the menu bar hooks for this redisplay, so there
11030 is no need to run them again. The return value is the
11031 updated value of this flag, to pass to the next call. */
11034 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11036 Lisp_Object window
;
11037 register struct window
*w
;
11039 /* If called recursively during a menu update, do nothing. This can
11040 happen when, for instance, an activate-menubar-hook causes a
11042 if (inhibit_menubar_update
)
11045 window
= FRAME_SELECTED_WINDOW (f
);
11046 w
= XWINDOW (window
);
11048 if (FRAME_WINDOW_P (f
)
11050 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11051 || defined (HAVE_NS) || defined (USE_GTK)
11052 FRAME_EXTERNAL_MENU_BAR (f
)
11054 FRAME_MENU_BAR_LINES (f
) > 0
11056 : FRAME_MENU_BAR_LINES (f
) > 0)
11058 /* If the user has switched buffers or windows, we need to
11059 recompute to reflect the new bindings. But we'll
11060 recompute when update_mode_lines is set too; that means
11061 that people can use force-mode-line-update to request
11062 that the menu bar be recomputed. The adverse effect on
11063 the rest of the redisplay algorithm is about the same as
11064 windows_or_buffers_changed anyway. */
11065 if (windows_or_buffers_changed
11066 /* This used to test w->update_mode_line, but we believe
11067 there is no need to recompute the menu in that case. */
11068 || update_mode_lines
11069 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11070 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11071 != !NILP (w
->last_had_star
))
11072 || ((!NILP (Vtransient_mark_mode
)
11073 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11074 != !NILP (w
->region_showing
)))
11076 struct buffer
*prev
= current_buffer
;
11077 int count
= SPECPDL_INDEX ();
11079 specbind (Qinhibit_menubar_update
, Qt
);
11081 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11082 if (save_match_data
)
11083 record_unwind_save_match_data ();
11084 if (NILP (Voverriding_local_map_menu_flag
))
11086 specbind (Qoverriding_terminal_local_map
, Qnil
);
11087 specbind (Qoverriding_local_map
, Qnil
);
11092 /* Run the Lucid hook. */
11093 safe_run_hooks (Qactivate_menubar_hook
);
11095 /* If it has changed current-menubar from previous value,
11096 really recompute the menu-bar from the value. */
11097 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11098 call0 (Qrecompute_lucid_menubar
);
11100 safe_run_hooks (Qmenu_bar_update_hook
);
11105 XSETFRAME (Vmenu_updating_frame
, f
);
11106 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
11108 /* Redisplay the menu bar in case we changed it. */
11109 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11110 || defined (HAVE_NS) || defined (USE_GTK)
11111 if (FRAME_WINDOW_P (f
))
11113 #if defined (HAVE_NS)
11114 /* All frames on Mac OS share the same menubar. So only
11115 the selected frame should be allowed to set it. */
11116 if (f
== SELECTED_FRAME ())
11118 set_frame_menubar (f
, 0, 0);
11121 /* On a terminal screen, the menu bar is an ordinary screen
11122 line, and this makes it get updated. */
11123 w
->update_mode_line
= Qt
;
11124 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11125 /* In the non-toolkit version, the menu bar is an ordinary screen
11126 line, and this makes it get updated. */
11127 w
->update_mode_line
= Qt
;
11128 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11130 unbind_to (count
, Qnil
);
11131 set_buffer_internal_1 (prev
);
11140 /***********************************************************************
11142 ***********************************************************************/
11144 #ifdef HAVE_WINDOW_SYSTEM
11147 Nominal cursor position -- where to draw output.
11148 HPOS and VPOS are window relative glyph matrix coordinates.
11149 X and Y are window relative pixel coordinates. */
11151 struct cursor_pos output_cursor
;
11155 Set the global variable output_cursor to CURSOR. All cursor
11156 positions are relative to updated_window. */
11159 set_output_cursor (struct cursor_pos
*cursor
)
11161 output_cursor
.hpos
= cursor
->hpos
;
11162 output_cursor
.vpos
= cursor
->vpos
;
11163 output_cursor
.x
= cursor
->x
;
11164 output_cursor
.y
= cursor
->y
;
11169 Set a nominal cursor position.
11171 HPOS and VPOS are column/row positions in a window glyph matrix. X
11172 and Y are window text area relative pixel positions.
11174 If this is done during an update, updated_window will contain the
11175 window that is being updated and the position is the future output
11176 cursor position for that window. If updated_window is null, use
11177 selected_window and display the cursor at the given position. */
11180 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11184 /* If updated_window is not set, work on selected_window. */
11185 if (updated_window
)
11186 w
= updated_window
;
11188 w
= XWINDOW (selected_window
);
11190 /* Set the output cursor. */
11191 output_cursor
.hpos
= hpos
;
11192 output_cursor
.vpos
= vpos
;
11193 output_cursor
.x
= x
;
11194 output_cursor
.y
= y
;
11196 /* If not called as part of an update, really display the cursor.
11197 This will also set the cursor position of W. */
11198 if (updated_window
== NULL
)
11201 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11202 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11203 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11208 #endif /* HAVE_WINDOW_SYSTEM */
11211 /***********************************************************************
11213 ***********************************************************************/
11215 #ifdef HAVE_WINDOW_SYSTEM
11217 /* Where the mouse was last time we reported a mouse event. */
11219 FRAME_PTR last_mouse_frame
;
11221 /* Tool-bar item index of the item on which a mouse button was pressed
11224 int last_tool_bar_item
;
11228 update_tool_bar_unwind (Lisp_Object frame
)
11230 selected_frame
= frame
;
11234 /* Update the tool-bar item list for frame F. This has to be done
11235 before we start to fill in any display lines. Called from
11236 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11237 and restore it here. */
11240 update_tool_bar (struct frame
*f
, int save_match_data
)
11242 #if defined (USE_GTK) || defined (HAVE_NS)
11243 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11245 int do_update
= WINDOWP (f
->tool_bar_window
)
11246 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11251 Lisp_Object window
;
11254 window
= FRAME_SELECTED_WINDOW (f
);
11255 w
= XWINDOW (window
);
11257 /* If the user has switched buffers or windows, we need to
11258 recompute to reflect the new bindings. But we'll
11259 recompute when update_mode_lines is set too; that means
11260 that people can use force-mode-line-update to request
11261 that the menu bar be recomputed. The adverse effect on
11262 the rest of the redisplay algorithm is about the same as
11263 windows_or_buffers_changed anyway. */
11264 if (windows_or_buffers_changed
11265 || !NILP (w
->update_mode_line
)
11266 || update_mode_lines
11267 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11268 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11269 != !NILP (w
->last_had_star
))
11270 || ((!NILP (Vtransient_mark_mode
)
11271 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11272 != !NILP (w
->region_showing
)))
11274 struct buffer
*prev
= current_buffer
;
11275 int count
= SPECPDL_INDEX ();
11276 Lisp_Object frame
, new_tool_bar
;
11277 int new_n_tool_bar
;
11278 struct gcpro gcpro1
;
11280 /* Set current_buffer to the buffer of the selected
11281 window of the frame, so that we get the right local
11283 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11285 /* Save match data, if we must. */
11286 if (save_match_data
)
11287 record_unwind_save_match_data ();
11289 /* Make sure that we don't accidentally use bogus keymaps. */
11290 if (NILP (Voverriding_local_map_menu_flag
))
11292 specbind (Qoverriding_terminal_local_map
, Qnil
);
11293 specbind (Qoverriding_local_map
, Qnil
);
11296 GCPRO1 (new_tool_bar
);
11298 /* We must temporarily set the selected frame to this frame
11299 before calling tool_bar_items, because the calculation of
11300 the tool-bar keymap uses the selected frame (see
11301 `tool-bar-make-keymap' in tool-bar.el). */
11302 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11303 XSETFRAME (frame
, f
);
11304 selected_frame
= frame
;
11306 /* Build desired tool-bar items from keymaps. */
11307 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11310 /* Redisplay the tool-bar if we changed it. */
11311 if (new_n_tool_bar
!= f
->n_tool_bar_items
11312 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11314 /* Redisplay that happens asynchronously due to an expose event
11315 may access f->tool_bar_items. Make sure we update both
11316 variables within BLOCK_INPUT so no such event interrupts. */
11318 f
->tool_bar_items
= new_tool_bar
;
11319 f
->n_tool_bar_items
= new_n_tool_bar
;
11320 w
->update_mode_line
= Qt
;
11326 unbind_to (count
, Qnil
);
11327 set_buffer_internal_1 (prev
);
11333 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11334 F's desired tool-bar contents. F->tool_bar_items must have
11335 been set up previously by calling prepare_menu_bars. */
11338 build_desired_tool_bar_string (struct frame
*f
)
11340 int i
, size
, size_needed
;
11341 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11342 Lisp_Object image
, plist
, props
;
11344 image
= plist
= props
= Qnil
;
11345 GCPRO3 (image
, plist
, props
);
11347 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11348 Otherwise, make a new string. */
11350 /* The size of the string we might be able to reuse. */
11351 size
= (STRINGP (f
->desired_tool_bar_string
)
11352 ? SCHARS (f
->desired_tool_bar_string
)
11355 /* We need one space in the string for each image. */
11356 size_needed
= f
->n_tool_bar_items
;
11358 /* Reuse f->desired_tool_bar_string, if possible. */
11359 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11360 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
11361 make_number (' '));
11364 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11365 Fremove_text_properties (make_number (0), make_number (size
),
11366 props
, f
->desired_tool_bar_string
);
11369 /* Put a `display' property on the string for the images to display,
11370 put a `menu_item' property on tool-bar items with a value that
11371 is the index of the item in F's tool-bar item vector. */
11372 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11374 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11376 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11377 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11378 int hmargin
, vmargin
, relief
, idx
, end
;
11380 /* If image is a vector, choose the image according to the
11382 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11383 if (VECTORP (image
))
11387 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11388 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11391 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11392 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11394 xassert (ASIZE (image
) >= idx
);
11395 image
= AREF (image
, idx
);
11400 /* Ignore invalid image specifications. */
11401 if (!valid_image_p (image
))
11404 /* Display the tool-bar button pressed, or depressed. */
11405 plist
= Fcopy_sequence (XCDR (image
));
11407 /* Compute margin and relief to draw. */
11408 relief
= (tool_bar_button_relief
>= 0
11409 ? tool_bar_button_relief
11410 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11411 hmargin
= vmargin
= relief
;
11413 if (INTEGERP (Vtool_bar_button_margin
)
11414 && XINT (Vtool_bar_button_margin
) > 0)
11416 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11417 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11419 else if (CONSP (Vtool_bar_button_margin
))
11421 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
11422 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
11423 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11425 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
11426 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
11427 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11430 if (auto_raise_tool_bar_buttons_p
)
11432 /* Add a `:relief' property to the image spec if the item is
11436 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11443 /* If image is selected, display it pressed, i.e. with a
11444 negative relief. If it's not selected, display it with a
11446 plist
= Fplist_put (plist
, QCrelief
,
11448 ? make_number (-relief
)
11449 : make_number (relief
)));
11454 /* Put a margin around the image. */
11455 if (hmargin
|| vmargin
)
11457 if (hmargin
== vmargin
)
11458 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11460 plist
= Fplist_put (plist
, QCmargin
,
11461 Fcons (make_number (hmargin
),
11462 make_number (vmargin
)));
11465 /* If button is not enabled, and we don't have special images
11466 for the disabled state, make the image appear disabled by
11467 applying an appropriate algorithm to it. */
11468 if (!enabled_p
&& idx
< 0)
11469 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11471 /* Put a `display' text property on the string for the image to
11472 display. Put a `menu-item' property on the string that gives
11473 the start of this item's properties in the tool-bar items
11475 image
= Fcons (Qimage
, plist
);
11476 props
= list4 (Qdisplay
, image
,
11477 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11479 /* Let the last image hide all remaining spaces in the tool bar
11480 string. The string can be longer than needed when we reuse a
11481 previous string. */
11482 if (i
+ 1 == f
->n_tool_bar_items
)
11483 end
= SCHARS (f
->desired_tool_bar_string
);
11486 Fadd_text_properties (make_number (i
), make_number (end
),
11487 props
, f
->desired_tool_bar_string
);
11495 /* Display one line of the tool-bar of frame IT->f.
11497 HEIGHT specifies the desired height of the tool-bar line.
11498 If the actual height of the glyph row is less than HEIGHT, the
11499 row's height is increased to HEIGHT, and the icons are centered
11500 vertically in the new height.
11502 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11503 count a final empty row in case the tool-bar width exactly matches
11508 display_tool_bar_line (struct it
*it
, int height
)
11510 struct glyph_row
*row
= it
->glyph_row
;
11511 int max_x
= it
->last_visible_x
;
11512 struct glyph
*last
;
11514 prepare_desired_row (row
);
11515 row
->y
= it
->current_y
;
11517 /* Note that this isn't made use of if the face hasn't a box,
11518 so there's no need to check the face here. */
11519 it
->start_of_box_run_p
= 1;
11521 while (it
->current_x
< max_x
)
11523 int x
, n_glyphs_before
, i
, nglyphs
;
11524 struct it it_before
;
11526 /* Get the next display element. */
11527 if (!get_next_display_element (it
))
11529 /* Don't count empty row if we are counting needed tool-bar lines. */
11530 if (height
< 0 && !it
->hpos
)
11535 /* Produce glyphs. */
11536 n_glyphs_before
= row
->used
[TEXT_AREA
];
11539 PRODUCE_GLYPHS (it
);
11541 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11543 x
= it_before
.current_x
;
11544 while (i
< nglyphs
)
11546 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11548 if (x
+ glyph
->pixel_width
> max_x
)
11550 /* Glyph doesn't fit on line. Backtrack. */
11551 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11553 /* If this is the only glyph on this line, it will never fit on the
11554 tool-bar, so skip it. But ensure there is at least one glyph,
11555 so we don't accidentally disable the tool-bar. */
11556 if (n_glyphs_before
== 0
11557 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11563 x
+= glyph
->pixel_width
;
11567 /* Stop at line end. */
11568 if (ITERATOR_AT_END_OF_LINE_P (it
))
11571 set_iterator_to_next (it
, 1);
11576 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11578 /* Use default face for the border below the tool bar.
11580 FIXME: When auto-resize-tool-bars is grow-only, there is
11581 no additional border below the possibly empty tool-bar lines.
11582 So to make the extra empty lines look "normal", we have to
11583 use the tool-bar face for the border too. */
11584 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11585 it
->face_id
= DEFAULT_FACE_ID
;
11587 extend_face_to_end_of_line (it
);
11588 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11589 last
->right_box_line_p
= 1;
11590 if (last
== row
->glyphs
[TEXT_AREA
])
11591 last
->left_box_line_p
= 1;
11593 /* Make line the desired height and center it vertically. */
11594 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11596 /* Don't add more than one line height. */
11597 height
%= FRAME_LINE_HEIGHT (it
->f
);
11598 it
->max_ascent
+= height
/ 2;
11599 it
->max_descent
+= (height
+ 1) / 2;
11602 compute_line_metrics (it
);
11604 /* If line is empty, make it occupy the rest of the tool-bar. */
11605 if (!row
->displays_text_p
)
11607 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11608 row
->visible_height
= row
->height
;
11609 row
->ascent
= row
->phys_ascent
= 0;
11610 row
->extra_line_spacing
= 0;
11613 row
->full_width_p
= 1;
11614 row
->continued_p
= 0;
11615 row
->truncated_on_left_p
= 0;
11616 row
->truncated_on_right_p
= 0;
11618 it
->current_x
= it
->hpos
= 0;
11619 it
->current_y
+= row
->height
;
11625 /* Max tool-bar height. */
11627 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11628 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11630 /* Value is the number of screen lines needed to make all tool-bar
11631 items of frame F visible. The number of actual rows needed is
11632 returned in *N_ROWS if non-NULL. */
11635 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11637 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11639 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11640 the desired matrix, so use (unused) mode-line row as temporary row to
11641 avoid destroying the first tool-bar row. */
11642 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11644 /* Initialize an iterator for iteration over
11645 F->desired_tool_bar_string in the tool-bar window of frame F. */
11646 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11647 it
.first_visible_x
= 0;
11648 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11649 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11650 it
.paragraph_embedding
= L2R
;
11652 while (!ITERATOR_AT_END_P (&it
))
11654 clear_glyph_row (temp_row
);
11655 it
.glyph_row
= temp_row
;
11656 display_tool_bar_line (&it
, -1);
11658 clear_glyph_row (temp_row
);
11660 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11662 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11664 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11668 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11670 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11671 (Lisp_Object frame
)
11678 frame
= selected_frame
;
11680 CHECK_FRAME (frame
);
11681 f
= XFRAME (frame
);
11683 if (WINDOWP (f
->tool_bar_window
)
11684 && (w
= XWINDOW (f
->tool_bar_window
),
11685 WINDOW_TOTAL_LINES (w
) > 0))
11687 update_tool_bar (f
, 1);
11688 if (f
->n_tool_bar_items
)
11690 build_desired_tool_bar_string (f
);
11691 nlines
= tool_bar_lines_needed (f
, NULL
);
11695 return make_number (nlines
);
11699 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11700 height should be changed. */
11703 redisplay_tool_bar (struct frame
*f
)
11707 struct glyph_row
*row
;
11709 #if defined (USE_GTK) || defined (HAVE_NS)
11710 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11711 update_frame_tool_bar (f
);
11715 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11716 do anything. This means you must start with tool-bar-lines
11717 non-zero to get the auto-sizing effect. Or in other words, you
11718 can turn off tool-bars by specifying tool-bar-lines zero. */
11719 if (!WINDOWP (f
->tool_bar_window
)
11720 || (w
= XWINDOW (f
->tool_bar_window
),
11721 WINDOW_TOTAL_LINES (w
) == 0))
11724 /* Set up an iterator for the tool-bar window. */
11725 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11726 it
.first_visible_x
= 0;
11727 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11728 row
= it
.glyph_row
;
11730 /* Build a string that represents the contents of the tool-bar. */
11731 build_desired_tool_bar_string (f
);
11732 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11733 /* FIXME: This should be controlled by a user option. But it
11734 doesn't make sense to have an R2L tool bar if the menu bar cannot
11735 be drawn also R2L, and making the menu bar R2L is tricky due
11736 toolkit-specific code that implements it. If an R2L tool bar is
11737 ever supported, display_tool_bar_line should also be augmented to
11738 call unproduce_glyphs like display_line and display_string
11740 it
.paragraph_embedding
= L2R
;
11742 if (f
->n_tool_bar_rows
== 0)
11746 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11747 nlines
!= WINDOW_TOTAL_LINES (w
)))
11750 int old_height
= WINDOW_TOTAL_LINES (w
);
11752 XSETFRAME (frame
, f
);
11753 Fmodify_frame_parameters (frame
,
11754 Fcons (Fcons (Qtool_bar_lines
,
11755 make_number (nlines
)),
11757 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11759 clear_glyph_matrix (w
->desired_matrix
);
11760 fonts_changed_p
= 1;
11766 /* Display as many lines as needed to display all tool-bar items. */
11768 if (f
->n_tool_bar_rows
> 0)
11770 int border
, rows
, height
, extra
;
11772 if (INTEGERP (Vtool_bar_border
))
11773 border
= XINT (Vtool_bar_border
);
11774 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11775 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11776 else if (EQ (Vtool_bar_border
, Qborder_width
))
11777 border
= f
->border_width
;
11783 rows
= f
->n_tool_bar_rows
;
11784 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11785 extra
= it
.last_visible_y
- border
- height
* rows
;
11787 while (it
.current_y
< it
.last_visible_y
)
11790 if (extra
> 0 && rows
-- > 0)
11792 h
= (extra
+ rows
- 1) / rows
;
11795 display_tool_bar_line (&it
, height
+ h
);
11800 while (it
.current_y
< it
.last_visible_y
)
11801 display_tool_bar_line (&it
, 0);
11804 /* It doesn't make much sense to try scrolling in the tool-bar
11805 window, so don't do it. */
11806 w
->desired_matrix
->no_scrolling_p
= 1;
11807 w
->must_be_updated_p
= 1;
11809 if (!NILP (Vauto_resize_tool_bars
))
11811 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11812 int change_height_p
= 0;
11814 /* If we couldn't display everything, change the tool-bar's
11815 height if there is room for more. */
11816 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11817 && it
.current_y
< max_tool_bar_height
)
11818 change_height_p
= 1;
11820 row
= it
.glyph_row
- 1;
11822 /* If there are blank lines at the end, except for a partially
11823 visible blank line at the end that is smaller than
11824 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11825 if (!row
->displays_text_p
11826 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11827 change_height_p
= 1;
11829 /* If row displays tool-bar items, but is partially visible,
11830 change the tool-bar's height. */
11831 if (row
->displays_text_p
11832 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11833 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11834 change_height_p
= 1;
11836 /* Resize windows as needed by changing the `tool-bar-lines'
11837 frame parameter. */
11838 if (change_height_p
)
11841 int old_height
= WINDOW_TOTAL_LINES (w
);
11843 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11845 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11846 && !f
->minimize_tool_bar_window_p
)
11847 ? (nlines
> old_height
)
11848 : (nlines
!= old_height
));
11849 f
->minimize_tool_bar_window_p
= 0;
11851 if (change_height_p
)
11853 XSETFRAME (frame
, f
);
11854 Fmodify_frame_parameters (frame
,
11855 Fcons (Fcons (Qtool_bar_lines
,
11856 make_number (nlines
)),
11858 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11860 clear_glyph_matrix (w
->desired_matrix
);
11861 f
->n_tool_bar_rows
= nrows
;
11862 fonts_changed_p
= 1;
11869 f
->minimize_tool_bar_window_p
= 0;
11874 /* Get information about the tool-bar item which is displayed in GLYPH
11875 on frame F. Return in *PROP_IDX the index where tool-bar item
11876 properties start in F->tool_bar_items. Value is zero if
11877 GLYPH doesn't display a tool-bar item. */
11880 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11886 /* This function can be called asynchronously, which means we must
11887 exclude any possibility that Fget_text_property signals an
11889 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11890 charpos
= max (0, charpos
);
11892 /* Get the text property `menu-item' at pos. The value of that
11893 property is the start index of this item's properties in
11894 F->tool_bar_items. */
11895 prop
= Fget_text_property (make_number (charpos
),
11896 Qmenu_item
, f
->current_tool_bar_string
);
11897 if (INTEGERP (prop
))
11899 *prop_idx
= XINT (prop
);
11909 /* Get information about the tool-bar item at position X/Y on frame F.
11910 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11911 the current matrix of the tool-bar window of F, or NULL if not
11912 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11913 item in F->tool_bar_items. Value is
11915 -1 if X/Y is not on a tool-bar item
11916 0 if X/Y is on the same item that was highlighted before.
11920 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11921 int *hpos
, int *vpos
, int *prop_idx
)
11923 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11924 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11927 /* Find the glyph under X/Y. */
11928 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11929 if (*glyph
== NULL
)
11932 /* Get the start of this tool-bar item's properties in
11933 f->tool_bar_items. */
11934 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11937 /* Is mouse on the highlighted item? */
11938 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11939 && *vpos
>= hlinfo
->mouse_face_beg_row
11940 && *vpos
<= hlinfo
->mouse_face_end_row
11941 && (*vpos
> hlinfo
->mouse_face_beg_row
11942 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11943 && (*vpos
< hlinfo
->mouse_face_end_row
11944 || *hpos
< hlinfo
->mouse_face_end_col
11945 || hlinfo
->mouse_face_past_end
))
11953 Handle mouse button event on the tool-bar of frame F, at
11954 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11955 0 for button release. MODIFIERS is event modifiers for button
11959 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11960 unsigned int modifiers
)
11962 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11963 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11964 int hpos
, vpos
, prop_idx
;
11965 struct glyph
*glyph
;
11966 Lisp_Object enabled_p
;
11968 /* If not on the highlighted tool-bar item, return. */
11969 frame_to_window_pixel_xy (w
, &x
, &y
);
11970 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11973 /* If item is disabled, do nothing. */
11974 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11975 if (NILP (enabled_p
))
11980 /* Show item in pressed state. */
11981 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11982 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11983 last_tool_bar_item
= prop_idx
;
11987 Lisp_Object key
, frame
;
11988 struct input_event event
;
11989 EVENT_INIT (event
);
11991 /* Show item in released state. */
11992 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11993 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11995 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11997 XSETFRAME (frame
, f
);
11998 event
.kind
= TOOL_BAR_EVENT
;
11999 event
.frame_or_window
= frame
;
12001 kbd_buffer_store_event (&event
);
12003 event
.kind
= TOOL_BAR_EVENT
;
12004 event
.frame_or_window
= frame
;
12006 event
.modifiers
= modifiers
;
12007 kbd_buffer_store_event (&event
);
12008 last_tool_bar_item
= -1;
12013 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12014 tool-bar window-relative coordinates X/Y. Called from
12015 note_mouse_highlight. */
12018 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12020 Lisp_Object window
= f
->tool_bar_window
;
12021 struct window
*w
= XWINDOW (window
);
12022 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12023 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12025 struct glyph
*glyph
;
12026 struct glyph_row
*row
;
12028 Lisp_Object enabled_p
;
12030 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12031 int mouse_down_p
, rc
;
12033 /* Function note_mouse_highlight is called with negative X/Y
12034 values when mouse moves outside of the frame. */
12035 if (x
<= 0 || y
<= 0)
12037 clear_mouse_face (hlinfo
);
12041 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12044 /* Not on tool-bar item. */
12045 clear_mouse_face (hlinfo
);
12049 /* On same tool-bar item as before. */
12050 goto set_help_echo
;
12052 clear_mouse_face (hlinfo
);
12054 /* Mouse is down, but on different tool-bar item? */
12055 mouse_down_p
= (dpyinfo
->grabbed
12056 && f
== last_mouse_frame
12057 && FRAME_LIVE_P (f
));
12059 && last_tool_bar_item
!= prop_idx
)
12062 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12063 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12065 /* If tool-bar item is not enabled, don't highlight it. */
12066 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12067 if (!NILP (enabled_p
))
12069 /* Compute the x-position of the glyph. In front and past the
12070 image is a space. We include this in the highlighted area. */
12071 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12072 for (i
= x
= 0; i
< hpos
; ++i
)
12073 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12075 /* Record this as the current active region. */
12076 hlinfo
->mouse_face_beg_col
= hpos
;
12077 hlinfo
->mouse_face_beg_row
= vpos
;
12078 hlinfo
->mouse_face_beg_x
= x
;
12079 hlinfo
->mouse_face_beg_y
= row
->y
;
12080 hlinfo
->mouse_face_past_end
= 0;
12082 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12083 hlinfo
->mouse_face_end_row
= vpos
;
12084 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12085 hlinfo
->mouse_face_end_y
= row
->y
;
12086 hlinfo
->mouse_face_window
= window
;
12087 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12089 /* Display it as active. */
12090 show_mouse_face (hlinfo
, draw
);
12091 hlinfo
->mouse_face_image_state
= draw
;
12096 /* Set help_echo_string to a help string to display for this tool-bar item.
12097 XTread_socket does the rest. */
12098 help_echo_object
= help_echo_window
= Qnil
;
12099 help_echo_pos
= -1;
12100 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12101 if (NILP (help_echo_string
))
12102 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12105 #endif /* HAVE_WINDOW_SYSTEM */
12109 /************************************************************************
12110 Horizontal scrolling
12111 ************************************************************************/
12113 static int hscroll_window_tree (Lisp_Object
);
12114 static int hscroll_windows (Lisp_Object
);
12116 /* For all leaf windows in the window tree rooted at WINDOW, set their
12117 hscroll value so that PT is (i) visible in the window, and (ii) so
12118 that it is not within a certain margin at the window's left and
12119 right border. Value is non-zero if any window's hscroll has been
12123 hscroll_window_tree (Lisp_Object window
)
12125 int hscrolled_p
= 0;
12126 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12127 int hscroll_step_abs
= 0;
12128 double hscroll_step_rel
= 0;
12130 if (hscroll_relative_p
)
12132 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12133 if (hscroll_step_rel
< 0)
12135 hscroll_relative_p
= 0;
12136 hscroll_step_abs
= 0;
12139 else if (INTEGERP (Vhscroll_step
))
12141 hscroll_step_abs
= XINT (Vhscroll_step
);
12142 if (hscroll_step_abs
< 0)
12143 hscroll_step_abs
= 0;
12146 hscroll_step_abs
= 0;
12148 while (WINDOWP (window
))
12150 struct window
*w
= XWINDOW (window
);
12152 if (WINDOWP (w
->hchild
))
12153 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12154 else if (WINDOWP (w
->vchild
))
12155 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12156 else if (w
->cursor
.vpos
>= 0)
12159 int text_area_width
;
12160 struct glyph_row
*current_cursor_row
12161 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12162 struct glyph_row
*desired_cursor_row
12163 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12164 struct glyph_row
*cursor_row
12165 = (desired_cursor_row
->enabled_p
12166 ? desired_cursor_row
12167 : current_cursor_row
);
12168 int row_r2l_p
= cursor_row
->reversed_p
;
12170 text_area_width
= window_box_width (w
, TEXT_AREA
);
12172 /* Scroll when cursor is inside this scroll margin. */
12173 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12175 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12176 /* For left-to-right rows, hscroll when cursor is either
12177 (i) inside the right hscroll margin, or (ii) if it is
12178 inside the left margin and the window is already
12181 && ((XFASTINT (w
->hscroll
)
12182 && w
->cursor
.x
<= h_margin
)
12183 || (cursor_row
->enabled_p
12184 && cursor_row
->truncated_on_right_p
12185 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12186 /* For right-to-left rows, the logic is similar,
12187 except that rules for scrolling to left and right
12188 are reversed. E.g., if cursor.x <= h_margin, we
12189 need to hscroll "to the right" unconditionally,
12190 and that will scroll the screen to the left so as
12191 to reveal the next portion of the row. */
12193 && ((cursor_row
->enabled_p
12194 /* FIXME: It is confusing to set the
12195 truncated_on_right_p flag when R2L rows
12196 are actually truncated on the left. */
12197 && cursor_row
->truncated_on_right_p
12198 && w
->cursor
.x
<= h_margin
)
12199 || (XFASTINT (w
->hscroll
)
12200 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12204 struct buffer
*saved_current_buffer
;
12208 /* Find point in a display of infinite width. */
12209 saved_current_buffer
= current_buffer
;
12210 current_buffer
= XBUFFER (w
->buffer
);
12212 if (w
== XWINDOW (selected_window
))
12216 pt
= marker_position (w
->pointm
);
12217 pt
= max (BEGV
, pt
);
12221 /* Move iterator to pt starting at cursor_row->start in
12222 a line with infinite width. */
12223 init_to_row_start (&it
, w
, cursor_row
);
12224 it
.last_visible_x
= INFINITY
;
12225 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12226 current_buffer
= saved_current_buffer
;
12228 /* Position cursor in window. */
12229 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12230 hscroll
= max (0, (it
.current_x
12231 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12232 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12233 : (text_area_width
/ 2))))
12234 / FRAME_COLUMN_WIDTH (it
.f
);
12235 else if ((!row_r2l_p
12236 && w
->cursor
.x
>= text_area_width
- h_margin
)
12237 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12239 if (hscroll_relative_p
)
12240 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12243 wanted_x
= text_area_width
12244 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12247 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12251 if (hscroll_relative_p
)
12252 wanted_x
= text_area_width
* hscroll_step_rel
12255 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12258 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12260 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
12262 /* Don't prevent redisplay optimizations if hscroll
12263 hasn't changed, as it will unnecessarily slow down
12265 if (XFASTINT (w
->hscroll
) != hscroll
)
12267 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12268 w
->hscroll
= make_number (hscroll
);
12277 /* Value is non-zero if hscroll of any leaf window has been changed. */
12278 return hscrolled_p
;
12282 /* Set hscroll so that cursor is visible and not inside horizontal
12283 scroll margins for all windows in the tree rooted at WINDOW. See
12284 also hscroll_window_tree above. Value is non-zero if any window's
12285 hscroll has been changed. If it has, desired matrices on the frame
12286 of WINDOW are cleared. */
12289 hscroll_windows (Lisp_Object window
)
12291 int hscrolled_p
= hscroll_window_tree (window
);
12293 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12294 return hscrolled_p
;
12299 /************************************************************************
12301 ************************************************************************/
12303 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12304 to a non-zero value. This is sometimes handy to have in a debugger
12309 /* First and last unchanged row for try_window_id. */
12311 static int debug_first_unchanged_at_end_vpos
;
12312 static int debug_last_unchanged_at_beg_vpos
;
12314 /* Delta vpos and y. */
12316 static int debug_dvpos
, debug_dy
;
12318 /* Delta in characters and bytes for try_window_id. */
12320 static EMACS_INT debug_delta
, debug_delta_bytes
;
12322 /* Values of window_end_pos and window_end_vpos at the end of
12325 static EMACS_INT debug_end_vpos
;
12327 /* Append a string to W->desired_matrix->method. FMT is a printf
12328 format string. If trace_redisplay_p is non-zero also printf the
12329 resulting string to stderr. */
12331 static void debug_method_add (struct window
*, char const *, ...)
12332 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12335 debug_method_add (struct window
*w
, char const *fmt
, ...)
12338 char *method
= w
->desired_matrix
->method
;
12339 int len
= strlen (method
);
12340 int size
= sizeof w
->desired_matrix
->method
;
12341 int remaining
= size
- len
- 1;
12344 va_start (ap
, fmt
);
12345 vsprintf (buffer
, fmt
, ap
);
12347 if (len
&& remaining
)
12350 --remaining
, ++len
;
12353 strncpy (method
+ len
, buffer
, remaining
);
12355 if (trace_redisplay_p
)
12356 fprintf (stderr
, "%p (%s): %s\n",
12358 ((BUFFERP (w
->buffer
)
12359 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12360 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12365 #endif /* GLYPH_DEBUG */
12368 /* Value is non-zero if all changes in window W, which displays
12369 current_buffer, are in the text between START and END. START is a
12370 buffer position, END is given as a distance from Z. Used in
12371 redisplay_internal for display optimization. */
12374 text_outside_line_unchanged_p (struct window
*w
,
12375 EMACS_INT start
, EMACS_INT end
)
12377 int unchanged_p
= 1;
12379 /* If text or overlays have changed, see where. */
12380 if (XFASTINT (w
->last_modified
) < MODIFF
12381 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12383 /* Gap in the line? */
12384 if (GPT
< start
|| Z
- GPT
< end
)
12387 /* Changes start in front of the line, or end after it? */
12389 && (BEG_UNCHANGED
< start
- 1
12390 || END_UNCHANGED
< end
))
12393 /* If selective display, can't optimize if changes start at the
12394 beginning of the line. */
12396 && INTEGERP (BVAR (current_buffer
, selective_display
))
12397 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12398 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12401 /* If there are overlays at the start or end of the line, these
12402 may have overlay strings with newlines in them. A change at
12403 START, for instance, may actually concern the display of such
12404 overlay strings as well, and they are displayed on different
12405 lines. So, quickly rule out this case. (For the future, it
12406 might be desirable to implement something more telling than
12407 just BEG/END_UNCHANGED.) */
12410 if (BEG
+ BEG_UNCHANGED
== start
12411 && overlay_touches_p (start
))
12413 if (END_UNCHANGED
== end
12414 && overlay_touches_p (Z
- end
))
12418 /* Under bidi reordering, adding or deleting a character in the
12419 beginning of a paragraph, before the first strong directional
12420 character, can change the base direction of the paragraph (unless
12421 the buffer specifies a fixed paragraph direction), which will
12422 require to redisplay the whole paragraph. It might be worthwhile
12423 to find the paragraph limits and widen the range of redisplayed
12424 lines to that, but for now just give up this optimization. */
12425 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12426 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12430 return unchanged_p
;
12434 /* Do a frame update, taking possible shortcuts into account. This is
12435 the main external entry point for redisplay.
12437 If the last redisplay displayed an echo area message and that message
12438 is no longer requested, we clear the echo area or bring back the
12439 mini-buffer if that is in use. */
12444 redisplay_internal ();
12449 overlay_arrow_string_or_property (Lisp_Object var
)
12453 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12456 return Voverlay_arrow_string
;
12459 /* Return 1 if there are any overlay-arrows in current_buffer. */
12461 overlay_arrow_in_current_buffer_p (void)
12465 for (vlist
= Voverlay_arrow_variable_list
;
12467 vlist
= XCDR (vlist
))
12469 Lisp_Object var
= XCAR (vlist
);
12472 if (!SYMBOLP (var
))
12474 val
= find_symbol_value (var
);
12476 && current_buffer
== XMARKER (val
)->buffer
)
12483 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12487 overlay_arrows_changed_p (void)
12491 for (vlist
= Voverlay_arrow_variable_list
;
12493 vlist
= XCDR (vlist
))
12495 Lisp_Object var
= XCAR (vlist
);
12496 Lisp_Object val
, pstr
;
12498 if (!SYMBOLP (var
))
12500 val
= find_symbol_value (var
);
12501 if (!MARKERP (val
))
12503 if (! EQ (COERCE_MARKER (val
),
12504 Fget (var
, Qlast_arrow_position
))
12505 || ! (pstr
= overlay_arrow_string_or_property (var
),
12506 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12512 /* Mark overlay arrows to be updated on next redisplay. */
12515 update_overlay_arrows (int up_to_date
)
12519 for (vlist
= Voverlay_arrow_variable_list
;
12521 vlist
= XCDR (vlist
))
12523 Lisp_Object var
= XCAR (vlist
);
12525 if (!SYMBOLP (var
))
12528 if (up_to_date
> 0)
12530 Lisp_Object val
= find_symbol_value (var
);
12531 Fput (var
, Qlast_arrow_position
,
12532 COERCE_MARKER (val
));
12533 Fput (var
, Qlast_arrow_string
,
12534 overlay_arrow_string_or_property (var
));
12536 else if (up_to_date
< 0
12537 || !NILP (Fget (var
, Qlast_arrow_position
)))
12539 Fput (var
, Qlast_arrow_position
, Qt
);
12540 Fput (var
, Qlast_arrow_string
, Qt
);
12546 /* Return overlay arrow string to display at row.
12547 Return integer (bitmap number) for arrow bitmap in left fringe.
12548 Return nil if no overlay arrow. */
12551 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12555 for (vlist
= Voverlay_arrow_variable_list
;
12557 vlist
= XCDR (vlist
))
12559 Lisp_Object var
= XCAR (vlist
);
12562 if (!SYMBOLP (var
))
12565 val
= find_symbol_value (var
);
12568 && current_buffer
== XMARKER (val
)->buffer
12569 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12571 if (FRAME_WINDOW_P (it
->f
)
12572 /* FIXME: if ROW->reversed_p is set, this should test
12573 the right fringe, not the left one. */
12574 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12576 #ifdef HAVE_WINDOW_SYSTEM
12577 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12580 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12581 return make_number (fringe_bitmap
);
12584 return make_number (-1); /* Use default arrow bitmap */
12586 return overlay_arrow_string_or_property (var
);
12593 /* Return 1 if point moved out of or into a composition. Otherwise
12594 return 0. PREV_BUF and PREV_PT are the last point buffer and
12595 position. BUF and PT are the current point buffer and position. */
12598 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
12599 struct buffer
*buf
, EMACS_INT pt
)
12601 EMACS_INT start
, end
;
12603 Lisp_Object buffer
;
12605 XSETBUFFER (buffer
, buf
);
12606 /* Check a composition at the last point if point moved within the
12608 if (prev_buf
== buf
)
12611 /* Point didn't move. */
12614 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12615 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12616 && COMPOSITION_VALID_P (start
, end
, prop
)
12617 && start
< prev_pt
&& end
> prev_pt
)
12618 /* The last point was within the composition. Return 1 iff
12619 point moved out of the composition. */
12620 return (pt
<= start
|| pt
>= end
);
12623 /* Check a composition at the current point. */
12624 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12625 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12626 && COMPOSITION_VALID_P (start
, end
, prop
)
12627 && start
< pt
&& end
> pt
);
12631 /* Reconsider the setting of B->clip_changed which is displayed
12635 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12637 if (b
->clip_changed
12638 && !NILP (w
->window_end_valid
)
12639 && w
->current_matrix
->buffer
== b
12640 && w
->current_matrix
->zv
== BUF_ZV (b
)
12641 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12642 b
->clip_changed
= 0;
12644 /* If display wasn't paused, and W is not a tool bar window, see if
12645 point has been moved into or out of a composition. In that case,
12646 we set b->clip_changed to 1 to force updating the screen. If
12647 b->clip_changed has already been set to 1, we can skip this
12649 if (!b
->clip_changed
12650 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12654 if (w
== XWINDOW (selected_window
))
12657 pt
= marker_position (w
->pointm
);
12659 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12660 || pt
!= XINT (w
->last_point
))
12661 && check_point_in_composition (w
->current_matrix
->buffer
,
12662 XINT (w
->last_point
),
12663 XBUFFER (w
->buffer
), pt
))
12664 b
->clip_changed
= 1;
12669 /* Select FRAME to forward the values of frame-local variables into C
12670 variables so that the redisplay routines can access those values
12674 select_frame_for_redisplay (Lisp_Object frame
)
12676 Lisp_Object tail
, tem
;
12677 Lisp_Object old
= selected_frame
;
12678 struct Lisp_Symbol
*sym
;
12680 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12682 selected_frame
= frame
;
12685 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12686 if (CONSP (XCAR (tail
))
12687 && (tem
= XCAR (XCAR (tail
)),
12689 && (sym
= indirect_variable (XSYMBOL (tem
)),
12690 sym
->redirect
== SYMBOL_LOCALIZED
)
12691 && sym
->val
.blv
->frame_local
)
12692 /* Use find_symbol_value rather than Fsymbol_value
12693 to avoid an error if it is void. */
12694 find_symbol_value (tem
);
12695 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12699 #define STOP_POLLING \
12700 do { if (! polling_stopped_here) stop_polling (); \
12701 polling_stopped_here = 1; } while (0)
12703 #define RESUME_POLLING \
12704 do { if (polling_stopped_here) start_polling (); \
12705 polling_stopped_here = 0; } while (0)
12708 /* Perhaps in the future avoid recentering windows if it
12709 is not necessary; currently that causes some problems. */
12712 redisplay_internal (void)
12714 struct window
*w
= XWINDOW (selected_window
);
12718 int must_finish
= 0;
12719 struct text_pos tlbufpos
, tlendpos
;
12720 int number_of_visible_frames
;
12723 int polling_stopped_here
= 0;
12724 Lisp_Object old_frame
= selected_frame
;
12726 /* Non-zero means redisplay has to consider all windows on all
12727 frames. Zero means, only selected_window is considered. */
12728 int consider_all_windows_p
;
12730 /* Non-zero means redisplay has to redisplay the miniwindow */
12731 int update_miniwindow_p
= 0;
12733 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12735 /* No redisplay if running in batch mode or frame is not yet fully
12736 initialized, or redisplay is explicitly turned off by setting
12737 Vinhibit_redisplay. */
12738 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12739 || !NILP (Vinhibit_redisplay
))
12742 /* Don't examine these until after testing Vinhibit_redisplay.
12743 When Emacs is shutting down, perhaps because its connection to
12744 X has dropped, we should not look at them at all. */
12745 fr
= XFRAME (w
->frame
);
12746 sf
= SELECTED_FRAME ();
12748 if (!fr
->glyphs_initialized_p
)
12751 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12752 if (popup_activated ())
12756 /* I don't think this happens but let's be paranoid. */
12757 if (redisplaying_p
)
12760 /* Record a function that resets redisplaying_p to its old value
12761 when we leave this function. */
12762 count
= SPECPDL_INDEX ();
12763 record_unwind_protect (unwind_redisplay
,
12764 Fcons (make_number (redisplaying_p
), selected_frame
));
12766 specbind (Qinhibit_free_realized_faces
, Qnil
);
12769 Lisp_Object tail
, frame
;
12771 FOR_EACH_FRAME (tail
, frame
)
12773 struct frame
*f
= XFRAME (frame
);
12774 f
->already_hscrolled_p
= 0;
12779 /* Remember the currently selected window. */
12782 if (!EQ (old_frame
, selected_frame
)
12783 && FRAME_LIVE_P (XFRAME (old_frame
)))
12784 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12785 selected_frame and selected_window to be temporarily out-of-sync so
12786 when we come back here via `goto retry', we need to resync because we
12787 may need to run Elisp code (via prepare_menu_bars). */
12788 select_frame_for_redisplay (old_frame
);
12791 reconsider_clip_changes (w
, current_buffer
);
12792 last_escape_glyph_frame
= NULL
;
12793 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12794 last_glyphless_glyph_frame
= NULL
;
12795 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12797 /* If new fonts have been loaded that make a glyph matrix adjustment
12798 necessary, do it. */
12799 if (fonts_changed_p
)
12801 adjust_glyphs (NULL
);
12802 ++windows_or_buffers_changed
;
12803 fonts_changed_p
= 0;
12806 /* If face_change_count is non-zero, init_iterator will free all
12807 realized faces, which includes the faces referenced from current
12808 matrices. So, we can't reuse current matrices in this case. */
12809 if (face_change_count
)
12810 ++windows_or_buffers_changed
;
12812 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12813 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12815 /* Since frames on a single ASCII terminal share the same
12816 display area, displaying a different frame means redisplay
12817 the whole thing. */
12818 windows_or_buffers_changed
++;
12819 SET_FRAME_GARBAGED (sf
);
12821 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12823 FRAME_TTY (sf
)->previous_frame
= sf
;
12826 /* Set the visible flags for all frames. Do this before checking
12827 for resized or garbaged frames; they want to know if their frames
12828 are visible. See the comment in frame.h for
12829 FRAME_SAMPLE_VISIBILITY. */
12831 Lisp_Object tail
, frame
;
12833 number_of_visible_frames
= 0;
12835 FOR_EACH_FRAME (tail
, frame
)
12837 struct frame
*f
= XFRAME (frame
);
12839 FRAME_SAMPLE_VISIBILITY (f
);
12840 if (FRAME_VISIBLE_P (f
))
12841 ++number_of_visible_frames
;
12842 clear_desired_matrices (f
);
12846 /* Notice any pending interrupt request to change frame size. */
12847 do_pending_window_change (1);
12849 /* do_pending_window_change could change the selected_window due to
12850 frame resizing which makes the selected window too small. */
12851 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12854 reconsider_clip_changes (w
, current_buffer
);
12857 /* Clear frames marked as garbaged. */
12858 if (frame_garbaged
)
12859 clear_garbaged_frames ();
12861 /* Build menubar and tool-bar items. */
12862 if (NILP (Vmemory_full
))
12863 prepare_menu_bars ();
12865 if (windows_or_buffers_changed
)
12866 update_mode_lines
++;
12868 /* Detect case that we need to write or remove a star in the mode line. */
12869 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12871 w
->update_mode_line
= Qt
;
12872 if (buffer_shared
> 1)
12873 update_mode_lines
++;
12876 /* Avoid invocation of point motion hooks by `current_column' below. */
12877 count1
= SPECPDL_INDEX ();
12878 specbind (Qinhibit_point_motion_hooks
, Qt
);
12880 /* If %c is in the mode line, update it if needed. */
12881 if (!NILP (w
->column_number_displayed
)
12882 /* This alternative quickly identifies a common case
12883 where no change is needed. */
12884 && !(PT
== XFASTINT (w
->last_point
)
12885 && XFASTINT (w
->last_modified
) >= MODIFF
12886 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12887 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12888 w
->update_mode_line
= Qt
;
12890 unbind_to (count1
, Qnil
);
12892 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12894 /* The variable buffer_shared is set in redisplay_window and
12895 indicates that we redisplay a buffer in different windows. See
12897 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12898 || cursor_type_changed
);
12900 /* If specs for an arrow have changed, do thorough redisplay
12901 to ensure we remove any arrow that should no longer exist. */
12902 if (overlay_arrows_changed_p ())
12903 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12905 /* Normally the message* functions will have already displayed and
12906 updated the echo area, but the frame may have been trashed, or
12907 the update may have been preempted, so display the echo area
12908 again here. Checking message_cleared_p captures the case that
12909 the echo area should be cleared. */
12910 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12911 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12912 || (message_cleared_p
12913 && minibuf_level
== 0
12914 /* If the mini-window is currently selected, this means the
12915 echo-area doesn't show through. */
12916 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12918 int window_height_changed_p
= echo_area_display (0);
12920 if (message_cleared_p
)
12921 update_miniwindow_p
= 1;
12925 /* If we don't display the current message, don't clear the
12926 message_cleared_p flag, because, if we did, we wouldn't clear
12927 the echo area in the next redisplay which doesn't preserve
12929 if (!display_last_displayed_message_p
)
12930 message_cleared_p
= 0;
12932 if (fonts_changed_p
)
12934 else if (window_height_changed_p
)
12936 consider_all_windows_p
= 1;
12937 ++update_mode_lines
;
12938 ++windows_or_buffers_changed
;
12940 /* If window configuration was changed, frames may have been
12941 marked garbaged. Clear them or we will experience
12942 surprises wrt scrolling. */
12943 if (frame_garbaged
)
12944 clear_garbaged_frames ();
12947 else if (EQ (selected_window
, minibuf_window
)
12948 && (current_buffer
->clip_changed
12949 || XFASTINT (w
->last_modified
) < MODIFF
12950 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12951 && resize_mini_window (w
, 0))
12953 /* Resized active mini-window to fit the size of what it is
12954 showing if its contents might have changed. */
12956 /* FIXME: this causes all frames to be updated, which seems unnecessary
12957 since only the current frame needs to be considered. This function needs
12958 to be rewritten with two variables, consider_all_windows and
12959 consider_all_frames. */
12960 consider_all_windows_p
= 1;
12961 ++windows_or_buffers_changed
;
12962 ++update_mode_lines
;
12964 /* If window configuration was changed, frames may have been
12965 marked garbaged. Clear them or we will experience
12966 surprises wrt scrolling. */
12967 if (frame_garbaged
)
12968 clear_garbaged_frames ();
12972 /* If showing the region, and mark has changed, we must redisplay
12973 the whole window. The assignment to this_line_start_pos prevents
12974 the optimization directly below this if-statement. */
12975 if (((!NILP (Vtransient_mark_mode
)
12976 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12977 != !NILP (w
->region_showing
))
12978 || (!NILP (w
->region_showing
)
12979 && !EQ (w
->region_showing
,
12980 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12981 CHARPOS (this_line_start_pos
) = 0;
12983 /* Optimize the case that only the line containing the cursor in the
12984 selected window has changed. Variables starting with this_ are
12985 set in display_line and record information about the line
12986 containing the cursor. */
12987 tlbufpos
= this_line_start_pos
;
12988 tlendpos
= this_line_end_pos
;
12989 if (!consider_all_windows_p
12990 && CHARPOS (tlbufpos
) > 0
12991 && NILP (w
->update_mode_line
)
12992 && !current_buffer
->clip_changed
12993 && !current_buffer
->prevent_redisplay_optimizations_p
12994 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12995 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12996 /* Make sure recorded data applies to current buffer, etc. */
12997 && this_line_buffer
== current_buffer
12998 && current_buffer
== XBUFFER (w
->buffer
)
12999 && NILP (w
->force_start
)
13000 && NILP (w
->optional_new_start
)
13001 /* Point must be on the line that we have info recorded about. */
13002 && PT
>= CHARPOS (tlbufpos
)
13003 && PT
<= Z
- CHARPOS (tlendpos
)
13004 /* All text outside that line, including its final newline,
13005 must be unchanged. */
13006 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13007 CHARPOS (tlendpos
)))
13009 if (CHARPOS (tlbufpos
) > BEGV
13010 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13011 && (CHARPOS (tlbufpos
) == ZV
13012 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13013 /* Former continuation line has disappeared by becoming empty. */
13015 else if (XFASTINT (w
->last_modified
) < MODIFF
13016 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
13017 || MINI_WINDOW_P (w
))
13019 /* We have to handle the case of continuation around a
13020 wide-column character (see the comment in indent.c around
13023 For instance, in the following case:
13025 -------- Insert --------
13026 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13027 J_I_ ==> J_I_ `^^' are cursors.
13031 As we have to redraw the line above, we cannot use this
13035 int line_height_before
= this_line_pixel_height
;
13037 /* Note that start_display will handle the case that the
13038 line starting at tlbufpos is a continuation line. */
13039 start_display (&it
, w
, tlbufpos
);
13041 /* Implementation note: It this still necessary? */
13042 if (it
.current_x
!= this_line_start_x
)
13045 TRACE ((stderr
, "trying display optimization 1\n"));
13046 w
->cursor
.vpos
= -1;
13047 overlay_arrow_seen
= 0;
13048 it
.vpos
= this_line_vpos
;
13049 it
.current_y
= this_line_y
;
13050 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13051 display_line (&it
);
13053 /* If line contains point, is not continued,
13054 and ends at same distance from eob as before, we win. */
13055 if (w
->cursor
.vpos
>= 0
13056 /* Line is not continued, otherwise this_line_start_pos
13057 would have been set to 0 in display_line. */
13058 && CHARPOS (this_line_start_pos
)
13059 /* Line ends as before. */
13060 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13061 /* Line has same height as before. Otherwise other lines
13062 would have to be shifted up or down. */
13063 && this_line_pixel_height
== line_height_before
)
13065 /* If this is not the window's last line, we must adjust
13066 the charstarts of the lines below. */
13067 if (it
.current_y
< it
.last_visible_y
)
13069 struct glyph_row
*row
13070 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13071 EMACS_INT delta
, delta_bytes
;
13073 /* We used to distinguish between two cases here,
13074 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13075 when the line ends in a newline or the end of the
13076 buffer's accessible portion. But both cases did
13077 the same, so they were collapsed. */
13079 - CHARPOS (tlendpos
)
13080 - MATRIX_ROW_START_CHARPOS (row
));
13081 delta_bytes
= (Z_BYTE
13082 - BYTEPOS (tlendpos
)
13083 - MATRIX_ROW_START_BYTEPOS (row
));
13085 increment_matrix_positions (w
->current_matrix
,
13086 this_line_vpos
+ 1,
13087 w
->current_matrix
->nrows
,
13088 delta
, delta_bytes
);
13091 /* If this row displays text now but previously didn't,
13092 or vice versa, w->window_end_vpos may have to be
13094 if ((it
.glyph_row
- 1)->displays_text_p
)
13096 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13097 XSETINT (w
->window_end_vpos
, this_line_vpos
);
13099 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13100 && this_line_vpos
> 0)
13101 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
13102 w
->window_end_valid
= Qnil
;
13104 /* Update hint: No need to try to scroll in update_window. */
13105 w
->desired_matrix
->no_scrolling_p
= 1;
13108 *w
->desired_matrix
->method
= 0;
13109 debug_method_add (w
, "optimization 1");
13111 #ifdef HAVE_WINDOW_SYSTEM
13112 update_window_fringes (w
, 0);
13119 else if (/* Cursor position hasn't changed. */
13120 PT
== XFASTINT (w
->last_point
)
13121 /* Make sure the cursor was last displayed
13122 in this window. Otherwise we have to reposition it. */
13123 && 0 <= w
->cursor
.vpos
13124 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13128 do_pending_window_change (1);
13129 /* If selected_window changed, redisplay again. */
13130 if (WINDOWP (selected_window
)
13131 && (w
= XWINDOW (selected_window
)) != sw
)
13134 /* We used to always goto end_of_redisplay here, but this
13135 isn't enough if we have a blinking cursor. */
13136 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13137 goto end_of_redisplay
;
13141 /* If highlighting the region, or if the cursor is in the echo area,
13142 then we can't just move the cursor. */
13143 else if (! (!NILP (Vtransient_mark_mode
)
13144 && !NILP (BVAR (current_buffer
, mark_active
)))
13145 && (EQ (selected_window
,
13146 BVAR (current_buffer
, last_selected_window
))
13147 || highlight_nonselected_windows
)
13148 && NILP (w
->region_showing
)
13149 && NILP (Vshow_trailing_whitespace
)
13150 && !cursor_in_echo_area
)
13153 struct glyph_row
*row
;
13155 /* Skip from tlbufpos to PT and see where it is. Note that
13156 PT may be in invisible text. If so, we will end at the
13157 next visible position. */
13158 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13159 NULL
, DEFAULT_FACE_ID
);
13160 it
.current_x
= this_line_start_x
;
13161 it
.current_y
= this_line_y
;
13162 it
.vpos
= this_line_vpos
;
13164 /* The call to move_it_to stops in front of PT, but
13165 moves over before-strings. */
13166 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13168 if (it
.vpos
== this_line_vpos
13169 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13172 xassert (this_line_vpos
== it
.vpos
);
13173 xassert (this_line_y
== it
.current_y
);
13174 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13176 *w
->desired_matrix
->method
= 0;
13177 debug_method_add (w
, "optimization 3");
13186 /* Text changed drastically or point moved off of line. */
13187 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13190 CHARPOS (this_line_start_pos
) = 0;
13191 consider_all_windows_p
|= buffer_shared
> 1;
13192 ++clear_face_cache_count
;
13193 #ifdef HAVE_WINDOW_SYSTEM
13194 ++clear_image_cache_count
;
13197 /* Build desired matrices, and update the display. If
13198 consider_all_windows_p is non-zero, do it for all windows on all
13199 frames. Otherwise do it for selected_window, only. */
13201 if (consider_all_windows_p
)
13203 Lisp_Object tail
, frame
;
13205 FOR_EACH_FRAME (tail
, frame
)
13206 XFRAME (frame
)->updated_p
= 0;
13208 /* Recompute # windows showing selected buffer. This will be
13209 incremented each time such a window is displayed. */
13212 FOR_EACH_FRAME (tail
, frame
)
13214 struct frame
*f
= XFRAME (frame
);
13216 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13218 if (! EQ (frame
, selected_frame
))
13219 /* Select the frame, for the sake of frame-local
13221 select_frame_for_redisplay (frame
);
13223 /* Mark all the scroll bars to be removed; we'll redeem
13224 the ones we want when we redisplay their windows. */
13225 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13226 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13228 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13229 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13231 /* The X error handler may have deleted that frame. */
13232 if (!FRAME_LIVE_P (f
))
13235 /* Any scroll bars which redisplay_windows should have
13236 nuked should now go away. */
13237 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13238 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13240 /* If fonts changed, display again. */
13241 /* ??? rms: I suspect it is a mistake to jump all the way
13242 back to retry here. It should just retry this frame. */
13243 if (fonts_changed_p
)
13246 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13248 /* See if we have to hscroll. */
13249 if (!f
->already_hscrolled_p
)
13251 f
->already_hscrolled_p
= 1;
13252 if (hscroll_windows (f
->root_window
))
13256 /* Prevent various kinds of signals during display
13257 update. stdio is not robust about handling
13258 signals, which can cause an apparent I/O
13260 if (interrupt_input
)
13261 unrequest_sigio ();
13264 /* Update the display. */
13265 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13266 pending
|= update_frame (f
, 0, 0);
13272 if (!EQ (old_frame
, selected_frame
)
13273 && FRAME_LIVE_P (XFRAME (old_frame
)))
13274 /* We played a bit fast-and-loose above and allowed selected_frame
13275 and selected_window to be temporarily out-of-sync but let's make
13276 sure this stays contained. */
13277 select_frame_for_redisplay (old_frame
);
13278 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13282 /* Do the mark_window_display_accurate after all windows have
13283 been redisplayed because this call resets flags in buffers
13284 which are needed for proper redisplay. */
13285 FOR_EACH_FRAME (tail
, frame
)
13287 struct frame
*f
= XFRAME (frame
);
13290 mark_window_display_accurate (f
->root_window
, 1);
13291 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13292 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13297 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13299 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13300 struct frame
*mini_frame
;
13302 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13303 /* Use list_of_error, not Qerror, so that
13304 we catch only errors and don't run the debugger. */
13305 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13307 redisplay_window_error
);
13308 if (update_miniwindow_p
)
13309 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13311 redisplay_window_error
);
13313 /* Compare desired and current matrices, perform output. */
13316 /* If fonts changed, display again. */
13317 if (fonts_changed_p
)
13320 /* Prevent various kinds of signals during display update.
13321 stdio is not robust about handling signals,
13322 which can cause an apparent I/O error. */
13323 if (interrupt_input
)
13324 unrequest_sigio ();
13327 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13329 if (hscroll_windows (selected_window
))
13332 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13333 pending
= update_frame (sf
, 0, 0);
13336 /* We may have called echo_area_display at the top of this
13337 function. If the echo area is on another frame, that may
13338 have put text on a frame other than the selected one, so the
13339 above call to update_frame would not have caught it. Catch
13341 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13342 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13344 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13346 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13347 pending
|= update_frame (mini_frame
, 0, 0);
13348 if (!pending
&& hscroll_windows (mini_window
))
13353 /* If display was paused because of pending input, make sure we do a
13354 thorough update the next time. */
13357 /* Prevent the optimization at the beginning of
13358 redisplay_internal that tries a single-line update of the
13359 line containing the cursor in the selected window. */
13360 CHARPOS (this_line_start_pos
) = 0;
13362 /* Let the overlay arrow be updated the next time. */
13363 update_overlay_arrows (0);
13365 /* If we pause after scrolling, some rows in the current
13366 matrices of some windows are not valid. */
13367 if (!WINDOW_FULL_WIDTH_P (w
)
13368 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13369 update_mode_lines
= 1;
13373 if (!consider_all_windows_p
)
13375 /* This has already been done above if
13376 consider_all_windows_p is set. */
13377 mark_window_display_accurate_1 (w
, 1);
13379 /* Say overlay arrows are up to date. */
13380 update_overlay_arrows (1);
13382 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13383 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13386 update_mode_lines
= 0;
13387 windows_or_buffers_changed
= 0;
13388 cursor_type_changed
= 0;
13391 /* Start SIGIO interrupts coming again. Having them off during the
13392 code above makes it less likely one will discard output, but not
13393 impossible, since there might be stuff in the system buffer here.
13394 But it is much hairier to try to do anything about that. */
13395 if (interrupt_input
)
13399 /* If a frame has become visible which was not before, redisplay
13400 again, so that we display it. Expose events for such a frame
13401 (which it gets when becoming visible) don't call the parts of
13402 redisplay constructing glyphs, so simply exposing a frame won't
13403 display anything in this case. So, we have to display these
13404 frames here explicitly. */
13407 Lisp_Object tail
, frame
;
13410 FOR_EACH_FRAME (tail
, frame
)
13412 int this_is_visible
= 0;
13414 if (XFRAME (frame
)->visible
)
13415 this_is_visible
= 1;
13416 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13417 if (XFRAME (frame
)->visible
)
13418 this_is_visible
= 1;
13420 if (this_is_visible
)
13424 if (new_count
!= number_of_visible_frames
)
13425 windows_or_buffers_changed
++;
13428 /* Change frame size now if a change is pending. */
13429 do_pending_window_change (1);
13431 /* If we just did a pending size change, or have additional
13432 visible frames, or selected_window changed, redisplay again. */
13433 if ((windows_or_buffers_changed
&& !pending
)
13434 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13437 /* Clear the face and image caches.
13439 We used to do this only if consider_all_windows_p. But the cache
13440 needs to be cleared if a timer creates images in the current
13441 buffer (e.g. the test case in Bug#6230). */
13443 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13445 clear_face_cache (0);
13446 clear_face_cache_count
= 0;
13449 #ifdef HAVE_WINDOW_SYSTEM
13450 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13452 clear_image_caches (Qnil
);
13453 clear_image_cache_count
= 0;
13455 #endif /* HAVE_WINDOW_SYSTEM */
13458 unbind_to (count
, Qnil
);
13463 /* Redisplay, but leave alone any recent echo area message unless
13464 another message has been requested in its place.
13466 This is useful in situations where you need to redisplay but no
13467 user action has occurred, making it inappropriate for the message
13468 area to be cleared. See tracking_off and
13469 wait_reading_process_output for examples of these situations.
13471 FROM_WHERE is an integer saying from where this function was
13472 called. This is useful for debugging. */
13475 redisplay_preserve_echo_area (int from_where
)
13477 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13479 if (!NILP (echo_area_buffer
[1]))
13481 /* We have a previously displayed message, but no current
13482 message. Redisplay the previous message. */
13483 display_last_displayed_message_p
= 1;
13484 redisplay_internal ();
13485 display_last_displayed_message_p
= 0;
13488 redisplay_internal ();
13490 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13491 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13492 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13496 /* Function registered with record_unwind_protect in
13497 redisplay_internal. Reset redisplaying_p to the value it had
13498 before redisplay_internal was called, and clear
13499 prevent_freeing_realized_faces_p. It also selects the previously
13500 selected frame, unless it has been deleted (by an X connection
13501 failure during redisplay, for example). */
13504 unwind_redisplay (Lisp_Object val
)
13506 Lisp_Object old_redisplaying_p
, old_frame
;
13508 old_redisplaying_p
= XCAR (val
);
13509 redisplaying_p
= XFASTINT (old_redisplaying_p
);
13510 old_frame
= XCDR (val
);
13511 if (! EQ (old_frame
, selected_frame
)
13512 && FRAME_LIVE_P (XFRAME (old_frame
)))
13513 select_frame_for_redisplay (old_frame
);
13518 /* Mark the display of window W as accurate or inaccurate. If
13519 ACCURATE_P is non-zero mark display of W as accurate. If
13520 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13521 redisplay_internal is called. */
13524 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13526 if (BUFFERP (w
->buffer
))
13528 struct buffer
*b
= XBUFFER (w
->buffer
);
13531 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
13532 w
->last_overlay_modified
13533 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
13535 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
13539 b
->clip_changed
= 0;
13540 b
->prevent_redisplay_optimizations_p
= 0;
13542 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13543 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13544 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13545 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13547 w
->current_matrix
->buffer
= b
;
13548 w
->current_matrix
->begv
= BUF_BEGV (b
);
13549 w
->current_matrix
->zv
= BUF_ZV (b
);
13551 w
->last_cursor
= w
->cursor
;
13552 w
->last_cursor_off_p
= w
->cursor_off_p
;
13554 if (w
== XWINDOW (selected_window
))
13555 w
->last_point
= make_number (BUF_PT (b
));
13557 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
13563 w
->window_end_valid
= w
->buffer
;
13564 w
->update_mode_line
= Qnil
;
13569 /* Mark the display of windows in the window tree rooted at WINDOW as
13570 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13571 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13572 be redisplayed the next time redisplay_internal is called. */
13575 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13579 for (; !NILP (window
); window
= w
->next
)
13581 w
= XWINDOW (window
);
13582 mark_window_display_accurate_1 (w
, accurate_p
);
13584 if (!NILP (w
->vchild
))
13585 mark_window_display_accurate (w
->vchild
, accurate_p
);
13586 if (!NILP (w
->hchild
))
13587 mark_window_display_accurate (w
->hchild
, accurate_p
);
13592 update_overlay_arrows (1);
13596 /* Force a thorough redisplay the next time by setting
13597 last_arrow_position and last_arrow_string to t, which is
13598 unequal to any useful value of Voverlay_arrow_... */
13599 update_overlay_arrows (-1);
13604 /* Return value in display table DP (Lisp_Char_Table *) for character
13605 C. Since a display table doesn't have any parent, we don't have to
13606 follow parent. Do not call this function directly but use the
13607 macro DISP_CHAR_VECTOR. */
13610 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13614 if (ASCII_CHAR_P (c
))
13617 if (SUB_CHAR_TABLE_P (val
))
13618 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13624 XSETCHAR_TABLE (table
, dp
);
13625 val
= char_table_ref (table
, c
);
13634 /***********************************************************************
13636 ***********************************************************************/
13638 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13641 redisplay_windows (Lisp_Object window
)
13643 while (!NILP (window
))
13645 struct window
*w
= XWINDOW (window
);
13647 if (!NILP (w
->hchild
))
13648 redisplay_windows (w
->hchild
);
13649 else if (!NILP (w
->vchild
))
13650 redisplay_windows (w
->vchild
);
13651 else if (!NILP (w
->buffer
))
13653 displayed_buffer
= XBUFFER (w
->buffer
);
13654 /* Use list_of_error, not Qerror, so that
13655 we catch only errors and don't run the debugger. */
13656 internal_condition_case_1 (redisplay_window_0
, window
,
13658 redisplay_window_error
);
13666 redisplay_window_error (Lisp_Object ignore
)
13668 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13673 redisplay_window_0 (Lisp_Object window
)
13675 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13676 redisplay_window (window
, 0);
13681 redisplay_window_1 (Lisp_Object window
)
13683 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13684 redisplay_window (window
, 1);
13689 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13690 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13691 which positions recorded in ROW differ from current buffer
13694 Return 0 if cursor is not on this row, 1 otherwise. */
13697 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13698 struct glyph_matrix
*matrix
,
13699 EMACS_INT delta
, EMACS_INT delta_bytes
,
13702 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13703 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13704 struct glyph
*cursor
= NULL
;
13705 /* The last known character position in row. */
13706 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13708 EMACS_INT pt_old
= PT
- delta
;
13709 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13710 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13711 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13712 /* A glyph beyond the edge of TEXT_AREA which we should never
13714 struct glyph
*glyphs_end
= end
;
13715 /* Non-zero means we've found a match for cursor position, but that
13716 glyph has the avoid_cursor_p flag set. */
13717 int match_with_avoid_cursor
= 0;
13718 /* Non-zero means we've seen at least one glyph that came from a
13720 int string_seen
= 0;
13721 /* Largest and smallest buffer positions seen so far during scan of
13723 EMACS_INT bpos_max
= pos_before
;
13724 EMACS_INT bpos_min
= pos_after
;
13725 /* Last buffer position covered by an overlay string with an integer
13726 `cursor' property. */
13727 EMACS_INT bpos_covered
= 0;
13728 /* Non-zero means the display string on which to display the cursor
13729 comes from a text property, not from an overlay. */
13730 int string_from_text_prop
= 0;
13732 /* Don't even try doing anything if called for a mode-line or
13733 header-line row, since the rest of the code isn't prepared to
13734 deal with such calamities. */
13735 xassert (!row
->mode_line_p
);
13736 if (row
->mode_line_p
)
13739 /* Skip over glyphs not having an object at the start and the end of
13740 the row. These are special glyphs like truncation marks on
13741 terminal frames. */
13742 if (row
->displays_text_p
)
13744 if (!row
->reversed_p
)
13747 && INTEGERP (glyph
->object
)
13748 && glyph
->charpos
< 0)
13750 x
+= glyph
->pixel_width
;
13754 && INTEGERP ((end
- 1)->object
)
13755 /* CHARPOS is zero for blanks and stretch glyphs
13756 inserted by extend_face_to_end_of_line. */
13757 && (end
- 1)->charpos
<= 0)
13759 glyph_before
= glyph
- 1;
13766 /* If the glyph row is reversed, we need to process it from back
13767 to front, so swap the edge pointers. */
13768 glyphs_end
= end
= glyph
- 1;
13769 glyph
+= row
->used
[TEXT_AREA
] - 1;
13771 while (glyph
> end
+ 1
13772 && INTEGERP (glyph
->object
)
13773 && glyph
->charpos
< 0)
13776 x
-= glyph
->pixel_width
;
13778 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13780 /* By default, in reversed rows we put the cursor on the
13781 rightmost (first in the reading order) glyph. */
13782 for (g
= end
+ 1; g
< glyph
; g
++)
13783 x
+= g
->pixel_width
;
13785 && INTEGERP ((end
+ 1)->object
)
13786 && (end
+ 1)->charpos
<= 0)
13788 glyph_before
= glyph
+ 1;
13792 else if (row
->reversed_p
)
13794 /* In R2L rows that don't display text, put the cursor on the
13795 rightmost glyph. Case in point: an empty last line that is
13796 part of an R2L paragraph. */
13798 /* Avoid placing the cursor on the last glyph of the row, where
13799 on terminal frames we hold the vertical border between
13800 adjacent windows. */
13801 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13802 && !WINDOW_RIGHTMOST_P (w
)
13803 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13805 x
= -1; /* will be computed below, at label compute_x */
13808 /* Step 1: Try to find the glyph whose character position
13809 corresponds to point. If that's not possible, find 2 glyphs
13810 whose character positions are the closest to point, one before
13811 point, the other after it. */
13812 if (!row
->reversed_p
)
13813 while (/* not marched to end of glyph row */
13815 /* glyph was not inserted by redisplay for internal purposes */
13816 && !INTEGERP (glyph
->object
))
13818 if (BUFFERP (glyph
->object
))
13820 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13822 if (glyph
->charpos
> bpos_max
)
13823 bpos_max
= glyph
->charpos
;
13824 if (glyph
->charpos
< bpos_min
)
13825 bpos_min
= glyph
->charpos
;
13826 if (!glyph
->avoid_cursor_p
)
13828 /* If we hit point, we've found the glyph on which to
13829 display the cursor. */
13832 match_with_avoid_cursor
= 0;
13835 /* See if we've found a better approximation to
13836 POS_BEFORE or to POS_AFTER. Note that we want the
13837 first (leftmost) glyph of all those that are the
13838 closest from below, and the last (rightmost) of all
13839 those from above. */
13840 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13842 pos_before
= glyph
->charpos
;
13843 glyph_before
= glyph
;
13845 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13847 pos_after
= glyph
->charpos
;
13848 glyph_after
= glyph
;
13851 else if (dpos
== 0)
13852 match_with_avoid_cursor
= 1;
13854 else if (STRINGP (glyph
->object
))
13856 Lisp_Object chprop
;
13857 EMACS_INT glyph_pos
= glyph
->charpos
;
13859 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13861 if (!NILP (chprop
))
13863 /* If the string came from a `display' text property,
13864 look up the buffer position of that property and
13865 use that position to update bpos_max, as if we
13866 actually saw such a position in one of the row's
13867 glyphs. This helps with supporting integer values
13868 of `cursor' property on the display string in
13869 situations where most or all of the row's buffer
13870 text is completely covered by display properties,
13871 so that no glyph with valid buffer positions is
13872 ever seen in the row. */
13873 EMACS_INT prop_pos
=
13874 string_buffer_position_lim (glyph
->object
, pos_before
,
13877 if (prop_pos
>= pos_before
)
13878 bpos_max
= prop_pos
- 1;
13880 if (INTEGERP (chprop
))
13882 bpos_covered
= bpos_max
+ XINT (chprop
);
13883 /* If the `cursor' property covers buffer positions up
13884 to and including point, we should display cursor on
13885 this glyph. Note that, if a `cursor' property on one
13886 of the string's characters has an integer value, we
13887 will break out of the loop below _before_ we get to
13888 the position match above. IOW, integer values of
13889 the `cursor' property override the "exact match for
13890 point" strategy of positioning the cursor. */
13891 /* Implementation note: bpos_max == pt_old when, e.g.,
13892 we are in an empty line, where bpos_max is set to
13893 MATRIX_ROW_START_CHARPOS, see above. */
13894 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13903 x
+= glyph
->pixel_width
;
13906 else if (glyph
> end
) /* row is reversed */
13907 while (!INTEGERP (glyph
->object
))
13909 if (BUFFERP (glyph
->object
))
13911 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13913 if (glyph
->charpos
> bpos_max
)
13914 bpos_max
= glyph
->charpos
;
13915 if (glyph
->charpos
< bpos_min
)
13916 bpos_min
= glyph
->charpos
;
13917 if (!glyph
->avoid_cursor_p
)
13921 match_with_avoid_cursor
= 0;
13924 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13926 pos_before
= glyph
->charpos
;
13927 glyph_before
= glyph
;
13929 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13931 pos_after
= glyph
->charpos
;
13932 glyph_after
= glyph
;
13935 else if (dpos
== 0)
13936 match_with_avoid_cursor
= 1;
13938 else if (STRINGP (glyph
->object
))
13940 Lisp_Object chprop
;
13941 EMACS_INT glyph_pos
= glyph
->charpos
;
13943 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13945 if (!NILP (chprop
))
13947 EMACS_INT prop_pos
=
13948 string_buffer_position_lim (glyph
->object
, pos_before
,
13951 if (prop_pos
>= pos_before
)
13952 bpos_max
= prop_pos
- 1;
13954 if (INTEGERP (chprop
))
13956 bpos_covered
= bpos_max
+ XINT (chprop
);
13957 /* If the `cursor' property covers buffer positions up
13958 to and including point, we should display cursor on
13960 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13969 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13971 x
--; /* can't use any pixel_width */
13974 x
-= glyph
->pixel_width
;
13977 /* Step 2: If we didn't find an exact match for point, we need to
13978 look for a proper place to put the cursor among glyphs between
13979 GLYPH_BEFORE and GLYPH_AFTER. */
13980 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13981 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13982 && bpos_covered
< pt_old
)
13984 /* An empty line has a single glyph whose OBJECT is zero and
13985 whose CHARPOS is the position of a newline on that line.
13986 Note that on a TTY, there are more glyphs after that, which
13987 were produced by extend_face_to_end_of_line, but their
13988 CHARPOS is zero or negative. */
13990 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13991 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13993 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13995 EMACS_INT ellipsis_pos
;
13997 /* Scan back over the ellipsis glyphs. */
13998 if (!row
->reversed_p
)
14000 ellipsis_pos
= (glyph
- 1)->charpos
;
14001 while (glyph
> row
->glyphs
[TEXT_AREA
]
14002 && (glyph
- 1)->charpos
== ellipsis_pos
)
14003 glyph
--, x
-= glyph
->pixel_width
;
14004 /* That loop always goes one position too far, including
14005 the glyph before the ellipsis. So scan forward over
14007 x
+= glyph
->pixel_width
;
14010 else /* row is reversed */
14012 ellipsis_pos
= (glyph
+ 1)->charpos
;
14013 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14014 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14015 glyph
++, x
+= glyph
->pixel_width
;
14016 x
-= glyph
->pixel_width
;
14020 else if (match_with_avoid_cursor
)
14022 cursor
= glyph_after
;
14025 else if (string_seen
)
14027 int incr
= row
->reversed_p
? -1 : +1;
14029 /* Need to find the glyph that came out of a string which is
14030 present at point. That glyph is somewhere between
14031 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14032 positioned between POS_BEFORE and POS_AFTER in the
14034 struct glyph
*start
, *stop
;
14035 EMACS_INT pos
= pos_before
;
14039 /* If the row ends in a newline from a display string,
14040 reordering could have moved the glyphs belonging to the
14041 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14042 in this case we extend the search to the last glyph in
14043 the row that was not inserted by redisplay. */
14044 if (row
->ends_in_newline_from_string_p
)
14047 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14050 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14051 correspond to POS_BEFORE and POS_AFTER, respectively. We
14052 need START and STOP in the order that corresponds to the
14053 row's direction as given by its reversed_p flag. If the
14054 directionality of characters between POS_BEFORE and
14055 POS_AFTER is the opposite of the row's base direction,
14056 these characters will have been reordered for display,
14057 and we need to reverse START and STOP. */
14058 if (!row
->reversed_p
)
14060 start
= min (glyph_before
, glyph_after
);
14061 stop
= max (glyph_before
, glyph_after
);
14065 start
= max (glyph_before
, glyph_after
);
14066 stop
= min (glyph_before
, glyph_after
);
14068 for (glyph
= start
+ incr
;
14069 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14072 /* Any glyphs that come from the buffer are here because
14073 of bidi reordering. Skip them, and only pay
14074 attention to glyphs that came from some string. */
14075 if (STRINGP (glyph
->object
))
14079 /* If the display property covers the newline, we
14080 need to search for it one position farther. */
14081 EMACS_INT lim
= pos_after
14082 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14084 string_from_text_prop
= 0;
14085 str
= glyph
->object
;
14086 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14087 if (tem
== 0 /* from overlay */
14090 /* If the string from which this glyph came is
14091 found in the buffer at point, or at position
14092 that is closer to point than pos_after, then
14093 we've found the glyph we've been looking for.
14094 If it comes from an overlay (tem == 0), and
14095 it has the `cursor' property on one of its
14096 glyphs, record that glyph as a candidate for
14097 displaying the cursor. (As in the
14098 unidirectional version, we will display the
14099 cursor on the last candidate we find.) */
14102 || (tem
- pt_old
> 0 && tem
< pos_after
))
14104 /* The glyphs from this string could have
14105 been reordered. Find the one with the
14106 smallest string position. Or there could
14107 be a character in the string with the
14108 `cursor' property, which means display
14109 cursor on that character's glyph. */
14110 EMACS_INT strpos
= glyph
->charpos
;
14115 string_from_text_prop
= 1;
14118 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14119 && EQ (glyph
->object
, str
);
14123 EMACS_INT gpos
= glyph
->charpos
;
14125 cprop
= Fget_char_property (make_number (gpos
),
14133 if (tem
&& glyph
->charpos
< strpos
)
14135 strpos
= glyph
->charpos
;
14141 || (tem
- pt_old
> 0 && tem
< pos_after
))
14145 pos
= tem
+ 1; /* don't find previous instances */
14147 /* This string is not what we want; skip all of the
14148 glyphs that came from it. */
14149 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14150 && EQ (glyph
->object
, str
))
14157 /* If we reached the end of the line, and END was from a string,
14158 the cursor is not on this line. */
14160 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14161 && STRINGP (end
->object
)
14162 && row
->continued_p
)
14165 /* A truncated row may not include PT among its character positions.
14166 Setting the cursor inside the scroll margin will trigger
14167 recalculation of hscroll in hscroll_window_tree. But if a
14168 display string covers point, defer to the string-handling
14169 code below to figure this out. */
14170 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14172 cursor
= glyph_before
;
14175 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14176 /* Zero-width characters produce no glyphs. */
14178 && (row
->reversed_p
14179 ? glyph_after
> glyphs_end
14180 : glyph_after
< glyphs_end
)))
14182 cursor
= glyph_after
;
14188 if (cursor
!= NULL
)
14194 /* Need to compute x that corresponds to GLYPH. */
14195 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14197 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14199 x
+= g
->pixel_width
;
14203 /* ROW could be part of a continued line, which, under bidi
14204 reordering, might have other rows whose start and end charpos
14205 occlude point. Only set w->cursor if we found a better
14206 approximation to the cursor position than we have from previously
14207 examined candidate rows belonging to the same continued line. */
14208 if (/* we already have a candidate row */
14209 w
->cursor
.vpos
>= 0
14210 /* that candidate is not the row we are processing */
14211 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14212 /* Make sure cursor.vpos specifies a row whose start and end
14213 charpos occlude point, and it is valid candidate for being a
14214 cursor-row. This is because some callers of this function
14215 leave cursor.vpos at the row where the cursor was displayed
14216 during the last redisplay cycle. */
14217 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14218 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14219 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14222 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14224 /* Don't consider glyphs that are outside TEXT_AREA. */
14225 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14227 /* Keep the candidate whose buffer position is the closest to
14228 point or has the `cursor' property. */
14229 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14230 w
->cursor
.hpos
>= 0
14231 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14232 && ((BUFFERP (g1
->object
)
14233 && (g1
->charpos
== pt_old
/* an exact match always wins */
14234 || (BUFFERP (glyph
->object
)
14235 && eabs (g1
->charpos
- pt_old
)
14236 < eabs (glyph
->charpos
- pt_old
))))
14237 /* previous candidate is a glyph from a string that has
14238 a non-nil `cursor' property */
14239 || (STRINGP (g1
->object
)
14240 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14241 Qcursor
, g1
->object
))
14242 /* previous candidate is from the same display
14243 string as this one, and the display string
14244 came from a text property */
14245 || (EQ (g1
->object
, glyph
->object
)
14246 && string_from_text_prop
)
14247 /* this candidate is from newline and its
14248 position is not an exact match */
14249 || (INTEGERP (glyph
->object
)
14250 && glyph
->charpos
!= pt_old
)))))
14252 /* If this candidate gives an exact match, use that. */
14253 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14254 /* If this candidate is a glyph created for the
14255 terminating newline of a line, and point is on that
14256 newline, it wins because it's an exact match. */
14257 || (!row
->continued_p
14258 && INTEGERP (glyph
->object
)
14259 && glyph
->charpos
== 0
14260 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14261 /* Otherwise, keep the candidate that comes from a row
14262 spanning less buffer positions. This may win when one or
14263 both candidate positions are on glyphs that came from
14264 display strings, for which we cannot compare buffer
14266 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14267 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14268 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14271 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14273 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14274 w
->cursor
.y
= row
->y
+ dy
;
14276 if (w
== XWINDOW (selected_window
))
14278 if (!row
->continued_p
14279 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14282 this_line_buffer
= XBUFFER (w
->buffer
);
14284 CHARPOS (this_line_start_pos
)
14285 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14286 BYTEPOS (this_line_start_pos
)
14287 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14289 CHARPOS (this_line_end_pos
)
14290 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14291 BYTEPOS (this_line_end_pos
)
14292 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14294 this_line_y
= w
->cursor
.y
;
14295 this_line_pixel_height
= row
->height
;
14296 this_line_vpos
= w
->cursor
.vpos
;
14297 this_line_start_x
= row
->x
;
14300 CHARPOS (this_line_start_pos
) = 0;
14307 /* Run window scroll functions, if any, for WINDOW with new window
14308 start STARTP. Sets the window start of WINDOW to that position.
14310 We assume that the window's buffer is really current. */
14312 static inline struct text_pos
14313 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14315 struct window
*w
= XWINDOW (window
);
14316 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14318 if (current_buffer
!= XBUFFER (w
->buffer
))
14321 if (!NILP (Vwindow_scroll_functions
))
14323 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14324 make_number (CHARPOS (startp
)));
14325 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14326 /* In case the hook functions switch buffers. */
14327 if (current_buffer
!= XBUFFER (w
->buffer
))
14328 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14335 /* Make sure the line containing the cursor is fully visible.
14336 A value of 1 means there is nothing to be done.
14337 (Either the line is fully visible, or it cannot be made so,
14338 or we cannot tell.)
14340 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14341 is higher than window.
14343 A value of 0 means the caller should do scrolling
14344 as if point had gone off the screen. */
14347 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14349 struct glyph_matrix
*matrix
;
14350 struct glyph_row
*row
;
14353 if (!make_cursor_line_fully_visible_p
)
14356 /* It's not always possible to find the cursor, e.g, when a window
14357 is full of overlay strings. Don't do anything in that case. */
14358 if (w
->cursor
.vpos
< 0)
14361 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14362 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14364 /* If the cursor row is not partially visible, there's nothing to do. */
14365 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14368 /* If the row the cursor is in is taller than the window's height,
14369 it's not clear what to do, so do nothing. */
14370 window_height
= window_box_height (w
);
14371 if (row
->height
>= window_height
)
14373 if (!force_p
|| MINI_WINDOW_P (w
)
14374 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14381 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14382 non-zero means only WINDOW is redisplayed in redisplay_internal.
14383 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14384 in redisplay_window to bring a partially visible line into view in
14385 the case that only the cursor has moved.
14387 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14388 last screen line's vertical height extends past the end of the screen.
14392 1 if scrolling succeeded
14394 0 if scrolling didn't find point.
14396 -1 if new fonts have been loaded so that we must interrupt
14397 redisplay, adjust glyph matrices, and try again. */
14403 SCROLLING_NEED_LARGER_MATRICES
14406 /* If scroll-conservatively is more than this, never recenter.
14408 If you change this, don't forget to update the doc string of
14409 `scroll-conservatively' and the Emacs manual. */
14410 #define SCROLL_LIMIT 100
14413 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14414 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
14415 int temp_scroll_step
, int last_line_misfit
)
14417 struct window
*w
= XWINDOW (window
);
14418 struct frame
*f
= XFRAME (w
->frame
);
14419 struct text_pos pos
, startp
;
14421 int this_scroll_margin
, scroll_max
, rc
, height
;
14422 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14423 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14424 Lisp_Object aggressive
;
14425 /* We will never try scrolling more than this number of lines. */
14426 int scroll_limit
= SCROLL_LIMIT
;
14429 debug_method_add (w
, "try_scrolling");
14432 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14434 /* Compute scroll margin height in pixels. We scroll when point is
14435 within this distance from the top or bottom of the window. */
14436 if (scroll_margin
> 0)
14437 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14438 * FRAME_LINE_HEIGHT (f
);
14440 this_scroll_margin
= 0;
14442 /* Force arg_scroll_conservatively to have a reasonable value, to
14443 avoid scrolling too far away with slow move_it_* functions. Note
14444 that the user can supply scroll-conservatively equal to
14445 `most-positive-fixnum', which can be larger than INT_MAX. */
14446 if (arg_scroll_conservatively
> scroll_limit
)
14448 arg_scroll_conservatively
= scroll_limit
+ 1;
14449 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14451 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14452 /* Compute how much we should try to scroll maximally to bring
14453 point into view. */
14454 scroll_max
= (max (scroll_step
,
14455 max (arg_scroll_conservatively
, temp_scroll_step
))
14456 * FRAME_LINE_HEIGHT (f
));
14457 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14458 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14459 /* We're trying to scroll because of aggressive scrolling but no
14460 scroll_step is set. Choose an arbitrary one. */
14461 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14467 /* Decide whether to scroll down. */
14468 if (PT
> CHARPOS (startp
))
14470 int scroll_margin_y
;
14472 /* Compute the pixel ypos of the scroll margin, then move IT to
14473 either that ypos or PT, whichever comes first. */
14474 start_display (&it
, w
, startp
);
14475 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14476 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14477 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14478 (MOVE_TO_POS
| MOVE_TO_Y
));
14480 if (PT
> CHARPOS (it
.current
.pos
))
14482 int y0
= line_bottom_y (&it
);
14483 /* Compute how many pixels below window bottom to stop searching
14484 for PT. This avoids costly search for PT that is far away if
14485 the user limited scrolling by a small number of lines, but
14486 always finds PT if scroll_conservatively is set to a large
14487 number, such as most-positive-fixnum. */
14488 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14489 int y_to_move
= it
.last_visible_y
+ slack
;
14491 /* Compute the distance from the scroll margin to PT or to
14492 the scroll limit, whichever comes first. This should
14493 include the height of the cursor line, to make that line
14495 move_it_to (&it
, PT
, -1, y_to_move
,
14496 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14497 dy
= line_bottom_y (&it
) - y0
;
14499 if (dy
> scroll_max
)
14500 return SCROLLING_FAILED
;
14509 /* Point is in or below the bottom scroll margin, so move the
14510 window start down. If scrolling conservatively, move it just
14511 enough down to make point visible. If scroll_step is set,
14512 move it down by scroll_step. */
14513 if (arg_scroll_conservatively
)
14515 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14516 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14517 else if (scroll_step
|| temp_scroll_step
)
14518 amount_to_scroll
= scroll_max
;
14521 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14522 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14523 if (NUMBERP (aggressive
))
14525 double float_amount
= XFLOATINT (aggressive
) * height
;
14526 amount_to_scroll
= float_amount
;
14527 if (amount_to_scroll
== 0 && float_amount
> 0)
14528 amount_to_scroll
= 1;
14529 /* Don't let point enter the scroll margin near top of
14531 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14532 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14536 if (amount_to_scroll
<= 0)
14537 return SCROLLING_FAILED
;
14539 start_display (&it
, w
, startp
);
14540 if (arg_scroll_conservatively
<= scroll_limit
)
14541 move_it_vertically (&it
, amount_to_scroll
);
14544 /* Extra precision for users who set scroll-conservatively
14545 to a large number: make sure the amount we scroll
14546 the window start is never less than amount_to_scroll,
14547 which was computed as distance from window bottom to
14548 point. This matters when lines at window top and lines
14549 below window bottom have different height. */
14551 void *it1data
= NULL
;
14552 /* We use a temporary it1 because line_bottom_y can modify
14553 its argument, if it moves one line down; see there. */
14556 SAVE_IT (it1
, it
, it1data
);
14557 start_y
= line_bottom_y (&it1
);
14559 RESTORE_IT (&it
, &it
, it1data
);
14560 move_it_by_lines (&it
, 1);
14561 SAVE_IT (it1
, it
, it1data
);
14562 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14565 /* If STARTP is unchanged, move it down another screen line. */
14566 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14567 move_it_by_lines (&it
, 1);
14568 startp
= it
.current
.pos
;
14572 struct text_pos scroll_margin_pos
= startp
;
14574 /* See if point is inside the scroll margin at the top of the
14576 if (this_scroll_margin
)
14578 start_display (&it
, w
, startp
);
14579 move_it_vertically (&it
, this_scroll_margin
);
14580 scroll_margin_pos
= it
.current
.pos
;
14583 if (PT
< CHARPOS (scroll_margin_pos
))
14585 /* Point is in the scroll margin at the top of the window or
14586 above what is displayed in the window. */
14589 /* Compute the vertical distance from PT to the scroll
14590 margin position. Move as far as scroll_max allows, or
14591 one screenful, or 10 screen lines, whichever is largest.
14592 Give up if distance is greater than scroll_max. */
14593 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14594 start_display (&it
, w
, pos
);
14596 y_to_move
= max (it
.last_visible_y
,
14597 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14598 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14600 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14601 dy
= it
.current_y
- y0
;
14602 if (dy
> scroll_max
)
14603 return SCROLLING_FAILED
;
14605 /* Compute new window start. */
14606 start_display (&it
, w
, startp
);
14608 if (arg_scroll_conservatively
)
14609 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14610 max (scroll_step
, temp_scroll_step
));
14611 else if (scroll_step
|| temp_scroll_step
)
14612 amount_to_scroll
= scroll_max
;
14615 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14616 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14617 if (NUMBERP (aggressive
))
14619 double float_amount
= XFLOATINT (aggressive
) * height
;
14620 amount_to_scroll
= float_amount
;
14621 if (amount_to_scroll
== 0 && float_amount
> 0)
14622 amount_to_scroll
= 1;
14623 amount_to_scroll
-=
14624 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14625 /* Don't let point enter the scroll margin near
14626 bottom of the window. */
14627 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14628 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14632 if (amount_to_scroll
<= 0)
14633 return SCROLLING_FAILED
;
14635 move_it_vertically_backward (&it
, amount_to_scroll
);
14636 startp
= it
.current
.pos
;
14640 /* Run window scroll functions. */
14641 startp
= run_window_scroll_functions (window
, startp
);
14643 /* Display the window. Give up if new fonts are loaded, or if point
14645 if (!try_window (window
, startp
, 0))
14646 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14647 else if (w
->cursor
.vpos
< 0)
14649 clear_glyph_matrix (w
->desired_matrix
);
14650 rc
= SCROLLING_FAILED
;
14654 /* Maybe forget recorded base line for line number display. */
14655 if (!just_this_one_p
14656 || current_buffer
->clip_changed
14657 || BEG_UNCHANGED
< CHARPOS (startp
))
14658 w
->base_line_number
= Qnil
;
14660 /* If cursor ends up on a partially visible line,
14661 treat that as being off the bottom of the screen. */
14662 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14663 /* It's possible that the cursor is on the first line of the
14664 buffer, which is partially obscured due to a vscroll
14665 (Bug#7537). In that case, avoid looping forever . */
14666 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14668 clear_glyph_matrix (w
->desired_matrix
);
14669 ++extra_scroll_margin_lines
;
14672 rc
= SCROLLING_SUCCESS
;
14679 /* Compute a suitable window start for window W if display of W starts
14680 on a continuation line. Value is non-zero if a new window start
14683 The new window start will be computed, based on W's width, starting
14684 from the start of the continued line. It is the start of the
14685 screen line with the minimum distance from the old start W->start. */
14688 compute_window_start_on_continuation_line (struct window
*w
)
14690 struct text_pos pos
, start_pos
;
14691 int window_start_changed_p
= 0;
14693 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14695 /* If window start is on a continuation line... Window start may be
14696 < BEGV in case there's invisible text at the start of the
14697 buffer (M-x rmail, for example). */
14698 if (CHARPOS (start_pos
) > BEGV
14699 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14702 struct glyph_row
*row
;
14704 /* Handle the case that the window start is out of range. */
14705 if (CHARPOS (start_pos
) < BEGV
)
14706 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14707 else if (CHARPOS (start_pos
) > ZV
)
14708 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14710 /* Find the start of the continued line. This should be fast
14711 because scan_buffer is fast (newline cache). */
14712 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14713 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14714 row
, DEFAULT_FACE_ID
);
14715 reseat_at_previous_visible_line_start (&it
);
14717 /* If the line start is "too far" away from the window start,
14718 say it takes too much time to compute a new window start. */
14719 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14720 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14722 int min_distance
, distance
;
14724 /* Move forward by display lines to find the new window
14725 start. If window width was enlarged, the new start can
14726 be expected to be > the old start. If window width was
14727 decreased, the new window start will be < the old start.
14728 So, we're looking for the display line start with the
14729 minimum distance from the old window start. */
14730 pos
= it
.current
.pos
;
14731 min_distance
= INFINITY
;
14732 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14733 distance
< min_distance
)
14735 min_distance
= distance
;
14736 pos
= it
.current
.pos
;
14737 move_it_by_lines (&it
, 1);
14740 /* Set the window start there. */
14741 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14742 window_start_changed_p
= 1;
14746 return window_start_changed_p
;
14750 /* Try cursor movement in case text has not changed in window WINDOW,
14751 with window start STARTP. Value is
14753 CURSOR_MOVEMENT_SUCCESS if successful
14755 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14757 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14758 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14759 we want to scroll as if scroll-step were set to 1. See the code.
14761 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14762 which case we have to abort this redisplay, and adjust matrices
14767 CURSOR_MOVEMENT_SUCCESS
,
14768 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14769 CURSOR_MOVEMENT_MUST_SCROLL
,
14770 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14774 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14776 struct window
*w
= XWINDOW (window
);
14777 struct frame
*f
= XFRAME (w
->frame
);
14778 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14781 if (inhibit_try_cursor_movement
)
14785 /* Handle case where text has not changed, only point, and it has
14786 not moved off the frame. */
14787 if (/* Point may be in this window. */
14788 PT
>= CHARPOS (startp
)
14789 /* Selective display hasn't changed. */
14790 && !current_buffer
->clip_changed
14791 /* Function force-mode-line-update is used to force a thorough
14792 redisplay. It sets either windows_or_buffers_changed or
14793 update_mode_lines. So don't take a shortcut here for these
14795 && !update_mode_lines
14796 && !windows_or_buffers_changed
14797 && !cursor_type_changed
14798 /* Can't use this case if highlighting a region. When a
14799 region exists, cursor movement has to do more than just
14801 && !(!NILP (Vtransient_mark_mode
)
14802 && !NILP (BVAR (current_buffer
, mark_active
)))
14803 && NILP (w
->region_showing
)
14804 && NILP (Vshow_trailing_whitespace
)
14805 /* Right after splitting windows, last_point may be nil. */
14806 && INTEGERP (w
->last_point
)
14807 /* This code is not used for mini-buffer for the sake of the case
14808 of redisplaying to replace an echo area message; since in
14809 that case the mini-buffer contents per se are usually
14810 unchanged. This code is of no real use in the mini-buffer
14811 since the handling of this_line_start_pos, etc., in redisplay
14812 handles the same cases. */
14813 && !EQ (window
, minibuf_window
)
14814 /* When splitting windows or for new windows, it happens that
14815 redisplay is called with a nil window_end_vpos or one being
14816 larger than the window. This should really be fixed in
14817 window.c. I don't have this on my list, now, so we do
14818 approximately the same as the old redisplay code. --gerd. */
14819 && INTEGERP (w
->window_end_vpos
)
14820 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14821 && (FRAME_WINDOW_P (f
)
14822 || !overlay_arrow_in_current_buffer_p ()))
14824 int this_scroll_margin
, top_scroll_margin
;
14825 struct glyph_row
*row
= NULL
;
14828 debug_method_add (w
, "cursor movement");
14831 /* Scroll if point within this distance from the top or bottom
14832 of the window. This is a pixel value. */
14833 if (scroll_margin
> 0)
14835 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14836 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14839 this_scroll_margin
= 0;
14841 top_scroll_margin
= this_scroll_margin
;
14842 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14843 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14845 /* Start with the row the cursor was displayed during the last
14846 not paused redisplay. Give up if that row is not valid. */
14847 if (w
->last_cursor
.vpos
< 0
14848 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14849 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14852 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14853 if (row
->mode_line_p
)
14855 if (!row
->enabled_p
)
14856 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14859 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14861 int scroll_p
= 0, must_scroll
= 0;
14862 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14864 if (PT
> XFASTINT (w
->last_point
))
14866 /* Point has moved forward. */
14867 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14868 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14870 xassert (row
->enabled_p
);
14874 /* If the end position of a row equals the start
14875 position of the next row, and PT is at that position,
14876 we would rather display cursor in the next line. */
14877 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14878 && MATRIX_ROW_END_CHARPOS (row
) == PT
14879 && row
< w
->current_matrix
->rows
14880 + w
->current_matrix
->nrows
- 1
14881 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14882 && !cursor_row_p (row
))
14885 /* If within the scroll margin, scroll. Note that
14886 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14887 the next line would be drawn, and that
14888 this_scroll_margin can be zero. */
14889 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14890 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14891 /* Line is completely visible last line in window
14892 and PT is to be set in the next line. */
14893 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14894 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14895 && !row
->ends_at_zv_p
14896 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14899 else if (PT
< XFASTINT (w
->last_point
))
14901 /* Cursor has to be moved backward. Note that PT >=
14902 CHARPOS (startp) because of the outer if-statement. */
14903 while (!row
->mode_line_p
14904 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14905 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14906 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14907 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14908 row
> w
->current_matrix
->rows
14909 && (row
-1)->ends_in_newline_from_string_p
))))
14910 && (row
->y
> top_scroll_margin
14911 || CHARPOS (startp
) == BEGV
))
14913 xassert (row
->enabled_p
);
14917 /* Consider the following case: Window starts at BEGV,
14918 there is invisible, intangible text at BEGV, so that
14919 display starts at some point START > BEGV. It can
14920 happen that we are called with PT somewhere between
14921 BEGV and START. Try to handle that case. */
14922 if (row
< w
->current_matrix
->rows
14923 || row
->mode_line_p
)
14925 row
= w
->current_matrix
->rows
;
14926 if (row
->mode_line_p
)
14930 /* Due to newlines in overlay strings, we may have to
14931 skip forward over overlay strings. */
14932 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14933 && MATRIX_ROW_END_CHARPOS (row
) == PT
14934 && !cursor_row_p (row
))
14937 /* If within the scroll margin, scroll. */
14938 if (row
->y
< top_scroll_margin
14939 && CHARPOS (startp
) != BEGV
)
14944 /* Cursor did not move. So don't scroll even if cursor line
14945 is partially visible, as it was so before. */
14946 rc
= CURSOR_MOVEMENT_SUCCESS
;
14949 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14950 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14952 /* if PT is not in the glyph row, give up. */
14953 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14956 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14957 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14959 struct glyph_row
*row1
;
14961 /* If rows are bidi-reordered and point moved, back up
14962 until we find a row that does not belong to a
14963 continuation line. This is because we must consider
14964 all rows of a continued line as candidates for the
14965 new cursor positioning, since row start and end
14966 positions change non-linearly with vertical position
14968 /* FIXME: Revisit this when glyph ``spilling'' in
14969 continuation lines' rows is implemented for
14970 bidi-reordered rows. */
14971 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14972 MATRIX_ROW_CONTINUATION_LINE_P (row
);
14975 /* If we hit the beginning of the displayed portion
14976 without finding the first row of a continued
14980 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14983 xassert (row
->enabled_p
);
14988 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14989 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14990 /* Make sure this isn't a header line by any chance, since
14991 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
14992 && !row
->mode_line_p
14993 && make_cursor_line_fully_visible_p
)
14995 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14996 && !row
->ends_at_zv_p
14997 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14998 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14999 else if (row
->height
> window_box_height (w
))
15001 /* If we end up in a partially visible line, let's
15002 make it fully visible, except when it's taller
15003 than the window, in which case we can't do much
15006 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15010 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15011 if (!cursor_row_fully_visible_p (w
, 0, 1))
15012 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15014 rc
= CURSOR_MOVEMENT_SUCCESS
;
15018 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15019 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15020 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15022 /* With bidi-reordered rows, there could be more than
15023 one candidate row whose start and end positions
15024 occlude point. We need to let set_cursor_from_row
15025 find the best candidate. */
15026 /* FIXME: Revisit this when glyph ``spilling'' in
15027 continuation lines' rows is implemented for
15028 bidi-reordered rows. */
15033 int at_zv_p
= 0, exact_match_p
= 0;
15035 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15036 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15037 && cursor_row_p (row
))
15038 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15040 /* As soon as we've found the exact match for point,
15041 or the first suitable row whose ends_at_zv_p flag
15042 is set, we are done. */
15044 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15046 && w
->cursor
.hpos
>= 0
15047 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15050 struct glyph_row
*candidate
=
15051 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15053 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15054 EMACS_INT endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15057 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15058 || (INTEGERP (g
->object
)
15059 && (g
->charpos
== PT
15060 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15062 if (rv
&& (at_zv_p
|| exact_match_p
))
15064 rc
= CURSOR_MOVEMENT_SUCCESS
;
15067 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15071 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15072 || row
->continued_p
)
15073 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15074 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15075 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15076 /* If we didn't find any candidate rows, or exited the
15077 loop before all the candidates were examined, signal
15078 to the caller that this method failed. */
15079 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15081 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15082 && !row
->continued_p
))
15083 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15085 rc
= CURSOR_MOVEMENT_SUCCESS
;
15091 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15093 rc
= CURSOR_MOVEMENT_SUCCESS
;
15098 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15099 && MATRIX_ROW_START_CHARPOS (row
) == PT
15100 && cursor_row_p (row
));
15108 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15112 set_vertical_scroll_bar (struct window
*w
)
15114 EMACS_INT start
, end
, whole
;
15116 /* Calculate the start and end positions for the current window.
15117 At some point, it would be nice to choose between scrollbars
15118 which reflect the whole buffer size, with special markers
15119 indicating narrowing, and scrollbars which reflect only the
15122 Note that mini-buffers sometimes aren't displaying any text. */
15123 if (!MINI_WINDOW_P (w
)
15124 || (w
== XWINDOW (minibuf_window
)
15125 && NILP (echo_area_buffer
[0])))
15127 struct buffer
*buf
= XBUFFER (w
->buffer
);
15128 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15129 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15130 /* I don't think this is guaranteed to be right. For the
15131 moment, we'll pretend it is. */
15132 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15136 if (whole
< (end
- start
))
15137 whole
= end
- start
;
15140 start
= end
= whole
= 0;
15142 /* Indicate what this scroll bar ought to be displaying now. */
15143 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15144 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15145 (w
, end
- start
, whole
, start
);
15149 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15150 selected_window is redisplayed.
15152 We can return without actually redisplaying the window if
15153 fonts_changed_p is nonzero. In that case, redisplay_internal will
15157 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15159 struct window
*w
= XWINDOW (window
);
15160 struct frame
*f
= XFRAME (w
->frame
);
15161 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15162 struct buffer
*old
= current_buffer
;
15163 struct text_pos lpoint
, opoint
, startp
;
15164 int update_mode_line
;
15167 /* Record it now because it's overwritten. */
15168 int current_matrix_up_to_date_p
= 0;
15169 int used_current_matrix_p
= 0;
15170 /* This is less strict than current_matrix_up_to_date_p.
15171 It indicates that the buffer contents and narrowing are unchanged. */
15172 int buffer_unchanged_p
= 0;
15173 int temp_scroll_step
= 0;
15174 int count
= SPECPDL_INDEX ();
15176 int centering_position
= -1;
15177 int last_line_misfit
= 0;
15178 EMACS_INT beg_unchanged
, end_unchanged
;
15180 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15183 /* W must be a leaf window here. */
15184 xassert (!NILP (w
->buffer
));
15186 *w
->desired_matrix
->method
= 0;
15190 reconsider_clip_changes (w
, buffer
);
15192 /* Has the mode line to be updated? */
15193 update_mode_line
= (!NILP (w
->update_mode_line
)
15194 || update_mode_lines
15195 || buffer
->clip_changed
15196 || buffer
->prevent_redisplay_optimizations_p
);
15198 if (MINI_WINDOW_P (w
))
15200 if (w
== XWINDOW (echo_area_window
)
15201 && !NILP (echo_area_buffer
[0]))
15203 if (update_mode_line
)
15204 /* We may have to update a tty frame's menu bar or a
15205 tool-bar. Example `M-x C-h C-h C-g'. */
15206 goto finish_menu_bars
;
15208 /* We've already displayed the echo area glyphs in this window. */
15209 goto finish_scroll_bars
;
15211 else if ((w
!= XWINDOW (minibuf_window
)
15212 || minibuf_level
== 0)
15213 /* When buffer is nonempty, redisplay window normally. */
15214 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15215 /* Quail displays non-mini buffers in minibuffer window.
15216 In that case, redisplay the window normally. */
15217 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15219 /* W is a mini-buffer window, but it's not active, so clear
15221 int yb
= window_text_bottom_y (w
);
15222 struct glyph_row
*row
;
15225 for (y
= 0, row
= w
->desired_matrix
->rows
;
15227 y
+= row
->height
, ++row
)
15228 blank_row (w
, row
, y
);
15229 goto finish_scroll_bars
;
15232 clear_glyph_matrix (w
->desired_matrix
);
15235 /* Otherwise set up data on this window; select its buffer and point
15237 /* Really select the buffer, for the sake of buffer-local
15239 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15241 current_matrix_up_to_date_p
15242 = (!NILP (w
->window_end_valid
)
15243 && !current_buffer
->clip_changed
15244 && !current_buffer
->prevent_redisplay_optimizations_p
15245 && XFASTINT (w
->last_modified
) >= MODIFF
15246 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15248 /* Run the window-bottom-change-functions
15249 if it is possible that the text on the screen has changed
15250 (either due to modification of the text, or any other reason). */
15251 if (!current_matrix_up_to_date_p
15252 && !NILP (Vwindow_text_change_functions
))
15254 safe_run_hooks (Qwindow_text_change_functions
);
15258 beg_unchanged
= BEG_UNCHANGED
;
15259 end_unchanged
= END_UNCHANGED
;
15261 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15263 specbind (Qinhibit_point_motion_hooks
, Qt
);
15266 = (!NILP (w
->window_end_valid
)
15267 && !current_buffer
->clip_changed
15268 && XFASTINT (w
->last_modified
) >= MODIFF
15269 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
15271 /* When windows_or_buffers_changed is non-zero, we can't rely on
15272 the window end being valid, so set it to nil there. */
15273 if (windows_or_buffers_changed
)
15275 /* If window starts on a continuation line, maybe adjust the
15276 window start in case the window's width changed. */
15277 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15278 compute_window_start_on_continuation_line (w
);
15280 w
->window_end_valid
= Qnil
;
15283 /* Some sanity checks. */
15284 CHECK_WINDOW_END (w
);
15285 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15287 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15290 /* If %c is in mode line, update it if needed. */
15291 if (!NILP (w
->column_number_displayed
)
15292 /* This alternative quickly identifies a common case
15293 where no change is needed. */
15294 && !(PT
== XFASTINT (w
->last_point
)
15295 && XFASTINT (w
->last_modified
) >= MODIFF
15296 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
15297 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15298 update_mode_line
= 1;
15300 /* Count number of windows showing the selected buffer. An indirect
15301 buffer counts as its base buffer. */
15302 if (!just_this_one_p
)
15304 struct buffer
*current_base
, *window_base
;
15305 current_base
= current_buffer
;
15306 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15307 if (current_base
->base_buffer
)
15308 current_base
= current_base
->base_buffer
;
15309 if (window_base
->base_buffer
)
15310 window_base
= window_base
->base_buffer
;
15311 if (current_base
== window_base
)
15315 /* Point refers normally to the selected window. For any other
15316 window, set up appropriate value. */
15317 if (!EQ (window
, selected_window
))
15319 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
15320 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
15324 new_pt_byte
= BEGV_BYTE
;
15325 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15327 else if (new_pt
> (ZV
- 1))
15330 new_pt_byte
= ZV_BYTE
;
15331 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15334 /* We don't use SET_PT so that the point-motion hooks don't run. */
15335 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15338 /* If any of the character widths specified in the display table
15339 have changed, invalidate the width run cache. It's true that
15340 this may be a bit late to catch such changes, but the rest of
15341 redisplay goes (non-fatally) haywire when the display table is
15342 changed, so why should we worry about doing any better? */
15343 if (current_buffer
->width_run_cache
)
15345 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15347 if (! disptab_matches_widthtab (disptab
,
15348 XVECTOR (BVAR (current_buffer
, width_table
))))
15350 invalidate_region_cache (current_buffer
,
15351 current_buffer
->width_run_cache
,
15353 recompute_width_table (current_buffer
, disptab
);
15357 /* If window-start is screwed up, choose a new one. */
15358 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15361 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15363 /* If someone specified a new starting point but did not insist,
15364 check whether it can be used. */
15365 if (!NILP (w
->optional_new_start
)
15366 && CHARPOS (startp
) >= BEGV
15367 && CHARPOS (startp
) <= ZV
)
15369 w
->optional_new_start
= Qnil
;
15370 start_display (&it
, w
, startp
);
15371 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15372 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15373 if (IT_CHARPOS (it
) == PT
)
15374 w
->force_start
= Qt
;
15375 /* IT may overshoot PT if text at PT is invisible. */
15376 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15377 w
->force_start
= Qt
;
15382 /* Handle case where place to start displaying has been specified,
15383 unless the specified location is outside the accessible range. */
15384 if (!NILP (w
->force_start
)
15385 || w
->frozen_window_start_p
)
15387 /* We set this later on if we have to adjust point. */
15390 w
->force_start
= Qnil
;
15392 w
->window_end_valid
= Qnil
;
15394 /* Forget any recorded base line for line number display. */
15395 if (!buffer_unchanged_p
)
15396 w
->base_line_number
= Qnil
;
15398 /* Redisplay the mode line. Select the buffer properly for that.
15399 Also, run the hook window-scroll-functions
15400 because we have scrolled. */
15401 /* Note, we do this after clearing force_start because
15402 if there's an error, it is better to forget about force_start
15403 than to get into an infinite loop calling the hook functions
15404 and having them get more errors. */
15405 if (!update_mode_line
15406 || ! NILP (Vwindow_scroll_functions
))
15408 update_mode_line
= 1;
15409 w
->update_mode_line
= Qt
;
15410 startp
= run_window_scroll_functions (window
, startp
);
15413 w
->last_modified
= make_number (0);
15414 w
->last_overlay_modified
= make_number (0);
15415 if (CHARPOS (startp
) < BEGV
)
15416 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15417 else if (CHARPOS (startp
) > ZV
)
15418 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15420 /* Redisplay, then check if cursor has been set during the
15421 redisplay. Give up if new fonts were loaded. */
15422 /* We used to issue a CHECK_MARGINS argument to try_window here,
15423 but this causes scrolling to fail when point begins inside
15424 the scroll margin (bug#148) -- cyd */
15425 if (!try_window (window
, startp
, 0))
15427 w
->force_start
= Qt
;
15428 clear_glyph_matrix (w
->desired_matrix
);
15429 goto need_larger_matrices
;
15432 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15434 /* If point does not appear, try to move point so it does
15435 appear. The desired matrix has been built above, so we
15436 can use it here. */
15437 new_vpos
= window_box_height (w
) / 2;
15440 if (!cursor_row_fully_visible_p (w
, 0, 0))
15442 /* Point does appear, but on a line partly visible at end of window.
15443 Move it back to a fully-visible line. */
15444 new_vpos
= window_box_height (w
);
15447 /* If we need to move point for either of the above reasons,
15448 now actually do it. */
15451 struct glyph_row
*row
;
15453 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15454 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15457 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15458 MATRIX_ROW_START_BYTEPOS (row
));
15460 if (w
!= XWINDOW (selected_window
))
15461 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15462 else if (current_buffer
== old
)
15463 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15465 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15467 /* If we are highlighting the region, then we just changed
15468 the region, so redisplay to show it. */
15469 if (!NILP (Vtransient_mark_mode
)
15470 && !NILP (BVAR (current_buffer
, mark_active
)))
15472 clear_glyph_matrix (w
->desired_matrix
);
15473 if (!try_window (window
, startp
, 0))
15474 goto need_larger_matrices
;
15479 debug_method_add (w
, "forced window start");
15484 /* Handle case where text has not changed, only point, and it has
15485 not moved off the frame, and we are not retrying after hscroll.
15486 (current_matrix_up_to_date_p is nonzero when retrying.) */
15487 if (current_matrix_up_to_date_p
15488 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15489 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15493 case CURSOR_MOVEMENT_SUCCESS
:
15494 used_current_matrix_p
= 1;
15497 case CURSOR_MOVEMENT_MUST_SCROLL
:
15498 goto try_to_scroll
;
15504 /* If current starting point was originally the beginning of a line
15505 but no longer is, find a new starting point. */
15506 else if (!NILP (w
->start_at_line_beg
)
15507 && !(CHARPOS (startp
) <= BEGV
15508 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15511 debug_method_add (w
, "recenter 1");
15516 /* Try scrolling with try_window_id. Value is > 0 if update has
15517 been done, it is -1 if we know that the same window start will
15518 not work. It is 0 if unsuccessful for some other reason. */
15519 else if ((tem
= try_window_id (w
)) != 0)
15522 debug_method_add (w
, "try_window_id %d", tem
);
15525 if (fonts_changed_p
)
15526 goto need_larger_matrices
;
15530 /* Otherwise try_window_id has returned -1 which means that we
15531 don't want the alternative below this comment to execute. */
15533 else if (CHARPOS (startp
) >= BEGV
15534 && CHARPOS (startp
) <= ZV
15535 && PT
>= CHARPOS (startp
)
15536 && (CHARPOS (startp
) < ZV
15537 /* Avoid starting at end of buffer. */
15538 || CHARPOS (startp
) == BEGV
15539 || (XFASTINT (w
->last_modified
) >= MODIFF
15540 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
15542 int d1
, d2
, d3
, d4
, d5
, d6
;
15544 /* If first window line is a continuation line, and window start
15545 is inside the modified region, but the first change is before
15546 current window start, we must select a new window start.
15548 However, if this is the result of a down-mouse event (e.g. by
15549 extending the mouse-drag-overlay), we don't want to select a
15550 new window start, since that would change the position under
15551 the mouse, resulting in an unwanted mouse-movement rather
15552 than a simple mouse-click. */
15553 if (NILP (w
->start_at_line_beg
)
15554 && NILP (do_mouse_tracking
)
15555 && CHARPOS (startp
) > BEGV
15556 && CHARPOS (startp
) > BEG
+ beg_unchanged
15557 && CHARPOS (startp
) <= Z
- end_unchanged
15558 /* Even if w->start_at_line_beg is nil, a new window may
15559 start at a line_beg, since that's how set_buffer_window
15560 sets it. So, we need to check the return value of
15561 compute_window_start_on_continuation_line. (See also
15563 && XMARKER (w
->start
)->buffer
== current_buffer
15564 && compute_window_start_on_continuation_line (w
)
15565 /* It doesn't make sense to force the window start like we
15566 do at label force_start if it is already known that point
15567 will not be visible in the resulting window, because
15568 doing so will move point from its correct position
15569 instead of scrolling the window to bring point into view.
15571 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15573 w
->force_start
= Qt
;
15574 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15579 debug_method_add (w
, "same window start");
15582 /* Try to redisplay starting at same place as before.
15583 If point has not moved off frame, accept the results. */
15584 if (!current_matrix_up_to_date_p
15585 /* Don't use try_window_reusing_current_matrix in this case
15586 because a window scroll function can have changed the
15588 || !NILP (Vwindow_scroll_functions
)
15589 || MINI_WINDOW_P (w
)
15590 || !(used_current_matrix_p
15591 = try_window_reusing_current_matrix (w
)))
15593 IF_DEBUG (debug_method_add (w
, "1"));
15594 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15595 /* -1 means we need to scroll.
15596 0 means we need new matrices, but fonts_changed_p
15597 is set in that case, so we will detect it below. */
15598 goto try_to_scroll
;
15601 if (fonts_changed_p
)
15602 goto need_larger_matrices
;
15604 if (w
->cursor
.vpos
>= 0)
15606 if (!just_this_one_p
15607 || current_buffer
->clip_changed
15608 || BEG_UNCHANGED
< CHARPOS (startp
))
15609 /* Forget any recorded base line for line number display. */
15610 w
->base_line_number
= Qnil
;
15612 if (!cursor_row_fully_visible_p (w
, 1, 0))
15614 clear_glyph_matrix (w
->desired_matrix
);
15615 last_line_misfit
= 1;
15617 /* Drop through and scroll. */
15622 clear_glyph_matrix (w
->desired_matrix
);
15627 w
->last_modified
= make_number (0);
15628 w
->last_overlay_modified
= make_number (0);
15630 /* Redisplay the mode line. Select the buffer properly for that. */
15631 if (!update_mode_line
)
15633 update_mode_line
= 1;
15634 w
->update_mode_line
= Qt
;
15637 /* Try to scroll by specified few lines. */
15638 if ((scroll_conservatively
15639 || emacs_scroll_step
15640 || temp_scroll_step
15641 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15642 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15643 && CHARPOS (startp
) >= BEGV
15644 && CHARPOS (startp
) <= ZV
)
15646 /* The function returns -1 if new fonts were loaded, 1 if
15647 successful, 0 if not successful. */
15648 int ss
= try_scrolling (window
, just_this_one_p
,
15649 scroll_conservatively
,
15651 temp_scroll_step
, last_line_misfit
);
15654 case SCROLLING_SUCCESS
:
15657 case SCROLLING_NEED_LARGER_MATRICES
:
15658 goto need_larger_matrices
;
15660 case SCROLLING_FAILED
:
15668 /* Finally, just choose a place to start which positions point
15669 according to user preferences. */
15674 debug_method_add (w
, "recenter");
15677 /* w->vscroll = 0; */
15679 /* Forget any previously recorded base line for line number display. */
15680 if (!buffer_unchanged_p
)
15681 w
->base_line_number
= Qnil
;
15683 /* Determine the window start relative to point. */
15684 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15685 it
.current_y
= it
.last_visible_y
;
15686 if (centering_position
< 0)
15690 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15692 EMACS_INT margin_pos
= CHARPOS (startp
);
15693 Lisp_Object aggressive
;
15696 /* If there is a scroll margin at the top of the window, find
15697 its character position. */
15699 /* Cannot call start_display if startp is not in the
15700 accessible region of the buffer. This can happen when we
15701 have just switched to a different buffer and/or changed
15702 its restriction. In that case, startp is initialized to
15703 the character position 1 (BEGV) because we did not yet
15704 have chance to display the buffer even once. */
15705 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15708 void *it1data
= NULL
;
15710 SAVE_IT (it1
, it
, it1data
);
15711 start_display (&it1
, w
, startp
);
15712 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15713 margin_pos
= IT_CHARPOS (it1
);
15714 RESTORE_IT (&it
, &it
, it1data
);
15716 scrolling_up
= PT
> margin_pos
;
15719 ? BVAR (current_buffer
, scroll_up_aggressively
)
15720 : BVAR (current_buffer
, scroll_down_aggressively
);
15722 if (!MINI_WINDOW_P (w
)
15723 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15727 /* Setting scroll-conservatively overrides
15728 scroll-*-aggressively. */
15729 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15731 double float_amount
= XFLOATINT (aggressive
);
15733 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15734 if (pt_offset
== 0 && float_amount
> 0)
15736 if (pt_offset
&& margin
> 0)
15739 /* Compute how much to move the window start backward from
15740 point so that point will be displayed where the user
15744 centering_position
= it
.last_visible_y
;
15746 centering_position
-= pt_offset
;
15747 centering_position
-=
15748 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15749 + WINDOW_HEADER_LINE_HEIGHT (w
);
15750 /* Don't let point enter the scroll margin near top of
15752 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15753 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15756 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15759 /* Set the window start half the height of the window backward
15761 centering_position
= window_box_height (w
) / 2;
15763 move_it_vertically_backward (&it
, centering_position
);
15765 xassert (IT_CHARPOS (it
) >= BEGV
);
15767 /* The function move_it_vertically_backward may move over more
15768 than the specified y-distance. If it->w is small, e.g. a
15769 mini-buffer window, we may end up in front of the window's
15770 display area. Start displaying at the start of the line
15771 containing PT in this case. */
15772 if (it
.current_y
<= 0)
15774 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15775 move_it_vertically_backward (&it
, 0);
15779 it
.current_x
= it
.hpos
= 0;
15781 /* Set the window start position here explicitly, to avoid an
15782 infinite loop in case the functions in window-scroll-functions
15784 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15786 /* Run scroll hooks. */
15787 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15789 /* Redisplay the window. */
15790 if (!current_matrix_up_to_date_p
15791 || windows_or_buffers_changed
15792 || cursor_type_changed
15793 /* Don't use try_window_reusing_current_matrix in this case
15794 because it can have changed the buffer. */
15795 || !NILP (Vwindow_scroll_functions
)
15796 || !just_this_one_p
15797 || MINI_WINDOW_P (w
)
15798 || !(used_current_matrix_p
15799 = try_window_reusing_current_matrix (w
)))
15800 try_window (window
, startp
, 0);
15802 /* If new fonts have been loaded (due to fontsets), give up. We
15803 have to start a new redisplay since we need to re-adjust glyph
15805 if (fonts_changed_p
)
15806 goto need_larger_matrices
;
15808 /* If cursor did not appear assume that the middle of the window is
15809 in the first line of the window. Do it again with the next line.
15810 (Imagine a window of height 100, displaying two lines of height
15811 60. Moving back 50 from it->last_visible_y will end in the first
15813 if (w
->cursor
.vpos
< 0)
15815 if (!NILP (w
->window_end_valid
)
15816 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
15818 clear_glyph_matrix (w
->desired_matrix
);
15819 move_it_by_lines (&it
, 1);
15820 try_window (window
, it
.current
.pos
, 0);
15822 else if (PT
< IT_CHARPOS (it
))
15824 clear_glyph_matrix (w
->desired_matrix
);
15825 move_it_by_lines (&it
, -1);
15826 try_window (window
, it
.current
.pos
, 0);
15830 /* Not much we can do about it. */
15834 /* Consider the following case: Window starts at BEGV, there is
15835 invisible, intangible text at BEGV, so that display starts at
15836 some point START > BEGV. It can happen that we are called with
15837 PT somewhere between BEGV and START. Try to handle that case. */
15838 if (w
->cursor
.vpos
< 0)
15840 struct glyph_row
*row
= w
->current_matrix
->rows
;
15841 if (row
->mode_line_p
)
15843 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15846 if (!cursor_row_fully_visible_p (w
, 0, 0))
15848 /* If vscroll is enabled, disable it and try again. */
15852 clear_glyph_matrix (w
->desired_matrix
);
15856 /* Users who set scroll-conservatively to a large number want
15857 point just above/below the scroll margin. If we ended up
15858 with point's row partially visible, move the window start to
15859 make that row fully visible and out of the margin. */
15860 if (scroll_conservatively
> SCROLL_LIMIT
)
15864 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15866 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15868 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15869 clear_glyph_matrix (w
->desired_matrix
);
15870 if (1 == try_window (window
, it
.current
.pos
,
15871 TRY_WINDOW_CHECK_MARGINS
))
15875 /* If centering point failed to make the whole line visible,
15876 put point at the top instead. That has to make the whole line
15877 visible, if it can be done. */
15878 if (centering_position
== 0)
15881 clear_glyph_matrix (w
->desired_matrix
);
15882 centering_position
= 0;
15888 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15889 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15890 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15893 /* Display the mode line, if we must. */
15894 if ((update_mode_line
15895 /* If window not full width, must redo its mode line
15896 if (a) the window to its side is being redone and
15897 (b) we do a frame-based redisplay. This is a consequence
15898 of how inverted lines are drawn in frame-based redisplay. */
15899 || (!just_this_one_p
15900 && !FRAME_WINDOW_P (f
)
15901 && !WINDOW_FULL_WIDTH_P (w
))
15902 /* Line number to display. */
15903 || INTEGERP (w
->base_line_pos
)
15904 /* Column number is displayed and different from the one displayed. */
15905 || (!NILP (w
->column_number_displayed
)
15906 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15907 /* This means that the window has a mode line. */
15908 && (WINDOW_WANTS_MODELINE_P (w
)
15909 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15911 display_mode_lines (w
);
15913 /* If mode line height has changed, arrange for a thorough
15914 immediate redisplay using the correct mode line height. */
15915 if (WINDOW_WANTS_MODELINE_P (w
)
15916 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15918 fonts_changed_p
= 1;
15919 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15920 = DESIRED_MODE_LINE_HEIGHT (w
);
15923 /* If header line height has changed, arrange for a thorough
15924 immediate redisplay using the correct header line height. */
15925 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15926 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15928 fonts_changed_p
= 1;
15929 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15930 = DESIRED_HEADER_LINE_HEIGHT (w
);
15933 if (fonts_changed_p
)
15934 goto need_larger_matrices
;
15937 if (!line_number_displayed
15938 && !BUFFERP (w
->base_line_pos
))
15940 w
->base_line_pos
= Qnil
;
15941 w
->base_line_number
= Qnil
;
15946 /* When we reach a frame's selected window, redo the frame's menu bar. */
15947 if (update_mode_line
15948 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15950 int redisplay_menu_p
= 0;
15952 if (FRAME_WINDOW_P (f
))
15954 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15955 || defined (HAVE_NS) || defined (USE_GTK)
15956 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15958 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15962 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15964 if (redisplay_menu_p
)
15965 display_menu_bar (w
);
15967 #ifdef HAVE_WINDOW_SYSTEM
15968 if (FRAME_WINDOW_P (f
))
15970 #if defined (USE_GTK) || defined (HAVE_NS)
15971 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15972 redisplay_tool_bar (f
);
15974 if (WINDOWP (f
->tool_bar_window
)
15975 && (FRAME_TOOL_BAR_LINES (f
) > 0
15976 || !NILP (Vauto_resize_tool_bars
))
15977 && redisplay_tool_bar (f
))
15978 ignore_mouse_drag_p
= 1;
15984 #ifdef HAVE_WINDOW_SYSTEM
15985 if (FRAME_WINDOW_P (f
)
15986 && update_window_fringes (w
, (just_this_one_p
15987 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15988 || w
->pseudo_window_p
)))
15992 if (draw_window_fringes (w
, 1))
15993 x_draw_vertical_border (w
);
15997 #endif /* HAVE_WINDOW_SYSTEM */
15999 /* We go to this label, with fonts_changed_p nonzero,
16000 if it is necessary to try again using larger glyph matrices.
16001 We have to redeem the scroll bar even in this case,
16002 because the loop in redisplay_internal expects that. */
16003 need_larger_matrices
:
16005 finish_scroll_bars
:
16007 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16009 /* Set the thumb's position and size. */
16010 set_vertical_scroll_bar (w
);
16012 /* Note that we actually used the scroll bar attached to this
16013 window, so it shouldn't be deleted at the end of redisplay. */
16014 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16015 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16018 /* Restore current_buffer and value of point in it. The window
16019 update may have changed the buffer, so first make sure `opoint'
16020 is still valid (Bug#6177). */
16021 if (CHARPOS (opoint
) < BEGV
)
16022 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16023 else if (CHARPOS (opoint
) > ZV
)
16024 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16026 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16028 set_buffer_internal_1 (old
);
16029 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16030 shorter. This can be caused by log truncation in *Messages*. */
16031 if (CHARPOS (lpoint
) <= ZV
)
16032 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16034 unbind_to (count
, Qnil
);
16038 /* Build the complete desired matrix of WINDOW with a window start
16039 buffer position POS.
16041 Value is 1 if successful. It is zero if fonts were loaded during
16042 redisplay which makes re-adjusting glyph matrices necessary, and -1
16043 if point would appear in the scroll margins.
16044 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16045 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16049 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16051 struct window
*w
= XWINDOW (window
);
16053 struct glyph_row
*last_text_row
= NULL
;
16054 struct frame
*f
= XFRAME (w
->frame
);
16056 /* Make POS the new window start. */
16057 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16059 /* Mark cursor position as unknown. No overlay arrow seen. */
16060 w
->cursor
.vpos
= -1;
16061 overlay_arrow_seen
= 0;
16063 /* Initialize iterator and info to start at POS. */
16064 start_display (&it
, w
, pos
);
16066 /* Display all lines of W. */
16067 while (it
.current_y
< it
.last_visible_y
)
16069 if (display_line (&it
))
16070 last_text_row
= it
.glyph_row
- 1;
16071 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16075 /* Don't let the cursor end in the scroll margins. */
16076 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16077 && !MINI_WINDOW_P (w
))
16079 int this_scroll_margin
;
16081 if (scroll_margin
> 0)
16083 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16084 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16087 this_scroll_margin
= 0;
16089 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16090 && w
->cursor
.y
< this_scroll_margin
16091 && CHARPOS (pos
) > BEGV
16092 && IT_CHARPOS (it
) < ZV
)
16093 /* rms: considering make_cursor_line_fully_visible_p here
16094 seems to give wrong results. We don't want to recenter
16095 when the last line is partly visible, we want to allow
16096 that case to be handled in the usual way. */
16097 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16099 w
->cursor
.vpos
= -1;
16100 clear_glyph_matrix (w
->desired_matrix
);
16105 /* If bottom moved off end of frame, change mode line percentage. */
16106 if (XFASTINT (w
->window_end_pos
) <= 0
16107 && Z
!= IT_CHARPOS (it
))
16108 w
->update_mode_line
= Qt
;
16110 /* Set window_end_pos to the offset of the last character displayed
16111 on the window from the end of current_buffer. Set
16112 window_end_vpos to its row number. */
16115 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16116 w
->window_end_bytepos
16117 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16119 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16121 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16122 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
16123 ->displays_text_p
);
16127 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16128 w
->window_end_pos
= make_number (Z
- ZV
);
16129 w
->window_end_vpos
= make_number (0);
16132 /* But that is not valid info until redisplay finishes. */
16133 w
->window_end_valid
= Qnil
;
16139 /************************************************************************
16140 Window redisplay reusing current matrix when buffer has not changed
16141 ************************************************************************/
16143 /* Try redisplay of window W showing an unchanged buffer with a
16144 different window start than the last time it was displayed by
16145 reusing its current matrix. Value is non-zero if successful.
16146 W->start is the new window start. */
16149 try_window_reusing_current_matrix (struct window
*w
)
16151 struct frame
*f
= XFRAME (w
->frame
);
16152 struct glyph_row
*bottom_row
;
16155 struct text_pos start
, new_start
;
16156 int nrows_scrolled
, i
;
16157 struct glyph_row
*last_text_row
;
16158 struct glyph_row
*last_reused_text_row
;
16159 struct glyph_row
*start_row
;
16160 int start_vpos
, min_y
, max_y
;
16163 if (inhibit_try_window_reusing
)
16167 if (/* This function doesn't handle terminal frames. */
16168 !FRAME_WINDOW_P (f
)
16169 /* Don't try to reuse the display if windows have been split
16171 || windows_or_buffers_changed
16172 || cursor_type_changed
)
16175 /* Can't do this if region may have changed. */
16176 if ((!NILP (Vtransient_mark_mode
)
16177 && !NILP (BVAR (current_buffer
, mark_active
)))
16178 || !NILP (w
->region_showing
)
16179 || !NILP (Vshow_trailing_whitespace
))
16182 /* If top-line visibility has changed, give up. */
16183 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16184 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16187 /* Give up if old or new display is scrolled vertically. We could
16188 make this function handle this, but right now it doesn't. */
16189 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16190 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16193 /* The variable new_start now holds the new window start. The old
16194 start `start' can be determined from the current matrix. */
16195 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16196 start
= start_row
->minpos
;
16197 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16199 /* Clear the desired matrix for the display below. */
16200 clear_glyph_matrix (w
->desired_matrix
);
16202 if (CHARPOS (new_start
) <= CHARPOS (start
))
16204 /* Don't use this method if the display starts with an ellipsis
16205 displayed for invisible text. It's not easy to handle that case
16206 below, and it's certainly not worth the effort since this is
16207 not a frequent case. */
16208 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16211 IF_DEBUG (debug_method_add (w
, "twu1"));
16213 /* Display up to a row that can be reused. The variable
16214 last_text_row is set to the last row displayed that displays
16215 text. Note that it.vpos == 0 if or if not there is a
16216 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16217 start_display (&it
, w
, new_start
);
16218 w
->cursor
.vpos
= -1;
16219 last_text_row
= last_reused_text_row
= NULL
;
16221 while (it
.current_y
< it
.last_visible_y
16222 && !fonts_changed_p
)
16224 /* If we have reached into the characters in the START row,
16225 that means the line boundaries have changed. So we
16226 can't start copying with the row START. Maybe it will
16227 work to start copying with the following row. */
16228 while (IT_CHARPOS (it
) > CHARPOS (start
))
16230 /* Advance to the next row as the "start". */
16232 start
= start_row
->minpos
;
16233 /* If there are no more rows to try, or just one, give up. */
16234 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16235 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16236 || CHARPOS (start
) == ZV
)
16238 clear_glyph_matrix (w
->desired_matrix
);
16242 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16244 /* If we have reached alignment, we can copy the rest of the
16246 if (IT_CHARPOS (it
) == CHARPOS (start
)
16247 /* Don't accept "alignment" inside a display vector,
16248 since start_row could have started in the middle of
16249 that same display vector (thus their character
16250 positions match), and we have no way of telling if
16251 that is the case. */
16252 && it
.current
.dpvec_index
< 0)
16255 if (display_line (&it
))
16256 last_text_row
= it
.glyph_row
- 1;
16260 /* A value of current_y < last_visible_y means that we stopped
16261 at the previous window start, which in turn means that we
16262 have at least one reusable row. */
16263 if (it
.current_y
< it
.last_visible_y
)
16265 struct glyph_row
*row
;
16267 /* IT.vpos always starts from 0; it counts text lines. */
16268 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16270 /* Find PT if not already found in the lines displayed. */
16271 if (w
->cursor
.vpos
< 0)
16273 int dy
= it
.current_y
- start_row
->y
;
16275 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16276 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16278 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16279 dy
, nrows_scrolled
);
16282 clear_glyph_matrix (w
->desired_matrix
);
16287 /* Scroll the display. Do it before the current matrix is
16288 changed. The problem here is that update has not yet
16289 run, i.e. part of the current matrix is not up to date.
16290 scroll_run_hook will clear the cursor, and use the
16291 current matrix to get the height of the row the cursor is
16293 run
.current_y
= start_row
->y
;
16294 run
.desired_y
= it
.current_y
;
16295 run
.height
= it
.last_visible_y
- it
.current_y
;
16297 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16300 FRAME_RIF (f
)->update_window_begin_hook (w
);
16301 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16302 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16303 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16307 /* Shift current matrix down by nrows_scrolled lines. */
16308 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16309 rotate_matrix (w
->current_matrix
,
16311 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16314 /* Disable lines that must be updated. */
16315 for (i
= 0; i
< nrows_scrolled
; ++i
)
16316 (start_row
+ i
)->enabled_p
= 0;
16318 /* Re-compute Y positions. */
16319 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16320 max_y
= it
.last_visible_y
;
16321 for (row
= start_row
+ nrows_scrolled
;
16325 row
->y
= it
.current_y
;
16326 row
->visible_height
= row
->height
;
16328 if (row
->y
< min_y
)
16329 row
->visible_height
-= min_y
- row
->y
;
16330 if (row
->y
+ row
->height
> max_y
)
16331 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16332 if (row
->fringe_bitmap_periodic_p
)
16333 row
->redraw_fringe_bitmaps_p
= 1;
16335 it
.current_y
+= row
->height
;
16337 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16338 last_reused_text_row
= row
;
16339 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16343 /* Disable lines in the current matrix which are now
16344 below the window. */
16345 for (++row
; row
< bottom_row
; ++row
)
16346 row
->enabled_p
= row
->mode_line_p
= 0;
16349 /* Update window_end_pos etc.; last_reused_text_row is the last
16350 reused row from the current matrix containing text, if any.
16351 The value of last_text_row is the last displayed line
16352 containing text. */
16353 if (last_reused_text_row
)
16355 w
->window_end_bytepos
16356 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16358 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
16360 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16361 w
->current_matrix
));
16363 else if (last_text_row
)
16365 w
->window_end_bytepos
16366 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16368 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16370 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16374 /* This window must be completely empty. */
16375 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16376 w
->window_end_pos
= make_number (Z
- ZV
);
16377 w
->window_end_vpos
= make_number (0);
16379 w
->window_end_valid
= Qnil
;
16381 /* Update hint: don't try scrolling again in update_window. */
16382 w
->desired_matrix
->no_scrolling_p
= 1;
16385 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16389 else if (CHARPOS (new_start
) > CHARPOS (start
))
16391 struct glyph_row
*pt_row
, *row
;
16392 struct glyph_row
*first_reusable_row
;
16393 struct glyph_row
*first_row_to_display
;
16395 int yb
= window_text_bottom_y (w
);
16397 /* Find the row starting at new_start, if there is one. Don't
16398 reuse a partially visible line at the end. */
16399 first_reusable_row
= start_row
;
16400 while (first_reusable_row
->enabled_p
16401 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16402 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16403 < CHARPOS (new_start
)))
16404 ++first_reusable_row
;
16406 /* Give up if there is no row to reuse. */
16407 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16408 || !first_reusable_row
->enabled_p
16409 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16410 != CHARPOS (new_start
)))
16413 /* We can reuse fully visible rows beginning with
16414 first_reusable_row to the end of the window. Set
16415 first_row_to_display to the first row that cannot be reused.
16416 Set pt_row to the row containing point, if there is any. */
16418 for (first_row_to_display
= first_reusable_row
;
16419 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16420 ++first_row_to_display
)
16422 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16423 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16424 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16425 && first_row_to_display
->ends_at_zv_p
16426 && pt_row
== NULL
)))
16427 pt_row
= first_row_to_display
;
16430 /* Start displaying at the start of first_row_to_display. */
16431 xassert (first_row_to_display
->y
< yb
);
16432 init_to_row_start (&it
, w
, first_row_to_display
);
16434 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16436 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16438 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16439 + WINDOW_HEADER_LINE_HEIGHT (w
));
16441 /* Display lines beginning with first_row_to_display in the
16442 desired matrix. Set last_text_row to the last row displayed
16443 that displays text. */
16444 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16445 if (pt_row
== NULL
)
16446 w
->cursor
.vpos
= -1;
16447 last_text_row
= NULL
;
16448 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16449 if (display_line (&it
))
16450 last_text_row
= it
.glyph_row
- 1;
16452 /* If point is in a reused row, adjust y and vpos of the cursor
16456 w
->cursor
.vpos
-= nrows_scrolled
;
16457 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16460 /* Give up if point isn't in a row displayed or reused. (This
16461 also handles the case where w->cursor.vpos < nrows_scrolled
16462 after the calls to display_line, which can happen with scroll
16463 margins. See bug#1295.) */
16464 if (w
->cursor
.vpos
< 0)
16466 clear_glyph_matrix (w
->desired_matrix
);
16470 /* Scroll the display. */
16471 run
.current_y
= first_reusable_row
->y
;
16472 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16473 run
.height
= it
.last_visible_y
- run
.current_y
;
16474 dy
= run
.current_y
- run
.desired_y
;
16479 FRAME_RIF (f
)->update_window_begin_hook (w
);
16480 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16481 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16482 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16486 /* Adjust Y positions of reused rows. */
16487 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16488 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16489 max_y
= it
.last_visible_y
;
16490 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16493 row
->visible_height
= row
->height
;
16494 if (row
->y
< min_y
)
16495 row
->visible_height
-= min_y
- row
->y
;
16496 if (row
->y
+ row
->height
> max_y
)
16497 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16498 if (row
->fringe_bitmap_periodic_p
)
16499 row
->redraw_fringe_bitmaps_p
= 1;
16502 /* Scroll the current matrix. */
16503 xassert (nrows_scrolled
> 0);
16504 rotate_matrix (w
->current_matrix
,
16506 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16509 /* Disable rows not reused. */
16510 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16511 row
->enabled_p
= 0;
16513 /* Point may have moved to a different line, so we cannot assume that
16514 the previous cursor position is valid; locate the correct row. */
16517 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16519 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16520 && !row
->ends_at_zv_p
;
16524 w
->cursor
.y
= row
->y
;
16526 if (row
< bottom_row
)
16528 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16529 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16531 /* Can't use this optimization with bidi-reordered glyph
16532 rows, unless cursor is already at point. */
16533 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16535 if (!(w
->cursor
.hpos
>= 0
16536 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16537 && BUFFERP (glyph
->object
)
16538 && glyph
->charpos
== PT
))
16543 && (!BUFFERP (glyph
->object
)
16544 || glyph
->charpos
< PT
);
16548 w
->cursor
.x
+= glyph
->pixel_width
;
16553 /* Adjust window end. A null value of last_text_row means that
16554 the window end is in reused rows which in turn means that
16555 only its vpos can have changed. */
16558 w
->window_end_bytepos
16559 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16561 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16563 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
16568 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
16571 w
->window_end_valid
= Qnil
;
16572 w
->desired_matrix
->no_scrolling_p
= 1;
16575 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16585 /************************************************************************
16586 Window redisplay reusing current matrix when buffer has changed
16587 ************************************************************************/
16589 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16590 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16591 EMACS_INT
*, EMACS_INT
*);
16592 static struct glyph_row
*
16593 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16594 struct glyph_row
*);
16597 /* Return the last row in MATRIX displaying text. If row START is
16598 non-null, start searching with that row. IT gives the dimensions
16599 of the display. Value is null if matrix is empty; otherwise it is
16600 a pointer to the row found. */
16602 static struct glyph_row
*
16603 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16604 struct glyph_row
*start
)
16606 struct glyph_row
*row
, *row_found
;
16608 /* Set row_found to the last row in IT->w's current matrix
16609 displaying text. The loop looks funny but think of partially
16612 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16613 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16615 xassert (row
->enabled_p
);
16617 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16626 /* Return the last row in the current matrix of W that is not affected
16627 by changes at the start of current_buffer that occurred since W's
16628 current matrix was built. Value is null if no such row exists.
16630 BEG_UNCHANGED us the number of characters unchanged at the start of
16631 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16632 first changed character in current_buffer. Characters at positions <
16633 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16634 when the current matrix was built. */
16636 static struct glyph_row
*
16637 find_last_unchanged_at_beg_row (struct window
*w
)
16639 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16640 struct glyph_row
*row
;
16641 struct glyph_row
*row_found
= NULL
;
16642 int yb
= window_text_bottom_y (w
);
16644 /* Find the last row displaying unchanged text. */
16645 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16646 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16647 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16650 if (/* If row ends before first_changed_pos, it is unchanged,
16651 except in some case. */
16652 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16653 /* When row ends in ZV and we write at ZV it is not
16655 && !row
->ends_at_zv_p
16656 /* When first_changed_pos is the end of a continued line,
16657 row is not unchanged because it may be no longer
16659 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16660 && (row
->continued_p
16661 || row
->exact_window_width_line_p
))
16662 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16663 needs to be recomputed, so don't consider this row as
16664 unchanged. This happens when the last line was
16665 bidi-reordered and was killed immediately before this
16666 redisplay cycle. In that case, ROW->end stores the
16667 buffer position of the first visual-order character of
16668 the killed text, which is now beyond ZV. */
16669 && CHARPOS (row
->end
.pos
) <= ZV
)
16672 /* Stop if last visible row. */
16673 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16681 /* Find the first glyph row in the current matrix of W that is not
16682 affected by changes at the end of current_buffer since the
16683 time W's current matrix was built.
16685 Return in *DELTA the number of chars by which buffer positions in
16686 unchanged text at the end of current_buffer must be adjusted.
16688 Return in *DELTA_BYTES the corresponding number of bytes.
16690 Value is null if no such row exists, i.e. all rows are affected by
16693 static struct glyph_row
*
16694 find_first_unchanged_at_end_row (struct window
*w
,
16695 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
16697 struct glyph_row
*row
;
16698 struct glyph_row
*row_found
= NULL
;
16700 *delta
= *delta_bytes
= 0;
16702 /* Display must not have been paused, otherwise the current matrix
16703 is not up to date. */
16704 eassert (!NILP (w
->window_end_valid
));
16706 /* A value of window_end_pos >= END_UNCHANGED means that the window
16707 end is in the range of changed text. If so, there is no
16708 unchanged row at the end of W's current matrix. */
16709 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16712 /* Set row to the last row in W's current matrix displaying text. */
16713 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16715 /* If matrix is entirely empty, no unchanged row exists. */
16716 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16718 /* The value of row is the last glyph row in the matrix having a
16719 meaningful buffer position in it. The end position of row
16720 corresponds to window_end_pos. This allows us to translate
16721 buffer positions in the current matrix to current buffer
16722 positions for characters not in changed text. */
16724 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16725 EMACS_INT Z_BYTE_old
=
16726 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16727 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
16728 struct glyph_row
*first_text_row
16729 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16731 *delta
= Z
- Z_old
;
16732 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16734 /* Set last_unchanged_pos to the buffer position of the last
16735 character in the buffer that has not been changed. Z is the
16736 index + 1 of the last character in current_buffer, i.e. by
16737 subtracting END_UNCHANGED we get the index of the last
16738 unchanged character, and we have to add BEG to get its buffer
16740 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16741 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16743 /* Search backward from ROW for a row displaying a line that
16744 starts at a minimum position >= last_unchanged_pos_old. */
16745 for (; row
> first_text_row
; --row
)
16747 /* This used to abort, but it can happen.
16748 It is ok to just stop the search instead here. KFS. */
16749 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16752 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16757 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16763 /* Make sure that glyph rows in the current matrix of window W
16764 reference the same glyph memory as corresponding rows in the
16765 frame's frame matrix. This function is called after scrolling W's
16766 current matrix on a terminal frame in try_window_id and
16767 try_window_reusing_current_matrix. */
16770 sync_frame_with_window_matrix_rows (struct window
*w
)
16772 struct frame
*f
= XFRAME (w
->frame
);
16773 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16775 /* Preconditions: W must be a leaf window and full-width. Its frame
16776 must have a frame matrix. */
16777 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16778 xassert (WINDOW_FULL_WIDTH_P (w
));
16779 xassert (!FRAME_WINDOW_P (f
));
16781 /* If W is a full-width window, glyph pointers in W's current matrix
16782 have, by definition, to be the same as glyph pointers in the
16783 corresponding frame matrix. Note that frame matrices have no
16784 marginal areas (see build_frame_matrix). */
16785 window_row
= w
->current_matrix
->rows
;
16786 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16787 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16788 while (window_row
< window_row_end
)
16790 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16791 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16793 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16794 frame_row
->glyphs
[TEXT_AREA
] = start
;
16795 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16796 frame_row
->glyphs
[LAST_AREA
] = end
;
16798 /* Disable frame rows whose corresponding window rows have
16799 been disabled in try_window_id. */
16800 if (!window_row
->enabled_p
)
16801 frame_row
->enabled_p
= 0;
16803 ++window_row
, ++frame_row
;
16808 /* Find the glyph row in window W containing CHARPOS. Consider all
16809 rows between START and END (not inclusive). END null means search
16810 all rows to the end of the display area of W. Value is the row
16811 containing CHARPOS or null. */
16814 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
16815 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16817 struct glyph_row
*row
= start
;
16818 struct glyph_row
*best_row
= NULL
;
16819 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16822 /* If we happen to start on a header-line, skip that. */
16823 if (row
->mode_line_p
)
16826 if ((end
&& row
>= end
) || !row
->enabled_p
)
16829 last_y
= window_text_bottom_y (w
) - dy
;
16833 /* Give up if we have gone too far. */
16834 if (end
&& row
>= end
)
16836 /* This formerly returned if they were equal.
16837 I think that both quantities are of a "last plus one" type;
16838 if so, when they are equal, the row is within the screen. -- rms. */
16839 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16842 /* If it is in this row, return this row. */
16843 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16844 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16845 /* The end position of a row equals the start
16846 position of the next row. If CHARPOS is there, we
16847 would rather display it in the next line, except
16848 when this line ends in ZV. */
16849 && !row
->ends_at_zv_p
16850 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16851 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16855 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16856 || (!best_row
&& !row
->continued_p
))
16858 /* In bidi-reordered rows, there could be several rows
16859 occluding point, all of them belonging to the same
16860 continued line. We need to find the row which fits
16861 CHARPOS the best. */
16862 for (g
= row
->glyphs
[TEXT_AREA
];
16863 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16866 if (!STRINGP (g
->object
))
16868 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16870 mindif
= eabs (g
->charpos
- charpos
);
16872 /* Exact match always wins. */
16879 else if (best_row
&& !row
->continued_p
)
16886 /* Try to redisplay window W by reusing its existing display. W's
16887 current matrix must be up to date when this function is called,
16888 i.e. window_end_valid must not be nil.
16892 1 if display has been updated
16893 0 if otherwise unsuccessful
16894 -1 if redisplay with same window start is known not to succeed
16896 The following steps are performed:
16898 1. Find the last row in the current matrix of W that is not
16899 affected by changes at the start of current_buffer. If no such row
16902 2. Find the first row in W's current matrix that is not affected by
16903 changes at the end of current_buffer. Maybe there is no such row.
16905 3. Display lines beginning with the row + 1 found in step 1 to the
16906 row found in step 2 or, if step 2 didn't find a row, to the end of
16909 4. If cursor is not known to appear on the window, give up.
16911 5. If display stopped at the row found in step 2, scroll the
16912 display and current matrix as needed.
16914 6. Maybe display some lines at the end of W, if we must. This can
16915 happen under various circumstances, like a partially visible line
16916 becoming fully visible, or because newly displayed lines are displayed
16917 in smaller font sizes.
16919 7. Update W's window end information. */
16922 try_window_id (struct window
*w
)
16924 struct frame
*f
= XFRAME (w
->frame
);
16925 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16926 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16927 struct glyph_row
*last_unchanged_at_beg_row
;
16928 struct glyph_row
*first_unchanged_at_end_row
;
16929 struct glyph_row
*row
;
16930 struct glyph_row
*bottom_row
;
16933 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
16935 struct text_pos start_pos
;
16937 int first_unchanged_at_end_vpos
= 0;
16938 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16939 struct text_pos start
;
16940 EMACS_INT first_changed_charpos
, last_changed_charpos
;
16943 if (inhibit_try_window_id
)
16947 /* This is handy for debugging. */
16949 #define GIVE_UP(X) \
16951 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16955 #define GIVE_UP(X) return 0
16958 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16960 /* Don't use this for mini-windows because these can show
16961 messages and mini-buffers, and we don't handle that here. */
16962 if (MINI_WINDOW_P (w
))
16965 /* This flag is used to prevent redisplay optimizations. */
16966 if (windows_or_buffers_changed
|| cursor_type_changed
)
16969 /* Verify that narrowing has not changed.
16970 Also verify that we were not told to prevent redisplay optimizations.
16971 It would be nice to further
16972 reduce the number of cases where this prevents try_window_id. */
16973 if (current_buffer
->clip_changed
16974 || current_buffer
->prevent_redisplay_optimizations_p
)
16977 /* Window must either use window-based redisplay or be full width. */
16978 if (!FRAME_WINDOW_P (f
)
16979 && (!FRAME_LINE_INS_DEL_OK (f
)
16980 || !WINDOW_FULL_WIDTH_P (w
)))
16983 /* Give up if point is known NOT to appear in W. */
16984 if (PT
< CHARPOS (start
))
16987 /* Another way to prevent redisplay optimizations. */
16988 if (XFASTINT (w
->last_modified
) == 0)
16991 /* Verify that window is not hscrolled. */
16992 if (XFASTINT (w
->hscroll
) != 0)
16995 /* Verify that display wasn't paused. */
16996 if (NILP (w
->window_end_valid
))
16999 /* Can't use this if highlighting a region because a cursor movement
17000 will do more than just set the cursor. */
17001 if (!NILP (Vtransient_mark_mode
)
17002 && !NILP (BVAR (current_buffer
, mark_active
)))
17005 /* Likewise if highlighting trailing whitespace. */
17006 if (!NILP (Vshow_trailing_whitespace
))
17009 /* Likewise if showing a region. */
17010 if (!NILP (w
->region_showing
))
17013 /* Can't use this if overlay arrow position and/or string have
17015 if (overlay_arrows_changed_p ())
17018 /* When word-wrap is on, adding a space to the first word of a
17019 wrapped line can change the wrap position, altering the line
17020 above it. It might be worthwhile to handle this more
17021 intelligently, but for now just redisplay from scratch. */
17022 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17025 /* Under bidi reordering, adding or deleting a character in the
17026 beginning of a paragraph, before the first strong directional
17027 character, can change the base direction of the paragraph (unless
17028 the buffer specifies a fixed paragraph direction), which will
17029 require to redisplay the whole paragraph. It might be worthwhile
17030 to find the paragraph limits and widen the range of redisplayed
17031 lines to that, but for now just give up this optimization and
17032 redisplay from scratch. */
17033 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17034 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17037 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17038 only if buffer has really changed. The reason is that the gap is
17039 initially at Z for freshly visited files. The code below would
17040 set end_unchanged to 0 in that case. */
17041 if (MODIFF
> SAVE_MODIFF
17042 /* This seems to happen sometimes after saving a buffer. */
17043 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17045 if (GPT
- BEG
< BEG_UNCHANGED
)
17046 BEG_UNCHANGED
= GPT
- BEG
;
17047 if (Z
- GPT
< END_UNCHANGED
)
17048 END_UNCHANGED
= Z
- GPT
;
17051 /* The position of the first and last character that has been changed. */
17052 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17053 last_changed_charpos
= Z
- END_UNCHANGED
;
17055 /* If window starts after a line end, and the last change is in
17056 front of that newline, then changes don't affect the display.
17057 This case happens with stealth-fontification. Note that although
17058 the display is unchanged, glyph positions in the matrix have to
17059 be adjusted, of course. */
17060 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17061 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17062 && ((last_changed_charpos
< CHARPOS (start
)
17063 && CHARPOS (start
) == BEGV
)
17064 || (last_changed_charpos
< CHARPOS (start
) - 1
17065 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17067 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17068 struct glyph_row
*r0
;
17070 /* Compute how many chars/bytes have been added to or removed
17071 from the buffer. */
17072 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17073 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17074 Z_delta
= Z
- Z_old
;
17075 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17077 /* Give up if PT is not in the window. Note that it already has
17078 been checked at the start of try_window_id that PT is not in
17079 front of the window start. */
17080 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17083 /* If window start is unchanged, we can reuse the whole matrix
17084 as is, after adjusting glyph positions. No need to compute
17085 the window end again, since its offset from Z hasn't changed. */
17086 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17087 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17088 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17089 /* PT must not be in a partially visible line. */
17090 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17091 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17093 /* Adjust positions in the glyph matrix. */
17094 if (Z_delta
|| Z_delta_bytes
)
17096 struct glyph_row
*r1
17097 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17098 increment_matrix_positions (w
->current_matrix
,
17099 MATRIX_ROW_VPOS (r0
, current_matrix
),
17100 MATRIX_ROW_VPOS (r1
, current_matrix
),
17101 Z_delta
, Z_delta_bytes
);
17104 /* Set the cursor. */
17105 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17107 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17114 /* Handle the case that changes are all below what is displayed in
17115 the window, and that PT is in the window. This shortcut cannot
17116 be taken if ZV is visible in the window, and text has been added
17117 there that is visible in the window. */
17118 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17119 /* ZV is not visible in the window, or there are no
17120 changes at ZV, actually. */
17121 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17122 || first_changed_charpos
== last_changed_charpos
))
17124 struct glyph_row
*r0
;
17126 /* Give up if PT is not in the window. Note that it already has
17127 been checked at the start of try_window_id that PT is not in
17128 front of the window start. */
17129 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17132 /* If window start is unchanged, we can reuse the whole matrix
17133 as is, without changing glyph positions since no text has
17134 been added/removed in front of the window end. */
17135 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17136 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17137 /* PT must not be in a partially visible line. */
17138 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17139 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17141 /* We have to compute the window end anew since text
17142 could have been added/removed after it. */
17144 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17145 w
->window_end_bytepos
17146 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17148 /* Set the cursor. */
17149 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17151 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17158 /* Give up if window start is in the changed area.
17160 The condition used to read
17162 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17164 but why that was tested escapes me at the moment. */
17165 if (CHARPOS (start
) >= first_changed_charpos
17166 && CHARPOS (start
) <= last_changed_charpos
)
17169 /* Check that window start agrees with the start of the first glyph
17170 row in its current matrix. Check this after we know the window
17171 start is not in changed text, otherwise positions would not be
17173 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17174 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17177 /* Give up if the window ends in strings. Overlay strings
17178 at the end are difficult to handle, so don't try. */
17179 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17180 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17183 /* Compute the position at which we have to start displaying new
17184 lines. Some of the lines at the top of the window might be
17185 reusable because they are not displaying changed text. Find the
17186 last row in W's current matrix not affected by changes at the
17187 start of current_buffer. Value is null if changes start in the
17188 first line of window. */
17189 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17190 if (last_unchanged_at_beg_row
)
17192 /* Avoid starting to display in the middle of a character, a TAB
17193 for instance. This is easier than to set up the iterator
17194 exactly, and it's not a frequent case, so the additional
17195 effort wouldn't really pay off. */
17196 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17197 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17198 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17199 --last_unchanged_at_beg_row
;
17201 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17204 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17206 start_pos
= it
.current
.pos
;
17208 /* Start displaying new lines in the desired matrix at the same
17209 vpos we would use in the current matrix, i.e. below
17210 last_unchanged_at_beg_row. */
17211 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17213 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17214 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17216 xassert (it
.hpos
== 0 && it
.current_x
== 0);
17220 /* There are no reusable lines at the start of the window.
17221 Start displaying in the first text line. */
17222 start_display (&it
, w
, start
);
17223 it
.vpos
= it
.first_vpos
;
17224 start_pos
= it
.current
.pos
;
17227 /* Find the first row that is not affected by changes at the end of
17228 the buffer. Value will be null if there is no unchanged row, in
17229 which case we must redisplay to the end of the window. delta
17230 will be set to the value by which buffer positions beginning with
17231 first_unchanged_at_end_row have to be adjusted due to text
17233 first_unchanged_at_end_row
17234 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17235 IF_DEBUG (debug_delta
= delta
);
17236 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17238 /* Set stop_pos to the buffer position up to which we will have to
17239 display new lines. If first_unchanged_at_end_row != NULL, this
17240 is the buffer position of the start of the line displayed in that
17241 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17242 that we don't stop at a buffer position. */
17244 if (first_unchanged_at_end_row
)
17246 xassert (last_unchanged_at_beg_row
== NULL
17247 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17249 /* If this is a continuation line, move forward to the next one
17250 that isn't. Changes in lines above affect this line.
17251 Caution: this may move first_unchanged_at_end_row to a row
17252 not displaying text. */
17253 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17254 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17255 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17256 < it
.last_visible_y
))
17257 ++first_unchanged_at_end_row
;
17259 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17260 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17261 >= it
.last_visible_y
))
17262 first_unchanged_at_end_row
= NULL
;
17265 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17267 first_unchanged_at_end_vpos
17268 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17269 xassert (stop_pos
>= Z
- END_UNCHANGED
);
17272 else if (last_unchanged_at_beg_row
== NULL
)
17278 /* Either there is no unchanged row at the end, or the one we have
17279 now displays text. This is a necessary condition for the window
17280 end pos calculation at the end of this function. */
17281 xassert (first_unchanged_at_end_row
== NULL
17282 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17284 debug_last_unchanged_at_beg_vpos
17285 = (last_unchanged_at_beg_row
17286 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17288 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17290 #endif /* GLYPH_DEBUG != 0 */
17293 /* Display new lines. Set last_text_row to the last new line
17294 displayed which has text on it, i.e. might end up as being the
17295 line where the window_end_vpos is. */
17296 w
->cursor
.vpos
= -1;
17297 last_text_row
= NULL
;
17298 overlay_arrow_seen
= 0;
17299 while (it
.current_y
< it
.last_visible_y
17300 && !fonts_changed_p
17301 && (first_unchanged_at_end_row
== NULL
17302 || IT_CHARPOS (it
) < stop_pos
))
17304 if (display_line (&it
))
17305 last_text_row
= it
.glyph_row
- 1;
17308 if (fonts_changed_p
)
17312 /* Compute differences in buffer positions, y-positions etc. for
17313 lines reused at the bottom of the window. Compute what we can
17315 if (first_unchanged_at_end_row
17316 /* No lines reused because we displayed everything up to the
17317 bottom of the window. */
17318 && it
.current_y
< it
.last_visible_y
)
17321 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17323 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17324 run
.current_y
= first_unchanged_at_end_row
->y
;
17325 run
.desired_y
= run
.current_y
+ dy
;
17326 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17330 delta
= delta_bytes
= dvpos
= dy
17331 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17332 first_unchanged_at_end_row
= NULL
;
17334 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17337 /* Find the cursor if not already found. We have to decide whether
17338 PT will appear on this window (it sometimes doesn't, but this is
17339 not a very frequent case.) This decision has to be made before
17340 the current matrix is altered. A value of cursor.vpos < 0 means
17341 that PT is either in one of the lines beginning at
17342 first_unchanged_at_end_row or below the window. Don't care for
17343 lines that might be displayed later at the window end; as
17344 mentioned, this is not a frequent case. */
17345 if (w
->cursor
.vpos
< 0)
17347 /* Cursor in unchanged rows at the top? */
17348 if (PT
< CHARPOS (start_pos
)
17349 && last_unchanged_at_beg_row
)
17351 row
= row_containing_pos (w
, PT
,
17352 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17353 last_unchanged_at_beg_row
+ 1, 0);
17355 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17358 /* Start from first_unchanged_at_end_row looking for PT. */
17359 else if (first_unchanged_at_end_row
)
17361 row
= row_containing_pos (w
, PT
- delta
,
17362 first_unchanged_at_end_row
, NULL
, 0);
17364 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17365 delta_bytes
, dy
, dvpos
);
17368 /* Give up if cursor was not found. */
17369 if (w
->cursor
.vpos
< 0)
17371 clear_glyph_matrix (w
->desired_matrix
);
17376 /* Don't let the cursor end in the scroll margins. */
17378 int this_scroll_margin
, cursor_height
;
17380 this_scroll_margin
=
17381 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17382 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17383 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17385 if ((w
->cursor
.y
< this_scroll_margin
17386 && CHARPOS (start
) > BEGV
)
17387 /* Old redisplay didn't take scroll margin into account at the bottom,
17388 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17389 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17390 ? cursor_height
+ this_scroll_margin
17391 : 1)) > it
.last_visible_y
)
17393 w
->cursor
.vpos
= -1;
17394 clear_glyph_matrix (w
->desired_matrix
);
17399 /* Scroll the display. Do it before changing the current matrix so
17400 that xterm.c doesn't get confused about where the cursor glyph is
17402 if (dy
&& run
.height
)
17406 if (FRAME_WINDOW_P (f
))
17408 FRAME_RIF (f
)->update_window_begin_hook (w
);
17409 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17410 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17411 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17415 /* Terminal frame. In this case, dvpos gives the number of
17416 lines to scroll by; dvpos < 0 means scroll up. */
17418 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17419 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17420 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17421 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17422 + window_internal_height (w
));
17424 #if defined (HAVE_GPM) || defined (MSDOS)
17425 x_clear_window_mouse_face (w
);
17427 /* Perform the operation on the screen. */
17430 /* Scroll last_unchanged_at_beg_row to the end of the
17431 window down dvpos lines. */
17432 set_terminal_window (f
, end
);
17434 /* On dumb terminals delete dvpos lines at the end
17435 before inserting dvpos empty lines. */
17436 if (!FRAME_SCROLL_REGION_OK (f
))
17437 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17439 /* Insert dvpos empty lines in front of
17440 last_unchanged_at_beg_row. */
17441 ins_del_lines (f
, from
, dvpos
);
17443 else if (dvpos
< 0)
17445 /* Scroll up last_unchanged_at_beg_vpos to the end of
17446 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17447 set_terminal_window (f
, end
);
17449 /* Delete dvpos lines in front of
17450 last_unchanged_at_beg_vpos. ins_del_lines will set
17451 the cursor to the given vpos and emit |dvpos| delete
17453 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17455 /* On a dumb terminal insert dvpos empty lines at the
17457 if (!FRAME_SCROLL_REGION_OK (f
))
17458 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17461 set_terminal_window (f
, 0);
17467 /* Shift reused rows of the current matrix to the right position.
17468 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17470 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17471 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17474 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17475 bottom_vpos
, dvpos
);
17476 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17479 else if (dvpos
> 0)
17481 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17482 bottom_vpos
, dvpos
);
17483 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17484 first_unchanged_at_end_vpos
+ dvpos
, 0);
17487 /* For frame-based redisplay, make sure that current frame and window
17488 matrix are in sync with respect to glyph memory. */
17489 if (!FRAME_WINDOW_P (f
))
17490 sync_frame_with_window_matrix_rows (w
);
17492 /* Adjust buffer positions in reused rows. */
17493 if (delta
|| delta_bytes
)
17494 increment_matrix_positions (current_matrix
,
17495 first_unchanged_at_end_vpos
+ dvpos
,
17496 bottom_vpos
, delta
, delta_bytes
);
17498 /* Adjust Y positions. */
17500 shift_glyph_matrix (w
, current_matrix
,
17501 first_unchanged_at_end_vpos
+ dvpos
,
17504 if (first_unchanged_at_end_row
)
17506 first_unchanged_at_end_row
+= dvpos
;
17507 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17508 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17509 first_unchanged_at_end_row
= NULL
;
17512 /* If scrolling up, there may be some lines to display at the end of
17514 last_text_row_at_end
= NULL
;
17517 /* Scrolling up can leave for example a partially visible line
17518 at the end of the window to be redisplayed. */
17519 /* Set last_row to the glyph row in the current matrix where the
17520 window end line is found. It has been moved up or down in
17521 the matrix by dvpos. */
17522 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17523 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17525 /* If last_row is the window end line, it should display text. */
17526 xassert (last_row
->displays_text_p
);
17528 /* If window end line was partially visible before, begin
17529 displaying at that line. Otherwise begin displaying with the
17530 line following it. */
17531 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17533 init_to_row_start (&it
, w
, last_row
);
17534 it
.vpos
= last_vpos
;
17535 it
.current_y
= last_row
->y
;
17539 init_to_row_end (&it
, w
, last_row
);
17540 it
.vpos
= 1 + last_vpos
;
17541 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17545 /* We may start in a continuation line. If so, we have to
17546 get the right continuation_lines_width and current_x. */
17547 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17548 it
.hpos
= it
.current_x
= 0;
17550 /* Display the rest of the lines at the window end. */
17551 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17552 while (it
.current_y
< it
.last_visible_y
17553 && !fonts_changed_p
)
17555 /* Is it always sure that the display agrees with lines in
17556 the current matrix? I don't think so, so we mark rows
17557 displayed invalid in the current matrix by setting their
17558 enabled_p flag to zero. */
17559 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17560 if (display_line (&it
))
17561 last_text_row_at_end
= it
.glyph_row
- 1;
17565 /* Update window_end_pos and window_end_vpos. */
17566 if (first_unchanged_at_end_row
17567 && !last_text_row_at_end
)
17569 /* Window end line if one of the preserved rows from the current
17570 matrix. Set row to the last row displaying text in current
17571 matrix starting at first_unchanged_at_end_row, after
17573 xassert (first_unchanged_at_end_row
->displays_text_p
);
17574 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17575 first_unchanged_at_end_row
);
17576 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17578 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17579 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17581 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
17582 xassert (w
->window_end_bytepos
>= 0);
17583 IF_DEBUG (debug_method_add (w
, "A"));
17585 else if (last_text_row_at_end
)
17588 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
17589 w
->window_end_bytepos
17590 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17592 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
17593 xassert (w
->window_end_bytepos
>= 0);
17594 IF_DEBUG (debug_method_add (w
, "B"));
17596 else if (last_text_row
)
17598 /* We have displayed either to the end of the window or at the
17599 end of the window, i.e. the last row with text is to be found
17600 in the desired matrix. */
17602 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
17603 w
->window_end_bytepos
17604 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17606 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
17607 xassert (w
->window_end_bytepos
>= 0);
17609 else if (first_unchanged_at_end_row
== NULL
17610 && last_text_row
== NULL
17611 && last_text_row_at_end
== NULL
)
17613 /* Displayed to end of window, but no line containing text was
17614 displayed. Lines were deleted at the end of the window. */
17615 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17616 int vpos
= XFASTINT (w
->window_end_vpos
);
17617 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17618 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17621 row
== NULL
&& vpos
>= first_vpos
;
17622 --vpos
, --current_row
, --desired_row
)
17624 if (desired_row
->enabled_p
)
17626 if (desired_row
->displays_text_p
)
17629 else if (current_row
->displays_text_p
)
17633 xassert (row
!= NULL
);
17634 w
->window_end_vpos
= make_number (vpos
+ 1);
17635 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
17636 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17637 xassert (w
->window_end_bytepos
>= 0);
17638 IF_DEBUG (debug_method_add (w
, "C"));
17643 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17644 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17646 /* Record that display has not been completed. */
17647 w
->window_end_valid
= Qnil
;
17648 w
->desired_matrix
->no_scrolling_p
= 1;
17656 /***********************************************************************
17657 More debugging support
17658 ***********************************************************************/
17662 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17663 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17664 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17667 /* Dump the contents of glyph matrix MATRIX on stderr.
17669 GLYPHS 0 means don't show glyph contents.
17670 GLYPHS 1 means show glyphs in short form
17671 GLYPHS > 1 means show glyphs in long form. */
17674 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17677 for (i
= 0; i
< matrix
->nrows
; ++i
)
17678 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17682 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17683 the glyph row and area where the glyph comes from. */
17686 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17688 if (glyph
->type
== CHAR_GLYPH
)
17691 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17692 glyph
- row
->glyphs
[TEXT_AREA
],
17695 (BUFFERP (glyph
->object
)
17697 : (STRINGP (glyph
->object
)
17700 glyph
->pixel_width
,
17702 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17706 glyph
->left_box_line_p
,
17707 glyph
->right_box_line_p
);
17709 else if (glyph
->type
== STRETCH_GLYPH
)
17712 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17713 glyph
- row
->glyphs
[TEXT_AREA
],
17716 (BUFFERP (glyph
->object
)
17718 : (STRINGP (glyph
->object
)
17721 glyph
->pixel_width
,
17725 glyph
->left_box_line_p
,
17726 glyph
->right_box_line_p
);
17728 else if (glyph
->type
== IMAGE_GLYPH
)
17731 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17732 glyph
- row
->glyphs
[TEXT_AREA
],
17735 (BUFFERP (glyph
->object
)
17737 : (STRINGP (glyph
->object
)
17740 glyph
->pixel_width
,
17744 glyph
->left_box_line_p
,
17745 glyph
->right_box_line_p
);
17747 else if (glyph
->type
== COMPOSITE_GLYPH
)
17750 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17751 glyph
- row
->glyphs
[TEXT_AREA
],
17754 (BUFFERP (glyph
->object
)
17756 : (STRINGP (glyph
->object
)
17759 glyph
->pixel_width
,
17761 if (glyph
->u
.cmp
.automatic
)
17764 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17765 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17767 glyph
->left_box_line_p
,
17768 glyph
->right_box_line_p
);
17773 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17774 GLYPHS 0 means don't show glyph contents.
17775 GLYPHS 1 means show glyphs in short form
17776 GLYPHS > 1 means show glyphs in long form. */
17779 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17783 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17784 fprintf (stderr
, "======================================================================\n");
17786 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17787 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17789 MATRIX_ROW_START_CHARPOS (row
),
17790 MATRIX_ROW_END_CHARPOS (row
),
17791 row
->used
[TEXT_AREA
],
17792 row
->contains_overlapping_glyphs_p
,
17794 row
->truncated_on_left_p
,
17795 row
->truncated_on_right_p
,
17797 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17798 row
->displays_text_p
,
17801 row
->ends_in_middle_of_char_p
,
17802 row
->starts_in_middle_of_char_p
,
17808 row
->visible_height
,
17811 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
17812 row
->end
.overlay_string_index
,
17813 row
->continuation_lines_width
);
17814 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
17815 CHARPOS (row
->start
.string_pos
),
17816 CHARPOS (row
->end
.string_pos
));
17817 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
17818 row
->end
.dpvec_index
);
17825 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17827 struct glyph
*glyph
= row
->glyphs
[area
];
17828 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17830 /* Glyph for a line end in text. */
17831 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17834 if (glyph
< glyph_end
)
17835 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
17837 for (; glyph
< glyph_end
; ++glyph
)
17838 dump_glyph (row
, glyph
, area
);
17841 else if (glyphs
== 1)
17845 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17847 char *s
= (char *) alloca (row
->used
[area
] + 1);
17850 for (i
= 0; i
< row
->used
[area
]; ++i
)
17852 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17853 if (glyph
->type
== CHAR_GLYPH
17854 && glyph
->u
.ch
< 0x80
17855 && glyph
->u
.ch
>= ' ')
17856 s
[i
] = glyph
->u
.ch
;
17862 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17868 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17869 Sdump_glyph_matrix
, 0, 1, "p",
17870 doc
: /* Dump the current matrix of the selected window to stderr.
17871 Shows contents of glyph row structures. With non-nil
17872 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17873 glyphs in short form, otherwise show glyphs in long form. */)
17874 (Lisp_Object glyphs
)
17876 struct window
*w
= XWINDOW (selected_window
);
17877 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17879 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17880 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17881 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17882 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17883 fprintf (stderr
, "=============================================\n");
17884 dump_glyph_matrix (w
->current_matrix
,
17885 NILP (glyphs
) ? 0 : XINT (glyphs
));
17890 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17891 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17894 struct frame
*f
= XFRAME (selected_frame
);
17895 dump_glyph_matrix (f
->current_matrix
, 1);
17900 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17901 doc
: /* Dump glyph row ROW to stderr.
17902 GLYPH 0 means don't dump glyphs.
17903 GLYPH 1 means dump glyphs in short form.
17904 GLYPH > 1 or omitted means dump glyphs in long form. */)
17905 (Lisp_Object row
, Lisp_Object glyphs
)
17907 struct glyph_matrix
*matrix
;
17910 CHECK_NUMBER (row
);
17911 matrix
= XWINDOW (selected_window
)->current_matrix
;
17913 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17914 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17916 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17921 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17922 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17923 GLYPH 0 means don't dump glyphs.
17924 GLYPH 1 means dump glyphs in short form.
17925 GLYPH > 1 or omitted means dump glyphs in long form. */)
17926 (Lisp_Object row
, Lisp_Object glyphs
)
17928 struct frame
*sf
= SELECTED_FRAME ();
17929 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17932 CHECK_NUMBER (row
);
17934 if (vpos
>= 0 && vpos
< m
->nrows
)
17935 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17936 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17941 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17942 doc
: /* Toggle tracing of redisplay.
17943 With ARG, turn tracing on if and only if ARG is positive. */)
17947 trace_redisplay_p
= !trace_redisplay_p
;
17950 arg
= Fprefix_numeric_value (arg
);
17951 trace_redisplay_p
= XINT (arg
) > 0;
17958 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17959 doc
: /* Like `format', but print result to stderr.
17960 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17961 (ptrdiff_t nargs
, Lisp_Object
*args
)
17963 Lisp_Object s
= Fformat (nargs
, args
);
17964 fprintf (stderr
, "%s", SDATA (s
));
17968 #endif /* GLYPH_DEBUG */
17972 /***********************************************************************
17973 Building Desired Matrix Rows
17974 ***********************************************************************/
17976 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17977 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17979 static struct glyph_row
*
17980 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17982 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17983 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17984 struct buffer
*old
= current_buffer
;
17985 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17986 int arrow_len
= SCHARS (overlay_arrow_string
);
17987 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17988 const unsigned char *p
;
17991 int n_glyphs_before
;
17993 set_buffer_temp (buffer
);
17994 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17995 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17996 SET_TEXT_POS (it
.position
, 0, 0);
17998 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18000 while (p
< arrow_end
)
18002 Lisp_Object face
, ilisp
;
18004 /* Get the next character. */
18006 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18009 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18010 if (! ASCII_CHAR_P (it
.c
))
18011 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18015 /* Get its face. */
18016 ilisp
= make_number (p
- arrow_string
);
18017 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18018 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18020 /* Compute its width, get its glyphs. */
18021 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18022 SET_TEXT_POS (it
.position
, -1, -1);
18023 PRODUCE_GLYPHS (&it
);
18025 /* If this character doesn't fit any more in the line, we have
18026 to remove some glyphs. */
18027 if (it
.current_x
> it
.last_visible_x
)
18029 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18034 set_buffer_temp (old
);
18035 return it
.glyph_row
;
18039 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
18040 glyphs are only inserted for terminal frames since we can't really
18041 win with truncation glyphs when partially visible glyphs are
18042 involved. Which glyphs to insert is determined by
18043 produce_special_glyphs. */
18046 insert_left_trunc_glyphs (struct it
*it
)
18048 struct it truncate_it
;
18049 struct glyph
*from
, *end
, *to
, *toend
;
18051 xassert (!FRAME_WINDOW_P (it
->f
));
18053 /* Get the truncation glyphs. */
18055 truncate_it
.current_x
= 0;
18056 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18057 truncate_it
.glyph_row
= &scratch_glyph_row
;
18058 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18059 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18060 truncate_it
.object
= make_number (0);
18061 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18063 /* Overwrite glyphs from IT with truncation glyphs. */
18064 if (!it
->glyph_row
->reversed_p
)
18066 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18067 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
18068 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18069 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18074 /* There may be padding glyphs left over. Overwrite them too. */
18075 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18077 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18083 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18087 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18088 that back to front. */
18089 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18090 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18091 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18092 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18094 while (from
>= end
&& to
>= toend
)
18096 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18099 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18100 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18101 while (from
>= end
&& to
>= toend
)
18106 /* Need to free some room before prepending additional
18108 int move_by
= from
- end
+ 1;
18109 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18110 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18112 for ( ; g
>= g0
; g
--)
18114 while (from
>= end
)
18116 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18121 /* Compute the hash code for ROW. */
18123 row_hash (struct glyph_row
*row
)
18126 unsigned hashval
= 0;
18128 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18129 for (k
= 0; k
< row
->used
[area
]; ++k
)
18130 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18131 + row
->glyphs
[area
][k
].u
.val
18132 + row
->glyphs
[area
][k
].face_id
18133 + row
->glyphs
[area
][k
].padding_p
18134 + (row
->glyphs
[area
][k
].type
<< 2));
18139 /* Compute the pixel height and width of IT->glyph_row.
18141 Most of the time, ascent and height of a display line will be equal
18142 to the max_ascent and max_height values of the display iterator
18143 structure. This is not the case if
18145 1. We hit ZV without displaying anything. In this case, max_ascent
18146 and max_height will be zero.
18148 2. We have some glyphs that don't contribute to the line height.
18149 (The glyph row flag contributes_to_line_height_p is for future
18150 pixmap extensions).
18152 The first case is easily covered by using default values because in
18153 these cases, the line height does not really matter, except that it
18154 must not be zero. */
18157 compute_line_metrics (struct it
*it
)
18159 struct glyph_row
*row
= it
->glyph_row
;
18161 if (FRAME_WINDOW_P (it
->f
))
18163 int i
, min_y
, max_y
;
18165 /* The line may consist of one space only, that was added to
18166 place the cursor on it. If so, the row's height hasn't been
18168 if (row
->height
== 0)
18170 if (it
->max_ascent
+ it
->max_descent
== 0)
18171 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18172 row
->ascent
= it
->max_ascent
;
18173 row
->height
= it
->max_ascent
+ it
->max_descent
;
18174 row
->phys_ascent
= it
->max_phys_ascent
;
18175 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18176 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18179 /* Compute the width of this line. */
18180 row
->pixel_width
= row
->x
;
18181 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18182 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18184 xassert (row
->pixel_width
>= 0);
18185 xassert (row
->ascent
>= 0 && row
->height
> 0);
18187 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18188 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18190 /* If first line's physical ascent is larger than its logical
18191 ascent, use the physical ascent, and make the row taller.
18192 This makes accented characters fully visible. */
18193 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18194 && row
->phys_ascent
> row
->ascent
)
18196 row
->height
+= row
->phys_ascent
- row
->ascent
;
18197 row
->ascent
= row
->phys_ascent
;
18200 /* Compute how much of the line is visible. */
18201 row
->visible_height
= row
->height
;
18203 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18204 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18206 if (row
->y
< min_y
)
18207 row
->visible_height
-= min_y
- row
->y
;
18208 if (row
->y
+ row
->height
> max_y
)
18209 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18213 row
->pixel_width
= row
->used
[TEXT_AREA
];
18214 if (row
->continued_p
)
18215 row
->pixel_width
-= it
->continuation_pixel_width
;
18216 else if (row
->truncated_on_right_p
)
18217 row
->pixel_width
-= it
->truncation_pixel_width
;
18218 row
->ascent
= row
->phys_ascent
= 0;
18219 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18220 row
->extra_line_spacing
= 0;
18223 /* Compute a hash code for this row. */
18224 row
->hash
= row_hash (row
);
18226 it
->max_ascent
= it
->max_descent
= 0;
18227 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18231 /* Append one space to the glyph row of iterator IT if doing a
18232 window-based redisplay. The space has the same face as
18233 IT->face_id. Value is non-zero if a space was added.
18235 This function is called to make sure that there is always one glyph
18236 at the end of a glyph row that the cursor can be set on under
18237 window-systems. (If there weren't such a glyph we would not know
18238 how wide and tall a box cursor should be displayed).
18240 At the same time this space let's a nicely handle clearing to the
18241 end of the line if the row ends in italic text. */
18244 append_space_for_newline (struct it
*it
, int default_face_p
)
18246 if (FRAME_WINDOW_P (it
->f
))
18248 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18250 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18251 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18253 /* Save some values that must not be changed.
18254 Must save IT->c and IT->len because otherwise
18255 ITERATOR_AT_END_P wouldn't work anymore after
18256 append_space_for_newline has been called. */
18257 enum display_element_type saved_what
= it
->what
;
18258 int saved_c
= it
->c
, saved_len
= it
->len
;
18259 int saved_char_to_display
= it
->char_to_display
;
18260 int saved_x
= it
->current_x
;
18261 int saved_face_id
= it
->face_id
;
18262 struct text_pos saved_pos
;
18263 Lisp_Object saved_object
;
18266 saved_object
= it
->object
;
18267 saved_pos
= it
->position
;
18269 it
->what
= IT_CHARACTER
;
18270 memset (&it
->position
, 0, sizeof it
->position
);
18271 it
->object
= make_number (0);
18272 it
->c
= it
->char_to_display
= ' ';
18275 /* If the default face was remapped, be sure to use the
18276 remapped face for the appended newline. */
18277 if (default_face_p
)
18278 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18279 else if (it
->face_before_selective_p
)
18280 it
->face_id
= it
->saved_face_id
;
18281 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18282 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18284 PRODUCE_GLYPHS (it
);
18286 it
->override_ascent
= -1;
18287 it
->constrain_row_ascent_descent_p
= 0;
18288 it
->current_x
= saved_x
;
18289 it
->object
= saved_object
;
18290 it
->position
= saved_pos
;
18291 it
->what
= saved_what
;
18292 it
->face_id
= saved_face_id
;
18293 it
->len
= saved_len
;
18295 it
->char_to_display
= saved_char_to_display
;
18304 /* Extend the face of the last glyph in the text area of IT->glyph_row
18305 to the end of the display line. Called from display_line. If the
18306 glyph row is empty, add a space glyph to it so that we know the
18307 face to draw. Set the glyph row flag fill_line_p. If the glyph
18308 row is R2L, prepend a stretch glyph to cover the empty space to the
18309 left of the leftmost glyph. */
18312 extend_face_to_end_of_line (struct it
*it
)
18314 struct face
*face
, *default_face
;
18315 struct frame
*f
= it
->f
;
18317 /* If line is already filled, do nothing. Non window-system frames
18318 get a grace of one more ``pixel'' because their characters are
18319 1-``pixel'' wide, so they hit the equality too early. This grace
18320 is needed only for R2L rows that are not continued, to produce
18321 one extra blank where we could display the cursor. */
18322 if (it
->current_x
>= it
->last_visible_x
18323 + (!FRAME_WINDOW_P (f
)
18324 && it
->glyph_row
->reversed_p
18325 && !it
->glyph_row
->continued_p
))
18328 /* The default face, possibly remapped. */
18329 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18331 /* Face extension extends the background and box of IT->face_id
18332 to the end of the line. If the background equals the background
18333 of the frame, we don't have to do anything. */
18334 if (it
->face_before_selective_p
)
18335 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18337 face
= FACE_FROM_ID (f
, it
->face_id
);
18339 if (FRAME_WINDOW_P (f
)
18340 && it
->glyph_row
->displays_text_p
18341 && face
->box
== FACE_NO_BOX
18342 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18344 && !it
->glyph_row
->reversed_p
)
18347 /* Set the glyph row flag indicating that the face of the last glyph
18348 in the text area has to be drawn to the end of the text area. */
18349 it
->glyph_row
->fill_line_p
= 1;
18351 /* If current character of IT is not ASCII, make sure we have the
18352 ASCII face. This will be automatically undone the next time
18353 get_next_display_element returns a multibyte character. Note
18354 that the character will always be single byte in unibyte
18356 if (!ASCII_CHAR_P (it
->c
))
18358 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18361 if (FRAME_WINDOW_P (f
))
18363 /* If the row is empty, add a space with the current face of IT,
18364 so that we know which face to draw. */
18365 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18367 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18368 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18369 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18371 #ifdef HAVE_WINDOW_SYSTEM
18372 if (it
->glyph_row
->reversed_p
)
18374 /* Prepend a stretch glyph to the row, such that the
18375 rightmost glyph will be drawn flushed all the way to the
18376 right margin of the window. The stretch glyph that will
18377 occupy the empty space, if any, to the left of the
18379 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18380 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18381 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18383 int row_width
, stretch_ascent
, stretch_width
;
18384 struct text_pos saved_pos
;
18385 int saved_face_id
, saved_avoid_cursor
;
18387 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18388 row_width
+= g
->pixel_width
;
18389 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18390 if (stretch_width
> 0)
18393 (((it
->ascent
+ it
->descent
)
18394 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18395 saved_pos
= it
->position
;
18396 memset (&it
->position
, 0, sizeof it
->position
);
18397 saved_avoid_cursor
= it
->avoid_cursor_p
;
18398 it
->avoid_cursor_p
= 1;
18399 saved_face_id
= it
->face_id
;
18400 /* The last row's stretch glyph should get the default
18401 face, to avoid painting the rest of the window with
18402 the region face, if the region ends at ZV. */
18403 if (it
->glyph_row
->ends_at_zv_p
)
18404 it
->face_id
= default_face
->id
;
18406 it
->face_id
= face
->id
;
18407 append_stretch_glyph (it
, make_number (0), stretch_width
,
18408 it
->ascent
+ it
->descent
, stretch_ascent
);
18409 it
->position
= saved_pos
;
18410 it
->avoid_cursor_p
= saved_avoid_cursor
;
18411 it
->face_id
= saved_face_id
;
18414 #endif /* HAVE_WINDOW_SYSTEM */
18418 /* Save some values that must not be changed. */
18419 int saved_x
= it
->current_x
;
18420 struct text_pos saved_pos
;
18421 Lisp_Object saved_object
;
18422 enum display_element_type saved_what
= it
->what
;
18423 int saved_face_id
= it
->face_id
;
18425 saved_object
= it
->object
;
18426 saved_pos
= it
->position
;
18428 it
->what
= IT_CHARACTER
;
18429 memset (&it
->position
, 0, sizeof it
->position
);
18430 it
->object
= make_number (0);
18431 it
->c
= it
->char_to_display
= ' ';
18433 /* The last row's blank glyphs should get the default face, to
18434 avoid painting the rest of the window with the region face,
18435 if the region ends at ZV. */
18436 if (it
->glyph_row
->ends_at_zv_p
)
18437 it
->face_id
= default_face
->id
;
18439 it
->face_id
= face
->id
;
18441 PRODUCE_GLYPHS (it
);
18443 while (it
->current_x
<= it
->last_visible_x
)
18444 PRODUCE_GLYPHS (it
);
18446 /* Don't count these blanks really. It would let us insert a left
18447 truncation glyph below and make us set the cursor on them, maybe. */
18448 it
->current_x
= saved_x
;
18449 it
->object
= saved_object
;
18450 it
->position
= saved_pos
;
18451 it
->what
= saved_what
;
18452 it
->face_id
= saved_face_id
;
18457 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18458 trailing whitespace. */
18461 trailing_whitespace_p (EMACS_INT charpos
)
18463 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
18466 while (bytepos
< ZV_BYTE
18467 && (c
= FETCH_CHAR (bytepos
),
18468 c
== ' ' || c
== '\t'))
18471 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18473 if (bytepos
!= PT_BYTE
)
18480 /* Highlight trailing whitespace, if any, in ROW. */
18483 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18485 int used
= row
->used
[TEXT_AREA
];
18489 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18490 struct glyph
*glyph
= start
+ used
- 1;
18492 if (row
->reversed_p
)
18494 /* Right-to-left rows need to be processed in the opposite
18495 direction, so swap the edge pointers. */
18497 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18500 /* Skip over glyphs inserted to display the cursor at the
18501 end of a line, for extending the face of the last glyph
18502 to the end of the line on terminals, and for truncation
18503 and continuation glyphs. */
18504 if (!row
->reversed_p
)
18506 while (glyph
>= start
18507 && glyph
->type
== CHAR_GLYPH
18508 && INTEGERP (glyph
->object
))
18513 while (glyph
<= start
18514 && glyph
->type
== CHAR_GLYPH
18515 && INTEGERP (glyph
->object
))
18519 /* If last glyph is a space or stretch, and it's trailing
18520 whitespace, set the face of all trailing whitespace glyphs in
18521 IT->glyph_row to `trailing-whitespace'. */
18522 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18523 && BUFFERP (glyph
->object
)
18524 && (glyph
->type
== STRETCH_GLYPH
18525 || (glyph
->type
== CHAR_GLYPH
18526 && glyph
->u
.ch
== ' '))
18527 && trailing_whitespace_p (glyph
->charpos
))
18529 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18533 if (!row
->reversed_p
)
18535 while (glyph
>= start
18536 && BUFFERP (glyph
->object
)
18537 && (glyph
->type
== STRETCH_GLYPH
18538 || (glyph
->type
== CHAR_GLYPH
18539 && glyph
->u
.ch
== ' ')))
18540 (glyph
--)->face_id
= face_id
;
18544 while (glyph
<= start
18545 && BUFFERP (glyph
->object
)
18546 && (glyph
->type
== STRETCH_GLYPH
18547 || (glyph
->type
== CHAR_GLYPH
18548 && glyph
->u
.ch
== ' ')))
18549 (glyph
++)->face_id
= face_id
;
18556 /* Value is non-zero if glyph row ROW should be
18557 used to hold the cursor. */
18560 cursor_row_p (struct glyph_row
*row
)
18564 if (PT
== CHARPOS (row
->end
.pos
)
18565 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18567 /* Suppose the row ends on a string.
18568 Unless the row is continued, that means it ends on a newline
18569 in the string. If it's anything other than a display string
18570 (e.g., a before-string from an overlay), we don't want the
18571 cursor there. (This heuristic seems to give the optimal
18572 behavior for the various types of multi-line strings.)
18573 One exception: if the string has `cursor' property on one of
18574 its characters, we _do_ want the cursor there. */
18575 if (CHARPOS (row
->end
.string_pos
) >= 0)
18577 if (row
->continued_p
)
18581 /* Check for `display' property. */
18582 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18583 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18584 struct glyph
*glyph
;
18587 for (glyph
= end
; glyph
>= beg
; --glyph
)
18588 if (STRINGP (glyph
->object
))
18591 = Fget_char_property (make_number (PT
),
18595 && display_prop_string_p (prop
, glyph
->object
));
18596 /* If there's a `cursor' property on one of the
18597 string's characters, this row is a cursor row,
18598 even though this is not a display string. */
18601 Lisp_Object s
= glyph
->object
;
18603 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18605 EMACS_INT gpos
= glyph
->charpos
;
18607 if (!NILP (Fget_char_property (make_number (gpos
),
18619 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18621 /* If the row ends in middle of a real character,
18622 and the line is continued, we want the cursor here.
18623 That's because CHARPOS (ROW->end.pos) would equal
18624 PT if PT is before the character. */
18625 if (!row
->ends_in_ellipsis_p
)
18626 result
= row
->continued_p
;
18628 /* If the row ends in an ellipsis, then
18629 CHARPOS (ROW->end.pos) will equal point after the
18630 invisible text. We want that position to be displayed
18631 after the ellipsis. */
18634 /* If the row ends at ZV, display the cursor at the end of that
18635 row instead of at the start of the row below. */
18636 else if (row
->ends_at_zv_p
)
18647 /* Push the property PROP so that it will be rendered at the current
18648 position in IT. Return 1 if PROP was successfully pushed, 0
18649 otherwise. Called from handle_line_prefix to handle the
18650 `line-prefix' and `wrap-prefix' properties. */
18653 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18655 struct text_pos pos
=
18656 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18658 xassert (it
->method
== GET_FROM_BUFFER
18659 || it
->method
== GET_FROM_DISPLAY_VECTOR
18660 || it
->method
== GET_FROM_STRING
);
18662 /* We need to save the current buffer/string position, so it will be
18663 restored by pop_it, because iterate_out_of_display_property
18664 depends on that being set correctly, but some situations leave
18665 it->position not yet set when this function is called. */
18666 push_it (it
, &pos
);
18668 if (STRINGP (prop
))
18670 if (SCHARS (prop
) == 0)
18677 it
->string_from_prefix_prop_p
= 1;
18678 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18679 it
->current
.overlay_string_index
= -1;
18680 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18681 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18682 it
->method
= GET_FROM_STRING
;
18683 it
->stop_charpos
= 0;
18685 it
->base_level_stop
= 0;
18687 /* Force paragraph direction to be that of the parent
18689 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18690 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18692 it
->paragraph_embedding
= L2R
;
18694 /* Set up the bidi iterator for this display string. */
18697 it
->bidi_it
.string
.lstring
= it
->string
;
18698 it
->bidi_it
.string
.s
= NULL
;
18699 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18700 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18701 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18702 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18703 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18706 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18708 it
->method
= GET_FROM_STRETCH
;
18711 #ifdef HAVE_WINDOW_SYSTEM
18712 else if (IMAGEP (prop
))
18714 it
->what
= IT_IMAGE
;
18715 it
->image_id
= lookup_image (it
->f
, prop
);
18716 it
->method
= GET_FROM_IMAGE
;
18718 #endif /* HAVE_WINDOW_SYSTEM */
18721 pop_it (it
); /* bogus display property, give up */
18728 /* Return the character-property PROP at the current position in IT. */
18731 get_it_property (struct it
*it
, Lisp_Object prop
)
18733 Lisp_Object position
;
18735 if (STRINGP (it
->object
))
18736 position
= make_number (IT_STRING_CHARPOS (*it
));
18737 else if (BUFFERP (it
->object
))
18738 position
= make_number (IT_CHARPOS (*it
));
18742 return Fget_char_property (position
, prop
, it
->object
);
18745 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18748 handle_line_prefix (struct it
*it
)
18750 Lisp_Object prefix
;
18752 if (it
->continuation_lines_width
> 0)
18754 prefix
= get_it_property (it
, Qwrap_prefix
);
18756 prefix
= Vwrap_prefix
;
18760 prefix
= get_it_property (it
, Qline_prefix
);
18762 prefix
= Vline_prefix
;
18764 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18766 /* If the prefix is wider than the window, and we try to wrap
18767 it, it would acquire its own wrap prefix, and so on till the
18768 iterator stack overflows. So, don't wrap the prefix. */
18769 it
->line_wrap
= TRUNCATE
;
18770 it
->avoid_cursor_p
= 1;
18776 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18777 only for R2L lines from display_line and display_string, when they
18778 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18779 the line/string needs to be continued on the next glyph row. */
18781 unproduce_glyphs (struct it
*it
, int n
)
18783 struct glyph
*glyph
, *end
;
18785 xassert (it
->glyph_row
);
18786 xassert (it
->glyph_row
->reversed_p
);
18787 xassert (it
->area
== TEXT_AREA
);
18788 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18790 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18791 n
= it
->glyph_row
->used
[TEXT_AREA
];
18792 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18793 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18794 for ( ; glyph
< end
; glyph
++)
18795 glyph
[-n
] = *glyph
;
18798 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18799 and ROW->maxpos. */
18801 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18802 EMACS_INT min_pos
, EMACS_INT min_bpos
,
18803 EMACS_INT max_pos
, EMACS_INT max_bpos
)
18805 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18806 lines' rows is implemented for bidi-reordered rows. */
18808 /* ROW->minpos is the value of min_pos, the minimal buffer position
18809 we have in ROW, or ROW->start.pos if that is smaller. */
18810 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18811 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18813 /* We didn't find buffer positions smaller than ROW->start, or
18814 didn't find _any_ valid buffer positions in any of the glyphs,
18815 so we must trust the iterator's computed positions. */
18816 row
->minpos
= row
->start
.pos
;
18819 max_pos
= CHARPOS (it
->current
.pos
);
18820 max_bpos
= BYTEPOS (it
->current
.pos
);
18823 /* Here are the various use-cases for ending the row, and the
18824 corresponding values for ROW->maxpos:
18826 Line ends in a newline from buffer eol_pos + 1
18827 Line is continued from buffer max_pos + 1
18828 Line is truncated on right it->current.pos
18829 Line ends in a newline from string max_pos + 1(*)
18830 (*) + 1 only when line ends in a forward scan
18831 Line is continued from string max_pos
18832 Line is continued from display vector max_pos
18833 Line is entirely from a string min_pos == max_pos
18834 Line is entirely from a display vector min_pos == max_pos
18835 Line that ends at ZV ZV
18837 If you discover other use-cases, please add them here as
18839 if (row
->ends_at_zv_p
)
18840 row
->maxpos
= it
->current
.pos
;
18841 else if (row
->used
[TEXT_AREA
])
18843 int seen_this_string
= 0;
18844 struct glyph_row
*r1
= row
- 1;
18846 /* Did we see the same display string on the previous row? */
18847 if (STRINGP (it
->object
)
18848 /* this is not the first row */
18849 && row
> it
->w
->desired_matrix
->rows
18850 /* previous row is not the header line */
18851 && !r1
->mode_line_p
18852 /* previous row also ends in a newline from a string */
18853 && r1
->ends_in_newline_from_string_p
)
18855 struct glyph
*start
, *end
;
18857 /* Search for the last glyph of the previous row that came
18858 from buffer or string. Depending on whether the row is
18859 L2R or R2L, we need to process it front to back or the
18860 other way round. */
18861 if (!r1
->reversed_p
)
18863 start
= r1
->glyphs
[TEXT_AREA
];
18864 end
= start
+ r1
->used
[TEXT_AREA
];
18865 /* Glyphs inserted by redisplay have an integer (zero)
18866 as their object. */
18868 && INTEGERP ((end
- 1)->object
)
18869 && (end
- 1)->charpos
<= 0)
18873 if (EQ ((end
- 1)->object
, it
->object
))
18874 seen_this_string
= 1;
18877 /* If all the glyphs of the previous row were inserted
18878 by redisplay, it means the previous row was
18879 produced from a single newline, which is only
18880 possible if that newline came from the same string
18881 as the one which produced this ROW. */
18882 seen_this_string
= 1;
18886 end
= r1
->glyphs
[TEXT_AREA
] - 1;
18887 start
= end
+ r1
->used
[TEXT_AREA
];
18889 && INTEGERP ((end
+ 1)->object
)
18890 && (end
+ 1)->charpos
<= 0)
18894 if (EQ ((end
+ 1)->object
, it
->object
))
18895 seen_this_string
= 1;
18898 seen_this_string
= 1;
18901 /* Take note of each display string that covers a newline only
18902 once, the first time we see it. This is for when a display
18903 string includes more than one newline in it. */
18904 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
18906 /* If we were scanning the buffer forward when we displayed
18907 the string, we want to account for at least one buffer
18908 position that belongs to this row (position covered by
18909 the display string), so that cursor positioning will
18910 consider this row as a candidate when point is at the end
18911 of the visual line represented by this row. This is not
18912 required when scanning back, because max_pos will already
18913 have a much larger value. */
18914 if (CHARPOS (row
->end
.pos
) > max_pos
)
18915 INC_BOTH (max_pos
, max_bpos
);
18916 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18918 else if (CHARPOS (it
->eol_pos
) > 0)
18919 SET_TEXT_POS (row
->maxpos
,
18920 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
18921 else if (row
->continued_p
)
18923 /* If max_pos is different from IT's current position, it
18924 means IT->method does not belong to the display element
18925 at max_pos. However, it also means that the display
18926 element at max_pos was displayed in its entirety on this
18927 line, which is equivalent to saying that the next line
18928 starts at the next buffer position. */
18929 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
18930 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18933 INC_BOTH (max_pos
, max_bpos
);
18934 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
18937 else if (row
->truncated_on_right_p
)
18938 /* display_line already called reseat_at_next_visible_line_start,
18939 which puts the iterator at the beginning of the next line, in
18940 the logical order. */
18941 row
->maxpos
= it
->current
.pos
;
18942 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
18943 /* A line that is entirely from a string/image/stretch... */
18944 row
->maxpos
= row
->minpos
;
18949 row
->maxpos
= it
->current
.pos
;
18952 /* Construct the glyph row IT->glyph_row in the desired matrix of
18953 IT->w from text at the current position of IT. See dispextern.h
18954 for an overview of struct it. Value is non-zero if
18955 IT->glyph_row displays text, as opposed to a line displaying ZV
18959 display_line (struct it
*it
)
18961 struct glyph_row
*row
= it
->glyph_row
;
18962 Lisp_Object overlay_arrow_string
;
18964 void *wrap_data
= NULL
;
18965 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
18966 int wrap_row_used
= -1;
18967 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
18968 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
18969 int wrap_row_extra_line_spacing
IF_LINT (= 0);
18970 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
18971 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
18973 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
18974 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18976 /* We always start displaying at hpos zero even if hscrolled. */
18977 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18979 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18980 >= it
->w
->desired_matrix
->nrows
)
18982 it
->w
->nrows_scale_factor
++;
18983 fonts_changed_p
= 1;
18987 /* Is IT->w showing the region? */
18988 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18990 /* Clear the result glyph row and enable it. */
18991 prepare_desired_row (row
);
18993 row
->y
= it
->current_y
;
18994 row
->start
= it
->start
;
18995 row
->continuation_lines_width
= it
->continuation_lines_width
;
18996 row
->displays_text_p
= 1;
18997 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18998 it
->starts_in_middle_of_char_p
= 0;
19000 /* Arrange the overlays nicely for our purposes. Usually, we call
19001 display_line on only one line at a time, in which case this
19002 can't really hurt too much, or we call it on lines which appear
19003 one after another in the buffer, in which case all calls to
19004 recenter_overlay_lists but the first will be pretty cheap. */
19005 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19007 /* Move over display elements that are not visible because we are
19008 hscrolled. This may stop at an x-position < IT->first_visible_x
19009 if the first glyph is partially visible or if we hit a line end. */
19010 if (it
->current_x
< it
->first_visible_x
)
19012 this_line_min_pos
= row
->start
.pos
;
19013 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19014 MOVE_TO_POS
| MOVE_TO_X
);
19015 /* Record the smallest positions seen while we moved over
19016 display elements that are not visible. This is needed by
19017 redisplay_internal for optimizing the case where the cursor
19018 stays inside the same line. The rest of this function only
19019 considers positions that are actually displayed, so
19020 RECORD_MAX_MIN_POS will not otherwise record positions that
19021 are hscrolled to the left of the left edge of the window. */
19022 min_pos
= CHARPOS (this_line_min_pos
);
19023 min_bpos
= BYTEPOS (this_line_min_pos
);
19027 /* We only do this when not calling `move_it_in_display_line_to'
19028 above, because move_it_in_display_line_to calls
19029 handle_line_prefix itself. */
19030 handle_line_prefix (it
);
19033 /* Get the initial row height. This is either the height of the
19034 text hscrolled, if there is any, or zero. */
19035 row
->ascent
= it
->max_ascent
;
19036 row
->height
= it
->max_ascent
+ it
->max_descent
;
19037 row
->phys_ascent
= it
->max_phys_ascent
;
19038 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19039 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19041 /* Utility macro to record max and min buffer positions seen until now. */
19042 #define RECORD_MAX_MIN_POS(IT) \
19045 int composition_p = !STRINGP ((IT)->string) \
19046 && ((IT)->what == IT_COMPOSITION); \
19047 EMACS_INT current_pos = \
19048 composition_p ? (IT)->cmp_it.charpos \
19049 : IT_CHARPOS (*(IT)); \
19050 EMACS_INT current_bpos = \
19051 composition_p ? CHAR_TO_BYTE (current_pos) \
19052 : IT_BYTEPOS (*(IT)); \
19053 if (current_pos < min_pos) \
19055 min_pos = current_pos; \
19056 min_bpos = current_bpos; \
19058 if (IT_CHARPOS (*it) > max_pos) \
19060 max_pos = IT_CHARPOS (*it); \
19061 max_bpos = IT_BYTEPOS (*it); \
19066 /* Loop generating characters. The loop is left with IT on the next
19067 character to display. */
19070 int n_glyphs_before
, hpos_before
, x_before
;
19072 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19074 /* Retrieve the next thing to display. Value is zero if end of
19076 if (!get_next_display_element (it
))
19078 /* Maybe add a space at the end of this line that is used to
19079 display the cursor there under X. Set the charpos of the
19080 first glyph of blank lines not corresponding to any text
19082 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19083 row
->exact_window_width_line_p
= 1;
19084 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19085 || row
->used
[TEXT_AREA
] == 0)
19087 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19088 row
->displays_text_p
= 0;
19090 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19091 && (!MINI_WINDOW_P (it
->w
)
19092 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19093 row
->indicate_empty_line_p
= 1;
19096 it
->continuation_lines_width
= 0;
19097 row
->ends_at_zv_p
= 1;
19098 /* A row that displays right-to-left text must always have
19099 its last face extended all the way to the end of line,
19100 even if this row ends in ZV, because we still write to
19101 the screen left to right. We also need to extend the
19102 last face if the default face is remapped to some
19103 different face, otherwise the functions that clear
19104 portions of the screen will clear with the default face's
19105 background color. */
19106 if (row
->reversed_p
19107 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19108 extend_face_to_end_of_line (it
);
19112 /* Now, get the metrics of what we want to display. This also
19113 generates glyphs in `row' (which is IT->glyph_row). */
19114 n_glyphs_before
= row
->used
[TEXT_AREA
];
19117 /* Remember the line height so far in case the next element doesn't
19118 fit on the line. */
19119 if (it
->line_wrap
!= TRUNCATE
)
19121 ascent
= it
->max_ascent
;
19122 descent
= it
->max_descent
;
19123 phys_ascent
= it
->max_phys_ascent
;
19124 phys_descent
= it
->max_phys_descent
;
19126 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19128 if (IT_DISPLAYING_WHITESPACE (it
))
19132 SAVE_IT (wrap_it
, *it
, wrap_data
);
19134 wrap_row_used
= row
->used
[TEXT_AREA
];
19135 wrap_row_ascent
= row
->ascent
;
19136 wrap_row_height
= row
->height
;
19137 wrap_row_phys_ascent
= row
->phys_ascent
;
19138 wrap_row_phys_height
= row
->phys_height
;
19139 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19140 wrap_row_min_pos
= min_pos
;
19141 wrap_row_min_bpos
= min_bpos
;
19142 wrap_row_max_pos
= max_pos
;
19143 wrap_row_max_bpos
= max_bpos
;
19149 PRODUCE_GLYPHS (it
);
19151 /* If this display element was in marginal areas, continue with
19153 if (it
->area
!= TEXT_AREA
)
19155 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19156 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19157 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19158 row
->phys_height
= max (row
->phys_height
,
19159 it
->max_phys_ascent
+ it
->max_phys_descent
);
19160 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19161 it
->max_extra_line_spacing
);
19162 set_iterator_to_next (it
, 1);
19166 /* Does the display element fit on the line? If we truncate
19167 lines, we should draw past the right edge of the window. If
19168 we don't truncate, we want to stop so that we can display the
19169 continuation glyph before the right margin. If lines are
19170 continued, there are two possible strategies for characters
19171 resulting in more than 1 glyph (e.g. tabs): Display as many
19172 glyphs as possible in this line and leave the rest for the
19173 continuation line, or display the whole element in the next
19174 line. Original redisplay did the former, so we do it also. */
19175 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19176 hpos_before
= it
->hpos
;
19179 if (/* Not a newline. */
19181 /* Glyphs produced fit entirely in the line. */
19182 && it
->current_x
< it
->last_visible_x
)
19184 it
->hpos
+= nglyphs
;
19185 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19186 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19187 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19188 row
->phys_height
= max (row
->phys_height
,
19189 it
->max_phys_ascent
+ it
->max_phys_descent
);
19190 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19191 it
->max_extra_line_spacing
);
19192 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19193 row
->x
= x
- it
->first_visible_x
;
19194 /* Record the maximum and minimum buffer positions seen so
19195 far in glyphs that will be displayed by this row. */
19197 RECORD_MAX_MIN_POS (it
);
19202 struct glyph
*glyph
;
19204 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19206 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19207 new_x
= x
+ glyph
->pixel_width
;
19209 if (/* Lines are continued. */
19210 it
->line_wrap
!= TRUNCATE
19211 && (/* Glyph doesn't fit on the line. */
19212 new_x
> it
->last_visible_x
19213 /* Or it fits exactly on a window system frame. */
19214 || (new_x
== it
->last_visible_x
19215 && FRAME_WINDOW_P (it
->f
))))
19217 /* End of a continued line. */
19220 || (new_x
== it
->last_visible_x
19221 && FRAME_WINDOW_P (it
->f
)))
19223 /* Current glyph is the only one on the line or
19224 fits exactly on the line. We must continue
19225 the line because we can't draw the cursor
19226 after the glyph. */
19227 row
->continued_p
= 1;
19228 it
->current_x
= new_x
;
19229 it
->continuation_lines_width
+= new_x
;
19231 if (i
== nglyphs
- 1)
19233 /* If line-wrap is on, check if a previous
19234 wrap point was found. */
19235 if (wrap_row_used
> 0
19236 /* Even if there is a previous wrap
19237 point, continue the line here as
19238 usual, if (i) the previous character
19239 was a space or tab AND (ii) the
19240 current character is not. */
19242 || IT_DISPLAYING_WHITESPACE (it
)))
19245 /* Record the maximum and minimum buffer
19246 positions seen so far in glyphs that will be
19247 displayed by this row. */
19249 RECORD_MAX_MIN_POS (it
);
19250 set_iterator_to_next (it
, 1);
19251 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19253 if (!get_next_display_element (it
))
19255 row
->exact_window_width_line_p
= 1;
19256 it
->continuation_lines_width
= 0;
19257 row
->continued_p
= 0;
19258 row
->ends_at_zv_p
= 1;
19260 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19262 row
->continued_p
= 0;
19263 row
->exact_window_width_line_p
= 1;
19267 else if (it
->bidi_p
)
19268 RECORD_MAX_MIN_POS (it
);
19270 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19271 && !FRAME_WINDOW_P (it
->f
))
19273 /* A padding glyph that doesn't fit on this line.
19274 This means the whole character doesn't fit
19276 if (row
->reversed_p
)
19277 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19278 - n_glyphs_before
);
19279 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19281 /* Fill the rest of the row with continuation
19282 glyphs like in 20.x. */
19283 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19284 < row
->glyphs
[1 + TEXT_AREA
])
19285 produce_special_glyphs (it
, IT_CONTINUATION
);
19287 row
->continued_p
= 1;
19288 it
->current_x
= x_before
;
19289 it
->continuation_lines_width
+= x_before
;
19291 /* Restore the height to what it was before the
19292 element not fitting on the line. */
19293 it
->max_ascent
= ascent
;
19294 it
->max_descent
= descent
;
19295 it
->max_phys_ascent
= phys_ascent
;
19296 it
->max_phys_descent
= phys_descent
;
19298 else if (wrap_row_used
> 0)
19301 if (row
->reversed_p
)
19302 unproduce_glyphs (it
,
19303 row
->used
[TEXT_AREA
] - wrap_row_used
);
19304 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19305 it
->continuation_lines_width
+= wrap_x
;
19306 row
->used
[TEXT_AREA
] = wrap_row_used
;
19307 row
->ascent
= wrap_row_ascent
;
19308 row
->height
= wrap_row_height
;
19309 row
->phys_ascent
= wrap_row_phys_ascent
;
19310 row
->phys_height
= wrap_row_phys_height
;
19311 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19312 min_pos
= wrap_row_min_pos
;
19313 min_bpos
= wrap_row_min_bpos
;
19314 max_pos
= wrap_row_max_pos
;
19315 max_bpos
= wrap_row_max_bpos
;
19316 row
->continued_p
= 1;
19317 row
->ends_at_zv_p
= 0;
19318 row
->exact_window_width_line_p
= 0;
19319 it
->continuation_lines_width
+= x
;
19321 /* Make sure that a non-default face is extended
19322 up to the right margin of the window. */
19323 extend_face_to_end_of_line (it
);
19325 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19327 /* A TAB that extends past the right edge of the
19328 window. This produces a single glyph on
19329 window system frames. We leave the glyph in
19330 this row and let it fill the row, but don't
19331 consume the TAB. */
19332 it
->continuation_lines_width
+= it
->last_visible_x
;
19333 row
->ends_in_middle_of_char_p
= 1;
19334 row
->continued_p
= 1;
19335 glyph
->pixel_width
= it
->last_visible_x
- x
;
19336 it
->starts_in_middle_of_char_p
= 1;
19340 /* Something other than a TAB that draws past
19341 the right edge of the window. Restore
19342 positions to values before the element. */
19343 if (row
->reversed_p
)
19344 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19345 - (n_glyphs_before
+ i
));
19346 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19348 /* Display continuation glyphs. */
19349 if (!FRAME_WINDOW_P (it
->f
))
19350 produce_special_glyphs (it
, IT_CONTINUATION
);
19351 row
->continued_p
= 1;
19353 it
->current_x
= x_before
;
19354 it
->continuation_lines_width
+= x
;
19355 extend_face_to_end_of_line (it
);
19357 if (nglyphs
> 1 && i
> 0)
19359 row
->ends_in_middle_of_char_p
= 1;
19360 it
->starts_in_middle_of_char_p
= 1;
19363 /* Restore the height to what it was before the
19364 element not fitting on the line. */
19365 it
->max_ascent
= ascent
;
19366 it
->max_descent
= descent
;
19367 it
->max_phys_ascent
= phys_ascent
;
19368 it
->max_phys_descent
= phys_descent
;
19373 else if (new_x
> it
->first_visible_x
)
19375 /* Increment number of glyphs actually displayed. */
19378 /* Record the maximum and minimum buffer positions
19379 seen so far in glyphs that will be displayed by
19382 RECORD_MAX_MIN_POS (it
);
19384 if (x
< it
->first_visible_x
)
19385 /* Glyph is partially visible, i.e. row starts at
19386 negative X position. */
19387 row
->x
= x
- it
->first_visible_x
;
19391 /* Glyph is completely off the left margin of the
19392 window. This should not happen because of the
19393 move_it_in_display_line at the start of this
19394 function, unless the text display area of the
19395 window is empty. */
19396 xassert (it
->first_visible_x
<= it
->last_visible_x
);
19399 /* Even if this display element produced no glyphs at all,
19400 we want to record its position. */
19401 if (it
->bidi_p
&& nglyphs
== 0)
19402 RECORD_MAX_MIN_POS (it
);
19404 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19405 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19406 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19407 row
->phys_height
= max (row
->phys_height
,
19408 it
->max_phys_ascent
+ it
->max_phys_descent
);
19409 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19410 it
->max_extra_line_spacing
);
19412 /* End of this display line if row is continued. */
19413 if (row
->continued_p
|| row
->ends_at_zv_p
)
19418 /* Is this a line end? If yes, we're also done, after making
19419 sure that a non-default face is extended up to the right
19420 margin of the window. */
19421 if (ITERATOR_AT_END_OF_LINE_P (it
))
19423 int used_before
= row
->used
[TEXT_AREA
];
19425 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19427 /* Add a space at the end of the line that is used to
19428 display the cursor there. */
19429 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19430 append_space_for_newline (it
, 0);
19432 /* Extend the face to the end of the line. */
19433 extend_face_to_end_of_line (it
);
19435 /* Make sure we have the position. */
19436 if (used_before
== 0)
19437 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19439 /* Record the position of the newline, for use in
19441 it
->eol_pos
= it
->current
.pos
;
19443 /* Consume the line end. This skips over invisible lines. */
19444 set_iterator_to_next (it
, 1);
19445 it
->continuation_lines_width
= 0;
19449 /* Proceed with next display element. Note that this skips
19450 over lines invisible because of selective display. */
19451 set_iterator_to_next (it
, 1);
19453 /* If we truncate lines, we are done when the last displayed
19454 glyphs reach past the right margin of the window. */
19455 if (it
->line_wrap
== TRUNCATE
19456 && (FRAME_WINDOW_P (it
->f
)
19457 ? (it
->current_x
>= it
->last_visible_x
)
19458 : (it
->current_x
> it
->last_visible_x
)))
19460 /* Maybe add truncation glyphs. */
19461 if (!FRAME_WINDOW_P (it
->f
))
19465 if (!row
->reversed_p
)
19467 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19468 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19473 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19474 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19476 /* Remove any padding glyphs at the front of ROW, to
19477 make room for the truncation glyphs we will be
19478 adding below. The loop below always inserts at
19479 least one truncation glyph, so also remove the
19480 last glyph added to ROW. */
19481 unproduce_glyphs (it
, i
+ 1);
19482 /* Adjust i for the loop below. */
19483 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19486 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19488 row
->used
[TEXT_AREA
] = i
;
19489 produce_special_glyphs (it
, IT_TRUNCATION
);
19492 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19494 /* Don't truncate if we can overflow newline into fringe. */
19495 if (!get_next_display_element (it
))
19497 it
->continuation_lines_width
= 0;
19498 row
->ends_at_zv_p
= 1;
19499 row
->exact_window_width_line_p
= 1;
19502 if (ITERATOR_AT_END_OF_LINE_P (it
))
19504 row
->exact_window_width_line_p
= 1;
19505 goto at_end_of_line
;
19509 row
->truncated_on_right_p
= 1;
19510 it
->continuation_lines_width
= 0;
19511 reseat_at_next_visible_line_start (it
, 0);
19512 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19513 it
->hpos
= hpos_before
;
19514 it
->current_x
= x_before
;
19520 bidi_unshelve_cache (wrap_data
, 1);
19522 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19523 at the left window margin. */
19524 if (it
->first_visible_x
19525 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19527 if (!FRAME_WINDOW_P (it
->f
))
19528 insert_left_trunc_glyphs (it
);
19529 row
->truncated_on_left_p
= 1;
19532 /* Remember the position at which this line ends.
19534 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19535 cannot be before the call to find_row_edges below, since that is
19536 where these positions are determined. */
19537 row
->end
= it
->current
;
19540 row
->minpos
= row
->start
.pos
;
19541 row
->maxpos
= row
->end
.pos
;
19545 /* ROW->minpos and ROW->maxpos must be the smallest and
19546 `1 + the largest' buffer positions in ROW. But if ROW was
19547 bidi-reordered, these two positions can be anywhere in the
19548 row, so we must determine them now. */
19549 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19552 /* If the start of this line is the overlay arrow-position, then
19553 mark this glyph row as the one containing the overlay arrow.
19554 This is clearly a mess with variable size fonts. It would be
19555 better to let it be displayed like cursors under X. */
19556 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19557 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19558 !NILP (overlay_arrow_string
)))
19560 /* Overlay arrow in window redisplay is a fringe bitmap. */
19561 if (STRINGP (overlay_arrow_string
))
19563 struct glyph_row
*arrow_row
19564 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19565 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19566 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19567 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19568 struct glyph
*p2
, *end
;
19570 /* Copy the arrow glyphs. */
19571 while (glyph
< arrow_end
)
19574 /* Throw away padding glyphs. */
19576 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19577 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19583 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19588 xassert (INTEGERP (overlay_arrow_string
));
19589 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19591 overlay_arrow_seen
= 1;
19594 /* Highlight trailing whitespace. */
19595 if (!NILP (Vshow_trailing_whitespace
))
19596 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19598 /* Compute pixel dimensions of this line. */
19599 compute_line_metrics (it
);
19601 /* Implementation note: No changes in the glyphs of ROW or in their
19602 faces can be done past this point, because compute_line_metrics
19603 computes ROW's hash value and stores it within the glyph_row
19606 /* Record whether this row ends inside an ellipsis. */
19607 row
->ends_in_ellipsis_p
19608 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19609 && it
->ellipsis_p
);
19611 /* Save fringe bitmaps in this row. */
19612 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19613 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19614 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19615 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19617 it
->left_user_fringe_bitmap
= 0;
19618 it
->left_user_fringe_face_id
= 0;
19619 it
->right_user_fringe_bitmap
= 0;
19620 it
->right_user_fringe_face_id
= 0;
19622 /* Maybe set the cursor. */
19623 cvpos
= it
->w
->cursor
.vpos
;
19625 /* In bidi-reordered rows, keep checking for proper cursor
19626 position even if one has been found already, because buffer
19627 positions in such rows change non-linearly with ROW->VPOS,
19628 when a line is continued. One exception: when we are at ZV,
19629 display cursor on the first suitable glyph row, since all
19630 the empty rows after that also have their position set to ZV. */
19631 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19632 lines' rows is implemented for bidi-reordered rows. */
19634 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19635 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19636 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19637 && cursor_row_p (row
))
19638 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19640 /* Prepare for the next line. This line starts horizontally at (X
19641 HPOS) = (0 0). Vertical positions are incremented. As a
19642 convenience for the caller, IT->glyph_row is set to the next
19644 it
->current_x
= it
->hpos
= 0;
19645 it
->current_y
+= row
->height
;
19646 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19649 /* The next row should by default use the same value of the
19650 reversed_p flag as this one. set_iterator_to_next decides when
19651 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19652 the flag accordingly. */
19653 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19654 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19655 it
->start
= row
->end
;
19656 return row
->displays_text_p
;
19658 #undef RECORD_MAX_MIN_POS
19661 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19662 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19663 doc
: /* Return paragraph direction at point in BUFFER.
19664 Value is either `left-to-right' or `right-to-left'.
19665 If BUFFER is omitted or nil, it defaults to the current buffer.
19667 Paragraph direction determines how the text in the paragraph is displayed.
19668 In left-to-right paragraphs, text begins at the left margin of the window
19669 and the reading direction is generally left to right. In right-to-left
19670 paragraphs, text begins at the right margin and is read from right to left.
19672 See also `bidi-paragraph-direction'. */)
19673 (Lisp_Object buffer
)
19675 struct buffer
*buf
= current_buffer
;
19676 struct buffer
*old
= buf
;
19678 if (! NILP (buffer
))
19680 CHECK_BUFFER (buffer
);
19681 buf
= XBUFFER (buffer
);
19684 if (NILP (BVAR (buf
, bidi_display_reordering
))
19685 || NILP (BVAR (buf
, enable_multibyte_characters
))
19686 /* When we are loading loadup.el, the character property tables
19687 needed for bidi iteration are not yet available. */
19688 || !NILP (Vpurify_flag
))
19689 return Qleft_to_right
;
19690 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19691 return BVAR (buf
, bidi_paragraph_direction
);
19694 /* Determine the direction from buffer text. We could try to
19695 use current_matrix if it is up to date, but this seems fast
19696 enough as it is. */
19697 struct bidi_it itb
;
19698 EMACS_INT pos
= BUF_PT (buf
);
19699 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
19701 void *itb_data
= bidi_shelve_cache ();
19703 set_buffer_temp (buf
);
19704 /* bidi_paragraph_init finds the base direction of the paragraph
19705 by searching forward from paragraph start. We need the base
19706 direction of the current or _previous_ paragraph, so we need
19707 to make sure we are within that paragraph. To that end, find
19708 the previous non-empty line. */
19709 if (pos
>= ZV
&& pos
> BEGV
)
19712 bytepos
= CHAR_TO_BYTE (pos
);
19714 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19715 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19717 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19718 || c
== ' ' || c
== '\t' || c
== '\f')
19720 if (bytepos
<= BEGV_BYTE
)
19725 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19728 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19729 itb
.paragraph_dir
= NEUTRAL_DIR
;
19730 itb
.string
.s
= NULL
;
19731 itb
.string
.lstring
= Qnil
;
19732 itb
.string
.bufpos
= 0;
19733 itb
.string
.unibyte
= 0;
19734 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19735 bidi_unshelve_cache (itb_data
, 0);
19736 set_buffer_temp (old
);
19737 switch (itb
.paragraph_dir
)
19740 return Qleft_to_right
;
19743 return Qright_to_left
;
19753 /***********************************************************************
19755 ***********************************************************************/
19757 /* Redisplay the menu bar in the frame for window W.
19759 The menu bar of X frames that don't have X toolkit support is
19760 displayed in a special window W->frame->menu_bar_window.
19762 The menu bar of terminal frames is treated specially as far as
19763 glyph matrices are concerned. Menu bar lines are not part of
19764 windows, so the update is done directly on the frame matrix rows
19765 for the menu bar. */
19768 display_menu_bar (struct window
*w
)
19770 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19775 /* Don't do all this for graphical frames. */
19777 if (FRAME_W32_P (f
))
19780 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19786 if (FRAME_NS_P (f
))
19788 #endif /* HAVE_NS */
19790 #ifdef USE_X_TOOLKIT
19791 xassert (!FRAME_WINDOW_P (f
));
19792 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19793 it
.first_visible_x
= 0;
19794 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19795 #else /* not USE_X_TOOLKIT */
19796 if (FRAME_WINDOW_P (f
))
19798 /* Menu bar lines are displayed in the desired matrix of the
19799 dummy window menu_bar_window. */
19800 struct window
*menu_w
;
19801 xassert (WINDOWP (f
->menu_bar_window
));
19802 menu_w
= XWINDOW (f
->menu_bar_window
);
19803 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19805 it
.first_visible_x
= 0;
19806 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19810 /* This is a TTY frame, i.e. character hpos/vpos are used as
19812 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
19814 it
.first_visible_x
= 0;
19815 it
.last_visible_x
= FRAME_COLS (f
);
19817 #endif /* not USE_X_TOOLKIT */
19819 /* FIXME: This should be controlled by a user option. See the
19820 comments in redisplay_tool_bar and display_mode_line about
19822 it
.paragraph_embedding
= L2R
;
19824 if (! mode_line_inverse_video
)
19825 /* Force the menu-bar to be displayed in the default face. */
19826 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
19828 /* Clear all rows of the menu bar. */
19829 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
19831 struct glyph_row
*row
= it
.glyph_row
+ i
;
19832 clear_glyph_row (row
);
19833 row
->enabled_p
= 1;
19834 row
->full_width_p
= 1;
19837 /* Display all items of the menu bar. */
19838 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
19839 for (i
= 0; i
< ASIZE (items
); i
+= 4)
19841 Lisp_Object string
;
19843 /* Stop at nil string. */
19844 string
= AREF (items
, i
+ 1);
19848 /* Remember where item was displayed. */
19849 ASET (items
, i
+ 3, make_number (it
.hpos
));
19851 /* Display the item, pad with one space. */
19852 if (it
.current_x
< it
.last_visible_x
)
19853 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
19854 SCHARS (string
) + 1, 0, 0, -1);
19857 /* Fill out the line with spaces. */
19858 if (it
.current_x
< it
.last_visible_x
)
19859 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
19861 /* Compute the total height of the lines. */
19862 compute_line_metrics (&it
);
19867 /***********************************************************************
19869 ***********************************************************************/
19871 /* Redisplay mode lines in the window tree whose root is WINDOW. If
19872 FORCE is non-zero, redisplay mode lines unconditionally.
19873 Otherwise, redisplay only mode lines that are garbaged. Value is
19874 the number of windows whose mode lines were redisplayed. */
19877 redisplay_mode_lines (Lisp_Object window
, int force
)
19881 while (!NILP (window
))
19883 struct window
*w
= XWINDOW (window
);
19885 if (WINDOWP (w
->hchild
))
19886 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
19887 else if (WINDOWP (w
->vchild
))
19888 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
19890 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
19891 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
19893 struct text_pos lpoint
;
19894 struct buffer
*old
= current_buffer
;
19896 /* Set the window's buffer for the mode line display. */
19897 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
19898 set_buffer_internal_1 (XBUFFER (w
->buffer
));
19900 /* Point refers normally to the selected window. For any
19901 other window, set up appropriate value. */
19902 if (!EQ (window
, selected_window
))
19904 struct text_pos pt
;
19906 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
19907 if (CHARPOS (pt
) < BEGV
)
19908 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
19909 else if (CHARPOS (pt
) > (ZV
- 1))
19910 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
19912 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
19915 /* Display mode lines. */
19916 clear_glyph_matrix (w
->desired_matrix
);
19917 if (display_mode_lines (w
))
19920 w
->must_be_updated_p
= 1;
19923 /* Restore old settings. */
19924 set_buffer_internal_1 (old
);
19925 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
19935 /* Display the mode and/or header line of window W. Value is the
19936 sum number of mode lines and header lines displayed. */
19939 display_mode_lines (struct window
*w
)
19941 Lisp_Object old_selected_window
, old_selected_frame
;
19944 old_selected_frame
= selected_frame
;
19945 selected_frame
= w
->frame
;
19946 old_selected_window
= selected_window
;
19947 XSETWINDOW (selected_window
, w
);
19949 /* These will be set while the mode line specs are processed. */
19950 line_number_displayed
= 0;
19951 w
->column_number_displayed
= Qnil
;
19953 if (WINDOW_WANTS_MODELINE_P (w
))
19955 struct window
*sel_w
= XWINDOW (old_selected_window
);
19957 /* Select mode line face based on the real selected window. */
19958 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
19959 BVAR (current_buffer
, mode_line_format
));
19963 if (WINDOW_WANTS_HEADER_LINE_P (w
))
19965 display_mode_line (w
, HEADER_LINE_FACE_ID
,
19966 BVAR (current_buffer
, header_line_format
));
19970 selected_frame
= old_selected_frame
;
19971 selected_window
= old_selected_window
;
19976 /* Display mode or header line of window W. FACE_ID specifies which
19977 line to display; it is either MODE_LINE_FACE_ID or
19978 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
19979 display. Value is the pixel height of the mode/header line
19983 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
19987 int count
= SPECPDL_INDEX ();
19989 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19990 /* Don't extend on a previously drawn mode-line.
19991 This may happen if called from pos_visible_p. */
19992 it
.glyph_row
->enabled_p
= 0;
19993 prepare_desired_row (it
.glyph_row
);
19995 it
.glyph_row
->mode_line_p
= 1;
19997 if (! mode_line_inverse_video
)
19998 /* Force the mode-line to be displayed in the default face. */
19999 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20001 /* FIXME: This should be controlled by a user option. But
20002 supporting such an option is not trivial, since the mode line is
20003 made up of many separate strings. */
20004 it
.paragraph_embedding
= L2R
;
20006 record_unwind_protect (unwind_format_mode_line
,
20007 format_mode_line_unwind_data (NULL
, Qnil
, 0));
20009 mode_line_target
= MODE_LINE_DISPLAY
;
20011 /* Temporarily make frame's keyboard the current kboard so that
20012 kboard-local variables in the mode_line_format will get the right
20014 push_kboard (FRAME_KBOARD (it
.f
));
20015 record_unwind_save_match_data ();
20016 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20019 unbind_to (count
, Qnil
);
20021 /* Fill up with spaces. */
20022 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20024 compute_line_metrics (&it
);
20025 it
.glyph_row
->full_width_p
= 1;
20026 it
.glyph_row
->continued_p
= 0;
20027 it
.glyph_row
->truncated_on_left_p
= 0;
20028 it
.glyph_row
->truncated_on_right_p
= 0;
20030 /* Make a 3D mode-line have a shadow at its right end. */
20031 face
= FACE_FROM_ID (it
.f
, face_id
);
20032 extend_face_to_end_of_line (&it
);
20033 if (face
->box
!= FACE_NO_BOX
)
20035 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20036 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20037 last
->right_box_line_p
= 1;
20040 return it
.glyph_row
->height
;
20043 /* Move element ELT in LIST to the front of LIST.
20044 Return the updated list. */
20047 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20049 register Lisp_Object tail
, prev
;
20050 register Lisp_Object tem
;
20054 while (CONSP (tail
))
20060 /* Splice out the link TAIL. */
20062 list
= XCDR (tail
);
20064 Fsetcdr (prev
, XCDR (tail
));
20066 /* Now make it the first. */
20067 Fsetcdr (tail
, list
);
20072 tail
= XCDR (tail
);
20076 /* Not found--return unchanged LIST. */
20080 /* Contribute ELT to the mode line for window IT->w. How it
20081 translates into text depends on its data type.
20083 IT describes the display environment in which we display, as usual.
20085 DEPTH is the depth in recursion. It is used to prevent
20086 infinite recursion here.
20088 FIELD_WIDTH is the number of characters the display of ELT should
20089 occupy in the mode line, and PRECISION is the maximum number of
20090 characters to display from ELT's representation. See
20091 display_string for details.
20093 Returns the hpos of the end of the text generated by ELT.
20095 PROPS is a property list to add to any string we encounter.
20097 If RISKY is nonzero, remove (disregard) any properties in any string
20098 we encounter, and ignore :eval and :propertize.
20100 The global variable `mode_line_target' determines whether the
20101 output is passed to `store_mode_line_noprop',
20102 `store_mode_line_string', or `display_string'. */
20105 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20106 Lisp_Object elt
, Lisp_Object props
, int risky
)
20108 int n
= 0, field
, prec
;
20113 elt
= build_string ("*too-deep*");
20117 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
20121 /* A string: output it and check for %-constructs within it. */
20123 EMACS_INT offset
= 0;
20125 if (SCHARS (elt
) > 0
20126 && (!NILP (props
) || risky
))
20128 Lisp_Object oprops
, aelt
;
20129 oprops
= Ftext_properties_at (make_number (0), elt
);
20131 /* If the starting string's properties are not what
20132 we want, translate the string. Also, if the string
20133 is risky, do that anyway. */
20135 if (NILP (Fequal (props
, oprops
)) || risky
)
20137 /* If the starting string has properties,
20138 merge the specified ones onto the existing ones. */
20139 if (! NILP (oprops
) && !risky
)
20143 oprops
= Fcopy_sequence (oprops
);
20145 while (CONSP (tem
))
20147 oprops
= Fplist_put (oprops
, XCAR (tem
),
20148 XCAR (XCDR (tem
)));
20149 tem
= XCDR (XCDR (tem
));
20154 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20155 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20157 /* AELT is what we want. Move it to the front
20158 without consing. */
20160 mode_line_proptrans_alist
20161 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20167 /* If AELT has the wrong props, it is useless.
20168 so get rid of it. */
20170 mode_line_proptrans_alist
20171 = Fdelq (aelt
, mode_line_proptrans_alist
);
20173 elt
= Fcopy_sequence (elt
);
20174 Fset_text_properties (make_number (0), Flength (elt
),
20176 /* Add this item to mode_line_proptrans_alist. */
20177 mode_line_proptrans_alist
20178 = Fcons (Fcons (elt
, props
),
20179 mode_line_proptrans_alist
);
20180 /* Truncate mode_line_proptrans_alist
20181 to at most 50 elements. */
20182 tem
= Fnthcdr (make_number (50),
20183 mode_line_proptrans_alist
);
20185 XSETCDR (tem
, Qnil
);
20194 prec
= precision
- n
;
20195 switch (mode_line_target
)
20197 case MODE_LINE_NOPROP
:
20198 case MODE_LINE_TITLE
:
20199 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20201 case MODE_LINE_STRING
:
20202 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20204 case MODE_LINE_DISPLAY
:
20205 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20206 0, prec
, 0, STRING_MULTIBYTE (elt
));
20213 /* Handle the non-literal case. */
20215 while ((precision
<= 0 || n
< precision
)
20216 && SREF (elt
, offset
) != 0
20217 && (mode_line_target
!= MODE_LINE_DISPLAY
20218 || it
->current_x
< it
->last_visible_x
))
20220 EMACS_INT last_offset
= offset
;
20222 /* Advance to end of string or next format specifier. */
20223 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20226 if (offset
- 1 != last_offset
)
20228 EMACS_INT nchars
, nbytes
;
20230 /* Output to end of string or up to '%'. Field width
20231 is length of string. Don't output more than
20232 PRECISION allows us. */
20235 prec
= c_string_width (SDATA (elt
) + last_offset
,
20236 offset
- last_offset
, precision
- n
,
20239 switch (mode_line_target
)
20241 case MODE_LINE_NOPROP
:
20242 case MODE_LINE_TITLE
:
20243 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20245 case MODE_LINE_STRING
:
20247 EMACS_INT bytepos
= last_offset
;
20248 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
20249 EMACS_INT endpos
= (precision
<= 0
20250 ? string_byte_to_char (elt
, offset
)
20251 : charpos
+ nchars
);
20253 n
+= store_mode_line_string (NULL
,
20254 Fsubstring (elt
, make_number (charpos
),
20255 make_number (endpos
)),
20259 case MODE_LINE_DISPLAY
:
20261 EMACS_INT bytepos
= last_offset
;
20262 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
20264 if (precision
<= 0)
20265 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20266 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20268 STRING_MULTIBYTE (elt
));
20273 else /* c == '%' */
20275 EMACS_INT percent_position
= offset
;
20277 /* Get the specified minimum width. Zero means
20280 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20281 field
= field
* 10 + c
- '0';
20283 /* Don't pad beyond the total padding allowed. */
20284 if (field_width
- n
> 0 && field
> field_width
- n
)
20285 field
= field_width
- n
;
20287 /* Note that either PRECISION <= 0 or N < PRECISION. */
20288 prec
= precision
- n
;
20291 n
+= display_mode_element (it
, depth
, field
, prec
,
20292 Vglobal_mode_string
, props
,
20297 EMACS_INT bytepos
, charpos
;
20299 Lisp_Object string
;
20301 bytepos
= percent_position
;
20302 charpos
= (STRING_MULTIBYTE (elt
)
20303 ? string_byte_to_char (elt
, bytepos
)
20305 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20306 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20308 switch (mode_line_target
)
20310 case MODE_LINE_NOPROP
:
20311 case MODE_LINE_TITLE
:
20312 n
+= store_mode_line_noprop (spec
, field
, prec
);
20314 case MODE_LINE_STRING
:
20316 Lisp_Object tem
= build_string (spec
);
20317 props
= Ftext_properties_at (make_number (charpos
), elt
);
20318 /* Should only keep face property in props */
20319 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20322 case MODE_LINE_DISPLAY
:
20324 int nglyphs_before
, nwritten
;
20326 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20327 nwritten
= display_string (spec
, string
, elt
,
20332 /* Assign to the glyphs written above the
20333 string where the `%x' came from, position
20337 struct glyph
*glyph
20338 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20342 for (i
= 0; i
< nwritten
; ++i
)
20344 glyph
[i
].object
= elt
;
20345 glyph
[i
].charpos
= charpos
;
20362 /* A symbol: process the value of the symbol recursively
20363 as if it appeared here directly. Avoid error if symbol void.
20364 Special case: if value of symbol is a string, output the string
20367 register Lisp_Object tem
;
20369 /* If the variable is not marked as risky to set
20370 then its contents are risky to use. */
20371 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20374 tem
= Fboundp (elt
);
20377 tem
= Fsymbol_value (elt
);
20378 /* If value is a string, output that string literally:
20379 don't check for % within it. */
20383 if (!EQ (tem
, elt
))
20385 /* Give up right away for nil or t. */
20395 register Lisp_Object car
, tem
;
20397 /* A cons cell: five distinct cases.
20398 If first element is :eval or :propertize, do something special.
20399 If first element is a string or a cons, process all the elements
20400 and effectively concatenate them.
20401 If first element is a negative number, truncate displaying cdr to
20402 at most that many characters. If positive, pad (with spaces)
20403 to at least that many characters.
20404 If first element is a symbol, process the cadr or caddr recursively
20405 according to whether the symbol's value is non-nil or nil. */
20407 if (EQ (car
, QCeval
))
20409 /* An element of the form (:eval FORM) means evaluate FORM
20410 and use the result as mode line elements. */
20415 if (CONSP (XCDR (elt
)))
20418 spec
= safe_eval (XCAR (XCDR (elt
)));
20419 n
+= display_mode_element (it
, depth
, field_width
- n
,
20420 precision
- n
, spec
, props
,
20424 else if (EQ (car
, QCpropertize
))
20426 /* An element of the form (:propertize ELT PROPS...)
20427 means display ELT but applying properties PROPS. */
20432 if (CONSP (XCDR (elt
)))
20433 n
+= display_mode_element (it
, depth
, field_width
- n
,
20434 precision
- n
, XCAR (XCDR (elt
)),
20435 XCDR (XCDR (elt
)), risky
);
20437 else if (SYMBOLP (car
))
20439 tem
= Fboundp (car
);
20443 /* elt is now the cdr, and we know it is a cons cell.
20444 Use its car if CAR has a non-nil value. */
20447 tem
= Fsymbol_value (car
);
20454 /* Symbol's value is nil (or symbol is unbound)
20455 Get the cddr of the original list
20456 and if possible find the caddr and use that. */
20460 else if (!CONSP (elt
))
20465 else if (INTEGERP (car
))
20467 register int lim
= XINT (car
);
20471 /* Negative int means reduce maximum width. */
20472 if (precision
<= 0)
20475 precision
= min (precision
, -lim
);
20479 /* Padding specified. Don't let it be more than
20480 current maximum. */
20482 lim
= min (precision
, lim
);
20484 /* If that's more padding than already wanted, queue it.
20485 But don't reduce padding already specified even if
20486 that is beyond the current truncation point. */
20487 field_width
= max (lim
, field_width
);
20491 else if (STRINGP (car
) || CONSP (car
))
20493 Lisp_Object halftail
= elt
;
20497 && (precision
<= 0 || n
< precision
))
20499 n
+= display_mode_element (it
, depth
,
20500 /* Do padding only after the last
20501 element in the list. */
20502 (! CONSP (XCDR (elt
))
20505 precision
- n
, XCAR (elt
),
20509 if ((len
& 1) == 0)
20510 halftail
= XCDR (halftail
);
20511 /* Check for cycle. */
20512 if (EQ (halftail
, elt
))
20521 elt
= build_string ("*invalid*");
20525 /* Pad to FIELD_WIDTH. */
20526 if (field_width
> 0 && n
< field_width
)
20528 switch (mode_line_target
)
20530 case MODE_LINE_NOPROP
:
20531 case MODE_LINE_TITLE
:
20532 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20534 case MODE_LINE_STRING
:
20535 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20537 case MODE_LINE_DISPLAY
:
20538 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20547 /* Store a mode-line string element in mode_line_string_list.
20549 If STRING is non-null, display that C string. Otherwise, the Lisp
20550 string LISP_STRING is displayed.
20552 FIELD_WIDTH is the minimum number of output glyphs to produce.
20553 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20554 with spaces. FIELD_WIDTH <= 0 means don't pad.
20556 PRECISION is the maximum number of characters to output from
20557 STRING. PRECISION <= 0 means don't truncate the string.
20559 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20560 properties to the string.
20562 PROPS are the properties to add to the string.
20563 The mode_line_string_face face property is always added to the string.
20567 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20568 int field_width
, int precision
, Lisp_Object props
)
20573 if (string
!= NULL
)
20575 len
= strlen (string
);
20576 if (precision
> 0 && len
> precision
)
20578 lisp_string
= make_string (string
, len
);
20580 props
= mode_line_string_face_prop
;
20581 else if (!NILP (mode_line_string_face
))
20583 Lisp_Object face
= Fplist_get (props
, Qface
);
20584 props
= Fcopy_sequence (props
);
20586 face
= mode_line_string_face
;
20588 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20589 props
= Fplist_put (props
, Qface
, face
);
20591 Fadd_text_properties (make_number (0), make_number (len
),
20592 props
, lisp_string
);
20596 len
= XFASTINT (Flength (lisp_string
));
20597 if (precision
> 0 && len
> precision
)
20600 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20603 if (!NILP (mode_line_string_face
))
20607 props
= Ftext_properties_at (make_number (0), lisp_string
);
20608 face
= Fplist_get (props
, Qface
);
20610 face
= mode_line_string_face
;
20612 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20613 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20615 lisp_string
= Fcopy_sequence (lisp_string
);
20618 Fadd_text_properties (make_number (0), make_number (len
),
20619 props
, lisp_string
);
20624 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20628 if (field_width
> len
)
20630 field_width
-= len
;
20631 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20633 Fadd_text_properties (make_number (0), make_number (field_width
),
20634 props
, lisp_string
);
20635 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20643 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20645 doc
: /* Format a string out of a mode line format specification.
20646 First arg FORMAT specifies the mode line format (see `mode-line-format'
20647 for details) to use.
20649 By default, the format is evaluated for the currently selected window.
20651 Optional second arg FACE specifies the face property to put on all
20652 characters for which no face is specified. The value nil means the
20653 default face. The value t means whatever face the window's mode line
20654 currently uses (either `mode-line' or `mode-line-inactive',
20655 depending on whether the window is the selected window or not).
20656 An integer value means the value string has no text
20659 Optional third and fourth args WINDOW and BUFFER specify the window
20660 and buffer to use as the context for the formatting (defaults
20661 are the selected window and the WINDOW's buffer). */)
20662 (Lisp_Object format
, Lisp_Object face
,
20663 Lisp_Object window
, Lisp_Object buffer
)
20668 struct buffer
*old_buffer
= NULL
;
20670 int no_props
= INTEGERP (face
);
20671 int count
= SPECPDL_INDEX ();
20673 int string_start
= 0;
20676 window
= selected_window
;
20677 CHECK_WINDOW (window
);
20678 w
= XWINDOW (window
);
20681 buffer
= w
->buffer
;
20682 CHECK_BUFFER (buffer
);
20684 /* Make formatting the modeline a non-op when noninteractive, otherwise
20685 there will be problems later caused by a partially initialized frame. */
20686 if (NILP (format
) || noninteractive
)
20687 return empty_unibyte_string
;
20692 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20693 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20694 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20695 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20696 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20697 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20698 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20701 if (XBUFFER (buffer
) != current_buffer
)
20702 old_buffer
= current_buffer
;
20704 /* Save things including mode_line_proptrans_alist,
20705 and set that to nil so that we don't alter the outer value. */
20706 record_unwind_protect (unwind_format_mode_line
,
20707 format_mode_line_unwind_data
20708 (old_buffer
, selected_window
, 1));
20709 mode_line_proptrans_alist
= Qnil
;
20711 Fselect_window (window
, Qt
);
20713 set_buffer_internal_1 (XBUFFER (buffer
));
20715 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20719 mode_line_target
= MODE_LINE_NOPROP
;
20720 mode_line_string_face_prop
= Qnil
;
20721 mode_line_string_list
= Qnil
;
20722 string_start
= MODE_LINE_NOPROP_LEN (0);
20726 mode_line_target
= MODE_LINE_STRING
;
20727 mode_line_string_list
= Qnil
;
20728 mode_line_string_face
= face
;
20729 mode_line_string_face_prop
20730 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20733 push_kboard (FRAME_KBOARD (it
.f
));
20734 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20739 len
= MODE_LINE_NOPROP_LEN (string_start
);
20740 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20744 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20745 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20746 empty_unibyte_string
);
20749 unbind_to (count
, Qnil
);
20753 /* Write a null-terminated, right justified decimal representation of
20754 the positive integer D to BUF using a minimal field width WIDTH. */
20757 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
20759 register char *p
= buf
;
20767 *p
++ = d
% 10 + '0';
20772 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20783 /* Write a null-terminated, right justified decimal and "human
20784 readable" representation of the nonnegative integer D to BUF using
20785 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20787 static const char power_letter
[] =
20801 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
20803 /* We aim to represent the nonnegative integer D as
20804 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20805 EMACS_INT quotient
= d
;
20807 /* -1 means: do not use TENTHS. */
20811 /* Length of QUOTIENT.TENTHS as a string. */
20817 if (1000 <= quotient
)
20819 /* Scale to the appropriate EXPONENT. */
20822 remainder
= quotient
% 1000;
20826 while (1000 <= quotient
);
20828 /* Round to nearest and decide whether to use TENTHS or not. */
20831 tenths
= remainder
/ 100;
20832 if (50 <= remainder
% 100)
20839 if (quotient
== 10)
20847 if (500 <= remainder
)
20849 if (quotient
< 999)
20860 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
20861 if (tenths
== -1 && quotient
<= 99)
20868 p
= psuffix
= buf
+ max (width
, length
);
20870 /* Print EXPONENT. */
20871 *psuffix
++ = power_letter
[exponent
];
20874 /* Print TENTHS. */
20877 *--p
= '0' + tenths
;
20881 /* Print QUOTIENT. */
20884 int digit
= quotient
% 10;
20885 *--p
= '0' + digit
;
20887 while ((quotient
/= 10) != 0);
20889 /* Print leading spaces. */
20894 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
20895 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
20896 type of CODING_SYSTEM. Return updated pointer into BUF. */
20898 static unsigned char invalid_eol_type
[] = "(*invalid*)";
20901 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
20904 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
20905 const unsigned char *eol_str
;
20907 /* The EOL conversion we are using. */
20908 Lisp_Object eoltype
;
20910 val
= CODING_SYSTEM_SPEC (coding_system
);
20913 if (!VECTORP (val
)) /* Not yet decided. */
20918 eoltype
= eol_mnemonic_undecided
;
20919 /* Don't mention EOL conversion if it isn't decided. */
20924 Lisp_Object eolvalue
;
20926 attrs
= AREF (val
, 0);
20927 eolvalue
= AREF (val
, 2);
20930 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
20934 /* The EOL conversion that is normal on this system. */
20936 if (NILP (eolvalue
)) /* Not yet decided. */
20937 eoltype
= eol_mnemonic_undecided
;
20938 else if (VECTORP (eolvalue
)) /* Not yet decided. */
20939 eoltype
= eol_mnemonic_undecided
;
20940 else /* eolvalue is Qunix, Qdos, or Qmac. */
20941 eoltype
= (EQ (eolvalue
, Qunix
)
20942 ? eol_mnemonic_unix
20943 : (EQ (eolvalue
, Qdos
) == 1
20944 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
20950 /* Mention the EOL conversion if it is not the usual one. */
20951 if (STRINGP (eoltype
))
20953 eol_str
= SDATA (eoltype
);
20954 eol_str_len
= SBYTES (eoltype
);
20956 else if (CHARACTERP (eoltype
))
20958 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
20959 int c
= XFASTINT (eoltype
);
20960 eol_str_len
= CHAR_STRING (c
, tmp
);
20965 eol_str
= invalid_eol_type
;
20966 eol_str_len
= sizeof (invalid_eol_type
) - 1;
20968 memcpy (buf
, eol_str
, eol_str_len
);
20969 buf
+= eol_str_len
;
20975 /* Return a string for the output of a mode line %-spec for window W,
20976 generated by character C. FIELD_WIDTH > 0 means pad the string
20977 returned with spaces to that value. Return a Lisp string in
20978 *STRING if the resulting string is taken from that Lisp string.
20980 Note we operate on the current buffer for most purposes,
20981 the exception being w->base_line_pos. */
20983 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
20985 static const char *
20986 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
20987 Lisp_Object
*string
)
20990 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20991 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
20992 struct buffer
*b
= current_buffer
;
21000 if (!NILP (BVAR (b
, read_only
)))
21002 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21007 /* This differs from %* only for a modified read-only buffer. */
21008 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21010 if (!NILP (BVAR (b
, read_only
)))
21015 /* This differs from %* in ignoring read-only-ness. */
21016 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21028 if (command_loop_level
> 5)
21030 p
= decode_mode_spec_buf
;
21031 for (i
= 0; i
< command_loop_level
; i
++)
21034 return decode_mode_spec_buf
;
21042 if (command_loop_level
> 5)
21044 p
= decode_mode_spec_buf
;
21045 for (i
= 0; i
< command_loop_level
; i
++)
21048 return decode_mode_spec_buf
;
21055 /* Let lots_of_dashes be a string of infinite length. */
21056 if (mode_line_target
== MODE_LINE_NOPROP
||
21057 mode_line_target
== MODE_LINE_STRING
)
21059 if (field_width
<= 0
21060 || field_width
> sizeof (lots_of_dashes
))
21062 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21063 decode_mode_spec_buf
[i
] = '-';
21064 decode_mode_spec_buf
[i
] = '\0';
21065 return decode_mode_spec_buf
;
21068 return lots_of_dashes
;
21072 obj
= BVAR (b
, name
);
21076 /* %c and %l are ignored in `frame-title-format'.
21077 (In redisplay_internal, the frame title is drawn _before_ the
21078 windows are updated, so the stuff which depends on actual
21079 window contents (such as %l) may fail to render properly, or
21080 even crash emacs.) */
21081 if (mode_line_target
== MODE_LINE_TITLE
)
21085 EMACS_INT col
= current_column ();
21086 w
->column_number_displayed
= make_number (col
);
21087 pint2str (decode_mode_spec_buf
, field_width
, col
);
21088 return decode_mode_spec_buf
;
21092 #ifndef SYSTEM_MALLOC
21094 if (NILP (Vmemory_full
))
21097 return "!MEM FULL! ";
21104 /* %F displays the frame name. */
21105 if (!NILP (f
->title
))
21106 return SSDATA (f
->title
);
21107 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21108 return SSDATA (f
->name
);
21112 obj
= BVAR (b
, filename
);
21117 EMACS_INT size
= ZV
- BEGV
;
21118 pint2str (decode_mode_spec_buf
, field_width
, size
);
21119 return decode_mode_spec_buf
;
21124 EMACS_INT size
= ZV
- BEGV
;
21125 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21126 return decode_mode_spec_buf
;
21131 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21132 EMACS_INT topline
, nlines
, height
;
21135 /* %c and %l are ignored in `frame-title-format'. */
21136 if (mode_line_target
== MODE_LINE_TITLE
)
21139 startpos
= XMARKER (w
->start
)->charpos
;
21140 startpos_byte
= marker_byte_position (w
->start
);
21141 height
= WINDOW_TOTAL_LINES (w
);
21143 /* If we decided that this buffer isn't suitable for line numbers,
21144 don't forget that too fast. */
21145 if (EQ (w
->base_line_pos
, w
->buffer
))
21147 /* But do forget it, if the window shows a different buffer now. */
21148 else if (BUFFERP (w
->base_line_pos
))
21149 w
->base_line_pos
= Qnil
;
21151 /* If the buffer is very big, don't waste time. */
21152 if (INTEGERP (Vline_number_display_limit
)
21153 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21155 w
->base_line_pos
= Qnil
;
21156 w
->base_line_number
= Qnil
;
21160 if (INTEGERP (w
->base_line_number
)
21161 && INTEGERP (w
->base_line_pos
)
21162 && XFASTINT (w
->base_line_pos
) <= startpos
)
21164 line
= XFASTINT (w
->base_line_number
);
21165 linepos
= XFASTINT (w
->base_line_pos
);
21166 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21171 linepos
= BUF_BEGV (b
);
21172 linepos_byte
= BUF_BEGV_BYTE (b
);
21175 /* Count lines from base line to window start position. */
21176 nlines
= display_count_lines (linepos_byte
,
21180 topline
= nlines
+ line
;
21182 /* Determine a new base line, if the old one is too close
21183 or too far away, or if we did not have one.
21184 "Too close" means it's plausible a scroll-down would
21185 go back past it. */
21186 if (startpos
== BUF_BEGV (b
))
21188 w
->base_line_number
= make_number (topline
);
21189 w
->base_line_pos
= make_number (BUF_BEGV (b
));
21191 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21192 || linepos
== BUF_BEGV (b
))
21194 EMACS_INT limit
= BUF_BEGV (b
);
21195 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
21196 EMACS_INT position
;
21197 EMACS_INT distance
=
21198 (height
* 2 + 30) * line_number_display_limit_width
;
21200 if (startpos
- distance
> limit
)
21202 limit
= startpos
- distance
;
21203 limit_byte
= CHAR_TO_BYTE (limit
);
21206 nlines
= display_count_lines (startpos_byte
,
21208 - (height
* 2 + 30),
21210 /* If we couldn't find the lines we wanted within
21211 line_number_display_limit_width chars per line,
21212 give up on line numbers for this window. */
21213 if (position
== limit_byte
&& limit
== startpos
- distance
)
21215 w
->base_line_pos
= w
->buffer
;
21216 w
->base_line_number
= Qnil
;
21220 w
->base_line_number
= make_number (topline
- nlines
);
21221 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
21224 /* Now count lines from the start pos to point. */
21225 nlines
= display_count_lines (startpos_byte
,
21226 PT_BYTE
, PT
, &junk
);
21228 /* Record that we did display the line number. */
21229 line_number_displayed
= 1;
21231 /* Make the string to show. */
21232 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21233 return decode_mode_spec_buf
;
21236 char* p
= decode_mode_spec_buf
;
21237 int pad
= field_width
- 2;
21243 return decode_mode_spec_buf
;
21249 obj
= BVAR (b
, mode_name
);
21253 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21259 EMACS_INT pos
= marker_position (w
->start
);
21260 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
21262 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21264 if (pos
<= BUF_BEGV (b
))
21269 else if (pos
<= BUF_BEGV (b
))
21273 if (total
> 1000000)
21274 /* Do it differently for a large value, to avoid overflow. */
21275 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21277 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21278 /* We can't normally display a 3-digit number,
21279 so get us a 2-digit number that is close. */
21282 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
21283 return decode_mode_spec_buf
;
21287 /* Display percentage of size above the bottom of the screen. */
21290 EMACS_INT toppos
= marker_position (w
->start
);
21291 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21292 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
21294 if (botpos
>= BUF_ZV (b
))
21296 if (toppos
<= BUF_BEGV (b
))
21303 if (total
> 1000000)
21304 /* Do it differently for a large value, to avoid overflow. */
21305 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21307 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21308 /* We can't normally display a 3-digit number,
21309 so get us a 2-digit number that is close. */
21312 if (toppos
<= BUF_BEGV (b
))
21313 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
21315 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
21316 return decode_mode_spec_buf
;
21321 /* status of process */
21322 obj
= Fget_buffer_process (Fcurrent_buffer ());
21324 return "no process";
21326 obj
= Fsymbol_name (Fprocess_status (obj
));
21332 int count
= inhibit_garbage_collection ();
21333 Lisp_Object val
= call1 (intern ("file-remote-p"),
21334 BVAR (current_buffer
, directory
));
21335 unbind_to (count
, Qnil
);
21343 case 't': /* indicate TEXT or BINARY */
21347 /* coding-system (not including end-of-line format) */
21349 /* coding-system (including end-of-line type) */
21351 int eol_flag
= (c
== 'Z');
21352 char *p
= decode_mode_spec_buf
;
21354 if (! FRAME_WINDOW_P (f
))
21356 /* No need to mention EOL here--the terminal never needs
21357 to do EOL conversion. */
21358 p
= decode_mode_spec_coding (CODING_ID_NAME
21359 (FRAME_KEYBOARD_CODING (f
)->id
),
21361 p
= decode_mode_spec_coding (CODING_ID_NAME
21362 (FRAME_TERMINAL_CODING (f
)->id
),
21365 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21368 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21369 #ifdef subprocesses
21370 obj
= Fget_buffer_process (Fcurrent_buffer ());
21371 if (PROCESSP (obj
))
21373 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
21375 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
21378 #endif /* subprocesses */
21381 return decode_mode_spec_buf
;
21388 return SSDATA (obj
);
21395 /* Count up to COUNT lines starting from START_BYTE.
21396 But don't go beyond LIMIT_BYTE.
21397 Return the number of lines thus found (always nonnegative).
21399 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21402 display_count_lines (EMACS_INT start_byte
,
21403 EMACS_INT limit_byte
, EMACS_INT count
,
21404 EMACS_INT
*byte_pos_ptr
)
21406 register unsigned char *cursor
;
21407 unsigned char *base
;
21409 register EMACS_INT ceiling
;
21410 register unsigned char *ceiling_addr
;
21411 EMACS_INT orig_count
= count
;
21413 /* If we are not in selective display mode,
21414 check only for newlines. */
21415 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21416 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21420 while (start_byte
< limit_byte
)
21422 ceiling
= BUFFER_CEILING_OF (start_byte
);
21423 ceiling
= min (limit_byte
- 1, ceiling
);
21424 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21425 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21428 if (selective_display
)
21429 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21432 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21435 if (cursor
!= ceiling_addr
)
21439 start_byte
+= cursor
- base
+ 1;
21440 *byte_pos_ptr
= start_byte
;
21444 if (++cursor
== ceiling_addr
)
21450 start_byte
+= cursor
- base
;
21455 while (start_byte
> limit_byte
)
21457 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21458 ceiling
= max (limit_byte
, ceiling
);
21459 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21460 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21463 if (selective_display
)
21464 while (--cursor
!= ceiling_addr
21465 && *cursor
!= '\n' && *cursor
!= 015)
21468 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21471 if (cursor
!= ceiling_addr
)
21475 start_byte
+= cursor
- base
+ 1;
21476 *byte_pos_ptr
= start_byte
;
21477 /* When scanning backwards, we should
21478 not count the newline posterior to which we stop. */
21479 return - orig_count
- 1;
21485 /* Here we add 1 to compensate for the last decrement
21486 of CURSOR, which took it past the valid range. */
21487 start_byte
+= cursor
- base
+ 1;
21491 *byte_pos_ptr
= limit_byte
;
21494 return - orig_count
+ count
;
21495 return orig_count
- count
;
21501 /***********************************************************************
21503 ***********************************************************************/
21505 /* Display a NUL-terminated string, starting with index START.
21507 If STRING is non-null, display that C string. Otherwise, the Lisp
21508 string LISP_STRING is displayed. There's a case that STRING is
21509 non-null and LISP_STRING is not nil. It means STRING is a string
21510 data of LISP_STRING. In that case, we display LISP_STRING while
21511 ignoring its text properties.
21513 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21514 FACE_STRING. Display STRING or LISP_STRING with the face at
21515 FACE_STRING_POS in FACE_STRING:
21517 Display the string in the environment given by IT, but use the
21518 standard display table, temporarily.
21520 FIELD_WIDTH is the minimum number of output glyphs to produce.
21521 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21522 with spaces. If STRING has more characters, more than FIELD_WIDTH
21523 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21525 PRECISION is the maximum number of characters to output from
21526 STRING. PRECISION < 0 means don't truncate the string.
21528 This is roughly equivalent to printf format specifiers:
21530 FIELD_WIDTH PRECISION PRINTF
21531 ----------------------------------------
21537 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21538 display them, and < 0 means obey the current buffer's value of
21539 enable_multibyte_characters.
21541 Value is the number of columns displayed. */
21544 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21545 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
21546 int field_width
, int precision
, int max_x
, int multibyte
)
21548 int hpos_at_start
= it
->hpos
;
21549 int saved_face_id
= it
->face_id
;
21550 struct glyph_row
*row
= it
->glyph_row
;
21551 EMACS_INT it_charpos
;
21553 /* Initialize the iterator IT for iteration over STRING beginning
21554 with index START. */
21555 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21556 precision
, field_width
, multibyte
);
21557 if (string
&& STRINGP (lisp_string
))
21558 /* LISP_STRING is the one returned by decode_mode_spec. We should
21559 ignore its text properties. */
21560 it
->stop_charpos
= it
->end_charpos
;
21562 /* If displaying STRING, set up the face of the iterator from
21563 FACE_STRING, if that's given. */
21564 if (STRINGP (face_string
))
21570 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21571 0, it
->region_beg_charpos
,
21572 it
->region_end_charpos
,
21573 &endptr
, it
->base_face_id
, 0);
21574 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21575 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21578 /* Set max_x to the maximum allowed X position. Don't let it go
21579 beyond the right edge of the window. */
21581 max_x
= it
->last_visible_x
;
21583 max_x
= min (max_x
, it
->last_visible_x
);
21585 /* Skip over display elements that are not visible. because IT->w is
21587 if (it
->current_x
< it
->first_visible_x
)
21588 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21589 MOVE_TO_POS
| MOVE_TO_X
);
21591 row
->ascent
= it
->max_ascent
;
21592 row
->height
= it
->max_ascent
+ it
->max_descent
;
21593 row
->phys_ascent
= it
->max_phys_ascent
;
21594 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21595 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21597 if (STRINGP (it
->string
))
21598 it_charpos
= IT_STRING_CHARPOS (*it
);
21600 it_charpos
= IT_CHARPOS (*it
);
21602 /* This condition is for the case that we are called with current_x
21603 past last_visible_x. */
21604 while (it
->current_x
< max_x
)
21606 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21608 /* Get the next display element. */
21609 if (!get_next_display_element (it
))
21612 /* Produce glyphs. */
21613 x_before
= it
->current_x
;
21614 n_glyphs_before
= row
->used
[TEXT_AREA
];
21615 PRODUCE_GLYPHS (it
);
21617 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21620 while (i
< nglyphs
)
21622 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21624 if (it
->line_wrap
!= TRUNCATE
21625 && x
+ glyph
->pixel_width
> max_x
)
21627 /* End of continued line or max_x reached. */
21628 if (CHAR_GLYPH_PADDING_P (*glyph
))
21630 /* A wide character is unbreakable. */
21631 if (row
->reversed_p
)
21632 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21633 - n_glyphs_before
);
21634 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21635 it
->current_x
= x_before
;
21639 if (row
->reversed_p
)
21640 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21641 - (n_glyphs_before
+ i
));
21642 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21647 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21649 /* Glyph is at least partially visible. */
21651 if (x
< it
->first_visible_x
)
21652 row
->x
= x
- it
->first_visible_x
;
21656 /* Glyph is off the left margin of the display area.
21657 Should not happen. */
21661 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21662 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21663 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21664 row
->phys_height
= max (row
->phys_height
,
21665 it
->max_phys_ascent
+ it
->max_phys_descent
);
21666 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21667 it
->max_extra_line_spacing
);
21668 x
+= glyph
->pixel_width
;
21672 /* Stop if max_x reached. */
21676 /* Stop at line ends. */
21677 if (ITERATOR_AT_END_OF_LINE_P (it
))
21679 it
->continuation_lines_width
= 0;
21683 set_iterator_to_next (it
, 1);
21684 if (STRINGP (it
->string
))
21685 it_charpos
= IT_STRING_CHARPOS (*it
);
21687 it_charpos
= IT_CHARPOS (*it
);
21689 /* Stop if truncating at the right edge. */
21690 if (it
->line_wrap
== TRUNCATE
21691 && it
->current_x
>= it
->last_visible_x
)
21693 /* Add truncation mark, but don't do it if the line is
21694 truncated at a padding space. */
21695 if (it_charpos
< it
->string_nchars
)
21697 if (!FRAME_WINDOW_P (it
->f
))
21701 if (it
->current_x
> it
->last_visible_x
)
21703 if (!row
->reversed_p
)
21705 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21706 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21711 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21712 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21714 unproduce_glyphs (it
, ii
+ 1);
21715 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21717 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21719 row
->used
[TEXT_AREA
] = ii
;
21720 produce_special_glyphs (it
, IT_TRUNCATION
);
21723 produce_special_glyphs (it
, IT_TRUNCATION
);
21725 row
->truncated_on_right_p
= 1;
21731 /* Maybe insert a truncation at the left. */
21732 if (it
->first_visible_x
21735 if (!FRAME_WINDOW_P (it
->f
))
21736 insert_left_trunc_glyphs (it
);
21737 row
->truncated_on_left_p
= 1;
21740 it
->face_id
= saved_face_id
;
21742 /* Value is number of columns displayed. */
21743 return it
->hpos
- hpos_at_start
;
21748 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21749 appears as an element of LIST or as the car of an element of LIST.
21750 If PROPVAL is a list, compare each element against LIST in that
21751 way, and return 1/2 if any element of PROPVAL is found in LIST.
21752 Otherwise return 0. This function cannot quit.
21753 The return value is 2 if the text is invisible but with an ellipsis
21754 and 1 if it's invisible and without an ellipsis. */
21757 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21759 register Lisp_Object tail
, proptail
;
21761 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21763 register Lisp_Object tem
;
21765 if (EQ (propval
, tem
))
21767 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21768 return NILP (XCDR (tem
)) ? 1 : 2;
21771 if (CONSP (propval
))
21773 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21775 Lisp_Object propelt
;
21776 propelt
= XCAR (proptail
);
21777 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21779 register Lisp_Object tem
;
21781 if (EQ (propelt
, tem
))
21783 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21784 return NILP (XCDR (tem
)) ? 1 : 2;
21792 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21793 doc
: /* Non-nil if the property makes the text invisible.
21794 POS-OR-PROP can be a marker or number, in which case it is taken to be
21795 a position in the current buffer and the value of the `invisible' property
21796 is checked; or it can be some other value, which is then presumed to be the
21797 value of the `invisible' property of the text of interest.
21798 The non-nil value returned can be t for truly invisible text or something
21799 else if the text is replaced by an ellipsis. */)
21800 (Lisp_Object pos_or_prop
)
21803 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21804 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21806 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21807 return (invis
== 0 ? Qnil
21809 : make_number (invis
));
21812 /* Calculate a width or height in pixels from a specification using
21813 the following elements:
21816 NUM - a (fractional) multiple of the default font width/height
21817 (NUM) - specifies exactly NUM pixels
21818 UNIT - a fixed number of pixels, see below.
21819 ELEMENT - size of a display element in pixels, see below.
21820 (NUM . SPEC) - equals NUM * SPEC
21821 (+ SPEC SPEC ...) - add pixel values
21822 (- SPEC SPEC ...) - subtract pixel values
21823 (- SPEC) - negate pixel value
21826 INT or FLOAT - a number constant
21827 SYMBOL - use symbol's (buffer local) variable binding.
21830 in - pixels per inch *)
21831 mm - pixels per 1/1000 meter *)
21832 cm - pixels per 1/100 meter *)
21833 width - width of current font in pixels.
21834 height - height of current font in pixels.
21836 *) using the ratio(s) defined in display-pixels-per-inch.
21840 left-fringe - left fringe width in pixels
21841 right-fringe - right fringe width in pixels
21843 left-margin - left margin width in pixels
21844 right-margin - right margin width in pixels
21846 scroll-bar - scroll-bar area width in pixels
21850 Pixels corresponding to 5 inches:
21853 Total width of non-text areas on left side of window (if scroll-bar is on left):
21854 '(space :width (+ left-fringe left-margin scroll-bar))
21856 Align to first text column (in header line):
21857 '(space :align-to 0)
21859 Align to middle of text area minus half the width of variable `my-image'
21860 containing a loaded image:
21861 '(space :align-to (0.5 . (- text my-image)))
21863 Width of left margin minus width of 1 character in the default font:
21864 '(space :width (- left-margin 1))
21866 Width of left margin minus width of 2 characters in the current font:
21867 '(space :width (- left-margin (2 . width)))
21869 Center 1 character over left-margin (in header line):
21870 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
21872 Different ways to express width of left fringe plus left margin minus one pixel:
21873 '(space :width (- (+ left-fringe left-margin) (1)))
21874 '(space :width (+ left-fringe left-margin (- (1))))
21875 '(space :width (+ left-fringe left-margin (-1)))
21879 #define NUMVAL(X) \
21880 ((INTEGERP (X) || FLOATP (X)) \
21885 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
21886 struct font
*font
, int width_p
, int *align_to
)
21890 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
21891 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
21894 return OK_PIXELS (0);
21896 xassert (FRAME_LIVE_P (it
->f
));
21898 if (SYMBOLP (prop
))
21900 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
21902 char *unit
= SSDATA (SYMBOL_NAME (prop
));
21904 if (unit
[0] == 'i' && unit
[1] == 'n')
21906 else if (unit
[0] == 'm' && unit
[1] == 'm')
21908 else if (unit
[0] == 'c' && unit
[1] == 'm')
21915 #ifdef HAVE_WINDOW_SYSTEM
21916 if (FRAME_WINDOW_P (it
->f
)
21918 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
21919 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
21921 return OK_PIXELS (ppi
/ pixels
);
21924 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
21925 || (CONSP (Vdisplay_pixels_per_inch
)
21927 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
21928 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
21930 return OK_PIXELS (ppi
/ pixels
);
21936 #ifdef HAVE_WINDOW_SYSTEM
21937 if (EQ (prop
, Qheight
))
21938 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
21939 if (EQ (prop
, Qwidth
))
21940 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
21942 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
21943 return OK_PIXELS (1);
21946 if (EQ (prop
, Qtext
))
21947 return OK_PIXELS (width_p
21948 ? window_box_width (it
->w
, TEXT_AREA
)
21949 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
21951 if (align_to
&& *align_to
< 0)
21954 if (EQ (prop
, Qleft
))
21955 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
21956 if (EQ (prop
, Qright
))
21957 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
21958 if (EQ (prop
, Qcenter
))
21959 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
21960 + window_box_width (it
->w
, TEXT_AREA
) / 2);
21961 if (EQ (prop
, Qleft_fringe
))
21962 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21963 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
21964 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
21965 if (EQ (prop
, Qright_fringe
))
21966 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21967 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21968 : window_box_right_offset (it
->w
, TEXT_AREA
));
21969 if (EQ (prop
, Qleft_margin
))
21970 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
21971 if (EQ (prop
, Qright_margin
))
21972 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
21973 if (EQ (prop
, Qscroll_bar
))
21974 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
21976 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
21977 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
21978 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21983 if (EQ (prop
, Qleft_fringe
))
21984 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
21985 if (EQ (prop
, Qright_fringe
))
21986 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
21987 if (EQ (prop
, Qleft_margin
))
21988 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
21989 if (EQ (prop
, Qright_margin
))
21990 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
21991 if (EQ (prop
, Qscroll_bar
))
21992 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
21995 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
21998 if (INTEGERP (prop
) || FLOATP (prop
))
22000 int base_unit
= (width_p
22001 ? FRAME_COLUMN_WIDTH (it
->f
)
22002 : FRAME_LINE_HEIGHT (it
->f
));
22003 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22008 Lisp_Object car
= XCAR (prop
);
22009 Lisp_Object cdr
= XCDR (prop
);
22013 #ifdef HAVE_WINDOW_SYSTEM
22014 if (FRAME_WINDOW_P (it
->f
)
22015 && valid_image_p (prop
))
22017 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22018 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22020 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22023 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22029 while (CONSP (cdr
))
22031 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22032 font
, width_p
, align_to
))
22035 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22040 if (EQ (car
, Qminus
))
22042 return OK_PIXELS (pixels
);
22045 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
22048 if (INTEGERP (car
) || FLOATP (car
))
22051 pixels
= XFLOATINT (car
);
22053 return OK_PIXELS (pixels
);
22054 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22055 font
, width_p
, align_to
))
22056 return OK_PIXELS (pixels
* fact
);
22067 /***********************************************************************
22069 ***********************************************************************/
22071 #ifdef HAVE_WINDOW_SYSTEM
22076 dump_glyph_string (struct glyph_string
*s
)
22078 fprintf (stderr
, "glyph string\n");
22079 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22080 s
->x
, s
->y
, s
->width
, s
->height
);
22081 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22082 fprintf (stderr
, " hl = %d\n", s
->hl
);
22083 fprintf (stderr
, " left overhang = %d, right = %d\n",
22084 s
->left_overhang
, s
->right_overhang
);
22085 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22086 fprintf (stderr
, " extends to end of line = %d\n",
22087 s
->extends_to_end_of_line_p
);
22088 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22089 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22092 #endif /* GLYPH_DEBUG */
22094 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22095 of XChar2b structures for S; it can't be allocated in
22096 init_glyph_string because it must be allocated via `alloca'. W
22097 is the window on which S is drawn. ROW and AREA are the glyph row
22098 and area within the row from which S is constructed. START is the
22099 index of the first glyph structure covered by S. HL is a
22100 face-override for drawing S. */
22103 #define OPTIONAL_HDC(hdc) HDC hdc,
22104 #define DECLARE_HDC(hdc) HDC hdc;
22105 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22106 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22109 #ifndef OPTIONAL_HDC
22110 #define OPTIONAL_HDC(hdc)
22111 #define DECLARE_HDC(hdc)
22112 #define ALLOCATE_HDC(hdc, f)
22113 #define RELEASE_HDC(hdc, f)
22117 init_glyph_string (struct glyph_string
*s
,
22119 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22120 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22122 memset (s
, 0, sizeof *s
);
22124 s
->f
= XFRAME (w
->frame
);
22128 s
->display
= FRAME_X_DISPLAY (s
->f
);
22129 s
->window
= FRAME_X_WINDOW (s
->f
);
22130 s
->char2b
= char2b
;
22134 s
->first_glyph
= row
->glyphs
[area
] + start
;
22135 s
->height
= row
->height
;
22136 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22137 s
->ybase
= s
->y
+ row
->ascent
;
22141 /* Append the list of glyph strings with head H and tail T to the list
22142 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22145 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22146 struct glyph_string
*h
, struct glyph_string
*t
)
22160 /* Prepend the list of glyph strings with head H and tail T to the
22161 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22165 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22166 struct glyph_string
*h
, struct glyph_string
*t
)
22180 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22181 Set *HEAD and *TAIL to the resulting list. */
22184 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22185 struct glyph_string
*s
)
22187 s
->next
= s
->prev
= NULL
;
22188 append_glyph_string_lists (head
, tail
, s
, s
);
22192 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22193 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22194 make sure that X resources for the face returned are allocated.
22195 Value is a pointer to a realized face that is ready for display if
22196 DISPLAY_P is non-zero. */
22198 static inline struct face
*
22199 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22200 XChar2b
*char2b
, int display_p
)
22202 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22206 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22208 if (code
!= FONT_INVALID_CODE
)
22209 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22211 STORE_XCHAR2B (char2b
, 0, 0);
22214 /* Make sure X resources of the face are allocated. */
22215 #ifdef HAVE_X_WINDOWS
22219 xassert (face
!= NULL
);
22220 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22227 /* Get face and two-byte form of character glyph GLYPH on frame F.
22228 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22229 a pointer to a realized face that is ready for display. */
22231 static inline struct face
*
22232 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22233 XChar2b
*char2b
, int *two_byte_p
)
22237 xassert (glyph
->type
== CHAR_GLYPH
);
22238 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22247 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22248 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22250 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22252 if (code
!= FONT_INVALID_CODE
)
22253 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22255 STORE_XCHAR2B (char2b
, 0, 0);
22258 /* Make sure X resources of the face are allocated. */
22259 xassert (face
!= NULL
);
22260 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22265 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22266 Return 1 if FONT has a glyph for C, otherwise return 0. */
22269 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22273 if (CHAR_BYTE8_P (c
))
22274 code
= CHAR_TO_BYTE8 (c
);
22276 code
= font
->driver
->encode_char (font
, c
);
22278 if (code
== FONT_INVALID_CODE
)
22280 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22285 /* Fill glyph string S with composition components specified by S->cmp.
22287 BASE_FACE is the base face of the composition.
22288 S->cmp_from is the index of the first component for S.
22290 OVERLAPS non-zero means S should draw the foreground only, and use
22291 its physical height for clipping. See also draw_glyphs.
22293 Value is the index of a component not in S. */
22296 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22300 /* For all glyphs of this composition, starting at the offset
22301 S->cmp_from, until we reach the end of the definition or encounter a
22302 glyph that requires the different face, add it to S. */
22307 s
->for_overlaps
= overlaps
;
22310 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22312 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22314 /* TAB in a composition means display glyphs with padding space
22315 on the left or right. */
22318 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22321 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22328 s
->font
= s
->face
->font
;
22330 else if (s
->face
!= face
)
22338 if (s
->face
== NULL
)
22340 s
->face
= base_face
->ascii_face
;
22341 s
->font
= s
->face
->font
;
22344 /* All glyph strings for the same composition has the same width,
22345 i.e. the width set for the first component of the composition. */
22346 s
->width
= s
->first_glyph
->pixel_width
;
22348 /* If the specified font could not be loaded, use the frame's
22349 default font, but record the fact that we couldn't load it in
22350 the glyph string so that we can draw rectangles for the
22351 characters of the glyph string. */
22352 if (s
->font
== NULL
)
22354 s
->font_not_found_p
= 1;
22355 s
->font
= FRAME_FONT (s
->f
);
22358 /* Adjust base line for subscript/superscript text. */
22359 s
->ybase
+= s
->first_glyph
->voffset
;
22361 /* This glyph string must always be drawn with 16-bit functions. */
22368 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22369 int start
, int end
, int overlaps
)
22371 struct glyph
*glyph
, *last
;
22372 Lisp_Object lgstring
;
22375 s
->for_overlaps
= overlaps
;
22376 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22377 last
= s
->row
->glyphs
[s
->area
] + end
;
22378 s
->cmp_id
= glyph
->u
.cmp
.id
;
22379 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22380 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22381 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22382 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22383 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22385 while (glyph
< last
22386 && glyph
->u
.cmp
.automatic
22387 && glyph
->u
.cmp
.id
== s
->cmp_id
22388 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22389 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22391 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22393 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22394 unsigned code
= LGLYPH_CODE (lglyph
);
22396 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22398 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22399 return glyph
- s
->row
->glyphs
[s
->area
];
22403 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22404 See the comment of fill_glyph_string for arguments.
22405 Value is the index of the first glyph not in S. */
22409 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22410 int start
, int end
, int overlaps
)
22412 struct glyph
*glyph
, *last
;
22415 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22416 s
->for_overlaps
= overlaps
;
22417 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22418 last
= s
->row
->glyphs
[s
->area
] + end
;
22419 voffset
= glyph
->voffset
;
22420 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22421 s
->font
= s
->face
->font
;
22423 s
->width
= glyph
->pixel_width
;
22425 while (glyph
< last
22426 && glyph
->type
== GLYPHLESS_GLYPH
22427 && glyph
->voffset
== voffset
22428 && glyph
->face_id
== face_id
)
22431 s
->width
+= glyph
->pixel_width
;
22434 s
->ybase
+= voffset
;
22435 return glyph
- s
->row
->glyphs
[s
->area
];
22439 /* Fill glyph string S from a sequence of character glyphs.
22441 FACE_ID is the face id of the string. START is the index of the
22442 first glyph to consider, END is the index of the last + 1.
22443 OVERLAPS non-zero means S should draw the foreground only, and use
22444 its physical height for clipping. See also draw_glyphs.
22446 Value is the index of the first glyph not in S. */
22449 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22450 int start
, int end
, int overlaps
)
22452 struct glyph
*glyph
, *last
;
22454 int glyph_not_available_p
;
22456 xassert (s
->f
== XFRAME (s
->w
->frame
));
22457 xassert (s
->nchars
== 0);
22458 xassert (start
>= 0 && end
> start
);
22460 s
->for_overlaps
= overlaps
;
22461 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22462 last
= s
->row
->glyphs
[s
->area
] + end
;
22463 voffset
= glyph
->voffset
;
22464 s
->padding_p
= glyph
->padding_p
;
22465 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22467 while (glyph
< last
22468 && glyph
->type
== CHAR_GLYPH
22469 && glyph
->voffset
== voffset
22470 /* Same face id implies same font, nowadays. */
22471 && glyph
->face_id
== face_id
22472 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22476 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22477 s
->char2b
+ s
->nchars
,
22479 s
->two_byte_p
= two_byte_p
;
22481 xassert (s
->nchars
<= end
- start
);
22482 s
->width
+= glyph
->pixel_width
;
22483 if (glyph
++->padding_p
!= s
->padding_p
)
22487 s
->font
= s
->face
->font
;
22489 /* If the specified font could not be loaded, use the frame's font,
22490 but record the fact that we couldn't load it in
22491 S->font_not_found_p so that we can draw rectangles for the
22492 characters of the glyph string. */
22493 if (s
->font
== NULL
|| glyph_not_available_p
)
22495 s
->font_not_found_p
= 1;
22496 s
->font
= FRAME_FONT (s
->f
);
22499 /* Adjust base line for subscript/superscript text. */
22500 s
->ybase
+= voffset
;
22502 xassert (s
->face
&& s
->face
->gc
);
22503 return glyph
- s
->row
->glyphs
[s
->area
];
22507 /* Fill glyph string S from image glyph S->first_glyph. */
22510 fill_image_glyph_string (struct glyph_string
*s
)
22512 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22513 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22515 s
->slice
= s
->first_glyph
->slice
.img
;
22516 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22517 s
->font
= s
->face
->font
;
22518 s
->width
= s
->first_glyph
->pixel_width
;
22520 /* Adjust base line for subscript/superscript text. */
22521 s
->ybase
+= s
->first_glyph
->voffset
;
22525 /* Fill glyph string S from a sequence of stretch glyphs.
22527 START is the index of the first glyph to consider,
22528 END is the index of the last + 1.
22530 Value is the index of the first glyph not in S. */
22533 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22535 struct glyph
*glyph
, *last
;
22536 int voffset
, face_id
;
22538 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22540 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22541 last
= s
->row
->glyphs
[s
->area
] + end
;
22542 face_id
= glyph
->face_id
;
22543 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22544 s
->font
= s
->face
->font
;
22545 s
->width
= glyph
->pixel_width
;
22547 voffset
= glyph
->voffset
;
22551 && glyph
->type
== STRETCH_GLYPH
22552 && glyph
->voffset
== voffset
22553 && glyph
->face_id
== face_id
);
22555 s
->width
+= glyph
->pixel_width
;
22557 /* Adjust base line for subscript/superscript text. */
22558 s
->ybase
+= voffset
;
22560 /* The case that face->gc == 0 is handled when drawing the glyph
22561 string by calling PREPARE_FACE_FOR_DISPLAY. */
22563 return glyph
- s
->row
->glyphs
[s
->area
];
22566 static struct font_metrics
*
22567 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22569 static struct font_metrics metrics
;
22570 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22572 if (! font
|| code
== FONT_INVALID_CODE
)
22574 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22579 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22580 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22581 assumed to be zero. */
22584 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22586 *left
= *right
= 0;
22588 if (glyph
->type
== CHAR_GLYPH
)
22592 struct font_metrics
*pcm
;
22594 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22595 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22597 if (pcm
->rbearing
> pcm
->width
)
22598 *right
= pcm
->rbearing
- pcm
->width
;
22599 if (pcm
->lbearing
< 0)
22600 *left
= -pcm
->lbearing
;
22603 else if (glyph
->type
== COMPOSITE_GLYPH
)
22605 if (! glyph
->u
.cmp
.automatic
)
22607 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22609 if (cmp
->rbearing
> cmp
->pixel_width
)
22610 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22611 if (cmp
->lbearing
< 0)
22612 *left
= - cmp
->lbearing
;
22616 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22617 struct font_metrics metrics
;
22619 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22620 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22621 if (metrics
.rbearing
> metrics
.width
)
22622 *right
= metrics
.rbearing
- metrics
.width
;
22623 if (metrics
.lbearing
< 0)
22624 *left
= - metrics
.lbearing
;
22630 /* Return the index of the first glyph preceding glyph string S that
22631 is overwritten by S because of S's left overhang. Value is -1
22632 if no glyphs are overwritten. */
22635 left_overwritten (struct glyph_string
*s
)
22639 if (s
->left_overhang
)
22642 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22643 int first
= s
->first_glyph
- glyphs
;
22645 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22646 x
-= glyphs
[i
].pixel_width
;
22657 /* Return the index of the first glyph preceding glyph string S that
22658 is overwriting S because of its right overhang. Value is -1 if no
22659 glyph in front of S overwrites S. */
22662 left_overwriting (struct glyph_string
*s
)
22665 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22666 int first
= s
->first_glyph
- glyphs
;
22670 for (i
= first
- 1; i
>= 0; --i
)
22673 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22676 x
-= glyphs
[i
].pixel_width
;
22683 /* Return the index of the last glyph following glyph string S that is
22684 overwritten by S because of S's right overhang. Value is -1 if
22685 no such glyph is found. */
22688 right_overwritten (struct glyph_string
*s
)
22692 if (s
->right_overhang
)
22695 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22696 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22697 int end
= s
->row
->used
[s
->area
];
22699 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22700 x
+= glyphs
[i
].pixel_width
;
22709 /* Return the index of the last glyph following glyph string S that
22710 overwrites S because of its left overhang. Value is negative
22711 if no such glyph is found. */
22714 right_overwriting (struct glyph_string
*s
)
22717 int end
= s
->row
->used
[s
->area
];
22718 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22719 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
22723 for (i
= first
; i
< end
; ++i
)
22726 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22729 x
+= glyphs
[i
].pixel_width
;
22736 /* Set background width of glyph string S. START is the index of the
22737 first glyph following S. LAST_X is the right-most x-position + 1
22738 in the drawing area. */
22741 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22743 /* If the face of this glyph string has to be drawn to the end of
22744 the drawing area, set S->extends_to_end_of_line_p. */
22746 if (start
== s
->row
->used
[s
->area
]
22747 && s
->area
== TEXT_AREA
22748 && ((s
->row
->fill_line_p
22749 && (s
->hl
== DRAW_NORMAL_TEXT
22750 || s
->hl
== DRAW_IMAGE_RAISED
22751 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22752 || s
->hl
== DRAW_MOUSE_FACE
))
22753 s
->extends_to_end_of_line_p
= 1;
22755 /* If S extends its face to the end of the line, set its
22756 background_width to the distance to the right edge of the drawing
22758 if (s
->extends_to_end_of_line_p
)
22759 s
->background_width
= last_x
- s
->x
+ 1;
22761 s
->background_width
= s
->width
;
22765 /* Compute overhangs and x-positions for glyph string S and its
22766 predecessors, or successors. X is the starting x-position for S.
22767 BACKWARD_P non-zero means process predecessors. */
22770 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22776 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22777 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22787 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22788 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22798 /* The following macros are only called from draw_glyphs below.
22799 They reference the following parameters of that function directly:
22800 `w', `row', `area', and `overlap_p'
22801 as well as the following local variables:
22802 `s', `f', and `hdc' (in W32) */
22805 /* On W32, silently add local `hdc' variable to argument list of
22806 init_glyph_string. */
22807 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22808 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
22810 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
22811 init_glyph_string (s, char2b, w, row, area, start, hl)
22814 /* Add a glyph string for a stretch glyph to the list of strings
22815 between HEAD and TAIL. START is the index of the stretch glyph in
22816 row area AREA of glyph row ROW. END is the index of the last glyph
22817 in that glyph row area. X is the current output position assigned
22818 to the new glyph string constructed. HL overrides that face of the
22819 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22820 is the right-most x-position of the drawing area. */
22822 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
22823 and below -- keep them on one line. */
22824 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22827 s = (struct glyph_string *) alloca (sizeof *s); \
22828 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22829 START = fill_stretch_glyph_string (s, START, END); \
22830 append_glyph_string (&HEAD, &TAIL, s); \
22836 /* Add a glyph string for an image glyph to the list of strings
22837 between HEAD and TAIL. START is the index of the image glyph in
22838 row area AREA of glyph row ROW. END is the index of the last glyph
22839 in that glyph row area. X is the current output position assigned
22840 to the new glyph string constructed. HL overrides that face of the
22841 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
22842 is the right-most x-position of the drawing area. */
22844 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22847 s = (struct glyph_string *) alloca (sizeof *s); \
22848 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22849 fill_image_glyph_string (s); \
22850 append_glyph_string (&HEAD, &TAIL, s); \
22857 /* Add a glyph string for a sequence of character glyphs to the list
22858 of strings between HEAD and TAIL. START is the index of the first
22859 glyph in row area AREA of glyph row ROW that is part of the new
22860 glyph string. END is the index of the last glyph in that glyph row
22861 area. X is the current output position assigned to the new glyph
22862 string constructed. HL overrides that face of the glyph; e.g. it
22863 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
22864 right-most x-position of the drawing area. */
22866 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22872 face_id = (row)->glyphs[area][START].face_id; \
22874 s = (struct glyph_string *) alloca (sizeof *s); \
22875 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
22876 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22877 append_glyph_string (&HEAD, &TAIL, s); \
22879 START = fill_glyph_string (s, face_id, START, END, overlaps); \
22884 /* Add a glyph string for a composite sequence to the list of strings
22885 between HEAD and TAIL. START is the index of the first glyph in
22886 row area AREA of glyph row ROW that is part of the new glyph
22887 string. END is the index of the last glyph in that glyph row area.
22888 X is the current output position assigned to the new glyph string
22889 constructed. HL overrides that face of the glyph; e.g. it is
22890 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
22891 x-position of the drawing area. */
22893 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22895 int face_id = (row)->glyphs[area][START].face_id; \
22896 struct face *base_face = FACE_FROM_ID (f, face_id); \
22897 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
22898 struct composition *cmp = composition_table[cmp_id]; \
22900 struct glyph_string *first_s = NULL; \
22903 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
22905 /* Make glyph_strings for each glyph sequence that is drawable by \
22906 the same face, and append them to HEAD/TAIL. */ \
22907 for (n = 0; n < cmp->glyph_len;) \
22909 s = (struct glyph_string *) alloca (sizeof *s); \
22910 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22911 append_glyph_string (&(HEAD), &(TAIL), s); \
22917 n = fill_composite_glyph_string (s, base_face, overlaps); \
22925 /* Add a glyph string for a glyph-string sequence to the list of strings
22926 between HEAD and TAIL. */
22928 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22932 Lisp_Object gstring; \
22934 face_id = (row)->glyphs[area][START].face_id; \
22935 gstring = (composition_gstring_from_id \
22936 ((row)->glyphs[area][START].u.cmp.id)); \
22937 s = (struct glyph_string *) alloca (sizeof *s); \
22938 char2b = (XChar2b *) alloca ((sizeof *char2b) \
22939 * LGSTRING_GLYPH_LEN (gstring)); \
22940 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
22941 append_glyph_string (&(HEAD), &(TAIL), s); \
22943 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
22947 /* Add a glyph string for a sequence of glyphless character's glyphs
22948 to the list of strings between HEAD and TAIL. The meanings of
22949 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
22951 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
22956 face_id = (row)->glyphs[area][START].face_id; \
22958 s = (struct glyph_string *) alloca (sizeof *s); \
22959 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
22960 append_glyph_string (&HEAD, &TAIL, s); \
22962 START = fill_glyphless_glyph_string (s, face_id, START, END, \
22968 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
22969 of AREA of glyph row ROW on window W between indices START and END.
22970 HL overrides the face for drawing glyph strings, e.g. it is
22971 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
22972 x-positions of the drawing area.
22974 This is an ugly monster macro construct because we must use alloca
22975 to allocate glyph strings (because draw_glyphs can be called
22976 asynchronously). */
22978 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
22981 HEAD = TAIL = NULL; \
22982 while (START < END) \
22984 struct glyph *first_glyph = (row)->glyphs[area] + START; \
22985 switch (first_glyph->type) \
22988 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
22992 case COMPOSITE_GLYPH: \
22993 if (first_glyph->u.cmp.automatic) \
22994 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
22997 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23001 case STRETCH_GLYPH: \
23002 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23006 case IMAGE_GLYPH: \
23007 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23011 case GLYPHLESS_GLYPH: \
23012 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23022 set_glyph_string_background_width (s, START, LAST_X); \
23029 /* Draw glyphs between START and END in AREA of ROW on window W,
23030 starting at x-position X. X is relative to AREA in W. HL is a
23031 face-override with the following meaning:
23033 DRAW_NORMAL_TEXT draw normally
23034 DRAW_CURSOR draw in cursor face
23035 DRAW_MOUSE_FACE draw in mouse face.
23036 DRAW_INVERSE_VIDEO draw in mode line face
23037 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23038 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23040 If OVERLAPS is non-zero, draw only the foreground of characters and
23041 clip to the physical height of ROW. Non-zero value also defines
23042 the overlapping part to be drawn:
23044 OVERLAPS_PRED overlap with preceding rows
23045 OVERLAPS_SUCC overlap with succeeding rows
23046 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23047 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23049 Value is the x-position reached, relative to AREA of W. */
23052 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23053 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
23054 enum draw_glyphs_face hl
, int overlaps
)
23056 struct glyph_string
*head
, *tail
;
23057 struct glyph_string
*s
;
23058 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23059 int i
, j
, x_reached
, last_x
, area_left
= 0;
23060 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23063 ALLOCATE_HDC (hdc
, f
);
23065 /* Let's rather be paranoid than getting a SEGV. */
23066 end
= min (end
, row
->used
[area
]);
23067 start
= max (0, start
);
23068 start
= min (end
, start
);
23070 /* Translate X to frame coordinates. Set last_x to the right
23071 end of the drawing area. */
23072 if (row
->full_width_p
)
23074 /* X is relative to the left edge of W, without scroll bars
23076 area_left
= WINDOW_LEFT_EDGE_X (w
);
23077 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23081 area_left
= window_box_left (w
, area
);
23082 last_x
= area_left
+ window_box_width (w
, area
);
23086 /* Build a doubly-linked list of glyph_string structures between
23087 head and tail from what we have to draw. Note that the macro
23088 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23089 the reason we use a separate variable `i'. */
23091 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23093 x_reached
= tail
->x
+ tail
->background_width
;
23097 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23098 the row, redraw some glyphs in front or following the glyph
23099 strings built above. */
23100 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23102 struct glyph_string
*h
, *t
;
23103 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23104 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23105 int check_mouse_face
= 0;
23108 /* If mouse highlighting is on, we may need to draw adjacent
23109 glyphs using mouse-face highlighting. */
23110 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23112 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23114 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23115 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23117 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23119 check_mouse_face
= 1;
23120 mouse_beg_col
= (row
== mouse_beg_row
)
23121 ? hlinfo
->mouse_face_beg_col
: 0;
23122 mouse_end_col
= (row
== mouse_end_row
)
23123 ? hlinfo
->mouse_face_end_col
23124 : row
->used
[TEXT_AREA
];
23128 /* Compute overhangs for all glyph strings. */
23129 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23130 for (s
= head
; s
; s
= s
->next
)
23131 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23133 /* Prepend glyph strings for glyphs in front of the first glyph
23134 string that are overwritten because of the first glyph
23135 string's left overhang. The background of all strings
23136 prepended must be drawn because the first glyph string
23138 i
= left_overwritten (head
);
23141 enum draw_glyphs_face overlap_hl
;
23143 /* If this row contains mouse highlighting, attempt to draw
23144 the overlapped glyphs with the correct highlight. This
23145 code fails if the overlap encompasses more than one glyph
23146 and mouse-highlight spans only some of these glyphs.
23147 However, making it work perfectly involves a lot more
23148 code, and I don't know if the pathological case occurs in
23149 practice, so we'll stick to this for now. --- cyd */
23150 if (check_mouse_face
23151 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23152 overlap_hl
= DRAW_MOUSE_FACE
;
23154 overlap_hl
= DRAW_NORMAL_TEXT
;
23157 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23158 overlap_hl
, dummy_x
, last_x
);
23160 compute_overhangs_and_x (t
, head
->x
, 1);
23161 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23165 /* Prepend glyph strings for glyphs in front of the first glyph
23166 string that overwrite that glyph string because of their
23167 right overhang. For these strings, only the foreground must
23168 be drawn, because it draws over the glyph string at `head'.
23169 The background must not be drawn because this would overwrite
23170 right overhangs of preceding glyphs for which no glyph
23172 i
= left_overwriting (head
);
23175 enum draw_glyphs_face overlap_hl
;
23177 if (check_mouse_face
23178 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23179 overlap_hl
= DRAW_MOUSE_FACE
;
23181 overlap_hl
= DRAW_NORMAL_TEXT
;
23184 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23185 overlap_hl
, dummy_x
, last_x
);
23186 for (s
= h
; s
; s
= s
->next
)
23187 s
->background_filled_p
= 1;
23188 compute_overhangs_and_x (t
, head
->x
, 1);
23189 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23192 /* Append glyphs strings for glyphs following the last glyph
23193 string tail that are overwritten by tail. The background of
23194 these strings has to be drawn because tail's foreground draws
23196 i
= right_overwritten (tail
);
23199 enum draw_glyphs_face overlap_hl
;
23201 if (check_mouse_face
23202 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23203 overlap_hl
= DRAW_MOUSE_FACE
;
23205 overlap_hl
= DRAW_NORMAL_TEXT
;
23207 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23208 overlap_hl
, x
, last_x
);
23209 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23210 we don't have `end = i;' here. */
23211 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23212 append_glyph_string_lists (&head
, &tail
, h
, t
);
23216 /* Append glyph strings for glyphs following the last glyph
23217 string tail that overwrite tail. The foreground of such
23218 glyphs has to be drawn because it writes into the background
23219 of tail. The background must not be drawn because it could
23220 paint over the foreground of following glyphs. */
23221 i
= right_overwriting (tail
);
23224 enum draw_glyphs_face overlap_hl
;
23225 if (check_mouse_face
23226 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23227 overlap_hl
= DRAW_MOUSE_FACE
;
23229 overlap_hl
= DRAW_NORMAL_TEXT
;
23232 i
++; /* We must include the Ith glyph. */
23233 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23234 overlap_hl
, x
, last_x
);
23235 for (s
= h
; s
; s
= s
->next
)
23236 s
->background_filled_p
= 1;
23237 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23238 append_glyph_string_lists (&head
, &tail
, h
, t
);
23240 if (clip_head
|| clip_tail
)
23241 for (s
= head
; s
; s
= s
->next
)
23243 s
->clip_head
= clip_head
;
23244 s
->clip_tail
= clip_tail
;
23248 /* Draw all strings. */
23249 for (s
= head
; s
; s
= s
->next
)
23250 FRAME_RIF (f
)->draw_glyph_string (s
);
23253 /* When focus a sole frame and move horizontally, this sets on_p to 0
23254 causing a failure to erase prev cursor position. */
23255 if (area
== TEXT_AREA
23256 && !row
->full_width_p
23257 /* When drawing overlapping rows, only the glyph strings'
23258 foreground is drawn, which doesn't erase a cursor
23262 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23263 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23264 : (tail
? tail
->x
+ tail
->background_width
: x
));
23268 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23269 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23273 /* Value is the x-position up to which drawn, relative to AREA of W.
23274 This doesn't include parts drawn because of overhangs. */
23275 if (row
->full_width_p
)
23276 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23278 x_reached
-= area_left
;
23280 RELEASE_HDC (hdc
, f
);
23285 /* Expand row matrix if too narrow. Don't expand if area
23288 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23290 if (!fonts_changed_p \
23291 && (it->glyph_row->glyphs[area] \
23292 < it->glyph_row->glyphs[area + 1])) \
23294 it->w->ncols_scale_factor++; \
23295 fonts_changed_p = 1; \
23299 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23300 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23303 append_glyph (struct it
*it
)
23305 struct glyph
*glyph
;
23306 enum glyph_row_area area
= it
->area
;
23308 xassert (it
->glyph_row
);
23309 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23311 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23312 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23314 /* If the glyph row is reversed, we need to prepend the glyph
23315 rather than append it. */
23316 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23320 /* Make room for the additional glyph. */
23321 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23323 glyph
= it
->glyph_row
->glyphs
[area
];
23325 glyph
->charpos
= CHARPOS (it
->position
);
23326 glyph
->object
= it
->object
;
23327 if (it
->pixel_width
> 0)
23329 glyph
->pixel_width
= it
->pixel_width
;
23330 glyph
->padding_p
= 0;
23334 /* Assure at least 1-pixel width. Otherwise, cursor can't
23335 be displayed correctly. */
23336 glyph
->pixel_width
= 1;
23337 glyph
->padding_p
= 1;
23339 glyph
->ascent
= it
->ascent
;
23340 glyph
->descent
= it
->descent
;
23341 glyph
->voffset
= it
->voffset
;
23342 glyph
->type
= CHAR_GLYPH
;
23343 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23344 glyph
->multibyte_p
= it
->multibyte_p
;
23345 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23346 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23347 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23348 || it
->phys_descent
> it
->descent
);
23349 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23350 glyph
->face_id
= it
->face_id
;
23351 glyph
->u
.ch
= it
->char_to_display
;
23352 glyph
->slice
.img
= null_glyph_slice
;
23353 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23356 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23357 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23359 glyph
->bidi_type
= it
->bidi_it
.type
;
23363 glyph
->resolved_level
= 0;
23364 glyph
->bidi_type
= UNKNOWN_BT
;
23366 ++it
->glyph_row
->used
[area
];
23369 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23372 /* Store one glyph for the composition IT->cmp_it.id in
23373 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23377 append_composite_glyph (struct it
*it
)
23379 struct glyph
*glyph
;
23380 enum glyph_row_area area
= it
->area
;
23382 xassert (it
->glyph_row
);
23384 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23385 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23387 /* If the glyph row is reversed, we need to prepend the glyph
23388 rather than append it. */
23389 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23393 /* Make room for the new glyph. */
23394 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23396 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23398 glyph
->charpos
= it
->cmp_it
.charpos
;
23399 glyph
->object
= it
->object
;
23400 glyph
->pixel_width
= it
->pixel_width
;
23401 glyph
->ascent
= it
->ascent
;
23402 glyph
->descent
= it
->descent
;
23403 glyph
->voffset
= it
->voffset
;
23404 glyph
->type
= COMPOSITE_GLYPH
;
23405 if (it
->cmp_it
.ch
< 0)
23407 glyph
->u
.cmp
.automatic
= 0;
23408 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23409 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23413 glyph
->u
.cmp
.automatic
= 1;
23414 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23415 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23416 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23418 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23419 glyph
->multibyte_p
= it
->multibyte_p
;
23420 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23421 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23422 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23423 || it
->phys_descent
> it
->descent
);
23424 glyph
->padding_p
= 0;
23425 glyph
->glyph_not_available_p
= 0;
23426 glyph
->face_id
= it
->face_id
;
23427 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23430 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23431 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23433 glyph
->bidi_type
= it
->bidi_it
.type
;
23435 ++it
->glyph_row
->used
[area
];
23438 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23442 /* Change IT->ascent and IT->height according to the setting of
23446 take_vertical_position_into_account (struct it
*it
)
23450 if (it
->voffset
< 0)
23451 /* Increase the ascent so that we can display the text higher
23453 it
->ascent
-= it
->voffset
;
23455 /* Increase the descent so that we can display the text lower
23457 it
->descent
+= it
->voffset
;
23462 /* Produce glyphs/get display metrics for the image IT is loaded with.
23463 See the description of struct display_iterator in dispextern.h for
23464 an overview of struct display_iterator. */
23467 produce_image_glyph (struct it
*it
)
23471 int glyph_ascent
, crop
;
23472 struct glyph_slice slice
;
23474 xassert (it
->what
== IT_IMAGE
);
23476 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23478 /* Make sure X resources of the face is loaded. */
23479 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23481 if (it
->image_id
< 0)
23483 /* Fringe bitmap. */
23484 it
->ascent
= it
->phys_ascent
= 0;
23485 it
->descent
= it
->phys_descent
= 0;
23486 it
->pixel_width
= 0;
23491 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23493 /* Make sure X resources of the image is loaded. */
23494 prepare_image_for_display (it
->f
, img
);
23496 slice
.x
= slice
.y
= 0;
23497 slice
.width
= img
->width
;
23498 slice
.height
= img
->height
;
23500 if (INTEGERP (it
->slice
.x
))
23501 slice
.x
= XINT (it
->slice
.x
);
23502 else if (FLOATP (it
->slice
.x
))
23503 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23505 if (INTEGERP (it
->slice
.y
))
23506 slice
.y
= XINT (it
->slice
.y
);
23507 else if (FLOATP (it
->slice
.y
))
23508 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23510 if (INTEGERP (it
->slice
.width
))
23511 slice
.width
= XINT (it
->slice
.width
);
23512 else if (FLOATP (it
->slice
.width
))
23513 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23515 if (INTEGERP (it
->slice
.height
))
23516 slice
.height
= XINT (it
->slice
.height
);
23517 else if (FLOATP (it
->slice
.height
))
23518 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23520 if (slice
.x
>= img
->width
)
23521 slice
.x
= img
->width
;
23522 if (slice
.y
>= img
->height
)
23523 slice
.y
= img
->height
;
23524 if (slice
.x
+ slice
.width
>= img
->width
)
23525 slice
.width
= img
->width
- slice
.x
;
23526 if (slice
.y
+ slice
.height
> img
->height
)
23527 slice
.height
= img
->height
- slice
.y
;
23529 if (slice
.width
== 0 || slice
.height
== 0)
23532 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23534 it
->descent
= slice
.height
- glyph_ascent
;
23536 it
->descent
+= img
->vmargin
;
23537 if (slice
.y
+ slice
.height
== img
->height
)
23538 it
->descent
+= img
->vmargin
;
23539 it
->phys_descent
= it
->descent
;
23541 it
->pixel_width
= slice
.width
;
23543 it
->pixel_width
+= img
->hmargin
;
23544 if (slice
.x
+ slice
.width
== img
->width
)
23545 it
->pixel_width
+= img
->hmargin
;
23547 /* It's quite possible for images to have an ascent greater than
23548 their height, so don't get confused in that case. */
23549 if (it
->descent
< 0)
23554 if (face
->box
!= FACE_NO_BOX
)
23556 if (face
->box_line_width
> 0)
23559 it
->ascent
+= face
->box_line_width
;
23560 if (slice
.y
+ slice
.height
== img
->height
)
23561 it
->descent
+= face
->box_line_width
;
23564 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23565 it
->pixel_width
+= eabs (face
->box_line_width
);
23566 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23567 it
->pixel_width
+= eabs (face
->box_line_width
);
23570 take_vertical_position_into_account (it
);
23572 /* Automatically crop wide image glyphs at right edge so we can
23573 draw the cursor on same display row. */
23574 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23575 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23577 it
->pixel_width
-= crop
;
23578 slice
.width
-= crop
;
23583 struct glyph
*glyph
;
23584 enum glyph_row_area area
= it
->area
;
23586 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23587 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23589 glyph
->charpos
= CHARPOS (it
->position
);
23590 glyph
->object
= it
->object
;
23591 glyph
->pixel_width
= it
->pixel_width
;
23592 glyph
->ascent
= glyph_ascent
;
23593 glyph
->descent
= it
->descent
;
23594 glyph
->voffset
= it
->voffset
;
23595 glyph
->type
= IMAGE_GLYPH
;
23596 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23597 glyph
->multibyte_p
= it
->multibyte_p
;
23598 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23599 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23600 glyph
->overlaps_vertically_p
= 0;
23601 glyph
->padding_p
= 0;
23602 glyph
->glyph_not_available_p
= 0;
23603 glyph
->face_id
= it
->face_id
;
23604 glyph
->u
.img_id
= img
->id
;
23605 glyph
->slice
.img
= slice
;
23606 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23609 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23610 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23612 glyph
->bidi_type
= it
->bidi_it
.type
;
23614 ++it
->glyph_row
->used
[area
];
23617 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23622 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23623 of the glyph, WIDTH and HEIGHT are the width and height of the
23624 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23627 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23628 int width
, int height
, int ascent
)
23630 struct glyph
*glyph
;
23631 enum glyph_row_area area
= it
->area
;
23633 xassert (ascent
>= 0 && ascent
<= height
);
23635 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23636 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23638 /* If the glyph row is reversed, we need to prepend the glyph
23639 rather than append it. */
23640 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23644 /* Make room for the additional glyph. */
23645 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23647 glyph
= it
->glyph_row
->glyphs
[area
];
23649 glyph
->charpos
= CHARPOS (it
->position
);
23650 glyph
->object
= object
;
23651 glyph
->pixel_width
= width
;
23652 glyph
->ascent
= ascent
;
23653 glyph
->descent
= height
- ascent
;
23654 glyph
->voffset
= it
->voffset
;
23655 glyph
->type
= STRETCH_GLYPH
;
23656 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23657 glyph
->multibyte_p
= it
->multibyte_p
;
23658 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23659 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23660 glyph
->overlaps_vertically_p
= 0;
23661 glyph
->padding_p
= 0;
23662 glyph
->glyph_not_available_p
= 0;
23663 glyph
->face_id
= it
->face_id
;
23664 glyph
->u
.stretch
.ascent
= ascent
;
23665 glyph
->u
.stretch
.height
= height
;
23666 glyph
->slice
.img
= null_glyph_slice
;
23667 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23670 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23671 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23673 glyph
->bidi_type
= it
->bidi_it
.type
;
23677 glyph
->resolved_level
= 0;
23678 glyph
->bidi_type
= UNKNOWN_BT
;
23680 ++it
->glyph_row
->used
[area
];
23683 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23686 #endif /* HAVE_WINDOW_SYSTEM */
23688 /* Produce a stretch glyph for iterator IT. IT->object is the value
23689 of the glyph property displayed. The value must be a list
23690 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23693 1. `:width WIDTH' specifies that the space should be WIDTH *
23694 canonical char width wide. WIDTH may be an integer or floating
23697 2. `:relative-width FACTOR' specifies that the width of the stretch
23698 should be computed from the width of the first character having the
23699 `glyph' property, and should be FACTOR times that width.
23701 3. `:align-to HPOS' specifies that the space should be wide enough
23702 to reach HPOS, a value in canonical character units.
23704 Exactly one of the above pairs must be present.
23706 4. `:height HEIGHT' specifies that the height of the stretch produced
23707 should be HEIGHT, measured in canonical character units.
23709 5. `:relative-height FACTOR' specifies that the height of the
23710 stretch should be FACTOR times the height of the characters having
23711 the glyph property.
23713 Either none or exactly one of 4 or 5 must be present.
23715 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23716 of the stretch should be used for the ascent of the stretch.
23717 ASCENT must be in the range 0 <= ASCENT <= 100. */
23720 produce_stretch_glyph (struct it
*it
)
23722 /* (space :width WIDTH :height HEIGHT ...) */
23723 Lisp_Object prop
, plist
;
23724 int width
= 0, height
= 0, align_to
= -1;
23725 int zero_width_ok_p
= 0;
23728 struct face
*face
= NULL
;
23729 struct font
*font
= NULL
;
23731 #ifdef HAVE_WINDOW_SYSTEM
23732 int zero_height_ok_p
= 0;
23734 if (FRAME_WINDOW_P (it
->f
))
23736 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23737 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23738 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23742 /* List should start with `space'. */
23743 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23744 plist
= XCDR (it
->object
);
23746 /* Compute the width of the stretch. */
23747 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23748 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23750 /* Absolute width `:width WIDTH' specified and valid. */
23751 zero_width_ok_p
= 1;
23754 #ifdef HAVE_WINDOW_SYSTEM
23755 else if (FRAME_WINDOW_P (it
->f
)
23756 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23758 /* Relative width `:relative-width FACTOR' specified and valid.
23759 Compute the width of the characters having the `glyph'
23762 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23765 if (it
->multibyte_p
)
23766 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
23769 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
23770 if (! ASCII_CHAR_P (it2
.c
))
23771 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
23774 it2
.glyph_row
= NULL
;
23775 it2
.what
= IT_CHARACTER
;
23776 x_produce_glyphs (&it2
);
23777 width
= NUMVAL (prop
) * it2
.pixel_width
;
23779 #endif /* HAVE_WINDOW_SYSTEM */
23780 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
23781 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
23783 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
23784 align_to
= (align_to
< 0
23786 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
23787 else if (align_to
< 0)
23788 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
23789 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
23790 zero_width_ok_p
= 1;
23793 /* Nothing specified -> width defaults to canonical char width. */
23794 width
= FRAME_COLUMN_WIDTH (it
->f
);
23796 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
23799 #ifdef HAVE_WINDOW_SYSTEM
23800 /* Compute height. */
23801 if (FRAME_WINDOW_P (it
->f
))
23803 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
23804 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23807 zero_height_ok_p
= 1;
23809 else if (prop
= Fplist_get (plist
, QCrelative_height
),
23811 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
23813 height
= FONT_HEIGHT (font
);
23815 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
23818 /* Compute percentage of height used for ascent. If
23819 `:ascent ASCENT' is present and valid, use that. Otherwise,
23820 derive the ascent from the font in use. */
23821 if (prop
= Fplist_get (plist
, QCascent
),
23822 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
23823 ascent
= height
* NUMVAL (prop
) / 100.0;
23824 else if (!NILP (prop
)
23825 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
23826 ascent
= min (max (0, (int)tem
), height
);
23828 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
23831 #endif /* HAVE_WINDOW_SYSTEM */
23834 if (width
> 0 && it
->line_wrap
!= TRUNCATE
23835 && it
->current_x
+ width
> it
->last_visible_x
)
23837 width
= it
->last_visible_x
- it
->current_x
;
23838 #ifdef HAVE_WINDOW_SYSTEM
23839 /* Subtract one more pixel from the stretch width, but only on
23840 GUI frames, since on a TTY each glyph is one "pixel" wide. */
23841 width
-= FRAME_WINDOW_P (it
->f
);
23845 if (width
> 0 && height
> 0 && it
->glyph_row
)
23847 Lisp_Object o_object
= it
->object
;
23848 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
23851 if (!STRINGP (object
))
23852 object
= it
->w
->buffer
;
23853 #ifdef HAVE_WINDOW_SYSTEM
23854 if (FRAME_WINDOW_P (it
->f
))
23855 append_stretch_glyph (it
, object
, width
, height
, ascent
);
23859 it
->object
= object
;
23860 it
->char_to_display
= ' ';
23861 it
->pixel_width
= it
->len
= 1;
23863 tty_append_glyph (it
);
23864 it
->object
= o_object
;
23868 it
->pixel_width
= width
;
23869 #ifdef HAVE_WINDOW_SYSTEM
23870 if (FRAME_WINDOW_P (it
->f
))
23872 it
->ascent
= it
->phys_ascent
= ascent
;
23873 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
23874 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
23875 take_vertical_position_into_account (it
);
23879 it
->nglyphs
= width
;
23882 #ifdef HAVE_WINDOW_SYSTEM
23884 /* Calculate line-height and line-spacing properties.
23885 An integer value specifies explicit pixel value.
23886 A float value specifies relative value to current face height.
23887 A cons (float . face-name) specifies relative value to
23888 height of specified face font.
23890 Returns height in pixels, or nil. */
23894 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
23895 int boff
, int override
)
23897 Lisp_Object face_name
= Qnil
;
23898 int ascent
, descent
, height
;
23900 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
23905 face_name
= XCAR (val
);
23907 if (!NUMBERP (val
))
23908 val
= make_number (1);
23909 if (NILP (face_name
))
23911 height
= it
->ascent
+ it
->descent
;
23916 if (NILP (face_name
))
23918 font
= FRAME_FONT (it
->f
);
23919 boff
= FRAME_BASELINE_OFFSET (it
->f
);
23921 else if (EQ (face_name
, Qt
))
23930 face_id
= lookup_named_face (it
->f
, face_name
, 0);
23932 return make_number (-1);
23934 face
= FACE_FROM_ID (it
->f
, face_id
);
23937 return make_number (-1);
23938 boff
= font
->baseline_offset
;
23939 if (font
->vertical_centering
)
23940 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23943 ascent
= FONT_BASE (font
) + boff
;
23944 descent
= FONT_DESCENT (font
) - boff
;
23948 it
->override_ascent
= ascent
;
23949 it
->override_descent
= descent
;
23950 it
->override_boff
= boff
;
23953 height
= ascent
+ descent
;
23957 height
= (int)(XFLOAT_DATA (val
) * height
);
23958 else if (INTEGERP (val
))
23959 height
*= XINT (val
);
23961 return make_number (height
);
23965 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
23966 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
23967 and only if this is for a character for which no font was found.
23969 If the display method (it->glyphless_method) is
23970 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
23971 length of the acronym or the hexadecimal string, UPPER_XOFF and
23972 UPPER_YOFF are pixel offsets for the upper part of the string,
23973 LOWER_XOFF and LOWER_YOFF are for the lower part.
23975 For the other display methods, LEN through LOWER_YOFF are zero. */
23978 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
23979 short upper_xoff
, short upper_yoff
,
23980 short lower_xoff
, short lower_yoff
)
23982 struct glyph
*glyph
;
23983 enum glyph_row_area area
= it
->area
;
23985 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23986 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23988 /* If the glyph row is reversed, we need to prepend the glyph
23989 rather than append it. */
23990 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23994 /* Make room for the additional glyph. */
23995 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23997 glyph
= it
->glyph_row
->glyphs
[area
];
23999 glyph
->charpos
= CHARPOS (it
->position
);
24000 glyph
->object
= it
->object
;
24001 glyph
->pixel_width
= it
->pixel_width
;
24002 glyph
->ascent
= it
->ascent
;
24003 glyph
->descent
= it
->descent
;
24004 glyph
->voffset
= it
->voffset
;
24005 glyph
->type
= GLYPHLESS_GLYPH
;
24006 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24007 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24008 glyph
->u
.glyphless
.len
= len
;
24009 glyph
->u
.glyphless
.ch
= it
->c
;
24010 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24011 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24012 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24013 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24014 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24015 glyph
->multibyte_p
= it
->multibyte_p
;
24016 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24017 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24018 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24019 || it
->phys_descent
> it
->descent
);
24020 glyph
->padding_p
= 0;
24021 glyph
->glyph_not_available_p
= 0;
24022 glyph
->face_id
= face_id
;
24023 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24026 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24027 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24029 glyph
->bidi_type
= it
->bidi_it
.type
;
24031 ++it
->glyph_row
->used
[area
];
24034 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24038 /* Produce a glyph for a glyphless character for iterator IT.
24039 IT->glyphless_method specifies which method to use for displaying
24040 the character. See the description of enum
24041 glyphless_display_method in dispextern.h for the detail.
24043 FOR_NO_FONT is nonzero if and only if this is for a character for
24044 which no font was found. ACRONYM, if non-nil, is an acronym string
24045 for the character. */
24048 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24053 int base_width
, base_height
, width
, height
;
24054 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24057 /* Get the metrics of the base font. We always refer to the current
24059 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24060 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24061 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24062 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24063 base_height
= it
->ascent
+ it
->descent
;
24064 base_width
= font
->average_width
;
24066 /* Get a face ID for the glyph by utilizing a cache (the same way as
24067 done for `escape-glyph' in get_next_display_element). */
24068 if (it
->f
== last_glyphless_glyph_frame
24069 && it
->face_id
== last_glyphless_glyph_face_id
)
24071 face_id
= last_glyphless_glyph_merged_face_id
;
24075 /* Merge the `glyphless-char' face into the current face. */
24076 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24077 last_glyphless_glyph_frame
= it
->f
;
24078 last_glyphless_glyph_face_id
= it
->face_id
;
24079 last_glyphless_glyph_merged_face_id
= face_id
;
24082 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24084 it
->pixel_width
= THIN_SPACE_WIDTH
;
24086 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24088 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24090 width
= CHAR_WIDTH (it
->c
);
24093 else if (width
> 4)
24095 it
->pixel_width
= base_width
* width
;
24097 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24103 unsigned int code
[6];
24105 int ascent
, descent
;
24106 struct font_metrics metrics_upper
, metrics_lower
;
24108 face
= FACE_FROM_ID (it
->f
, face_id
);
24109 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24110 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24112 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24114 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24115 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24116 if (CONSP (acronym
))
24117 acronym
= XCAR (acronym
);
24118 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24122 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24123 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24126 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24127 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24128 upper_len
= (len
+ 1) / 2;
24129 font
->driver
->text_extents (font
, code
, upper_len
,
24131 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24136 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24137 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24138 upper_xoff
= upper_yoff
= 2; /* the typical case */
24139 if (base_width
>= width
)
24141 /* Align the upper to the left, the lower to the right. */
24142 it
->pixel_width
= base_width
;
24143 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24147 /* Center the shorter one. */
24148 it
->pixel_width
= width
;
24149 if (metrics_upper
.width
>= metrics_lower
.width
)
24150 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24153 /* FIXME: This code doesn't look right. It formerly was
24154 missing the "lower_xoff = 0;", which couldn't have
24155 been right since it left lower_xoff uninitialized. */
24157 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24161 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24162 top, bottom, and between upper and lower strings. */
24163 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24164 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24165 /* Center vertically.
24166 H:base_height, D:base_descent
24167 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24169 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24170 descent = D - H/2 + h/2;
24171 lower_yoff = descent - 2 - ld;
24172 upper_yoff = lower_yoff - la - 1 - ud; */
24173 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24174 descent
= it
->descent
- (base_height
- height
) / 2;
24175 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24176 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24177 - metrics_upper
.descent
);
24178 /* Don't make the height shorter than the base height. */
24179 if (height
> base_height
)
24181 it
->ascent
= ascent
;
24182 it
->descent
= descent
;
24186 it
->phys_ascent
= it
->ascent
;
24187 it
->phys_descent
= it
->descent
;
24189 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24190 upper_xoff
, upper_yoff
,
24191 lower_xoff
, lower_yoff
);
24193 take_vertical_position_into_account (it
);
24198 Produce glyphs/get display metrics for the display element IT is
24199 loaded with. See the description of struct it in dispextern.h
24200 for an overview of struct it. */
24203 x_produce_glyphs (struct it
*it
)
24205 int extra_line_spacing
= it
->extra_line_spacing
;
24207 it
->glyph_not_available_p
= 0;
24209 if (it
->what
== IT_CHARACTER
)
24212 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24213 struct font
*font
= face
->font
;
24214 struct font_metrics
*pcm
= NULL
;
24215 int boff
; /* baseline offset */
24219 /* When no suitable font is found, display this character by
24220 the method specified in the first extra slot of
24221 Vglyphless_char_display. */
24222 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24224 xassert (it
->what
== IT_GLYPHLESS
);
24225 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24229 boff
= font
->baseline_offset
;
24230 if (font
->vertical_centering
)
24231 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24233 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24239 if (it
->override_ascent
>= 0)
24241 it
->ascent
= it
->override_ascent
;
24242 it
->descent
= it
->override_descent
;
24243 boff
= it
->override_boff
;
24247 it
->ascent
= FONT_BASE (font
) + boff
;
24248 it
->descent
= FONT_DESCENT (font
) - boff
;
24251 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24253 pcm
= get_per_char_metric (font
, &char2b
);
24254 if (pcm
->width
== 0
24255 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24261 it
->phys_ascent
= pcm
->ascent
+ boff
;
24262 it
->phys_descent
= pcm
->descent
- boff
;
24263 it
->pixel_width
= pcm
->width
;
24267 it
->glyph_not_available_p
= 1;
24268 it
->phys_ascent
= it
->ascent
;
24269 it
->phys_descent
= it
->descent
;
24270 it
->pixel_width
= font
->space_width
;
24273 if (it
->constrain_row_ascent_descent_p
)
24275 if (it
->descent
> it
->max_descent
)
24277 it
->ascent
+= it
->descent
- it
->max_descent
;
24278 it
->descent
= it
->max_descent
;
24280 if (it
->ascent
> it
->max_ascent
)
24282 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24283 it
->ascent
= it
->max_ascent
;
24285 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24286 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24287 extra_line_spacing
= 0;
24290 /* If this is a space inside a region of text with
24291 `space-width' property, change its width. */
24292 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24294 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24296 /* If face has a box, add the box thickness to the character
24297 height. If character has a box line to the left and/or
24298 right, add the box line width to the character's width. */
24299 if (face
->box
!= FACE_NO_BOX
)
24301 int thick
= face
->box_line_width
;
24305 it
->ascent
+= thick
;
24306 it
->descent
+= thick
;
24311 if (it
->start_of_box_run_p
)
24312 it
->pixel_width
+= thick
;
24313 if (it
->end_of_box_run_p
)
24314 it
->pixel_width
+= thick
;
24317 /* If face has an overline, add the height of the overline
24318 (1 pixel) and a 1 pixel margin to the character height. */
24319 if (face
->overline_p
)
24320 it
->ascent
+= overline_margin
;
24322 if (it
->constrain_row_ascent_descent_p
)
24324 if (it
->ascent
> it
->max_ascent
)
24325 it
->ascent
= it
->max_ascent
;
24326 if (it
->descent
> it
->max_descent
)
24327 it
->descent
= it
->max_descent
;
24330 take_vertical_position_into_account (it
);
24332 /* If we have to actually produce glyphs, do it. */
24337 /* Translate a space with a `space-width' property
24338 into a stretch glyph. */
24339 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24340 / FONT_HEIGHT (font
));
24341 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24342 it
->ascent
+ it
->descent
, ascent
);
24347 /* If characters with lbearing or rbearing are displayed
24348 in this line, record that fact in a flag of the
24349 glyph row. This is used to optimize X output code. */
24350 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24351 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24353 if (! stretched_p
&& it
->pixel_width
== 0)
24354 /* We assure that all visible glyphs have at least 1-pixel
24356 it
->pixel_width
= 1;
24358 else if (it
->char_to_display
== '\n')
24360 /* A newline has no width, but we need the height of the
24361 line. But if previous part of the line sets a height,
24362 don't increase that height */
24364 Lisp_Object height
;
24365 Lisp_Object total_height
= Qnil
;
24367 it
->override_ascent
= -1;
24368 it
->pixel_width
= 0;
24371 height
= get_it_property (it
, Qline_height
);
24372 /* Split (line-height total-height) list */
24374 && CONSP (XCDR (height
))
24375 && NILP (XCDR (XCDR (height
))))
24377 total_height
= XCAR (XCDR (height
));
24378 height
= XCAR (height
);
24380 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24382 if (it
->override_ascent
>= 0)
24384 it
->ascent
= it
->override_ascent
;
24385 it
->descent
= it
->override_descent
;
24386 boff
= it
->override_boff
;
24390 it
->ascent
= FONT_BASE (font
) + boff
;
24391 it
->descent
= FONT_DESCENT (font
) - boff
;
24394 if (EQ (height
, Qt
))
24396 if (it
->descent
> it
->max_descent
)
24398 it
->ascent
+= it
->descent
- it
->max_descent
;
24399 it
->descent
= it
->max_descent
;
24401 if (it
->ascent
> it
->max_ascent
)
24403 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24404 it
->ascent
= it
->max_ascent
;
24406 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24407 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24408 it
->constrain_row_ascent_descent_p
= 1;
24409 extra_line_spacing
= 0;
24413 Lisp_Object spacing
;
24415 it
->phys_ascent
= it
->ascent
;
24416 it
->phys_descent
= it
->descent
;
24418 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24419 && face
->box
!= FACE_NO_BOX
24420 && face
->box_line_width
> 0)
24422 it
->ascent
+= face
->box_line_width
;
24423 it
->descent
+= face
->box_line_width
;
24426 && XINT (height
) > it
->ascent
+ it
->descent
)
24427 it
->ascent
= XINT (height
) - it
->descent
;
24429 if (!NILP (total_height
))
24430 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24433 spacing
= get_it_property (it
, Qline_spacing
);
24434 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24436 if (INTEGERP (spacing
))
24438 extra_line_spacing
= XINT (spacing
);
24439 if (!NILP (total_height
))
24440 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24444 else /* i.e. (it->char_to_display == '\t') */
24446 if (font
->space_width
> 0)
24448 int tab_width
= it
->tab_width
* font
->space_width
;
24449 int x
= it
->current_x
+ it
->continuation_lines_width
;
24450 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24452 /* If the distance from the current position to the next tab
24453 stop is less than a space character width, use the
24454 tab stop after that. */
24455 if (next_tab_x
- x
< font
->space_width
)
24456 next_tab_x
+= tab_width
;
24458 it
->pixel_width
= next_tab_x
- x
;
24460 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24461 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24465 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24466 it
->ascent
+ it
->descent
, it
->ascent
);
24471 it
->pixel_width
= 0;
24476 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24478 /* A static composition.
24480 Note: A composition is represented as one glyph in the
24481 glyph matrix. There are no padding glyphs.
24483 Important note: pixel_width, ascent, and descent are the
24484 values of what is drawn by draw_glyphs (i.e. the values of
24485 the overall glyphs composed). */
24486 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24487 int boff
; /* baseline offset */
24488 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24489 int glyph_len
= cmp
->glyph_len
;
24490 struct font
*font
= face
->font
;
24494 /* If we have not yet calculated pixel size data of glyphs of
24495 the composition for the current face font, calculate them
24496 now. Theoretically, we have to check all fonts for the
24497 glyphs, but that requires much time and memory space. So,
24498 here we check only the font of the first glyph. This may
24499 lead to incorrect display, but it's very rare, and C-l
24500 (recenter-top-bottom) can correct the display anyway. */
24501 if (! cmp
->font
|| cmp
->font
!= font
)
24503 /* Ascent and descent of the font of the first character
24504 of this composition (adjusted by baseline offset).
24505 Ascent and descent of overall glyphs should not be less
24506 than these, respectively. */
24507 int font_ascent
, font_descent
, font_height
;
24508 /* Bounding box of the overall glyphs. */
24509 int leftmost
, rightmost
, lowest
, highest
;
24510 int lbearing
, rbearing
;
24511 int i
, width
, ascent
, descent
;
24512 int left_padded
= 0, right_padded
= 0;
24513 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24515 struct font_metrics
*pcm
;
24516 int font_not_found_p
;
24519 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24520 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24522 if (glyph_len
< cmp
->glyph_len
)
24524 for (i
= 0; i
< glyph_len
; i
++)
24526 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24528 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24533 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24534 : IT_CHARPOS (*it
));
24535 /* If no suitable font is found, use the default font. */
24536 font_not_found_p
= font
== NULL
;
24537 if (font_not_found_p
)
24539 face
= face
->ascii_face
;
24542 boff
= font
->baseline_offset
;
24543 if (font
->vertical_centering
)
24544 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24545 font_ascent
= FONT_BASE (font
) + boff
;
24546 font_descent
= FONT_DESCENT (font
) - boff
;
24547 font_height
= FONT_HEIGHT (font
);
24549 cmp
->font
= (void *) font
;
24552 if (! font_not_found_p
)
24554 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24556 pcm
= get_per_char_metric (font
, &char2b
);
24559 /* Initialize the bounding box. */
24562 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24563 ascent
= pcm
->ascent
;
24564 descent
= pcm
->descent
;
24565 lbearing
= pcm
->lbearing
;
24566 rbearing
= pcm
->rbearing
;
24570 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24571 ascent
= FONT_BASE (font
);
24572 descent
= FONT_DESCENT (font
);
24579 lowest
= - descent
+ boff
;
24580 highest
= ascent
+ boff
;
24582 if (! font_not_found_p
24583 && font
->default_ascent
24584 && CHAR_TABLE_P (Vuse_default_ascent
)
24585 && !NILP (Faref (Vuse_default_ascent
,
24586 make_number (it
->char_to_display
))))
24587 highest
= font
->default_ascent
+ boff
;
24589 /* Draw the first glyph at the normal position. It may be
24590 shifted to right later if some other glyphs are drawn
24592 cmp
->offsets
[i
* 2] = 0;
24593 cmp
->offsets
[i
* 2 + 1] = boff
;
24594 cmp
->lbearing
= lbearing
;
24595 cmp
->rbearing
= rbearing
;
24597 /* Set cmp->offsets for the remaining glyphs. */
24598 for (i
++; i
< glyph_len
; i
++)
24600 int left
, right
, btm
, top
;
24601 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24603 struct face
*this_face
;
24607 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24608 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24609 font
= this_face
->font
;
24615 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24617 pcm
= get_per_char_metric (font
, &char2b
);
24620 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24623 width
= pcm
->width
;
24624 ascent
= pcm
->ascent
;
24625 descent
= pcm
->descent
;
24626 lbearing
= pcm
->lbearing
;
24627 rbearing
= pcm
->rbearing
;
24628 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24630 /* Relative composition with or without
24631 alternate chars. */
24632 left
= (leftmost
+ rightmost
- width
) / 2;
24633 btm
= - descent
+ boff
;
24634 if (font
->relative_compose
24635 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24636 || NILP (Faref (Vignore_relative_composition
,
24637 make_number (ch
)))))
24640 if (- descent
>= font
->relative_compose
)
24641 /* One extra pixel between two glyphs. */
24643 else if (ascent
<= 0)
24644 /* One extra pixel between two glyphs. */
24645 btm
= lowest
- 1 - ascent
- descent
;
24650 /* A composition rule is specified by an integer
24651 value that encodes global and new reference
24652 points (GREF and NREF). GREF and NREF are
24653 specified by numbers as below:
24655 0---1---2 -- ascent
24659 9--10--11 -- center
24661 ---3---4---5--- baseline
24663 6---7---8 -- descent
24665 int rule
= COMPOSITION_RULE (cmp
, i
);
24666 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
24668 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
24669 grefx
= gref
% 3, nrefx
= nref
% 3;
24670 grefy
= gref
/ 3, nrefy
= nref
/ 3;
24672 xoff
= font_height
* (xoff
- 128) / 256;
24674 yoff
= font_height
* (yoff
- 128) / 256;
24677 + grefx
* (rightmost
- leftmost
) / 2
24678 - nrefx
* width
/ 2
24681 btm
= ((grefy
== 0 ? highest
24683 : grefy
== 2 ? lowest
24684 : (highest
+ lowest
) / 2)
24685 - (nrefy
== 0 ? ascent
+ descent
24686 : nrefy
== 1 ? descent
- boff
24688 : (ascent
+ descent
) / 2)
24692 cmp
->offsets
[i
* 2] = left
;
24693 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
24695 /* Update the bounding box of the overall glyphs. */
24698 right
= left
+ width
;
24699 if (left
< leftmost
)
24701 if (right
> rightmost
)
24704 top
= btm
+ descent
+ ascent
;
24710 if (cmp
->lbearing
> left
+ lbearing
)
24711 cmp
->lbearing
= left
+ lbearing
;
24712 if (cmp
->rbearing
< left
+ rbearing
)
24713 cmp
->rbearing
= left
+ rbearing
;
24717 /* If there are glyphs whose x-offsets are negative,
24718 shift all glyphs to the right and make all x-offsets
24722 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24723 cmp
->offsets
[i
* 2] -= leftmost
;
24724 rightmost
-= leftmost
;
24725 cmp
->lbearing
-= leftmost
;
24726 cmp
->rbearing
-= leftmost
;
24729 if (left_padded
&& cmp
->lbearing
< 0)
24731 for (i
= 0; i
< cmp
->glyph_len
; i
++)
24732 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
24733 rightmost
-= cmp
->lbearing
;
24734 cmp
->rbearing
-= cmp
->lbearing
;
24737 if (right_padded
&& rightmost
< cmp
->rbearing
)
24739 rightmost
= cmp
->rbearing
;
24742 cmp
->pixel_width
= rightmost
;
24743 cmp
->ascent
= highest
;
24744 cmp
->descent
= - lowest
;
24745 if (cmp
->ascent
< font_ascent
)
24746 cmp
->ascent
= font_ascent
;
24747 if (cmp
->descent
< font_descent
)
24748 cmp
->descent
= font_descent
;
24752 && (cmp
->lbearing
< 0
24753 || cmp
->rbearing
> cmp
->pixel_width
))
24754 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24756 it
->pixel_width
= cmp
->pixel_width
;
24757 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
24758 it
->descent
= it
->phys_descent
= cmp
->descent
;
24759 if (face
->box
!= FACE_NO_BOX
)
24761 int thick
= face
->box_line_width
;
24765 it
->ascent
+= thick
;
24766 it
->descent
+= thick
;
24771 if (it
->start_of_box_run_p
)
24772 it
->pixel_width
+= thick
;
24773 if (it
->end_of_box_run_p
)
24774 it
->pixel_width
+= thick
;
24777 /* If face has an overline, add the height of the overline
24778 (1 pixel) and a 1 pixel margin to the character height. */
24779 if (face
->overline_p
)
24780 it
->ascent
+= overline_margin
;
24782 take_vertical_position_into_account (it
);
24783 if (it
->ascent
< 0)
24785 if (it
->descent
< 0)
24788 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
24789 append_composite_glyph (it
);
24791 else if (it
->what
== IT_COMPOSITION
)
24793 /* A dynamic (automatic) composition. */
24794 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24795 Lisp_Object gstring
;
24796 struct font_metrics metrics
;
24800 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
24802 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
24805 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
24806 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24807 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
24808 it
->descent
= it
->phys_descent
= metrics
.descent
;
24809 if (face
->box
!= FACE_NO_BOX
)
24811 int thick
= face
->box_line_width
;
24815 it
->ascent
+= thick
;
24816 it
->descent
+= thick
;
24821 if (it
->start_of_box_run_p
)
24822 it
->pixel_width
+= thick
;
24823 if (it
->end_of_box_run_p
)
24824 it
->pixel_width
+= thick
;
24826 /* If face has an overline, add the height of the overline
24827 (1 pixel) and a 1 pixel margin to the character height. */
24828 if (face
->overline_p
)
24829 it
->ascent
+= overline_margin
;
24830 take_vertical_position_into_account (it
);
24831 if (it
->ascent
< 0)
24833 if (it
->descent
< 0)
24837 append_composite_glyph (it
);
24839 else if (it
->what
== IT_GLYPHLESS
)
24840 produce_glyphless_glyph (it
, 0, Qnil
);
24841 else if (it
->what
== IT_IMAGE
)
24842 produce_image_glyph (it
);
24843 else if (it
->what
== IT_STRETCH
)
24844 produce_stretch_glyph (it
);
24847 /* Accumulate dimensions. Note: can't assume that it->descent > 0
24848 because this isn't true for images with `:ascent 100'. */
24849 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
24850 if (it
->area
== TEXT_AREA
)
24851 it
->current_x
+= it
->pixel_width
;
24853 if (extra_line_spacing
> 0)
24855 it
->descent
+= extra_line_spacing
;
24856 if (extra_line_spacing
> it
->max_extra_line_spacing
)
24857 it
->max_extra_line_spacing
= extra_line_spacing
;
24860 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
24861 it
->max_descent
= max (it
->max_descent
, it
->descent
);
24862 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
24863 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
24867 Output LEN glyphs starting at START at the nominal cursor position.
24868 Advance the nominal cursor over the text. The global variable
24869 updated_window contains the window being updated, updated_row is
24870 the glyph row being updated, and updated_area is the area of that
24871 row being updated. */
24874 x_write_glyphs (struct glyph
*start
, int len
)
24876 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
24878 xassert (updated_window
&& updated_row
);
24879 /* When the window is hscrolled, cursor hpos can legitimately be out
24880 of bounds, but we draw the cursor at the corresponding window
24881 margin in that case. */
24882 if (!updated_row
->reversed_p
&& chpos
< 0)
24884 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
24885 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
24889 /* Write glyphs. */
24891 hpos
= start
- updated_row
->glyphs
[updated_area
];
24892 x
= draw_glyphs (updated_window
, output_cursor
.x
,
24893 updated_row
, updated_area
,
24895 DRAW_NORMAL_TEXT
, 0);
24897 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
24898 if (updated_area
== TEXT_AREA
24899 && updated_window
->phys_cursor_on_p
24900 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
24902 && chpos
< hpos
+ len
)
24903 updated_window
->phys_cursor_on_p
= 0;
24907 /* Advance the output cursor. */
24908 output_cursor
.hpos
+= len
;
24909 output_cursor
.x
= x
;
24914 Insert LEN glyphs from START at the nominal cursor position. */
24917 x_insert_glyphs (struct glyph
*start
, int len
)
24921 int line_height
, shift_by_width
, shifted_region_width
;
24922 struct glyph_row
*row
;
24923 struct glyph
*glyph
;
24924 int frame_x
, frame_y
;
24927 xassert (updated_window
&& updated_row
);
24929 w
= updated_window
;
24930 f
= XFRAME (WINDOW_FRAME (w
));
24932 /* Get the height of the line we are in. */
24934 line_height
= row
->height
;
24936 /* Get the width of the glyphs to insert. */
24937 shift_by_width
= 0;
24938 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
24939 shift_by_width
+= glyph
->pixel_width
;
24941 /* Get the width of the region to shift right. */
24942 shifted_region_width
= (window_box_width (w
, updated_area
)
24947 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
24948 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
24950 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
24951 line_height
, shift_by_width
);
24953 /* Write the glyphs. */
24954 hpos
= start
- row
->glyphs
[updated_area
];
24955 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
24957 DRAW_NORMAL_TEXT
, 0);
24959 /* Advance the output cursor. */
24960 output_cursor
.hpos
+= len
;
24961 output_cursor
.x
+= shift_by_width
;
24967 Erase the current text line from the nominal cursor position
24968 (inclusive) to pixel column TO_X (exclusive). The idea is that
24969 everything from TO_X onward is already erased.
24971 TO_X is a pixel position relative to updated_area of
24972 updated_window. TO_X == -1 means clear to the end of this area. */
24975 x_clear_end_of_line (int to_x
)
24978 struct window
*w
= updated_window
;
24979 int max_x
, min_y
, max_y
;
24980 int from_x
, from_y
, to_y
;
24982 xassert (updated_window
&& updated_row
);
24983 f
= XFRAME (w
->frame
);
24985 if (updated_row
->full_width_p
)
24986 max_x
= WINDOW_TOTAL_WIDTH (w
);
24988 max_x
= window_box_width (w
, updated_area
);
24989 max_y
= window_text_bottom_y (w
);
24991 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
24992 of window. For TO_X > 0, truncate to end of drawing area. */
24998 to_x
= min (to_x
, max_x
);
25000 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25002 /* Notice if the cursor will be cleared by this operation. */
25003 if (!updated_row
->full_width_p
)
25004 notice_overwritten_cursor (w
, updated_area
,
25005 output_cursor
.x
, -1,
25007 MATRIX_ROW_BOTTOM_Y (updated_row
));
25009 from_x
= output_cursor
.x
;
25011 /* Translate to frame coordinates. */
25012 if (updated_row
->full_width_p
)
25014 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25015 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25019 int area_left
= window_box_left (w
, updated_area
);
25020 from_x
+= area_left
;
25024 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25025 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25026 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25028 /* Prevent inadvertently clearing to end of the X window. */
25029 if (to_x
> from_x
&& to_y
> from_y
)
25032 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25033 to_x
- from_x
, to_y
- from_y
);
25038 #endif /* HAVE_WINDOW_SYSTEM */
25042 /***********************************************************************
25044 ***********************************************************************/
25046 /* Value is the internal representation of the specified cursor type
25047 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25048 of the bar cursor. */
25050 static enum text_cursor_kinds
25051 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25053 enum text_cursor_kinds type
;
25058 if (EQ (arg
, Qbox
))
25059 return FILLED_BOX_CURSOR
;
25061 if (EQ (arg
, Qhollow
))
25062 return HOLLOW_BOX_CURSOR
;
25064 if (EQ (arg
, Qbar
))
25071 && EQ (XCAR (arg
), Qbar
)
25072 && INTEGERP (XCDR (arg
))
25073 && XINT (XCDR (arg
)) >= 0)
25075 *width
= XINT (XCDR (arg
));
25079 if (EQ (arg
, Qhbar
))
25082 return HBAR_CURSOR
;
25086 && EQ (XCAR (arg
), Qhbar
)
25087 && INTEGERP (XCDR (arg
))
25088 && XINT (XCDR (arg
)) >= 0)
25090 *width
= XINT (XCDR (arg
));
25091 return HBAR_CURSOR
;
25094 /* Treat anything unknown as "hollow box cursor".
25095 It was bad to signal an error; people have trouble fixing
25096 .Xdefaults with Emacs, when it has something bad in it. */
25097 type
= HOLLOW_BOX_CURSOR
;
25102 /* Set the default cursor types for specified frame. */
25104 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25109 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25110 FRAME_CURSOR_WIDTH (f
) = width
;
25112 /* By default, set up the blink-off state depending on the on-state. */
25114 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25117 FRAME_BLINK_OFF_CURSOR (f
)
25118 = get_specified_cursor_type (XCDR (tem
), &width
);
25119 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25122 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25126 #ifdef HAVE_WINDOW_SYSTEM
25128 /* Return the cursor we want to be displayed in window W. Return
25129 width of bar/hbar cursor through WIDTH arg. Return with
25130 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25131 (i.e. if the `system caret' should track this cursor).
25133 In a mini-buffer window, we want the cursor only to appear if we
25134 are reading input from this window. For the selected window, we
25135 want the cursor type given by the frame parameter or buffer local
25136 setting of cursor-type. If explicitly marked off, draw no cursor.
25137 In all other cases, we want a hollow box cursor. */
25139 static enum text_cursor_kinds
25140 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25141 int *active_cursor
)
25143 struct frame
*f
= XFRAME (w
->frame
);
25144 struct buffer
*b
= XBUFFER (w
->buffer
);
25145 int cursor_type
= DEFAULT_CURSOR
;
25146 Lisp_Object alt_cursor
;
25147 int non_selected
= 0;
25149 *active_cursor
= 1;
25152 if (cursor_in_echo_area
25153 && FRAME_HAS_MINIBUF_P (f
)
25154 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25156 if (w
== XWINDOW (echo_area_window
))
25158 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25160 *width
= FRAME_CURSOR_WIDTH (f
);
25161 return FRAME_DESIRED_CURSOR (f
);
25164 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25167 *active_cursor
= 0;
25171 /* Detect a nonselected window or nonselected frame. */
25172 else if (w
!= XWINDOW (f
->selected_window
)
25173 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25175 *active_cursor
= 0;
25177 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25183 /* Never display a cursor in a window in which cursor-type is nil. */
25184 if (NILP (BVAR (b
, cursor_type
)))
25187 /* Get the normal cursor type for this window. */
25188 if (EQ (BVAR (b
, cursor_type
), Qt
))
25190 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25191 *width
= FRAME_CURSOR_WIDTH (f
);
25194 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25196 /* Use cursor-in-non-selected-windows instead
25197 for non-selected window or frame. */
25200 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25201 if (!EQ (Qt
, alt_cursor
))
25202 return get_specified_cursor_type (alt_cursor
, width
);
25203 /* t means modify the normal cursor type. */
25204 if (cursor_type
== FILLED_BOX_CURSOR
)
25205 cursor_type
= HOLLOW_BOX_CURSOR
;
25206 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25208 return cursor_type
;
25211 /* Use normal cursor if not blinked off. */
25212 if (!w
->cursor_off_p
)
25214 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25216 if (cursor_type
== FILLED_BOX_CURSOR
)
25218 /* Using a block cursor on large images can be very annoying.
25219 So use a hollow cursor for "large" images.
25220 If image is not transparent (no mask), also use hollow cursor. */
25221 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25222 if (img
!= NULL
&& IMAGEP (img
->spec
))
25224 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25225 where N = size of default frame font size.
25226 This should cover most of the "tiny" icons people may use. */
25228 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25229 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25230 cursor_type
= HOLLOW_BOX_CURSOR
;
25233 else if (cursor_type
!= NO_CURSOR
)
25235 /* Display current only supports BOX and HOLLOW cursors for images.
25236 So for now, unconditionally use a HOLLOW cursor when cursor is
25237 not a solid box cursor. */
25238 cursor_type
= HOLLOW_BOX_CURSOR
;
25241 return cursor_type
;
25244 /* Cursor is blinked off, so determine how to "toggle" it. */
25246 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25247 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25248 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25250 /* Then see if frame has specified a specific blink off cursor type. */
25251 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25253 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25254 return FRAME_BLINK_OFF_CURSOR (f
);
25258 /* Some people liked having a permanently visible blinking cursor,
25259 while others had very strong opinions against it. So it was
25260 decided to remove it. KFS 2003-09-03 */
25262 /* Finally perform built-in cursor blinking:
25263 filled box <-> hollow box
25264 wide [h]bar <-> narrow [h]bar
25265 narrow [h]bar <-> no cursor
25266 other type <-> no cursor */
25268 if (cursor_type
== FILLED_BOX_CURSOR
)
25269 return HOLLOW_BOX_CURSOR
;
25271 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25274 return cursor_type
;
25282 /* Notice when the text cursor of window W has been completely
25283 overwritten by a drawing operation that outputs glyphs in AREA
25284 starting at X0 and ending at X1 in the line starting at Y0 and
25285 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25286 the rest of the line after X0 has been written. Y coordinates
25287 are window-relative. */
25290 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25291 int x0
, int x1
, int y0
, int y1
)
25293 int cx0
, cx1
, cy0
, cy1
;
25294 struct glyph_row
*row
;
25296 if (!w
->phys_cursor_on_p
)
25298 if (area
!= TEXT_AREA
)
25301 if (w
->phys_cursor
.vpos
< 0
25302 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25303 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25304 !(row
->enabled_p
&& row
->displays_text_p
)))
25307 if (row
->cursor_in_fringe_p
)
25309 row
->cursor_in_fringe_p
= 0;
25310 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25311 w
->phys_cursor_on_p
= 0;
25315 cx0
= w
->phys_cursor
.x
;
25316 cx1
= cx0
+ w
->phys_cursor_width
;
25317 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25320 /* The cursor image will be completely removed from the
25321 screen if the output area intersects the cursor area in
25322 y-direction. When we draw in [y0 y1[, and some part of
25323 the cursor is at y < y0, that part must have been drawn
25324 before. When scrolling, the cursor is erased before
25325 actually scrolling, so we don't come here. When not
25326 scrolling, the rows above the old cursor row must have
25327 changed, and in this case these rows must have written
25328 over the cursor image.
25330 Likewise if part of the cursor is below y1, with the
25331 exception of the cursor being in the first blank row at
25332 the buffer and window end because update_text_area
25333 doesn't draw that row. (Except when it does, but
25334 that's handled in update_text_area.) */
25336 cy0
= w
->phys_cursor
.y
;
25337 cy1
= cy0
+ w
->phys_cursor_height
;
25338 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25341 w
->phys_cursor_on_p
= 0;
25344 #endif /* HAVE_WINDOW_SYSTEM */
25347 /************************************************************************
25349 ************************************************************************/
25351 #ifdef HAVE_WINDOW_SYSTEM
25354 Fix the display of area AREA of overlapping row ROW in window W
25355 with respect to the overlapping part OVERLAPS. */
25358 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25359 enum glyph_row_area area
, int overlaps
)
25366 for (i
= 0; i
< row
->used
[area
];)
25368 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25370 int start
= i
, start_x
= x
;
25374 x
+= row
->glyphs
[area
][i
].pixel_width
;
25377 while (i
< row
->used
[area
]
25378 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25380 draw_glyphs (w
, start_x
, row
, area
,
25382 DRAW_NORMAL_TEXT
, overlaps
);
25386 x
+= row
->glyphs
[area
][i
].pixel_width
;
25396 Draw the cursor glyph of window W in glyph row ROW. See the
25397 comment of draw_glyphs for the meaning of HL. */
25400 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25401 enum draw_glyphs_face hl
)
25403 /* If cursor hpos is out of bounds, don't draw garbage. This can
25404 happen in mini-buffer windows when switching between echo area
25405 glyphs and mini-buffer. */
25406 if ((row
->reversed_p
25407 ? (w
->phys_cursor
.hpos
>= 0)
25408 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25410 int on_p
= w
->phys_cursor_on_p
;
25412 int hpos
= w
->phys_cursor
.hpos
;
25414 /* When the window is hscrolled, cursor hpos can legitimately be
25415 out of bounds, but we draw the cursor at the corresponding
25416 window margin in that case. */
25417 if (!row
->reversed_p
&& hpos
< 0)
25419 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25420 hpos
= row
->used
[TEXT_AREA
] - 1;
25422 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25424 w
->phys_cursor_on_p
= on_p
;
25426 if (hl
== DRAW_CURSOR
)
25427 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25428 /* When we erase the cursor, and ROW is overlapped by other
25429 rows, make sure that these overlapping parts of other rows
25431 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25433 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25435 if (row
> w
->current_matrix
->rows
25436 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25437 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25438 OVERLAPS_ERASED_CURSOR
);
25440 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25441 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25442 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25443 OVERLAPS_ERASED_CURSOR
);
25450 Erase the image of a cursor of window W from the screen. */
25453 erase_phys_cursor (struct window
*w
)
25455 struct frame
*f
= XFRAME (w
->frame
);
25456 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25457 int hpos
= w
->phys_cursor
.hpos
;
25458 int vpos
= w
->phys_cursor
.vpos
;
25459 int mouse_face_here_p
= 0;
25460 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25461 struct glyph_row
*cursor_row
;
25462 struct glyph
*cursor_glyph
;
25463 enum draw_glyphs_face hl
;
25465 /* No cursor displayed or row invalidated => nothing to do on the
25467 if (w
->phys_cursor_type
== NO_CURSOR
)
25468 goto mark_cursor_off
;
25470 /* VPOS >= active_glyphs->nrows means that window has been resized.
25471 Don't bother to erase the cursor. */
25472 if (vpos
>= active_glyphs
->nrows
)
25473 goto mark_cursor_off
;
25475 /* If row containing cursor is marked invalid, there is nothing we
25477 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25478 if (!cursor_row
->enabled_p
)
25479 goto mark_cursor_off
;
25481 /* If line spacing is > 0, old cursor may only be partially visible in
25482 window after split-window. So adjust visible height. */
25483 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25484 window_text_bottom_y (w
) - cursor_row
->y
);
25486 /* If row is completely invisible, don't attempt to delete a cursor which
25487 isn't there. This can happen if cursor is at top of a window, and
25488 we switch to a buffer with a header line in that window. */
25489 if (cursor_row
->visible_height
<= 0)
25490 goto mark_cursor_off
;
25492 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25493 if (cursor_row
->cursor_in_fringe_p
)
25495 cursor_row
->cursor_in_fringe_p
= 0;
25496 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25497 goto mark_cursor_off
;
25500 /* This can happen when the new row is shorter than the old one.
25501 In this case, either draw_glyphs or clear_end_of_line
25502 should have cleared the cursor. Note that we wouldn't be
25503 able to erase the cursor in this case because we don't have a
25504 cursor glyph at hand. */
25505 if ((cursor_row
->reversed_p
25506 ? (w
->phys_cursor
.hpos
< 0)
25507 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25508 goto mark_cursor_off
;
25510 /* When the window is hscrolled, cursor hpos can legitimately be out
25511 of bounds, but we draw the cursor at the corresponding window
25512 margin in that case. */
25513 if (!cursor_row
->reversed_p
&& hpos
< 0)
25515 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25516 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25518 /* If the cursor is in the mouse face area, redisplay that when
25519 we clear the cursor. */
25520 if (! NILP (hlinfo
->mouse_face_window
)
25521 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25522 /* Don't redraw the cursor's spot in mouse face if it is at the
25523 end of a line (on a newline). The cursor appears there, but
25524 mouse highlighting does not. */
25525 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25526 mouse_face_here_p
= 1;
25528 /* Maybe clear the display under the cursor. */
25529 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25532 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25535 cursor_glyph
= get_phys_cursor_glyph (w
);
25536 if (cursor_glyph
== NULL
)
25537 goto mark_cursor_off
;
25539 width
= cursor_glyph
->pixel_width
;
25540 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25541 x
= w
->phys_cursor
.x
;
25543 width
-= left_x
- x
;
25544 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25545 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25546 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25549 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25552 /* Erase the cursor by redrawing the character underneath it. */
25553 if (mouse_face_here_p
)
25554 hl
= DRAW_MOUSE_FACE
;
25556 hl
= DRAW_NORMAL_TEXT
;
25557 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25560 w
->phys_cursor_on_p
= 0;
25561 w
->phys_cursor_type
= NO_CURSOR
;
25566 Display or clear cursor of window W. If ON is zero, clear the
25567 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25568 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25571 display_and_set_cursor (struct window
*w
, int on
,
25572 int hpos
, int vpos
, int x
, int y
)
25574 struct frame
*f
= XFRAME (w
->frame
);
25575 int new_cursor_type
;
25576 int new_cursor_width
;
25578 struct glyph_row
*glyph_row
;
25579 struct glyph
*glyph
;
25581 /* This is pointless on invisible frames, and dangerous on garbaged
25582 windows and frames; in the latter case, the frame or window may
25583 be in the midst of changing its size, and x and y may be off the
25585 if (! FRAME_VISIBLE_P (f
)
25586 || FRAME_GARBAGED_P (f
)
25587 || vpos
>= w
->current_matrix
->nrows
25588 || hpos
>= w
->current_matrix
->matrix_w
)
25591 /* If cursor is off and we want it off, return quickly. */
25592 if (!on
&& !w
->phys_cursor_on_p
)
25595 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25596 /* If cursor row is not enabled, we don't really know where to
25597 display the cursor. */
25598 if (!glyph_row
->enabled_p
)
25600 w
->phys_cursor_on_p
= 0;
25605 if (!glyph_row
->exact_window_width_line_p
25606 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25607 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25609 xassert (interrupt_input_blocked
);
25611 /* Set new_cursor_type to the cursor we want to be displayed. */
25612 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25613 &new_cursor_width
, &active_cursor
);
25615 /* If cursor is currently being shown and we don't want it to be or
25616 it is in the wrong place, or the cursor type is not what we want,
25618 if (w
->phys_cursor_on_p
25620 || w
->phys_cursor
.x
!= x
25621 || w
->phys_cursor
.y
!= y
25622 || new_cursor_type
!= w
->phys_cursor_type
25623 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25624 && new_cursor_width
!= w
->phys_cursor_width
)))
25625 erase_phys_cursor (w
);
25627 /* Don't check phys_cursor_on_p here because that flag is only set
25628 to zero in some cases where we know that the cursor has been
25629 completely erased, to avoid the extra work of erasing the cursor
25630 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25631 still not be visible, or it has only been partly erased. */
25634 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25635 w
->phys_cursor_height
= glyph_row
->height
;
25637 /* Set phys_cursor_.* before x_draw_.* is called because some
25638 of them may need the information. */
25639 w
->phys_cursor
.x
= x
;
25640 w
->phys_cursor
.y
= glyph_row
->y
;
25641 w
->phys_cursor
.hpos
= hpos
;
25642 w
->phys_cursor
.vpos
= vpos
;
25645 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25646 new_cursor_type
, new_cursor_width
,
25647 on
, active_cursor
);
25651 /* Switch the display of W's cursor on or off, according to the value
25655 update_window_cursor (struct window
*w
, int on
)
25657 /* Don't update cursor in windows whose frame is in the process
25658 of being deleted. */
25659 if (w
->current_matrix
)
25661 int hpos
= w
->phys_cursor
.hpos
;
25662 int vpos
= w
->phys_cursor
.vpos
;
25663 struct glyph_row
*row
;
25665 if (vpos
>= w
->current_matrix
->nrows
25666 || hpos
>= w
->current_matrix
->matrix_w
)
25669 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25671 /* When the window is hscrolled, cursor hpos can legitimately be
25672 out of bounds, but we draw the cursor at the corresponding
25673 window margin in that case. */
25674 if (!row
->reversed_p
&& hpos
< 0)
25676 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25677 hpos
= row
->used
[TEXT_AREA
] - 1;
25680 display_and_set_cursor (w
, on
, hpos
, vpos
,
25681 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25687 /* Call update_window_cursor with parameter ON_P on all leaf windows
25688 in the window tree rooted at W. */
25691 update_cursor_in_window_tree (struct window
*w
, int on_p
)
25695 if (!NILP (w
->hchild
))
25696 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
25697 else if (!NILP (w
->vchild
))
25698 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
25700 update_window_cursor (w
, on_p
);
25702 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
25708 Display the cursor on window W, or clear it, according to ON_P.
25709 Don't change the cursor's position. */
25712 x_update_cursor (struct frame
*f
, int on_p
)
25714 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
25719 Clear the cursor of window W to background color, and mark the
25720 cursor as not shown. This is used when the text where the cursor
25721 is about to be rewritten. */
25724 x_clear_cursor (struct window
*w
)
25726 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
25727 update_window_cursor (w
, 0);
25730 #endif /* HAVE_WINDOW_SYSTEM */
25732 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
25735 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
25736 int start_hpos
, int end_hpos
,
25737 enum draw_glyphs_face draw
)
25739 #ifdef HAVE_WINDOW_SYSTEM
25740 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
25742 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
25746 #if defined (HAVE_GPM) || defined (MSDOS)
25747 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
25751 /* Display the active region described by mouse_face_* according to DRAW. */
25754 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
25756 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
25757 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25759 if (/* If window is in the process of being destroyed, don't bother
25761 w
->current_matrix
!= NULL
25762 /* Don't update mouse highlight if hidden */
25763 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
25764 /* Recognize when we are called to operate on rows that don't exist
25765 anymore. This can happen when a window is split. */
25766 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
25768 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
25769 struct glyph_row
*row
, *first
, *last
;
25771 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
25772 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
25774 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
25776 int start_hpos
, end_hpos
, start_x
;
25778 /* For all but the first row, the highlight starts at column 0. */
25781 /* R2L rows have BEG and END in reversed order, but the
25782 screen drawing geometry is always left to right. So
25783 we need to mirror the beginning and end of the
25784 highlighted area in R2L rows. */
25785 if (!row
->reversed_p
)
25787 start_hpos
= hlinfo
->mouse_face_beg_col
;
25788 start_x
= hlinfo
->mouse_face_beg_x
;
25790 else if (row
== last
)
25792 start_hpos
= hlinfo
->mouse_face_end_col
;
25793 start_x
= hlinfo
->mouse_face_end_x
;
25801 else if (row
->reversed_p
&& row
== last
)
25803 start_hpos
= hlinfo
->mouse_face_end_col
;
25804 start_x
= hlinfo
->mouse_face_end_x
;
25814 if (!row
->reversed_p
)
25815 end_hpos
= hlinfo
->mouse_face_end_col
;
25816 else if (row
== first
)
25817 end_hpos
= hlinfo
->mouse_face_beg_col
;
25820 end_hpos
= row
->used
[TEXT_AREA
];
25821 if (draw
== DRAW_NORMAL_TEXT
)
25822 row
->fill_line_p
= 1; /* Clear to end of line */
25825 else if (row
->reversed_p
&& row
== first
)
25826 end_hpos
= hlinfo
->mouse_face_beg_col
;
25829 end_hpos
= row
->used
[TEXT_AREA
];
25830 if (draw
== DRAW_NORMAL_TEXT
)
25831 row
->fill_line_p
= 1; /* Clear to end of line */
25834 if (end_hpos
> start_hpos
)
25836 draw_row_with_mouse_face (w
, start_x
, row
,
25837 start_hpos
, end_hpos
, draw
);
25840 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
25844 #ifdef HAVE_WINDOW_SYSTEM
25845 /* When we've written over the cursor, arrange for it to
25846 be displayed again. */
25847 if (FRAME_WINDOW_P (f
)
25848 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
25850 int hpos
= w
->phys_cursor
.hpos
;
25852 /* When the window is hscrolled, cursor hpos can legitimately be
25853 out of bounds, but we draw the cursor at the corresponding
25854 window margin in that case. */
25855 if (!row
->reversed_p
&& hpos
< 0)
25857 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25858 hpos
= row
->used
[TEXT_AREA
] - 1;
25861 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
25862 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
25865 #endif /* HAVE_WINDOW_SYSTEM */
25868 #ifdef HAVE_WINDOW_SYSTEM
25869 /* Change the mouse cursor. */
25870 if (FRAME_WINDOW_P (f
))
25872 if (draw
== DRAW_NORMAL_TEXT
25873 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
25874 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
25875 else if (draw
== DRAW_MOUSE_FACE
)
25876 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
25878 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
25880 #endif /* HAVE_WINDOW_SYSTEM */
25884 Clear out the mouse-highlighted active region.
25885 Redraw it un-highlighted first. Value is non-zero if mouse
25886 face was actually drawn unhighlighted. */
25889 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
25893 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
25895 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
25899 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25900 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25901 hlinfo
->mouse_face_window
= Qnil
;
25902 hlinfo
->mouse_face_overlay
= Qnil
;
25906 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
25907 within the mouse face on that window. */
25909 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
25911 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25913 /* Quickly resolve the easy cases. */
25914 if (!(WINDOWP (hlinfo
->mouse_face_window
)
25915 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
25917 if (vpos
< hlinfo
->mouse_face_beg_row
25918 || vpos
> hlinfo
->mouse_face_end_row
)
25920 if (vpos
> hlinfo
->mouse_face_beg_row
25921 && vpos
< hlinfo
->mouse_face_end_row
)
25924 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
25926 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25928 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
25931 else if ((vpos
== hlinfo
->mouse_face_beg_row
25932 && hpos
>= hlinfo
->mouse_face_beg_col
)
25933 || (vpos
== hlinfo
->mouse_face_end_row
25934 && hpos
< hlinfo
->mouse_face_end_col
))
25939 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
25941 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
25944 else if ((vpos
== hlinfo
->mouse_face_beg_row
25945 && hpos
<= hlinfo
->mouse_face_beg_col
)
25946 || (vpos
== hlinfo
->mouse_face_end_row
25947 && hpos
> hlinfo
->mouse_face_end_col
))
25955 Non-zero if physical cursor of window W is within mouse face. */
25958 cursor_in_mouse_face_p (struct window
*w
)
25960 int hpos
= w
->phys_cursor
.hpos
;
25961 int vpos
= w
->phys_cursor
.vpos
;
25962 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25964 /* When the window is hscrolled, cursor hpos can legitimately be out
25965 of bounds, but we draw the cursor at the corresponding window
25966 margin in that case. */
25967 if (!row
->reversed_p
&& hpos
< 0)
25969 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25970 hpos
= row
->used
[TEXT_AREA
] - 1;
25972 return coords_in_mouse_face_p (w
, hpos
, vpos
);
25977 /* Find the glyph rows START_ROW and END_ROW of window W that display
25978 characters between buffer positions START_CHARPOS and END_CHARPOS
25979 (excluding END_CHARPOS). DISP_STRING is a display string that
25980 covers these buffer positions. This is similar to
25981 row_containing_pos, but is more accurate when bidi reordering makes
25982 buffer positions change non-linearly with glyph rows. */
25984 rows_from_pos_range (struct window
*w
,
25985 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
25986 Lisp_Object disp_string
,
25987 struct glyph_row
**start
, struct glyph_row
**end
)
25989 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25990 int last_y
= window_text_bottom_y (w
);
25991 struct glyph_row
*row
;
25996 while (!first
->enabled_p
25997 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26000 /* Find the START row. */
26002 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26005 /* A row can potentially be the START row if the range of the
26006 characters it displays intersects the range
26007 [START_CHARPOS..END_CHARPOS). */
26008 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26009 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26010 /* See the commentary in row_containing_pos, for the
26011 explanation of the complicated way to check whether
26012 some position is beyond the end of the characters
26013 displayed by a row. */
26014 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26015 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26016 && !row
->ends_at_zv_p
26017 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26018 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26019 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26020 && !row
->ends_at_zv_p
26021 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26023 /* Found a candidate row. Now make sure at least one of the
26024 glyphs it displays has a charpos from the range
26025 [START_CHARPOS..END_CHARPOS).
26027 This is not obvious because bidi reordering could make
26028 buffer positions of a row be 1,2,3,102,101,100, and if we
26029 want to highlight characters in [50..60), we don't want
26030 this row, even though [50..60) does intersect [1..103),
26031 the range of character positions given by the row's start
26032 and end positions. */
26033 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26034 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26038 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26039 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26040 /* A glyph that comes from DISP_STRING is by
26041 definition to be highlighted. */
26042 || EQ (g
->object
, disp_string
))
26051 /* Find the END row. */
26053 /* If the last row is partially visible, start looking for END
26054 from that row, instead of starting from FIRST. */
26055 && !(row
->enabled_p
26056 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26058 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26060 struct glyph_row
*next
= row
+ 1;
26061 EMACS_INT next_start
= MATRIX_ROW_START_CHARPOS (next
);
26063 if (!next
->enabled_p
26064 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26065 /* The first row >= START whose range of displayed characters
26066 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26067 is the row END + 1. */
26068 || (start_charpos
< next_start
26069 && end_charpos
< next_start
)
26070 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26071 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26072 && !next
->ends_at_zv_p
26073 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26074 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26075 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26076 && !next
->ends_at_zv_p
26077 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26084 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26085 but none of the characters it displays are in the range, it is
26087 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26088 struct glyph
*s
= g
;
26089 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26093 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26094 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26095 /* If the buffer position of the first glyph in
26096 the row is equal to END_CHARPOS, it means
26097 the last character to be highlighted is the
26098 newline of ROW, and we must consider NEXT as
26100 || (((!next
->reversed_p
&& g
== s
)
26101 || (next
->reversed_p
&& g
== e
- 1))
26102 && (g
->charpos
== end_charpos
26103 /* Special case for when NEXT is an
26104 empty line at ZV. */
26105 || (g
->charpos
== -1
26106 && !row
->ends_at_zv_p
26107 && next_start
== end_charpos
)))))
26108 /* A glyph that comes from DISP_STRING is by
26109 definition to be highlighted. */
26110 || EQ (g
->object
, disp_string
))
26119 /* The first row that ends at ZV must be the last to be
26121 else if (next
->ends_at_zv_p
)
26130 /* This function sets the mouse_face_* elements of HLINFO, assuming
26131 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26132 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26133 for the overlay or run of text properties specifying the mouse
26134 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26135 before-string and after-string that must also be highlighted.
26136 DISP_STRING, if non-nil, is a display string that may cover some
26137 or all of the highlighted text. */
26140 mouse_face_from_buffer_pos (Lisp_Object window
,
26141 Mouse_HLInfo
*hlinfo
,
26142 EMACS_INT mouse_charpos
,
26143 EMACS_INT start_charpos
,
26144 EMACS_INT end_charpos
,
26145 Lisp_Object before_string
,
26146 Lisp_Object after_string
,
26147 Lisp_Object disp_string
)
26149 struct window
*w
= XWINDOW (window
);
26150 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26151 struct glyph_row
*r1
, *r2
;
26152 struct glyph
*glyph
, *end
;
26153 EMACS_INT ignore
, pos
;
26156 xassert (NILP (disp_string
) || STRINGP (disp_string
));
26157 xassert (NILP (before_string
) || STRINGP (before_string
));
26158 xassert (NILP (after_string
) || STRINGP (after_string
));
26160 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26161 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26163 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26164 /* If the before-string or display-string contains newlines,
26165 rows_from_pos_range skips to its last row. Move back. */
26166 if (!NILP (before_string
) || !NILP (disp_string
))
26168 struct glyph_row
*prev
;
26169 while ((prev
= r1
- 1, prev
>= first
)
26170 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26171 && prev
->used
[TEXT_AREA
] > 0)
26173 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26174 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26175 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26177 || !(EQ (glyph
->object
, before_string
)
26178 || EQ (glyph
->object
, disp_string
)))
26185 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26186 hlinfo
->mouse_face_past_end
= 1;
26188 else if (!NILP (after_string
))
26190 /* If the after-string has newlines, advance to its last row. */
26191 struct glyph_row
*next
;
26192 struct glyph_row
*last
26193 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26195 for (next
= r2
+ 1;
26197 && next
->used
[TEXT_AREA
] > 0
26198 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26202 /* The rest of the display engine assumes that mouse_face_beg_row is
26203 either above mouse_face_end_row or identical to it. But with
26204 bidi-reordered continued lines, the row for START_CHARPOS could
26205 be below the row for END_CHARPOS. If so, swap the rows and store
26206 them in correct order. */
26209 struct glyph_row
*tem
= r2
;
26215 hlinfo
->mouse_face_beg_y
= r1
->y
;
26216 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26217 hlinfo
->mouse_face_end_y
= r2
->y
;
26218 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26220 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26221 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26222 could be anywhere in the row and in any order. The strategy
26223 below is to find the leftmost and the rightmost glyph that
26224 belongs to either of these 3 strings, or whose position is
26225 between START_CHARPOS and END_CHARPOS, and highlight all the
26226 glyphs between those two. This may cover more than just the text
26227 between START_CHARPOS and END_CHARPOS if the range of characters
26228 strides the bidi level boundary, e.g. if the beginning is in R2L
26229 text while the end is in L2R text or vice versa. */
26230 if (!r1
->reversed_p
)
26232 /* This row is in a left to right paragraph. Scan it left to
26234 glyph
= r1
->glyphs
[TEXT_AREA
];
26235 end
= glyph
+ r1
->used
[TEXT_AREA
];
26238 /* Skip truncation glyphs at the start of the glyph row. */
26239 if (r1
->displays_text_p
)
26241 && INTEGERP (glyph
->object
)
26242 && glyph
->charpos
< 0;
26244 x
+= glyph
->pixel_width
;
26246 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26247 or DISP_STRING, and the first glyph from buffer whose
26248 position is between START_CHARPOS and END_CHARPOS. */
26250 && !INTEGERP (glyph
->object
)
26251 && !EQ (glyph
->object
, disp_string
)
26252 && !(BUFFERP (glyph
->object
)
26253 && (glyph
->charpos
>= start_charpos
26254 && glyph
->charpos
< end_charpos
));
26257 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26258 are present at buffer positions between START_CHARPOS and
26259 END_CHARPOS, or if they come from an overlay. */
26260 if (EQ (glyph
->object
, before_string
))
26262 pos
= string_buffer_position (before_string
,
26264 /* If pos == 0, it means before_string came from an
26265 overlay, not from a buffer position. */
26266 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26269 else if (EQ (glyph
->object
, after_string
))
26271 pos
= string_buffer_position (after_string
, end_charpos
);
26272 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26275 x
+= glyph
->pixel_width
;
26277 hlinfo
->mouse_face_beg_x
= x
;
26278 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26282 /* This row is in a right to left paragraph. Scan it right to
26286 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26287 glyph
= end
+ r1
->used
[TEXT_AREA
];
26289 /* Skip truncation glyphs at the start of the glyph row. */
26290 if (r1
->displays_text_p
)
26292 && INTEGERP (glyph
->object
)
26293 && glyph
->charpos
< 0;
26297 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26298 or DISP_STRING, and the first glyph from buffer whose
26299 position is between START_CHARPOS and END_CHARPOS. */
26301 && !INTEGERP (glyph
->object
)
26302 && !EQ (glyph
->object
, disp_string
)
26303 && !(BUFFERP (glyph
->object
)
26304 && (glyph
->charpos
>= start_charpos
26305 && glyph
->charpos
< end_charpos
));
26308 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26309 are present at buffer positions between START_CHARPOS and
26310 END_CHARPOS, or if they come from an overlay. */
26311 if (EQ (glyph
->object
, before_string
))
26313 pos
= string_buffer_position (before_string
, start_charpos
);
26314 /* If pos == 0, it means before_string came from an
26315 overlay, not from a buffer position. */
26316 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26319 else if (EQ (glyph
->object
, after_string
))
26321 pos
= string_buffer_position (after_string
, end_charpos
);
26322 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26327 glyph
++; /* first glyph to the right of the highlighted area */
26328 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26329 x
+= g
->pixel_width
;
26330 hlinfo
->mouse_face_beg_x
= x
;
26331 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26334 /* If the highlight ends in a different row, compute GLYPH and END
26335 for the end row. Otherwise, reuse the values computed above for
26336 the row where the highlight begins. */
26339 if (!r2
->reversed_p
)
26341 glyph
= r2
->glyphs
[TEXT_AREA
];
26342 end
= glyph
+ r2
->used
[TEXT_AREA
];
26347 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26348 glyph
= end
+ r2
->used
[TEXT_AREA
];
26352 if (!r2
->reversed_p
)
26354 /* Skip truncation and continuation glyphs near the end of the
26355 row, and also blanks and stretch glyphs inserted by
26356 extend_face_to_end_of_line. */
26358 && INTEGERP ((end
- 1)->object
))
26360 /* Scan the rest of the glyph row from the end, looking for the
26361 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26362 DISP_STRING, or whose position is between START_CHARPOS
26366 && !INTEGERP (end
->object
)
26367 && !EQ (end
->object
, disp_string
)
26368 && !(BUFFERP (end
->object
)
26369 && (end
->charpos
>= start_charpos
26370 && end
->charpos
< end_charpos
));
26373 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26374 are present at buffer positions between START_CHARPOS and
26375 END_CHARPOS, or if they come from an overlay. */
26376 if (EQ (end
->object
, before_string
))
26378 pos
= string_buffer_position (before_string
, start_charpos
);
26379 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26382 else if (EQ (end
->object
, after_string
))
26384 pos
= string_buffer_position (after_string
, end_charpos
);
26385 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26389 /* Find the X coordinate of the last glyph to be highlighted. */
26390 for (; glyph
<= end
; ++glyph
)
26391 x
+= glyph
->pixel_width
;
26393 hlinfo
->mouse_face_end_x
= x
;
26394 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26398 /* Skip truncation and continuation glyphs near the end of the
26399 row, and also blanks and stretch glyphs inserted by
26400 extend_face_to_end_of_line. */
26404 && INTEGERP (end
->object
))
26406 x
+= end
->pixel_width
;
26409 /* Scan the rest of the glyph row from the end, looking for the
26410 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26411 DISP_STRING, or whose position is between START_CHARPOS
26415 && !INTEGERP (end
->object
)
26416 && !EQ (end
->object
, disp_string
)
26417 && !(BUFFERP (end
->object
)
26418 && (end
->charpos
>= start_charpos
26419 && end
->charpos
< end_charpos
));
26422 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26423 are present at buffer positions between START_CHARPOS and
26424 END_CHARPOS, or if they come from an overlay. */
26425 if (EQ (end
->object
, before_string
))
26427 pos
= string_buffer_position (before_string
, start_charpos
);
26428 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26431 else if (EQ (end
->object
, after_string
))
26433 pos
= string_buffer_position (after_string
, end_charpos
);
26434 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26437 x
+= end
->pixel_width
;
26439 /* If we exited the above loop because we arrived at the last
26440 glyph of the row, and its buffer position is still not in
26441 range, it means the last character in range is the preceding
26442 newline. Bump the end column and x values to get past the
26445 && BUFFERP (end
->object
)
26446 && (end
->charpos
< start_charpos
26447 || end
->charpos
>= end_charpos
))
26449 x
+= end
->pixel_width
;
26452 hlinfo
->mouse_face_end_x
= x
;
26453 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26456 hlinfo
->mouse_face_window
= window
;
26457 hlinfo
->mouse_face_face_id
26458 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26460 !hlinfo
->mouse_face_hidden
, -1);
26461 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26464 /* The following function is not used anymore (replaced with
26465 mouse_face_from_string_pos), but I leave it here for the time
26466 being, in case someone would. */
26468 #if 0 /* not used */
26470 /* Find the position of the glyph for position POS in OBJECT in
26471 window W's current matrix, and return in *X, *Y the pixel
26472 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26474 RIGHT_P non-zero means return the position of the right edge of the
26475 glyph, RIGHT_P zero means return the left edge position.
26477 If no glyph for POS exists in the matrix, return the position of
26478 the glyph with the next smaller position that is in the matrix, if
26479 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26480 exists in the matrix, return the position of the glyph with the
26481 next larger position in OBJECT.
26483 Value is non-zero if a glyph was found. */
26486 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
26487 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26489 int yb
= window_text_bottom_y (w
);
26490 struct glyph_row
*r
;
26491 struct glyph
*best_glyph
= NULL
;
26492 struct glyph_row
*best_row
= NULL
;
26495 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26496 r
->enabled_p
&& r
->y
< yb
;
26499 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26500 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26503 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26504 if (EQ (g
->object
, object
))
26506 if (g
->charpos
== pos
)
26513 else if (best_glyph
== NULL
26514 || ((eabs (g
->charpos
- pos
)
26515 < eabs (best_glyph
->charpos
- pos
))
26518 : g
->charpos
> pos
)))
26532 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26536 *x
+= best_glyph
->pixel_width
;
26541 *vpos
= best_row
- w
->current_matrix
->rows
;
26544 return best_glyph
!= NULL
;
26546 #endif /* not used */
26548 /* Find the positions of the first and the last glyphs in window W's
26549 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26550 (assumed to be a string), and return in HLINFO's mouse_face_*
26551 members the pixel and column/row coordinates of those glyphs. */
26554 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26555 Lisp_Object object
,
26556 EMACS_INT startpos
, EMACS_INT endpos
)
26558 int yb
= window_text_bottom_y (w
);
26559 struct glyph_row
*r
;
26560 struct glyph
*g
, *e
;
26564 /* Find the glyph row with at least one position in the range
26565 [STARTPOS..ENDPOS], and the first glyph in that row whose
26566 position belongs to that range. */
26567 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26568 r
->enabled_p
&& r
->y
< yb
;
26571 if (!r
->reversed_p
)
26573 g
= r
->glyphs
[TEXT_AREA
];
26574 e
= g
+ r
->used
[TEXT_AREA
];
26575 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26576 if (EQ (g
->object
, object
)
26577 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26579 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26580 hlinfo
->mouse_face_beg_y
= r
->y
;
26581 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26582 hlinfo
->mouse_face_beg_x
= gx
;
26591 e
= r
->glyphs
[TEXT_AREA
];
26592 g
= e
+ r
->used
[TEXT_AREA
];
26593 for ( ; g
> e
; --g
)
26594 if (EQ ((g
-1)->object
, object
)
26595 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26597 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26598 hlinfo
->mouse_face_beg_y
= r
->y
;
26599 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26600 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26601 gx
+= g1
->pixel_width
;
26602 hlinfo
->mouse_face_beg_x
= gx
;
26614 /* Starting with the next row, look for the first row which does NOT
26615 include any glyphs whose positions are in the range. */
26616 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26618 g
= r
->glyphs
[TEXT_AREA
];
26619 e
= g
+ r
->used
[TEXT_AREA
];
26621 for ( ; g
< e
; ++g
)
26622 if (EQ (g
->object
, object
)
26623 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26632 /* The highlighted region ends on the previous row. */
26635 /* Set the end row and its vertical pixel coordinate. */
26636 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26637 hlinfo
->mouse_face_end_y
= r
->y
;
26639 /* Compute and set the end column and the end column's horizontal
26640 pixel coordinate. */
26641 if (!r
->reversed_p
)
26643 g
= r
->glyphs
[TEXT_AREA
];
26644 e
= g
+ r
->used
[TEXT_AREA
];
26645 for ( ; e
> g
; --e
)
26646 if (EQ ((e
-1)->object
, object
)
26647 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26649 hlinfo
->mouse_face_end_col
= e
- g
;
26651 for (gx
= r
->x
; g
< e
; ++g
)
26652 gx
+= g
->pixel_width
;
26653 hlinfo
->mouse_face_end_x
= gx
;
26657 e
= r
->glyphs
[TEXT_AREA
];
26658 g
= e
+ r
->used
[TEXT_AREA
];
26659 for (gx
= r
->x
; e
< g
; ++e
)
26661 if (EQ (e
->object
, object
)
26662 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
26664 gx
+= e
->pixel_width
;
26666 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
26667 hlinfo
->mouse_face_end_x
= gx
;
26671 #ifdef HAVE_WINDOW_SYSTEM
26673 /* See if position X, Y is within a hot-spot of an image. */
26676 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
26678 if (!CONSP (hot_spot
))
26681 if (EQ (XCAR (hot_spot
), Qrect
))
26683 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
26684 Lisp_Object rect
= XCDR (hot_spot
);
26688 if (!CONSP (XCAR (rect
)))
26690 if (!CONSP (XCDR (rect
)))
26692 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
26694 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
26696 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
26698 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
26702 else if (EQ (XCAR (hot_spot
), Qcircle
))
26704 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
26705 Lisp_Object circ
= XCDR (hot_spot
);
26706 Lisp_Object lr
, lx0
, ly0
;
26708 && CONSP (XCAR (circ
))
26709 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
26710 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
26711 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
26713 double r
= XFLOATINT (lr
);
26714 double dx
= XINT (lx0
) - x
;
26715 double dy
= XINT (ly0
) - y
;
26716 return (dx
* dx
+ dy
* dy
<= r
* r
);
26719 else if (EQ (XCAR (hot_spot
), Qpoly
))
26721 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
26722 if (VECTORP (XCDR (hot_spot
)))
26724 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
26725 Lisp_Object
*poly
= v
->contents
;
26726 int n
= v
->header
.size
;
26729 Lisp_Object lx
, ly
;
26732 /* Need an even number of coordinates, and at least 3 edges. */
26733 if (n
< 6 || n
& 1)
26736 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
26737 If count is odd, we are inside polygon. Pixels on edges
26738 may or may not be included depending on actual geometry of the
26740 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
26741 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
26743 x0
= XINT (lx
), y0
= XINT (ly
);
26744 for (i
= 0; i
< n
; i
+= 2)
26746 int x1
= x0
, y1
= y0
;
26747 if ((lx
= poly
[i
], !INTEGERP (lx
))
26748 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
26750 x0
= XINT (lx
), y0
= XINT (ly
);
26752 /* Does this segment cross the X line? */
26760 if (y
> y0
&& y
> y1
)
26762 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
26772 find_hot_spot (Lisp_Object map
, int x
, int y
)
26774 while (CONSP (map
))
26776 if (CONSP (XCAR (map
))
26777 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
26785 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
26787 doc
: /* Lookup in image map MAP coordinates X and Y.
26788 An image map is an alist where each element has the format (AREA ID PLIST).
26789 An AREA is specified as either a rectangle, a circle, or a polygon:
26790 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
26791 pixel coordinates of the upper left and bottom right corners.
26792 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
26793 and the radius of the circle; r may be a float or integer.
26794 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
26795 vector describes one corner in the polygon.
26796 Returns the alist element for the first matching AREA in MAP. */)
26797 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
26805 return find_hot_spot (map
, XINT (x
), XINT (y
));
26809 /* Display frame CURSOR, optionally using shape defined by POINTER. */
26811 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
26813 /* Do not change cursor shape while dragging mouse. */
26814 if (!NILP (do_mouse_tracking
))
26817 if (!NILP (pointer
))
26819 if (EQ (pointer
, Qarrow
))
26820 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26821 else if (EQ (pointer
, Qhand
))
26822 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
26823 else if (EQ (pointer
, Qtext
))
26824 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26825 else if (EQ (pointer
, intern ("hdrag")))
26826 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26827 #ifdef HAVE_X_WINDOWS
26828 else if (EQ (pointer
, intern ("vdrag")))
26829 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
26831 else if (EQ (pointer
, intern ("hourglass")))
26832 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
26833 else if (EQ (pointer
, Qmodeline
))
26834 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
26836 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26839 if (cursor
!= No_Cursor
)
26840 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
26843 #endif /* HAVE_WINDOW_SYSTEM */
26845 /* Take proper action when mouse has moved to the mode or header line
26846 or marginal area AREA of window W, x-position X and y-position Y.
26847 X is relative to the start of the text display area of W, so the
26848 width of bitmap areas and scroll bars must be subtracted to get a
26849 position relative to the start of the mode line. */
26852 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
26853 enum window_part area
)
26855 struct window
*w
= XWINDOW (window
);
26856 struct frame
*f
= XFRAME (w
->frame
);
26857 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26858 #ifdef HAVE_WINDOW_SYSTEM
26859 Display_Info
*dpyinfo
;
26861 Cursor cursor
= No_Cursor
;
26862 Lisp_Object pointer
= Qnil
;
26863 int dx
, dy
, width
, height
;
26865 Lisp_Object string
, object
= Qnil
;
26866 Lisp_Object pos
, help
;
26868 Lisp_Object mouse_face
;
26869 int original_x_pixel
= x
;
26870 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
26871 struct glyph_row
*row
;
26873 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
26878 /* Kludge alert: mode_line_string takes X/Y in pixels, but
26879 returns them in row/column units! */
26880 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
26881 &object
, &dx
, &dy
, &width
, &height
);
26883 row
= (area
== ON_MODE_LINE
26884 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
26885 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
26887 /* Find the glyph under the mouse pointer. */
26888 if (row
->mode_line_p
&& row
->enabled_p
)
26890 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
26891 end
= glyph
+ row
->used
[TEXT_AREA
];
26893 for (x0
= original_x_pixel
;
26894 glyph
< end
&& x0
>= glyph
->pixel_width
;
26896 x0
-= glyph
->pixel_width
;
26904 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
26905 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
26906 returns them in row/column units! */
26907 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
26908 &object
, &dx
, &dy
, &width
, &height
);
26913 #ifdef HAVE_WINDOW_SYSTEM
26914 if (IMAGEP (object
))
26916 Lisp_Object image_map
, hotspot
;
26917 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
26919 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
26921 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26925 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
26926 If so, we could look for mouse-enter, mouse-leave
26927 properties in PLIST (and do something...). */
26928 hotspot
= XCDR (hotspot
);
26929 if (CONSP (hotspot
)
26930 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26932 pointer
= Fplist_get (plist
, Qpointer
);
26933 if (NILP (pointer
))
26935 help
= Fplist_get (plist
, Qhelp_echo
);
26938 help_echo_string
= help
;
26939 /* Is this correct? ++kfs */
26940 XSETWINDOW (help_echo_window
, w
);
26941 help_echo_object
= w
->buffer
;
26942 help_echo_pos
= charpos
;
26946 if (NILP (pointer
))
26947 pointer
= Fplist_get (XCDR (object
), QCpointer
);
26949 #endif /* HAVE_WINDOW_SYSTEM */
26951 if (STRINGP (string
))
26953 pos
= make_number (charpos
);
26954 /* If we're on a string with `help-echo' text property, arrange
26955 for the help to be displayed. This is done by setting the
26956 global variable help_echo_string to the help string. */
26959 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
26962 help_echo_string
= help
;
26963 XSETWINDOW (help_echo_window
, w
);
26964 help_echo_object
= string
;
26965 help_echo_pos
= charpos
;
26969 #ifdef HAVE_WINDOW_SYSTEM
26970 if (FRAME_WINDOW_P (f
))
26972 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
26973 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26974 if (NILP (pointer
))
26975 pointer
= Fget_text_property (pos
, Qpointer
, string
);
26977 /* Change the mouse pointer according to what is under X/Y. */
26979 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
26982 map
= Fget_text_property (pos
, Qlocal_map
, string
);
26983 if (!KEYMAPP (map
))
26984 map
= Fget_text_property (pos
, Qkeymap
, string
);
26985 if (!KEYMAPP (map
))
26986 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
26991 /* Change the mouse face according to what is under X/Y. */
26992 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
26993 if (!NILP (mouse_face
)
26994 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
26999 struct glyph
* tmp_glyph
;
27003 int total_pixel_width
;
27004 EMACS_INT begpos
, endpos
, ignore
;
27008 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27009 Qmouse_face
, string
, Qnil
);
27015 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27017 endpos
= SCHARS (string
);
27021 /* Calculate the glyph position GPOS of GLYPH in the
27022 displayed string, relative to the beginning of the
27023 highlighted part of the string.
27025 Note: GPOS is different from CHARPOS. CHARPOS is the
27026 position of GLYPH in the internal string object. A mode
27027 line string format has structures which are converted to
27028 a flattened string by the Emacs Lisp interpreter. The
27029 internal string is an element of those structures. The
27030 displayed string is the flattened string. */
27031 tmp_glyph
= row_start_glyph
;
27032 while (tmp_glyph
< glyph
27033 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27034 && begpos
<= tmp_glyph
->charpos
27035 && tmp_glyph
->charpos
< endpos
)))
27037 gpos
= glyph
- tmp_glyph
;
27039 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27040 the highlighted part of the displayed string to which
27041 GLYPH belongs. Note: GSEQ_LENGTH is different from
27042 SCHARS (STRING), because the latter returns the length of
27043 the internal string. */
27044 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27046 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27047 && begpos
<= tmp_glyph
->charpos
27048 && tmp_glyph
->charpos
< endpos
));
27051 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27053 /* Calculate the total pixel width of all the glyphs between
27054 the beginning of the highlighted area and GLYPH. */
27055 total_pixel_width
= 0;
27056 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27057 total_pixel_width
+= tmp_glyph
->pixel_width
;
27059 /* Pre calculation of re-rendering position. Note: X is in
27060 column units here, after the call to mode_line_string or
27061 marginal_area_string. */
27063 vpos
= (area
== ON_MODE_LINE
27064 ? (w
->current_matrix
)->nrows
- 1
27067 /* If GLYPH's position is included in the region that is
27068 already drawn in mouse face, we have nothing to do. */
27069 if ( EQ (window
, hlinfo
->mouse_face_window
)
27070 && (!row
->reversed_p
27071 ? (hlinfo
->mouse_face_beg_col
<= hpos
27072 && hpos
< hlinfo
->mouse_face_end_col
)
27073 /* In R2L rows we swap BEG and END, see below. */
27074 : (hlinfo
->mouse_face_end_col
<= hpos
27075 && hpos
< hlinfo
->mouse_face_beg_col
))
27076 && hlinfo
->mouse_face_beg_row
== vpos
)
27079 if (clear_mouse_face (hlinfo
))
27080 cursor
= No_Cursor
;
27082 if (!row
->reversed_p
)
27084 hlinfo
->mouse_face_beg_col
= hpos
;
27085 hlinfo
->mouse_face_beg_x
= original_x_pixel
27086 - (total_pixel_width
+ dx
);
27087 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27088 hlinfo
->mouse_face_end_x
= 0;
27092 /* In R2L rows, show_mouse_face expects BEG and END
27093 coordinates to be swapped. */
27094 hlinfo
->mouse_face_end_col
= hpos
;
27095 hlinfo
->mouse_face_end_x
= original_x_pixel
27096 - (total_pixel_width
+ dx
);
27097 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27098 hlinfo
->mouse_face_beg_x
= 0;
27101 hlinfo
->mouse_face_beg_row
= vpos
;
27102 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27103 hlinfo
->mouse_face_beg_y
= 0;
27104 hlinfo
->mouse_face_end_y
= 0;
27105 hlinfo
->mouse_face_past_end
= 0;
27106 hlinfo
->mouse_face_window
= window
;
27108 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27114 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27116 if (NILP (pointer
))
27119 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27120 clear_mouse_face (hlinfo
);
27122 #ifdef HAVE_WINDOW_SYSTEM
27123 if (FRAME_WINDOW_P (f
))
27124 define_frame_cursor1 (f
, cursor
, pointer
);
27130 Take proper action when the mouse has moved to position X, Y on
27131 frame F as regards highlighting characters that have mouse-face
27132 properties. Also de-highlighting chars where the mouse was before.
27133 X and Y can be negative or out of range. */
27136 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27138 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27139 enum window_part part
= ON_NOTHING
;
27140 Lisp_Object window
;
27142 Cursor cursor
= No_Cursor
;
27143 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27146 /* When a menu is active, don't highlight because this looks odd. */
27147 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27148 if (popup_activated ())
27152 if (NILP (Vmouse_highlight
)
27153 || !f
->glyphs_initialized_p
27154 || f
->pointer_invisible
)
27157 hlinfo
->mouse_face_mouse_x
= x
;
27158 hlinfo
->mouse_face_mouse_y
= y
;
27159 hlinfo
->mouse_face_mouse_frame
= f
;
27161 if (hlinfo
->mouse_face_defer
)
27164 if (gc_in_progress
)
27166 hlinfo
->mouse_face_deferred_gc
= 1;
27170 /* Which window is that in? */
27171 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27173 /* If displaying active text in another window, clear that. */
27174 if (! EQ (window
, hlinfo
->mouse_face_window
)
27175 /* Also clear if we move out of text area in same window. */
27176 || (!NILP (hlinfo
->mouse_face_window
)
27179 && part
!= ON_MODE_LINE
27180 && part
!= ON_HEADER_LINE
))
27181 clear_mouse_face (hlinfo
);
27183 /* Not on a window -> return. */
27184 if (!WINDOWP (window
))
27187 /* Reset help_echo_string. It will get recomputed below. */
27188 help_echo_string
= Qnil
;
27190 /* Convert to window-relative pixel coordinates. */
27191 w
= XWINDOW (window
);
27192 frame_to_window_pixel_xy (w
, &x
, &y
);
27194 #ifdef HAVE_WINDOW_SYSTEM
27195 /* Handle tool-bar window differently since it doesn't display a
27197 if (EQ (window
, f
->tool_bar_window
))
27199 note_tool_bar_highlight (f
, x
, y
);
27204 /* Mouse is on the mode, header line or margin? */
27205 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27206 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27208 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27212 #ifdef HAVE_WINDOW_SYSTEM
27213 if (part
== ON_VERTICAL_BORDER
)
27215 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27216 help_echo_string
= build_string ("drag-mouse-1: resize");
27218 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27219 || part
== ON_SCROLL_BAR
)
27220 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27222 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27225 /* Are we in a window whose display is up to date?
27226 And verify the buffer's text has not changed. */
27227 b
= XBUFFER (w
->buffer
);
27228 if (part
== ON_TEXT
27229 && EQ (w
->window_end_valid
, w
->buffer
)
27230 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
27231 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
27233 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27235 struct glyph
*glyph
;
27236 Lisp_Object object
;
27237 Lisp_Object mouse_face
= Qnil
, position
;
27238 Lisp_Object
*overlay_vec
= NULL
;
27239 ptrdiff_t i
, noverlays
;
27240 struct buffer
*obuf
;
27241 EMACS_INT obegv
, ozv
;
27244 /* Find the glyph under X/Y. */
27245 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27247 #ifdef HAVE_WINDOW_SYSTEM
27248 /* Look for :pointer property on image. */
27249 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27251 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27252 if (img
!= NULL
&& IMAGEP (img
->spec
))
27254 Lisp_Object image_map
, hotspot
;
27255 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27257 && (hotspot
= find_hot_spot (image_map
,
27258 glyph
->slice
.img
.x
+ dx
,
27259 glyph
->slice
.img
.y
+ dy
),
27261 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27265 /* Could check XCAR (hotspot) to see if we enter/leave
27267 If so, we could look for mouse-enter, mouse-leave
27268 properties in PLIST (and do something...). */
27269 hotspot
= XCDR (hotspot
);
27270 if (CONSP (hotspot
)
27271 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27273 pointer
= Fplist_get (plist
, Qpointer
);
27274 if (NILP (pointer
))
27276 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27277 if (!NILP (help_echo_string
))
27279 help_echo_window
= window
;
27280 help_echo_object
= glyph
->object
;
27281 help_echo_pos
= glyph
->charpos
;
27285 if (NILP (pointer
))
27286 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27289 #endif /* HAVE_WINDOW_SYSTEM */
27291 /* Clear mouse face if X/Y not over text. */
27293 || area
!= TEXT_AREA
27294 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27295 /* Glyph's OBJECT is an integer for glyphs inserted by the
27296 display engine for its internal purposes, like truncation
27297 and continuation glyphs and blanks beyond the end of
27298 line's text on text terminals. If we are over such a
27299 glyph, we are not over any text. */
27300 || INTEGERP (glyph
->object
)
27301 /* R2L rows have a stretch glyph at their front, which
27302 stands for no text, whereas L2R rows have no glyphs at
27303 all beyond the end of text. Treat such stretch glyphs
27304 like we do with NULL glyphs in L2R rows. */
27305 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27306 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27307 && glyph
->type
== STRETCH_GLYPH
27308 && glyph
->avoid_cursor_p
))
27310 if (clear_mouse_face (hlinfo
))
27311 cursor
= No_Cursor
;
27312 #ifdef HAVE_WINDOW_SYSTEM
27313 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27315 if (area
!= TEXT_AREA
)
27316 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27318 pointer
= Vvoid_text_area_pointer
;
27324 pos
= glyph
->charpos
;
27325 object
= glyph
->object
;
27326 if (!STRINGP (object
) && !BUFFERP (object
))
27329 /* If we get an out-of-range value, return now; avoid an error. */
27330 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27333 /* Make the window's buffer temporarily current for
27334 overlays_at and compute_char_face. */
27335 obuf
= current_buffer
;
27336 current_buffer
= b
;
27342 /* Is this char mouse-active or does it have help-echo? */
27343 position
= make_number (pos
);
27345 if (BUFFERP (object
))
27347 /* Put all the overlays we want in a vector in overlay_vec. */
27348 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27349 /* Sort overlays into increasing priority order. */
27350 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27355 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27358 cursor
= No_Cursor
;
27360 /* Check mouse-face highlighting. */
27362 /* If there exists an overlay with mouse-face overlapping
27363 the one we are currently highlighting, we have to
27364 check if we enter the overlapping overlay, and then
27365 highlight only that. */
27366 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27367 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27369 /* Find the highest priority overlay with a mouse-face. */
27370 Lisp_Object overlay
= Qnil
;
27371 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27373 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27374 if (!NILP (mouse_face
))
27375 overlay
= overlay_vec
[i
];
27378 /* If we're highlighting the same overlay as before, there's
27379 no need to do that again. */
27380 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27381 goto check_help_echo
;
27382 hlinfo
->mouse_face_overlay
= overlay
;
27384 /* Clear the display of the old active region, if any. */
27385 if (clear_mouse_face (hlinfo
))
27386 cursor
= No_Cursor
;
27388 /* If no overlay applies, get a text property. */
27389 if (NILP (overlay
))
27390 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27392 /* Next, compute the bounds of the mouse highlighting and
27394 if (!NILP (mouse_face
) && STRINGP (object
))
27396 /* The mouse-highlighting comes from a display string
27397 with a mouse-face. */
27401 s
= Fprevious_single_property_change
27402 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27403 e
= Fnext_single_property_change
27404 (position
, Qmouse_face
, object
, Qnil
);
27406 s
= make_number (0);
27408 e
= make_number (SCHARS (object
) - 1);
27409 mouse_face_from_string_pos (w
, hlinfo
, object
,
27410 XINT (s
), XINT (e
));
27411 hlinfo
->mouse_face_past_end
= 0;
27412 hlinfo
->mouse_face_window
= window
;
27413 hlinfo
->mouse_face_face_id
27414 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27415 glyph
->face_id
, 1);
27416 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27417 cursor
= No_Cursor
;
27421 /* The mouse-highlighting, if any, comes from an overlay
27422 or text property in the buffer. */
27423 Lisp_Object buffer
IF_LINT (= Qnil
);
27424 Lisp_Object disp_string
IF_LINT (= Qnil
);
27426 if (STRINGP (object
))
27428 /* If we are on a display string with no mouse-face,
27429 check if the text under it has one. */
27430 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27431 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
27432 pos
= string_buffer_position (object
, start
);
27435 mouse_face
= get_char_property_and_overlay
27436 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27437 buffer
= w
->buffer
;
27438 disp_string
= object
;
27444 disp_string
= Qnil
;
27447 if (!NILP (mouse_face
))
27449 Lisp_Object before
, after
;
27450 Lisp_Object before_string
, after_string
;
27451 /* To correctly find the limits of mouse highlight
27452 in a bidi-reordered buffer, we must not use the
27453 optimization of limiting the search in
27454 previous-single-property-change and
27455 next-single-property-change, because
27456 rows_from_pos_range needs the real start and end
27457 positions to DTRT in this case. That's because
27458 the first row visible in a window does not
27459 necessarily display the character whose position
27460 is the smallest. */
27462 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27463 ? Fmarker_position (w
->start
)
27466 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27467 ? make_number (BUF_Z (XBUFFER (buffer
))
27468 - XFASTINT (w
->window_end_pos
))
27471 if (NILP (overlay
))
27473 /* Handle the text property case. */
27474 before
= Fprevious_single_property_change
27475 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27476 after
= Fnext_single_property_change
27477 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27478 before_string
= after_string
= Qnil
;
27482 /* Handle the overlay case. */
27483 before
= Foverlay_start (overlay
);
27484 after
= Foverlay_end (overlay
);
27485 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27486 after_string
= Foverlay_get (overlay
, Qafter_string
);
27488 if (!STRINGP (before_string
)) before_string
= Qnil
;
27489 if (!STRINGP (after_string
)) after_string
= Qnil
;
27492 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27495 : XFASTINT (before
),
27497 ? BUF_Z (XBUFFER (buffer
))
27498 : XFASTINT (after
),
27499 before_string
, after_string
,
27501 cursor
= No_Cursor
;
27508 /* Look for a `help-echo' property. */
27509 if (NILP (help_echo_string
)) {
27510 Lisp_Object help
, overlay
;
27512 /* Check overlays first. */
27513 help
= overlay
= Qnil
;
27514 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27516 overlay
= overlay_vec
[i
];
27517 help
= Foverlay_get (overlay
, Qhelp_echo
);
27522 help_echo_string
= help
;
27523 help_echo_window
= window
;
27524 help_echo_object
= overlay
;
27525 help_echo_pos
= pos
;
27529 Lisp_Object obj
= glyph
->object
;
27530 EMACS_INT charpos
= glyph
->charpos
;
27532 /* Try text properties. */
27535 && charpos
< SCHARS (obj
))
27537 help
= Fget_text_property (make_number (charpos
),
27541 /* If the string itself doesn't specify a help-echo,
27542 see if the buffer text ``under'' it does. */
27543 struct glyph_row
*r
27544 = MATRIX_ROW (w
->current_matrix
, vpos
);
27545 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
27546 EMACS_INT p
= string_buffer_position (obj
, start
);
27549 help
= Fget_char_property (make_number (p
),
27550 Qhelp_echo
, w
->buffer
);
27559 else if (BUFFERP (obj
)
27562 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27567 help_echo_string
= help
;
27568 help_echo_window
= window
;
27569 help_echo_object
= obj
;
27570 help_echo_pos
= charpos
;
27575 #ifdef HAVE_WINDOW_SYSTEM
27576 /* Look for a `pointer' property. */
27577 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27579 /* Check overlays first. */
27580 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27581 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27583 if (NILP (pointer
))
27585 Lisp_Object obj
= glyph
->object
;
27586 EMACS_INT charpos
= glyph
->charpos
;
27588 /* Try text properties. */
27591 && charpos
< SCHARS (obj
))
27593 pointer
= Fget_text_property (make_number (charpos
),
27595 if (NILP (pointer
))
27597 /* If the string itself doesn't specify a pointer,
27598 see if the buffer text ``under'' it does. */
27599 struct glyph_row
*r
27600 = MATRIX_ROW (w
->current_matrix
, vpos
);
27601 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
27602 EMACS_INT p
= string_buffer_position (obj
, start
);
27604 pointer
= Fget_char_property (make_number (p
),
27605 Qpointer
, w
->buffer
);
27608 else if (BUFFERP (obj
)
27611 pointer
= Fget_text_property (make_number (charpos
),
27615 #endif /* HAVE_WINDOW_SYSTEM */
27619 current_buffer
= obuf
;
27624 #ifdef HAVE_WINDOW_SYSTEM
27625 if (FRAME_WINDOW_P (f
))
27626 define_frame_cursor1 (f
, cursor
, pointer
);
27628 /* This is here to prevent a compiler error, about "label at end of
27629 compound statement". */
27636 Clear any mouse-face on window W. This function is part of the
27637 redisplay interface, and is called from try_window_id and similar
27638 functions to ensure the mouse-highlight is off. */
27641 x_clear_window_mouse_face (struct window
*w
)
27643 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27644 Lisp_Object window
;
27647 XSETWINDOW (window
, w
);
27648 if (EQ (window
, hlinfo
->mouse_face_window
))
27649 clear_mouse_face (hlinfo
);
27655 Just discard the mouse face information for frame F, if any.
27656 This is used when the size of F is changed. */
27659 cancel_mouse_face (struct frame
*f
)
27661 Lisp_Object window
;
27662 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27664 window
= hlinfo
->mouse_face_window
;
27665 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
27667 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27668 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27669 hlinfo
->mouse_face_window
= Qnil
;
27675 /***********************************************************************
27677 ***********************************************************************/
27679 #ifdef HAVE_WINDOW_SYSTEM
27681 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
27682 which intersects rectangle R. R is in window-relative coordinates. */
27685 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
27686 enum glyph_row_area area
)
27688 struct glyph
*first
= row
->glyphs
[area
];
27689 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
27690 struct glyph
*last
;
27691 int first_x
, start_x
, x
;
27693 if (area
== TEXT_AREA
&& row
->fill_line_p
)
27694 /* If row extends face to end of line write the whole line. */
27695 draw_glyphs (w
, 0, row
, area
,
27696 0, row
->used
[area
],
27697 DRAW_NORMAL_TEXT
, 0);
27700 /* Set START_X to the window-relative start position for drawing glyphs of
27701 AREA. The first glyph of the text area can be partially visible.
27702 The first glyphs of other areas cannot. */
27703 start_x
= window_box_left_offset (w
, area
);
27705 if (area
== TEXT_AREA
)
27708 /* Find the first glyph that must be redrawn. */
27710 && x
+ first
->pixel_width
< r
->x
)
27712 x
+= first
->pixel_width
;
27716 /* Find the last one. */
27720 && x
< r
->x
+ r
->width
)
27722 x
+= last
->pixel_width
;
27728 draw_glyphs (w
, first_x
- start_x
, row
, area
,
27729 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
27730 DRAW_NORMAL_TEXT
, 0);
27735 /* Redraw the parts of the glyph row ROW on window W intersecting
27736 rectangle R. R is in window-relative coordinates. Value is
27737 non-zero if mouse-face was overwritten. */
27740 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
27742 xassert (row
->enabled_p
);
27744 if (row
->mode_line_p
|| w
->pseudo_window_p
)
27745 draw_glyphs (w
, 0, row
, TEXT_AREA
,
27746 0, row
->used
[TEXT_AREA
],
27747 DRAW_NORMAL_TEXT
, 0);
27750 if (row
->used
[LEFT_MARGIN_AREA
])
27751 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
27752 if (row
->used
[TEXT_AREA
])
27753 expose_area (w
, row
, r
, TEXT_AREA
);
27754 if (row
->used
[RIGHT_MARGIN_AREA
])
27755 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
27756 draw_row_fringe_bitmaps (w
, row
);
27759 return row
->mouse_face_p
;
27763 /* Redraw those parts of glyphs rows during expose event handling that
27764 overlap other rows. Redrawing of an exposed line writes over parts
27765 of lines overlapping that exposed line; this function fixes that.
27767 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
27768 row in W's current matrix that is exposed and overlaps other rows.
27769 LAST_OVERLAPPING_ROW is the last such row. */
27772 expose_overlaps (struct window
*w
,
27773 struct glyph_row
*first_overlapping_row
,
27774 struct glyph_row
*last_overlapping_row
,
27777 struct glyph_row
*row
;
27779 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
27780 if (row
->overlapping_p
)
27782 xassert (row
->enabled_p
&& !row
->mode_line_p
);
27785 if (row
->used
[LEFT_MARGIN_AREA
])
27786 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
27788 if (row
->used
[TEXT_AREA
])
27789 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
27791 if (row
->used
[RIGHT_MARGIN_AREA
])
27792 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
27798 /* Return non-zero if W's cursor intersects rectangle R. */
27801 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
27803 XRectangle cr
, result
;
27804 struct glyph
*cursor_glyph
;
27805 struct glyph_row
*row
;
27807 if (w
->phys_cursor
.vpos
>= 0
27808 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
27809 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
27811 && row
->cursor_in_fringe_p
)
27813 /* Cursor is in the fringe. */
27814 cr
.x
= window_box_right_offset (w
,
27815 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
27816 ? RIGHT_MARGIN_AREA
27819 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
27820 cr
.height
= row
->height
;
27821 return x_intersect_rectangles (&cr
, r
, &result
);
27824 cursor_glyph
= get_phys_cursor_glyph (w
);
27827 /* r is relative to W's box, but w->phys_cursor.x is relative
27828 to left edge of W's TEXT area. Adjust it. */
27829 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
27830 cr
.y
= w
->phys_cursor
.y
;
27831 cr
.width
= cursor_glyph
->pixel_width
;
27832 cr
.height
= w
->phys_cursor_height
;
27833 /* ++KFS: W32 version used W32-specific IntersectRect here, but
27834 I assume the effect is the same -- and this is portable. */
27835 return x_intersect_rectangles (&cr
, r
, &result
);
27837 /* If we don't understand the format, pretend we're not in the hot-spot. */
27843 Draw a vertical window border to the right of window W if W doesn't
27844 have vertical scroll bars. */
27847 x_draw_vertical_border (struct window
*w
)
27849 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27851 /* We could do better, if we knew what type of scroll-bar the adjacent
27852 windows (on either side) have... But we don't :-(
27853 However, I think this works ok. ++KFS 2003-04-25 */
27855 /* Redraw borders between horizontally adjacent windows. Don't
27856 do it for frames with vertical scroll bars because either the
27857 right scroll bar of a window, or the left scroll bar of its
27858 neighbor will suffice as a border. */
27859 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
27862 if (!WINDOW_RIGHTMOST_P (w
)
27863 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
27865 int x0
, x1
, y0
, y1
;
27867 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27870 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27873 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
27875 else if (!WINDOW_LEFTMOST_P (w
)
27876 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
27878 int x0
, x1
, y0
, y1
;
27880 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
27883 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
27886 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
27891 /* Redraw the part of window W intersection rectangle FR. Pixel
27892 coordinates in FR are frame-relative. Call this function with
27893 input blocked. Value is non-zero if the exposure overwrites
27897 expose_window (struct window
*w
, XRectangle
*fr
)
27899 struct frame
*f
= XFRAME (w
->frame
);
27901 int mouse_face_overwritten_p
= 0;
27903 /* If window is not yet fully initialized, do nothing. This can
27904 happen when toolkit scroll bars are used and a window is split.
27905 Reconfiguring the scroll bar will generate an expose for a newly
27907 if (w
->current_matrix
== NULL
)
27910 /* When we're currently updating the window, display and current
27911 matrix usually don't agree. Arrange for a thorough display
27913 if (w
== updated_window
)
27915 SET_FRAME_GARBAGED (f
);
27919 /* Frame-relative pixel rectangle of W. */
27920 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
27921 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
27922 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
27923 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
27925 if (x_intersect_rectangles (fr
, &wr
, &r
))
27927 int yb
= window_text_bottom_y (w
);
27928 struct glyph_row
*row
;
27929 int cursor_cleared_p
, phys_cursor_on_p
;
27930 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
27932 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
27933 r
.x
, r
.y
, r
.width
, r
.height
));
27935 /* Convert to window coordinates. */
27936 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
27937 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
27939 /* Turn off the cursor. */
27940 if (!w
->pseudo_window_p
27941 && phys_cursor_in_rect_p (w
, &r
))
27943 x_clear_cursor (w
);
27944 cursor_cleared_p
= 1;
27947 cursor_cleared_p
= 0;
27949 /* If the row containing the cursor extends face to end of line,
27950 then expose_area might overwrite the cursor outside the
27951 rectangle and thus notice_overwritten_cursor might clear
27952 w->phys_cursor_on_p. We remember the original value and
27953 check later if it is changed. */
27954 phys_cursor_on_p
= w
->phys_cursor_on_p
;
27956 /* Update lines intersecting rectangle R. */
27957 first_overlapping_row
= last_overlapping_row
= NULL
;
27958 for (row
= w
->current_matrix
->rows
;
27963 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
27965 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
27966 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
27967 || (r
.y
>= y0
&& r
.y
< y1
)
27968 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
27970 /* A header line may be overlapping, but there is no need
27971 to fix overlapping areas for them. KFS 2005-02-12 */
27972 if (row
->overlapping_p
&& !row
->mode_line_p
)
27974 if (first_overlapping_row
== NULL
)
27975 first_overlapping_row
= row
;
27976 last_overlapping_row
= row
;
27980 if (expose_line (w
, row
, &r
))
27981 mouse_face_overwritten_p
= 1;
27984 else if (row
->overlapping_p
)
27986 /* We must redraw a row overlapping the exposed area. */
27988 ? y0
+ row
->phys_height
> r
.y
27989 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
27991 if (first_overlapping_row
== NULL
)
27992 first_overlapping_row
= row
;
27993 last_overlapping_row
= row
;
28001 /* Display the mode line if there is one. */
28002 if (WINDOW_WANTS_MODELINE_P (w
)
28003 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28005 && row
->y
< r
.y
+ r
.height
)
28007 if (expose_line (w
, row
, &r
))
28008 mouse_face_overwritten_p
= 1;
28011 if (!w
->pseudo_window_p
)
28013 /* Fix the display of overlapping rows. */
28014 if (first_overlapping_row
)
28015 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28018 /* Draw border between windows. */
28019 x_draw_vertical_border (w
);
28021 /* Turn the cursor on again. */
28022 if (cursor_cleared_p
28023 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28024 update_window_cursor (w
, 1);
28028 return mouse_face_overwritten_p
;
28033 /* Redraw (parts) of all windows in the window tree rooted at W that
28034 intersect R. R contains frame pixel coordinates. Value is
28035 non-zero if the exposure overwrites mouse-face. */
28038 expose_window_tree (struct window
*w
, XRectangle
*r
)
28040 struct frame
*f
= XFRAME (w
->frame
);
28041 int mouse_face_overwritten_p
= 0;
28043 while (w
&& !FRAME_GARBAGED_P (f
))
28045 if (!NILP (w
->hchild
))
28046 mouse_face_overwritten_p
28047 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28048 else if (!NILP (w
->vchild
))
28049 mouse_face_overwritten_p
28050 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28052 mouse_face_overwritten_p
|= expose_window (w
, r
);
28054 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28057 return mouse_face_overwritten_p
;
28062 Redisplay an exposed area of frame F. X and Y are the upper-left
28063 corner of the exposed rectangle. W and H are width and height of
28064 the exposed area. All are pixel values. W or H zero means redraw
28065 the entire frame. */
28068 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28071 int mouse_face_overwritten_p
= 0;
28073 TRACE ((stderr
, "expose_frame "));
28075 /* No need to redraw if frame will be redrawn soon. */
28076 if (FRAME_GARBAGED_P (f
))
28078 TRACE ((stderr
, " garbaged\n"));
28082 /* If basic faces haven't been realized yet, there is no point in
28083 trying to redraw anything. This can happen when we get an expose
28084 event while Emacs is starting, e.g. by moving another window. */
28085 if (FRAME_FACE_CACHE (f
) == NULL
28086 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28088 TRACE ((stderr
, " no faces\n"));
28092 if (w
== 0 || h
== 0)
28095 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28096 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28106 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28107 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28109 if (WINDOWP (f
->tool_bar_window
))
28110 mouse_face_overwritten_p
28111 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28113 #ifdef HAVE_X_WINDOWS
28115 #ifndef USE_X_TOOLKIT
28116 if (WINDOWP (f
->menu_bar_window
))
28117 mouse_face_overwritten_p
28118 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28119 #endif /* not USE_X_TOOLKIT */
28123 /* Some window managers support a focus-follows-mouse style with
28124 delayed raising of frames. Imagine a partially obscured frame,
28125 and moving the mouse into partially obscured mouse-face on that
28126 frame. The visible part of the mouse-face will be highlighted,
28127 then the WM raises the obscured frame. With at least one WM, KDE
28128 2.1, Emacs is not getting any event for the raising of the frame
28129 (even tried with SubstructureRedirectMask), only Expose events.
28130 These expose events will draw text normally, i.e. not
28131 highlighted. Which means we must redo the highlight here.
28132 Subsume it under ``we love X''. --gerd 2001-08-15 */
28133 /* Included in Windows version because Windows most likely does not
28134 do the right thing if any third party tool offers
28135 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28136 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28138 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28139 if (f
== hlinfo
->mouse_face_mouse_frame
)
28141 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28142 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28143 clear_mouse_face (hlinfo
);
28144 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28151 Determine the intersection of two rectangles R1 and R2. Return
28152 the intersection in *RESULT. Value is non-zero if RESULT is not
28156 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28158 XRectangle
*left
, *right
;
28159 XRectangle
*upper
, *lower
;
28160 int intersection_p
= 0;
28162 /* Rearrange so that R1 is the left-most rectangle. */
28164 left
= r1
, right
= r2
;
28166 left
= r2
, right
= r1
;
28168 /* X0 of the intersection is right.x0, if this is inside R1,
28169 otherwise there is no intersection. */
28170 if (right
->x
<= left
->x
+ left
->width
)
28172 result
->x
= right
->x
;
28174 /* The right end of the intersection is the minimum of
28175 the right ends of left and right. */
28176 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28179 /* Same game for Y. */
28181 upper
= r1
, lower
= r2
;
28183 upper
= r2
, lower
= r1
;
28185 /* The upper end of the intersection is lower.y0, if this is inside
28186 of upper. Otherwise, there is no intersection. */
28187 if (lower
->y
<= upper
->y
+ upper
->height
)
28189 result
->y
= lower
->y
;
28191 /* The lower end of the intersection is the minimum of the lower
28192 ends of upper and lower. */
28193 result
->height
= (min (lower
->y
+ lower
->height
,
28194 upper
->y
+ upper
->height
)
28196 intersection_p
= 1;
28200 return intersection_p
;
28203 #endif /* HAVE_WINDOW_SYSTEM */
28206 /***********************************************************************
28208 ***********************************************************************/
28211 syms_of_xdisp (void)
28213 Vwith_echo_area_save_vector
= Qnil
;
28214 staticpro (&Vwith_echo_area_save_vector
);
28216 Vmessage_stack
= Qnil
;
28217 staticpro (&Vmessage_stack
);
28219 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28221 message_dolog_marker1
= Fmake_marker ();
28222 staticpro (&message_dolog_marker1
);
28223 message_dolog_marker2
= Fmake_marker ();
28224 staticpro (&message_dolog_marker2
);
28225 message_dolog_marker3
= Fmake_marker ();
28226 staticpro (&message_dolog_marker3
);
28229 defsubr (&Sdump_frame_glyph_matrix
);
28230 defsubr (&Sdump_glyph_matrix
);
28231 defsubr (&Sdump_glyph_row
);
28232 defsubr (&Sdump_tool_bar_row
);
28233 defsubr (&Strace_redisplay
);
28234 defsubr (&Strace_to_stderr
);
28236 #ifdef HAVE_WINDOW_SYSTEM
28237 defsubr (&Stool_bar_lines_needed
);
28238 defsubr (&Slookup_image_map
);
28240 defsubr (&Sformat_mode_line
);
28241 defsubr (&Sinvisible_p
);
28242 defsubr (&Scurrent_bidi_paragraph_direction
);
28244 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28245 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28246 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28247 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28248 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28249 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28250 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28251 DEFSYM (Qeval
, "eval");
28252 DEFSYM (QCdata
, ":data");
28253 DEFSYM (Qdisplay
, "display");
28254 DEFSYM (Qspace_width
, "space-width");
28255 DEFSYM (Qraise
, "raise");
28256 DEFSYM (Qslice
, "slice");
28257 DEFSYM (Qspace
, "space");
28258 DEFSYM (Qmargin
, "margin");
28259 DEFSYM (Qpointer
, "pointer");
28260 DEFSYM (Qleft_margin
, "left-margin");
28261 DEFSYM (Qright_margin
, "right-margin");
28262 DEFSYM (Qcenter
, "center");
28263 DEFSYM (Qline_height
, "line-height");
28264 DEFSYM (QCalign_to
, ":align-to");
28265 DEFSYM (QCrelative_width
, ":relative-width");
28266 DEFSYM (QCrelative_height
, ":relative-height");
28267 DEFSYM (QCeval
, ":eval");
28268 DEFSYM (QCpropertize
, ":propertize");
28269 DEFSYM (QCfile
, ":file");
28270 DEFSYM (Qfontified
, "fontified");
28271 DEFSYM (Qfontification_functions
, "fontification-functions");
28272 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28273 DEFSYM (Qescape_glyph
, "escape-glyph");
28274 DEFSYM (Qnobreak_space
, "nobreak-space");
28275 DEFSYM (Qimage
, "image");
28276 DEFSYM (Qtext
, "text");
28277 DEFSYM (Qboth
, "both");
28278 DEFSYM (Qboth_horiz
, "both-horiz");
28279 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28280 DEFSYM (QCmap
, ":map");
28281 DEFSYM (QCpointer
, ":pointer");
28282 DEFSYM (Qrect
, "rect");
28283 DEFSYM (Qcircle
, "circle");
28284 DEFSYM (Qpoly
, "poly");
28285 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28286 DEFSYM (Qgrow_only
, "grow-only");
28287 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28288 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28289 DEFSYM (Qposition
, "position");
28290 DEFSYM (Qbuffer_position
, "buffer-position");
28291 DEFSYM (Qobject
, "object");
28292 DEFSYM (Qbar
, "bar");
28293 DEFSYM (Qhbar
, "hbar");
28294 DEFSYM (Qbox
, "box");
28295 DEFSYM (Qhollow
, "hollow");
28296 DEFSYM (Qhand
, "hand");
28297 DEFSYM (Qarrow
, "arrow");
28298 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28300 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28301 Fcons (intern_c_string ("void-variable"), Qnil
)),
28303 staticpro (&list_of_error
);
28305 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28306 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28307 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28308 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28310 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28311 staticpro (&echo_buffer
[0]);
28312 staticpro (&echo_buffer
[1]);
28314 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28315 staticpro (&echo_area_buffer
[0]);
28316 staticpro (&echo_area_buffer
[1]);
28318 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
28319 staticpro (&Vmessages_buffer_name
);
28321 mode_line_proptrans_alist
= Qnil
;
28322 staticpro (&mode_line_proptrans_alist
);
28323 mode_line_string_list
= Qnil
;
28324 staticpro (&mode_line_string_list
);
28325 mode_line_string_face
= Qnil
;
28326 staticpro (&mode_line_string_face
);
28327 mode_line_string_face_prop
= Qnil
;
28328 staticpro (&mode_line_string_face_prop
);
28329 Vmode_line_unwind_vector
= Qnil
;
28330 staticpro (&Vmode_line_unwind_vector
);
28332 help_echo_string
= Qnil
;
28333 staticpro (&help_echo_string
);
28334 help_echo_object
= Qnil
;
28335 staticpro (&help_echo_object
);
28336 help_echo_window
= Qnil
;
28337 staticpro (&help_echo_window
);
28338 previous_help_echo_string
= Qnil
;
28339 staticpro (&previous_help_echo_string
);
28340 help_echo_pos
= -1;
28342 DEFSYM (Qright_to_left
, "right-to-left");
28343 DEFSYM (Qleft_to_right
, "left-to-right");
28345 #ifdef HAVE_WINDOW_SYSTEM
28346 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28347 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28348 For example, if a block cursor is over a tab, it will be drawn as
28349 wide as that tab on the display. */);
28350 x_stretch_cursor_p
= 0;
28353 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28354 doc
: /* Non-nil means highlight trailing whitespace.
28355 The face used for trailing whitespace is `trailing-whitespace'. */);
28356 Vshow_trailing_whitespace
= Qnil
;
28358 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28359 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28360 If the value is t, Emacs highlights non-ASCII chars which have the
28361 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28362 or `escape-glyph' face respectively.
28364 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28365 U+2011 (non-breaking hyphen) are affected.
28367 Any other non-nil value means to display these characters as a escape
28368 glyph followed by an ordinary space or hyphen.
28370 A value of nil means no special handling of these characters. */);
28371 Vnobreak_char_display
= Qt
;
28373 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28374 doc
: /* The pointer shape to show in void text areas.
28375 A value of nil means to show the text pointer. Other options are `arrow',
28376 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28377 Vvoid_text_area_pointer
= Qarrow
;
28379 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28380 doc
: /* Non-nil means don't actually do any redisplay.
28381 This is used for internal purposes. */);
28382 Vinhibit_redisplay
= Qnil
;
28384 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28385 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28386 Vglobal_mode_string
= Qnil
;
28388 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28389 doc
: /* Marker for where to display an arrow on top of the buffer text.
28390 This must be the beginning of a line in order to work.
28391 See also `overlay-arrow-string'. */);
28392 Voverlay_arrow_position
= Qnil
;
28394 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28395 doc
: /* String to display as an arrow in non-window frames.
28396 See also `overlay-arrow-position'. */);
28397 Voverlay_arrow_string
= make_pure_c_string ("=>");
28399 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28400 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28401 The symbols on this list are examined during redisplay to determine
28402 where to display overlay arrows. */);
28403 Voverlay_arrow_variable_list
28404 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28406 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28407 doc
: /* The number of lines to try scrolling a window by when point moves out.
28408 If that fails to bring point back on frame, point is centered instead.
28409 If this is zero, point is always centered after it moves off frame.
28410 If you want scrolling to always be a line at a time, you should set
28411 `scroll-conservatively' to a large value rather than set this to 1. */);
28413 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28414 doc
: /* Scroll up to this many lines, to bring point back on screen.
28415 If point moves off-screen, redisplay will scroll by up to
28416 `scroll-conservatively' lines in order to bring point just barely
28417 onto the screen again. If that cannot be done, then redisplay
28418 recenters point as usual.
28420 If the value is greater than 100, redisplay will never recenter point,
28421 but will always scroll just enough text to bring point into view, even
28422 if you move far away.
28424 A value of zero means always recenter point if it moves off screen. */);
28425 scroll_conservatively
= 0;
28427 DEFVAR_INT ("scroll-margin", scroll_margin
,
28428 doc
: /* Number of lines of margin at the top and bottom of a window.
28429 Recenter the window whenever point gets within this many lines
28430 of the top or bottom of the window. */);
28433 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28434 doc
: /* Pixels per inch value for non-window system displays.
28435 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28436 Vdisplay_pixels_per_inch
= make_float (72.0);
28439 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28442 DEFVAR_LISP ("truncate-partial-width-windows",
28443 Vtruncate_partial_width_windows
,
28444 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28445 For an integer value, truncate lines in each window narrower than the
28446 full frame width, provided the window width is less than that integer;
28447 otherwise, respect the value of `truncate-lines'.
28449 For any other non-nil value, truncate lines in all windows that do
28450 not span the full frame width.
28452 A value of nil means to respect the value of `truncate-lines'.
28454 If `word-wrap' is enabled, you might want to reduce this. */);
28455 Vtruncate_partial_width_windows
= make_number (50);
28457 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28458 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28459 Any other value means to use the appropriate face, `mode-line',
28460 `header-line', or `menu' respectively. */);
28461 mode_line_inverse_video
= 1;
28463 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28464 doc
: /* Maximum buffer size for which line number should be displayed.
28465 If the buffer is bigger than this, the line number does not appear
28466 in the mode line. A value of nil means no limit. */);
28467 Vline_number_display_limit
= Qnil
;
28469 DEFVAR_INT ("line-number-display-limit-width",
28470 line_number_display_limit_width
,
28471 doc
: /* Maximum line width (in characters) for line number display.
28472 If the average length of the lines near point is bigger than this, then the
28473 line number may be omitted from the mode line. */);
28474 line_number_display_limit_width
= 200;
28476 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28477 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28478 highlight_nonselected_windows
= 0;
28480 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28481 doc
: /* Non-nil if more than one frame is visible on this display.
28482 Minibuffer-only frames don't count, but iconified frames do.
28483 This variable is not guaranteed to be accurate except while processing
28484 `frame-title-format' and `icon-title-format'. */);
28486 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28487 doc
: /* Template for displaying the title bar of visible frames.
28488 \(Assuming the window manager supports this feature.)
28490 This variable has the same structure as `mode-line-format', except that
28491 the %c and %l constructs are ignored. It is used only on frames for
28492 which no explicit name has been set \(see `modify-frame-parameters'). */);
28494 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28495 doc
: /* Template for displaying the title bar of an iconified frame.
28496 \(Assuming the window manager supports this feature.)
28497 This variable has the same structure as `mode-line-format' (which see),
28498 and is used only on frames for which no explicit name has been set
28499 \(see `modify-frame-parameters'). */);
28501 = Vframe_title_format
28502 = pure_cons (intern_c_string ("multiple-frames"),
28503 pure_cons (make_pure_c_string ("%b"),
28504 pure_cons (pure_cons (empty_unibyte_string
,
28505 pure_cons (intern_c_string ("invocation-name"),
28506 pure_cons (make_pure_c_string ("@"),
28507 pure_cons (intern_c_string ("system-name"),
28511 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28512 doc
: /* Maximum number of lines to keep in the message log buffer.
28513 If nil, disable message logging. If t, log messages but don't truncate
28514 the buffer when it becomes large. */);
28515 Vmessage_log_max
= make_number (100);
28517 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28518 doc
: /* Functions called before redisplay, if window sizes have changed.
28519 The value should be a list of functions that take one argument.
28520 Just before redisplay, for each frame, if any of its windows have changed
28521 size since the last redisplay, or have been split or deleted,
28522 all the functions in the list are called, with the frame as argument. */);
28523 Vwindow_size_change_functions
= Qnil
;
28525 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28526 doc
: /* List of functions to call before redisplaying a window with scrolling.
28527 Each function is called with two arguments, the window and its new
28528 display-start position. Note that these functions are also called by
28529 `set-window-buffer'. Also note that the value of `window-end' is not
28530 valid when these functions are called.
28532 Warning: Do not use this feature to alter the way the window
28533 is scrolled. It is not designed for that, and such use probably won't
28535 Vwindow_scroll_functions
= Qnil
;
28537 DEFVAR_LISP ("window-text-change-functions",
28538 Vwindow_text_change_functions
,
28539 doc
: /* Functions to call in redisplay when text in the window might change. */);
28540 Vwindow_text_change_functions
= Qnil
;
28542 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28543 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28544 Each function is called with two arguments, the window and the end trigger value.
28545 See `set-window-redisplay-end-trigger'. */);
28546 Vredisplay_end_trigger_functions
= Qnil
;
28548 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28549 doc
: /* Non-nil means autoselect window with mouse pointer.
28550 If nil, do not autoselect windows.
28551 A positive number means delay autoselection by that many seconds: a
28552 window is autoselected only after the mouse has remained in that
28553 window for the duration of the delay.
28554 A negative number has a similar effect, but causes windows to be
28555 autoselected only after the mouse has stopped moving. \(Because of
28556 the way Emacs compares mouse events, you will occasionally wait twice
28557 that time before the window gets selected.\)
28558 Any other value means to autoselect window instantaneously when the
28559 mouse pointer enters it.
28561 Autoselection selects the minibuffer only if it is active, and never
28562 unselects the minibuffer if it is active.
28564 When customizing this variable make sure that the actual value of
28565 `focus-follows-mouse' matches the behavior of your window manager. */);
28566 Vmouse_autoselect_window
= Qnil
;
28568 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28569 doc
: /* Non-nil means automatically resize tool-bars.
28570 This dynamically changes the tool-bar's height to the minimum height
28571 that is needed to make all tool-bar items visible.
28572 If value is `grow-only', the tool-bar's height is only increased
28573 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28574 Vauto_resize_tool_bars
= Qt
;
28576 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28577 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28578 auto_raise_tool_bar_buttons_p
= 1;
28580 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28581 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28582 make_cursor_line_fully_visible_p
= 1;
28584 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28585 doc
: /* Border below tool-bar in pixels.
28586 If an integer, use it as the height of the border.
28587 If it is one of `internal-border-width' or `border-width', use the
28588 value of the corresponding frame parameter.
28589 Otherwise, no border is added below the tool-bar. */);
28590 Vtool_bar_border
= Qinternal_border_width
;
28592 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28593 doc
: /* Margin around tool-bar buttons in pixels.
28594 If an integer, use that for both horizontal and vertical margins.
28595 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28596 HORZ specifying the horizontal margin, and VERT specifying the
28597 vertical margin. */);
28598 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28600 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28601 doc
: /* Relief thickness of tool-bar buttons. */);
28602 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28604 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28605 doc
: /* Tool bar style to use.
28607 image - show images only
28608 text - show text only
28609 both - show both, text below image
28610 both-horiz - show text to the right of the image
28611 text-image-horiz - show text to the left of the image
28612 any other - use system default or image if no system default. */);
28613 Vtool_bar_style
= Qnil
;
28615 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28616 doc
: /* Maximum number of characters a label can have to be shown.
28617 The tool bar style must also show labels for this to have any effect, see
28618 `tool-bar-style'. */);
28619 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28621 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28622 doc
: /* List of functions to call to fontify regions of text.
28623 Each function is called with one argument POS. Functions must
28624 fontify a region starting at POS in the current buffer, and give
28625 fontified regions the property `fontified'. */);
28626 Vfontification_functions
= Qnil
;
28627 Fmake_variable_buffer_local (Qfontification_functions
);
28629 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28630 unibyte_display_via_language_environment
,
28631 doc
: /* Non-nil means display unibyte text according to language environment.
28632 Specifically, this means that raw bytes in the range 160-255 decimal
28633 are displayed by converting them to the equivalent multibyte characters
28634 according to the current language environment. As a result, they are
28635 displayed according to the current fontset.
28637 Note that this variable affects only how these bytes are displayed,
28638 but does not change the fact they are interpreted as raw bytes. */);
28639 unibyte_display_via_language_environment
= 0;
28641 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
28642 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
28643 If a float, it specifies a fraction of the mini-window frame's height.
28644 If an integer, it specifies a number of lines. */);
28645 Vmax_mini_window_height
= make_float (0.25);
28647 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
28648 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
28649 A value of nil means don't automatically resize mini-windows.
28650 A value of t means resize them to fit the text displayed in them.
28651 A value of `grow-only', the default, means let mini-windows grow only;
28652 they return to their normal size when the minibuffer is closed, or the
28653 echo area becomes empty. */);
28654 Vresize_mini_windows
= Qgrow_only
;
28656 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
28657 doc
: /* Alist specifying how to blink the cursor off.
28658 Each element has the form (ON-STATE . OFF-STATE). Whenever the
28659 `cursor-type' frame-parameter or variable equals ON-STATE,
28660 comparing using `equal', Emacs uses OFF-STATE to specify
28661 how to blink it off. ON-STATE and OFF-STATE are values for
28662 the `cursor-type' frame parameter.
28664 If a frame's ON-STATE has no entry in this list,
28665 the frame's other specifications determine how to blink the cursor off. */);
28666 Vblink_cursor_alist
= Qnil
;
28668 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
28669 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
28670 If non-nil, windows are automatically scrolled horizontally to make
28671 point visible. */);
28672 automatic_hscrolling_p
= 1;
28673 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
28675 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
28676 doc
: /* How many columns away from the window edge point is allowed to get
28677 before automatic hscrolling will horizontally scroll the window. */);
28678 hscroll_margin
= 5;
28680 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
28681 doc
: /* How many columns to scroll the window when point gets too close to the edge.
28682 When point is less than `hscroll-margin' columns from the window
28683 edge, automatic hscrolling will scroll the window by the amount of columns
28684 determined by this variable. If its value is a positive integer, scroll that
28685 many columns. If it's a positive floating-point number, it specifies the
28686 fraction of the window's width to scroll. If it's nil or zero, point will be
28687 centered horizontally after the scroll. Any other value, including negative
28688 numbers, are treated as if the value were zero.
28690 Automatic hscrolling always moves point outside the scroll margin, so if
28691 point was more than scroll step columns inside the margin, the window will
28692 scroll more than the value given by the scroll step.
28694 Note that the lower bound for automatic hscrolling specified by `scroll-left'
28695 and `scroll-right' overrides this variable's effect. */);
28696 Vhscroll_step
= make_number (0);
28698 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
28699 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
28700 Bind this around calls to `message' to let it take effect. */);
28701 message_truncate_lines
= 0;
28703 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
28704 doc
: /* Normal hook run to update the menu bar definitions.
28705 Redisplay runs this hook before it redisplays the menu bar.
28706 This is used to update submenus such as Buffers,
28707 whose contents depend on various data. */);
28708 Vmenu_bar_update_hook
= Qnil
;
28710 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
28711 doc
: /* Frame for which we are updating a menu.
28712 The enable predicate for a menu binding should check this variable. */);
28713 Vmenu_updating_frame
= Qnil
;
28715 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
28716 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
28717 inhibit_menubar_update
= 0;
28719 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
28720 doc
: /* Prefix prepended to all continuation lines at display time.
28721 The value may be a string, an image, or a stretch-glyph; it is
28722 interpreted in the same way as the value of a `display' text property.
28724 This variable is overridden by any `wrap-prefix' text or overlay
28727 To add a prefix to non-continuation lines, use `line-prefix'. */);
28728 Vwrap_prefix
= Qnil
;
28729 DEFSYM (Qwrap_prefix
, "wrap-prefix");
28730 Fmake_variable_buffer_local (Qwrap_prefix
);
28732 DEFVAR_LISP ("line-prefix", Vline_prefix
,
28733 doc
: /* Prefix prepended to all non-continuation lines at display time.
28734 The value may be a string, an image, or a stretch-glyph; it is
28735 interpreted in the same way as the value of a `display' text property.
28737 This variable is overridden by any `line-prefix' text or overlay
28740 To add a prefix to continuation lines, use `wrap-prefix'. */);
28741 Vline_prefix
= Qnil
;
28742 DEFSYM (Qline_prefix
, "line-prefix");
28743 Fmake_variable_buffer_local (Qline_prefix
);
28745 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
28746 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
28747 inhibit_eval_during_redisplay
= 0;
28749 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
28750 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
28751 inhibit_free_realized_faces
= 0;
28754 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
28755 doc
: /* Inhibit try_window_id display optimization. */);
28756 inhibit_try_window_id
= 0;
28758 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
28759 doc
: /* Inhibit try_window_reusing display optimization. */);
28760 inhibit_try_window_reusing
= 0;
28762 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
28763 doc
: /* Inhibit try_cursor_movement display optimization. */);
28764 inhibit_try_cursor_movement
= 0;
28765 #endif /* GLYPH_DEBUG */
28767 DEFVAR_INT ("overline-margin", overline_margin
,
28768 doc
: /* Space between overline and text, in pixels.
28769 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
28770 margin to the character height. */);
28771 overline_margin
= 2;
28773 DEFVAR_INT ("underline-minimum-offset",
28774 underline_minimum_offset
,
28775 doc
: /* Minimum distance between baseline and underline.
28776 This can improve legibility of underlined text at small font sizes,
28777 particularly when using variable `x-use-underline-position-properties'
28778 with fonts that specify an UNDERLINE_POSITION relatively close to the
28779 baseline. The default value is 1. */);
28780 underline_minimum_offset
= 1;
28782 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
28783 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
28784 This feature only works when on a window system that can change
28785 cursor shapes. */);
28786 display_hourglass_p
= 1;
28788 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
28789 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
28790 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
28792 hourglass_atimer
= NULL
;
28793 hourglass_shown_p
= 0;
28795 DEFSYM (Qglyphless_char
, "glyphless-char");
28796 DEFSYM (Qhex_code
, "hex-code");
28797 DEFSYM (Qempty_box
, "empty-box");
28798 DEFSYM (Qthin_space
, "thin-space");
28799 DEFSYM (Qzero_width
, "zero-width");
28801 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
28802 /* Intern this now in case it isn't already done.
28803 Setting this variable twice is harmless.
28804 But don't staticpro it here--that is done in alloc.c. */
28805 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
28806 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
28808 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
28809 doc
: /* Char-table defining glyphless characters.
28810 Each element, if non-nil, should be one of the following:
28811 an ASCII acronym string: display this string in a box
28812 `hex-code': display the hexadecimal code of a character in a box
28813 `empty-box': display as an empty box
28814 `thin-space': display as 1-pixel width space
28815 `zero-width': don't display
28816 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
28817 display method for graphical terminals and text terminals respectively.
28818 GRAPHICAL and TEXT should each have one of the values listed above.
28820 The char-table has one extra slot to control the display of a character for
28821 which no font is found. This slot only takes effect on graphical terminals.
28822 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
28823 `thin-space'. The default is `empty-box'. */);
28824 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
28825 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
28830 /* Initialize this module when Emacs starts. */
28835 current_header_line_height
= current_mode_line_height
= -1;
28837 CHARPOS (this_line_start_pos
) = 0;
28839 if (!noninteractive
)
28841 struct window
*m
= XWINDOW (minibuf_window
);
28842 Lisp_Object frame
= m
->frame
;
28843 struct frame
*f
= XFRAME (frame
);
28844 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
28845 struct window
*r
= XWINDOW (root
);
28848 echo_area_window
= minibuf_window
;
28850 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
28851 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
28852 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
28853 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
28854 XSETFASTINT (m
->total_lines
, 1);
28855 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
28857 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
28858 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
28859 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
28861 /* The default ellipsis glyphs `...'. */
28862 for (i
= 0; i
< 3; ++i
)
28863 default_invis_vector
[i
] = make_number ('.');
28867 /* Allocate the buffer for frame titles.
28868 Also used for `format-mode-line'. */
28870 mode_line_noprop_buf
= (char *) xmalloc (size
);
28871 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
28872 mode_line_noprop_ptr
= mode_line_noprop_buf
;
28873 mode_line_target
= MODE_LINE_DISPLAY
;
28876 help_echo_showing_p
= 0;
28879 /* Since w32 does not support atimers, it defines its own implementation of
28880 the following three functions in w32fns.c. */
28883 /* Platform-independent portion of hourglass implementation. */
28885 /* Return non-zero if hourglass timer has been started or hourglass is
28888 hourglass_started (void)
28890 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
28893 /* Cancel a currently active hourglass timer, and start a new one. */
28895 start_hourglass (void)
28897 #if defined (HAVE_WINDOW_SYSTEM)
28899 int secs
, usecs
= 0;
28901 cancel_hourglass ();
28903 if (INTEGERP (Vhourglass_delay
)
28904 && XINT (Vhourglass_delay
) > 0)
28905 secs
= XFASTINT (Vhourglass_delay
);
28906 else if (FLOATP (Vhourglass_delay
)
28907 && XFLOAT_DATA (Vhourglass_delay
) > 0)
28910 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
28911 secs
= XFASTINT (tem
);
28912 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
28915 secs
= DEFAULT_HOURGLASS_DELAY
;
28917 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
28918 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
28919 show_hourglass
, NULL
);
28924 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
28927 cancel_hourglass (void)
28929 #if defined (HAVE_WINDOW_SYSTEM)
28930 if (hourglass_atimer
)
28932 cancel_atimer (hourglass_atimer
);
28933 hourglass_atimer
= NULL
;
28936 if (hourglass_shown_p
)
28940 #endif /* ! WINDOWSNT */