1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2011 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 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 is a space or tab
387 character. This is used to determine word wrapping. */
389 #define IT_DISPLAYING_WHITESPACE(it) \
390 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
392 /* Name of the face used to highlight trailing whitespace. */
394 static Lisp_Object Qtrailing_whitespace
;
396 /* Name and number of the face used to highlight escape glyphs. */
398 static Lisp_Object Qescape_glyph
;
400 /* Name and number of the face used to highlight non-breaking spaces. */
402 static Lisp_Object Qnobreak_space
;
404 /* The symbol `image' which is the car of the lists used to represent
405 images in Lisp. Also a tool bar style. */
409 /* The image map types. */
411 static Lisp_Object QCpointer
;
412 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
414 /* Tool bar styles */
415 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
417 /* Non-zero means print newline to stdout before next mini-buffer
420 int noninteractive_need_newline
;
422 /* Non-zero means print newline to message log before next message. */
424 static int message_log_need_newline
;
426 /* Three markers that message_dolog uses.
427 It could allocate them itself, but that causes trouble
428 in handling memory-full errors. */
429 static Lisp_Object message_dolog_marker1
;
430 static Lisp_Object message_dolog_marker2
;
431 static Lisp_Object message_dolog_marker3
;
433 /* The buffer position of the first character appearing entirely or
434 partially on the line of the selected window which contains the
435 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
436 redisplay optimization in redisplay_internal. */
438 static struct text_pos this_line_start_pos
;
440 /* Number of characters past the end of the line above, including the
441 terminating newline. */
443 static struct text_pos this_line_end_pos
;
445 /* The vertical positions and the height of this line. */
447 static int this_line_vpos
;
448 static int this_line_y
;
449 static int this_line_pixel_height
;
451 /* X position at which this display line starts. Usually zero;
452 negative if first character is partially visible. */
454 static int this_line_start_x
;
456 /* The smallest character position seen by move_it_* functions as they
457 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
458 hscrolled lines, see display_line. */
460 static struct text_pos this_line_min_pos
;
462 /* Buffer that this_line_.* variables are referring to. */
464 static struct buffer
*this_line_buffer
;
467 /* Values of those variables at last redisplay are stored as
468 properties on `overlay-arrow-position' symbol. However, if
469 Voverlay_arrow_position is a marker, last-arrow-position is its
470 numerical position. */
472 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
474 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
475 properties on a symbol in overlay-arrow-variable-list. */
477 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
479 Lisp_Object Qmenu_bar_update_hook
;
481 /* Nonzero if an overlay arrow has been displayed in this window. */
483 static int overlay_arrow_seen
;
485 /* Number of windows showing the buffer of the selected window (or
486 another buffer with the same base buffer). keyboard.c refers to
491 /* Vector containing glyphs for an ellipsis `...'. */
493 static Lisp_Object default_invis_vector
[3];
495 /* This is the window where the echo area message was displayed. It
496 is always a mini-buffer window, but it may not be the same window
497 currently active as a mini-buffer. */
499 Lisp_Object echo_area_window
;
501 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
502 pushes the current message and the value of
503 message_enable_multibyte on the stack, the function restore_message
504 pops the stack and displays MESSAGE again. */
506 static Lisp_Object Vmessage_stack
;
508 /* Nonzero means multibyte characters were enabled when the echo area
509 message was specified. */
511 static int message_enable_multibyte
;
513 /* Nonzero if we should redraw the mode lines on the next redisplay. */
515 int update_mode_lines
;
517 /* Nonzero if window sizes or contents have changed since last
518 redisplay that finished. */
520 int windows_or_buffers_changed
;
522 /* Nonzero means a frame's cursor type has been changed. */
524 int cursor_type_changed
;
526 /* Nonzero after display_mode_line if %l was used and it displayed a
529 static int line_number_displayed
;
531 /* The name of the *Messages* buffer, a string. */
533 static Lisp_Object Vmessages_buffer_name
;
535 /* Current, index 0, and last displayed echo area message. Either
536 buffers from echo_buffers, or nil to indicate no message. */
538 Lisp_Object echo_area_buffer
[2];
540 /* The buffers referenced from echo_area_buffer. */
542 static Lisp_Object echo_buffer
[2];
544 /* A vector saved used in with_area_buffer to reduce consing. */
546 static Lisp_Object Vwith_echo_area_save_vector
;
548 /* Non-zero means display_echo_area should display the last echo area
549 message again. Set by redisplay_preserve_echo_area. */
551 static int display_last_displayed_message_p
;
553 /* Nonzero if echo area is being used by print; zero if being used by
556 static int message_buf_print
;
558 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
560 static Lisp_Object Qinhibit_menubar_update
;
561 static Lisp_Object Qmessage_truncate_lines
;
563 /* Set to 1 in clear_message to make redisplay_internal aware
564 of an emptied echo area. */
566 static int message_cleared_p
;
568 /* A scratch glyph row with contents used for generating truncation
569 glyphs. Also used in direct_output_for_insert. */
571 #define MAX_SCRATCH_GLYPHS 100
572 static struct glyph_row scratch_glyph_row
;
573 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
575 /* Ascent and height of the last line processed by move_it_to. */
577 static int last_max_ascent
, last_height
;
579 /* Non-zero if there's a help-echo in the echo area. */
581 int help_echo_showing_p
;
583 /* If >= 0, computed, exact values of mode-line and header-line height
584 to use in the macros CURRENT_MODE_LINE_HEIGHT and
585 CURRENT_HEADER_LINE_HEIGHT. */
587 int current_mode_line_height
, current_header_line_height
;
589 /* The maximum distance to look ahead for text properties. Values
590 that are too small let us call compute_char_face and similar
591 functions too often which is expensive. Values that are too large
592 let us call compute_char_face and alike too often because we
593 might not be interested in text properties that far away. */
595 #define TEXT_PROP_DISTANCE_LIMIT 100
599 /* Non-zero means print traces of redisplay if compiled with
602 int trace_redisplay_p
;
604 #endif /* GLYPH_DEBUG */
606 #ifdef DEBUG_TRACE_MOVE
607 /* Non-zero means trace with TRACE_MOVE to stderr. */
610 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
612 #define TRACE_MOVE(x) (void) 0
615 static Lisp_Object Qauto_hscroll_mode
;
617 /* Buffer being redisplayed -- for redisplay_window_error. */
619 static struct buffer
*displayed_buffer
;
621 /* Value returned from text property handlers (see below). */
626 HANDLED_RECOMPUTE_PROPS
,
627 HANDLED_OVERLAY_STRING_CONSUMED
,
631 /* A description of text properties that redisplay is interested
636 /* The name of the property. */
639 /* A unique index for the property. */
642 /* A handler function called to set up iterator IT from the property
643 at IT's current position. Value is used to steer handle_stop. */
644 enum prop_handled (*handler
) (struct it
*it
);
647 static enum prop_handled
handle_face_prop (struct it
*);
648 static enum prop_handled
handle_invisible_prop (struct it
*);
649 static enum prop_handled
handle_display_prop (struct it
*);
650 static enum prop_handled
handle_composition_prop (struct it
*);
651 static enum prop_handled
handle_overlay_change (struct it
*);
652 static enum prop_handled
handle_fontified_prop (struct it
*);
654 /* Properties handled by iterators. */
656 static struct props it_props
[] =
658 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
659 /* Handle `face' before `display' because some sub-properties of
660 `display' need to know the face. */
661 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
662 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
663 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
664 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
668 /* Value is the position described by X. If X is a marker, value is
669 the marker_position of X. Otherwise, value is X. */
671 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
673 /* Enumeration returned by some move_it_.* functions internally. */
677 /* Not used. Undefined value. */
680 /* Move ended at the requested buffer position or ZV. */
681 MOVE_POS_MATCH_OR_ZV
,
683 /* Move ended at the requested X pixel position. */
686 /* Move within a line ended at the end of a line that must be
690 /* Move within a line ended at the end of a line that would
691 be displayed truncated. */
694 /* Move within a line ended at a line end. */
698 /* This counter is used to clear the face cache every once in a while
699 in redisplay_internal. It is incremented for each redisplay.
700 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
703 #define CLEAR_FACE_CACHE_COUNT 500
704 static int clear_face_cache_count
;
706 /* Similarly for the image cache. */
708 #ifdef HAVE_WINDOW_SYSTEM
709 #define CLEAR_IMAGE_CACHE_COUNT 101
710 static int clear_image_cache_count
;
712 /* Null glyph slice */
713 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
716 /* Non-zero while redisplay_internal is in progress. */
720 static Lisp_Object Qinhibit_free_realized_faces
;
722 /* If a string, XTread_socket generates an event to display that string.
723 (The display is done in read_char.) */
725 Lisp_Object help_echo_string
;
726 Lisp_Object help_echo_window
;
727 Lisp_Object help_echo_object
;
728 EMACS_INT help_echo_pos
;
730 /* Temporary variable for XTread_socket. */
732 Lisp_Object previous_help_echo_string
;
734 /* Platform-independent portion of hourglass implementation. */
736 /* Non-zero means an hourglass cursor is currently shown. */
737 int hourglass_shown_p
;
739 /* If non-null, an asynchronous timer that, when it expires, displays
740 an hourglass cursor on all frames. */
741 struct atimer
*hourglass_atimer
;
743 /* Name of the face used to display glyphless characters. */
744 Lisp_Object Qglyphless_char
;
746 /* Symbol for the purpose of Vglyphless_char_display. */
747 static Lisp_Object Qglyphless_char_display
;
749 /* Method symbols for Vglyphless_char_display. */
750 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
752 /* Default pixel width of `thin-space' display method. */
753 #define THIN_SPACE_WIDTH 1
755 /* Default number of seconds to wait before displaying an hourglass
757 #define DEFAULT_HOURGLASS_DELAY 1
760 /* Function prototypes. */
762 static void setup_for_ellipsis (struct it
*, int);
763 static void set_iterator_to_next (struct it
*, int);
764 static void mark_window_display_accurate_1 (struct window
*, int);
765 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
766 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
767 static int cursor_row_p (struct glyph_row
*);
768 static int redisplay_mode_lines (Lisp_Object
, int);
769 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
771 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
773 static void handle_line_prefix (struct it
*);
775 static void pint2str (char *, int, EMACS_INT
);
776 static void pint2hrstr (char *, int, EMACS_INT
);
777 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
779 static void reconsider_clip_changes (struct window
*, struct buffer
*);
780 static int text_outside_line_unchanged_p (struct window
*,
781 EMACS_INT
, EMACS_INT
);
782 static void store_mode_line_noprop_char (char);
783 static int store_mode_line_noprop (const char *, int, int);
784 static void handle_stop (struct it
*);
785 static void handle_stop_backwards (struct it
*, EMACS_INT
);
786 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
787 static void ensure_echo_area_buffers (void);
788 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
789 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
790 static int with_echo_area_buffer (struct window
*, int,
791 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
792 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
793 static void clear_garbaged_frames (void);
794 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
795 static void pop_message (void);
796 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
797 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
798 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
799 static int display_echo_area (struct window
*);
800 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
801 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
802 static Lisp_Object
unwind_redisplay (Lisp_Object
);
803 static int string_char_and_length (const unsigned char *, int *);
804 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
806 static int compute_window_start_on_continuation_line (struct window
*);
807 static Lisp_Object
safe_eval_handler (Lisp_Object
);
808 static void insert_left_trunc_glyphs (struct it
*);
809 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
811 static void extend_face_to_end_of_line (struct it
*);
812 static int append_space_for_newline (struct it
*, int);
813 static int cursor_row_fully_visible_p (struct window
*, int, int);
814 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
815 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
816 static int trailing_whitespace_p (EMACS_INT
);
817 static unsigned long int message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
818 static void push_it (struct it
*, struct text_pos
*);
819 static void pop_it (struct it
*);
820 static void sync_frame_with_window_matrix_rows (struct window
*);
821 static void select_frame_for_redisplay (Lisp_Object
);
822 static void redisplay_internal (void);
823 static int echo_area_display (int);
824 static void redisplay_windows (Lisp_Object
);
825 static void redisplay_window (Lisp_Object
, int);
826 static Lisp_Object
redisplay_window_error (Lisp_Object
);
827 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
828 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
829 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
830 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
832 static int update_menu_bar (struct frame
*, int, int);
833 static int try_window_reusing_current_matrix (struct window
*);
834 static int try_window_id (struct window
*);
835 static int display_line (struct it
*);
836 static int display_mode_lines (struct window
*);
837 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
838 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
839 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
840 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
841 static void display_menu_bar (struct window
*);
842 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
844 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
845 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
846 static void compute_line_metrics (struct it
*);
847 static void run_redisplay_end_trigger_hook (struct it
*);
848 static int get_overlay_strings (struct it
*, EMACS_INT
);
849 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
850 static void next_overlay_string (struct it
*);
851 static void reseat (struct it
*, struct text_pos
, int);
852 static void reseat_1 (struct it
*, struct text_pos
, int);
853 static void back_to_previous_visible_line_start (struct it
*);
854 void reseat_at_previous_visible_line_start (struct it
*);
855 static void reseat_at_next_visible_line_start (struct it
*, int);
856 static int next_element_from_ellipsis (struct it
*);
857 static int next_element_from_display_vector (struct it
*);
858 static int next_element_from_string (struct it
*);
859 static int next_element_from_c_string (struct it
*);
860 static int next_element_from_buffer (struct it
*);
861 static int next_element_from_composition (struct it
*);
862 static int next_element_from_image (struct it
*);
863 static int next_element_from_stretch (struct it
*);
864 static void load_overlay_strings (struct it
*, EMACS_INT
);
865 static int init_from_display_pos (struct it
*, struct window
*,
866 struct display_pos
*);
867 static void reseat_to_string (struct it
*, const char *,
868 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
869 static int get_next_display_element (struct it
*);
870 static enum move_it_result
871 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
872 enum move_operation_enum
);
873 void move_it_vertically_backward (struct it
*, int);
874 static void init_to_row_start (struct it
*, struct window
*,
876 static int init_to_row_end (struct it
*, struct window
*,
878 static void back_to_previous_line_start (struct it
*);
879 static int forward_to_next_line_start (struct it
*, int *);
880 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
881 Lisp_Object
, EMACS_INT
);
882 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
883 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
884 static EMACS_INT
number_of_chars (const char *, int);
885 static void compute_stop_pos (struct it
*);
886 static void compute_string_pos (struct text_pos
*, struct text_pos
,
888 static int face_before_or_after_it_pos (struct it
*, int);
889 static EMACS_INT
next_overlay_change (EMACS_INT
);
890 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
891 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
892 static int handle_single_display_spec (struct it
*, Lisp_Object
,
893 Lisp_Object
, Lisp_Object
,
894 struct text_pos
*, EMACS_INT
, int, int);
895 static int underlying_face_id (struct it
*);
896 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
899 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
900 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
902 #ifdef HAVE_WINDOW_SYSTEM
904 static void x_consider_frame_title (Lisp_Object
);
905 static int tool_bar_lines_needed (struct frame
*, int *);
906 static void update_tool_bar (struct frame
*, int);
907 static void build_desired_tool_bar_string (struct frame
*f
);
908 static int redisplay_tool_bar (struct frame
*);
909 static void display_tool_bar_line (struct it
*, int);
910 static void notice_overwritten_cursor (struct window
*,
913 static void append_stretch_glyph (struct it
*, Lisp_Object
,
917 #endif /* HAVE_WINDOW_SYSTEM */
919 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
920 static int coords_in_mouse_face_p (struct window
*, int, int);
924 /***********************************************************************
925 Window display dimensions
926 ***********************************************************************/
928 /* Return the bottom boundary y-position for text lines in window W.
929 This is the first y position at which a line cannot start.
930 It is relative to the top of the window.
932 This is the height of W minus the height of a mode line, if any. */
935 window_text_bottom_y (struct window
*w
)
937 int height
= WINDOW_TOTAL_HEIGHT (w
);
939 if (WINDOW_WANTS_MODELINE_P (w
))
940 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
944 /* Return the pixel width of display area AREA of window W. AREA < 0
945 means return the total width of W, not including fringes to
946 the left and right of the window. */
949 window_box_width (struct window
*w
, int area
)
951 int cols
= XFASTINT (w
->total_cols
);
954 if (!w
->pseudo_window_p
)
956 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
958 if (area
== TEXT_AREA
)
960 if (INTEGERP (w
->left_margin_cols
))
961 cols
-= XFASTINT (w
->left_margin_cols
);
962 if (INTEGERP (w
->right_margin_cols
))
963 cols
-= XFASTINT (w
->right_margin_cols
);
964 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
966 else if (area
== LEFT_MARGIN_AREA
)
968 cols
= (INTEGERP (w
->left_margin_cols
)
969 ? XFASTINT (w
->left_margin_cols
) : 0);
972 else if (area
== RIGHT_MARGIN_AREA
)
974 cols
= (INTEGERP (w
->right_margin_cols
)
975 ? XFASTINT (w
->right_margin_cols
) : 0);
980 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
984 /* Return the pixel height of the display area of window W, not
985 including mode lines of W, if any. */
988 window_box_height (struct window
*w
)
990 struct frame
*f
= XFRAME (w
->frame
);
991 int height
= WINDOW_TOTAL_HEIGHT (w
);
993 xassert (height
>= 0);
995 /* Note: the code below that determines the mode-line/header-line
996 height is essentially the same as that contained in the macro
997 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
998 the appropriate glyph row has its `mode_line_p' flag set,
999 and if it doesn't, uses estimate_mode_line_height instead. */
1001 if (WINDOW_WANTS_MODELINE_P (w
))
1003 struct glyph_row
*ml_row
1004 = (w
->current_matrix
&& w
->current_matrix
->rows
1005 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1007 if (ml_row
&& ml_row
->mode_line_p
)
1008 height
-= ml_row
->height
;
1010 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1013 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1015 struct glyph_row
*hl_row
1016 = (w
->current_matrix
&& w
->current_matrix
->rows
1017 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1019 if (hl_row
&& hl_row
->mode_line_p
)
1020 height
-= hl_row
->height
;
1022 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1025 /* With a very small font and a mode-line that's taller than
1026 default, we might end up with a negative height. */
1027 return max (0, height
);
1030 /* Return the window-relative coordinate of the left edge of display
1031 area AREA of window W. AREA < 0 means return the left edge of the
1032 whole window, to the right of the left fringe of W. */
1035 window_box_left_offset (struct window
*w
, int area
)
1039 if (w
->pseudo_window_p
)
1042 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1044 if (area
== TEXT_AREA
)
1045 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1046 + window_box_width (w
, LEFT_MARGIN_AREA
));
1047 else if (area
== RIGHT_MARGIN_AREA
)
1048 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1049 + window_box_width (w
, LEFT_MARGIN_AREA
)
1050 + window_box_width (w
, TEXT_AREA
)
1051 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1053 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1054 else if (area
== LEFT_MARGIN_AREA
1055 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1056 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1062 /* Return the window-relative coordinate of the right edge of display
1063 area AREA of window W. AREA < 0 means return the right edge of the
1064 whole window, to the left of the right fringe of W. */
1067 window_box_right_offset (struct window
*w
, int area
)
1069 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1072 /* Return the frame-relative coordinate of the left edge of display
1073 area AREA of window W. AREA < 0 means return the left edge of the
1074 whole window, to the right of the left fringe of W. */
1077 window_box_left (struct window
*w
, int area
)
1079 struct frame
*f
= XFRAME (w
->frame
);
1082 if (w
->pseudo_window_p
)
1083 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1085 x
= (WINDOW_LEFT_EDGE_X (w
)
1086 + window_box_left_offset (w
, area
));
1092 /* Return the frame-relative coordinate of the right edge of display
1093 area AREA of window W. AREA < 0 means return the right edge of the
1094 whole window, to the left of the right fringe of W. */
1097 window_box_right (struct window
*w
, int area
)
1099 return window_box_left (w
, area
) + window_box_width (w
, area
);
1102 /* Get the bounding box of the display area AREA of window W, without
1103 mode lines, in frame-relative coordinates. AREA < 0 means the
1104 whole window, not including the left and right fringes of
1105 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1106 coordinates of the upper-left corner of the box. Return in
1107 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1110 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1111 int *box_width
, int *box_height
)
1114 *box_width
= window_box_width (w
, area
);
1116 *box_height
= window_box_height (w
);
1118 *box_x
= window_box_left (w
, area
);
1121 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1122 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1123 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1128 /* Get the bounding box of the display area AREA of window W, without
1129 mode lines. AREA < 0 means the whole window, not including the
1130 left and right fringe of the window. Return in *TOP_LEFT_X
1131 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1132 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1133 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1137 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1138 int *bottom_right_x
, int *bottom_right_y
)
1140 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1142 *bottom_right_x
+= *top_left_x
;
1143 *bottom_right_y
+= *top_left_y
;
1148 /***********************************************************************
1150 ***********************************************************************/
1152 /* Return the bottom y-position of the line the iterator IT is in.
1153 This can modify IT's settings. */
1156 line_bottom_y (struct it
*it
)
1158 int line_height
= it
->max_ascent
+ it
->max_descent
;
1159 int line_top_y
= it
->current_y
;
1161 if (line_height
== 0)
1164 line_height
= last_height
;
1165 else if (IT_CHARPOS (*it
) < ZV
)
1167 move_it_by_lines (it
, 1);
1168 line_height
= (it
->max_ascent
|| it
->max_descent
1169 ? it
->max_ascent
+ it
->max_descent
1174 struct glyph_row
*row
= it
->glyph_row
;
1176 /* Use the default character height. */
1177 it
->glyph_row
= NULL
;
1178 it
->what
= IT_CHARACTER
;
1181 PRODUCE_GLYPHS (it
);
1182 line_height
= it
->ascent
+ it
->descent
;
1183 it
->glyph_row
= row
;
1187 return line_top_y
+ line_height
;
1191 /* Return 1 if position CHARPOS is visible in window W.
1192 CHARPOS < 0 means return info about WINDOW_END position.
1193 If visible, set *X and *Y to pixel coordinates of top left corner.
1194 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1195 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1198 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1199 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1202 struct text_pos top
;
1204 struct buffer
*old_buffer
= NULL
;
1206 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1209 if (XBUFFER (w
->buffer
) != current_buffer
)
1211 old_buffer
= current_buffer
;
1212 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1215 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1217 /* Compute exact mode line heights. */
1218 if (WINDOW_WANTS_MODELINE_P (w
))
1219 current_mode_line_height
1220 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1221 BVAR (current_buffer
, mode_line_format
));
1223 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1224 current_header_line_height
1225 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1226 BVAR (current_buffer
, header_line_format
));
1228 start_display (&it
, w
, top
);
1229 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1230 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1232 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1234 /* We have reached CHARPOS, or passed it. How the call to
1235 move_it_to can overshoot: (i) If CHARPOS is on invisible
1236 text, move_it_to stops at the end of the invisible text,
1237 after CHARPOS. (ii) If CHARPOS is in a display vector,
1238 move_it_to stops on its last glyph. */
1239 int top_x
= it
.current_x
;
1240 int top_y
= it
.current_y
;
1241 enum it_method it_method
= it
.method
;
1242 /* Calling line_bottom_y may change it.method, it.position, etc. */
1243 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1244 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1246 if (top_y
< window_top_y
)
1247 visible_p
= bottom_y
> window_top_y
;
1248 else if (top_y
< it
.last_visible_y
)
1252 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1254 /* We stopped on the last glyph of a display vector.
1255 Try and recompute. Hack alert! */
1256 if (charpos
< 2 || top
.charpos
>= charpos
)
1257 top_x
= it
.glyph_row
->x
;
1261 start_display (&it2
, w
, top
);
1262 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1263 get_next_display_element (&it2
);
1264 PRODUCE_GLYPHS (&it2
);
1265 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1266 || it2
.current_x
> it2
.last_visible_x
)
1267 top_x
= it
.glyph_row
->x
;
1270 top_x
= it2
.current_x
;
1271 top_y
= it2
.current_y
;
1277 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1278 *rtop
= max (0, window_top_y
- top_y
);
1279 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1280 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1281 - max (top_y
, window_top_y
)));
1290 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1291 move_it_by_lines (&it
, 1);
1292 if (charpos
< IT_CHARPOS (it
)
1293 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1296 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1298 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1299 *rtop
= max (0, -it2
.current_y
);
1300 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1301 - it
.last_visible_y
));
1302 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1304 - max (it2
.current_y
,
1305 WINDOW_HEADER_LINE_HEIGHT (w
))));
1311 set_buffer_internal_1 (old_buffer
);
1313 current_header_line_height
= current_mode_line_height
= -1;
1315 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1316 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1319 /* Debugging code. */
1321 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1322 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1324 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1331 /* Return the next character from STR. Return in *LEN the length of
1332 the character. This is like STRING_CHAR_AND_LENGTH but never
1333 returns an invalid character. If we find one, we return a `?', but
1334 with the length of the invalid character. */
1337 string_char_and_length (const unsigned char *str
, int *len
)
1341 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1342 if (!CHAR_VALID_P (c
, 1))
1343 /* We may not change the length here because other places in Emacs
1344 don't use this function, i.e. they silently accept invalid
1353 /* Given a position POS containing a valid character and byte position
1354 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1356 static struct text_pos
1357 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1359 xassert (STRINGP (string
) && nchars
>= 0);
1361 if (STRING_MULTIBYTE (string
))
1363 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1368 string_char_and_length (p
, &len
);
1371 BYTEPOS (pos
) += len
;
1375 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1381 /* Value is the text position, i.e. character and byte position,
1382 for character position CHARPOS in STRING. */
1384 static INLINE
struct text_pos
1385 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1387 struct text_pos pos
;
1388 xassert (STRINGP (string
));
1389 xassert (charpos
>= 0);
1390 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1395 /* Value is a text position, i.e. character and byte position, for
1396 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1397 means recognize multibyte characters. */
1399 static struct text_pos
1400 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1402 struct text_pos pos
;
1404 xassert (s
!= NULL
);
1405 xassert (charpos
>= 0);
1411 SET_TEXT_POS (pos
, 0, 0);
1414 string_char_and_length ((const unsigned char *) s
, &len
);
1417 BYTEPOS (pos
) += len
;
1421 SET_TEXT_POS (pos
, charpos
, charpos
);
1427 /* Value is the number of characters in C string S. MULTIBYTE_P
1428 non-zero means recognize multibyte characters. */
1431 number_of_chars (const char *s
, int multibyte_p
)
1437 EMACS_INT rest
= strlen (s
);
1439 const unsigned char *p
= (const unsigned char *) s
;
1441 for (nchars
= 0; rest
> 0; ++nchars
)
1443 string_char_and_length (p
, &len
);
1444 rest
-= len
, p
+= len
;
1448 nchars
= strlen (s
);
1454 /* Compute byte position NEWPOS->bytepos corresponding to
1455 NEWPOS->charpos. POS is a known position in string STRING.
1456 NEWPOS->charpos must be >= POS.charpos. */
1459 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1461 xassert (STRINGP (string
));
1462 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1464 if (STRING_MULTIBYTE (string
))
1465 *newpos
= string_pos_nchars_ahead (pos
, string
,
1466 CHARPOS (*newpos
) - CHARPOS (pos
));
1468 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1472 Return an estimation of the pixel height of mode or header lines on
1473 frame F. FACE_ID specifies what line's height to estimate. */
1476 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1478 #ifdef HAVE_WINDOW_SYSTEM
1479 if (FRAME_WINDOW_P (f
))
1481 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1483 /* This function is called so early when Emacs starts that the face
1484 cache and mode line face are not yet initialized. */
1485 if (FRAME_FACE_CACHE (f
))
1487 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1491 height
= FONT_HEIGHT (face
->font
);
1492 if (face
->box_line_width
> 0)
1493 height
+= 2 * face
->box_line_width
;
1504 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1505 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1506 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1507 not force the value into range. */
1510 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1511 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1514 #ifdef HAVE_WINDOW_SYSTEM
1515 if (FRAME_WINDOW_P (f
))
1517 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1518 even for negative values. */
1520 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1522 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1524 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1525 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1528 STORE_NATIVE_RECT (*bounds
,
1529 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1530 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1531 FRAME_COLUMN_WIDTH (f
) - 1,
1532 FRAME_LINE_HEIGHT (f
) - 1);
1538 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1539 pix_x
= FRAME_TOTAL_COLS (f
);
1543 else if (pix_y
> FRAME_LINES (f
))
1544 pix_y
= FRAME_LINES (f
);
1554 /* Find the glyph under window-relative coordinates X/Y in window W.
1555 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1556 strings. Return in *HPOS and *VPOS the row and column number of
1557 the glyph found. Return in *AREA the glyph area containing X.
1558 Value is a pointer to the glyph found or null if X/Y is not on
1559 text, or we can't tell because W's current matrix is not up to
1564 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1565 int *dx
, int *dy
, int *area
)
1567 struct glyph
*glyph
, *end
;
1568 struct glyph_row
*row
= NULL
;
1571 /* Find row containing Y. Give up if some row is not enabled. */
1572 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1574 row
= MATRIX_ROW (w
->current_matrix
, i
);
1575 if (!row
->enabled_p
)
1577 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1584 /* Give up if Y is not in the window. */
1585 if (i
== w
->current_matrix
->nrows
)
1588 /* Get the glyph area containing X. */
1589 if (w
->pseudo_window_p
)
1596 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1598 *area
= LEFT_MARGIN_AREA
;
1599 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1601 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1604 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1608 *area
= RIGHT_MARGIN_AREA
;
1609 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1613 /* Find glyph containing X. */
1614 glyph
= row
->glyphs
[*area
];
1615 end
= glyph
+ row
->used
[*area
];
1617 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1619 x
-= glyph
->pixel_width
;
1629 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1632 *hpos
= glyph
- row
->glyphs
[*area
];
1636 /* Convert frame-relative x/y to coordinates relative to window W.
1637 Takes pseudo-windows into account. */
1640 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1642 if (w
->pseudo_window_p
)
1644 /* A pseudo-window is always full-width, and starts at the
1645 left edge of the frame, plus a frame border. */
1646 struct frame
*f
= XFRAME (w
->frame
);
1647 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1648 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1652 *x
-= WINDOW_LEFT_EDGE_X (w
);
1653 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1657 #ifdef HAVE_WINDOW_SYSTEM
1660 Return in RECTS[] at most N clipping rectangles for glyph string S.
1661 Return the number of stored rectangles. */
1664 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1671 if (s
->row
->full_width_p
)
1673 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1674 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1675 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1677 /* Unless displaying a mode or menu bar line, which are always
1678 fully visible, clip to the visible part of the row. */
1679 if (s
->w
->pseudo_window_p
)
1680 r
.height
= s
->row
->visible_height
;
1682 r
.height
= s
->height
;
1686 /* This is a text line that may be partially visible. */
1687 r
.x
= window_box_left (s
->w
, s
->area
);
1688 r
.width
= window_box_width (s
->w
, s
->area
);
1689 r
.height
= s
->row
->visible_height
;
1693 if (r
.x
< s
->clip_head
->x
)
1695 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1696 r
.width
-= s
->clip_head
->x
- r
.x
;
1699 r
.x
= s
->clip_head
->x
;
1702 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1704 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1705 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1710 /* If S draws overlapping rows, it's sufficient to use the top and
1711 bottom of the window for clipping because this glyph string
1712 intentionally draws over other lines. */
1713 if (s
->for_overlaps
)
1715 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1716 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1718 /* Alas, the above simple strategy does not work for the
1719 environments with anti-aliased text: if the same text is
1720 drawn onto the same place multiple times, it gets thicker.
1721 If the overlap we are processing is for the erased cursor, we
1722 take the intersection with the rectagle of the cursor. */
1723 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1725 XRectangle rc
, r_save
= r
;
1727 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1728 rc
.y
= s
->w
->phys_cursor
.y
;
1729 rc
.width
= s
->w
->phys_cursor_width
;
1730 rc
.height
= s
->w
->phys_cursor_height
;
1732 x_intersect_rectangles (&r_save
, &rc
, &r
);
1737 /* Don't use S->y for clipping because it doesn't take partially
1738 visible lines into account. For example, it can be negative for
1739 partially visible lines at the top of a window. */
1740 if (!s
->row
->full_width_p
1741 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1742 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1744 r
.y
= max (0, s
->row
->y
);
1747 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1749 /* If drawing the cursor, don't let glyph draw outside its
1750 advertised boundaries. Cleartype does this under some circumstances. */
1751 if (s
->hl
== DRAW_CURSOR
)
1753 struct glyph
*glyph
= s
->first_glyph
;
1758 r
.width
-= s
->x
- r
.x
;
1761 r
.width
= min (r
.width
, glyph
->pixel_width
);
1763 /* If r.y is below window bottom, ensure that we still see a cursor. */
1764 height
= min (glyph
->ascent
+ glyph
->descent
,
1765 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1766 max_y
= window_text_bottom_y (s
->w
) - height
;
1767 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1768 if (s
->ybase
- glyph
->ascent
> max_y
)
1775 /* Don't draw cursor glyph taller than our actual glyph. */
1776 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1777 if (height
< r
.height
)
1779 max_y
= r
.y
+ r
.height
;
1780 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1781 r
.height
= min (max_y
- r
.y
, height
);
1788 XRectangle r_save
= r
;
1790 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1794 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1795 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1797 #ifdef CONVERT_FROM_XRECT
1798 CONVERT_FROM_XRECT (r
, *rects
);
1806 /* If we are processing overlapping and allowed to return
1807 multiple clipping rectangles, we exclude the row of the glyph
1808 string from the clipping rectangle. This is to avoid drawing
1809 the same text on the environment with anti-aliasing. */
1810 #ifdef CONVERT_FROM_XRECT
1813 XRectangle
*rs
= rects
;
1815 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1817 if (s
->for_overlaps
& OVERLAPS_PRED
)
1820 if (r
.y
+ r
.height
> row_y
)
1823 rs
[i
].height
= row_y
- r
.y
;
1829 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1832 if (r
.y
< row_y
+ s
->row
->visible_height
)
1834 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1836 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1837 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1846 #ifdef CONVERT_FROM_XRECT
1847 for (i
= 0; i
< n
; i
++)
1848 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1855 Return in *NR the clipping rectangle for glyph string S. */
1858 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
1860 get_glyph_string_clip_rects (s
, nr
, 1);
1865 Return the position and height of the phys cursor in window W.
1866 Set w->phys_cursor_width to width of phys cursor.
1870 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
1871 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
1873 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1874 int x
, y
, wd
, h
, h0
, y0
;
1876 /* Compute the width of the rectangle to draw. If on a stretch
1877 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1878 rectangle as wide as the glyph, but use a canonical character
1880 wd
= glyph
->pixel_width
- 1;
1881 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
1885 x
= w
->phys_cursor
.x
;
1892 if (glyph
->type
== STRETCH_GLYPH
1893 && !x_stretch_cursor_p
)
1894 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1895 w
->phys_cursor_width
= wd
;
1897 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1899 /* If y is below window bottom, ensure that we still see a cursor. */
1900 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1902 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1903 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1905 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1908 h
= max (h
- (y0
- y
) + 1, h0
);
1913 y0
= window_text_bottom_y (w
) - h0
;
1921 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
1922 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1927 * Remember which glyph the mouse is over.
1931 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
1935 struct glyph_row
*r
, *gr
, *end_row
;
1936 enum window_part part
;
1937 enum glyph_row_area area
;
1938 int x
, y
, width
, height
;
1940 /* Try to determine frame pixel position and size of the glyph under
1941 frame pixel coordinates X/Y on frame F. */
1943 if (!f
->glyphs_initialized_p
1944 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
1947 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1948 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1952 w
= XWINDOW (window
);
1953 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
1954 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
1956 x
= window_relative_x_coord (w
, part
, gx
);
1957 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
1959 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1960 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1962 if (w
->pseudo_window_p
)
1965 part
= ON_MODE_LINE
; /* Don't adjust margin. */
1971 case ON_LEFT_MARGIN
:
1972 area
= LEFT_MARGIN_AREA
;
1975 case ON_RIGHT_MARGIN
:
1976 area
= RIGHT_MARGIN_AREA
;
1979 case ON_HEADER_LINE
:
1981 gr
= (part
== ON_HEADER_LINE
1982 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1983 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
1986 goto text_glyph_row_found
;
1993 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
1994 if (r
->y
+ r
->height
> y
)
2000 text_glyph_row_found
:
2003 struct glyph
*g
= gr
->glyphs
[area
];
2004 struct glyph
*end
= g
+ gr
->used
[area
];
2006 height
= gr
->height
;
2007 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2008 if (gx
+ g
->pixel_width
> x
)
2013 if (g
->type
== IMAGE_GLYPH
)
2015 /* Don't remember when mouse is over image, as
2016 image may have hot-spots. */
2017 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2020 width
= g
->pixel_width
;
2024 /* Use nominal char spacing at end of line. */
2026 gx
+= (x
/ width
) * width
;
2029 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2030 gx
+= window_box_left_offset (w
, area
);
2034 /* Use nominal line height at end of window. */
2035 gx
= (x
/ width
) * width
;
2037 gy
+= (y
/ height
) * height
;
2041 case ON_LEFT_FRINGE
:
2042 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2043 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2044 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2045 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2048 case ON_RIGHT_FRINGE
:
2049 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2050 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2051 : window_box_right_offset (w
, TEXT_AREA
));
2052 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2056 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2058 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2059 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2060 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2062 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2066 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2067 if (r
->y
+ r
->height
> y
)
2074 height
= gr
->height
;
2077 /* Use nominal line height at end of window. */
2079 gy
+= (y
/ height
) * height
;
2086 /* If there is no glyph under the mouse, then we divide the screen
2087 into a grid of the smallest glyph in the frame, and use that
2090 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2091 round down even for negative values. */
2097 gx
= (gx
/ width
) * width
;
2098 gy
= (gy
/ height
) * height
;
2103 gx
+= WINDOW_LEFT_EDGE_X (w
);
2104 gy
+= WINDOW_TOP_EDGE_Y (w
);
2107 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2109 /* Visible feedback for debugging. */
2112 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2113 f
->output_data
.x
->normal_gc
,
2114 gx
, gy
, width
, height
);
2120 #endif /* HAVE_WINDOW_SYSTEM */
2123 /***********************************************************************
2124 Lisp form evaluation
2125 ***********************************************************************/
2127 /* Error handler for safe_eval and safe_call. */
2130 safe_eval_handler (Lisp_Object arg
)
2132 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2137 /* Evaluate SEXPR and return the result, or nil if something went
2138 wrong. Prevent redisplay during the evaluation. */
2140 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2141 Return the result, or nil if something went wrong. Prevent
2142 redisplay during the evaluation. */
2145 safe_call (size_t nargs
, Lisp_Object
*args
)
2149 if (inhibit_eval_during_redisplay
)
2153 int count
= SPECPDL_INDEX ();
2154 struct gcpro gcpro1
;
2157 gcpro1
.nvars
= nargs
;
2158 specbind (Qinhibit_redisplay
, Qt
);
2159 /* Use Qt to ensure debugger does not run,
2160 so there is no possibility of wanting to redisplay. */
2161 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2164 val
= unbind_to (count
, val
);
2171 /* Call function FN with one argument ARG.
2172 Return the result, or nil if something went wrong. */
2175 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2177 Lisp_Object args
[2];
2180 return safe_call (2, args
);
2183 static Lisp_Object Qeval
;
2186 safe_eval (Lisp_Object sexpr
)
2188 return safe_call1 (Qeval
, sexpr
);
2191 /* Call function FN with one argument ARG.
2192 Return the result, or nil if something went wrong. */
2195 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2197 Lisp_Object args
[3];
2201 return safe_call (3, args
);
2206 /***********************************************************************
2208 ***********************************************************************/
2212 /* Define CHECK_IT to perform sanity checks on iterators.
2213 This is for debugging. It is too slow to do unconditionally. */
2219 if (it
->method
== GET_FROM_STRING
)
2221 xassert (STRINGP (it
->string
));
2222 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2226 xassert (IT_STRING_CHARPOS (*it
) < 0);
2227 if (it
->method
== GET_FROM_BUFFER
)
2229 /* Check that character and byte positions agree. */
2230 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2235 xassert (it
->current
.dpvec_index
>= 0);
2237 xassert (it
->current
.dpvec_index
< 0);
2240 #define CHECK_IT(IT) check_it ((IT))
2244 #define CHECK_IT(IT) (void) 0
2251 /* Check that the window end of window W is what we expect it
2252 to be---the last row in the current matrix displaying text. */
2255 check_window_end (w
)
2258 if (!MINI_WINDOW_P (w
)
2259 && !NILP (w
->window_end_valid
))
2261 struct glyph_row
*row
;
2262 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2263 XFASTINT (w
->window_end_vpos
)),
2265 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2266 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2270 #define CHECK_WINDOW_END(W) check_window_end ((W))
2272 #else /* not GLYPH_DEBUG */
2274 #define CHECK_WINDOW_END(W) (void) 0
2276 #endif /* not GLYPH_DEBUG */
2280 /***********************************************************************
2281 Iterator initialization
2282 ***********************************************************************/
2284 /* Initialize IT for displaying current_buffer in window W, starting
2285 at character position CHARPOS. CHARPOS < 0 means that no buffer
2286 position is specified which is useful when the iterator is assigned
2287 a position later. BYTEPOS is the byte position corresponding to
2288 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2290 If ROW is not null, calls to produce_glyphs with IT as parameter
2291 will produce glyphs in that row.
2293 BASE_FACE_ID is the id of a base face to use. It must be one of
2294 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2295 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2296 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2298 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2299 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2300 will be initialized to use the corresponding mode line glyph row of
2301 the desired matrix of W. */
2304 init_iterator (struct it
*it
, struct window
*w
,
2305 EMACS_INT charpos
, EMACS_INT bytepos
,
2306 struct glyph_row
*row
, enum face_id base_face_id
)
2308 int highlight_region_p
;
2309 enum face_id remapped_base_face_id
= base_face_id
;
2311 /* Some precondition checks. */
2312 xassert (w
!= NULL
&& it
!= NULL
);
2313 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2316 /* If face attributes have been changed since the last redisplay,
2317 free realized faces now because they depend on face definitions
2318 that might have changed. Don't free faces while there might be
2319 desired matrices pending which reference these faces. */
2320 if (face_change_count
&& !inhibit_free_realized_faces
)
2322 face_change_count
= 0;
2323 free_all_realized_faces (Qnil
);
2326 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2327 if (! NILP (Vface_remapping_alist
))
2328 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2330 /* Use one of the mode line rows of W's desired matrix if
2334 if (base_face_id
== MODE_LINE_FACE_ID
2335 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2336 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2337 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2338 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2342 memset (it
, 0, sizeof *it
);
2343 it
->current
.overlay_string_index
= -1;
2344 it
->current
.dpvec_index
= -1;
2345 it
->base_face_id
= remapped_base_face_id
;
2347 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2348 it
->paragraph_embedding
= L2R
;
2349 it
->bidi_it
.string
.lstring
= Qnil
;
2350 it
->bidi_it
.string
.s
= NULL
;
2351 it
->bidi_it
.string
.bufpos
= 0;
2353 /* The window in which we iterate over current_buffer: */
2354 XSETWINDOW (it
->window
, w
);
2356 it
->f
= XFRAME (w
->frame
);
2360 /* Extra space between lines (on window systems only). */
2361 if (base_face_id
== DEFAULT_FACE_ID
2362 && FRAME_WINDOW_P (it
->f
))
2364 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2365 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2366 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2367 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2368 * FRAME_LINE_HEIGHT (it
->f
));
2369 else if (it
->f
->extra_line_spacing
> 0)
2370 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2371 it
->max_extra_line_spacing
= 0;
2374 /* If realized faces have been removed, e.g. because of face
2375 attribute changes of named faces, recompute them. When running
2376 in batch mode, the face cache of the initial frame is null. If
2377 we happen to get called, make a dummy face cache. */
2378 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2379 init_frame_faces (it
->f
);
2380 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2381 recompute_basic_faces (it
->f
);
2383 /* Current value of the `slice', `space-width', and 'height' properties. */
2384 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2385 it
->space_width
= Qnil
;
2386 it
->font_height
= Qnil
;
2387 it
->override_ascent
= -1;
2389 /* Are control characters displayed as `^C'? */
2390 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2392 /* -1 means everything between a CR and the following line end
2393 is invisible. >0 means lines indented more than this value are
2395 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2396 ? XFASTINT (BVAR (current_buffer
, selective_display
))
2397 : (!NILP (BVAR (current_buffer
, selective_display
))
2399 it
->selective_display_ellipsis_p
2400 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2402 /* Display table to use. */
2403 it
->dp
= window_display_table (w
);
2405 /* Are multibyte characters enabled in current_buffer? */
2406 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2409 /* Bidirectional reordering of strings is controlled by the default
2410 value of bidi-display-reordering. For buffers, we reconsider
2413 !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
)) && it
->multibyte_p
;
2415 /* Non-zero if we should highlight the region. */
2417 = (!NILP (Vtransient_mark_mode
)
2418 && !NILP (BVAR (current_buffer
, mark_active
))
2419 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2421 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2422 start and end of a visible region in window IT->w. Set both to
2423 -1 to indicate no region. */
2424 if (highlight_region_p
2425 /* Maybe highlight only in selected window. */
2426 && (/* Either show region everywhere. */
2427 highlight_nonselected_windows
2428 /* Or show region in the selected window. */
2429 || w
== XWINDOW (selected_window
)
2430 /* Or show the region if we are in the mini-buffer and W is
2431 the window the mini-buffer refers to. */
2432 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2433 && WINDOWP (minibuf_selected_window
)
2434 && w
== XWINDOW (minibuf_selected_window
))))
2436 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2437 it
->region_beg_charpos
= min (PT
, markpos
);
2438 it
->region_end_charpos
= max (PT
, markpos
);
2441 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2443 /* Get the position at which the redisplay_end_trigger hook should
2444 be run, if it is to be run at all. */
2445 if (MARKERP (w
->redisplay_end_trigger
)
2446 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2447 it
->redisplay_end_trigger_charpos
2448 = marker_position (w
->redisplay_end_trigger
);
2449 else if (INTEGERP (w
->redisplay_end_trigger
))
2450 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2452 /* Correct bogus values of tab_width. */
2453 it
->tab_width
= XINT (BVAR (current_buffer
, tab_width
));
2454 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2457 /* Are lines in the display truncated? */
2458 if (base_face_id
!= DEFAULT_FACE_ID
2459 || XINT (it
->w
->hscroll
)
2460 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2461 && ((!NILP (Vtruncate_partial_width_windows
)
2462 && !INTEGERP (Vtruncate_partial_width_windows
))
2463 || (INTEGERP (Vtruncate_partial_width_windows
)
2464 && (WINDOW_TOTAL_COLS (it
->w
)
2465 < XINT (Vtruncate_partial_width_windows
))))))
2466 it
->line_wrap
= TRUNCATE
;
2467 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2468 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2469 ? WINDOW_WRAP
: WORD_WRAP
;
2471 it
->line_wrap
= TRUNCATE
;
2473 /* Get dimensions of truncation and continuation glyphs. These are
2474 displayed as fringe bitmaps under X, so we don't need them for such
2476 if (!FRAME_WINDOW_P (it
->f
))
2478 if (it
->line_wrap
== TRUNCATE
)
2480 /* We will need the truncation glyph. */
2481 xassert (it
->glyph_row
== NULL
);
2482 produce_special_glyphs (it
, IT_TRUNCATION
);
2483 it
->truncation_pixel_width
= it
->pixel_width
;
2487 /* We will need the continuation glyph. */
2488 xassert (it
->glyph_row
== NULL
);
2489 produce_special_glyphs (it
, IT_CONTINUATION
);
2490 it
->continuation_pixel_width
= it
->pixel_width
;
2493 /* Reset these values to zero because the produce_special_glyphs
2494 above has changed them. */
2495 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2496 it
->phys_ascent
= it
->phys_descent
= 0;
2499 /* Set this after getting the dimensions of truncation and
2500 continuation glyphs, so that we don't produce glyphs when calling
2501 produce_special_glyphs, above. */
2502 it
->glyph_row
= row
;
2503 it
->area
= TEXT_AREA
;
2505 /* Forget any previous info about this row being reversed. */
2507 it
->glyph_row
->reversed_p
= 0;
2509 /* Get the dimensions of the display area. The display area
2510 consists of the visible window area plus a horizontally scrolled
2511 part to the left of the window. All x-values are relative to the
2512 start of this total display area. */
2513 if (base_face_id
!= DEFAULT_FACE_ID
)
2515 /* Mode lines, menu bar in terminal frames. */
2516 it
->first_visible_x
= 0;
2517 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2522 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2523 it
->last_visible_x
= (it
->first_visible_x
2524 + window_box_width (w
, TEXT_AREA
));
2526 /* If we truncate lines, leave room for the truncator glyph(s) at
2527 the right margin. Otherwise, leave room for the continuation
2528 glyph(s). Truncation and continuation glyphs are not inserted
2529 for window-based redisplay. */
2530 if (!FRAME_WINDOW_P (it
->f
))
2532 if (it
->line_wrap
== TRUNCATE
)
2533 it
->last_visible_x
-= it
->truncation_pixel_width
;
2535 it
->last_visible_x
-= it
->continuation_pixel_width
;
2538 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2539 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2542 /* Leave room for a border glyph. */
2543 if (!FRAME_WINDOW_P (it
->f
)
2544 && !WINDOW_RIGHTMOST_P (it
->w
))
2545 it
->last_visible_x
-= 1;
2547 it
->last_visible_y
= window_text_bottom_y (w
);
2549 /* For mode lines and alike, arrange for the first glyph having a
2550 left box line if the face specifies a box. */
2551 if (base_face_id
!= DEFAULT_FACE_ID
)
2555 it
->face_id
= remapped_base_face_id
;
2557 /* If we have a boxed mode line, make the first character appear
2558 with a left box line. */
2559 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2560 if (face
->box
!= FACE_NO_BOX
)
2561 it
->start_of_box_run_p
= 1;
2564 /* If a buffer position was specified, set the iterator there,
2565 getting overlays and face properties from that position. */
2566 if (charpos
>= BUF_BEG (current_buffer
))
2568 it
->end_charpos
= ZV
;
2570 IT_CHARPOS (*it
) = charpos
;
2572 /* Compute byte position if not specified. */
2573 if (bytepos
< charpos
)
2574 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2576 IT_BYTEPOS (*it
) = bytepos
;
2578 it
->start
= it
->current
;
2579 /* Do we need to reorder bidirectional text? Not if this is a
2580 unibyte buffer: by definition, none of the single-byte
2581 characters are strong R2L, so no reordering is needed. And
2582 bidi.c doesn't support unibyte buffers anyway. */
2584 !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2587 /* If we are to reorder bidirectional text, init the bidi
2591 /* Note the paragraph direction that this buffer wants to
2593 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2595 it
->paragraph_embedding
= L2R
;
2596 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2598 it
->paragraph_embedding
= R2L
;
2600 it
->paragraph_embedding
= NEUTRAL_DIR
;
2601 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2605 /* Compute faces etc. */
2606 reseat (it
, it
->current
.pos
, 1);
2613 /* Initialize IT for the display of window W with window start POS. */
2616 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2618 struct glyph_row
*row
;
2619 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2621 row
= w
->desired_matrix
->rows
+ first_vpos
;
2622 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2623 it
->first_vpos
= first_vpos
;
2625 /* Don't reseat to previous visible line start if current start
2626 position is in a string or image. */
2627 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2629 int start_at_line_beg_p
;
2630 int first_y
= it
->current_y
;
2632 /* If window start is not at a line start, skip forward to POS to
2633 get the correct continuation lines width. */
2634 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2635 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2636 if (!start_at_line_beg_p
)
2640 reseat_at_previous_visible_line_start (it
);
2641 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2643 new_x
= it
->current_x
+ it
->pixel_width
;
2645 /* If lines are continued, this line may end in the middle
2646 of a multi-glyph character (e.g. a control character
2647 displayed as \003, or in the middle of an overlay
2648 string). In this case move_it_to above will not have
2649 taken us to the start of the continuation line but to the
2650 end of the continued line. */
2651 if (it
->current_x
> 0
2652 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2653 && (/* And glyph doesn't fit on the line. */
2654 new_x
> it
->last_visible_x
2655 /* Or it fits exactly and we're on a window
2657 || (new_x
== it
->last_visible_x
2658 && FRAME_WINDOW_P (it
->f
))))
2660 if (it
->current
.dpvec_index
>= 0
2661 || it
->current
.overlay_string_index
>= 0)
2663 set_iterator_to_next (it
, 1);
2664 move_it_in_display_line_to (it
, -1, -1, 0);
2667 it
->continuation_lines_width
+= it
->current_x
;
2670 /* We're starting a new display line, not affected by the
2671 height of the continued line, so clear the appropriate
2672 fields in the iterator structure. */
2673 it
->max_ascent
= it
->max_descent
= 0;
2674 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2676 it
->current_y
= first_y
;
2678 it
->current_x
= it
->hpos
= 0;
2684 /* Return 1 if POS is a position in ellipses displayed for invisible
2685 text. W is the window we display, for text property lookup. */
2688 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2690 Lisp_Object prop
, window
;
2692 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2694 /* If POS specifies a position in a display vector, this might
2695 be for an ellipsis displayed for invisible text. We won't
2696 get the iterator set up for delivering that ellipsis unless
2697 we make sure that it gets aware of the invisible text. */
2698 if (pos
->dpvec_index
>= 0
2699 && pos
->overlay_string_index
< 0
2700 && CHARPOS (pos
->string_pos
) < 0
2702 && (XSETWINDOW (window
, w
),
2703 prop
= Fget_char_property (make_number (charpos
),
2704 Qinvisible
, window
),
2705 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2707 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2709 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2716 /* Initialize IT for stepping through current_buffer in window W,
2717 starting at position POS that includes overlay string and display
2718 vector/ control character translation position information. Value
2719 is zero if there are overlay strings with newlines at POS. */
2722 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2724 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2725 int i
, overlay_strings_with_newlines
= 0;
2727 /* If POS specifies a position in a display vector, this might
2728 be for an ellipsis displayed for invisible text. We won't
2729 get the iterator set up for delivering that ellipsis unless
2730 we make sure that it gets aware of the invisible text. */
2731 if (in_ellipses_for_invisible_text_p (pos
, w
))
2737 /* Keep in mind: the call to reseat in init_iterator skips invisible
2738 text, so we might end up at a position different from POS. This
2739 is only a problem when POS is a row start after a newline and an
2740 overlay starts there with an after-string, and the overlay has an
2741 invisible property. Since we don't skip invisible text in
2742 display_line and elsewhere immediately after consuming the
2743 newline before the row start, such a POS will not be in a string,
2744 but the call to init_iterator below will move us to the
2746 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2748 /* This only scans the current chunk -- it should scan all chunks.
2749 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2750 to 16 in 22.1 to make this a lesser problem. */
2751 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2753 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2754 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2756 while (s
< e
&& *s
!= '\n')
2761 overlay_strings_with_newlines
= 1;
2766 /* If position is within an overlay string, set up IT to the right
2768 if (pos
->overlay_string_index
>= 0)
2772 /* If the first overlay string happens to have a `display'
2773 property for an image, the iterator will be set up for that
2774 image, and we have to undo that setup first before we can
2775 correct the overlay string index. */
2776 if (it
->method
== GET_FROM_IMAGE
)
2779 /* We already have the first chunk of overlay strings in
2780 IT->overlay_strings. Load more until the one for
2781 pos->overlay_string_index is in IT->overlay_strings. */
2782 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2784 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2785 it
->current
.overlay_string_index
= 0;
2788 load_overlay_strings (it
, 0);
2789 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2793 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2794 relative_index
= (it
->current
.overlay_string_index
2795 % OVERLAY_STRING_CHUNK_SIZE
);
2796 it
->string
= it
->overlay_strings
[relative_index
];
2797 xassert (STRINGP (it
->string
));
2798 it
->current
.string_pos
= pos
->string_pos
;
2799 it
->method
= GET_FROM_STRING
;
2802 if (CHARPOS (pos
->string_pos
) >= 0)
2804 /* Recorded position is not in an overlay string, but in another
2805 string. This can only be a string from a `display' property.
2806 IT should already be filled with that string. */
2807 it
->current
.string_pos
= pos
->string_pos
;
2808 xassert (STRINGP (it
->string
));
2811 /* Restore position in display vector translations, control
2812 character translations or ellipses. */
2813 if (pos
->dpvec_index
>= 0)
2815 if (it
->dpvec
== NULL
)
2816 get_next_display_element (it
);
2817 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2818 it
->current
.dpvec_index
= pos
->dpvec_index
;
2822 return !overlay_strings_with_newlines
;
2826 /* Initialize IT for stepping through current_buffer in window W
2827 starting at ROW->start. */
2830 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2832 init_from_display_pos (it
, w
, &row
->start
);
2833 it
->start
= row
->start
;
2834 it
->continuation_lines_width
= row
->continuation_lines_width
;
2839 /* Initialize IT for stepping through current_buffer in window W
2840 starting in the line following ROW, i.e. starting at ROW->end.
2841 Value is zero if there are overlay strings with newlines at ROW's
2845 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2849 if (init_from_display_pos (it
, w
, &row
->end
))
2851 if (row
->continued_p
)
2852 it
->continuation_lines_width
2853 = row
->continuation_lines_width
+ row
->pixel_width
;
2864 /***********************************************************************
2866 ***********************************************************************/
2868 /* Called when IT reaches IT->stop_charpos. Handle text property and
2869 overlay changes. Set IT->stop_charpos to the next position where
2873 handle_stop (struct it
*it
)
2875 enum prop_handled handled
;
2876 int handle_overlay_change_p
;
2880 it
->current
.dpvec_index
= -1;
2881 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2882 it
->ignore_overlay_strings_at_pos_p
= 0;
2885 /* Use face of preceding text for ellipsis (if invisible) */
2886 if (it
->selective_display_ellipsis_p
)
2887 it
->saved_face_id
= it
->face_id
;
2891 handled
= HANDLED_NORMALLY
;
2893 /* Call text property handlers. */
2894 for (p
= it_props
; p
->handler
; ++p
)
2896 handled
= p
->handler (it
);
2898 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2900 else if (handled
== HANDLED_RETURN
)
2902 /* We still want to show before and after strings from
2903 overlays even if the actual buffer text is replaced. */
2904 if (!handle_overlay_change_p
2906 || !get_overlay_strings_1 (it
, 0, 0))
2909 setup_for_ellipsis (it
, 0);
2910 /* When handling a display spec, we might load an
2911 empty string. In that case, discard it here. We
2912 used to discard it in handle_single_display_spec,
2913 but that causes get_overlay_strings_1, above, to
2914 ignore overlay strings that we must check. */
2915 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2919 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2923 it
->ignore_overlay_strings_at_pos_p
= 1;
2924 it
->string_from_display_prop_p
= 0;
2925 handle_overlay_change_p
= 0;
2927 handled
= HANDLED_RECOMPUTE_PROPS
;
2930 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2931 handle_overlay_change_p
= 0;
2934 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2936 /* Don't check for overlay strings below when set to deliver
2937 characters from a display vector. */
2938 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2939 handle_overlay_change_p
= 0;
2941 /* Handle overlay changes.
2942 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
2943 if it finds overlays. */
2944 if (handle_overlay_change_p
)
2945 handled
= handle_overlay_change (it
);
2950 setup_for_ellipsis (it
, 0);
2954 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2956 /* Determine where to stop next. */
2957 if (handled
== HANDLED_NORMALLY
)
2958 compute_stop_pos (it
);
2962 /* Compute IT->stop_charpos from text property and overlay change
2963 information for IT's current position. */
2966 compute_stop_pos (struct it
*it
)
2968 register INTERVAL iv
, next_iv
;
2969 Lisp_Object object
, limit
, position
;
2970 EMACS_INT charpos
, bytepos
;
2972 /* If nowhere else, stop at the end. */
2973 it
->stop_charpos
= it
->end_charpos
;
2975 if (STRINGP (it
->string
))
2977 /* Strings are usually short, so don't limit the search for
2979 object
= it
->string
;
2981 charpos
= IT_STRING_CHARPOS (*it
);
2982 bytepos
= IT_STRING_BYTEPOS (*it
);
2988 /* If next overlay change is in front of the current stop pos
2989 (which is IT->end_charpos), stop there. Note: value of
2990 next_overlay_change is point-max if no overlay change
2992 charpos
= IT_CHARPOS (*it
);
2993 bytepos
= IT_BYTEPOS (*it
);
2994 pos
= next_overlay_change (charpos
);
2995 if (pos
< it
->stop_charpos
)
2996 it
->stop_charpos
= pos
;
2998 /* If showing the region, we have to stop at the region
2999 start or end because the face might change there. */
3000 if (it
->region_beg_charpos
> 0)
3002 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3003 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3004 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3005 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3008 /* Set up variables for computing the stop position from text
3009 property changes. */
3010 XSETBUFFER (object
, current_buffer
);
3011 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3014 /* Get the interval containing IT's position. Value is a null
3015 interval if there isn't such an interval. */
3016 position
= make_number (charpos
);
3017 iv
= validate_interval_range (object
, &position
, &position
, 0);
3018 if (!NULL_INTERVAL_P (iv
))
3020 Lisp_Object values_here
[LAST_PROP_IDX
];
3023 /* Get properties here. */
3024 for (p
= it_props
; p
->handler
; ++p
)
3025 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3027 /* Look for an interval following iv that has different
3029 for (next_iv
= next_interval (iv
);
3030 (!NULL_INTERVAL_P (next_iv
)
3032 || XFASTINT (limit
) > next_iv
->position
));
3033 next_iv
= next_interval (next_iv
))
3035 for (p
= it_props
; p
->handler
; ++p
)
3037 Lisp_Object new_value
;
3039 new_value
= textget (next_iv
->plist
, *p
->name
);
3040 if (!EQ (values_here
[p
->idx
], new_value
))
3048 if (!NULL_INTERVAL_P (next_iv
))
3050 if (INTEGERP (limit
)
3051 && next_iv
->position
>= XFASTINT (limit
))
3052 /* No text property change up to limit. */
3053 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3055 /* Text properties change in next_iv. */
3056 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3060 if (it
->cmp_it
.id
< 0)
3062 EMACS_INT stoppos
= it
->end_charpos
;
3064 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3066 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3067 stoppos
, it
->string
);
3070 xassert (STRINGP (it
->string
)
3071 || (it
->stop_charpos
>= BEGV
3072 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3076 /* Return the position of the next overlay change after POS in
3077 current_buffer. Value is point-max if no overlay change
3078 follows. This is like `next-overlay-change' but doesn't use
3082 next_overlay_change (EMACS_INT pos
)
3086 Lisp_Object
*overlays
;
3089 /* Get all overlays at the given position. */
3090 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3092 /* If any of these overlays ends before endpos,
3093 use its ending point instead. */
3094 for (i
= 0; i
< noverlays
; ++i
)
3099 oend
= OVERLAY_END (overlays
[i
]);
3100 oendpos
= OVERLAY_POSITION (oend
);
3101 endpos
= min (endpos
, oendpos
);
3107 /* Return the character position of a display string at or after
3108 position specified by POSITION. If no display string exists at or
3109 after POSITION, return ZV. A display string is either an overlay
3110 with `display' property whose value is a string, or a `display'
3111 text property whose value is a string. STRING is data about the
3112 string to iterate; if STRING->lstring is nil, we are iterating a
3113 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3116 compute_display_string_pos (struct text_pos
*position
,
3117 struct bidi_string_data
*string
, int frame_window_p
)
3119 /* OBJECT = nil means current buffer. */
3120 Lisp_Object object
= (string
&& string
->s
) ? string
->lstring
: Qnil
;
3121 Lisp_Object pos
, spec
;
3122 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3123 EMACS_INT begb
= STRINGP (object
) ? 0 : BEGV
;
3124 EMACS_INT bufpos
, charpos
= CHARPOS (*position
);
3125 struct text_pos tpos
;
3128 /* We don't support display properties whose values are strings
3129 that have display string properties. */
3130 || string
->from_disp_str
3131 /* C strings cannot have display properties. */
3132 || (string
->s
&& !STRINGP (object
)))
3135 /* If the character at CHARPOS is where the display string begins,
3137 pos
= make_number (charpos
);
3138 if (STRINGP (object
))
3139 bufpos
= string
->bufpos
;
3143 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3145 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3148 && handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3152 /* Look forward for the first character with a `display' property
3153 that will replace the underlying text when displayed. */
3155 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3156 CHARPOS (tpos
) = XFASTINT (pos
);
3157 if (STRINGP (object
))
3158 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3160 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3161 if (CHARPOS (tpos
) >= eob
)
3163 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3164 if (!STRINGP (object
))
3165 bufpos
= CHARPOS (tpos
);
3166 } while (NILP (spec
)
3167 || !handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3170 return CHARPOS (tpos
);
3173 /* Return the character position of the end of the display string that
3174 started at CHARPOS. A display string is either an overlay with
3175 `display' property whose value is a string or a `display' text
3176 property whose value is a string. */
3178 compute_display_string_end (EMACS_INT charpos
, struct bidi_string_data
*string
)
3180 /* OBJECT = nil means current buffer. */
3181 Lisp_Object object
= (string
&& string
->s
) ? string
->lstring
: Qnil
;
3182 Lisp_Object pos
= make_number (charpos
);
3183 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3188 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3191 /* Look forward for the first character where the `display' property
3193 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3195 return XFASTINT (pos
);
3200 /***********************************************************************
3202 ***********************************************************************/
3204 /* Handle changes in the `fontified' property of the current buffer by
3205 calling hook functions from Qfontification_functions to fontify
3208 static enum prop_handled
3209 handle_fontified_prop (struct it
*it
)
3211 Lisp_Object prop
, pos
;
3212 enum prop_handled handled
= HANDLED_NORMALLY
;
3214 if (!NILP (Vmemory_full
))
3217 /* Get the value of the `fontified' property at IT's current buffer
3218 position. (The `fontified' property doesn't have a special
3219 meaning in strings.) If the value is nil, call functions from
3220 Qfontification_functions. */
3221 if (!STRINGP (it
->string
)
3223 && !NILP (Vfontification_functions
)
3224 && !NILP (Vrun_hooks
)
3225 && (pos
= make_number (IT_CHARPOS (*it
)),
3226 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3227 /* Ignore the special cased nil value always present at EOB since
3228 no amount of fontifying will be able to change it. */
3229 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3231 int count
= SPECPDL_INDEX ();
3233 struct buffer
*obuf
= current_buffer
;
3234 int begv
= BEGV
, zv
= ZV
;
3235 int old_clip_changed
= current_buffer
->clip_changed
;
3237 val
= Vfontification_functions
;
3238 specbind (Qfontification_functions
, Qnil
);
3240 xassert (it
->end_charpos
== ZV
);
3242 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3243 safe_call1 (val
, pos
);
3246 Lisp_Object fns
, fn
;
3247 struct gcpro gcpro1
, gcpro2
;
3252 for (; CONSP (val
); val
= XCDR (val
))
3258 /* A value of t indicates this hook has a local
3259 binding; it means to run the global binding too.
3260 In a global value, t should not occur. If it
3261 does, we must ignore it to avoid an endless
3263 for (fns
= Fdefault_value (Qfontification_functions
);
3269 safe_call1 (fn
, pos
);
3273 safe_call1 (fn
, pos
);
3279 unbind_to (count
, Qnil
);
3281 /* Fontification functions routinely call `save-restriction'.
3282 Normally, this tags clip_changed, which can confuse redisplay
3283 (see discussion in Bug#6671). Since we don't perform any
3284 special handling of fontification changes in the case where
3285 `save-restriction' isn't called, there's no point doing so in
3286 this case either. So, if the buffer's restrictions are
3287 actually left unchanged, reset clip_changed. */
3288 if (obuf
== current_buffer
)
3290 if (begv
== BEGV
&& zv
== ZV
)
3291 current_buffer
->clip_changed
= old_clip_changed
;
3293 /* There isn't much we can reasonably do to protect against
3294 misbehaving fontification, but here's a fig leaf. */
3295 else if (!NILP (BVAR (obuf
, name
)))
3296 set_buffer_internal_1 (obuf
);
3298 /* The fontification code may have added/removed text.
3299 It could do even a lot worse, but let's at least protect against
3300 the most obvious case where only the text past `pos' gets changed',
3301 as is/was done in grep.el where some escapes sequences are turned
3302 into face properties (bug#7876). */
3303 it
->end_charpos
= ZV
;
3305 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3306 something. This avoids an endless loop if they failed to
3307 fontify the text for which reason ever. */
3308 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3309 handled
= HANDLED_RECOMPUTE_PROPS
;
3317 /***********************************************************************
3319 ***********************************************************************/
3321 /* Set up iterator IT from face properties at its current position.
3322 Called from handle_stop. */
3324 static enum prop_handled
3325 handle_face_prop (struct it
*it
)
3328 EMACS_INT next_stop
;
3330 if (!STRINGP (it
->string
))
3333 = face_at_buffer_position (it
->w
,
3335 it
->region_beg_charpos
,
3336 it
->region_end_charpos
,
3339 + TEXT_PROP_DISTANCE_LIMIT
),
3340 0, it
->base_face_id
);
3342 /* Is this a start of a run of characters with box face?
3343 Caveat: this can be called for a freshly initialized
3344 iterator; face_id is -1 in this case. We know that the new
3345 face will not change until limit, i.e. if the new face has a
3346 box, all characters up to limit will have one. But, as
3347 usual, we don't know whether limit is really the end. */
3348 if (new_face_id
!= it
->face_id
)
3350 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3352 /* If new face has a box but old face has not, this is
3353 the start of a run of characters with box, i.e. it has
3354 a shadow on the left side. The value of face_id of the
3355 iterator will be -1 if this is the initial call that gets
3356 the face. In this case, we have to look in front of IT's
3357 position and see whether there is a face != new_face_id. */
3358 it
->start_of_box_run_p
3359 = (new_face
->box
!= FACE_NO_BOX
3360 && (it
->face_id
>= 0
3361 || IT_CHARPOS (*it
) == BEG
3362 || new_face_id
!= face_before_it_pos (it
)));
3363 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3371 Lisp_Object from_overlay
3372 = (it
->current
.overlay_string_index
>= 0
3373 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3376 /* See if we got to this string directly or indirectly from
3377 an overlay property. That includes the before-string or
3378 after-string of an overlay, strings in display properties
3379 provided by an overlay, their text properties, etc.
3381 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3382 if (! NILP (from_overlay
))
3383 for (i
= it
->sp
- 1; i
>= 0; i
--)
3385 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3387 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3388 else if (! NILP (it
->stack
[i
].from_overlay
))
3389 from_overlay
= it
->stack
[i
].from_overlay
;
3391 if (!NILP (from_overlay
))
3395 if (! NILP (from_overlay
))
3397 bufpos
= IT_CHARPOS (*it
);
3398 /* For a string from an overlay, the base face depends
3399 only on text properties and ignores overlays. */
3401 = face_for_overlay_string (it
->w
,
3403 it
->region_beg_charpos
,
3404 it
->region_end_charpos
,
3407 + TEXT_PROP_DISTANCE_LIMIT
),
3415 /* For strings from a `display' property, use the face at
3416 IT's current buffer position as the base face to merge
3417 with, so that overlay strings appear in the same face as
3418 surrounding text, unless they specify their own
3420 base_face_id
= underlying_face_id (it
);
3423 new_face_id
= face_at_string_position (it
->w
,
3425 IT_STRING_CHARPOS (*it
),
3427 it
->region_beg_charpos
,
3428 it
->region_end_charpos
,
3432 /* Is this a start of a run of characters with box? Caveat:
3433 this can be called for a freshly allocated iterator; face_id
3434 is -1 is this case. We know that the new face will not
3435 change until the next check pos, i.e. if the new face has a
3436 box, all characters up to that position will have a
3437 box. But, as usual, we don't know whether that position
3438 is really the end. */
3439 if (new_face_id
!= it
->face_id
)
3441 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3442 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3444 /* If new face has a box but old face hasn't, this is the
3445 start of a run of characters with box, i.e. it has a
3446 shadow on the left side. */
3447 it
->start_of_box_run_p
3448 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3449 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3453 it
->face_id
= new_face_id
;
3454 return HANDLED_NORMALLY
;
3458 /* Return the ID of the face ``underlying'' IT's current position,
3459 which is in a string. If the iterator is associated with a
3460 buffer, return the face at IT's current buffer position.
3461 Otherwise, use the iterator's base_face_id. */
3464 underlying_face_id (struct it
*it
)
3466 int face_id
= it
->base_face_id
, i
;
3468 xassert (STRINGP (it
->string
));
3470 for (i
= it
->sp
- 1; i
>= 0; --i
)
3471 if (NILP (it
->stack
[i
].string
))
3472 face_id
= it
->stack
[i
].face_id
;
3478 /* Compute the face one character before or after the current position
3479 of IT. BEFORE_P non-zero means get the face in front of IT's
3480 position. Value is the id of the face. */
3483 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3486 EMACS_INT next_check_charpos
;
3487 struct text_pos pos
;
3489 xassert (it
->s
== NULL
);
3491 if (STRINGP (it
->string
))
3496 /* No face change past the end of the string (for the case
3497 we are padding with spaces). No face change before the
3499 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3500 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3503 /* Set pos to the position before or after IT's current position. */
3505 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3507 /* For composition, we must check the character after the
3509 pos
= (it
->what
== IT_COMPOSITION
3510 ? string_pos (IT_STRING_CHARPOS (*it
)
3511 + it
->cmp_it
.nchars
, it
->string
)
3512 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3514 if (it
->current
.overlay_string_index
>= 0)
3515 bufpos
= IT_CHARPOS (*it
);
3519 base_face_id
= underlying_face_id (it
);
3521 /* Get the face for ASCII, or unibyte. */
3522 face_id
= face_at_string_position (it
->w
,
3526 it
->region_beg_charpos
,
3527 it
->region_end_charpos
,
3528 &next_check_charpos
,
3531 /* Correct the face for charsets different from ASCII. Do it
3532 for the multibyte case only. The face returned above is
3533 suitable for unibyte text if IT->string is unibyte. */
3534 if (STRING_MULTIBYTE (it
->string
))
3536 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3538 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3540 c
= string_char_and_length (p
, &len
);
3541 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3546 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3547 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3550 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3551 pos
= it
->current
.pos
;
3554 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3557 if (it
->what
== IT_COMPOSITION
)
3558 /* For composition, we must check the position after the
3560 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3562 INC_TEXT_POS (pos
, it
->multibyte_p
);
3565 /* Determine face for CHARSET_ASCII, or unibyte. */
3566 face_id
= face_at_buffer_position (it
->w
,
3568 it
->region_beg_charpos
,
3569 it
->region_end_charpos
,
3570 &next_check_charpos
,
3573 /* Correct the face for charsets different from ASCII. Do it
3574 for the multibyte case only. The face returned above is
3575 suitable for unibyte text if current_buffer is unibyte. */
3576 if (it
->multibyte_p
)
3578 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3579 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3580 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3589 /***********************************************************************
3591 ***********************************************************************/
3593 /* Set up iterator IT from invisible properties at its current
3594 position. Called from handle_stop. */
3596 static enum prop_handled
3597 handle_invisible_prop (struct it
*it
)
3599 enum prop_handled handled
= HANDLED_NORMALLY
;
3601 if (STRINGP (it
->string
))
3603 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3605 /* Get the value of the invisible text property at the
3606 current position. Value will be nil if there is no such
3608 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3609 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3612 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3616 handled
= HANDLED_RECOMPUTE_PROPS
;
3618 /* Get the position at which the next change of the
3619 invisible text property can be found in IT->string.
3620 Value will be nil if the property value is the same for
3621 all the rest of IT->string. */
3622 XSETINT (limit
, SCHARS (it
->string
));
3623 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3626 /* Text at current position is invisible. The next
3627 change in the property is at position end_charpos.
3628 Move IT's current position to that position. */
3629 if (INTEGERP (end_charpos
)
3630 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3632 struct text_pos old
;
3635 old
= it
->current
.string_pos
;
3636 oldpos
= CHARPOS (old
);
3639 if (it
->bidi_it
.first_elt
3640 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
3641 bidi_paragraph_init (it
->paragraph_embedding
,
3643 /* Bidi-iterate out of the invisible text. */
3646 bidi_move_to_visually_next (&it
->bidi_it
);
3648 while (oldpos
<= it
->bidi_it
.charpos
3649 && it
->bidi_it
.charpos
< endpos
);
3651 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3652 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3653 if (IT_CHARPOS (*it
) >= endpos
)
3654 it
->prev_stop
= endpos
;
3658 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3659 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3664 /* The rest of the string is invisible. If this is an
3665 overlay string, proceed with the next overlay string
3666 or whatever comes and return a character from there. */
3667 if (it
->current
.overlay_string_index
>= 0)
3669 next_overlay_string (it
);
3670 /* Don't check for overlay strings when we just
3671 finished processing them. */
3672 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3676 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3677 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3685 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3686 Lisp_Object pos
, prop
, overlay
;
3688 /* First of all, is there invisible text at this position? */
3689 tem
= start_charpos
= IT_CHARPOS (*it
);
3690 pos
= make_number (tem
);
3691 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3693 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3695 /* If we are on invisible text, skip over it. */
3696 if (invis_p
&& start_charpos
< it
->end_charpos
)
3698 /* Record whether we have to display an ellipsis for the
3700 int display_ellipsis_p
= invis_p
== 2;
3702 handled
= HANDLED_RECOMPUTE_PROPS
;
3704 /* Loop skipping over invisible text. The loop is left at
3705 ZV or with IT on the first char being visible again. */
3708 /* Try to skip some invisible text. Return value is the
3709 position reached which can be equal to where we start
3710 if there is nothing invisible there. This skips both
3711 over invisible text properties and overlays with
3712 invisible property. */
3713 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3715 /* If we skipped nothing at all we weren't at invisible
3716 text in the first place. If everything to the end of
3717 the buffer was skipped, end the loop. */
3718 if (newpos
== tem
|| newpos
>= ZV
)
3722 /* We skipped some characters but not necessarily
3723 all there are. Check if we ended up on visible
3724 text. Fget_char_property returns the property of
3725 the char before the given position, i.e. if we
3726 get invis_p = 0, this means that the char at
3727 newpos is visible. */
3728 pos
= make_number (newpos
);
3729 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3730 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3733 /* If we ended up on invisible text, proceed to
3734 skip starting with next_stop. */
3738 /* If there are adjacent invisible texts, don't lose the
3739 second one's ellipsis. */
3741 display_ellipsis_p
= 1;
3745 /* The position newpos is now either ZV or on visible text. */
3746 if (it
->bidi_p
&& newpos
< ZV
)
3748 /* With bidi iteration, the region of invisible text
3749 could start and/or end in the middle of a non-base
3750 embedding level. Therefore, we need to skip
3751 invisible text using the bidi iterator, starting at
3752 IT's current position, until we find ourselves
3753 outside the invisible text. Skipping invisible text
3754 _after_ bidi iteration avoids affecting the visual
3755 order of the displayed text when invisible properties
3756 are added or removed. */
3757 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3759 /* If we were `reseat'ed to a new paragraph,
3760 determine the paragraph base direction. We need
3761 to do it now because next_element_from_buffer may
3762 not have a chance to do it, if we are going to
3763 skip any text at the beginning, which resets the
3765 bidi_paragraph_init (it
->paragraph_embedding
,
3770 bidi_move_to_visually_next (&it
->bidi_it
);
3772 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3773 && it
->bidi_it
.charpos
< newpos
);
3774 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3775 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3776 /* If we overstepped NEWPOS, record its position in the
3777 iterator, so that we skip invisible text if later the
3778 bidi iteration lands us in the invisible region
3780 if (IT_CHARPOS (*it
) >= newpos
)
3781 it
->prev_stop
= newpos
;
3785 IT_CHARPOS (*it
) = newpos
;
3786 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3789 /* If there are before-strings at the start of invisible
3790 text, and the text is invisible because of a text
3791 property, arrange to show before-strings because 20.x did
3792 it that way. (If the text is invisible because of an
3793 overlay property instead of a text property, this is
3794 already handled in the overlay code.) */
3796 && get_overlay_strings (it
, it
->stop_charpos
))
3798 handled
= HANDLED_RECOMPUTE_PROPS
;
3799 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3801 else if (display_ellipsis_p
)
3803 /* Make sure that the glyphs of the ellipsis will get
3804 correct `charpos' values. If we would not update
3805 it->position here, the glyphs would belong to the
3806 last visible character _before_ the invisible
3807 text, which confuses `set_cursor_from_row'.
3809 We use the last invisible position instead of the
3810 first because this way the cursor is always drawn on
3811 the first "." of the ellipsis, whenever PT is inside
3812 the invisible text. Otherwise the cursor would be
3813 placed _after_ the ellipsis when the point is after the
3814 first invisible character. */
3815 if (!STRINGP (it
->object
))
3817 it
->position
.charpos
= newpos
- 1;
3818 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3821 /* Let the ellipsis display before
3822 considering any properties of the following char.
3823 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3824 handled
= HANDLED_RETURN
;
3833 /* Make iterator IT return `...' next.
3834 Replaces LEN characters from buffer. */
3837 setup_for_ellipsis (struct it
*it
, int len
)
3839 /* Use the display table definition for `...'. Invalid glyphs
3840 will be handled by the method returning elements from dpvec. */
3841 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3843 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3844 it
->dpvec
= v
->contents
;
3845 it
->dpend
= v
->contents
+ v
->header
.size
;
3849 /* Default `...'. */
3850 it
->dpvec
= default_invis_vector
;
3851 it
->dpend
= default_invis_vector
+ 3;
3854 it
->dpvec_char_len
= len
;
3855 it
->current
.dpvec_index
= 0;
3856 it
->dpvec_face_id
= -1;
3858 /* Remember the current face id in case glyphs specify faces.
3859 IT's face is restored in set_iterator_to_next.
3860 saved_face_id was set to preceding char's face in handle_stop. */
3861 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3862 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3864 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3870 /***********************************************************************
3872 ***********************************************************************/
3874 /* Set up iterator IT from `display' property at its current position.
3875 Called from handle_stop.
3876 We return HANDLED_RETURN if some part of the display property
3877 overrides the display of the buffer text itself.
3878 Otherwise we return HANDLED_NORMALLY. */
3880 static enum prop_handled
3881 handle_display_prop (struct it
*it
)
3883 Lisp_Object propval
, object
, overlay
;
3884 struct text_pos
*position
;
3886 /* Nonzero if some property replaces the display of the text itself. */
3887 int display_replaced_p
= 0;
3889 if (STRINGP (it
->string
))
3891 object
= it
->string
;
3892 position
= &it
->current
.string_pos
;
3893 bufpos
= CHARPOS (it
->current
.pos
);
3897 XSETWINDOW (object
, it
->w
);
3898 position
= &it
->current
.pos
;
3899 bufpos
= CHARPOS (*position
);
3902 /* Reset those iterator values set from display property values. */
3903 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3904 it
->space_width
= Qnil
;
3905 it
->font_height
= Qnil
;
3908 /* We don't support recursive `display' properties, i.e. string
3909 values that have a string `display' property, that have a string
3910 `display' property etc. */
3911 if (!it
->string_from_display_prop_p
)
3912 it
->area
= TEXT_AREA
;
3914 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
3915 Qdisplay
, object
, &overlay
);
3917 return HANDLED_NORMALLY
;
3918 /* Now OVERLAY is the overlay that gave us this property, or nil
3919 if it was a text property. */
3921 if (!STRINGP (it
->string
))
3922 object
= it
->w
->buffer
;
3924 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
3926 FRAME_WINDOW_P (it
->f
));
3928 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3931 /* Subroutine of handle_display_prop. Returns non-zero if the display
3932 specification in SPEC is a replacing specification, i.e. it would
3933 replace the text covered by `display' property with something else,
3934 such as an image or a display string.
3936 See handle_single_display_spec for documentation of arguments.
3937 frame_window_p is non-zero if the window being redisplayed is on a
3938 GUI frame; this argument is used only if IT is NULL, see below.
3940 IT can be NULL, if this is called by the bidi reordering code
3941 through compute_display_string_pos, which see. In that case, this
3942 function only examines SPEC, but does not otherwise "handle" it, in
3943 the sense that it doesn't set up members of IT from the display
3946 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
3947 Lisp_Object overlay
, struct text_pos
*position
,
3948 EMACS_INT bufpos
, int frame_window_p
)
3950 int replacing_p
= 0;
3953 /* Simple specerties. */
3954 && !EQ (XCAR (spec
), Qimage
)
3955 && !EQ (XCAR (spec
), Qspace
)
3956 && !EQ (XCAR (spec
), Qwhen
)
3957 && !EQ (XCAR (spec
), Qslice
)
3958 && !EQ (XCAR (spec
), Qspace_width
)
3959 && !EQ (XCAR (spec
), Qheight
)
3960 && !EQ (XCAR (spec
), Qraise
)
3961 /* Marginal area specifications. */
3962 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
3963 && !EQ (XCAR (spec
), Qleft_fringe
)
3964 && !EQ (XCAR (spec
), Qright_fringe
)
3965 && !NILP (XCAR (spec
)))
3967 for (; CONSP (spec
); spec
= XCDR (spec
))
3969 if (handle_single_display_spec (it
, XCAR (spec
), object
, overlay
,
3970 position
, bufpos
, replacing_p
,
3974 /* If some text in a string is replaced, `position' no
3975 longer points to the position of `object'. */
3976 if (!it
|| STRINGP (object
))
3981 else if (VECTORP (spec
))
3984 for (i
= 0; i
< ASIZE (spec
); ++i
)
3985 if (handle_single_display_spec (it
, AREF (spec
, i
), object
, overlay
,
3986 position
, bufpos
, replacing_p
,
3990 /* If some text in a string is replaced, `position' no
3991 longer points to the position of `object'. */
3992 if (!it
|| STRINGP (object
))
3998 if (handle_single_display_spec (it
, spec
, object
, overlay
,
3999 position
, bufpos
, 0, frame_window_p
))
4006 /* Value is the position of the end of the `display' property starting
4007 at START_POS in OBJECT. */
4009 static struct text_pos
4010 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4013 struct text_pos end_pos
;
4015 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4016 Qdisplay
, object
, Qnil
);
4017 CHARPOS (end_pos
) = XFASTINT (end
);
4018 if (STRINGP (object
))
4019 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4021 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4027 /* Set up IT from a single `display' property specification SPEC. OBJECT
4028 is the object in which the `display' property was found. *POSITION
4029 is the position in OBJECT at which the `display' property was found.
4030 BUFPOS is the buffer position of OBJECT (different from POSITION if
4031 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4032 previously saw a display specification which already replaced text
4033 display with something else, for example an image; we ignore such
4034 properties after the first one has been processed.
4036 OVERLAY is the overlay this `display' property came from,
4037 or nil if it was a text property.
4039 If SPEC is a `space' or `image' specification, and in some other
4040 cases too, set *POSITION to the position where the `display'
4043 If IT is NULL, only examine the property specification in SPEC, but
4044 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4045 is intended to be displayed in a window on a GUI frame.
4047 Value is non-zero if something was found which replaces the display
4048 of buffer or string text. */
4051 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4052 Lisp_Object overlay
, struct text_pos
*position
,
4053 EMACS_INT bufpos
, int display_replaced_p
,
4057 Lisp_Object location
, value
;
4058 struct text_pos start_pos
= *position
;
4061 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4062 If the result is non-nil, use VALUE instead of SPEC. */
4064 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4073 if (!NILP (form
) && !EQ (form
, Qt
))
4075 int count
= SPECPDL_INDEX ();
4076 struct gcpro gcpro1
;
4078 /* Bind `object' to the object having the `display' property, a
4079 buffer or string. Bind `position' to the position in the
4080 object where the property was found, and `buffer-position'
4081 to the current position in the buffer. */
4084 XSETBUFFER (object
, current_buffer
);
4085 specbind (Qobject
, object
);
4086 specbind (Qposition
, make_number (CHARPOS (*position
)));
4087 specbind (Qbuffer_position
, make_number (bufpos
));
4089 form
= safe_eval (form
);
4091 unbind_to (count
, Qnil
);
4097 /* Handle `(height HEIGHT)' specifications. */
4099 && EQ (XCAR (spec
), Qheight
)
4100 && CONSP (XCDR (spec
)))
4104 if (!FRAME_WINDOW_P (it
->f
))
4107 it
->font_height
= XCAR (XCDR (spec
));
4108 if (!NILP (it
->font_height
))
4110 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4111 int new_height
= -1;
4113 if (CONSP (it
->font_height
)
4114 && (EQ (XCAR (it
->font_height
), Qplus
)
4115 || EQ (XCAR (it
->font_height
), Qminus
))
4116 && CONSP (XCDR (it
->font_height
))
4117 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4119 /* `(+ N)' or `(- N)' where N is an integer. */
4120 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4121 if (EQ (XCAR (it
->font_height
), Qplus
))
4123 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4125 else if (FUNCTIONP (it
->font_height
))
4127 /* Call function with current height as argument.
4128 Value is the new height. */
4130 height
= safe_call1 (it
->font_height
,
4131 face
->lface
[LFACE_HEIGHT_INDEX
]);
4132 if (NUMBERP (height
))
4133 new_height
= XFLOATINT (height
);
4135 else if (NUMBERP (it
->font_height
))
4137 /* Value is a multiple of the canonical char height. */
4140 f
= FACE_FROM_ID (it
->f
,
4141 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4142 new_height
= (XFLOATINT (it
->font_height
)
4143 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4147 /* Evaluate IT->font_height with `height' bound to the
4148 current specified height to get the new height. */
4149 int count
= SPECPDL_INDEX ();
4151 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4152 value
= safe_eval (it
->font_height
);
4153 unbind_to (count
, Qnil
);
4155 if (NUMBERP (value
))
4156 new_height
= XFLOATINT (value
);
4160 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4167 /* Handle `(space-width WIDTH)'. */
4169 && EQ (XCAR (spec
), Qspace_width
)
4170 && CONSP (XCDR (spec
)))
4174 if (!FRAME_WINDOW_P (it
->f
))
4177 value
= XCAR (XCDR (spec
));
4178 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4179 it
->space_width
= value
;
4185 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4187 && EQ (XCAR (spec
), Qslice
))
4193 if (!FRAME_WINDOW_P (it
->f
))
4196 if (tem
= XCDR (spec
), CONSP (tem
))
4198 it
->slice
.x
= XCAR (tem
);
4199 if (tem
= XCDR (tem
), CONSP (tem
))
4201 it
->slice
.y
= XCAR (tem
);
4202 if (tem
= XCDR (tem
), CONSP (tem
))
4204 it
->slice
.width
= XCAR (tem
);
4205 if (tem
= XCDR (tem
), CONSP (tem
))
4206 it
->slice
.height
= XCAR (tem
);
4215 /* Handle `(raise FACTOR)'. */
4217 && EQ (XCAR (spec
), Qraise
)
4218 && CONSP (XCDR (spec
)))
4222 if (!FRAME_WINDOW_P (it
->f
))
4225 #ifdef HAVE_WINDOW_SYSTEM
4226 value
= XCAR (XCDR (spec
));
4227 if (NUMBERP (value
))
4229 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4230 it
->voffset
= - (XFLOATINT (value
)
4231 * (FONT_HEIGHT (face
->font
)));
4233 #endif /* HAVE_WINDOW_SYSTEM */
4239 /* Don't handle the other kinds of display specifications
4240 inside a string that we got from a `display' property. */
4241 if (it
&& it
->string_from_display_prop_p
)
4244 /* Characters having this form of property are not displayed, so
4245 we have to find the end of the property. */
4248 start_pos
= *position
;
4249 *position
= display_prop_end (it
, object
, start_pos
);
4253 /* Stop the scan at that end position--we assume that all
4254 text properties change there. */
4256 it
->stop_charpos
= position
->charpos
;
4258 /* Handle `(left-fringe BITMAP [FACE])'
4259 and `(right-fringe BITMAP [FACE])'. */
4261 && (EQ (XCAR (spec
), Qleft_fringe
)
4262 || EQ (XCAR (spec
), Qright_fringe
))
4263 && CONSP (XCDR (spec
)))
4269 if (!FRAME_WINDOW_P (it
->f
))
4270 /* If we return here, POSITION has been advanced
4271 across the text with this property. */
4274 else if (!frame_window_p
)
4277 #ifdef HAVE_WINDOW_SYSTEM
4278 value
= XCAR (XCDR (spec
));
4279 if (!SYMBOLP (value
)
4280 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4281 /* If we return here, POSITION has been advanced
4282 across the text with this property. */
4287 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4289 if (CONSP (XCDR (XCDR (spec
))))
4291 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4292 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4298 /* Save current settings of IT so that we can restore them
4299 when we are finished with the glyph property value. */
4300 push_it (it
, position
);
4302 it
->area
= TEXT_AREA
;
4303 it
->what
= IT_IMAGE
;
4304 it
->image_id
= -1; /* no image */
4305 it
->position
= start_pos
;
4306 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4307 it
->method
= GET_FROM_IMAGE
;
4308 it
->from_overlay
= Qnil
;
4309 it
->face_id
= face_id
;
4311 /* Say that we haven't consumed the characters with
4312 `display' property yet. The call to pop_it in
4313 set_iterator_to_next will clean this up. */
4314 *position
= start_pos
;
4316 if (EQ (XCAR (spec
), Qleft_fringe
))
4318 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4319 it
->left_user_fringe_face_id
= face_id
;
4323 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4324 it
->right_user_fringe_face_id
= face_id
;
4327 #endif /* HAVE_WINDOW_SYSTEM */
4331 /* Prepare to handle `((margin left-margin) ...)',
4332 `((margin right-margin) ...)' and `((margin nil) ...)'
4333 prefixes for display specifications. */
4334 location
= Qunbound
;
4335 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4339 value
= XCDR (spec
);
4341 value
= XCAR (value
);
4344 if (EQ (XCAR (tem
), Qmargin
)
4345 && (tem
= XCDR (tem
),
4346 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4348 || EQ (tem
, Qleft_margin
)
4349 || EQ (tem
, Qright_margin
))))
4353 if (EQ (location
, Qunbound
))
4359 /* After this point, VALUE is the property after any
4360 margin prefix has been stripped. It must be a string,
4361 an image specification, or `(space ...)'.
4363 LOCATION specifies where to display: `left-margin',
4364 `right-margin' or nil. */
4366 valid_p
= (STRINGP (value
)
4367 #ifdef HAVE_WINDOW_SYSTEM
4368 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4369 && valid_image_p (value
))
4370 #endif /* not HAVE_WINDOW_SYSTEM */
4371 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4373 if (valid_p
&& !display_replaced_p
)
4378 /* Save current settings of IT so that we can restore them
4379 when we are finished with the glyph property value. */
4380 push_it (it
, position
);
4381 it
->from_overlay
= overlay
;
4383 if (NILP (location
))
4384 it
->area
= TEXT_AREA
;
4385 else if (EQ (location
, Qleft_margin
))
4386 it
->area
= LEFT_MARGIN_AREA
;
4388 it
->area
= RIGHT_MARGIN_AREA
;
4390 if (STRINGP (value
))
4393 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4394 it
->current
.overlay_string_index
= -1;
4395 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4396 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4397 it
->method
= GET_FROM_STRING
;
4398 it
->stop_charpos
= 0;
4399 it
->string_from_display_prop_p
= 1;
4400 /* Say that we haven't consumed the characters with
4401 `display' property yet. The call to pop_it in
4402 set_iterator_to_next will clean this up. */
4403 if (BUFFERP (object
))
4404 *position
= start_pos
;
4406 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4408 it
->method
= GET_FROM_STRETCH
;
4410 *position
= it
->position
= start_pos
;
4412 #ifdef HAVE_WINDOW_SYSTEM
4415 it
->what
= IT_IMAGE
;
4416 it
->image_id
= lookup_image (it
->f
, value
);
4417 it
->position
= start_pos
;
4418 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4419 it
->method
= GET_FROM_IMAGE
;
4421 /* Say that we haven't consumed the characters with
4422 `display' property yet. The call to pop_it in
4423 set_iterator_to_next will clean this up. */
4424 *position
= start_pos
;
4426 #endif /* HAVE_WINDOW_SYSTEM */
4431 /* Invalid property or property not supported. Restore
4432 POSITION to what it was before. */
4433 *position
= start_pos
;
4437 /* Check if PROP is a display property value whose text should be
4438 treated as intangible. OVERLAY is the overlay from which PROP
4439 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4440 specify the buffer position covered by PROP. */
4443 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4444 EMACS_INT charpos
, EMACS_INT bytepos
)
4446 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4447 struct text_pos position
;
4449 SET_TEXT_POS (position
, charpos
, bytepos
);
4450 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4451 &position
, charpos
, frame_window_p
);
4455 /* Return 1 if PROP is a display sub-property value containing STRING.
4457 Implementation note: this and the following function are really
4458 special cases of handle_display_spec and
4459 handle_single_display_spec, and should ideally use the same code.
4460 Until they do, these two pairs must be consistent and must be
4461 modified in sync. */
4464 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4466 if (EQ (string
, prop
))
4469 /* Skip over `when FORM'. */
4470 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4475 /* Actually, the condition following `when' should be eval'ed,
4476 like handle_single_display_spec does, and we should return
4477 zero if it evaluates to nil. However, this function is
4478 called only when the buffer was already displayed and some
4479 glyph in the glyph matrix was found to come from a display
4480 string. Therefore, the condition was already evaluated, and
4481 the result was non-nil, otherwise the display string wouldn't
4482 have been displayed and we would have never been called for
4483 this property. Thus, we can skip the evaluation and assume
4484 its result is non-nil. */
4489 /* Skip over `margin LOCATION'. */
4490 if (EQ (XCAR (prop
), Qmargin
))
4501 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4505 /* Return 1 if STRING appears in the `display' property PROP. */
4508 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4511 && !EQ (XCAR (prop
), Qwhen
)
4512 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4514 /* A list of sub-properties. */
4515 while (CONSP (prop
))
4517 if (single_display_spec_string_p (XCAR (prop
), string
))
4522 else if (VECTORP (prop
))
4524 /* A vector of sub-properties. */
4526 for (i
= 0; i
< ASIZE (prop
); ++i
)
4527 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4531 return single_display_spec_string_p (prop
, string
);
4536 /* Look for STRING in overlays and text properties in the current
4537 buffer, between character positions FROM and TO (excluding TO).
4538 BACK_P non-zero means look back (in this case, TO is supposed to be
4540 Value is the first character position where STRING was found, or
4541 zero if it wasn't found before hitting TO.
4543 This function may only use code that doesn't eval because it is
4544 called asynchronously from note_mouse_highlight. */
4547 string_buffer_position_lim (Lisp_Object string
,
4548 EMACS_INT from
, EMACS_INT to
, int back_p
)
4550 Lisp_Object limit
, prop
, pos
;
4553 pos
= make_number (from
);
4555 if (!back_p
) /* looking forward */
4557 limit
= make_number (min (to
, ZV
));
4558 while (!found
&& !EQ (pos
, limit
))
4560 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4561 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4564 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4568 else /* looking back */
4570 limit
= make_number (max (to
, BEGV
));
4571 while (!found
&& !EQ (pos
, limit
))
4573 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4574 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4577 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4582 return found
? XINT (pos
) : 0;
4585 /* Determine which buffer position in current buffer STRING comes from.
4586 AROUND_CHARPOS is an approximate position where it could come from.
4587 Value is the buffer position or 0 if it couldn't be determined.
4589 This function is necessary because we don't record buffer positions
4590 in glyphs generated from strings (to keep struct glyph small).
4591 This function may only use code that doesn't eval because it is
4592 called asynchronously from note_mouse_highlight. */
4595 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4597 const int MAX_DISTANCE
= 1000;
4598 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4599 around_charpos
+ MAX_DISTANCE
,
4603 found
= string_buffer_position_lim (string
, around_charpos
,
4604 around_charpos
- MAX_DISTANCE
, 1);
4610 /***********************************************************************
4611 `composition' property
4612 ***********************************************************************/
4614 /* Set up iterator IT from `composition' property at its current
4615 position. Called from handle_stop. */
4617 static enum prop_handled
4618 handle_composition_prop (struct it
*it
)
4620 Lisp_Object prop
, string
;
4621 EMACS_INT pos
, pos_byte
, start
, end
;
4623 if (STRINGP (it
->string
))
4627 pos
= IT_STRING_CHARPOS (*it
);
4628 pos_byte
= IT_STRING_BYTEPOS (*it
);
4629 string
= it
->string
;
4630 s
= SDATA (string
) + pos_byte
;
4631 it
->c
= STRING_CHAR (s
);
4635 pos
= IT_CHARPOS (*it
);
4636 pos_byte
= IT_BYTEPOS (*it
);
4638 it
->c
= FETCH_CHAR (pos_byte
);
4641 /* If there's a valid composition and point is not inside of the
4642 composition (in the case that the composition is from the current
4643 buffer), draw a glyph composed from the composition components. */
4644 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4645 && COMPOSITION_VALID_P (start
, end
, prop
)
4646 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4650 if (STRINGP (it
->string
))
4651 pos_byte
= string_char_to_byte (it
->string
, start
);
4653 pos_byte
= CHAR_TO_BYTE (start
);
4655 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4658 if (it
->cmp_it
.id
>= 0)
4661 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4662 it
->cmp_it
.nglyphs
= -1;
4666 return HANDLED_NORMALLY
;
4671 /***********************************************************************
4673 ***********************************************************************/
4675 /* The following structure is used to record overlay strings for
4676 later sorting in load_overlay_strings. */
4678 struct overlay_entry
4680 Lisp_Object overlay
;
4687 /* Set up iterator IT from overlay strings at its current position.
4688 Called from handle_stop. */
4690 static enum prop_handled
4691 handle_overlay_change (struct it
*it
)
4693 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4694 return HANDLED_RECOMPUTE_PROPS
;
4696 return HANDLED_NORMALLY
;
4700 /* Set up the next overlay string for delivery by IT, if there is an
4701 overlay string to deliver. Called by set_iterator_to_next when the
4702 end of the current overlay string is reached. If there are more
4703 overlay strings to display, IT->string and
4704 IT->current.overlay_string_index are set appropriately here.
4705 Otherwise IT->string is set to nil. */
4708 next_overlay_string (struct it
*it
)
4710 ++it
->current
.overlay_string_index
;
4711 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4713 /* No more overlay strings. Restore IT's settings to what
4714 they were before overlay strings were processed, and
4715 continue to deliver from current_buffer. */
4717 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4720 || (NILP (it
->string
)
4721 && it
->method
== GET_FROM_BUFFER
4722 && it
->stop_charpos
>= BEGV
4723 && it
->stop_charpos
<= it
->end_charpos
));
4724 it
->current
.overlay_string_index
= -1;
4725 it
->n_overlay_strings
= 0;
4726 it
->overlay_strings_charpos
= -1;
4728 /* If we're at the end of the buffer, record that we have
4729 processed the overlay strings there already, so that
4730 next_element_from_buffer doesn't try it again. */
4731 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4732 it
->overlay_strings_at_end_processed_p
= 1;
4736 /* There are more overlay strings to process. If
4737 IT->current.overlay_string_index has advanced to a position
4738 where we must load IT->overlay_strings with more strings, do
4739 it. We must load at the IT->overlay_strings_charpos where
4740 IT->n_overlay_strings was originally computed; when invisible
4741 text is present, this might not be IT_CHARPOS (Bug#7016). */
4742 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4744 if (it
->current
.overlay_string_index
&& i
== 0)
4745 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4747 /* Initialize IT to deliver display elements from the overlay
4749 it
->string
= it
->overlay_strings
[i
];
4750 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4751 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4752 it
->method
= GET_FROM_STRING
;
4753 it
->stop_charpos
= 0;
4754 if (it
->cmp_it
.stop_pos
>= 0)
4755 it
->cmp_it
.stop_pos
= 0;
4762 /* Compare two overlay_entry structures E1 and E2. Used as a
4763 comparison function for qsort in load_overlay_strings. Overlay
4764 strings for the same position are sorted so that
4766 1. All after-strings come in front of before-strings, except
4767 when they come from the same overlay.
4769 2. Within after-strings, strings are sorted so that overlay strings
4770 from overlays with higher priorities come first.
4772 2. Within before-strings, strings are sorted so that overlay
4773 strings from overlays with higher priorities come last.
4775 Value is analogous to strcmp. */
4779 compare_overlay_entries (const void *e1
, const void *e2
)
4781 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4782 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4785 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4787 /* Let after-strings appear in front of before-strings if
4788 they come from different overlays. */
4789 if (EQ (entry1
->overlay
, entry2
->overlay
))
4790 result
= entry1
->after_string_p
? 1 : -1;
4792 result
= entry1
->after_string_p
? -1 : 1;
4794 else if (entry1
->after_string_p
)
4795 /* After-strings sorted in order of decreasing priority. */
4796 result
= entry2
->priority
- entry1
->priority
;
4798 /* Before-strings sorted in order of increasing priority. */
4799 result
= entry1
->priority
- entry2
->priority
;
4805 /* Load the vector IT->overlay_strings with overlay strings from IT's
4806 current buffer position, or from CHARPOS if that is > 0. Set
4807 IT->n_overlays to the total number of overlay strings found.
4809 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4810 a time. On entry into load_overlay_strings,
4811 IT->current.overlay_string_index gives the number of overlay
4812 strings that have already been loaded by previous calls to this
4815 IT->add_overlay_start contains an additional overlay start
4816 position to consider for taking overlay strings from, if non-zero.
4817 This position comes into play when the overlay has an `invisible'
4818 property, and both before and after-strings. When we've skipped to
4819 the end of the overlay, because of its `invisible' property, we
4820 nevertheless want its before-string to appear.
4821 IT->add_overlay_start will contain the overlay start position
4824 Overlay strings are sorted so that after-string strings come in
4825 front of before-string strings. Within before and after-strings,
4826 strings are sorted by overlay priority. See also function
4827 compare_overlay_entries. */
4830 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4832 Lisp_Object overlay
, window
, str
, invisible
;
4833 struct Lisp_Overlay
*ov
;
4834 EMACS_INT start
, end
;
4836 int n
= 0, i
, j
, invis_p
;
4837 struct overlay_entry
*entries
4838 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4841 charpos
= IT_CHARPOS (*it
);
4843 /* Append the overlay string STRING of overlay OVERLAY to vector
4844 `entries' which has size `size' and currently contains `n'
4845 elements. AFTER_P non-zero means STRING is an after-string of
4847 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4850 Lisp_Object priority; \
4854 int new_size = 2 * size; \
4855 struct overlay_entry *old = entries; \
4857 (struct overlay_entry *) alloca (new_size \
4858 * sizeof *entries); \
4859 memcpy (entries, old, size * sizeof *entries); \
4863 entries[n].string = (STRING); \
4864 entries[n].overlay = (OVERLAY); \
4865 priority = Foverlay_get ((OVERLAY), Qpriority); \
4866 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4867 entries[n].after_string_p = (AFTER_P); \
4872 /* Process overlay before the overlay center. */
4873 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4875 XSETMISC (overlay
, ov
);
4876 xassert (OVERLAYP (overlay
));
4877 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4878 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4883 /* Skip this overlay if it doesn't start or end at IT's current
4885 if (end
!= charpos
&& start
!= charpos
)
4888 /* Skip this overlay if it doesn't apply to IT->w. */
4889 window
= Foverlay_get (overlay
, Qwindow
);
4890 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4893 /* If the text ``under'' the overlay is invisible, both before-
4894 and after-strings from this overlay are visible; start and
4895 end position are indistinguishable. */
4896 invisible
= Foverlay_get (overlay
, Qinvisible
);
4897 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4899 /* If overlay has a non-empty before-string, record it. */
4900 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4901 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4903 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4905 /* If overlay has a non-empty after-string, record it. */
4906 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4907 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4909 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4912 /* Process overlays after the overlay center. */
4913 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4915 XSETMISC (overlay
, ov
);
4916 xassert (OVERLAYP (overlay
));
4917 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4918 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4920 if (start
> charpos
)
4923 /* Skip this overlay if it doesn't start or end at IT's current
4925 if (end
!= charpos
&& start
!= charpos
)
4928 /* Skip this overlay if it doesn't apply to IT->w. */
4929 window
= Foverlay_get (overlay
, Qwindow
);
4930 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4933 /* If the text ``under'' the overlay is invisible, it has a zero
4934 dimension, and both before- and after-strings apply. */
4935 invisible
= Foverlay_get (overlay
, Qinvisible
);
4936 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4938 /* If overlay has a non-empty before-string, record it. */
4939 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4940 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4942 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4944 /* If overlay has a non-empty after-string, record it. */
4945 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4946 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4948 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4951 #undef RECORD_OVERLAY_STRING
4955 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4957 /* Record number of overlay strings, and where we computed it. */
4958 it
->n_overlay_strings
= n
;
4959 it
->overlay_strings_charpos
= charpos
;
4961 /* IT->current.overlay_string_index is the number of overlay strings
4962 that have already been consumed by IT. Copy some of the
4963 remaining overlay strings to IT->overlay_strings. */
4965 j
= it
->current
.overlay_string_index
;
4966 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4968 it
->overlay_strings
[i
] = entries
[j
].string
;
4969 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4976 /* Get the first chunk of overlay strings at IT's current buffer
4977 position, or at CHARPOS if that is > 0. Value is non-zero if at
4978 least one overlay string was found. */
4981 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
4983 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4984 process. This fills IT->overlay_strings with strings, and sets
4985 IT->n_overlay_strings to the total number of strings to process.
4986 IT->pos.overlay_string_index has to be set temporarily to zero
4987 because load_overlay_strings needs this; it must be set to -1
4988 when no overlay strings are found because a zero value would
4989 indicate a position in the first overlay string. */
4990 it
->current
.overlay_string_index
= 0;
4991 load_overlay_strings (it
, charpos
);
4993 /* If we found overlay strings, set up IT to deliver display
4994 elements from the first one. Otherwise set up IT to deliver
4995 from current_buffer. */
4996 if (it
->n_overlay_strings
)
4998 /* Make sure we know settings in current_buffer, so that we can
4999 restore meaningful values when we're done with the overlay
5002 compute_stop_pos (it
);
5003 xassert (it
->face_id
>= 0);
5005 /* Save IT's settings. They are restored after all overlay
5006 strings have been processed. */
5007 xassert (!compute_stop_p
|| it
->sp
== 0);
5009 /* When called from handle_stop, there might be an empty display
5010 string loaded. In that case, don't bother saving it. */
5011 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5014 /* Set up IT to deliver display elements from the first overlay
5016 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5017 it
->string
= it
->overlay_strings
[0];
5018 it
->from_overlay
= Qnil
;
5019 it
->stop_charpos
= 0;
5020 xassert (STRINGP (it
->string
));
5021 it
->end_charpos
= SCHARS (it
->string
);
5022 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5023 it
->method
= GET_FROM_STRING
;
5027 it
->current
.overlay_string_index
= -1;
5032 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5035 it
->method
= GET_FROM_BUFFER
;
5037 (void) get_overlay_strings_1 (it
, charpos
, 1);
5041 /* Value is non-zero if we found at least one overlay string. */
5042 return STRINGP (it
->string
);
5047 /***********************************************************************
5048 Saving and restoring state
5049 ***********************************************************************/
5051 /* Save current settings of IT on IT->stack. Called, for example,
5052 before setting up IT for an overlay string, to be able to restore
5053 IT's settings to what they were after the overlay string has been
5054 processed. If POSITION is non-NULL, it is the position to save on
5055 the stack instead of IT->position. */
5058 push_it (struct it
*it
, struct text_pos
*position
)
5060 struct iterator_stack_entry
*p
;
5062 xassert (it
->sp
< IT_STACK_SIZE
);
5063 p
= it
->stack
+ it
->sp
;
5065 p
->stop_charpos
= it
->stop_charpos
;
5066 p
->prev_stop
= it
->prev_stop
;
5067 p
->base_level_stop
= it
->base_level_stop
;
5068 p
->cmp_it
= it
->cmp_it
;
5069 xassert (it
->face_id
>= 0);
5070 p
->face_id
= it
->face_id
;
5071 p
->string
= it
->string
;
5072 p
->method
= it
->method
;
5073 p
->from_overlay
= it
->from_overlay
;
5076 case GET_FROM_IMAGE
:
5077 p
->u
.image
.object
= it
->object
;
5078 p
->u
.image
.image_id
= it
->image_id
;
5079 p
->u
.image
.slice
= it
->slice
;
5081 case GET_FROM_STRETCH
:
5082 p
->u
.stretch
.object
= it
->object
;
5085 p
->position
= position
? *position
: it
->position
;
5086 p
->current
= it
->current
;
5087 p
->end_charpos
= it
->end_charpos
;
5088 p
->string_nchars
= it
->string_nchars
;
5090 p
->multibyte_p
= it
->multibyte_p
;
5091 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5092 p
->space_width
= it
->space_width
;
5093 p
->font_height
= it
->font_height
;
5094 p
->voffset
= it
->voffset
;
5095 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5096 p
->display_ellipsis_p
= 0;
5097 p
->line_wrap
= it
->line_wrap
;
5102 iterate_out_of_display_property (struct it
*it
)
5104 /* Maybe initialize paragraph direction. If we are at the beginning
5105 of a new paragraph, next_element_from_buffer may not have a
5106 chance to do that. */
5107 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5108 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5109 /* prev_stop can be zero, so check against BEGV as well. */
5110 while (it
->bidi_it
.charpos
>= BEGV
5111 && it
->prev_stop
<= it
->bidi_it
.charpos
5112 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5113 bidi_move_to_visually_next (&it
->bidi_it
);
5114 /* Record the stop_pos we just crossed, for when we cross it
5116 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5117 it
->prev_stop
= CHARPOS (it
->position
);
5118 /* If we ended up not where pop_it put us, resync IT's
5119 positional members with the bidi iterator. */
5120 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5122 SET_TEXT_POS (it
->position
,
5123 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5124 it
->current
.pos
= it
->position
;
5128 /* Restore IT's settings from IT->stack. Called, for example, when no
5129 more overlay strings must be processed, and we return to delivering
5130 display elements from a buffer, or when the end of a string from a
5131 `display' property is reached and we return to delivering display
5132 elements from an overlay string, or from a buffer. */
5135 pop_it (struct it
*it
)
5137 struct iterator_stack_entry
*p
;
5139 xassert (it
->sp
> 0);
5141 p
= it
->stack
+ it
->sp
;
5142 it
->stop_charpos
= p
->stop_charpos
;
5143 it
->prev_stop
= p
->prev_stop
;
5144 it
->base_level_stop
= p
->base_level_stop
;
5145 it
->cmp_it
= p
->cmp_it
;
5146 it
->face_id
= p
->face_id
;
5147 it
->current
= p
->current
;
5148 it
->position
= p
->position
;
5149 it
->string
= p
->string
;
5150 it
->from_overlay
= p
->from_overlay
;
5151 if (NILP (it
->string
))
5152 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5153 it
->method
= p
->method
;
5156 case GET_FROM_IMAGE
:
5157 it
->image_id
= p
->u
.image
.image_id
;
5158 it
->object
= p
->u
.image
.object
;
5159 it
->slice
= p
->u
.image
.slice
;
5161 case GET_FROM_STRETCH
:
5162 it
->object
= p
->u
.comp
.object
;
5164 case GET_FROM_BUFFER
:
5165 it
->object
= it
->w
->buffer
;
5168 /* Bidi-iterate until we get out of the portion of text, if
5169 any, covered by a `display' text property or an overlay
5170 with `display' property. (We cannot just jump there,
5171 because the internal coherency of the bidi iterator state
5172 can not be preserved across such jumps.) We also must
5173 determine the paragraph base direction if the overlay we
5174 just processed is at the beginning of a new
5176 iterate_out_of_display_property (it
);
5179 case GET_FROM_STRING
:
5180 it
->object
= it
->string
;
5182 case GET_FROM_DISPLAY_VECTOR
:
5184 it
->method
= GET_FROM_C_STRING
;
5185 else if (STRINGP (it
->string
))
5186 it
->method
= GET_FROM_STRING
;
5189 it
->method
= GET_FROM_BUFFER
;
5190 it
->object
= it
->w
->buffer
;
5193 it
->end_charpos
= p
->end_charpos
;
5194 it
->string_nchars
= p
->string_nchars
;
5196 it
->multibyte_p
= p
->multibyte_p
;
5197 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5198 it
->space_width
= p
->space_width
;
5199 it
->font_height
= p
->font_height
;
5200 it
->voffset
= p
->voffset
;
5201 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5202 it
->line_wrap
= p
->line_wrap
;
5207 /***********************************************************************
5209 ***********************************************************************/
5211 /* Set IT's current position to the previous line start. */
5214 back_to_previous_line_start (struct it
*it
)
5216 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5217 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5221 /* Move IT to the next line start.
5223 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5224 we skipped over part of the text (as opposed to moving the iterator
5225 continuously over the text). Otherwise, don't change the value
5228 Newlines may come from buffer text, overlay strings, or strings
5229 displayed via the `display' property. That's the reason we can't
5230 simply use find_next_newline_no_quit.
5232 Note that this function may not skip over invisible text that is so
5233 because of text properties and immediately follows a newline. If
5234 it would, function reseat_at_next_visible_line_start, when called
5235 from set_iterator_to_next, would effectively make invisible
5236 characters following a newline part of the wrong glyph row, which
5237 leads to wrong cursor motion. */
5240 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5242 int old_selective
, newline_found_p
, n
;
5243 const int MAX_NEWLINE_DISTANCE
= 500;
5245 /* If already on a newline, just consume it to avoid unintended
5246 skipping over invisible text below. */
5247 if (it
->what
== IT_CHARACTER
5249 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5251 set_iterator_to_next (it
, 0);
5256 /* Don't handle selective display in the following. It's (a)
5257 unnecessary because it's done by the caller, and (b) leads to an
5258 infinite recursion because next_element_from_ellipsis indirectly
5259 calls this function. */
5260 old_selective
= it
->selective
;
5263 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5264 from buffer text. */
5265 for (n
= newline_found_p
= 0;
5266 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5267 n
+= STRINGP (it
->string
) ? 0 : 1)
5269 if (!get_next_display_element (it
))
5271 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5272 set_iterator_to_next (it
, 0);
5275 /* If we didn't find a newline near enough, see if we can use a
5277 if (!newline_found_p
)
5279 EMACS_INT start
= IT_CHARPOS (*it
);
5280 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5283 xassert (!STRINGP (it
->string
));
5285 /* If there isn't any `display' property in sight, and no
5286 overlays, we can just use the position of the newline in
5288 if (it
->stop_charpos
>= limit
5289 || ((pos
= Fnext_single_property_change (make_number (start
),
5291 Qnil
, make_number (limit
)),
5293 && next_overlay_change (start
) == ZV
))
5295 IT_CHARPOS (*it
) = limit
;
5296 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5297 *skipped_p
= newline_found_p
= 1;
5301 while (get_next_display_element (it
)
5302 && !newline_found_p
)
5304 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5305 set_iterator_to_next (it
, 0);
5310 it
->selective
= old_selective
;
5311 return newline_found_p
;
5315 /* Set IT's current position to the previous visible line start. Skip
5316 invisible text that is so either due to text properties or due to
5317 selective display. Caution: this does not change IT->current_x and
5321 back_to_previous_visible_line_start (struct it
*it
)
5323 while (IT_CHARPOS (*it
) > BEGV
)
5325 back_to_previous_line_start (it
);
5327 if (IT_CHARPOS (*it
) <= BEGV
)
5330 /* If selective > 0, then lines indented more than its value are
5332 if (it
->selective
> 0
5333 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5334 (double) it
->selective
)) /* iftc */
5337 /* Check the newline before point for invisibility. */
5340 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5341 Qinvisible
, it
->window
);
5342 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5346 if (IT_CHARPOS (*it
) <= BEGV
)
5353 Lisp_Object val
, overlay
;
5355 /* If newline is part of a composition, continue from start of composition */
5356 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5357 && beg
< IT_CHARPOS (*it
))
5360 /* If newline is replaced by a display property, find start of overlay
5361 or interval and continue search from that point. */
5363 pos
= --IT_CHARPOS (it2
);
5366 it2
.string_from_display_prop_p
= 0;
5367 if (handle_display_prop (&it2
) == HANDLED_RETURN
5368 && !NILP (val
= get_char_property_and_overlay
5369 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5370 && (OVERLAYP (overlay
)
5371 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5372 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5375 /* Newline is not replaced by anything -- so we are done. */
5381 IT_CHARPOS (*it
) = beg
;
5382 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5386 it
->continuation_lines_width
= 0;
5388 xassert (IT_CHARPOS (*it
) >= BEGV
);
5389 xassert (IT_CHARPOS (*it
) == BEGV
5390 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5395 /* Reseat iterator IT at the previous visible line start. Skip
5396 invisible text that is so either due to text properties or due to
5397 selective display. At the end, update IT's overlay information,
5398 face information etc. */
5401 reseat_at_previous_visible_line_start (struct it
*it
)
5403 back_to_previous_visible_line_start (it
);
5404 reseat (it
, it
->current
.pos
, 1);
5409 /* Reseat iterator IT on the next visible line start in the current
5410 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5411 preceding the line start. Skip over invisible text that is so
5412 because of selective display. Compute faces, overlays etc at the
5413 new position. Note that this function does not skip over text that
5414 is invisible because of text properties. */
5417 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5419 int newline_found_p
, skipped_p
= 0;
5421 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5423 /* Skip over lines that are invisible because they are indented
5424 more than the value of IT->selective. */
5425 if (it
->selective
> 0)
5426 while (IT_CHARPOS (*it
) < ZV
5427 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5428 (double) it
->selective
)) /* iftc */
5430 xassert (IT_BYTEPOS (*it
) == BEGV
5431 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5432 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5435 /* Position on the newline if that's what's requested. */
5436 if (on_newline_p
&& newline_found_p
)
5438 if (STRINGP (it
->string
))
5440 if (IT_STRING_CHARPOS (*it
) > 0)
5442 --IT_STRING_CHARPOS (*it
);
5443 --IT_STRING_BYTEPOS (*it
);
5446 else if (IT_CHARPOS (*it
) > BEGV
)
5450 reseat (it
, it
->current
.pos
, 0);
5454 reseat (it
, it
->current
.pos
, 0);
5461 /***********************************************************************
5462 Changing an iterator's position
5463 ***********************************************************************/
5465 /* Change IT's current position to POS in current_buffer. If FORCE_P
5466 is non-zero, always check for text properties at the new position.
5467 Otherwise, text properties are only looked up if POS >=
5468 IT->check_charpos of a property. */
5471 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5473 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5475 reseat_1 (it
, pos
, 0);
5477 /* Determine where to check text properties. Avoid doing it
5478 where possible because text property lookup is very expensive. */
5480 || CHARPOS (pos
) > it
->stop_charpos
5481 || CHARPOS (pos
) < original_pos
)
5485 /* For bidi iteration, we need to prime prev_stop and
5486 base_level_stop with our best estimations. */
5487 if (CHARPOS (pos
) < it
->prev_stop
)
5489 handle_stop_backwards (it
, BEGV
);
5490 if (CHARPOS (pos
) < it
->base_level_stop
)
5491 it
->base_level_stop
= 0;
5493 else if (CHARPOS (pos
) > it
->stop_charpos
5494 && it
->stop_charpos
>= BEGV
)
5495 handle_stop_backwards (it
, it
->stop_charpos
);
5502 it
->prev_stop
= it
->base_level_stop
= 0;
5511 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5512 IT->stop_pos to POS, also. */
5515 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5517 /* Don't call this function when scanning a C string. */
5518 xassert (it
->s
== NULL
);
5520 /* POS must be a reasonable value. */
5521 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5523 it
->current
.pos
= it
->position
= pos
;
5524 it
->end_charpos
= ZV
;
5526 it
->current
.dpvec_index
= -1;
5527 it
->current
.overlay_string_index
= -1;
5528 IT_STRING_CHARPOS (*it
) = -1;
5529 IT_STRING_BYTEPOS (*it
) = -1;
5531 it
->string_from_display_prop_p
= 0;
5532 it
->method
= GET_FROM_BUFFER
;
5533 it
->object
= it
->w
->buffer
;
5534 it
->area
= TEXT_AREA
;
5535 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5537 it
->string_from_display_prop_p
= 0;
5538 it
->face_before_selective_p
= 0;
5541 it
->bidi_it
.first_elt
= 1;
5542 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5543 it
->bidi_it
.disp_pos
= -1;
5544 it
->bidi_it
.string
.s
= NULL
;
5545 it
->bidi_it
.string
.lstring
= Qnil
;
5546 it
->bidi_it
.string
.bufpos
= 0;
5551 it
->stop_charpos
= CHARPOS (pos
);
5552 it
->base_level_stop
= CHARPOS (pos
);
5557 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5558 If S is non-null, it is a C string to iterate over. Otherwise,
5559 STRING gives a Lisp string to iterate over.
5561 If PRECISION > 0, don't return more then PRECISION number of
5562 characters from the string.
5564 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5565 characters have been returned. FIELD_WIDTH < 0 means an infinite
5568 MULTIBYTE = 0 means disable processing of multibyte characters,
5569 MULTIBYTE > 0 means enable it,
5570 MULTIBYTE < 0 means use IT->multibyte_p.
5572 IT must be initialized via a prior call to init_iterator before
5573 calling this function. */
5576 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5577 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5580 /* No region in strings. */
5581 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5583 /* No text property checks performed by default, but see below. */
5584 it
->stop_charpos
= -1;
5586 /* Set iterator position and end position. */
5587 memset (&it
->current
, 0, sizeof it
->current
);
5588 it
->current
.overlay_string_index
= -1;
5589 it
->current
.dpvec_index
= -1;
5590 xassert (charpos
>= 0);
5592 /* If STRING is specified, use its multibyteness, otherwise use the
5593 setting of MULTIBYTE, if specified. */
5595 it
->multibyte_p
= multibyte
> 0;
5599 xassert (STRINGP (string
));
5600 it
->string
= string
;
5602 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5603 it
->method
= GET_FROM_STRING
;
5604 it
->current
.string_pos
= string_pos (charpos
, string
);
5608 it
->paragraph_embedding
= NEUTRAL_DIR
;
5609 it
->bidi_it
.string
.lstring
= string
;
5610 it
->bidi_it
.string
.s
= SDATA (string
);
5611 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5612 it
->bidi_it
.string
.bufpos
= 0;
5613 it
->bidi_it
.string
.from_disp_str
= 0;
5614 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5615 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5620 it
->s
= (const unsigned char *) s
;
5623 /* Note that we use IT->current.pos, not it->current.string_pos,
5624 for displaying C strings. */
5625 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5626 if (it
->multibyte_p
)
5628 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5629 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5633 it
->paragraph_embedding
= NEUTRAL_DIR
;
5634 it
->bidi_it
.string
.lstring
= Qnil
;
5635 it
->bidi_it
.string
.s
= s
;
5636 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5637 it
->bidi_it
.string
.bufpos
= 0;
5638 it
->bidi_it
.string
.from_disp_str
= 0;
5639 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5645 /* Unibyte (a.k.a. ASCII) C strings are never bidi-reordered. */
5646 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5647 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5650 it
->method
= GET_FROM_C_STRING
;
5653 /* PRECISION > 0 means don't return more than PRECISION characters
5655 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5657 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5659 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5662 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5663 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5664 FIELD_WIDTH < 0 means infinite field width. This is useful for
5665 padding with `-' at the end of a mode line. */
5666 if (field_width
< 0)
5667 field_width
= INFINITY
;
5668 /* Implementation note: We deliberately don't enlarge
5669 it->bidi_it.string.schars here to fit it->end_charpos, because
5670 the bidi iterator cannot produce characters out of thin air. */
5671 if (field_width
> it
->end_charpos
- charpos
)
5672 it
->end_charpos
= charpos
+ field_width
;
5674 /* Use the standard display table for displaying strings. */
5675 if (DISP_TABLE_P (Vstandard_display_table
))
5676 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5678 it
->stop_charpos
= charpos
;
5679 it
->prev_stop
= charpos
;
5680 it
->base_level_stop
= 0;
5683 it
->bidi_it
.first_elt
= 1;
5684 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5685 it
->bidi_it
.disp_pos
= -1;
5687 if (s
== NULL
&& it
->multibyte_p
)
5689 EMACS_INT endpos
= SCHARS (it
->string
);
5690 if (endpos
> it
->end_charpos
)
5691 endpos
= it
->end_charpos
;
5692 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5700 /***********************************************************************
5702 ***********************************************************************/
5704 /* Map enum it_method value to corresponding next_element_from_* function. */
5706 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5708 next_element_from_buffer
,
5709 next_element_from_display_vector
,
5710 next_element_from_string
,
5711 next_element_from_c_string
,
5712 next_element_from_image
,
5713 next_element_from_stretch
5716 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5719 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5720 (possibly with the following characters). */
5722 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5723 ((IT)->cmp_it.id >= 0 \
5724 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5725 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5726 END_CHARPOS, (IT)->w, \
5727 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5731 /* Lookup the char-table Vglyphless_char_display for character C (-1
5732 if we want information for no-font case), and return the display
5733 method symbol. By side-effect, update it->what and
5734 it->glyphless_method. This function is called from
5735 get_next_display_element for each character element, and from
5736 x_produce_glyphs when no suitable font was found. */
5739 lookup_glyphless_char_display (int c
, struct it
*it
)
5741 Lisp_Object glyphless_method
= Qnil
;
5743 if (CHAR_TABLE_P (Vglyphless_char_display
)
5744 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5748 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5749 if (CONSP (glyphless_method
))
5750 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5751 ? XCAR (glyphless_method
)
5752 : XCDR (glyphless_method
);
5755 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5759 if (NILP (glyphless_method
))
5762 /* The default is to display the character by a proper font. */
5764 /* The default for the no-font case is to display an empty box. */
5765 glyphless_method
= Qempty_box
;
5767 if (EQ (glyphless_method
, Qzero_width
))
5770 return glyphless_method
;
5771 /* This method can't be used for the no-font case. */
5772 glyphless_method
= Qempty_box
;
5774 if (EQ (glyphless_method
, Qthin_space
))
5775 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5776 else if (EQ (glyphless_method
, Qempty_box
))
5777 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5778 else if (EQ (glyphless_method
, Qhex_code
))
5779 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5780 else if (STRINGP (glyphless_method
))
5781 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5784 /* Invalid value. We use the default method. */
5785 glyphless_method
= Qnil
;
5788 it
->what
= IT_GLYPHLESS
;
5789 return glyphless_method
;
5792 /* Load IT's display element fields with information about the next
5793 display element from the current position of IT. Value is zero if
5794 end of buffer (or C string) is reached. */
5796 static struct frame
*last_escape_glyph_frame
= NULL
;
5797 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5798 static int last_escape_glyph_merged_face_id
= 0;
5800 struct frame
*last_glyphless_glyph_frame
= NULL
;
5801 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5802 int last_glyphless_glyph_merged_face_id
= 0;
5805 get_next_display_element (struct it
*it
)
5807 /* Non-zero means that we found a display element. Zero means that
5808 we hit the end of what we iterate over. Performance note: the
5809 function pointer `method' used here turns out to be faster than
5810 using a sequence of if-statements. */
5814 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5816 if (it
->what
== IT_CHARACTER
)
5818 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5819 and only if (a) the resolved directionality of that character
5821 /* FIXME: Do we need an exception for characters from display
5823 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5824 it
->c
= bidi_mirror_char (it
->c
);
5825 /* Map via display table or translate control characters.
5826 IT->c, IT->len etc. have been set to the next character by
5827 the function call above. If we have a display table, and it
5828 contains an entry for IT->c, translate it. Don't do this if
5829 IT->c itself comes from a display table, otherwise we could
5830 end up in an infinite recursion. (An alternative could be to
5831 count the recursion depth of this function and signal an
5832 error when a certain maximum depth is reached.) Is it worth
5834 if (success_p
&& it
->dpvec
== NULL
)
5837 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5838 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5839 nbsp_or_shy
= char_is_other
;
5840 int c
= it
->c
; /* This is the character to display. */
5842 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5844 xassert (SINGLE_BYTE_CHAR_P (c
));
5845 if (unibyte_display_via_language_environment
)
5847 c
= DECODE_CHAR (unibyte
, c
);
5849 c
= BYTE8_TO_CHAR (it
->c
);
5852 c
= BYTE8_TO_CHAR (it
->c
);
5856 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5859 struct Lisp_Vector
*v
= XVECTOR (dv
);
5861 /* Return the first character from the display table
5862 entry, if not empty. If empty, don't display the
5863 current character. */
5866 it
->dpvec_char_len
= it
->len
;
5867 it
->dpvec
= v
->contents
;
5868 it
->dpend
= v
->contents
+ v
->header
.size
;
5869 it
->current
.dpvec_index
= 0;
5870 it
->dpvec_face_id
= -1;
5871 it
->saved_face_id
= it
->face_id
;
5872 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5877 set_iterator_to_next (it
, 0);
5882 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5884 if (it
->what
== IT_GLYPHLESS
)
5886 /* Don't display this character. */
5887 set_iterator_to_next (it
, 0);
5891 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5892 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5893 : c
== 0xAD ? char_is_soft_hyphen
5896 /* Translate control characters into `\003' or `^C' form.
5897 Control characters coming from a display table entry are
5898 currently not translated because we use IT->dpvec to hold
5899 the translation. This could easily be changed but I
5900 don't believe that it is worth doing.
5902 NBSP and SOFT-HYPEN are property translated too.
5904 Non-printable characters and raw-byte characters are also
5905 translated to octal form. */
5906 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5907 ? (it
->area
!= TEXT_AREA
5908 /* In mode line, treat \n, \t like other crl chars. */
5911 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5912 || (c
!= '\n' && c
!= '\t'))
5915 || ! CHAR_PRINTABLE_P (c
))))
5917 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5918 or a non-printable character which must be displayed
5919 either as '\003' or as `^C' where the '\\' and '^'
5920 can be defined in the display table. Fill
5921 IT->ctl_chars with glyphs for what we have to
5922 display. Then, set IT->dpvec to these glyphs. */
5925 int face_id
, lface_id
= 0 ;
5928 /* Handle control characters with ^. */
5930 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5934 g
= '^'; /* default glyph for Control */
5935 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5937 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5938 && GLYPH_CODE_CHAR_VALID_P (gc
))
5940 g
= GLYPH_CODE_CHAR (gc
);
5941 lface_id
= GLYPH_CODE_FACE (gc
);
5945 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5947 else if (it
->f
== last_escape_glyph_frame
5948 && it
->face_id
== last_escape_glyph_face_id
)
5950 face_id
= last_escape_glyph_merged_face_id
;
5954 /* Merge the escape-glyph face into the current face. */
5955 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5957 last_escape_glyph_frame
= it
->f
;
5958 last_escape_glyph_face_id
= it
->face_id
;
5959 last_escape_glyph_merged_face_id
= face_id
;
5962 XSETINT (it
->ctl_chars
[0], g
);
5963 XSETINT (it
->ctl_chars
[1], c
^ 0100);
5965 goto display_control
;
5968 /* Handle non-break space in the mode where it only gets
5971 if (EQ (Vnobreak_char_display
, Qt
)
5972 && nbsp_or_shy
== char_is_nbsp
)
5974 /* Merge the no-break-space face into the current face. */
5975 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5979 XSETINT (it
->ctl_chars
[0], ' ');
5981 goto display_control
;
5984 /* Handle sequences that start with the "escape glyph". */
5986 /* the default escape glyph is \. */
5987 escape_glyph
= '\\';
5990 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5991 && GLYPH_CODE_CHAR_VALID_P (gc
))
5993 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5994 lface_id
= GLYPH_CODE_FACE (gc
);
5998 /* The display table specified a face.
5999 Merge it into face_id and also into escape_glyph. */
6000 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6003 else if (it
->f
== last_escape_glyph_frame
6004 && it
->face_id
== last_escape_glyph_face_id
)
6006 face_id
= last_escape_glyph_merged_face_id
;
6010 /* Merge the escape-glyph face into the current face. */
6011 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6013 last_escape_glyph_frame
= it
->f
;
6014 last_escape_glyph_face_id
= it
->face_id
;
6015 last_escape_glyph_merged_face_id
= face_id
;
6018 /* Handle soft hyphens in the mode where they only get
6021 if (EQ (Vnobreak_char_display
, Qt
)
6022 && nbsp_or_shy
== char_is_soft_hyphen
)
6024 XSETINT (it
->ctl_chars
[0], '-');
6026 goto display_control
;
6029 /* Handle non-break space and soft hyphen
6030 with the escape glyph. */
6034 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6035 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6036 XSETINT (it
->ctl_chars
[1], c
);
6038 goto display_control
;
6045 if (CHAR_BYTE8_P (c
))
6046 /* Display \200 instead of \17777600. */
6047 c
= CHAR_TO_BYTE8 (c
);
6048 len
= sprintf (str
, "%03o", c
);
6050 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6051 for (i
= 0; i
< len
; i
++)
6052 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6057 /* Set up IT->dpvec and return first character from it. */
6058 it
->dpvec_char_len
= it
->len
;
6059 it
->dpvec
= it
->ctl_chars
;
6060 it
->dpend
= it
->dpvec
+ ctl_len
;
6061 it
->current
.dpvec_index
= 0;
6062 it
->dpvec_face_id
= face_id
;
6063 it
->saved_face_id
= it
->face_id
;
6064 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6068 it
->char_to_display
= c
;
6072 it
->char_to_display
= it
->c
;
6076 /* Adjust face id for a multibyte character. There are no multibyte
6077 character in unibyte text. */
6078 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6081 && FRAME_WINDOW_P (it
->f
))
6083 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6085 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6087 /* Automatic composition with glyph-string. */
6088 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6090 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6094 EMACS_INT pos
= (it
->s
? -1
6095 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6096 : IT_CHARPOS (*it
));
6098 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6104 /* Is this character the last one of a run of characters with
6105 box? If yes, set IT->end_of_box_run_p to 1. */
6109 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6111 int face_id
= underlying_face_id (it
);
6112 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6116 if (face
->box
== FACE_NO_BOX
)
6118 /* If the box comes from face properties in a
6119 display string, check faces in that string. */
6120 int string_face_id
= face_after_it_pos (it
);
6121 it
->end_of_box_run_p
6122 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6125 /* Otherwise, the box comes from the underlying face.
6126 If this is the last string character displayed, check
6127 the next buffer location. */
6128 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6129 && (it
->current
.overlay_string_index
6130 == it
->n_overlay_strings
- 1))
6134 struct text_pos pos
= it
->current
.pos
;
6135 INC_TEXT_POS (pos
, it
->multibyte_p
);
6137 next_face_id
= face_at_buffer_position
6138 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6139 it
->region_end_charpos
, &ignore
,
6140 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6142 it
->end_of_box_run_p
6143 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6150 int face_id
= face_after_it_pos (it
);
6151 it
->end_of_box_run_p
6152 = (face_id
!= it
->face_id
6153 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6157 /* Value is 0 if end of buffer or string reached. */
6162 /* Move IT to the next display element.
6164 RESEAT_P non-zero means if called on a newline in buffer text,
6165 skip to the next visible line start.
6167 Functions get_next_display_element and set_iterator_to_next are
6168 separate because I find this arrangement easier to handle than a
6169 get_next_display_element function that also increments IT's
6170 position. The way it is we can first look at an iterator's current
6171 display element, decide whether it fits on a line, and if it does,
6172 increment the iterator position. The other way around we probably
6173 would either need a flag indicating whether the iterator has to be
6174 incremented the next time, or we would have to implement a
6175 decrement position function which would not be easy to write. */
6178 set_iterator_to_next (struct it
*it
, int reseat_p
)
6180 /* Reset flags indicating start and end of a sequence of characters
6181 with box. Reset them at the start of this function because
6182 moving the iterator to a new position might set them. */
6183 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6187 case GET_FROM_BUFFER
:
6188 /* The current display element of IT is a character from
6189 current_buffer. Advance in the buffer, and maybe skip over
6190 invisible lines that are so because of selective display. */
6191 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6192 reseat_at_next_visible_line_start (it
, 0);
6193 else if (it
->cmp_it
.id
>= 0)
6195 /* We are currently getting glyphs from a composition. */
6200 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6201 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6202 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6204 it
->cmp_it
.from
= it
->cmp_it
.to
;
6209 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6211 it
->end_charpos
, Qnil
);
6214 else if (! it
->cmp_it
.reversed_p
)
6216 /* Composition created while scanning forward. */
6217 /* Update IT's char/byte positions to point to the first
6218 character of the next grapheme cluster, or to the
6219 character visually after the current composition. */
6220 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6221 bidi_move_to_visually_next (&it
->bidi_it
);
6222 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6223 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6225 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6227 /* Proceed to the next grapheme cluster. */
6228 it
->cmp_it
.from
= it
->cmp_it
.to
;
6232 /* No more grapheme clusters in this composition.
6233 Find the next stop position. */
6234 EMACS_INT stop
= it
->end_charpos
;
6235 if (it
->bidi_it
.scan_dir
< 0)
6236 /* Now we are scanning backward and don't know
6239 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6240 IT_BYTEPOS (*it
), stop
, Qnil
);
6245 /* Composition created while scanning backward. */
6246 /* Update IT's char/byte positions to point to the last
6247 character of the previous grapheme cluster, or the
6248 character visually after the current composition. */
6249 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6250 bidi_move_to_visually_next (&it
->bidi_it
);
6251 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6252 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6253 if (it
->cmp_it
.from
> 0)
6255 /* Proceed to the previous grapheme cluster. */
6256 it
->cmp_it
.to
= it
->cmp_it
.from
;
6260 /* No more grapheme clusters in this composition.
6261 Find the next stop position. */
6262 EMACS_INT stop
= it
->end_charpos
;
6263 if (it
->bidi_it
.scan_dir
< 0)
6264 /* Now we are scanning backward and don't know
6267 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6268 IT_BYTEPOS (*it
), stop
, Qnil
);
6274 xassert (it
->len
!= 0);
6278 IT_BYTEPOS (*it
) += it
->len
;
6279 IT_CHARPOS (*it
) += 1;
6283 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6284 /* If this is a new paragraph, determine its base
6285 direction (a.k.a. its base embedding level). */
6286 if (it
->bidi_it
.new_paragraph
)
6287 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6288 bidi_move_to_visually_next (&it
->bidi_it
);
6289 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6290 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6291 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6293 /* As the scan direction was changed, we must
6294 re-compute the stop position for composition. */
6295 EMACS_INT stop
= it
->end_charpos
;
6296 if (it
->bidi_it
.scan_dir
< 0)
6298 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6299 IT_BYTEPOS (*it
), stop
, Qnil
);
6302 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6306 case GET_FROM_C_STRING
:
6307 /* Current display element of IT is from a C string. */
6309 /* If the string position is beyond string_nchars, it means
6310 next_element_from_c_string is padding the string with
6311 blanks, in which case we bypass the bidi iterator,
6312 because it cannot deal with such virtual characters. */
6313 || IT_CHARPOS (*it
) >= it
->string_nchars
)
6315 IT_BYTEPOS (*it
) += it
->len
;
6316 IT_CHARPOS (*it
) += 1;
6320 bidi_move_to_visually_next (&it
->bidi_it
);
6321 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6322 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6326 case GET_FROM_DISPLAY_VECTOR
:
6327 /* Current display element of IT is from a display table entry.
6328 Advance in the display table definition. Reset it to null if
6329 end reached, and continue with characters from buffers/
6331 ++it
->current
.dpvec_index
;
6333 /* Restore face of the iterator to what they were before the
6334 display vector entry (these entries may contain faces). */
6335 it
->face_id
= it
->saved_face_id
;
6337 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6339 int recheck_faces
= it
->ellipsis_p
;
6342 it
->method
= GET_FROM_C_STRING
;
6343 else if (STRINGP (it
->string
))
6344 it
->method
= GET_FROM_STRING
;
6347 it
->method
= GET_FROM_BUFFER
;
6348 it
->object
= it
->w
->buffer
;
6352 it
->current
.dpvec_index
= -1;
6354 /* Skip over characters which were displayed via IT->dpvec. */
6355 if (it
->dpvec_char_len
< 0)
6356 reseat_at_next_visible_line_start (it
, 1);
6357 else if (it
->dpvec_char_len
> 0)
6359 if (it
->method
== GET_FROM_STRING
6360 && it
->n_overlay_strings
> 0)
6361 it
->ignore_overlay_strings_at_pos_p
= 1;
6362 it
->len
= it
->dpvec_char_len
;
6363 set_iterator_to_next (it
, reseat_p
);
6366 /* Maybe recheck faces after display vector */
6368 it
->stop_charpos
= IT_CHARPOS (*it
);
6372 case GET_FROM_STRING
:
6373 /* Current display element is a character from a Lisp string. */
6374 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6375 if (it
->cmp_it
.id
>= 0)
6381 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6382 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6383 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6384 it
->cmp_it
.from
= it
->cmp_it
.to
;
6388 composition_compute_stop_pos (&it
->cmp_it
,
6389 IT_STRING_CHARPOS (*it
),
6390 IT_STRING_BYTEPOS (*it
),
6391 it
->end_charpos
, it
->string
);
6394 else if (! it
->cmp_it
.reversed_p
)
6396 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6397 bidi_move_to_visually_next (&it
->bidi_it
);
6398 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6399 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6401 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6402 it
->cmp_it
.from
= it
->cmp_it
.to
;
6405 EMACS_INT stop
= it
->end_charpos
;
6406 if (it
->bidi_it
.scan_dir
< 0)
6408 composition_compute_stop_pos (&it
->cmp_it
,
6409 IT_STRING_CHARPOS (*it
),
6410 IT_STRING_BYTEPOS (*it
), stop
,
6416 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6417 bidi_move_to_visually_next (&it
->bidi_it
);
6418 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6419 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6420 if (it
->cmp_it
.from
> 0)
6421 it
->cmp_it
.to
= it
->cmp_it
.from
;
6424 EMACS_INT stop
= it
->end_charpos
;
6425 if (it
->bidi_it
.scan_dir
< 0)
6427 composition_compute_stop_pos (&it
->cmp_it
,
6428 IT_STRING_CHARPOS (*it
),
6429 IT_STRING_BYTEPOS (*it
), stop
,
6437 /* If the string position is beyond string_nchars, it
6438 means next_element_from_string is padding the string
6439 with blanks, in which case we bypass the bidi
6440 iterator, because it cannot deal with such virtual
6442 || IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6444 IT_STRING_BYTEPOS (*it
) += it
->len
;
6445 IT_STRING_CHARPOS (*it
) += 1;
6449 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6451 bidi_move_to_visually_next (&it
->bidi_it
);
6452 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6453 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6454 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6456 EMACS_INT stop
= it
->end_charpos
;
6458 if (it
->bidi_it
.scan_dir
< 0)
6460 composition_compute_stop_pos (&it
->cmp_it
,
6461 IT_STRING_CHARPOS (*it
),
6462 IT_STRING_BYTEPOS (*it
), stop
,
6468 consider_string_end
:
6470 if (it
->current
.overlay_string_index
>= 0)
6472 /* IT->string is an overlay string. Advance to the
6473 next, if there is one. */
6474 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6477 next_overlay_string (it
);
6479 setup_for_ellipsis (it
, 0);
6484 /* IT->string is not an overlay string. If we reached
6485 its end, and there is something on IT->stack, proceed
6486 with what is on the stack. This can be either another
6487 string, this time an overlay string, or a buffer. */
6488 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6492 if (it
->method
== GET_FROM_STRING
)
6493 goto consider_string_end
;
6498 case GET_FROM_IMAGE
:
6499 case GET_FROM_STRETCH
:
6500 /* The position etc with which we have to proceed are on
6501 the stack. The position may be at the end of a string,
6502 if the `display' property takes up the whole string. */
6503 xassert (it
->sp
> 0);
6505 if (it
->method
== GET_FROM_STRING
)
6506 goto consider_string_end
;
6510 /* There are no other methods defined, so this should be a bug. */
6514 xassert (it
->method
!= GET_FROM_STRING
6515 || (STRINGP (it
->string
)
6516 && IT_STRING_CHARPOS (*it
) >= 0));
6519 /* Load IT's display element fields with information about the next
6520 display element which comes from a display table entry or from the
6521 result of translating a control character to one of the forms `^C'
6524 IT->dpvec holds the glyphs to return as characters.
6525 IT->saved_face_id holds the face id before the display vector--it
6526 is restored into IT->face_id in set_iterator_to_next. */
6529 next_element_from_display_vector (struct it
*it
)
6534 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6536 it
->face_id
= it
->saved_face_id
;
6538 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6539 That seemed totally bogus - so I changed it... */
6540 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6542 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6544 it
->c
= GLYPH_CODE_CHAR (gc
);
6545 it
->len
= CHAR_BYTES (it
->c
);
6547 /* The entry may contain a face id to use. Such a face id is
6548 the id of a Lisp face, not a realized face. A face id of
6549 zero means no face is specified. */
6550 if (it
->dpvec_face_id
>= 0)
6551 it
->face_id
= it
->dpvec_face_id
;
6554 int lface_id
= GLYPH_CODE_FACE (gc
);
6556 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6561 /* Display table entry is invalid. Return a space. */
6562 it
->c
= ' ', it
->len
= 1;
6564 /* Don't change position and object of the iterator here. They are
6565 still the values of the character that had this display table
6566 entry or was translated, and that's what we want. */
6567 it
->what
= IT_CHARACTER
;
6572 /* Load IT with the next display element from Lisp string IT->string.
6573 IT->current.string_pos is the current position within the string.
6574 If IT->current.overlay_string_index >= 0, the Lisp string is an
6578 next_element_from_string (struct it
*it
)
6580 struct text_pos position
;
6582 xassert (STRINGP (it
->string
));
6583 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6584 position
= it
->current
.string_pos
;
6586 /* With bidi reordering, the character to display might not be the
6587 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
6588 that we were reseat()ed to a new string, whose paragraph
6589 direction is not known. */
6590 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6592 it
->bidi_it
.charpos
= CHARPOS (position
);
6593 it
->bidi_it
.bytepos
= BYTEPOS (position
);
6594 if (it
->bidi_it
.charpos
>= it
->string_nchars
)
6596 /* Nothing to do, but reset the FIRST_ELT flag, like
6597 bidi_paragraph_init does, because we are not going to
6599 it
->bidi_it
.first_elt
= 0;
6601 else if (it
->bidi_it
.charpos
<= 0)
6603 /* If we are at the beginning of the string, we can produce
6604 the next element right away. */
6605 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6606 bidi_move_to_visually_next (&it
->bidi_it
);
6610 EMACS_INT orig_bytepos
= BYTEPOS (position
);
6612 /* We need to prime the bidi iterator starting at the string
6613 beginning, before we will be able to produce the next
6615 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
6616 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6619 /* Now return to buffer position where we were asked to
6620 get the next display element, and produce that. */
6621 bidi_move_to_visually_next (&it
->bidi_it
);
6623 while (it
->bidi_it
.bytepos
!= orig_bytepos
6624 && it
->bidi_it
.charpos
< it
->string_nchars
);
6627 /* Adjust IT's position information to where we ended up. */
6628 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6629 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6630 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
6632 EMACS_INT stop
= SCHARS (it
->string
);
6634 if (it
->bidi_it
.scan_dir
< 0)
6636 else if (stop
> it
->end_charpos
)
6637 stop
= it
->end_charpos
;
6638 composition_compute_stop_pos (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6639 IT_STRING_BYTEPOS (*it
), stop
,
6644 /* Time to check for invisible text? */
6645 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
6647 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
6650 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6651 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
6653 /* With bidi non-linear iteration, we could find
6654 ourselves far beyond the last computed stop_charpos,
6655 with several other stop positions in between that we
6656 missed. Scan them all now, in buffer's logical
6657 order, until we find and handle the last stop_charpos
6658 that precedes our current position. */
6659 handle_stop_backwards (it
, it
->stop_charpos
);
6660 return GET_NEXT_DISPLAY_ELEMENT (it
);
6666 /* Take note of the stop position we just moved
6667 across, for when we will move back across it. */
6668 it
->prev_stop
= it
->stop_charpos
;
6669 /* If we are at base paragraph embedding level, take
6670 note of the last stop position seen at this
6672 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6673 it
->base_level_stop
= it
->stop_charpos
;
6677 /* Since a handler may have changed IT->method, we must
6679 return GET_NEXT_DISPLAY_ELEMENT (it
);
6683 /* If we are before prev_stop, we may have overstepped
6684 on our way backwards a stop_pos, and if so, we need
6685 to handle that stop_pos. */
6686 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
6687 /* We can sometimes back up for reasons that have nothing
6688 to do with bidi reordering. E.g., compositions. The
6689 code below is only needed when we are above the base
6690 embedding level, so test for that explicitly. */
6691 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6693 /* If we lost track of base_level_stop, we have no better place
6694 for handle_stop_backwards to start from than BEGV. This
6695 happens, e.g., when we were reseated to the previous
6696 screenful of text by vertical-motion. */
6697 if (it
->base_level_stop
<= 0
6698 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
6699 it
->base_level_stop
= 0;
6700 handle_stop_backwards (it
, it
->base_level_stop
);
6701 return GET_NEXT_DISPLAY_ELEMENT (it
);
6705 if (it
->current
.overlay_string_index
>= 0)
6707 /* Get the next character from an overlay string. In overlay
6708 strings, There is no field width or padding with spaces to
6710 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6715 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6716 IT_STRING_BYTEPOS (*it
),
6717 it
->bidi_it
.scan_dir
< 0
6719 : SCHARS (it
->string
))
6720 && next_element_from_composition (it
))
6724 else if (STRING_MULTIBYTE (it
->string
))
6726 const unsigned char *s
= (SDATA (it
->string
)
6727 + IT_STRING_BYTEPOS (*it
));
6728 it
->c
= string_char_and_length (s
, &it
->len
);
6732 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6738 /* Get the next character from a Lisp string that is not an
6739 overlay string. Such strings come from the mode line, for
6740 example. We may have to pad with spaces, or truncate the
6741 string. See also next_element_from_c_string. */
6742 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6747 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6749 /* Pad with spaces. */
6750 it
->c
= ' ', it
->len
= 1;
6751 CHARPOS (position
) = BYTEPOS (position
) = -1;
6753 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6754 IT_STRING_BYTEPOS (*it
),
6755 it
->bidi_it
.scan_dir
< 0
6757 : it
->string_nchars
)
6758 && next_element_from_composition (it
))
6762 else if (STRING_MULTIBYTE (it
->string
))
6764 const unsigned char *s
= (SDATA (it
->string
)
6765 + IT_STRING_BYTEPOS (*it
));
6766 it
->c
= string_char_and_length (s
, &it
->len
);
6770 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6775 /* Record what we have and where it came from. */
6776 it
->what
= IT_CHARACTER
;
6777 it
->object
= it
->string
;
6778 it
->position
= position
;
6783 /* Load IT with next display element from C string IT->s.
6784 IT->string_nchars is the maximum number of characters to return
6785 from the string. IT->end_charpos may be greater than
6786 IT->string_nchars when this function is called, in which case we
6787 may have to return padding spaces. Value is zero if end of string
6788 reached, including padding spaces. */
6791 next_element_from_c_string (struct it
*it
)
6796 it
->what
= IT_CHARACTER
;
6797 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6800 /* IT's position can be greater IT->string_nchars in case a field
6801 width or precision has been specified when the iterator was
6803 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6805 /* End of the game. */
6809 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6811 /* Pad with spaces. */
6812 it
->c
= ' ', it
->len
= 1;
6813 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6815 else if (it
->multibyte_p
)
6816 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6818 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6824 /* Set up IT to return characters from an ellipsis, if appropriate.
6825 The definition of the ellipsis glyphs may come from a display table
6826 entry. This function fills IT with the first glyph from the
6827 ellipsis if an ellipsis is to be displayed. */
6830 next_element_from_ellipsis (struct it
*it
)
6832 if (it
->selective_display_ellipsis_p
)
6833 setup_for_ellipsis (it
, it
->len
);
6836 /* The face at the current position may be different from the
6837 face we find after the invisible text. Remember what it
6838 was in IT->saved_face_id, and signal that it's there by
6839 setting face_before_selective_p. */
6840 it
->saved_face_id
= it
->face_id
;
6841 it
->method
= GET_FROM_BUFFER
;
6842 it
->object
= it
->w
->buffer
;
6843 reseat_at_next_visible_line_start (it
, 1);
6844 it
->face_before_selective_p
= 1;
6847 return GET_NEXT_DISPLAY_ELEMENT (it
);
6851 /* Deliver an image display element. The iterator IT is already
6852 filled with image information (done in handle_display_prop). Value
6857 next_element_from_image (struct it
*it
)
6859 it
->what
= IT_IMAGE
;
6860 it
->ignore_overlay_strings_at_pos_p
= 0;
6865 /* Fill iterator IT with next display element from a stretch glyph
6866 property. IT->object is the value of the text property. Value is
6870 next_element_from_stretch (struct it
*it
)
6872 it
->what
= IT_STRETCH
;
6876 /* Scan forward from CHARPOS in the current buffer/string, until we
6877 find a stop position > current IT's position. Then handle the stop
6878 position before that. This is called when we bump into a stop
6879 position while reordering bidirectional text. CHARPOS should be
6880 the last previously processed stop_pos (or BEGV/0, if none were
6881 processed yet) whose position is less that IT's current
6885 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
6887 int bufp
= !STRINGP (it
->string
);
6888 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
6889 struct display_pos save_current
= it
->current
;
6890 struct text_pos save_position
= it
->position
;
6891 struct text_pos pos1
;
6892 EMACS_INT next_stop
;
6894 /* Scan in strict logical order. */
6898 it
->prev_stop
= charpos
;
6901 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6902 reseat_1 (it
, pos1
, 0);
6905 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
6906 compute_stop_pos (it
);
6907 /* We must advance forward, right? */
6908 if (it
->stop_charpos
<= it
->prev_stop
)
6910 charpos
= it
->stop_charpos
;
6912 while (charpos
<= where_we_are
);
6914 next_stop
= it
->stop_charpos
;
6915 it
->stop_charpos
= it
->prev_stop
;
6917 it
->current
= save_current
;
6918 it
->position
= save_position
;
6920 it
->stop_charpos
= next_stop
;
6923 /* Load IT with the next display element from current_buffer. Value
6924 is zero if end of buffer reached. IT->stop_charpos is the next
6925 position at which to stop and check for text properties or buffer
6929 next_element_from_buffer (struct it
*it
)
6933 xassert (IT_CHARPOS (*it
) >= BEGV
);
6935 /* With bidi reordering, the character to display might not be the
6936 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6937 we were reseat()ed to a new buffer position, which is potentially
6938 a different paragraph. */
6939 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6941 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6942 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6943 if (it
->bidi_it
.bytepos
== ZV_BYTE
)
6945 /* Nothing to do, but reset the FIRST_ELT flag, like
6946 bidi_paragraph_init does, because we are not going to
6948 it
->bidi_it
.first_elt
= 0;
6950 else if (it
->bidi_it
.bytepos
== BEGV_BYTE
6951 /* FIXME: Should support all Unicode line separators. */
6952 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6953 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6955 /* If we are at the beginning of a line, we can produce the
6956 next element right away. */
6957 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6958 bidi_move_to_visually_next (&it
->bidi_it
);
6962 EMACS_INT orig_bytepos
= IT_BYTEPOS (*it
);
6964 /* We need to prime the bidi iterator starting at the line's
6965 beginning, before we will be able to produce the next
6967 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6968 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6969 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6970 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6971 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6974 /* Now return to buffer position where we were asked to
6975 get the next display element, and produce that. */
6976 bidi_move_to_visually_next (&it
->bidi_it
);
6978 while (it
->bidi_it
.bytepos
!= orig_bytepos
6979 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6982 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6983 /* Adjust IT's position information to where we ended up. */
6984 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6985 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6986 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6988 EMACS_INT stop
= it
->end_charpos
;
6989 if (it
->bidi_it
.scan_dir
< 0)
6991 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6992 IT_BYTEPOS (*it
), stop
, Qnil
);
6996 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6998 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7000 int overlay_strings_follow_p
;
7002 /* End of the game, except when overlay strings follow that
7003 haven't been returned yet. */
7004 if (it
->overlay_strings_at_end_processed_p
)
7005 overlay_strings_follow_p
= 0;
7008 it
->overlay_strings_at_end_processed_p
= 1;
7009 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7012 if (overlay_strings_follow_p
)
7013 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7017 it
->position
= it
->current
.pos
;
7021 else if (!(!it
->bidi_p
7022 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7023 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7025 /* With bidi non-linear iteration, we could find ourselves
7026 far beyond the last computed stop_charpos, with several
7027 other stop positions in between that we missed. Scan
7028 them all now, in buffer's logical order, until we find
7029 and handle the last stop_charpos that precedes our
7030 current position. */
7031 handle_stop_backwards (it
, it
->stop_charpos
);
7032 return GET_NEXT_DISPLAY_ELEMENT (it
);
7038 /* Take note of the stop position we just moved across,
7039 for when we will move back across it. */
7040 it
->prev_stop
= it
->stop_charpos
;
7041 /* If we are at base paragraph embedding level, take
7042 note of the last stop position seen at this
7044 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7045 it
->base_level_stop
= it
->stop_charpos
;
7048 return GET_NEXT_DISPLAY_ELEMENT (it
);
7052 /* If we are before prev_stop, we may have overstepped on
7053 our way backwards a stop_pos, and if so, we need to
7054 handle that stop_pos. */
7055 && IT_CHARPOS (*it
) < it
->prev_stop
7056 /* We can sometimes back up for reasons that have nothing
7057 to do with bidi reordering. E.g., compositions. The
7058 code below is only needed when we are above the base
7059 embedding level, so test for that explicitly. */
7060 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7062 /* If we lost track of base_level_stop, we have no better place
7063 for handle_stop_backwards to start from than BEGV. This
7064 happens, e.g., when we were reseated to the previous
7065 screenful of text by vertical-motion. */
7066 if (it
->base_level_stop
<= 0
7067 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7068 it
->base_level_stop
= BEGV
;
7069 handle_stop_backwards (it
, it
->base_level_stop
);
7070 return GET_NEXT_DISPLAY_ELEMENT (it
);
7074 /* No face changes, overlays etc. in sight, so just return a
7075 character from current_buffer. */
7079 /* Maybe run the redisplay end trigger hook. Performance note:
7080 This doesn't seem to cost measurable time. */
7081 if (it
->redisplay_end_trigger_charpos
7083 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7084 run_redisplay_end_trigger_hook (it
);
7086 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7087 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7089 && next_element_from_composition (it
))
7094 /* Get the next character, maybe multibyte. */
7095 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7096 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7097 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7099 it
->c
= *p
, it
->len
= 1;
7101 /* Record what we have and where it came from. */
7102 it
->what
= IT_CHARACTER
;
7103 it
->object
= it
->w
->buffer
;
7104 it
->position
= it
->current
.pos
;
7106 /* Normally we return the character found above, except when we
7107 really want to return an ellipsis for selective display. */
7112 /* A value of selective > 0 means hide lines indented more
7113 than that number of columns. */
7114 if (it
->selective
> 0
7115 && IT_CHARPOS (*it
) + 1 < ZV
7116 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7117 IT_BYTEPOS (*it
) + 1,
7118 (double) it
->selective
)) /* iftc */
7120 success_p
= next_element_from_ellipsis (it
);
7121 it
->dpvec_char_len
= -1;
7124 else if (it
->c
== '\r' && it
->selective
== -1)
7126 /* A value of selective == -1 means that everything from the
7127 CR to the end of the line is invisible, with maybe an
7128 ellipsis displayed for it. */
7129 success_p
= next_element_from_ellipsis (it
);
7130 it
->dpvec_char_len
= -1;
7135 /* Value is zero if end of buffer reached. */
7136 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7141 /* Run the redisplay end trigger hook for IT. */
7144 run_redisplay_end_trigger_hook (struct it
*it
)
7146 Lisp_Object args
[3];
7148 /* IT->glyph_row should be non-null, i.e. we should be actually
7149 displaying something, or otherwise we should not run the hook. */
7150 xassert (it
->glyph_row
);
7152 /* Set up hook arguments. */
7153 args
[0] = Qredisplay_end_trigger_functions
;
7154 args
[1] = it
->window
;
7155 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7156 it
->redisplay_end_trigger_charpos
= 0;
7158 /* Since we are *trying* to run these functions, don't try to run
7159 them again, even if they get an error. */
7160 it
->w
->redisplay_end_trigger
= Qnil
;
7161 Frun_hook_with_args (3, args
);
7163 /* Notice if it changed the face of the character we are on. */
7164 handle_face_prop (it
);
7168 /* Deliver a composition display element. Unlike the other
7169 next_element_from_XXX, this function is not registered in the array
7170 get_next_element[]. It is called from next_element_from_buffer and
7171 next_element_from_string when necessary. */
7174 next_element_from_composition (struct it
*it
)
7176 it
->what
= IT_COMPOSITION
;
7177 it
->len
= it
->cmp_it
.nbytes
;
7178 if (STRINGP (it
->string
))
7182 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7183 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7186 it
->position
= it
->current
.string_pos
;
7187 it
->object
= it
->string
;
7188 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7189 IT_STRING_BYTEPOS (*it
), it
->string
);
7195 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7196 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7199 if (it
->bidi_it
.new_paragraph
)
7200 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7201 /* Resync the bidi iterator with IT's new position.
7202 FIXME: this doesn't support bidirectional text. */
7203 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7204 bidi_move_to_visually_next (&it
->bidi_it
);
7208 it
->position
= it
->current
.pos
;
7209 it
->object
= it
->w
->buffer
;
7210 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7211 IT_BYTEPOS (*it
), Qnil
);
7218 /***********************************************************************
7219 Moving an iterator without producing glyphs
7220 ***********************************************************************/
7222 /* Check if iterator is at a position corresponding to a valid buffer
7223 position after some move_it_ call. */
7225 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7226 ((it)->method == GET_FROM_STRING \
7227 ? IT_STRING_CHARPOS (*it) == 0 \
7231 /* Move iterator IT to a specified buffer or X position within one
7232 line on the display without producing glyphs.
7234 OP should be a bit mask including some or all of these bits:
7235 MOVE_TO_X: Stop upon reaching x-position TO_X.
7236 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7237 Regardless of OP's value, stop upon reaching the end of the display line.
7239 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7240 This means, in particular, that TO_X includes window's horizontal
7243 The return value has several possible values that
7244 say what condition caused the scan to stop:
7246 MOVE_POS_MATCH_OR_ZV
7247 - when TO_POS or ZV was reached.
7250 -when TO_X was reached before TO_POS or ZV were reached.
7253 - when we reached the end of the display area and the line must
7257 - when we reached the end of the display area and the line is
7261 - when we stopped at a line end, i.e. a newline or a CR and selective
7264 static enum move_it_result
7265 move_it_in_display_line_to (struct it
*it
,
7266 EMACS_INT to_charpos
, int to_x
,
7267 enum move_operation_enum op
)
7269 enum move_it_result result
= MOVE_UNDEFINED
;
7270 struct glyph_row
*saved_glyph_row
;
7271 struct it wrap_it
, atpos_it
, atx_it
;
7273 enum it_method prev_method
= it
->method
;
7274 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7276 /* Don't produce glyphs in produce_glyphs. */
7277 saved_glyph_row
= it
->glyph_row
;
7278 it
->glyph_row
= NULL
;
7280 /* Use wrap_it to save a copy of IT wherever a word wrap could
7281 occur. Use atpos_it to save a copy of IT at the desired buffer
7282 position, if found, so that we can scan ahead and check if the
7283 word later overshoots the window edge. Use atx_it similarly, for
7289 #define BUFFER_POS_REACHED_P() \
7290 ((op & MOVE_TO_POS) != 0 \
7291 && BUFFERP (it->object) \
7292 && (IT_CHARPOS (*it) == to_charpos \
7293 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7294 && (it->method == GET_FROM_BUFFER \
7295 || (it->method == GET_FROM_DISPLAY_VECTOR \
7296 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7298 /* If there's a line-/wrap-prefix, handle it. */
7299 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7300 && it
->current_y
< it
->last_visible_y
)
7301 handle_line_prefix (it
);
7303 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7304 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7308 int x
, i
, ascent
= 0, descent
= 0;
7310 /* Utility macro to reset an iterator with x, ascent, and descent. */
7311 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7312 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7313 (IT)->max_descent = descent)
7315 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7317 if ((op
& MOVE_TO_POS
) != 0
7318 && BUFFERP (it
->object
)
7319 && it
->method
== GET_FROM_BUFFER
7320 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7322 && (prev_method
== GET_FROM_IMAGE
7323 || prev_method
== GET_FROM_STRETCH
)
7324 /* Passed TO_CHARPOS from left to right. */
7325 && ((prev_pos
< to_charpos
7326 && IT_CHARPOS (*it
) > to_charpos
)
7327 /* Passed TO_CHARPOS from right to left. */
7328 || (prev_pos
> to_charpos
7329 && IT_CHARPOS (*it
) < to_charpos
)))))
7331 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7333 result
= MOVE_POS_MATCH_OR_ZV
;
7336 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7337 /* If wrap_it is valid, the current position might be in a
7338 word that is wrapped. So, save the iterator in
7339 atpos_it and continue to see if wrapping happens. */
7343 prev_method
= it
->method
;
7344 if (it
->method
== GET_FROM_BUFFER
)
7345 prev_pos
= IT_CHARPOS (*it
);
7346 /* Stop when ZV reached.
7347 We used to stop here when TO_CHARPOS reached as well, but that is
7348 too soon if this glyph does not fit on this line. So we handle it
7349 explicitly below. */
7350 if (!get_next_display_element (it
))
7352 result
= MOVE_POS_MATCH_OR_ZV
;
7356 if (it
->line_wrap
== TRUNCATE
)
7358 if (BUFFER_POS_REACHED_P ())
7360 result
= MOVE_POS_MATCH_OR_ZV
;
7366 if (it
->line_wrap
== WORD_WRAP
)
7368 if (IT_DISPLAYING_WHITESPACE (it
))
7372 /* We have reached a glyph that follows one or more
7373 whitespace characters. If the position is
7374 already found, we are done. */
7375 if (atpos_it
.sp
>= 0)
7378 result
= MOVE_POS_MATCH_OR_ZV
;
7384 result
= MOVE_X_REACHED
;
7387 /* Otherwise, we can wrap here. */
7394 /* Remember the line height for the current line, in case
7395 the next element doesn't fit on the line. */
7396 ascent
= it
->max_ascent
;
7397 descent
= it
->max_descent
;
7399 /* The call to produce_glyphs will get the metrics of the
7400 display element IT is loaded with. Record the x-position
7401 before this display element, in case it doesn't fit on the
7405 PRODUCE_GLYPHS (it
);
7407 if (it
->area
!= TEXT_AREA
)
7409 set_iterator_to_next (it
, 1);
7410 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7411 SET_TEXT_POS (this_line_min_pos
,
7412 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7416 /* The number of glyphs we get back in IT->nglyphs will normally
7417 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7418 character on a terminal frame, or (iii) a line end. For the
7419 second case, IT->nglyphs - 1 padding glyphs will be present.
7420 (On X frames, there is only one glyph produced for a
7421 composite character.)
7423 The behavior implemented below means, for continuation lines,
7424 that as many spaces of a TAB as fit on the current line are
7425 displayed there. For terminal frames, as many glyphs of a
7426 multi-glyph character are displayed in the current line, too.
7427 This is what the old redisplay code did, and we keep it that
7428 way. Under X, the whole shape of a complex character must
7429 fit on the line or it will be completely displayed in the
7432 Note that both for tabs and padding glyphs, all glyphs have
7436 /* More than one glyph or glyph doesn't fit on line. All
7437 glyphs have the same width. */
7438 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7440 int x_before_this_char
= x
;
7441 int hpos_before_this_char
= it
->hpos
;
7443 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7445 new_x
= x
+ single_glyph_width
;
7447 /* We want to leave anything reaching TO_X to the caller. */
7448 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7450 if (BUFFER_POS_REACHED_P ())
7452 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7453 goto buffer_pos_reached
;
7454 if (atpos_it
.sp
< 0)
7457 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7462 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7465 result
= MOVE_X_REACHED
;
7471 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7476 if (/* Lines are continued. */
7477 it
->line_wrap
!= TRUNCATE
7478 && (/* And glyph doesn't fit on the line. */
7479 new_x
> it
->last_visible_x
7480 /* Or it fits exactly and we're on a window
7482 || (new_x
== it
->last_visible_x
7483 && FRAME_WINDOW_P (it
->f
))))
7485 if (/* IT->hpos == 0 means the very first glyph
7486 doesn't fit on the line, e.g. a wide image. */
7488 || (new_x
== it
->last_visible_x
7489 && FRAME_WINDOW_P (it
->f
)))
7492 it
->current_x
= new_x
;
7494 /* The character's last glyph just barely fits
7496 if (i
== it
->nglyphs
- 1)
7498 /* If this is the destination position,
7499 return a position *before* it in this row,
7500 now that we know it fits in this row. */
7501 if (BUFFER_POS_REACHED_P ())
7503 if (it
->line_wrap
!= WORD_WRAP
7506 it
->hpos
= hpos_before_this_char
;
7507 it
->current_x
= x_before_this_char
;
7508 result
= MOVE_POS_MATCH_OR_ZV
;
7511 if (it
->line_wrap
== WORD_WRAP
7515 atpos_it
.current_x
= x_before_this_char
;
7516 atpos_it
.hpos
= hpos_before_this_char
;
7520 set_iterator_to_next (it
, 1);
7521 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7522 SET_TEXT_POS (this_line_min_pos
,
7523 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7524 /* On graphical terminals, newlines may
7525 "overflow" into the fringe if
7526 overflow-newline-into-fringe is non-nil.
7527 On text-only terminals, newlines may
7528 overflow into the last glyph on the
7530 if (!FRAME_WINDOW_P (it
->f
)
7531 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7533 if (!get_next_display_element (it
))
7535 result
= MOVE_POS_MATCH_OR_ZV
;
7538 if (BUFFER_POS_REACHED_P ())
7540 if (ITERATOR_AT_END_OF_LINE_P (it
))
7541 result
= MOVE_POS_MATCH_OR_ZV
;
7543 result
= MOVE_LINE_CONTINUED
;
7546 if (ITERATOR_AT_END_OF_LINE_P (it
))
7548 result
= MOVE_NEWLINE_OR_CR
;
7555 IT_RESET_X_ASCENT_DESCENT (it
);
7557 if (wrap_it
.sp
>= 0)
7564 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7566 result
= MOVE_LINE_CONTINUED
;
7570 if (BUFFER_POS_REACHED_P ())
7572 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7573 goto buffer_pos_reached
;
7574 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7577 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7581 if (new_x
> it
->first_visible_x
)
7583 /* Glyph is visible. Increment number of glyphs that
7584 would be displayed. */
7589 if (result
!= MOVE_UNDEFINED
)
7592 else if (BUFFER_POS_REACHED_P ())
7595 IT_RESET_X_ASCENT_DESCENT (it
);
7596 result
= MOVE_POS_MATCH_OR_ZV
;
7599 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7601 /* Stop when TO_X specified and reached. This check is
7602 necessary here because of lines consisting of a line end,
7603 only. The line end will not produce any glyphs and we
7604 would never get MOVE_X_REACHED. */
7605 xassert (it
->nglyphs
== 0);
7606 result
= MOVE_X_REACHED
;
7610 /* Is this a line end? If yes, we're done. */
7611 if (ITERATOR_AT_END_OF_LINE_P (it
))
7613 result
= MOVE_NEWLINE_OR_CR
;
7617 if (it
->method
== GET_FROM_BUFFER
)
7618 prev_pos
= IT_CHARPOS (*it
);
7619 /* The current display element has been consumed. Advance
7621 set_iterator_to_next (it
, 1);
7622 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7623 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7625 /* Stop if lines are truncated and IT's current x-position is
7626 past the right edge of the window now. */
7627 if (it
->line_wrap
== TRUNCATE
7628 && it
->current_x
>= it
->last_visible_x
)
7630 if (!FRAME_WINDOW_P (it
->f
)
7631 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7633 if (!get_next_display_element (it
)
7634 || BUFFER_POS_REACHED_P ())
7636 result
= MOVE_POS_MATCH_OR_ZV
;
7639 if (ITERATOR_AT_END_OF_LINE_P (it
))
7641 result
= MOVE_NEWLINE_OR_CR
;
7645 result
= MOVE_LINE_TRUNCATED
;
7648 #undef IT_RESET_X_ASCENT_DESCENT
7651 #undef BUFFER_POS_REACHED_P
7653 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7654 restore the saved iterator. */
7655 if (atpos_it
.sp
>= 0)
7657 else if (atx_it
.sp
>= 0)
7662 /* Restore the iterator settings altered at the beginning of this
7664 it
->glyph_row
= saved_glyph_row
;
7668 /* For external use. */
7670 move_it_in_display_line (struct it
*it
,
7671 EMACS_INT to_charpos
, int to_x
,
7672 enum move_operation_enum op
)
7674 if (it
->line_wrap
== WORD_WRAP
7675 && (op
& MOVE_TO_X
))
7677 struct it save_it
= *it
;
7678 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7679 /* When word-wrap is on, TO_X may lie past the end
7680 of a wrapped line. Then it->current is the
7681 character on the next line, so backtrack to the
7682 space before the wrap point. */
7683 if (skip
== MOVE_LINE_CONTINUED
)
7685 int prev_x
= max (it
->current_x
- 1, 0);
7687 move_it_in_display_line_to
7688 (it
, -1, prev_x
, MOVE_TO_X
);
7692 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7696 /* Move IT forward until it satisfies one or more of the criteria in
7697 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7699 OP is a bit-mask that specifies where to stop, and in particular,
7700 which of those four position arguments makes a difference. See the
7701 description of enum move_operation_enum.
7703 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7704 screen line, this function will set IT to the next position >
7708 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7710 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7711 int line_height
, line_start_x
= 0, reached
= 0;
7715 if (op
& MOVE_TO_VPOS
)
7717 /* If no TO_CHARPOS and no TO_X specified, stop at the
7718 start of the line TO_VPOS. */
7719 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7721 if (it
->vpos
== to_vpos
)
7727 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7731 /* TO_VPOS >= 0 means stop at TO_X in the line at
7732 TO_VPOS, or at TO_POS, whichever comes first. */
7733 if (it
->vpos
== to_vpos
)
7739 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7741 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7746 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7748 /* We have reached TO_X but not in the line we want. */
7749 skip
= move_it_in_display_line_to (it
, to_charpos
,
7751 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7759 else if (op
& MOVE_TO_Y
)
7761 struct it it_backup
;
7763 if (it
->line_wrap
== WORD_WRAP
)
7766 /* TO_Y specified means stop at TO_X in the line containing
7767 TO_Y---or at TO_CHARPOS if this is reached first. The
7768 problem is that we can't really tell whether the line
7769 contains TO_Y before we have completely scanned it, and
7770 this may skip past TO_X. What we do is to first scan to
7773 If TO_X is not specified, use a TO_X of zero. The reason
7774 is to make the outcome of this function more predictable.
7775 If we didn't use TO_X == 0, we would stop at the end of
7776 the line which is probably not what a caller would expect
7778 skip
= move_it_in_display_line_to
7779 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7780 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7782 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7783 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7785 else if (skip
== MOVE_X_REACHED
)
7787 /* If TO_X was reached, we want to know whether TO_Y is
7788 in the line. We know this is the case if the already
7789 scanned glyphs make the line tall enough. Otherwise,
7790 we must check by scanning the rest of the line. */
7791 line_height
= it
->max_ascent
+ it
->max_descent
;
7792 if (to_y
>= it
->current_y
7793 && to_y
< it
->current_y
+ line_height
)
7799 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7800 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7802 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7803 line_height
= it
->max_ascent
+ it
->max_descent
;
7804 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7806 if (to_y
>= it
->current_y
7807 && to_y
< it
->current_y
+ line_height
)
7809 /* If TO_Y is in this line and TO_X was reached
7810 above, we scanned too far. We have to restore
7811 IT's settings to the ones before skipping. */
7818 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7824 /* Check whether TO_Y is in this line. */
7825 line_height
= it
->max_ascent
+ it
->max_descent
;
7826 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7828 if (to_y
>= it
->current_y
7829 && to_y
< it
->current_y
+ line_height
)
7831 /* When word-wrap is on, TO_X may lie past the end
7832 of a wrapped line. Then it->current is the
7833 character on the next line, so backtrack to the
7834 space before the wrap point. */
7835 if (skip
== MOVE_LINE_CONTINUED
7836 && it
->line_wrap
== WORD_WRAP
)
7838 int prev_x
= max (it
->current_x
- 1, 0);
7840 skip
= move_it_in_display_line_to
7841 (it
, -1, prev_x
, MOVE_TO_X
);
7850 else if (BUFFERP (it
->object
)
7851 && (it
->method
== GET_FROM_BUFFER
7852 || it
->method
== GET_FROM_STRETCH
)
7853 && IT_CHARPOS (*it
) >= to_charpos
)
7854 skip
= MOVE_POS_MATCH_OR_ZV
;
7856 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7860 case MOVE_POS_MATCH_OR_ZV
:
7864 case MOVE_NEWLINE_OR_CR
:
7865 set_iterator_to_next (it
, 1);
7866 it
->continuation_lines_width
= 0;
7869 case MOVE_LINE_TRUNCATED
:
7870 it
->continuation_lines_width
= 0;
7871 reseat_at_next_visible_line_start (it
, 0);
7872 if ((op
& MOVE_TO_POS
) != 0
7873 && IT_CHARPOS (*it
) > to_charpos
)
7880 case MOVE_LINE_CONTINUED
:
7881 /* For continued lines ending in a tab, some of the glyphs
7882 associated with the tab are displayed on the current
7883 line. Since it->current_x does not include these glyphs,
7884 we use it->last_visible_x instead. */
7887 it
->continuation_lines_width
+= it
->last_visible_x
;
7888 /* When moving by vpos, ensure that the iterator really
7889 advances to the next line (bug#847, bug#969). Fixme:
7890 do we need to do this in other circumstances? */
7891 if (it
->current_x
!= it
->last_visible_x
7892 && (op
& MOVE_TO_VPOS
)
7893 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7895 line_start_x
= it
->current_x
+ it
->pixel_width
7896 - it
->last_visible_x
;
7897 set_iterator_to_next (it
, 0);
7901 it
->continuation_lines_width
+= it
->current_x
;
7908 /* Reset/increment for the next run. */
7909 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7910 it
->current_x
= line_start_x
;
7913 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7915 last_height
= it
->max_ascent
+ it
->max_descent
;
7916 last_max_ascent
= it
->max_ascent
;
7917 it
->max_ascent
= it
->max_descent
= 0;
7922 /* On text terminals, we may stop at the end of a line in the middle
7923 of a multi-character glyph. If the glyph itself is continued,
7924 i.e. it is actually displayed on the next line, don't treat this
7925 stopping point as valid; move to the next line instead (unless
7926 that brings us offscreen). */
7927 if (!FRAME_WINDOW_P (it
->f
)
7929 && IT_CHARPOS (*it
) == to_charpos
7930 && it
->what
== IT_CHARACTER
7932 && it
->line_wrap
== WINDOW_WRAP
7933 && it
->current_x
== it
->last_visible_x
- 1
7936 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7938 it
->continuation_lines_width
+= it
->current_x
;
7939 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7940 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7942 last_height
= it
->max_ascent
+ it
->max_descent
;
7943 last_max_ascent
= it
->max_ascent
;
7946 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7950 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7952 If DY > 0, move IT backward at least that many pixels. DY = 0
7953 means move IT backward to the preceding line start or BEGV. This
7954 function may move over more than DY pixels if IT->current_y - DY
7955 ends up in the middle of a line; in this case IT->current_y will be
7956 set to the top of the line moved to. */
7959 move_it_vertically_backward (struct it
*it
, int dy
)
7963 EMACS_INT start_pos
;
7968 start_pos
= IT_CHARPOS (*it
);
7970 /* Estimate how many newlines we must move back. */
7971 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7973 /* Set the iterator's position that many lines back. */
7974 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7975 back_to_previous_visible_line_start (it
);
7977 /* Reseat the iterator here. When moving backward, we don't want
7978 reseat to skip forward over invisible text, set up the iterator
7979 to deliver from overlay strings at the new position etc. So,
7980 use reseat_1 here. */
7981 reseat_1 (it
, it
->current
.pos
, 1);
7983 /* We are now surely at a line start. */
7984 it
->current_x
= it
->hpos
= 0;
7985 it
->continuation_lines_width
= 0;
7987 /* Move forward and see what y-distance we moved. First move to the
7988 start of the next line so that we get its height. We need this
7989 height to be able to tell whether we reached the specified
7992 it2
.max_ascent
= it2
.max_descent
= 0;
7995 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7996 MOVE_TO_POS
| MOVE_TO_VPOS
);
7998 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7999 xassert (IT_CHARPOS (*it
) >= BEGV
);
8002 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8003 xassert (IT_CHARPOS (*it
) >= BEGV
);
8004 /* H is the actual vertical distance from the position in *IT
8005 and the starting position. */
8006 h
= it2
.current_y
- it
->current_y
;
8007 /* NLINES is the distance in number of lines. */
8008 nlines
= it2
.vpos
- it
->vpos
;
8010 /* Correct IT's y and vpos position
8011 so that they are relative to the starting point. */
8017 /* DY == 0 means move to the start of the screen line. The
8018 value of nlines is > 0 if continuation lines were involved. */
8020 move_it_by_lines (it
, nlines
);
8024 /* The y-position we try to reach, relative to *IT.
8025 Note that H has been subtracted in front of the if-statement. */
8026 int target_y
= it
->current_y
+ h
- dy
;
8027 int y0
= it3
.current_y
;
8028 int y1
= line_bottom_y (&it3
);
8029 int line_height
= y1
- y0
;
8031 /* If we did not reach target_y, try to move further backward if
8032 we can. If we moved too far backward, try to move forward. */
8033 if (target_y
< it
->current_y
8034 /* This is heuristic. In a window that's 3 lines high, with
8035 a line height of 13 pixels each, recentering with point
8036 on the bottom line will try to move -39/2 = 19 pixels
8037 backward. Try to avoid moving into the first line. */
8038 && (it
->current_y
- target_y
8039 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8040 && IT_CHARPOS (*it
) > BEGV
)
8042 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8043 target_y
- it
->current_y
));
8044 dy
= it
->current_y
- target_y
;
8045 goto move_further_back
;
8047 else if (target_y
>= it
->current_y
+ line_height
8048 && IT_CHARPOS (*it
) < ZV
)
8050 /* Should move forward by at least one line, maybe more.
8052 Note: Calling move_it_by_lines can be expensive on
8053 terminal frames, where compute_motion is used (via
8054 vmotion) to do the job, when there are very long lines
8055 and truncate-lines is nil. That's the reason for
8056 treating terminal frames specially here. */
8058 if (!FRAME_WINDOW_P (it
->f
))
8059 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8064 move_it_by_lines (it
, 1);
8066 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8073 /* Move IT by a specified amount of pixel lines DY. DY negative means
8074 move backwards. DY = 0 means move to start of screen line. At the
8075 end, IT will be on the start of a screen line. */
8078 move_it_vertically (struct it
*it
, int dy
)
8081 move_it_vertically_backward (it
, -dy
);
8084 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8085 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8086 MOVE_TO_POS
| MOVE_TO_Y
);
8087 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8089 /* If buffer ends in ZV without a newline, move to the start of
8090 the line to satisfy the post-condition. */
8091 if (IT_CHARPOS (*it
) == ZV
8093 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8094 move_it_by_lines (it
, 0);
8099 /* Move iterator IT past the end of the text line it is in. */
8102 move_it_past_eol (struct it
*it
)
8104 enum move_it_result rc
;
8106 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8107 if (rc
== MOVE_NEWLINE_OR_CR
)
8108 set_iterator_to_next (it
, 0);
8112 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8113 negative means move up. DVPOS == 0 means move to the start of the
8116 Optimization idea: If we would know that IT->f doesn't use
8117 a face with proportional font, we could be faster for
8118 truncate-lines nil. */
8121 move_it_by_lines (struct it
*it
, int dvpos
)
8124 /* The commented-out optimization uses vmotion on terminals. This
8125 gives bad results, because elements like it->what, on which
8126 callers such as pos_visible_p rely, aren't updated. */
8127 /* struct position pos;
8128 if (!FRAME_WINDOW_P (it->f))
8130 struct text_pos textpos;
8132 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8133 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8134 reseat (it, textpos, 1);
8135 it->vpos += pos.vpos;
8136 it->current_y += pos.vpos;
8142 /* DVPOS == 0 means move to the start of the screen line. */
8143 move_it_vertically_backward (it
, 0);
8144 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8145 /* Let next call to line_bottom_y calculate real line height */
8150 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8151 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8152 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8157 EMACS_INT start_charpos
, i
;
8159 /* Start at the beginning of the screen line containing IT's
8160 position. This may actually move vertically backwards,
8161 in case of overlays, so adjust dvpos accordingly. */
8163 move_it_vertically_backward (it
, 0);
8166 /* Go back -DVPOS visible lines and reseat the iterator there. */
8167 start_charpos
= IT_CHARPOS (*it
);
8168 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8169 back_to_previous_visible_line_start (it
);
8170 reseat (it
, it
->current
.pos
, 1);
8172 /* Move further back if we end up in a string or an image. */
8173 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8175 /* First try to move to start of display line. */
8177 move_it_vertically_backward (it
, 0);
8179 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8181 /* If start of line is still in string or image,
8182 move further back. */
8183 back_to_previous_visible_line_start (it
);
8184 reseat (it
, it
->current
.pos
, 1);
8188 it
->current_x
= it
->hpos
= 0;
8190 /* Above call may have moved too far if continuation lines
8191 are involved. Scan forward and see if it did. */
8193 it2
.vpos
= it2
.current_y
= 0;
8194 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8195 it
->vpos
-= it2
.vpos
;
8196 it
->current_y
-= it2
.current_y
;
8197 it
->current_x
= it
->hpos
= 0;
8199 /* If we moved too far back, move IT some lines forward. */
8200 if (it2
.vpos
> -dvpos
)
8202 int delta
= it2
.vpos
+ dvpos
;
8204 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8205 /* Move back again if we got too far ahead. */
8206 if (IT_CHARPOS (*it
) >= start_charpos
)
8212 /* Return 1 if IT points into the middle of a display vector. */
8215 in_display_vector_p (struct it
*it
)
8217 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8218 && it
->current
.dpvec_index
> 0
8219 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8223 /***********************************************************************
8225 ***********************************************************************/
8228 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8232 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8234 Lisp_Object args
[3];
8235 Lisp_Object msg
, fmt
;
8238 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8241 /* Do nothing if called asynchronously. Inserting text into
8242 a buffer may call after-change-functions and alike and
8243 that would means running Lisp asynchronously. */
8244 if (handling_signal
)
8248 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8250 args
[0] = fmt
= build_string (format
);
8253 msg
= Fformat (3, args
);
8255 len
= SBYTES (msg
) + 1;
8256 SAFE_ALLOCA (buffer
, char *, len
);
8257 memcpy (buffer
, SDATA (msg
), len
);
8259 message_dolog (buffer
, len
- 1, 1, 0);
8266 /* Output a newline in the *Messages* buffer if "needs" one. */
8269 message_log_maybe_newline (void)
8271 if (message_log_need_newline
)
8272 message_dolog ("", 0, 1, 0);
8276 /* Add a string M of length NBYTES to the message log, optionally
8277 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8278 nonzero, means interpret the contents of M as multibyte. This
8279 function calls low-level routines in order to bypass text property
8280 hooks, etc. which might not be safe to run.
8282 This may GC (insert may run before/after change hooks),
8283 so the buffer M must NOT point to a Lisp string. */
8286 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8288 const unsigned char *msg
= (const unsigned char *) m
;
8290 if (!NILP (Vmemory_full
))
8293 if (!NILP (Vmessage_log_max
))
8295 struct buffer
*oldbuf
;
8296 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8297 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8298 EMACS_INT point_at_end
= 0;
8299 EMACS_INT zv_at_end
= 0;
8300 Lisp_Object old_deactivate_mark
, tem
;
8301 struct gcpro gcpro1
;
8303 old_deactivate_mark
= Vdeactivate_mark
;
8304 oldbuf
= current_buffer
;
8305 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8306 BVAR (current_buffer
, undo_list
) = Qt
;
8308 oldpoint
= message_dolog_marker1
;
8309 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8310 oldbegv
= message_dolog_marker2
;
8311 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8312 oldzv
= message_dolog_marker3
;
8313 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8314 GCPRO1 (old_deactivate_mark
);
8322 BEGV_BYTE
= BEG_BYTE
;
8325 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8327 /* Insert the string--maybe converting multibyte to single byte
8328 or vice versa, so that all the text fits the buffer. */
8330 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8336 /* Convert a multibyte string to single-byte
8337 for the *Message* buffer. */
8338 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8340 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8341 work
[0] = (ASCII_CHAR_P (c
)
8343 : multibyte_char_to_unibyte (c
));
8344 insert_1_both (work
, 1, 1, 1, 0, 0);
8347 else if (! multibyte
8348 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8352 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8353 /* Convert a single-byte string to multibyte
8354 for the *Message* buffer. */
8355 for (i
= 0; i
< nbytes
; i
++)
8358 MAKE_CHAR_MULTIBYTE (c
);
8359 char_bytes
= CHAR_STRING (c
, str
);
8360 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8364 insert_1 (m
, nbytes
, 1, 0, 0);
8368 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8369 unsigned long int dups
;
8370 insert_1 ("\n", 1, 1, 0, 0);
8372 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8374 this_bol_byte
= PT_BYTE
;
8376 /* See if this line duplicates the previous one.
8377 If so, combine duplicates. */
8380 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8382 prev_bol_byte
= PT_BYTE
;
8384 dups
= message_log_check_duplicate (prev_bol_byte
,
8388 del_range_both (prev_bol
, prev_bol_byte
,
8389 this_bol
, this_bol_byte
, 0);
8395 /* If you change this format, don't forget to also
8396 change message_log_check_duplicate. */
8397 sprintf (dupstr
, " [%lu times]", dups
);
8398 duplen
= strlen (dupstr
);
8399 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8400 insert_1 (dupstr
, duplen
, 1, 0, 1);
8405 /* If we have more than the desired maximum number of lines
8406 in the *Messages* buffer now, delete the oldest ones.
8407 This is safe because we don't have undo in this buffer. */
8409 if (NATNUMP (Vmessage_log_max
))
8411 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8412 -XFASTINT (Vmessage_log_max
) - 1, 0);
8413 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8416 BEGV
= XMARKER (oldbegv
)->charpos
;
8417 BEGV_BYTE
= marker_byte_position (oldbegv
);
8426 ZV
= XMARKER (oldzv
)->charpos
;
8427 ZV_BYTE
= marker_byte_position (oldzv
);
8431 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8433 /* We can't do Fgoto_char (oldpoint) because it will run some
8435 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8436 XMARKER (oldpoint
)->bytepos
);
8439 unchain_marker (XMARKER (oldpoint
));
8440 unchain_marker (XMARKER (oldbegv
));
8441 unchain_marker (XMARKER (oldzv
));
8443 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8444 set_buffer_internal (oldbuf
);
8446 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8447 message_log_need_newline
= !nlflag
;
8448 Vdeactivate_mark
= old_deactivate_mark
;
8453 /* We are at the end of the buffer after just having inserted a newline.
8454 (Note: We depend on the fact we won't be crossing the gap.)
8455 Check to see if the most recent message looks a lot like the previous one.
8456 Return 0 if different, 1 if the new one should just replace it, or a
8457 value N > 1 if we should also append " [N times]". */
8459 static unsigned long int
8460 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8463 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8465 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8466 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8468 for (i
= 0; i
< len
; i
++)
8470 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8478 if (*p1
++ == ' ' && *p1
++ == '[')
8481 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8482 if (strncmp (pend
, " times]\n", 8) == 0)
8489 /* Display an echo area message M with a specified length of NBYTES
8490 bytes. The string may include null characters. If M is 0, clear
8491 out any existing message, and let the mini-buffer text show
8494 This may GC, so the buffer M must NOT point to a Lisp string. */
8497 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8499 /* First flush out any partial line written with print. */
8500 message_log_maybe_newline ();
8502 message_dolog (m
, nbytes
, 1, multibyte
);
8503 message2_nolog (m
, nbytes
, multibyte
);
8507 /* The non-logging counterpart of message2. */
8510 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8512 struct frame
*sf
= SELECTED_FRAME ();
8513 message_enable_multibyte
= multibyte
;
8515 if (FRAME_INITIAL_P (sf
))
8517 if (noninteractive_need_newline
)
8518 putc ('\n', stderr
);
8519 noninteractive_need_newline
= 0;
8521 fwrite (m
, nbytes
, 1, stderr
);
8522 if (cursor_in_echo_area
== 0)
8523 fprintf (stderr
, "\n");
8526 /* A null message buffer means that the frame hasn't really been
8527 initialized yet. Error messages get reported properly by
8528 cmd_error, so this must be just an informative message; toss it. */
8529 else if (INTERACTIVE
8530 && sf
->glyphs_initialized_p
8531 && FRAME_MESSAGE_BUF (sf
))
8533 Lisp_Object mini_window
;
8536 /* Get the frame containing the mini-buffer
8537 that the selected frame is using. */
8538 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8539 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8541 FRAME_SAMPLE_VISIBILITY (f
);
8542 if (FRAME_VISIBLE_P (sf
)
8543 && ! FRAME_VISIBLE_P (f
))
8544 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8548 set_message (m
, Qnil
, nbytes
, multibyte
);
8549 if (minibuffer_auto_raise
)
8550 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8553 clear_message (1, 1);
8555 do_pending_window_change (0);
8556 echo_area_display (1);
8557 do_pending_window_change (0);
8558 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8559 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8564 /* Display an echo area message M with a specified length of NBYTES
8565 bytes. The string may include null characters. If M is not a
8566 string, clear out any existing message, and let the mini-buffer
8569 This function cancels echoing. */
8572 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8574 struct gcpro gcpro1
;
8577 clear_message (1,1);
8580 /* First flush out any partial line written with print. */
8581 message_log_maybe_newline ();
8587 SAFE_ALLOCA (buffer
, char *, nbytes
);
8588 memcpy (buffer
, SDATA (m
), nbytes
);
8589 message_dolog (buffer
, nbytes
, 1, multibyte
);
8592 message3_nolog (m
, nbytes
, multibyte
);
8598 /* The non-logging version of message3.
8599 This does not cancel echoing, because it is used for echoing.
8600 Perhaps we need to make a separate function for echoing
8601 and make this cancel echoing. */
8604 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8606 struct frame
*sf
= SELECTED_FRAME ();
8607 message_enable_multibyte
= multibyte
;
8609 if (FRAME_INITIAL_P (sf
))
8611 if (noninteractive_need_newline
)
8612 putc ('\n', stderr
);
8613 noninteractive_need_newline
= 0;
8615 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8616 if (cursor_in_echo_area
== 0)
8617 fprintf (stderr
, "\n");
8620 /* A null message buffer means that the frame hasn't really been
8621 initialized yet. Error messages get reported properly by
8622 cmd_error, so this must be just an informative message; toss it. */
8623 else if (INTERACTIVE
8624 && sf
->glyphs_initialized_p
8625 && FRAME_MESSAGE_BUF (sf
))
8627 Lisp_Object mini_window
;
8631 /* Get the frame containing the mini-buffer
8632 that the selected frame is using. */
8633 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8634 frame
= XWINDOW (mini_window
)->frame
;
8637 FRAME_SAMPLE_VISIBILITY (f
);
8638 if (FRAME_VISIBLE_P (sf
)
8639 && !FRAME_VISIBLE_P (f
))
8640 Fmake_frame_visible (frame
);
8642 if (STRINGP (m
) && SCHARS (m
) > 0)
8644 set_message (NULL
, m
, nbytes
, multibyte
);
8645 if (minibuffer_auto_raise
)
8646 Fraise_frame (frame
);
8647 /* Assume we are not echoing.
8648 (If we are, echo_now will override this.) */
8649 echo_message_buffer
= Qnil
;
8652 clear_message (1, 1);
8654 do_pending_window_change (0);
8655 echo_area_display (1);
8656 do_pending_window_change (0);
8657 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8658 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8663 /* Display a null-terminated echo area message M. If M is 0, clear
8664 out any existing message, and let the mini-buffer text show through.
8666 The buffer M must continue to exist until after the echo area gets
8667 cleared or some other message gets displayed there. Do not pass
8668 text that is stored in a Lisp string. Do not pass text in a buffer
8669 that was alloca'd. */
8672 message1 (const char *m
)
8674 message2 (m
, (m
? strlen (m
) : 0), 0);
8678 /* The non-logging counterpart of message1. */
8681 message1_nolog (const char *m
)
8683 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8686 /* Display a message M which contains a single %s
8687 which gets replaced with STRING. */
8690 message_with_string (const char *m
, Lisp_Object string
, int log
)
8692 CHECK_STRING (string
);
8698 if (noninteractive_need_newline
)
8699 putc ('\n', stderr
);
8700 noninteractive_need_newline
= 0;
8701 fprintf (stderr
, m
, SDATA (string
));
8702 if (!cursor_in_echo_area
)
8703 fprintf (stderr
, "\n");
8707 else if (INTERACTIVE
)
8709 /* The frame whose minibuffer we're going to display the message on.
8710 It may be larger than the selected frame, so we need
8711 to use its buffer, not the selected frame's buffer. */
8712 Lisp_Object mini_window
;
8713 struct frame
*f
, *sf
= SELECTED_FRAME ();
8715 /* Get the frame containing the minibuffer
8716 that the selected frame is using. */
8717 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8718 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8720 /* A null message buffer means that the frame hasn't really been
8721 initialized yet. Error messages get reported properly by
8722 cmd_error, so this must be just an informative message; toss it. */
8723 if (FRAME_MESSAGE_BUF (f
))
8725 Lisp_Object args
[2], msg
;
8726 struct gcpro gcpro1
, gcpro2
;
8728 args
[0] = build_string (m
);
8729 args
[1] = msg
= string
;
8730 GCPRO2 (args
[0], msg
);
8733 msg
= Fformat (2, args
);
8736 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8738 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8742 /* Print should start at the beginning of the message
8743 buffer next time. */
8744 message_buf_print
= 0;
8750 /* Dump an informative message to the minibuf. If M is 0, clear out
8751 any existing message, and let the mini-buffer text show through. */
8754 vmessage (const char *m
, va_list ap
)
8760 if (noninteractive_need_newline
)
8761 putc ('\n', stderr
);
8762 noninteractive_need_newline
= 0;
8763 vfprintf (stderr
, m
, ap
);
8764 if (cursor_in_echo_area
== 0)
8765 fprintf (stderr
, "\n");
8769 else if (INTERACTIVE
)
8771 /* The frame whose mini-buffer we're going to display the message
8772 on. It may be larger than the selected frame, so we need to
8773 use its buffer, not the selected frame's buffer. */
8774 Lisp_Object mini_window
;
8775 struct frame
*f
, *sf
= SELECTED_FRAME ();
8777 /* Get the frame containing the mini-buffer
8778 that the selected frame is using. */
8779 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8780 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8782 /* A null message buffer means that the frame hasn't really been
8783 initialized yet. Error messages get reported properly by
8784 cmd_error, so this must be just an informative message; toss
8786 if (FRAME_MESSAGE_BUF (f
))
8792 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8793 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8795 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8800 /* Print should start at the beginning of the message
8801 buffer next time. */
8802 message_buf_print
= 0;
8808 message (const char *m
, ...)
8818 /* The non-logging version of message. */
8821 message_nolog (const char *m
, ...)
8823 Lisp_Object old_log_max
;
8826 old_log_max
= Vmessage_log_max
;
8827 Vmessage_log_max
= Qnil
;
8829 Vmessage_log_max
= old_log_max
;
8835 /* Display the current message in the current mini-buffer. This is
8836 only called from error handlers in process.c, and is not time
8840 update_echo_area (void)
8842 if (!NILP (echo_area_buffer
[0]))
8845 string
= Fcurrent_message ();
8846 message3 (string
, SBYTES (string
),
8847 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
8852 /* Make sure echo area buffers in `echo_buffers' are live.
8853 If they aren't, make new ones. */
8856 ensure_echo_area_buffers (void)
8860 for (i
= 0; i
< 2; ++i
)
8861 if (!BUFFERP (echo_buffer
[i
])
8862 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
8865 Lisp_Object old_buffer
;
8868 old_buffer
= echo_buffer
[i
];
8869 sprintf (name
, " *Echo Area %d*", i
);
8870 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8871 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
8872 /* to force word wrap in echo area -
8873 it was decided to postpone this*/
8874 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8876 for (j
= 0; j
< 2; ++j
)
8877 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8878 echo_area_buffer
[j
] = echo_buffer
[i
];
8883 /* Call FN with args A1..A4 with either the current or last displayed
8884 echo_area_buffer as current buffer.
8886 WHICH zero means use the current message buffer
8887 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8888 from echo_buffer[] and clear it.
8890 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8891 suitable buffer from echo_buffer[] and clear it.
8893 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8894 that the current message becomes the last displayed one, make
8895 choose a suitable buffer for echo_area_buffer[0], and clear it.
8897 Value is what FN returns. */
8900 with_echo_area_buffer (struct window
*w
, int which
,
8901 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
8902 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8905 int this_one
, the_other
, clear_buffer_p
, rc
;
8906 int count
= SPECPDL_INDEX ();
8908 /* If buffers aren't live, make new ones. */
8909 ensure_echo_area_buffers ();
8914 this_one
= 0, the_other
= 1;
8916 this_one
= 1, the_other
= 0;
8919 this_one
= 0, the_other
= 1;
8922 /* We need a fresh one in case the current echo buffer equals
8923 the one containing the last displayed echo area message. */
8924 if (!NILP (echo_area_buffer
[this_one
])
8925 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8926 echo_area_buffer
[this_one
] = Qnil
;
8929 /* Choose a suitable buffer from echo_buffer[] is we don't
8931 if (NILP (echo_area_buffer
[this_one
]))
8933 echo_area_buffer
[this_one
]
8934 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8935 ? echo_buffer
[the_other
]
8936 : echo_buffer
[this_one
]);
8940 buffer
= echo_area_buffer
[this_one
];
8942 /* Don't get confused by reusing the buffer used for echoing
8943 for a different purpose. */
8944 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8947 record_unwind_protect (unwind_with_echo_area_buffer
,
8948 with_echo_area_buffer_unwind_data (w
));
8950 /* Make the echo area buffer current. Note that for display
8951 purposes, it is not necessary that the displayed window's buffer
8952 == current_buffer, except for text property lookup. So, let's
8953 only set that buffer temporarily here without doing a full
8954 Fset_window_buffer. We must also change w->pointm, though,
8955 because otherwise an assertions in unshow_buffer fails, and Emacs
8957 set_buffer_internal_1 (XBUFFER (buffer
));
8961 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8964 BVAR (current_buffer
, undo_list
) = Qt
;
8965 BVAR (current_buffer
, read_only
) = Qnil
;
8966 specbind (Qinhibit_read_only
, Qt
);
8967 specbind (Qinhibit_modification_hooks
, Qt
);
8969 if (clear_buffer_p
&& Z
> BEG
)
8972 xassert (BEGV
>= BEG
);
8973 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8975 rc
= fn (a1
, a2
, a3
, a4
);
8977 xassert (BEGV
>= BEG
);
8978 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8980 unbind_to (count
, Qnil
);
8985 /* Save state that should be preserved around the call to the function
8986 FN called in with_echo_area_buffer. */
8989 with_echo_area_buffer_unwind_data (struct window
*w
)
8992 Lisp_Object vector
, tmp
;
8994 /* Reduce consing by keeping one vector in
8995 Vwith_echo_area_save_vector. */
8996 vector
= Vwith_echo_area_save_vector
;
8997 Vwith_echo_area_save_vector
= Qnil
;
9000 vector
= Fmake_vector (make_number (7), Qnil
);
9002 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9003 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9004 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9008 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9009 ASET (vector
, i
, w
->buffer
); ++i
;
9010 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9011 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9016 for (; i
< end
; ++i
)
9017 ASET (vector
, i
, Qnil
);
9020 xassert (i
== ASIZE (vector
));
9025 /* Restore global state from VECTOR which was created by
9026 with_echo_area_buffer_unwind_data. */
9029 unwind_with_echo_area_buffer (Lisp_Object vector
)
9031 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9032 Vdeactivate_mark
= AREF (vector
, 1);
9033 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9035 if (WINDOWP (AREF (vector
, 3)))
9038 Lisp_Object buffer
, charpos
, bytepos
;
9040 w
= XWINDOW (AREF (vector
, 3));
9041 buffer
= AREF (vector
, 4);
9042 charpos
= AREF (vector
, 5);
9043 bytepos
= AREF (vector
, 6);
9046 set_marker_both (w
->pointm
, buffer
,
9047 XFASTINT (charpos
), XFASTINT (bytepos
));
9050 Vwith_echo_area_save_vector
= vector
;
9055 /* Set up the echo area for use by print functions. MULTIBYTE_P
9056 non-zero means we will print multibyte. */
9059 setup_echo_area_for_printing (int multibyte_p
)
9061 /* If we can't find an echo area any more, exit. */
9062 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9065 ensure_echo_area_buffers ();
9067 if (!message_buf_print
)
9069 /* A message has been output since the last time we printed.
9070 Choose a fresh echo area buffer. */
9071 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9072 echo_area_buffer
[0] = echo_buffer
[1];
9074 echo_area_buffer
[0] = echo_buffer
[0];
9076 /* Switch to that buffer and clear it. */
9077 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9078 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9082 int count
= SPECPDL_INDEX ();
9083 specbind (Qinhibit_read_only
, Qt
);
9084 /* Note that undo recording is always disabled. */
9086 unbind_to (count
, Qnil
);
9088 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9090 /* Set up the buffer for the multibyteness we need. */
9092 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9093 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9095 /* Raise the frame containing the echo area. */
9096 if (minibuffer_auto_raise
)
9098 struct frame
*sf
= SELECTED_FRAME ();
9099 Lisp_Object mini_window
;
9100 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9101 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9104 message_log_maybe_newline ();
9105 message_buf_print
= 1;
9109 if (NILP (echo_area_buffer
[0]))
9111 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9112 echo_area_buffer
[0] = echo_buffer
[1];
9114 echo_area_buffer
[0] = echo_buffer
[0];
9117 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9119 /* Someone switched buffers between print requests. */
9120 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9121 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9127 /* Display an echo area message in window W. Value is non-zero if W's
9128 height is changed. If display_last_displayed_message_p is
9129 non-zero, display the message that was last displayed, otherwise
9130 display the current message. */
9133 display_echo_area (struct window
*w
)
9135 int i
, no_message_p
, window_height_changed_p
, count
;
9137 /* Temporarily disable garbage collections while displaying the echo
9138 area. This is done because a GC can print a message itself.
9139 That message would modify the echo area buffer's contents while a
9140 redisplay of the buffer is going on, and seriously confuse
9142 count
= inhibit_garbage_collection ();
9144 /* If there is no message, we must call display_echo_area_1
9145 nevertheless because it resizes the window. But we will have to
9146 reset the echo_area_buffer in question to nil at the end because
9147 with_echo_area_buffer will sets it to an empty buffer. */
9148 i
= display_last_displayed_message_p
? 1 : 0;
9149 no_message_p
= NILP (echo_area_buffer
[i
]);
9151 window_height_changed_p
9152 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9153 display_echo_area_1
,
9154 (intptr_t) w
, Qnil
, 0, 0);
9157 echo_area_buffer
[i
] = Qnil
;
9159 unbind_to (count
, Qnil
);
9160 return window_height_changed_p
;
9164 /* Helper for display_echo_area. Display the current buffer which
9165 contains the current echo area message in window W, a mini-window,
9166 a pointer to which is passed in A1. A2..A4 are currently not used.
9167 Change the height of W so that all of the message is displayed.
9168 Value is non-zero if height of W was changed. */
9171 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9174 struct window
*w
= (struct window
*) i1
;
9176 struct text_pos start
;
9177 int window_height_changed_p
= 0;
9179 /* Do this before displaying, so that we have a large enough glyph
9180 matrix for the display. If we can't get enough space for the
9181 whole text, display the last N lines. That works by setting w->start. */
9182 window_height_changed_p
= resize_mini_window (w
, 0);
9184 /* Use the starting position chosen by resize_mini_window. */
9185 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9188 clear_glyph_matrix (w
->desired_matrix
);
9189 XSETWINDOW (window
, w
);
9190 try_window (window
, start
, 0);
9192 return window_height_changed_p
;
9196 /* Resize the echo area window to exactly the size needed for the
9197 currently displayed message, if there is one. If a mini-buffer
9198 is active, don't shrink it. */
9201 resize_echo_area_exactly (void)
9203 if (BUFFERP (echo_area_buffer
[0])
9204 && WINDOWP (echo_area_window
))
9206 struct window
*w
= XWINDOW (echo_area_window
);
9208 Lisp_Object resize_exactly
;
9210 if (minibuf_level
== 0)
9211 resize_exactly
= Qt
;
9213 resize_exactly
= Qnil
;
9215 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9216 (intptr_t) w
, resize_exactly
,
9220 ++windows_or_buffers_changed
;
9221 ++update_mode_lines
;
9222 redisplay_internal ();
9228 /* Callback function for with_echo_area_buffer, when used from
9229 resize_echo_area_exactly. A1 contains a pointer to the window to
9230 resize, EXACTLY non-nil means resize the mini-window exactly to the
9231 size of the text displayed. A3 and A4 are not used. Value is what
9232 resize_mini_window returns. */
9235 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9238 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9242 /* Resize mini-window W to fit the size of its contents. EXACT_P
9243 means size the window exactly to the size needed. Otherwise, it's
9244 only enlarged until W's buffer is empty.
9246 Set W->start to the right place to begin display. If the whole
9247 contents fit, start at the beginning. Otherwise, start so as
9248 to make the end of the contents appear. This is particularly
9249 important for y-or-n-p, but seems desirable generally.
9251 Value is non-zero if the window height has been changed. */
9254 resize_mini_window (struct window
*w
, int exact_p
)
9256 struct frame
*f
= XFRAME (w
->frame
);
9257 int window_height_changed_p
= 0;
9259 xassert (MINI_WINDOW_P (w
));
9261 /* By default, start display at the beginning. */
9262 set_marker_both (w
->start
, w
->buffer
,
9263 BUF_BEGV (XBUFFER (w
->buffer
)),
9264 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9266 /* Don't resize windows while redisplaying a window; it would
9267 confuse redisplay functions when the size of the window they are
9268 displaying changes from under them. Such a resizing can happen,
9269 for instance, when which-func prints a long message while
9270 we are running fontification-functions. We're running these
9271 functions with safe_call which binds inhibit-redisplay to t. */
9272 if (!NILP (Vinhibit_redisplay
))
9275 /* Nil means don't try to resize. */
9276 if (NILP (Vresize_mini_windows
)
9277 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9280 if (!FRAME_MINIBUF_ONLY_P (f
))
9283 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9284 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9285 int height
, max_height
;
9286 int unit
= FRAME_LINE_HEIGHT (f
);
9287 struct text_pos start
;
9288 struct buffer
*old_current_buffer
= NULL
;
9290 if (current_buffer
!= XBUFFER (w
->buffer
))
9292 old_current_buffer
= current_buffer
;
9293 set_buffer_internal (XBUFFER (w
->buffer
));
9296 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9298 /* Compute the max. number of lines specified by the user. */
9299 if (FLOATP (Vmax_mini_window_height
))
9300 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9301 else if (INTEGERP (Vmax_mini_window_height
))
9302 max_height
= XINT (Vmax_mini_window_height
);
9304 max_height
= total_height
/ 4;
9306 /* Correct that max. height if it's bogus. */
9307 max_height
= max (1, max_height
);
9308 max_height
= min (total_height
, max_height
);
9310 /* Find out the height of the text in the window. */
9311 if (it
.line_wrap
== TRUNCATE
)
9316 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9317 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9318 height
= it
.current_y
+ last_height
;
9320 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9321 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9322 height
= (height
+ unit
- 1) / unit
;
9325 /* Compute a suitable window start. */
9326 if (height
> max_height
)
9328 height
= max_height
;
9329 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9330 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9331 start
= it
.current
.pos
;
9334 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9335 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9337 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9339 /* Let it grow only, until we display an empty message, in which
9340 case the window shrinks again. */
9341 if (height
> WINDOW_TOTAL_LINES (w
))
9343 int old_height
= WINDOW_TOTAL_LINES (w
);
9344 freeze_window_starts (f
, 1);
9345 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9346 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9348 else if (height
< WINDOW_TOTAL_LINES (w
)
9349 && (exact_p
|| BEGV
== ZV
))
9351 int old_height
= WINDOW_TOTAL_LINES (w
);
9352 freeze_window_starts (f
, 0);
9353 shrink_mini_window (w
);
9354 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9359 /* Always resize to exact size needed. */
9360 if (height
> WINDOW_TOTAL_LINES (w
))
9362 int old_height
= WINDOW_TOTAL_LINES (w
);
9363 freeze_window_starts (f
, 1);
9364 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9365 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9367 else if (height
< WINDOW_TOTAL_LINES (w
))
9369 int old_height
= WINDOW_TOTAL_LINES (w
);
9370 freeze_window_starts (f
, 0);
9371 shrink_mini_window (w
);
9375 freeze_window_starts (f
, 1);
9376 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9379 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9383 if (old_current_buffer
)
9384 set_buffer_internal (old_current_buffer
);
9387 return window_height_changed_p
;
9391 /* Value is the current message, a string, or nil if there is no
9395 current_message (void)
9399 if (!BUFFERP (echo_area_buffer
[0]))
9403 with_echo_area_buffer (0, 0, current_message_1
,
9404 (intptr_t) &msg
, Qnil
, 0, 0);
9406 echo_area_buffer
[0] = Qnil
;
9414 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9417 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9420 *msg
= make_buffer_string (BEG
, Z
, 1);
9427 /* Push the current message on Vmessage_stack for later restauration
9428 by restore_message. Value is non-zero if the current message isn't
9429 empty. This is a relatively infrequent operation, so it's not
9430 worth optimizing. */
9436 msg
= current_message ();
9437 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9438 return STRINGP (msg
);
9442 /* Restore message display from the top of Vmessage_stack. */
9445 restore_message (void)
9449 xassert (CONSP (Vmessage_stack
));
9450 msg
= XCAR (Vmessage_stack
);
9452 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9454 message3_nolog (msg
, 0, 0);
9458 /* Handler for record_unwind_protect calling pop_message. */
9461 pop_message_unwind (Lisp_Object dummy
)
9467 /* Pop the top-most entry off Vmessage_stack. */
9472 xassert (CONSP (Vmessage_stack
));
9473 Vmessage_stack
= XCDR (Vmessage_stack
);
9477 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9478 exits. If the stack is not empty, we have a missing pop_message
9482 check_message_stack (void)
9484 if (!NILP (Vmessage_stack
))
9489 /* Truncate to NCHARS what will be displayed in the echo area the next
9490 time we display it---but don't redisplay it now. */
9493 truncate_echo_area (EMACS_INT nchars
)
9496 echo_area_buffer
[0] = Qnil
;
9497 /* A null message buffer means that the frame hasn't really been
9498 initialized yet. Error messages get reported properly by
9499 cmd_error, so this must be just an informative message; toss it. */
9500 else if (!noninteractive
9502 && !NILP (echo_area_buffer
[0]))
9504 struct frame
*sf
= SELECTED_FRAME ();
9505 if (FRAME_MESSAGE_BUF (sf
))
9506 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9511 /* Helper function for truncate_echo_area. Truncate the current
9512 message to at most NCHARS characters. */
9515 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9517 if (BEG
+ nchars
< Z
)
9518 del_range (BEG
+ nchars
, Z
);
9520 echo_area_buffer
[0] = Qnil
;
9525 /* Set the current message to a substring of S or STRING.
9527 If STRING is a Lisp string, set the message to the first NBYTES
9528 bytes from STRING. NBYTES zero means use the whole string. If
9529 STRING is multibyte, the message will be displayed multibyte.
9531 If S is not null, set the message to the first LEN bytes of S. LEN
9532 zero means use the whole string. MULTIBYTE_P non-zero means S is
9533 multibyte. Display the message multibyte in that case.
9535 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9536 to t before calling set_message_1 (which calls insert).
9540 set_message (const char *s
, Lisp_Object string
,
9541 EMACS_INT nbytes
, int multibyte_p
)
9543 message_enable_multibyte
9544 = ((s
&& multibyte_p
)
9545 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9547 with_echo_area_buffer (0, -1, set_message_1
,
9548 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9549 message_buf_print
= 0;
9550 help_echo_showing_p
= 0;
9554 /* Helper function for set_message. Arguments have the same meaning
9555 as there, with A1 corresponding to S and A2 corresponding to STRING
9556 This function is called with the echo area buffer being
9560 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9563 const char *s
= (const char *) i1
;
9564 const unsigned char *msg
= (const unsigned char *) s
;
9565 Lisp_Object string
= a2
;
9567 /* Change multibyteness of the echo buffer appropriately. */
9568 if (message_enable_multibyte
9569 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9570 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9572 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9573 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9574 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9576 /* Insert new message at BEG. */
9577 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9579 if (STRINGP (string
))
9584 nbytes
= SBYTES (string
);
9585 nchars
= string_byte_to_char (string
, nbytes
);
9587 /* This function takes care of single/multibyte conversion. We
9588 just have to ensure that the echo area buffer has the right
9589 setting of enable_multibyte_characters. */
9590 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9595 nbytes
= strlen (s
);
9597 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9599 /* Convert from multi-byte to single-byte. */
9604 /* Convert a multibyte string to single-byte. */
9605 for (i
= 0; i
< nbytes
; i
+= n
)
9607 c
= string_char_and_length (msg
+ i
, &n
);
9608 work
[0] = (ASCII_CHAR_P (c
)
9610 : multibyte_char_to_unibyte (c
));
9611 insert_1_both (work
, 1, 1, 1, 0, 0);
9614 else if (!multibyte_p
9615 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9617 /* Convert from single-byte to multi-byte. */
9620 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9622 /* Convert a single-byte string to multibyte. */
9623 for (i
= 0; i
< nbytes
; i
++)
9626 MAKE_CHAR_MULTIBYTE (c
);
9627 n
= CHAR_STRING (c
, str
);
9628 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9632 insert_1 (s
, nbytes
, 1, 0, 0);
9639 /* Clear messages. CURRENT_P non-zero means clear the current
9640 message. LAST_DISPLAYED_P non-zero means clear the message
9644 clear_message (int current_p
, int last_displayed_p
)
9648 echo_area_buffer
[0] = Qnil
;
9649 message_cleared_p
= 1;
9652 if (last_displayed_p
)
9653 echo_area_buffer
[1] = Qnil
;
9655 message_buf_print
= 0;
9658 /* Clear garbaged frames.
9660 This function is used where the old redisplay called
9661 redraw_garbaged_frames which in turn called redraw_frame which in
9662 turn called clear_frame. The call to clear_frame was a source of
9663 flickering. I believe a clear_frame is not necessary. It should
9664 suffice in the new redisplay to invalidate all current matrices,
9665 and ensure a complete redisplay of all windows. */
9668 clear_garbaged_frames (void)
9672 Lisp_Object tail
, frame
;
9673 int changed_count
= 0;
9675 FOR_EACH_FRAME (tail
, frame
)
9677 struct frame
*f
= XFRAME (frame
);
9679 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9683 Fredraw_frame (frame
);
9684 f
->force_flush_display_p
= 1;
9686 clear_current_matrices (f
);
9695 ++windows_or_buffers_changed
;
9700 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9701 is non-zero update selected_frame. Value is non-zero if the
9702 mini-windows height has been changed. */
9705 echo_area_display (int update_frame_p
)
9707 Lisp_Object mini_window
;
9710 int window_height_changed_p
= 0;
9711 struct frame
*sf
= SELECTED_FRAME ();
9713 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9714 w
= XWINDOW (mini_window
);
9715 f
= XFRAME (WINDOW_FRAME (w
));
9717 /* Don't display if frame is invisible or not yet initialized. */
9718 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9721 #ifdef HAVE_WINDOW_SYSTEM
9722 /* When Emacs starts, selected_frame may be the initial terminal
9723 frame. If we let this through, a message would be displayed on
9725 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9727 #endif /* HAVE_WINDOW_SYSTEM */
9729 /* Redraw garbaged frames. */
9731 clear_garbaged_frames ();
9733 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9735 echo_area_window
= mini_window
;
9736 window_height_changed_p
= display_echo_area (w
);
9737 w
->must_be_updated_p
= 1;
9739 /* Update the display, unless called from redisplay_internal.
9740 Also don't update the screen during redisplay itself. The
9741 update will happen at the end of redisplay, and an update
9742 here could cause confusion. */
9743 if (update_frame_p
&& !redisplaying_p
)
9747 /* If the display update has been interrupted by pending
9748 input, update mode lines in the frame. Due to the
9749 pending input, it might have been that redisplay hasn't
9750 been called, so that mode lines above the echo area are
9751 garbaged. This looks odd, so we prevent it here. */
9752 if (!display_completed
)
9753 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9755 if (window_height_changed_p
9756 /* Don't do this if Emacs is shutting down. Redisplay
9757 needs to run hooks. */
9758 && !NILP (Vrun_hooks
))
9760 /* Must update other windows. Likewise as in other
9761 cases, don't let this update be interrupted by
9763 int count
= SPECPDL_INDEX ();
9764 specbind (Qredisplay_dont_pause
, Qt
);
9765 windows_or_buffers_changed
= 1;
9766 redisplay_internal ();
9767 unbind_to (count
, Qnil
);
9769 else if (FRAME_WINDOW_P (f
) && n
== 0)
9771 /* Window configuration is the same as before.
9772 Can do with a display update of the echo area,
9773 unless we displayed some mode lines. */
9774 update_single_window (w
, 1);
9775 FRAME_RIF (f
)->flush_display (f
);
9778 update_frame (f
, 1, 1);
9780 /* If cursor is in the echo area, make sure that the next
9781 redisplay displays the minibuffer, so that the cursor will
9782 be replaced with what the minibuffer wants. */
9783 if (cursor_in_echo_area
)
9784 ++windows_or_buffers_changed
;
9787 else if (!EQ (mini_window
, selected_window
))
9788 windows_or_buffers_changed
++;
9790 /* Last displayed message is now the current message. */
9791 echo_area_buffer
[1] = echo_area_buffer
[0];
9792 /* Inform read_char that we're not echoing. */
9793 echo_message_buffer
= Qnil
;
9795 /* Prevent redisplay optimization in redisplay_internal by resetting
9796 this_line_start_pos. This is done because the mini-buffer now
9797 displays the message instead of its buffer text. */
9798 if (EQ (mini_window
, selected_window
))
9799 CHARPOS (this_line_start_pos
) = 0;
9801 return window_height_changed_p
;
9806 /***********************************************************************
9807 Mode Lines and Frame Titles
9808 ***********************************************************************/
9810 /* A buffer for constructing non-propertized mode-line strings and
9811 frame titles in it; allocated from the heap in init_xdisp and
9812 resized as needed in store_mode_line_noprop_char. */
9814 static char *mode_line_noprop_buf
;
9816 /* The buffer's end, and a current output position in it. */
9818 static char *mode_line_noprop_buf_end
;
9819 static char *mode_line_noprop_ptr
;
9821 #define MODE_LINE_NOPROP_LEN(start) \
9822 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9825 MODE_LINE_DISPLAY
= 0,
9831 /* Alist that caches the results of :propertize.
9832 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9833 static Lisp_Object mode_line_proptrans_alist
;
9835 /* List of strings making up the mode-line. */
9836 static Lisp_Object mode_line_string_list
;
9838 /* Base face property when building propertized mode line string. */
9839 static Lisp_Object mode_line_string_face
;
9840 static Lisp_Object mode_line_string_face_prop
;
9843 /* Unwind data for mode line strings */
9845 static Lisp_Object Vmode_line_unwind_vector
;
9848 format_mode_line_unwind_data (struct buffer
*obuf
,
9852 Lisp_Object vector
, tmp
;
9854 /* Reduce consing by keeping one vector in
9855 Vwith_echo_area_save_vector. */
9856 vector
= Vmode_line_unwind_vector
;
9857 Vmode_line_unwind_vector
= Qnil
;
9860 vector
= Fmake_vector (make_number (8), Qnil
);
9862 ASET (vector
, 0, make_number (mode_line_target
));
9863 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9864 ASET (vector
, 2, mode_line_string_list
);
9865 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9866 ASET (vector
, 4, mode_line_string_face
);
9867 ASET (vector
, 5, mode_line_string_face_prop
);
9870 XSETBUFFER (tmp
, obuf
);
9873 ASET (vector
, 6, tmp
);
9874 ASET (vector
, 7, owin
);
9880 unwind_format_mode_line (Lisp_Object vector
)
9882 mode_line_target
= XINT (AREF (vector
, 0));
9883 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9884 mode_line_string_list
= AREF (vector
, 2);
9885 if (! EQ (AREF (vector
, 3), Qt
))
9886 mode_line_proptrans_alist
= AREF (vector
, 3);
9887 mode_line_string_face
= AREF (vector
, 4);
9888 mode_line_string_face_prop
= AREF (vector
, 5);
9890 if (!NILP (AREF (vector
, 7)))
9891 /* Select window before buffer, since it may change the buffer. */
9892 Fselect_window (AREF (vector
, 7), Qt
);
9894 if (!NILP (AREF (vector
, 6)))
9896 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9897 ASET (vector
, 6, Qnil
);
9900 Vmode_line_unwind_vector
= vector
;
9905 /* Store a single character C for the frame title in mode_line_noprop_buf.
9906 Re-allocate mode_line_noprop_buf if necessary. */
9909 store_mode_line_noprop_char (char c
)
9911 /* If output position has reached the end of the allocated buffer,
9912 double the buffer's size. */
9913 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9915 int len
= MODE_LINE_NOPROP_LEN (0);
9916 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9917 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9918 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9919 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9922 *mode_line_noprop_ptr
++ = c
;
9926 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9927 mode_line_noprop_ptr. STRING is the string to store. Do not copy
9928 characters that yield more columns than PRECISION; PRECISION <= 0
9929 means copy the whole string. Pad with spaces until FIELD_WIDTH
9930 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9931 pad. Called from display_mode_element when it is used to build a
9935 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
9937 const unsigned char *str
= (const unsigned char *) string
;
9939 EMACS_INT dummy
, nbytes
;
9941 /* Copy at most PRECISION chars from STR. */
9942 nbytes
= strlen (string
);
9943 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9945 store_mode_line_noprop_char (*str
++);
9947 /* Fill up with spaces until FIELD_WIDTH reached. */
9948 while (field_width
> 0
9951 store_mode_line_noprop_char (' ');
9958 /***********************************************************************
9960 ***********************************************************************/
9962 #ifdef HAVE_WINDOW_SYSTEM
9964 /* Set the title of FRAME, if it has changed. The title format is
9965 Vicon_title_format if FRAME is iconified, otherwise it is
9966 frame_title_format. */
9969 x_consider_frame_title (Lisp_Object frame
)
9971 struct frame
*f
= XFRAME (frame
);
9973 if (FRAME_WINDOW_P (f
)
9974 || FRAME_MINIBUF_ONLY_P (f
)
9975 || f
->explicit_name
)
9977 /* Do we have more than one visible frame on this X display? */
9984 int count
= SPECPDL_INDEX ();
9986 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9988 Lisp_Object other_frame
= XCAR (tail
);
9989 struct frame
*tf
= XFRAME (other_frame
);
9992 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9993 && !FRAME_MINIBUF_ONLY_P (tf
)
9994 && !EQ (other_frame
, tip_frame
)
9995 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9999 /* Set global variable indicating that multiple frames exist. */
10000 multiple_frames
= CONSP (tail
);
10002 /* Switch to the buffer of selected window of the frame. Set up
10003 mode_line_target so that display_mode_element will output into
10004 mode_line_noprop_buf; then display the title. */
10005 record_unwind_protect (unwind_format_mode_line
,
10006 format_mode_line_unwind_data
10007 (current_buffer
, selected_window
, 0));
10009 Fselect_window (f
->selected_window
, Qt
);
10010 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10011 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10013 mode_line_target
= MODE_LINE_TITLE
;
10014 title_start
= MODE_LINE_NOPROP_LEN (0);
10015 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10016 NULL
, DEFAULT_FACE_ID
);
10017 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10018 len
= MODE_LINE_NOPROP_LEN (title_start
);
10019 title
= mode_line_noprop_buf
+ title_start
;
10020 unbind_to (count
, Qnil
);
10022 /* Set the title only if it's changed. This avoids consing in
10023 the common case where it hasn't. (If it turns out that we've
10024 already wasted too much time by walking through the list with
10025 display_mode_element, then we might need to optimize at a
10026 higher level than this.) */
10027 if (! STRINGP (f
->name
)
10028 || SBYTES (f
->name
) != len
10029 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10030 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10034 #endif /* not HAVE_WINDOW_SYSTEM */
10039 /***********************************************************************
10041 ***********************************************************************/
10044 /* Prepare for redisplay by updating menu-bar item lists when
10045 appropriate. This can call eval. */
10048 prepare_menu_bars (void)
10051 struct gcpro gcpro1
, gcpro2
;
10053 Lisp_Object tooltip_frame
;
10055 #ifdef HAVE_WINDOW_SYSTEM
10056 tooltip_frame
= tip_frame
;
10058 tooltip_frame
= Qnil
;
10061 /* Update all frame titles based on their buffer names, etc. We do
10062 this before the menu bars so that the buffer-menu will show the
10063 up-to-date frame titles. */
10064 #ifdef HAVE_WINDOW_SYSTEM
10065 if (windows_or_buffers_changed
|| update_mode_lines
)
10067 Lisp_Object tail
, frame
;
10069 FOR_EACH_FRAME (tail
, frame
)
10071 f
= XFRAME (frame
);
10072 if (!EQ (frame
, tooltip_frame
)
10073 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10074 x_consider_frame_title (frame
);
10077 #endif /* HAVE_WINDOW_SYSTEM */
10079 /* Update the menu bar item lists, if appropriate. This has to be
10080 done before any actual redisplay or generation of display lines. */
10081 all_windows
= (update_mode_lines
10082 || buffer_shared
> 1
10083 || windows_or_buffers_changed
);
10086 Lisp_Object tail
, frame
;
10087 int count
= SPECPDL_INDEX ();
10088 /* 1 means that update_menu_bar has run its hooks
10089 so any further calls to update_menu_bar shouldn't do so again. */
10090 int menu_bar_hooks_run
= 0;
10092 record_unwind_save_match_data ();
10094 FOR_EACH_FRAME (tail
, frame
)
10096 f
= XFRAME (frame
);
10098 /* Ignore tooltip frame. */
10099 if (EQ (frame
, tooltip_frame
))
10102 /* If a window on this frame changed size, report that to
10103 the user and clear the size-change flag. */
10104 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10106 Lisp_Object functions
;
10108 /* Clear flag first in case we get an error below. */
10109 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10110 functions
= Vwindow_size_change_functions
;
10111 GCPRO2 (tail
, functions
);
10113 while (CONSP (functions
))
10115 if (!EQ (XCAR (functions
), Qt
))
10116 call1 (XCAR (functions
), frame
);
10117 functions
= XCDR (functions
);
10123 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10124 #ifdef HAVE_WINDOW_SYSTEM
10125 update_tool_bar (f
, 0);
10128 if (windows_or_buffers_changed
10130 ns_set_doc_edited (f
, Fbuffer_modified_p
10131 (XWINDOW (f
->selected_window
)->buffer
));
10136 unbind_to (count
, Qnil
);
10140 struct frame
*sf
= SELECTED_FRAME ();
10141 update_menu_bar (sf
, 1, 0);
10142 #ifdef HAVE_WINDOW_SYSTEM
10143 update_tool_bar (sf
, 1);
10149 /* Update the menu bar item list for frame F. This has to be done
10150 before we start to fill in any display lines, because it can call
10153 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10155 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10156 already ran the menu bar hooks for this redisplay, so there
10157 is no need to run them again. The return value is the
10158 updated value of this flag, to pass to the next call. */
10161 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10163 Lisp_Object window
;
10164 register struct window
*w
;
10166 /* If called recursively during a menu update, do nothing. This can
10167 happen when, for instance, an activate-menubar-hook causes a
10169 if (inhibit_menubar_update
)
10172 window
= FRAME_SELECTED_WINDOW (f
);
10173 w
= XWINDOW (window
);
10175 if (FRAME_WINDOW_P (f
)
10177 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10178 || defined (HAVE_NS) || defined (USE_GTK)
10179 FRAME_EXTERNAL_MENU_BAR (f
)
10181 FRAME_MENU_BAR_LINES (f
) > 0
10183 : FRAME_MENU_BAR_LINES (f
) > 0)
10185 /* If the user has switched buffers or windows, we need to
10186 recompute to reflect the new bindings. But we'll
10187 recompute when update_mode_lines is set too; that means
10188 that people can use force-mode-line-update to request
10189 that the menu bar be recomputed. The adverse effect on
10190 the rest of the redisplay algorithm is about the same as
10191 windows_or_buffers_changed anyway. */
10192 if (windows_or_buffers_changed
10193 /* This used to test w->update_mode_line, but we believe
10194 there is no need to recompute the menu in that case. */
10195 || update_mode_lines
10196 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10197 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10198 != !NILP (w
->last_had_star
))
10199 || ((!NILP (Vtransient_mark_mode
)
10200 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10201 != !NILP (w
->region_showing
)))
10203 struct buffer
*prev
= current_buffer
;
10204 int count
= SPECPDL_INDEX ();
10206 specbind (Qinhibit_menubar_update
, Qt
);
10208 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10209 if (save_match_data
)
10210 record_unwind_save_match_data ();
10211 if (NILP (Voverriding_local_map_menu_flag
))
10213 specbind (Qoverriding_terminal_local_map
, Qnil
);
10214 specbind (Qoverriding_local_map
, Qnil
);
10219 /* Run the Lucid hook. */
10220 safe_run_hooks (Qactivate_menubar_hook
);
10222 /* If it has changed current-menubar from previous value,
10223 really recompute the menu-bar from the value. */
10224 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10225 call0 (Qrecompute_lucid_menubar
);
10227 safe_run_hooks (Qmenu_bar_update_hook
);
10232 XSETFRAME (Vmenu_updating_frame
, f
);
10233 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10235 /* Redisplay the menu bar in case we changed it. */
10236 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10237 || defined (HAVE_NS) || defined (USE_GTK)
10238 if (FRAME_WINDOW_P (f
))
10240 #if defined (HAVE_NS)
10241 /* All frames on Mac OS share the same menubar. So only
10242 the selected frame should be allowed to set it. */
10243 if (f
== SELECTED_FRAME ())
10245 set_frame_menubar (f
, 0, 0);
10248 /* On a terminal screen, the menu bar is an ordinary screen
10249 line, and this makes it get updated. */
10250 w
->update_mode_line
= Qt
;
10251 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10252 /* In the non-toolkit version, the menu bar is an ordinary screen
10253 line, and this makes it get updated. */
10254 w
->update_mode_line
= Qt
;
10255 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10257 unbind_to (count
, Qnil
);
10258 set_buffer_internal_1 (prev
);
10267 /***********************************************************************
10269 ***********************************************************************/
10271 #ifdef HAVE_WINDOW_SYSTEM
10274 Nominal cursor position -- where to draw output.
10275 HPOS and VPOS are window relative glyph matrix coordinates.
10276 X and Y are window relative pixel coordinates. */
10278 struct cursor_pos output_cursor
;
10282 Set the global variable output_cursor to CURSOR. All cursor
10283 positions are relative to updated_window. */
10286 set_output_cursor (struct cursor_pos
*cursor
)
10288 output_cursor
.hpos
= cursor
->hpos
;
10289 output_cursor
.vpos
= cursor
->vpos
;
10290 output_cursor
.x
= cursor
->x
;
10291 output_cursor
.y
= cursor
->y
;
10296 Set a nominal cursor position.
10298 HPOS and VPOS are column/row positions in a window glyph matrix. X
10299 and Y are window text area relative pixel positions.
10301 If this is done during an update, updated_window will contain the
10302 window that is being updated and the position is the future output
10303 cursor position for that window. If updated_window is null, use
10304 selected_window and display the cursor at the given position. */
10307 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10311 /* If updated_window is not set, work on selected_window. */
10312 if (updated_window
)
10313 w
= updated_window
;
10315 w
= XWINDOW (selected_window
);
10317 /* Set the output cursor. */
10318 output_cursor
.hpos
= hpos
;
10319 output_cursor
.vpos
= vpos
;
10320 output_cursor
.x
= x
;
10321 output_cursor
.y
= y
;
10323 /* If not called as part of an update, really display the cursor.
10324 This will also set the cursor position of W. */
10325 if (updated_window
== NULL
)
10328 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10329 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10330 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10335 #endif /* HAVE_WINDOW_SYSTEM */
10338 /***********************************************************************
10340 ***********************************************************************/
10342 #ifdef HAVE_WINDOW_SYSTEM
10344 /* Where the mouse was last time we reported a mouse event. */
10346 FRAME_PTR last_mouse_frame
;
10348 /* Tool-bar item index of the item on which a mouse button was pressed
10351 int last_tool_bar_item
;
10355 update_tool_bar_unwind (Lisp_Object frame
)
10357 selected_frame
= frame
;
10361 /* Update the tool-bar item list for frame F. This has to be done
10362 before we start to fill in any display lines. Called from
10363 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10364 and restore it here. */
10367 update_tool_bar (struct frame
*f
, int save_match_data
)
10369 #if defined (USE_GTK) || defined (HAVE_NS)
10370 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10372 int do_update
= WINDOWP (f
->tool_bar_window
)
10373 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10378 Lisp_Object window
;
10381 window
= FRAME_SELECTED_WINDOW (f
);
10382 w
= XWINDOW (window
);
10384 /* If the user has switched buffers or windows, we need to
10385 recompute to reflect the new bindings. But we'll
10386 recompute when update_mode_lines is set too; that means
10387 that people can use force-mode-line-update to request
10388 that the menu bar be recomputed. The adverse effect on
10389 the rest of the redisplay algorithm is about the same as
10390 windows_or_buffers_changed anyway. */
10391 if (windows_or_buffers_changed
10392 || !NILP (w
->update_mode_line
)
10393 || update_mode_lines
10394 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10395 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10396 != !NILP (w
->last_had_star
))
10397 || ((!NILP (Vtransient_mark_mode
)
10398 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10399 != !NILP (w
->region_showing
)))
10401 struct buffer
*prev
= current_buffer
;
10402 int count
= SPECPDL_INDEX ();
10403 Lisp_Object frame
, new_tool_bar
;
10404 int new_n_tool_bar
;
10405 struct gcpro gcpro1
;
10407 /* Set current_buffer to the buffer of the selected
10408 window of the frame, so that we get the right local
10410 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10412 /* Save match data, if we must. */
10413 if (save_match_data
)
10414 record_unwind_save_match_data ();
10416 /* Make sure that we don't accidentally use bogus keymaps. */
10417 if (NILP (Voverriding_local_map_menu_flag
))
10419 specbind (Qoverriding_terminal_local_map
, Qnil
);
10420 specbind (Qoverriding_local_map
, Qnil
);
10423 GCPRO1 (new_tool_bar
);
10425 /* We must temporarily set the selected frame to this frame
10426 before calling tool_bar_items, because the calculation of
10427 the tool-bar keymap uses the selected frame (see
10428 `tool-bar-make-keymap' in tool-bar.el). */
10429 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10430 XSETFRAME (frame
, f
);
10431 selected_frame
= frame
;
10433 /* Build desired tool-bar items from keymaps. */
10434 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10437 /* Redisplay the tool-bar if we changed it. */
10438 if (new_n_tool_bar
!= f
->n_tool_bar_items
10439 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10441 /* Redisplay that happens asynchronously due to an expose event
10442 may access f->tool_bar_items. Make sure we update both
10443 variables within BLOCK_INPUT so no such event interrupts. */
10445 f
->tool_bar_items
= new_tool_bar
;
10446 f
->n_tool_bar_items
= new_n_tool_bar
;
10447 w
->update_mode_line
= Qt
;
10453 unbind_to (count
, Qnil
);
10454 set_buffer_internal_1 (prev
);
10460 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10461 F's desired tool-bar contents. F->tool_bar_items must have
10462 been set up previously by calling prepare_menu_bars. */
10465 build_desired_tool_bar_string (struct frame
*f
)
10467 int i
, size
, size_needed
;
10468 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10469 Lisp_Object image
, plist
, props
;
10471 image
= plist
= props
= Qnil
;
10472 GCPRO3 (image
, plist
, props
);
10474 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10475 Otherwise, make a new string. */
10477 /* The size of the string we might be able to reuse. */
10478 size
= (STRINGP (f
->desired_tool_bar_string
)
10479 ? SCHARS (f
->desired_tool_bar_string
)
10482 /* We need one space in the string for each image. */
10483 size_needed
= f
->n_tool_bar_items
;
10485 /* Reuse f->desired_tool_bar_string, if possible. */
10486 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10487 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10488 make_number (' '));
10491 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10492 Fremove_text_properties (make_number (0), make_number (size
),
10493 props
, f
->desired_tool_bar_string
);
10496 /* Put a `display' property on the string for the images to display,
10497 put a `menu_item' property on tool-bar items with a value that
10498 is the index of the item in F's tool-bar item vector. */
10499 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10501 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10503 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10504 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10505 int hmargin
, vmargin
, relief
, idx
, end
;
10507 /* If image is a vector, choose the image according to the
10509 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10510 if (VECTORP (image
))
10514 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10515 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10518 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10519 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10521 xassert (ASIZE (image
) >= idx
);
10522 image
= AREF (image
, idx
);
10527 /* Ignore invalid image specifications. */
10528 if (!valid_image_p (image
))
10531 /* Display the tool-bar button pressed, or depressed. */
10532 plist
= Fcopy_sequence (XCDR (image
));
10534 /* Compute margin and relief to draw. */
10535 relief
= (tool_bar_button_relief
>= 0
10536 ? tool_bar_button_relief
10537 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10538 hmargin
= vmargin
= relief
;
10540 if (INTEGERP (Vtool_bar_button_margin
)
10541 && XINT (Vtool_bar_button_margin
) > 0)
10543 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10544 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10546 else if (CONSP (Vtool_bar_button_margin
))
10548 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10549 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10550 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10552 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10553 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10554 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10557 if (auto_raise_tool_bar_buttons_p
)
10559 /* Add a `:relief' property to the image spec if the item is
10563 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10570 /* If image is selected, display it pressed, i.e. with a
10571 negative relief. If it's not selected, display it with a
10573 plist
= Fplist_put (plist
, QCrelief
,
10575 ? make_number (-relief
)
10576 : make_number (relief
)));
10581 /* Put a margin around the image. */
10582 if (hmargin
|| vmargin
)
10584 if (hmargin
== vmargin
)
10585 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10587 plist
= Fplist_put (plist
, QCmargin
,
10588 Fcons (make_number (hmargin
),
10589 make_number (vmargin
)));
10592 /* If button is not enabled, and we don't have special images
10593 for the disabled state, make the image appear disabled by
10594 applying an appropriate algorithm to it. */
10595 if (!enabled_p
&& idx
< 0)
10596 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10598 /* Put a `display' text property on the string for the image to
10599 display. Put a `menu-item' property on the string that gives
10600 the start of this item's properties in the tool-bar items
10602 image
= Fcons (Qimage
, plist
);
10603 props
= list4 (Qdisplay
, image
,
10604 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10606 /* Let the last image hide all remaining spaces in the tool bar
10607 string. The string can be longer than needed when we reuse a
10608 previous string. */
10609 if (i
+ 1 == f
->n_tool_bar_items
)
10610 end
= SCHARS (f
->desired_tool_bar_string
);
10613 Fadd_text_properties (make_number (i
), make_number (end
),
10614 props
, f
->desired_tool_bar_string
);
10622 /* Display one line of the tool-bar of frame IT->f.
10624 HEIGHT specifies the desired height of the tool-bar line.
10625 If the actual height of the glyph row is less than HEIGHT, the
10626 row's height is increased to HEIGHT, and the icons are centered
10627 vertically in the new height.
10629 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10630 count a final empty row in case the tool-bar width exactly matches
10635 display_tool_bar_line (struct it
*it
, int height
)
10637 struct glyph_row
*row
= it
->glyph_row
;
10638 int max_x
= it
->last_visible_x
;
10639 struct glyph
*last
;
10641 prepare_desired_row (row
);
10642 row
->y
= it
->current_y
;
10644 /* Note that this isn't made use of if the face hasn't a box,
10645 so there's no need to check the face here. */
10646 it
->start_of_box_run_p
= 1;
10648 while (it
->current_x
< max_x
)
10650 int x
, n_glyphs_before
, i
, nglyphs
;
10651 struct it it_before
;
10653 /* Get the next display element. */
10654 if (!get_next_display_element (it
))
10656 /* Don't count empty row if we are counting needed tool-bar lines. */
10657 if (height
< 0 && !it
->hpos
)
10662 /* Produce glyphs. */
10663 n_glyphs_before
= row
->used
[TEXT_AREA
];
10666 PRODUCE_GLYPHS (it
);
10668 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10670 x
= it_before
.current_x
;
10671 while (i
< nglyphs
)
10673 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10675 if (x
+ glyph
->pixel_width
> max_x
)
10677 /* Glyph doesn't fit on line. Backtrack. */
10678 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10680 /* If this is the only glyph on this line, it will never fit on the
10681 tool-bar, so skip it. But ensure there is at least one glyph,
10682 so we don't accidentally disable the tool-bar. */
10683 if (n_glyphs_before
== 0
10684 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10690 x
+= glyph
->pixel_width
;
10694 /* Stop at line ends. */
10695 if (ITERATOR_AT_END_OF_LINE_P (it
))
10698 set_iterator_to_next (it
, 1);
10703 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10705 /* Use default face for the border below the tool bar.
10707 FIXME: When auto-resize-tool-bars is grow-only, there is
10708 no additional border below the possibly empty tool-bar lines.
10709 So to make the extra empty lines look "normal", we have to
10710 use the tool-bar face for the border too. */
10711 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10712 it
->face_id
= DEFAULT_FACE_ID
;
10714 extend_face_to_end_of_line (it
);
10715 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10716 last
->right_box_line_p
= 1;
10717 if (last
== row
->glyphs
[TEXT_AREA
])
10718 last
->left_box_line_p
= 1;
10720 /* Make line the desired height and center it vertically. */
10721 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10723 /* Don't add more than one line height. */
10724 height
%= FRAME_LINE_HEIGHT (it
->f
);
10725 it
->max_ascent
+= height
/ 2;
10726 it
->max_descent
+= (height
+ 1) / 2;
10729 compute_line_metrics (it
);
10731 /* If line is empty, make it occupy the rest of the tool-bar. */
10732 if (!row
->displays_text_p
)
10734 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10735 row
->visible_height
= row
->height
;
10736 row
->ascent
= row
->phys_ascent
= 0;
10737 row
->extra_line_spacing
= 0;
10740 row
->full_width_p
= 1;
10741 row
->continued_p
= 0;
10742 row
->truncated_on_left_p
= 0;
10743 row
->truncated_on_right_p
= 0;
10745 it
->current_x
= it
->hpos
= 0;
10746 it
->current_y
+= row
->height
;
10752 /* Max tool-bar height. */
10754 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10755 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10757 /* Value is the number of screen lines needed to make all tool-bar
10758 items of frame F visible. The number of actual rows needed is
10759 returned in *N_ROWS if non-NULL. */
10762 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10764 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10766 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10767 the desired matrix, so use (unused) mode-line row as temporary row to
10768 avoid destroying the first tool-bar row. */
10769 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10771 /* Initialize an iterator for iteration over
10772 F->desired_tool_bar_string in the tool-bar window of frame F. */
10773 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10774 it
.first_visible_x
= 0;
10775 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10776 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10778 while (!ITERATOR_AT_END_P (&it
))
10780 clear_glyph_row (temp_row
);
10781 it
.glyph_row
= temp_row
;
10782 display_tool_bar_line (&it
, -1);
10784 clear_glyph_row (temp_row
);
10786 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10788 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10790 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10794 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10796 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10797 (Lisp_Object frame
)
10804 frame
= selected_frame
;
10806 CHECK_FRAME (frame
);
10807 f
= XFRAME (frame
);
10809 if (WINDOWP (f
->tool_bar_window
)
10810 || (w
= XWINDOW (f
->tool_bar_window
),
10811 WINDOW_TOTAL_LINES (w
) > 0))
10813 update_tool_bar (f
, 1);
10814 if (f
->n_tool_bar_items
)
10816 build_desired_tool_bar_string (f
);
10817 nlines
= tool_bar_lines_needed (f
, NULL
);
10821 return make_number (nlines
);
10825 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10826 height should be changed. */
10829 redisplay_tool_bar (struct frame
*f
)
10833 struct glyph_row
*row
;
10835 #if defined (USE_GTK) || defined (HAVE_NS)
10836 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10837 update_frame_tool_bar (f
);
10841 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10842 do anything. This means you must start with tool-bar-lines
10843 non-zero to get the auto-sizing effect. Or in other words, you
10844 can turn off tool-bars by specifying tool-bar-lines zero. */
10845 if (!WINDOWP (f
->tool_bar_window
)
10846 || (w
= XWINDOW (f
->tool_bar_window
),
10847 WINDOW_TOTAL_LINES (w
) == 0))
10850 /* Set up an iterator for the tool-bar window. */
10851 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10852 it
.first_visible_x
= 0;
10853 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10854 row
= it
.glyph_row
;
10856 /* Build a string that represents the contents of the tool-bar. */
10857 build_desired_tool_bar_string (f
);
10858 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10860 if (f
->n_tool_bar_rows
== 0)
10864 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10865 nlines
!= WINDOW_TOTAL_LINES (w
)))
10868 int old_height
= WINDOW_TOTAL_LINES (w
);
10870 XSETFRAME (frame
, f
);
10871 Fmodify_frame_parameters (frame
,
10872 Fcons (Fcons (Qtool_bar_lines
,
10873 make_number (nlines
)),
10875 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10877 clear_glyph_matrix (w
->desired_matrix
);
10878 fonts_changed_p
= 1;
10884 /* Display as many lines as needed to display all tool-bar items. */
10886 if (f
->n_tool_bar_rows
> 0)
10888 int border
, rows
, height
, extra
;
10890 if (INTEGERP (Vtool_bar_border
))
10891 border
= XINT (Vtool_bar_border
);
10892 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10893 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10894 else if (EQ (Vtool_bar_border
, Qborder_width
))
10895 border
= f
->border_width
;
10901 rows
= f
->n_tool_bar_rows
;
10902 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10903 extra
= it
.last_visible_y
- border
- height
* rows
;
10905 while (it
.current_y
< it
.last_visible_y
)
10908 if (extra
> 0 && rows
-- > 0)
10910 h
= (extra
+ rows
- 1) / rows
;
10913 display_tool_bar_line (&it
, height
+ h
);
10918 while (it
.current_y
< it
.last_visible_y
)
10919 display_tool_bar_line (&it
, 0);
10922 /* It doesn't make much sense to try scrolling in the tool-bar
10923 window, so don't do it. */
10924 w
->desired_matrix
->no_scrolling_p
= 1;
10925 w
->must_be_updated_p
= 1;
10927 if (!NILP (Vauto_resize_tool_bars
))
10929 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10930 int change_height_p
= 0;
10932 /* If we couldn't display everything, change the tool-bar's
10933 height if there is room for more. */
10934 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10935 && it
.current_y
< max_tool_bar_height
)
10936 change_height_p
= 1;
10938 row
= it
.glyph_row
- 1;
10940 /* If there are blank lines at the end, except for a partially
10941 visible blank line at the end that is smaller than
10942 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10943 if (!row
->displays_text_p
10944 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10945 change_height_p
= 1;
10947 /* If row displays tool-bar items, but is partially visible,
10948 change the tool-bar's height. */
10949 if (row
->displays_text_p
10950 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10951 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10952 change_height_p
= 1;
10954 /* Resize windows as needed by changing the `tool-bar-lines'
10955 frame parameter. */
10956 if (change_height_p
)
10959 int old_height
= WINDOW_TOTAL_LINES (w
);
10961 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10963 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10964 && !f
->minimize_tool_bar_window_p
)
10965 ? (nlines
> old_height
)
10966 : (nlines
!= old_height
));
10967 f
->minimize_tool_bar_window_p
= 0;
10969 if (change_height_p
)
10971 XSETFRAME (frame
, f
);
10972 Fmodify_frame_parameters (frame
,
10973 Fcons (Fcons (Qtool_bar_lines
,
10974 make_number (nlines
)),
10976 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10978 clear_glyph_matrix (w
->desired_matrix
);
10979 f
->n_tool_bar_rows
= nrows
;
10980 fonts_changed_p
= 1;
10987 f
->minimize_tool_bar_window_p
= 0;
10992 /* Get information about the tool-bar item which is displayed in GLYPH
10993 on frame F. Return in *PROP_IDX the index where tool-bar item
10994 properties start in F->tool_bar_items. Value is zero if
10995 GLYPH doesn't display a tool-bar item. */
10998 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11004 /* This function can be called asynchronously, which means we must
11005 exclude any possibility that Fget_text_property signals an
11007 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11008 charpos
= max (0, charpos
);
11010 /* Get the text property `menu-item' at pos. The value of that
11011 property is the start index of this item's properties in
11012 F->tool_bar_items. */
11013 prop
= Fget_text_property (make_number (charpos
),
11014 Qmenu_item
, f
->current_tool_bar_string
);
11015 if (INTEGERP (prop
))
11017 *prop_idx
= XINT (prop
);
11027 /* Get information about the tool-bar item at position X/Y on frame F.
11028 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11029 the current matrix of the tool-bar window of F, or NULL if not
11030 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11031 item in F->tool_bar_items. Value is
11033 -1 if X/Y is not on a tool-bar item
11034 0 if X/Y is on the same item that was highlighted before.
11038 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11039 int *hpos
, int *vpos
, int *prop_idx
)
11041 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11042 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11045 /* Find the glyph under X/Y. */
11046 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11047 if (*glyph
== NULL
)
11050 /* Get the start of this tool-bar item's properties in
11051 f->tool_bar_items. */
11052 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11055 /* Is mouse on the highlighted item? */
11056 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11057 && *vpos
>= hlinfo
->mouse_face_beg_row
11058 && *vpos
<= hlinfo
->mouse_face_end_row
11059 && (*vpos
> hlinfo
->mouse_face_beg_row
11060 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11061 && (*vpos
< hlinfo
->mouse_face_end_row
11062 || *hpos
< hlinfo
->mouse_face_end_col
11063 || hlinfo
->mouse_face_past_end
))
11071 Handle mouse button event on the tool-bar of frame F, at
11072 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11073 0 for button release. MODIFIERS is event modifiers for button
11077 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11078 unsigned int modifiers
)
11080 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11081 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11082 int hpos
, vpos
, prop_idx
;
11083 struct glyph
*glyph
;
11084 Lisp_Object enabled_p
;
11086 /* If not on the highlighted tool-bar item, return. */
11087 frame_to_window_pixel_xy (w
, &x
, &y
);
11088 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11091 /* If item is disabled, do nothing. */
11092 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11093 if (NILP (enabled_p
))
11098 /* Show item in pressed state. */
11099 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11100 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11101 last_tool_bar_item
= prop_idx
;
11105 Lisp_Object key
, frame
;
11106 struct input_event event
;
11107 EVENT_INIT (event
);
11109 /* Show item in released state. */
11110 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11111 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11113 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11115 XSETFRAME (frame
, f
);
11116 event
.kind
= TOOL_BAR_EVENT
;
11117 event
.frame_or_window
= frame
;
11119 kbd_buffer_store_event (&event
);
11121 event
.kind
= TOOL_BAR_EVENT
;
11122 event
.frame_or_window
= frame
;
11124 event
.modifiers
= modifiers
;
11125 kbd_buffer_store_event (&event
);
11126 last_tool_bar_item
= -1;
11131 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11132 tool-bar window-relative coordinates X/Y. Called from
11133 note_mouse_highlight. */
11136 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11138 Lisp_Object window
= f
->tool_bar_window
;
11139 struct window
*w
= XWINDOW (window
);
11140 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11141 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11143 struct glyph
*glyph
;
11144 struct glyph_row
*row
;
11146 Lisp_Object enabled_p
;
11148 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11149 int mouse_down_p
, rc
;
11151 /* Function note_mouse_highlight is called with negative X/Y
11152 values when mouse moves outside of the frame. */
11153 if (x
<= 0 || y
<= 0)
11155 clear_mouse_face (hlinfo
);
11159 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11162 /* Not on tool-bar item. */
11163 clear_mouse_face (hlinfo
);
11167 /* On same tool-bar item as before. */
11168 goto set_help_echo
;
11170 clear_mouse_face (hlinfo
);
11172 /* Mouse is down, but on different tool-bar item? */
11173 mouse_down_p
= (dpyinfo
->grabbed
11174 && f
== last_mouse_frame
11175 && FRAME_LIVE_P (f
));
11177 && last_tool_bar_item
!= prop_idx
)
11180 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11181 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11183 /* If tool-bar item is not enabled, don't highlight it. */
11184 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11185 if (!NILP (enabled_p
))
11187 /* Compute the x-position of the glyph. In front and past the
11188 image is a space. We include this in the highlighted area. */
11189 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11190 for (i
= x
= 0; i
< hpos
; ++i
)
11191 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11193 /* Record this as the current active region. */
11194 hlinfo
->mouse_face_beg_col
= hpos
;
11195 hlinfo
->mouse_face_beg_row
= vpos
;
11196 hlinfo
->mouse_face_beg_x
= x
;
11197 hlinfo
->mouse_face_beg_y
= row
->y
;
11198 hlinfo
->mouse_face_past_end
= 0;
11200 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11201 hlinfo
->mouse_face_end_row
= vpos
;
11202 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11203 hlinfo
->mouse_face_end_y
= row
->y
;
11204 hlinfo
->mouse_face_window
= window
;
11205 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11207 /* Display it as active. */
11208 show_mouse_face (hlinfo
, draw
);
11209 hlinfo
->mouse_face_image_state
= draw
;
11214 /* Set help_echo_string to a help string to display for this tool-bar item.
11215 XTread_socket does the rest. */
11216 help_echo_object
= help_echo_window
= Qnil
;
11217 help_echo_pos
= -1;
11218 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11219 if (NILP (help_echo_string
))
11220 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11223 #endif /* HAVE_WINDOW_SYSTEM */
11227 /************************************************************************
11228 Horizontal scrolling
11229 ************************************************************************/
11231 static int hscroll_window_tree (Lisp_Object
);
11232 static int hscroll_windows (Lisp_Object
);
11234 /* For all leaf windows in the window tree rooted at WINDOW, set their
11235 hscroll value so that PT is (i) visible in the window, and (ii) so
11236 that it is not within a certain margin at the window's left and
11237 right border. Value is non-zero if any window's hscroll has been
11241 hscroll_window_tree (Lisp_Object window
)
11243 int hscrolled_p
= 0;
11244 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11245 int hscroll_step_abs
= 0;
11246 double hscroll_step_rel
= 0;
11248 if (hscroll_relative_p
)
11250 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11251 if (hscroll_step_rel
< 0)
11253 hscroll_relative_p
= 0;
11254 hscroll_step_abs
= 0;
11257 else if (INTEGERP (Vhscroll_step
))
11259 hscroll_step_abs
= XINT (Vhscroll_step
);
11260 if (hscroll_step_abs
< 0)
11261 hscroll_step_abs
= 0;
11264 hscroll_step_abs
= 0;
11266 while (WINDOWP (window
))
11268 struct window
*w
= XWINDOW (window
);
11270 if (WINDOWP (w
->hchild
))
11271 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11272 else if (WINDOWP (w
->vchild
))
11273 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11274 else if (w
->cursor
.vpos
>= 0)
11277 int text_area_width
;
11278 struct glyph_row
*current_cursor_row
11279 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11280 struct glyph_row
*desired_cursor_row
11281 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11282 struct glyph_row
*cursor_row
11283 = (desired_cursor_row
->enabled_p
11284 ? desired_cursor_row
11285 : current_cursor_row
);
11287 text_area_width
= window_box_width (w
, TEXT_AREA
);
11289 /* Scroll when cursor is inside this scroll margin. */
11290 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11292 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11293 && ((XFASTINT (w
->hscroll
)
11294 && w
->cursor
.x
<= h_margin
)
11295 || (cursor_row
->enabled_p
11296 && cursor_row
->truncated_on_right_p
11297 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11301 struct buffer
*saved_current_buffer
;
11305 /* Find point in a display of infinite width. */
11306 saved_current_buffer
= current_buffer
;
11307 current_buffer
= XBUFFER (w
->buffer
);
11309 if (w
== XWINDOW (selected_window
))
11313 pt
= marker_position (w
->pointm
);
11314 pt
= max (BEGV
, pt
);
11318 /* Move iterator to pt starting at cursor_row->start in
11319 a line with infinite width. */
11320 init_to_row_start (&it
, w
, cursor_row
);
11321 it
.last_visible_x
= INFINITY
;
11322 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11323 current_buffer
= saved_current_buffer
;
11325 /* Position cursor in window. */
11326 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11327 hscroll
= max (0, (it
.current_x
11328 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11329 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11330 : (text_area_width
/ 2))))
11331 / FRAME_COLUMN_WIDTH (it
.f
);
11332 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11334 if (hscroll_relative_p
)
11335 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11338 wanted_x
= text_area_width
11339 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11342 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11346 if (hscroll_relative_p
)
11347 wanted_x
= text_area_width
* hscroll_step_rel
11350 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11353 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11355 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11357 /* Don't call Fset_window_hscroll if value hasn't
11358 changed because it will prevent redisplay
11360 if (XFASTINT (w
->hscroll
) != hscroll
)
11362 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11363 w
->hscroll
= make_number (hscroll
);
11372 /* Value is non-zero if hscroll of any leaf window has been changed. */
11373 return hscrolled_p
;
11377 /* Set hscroll so that cursor is visible and not inside horizontal
11378 scroll margins for all windows in the tree rooted at WINDOW. See
11379 also hscroll_window_tree above. Value is non-zero if any window's
11380 hscroll has been changed. If it has, desired matrices on the frame
11381 of WINDOW are cleared. */
11384 hscroll_windows (Lisp_Object window
)
11386 int hscrolled_p
= hscroll_window_tree (window
);
11388 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11389 return hscrolled_p
;
11394 /************************************************************************
11396 ************************************************************************/
11398 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11399 to a non-zero value. This is sometimes handy to have in a debugger
11404 /* First and last unchanged row for try_window_id. */
11406 int debug_first_unchanged_at_end_vpos
;
11407 int debug_last_unchanged_at_beg_vpos
;
11409 /* Delta vpos and y. */
11411 int debug_dvpos
, debug_dy
;
11413 /* Delta in characters and bytes for try_window_id. */
11415 EMACS_INT debug_delta
, debug_delta_bytes
;
11417 /* Values of window_end_pos and window_end_vpos at the end of
11420 EMACS_INT debug_end_vpos
;
11422 /* Append a string to W->desired_matrix->method. FMT is a printf
11423 format string. A1...A9 are a supplement for a variable-length
11424 argument list. If trace_redisplay_p is non-zero also printf the
11425 resulting string to stderr. */
11428 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11431 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11434 char *method
= w
->desired_matrix
->method
;
11435 int len
= strlen (method
);
11436 int size
= sizeof w
->desired_matrix
->method
;
11437 int remaining
= size
- len
- 1;
11439 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11440 if (len
&& remaining
)
11443 --remaining
, ++len
;
11446 strncpy (method
+ len
, buffer
, remaining
);
11448 if (trace_redisplay_p
)
11449 fprintf (stderr
, "%p (%s): %s\n",
11451 ((BUFFERP (w
->buffer
)
11452 && STRINGP (XBUFFER (w
->buffer
)->name
))
11453 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11458 #endif /* GLYPH_DEBUG */
11461 /* Value is non-zero if all changes in window W, which displays
11462 current_buffer, are in the text between START and END. START is a
11463 buffer position, END is given as a distance from Z. Used in
11464 redisplay_internal for display optimization. */
11467 text_outside_line_unchanged_p (struct window
*w
,
11468 EMACS_INT start
, EMACS_INT end
)
11470 int unchanged_p
= 1;
11472 /* If text or overlays have changed, see where. */
11473 if (XFASTINT (w
->last_modified
) < MODIFF
11474 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11476 /* Gap in the line? */
11477 if (GPT
< start
|| Z
- GPT
< end
)
11480 /* Changes start in front of the line, or end after it? */
11482 && (BEG_UNCHANGED
< start
- 1
11483 || END_UNCHANGED
< end
))
11486 /* If selective display, can't optimize if changes start at the
11487 beginning of the line. */
11489 && INTEGERP (BVAR (current_buffer
, selective_display
))
11490 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11491 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11494 /* If there are overlays at the start or end of the line, these
11495 may have overlay strings with newlines in them. A change at
11496 START, for instance, may actually concern the display of such
11497 overlay strings as well, and they are displayed on different
11498 lines. So, quickly rule out this case. (For the future, it
11499 might be desirable to implement something more telling than
11500 just BEG/END_UNCHANGED.) */
11503 if (BEG
+ BEG_UNCHANGED
== start
11504 && overlay_touches_p (start
))
11506 if (END_UNCHANGED
== end
11507 && overlay_touches_p (Z
- end
))
11511 /* Under bidi reordering, adding or deleting a character in the
11512 beginning of a paragraph, before the first strong directional
11513 character, can change the base direction of the paragraph (unless
11514 the buffer specifies a fixed paragraph direction), which will
11515 require to redisplay the whole paragraph. It might be worthwhile
11516 to find the paragraph limits and widen the range of redisplayed
11517 lines to that, but for now just give up this optimization. */
11518 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11519 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11523 return unchanged_p
;
11527 /* Do a frame update, taking possible shortcuts into account. This is
11528 the main external entry point for redisplay.
11530 If the last redisplay displayed an echo area message and that message
11531 is no longer requested, we clear the echo area or bring back the
11532 mini-buffer if that is in use. */
11537 redisplay_internal ();
11542 overlay_arrow_string_or_property (Lisp_Object var
)
11546 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11549 return Voverlay_arrow_string
;
11552 /* Return 1 if there are any overlay-arrows in current_buffer. */
11554 overlay_arrow_in_current_buffer_p (void)
11558 for (vlist
= Voverlay_arrow_variable_list
;
11560 vlist
= XCDR (vlist
))
11562 Lisp_Object var
= XCAR (vlist
);
11565 if (!SYMBOLP (var
))
11567 val
= find_symbol_value (var
);
11569 && current_buffer
== XMARKER (val
)->buffer
)
11576 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11580 overlay_arrows_changed_p (void)
11584 for (vlist
= Voverlay_arrow_variable_list
;
11586 vlist
= XCDR (vlist
))
11588 Lisp_Object var
= XCAR (vlist
);
11589 Lisp_Object val
, pstr
;
11591 if (!SYMBOLP (var
))
11593 val
= find_symbol_value (var
);
11594 if (!MARKERP (val
))
11596 if (! EQ (COERCE_MARKER (val
),
11597 Fget (var
, Qlast_arrow_position
))
11598 || ! (pstr
= overlay_arrow_string_or_property (var
),
11599 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11605 /* Mark overlay arrows to be updated on next redisplay. */
11608 update_overlay_arrows (int up_to_date
)
11612 for (vlist
= Voverlay_arrow_variable_list
;
11614 vlist
= XCDR (vlist
))
11616 Lisp_Object var
= XCAR (vlist
);
11618 if (!SYMBOLP (var
))
11621 if (up_to_date
> 0)
11623 Lisp_Object val
= find_symbol_value (var
);
11624 Fput (var
, Qlast_arrow_position
,
11625 COERCE_MARKER (val
));
11626 Fput (var
, Qlast_arrow_string
,
11627 overlay_arrow_string_or_property (var
));
11629 else if (up_to_date
< 0
11630 || !NILP (Fget (var
, Qlast_arrow_position
)))
11632 Fput (var
, Qlast_arrow_position
, Qt
);
11633 Fput (var
, Qlast_arrow_string
, Qt
);
11639 /* Return overlay arrow string to display at row.
11640 Return integer (bitmap number) for arrow bitmap in left fringe.
11641 Return nil if no overlay arrow. */
11644 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11648 for (vlist
= Voverlay_arrow_variable_list
;
11650 vlist
= XCDR (vlist
))
11652 Lisp_Object var
= XCAR (vlist
);
11655 if (!SYMBOLP (var
))
11658 val
= find_symbol_value (var
);
11661 && current_buffer
== XMARKER (val
)->buffer
11662 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11664 if (FRAME_WINDOW_P (it
->f
)
11665 /* FIXME: if ROW->reversed_p is set, this should test
11666 the right fringe, not the left one. */
11667 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11669 #ifdef HAVE_WINDOW_SYSTEM
11670 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11673 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11674 return make_number (fringe_bitmap
);
11677 return make_number (-1); /* Use default arrow bitmap */
11679 return overlay_arrow_string_or_property (var
);
11686 /* Return 1 if point moved out of or into a composition. Otherwise
11687 return 0. PREV_BUF and PREV_PT are the last point buffer and
11688 position. BUF and PT are the current point buffer and position. */
11691 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11692 struct buffer
*buf
, EMACS_INT pt
)
11694 EMACS_INT start
, end
;
11696 Lisp_Object buffer
;
11698 XSETBUFFER (buffer
, buf
);
11699 /* Check a composition at the last point if point moved within the
11701 if (prev_buf
== buf
)
11704 /* Point didn't move. */
11707 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11708 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11709 && COMPOSITION_VALID_P (start
, end
, prop
)
11710 && start
< prev_pt
&& end
> prev_pt
)
11711 /* The last point was within the composition. Return 1 iff
11712 point moved out of the composition. */
11713 return (pt
<= start
|| pt
>= end
);
11716 /* Check a composition at the current point. */
11717 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11718 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11719 && COMPOSITION_VALID_P (start
, end
, prop
)
11720 && start
< pt
&& end
> pt
);
11724 /* Reconsider the setting of B->clip_changed which is displayed
11728 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11730 if (b
->clip_changed
11731 && !NILP (w
->window_end_valid
)
11732 && w
->current_matrix
->buffer
== b
11733 && w
->current_matrix
->zv
== BUF_ZV (b
)
11734 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11735 b
->clip_changed
= 0;
11737 /* If display wasn't paused, and W is not a tool bar window, see if
11738 point has been moved into or out of a composition. In that case,
11739 we set b->clip_changed to 1 to force updating the screen. If
11740 b->clip_changed has already been set to 1, we can skip this
11742 if (!b
->clip_changed
11743 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11747 if (w
== XWINDOW (selected_window
))
11750 pt
= marker_position (w
->pointm
);
11752 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11753 || pt
!= XINT (w
->last_point
))
11754 && check_point_in_composition (w
->current_matrix
->buffer
,
11755 XINT (w
->last_point
),
11756 XBUFFER (w
->buffer
), pt
))
11757 b
->clip_changed
= 1;
11762 /* Select FRAME to forward the values of frame-local variables into C
11763 variables so that the redisplay routines can access those values
11767 select_frame_for_redisplay (Lisp_Object frame
)
11769 Lisp_Object tail
, tem
;
11770 Lisp_Object old
= selected_frame
;
11771 struct Lisp_Symbol
*sym
;
11773 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11775 selected_frame
= frame
;
11778 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11779 if (CONSP (XCAR (tail
))
11780 && (tem
= XCAR (XCAR (tail
)),
11782 && (sym
= indirect_variable (XSYMBOL (tem
)),
11783 sym
->redirect
== SYMBOL_LOCALIZED
)
11784 && sym
->val
.blv
->frame_local
)
11785 /* Use find_symbol_value rather than Fsymbol_value
11786 to avoid an error if it is void. */
11787 find_symbol_value (tem
);
11788 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11792 #define STOP_POLLING \
11793 do { if (! polling_stopped_here) stop_polling (); \
11794 polling_stopped_here = 1; } while (0)
11796 #define RESUME_POLLING \
11797 do { if (polling_stopped_here) start_polling (); \
11798 polling_stopped_here = 0; } while (0)
11801 /* Perhaps in the future avoid recentering windows if it
11802 is not necessary; currently that causes some problems. */
11805 redisplay_internal (void)
11807 struct window
*w
= XWINDOW (selected_window
);
11811 int must_finish
= 0;
11812 struct text_pos tlbufpos
, tlendpos
;
11813 int number_of_visible_frames
;
11816 int polling_stopped_here
= 0;
11817 Lisp_Object old_frame
= selected_frame
;
11819 /* Non-zero means redisplay has to consider all windows on all
11820 frames. Zero means, only selected_window is considered. */
11821 int consider_all_windows_p
;
11823 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11825 /* No redisplay if running in batch mode or frame is not yet fully
11826 initialized, or redisplay is explicitly turned off by setting
11827 Vinhibit_redisplay. */
11828 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11829 || !NILP (Vinhibit_redisplay
))
11832 /* Don't examine these until after testing Vinhibit_redisplay.
11833 When Emacs is shutting down, perhaps because its connection to
11834 X has dropped, we should not look at them at all. */
11835 fr
= XFRAME (w
->frame
);
11836 sf
= SELECTED_FRAME ();
11838 if (!fr
->glyphs_initialized_p
)
11841 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11842 if (popup_activated ())
11846 /* I don't think this happens but let's be paranoid. */
11847 if (redisplaying_p
)
11850 /* Record a function that resets redisplaying_p to its old value
11851 when we leave this function. */
11852 count
= SPECPDL_INDEX ();
11853 record_unwind_protect (unwind_redisplay
,
11854 Fcons (make_number (redisplaying_p
), selected_frame
));
11856 specbind (Qinhibit_free_realized_faces
, Qnil
);
11859 Lisp_Object tail
, frame
;
11861 FOR_EACH_FRAME (tail
, frame
)
11863 struct frame
*f
= XFRAME (frame
);
11864 f
->already_hscrolled_p
= 0;
11869 /* Remember the currently selected window. */
11872 if (!EQ (old_frame
, selected_frame
)
11873 && FRAME_LIVE_P (XFRAME (old_frame
)))
11874 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11875 selected_frame and selected_window to be temporarily out-of-sync so
11876 when we come back here via `goto retry', we need to resync because we
11877 may need to run Elisp code (via prepare_menu_bars). */
11878 select_frame_for_redisplay (old_frame
);
11881 reconsider_clip_changes (w
, current_buffer
);
11882 last_escape_glyph_frame
= NULL
;
11883 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11884 last_glyphless_glyph_frame
= NULL
;
11885 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11887 /* If new fonts have been loaded that make a glyph matrix adjustment
11888 necessary, do it. */
11889 if (fonts_changed_p
)
11891 adjust_glyphs (NULL
);
11892 ++windows_or_buffers_changed
;
11893 fonts_changed_p
= 0;
11896 /* If face_change_count is non-zero, init_iterator will free all
11897 realized faces, which includes the faces referenced from current
11898 matrices. So, we can't reuse current matrices in this case. */
11899 if (face_change_count
)
11900 ++windows_or_buffers_changed
;
11902 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11903 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11905 /* Since frames on a single ASCII terminal share the same
11906 display area, displaying a different frame means redisplay
11907 the whole thing. */
11908 windows_or_buffers_changed
++;
11909 SET_FRAME_GARBAGED (sf
);
11911 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11913 FRAME_TTY (sf
)->previous_frame
= sf
;
11916 /* Set the visible flags for all frames. Do this before checking
11917 for resized or garbaged frames; they want to know if their frames
11918 are visible. See the comment in frame.h for
11919 FRAME_SAMPLE_VISIBILITY. */
11921 Lisp_Object tail
, frame
;
11923 number_of_visible_frames
= 0;
11925 FOR_EACH_FRAME (tail
, frame
)
11927 struct frame
*f
= XFRAME (frame
);
11929 FRAME_SAMPLE_VISIBILITY (f
);
11930 if (FRAME_VISIBLE_P (f
))
11931 ++number_of_visible_frames
;
11932 clear_desired_matrices (f
);
11936 /* Notice any pending interrupt request to change frame size. */
11937 do_pending_window_change (1);
11939 /* do_pending_window_change could change the selected_window due to
11940 frame resizing which makes the selected window too small. */
11941 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
11944 reconsider_clip_changes (w
, current_buffer
);
11947 /* Clear frames marked as garbaged. */
11948 if (frame_garbaged
)
11949 clear_garbaged_frames ();
11951 /* Build menubar and tool-bar items. */
11952 if (NILP (Vmemory_full
))
11953 prepare_menu_bars ();
11955 if (windows_or_buffers_changed
)
11956 update_mode_lines
++;
11958 /* Detect case that we need to write or remove a star in the mode line. */
11959 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11961 w
->update_mode_line
= Qt
;
11962 if (buffer_shared
> 1)
11963 update_mode_lines
++;
11966 /* Avoid invocation of point motion hooks by `current_column' below. */
11967 count1
= SPECPDL_INDEX ();
11968 specbind (Qinhibit_point_motion_hooks
, Qt
);
11970 /* If %c is in the mode line, update it if needed. */
11971 if (!NILP (w
->column_number_displayed
)
11972 /* This alternative quickly identifies a common case
11973 where no change is needed. */
11974 && !(PT
== XFASTINT (w
->last_point
)
11975 && XFASTINT (w
->last_modified
) >= MODIFF
11976 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11977 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
11978 w
->update_mode_line
= Qt
;
11980 unbind_to (count1
, Qnil
);
11982 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11984 /* The variable buffer_shared is set in redisplay_window and
11985 indicates that we redisplay a buffer in different windows. See
11987 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11988 || cursor_type_changed
);
11990 /* If specs for an arrow have changed, do thorough redisplay
11991 to ensure we remove any arrow that should no longer exist. */
11992 if (overlay_arrows_changed_p ())
11993 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11995 /* Normally the message* functions will have already displayed and
11996 updated the echo area, but the frame may have been trashed, or
11997 the update may have been preempted, so display the echo area
11998 again here. Checking message_cleared_p captures the case that
11999 the echo area should be cleared. */
12000 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12001 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12002 || (message_cleared_p
12003 && minibuf_level
== 0
12004 /* If the mini-window is currently selected, this means the
12005 echo-area doesn't show through. */
12006 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12008 int window_height_changed_p
= echo_area_display (0);
12011 /* If we don't display the current message, don't clear the
12012 message_cleared_p flag, because, if we did, we wouldn't clear
12013 the echo area in the next redisplay which doesn't preserve
12015 if (!display_last_displayed_message_p
)
12016 message_cleared_p
= 0;
12018 if (fonts_changed_p
)
12020 else if (window_height_changed_p
)
12022 consider_all_windows_p
= 1;
12023 ++update_mode_lines
;
12024 ++windows_or_buffers_changed
;
12026 /* If window configuration was changed, frames may have been
12027 marked garbaged. Clear them or we will experience
12028 surprises wrt scrolling. */
12029 if (frame_garbaged
)
12030 clear_garbaged_frames ();
12033 else if (EQ (selected_window
, minibuf_window
)
12034 && (current_buffer
->clip_changed
12035 || XFASTINT (w
->last_modified
) < MODIFF
12036 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12037 && resize_mini_window (w
, 0))
12039 /* Resized active mini-window to fit the size of what it is
12040 showing if its contents might have changed. */
12042 /* FIXME: this causes all frames to be updated, which seems unnecessary
12043 since only the current frame needs to be considered. This function needs
12044 to be rewritten with two variables, consider_all_windows and
12045 consider_all_frames. */
12046 consider_all_windows_p
= 1;
12047 ++windows_or_buffers_changed
;
12048 ++update_mode_lines
;
12050 /* If window configuration was changed, frames may have been
12051 marked garbaged. Clear them or we will experience
12052 surprises wrt scrolling. */
12053 if (frame_garbaged
)
12054 clear_garbaged_frames ();
12058 /* If showing the region, and mark has changed, we must redisplay
12059 the whole window. The assignment to this_line_start_pos prevents
12060 the optimization directly below this if-statement. */
12061 if (((!NILP (Vtransient_mark_mode
)
12062 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12063 != !NILP (w
->region_showing
))
12064 || (!NILP (w
->region_showing
)
12065 && !EQ (w
->region_showing
,
12066 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12067 CHARPOS (this_line_start_pos
) = 0;
12069 /* Optimize the case that only the line containing the cursor in the
12070 selected window has changed. Variables starting with this_ are
12071 set in display_line and record information about the line
12072 containing the cursor. */
12073 tlbufpos
= this_line_start_pos
;
12074 tlendpos
= this_line_end_pos
;
12075 if (!consider_all_windows_p
12076 && CHARPOS (tlbufpos
) > 0
12077 && NILP (w
->update_mode_line
)
12078 && !current_buffer
->clip_changed
12079 && !current_buffer
->prevent_redisplay_optimizations_p
12080 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12081 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12082 /* Make sure recorded data applies to current buffer, etc. */
12083 && this_line_buffer
== current_buffer
12084 && current_buffer
== XBUFFER (w
->buffer
)
12085 && NILP (w
->force_start
)
12086 && NILP (w
->optional_new_start
)
12087 /* Point must be on the line that we have info recorded about. */
12088 && PT
>= CHARPOS (tlbufpos
)
12089 && PT
<= Z
- CHARPOS (tlendpos
)
12090 /* All text outside that line, including its final newline,
12091 must be unchanged. */
12092 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12093 CHARPOS (tlendpos
)))
12095 if (CHARPOS (tlbufpos
) > BEGV
12096 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12097 && (CHARPOS (tlbufpos
) == ZV
12098 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12099 /* Former continuation line has disappeared by becoming empty. */
12101 else if (XFASTINT (w
->last_modified
) < MODIFF
12102 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12103 || MINI_WINDOW_P (w
))
12105 /* We have to handle the case of continuation around a
12106 wide-column character (see the comment in indent.c around
12109 For instance, in the following case:
12111 -------- Insert --------
12112 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12113 J_I_ ==> J_I_ `^^' are cursors.
12117 As we have to redraw the line above, we cannot use this
12121 int line_height_before
= this_line_pixel_height
;
12123 /* Note that start_display will handle the case that the
12124 line starting at tlbufpos is a continuation line. */
12125 start_display (&it
, w
, tlbufpos
);
12127 /* Implementation note: It this still necessary? */
12128 if (it
.current_x
!= this_line_start_x
)
12131 TRACE ((stderr
, "trying display optimization 1\n"));
12132 w
->cursor
.vpos
= -1;
12133 overlay_arrow_seen
= 0;
12134 it
.vpos
= this_line_vpos
;
12135 it
.current_y
= this_line_y
;
12136 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12137 display_line (&it
);
12139 /* If line contains point, is not continued,
12140 and ends at same distance from eob as before, we win. */
12141 if (w
->cursor
.vpos
>= 0
12142 /* Line is not continued, otherwise this_line_start_pos
12143 would have been set to 0 in display_line. */
12144 && CHARPOS (this_line_start_pos
)
12145 /* Line ends as before. */
12146 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12147 /* Line has same height as before. Otherwise other lines
12148 would have to be shifted up or down. */
12149 && this_line_pixel_height
== line_height_before
)
12151 /* If this is not the window's last line, we must adjust
12152 the charstarts of the lines below. */
12153 if (it
.current_y
< it
.last_visible_y
)
12155 struct glyph_row
*row
12156 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12157 EMACS_INT delta
, delta_bytes
;
12159 /* We used to distinguish between two cases here,
12160 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12161 when the line ends in a newline or the end of the
12162 buffer's accessible portion. But both cases did
12163 the same, so they were collapsed. */
12165 - CHARPOS (tlendpos
)
12166 - MATRIX_ROW_START_CHARPOS (row
));
12167 delta_bytes
= (Z_BYTE
12168 - BYTEPOS (tlendpos
)
12169 - MATRIX_ROW_START_BYTEPOS (row
));
12171 increment_matrix_positions (w
->current_matrix
,
12172 this_line_vpos
+ 1,
12173 w
->current_matrix
->nrows
,
12174 delta
, delta_bytes
);
12177 /* If this row displays text now but previously didn't,
12178 or vice versa, w->window_end_vpos may have to be
12180 if ((it
.glyph_row
- 1)->displays_text_p
)
12182 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12183 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12185 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12186 && this_line_vpos
> 0)
12187 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12188 w
->window_end_valid
= Qnil
;
12190 /* Update hint: No need to try to scroll in update_window. */
12191 w
->desired_matrix
->no_scrolling_p
= 1;
12194 *w
->desired_matrix
->method
= 0;
12195 debug_method_add (w
, "optimization 1");
12197 #ifdef HAVE_WINDOW_SYSTEM
12198 update_window_fringes (w
, 0);
12205 else if (/* Cursor position hasn't changed. */
12206 PT
== XFASTINT (w
->last_point
)
12207 /* Make sure the cursor was last displayed
12208 in this window. Otherwise we have to reposition it. */
12209 && 0 <= w
->cursor
.vpos
12210 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12214 do_pending_window_change (1);
12215 /* If selected_window changed, redisplay again. */
12216 if (WINDOWP (selected_window
)
12217 && (w
= XWINDOW (selected_window
)) != sw
)
12220 /* We used to always goto end_of_redisplay here, but this
12221 isn't enough if we have a blinking cursor. */
12222 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12223 goto end_of_redisplay
;
12227 /* If highlighting the region, or if the cursor is in the echo area,
12228 then we can't just move the cursor. */
12229 else if (! (!NILP (Vtransient_mark_mode
)
12230 && !NILP (BVAR (current_buffer
, mark_active
)))
12231 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
12232 || highlight_nonselected_windows
)
12233 && NILP (w
->region_showing
)
12234 && NILP (Vshow_trailing_whitespace
)
12235 && !cursor_in_echo_area
)
12238 struct glyph_row
*row
;
12240 /* Skip from tlbufpos to PT and see where it is. Note that
12241 PT may be in invisible text. If so, we will end at the
12242 next visible position. */
12243 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12244 NULL
, DEFAULT_FACE_ID
);
12245 it
.current_x
= this_line_start_x
;
12246 it
.current_y
= this_line_y
;
12247 it
.vpos
= this_line_vpos
;
12249 /* The call to move_it_to stops in front of PT, but
12250 moves over before-strings. */
12251 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12253 if (it
.vpos
== this_line_vpos
12254 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12257 xassert (this_line_vpos
== it
.vpos
);
12258 xassert (this_line_y
== it
.current_y
);
12259 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12261 *w
->desired_matrix
->method
= 0;
12262 debug_method_add (w
, "optimization 3");
12271 /* Text changed drastically or point moved off of line. */
12272 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12275 CHARPOS (this_line_start_pos
) = 0;
12276 consider_all_windows_p
|= buffer_shared
> 1;
12277 ++clear_face_cache_count
;
12278 #ifdef HAVE_WINDOW_SYSTEM
12279 ++clear_image_cache_count
;
12282 /* Build desired matrices, and update the display. If
12283 consider_all_windows_p is non-zero, do it for all windows on all
12284 frames. Otherwise do it for selected_window, only. */
12286 if (consider_all_windows_p
)
12288 Lisp_Object tail
, frame
;
12290 FOR_EACH_FRAME (tail
, frame
)
12291 XFRAME (frame
)->updated_p
= 0;
12293 /* Recompute # windows showing selected buffer. This will be
12294 incremented each time such a window is displayed. */
12297 FOR_EACH_FRAME (tail
, frame
)
12299 struct frame
*f
= XFRAME (frame
);
12301 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12303 if (! EQ (frame
, selected_frame
))
12304 /* Select the frame, for the sake of frame-local
12306 select_frame_for_redisplay (frame
);
12308 /* Mark all the scroll bars to be removed; we'll redeem
12309 the ones we want when we redisplay their windows. */
12310 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12311 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12313 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12314 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12316 /* The X error handler may have deleted that frame. */
12317 if (!FRAME_LIVE_P (f
))
12320 /* Any scroll bars which redisplay_windows should have
12321 nuked should now go away. */
12322 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12323 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12325 /* If fonts changed, display again. */
12326 /* ??? rms: I suspect it is a mistake to jump all the way
12327 back to retry here. It should just retry this frame. */
12328 if (fonts_changed_p
)
12331 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12333 /* See if we have to hscroll. */
12334 if (!f
->already_hscrolled_p
)
12336 f
->already_hscrolled_p
= 1;
12337 if (hscroll_windows (f
->root_window
))
12341 /* Prevent various kinds of signals during display
12342 update. stdio is not robust about handling
12343 signals, which can cause an apparent I/O
12345 if (interrupt_input
)
12346 unrequest_sigio ();
12349 /* Update the display. */
12350 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12351 pending
|= update_frame (f
, 0, 0);
12357 if (!EQ (old_frame
, selected_frame
)
12358 && FRAME_LIVE_P (XFRAME (old_frame
)))
12359 /* We played a bit fast-and-loose above and allowed selected_frame
12360 and selected_window to be temporarily out-of-sync but let's make
12361 sure this stays contained. */
12362 select_frame_for_redisplay (old_frame
);
12363 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12367 /* Do the mark_window_display_accurate after all windows have
12368 been redisplayed because this call resets flags in buffers
12369 which are needed for proper redisplay. */
12370 FOR_EACH_FRAME (tail
, frame
)
12372 struct frame
*f
= XFRAME (frame
);
12375 mark_window_display_accurate (f
->root_window
, 1);
12376 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12377 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12382 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12384 Lisp_Object mini_window
;
12385 struct frame
*mini_frame
;
12387 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12388 /* Use list_of_error, not Qerror, so that
12389 we catch only errors and don't run the debugger. */
12390 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12392 redisplay_window_error
);
12394 /* Compare desired and current matrices, perform output. */
12397 /* If fonts changed, display again. */
12398 if (fonts_changed_p
)
12401 /* Prevent various kinds of signals during display update.
12402 stdio is not robust about handling signals,
12403 which can cause an apparent I/O error. */
12404 if (interrupt_input
)
12405 unrequest_sigio ();
12408 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12410 if (hscroll_windows (selected_window
))
12413 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12414 pending
= update_frame (sf
, 0, 0);
12417 /* We may have called echo_area_display at the top of this
12418 function. If the echo area is on another frame, that may
12419 have put text on a frame other than the selected one, so the
12420 above call to update_frame would not have caught it. Catch
12422 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12423 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12425 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12427 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12428 pending
|= update_frame (mini_frame
, 0, 0);
12429 if (!pending
&& hscroll_windows (mini_window
))
12434 /* If display was paused because of pending input, make sure we do a
12435 thorough update the next time. */
12438 /* Prevent the optimization at the beginning of
12439 redisplay_internal that tries a single-line update of the
12440 line containing the cursor in the selected window. */
12441 CHARPOS (this_line_start_pos
) = 0;
12443 /* Let the overlay arrow be updated the next time. */
12444 update_overlay_arrows (0);
12446 /* If we pause after scrolling, some rows in the current
12447 matrices of some windows are not valid. */
12448 if (!WINDOW_FULL_WIDTH_P (w
)
12449 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12450 update_mode_lines
= 1;
12454 if (!consider_all_windows_p
)
12456 /* This has already been done above if
12457 consider_all_windows_p is set. */
12458 mark_window_display_accurate_1 (w
, 1);
12460 /* Say overlay arrows are up to date. */
12461 update_overlay_arrows (1);
12463 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12464 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12467 update_mode_lines
= 0;
12468 windows_or_buffers_changed
= 0;
12469 cursor_type_changed
= 0;
12472 /* Start SIGIO interrupts coming again. Having them off during the
12473 code above makes it less likely one will discard output, but not
12474 impossible, since there might be stuff in the system buffer here.
12475 But it is much hairier to try to do anything about that. */
12476 if (interrupt_input
)
12480 /* If a frame has become visible which was not before, redisplay
12481 again, so that we display it. Expose events for such a frame
12482 (which it gets when becoming visible) don't call the parts of
12483 redisplay constructing glyphs, so simply exposing a frame won't
12484 display anything in this case. So, we have to display these
12485 frames here explicitly. */
12488 Lisp_Object tail
, frame
;
12491 FOR_EACH_FRAME (tail
, frame
)
12493 int this_is_visible
= 0;
12495 if (XFRAME (frame
)->visible
)
12496 this_is_visible
= 1;
12497 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12498 if (XFRAME (frame
)->visible
)
12499 this_is_visible
= 1;
12501 if (this_is_visible
)
12505 if (new_count
!= number_of_visible_frames
)
12506 windows_or_buffers_changed
++;
12509 /* Change frame size now if a change is pending. */
12510 do_pending_window_change (1);
12512 /* If we just did a pending size change, or have additional
12513 visible frames, or selected_window changed, redisplay again. */
12514 if ((windows_or_buffers_changed
&& !pending
)
12515 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12518 /* Clear the face and image caches.
12520 We used to do this only if consider_all_windows_p. But the cache
12521 needs to be cleared if a timer creates images in the current
12522 buffer (e.g. the test case in Bug#6230). */
12524 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12526 clear_face_cache (0);
12527 clear_face_cache_count
= 0;
12530 #ifdef HAVE_WINDOW_SYSTEM
12531 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12533 clear_image_caches (Qnil
);
12534 clear_image_cache_count
= 0;
12536 #endif /* HAVE_WINDOW_SYSTEM */
12539 unbind_to (count
, Qnil
);
12544 /* Redisplay, but leave alone any recent echo area message unless
12545 another message has been requested in its place.
12547 This is useful in situations where you need to redisplay but no
12548 user action has occurred, making it inappropriate for the message
12549 area to be cleared. See tracking_off and
12550 wait_reading_process_output for examples of these situations.
12552 FROM_WHERE is an integer saying from where this function was
12553 called. This is useful for debugging. */
12556 redisplay_preserve_echo_area (int from_where
)
12558 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12560 if (!NILP (echo_area_buffer
[1]))
12562 /* We have a previously displayed message, but no current
12563 message. Redisplay the previous message. */
12564 display_last_displayed_message_p
= 1;
12565 redisplay_internal ();
12566 display_last_displayed_message_p
= 0;
12569 redisplay_internal ();
12571 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12572 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12573 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12577 /* Function registered with record_unwind_protect in
12578 redisplay_internal. Reset redisplaying_p to the value it had
12579 before redisplay_internal was called, and clear
12580 prevent_freeing_realized_faces_p. It also selects the previously
12581 selected frame, unless it has been deleted (by an X connection
12582 failure during redisplay, for example). */
12585 unwind_redisplay (Lisp_Object val
)
12587 Lisp_Object old_redisplaying_p
, old_frame
;
12589 old_redisplaying_p
= XCAR (val
);
12590 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12591 old_frame
= XCDR (val
);
12592 if (! EQ (old_frame
, selected_frame
)
12593 && FRAME_LIVE_P (XFRAME (old_frame
)))
12594 select_frame_for_redisplay (old_frame
);
12599 /* Mark the display of window W as accurate or inaccurate. If
12600 ACCURATE_P is non-zero mark display of W as accurate. If
12601 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12602 redisplay_internal is called. */
12605 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12607 if (BUFFERP (w
->buffer
))
12609 struct buffer
*b
= XBUFFER (w
->buffer
);
12612 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12613 w
->last_overlay_modified
12614 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12616 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12620 b
->clip_changed
= 0;
12621 b
->prevent_redisplay_optimizations_p
= 0;
12623 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12624 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12625 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12626 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12628 w
->current_matrix
->buffer
= b
;
12629 w
->current_matrix
->begv
= BUF_BEGV (b
);
12630 w
->current_matrix
->zv
= BUF_ZV (b
);
12632 w
->last_cursor
= w
->cursor
;
12633 w
->last_cursor_off_p
= w
->cursor_off_p
;
12635 if (w
== XWINDOW (selected_window
))
12636 w
->last_point
= make_number (BUF_PT (b
));
12638 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12644 w
->window_end_valid
= w
->buffer
;
12645 w
->update_mode_line
= Qnil
;
12650 /* Mark the display of windows in the window tree rooted at WINDOW as
12651 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12652 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12653 be redisplayed the next time redisplay_internal is called. */
12656 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12660 for (; !NILP (window
); window
= w
->next
)
12662 w
= XWINDOW (window
);
12663 mark_window_display_accurate_1 (w
, accurate_p
);
12665 if (!NILP (w
->vchild
))
12666 mark_window_display_accurate (w
->vchild
, accurate_p
);
12667 if (!NILP (w
->hchild
))
12668 mark_window_display_accurate (w
->hchild
, accurate_p
);
12673 update_overlay_arrows (1);
12677 /* Force a thorough redisplay the next time by setting
12678 last_arrow_position and last_arrow_string to t, which is
12679 unequal to any useful value of Voverlay_arrow_... */
12680 update_overlay_arrows (-1);
12685 /* Return value in display table DP (Lisp_Char_Table *) for character
12686 C. Since a display table doesn't have any parent, we don't have to
12687 follow parent. Do not call this function directly but use the
12688 macro DISP_CHAR_VECTOR. */
12691 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12695 if (ASCII_CHAR_P (c
))
12698 if (SUB_CHAR_TABLE_P (val
))
12699 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12705 XSETCHAR_TABLE (table
, dp
);
12706 val
= char_table_ref (table
, c
);
12715 /***********************************************************************
12717 ***********************************************************************/
12719 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12722 redisplay_windows (Lisp_Object window
)
12724 while (!NILP (window
))
12726 struct window
*w
= XWINDOW (window
);
12728 if (!NILP (w
->hchild
))
12729 redisplay_windows (w
->hchild
);
12730 else if (!NILP (w
->vchild
))
12731 redisplay_windows (w
->vchild
);
12732 else if (!NILP (w
->buffer
))
12734 displayed_buffer
= XBUFFER (w
->buffer
);
12735 /* Use list_of_error, not Qerror, so that
12736 we catch only errors and don't run the debugger. */
12737 internal_condition_case_1 (redisplay_window_0
, window
,
12739 redisplay_window_error
);
12747 redisplay_window_error (Lisp_Object ignore
)
12749 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12754 redisplay_window_0 (Lisp_Object window
)
12756 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12757 redisplay_window (window
, 0);
12762 redisplay_window_1 (Lisp_Object window
)
12764 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12765 redisplay_window (window
, 1);
12770 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12771 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12772 which positions recorded in ROW differ from current buffer
12775 Return 0 if cursor is not on this row, 1 otherwise. */
12778 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12779 struct glyph_matrix
*matrix
,
12780 EMACS_INT delta
, EMACS_INT delta_bytes
,
12783 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12784 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12785 struct glyph
*cursor
= NULL
;
12786 /* The last known character position in row. */
12787 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12789 EMACS_INT pt_old
= PT
- delta
;
12790 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12791 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12792 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12793 /* A glyph beyond the edge of TEXT_AREA which we should never
12795 struct glyph
*glyphs_end
= end
;
12796 /* Non-zero means we've found a match for cursor position, but that
12797 glyph has the avoid_cursor_p flag set. */
12798 int match_with_avoid_cursor
= 0;
12799 /* Non-zero means we've seen at least one glyph that came from a
12801 int string_seen
= 0;
12802 /* Largest and smalles buffer positions seen so far during scan of
12804 EMACS_INT bpos_max
= pos_before
;
12805 EMACS_INT bpos_min
= pos_after
;
12806 /* Last buffer position covered by an overlay string with an integer
12807 `cursor' property. */
12808 EMACS_INT bpos_covered
= 0;
12810 /* Skip over glyphs not having an object at the start and the end of
12811 the row. These are special glyphs like truncation marks on
12812 terminal frames. */
12813 if (row
->displays_text_p
)
12815 if (!row
->reversed_p
)
12818 && INTEGERP (glyph
->object
)
12819 && glyph
->charpos
< 0)
12821 x
+= glyph
->pixel_width
;
12825 && INTEGERP ((end
- 1)->object
)
12826 /* CHARPOS is zero for blanks and stretch glyphs
12827 inserted by extend_face_to_end_of_line. */
12828 && (end
- 1)->charpos
<= 0)
12830 glyph_before
= glyph
- 1;
12837 /* If the glyph row is reversed, we need to process it from back
12838 to front, so swap the edge pointers. */
12839 glyphs_end
= end
= glyph
- 1;
12840 glyph
+= row
->used
[TEXT_AREA
] - 1;
12842 while (glyph
> end
+ 1
12843 && INTEGERP (glyph
->object
)
12844 && glyph
->charpos
< 0)
12847 x
-= glyph
->pixel_width
;
12849 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12851 /* By default, in reversed rows we put the cursor on the
12852 rightmost (first in the reading order) glyph. */
12853 for (g
= end
+ 1; g
< glyph
; g
++)
12854 x
+= g
->pixel_width
;
12856 && INTEGERP ((end
+ 1)->object
)
12857 && (end
+ 1)->charpos
<= 0)
12859 glyph_before
= glyph
+ 1;
12863 else if (row
->reversed_p
)
12865 /* In R2L rows that don't display text, put the cursor on the
12866 rightmost glyph. Case in point: an empty last line that is
12867 part of an R2L paragraph. */
12869 /* Avoid placing the cursor on the last glyph of the row, where
12870 on terminal frames we hold the vertical border between
12871 adjacent windows. */
12872 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12873 && !WINDOW_RIGHTMOST_P (w
)
12874 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12876 x
= -1; /* will be computed below, at label compute_x */
12879 /* Step 1: Try to find the glyph whose character position
12880 corresponds to point. If that's not possible, find 2 glyphs
12881 whose character positions are the closest to point, one before
12882 point, the other after it. */
12883 if (!row
->reversed_p
)
12884 while (/* not marched to end of glyph row */
12886 /* glyph was not inserted by redisplay for internal purposes */
12887 && !INTEGERP (glyph
->object
))
12889 if (BUFFERP (glyph
->object
))
12891 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12893 if (glyph
->charpos
> bpos_max
)
12894 bpos_max
= glyph
->charpos
;
12895 if (glyph
->charpos
< bpos_min
)
12896 bpos_min
= glyph
->charpos
;
12897 if (!glyph
->avoid_cursor_p
)
12899 /* If we hit point, we've found the glyph on which to
12900 display the cursor. */
12903 match_with_avoid_cursor
= 0;
12906 /* See if we've found a better approximation to
12907 POS_BEFORE or to POS_AFTER. Note that we want the
12908 first (leftmost) glyph of all those that are the
12909 closest from below, and the last (rightmost) of all
12910 those from above. */
12911 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12913 pos_before
= glyph
->charpos
;
12914 glyph_before
= glyph
;
12916 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12918 pos_after
= glyph
->charpos
;
12919 glyph_after
= glyph
;
12922 else if (dpos
== 0)
12923 match_with_avoid_cursor
= 1;
12925 else if (STRINGP (glyph
->object
))
12927 Lisp_Object chprop
;
12928 EMACS_INT glyph_pos
= glyph
->charpos
;
12930 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12932 if (INTEGERP (chprop
))
12934 bpos_covered
= bpos_max
+ XINT (chprop
);
12935 /* If the `cursor' property covers buffer positions up
12936 to and including point, we should display cursor on
12937 this glyph. Note that overlays and text properties
12938 with string values stop bidi reordering, so every
12939 buffer position to the left of the string is always
12940 smaller than any position to the right of the
12941 string. Therefore, if a `cursor' property on one
12942 of the string's characters has an integer value, we
12943 will break out of the loop below _before_ we get to
12944 the position match above. IOW, integer values of
12945 the `cursor' property override the "exact match for
12946 point" strategy of positioning the cursor. */
12947 /* Implementation note: bpos_max == pt_old when, e.g.,
12948 we are in an empty line, where bpos_max is set to
12949 MATRIX_ROW_START_CHARPOS, see above. */
12950 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12959 x
+= glyph
->pixel_width
;
12962 else if (glyph
> end
) /* row is reversed */
12963 while (!INTEGERP (glyph
->object
))
12965 if (BUFFERP (glyph
->object
))
12967 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12969 if (glyph
->charpos
> bpos_max
)
12970 bpos_max
= glyph
->charpos
;
12971 if (glyph
->charpos
< bpos_min
)
12972 bpos_min
= glyph
->charpos
;
12973 if (!glyph
->avoid_cursor_p
)
12977 match_with_avoid_cursor
= 0;
12980 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12982 pos_before
= glyph
->charpos
;
12983 glyph_before
= glyph
;
12985 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12987 pos_after
= glyph
->charpos
;
12988 glyph_after
= glyph
;
12991 else if (dpos
== 0)
12992 match_with_avoid_cursor
= 1;
12994 else if (STRINGP (glyph
->object
))
12996 Lisp_Object chprop
;
12997 EMACS_INT glyph_pos
= glyph
->charpos
;
12999 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13001 if (INTEGERP (chprop
))
13003 bpos_covered
= bpos_max
+ XINT (chprop
);
13004 /* If the `cursor' property covers buffer positions up
13005 to and including point, we should display cursor on
13007 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13016 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13018 x
--; /* can't use any pixel_width */
13021 x
-= glyph
->pixel_width
;
13024 /* Step 2: If we didn't find an exact match for point, we need to
13025 look for a proper place to put the cursor among glyphs between
13026 GLYPH_BEFORE and GLYPH_AFTER. */
13027 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13028 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13029 && bpos_covered
< pt_old
)
13031 /* An empty line has a single glyph whose OBJECT is zero and
13032 whose CHARPOS is the position of a newline on that line.
13033 Note that on a TTY, there are more glyphs after that, which
13034 were produced by extend_face_to_end_of_line, but their
13035 CHARPOS is zero or negative. */
13037 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13038 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13040 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13042 EMACS_INT ellipsis_pos
;
13044 /* Scan back over the ellipsis glyphs. */
13045 if (!row
->reversed_p
)
13047 ellipsis_pos
= (glyph
- 1)->charpos
;
13048 while (glyph
> row
->glyphs
[TEXT_AREA
]
13049 && (glyph
- 1)->charpos
== ellipsis_pos
)
13050 glyph
--, x
-= glyph
->pixel_width
;
13051 /* That loop always goes one position too far, including
13052 the glyph before the ellipsis. So scan forward over
13054 x
+= glyph
->pixel_width
;
13057 else /* row is reversed */
13059 ellipsis_pos
= (glyph
+ 1)->charpos
;
13060 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13061 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13062 glyph
++, x
+= glyph
->pixel_width
;
13063 x
-= glyph
->pixel_width
;
13067 else if (match_with_avoid_cursor
13068 /* A truncated row may not include PT among its
13069 character positions. Setting the cursor inside the
13070 scroll margin will trigger recalculation of hscroll
13071 in hscroll_window_tree. */
13072 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
13073 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
13074 /* Zero-width characters produce no glyphs. */
13077 && (row
->reversed_p
13078 ? glyph_after
> glyphs_end
13079 : glyph_after
< glyphs_end
)))
13081 cursor
= glyph_after
;
13084 else if (string_seen
)
13086 int incr
= row
->reversed_p
? -1 : +1;
13088 /* Need to find the glyph that came out of a string which is
13089 present at point. That glyph is somewhere between
13090 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13091 positioned between POS_BEFORE and POS_AFTER in the
13093 struct glyph
*start
, *stop
;
13094 EMACS_INT pos
= pos_before
;
13098 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13099 correspond to POS_BEFORE and POS_AFTER, respectively. We
13100 need START and STOP in the order that corresponds to the
13101 row's direction as given by its reversed_p flag. If the
13102 directionality of characters between POS_BEFORE and
13103 POS_AFTER is the opposite of the row's base direction,
13104 these characters will have been reordered for display,
13105 and we need to reverse START and STOP. */
13106 if (!row
->reversed_p
)
13108 start
= min (glyph_before
, glyph_after
);
13109 stop
= max (glyph_before
, glyph_after
);
13113 start
= max (glyph_before
, glyph_after
);
13114 stop
= min (glyph_before
, glyph_after
);
13116 for (glyph
= start
+ incr
;
13117 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13120 /* Any glyphs that come from the buffer are here because
13121 of bidi reordering. Skip them, and only pay
13122 attention to glyphs that came from some string. */
13123 if (STRINGP (glyph
->object
))
13128 str
= glyph
->object
;
13129 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
13130 if (tem
== 0 /* from overlay */
13133 /* If the string from which this glyph came is
13134 found in the buffer at point, then we've
13135 found the glyph we've been looking for. If
13136 it comes from an overlay (tem == 0), and it
13137 has the `cursor' property on one of its
13138 glyphs, record that glyph as a candidate for
13139 displaying the cursor. (As in the
13140 unidirectional version, we will display the
13141 cursor on the last candidate we find.) */
13142 if (tem
== 0 || tem
== pt_old
)
13144 /* The glyphs from this string could have
13145 been reordered. Find the one with the
13146 smallest string position. Or there could
13147 be a character in the string with the
13148 `cursor' property, which means display
13149 cursor on that character's glyph. */
13150 EMACS_INT strpos
= glyph
->charpos
;
13155 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13156 && EQ (glyph
->object
, str
);
13160 EMACS_INT gpos
= glyph
->charpos
;
13162 cprop
= Fget_char_property (make_number (gpos
),
13170 if (tem
&& glyph
->charpos
< strpos
)
13172 strpos
= glyph
->charpos
;
13181 pos
= tem
+ 1; /* don't find previous instances */
13183 /* This string is not what we want; skip all of the
13184 glyphs that came from it. */
13185 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13186 && EQ (glyph
->object
, str
))
13193 /* If we reached the end of the line, and END was from a string,
13194 the cursor is not on this line. */
13196 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
13197 && STRINGP (end
->object
)
13198 && row
->continued_p
)
13204 if (cursor
!= NULL
)
13210 /* Need to compute x that corresponds to GLYPH. */
13211 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13213 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13215 x
+= g
->pixel_width
;
13219 /* ROW could be part of a continued line, which, under bidi
13220 reordering, might have other rows whose start and end charpos
13221 occlude point. Only set w->cursor if we found a better
13222 approximation to the cursor position than we have from previously
13223 examined candidate rows belonging to the same continued line. */
13224 if (/* we already have a candidate row */
13225 w
->cursor
.vpos
>= 0
13226 /* that candidate is not the row we are processing */
13227 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13228 /* the row we are processing is part of a continued line */
13229 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13230 /* Make sure cursor.vpos specifies a row whose start and end
13231 charpos occlude point. This is because some callers of this
13232 function leave cursor.vpos at the row where the cursor was
13233 displayed during the last redisplay cycle. */
13234 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13235 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13238 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13240 /* Don't consider glyphs that are outside TEXT_AREA. */
13241 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13243 /* Keep the candidate whose buffer position is the closest to
13245 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13246 w
->cursor
.hpos
>= 0
13247 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13248 && BUFFERP (g1
->object
)
13249 && (g1
->charpos
== pt_old
/* an exact match always wins */
13250 || (BUFFERP (glyph
->object
)
13251 && eabs (g1
->charpos
- pt_old
)
13252 < eabs (glyph
->charpos
- pt_old
))))
13254 /* If this candidate gives an exact match, use that. */
13255 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13256 /* Otherwise, keep the candidate that comes from a row
13257 spanning less buffer positions. This may win when one or
13258 both candidate positions are on glyphs that came from
13259 display strings, for which we cannot compare buffer
13261 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13262 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13263 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13266 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13268 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13269 w
->cursor
.y
= row
->y
+ dy
;
13271 if (w
== XWINDOW (selected_window
))
13273 if (!row
->continued_p
13274 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13277 this_line_buffer
= XBUFFER (w
->buffer
);
13279 CHARPOS (this_line_start_pos
)
13280 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13281 BYTEPOS (this_line_start_pos
)
13282 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13284 CHARPOS (this_line_end_pos
)
13285 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13286 BYTEPOS (this_line_end_pos
)
13287 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13289 this_line_y
= w
->cursor
.y
;
13290 this_line_pixel_height
= row
->height
;
13291 this_line_vpos
= w
->cursor
.vpos
;
13292 this_line_start_x
= row
->x
;
13295 CHARPOS (this_line_start_pos
) = 0;
13302 /* Run window scroll functions, if any, for WINDOW with new window
13303 start STARTP. Sets the window start of WINDOW to that position.
13305 We assume that the window's buffer is really current. */
13307 static INLINE
struct text_pos
13308 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13310 struct window
*w
= XWINDOW (window
);
13311 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13313 if (current_buffer
!= XBUFFER (w
->buffer
))
13316 if (!NILP (Vwindow_scroll_functions
))
13318 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13319 make_number (CHARPOS (startp
)));
13320 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13321 /* In case the hook functions switch buffers. */
13322 if (current_buffer
!= XBUFFER (w
->buffer
))
13323 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13330 /* Make sure the line containing the cursor is fully visible.
13331 A value of 1 means there is nothing to be done.
13332 (Either the line is fully visible, or it cannot be made so,
13333 or we cannot tell.)
13335 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13336 is higher than window.
13338 A value of 0 means the caller should do scrolling
13339 as if point had gone off the screen. */
13342 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13344 struct glyph_matrix
*matrix
;
13345 struct glyph_row
*row
;
13348 if (!make_cursor_line_fully_visible_p
)
13351 /* It's not always possible to find the cursor, e.g, when a window
13352 is full of overlay strings. Don't do anything in that case. */
13353 if (w
->cursor
.vpos
< 0)
13356 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13357 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13359 /* If the cursor row is not partially visible, there's nothing to do. */
13360 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13363 /* If the row the cursor is in is taller than the window's height,
13364 it's not clear what to do, so do nothing. */
13365 window_height
= window_box_height (w
);
13366 if (row
->height
>= window_height
)
13368 if (!force_p
|| MINI_WINDOW_P (w
)
13369 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13376 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13377 non-zero means only WINDOW is redisplayed in redisplay_internal.
13378 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13379 in redisplay_window to bring a partially visible line into view in
13380 the case that only the cursor has moved.
13382 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13383 last screen line's vertical height extends past the end of the screen.
13387 1 if scrolling succeeded
13389 0 if scrolling didn't find point.
13391 -1 if new fonts have been loaded so that we must interrupt
13392 redisplay, adjust glyph matrices, and try again. */
13398 SCROLLING_NEED_LARGER_MATRICES
13401 /* If scroll-conservatively is more than this, never recenter.
13403 If you change this, don't forget to update the doc string of
13404 `scroll-conservatively' and the Emacs manual. */
13405 #define SCROLL_LIMIT 100
13408 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13409 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13410 int temp_scroll_step
, int last_line_misfit
)
13412 struct window
*w
= XWINDOW (window
);
13413 struct frame
*f
= XFRAME (w
->frame
);
13414 struct text_pos pos
, startp
;
13416 int this_scroll_margin
, scroll_max
, rc
, height
;
13417 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13418 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13419 Lisp_Object aggressive
;
13420 /* We will never try scrolling more than this number of lines. */
13421 int scroll_limit
= SCROLL_LIMIT
;
13424 debug_method_add (w
, "try_scrolling");
13427 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13429 /* Compute scroll margin height in pixels. We scroll when point is
13430 within this distance from the top or bottom of the window. */
13431 if (scroll_margin
> 0)
13432 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13433 * FRAME_LINE_HEIGHT (f
);
13435 this_scroll_margin
= 0;
13437 /* Force arg_scroll_conservatively to have a reasonable value, to
13438 avoid scrolling too far away with slow move_it_* functions. Note
13439 that the user can supply scroll-conservatively equal to
13440 `most-positive-fixnum', which can be larger than INT_MAX. */
13441 if (arg_scroll_conservatively
> scroll_limit
)
13443 arg_scroll_conservatively
= scroll_limit
+ 1;
13444 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13446 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13447 /* Compute how much we should try to scroll maximally to bring
13448 point into view. */
13449 scroll_max
= (max (scroll_step
,
13450 max (arg_scroll_conservatively
, temp_scroll_step
))
13451 * FRAME_LINE_HEIGHT (f
));
13452 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13453 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13454 /* We're trying to scroll because of aggressive scrolling but no
13455 scroll_step is set. Choose an arbitrary one. */
13456 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13462 /* Decide whether to scroll down. */
13463 if (PT
> CHARPOS (startp
))
13465 int scroll_margin_y
;
13467 /* Compute the pixel ypos of the scroll margin, then move it to
13468 either that ypos or PT, whichever comes first. */
13469 start_display (&it
, w
, startp
);
13470 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13471 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13472 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13473 (MOVE_TO_POS
| MOVE_TO_Y
));
13475 if (PT
> CHARPOS (it
.current
.pos
))
13477 int y0
= line_bottom_y (&it
);
13478 /* Compute how many pixels below window bottom to stop searching
13479 for PT. This avoids costly search for PT that is far away if
13480 the user limited scrolling by a small number of lines, but
13481 always finds PT if scroll_conservatively is set to a large
13482 number, such as most-positive-fixnum. */
13483 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13484 int y_to_move
= it
.last_visible_y
+ slack
;
13486 /* Compute the distance from the scroll margin to PT or to
13487 the scroll limit, whichever comes first. This should
13488 include the height of the cursor line, to make that line
13490 move_it_to (&it
, PT
, -1, y_to_move
,
13491 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13492 dy
= line_bottom_y (&it
) - y0
;
13494 if (dy
> scroll_max
)
13495 return SCROLLING_FAILED
;
13503 /* Point is in or below the bottom scroll margin, so move the
13504 window start down. If scrolling conservatively, move it just
13505 enough down to make point visible. If scroll_step is set,
13506 move it down by scroll_step. */
13507 if (arg_scroll_conservatively
)
13509 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13510 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13511 else if (scroll_step
|| temp_scroll_step
)
13512 amount_to_scroll
= scroll_max
;
13515 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13516 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13517 if (NUMBERP (aggressive
))
13519 double float_amount
= XFLOATINT (aggressive
) * height
;
13520 amount_to_scroll
= float_amount
;
13521 if (amount_to_scroll
== 0 && float_amount
> 0)
13522 amount_to_scroll
= 1;
13523 /* Don't let point enter the scroll margin near top of
13525 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13526 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13530 if (amount_to_scroll
<= 0)
13531 return SCROLLING_FAILED
;
13533 start_display (&it
, w
, startp
);
13534 if (arg_scroll_conservatively
<= scroll_limit
)
13535 move_it_vertically (&it
, amount_to_scroll
);
13538 /* Extra precision for users who set scroll-conservatively
13539 to a large number: make sure the amount we scroll
13540 the window start is never less than amount_to_scroll,
13541 which was computed as distance from window bottom to
13542 point. This matters when lines at window top and lines
13543 below window bottom have different height. */
13544 struct it it1
= it
;
13545 /* We use a temporary it1 because line_bottom_y can modify
13546 its argument, if it moves one line down; see there. */
13547 int start_y
= line_bottom_y (&it1
);
13550 move_it_by_lines (&it
, 1);
13552 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13555 /* If STARTP is unchanged, move it down another screen line. */
13556 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13557 move_it_by_lines (&it
, 1);
13558 startp
= it
.current
.pos
;
13562 struct text_pos scroll_margin_pos
= startp
;
13564 /* See if point is inside the scroll margin at the top of the
13566 if (this_scroll_margin
)
13568 start_display (&it
, w
, startp
);
13569 move_it_vertically (&it
, this_scroll_margin
);
13570 scroll_margin_pos
= it
.current
.pos
;
13573 if (PT
< CHARPOS (scroll_margin_pos
))
13575 /* Point is in the scroll margin at the top of the window or
13576 above what is displayed in the window. */
13579 /* Compute the vertical distance from PT to the scroll
13580 margin position. Move as far as scroll_max allows, or
13581 one screenful, or 10 screen lines, whichever is largest.
13582 Give up if distance is greater than scroll_max. */
13583 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13584 start_display (&it
, w
, pos
);
13586 y_to_move
= max (it
.last_visible_y
,
13587 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13588 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13590 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13591 dy
= it
.current_y
- y0
;
13592 if (dy
> scroll_max
)
13593 return SCROLLING_FAILED
;
13595 /* Compute new window start. */
13596 start_display (&it
, w
, startp
);
13598 if (arg_scroll_conservatively
)
13599 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13600 max (scroll_step
, temp_scroll_step
));
13601 else if (scroll_step
|| temp_scroll_step
)
13602 amount_to_scroll
= scroll_max
;
13605 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13606 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13607 if (NUMBERP (aggressive
))
13609 double float_amount
= XFLOATINT (aggressive
) * height
;
13610 amount_to_scroll
= float_amount
;
13611 if (amount_to_scroll
== 0 && float_amount
> 0)
13612 amount_to_scroll
= 1;
13613 amount_to_scroll
-=
13614 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13615 /* Don't let point enter the scroll margin near
13616 bottom of the window. */
13617 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13618 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13622 if (amount_to_scroll
<= 0)
13623 return SCROLLING_FAILED
;
13625 move_it_vertically_backward (&it
, amount_to_scroll
);
13626 startp
= it
.current
.pos
;
13630 /* Run window scroll functions. */
13631 startp
= run_window_scroll_functions (window
, startp
);
13633 /* Display the window. Give up if new fonts are loaded, or if point
13635 if (!try_window (window
, startp
, 0))
13636 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13637 else if (w
->cursor
.vpos
< 0)
13639 clear_glyph_matrix (w
->desired_matrix
);
13640 rc
= SCROLLING_FAILED
;
13644 /* Maybe forget recorded base line for line number display. */
13645 if (!just_this_one_p
13646 || current_buffer
->clip_changed
13647 || BEG_UNCHANGED
< CHARPOS (startp
))
13648 w
->base_line_number
= Qnil
;
13650 /* If cursor ends up on a partially visible line,
13651 treat that as being off the bottom of the screen. */
13652 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13653 /* It's possible that the cursor is on the first line of the
13654 buffer, which is partially obscured due to a vscroll
13655 (Bug#7537). In that case, avoid looping forever . */
13656 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13658 clear_glyph_matrix (w
->desired_matrix
);
13659 ++extra_scroll_margin_lines
;
13662 rc
= SCROLLING_SUCCESS
;
13669 /* Compute a suitable window start for window W if display of W starts
13670 on a continuation line. Value is non-zero if a new window start
13673 The new window start will be computed, based on W's width, starting
13674 from the start of the continued line. It is the start of the
13675 screen line with the minimum distance from the old start W->start. */
13678 compute_window_start_on_continuation_line (struct window
*w
)
13680 struct text_pos pos
, start_pos
;
13681 int window_start_changed_p
= 0;
13683 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13685 /* If window start is on a continuation line... Window start may be
13686 < BEGV in case there's invisible text at the start of the
13687 buffer (M-x rmail, for example). */
13688 if (CHARPOS (start_pos
) > BEGV
13689 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13692 struct glyph_row
*row
;
13694 /* Handle the case that the window start is out of range. */
13695 if (CHARPOS (start_pos
) < BEGV
)
13696 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13697 else if (CHARPOS (start_pos
) > ZV
)
13698 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13700 /* Find the start of the continued line. This should be fast
13701 because scan_buffer is fast (newline cache). */
13702 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13703 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13704 row
, DEFAULT_FACE_ID
);
13705 reseat_at_previous_visible_line_start (&it
);
13707 /* If the line start is "too far" away from the window start,
13708 say it takes too much time to compute a new window start. */
13709 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13710 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13712 int min_distance
, distance
;
13714 /* Move forward by display lines to find the new window
13715 start. If window width was enlarged, the new start can
13716 be expected to be > the old start. If window width was
13717 decreased, the new window start will be < the old start.
13718 So, we're looking for the display line start with the
13719 minimum distance from the old window start. */
13720 pos
= it
.current
.pos
;
13721 min_distance
= INFINITY
;
13722 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13723 distance
< min_distance
)
13725 min_distance
= distance
;
13726 pos
= it
.current
.pos
;
13727 move_it_by_lines (&it
, 1);
13730 /* Set the window start there. */
13731 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13732 window_start_changed_p
= 1;
13736 return window_start_changed_p
;
13740 /* Try cursor movement in case text has not changed in window WINDOW,
13741 with window start STARTP. Value is
13743 CURSOR_MOVEMENT_SUCCESS if successful
13745 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13747 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13748 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13749 we want to scroll as if scroll-step were set to 1. See the code.
13751 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13752 which case we have to abort this redisplay, and adjust matrices
13757 CURSOR_MOVEMENT_SUCCESS
,
13758 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13759 CURSOR_MOVEMENT_MUST_SCROLL
,
13760 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13764 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13766 struct window
*w
= XWINDOW (window
);
13767 struct frame
*f
= XFRAME (w
->frame
);
13768 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13771 if (inhibit_try_cursor_movement
)
13775 /* Handle case where text has not changed, only point, and it has
13776 not moved off the frame. */
13777 if (/* Point may be in this window. */
13778 PT
>= CHARPOS (startp
)
13779 /* Selective display hasn't changed. */
13780 && !current_buffer
->clip_changed
13781 /* Function force-mode-line-update is used to force a thorough
13782 redisplay. It sets either windows_or_buffers_changed or
13783 update_mode_lines. So don't take a shortcut here for these
13785 && !update_mode_lines
13786 && !windows_or_buffers_changed
13787 && !cursor_type_changed
13788 /* Can't use this case if highlighting a region. When a
13789 region exists, cursor movement has to do more than just
13791 && !(!NILP (Vtransient_mark_mode
)
13792 && !NILP (BVAR (current_buffer
, mark_active
)))
13793 && NILP (w
->region_showing
)
13794 && NILP (Vshow_trailing_whitespace
)
13795 /* Right after splitting windows, last_point may be nil. */
13796 && INTEGERP (w
->last_point
)
13797 /* This code is not used for mini-buffer for the sake of the case
13798 of redisplaying to replace an echo area message; since in
13799 that case the mini-buffer contents per se are usually
13800 unchanged. This code is of no real use in the mini-buffer
13801 since the handling of this_line_start_pos, etc., in redisplay
13802 handles the same cases. */
13803 && !EQ (window
, minibuf_window
)
13804 /* When splitting windows or for new windows, it happens that
13805 redisplay is called with a nil window_end_vpos or one being
13806 larger than the window. This should really be fixed in
13807 window.c. I don't have this on my list, now, so we do
13808 approximately the same as the old redisplay code. --gerd. */
13809 && INTEGERP (w
->window_end_vpos
)
13810 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13811 && (FRAME_WINDOW_P (f
)
13812 || !overlay_arrow_in_current_buffer_p ()))
13814 int this_scroll_margin
, top_scroll_margin
;
13815 struct glyph_row
*row
= NULL
;
13818 debug_method_add (w
, "cursor movement");
13821 /* Scroll if point within this distance from the top or bottom
13822 of the window. This is a pixel value. */
13823 if (scroll_margin
> 0)
13825 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13826 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13829 this_scroll_margin
= 0;
13831 top_scroll_margin
= this_scroll_margin
;
13832 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13833 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13835 /* Start with the row the cursor was displayed during the last
13836 not paused redisplay. Give up if that row is not valid. */
13837 if (w
->last_cursor
.vpos
< 0
13838 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13839 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13842 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13843 if (row
->mode_line_p
)
13845 if (!row
->enabled_p
)
13846 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13849 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13851 int scroll_p
= 0, must_scroll
= 0;
13852 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13854 if (PT
> XFASTINT (w
->last_point
))
13856 /* Point has moved forward. */
13857 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13858 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13860 xassert (row
->enabled_p
);
13864 /* If the end position of a row equals the start
13865 position of the next row, and PT is at that position,
13866 we would rather display cursor in the next line. */
13867 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13868 && MATRIX_ROW_END_CHARPOS (row
) == PT
13869 && row
< w
->current_matrix
->rows
13870 + w
->current_matrix
->nrows
- 1
13871 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13872 && !cursor_row_p (row
))
13875 /* If within the scroll margin, scroll. Note that
13876 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13877 the next line would be drawn, and that
13878 this_scroll_margin can be zero. */
13879 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13880 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13881 /* Line is completely visible last line in window
13882 and PT is to be set in the next line. */
13883 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13884 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13885 && !row
->ends_at_zv_p
13886 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13889 else if (PT
< XFASTINT (w
->last_point
))
13891 /* Cursor has to be moved backward. Note that PT >=
13892 CHARPOS (startp) because of the outer if-statement. */
13893 while (!row
->mode_line_p
13894 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13895 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13896 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13897 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13898 row
> w
->current_matrix
->rows
13899 && (row
-1)->ends_in_newline_from_string_p
))))
13900 && (row
->y
> top_scroll_margin
13901 || CHARPOS (startp
) == BEGV
))
13903 xassert (row
->enabled_p
);
13907 /* Consider the following case: Window starts at BEGV,
13908 there is invisible, intangible text at BEGV, so that
13909 display starts at some point START > BEGV. It can
13910 happen that we are called with PT somewhere between
13911 BEGV and START. Try to handle that case. */
13912 if (row
< w
->current_matrix
->rows
13913 || row
->mode_line_p
)
13915 row
= w
->current_matrix
->rows
;
13916 if (row
->mode_line_p
)
13920 /* Due to newlines in overlay strings, we may have to
13921 skip forward over overlay strings. */
13922 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13923 && MATRIX_ROW_END_CHARPOS (row
) == PT
13924 && !cursor_row_p (row
))
13927 /* If within the scroll margin, scroll. */
13928 if (row
->y
< top_scroll_margin
13929 && CHARPOS (startp
) != BEGV
)
13934 /* Cursor did not move. So don't scroll even if cursor line
13935 is partially visible, as it was so before. */
13936 rc
= CURSOR_MOVEMENT_SUCCESS
;
13939 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13940 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13942 /* if PT is not in the glyph row, give up. */
13943 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13946 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13947 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13949 /* If rows are bidi-reordered and point moved, back up
13950 until we find a row that does not belong to a
13951 continuation line. This is because we must consider
13952 all rows of a continued line as candidates for the
13953 new cursor positioning, since row start and end
13954 positions change non-linearly with vertical position
13956 /* FIXME: Revisit this when glyph ``spilling'' in
13957 continuation lines' rows is implemented for
13958 bidi-reordered rows. */
13959 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13961 xassert (row
->enabled_p
);
13963 /* If we hit the beginning of the displayed portion
13964 without finding the first row of a continued
13966 if (row
<= w
->current_matrix
->rows
)
13968 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13976 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13977 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13978 && make_cursor_line_fully_visible_p
)
13980 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13981 && !row
->ends_at_zv_p
13982 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13983 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13984 else if (row
->height
> window_box_height (w
))
13986 /* If we end up in a partially visible line, let's
13987 make it fully visible, except when it's taller
13988 than the window, in which case we can't do much
13991 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13995 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13996 if (!cursor_row_fully_visible_p (w
, 0, 1))
13997 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13999 rc
= CURSOR_MOVEMENT_SUCCESS
;
14003 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14004 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14005 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14007 /* With bidi-reordered rows, there could be more than
14008 one candidate row whose start and end positions
14009 occlude point. We need to let set_cursor_from_row
14010 find the best candidate. */
14011 /* FIXME: Revisit this when glyph ``spilling'' in
14012 continuation lines' rows is implemented for
14013 bidi-reordered rows. */
14018 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14019 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14020 && cursor_row_p (row
))
14021 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14023 /* As soon as we've found the first suitable row
14024 whose ends_at_zv_p flag is set, we are done. */
14026 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
14028 rc
= CURSOR_MOVEMENT_SUCCESS
;
14033 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14034 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14035 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14036 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14037 /* If we didn't find any candidate rows, or exited the
14038 loop before all the candidates were examined, signal
14039 to the caller that this method failed. */
14040 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14041 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
14042 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14044 rc
= CURSOR_MOVEMENT_SUCCESS
;
14050 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14052 rc
= CURSOR_MOVEMENT_SUCCESS
;
14057 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14058 && MATRIX_ROW_START_CHARPOS (row
) == PT
14059 && cursor_row_p (row
));
14067 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
14071 set_vertical_scroll_bar (struct window
*w
)
14073 EMACS_INT start
, end
, whole
;
14075 /* Calculate the start and end positions for the current window.
14076 At some point, it would be nice to choose between scrollbars
14077 which reflect the whole buffer size, with special markers
14078 indicating narrowing, and scrollbars which reflect only the
14081 Note that mini-buffers sometimes aren't displaying any text. */
14082 if (!MINI_WINDOW_P (w
)
14083 || (w
== XWINDOW (minibuf_window
)
14084 && NILP (echo_area_buffer
[0])))
14086 struct buffer
*buf
= XBUFFER (w
->buffer
);
14087 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
14088 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
14089 /* I don't think this is guaranteed to be right. For the
14090 moment, we'll pretend it is. */
14091 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
14095 if (whole
< (end
- start
))
14096 whole
= end
- start
;
14099 start
= end
= whole
= 0;
14101 /* Indicate what this scroll bar ought to be displaying now. */
14102 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14103 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14104 (w
, end
- start
, whole
, start
);
14108 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
14109 selected_window is redisplayed.
14111 We can return without actually redisplaying the window if
14112 fonts_changed_p is nonzero. In that case, redisplay_internal will
14116 redisplay_window (Lisp_Object window
, int just_this_one_p
)
14118 struct window
*w
= XWINDOW (window
);
14119 struct frame
*f
= XFRAME (w
->frame
);
14120 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14121 struct buffer
*old
= current_buffer
;
14122 struct text_pos lpoint
, opoint
, startp
;
14123 int update_mode_line
;
14126 /* Record it now because it's overwritten. */
14127 int current_matrix_up_to_date_p
= 0;
14128 int used_current_matrix_p
= 0;
14129 /* This is less strict than current_matrix_up_to_date_p.
14130 It indictes that the buffer contents and narrowing are unchanged. */
14131 int buffer_unchanged_p
= 0;
14132 int temp_scroll_step
= 0;
14133 int count
= SPECPDL_INDEX ();
14135 int centering_position
= -1;
14136 int last_line_misfit
= 0;
14137 EMACS_INT beg_unchanged
, end_unchanged
;
14139 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14142 /* W must be a leaf window here. */
14143 xassert (!NILP (w
->buffer
));
14145 *w
->desired_matrix
->method
= 0;
14149 reconsider_clip_changes (w
, buffer
);
14151 /* Has the mode line to be updated? */
14152 update_mode_line
= (!NILP (w
->update_mode_line
)
14153 || update_mode_lines
14154 || buffer
->clip_changed
14155 || buffer
->prevent_redisplay_optimizations_p
);
14157 if (MINI_WINDOW_P (w
))
14159 if (w
== XWINDOW (echo_area_window
)
14160 && !NILP (echo_area_buffer
[0]))
14162 if (update_mode_line
)
14163 /* We may have to update a tty frame's menu bar or a
14164 tool-bar. Example `M-x C-h C-h C-g'. */
14165 goto finish_menu_bars
;
14167 /* We've already displayed the echo area glyphs in this window. */
14168 goto finish_scroll_bars
;
14170 else if ((w
!= XWINDOW (minibuf_window
)
14171 || minibuf_level
== 0)
14172 /* When buffer is nonempty, redisplay window normally. */
14173 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
14174 /* Quail displays non-mini buffers in minibuffer window.
14175 In that case, redisplay the window normally. */
14176 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
14178 /* W is a mini-buffer window, but it's not active, so clear
14180 int yb
= window_text_bottom_y (w
);
14181 struct glyph_row
*row
;
14184 for (y
= 0, row
= w
->desired_matrix
->rows
;
14186 y
+= row
->height
, ++row
)
14187 blank_row (w
, row
, y
);
14188 goto finish_scroll_bars
;
14191 clear_glyph_matrix (w
->desired_matrix
);
14194 /* Otherwise set up data on this window; select its buffer and point
14196 /* Really select the buffer, for the sake of buffer-local
14198 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14200 current_matrix_up_to_date_p
14201 = (!NILP (w
->window_end_valid
)
14202 && !current_buffer
->clip_changed
14203 && !current_buffer
->prevent_redisplay_optimizations_p
14204 && XFASTINT (w
->last_modified
) >= MODIFF
14205 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14207 /* Run the window-bottom-change-functions
14208 if it is possible that the text on the screen has changed
14209 (either due to modification of the text, or any other reason). */
14210 if (!current_matrix_up_to_date_p
14211 && !NILP (Vwindow_text_change_functions
))
14213 safe_run_hooks (Qwindow_text_change_functions
);
14217 beg_unchanged
= BEG_UNCHANGED
;
14218 end_unchanged
= END_UNCHANGED
;
14220 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
14222 specbind (Qinhibit_point_motion_hooks
, Qt
);
14225 = (!NILP (w
->window_end_valid
)
14226 && !current_buffer
->clip_changed
14227 && XFASTINT (w
->last_modified
) >= MODIFF
14228 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14230 /* When windows_or_buffers_changed is non-zero, we can't rely on
14231 the window end being valid, so set it to nil there. */
14232 if (windows_or_buffers_changed
)
14234 /* If window starts on a continuation line, maybe adjust the
14235 window start in case the window's width changed. */
14236 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14237 compute_window_start_on_continuation_line (w
);
14239 w
->window_end_valid
= Qnil
;
14242 /* Some sanity checks. */
14243 CHECK_WINDOW_END (w
);
14244 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14246 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14249 /* If %c is in mode line, update it if needed. */
14250 if (!NILP (w
->column_number_displayed
)
14251 /* This alternative quickly identifies a common case
14252 where no change is needed. */
14253 && !(PT
== XFASTINT (w
->last_point
)
14254 && XFASTINT (w
->last_modified
) >= MODIFF
14255 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14256 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14257 update_mode_line
= 1;
14259 /* Count number of windows showing the selected buffer. An indirect
14260 buffer counts as its base buffer. */
14261 if (!just_this_one_p
)
14263 struct buffer
*current_base
, *window_base
;
14264 current_base
= current_buffer
;
14265 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14266 if (current_base
->base_buffer
)
14267 current_base
= current_base
->base_buffer
;
14268 if (window_base
->base_buffer
)
14269 window_base
= window_base
->base_buffer
;
14270 if (current_base
== window_base
)
14274 /* Point refers normally to the selected window. For any other
14275 window, set up appropriate value. */
14276 if (!EQ (window
, selected_window
))
14278 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14279 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14283 new_pt_byte
= BEGV_BYTE
;
14284 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14286 else if (new_pt
> (ZV
- 1))
14289 new_pt_byte
= ZV_BYTE
;
14290 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14293 /* We don't use SET_PT so that the point-motion hooks don't run. */
14294 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14297 /* If any of the character widths specified in the display table
14298 have changed, invalidate the width run cache. It's true that
14299 this may be a bit late to catch such changes, but the rest of
14300 redisplay goes (non-fatally) haywire when the display table is
14301 changed, so why should we worry about doing any better? */
14302 if (current_buffer
->width_run_cache
)
14304 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14306 if (! disptab_matches_widthtab (disptab
,
14307 XVECTOR (BVAR (current_buffer
, width_table
))))
14309 invalidate_region_cache (current_buffer
,
14310 current_buffer
->width_run_cache
,
14312 recompute_width_table (current_buffer
, disptab
);
14316 /* If window-start is screwed up, choose a new one. */
14317 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14320 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14322 /* If someone specified a new starting point but did not insist,
14323 check whether it can be used. */
14324 if (!NILP (w
->optional_new_start
)
14325 && CHARPOS (startp
) >= BEGV
14326 && CHARPOS (startp
) <= ZV
)
14328 w
->optional_new_start
= Qnil
;
14329 start_display (&it
, w
, startp
);
14330 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14331 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14332 if (IT_CHARPOS (it
) == PT
)
14333 w
->force_start
= Qt
;
14334 /* IT may overshoot PT if text at PT is invisible. */
14335 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14336 w
->force_start
= Qt
;
14341 /* Handle case where place to start displaying has been specified,
14342 unless the specified location is outside the accessible range. */
14343 if (!NILP (w
->force_start
)
14344 || w
->frozen_window_start_p
)
14346 /* We set this later on if we have to adjust point. */
14349 w
->force_start
= Qnil
;
14351 w
->window_end_valid
= Qnil
;
14353 /* Forget any recorded base line for line number display. */
14354 if (!buffer_unchanged_p
)
14355 w
->base_line_number
= Qnil
;
14357 /* Redisplay the mode line. Select the buffer properly for that.
14358 Also, run the hook window-scroll-functions
14359 because we have scrolled. */
14360 /* Note, we do this after clearing force_start because
14361 if there's an error, it is better to forget about force_start
14362 than to get into an infinite loop calling the hook functions
14363 and having them get more errors. */
14364 if (!update_mode_line
14365 || ! NILP (Vwindow_scroll_functions
))
14367 update_mode_line
= 1;
14368 w
->update_mode_line
= Qt
;
14369 startp
= run_window_scroll_functions (window
, startp
);
14372 w
->last_modified
= make_number (0);
14373 w
->last_overlay_modified
= make_number (0);
14374 if (CHARPOS (startp
) < BEGV
)
14375 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14376 else if (CHARPOS (startp
) > ZV
)
14377 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14379 /* Redisplay, then check if cursor has been set during the
14380 redisplay. Give up if new fonts were loaded. */
14381 /* We used to issue a CHECK_MARGINS argument to try_window here,
14382 but this causes scrolling to fail when point begins inside
14383 the scroll margin (bug#148) -- cyd */
14384 if (!try_window (window
, startp
, 0))
14386 w
->force_start
= Qt
;
14387 clear_glyph_matrix (w
->desired_matrix
);
14388 goto need_larger_matrices
;
14391 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14393 /* If point does not appear, try to move point so it does
14394 appear. The desired matrix has been built above, so we
14395 can use it here. */
14396 new_vpos
= window_box_height (w
) / 2;
14399 if (!cursor_row_fully_visible_p (w
, 0, 0))
14401 /* Point does appear, but on a line partly visible at end of window.
14402 Move it back to a fully-visible line. */
14403 new_vpos
= window_box_height (w
);
14406 /* If we need to move point for either of the above reasons,
14407 now actually do it. */
14410 struct glyph_row
*row
;
14412 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14413 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14416 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14417 MATRIX_ROW_START_BYTEPOS (row
));
14419 if (w
!= XWINDOW (selected_window
))
14420 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14421 else if (current_buffer
== old
)
14422 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14424 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14426 /* If we are highlighting the region, then we just changed
14427 the region, so redisplay to show it. */
14428 if (!NILP (Vtransient_mark_mode
)
14429 && !NILP (BVAR (current_buffer
, mark_active
)))
14431 clear_glyph_matrix (w
->desired_matrix
);
14432 if (!try_window (window
, startp
, 0))
14433 goto need_larger_matrices
;
14438 debug_method_add (w
, "forced window start");
14443 /* Handle case where text has not changed, only point, and it has
14444 not moved off the frame, and we are not retrying after hscroll.
14445 (current_matrix_up_to_date_p is nonzero when retrying.) */
14446 if (current_matrix_up_to_date_p
14447 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14448 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14452 case CURSOR_MOVEMENT_SUCCESS
:
14453 used_current_matrix_p
= 1;
14456 case CURSOR_MOVEMENT_MUST_SCROLL
:
14457 goto try_to_scroll
;
14463 /* If current starting point was originally the beginning of a line
14464 but no longer is, find a new starting point. */
14465 else if (!NILP (w
->start_at_line_beg
)
14466 && !(CHARPOS (startp
) <= BEGV
14467 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14470 debug_method_add (w
, "recenter 1");
14475 /* Try scrolling with try_window_id. Value is > 0 if update has
14476 been done, it is -1 if we know that the same window start will
14477 not work. It is 0 if unsuccessful for some other reason. */
14478 else if ((tem
= try_window_id (w
)) != 0)
14481 debug_method_add (w
, "try_window_id %d", tem
);
14484 if (fonts_changed_p
)
14485 goto need_larger_matrices
;
14489 /* Otherwise try_window_id has returned -1 which means that we
14490 don't want the alternative below this comment to execute. */
14492 else if (CHARPOS (startp
) >= BEGV
14493 && CHARPOS (startp
) <= ZV
14494 && PT
>= CHARPOS (startp
)
14495 && (CHARPOS (startp
) < ZV
14496 /* Avoid starting at end of buffer. */
14497 || CHARPOS (startp
) == BEGV
14498 || (XFASTINT (w
->last_modified
) >= MODIFF
14499 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14502 /* If first window line is a continuation line, and window start
14503 is inside the modified region, but the first change is before
14504 current window start, we must select a new window start.
14506 However, if this is the result of a down-mouse event (e.g. by
14507 extending the mouse-drag-overlay), we don't want to select a
14508 new window start, since that would change the position under
14509 the mouse, resulting in an unwanted mouse-movement rather
14510 than a simple mouse-click. */
14511 if (NILP (w
->start_at_line_beg
)
14512 && NILP (do_mouse_tracking
)
14513 && CHARPOS (startp
) > BEGV
14514 && CHARPOS (startp
) > BEG
+ beg_unchanged
14515 && CHARPOS (startp
) <= Z
- end_unchanged
14516 /* Even if w->start_at_line_beg is nil, a new window may
14517 start at a line_beg, since that's how set_buffer_window
14518 sets it. So, we need to check the return value of
14519 compute_window_start_on_continuation_line. (See also
14521 && XMARKER (w
->start
)->buffer
== current_buffer
14522 && compute_window_start_on_continuation_line (w
))
14524 w
->force_start
= Qt
;
14525 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14530 debug_method_add (w
, "same window start");
14533 /* Try to redisplay starting at same place as before.
14534 If point has not moved off frame, accept the results. */
14535 if (!current_matrix_up_to_date_p
14536 /* Don't use try_window_reusing_current_matrix in this case
14537 because a window scroll function can have changed the
14539 || !NILP (Vwindow_scroll_functions
)
14540 || MINI_WINDOW_P (w
)
14541 || !(used_current_matrix_p
14542 = try_window_reusing_current_matrix (w
)))
14544 IF_DEBUG (debug_method_add (w
, "1"));
14545 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14546 /* -1 means we need to scroll.
14547 0 means we need new matrices, but fonts_changed_p
14548 is set in that case, so we will detect it below. */
14549 goto try_to_scroll
;
14552 if (fonts_changed_p
)
14553 goto need_larger_matrices
;
14555 if (w
->cursor
.vpos
>= 0)
14557 if (!just_this_one_p
14558 || current_buffer
->clip_changed
14559 || BEG_UNCHANGED
< CHARPOS (startp
))
14560 /* Forget any recorded base line for line number display. */
14561 w
->base_line_number
= Qnil
;
14563 if (!cursor_row_fully_visible_p (w
, 1, 0))
14565 clear_glyph_matrix (w
->desired_matrix
);
14566 last_line_misfit
= 1;
14568 /* Drop through and scroll. */
14573 clear_glyph_matrix (w
->desired_matrix
);
14578 w
->last_modified
= make_number (0);
14579 w
->last_overlay_modified
= make_number (0);
14581 /* Redisplay the mode line. Select the buffer properly for that. */
14582 if (!update_mode_line
)
14584 update_mode_line
= 1;
14585 w
->update_mode_line
= Qt
;
14588 /* Try to scroll by specified few lines. */
14589 if ((scroll_conservatively
14590 || emacs_scroll_step
14591 || temp_scroll_step
14592 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14593 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14594 && CHARPOS (startp
) >= BEGV
14595 && CHARPOS (startp
) <= ZV
)
14597 /* The function returns -1 if new fonts were loaded, 1 if
14598 successful, 0 if not successful. */
14599 int ss
= try_scrolling (window
, just_this_one_p
,
14600 scroll_conservatively
,
14602 temp_scroll_step
, last_line_misfit
);
14605 case SCROLLING_SUCCESS
:
14608 case SCROLLING_NEED_LARGER_MATRICES
:
14609 goto need_larger_matrices
;
14611 case SCROLLING_FAILED
:
14619 /* Finally, just choose a place to start which positions point
14620 according to user preferences. */
14625 debug_method_add (w
, "recenter");
14628 /* w->vscroll = 0; */
14630 /* Forget any previously recorded base line for line number display. */
14631 if (!buffer_unchanged_p
)
14632 w
->base_line_number
= Qnil
;
14634 /* Determine the window start relative to point. */
14635 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14636 it
.current_y
= it
.last_visible_y
;
14637 if (centering_position
< 0)
14641 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14643 EMACS_INT margin_pos
= CHARPOS (startp
);
14645 Lisp_Object aggressive
;
14647 /* If there is a scroll margin at the top of the window, find
14648 its character position. */
14650 /* Cannot call start_display if startp is not in the
14651 accessible region of the buffer. This can happen when we
14652 have just switched to a different buffer and/or changed
14653 its restriction. In that case, startp is initialized to
14654 the character position 1 (BEG) because we did not yet
14655 have chance to display the buffer even once. */
14656 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14660 start_display (&it1
, w
, startp
);
14661 move_it_vertically (&it1
, margin
);
14662 margin_pos
= IT_CHARPOS (it1
);
14664 scrolling_up
= PT
> margin_pos
;
14667 ? BVAR (current_buffer
, scroll_up_aggressively
)
14668 : BVAR (current_buffer
, scroll_down_aggressively
);
14670 if (!MINI_WINDOW_P (w
)
14671 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14675 /* Setting scroll-conservatively overrides
14676 scroll-*-aggressively. */
14677 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14679 double float_amount
= XFLOATINT (aggressive
);
14681 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14682 if (pt_offset
== 0 && float_amount
> 0)
14687 /* Compute how much to move the window start backward from
14688 point so that point will be displayed where the user
14692 centering_position
= it
.last_visible_y
;
14694 centering_position
-= pt_offset
;
14695 centering_position
-=
14696 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14697 /* Don't let point enter the scroll margin near top of
14699 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14700 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14703 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14706 /* Set the window start half the height of the window backward
14708 centering_position
= window_box_height (w
) / 2;
14710 move_it_vertically_backward (&it
, centering_position
);
14712 xassert (IT_CHARPOS (it
) >= BEGV
);
14714 /* The function move_it_vertically_backward may move over more
14715 than the specified y-distance. If it->w is small, e.g. a
14716 mini-buffer window, we may end up in front of the window's
14717 display area. Start displaying at the start of the line
14718 containing PT in this case. */
14719 if (it
.current_y
<= 0)
14721 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14722 move_it_vertically_backward (&it
, 0);
14726 it
.current_x
= it
.hpos
= 0;
14728 /* Set the window start position here explicitly, to avoid an
14729 infinite loop in case the functions in window-scroll-functions
14731 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14733 /* Run scroll hooks. */
14734 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14736 /* Redisplay the window. */
14737 if (!current_matrix_up_to_date_p
14738 || windows_or_buffers_changed
14739 || cursor_type_changed
14740 /* Don't use try_window_reusing_current_matrix in this case
14741 because it can have changed the buffer. */
14742 || !NILP (Vwindow_scroll_functions
)
14743 || !just_this_one_p
14744 || MINI_WINDOW_P (w
)
14745 || !(used_current_matrix_p
14746 = try_window_reusing_current_matrix (w
)))
14747 try_window (window
, startp
, 0);
14749 /* If new fonts have been loaded (due to fontsets), give up. We
14750 have to start a new redisplay since we need to re-adjust glyph
14752 if (fonts_changed_p
)
14753 goto need_larger_matrices
;
14755 /* If cursor did not appear assume that the middle of the window is
14756 in the first line of the window. Do it again with the next line.
14757 (Imagine a window of height 100, displaying two lines of height
14758 60. Moving back 50 from it->last_visible_y will end in the first
14760 if (w
->cursor
.vpos
< 0)
14762 if (!NILP (w
->window_end_valid
)
14763 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14765 clear_glyph_matrix (w
->desired_matrix
);
14766 move_it_by_lines (&it
, 1);
14767 try_window (window
, it
.current
.pos
, 0);
14769 else if (PT
< IT_CHARPOS (it
))
14771 clear_glyph_matrix (w
->desired_matrix
);
14772 move_it_by_lines (&it
, -1);
14773 try_window (window
, it
.current
.pos
, 0);
14777 /* Not much we can do about it. */
14781 /* Consider the following case: Window starts at BEGV, there is
14782 invisible, intangible text at BEGV, so that display starts at
14783 some point START > BEGV. It can happen that we are called with
14784 PT somewhere between BEGV and START. Try to handle that case. */
14785 if (w
->cursor
.vpos
< 0)
14787 struct glyph_row
*row
= w
->current_matrix
->rows
;
14788 if (row
->mode_line_p
)
14790 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14793 if (!cursor_row_fully_visible_p (w
, 0, 0))
14795 /* If vscroll is enabled, disable it and try again. */
14799 clear_glyph_matrix (w
->desired_matrix
);
14803 /* If centering point failed to make the whole line visible,
14804 put point at the top instead. That has to make the whole line
14805 visible, if it can be done. */
14806 if (centering_position
== 0)
14809 clear_glyph_matrix (w
->desired_matrix
);
14810 centering_position
= 0;
14816 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14817 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14818 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14821 /* Display the mode line, if we must. */
14822 if ((update_mode_line
14823 /* If window not full width, must redo its mode line
14824 if (a) the window to its side is being redone and
14825 (b) we do a frame-based redisplay. This is a consequence
14826 of how inverted lines are drawn in frame-based redisplay. */
14827 || (!just_this_one_p
14828 && !FRAME_WINDOW_P (f
)
14829 && !WINDOW_FULL_WIDTH_P (w
))
14830 /* Line number to display. */
14831 || INTEGERP (w
->base_line_pos
)
14832 /* Column number is displayed and different from the one displayed. */
14833 || (!NILP (w
->column_number_displayed
)
14834 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
14835 /* This means that the window has a mode line. */
14836 && (WINDOW_WANTS_MODELINE_P (w
)
14837 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14839 display_mode_lines (w
);
14841 /* If mode line height has changed, arrange for a thorough
14842 immediate redisplay using the correct mode line height. */
14843 if (WINDOW_WANTS_MODELINE_P (w
)
14844 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14846 fonts_changed_p
= 1;
14847 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14848 = DESIRED_MODE_LINE_HEIGHT (w
);
14851 /* If header line height has changed, arrange for a thorough
14852 immediate redisplay using the correct header line height. */
14853 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14854 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14856 fonts_changed_p
= 1;
14857 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14858 = DESIRED_HEADER_LINE_HEIGHT (w
);
14861 if (fonts_changed_p
)
14862 goto need_larger_matrices
;
14865 if (!line_number_displayed
14866 && !BUFFERP (w
->base_line_pos
))
14868 w
->base_line_pos
= Qnil
;
14869 w
->base_line_number
= Qnil
;
14874 /* When we reach a frame's selected window, redo the frame's menu bar. */
14875 if (update_mode_line
14876 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14878 int redisplay_menu_p
= 0;
14880 if (FRAME_WINDOW_P (f
))
14882 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14883 || defined (HAVE_NS) || defined (USE_GTK)
14884 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14886 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14890 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14892 if (redisplay_menu_p
)
14893 display_menu_bar (w
);
14895 #ifdef HAVE_WINDOW_SYSTEM
14896 if (FRAME_WINDOW_P (f
))
14898 #if defined (USE_GTK) || defined (HAVE_NS)
14899 if (FRAME_EXTERNAL_TOOL_BAR (f
))
14900 redisplay_tool_bar (f
);
14902 if (WINDOWP (f
->tool_bar_window
)
14903 && (FRAME_TOOL_BAR_LINES (f
) > 0
14904 || !NILP (Vauto_resize_tool_bars
))
14905 && redisplay_tool_bar (f
))
14906 ignore_mouse_drag_p
= 1;
14912 #ifdef HAVE_WINDOW_SYSTEM
14913 if (FRAME_WINDOW_P (f
)
14914 && update_window_fringes (w
, (just_this_one_p
14915 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14916 || w
->pseudo_window_p
)))
14920 if (draw_window_fringes (w
, 1))
14921 x_draw_vertical_border (w
);
14925 #endif /* HAVE_WINDOW_SYSTEM */
14927 /* We go to this label, with fonts_changed_p nonzero,
14928 if it is necessary to try again using larger glyph matrices.
14929 We have to redeem the scroll bar even in this case,
14930 because the loop in redisplay_internal expects that. */
14931 need_larger_matrices
:
14933 finish_scroll_bars
:
14935 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14937 /* Set the thumb's position and size. */
14938 set_vertical_scroll_bar (w
);
14940 /* Note that we actually used the scroll bar attached to this
14941 window, so it shouldn't be deleted at the end of redisplay. */
14942 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14943 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14946 /* Restore current_buffer and value of point in it. The window
14947 update may have changed the buffer, so first make sure `opoint'
14948 is still valid (Bug#6177). */
14949 if (CHARPOS (opoint
) < BEGV
)
14950 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14951 else if (CHARPOS (opoint
) > ZV
)
14952 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14954 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14956 set_buffer_internal_1 (old
);
14957 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14958 shorter. This can be caused by log truncation in *Messages*. */
14959 if (CHARPOS (lpoint
) <= ZV
)
14960 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14962 unbind_to (count
, Qnil
);
14966 /* Build the complete desired matrix of WINDOW with a window start
14967 buffer position POS.
14969 Value is 1 if successful. It is zero if fonts were loaded during
14970 redisplay which makes re-adjusting glyph matrices necessary, and -1
14971 if point would appear in the scroll margins.
14972 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14973 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14977 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14979 struct window
*w
= XWINDOW (window
);
14981 struct glyph_row
*last_text_row
= NULL
;
14982 struct frame
*f
= XFRAME (w
->frame
);
14984 /* Make POS the new window start. */
14985 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14987 /* Mark cursor position as unknown. No overlay arrow seen. */
14988 w
->cursor
.vpos
= -1;
14989 overlay_arrow_seen
= 0;
14991 /* Initialize iterator and info to start at POS. */
14992 start_display (&it
, w
, pos
);
14994 /* Display all lines of W. */
14995 while (it
.current_y
< it
.last_visible_y
)
14997 if (display_line (&it
))
14998 last_text_row
= it
.glyph_row
- 1;
14999 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15003 /* Don't let the cursor end in the scroll margins. */
15004 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15005 && !MINI_WINDOW_P (w
))
15007 int this_scroll_margin
;
15009 if (scroll_margin
> 0)
15011 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15012 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15015 this_scroll_margin
= 0;
15017 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15018 && w
->cursor
.y
< this_scroll_margin
15019 && CHARPOS (pos
) > BEGV
15020 && IT_CHARPOS (it
) < ZV
)
15021 /* rms: considering make_cursor_line_fully_visible_p here
15022 seems to give wrong results. We don't want to recenter
15023 when the last line is partly visible, we want to allow
15024 that case to be handled in the usual way. */
15025 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15027 w
->cursor
.vpos
= -1;
15028 clear_glyph_matrix (w
->desired_matrix
);
15033 /* If bottom moved off end of frame, change mode line percentage. */
15034 if (XFASTINT (w
->window_end_pos
) <= 0
15035 && Z
!= IT_CHARPOS (it
))
15036 w
->update_mode_line
= Qt
;
15038 /* Set window_end_pos to the offset of the last character displayed
15039 on the window from the end of current_buffer. Set
15040 window_end_vpos to its row number. */
15043 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
15044 w
->window_end_bytepos
15045 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15047 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15049 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15050 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
15051 ->displays_text_p
);
15055 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15056 w
->window_end_pos
= make_number (Z
- ZV
);
15057 w
->window_end_vpos
= make_number (0);
15060 /* But that is not valid info until redisplay finishes. */
15061 w
->window_end_valid
= Qnil
;
15067 /************************************************************************
15068 Window redisplay reusing current matrix when buffer has not changed
15069 ************************************************************************/
15071 /* Try redisplay of window W showing an unchanged buffer with a
15072 different window start than the last time it was displayed by
15073 reusing its current matrix. Value is non-zero if successful.
15074 W->start is the new window start. */
15077 try_window_reusing_current_matrix (struct window
*w
)
15079 struct frame
*f
= XFRAME (w
->frame
);
15080 struct glyph_row
*bottom_row
;
15083 struct text_pos start
, new_start
;
15084 int nrows_scrolled
, i
;
15085 struct glyph_row
*last_text_row
;
15086 struct glyph_row
*last_reused_text_row
;
15087 struct glyph_row
*start_row
;
15088 int start_vpos
, min_y
, max_y
;
15091 if (inhibit_try_window_reusing
)
15095 if (/* This function doesn't handle terminal frames. */
15096 !FRAME_WINDOW_P (f
)
15097 /* Don't try to reuse the display if windows have been split
15099 || windows_or_buffers_changed
15100 || cursor_type_changed
)
15103 /* Can't do this if region may have changed. */
15104 if ((!NILP (Vtransient_mark_mode
)
15105 && !NILP (BVAR (current_buffer
, mark_active
)))
15106 || !NILP (w
->region_showing
)
15107 || !NILP (Vshow_trailing_whitespace
))
15110 /* If top-line visibility has changed, give up. */
15111 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15112 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
15115 /* Give up if old or new display is scrolled vertically. We could
15116 make this function handle this, but right now it doesn't. */
15117 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15118 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
15121 /* The variable new_start now holds the new window start. The old
15122 start `start' can be determined from the current matrix. */
15123 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
15124 start
= start_row
->minpos
;
15125 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15127 /* Clear the desired matrix for the display below. */
15128 clear_glyph_matrix (w
->desired_matrix
);
15130 if (CHARPOS (new_start
) <= CHARPOS (start
))
15132 /* Don't use this method if the display starts with an ellipsis
15133 displayed for invisible text. It's not easy to handle that case
15134 below, and it's certainly not worth the effort since this is
15135 not a frequent case. */
15136 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
15139 IF_DEBUG (debug_method_add (w
, "twu1"));
15141 /* Display up to a row that can be reused. The variable
15142 last_text_row is set to the last row displayed that displays
15143 text. Note that it.vpos == 0 if or if not there is a
15144 header-line; it's not the same as the MATRIX_ROW_VPOS! */
15145 start_display (&it
, w
, new_start
);
15146 w
->cursor
.vpos
= -1;
15147 last_text_row
= last_reused_text_row
= NULL
;
15149 while (it
.current_y
< it
.last_visible_y
15150 && !fonts_changed_p
)
15152 /* If we have reached into the characters in the START row,
15153 that means the line boundaries have changed. So we
15154 can't start copying with the row START. Maybe it will
15155 work to start copying with the following row. */
15156 while (IT_CHARPOS (it
) > CHARPOS (start
))
15158 /* Advance to the next row as the "start". */
15160 start
= start_row
->minpos
;
15161 /* If there are no more rows to try, or just one, give up. */
15162 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
15163 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
15164 || CHARPOS (start
) == ZV
)
15166 clear_glyph_matrix (w
->desired_matrix
);
15170 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15172 /* If we have reached alignment,
15173 we can copy the rest of the rows. */
15174 if (IT_CHARPOS (it
) == CHARPOS (start
))
15177 if (display_line (&it
))
15178 last_text_row
= it
.glyph_row
- 1;
15181 /* A value of current_y < last_visible_y means that we stopped
15182 at the previous window start, which in turn means that we
15183 have at least one reusable row. */
15184 if (it
.current_y
< it
.last_visible_y
)
15186 struct glyph_row
*row
;
15188 /* IT.vpos always starts from 0; it counts text lines. */
15189 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
15191 /* Find PT if not already found in the lines displayed. */
15192 if (w
->cursor
.vpos
< 0)
15194 int dy
= it
.current_y
- start_row
->y
;
15196 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15197 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
15199 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
15200 dy
, nrows_scrolled
);
15203 clear_glyph_matrix (w
->desired_matrix
);
15208 /* Scroll the display. Do it before the current matrix is
15209 changed. The problem here is that update has not yet
15210 run, i.e. part of the current matrix is not up to date.
15211 scroll_run_hook will clear the cursor, and use the
15212 current matrix to get the height of the row the cursor is
15214 run
.current_y
= start_row
->y
;
15215 run
.desired_y
= it
.current_y
;
15216 run
.height
= it
.last_visible_y
- it
.current_y
;
15218 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
15221 FRAME_RIF (f
)->update_window_begin_hook (w
);
15222 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15223 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15224 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15228 /* Shift current matrix down by nrows_scrolled lines. */
15229 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15230 rotate_matrix (w
->current_matrix
,
15232 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15235 /* Disable lines that must be updated. */
15236 for (i
= 0; i
< nrows_scrolled
; ++i
)
15237 (start_row
+ i
)->enabled_p
= 0;
15239 /* Re-compute Y positions. */
15240 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15241 max_y
= it
.last_visible_y
;
15242 for (row
= start_row
+ nrows_scrolled
;
15246 row
->y
= it
.current_y
;
15247 row
->visible_height
= row
->height
;
15249 if (row
->y
< min_y
)
15250 row
->visible_height
-= min_y
- row
->y
;
15251 if (row
->y
+ row
->height
> max_y
)
15252 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15253 row
->redraw_fringe_bitmaps_p
= 1;
15255 it
.current_y
+= row
->height
;
15257 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15258 last_reused_text_row
= row
;
15259 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15263 /* Disable lines in the current matrix which are now
15264 below the window. */
15265 for (++row
; row
< bottom_row
; ++row
)
15266 row
->enabled_p
= row
->mode_line_p
= 0;
15269 /* Update window_end_pos etc.; last_reused_text_row is the last
15270 reused row from the current matrix containing text, if any.
15271 The value of last_text_row is the last displayed line
15272 containing text. */
15273 if (last_reused_text_row
)
15275 w
->window_end_bytepos
15276 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15278 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15280 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15281 w
->current_matrix
));
15283 else if (last_text_row
)
15285 w
->window_end_bytepos
15286 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15288 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15290 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15294 /* This window must be completely empty. */
15295 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15296 w
->window_end_pos
= make_number (Z
- ZV
);
15297 w
->window_end_vpos
= make_number (0);
15299 w
->window_end_valid
= Qnil
;
15301 /* Update hint: don't try scrolling again in update_window. */
15302 w
->desired_matrix
->no_scrolling_p
= 1;
15305 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15309 else if (CHARPOS (new_start
) > CHARPOS (start
))
15311 struct glyph_row
*pt_row
, *row
;
15312 struct glyph_row
*first_reusable_row
;
15313 struct glyph_row
*first_row_to_display
;
15315 int yb
= window_text_bottom_y (w
);
15317 /* Find the row starting at new_start, if there is one. Don't
15318 reuse a partially visible line at the end. */
15319 first_reusable_row
= start_row
;
15320 while (first_reusable_row
->enabled_p
15321 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15322 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15323 < CHARPOS (new_start
)))
15324 ++first_reusable_row
;
15326 /* Give up if there is no row to reuse. */
15327 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15328 || !first_reusable_row
->enabled_p
15329 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15330 != CHARPOS (new_start
)))
15333 /* We can reuse fully visible rows beginning with
15334 first_reusable_row to the end of the window. Set
15335 first_row_to_display to the first row that cannot be reused.
15336 Set pt_row to the row containing point, if there is any. */
15338 for (first_row_to_display
= first_reusable_row
;
15339 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15340 ++first_row_to_display
)
15342 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15343 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15344 pt_row
= first_row_to_display
;
15347 /* Start displaying at the start of first_row_to_display. */
15348 xassert (first_row_to_display
->y
< yb
);
15349 init_to_row_start (&it
, w
, first_row_to_display
);
15351 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15353 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15355 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15356 + WINDOW_HEADER_LINE_HEIGHT (w
));
15358 /* Display lines beginning with first_row_to_display in the
15359 desired matrix. Set last_text_row to the last row displayed
15360 that displays text. */
15361 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15362 if (pt_row
== NULL
)
15363 w
->cursor
.vpos
= -1;
15364 last_text_row
= NULL
;
15365 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15366 if (display_line (&it
))
15367 last_text_row
= it
.glyph_row
- 1;
15369 /* If point is in a reused row, adjust y and vpos of the cursor
15373 w
->cursor
.vpos
-= nrows_scrolled
;
15374 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15377 /* Give up if point isn't in a row displayed or reused. (This
15378 also handles the case where w->cursor.vpos < nrows_scrolled
15379 after the calls to display_line, which can happen with scroll
15380 margins. See bug#1295.) */
15381 if (w
->cursor
.vpos
< 0)
15383 clear_glyph_matrix (w
->desired_matrix
);
15387 /* Scroll the display. */
15388 run
.current_y
= first_reusable_row
->y
;
15389 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15390 run
.height
= it
.last_visible_y
- run
.current_y
;
15391 dy
= run
.current_y
- run
.desired_y
;
15396 FRAME_RIF (f
)->update_window_begin_hook (w
);
15397 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15398 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15399 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15403 /* Adjust Y positions of reused rows. */
15404 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15405 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15406 max_y
= it
.last_visible_y
;
15407 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15410 row
->visible_height
= row
->height
;
15411 if (row
->y
< min_y
)
15412 row
->visible_height
-= min_y
- row
->y
;
15413 if (row
->y
+ row
->height
> max_y
)
15414 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15415 row
->redraw_fringe_bitmaps_p
= 1;
15418 /* Scroll the current matrix. */
15419 xassert (nrows_scrolled
> 0);
15420 rotate_matrix (w
->current_matrix
,
15422 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15425 /* Disable rows not reused. */
15426 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15427 row
->enabled_p
= 0;
15429 /* Point may have moved to a different line, so we cannot assume that
15430 the previous cursor position is valid; locate the correct row. */
15433 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15434 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15438 w
->cursor
.y
= row
->y
;
15440 if (row
< bottom_row
)
15442 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15443 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15445 /* Can't use this optimization with bidi-reordered glyph
15446 rows, unless cursor is already at point. */
15447 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15449 if (!(w
->cursor
.hpos
>= 0
15450 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15451 && BUFFERP (glyph
->object
)
15452 && glyph
->charpos
== PT
))
15457 && (!BUFFERP (glyph
->object
)
15458 || glyph
->charpos
< PT
);
15462 w
->cursor
.x
+= glyph
->pixel_width
;
15467 /* Adjust window end. A null value of last_text_row means that
15468 the window end is in reused rows which in turn means that
15469 only its vpos can have changed. */
15472 w
->window_end_bytepos
15473 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15475 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15477 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15482 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15485 w
->window_end_valid
= Qnil
;
15486 w
->desired_matrix
->no_scrolling_p
= 1;
15489 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15499 /************************************************************************
15500 Window redisplay reusing current matrix when buffer has changed
15501 ************************************************************************/
15503 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15504 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15505 EMACS_INT
*, EMACS_INT
*);
15506 static struct glyph_row
*
15507 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15508 struct glyph_row
*);
15511 /* Return the last row in MATRIX displaying text. If row START is
15512 non-null, start searching with that row. IT gives the dimensions
15513 of the display. Value is null if matrix is empty; otherwise it is
15514 a pointer to the row found. */
15516 static struct glyph_row
*
15517 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15518 struct glyph_row
*start
)
15520 struct glyph_row
*row
, *row_found
;
15522 /* Set row_found to the last row in IT->w's current matrix
15523 displaying text. The loop looks funny but think of partially
15526 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15527 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15529 xassert (row
->enabled_p
);
15531 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15540 /* Return the last row in the current matrix of W that is not affected
15541 by changes at the start of current_buffer that occurred since W's
15542 current matrix was built. Value is null if no such row exists.
15544 BEG_UNCHANGED us the number of characters unchanged at the start of
15545 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15546 first changed character in current_buffer. Characters at positions <
15547 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15548 when the current matrix was built. */
15550 static struct glyph_row
*
15551 find_last_unchanged_at_beg_row (struct window
*w
)
15553 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15554 struct glyph_row
*row
;
15555 struct glyph_row
*row_found
= NULL
;
15556 int yb
= window_text_bottom_y (w
);
15558 /* Find the last row displaying unchanged text. */
15559 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15560 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15561 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15564 if (/* If row ends before first_changed_pos, it is unchanged,
15565 except in some case. */
15566 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15567 /* When row ends in ZV and we write at ZV it is not
15569 && !row
->ends_at_zv_p
15570 /* When first_changed_pos is the end of a continued line,
15571 row is not unchanged because it may be no longer
15573 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15574 && (row
->continued_p
15575 || row
->exact_window_width_line_p
)))
15578 /* Stop if last visible row. */
15579 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15587 /* Find the first glyph row in the current matrix of W that is not
15588 affected by changes at the end of current_buffer since the
15589 time W's current matrix was built.
15591 Return in *DELTA the number of chars by which buffer positions in
15592 unchanged text at the end of current_buffer must be adjusted.
15594 Return in *DELTA_BYTES the corresponding number of bytes.
15596 Value is null if no such row exists, i.e. all rows are affected by
15599 static struct glyph_row
*
15600 find_first_unchanged_at_end_row (struct window
*w
,
15601 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15603 struct glyph_row
*row
;
15604 struct glyph_row
*row_found
= NULL
;
15606 *delta
= *delta_bytes
= 0;
15608 /* Display must not have been paused, otherwise the current matrix
15609 is not up to date. */
15610 eassert (!NILP (w
->window_end_valid
));
15612 /* A value of window_end_pos >= END_UNCHANGED means that the window
15613 end is in the range of changed text. If so, there is no
15614 unchanged row at the end of W's current matrix. */
15615 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15618 /* Set row to the last row in W's current matrix displaying text. */
15619 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15621 /* If matrix is entirely empty, no unchanged row exists. */
15622 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15624 /* The value of row is the last glyph row in the matrix having a
15625 meaningful buffer position in it. The end position of row
15626 corresponds to window_end_pos. This allows us to translate
15627 buffer positions in the current matrix to current buffer
15628 positions for characters not in changed text. */
15630 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15631 EMACS_INT Z_BYTE_old
=
15632 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15633 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15634 struct glyph_row
*first_text_row
15635 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15637 *delta
= Z
- Z_old
;
15638 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15640 /* Set last_unchanged_pos to the buffer position of the last
15641 character in the buffer that has not been changed. Z is the
15642 index + 1 of the last character in current_buffer, i.e. by
15643 subtracting END_UNCHANGED we get the index of the last
15644 unchanged character, and we have to add BEG to get its buffer
15646 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15647 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15649 /* Search backward from ROW for a row displaying a line that
15650 starts at a minimum position >= last_unchanged_pos_old. */
15651 for (; row
> first_text_row
; --row
)
15653 /* This used to abort, but it can happen.
15654 It is ok to just stop the search instead here. KFS. */
15655 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15658 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15663 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15669 /* Make sure that glyph rows in the current matrix of window W
15670 reference the same glyph memory as corresponding rows in the
15671 frame's frame matrix. This function is called after scrolling W's
15672 current matrix on a terminal frame in try_window_id and
15673 try_window_reusing_current_matrix. */
15676 sync_frame_with_window_matrix_rows (struct window
*w
)
15678 struct frame
*f
= XFRAME (w
->frame
);
15679 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15681 /* Preconditions: W must be a leaf window and full-width. Its frame
15682 must have a frame matrix. */
15683 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15684 xassert (WINDOW_FULL_WIDTH_P (w
));
15685 xassert (!FRAME_WINDOW_P (f
));
15687 /* If W is a full-width window, glyph pointers in W's current matrix
15688 have, by definition, to be the same as glyph pointers in the
15689 corresponding frame matrix. Note that frame matrices have no
15690 marginal areas (see build_frame_matrix). */
15691 window_row
= w
->current_matrix
->rows
;
15692 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15693 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15694 while (window_row
< window_row_end
)
15696 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15697 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15699 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15700 frame_row
->glyphs
[TEXT_AREA
] = start
;
15701 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15702 frame_row
->glyphs
[LAST_AREA
] = end
;
15704 /* Disable frame rows whose corresponding window rows have
15705 been disabled in try_window_id. */
15706 if (!window_row
->enabled_p
)
15707 frame_row
->enabled_p
= 0;
15709 ++window_row
, ++frame_row
;
15714 /* Find the glyph row in window W containing CHARPOS. Consider all
15715 rows between START and END (not inclusive). END null means search
15716 all rows to the end of the display area of W. Value is the row
15717 containing CHARPOS or null. */
15720 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15721 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15723 struct glyph_row
*row
= start
;
15724 struct glyph_row
*best_row
= NULL
;
15725 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15728 /* If we happen to start on a header-line, skip that. */
15729 if (row
->mode_line_p
)
15732 if ((end
&& row
>= end
) || !row
->enabled_p
)
15735 last_y
= window_text_bottom_y (w
) - dy
;
15739 /* Give up if we have gone too far. */
15740 if (end
&& row
>= end
)
15742 /* This formerly returned if they were equal.
15743 I think that both quantities are of a "last plus one" type;
15744 if so, when they are equal, the row is within the screen. -- rms. */
15745 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15748 /* If it is in this row, return this row. */
15749 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15750 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15751 /* The end position of a row equals the start
15752 position of the next row. If CHARPOS is there, we
15753 would rather display it in the next line, except
15754 when this line ends in ZV. */
15755 && !row
->ends_at_zv_p
15756 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15757 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15761 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15762 || (!best_row
&& !row
->continued_p
))
15764 /* In bidi-reordered rows, there could be several rows
15765 occluding point, all of them belonging to the same
15766 continued line. We need to find the row which fits
15767 CHARPOS the best. */
15768 for (g
= row
->glyphs
[TEXT_AREA
];
15769 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15772 if (!STRINGP (g
->object
))
15774 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15776 mindif
= eabs (g
->charpos
- charpos
);
15778 /* Exact match always wins. */
15785 else if (best_row
&& !row
->continued_p
)
15792 /* Try to redisplay window W by reusing its existing display. W's
15793 current matrix must be up to date when this function is called,
15794 i.e. window_end_valid must not be nil.
15798 1 if display has been updated
15799 0 if otherwise unsuccessful
15800 -1 if redisplay with same window start is known not to succeed
15802 The following steps are performed:
15804 1. Find the last row in the current matrix of W that is not
15805 affected by changes at the start of current_buffer. If no such row
15808 2. Find the first row in W's current matrix that is not affected by
15809 changes at the end of current_buffer. Maybe there is no such row.
15811 3. Display lines beginning with the row + 1 found in step 1 to the
15812 row found in step 2 or, if step 2 didn't find a row, to the end of
15815 4. If cursor is not known to appear on the window, give up.
15817 5. If display stopped at the row found in step 2, scroll the
15818 display and current matrix as needed.
15820 6. Maybe display some lines at the end of W, if we must. This can
15821 happen under various circumstances, like a partially visible line
15822 becoming fully visible, or because newly displayed lines are displayed
15823 in smaller font sizes.
15825 7. Update W's window end information. */
15828 try_window_id (struct window
*w
)
15830 struct frame
*f
= XFRAME (w
->frame
);
15831 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15832 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15833 struct glyph_row
*last_unchanged_at_beg_row
;
15834 struct glyph_row
*first_unchanged_at_end_row
;
15835 struct glyph_row
*row
;
15836 struct glyph_row
*bottom_row
;
15839 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15841 struct text_pos start_pos
;
15843 int first_unchanged_at_end_vpos
= 0;
15844 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15845 struct text_pos start
;
15846 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15849 if (inhibit_try_window_id
)
15853 /* This is handy for debugging. */
15855 #define GIVE_UP(X) \
15857 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15861 #define GIVE_UP(X) return 0
15864 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15866 /* Don't use this for mini-windows because these can show
15867 messages and mini-buffers, and we don't handle that here. */
15868 if (MINI_WINDOW_P (w
))
15871 /* This flag is used to prevent redisplay optimizations. */
15872 if (windows_or_buffers_changed
|| cursor_type_changed
)
15875 /* Verify that narrowing has not changed.
15876 Also verify that we were not told to prevent redisplay optimizations.
15877 It would be nice to further
15878 reduce the number of cases where this prevents try_window_id. */
15879 if (current_buffer
->clip_changed
15880 || current_buffer
->prevent_redisplay_optimizations_p
)
15883 /* Window must either use window-based redisplay or be full width. */
15884 if (!FRAME_WINDOW_P (f
)
15885 && (!FRAME_LINE_INS_DEL_OK (f
)
15886 || !WINDOW_FULL_WIDTH_P (w
)))
15889 /* Give up if point is known NOT to appear in W. */
15890 if (PT
< CHARPOS (start
))
15893 /* Another way to prevent redisplay optimizations. */
15894 if (XFASTINT (w
->last_modified
) == 0)
15897 /* Verify that window is not hscrolled. */
15898 if (XFASTINT (w
->hscroll
) != 0)
15901 /* Verify that display wasn't paused. */
15902 if (NILP (w
->window_end_valid
))
15905 /* Can't use this if highlighting a region because a cursor movement
15906 will do more than just set the cursor. */
15907 if (!NILP (Vtransient_mark_mode
)
15908 && !NILP (BVAR (current_buffer
, mark_active
)))
15911 /* Likewise if highlighting trailing whitespace. */
15912 if (!NILP (Vshow_trailing_whitespace
))
15915 /* Likewise if showing a region. */
15916 if (!NILP (w
->region_showing
))
15919 /* Can't use this if overlay arrow position and/or string have
15921 if (overlay_arrows_changed_p ())
15924 /* When word-wrap is on, adding a space to the first word of a
15925 wrapped line can change the wrap position, altering the line
15926 above it. It might be worthwhile to handle this more
15927 intelligently, but for now just redisplay from scratch. */
15928 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
15931 /* Under bidi reordering, adding or deleting a character in the
15932 beginning of a paragraph, before the first strong directional
15933 character, can change the base direction of the paragraph (unless
15934 the buffer specifies a fixed paragraph direction), which will
15935 require to redisplay the whole paragraph. It might be worthwhile
15936 to find the paragraph limits and widen the range of redisplayed
15937 lines to that, but for now just give up this optimization and
15938 redisplay from scratch. */
15939 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15940 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
15943 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15944 only if buffer has really changed. The reason is that the gap is
15945 initially at Z for freshly visited files. The code below would
15946 set end_unchanged to 0 in that case. */
15947 if (MODIFF
> SAVE_MODIFF
15948 /* This seems to happen sometimes after saving a buffer. */
15949 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15951 if (GPT
- BEG
< BEG_UNCHANGED
)
15952 BEG_UNCHANGED
= GPT
- BEG
;
15953 if (Z
- GPT
< END_UNCHANGED
)
15954 END_UNCHANGED
= Z
- GPT
;
15957 /* The position of the first and last character that has been changed. */
15958 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15959 last_changed_charpos
= Z
- END_UNCHANGED
;
15961 /* If window starts after a line end, and the last change is in
15962 front of that newline, then changes don't affect the display.
15963 This case happens with stealth-fontification. Note that although
15964 the display is unchanged, glyph positions in the matrix have to
15965 be adjusted, of course. */
15966 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15967 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15968 && ((last_changed_charpos
< CHARPOS (start
)
15969 && CHARPOS (start
) == BEGV
)
15970 || (last_changed_charpos
< CHARPOS (start
) - 1
15971 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15973 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
15974 struct glyph_row
*r0
;
15976 /* Compute how many chars/bytes have been added to or removed
15977 from the buffer. */
15978 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15979 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15980 Z_delta
= Z
- Z_old
;
15981 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15983 /* Give up if PT is not in the window. Note that it already has
15984 been checked at the start of try_window_id that PT is not in
15985 front of the window start. */
15986 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
15989 /* If window start is unchanged, we can reuse the whole matrix
15990 as is, after adjusting glyph positions. No need to compute
15991 the window end again, since its offset from Z hasn't changed. */
15992 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15993 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
15994 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
15995 /* PT must not be in a partially visible line. */
15996 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
15997 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15999 /* Adjust positions in the glyph matrix. */
16000 if (Z_delta
|| Z_delta_bytes
)
16002 struct glyph_row
*r1
16003 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16004 increment_matrix_positions (w
->current_matrix
,
16005 MATRIX_ROW_VPOS (r0
, current_matrix
),
16006 MATRIX_ROW_VPOS (r1
, current_matrix
),
16007 Z_delta
, Z_delta_bytes
);
16010 /* Set the cursor. */
16011 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16013 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16020 /* Handle the case that changes are all below what is displayed in
16021 the window, and that PT is in the window. This shortcut cannot
16022 be taken if ZV is visible in the window, and text has been added
16023 there that is visible in the window. */
16024 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16025 /* ZV is not visible in the window, or there are no
16026 changes at ZV, actually. */
16027 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
16028 || first_changed_charpos
== last_changed_charpos
))
16030 struct glyph_row
*r0
;
16032 /* Give up if PT is not in the window. Note that it already has
16033 been checked at the start of try_window_id that PT is not in
16034 front of the window start. */
16035 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
16038 /* If window start is unchanged, we can reuse the whole matrix
16039 as is, without changing glyph positions since no text has
16040 been added/removed in front of the window end. */
16041 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16042 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
16043 /* PT must not be in a partially visible line. */
16044 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
16045 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16047 /* We have to compute the window end anew since text
16048 could have been added/removed after it. */
16050 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16051 w
->window_end_bytepos
16052 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16054 /* Set the cursor. */
16055 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16057 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16064 /* Give up if window start is in the changed area.
16066 The condition used to read
16068 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
16070 but why that was tested escapes me at the moment. */
16071 if (CHARPOS (start
) >= first_changed_charpos
16072 && CHARPOS (start
) <= last_changed_charpos
)
16075 /* Check that window start agrees with the start of the first glyph
16076 row in its current matrix. Check this after we know the window
16077 start is not in changed text, otherwise positions would not be
16079 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16080 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
16083 /* Give up if the window ends in strings. Overlay strings
16084 at the end are difficult to handle, so don't try. */
16085 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
16086 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
16089 /* Compute the position at which we have to start displaying new
16090 lines. Some of the lines at the top of the window might be
16091 reusable because they are not displaying changed text. Find the
16092 last row in W's current matrix not affected by changes at the
16093 start of current_buffer. Value is null if changes start in the
16094 first line of window. */
16095 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
16096 if (last_unchanged_at_beg_row
)
16098 /* Avoid starting to display in the moddle of a character, a TAB
16099 for instance. This is easier than to set up the iterator
16100 exactly, and it's not a frequent case, so the additional
16101 effort wouldn't really pay off. */
16102 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
16103 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
16104 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
16105 --last_unchanged_at_beg_row
;
16107 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
16110 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
16112 start_pos
= it
.current
.pos
;
16114 /* Start displaying new lines in the desired matrix at the same
16115 vpos we would use in the current matrix, i.e. below
16116 last_unchanged_at_beg_row. */
16117 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
16119 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16120 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
16122 xassert (it
.hpos
== 0 && it
.current_x
== 0);
16126 /* There are no reusable lines at the start of the window.
16127 Start displaying in the first text line. */
16128 start_display (&it
, w
, start
);
16129 it
.vpos
= it
.first_vpos
;
16130 start_pos
= it
.current
.pos
;
16133 /* Find the first row that is not affected by changes at the end of
16134 the buffer. Value will be null if there is no unchanged row, in
16135 which case we must redisplay to the end of the window. delta
16136 will be set to the value by which buffer positions beginning with
16137 first_unchanged_at_end_row have to be adjusted due to text
16139 first_unchanged_at_end_row
16140 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
16141 IF_DEBUG (debug_delta
= delta
);
16142 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
16144 /* Set stop_pos to the buffer position up to which we will have to
16145 display new lines. If first_unchanged_at_end_row != NULL, this
16146 is the buffer position of the start of the line displayed in that
16147 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
16148 that we don't stop at a buffer position. */
16150 if (first_unchanged_at_end_row
)
16152 xassert (last_unchanged_at_beg_row
== NULL
16153 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
16155 /* If this is a continuation line, move forward to the next one
16156 that isn't. Changes in lines above affect this line.
16157 Caution: this may move first_unchanged_at_end_row to a row
16158 not displaying text. */
16159 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
16160 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16161 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16162 < it
.last_visible_y
))
16163 ++first_unchanged_at_end_row
;
16165 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16166 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16167 >= it
.last_visible_y
))
16168 first_unchanged_at_end_row
= NULL
;
16171 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
16173 first_unchanged_at_end_vpos
16174 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
16175 xassert (stop_pos
>= Z
- END_UNCHANGED
);
16178 else if (last_unchanged_at_beg_row
== NULL
)
16184 /* Either there is no unchanged row at the end, or the one we have
16185 now displays text. This is a necessary condition for the window
16186 end pos calculation at the end of this function. */
16187 xassert (first_unchanged_at_end_row
== NULL
16188 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
16190 debug_last_unchanged_at_beg_vpos
16191 = (last_unchanged_at_beg_row
16192 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
16194 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
16196 #endif /* GLYPH_DEBUG != 0 */
16199 /* Display new lines. Set last_text_row to the last new line
16200 displayed which has text on it, i.e. might end up as being the
16201 line where the window_end_vpos is. */
16202 w
->cursor
.vpos
= -1;
16203 last_text_row
= NULL
;
16204 overlay_arrow_seen
= 0;
16205 while (it
.current_y
< it
.last_visible_y
16206 && !fonts_changed_p
16207 && (first_unchanged_at_end_row
== NULL
16208 || IT_CHARPOS (it
) < stop_pos
))
16210 if (display_line (&it
))
16211 last_text_row
= it
.glyph_row
- 1;
16214 if (fonts_changed_p
)
16218 /* Compute differences in buffer positions, y-positions etc. for
16219 lines reused at the bottom of the window. Compute what we can
16221 if (first_unchanged_at_end_row
16222 /* No lines reused because we displayed everything up to the
16223 bottom of the window. */
16224 && it
.current_y
< it
.last_visible_y
)
16227 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
16229 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
16230 run
.current_y
= first_unchanged_at_end_row
->y
;
16231 run
.desired_y
= run
.current_y
+ dy
;
16232 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16236 delta
= delta_bytes
= dvpos
= dy
16237 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16238 first_unchanged_at_end_row
= NULL
;
16240 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16243 /* Find the cursor if not already found. We have to decide whether
16244 PT will appear on this window (it sometimes doesn't, but this is
16245 not a very frequent case.) This decision has to be made before
16246 the current matrix is altered. A value of cursor.vpos < 0 means
16247 that PT is either in one of the lines beginning at
16248 first_unchanged_at_end_row or below the window. Don't care for
16249 lines that might be displayed later at the window end; as
16250 mentioned, this is not a frequent case. */
16251 if (w
->cursor
.vpos
< 0)
16253 /* Cursor in unchanged rows at the top? */
16254 if (PT
< CHARPOS (start_pos
)
16255 && last_unchanged_at_beg_row
)
16257 row
= row_containing_pos (w
, PT
,
16258 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16259 last_unchanged_at_beg_row
+ 1, 0);
16261 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16264 /* Start from first_unchanged_at_end_row looking for PT. */
16265 else if (first_unchanged_at_end_row
)
16267 row
= row_containing_pos (w
, PT
- delta
,
16268 first_unchanged_at_end_row
, NULL
, 0);
16270 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16271 delta_bytes
, dy
, dvpos
);
16274 /* Give up if cursor was not found. */
16275 if (w
->cursor
.vpos
< 0)
16277 clear_glyph_matrix (w
->desired_matrix
);
16282 /* Don't let the cursor end in the scroll margins. */
16284 int this_scroll_margin
, cursor_height
;
16286 this_scroll_margin
= max (0, scroll_margin
);
16287 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16288 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16289 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16291 if ((w
->cursor
.y
< this_scroll_margin
16292 && CHARPOS (start
) > BEGV
)
16293 /* Old redisplay didn't take scroll margin into account at the bottom,
16294 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16295 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16296 ? cursor_height
+ this_scroll_margin
16297 : 1)) > it
.last_visible_y
)
16299 w
->cursor
.vpos
= -1;
16300 clear_glyph_matrix (w
->desired_matrix
);
16305 /* Scroll the display. Do it before changing the current matrix so
16306 that xterm.c doesn't get confused about where the cursor glyph is
16308 if (dy
&& run
.height
)
16312 if (FRAME_WINDOW_P (f
))
16314 FRAME_RIF (f
)->update_window_begin_hook (w
);
16315 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16316 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16317 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16321 /* Terminal frame. In this case, dvpos gives the number of
16322 lines to scroll by; dvpos < 0 means scroll up. */
16324 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16325 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16326 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16327 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16328 + window_internal_height (w
));
16330 #if defined (HAVE_GPM) || defined (MSDOS)
16331 x_clear_window_mouse_face (w
);
16333 /* Perform the operation on the screen. */
16336 /* Scroll last_unchanged_at_beg_row to the end of the
16337 window down dvpos lines. */
16338 set_terminal_window (f
, end
);
16340 /* On dumb terminals delete dvpos lines at the end
16341 before inserting dvpos empty lines. */
16342 if (!FRAME_SCROLL_REGION_OK (f
))
16343 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16345 /* Insert dvpos empty lines in front of
16346 last_unchanged_at_beg_row. */
16347 ins_del_lines (f
, from
, dvpos
);
16349 else if (dvpos
< 0)
16351 /* Scroll up last_unchanged_at_beg_vpos to the end of
16352 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16353 set_terminal_window (f
, end
);
16355 /* Delete dvpos lines in front of
16356 last_unchanged_at_beg_vpos. ins_del_lines will set
16357 the cursor to the given vpos and emit |dvpos| delete
16359 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16361 /* On a dumb terminal insert dvpos empty lines at the
16363 if (!FRAME_SCROLL_REGION_OK (f
))
16364 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16367 set_terminal_window (f
, 0);
16373 /* Shift reused rows of the current matrix to the right position.
16374 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16376 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16377 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16380 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16381 bottom_vpos
, dvpos
);
16382 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16385 else if (dvpos
> 0)
16387 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16388 bottom_vpos
, dvpos
);
16389 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16390 first_unchanged_at_end_vpos
+ dvpos
, 0);
16393 /* For frame-based redisplay, make sure that current frame and window
16394 matrix are in sync with respect to glyph memory. */
16395 if (!FRAME_WINDOW_P (f
))
16396 sync_frame_with_window_matrix_rows (w
);
16398 /* Adjust buffer positions in reused rows. */
16399 if (delta
|| delta_bytes
)
16400 increment_matrix_positions (current_matrix
,
16401 first_unchanged_at_end_vpos
+ dvpos
,
16402 bottom_vpos
, delta
, delta_bytes
);
16404 /* Adjust Y positions. */
16406 shift_glyph_matrix (w
, current_matrix
,
16407 first_unchanged_at_end_vpos
+ dvpos
,
16410 if (first_unchanged_at_end_row
)
16412 first_unchanged_at_end_row
+= dvpos
;
16413 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16414 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16415 first_unchanged_at_end_row
= NULL
;
16418 /* If scrolling up, there may be some lines to display at the end of
16420 last_text_row_at_end
= NULL
;
16423 /* Scrolling up can leave for example a partially visible line
16424 at the end of the window to be redisplayed. */
16425 /* Set last_row to the glyph row in the current matrix where the
16426 window end line is found. It has been moved up or down in
16427 the matrix by dvpos. */
16428 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16429 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16431 /* If last_row is the window end line, it should display text. */
16432 xassert (last_row
->displays_text_p
);
16434 /* If window end line was partially visible before, begin
16435 displaying at that line. Otherwise begin displaying with the
16436 line following it. */
16437 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16439 init_to_row_start (&it
, w
, last_row
);
16440 it
.vpos
= last_vpos
;
16441 it
.current_y
= last_row
->y
;
16445 init_to_row_end (&it
, w
, last_row
);
16446 it
.vpos
= 1 + last_vpos
;
16447 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16451 /* We may start in a continuation line. If so, we have to
16452 get the right continuation_lines_width and current_x. */
16453 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16454 it
.hpos
= it
.current_x
= 0;
16456 /* Display the rest of the lines at the window end. */
16457 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16458 while (it
.current_y
< it
.last_visible_y
16459 && !fonts_changed_p
)
16461 /* Is it always sure that the display agrees with lines in
16462 the current matrix? I don't think so, so we mark rows
16463 displayed invalid in the current matrix by setting their
16464 enabled_p flag to zero. */
16465 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16466 if (display_line (&it
))
16467 last_text_row_at_end
= it
.glyph_row
- 1;
16471 /* Update window_end_pos and window_end_vpos. */
16472 if (first_unchanged_at_end_row
16473 && !last_text_row_at_end
)
16475 /* Window end line if one of the preserved rows from the current
16476 matrix. Set row to the last row displaying text in current
16477 matrix starting at first_unchanged_at_end_row, after
16479 xassert (first_unchanged_at_end_row
->displays_text_p
);
16480 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16481 first_unchanged_at_end_row
);
16482 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16484 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16485 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16487 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16488 xassert (w
->window_end_bytepos
>= 0);
16489 IF_DEBUG (debug_method_add (w
, "A"));
16491 else if (last_text_row_at_end
)
16494 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16495 w
->window_end_bytepos
16496 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16498 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16499 xassert (w
->window_end_bytepos
>= 0);
16500 IF_DEBUG (debug_method_add (w
, "B"));
16502 else if (last_text_row
)
16504 /* We have displayed either to the end of the window or at the
16505 end of the window, i.e. the last row with text is to be found
16506 in the desired matrix. */
16508 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16509 w
->window_end_bytepos
16510 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16512 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16513 xassert (w
->window_end_bytepos
>= 0);
16515 else if (first_unchanged_at_end_row
== NULL
16516 && last_text_row
== NULL
16517 && last_text_row_at_end
== NULL
)
16519 /* Displayed to end of window, but no line containing text was
16520 displayed. Lines were deleted at the end of the window. */
16521 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16522 int vpos
= XFASTINT (w
->window_end_vpos
);
16523 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16524 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16527 row
== NULL
&& vpos
>= first_vpos
;
16528 --vpos
, --current_row
, --desired_row
)
16530 if (desired_row
->enabled_p
)
16532 if (desired_row
->displays_text_p
)
16535 else if (current_row
->displays_text_p
)
16539 xassert (row
!= NULL
);
16540 w
->window_end_vpos
= make_number (vpos
+ 1);
16541 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16542 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16543 xassert (w
->window_end_bytepos
>= 0);
16544 IF_DEBUG (debug_method_add (w
, "C"));
16549 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16550 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16552 /* Record that display has not been completed. */
16553 w
->window_end_valid
= Qnil
;
16554 w
->desired_matrix
->no_scrolling_p
= 1;
16562 /***********************************************************************
16563 More debugging support
16564 ***********************************************************************/
16568 void dump_glyph_row (struct glyph_row
*, int, int);
16569 void dump_glyph_matrix (struct glyph_matrix
*, int);
16570 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16573 /* Dump the contents of glyph matrix MATRIX on stderr.
16575 GLYPHS 0 means don't show glyph contents.
16576 GLYPHS 1 means show glyphs in short form
16577 GLYPHS > 1 means show glyphs in long form. */
16580 dump_glyph_matrix (matrix
, glyphs
)
16581 struct glyph_matrix
*matrix
;
16585 for (i
= 0; i
< matrix
->nrows
; ++i
)
16586 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16590 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16591 the glyph row and area where the glyph comes from. */
16594 dump_glyph (row
, glyph
, area
)
16595 struct glyph_row
*row
;
16596 struct glyph
*glyph
;
16599 if (glyph
->type
== CHAR_GLYPH
)
16602 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16603 glyph
- row
->glyphs
[TEXT_AREA
],
16606 (BUFFERP (glyph
->object
)
16608 : (STRINGP (glyph
->object
)
16611 glyph
->pixel_width
,
16613 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16617 glyph
->left_box_line_p
,
16618 glyph
->right_box_line_p
);
16620 else if (glyph
->type
== STRETCH_GLYPH
)
16623 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16624 glyph
- row
->glyphs
[TEXT_AREA
],
16627 (BUFFERP (glyph
->object
)
16629 : (STRINGP (glyph
->object
)
16632 glyph
->pixel_width
,
16636 glyph
->left_box_line_p
,
16637 glyph
->right_box_line_p
);
16639 else if (glyph
->type
== IMAGE_GLYPH
)
16642 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16643 glyph
- row
->glyphs
[TEXT_AREA
],
16646 (BUFFERP (glyph
->object
)
16648 : (STRINGP (glyph
->object
)
16651 glyph
->pixel_width
,
16655 glyph
->left_box_line_p
,
16656 glyph
->right_box_line_p
);
16658 else if (glyph
->type
== COMPOSITE_GLYPH
)
16661 " %5d %4c %6d %c %3d 0x%05x",
16662 glyph
- row
->glyphs
[TEXT_AREA
],
16665 (BUFFERP (glyph
->object
)
16667 : (STRINGP (glyph
->object
)
16670 glyph
->pixel_width
,
16672 if (glyph
->u
.cmp
.automatic
)
16675 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16676 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16678 glyph
->left_box_line_p
,
16679 glyph
->right_box_line_p
);
16684 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16685 GLYPHS 0 means don't show glyph contents.
16686 GLYPHS 1 means show glyphs in short form
16687 GLYPHS > 1 means show glyphs in long form. */
16690 dump_glyph_row (row
, vpos
, glyphs
)
16691 struct glyph_row
*row
;
16696 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16697 fprintf (stderr
, "======================================================================\n");
16699 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16700 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16702 MATRIX_ROW_START_CHARPOS (row
),
16703 MATRIX_ROW_END_CHARPOS (row
),
16704 row
->used
[TEXT_AREA
],
16705 row
->contains_overlapping_glyphs_p
,
16707 row
->truncated_on_left_p
,
16708 row
->truncated_on_right_p
,
16710 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16711 row
->displays_text_p
,
16714 row
->ends_in_middle_of_char_p
,
16715 row
->starts_in_middle_of_char_p
,
16721 row
->visible_height
,
16724 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16725 row
->end
.overlay_string_index
,
16726 row
->continuation_lines_width
);
16727 fprintf (stderr
, "%9d %5d\n",
16728 CHARPOS (row
->start
.string_pos
),
16729 CHARPOS (row
->end
.string_pos
));
16730 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16731 row
->end
.dpvec_index
);
16738 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16740 struct glyph
*glyph
= row
->glyphs
[area
];
16741 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16743 /* Glyph for a line end in text. */
16744 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16747 if (glyph
< glyph_end
)
16748 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16750 for (; glyph
< glyph_end
; ++glyph
)
16751 dump_glyph (row
, glyph
, area
);
16754 else if (glyphs
== 1)
16758 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16760 char *s
= (char *) alloca (row
->used
[area
] + 1);
16763 for (i
= 0; i
< row
->used
[area
]; ++i
)
16765 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16766 if (glyph
->type
== CHAR_GLYPH
16767 && glyph
->u
.ch
< 0x80
16768 && glyph
->u
.ch
>= ' ')
16769 s
[i
] = glyph
->u
.ch
;
16775 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16781 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16782 Sdump_glyph_matrix
, 0, 1, "p",
16783 doc
: /* Dump the current matrix of the selected window to stderr.
16784 Shows contents of glyph row structures. With non-nil
16785 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16786 glyphs in short form, otherwise show glyphs in long form. */)
16787 (Lisp_Object glyphs
)
16789 struct window
*w
= XWINDOW (selected_window
);
16790 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16792 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16793 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16794 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16795 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16796 fprintf (stderr
, "=============================================\n");
16797 dump_glyph_matrix (w
->current_matrix
,
16798 NILP (glyphs
) ? 0 : XINT (glyphs
));
16803 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16804 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16807 struct frame
*f
= XFRAME (selected_frame
);
16808 dump_glyph_matrix (f
->current_matrix
, 1);
16813 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16814 doc
: /* Dump glyph row ROW to stderr.
16815 GLYPH 0 means don't dump glyphs.
16816 GLYPH 1 means dump glyphs in short form.
16817 GLYPH > 1 or omitted means dump glyphs in long form. */)
16818 (Lisp_Object row
, Lisp_Object glyphs
)
16820 struct glyph_matrix
*matrix
;
16823 CHECK_NUMBER (row
);
16824 matrix
= XWINDOW (selected_window
)->current_matrix
;
16826 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16827 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16829 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16834 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16835 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16836 GLYPH 0 means don't dump glyphs.
16837 GLYPH 1 means dump glyphs in short form.
16838 GLYPH > 1 or omitted means dump glyphs in long form. */)
16839 (Lisp_Object row
, Lisp_Object glyphs
)
16841 struct frame
*sf
= SELECTED_FRAME ();
16842 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16845 CHECK_NUMBER (row
);
16847 if (vpos
>= 0 && vpos
< m
->nrows
)
16848 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16849 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16854 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16855 doc
: /* Toggle tracing of redisplay.
16856 With ARG, turn tracing on if and only if ARG is positive. */)
16860 trace_redisplay_p
= !trace_redisplay_p
;
16863 arg
= Fprefix_numeric_value (arg
);
16864 trace_redisplay_p
= XINT (arg
) > 0;
16871 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16872 doc
: /* Like `format', but print result to stderr.
16873 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16874 (size_t nargs
, Lisp_Object
*args
)
16876 Lisp_Object s
= Fformat (nargs
, args
);
16877 fprintf (stderr
, "%s", SDATA (s
));
16881 #endif /* GLYPH_DEBUG */
16885 /***********************************************************************
16886 Building Desired Matrix Rows
16887 ***********************************************************************/
16889 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16890 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16892 static struct glyph_row
*
16893 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16895 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16896 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16897 struct buffer
*old
= current_buffer
;
16898 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16899 int arrow_len
= SCHARS (overlay_arrow_string
);
16900 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16901 const unsigned char *p
;
16904 int n_glyphs_before
;
16906 set_buffer_temp (buffer
);
16907 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16908 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16909 SET_TEXT_POS (it
.position
, 0, 0);
16911 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
16913 while (p
< arrow_end
)
16915 Lisp_Object face
, ilisp
;
16917 /* Get the next character. */
16919 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16922 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16923 if (! ASCII_CHAR_P (it
.c
))
16924 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16928 /* Get its face. */
16929 ilisp
= make_number (p
- arrow_string
);
16930 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16931 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16933 /* Compute its width, get its glyphs. */
16934 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16935 SET_TEXT_POS (it
.position
, -1, -1);
16936 PRODUCE_GLYPHS (&it
);
16938 /* If this character doesn't fit any more in the line, we have
16939 to remove some glyphs. */
16940 if (it
.current_x
> it
.last_visible_x
)
16942 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16947 set_buffer_temp (old
);
16948 return it
.glyph_row
;
16952 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16953 glyphs are only inserted for terminal frames since we can't really
16954 win with truncation glyphs when partially visible glyphs are
16955 involved. Which glyphs to insert is determined by
16956 produce_special_glyphs. */
16959 insert_left_trunc_glyphs (struct it
*it
)
16961 struct it truncate_it
;
16962 struct glyph
*from
, *end
, *to
, *toend
;
16964 xassert (!FRAME_WINDOW_P (it
->f
));
16966 /* Get the truncation glyphs. */
16968 truncate_it
.current_x
= 0;
16969 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16970 truncate_it
.glyph_row
= &scratch_glyph_row
;
16971 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16972 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16973 truncate_it
.object
= make_number (0);
16974 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16976 /* Overwrite glyphs from IT with truncation glyphs. */
16977 if (!it
->glyph_row
->reversed_p
)
16979 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16980 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16981 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16982 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16987 /* There may be padding glyphs left over. Overwrite them too. */
16988 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16990 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16996 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17000 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17001 that back to front. */
17002 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17003 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17004 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17005 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17007 while (from
>= end
&& to
>= toend
)
17009 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17012 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17013 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17014 while (from
>= end
&& to
>= toend
)
17019 /* Need to free some room before prepending additional
17021 int move_by
= from
- end
+ 1;
17022 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17023 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17025 for ( ; g
>= g0
; g
--)
17027 while (from
>= end
)
17029 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
17035 /* Compute the pixel height and width of IT->glyph_row.
17037 Most of the time, ascent and height of a display line will be equal
17038 to the max_ascent and max_height values of the display iterator
17039 structure. This is not the case if
17041 1. We hit ZV without displaying anything. In this case, max_ascent
17042 and max_height will be zero.
17044 2. We have some glyphs that don't contribute to the line height.
17045 (The glyph row flag contributes_to_line_height_p is for future
17046 pixmap extensions).
17048 The first case is easily covered by using default values because in
17049 these cases, the line height does not really matter, except that it
17050 must not be zero. */
17053 compute_line_metrics (struct it
*it
)
17055 struct glyph_row
*row
= it
->glyph_row
;
17057 if (FRAME_WINDOW_P (it
->f
))
17059 int i
, min_y
, max_y
;
17061 /* The line may consist of one space only, that was added to
17062 place the cursor on it. If so, the row's height hasn't been
17064 if (row
->height
== 0)
17066 if (it
->max_ascent
+ it
->max_descent
== 0)
17067 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
17068 row
->ascent
= it
->max_ascent
;
17069 row
->height
= it
->max_ascent
+ it
->max_descent
;
17070 row
->phys_ascent
= it
->max_phys_ascent
;
17071 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17072 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17075 /* Compute the width of this line. */
17076 row
->pixel_width
= row
->x
;
17077 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
17078 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
17080 xassert (row
->pixel_width
>= 0);
17081 xassert (row
->ascent
>= 0 && row
->height
> 0);
17083 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
17084 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
17086 /* If first line's physical ascent is larger than its logical
17087 ascent, use the physical ascent, and make the row taller.
17088 This makes accented characters fully visible. */
17089 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
17090 && row
->phys_ascent
> row
->ascent
)
17092 row
->height
+= row
->phys_ascent
- row
->ascent
;
17093 row
->ascent
= row
->phys_ascent
;
17096 /* Compute how much of the line is visible. */
17097 row
->visible_height
= row
->height
;
17099 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
17100 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
17102 if (row
->y
< min_y
)
17103 row
->visible_height
-= min_y
- row
->y
;
17104 if (row
->y
+ row
->height
> max_y
)
17105 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17109 row
->pixel_width
= row
->used
[TEXT_AREA
];
17110 if (row
->continued_p
)
17111 row
->pixel_width
-= it
->continuation_pixel_width
;
17112 else if (row
->truncated_on_right_p
)
17113 row
->pixel_width
-= it
->truncation_pixel_width
;
17114 row
->ascent
= row
->phys_ascent
= 0;
17115 row
->height
= row
->phys_height
= row
->visible_height
= 1;
17116 row
->extra_line_spacing
= 0;
17119 /* Compute a hash code for this row. */
17123 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17124 for (i
= 0; i
< row
->used
[area
]; ++i
)
17125 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
17126 + row
->glyphs
[area
][i
].u
.val
17127 + row
->glyphs
[area
][i
].face_id
17128 + row
->glyphs
[area
][i
].padding_p
17129 + (row
->glyphs
[area
][i
].type
<< 2));
17132 it
->max_ascent
= it
->max_descent
= 0;
17133 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
17137 /* Append one space to the glyph row of iterator IT if doing a
17138 window-based redisplay. The space has the same face as
17139 IT->face_id. Value is non-zero if a space was added.
17141 This function is called to make sure that there is always one glyph
17142 at the end of a glyph row that the cursor can be set on under
17143 window-systems. (If there weren't such a glyph we would not know
17144 how wide and tall a box cursor should be displayed).
17146 At the same time this space let's a nicely handle clearing to the
17147 end of the line if the row ends in italic text. */
17150 append_space_for_newline (struct it
*it
, int default_face_p
)
17152 if (FRAME_WINDOW_P (it
->f
))
17154 int n
= it
->glyph_row
->used
[TEXT_AREA
];
17156 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
17157 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
17159 /* Save some values that must not be changed.
17160 Must save IT->c and IT->len because otherwise
17161 ITERATOR_AT_END_P wouldn't work anymore after
17162 append_space_for_newline has been called. */
17163 enum display_element_type saved_what
= it
->what
;
17164 int saved_c
= it
->c
, saved_len
= it
->len
;
17165 int saved_char_to_display
= it
->char_to_display
;
17166 int saved_x
= it
->current_x
;
17167 int saved_face_id
= it
->face_id
;
17168 struct text_pos saved_pos
;
17169 Lisp_Object saved_object
;
17172 saved_object
= it
->object
;
17173 saved_pos
= it
->position
;
17175 it
->what
= IT_CHARACTER
;
17176 memset (&it
->position
, 0, sizeof it
->position
);
17177 it
->object
= make_number (0);
17178 it
->c
= it
->char_to_display
= ' ';
17181 if (default_face_p
)
17182 it
->face_id
= DEFAULT_FACE_ID
;
17183 else if (it
->face_before_selective_p
)
17184 it
->face_id
= it
->saved_face_id
;
17185 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17186 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
17188 PRODUCE_GLYPHS (it
);
17190 it
->override_ascent
= -1;
17191 it
->constrain_row_ascent_descent_p
= 0;
17192 it
->current_x
= saved_x
;
17193 it
->object
= saved_object
;
17194 it
->position
= saved_pos
;
17195 it
->what
= saved_what
;
17196 it
->face_id
= saved_face_id
;
17197 it
->len
= saved_len
;
17199 it
->char_to_display
= saved_char_to_display
;
17208 /* Extend the face of the last glyph in the text area of IT->glyph_row
17209 to the end of the display line. Called from display_line. If the
17210 glyph row is empty, add a space glyph to it so that we know the
17211 face to draw. Set the glyph row flag fill_line_p. If the glyph
17212 row is R2L, prepend a stretch glyph to cover the empty space to the
17213 left of the leftmost glyph. */
17216 extend_face_to_end_of_line (struct it
*it
)
17219 struct frame
*f
= it
->f
;
17221 /* If line is already filled, do nothing. Non window-system frames
17222 get a grace of one more ``pixel'' because their characters are
17223 1-``pixel'' wide, so they hit the equality too early. This grace
17224 is needed only for R2L rows that are not continued, to produce
17225 one extra blank where we could display the cursor. */
17226 if (it
->current_x
>= it
->last_visible_x
17227 + (!FRAME_WINDOW_P (f
)
17228 && it
->glyph_row
->reversed_p
17229 && !it
->glyph_row
->continued_p
))
17232 /* Face extension extends the background and box of IT->face_id
17233 to the end of the line. If the background equals the background
17234 of the frame, we don't have to do anything. */
17235 if (it
->face_before_selective_p
)
17236 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17238 face
= FACE_FROM_ID (f
, it
->face_id
);
17240 if (FRAME_WINDOW_P (f
)
17241 && it
->glyph_row
->displays_text_p
17242 && face
->box
== FACE_NO_BOX
17243 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17245 && !it
->glyph_row
->reversed_p
)
17248 /* Set the glyph row flag indicating that the face of the last glyph
17249 in the text area has to be drawn to the end of the text area. */
17250 it
->glyph_row
->fill_line_p
= 1;
17252 /* If current character of IT is not ASCII, make sure we have the
17253 ASCII face. This will be automatically undone the next time
17254 get_next_display_element returns a multibyte character. Note
17255 that the character will always be single byte in unibyte
17257 if (!ASCII_CHAR_P (it
->c
))
17259 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17262 if (FRAME_WINDOW_P (f
))
17264 /* If the row is empty, add a space with the current face of IT,
17265 so that we know which face to draw. */
17266 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17268 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17269 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17270 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17272 #ifdef HAVE_WINDOW_SYSTEM
17273 if (it
->glyph_row
->reversed_p
)
17275 /* Prepend a stretch glyph to the row, such that the
17276 rightmost glyph will be drawn flushed all the way to the
17277 right margin of the window. The stretch glyph that will
17278 occupy the empty space, if any, to the left of the
17280 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17281 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17282 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17284 int row_width
, stretch_ascent
, stretch_width
;
17285 struct text_pos saved_pos
;
17286 int saved_face_id
, saved_avoid_cursor
;
17288 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17289 row_width
+= g
->pixel_width
;
17290 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17291 if (stretch_width
> 0)
17294 (((it
->ascent
+ it
->descent
)
17295 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17296 saved_pos
= it
->position
;
17297 memset (&it
->position
, 0, sizeof it
->position
);
17298 saved_avoid_cursor
= it
->avoid_cursor_p
;
17299 it
->avoid_cursor_p
= 1;
17300 saved_face_id
= it
->face_id
;
17301 /* The last row's stretch glyph should get the default
17302 face, to avoid painting the rest of the window with
17303 the region face, if the region ends at ZV. */
17304 if (it
->glyph_row
->ends_at_zv_p
)
17305 it
->face_id
= DEFAULT_FACE_ID
;
17307 it
->face_id
= face
->id
;
17308 append_stretch_glyph (it
, make_number (0), stretch_width
,
17309 it
->ascent
+ it
->descent
, stretch_ascent
);
17310 it
->position
= saved_pos
;
17311 it
->avoid_cursor_p
= saved_avoid_cursor
;
17312 it
->face_id
= saved_face_id
;
17315 #endif /* HAVE_WINDOW_SYSTEM */
17319 /* Save some values that must not be changed. */
17320 int saved_x
= it
->current_x
;
17321 struct text_pos saved_pos
;
17322 Lisp_Object saved_object
;
17323 enum display_element_type saved_what
= it
->what
;
17324 int saved_face_id
= it
->face_id
;
17326 saved_object
= it
->object
;
17327 saved_pos
= it
->position
;
17329 it
->what
= IT_CHARACTER
;
17330 memset (&it
->position
, 0, sizeof it
->position
);
17331 it
->object
= make_number (0);
17332 it
->c
= it
->char_to_display
= ' ';
17334 /* The last row's blank glyphs should get the default face, to
17335 avoid painting the rest of the window with the region face,
17336 if the region ends at ZV. */
17337 if (it
->glyph_row
->ends_at_zv_p
)
17338 it
->face_id
= DEFAULT_FACE_ID
;
17340 it
->face_id
= face
->id
;
17342 PRODUCE_GLYPHS (it
);
17344 while (it
->current_x
<= it
->last_visible_x
)
17345 PRODUCE_GLYPHS (it
);
17347 /* Don't count these blanks really. It would let us insert a left
17348 truncation glyph below and make us set the cursor on them, maybe. */
17349 it
->current_x
= saved_x
;
17350 it
->object
= saved_object
;
17351 it
->position
= saved_pos
;
17352 it
->what
= saved_what
;
17353 it
->face_id
= saved_face_id
;
17358 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17359 trailing whitespace. */
17362 trailing_whitespace_p (EMACS_INT charpos
)
17364 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17367 while (bytepos
< ZV_BYTE
17368 && (c
= FETCH_CHAR (bytepos
),
17369 c
== ' ' || c
== '\t'))
17372 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17374 if (bytepos
!= PT_BYTE
)
17381 /* Highlight trailing whitespace, if any, in ROW. */
17384 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17386 int used
= row
->used
[TEXT_AREA
];
17390 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17391 struct glyph
*glyph
= start
+ used
- 1;
17393 if (row
->reversed_p
)
17395 /* Right-to-left rows need to be processed in the opposite
17396 direction, so swap the edge pointers. */
17398 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17401 /* Skip over glyphs inserted to display the cursor at the
17402 end of a line, for extending the face of the last glyph
17403 to the end of the line on terminals, and for truncation
17404 and continuation glyphs. */
17405 if (!row
->reversed_p
)
17407 while (glyph
>= start
17408 && glyph
->type
== CHAR_GLYPH
17409 && INTEGERP (glyph
->object
))
17414 while (glyph
<= start
17415 && glyph
->type
== CHAR_GLYPH
17416 && INTEGERP (glyph
->object
))
17420 /* If last glyph is a space or stretch, and it's trailing
17421 whitespace, set the face of all trailing whitespace glyphs in
17422 IT->glyph_row to `trailing-whitespace'. */
17423 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17424 && BUFFERP (glyph
->object
)
17425 && (glyph
->type
== STRETCH_GLYPH
17426 || (glyph
->type
== CHAR_GLYPH
17427 && glyph
->u
.ch
== ' '))
17428 && trailing_whitespace_p (glyph
->charpos
))
17430 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17434 if (!row
->reversed_p
)
17436 while (glyph
>= start
17437 && BUFFERP (glyph
->object
)
17438 && (glyph
->type
== STRETCH_GLYPH
17439 || (glyph
->type
== CHAR_GLYPH
17440 && glyph
->u
.ch
== ' ')))
17441 (glyph
--)->face_id
= face_id
;
17445 while (glyph
<= start
17446 && BUFFERP (glyph
->object
)
17447 && (glyph
->type
== STRETCH_GLYPH
17448 || (glyph
->type
== CHAR_GLYPH
17449 && glyph
->u
.ch
== ' ')))
17450 (glyph
++)->face_id
= face_id
;
17457 /* Value is non-zero if glyph row ROW should be
17458 used to hold the cursor. */
17461 cursor_row_p (struct glyph_row
*row
)
17465 if (PT
== CHARPOS (row
->end
.pos
))
17467 /* Suppose the row ends on a string.
17468 Unless the row is continued, that means it ends on a newline
17469 in the string. If it's anything other than a display string
17470 (e.g. a before-string from an overlay), we don't want the
17471 cursor there. (This heuristic seems to give the optimal
17472 behavior for the various types of multi-line strings.) */
17473 if (CHARPOS (row
->end
.string_pos
) >= 0)
17475 if (row
->continued_p
)
17479 /* Check for `display' property. */
17480 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17481 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17482 struct glyph
*glyph
;
17485 for (glyph
= end
; glyph
>= beg
; --glyph
)
17486 if (STRINGP (glyph
->object
))
17489 = Fget_char_property (make_number (PT
),
17493 && display_prop_string_p (prop
, glyph
->object
));
17498 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17500 /* If the row ends in middle of a real character,
17501 and the line is continued, we want the cursor here.
17502 That's because CHARPOS (ROW->end.pos) would equal
17503 PT if PT is before the character. */
17504 if (!row
->ends_in_ellipsis_p
)
17505 result
= row
->continued_p
;
17507 /* If the row ends in an ellipsis, then
17508 CHARPOS (ROW->end.pos) will equal point after the
17509 invisible text. We want that position to be displayed
17510 after the ellipsis. */
17513 /* If the row ends at ZV, display the cursor at the end of that
17514 row instead of at the start of the row below. */
17515 else if (row
->ends_at_zv_p
)
17526 /* Push the display property PROP so that it will be rendered at the
17527 current position in IT. Return 1 if PROP was successfully pushed,
17531 push_display_prop (struct it
*it
, Lisp_Object prop
)
17533 push_it (it
, NULL
);
17535 if (STRINGP (prop
))
17537 if (SCHARS (prop
) == 0)
17544 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17545 it
->current
.overlay_string_index
= -1;
17546 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17547 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17548 it
->method
= GET_FROM_STRING
;
17549 it
->stop_charpos
= 0;
17551 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17553 it
->method
= GET_FROM_STRETCH
;
17556 #ifdef HAVE_WINDOW_SYSTEM
17557 else if (IMAGEP (prop
))
17559 it
->what
= IT_IMAGE
;
17560 it
->image_id
= lookup_image (it
->f
, prop
);
17561 it
->method
= GET_FROM_IMAGE
;
17563 #endif /* HAVE_WINDOW_SYSTEM */
17566 pop_it (it
); /* bogus display property, give up */
17573 /* Return the character-property PROP at the current position in IT. */
17576 get_it_property (struct it
*it
, Lisp_Object prop
)
17578 Lisp_Object position
;
17580 if (STRINGP (it
->object
))
17581 position
= make_number (IT_STRING_CHARPOS (*it
));
17582 else if (BUFFERP (it
->object
))
17583 position
= make_number (IT_CHARPOS (*it
));
17587 return Fget_char_property (position
, prop
, it
->object
);
17590 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17593 handle_line_prefix (struct it
*it
)
17595 Lisp_Object prefix
;
17596 if (it
->continuation_lines_width
> 0)
17598 prefix
= get_it_property (it
, Qwrap_prefix
);
17600 prefix
= Vwrap_prefix
;
17604 prefix
= get_it_property (it
, Qline_prefix
);
17606 prefix
= Vline_prefix
;
17608 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17610 /* If the prefix is wider than the window, and we try to wrap
17611 it, it would acquire its own wrap prefix, and so on till the
17612 iterator stack overflows. So, don't wrap the prefix. */
17613 it
->line_wrap
= TRUNCATE
;
17614 it
->avoid_cursor_p
= 1;
17620 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17621 only for R2L lines from display_line and display_string, when they
17622 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
17623 the line/string needs to be continued on the next glyph row. */
17625 unproduce_glyphs (struct it
*it
, int n
)
17627 struct glyph
*glyph
, *end
;
17629 xassert (it
->glyph_row
);
17630 xassert (it
->glyph_row
->reversed_p
);
17631 xassert (it
->area
== TEXT_AREA
);
17632 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17634 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17635 n
= it
->glyph_row
->used
[TEXT_AREA
];
17636 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17637 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17638 for ( ; glyph
< end
; glyph
++)
17639 glyph
[-n
] = *glyph
;
17642 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17643 and ROW->maxpos. */
17645 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17646 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17647 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17649 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17650 lines' rows is implemented for bidi-reordered rows. */
17652 /* ROW->minpos is the value of min_pos, the minimal buffer position
17655 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17657 /* We didn't find _any_ valid buffer positions in any of the
17658 glyphs, so we must trust the iterator's computed positions. */
17659 row
->minpos
= row
->start
.pos
;
17662 max_pos
= CHARPOS (it
->current
.pos
);
17663 max_bpos
= BYTEPOS (it
->current
.pos
);
17666 /* Here are the various use-cases for ending the row, and the
17667 corresponding values for ROW->maxpos:
17669 Line ends in a newline from buffer eol_pos + 1
17670 Line is continued from buffer max_pos + 1
17671 Line is truncated on right it->current.pos
17672 Line ends in a newline from string max_pos
17673 Line is continued from string max_pos
17674 Line is continued from display vector max_pos
17675 Line is entirely from a string min_pos == max_pos
17676 Line is entirely from a display vector min_pos == max_pos
17677 Line that ends at ZV ZV
17679 If you discover other use-cases, please add them here as
17681 if (row
->ends_at_zv_p
)
17682 row
->maxpos
= it
->current
.pos
;
17683 else if (row
->used
[TEXT_AREA
])
17685 if (row
->ends_in_newline_from_string_p
)
17686 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17687 else if (CHARPOS (it
->eol_pos
) > 0)
17688 SET_TEXT_POS (row
->maxpos
,
17689 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17690 else if (row
->continued_p
)
17692 /* If max_pos is different from IT's current position, it
17693 means IT->method does not belong to the display element
17694 at max_pos. However, it also means that the display
17695 element at max_pos was displayed in its entirety on this
17696 line, which is equivalent to saying that the next line
17697 starts at the next buffer position. */
17698 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17699 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17702 INC_BOTH (max_pos
, max_bpos
);
17703 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17706 else if (row
->truncated_on_right_p
)
17707 /* display_line already called reseat_at_next_visible_line_start,
17708 which puts the iterator at the beginning of the next line, in
17709 the logical order. */
17710 row
->maxpos
= it
->current
.pos
;
17711 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17712 /* A line that is entirely from a string/image/stretch... */
17713 row
->maxpos
= row
->minpos
;
17718 row
->maxpos
= it
->current
.pos
;
17721 /* Construct the glyph row IT->glyph_row in the desired matrix of
17722 IT->w from text at the current position of IT. See dispextern.h
17723 for an overview of struct it. Value is non-zero if
17724 IT->glyph_row displays text, as opposed to a line displaying ZV
17728 display_line (struct it
*it
)
17730 struct glyph_row
*row
= it
->glyph_row
;
17731 Lisp_Object overlay_arrow_string
;
17733 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17734 int wrap_row_used
= -1;
17735 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17736 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17737 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17738 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17739 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17741 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17742 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
17744 /* We always start displaying at hpos zero even if hscrolled. */
17745 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17747 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17748 >= it
->w
->desired_matrix
->nrows
)
17750 it
->w
->nrows_scale_factor
++;
17751 fonts_changed_p
= 1;
17755 /* Is IT->w showing the region? */
17756 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17758 /* Clear the result glyph row and enable it. */
17759 prepare_desired_row (row
);
17761 row
->y
= it
->current_y
;
17762 row
->start
= it
->start
;
17763 row
->continuation_lines_width
= it
->continuation_lines_width
;
17764 row
->displays_text_p
= 1;
17765 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17766 it
->starts_in_middle_of_char_p
= 0;
17768 /* Arrange the overlays nicely for our purposes. Usually, we call
17769 display_line on only one line at a time, in which case this
17770 can't really hurt too much, or we call it on lines which appear
17771 one after another in the buffer, in which case all calls to
17772 recenter_overlay_lists but the first will be pretty cheap. */
17773 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17775 /* Move over display elements that are not visible because we are
17776 hscrolled. This may stop at an x-position < IT->first_visible_x
17777 if the first glyph is partially visible or if we hit a line end. */
17778 if (it
->current_x
< it
->first_visible_x
)
17780 this_line_min_pos
= row
->start
.pos
;
17781 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17782 MOVE_TO_POS
| MOVE_TO_X
);
17783 /* Record the smallest positions seen while we moved over
17784 display elements that are not visible. This is needed by
17785 redisplay_internal for optimizing the case where the cursor
17786 stays inside the same line. The rest of this function only
17787 considers positions that are actually displayed, so
17788 RECORD_MAX_MIN_POS will not otherwise record positions that
17789 are hscrolled to the left of the left edge of the window. */
17790 min_pos
= CHARPOS (this_line_min_pos
);
17791 min_bpos
= BYTEPOS (this_line_min_pos
);
17795 /* We only do this when not calling `move_it_in_display_line_to'
17796 above, because move_it_in_display_line_to calls
17797 handle_line_prefix itself. */
17798 handle_line_prefix (it
);
17801 /* Get the initial row height. This is either the height of the
17802 text hscrolled, if there is any, or zero. */
17803 row
->ascent
= it
->max_ascent
;
17804 row
->height
= it
->max_ascent
+ it
->max_descent
;
17805 row
->phys_ascent
= it
->max_phys_ascent
;
17806 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17807 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17809 /* Utility macro to record max and min buffer positions seen until now. */
17810 #define RECORD_MAX_MIN_POS(IT) \
17813 if (IT_CHARPOS (*(IT)) < min_pos) \
17815 min_pos = IT_CHARPOS (*(IT)); \
17816 min_bpos = IT_BYTEPOS (*(IT)); \
17818 if (IT_CHARPOS (*(IT)) > max_pos) \
17820 max_pos = IT_CHARPOS (*(IT)); \
17821 max_bpos = IT_BYTEPOS (*(IT)); \
17826 /* Loop generating characters. The loop is left with IT on the next
17827 character to display. */
17830 int n_glyphs_before
, hpos_before
, x_before
;
17832 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17834 /* Retrieve the next thing to display. Value is zero if end of
17836 if (!get_next_display_element (it
))
17838 /* Maybe add a space at the end of this line that is used to
17839 display the cursor there under X. Set the charpos of the
17840 first glyph of blank lines not corresponding to any text
17842 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17843 row
->exact_window_width_line_p
= 1;
17844 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17845 || row
->used
[TEXT_AREA
] == 0)
17847 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17848 row
->displays_text_p
= 0;
17850 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
17851 && (!MINI_WINDOW_P (it
->w
)
17852 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17853 row
->indicate_empty_line_p
= 1;
17856 it
->continuation_lines_width
= 0;
17857 row
->ends_at_zv_p
= 1;
17858 /* A row that displays right-to-left text must always have
17859 its last face extended all the way to the end of line,
17860 even if this row ends in ZV, because we still write to
17861 the screen left to right. */
17862 if (row
->reversed_p
)
17863 extend_face_to_end_of_line (it
);
17867 /* Now, get the metrics of what we want to display. This also
17868 generates glyphs in `row' (which is IT->glyph_row). */
17869 n_glyphs_before
= row
->used
[TEXT_AREA
];
17872 /* Remember the line height so far in case the next element doesn't
17873 fit on the line. */
17874 if (it
->line_wrap
!= TRUNCATE
)
17876 ascent
= it
->max_ascent
;
17877 descent
= it
->max_descent
;
17878 phys_ascent
= it
->max_phys_ascent
;
17879 phys_descent
= it
->max_phys_descent
;
17881 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17883 if (IT_DISPLAYING_WHITESPACE (it
))
17889 wrap_row_used
= row
->used
[TEXT_AREA
];
17890 wrap_row_ascent
= row
->ascent
;
17891 wrap_row_height
= row
->height
;
17892 wrap_row_phys_ascent
= row
->phys_ascent
;
17893 wrap_row_phys_height
= row
->phys_height
;
17894 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17895 wrap_row_min_pos
= min_pos
;
17896 wrap_row_min_bpos
= min_bpos
;
17897 wrap_row_max_pos
= max_pos
;
17898 wrap_row_max_bpos
= max_bpos
;
17904 PRODUCE_GLYPHS (it
);
17906 /* If this display element was in marginal areas, continue with
17908 if (it
->area
!= TEXT_AREA
)
17910 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17911 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17912 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17913 row
->phys_height
= max (row
->phys_height
,
17914 it
->max_phys_ascent
+ it
->max_phys_descent
);
17915 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17916 it
->max_extra_line_spacing
);
17917 set_iterator_to_next (it
, 1);
17921 /* Does the display element fit on the line? If we truncate
17922 lines, we should draw past the right edge of the window. If
17923 we don't truncate, we want to stop so that we can display the
17924 continuation glyph before the right margin. If lines are
17925 continued, there are two possible strategies for characters
17926 resulting in more than 1 glyph (e.g. tabs): Display as many
17927 glyphs as possible in this line and leave the rest for the
17928 continuation line, or display the whole element in the next
17929 line. Original redisplay did the former, so we do it also. */
17930 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17931 hpos_before
= it
->hpos
;
17934 if (/* Not a newline. */
17936 /* Glyphs produced fit entirely in the line. */
17937 && it
->current_x
< it
->last_visible_x
)
17939 it
->hpos
+= nglyphs
;
17940 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17941 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17942 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17943 row
->phys_height
= max (row
->phys_height
,
17944 it
->max_phys_ascent
+ it
->max_phys_descent
);
17945 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17946 it
->max_extra_line_spacing
);
17947 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17948 row
->x
= x
- it
->first_visible_x
;
17949 /* Record the maximum and minimum buffer positions seen so
17950 far in glyphs that will be displayed by this row. */
17952 RECORD_MAX_MIN_POS (it
);
17957 struct glyph
*glyph
;
17959 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17961 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17962 new_x
= x
+ glyph
->pixel_width
;
17964 if (/* Lines are continued. */
17965 it
->line_wrap
!= TRUNCATE
17966 && (/* Glyph doesn't fit on the line. */
17967 new_x
> it
->last_visible_x
17968 /* Or it fits exactly on a window system frame. */
17969 || (new_x
== it
->last_visible_x
17970 && FRAME_WINDOW_P (it
->f
))))
17972 /* End of a continued line. */
17975 || (new_x
== it
->last_visible_x
17976 && FRAME_WINDOW_P (it
->f
)))
17978 /* Current glyph is the only one on the line or
17979 fits exactly on the line. We must continue
17980 the line because we can't draw the cursor
17981 after the glyph. */
17982 row
->continued_p
= 1;
17983 it
->current_x
= new_x
;
17984 it
->continuation_lines_width
+= new_x
;
17986 /* Record the maximum and minimum buffer
17987 positions seen so far in glyphs that will be
17988 displayed by this row. */
17990 RECORD_MAX_MIN_POS (it
);
17991 if (i
== nglyphs
- 1)
17993 /* If line-wrap is on, check if a previous
17994 wrap point was found. */
17995 if (wrap_row_used
> 0
17996 /* Even if there is a previous wrap
17997 point, continue the line here as
17998 usual, if (i) the previous character
17999 was a space or tab AND (ii) the
18000 current character is not. */
18002 || IT_DISPLAYING_WHITESPACE (it
)))
18005 set_iterator_to_next (it
, 1);
18006 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18008 if (!get_next_display_element (it
))
18010 row
->exact_window_width_line_p
= 1;
18011 it
->continuation_lines_width
= 0;
18012 row
->continued_p
= 0;
18013 row
->ends_at_zv_p
= 1;
18015 else if (ITERATOR_AT_END_OF_LINE_P (it
))
18017 row
->continued_p
= 0;
18018 row
->exact_window_width_line_p
= 1;
18023 else if (CHAR_GLYPH_PADDING_P (*glyph
)
18024 && !FRAME_WINDOW_P (it
->f
))
18026 /* A padding glyph that doesn't fit on this line.
18027 This means the whole character doesn't fit
18029 if (row
->reversed_p
)
18030 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18031 - n_glyphs_before
);
18032 row
->used
[TEXT_AREA
] = n_glyphs_before
;
18034 /* Fill the rest of the row with continuation
18035 glyphs like in 20.x. */
18036 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
18037 < row
->glyphs
[1 + TEXT_AREA
])
18038 produce_special_glyphs (it
, IT_CONTINUATION
);
18040 row
->continued_p
= 1;
18041 it
->current_x
= x_before
;
18042 it
->continuation_lines_width
+= x_before
;
18044 /* Restore the height to what it was before the
18045 element not fitting on the line. */
18046 it
->max_ascent
= ascent
;
18047 it
->max_descent
= descent
;
18048 it
->max_phys_ascent
= phys_ascent
;
18049 it
->max_phys_descent
= phys_descent
;
18051 else if (wrap_row_used
> 0)
18054 if (row
->reversed_p
)
18055 unproduce_glyphs (it
,
18056 row
->used
[TEXT_AREA
] - wrap_row_used
);
18058 it
->continuation_lines_width
+= wrap_x
;
18059 row
->used
[TEXT_AREA
] = wrap_row_used
;
18060 row
->ascent
= wrap_row_ascent
;
18061 row
->height
= wrap_row_height
;
18062 row
->phys_ascent
= wrap_row_phys_ascent
;
18063 row
->phys_height
= wrap_row_phys_height
;
18064 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
18065 min_pos
= wrap_row_min_pos
;
18066 min_bpos
= wrap_row_min_bpos
;
18067 max_pos
= wrap_row_max_pos
;
18068 max_bpos
= wrap_row_max_bpos
;
18069 row
->continued_p
= 1;
18070 row
->ends_at_zv_p
= 0;
18071 row
->exact_window_width_line_p
= 0;
18072 it
->continuation_lines_width
+= x
;
18074 /* Make sure that a non-default face is extended
18075 up to the right margin of the window. */
18076 extend_face_to_end_of_line (it
);
18078 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
18080 /* A TAB that extends past the right edge of the
18081 window. This produces a single glyph on
18082 window system frames. We leave the glyph in
18083 this row and let it fill the row, but don't
18084 consume the TAB. */
18085 it
->continuation_lines_width
+= it
->last_visible_x
;
18086 row
->ends_in_middle_of_char_p
= 1;
18087 row
->continued_p
= 1;
18088 glyph
->pixel_width
= it
->last_visible_x
- x
;
18089 it
->starts_in_middle_of_char_p
= 1;
18093 /* Something other than a TAB that draws past
18094 the right edge of the window. Restore
18095 positions to values before the element. */
18096 if (row
->reversed_p
)
18097 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18098 - (n_glyphs_before
+ i
));
18099 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18101 /* Display continuation glyphs. */
18102 if (!FRAME_WINDOW_P (it
->f
))
18103 produce_special_glyphs (it
, IT_CONTINUATION
);
18104 row
->continued_p
= 1;
18106 it
->current_x
= x_before
;
18107 it
->continuation_lines_width
+= x
;
18108 extend_face_to_end_of_line (it
);
18110 if (nglyphs
> 1 && i
> 0)
18112 row
->ends_in_middle_of_char_p
= 1;
18113 it
->starts_in_middle_of_char_p
= 1;
18116 /* Restore the height to what it was before the
18117 element not fitting on the line. */
18118 it
->max_ascent
= ascent
;
18119 it
->max_descent
= descent
;
18120 it
->max_phys_ascent
= phys_ascent
;
18121 it
->max_phys_descent
= phys_descent
;
18126 else if (new_x
> it
->first_visible_x
)
18128 /* Increment number of glyphs actually displayed. */
18131 /* Record the maximum and minimum buffer positions
18132 seen so far in glyphs that will be displayed by
18135 RECORD_MAX_MIN_POS (it
);
18137 if (x
< it
->first_visible_x
)
18138 /* Glyph is partially visible, i.e. row starts at
18139 negative X position. */
18140 row
->x
= x
- it
->first_visible_x
;
18144 /* Glyph is completely off the left margin of the
18145 window. This should not happen because of the
18146 move_it_in_display_line at the start of this
18147 function, unless the text display area of the
18148 window is empty. */
18149 xassert (it
->first_visible_x
<= it
->last_visible_x
);
18153 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18154 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18155 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18156 row
->phys_height
= max (row
->phys_height
,
18157 it
->max_phys_ascent
+ it
->max_phys_descent
);
18158 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18159 it
->max_extra_line_spacing
);
18161 /* End of this display line if row is continued. */
18162 if (row
->continued_p
|| row
->ends_at_zv_p
)
18167 /* Is this a line end? If yes, we're also done, after making
18168 sure that a non-default face is extended up to the right
18169 margin of the window. */
18170 if (ITERATOR_AT_END_OF_LINE_P (it
))
18172 int used_before
= row
->used
[TEXT_AREA
];
18174 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
18176 /* Add a space at the end of the line that is used to
18177 display the cursor there. */
18178 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18179 append_space_for_newline (it
, 0);
18181 /* Extend the face to the end of the line. */
18182 extend_face_to_end_of_line (it
);
18184 /* Make sure we have the position. */
18185 if (used_before
== 0)
18186 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
18188 /* Record the position of the newline, for use in
18190 it
->eol_pos
= it
->current
.pos
;
18192 /* Consume the line end. This skips over invisible lines. */
18193 set_iterator_to_next (it
, 1);
18194 it
->continuation_lines_width
= 0;
18198 /* Proceed with next display element. Note that this skips
18199 over lines invisible because of selective display. */
18200 set_iterator_to_next (it
, 1);
18202 /* If we truncate lines, we are done when the last displayed
18203 glyphs reach past the right margin of the window. */
18204 if (it
->line_wrap
== TRUNCATE
18205 && (FRAME_WINDOW_P (it
->f
)
18206 ? (it
->current_x
>= it
->last_visible_x
)
18207 : (it
->current_x
> it
->last_visible_x
)))
18209 /* Maybe add truncation glyphs. */
18210 if (!FRAME_WINDOW_P (it
->f
))
18214 if (!row
->reversed_p
)
18216 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18217 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18222 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
18223 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18225 /* Remove any padding glyphs at the front of ROW, to
18226 make room for the truncation glyphs we will be
18227 adding below. The loop below always inserts at
18228 least one truncation glyph, so also remove the
18229 last glyph added to ROW. */
18230 unproduce_glyphs (it
, i
+ 1);
18231 /* Adjust i for the loop below. */
18232 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18235 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18237 row
->used
[TEXT_AREA
] = i
;
18238 produce_special_glyphs (it
, IT_TRUNCATION
);
18241 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18243 /* Don't truncate if we can overflow newline into fringe. */
18244 if (!get_next_display_element (it
))
18246 it
->continuation_lines_width
= 0;
18247 row
->ends_at_zv_p
= 1;
18248 row
->exact_window_width_line_p
= 1;
18251 if (ITERATOR_AT_END_OF_LINE_P (it
))
18253 row
->exact_window_width_line_p
= 1;
18254 goto at_end_of_line
;
18258 row
->truncated_on_right_p
= 1;
18259 it
->continuation_lines_width
= 0;
18260 reseat_at_next_visible_line_start (it
, 0);
18261 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18262 it
->hpos
= hpos_before
;
18263 it
->current_x
= x_before
;
18268 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18269 at the left window margin. */
18270 if (it
->first_visible_x
18271 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18273 if (!FRAME_WINDOW_P (it
->f
))
18274 insert_left_trunc_glyphs (it
);
18275 row
->truncated_on_left_p
= 1;
18278 /* Remember the position at which this line ends.
18280 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18281 cannot be before the call to find_row_edges below, since that is
18282 where these positions are determined. */
18283 row
->end
= it
->current
;
18286 row
->minpos
= row
->start
.pos
;
18287 row
->maxpos
= row
->end
.pos
;
18291 /* ROW->minpos and ROW->maxpos must be the smallest and
18292 `1 + the largest' buffer positions in ROW. But if ROW was
18293 bidi-reordered, these two positions can be anywhere in the
18294 row, so we must determine them now. */
18295 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18298 /* If the start of this line is the overlay arrow-position, then
18299 mark this glyph row as the one containing the overlay arrow.
18300 This is clearly a mess with variable size fonts. It would be
18301 better to let it be displayed like cursors under X. */
18302 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18303 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18304 !NILP (overlay_arrow_string
)))
18306 /* Overlay arrow in window redisplay is a fringe bitmap. */
18307 if (STRINGP (overlay_arrow_string
))
18309 struct glyph_row
*arrow_row
18310 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18311 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18312 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18313 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18314 struct glyph
*p2
, *end
;
18316 /* Copy the arrow glyphs. */
18317 while (glyph
< arrow_end
)
18320 /* Throw away padding glyphs. */
18322 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18323 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18329 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18334 xassert (INTEGERP (overlay_arrow_string
));
18335 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18337 overlay_arrow_seen
= 1;
18340 /* Compute pixel dimensions of this line. */
18341 compute_line_metrics (it
);
18343 /* Record whether this row ends inside an ellipsis. */
18344 row
->ends_in_ellipsis_p
18345 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18346 && it
->ellipsis_p
);
18348 /* Save fringe bitmaps in this row. */
18349 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18350 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18351 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18352 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18354 it
->left_user_fringe_bitmap
= 0;
18355 it
->left_user_fringe_face_id
= 0;
18356 it
->right_user_fringe_bitmap
= 0;
18357 it
->right_user_fringe_face_id
= 0;
18359 /* Maybe set the cursor. */
18360 cvpos
= it
->w
->cursor
.vpos
;
18362 /* In bidi-reordered rows, keep checking for proper cursor
18363 position even if one has been found already, because buffer
18364 positions in such rows change non-linearly with ROW->VPOS,
18365 when a line is continued. One exception: when we are at ZV,
18366 display cursor on the first suitable glyph row, since all
18367 the empty rows after that also have their position set to ZV. */
18368 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18369 lines' rows is implemented for bidi-reordered rows. */
18371 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18372 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18373 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18374 && cursor_row_p (row
))
18375 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18377 /* Highlight trailing whitespace. */
18378 if (!NILP (Vshow_trailing_whitespace
))
18379 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18381 /* Prepare for the next line. This line starts horizontally at (X
18382 HPOS) = (0 0). Vertical positions are incremented. As a
18383 convenience for the caller, IT->glyph_row is set to the next
18385 it
->current_x
= it
->hpos
= 0;
18386 it
->current_y
+= row
->height
;
18387 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18390 /* The next row should by default use the same value of the
18391 reversed_p flag as this one. set_iterator_to_next decides when
18392 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18393 the flag accordingly. */
18394 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18395 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18396 it
->start
= row
->end
;
18397 return row
->displays_text_p
;
18399 #undef RECORD_MAX_MIN_POS
18402 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18403 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18404 doc
: /* Return paragraph direction at point in BUFFER.
18405 Value is either `left-to-right' or `right-to-left'.
18406 If BUFFER is omitted or nil, it defaults to the current buffer.
18408 Paragraph direction determines how the text in the paragraph is displayed.
18409 In left-to-right paragraphs, text begins at the left margin of the window
18410 and the reading direction is generally left to right. In right-to-left
18411 paragraphs, text begins at the right margin and is read from right to left.
18413 See also `bidi-paragraph-direction'. */)
18414 (Lisp_Object buffer
)
18416 struct buffer
*buf
= current_buffer
;
18417 struct buffer
*old
= buf
;
18419 if (! NILP (buffer
))
18421 CHECK_BUFFER (buffer
);
18422 buf
= XBUFFER (buffer
);
18425 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18426 return Qleft_to_right
;
18427 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18428 return BVAR (buf
, bidi_paragraph_direction
);
18431 /* Determine the direction from buffer text. We could try to
18432 use current_matrix if it is up to date, but this seems fast
18433 enough as it is. */
18434 struct bidi_it itb
;
18435 EMACS_INT pos
= BUF_PT (buf
);
18436 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18439 set_buffer_temp (buf
);
18440 /* bidi_paragraph_init finds the base direction of the paragraph
18441 by searching forward from paragraph start. We need the base
18442 direction of the current or _previous_ paragraph, so we need
18443 to make sure we are within that paragraph. To that end, find
18444 the previous non-empty line. */
18445 if (pos
>= ZV
&& pos
> BEGV
)
18448 bytepos
= CHAR_TO_BYTE (pos
);
18450 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18451 || c
== ' ' || c
== '\t' || c
== '\f')
18453 if (bytepos
<= BEGV_BYTE
)
18458 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18461 itb
.bytepos
= bytepos
;
18463 itb
.string
.s
= NULL
;
18464 itb
.string
.lstring
= Qnil
;
18465 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18467 itb
.separator_limit
= -1;
18468 itb
.paragraph_dir
= NEUTRAL_DIR
;
18470 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18471 set_buffer_temp (old
);
18472 switch (itb
.paragraph_dir
)
18475 return Qleft_to_right
;
18478 return Qright_to_left
;
18488 /***********************************************************************
18490 ***********************************************************************/
18492 /* Redisplay the menu bar in the frame for window W.
18494 The menu bar of X frames that don't have X toolkit support is
18495 displayed in a special window W->frame->menu_bar_window.
18497 The menu bar of terminal frames is treated specially as far as
18498 glyph matrices are concerned. Menu bar lines are not part of
18499 windows, so the update is done directly on the frame matrix rows
18500 for the menu bar. */
18503 display_menu_bar (struct window
*w
)
18505 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18510 /* Don't do all this for graphical frames. */
18512 if (FRAME_W32_P (f
))
18515 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18521 if (FRAME_NS_P (f
))
18523 #endif /* HAVE_NS */
18525 #ifdef USE_X_TOOLKIT
18526 xassert (!FRAME_WINDOW_P (f
));
18527 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18528 it
.first_visible_x
= 0;
18529 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18530 #else /* not USE_X_TOOLKIT */
18531 if (FRAME_WINDOW_P (f
))
18533 /* Menu bar lines are displayed in the desired matrix of the
18534 dummy window menu_bar_window. */
18535 struct window
*menu_w
;
18536 xassert (WINDOWP (f
->menu_bar_window
));
18537 menu_w
= XWINDOW (f
->menu_bar_window
);
18538 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18540 it
.first_visible_x
= 0;
18541 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18545 /* This is a TTY frame, i.e. character hpos/vpos are used as
18547 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18549 it
.first_visible_x
= 0;
18550 it
.last_visible_x
= FRAME_COLS (f
);
18552 #endif /* not USE_X_TOOLKIT */
18554 if (! mode_line_inverse_video
)
18555 /* Force the menu-bar to be displayed in the default face. */
18556 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18558 /* Clear all rows of the menu bar. */
18559 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18561 struct glyph_row
*row
= it
.glyph_row
+ i
;
18562 clear_glyph_row (row
);
18563 row
->enabled_p
= 1;
18564 row
->full_width_p
= 1;
18567 /* Display all items of the menu bar. */
18568 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18569 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18571 Lisp_Object string
;
18573 /* Stop at nil string. */
18574 string
= AREF (items
, i
+ 1);
18578 /* Remember where item was displayed. */
18579 ASET (items
, i
+ 3, make_number (it
.hpos
));
18581 /* Display the item, pad with one space. */
18582 if (it
.current_x
< it
.last_visible_x
)
18583 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18584 SCHARS (string
) + 1, 0, 0, -1);
18587 /* Fill out the line with spaces. */
18588 if (it
.current_x
< it
.last_visible_x
)
18589 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18591 /* Compute the total height of the lines. */
18592 compute_line_metrics (&it
);
18597 /***********************************************************************
18599 ***********************************************************************/
18601 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18602 FORCE is non-zero, redisplay mode lines unconditionally.
18603 Otherwise, redisplay only mode lines that are garbaged. Value is
18604 the number of windows whose mode lines were redisplayed. */
18607 redisplay_mode_lines (Lisp_Object window
, int force
)
18611 while (!NILP (window
))
18613 struct window
*w
= XWINDOW (window
);
18615 if (WINDOWP (w
->hchild
))
18616 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18617 else if (WINDOWP (w
->vchild
))
18618 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18620 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18621 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18623 struct text_pos lpoint
;
18624 struct buffer
*old
= current_buffer
;
18626 /* Set the window's buffer for the mode line display. */
18627 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18628 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18630 /* Point refers normally to the selected window. For any
18631 other window, set up appropriate value. */
18632 if (!EQ (window
, selected_window
))
18634 struct text_pos pt
;
18636 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18637 if (CHARPOS (pt
) < BEGV
)
18638 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18639 else if (CHARPOS (pt
) > (ZV
- 1))
18640 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18642 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18645 /* Display mode lines. */
18646 clear_glyph_matrix (w
->desired_matrix
);
18647 if (display_mode_lines (w
))
18650 w
->must_be_updated_p
= 1;
18653 /* Restore old settings. */
18654 set_buffer_internal_1 (old
);
18655 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18665 /* Display the mode and/or header line of window W. Value is the
18666 sum number of mode lines and header lines displayed. */
18669 display_mode_lines (struct window
*w
)
18671 Lisp_Object old_selected_window
, old_selected_frame
;
18674 old_selected_frame
= selected_frame
;
18675 selected_frame
= w
->frame
;
18676 old_selected_window
= selected_window
;
18677 XSETWINDOW (selected_window
, w
);
18679 /* These will be set while the mode line specs are processed. */
18680 line_number_displayed
= 0;
18681 w
->column_number_displayed
= Qnil
;
18683 if (WINDOW_WANTS_MODELINE_P (w
))
18685 struct window
*sel_w
= XWINDOW (old_selected_window
);
18687 /* Select mode line face based on the real selected window. */
18688 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18689 BVAR (current_buffer
, mode_line_format
));
18693 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18695 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18696 BVAR (current_buffer
, header_line_format
));
18700 selected_frame
= old_selected_frame
;
18701 selected_window
= old_selected_window
;
18706 /* Display mode or header line of window W. FACE_ID specifies which
18707 line to display; it is either MODE_LINE_FACE_ID or
18708 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18709 display. Value is the pixel height of the mode/header line
18713 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18717 int count
= SPECPDL_INDEX ();
18719 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18720 /* Don't extend on a previously drawn mode-line.
18721 This may happen if called from pos_visible_p. */
18722 it
.glyph_row
->enabled_p
= 0;
18723 prepare_desired_row (it
.glyph_row
);
18725 it
.glyph_row
->mode_line_p
= 1;
18727 if (! mode_line_inverse_video
)
18728 /* Force the mode-line to be displayed in the default face. */
18729 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18731 /* FIXME: This should take its value from a user option. */
18732 it
.paragraph_embedding
= L2R
;
18734 record_unwind_protect (unwind_format_mode_line
,
18735 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18737 mode_line_target
= MODE_LINE_DISPLAY
;
18739 /* Temporarily make frame's keyboard the current kboard so that
18740 kboard-local variables in the mode_line_format will get the right
18742 push_kboard (FRAME_KBOARD (it
.f
));
18743 record_unwind_save_match_data ();
18744 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18747 unbind_to (count
, Qnil
);
18749 /* Fill up with spaces. */
18750 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18752 compute_line_metrics (&it
);
18753 it
.glyph_row
->full_width_p
= 1;
18754 it
.glyph_row
->continued_p
= 0;
18755 it
.glyph_row
->truncated_on_left_p
= 0;
18756 it
.glyph_row
->truncated_on_right_p
= 0;
18758 /* Make a 3D mode-line have a shadow at its right end. */
18759 face
= FACE_FROM_ID (it
.f
, face_id
);
18760 extend_face_to_end_of_line (&it
);
18761 if (face
->box
!= FACE_NO_BOX
)
18763 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18764 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18765 last
->right_box_line_p
= 1;
18768 return it
.glyph_row
->height
;
18771 /* Move element ELT in LIST to the front of LIST.
18772 Return the updated list. */
18775 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18777 register Lisp_Object tail
, prev
;
18778 register Lisp_Object tem
;
18782 while (CONSP (tail
))
18788 /* Splice out the link TAIL. */
18790 list
= XCDR (tail
);
18792 Fsetcdr (prev
, XCDR (tail
));
18794 /* Now make it the first. */
18795 Fsetcdr (tail
, list
);
18800 tail
= XCDR (tail
);
18804 /* Not found--return unchanged LIST. */
18808 /* Contribute ELT to the mode line for window IT->w. How it
18809 translates into text depends on its data type.
18811 IT describes the display environment in which we display, as usual.
18813 DEPTH is the depth in recursion. It is used to prevent
18814 infinite recursion here.
18816 FIELD_WIDTH is the number of characters the display of ELT should
18817 occupy in the mode line, and PRECISION is the maximum number of
18818 characters to display from ELT's representation. See
18819 display_string for details.
18821 Returns the hpos of the end of the text generated by ELT.
18823 PROPS is a property list to add to any string we encounter.
18825 If RISKY is nonzero, remove (disregard) any properties in any string
18826 we encounter, and ignore :eval and :propertize.
18828 The global variable `mode_line_target' determines whether the
18829 output is passed to `store_mode_line_noprop',
18830 `store_mode_line_string', or `display_string'. */
18833 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18834 Lisp_Object elt
, Lisp_Object props
, int risky
)
18836 int n
= 0, field
, prec
;
18839 it
->paragraph_embedding
= L2R
;
18843 elt
= build_string ("*too-deep*");
18847 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18851 /* A string: output it and check for %-constructs within it. */
18853 EMACS_INT offset
= 0;
18855 if (SCHARS (elt
) > 0
18856 && (!NILP (props
) || risky
))
18858 Lisp_Object oprops
, aelt
;
18859 oprops
= Ftext_properties_at (make_number (0), elt
);
18861 /* If the starting string's properties are not what
18862 we want, translate the string. Also, if the string
18863 is risky, do that anyway. */
18865 if (NILP (Fequal (props
, oprops
)) || risky
)
18867 /* If the starting string has properties,
18868 merge the specified ones onto the existing ones. */
18869 if (! NILP (oprops
) && !risky
)
18873 oprops
= Fcopy_sequence (oprops
);
18875 while (CONSP (tem
))
18877 oprops
= Fplist_put (oprops
, XCAR (tem
),
18878 XCAR (XCDR (tem
)));
18879 tem
= XCDR (XCDR (tem
));
18884 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18885 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18887 /* AELT is what we want. Move it to the front
18888 without consing. */
18890 mode_line_proptrans_alist
18891 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18897 /* If AELT has the wrong props, it is useless.
18898 so get rid of it. */
18900 mode_line_proptrans_alist
18901 = Fdelq (aelt
, mode_line_proptrans_alist
);
18903 elt
= Fcopy_sequence (elt
);
18904 Fset_text_properties (make_number (0), Flength (elt
),
18906 /* Add this item to mode_line_proptrans_alist. */
18907 mode_line_proptrans_alist
18908 = Fcons (Fcons (elt
, props
),
18909 mode_line_proptrans_alist
);
18910 /* Truncate mode_line_proptrans_alist
18911 to at most 50 elements. */
18912 tem
= Fnthcdr (make_number (50),
18913 mode_line_proptrans_alist
);
18915 XSETCDR (tem
, Qnil
);
18924 prec
= precision
- n
;
18925 switch (mode_line_target
)
18927 case MODE_LINE_NOPROP
:
18928 case MODE_LINE_TITLE
:
18929 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
18931 case MODE_LINE_STRING
:
18932 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18934 case MODE_LINE_DISPLAY
:
18935 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18936 0, prec
, 0, STRING_MULTIBYTE (elt
));
18943 /* Handle the non-literal case. */
18945 while ((precision
<= 0 || n
< precision
)
18946 && SREF (elt
, offset
) != 0
18947 && (mode_line_target
!= MODE_LINE_DISPLAY
18948 || it
->current_x
< it
->last_visible_x
))
18950 EMACS_INT last_offset
= offset
;
18952 /* Advance to end of string or next format specifier. */
18953 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18956 if (offset
- 1 != last_offset
)
18958 EMACS_INT nchars
, nbytes
;
18960 /* Output to end of string or up to '%'. Field width
18961 is length of string. Don't output more than
18962 PRECISION allows us. */
18965 prec
= c_string_width (SDATA (elt
) + last_offset
,
18966 offset
- last_offset
, precision
- n
,
18969 switch (mode_line_target
)
18971 case MODE_LINE_NOPROP
:
18972 case MODE_LINE_TITLE
:
18973 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
18975 case MODE_LINE_STRING
:
18977 EMACS_INT bytepos
= last_offset
;
18978 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18979 EMACS_INT endpos
= (precision
<= 0
18980 ? string_byte_to_char (elt
, offset
)
18981 : charpos
+ nchars
);
18983 n
+= store_mode_line_string (NULL
,
18984 Fsubstring (elt
, make_number (charpos
),
18985 make_number (endpos
)),
18989 case MODE_LINE_DISPLAY
:
18991 EMACS_INT bytepos
= last_offset
;
18992 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18994 if (precision
<= 0)
18995 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18996 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18998 STRING_MULTIBYTE (elt
));
19003 else /* c == '%' */
19005 EMACS_INT percent_position
= offset
;
19007 /* Get the specified minimum width. Zero means
19010 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
19011 field
= field
* 10 + c
- '0';
19013 /* Don't pad beyond the total padding allowed. */
19014 if (field_width
- n
> 0 && field
> field_width
- n
)
19015 field
= field_width
- n
;
19017 /* Note that either PRECISION <= 0 or N < PRECISION. */
19018 prec
= precision
- n
;
19021 n
+= display_mode_element (it
, depth
, field
, prec
,
19022 Vglobal_mode_string
, props
,
19027 EMACS_INT bytepos
, charpos
;
19029 Lisp_Object string
;
19031 bytepos
= percent_position
;
19032 charpos
= (STRING_MULTIBYTE (elt
)
19033 ? string_byte_to_char (elt
, bytepos
)
19035 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
19036 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
19038 switch (mode_line_target
)
19040 case MODE_LINE_NOPROP
:
19041 case MODE_LINE_TITLE
:
19042 n
+= store_mode_line_noprop (spec
, field
, prec
);
19044 case MODE_LINE_STRING
:
19046 int len
= strlen (spec
);
19047 Lisp_Object tem
= make_string (spec
, len
);
19048 props
= Ftext_properties_at (make_number (charpos
), elt
);
19049 /* Should only keep face property in props */
19050 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
19053 case MODE_LINE_DISPLAY
:
19055 int nglyphs_before
, nwritten
;
19057 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19058 nwritten
= display_string (spec
, string
, elt
,
19063 /* Assign to the glyphs written above the
19064 string where the `%x' came from, position
19068 struct glyph
*glyph
19069 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
19073 for (i
= 0; i
< nwritten
; ++i
)
19075 glyph
[i
].object
= elt
;
19076 glyph
[i
].charpos
= charpos
;
19093 /* A symbol: process the value of the symbol recursively
19094 as if it appeared here directly. Avoid error if symbol void.
19095 Special case: if value of symbol is a string, output the string
19098 register Lisp_Object tem
;
19100 /* If the variable is not marked as risky to set
19101 then its contents are risky to use. */
19102 if (NILP (Fget (elt
, Qrisky_local_variable
)))
19105 tem
= Fboundp (elt
);
19108 tem
= Fsymbol_value (elt
);
19109 /* If value is a string, output that string literally:
19110 don't check for % within it. */
19114 if (!EQ (tem
, elt
))
19116 /* Give up right away for nil or t. */
19126 register Lisp_Object car
, tem
;
19128 /* A cons cell: five distinct cases.
19129 If first element is :eval or :propertize, do something special.
19130 If first element is a string or a cons, process all the elements
19131 and effectively concatenate them.
19132 If first element is a negative number, truncate displaying cdr to
19133 at most that many characters. If positive, pad (with spaces)
19134 to at least that many characters.
19135 If first element is a symbol, process the cadr or caddr recursively
19136 according to whether the symbol's value is non-nil or nil. */
19138 if (EQ (car
, QCeval
))
19140 /* An element of the form (:eval FORM) means evaluate FORM
19141 and use the result as mode line elements. */
19146 if (CONSP (XCDR (elt
)))
19149 spec
= safe_eval (XCAR (XCDR (elt
)));
19150 n
+= display_mode_element (it
, depth
, field_width
- n
,
19151 precision
- n
, spec
, props
,
19155 else if (EQ (car
, QCpropertize
))
19157 /* An element of the form (:propertize ELT PROPS...)
19158 means display ELT but applying properties PROPS. */
19163 if (CONSP (XCDR (elt
)))
19164 n
+= display_mode_element (it
, depth
, field_width
- n
,
19165 precision
- n
, XCAR (XCDR (elt
)),
19166 XCDR (XCDR (elt
)), risky
);
19168 else if (SYMBOLP (car
))
19170 tem
= Fboundp (car
);
19174 /* elt is now the cdr, and we know it is a cons cell.
19175 Use its car if CAR has a non-nil value. */
19178 tem
= Fsymbol_value (car
);
19185 /* Symbol's value is nil (or symbol is unbound)
19186 Get the cddr of the original list
19187 and if possible find the caddr and use that. */
19191 else if (!CONSP (elt
))
19196 else if (INTEGERP (car
))
19198 register int lim
= XINT (car
);
19202 /* Negative int means reduce maximum width. */
19203 if (precision
<= 0)
19206 precision
= min (precision
, -lim
);
19210 /* Padding specified. Don't let it be more than
19211 current maximum. */
19213 lim
= min (precision
, lim
);
19215 /* If that's more padding than already wanted, queue it.
19216 But don't reduce padding already specified even if
19217 that is beyond the current truncation point. */
19218 field_width
= max (lim
, field_width
);
19222 else if (STRINGP (car
) || CONSP (car
))
19224 Lisp_Object halftail
= elt
;
19228 && (precision
<= 0 || n
< precision
))
19230 n
+= display_mode_element (it
, depth
,
19231 /* Do padding only after the last
19232 element in the list. */
19233 (! CONSP (XCDR (elt
))
19236 precision
- n
, XCAR (elt
),
19240 if ((len
& 1) == 0)
19241 halftail
= XCDR (halftail
);
19242 /* Check for cycle. */
19243 if (EQ (halftail
, elt
))
19252 elt
= build_string ("*invalid*");
19256 /* Pad to FIELD_WIDTH. */
19257 if (field_width
> 0 && n
< field_width
)
19259 switch (mode_line_target
)
19261 case MODE_LINE_NOPROP
:
19262 case MODE_LINE_TITLE
:
19263 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19265 case MODE_LINE_STRING
:
19266 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19268 case MODE_LINE_DISPLAY
:
19269 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19278 /* Store a mode-line string element in mode_line_string_list.
19280 If STRING is non-null, display that C string. Otherwise, the Lisp
19281 string LISP_STRING is displayed.
19283 FIELD_WIDTH is the minimum number of output glyphs to produce.
19284 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19285 with spaces. FIELD_WIDTH <= 0 means don't pad.
19287 PRECISION is the maximum number of characters to output from
19288 STRING. PRECISION <= 0 means don't truncate the string.
19290 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19291 properties to the string.
19293 PROPS are the properties to add to the string.
19294 The mode_line_string_face face property is always added to the string.
19298 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19299 int field_width
, int precision
, Lisp_Object props
)
19304 if (string
!= NULL
)
19306 len
= strlen (string
);
19307 if (precision
> 0 && len
> precision
)
19309 lisp_string
= make_string (string
, len
);
19311 props
= mode_line_string_face_prop
;
19312 else if (!NILP (mode_line_string_face
))
19314 Lisp_Object face
= Fplist_get (props
, Qface
);
19315 props
= Fcopy_sequence (props
);
19317 face
= mode_line_string_face
;
19319 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19320 props
= Fplist_put (props
, Qface
, face
);
19322 Fadd_text_properties (make_number (0), make_number (len
),
19323 props
, lisp_string
);
19327 len
= XFASTINT (Flength (lisp_string
));
19328 if (precision
> 0 && len
> precision
)
19331 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19334 if (!NILP (mode_line_string_face
))
19338 props
= Ftext_properties_at (make_number (0), lisp_string
);
19339 face
= Fplist_get (props
, Qface
);
19341 face
= mode_line_string_face
;
19343 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19344 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19346 lisp_string
= Fcopy_sequence (lisp_string
);
19349 Fadd_text_properties (make_number (0), make_number (len
),
19350 props
, lisp_string
);
19355 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19359 if (field_width
> len
)
19361 field_width
-= len
;
19362 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19364 Fadd_text_properties (make_number (0), make_number (field_width
),
19365 props
, lisp_string
);
19366 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19374 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19376 doc
: /* Format a string out of a mode line format specification.
19377 First arg FORMAT specifies the mode line format (see `mode-line-format'
19378 for details) to use.
19380 By default, the format is evaluated for the currently selected window.
19382 Optional second arg FACE specifies the face property to put on all
19383 characters for which no face is specified. The value nil means the
19384 default face. The value t means whatever face the window's mode line
19385 currently uses (either `mode-line' or `mode-line-inactive',
19386 depending on whether the window is the selected window or not).
19387 An integer value means the value string has no text
19390 Optional third and fourth args WINDOW and BUFFER specify the window
19391 and buffer to use as the context for the formatting (defaults
19392 are the selected window and the WINDOW's buffer). */)
19393 (Lisp_Object format
, Lisp_Object face
,
19394 Lisp_Object window
, Lisp_Object buffer
)
19399 struct buffer
*old_buffer
= NULL
;
19401 int no_props
= INTEGERP (face
);
19402 int count
= SPECPDL_INDEX ();
19404 int string_start
= 0;
19407 window
= selected_window
;
19408 CHECK_WINDOW (window
);
19409 w
= XWINDOW (window
);
19412 buffer
= w
->buffer
;
19413 CHECK_BUFFER (buffer
);
19415 /* Make formatting the modeline a non-op when noninteractive, otherwise
19416 there will be problems later caused by a partially initialized frame. */
19417 if (NILP (format
) || noninteractive
)
19418 return empty_unibyte_string
;
19423 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19424 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19425 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19426 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19427 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19428 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19429 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19432 if (XBUFFER (buffer
) != current_buffer
)
19433 old_buffer
= current_buffer
;
19435 /* Save things including mode_line_proptrans_alist,
19436 and set that to nil so that we don't alter the outer value. */
19437 record_unwind_protect (unwind_format_mode_line
,
19438 format_mode_line_unwind_data
19439 (old_buffer
, selected_window
, 1));
19440 mode_line_proptrans_alist
= Qnil
;
19442 Fselect_window (window
, Qt
);
19444 set_buffer_internal_1 (XBUFFER (buffer
));
19446 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19450 mode_line_target
= MODE_LINE_NOPROP
;
19451 mode_line_string_face_prop
= Qnil
;
19452 mode_line_string_list
= Qnil
;
19453 string_start
= MODE_LINE_NOPROP_LEN (0);
19457 mode_line_target
= MODE_LINE_STRING
;
19458 mode_line_string_list
= Qnil
;
19459 mode_line_string_face
= face
;
19460 mode_line_string_face_prop
19461 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19464 push_kboard (FRAME_KBOARD (it
.f
));
19465 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19470 len
= MODE_LINE_NOPROP_LEN (string_start
);
19471 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19475 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19476 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19477 empty_unibyte_string
);
19480 unbind_to (count
, Qnil
);
19484 /* Write a null-terminated, right justified decimal representation of
19485 the positive integer D to BUF using a minimal field width WIDTH. */
19488 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19490 register char *p
= buf
;
19498 *p
++ = d
% 10 + '0';
19503 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19514 /* Write a null-terminated, right justified decimal and "human
19515 readable" representation of the nonnegative integer D to BUF using
19516 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19518 static const char power_letter
[] =
19532 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19534 /* We aim to represent the nonnegative integer D as
19535 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19536 EMACS_INT quotient
= d
;
19538 /* -1 means: do not use TENTHS. */
19542 /* Length of QUOTIENT.TENTHS as a string. */
19548 if (1000 <= quotient
)
19550 /* Scale to the appropriate EXPONENT. */
19553 remainder
= quotient
% 1000;
19557 while (1000 <= quotient
);
19559 /* Round to nearest and decide whether to use TENTHS or not. */
19562 tenths
= remainder
/ 100;
19563 if (50 <= remainder
% 100)
19570 if (quotient
== 10)
19578 if (500 <= remainder
)
19580 if (quotient
< 999)
19591 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19592 if (tenths
== -1 && quotient
<= 99)
19599 p
= psuffix
= buf
+ max (width
, length
);
19601 /* Print EXPONENT. */
19602 *psuffix
++ = power_letter
[exponent
];
19605 /* Print TENTHS. */
19608 *--p
= '0' + tenths
;
19612 /* Print QUOTIENT. */
19615 int digit
= quotient
% 10;
19616 *--p
= '0' + digit
;
19618 while ((quotient
/= 10) != 0);
19620 /* Print leading spaces. */
19625 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19626 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19627 type of CODING_SYSTEM. Return updated pointer into BUF. */
19629 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19632 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19635 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19636 const unsigned char *eol_str
;
19638 /* The EOL conversion we are using. */
19639 Lisp_Object eoltype
;
19641 val
= CODING_SYSTEM_SPEC (coding_system
);
19644 if (!VECTORP (val
)) /* Not yet decided. */
19649 eoltype
= eol_mnemonic_undecided
;
19650 /* Don't mention EOL conversion if it isn't decided. */
19655 Lisp_Object eolvalue
;
19657 attrs
= AREF (val
, 0);
19658 eolvalue
= AREF (val
, 2);
19661 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19665 /* The EOL conversion that is normal on this system. */
19667 if (NILP (eolvalue
)) /* Not yet decided. */
19668 eoltype
= eol_mnemonic_undecided
;
19669 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19670 eoltype
= eol_mnemonic_undecided
;
19671 else /* eolvalue is Qunix, Qdos, or Qmac. */
19672 eoltype
= (EQ (eolvalue
, Qunix
)
19673 ? eol_mnemonic_unix
19674 : (EQ (eolvalue
, Qdos
) == 1
19675 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19681 /* Mention the EOL conversion if it is not the usual one. */
19682 if (STRINGP (eoltype
))
19684 eol_str
= SDATA (eoltype
);
19685 eol_str_len
= SBYTES (eoltype
);
19687 else if (CHARACTERP (eoltype
))
19689 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19690 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19695 eol_str
= invalid_eol_type
;
19696 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19698 memcpy (buf
, eol_str
, eol_str_len
);
19699 buf
+= eol_str_len
;
19705 /* Return a string for the output of a mode line %-spec for window W,
19706 generated by character C. FIELD_WIDTH > 0 means pad the string
19707 returned with spaces to that value. Return a Lisp string in
19708 *STRING if the resulting string is taken from that Lisp string.
19710 Note we operate on the current buffer for most purposes,
19711 the exception being w->base_line_pos. */
19713 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19715 static const char *
19716 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19717 Lisp_Object
*string
)
19720 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19721 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19722 struct buffer
*b
= current_buffer
;
19730 if (!NILP (BVAR (b
, read_only
)))
19732 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19737 /* This differs from %* only for a modified read-only buffer. */
19738 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19740 if (!NILP (BVAR (b
, read_only
)))
19745 /* This differs from %* in ignoring read-only-ness. */
19746 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19758 if (command_loop_level
> 5)
19760 p
= decode_mode_spec_buf
;
19761 for (i
= 0; i
< command_loop_level
; i
++)
19764 return decode_mode_spec_buf
;
19772 if (command_loop_level
> 5)
19774 p
= decode_mode_spec_buf
;
19775 for (i
= 0; i
< command_loop_level
; i
++)
19778 return decode_mode_spec_buf
;
19785 /* Let lots_of_dashes be a string of infinite length. */
19786 if (mode_line_target
== MODE_LINE_NOPROP
||
19787 mode_line_target
== MODE_LINE_STRING
)
19789 if (field_width
<= 0
19790 || field_width
> sizeof (lots_of_dashes
))
19792 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19793 decode_mode_spec_buf
[i
] = '-';
19794 decode_mode_spec_buf
[i
] = '\0';
19795 return decode_mode_spec_buf
;
19798 return lots_of_dashes
;
19802 obj
= BVAR (b
, name
);
19806 /* %c and %l are ignored in `frame-title-format'.
19807 (In redisplay_internal, the frame title is drawn _before_ the
19808 windows are updated, so the stuff which depends on actual
19809 window contents (such as %l) may fail to render properly, or
19810 even crash emacs.) */
19811 if (mode_line_target
== MODE_LINE_TITLE
)
19815 EMACS_INT col
= current_column ();
19816 w
->column_number_displayed
= make_number (col
);
19817 pint2str (decode_mode_spec_buf
, field_width
, col
);
19818 return decode_mode_spec_buf
;
19822 #ifndef SYSTEM_MALLOC
19824 if (NILP (Vmemory_full
))
19827 return "!MEM FULL! ";
19834 /* %F displays the frame name. */
19835 if (!NILP (f
->title
))
19836 return SSDATA (f
->title
);
19837 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19838 return SSDATA (f
->name
);
19842 obj
= BVAR (b
, filename
);
19847 EMACS_INT size
= ZV
- BEGV
;
19848 pint2str (decode_mode_spec_buf
, field_width
, size
);
19849 return decode_mode_spec_buf
;
19854 EMACS_INT size
= ZV
- BEGV
;
19855 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19856 return decode_mode_spec_buf
;
19861 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19862 EMACS_INT topline
, nlines
, height
;
19865 /* %c and %l are ignored in `frame-title-format'. */
19866 if (mode_line_target
== MODE_LINE_TITLE
)
19869 startpos
= XMARKER (w
->start
)->charpos
;
19870 startpos_byte
= marker_byte_position (w
->start
);
19871 height
= WINDOW_TOTAL_LINES (w
);
19873 /* If we decided that this buffer isn't suitable for line numbers,
19874 don't forget that too fast. */
19875 if (EQ (w
->base_line_pos
, w
->buffer
))
19877 /* But do forget it, if the window shows a different buffer now. */
19878 else if (BUFFERP (w
->base_line_pos
))
19879 w
->base_line_pos
= Qnil
;
19881 /* If the buffer is very big, don't waste time. */
19882 if (INTEGERP (Vline_number_display_limit
)
19883 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19885 w
->base_line_pos
= Qnil
;
19886 w
->base_line_number
= Qnil
;
19890 if (INTEGERP (w
->base_line_number
)
19891 && INTEGERP (w
->base_line_pos
)
19892 && XFASTINT (w
->base_line_pos
) <= startpos
)
19894 line
= XFASTINT (w
->base_line_number
);
19895 linepos
= XFASTINT (w
->base_line_pos
);
19896 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19901 linepos
= BUF_BEGV (b
);
19902 linepos_byte
= BUF_BEGV_BYTE (b
);
19905 /* Count lines from base line to window start position. */
19906 nlines
= display_count_lines (linepos_byte
,
19910 topline
= nlines
+ line
;
19912 /* Determine a new base line, if the old one is too close
19913 or too far away, or if we did not have one.
19914 "Too close" means it's plausible a scroll-down would
19915 go back past it. */
19916 if (startpos
== BUF_BEGV (b
))
19918 w
->base_line_number
= make_number (topline
);
19919 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19921 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19922 || linepos
== BUF_BEGV (b
))
19924 EMACS_INT limit
= BUF_BEGV (b
);
19925 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19926 EMACS_INT position
;
19927 EMACS_INT distance
=
19928 (height
* 2 + 30) * line_number_display_limit_width
;
19930 if (startpos
- distance
> limit
)
19932 limit
= startpos
- distance
;
19933 limit_byte
= CHAR_TO_BYTE (limit
);
19936 nlines
= display_count_lines (startpos_byte
,
19938 - (height
* 2 + 30),
19940 /* If we couldn't find the lines we wanted within
19941 line_number_display_limit_width chars per line,
19942 give up on line numbers for this window. */
19943 if (position
== limit_byte
&& limit
== startpos
- distance
)
19945 w
->base_line_pos
= w
->buffer
;
19946 w
->base_line_number
= Qnil
;
19950 w
->base_line_number
= make_number (topline
- nlines
);
19951 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19954 /* Now count lines from the start pos to point. */
19955 nlines
= display_count_lines (startpos_byte
,
19956 PT_BYTE
, PT
, &junk
);
19958 /* Record that we did display the line number. */
19959 line_number_displayed
= 1;
19961 /* Make the string to show. */
19962 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19963 return decode_mode_spec_buf
;
19966 char* p
= decode_mode_spec_buf
;
19967 int pad
= field_width
- 2;
19973 return decode_mode_spec_buf
;
19979 obj
= BVAR (b
, mode_name
);
19983 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19989 EMACS_INT pos
= marker_position (w
->start
);
19990 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19992 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19994 if (pos
<= BUF_BEGV (b
))
19999 else if (pos
<= BUF_BEGV (b
))
20003 if (total
> 1000000)
20004 /* Do it differently for a large value, to avoid overflow. */
20005 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20007 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20008 /* We can't normally display a 3-digit number,
20009 so get us a 2-digit number that is close. */
20012 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20013 return decode_mode_spec_buf
;
20017 /* Display percentage of size above the bottom of the screen. */
20020 EMACS_INT toppos
= marker_position (w
->start
);
20021 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
20022 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20024 if (botpos
>= BUF_ZV (b
))
20026 if (toppos
<= BUF_BEGV (b
))
20033 if (total
> 1000000)
20034 /* Do it differently for a large value, to avoid overflow. */
20035 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20037 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20038 /* We can't normally display a 3-digit number,
20039 so get us a 2-digit number that is close. */
20042 if (toppos
<= BUF_BEGV (b
))
20043 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
20045 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20046 return decode_mode_spec_buf
;
20051 /* status of process */
20052 obj
= Fget_buffer_process (Fcurrent_buffer ());
20054 return "no process";
20056 obj
= Fsymbol_name (Fprocess_status (obj
));
20062 int count
= inhibit_garbage_collection ();
20063 Lisp_Object val
= call1 (intern ("file-remote-p"),
20064 BVAR (current_buffer
, directory
));
20065 unbind_to (count
, Qnil
);
20073 case 't': /* indicate TEXT or BINARY */
20077 /* coding-system (not including end-of-line format) */
20079 /* coding-system (including end-of-line type) */
20081 int eol_flag
= (c
== 'Z');
20082 char *p
= decode_mode_spec_buf
;
20084 if (! FRAME_WINDOW_P (f
))
20086 /* No need to mention EOL here--the terminal never needs
20087 to do EOL conversion. */
20088 p
= decode_mode_spec_coding (CODING_ID_NAME
20089 (FRAME_KEYBOARD_CODING (f
)->id
),
20091 p
= decode_mode_spec_coding (CODING_ID_NAME
20092 (FRAME_TERMINAL_CODING (f
)->id
),
20095 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
20098 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
20099 #ifdef subprocesses
20100 obj
= Fget_buffer_process (Fcurrent_buffer ());
20101 if (PROCESSP (obj
))
20103 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
20105 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
20108 #endif /* subprocesses */
20111 return decode_mode_spec_buf
;
20118 return SSDATA (obj
);
20125 /* Count up to COUNT lines starting from START_BYTE.
20126 But don't go beyond LIMIT_BYTE.
20127 Return the number of lines thus found (always nonnegative).
20129 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
20132 display_count_lines (EMACS_INT start_byte
,
20133 EMACS_INT limit_byte
, EMACS_INT count
,
20134 EMACS_INT
*byte_pos_ptr
)
20136 register unsigned char *cursor
;
20137 unsigned char *base
;
20139 register EMACS_INT ceiling
;
20140 register unsigned char *ceiling_addr
;
20141 EMACS_INT orig_count
= count
;
20143 /* If we are not in selective display mode,
20144 check only for newlines. */
20145 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
20146 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
20150 while (start_byte
< limit_byte
)
20152 ceiling
= BUFFER_CEILING_OF (start_byte
);
20153 ceiling
= min (limit_byte
- 1, ceiling
);
20154 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
20155 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
20158 if (selective_display
)
20159 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
20162 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
20165 if (cursor
!= ceiling_addr
)
20169 start_byte
+= cursor
- base
+ 1;
20170 *byte_pos_ptr
= start_byte
;
20174 if (++cursor
== ceiling_addr
)
20180 start_byte
+= cursor
- base
;
20185 while (start_byte
> limit_byte
)
20187 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
20188 ceiling
= max (limit_byte
, ceiling
);
20189 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
20190 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
20193 if (selective_display
)
20194 while (--cursor
!= ceiling_addr
20195 && *cursor
!= '\n' && *cursor
!= 015)
20198 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
20201 if (cursor
!= ceiling_addr
)
20205 start_byte
+= cursor
- base
+ 1;
20206 *byte_pos_ptr
= start_byte
;
20207 /* When scanning backwards, we should
20208 not count the newline posterior to which we stop. */
20209 return - orig_count
- 1;
20215 /* Here we add 1 to compensate for the last decrement
20216 of CURSOR, which took it past the valid range. */
20217 start_byte
+= cursor
- base
+ 1;
20221 *byte_pos_ptr
= limit_byte
;
20224 return - orig_count
+ count
;
20225 return orig_count
- count
;
20231 /***********************************************************************
20233 ***********************************************************************/
20235 /* Display a NUL-terminated string, starting with index START.
20237 If STRING is non-null, display that C string. Otherwise, the Lisp
20238 string LISP_STRING is displayed. There's a case that STRING is
20239 non-null and LISP_STRING is not nil. It means STRING is a string
20240 data of LISP_STRING. In that case, we display LISP_STRING while
20241 ignoring its text properties.
20243 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20244 FACE_STRING. Display STRING or LISP_STRING with the face at
20245 FACE_STRING_POS in FACE_STRING:
20247 Display the string in the environment given by IT, but use the
20248 standard display table, temporarily.
20250 FIELD_WIDTH is the minimum number of output glyphs to produce.
20251 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20252 with spaces. If STRING has more characters, more than FIELD_WIDTH
20253 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20255 PRECISION is the maximum number of characters to output from
20256 STRING. PRECISION < 0 means don't truncate the string.
20258 This is roughly equivalent to printf format specifiers:
20260 FIELD_WIDTH PRECISION PRINTF
20261 ----------------------------------------
20267 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20268 display them, and < 0 means obey the current buffer's value of
20269 enable_multibyte_characters.
20271 Value is the number of columns displayed. */
20274 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20275 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20276 int field_width
, int precision
, int max_x
, int multibyte
)
20278 int hpos_at_start
= it
->hpos
;
20279 int saved_face_id
= it
->face_id
;
20280 struct glyph_row
*row
= it
->glyph_row
;
20281 EMACS_INT it_charpos
;
20283 /* Initialize the iterator IT for iteration over STRING beginning
20284 with index START. */
20285 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20286 precision
, field_width
, multibyte
);
20287 if (string
&& STRINGP (lisp_string
))
20288 /* LISP_STRING is the one returned by decode_mode_spec. We should
20289 ignore its text properties. */
20290 it
->stop_charpos
= it
->end_charpos
;
20292 /* If displaying STRING, set up the face of the iterator from
20293 FACE_STRING, if that's given. */
20294 if (STRINGP (face_string
))
20300 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20301 0, it
->region_beg_charpos
,
20302 it
->region_end_charpos
,
20303 &endptr
, it
->base_face_id
, 0);
20304 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20305 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20308 /* Set max_x to the maximum allowed X position. Don't let it go
20309 beyond the right edge of the window. */
20311 max_x
= it
->last_visible_x
;
20313 max_x
= min (max_x
, it
->last_visible_x
);
20315 /* Skip over display elements that are not visible. because IT->w is
20317 if (it
->current_x
< it
->first_visible_x
)
20318 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20319 MOVE_TO_POS
| MOVE_TO_X
);
20321 row
->ascent
= it
->max_ascent
;
20322 row
->height
= it
->max_ascent
+ it
->max_descent
;
20323 row
->phys_ascent
= it
->max_phys_ascent
;
20324 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20325 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20327 if (STRINGP (it
->string
))
20328 it_charpos
= IT_STRING_CHARPOS (*it
);
20330 it_charpos
= IT_CHARPOS (*it
);
20332 /* This condition is for the case that we are called with current_x
20333 past last_visible_x. */
20334 while (it
->current_x
< max_x
)
20336 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20338 /* Get the next display element. */
20339 if (!get_next_display_element (it
))
20342 /* Produce glyphs. */
20343 x_before
= it
->current_x
;
20344 n_glyphs_before
= row
->used
[TEXT_AREA
];
20345 PRODUCE_GLYPHS (it
);
20347 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20350 while (i
< nglyphs
)
20352 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20354 if (it
->line_wrap
!= TRUNCATE
20355 && x
+ glyph
->pixel_width
> max_x
)
20357 /* End of continued line or max_x reached. */
20358 if (CHAR_GLYPH_PADDING_P (*glyph
))
20360 /* A wide character is unbreakable. */
20361 if (row
->reversed_p
)
20362 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20363 - n_glyphs_before
);
20364 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20365 it
->current_x
= x_before
;
20369 if (row
->reversed_p
)
20370 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20371 - (n_glyphs_before
+ i
));
20372 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20377 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20379 /* Glyph is at least partially visible. */
20381 if (x
< it
->first_visible_x
)
20382 row
->x
= x
- it
->first_visible_x
;
20386 /* Glyph is off the left margin of the display area.
20387 Should not happen. */
20391 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20392 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20393 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20394 row
->phys_height
= max (row
->phys_height
,
20395 it
->max_phys_ascent
+ it
->max_phys_descent
);
20396 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20397 it
->max_extra_line_spacing
);
20398 x
+= glyph
->pixel_width
;
20402 /* Stop if max_x reached. */
20406 /* Stop at line ends. */
20407 if (ITERATOR_AT_END_OF_LINE_P (it
))
20409 it
->continuation_lines_width
= 0;
20413 set_iterator_to_next (it
, 1);
20414 if (STRINGP (it
->string
))
20415 it_charpos
= IT_STRING_CHARPOS (*it
);
20417 it_charpos
= IT_CHARPOS (*it
);
20419 /* Stop if truncating at the right edge. */
20420 if (it
->line_wrap
== TRUNCATE
20421 && it
->current_x
>= it
->last_visible_x
)
20423 /* Add truncation mark, but don't do it if the line is
20424 truncated at a padding space. */
20425 if (it_charpos
< it
->string_nchars
)
20427 if (!FRAME_WINDOW_P (it
->f
))
20431 if (it
->current_x
> it
->last_visible_x
)
20433 if (!row
->reversed_p
)
20435 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20436 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20441 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
20442 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20444 unproduce_glyphs (it
, ii
+ 1);
20445 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
20447 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20449 row
->used
[TEXT_AREA
] = ii
;
20450 produce_special_glyphs (it
, IT_TRUNCATION
);
20453 produce_special_glyphs (it
, IT_TRUNCATION
);
20455 row
->truncated_on_right_p
= 1;
20461 /* Maybe insert a truncation at the left. */
20462 if (it
->first_visible_x
20465 if (!FRAME_WINDOW_P (it
->f
))
20466 insert_left_trunc_glyphs (it
);
20467 row
->truncated_on_left_p
= 1;
20470 it
->face_id
= saved_face_id
;
20472 /* Value is number of columns displayed. */
20473 return it
->hpos
- hpos_at_start
;
20478 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20479 appears as an element of LIST or as the car of an element of LIST.
20480 If PROPVAL is a list, compare each element against LIST in that
20481 way, and return 1/2 if any element of PROPVAL is found in LIST.
20482 Otherwise return 0. This function cannot quit.
20483 The return value is 2 if the text is invisible but with an ellipsis
20484 and 1 if it's invisible and without an ellipsis. */
20487 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20489 register Lisp_Object tail
, proptail
;
20491 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20493 register Lisp_Object tem
;
20495 if (EQ (propval
, tem
))
20497 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20498 return NILP (XCDR (tem
)) ? 1 : 2;
20501 if (CONSP (propval
))
20503 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20505 Lisp_Object propelt
;
20506 propelt
= XCAR (proptail
);
20507 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20509 register Lisp_Object tem
;
20511 if (EQ (propelt
, tem
))
20513 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20514 return NILP (XCDR (tem
)) ? 1 : 2;
20522 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20523 doc
: /* Non-nil if the property makes the text invisible.
20524 POS-OR-PROP can be a marker or number, in which case it is taken to be
20525 a position in the current buffer and the value of the `invisible' property
20526 is checked; or it can be some other value, which is then presumed to be the
20527 value of the `invisible' property of the text of interest.
20528 The non-nil value returned can be t for truly invisible text or something
20529 else if the text is replaced by an ellipsis. */)
20530 (Lisp_Object pos_or_prop
)
20533 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20534 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20536 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20537 return (invis
== 0 ? Qnil
20539 : make_number (invis
));
20542 /* Calculate a width or height in pixels from a specification using
20543 the following elements:
20546 NUM - a (fractional) multiple of the default font width/height
20547 (NUM) - specifies exactly NUM pixels
20548 UNIT - a fixed number of pixels, see below.
20549 ELEMENT - size of a display element in pixels, see below.
20550 (NUM . SPEC) - equals NUM * SPEC
20551 (+ SPEC SPEC ...) - add pixel values
20552 (- SPEC SPEC ...) - subtract pixel values
20553 (- SPEC) - negate pixel value
20556 INT or FLOAT - a number constant
20557 SYMBOL - use symbol's (buffer local) variable binding.
20560 in - pixels per inch *)
20561 mm - pixels per 1/1000 meter *)
20562 cm - pixels per 1/100 meter *)
20563 width - width of current font in pixels.
20564 height - height of current font in pixels.
20566 *) using the ratio(s) defined in display-pixels-per-inch.
20570 left-fringe - left fringe width in pixels
20571 right-fringe - right fringe width in pixels
20573 left-margin - left margin width in pixels
20574 right-margin - right margin width in pixels
20576 scroll-bar - scroll-bar area width in pixels
20580 Pixels corresponding to 5 inches:
20583 Total width of non-text areas on left side of window (if scroll-bar is on left):
20584 '(space :width (+ left-fringe left-margin scroll-bar))
20586 Align to first text column (in header line):
20587 '(space :align-to 0)
20589 Align to middle of text area minus half the width of variable `my-image'
20590 containing a loaded image:
20591 '(space :align-to (0.5 . (- text my-image)))
20593 Width of left margin minus width of 1 character in the default font:
20594 '(space :width (- left-margin 1))
20596 Width of left margin minus width of 2 characters in the current font:
20597 '(space :width (- left-margin (2 . width)))
20599 Center 1 character over left-margin (in header line):
20600 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20602 Different ways to express width of left fringe plus left margin minus one pixel:
20603 '(space :width (- (+ left-fringe left-margin) (1)))
20604 '(space :width (+ left-fringe left-margin (- (1))))
20605 '(space :width (+ left-fringe left-margin (-1)))
20609 #define NUMVAL(X) \
20610 ((INTEGERP (X) || FLOATP (X)) \
20615 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20616 struct font
*font
, int width_p
, int *align_to
)
20620 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20621 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20624 return OK_PIXELS (0);
20626 xassert (FRAME_LIVE_P (it
->f
));
20628 if (SYMBOLP (prop
))
20630 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20632 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20634 if (unit
[0] == 'i' && unit
[1] == 'n')
20636 else if (unit
[0] == 'm' && unit
[1] == 'm')
20638 else if (unit
[0] == 'c' && unit
[1] == 'm')
20645 #ifdef HAVE_WINDOW_SYSTEM
20646 if (FRAME_WINDOW_P (it
->f
)
20648 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20649 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20651 return OK_PIXELS (ppi
/ pixels
);
20654 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20655 || (CONSP (Vdisplay_pixels_per_inch
)
20657 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20658 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20660 return OK_PIXELS (ppi
/ pixels
);
20666 #ifdef HAVE_WINDOW_SYSTEM
20667 if (EQ (prop
, Qheight
))
20668 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20669 if (EQ (prop
, Qwidth
))
20670 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20672 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20673 return OK_PIXELS (1);
20676 if (EQ (prop
, Qtext
))
20677 return OK_PIXELS (width_p
20678 ? window_box_width (it
->w
, TEXT_AREA
)
20679 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20681 if (align_to
&& *align_to
< 0)
20684 if (EQ (prop
, Qleft
))
20685 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20686 if (EQ (prop
, Qright
))
20687 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20688 if (EQ (prop
, Qcenter
))
20689 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20690 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20691 if (EQ (prop
, Qleft_fringe
))
20692 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20693 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20694 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20695 if (EQ (prop
, Qright_fringe
))
20696 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20697 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20698 : window_box_right_offset (it
->w
, TEXT_AREA
));
20699 if (EQ (prop
, Qleft_margin
))
20700 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20701 if (EQ (prop
, Qright_margin
))
20702 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20703 if (EQ (prop
, Qscroll_bar
))
20704 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20706 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20707 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20708 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20713 if (EQ (prop
, Qleft_fringe
))
20714 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20715 if (EQ (prop
, Qright_fringe
))
20716 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20717 if (EQ (prop
, Qleft_margin
))
20718 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20719 if (EQ (prop
, Qright_margin
))
20720 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20721 if (EQ (prop
, Qscroll_bar
))
20722 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20725 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20728 if (INTEGERP (prop
) || FLOATP (prop
))
20730 int base_unit
= (width_p
20731 ? FRAME_COLUMN_WIDTH (it
->f
)
20732 : FRAME_LINE_HEIGHT (it
->f
));
20733 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20738 Lisp_Object car
= XCAR (prop
);
20739 Lisp_Object cdr
= XCDR (prop
);
20743 #ifdef HAVE_WINDOW_SYSTEM
20744 if (FRAME_WINDOW_P (it
->f
)
20745 && valid_image_p (prop
))
20747 int id
= lookup_image (it
->f
, prop
);
20748 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20750 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20753 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20759 while (CONSP (cdr
))
20761 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20762 font
, width_p
, align_to
))
20765 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20770 if (EQ (car
, Qminus
))
20772 return OK_PIXELS (pixels
);
20775 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20778 if (INTEGERP (car
) || FLOATP (car
))
20781 pixels
= XFLOATINT (car
);
20783 return OK_PIXELS (pixels
);
20784 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20785 font
, width_p
, align_to
))
20786 return OK_PIXELS (pixels
* fact
);
20797 /***********************************************************************
20799 ***********************************************************************/
20801 #ifdef HAVE_WINDOW_SYSTEM
20806 dump_glyph_string (s
)
20807 struct glyph_string
*s
;
20809 fprintf (stderr
, "glyph string\n");
20810 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20811 s
->x
, s
->y
, s
->width
, s
->height
);
20812 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20813 fprintf (stderr
, " hl = %d\n", s
->hl
);
20814 fprintf (stderr
, " left overhang = %d, right = %d\n",
20815 s
->left_overhang
, s
->right_overhang
);
20816 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20817 fprintf (stderr
, " extends to end of line = %d\n",
20818 s
->extends_to_end_of_line_p
);
20819 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20820 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20823 #endif /* GLYPH_DEBUG */
20825 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20826 of XChar2b structures for S; it can't be allocated in
20827 init_glyph_string because it must be allocated via `alloca'. W
20828 is the window on which S is drawn. ROW and AREA are the glyph row
20829 and area within the row from which S is constructed. START is the
20830 index of the first glyph structure covered by S. HL is a
20831 face-override for drawing S. */
20834 #define OPTIONAL_HDC(hdc) HDC hdc,
20835 #define DECLARE_HDC(hdc) HDC hdc;
20836 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20837 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20840 #ifndef OPTIONAL_HDC
20841 #define OPTIONAL_HDC(hdc)
20842 #define DECLARE_HDC(hdc)
20843 #define ALLOCATE_HDC(hdc, f)
20844 #define RELEASE_HDC(hdc, f)
20848 init_glyph_string (struct glyph_string
*s
,
20850 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20851 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20853 memset (s
, 0, sizeof *s
);
20855 s
->f
= XFRAME (w
->frame
);
20859 s
->display
= FRAME_X_DISPLAY (s
->f
);
20860 s
->window
= FRAME_X_WINDOW (s
->f
);
20861 s
->char2b
= char2b
;
20865 s
->first_glyph
= row
->glyphs
[area
] + start
;
20866 s
->height
= row
->height
;
20867 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20868 s
->ybase
= s
->y
+ row
->ascent
;
20872 /* Append the list of glyph strings with head H and tail T to the list
20873 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20876 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20877 struct glyph_string
*h
, struct glyph_string
*t
)
20891 /* Prepend the list of glyph strings with head H and tail T to the
20892 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20896 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20897 struct glyph_string
*h
, struct glyph_string
*t
)
20911 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20912 Set *HEAD and *TAIL to the resulting list. */
20915 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20916 struct glyph_string
*s
)
20918 s
->next
= s
->prev
= NULL
;
20919 append_glyph_string_lists (head
, tail
, s
, s
);
20923 /* Get face and two-byte form of character C in face FACE_ID on frame F.
20924 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
20925 make sure that X resources for the face returned are allocated.
20926 Value is a pointer to a realized face that is ready for display if
20927 DISPLAY_P is non-zero. */
20929 static INLINE
struct face
*
20930 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20931 XChar2b
*char2b
, int display_p
)
20933 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20937 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20939 if (code
!= FONT_INVALID_CODE
)
20940 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20942 STORE_XCHAR2B (char2b
, 0, 0);
20945 /* Make sure X resources of the face are allocated. */
20946 #ifdef HAVE_X_WINDOWS
20950 xassert (face
!= NULL
);
20951 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20958 /* Get face and two-byte form of character glyph GLYPH on frame F.
20959 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20960 a pointer to a realized face that is ready for display. */
20962 static INLINE
struct face
*
20963 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20964 XChar2b
*char2b
, int *two_byte_p
)
20968 xassert (glyph
->type
== CHAR_GLYPH
);
20969 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20978 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20979 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20981 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20983 if (code
!= FONT_INVALID_CODE
)
20984 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20986 STORE_XCHAR2B (char2b
, 0, 0);
20989 /* Make sure X resources of the face are allocated. */
20990 xassert (face
!= NULL
);
20991 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20996 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20997 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
21000 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
21004 if (CHAR_BYTE8_P (c
))
21005 code
= CHAR_TO_BYTE8 (c
);
21007 code
= font
->driver
->encode_char (font
, c
);
21009 if (code
== FONT_INVALID_CODE
)
21011 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21016 /* Fill glyph string S with composition components specified by S->cmp.
21018 BASE_FACE is the base face of the composition.
21019 S->cmp_from is the index of the first component for S.
21021 OVERLAPS non-zero means S should draw the foreground only, and use
21022 its physical height for clipping. See also draw_glyphs.
21024 Value is the index of a component not in S. */
21027 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
21031 /* For all glyphs of this composition, starting at the offset
21032 S->cmp_from, until we reach the end of the definition or encounter a
21033 glyph that requires the different face, add it to S. */
21038 s
->for_overlaps
= overlaps
;
21041 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
21043 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
21047 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
21050 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
21057 s
->font
= s
->face
->font
;
21059 else if (s
->face
!= face
)
21067 /* All glyph strings for the same composition has the same width,
21068 i.e. the width set for the first component of the composition. */
21069 s
->width
= s
->first_glyph
->pixel_width
;
21071 /* If the specified font could not be loaded, use the frame's
21072 default font, but record the fact that we couldn't load it in
21073 the glyph string so that we can draw rectangles for the
21074 characters of the glyph string. */
21075 if (s
->font
== NULL
)
21077 s
->font_not_found_p
= 1;
21078 s
->font
= FRAME_FONT (s
->f
);
21081 /* Adjust base line for subscript/superscript text. */
21082 s
->ybase
+= s
->first_glyph
->voffset
;
21084 /* This glyph string must always be drawn with 16-bit functions. */
21091 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
21092 int start
, int end
, int overlaps
)
21094 struct glyph
*glyph
, *last
;
21095 Lisp_Object lgstring
;
21098 s
->for_overlaps
= overlaps
;
21099 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21100 last
= s
->row
->glyphs
[s
->area
] + end
;
21101 s
->cmp_id
= glyph
->u
.cmp
.id
;
21102 s
->cmp_from
= glyph
->slice
.cmp
.from
;
21103 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
21104 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21105 lgstring
= composition_gstring_from_id (s
->cmp_id
);
21106 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
21108 while (glyph
< last
21109 && glyph
->u
.cmp
.automatic
21110 && glyph
->u
.cmp
.id
== s
->cmp_id
21111 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
21112 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
21114 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
21116 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
21117 unsigned code
= LGLYPH_CODE (lglyph
);
21119 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
21121 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
21122 return glyph
- s
->row
->glyphs
[s
->area
];
21126 /* Fill glyph string S from a sequence glyphs for glyphless characters.
21127 See the comment of fill_glyph_string for arguments.
21128 Value is the index of the first glyph not in S. */
21132 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
21133 int start
, int end
, int overlaps
)
21135 struct glyph
*glyph
, *last
;
21138 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
21139 s
->for_overlaps
= overlaps
;
21140 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21141 last
= s
->row
->glyphs
[s
->area
] + end
;
21142 voffset
= glyph
->voffset
;
21143 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21144 s
->font
= s
->face
->font
;
21146 s
->width
= glyph
->pixel_width
;
21148 while (glyph
< last
21149 && glyph
->type
== GLYPHLESS_GLYPH
21150 && glyph
->voffset
== voffset
21151 && glyph
->face_id
== face_id
)
21154 s
->width
+= glyph
->pixel_width
;
21157 s
->ybase
+= voffset
;
21158 return glyph
- s
->row
->glyphs
[s
->area
];
21162 /* Fill glyph string S from a sequence of character glyphs.
21164 FACE_ID is the face id of the string. START is the index of the
21165 first glyph to consider, END is the index of the last + 1.
21166 OVERLAPS non-zero means S should draw the foreground only, and use
21167 its physical height for clipping. See also draw_glyphs.
21169 Value is the index of the first glyph not in S. */
21172 fill_glyph_string (struct glyph_string
*s
, int face_id
,
21173 int start
, int end
, int overlaps
)
21175 struct glyph
*glyph
, *last
;
21177 int glyph_not_available_p
;
21179 xassert (s
->f
== XFRAME (s
->w
->frame
));
21180 xassert (s
->nchars
== 0);
21181 xassert (start
>= 0 && end
> start
);
21183 s
->for_overlaps
= overlaps
;
21184 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21185 last
= s
->row
->glyphs
[s
->area
] + end
;
21186 voffset
= glyph
->voffset
;
21187 s
->padding_p
= glyph
->padding_p
;
21188 glyph_not_available_p
= glyph
->glyph_not_available_p
;
21190 while (glyph
< last
21191 && glyph
->type
== CHAR_GLYPH
21192 && glyph
->voffset
== voffset
21193 /* Same face id implies same font, nowadays. */
21194 && glyph
->face_id
== face_id
21195 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
21199 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
21200 s
->char2b
+ s
->nchars
,
21202 s
->two_byte_p
= two_byte_p
;
21204 xassert (s
->nchars
<= end
- start
);
21205 s
->width
+= glyph
->pixel_width
;
21206 if (glyph
++->padding_p
!= s
->padding_p
)
21210 s
->font
= s
->face
->font
;
21212 /* If the specified font could not be loaded, use the frame's font,
21213 but record the fact that we couldn't load it in
21214 S->font_not_found_p so that we can draw rectangles for the
21215 characters of the glyph string. */
21216 if (s
->font
== NULL
|| glyph_not_available_p
)
21218 s
->font_not_found_p
= 1;
21219 s
->font
= FRAME_FONT (s
->f
);
21222 /* Adjust base line for subscript/superscript text. */
21223 s
->ybase
+= voffset
;
21225 xassert (s
->face
&& s
->face
->gc
);
21226 return glyph
- s
->row
->glyphs
[s
->area
];
21230 /* Fill glyph string S from image glyph S->first_glyph. */
21233 fill_image_glyph_string (struct glyph_string
*s
)
21235 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
21236 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
21238 s
->slice
= s
->first_glyph
->slice
.img
;
21239 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
21240 s
->font
= s
->face
->font
;
21241 s
->width
= s
->first_glyph
->pixel_width
;
21243 /* Adjust base line for subscript/superscript text. */
21244 s
->ybase
+= s
->first_glyph
->voffset
;
21248 /* Fill glyph string S from a sequence of stretch glyphs.
21250 START is the index of the first glyph to consider,
21251 END is the index of the last + 1.
21253 Value is the index of the first glyph not in S. */
21256 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
21258 struct glyph
*glyph
, *last
;
21259 int voffset
, face_id
;
21261 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
21263 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21264 last
= s
->row
->glyphs
[s
->area
] + end
;
21265 face_id
= glyph
->face_id
;
21266 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21267 s
->font
= s
->face
->font
;
21268 s
->width
= glyph
->pixel_width
;
21270 voffset
= glyph
->voffset
;
21274 && glyph
->type
== STRETCH_GLYPH
21275 && glyph
->voffset
== voffset
21276 && glyph
->face_id
== face_id
);
21278 s
->width
+= glyph
->pixel_width
;
21280 /* Adjust base line for subscript/superscript text. */
21281 s
->ybase
+= voffset
;
21283 /* The case that face->gc == 0 is handled when drawing the glyph
21284 string by calling PREPARE_FACE_FOR_DISPLAY. */
21286 return glyph
- s
->row
->glyphs
[s
->area
];
21289 static struct font_metrics
*
21290 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21292 static struct font_metrics metrics
;
21293 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21295 if (! font
|| code
== FONT_INVALID_CODE
)
21297 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21302 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21303 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21304 assumed to be zero. */
21307 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21309 *left
= *right
= 0;
21311 if (glyph
->type
== CHAR_GLYPH
)
21315 struct font_metrics
*pcm
;
21317 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21318 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21320 if (pcm
->rbearing
> pcm
->width
)
21321 *right
= pcm
->rbearing
- pcm
->width
;
21322 if (pcm
->lbearing
< 0)
21323 *left
= -pcm
->lbearing
;
21326 else if (glyph
->type
== COMPOSITE_GLYPH
)
21328 if (! glyph
->u
.cmp
.automatic
)
21330 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21332 if (cmp
->rbearing
> cmp
->pixel_width
)
21333 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21334 if (cmp
->lbearing
< 0)
21335 *left
= - cmp
->lbearing
;
21339 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21340 struct font_metrics metrics
;
21342 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21343 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21344 if (metrics
.rbearing
> metrics
.width
)
21345 *right
= metrics
.rbearing
- metrics
.width
;
21346 if (metrics
.lbearing
< 0)
21347 *left
= - metrics
.lbearing
;
21353 /* Return the index of the first glyph preceding glyph string S that
21354 is overwritten by S because of S's left overhang. Value is -1
21355 if no glyphs are overwritten. */
21358 left_overwritten (struct glyph_string
*s
)
21362 if (s
->left_overhang
)
21365 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21366 int first
= s
->first_glyph
- glyphs
;
21368 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21369 x
-= glyphs
[i
].pixel_width
;
21380 /* Return the index of the first glyph preceding glyph string S that
21381 is overwriting S because of its right overhang. Value is -1 if no
21382 glyph in front of S overwrites S. */
21385 left_overwriting (struct glyph_string
*s
)
21388 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21389 int first
= s
->first_glyph
- glyphs
;
21393 for (i
= first
- 1; i
>= 0; --i
)
21396 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21399 x
-= glyphs
[i
].pixel_width
;
21406 /* Return the index of the last glyph following glyph string S that is
21407 overwritten by S because of S's right overhang. Value is -1 if
21408 no such glyph is found. */
21411 right_overwritten (struct glyph_string
*s
)
21415 if (s
->right_overhang
)
21418 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21419 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21420 int end
= s
->row
->used
[s
->area
];
21422 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21423 x
+= glyphs
[i
].pixel_width
;
21432 /* Return the index of the last glyph following glyph string S that
21433 overwrites S because of its left overhang. Value is negative
21434 if no such glyph is found. */
21437 right_overwriting (struct glyph_string
*s
)
21440 int end
= s
->row
->used
[s
->area
];
21441 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21442 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21446 for (i
= first
; i
< end
; ++i
)
21449 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21452 x
+= glyphs
[i
].pixel_width
;
21459 /* Set background width of glyph string S. START is the index of the
21460 first glyph following S. LAST_X is the right-most x-position + 1
21461 in the drawing area. */
21464 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21466 /* If the face of this glyph string has to be drawn to the end of
21467 the drawing area, set S->extends_to_end_of_line_p. */
21469 if (start
== s
->row
->used
[s
->area
]
21470 && s
->area
== TEXT_AREA
21471 && ((s
->row
->fill_line_p
21472 && (s
->hl
== DRAW_NORMAL_TEXT
21473 || s
->hl
== DRAW_IMAGE_RAISED
21474 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21475 || s
->hl
== DRAW_MOUSE_FACE
))
21476 s
->extends_to_end_of_line_p
= 1;
21478 /* If S extends its face to the end of the line, set its
21479 background_width to the distance to the right edge of the drawing
21481 if (s
->extends_to_end_of_line_p
)
21482 s
->background_width
= last_x
- s
->x
+ 1;
21484 s
->background_width
= s
->width
;
21488 /* Compute overhangs and x-positions for glyph string S and its
21489 predecessors, or successors. X is the starting x-position for S.
21490 BACKWARD_P non-zero means process predecessors. */
21493 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21499 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21500 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21510 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21511 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21521 /* The following macros are only called from draw_glyphs below.
21522 They reference the following parameters of that function directly:
21523 `w', `row', `area', and `overlap_p'
21524 as well as the following local variables:
21525 `s', `f', and `hdc' (in W32) */
21528 /* On W32, silently add local `hdc' variable to argument list of
21529 init_glyph_string. */
21530 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21531 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21533 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21534 init_glyph_string (s, char2b, w, row, area, start, hl)
21537 /* Add a glyph string for a stretch glyph to the list of strings
21538 between HEAD and TAIL. START is the index of the stretch glyph in
21539 row area AREA of glyph row ROW. END is the index of the last glyph
21540 in that glyph row area. X is the current output position assigned
21541 to the new glyph string constructed. HL overrides that face of the
21542 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21543 is the right-most x-position of the drawing area. */
21545 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21546 and below -- keep them on one line. */
21547 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21550 s = (struct glyph_string *) alloca (sizeof *s); \
21551 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21552 START = fill_stretch_glyph_string (s, START, END); \
21553 append_glyph_string (&HEAD, &TAIL, s); \
21559 /* Add a glyph string for an image glyph to the list of strings
21560 between HEAD and TAIL. START is the index of the image glyph in
21561 row area AREA of glyph row ROW. END is the index of the last glyph
21562 in that glyph row area. X is the current output position assigned
21563 to the new glyph string constructed. HL overrides that face of the
21564 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21565 is the right-most x-position of the drawing area. */
21567 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21570 s = (struct glyph_string *) alloca (sizeof *s); \
21571 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21572 fill_image_glyph_string (s); \
21573 append_glyph_string (&HEAD, &TAIL, s); \
21580 /* Add a glyph string for a sequence of character glyphs to the list
21581 of strings between HEAD and TAIL. START is the index of the first
21582 glyph in row area AREA of glyph row ROW that is part of the new
21583 glyph string. END is the index of the last glyph in that glyph row
21584 area. X is the current output position assigned to the new glyph
21585 string constructed. HL overrides that face of the glyph; e.g. it
21586 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21587 right-most x-position of the drawing area. */
21589 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21595 face_id = (row)->glyphs[area][START].face_id; \
21597 s = (struct glyph_string *) alloca (sizeof *s); \
21598 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21599 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21600 append_glyph_string (&HEAD, &TAIL, s); \
21602 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21607 /* Add a glyph string for a composite sequence to the list of strings
21608 between HEAD and TAIL. START is the index of the first glyph in
21609 row area AREA of glyph row ROW that is part of the new glyph
21610 string. END is the index of the last glyph in that glyph row area.
21611 X is the current output position assigned to the new glyph string
21612 constructed. HL overrides that face of the glyph; e.g. it is
21613 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21614 x-position of the drawing area. */
21616 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21618 int face_id = (row)->glyphs[area][START].face_id; \
21619 struct face *base_face = FACE_FROM_ID (f, face_id); \
21620 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21621 struct composition *cmp = composition_table[cmp_id]; \
21623 struct glyph_string *first_s IF_LINT (= NULL); \
21626 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21628 /* Make glyph_strings for each glyph sequence that is drawable by \
21629 the same face, and append them to HEAD/TAIL. */ \
21630 for (n = 0; n < cmp->glyph_len;) \
21632 s = (struct glyph_string *) alloca (sizeof *s); \
21633 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21634 append_glyph_string (&(HEAD), &(TAIL), s); \
21640 n = fill_composite_glyph_string (s, base_face, overlaps); \
21648 /* Add a glyph string for a glyph-string sequence to the list of strings
21649 between HEAD and TAIL. */
21651 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21655 Lisp_Object gstring; \
21657 face_id = (row)->glyphs[area][START].face_id; \
21658 gstring = (composition_gstring_from_id \
21659 ((row)->glyphs[area][START].u.cmp.id)); \
21660 s = (struct glyph_string *) alloca (sizeof *s); \
21661 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21662 * LGSTRING_GLYPH_LEN (gstring)); \
21663 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21664 append_glyph_string (&(HEAD), &(TAIL), s); \
21666 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21670 /* Add a glyph string for a sequence of glyphless character's glyphs
21671 to the list of strings between HEAD and TAIL. The meanings of
21672 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21674 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21679 face_id = (row)->glyphs[area][START].face_id; \
21681 s = (struct glyph_string *) alloca (sizeof *s); \
21682 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21683 append_glyph_string (&HEAD, &TAIL, s); \
21685 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21691 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21692 of AREA of glyph row ROW on window W between indices START and END.
21693 HL overrides the face for drawing glyph strings, e.g. it is
21694 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21695 x-positions of the drawing area.
21697 This is an ugly monster macro construct because we must use alloca
21698 to allocate glyph strings (because draw_glyphs can be called
21699 asynchronously). */
21701 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21704 HEAD = TAIL = NULL; \
21705 while (START < END) \
21707 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21708 switch (first_glyph->type) \
21711 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21715 case COMPOSITE_GLYPH: \
21716 if (first_glyph->u.cmp.automatic) \
21717 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21720 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21724 case STRETCH_GLYPH: \
21725 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21729 case IMAGE_GLYPH: \
21730 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21734 case GLYPHLESS_GLYPH: \
21735 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21745 set_glyph_string_background_width (s, START, LAST_X); \
21752 /* Draw glyphs between START and END in AREA of ROW on window W,
21753 starting at x-position X. X is relative to AREA in W. HL is a
21754 face-override with the following meaning:
21756 DRAW_NORMAL_TEXT draw normally
21757 DRAW_CURSOR draw in cursor face
21758 DRAW_MOUSE_FACE draw in mouse face.
21759 DRAW_INVERSE_VIDEO draw in mode line face
21760 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21761 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21763 If OVERLAPS is non-zero, draw only the foreground of characters and
21764 clip to the physical height of ROW. Non-zero value also defines
21765 the overlapping part to be drawn:
21767 OVERLAPS_PRED overlap with preceding rows
21768 OVERLAPS_SUCC overlap with succeeding rows
21769 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21770 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21772 Value is the x-position reached, relative to AREA of W. */
21775 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21776 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21777 enum draw_glyphs_face hl
, int overlaps
)
21779 struct glyph_string
*head
, *tail
;
21780 struct glyph_string
*s
;
21781 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21782 int i
, j
, x_reached
, last_x
, area_left
= 0;
21783 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21786 ALLOCATE_HDC (hdc
, f
);
21788 /* Let's rather be paranoid than getting a SEGV. */
21789 end
= min (end
, row
->used
[area
]);
21790 start
= max (0, start
);
21791 start
= min (end
, start
);
21793 /* Translate X to frame coordinates. Set last_x to the right
21794 end of the drawing area. */
21795 if (row
->full_width_p
)
21797 /* X is relative to the left edge of W, without scroll bars
21799 area_left
= WINDOW_LEFT_EDGE_X (w
);
21800 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21804 area_left
= window_box_left (w
, area
);
21805 last_x
= area_left
+ window_box_width (w
, area
);
21809 /* Build a doubly-linked list of glyph_string structures between
21810 head and tail from what we have to draw. Note that the macro
21811 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21812 the reason we use a separate variable `i'. */
21814 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21816 x_reached
= tail
->x
+ tail
->background_width
;
21820 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21821 the row, redraw some glyphs in front or following the glyph
21822 strings built above. */
21823 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21825 struct glyph_string
*h
, *t
;
21826 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21827 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
21828 int check_mouse_face
= 0;
21831 /* If mouse highlighting is on, we may need to draw adjacent
21832 glyphs using mouse-face highlighting. */
21833 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21835 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21837 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21838 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21840 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21842 check_mouse_face
= 1;
21843 mouse_beg_col
= (row
== mouse_beg_row
)
21844 ? hlinfo
->mouse_face_beg_col
: 0;
21845 mouse_end_col
= (row
== mouse_end_row
)
21846 ? hlinfo
->mouse_face_end_col
21847 : row
->used
[TEXT_AREA
];
21851 /* Compute overhangs for all glyph strings. */
21852 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21853 for (s
= head
; s
; s
= s
->next
)
21854 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21856 /* Prepend glyph strings for glyphs in front of the first glyph
21857 string that are overwritten because of the first glyph
21858 string's left overhang. The background of all strings
21859 prepended must be drawn because the first glyph string
21861 i
= left_overwritten (head
);
21864 enum draw_glyphs_face overlap_hl
;
21866 /* If this row contains mouse highlighting, attempt to draw
21867 the overlapped glyphs with the correct highlight. This
21868 code fails if the overlap encompasses more than one glyph
21869 and mouse-highlight spans only some of these glyphs.
21870 However, making it work perfectly involves a lot more
21871 code, and I don't know if the pathological case occurs in
21872 practice, so we'll stick to this for now. --- cyd */
21873 if (check_mouse_face
21874 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21875 overlap_hl
= DRAW_MOUSE_FACE
;
21877 overlap_hl
= DRAW_NORMAL_TEXT
;
21880 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21881 overlap_hl
, dummy_x
, last_x
);
21883 compute_overhangs_and_x (t
, head
->x
, 1);
21884 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21888 /* Prepend glyph strings for glyphs in front of the first glyph
21889 string that overwrite that glyph string because of their
21890 right overhang. For these strings, only the foreground must
21891 be drawn, because it draws over the glyph string at `head'.
21892 The background must not be drawn because this would overwrite
21893 right overhangs of preceding glyphs for which no glyph
21895 i
= left_overwriting (head
);
21898 enum draw_glyphs_face overlap_hl
;
21900 if (check_mouse_face
21901 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21902 overlap_hl
= DRAW_MOUSE_FACE
;
21904 overlap_hl
= DRAW_NORMAL_TEXT
;
21907 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21908 overlap_hl
, dummy_x
, last_x
);
21909 for (s
= h
; s
; s
= s
->next
)
21910 s
->background_filled_p
= 1;
21911 compute_overhangs_and_x (t
, head
->x
, 1);
21912 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21915 /* Append glyphs strings for glyphs following the last glyph
21916 string tail that are overwritten by tail. The background of
21917 these strings has to be drawn because tail's foreground draws
21919 i
= right_overwritten (tail
);
21922 enum draw_glyphs_face overlap_hl
;
21924 if (check_mouse_face
21925 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21926 overlap_hl
= DRAW_MOUSE_FACE
;
21928 overlap_hl
= DRAW_NORMAL_TEXT
;
21930 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21931 overlap_hl
, x
, last_x
);
21932 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21933 we don't have `end = i;' here. */
21934 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21935 append_glyph_string_lists (&head
, &tail
, h
, t
);
21939 /* Append glyph strings for glyphs following the last glyph
21940 string tail that overwrite tail. The foreground of such
21941 glyphs has to be drawn because it writes into the background
21942 of tail. The background must not be drawn because it could
21943 paint over the foreground of following glyphs. */
21944 i
= right_overwriting (tail
);
21947 enum draw_glyphs_face overlap_hl
;
21948 if (check_mouse_face
21949 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21950 overlap_hl
= DRAW_MOUSE_FACE
;
21952 overlap_hl
= DRAW_NORMAL_TEXT
;
21955 i
++; /* We must include the Ith glyph. */
21956 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21957 overlap_hl
, x
, last_x
);
21958 for (s
= h
; s
; s
= s
->next
)
21959 s
->background_filled_p
= 1;
21960 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21961 append_glyph_string_lists (&head
, &tail
, h
, t
);
21963 if (clip_head
|| clip_tail
)
21964 for (s
= head
; s
; s
= s
->next
)
21966 s
->clip_head
= clip_head
;
21967 s
->clip_tail
= clip_tail
;
21971 /* Draw all strings. */
21972 for (s
= head
; s
; s
= s
->next
)
21973 FRAME_RIF (f
)->draw_glyph_string (s
);
21976 /* When focus a sole frame and move horizontally, this sets on_p to 0
21977 causing a failure to erase prev cursor position. */
21978 if (area
== TEXT_AREA
21979 && !row
->full_width_p
21980 /* When drawing overlapping rows, only the glyph strings'
21981 foreground is drawn, which doesn't erase a cursor
21985 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21986 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21987 : (tail
? tail
->x
+ tail
->background_width
: x
));
21991 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21992 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21996 /* Value is the x-position up to which drawn, relative to AREA of W.
21997 This doesn't include parts drawn because of overhangs. */
21998 if (row
->full_width_p
)
21999 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
22001 x_reached
-= area_left
;
22003 RELEASE_HDC (hdc
, f
);
22008 /* Expand row matrix if too narrow. Don't expand if area
22011 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
22013 if (!fonts_changed_p \
22014 && (it->glyph_row->glyphs[area] \
22015 < it->glyph_row->glyphs[area + 1])) \
22017 it->w->ncols_scale_factor++; \
22018 fonts_changed_p = 1; \
22022 /* Store one glyph for IT->char_to_display in IT->glyph_row.
22023 Called from x_produce_glyphs when IT->glyph_row is non-null. */
22026 append_glyph (struct it
*it
)
22028 struct glyph
*glyph
;
22029 enum glyph_row_area area
= it
->area
;
22031 xassert (it
->glyph_row
);
22032 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
22034 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22035 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22037 /* If the glyph row is reversed, we need to prepend the glyph
22038 rather than append it. */
22039 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22043 /* Make room for the additional glyph. */
22044 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22046 glyph
= it
->glyph_row
->glyphs
[area
];
22048 glyph
->charpos
= CHARPOS (it
->position
);
22049 glyph
->object
= it
->object
;
22050 if (it
->pixel_width
> 0)
22052 glyph
->pixel_width
= it
->pixel_width
;
22053 glyph
->padding_p
= 0;
22057 /* Assure at least 1-pixel width. Otherwise, cursor can't
22058 be displayed correctly. */
22059 glyph
->pixel_width
= 1;
22060 glyph
->padding_p
= 1;
22062 glyph
->ascent
= it
->ascent
;
22063 glyph
->descent
= it
->descent
;
22064 glyph
->voffset
= it
->voffset
;
22065 glyph
->type
= CHAR_GLYPH
;
22066 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22067 glyph
->multibyte_p
= it
->multibyte_p
;
22068 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22069 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22070 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22071 || it
->phys_descent
> it
->descent
);
22072 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
22073 glyph
->face_id
= it
->face_id
;
22074 glyph
->u
.ch
= it
->char_to_display
;
22075 glyph
->slice
.img
= null_glyph_slice
;
22076 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22079 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22080 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22082 glyph
->bidi_type
= it
->bidi_it
.type
;
22086 glyph
->resolved_level
= 0;
22087 glyph
->bidi_type
= UNKNOWN_BT
;
22089 ++it
->glyph_row
->used
[area
];
22092 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22095 /* Store one glyph for the composition IT->cmp_it.id in
22096 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
22100 append_composite_glyph (struct it
*it
)
22102 struct glyph
*glyph
;
22103 enum glyph_row_area area
= it
->area
;
22105 xassert (it
->glyph_row
);
22107 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22108 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22110 /* If the glyph row is reversed, we need to prepend the glyph
22111 rather than append it. */
22112 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
22116 /* Make room for the new glyph. */
22117 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
22119 glyph
= it
->glyph_row
->glyphs
[it
->area
];
22121 glyph
->charpos
= it
->cmp_it
.charpos
;
22122 glyph
->object
= it
->object
;
22123 glyph
->pixel_width
= it
->pixel_width
;
22124 glyph
->ascent
= it
->ascent
;
22125 glyph
->descent
= it
->descent
;
22126 glyph
->voffset
= it
->voffset
;
22127 glyph
->type
= COMPOSITE_GLYPH
;
22128 if (it
->cmp_it
.ch
< 0)
22130 glyph
->u
.cmp
.automatic
= 0;
22131 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22132 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
22136 glyph
->u
.cmp
.automatic
= 1;
22137 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22138 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
22139 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
22141 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22142 glyph
->multibyte_p
= it
->multibyte_p
;
22143 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22144 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22145 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22146 || it
->phys_descent
> it
->descent
);
22147 glyph
->padding_p
= 0;
22148 glyph
->glyph_not_available_p
= 0;
22149 glyph
->face_id
= it
->face_id
;
22150 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22153 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22154 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22156 glyph
->bidi_type
= it
->bidi_it
.type
;
22158 ++it
->glyph_row
->used
[area
];
22161 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22165 /* Change IT->ascent and IT->height according to the setting of
22169 take_vertical_position_into_account (struct it
*it
)
22173 if (it
->voffset
< 0)
22174 /* Increase the ascent so that we can display the text higher
22176 it
->ascent
-= it
->voffset
;
22178 /* Increase the descent so that we can display the text lower
22180 it
->descent
+= it
->voffset
;
22185 /* Produce glyphs/get display metrics for the image IT is loaded with.
22186 See the description of struct display_iterator in dispextern.h for
22187 an overview of struct display_iterator. */
22190 produce_image_glyph (struct it
*it
)
22194 int glyph_ascent
, crop
;
22195 struct glyph_slice slice
;
22197 xassert (it
->what
== IT_IMAGE
);
22199 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22201 /* Make sure X resources of the face is loaded. */
22202 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22204 if (it
->image_id
< 0)
22206 /* Fringe bitmap. */
22207 it
->ascent
= it
->phys_ascent
= 0;
22208 it
->descent
= it
->phys_descent
= 0;
22209 it
->pixel_width
= 0;
22214 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
22216 /* Make sure X resources of the image is loaded. */
22217 prepare_image_for_display (it
->f
, img
);
22219 slice
.x
= slice
.y
= 0;
22220 slice
.width
= img
->width
;
22221 slice
.height
= img
->height
;
22223 if (INTEGERP (it
->slice
.x
))
22224 slice
.x
= XINT (it
->slice
.x
);
22225 else if (FLOATP (it
->slice
.x
))
22226 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
22228 if (INTEGERP (it
->slice
.y
))
22229 slice
.y
= XINT (it
->slice
.y
);
22230 else if (FLOATP (it
->slice
.y
))
22231 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
22233 if (INTEGERP (it
->slice
.width
))
22234 slice
.width
= XINT (it
->slice
.width
);
22235 else if (FLOATP (it
->slice
.width
))
22236 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
22238 if (INTEGERP (it
->slice
.height
))
22239 slice
.height
= XINT (it
->slice
.height
);
22240 else if (FLOATP (it
->slice
.height
))
22241 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
22243 if (slice
.x
>= img
->width
)
22244 slice
.x
= img
->width
;
22245 if (slice
.y
>= img
->height
)
22246 slice
.y
= img
->height
;
22247 if (slice
.x
+ slice
.width
>= img
->width
)
22248 slice
.width
= img
->width
- slice
.x
;
22249 if (slice
.y
+ slice
.height
> img
->height
)
22250 slice
.height
= img
->height
- slice
.y
;
22252 if (slice
.width
== 0 || slice
.height
== 0)
22255 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
22257 it
->descent
= slice
.height
- glyph_ascent
;
22259 it
->descent
+= img
->vmargin
;
22260 if (slice
.y
+ slice
.height
== img
->height
)
22261 it
->descent
+= img
->vmargin
;
22262 it
->phys_descent
= it
->descent
;
22264 it
->pixel_width
= slice
.width
;
22266 it
->pixel_width
+= img
->hmargin
;
22267 if (slice
.x
+ slice
.width
== img
->width
)
22268 it
->pixel_width
+= img
->hmargin
;
22270 /* It's quite possible for images to have an ascent greater than
22271 their height, so don't get confused in that case. */
22272 if (it
->descent
< 0)
22277 if (face
->box
!= FACE_NO_BOX
)
22279 if (face
->box_line_width
> 0)
22282 it
->ascent
+= face
->box_line_width
;
22283 if (slice
.y
+ slice
.height
== img
->height
)
22284 it
->descent
+= face
->box_line_width
;
22287 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22288 it
->pixel_width
+= eabs (face
->box_line_width
);
22289 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22290 it
->pixel_width
+= eabs (face
->box_line_width
);
22293 take_vertical_position_into_account (it
);
22295 /* Automatically crop wide image glyphs at right edge so we can
22296 draw the cursor on same display row. */
22297 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22298 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22300 it
->pixel_width
-= crop
;
22301 slice
.width
-= crop
;
22306 struct glyph
*glyph
;
22307 enum glyph_row_area area
= it
->area
;
22309 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22310 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22312 glyph
->charpos
= CHARPOS (it
->position
);
22313 glyph
->object
= it
->object
;
22314 glyph
->pixel_width
= it
->pixel_width
;
22315 glyph
->ascent
= glyph_ascent
;
22316 glyph
->descent
= it
->descent
;
22317 glyph
->voffset
= it
->voffset
;
22318 glyph
->type
= IMAGE_GLYPH
;
22319 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22320 glyph
->multibyte_p
= it
->multibyte_p
;
22321 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22322 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22323 glyph
->overlaps_vertically_p
= 0;
22324 glyph
->padding_p
= 0;
22325 glyph
->glyph_not_available_p
= 0;
22326 glyph
->face_id
= it
->face_id
;
22327 glyph
->u
.img_id
= img
->id
;
22328 glyph
->slice
.img
= slice
;
22329 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22332 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22333 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22335 glyph
->bidi_type
= it
->bidi_it
.type
;
22337 ++it
->glyph_row
->used
[area
];
22340 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22345 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22346 of the glyph, WIDTH and HEIGHT are the width and height of the
22347 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22350 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22351 int width
, int height
, int ascent
)
22353 struct glyph
*glyph
;
22354 enum glyph_row_area area
= it
->area
;
22356 xassert (ascent
>= 0 && ascent
<= height
);
22358 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22359 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22361 /* If the glyph row is reversed, we need to prepend the glyph
22362 rather than append it. */
22363 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22367 /* Make room for the additional glyph. */
22368 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22370 glyph
= it
->glyph_row
->glyphs
[area
];
22372 glyph
->charpos
= CHARPOS (it
->position
);
22373 glyph
->object
= object
;
22374 glyph
->pixel_width
= width
;
22375 glyph
->ascent
= ascent
;
22376 glyph
->descent
= height
- ascent
;
22377 glyph
->voffset
= it
->voffset
;
22378 glyph
->type
= STRETCH_GLYPH
;
22379 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22380 glyph
->multibyte_p
= it
->multibyte_p
;
22381 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22382 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22383 glyph
->overlaps_vertically_p
= 0;
22384 glyph
->padding_p
= 0;
22385 glyph
->glyph_not_available_p
= 0;
22386 glyph
->face_id
= it
->face_id
;
22387 glyph
->u
.stretch
.ascent
= ascent
;
22388 glyph
->u
.stretch
.height
= height
;
22389 glyph
->slice
.img
= null_glyph_slice
;
22390 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22393 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22394 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22396 glyph
->bidi_type
= it
->bidi_it
.type
;
22400 glyph
->resolved_level
= 0;
22401 glyph
->bidi_type
= UNKNOWN_BT
;
22403 ++it
->glyph_row
->used
[area
];
22406 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22410 /* Produce a stretch glyph for iterator IT. IT->object is the value
22411 of the glyph property displayed. The value must be a list
22412 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22415 1. `:width WIDTH' specifies that the space should be WIDTH *
22416 canonical char width wide. WIDTH may be an integer or floating
22419 2. `:relative-width FACTOR' specifies that the width of the stretch
22420 should be computed from the width of the first character having the
22421 `glyph' property, and should be FACTOR times that width.
22423 3. `:align-to HPOS' specifies that the space should be wide enough
22424 to reach HPOS, a value in canonical character units.
22426 Exactly one of the above pairs must be present.
22428 4. `:height HEIGHT' specifies that the height of the stretch produced
22429 should be HEIGHT, measured in canonical character units.
22431 5. `:relative-height FACTOR' specifies that the height of the
22432 stretch should be FACTOR times the height of the characters having
22433 the glyph property.
22435 Either none or exactly one of 4 or 5 must be present.
22437 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22438 of the stretch should be used for the ascent of the stretch.
22439 ASCENT must be in the range 0 <= ASCENT <= 100. */
22442 produce_stretch_glyph (struct it
*it
)
22444 /* (space :width WIDTH :height HEIGHT ...) */
22445 Lisp_Object prop
, plist
;
22446 int width
= 0, height
= 0, align_to
= -1;
22447 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22450 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22451 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22453 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22455 /* List should start with `space'. */
22456 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22457 plist
= XCDR (it
->object
);
22459 /* Compute the width of the stretch. */
22460 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22461 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22463 /* Absolute width `:width WIDTH' specified and valid. */
22464 zero_width_ok_p
= 1;
22467 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22470 /* Relative width `:relative-width FACTOR' specified and valid.
22471 Compute the width of the characters having the `glyph'
22474 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22477 if (it
->multibyte_p
)
22478 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22481 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22482 if (! ASCII_CHAR_P (it2
.c
))
22483 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22486 it2
.glyph_row
= NULL
;
22487 it2
.what
= IT_CHARACTER
;
22488 x_produce_glyphs (&it2
);
22489 width
= NUMVAL (prop
) * it2
.pixel_width
;
22491 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22492 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22494 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22495 align_to
= (align_to
< 0
22497 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22498 else if (align_to
< 0)
22499 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22500 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22501 zero_width_ok_p
= 1;
22504 /* Nothing specified -> width defaults to canonical char width. */
22505 width
= FRAME_COLUMN_WIDTH (it
->f
);
22507 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22510 /* Compute height. */
22511 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22512 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22515 zero_height_ok_p
= 1;
22517 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22519 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22521 height
= FONT_HEIGHT (font
);
22523 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22526 /* Compute percentage of height used for ascent. If
22527 `:ascent ASCENT' is present and valid, use that. Otherwise,
22528 derive the ascent from the font in use. */
22529 if (prop
= Fplist_get (plist
, QCascent
),
22530 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22531 ascent
= height
* NUMVAL (prop
) / 100.0;
22532 else if (!NILP (prop
)
22533 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22534 ascent
= min (max (0, (int)tem
), height
);
22536 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22538 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22539 && it
->current_x
+ width
> it
->last_visible_x
)
22540 width
= it
->last_visible_x
- it
->current_x
- 1;
22542 if (width
> 0 && height
> 0 && it
->glyph_row
)
22544 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22545 if (!STRINGP (object
))
22546 object
= it
->w
->buffer
;
22547 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22550 it
->pixel_width
= width
;
22551 it
->ascent
= it
->phys_ascent
= ascent
;
22552 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22553 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22555 take_vertical_position_into_account (it
);
22558 /* Calculate line-height and line-spacing properties.
22559 An integer value specifies explicit pixel value.
22560 A float value specifies relative value to current face height.
22561 A cons (float . face-name) specifies relative value to
22562 height of specified face font.
22564 Returns height in pixels, or nil. */
22568 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22569 int boff
, int override
)
22571 Lisp_Object face_name
= Qnil
;
22572 int ascent
, descent
, height
;
22574 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22579 face_name
= XCAR (val
);
22581 if (!NUMBERP (val
))
22582 val
= make_number (1);
22583 if (NILP (face_name
))
22585 height
= it
->ascent
+ it
->descent
;
22590 if (NILP (face_name
))
22592 font
= FRAME_FONT (it
->f
);
22593 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22595 else if (EQ (face_name
, Qt
))
22604 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22606 return make_number (-1);
22608 face
= FACE_FROM_ID (it
->f
, face_id
);
22611 return make_number (-1);
22612 boff
= font
->baseline_offset
;
22613 if (font
->vertical_centering
)
22614 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22617 ascent
= FONT_BASE (font
) + boff
;
22618 descent
= FONT_DESCENT (font
) - boff
;
22622 it
->override_ascent
= ascent
;
22623 it
->override_descent
= descent
;
22624 it
->override_boff
= boff
;
22627 height
= ascent
+ descent
;
22631 height
= (int)(XFLOAT_DATA (val
) * height
);
22632 else if (INTEGERP (val
))
22633 height
*= XINT (val
);
22635 return make_number (height
);
22639 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22640 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22641 and only if this is for a character for which no font was found.
22643 If the display method (it->glyphless_method) is
22644 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22645 length of the acronym or the hexadecimal string, UPPER_XOFF and
22646 UPPER_YOFF are pixel offsets for the upper part of the string,
22647 LOWER_XOFF and LOWER_YOFF are for the lower part.
22649 For the other display methods, LEN through LOWER_YOFF are zero. */
22652 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22653 short upper_xoff
, short upper_yoff
,
22654 short lower_xoff
, short lower_yoff
)
22656 struct glyph
*glyph
;
22657 enum glyph_row_area area
= it
->area
;
22659 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22660 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22662 /* If the glyph row is reversed, we need to prepend the glyph
22663 rather than append it. */
22664 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22668 /* Make room for the additional glyph. */
22669 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22671 glyph
= it
->glyph_row
->glyphs
[area
];
22673 glyph
->charpos
= CHARPOS (it
->position
);
22674 glyph
->object
= it
->object
;
22675 glyph
->pixel_width
= it
->pixel_width
;
22676 glyph
->ascent
= it
->ascent
;
22677 glyph
->descent
= it
->descent
;
22678 glyph
->voffset
= it
->voffset
;
22679 glyph
->type
= GLYPHLESS_GLYPH
;
22680 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22681 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22682 glyph
->u
.glyphless
.len
= len
;
22683 glyph
->u
.glyphless
.ch
= it
->c
;
22684 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22685 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22686 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22687 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22688 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22689 glyph
->multibyte_p
= it
->multibyte_p
;
22690 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22691 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22692 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22693 || it
->phys_descent
> it
->descent
);
22694 glyph
->padding_p
= 0;
22695 glyph
->glyph_not_available_p
= 0;
22696 glyph
->face_id
= face_id
;
22697 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22700 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22701 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22703 glyph
->bidi_type
= it
->bidi_it
.type
;
22705 ++it
->glyph_row
->used
[area
];
22708 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22712 /* Produce a glyph for a glyphless character for iterator IT.
22713 IT->glyphless_method specifies which method to use for displaying
22714 the character. See the description of enum
22715 glyphless_display_method in dispextern.h for the detail.
22717 FOR_NO_FONT is nonzero if and only if this is for a character for
22718 which no font was found. ACRONYM, if non-nil, is an acronym string
22719 for the character. */
22722 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22727 int base_width
, base_height
, width
, height
;
22728 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22731 /* Get the metrics of the base font. We always refer to the current
22733 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22734 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22735 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22736 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22737 base_height
= it
->ascent
+ it
->descent
;
22738 base_width
= font
->average_width
;
22740 /* Get a face ID for the glyph by utilizing a cache (the same way as
22741 doen for `escape-glyph' in get_next_display_element). */
22742 if (it
->f
== last_glyphless_glyph_frame
22743 && it
->face_id
== last_glyphless_glyph_face_id
)
22745 face_id
= last_glyphless_glyph_merged_face_id
;
22749 /* Merge the `glyphless-char' face into the current face. */
22750 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22751 last_glyphless_glyph_frame
= it
->f
;
22752 last_glyphless_glyph_face_id
= it
->face_id
;
22753 last_glyphless_glyph_merged_face_id
= face_id
;
22756 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22758 it
->pixel_width
= THIN_SPACE_WIDTH
;
22760 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22762 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22764 width
= CHAR_WIDTH (it
->c
);
22767 else if (width
> 4)
22769 it
->pixel_width
= base_width
* width
;
22771 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22777 unsigned int code
[6];
22779 int ascent
, descent
;
22780 struct font_metrics metrics_upper
, metrics_lower
;
22782 face
= FACE_FROM_ID (it
->f
, face_id
);
22783 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22784 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22786 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22788 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22789 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22790 if (CONSP (acronym
))
22791 acronym
= XCAR (acronym
);
22792 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
22796 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22797 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22800 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22801 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22802 upper_len
= (len
+ 1) / 2;
22803 font
->driver
->text_extents (font
, code
, upper_len
,
22805 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22810 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22811 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22812 upper_xoff
= upper_yoff
= 2; /* the typical case */
22813 if (base_width
>= width
)
22815 /* Align the upper to the left, the lower to the right. */
22816 it
->pixel_width
= base_width
;
22817 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22821 /* Center the shorter one. */
22822 it
->pixel_width
= width
;
22823 if (metrics_upper
.width
>= metrics_lower
.width
)
22824 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22827 /* FIXME: This code doesn't look right. It formerly was
22828 missing the "lower_xoff = 0;", which couldn't have
22829 been right since it left lower_xoff uninitialized. */
22831 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22835 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22836 top, bottom, and between upper and lower strings. */
22837 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22838 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22839 /* Center vertically.
22840 H:base_height, D:base_descent
22841 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22843 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22844 descent = D - H/2 + h/2;
22845 lower_yoff = descent - 2 - ld;
22846 upper_yoff = lower_yoff - la - 1 - ud; */
22847 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22848 descent
= it
->descent
- (base_height
- height
) / 2;
22849 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22850 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22851 - metrics_upper
.descent
);
22852 /* Don't make the height shorter than the base height. */
22853 if (height
> base_height
)
22855 it
->ascent
= ascent
;
22856 it
->descent
= descent
;
22860 it
->phys_ascent
= it
->ascent
;
22861 it
->phys_descent
= it
->descent
;
22863 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22864 upper_xoff
, upper_yoff
,
22865 lower_xoff
, lower_yoff
);
22867 take_vertical_position_into_account (it
);
22872 Produce glyphs/get display metrics for the display element IT is
22873 loaded with. See the description of struct it in dispextern.h
22874 for an overview of struct it. */
22877 x_produce_glyphs (struct it
*it
)
22879 int extra_line_spacing
= it
->extra_line_spacing
;
22881 it
->glyph_not_available_p
= 0;
22883 if (it
->what
== IT_CHARACTER
)
22886 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22887 struct font
*font
= face
->font
;
22888 struct font_metrics
*pcm
= NULL
;
22889 int boff
; /* baseline offset */
22893 /* When no suitable font is found, display this character by
22894 the method specified in the first extra slot of
22895 Vglyphless_char_display. */
22896 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22898 xassert (it
->what
== IT_GLYPHLESS
);
22899 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22903 boff
= font
->baseline_offset
;
22904 if (font
->vertical_centering
)
22905 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22907 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22913 if (it
->override_ascent
>= 0)
22915 it
->ascent
= it
->override_ascent
;
22916 it
->descent
= it
->override_descent
;
22917 boff
= it
->override_boff
;
22921 it
->ascent
= FONT_BASE (font
) + boff
;
22922 it
->descent
= FONT_DESCENT (font
) - boff
;
22925 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22927 pcm
= get_per_char_metric (font
, &char2b
);
22928 if (pcm
->width
== 0
22929 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22935 it
->phys_ascent
= pcm
->ascent
+ boff
;
22936 it
->phys_descent
= pcm
->descent
- boff
;
22937 it
->pixel_width
= pcm
->width
;
22941 it
->glyph_not_available_p
= 1;
22942 it
->phys_ascent
= it
->ascent
;
22943 it
->phys_descent
= it
->descent
;
22944 it
->pixel_width
= font
->space_width
;
22947 if (it
->constrain_row_ascent_descent_p
)
22949 if (it
->descent
> it
->max_descent
)
22951 it
->ascent
+= it
->descent
- it
->max_descent
;
22952 it
->descent
= it
->max_descent
;
22954 if (it
->ascent
> it
->max_ascent
)
22956 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22957 it
->ascent
= it
->max_ascent
;
22959 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22960 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22961 extra_line_spacing
= 0;
22964 /* If this is a space inside a region of text with
22965 `space-width' property, change its width. */
22966 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22968 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22970 /* If face has a box, add the box thickness to the character
22971 height. If character has a box line to the left and/or
22972 right, add the box line width to the character's width. */
22973 if (face
->box
!= FACE_NO_BOX
)
22975 int thick
= face
->box_line_width
;
22979 it
->ascent
+= thick
;
22980 it
->descent
+= thick
;
22985 if (it
->start_of_box_run_p
)
22986 it
->pixel_width
+= thick
;
22987 if (it
->end_of_box_run_p
)
22988 it
->pixel_width
+= thick
;
22991 /* If face has an overline, add the height of the overline
22992 (1 pixel) and a 1 pixel margin to the character height. */
22993 if (face
->overline_p
)
22994 it
->ascent
+= overline_margin
;
22996 if (it
->constrain_row_ascent_descent_p
)
22998 if (it
->ascent
> it
->max_ascent
)
22999 it
->ascent
= it
->max_ascent
;
23000 if (it
->descent
> it
->max_descent
)
23001 it
->descent
= it
->max_descent
;
23004 take_vertical_position_into_account (it
);
23006 /* If we have to actually produce glyphs, do it. */
23011 /* Translate a space with a `space-width' property
23012 into a stretch glyph. */
23013 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
23014 / FONT_HEIGHT (font
));
23015 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23016 it
->ascent
+ it
->descent
, ascent
);
23021 /* If characters with lbearing or rbearing are displayed
23022 in this line, record that fact in a flag of the
23023 glyph row. This is used to optimize X output code. */
23024 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
23025 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23027 if (! stretched_p
&& it
->pixel_width
== 0)
23028 /* We assure that all visible glyphs have at least 1-pixel
23030 it
->pixel_width
= 1;
23032 else if (it
->char_to_display
== '\n')
23034 /* A newline has no width, but we need the height of the
23035 line. But if previous part of the line sets a height,
23036 don't increase that height */
23038 Lisp_Object height
;
23039 Lisp_Object total_height
= Qnil
;
23041 it
->override_ascent
= -1;
23042 it
->pixel_width
= 0;
23045 height
= get_it_property (it
, Qline_height
);
23046 /* Split (line-height total-height) list */
23048 && CONSP (XCDR (height
))
23049 && NILP (XCDR (XCDR (height
))))
23051 total_height
= XCAR (XCDR (height
));
23052 height
= XCAR (height
);
23054 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
23056 if (it
->override_ascent
>= 0)
23058 it
->ascent
= it
->override_ascent
;
23059 it
->descent
= it
->override_descent
;
23060 boff
= it
->override_boff
;
23064 it
->ascent
= FONT_BASE (font
) + boff
;
23065 it
->descent
= FONT_DESCENT (font
) - boff
;
23068 if (EQ (height
, Qt
))
23070 if (it
->descent
> it
->max_descent
)
23072 it
->ascent
+= it
->descent
- it
->max_descent
;
23073 it
->descent
= it
->max_descent
;
23075 if (it
->ascent
> it
->max_ascent
)
23077 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23078 it
->ascent
= it
->max_ascent
;
23080 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23081 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23082 it
->constrain_row_ascent_descent_p
= 1;
23083 extra_line_spacing
= 0;
23087 Lisp_Object spacing
;
23089 it
->phys_ascent
= it
->ascent
;
23090 it
->phys_descent
= it
->descent
;
23092 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
23093 && face
->box
!= FACE_NO_BOX
23094 && face
->box_line_width
> 0)
23096 it
->ascent
+= face
->box_line_width
;
23097 it
->descent
+= face
->box_line_width
;
23100 && XINT (height
) > it
->ascent
+ it
->descent
)
23101 it
->ascent
= XINT (height
) - it
->descent
;
23103 if (!NILP (total_height
))
23104 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
23107 spacing
= get_it_property (it
, Qline_spacing
);
23108 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
23110 if (INTEGERP (spacing
))
23112 extra_line_spacing
= XINT (spacing
);
23113 if (!NILP (total_height
))
23114 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
23118 else /* i.e. (it->char_to_display == '\t') */
23120 if (font
->space_width
> 0)
23122 int tab_width
= it
->tab_width
* font
->space_width
;
23123 int x
= it
->current_x
+ it
->continuation_lines_width
;
23124 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
23126 /* If the distance from the current position to the next tab
23127 stop is less than a space character width, use the
23128 tab stop after that. */
23129 if (next_tab_x
- x
< font
->space_width
)
23130 next_tab_x
+= tab_width
;
23132 it
->pixel_width
= next_tab_x
- x
;
23134 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
23135 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
23139 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23140 it
->ascent
+ it
->descent
, it
->ascent
);
23145 it
->pixel_width
= 0;
23150 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
23152 /* A static composition.
23154 Note: A composition is represented as one glyph in the
23155 glyph matrix. There are no padding glyphs.
23157 Important note: pixel_width, ascent, and descent are the
23158 values of what is drawn by draw_glyphs (i.e. the values of
23159 the overall glyphs composed). */
23160 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23161 int boff
; /* baseline offset */
23162 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
23163 int glyph_len
= cmp
->glyph_len
;
23164 struct font
*font
= face
->font
;
23168 /* If we have not yet calculated pixel size data of glyphs of
23169 the composition for the current face font, calculate them
23170 now. Theoretically, we have to check all fonts for the
23171 glyphs, but that requires much time and memory space. So,
23172 here we check only the font of the first glyph. This may
23173 lead to incorrect display, but it's very rare, and C-l
23174 (recenter-top-bottom) can correct the display anyway. */
23175 if (! cmp
->font
|| cmp
->font
!= font
)
23177 /* Ascent and descent of the font of the first character
23178 of this composition (adjusted by baseline offset).
23179 Ascent and descent of overall glyphs should not be less
23180 than these, respectively. */
23181 int font_ascent
, font_descent
, font_height
;
23182 /* Bounding box of the overall glyphs. */
23183 int leftmost
, rightmost
, lowest
, highest
;
23184 int lbearing
, rbearing
;
23185 int i
, width
, ascent
, descent
;
23186 int left_padded
= 0, right_padded
= 0;
23187 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
23189 struct font_metrics
*pcm
;
23190 int font_not_found_p
;
23193 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
23194 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
23196 if (glyph_len
< cmp
->glyph_len
)
23198 for (i
= 0; i
< glyph_len
; i
++)
23200 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
23202 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23207 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
23208 : IT_CHARPOS (*it
));
23209 /* If no suitable font is found, use the default font. */
23210 font_not_found_p
= font
== NULL
;
23211 if (font_not_found_p
)
23213 face
= face
->ascii_face
;
23216 boff
= font
->baseline_offset
;
23217 if (font
->vertical_centering
)
23218 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23219 font_ascent
= FONT_BASE (font
) + boff
;
23220 font_descent
= FONT_DESCENT (font
) - boff
;
23221 font_height
= FONT_HEIGHT (font
);
23223 cmp
->font
= (void *) font
;
23226 if (! font_not_found_p
)
23228 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
23230 pcm
= get_per_char_metric (font
, &char2b
);
23233 /* Initialize the bounding box. */
23236 width
= pcm
->width
;
23237 ascent
= pcm
->ascent
;
23238 descent
= pcm
->descent
;
23239 lbearing
= pcm
->lbearing
;
23240 rbearing
= pcm
->rbearing
;
23244 width
= font
->space_width
;
23245 ascent
= FONT_BASE (font
);
23246 descent
= FONT_DESCENT (font
);
23253 lowest
= - descent
+ boff
;
23254 highest
= ascent
+ boff
;
23256 if (! font_not_found_p
23257 && font
->default_ascent
23258 && CHAR_TABLE_P (Vuse_default_ascent
)
23259 && !NILP (Faref (Vuse_default_ascent
,
23260 make_number (it
->char_to_display
))))
23261 highest
= font
->default_ascent
+ boff
;
23263 /* Draw the first glyph at the normal position. It may be
23264 shifted to right later if some other glyphs are drawn
23266 cmp
->offsets
[i
* 2] = 0;
23267 cmp
->offsets
[i
* 2 + 1] = boff
;
23268 cmp
->lbearing
= lbearing
;
23269 cmp
->rbearing
= rbearing
;
23271 /* Set cmp->offsets for the remaining glyphs. */
23272 for (i
++; i
< glyph_len
; i
++)
23274 int left
, right
, btm
, top
;
23275 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23277 struct face
*this_face
;
23281 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23282 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23283 font
= this_face
->font
;
23289 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23291 pcm
= get_per_char_metric (font
, &char2b
);
23294 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23297 width
= pcm
->width
;
23298 ascent
= pcm
->ascent
;
23299 descent
= pcm
->descent
;
23300 lbearing
= pcm
->lbearing
;
23301 rbearing
= pcm
->rbearing
;
23302 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23304 /* Relative composition with or without
23305 alternate chars. */
23306 left
= (leftmost
+ rightmost
- width
) / 2;
23307 btm
= - descent
+ boff
;
23308 if (font
->relative_compose
23309 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23310 || NILP (Faref (Vignore_relative_composition
,
23311 make_number (ch
)))))
23314 if (- descent
>= font
->relative_compose
)
23315 /* One extra pixel between two glyphs. */
23317 else if (ascent
<= 0)
23318 /* One extra pixel between two glyphs. */
23319 btm
= lowest
- 1 - ascent
- descent
;
23324 /* A composition rule is specified by an integer
23325 value that encodes global and new reference
23326 points (GREF and NREF). GREF and NREF are
23327 specified by numbers as below:
23329 0---1---2 -- ascent
23333 9--10--11 -- center
23335 ---3---4---5--- baseline
23337 6---7---8 -- descent
23339 int rule
= COMPOSITION_RULE (cmp
, i
);
23340 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23342 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23343 grefx
= gref
% 3, nrefx
= nref
% 3;
23344 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23346 xoff
= font_height
* (xoff
- 128) / 256;
23348 yoff
= font_height
* (yoff
- 128) / 256;
23351 + grefx
* (rightmost
- leftmost
) / 2
23352 - nrefx
* width
/ 2
23355 btm
= ((grefy
== 0 ? highest
23357 : grefy
== 2 ? lowest
23358 : (highest
+ lowest
) / 2)
23359 - (nrefy
== 0 ? ascent
+ descent
23360 : nrefy
== 1 ? descent
- boff
23362 : (ascent
+ descent
) / 2)
23366 cmp
->offsets
[i
* 2] = left
;
23367 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23369 /* Update the bounding box of the overall glyphs. */
23372 right
= left
+ width
;
23373 if (left
< leftmost
)
23375 if (right
> rightmost
)
23378 top
= btm
+ descent
+ ascent
;
23384 if (cmp
->lbearing
> left
+ lbearing
)
23385 cmp
->lbearing
= left
+ lbearing
;
23386 if (cmp
->rbearing
< left
+ rbearing
)
23387 cmp
->rbearing
= left
+ rbearing
;
23391 /* If there are glyphs whose x-offsets are negative,
23392 shift all glyphs to the right and make all x-offsets
23396 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23397 cmp
->offsets
[i
* 2] -= leftmost
;
23398 rightmost
-= leftmost
;
23399 cmp
->lbearing
-= leftmost
;
23400 cmp
->rbearing
-= leftmost
;
23403 if (left_padded
&& cmp
->lbearing
< 0)
23405 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23406 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23407 rightmost
-= cmp
->lbearing
;
23408 cmp
->rbearing
-= cmp
->lbearing
;
23411 if (right_padded
&& rightmost
< cmp
->rbearing
)
23413 rightmost
= cmp
->rbearing
;
23416 cmp
->pixel_width
= rightmost
;
23417 cmp
->ascent
= highest
;
23418 cmp
->descent
= - lowest
;
23419 if (cmp
->ascent
< font_ascent
)
23420 cmp
->ascent
= font_ascent
;
23421 if (cmp
->descent
< font_descent
)
23422 cmp
->descent
= font_descent
;
23426 && (cmp
->lbearing
< 0
23427 || cmp
->rbearing
> cmp
->pixel_width
))
23428 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23430 it
->pixel_width
= cmp
->pixel_width
;
23431 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23432 it
->descent
= it
->phys_descent
= cmp
->descent
;
23433 if (face
->box
!= FACE_NO_BOX
)
23435 int thick
= face
->box_line_width
;
23439 it
->ascent
+= thick
;
23440 it
->descent
+= thick
;
23445 if (it
->start_of_box_run_p
)
23446 it
->pixel_width
+= thick
;
23447 if (it
->end_of_box_run_p
)
23448 it
->pixel_width
+= thick
;
23451 /* If face has an overline, add the height of the overline
23452 (1 pixel) and a 1 pixel margin to the character height. */
23453 if (face
->overline_p
)
23454 it
->ascent
+= overline_margin
;
23456 take_vertical_position_into_account (it
);
23457 if (it
->ascent
< 0)
23459 if (it
->descent
< 0)
23463 append_composite_glyph (it
);
23465 else if (it
->what
== IT_COMPOSITION
)
23467 /* A dynamic (automatic) composition. */
23468 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23469 Lisp_Object gstring
;
23470 struct font_metrics metrics
;
23472 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23474 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23477 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23478 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23479 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23480 it
->descent
= it
->phys_descent
= metrics
.descent
;
23481 if (face
->box
!= FACE_NO_BOX
)
23483 int thick
= face
->box_line_width
;
23487 it
->ascent
+= thick
;
23488 it
->descent
+= thick
;
23493 if (it
->start_of_box_run_p
)
23494 it
->pixel_width
+= thick
;
23495 if (it
->end_of_box_run_p
)
23496 it
->pixel_width
+= thick
;
23498 /* If face has an overline, add the height of the overline
23499 (1 pixel) and a 1 pixel margin to the character height. */
23500 if (face
->overline_p
)
23501 it
->ascent
+= overline_margin
;
23502 take_vertical_position_into_account (it
);
23503 if (it
->ascent
< 0)
23505 if (it
->descent
< 0)
23509 append_composite_glyph (it
);
23511 else if (it
->what
== IT_GLYPHLESS
)
23512 produce_glyphless_glyph (it
, 0, Qnil
);
23513 else if (it
->what
== IT_IMAGE
)
23514 produce_image_glyph (it
);
23515 else if (it
->what
== IT_STRETCH
)
23516 produce_stretch_glyph (it
);
23519 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23520 because this isn't true for images with `:ascent 100'. */
23521 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23522 if (it
->area
== TEXT_AREA
)
23523 it
->current_x
+= it
->pixel_width
;
23525 if (extra_line_spacing
> 0)
23527 it
->descent
+= extra_line_spacing
;
23528 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23529 it
->max_extra_line_spacing
= extra_line_spacing
;
23532 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23533 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23534 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23535 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23539 Output LEN glyphs starting at START at the nominal cursor position.
23540 Advance the nominal cursor over the text. The global variable
23541 updated_window contains the window being updated, updated_row is
23542 the glyph row being updated, and updated_area is the area of that
23543 row being updated. */
23546 x_write_glyphs (struct glyph
*start
, int len
)
23550 xassert (updated_window
&& updated_row
);
23553 /* Write glyphs. */
23555 hpos
= start
- updated_row
->glyphs
[updated_area
];
23556 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23557 updated_row
, updated_area
,
23559 DRAW_NORMAL_TEXT
, 0);
23561 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23562 if (updated_area
== TEXT_AREA
23563 && updated_window
->phys_cursor_on_p
23564 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23565 && updated_window
->phys_cursor
.hpos
>= hpos
23566 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23567 updated_window
->phys_cursor_on_p
= 0;
23571 /* Advance the output cursor. */
23572 output_cursor
.hpos
+= len
;
23573 output_cursor
.x
= x
;
23578 Insert LEN glyphs from START at the nominal cursor position. */
23581 x_insert_glyphs (struct glyph
*start
, int len
)
23585 int line_height
, shift_by_width
, shifted_region_width
;
23586 struct glyph_row
*row
;
23587 struct glyph
*glyph
;
23588 int frame_x
, frame_y
;
23591 xassert (updated_window
&& updated_row
);
23593 w
= updated_window
;
23594 f
= XFRAME (WINDOW_FRAME (w
));
23596 /* Get the height of the line we are in. */
23598 line_height
= row
->height
;
23600 /* Get the width of the glyphs to insert. */
23601 shift_by_width
= 0;
23602 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23603 shift_by_width
+= glyph
->pixel_width
;
23605 /* Get the width of the region to shift right. */
23606 shifted_region_width
= (window_box_width (w
, updated_area
)
23611 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23612 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23614 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23615 line_height
, shift_by_width
);
23617 /* Write the glyphs. */
23618 hpos
= start
- row
->glyphs
[updated_area
];
23619 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23621 DRAW_NORMAL_TEXT
, 0);
23623 /* Advance the output cursor. */
23624 output_cursor
.hpos
+= len
;
23625 output_cursor
.x
+= shift_by_width
;
23631 Erase the current text line from the nominal cursor position
23632 (inclusive) to pixel column TO_X (exclusive). The idea is that
23633 everything from TO_X onward is already erased.
23635 TO_X is a pixel position relative to updated_area of
23636 updated_window. TO_X == -1 means clear to the end of this area. */
23639 x_clear_end_of_line (int to_x
)
23642 struct window
*w
= updated_window
;
23643 int max_x
, min_y
, max_y
;
23644 int from_x
, from_y
, to_y
;
23646 xassert (updated_window
&& updated_row
);
23647 f
= XFRAME (w
->frame
);
23649 if (updated_row
->full_width_p
)
23650 max_x
= WINDOW_TOTAL_WIDTH (w
);
23652 max_x
= window_box_width (w
, updated_area
);
23653 max_y
= window_text_bottom_y (w
);
23655 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23656 of window. For TO_X > 0, truncate to end of drawing area. */
23662 to_x
= min (to_x
, max_x
);
23664 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23666 /* Notice if the cursor will be cleared by this operation. */
23667 if (!updated_row
->full_width_p
)
23668 notice_overwritten_cursor (w
, updated_area
,
23669 output_cursor
.x
, -1,
23671 MATRIX_ROW_BOTTOM_Y (updated_row
));
23673 from_x
= output_cursor
.x
;
23675 /* Translate to frame coordinates. */
23676 if (updated_row
->full_width_p
)
23678 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23679 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23683 int area_left
= window_box_left (w
, updated_area
);
23684 from_x
+= area_left
;
23688 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23689 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23690 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23692 /* Prevent inadvertently clearing to end of the X window. */
23693 if (to_x
> from_x
&& to_y
> from_y
)
23696 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23697 to_x
- from_x
, to_y
- from_y
);
23702 #endif /* HAVE_WINDOW_SYSTEM */
23706 /***********************************************************************
23708 ***********************************************************************/
23710 /* Value is the internal representation of the specified cursor type
23711 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23712 of the bar cursor. */
23714 static enum text_cursor_kinds
23715 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23717 enum text_cursor_kinds type
;
23722 if (EQ (arg
, Qbox
))
23723 return FILLED_BOX_CURSOR
;
23725 if (EQ (arg
, Qhollow
))
23726 return HOLLOW_BOX_CURSOR
;
23728 if (EQ (arg
, Qbar
))
23735 && EQ (XCAR (arg
), Qbar
)
23736 && INTEGERP (XCDR (arg
))
23737 && XINT (XCDR (arg
)) >= 0)
23739 *width
= XINT (XCDR (arg
));
23743 if (EQ (arg
, Qhbar
))
23746 return HBAR_CURSOR
;
23750 && EQ (XCAR (arg
), Qhbar
)
23751 && INTEGERP (XCDR (arg
))
23752 && XINT (XCDR (arg
)) >= 0)
23754 *width
= XINT (XCDR (arg
));
23755 return HBAR_CURSOR
;
23758 /* Treat anything unknown as "hollow box cursor".
23759 It was bad to signal an error; people have trouble fixing
23760 .Xdefaults with Emacs, when it has something bad in it. */
23761 type
= HOLLOW_BOX_CURSOR
;
23766 /* Set the default cursor types for specified frame. */
23768 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23773 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23774 FRAME_CURSOR_WIDTH (f
) = width
;
23776 /* By default, set up the blink-off state depending on the on-state. */
23778 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23781 FRAME_BLINK_OFF_CURSOR (f
)
23782 = get_specified_cursor_type (XCDR (tem
), &width
);
23783 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23786 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23790 #ifdef HAVE_WINDOW_SYSTEM
23792 /* Return the cursor we want to be displayed in window W. Return
23793 width of bar/hbar cursor through WIDTH arg. Return with
23794 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23795 (i.e. if the `system caret' should track this cursor).
23797 In a mini-buffer window, we want the cursor only to appear if we
23798 are reading input from this window. For the selected window, we
23799 want the cursor type given by the frame parameter or buffer local
23800 setting of cursor-type. If explicitly marked off, draw no cursor.
23801 In all other cases, we want a hollow box cursor. */
23803 static enum text_cursor_kinds
23804 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23805 int *active_cursor
)
23807 struct frame
*f
= XFRAME (w
->frame
);
23808 struct buffer
*b
= XBUFFER (w
->buffer
);
23809 int cursor_type
= DEFAULT_CURSOR
;
23810 Lisp_Object alt_cursor
;
23811 int non_selected
= 0;
23813 *active_cursor
= 1;
23816 if (cursor_in_echo_area
23817 && FRAME_HAS_MINIBUF_P (f
)
23818 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23820 if (w
== XWINDOW (echo_area_window
))
23822 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
23824 *width
= FRAME_CURSOR_WIDTH (f
);
23825 return FRAME_DESIRED_CURSOR (f
);
23828 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23831 *active_cursor
= 0;
23835 /* Detect a nonselected window or nonselected frame. */
23836 else if (w
!= XWINDOW (f
->selected_window
)
23837 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23839 *active_cursor
= 0;
23841 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23847 /* Never display a cursor in a window in which cursor-type is nil. */
23848 if (NILP (BVAR (b
, cursor_type
)))
23851 /* Get the normal cursor type for this window. */
23852 if (EQ (BVAR (b
, cursor_type
), Qt
))
23854 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23855 *width
= FRAME_CURSOR_WIDTH (f
);
23858 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23860 /* Use cursor-in-non-selected-windows instead
23861 for non-selected window or frame. */
23864 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
23865 if (!EQ (Qt
, alt_cursor
))
23866 return get_specified_cursor_type (alt_cursor
, width
);
23867 /* t means modify the normal cursor type. */
23868 if (cursor_type
== FILLED_BOX_CURSOR
)
23869 cursor_type
= HOLLOW_BOX_CURSOR
;
23870 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23872 return cursor_type
;
23875 /* Use normal cursor if not blinked off. */
23876 if (!w
->cursor_off_p
)
23878 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23880 if (cursor_type
== FILLED_BOX_CURSOR
)
23882 /* Using a block cursor on large images can be very annoying.
23883 So use a hollow cursor for "large" images.
23884 If image is not transparent (no mask), also use hollow cursor. */
23885 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23886 if (img
!= NULL
&& IMAGEP (img
->spec
))
23888 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23889 where N = size of default frame font size.
23890 This should cover most of the "tiny" icons people may use. */
23892 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23893 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23894 cursor_type
= HOLLOW_BOX_CURSOR
;
23897 else if (cursor_type
!= NO_CURSOR
)
23899 /* Display current only supports BOX and HOLLOW cursors for images.
23900 So for now, unconditionally use a HOLLOW cursor when cursor is
23901 not a solid box cursor. */
23902 cursor_type
= HOLLOW_BOX_CURSOR
;
23905 return cursor_type
;
23908 /* Cursor is blinked off, so determine how to "toggle" it. */
23910 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23911 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
23912 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23914 /* Then see if frame has specified a specific blink off cursor type. */
23915 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23917 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23918 return FRAME_BLINK_OFF_CURSOR (f
);
23922 /* Some people liked having a permanently visible blinking cursor,
23923 while others had very strong opinions against it. So it was
23924 decided to remove it. KFS 2003-09-03 */
23926 /* Finally perform built-in cursor blinking:
23927 filled box <-> hollow box
23928 wide [h]bar <-> narrow [h]bar
23929 narrow [h]bar <-> no cursor
23930 other type <-> no cursor */
23932 if (cursor_type
== FILLED_BOX_CURSOR
)
23933 return HOLLOW_BOX_CURSOR
;
23935 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23938 return cursor_type
;
23946 /* Notice when the text cursor of window W has been completely
23947 overwritten by a drawing operation that outputs glyphs in AREA
23948 starting at X0 and ending at X1 in the line starting at Y0 and
23949 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23950 the rest of the line after X0 has been written. Y coordinates
23951 are window-relative. */
23954 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23955 int x0
, int x1
, int y0
, int y1
)
23957 int cx0
, cx1
, cy0
, cy1
;
23958 struct glyph_row
*row
;
23960 if (!w
->phys_cursor_on_p
)
23962 if (area
!= TEXT_AREA
)
23965 if (w
->phys_cursor
.vpos
< 0
23966 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23967 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23968 !(row
->enabled_p
&& row
->displays_text_p
)))
23971 if (row
->cursor_in_fringe_p
)
23973 row
->cursor_in_fringe_p
= 0;
23974 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23975 w
->phys_cursor_on_p
= 0;
23979 cx0
= w
->phys_cursor
.x
;
23980 cx1
= cx0
+ w
->phys_cursor_width
;
23981 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23984 /* The cursor image will be completely removed from the
23985 screen if the output area intersects the cursor area in
23986 y-direction. When we draw in [y0 y1[, and some part of
23987 the cursor is at y < y0, that part must have been drawn
23988 before. When scrolling, the cursor is erased before
23989 actually scrolling, so we don't come here. When not
23990 scrolling, the rows above the old cursor row must have
23991 changed, and in this case these rows must have written
23992 over the cursor image.
23994 Likewise if part of the cursor is below y1, with the
23995 exception of the cursor being in the first blank row at
23996 the buffer and window end because update_text_area
23997 doesn't draw that row. (Except when it does, but
23998 that's handled in update_text_area.) */
24000 cy0
= w
->phys_cursor
.y
;
24001 cy1
= cy0
+ w
->phys_cursor_height
;
24002 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
24005 w
->phys_cursor_on_p
= 0;
24008 #endif /* HAVE_WINDOW_SYSTEM */
24011 /************************************************************************
24013 ************************************************************************/
24015 #ifdef HAVE_WINDOW_SYSTEM
24018 Fix the display of area AREA of overlapping row ROW in window W
24019 with respect to the overlapping part OVERLAPS. */
24022 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
24023 enum glyph_row_area area
, int overlaps
)
24030 for (i
= 0; i
< row
->used
[area
];)
24032 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
24034 int start
= i
, start_x
= x
;
24038 x
+= row
->glyphs
[area
][i
].pixel_width
;
24041 while (i
< row
->used
[area
]
24042 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
24044 draw_glyphs (w
, start_x
, row
, area
,
24046 DRAW_NORMAL_TEXT
, overlaps
);
24050 x
+= row
->glyphs
[area
][i
].pixel_width
;
24060 Draw the cursor glyph of window W in glyph row ROW. See the
24061 comment of draw_glyphs for the meaning of HL. */
24064 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
24065 enum draw_glyphs_face hl
)
24067 /* If cursor hpos is out of bounds, don't draw garbage. This can
24068 happen in mini-buffer windows when switching between echo area
24069 glyphs and mini-buffer. */
24070 if ((row
->reversed_p
24071 ? (w
->phys_cursor
.hpos
>= 0)
24072 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
24074 int on_p
= w
->phys_cursor_on_p
;
24076 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
24077 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
24079 w
->phys_cursor_on_p
= on_p
;
24081 if (hl
== DRAW_CURSOR
)
24082 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24083 /* When we erase the cursor, and ROW is overlapped by other
24084 rows, make sure that these overlapping parts of other rows
24086 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
24088 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24090 if (row
> w
->current_matrix
->rows
24091 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
24092 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
24093 OVERLAPS_ERASED_CURSOR
);
24095 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
24096 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
24097 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
24098 OVERLAPS_ERASED_CURSOR
);
24105 Erase the image of a cursor of window W from the screen. */
24108 erase_phys_cursor (struct window
*w
)
24110 struct frame
*f
= XFRAME (w
->frame
);
24111 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24112 int hpos
= w
->phys_cursor
.hpos
;
24113 int vpos
= w
->phys_cursor
.vpos
;
24114 int mouse_face_here_p
= 0;
24115 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
24116 struct glyph_row
*cursor_row
;
24117 struct glyph
*cursor_glyph
;
24118 enum draw_glyphs_face hl
;
24120 /* No cursor displayed or row invalidated => nothing to do on the
24122 if (w
->phys_cursor_type
== NO_CURSOR
)
24123 goto mark_cursor_off
;
24125 /* VPOS >= active_glyphs->nrows means that window has been resized.
24126 Don't bother to erase the cursor. */
24127 if (vpos
>= active_glyphs
->nrows
)
24128 goto mark_cursor_off
;
24130 /* If row containing cursor is marked invalid, there is nothing we
24132 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
24133 if (!cursor_row
->enabled_p
)
24134 goto mark_cursor_off
;
24136 /* If line spacing is > 0, old cursor may only be partially visible in
24137 window after split-window. So adjust visible height. */
24138 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
24139 window_text_bottom_y (w
) - cursor_row
->y
);
24141 /* If row is completely invisible, don't attempt to delete a cursor which
24142 isn't there. This can happen if cursor is at top of a window, and
24143 we switch to a buffer with a header line in that window. */
24144 if (cursor_row
->visible_height
<= 0)
24145 goto mark_cursor_off
;
24147 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
24148 if (cursor_row
->cursor_in_fringe_p
)
24150 cursor_row
->cursor_in_fringe_p
= 0;
24151 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
24152 goto mark_cursor_off
;
24155 /* This can happen when the new row is shorter than the old one.
24156 In this case, either draw_glyphs or clear_end_of_line
24157 should have cleared the cursor. Note that we wouldn't be
24158 able to erase the cursor in this case because we don't have a
24159 cursor glyph at hand. */
24160 if ((cursor_row
->reversed_p
24161 ? (w
->phys_cursor
.hpos
< 0)
24162 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
24163 goto mark_cursor_off
;
24165 /* If the cursor is in the mouse face area, redisplay that when
24166 we clear the cursor. */
24167 if (! NILP (hlinfo
->mouse_face_window
)
24168 && coords_in_mouse_face_p (w
, hpos
, vpos
)
24169 /* Don't redraw the cursor's spot in mouse face if it is at the
24170 end of a line (on a newline). The cursor appears there, but
24171 mouse highlighting does not. */
24172 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
24173 mouse_face_here_p
= 1;
24175 /* Maybe clear the display under the cursor. */
24176 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
24179 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
24182 cursor_glyph
= get_phys_cursor_glyph (w
);
24183 if (cursor_glyph
== NULL
)
24184 goto mark_cursor_off
;
24186 width
= cursor_glyph
->pixel_width
;
24187 left_x
= window_box_left_offset (w
, TEXT_AREA
);
24188 x
= w
->phys_cursor
.x
;
24190 width
-= left_x
- x
;
24191 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
24192 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
24193 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
24196 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
24199 /* Erase the cursor by redrawing the character underneath it. */
24200 if (mouse_face_here_p
)
24201 hl
= DRAW_MOUSE_FACE
;
24203 hl
= DRAW_NORMAL_TEXT
;
24204 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
24207 w
->phys_cursor_on_p
= 0;
24208 w
->phys_cursor_type
= NO_CURSOR
;
24213 Display or clear cursor of window W. If ON is zero, clear the
24214 cursor. If it is non-zero, display the cursor. If ON is nonzero,
24215 where to put the cursor is specified by HPOS, VPOS, X and Y. */
24218 display_and_set_cursor (struct window
*w
, int on
,
24219 int hpos
, int vpos
, int x
, int y
)
24221 struct frame
*f
= XFRAME (w
->frame
);
24222 int new_cursor_type
;
24223 int new_cursor_width
;
24225 struct glyph_row
*glyph_row
;
24226 struct glyph
*glyph
;
24228 /* This is pointless on invisible frames, and dangerous on garbaged
24229 windows and frames; in the latter case, the frame or window may
24230 be in the midst of changing its size, and x and y may be off the
24232 if (! FRAME_VISIBLE_P (f
)
24233 || FRAME_GARBAGED_P (f
)
24234 || vpos
>= w
->current_matrix
->nrows
24235 || hpos
>= w
->current_matrix
->matrix_w
)
24238 /* If cursor is off and we want it off, return quickly. */
24239 if (!on
&& !w
->phys_cursor_on_p
)
24242 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
24243 /* If cursor row is not enabled, we don't really know where to
24244 display the cursor. */
24245 if (!glyph_row
->enabled_p
)
24247 w
->phys_cursor_on_p
= 0;
24252 if (!glyph_row
->exact_window_width_line_p
24253 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
24254 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
24256 xassert (interrupt_input_blocked
);
24258 /* Set new_cursor_type to the cursor we want to be displayed. */
24259 new_cursor_type
= get_window_cursor_type (w
, glyph
,
24260 &new_cursor_width
, &active_cursor
);
24262 /* If cursor is currently being shown and we don't want it to be or
24263 it is in the wrong place, or the cursor type is not what we want,
24265 if (w
->phys_cursor_on_p
24267 || w
->phys_cursor
.x
!= x
24268 || w
->phys_cursor
.y
!= y
24269 || new_cursor_type
!= w
->phys_cursor_type
24270 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24271 && new_cursor_width
!= w
->phys_cursor_width
)))
24272 erase_phys_cursor (w
);
24274 /* Don't check phys_cursor_on_p here because that flag is only set
24275 to zero in some cases where we know that the cursor has been
24276 completely erased, to avoid the extra work of erasing the cursor
24277 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24278 still not be visible, or it has only been partly erased. */
24281 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24282 w
->phys_cursor_height
= glyph_row
->height
;
24284 /* Set phys_cursor_.* before x_draw_.* is called because some
24285 of them may need the information. */
24286 w
->phys_cursor
.x
= x
;
24287 w
->phys_cursor
.y
= glyph_row
->y
;
24288 w
->phys_cursor
.hpos
= hpos
;
24289 w
->phys_cursor
.vpos
= vpos
;
24292 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24293 new_cursor_type
, new_cursor_width
,
24294 on
, active_cursor
);
24298 /* Switch the display of W's cursor on or off, according to the value
24302 update_window_cursor (struct window
*w
, int on
)
24304 /* Don't update cursor in windows whose frame is in the process
24305 of being deleted. */
24306 if (w
->current_matrix
)
24309 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24310 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24316 /* Call update_window_cursor with parameter ON_P on all leaf windows
24317 in the window tree rooted at W. */
24320 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24324 if (!NILP (w
->hchild
))
24325 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24326 else if (!NILP (w
->vchild
))
24327 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24329 update_window_cursor (w
, on_p
);
24331 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24337 Display the cursor on window W, or clear it, according to ON_P.
24338 Don't change the cursor's position. */
24341 x_update_cursor (struct frame
*f
, int on_p
)
24343 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24348 Clear the cursor of window W to background color, and mark the
24349 cursor as not shown. This is used when the text where the cursor
24350 is about to be rewritten. */
24353 x_clear_cursor (struct window
*w
)
24355 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24356 update_window_cursor (w
, 0);
24359 #endif /* HAVE_WINDOW_SYSTEM */
24361 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24364 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24365 int start_hpos
, int end_hpos
,
24366 enum draw_glyphs_face draw
)
24368 #ifdef HAVE_WINDOW_SYSTEM
24369 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24371 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24375 #if defined (HAVE_GPM) || defined (MSDOS)
24376 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24380 /* Display the active region described by mouse_face_* according to DRAW. */
24383 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24385 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24386 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24388 if (/* If window is in the process of being destroyed, don't bother
24390 w
->current_matrix
!= NULL
24391 /* Don't update mouse highlight if hidden */
24392 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24393 /* Recognize when we are called to operate on rows that don't exist
24394 anymore. This can happen when a window is split. */
24395 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24397 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24398 struct glyph_row
*row
, *first
, *last
;
24400 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24401 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24403 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24405 int start_hpos
, end_hpos
, start_x
;
24407 /* For all but the first row, the highlight starts at column 0. */
24410 /* R2L rows have BEG and END in reversed order, but the
24411 screen drawing geometry is always left to right. So
24412 we need to mirror the beginning and end of the
24413 highlighted area in R2L rows. */
24414 if (!row
->reversed_p
)
24416 start_hpos
= hlinfo
->mouse_face_beg_col
;
24417 start_x
= hlinfo
->mouse_face_beg_x
;
24419 else if (row
== last
)
24421 start_hpos
= hlinfo
->mouse_face_end_col
;
24422 start_x
= hlinfo
->mouse_face_end_x
;
24430 else if (row
->reversed_p
&& row
== last
)
24432 start_hpos
= hlinfo
->mouse_face_end_col
;
24433 start_x
= hlinfo
->mouse_face_end_x
;
24443 if (!row
->reversed_p
)
24444 end_hpos
= hlinfo
->mouse_face_end_col
;
24445 else if (row
== first
)
24446 end_hpos
= hlinfo
->mouse_face_beg_col
;
24449 end_hpos
= row
->used
[TEXT_AREA
];
24450 if (draw
== DRAW_NORMAL_TEXT
)
24451 row
->fill_line_p
= 1; /* Clear to end of line */
24454 else if (row
->reversed_p
&& row
== first
)
24455 end_hpos
= hlinfo
->mouse_face_beg_col
;
24458 end_hpos
= row
->used
[TEXT_AREA
];
24459 if (draw
== DRAW_NORMAL_TEXT
)
24460 row
->fill_line_p
= 1; /* Clear to end of line */
24463 if (end_hpos
> start_hpos
)
24465 draw_row_with_mouse_face (w
, start_x
, row
,
24466 start_hpos
, end_hpos
, draw
);
24469 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24473 #ifdef HAVE_WINDOW_SYSTEM
24474 /* When we've written over the cursor, arrange for it to
24475 be displayed again. */
24476 if (FRAME_WINDOW_P (f
)
24477 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24480 display_and_set_cursor (w
, 1,
24481 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24482 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24485 #endif /* HAVE_WINDOW_SYSTEM */
24488 #ifdef HAVE_WINDOW_SYSTEM
24489 /* Change the mouse cursor. */
24490 if (FRAME_WINDOW_P (f
))
24492 if (draw
== DRAW_NORMAL_TEXT
24493 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24494 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24495 else if (draw
== DRAW_MOUSE_FACE
)
24496 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24498 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24500 #endif /* HAVE_WINDOW_SYSTEM */
24504 Clear out the mouse-highlighted active region.
24505 Redraw it un-highlighted first. Value is non-zero if mouse
24506 face was actually drawn unhighlighted. */
24509 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24513 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24515 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24519 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24520 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24521 hlinfo
->mouse_face_window
= Qnil
;
24522 hlinfo
->mouse_face_overlay
= Qnil
;
24526 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24527 within the mouse face on that window. */
24529 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24531 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24533 /* Quickly resolve the easy cases. */
24534 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24535 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24537 if (vpos
< hlinfo
->mouse_face_beg_row
24538 || vpos
> hlinfo
->mouse_face_end_row
)
24540 if (vpos
> hlinfo
->mouse_face_beg_row
24541 && vpos
< hlinfo
->mouse_face_end_row
)
24544 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24546 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24548 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24551 else if ((vpos
== hlinfo
->mouse_face_beg_row
24552 && hpos
>= hlinfo
->mouse_face_beg_col
)
24553 || (vpos
== hlinfo
->mouse_face_end_row
24554 && hpos
< hlinfo
->mouse_face_end_col
))
24559 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24561 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24564 else if ((vpos
== hlinfo
->mouse_face_beg_row
24565 && hpos
<= hlinfo
->mouse_face_beg_col
)
24566 || (vpos
== hlinfo
->mouse_face_end_row
24567 && hpos
> hlinfo
->mouse_face_end_col
))
24575 Non-zero if physical cursor of window W is within mouse face. */
24578 cursor_in_mouse_face_p (struct window
*w
)
24580 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24585 /* Find the glyph rows START_ROW and END_ROW of window W that display
24586 characters between buffer positions START_CHARPOS and END_CHARPOS
24587 (excluding END_CHARPOS). This is similar to row_containing_pos,
24588 but is more accurate when bidi reordering makes buffer positions
24589 change non-linearly with glyph rows. */
24591 rows_from_pos_range (struct window
*w
,
24592 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24593 struct glyph_row
**start
, struct glyph_row
**end
)
24595 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24596 int last_y
= window_text_bottom_y (w
);
24597 struct glyph_row
*row
;
24602 while (!first
->enabled_p
24603 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24606 /* Find the START row. */
24608 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24611 /* A row can potentially be the START row if the range of the
24612 characters it displays intersects the range
24613 [START_CHARPOS..END_CHARPOS). */
24614 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24615 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24616 /* See the commentary in row_containing_pos, for the
24617 explanation of the complicated way to check whether
24618 some position is beyond the end of the characters
24619 displayed by a row. */
24620 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24621 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24622 && !row
->ends_at_zv_p
24623 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24624 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24625 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24626 && !row
->ends_at_zv_p
24627 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24629 /* Found a candidate row. Now make sure at least one of the
24630 glyphs it displays has a charpos from the range
24631 [START_CHARPOS..END_CHARPOS).
24633 This is not obvious because bidi reordering could make
24634 buffer positions of a row be 1,2,3,102,101,100, and if we
24635 want to highlight characters in [50..60), we don't want
24636 this row, even though [50..60) does intersect [1..103),
24637 the range of character positions given by the row's start
24638 and end positions. */
24639 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24640 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24644 if (BUFFERP (g
->object
)
24645 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24654 /* Find the END row. */
24656 /* If the last row is partially visible, start looking for END
24657 from that row, instead of starting from FIRST. */
24658 && !(row
->enabled_p
24659 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24661 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24663 struct glyph_row
*next
= row
+ 1;
24665 if (!next
->enabled_p
24666 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24667 /* The first row >= START whose range of displayed characters
24668 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24669 is the row END + 1. */
24670 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24671 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24672 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24673 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24674 && !next
->ends_at_zv_p
24675 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24676 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24677 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24678 && !next
->ends_at_zv_p
24679 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24686 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24687 but none of the characters it displays are in the range, it is
24689 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24690 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24694 if (BUFFERP (g
->object
)
24695 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24708 /* This function sets the mouse_face_* elements of HLINFO, assuming
24709 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24710 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24711 for the overlay or run of text properties specifying the mouse
24712 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24713 before-string and after-string that must also be highlighted.
24714 COVER_STRING, if non-nil, is a display string that may cover some
24715 or all of the highlighted text. */
24718 mouse_face_from_buffer_pos (Lisp_Object window
,
24719 Mouse_HLInfo
*hlinfo
,
24720 EMACS_INT mouse_charpos
,
24721 EMACS_INT start_charpos
,
24722 EMACS_INT end_charpos
,
24723 Lisp_Object before_string
,
24724 Lisp_Object after_string
,
24725 Lisp_Object cover_string
)
24727 struct window
*w
= XWINDOW (window
);
24728 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24729 struct glyph_row
*r1
, *r2
;
24730 struct glyph
*glyph
, *end
;
24731 EMACS_INT ignore
, pos
;
24734 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24735 xassert (NILP (before_string
) || STRINGP (before_string
));
24736 xassert (NILP (after_string
) || STRINGP (after_string
));
24738 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24739 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24741 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24742 /* If the before-string or display-string contains newlines,
24743 rows_from_pos_range skips to its last row. Move back. */
24744 if (!NILP (before_string
) || !NILP (cover_string
))
24746 struct glyph_row
*prev
;
24747 while ((prev
= r1
- 1, prev
>= first
)
24748 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24749 && prev
->used
[TEXT_AREA
] > 0)
24751 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24752 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24753 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24755 || !(EQ (glyph
->object
, before_string
)
24756 || EQ (glyph
->object
, cover_string
)))
24763 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24764 hlinfo
->mouse_face_past_end
= 1;
24766 else if (!NILP (after_string
))
24768 /* If the after-string has newlines, advance to its last row. */
24769 struct glyph_row
*next
;
24770 struct glyph_row
*last
24771 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24773 for (next
= r2
+ 1;
24775 && next
->used
[TEXT_AREA
] > 0
24776 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24780 /* The rest of the display engine assumes that mouse_face_beg_row is
24781 either above below mouse_face_end_row or identical to it. But
24782 with bidi-reordered continued lines, the row for START_CHARPOS
24783 could be below the row for END_CHARPOS. If so, swap the rows and
24784 store them in correct order. */
24787 struct glyph_row
*tem
= r2
;
24793 hlinfo
->mouse_face_beg_y
= r1
->y
;
24794 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24795 hlinfo
->mouse_face_end_y
= r2
->y
;
24796 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24798 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24799 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
24800 could be anywhere in the row and in any order. The strategy
24801 below is to find the leftmost and the rightmost glyph that
24802 belongs to either of these 3 strings, or whose position is
24803 between START_CHARPOS and END_CHARPOS, and highlight all the
24804 glyphs between those two. This may cover more than just the text
24805 between START_CHARPOS and END_CHARPOS if the range of characters
24806 strides the bidi level boundary, e.g. if the beginning is in R2L
24807 text while the end is in L2R text or vice versa. */
24808 if (!r1
->reversed_p
)
24810 /* This row is in a left to right paragraph. Scan it left to
24812 glyph
= r1
->glyphs
[TEXT_AREA
];
24813 end
= glyph
+ r1
->used
[TEXT_AREA
];
24816 /* Skip truncation glyphs at the start of the glyph row. */
24817 if (r1
->displays_text_p
)
24819 && INTEGERP (glyph
->object
)
24820 && glyph
->charpos
< 0;
24822 x
+= glyph
->pixel_width
;
24824 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24825 or COVER_STRING, and the first glyph from buffer whose
24826 position is between START_CHARPOS and END_CHARPOS. */
24828 && !INTEGERP (glyph
->object
)
24829 && !EQ (glyph
->object
, cover_string
)
24830 && !(BUFFERP (glyph
->object
)
24831 && (glyph
->charpos
>= start_charpos
24832 && glyph
->charpos
< end_charpos
));
24835 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24836 are present at buffer positions between START_CHARPOS and
24837 END_CHARPOS, or if they come from an overlay. */
24838 if (EQ (glyph
->object
, before_string
))
24840 pos
= string_buffer_position (before_string
,
24842 /* If pos == 0, it means before_string came from an
24843 overlay, not from a buffer position. */
24844 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24847 else if (EQ (glyph
->object
, after_string
))
24849 pos
= string_buffer_position (after_string
, end_charpos
);
24850 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24853 x
+= glyph
->pixel_width
;
24855 hlinfo
->mouse_face_beg_x
= x
;
24856 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24860 /* This row is in a right to left paragraph. Scan it right to
24864 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24865 glyph
= end
+ r1
->used
[TEXT_AREA
];
24867 /* Skip truncation glyphs at the start of the glyph row. */
24868 if (r1
->displays_text_p
)
24870 && INTEGERP (glyph
->object
)
24871 && glyph
->charpos
< 0;
24875 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24876 or COVER_STRING, and the first glyph from buffer whose
24877 position is between START_CHARPOS and END_CHARPOS. */
24879 && !INTEGERP (glyph
->object
)
24880 && !EQ (glyph
->object
, cover_string
)
24881 && !(BUFFERP (glyph
->object
)
24882 && (glyph
->charpos
>= start_charpos
24883 && glyph
->charpos
< end_charpos
));
24886 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24887 are present at buffer positions between START_CHARPOS and
24888 END_CHARPOS, or if they come from an overlay. */
24889 if (EQ (glyph
->object
, before_string
))
24891 pos
= string_buffer_position (before_string
, start_charpos
);
24892 /* If pos == 0, it means before_string came from an
24893 overlay, not from a buffer position. */
24894 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24897 else if (EQ (glyph
->object
, after_string
))
24899 pos
= string_buffer_position (after_string
, end_charpos
);
24900 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24905 glyph
++; /* first glyph to the right of the highlighted area */
24906 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24907 x
+= g
->pixel_width
;
24908 hlinfo
->mouse_face_beg_x
= x
;
24909 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24912 /* If the highlight ends in a different row, compute GLYPH and END
24913 for the end row. Otherwise, reuse the values computed above for
24914 the row where the highlight begins. */
24917 if (!r2
->reversed_p
)
24919 glyph
= r2
->glyphs
[TEXT_AREA
];
24920 end
= glyph
+ r2
->used
[TEXT_AREA
];
24925 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24926 glyph
= end
+ r2
->used
[TEXT_AREA
];
24930 if (!r2
->reversed_p
)
24932 /* Skip truncation and continuation glyphs near the end of the
24933 row, and also blanks and stretch glyphs inserted by
24934 extend_face_to_end_of_line. */
24936 && INTEGERP ((end
- 1)->object
)
24937 && (end
- 1)->charpos
<= 0)
24939 /* Scan the rest of the glyph row from the end, looking for the
24940 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24941 COVER_STRING, or whose position is between START_CHARPOS
24945 && !INTEGERP (end
->object
)
24946 && !EQ (end
->object
, cover_string
)
24947 && !(BUFFERP (end
->object
)
24948 && (end
->charpos
>= start_charpos
24949 && end
->charpos
< end_charpos
));
24952 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24953 are present at buffer positions between START_CHARPOS and
24954 END_CHARPOS, or if they come from an overlay. */
24955 if (EQ (end
->object
, before_string
))
24957 pos
= string_buffer_position (before_string
, start_charpos
);
24958 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24961 else if (EQ (end
->object
, after_string
))
24963 pos
= string_buffer_position (after_string
, end_charpos
);
24964 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24968 /* Find the X coordinate of the last glyph to be highlighted. */
24969 for (; glyph
<= end
; ++glyph
)
24970 x
+= glyph
->pixel_width
;
24972 hlinfo
->mouse_face_end_x
= x
;
24973 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24977 /* Skip truncation and continuation glyphs near the end of the
24978 row, and also blanks and stretch glyphs inserted by
24979 extend_face_to_end_of_line. */
24983 && INTEGERP (end
->object
)
24984 && end
->charpos
<= 0)
24986 x
+= end
->pixel_width
;
24989 /* Scan the rest of the glyph row from the end, looking for the
24990 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24991 COVER_STRING, or whose position is between START_CHARPOS
24995 && !INTEGERP (end
->object
)
24996 && !EQ (end
->object
, cover_string
)
24997 && !(BUFFERP (end
->object
)
24998 && (end
->charpos
>= start_charpos
24999 && end
->charpos
< end_charpos
));
25002 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25003 are present at buffer positions between START_CHARPOS and
25004 END_CHARPOS, or if they come from an overlay. */
25005 if (EQ (end
->object
, before_string
))
25007 pos
= string_buffer_position (before_string
, start_charpos
);
25008 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25011 else if (EQ (end
->object
, after_string
))
25013 pos
= string_buffer_position (after_string
, end_charpos
);
25014 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25017 x
+= end
->pixel_width
;
25019 hlinfo
->mouse_face_end_x
= x
;
25020 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
25023 hlinfo
->mouse_face_window
= window
;
25024 hlinfo
->mouse_face_face_id
25025 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
25027 !hlinfo
->mouse_face_hidden
, -1);
25028 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25031 /* The following function is not used anymore (replaced with
25032 mouse_face_from_string_pos), but I leave it here for the time
25033 being, in case someone would. */
25035 #if 0 /* not used */
25037 /* Find the position of the glyph for position POS in OBJECT in
25038 window W's current matrix, and return in *X, *Y the pixel
25039 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
25041 RIGHT_P non-zero means return the position of the right edge of the
25042 glyph, RIGHT_P zero means return the left edge position.
25044 If no glyph for POS exists in the matrix, return the position of
25045 the glyph with the next smaller position that is in the matrix, if
25046 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
25047 exists in the matrix, return the position of the glyph with the
25048 next larger position in OBJECT.
25050 Value is non-zero if a glyph was found. */
25053 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
25054 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
25056 int yb
= window_text_bottom_y (w
);
25057 struct glyph_row
*r
;
25058 struct glyph
*best_glyph
= NULL
;
25059 struct glyph_row
*best_row
= NULL
;
25062 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25063 r
->enabled_p
&& r
->y
< yb
;
25066 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
25067 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
25070 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25071 if (EQ (g
->object
, object
))
25073 if (g
->charpos
== pos
)
25080 else if (best_glyph
== NULL
25081 || ((eabs (g
->charpos
- pos
)
25082 < eabs (best_glyph
->charpos
- pos
))
25085 : g
->charpos
> pos
)))
25099 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
25103 *x
+= best_glyph
->pixel_width
;
25108 *vpos
= best_row
- w
->current_matrix
->rows
;
25111 return best_glyph
!= NULL
;
25113 #endif /* not used */
25115 /* Find the positions of the first and the last glyphs in window W's
25116 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
25117 (assumed to be a string), and return in HLINFO's mouse_face_*
25118 members the pixel and column/row coordinates of those glyphs. */
25121 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
25122 Lisp_Object object
,
25123 EMACS_INT startpos
, EMACS_INT endpos
)
25125 int yb
= window_text_bottom_y (w
);
25126 struct glyph_row
*r
;
25127 struct glyph
*g
, *e
;
25131 /* Find the glyph row with at least one position in the range
25132 [STARTPOS..ENDPOS], and the first glyph in that row whose
25133 position belongs to that range. */
25134 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25135 r
->enabled_p
&& r
->y
< yb
;
25138 if (!r
->reversed_p
)
25140 g
= r
->glyphs
[TEXT_AREA
];
25141 e
= g
+ r
->used
[TEXT_AREA
];
25142 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25143 if (EQ (g
->object
, object
)
25144 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25146 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25147 hlinfo
->mouse_face_beg_y
= r
->y
;
25148 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25149 hlinfo
->mouse_face_beg_x
= gx
;
25158 e
= r
->glyphs
[TEXT_AREA
];
25159 g
= e
+ r
->used
[TEXT_AREA
];
25160 for ( ; g
> e
; --g
)
25161 if (EQ ((g
-1)->object
, object
)
25162 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
25164 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25165 hlinfo
->mouse_face_beg_y
= r
->y
;
25166 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25167 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
25168 gx
+= g1
->pixel_width
;
25169 hlinfo
->mouse_face_beg_x
= gx
;
25181 /* Starting with the next row, look for the first row which does NOT
25182 include any glyphs whose positions are in the range. */
25183 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
25185 g
= r
->glyphs
[TEXT_AREA
];
25186 e
= g
+ r
->used
[TEXT_AREA
];
25188 for ( ; g
< e
; ++g
)
25189 if (EQ (g
->object
, object
)
25190 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25199 /* The highlighted region ends on the previous row. */
25202 /* Set the end row and its vertical pixel coordinate. */
25203 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
25204 hlinfo
->mouse_face_end_y
= r
->y
;
25206 /* Compute and set the end column and the end column's horizontal
25207 pixel coordinate. */
25208 if (!r
->reversed_p
)
25210 g
= r
->glyphs
[TEXT_AREA
];
25211 e
= g
+ r
->used
[TEXT_AREA
];
25212 for ( ; e
> g
; --e
)
25213 if (EQ ((e
-1)->object
, object
)
25214 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
25216 hlinfo
->mouse_face_end_col
= e
- g
;
25218 for (gx
= r
->x
; g
< e
; ++g
)
25219 gx
+= g
->pixel_width
;
25220 hlinfo
->mouse_face_end_x
= gx
;
25224 e
= r
->glyphs
[TEXT_AREA
];
25225 g
= e
+ r
->used
[TEXT_AREA
];
25226 for (gx
= r
->x
; e
< g
; ++e
)
25228 if (EQ (e
->object
, object
)
25229 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
25231 gx
+= e
->pixel_width
;
25233 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
25234 hlinfo
->mouse_face_end_x
= gx
;
25238 #ifdef HAVE_WINDOW_SYSTEM
25240 /* See if position X, Y is within a hot-spot of an image. */
25243 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
25245 if (!CONSP (hot_spot
))
25248 if (EQ (XCAR (hot_spot
), Qrect
))
25250 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
25251 Lisp_Object rect
= XCDR (hot_spot
);
25255 if (!CONSP (XCAR (rect
)))
25257 if (!CONSP (XCDR (rect
)))
25259 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
25261 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
25263 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
25265 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25269 else if (EQ (XCAR (hot_spot
), Qcircle
))
25271 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25272 Lisp_Object circ
= XCDR (hot_spot
);
25273 Lisp_Object lr
, lx0
, ly0
;
25275 && CONSP (XCAR (circ
))
25276 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25277 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25278 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25280 double r
= XFLOATINT (lr
);
25281 double dx
= XINT (lx0
) - x
;
25282 double dy
= XINT (ly0
) - y
;
25283 return (dx
* dx
+ dy
* dy
<= r
* r
);
25286 else if (EQ (XCAR (hot_spot
), Qpoly
))
25288 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25289 if (VECTORP (XCDR (hot_spot
)))
25291 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25292 Lisp_Object
*poly
= v
->contents
;
25293 int n
= v
->header
.size
;
25296 Lisp_Object lx
, ly
;
25299 /* Need an even number of coordinates, and at least 3 edges. */
25300 if (n
< 6 || n
& 1)
25303 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25304 If count is odd, we are inside polygon. Pixels on edges
25305 may or may not be included depending on actual geometry of the
25307 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25308 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25310 x0
= XINT (lx
), y0
= XINT (ly
);
25311 for (i
= 0; i
< n
; i
+= 2)
25313 int x1
= x0
, y1
= y0
;
25314 if ((lx
= poly
[i
], !INTEGERP (lx
))
25315 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25317 x0
= XINT (lx
), y0
= XINT (ly
);
25319 /* Does this segment cross the X line? */
25327 if (y
> y0
&& y
> y1
)
25329 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25339 find_hot_spot (Lisp_Object map
, int x
, int y
)
25341 while (CONSP (map
))
25343 if (CONSP (XCAR (map
))
25344 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25352 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25354 doc
: /* Lookup in image map MAP coordinates X and Y.
25355 An image map is an alist where each element has the format (AREA ID PLIST).
25356 An AREA is specified as either a rectangle, a circle, or a polygon:
25357 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25358 pixel coordinates of the upper left and bottom right corners.
25359 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25360 and the radius of the circle; r may be a float or integer.
25361 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25362 vector describes one corner in the polygon.
25363 Returns the alist element for the first matching AREA in MAP. */)
25364 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25372 return find_hot_spot (map
, XINT (x
), XINT (y
));
25376 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25378 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25380 /* Do not change cursor shape while dragging mouse. */
25381 if (!NILP (do_mouse_tracking
))
25384 if (!NILP (pointer
))
25386 if (EQ (pointer
, Qarrow
))
25387 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25388 else if (EQ (pointer
, Qhand
))
25389 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25390 else if (EQ (pointer
, Qtext
))
25391 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25392 else if (EQ (pointer
, intern ("hdrag")))
25393 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25394 #ifdef HAVE_X_WINDOWS
25395 else if (EQ (pointer
, intern ("vdrag")))
25396 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25398 else if (EQ (pointer
, intern ("hourglass")))
25399 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25400 else if (EQ (pointer
, Qmodeline
))
25401 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25403 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25406 if (cursor
!= No_Cursor
)
25407 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25410 #endif /* HAVE_WINDOW_SYSTEM */
25412 /* Take proper action when mouse has moved to the mode or header line
25413 or marginal area AREA of window W, x-position X and y-position Y.
25414 X is relative to the start of the text display area of W, so the
25415 width of bitmap areas and scroll bars must be subtracted to get a
25416 position relative to the start of the mode line. */
25419 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25420 enum window_part area
)
25422 struct window
*w
= XWINDOW (window
);
25423 struct frame
*f
= XFRAME (w
->frame
);
25424 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25425 #ifdef HAVE_WINDOW_SYSTEM
25426 Display_Info
*dpyinfo
;
25428 Cursor cursor
= No_Cursor
;
25429 Lisp_Object pointer
= Qnil
;
25430 int dx
, dy
, width
, height
;
25432 Lisp_Object string
, object
= Qnil
;
25433 Lisp_Object pos
, help
;
25435 Lisp_Object mouse_face
;
25436 int original_x_pixel
= x
;
25437 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25438 struct glyph_row
*row
;
25440 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25445 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25446 returns them in row/column units! */
25447 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25448 &object
, &dx
, &dy
, &width
, &height
);
25450 row
= (area
== ON_MODE_LINE
25451 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25452 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25454 /* Find the glyph under the mouse pointer. */
25455 if (row
->mode_line_p
&& row
->enabled_p
)
25457 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25458 end
= glyph
+ row
->used
[TEXT_AREA
];
25460 for (x0
= original_x_pixel
;
25461 glyph
< end
&& x0
>= glyph
->pixel_width
;
25463 x0
-= glyph
->pixel_width
;
25471 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25472 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25473 returns them in row/column units! */
25474 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25475 &object
, &dx
, &dy
, &width
, &height
);
25480 #ifdef HAVE_WINDOW_SYSTEM
25481 if (IMAGEP (object
))
25483 Lisp_Object image_map
, hotspot
;
25484 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25486 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25488 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25492 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25493 If so, we could look for mouse-enter, mouse-leave
25494 properties in PLIST (and do something...). */
25495 hotspot
= XCDR (hotspot
);
25496 if (CONSP (hotspot
)
25497 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25499 pointer
= Fplist_get (plist
, Qpointer
);
25500 if (NILP (pointer
))
25502 help
= Fplist_get (plist
, Qhelp_echo
);
25505 help_echo_string
= help
;
25506 /* Is this correct? ++kfs */
25507 XSETWINDOW (help_echo_window
, w
);
25508 help_echo_object
= w
->buffer
;
25509 help_echo_pos
= charpos
;
25513 if (NILP (pointer
))
25514 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25516 #endif /* HAVE_WINDOW_SYSTEM */
25518 if (STRINGP (string
))
25520 pos
= make_number (charpos
);
25521 /* If we're on a string with `help-echo' text property, arrange
25522 for the help to be displayed. This is done by setting the
25523 global variable help_echo_string to the help string. */
25526 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25529 help_echo_string
= help
;
25530 XSETWINDOW (help_echo_window
, w
);
25531 help_echo_object
= string
;
25532 help_echo_pos
= charpos
;
25536 #ifdef HAVE_WINDOW_SYSTEM
25537 if (FRAME_WINDOW_P (f
))
25539 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25540 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25541 if (NILP (pointer
))
25542 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25544 /* Change the mouse pointer according to what is under X/Y. */
25546 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25549 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25550 if (!KEYMAPP (map
))
25551 map
= Fget_text_property (pos
, Qkeymap
, string
);
25552 if (!KEYMAPP (map
))
25553 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25558 /* Change the mouse face according to what is under X/Y. */
25559 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25560 if (!NILP (mouse_face
)
25561 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25566 struct glyph
* tmp_glyph
;
25570 int total_pixel_width
;
25571 EMACS_INT begpos
, endpos
, ignore
;
25575 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25576 Qmouse_face
, string
, Qnil
);
25582 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25584 endpos
= SCHARS (string
);
25588 /* Calculate the glyph position GPOS of GLYPH in the
25589 displayed string, relative to the beginning of the
25590 highlighted part of the string.
25592 Note: GPOS is different from CHARPOS. CHARPOS is the
25593 position of GLYPH in the internal string object. A mode
25594 line string format has structures which are converted to
25595 a flattened string by the Emacs Lisp interpreter. The
25596 internal string is an element of those structures. The
25597 displayed string is the flattened string. */
25598 tmp_glyph
= row_start_glyph
;
25599 while (tmp_glyph
< glyph
25600 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25601 && begpos
<= tmp_glyph
->charpos
25602 && tmp_glyph
->charpos
< endpos
)))
25604 gpos
= glyph
- tmp_glyph
;
25606 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25607 the highlighted part of the displayed string to which
25608 GLYPH belongs. Note: GSEQ_LENGTH is different from
25609 SCHARS (STRING), because the latter returns the length of
25610 the internal string. */
25611 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25613 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25614 && begpos
<= tmp_glyph
->charpos
25615 && tmp_glyph
->charpos
< endpos
));
25618 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25620 /* Calculate the total pixel width of all the glyphs between
25621 the beginning of the highlighted area and GLYPH. */
25622 total_pixel_width
= 0;
25623 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25624 total_pixel_width
+= tmp_glyph
->pixel_width
;
25626 /* Pre calculation of re-rendering position. Note: X is in
25627 column units here, after the call to mode_line_string or
25628 marginal_area_string. */
25630 vpos
= (area
== ON_MODE_LINE
25631 ? (w
->current_matrix
)->nrows
- 1
25634 /* If GLYPH's position is included in the region that is
25635 already drawn in mouse face, we have nothing to do. */
25636 if ( EQ (window
, hlinfo
->mouse_face_window
)
25637 && (!row
->reversed_p
25638 ? (hlinfo
->mouse_face_beg_col
<= hpos
25639 && hpos
< hlinfo
->mouse_face_end_col
)
25640 /* In R2L rows we swap BEG and END, see below. */
25641 : (hlinfo
->mouse_face_end_col
<= hpos
25642 && hpos
< hlinfo
->mouse_face_beg_col
))
25643 && hlinfo
->mouse_face_beg_row
== vpos
)
25646 if (clear_mouse_face (hlinfo
))
25647 cursor
= No_Cursor
;
25649 if (!row
->reversed_p
)
25651 hlinfo
->mouse_face_beg_col
= hpos
;
25652 hlinfo
->mouse_face_beg_x
= original_x_pixel
25653 - (total_pixel_width
+ dx
);
25654 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25655 hlinfo
->mouse_face_end_x
= 0;
25659 /* In R2L rows, show_mouse_face expects BEG and END
25660 coordinates to be swapped. */
25661 hlinfo
->mouse_face_end_col
= hpos
;
25662 hlinfo
->mouse_face_end_x
= original_x_pixel
25663 - (total_pixel_width
+ dx
);
25664 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25665 hlinfo
->mouse_face_beg_x
= 0;
25668 hlinfo
->mouse_face_beg_row
= vpos
;
25669 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25670 hlinfo
->mouse_face_beg_y
= 0;
25671 hlinfo
->mouse_face_end_y
= 0;
25672 hlinfo
->mouse_face_past_end
= 0;
25673 hlinfo
->mouse_face_window
= window
;
25675 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25681 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25683 if (NILP (pointer
))
25686 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25687 clear_mouse_face (hlinfo
);
25689 #ifdef HAVE_WINDOW_SYSTEM
25690 if (FRAME_WINDOW_P (f
))
25691 define_frame_cursor1 (f
, cursor
, pointer
);
25697 Take proper action when the mouse has moved to position X, Y on
25698 frame F as regards highlighting characters that have mouse-face
25699 properties. Also de-highlighting chars where the mouse was before.
25700 X and Y can be negative or out of range. */
25703 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25705 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25706 enum window_part part
;
25707 Lisp_Object window
;
25709 Cursor cursor
= No_Cursor
;
25710 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25713 /* When a menu is active, don't highlight because this looks odd. */
25714 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25715 if (popup_activated ())
25719 if (NILP (Vmouse_highlight
)
25720 || !f
->glyphs_initialized_p
25721 || f
->pointer_invisible
)
25724 hlinfo
->mouse_face_mouse_x
= x
;
25725 hlinfo
->mouse_face_mouse_y
= y
;
25726 hlinfo
->mouse_face_mouse_frame
= f
;
25728 if (hlinfo
->mouse_face_defer
)
25731 if (gc_in_progress
)
25733 hlinfo
->mouse_face_deferred_gc
= 1;
25737 /* Which window is that in? */
25738 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25740 /* If we were displaying active text in another window, clear that.
25741 Also clear if we move out of text area in same window. */
25742 if (! EQ (window
, hlinfo
->mouse_face_window
)
25743 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25744 && !NILP (hlinfo
->mouse_face_window
)))
25745 clear_mouse_face (hlinfo
);
25747 /* Not on a window -> return. */
25748 if (!WINDOWP (window
))
25751 /* Reset help_echo_string. It will get recomputed below. */
25752 help_echo_string
= Qnil
;
25754 /* Convert to window-relative pixel coordinates. */
25755 w
= XWINDOW (window
);
25756 frame_to_window_pixel_xy (w
, &x
, &y
);
25758 #ifdef HAVE_WINDOW_SYSTEM
25759 /* Handle tool-bar window differently since it doesn't display a
25761 if (EQ (window
, f
->tool_bar_window
))
25763 note_tool_bar_highlight (f
, x
, y
);
25768 /* Mouse is on the mode, header line or margin? */
25769 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25770 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25772 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25776 #ifdef HAVE_WINDOW_SYSTEM
25777 if (part
== ON_VERTICAL_BORDER
)
25779 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25780 help_echo_string
= build_string ("drag-mouse-1: resize");
25782 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25783 || part
== ON_SCROLL_BAR
)
25784 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25786 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25789 /* Are we in a window whose display is up to date?
25790 And verify the buffer's text has not changed. */
25791 b
= XBUFFER (w
->buffer
);
25792 if (part
== ON_TEXT
25793 && EQ (w
->window_end_valid
, w
->buffer
)
25794 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25795 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25797 int hpos
, vpos
, i
, dx
, dy
, area
;
25799 struct glyph
*glyph
;
25800 Lisp_Object object
;
25801 Lisp_Object mouse_face
= Qnil
, position
;
25802 Lisp_Object
*overlay_vec
= NULL
;
25804 struct buffer
*obuf
;
25805 EMACS_INT obegv
, ozv
;
25808 /* Find the glyph under X/Y. */
25809 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25811 #ifdef HAVE_WINDOW_SYSTEM
25812 /* Look for :pointer property on image. */
25813 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25815 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25816 if (img
!= NULL
&& IMAGEP (img
->spec
))
25818 Lisp_Object image_map
, hotspot
;
25819 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25821 && (hotspot
= find_hot_spot (image_map
,
25822 glyph
->slice
.img
.x
+ dx
,
25823 glyph
->slice
.img
.y
+ dy
),
25825 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25829 /* Could check XCAR (hotspot) to see if we enter/leave
25831 If so, we could look for mouse-enter, mouse-leave
25832 properties in PLIST (and do something...). */
25833 hotspot
= XCDR (hotspot
);
25834 if (CONSP (hotspot
)
25835 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25837 pointer
= Fplist_get (plist
, Qpointer
);
25838 if (NILP (pointer
))
25840 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25841 if (!NILP (help_echo_string
))
25843 help_echo_window
= window
;
25844 help_echo_object
= glyph
->object
;
25845 help_echo_pos
= glyph
->charpos
;
25849 if (NILP (pointer
))
25850 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25853 #endif /* HAVE_WINDOW_SYSTEM */
25855 /* Clear mouse face if X/Y not over text. */
25857 || area
!= TEXT_AREA
25858 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25859 /* Glyph's OBJECT is an integer for glyphs inserted by the
25860 display engine for its internal purposes, like truncation
25861 and continuation glyphs and blanks beyond the end of
25862 line's text on text terminals. If we are over such a
25863 glyph, we are not over any text. */
25864 || INTEGERP (glyph
->object
)
25865 /* R2L rows have a stretch glyph at their front, which
25866 stands for no text, whereas L2R rows have no glyphs at
25867 all beyond the end of text. Treat such stretch glyphs
25868 like we do with NULL glyphs in L2R rows. */
25869 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25870 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25871 && glyph
->type
== STRETCH_GLYPH
25872 && glyph
->avoid_cursor_p
))
25874 if (clear_mouse_face (hlinfo
))
25875 cursor
= No_Cursor
;
25876 #ifdef HAVE_WINDOW_SYSTEM
25877 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25879 if (area
!= TEXT_AREA
)
25880 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25882 pointer
= Vvoid_text_area_pointer
;
25888 pos
= glyph
->charpos
;
25889 object
= glyph
->object
;
25890 if (!STRINGP (object
) && !BUFFERP (object
))
25893 /* If we get an out-of-range value, return now; avoid an error. */
25894 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25897 /* Make the window's buffer temporarily current for
25898 overlays_at and compute_char_face. */
25899 obuf
= current_buffer
;
25900 current_buffer
= b
;
25906 /* Is this char mouse-active or does it have help-echo? */
25907 position
= make_number (pos
);
25909 if (BUFFERP (object
))
25911 /* Put all the overlays we want in a vector in overlay_vec. */
25912 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25913 /* Sort overlays into increasing priority order. */
25914 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25919 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25922 cursor
= No_Cursor
;
25924 /* Check mouse-face highlighting. */
25926 /* If there exists an overlay with mouse-face overlapping
25927 the one we are currently highlighting, we have to
25928 check if we enter the overlapping overlay, and then
25929 highlight only that. */
25930 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25931 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25933 /* Find the highest priority overlay with a mouse-face. */
25934 Lisp_Object overlay
= Qnil
;
25935 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25937 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25938 if (!NILP (mouse_face
))
25939 overlay
= overlay_vec
[i
];
25942 /* If we're highlighting the same overlay as before, there's
25943 no need to do that again. */
25944 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25945 goto check_help_echo
;
25946 hlinfo
->mouse_face_overlay
= overlay
;
25948 /* Clear the display of the old active region, if any. */
25949 if (clear_mouse_face (hlinfo
))
25950 cursor
= No_Cursor
;
25952 /* If no overlay applies, get a text property. */
25953 if (NILP (overlay
))
25954 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25956 /* Next, compute the bounds of the mouse highlighting and
25958 if (!NILP (mouse_face
) && STRINGP (object
))
25960 /* The mouse-highlighting comes from a display string
25961 with a mouse-face. */
25965 s
= Fprevious_single_property_change
25966 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25967 e
= Fnext_single_property_change
25968 (position
, Qmouse_face
, object
, Qnil
);
25970 s
= make_number (0);
25972 e
= make_number (SCHARS (object
) - 1);
25973 mouse_face_from_string_pos (w
, hlinfo
, object
,
25974 XINT (s
), XINT (e
));
25975 hlinfo
->mouse_face_past_end
= 0;
25976 hlinfo
->mouse_face_window
= window
;
25977 hlinfo
->mouse_face_face_id
25978 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25979 glyph
->face_id
, 1);
25980 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25981 cursor
= No_Cursor
;
25985 /* The mouse-highlighting, if any, comes from an overlay
25986 or text property in the buffer. */
25987 Lisp_Object buffer
IF_LINT (= Qnil
);
25988 Lisp_Object cover_string
IF_LINT (= Qnil
);
25990 if (STRINGP (object
))
25992 /* If we are on a display string with no mouse-face,
25993 check if the text under it has one. */
25994 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25995 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25996 pos
= string_buffer_position (object
, start
);
25999 mouse_face
= get_char_property_and_overlay
26000 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
26001 buffer
= w
->buffer
;
26002 cover_string
= object
;
26008 cover_string
= Qnil
;
26011 if (!NILP (mouse_face
))
26013 Lisp_Object before
, after
;
26014 Lisp_Object before_string
, after_string
;
26015 /* To correctly find the limits of mouse highlight
26016 in a bidi-reordered buffer, we must not use the
26017 optimization of limiting the search in
26018 previous-single-property-change and
26019 next-single-property-change, because
26020 rows_from_pos_range needs the real start and end
26021 positions to DTRT in this case. That's because
26022 the first row visible in a window does not
26023 necessarily display the character whose position
26024 is the smallest. */
26026 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26027 ? Fmarker_position (w
->start
)
26030 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26031 ? make_number (BUF_Z (XBUFFER (buffer
))
26032 - XFASTINT (w
->window_end_pos
))
26035 if (NILP (overlay
))
26037 /* Handle the text property case. */
26038 before
= Fprevious_single_property_change
26039 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
26040 after
= Fnext_single_property_change
26041 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
26042 before_string
= after_string
= Qnil
;
26046 /* Handle the overlay case. */
26047 before
= Foverlay_start (overlay
);
26048 after
= Foverlay_end (overlay
);
26049 before_string
= Foverlay_get (overlay
, Qbefore_string
);
26050 after_string
= Foverlay_get (overlay
, Qafter_string
);
26052 if (!STRINGP (before_string
)) before_string
= Qnil
;
26053 if (!STRINGP (after_string
)) after_string
= Qnil
;
26056 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
26059 before_string
, after_string
,
26061 cursor
= No_Cursor
;
26068 /* Look for a `help-echo' property. */
26069 if (NILP (help_echo_string
)) {
26070 Lisp_Object help
, overlay
;
26072 /* Check overlays first. */
26073 help
= overlay
= Qnil
;
26074 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
26076 overlay
= overlay_vec
[i
];
26077 help
= Foverlay_get (overlay
, Qhelp_echo
);
26082 help_echo_string
= help
;
26083 help_echo_window
= window
;
26084 help_echo_object
= overlay
;
26085 help_echo_pos
= pos
;
26089 Lisp_Object obj
= glyph
->object
;
26090 EMACS_INT charpos
= glyph
->charpos
;
26092 /* Try text properties. */
26095 && charpos
< SCHARS (obj
))
26097 help
= Fget_text_property (make_number (charpos
),
26101 /* If the string itself doesn't specify a help-echo,
26102 see if the buffer text ``under'' it does. */
26103 struct glyph_row
*r
26104 = MATRIX_ROW (w
->current_matrix
, vpos
);
26105 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26106 EMACS_INT p
= string_buffer_position (obj
, start
);
26109 help
= Fget_char_property (make_number (p
),
26110 Qhelp_echo
, w
->buffer
);
26119 else if (BUFFERP (obj
)
26122 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
26127 help_echo_string
= help
;
26128 help_echo_window
= window
;
26129 help_echo_object
= obj
;
26130 help_echo_pos
= charpos
;
26135 #ifdef HAVE_WINDOW_SYSTEM
26136 /* Look for a `pointer' property. */
26137 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26139 /* Check overlays first. */
26140 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
26141 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
26143 if (NILP (pointer
))
26145 Lisp_Object obj
= glyph
->object
;
26146 EMACS_INT charpos
= glyph
->charpos
;
26148 /* Try text properties. */
26151 && charpos
< SCHARS (obj
))
26153 pointer
= Fget_text_property (make_number (charpos
),
26155 if (NILP (pointer
))
26157 /* If the string itself doesn't specify a pointer,
26158 see if the buffer text ``under'' it does. */
26159 struct glyph_row
*r
26160 = MATRIX_ROW (w
->current_matrix
, vpos
);
26161 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26162 EMACS_INT p
= string_buffer_position (obj
, start
);
26164 pointer
= Fget_char_property (make_number (p
),
26165 Qpointer
, w
->buffer
);
26168 else if (BUFFERP (obj
)
26171 pointer
= Fget_text_property (make_number (charpos
),
26175 #endif /* HAVE_WINDOW_SYSTEM */
26179 current_buffer
= obuf
;
26184 #ifdef HAVE_WINDOW_SYSTEM
26185 if (FRAME_WINDOW_P (f
))
26186 define_frame_cursor1 (f
, cursor
, pointer
);
26188 /* This is here to prevent a compiler error, about "label at end of
26189 compound statement". */
26196 Clear any mouse-face on window W. This function is part of the
26197 redisplay interface, and is called from try_window_id and similar
26198 functions to ensure the mouse-highlight is off. */
26201 x_clear_window_mouse_face (struct window
*w
)
26203 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26204 Lisp_Object window
;
26207 XSETWINDOW (window
, w
);
26208 if (EQ (window
, hlinfo
->mouse_face_window
))
26209 clear_mouse_face (hlinfo
);
26215 Just discard the mouse face information for frame F, if any.
26216 This is used when the size of F is changed. */
26219 cancel_mouse_face (struct frame
*f
)
26221 Lisp_Object window
;
26222 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26224 window
= hlinfo
->mouse_face_window
;
26225 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
26227 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26228 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26229 hlinfo
->mouse_face_window
= Qnil
;
26235 /***********************************************************************
26237 ***********************************************************************/
26239 #ifdef HAVE_WINDOW_SYSTEM
26241 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
26242 which intersects rectangle R. R is in window-relative coordinates. */
26245 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
26246 enum glyph_row_area area
)
26248 struct glyph
*first
= row
->glyphs
[area
];
26249 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
26250 struct glyph
*last
;
26251 int first_x
, start_x
, x
;
26253 if (area
== TEXT_AREA
&& row
->fill_line_p
)
26254 /* If row extends face to end of line write the whole line. */
26255 draw_glyphs (w
, 0, row
, area
,
26256 0, row
->used
[area
],
26257 DRAW_NORMAL_TEXT
, 0);
26260 /* Set START_X to the window-relative start position for drawing glyphs of
26261 AREA. The first glyph of the text area can be partially visible.
26262 The first glyphs of other areas cannot. */
26263 start_x
= window_box_left_offset (w
, area
);
26265 if (area
== TEXT_AREA
)
26268 /* Find the first glyph that must be redrawn. */
26270 && x
+ first
->pixel_width
< r
->x
)
26272 x
+= first
->pixel_width
;
26276 /* Find the last one. */
26280 && x
< r
->x
+ r
->width
)
26282 x
+= last
->pixel_width
;
26288 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26289 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26290 DRAW_NORMAL_TEXT
, 0);
26295 /* Redraw the parts of the glyph row ROW on window W intersecting
26296 rectangle R. R is in window-relative coordinates. Value is
26297 non-zero if mouse-face was overwritten. */
26300 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26302 xassert (row
->enabled_p
);
26304 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26305 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26306 0, row
->used
[TEXT_AREA
],
26307 DRAW_NORMAL_TEXT
, 0);
26310 if (row
->used
[LEFT_MARGIN_AREA
])
26311 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26312 if (row
->used
[TEXT_AREA
])
26313 expose_area (w
, row
, r
, TEXT_AREA
);
26314 if (row
->used
[RIGHT_MARGIN_AREA
])
26315 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26316 draw_row_fringe_bitmaps (w
, row
);
26319 return row
->mouse_face_p
;
26323 /* Redraw those parts of glyphs rows during expose event handling that
26324 overlap other rows. Redrawing of an exposed line writes over parts
26325 of lines overlapping that exposed line; this function fixes that.
26327 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26328 row in W's current matrix that is exposed and overlaps other rows.
26329 LAST_OVERLAPPING_ROW is the last such row. */
26332 expose_overlaps (struct window
*w
,
26333 struct glyph_row
*first_overlapping_row
,
26334 struct glyph_row
*last_overlapping_row
,
26337 struct glyph_row
*row
;
26339 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26340 if (row
->overlapping_p
)
26342 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26345 if (row
->used
[LEFT_MARGIN_AREA
])
26346 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26348 if (row
->used
[TEXT_AREA
])
26349 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26351 if (row
->used
[RIGHT_MARGIN_AREA
])
26352 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26358 /* Return non-zero if W's cursor intersects rectangle R. */
26361 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26363 XRectangle cr
, result
;
26364 struct glyph
*cursor_glyph
;
26365 struct glyph_row
*row
;
26367 if (w
->phys_cursor
.vpos
>= 0
26368 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26369 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26371 && row
->cursor_in_fringe_p
)
26373 /* Cursor is in the fringe. */
26374 cr
.x
= window_box_right_offset (w
,
26375 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26376 ? RIGHT_MARGIN_AREA
26379 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26380 cr
.height
= row
->height
;
26381 return x_intersect_rectangles (&cr
, r
, &result
);
26384 cursor_glyph
= get_phys_cursor_glyph (w
);
26387 /* r is relative to W's box, but w->phys_cursor.x is relative
26388 to left edge of W's TEXT area. Adjust it. */
26389 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26390 cr
.y
= w
->phys_cursor
.y
;
26391 cr
.width
= cursor_glyph
->pixel_width
;
26392 cr
.height
= w
->phys_cursor_height
;
26393 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26394 I assume the effect is the same -- and this is portable. */
26395 return x_intersect_rectangles (&cr
, r
, &result
);
26397 /* If we don't understand the format, pretend we're not in the hot-spot. */
26403 Draw a vertical window border to the right of window W if W doesn't
26404 have vertical scroll bars. */
26407 x_draw_vertical_border (struct window
*w
)
26409 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26411 /* We could do better, if we knew what type of scroll-bar the adjacent
26412 windows (on either side) have... But we don't :-(
26413 However, I think this works ok. ++KFS 2003-04-25 */
26415 /* Redraw borders between horizontally adjacent windows. Don't
26416 do it for frames with vertical scroll bars because either the
26417 right scroll bar of a window, or the left scroll bar of its
26418 neighbor will suffice as a border. */
26419 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26422 if (!WINDOW_RIGHTMOST_P (w
)
26423 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26425 int x0
, x1
, y0
, y1
;
26427 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26430 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26433 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26435 else if (!WINDOW_LEFTMOST_P (w
)
26436 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26438 int x0
, x1
, y0
, y1
;
26440 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26443 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26446 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26451 /* Redraw the part of window W intersection rectangle FR. Pixel
26452 coordinates in FR are frame-relative. Call this function with
26453 input blocked. Value is non-zero if the exposure overwrites
26457 expose_window (struct window
*w
, XRectangle
*fr
)
26459 struct frame
*f
= XFRAME (w
->frame
);
26461 int mouse_face_overwritten_p
= 0;
26463 /* If window is not yet fully initialized, do nothing. This can
26464 happen when toolkit scroll bars are used and a window is split.
26465 Reconfiguring the scroll bar will generate an expose for a newly
26467 if (w
->current_matrix
== NULL
)
26470 /* When we're currently updating the window, display and current
26471 matrix usually don't agree. Arrange for a thorough display
26473 if (w
== updated_window
)
26475 SET_FRAME_GARBAGED (f
);
26479 /* Frame-relative pixel rectangle of W. */
26480 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26481 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26482 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26483 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26485 if (x_intersect_rectangles (fr
, &wr
, &r
))
26487 int yb
= window_text_bottom_y (w
);
26488 struct glyph_row
*row
;
26489 int cursor_cleared_p
;
26490 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26492 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26493 r
.x
, r
.y
, r
.width
, r
.height
));
26495 /* Convert to window coordinates. */
26496 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26497 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26499 /* Turn off the cursor. */
26500 if (!w
->pseudo_window_p
26501 && phys_cursor_in_rect_p (w
, &r
))
26503 x_clear_cursor (w
);
26504 cursor_cleared_p
= 1;
26507 cursor_cleared_p
= 0;
26509 /* Update lines intersecting rectangle R. */
26510 first_overlapping_row
= last_overlapping_row
= NULL
;
26511 for (row
= w
->current_matrix
->rows
;
26516 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26518 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26519 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26520 || (r
.y
>= y0
&& r
.y
< y1
)
26521 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26523 /* A header line may be overlapping, but there is no need
26524 to fix overlapping areas for them. KFS 2005-02-12 */
26525 if (row
->overlapping_p
&& !row
->mode_line_p
)
26527 if (first_overlapping_row
== NULL
)
26528 first_overlapping_row
= row
;
26529 last_overlapping_row
= row
;
26533 if (expose_line (w
, row
, &r
))
26534 mouse_face_overwritten_p
= 1;
26537 else if (row
->overlapping_p
)
26539 /* We must redraw a row overlapping the exposed area. */
26541 ? y0
+ row
->phys_height
> r
.y
26542 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26544 if (first_overlapping_row
== NULL
)
26545 first_overlapping_row
= row
;
26546 last_overlapping_row
= row
;
26554 /* Display the mode line if there is one. */
26555 if (WINDOW_WANTS_MODELINE_P (w
)
26556 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26558 && row
->y
< r
.y
+ r
.height
)
26560 if (expose_line (w
, row
, &r
))
26561 mouse_face_overwritten_p
= 1;
26564 if (!w
->pseudo_window_p
)
26566 /* Fix the display of overlapping rows. */
26567 if (first_overlapping_row
)
26568 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26571 /* Draw border between windows. */
26572 x_draw_vertical_border (w
);
26574 /* Turn the cursor on again. */
26575 if (cursor_cleared_p
)
26576 update_window_cursor (w
, 1);
26580 return mouse_face_overwritten_p
;
26585 /* Redraw (parts) of all windows in the window tree rooted at W that
26586 intersect R. R contains frame pixel coordinates. Value is
26587 non-zero if the exposure overwrites mouse-face. */
26590 expose_window_tree (struct window
*w
, XRectangle
*r
)
26592 struct frame
*f
= XFRAME (w
->frame
);
26593 int mouse_face_overwritten_p
= 0;
26595 while (w
&& !FRAME_GARBAGED_P (f
))
26597 if (!NILP (w
->hchild
))
26598 mouse_face_overwritten_p
26599 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26600 else if (!NILP (w
->vchild
))
26601 mouse_face_overwritten_p
26602 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26604 mouse_face_overwritten_p
|= expose_window (w
, r
);
26606 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26609 return mouse_face_overwritten_p
;
26614 Redisplay an exposed area of frame F. X and Y are the upper-left
26615 corner of the exposed rectangle. W and H are width and height of
26616 the exposed area. All are pixel values. W or H zero means redraw
26617 the entire frame. */
26620 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26623 int mouse_face_overwritten_p
= 0;
26625 TRACE ((stderr
, "expose_frame "));
26627 /* No need to redraw if frame will be redrawn soon. */
26628 if (FRAME_GARBAGED_P (f
))
26630 TRACE ((stderr
, " garbaged\n"));
26634 /* If basic faces haven't been realized yet, there is no point in
26635 trying to redraw anything. This can happen when we get an expose
26636 event while Emacs is starting, e.g. by moving another window. */
26637 if (FRAME_FACE_CACHE (f
) == NULL
26638 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26640 TRACE ((stderr
, " no faces\n"));
26644 if (w
== 0 || h
== 0)
26647 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26648 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26658 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26659 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26661 if (WINDOWP (f
->tool_bar_window
))
26662 mouse_face_overwritten_p
26663 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26665 #ifdef HAVE_X_WINDOWS
26667 #ifndef USE_X_TOOLKIT
26668 if (WINDOWP (f
->menu_bar_window
))
26669 mouse_face_overwritten_p
26670 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26671 #endif /* not USE_X_TOOLKIT */
26675 /* Some window managers support a focus-follows-mouse style with
26676 delayed raising of frames. Imagine a partially obscured frame,
26677 and moving the mouse into partially obscured mouse-face on that
26678 frame. The visible part of the mouse-face will be highlighted,
26679 then the WM raises the obscured frame. With at least one WM, KDE
26680 2.1, Emacs is not getting any event for the raising of the frame
26681 (even tried with SubstructureRedirectMask), only Expose events.
26682 These expose events will draw text normally, i.e. not
26683 highlighted. Which means we must redo the highlight here.
26684 Subsume it under ``we love X''. --gerd 2001-08-15 */
26685 /* Included in Windows version because Windows most likely does not
26686 do the right thing if any third party tool offers
26687 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26688 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26690 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26691 if (f
== hlinfo
->mouse_face_mouse_frame
)
26693 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26694 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26695 clear_mouse_face (hlinfo
);
26696 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26703 Determine the intersection of two rectangles R1 and R2. Return
26704 the intersection in *RESULT. Value is non-zero if RESULT is not
26708 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26710 XRectangle
*left
, *right
;
26711 XRectangle
*upper
, *lower
;
26712 int intersection_p
= 0;
26714 /* Rearrange so that R1 is the left-most rectangle. */
26716 left
= r1
, right
= r2
;
26718 left
= r2
, right
= r1
;
26720 /* X0 of the intersection is right.x0, if this is inside R1,
26721 otherwise there is no intersection. */
26722 if (right
->x
<= left
->x
+ left
->width
)
26724 result
->x
= right
->x
;
26726 /* The right end of the intersection is the minimum of the
26727 the right ends of left and right. */
26728 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26731 /* Same game for Y. */
26733 upper
= r1
, lower
= r2
;
26735 upper
= r2
, lower
= r1
;
26737 /* The upper end of the intersection is lower.y0, if this is inside
26738 of upper. Otherwise, there is no intersection. */
26739 if (lower
->y
<= upper
->y
+ upper
->height
)
26741 result
->y
= lower
->y
;
26743 /* The lower end of the intersection is the minimum of the lower
26744 ends of upper and lower. */
26745 result
->height
= (min (lower
->y
+ lower
->height
,
26746 upper
->y
+ upper
->height
)
26748 intersection_p
= 1;
26752 return intersection_p
;
26755 #endif /* HAVE_WINDOW_SYSTEM */
26758 /***********************************************************************
26760 ***********************************************************************/
26763 syms_of_xdisp (void)
26765 Vwith_echo_area_save_vector
= Qnil
;
26766 staticpro (&Vwith_echo_area_save_vector
);
26768 Vmessage_stack
= Qnil
;
26769 staticpro (&Vmessage_stack
);
26771 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26772 staticpro (&Qinhibit_redisplay
);
26774 message_dolog_marker1
= Fmake_marker ();
26775 staticpro (&message_dolog_marker1
);
26776 message_dolog_marker2
= Fmake_marker ();
26777 staticpro (&message_dolog_marker2
);
26778 message_dolog_marker3
= Fmake_marker ();
26779 staticpro (&message_dolog_marker3
);
26782 defsubr (&Sdump_frame_glyph_matrix
);
26783 defsubr (&Sdump_glyph_matrix
);
26784 defsubr (&Sdump_glyph_row
);
26785 defsubr (&Sdump_tool_bar_row
);
26786 defsubr (&Strace_redisplay
);
26787 defsubr (&Strace_to_stderr
);
26789 #ifdef HAVE_WINDOW_SYSTEM
26790 defsubr (&Stool_bar_lines_needed
);
26791 defsubr (&Slookup_image_map
);
26793 defsubr (&Sformat_mode_line
);
26794 defsubr (&Sinvisible_p
);
26795 defsubr (&Scurrent_bidi_paragraph_direction
);
26797 staticpro (&Qmenu_bar_update_hook
);
26798 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26800 staticpro (&Qoverriding_terminal_local_map
);
26801 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26803 staticpro (&Qoverriding_local_map
);
26804 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26806 staticpro (&Qwindow_scroll_functions
);
26807 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26809 staticpro (&Qwindow_text_change_functions
);
26810 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26812 staticpro (&Qredisplay_end_trigger_functions
);
26813 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26815 staticpro (&Qinhibit_point_motion_hooks
);
26816 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26818 Qeval
= intern_c_string ("eval");
26819 staticpro (&Qeval
);
26821 QCdata
= intern_c_string (":data");
26822 staticpro (&QCdata
);
26823 Qdisplay
= intern_c_string ("display");
26824 staticpro (&Qdisplay
);
26825 Qspace_width
= intern_c_string ("space-width");
26826 staticpro (&Qspace_width
);
26827 Qraise
= intern_c_string ("raise");
26828 staticpro (&Qraise
);
26829 Qslice
= intern_c_string ("slice");
26830 staticpro (&Qslice
);
26831 Qspace
= intern_c_string ("space");
26832 staticpro (&Qspace
);
26833 Qmargin
= intern_c_string ("margin");
26834 staticpro (&Qmargin
);
26835 Qpointer
= intern_c_string ("pointer");
26836 staticpro (&Qpointer
);
26837 Qleft_margin
= intern_c_string ("left-margin");
26838 staticpro (&Qleft_margin
);
26839 Qright_margin
= intern_c_string ("right-margin");
26840 staticpro (&Qright_margin
);
26841 Qcenter
= intern_c_string ("center");
26842 staticpro (&Qcenter
);
26843 Qline_height
= intern_c_string ("line-height");
26844 staticpro (&Qline_height
);
26845 QCalign_to
= intern_c_string (":align-to");
26846 staticpro (&QCalign_to
);
26847 QCrelative_width
= intern_c_string (":relative-width");
26848 staticpro (&QCrelative_width
);
26849 QCrelative_height
= intern_c_string (":relative-height");
26850 staticpro (&QCrelative_height
);
26851 QCeval
= intern_c_string (":eval");
26852 staticpro (&QCeval
);
26853 QCpropertize
= intern_c_string (":propertize");
26854 staticpro (&QCpropertize
);
26855 QCfile
= intern_c_string (":file");
26856 staticpro (&QCfile
);
26857 Qfontified
= intern_c_string ("fontified");
26858 staticpro (&Qfontified
);
26859 Qfontification_functions
= intern_c_string ("fontification-functions");
26860 staticpro (&Qfontification_functions
);
26861 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26862 staticpro (&Qtrailing_whitespace
);
26863 Qescape_glyph
= intern_c_string ("escape-glyph");
26864 staticpro (&Qescape_glyph
);
26865 Qnobreak_space
= intern_c_string ("nobreak-space");
26866 staticpro (&Qnobreak_space
);
26867 Qimage
= intern_c_string ("image");
26868 staticpro (&Qimage
);
26869 Qtext
= intern_c_string ("text");
26870 staticpro (&Qtext
);
26871 Qboth
= intern_c_string ("both");
26872 staticpro (&Qboth
);
26873 Qboth_horiz
= intern_c_string ("both-horiz");
26874 staticpro (&Qboth_horiz
);
26875 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26876 staticpro (&Qtext_image_horiz
);
26877 QCmap
= intern_c_string (":map");
26878 staticpro (&QCmap
);
26879 QCpointer
= intern_c_string (":pointer");
26880 staticpro (&QCpointer
);
26881 Qrect
= intern_c_string ("rect");
26882 staticpro (&Qrect
);
26883 Qcircle
= intern_c_string ("circle");
26884 staticpro (&Qcircle
);
26885 Qpoly
= intern_c_string ("poly");
26886 staticpro (&Qpoly
);
26887 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
26888 staticpro (&Qmessage_truncate_lines
);
26889 Qgrow_only
= intern_c_string ("grow-only");
26890 staticpro (&Qgrow_only
);
26891 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
26892 staticpro (&Qinhibit_menubar_update
);
26893 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
26894 staticpro (&Qinhibit_eval_during_redisplay
);
26895 Qposition
= intern_c_string ("position");
26896 staticpro (&Qposition
);
26897 Qbuffer_position
= intern_c_string ("buffer-position");
26898 staticpro (&Qbuffer_position
);
26899 Qobject
= intern_c_string ("object");
26900 staticpro (&Qobject
);
26901 Qbar
= intern_c_string ("bar");
26903 Qhbar
= intern_c_string ("hbar");
26904 staticpro (&Qhbar
);
26905 Qbox
= intern_c_string ("box");
26907 Qhollow
= intern_c_string ("hollow");
26908 staticpro (&Qhollow
);
26909 Qhand
= intern_c_string ("hand");
26910 staticpro (&Qhand
);
26911 Qarrow
= intern_c_string ("arrow");
26912 staticpro (&Qarrow
);
26913 Qtext
= intern_c_string ("text");
26914 staticpro (&Qtext
);
26915 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
26916 staticpro (&Qinhibit_free_realized_faces
);
26918 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26919 Fcons (intern_c_string ("void-variable"), Qnil
)),
26921 staticpro (&list_of_error
);
26923 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
26924 staticpro (&Qlast_arrow_position
);
26925 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
26926 staticpro (&Qlast_arrow_string
);
26928 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
26929 staticpro (&Qoverlay_arrow_string
);
26930 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
26931 staticpro (&Qoverlay_arrow_bitmap
);
26933 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26934 staticpro (&echo_buffer
[0]);
26935 staticpro (&echo_buffer
[1]);
26937 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26938 staticpro (&echo_area_buffer
[0]);
26939 staticpro (&echo_area_buffer
[1]);
26941 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26942 staticpro (&Vmessages_buffer_name
);
26944 mode_line_proptrans_alist
= Qnil
;
26945 staticpro (&mode_line_proptrans_alist
);
26946 mode_line_string_list
= Qnil
;
26947 staticpro (&mode_line_string_list
);
26948 mode_line_string_face
= Qnil
;
26949 staticpro (&mode_line_string_face
);
26950 mode_line_string_face_prop
= Qnil
;
26951 staticpro (&mode_line_string_face_prop
);
26952 Vmode_line_unwind_vector
= Qnil
;
26953 staticpro (&Vmode_line_unwind_vector
);
26955 help_echo_string
= Qnil
;
26956 staticpro (&help_echo_string
);
26957 help_echo_object
= Qnil
;
26958 staticpro (&help_echo_object
);
26959 help_echo_window
= Qnil
;
26960 staticpro (&help_echo_window
);
26961 previous_help_echo_string
= Qnil
;
26962 staticpro (&previous_help_echo_string
);
26963 help_echo_pos
= -1;
26965 Qright_to_left
= intern_c_string ("right-to-left");
26966 staticpro (&Qright_to_left
);
26967 Qleft_to_right
= intern_c_string ("left-to-right");
26968 staticpro (&Qleft_to_right
);
26970 #ifdef HAVE_WINDOW_SYSTEM
26971 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
26972 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26973 For example, if a block cursor is over a tab, it will be drawn as
26974 wide as that tab on the display. */);
26975 x_stretch_cursor_p
= 0;
26978 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
26979 doc
: /* *Non-nil means highlight trailing whitespace.
26980 The face used for trailing whitespace is `trailing-whitespace'. */);
26981 Vshow_trailing_whitespace
= Qnil
;
26983 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
26984 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26985 A value of t means highlight the character itself (for nobreak space,
26986 use face `nobreak-space').
26987 A value of nil means no highlighting.
26988 Other values mean display the escape glyph followed by an ordinary
26989 space or ordinary hyphen. */);
26990 Vnobreak_char_display
= Qt
;
26992 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
26993 doc
: /* *The pointer shape to show in void text areas.
26994 A value of nil means to show the text pointer. Other options are `arrow',
26995 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26996 Vvoid_text_area_pointer
= Qarrow
;
26998 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
26999 doc
: /* Non-nil means don't actually do any redisplay.
27000 This is used for internal purposes. */);
27001 Vinhibit_redisplay
= Qnil
;
27003 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
27004 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
27005 Vglobal_mode_string
= Qnil
;
27007 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
27008 doc
: /* Marker for where to display an arrow on top of the buffer text.
27009 This must be the beginning of a line in order to work.
27010 See also `overlay-arrow-string'. */);
27011 Voverlay_arrow_position
= Qnil
;
27013 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
27014 doc
: /* String to display as an arrow in non-window frames.
27015 See also `overlay-arrow-position'. */);
27016 Voverlay_arrow_string
= make_pure_c_string ("=>");
27018 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
27019 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
27020 The symbols on this list are examined during redisplay to determine
27021 where to display overlay arrows. */);
27022 Voverlay_arrow_variable_list
27023 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
27025 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
27026 doc
: /* *The number of lines to try scrolling a window by when point moves out.
27027 If that fails to bring point back on frame, point is centered instead.
27028 If this is zero, point is always centered after it moves off frame.
27029 If you want scrolling to always be a line at a time, you should set
27030 `scroll-conservatively' to a large value rather than set this to 1. */);
27032 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
27033 doc
: /* *Scroll up to this many lines, to bring point back on screen.
27034 If point moves off-screen, redisplay will scroll by up to
27035 `scroll-conservatively' lines in order to bring point just barely
27036 onto the screen again. If that cannot be done, then redisplay
27037 recenters point as usual.
27039 If the value is greater than 100, redisplay will never recenter point,
27040 but will always scroll just enough text to bring point into view, even
27041 if you move far away.
27043 A value of zero means always recenter point if it moves off screen. */);
27044 scroll_conservatively
= 0;
27046 DEFVAR_INT ("scroll-margin", scroll_margin
,
27047 doc
: /* *Number of lines of margin at the top and bottom of a window.
27048 Recenter the window whenever point gets within this many lines
27049 of the top or bottom of the window. */);
27052 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
27053 doc
: /* Pixels per inch value for non-window system displays.
27054 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
27055 Vdisplay_pixels_per_inch
= make_float (72.0);
27058 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
27061 DEFVAR_LISP ("truncate-partial-width-windows",
27062 Vtruncate_partial_width_windows
,
27063 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
27064 For an integer value, truncate lines in each window narrower than the
27065 full frame width, provided the window width is less than that integer;
27066 otherwise, respect the value of `truncate-lines'.
27068 For any other non-nil value, truncate lines in all windows that do
27069 not span the full frame width.
27071 A value of nil means to respect the value of `truncate-lines'.
27073 If `word-wrap' is enabled, you might want to reduce this. */);
27074 Vtruncate_partial_width_windows
= make_number (50);
27076 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
27077 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
27078 Any other value means to use the appropriate face, `mode-line',
27079 `header-line', or `menu' respectively. */);
27080 mode_line_inverse_video
= 1;
27082 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
27083 doc
: /* *Maximum buffer size for which line number should be displayed.
27084 If the buffer is bigger than this, the line number does not appear
27085 in the mode line. A value of nil means no limit. */);
27086 Vline_number_display_limit
= Qnil
;
27088 DEFVAR_INT ("line-number-display-limit-width",
27089 line_number_display_limit_width
,
27090 doc
: /* *Maximum line width (in characters) for line number display.
27091 If the average length of the lines near point is bigger than this, then the
27092 line number may be omitted from the mode line. */);
27093 line_number_display_limit_width
= 200;
27095 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
27096 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
27097 highlight_nonselected_windows
= 0;
27099 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
27100 doc
: /* Non-nil if more than one frame is visible on this display.
27101 Minibuffer-only frames don't count, but iconified frames do.
27102 This variable is not guaranteed to be accurate except while processing
27103 `frame-title-format' and `icon-title-format'. */);
27105 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
27106 doc
: /* Template for displaying the title bar of visible frames.
27107 \(Assuming the window manager supports this feature.)
27109 This variable has the same structure as `mode-line-format', except that
27110 the %c and %l constructs are ignored. It is used only on frames for
27111 which no explicit name has been set \(see `modify-frame-parameters'). */);
27113 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
27114 doc
: /* Template for displaying the title bar of an iconified frame.
27115 \(Assuming the window manager supports this feature.)
27116 This variable has the same structure as `mode-line-format' (which see),
27117 and is used only on frames for which no explicit name has been set
27118 \(see `modify-frame-parameters'). */);
27120 = Vframe_title_format
27121 = pure_cons (intern_c_string ("multiple-frames"),
27122 pure_cons (make_pure_c_string ("%b"),
27123 pure_cons (pure_cons (empty_unibyte_string
,
27124 pure_cons (intern_c_string ("invocation-name"),
27125 pure_cons (make_pure_c_string ("@"),
27126 pure_cons (intern_c_string ("system-name"),
27130 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
27131 doc
: /* Maximum number of lines to keep in the message log buffer.
27132 If nil, disable message logging. If t, log messages but don't truncate
27133 the buffer when it becomes large. */);
27134 Vmessage_log_max
= make_number (100);
27136 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
27137 doc
: /* Functions called before redisplay, if window sizes have changed.
27138 The value should be a list of functions that take one argument.
27139 Just before redisplay, for each frame, if any of its windows have changed
27140 size since the last redisplay, or have been split or deleted,
27141 all the functions in the list are called, with the frame as argument. */);
27142 Vwindow_size_change_functions
= Qnil
;
27144 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
27145 doc
: /* List of functions to call before redisplaying a window with scrolling.
27146 Each function is called with two arguments, the window and its new
27147 display-start position. Note that these functions are also called by
27148 `set-window-buffer'. Also note that the value of `window-end' is not
27149 valid when these functions are called. */);
27150 Vwindow_scroll_functions
= Qnil
;
27152 DEFVAR_LISP ("window-text-change-functions",
27153 Vwindow_text_change_functions
,
27154 doc
: /* Functions to call in redisplay when text in the window might change. */);
27155 Vwindow_text_change_functions
= Qnil
;
27157 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
27158 doc
: /* Functions called when redisplay of a window reaches the end trigger.
27159 Each function is called with two arguments, the window and the end trigger value.
27160 See `set-window-redisplay-end-trigger'. */);
27161 Vredisplay_end_trigger_functions
= Qnil
;
27163 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
27164 doc
: /* *Non-nil means autoselect window with mouse pointer.
27165 If nil, do not autoselect windows.
27166 A positive number means delay autoselection by that many seconds: a
27167 window is autoselected only after the mouse has remained in that
27168 window for the duration of the delay.
27169 A negative number has a similar effect, but causes windows to be
27170 autoselected only after the mouse has stopped moving. \(Because of
27171 the way Emacs compares mouse events, you will occasionally wait twice
27172 that time before the window gets selected.\)
27173 Any other value means to autoselect window instantaneously when the
27174 mouse pointer enters it.
27176 Autoselection selects the minibuffer only if it is active, and never
27177 unselects the minibuffer if it is active.
27179 When customizing this variable make sure that the actual value of
27180 `focus-follows-mouse' matches the behavior of your window manager. */);
27181 Vmouse_autoselect_window
= Qnil
;
27183 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
27184 doc
: /* *Non-nil means automatically resize tool-bars.
27185 This dynamically changes the tool-bar's height to the minimum height
27186 that is needed to make all tool-bar items visible.
27187 If value is `grow-only', the tool-bar's height is only increased
27188 automatically; to decrease the tool-bar height, use \\[recenter]. */);
27189 Vauto_resize_tool_bars
= Qt
;
27191 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
27192 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
27193 auto_raise_tool_bar_buttons_p
= 1;
27195 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
27196 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
27197 make_cursor_line_fully_visible_p
= 1;
27199 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
27200 doc
: /* *Border below tool-bar in pixels.
27201 If an integer, use it as the height of the border.
27202 If it is one of `internal-border-width' or `border-width', use the
27203 value of the corresponding frame parameter.
27204 Otherwise, no border is added below the tool-bar. */);
27205 Vtool_bar_border
= Qinternal_border_width
;
27207 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
27208 doc
: /* *Margin around tool-bar buttons in pixels.
27209 If an integer, use that for both horizontal and vertical margins.
27210 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
27211 HORZ specifying the horizontal margin, and VERT specifying the
27212 vertical margin. */);
27213 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
27215 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
27216 doc
: /* *Relief thickness of tool-bar buttons. */);
27217 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
27219 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
27220 doc
: /* Tool bar style to use.
27222 image - show images only
27223 text - show text only
27224 both - show both, text below image
27225 both-horiz - show text to the right of the image
27226 text-image-horiz - show text to the left of the image
27227 any other - use system default or image if no system default. */);
27228 Vtool_bar_style
= Qnil
;
27230 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
27231 doc
: /* *Maximum number of characters a label can have to be shown.
27232 The tool bar style must also show labels for this to have any effect, see
27233 `tool-bar-style'. */);
27234 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
27236 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
27237 doc
: /* List of functions to call to fontify regions of text.
27238 Each function is called with one argument POS. Functions must
27239 fontify a region starting at POS in the current buffer, and give
27240 fontified regions the property `fontified'. */);
27241 Vfontification_functions
= Qnil
;
27242 Fmake_variable_buffer_local (Qfontification_functions
);
27244 DEFVAR_BOOL ("unibyte-display-via-language-environment",
27245 unibyte_display_via_language_environment
,
27246 doc
: /* *Non-nil means display unibyte text according to language environment.
27247 Specifically, this means that raw bytes in the range 160-255 decimal
27248 are displayed by converting them to the equivalent multibyte characters
27249 according to the current language environment. As a result, they are
27250 displayed according to the current fontset.
27252 Note that this variable affects only how these bytes are displayed,
27253 but does not change the fact they are interpreted as raw bytes. */);
27254 unibyte_display_via_language_environment
= 0;
27256 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
27257 doc
: /* *Maximum height for resizing mini-windows.
27258 If a float, it specifies a fraction of the mini-window frame's height.
27259 If an integer, it specifies a number of lines. */);
27260 Vmax_mini_window_height
= make_float (0.25);
27262 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
27263 doc
: /* *How to resize mini-windows.
27264 A value of nil means don't automatically resize mini-windows.
27265 A value of t means resize them to fit the text displayed in them.
27266 A value of `grow-only', the default, means let mini-windows grow
27267 only, until their display becomes empty, at which point the windows
27268 go back to their normal size. */);
27269 Vresize_mini_windows
= Qgrow_only
;
27271 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27272 doc
: /* Alist specifying how to blink the cursor off.
27273 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27274 `cursor-type' frame-parameter or variable equals ON-STATE,
27275 comparing using `equal', Emacs uses OFF-STATE to specify
27276 how to blink it off. ON-STATE and OFF-STATE are values for
27277 the `cursor-type' frame parameter.
27279 If a frame's ON-STATE has no entry in this list,
27280 the frame's other specifications determine how to blink the cursor off. */);
27281 Vblink_cursor_alist
= Qnil
;
27283 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27284 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27285 If non-nil, windows are automatically scrolled horizontally to make
27286 point visible. */);
27287 automatic_hscrolling_p
= 1;
27288 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27289 staticpro (&Qauto_hscroll_mode
);
27291 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27292 doc
: /* *How many columns away from the window edge point is allowed to get
27293 before automatic hscrolling will horizontally scroll the window. */);
27294 hscroll_margin
= 5;
27296 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27297 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27298 When point is less than `hscroll-margin' columns from the window
27299 edge, automatic hscrolling will scroll the window by the amount of columns
27300 determined by this variable. If its value is a positive integer, scroll that
27301 many columns. If it's a positive floating-point number, it specifies the
27302 fraction of the window's width to scroll. If it's nil or zero, point will be
27303 centered horizontally after the scroll. Any other value, including negative
27304 numbers, are treated as if the value were zero.
27306 Automatic hscrolling always moves point outside the scroll margin, so if
27307 point was more than scroll step columns inside the margin, the window will
27308 scroll more than the value given by the scroll step.
27310 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27311 and `scroll-right' overrides this variable's effect. */);
27312 Vhscroll_step
= make_number (0);
27314 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27315 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27316 Bind this around calls to `message' to let it take effect. */);
27317 message_truncate_lines
= 0;
27319 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27320 doc
: /* Normal hook run to update the menu bar definitions.
27321 Redisplay runs this hook before it redisplays the menu bar.
27322 This is used to update submenus such as Buffers,
27323 whose contents depend on various data. */);
27324 Vmenu_bar_update_hook
= Qnil
;
27326 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27327 doc
: /* Frame for which we are updating a menu.
27328 The enable predicate for a menu binding should check this variable. */);
27329 Vmenu_updating_frame
= Qnil
;
27331 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27332 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27333 inhibit_menubar_update
= 0;
27335 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27336 doc
: /* Prefix prepended to all continuation lines at display time.
27337 The value may be a string, an image, or a stretch-glyph; it is
27338 interpreted in the same way as the value of a `display' text property.
27340 This variable is overridden by any `wrap-prefix' text or overlay
27343 To add a prefix to non-continuation lines, use `line-prefix'. */);
27344 Vwrap_prefix
= Qnil
;
27345 staticpro (&Qwrap_prefix
);
27346 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27347 Fmake_variable_buffer_local (Qwrap_prefix
);
27349 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27350 doc
: /* Prefix prepended to all non-continuation lines at display time.
27351 The value may be a string, an image, or a stretch-glyph; it is
27352 interpreted in the same way as the value of a `display' text property.
27354 This variable is overridden by any `line-prefix' text or overlay
27357 To add a prefix to continuation lines, use `wrap-prefix'. */);
27358 Vline_prefix
= Qnil
;
27359 staticpro (&Qline_prefix
);
27360 Qline_prefix
= intern_c_string ("line-prefix");
27361 Fmake_variable_buffer_local (Qline_prefix
);
27363 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27364 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27365 inhibit_eval_during_redisplay
= 0;
27367 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27368 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27369 inhibit_free_realized_faces
= 0;
27372 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27373 doc
: /* Inhibit try_window_id display optimization. */);
27374 inhibit_try_window_id
= 0;
27376 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27377 doc
: /* Inhibit try_window_reusing display optimization. */);
27378 inhibit_try_window_reusing
= 0;
27380 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27381 doc
: /* Inhibit try_cursor_movement display optimization. */);
27382 inhibit_try_cursor_movement
= 0;
27383 #endif /* GLYPH_DEBUG */
27385 DEFVAR_INT ("overline-margin", overline_margin
,
27386 doc
: /* *Space between overline and text, in pixels.
27387 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27388 margin to the caracter height. */);
27389 overline_margin
= 2;
27391 DEFVAR_INT ("underline-minimum-offset",
27392 underline_minimum_offset
,
27393 doc
: /* Minimum distance between baseline and underline.
27394 This can improve legibility of underlined text at small font sizes,
27395 particularly when using variable `x-use-underline-position-properties'
27396 with fonts that specify an UNDERLINE_POSITION relatively close to the
27397 baseline. The default value is 1. */);
27398 underline_minimum_offset
= 1;
27400 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27401 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27402 This feature only works when on a window system that can change
27403 cursor shapes. */);
27404 display_hourglass_p
= 1;
27406 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27407 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27408 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27410 hourglass_atimer
= NULL
;
27411 hourglass_shown_p
= 0;
27413 DEFSYM (Qglyphless_char
, "glyphless-char");
27414 DEFSYM (Qhex_code
, "hex-code");
27415 DEFSYM (Qempty_box
, "empty-box");
27416 DEFSYM (Qthin_space
, "thin-space");
27417 DEFSYM (Qzero_width
, "zero-width");
27419 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27420 /* Intern this now in case it isn't already done.
27421 Setting this variable twice is harmless.
27422 But don't staticpro it here--that is done in alloc.c. */
27423 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27424 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27426 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27427 doc
: /* Char-table defining glyphless characters.
27428 Each element, if non-nil, should be one of the following:
27429 an ASCII acronym string: display this string in a box
27430 `hex-code': display the hexadecimal code of a character in a box
27431 `empty-box': display as an empty box
27432 `thin-space': display as 1-pixel width space
27433 `zero-width': don't display
27434 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27435 display method for graphical terminals and text terminals respectively.
27436 GRAPHICAL and TEXT should each have one of the values listed above.
27438 The char-table has one extra slot to control the display of a character for
27439 which no font is found. This slot only takes effect on graphical terminals.
27440 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27441 `thin-space'. The default is `empty-box'. */);
27442 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27443 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27448 /* Initialize this module when Emacs starts. */
27453 Lisp_Object root_window
;
27454 struct window
*mini_w
;
27456 current_header_line_height
= current_mode_line_height
= -1;
27458 CHARPOS (this_line_start_pos
) = 0;
27460 mini_w
= XWINDOW (minibuf_window
);
27461 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27462 echo_area_window
= minibuf_window
;
27464 if (!noninteractive
)
27466 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27469 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27470 set_window_height (root_window
,
27471 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27473 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27474 set_window_height (minibuf_window
, 1, 0);
27476 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27477 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27479 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27480 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27481 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27483 /* The default ellipsis glyphs `...'. */
27484 for (i
= 0; i
< 3; ++i
)
27485 default_invis_vector
[i
] = make_number ('.');
27489 /* Allocate the buffer for frame titles.
27490 Also used for `format-mode-line'. */
27492 mode_line_noprop_buf
= (char *) xmalloc (size
);
27493 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27494 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27495 mode_line_target
= MODE_LINE_DISPLAY
;
27498 help_echo_showing_p
= 0;
27501 /* Since w32 does not support atimers, it defines its own implementation of
27502 the following three functions in w32fns.c. */
27505 /* Platform-independent portion of hourglass implementation. */
27507 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27509 hourglass_started (void)
27511 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27514 /* Cancel a currently active hourglass timer, and start a new one. */
27516 start_hourglass (void)
27518 #if defined (HAVE_WINDOW_SYSTEM)
27520 int secs
, usecs
= 0;
27522 cancel_hourglass ();
27524 if (INTEGERP (Vhourglass_delay
)
27525 && XINT (Vhourglass_delay
) > 0)
27526 secs
= XFASTINT (Vhourglass_delay
);
27527 else if (FLOATP (Vhourglass_delay
)
27528 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27531 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27532 secs
= XFASTINT (tem
);
27533 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27536 secs
= DEFAULT_HOURGLASS_DELAY
;
27538 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27539 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27540 show_hourglass
, NULL
);
27545 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27548 cancel_hourglass (void)
27550 #if defined (HAVE_WINDOW_SYSTEM)
27551 if (hourglass_atimer
)
27553 cancel_atimer (hourglass_atimer
);
27554 hourglass_atimer
= NULL
;
27557 if (hourglass_shown_p
)
27561 #endif /* ! WINDOWSNT */