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 Calls to get_next_display_element fill the iterator structure with
134 relevant information about the next thing to display. Calls to
135 set_iterator_to_next move the iterator to the next thing.
137 Besides this, an iterator also contains information about the
138 display environment in which glyphs for display elements are to be
139 produced. It has fields for the width and height of the display,
140 the information whether long lines are truncated or continued, a
141 current X and Y position, and lots of other stuff you can better
144 Glyphs in a desired matrix are normally constructed in a loop
145 calling get_next_display_element and then PRODUCE_GLYPHS. The call
146 to PRODUCE_GLYPHS will fill the iterator structure with pixel
147 information about the element being displayed and at the same time
148 produce glyphs for it. If the display element fits on the line
149 being displayed, set_iterator_to_next is called next, otherwise the
150 glyphs produced are discarded. The function display_line is the
151 workhorse of filling glyph rows in the desired matrix with glyphs.
152 In addition to producing glyphs, it also handles line truncation
153 and continuation, word wrap, and cursor positioning (for the
154 latter, see also set_cursor_from_row).
158 That just couldn't be all, could it? What about terminal types not
159 supporting operations on sub-windows of the screen? To update the
160 display on such a terminal, window-based glyph matrices are not
161 well suited. To be able to reuse part of the display (scrolling
162 lines up and down), we must instead have a view of the whole
163 screen. This is what `frame matrices' are for. They are a trick.
165 Frames on terminals like above have a glyph pool. Windows on such
166 a frame sub-allocate their glyph memory from their frame's glyph
167 pool. The frame itself is given its own glyph matrices. By
168 coincidence---or maybe something else---rows in window glyph
169 matrices are slices of corresponding rows in frame matrices. Thus
170 writing to window matrices implicitly updates a frame matrix which
171 provides us with the view of the whole screen that we originally
172 wanted to have without having to move many bytes around. To be
173 honest, there is a little bit more done, but not much more. If you
174 plan to extend that code, take a look at dispnew.c. The function
175 build_frame_matrix is a good starting point.
177 Bidirectional display.
179 Bidirectional display adds quite some hair to this already complex
180 design. The good news are that a large portion of that hairy stuff
181 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
182 reordering engine which is called by set_iterator_to_next and
183 returns the next character to display in the visual order. See
184 commentary on bidi.c for more details. As far as redisplay is
185 concerned, the effect of calling bidi_move_to_visually_next, the
186 main interface of the reordering engine, is that the iterator gets
187 magically placed on the buffer or string position that is to be
188 displayed next. In other words, a linear iteration through the
189 buffer/string is replaced with a non-linear one. All the rest of
190 the redisplay is oblivious to the bidi reordering.
192 Well, almost oblivious---there are still complications, most of
193 them due to the fact that buffer and string positions no longer
194 change monotonously with glyph indices in a glyph row. Moreover,
195 for continued lines, the buffer positions may not even be
196 monotonously changing with vertical positions. Also, accounting
197 for face changes, overlays, etc. becomes more complex because
198 non-linear iteration could potentially skip many positions with
199 changes, and then cross them again on the way back...
201 One other prominent effect of bidirectional display is that some
202 paragraphs of text need to be displayed starting at the right
203 margin of the window---the so-called right-to-left, or R2L
204 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
205 which have their reversed_p flag set. The bidi reordering engine
206 produces characters in such rows starting from the character which
207 should be the rightmost on display. PRODUCE_GLYPHS then reverses
208 the order, when it fills up the glyph row whose reversed_p flag is
209 set, by prepending each new glyph to what is already there, instead
210 of appending it. When the glyph row is complete, the function
211 extend_face_to_end_of_line fills the empty space to the left of the
212 leftmost character with special glyphs, which will display as,
213 well, empty. On text terminals, these special glyphs are simply
214 blank characters. On graphics terminals, there's a single stretch
215 glyph of a suitably computed width. Both the blanks and the
216 stretch glyph are given the face of the background of the line.
217 This way, the terminal-specific back-end can still draw the glyphs
218 left to right, even for R2L lines.
220 Bidirectional display and character compositions
222 Some scripts cannot be displayed by drawing each character
223 individually, because adjacent characters change each other's shape
224 on display. For example, Arabic and Indic scripts belong to this
227 Emacs display supports this by providing "character compositions",
228 most of which is implemented in composite.c. During the buffer
229 scan that delivers characters to PRODUCE_GLYPHS, if the next
230 character to be delivered is a composed character, the iteration
231 calls composition_reseat_it and next_element_from_composition. If
232 they succeed to compose the character with one or more of the
233 following characters, the whole sequence of characters that where
234 composed is recorded in the `struct composition_it' object that is
235 part of the buffer iterator. The composed sequence could produce
236 one or more font glyphs (called "grapheme clusters") on the screen.
237 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
238 in the direction corresponding to the current bidi scan direction
239 (recorded in the scan_dir member of the `struct bidi_it' object
240 that is part of the buffer iterator). In particular, if the bidi
241 iterator currently scans the buffer backwards, the grapheme
242 clusters are delivered back to front. This reorders the grapheme
243 clusters as appropriate for the current bidi context. Note that
244 this means that the grapheme clusters are always stored in the
245 LGSTRING object (see composite.c) in the logical order.
247 Moving an iterator in bidirectional text
248 without producing glyphs
250 Note one important detail mentioned above: that the bidi reordering
251 engine, driven by the iterator, produces characters in R2L rows
252 starting at the character that will be the rightmost on display.
253 As far as the iterator is concerned, the geometry of such rows is
254 still left to right, i.e. the iterator "thinks" the first character
255 is at the leftmost pixel position. The iterator does not know that
256 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
257 delivers. This is important when functions from the the move_it_*
258 family are used to get to certain screen position or to match
259 screen coordinates with buffer coordinates: these functions use the
260 iterator geometry, which is left to right even in R2L paragraphs.
261 This works well with most callers of move_it_*, because they need
262 to get to a specific column, and columns are still numbered in the
263 reading order, i.e. the rightmost character in a R2L paragraph is
264 still column zero. But some callers do not get well with this; a
265 notable example is mouse clicks that need to find the character
266 that corresponds to certain pixel coordinates. See
267 buffer_posn_from_coords in dispnew.c for how this is handled. */
275 #include "keyboard.h"
278 #include "termchar.h"
279 #include "dispextern.h"
281 #include "character.h"
284 #include "commands.h"
288 #include "termhooks.h"
289 #include "termopts.h"
290 #include "intervals.h"
293 #include "region-cache.h"
296 #include "blockinput.h"
298 #ifdef HAVE_X_WINDOWS
313 #ifndef FRAME_X_OUTPUT
314 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
317 #define INFINITY 10000000
319 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
320 Lisp_Object Qwindow_scroll_functions
;
321 static Lisp_Object Qwindow_text_change_functions
;
322 static Lisp_Object Qredisplay_end_trigger_functions
;
323 Lisp_Object Qinhibit_point_motion_hooks
;
324 static Lisp_Object QCeval
, QCpropertize
;
325 Lisp_Object QCfile
, QCdata
;
326 static Lisp_Object Qfontified
;
327 static Lisp_Object Qgrow_only
;
328 static Lisp_Object Qinhibit_eval_during_redisplay
;
329 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
330 static Lisp_Object Qright_to_left
, Qleft_to_right
;
333 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
336 static Lisp_Object Qarrow
, Qhand
;
339 /* Holds the list (error). */
340 static Lisp_Object list_of_error
;
342 static Lisp_Object Qfontification_functions
;
344 static Lisp_Object Qwrap_prefix
;
345 static Lisp_Object Qline_prefix
;
347 /* Non-nil means don't actually do any redisplay. */
349 Lisp_Object Qinhibit_redisplay
;
351 /* Names of text properties relevant for redisplay. */
353 Lisp_Object Qdisplay
;
355 Lisp_Object Qspace
, QCalign_to
;
356 static Lisp_Object QCrelative_width
, QCrelative_height
;
357 Lisp_Object Qleft_margin
, Qright_margin
;
358 static Lisp_Object Qspace_width
, Qraise
;
359 static Lisp_Object Qslice
;
361 static Lisp_Object Qmargin
, Qpointer
;
362 static Lisp_Object Qline_height
;
364 #ifdef HAVE_WINDOW_SYSTEM
366 /* Test if overflow newline into fringe. Called with iterator IT
367 at or past right window margin, and with IT->current_x set. */
369 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
370 (!NILP (Voverflow_newline_into_fringe) \
371 && FRAME_WINDOW_P ((IT)->f) \
372 && ((IT)->bidi_it.paragraph_dir == R2L \
373 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
374 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
375 && (IT)->current_x == (IT)->last_visible_x \
376 && (IT)->line_wrap != WORD_WRAP)
378 #else /* !HAVE_WINDOW_SYSTEM */
379 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
380 #endif /* HAVE_WINDOW_SYSTEM */
382 /* Test if the display element loaded in IT is a space or tab
383 character. This is used to determine word wrapping. */
385 #define IT_DISPLAYING_WHITESPACE(it) \
386 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
388 /* Name of the face used to highlight trailing whitespace. */
390 static Lisp_Object Qtrailing_whitespace
;
392 /* Name and number of the face used to highlight escape glyphs. */
394 static Lisp_Object Qescape_glyph
;
396 /* Name and number of the face used to highlight non-breaking spaces. */
398 static Lisp_Object Qnobreak_space
;
400 /* The symbol `image' which is the car of the lists used to represent
401 images in Lisp. Also a tool bar style. */
405 /* The image map types. */
407 static Lisp_Object QCpointer
;
408 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
410 /* Tool bar styles */
411 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
413 /* Non-zero means print newline to stdout before next mini-buffer
416 int noninteractive_need_newline
;
418 /* Non-zero means print newline to message log before next message. */
420 static int message_log_need_newline
;
422 /* Three markers that message_dolog uses.
423 It could allocate them itself, but that causes trouble
424 in handling memory-full errors. */
425 static Lisp_Object message_dolog_marker1
;
426 static Lisp_Object message_dolog_marker2
;
427 static Lisp_Object message_dolog_marker3
;
429 /* The buffer position of the first character appearing entirely or
430 partially on the line of the selected window which contains the
431 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
432 redisplay optimization in redisplay_internal. */
434 static struct text_pos this_line_start_pos
;
436 /* Number of characters past the end of the line above, including the
437 terminating newline. */
439 static struct text_pos this_line_end_pos
;
441 /* The vertical positions and the height of this line. */
443 static int this_line_vpos
;
444 static int this_line_y
;
445 static int this_line_pixel_height
;
447 /* X position at which this display line starts. Usually zero;
448 negative if first character is partially visible. */
450 static int this_line_start_x
;
452 /* The smallest character position seen by move_it_* functions as they
453 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
454 hscrolled lines, see display_line. */
456 static struct text_pos this_line_min_pos
;
458 /* Buffer that this_line_.* variables are referring to. */
460 static struct buffer
*this_line_buffer
;
463 /* Values of those variables at last redisplay are stored as
464 properties on `overlay-arrow-position' symbol. However, if
465 Voverlay_arrow_position is a marker, last-arrow-position is its
466 numerical position. */
468 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
470 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
471 properties on a symbol in overlay-arrow-variable-list. */
473 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
475 Lisp_Object Qmenu_bar_update_hook
;
477 /* Nonzero if an overlay arrow has been displayed in this window. */
479 static int overlay_arrow_seen
;
481 /* Number of windows showing the buffer of the selected window (or
482 another buffer with the same base buffer). keyboard.c refers to
487 /* Vector containing glyphs for an ellipsis `...'. */
489 static Lisp_Object default_invis_vector
[3];
491 /* This is the window where the echo area message was displayed. It
492 is always a mini-buffer window, but it may not be the same window
493 currently active as a mini-buffer. */
495 Lisp_Object echo_area_window
;
497 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
498 pushes the current message and the value of
499 message_enable_multibyte on the stack, the function restore_message
500 pops the stack and displays MESSAGE again. */
502 static Lisp_Object Vmessage_stack
;
504 /* Nonzero means multibyte characters were enabled when the echo area
505 message was specified. */
507 static int message_enable_multibyte
;
509 /* Nonzero if we should redraw the mode lines on the next redisplay. */
511 int update_mode_lines
;
513 /* Nonzero if window sizes or contents have changed since last
514 redisplay that finished. */
516 int windows_or_buffers_changed
;
518 /* Nonzero means a frame's cursor type has been changed. */
520 int cursor_type_changed
;
522 /* Nonzero after display_mode_line if %l was used and it displayed a
525 static int line_number_displayed
;
527 /* The name of the *Messages* buffer, a string. */
529 static Lisp_Object Vmessages_buffer_name
;
531 /* Current, index 0, and last displayed echo area message. Either
532 buffers from echo_buffers, or nil to indicate no message. */
534 Lisp_Object echo_area_buffer
[2];
536 /* The buffers referenced from echo_area_buffer. */
538 static Lisp_Object echo_buffer
[2];
540 /* A vector saved used in with_area_buffer to reduce consing. */
542 static Lisp_Object Vwith_echo_area_save_vector
;
544 /* Non-zero means display_echo_area should display the last echo area
545 message again. Set by redisplay_preserve_echo_area. */
547 static int display_last_displayed_message_p
;
549 /* Nonzero if echo area is being used by print; zero if being used by
552 static int message_buf_print
;
554 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
556 static Lisp_Object Qinhibit_menubar_update
;
557 static Lisp_Object Qmessage_truncate_lines
;
559 /* Set to 1 in clear_message to make redisplay_internal aware
560 of an emptied echo area. */
562 static int message_cleared_p
;
564 /* A scratch glyph row with contents used for generating truncation
565 glyphs. Also used in direct_output_for_insert. */
567 #define MAX_SCRATCH_GLYPHS 100
568 static struct glyph_row scratch_glyph_row
;
569 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
571 /* Ascent and height of the last line processed by move_it_to. */
573 static int last_max_ascent
, last_height
;
575 /* Non-zero if there's a help-echo in the echo area. */
577 int help_echo_showing_p
;
579 /* If >= 0, computed, exact values of mode-line and header-line height
580 to use in the macros CURRENT_MODE_LINE_HEIGHT and
581 CURRENT_HEADER_LINE_HEIGHT. */
583 int current_mode_line_height
, current_header_line_height
;
585 /* The maximum distance to look ahead for text properties. Values
586 that are too small let us call compute_char_face and similar
587 functions too often which is expensive. Values that are too large
588 let us call compute_char_face and alike too often because we
589 might not be interested in text properties that far away. */
591 #define TEXT_PROP_DISTANCE_LIMIT 100
595 /* Non-zero means print traces of redisplay if compiled with
598 int trace_redisplay_p
;
600 #endif /* GLYPH_DEBUG */
602 #ifdef DEBUG_TRACE_MOVE
603 /* Non-zero means trace with TRACE_MOVE to stderr. */
606 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
608 #define TRACE_MOVE(x) (void) 0
611 static Lisp_Object Qauto_hscroll_mode
;
613 /* Buffer being redisplayed -- for redisplay_window_error. */
615 static struct buffer
*displayed_buffer
;
617 /* Value returned from text property handlers (see below). */
622 HANDLED_RECOMPUTE_PROPS
,
623 HANDLED_OVERLAY_STRING_CONSUMED
,
627 /* A description of text properties that redisplay is interested
632 /* The name of the property. */
635 /* A unique index for the property. */
638 /* A handler function called to set up iterator IT from the property
639 at IT's current position. Value is used to steer handle_stop. */
640 enum prop_handled (*handler
) (struct it
*it
);
643 static enum prop_handled
handle_face_prop (struct it
*);
644 static enum prop_handled
handle_invisible_prop (struct it
*);
645 static enum prop_handled
handle_display_prop (struct it
*);
646 static enum prop_handled
handle_composition_prop (struct it
*);
647 static enum prop_handled
handle_overlay_change (struct it
*);
648 static enum prop_handled
handle_fontified_prop (struct it
*);
650 /* Properties handled by iterators. */
652 static struct props it_props
[] =
654 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
655 /* Handle `face' before `display' because some sub-properties of
656 `display' need to know the face. */
657 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
658 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
659 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
660 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
664 /* Value is the position described by X. If X is a marker, value is
665 the marker_position of X. Otherwise, value is X. */
667 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
669 /* Enumeration returned by some move_it_.* functions internally. */
673 /* Not used. Undefined value. */
676 /* Move ended at the requested buffer position or ZV. */
677 MOVE_POS_MATCH_OR_ZV
,
679 /* Move ended at the requested X pixel position. */
682 /* Move within a line ended at the end of a line that must be
686 /* Move within a line ended at the end of a line that would
687 be displayed truncated. */
690 /* Move within a line ended at a line end. */
694 /* This counter is used to clear the face cache every once in a while
695 in redisplay_internal. It is incremented for each redisplay.
696 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
699 #define CLEAR_FACE_CACHE_COUNT 500
700 static int clear_face_cache_count
;
702 /* Similarly for the image cache. */
704 #ifdef HAVE_WINDOW_SYSTEM
705 #define CLEAR_IMAGE_CACHE_COUNT 101
706 static int clear_image_cache_count
;
708 /* Null glyph slice */
709 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
712 /* Non-zero while redisplay_internal is in progress. */
716 static Lisp_Object Qinhibit_free_realized_faces
;
718 /* If a string, XTread_socket generates an event to display that string.
719 (The display is done in read_char.) */
721 Lisp_Object help_echo_string
;
722 Lisp_Object help_echo_window
;
723 Lisp_Object help_echo_object
;
724 EMACS_INT help_echo_pos
;
726 /* Temporary variable for XTread_socket. */
728 Lisp_Object previous_help_echo_string
;
730 /* Platform-independent portion of hourglass implementation. */
732 /* Non-zero means an hourglass cursor is currently shown. */
733 int hourglass_shown_p
;
735 /* If non-null, an asynchronous timer that, when it expires, displays
736 an hourglass cursor on all frames. */
737 struct atimer
*hourglass_atimer
;
739 /* Name of the face used to display glyphless characters. */
740 Lisp_Object Qglyphless_char
;
742 /* Symbol for the purpose of Vglyphless_char_display. */
743 static Lisp_Object Qglyphless_char_display
;
745 /* Method symbols for Vglyphless_char_display. */
746 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
748 /* Default pixel width of `thin-space' display method. */
749 #define THIN_SPACE_WIDTH 1
751 /* Default number of seconds to wait before displaying an hourglass
753 #define DEFAULT_HOURGLASS_DELAY 1
756 /* Function prototypes. */
758 static void setup_for_ellipsis (struct it
*, int);
759 static void set_iterator_to_next (struct it
*, int);
760 static void mark_window_display_accurate_1 (struct window
*, int);
761 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
762 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
763 static int cursor_row_p (struct glyph_row
*);
764 static int redisplay_mode_lines (Lisp_Object
, int);
765 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
767 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
769 static void handle_line_prefix (struct it
*);
771 static void pint2str (char *, int, EMACS_INT
);
772 static void pint2hrstr (char *, int, EMACS_INT
);
773 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
775 static void reconsider_clip_changes (struct window
*, struct buffer
*);
776 static int text_outside_line_unchanged_p (struct window
*,
777 EMACS_INT
, EMACS_INT
);
778 static void store_mode_line_noprop_char (char);
779 static int store_mode_line_noprop (const char *, int, int);
780 static void handle_stop (struct it
*);
781 static void handle_stop_backwards (struct it
*, EMACS_INT
);
782 static int single_display_spec_intangible_p (Lisp_Object
);
783 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
784 static void ensure_echo_area_buffers (void);
785 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
786 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
787 static int with_echo_area_buffer (struct window
*, int,
788 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
789 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
790 static void clear_garbaged_frames (void);
791 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
792 static void pop_message (void);
793 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
794 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
795 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
796 static int display_echo_area (struct window
*);
797 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
798 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
799 static Lisp_Object
unwind_redisplay (Lisp_Object
);
800 static int string_char_and_length (const unsigned char *, int *);
801 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
803 static int compute_window_start_on_continuation_line (struct window
*);
804 static Lisp_Object
safe_eval_handler (Lisp_Object
);
805 static void insert_left_trunc_glyphs (struct it
*);
806 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
808 static void extend_face_to_end_of_line (struct it
*);
809 static int append_space_for_newline (struct it
*, int);
810 static int cursor_row_fully_visible_p (struct window
*, int, int);
811 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
812 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
813 static int trailing_whitespace_p (EMACS_INT
);
814 static unsigned long int message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
815 static void push_it (struct it
*);
816 static void pop_it (struct it
*);
817 static void sync_frame_with_window_matrix_rows (struct window
*);
818 static void select_frame_for_redisplay (Lisp_Object
);
819 static void redisplay_internal (void);
820 static int echo_area_display (int);
821 static void redisplay_windows (Lisp_Object
);
822 static void redisplay_window (Lisp_Object
, int);
823 static Lisp_Object
redisplay_window_error (Lisp_Object
);
824 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
825 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
826 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
827 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
829 static int update_menu_bar (struct frame
*, int, int);
830 static int try_window_reusing_current_matrix (struct window
*);
831 static int try_window_id (struct window
*);
832 static int display_line (struct it
*);
833 static int display_mode_lines (struct window
*);
834 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
835 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
836 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
837 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
838 static void display_menu_bar (struct window
*);
839 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
841 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
842 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
843 static void compute_line_metrics (struct it
*);
844 static void run_redisplay_end_trigger_hook (struct it
*);
845 static int get_overlay_strings (struct it
*, EMACS_INT
);
846 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
847 static void next_overlay_string (struct it
*);
848 static void reseat (struct it
*, struct text_pos
, int);
849 static void reseat_1 (struct it
*, struct text_pos
, int);
850 static void back_to_previous_visible_line_start (struct it
*);
851 void reseat_at_previous_visible_line_start (struct it
*);
852 static void reseat_at_next_visible_line_start (struct it
*, int);
853 static int next_element_from_ellipsis (struct it
*);
854 static int next_element_from_display_vector (struct it
*);
855 static int next_element_from_string (struct it
*);
856 static int next_element_from_c_string (struct it
*);
857 static int next_element_from_buffer (struct it
*);
858 static int next_element_from_composition (struct it
*);
859 static int next_element_from_image (struct it
*);
860 static int next_element_from_stretch (struct it
*);
861 static void load_overlay_strings (struct it
*, EMACS_INT
);
862 static int init_from_display_pos (struct it
*, struct window
*,
863 struct display_pos
*);
864 static void reseat_to_string (struct it
*, const char *,
865 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
866 static int get_next_display_element (struct it
*);
867 static enum move_it_result
868 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
869 enum move_operation_enum
);
870 void move_it_vertically_backward (struct it
*, int);
871 static void init_to_row_start (struct it
*, struct window
*,
873 static int init_to_row_end (struct it
*, struct window
*,
875 static void back_to_previous_line_start (struct it
*);
876 static int forward_to_next_line_start (struct it
*, int *);
877 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
878 Lisp_Object
, EMACS_INT
);
879 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
880 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
881 static EMACS_INT
number_of_chars (const char *, int);
882 static void compute_stop_pos (struct it
*);
883 static void compute_string_pos (struct text_pos
*, struct text_pos
,
885 static int face_before_or_after_it_pos (struct it
*, int);
886 static EMACS_INT
next_overlay_change (EMACS_INT
);
887 static int handle_single_display_spec (struct it
*, Lisp_Object
,
888 Lisp_Object
, Lisp_Object
,
889 struct text_pos
*, int);
890 static int underlying_face_id (struct it
*);
891 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
894 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
895 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
897 #ifdef HAVE_WINDOW_SYSTEM
899 static void x_consider_frame_title (Lisp_Object
);
900 static int tool_bar_lines_needed (struct frame
*, int *);
901 static void update_tool_bar (struct frame
*, int);
902 static void build_desired_tool_bar_string (struct frame
*f
);
903 static int redisplay_tool_bar (struct frame
*);
904 static void display_tool_bar_line (struct it
*, int);
905 static void notice_overwritten_cursor (struct window
*,
908 static void append_stretch_glyph (struct it
*, Lisp_Object
,
912 #endif /* HAVE_WINDOW_SYSTEM */
914 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
915 static int coords_in_mouse_face_p (struct window
*, int, int);
919 /***********************************************************************
920 Window display dimensions
921 ***********************************************************************/
923 /* Return the bottom boundary y-position for text lines in window W.
924 This is the first y position at which a line cannot start.
925 It is relative to the top of the window.
927 This is the height of W minus the height of a mode line, if any. */
930 window_text_bottom_y (struct window
*w
)
932 int height
= WINDOW_TOTAL_HEIGHT (w
);
934 if (WINDOW_WANTS_MODELINE_P (w
))
935 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
939 /* Return the pixel width of display area AREA of window W. AREA < 0
940 means return the total width of W, not including fringes to
941 the left and right of the window. */
944 window_box_width (struct window
*w
, int area
)
946 int cols
= XFASTINT (w
->total_cols
);
949 if (!w
->pseudo_window_p
)
951 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
953 if (area
== TEXT_AREA
)
955 if (INTEGERP (w
->left_margin_cols
))
956 cols
-= XFASTINT (w
->left_margin_cols
);
957 if (INTEGERP (w
->right_margin_cols
))
958 cols
-= XFASTINT (w
->right_margin_cols
);
959 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
961 else if (area
== LEFT_MARGIN_AREA
)
963 cols
= (INTEGERP (w
->left_margin_cols
)
964 ? XFASTINT (w
->left_margin_cols
) : 0);
967 else if (area
== RIGHT_MARGIN_AREA
)
969 cols
= (INTEGERP (w
->right_margin_cols
)
970 ? XFASTINT (w
->right_margin_cols
) : 0);
975 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
979 /* Return the pixel height of the display area of window W, not
980 including mode lines of W, if any. */
983 window_box_height (struct window
*w
)
985 struct frame
*f
= XFRAME (w
->frame
);
986 int height
= WINDOW_TOTAL_HEIGHT (w
);
988 xassert (height
>= 0);
990 /* Note: the code below that determines the mode-line/header-line
991 height is essentially the same as that contained in the macro
992 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
993 the appropriate glyph row has its `mode_line_p' flag set,
994 and if it doesn't, uses estimate_mode_line_height instead. */
996 if (WINDOW_WANTS_MODELINE_P (w
))
998 struct glyph_row
*ml_row
999 = (w
->current_matrix
&& w
->current_matrix
->rows
1000 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1002 if (ml_row
&& ml_row
->mode_line_p
)
1003 height
-= ml_row
->height
;
1005 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1008 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1010 struct glyph_row
*hl_row
1011 = (w
->current_matrix
&& w
->current_matrix
->rows
1012 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1014 if (hl_row
&& hl_row
->mode_line_p
)
1015 height
-= hl_row
->height
;
1017 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1020 /* With a very small font and a mode-line that's taller than
1021 default, we might end up with a negative height. */
1022 return max (0, height
);
1025 /* Return the window-relative coordinate of the left edge of display
1026 area AREA of window W. AREA < 0 means return the left edge of the
1027 whole window, to the right of the left fringe of W. */
1030 window_box_left_offset (struct window
*w
, int area
)
1034 if (w
->pseudo_window_p
)
1037 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1039 if (area
== TEXT_AREA
)
1040 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1041 + window_box_width (w
, LEFT_MARGIN_AREA
));
1042 else if (area
== RIGHT_MARGIN_AREA
)
1043 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1044 + window_box_width (w
, LEFT_MARGIN_AREA
)
1045 + window_box_width (w
, TEXT_AREA
)
1046 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1048 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1049 else if (area
== LEFT_MARGIN_AREA
1050 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1051 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1057 /* Return the window-relative coordinate of the right edge of display
1058 area AREA of window W. AREA < 0 means return the right edge of the
1059 whole window, to the left of the right fringe of W. */
1062 window_box_right_offset (struct window
*w
, int area
)
1064 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1067 /* Return the frame-relative coordinate of the left edge of display
1068 area AREA of window W. AREA < 0 means return the left edge of the
1069 whole window, to the right of the left fringe of W. */
1072 window_box_left (struct window
*w
, int area
)
1074 struct frame
*f
= XFRAME (w
->frame
);
1077 if (w
->pseudo_window_p
)
1078 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1080 x
= (WINDOW_LEFT_EDGE_X (w
)
1081 + window_box_left_offset (w
, area
));
1087 /* Return the frame-relative coordinate of the right edge of display
1088 area AREA of window W. AREA < 0 means return the right edge of the
1089 whole window, to the left of the right fringe of W. */
1092 window_box_right (struct window
*w
, int area
)
1094 return window_box_left (w
, area
) + window_box_width (w
, area
);
1097 /* Get the bounding box of the display area AREA of window W, without
1098 mode lines, in frame-relative coordinates. AREA < 0 means the
1099 whole window, not including the left and right fringes of
1100 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1101 coordinates of the upper-left corner of the box. Return in
1102 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1105 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1106 int *box_width
, int *box_height
)
1109 *box_width
= window_box_width (w
, area
);
1111 *box_height
= window_box_height (w
);
1113 *box_x
= window_box_left (w
, area
);
1116 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1117 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1118 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1123 /* Get the bounding box of the display area AREA of window W, without
1124 mode lines. AREA < 0 means the whole window, not including the
1125 left and right fringe of the window. Return in *TOP_LEFT_X
1126 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1127 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1128 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1132 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1133 int *bottom_right_x
, int *bottom_right_y
)
1135 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1137 *bottom_right_x
+= *top_left_x
;
1138 *bottom_right_y
+= *top_left_y
;
1143 /***********************************************************************
1145 ***********************************************************************/
1147 /* Return the bottom y-position of the line the iterator IT is in.
1148 This can modify IT's settings. */
1151 line_bottom_y (struct it
*it
)
1153 int line_height
= it
->max_ascent
+ it
->max_descent
;
1154 int line_top_y
= it
->current_y
;
1156 if (line_height
== 0)
1159 line_height
= last_height
;
1160 else if (IT_CHARPOS (*it
) < ZV
)
1162 move_it_by_lines (it
, 1);
1163 line_height
= (it
->max_ascent
|| it
->max_descent
1164 ? it
->max_ascent
+ it
->max_descent
1169 struct glyph_row
*row
= it
->glyph_row
;
1171 /* Use the default character height. */
1172 it
->glyph_row
= NULL
;
1173 it
->what
= IT_CHARACTER
;
1176 PRODUCE_GLYPHS (it
);
1177 line_height
= it
->ascent
+ it
->descent
;
1178 it
->glyph_row
= row
;
1182 return line_top_y
+ line_height
;
1186 /* Return 1 if position CHARPOS is visible in window W.
1187 CHARPOS < 0 means return info about WINDOW_END position.
1188 If visible, set *X and *Y to pixel coordinates of top left corner.
1189 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1190 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1193 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1194 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1197 struct text_pos top
;
1199 struct buffer
*old_buffer
= NULL
;
1201 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1204 if (XBUFFER (w
->buffer
) != current_buffer
)
1206 old_buffer
= current_buffer
;
1207 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1210 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1212 /* Compute exact mode line heights. */
1213 if (WINDOW_WANTS_MODELINE_P (w
))
1214 current_mode_line_height
1215 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1216 BVAR (current_buffer
, mode_line_format
));
1218 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1219 current_header_line_height
1220 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1221 BVAR (current_buffer
, header_line_format
));
1223 start_display (&it
, w
, top
);
1224 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1225 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1227 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1229 /* We have reached CHARPOS, or passed it. How the call to
1230 move_it_to can overshoot: (i) If CHARPOS is on invisible
1231 text, move_it_to stops at the end of the invisible text,
1232 after CHARPOS. (ii) If CHARPOS is in a display vector,
1233 move_it_to stops on its last glyph. */
1234 int top_x
= it
.current_x
;
1235 int top_y
= it
.current_y
;
1236 enum it_method it_method
= it
.method
;
1237 /* Calling line_bottom_y may change it.method, it.position, etc. */
1238 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1239 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1241 if (top_y
< window_top_y
)
1242 visible_p
= bottom_y
> window_top_y
;
1243 else if (top_y
< it
.last_visible_y
)
1247 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1249 /* We stopped on the last glyph of a display vector.
1250 Try and recompute. Hack alert! */
1251 if (charpos
< 2 || top
.charpos
>= charpos
)
1252 top_x
= it
.glyph_row
->x
;
1256 start_display (&it2
, w
, top
);
1257 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1258 get_next_display_element (&it2
);
1259 PRODUCE_GLYPHS (&it2
);
1260 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1261 || it2
.current_x
> it2
.last_visible_x
)
1262 top_x
= it
.glyph_row
->x
;
1265 top_x
= it2
.current_x
;
1266 top_y
= it2
.current_y
;
1272 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1273 *rtop
= max (0, window_top_y
- top_y
);
1274 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1275 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1276 - max (top_y
, window_top_y
)));
1285 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1286 move_it_by_lines (&it
, 1);
1287 if (charpos
< IT_CHARPOS (it
)
1288 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1291 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1293 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1294 *rtop
= max (0, -it2
.current_y
);
1295 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1296 - it
.last_visible_y
));
1297 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1299 - max (it2
.current_y
,
1300 WINDOW_HEADER_LINE_HEIGHT (w
))));
1306 set_buffer_internal_1 (old_buffer
);
1308 current_header_line_height
= current_mode_line_height
= -1;
1310 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1311 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1314 /* Debugging code. */
1316 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1317 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1319 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1326 /* Return the next character from STR. Return in *LEN the length of
1327 the character. This is like STRING_CHAR_AND_LENGTH but never
1328 returns an invalid character. If we find one, we return a `?', but
1329 with the length of the invalid character. */
1332 string_char_and_length (const unsigned char *str
, int *len
)
1336 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1337 if (!CHAR_VALID_P (c
, 1))
1338 /* We may not change the length here because other places in Emacs
1339 don't use this function, i.e. they silently accept invalid
1348 /* Given a position POS containing a valid character and byte position
1349 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1351 static struct text_pos
1352 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1354 xassert (STRINGP (string
) && nchars
>= 0);
1356 if (STRING_MULTIBYTE (string
))
1358 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1363 string_char_and_length (p
, &len
);
1366 BYTEPOS (pos
) += len
;
1370 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1376 /* Value is the text position, i.e. character and byte position,
1377 for character position CHARPOS in STRING. */
1379 static INLINE
struct text_pos
1380 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1382 struct text_pos pos
;
1383 xassert (STRINGP (string
));
1384 xassert (charpos
>= 0);
1385 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1390 /* Value is a text position, i.e. character and byte position, for
1391 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1392 means recognize multibyte characters. */
1394 static struct text_pos
1395 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1397 struct text_pos pos
;
1399 xassert (s
!= NULL
);
1400 xassert (charpos
>= 0);
1406 SET_TEXT_POS (pos
, 0, 0);
1409 string_char_and_length ((const unsigned char *) s
, &len
);
1412 BYTEPOS (pos
) += len
;
1416 SET_TEXT_POS (pos
, charpos
, charpos
);
1422 /* Value is the number of characters in C string S. MULTIBYTE_P
1423 non-zero means recognize multibyte characters. */
1426 number_of_chars (const char *s
, int multibyte_p
)
1432 EMACS_INT rest
= strlen (s
);
1434 const unsigned char *p
= (const unsigned char *) s
;
1436 for (nchars
= 0; rest
> 0; ++nchars
)
1438 string_char_and_length (p
, &len
);
1439 rest
-= len
, p
+= len
;
1443 nchars
= strlen (s
);
1449 /* Compute byte position NEWPOS->bytepos corresponding to
1450 NEWPOS->charpos. POS is a known position in string STRING.
1451 NEWPOS->charpos must be >= POS.charpos. */
1454 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1456 xassert (STRINGP (string
));
1457 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1459 if (STRING_MULTIBYTE (string
))
1460 *newpos
= string_pos_nchars_ahead (pos
, string
,
1461 CHARPOS (*newpos
) - CHARPOS (pos
));
1463 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1467 Return an estimation of the pixel height of mode or header lines on
1468 frame F. FACE_ID specifies what line's height to estimate. */
1471 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1473 #ifdef HAVE_WINDOW_SYSTEM
1474 if (FRAME_WINDOW_P (f
))
1476 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1478 /* This function is called so early when Emacs starts that the face
1479 cache and mode line face are not yet initialized. */
1480 if (FRAME_FACE_CACHE (f
))
1482 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1486 height
= FONT_HEIGHT (face
->font
);
1487 if (face
->box_line_width
> 0)
1488 height
+= 2 * face
->box_line_width
;
1499 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1500 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1501 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1502 not force the value into range. */
1505 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1506 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1509 #ifdef HAVE_WINDOW_SYSTEM
1510 if (FRAME_WINDOW_P (f
))
1512 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1513 even for negative values. */
1515 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1517 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1519 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1520 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1523 STORE_NATIVE_RECT (*bounds
,
1524 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1525 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1526 FRAME_COLUMN_WIDTH (f
) - 1,
1527 FRAME_LINE_HEIGHT (f
) - 1);
1533 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1534 pix_x
= FRAME_TOTAL_COLS (f
);
1538 else if (pix_y
> FRAME_LINES (f
))
1539 pix_y
= FRAME_LINES (f
);
1549 /* Find the glyph under window-relative coordinates X/Y in window W.
1550 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1551 strings. Return in *HPOS and *VPOS the row and column number of
1552 the glyph found. Return in *AREA the glyph area containing X.
1553 Value is a pointer to the glyph found or null if X/Y is not on
1554 text, or we can't tell because W's current matrix is not up to
1559 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1560 int *dx
, int *dy
, int *area
)
1562 struct glyph
*glyph
, *end
;
1563 struct glyph_row
*row
= NULL
;
1566 /* Find row containing Y. Give up if some row is not enabled. */
1567 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1569 row
= MATRIX_ROW (w
->current_matrix
, i
);
1570 if (!row
->enabled_p
)
1572 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1579 /* Give up if Y is not in the window. */
1580 if (i
== w
->current_matrix
->nrows
)
1583 /* Get the glyph area containing X. */
1584 if (w
->pseudo_window_p
)
1591 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1593 *area
= LEFT_MARGIN_AREA
;
1594 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1596 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1599 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1603 *area
= RIGHT_MARGIN_AREA
;
1604 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1608 /* Find glyph containing X. */
1609 glyph
= row
->glyphs
[*area
];
1610 end
= glyph
+ row
->used
[*area
];
1612 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1614 x
-= glyph
->pixel_width
;
1624 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1627 *hpos
= glyph
- row
->glyphs
[*area
];
1631 /* Convert frame-relative x/y to coordinates relative to window W.
1632 Takes pseudo-windows into account. */
1635 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1637 if (w
->pseudo_window_p
)
1639 /* A pseudo-window is always full-width, and starts at the
1640 left edge of the frame, plus a frame border. */
1641 struct frame
*f
= XFRAME (w
->frame
);
1642 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1643 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1647 *x
-= WINDOW_LEFT_EDGE_X (w
);
1648 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1652 #ifdef HAVE_WINDOW_SYSTEM
1655 Return in RECTS[] at most N clipping rectangles for glyph string S.
1656 Return the number of stored rectangles. */
1659 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1666 if (s
->row
->full_width_p
)
1668 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1669 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1670 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1672 /* Unless displaying a mode or menu bar line, which are always
1673 fully visible, clip to the visible part of the row. */
1674 if (s
->w
->pseudo_window_p
)
1675 r
.height
= s
->row
->visible_height
;
1677 r
.height
= s
->height
;
1681 /* This is a text line that may be partially visible. */
1682 r
.x
= window_box_left (s
->w
, s
->area
);
1683 r
.width
= window_box_width (s
->w
, s
->area
);
1684 r
.height
= s
->row
->visible_height
;
1688 if (r
.x
< s
->clip_head
->x
)
1690 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1691 r
.width
-= s
->clip_head
->x
- r
.x
;
1694 r
.x
= s
->clip_head
->x
;
1697 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1699 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1700 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1705 /* If S draws overlapping rows, it's sufficient to use the top and
1706 bottom of the window for clipping because this glyph string
1707 intentionally draws over other lines. */
1708 if (s
->for_overlaps
)
1710 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1711 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1713 /* Alas, the above simple strategy does not work for the
1714 environments with anti-aliased text: if the same text is
1715 drawn onto the same place multiple times, it gets thicker.
1716 If the overlap we are processing is for the erased cursor, we
1717 take the intersection with the rectagle of the cursor. */
1718 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1720 XRectangle rc
, r_save
= r
;
1722 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1723 rc
.y
= s
->w
->phys_cursor
.y
;
1724 rc
.width
= s
->w
->phys_cursor_width
;
1725 rc
.height
= s
->w
->phys_cursor_height
;
1727 x_intersect_rectangles (&r_save
, &rc
, &r
);
1732 /* Don't use S->y for clipping because it doesn't take partially
1733 visible lines into account. For example, it can be negative for
1734 partially visible lines at the top of a window. */
1735 if (!s
->row
->full_width_p
1736 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1737 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1739 r
.y
= max (0, s
->row
->y
);
1742 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1744 /* If drawing the cursor, don't let glyph draw outside its
1745 advertised boundaries. Cleartype does this under some circumstances. */
1746 if (s
->hl
== DRAW_CURSOR
)
1748 struct glyph
*glyph
= s
->first_glyph
;
1753 r
.width
-= s
->x
- r
.x
;
1756 r
.width
= min (r
.width
, glyph
->pixel_width
);
1758 /* If r.y is below window bottom, ensure that we still see a cursor. */
1759 height
= min (glyph
->ascent
+ glyph
->descent
,
1760 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1761 max_y
= window_text_bottom_y (s
->w
) - height
;
1762 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1763 if (s
->ybase
- glyph
->ascent
> max_y
)
1770 /* Don't draw cursor glyph taller than our actual glyph. */
1771 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1772 if (height
< r
.height
)
1774 max_y
= r
.y
+ r
.height
;
1775 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1776 r
.height
= min (max_y
- r
.y
, height
);
1783 XRectangle r_save
= r
;
1785 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1789 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1790 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1792 #ifdef CONVERT_FROM_XRECT
1793 CONVERT_FROM_XRECT (r
, *rects
);
1801 /* If we are processing overlapping and allowed to return
1802 multiple clipping rectangles, we exclude the row of the glyph
1803 string from the clipping rectangle. This is to avoid drawing
1804 the same text on the environment with anti-aliasing. */
1805 #ifdef CONVERT_FROM_XRECT
1808 XRectangle
*rs
= rects
;
1810 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1812 if (s
->for_overlaps
& OVERLAPS_PRED
)
1815 if (r
.y
+ r
.height
> row_y
)
1818 rs
[i
].height
= row_y
- r
.y
;
1824 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1827 if (r
.y
< row_y
+ s
->row
->visible_height
)
1829 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1831 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1832 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1841 #ifdef CONVERT_FROM_XRECT
1842 for (i
= 0; i
< n
; i
++)
1843 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1850 Return in *NR the clipping rectangle for glyph string S. */
1853 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
1855 get_glyph_string_clip_rects (s
, nr
, 1);
1860 Return the position and height of the phys cursor in window W.
1861 Set w->phys_cursor_width to width of phys cursor.
1865 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
1866 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
1868 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1869 int x
, y
, wd
, h
, h0
, y0
;
1871 /* Compute the width of the rectangle to draw. If on a stretch
1872 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1873 rectangle as wide as the glyph, but use a canonical character
1875 wd
= glyph
->pixel_width
- 1;
1876 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
1880 x
= w
->phys_cursor
.x
;
1887 if (glyph
->type
== STRETCH_GLYPH
1888 && !x_stretch_cursor_p
)
1889 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1890 w
->phys_cursor_width
= wd
;
1892 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1894 /* If y is below window bottom, ensure that we still see a cursor. */
1895 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1897 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1898 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1900 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1903 h
= max (h
- (y0
- y
) + 1, h0
);
1908 y0
= window_text_bottom_y (w
) - h0
;
1916 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
1917 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1922 * Remember which glyph the mouse is over.
1926 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
1930 struct glyph_row
*r
, *gr
, *end_row
;
1931 enum window_part part
;
1932 enum glyph_row_area area
;
1933 int x
, y
, width
, height
;
1935 /* Try to determine frame pixel position and size of the glyph under
1936 frame pixel coordinates X/Y on frame F. */
1938 if (!f
->glyphs_initialized_p
1939 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
1942 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1943 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1947 w
= XWINDOW (window
);
1948 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
1949 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
1951 x
= window_relative_x_coord (w
, part
, gx
);
1952 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
1954 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1955 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1957 if (w
->pseudo_window_p
)
1960 part
= ON_MODE_LINE
; /* Don't adjust margin. */
1966 case ON_LEFT_MARGIN
:
1967 area
= LEFT_MARGIN_AREA
;
1970 case ON_RIGHT_MARGIN
:
1971 area
= RIGHT_MARGIN_AREA
;
1974 case ON_HEADER_LINE
:
1976 gr
= (part
== ON_HEADER_LINE
1977 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1978 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
1981 goto text_glyph_row_found
;
1988 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
1989 if (r
->y
+ r
->height
> y
)
1995 text_glyph_row_found
:
1998 struct glyph
*g
= gr
->glyphs
[area
];
1999 struct glyph
*end
= g
+ gr
->used
[area
];
2001 height
= gr
->height
;
2002 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2003 if (gx
+ g
->pixel_width
> x
)
2008 if (g
->type
== IMAGE_GLYPH
)
2010 /* Don't remember when mouse is over image, as
2011 image may have hot-spots. */
2012 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2015 width
= g
->pixel_width
;
2019 /* Use nominal char spacing at end of line. */
2021 gx
+= (x
/ width
) * width
;
2024 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2025 gx
+= window_box_left_offset (w
, area
);
2029 /* Use nominal line height at end of window. */
2030 gx
= (x
/ width
) * width
;
2032 gy
+= (y
/ height
) * height
;
2036 case ON_LEFT_FRINGE
:
2037 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2038 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2039 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2040 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2043 case ON_RIGHT_FRINGE
:
2044 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2045 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2046 : window_box_right_offset (w
, TEXT_AREA
));
2047 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2051 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2053 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2054 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2055 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2057 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2061 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2062 if (r
->y
+ r
->height
> y
)
2069 height
= gr
->height
;
2072 /* Use nominal line height at end of window. */
2074 gy
+= (y
/ height
) * height
;
2081 /* If there is no glyph under the mouse, then we divide the screen
2082 into a grid of the smallest glyph in the frame, and use that
2085 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2086 round down even for negative values. */
2092 gx
= (gx
/ width
) * width
;
2093 gy
= (gy
/ height
) * height
;
2098 gx
+= WINDOW_LEFT_EDGE_X (w
);
2099 gy
+= WINDOW_TOP_EDGE_Y (w
);
2102 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2104 /* Visible feedback for debugging. */
2107 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2108 f
->output_data
.x
->normal_gc
,
2109 gx
, gy
, width
, height
);
2115 #endif /* HAVE_WINDOW_SYSTEM */
2118 /***********************************************************************
2119 Lisp form evaluation
2120 ***********************************************************************/
2122 /* Error handler for safe_eval and safe_call. */
2125 safe_eval_handler (Lisp_Object arg
)
2127 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2132 /* Evaluate SEXPR and return the result, or nil if something went
2133 wrong. Prevent redisplay during the evaluation. */
2135 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2136 Return the result, or nil if something went wrong. Prevent
2137 redisplay during the evaluation. */
2140 safe_call (size_t nargs
, Lisp_Object
*args
)
2144 if (inhibit_eval_during_redisplay
)
2148 int count
= SPECPDL_INDEX ();
2149 struct gcpro gcpro1
;
2152 gcpro1
.nvars
= nargs
;
2153 specbind (Qinhibit_redisplay
, Qt
);
2154 /* Use Qt to ensure debugger does not run,
2155 so there is no possibility of wanting to redisplay. */
2156 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2159 val
= unbind_to (count
, val
);
2166 /* Call function FN with one argument ARG.
2167 Return the result, or nil if something went wrong. */
2170 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2172 Lisp_Object args
[2];
2175 return safe_call (2, args
);
2178 static Lisp_Object Qeval
;
2181 safe_eval (Lisp_Object sexpr
)
2183 return safe_call1 (Qeval
, sexpr
);
2186 /* Call function FN with one argument ARG.
2187 Return the result, or nil if something went wrong. */
2190 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2192 Lisp_Object args
[3];
2196 return safe_call (3, args
);
2201 /***********************************************************************
2203 ***********************************************************************/
2207 /* Define CHECK_IT to perform sanity checks on iterators.
2208 This is for debugging. It is too slow to do unconditionally. */
2214 if (it
->method
== GET_FROM_STRING
)
2216 xassert (STRINGP (it
->string
));
2217 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2221 xassert (IT_STRING_CHARPOS (*it
) < 0);
2222 if (it
->method
== GET_FROM_BUFFER
)
2224 /* Check that character and byte positions agree. */
2225 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2230 xassert (it
->current
.dpvec_index
>= 0);
2232 xassert (it
->current
.dpvec_index
< 0);
2235 #define CHECK_IT(IT) check_it ((IT))
2239 #define CHECK_IT(IT) (void) 0
2246 /* Check that the window end of window W is what we expect it
2247 to be---the last row in the current matrix displaying text. */
2250 check_window_end (w
)
2253 if (!MINI_WINDOW_P (w
)
2254 && !NILP (w
->window_end_valid
))
2256 struct glyph_row
*row
;
2257 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2258 XFASTINT (w
->window_end_vpos
)),
2260 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2261 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2265 #define CHECK_WINDOW_END(W) check_window_end ((W))
2267 #else /* not GLYPH_DEBUG */
2269 #define CHECK_WINDOW_END(W) (void) 0
2271 #endif /* not GLYPH_DEBUG */
2275 /***********************************************************************
2276 Iterator initialization
2277 ***********************************************************************/
2279 /* Initialize IT for displaying current_buffer in window W, starting
2280 at character position CHARPOS. CHARPOS < 0 means that no buffer
2281 position is specified which is useful when the iterator is assigned
2282 a position later. BYTEPOS is the byte position corresponding to
2283 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2285 If ROW is not null, calls to produce_glyphs with IT as parameter
2286 will produce glyphs in that row.
2288 BASE_FACE_ID is the id of a base face to use. It must be one of
2289 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2290 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2291 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2293 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2294 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2295 will be initialized to use the corresponding mode line glyph row of
2296 the desired matrix of W. */
2299 init_iterator (struct it
*it
, struct window
*w
,
2300 EMACS_INT charpos
, EMACS_INT bytepos
,
2301 struct glyph_row
*row
, enum face_id base_face_id
)
2303 int highlight_region_p
;
2304 enum face_id remapped_base_face_id
= base_face_id
;
2306 /* Some precondition checks. */
2307 xassert (w
!= NULL
&& it
!= NULL
);
2308 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2311 /* If face attributes have been changed since the last redisplay,
2312 free realized faces now because they depend on face definitions
2313 that might have changed. Don't free faces while there might be
2314 desired matrices pending which reference these faces. */
2315 if (face_change_count
&& !inhibit_free_realized_faces
)
2317 face_change_count
= 0;
2318 free_all_realized_faces (Qnil
);
2321 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2322 if (! NILP (Vface_remapping_alist
))
2323 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2325 /* Use one of the mode line rows of W's desired matrix if
2329 if (base_face_id
== MODE_LINE_FACE_ID
2330 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2331 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2332 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2333 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2337 memset (it
, 0, sizeof *it
);
2338 it
->current
.overlay_string_index
= -1;
2339 it
->current
.dpvec_index
= -1;
2340 it
->base_face_id
= remapped_base_face_id
;
2342 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2344 /* The window in which we iterate over current_buffer: */
2345 XSETWINDOW (it
->window
, w
);
2347 it
->f
= XFRAME (w
->frame
);
2351 /* Extra space between lines (on window systems only). */
2352 if (base_face_id
== DEFAULT_FACE_ID
2353 && FRAME_WINDOW_P (it
->f
))
2355 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2356 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2357 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2358 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2359 * FRAME_LINE_HEIGHT (it
->f
));
2360 else if (it
->f
->extra_line_spacing
> 0)
2361 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2362 it
->max_extra_line_spacing
= 0;
2365 /* If realized faces have been removed, e.g. because of face
2366 attribute changes of named faces, recompute them. When running
2367 in batch mode, the face cache of the initial frame is null. If
2368 we happen to get called, make a dummy face cache. */
2369 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2370 init_frame_faces (it
->f
);
2371 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2372 recompute_basic_faces (it
->f
);
2374 /* Current value of the `slice', `space-width', and 'height' properties. */
2375 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2376 it
->space_width
= Qnil
;
2377 it
->font_height
= Qnil
;
2378 it
->override_ascent
= -1;
2380 /* Are control characters displayed as `^C'? */
2381 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2383 /* -1 means everything between a CR and the following line end
2384 is invisible. >0 means lines indented more than this value are
2386 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2387 ? XFASTINT (BVAR (current_buffer
, selective_display
))
2388 : (!NILP (BVAR (current_buffer
, selective_display
))
2390 it
->selective_display_ellipsis_p
2391 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2393 /* Display table to use. */
2394 it
->dp
= window_display_table (w
);
2396 /* Are multibyte characters enabled in current_buffer? */
2397 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2399 /* Do we need to reorder bidirectional text? Not if this is a
2400 unibyte buffer: by definition, none of the single-byte characters
2401 are strong R2L, so no reordering is needed. And bidi.c doesn't
2402 support unibyte buffers anyway. */
2404 = !NILP (BVAR (current_buffer
, bidi_display_reordering
)) && it
->multibyte_p
;
2406 /* Non-zero if we should highlight the region. */
2408 = (!NILP (Vtransient_mark_mode
)
2409 && !NILP (BVAR (current_buffer
, mark_active
))
2410 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2412 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2413 start and end of a visible region in window IT->w. Set both to
2414 -1 to indicate no region. */
2415 if (highlight_region_p
2416 /* Maybe highlight only in selected window. */
2417 && (/* Either show region everywhere. */
2418 highlight_nonselected_windows
2419 /* Or show region in the selected window. */
2420 || w
== XWINDOW (selected_window
)
2421 /* Or show the region if we are in the mini-buffer and W is
2422 the window the mini-buffer refers to. */
2423 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2424 && WINDOWP (minibuf_selected_window
)
2425 && w
== XWINDOW (minibuf_selected_window
))))
2427 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2428 it
->region_beg_charpos
= min (PT
, markpos
);
2429 it
->region_end_charpos
= max (PT
, markpos
);
2432 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2434 /* Get the position at which the redisplay_end_trigger hook should
2435 be run, if it is to be run at all. */
2436 if (MARKERP (w
->redisplay_end_trigger
)
2437 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2438 it
->redisplay_end_trigger_charpos
2439 = marker_position (w
->redisplay_end_trigger
);
2440 else if (INTEGERP (w
->redisplay_end_trigger
))
2441 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2443 /* Correct bogus values of tab_width. */
2444 it
->tab_width
= XINT (BVAR (current_buffer
, tab_width
));
2445 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2448 /* Are lines in the display truncated? */
2449 if (base_face_id
!= DEFAULT_FACE_ID
2450 || XINT (it
->w
->hscroll
)
2451 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2452 && ((!NILP (Vtruncate_partial_width_windows
)
2453 && !INTEGERP (Vtruncate_partial_width_windows
))
2454 || (INTEGERP (Vtruncate_partial_width_windows
)
2455 && (WINDOW_TOTAL_COLS (it
->w
)
2456 < XINT (Vtruncate_partial_width_windows
))))))
2457 it
->line_wrap
= TRUNCATE
;
2458 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2459 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2460 ? WINDOW_WRAP
: WORD_WRAP
;
2462 it
->line_wrap
= TRUNCATE
;
2464 /* Get dimensions of truncation and continuation glyphs. These are
2465 displayed as fringe bitmaps under X, so we don't need them for such
2467 if (!FRAME_WINDOW_P (it
->f
))
2469 if (it
->line_wrap
== TRUNCATE
)
2471 /* We will need the truncation glyph. */
2472 xassert (it
->glyph_row
== NULL
);
2473 produce_special_glyphs (it
, IT_TRUNCATION
);
2474 it
->truncation_pixel_width
= it
->pixel_width
;
2478 /* We will need the continuation glyph. */
2479 xassert (it
->glyph_row
== NULL
);
2480 produce_special_glyphs (it
, IT_CONTINUATION
);
2481 it
->continuation_pixel_width
= it
->pixel_width
;
2484 /* Reset these values to zero because the produce_special_glyphs
2485 above has changed them. */
2486 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2487 it
->phys_ascent
= it
->phys_descent
= 0;
2490 /* Set this after getting the dimensions of truncation and
2491 continuation glyphs, so that we don't produce glyphs when calling
2492 produce_special_glyphs, above. */
2493 it
->glyph_row
= row
;
2494 it
->area
= TEXT_AREA
;
2496 /* Forget any previous info about this row being reversed. */
2498 it
->glyph_row
->reversed_p
= 0;
2500 /* Get the dimensions of the display area. The display area
2501 consists of the visible window area plus a horizontally scrolled
2502 part to the left of the window. All x-values are relative to the
2503 start of this total display area. */
2504 if (base_face_id
!= DEFAULT_FACE_ID
)
2506 /* Mode lines, menu bar in terminal frames. */
2507 it
->first_visible_x
= 0;
2508 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2513 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2514 it
->last_visible_x
= (it
->first_visible_x
2515 + window_box_width (w
, TEXT_AREA
));
2517 /* If we truncate lines, leave room for the truncator glyph(s) at
2518 the right margin. Otherwise, leave room for the continuation
2519 glyph(s). Truncation and continuation glyphs are not inserted
2520 for window-based redisplay. */
2521 if (!FRAME_WINDOW_P (it
->f
))
2523 if (it
->line_wrap
== TRUNCATE
)
2524 it
->last_visible_x
-= it
->truncation_pixel_width
;
2526 it
->last_visible_x
-= it
->continuation_pixel_width
;
2529 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2530 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2533 /* Leave room for a border glyph. */
2534 if (!FRAME_WINDOW_P (it
->f
)
2535 && !WINDOW_RIGHTMOST_P (it
->w
))
2536 it
->last_visible_x
-= 1;
2538 it
->last_visible_y
= window_text_bottom_y (w
);
2540 /* For mode lines and alike, arrange for the first glyph having a
2541 left box line if the face specifies a box. */
2542 if (base_face_id
!= DEFAULT_FACE_ID
)
2546 it
->face_id
= remapped_base_face_id
;
2548 /* If we have a boxed mode line, make the first character appear
2549 with a left box line. */
2550 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2551 if (face
->box
!= FACE_NO_BOX
)
2552 it
->start_of_box_run_p
= 1;
2555 /* If we are to reorder bidirectional text, init the bidi
2559 /* Note the paragraph direction that this buffer wants to
2561 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
), Qleft_to_right
))
2562 it
->paragraph_embedding
= L2R
;
2563 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
), Qright_to_left
))
2564 it
->paragraph_embedding
= R2L
;
2566 it
->paragraph_embedding
= NEUTRAL_DIR
;
2567 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2570 /* If a buffer position was specified, set the iterator there,
2571 getting overlays and face properties from that position. */
2572 if (charpos
>= BUF_BEG (current_buffer
))
2574 it
->end_charpos
= ZV
;
2576 IT_CHARPOS (*it
) = charpos
;
2578 /* Compute byte position if not specified. */
2579 if (bytepos
< charpos
)
2580 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2582 IT_BYTEPOS (*it
) = bytepos
;
2584 it
->start
= it
->current
;
2586 /* Compute faces etc. */
2587 reseat (it
, it
->current
.pos
, 1);
2594 /* Initialize IT for the display of window W with window start POS. */
2597 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2599 struct glyph_row
*row
;
2600 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2602 row
= w
->desired_matrix
->rows
+ first_vpos
;
2603 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2604 it
->first_vpos
= first_vpos
;
2606 /* Don't reseat to previous visible line start if current start
2607 position is in a string or image. */
2608 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2610 int start_at_line_beg_p
;
2611 int first_y
= it
->current_y
;
2613 /* If window start is not at a line start, skip forward to POS to
2614 get the correct continuation lines width. */
2615 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2616 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2617 if (!start_at_line_beg_p
)
2621 reseat_at_previous_visible_line_start (it
);
2622 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2624 new_x
= it
->current_x
+ it
->pixel_width
;
2626 /* If lines are continued, this line may end in the middle
2627 of a multi-glyph character (e.g. a control character
2628 displayed as \003, or in the middle of an overlay
2629 string). In this case move_it_to above will not have
2630 taken us to the start of the continuation line but to the
2631 end of the continued line. */
2632 if (it
->current_x
> 0
2633 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2634 && (/* And glyph doesn't fit on the line. */
2635 new_x
> it
->last_visible_x
2636 /* Or it fits exactly and we're on a window
2638 || (new_x
== it
->last_visible_x
2639 && FRAME_WINDOW_P (it
->f
))))
2641 if (it
->current
.dpvec_index
>= 0
2642 || it
->current
.overlay_string_index
>= 0)
2644 set_iterator_to_next (it
, 1);
2645 move_it_in_display_line_to (it
, -1, -1, 0);
2648 it
->continuation_lines_width
+= it
->current_x
;
2651 /* We're starting a new display line, not affected by the
2652 height of the continued line, so clear the appropriate
2653 fields in the iterator structure. */
2654 it
->max_ascent
= it
->max_descent
= 0;
2655 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2657 it
->current_y
= first_y
;
2659 it
->current_x
= it
->hpos
= 0;
2665 /* Return 1 if POS is a position in ellipses displayed for invisible
2666 text. W is the window we display, for text property lookup. */
2669 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2671 Lisp_Object prop
, window
;
2673 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2675 /* If POS specifies a position in a display vector, this might
2676 be for an ellipsis displayed for invisible text. We won't
2677 get the iterator set up for delivering that ellipsis unless
2678 we make sure that it gets aware of the invisible text. */
2679 if (pos
->dpvec_index
>= 0
2680 && pos
->overlay_string_index
< 0
2681 && CHARPOS (pos
->string_pos
) < 0
2683 && (XSETWINDOW (window
, w
),
2684 prop
= Fget_char_property (make_number (charpos
),
2685 Qinvisible
, window
),
2686 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2688 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2690 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2697 /* Initialize IT for stepping through current_buffer in window W,
2698 starting at position POS that includes overlay string and display
2699 vector/ control character translation position information. Value
2700 is zero if there are overlay strings with newlines at POS. */
2703 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2705 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2706 int i
, overlay_strings_with_newlines
= 0;
2708 /* If POS specifies a position in a display vector, this might
2709 be for an ellipsis displayed for invisible text. We won't
2710 get the iterator set up for delivering that ellipsis unless
2711 we make sure that it gets aware of the invisible text. */
2712 if (in_ellipses_for_invisible_text_p (pos
, w
))
2718 /* Keep in mind: the call to reseat in init_iterator skips invisible
2719 text, so we might end up at a position different from POS. This
2720 is only a problem when POS is a row start after a newline and an
2721 overlay starts there with an after-string, and the overlay has an
2722 invisible property. Since we don't skip invisible text in
2723 display_line and elsewhere immediately after consuming the
2724 newline before the row start, such a POS will not be in a string,
2725 but the call to init_iterator below will move us to the
2727 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2729 /* This only scans the current chunk -- it should scan all chunks.
2730 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2731 to 16 in 22.1 to make this a lesser problem. */
2732 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2734 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2735 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2737 while (s
< e
&& *s
!= '\n')
2742 overlay_strings_with_newlines
= 1;
2747 /* If position is within an overlay string, set up IT to the right
2749 if (pos
->overlay_string_index
>= 0)
2753 /* If the first overlay string happens to have a `display'
2754 property for an image, the iterator will be set up for that
2755 image, and we have to undo that setup first before we can
2756 correct the overlay string index. */
2757 if (it
->method
== GET_FROM_IMAGE
)
2760 /* We already have the first chunk of overlay strings in
2761 IT->overlay_strings. Load more until the one for
2762 pos->overlay_string_index is in IT->overlay_strings. */
2763 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2765 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2766 it
->current
.overlay_string_index
= 0;
2769 load_overlay_strings (it
, 0);
2770 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2774 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2775 relative_index
= (it
->current
.overlay_string_index
2776 % OVERLAY_STRING_CHUNK_SIZE
);
2777 it
->string
= it
->overlay_strings
[relative_index
];
2778 xassert (STRINGP (it
->string
));
2779 it
->current
.string_pos
= pos
->string_pos
;
2780 it
->method
= GET_FROM_STRING
;
2783 if (CHARPOS (pos
->string_pos
) >= 0)
2785 /* Recorded position is not in an overlay string, but in another
2786 string. This can only be a string from a `display' property.
2787 IT should already be filled with that string. */
2788 it
->current
.string_pos
= pos
->string_pos
;
2789 xassert (STRINGP (it
->string
));
2792 /* Restore position in display vector translations, control
2793 character translations or ellipses. */
2794 if (pos
->dpvec_index
>= 0)
2796 if (it
->dpvec
== NULL
)
2797 get_next_display_element (it
);
2798 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2799 it
->current
.dpvec_index
= pos
->dpvec_index
;
2803 return !overlay_strings_with_newlines
;
2807 /* Initialize IT for stepping through current_buffer in window W
2808 starting at ROW->start. */
2811 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2813 init_from_display_pos (it
, w
, &row
->start
);
2814 it
->start
= row
->start
;
2815 it
->continuation_lines_width
= row
->continuation_lines_width
;
2820 /* Initialize IT for stepping through current_buffer in window W
2821 starting in the line following ROW, i.e. starting at ROW->end.
2822 Value is zero if there are overlay strings with newlines at ROW's
2826 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2830 if (init_from_display_pos (it
, w
, &row
->end
))
2832 if (row
->continued_p
)
2833 it
->continuation_lines_width
2834 = row
->continuation_lines_width
+ row
->pixel_width
;
2845 /***********************************************************************
2847 ***********************************************************************/
2849 /* Called when IT reaches IT->stop_charpos. Handle text property and
2850 overlay changes. Set IT->stop_charpos to the next position where
2854 handle_stop (struct it
*it
)
2856 enum prop_handled handled
;
2857 int handle_overlay_change_p
;
2861 it
->current
.dpvec_index
= -1;
2862 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2863 it
->ignore_overlay_strings_at_pos_p
= 0;
2866 /* Use face of preceding text for ellipsis (if invisible) */
2867 if (it
->selective_display_ellipsis_p
)
2868 it
->saved_face_id
= it
->face_id
;
2872 handled
= HANDLED_NORMALLY
;
2874 /* Call text property handlers. */
2875 for (p
= it_props
; p
->handler
; ++p
)
2877 handled
= p
->handler (it
);
2879 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2881 else if (handled
== HANDLED_RETURN
)
2883 /* We still want to show before and after strings from
2884 overlays even if the actual buffer text is replaced. */
2885 if (!handle_overlay_change_p
2887 || !get_overlay_strings_1 (it
, 0, 0))
2890 setup_for_ellipsis (it
, 0);
2891 /* When handling a display spec, we might load an
2892 empty string. In that case, discard it here. We
2893 used to discard it in handle_single_display_spec,
2894 but that causes get_overlay_strings_1, above, to
2895 ignore overlay strings that we must check. */
2896 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2900 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2904 it
->ignore_overlay_strings_at_pos_p
= 1;
2905 it
->string_from_display_prop_p
= 0;
2906 handle_overlay_change_p
= 0;
2908 handled
= HANDLED_RECOMPUTE_PROPS
;
2911 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2912 handle_overlay_change_p
= 0;
2915 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2917 /* Don't check for overlay strings below when set to deliver
2918 characters from a display vector. */
2919 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2920 handle_overlay_change_p
= 0;
2922 /* Handle overlay changes.
2923 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
2924 if it finds overlays. */
2925 if (handle_overlay_change_p
)
2926 handled
= handle_overlay_change (it
);
2931 setup_for_ellipsis (it
, 0);
2935 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2937 /* Determine where to stop next. */
2938 if (handled
== HANDLED_NORMALLY
)
2939 compute_stop_pos (it
);
2943 /* Compute IT->stop_charpos from text property and overlay change
2944 information for IT's current position. */
2947 compute_stop_pos (struct it
*it
)
2949 register INTERVAL iv
, next_iv
;
2950 Lisp_Object object
, limit
, position
;
2951 EMACS_INT charpos
, bytepos
;
2953 /* If nowhere else, stop at the end. */
2954 it
->stop_charpos
= it
->end_charpos
;
2956 if (STRINGP (it
->string
))
2958 /* Strings are usually short, so don't limit the search for
2960 object
= it
->string
;
2962 charpos
= IT_STRING_CHARPOS (*it
);
2963 bytepos
= IT_STRING_BYTEPOS (*it
);
2969 /* If next overlay change is in front of the current stop pos
2970 (which is IT->end_charpos), stop there. Note: value of
2971 next_overlay_change is point-max if no overlay change
2973 charpos
= IT_CHARPOS (*it
);
2974 bytepos
= IT_BYTEPOS (*it
);
2975 pos
= next_overlay_change (charpos
);
2976 if (pos
< it
->stop_charpos
)
2977 it
->stop_charpos
= pos
;
2979 /* If showing the region, we have to stop at the region
2980 start or end because the face might change there. */
2981 if (it
->region_beg_charpos
> 0)
2983 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2984 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2985 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2986 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2989 /* Set up variables for computing the stop position from text
2990 property changes. */
2991 XSETBUFFER (object
, current_buffer
);
2992 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2995 /* Get the interval containing IT's position. Value is a null
2996 interval if there isn't such an interval. */
2997 position
= make_number (charpos
);
2998 iv
= validate_interval_range (object
, &position
, &position
, 0);
2999 if (!NULL_INTERVAL_P (iv
))
3001 Lisp_Object values_here
[LAST_PROP_IDX
];
3004 /* Get properties here. */
3005 for (p
= it_props
; p
->handler
; ++p
)
3006 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3008 /* Look for an interval following iv that has different
3010 for (next_iv
= next_interval (iv
);
3011 (!NULL_INTERVAL_P (next_iv
)
3013 || XFASTINT (limit
) > next_iv
->position
));
3014 next_iv
= next_interval (next_iv
))
3016 for (p
= it_props
; p
->handler
; ++p
)
3018 Lisp_Object new_value
;
3020 new_value
= textget (next_iv
->plist
, *p
->name
);
3021 if (!EQ (values_here
[p
->idx
], new_value
))
3029 if (!NULL_INTERVAL_P (next_iv
))
3031 if (INTEGERP (limit
)
3032 && next_iv
->position
>= XFASTINT (limit
))
3033 /* No text property change up to limit. */
3034 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3036 /* Text properties change in next_iv. */
3037 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3041 if (it
->cmp_it
.id
< 0)
3043 EMACS_INT stoppos
= it
->end_charpos
;
3045 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3047 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3048 stoppos
, it
->string
);
3051 xassert (STRINGP (it
->string
)
3052 || (it
->stop_charpos
>= BEGV
3053 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3057 /* Return the position of the next overlay change after POS in
3058 current_buffer. Value is point-max if no overlay change
3059 follows. This is like `next-overlay-change' but doesn't use
3063 next_overlay_change (EMACS_INT pos
)
3067 Lisp_Object
*overlays
;
3070 /* Get all overlays at the given position. */
3071 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3073 /* If any of these overlays ends before endpos,
3074 use its ending point instead. */
3075 for (i
= 0; i
< noverlays
; ++i
)
3080 oend
= OVERLAY_END (overlays
[i
]);
3081 oendpos
= OVERLAY_POSITION (oend
);
3082 endpos
= min (endpos
, oendpos
);
3088 /* Return the character position of a display string at or after CHARPOS.
3089 If no display string exist at or after CHARPOS, return ZV. A
3090 display string is either an overlay with `display' property whose
3091 value is a string or a `display' text property whose value is a
3094 compute_display_string_pos (EMACS_INT charpos
)
3096 /* FIXME: Support display properties on strings (object = Qnil means
3098 Lisp_Object object
= Qnil
;
3099 Lisp_Object pos
= make_number (charpos
);
3104 /* If the character at CHARPOS is where the display string begins,
3106 if (!NILP (Fget_char_property (pos
, Qdisplay
, object
))
3108 || NILP (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3112 /* Look forward for the first character where the `display' property
3113 changes from nil to non-nil. */
3115 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3116 } while (XFASTINT (pos
) < ZV
3117 && NILP (Fget_char_property (pos
, Qdisplay
, object
)));
3119 return XFASTINT (pos
);
3122 /* Return the character position of the end of the display string that
3123 started at CHARPOS. A display string is either an overlay with
3124 `display' property whose value is a string or a `display' text
3125 property whose value is a string. */
3127 compute_display_string_end (EMACS_INT charpos
)
3129 /* FIXME: Support display properties on strings (object = Qnil means
3131 Lisp_Object object
= Qnil
;
3132 Lisp_Object pos
= make_number (charpos
);
3137 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3140 /* Look forward for the first character where the `display' property
3142 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3144 return XFASTINT (pos
);
3149 /***********************************************************************
3151 ***********************************************************************/
3153 /* Handle changes in the `fontified' property of the current buffer by
3154 calling hook functions from Qfontification_functions to fontify
3157 static enum prop_handled
3158 handle_fontified_prop (struct it
*it
)
3160 Lisp_Object prop
, pos
;
3161 enum prop_handled handled
= HANDLED_NORMALLY
;
3163 if (!NILP (Vmemory_full
))
3166 /* Get the value of the `fontified' property at IT's current buffer
3167 position. (The `fontified' property doesn't have a special
3168 meaning in strings.) If the value is nil, call functions from
3169 Qfontification_functions. */
3170 if (!STRINGP (it
->string
)
3172 && !NILP (Vfontification_functions
)
3173 && !NILP (Vrun_hooks
)
3174 && (pos
= make_number (IT_CHARPOS (*it
)),
3175 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3176 /* Ignore the special cased nil value always present at EOB since
3177 no amount of fontifying will be able to change it. */
3178 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3180 int count
= SPECPDL_INDEX ();
3182 struct buffer
*obuf
= current_buffer
;
3183 int begv
= BEGV
, zv
= ZV
;
3184 int old_clip_changed
= current_buffer
->clip_changed
;
3186 val
= Vfontification_functions
;
3187 specbind (Qfontification_functions
, Qnil
);
3189 xassert (it
->end_charpos
== ZV
);
3191 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3192 safe_call1 (val
, pos
);
3195 Lisp_Object fns
, fn
;
3196 struct gcpro gcpro1
, gcpro2
;
3201 for (; CONSP (val
); val
= XCDR (val
))
3207 /* A value of t indicates this hook has a local
3208 binding; it means to run the global binding too.
3209 In a global value, t should not occur. If it
3210 does, we must ignore it to avoid an endless
3212 for (fns
= Fdefault_value (Qfontification_functions
);
3218 safe_call1 (fn
, pos
);
3222 safe_call1 (fn
, pos
);
3228 unbind_to (count
, Qnil
);
3230 /* Fontification functions routinely call `save-restriction'.
3231 Normally, this tags clip_changed, which can confuse redisplay
3232 (see discussion in Bug#6671). Since we don't perform any
3233 special handling of fontification changes in the case where
3234 `save-restriction' isn't called, there's no point doing so in
3235 this case either. So, if the buffer's restrictions are
3236 actually left unchanged, reset clip_changed. */
3237 if (obuf
== current_buffer
)
3239 if (begv
== BEGV
&& zv
== ZV
)
3240 current_buffer
->clip_changed
= old_clip_changed
;
3242 /* There isn't much we can reasonably do to protect against
3243 misbehaving fontification, but here's a fig leaf. */
3244 else if (!NILP (BVAR (obuf
, name
)))
3245 set_buffer_internal_1 (obuf
);
3247 /* The fontification code may have added/removed text.
3248 It could do even a lot worse, but let's at least protect against
3249 the most obvious case where only the text past `pos' gets changed',
3250 as is/was done in grep.el where some escapes sequences are turned
3251 into face properties (bug#7876). */
3252 it
->end_charpos
= ZV
;
3254 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3255 something. This avoids an endless loop if they failed to
3256 fontify the text for which reason ever. */
3257 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3258 handled
= HANDLED_RECOMPUTE_PROPS
;
3266 /***********************************************************************
3268 ***********************************************************************/
3270 /* Set up iterator IT from face properties at its current position.
3271 Called from handle_stop. */
3273 static enum prop_handled
3274 handle_face_prop (struct it
*it
)
3277 EMACS_INT next_stop
;
3279 if (!STRINGP (it
->string
))
3282 = face_at_buffer_position (it
->w
,
3284 it
->region_beg_charpos
,
3285 it
->region_end_charpos
,
3288 + TEXT_PROP_DISTANCE_LIMIT
),
3289 0, it
->base_face_id
);
3291 /* Is this a start of a run of characters with box face?
3292 Caveat: this can be called for a freshly initialized
3293 iterator; face_id is -1 in this case. We know that the new
3294 face will not change until limit, i.e. if the new face has a
3295 box, all characters up to limit will have one. But, as
3296 usual, we don't know whether limit is really the end. */
3297 if (new_face_id
!= it
->face_id
)
3299 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3301 /* If new face has a box but old face has not, this is
3302 the start of a run of characters with box, i.e. it has
3303 a shadow on the left side. The value of face_id of the
3304 iterator will be -1 if this is the initial call that gets
3305 the face. In this case, we have to look in front of IT's
3306 position and see whether there is a face != new_face_id. */
3307 it
->start_of_box_run_p
3308 = (new_face
->box
!= FACE_NO_BOX
3309 && (it
->face_id
>= 0
3310 || IT_CHARPOS (*it
) == BEG
3311 || new_face_id
!= face_before_it_pos (it
)));
3312 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3320 Lisp_Object from_overlay
3321 = (it
->current
.overlay_string_index
>= 0
3322 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3325 /* See if we got to this string directly or indirectly from
3326 an overlay property. That includes the before-string or
3327 after-string of an overlay, strings in display properties
3328 provided by an overlay, their text properties, etc.
3330 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3331 if (! NILP (from_overlay
))
3332 for (i
= it
->sp
- 1; i
>= 0; i
--)
3334 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3336 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3337 else if (! NILP (it
->stack
[i
].from_overlay
))
3338 from_overlay
= it
->stack
[i
].from_overlay
;
3340 if (!NILP (from_overlay
))
3344 if (! NILP (from_overlay
))
3346 bufpos
= IT_CHARPOS (*it
);
3347 /* For a string from an overlay, the base face depends
3348 only on text properties and ignores overlays. */
3350 = face_for_overlay_string (it
->w
,
3352 it
->region_beg_charpos
,
3353 it
->region_end_charpos
,
3356 + TEXT_PROP_DISTANCE_LIMIT
),
3364 /* For strings from a `display' property, use the face at
3365 IT's current buffer position as the base face to merge
3366 with, so that overlay strings appear in the same face as
3367 surrounding text, unless they specify their own
3369 base_face_id
= underlying_face_id (it
);
3372 new_face_id
= face_at_string_position (it
->w
,
3374 IT_STRING_CHARPOS (*it
),
3376 it
->region_beg_charpos
,
3377 it
->region_end_charpos
,
3381 /* Is this a start of a run of characters with box? Caveat:
3382 this can be called for a freshly allocated iterator; face_id
3383 is -1 is this case. We know that the new face will not
3384 change until the next check pos, i.e. if the new face has a
3385 box, all characters up to that position will have a
3386 box. But, as usual, we don't know whether that position
3387 is really the end. */
3388 if (new_face_id
!= it
->face_id
)
3390 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3391 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3393 /* If new face has a box but old face hasn't, this is the
3394 start of a run of characters with box, i.e. it has a
3395 shadow on the left side. */
3396 it
->start_of_box_run_p
3397 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3398 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3402 it
->face_id
= new_face_id
;
3403 return HANDLED_NORMALLY
;
3407 /* Return the ID of the face ``underlying'' IT's current position,
3408 which is in a string. If the iterator is associated with a
3409 buffer, return the face at IT's current buffer position.
3410 Otherwise, use the iterator's base_face_id. */
3413 underlying_face_id (struct it
*it
)
3415 int face_id
= it
->base_face_id
, i
;
3417 xassert (STRINGP (it
->string
));
3419 for (i
= it
->sp
- 1; i
>= 0; --i
)
3420 if (NILP (it
->stack
[i
].string
))
3421 face_id
= it
->stack
[i
].face_id
;
3427 /* Compute the face one character before or after the current position
3428 of IT. BEFORE_P non-zero means get the face in front of IT's
3429 position. Value is the id of the face. */
3432 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3435 EMACS_INT next_check_charpos
;
3436 struct text_pos pos
;
3438 xassert (it
->s
== NULL
);
3440 if (STRINGP (it
->string
))
3445 /* No face change past the end of the string (for the case
3446 we are padding with spaces). No face change before the
3448 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3449 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3452 /* Set pos to the position before or after IT's current position. */
3454 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3456 /* For composition, we must check the character after the
3458 pos
= (it
->what
== IT_COMPOSITION
3459 ? string_pos (IT_STRING_CHARPOS (*it
)
3460 + it
->cmp_it
.nchars
, it
->string
)
3461 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3463 if (it
->current
.overlay_string_index
>= 0)
3464 bufpos
= IT_CHARPOS (*it
);
3468 base_face_id
= underlying_face_id (it
);
3470 /* Get the face for ASCII, or unibyte. */
3471 face_id
= face_at_string_position (it
->w
,
3475 it
->region_beg_charpos
,
3476 it
->region_end_charpos
,
3477 &next_check_charpos
,
3480 /* Correct the face for charsets different from ASCII. Do it
3481 for the multibyte case only. The face returned above is
3482 suitable for unibyte text if IT->string is unibyte. */
3483 if (STRING_MULTIBYTE (it
->string
))
3485 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3487 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3489 c
= string_char_and_length (p
, &len
);
3490 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3495 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3496 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3499 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3500 pos
= it
->current
.pos
;
3503 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3506 if (it
->what
== IT_COMPOSITION
)
3507 /* For composition, we must check the position after the
3509 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3511 INC_TEXT_POS (pos
, it
->multibyte_p
);
3514 /* Determine face for CHARSET_ASCII, or unibyte. */
3515 face_id
= face_at_buffer_position (it
->w
,
3517 it
->region_beg_charpos
,
3518 it
->region_end_charpos
,
3519 &next_check_charpos
,
3522 /* Correct the face for charsets different from ASCII. Do it
3523 for the multibyte case only. The face returned above is
3524 suitable for unibyte text if current_buffer is unibyte. */
3525 if (it
->multibyte_p
)
3527 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3528 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3529 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3538 /***********************************************************************
3540 ***********************************************************************/
3542 /* Set up iterator IT from invisible properties at its current
3543 position. Called from handle_stop. */
3545 static enum prop_handled
3546 handle_invisible_prop (struct it
*it
)
3548 enum prop_handled handled
= HANDLED_NORMALLY
;
3550 if (STRINGP (it
->string
))
3552 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3554 /* Get the value of the invisible text property at the
3555 current position. Value will be nil if there is no such
3557 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3558 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3561 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3563 handled
= HANDLED_RECOMPUTE_PROPS
;
3565 /* Get the position at which the next change of the
3566 invisible text property can be found in IT->string.
3567 Value will be nil if the property value is the same for
3568 all the rest of IT->string. */
3569 XSETINT (limit
, SCHARS (it
->string
));
3570 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3573 /* Text at current position is invisible. The next
3574 change in the property is at position end_charpos.
3575 Move IT's current position to that position. */
3576 if (INTEGERP (end_charpos
)
3577 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3579 struct text_pos old
;
3580 old
= it
->current
.string_pos
;
3581 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3582 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3586 /* The rest of the string is invisible. If this is an
3587 overlay string, proceed with the next overlay string
3588 or whatever comes and return a character from there. */
3589 if (it
->current
.overlay_string_index
>= 0)
3591 next_overlay_string (it
);
3592 /* Don't check for overlay strings when we just
3593 finished processing them. */
3594 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3598 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3599 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3607 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3608 Lisp_Object pos
, prop
, overlay
;
3610 /* First of all, is there invisible text at this position? */
3611 tem
= start_charpos
= IT_CHARPOS (*it
);
3612 pos
= make_number (tem
);
3613 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3615 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3617 /* If we are on invisible text, skip over it. */
3618 if (invis_p
&& start_charpos
< it
->end_charpos
)
3620 /* Record whether we have to display an ellipsis for the
3622 int display_ellipsis_p
= invis_p
== 2;
3624 handled
= HANDLED_RECOMPUTE_PROPS
;
3626 /* Loop skipping over invisible text. The loop is left at
3627 ZV or with IT on the first char being visible again. */
3630 /* Try to skip some invisible text. Return value is the
3631 position reached which can be equal to where we start
3632 if there is nothing invisible there. This skips both
3633 over invisible text properties and overlays with
3634 invisible property. */
3635 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3637 /* If we skipped nothing at all we weren't at invisible
3638 text in the first place. If everything to the end of
3639 the buffer was skipped, end the loop. */
3640 if (newpos
== tem
|| newpos
>= ZV
)
3644 /* We skipped some characters but not necessarily
3645 all there are. Check if we ended up on visible
3646 text. Fget_char_property returns the property of
3647 the char before the given position, i.e. if we
3648 get invis_p = 0, this means that the char at
3649 newpos is visible. */
3650 pos
= make_number (newpos
);
3651 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3652 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3655 /* If we ended up on invisible text, proceed to
3656 skip starting with next_stop. */
3660 /* If there are adjacent invisible texts, don't lose the
3661 second one's ellipsis. */
3663 display_ellipsis_p
= 1;
3667 /* The position newpos is now either ZV or on visible text. */
3668 if (it
->bidi_p
&& newpos
< ZV
)
3670 /* With bidi iteration, the region of invisible text
3671 could start and/or end in the middle of a non-base
3672 embedding level. Therefore, we need to skip
3673 invisible text using the bidi iterator, starting at
3674 IT's current position, until we find ourselves
3675 outside the invisible text. Skipping invisible text
3676 _after_ bidi iteration avoids affecting the visual
3677 order of the displayed text when invisible properties
3678 are added or removed. */
3679 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3681 /* If we were `reseat'ed to a new paragraph,
3682 determine the paragraph base direction. We need
3683 to do it now because next_element_from_buffer may
3684 not have a chance to do it, if we are going to
3685 skip any text at the beginning, which resets the
3687 bidi_paragraph_init (it
->paragraph_embedding
,
3692 bidi_move_to_visually_next (&it
->bidi_it
);
3694 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3695 && it
->bidi_it
.charpos
< newpos
);
3696 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3697 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3698 /* If we overstepped NEWPOS, record its position in the
3699 iterator, so that we skip invisible text if later the
3700 bidi iteration lands us in the invisible region
3702 if (IT_CHARPOS (*it
) >= newpos
)
3703 it
->prev_stop
= newpos
;
3707 IT_CHARPOS (*it
) = newpos
;
3708 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3711 /* If there are before-strings at the start of invisible
3712 text, and the text is invisible because of a text
3713 property, arrange to show before-strings because 20.x did
3714 it that way. (If the text is invisible because of an
3715 overlay property instead of a text property, this is
3716 already handled in the overlay code.) */
3718 && get_overlay_strings (it
, it
->stop_charpos
))
3720 handled
= HANDLED_RECOMPUTE_PROPS
;
3721 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3723 else if (display_ellipsis_p
)
3725 /* Make sure that the glyphs of the ellipsis will get
3726 correct `charpos' values. If we would not update
3727 it->position here, the glyphs would belong to the
3728 last visible character _before_ the invisible
3729 text, which confuses `set_cursor_from_row'.
3731 We use the last invisible position instead of the
3732 first because this way the cursor is always drawn on
3733 the first "." of the ellipsis, whenever PT is inside
3734 the invisible text. Otherwise the cursor would be
3735 placed _after_ the ellipsis when the point is after the
3736 first invisible character. */
3737 if (!STRINGP (it
->object
))
3739 it
->position
.charpos
= newpos
- 1;
3740 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3743 /* Let the ellipsis display before
3744 considering any properties of the following char.
3745 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3746 handled
= HANDLED_RETURN
;
3755 /* Make iterator IT return `...' next.
3756 Replaces LEN characters from buffer. */
3759 setup_for_ellipsis (struct it
*it
, int len
)
3761 /* Use the display table definition for `...'. Invalid glyphs
3762 will be handled by the method returning elements from dpvec. */
3763 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3765 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3766 it
->dpvec
= v
->contents
;
3767 it
->dpend
= v
->contents
+ v
->header
.size
;
3771 /* Default `...'. */
3772 it
->dpvec
= default_invis_vector
;
3773 it
->dpend
= default_invis_vector
+ 3;
3776 it
->dpvec_char_len
= len
;
3777 it
->current
.dpvec_index
= 0;
3778 it
->dpvec_face_id
= -1;
3780 /* Remember the current face id in case glyphs specify faces.
3781 IT's face is restored in set_iterator_to_next.
3782 saved_face_id was set to preceding char's face in handle_stop. */
3783 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3784 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3786 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3792 /***********************************************************************
3794 ***********************************************************************/
3796 /* Set up iterator IT from `display' property at its current position.
3797 Called from handle_stop.
3798 We return HANDLED_RETURN if some part of the display property
3799 overrides the display of the buffer text itself.
3800 Otherwise we return HANDLED_NORMALLY. */
3802 static enum prop_handled
3803 handle_display_prop (struct it
*it
)
3805 Lisp_Object prop
, object
, overlay
;
3806 struct text_pos
*position
;
3807 /* Nonzero if some property replaces the display of the text itself. */
3808 int display_replaced_p
= 0;
3810 if (STRINGP (it
->string
))
3812 object
= it
->string
;
3813 position
= &it
->current
.string_pos
;
3817 XSETWINDOW (object
, it
->w
);
3818 position
= &it
->current
.pos
;
3821 /* Reset those iterator values set from display property values. */
3822 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3823 it
->space_width
= Qnil
;
3824 it
->font_height
= Qnil
;
3827 /* We don't support recursive `display' properties, i.e. string
3828 values that have a string `display' property, that have a string
3829 `display' property etc. */
3830 if (!it
->string_from_display_prop_p
)
3831 it
->area
= TEXT_AREA
;
3833 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3834 Qdisplay
, object
, &overlay
);
3836 return HANDLED_NORMALLY
;
3837 /* Now OVERLAY is the overlay that gave us this property, or nil
3838 if it was a text property. */
3840 if (!STRINGP (it
->string
))
3841 object
= it
->w
->buffer
;
3844 /* Simple properties. */
3845 && !EQ (XCAR (prop
), Qimage
)
3846 && !EQ (XCAR (prop
), Qspace
)
3847 && !EQ (XCAR (prop
), Qwhen
)
3848 && !EQ (XCAR (prop
), Qslice
)
3849 && !EQ (XCAR (prop
), Qspace_width
)
3850 && !EQ (XCAR (prop
), Qheight
)
3851 && !EQ (XCAR (prop
), Qraise
)
3852 /* Marginal area specifications. */
3853 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3854 && !EQ (XCAR (prop
), Qleft_fringe
)
3855 && !EQ (XCAR (prop
), Qright_fringe
)
3856 && !NILP (XCAR (prop
)))
3858 for (; CONSP (prop
); prop
= XCDR (prop
))
3860 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3861 position
, display_replaced_p
))
3863 display_replaced_p
= 1;
3864 /* If some text in a string is replaced, `position' no
3865 longer points to the position of `object'. */
3866 if (STRINGP (object
))
3871 else if (VECTORP (prop
))
3874 for (i
= 0; i
< ASIZE (prop
); ++i
)
3875 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3876 position
, display_replaced_p
))
3878 display_replaced_p
= 1;
3879 /* If some text in a string is replaced, `position' no
3880 longer points to the position of `object'. */
3881 if (STRINGP (object
))
3887 if (handle_single_display_spec (it
, prop
, object
, overlay
,
3889 display_replaced_p
= 1;
3892 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3896 /* Value is the position of the end of the `display' property starting
3897 at START_POS in OBJECT. */
3899 static struct text_pos
3900 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
3903 struct text_pos end_pos
;
3905 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3906 Qdisplay
, object
, Qnil
);
3907 CHARPOS (end_pos
) = XFASTINT (end
);
3908 if (STRINGP (object
))
3909 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3911 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3917 /* Set up IT from a single `display' property specification SPEC. OBJECT
3918 is the object in which the `display' property was found. *POSITION
3919 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3920 means that we previously saw a display specification which already
3921 replaced text display with something else, for example an image;
3922 we ignore such properties after the first one has been processed.
3924 OVERLAY is the overlay this `display' property came from,
3925 or nil if it was a text property.
3927 If SPEC is a `space' or `image' specification, and in some other
3928 cases too, set *POSITION to the position where the `display'
3931 Value is non-zero if something was found which replaces the display
3932 of buffer or string text. */
3935 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
3936 Lisp_Object overlay
, struct text_pos
*position
,
3937 int display_replaced_p
)
3940 Lisp_Object location
, value
;
3941 struct text_pos start_pos
, save_pos
;
3944 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3945 If the result is non-nil, use VALUE instead of SPEC. */
3947 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3956 if (!NILP (form
) && !EQ (form
, Qt
))
3958 int count
= SPECPDL_INDEX ();
3959 struct gcpro gcpro1
;
3961 /* Bind `object' to the object having the `display' property, a
3962 buffer or string. Bind `position' to the position in the
3963 object where the property was found, and `buffer-position'
3964 to the current position in the buffer. */
3965 specbind (Qobject
, object
);
3966 specbind (Qposition
, make_number (CHARPOS (*position
)));
3967 specbind (Qbuffer_position
,
3968 make_number (STRINGP (object
)
3969 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3971 form
= safe_eval (form
);
3973 unbind_to (count
, Qnil
);
3979 /* Handle `(height HEIGHT)' specifications. */
3981 && EQ (XCAR (spec
), Qheight
)
3982 && CONSP (XCDR (spec
)))
3984 if (!FRAME_WINDOW_P (it
->f
))
3987 it
->font_height
= XCAR (XCDR (spec
));
3988 if (!NILP (it
->font_height
))
3990 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3991 int new_height
= -1;
3993 if (CONSP (it
->font_height
)
3994 && (EQ (XCAR (it
->font_height
), Qplus
)
3995 || EQ (XCAR (it
->font_height
), Qminus
))
3996 && CONSP (XCDR (it
->font_height
))
3997 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3999 /* `(+ N)' or `(- N)' where N is an integer. */
4000 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4001 if (EQ (XCAR (it
->font_height
), Qplus
))
4003 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4005 else if (FUNCTIONP (it
->font_height
))
4007 /* Call function with current height as argument.
4008 Value is the new height. */
4010 height
= safe_call1 (it
->font_height
,
4011 face
->lface
[LFACE_HEIGHT_INDEX
]);
4012 if (NUMBERP (height
))
4013 new_height
= XFLOATINT (height
);
4015 else if (NUMBERP (it
->font_height
))
4017 /* Value is a multiple of the canonical char height. */
4020 f
= FACE_FROM_ID (it
->f
,
4021 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4022 new_height
= (XFLOATINT (it
->font_height
)
4023 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4027 /* Evaluate IT->font_height with `height' bound to the
4028 current specified height to get the new height. */
4029 int count
= SPECPDL_INDEX ();
4031 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4032 value
= safe_eval (it
->font_height
);
4033 unbind_to (count
, Qnil
);
4035 if (NUMBERP (value
))
4036 new_height
= XFLOATINT (value
);
4040 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4046 /* Handle `(space-width WIDTH)'. */
4048 && EQ (XCAR (spec
), Qspace_width
)
4049 && CONSP (XCDR (spec
)))
4051 if (!FRAME_WINDOW_P (it
->f
))
4054 value
= XCAR (XCDR (spec
));
4055 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4056 it
->space_width
= value
;
4061 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4063 && EQ (XCAR (spec
), Qslice
))
4067 if (!FRAME_WINDOW_P (it
->f
))
4070 if (tem
= XCDR (spec
), CONSP (tem
))
4072 it
->slice
.x
= XCAR (tem
);
4073 if (tem
= XCDR (tem
), CONSP (tem
))
4075 it
->slice
.y
= XCAR (tem
);
4076 if (tem
= XCDR (tem
), CONSP (tem
))
4078 it
->slice
.width
= XCAR (tem
);
4079 if (tem
= XCDR (tem
), CONSP (tem
))
4080 it
->slice
.height
= XCAR (tem
);
4088 /* Handle `(raise FACTOR)'. */
4090 && EQ (XCAR (spec
), Qraise
)
4091 && CONSP (XCDR (spec
)))
4093 if (!FRAME_WINDOW_P (it
->f
))
4096 #ifdef HAVE_WINDOW_SYSTEM
4097 value
= XCAR (XCDR (spec
));
4098 if (NUMBERP (value
))
4100 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4101 it
->voffset
= - (XFLOATINT (value
)
4102 * (FONT_HEIGHT (face
->font
)));
4104 #endif /* HAVE_WINDOW_SYSTEM */
4109 /* Don't handle the other kinds of display specifications
4110 inside a string that we got from a `display' property. */
4111 if (it
->string_from_display_prop_p
)
4114 /* Characters having this form of property are not displayed, so
4115 we have to find the end of the property. */
4116 start_pos
= *position
;
4117 *position
= display_prop_end (it
, object
, start_pos
);
4120 /* Stop the scan at that end position--we assume that all
4121 text properties change there. */
4122 it
->stop_charpos
= position
->charpos
;
4124 /* Handle `(left-fringe BITMAP [FACE])'
4125 and `(right-fringe BITMAP [FACE])'. */
4127 && (EQ (XCAR (spec
), Qleft_fringe
)
4128 || EQ (XCAR (spec
), Qright_fringe
))
4129 && CONSP (XCDR (spec
)))
4131 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4134 if (!FRAME_WINDOW_P (it
->f
))
4135 /* If we return here, POSITION has been advanced
4136 across the text with this property. */
4139 #ifdef HAVE_WINDOW_SYSTEM
4140 value
= XCAR (XCDR (spec
));
4141 if (!SYMBOLP (value
)
4142 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4143 /* If we return here, POSITION has been advanced
4144 across the text with this property. */
4147 if (CONSP (XCDR (XCDR (spec
))))
4149 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4150 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4156 /* Save current settings of IT so that we can restore them
4157 when we are finished with the glyph property value. */
4159 save_pos
= it
->position
;
4160 it
->position
= *position
;
4162 it
->position
= save_pos
;
4164 it
->area
= TEXT_AREA
;
4165 it
->what
= IT_IMAGE
;
4166 it
->image_id
= -1; /* no image */
4167 it
->position
= start_pos
;
4168 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4169 it
->method
= GET_FROM_IMAGE
;
4170 it
->from_overlay
= Qnil
;
4171 it
->face_id
= face_id
;
4173 /* Say that we haven't consumed the characters with
4174 `display' property yet. The call to pop_it in
4175 set_iterator_to_next will clean this up. */
4176 *position
= start_pos
;
4178 if (EQ (XCAR (spec
), Qleft_fringe
))
4180 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4181 it
->left_user_fringe_face_id
= face_id
;
4185 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4186 it
->right_user_fringe_face_id
= face_id
;
4188 #endif /* HAVE_WINDOW_SYSTEM */
4192 /* Prepare to handle `((margin left-margin) ...)',
4193 `((margin right-margin) ...)' and `((margin nil) ...)'
4194 prefixes for display specifications. */
4195 location
= Qunbound
;
4196 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4200 value
= XCDR (spec
);
4202 value
= XCAR (value
);
4205 if (EQ (XCAR (tem
), Qmargin
)
4206 && (tem
= XCDR (tem
),
4207 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4209 || EQ (tem
, Qleft_margin
)
4210 || EQ (tem
, Qright_margin
))))
4214 if (EQ (location
, Qunbound
))
4220 /* After this point, VALUE is the property after any
4221 margin prefix has been stripped. It must be a string,
4222 an image specification, or `(space ...)'.
4224 LOCATION specifies where to display: `left-margin',
4225 `right-margin' or nil. */
4227 valid_p
= (STRINGP (value
)
4228 #ifdef HAVE_WINDOW_SYSTEM
4229 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4230 #endif /* not HAVE_WINDOW_SYSTEM */
4231 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4233 if (valid_p
&& !display_replaced_p
)
4235 /* Save current settings of IT so that we can restore them
4236 when we are finished with the glyph property value. */
4237 save_pos
= it
->position
;
4238 it
->position
= *position
;
4240 it
->position
= save_pos
;
4241 it
->from_overlay
= overlay
;
4243 if (NILP (location
))
4244 it
->area
= TEXT_AREA
;
4245 else if (EQ (location
, Qleft_margin
))
4246 it
->area
= LEFT_MARGIN_AREA
;
4248 it
->area
= RIGHT_MARGIN_AREA
;
4250 if (STRINGP (value
))
4253 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4254 it
->current
.overlay_string_index
= -1;
4255 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4256 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4257 it
->method
= GET_FROM_STRING
;
4258 it
->stop_charpos
= 0;
4259 it
->string_from_display_prop_p
= 1;
4260 /* Say that we haven't consumed the characters with
4261 `display' property yet. The call to pop_it in
4262 set_iterator_to_next will clean this up. */
4263 if (BUFFERP (object
))
4264 *position
= start_pos
;
4266 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4268 it
->method
= GET_FROM_STRETCH
;
4270 *position
= it
->position
= start_pos
;
4272 #ifdef HAVE_WINDOW_SYSTEM
4275 it
->what
= IT_IMAGE
;
4276 it
->image_id
= lookup_image (it
->f
, value
);
4277 it
->position
= start_pos
;
4278 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4279 it
->method
= GET_FROM_IMAGE
;
4281 /* Say that we haven't consumed the characters with
4282 `display' property yet. The call to pop_it in
4283 set_iterator_to_next will clean this up. */
4284 *position
= start_pos
;
4286 #endif /* HAVE_WINDOW_SYSTEM */
4291 /* Invalid property or property not supported. Restore
4292 POSITION to what it was before. */
4293 *position
= start_pos
;
4298 /* Check if SPEC is a display sub-property value whose text should be
4299 treated as intangible. */
4302 single_display_spec_intangible_p (Lisp_Object prop
)
4304 /* Skip over `when FORM'. */
4305 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4319 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4320 we don't need to treat text as intangible. */
4321 if (EQ (XCAR (prop
), Qmargin
))
4329 || EQ (XCAR (prop
), Qleft_margin
)
4330 || EQ (XCAR (prop
), Qright_margin
))
4334 return (CONSP (prop
)
4335 && (EQ (XCAR (prop
), Qimage
)
4336 || EQ (XCAR (prop
), Qspace
)));
4340 /* Check if PROP is a display property value whose text should be
4341 treated as intangible. */
4344 display_prop_intangible_p (Lisp_Object prop
)
4347 && CONSP (XCAR (prop
))
4348 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4350 /* A list of sub-properties. */
4351 while (CONSP (prop
))
4353 if (single_display_spec_intangible_p (XCAR (prop
)))
4358 else if (VECTORP (prop
))
4360 /* A vector of sub-properties. */
4362 for (i
= 0; i
< ASIZE (prop
); ++i
)
4363 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4367 return single_display_spec_intangible_p (prop
);
4373 /* Return 1 if PROP is a display sub-property value containing STRING. */
4376 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4378 if (EQ (string
, prop
))
4381 /* Skip over `when FORM'. */
4382 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4391 /* Skip over `margin LOCATION'. */
4392 if (EQ (XCAR (prop
), Qmargin
))
4403 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4407 /* Return 1 if STRING appears in the `display' property PROP. */
4410 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4413 && CONSP (XCAR (prop
))
4414 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4416 /* A list of sub-properties. */
4417 while (CONSP (prop
))
4419 if (single_display_spec_string_p (XCAR (prop
), string
))
4424 else if (VECTORP (prop
))
4426 /* A vector of sub-properties. */
4428 for (i
= 0; i
< ASIZE (prop
); ++i
)
4429 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4433 return single_display_spec_string_p (prop
, string
);
4438 /* Look for STRING in overlays and text properties in the current
4439 buffer, between character positions FROM and TO (excluding TO).
4440 BACK_P non-zero means look back (in this case, TO is supposed to be
4442 Value is the first character position where STRING was found, or
4443 zero if it wasn't found before hitting TO.
4445 This function may only use code that doesn't eval because it is
4446 called asynchronously from note_mouse_highlight. */
4449 string_buffer_position_lim (Lisp_Object string
,
4450 EMACS_INT from
, EMACS_INT to
, int back_p
)
4452 Lisp_Object limit
, prop
, pos
;
4455 pos
= make_number (from
);
4457 if (!back_p
) /* looking forward */
4459 limit
= make_number (min (to
, ZV
));
4460 while (!found
&& !EQ (pos
, limit
))
4462 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4463 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4466 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4470 else /* looking back */
4472 limit
= make_number (max (to
, BEGV
));
4473 while (!found
&& !EQ (pos
, limit
))
4475 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4476 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4479 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4484 return found
? XINT (pos
) : 0;
4487 /* Determine which buffer position in current buffer STRING comes from.
4488 AROUND_CHARPOS is an approximate position where it could come from.
4489 Value is the buffer position or 0 if it couldn't be determined.
4491 This function is necessary because we don't record buffer positions
4492 in glyphs generated from strings (to keep struct glyph small).
4493 This function may only use code that doesn't eval because it is
4494 called asynchronously from note_mouse_highlight. */
4497 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4499 const int MAX_DISTANCE
= 1000;
4500 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4501 around_charpos
+ MAX_DISTANCE
,
4505 found
= string_buffer_position_lim (string
, around_charpos
,
4506 around_charpos
- MAX_DISTANCE
, 1);
4512 /***********************************************************************
4513 `composition' property
4514 ***********************************************************************/
4516 /* Set up iterator IT from `composition' property at its current
4517 position. Called from handle_stop. */
4519 static enum prop_handled
4520 handle_composition_prop (struct it
*it
)
4522 Lisp_Object prop
, string
;
4523 EMACS_INT pos
, pos_byte
, start
, end
;
4525 if (STRINGP (it
->string
))
4529 pos
= IT_STRING_CHARPOS (*it
);
4530 pos_byte
= IT_STRING_BYTEPOS (*it
);
4531 string
= it
->string
;
4532 s
= SDATA (string
) + pos_byte
;
4533 it
->c
= STRING_CHAR (s
);
4537 pos
= IT_CHARPOS (*it
);
4538 pos_byte
= IT_BYTEPOS (*it
);
4540 it
->c
= FETCH_CHAR (pos_byte
);
4543 /* If there's a valid composition and point is not inside of the
4544 composition (in the case that the composition is from the current
4545 buffer), draw a glyph composed from the composition components. */
4546 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4547 && COMPOSITION_VALID_P (start
, end
, prop
)
4548 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4552 if (STRINGP (it
->string
))
4553 pos_byte
= string_char_to_byte (it
->string
, start
);
4555 pos_byte
= CHAR_TO_BYTE (start
);
4557 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4560 if (it
->cmp_it
.id
>= 0)
4563 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4564 it
->cmp_it
.nglyphs
= -1;
4568 return HANDLED_NORMALLY
;
4573 /***********************************************************************
4575 ***********************************************************************/
4577 /* The following structure is used to record overlay strings for
4578 later sorting in load_overlay_strings. */
4580 struct overlay_entry
4582 Lisp_Object overlay
;
4589 /* Set up iterator IT from overlay strings at its current position.
4590 Called from handle_stop. */
4592 static enum prop_handled
4593 handle_overlay_change (struct it
*it
)
4595 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4596 return HANDLED_RECOMPUTE_PROPS
;
4598 return HANDLED_NORMALLY
;
4602 /* Set up the next overlay string for delivery by IT, if there is an
4603 overlay string to deliver. Called by set_iterator_to_next when the
4604 end of the current overlay string is reached. If there are more
4605 overlay strings to display, IT->string and
4606 IT->current.overlay_string_index are set appropriately here.
4607 Otherwise IT->string is set to nil. */
4610 next_overlay_string (struct it
*it
)
4612 ++it
->current
.overlay_string_index
;
4613 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4615 /* No more overlay strings. Restore IT's settings to what
4616 they were before overlay strings were processed, and
4617 continue to deliver from current_buffer. */
4619 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4622 || (NILP (it
->string
)
4623 && it
->method
== GET_FROM_BUFFER
4624 && it
->stop_charpos
>= BEGV
4625 && it
->stop_charpos
<= it
->end_charpos
));
4626 it
->current
.overlay_string_index
= -1;
4627 it
->n_overlay_strings
= 0;
4628 it
->overlay_strings_charpos
= -1;
4630 /* If we're at the end of the buffer, record that we have
4631 processed the overlay strings there already, so that
4632 next_element_from_buffer doesn't try it again. */
4633 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4634 it
->overlay_strings_at_end_processed_p
= 1;
4638 /* There are more overlay strings to process. If
4639 IT->current.overlay_string_index has advanced to a position
4640 where we must load IT->overlay_strings with more strings, do
4641 it. We must load at the IT->overlay_strings_charpos where
4642 IT->n_overlay_strings was originally computed; when invisible
4643 text is present, this might not be IT_CHARPOS (Bug#7016). */
4644 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4646 if (it
->current
.overlay_string_index
&& i
== 0)
4647 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4649 /* Initialize IT to deliver display elements from the overlay
4651 it
->string
= it
->overlay_strings
[i
];
4652 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4653 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4654 it
->method
= GET_FROM_STRING
;
4655 it
->stop_charpos
= 0;
4656 if (it
->cmp_it
.stop_pos
>= 0)
4657 it
->cmp_it
.stop_pos
= 0;
4664 /* Compare two overlay_entry structures E1 and E2. Used as a
4665 comparison function for qsort in load_overlay_strings. Overlay
4666 strings for the same position are sorted so that
4668 1. All after-strings come in front of before-strings, except
4669 when they come from the same overlay.
4671 2. Within after-strings, strings are sorted so that overlay strings
4672 from overlays with higher priorities come first.
4674 2. Within before-strings, strings are sorted so that overlay
4675 strings from overlays with higher priorities come last.
4677 Value is analogous to strcmp. */
4681 compare_overlay_entries (const void *e1
, const void *e2
)
4683 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4684 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4687 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4689 /* Let after-strings appear in front of before-strings if
4690 they come from different overlays. */
4691 if (EQ (entry1
->overlay
, entry2
->overlay
))
4692 result
= entry1
->after_string_p
? 1 : -1;
4694 result
= entry1
->after_string_p
? -1 : 1;
4696 else if (entry1
->after_string_p
)
4697 /* After-strings sorted in order of decreasing priority. */
4698 result
= entry2
->priority
- entry1
->priority
;
4700 /* Before-strings sorted in order of increasing priority. */
4701 result
= entry1
->priority
- entry2
->priority
;
4707 /* Load the vector IT->overlay_strings with overlay strings from IT's
4708 current buffer position, or from CHARPOS if that is > 0. Set
4709 IT->n_overlays to the total number of overlay strings found.
4711 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4712 a time. On entry into load_overlay_strings,
4713 IT->current.overlay_string_index gives the number of overlay
4714 strings that have already been loaded by previous calls to this
4717 IT->add_overlay_start contains an additional overlay start
4718 position to consider for taking overlay strings from, if non-zero.
4719 This position comes into play when the overlay has an `invisible'
4720 property, and both before and after-strings. When we've skipped to
4721 the end of the overlay, because of its `invisible' property, we
4722 nevertheless want its before-string to appear.
4723 IT->add_overlay_start will contain the overlay start position
4726 Overlay strings are sorted so that after-string strings come in
4727 front of before-string strings. Within before and after-strings,
4728 strings are sorted by overlay priority. See also function
4729 compare_overlay_entries. */
4732 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4734 Lisp_Object overlay
, window
, str
, invisible
;
4735 struct Lisp_Overlay
*ov
;
4736 EMACS_INT start
, end
;
4738 int n
= 0, i
, j
, invis_p
;
4739 struct overlay_entry
*entries
4740 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4743 charpos
= IT_CHARPOS (*it
);
4745 /* Append the overlay string STRING of overlay OVERLAY to vector
4746 `entries' which has size `size' and currently contains `n'
4747 elements. AFTER_P non-zero means STRING is an after-string of
4749 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4752 Lisp_Object priority; \
4756 int new_size = 2 * size; \
4757 struct overlay_entry *old = entries; \
4759 (struct overlay_entry *) alloca (new_size \
4760 * sizeof *entries); \
4761 memcpy (entries, old, size * sizeof *entries); \
4765 entries[n].string = (STRING); \
4766 entries[n].overlay = (OVERLAY); \
4767 priority = Foverlay_get ((OVERLAY), Qpriority); \
4768 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4769 entries[n].after_string_p = (AFTER_P); \
4774 /* Process overlay before the overlay center. */
4775 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4777 XSETMISC (overlay
, ov
);
4778 xassert (OVERLAYP (overlay
));
4779 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4780 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4785 /* Skip this overlay if it doesn't start or end at IT's current
4787 if (end
!= charpos
&& start
!= charpos
)
4790 /* Skip this overlay if it doesn't apply to IT->w. */
4791 window
= Foverlay_get (overlay
, Qwindow
);
4792 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4795 /* If the text ``under'' the overlay is invisible, both before-
4796 and after-strings from this overlay are visible; start and
4797 end position are indistinguishable. */
4798 invisible
= Foverlay_get (overlay
, Qinvisible
);
4799 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4801 /* If overlay has a non-empty before-string, record it. */
4802 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4803 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4805 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4807 /* If overlay has a non-empty after-string, record it. */
4808 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4809 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4811 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4814 /* Process overlays after the overlay center. */
4815 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4817 XSETMISC (overlay
, ov
);
4818 xassert (OVERLAYP (overlay
));
4819 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4820 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4822 if (start
> charpos
)
4825 /* Skip this overlay if it doesn't start or end at IT's current
4827 if (end
!= charpos
&& start
!= charpos
)
4830 /* Skip this overlay if it doesn't apply to IT->w. */
4831 window
= Foverlay_get (overlay
, Qwindow
);
4832 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4835 /* If the text ``under'' the overlay is invisible, it has a zero
4836 dimension, and both before- and after-strings apply. */
4837 invisible
= Foverlay_get (overlay
, Qinvisible
);
4838 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4840 /* If overlay has a non-empty before-string, record it. */
4841 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4842 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4844 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4846 /* If overlay has a non-empty after-string, record it. */
4847 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4848 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4850 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4853 #undef RECORD_OVERLAY_STRING
4857 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4859 /* Record number of overlay strings, and where we computed it. */
4860 it
->n_overlay_strings
= n
;
4861 it
->overlay_strings_charpos
= charpos
;
4863 /* IT->current.overlay_string_index is the number of overlay strings
4864 that have already been consumed by IT. Copy some of the
4865 remaining overlay strings to IT->overlay_strings. */
4867 j
= it
->current
.overlay_string_index
;
4868 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4870 it
->overlay_strings
[i
] = entries
[j
].string
;
4871 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4878 /* Get the first chunk of overlay strings at IT's current buffer
4879 position, or at CHARPOS if that is > 0. Value is non-zero if at
4880 least one overlay string was found. */
4883 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
4885 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4886 process. This fills IT->overlay_strings with strings, and sets
4887 IT->n_overlay_strings to the total number of strings to process.
4888 IT->pos.overlay_string_index has to be set temporarily to zero
4889 because load_overlay_strings needs this; it must be set to -1
4890 when no overlay strings are found because a zero value would
4891 indicate a position in the first overlay string. */
4892 it
->current
.overlay_string_index
= 0;
4893 load_overlay_strings (it
, charpos
);
4895 /* If we found overlay strings, set up IT to deliver display
4896 elements from the first one. Otherwise set up IT to deliver
4897 from current_buffer. */
4898 if (it
->n_overlay_strings
)
4900 /* Make sure we know settings in current_buffer, so that we can
4901 restore meaningful values when we're done with the overlay
4904 compute_stop_pos (it
);
4905 xassert (it
->face_id
>= 0);
4907 /* Save IT's settings. They are restored after all overlay
4908 strings have been processed. */
4909 xassert (!compute_stop_p
|| it
->sp
== 0);
4911 /* When called from handle_stop, there might be an empty display
4912 string loaded. In that case, don't bother saving it. */
4913 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
4916 /* Set up IT to deliver display elements from the first overlay
4918 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4919 it
->string
= it
->overlay_strings
[0];
4920 it
->from_overlay
= Qnil
;
4921 it
->stop_charpos
= 0;
4922 xassert (STRINGP (it
->string
));
4923 it
->end_charpos
= SCHARS (it
->string
);
4924 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4925 it
->method
= GET_FROM_STRING
;
4929 it
->current
.overlay_string_index
= -1;
4934 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4937 it
->method
= GET_FROM_BUFFER
;
4939 (void) get_overlay_strings_1 (it
, charpos
, 1);
4943 /* Value is non-zero if we found at least one overlay string. */
4944 return STRINGP (it
->string
);
4949 /***********************************************************************
4950 Saving and restoring state
4951 ***********************************************************************/
4953 /* Save current settings of IT on IT->stack. Called, for example,
4954 before setting up IT for an overlay string, to be able to restore
4955 IT's settings to what they were after the overlay string has been
4959 push_it (struct it
*it
)
4961 struct iterator_stack_entry
*p
;
4963 xassert (it
->sp
< IT_STACK_SIZE
);
4964 p
= it
->stack
+ it
->sp
;
4966 p
->stop_charpos
= it
->stop_charpos
;
4967 p
->prev_stop
= it
->prev_stop
;
4968 p
->base_level_stop
= it
->base_level_stop
;
4969 p
->cmp_it
= it
->cmp_it
;
4970 xassert (it
->face_id
>= 0);
4971 p
->face_id
= it
->face_id
;
4972 p
->string
= it
->string
;
4973 p
->method
= it
->method
;
4974 p
->from_overlay
= it
->from_overlay
;
4977 case GET_FROM_IMAGE
:
4978 p
->u
.image
.object
= it
->object
;
4979 p
->u
.image
.image_id
= it
->image_id
;
4980 p
->u
.image
.slice
= it
->slice
;
4982 case GET_FROM_STRETCH
:
4983 p
->u
.stretch
.object
= it
->object
;
4986 p
->position
= it
->position
;
4987 p
->current
= it
->current
;
4988 p
->end_charpos
= it
->end_charpos
;
4989 p
->string_nchars
= it
->string_nchars
;
4991 p
->multibyte_p
= it
->multibyte_p
;
4992 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
4993 p
->space_width
= it
->space_width
;
4994 p
->font_height
= it
->font_height
;
4995 p
->voffset
= it
->voffset
;
4996 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4997 p
->display_ellipsis_p
= 0;
4998 p
->line_wrap
= it
->line_wrap
;
5003 iterate_out_of_display_property (struct it
*it
)
5005 /* Maybe initialize paragraph direction. If we are at the beginning
5006 of a new paragraph, next_element_from_buffer may not have a
5007 chance to do that. */
5008 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5009 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5010 /* prev_stop can be zero, so check against BEGV as well. */
5011 while (it
->bidi_it
.charpos
>= BEGV
5012 && it
->prev_stop
<= it
->bidi_it
.charpos
5013 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5014 bidi_move_to_visually_next (&it
->bidi_it
);
5015 /* Record the stop_pos we just crossed, for when we cross it
5017 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5018 it
->prev_stop
= CHARPOS (it
->position
);
5019 /* If we ended up not where pop_it put us, resync IT's
5020 positional members with the bidi iterator. */
5021 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5023 SET_TEXT_POS (it
->position
,
5024 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5025 it
->current
.pos
= it
->position
;
5029 /* Restore IT's settings from IT->stack. Called, for example, when no
5030 more overlay strings must be processed, and we return to delivering
5031 display elements from a buffer, or when the end of a string from a
5032 `display' property is reached and we return to delivering display
5033 elements from an overlay string, or from a buffer. */
5036 pop_it (struct it
*it
)
5038 struct iterator_stack_entry
*p
;
5040 xassert (it
->sp
> 0);
5042 p
= it
->stack
+ it
->sp
;
5043 it
->stop_charpos
= p
->stop_charpos
;
5044 it
->prev_stop
= p
->prev_stop
;
5045 it
->base_level_stop
= p
->base_level_stop
;
5046 it
->cmp_it
= p
->cmp_it
;
5047 it
->face_id
= p
->face_id
;
5048 it
->current
= p
->current
;
5049 it
->position
= p
->position
;
5050 it
->string
= p
->string
;
5051 it
->from_overlay
= p
->from_overlay
;
5052 if (NILP (it
->string
))
5053 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5054 it
->method
= p
->method
;
5057 case GET_FROM_IMAGE
:
5058 it
->image_id
= p
->u
.image
.image_id
;
5059 it
->object
= p
->u
.image
.object
;
5060 it
->slice
= p
->u
.image
.slice
;
5062 case GET_FROM_STRETCH
:
5063 it
->object
= p
->u
.comp
.object
;
5065 case GET_FROM_BUFFER
:
5066 it
->object
= it
->w
->buffer
;
5069 /* Bidi-iterate until we get out of the portion of text, if
5070 any, covered by a `display' text property or an overlay
5071 with `display' property. (We cannot just jump there,
5072 because the internal coherency of the bidi iterator state
5073 can not be preserved across such jumps.) We also must
5074 determine the paragraph base direction if the overlay we
5075 just processed is at the beginning of a new
5077 iterate_out_of_display_property (it
);
5080 case GET_FROM_STRING
:
5081 it
->object
= it
->string
;
5083 case GET_FROM_DISPLAY_VECTOR
:
5085 it
->method
= GET_FROM_C_STRING
;
5086 else if (STRINGP (it
->string
))
5087 it
->method
= GET_FROM_STRING
;
5090 it
->method
= GET_FROM_BUFFER
;
5091 it
->object
= it
->w
->buffer
;
5094 it
->end_charpos
= p
->end_charpos
;
5095 it
->string_nchars
= p
->string_nchars
;
5097 it
->multibyte_p
= p
->multibyte_p
;
5098 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5099 it
->space_width
= p
->space_width
;
5100 it
->font_height
= p
->font_height
;
5101 it
->voffset
= p
->voffset
;
5102 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5103 it
->line_wrap
= p
->line_wrap
;
5108 /***********************************************************************
5110 ***********************************************************************/
5112 /* Set IT's current position to the previous line start. */
5115 back_to_previous_line_start (struct it
*it
)
5117 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5118 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5122 /* Move IT to the next line start.
5124 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5125 we skipped over part of the text (as opposed to moving the iterator
5126 continuously over the text). Otherwise, don't change the value
5129 Newlines may come from buffer text, overlay strings, or strings
5130 displayed via the `display' property. That's the reason we can't
5131 simply use find_next_newline_no_quit.
5133 Note that this function may not skip over invisible text that is so
5134 because of text properties and immediately follows a newline. If
5135 it would, function reseat_at_next_visible_line_start, when called
5136 from set_iterator_to_next, would effectively make invisible
5137 characters following a newline part of the wrong glyph row, which
5138 leads to wrong cursor motion. */
5141 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5143 int old_selective
, newline_found_p
, n
;
5144 const int MAX_NEWLINE_DISTANCE
= 500;
5146 /* If already on a newline, just consume it to avoid unintended
5147 skipping over invisible text below. */
5148 if (it
->what
== IT_CHARACTER
5150 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5152 set_iterator_to_next (it
, 0);
5157 /* Don't handle selective display in the following. It's (a)
5158 unnecessary because it's done by the caller, and (b) leads to an
5159 infinite recursion because next_element_from_ellipsis indirectly
5160 calls this function. */
5161 old_selective
= it
->selective
;
5164 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5165 from buffer text. */
5166 for (n
= newline_found_p
= 0;
5167 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5168 n
+= STRINGP (it
->string
) ? 0 : 1)
5170 if (!get_next_display_element (it
))
5172 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5173 set_iterator_to_next (it
, 0);
5176 /* If we didn't find a newline near enough, see if we can use a
5178 if (!newline_found_p
)
5180 EMACS_INT start
= IT_CHARPOS (*it
);
5181 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5184 xassert (!STRINGP (it
->string
));
5186 /* If there isn't any `display' property in sight, and no
5187 overlays, we can just use the position of the newline in
5189 if (it
->stop_charpos
>= limit
5190 || ((pos
= Fnext_single_property_change (make_number (start
),
5192 Qnil
, make_number (limit
)),
5194 && next_overlay_change (start
) == ZV
))
5196 IT_CHARPOS (*it
) = limit
;
5197 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5198 *skipped_p
= newline_found_p
= 1;
5202 while (get_next_display_element (it
)
5203 && !newline_found_p
)
5205 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5206 set_iterator_to_next (it
, 0);
5211 it
->selective
= old_selective
;
5212 return newline_found_p
;
5216 /* Set IT's current position to the previous visible line start. Skip
5217 invisible text that is so either due to text properties or due to
5218 selective display. Caution: this does not change IT->current_x and
5222 back_to_previous_visible_line_start (struct it
*it
)
5224 while (IT_CHARPOS (*it
) > BEGV
)
5226 back_to_previous_line_start (it
);
5228 if (IT_CHARPOS (*it
) <= BEGV
)
5231 /* If selective > 0, then lines indented more than its value are
5233 if (it
->selective
> 0
5234 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5235 (double) it
->selective
)) /* iftc */
5238 /* Check the newline before point for invisibility. */
5241 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5242 Qinvisible
, it
->window
);
5243 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5247 if (IT_CHARPOS (*it
) <= BEGV
)
5254 Lisp_Object val
, overlay
;
5256 /* If newline is part of a composition, continue from start of composition */
5257 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5258 && beg
< IT_CHARPOS (*it
))
5261 /* If newline is replaced by a display property, find start of overlay
5262 or interval and continue search from that point. */
5264 pos
= --IT_CHARPOS (it2
);
5267 it2
.string_from_display_prop_p
= 0;
5268 if (handle_display_prop (&it2
) == HANDLED_RETURN
5269 && !NILP (val
= get_char_property_and_overlay
5270 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5271 && (OVERLAYP (overlay
)
5272 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5273 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5276 /* Newline is not replaced by anything -- so we are done. */
5282 IT_CHARPOS (*it
) = beg
;
5283 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5287 it
->continuation_lines_width
= 0;
5289 xassert (IT_CHARPOS (*it
) >= BEGV
);
5290 xassert (IT_CHARPOS (*it
) == BEGV
5291 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5296 /* Reseat iterator IT at the previous visible line start. Skip
5297 invisible text that is so either due to text properties or due to
5298 selective display. At the end, update IT's overlay information,
5299 face information etc. */
5302 reseat_at_previous_visible_line_start (struct it
*it
)
5304 back_to_previous_visible_line_start (it
);
5305 reseat (it
, it
->current
.pos
, 1);
5310 /* Reseat iterator IT on the next visible line start in the current
5311 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5312 preceding the line start. Skip over invisible text that is so
5313 because of selective display. Compute faces, overlays etc at the
5314 new position. Note that this function does not skip over text that
5315 is invisible because of text properties. */
5318 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5320 int newline_found_p
, skipped_p
= 0;
5322 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5324 /* Skip over lines that are invisible because they are indented
5325 more than the value of IT->selective. */
5326 if (it
->selective
> 0)
5327 while (IT_CHARPOS (*it
) < ZV
5328 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5329 (double) it
->selective
)) /* iftc */
5331 xassert (IT_BYTEPOS (*it
) == BEGV
5332 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5333 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5336 /* Position on the newline if that's what's requested. */
5337 if (on_newline_p
&& newline_found_p
)
5339 if (STRINGP (it
->string
))
5341 if (IT_STRING_CHARPOS (*it
) > 0)
5343 --IT_STRING_CHARPOS (*it
);
5344 --IT_STRING_BYTEPOS (*it
);
5347 else if (IT_CHARPOS (*it
) > BEGV
)
5351 reseat (it
, it
->current
.pos
, 0);
5355 reseat (it
, it
->current
.pos
, 0);
5362 /***********************************************************************
5363 Changing an iterator's position
5364 ***********************************************************************/
5366 /* Change IT's current position to POS in current_buffer. If FORCE_P
5367 is non-zero, always check for text properties at the new position.
5368 Otherwise, text properties are only looked up if POS >=
5369 IT->check_charpos of a property. */
5372 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5374 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5376 reseat_1 (it
, pos
, 0);
5378 /* Determine where to check text properties. Avoid doing it
5379 where possible because text property lookup is very expensive. */
5381 || CHARPOS (pos
) > it
->stop_charpos
5382 || CHARPOS (pos
) < original_pos
)
5386 /* For bidi iteration, we need to prime prev_stop and
5387 base_level_stop with our best estimations. */
5388 if (CHARPOS (pos
) < it
->prev_stop
)
5390 handle_stop_backwards (it
, BEGV
);
5391 if (CHARPOS (pos
) < it
->base_level_stop
)
5392 it
->base_level_stop
= 0;
5394 else if (CHARPOS (pos
) > it
->stop_charpos
5395 && it
->stop_charpos
>= BEGV
)
5396 handle_stop_backwards (it
, it
->stop_charpos
);
5403 it
->prev_stop
= it
->base_level_stop
= 0;
5412 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5413 IT->stop_pos to POS, also. */
5416 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5418 /* Don't call this function when scanning a C string. */
5419 xassert (it
->s
== NULL
);
5421 /* POS must be a reasonable value. */
5422 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5424 it
->current
.pos
= it
->position
= pos
;
5425 it
->end_charpos
= ZV
;
5427 it
->current
.dpvec_index
= -1;
5428 it
->current
.overlay_string_index
= -1;
5429 IT_STRING_CHARPOS (*it
) = -1;
5430 IT_STRING_BYTEPOS (*it
) = -1;
5432 it
->string_from_display_prop_p
= 0;
5433 it
->method
= GET_FROM_BUFFER
;
5434 it
->object
= it
->w
->buffer
;
5435 it
->area
= TEXT_AREA
;
5436 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5438 it
->string_from_display_prop_p
= 0;
5439 it
->face_before_selective_p
= 0;
5442 it
->bidi_it
.first_elt
= 1;
5443 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5444 it
->bidi_it
.disp_pos
= -1;
5449 it
->stop_charpos
= CHARPOS (pos
);
5450 it
->base_level_stop
= CHARPOS (pos
);
5455 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5456 If S is non-null, it is a C string to iterate over. Otherwise,
5457 STRING gives a Lisp string to iterate over.
5459 If PRECISION > 0, don't return more then PRECISION number of
5460 characters from the string.
5462 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5463 characters have been returned. FIELD_WIDTH < 0 means an infinite
5466 MULTIBYTE = 0 means disable processing of multibyte characters,
5467 MULTIBYTE > 0 means enable it,
5468 MULTIBYTE < 0 means use IT->multibyte_p.
5470 IT must be initialized via a prior call to init_iterator before
5471 calling this function. */
5474 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5475 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5478 /* No region in strings. */
5479 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5481 /* No text property checks performed by default, but see below. */
5482 it
->stop_charpos
= -1;
5484 /* Set iterator position and end position. */
5485 memset (&it
->current
, 0, sizeof it
->current
);
5486 it
->current
.overlay_string_index
= -1;
5487 it
->current
.dpvec_index
= -1;
5488 xassert (charpos
>= 0);
5490 /* If STRING is specified, use its multibyteness, otherwise use the
5491 setting of MULTIBYTE, if specified. */
5493 it
->multibyte_p
= multibyte
> 0;
5497 xassert (STRINGP (string
));
5498 it
->string
= string
;
5500 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5501 it
->method
= GET_FROM_STRING
;
5502 it
->current
.string_pos
= string_pos (charpos
, string
);
5506 it
->s
= (const unsigned char *) s
;
5509 /* Note that we use IT->current.pos, not it->current.string_pos,
5510 for displaying C strings. */
5511 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5512 if (it
->multibyte_p
)
5514 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5515 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5519 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5520 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5523 it
->method
= GET_FROM_C_STRING
;
5526 /* PRECISION > 0 means don't return more than PRECISION characters
5528 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5529 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5531 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5532 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5533 FIELD_WIDTH < 0 means infinite field width. This is useful for
5534 padding with `-' at the end of a mode line. */
5535 if (field_width
< 0)
5536 field_width
= INFINITY
;
5537 if (field_width
> it
->end_charpos
- charpos
)
5538 it
->end_charpos
= charpos
+ field_width
;
5540 /* Use the standard display table for displaying strings. */
5541 if (DISP_TABLE_P (Vstandard_display_table
))
5542 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5544 it
->stop_charpos
= charpos
;
5545 if (s
== NULL
&& it
->multibyte_p
)
5547 EMACS_INT endpos
= SCHARS (it
->string
);
5548 if (endpos
> it
->end_charpos
)
5549 endpos
= it
->end_charpos
;
5550 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5558 /***********************************************************************
5560 ***********************************************************************/
5562 /* Map enum it_method value to corresponding next_element_from_* function. */
5564 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5566 next_element_from_buffer
,
5567 next_element_from_display_vector
,
5568 next_element_from_string
,
5569 next_element_from_c_string
,
5570 next_element_from_image
,
5571 next_element_from_stretch
5574 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5577 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5578 (possibly with the following characters). */
5580 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5581 ((IT)->cmp_it.id >= 0 \
5582 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5583 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5584 END_CHARPOS, (IT)->w, \
5585 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5589 /* Lookup the char-table Vglyphless_char_display for character C (-1
5590 if we want information for no-font case), and return the display
5591 method symbol. By side-effect, update it->what and
5592 it->glyphless_method. This function is called from
5593 get_next_display_element for each character element, and from
5594 x_produce_glyphs when no suitable font was found. */
5597 lookup_glyphless_char_display (int c
, struct it
*it
)
5599 Lisp_Object glyphless_method
= Qnil
;
5601 if (CHAR_TABLE_P (Vglyphless_char_display
)
5602 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5606 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5607 if (CONSP (glyphless_method
))
5608 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5609 ? XCAR (glyphless_method
)
5610 : XCDR (glyphless_method
);
5613 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5617 if (NILP (glyphless_method
))
5620 /* The default is to display the character by a proper font. */
5622 /* The default for the no-font case is to display an empty box. */
5623 glyphless_method
= Qempty_box
;
5625 if (EQ (glyphless_method
, Qzero_width
))
5628 return glyphless_method
;
5629 /* This method can't be used for the no-font case. */
5630 glyphless_method
= Qempty_box
;
5632 if (EQ (glyphless_method
, Qthin_space
))
5633 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5634 else if (EQ (glyphless_method
, Qempty_box
))
5635 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5636 else if (EQ (glyphless_method
, Qhex_code
))
5637 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5638 else if (STRINGP (glyphless_method
))
5639 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5642 /* Invalid value. We use the default method. */
5643 glyphless_method
= Qnil
;
5646 it
->what
= IT_GLYPHLESS
;
5647 return glyphless_method
;
5650 /* Load IT's display element fields with information about the next
5651 display element from the current position of IT. Value is zero if
5652 end of buffer (or C string) is reached. */
5654 static struct frame
*last_escape_glyph_frame
= NULL
;
5655 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5656 static int last_escape_glyph_merged_face_id
= 0;
5658 struct frame
*last_glyphless_glyph_frame
= NULL
;
5659 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5660 int last_glyphless_glyph_merged_face_id
= 0;
5663 get_next_display_element (struct it
*it
)
5665 /* Non-zero means that we found a display element. Zero means that
5666 we hit the end of what we iterate over. Performance note: the
5667 function pointer `method' used here turns out to be faster than
5668 using a sequence of if-statements. */
5672 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5674 if (it
->what
== IT_CHARACTER
)
5676 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5677 and only if (a) the resolved directionality of that character
5679 /* FIXME: Do we need an exception for characters from display
5681 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5682 it
->c
= bidi_mirror_char (it
->c
);
5683 /* Map via display table or translate control characters.
5684 IT->c, IT->len etc. have been set to the next character by
5685 the function call above. If we have a display table, and it
5686 contains an entry for IT->c, translate it. Don't do this if
5687 IT->c itself comes from a display table, otherwise we could
5688 end up in an infinite recursion. (An alternative could be to
5689 count the recursion depth of this function and signal an
5690 error when a certain maximum depth is reached.) Is it worth
5692 if (success_p
&& it
->dpvec
== NULL
)
5695 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5696 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5697 nbsp_or_shy
= char_is_other
;
5698 int c
= it
->c
; /* This is the character to display. */
5700 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5702 xassert (SINGLE_BYTE_CHAR_P (c
));
5703 if (unibyte_display_via_language_environment
)
5705 c
= DECODE_CHAR (unibyte
, c
);
5707 c
= BYTE8_TO_CHAR (it
->c
);
5710 c
= BYTE8_TO_CHAR (it
->c
);
5714 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5717 struct Lisp_Vector
*v
= XVECTOR (dv
);
5719 /* Return the first character from the display table
5720 entry, if not empty. If empty, don't display the
5721 current character. */
5724 it
->dpvec_char_len
= it
->len
;
5725 it
->dpvec
= v
->contents
;
5726 it
->dpend
= v
->contents
+ v
->header
.size
;
5727 it
->current
.dpvec_index
= 0;
5728 it
->dpvec_face_id
= -1;
5729 it
->saved_face_id
= it
->face_id
;
5730 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5735 set_iterator_to_next (it
, 0);
5740 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5742 if (it
->what
== IT_GLYPHLESS
)
5744 /* Don't display this character. */
5745 set_iterator_to_next (it
, 0);
5749 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5750 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5751 : c
== 0xAD ? char_is_soft_hyphen
5754 /* Translate control characters into `\003' or `^C' form.
5755 Control characters coming from a display table entry are
5756 currently not translated because we use IT->dpvec to hold
5757 the translation. This could easily be changed but I
5758 don't believe that it is worth doing.
5760 NBSP and SOFT-HYPEN are property translated too.
5762 Non-printable characters and raw-byte characters are also
5763 translated to octal form. */
5764 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5765 ? (it
->area
!= TEXT_AREA
5766 /* In mode line, treat \n, \t like other crl chars. */
5769 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5770 || (c
!= '\n' && c
!= '\t'))
5773 || ! CHAR_PRINTABLE_P (c
))))
5775 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5776 or a non-printable character which must be displayed
5777 either as '\003' or as `^C' where the '\\' and '^'
5778 can be defined in the display table. Fill
5779 IT->ctl_chars with glyphs for what we have to
5780 display. Then, set IT->dpvec to these glyphs. */
5783 int face_id
, lface_id
= 0 ;
5786 /* Handle control characters with ^. */
5788 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5792 g
= '^'; /* default glyph for Control */
5793 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5795 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5796 && GLYPH_CODE_CHAR_VALID_P (gc
))
5798 g
= GLYPH_CODE_CHAR (gc
);
5799 lface_id
= GLYPH_CODE_FACE (gc
);
5803 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5805 else if (it
->f
== last_escape_glyph_frame
5806 && it
->face_id
== last_escape_glyph_face_id
)
5808 face_id
= last_escape_glyph_merged_face_id
;
5812 /* Merge the escape-glyph face into the current face. */
5813 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5815 last_escape_glyph_frame
= it
->f
;
5816 last_escape_glyph_face_id
= it
->face_id
;
5817 last_escape_glyph_merged_face_id
= face_id
;
5820 XSETINT (it
->ctl_chars
[0], g
);
5821 XSETINT (it
->ctl_chars
[1], c
^ 0100);
5823 goto display_control
;
5826 /* Handle non-break space in the mode where it only gets
5829 if (EQ (Vnobreak_char_display
, Qt
)
5830 && nbsp_or_shy
== char_is_nbsp
)
5832 /* Merge the no-break-space face into the current face. */
5833 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5837 XSETINT (it
->ctl_chars
[0], ' ');
5839 goto display_control
;
5842 /* Handle sequences that start with the "escape glyph". */
5844 /* the default escape glyph is \. */
5845 escape_glyph
= '\\';
5848 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5849 && GLYPH_CODE_CHAR_VALID_P (gc
))
5851 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5852 lface_id
= GLYPH_CODE_FACE (gc
);
5856 /* The display table specified a face.
5857 Merge it into face_id and also into escape_glyph. */
5858 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5861 else if (it
->f
== last_escape_glyph_frame
5862 && it
->face_id
== last_escape_glyph_face_id
)
5864 face_id
= last_escape_glyph_merged_face_id
;
5868 /* Merge the escape-glyph face into the current face. */
5869 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5871 last_escape_glyph_frame
= it
->f
;
5872 last_escape_glyph_face_id
= it
->face_id
;
5873 last_escape_glyph_merged_face_id
= face_id
;
5876 /* Handle soft hyphens in the mode where they only get
5879 if (EQ (Vnobreak_char_display
, Qt
)
5880 && nbsp_or_shy
== char_is_soft_hyphen
)
5882 XSETINT (it
->ctl_chars
[0], '-');
5884 goto display_control
;
5887 /* Handle non-break space and soft hyphen
5888 with the escape glyph. */
5892 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5893 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5894 XSETINT (it
->ctl_chars
[1], c
);
5896 goto display_control
;
5903 if (CHAR_BYTE8_P (c
))
5904 /* Display \200 instead of \17777600. */
5905 c
= CHAR_TO_BYTE8 (c
);
5906 len
= sprintf (str
, "%03o", c
);
5908 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5909 for (i
= 0; i
< len
; i
++)
5910 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
5915 /* Set up IT->dpvec and return first character from it. */
5916 it
->dpvec_char_len
= it
->len
;
5917 it
->dpvec
= it
->ctl_chars
;
5918 it
->dpend
= it
->dpvec
+ ctl_len
;
5919 it
->current
.dpvec_index
= 0;
5920 it
->dpvec_face_id
= face_id
;
5921 it
->saved_face_id
= it
->face_id
;
5922 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5926 it
->char_to_display
= c
;
5930 it
->char_to_display
= it
->c
;
5934 /* Adjust face id for a multibyte character. There are no multibyte
5935 character in unibyte text. */
5936 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5939 && FRAME_WINDOW_P (it
->f
))
5941 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5943 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5945 /* Automatic composition with glyph-string. */
5946 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5948 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5952 EMACS_INT pos
= (it
->s
? -1
5953 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5954 : IT_CHARPOS (*it
));
5956 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
5962 /* Is this character the last one of a run of characters with
5963 box? If yes, set IT->end_of_box_run_p to 1. */
5967 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5969 int face_id
= underlying_face_id (it
);
5970 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5974 if (face
->box
== FACE_NO_BOX
)
5976 /* If the box comes from face properties in a
5977 display string, check faces in that string. */
5978 int string_face_id
= face_after_it_pos (it
);
5979 it
->end_of_box_run_p
5980 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5983 /* Otherwise, the box comes from the underlying face.
5984 If this is the last string character displayed, check
5985 the next buffer location. */
5986 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5987 && (it
->current
.overlay_string_index
5988 == it
->n_overlay_strings
- 1))
5992 struct text_pos pos
= it
->current
.pos
;
5993 INC_TEXT_POS (pos
, it
->multibyte_p
);
5995 next_face_id
= face_at_buffer_position
5996 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
5997 it
->region_end_charpos
, &ignore
,
5998 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6000 it
->end_of_box_run_p
6001 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6008 int face_id
= face_after_it_pos (it
);
6009 it
->end_of_box_run_p
6010 = (face_id
!= it
->face_id
6011 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6015 /* Value is 0 if end of buffer or string reached. */
6020 /* Move IT to the next display element.
6022 RESEAT_P non-zero means if called on a newline in buffer text,
6023 skip to the next visible line start.
6025 Functions get_next_display_element and set_iterator_to_next are
6026 separate because I find this arrangement easier to handle than a
6027 get_next_display_element function that also increments IT's
6028 position. The way it is we can first look at an iterator's current
6029 display element, decide whether it fits on a line, and if it does,
6030 increment the iterator position. The other way around we probably
6031 would either need a flag indicating whether the iterator has to be
6032 incremented the next time, or we would have to implement a
6033 decrement position function which would not be easy to write. */
6036 set_iterator_to_next (struct it
*it
, int reseat_p
)
6038 /* Reset flags indicating start and end of a sequence of characters
6039 with box. Reset them at the start of this function because
6040 moving the iterator to a new position might set them. */
6041 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6045 case GET_FROM_BUFFER
:
6046 /* The current display element of IT is a character from
6047 current_buffer. Advance in the buffer, and maybe skip over
6048 invisible lines that are so because of selective display. */
6049 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6050 reseat_at_next_visible_line_start (it
, 0);
6051 else if (it
->cmp_it
.id
>= 0)
6053 /* We are currently getting glyphs from a composition. */
6058 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6059 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6060 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6062 it
->cmp_it
.from
= it
->cmp_it
.to
;
6067 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6069 it
->end_charpos
, Qnil
);
6072 else if (! it
->cmp_it
.reversed_p
)
6074 /* Composition created while scanning forward. */
6075 /* Update IT's char/byte positions to point to the first
6076 character of the next grapheme cluster, or to the
6077 character visually after the current composition. */
6078 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6079 bidi_move_to_visually_next (&it
->bidi_it
);
6080 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6081 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6083 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6085 /* Proceed to the next grapheme cluster. */
6086 it
->cmp_it
.from
= it
->cmp_it
.to
;
6090 /* No more grapheme clusters in this composition.
6091 Find the next stop position. */
6092 EMACS_INT stop
= it
->end_charpos
;
6093 if (it
->bidi_it
.scan_dir
< 0)
6094 /* Now we are scanning backward and don't know
6097 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6098 IT_BYTEPOS (*it
), stop
, Qnil
);
6103 /* Composition created while scanning backward. */
6104 /* Update IT's char/byte positions to point to the last
6105 character of the previous grapheme cluster, or the
6106 character visually after the current composition. */
6107 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6108 bidi_move_to_visually_next (&it
->bidi_it
);
6109 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6110 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6111 if (it
->cmp_it
.from
> 0)
6113 /* Proceed to the previous grapheme cluster. */
6114 it
->cmp_it
.to
= it
->cmp_it
.from
;
6118 /* No more grapheme clusters in this composition.
6119 Find the next stop position. */
6120 EMACS_INT stop
= it
->end_charpos
;
6121 if (it
->bidi_it
.scan_dir
< 0)
6122 /* Now we are scanning backward and don't know
6125 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6126 IT_BYTEPOS (*it
), stop
, Qnil
);
6132 xassert (it
->len
!= 0);
6136 IT_BYTEPOS (*it
) += it
->len
;
6137 IT_CHARPOS (*it
) += 1;
6141 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6142 /* If this is a new paragraph, determine its base
6143 direction (a.k.a. its base embedding level). */
6144 if (it
->bidi_it
.new_paragraph
)
6145 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6146 bidi_move_to_visually_next (&it
->bidi_it
);
6147 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6148 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6149 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6151 /* As the scan direction was changed, we must
6152 re-compute the stop position for composition. */
6153 EMACS_INT stop
= it
->end_charpos
;
6154 if (it
->bidi_it
.scan_dir
< 0)
6156 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6157 IT_BYTEPOS (*it
), stop
, Qnil
);
6160 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6164 case GET_FROM_C_STRING
:
6165 /* Current display element of IT is from a C string. */
6166 IT_BYTEPOS (*it
) += it
->len
;
6167 IT_CHARPOS (*it
) += 1;
6170 case GET_FROM_DISPLAY_VECTOR
:
6171 /* Current display element of IT is from a display table entry.
6172 Advance in the display table definition. Reset it to null if
6173 end reached, and continue with characters from buffers/
6175 ++it
->current
.dpvec_index
;
6177 /* Restore face of the iterator to what they were before the
6178 display vector entry (these entries may contain faces). */
6179 it
->face_id
= it
->saved_face_id
;
6181 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6183 int recheck_faces
= it
->ellipsis_p
;
6186 it
->method
= GET_FROM_C_STRING
;
6187 else if (STRINGP (it
->string
))
6188 it
->method
= GET_FROM_STRING
;
6191 it
->method
= GET_FROM_BUFFER
;
6192 it
->object
= it
->w
->buffer
;
6196 it
->current
.dpvec_index
= -1;
6198 /* Skip over characters which were displayed via IT->dpvec. */
6199 if (it
->dpvec_char_len
< 0)
6200 reseat_at_next_visible_line_start (it
, 1);
6201 else if (it
->dpvec_char_len
> 0)
6203 if (it
->method
== GET_FROM_STRING
6204 && it
->n_overlay_strings
> 0)
6205 it
->ignore_overlay_strings_at_pos_p
= 1;
6206 it
->len
= it
->dpvec_char_len
;
6207 set_iterator_to_next (it
, reseat_p
);
6210 /* Maybe recheck faces after display vector */
6212 it
->stop_charpos
= IT_CHARPOS (*it
);
6216 case GET_FROM_STRING
:
6217 /* Current display element is a character from a Lisp string. */
6218 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6219 if (it
->cmp_it
.id
>= 0)
6221 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6222 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6223 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6224 it
->cmp_it
.from
= it
->cmp_it
.to
;
6228 composition_compute_stop_pos (&it
->cmp_it
,
6229 IT_STRING_CHARPOS (*it
),
6230 IT_STRING_BYTEPOS (*it
),
6231 it
->end_charpos
, it
->string
);
6236 IT_STRING_BYTEPOS (*it
) += it
->len
;
6237 IT_STRING_CHARPOS (*it
) += 1;
6240 consider_string_end
:
6242 if (it
->current
.overlay_string_index
>= 0)
6244 /* IT->string is an overlay string. Advance to the
6245 next, if there is one. */
6246 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6249 next_overlay_string (it
);
6251 setup_for_ellipsis (it
, 0);
6256 /* IT->string is not an overlay string. If we reached
6257 its end, and there is something on IT->stack, proceed
6258 with what is on the stack. This can be either another
6259 string, this time an overlay string, or a buffer. */
6260 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6264 if (it
->method
== GET_FROM_STRING
)
6265 goto consider_string_end
;
6270 case GET_FROM_IMAGE
:
6271 case GET_FROM_STRETCH
:
6272 /* The position etc with which we have to proceed are on
6273 the stack. The position may be at the end of a string,
6274 if the `display' property takes up the whole string. */
6275 xassert (it
->sp
> 0);
6277 if (it
->method
== GET_FROM_STRING
)
6278 goto consider_string_end
;
6282 /* There are no other methods defined, so this should be a bug. */
6286 xassert (it
->method
!= GET_FROM_STRING
6287 || (STRINGP (it
->string
)
6288 && IT_STRING_CHARPOS (*it
) >= 0));
6291 /* Load IT's display element fields with information about the next
6292 display element which comes from a display table entry or from the
6293 result of translating a control character to one of the forms `^C'
6296 IT->dpvec holds the glyphs to return as characters.
6297 IT->saved_face_id holds the face id before the display vector--it
6298 is restored into IT->face_id in set_iterator_to_next. */
6301 next_element_from_display_vector (struct it
*it
)
6306 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6308 it
->face_id
= it
->saved_face_id
;
6310 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6311 That seemed totally bogus - so I changed it... */
6312 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6314 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6316 it
->c
= GLYPH_CODE_CHAR (gc
);
6317 it
->len
= CHAR_BYTES (it
->c
);
6319 /* The entry may contain a face id to use. Such a face id is
6320 the id of a Lisp face, not a realized face. A face id of
6321 zero means no face is specified. */
6322 if (it
->dpvec_face_id
>= 0)
6323 it
->face_id
= it
->dpvec_face_id
;
6326 int lface_id
= GLYPH_CODE_FACE (gc
);
6328 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6333 /* Display table entry is invalid. Return a space. */
6334 it
->c
= ' ', it
->len
= 1;
6336 /* Don't change position and object of the iterator here. They are
6337 still the values of the character that had this display table
6338 entry or was translated, and that's what we want. */
6339 it
->what
= IT_CHARACTER
;
6344 /* Load IT with the next display element from Lisp string IT->string.
6345 IT->current.string_pos is the current position within the string.
6346 If IT->current.overlay_string_index >= 0, the Lisp string is an
6350 next_element_from_string (struct it
*it
)
6352 struct text_pos position
;
6354 xassert (STRINGP (it
->string
));
6355 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6356 position
= it
->current
.string_pos
;
6358 /* Time to check for invisible text? */
6359 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6360 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6364 /* Since a handler may have changed IT->method, we must
6366 return GET_NEXT_DISPLAY_ELEMENT (it
);
6369 if (it
->current
.overlay_string_index
>= 0)
6371 /* Get the next character from an overlay string. In overlay
6372 strings, There is no field width or padding with spaces to
6374 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6379 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6380 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6381 && next_element_from_composition (it
))
6385 else if (STRING_MULTIBYTE (it
->string
))
6387 const unsigned char *s
= (SDATA (it
->string
)
6388 + IT_STRING_BYTEPOS (*it
));
6389 it
->c
= string_char_and_length (s
, &it
->len
);
6393 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6399 /* Get the next character from a Lisp string that is not an
6400 overlay string. Such strings come from the mode line, for
6401 example. We may have to pad with spaces, or truncate the
6402 string. See also next_element_from_c_string. */
6403 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6408 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6410 /* Pad with spaces. */
6411 it
->c
= ' ', it
->len
= 1;
6412 CHARPOS (position
) = BYTEPOS (position
) = -1;
6414 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6415 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6416 && next_element_from_composition (it
))
6420 else if (STRING_MULTIBYTE (it
->string
))
6422 const unsigned char *s
= (SDATA (it
->string
)
6423 + IT_STRING_BYTEPOS (*it
));
6424 it
->c
= string_char_and_length (s
, &it
->len
);
6428 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6433 /* Record what we have and where it came from. */
6434 it
->what
= IT_CHARACTER
;
6435 it
->object
= it
->string
;
6436 it
->position
= position
;
6441 /* Load IT with next display element from C string IT->s.
6442 IT->string_nchars is the maximum number of characters to return
6443 from the string. IT->end_charpos may be greater than
6444 IT->string_nchars when this function is called, in which case we
6445 may have to return padding spaces. Value is zero if end of string
6446 reached, including padding spaces. */
6449 next_element_from_c_string (struct it
*it
)
6454 it
->what
= IT_CHARACTER
;
6455 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6458 /* IT's position can be greater IT->string_nchars in case a field
6459 width or precision has been specified when the iterator was
6461 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6463 /* End of the game. */
6467 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6469 /* Pad with spaces. */
6470 it
->c
= ' ', it
->len
= 1;
6471 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6473 else if (it
->multibyte_p
)
6474 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6476 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6482 /* Set up IT to return characters from an ellipsis, if appropriate.
6483 The definition of the ellipsis glyphs may come from a display table
6484 entry. This function fills IT with the first glyph from the
6485 ellipsis if an ellipsis is to be displayed. */
6488 next_element_from_ellipsis (struct it
*it
)
6490 if (it
->selective_display_ellipsis_p
)
6491 setup_for_ellipsis (it
, it
->len
);
6494 /* The face at the current position may be different from the
6495 face we find after the invisible text. Remember what it
6496 was in IT->saved_face_id, and signal that it's there by
6497 setting face_before_selective_p. */
6498 it
->saved_face_id
= it
->face_id
;
6499 it
->method
= GET_FROM_BUFFER
;
6500 it
->object
= it
->w
->buffer
;
6501 reseat_at_next_visible_line_start (it
, 1);
6502 it
->face_before_selective_p
= 1;
6505 return GET_NEXT_DISPLAY_ELEMENT (it
);
6509 /* Deliver an image display element. The iterator IT is already
6510 filled with image information (done in handle_display_prop). Value
6515 next_element_from_image (struct it
*it
)
6517 it
->what
= IT_IMAGE
;
6518 it
->ignore_overlay_strings_at_pos_p
= 0;
6523 /* Fill iterator IT with next display element from a stretch glyph
6524 property. IT->object is the value of the text property. Value is
6528 next_element_from_stretch (struct it
*it
)
6530 it
->what
= IT_STRETCH
;
6534 /* Scan forward from CHARPOS in the current buffer, until we find a
6535 stop position > current IT's position. Then handle the stop
6536 position before that. This is called when we bump into a stop
6537 position while reordering bidirectional text. CHARPOS should be
6538 the last previously processed stop_pos (or BEGV, if none were
6539 processed yet) whose position is less that IT's current
6543 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
6545 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6546 struct display_pos save_current
= it
->current
;
6547 struct text_pos save_position
= it
->position
;
6548 struct text_pos pos1
;
6549 EMACS_INT next_stop
;
6551 /* Scan in strict logical order. */
6555 it
->prev_stop
= charpos
;
6556 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6557 reseat_1 (it
, pos1
, 0);
6558 compute_stop_pos (it
);
6559 /* We must advance forward, right? */
6560 if (it
->stop_charpos
<= it
->prev_stop
)
6562 charpos
= it
->stop_charpos
;
6564 while (charpos
<= where_we_are
);
6566 next_stop
= it
->stop_charpos
;
6567 it
->stop_charpos
= it
->prev_stop
;
6569 it
->current
= save_current
;
6570 it
->position
= save_position
;
6572 it
->stop_charpos
= next_stop
;
6575 /* Load IT with the next display element from current_buffer. Value
6576 is zero if end of buffer reached. IT->stop_charpos is the next
6577 position at which to stop and check for text properties or buffer
6581 next_element_from_buffer (struct it
*it
)
6585 xassert (IT_CHARPOS (*it
) >= BEGV
);
6587 /* With bidi reordering, the character to display might not be the
6588 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6589 we were reseat()ed to a new buffer position, which is potentially
6590 a different paragraph. */
6591 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6593 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6594 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6595 if (it
->bidi_it
.bytepos
== ZV_BYTE
)
6597 /* Nothing to do, but reset the FIRST_ELT flag, like
6598 bidi_paragraph_init does, because we are not going to
6600 it
->bidi_it
.first_elt
= 0;
6602 else if (it
->bidi_it
.bytepos
== BEGV_BYTE
6603 /* FIXME: Should support all Unicode line separators. */
6604 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6605 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6607 /* If we are at the beginning of a line, we can produce the
6608 next element right away. */
6609 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6610 bidi_move_to_visually_next (&it
->bidi_it
);
6614 EMACS_INT orig_bytepos
= IT_BYTEPOS (*it
);
6616 /* We need to prime the bidi iterator starting at the line's
6617 beginning, before we will be able to produce the next
6619 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6620 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6621 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6622 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6623 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6626 /* Now return to buffer position where we were asked to
6627 get the next display element, and produce that. */
6628 bidi_move_to_visually_next (&it
->bidi_it
);
6630 while (it
->bidi_it
.bytepos
!= orig_bytepos
6631 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6634 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6635 /* Adjust IT's position information to where we ended up. */
6636 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6637 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6638 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6640 EMACS_INT stop
= it
->end_charpos
;
6641 if (it
->bidi_it
.scan_dir
< 0)
6643 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6644 IT_BYTEPOS (*it
), stop
, Qnil
);
6648 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6650 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6652 int overlay_strings_follow_p
;
6654 /* End of the game, except when overlay strings follow that
6655 haven't been returned yet. */
6656 if (it
->overlay_strings_at_end_processed_p
)
6657 overlay_strings_follow_p
= 0;
6660 it
->overlay_strings_at_end_processed_p
= 1;
6661 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6664 if (overlay_strings_follow_p
)
6665 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6669 it
->position
= it
->current
.pos
;
6673 else if (!(!it
->bidi_p
6674 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6675 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6677 /* With bidi non-linear iteration, we could find ourselves
6678 far beyond the last computed stop_charpos, with several
6679 other stop positions in between that we missed. Scan
6680 them all now, in buffer's logical order, until we find
6681 and handle the last stop_charpos that precedes our
6682 current position. */
6683 handle_stop_backwards (it
, it
->stop_charpos
);
6684 return GET_NEXT_DISPLAY_ELEMENT (it
);
6690 /* Take note of the stop position we just moved across,
6691 for when we will move back across it. */
6692 it
->prev_stop
= it
->stop_charpos
;
6693 /* If we are at base paragraph embedding level, take
6694 note of the last stop position seen at this
6696 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6697 it
->base_level_stop
= it
->stop_charpos
;
6700 return GET_NEXT_DISPLAY_ELEMENT (it
);
6704 /* We can sometimes back up for reasons that have nothing
6705 to do with bidi reordering. E.g., compositions. The
6706 code below is only needed when we are above the base
6707 embedding level, so test for that explicitly. */
6708 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6709 && IT_CHARPOS (*it
) < it
->prev_stop
)
6711 if (it
->base_level_stop
<= 0)
6712 it
->base_level_stop
= BEGV
;
6713 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6715 handle_stop_backwards (it
, it
->base_level_stop
);
6716 return GET_NEXT_DISPLAY_ELEMENT (it
);
6720 /* No face changes, overlays etc. in sight, so just return a
6721 character from current_buffer. */
6725 /* Maybe run the redisplay end trigger hook. Performance note:
6726 This doesn't seem to cost measurable time. */
6727 if (it
->redisplay_end_trigger_charpos
6729 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6730 run_redisplay_end_trigger_hook (it
);
6732 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
6733 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6735 && next_element_from_composition (it
))
6740 /* Get the next character, maybe multibyte. */
6741 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6742 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6743 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6745 it
->c
= *p
, it
->len
= 1;
6747 /* Record what we have and where it came from. */
6748 it
->what
= IT_CHARACTER
;
6749 it
->object
= it
->w
->buffer
;
6750 it
->position
= it
->current
.pos
;
6752 /* Normally we return the character found above, except when we
6753 really want to return an ellipsis for selective display. */
6758 /* A value of selective > 0 means hide lines indented more
6759 than that number of columns. */
6760 if (it
->selective
> 0
6761 && IT_CHARPOS (*it
) + 1 < ZV
6762 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6763 IT_BYTEPOS (*it
) + 1,
6764 (double) it
->selective
)) /* iftc */
6766 success_p
= next_element_from_ellipsis (it
);
6767 it
->dpvec_char_len
= -1;
6770 else if (it
->c
== '\r' && it
->selective
== -1)
6772 /* A value of selective == -1 means that everything from the
6773 CR to the end of the line is invisible, with maybe an
6774 ellipsis displayed for it. */
6775 success_p
= next_element_from_ellipsis (it
);
6776 it
->dpvec_char_len
= -1;
6781 /* Value is zero if end of buffer reached. */
6782 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6787 /* Run the redisplay end trigger hook for IT. */
6790 run_redisplay_end_trigger_hook (struct it
*it
)
6792 Lisp_Object args
[3];
6794 /* IT->glyph_row should be non-null, i.e. we should be actually
6795 displaying something, or otherwise we should not run the hook. */
6796 xassert (it
->glyph_row
);
6798 /* Set up hook arguments. */
6799 args
[0] = Qredisplay_end_trigger_functions
;
6800 args
[1] = it
->window
;
6801 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6802 it
->redisplay_end_trigger_charpos
= 0;
6804 /* Since we are *trying* to run these functions, don't try to run
6805 them again, even if they get an error. */
6806 it
->w
->redisplay_end_trigger
= Qnil
;
6807 Frun_hook_with_args (3, args
);
6809 /* Notice if it changed the face of the character we are on. */
6810 handle_face_prop (it
);
6814 /* Deliver a composition display element. Unlike the other
6815 next_element_from_XXX, this function is not registered in the array
6816 get_next_element[]. It is called from next_element_from_buffer and
6817 next_element_from_string when necessary. */
6820 next_element_from_composition (struct it
*it
)
6822 it
->what
= IT_COMPOSITION
;
6823 it
->len
= it
->cmp_it
.nbytes
;
6824 if (STRINGP (it
->string
))
6828 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6829 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6832 it
->position
= it
->current
.string_pos
;
6833 it
->object
= it
->string
;
6834 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6835 IT_STRING_BYTEPOS (*it
), it
->string
);
6841 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6842 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6845 if (it
->bidi_it
.new_paragraph
)
6846 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6847 /* Resync the bidi iterator with IT's new position.
6848 FIXME: this doesn't support bidirectional text. */
6849 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
6850 bidi_move_to_visually_next (&it
->bidi_it
);
6854 it
->position
= it
->current
.pos
;
6855 it
->object
= it
->w
->buffer
;
6856 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6857 IT_BYTEPOS (*it
), Qnil
);
6864 /***********************************************************************
6865 Moving an iterator without producing glyphs
6866 ***********************************************************************/
6868 /* Check if iterator is at a position corresponding to a valid buffer
6869 position after some move_it_ call. */
6871 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6872 ((it)->method == GET_FROM_STRING \
6873 ? IT_STRING_CHARPOS (*it) == 0 \
6877 /* Move iterator IT to a specified buffer or X position within one
6878 line on the display without producing glyphs.
6880 OP should be a bit mask including some or all of these bits:
6881 MOVE_TO_X: Stop upon reaching x-position TO_X.
6882 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6883 Regardless of OP's value, stop upon reaching the end of the display line.
6885 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6886 This means, in particular, that TO_X includes window's horizontal
6889 The return value has several possible values that
6890 say what condition caused the scan to stop:
6892 MOVE_POS_MATCH_OR_ZV
6893 - when TO_POS or ZV was reached.
6896 -when TO_X was reached before TO_POS or ZV were reached.
6899 - when we reached the end of the display area and the line must
6903 - when we reached the end of the display area and the line is
6907 - when we stopped at a line end, i.e. a newline or a CR and selective
6910 static enum move_it_result
6911 move_it_in_display_line_to (struct it
*it
,
6912 EMACS_INT to_charpos
, int to_x
,
6913 enum move_operation_enum op
)
6915 enum move_it_result result
= MOVE_UNDEFINED
;
6916 struct glyph_row
*saved_glyph_row
;
6917 struct it wrap_it
, atpos_it
, atx_it
;
6919 enum it_method prev_method
= it
->method
;
6920 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
6922 /* Don't produce glyphs in produce_glyphs. */
6923 saved_glyph_row
= it
->glyph_row
;
6924 it
->glyph_row
= NULL
;
6926 /* Use wrap_it to save a copy of IT wherever a word wrap could
6927 occur. Use atpos_it to save a copy of IT at the desired buffer
6928 position, if found, so that we can scan ahead and check if the
6929 word later overshoots the window edge. Use atx_it similarly, for
6935 #define BUFFER_POS_REACHED_P() \
6936 ((op & MOVE_TO_POS) != 0 \
6937 && BUFFERP (it->object) \
6938 && (IT_CHARPOS (*it) == to_charpos \
6939 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
6940 && (it->method == GET_FROM_BUFFER \
6941 || (it->method == GET_FROM_DISPLAY_VECTOR \
6942 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6944 /* If there's a line-/wrap-prefix, handle it. */
6945 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6946 && it
->current_y
< it
->last_visible_y
)
6947 handle_line_prefix (it
);
6949 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
6950 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6954 int x
, i
, ascent
= 0, descent
= 0;
6956 /* Utility macro to reset an iterator with x, ascent, and descent. */
6957 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6958 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6959 (IT)->max_descent = descent)
6961 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6963 if ((op
& MOVE_TO_POS
) != 0
6964 && BUFFERP (it
->object
)
6965 && it
->method
== GET_FROM_BUFFER
6966 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
6968 && (prev_method
== GET_FROM_IMAGE
6969 || prev_method
== GET_FROM_STRETCH
)
6970 /* Passed TO_CHARPOS from left to right. */
6971 && ((prev_pos
< to_charpos
6972 && IT_CHARPOS (*it
) > to_charpos
)
6973 /* Passed TO_CHARPOS from right to left. */
6974 || (prev_pos
> to_charpos
6975 && IT_CHARPOS (*it
) < to_charpos
)))))
6977 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6979 result
= MOVE_POS_MATCH_OR_ZV
;
6982 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6983 /* If wrap_it is valid, the current position might be in a
6984 word that is wrapped. So, save the iterator in
6985 atpos_it and continue to see if wrapping happens. */
6989 prev_method
= it
->method
;
6990 if (it
->method
== GET_FROM_BUFFER
)
6991 prev_pos
= IT_CHARPOS (*it
);
6992 /* Stop when ZV reached.
6993 We used to stop here when TO_CHARPOS reached as well, but that is
6994 too soon if this glyph does not fit on this line. So we handle it
6995 explicitly below. */
6996 if (!get_next_display_element (it
))
6998 result
= MOVE_POS_MATCH_OR_ZV
;
7002 if (it
->line_wrap
== TRUNCATE
)
7004 if (BUFFER_POS_REACHED_P ())
7006 result
= MOVE_POS_MATCH_OR_ZV
;
7012 if (it
->line_wrap
== WORD_WRAP
)
7014 if (IT_DISPLAYING_WHITESPACE (it
))
7018 /* We have reached a glyph that follows one or more
7019 whitespace characters. If the position is
7020 already found, we are done. */
7021 if (atpos_it
.sp
>= 0)
7024 result
= MOVE_POS_MATCH_OR_ZV
;
7030 result
= MOVE_X_REACHED
;
7033 /* Otherwise, we can wrap here. */
7040 /* Remember the line height for the current line, in case
7041 the next element doesn't fit on the line. */
7042 ascent
= it
->max_ascent
;
7043 descent
= it
->max_descent
;
7045 /* The call to produce_glyphs will get the metrics of the
7046 display element IT is loaded with. Record the x-position
7047 before this display element, in case it doesn't fit on the
7051 PRODUCE_GLYPHS (it
);
7053 if (it
->area
!= TEXT_AREA
)
7055 set_iterator_to_next (it
, 1);
7056 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7057 SET_TEXT_POS (this_line_min_pos
,
7058 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7062 /* The number of glyphs we get back in IT->nglyphs will normally
7063 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7064 character on a terminal frame, or (iii) a line end. For the
7065 second case, IT->nglyphs - 1 padding glyphs will be present.
7066 (On X frames, there is only one glyph produced for a
7067 composite character.)
7069 The behavior implemented below means, for continuation lines,
7070 that as many spaces of a TAB as fit on the current line are
7071 displayed there. For terminal frames, as many glyphs of a
7072 multi-glyph character are displayed in the current line, too.
7073 This is what the old redisplay code did, and we keep it that
7074 way. Under X, the whole shape of a complex character must
7075 fit on the line or it will be completely displayed in the
7078 Note that both for tabs and padding glyphs, all glyphs have
7082 /* More than one glyph or glyph doesn't fit on line. All
7083 glyphs have the same width. */
7084 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7086 int x_before_this_char
= x
;
7087 int hpos_before_this_char
= it
->hpos
;
7089 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7091 new_x
= x
+ single_glyph_width
;
7093 /* We want to leave anything reaching TO_X to the caller. */
7094 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7096 if (BUFFER_POS_REACHED_P ())
7098 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7099 goto buffer_pos_reached
;
7100 if (atpos_it
.sp
< 0)
7103 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7108 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7111 result
= MOVE_X_REACHED
;
7117 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7122 if (/* Lines are continued. */
7123 it
->line_wrap
!= TRUNCATE
7124 && (/* And glyph doesn't fit on the line. */
7125 new_x
> it
->last_visible_x
7126 /* Or it fits exactly and we're on a window
7128 || (new_x
== it
->last_visible_x
7129 && FRAME_WINDOW_P (it
->f
))))
7131 if (/* IT->hpos == 0 means the very first glyph
7132 doesn't fit on the line, e.g. a wide image. */
7134 || (new_x
== it
->last_visible_x
7135 && FRAME_WINDOW_P (it
->f
)))
7138 it
->current_x
= new_x
;
7140 /* The character's last glyph just barely fits
7142 if (i
== it
->nglyphs
- 1)
7144 /* If this is the destination position,
7145 return a position *before* it in this row,
7146 now that we know it fits in this row. */
7147 if (BUFFER_POS_REACHED_P ())
7149 if (it
->line_wrap
!= WORD_WRAP
7152 it
->hpos
= hpos_before_this_char
;
7153 it
->current_x
= x_before_this_char
;
7154 result
= MOVE_POS_MATCH_OR_ZV
;
7157 if (it
->line_wrap
== WORD_WRAP
7161 atpos_it
.current_x
= x_before_this_char
;
7162 atpos_it
.hpos
= hpos_before_this_char
;
7166 set_iterator_to_next (it
, 1);
7167 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7168 SET_TEXT_POS (this_line_min_pos
,
7169 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7170 /* On graphical terminals, newlines may
7171 "overflow" into the fringe if
7172 overflow-newline-into-fringe is non-nil.
7173 On text-only terminals, newlines may
7174 overflow into the last glyph on the
7176 if (!FRAME_WINDOW_P (it
->f
)
7177 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7179 if (!get_next_display_element (it
))
7181 result
= MOVE_POS_MATCH_OR_ZV
;
7184 if (BUFFER_POS_REACHED_P ())
7186 if (ITERATOR_AT_END_OF_LINE_P (it
))
7187 result
= MOVE_POS_MATCH_OR_ZV
;
7189 result
= MOVE_LINE_CONTINUED
;
7192 if (ITERATOR_AT_END_OF_LINE_P (it
))
7194 result
= MOVE_NEWLINE_OR_CR
;
7201 IT_RESET_X_ASCENT_DESCENT (it
);
7203 if (wrap_it
.sp
>= 0)
7210 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7212 result
= MOVE_LINE_CONTINUED
;
7216 if (BUFFER_POS_REACHED_P ())
7218 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7219 goto buffer_pos_reached
;
7220 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7223 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7227 if (new_x
> it
->first_visible_x
)
7229 /* Glyph is visible. Increment number of glyphs that
7230 would be displayed. */
7235 if (result
!= MOVE_UNDEFINED
)
7238 else if (BUFFER_POS_REACHED_P ())
7241 IT_RESET_X_ASCENT_DESCENT (it
);
7242 result
= MOVE_POS_MATCH_OR_ZV
;
7245 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7247 /* Stop when TO_X specified and reached. This check is
7248 necessary here because of lines consisting of a line end,
7249 only. The line end will not produce any glyphs and we
7250 would never get MOVE_X_REACHED. */
7251 xassert (it
->nglyphs
== 0);
7252 result
= MOVE_X_REACHED
;
7256 /* Is this a line end? If yes, we're done. */
7257 if (ITERATOR_AT_END_OF_LINE_P (it
))
7259 result
= MOVE_NEWLINE_OR_CR
;
7263 if (it
->method
== GET_FROM_BUFFER
)
7264 prev_pos
= IT_CHARPOS (*it
);
7265 /* The current display element has been consumed. Advance
7267 set_iterator_to_next (it
, 1);
7268 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7269 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7271 /* Stop if lines are truncated and IT's current x-position is
7272 past the right edge of the window now. */
7273 if (it
->line_wrap
== TRUNCATE
7274 && it
->current_x
>= it
->last_visible_x
)
7276 if (!FRAME_WINDOW_P (it
->f
)
7277 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7279 if (!get_next_display_element (it
)
7280 || BUFFER_POS_REACHED_P ())
7282 result
= MOVE_POS_MATCH_OR_ZV
;
7285 if (ITERATOR_AT_END_OF_LINE_P (it
))
7287 result
= MOVE_NEWLINE_OR_CR
;
7291 result
= MOVE_LINE_TRUNCATED
;
7294 #undef IT_RESET_X_ASCENT_DESCENT
7297 #undef BUFFER_POS_REACHED_P
7299 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7300 restore the saved iterator. */
7301 if (atpos_it
.sp
>= 0)
7303 else if (atx_it
.sp
>= 0)
7308 /* Restore the iterator settings altered at the beginning of this
7310 it
->glyph_row
= saved_glyph_row
;
7314 /* For external use. */
7316 move_it_in_display_line (struct it
*it
,
7317 EMACS_INT to_charpos
, int to_x
,
7318 enum move_operation_enum op
)
7320 if (it
->line_wrap
== WORD_WRAP
7321 && (op
& MOVE_TO_X
))
7323 struct it save_it
= *it
;
7324 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7325 /* When word-wrap is on, TO_X may lie past the end
7326 of a wrapped line. Then it->current is the
7327 character on the next line, so backtrack to the
7328 space before the wrap point. */
7329 if (skip
== MOVE_LINE_CONTINUED
)
7331 int prev_x
= max (it
->current_x
- 1, 0);
7333 move_it_in_display_line_to
7334 (it
, -1, prev_x
, MOVE_TO_X
);
7338 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7342 /* Move IT forward until it satisfies one or more of the criteria in
7343 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7345 OP is a bit-mask that specifies where to stop, and in particular,
7346 which of those four position arguments makes a difference. See the
7347 description of enum move_operation_enum.
7349 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7350 screen line, this function will set IT to the next position >
7354 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7356 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7357 int line_height
, line_start_x
= 0, reached
= 0;
7361 if (op
& MOVE_TO_VPOS
)
7363 /* If no TO_CHARPOS and no TO_X specified, stop at the
7364 start of the line TO_VPOS. */
7365 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7367 if (it
->vpos
== to_vpos
)
7373 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7377 /* TO_VPOS >= 0 means stop at TO_X in the line at
7378 TO_VPOS, or at TO_POS, whichever comes first. */
7379 if (it
->vpos
== to_vpos
)
7385 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7387 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7392 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7394 /* We have reached TO_X but not in the line we want. */
7395 skip
= move_it_in_display_line_to (it
, to_charpos
,
7397 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7405 else if (op
& MOVE_TO_Y
)
7407 struct it it_backup
;
7409 if (it
->line_wrap
== WORD_WRAP
)
7412 /* TO_Y specified means stop at TO_X in the line containing
7413 TO_Y---or at TO_CHARPOS if this is reached first. The
7414 problem is that we can't really tell whether the line
7415 contains TO_Y before we have completely scanned it, and
7416 this may skip past TO_X. What we do is to first scan to
7419 If TO_X is not specified, use a TO_X of zero. The reason
7420 is to make the outcome of this function more predictable.
7421 If we didn't use TO_X == 0, we would stop at the end of
7422 the line which is probably not what a caller would expect
7424 skip
= move_it_in_display_line_to
7425 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7426 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7428 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7429 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7431 else if (skip
== MOVE_X_REACHED
)
7433 /* If TO_X was reached, we want to know whether TO_Y is
7434 in the line. We know this is the case if the already
7435 scanned glyphs make the line tall enough. Otherwise,
7436 we must check by scanning the rest of the line. */
7437 line_height
= it
->max_ascent
+ it
->max_descent
;
7438 if (to_y
>= it
->current_y
7439 && to_y
< it
->current_y
+ line_height
)
7445 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7446 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7448 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7449 line_height
= it
->max_ascent
+ it
->max_descent
;
7450 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7452 if (to_y
>= it
->current_y
7453 && to_y
< it
->current_y
+ line_height
)
7455 /* If TO_Y is in this line and TO_X was reached
7456 above, we scanned too far. We have to restore
7457 IT's settings to the ones before skipping. */
7464 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7470 /* Check whether TO_Y is in this line. */
7471 line_height
= it
->max_ascent
+ it
->max_descent
;
7472 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7474 if (to_y
>= it
->current_y
7475 && to_y
< it
->current_y
+ line_height
)
7477 /* When word-wrap is on, TO_X may lie past the end
7478 of a wrapped line. Then it->current is the
7479 character on the next line, so backtrack to the
7480 space before the wrap point. */
7481 if (skip
== MOVE_LINE_CONTINUED
7482 && it
->line_wrap
== WORD_WRAP
)
7484 int prev_x
= max (it
->current_x
- 1, 0);
7486 skip
= move_it_in_display_line_to
7487 (it
, -1, prev_x
, MOVE_TO_X
);
7496 else if (BUFFERP (it
->object
)
7497 && (it
->method
== GET_FROM_BUFFER
7498 || it
->method
== GET_FROM_STRETCH
)
7499 && IT_CHARPOS (*it
) >= to_charpos
)
7500 skip
= MOVE_POS_MATCH_OR_ZV
;
7502 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7506 case MOVE_POS_MATCH_OR_ZV
:
7510 case MOVE_NEWLINE_OR_CR
:
7511 set_iterator_to_next (it
, 1);
7512 it
->continuation_lines_width
= 0;
7515 case MOVE_LINE_TRUNCATED
:
7516 it
->continuation_lines_width
= 0;
7517 reseat_at_next_visible_line_start (it
, 0);
7518 if ((op
& MOVE_TO_POS
) != 0
7519 && IT_CHARPOS (*it
) > to_charpos
)
7526 case MOVE_LINE_CONTINUED
:
7527 /* For continued lines ending in a tab, some of the glyphs
7528 associated with the tab are displayed on the current
7529 line. Since it->current_x does not include these glyphs,
7530 we use it->last_visible_x instead. */
7533 it
->continuation_lines_width
+= it
->last_visible_x
;
7534 /* When moving by vpos, ensure that the iterator really
7535 advances to the next line (bug#847, bug#969). Fixme:
7536 do we need to do this in other circumstances? */
7537 if (it
->current_x
!= it
->last_visible_x
7538 && (op
& MOVE_TO_VPOS
)
7539 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7541 line_start_x
= it
->current_x
+ it
->pixel_width
7542 - it
->last_visible_x
;
7543 set_iterator_to_next (it
, 0);
7547 it
->continuation_lines_width
+= it
->current_x
;
7554 /* Reset/increment for the next run. */
7555 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7556 it
->current_x
= line_start_x
;
7559 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7561 last_height
= it
->max_ascent
+ it
->max_descent
;
7562 last_max_ascent
= it
->max_ascent
;
7563 it
->max_ascent
= it
->max_descent
= 0;
7568 /* On text terminals, we may stop at the end of a line in the middle
7569 of a multi-character glyph. If the glyph itself is continued,
7570 i.e. it is actually displayed on the next line, don't treat this
7571 stopping point as valid; move to the next line instead (unless
7572 that brings us offscreen). */
7573 if (!FRAME_WINDOW_P (it
->f
)
7575 && IT_CHARPOS (*it
) == to_charpos
7576 && it
->what
== IT_CHARACTER
7578 && it
->line_wrap
== WINDOW_WRAP
7579 && it
->current_x
== it
->last_visible_x
- 1
7582 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7584 it
->continuation_lines_width
+= it
->current_x
;
7585 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7586 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7588 last_height
= it
->max_ascent
+ it
->max_descent
;
7589 last_max_ascent
= it
->max_ascent
;
7592 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7596 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7598 If DY > 0, move IT backward at least that many pixels. DY = 0
7599 means move IT backward to the preceding line start or BEGV. This
7600 function may move over more than DY pixels if IT->current_y - DY
7601 ends up in the middle of a line; in this case IT->current_y will be
7602 set to the top of the line moved to. */
7605 move_it_vertically_backward (struct it
*it
, int dy
)
7609 EMACS_INT start_pos
;
7614 start_pos
= IT_CHARPOS (*it
);
7616 /* Estimate how many newlines we must move back. */
7617 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7619 /* Set the iterator's position that many lines back. */
7620 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7621 back_to_previous_visible_line_start (it
);
7623 /* Reseat the iterator here. When moving backward, we don't want
7624 reseat to skip forward over invisible text, set up the iterator
7625 to deliver from overlay strings at the new position etc. So,
7626 use reseat_1 here. */
7627 reseat_1 (it
, it
->current
.pos
, 1);
7629 /* We are now surely at a line start. */
7630 it
->current_x
= it
->hpos
= 0;
7631 it
->continuation_lines_width
= 0;
7633 /* Move forward and see what y-distance we moved. First move to the
7634 start of the next line so that we get its height. We need this
7635 height to be able to tell whether we reached the specified
7638 it2
.max_ascent
= it2
.max_descent
= 0;
7641 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7642 MOVE_TO_POS
| MOVE_TO_VPOS
);
7644 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7645 xassert (IT_CHARPOS (*it
) >= BEGV
);
7648 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7649 xassert (IT_CHARPOS (*it
) >= BEGV
);
7650 /* H is the actual vertical distance from the position in *IT
7651 and the starting position. */
7652 h
= it2
.current_y
- it
->current_y
;
7653 /* NLINES is the distance in number of lines. */
7654 nlines
= it2
.vpos
- it
->vpos
;
7656 /* Correct IT's y and vpos position
7657 so that they are relative to the starting point. */
7663 /* DY == 0 means move to the start of the screen line. The
7664 value of nlines is > 0 if continuation lines were involved. */
7666 move_it_by_lines (it
, nlines
);
7670 /* The y-position we try to reach, relative to *IT.
7671 Note that H has been subtracted in front of the if-statement. */
7672 int target_y
= it
->current_y
+ h
- dy
;
7673 int y0
= it3
.current_y
;
7674 int y1
= line_bottom_y (&it3
);
7675 int line_height
= y1
- y0
;
7677 /* If we did not reach target_y, try to move further backward if
7678 we can. If we moved too far backward, try to move forward. */
7679 if (target_y
< it
->current_y
7680 /* This is heuristic. In a window that's 3 lines high, with
7681 a line height of 13 pixels each, recentering with point
7682 on the bottom line will try to move -39/2 = 19 pixels
7683 backward. Try to avoid moving into the first line. */
7684 && (it
->current_y
- target_y
7685 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7686 && IT_CHARPOS (*it
) > BEGV
)
7688 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7689 target_y
- it
->current_y
));
7690 dy
= it
->current_y
- target_y
;
7691 goto move_further_back
;
7693 else if (target_y
>= it
->current_y
+ line_height
7694 && IT_CHARPOS (*it
) < ZV
)
7696 /* Should move forward by at least one line, maybe more.
7698 Note: Calling move_it_by_lines can be expensive on
7699 terminal frames, where compute_motion is used (via
7700 vmotion) to do the job, when there are very long lines
7701 and truncate-lines is nil. That's the reason for
7702 treating terminal frames specially here. */
7704 if (!FRAME_WINDOW_P (it
->f
))
7705 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7710 move_it_by_lines (it
, 1);
7712 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7719 /* Move IT by a specified amount of pixel lines DY. DY negative means
7720 move backwards. DY = 0 means move to start of screen line. At the
7721 end, IT will be on the start of a screen line. */
7724 move_it_vertically (struct it
*it
, int dy
)
7727 move_it_vertically_backward (it
, -dy
);
7730 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7731 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7732 MOVE_TO_POS
| MOVE_TO_Y
);
7733 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7735 /* If buffer ends in ZV without a newline, move to the start of
7736 the line to satisfy the post-condition. */
7737 if (IT_CHARPOS (*it
) == ZV
7739 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7740 move_it_by_lines (it
, 0);
7745 /* Move iterator IT past the end of the text line it is in. */
7748 move_it_past_eol (struct it
*it
)
7750 enum move_it_result rc
;
7752 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7753 if (rc
== MOVE_NEWLINE_OR_CR
)
7754 set_iterator_to_next (it
, 0);
7758 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7759 negative means move up. DVPOS == 0 means move to the start of the
7762 Optimization idea: If we would know that IT->f doesn't use
7763 a face with proportional font, we could be faster for
7764 truncate-lines nil. */
7767 move_it_by_lines (struct it
*it
, int dvpos
)
7770 /* The commented-out optimization uses vmotion on terminals. This
7771 gives bad results, because elements like it->what, on which
7772 callers such as pos_visible_p rely, aren't updated. */
7773 /* struct position pos;
7774 if (!FRAME_WINDOW_P (it->f))
7776 struct text_pos textpos;
7778 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7779 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7780 reseat (it, textpos, 1);
7781 it->vpos += pos.vpos;
7782 it->current_y += pos.vpos;
7788 /* DVPOS == 0 means move to the start of the screen line. */
7789 move_it_vertically_backward (it
, 0);
7790 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7791 /* Let next call to line_bottom_y calculate real line height */
7796 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7797 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7798 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7803 EMACS_INT start_charpos
, i
;
7805 /* Start at the beginning of the screen line containing IT's
7806 position. This may actually move vertically backwards,
7807 in case of overlays, so adjust dvpos accordingly. */
7809 move_it_vertically_backward (it
, 0);
7812 /* Go back -DVPOS visible lines and reseat the iterator there. */
7813 start_charpos
= IT_CHARPOS (*it
);
7814 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7815 back_to_previous_visible_line_start (it
);
7816 reseat (it
, it
->current
.pos
, 1);
7818 /* Move further back if we end up in a string or an image. */
7819 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7821 /* First try to move to start of display line. */
7823 move_it_vertically_backward (it
, 0);
7825 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7827 /* If start of line is still in string or image,
7828 move further back. */
7829 back_to_previous_visible_line_start (it
);
7830 reseat (it
, it
->current
.pos
, 1);
7834 it
->current_x
= it
->hpos
= 0;
7836 /* Above call may have moved too far if continuation lines
7837 are involved. Scan forward and see if it did. */
7839 it2
.vpos
= it2
.current_y
= 0;
7840 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7841 it
->vpos
-= it2
.vpos
;
7842 it
->current_y
-= it2
.current_y
;
7843 it
->current_x
= it
->hpos
= 0;
7845 /* If we moved too far back, move IT some lines forward. */
7846 if (it2
.vpos
> -dvpos
)
7848 int delta
= it2
.vpos
+ dvpos
;
7850 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7851 /* Move back again if we got too far ahead. */
7852 if (IT_CHARPOS (*it
) >= start_charpos
)
7858 /* Return 1 if IT points into the middle of a display vector. */
7861 in_display_vector_p (struct it
*it
)
7863 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7864 && it
->current
.dpvec_index
> 0
7865 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7869 /***********************************************************************
7871 ***********************************************************************/
7874 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7878 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
7880 Lisp_Object args
[3];
7881 Lisp_Object msg
, fmt
;
7884 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7887 /* Do nothing if called asynchronously. Inserting text into
7888 a buffer may call after-change-functions and alike and
7889 that would means running Lisp asynchronously. */
7890 if (handling_signal
)
7894 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7896 args
[0] = fmt
= build_string (format
);
7899 msg
= Fformat (3, args
);
7901 len
= SBYTES (msg
) + 1;
7902 SAFE_ALLOCA (buffer
, char *, len
);
7903 memcpy (buffer
, SDATA (msg
), len
);
7905 message_dolog (buffer
, len
- 1, 1, 0);
7912 /* Output a newline in the *Messages* buffer if "needs" one. */
7915 message_log_maybe_newline (void)
7917 if (message_log_need_newline
)
7918 message_dolog ("", 0, 1, 0);
7922 /* Add a string M of length NBYTES to the message log, optionally
7923 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7924 nonzero, means interpret the contents of M as multibyte. This
7925 function calls low-level routines in order to bypass text property
7926 hooks, etc. which might not be safe to run.
7928 This may GC (insert may run before/after change hooks),
7929 so the buffer M must NOT point to a Lisp string. */
7932 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
7934 const unsigned char *msg
= (const unsigned char *) m
;
7936 if (!NILP (Vmemory_full
))
7939 if (!NILP (Vmessage_log_max
))
7941 struct buffer
*oldbuf
;
7942 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7943 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7944 EMACS_INT point_at_end
= 0;
7945 EMACS_INT zv_at_end
= 0;
7946 Lisp_Object old_deactivate_mark
, tem
;
7947 struct gcpro gcpro1
;
7949 old_deactivate_mark
= Vdeactivate_mark
;
7950 oldbuf
= current_buffer
;
7951 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7952 BVAR (current_buffer
, undo_list
) = Qt
;
7954 oldpoint
= message_dolog_marker1
;
7955 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7956 oldbegv
= message_dolog_marker2
;
7957 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7958 oldzv
= message_dolog_marker3
;
7959 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7960 GCPRO1 (old_deactivate_mark
);
7968 BEGV_BYTE
= BEG_BYTE
;
7971 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7973 /* Insert the string--maybe converting multibyte to single byte
7974 or vice versa, so that all the text fits the buffer. */
7976 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
7982 /* Convert a multibyte string to single-byte
7983 for the *Message* buffer. */
7984 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7986 c
= string_char_and_length (msg
+ i
, &char_bytes
);
7987 work
[0] = (ASCII_CHAR_P (c
)
7989 : multibyte_char_to_unibyte (c
));
7990 insert_1_both (work
, 1, 1, 1, 0, 0);
7993 else if (! multibyte
7994 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
7998 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7999 /* Convert a single-byte string to multibyte
8000 for the *Message* buffer. */
8001 for (i
= 0; i
< nbytes
; i
++)
8004 MAKE_CHAR_MULTIBYTE (c
);
8005 char_bytes
= CHAR_STRING (c
, str
);
8006 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8010 insert_1 (m
, nbytes
, 1, 0, 0);
8014 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8015 unsigned long int dups
;
8016 insert_1 ("\n", 1, 1, 0, 0);
8018 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8020 this_bol_byte
= PT_BYTE
;
8022 /* See if this line duplicates the previous one.
8023 If so, combine duplicates. */
8026 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8028 prev_bol_byte
= PT_BYTE
;
8030 dups
= message_log_check_duplicate (prev_bol_byte
,
8034 del_range_both (prev_bol
, prev_bol_byte
,
8035 this_bol
, this_bol_byte
, 0);
8041 /* If you change this format, don't forget to also
8042 change message_log_check_duplicate. */
8043 sprintf (dupstr
, " [%lu times]", dups
);
8044 duplen
= strlen (dupstr
);
8045 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8046 insert_1 (dupstr
, duplen
, 1, 0, 1);
8051 /* If we have more than the desired maximum number of lines
8052 in the *Messages* buffer now, delete the oldest ones.
8053 This is safe because we don't have undo in this buffer. */
8055 if (NATNUMP (Vmessage_log_max
))
8057 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8058 -XFASTINT (Vmessage_log_max
) - 1, 0);
8059 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8062 BEGV
= XMARKER (oldbegv
)->charpos
;
8063 BEGV_BYTE
= marker_byte_position (oldbegv
);
8072 ZV
= XMARKER (oldzv
)->charpos
;
8073 ZV_BYTE
= marker_byte_position (oldzv
);
8077 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8079 /* We can't do Fgoto_char (oldpoint) because it will run some
8081 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8082 XMARKER (oldpoint
)->bytepos
);
8085 unchain_marker (XMARKER (oldpoint
));
8086 unchain_marker (XMARKER (oldbegv
));
8087 unchain_marker (XMARKER (oldzv
));
8089 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8090 set_buffer_internal (oldbuf
);
8092 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8093 message_log_need_newline
= !nlflag
;
8094 Vdeactivate_mark
= old_deactivate_mark
;
8099 /* We are at the end of the buffer after just having inserted a newline.
8100 (Note: We depend on the fact we won't be crossing the gap.)
8101 Check to see if the most recent message looks a lot like the previous one.
8102 Return 0 if different, 1 if the new one should just replace it, or a
8103 value N > 1 if we should also append " [N times]". */
8105 static unsigned long int
8106 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8109 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8111 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8112 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8114 for (i
= 0; i
< len
; i
++)
8116 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8124 if (*p1
++ == ' ' && *p1
++ == '[')
8127 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8128 if (strncmp (pend
, " times]\n", 8) == 0)
8135 /* Display an echo area message M with a specified length of NBYTES
8136 bytes. The string may include null characters. If M is 0, clear
8137 out any existing message, and let the mini-buffer text show
8140 This may GC, so the buffer M must NOT point to a Lisp string. */
8143 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8145 /* First flush out any partial line written with print. */
8146 message_log_maybe_newline ();
8148 message_dolog (m
, nbytes
, 1, multibyte
);
8149 message2_nolog (m
, nbytes
, multibyte
);
8153 /* The non-logging counterpart of message2. */
8156 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8158 struct frame
*sf
= SELECTED_FRAME ();
8159 message_enable_multibyte
= multibyte
;
8161 if (FRAME_INITIAL_P (sf
))
8163 if (noninteractive_need_newline
)
8164 putc ('\n', stderr
);
8165 noninteractive_need_newline
= 0;
8167 fwrite (m
, nbytes
, 1, stderr
);
8168 if (cursor_in_echo_area
== 0)
8169 fprintf (stderr
, "\n");
8172 /* A null message buffer means that the frame hasn't really been
8173 initialized yet. Error messages get reported properly by
8174 cmd_error, so this must be just an informative message; toss it. */
8175 else if (INTERACTIVE
8176 && sf
->glyphs_initialized_p
8177 && FRAME_MESSAGE_BUF (sf
))
8179 Lisp_Object mini_window
;
8182 /* Get the frame containing the mini-buffer
8183 that the selected frame is using. */
8184 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8185 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8187 FRAME_SAMPLE_VISIBILITY (f
);
8188 if (FRAME_VISIBLE_P (sf
)
8189 && ! FRAME_VISIBLE_P (f
))
8190 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8194 set_message (m
, Qnil
, nbytes
, multibyte
);
8195 if (minibuffer_auto_raise
)
8196 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8199 clear_message (1, 1);
8201 do_pending_window_change (0);
8202 echo_area_display (1);
8203 do_pending_window_change (0);
8204 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8205 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8210 /* Display an echo area message M with a specified length of NBYTES
8211 bytes. The string may include null characters. If M is not a
8212 string, clear out any existing message, and let the mini-buffer
8215 This function cancels echoing. */
8218 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8220 struct gcpro gcpro1
;
8223 clear_message (1,1);
8226 /* First flush out any partial line written with print. */
8227 message_log_maybe_newline ();
8233 SAFE_ALLOCA (buffer
, char *, nbytes
);
8234 memcpy (buffer
, SDATA (m
), nbytes
);
8235 message_dolog (buffer
, nbytes
, 1, multibyte
);
8238 message3_nolog (m
, nbytes
, multibyte
);
8244 /* The non-logging version of message3.
8245 This does not cancel echoing, because it is used for echoing.
8246 Perhaps we need to make a separate function for echoing
8247 and make this cancel echoing. */
8250 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8252 struct frame
*sf
= SELECTED_FRAME ();
8253 message_enable_multibyte
= multibyte
;
8255 if (FRAME_INITIAL_P (sf
))
8257 if (noninteractive_need_newline
)
8258 putc ('\n', stderr
);
8259 noninteractive_need_newline
= 0;
8261 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8262 if (cursor_in_echo_area
== 0)
8263 fprintf (stderr
, "\n");
8266 /* A null message buffer means that the frame hasn't really been
8267 initialized yet. Error messages get reported properly by
8268 cmd_error, so this must be just an informative message; toss it. */
8269 else if (INTERACTIVE
8270 && sf
->glyphs_initialized_p
8271 && FRAME_MESSAGE_BUF (sf
))
8273 Lisp_Object mini_window
;
8277 /* Get the frame containing the mini-buffer
8278 that the selected frame is using. */
8279 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8280 frame
= XWINDOW (mini_window
)->frame
;
8283 FRAME_SAMPLE_VISIBILITY (f
);
8284 if (FRAME_VISIBLE_P (sf
)
8285 && !FRAME_VISIBLE_P (f
))
8286 Fmake_frame_visible (frame
);
8288 if (STRINGP (m
) && SCHARS (m
) > 0)
8290 set_message (NULL
, m
, nbytes
, multibyte
);
8291 if (minibuffer_auto_raise
)
8292 Fraise_frame (frame
);
8293 /* Assume we are not echoing.
8294 (If we are, echo_now will override this.) */
8295 echo_message_buffer
= Qnil
;
8298 clear_message (1, 1);
8300 do_pending_window_change (0);
8301 echo_area_display (1);
8302 do_pending_window_change (0);
8303 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8304 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8309 /* Display a null-terminated echo area message M. If M is 0, clear
8310 out any existing message, and let the mini-buffer text show through.
8312 The buffer M must continue to exist until after the echo area gets
8313 cleared or some other message gets displayed there. Do not pass
8314 text that is stored in a Lisp string. Do not pass text in a buffer
8315 that was alloca'd. */
8318 message1 (const char *m
)
8320 message2 (m
, (m
? strlen (m
) : 0), 0);
8324 /* The non-logging counterpart of message1. */
8327 message1_nolog (const char *m
)
8329 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8332 /* Display a message M which contains a single %s
8333 which gets replaced with STRING. */
8336 message_with_string (const char *m
, Lisp_Object string
, int log
)
8338 CHECK_STRING (string
);
8344 if (noninteractive_need_newline
)
8345 putc ('\n', stderr
);
8346 noninteractive_need_newline
= 0;
8347 fprintf (stderr
, m
, SDATA (string
));
8348 if (!cursor_in_echo_area
)
8349 fprintf (stderr
, "\n");
8353 else if (INTERACTIVE
)
8355 /* The frame whose minibuffer we're going to display the message on.
8356 It may be larger than the selected frame, so we need
8357 to use its buffer, not the selected frame's buffer. */
8358 Lisp_Object mini_window
;
8359 struct frame
*f
, *sf
= SELECTED_FRAME ();
8361 /* Get the frame containing the minibuffer
8362 that the selected frame is using. */
8363 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8364 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8366 /* A null message buffer means that the frame hasn't really been
8367 initialized yet. Error messages get reported properly by
8368 cmd_error, so this must be just an informative message; toss it. */
8369 if (FRAME_MESSAGE_BUF (f
))
8371 Lisp_Object args
[2], msg
;
8372 struct gcpro gcpro1
, gcpro2
;
8374 args
[0] = build_string (m
);
8375 args
[1] = msg
= string
;
8376 GCPRO2 (args
[0], msg
);
8379 msg
= Fformat (2, args
);
8382 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8384 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8388 /* Print should start at the beginning of the message
8389 buffer next time. */
8390 message_buf_print
= 0;
8396 /* Dump an informative message to the minibuf. If M is 0, clear out
8397 any existing message, and let the mini-buffer text show through. */
8400 vmessage (const char *m
, va_list ap
)
8406 if (noninteractive_need_newline
)
8407 putc ('\n', stderr
);
8408 noninteractive_need_newline
= 0;
8409 vfprintf (stderr
, m
, ap
);
8410 if (cursor_in_echo_area
== 0)
8411 fprintf (stderr
, "\n");
8415 else if (INTERACTIVE
)
8417 /* The frame whose mini-buffer we're going to display the message
8418 on. It may be larger than the selected frame, so we need to
8419 use its buffer, not the selected frame's buffer. */
8420 Lisp_Object mini_window
;
8421 struct frame
*f
, *sf
= SELECTED_FRAME ();
8423 /* Get the frame containing the mini-buffer
8424 that the selected frame is using. */
8425 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8426 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8428 /* A null message buffer means that the frame hasn't really been
8429 initialized yet. Error messages get reported properly by
8430 cmd_error, so this must be just an informative message; toss
8432 if (FRAME_MESSAGE_BUF (f
))
8438 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8439 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8441 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8446 /* Print should start at the beginning of the message
8447 buffer next time. */
8448 message_buf_print
= 0;
8454 message (const char *m
, ...)
8464 /* The non-logging version of message. */
8467 message_nolog (const char *m
, ...)
8469 Lisp_Object old_log_max
;
8472 old_log_max
= Vmessage_log_max
;
8473 Vmessage_log_max
= Qnil
;
8475 Vmessage_log_max
= old_log_max
;
8481 /* Display the current message in the current mini-buffer. This is
8482 only called from error handlers in process.c, and is not time
8486 update_echo_area (void)
8488 if (!NILP (echo_area_buffer
[0]))
8491 string
= Fcurrent_message ();
8492 message3 (string
, SBYTES (string
),
8493 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
8498 /* Make sure echo area buffers in `echo_buffers' are live.
8499 If they aren't, make new ones. */
8502 ensure_echo_area_buffers (void)
8506 for (i
= 0; i
< 2; ++i
)
8507 if (!BUFFERP (echo_buffer
[i
])
8508 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
8511 Lisp_Object old_buffer
;
8514 old_buffer
= echo_buffer
[i
];
8515 sprintf (name
, " *Echo Area %d*", i
);
8516 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8517 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
8518 /* to force word wrap in echo area -
8519 it was decided to postpone this*/
8520 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8522 for (j
= 0; j
< 2; ++j
)
8523 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8524 echo_area_buffer
[j
] = echo_buffer
[i
];
8529 /* Call FN with args A1..A4 with either the current or last displayed
8530 echo_area_buffer as current buffer.
8532 WHICH zero means use the current message buffer
8533 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8534 from echo_buffer[] and clear it.
8536 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8537 suitable buffer from echo_buffer[] and clear it.
8539 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8540 that the current message becomes the last displayed one, make
8541 choose a suitable buffer for echo_area_buffer[0], and clear it.
8543 Value is what FN returns. */
8546 with_echo_area_buffer (struct window
*w
, int which
,
8547 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
8548 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8551 int this_one
, the_other
, clear_buffer_p
, rc
;
8552 int count
= SPECPDL_INDEX ();
8554 /* If buffers aren't live, make new ones. */
8555 ensure_echo_area_buffers ();
8560 this_one
= 0, the_other
= 1;
8562 this_one
= 1, the_other
= 0;
8565 this_one
= 0, the_other
= 1;
8568 /* We need a fresh one in case the current echo buffer equals
8569 the one containing the last displayed echo area message. */
8570 if (!NILP (echo_area_buffer
[this_one
])
8571 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8572 echo_area_buffer
[this_one
] = Qnil
;
8575 /* Choose a suitable buffer from echo_buffer[] is we don't
8577 if (NILP (echo_area_buffer
[this_one
]))
8579 echo_area_buffer
[this_one
]
8580 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8581 ? echo_buffer
[the_other
]
8582 : echo_buffer
[this_one
]);
8586 buffer
= echo_area_buffer
[this_one
];
8588 /* Don't get confused by reusing the buffer used for echoing
8589 for a different purpose. */
8590 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8593 record_unwind_protect (unwind_with_echo_area_buffer
,
8594 with_echo_area_buffer_unwind_data (w
));
8596 /* Make the echo area buffer current. Note that for display
8597 purposes, it is not necessary that the displayed window's buffer
8598 == current_buffer, except for text property lookup. So, let's
8599 only set that buffer temporarily here without doing a full
8600 Fset_window_buffer. We must also change w->pointm, though,
8601 because otherwise an assertions in unshow_buffer fails, and Emacs
8603 set_buffer_internal_1 (XBUFFER (buffer
));
8607 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8610 BVAR (current_buffer
, undo_list
) = Qt
;
8611 BVAR (current_buffer
, read_only
) = Qnil
;
8612 specbind (Qinhibit_read_only
, Qt
);
8613 specbind (Qinhibit_modification_hooks
, Qt
);
8615 if (clear_buffer_p
&& Z
> BEG
)
8618 xassert (BEGV
>= BEG
);
8619 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8621 rc
= fn (a1
, a2
, a3
, a4
);
8623 xassert (BEGV
>= BEG
);
8624 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8626 unbind_to (count
, Qnil
);
8631 /* Save state that should be preserved around the call to the function
8632 FN called in with_echo_area_buffer. */
8635 with_echo_area_buffer_unwind_data (struct window
*w
)
8638 Lisp_Object vector
, tmp
;
8640 /* Reduce consing by keeping one vector in
8641 Vwith_echo_area_save_vector. */
8642 vector
= Vwith_echo_area_save_vector
;
8643 Vwith_echo_area_save_vector
= Qnil
;
8646 vector
= Fmake_vector (make_number (7), Qnil
);
8648 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8649 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8650 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8654 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8655 ASET (vector
, i
, w
->buffer
); ++i
;
8656 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8657 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8662 for (; i
< end
; ++i
)
8663 ASET (vector
, i
, Qnil
);
8666 xassert (i
== ASIZE (vector
));
8671 /* Restore global state from VECTOR which was created by
8672 with_echo_area_buffer_unwind_data. */
8675 unwind_with_echo_area_buffer (Lisp_Object vector
)
8677 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8678 Vdeactivate_mark
= AREF (vector
, 1);
8679 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8681 if (WINDOWP (AREF (vector
, 3)))
8684 Lisp_Object buffer
, charpos
, bytepos
;
8686 w
= XWINDOW (AREF (vector
, 3));
8687 buffer
= AREF (vector
, 4);
8688 charpos
= AREF (vector
, 5);
8689 bytepos
= AREF (vector
, 6);
8692 set_marker_both (w
->pointm
, buffer
,
8693 XFASTINT (charpos
), XFASTINT (bytepos
));
8696 Vwith_echo_area_save_vector
= vector
;
8701 /* Set up the echo area for use by print functions. MULTIBYTE_P
8702 non-zero means we will print multibyte. */
8705 setup_echo_area_for_printing (int multibyte_p
)
8707 /* If we can't find an echo area any more, exit. */
8708 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8711 ensure_echo_area_buffers ();
8713 if (!message_buf_print
)
8715 /* A message has been output since the last time we printed.
8716 Choose a fresh echo area buffer. */
8717 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8718 echo_area_buffer
[0] = echo_buffer
[1];
8720 echo_area_buffer
[0] = echo_buffer
[0];
8722 /* Switch to that buffer and clear it. */
8723 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8724 BVAR (current_buffer
, truncate_lines
) = Qnil
;
8728 int count
= SPECPDL_INDEX ();
8729 specbind (Qinhibit_read_only
, Qt
);
8730 /* Note that undo recording is always disabled. */
8732 unbind_to (count
, Qnil
);
8734 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8736 /* Set up the buffer for the multibyteness we need. */
8738 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8739 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8741 /* Raise the frame containing the echo area. */
8742 if (minibuffer_auto_raise
)
8744 struct frame
*sf
= SELECTED_FRAME ();
8745 Lisp_Object mini_window
;
8746 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8747 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8750 message_log_maybe_newline ();
8751 message_buf_print
= 1;
8755 if (NILP (echo_area_buffer
[0]))
8757 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8758 echo_area_buffer
[0] = echo_buffer
[1];
8760 echo_area_buffer
[0] = echo_buffer
[0];
8763 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8765 /* Someone switched buffers between print requests. */
8766 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8767 BVAR (current_buffer
, truncate_lines
) = Qnil
;
8773 /* Display an echo area message in window W. Value is non-zero if W's
8774 height is changed. If display_last_displayed_message_p is
8775 non-zero, display the message that was last displayed, otherwise
8776 display the current message. */
8779 display_echo_area (struct window
*w
)
8781 int i
, no_message_p
, window_height_changed_p
, count
;
8783 /* Temporarily disable garbage collections while displaying the echo
8784 area. This is done because a GC can print a message itself.
8785 That message would modify the echo area buffer's contents while a
8786 redisplay of the buffer is going on, and seriously confuse
8788 count
= inhibit_garbage_collection ();
8790 /* If there is no message, we must call display_echo_area_1
8791 nevertheless because it resizes the window. But we will have to
8792 reset the echo_area_buffer in question to nil at the end because
8793 with_echo_area_buffer will sets it to an empty buffer. */
8794 i
= display_last_displayed_message_p
? 1 : 0;
8795 no_message_p
= NILP (echo_area_buffer
[i
]);
8797 window_height_changed_p
8798 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8799 display_echo_area_1
,
8800 (intptr_t) w
, Qnil
, 0, 0);
8803 echo_area_buffer
[i
] = Qnil
;
8805 unbind_to (count
, Qnil
);
8806 return window_height_changed_p
;
8810 /* Helper for display_echo_area. Display the current buffer which
8811 contains the current echo area message in window W, a mini-window,
8812 a pointer to which is passed in A1. A2..A4 are currently not used.
8813 Change the height of W so that all of the message is displayed.
8814 Value is non-zero if height of W was changed. */
8817 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8820 struct window
*w
= (struct window
*) i1
;
8822 struct text_pos start
;
8823 int window_height_changed_p
= 0;
8825 /* Do this before displaying, so that we have a large enough glyph
8826 matrix for the display. If we can't get enough space for the
8827 whole text, display the last N lines. That works by setting w->start. */
8828 window_height_changed_p
= resize_mini_window (w
, 0);
8830 /* Use the starting position chosen by resize_mini_window. */
8831 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8834 clear_glyph_matrix (w
->desired_matrix
);
8835 XSETWINDOW (window
, w
);
8836 try_window (window
, start
, 0);
8838 return window_height_changed_p
;
8842 /* Resize the echo area window to exactly the size needed for the
8843 currently displayed message, if there is one. If a mini-buffer
8844 is active, don't shrink it. */
8847 resize_echo_area_exactly (void)
8849 if (BUFFERP (echo_area_buffer
[0])
8850 && WINDOWP (echo_area_window
))
8852 struct window
*w
= XWINDOW (echo_area_window
);
8854 Lisp_Object resize_exactly
;
8856 if (minibuf_level
== 0)
8857 resize_exactly
= Qt
;
8859 resize_exactly
= Qnil
;
8861 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8862 (intptr_t) w
, resize_exactly
,
8866 ++windows_or_buffers_changed
;
8867 ++update_mode_lines
;
8868 redisplay_internal ();
8874 /* Callback function for with_echo_area_buffer, when used from
8875 resize_echo_area_exactly. A1 contains a pointer to the window to
8876 resize, EXACTLY non-nil means resize the mini-window exactly to the
8877 size of the text displayed. A3 and A4 are not used. Value is what
8878 resize_mini_window returns. */
8881 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
8884 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
8888 /* Resize mini-window W to fit the size of its contents. EXACT_P
8889 means size the window exactly to the size needed. Otherwise, it's
8890 only enlarged until W's buffer is empty.
8892 Set W->start to the right place to begin display. If the whole
8893 contents fit, start at the beginning. Otherwise, start so as
8894 to make the end of the contents appear. This is particularly
8895 important for y-or-n-p, but seems desirable generally.
8897 Value is non-zero if the window height has been changed. */
8900 resize_mini_window (struct window
*w
, int exact_p
)
8902 struct frame
*f
= XFRAME (w
->frame
);
8903 int window_height_changed_p
= 0;
8905 xassert (MINI_WINDOW_P (w
));
8907 /* By default, start display at the beginning. */
8908 set_marker_both (w
->start
, w
->buffer
,
8909 BUF_BEGV (XBUFFER (w
->buffer
)),
8910 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8912 /* Don't resize windows while redisplaying a window; it would
8913 confuse redisplay functions when the size of the window they are
8914 displaying changes from under them. Such a resizing can happen,
8915 for instance, when which-func prints a long message while
8916 we are running fontification-functions. We're running these
8917 functions with safe_call which binds inhibit-redisplay to t. */
8918 if (!NILP (Vinhibit_redisplay
))
8921 /* Nil means don't try to resize. */
8922 if (NILP (Vresize_mini_windows
)
8923 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8926 if (!FRAME_MINIBUF_ONLY_P (f
))
8929 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8930 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8931 int height
, max_height
;
8932 int unit
= FRAME_LINE_HEIGHT (f
);
8933 struct text_pos start
;
8934 struct buffer
*old_current_buffer
= NULL
;
8936 if (current_buffer
!= XBUFFER (w
->buffer
))
8938 old_current_buffer
= current_buffer
;
8939 set_buffer_internal (XBUFFER (w
->buffer
));
8942 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8944 /* Compute the max. number of lines specified by the user. */
8945 if (FLOATP (Vmax_mini_window_height
))
8946 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8947 else if (INTEGERP (Vmax_mini_window_height
))
8948 max_height
= XINT (Vmax_mini_window_height
);
8950 max_height
= total_height
/ 4;
8952 /* Correct that max. height if it's bogus. */
8953 max_height
= max (1, max_height
);
8954 max_height
= min (total_height
, max_height
);
8956 /* Find out the height of the text in the window. */
8957 if (it
.line_wrap
== TRUNCATE
)
8962 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8963 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8964 height
= it
.current_y
+ last_height
;
8966 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8967 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8968 height
= (height
+ unit
- 1) / unit
;
8971 /* Compute a suitable window start. */
8972 if (height
> max_height
)
8974 height
= max_height
;
8975 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8976 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8977 start
= it
.current
.pos
;
8980 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8981 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8983 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8985 /* Let it grow only, until we display an empty message, in which
8986 case the window shrinks again. */
8987 if (height
> WINDOW_TOTAL_LINES (w
))
8989 int old_height
= WINDOW_TOTAL_LINES (w
);
8990 freeze_window_starts (f
, 1);
8991 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8992 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8994 else if (height
< WINDOW_TOTAL_LINES (w
)
8995 && (exact_p
|| BEGV
== ZV
))
8997 int old_height
= WINDOW_TOTAL_LINES (w
);
8998 freeze_window_starts (f
, 0);
8999 shrink_mini_window (w
);
9000 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9005 /* Always resize to exact size needed. */
9006 if (height
> WINDOW_TOTAL_LINES (w
))
9008 int old_height
= WINDOW_TOTAL_LINES (w
);
9009 freeze_window_starts (f
, 1);
9010 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9011 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9013 else if (height
< WINDOW_TOTAL_LINES (w
))
9015 int old_height
= WINDOW_TOTAL_LINES (w
);
9016 freeze_window_starts (f
, 0);
9017 shrink_mini_window (w
);
9021 freeze_window_starts (f
, 1);
9022 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9025 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9029 if (old_current_buffer
)
9030 set_buffer_internal (old_current_buffer
);
9033 return window_height_changed_p
;
9037 /* Value is the current message, a string, or nil if there is no
9041 current_message (void)
9045 if (!BUFFERP (echo_area_buffer
[0]))
9049 with_echo_area_buffer (0, 0, current_message_1
,
9050 (intptr_t) &msg
, Qnil
, 0, 0);
9052 echo_area_buffer
[0] = Qnil
;
9060 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9063 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9066 *msg
= make_buffer_string (BEG
, Z
, 1);
9073 /* Push the current message on Vmessage_stack for later restauration
9074 by restore_message. Value is non-zero if the current message isn't
9075 empty. This is a relatively infrequent operation, so it's not
9076 worth optimizing. */
9082 msg
= current_message ();
9083 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9084 return STRINGP (msg
);
9088 /* Restore message display from the top of Vmessage_stack. */
9091 restore_message (void)
9095 xassert (CONSP (Vmessage_stack
));
9096 msg
= XCAR (Vmessage_stack
);
9098 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9100 message3_nolog (msg
, 0, 0);
9104 /* Handler for record_unwind_protect calling pop_message. */
9107 pop_message_unwind (Lisp_Object dummy
)
9113 /* Pop the top-most entry off Vmessage_stack. */
9118 xassert (CONSP (Vmessage_stack
));
9119 Vmessage_stack
= XCDR (Vmessage_stack
);
9123 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9124 exits. If the stack is not empty, we have a missing pop_message
9128 check_message_stack (void)
9130 if (!NILP (Vmessage_stack
))
9135 /* Truncate to NCHARS what will be displayed in the echo area the next
9136 time we display it---but don't redisplay it now. */
9139 truncate_echo_area (EMACS_INT nchars
)
9142 echo_area_buffer
[0] = Qnil
;
9143 /* A null message buffer means that the frame hasn't really been
9144 initialized yet. Error messages get reported properly by
9145 cmd_error, so this must be just an informative message; toss it. */
9146 else if (!noninteractive
9148 && !NILP (echo_area_buffer
[0]))
9150 struct frame
*sf
= SELECTED_FRAME ();
9151 if (FRAME_MESSAGE_BUF (sf
))
9152 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9157 /* Helper function for truncate_echo_area. Truncate the current
9158 message to at most NCHARS characters. */
9161 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9163 if (BEG
+ nchars
< Z
)
9164 del_range (BEG
+ nchars
, Z
);
9166 echo_area_buffer
[0] = Qnil
;
9171 /* Set the current message to a substring of S or STRING.
9173 If STRING is a Lisp string, set the message to the first NBYTES
9174 bytes from STRING. NBYTES zero means use the whole string. If
9175 STRING is multibyte, the message will be displayed multibyte.
9177 If S is not null, set the message to the first LEN bytes of S. LEN
9178 zero means use the whole string. MULTIBYTE_P non-zero means S is
9179 multibyte. Display the message multibyte in that case.
9181 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9182 to t before calling set_message_1 (which calls insert).
9186 set_message (const char *s
, Lisp_Object string
,
9187 EMACS_INT nbytes
, int multibyte_p
)
9189 message_enable_multibyte
9190 = ((s
&& multibyte_p
)
9191 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9193 with_echo_area_buffer (0, -1, set_message_1
,
9194 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9195 message_buf_print
= 0;
9196 help_echo_showing_p
= 0;
9200 /* Helper function for set_message. Arguments have the same meaning
9201 as there, with A1 corresponding to S and A2 corresponding to STRING
9202 This function is called with the echo area buffer being
9206 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9209 const char *s
= (const char *) i1
;
9210 const unsigned char *msg
= (const unsigned char *) s
;
9211 Lisp_Object string
= a2
;
9213 /* Change multibyteness of the echo buffer appropriately. */
9214 if (message_enable_multibyte
9215 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9216 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9218 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9219 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9220 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9222 /* Insert new message at BEG. */
9223 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9225 if (STRINGP (string
))
9230 nbytes
= SBYTES (string
);
9231 nchars
= string_byte_to_char (string
, nbytes
);
9233 /* This function takes care of single/multibyte conversion. We
9234 just have to ensure that the echo area buffer has the right
9235 setting of enable_multibyte_characters. */
9236 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9241 nbytes
= strlen (s
);
9243 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9245 /* Convert from multi-byte to single-byte. */
9250 /* Convert a multibyte string to single-byte. */
9251 for (i
= 0; i
< nbytes
; i
+= n
)
9253 c
= string_char_and_length (msg
+ i
, &n
);
9254 work
[0] = (ASCII_CHAR_P (c
)
9256 : multibyte_char_to_unibyte (c
));
9257 insert_1_both (work
, 1, 1, 1, 0, 0);
9260 else if (!multibyte_p
9261 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9263 /* Convert from single-byte to multi-byte. */
9266 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9268 /* Convert a single-byte string to multibyte. */
9269 for (i
= 0; i
< nbytes
; i
++)
9272 MAKE_CHAR_MULTIBYTE (c
);
9273 n
= CHAR_STRING (c
, str
);
9274 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9278 insert_1 (s
, nbytes
, 1, 0, 0);
9285 /* Clear messages. CURRENT_P non-zero means clear the current
9286 message. LAST_DISPLAYED_P non-zero means clear the message
9290 clear_message (int current_p
, int last_displayed_p
)
9294 echo_area_buffer
[0] = Qnil
;
9295 message_cleared_p
= 1;
9298 if (last_displayed_p
)
9299 echo_area_buffer
[1] = Qnil
;
9301 message_buf_print
= 0;
9304 /* Clear garbaged frames.
9306 This function is used where the old redisplay called
9307 redraw_garbaged_frames which in turn called redraw_frame which in
9308 turn called clear_frame. The call to clear_frame was a source of
9309 flickering. I believe a clear_frame is not necessary. It should
9310 suffice in the new redisplay to invalidate all current matrices,
9311 and ensure a complete redisplay of all windows. */
9314 clear_garbaged_frames (void)
9318 Lisp_Object tail
, frame
;
9319 int changed_count
= 0;
9321 FOR_EACH_FRAME (tail
, frame
)
9323 struct frame
*f
= XFRAME (frame
);
9325 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9329 Fredraw_frame (frame
);
9330 f
->force_flush_display_p
= 1;
9332 clear_current_matrices (f
);
9341 ++windows_or_buffers_changed
;
9346 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9347 is non-zero update selected_frame. Value is non-zero if the
9348 mini-windows height has been changed. */
9351 echo_area_display (int update_frame_p
)
9353 Lisp_Object mini_window
;
9356 int window_height_changed_p
= 0;
9357 struct frame
*sf
= SELECTED_FRAME ();
9359 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9360 w
= XWINDOW (mini_window
);
9361 f
= XFRAME (WINDOW_FRAME (w
));
9363 /* Don't display if frame is invisible or not yet initialized. */
9364 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9367 #ifdef HAVE_WINDOW_SYSTEM
9368 /* When Emacs starts, selected_frame may be the initial terminal
9369 frame. If we let this through, a message would be displayed on
9371 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9373 #endif /* HAVE_WINDOW_SYSTEM */
9375 /* Redraw garbaged frames. */
9377 clear_garbaged_frames ();
9379 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9381 echo_area_window
= mini_window
;
9382 window_height_changed_p
= display_echo_area (w
);
9383 w
->must_be_updated_p
= 1;
9385 /* Update the display, unless called from redisplay_internal.
9386 Also don't update the screen during redisplay itself. The
9387 update will happen at the end of redisplay, and an update
9388 here could cause confusion. */
9389 if (update_frame_p
&& !redisplaying_p
)
9393 /* If the display update has been interrupted by pending
9394 input, update mode lines in the frame. Due to the
9395 pending input, it might have been that redisplay hasn't
9396 been called, so that mode lines above the echo area are
9397 garbaged. This looks odd, so we prevent it here. */
9398 if (!display_completed
)
9399 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9401 if (window_height_changed_p
9402 /* Don't do this if Emacs is shutting down. Redisplay
9403 needs to run hooks. */
9404 && !NILP (Vrun_hooks
))
9406 /* Must update other windows. Likewise as in other
9407 cases, don't let this update be interrupted by
9409 int count
= SPECPDL_INDEX ();
9410 specbind (Qredisplay_dont_pause
, Qt
);
9411 windows_or_buffers_changed
= 1;
9412 redisplay_internal ();
9413 unbind_to (count
, Qnil
);
9415 else if (FRAME_WINDOW_P (f
) && n
== 0)
9417 /* Window configuration is the same as before.
9418 Can do with a display update of the echo area,
9419 unless we displayed some mode lines. */
9420 update_single_window (w
, 1);
9421 FRAME_RIF (f
)->flush_display (f
);
9424 update_frame (f
, 1, 1);
9426 /* If cursor is in the echo area, make sure that the next
9427 redisplay displays the minibuffer, so that the cursor will
9428 be replaced with what the minibuffer wants. */
9429 if (cursor_in_echo_area
)
9430 ++windows_or_buffers_changed
;
9433 else if (!EQ (mini_window
, selected_window
))
9434 windows_or_buffers_changed
++;
9436 /* Last displayed message is now the current message. */
9437 echo_area_buffer
[1] = echo_area_buffer
[0];
9438 /* Inform read_char that we're not echoing. */
9439 echo_message_buffer
= Qnil
;
9441 /* Prevent redisplay optimization in redisplay_internal by resetting
9442 this_line_start_pos. This is done because the mini-buffer now
9443 displays the message instead of its buffer text. */
9444 if (EQ (mini_window
, selected_window
))
9445 CHARPOS (this_line_start_pos
) = 0;
9447 return window_height_changed_p
;
9452 /***********************************************************************
9453 Mode Lines and Frame Titles
9454 ***********************************************************************/
9456 /* A buffer for constructing non-propertized mode-line strings and
9457 frame titles in it; allocated from the heap in init_xdisp and
9458 resized as needed in store_mode_line_noprop_char. */
9460 static char *mode_line_noprop_buf
;
9462 /* The buffer's end, and a current output position in it. */
9464 static char *mode_line_noprop_buf_end
;
9465 static char *mode_line_noprop_ptr
;
9467 #define MODE_LINE_NOPROP_LEN(start) \
9468 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9471 MODE_LINE_DISPLAY
= 0,
9477 /* Alist that caches the results of :propertize.
9478 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9479 static Lisp_Object mode_line_proptrans_alist
;
9481 /* List of strings making up the mode-line. */
9482 static Lisp_Object mode_line_string_list
;
9484 /* Base face property when building propertized mode line string. */
9485 static Lisp_Object mode_line_string_face
;
9486 static Lisp_Object mode_line_string_face_prop
;
9489 /* Unwind data for mode line strings */
9491 static Lisp_Object Vmode_line_unwind_vector
;
9494 format_mode_line_unwind_data (struct buffer
*obuf
,
9498 Lisp_Object vector
, tmp
;
9500 /* Reduce consing by keeping one vector in
9501 Vwith_echo_area_save_vector. */
9502 vector
= Vmode_line_unwind_vector
;
9503 Vmode_line_unwind_vector
= Qnil
;
9506 vector
= Fmake_vector (make_number (8), Qnil
);
9508 ASET (vector
, 0, make_number (mode_line_target
));
9509 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9510 ASET (vector
, 2, mode_line_string_list
);
9511 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9512 ASET (vector
, 4, mode_line_string_face
);
9513 ASET (vector
, 5, mode_line_string_face_prop
);
9516 XSETBUFFER (tmp
, obuf
);
9519 ASET (vector
, 6, tmp
);
9520 ASET (vector
, 7, owin
);
9526 unwind_format_mode_line (Lisp_Object vector
)
9528 mode_line_target
= XINT (AREF (vector
, 0));
9529 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9530 mode_line_string_list
= AREF (vector
, 2);
9531 if (! EQ (AREF (vector
, 3), Qt
))
9532 mode_line_proptrans_alist
= AREF (vector
, 3);
9533 mode_line_string_face
= AREF (vector
, 4);
9534 mode_line_string_face_prop
= AREF (vector
, 5);
9536 if (!NILP (AREF (vector
, 7)))
9537 /* Select window before buffer, since it may change the buffer. */
9538 Fselect_window (AREF (vector
, 7), Qt
);
9540 if (!NILP (AREF (vector
, 6)))
9542 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9543 ASET (vector
, 6, Qnil
);
9546 Vmode_line_unwind_vector
= vector
;
9551 /* Store a single character C for the frame title in mode_line_noprop_buf.
9552 Re-allocate mode_line_noprop_buf if necessary. */
9555 store_mode_line_noprop_char (char c
)
9557 /* If output position has reached the end of the allocated buffer,
9558 double the buffer's size. */
9559 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9561 int len
= MODE_LINE_NOPROP_LEN (0);
9562 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9563 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9564 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9565 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9568 *mode_line_noprop_ptr
++ = c
;
9572 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9573 mode_line_noprop_ptr. STRING is the string to store. Do not copy
9574 characters that yield more columns than PRECISION; PRECISION <= 0
9575 means copy the whole string. Pad with spaces until FIELD_WIDTH
9576 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9577 pad. Called from display_mode_element when it is used to build a
9581 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
9583 const unsigned char *str
= (const unsigned char *) string
;
9585 EMACS_INT dummy
, nbytes
;
9587 /* Copy at most PRECISION chars from STR. */
9588 nbytes
= strlen (string
);
9589 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9591 store_mode_line_noprop_char (*str
++);
9593 /* Fill up with spaces until FIELD_WIDTH reached. */
9594 while (field_width
> 0
9597 store_mode_line_noprop_char (' ');
9604 /***********************************************************************
9606 ***********************************************************************/
9608 #ifdef HAVE_WINDOW_SYSTEM
9610 /* Set the title of FRAME, if it has changed. The title format is
9611 Vicon_title_format if FRAME is iconified, otherwise it is
9612 frame_title_format. */
9615 x_consider_frame_title (Lisp_Object frame
)
9617 struct frame
*f
= XFRAME (frame
);
9619 if (FRAME_WINDOW_P (f
)
9620 || FRAME_MINIBUF_ONLY_P (f
)
9621 || f
->explicit_name
)
9623 /* Do we have more than one visible frame on this X display? */
9630 int count
= SPECPDL_INDEX ();
9632 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9634 Lisp_Object other_frame
= XCAR (tail
);
9635 struct frame
*tf
= XFRAME (other_frame
);
9638 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9639 && !FRAME_MINIBUF_ONLY_P (tf
)
9640 && !EQ (other_frame
, tip_frame
)
9641 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9645 /* Set global variable indicating that multiple frames exist. */
9646 multiple_frames
= CONSP (tail
);
9648 /* Switch to the buffer of selected window of the frame. Set up
9649 mode_line_target so that display_mode_element will output into
9650 mode_line_noprop_buf; then display the title. */
9651 record_unwind_protect (unwind_format_mode_line
,
9652 format_mode_line_unwind_data
9653 (current_buffer
, selected_window
, 0));
9655 Fselect_window (f
->selected_window
, Qt
);
9656 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9657 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9659 mode_line_target
= MODE_LINE_TITLE
;
9660 title_start
= MODE_LINE_NOPROP_LEN (0);
9661 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9662 NULL
, DEFAULT_FACE_ID
);
9663 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9664 len
= MODE_LINE_NOPROP_LEN (title_start
);
9665 title
= mode_line_noprop_buf
+ title_start
;
9666 unbind_to (count
, Qnil
);
9668 /* Set the title only if it's changed. This avoids consing in
9669 the common case where it hasn't. (If it turns out that we've
9670 already wasted too much time by walking through the list with
9671 display_mode_element, then we might need to optimize at a
9672 higher level than this.) */
9673 if (! STRINGP (f
->name
)
9674 || SBYTES (f
->name
) != len
9675 || memcmp (title
, SDATA (f
->name
), len
) != 0)
9676 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9680 #endif /* not HAVE_WINDOW_SYSTEM */
9685 /***********************************************************************
9687 ***********************************************************************/
9690 /* Prepare for redisplay by updating menu-bar item lists when
9691 appropriate. This can call eval. */
9694 prepare_menu_bars (void)
9697 struct gcpro gcpro1
, gcpro2
;
9699 Lisp_Object tooltip_frame
;
9701 #ifdef HAVE_WINDOW_SYSTEM
9702 tooltip_frame
= tip_frame
;
9704 tooltip_frame
= Qnil
;
9707 /* Update all frame titles based on their buffer names, etc. We do
9708 this before the menu bars so that the buffer-menu will show the
9709 up-to-date frame titles. */
9710 #ifdef HAVE_WINDOW_SYSTEM
9711 if (windows_or_buffers_changed
|| update_mode_lines
)
9713 Lisp_Object tail
, frame
;
9715 FOR_EACH_FRAME (tail
, frame
)
9718 if (!EQ (frame
, tooltip_frame
)
9719 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9720 x_consider_frame_title (frame
);
9723 #endif /* HAVE_WINDOW_SYSTEM */
9725 /* Update the menu bar item lists, if appropriate. This has to be
9726 done before any actual redisplay or generation of display lines. */
9727 all_windows
= (update_mode_lines
9728 || buffer_shared
> 1
9729 || windows_or_buffers_changed
);
9732 Lisp_Object tail
, frame
;
9733 int count
= SPECPDL_INDEX ();
9734 /* 1 means that update_menu_bar has run its hooks
9735 so any further calls to update_menu_bar shouldn't do so again. */
9736 int menu_bar_hooks_run
= 0;
9738 record_unwind_save_match_data ();
9740 FOR_EACH_FRAME (tail
, frame
)
9744 /* Ignore tooltip frame. */
9745 if (EQ (frame
, tooltip_frame
))
9748 /* If a window on this frame changed size, report that to
9749 the user and clear the size-change flag. */
9750 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9752 Lisp_Object functions
;
9754 /* Clear flag first in case we get an error below. */
9755 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9756 functions
= Vwindow_size_change_functions
;
9757 GCPRO2 (tail
, functions
);
9759 while (CONSP (functions
))
9761 if (!EQ (XCAR (functions
), Qt
))
9762 call1 (XCAR (functions
), frame
);
9763 functions
= XCDR (functions
);
9769 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9770 #ifdef HAVE_WINDOW_SYSTEM
9771 update_tool_bar (f
, 0);
9774 if (windows_or_buffers_changed
9776 ns_set_doc_edited (f
, Fbuffer_modified_p
9777 (XWINDOW (f
->selected_window
)->buffer
));
9782 unbind_to (count
, Qnil
);
9786 struct frame
*sf
= SELECTED_FRAME ();
9787 update_menu_bar (sf
, 1, 0);
9788 #ifdef HAVE_WINDOW_SYSTEM
9789 update_tool_bar (sf
, 1);
9795 /* Update the menu bar item list for frame F. This has to be done
9796 before we start to fill in any display lines, because it can call
9799 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9801 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9802 already ran the menu bar hooks for this redisplay, so there
9803 is no need to run them again. The return value is the
9804 updated value of this flag, to pass to the next call. */
9807 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
9810 register struct window
*w
;
9812 /* If called recursively during a menu update, do nothing. This can
9813 happen when, for instance, an activate-menubar-hook causes a
9815 if (inhibit_menubar_update
)
9818 window
= FRAME_SELECTED_WINDOW (f
);
9819 w
= XWINDOW (window
);
9821 if (FRAME_WINDOW_P (f
)
9823 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9824 || defined (HAVE_NS) || defined (USE_GTK)
9825 FRAME_EXTERNAL_MENU_BAR (f
)
9827 FRAME_MENU_BAR_LINES (f
) > 0
9829 : FRAME_MENU_BAR_LINES (f
) > 0)
9831 /* If the user has switched buffers or windows, we need to
9832 recompute to reflect the new bindings. But we'll
9833 recompute when update_mode_lines is set too; that means
9834 that people can use force-mode-line-update to request
9835 that the menu bar be recomputed. The adverse effect on
9836 the rest of the redisplay algorithm is about the same as
9837 windows_or_buffers_changed anyway. */
9838 if (windows_or_buffers_changed
9839 /* This used to test w->update_mode_line, but we believe
9840 there is no need to recompute the menu in that case. */
9841 || update_mode_lines
9842 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9843 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9844 != !NILP (w
->last_had_star
))
9845 || ((!NILP (Vtransient_mark_mode
)
9846 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
9847 != !NILP (w
->region_showing
)))
9849 struct buffer
*prev
= current_buffer
;
9850 int count
= SPECPDL_INDEX ();
9852 specbind (Qinhibit_menubar_update
, Qt
);
9854 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9855 if (save_match_data
)
9856 record_unwind_save_match_data ();
9857 if (NILP (Voverriding_local_map_menu_flag
))
9859 specbind (Qoverriding_terminal_local_map
, Qnil
);
9860 specbind (Qoverriding_local_map
, Qnil
);
9865 /* Run the Lucid hook. */
9866 safe_run_hooks (Qactivate_menubar_hook
);
9868 /* If it has changed current-menubar from previous value,
9869 really recompute the menu-bar from the value. */
9870 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9871 call0 (Qrecompute_lucid_menubar
);
9873 safe_run_hooks (Qmenu_bar_update_hook
);
9878 XSETFRAME (Vmenu_updating_frame
, f
);
9879 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9881 /* Redisplay the menu bar in case we changed it. */
9882 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9883 || defined (HAVE_NS) || defined (USE_GTK)
9884 if (FRAME_WINDOW_P (f
))
9886 #if defined (HAVE_NS)
9887 /* All frames on Mac OS share the same menubar. So only
9888 the selected frame should be allowed to set it. */
9889 if (f
== SELECTED_FRAME ())
9891 set_frame_menubar (f
, 0, 0);
9894 /* On a terminal screen, the menu bar is an ordinary screen
9895 line, and this makes it get updated. */
9896 w
->update_mode_line
= Qt
;
9897 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9898 /* In the non-toolkit version, the menu bar is an ordinary screen
9899 line, and this makes it get updated. */
9900 w
->update_mode_line
= Qt
;
9901 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9903 unbind_to (count
, Qnil
);
9904 set_buffer_internal_1 (prev
);
9913 /***********************************************************************
9915 ***********************************************************************/
9917 #ifdef HAVE_WINDOW_SYSTEM
9920 Nominal cursor position -- where to draw output.
9921 HPOS and VPOS are window relative glyph matrix coordinates.
9922 X and Y are window relative pixel coordinates. */
9924 struct cursor_pos output_cursor
;
9928 Set the global variable output_cursor to CURSOR. All cursor
9929 positions are relative to updated_window. */
9932 set_output_cursor (struct cursor_pos
*cursor
)
9934 output_cursor
.hpos
= cursor
->hpos
;
9935 output_cursor
.vpos
= cursor
->vpos
;
9936 output_cursor
.x
= cursor
->x
;
9937 output_cursor
.y
= cursor
->y
;
9942 Set a nominal cursor position.
9944 HPOS and VPOS are column/row positions in a window glyph matrix. X
9945 and Y are window text area relative pixel positions.
9947 If this is done during an update, updated_window will contain the
9948 window that is being updated and the position is the future output
9949 cursor position for that window. If updated_window is null, use
9950 selected_window and display the cursor at the given position. */
9953 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
9957 /* If updated_window is not set, work on selected_window. */
9961 w
= XWINDOW (selected_window
);
9963 /* Set the output cursor. */
9964 output_cursor
.hpos
= hpos
;
9965 output_cursor
.vpos
= vpos
;
9966 output_cursor
.x
= x
;
9967 output_cursor
.y
= y
;
9969 /* If not called as part of an update, really display the cursor.
9970 This will also set the cursor position of W. */
9971 if (updated_window
== NULL
)
9974 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9975 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9976 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9981 #endif /* HAVE_WINDOW_SYSTEM */
9984 /***********************************************************************
9986 ***********************************************************************/
9988 #ifdef HAVE_WINDOW_SYSTEM
9990 /* Where the mouse was last time we reported a mouse event. */
9992 FRAME_PTR last_mouse_frame
;
9994 /* Tool-bar item index of the item on which a mouse button was pressed
9997 int last_tool_bar_item
;
10001 update_tool_bar_unwind (Lisp_Object frame
)
10003 selected_frame
= frame
;
10007 /* Update the tool-bar item list for frame F. This has to be done
10008 before we start to fill in any display lines. Called from
10009 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10010 and restore it here. */
10013 update_tool_bar (struct frame
*f
, int save_match_data
)
10015 #if defined (USE_GTK) || defined (HAVE_NS)
10016 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10018 int do_update
= WINDOWP (f
->tool_bar_window
)
10019 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10024 Lisp_Object window
;
10027 window
= FRAME_SELECTED_WINDOW (f
);
10028 w
= XWINDOW (window
);
10030 /* If the user has switched buffers or windows, we need to
10031 recompute to reflect the new bindings. But we'll
10032 recompute when update_mode_lines is set too; that means
10033 that people can use force-mode-line-update to request
10034 that the menu bar be recomputed. The adverse effect on
10035 the rest of the redisplay algorithm is about the same as
10036 windows_or_buffers_changed anyway. */
10037 if (windows_or_buffers_changed
10038 || !NILP (w
->update_mode_line
)
10039 || update_mode_lines
10040 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10041 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10042 != !NILP (w
->last_had_star
))
10043 || ((!NILP (Vtransient_mark_mode
)
10044 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10045 != !NILP (w
->region_showing
)))
10047 struct buffer
*prev
= current_buffer
;
10048 int count
= SPECPDL_INDEX ();
10049 Lisp_Object frame
, new_tool_bar
;
10050 int new_n_tool_bar
;
10051 struct gcpro gcpro1
;
10053 /* Set current_buffer to the buffer of the selected
10054 window of the frame, so that we get the right local
10056 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10058 /* Save match data, if we must. */
10059 if (save_match_data
)
10060 record_unwind_save_match_data ();
10062 /* Make sure that we don't accidentally use bogus keymaps. */
10063 if (NILP (Voverriding_local_map_menu_flag
))
10065 specbind (Qoverriding_terminal_local_map
, Qnil
);
10066 specbind (Qoverriding_local_map
, Qnil
);
10069 GCPRO1 (new_tool_bar
);
10071 /* We must temporarily set the selected frame to this frame
10072 before calling tool_bar_items, because the calculation of
10073 the tool-bar keymap uses the selected frame (see
10074 `tool-bar-make-keymap' in tool-bar.el). */
10075 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10076 XSETFRAME (frame
, f
);
10077 selected_frame
= frame
;
10079 /* Build desired tool-bar items from keymaps. */
10080 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10083 /* Redisplay the tool-bar if we changed it. */
10084 if (new_n_tool_bar
!= f
->n_tool_bar_items
10085 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10087 /* Redisplay that happens asynchronously due to an expose event
10088 may access f->tool_bar_items. Make sure we update both
10089 variables within BLOCK_INPUT so no such event interrupts. */
10091 f
->tool_bar_items
= new_tool_bar
;
10092 f
->n_tool_bar_items
= new_n_tool_bar
;
10093 w
->update_mode_line
= Qt
;
10099 unbind_to (count
, Qnil
);
10100 set_buffer_internal_1 (prev
);
10106 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10107 F's desired tool-bar contents. F->tool_bar_items must have
10108 been set up previously by calling prepare_menu_bars. */
10111 build_desired_tool_bar_string (struct frame
*f
)
10113 int i
, size
, size_needed
;
10114 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10115 Lisp_Object image
, plist
, props
;
10117 image
= plist
= props
= Qnil
;
10118 GCPRO3 (image
, plist
, props
);
10120 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10121 Otherwise, make a new string. */
10123 /* The size of the string we might be able to reuse. */
10124 size
= (STRINGP (f
->desired_tool_bar_string
)
10125 ? SCHARS (f
->desired_tool_bar_string
)
10128 /* We need one space in the string for each image. */
10129 size_needed
= f
->n_tool_bar_items
;
10131 /* Reuse f->desired_tool_bar_string, if possible. */
10132 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10133 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10134 make_number (' '));
10137 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10138 Fremove_text_properties (make_number (0), make_number (size
),
10139 props
, f
->desired_tool_bar_string
);
10142 /* Put a `display' property on the string for the images to display,
10143 put a `menu_item' property on tool-bar items with a value that
10144 is the index of the item in F's tool-bar item vector. */
10145 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10147 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10149 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10150 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10151 int hmargin
, vmargin
, relief
, idx
, end
;
10153 /* If image is a vector, choose the image according to the
10155 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10156 if (VECTORP (image
))
10160 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10161 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10164 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10165 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10167 xassert (ASIZE (image
) >= idx
);
10168 image
= AREF (image
, idx
);
10173 /* Ignore invalid image specifications. */
10174 if (!valid_image_p (image
))
10177 /* Display the tool-bar button pressed, or depressed. */
10178 plist
= Fcopy_sequence (XCDR (image
));
10180 /* Compute margin and relief to draw. */
10181 relief
= (tool_bar_button_relief
>= 0
10182 ? tool_bar_button_relief
10183 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10184 hmargin
= vmargin
= relief
;
10186 if (INTEGERP (Vtool_bar_button_margin
)
10187 && XINT (Vtool_bar_button_margin
) > 0)
10189 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10190 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10192 else if (CONSP (Vtool_bar_button_margin
))
10194 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10195 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10196 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10198 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10199 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10200 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10203 if (auto_raise_tool_bar_buttons_p
)
10205 /* Add a `:relief' property to the image spec if the item is
10209 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10216 /* If image is selected, display it pressed, i.e. with a
10217 negative relief. If it's not selected, display it with a
10219 plist
= Fplist_put (plist
, QCrelief
,
10221 ? make_number (-relief
)
10222 : make_number (relief
)));
10227 /* Put a margin around the image. */
10228 if (hmargin
|| vmargin
)
10230 if (hmargin
== vmargin
)
10231 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10233 plist
= Fplist_put (plist
, QCmargin
,
10234 Fcons (make_number (hmargin
),
10235 make_number (vmargin
)));
10238 /* If button is not enabled, and we don't have special images
10239 for the disabled state, make the image appear disabled by
10240 applying an appropriate algorithm to it. */
10241 if (!enabled_p
&& idx
< 0)
10242 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10244 /* Put a `display' text property on the string for the image to
10245 display. Put a `menu-item' property on the string that gives
10246 the start of this item's properties in the tool-bar items
10248 image
= Fcons (Qimage
, plist
);
10249 props
= list4 (Qdisplay
, image
,
10250 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10252 /* Let the last image hide all remaining spaces in the tool bar
10253 string. The string can be longer than needed when we reuse a
10254 previous string. */
10255 if (i
+ 1 == f
->n_tool_bar_items
)
10256 end
= SCHARS (f
->desired_tool_bar_string
);
10259 Fadd_text_properties (make_number (i
), make_number (end
),
10260 props
, f
->desired_tool_bar_string
);
10268 /* Display one line of the tool-bar of frame IT->f.
10270 HEIGHT specifies the desired height of the tool-bar line.
10271 If the actual height of the glyph row is less than HEIGHT, the
10272 row's height is increased to HEIGHT, and the icons are centered
10273 vertically in the new height.
10275 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10276 count a final empty row in case the tool-bar width exactly matches
10281 display_tool_bar_line (struct it
*it
, int height
)
10283 struct glyph_row
*row
= it
->glyph_row
;
10284 int max_x
= it
->last_visible_x
;
10285 struct glyph
*last
;
10287 prepare_desired_row (row
);
10288 row
->y
= it
->current_y
;
10290 /* Note that this isn't made use of if the face hasn't a box,
10291 so there's no need to check the face here. */
10292 it
->start_of_box_run_p
= 1;
10294 while (it
->current_x
< max_x
)
10296 int x
, n_glyphs_before
, i
, nglyphs
;
10297 struct it it_before
;
10299 /* Get the next display element. */
10300 if (!get_next_display_element (it
))
10302 /* Don't count empty row if we are counting needed tool-bar lines. */
10303 if (height
< 0 && !it
->hpos
)
10308 /* Produce glyphs. */
10309 n_glyphs_before
= row
->used
[TEXT_AREA
];
10312 PRODUCE_GLYPHS (it
);
10314 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10316 x
= it_before
.current_x
;
10317 while (i
< nglyphs
)
10319 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10321 if (x
+ glyph
->pixel_width
> max_x
)
10323 /* Glyph doesn't fit on line. Backtrack. */
10324 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10326 /* If this is the only glyph on this line, it will never fit on the
10327 tool-bar, so skip it. But ensure there is at least one glyph,
10328 so we don't accidentally disable the tool-bar. */
10329 if (n_glyphs_before
== 0
10330 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10336 x
+= glyph
->pixel_width
;
10340 /* Stop at line ends. */
10341 if (ITERATOR_AT_END_OF_LINE_P (it
))
10344 set_iterator_to_next (it
, 1);
10349 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10351 /* Use default face for the border below the tool bar.
10353 FIXME: When auto-resize-tool-bars is grow-only, there is
10354 no additional border below the possibly empty tool-bar lines.
10355 So to make the extra empty lines look "normal", we have to
10356 use the tool-bar face for the border too. */
10357 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10358 it
->face_id
= DEFAULT_FACE_ID
;
10360 extend_face_to_end_of_line (it
);
10361 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10362 last
->right_box_line_p
= 1;
10363 if (last
== row
->glyphs
[TEXT_AREA
])
10364 last
->left_box_line_p
= 1;
10366 /* Make line the desired height and center it vertically. */
10367 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10369 /* Don't add more than one line height. */
10370 height
%= FRAME_LINE_HEIGHT (it
->f
);
10371 it
->max_ascent
+= height
/ 2;
10372 it
->max_descent
+= (height
+ 1) / 2;
10375 compute_line_metrics (it
);
10377 /* If line is empty, make it occupy the rest of the tool-bar. */
10378 if (!row
->displays_text_p
)
10380 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10381 row
->visible_height
= row
->height
;
10382 row
->ascent
= row
->phys_ascent
= 0;
10383 row
->extra_line_spacing
= 0;
10386 row
->full_width_p
= 1;
10387 row
->continued_p
= 0;
10388 row
->truncated_on_left_p
= 0;
10389 row
->truncated_on_right_p
= 0;
10391 it
->current_x
= it
->hpos
= 0;
10392 it
->current_y
+= row
->height
;
10398 /* Max tool-bar height. */
10400 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10401 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10403 /* Value is the number of screen lines needed to make all tool-bar
10404 items of frame F visible. The number of actual rows needed is
10405 returned in *N_ROWS if non-NULL. */
10408 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10410 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10412 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10413 the desired matrix, so use (unused) mode-line row as temporary row to
10414 avoid destroying the first tool-bar row. */
10415 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10417 /* Initialize an iterator for iteration over
10418 F->desired_tool_bar_string in the tool-bar window of frame F. */
10419 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10420 it
.first_visible_x
= 0;
10421 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10422 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10424 while (!ITERATOR_AT_END_P (&it
))
10426 clear_glyph_row (temp_row
);
10427 it
.glyph_row
= temp_row
;
10428 display_tool_bar_line (&it
, -1);
10430 clear_glyph_row (temp_row
);
10432 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10434 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10436 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10440 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10442 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10443 (Lisp_Object frame
)
10450 frame
= selected_frame
;
10452 CHECK_FRAME (frame
);
10453 f
= XFRAME (frame
);
10455 if (WINDOWP (f
->tool_bar_window
)
10456 || (w
= XWINDOW (f
->tool_bar_window
),
10457 WINDOW_TOTAL_LINES (w
) > 0))
10459 update_tool_bar (f
, 1);
10460 if (f
->n_tool_bar_items
)
10462 build_desired_tool_bar_string (f
);
10463 nlines
= tool_bar_lines_needed (f
, NULL
);
10467 return make_number (nlines
);
10471 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10472 height should be changed. */
10475 redisplay_tool_bar (struct frame
*f
)
10479 struct glyph_row
*row
;
10481 #if defined (USE_GTK) || defined (HAVE_NS)
10482 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10483 update_frame_tool_bar (f
);
10487 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10488 do anything. This means you must start with tool-bar-lines
10489 non-zero to get the auto-sizing effect. Or in other words, you
10490 can turn off tool-bars by specifying tool-bar-lines zero. */
10491 if (!WINDOWP (f
->tool_bar_window
)
10492 || (w
= XWINDOW (f
->tool_bar_window
),
10493 WINDOW_TOTAL_LINES (w
) == 0))
10496 /* Set up an iterator for the tool-bar window. */
10497 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10498 it
.first_visible_x
= 0;
10499 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10500 row
= it
.glyph_row
;
10502 /* Build a string that represents the contents of the tool-bar. */
10503 build_desired_tool_bar_string (f
);
10504 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10506 if (f
->n_tool_bar_rows
== 0)
10510 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10511 nlines
!= WINDOW_TOTAL_LINES (w
)))
10514 int old_height
= WINDOW_TOTAL_LINES (w
);
10516 XSETFRAME (frame
, f
);
10517 Fmodify_frame_parameters (frame
,
10518 Fcons (Fcons (Qtool_bar_lines
,
10519 make_number (nlines
)),
10521 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10523 clear_glyph_matrix (w
->desired_matrix
);
10524 fonts_changed_p
= 1;
10530 /* Display as many lines as needed to display all tool-bar items. */
10532 if (f
->n_tool_bar_rows
> 0)
10534 int border
, rows
, height
, extra
;
10536 if (INTEGERP (Vtool_bar_border
))
10537 border
= XINT (Vtool_bar_border
);
10538 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10539 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10540 else if (EQ (Vtool_bar_border
, Qborder_width
))
10541 border
= f
->border_width
;
10547 rows
= f
->n_tool_bar_rows
;
10548 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10549 extra
= it
.last_visible_y
- border
- height
* rows
;
10551 while (it
.current_y
< it
.last_visible_y
)
10554 if (extra
> 0 && rows
-- > 0)
10556 h
= (extra
+ rows
- 1) / rows
;
10559 display_tool_bar_line (&it
, height
+ h
);
10564 while (it
.current_y
< it
.last_visible_y
)
10565 display_tool_bar_line (&it
, 0);
10568 /* It doesn't make much sense to try scrolling in the tool-bar
10569 window, so don't do it. */
10570 w
->desired_matrix
->no_scrolling_p
= 1;
10571 w
->must_be_updated_p
= 1;
10573 if (!NILP (Vauto_resize_tool_bars
))
10575 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10576 int change_height_p
= 0;
10578 /* If we couldn't display everything, change the tool-bar's
10579 height if there is room for more. */
10580 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10581 && it
.current_y
< max_tool_bar_height
)
10582 change_height_p
= 1;
10584 row
= it
.glyph_row
- 1;
10586 /* If there are blank lines at the end, except for a partially
10587 visible blank line at the end that is smaller than
10588 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10589 if (!row
->displays_text_p
10590 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10591 change_height_p
= 1;
10593 /* If row displays tool-bar items, but is partially visible,
10594 change the tool-bar's height. */
10595 if (row
->displays_text_p
10596 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10597 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10598 change_height_p
= 1;
10600 /* Resize windows as needed by changing the `tool-bar-lines'
10601 frame parameter. */
10602 if (change_height_p
)
10605 int old_height
= WINDOW_TOTAL_LINES (w
);
10607 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10609 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10610 && !f
->minimize_tool_bar_window_p
)
10611 ? (nlines
> old_height
)
10612 : (nlines
!= old_height
));
10613 f
->minimize_tool_bar_window_p
= 0;
10615 if (change_height_p
)
10617 XSETFRAME (frame
, f
);
10618 Fmodify_frame_parameters (frame
,
10619 Fcons (Fcons (Qtool_bar_lines
,
10620 make_number (nlines
)),
10622 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10624 clear_glyph_matrix (w
->desired_matrix
);
10625 f
->n_tool_bar_rows
= nrows
;
10626 fonts_changed_p
= 1;
10633 f
->minimize_tool_bar_window_p
= 0;
10638 /* Get information about the tool-bar item which is displayed in GLYPH
10639 on frame F. Return in *PROP_IDX the index where tool-bar item
10640 properties start in F->tool_bar_items. Value is zero if
10641 GLYPH doesn't display a tool-bar item. */
10644 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
10650 /* This function can be called asynchronously, which means we must
10651 exclude any possibility that Fget_text_property signals an
10653 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10654 charpos
= max (0, charpos
);
10656 /* Get the text property `menu-item' at pos. The value of that
10657 property is the start index of this item's properties in
10658 F->tool_bar_items. */
10659 prop
= Fget_text_property (make_number (charpos
),
10660 Qmenu_item
, f
->current_tool_bar_string
);
10661 if (INTEGERP (prop
))
10663 *prop_idx
= XINT (prop
);
10673 /* Get information about the tool-bar item at position X/Y on frame F.
10674 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10675 the current matrix of the tool-bar window of F, or NULL if not
10676 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10677 item in F->tool_bar_items. Value is
10679 -1 if X/Y is not on a tool-bar item
10680 0 if X/Y is on the same item that was highlighted before.
10684 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
10685 int *hpos
, int *vpos
, int *prop_idx
)
10687 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10688 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10691 /* Find the glyph under X/Y. */
10692 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10693 if (*glyph
== NULL
)
10696 /* Get the start of this tool-bar item's properties in
10697 f->tool_bar_items. */
10698 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10701 /* Is mouse on the highlighted item? */
10702 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
10703 && *vpos
>= hlinfo
->mouse_face_beg_row
10704 && *vpos
<= hlinfo
->mouse_face_end_row
10705 && (*vpos
> hlinfo
->mouse_face_beg_row
10706 || *hpos
>= hlinfo
->mouse_face_beg_col
)
10707 && (*vpos
< hlinfo
->mouse_face_end_row
10708 || *hpos
< hlinfo
->mouse_face_end_col
10709 || hlinfo
->mouse_face_past_end
))
10717 Handle mouse button event on the tool-bar of frame F, at
10718 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10719 0 for button release. MODIFIERS is event modifiers for button
10723 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
10724 unsigned int modifiers
)
10726 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10727 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10728 int hpos
, vpos
, prop_idx
;
10729 struct glyph
*glyph
;
10730 Lisp_Object enabled_p
;
10732 /* If not on the highlighted tool-bar item, return. */
10733 frame_to_window_pixel_xy (w
, &x
, &y
);
10734 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10737 /* If item is disabled, do nothing. */
10738 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10739 if (NILP (enabled_p
))
10744 /* Show item in pressed state. */
10745 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
10746 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10747 last_tool_bar_item
= prop_idx
;
10751 Lisp_Object key
, frame
;
10752 struct input_event event
;
10753 EVENT_INIT (event
);
10755 /* Show item in released state. */
10756 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
10757 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10759 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10761 XSETFRAME (frame
, f
);
10762 event
.kind
= TOOL_BAR_EVENT
;
10763 event
.frame_or_window
= frame
;
10765 kbd_buffer_store_event (&event
);
10767 event
.kind
= TOOL_BAR_EVENT
;
10768 event
.frame_or_window
= frame
;
10770 event
.modifiers
= modifiers
;
10771 kbd_buffer_store_event (&event
);
10772 last_tool_bar_item
= -1;
10777 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10778 tool-bar window-relative coordinates X/Y. Called from
10779 note_mouse_highlight. */
10782 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
10784 Lisp_Object window
= f
->tool_bar_window
;
10785 struct window
*w
= XWINDOW (window
);
10786 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10787 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10789 struct glyph
*glyph
;
10790 struct glyph_row
*row
;
10792 Lisp_Object enabled_p
;
10794 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10795 int mouse_down_p
, rc
;
10797 /* Function note_mouse_highlight is called with negative X/Y
10798 values when mouse moves outside of the frame. */
10799 if (x
<= 0 || y
<= 0)
10801 clear_mouse_face (hlinfo
);
10805 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10808 /* Not on tool-bar item. */
10809 clear_mouse_face (hlinfo
);
10813 /* On same tool-bar item as before. */
10814 goto set_help_echo
;
10816 clear_mouse_face (hlinfo
);
10818 /* Mouse is down, but on different tool-bar item? */
10819 mouse_down_p
= (dpyinfo
->grabbed
10820 && f
== last_mouse_frame
10821 && FRAME_LIVE_P (f
));
10823 && last_tool_bar_item
!= prop_idx
)
10826 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10827 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10829 /* If tool-bar item is not enabled, don't highlight it. */
10830 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10831 if (!NILP (enabled_p
))
10833 /* Compute the x-position of the glyph. In front and past the
10834 image is a space. We include this in the highlighted area. */
10835 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10836 for (i
= x
= 0; i
< hpos
; ++i
)
10837 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10839 /* Record this as the current active region. */
10840 hlinfo
->mouse_face_beg_col
= hpos
;
10841 hlinfo
->mouse_face_beg_row
= vpos
;
10842 hlinfo
->mouse_face_beg_x
= x
;
10843 hlinfo
->mouse_face_beg_y
= row
->y
;
10844 hlinfo
->mouse_face_past_end
= 0;
10846 hlinfo
->mouse_face_end_col
= hpos
+ 1;
10847 hlinfo
->mouse_face_end_row
= vpos
;
10848 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10849 hlinfo
->mouse_face_end_y
= row
->y
;
10850 hlinfo
->mouse_face_window
= window
;
10851 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10853 /* Display it as active. */
10854 show_mouse_face (hlinfo
, draw
);
10855 hlinfo
->mouse_face_image_state
= draw
;
10860 /* Set help_echo_string to a help string to display for this tool-bar item.
10861 XTread_socket does the rest. */
10862 help_echo_object
= help_echo_window
= Qnil
;
10863 help_echo_pos
= -1;
10864 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10865 if (NILP (help_echo_string
))
10866 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10869 #endif /* HAVE_WINDOW_SYSTEM */
10873 /************************************************************************
10874 Horizontal scrolling
10875 ************************************************************************/
10877 static int hscroll_window_tree (Lisp_Object
);
10878 static int hscroll_windows (Lisp_Object
);
10880 /* For all leaf windows in the window tree rooted at WINDOW, set their
10881 hscroll value so that PT is (i) visible in the window, and (ii) so
10882 that it is not within a certain margin at the window's left and
10883 right border. Value is non-zero if any window's hscroll has been
10887 hscroll_window_tree (Lisp_Object window
)
10889 int hscrolled_p
= 0;
10890 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10891 int hscroll_step_abs
= 0;
10892 double hscroll_step_rel
= 0;
10894 if (hscroll_relative_p
)
10896 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10897 if (hscroll_step_rel
< 0)
10899 hscroll_relative_p
= 0;
10900 hscroll_step_abs
= 0;
10903 else if (INTEGERP (Vhscroll_step
))
10905 hscroll_step_abs
= XINT (Vhscroll_step
);
10906 if (hscroll_step_abs
< 0)
10907 hscroll_step_abs
= 0;
10910 hscroll_step_abs
= 0;
10912 while (WINDOWP (window
))
10914 struct window
*w
= XWINDOW (window
);
10916 if (WINDOWP (w
->hchild
))
10917 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10918 else if (WINDOWP (w
->vchild
))
10919 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10920 else if (w
->cursor
.vpos
>= 0)
10923 int text_area_width
;
10924 struct glyph_row
*current_cursor_row
10925 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10926 struct glyph_row
*desired_cursor_row
10927 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10928 struct glyph_row
*cursor_row
10929 = (desired_cursor_row
->enabled_p
10930 ? desired_cursor_row
10931 : current_cursor_row
);
10933 text_area_width
= window_box_width (w
, TEXT_AREA
);
10935 /* Scroll when cursor is inside this scroll margin. */
10936 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10938 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10939 && ((XFASTINT (w
->hscroll
)
10940 && w
->cursor
.x
<= h_margin
)
10941 || (cursor_row
->enabled_p
10942 && cursor_row
->truncated_on_right_p
10943 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10947 struct buffer
*saved_current_buffer
;
10951 /* Find point in a display of infinite width. */
10952 saved_current_buffer
= current_buffer
;
10953 current_buffer
= XBUFFER (w
->buffer
);
10955 if (w
== XWINDOW (selected_window
))
10959 pt
= marker_position (w
->pointm
);
10960 pt
= max (BEGV
, pt
);
10964 /* Move iterator to pt starting at cursor_row->start in
10965 a line with infinite width. */
10966 init_to_row_start (&it
, w
, cursor_row
);
10967 it
.last_visible_x
= INFINITY
;
10968 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10969 current_buffer
= saved_current_buffer
;
10971 /* Position cursor in window. */
10972 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10973 hscroll
= max (0, (it
.current_x
10974 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10975 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10976 : (text_area_width
/ 2))))
10977 / FRAME_COLUMN_WIDTH (it
.f
);
10978 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10980 if (hscroll_relative_p
)
10981 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10984 wanted_x
= text_area_width
10985 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10988 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10992 if (hscroll_relative_p
)
10993 wanted_x
= text_area_width
* hscroll_step_rel
10996 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10999 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11001 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11003 /* Don't call Fset_window_hscroll if value hasn't
11004 changed because it will prevent redisplay
11006 if (XFASTINT (w
->hscroll
) != hscroll
)
11008 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11009 w
->hscroll
= make_number (hscroll
);
11018 /* Value is non-zero if hscroll of any leaf window has been changed. */
11019 return hscrolled_p
;
11023 /* Set hscroll so that cursor is visible and not inside horizontal
11024 scroll margins for all windows in the tree rooted at WINDOW. See
11025 also hscroll_window_tree above. Value is non-zero if any window's
11026 hscroll has been changed. If it has, desired matrices on the frame
11027 of WINDOW are cleared. */
11030 hscroll_windows (Lisp_Object window
)
11032 int hscrolled_p
= hscroll_window_tree (window
);
11034 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11035 return hscrolled_p
;
11040 /************************************************************************
11042 ************************************************************************/
11044 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11045 to a non-zero value. This is sometimes handy to have in a debugger
11050 /* First and last unchanged row for try_window_id. */
11052 int debug_first_unchanged_at_end_vpos
;
11053 int debug_last_unchanged_at_beg_vpos
;
11055 /* Delta vpos and y. */
11057 int debug_dvpos
, debug_dy
;
11059 /* Delta in characters and bytes for try_window_id. */
11061 EMACS_INT debug_delta
, debug_delta_bytes
;
11063 /* Values of window_end_pos and window_end_vpos at the end of
11066 EMACS_INT debug_end_vpos
;
11068 /* Append a string to W->desired_matrix->method. FMT is a printf
11069 format string. A1...A9 are a supplement for a variable-length
11070 argument list. If trace_redisplay_p is non-zero also printf the
11071 resulting string to stderr. */
11074 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11077 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11080 char *method
= w
->desired_matrix
->method
;
11081 int len
= strlen (method
);
11082 int size
= sizeof w
->desired_matrix
->method
;
11083 int remaining
= size
- len
- 1;
11085 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11086 if (len
&& remaining
)
11089 --remaining
, ++len
;
11092 strncpy (method
+ len
, buffer
, remaining
);
11094 if (trace_redisplay_p
)
11095 fprintf (stderr
, "%p (%s): %s\n",
11097 ((BUFFERP (w
->buffer
)
11098 && STRINGP (XBUFFER (w
->buffer
)->name
))
11099 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11104 #endif /* GLYPH_DEBUG */
11107 /* Value is non-zero if all changes in window W, which displays
11108 current_buffer, are in the text between START and END. START is a
11109 buffer position, END is given as a distance from Z. Used in
11110 redisplay_internal for display optimization. */
11113 text_outside_line_unchanged_p (struct window
*w
,
11114 EMACS_INT start
, EMACS_INT end
)
11116 int unchanged_p
= 1;
11118 /* If text or overlays have changed, see where. */
11119 if (XFASTINT (w
->last_modified
) < MODIFF
11120 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11122 /* Gap in the line? */
11123 if (GPT
< start
|| Z
- GPT
< end
)
11126 /* Changes start in front of the line, or end after it? */
11128 && (BEG_UNCHANGED
< start
- 1
11129 || END_UNCHANGED
< end
))
11132 /* If selective display, can't optimize if changes start at the
11133 beginning of the line. */
11135 && INTEGERP (BVAR (current_buffer
, selective_display
))
11136 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11137 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11140 /* If there are overlays at the start or end of the line, these
11141 may have overlay strings with newlines in them. A change at
11142 START, for instance, may actually concern the display of such
11143 overlay strings as well, and they are displayed on different
11144 lines. So, quickly rule out this case. (For the future, it
11145 might be desirable to implement something more telling than
11146 just BEG/END_UNCHANGED.) */
11149 if (BEG
+ BEG_UNCHANGED
== start
11150 && overlay_touches_p (start
))
11152 if (END_UNCHANGED
== end
11153 && overlay_touches_p (Z
- end
))
11157 /* Under bidi reordering, adding or deleting a character in the
11158 beginning of a paragraph, before the first strong directional
11159 character, can change the base direction of the paragraph (unless
11160 the buffer specifies a fixed paragraph direction), which will
11161 require to redisplay the whole paragraph. It might be worthwhile
11162 to find the paragraph limits and widen the range of redisplayed
11163 lines to that, but for now just give up this optimization. */
11164 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11165 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11169 return unchanged_p
;
11173 /* Do a frame update, taking possible shortcuts into account. This is
11174 the main external entry point for redisplay.
11176 If the last redisplay displayed an echo area message and that message
11177 is no longer requested, we clear the echo area or bring back the
11178 mini-buffer if that is in use. */
11183 redisplay_internal ();
11188 overlay_arrow_string_or_property (Lisp_Object var
)
11192 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11195 return Voverlay_arrow_string
;
11198 /* Return 1 if there are any overlay-arrows in current_buffer. */
11200 overlay_arrow_in_current_buffer_p (void)
11204 for (vlist
= Voverlay_arrow_variable_list
;
11206 vlist
= XCDR (vlist
))
11208 Lisp_Object var
= XCAR (vlist
);
11211 if (!SYMBOLP (var
))
11213 val
= find_symbol_value (var
);
11215 && current_buffer
== XMARKER (val
)->buffer
)
11222 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11226 overlay_arrows_changed_p (void)
11230 for (vlist
= Voverlay_arrow_variable_list
;
11232 vlist
= XCDR (vlist
))
11234 Lisp_Object var
= XCAR (vlist
);
11235 Lisp_Object val
, pstr
;
11237 if (!SYMBOLP (var
))
11239 val
= find_symbol_value (var
);
11240 if (!MARKERP (val
))
11242 if (! EQ (COERCE_MARKER (val
),
11243 Fget (var
, Qlast_arrow_position
))
11244 || ! (pstr
= overlay_arrow_string_or_property (var
),
11245 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11251 /* Mark overlay arrows to be updated on next redisplay. */
11254 update_overlay_arrows (int up_to_date
)
11258 for (vlist
= Voverlay_arrow_variable_list
;
11260 vlist
= XCDR (vlist
))
11262 Lisp_Object var
= XCAR (vlist
);
11264 if (!SYMBOLP (var
))
11267 if (up_to_date
> 0)
11269 Lisp_Object val
= find_symbol_value (var
);
11270 Fput (var
, Qlast_arrow_position
,
11271 COERCE_MARKER (val
));
11272 Fput (var
, Qlast_arrow_string
,
11273 overlay_arrow_string_or_property (var
));
11275 else if (up_to_date
< 0
11276 || !NILP (Fget (var
, Qlast_arrow_position
)))
11278 Fput (var
, Qlast_arrow_position
, Qt
);
11279 Fput (var
, Qlast_arrow_string
, Qt
);
11285 /* Return overlay arrow string to display at row.
11286 Return integer (bitmap number) for arrow bitmap in left fringe.
11287 Return nil if no overlay arrow. */
11290 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11294 for (vlist
= Voverlay_arrow_variable_list
;
11296 vlist
= XCDR (vlist
))
11298 Lisp_Object var
= XCAR (vlist
);
11301 if (!SYMBOLP (var
))
11304 val
= find_symbol_value (var
);
11307 && current_buffer
== XMARKER (val
)->buffer
11308 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11310 if (FRAME_WINDOW_P (it
->f
)
11311 /* FIXME: if ROW->reversed_p is set, this should test
11312 the right fringe, not the left one. */
11313 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11315 #ifdef HAVE_WINDOW_SYSTEM
11316 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11319 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11320 return make_number (fringe_bitmap
);
11323 return make_number (-1); /* Use default arrow bitmap */
11325 return overlay_arrow_string_or_property (var
);
11332 /* Return 1 if point moved out of or into a composition. Otherwise
11333 return 0. PREV_BUF and PREV_PT are the last point buffer and
11334 position. BUF and PT are the current point buffer and position. */
11337 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11338 struct buffer
*buf
, EMACS_INT pt
)
11340 EMACS_INT start
, end
;
11342 Lisp_Object buffer
;
11344 XSETBUFFER (buffer
, buf
);
11345 /* Check a composition at the last point if point moved within the
11347 if (prev_buf
== buf
)
11350 /* Point didn't move. */
11353 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11354 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11355 && COMPOSITION_VALID_P (start
, end
, prop
)
11356 && start
< prev_pt
&& end
> prev_pt
)
11357 /* The last point was within the composition. Return 1 iff
11358 point moved out of the composition. */
11359 return (pt
<= start
|| pt
>= end
);
11362 /* Check a composition at the current point. */
11363 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11364 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11365 && COMPOSITION_VALID_P (start
, end
, prop
)
11366 && start
< pt
&& end
> pt
);
11370 /* Reconsider the setting of B->clip_changed which is displayed
11374 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11376 if (b
->clip_changed
11377 && !NILP (w
->window_end_valid
)
11378 && w
->current_matrix
->buffer
== b
11379 && w
->current_matrix
->zv
== BUF_ZV (b
)
11380 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11381 b
->clip_changed
= 0;
11383 /* If display wasn't paused, and W is not a tool bar window, see if
11384 point has been moved into or out of a composition. In that case,
11385 we set b->clip_changed to 1 to force updating the screen. If
11386 b->clip_changed has already been set to 1, we can skip this
11388 if (!b
->clip_changed
11389 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11393 if (w
== XWINDOW (selected_window
))
11396 pt
= marker_position (w
->pointm
);
11398 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11399 || pt
!= XINT (w
->last_point
))
11400 && check_point_in_composition (w
->current_matrix
->buffer
,
11401 XINT (w
->last_point
),
11402 XBUFFER (w
->buffer
), pt
))
11403 b
->clip_changed
= 1;
11408 /* Select FRAME to forward the values of frame-local variables into C
11409 variables so that the redisplay routines can access those values
11413 select_frame_for_redisplay (Lisp_Object frame
)
11415 Lisp_Object tail
, tem
;
11416 Lisp_Object old
= selected_frame
;
11417 struct Lisp_Symbol
*sym
;
11419 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11421 selected_frame
= frame
;
11424 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11425 if (CONSP (XCAR (tail
))
11426 && (tem
= XCAR (XCAR (tail
)),
11428 && (sym
= indirect_variable (XSYMBOL (tem
)),
11429 sym
->redirect
== SYMBOL_LOCALIZED
)
11430 && sym
->val
.blv
->frame_local
)
11431 /* Use find_symbol_value rather than Fsymbol_value
11432 to avoid an error if it is void. */
11433 find_symbol_value (tem
);
11434 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11438 #define STOP_POLLING \
11439 do { if (! polling_stopped_here) stop_polling (); \
11440 polling_stopped_here = 1; } while (0)
11442 #define RESUME_POLLING \
11443 do { if (polling_stopped_here) start_polling (); \
11444 polling_stopped_here = 0; } while (0)
11447 /* Perhaps in the future avoid recentering windows if it
11448 is not necessary; currently that causes some problems. */
11451 redisplay_internal (void)
11453 struct window
*w
= XWINDOW (selected_window
);
11457 int must_finish
= 0;
11458 struct text_pos tlbufpos
, tlendpos
;
11459 int number_of_visible_frames
;
11462 int polling_stopped_here
= 0;
11463 Lisp_Object old_frame
= selected_frame
;
11465 /* Non-zero means redisplay has to consider all windows on all
11466 frames. Zero means, only selected_window is considered. */
11467 int consider_all_windows_p
;
11469 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11471 /* No redisplay if running in batch mode or frame is not yet fully
11472 initialized, or redisplay is explicitly turned off by setting
11473 Vinhibit_redisplay. */
11474 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11475 || !NILP (Vinhibit_redisplay
))
11478 /* Don't examine these until after testing Vinhibit_redisplay.
11479 When Emacs is shutting down, perhaps because its connection to
11480 X has dropped, we should not look at them at all. */
11481 fr
= XFRAME (w
->frame
);
11482 sf
= SELECTED_FRAME ();
11484 if (!fr
->glyphs_initialized_p
)
11487 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11488 if (popup_activated ())
11492 /* I don't think this happens but let's be paranoid. */
11493 if (redisplaying_p
)
11496 /* Record a function that resets redisplaying_p to its old value
11497 when we leave this function. */
11498 count
= SPECPDL_INDEX ();
11499 record_unwind_protect (unwind_redisplay
,
11500 Fcons (make_number (redisplaying_p
), selected_frame
));
11502 specbind (Qinhibit_free_realized_faces
, Qnil
);
11505 Lisp_Object tail
, frame
;
11507 FOR_EACH_FRAME (tail
, frame
)
11509 struct frame
*f
= XFRAME (frame
);
11510 f
->already_hscrolled_p
= 0;
11515 /* Remember the currently selected window. */
11518 if (!EQ (old_frame
, selected_frame
)
11519 && FRAME_LIVE_P (XFRAME (old_frame
)))
11520 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11521 selected_frame and selected_window to be temporarily out-of-sync so
11522 when we come back here via `goto retry', we need to resync because we
11523 may need to run Elisp code (via prepare_menu_bars). */
11524 select_frame_for_redisplay (old_frame
);
11527 reconsider_clip_changes (w
, current_buffer
);
11528 last_escape_glyph_frame
= NULL
;
11529 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11530 last_glyphless_glyph_frame
= NULL
;
11531 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11533 /* If new fonts have been loaded that make a glyph matrix adjustment
11534 necessary, do it. */
11535 if (fonts_changed_p
)
11537 adjust_glyphs (NULL
);
11538 ++windows_or_buffers_changed
;
11539 fonts_changed_p
= 0;
11542 /* If face_change_count is non-zero, init_iterator will free all
11543 realized faces, which includes the faces referenced from current
11544 matrices. So, we can't reuse current matrices in this case. */
11545 if (face_change_count
)
11546 ++windows_or_buffers_changed
;
11548 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11549 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11551 /* Since frames on a single ASCII terminal share the same
11552 display area, displaying a different frame means redisplay
11553 the whole thing. */
11554 windows_or_buffers_changed
++;
11555 SET_FRAME_GARBAGED (sf
);
11557 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11559 FRAME_TTY (sf
)->previous_frame
= sf
;
11562 /* Set the visible flags for all frames. Do this before checking
11563 for resized or garbaged frames; they want to know if their frames
11564 are visible. See the comment in frame.h for
11565 FRAME_SAMPLE_VISIBILITY. */
11567 Lisp_Object tail
, frame
;
11569 number_of_visible_frames
= 0;
11571 FOR_EACH_FRAME (tail
, frame
)
11573 struct frame
*f
= XFRAME (frame
);
11575 FRAME_SAMPLE_VISIBILITY (f
);
11576 if (FRAME_VISIBLE_P (f
))
11577 ++number_of_visible_frames
;
11578 clear_desired_matrices (f
);
11582 /* Notice any pending interrupt request to change frame size. */
11583 do_pending_window_change (1);
11585 /* do_pending_window_change could change the selected_window due to
11586 frame resizing which makes the selected window too small. */
11587 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
11590 reconsider_clip_changes (w
, current_buffer
);
11593 /* Clear frames marked as garbaged. */
11594 if (frame_garbaged
)
11595 clear_garbaged_frames ();
11597 /* Build menubar and tool-bar items. */
11598 if (NILP (Vmemory_full
))
11599 prepare_menu_bars ();
11601 if (windows_or_buffers_changed
)
11602 update_mode_lines
++;
11604 /* Detect case that we need to write or remove a star in the mode line. */
11605 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11607 w
->update_mode_line
= Qt
;
11608 if (buffer_shared
> 1)
11609 update_mode_lines
++;
11612 /* Avoid invocation of point motion hooks by `current_column' below. */
11613 count1
= SPECPDL_INDEX ();
11614 specbind (Qinhibit_point_motion_hooks
, Qt
);
11616 /* If %c is in the mode line, update it if needed. */
11617 if (!NILP (w
->column_number_displayed
)
11618 /* This alternative quickly identifies a common case
11619 where no change is needed. */
11620 && !(PT
== XFASTINT (w
->last_point
)
11621 && XFASTINT (w
->last_modified
) >= MODIFF
11622 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11623 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
11624 w
->update_mode_line
= Qt
;
11626 unbind_to (count1
, Qnil
);
11628 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11630 /* The variable buffer_shared is set in redisplay_window and
11631 indicates that we redisplay a buffer in different windows. See
11633 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11634 || cursor_type_changed
);
11636 /* If specs for an arrow have changed, do thorough redisplay
11637 to ensure we remove any arrow that should no longer exist. */
11638 if (overlay_arrows_changed_p ())
11639 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11641 /* Normally the message* functions will have already displayed and
11642 updated the echo area, but the frame may have been trashed, or
11643 the update may have been preempted, so display the echo area
11644 again here. Checking message_cleared_p captures the case that
11645 the echo area should be cleared. */
11646 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11647 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11648 || (message_cleared_p
11649 && minibuf_level
== 0
11650 /* If the mini-window is currently selected, this means the
11651 echo-area doesn't show through. */
11652 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11654 int window_height_changed_p
= echo_area_display (0);
11657 /* If we don't display the current message, don't clear the
11658 message_cleared_p flag, because, if we did, we wouldn't clear
11659 the echo area in the next redisplay which doesn't preserve
11661 if (!display_last_displayed_message_p
)
11662 message_cleared_p
= 0;
11664 if (fonts_changed_p
)
11666 else if (window_height_changed_p
)
11668 consider_all_windows_p
= 1;
11669 ++update_mode_lines
;
11670 ++windows_or_buffers_changed
;
11672 /* If window configuration was changed, frames may have been
11673 marked garbaged. Clear them or we will experience
11674 surprises wrt scrolling. */
11675 if (frame_garbaged
)
11676 clear_garbaged_frames ();
11679 else if (EQ (selected_window
, minibuf_window
)
11680 && (current_buffer
->clip_changed
11681 || XFASTINT (w
->last_modified
) < MODIFF
11682 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11683 && resize_mini_window (w
, 0))
11685 /* Resized active mini-window to fit the size of what it is
11686 showing if its contents might have changed. */
11688 /* FIXME: this causes all frames to be updated, which seems unnecessary
11689 since only the current frame needs to be considered. This function needs
11690 to be rewritten with two variables, consider_all_windows and
11691 consider_all_frames. */
11692 consider_all_windows_p
= 1;
11693 ++windows_or_buffers_changed
;
11694 ++update_mode_lines
;
11696 /* If window configuration was changed, frames may have been
11697 marked garbaged. Clear them or we will experience
11698 surprises wrt scrolling. */
11699 if (frame_garbaged
)
11700 clear_garbaged_frames ();
11704 /* If showing the region, and mark has changed, we must redisplay
11705 the whole window. The assignment to this_line_start_pos prevents
11706 the optimization directly below this if-statement. */
11707 if (((!NILP (Vtransient_mark_mode
)
11708 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11709 != !NILP (w
->region_showing
))
11710 || (!NILP (w
->region_showing
)
11711 && !EQ (w
->region_showing
,
11712 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
11713 CHARPOS (this_line_start_pos
) = 0;
11715 /* Optimize the case that only the line containing the cursor in the
11716 selected window has changed. Variables starting with this_ are
11717 set in display_line and record information about the line
11718 containing the cursor. */
11719 tlbufpos
= this_line_start_pos
;
11720 tlendpos
= this_line_end_pos
;
11721 if (!consider_all_windows_p
11722 && CHARPOS (tlbufpos
) > 0
11723 && NILP (w
->update_mode_line
)
11724 && !current_buffer
->clip_changed
11725 && !current_buffer
->prevent_redisplay_optimizations_p
11726 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11727 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11728 /* Make sure recorded data applies to current buffer, etc. */
11729 && this_line_buffer
== current_buffer
11730 && current_buffer
== XBUFFER (w
->buffer
)
11731 && NILP (w
->force_start
)
11732 && NILP (w
->optional_new_start
)
11733 /* Point must be on the line that we have info recorded about. */
11734 && PT
>= CHARPOS (tlbufpos
)
11735 && PT
<= Z
- CHARPOS (tlendpos
)
11736 /* All text outside that line, including its final newline,
11737 must be unchanged. */
11738 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11739 CHARPOS (tlendpos
)))
11741 if (CHARPOS (tlbufpos
) > BEGV
11742 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11743 && (CHARPOS (tlbufpos
) == ZV
11744 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11745 /* Former continuation line has disappeared by becoming empty. */
11747 else if (XFASTINT (w
->last_modified
) < MODIFF
11748 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11749 || MINI_WINDOW_P (w
))
11751 /* We have to handle the case of continuation around a
11752 wide-column character (see the comment in indent.c around
11755 For instance, in the following case:
11757 -------- Insert --------
11758 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11759 J_I_ ==> J_I_ `^^' are cursors.
11763 As we have to redraw the line above, we cannot use this
11767 int line_height_before
= this_line_pixel_height
;
11769 /* Note that start_display will handle the case that the
11770 line starting at tlbufpos is a continuation line. */
11771 start_display (&it
, w
, tlbufpos
);
11773 /* Implementation note: It this still necessary? */
11774 if (it
.current_x
!= this_line_start_x
)
11777 TRACE ((stderr
, "trying display optimization 1\n"));
11778 w
->cursor
.vpos
= -1;
11779 overlay_arrow_seen
= 0;
11780 it
.vpos
= this_line_vpos
;
11781 it
.current_y
= this_line_y
;
11782 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11783 display_line (&it
);
11785 /* If line contains point, is not continued,
11786 and ends at same distance from eob as before, we win. */
11787 if (w
->cursor
.vpos
>= 0
11788 /* Line is not continued, otherwise this_line_start_pos
11789 would have been set to 0 in display_line. */
11790 && CHARPOS (this_line_start_pos
)
11791 /* Line ends as before. */
11792 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11793 /* Line has same height as before. Otherwise other lines
11794 would have to be shifted up or down. */
11795 && this_line_pixel_height
== line_height_before
)
11797 /* If this is not the window's last line, we must adjust
11798 the charstarts of the lines below. */
11799 if (it
.current_y
< it
.last_visible_y
)
11801 struct glyph_row
*row
11802 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11803 EMACS_INT delta
, delta_bytes
;
11805 /* We used to distinguish between two cases here,
11806 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11807 when the line ends in a newline or the end of the
11808 buffer's accessible portion. But both cases did
11809 the same, so they were collapsed. */
11811 - CHARPOS (tlendpos
)
11812 - MATRIX_ROW_START_CHARPOS (row
));
11813 delta_bytes
= (Z_BYTE
11814 - BYTEPOS (tlendpos
)
11815 - MATRIX_ROW_START_BYTEPOS (row
));
11817 increment_matrix_positions (w
->current_matrix
,
11818 this_line_vpos
+ 1,
11819 w
->current_matrix
->nrows
,
11820 delta
, delta_bytes
);
11823 /* If this row displays text now but previously didn't,
11824 or vice versa, w->window_end_vpos may have to be
11826 if ((it
.glyph_row
- 1)->displays_text_p
)
11828 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11829 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11831 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11832 && this_line_vpos
> 0)
11833 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11834 w
->window_end_valid
= Qnil
;
11836 /* Update hint: No need to try to scroll in update_window. */
11837 w
->desired_matrix
->no_scrolling_p
= 1;
11840 *w
->desired_matrix
->method
= 0;
11841 debug_method_add (w
, "optimization 1");
11843 #ifdef HAVE_WINDOW_SYSTEM
11844 update_window_fringes (w
, 0);
11851 else if (/* Cursor position hasn't changed. */
11852 PT
== XFASTINT (w
->last_point
)
11853 /* Make sure the cursor was last displayed
11854 in this window. Otherwise we have to reposition it. */
11855 && 0 <= w
->cursor
.vpos
11856 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11860 do_pending_window_change (1);
11861 /* If selected_window changed, redisplay again. */
11862 if (WINDOWP (selected_window
)
11863 && (w
= XWINDOW (selected_window
)) != sw
)
11866 /* We used to always goto end_of_redisplay here, but this
11867 isn't enough if we have a blinking cursor. */
11868 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11869 goto end_of_redisplay
;
11873 /* If highlighting the region, or if the cursor is in the echo area,
11874 then we can't just move the cursor. */
11875 else if (! (!NILP (Vtransient_mark_mode
)
11876 && !NILP (BVAR (current_buffer
, mark_active
)))
11877 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
11878 || highlight_nonselected_windows
)
11879 && NILP (w
->region_showing
)
11880 && NILP (Vshow_trailing_whitespace
)
11881 && !cursor_in_echo_area
)
11884 struct glyph_row
*row
;
11886 /* Skip from tlbufpos to PT and see where it is. Note that
11887 PT may be in invisible text. If so, we will end at the
11888 next visible position. */
11889 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11890 NULL
, DEFAULT_FACE_ID
);
11891 it
.current_x
= this_line_start_x
;
11892 it
.current_y
= this_line_y
;
11893 it
.vpos
= this_line_vpos
;
11895 /* The call to move_it_to stops in front of PT, but
11896 moves over before-strings. */
11897 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11899 if (it
.vpos
== this_line_vpos
11900 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11903 xassert (this_line_vpos
== it
.vpos
);
11904 xassert (this_line_y
== it
.current_y
);
11905 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11907 *w
->desired_matrix
->method
= 0;
11908 debug_method_add (w
, "optimization 3");
11917 /* Text changed drastically or point moved off of line. */
11918 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11921 CHARPOS (this_line_start_pos
) = 0;
11922 consider_all_windows_p
|= buffer_shared
> 1;
11923 ++clear_face_cache_count
;
11924 #ifdef HAVE_WINDOW_SYSTEM
11925 ++clear_image_cache_count
;
11928 /* Build desired matrices, and update the display. If
11929 consider_all_windows_p is non-zero, do it for all windows on all
11930 frames. Otherwise do it for selected_window, only. */
11932 if (consider_all_windows_p
)
11934 Lisp_Object tail
, frame
;
11936 FOR_EACH_FRAME (tail
, frame
)
11937 XFRAME (frame
)->updated_p
= 0;
11939 /* Recompute # windows showing selected buffer. This will be
11940 incremented each time such a window is displayed. */
11943 FOR_EACH_FRAME (tail
, frame
)
11945 struct frame
*f
= XFRAME (frame
);
11947 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11949 if (! EQ (frame
, selected_frame
))
11950 /* Select the frame, for the sake of frame-local
11952 select_frame_for_redisplay (frame
);
11954 /* Mark all the scroll bars to be removed; we'll redeem
11955 the ones we want when we redisplay their windows. */
11956 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11957 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11959 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11960 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11962 /* The X error handler may have deleted that frame. */
11963 if (!FRAME_LIVE_P (f
))
11966 /* Any scroll bars which redisplay_windows should have
11967 nuked should now go away. */
11968 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11969 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11971 /* If fonts changed, display again. */
11972 /* ??? rms: I suspect it is a mistake to jump all the way
11973 back to retry here. It should just retry this frame. */
11974 if (fonts_changed_p
)
11977 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11979 /* See if we have to hscroll. */
11980 if (!f
->already_hscrolled_p
)
11982 f
->already_hscrolled_p
= 1;
11983 if (hscroll_windows (f
->root_window
))
11987 /* Prevent various kinds of signals during display
11988 update. stdio is not robust about handling
11989 signals, which can cause an apparent I/O
11991 if (interrupt_input
)
11992 unrequest_sigio ();
11995 /* Update the display. */
11996 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11997 pending
|= update_frame (f
, 0, 0);
12003 if (!EQ (old_frame
, selected_frame
)
12004 && FRAME_LIVE_P (XFRAME (old_frame
)))
12005 /* We played a bit fast-and-loose above and allowed selected_frame
12006 and selected_window to be temporarily out-of-sync but let's make
12007 sure this stays contained. */
12008 select_frame_for_redisplay (old_frame
);
12009 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12013 /* Do the mark_window_display_accurate after all windows have
12014 been redisplayed because this call resets flags in buffers
12015 which are needed for proper redisplay. */
12016 FOR_EACH_FRAME (tail
, frame
)
12018 struct frame
*f
= XFRAME (frame
);
12021 mark_window_display_accurate (f
->root_window
, 1);
12022 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12023 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12028 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12030 Lisp_Object mini_window
;
12031 struct frame
*mini_frame
;
12033 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12034 /* Use list_of_error, not Qerror, so that
12035 we catch only errors and don't run the debugger. */
12036 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12038 redisplay_window_error
);
12040 /* Compare desired and current matrices, perform output. */
12043 /* If fonts changed, display again. */
12044 if (fonts_changed_p
)
12047 /* Prevent various kinds of signals during display update.
12048 stdio is not robust about handling signals,
12049 which can cause an apparent I/O error. */
12050 if (interrupt_input
)
12051 unrequest_sigio ();
12054 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12056 if (hscroll_windows (selected_window
))
12059 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12060 pending
= update_frame (sf
, 0, 0);
12063 /* We may have called echo_area_display at the top of this
12064 function. If the echo area is on another frame, that may
12065 have put text on a frame other than the selected one, so the
12066 above call to update_frame would not have caught it. Catch
12068 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12069 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12071 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12073 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12074 pending
|= update_frame (mini_frame
, 0, 0);
12075 if (!pending
&& hscroll_windows (mini_window
))
12080 /* If display was paused because of pending input, make sure we do a
12081 thorough update the next time. */
12084 /* Prevent the optimization at the beginning of
12085 redisplay_internal that tries a single-line update of the
12086 line containing the cursor in the selected window. */
12087 CHARPOS (this_line_start_pos
) = 0;
12089 /* Let the overlay arrow be updated the next time. */
12090 update_overlay_arrows (0);
12092 /* If we pause after scrolling, some rows in the current
12093 matrices of some windows are not valid. */
12094 if (!WINDOW_FULL_WIDTH_P (w
)
12095 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12096 update_mode_lines
= 1;
12100 if (!consider_all_windows_p
)
12102 /* This has already been done above if
12103 consider_all_windows_p is set. */
12104 mark_window_display_accurate_1 (w
, 1);
12106 /* Say overlay arrows are up to date. */
12107 update_overlay_arrows (1);
12109 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12110 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12113 update_mode_lines
= 0;
12114 windows_or_buffers_changed
= 0;
12115 cursor_type_changed
= 0;
12118 /* Start SIGIO interrupts coming again. Having them off during the
12119 code above makes it less likely one will discard output, but not
12120 impossible, since there might be stuff in the system buffer here.
12121 But it is much hairier to try to do anything about that. */
12122 if (interrupt_input
)
12126 /* If a frame has become visible which was not before, redisplay
12127 again, so that we display it. Expose events for such a frame
12128 (which it gets when becoming visible) don't call the parts of
12129 redisplay constructing glyphs, so simply exposing a frame won't
12130 display anything in this case. So, we have to display these
12131 frames here explicitly. */
12134 Lisp_Object tail
, frame
;
12137 FOR_EACH_FRAME (tail
, frame
)
12139 int this_is_visible
= 0;
12141 if (XFRAME (frame
)->visible
)
12142 this_is_visible
= 1;
12143 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12144 if (XFRAME (frame
)->visible
)
12145 this_is_visible
= 1;
12147 if (this_is_visible
)
12151 if (new_count
!= number_of_visible_frames
)
12152 windows_or_buffers_changed
++;
12155 /* Change frame size now if a change is pending. */
12156 do_pending_window_change (1);
12158 /* If we just did a pending size change, or have additional
12159 visible frames, or selected_window changed, redisplay again. */
12160 if ((windows_or_buffers_changed
&& !pending
)
12161 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12164 /* Clear the face and image caches.
12166 We used to do this only if consider_all_windows_p. But the cache
12167 needs to be cleared if a timer creates images in the current
12168 buffer (e.g. the test case in Bug#6230). */
12170 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12172 clear_face_cache (0);
12173 clear_face_cache_count
= 0;
12176 #ifdef HAVE_WINDOW_SYSTEM
12177 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12179 clear_image_caches (Qnil
);
12180 clear_image_cache_count
= 0;
12182 #endif /* HAVE_WINDOW_SYSTEM */
12185 unbind_to (count
, Qnil
);
12190 /* Redisplay, but leave alone any recent echo area message unless
12191 another message has been requested in its place.
12193 This is useful in situations where you need to redisplay but no
12194 user action has occurred, making it inappropriate for the message
12195 area to be cleared. See tracking_off and
12196 wait_reading_process_output for examples of these situations.
12198 FROM_WHERE is an integer saying from where this function was
12199 called. This is useful for debugging. */
12202 redisplay_preserve_echo_area (int from_where
)
12204 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12206 if (!NILP (echo_area_buffer
[1]))
12208 /* We have a previously displayed message, but no current
12209 message. Redisplay the previous message. */
12210 display_last_displayed_message_p
= 1;
12211 redisplay_internal ();
12212 display_last_displayed_message_p
= 0;
12215 redisplay_internal ();
12217 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12218 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12219 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12223 /* Function registered with record_unwind_protect in
12224 redisplay_internal. Reset redisplaying_p to the value it had
12225 before redisplay_internal was called, and clear
12226 prevent_freeing_realized_faces_p. It also selects the previously
12227 selected frame, unless it has been deleted (by an X connection
12228 failure during redisplay, for example). */
12231 unwind_redisplay (Lisp_Object val
)
12233 Lisp_Object old_redisplaying_p
, old_frame
;
12235 old_redisplaying_p
= XCAR (val
);
12236 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12237 old_frame
= XCDR (val
);
12238 if (! EQ (old_frame
, selected_frame
)
12239 && FRAME_LIVE_P (XFRAME (old_frame
)))
12240 select_frame_for_redisplay (old_frame
);
12245 /* Mark the display of window W as accurate or inaccurate. If
12246 ACCURATE_P is non-zero mark display of W as accurate. If
12247 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12248 redisplay_internal is called. */
12251 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12253 if (BUFFERP (w
->buffer
))
12255 struct buffer
*b
= XBUFFER (w
->buffer
);
12258 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12259 w
->last_overlay_modified
12260 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12262 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12266 b
->clip_changed
= 0;
12267 b
->prevent_redisplay_optimizations_p
= 0;
12269 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12270 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12271 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12272 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12274 w
->current_matrix
->buffer
= b
;
12275 w
->current_matrix
->begv
= BUF_BEGV (b
);
12276 w
->current_matrix
->zv
= BUF_ZV (b
);
12278 w
->last_cursor
= w
->cursor
;
12279 w
->last_cursor_off_p
= w
->cursor_off_p
;
12281 if (w
== XWINDOW (selected_window
))
12282 w
->last_point
= make_number (BUF_PT (b
));
12284 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12290 w
->window_end_valid
= w
->buffer
;
12291 w
->update_mode_line
= Qnil
;
12296 /* Mark the display of windows in the window tree rooted at WINDOW as
12297 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12298 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12299 be redisplayed the next time redisplay_internal is called. */
12302 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12306 for (; !NILP (window
); window
= w
->next
)
12308 w
= XWINDOW (window
);
12309 mark_window_display_accurate_1 (w
, accurate_p
);
12311 if (!NILP (w
->vchild
))
12312 mark_window_display_accurate (w
->vchild
, accurate_p
);
12313 if (!NILP (w
->hchild
))
12314 mark_window_display_accurate (w
->hchild
, accurate_p
);
12319 update_overlay_arrows (1);
12323 /* Force a thorough redisplay the next time by setting
12324 last_arrow_position and last_arrow_string to t, which is
12325 unequal to any useful value of Voverlay_arrow_... */
12326 update_overlay_arrows (-1);
12331 /* Return value in display table DP (Lisp_Char_Table *) for character
12332 C. Since a display table doesn't have any parent, we don't have to
12333 follow parent. Do not call this function directly but use the
12334 macro DISP_CHAR_VECTOR. */
12337 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12341 if (ASCII_CHAR_P (c
))
12344 if (SUB_CHAR_TABLE_P (val
))
12345 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12351 XSETCHAR_TABLE (table
, dp
);
12352 val
= char_table_ref (table
, c
);
12361 /***********************************************************************
12363 ***********************************************************************/
12365 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12368 redisplay_windows (Lisp_Object window
)
12370 while (!NILP (window
))
12372 struct window
*w
= XWINDOW (window
);
12374 if (!NILP (w
->hchild
))
12375 redisplay_windows (w
->hchild
);
12376 else if (!NILP (w
->vchild
))
12377 redisplay_windows (w
->vchild
);
12378 else if (!NILP (w
->buffer
))
12380 displayed_buffer
= XBUFFER (w
->buffer
);
12381 /* Use list_of_error, not Qerror, so that
12382 we catch only errors and don't run the debugger. */
12383 internal_condition_case_1 (redisplay_window_0
, window
,
12385 redisplay_window_error
);
12393 redisplay_window_error (Lisp_Object ignore
)
12395 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12400 redisplay_window_0 (Lisp_Object window
)
12402 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12403 redisplay_window (window
, 0);
12408 redisplay_window_1 (Lisp_Object window
)
12410 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12411 redisplay_window (window
, 1);
12416 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12417 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12418 which positions recorded in ROW differ from current buffer
12421 Return 0 if cursor is not on this row, 1 otherwise. */
12424 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12425 struct glyph_matrix
*matrix
,
12426 EMACS_INT delta
, EMACS_INT delta_bytes
,
12429 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12430 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12431 struct glyph
*cursor
= NULL
;
12432 /* The last known character position in row. */
12433 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12435 EMACS_INT pt_old
= PT
- delta
;
12436 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12437 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12438 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12439 /* A glyph beyond the edge of TEXT_AREA which we should never
12441 struct glyph
*glyphs_end
= end
;
12442 /* Non-zero means we've found a match for cursor position, but that
12443 glyph has the avoid_cursor_p flag set. */
12444 int match_with_avoid_cursor
= 0;
12445 /* Non-zero means we've seen at least one glyph that came from a
12447 int string_seen
= 0;
12448 /* Largest and smalles buffer positions seen so far during scan of
12450 EMACS_INT bpos_max
= pos_before
;
12451 EMACS_INT bpos_min
= pos_after
;
12452 /* Last buffer position covered by an overlay string with an integer
12453 `cursor' property. */
12454 EMACS_INT bpos_covered
= 0;
12456 /* Skip over glyphs not having an object at the start and the end of
12457 the row. These are special glyphs like truncation marks on
12458 terminal frames. */
12459 if (row
->displays_text_p
)
12461 if (!row
->reversed_p
)
12464 && INTEGERP (glyph
->object
)
12465 && glyph
->charpos
< 0)
12467 x
+= glyph
->pixel_width
;
12471 && INTEGERP ((end
- 1)->object
)
12472 /* CHARPOS is zero for blanks and stretch glyphs
12473 inserted by extend_face_to_end_of_line. */
12474 && (end
- 1)->charpos
<= 0)
12476 glyph_before
= glyph
- 1;
12483 /* If the glyph row is reversed, we need to process it from back
12484 to front, so swap the edge pointers. */
12485 glyphs_end
= end
= glyph
- 1;
12486 glyph
+= row
->used
[TEXT_AREA
] - 1;
12488 while (glyph
> end
+ 1
12489 && INTEGERP (glyph
->object
)
12490 && glyph
->charpos
< 0)
12493 x
-= glyph
->pixel_width
;
12495 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12497 /* By default, in reversed rows we put the cursor on the
12498 rightmost (first in the reading order) glyph. */
12499 for (g
= end
+ 1; g
< glyph
; g
++)
12500 x
+= g
->pixel_width
;
12502 && INTEGERP ((end
+ 1)->object
)
12503 && (end
+ 1)->charpos
<= 0)
12505 glyph_before
= glyph
+ 1;
12509 else if (row
->reversed_p
)
12511 /* In R2L rows that don't display text, put the cursor on the
12512 rightmost glyph. Case in point: an empty last line that is
12513 part of an R2L paragraph. */
12515 /* Avoid placing the cursor on the last glyph of the row, where
12516 on terminal frames we hold the vertical border between
12517 adjacent windows. */
12518 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12519 && !WINDOW_RIGHTMOST_P (w
)
12520 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12522 x
= -1; /* will be computed below, at label compute_x */
12525 /* Step 1: Try to find the glyph whose character position
12526 corresponds to point. If that's not possible, find 2 glyphs
12527 whose character positions are the closest to point, one before
12528 point, the other after it. */
12529 if (!row
->reversed_p
)
12530 while (/* not marched to end of glyph row */
12532 /* glyph was not inserted by redisplay for internal purposes */
12533 && !INTEGERP (glyph
->object
))
12535 if (BUFFERP (glyph
->object
))
12537 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12539 if (glyph
->charpos
> bpos_max
)
12540 bpos_max
= glyph
->charpos
;
12541 if (glyph
->charpos
< bpos_min
)
12542 bpos_min
= glyph
->charpos
;
12543 if (!glyph
->avoid_cursor_p
)
12545 /* If we hit point, we've found the glyph on which to
12546 display the cursor. */
12549 match_with_avoid_cursor
= 0;
12552 /* See if we've found a better approximation to
12553 POS_BEFORE or to POS_AFTER. Note that we want the
12554 first (leftmost) glyph of all those that are the
12555 closest from below, and the last (rightmost) of all
12556 those from above. */
12557 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12559 pos_before
= glyph
->charpos
;
12560 glyph_before
= glyph
;
12562 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12564 pos_after
= glyph
->charpos
;
12565 glyph_after
= glyph
;
12568 else if (dpos
== 0)
12569 match_with_avoid_cursor
= 1;
12571 else if (STRINGP (glyph
->object
))
12573 Lisp_Object chprop
;
12574 EMACS_INT glyph_pos
= glyph
->charpos
;
12576 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12578 if (INTEGERP (chprop
))
12580 bpos_covered
= bpos_max
+ XINT (chprop
);
12581 /* If the `cursor' property covers buffer positions up
12582 to and including point, we should display cursor on
12583 this glyph. Note that overlays and text properties
12584 with string values stop bidi reordering, so every
12585 buffer position to the left of the string is always
12586 smaller than any position to the right of the
12587 string. Therefore, if a `cursor' property on one
12588 of the string's characters has an integer value, we
12589 will break out of the loop below _before_ we get to
12590 the position match above. IOW, integer values of
12591 the `cursor' property override the "exact match for
12592 point" strategy of positioning the cursor. */
12593 /* Implementation note: bpos_max == pt_old when, e.g.,
12594 we are in an empty line, where bpos_max is set to
12595 MATRIX_ROW_START_CHARPOS, see above. */
12596 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12605 x
+= glyph
->pixel_width
;
12608 else if (glyph
> end
) /* row is reversed */
12609 while (!INTEGERP (glyph
->object
))
12611 if (BUFFERP (glyph
->object
))
12613 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12615 if (glyph
->charpos
> bpos_max
)
12616 bpos_max
= glyph
->charpos
;
12617 if (glyph
->charpos
< bpos_min
)
12618 bpos_min
= glyph
->charpos
;
12619 if (!glyph
->avoid_cursor_p
)
12623 match_with_avoid_cursor
= 0;
12626 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12628 pos_before
= glyph
->charpos
;
12629 glyph_before
= glyph
;
12631 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12633 pos_after
= glyph
->charpos
;
12634 glyph_after
= glyph
;
12637 else if (dpos
== 0)
12638 match_with_avoid_cursor
= 1;
12640 else if (STRINGP (glyph
->object
))
12642 Lisp_Object chprop
;
12643 EMACS_INT glyph_pos
= glyph
->charpos
;
12645 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12647 if (INTEGERP (chprop
))
12649 bpos_covered
= bpos_max
+ XINT (chprop
);
12650 /* If the `cursor' property covers buffer positions up
12651 to and including point, we should display cursor on
12653 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12662 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12664 x
--; /* can't use any pixel_width */
12667 x
-= glyph
->pixel_width
;
12670 /* Step 2: If we didn't find an exact match for point, we need to
12671 look for a proper place to put the cursor among glyphs between
12672 GLYPH_BEFORE and GLYPH_AFTER. */
12673 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12674 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12675 && bpos_covered
< pt_old
)
12677 /* An empty line has a single glyph whose OBJECT is zero and
12678 whose CHARPOS is the position of a newline on that line.
12679 Note that on a TTY, there are more glyphs after that, which
12680 were produced by extend_face_to_end_of_line, but their
12681 CHARPOS is zero or negative. */
12683 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12684 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
12686 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12688 EMACS_INT ellipsis_pos
;
12690 /* Scan back over the ellipsis glyphs. */
12691 if (!row
->reversed_p
)
12693 ellipsis_pos
= (glyph
- 1)->charpos
;
12694 while (glyph
> row
->glyphs
[TEXT_AREA
]
12695 && (glyph
- 1)->charpos
== ellipsis_pos
)
12696 glyph
--, x
-= glyph
->pixel_width
;
12697 /* That loop always goes one position too far, including
12698 the glyph before the ellipsis. So scan forward over
12700 x
+= glyph
->pixel_width
;
12703 else /* row is reversed */
12705 ellipsis_pos
= (glyph
+ 1)->charpos
;
12706 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12707 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12708 glyph
++, x
+= glyph
->pixel_width
;
12709 x
-= glyph
->pixel_width
;
12713 else if (match_with_avoid_cursor
12714 /* A truncated row may not include PT among its
12715 character positions. Setting the cursor inside the
12716 scroll margin will trigger recalculation of hscroll
12717 in hscroll_window_tree. */
12718 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
12719 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
12720 /* Zero-width characters produce no glyphs. */
12723 && (row
->reversed_p
12724 ? glyph_after
> glyphs_end
12725 : glyph_after
< glyphs_end
)))
12727 cursor
= glyph_after
;
12730 else if (string_seen
)
12732 int incr
= row
->reversed_p
? -1 : +1;
12734 /* Need to find the glyph that came out of a string which is
12735 present at point. That glyph is somewhere between
12736 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12737 positioned between POS_BEFORE and POS_AFTER in the
12739 struct glyph
*stop
= glyph_after
;
12740 EMACS_INT pos
= pos_before
;
12743 for (glyph
= glyph_before
+ incr
;
12744 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12747 /* Any glyphs that come from the buffer are here because
12748 of bidi reordering. Skip them, and only pay
12749 attention to glyphs that came from some string. */
12750 if (STRINGP (glyph
->object
))
12755 str
= glyph
->object
;
12756 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
12757 if (tem
== 0 /* from overlay */
12760 /* If the string from which this glyph came is
12761 found in the buffer at point, then we've
12762 found the glyph we've been looking for. If
12763 it comes from an overlay (tem == 0), and it
12764 has the `cursor' property on one of its
12765 glyphs, record that glyph as a candidate for
12766 displaying the cursor. (As in the
12767 unidirectional version, we will display the
12768 cursor on the last candidate we find.) */
12769 if (tem
== 0 || tem
== pt_old
)
12771 /* The glyphs from this string could have
12772 been reordered. Find the one with the
12773 smallest string position. Or there could
12774 be a character in the string with the
12775 `cursor' property, which means display
12776 cursor on that character's glyph. */
12777 EMACS_INT strpos
= glyph
->charpos
;
12782 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12783 && EQ (glyph
->object
, str
);
12787 EMACS_INT gpos
= glyph
->charpos
;
12789 cprop
= Fget_char_property (make_number (gpos
),
12797 if (tem
&& glyph
->charpos
< strpos
)
12799 strpos
= glyph
->charpos
;
12808 pos
= tem
+ 1; /* don't find previous instances */
12810 /* This string is not what we want; skip all of the
12811 glyphs that came from it. */
12812 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12813 && EQ (glyph
->object
, str
))
12820 /* If we reached the end of the line, and END was from a string,
12821 the cursor is not on this line. */
12823 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
12824 && STRINGP (end
->object
)
12825 && row
->continued_p
)
12831 if (cursor
!= NULL
)
12837 /* Need to compute x that corresponds to GLYPH. */
12838 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12840 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12842 x
+= g
->pixel_width
;
12846 /* ROW could be part of a continued line, which, under bidi
12847 reordering, might have other rows whose start and end charpos
12848 occlude point. Only set w->cursor if we found a better
12849 approximation to the cursor position than we have from previously
12850 examined candidate rows belonging to the same continued line. */
12851 if (/* we already have a candidate row */
12852 w
->cursor
.vpos
>= 0
12853 /* that candidate is not the row we are processing */
12854 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
12855 /* the row we are processing is part of a continued line */
12856 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
12857 /* Make sure cursor.vpos specifies a row whose start and end
12858 charpos occlude point. This is because some callers of this
12859 function leave cursor.vpos at the row where the cursor was
12860 displayed during the last redisplay cycle. */
12861 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
12862 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
12865 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
12867 /* Don't consider glyphs that are outside TEXT_AREA. */
12868 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
12870 /* Keep the candidate whose buffer position is the closest to
12872 if (/* previous candidate is a glyph in TEXT_AREA of that row */
12873 w
->cursor
.hpos
>= 0
12874 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
12875 && BUFFERP (g1
->object
)
12876 && (g1
->charpos
== pt_old
/* an exact match always wins */
12877 || (BUFFERP (glyph
->object
)
12878 && eabs (g1
->charpos
- pt_old
)
12879 < eabs (glyph
->charpos
- pt_old
))))
12881 /* If this candidate gives an exact match, use that. */
12882 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12883 /* Otherwise, keep the candidate that comes from a row
12884 spanning less buffer positions. This may win when one or
12885 both candidate positions are on glyphs that came from
12886 display strings, for which we cannot compare buffer
12888 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12889 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12890 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
12893 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12895 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12896 w
->cursor
.y
= row
->y
+ dy
;
12898 if (w
== XWINDOW (selected_window
))
12900 if (!row
->continued_p
12901 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12904 this_line_buffer
= XBUFFER (w
->buffer
);
12906 CHARPOS (this_line_start_pos
)
12907 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12908 BYTEPOS (this_line_start_pos
)
12909 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12911 CHARPOS (this_line_end_pos
)
12912 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12913 BYTEPOS (this_line_end_pos
)
12914 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12916 this_line_y
= w
->cursor
.y
;
12917 this_line_pixel_height
= row
->height
;
12918 this_line_vpos
= w
->cursor
.vpos
;
12919 this_line_start_x
= row
->x
;
12922 CHARPOS (this_line_start_pos
) = 0;
12929 /* Run window scroll functions, if any, for WINDOW with new window
12930 start STARTP. Sets the window start of WINDOW to that position.
12932 We assume that the window's buffer is really current. */
12934 static INLINE
struct text_pos
12935 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
12937 struct window
*w
= XWINDOW (window
);
12938 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12940 if (current_buffer
!= XBUFFER (w
->buffer
))
12943 if (!NILP (Vwindow_scroll_functions
))
12945 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12946 make_number (CHARPOS (startp
)));
12947 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12948 /* In case the hook functions switch buffers. */
12949 if (current_buffer
!= XBUFFER (w
->buffer
))
12950 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12957 /* Make sure the line containing the cursor is fully visible.
12958 A value of 1 means there is nothing to be done.
12959 (Either the line is fully visible, or it cannot be made so,
12960 or we cannot tell.)
12962 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12963 is higher than window.
12965 A value of 0 means the caller should do scrolling
12966 as if point had gone off the screen. */
12969 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
12971 struct glyph_matrix
*matrix
;
12972 struct glyph_row
*row
;
12975 if (!make_cursor_line_fully_visible_p
)
12978 /* It's not always possible to find the cursor, e.g, when a window
12979 is full of overlay strings. Don't do anything in that case. */
12980 if (w
->cursor
.vpos
< 0)
12983 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12984 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12986 /* If the cursor row is not partially visible, there's nothing to do. */
12987 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12990 /* If the row the cursor is in is taller than the window's height,
12991 it's not clear what to do, so do nothing. */
12992 window_height
= window_box_height (w
);
12993 if (row
->height
>= window_height
)
12995 if (!force_p
|| MINI_WINDOW_P (w
)
12996 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13003 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13004 non-zero means only WINDOW is redisplayed in redisplay_internal.
13005 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13006 in redisplay_window to bring a partially visible line into view in
13007 the case that only the cursor has moved.
13009 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13010 last screen line's vertical height extends past the end of the screen.
13014 1 if scrolling succeeded
13016 0 if scrolling didn't find point.
13018 -1 if new fonts have been loaded so that we must interrupt
13019 redisplay, adjust glyph matrices, and try again. */
13025 SCROLLING_NEED_LARGER_MATRICES
13028 /* If scroll-conservatively is more than this, never recenter.
13030 If you change this, don't forget to update the doc string of
13031 `scroll-conservatively' and the Emacs manual. */
13032 #define SCROLL_LIMIT 100
13035 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13036 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13037 int temp_scroll_step
, int last_line_misfit
)
13039 struct window
*w
= XWINDOW (window
);
13040 struct frame
*f
= XFRAME (w
->frame
);
13041 struct text_pos pos
, startp
;
13043 int this_scroll_margin
, scroll_max
, rc
, height
;
13044 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13045 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13046 Lisp_Object aggressive
;
13047 /* We will never try scrolling more than this number of lines. */
13048 int scroll_limit
= SCROLL_LIMIT
;
13051 debug_method_add (w
, "try_scrolling");
13054 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13056 /* Compute scroll margin height in pixels. We scroll when point is
13057 within this distance from the top or bottom of the window. */
13058 if (scroll_margin
> 0)
13059 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13060 * FRAME_LINE_HEIGHT (f
);
13062 this_scroll_margin
= 0;
13064 /* Force arg_scroll_conservatively to have a reasonable value, to
13065 avoid scrolling too far away with slow move_it_* functions. Note
13066 that the user can supply scroll-conservatively equal to
13067 `most-positive-fixnum', which can be larger than INT_MAX. */
13068 if (arg_scroll_conservatively
> scroll_limit
)
13070 arg_scroll_conservatively
= scroll_limit
+ 1;
13071 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13073 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13074 /* Compute how much we should try to scroll maximally to bring
13075 point into view. */
13076 scroll_max
= (max (scroll_step
,
13077 max (arg_scroll_conservatively
, temp_scroll_step
))
13078 * FRAME_LINE_HEIGHT (f
));
13079 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13080 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13081 /* We're trying to scroll because of aggressive scrolling but no
13082 scroll_step is set. Choose an arbitrary one. */
13083 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13089 /* Decide whether to scroll down. */
13090 if (PT
> CHARPOS (startp
))
13092 int scroll_margin_y
;
13094 /* Compute the pixel ypos of the scroll margin, then move it to
13095 either that ypos or PT, whichever comes first. */
13096 start_display (&it
, w
, startp
);
13097 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13098 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13099 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13100 (MOVE_TO_POS
| MOVE_TO_Y
));
13102 if (PT
> CHARPOS (it
.current
.pos
))
13104 int y0
= line_bottom_y (&it
);
13105 /* Compute how many pixels below window bottom to stop searching
13106 for PT. This avoids costly search for PT that is far away if
13107 the user limited scrolling by a small number of lines, but
13108 always finds PT if scroll_conservatively is set to a large
13109 number, such as most-positive-fixnum. */
13110 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13111 int y_to_move
= it
.last_visible_y
+ slack
;
13113 /* Compute the distance from the scroll margin to PT or to
13114 the scroll limit, whichever comes first. This should
13115 include the height of the cursor line, to make that line
13117 move_it_to (&it
, PT
, -1, y_to_move
,
13118 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13119 dy
= line_bottom_y (&it
) - y0
;
13121 if (dy
> scroll_max
)
13122 return SCROLLING_FAILED
;
13130 /* Point is in or below the bottom scroll margin, so move the
13131 window start down. If scrolling conservatively, move it just
13132 enough down to make point visible. If scroll_step is set,
13133 move it down by scroll_step. */
13134 if (arg_scroll_conservatively
)
13136 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13137 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13138 else if (scroll_step
|| temp_scroll_step
)
13139 amount_to_scroll
= scroll_max
;
13142 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13143 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13144 if (NUMBERP (aggressive
))
13146 double float_amount
= XFLOATINT (aggressive
) * height
;
13147 amount_to_scroll
= float_amount
;
13148 if (amount_to_scroll
== 0 && float_amount
> 0)
13149 amount_to_scroll
= 1;
13150 /* Don't let point enter the scroll margin near top of
13152 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13153 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13157 if (amount_to_scroll
<= 0)
13158 return SCROLLING_FAILED
;
13160 start_display (&it
, w
, startp
);
13161 if (arg_scroll_conservatively
<= scroll_limit
)
13162 move_it_vertically (&it
, amount_to_scroll
);
13165 /* Extra precision for users who set scroll-conservatively
13166 to a large number: make sure the amount we scroll
13167 the window start is never less than amount_to_scroll,
13168 which was computed as distance from window bottom to
13169 point. This matters when lines at window top and lines
13170 below window bottom have different height. */
13171 struct it it1
= it
;
13172 /* We use a temporary it1 because line_bottom_y can modify
13173 its argument, if it moves one line down; see there. */
13174 int start_y
= line_bottom_y (&it1
);
13177 move_it_by_lines (&it
, 1);
13179 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13182 /* If STARTP is unchanged, move it down another screen line. */
13183 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13184 move_it_by_lines (&it
, 1);
13185 startp
= it
.current
.pos
;
13189 struct text_pos scroll_margin_pos
= startp
;
13191 /* See if point is inside the scroll margin at the top of the
13193 if (this_scroll_margin
)
13195 start_display (&it
, w
, startp
);
13196 move_it_vertically (&it
, this_scroll_margin
);
13197 scroll_margin_pos
= it
.current
.pos
;
13200 if (PT
< CHARPOS (scroll_margin_pos
))
13202 /* Point is in the scroll margin at the top of the window or
13203 above what is displayed in the window. */
13206 /* Compute the vertical distance from PT to the scroll
13207 margin position. Move as far as scroll_max allows, or
13208 one screenful, or 10 screen lines, whichever is largest.
13209 Give up if distance is greater than scroll_max. */
13210 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13211 start_display (&it
, w
, pos
);
13213 y_to_move
= max (it
.last_visible_y
,
13214 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13215 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13217 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13218 dy
= it
.current_y
- y0
;
13219 if (dy
> scroll_max
)
13220 return SCROLLING_FAILED
;
13222 /* Compute new window start. */
13223 start_display (&it
, w
, startp
);
13225 if (arg_scroll_conservatively
)
13226 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13227 max (scroll_step
, temp_scroll_step
));
13228 else if (scroll_step
|| temp_scroll_step
)
13229 amount_to_scroll
= scroll_max
;
13232 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13233 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13234 if (NUMBERP (aggressive
))
13236 double float_amount
= XFLOATINT (aggressive
) * height
;
13237 amount_to_scroll
= float_amount
;
13238 if (amount_to_scroll
== 0 && float_amount
> 0)
13239 amount_to_scroll
= 1;
13240 amount_to_scroll
-=
13241 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13242 /* Don't let point enter the scroll margin near
13243 bottom of the window. */
13244 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13245 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13249 if (amount_to_scroll
<= 0)
13250 return SCROLLING_FAILED
;
13252 move_it_vertically_backward (&it
, amount_to_scroll
);
13253 startp
= it
.current
.pos
;
13257 /* Run window scroll functions. */
13258 startp
= run_window_scroll_functions (window
, startp
);
13260 /* Display the window. Give up if new fonts are loaded, or if point
13262 if (!try_window (window
, startp
, 0))
13263 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13264 else if (w
->cursor
.vpos
< 0)
13266 clear_glyph_matrix (w
->desired_matrix
);
13267 rc
= SCROLLING_FAILED
;
13271 /* Maybe forget recorded base line for line number display. */
13272 if (!just_this_one_p
13273 || current_buffer
->clip_changed
13274 || BEG_UNCHANGED
< CHARPOS (startp
))
13275 w
->base_line_number
= Qnil
;
13277 /* If cursor ends up on a partially visible line,
13278 treat that as being off the bottom of the screen. */
13279 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13280 /* It's possible that the cursor is on the first line of the
13281 buffer, which is partially obscured due to a vscroll
13282 (Bug#7537). In that case, avoid looping forever . */
13283 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13285 clear_glyph_matrix (w
->desired_matrix
);
13286 ++extra_scroll_margin_lines
;
13289 rc
= SCROLLING_SUCCESS
;
13296 /* Compute a suitable window start for window W if display of W starts
13297 on a continuation line. Value is non-zero if a new window start
13300 The new window start will be computed, based on W's width, starting
13301 from the start of the continued line. It is the start of the
13302 screen line with the minimum distance from the old start W->start. */
13305 compute_window_start_on_continuation_line (struct window
*w
)
13307 struct text_pos pos
, start_pos
;
13308 int window_start_changed_p
= 0;
13310 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13312 /* If window start is on a continuation line... Window start may be
13313 < BEGV in case there's invisible text at the start of the
13314 buffer (M-x rmail, for example). */
13315 if (CHARPOS (start_pos
) > BEGV
13316 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13319 struct glyph_row
*row
;
13321 /* Handle the case that the window start is out of range. */
13322 if (CHARPOS (start_pos
) < BEGV
)
13323 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13324 else if (CHARPOS (start_pos
) > ZV
)
13325 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13327 /* Find the start of the continued line. This should be fast
13328 because scan_buffer is fast (newline cache). */
13329 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13330 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13331 row
, DEFAULT_FACE_ID
);
13332 reseat_at_previous_visible_line_start (&it
);
13334 /* If the line start is "too far" away from the window start,
13335 say it takes too much time to compute a new window start. */
13336 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13337 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13339 int min_distance
, distance
;
13341 /* Move forward by display lines to find the new window
13342 start. If window width was enlarged, the new start can
13343 be expected to be > the old start. If window width was
13344 decreased, the new window start will be < the old start.
13345 So, we're looking for the display line start with the
13346 minimum distance from the old window start. */
13347 pos
= it
.current
.pos
;
13348 min_distance
= INFINITY
;
13349 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13350 distance
< min_distance
)
13352 min_distance
= distance
;
13353 pos
= it
.current
.pos
;
13354 move_it_by_lines (&it
, 1);
13357 /* Set the window start there. */
13358 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13359 window_start_changed_p
= 1;
13363 return window_start_changed_p
;
13367 /* Try cursor movement in case text has not changed in window WINDOW,
13368 with window start STARTP. Value is
13370 CURSOR_MOVEMENT_SUCCESS if successful
13372 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13374 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13375 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13376 we want to scroll as if scroll-step were set to 1. See the code.
13378 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13379 which case we have to abort this redisplay, and adjust matrices
13384 CURSOR_MOVEMENT_SUCCESS
,
13385 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13386 CURSOR_MOVEMENT_MUST_SCROLL
,
13387 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13391 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13393 struct window
*w
= XWINDOW (window
);
13394 struct frame
*f
= XFRAME (w
->frame
);
13395 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13398 if (inhibit_try_cursor_movement
)
13402 /* Handle case where text has not changed, only point, and it has
13403 not moved off the frame. */
13404 if (/* Point may be in this window. */
13405 PT
>= CHARPOS (startp
)
13406 /* Selective display hasn't changed. */
13407 && !current_buffer
->clip_changed
13408 /* Function force-mode-line-update is used to force a thorough
13409 redisplay. It sets either windows_or_buffers_changed or
13410 update_mode_lines. So don't take a shortcut here for these
13412 && !update_mode_lines
13413 && !windows_or_buffers_changed
13414 && !cursor_type_changed
13415 /* Can't use this case if highlighting a region. When a
13416 region exists, cursor movement has to do more than just
13418 && !(!NILP (Vtransient_mark_mode
)
13419 && !NILP (BVAR (current_buffer
, mark_active
)))
13420 && NILP (w
->region_showing
)
13421 && NILP (Vshow_trailing_whitespace
)
13422 /* Right after splitting windows, last_point may be nil. */
13423 && INTEGERP (w
->last_point
)
13424 /* This code is not used for mini-buffer for the sake of the case
13425 of redisplaying to replace an echo area message; since in
13426 that case the mini-buffer contents per se are usually
13427 unchanged. This code is of no real use in the mini-buffer
13428 since the handling of this_line_start_pos, etc., in redisplay
13429 handles the same cases. */
13430 && !EQ (window
, minibuf_window
)
13431 /* When splitting windows or for new windows, it happens that
13432 redisplay is called with a nil window_end_vpos or one being
13433 larger than the window. This should really be fixed in
13434 window.c. I don't have this on my list, now, so we do
13435 approximately the same as the old redisplay code. --gerd. */
13436 && INTEGERP (w
->window_end_vpos
)
13437 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13438 && (FRAME_WINDOW_P (f
)
13439 || !overlay_arrow_in_current_buffer_p ()))
13441 int this_scroll_margin
, top_scroll_margin
;
13442 struct glyph_row
*row
= NULL
;
13445 debug_method_add (w
, "cursor movement");
13448 /* Scroll if point within this distance from the top or bottom
13449 of the window. This is a pixel value. */
13450 if (scroll_margin
> 0)
13452 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13453 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13456 this_scroll_margin
= 0;
13458 top_scroll_margin
= this_scroll_margin
;
13459 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13460 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13462 /* Start with the row the cursor was displayed during the last
13463 not paused redisplay. Give up if that row is not valid. */
13464 if (w
->last_cursor
.vpos
< 0
13465 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13466 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13469 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13470 if (row
->mode_line_p
)
13472 if (!row
->enabled_p
)
13473 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13476 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13478 int scroll_p
= 0, must_scroll
= 0;
13479 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13481 if (PT
> XFASTINT (w
->last_point
))
13483 /* Point has moved forward. */
13484 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13485 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13487 xassert (row
->enabled_p
);
13491 /* If the end position of a row equals the start
13492 position of the next row, and PT is at that position,
13493 we would rather display cursor in the next line. */
13494 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13495 && MATRIX_ROW_END_CHARPOS (row
) == PT
13496 && row
< w
->current_matrix
->rows
13497 + w
->current_matrix
->nrows
- 1
13498 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13499 && !cursor_row_p (row
))
13502 /* If within the scroll margin, scroll. Note that
13503 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13504 the next line would be drawn, and that
13505 this_scroll_margin can be zero. */
13506 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13507 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13508 /* Line is completely visible last line in window
13509 and PT is to be set in the next line. */
13510 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13511 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13512 && !row
->ends_at_zv_p
13513 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13516 else if (PT
< XFASTINT (w
->last_point
))
13518 /* Cursor has to be moved backward. Note that PT >=
13519 CHARPOS (startp) because of the outer if-statement. */
13520 while (!row
->mode_line_p
13521 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13522 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13523 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13524 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13525 row
> w
->current_matrix
->rows
13526 && (row
-1)->ends_in_newline_from_string_p
))))
13527 && (row
->y
> top_scroll_margin
13528 || CHARPOS (startp
) == BEGV
))
13530 xassert (row
->enabled_p
);
13534 /* Consider the following case: Window starts at BEGV,
13535 there is invisible, intangible text at BEGV, so that
13536 display starts at some point START > BEGV. It can
13537 happen that we are called with PT somewhere between
13538 BEGV and START. Try to handle that case. */
13539 if (row
< w
->current_matrix
->rows
13540 || row
->mode_line_p
)
13542 row
= w
->current_matrix
->rows
;
13543 if (row
->mode_line_p
)
13547 /* Due to newlines in overlay strings, we may have to
13548 skip forward over overlay strings. */
13549 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13550 && MATRIX_ROW_END_CHARPOS (row
) == PT
13551 && !cursor_row_p (row
))
13554 /* If within the scroll margin, scroll. */
13555 if (row
->y
< top_scroll_margin
13556 && CHARPOS (startp
) != BEGV
)
13561 /* Cursor did not move. So don't scroll even if cursor line
13562 is partially visible, as it was so before. */
13563 rc
= CURSOR_MOVEMENT_SUCCESS
;
13566 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13567 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13569 /* if PT is not in the glyph row, give up. */
13570 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13573 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13574 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13576 /* If rows are bidi-reordered and point moved, back up
13577 until we find a row that does not belong to a
13578 continuation line. This is because we must consider
13579 all rows of a continued line as candidates for the
13580 new cursor positioning, since row start and end
13581 positions change non-linearly with vertical position
13583 /* FIXME: Revisit this when glyph ``spilling'' in
13584 continuation lines' rows is implemented for
13585 bidi-reordered rows. */
13586 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13588 xassert (row
->enabled_p
);
13590 /* If we hit the beginning of the displayed portion
13591 without finding the first row of a continued
13593 if (row
<= w
->current_matrix
->rows
)
13595 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13603 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13604 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13605 && make_cursor_line_fully_visible_p
)
13607 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13608 && !row
->ends_at_zv_p
13609 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13610 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13611 else if (row
->height
> window_box_height (w
))
13613 /* If we end up in a partially visible line, let's
13614 make it fully visible, except when it's taller
13615 than the window, in which case we can't do much
13618 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13622 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13623 if (!cursor_row_fully_visible_p (w
, 0, 1))
13624 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13626 rc
= CURSOR_MOVEMENT_SUCCESS
;
13630 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13631 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13632 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13634 /* With bidi-reordered rows, there could be more than
13635 one candidate row whose start and end positions
13636 occlude point. We need to let set_cursor_from_row
13637 find the best candidate. */
13638 /* FIXME: Revisit this when glyph ``spilling'' in
13639 continuation lines' rows is implemented for
13640 bidi-reordered rows. */
13645 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
13646 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13647 && cursor_row_p (row
))
13648 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13650 /* As soon as we've found the first suitable row
13651 whose ends_at_zv_p flag is set, we are done. */
13653 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13655 rc
= CURSOR_MOVEMENT_SUCCESS
;
13660 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
13661 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
13662 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13663 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
13664 /* If we didn't find any candidate rows, or exited the
13665 loop before all the candidates were examined, signal
13666 to the caller that this method failed. */
13667 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13668 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
13669 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13671 rc
= CURSOR_MOVEMENT_SUCCESS
;
13677 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13679 rc
= CURSOR_MOVEMENT_SUCCESS
;
13684 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13685 && MATRIX_ROW_START_CHARPOS (row
) == PT
13686 && cursor_row_p (row
));
13694 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
13698 set_vertical_scroll_bar (struct window
*w
)
13700 EMACS_INT start
, end
, whole
;
13702 /* Calculate the start and end positions for the current window.
13703 At some point, it would be nice to choose between scrollbars
13704 which reflect the whole buffer size, with special markers
13705 indicating narrowing, and scrollbars which reflect only the
13708 Note that mini-buffers sometimes aren't displaying any text. */
13709 if (!MINI_WINDOW_P (w
)
13710 || (w
== XWINDOW (minibuf_window
)
13711 && NILP (echo_area_buffer
[0])))
13713 struct buffer
*buf
= XBUFFER (w
->buffer
);
13714 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13715 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13716 /* I don't think this is guaranteed to be right. For the
13717 moment, we'll pretend it is. */
13718 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13722 if (whole
< (end
- start
))
13723 whole
= end
- start
;
13726 start
= end
= whole
= 0;
13728 /* Indicate what this scroll bar ought to be displaying now. */
13729 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13730 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13731 (w
, end
- start
, whole
, start
);
13735 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13736 selected_window is redisplayed.
13738 We can return without actually redisplaying the window if
13739 fonts_changed_p is nonzero. In that case, redisplay_internal will
13743 redisplay_window (Lisp_Object window
, int just_this_one_p
)
13745 struct window
*w
= XWINDOW (window
);
13746 struct frame
*f
= XFRAME (w
->frame
);
13747 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13748 struct buffer
*old
= current_buffer
;
13749 struct text_pos lpoint
, opoint
, startp
;
13750 int update_mode_line
;
13753 /* Record it now because it's overwritten. */
13754 int current_matrix_up_to_date_p
= 0;
13755 int used_current_matrix_p
= 0;
13756 /* This is less strict than current_matrix_up_to_date_p.
13757 It indictes that the buffer contents and narrowing are unchanged. */
13758 int buffer_unchanged_p
= 0;
13759 int temp_scroll_step
= 0;
13760 int count
= SPECPDL_INDEX ();
13762 int centering_position
= -1;
13763 int last_line_misfit
= 0;
13764 EMACS_INT beg_unchanged
, end_unchanged
;
13766 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13769 /* W must be a leaf window here. */
13770 xassert (!NILP (w
->buffer
));
13772 *w
->desired_matrix
->method
= 0;
13776 reconsider_clip_changes (w
, buffer
);
13778 /* Has the mode line to be updated? */
13779 update_mode_line
= (!NILP (w
->update_mode_line
)
13780 || update_mode_lines
13781 || buffer
->clip_changed
13782 || buffer
->prevent_redisplay_optimizations_p
);
13784 if (MINI_WINDOW_P (w
))
13786 if (w
== XWINDOW (echo_area_window
)
13787 && !NILP (echo_area_buffer
[0]))
13789 if (update_mode_line
)
13790 /* We may have to update a tty frame's menu bar or a
13791 tool-bar. Example `M-x C-h C-h C-g'. */
13792 goto finish_menu_bars
;
13794 /* We've already displayed the echo area glyphs in this window. */
13795 goto finish_scroll_bars
;
13797 else if ((w
!= XWINDOW (minibuf_window
)
13798 || minibuf_level
== 0)
13799 /* When buffer is nonempty, redisplay window normally. */
13800 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13801 /* Quail displays non-mini buffers in minibuffer window.
13802 In that case, redisplay the window normally. */
13803 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13805 /* W is a mini-buffer window, but it's not active, so clear
13807 int yb
= window_text_bottom_y (w
);
13808 struct glyph_row
*row
;
13811 for (y
= 0, row
= w
->desired_matrix
->rows
;
13813 y
+= row
->height
, ++row
)
13814 blank_row (w
, row
, y
);
13815 goto finish_scroll_bars
;
13818 clear_glyph_matrix (w
->desired_matrix
);
13821 /* Otherwise set up data on this window; select its buffer and point
13823 /* Really select the buffer, for the sake of buffer-local
13825 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13827 current_matrix_up_to_date_p
13828 = (!NILP (w
->window_end_valid
)
13829 && !current_buffer
->clip_changed
13830 && !current_buffer
->prevent_redisplay_optimizations_p
13831 && XFASTINT (w
->last_modified
) >= MODIFF
13832 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13834 /* Run the window-bottom-change-functions
13835 if it is possible that the text on the screen has changed
13836 (either due to modification of the text, or any other reason). */
13837 if (!current_matrix_up_to_date_p
13838 && !NILP (Vwindow_text_change_functions
))
13840 safe_run_hooks (Qwindow_text_change_functions
);
13844 beg_unchanged
= BEG_UNCHANGED
;
13845 end_unchanged
= END_UNCHANGED
;
13847 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13849 specbind (Qinhibit_point_motion_hooks
, Qt
);
13852 = (!NILP (w
->window_end_valid
)
13853 && !current_buffer
->clip_changed
13854 && XFASTINT (w
->last_modified
) >= MODIFF
13855 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13857 /* When windows_or_buffers_changed is non-zero, we can't rely on
13858 the window end being valid, so set it to nil there. */
13859 if (windows_or_buffers_changed
)
13861 /* If window starts on a continuation line, maybe adjust the
13862 window start in case the window's width changed. */
13863 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13864 compute_window_start_on_continuation_line (w
);
13866 w
->window_end_valid
= Qnil
;
13869 /* Some sanity checks. */
13870 CHECK_WINDOW_END (w
);
13871 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13873 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13876 /* If %c is in mode line, update it if needed. */
13877 if (!NILP (w
->column_number_displayed
)
13878 /* This alternative quickly identifies a common case
13879 where no change is needed. */
13880 && !(PT
== XFASTINT (w
->last_point
)
13881 && XFASTINT (w
->last_modified
) >= MODIFF
13882 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13883 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13884 update_mode_line
= 1;
13886 /* Count number of windows showing the selected buffer. An indirect
13887 buffer counts as its base buffer. */
13888 if (!just_this_one_p
)
13890 struct buffer
*current_base
, *window_base
;
13891 current_base
= current_buffer
;
13892 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13893 if (current_base
->base_buffer
)
13894 current_base
= current_base
->base_buffer
;
13895 if (window_base
->base_buffer
)
13896 window_base
= window_base
->base_buffer
;
13897 if (current_base
== window_base
)
13901 /* Point refers normally to the selected window. For any other
13902 window, set up appropriate value. */
13903 if (!EQ (window
, selected_window
))
13905 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
13906 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
13910 new_pt_byte
= BEGV_BYTE
;
13911 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13913 else if (new_pt
> (ZV
- 1))
13916 new_pt_byte
= ZV_BYTE
;
13917 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13920 /* We don't use SET_PT so that the point-motion hooks don't run. */
13921 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13924 /* If any of the character widths specified in the display table
13925 have changed, invalidate the width run cache. It's true that
13926 this may be a bit late to catch such changes, but the rest of
13927 redisplay goes (non-fatally) haywire when the display table is
13928 changed, so why should we worry about doing any better? */
13929 if (current_buffer
->width_run_cache
)
13931 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13933 if (! disptab_matches_widthtab (disptab
,
13934 XVECTOR (BVAR (current_buffer
, width_table
))))
13936 invalidate_region_cache (current_buffer
,
13937 current_buffer
->width_run_cache
,
13939 recompute_width_table (current_buffer
, disptab
);
13943 /* If window-start is screwed up, choose a new one. */
13944 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13947 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13949 /* If someone specified a new starting point but did not insist,
13950 check whether it can be used. */
13951 if (!NILP (w
->optional_new_start
)
13952 && CHARPOS (startp
) >= BEGV
13953 && CHARPOS (startp
) <= ZV
)
13955 w
->optional_new_start
= Qnil
;
13956 start_display (&it
, w
, startp
);
13957 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13958 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13959 if (IT_CHARPOS (it
) == PT
)
13960 w
->force_start
= Qt
;
13961 /* IT may overshoot PT if text at PT is invisible. */
13962 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13963 w
->force_start
= Qt
;
13968 /* Handle case where place to start displaying has been specified,
13969 unless the specified location is outside the accessible range. */
13970 if (!NILP (w
->force_start
)
13971 || w
->frozen_window_start_p
)
13973 /* We set this later on if we have to adjust point. */
13976 w
->force_start
= Qnil
;
13978 w
->window_end_valid
= Qnil
;
13980 /* Forget any recorded base line for line number display. */
13981 if (!buffer_unchanged_p
)
13982 w
->base_line_number
= Qnil
;
13984 /* Redisplay the mode line. Select the buffer properly for that.
13985 Also, run the hook window-scroll-functions
13986 because we have scrolled. */
13987 /* Note, we do this after clearing force_start because
13988 if there's an error, it is better to forget about force_start
13989 than to get into an infinite loop calling the hook functions
13990 and having them get more errors. */
13991 if (!update_mode_line
13992 || ! NILP (Vwindow_scroll_functions
))
13994 update_mode_line
= 1;
13995 w
->update_mode_line
= Qt
;
13996 startp
= run_window_scroll_functions (window
, startp
);
13999 w
->last_modified
= make_number (0);
14000 w
->last_overlay_modified
= make_number (0);
14001 if (CHARPOS (startp
) < BEGV
)
14002 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14003 else if (CHARPOS (startp
) > ZV
)
14004 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14006 /* Redisplay, then check if cursor has been set during the
14007 redisplay. Give up if new fonts were loaded. */
14008 /* We used to issue a CHECK_MARGINS argument to try_window here,
14009 but this causes scrolling to fail when point begins inside
14010 the scroll margin (bug#148) -- cyd */
14011 if (!try_window (window
, startp
, 0))
14013 w
->force_start
= Qt
;
14014 clear_glyph_matrix (w
->desired_matrix
);
14015 goto need_larger_matrices
;
14018 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14020 /* If point does not appear, try to move point so it does
14021 appear. The desired matrix has been built above, so we
14022 can use it here. */
14023 new_vpos
= window_box_height (w
) / 2;
14026 if (!cursor_row_fully_visible_p (w
, 0, 0))
14028 /* Point does appear, but on a line partly visible at end of window.
14029 Move it back to a fully-visible line. */
14030 new_vpos
= window_box_height (w
);
14033 /* If we need to move point for either of the above reasons,
14034 now actually do it. */
14037 struct glyph_row
*row
;
14039 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14040 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14043 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14044 MATRIX_ROW_START_BYTEPOS (row
));
14046 if (w
!= XWINDOW (selected_window
))
14047 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14048 else if (current_buffer
== old
)
14049 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14051 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14053 /* If we are highlighting the region, then we just changed
14054 the region, so redisplay to show it. */
14055 if (!NILP (Vtransient_mark_mode
)
14056 && !NILP (BVAR (current_buffer
, mark_active
)))
14058 clear_glyph_matrix (w
->desired_matrix
);
14059 if (!try_window (window
, startp
, 0))
14060 goto need_larger_matrices
;
14065 debug_method_add (w
, "forced window start");
14070 /* Handle case where text has not changed, only point, and it has
14071 not moved off the frame, and we are not retrying after hscroll.
14072 (current_matrix_up_to_date_p is nonzero when retrying.) */
14073 if (current_matrix_up_to_date_p
14074 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14075 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14079 case CURSOR_MOVEMENT_SUCCESS
:
14080 used_current_matrix_p
= 1;
14083 case CURSOR_MOVEMENT_MUST_SCROLL
:
14084 goto try_to_scroll
;
14090 /* If current starting point was originally the beginning of a line
14091 but no longer is, find a new starting point. */
14092 else if (!NILP (w
->start_at_line_beg
)
14093 && !(CHARPOS (startp
) <= BEGV
14094 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14097 debug_method_add (w
, "recenter 1");
14102 /* Try scrolling with try_window_id. Value is > 0 if update has
14103 been done, it is -1 if we know that the same window start will
14104 not work. It is 0 if unsuccessful for some other reason. */
14105 else if ((tem
= try_window_id (w
)) != 0)
14108 debug_method_add (w
, "try_window_id %d", tem
);
14111 if (fonts_changed_p
)
14112 goto need_larger_matrices
;
14116 /* Otherwise try_window_id has returned -1 which means that we
14117 don't want the alternative below this comment to execute. */
14119 else if (CHARPOS (startp
) >= BEGV
14120 && CHARPOS (startp
) <= ZV
14121 && PT
>= CHARPOS (startp
)
14122 && (CHARPOS (startp
) < ZV
14123 /* Avoid starting at end of buffer. */
14124 || CHARPOS (startp
) == BEGV
14125 || (XFASTINT (w
->last_modified
) >= MODIFF
14126 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14129 /* If first window line is a continuation line, and window start
14130 is inside the modified region, but the first change is before
14131 current window start, we must select a new window start.
14133 However, if this is the result of a down-mouse event (e.g. by
14134 extending the mouse-drag-overlay), we don't want to select a
14135 new window start, since that would change the position under
14136 the mouse, resulting in an unwanted mouse-movement rather
14137 than a simple mouse-click. */
14138 if (NILP (w
->start_at_line_beg
)
14139 && NILP (do_mouse_tracking
)
14140 && CHARPOS (startp
) > BEGV
14141 && CHARPOS (startp
) > BEG
+ beg_unchanged
14142 && CHARPOS (startp
) <= Z
- end_unchanged
14143 /* Even if w->start_at_line_beg is nil, a new window may
14144 start at a line_beg, since that's how set_buffer_window
14145 sets it. So, we need to check the return value of
14146 compute_window_start_on_continuation_line. (See also
14148 && XMARKER (w
->start
)->buffer
== current_buffer
14149 && compute_window_start_on_continuation_line (w
))
14151 w
->force_start
= Qt
;
14152 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14157 debug_method_add (w
, "same window start");
14160 /* Try to redisplay starting at same place as before.
14161 If point has not moved off frame, accept the results. */
14162 if (!current_matrix_up_to_date_p
14163 /* Don't use try_window_reusing_current_matrix in this case
14164 because a window scroll function can have changed the
14166 || !NILP (Vwindow_scroll_functions
)
14167 || MINI_WINDOW_P (w
)
14168 || !(used_current_matrix_p
14169 = try_window_reusing_current_matrix (w
)))
14171 IF_DEBUG (debug_method_add (w
, "1"));
14172 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14173 /* -1 means we need to scroll.
14174 0 means we need new matrices, but fonts_changed_p
14175 is set in that case, so we will detect it below. */
14176 goto try_to_scroll
;
14179 if (fonts_changed_p
)
14180 goto need_larger_matrices
;
14182 if (w
->cursor
.vpos
>= 0)
14184 if (!just_this_one_p
14185 || current_buffer
->clip_changed
14186 || BEG_UNCHANGED
< CHARPOS (startp
))
14187 /* Forget any recorded base line for line number display. */
14188 w
->base_line_number
= Qnil
;
14190 if (!cursor_row_fully_visible_p (w
, 1, 0))
14192 clear_glyph_matrix (w
->desired_matrix
);
14193 last_line_misfit
= 1;
14195 /* Drop through and scroll. */
14200 clear_glyph_matrix (w
->desired_matrix
);
14205 w
->last_modified
= make_number (0);
14206 w
->last_overlay_modified
= make_number (0);
14208 /* Redisplay the mode line. Select the buffer properly for that. */
14209 if (!update_mode_line
)
14211 update_mode_line
= 1;
14212 w
->update_mode_line
= Qt
;
14215 /* Try to scroll by specified few lines. */
14216 if ((scroll_conservatively
14217 || emacs_scroll_step
14218 || temp_scroll_step
14219 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14220 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14221 && CHARPOS (startp
) >= BEGV
14222 && CHARPOS (startp
) <= ZV
)
14224 /* The function returns -1 if new fonts were loaded, 1 if
14225 successful, 0 if not successful. */
14226 int ss
= try_scrolling (window
, just_this_one_p
,
14227 scroll_conservatively
,
14229 temp_scroll_step
, last_line_misfit
);
14232 case SCROLLING_SUCCESS
:
14235 case SCROLLING_NEED_LARGER_MATRICES
:
14236 goto need_larger_matrices
;
14238 case SCROLLING_FAILED
:
14246 /* Finally, just choose a place to start which positions point
14247 according to user preferences. */
14252 debug_method_add (w
, "recenter");
14255 /* w->vscroll = 0; */
14257 /* Forget any previously recorded base line for line number display. */
14258 if (!buffer_unchanged_p
)
14259 w
->base_line_number
= Qnil
;
14261 /* Determine the window start relative to point. */
14262 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14263 it
.current_y
= it
.last_visible_y
;
14264 if (centering_position
< 0)
14268 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14270 EMACS_INT margin_pos
= CHARPOS (startp
);
14272 Lisp_Object aggressive
;
14274 /* If there is a scroll margin at the top of the window, find
14275 its character position. */
14277 /* Cannot call start_display if startp is not in the
14278 accessible region of the buffer. This can happen when we
14279 have just switched to a different buffer and/or changed
14280 its restriction. In that case, startp is initialized to
14281 the character position 1 (BEG) because we did not yet
14282 have chance to display the buffer even once. */
14283 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14287 start_display (&it1
, w
, startp
);
14288 move_it_vertically (&it1
, margin
);
14289 margin_pos
= IT_CHARPOS (it1
);
14291 scrolling_up
= PT
> margin_pos
;
14294 ? BVAR (current_buffer
, scroll_up_aggressively
)
14295 : BVAR (current_buffer
, scroll_down_aggressively
);
14297 if (!MINI_WINDOW_P (w
)
14298 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14302 /* Setting scroll-conservatively overrides
14303 scroll-*-aggressively. */
14304 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14306 double float_amount
= XFLOATINT (aggressive
);
14308 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14309 if (pt_offset
== 0 && float_amount
> 0)
14314 /* Compute how much to move the window start backward from
14315 point so that point will be displayed where the user
14319 centering_position
= it
.last_visible_y
;
14321 centering_position
-= pt_offset
;
14322 centering_position
-=
14323 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14324 /* Don't let point enter the scroll margin near top of
14326 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14327 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14330 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14333 /* Set the window start half the height of the window backward
14335 centering_position
= window_box_height (w
) / 2;
14337 move_it_vertically_backward (&it
, centering_position
);
14339 xassert (IT_CHARPOS (it
) >= BEGV
);
14341 /* The function move_it_vertically_backward may move over more
14342 than the specified y-distance. If it->w is small, e.g. a
14343 mini-buffer window, we may end up in front of the window's
14344 display area. Start displaying at the start of the line
14345 containing PT in this case. */
14346 if (it
.current_y
<= 0)
14348 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14349 move_it_vertically_backward (&it
, 0);
14353 it
.current_x
= it
.hpos
= 0;
14355 /* Set the window start position here explicitly, to avoid an
14356 infinite loop in case the functions in window-scroll-functions
14358 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14360 /* Run scroll hooks. */
14361 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14363 /* Redisplay the window. */
14364 if (!current_matrix_up_to_date_p
14365 || windows_or_buffers_changed
14366 || cursor_type_changed
14367 /* Don't use try_window_reusing_current_matrix in this case
14368 because it can have changed the buffer. */
14369 || !NILP (Vwindow_scroll_functions
)
14370 || !just_this_one_p
14371 || MINI_WINDOW_P (w
)
14372 || !(used_current_matrix_p
14373 = try_window_reusing_current_matrix (w
)))
14374 try_window (window
, startp
, 0);
14376 /* If new fonts have been loaded (due to fontsets), give up. We
14377 have to start a new redisplay since we need to re-adjust glyph
14379 if (fonts_changed_p
)
14380 goto need_larger_matrices
;
14382 /* If cursor did not appear assume that the middle of the window is
14383 in the first line of the window. Do it again with the next line.
14384 (Imagine a window of height 100, displaying two lines of height
14385 60. Moving back 50 from it->last_visible_y will end in the first
14387 if (w
->cursor
.vpos
< 0)
14389 if (!NILP (w
->window_end_valid
)
14390 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14392 clear_glyph_matrix (w
->desired_matrix
);
14393 move_it_by_lines (&it
, 1);
14394 try_window (window
, it
.current
.pos
, 0);
14396 else if (PT
< IT_CHARPOS (it
))
14398 clear_glyph_matrix (w
->desired_matrix
);
14399 move_it_by_lines (&it
, -1);
14400 try_window (window
, it
.current
.pos
, 0);
14404 /* Not much we can do about it. */
14408 /* Consider the following case: Window starts at BEGV, there is
14409 invisible, intangible text at BEGV, so that display starts at
14410 some point START > BEGV. It can happen that we are called with
14411 PT somewhere between BEGV and START. Try to handle that case. */
14412 if (w
->cursor
.vpos
< 0)
14414 struct glyph_row
*row
= w
->current_matrix
->rows
;
14415 if (row
->mode_line_p
)
14417 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14420 if (!cursor_row_fully_visible_p (w
, 0, 0))
14422 /* If vscroll is enabled, disable it and try again. */
14426 clear_glyph_matrix (w
->desired_matrix
);
14430 /* If centering point failed to make the whole line visible,
14431 put point at the top instead. That has to make the whole line
14432 visible, if it can be done. */
14433 if (centering_position
== 0)
14436 clear_glyph_matrix (w
->desired_matrix
);
14437 centering_position
= 0;
14443 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14444 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14445 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14448 /* Display the mode line, if we must. */
14449 if ((update_mode_line
14450 /* If window not full width, must redo its mode line
14451 if (a) the window to its side is being redone and
14452 (b) we do a frame-based redisplay. This is a consequence
14453 of how inverted lines are drawn in frame-based redisplay. */
14454 || (!just_this_one_p
14455 && !FRAME_WINDOW_P (f
)
14456 && !WINDOW_FULL_WIDTH_P (w
))
14457 /* Line number to display. */
14458 || INTEGERP (w
->base_line_pos
)
14459 /* Column number is displayed and different from the one displayed. */
14460 || (!NILP (w
->column_number_displayed
)
14461 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
14462 /* This means that the window has a mode line. */
14463 && (WINDOW_WANTS_MODELINE_P (w
)
14464 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14466 display_mode_lines (w
);
14468 /* If mode line height has changed, arrange for a thorough
14469 immediate redisplay using the correct mode line height. */
14470 if (WINDOW_WANTS_MODELINE_P (w
)
14471 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14473 fonts_changed_p
= 1;
14474 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14475 = DESIRED_MODE_LINE_HEIGHT (w
);
14478 /* If header line height has changed, arrange for a thorough
14479 immediate redisplay using the correct header line height. */
14480 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14481 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14483 fonts_changed_p
= 1;
14484 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14485 = DESIRED_HEADER_LINE_HEIGHT (w
);
14488 if (fonts_changed_p
)
14489 goto need_larger_matrices
;
14492 if (!line_number_displayed
14493 && !BUFFERP (w
->base_line_pos
))
14495 w
->base_line_pos
= Qnil
;
14496 w
->base_line_number
= Qnil
;
14501 /* When we reach a frame's selected window, redo the frame's menu bar. */
14502 if (update_mode_line
14503 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14505 int redisplay_menu_p
= 0;
14507 if (FRAME_WINDOW_P (f
))
14509 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14510 || defined (HAVE_NS) || defined (USE_GTK)
14511 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14513 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14517 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14519 if (redisplay_menu_p
)
14520 display_menu_bar (w
);
14522 #ifdef HAVE_WINDOW_SYSTEM
14523 if (FRAME_WINDOW_P (f
))
14525 #if defined (USE_GTK) || defined (HAVE_NS)
14526 if (FRAME_EXTERNAL_TOOL_BAR (f
))
14527 redisplay_tool_bar (f
);
14529 if (WINDOWP (f
->tool_bar_window
)
14530 && (FRAME_TOOL_BAR_LINES (f
) > 0
14531 || !NILP (Vauto_resize_tool_bars
))
14532 && redisplay_tool_bar (f
))
14533 ignore_mouse_drag_p
= 1;
14539 #ifdef HAVE_WINDOW_SYSTEM
14540 if (FRAME_WINDOW_P (f
)
14541 && update_window_fringes (w
, (just_this_one_p
14542 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14543 || w
->pseudo_window_p
)))
14547 if (draw_window_fringes (w
, 1))
14548 x_draw_vertical_border (w
);
14552 #endif /* HAVE_WINDOW_SYSTEM */
14554 /* We go to this label, with fonts_changed_p nonzero,
14555 if it is necessary to try again using larger glyph matrices.
14556 We have to redeem the scroll bar even in this case,
14557 because the loop in redisplay_internal expects that. */
14558 need_larger_matrices
:
14560 finish_scroll_bars
:
14562 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14564 /* Set the thumb's position and size. */
14565 set_vertical_scroll_bar (w
);
14567 /* Note that we actually used the scroll bar attached to this
14568 window, so it shouldn't be deleted at the end of redisplay. */
14569 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14570 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14573 /* Restore current_buffer and value of point in it. The window
14574 update may have changed the buffer, so first make sure `opoint'
14575 is still valid (Bug#6177). */
14576 if (CHARPOS (opoint
) < BEGV
)
14577 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14578 else if (CHARPOS (opoint
) > ZV
)
14579 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14581 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14583 set_buffer_internal_1 (old
);
14584 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14585 shorter. This can be caused by log truncation in *Messages*. */
14586 if (CHARPOS (lpoint
) <= ZV
)
14587 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14589 unbind_to (count
, Qnil
);
14593 /* Build the complete desired matrix of WINDOW with a window start
14594 buffer position POS.
14596 Value is 1 if successful. It is zero if fonts were loaded during
14597 redisplay which makes re-adjusting glyph matrices necessary, and -1
14598 if point would appear in the scroll margins.
14599 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14600 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14604 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14606 struct window
*w
= XWINDOW (window
);
14608 struct glyph_row
*last_text_row
= NULL
;
14609 struct frame
*f
= XFRAME (w
->frame
);
14611 /* Make POS the new window start. */
14612 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14614 /* Mark cursor position as unknown. No overlay arrow seen. */
14615 w
->cursor
.vpos
= -1;
14616 overlay_arrow_seen
= 0;
14618 /* Initialize iterator and info to start at POS. */
14619 start_display (&it
, w
, pos
);
14621 /* Display all lines of W. */
14622 while (it
.current_y
< it
.last_visible_y
)
14624 if (display_line (&it
))
14625 last_text_row
= it
.glyph_row
- 1;
14626 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
14630 /* Don't let the cursor end in the scroll margins. */
14631 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
14632 && !MINI_WINDOW_P (w
))
14634 int this_scroll_margin
;
14636 if (scroll_margin
> 0)
14638 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14639 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14642 this_scroll_margin
= 0;
14644 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14645 && w
->cursor
.y
< this_scroll_margin
14646 && CHARPOS (pos
) > BEGV
14647 && IT_CHARPOS (it
) < ZV
)
14648 /* rms: considering make_cursor_line_fully_visible_p here
14649 seems to give wrong results. We don't want to recenter
14650 when the last line is partly visible, we want to allow
14651 that case to be handled in the usual way. */
14652 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14654 w
->cursor
.vpos
= -1;
14655 clear_glyph_matrix (w
->desired_matrix
);
14660 /* If bottom moved off end of frame, change mode line percentage. */
14661 if (XFASTINT (w
->window_end_pos
) <= 0
14662 && Z
!= IT_CHARPOS (it
))
14663 w
->update_mode_line
= Qt
;
14665 /* Set window_end_pos to the offset of the last character displayed
14666 on the window from the end of current_buffer. Set
14667 window_end_vpos to its row number. */
14670 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14671 w
->window_end_bytepos
14672 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14674 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14676 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14677 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14678 ->displays_text_p
);
14682 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14683 w
->window_end_pos
= make_number (Z
- ZV
);
14684 w
->window_end_vpos
= make_number (0);
14687 /* But that is not valid info until redisplay finishes. */
14688 w
->window_end_valid
= Qnil
;
14694 /************************************************************************
14695 Window redisplay reusing current matrix when buffer has not changed
14696 ************************************************************************/
14698 /* Try redisplay of window W showing an unchanged buffer with a
14699 different window start than the last time it was displayed by
14700 reusing its current matrix. Value is non-zero if successful.
14701 W->start is the new window start. */
14704 try_window_reusing_current_matrix (struct window
*w
)
14706 struct frame
*f
= XFRAME (w
->frame
);
14707 struct glyph_row
*bottom_row
;
14710 struct text_pos start
, new_start
;
14711 int nrows_scrolled
, i
;
14712 struct glyph_row
*last_text_row
;
14713 struct glyph_row
*last_reused_text_row
;
14714 struct glyph_row
*start_row
;
14715 int start_vpos
, min_y
, max_y
;
14718 if (inhibit_try_window_reusing
)
14722 if (/* This function doesn't handle terminal frames. */
14723 !FRAME_WINDOW_P (f
)
14724 /* Don't try to reuse the display if windows have been split
14726 || windows_or_buffers_changed
14727 || cursor_type_changed
)
14730 /* Can't do this if region may have changed. */
14731 if ((!NILP (Vtransient_mark_mode
)
14732 && !NILP (BVAR (current_buffer
, mark_active
)))
14733 || !NILP (w
->region_showing
)
14734 || !NILP (Vshow_trailing_whitespace
))
14737 /* If top-line visibility has changed, give up. */
14738 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14739 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14742 /* Give up if old or new display is scrolled vertically. We could
14743 make this function handle this, but right now it doesn't. */
14744 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14745 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14748 /* The variable new_start now holds the new window start. The old
14749 start `start' can be determined from the current matrix. */
14750 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14751 start
= start_row
->minpos
;
14752 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14754 /* Clear the desired matrix for the display below. */
14755 clear_glyph_matrix (w
->desired_matrix
);
14757 if (CHARPOS (new_start
) <= CHARPOS (start
))
14759 /* Don't use this method if the display starts with an ellipsis
14760 displayed for invisible text. It's not easy to handle that case
14761 below, and it's certainly not worth the effort since this is
14762 not a frequent case. */
14763 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14766 IF_DEBUG (debug_method_add (w
, "twu1"));
14768 /* Display up to a row that can be reused. The variable
14769 last_text_row is set to the last row displayed that displays
14770 text. Note that it.vpos == 0 if or if not there is a
14771 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14772 start_display (&it
, w
, new_start
);
14773 w
->cursor
.vpos
= -1;
14774 last_text_row
= last_reused_text_row
= NULL
;
14776 while (it
.current_y
< it
.last_visible_y
14777 && !fonts_changed_p
)
14779 /* If we have reached into the characters in the START row,
14780 that means the line boundaries have changed. So we
14781 can't start copying with the row START. Maybe it will
14782 work to start copying with the following row. */
14783 while (IT_CHARPOS (it
) > CHARPOS (start
))
14785 /* Advance to the next row as the "start". */
14787 start
= start_row
->minpos
;
14788 /* If there are no more rows to try, or just one, give up. */
14789 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14790 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14791 || CHARPOS (start
) == ZV
)
14793 clear_glyph_matrix (w
->desired_matrix
);
14797 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14799 /* If we have reached alignment,
14800 we can copy the rest of the rows. */
14801 if (IT_CHARPOS (it
) == CHARPOS (start
))
14804 if (display_line (&it
))
14805 last_text_row
= it
.glyph_row
- 1;
14808 /* A value of current_y < last_visible_y means that we stopped
14809 at the previous window start, which in turn means that we
14810 have at least one reusable row. */
14811 if (it
.current_y
< it
.last_visible_y
)
14813 struct glyph_row
*row
;
14815 /* IT.vpos always starts from 0; it counts text lines. */
14816 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14818 /* Find PT if not already found in the lines displayed. */
14819 if (w
->cursor
.vpos
< 0)
14821 int dy
= it
.current_y
- start_row
->y
;
14823 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14824 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14826 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14827 dy
, nrows_scrolled
);
14830 clear_glyph_matrix (w
->desired_matrix
);
14835 /* Scroll the display. Do it before the current matrix is
14836 changed. The problem here is that update has not yet
14837 run, i.e. part of the current matrix is not up to date.
14838 scroll_run_hook will clear the cursor, and use the
14839 current matrix to get the height of the row the cursor is
14841 run
.current_y
= start_row
->y
;
14842 run
.desired_y
= it
.current_y
;
14843 run
.height
= it
.last_visible_y
- it
.current_y
;
14845 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14848 FRAME_RIF (f
)->update_window_begin_hook (w
);
14849 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14850 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14851 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14855 /* Shift current matrix down by nrows_scrolled lines. */
14856 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14857 rotate_matrix (w
->current_matrix
,
14859 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14862 /* Disable lines that must be updated. */
14863 for (i
= 0; i
< nrows_scrolled
; ++i
)
14864 (start_row
+ i
)->enabled_p
= 0;
14866 /* Re-compute Y positions. */
14867 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14868 max_y
= it
.last_visible_y
;
14869 for (row
= start_row
+ nrows_scrolled
;
14873 row
->y
= it
.current_y
;
14874 row
->visible_height
= row
->height
;
14876 if (row
->y
< min_y
)
14877 row
->visible_height
-= min_y
- row
->y
;
14878 if (row
->y
+ row
->height
> max_y
)
14879 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14880 row
->redraw_fringe_bitmaps_p
= 1;
14882 it
.current_y
+= row
->height
;
14884 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14885 last_reused_text_row
= row
;
14886 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14890 /* Disable lines in the current matrix which are now
14891 below the window. */
14892 for (++row
; row
< bottom_row
; ++row
)
14893 row
->enabled_p
= row
->mode_line_p
= 0;
14896 /* Update window_end_pos etc.; last_reused_text_row is the last
14897 reused row from the current matrix containing text, if any.
14898 The value of last_text_row is the last displayed line
14899 containing text. */
14900 if (last_reused_text_row
)
14902 w
->window_end_bytepos
14903 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14905 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14907 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14908 w
->current_matrix
));
14910 else if (last_text_row
)
14912 w
->window_end_bytepos
14913 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14915 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14917 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14921 /* This window must be completely empty. */
14922 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14923 w
->window_end_pos
= make_number (Z
- ZV
);
14924 w
->window_end_vpos
= make_number (0);
14926 w
->window_end_valid
= Qnil
;
14928 /* Update hint: don't try scrolling again in update_window. */
14929 w
->desired_matrix
->no_scrolling_p
= 1;
14932 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14936 else if (CHARPOS (new_start
) > CHARPOS (start
))
14938 struct glyph_row
*pt_row
, *row
;
14939 struct glyph_row
*first_reusable_row
;
14940 struct glyph_row
*first_row_to_display
;
14942 int yb
= window_text_bottom_y (w
);
14944 /* Find the row starting at new_start, if there is one. Don't
14945 reuse a partially visible line at the end. */
14946 first_reusable_row
= start_row
;
14947 while (first_reusable_row
->enabled_p
14948 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14949 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14950 < CHARPOS (new_start
)))
14951 ++first_reusable_row
;
14953 /* Give up if there is no row to reuse. */
14954 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14955 || !first_reusable_row
->enabled_p
14956 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14957 != CHARPOS (new_start
)))
14960 /* We can reuse fully visible rows beginning with
14961 first_reusable_row to the end of the window. Set
14962 first_row_to_display to the first row that cannot be reused.
14963 Set pt_row to the row containing point, if there is any. */
14965 for (first_row_to_display
= first_reusable_row
;
14966 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14967 ++first_row_to_display
)
14969 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14970 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14971 pt_row
= first_row_to_display
;
14974 /* Start displaying at the start of first_row_to_display. */
14975 xassert (first_row_to_display
->y
< yb
);
14976 init_to_row_start (&it
, w
, first_row_to_display
);
14978 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14980 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14982 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14983 + WINDOW_HEADER_LINE_HEIGHT (w
));
14985 /* Display lines beginning with first_row_to_display in the
14986 desired matrix. Set last_text_row to the last row displayed
14987 that displays text. */
14988 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14989 if (pt_row
== NULL
)
14990 w
->cursor
.vpos
= -1;
14991 last_text_row
= NULL
;
14992 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14993 if (display_line (&it
))
14994 last_text_row
= it
.glyph_row
- 1;
14996 /* If point is in a reused row, adjust y and vpos of the cursor
15000 w
->cursor
.vpos
-= nrows_scrolled
;
15001 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15004 /* Give up if point isn't in a row displayed or reused. (This
15005 also handles the case where w->cursor.vpos < nrows_scrolled
15006 after the calls to display_line, which can happen with scroll
15007 margins. See bug#1295.) */
15008 if (w
->cursor
.vpos
< 0)
15010 clear_glyph_matrix (w
->desired_matrix
);
15014 /* Scroll the display. */
15015 run
.current_y
= first_reusable_row
->y
;
15016 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15017 run
.height
= it
.last_visible_y
- run
.current_y
;
15018 dy
= run
.current_y
- run
.desired_y
;
15023 FRAME_RIF (f
)->update_window_begin_hook (w
);
15024 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15025 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15026 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15030 /* Adjust Y positions of reused rows. */
15031 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15032 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15033 max_y
= it
.last_visible_y
;
15034 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15037 row
->visible_height
= row
->height
;
15038 if (row
->y
< min_y
)
15039 row
->visible_height
-= min_y
- row
->y
;
15040 if (row
->y
+ row
->height
> max_y
)
15041 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15042 row
->redraw_fringe_bitmaps_p
= 1;
15045 /* Scroll the current matrix. */
15046 xassert (nrows_scrolled
> 0);
15047 rotate_matrix (w
->current_matrix
,
15049 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15052 /* Disable rows not reused. */
15053 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15054 row
->enabled_p
= 0;
15056 /* Point may have moved to a different line, so we cannot assume that
15057 the previous cursor position is valid; locate the correct row. */
15060 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15061 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15065 w
->cursor
.y
= row
->y
;
15067 if (row
< bottom_row
)
15069 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15070 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15072 /* Can't use this optimization with bidi-reordered glyph
15073 rows, unless cursor is already at point. */
15074 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15076 if (!(w
->cursor
.hpos
>= 0
15077 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15078 && BUFFERP (glyph
->object
)
15079 && glyph
->charpos
== PT
))
15084 && (!BUFFERP (glyph
->object
)
15085 || glyph
->charpos
< PT
);
15089 w
->cursor
.x
+= glyph
->pixel_width
;
15094 /* Adjust window end. A null value of last_text_row means that
15095 the window end is in reused rows which in turn means that
15096 only its vpos can have changed. */
15099 w
->window_end_bytepos
15100 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15102 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15104 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15109 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15112 w
->window_end_valid
= Qnil
;
15113 w
->desired_matrix
->no_scrolling_p
= 1;
15116 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15126 /************************************************************************
15127 Window redisplay reusing current matrix when buffer has changed
15128 ************************************************************************/
15130 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15131 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15132 EMACS_INT
*, EMACS_INT
*);
15133 static struct glyph_row
*
15134 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15135 struct glyph_row
*);
15138 /* Return the last row in MATRIX displaying text. If row START is
15139 non-null, start searching with that row. IT gives the dimensions
15140 of the display. Value is null if matrix is empty; otherwise it is
15141 a pointer to the row found. */
15143 static struct glyph_row
*
15144 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15145 struct glyph_row
*start
)
15147 struct glyph_row
*row
, *row_found
;
15149 /* Set row_found to the last row in IT->w's current matrix
15150 displaying text. The loop looks funny but think of partially
15153 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15154 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15156 xassert (row
->enabled_p
);
15158 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15167 /* Return the last row in the current matrix of W that is not affected
15168 by changes at the start of current_buffer that occurred since W's
15169 current matrix was built. Value is null if no such row exists.
15171 BEG_UNCHANGED us the number of characters unchanged at the start of
15172 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15173 first changed character in current_buffer. Characters at positions <
15174 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15175 when the current matrix was built. */
15177 static struct glyph_row
*
15178 find_last_unchanged_at_beg_row (struct window
*w
)
15180 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15181 struct glyph_row
*row
;
15182 struct glyph_row
*row_found
= NULL
;
15183 int yb
= window_text_bottom_y (w
);
15185 /* Find the last row displaying unchanged text. */
15186 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15187 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15188 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15191 if (/* If row ends before first_changed_pos, it is unchanged,
15192 except in some case. */
15193 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15194 /* When row ends in ZV and we write at ZV it is not
15196 && !row
->ends_at_zv_p
15197 /* When first_changed_pos is the end of a continued line,
15198 row is not unchanged because it may be no longer
15200 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15201 && (row
->continued_p
15202 || row
->exact_window_width_line_p
)))
15205 /* Stop if last visible row. */
15206 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15214 /* Find the first glyph row in the current matrix of W that is not
15215 affected by changes at the end of current_buffer since the
15216 time W's current matrix was built.
15218 Return in *DELTA the number of chars by which buffer positions in
15219 unchanged text at the end of current_buffer must be adjusted.
15221 Return in *DELTA_BYTES the corresponding number of bytes.
15223 Value is null if no such row exists, i.e. all rows are affected by
15226 static struct glyph_row
*
15227 find_first_unchanged_at_end_row (struct window
*w
,
15228 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15230 struct glyph_row
*row
;
15231 struct glyph_row
*row_found
= NULL
;
15233 *delta
= *delta_bytes
= 0;
15235 /* Display must not have been paused, otherwise the current matrix
15236 is not up to date. */
15237 eassert (!NILP (w
->window_end_valid
));
15239 /* A value of window_end_pos >= END_UNCHANGED means that the window
15240 end is in the range of changed text. If so, there is no
15241 unchanged row at the end of W's current matrix. */
15242 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15245 /* Set row to the last row in W's current matrix displaying text. */
15246 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15248 /* If matrix is entirely empty, no unchanged row exists. */
15249 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15251 /* The value of row is the last glyph row in the matrix having a
15252 meaningful buffer position in it. The end position of row
15253 corresponds to window_end_pos. This allows us to translate
15254 buffer positions in the current matrix to current buffer
15255 positions for characters not in changed text. */
15257 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15258 EMACS_INT Z_BYTE_old
=
15259 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15260 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15261 struct glyph_row
*first_text_row
15262 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15264 *delta
= Z
- Z_old
;
15265 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15267 /* Set last_unchanged_pos to the buffer position of the last
15268 character in the buffer that has not been changed. Z is the
15269 index + 1 of the last character in current_buffer, i.e. by
15270 subtracting END_UNCHANGED we get the index of the last
15271 unchanged character, and we have to add BEG to get its buffer
15273 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15274 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15276 /* Search backward from ROW for a row displaying a line that
15277 starts at a minimum position >= last_unchanged_pos_old. */
15278 for (; row
> first_text_row
; --row
)
15280 /* This used to abort, but it can happen.
15281 It is ok to just stop the search instead here. KFS. */
15282 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15285 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15290 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15296 /* Make sure that glyph rows in the current matrix of window W
15297 reference the same glyph memory as corresponding rows in the
15298 frame's frame matrix. This function is called after scrolling W's
15299 current matrix on a terminal frame in try_window_id and
15300 try_window_reusing_current_matrix. */
15303 sync_frame_with_window_matrix_rows (struct window
*w
)
15305 struct frame
*f
= XFRAME (w
->frame
);
15306 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15308 /* Preconditions: W must be a leaf window and full-width. Its frame
15309 must have a frame matrix. */
15310 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15311 xassert (WINDOW_FULL_WIDTH_P (w
));
15312 xassert (!FRAME_WINDOW_P (f
));
15314 /* If W is a full-width window, glyph pointers in W's current matrix
15315 have, by definition, to be the same as glyph pointers in the
15316 corresponding frame matrix. Note that frame matrices have no
15317 marginal areas (see build_frame_matrix). */
15318 window_row
= w
->current_matrix
->rows
;
15319 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15320 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15321 while (window_row
< window_row_end
)
15323 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15324 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15326 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15327 frame_row
->glyphs
[TEXT_AREA
] = start
;
15328 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15329 frame_row
->glyphs
[LAST_AREA
] = end
;
15331 /* Disable frame rows whose corresponding window rows have
15332 been disabled in try_window_id. */
15333 if (!window_row
->enabled_p
)
15334 frame_row
->enabled_p
= 0;
15336 ++window_row
, ++frame_row
;
15341 /* Find the glyph row in window W containing CHARPOS. Consider all
15342 rows between START and END (not inclusive). END null means search
15343 all rows to the end of the display area of W. Value is the row
15344 containing CHARPOS or null. */
15347 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15348 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15350 struct glyph_row
*row
= start
;
15351 struct glyph_row
*best_row
= NULL
;
15352 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15355 /* If we happen to start on a header-line, skip that. */
15356 if (row
->mode_line_p
)
15359 if ((end
&& row
>= end
) || !row
->enabled_p
)
15362 last_y
= window_text_bottom_y (w
) - dy
;
15366 /* Give up if we have gone too far. */
15367 if (end
&& row
>= end
)
15369 /* This formerly returned if they were equal.
15370 I think that both quantities are of a "last plus one" type;
15371 if so, when they are equal, the row is within the screen. -- rms. */
15372 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15375 /* If it is in this row, return this row. */
15376 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15377 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15378 /* The end position of a row equals the start
15379 position of the next row. If CHARPOS is there, we
15380 would rather display it in the next line, except
15381 when this line ends in ZV. */
15382 && !row
->ends_at_zv_p
15383 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15384 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15388 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15389 || (!best_row
&& !row
->continued_p
))
15391 /* In bidi-reordered rows, there could be several rows
15392 occluding point, all of them belonging to the same
15393 continued line. We need to find the row which fits
15394 CHARPOS the best. */
15395 for (g
= row
->glyphs
[TEXT_AREA
];
15396 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15399 if (!STRINGP (g
->object
))
15401 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15403 mindif
= eabs (g
->charpos
- charpos
);
15405 /* Exact match always wins. */
15412 else if (best_row
&& !row
->continued_p
)
15419 /* Try to redisplay window W by reusing its existing display. W's
15420 current matrix must be up to date when this function is called,
15421 i.e. window_end_valid must not be nil.
15425 1 if display has been updated
15426 0 if otherwise unsuccessful
15427 -1 if redisplay with same window start is known not to succeed
15429 The following steps are performed:
15431 1. Find the last row in the current matrix of W that is not
15432 affected by changes at the start of current_buffer. If no such row
15435 2. Find the first row in W's current matrix that is not affected by
15436 changes at the end of current_buffer. Maybe there is no such row.
15438 3. Display lines beginning with the row + 1 found in step 1 to the
15439 row found in step 2 or, if step 2 didn't find a row, to the end of
15442 4. If cursor is not known to appear on the window, give up.
15444 5. If display stopped at the row found in step 2, scroll the
15445 display and current matrix as needed.
15447 6. Maybe display some lines at the end of W, if we must. This can
15448 happen under various circumstances, like a partially visible line
15449 becoming fully visible, or because newly displayed lines are displayed
15450 in smaller font sizes.
15452 7. Update W's window end information. */
15455 try_window_id (struct window
*w
)
15457 struct frame
*f
= XFRAME (w
->frame
);
15458 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15459 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15460 struct glyph_row
*last_unchanged_at_beg_row
;
15461 struct glyph_row
*first_unchanged_at_end_row
;
15462 struct glyph_row
*row
;
15463 struct glyph_row
*bottom_row
;
15466 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15468 struct text_pos start_pos
;
15470 int first_unchanged_at_end_vpos
= 0;
15471 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15472 struct text_pos start
;
15473 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15476 if (inhibit_try_window_id
)
15480 /* This is handy for debugging. */
15482 #define GIVE_UP(X) \
15484 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15488 #define GIVE_UP(X) return 0
15491 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15493 /* Don't use this for mini-windows because these can show
15494 messages and mini-buffers, and we don't handle that here. */
15495 if (MINI_WINDOW_P (w
))
15498 /* This flag is used to prevent redisplay optimizations. */
15499 if (windows_or_buffers_changed
|| cursor_type_changed
)
15502 /* Verify that narrowing has not changed.
15503 Also verify that we were not told to prevent redisplay optimizations.
15504 It would be nice to further
15505 reduce the number of cases where this prevents try_window_id. */
15506 if (current_buffer
->clip_changed
15507 || current_buffer
->prevent_redisplay_optimizations_p
)
15510 /* Window must either use window-based redisplay or be full width. */
15511 if (!FRAME_WINDOW_P (f
)
15512 && (!FRAME_LINE_INS_DEL_OK (f
)
15513 || !WINDOW_FULL_WIDTH_P (w
)))
15516 /* Give up if point is known NOT to appear in W. */
15517 if (PT
< CHARPOS (start
))
15520 /* Another way to prevent redisplay optimizations. */
15521 if (XFASTINT (w
->last_modified
) == 0)
15524 /* Verify that window is not hscrolled. */
15525 if (XFASTINT (w
->hscroll
) != 0)
15528 /* Verify that display wasn't paused. */
15529 if (NILP (w
->window_end_valid
))
15532 /* Can't use this if highlighting a region because a cursor movement
15533 will do more than just set the cursor. */
15534 if (!NILP (Vtransient_mark_mode
)
15535 && !NILP (BVAR (current_buffer
, mark_active
)))
15538 /* Likewise if highlighting trailing whitespace. */
15539 if (!NILP (Vshow_trailing_whitespace
))
15542 /* Likewise if showing a region. */
15543 if (!NILP (w
->region_showing
))
15546 /* Can't use this if overlay arrow position and/or string have
15548 if (overlay_arrows_changed_p ())
15551 /* When word-wrap is on, adding a space to the first word of a
15552 wrapped line can change the wrap position, altering the line
15553 above it. It might be worthwhile to handle this more
15554 intelligently, but for now just redisplay from scratch. */
15555 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
15558 /* Under bidi reordering, adding or deleting a character in the
15559 beginning of a paragraph, before the first strong directional
15560 character, can change the base direction of the paragraph (unless
15561 the buffer specifies a fixed paragraph direction), which will
15562 require to redisplay the whole paragraph. It might be worthwhile
15563 to find the paragraph limits and widen the range of redisplayed
15564 lines to that, but for now just give up this optimization and
15565 redisplay from scratch. */
15566 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15567 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
15570 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15571 only if buffer has really changed. The reason is that the gap is
15572 initially at Z for freshly visited files. The code below would
15573 set end_unchanged to 0 in that case. */
15574 if (MODIFF
> SAVE_MODIFF
15575 /* This seems to happen sometimes after saving a buffer. */
15576 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15578 if (GPT
- BEG
< BEG_UNCHANGED
)
15579 BEG_UNCHANGED
= GPT
- BEG
;
15580 if (Z
- GPT
< END_UNCHANGED
)
15581 END_UNCHANGED
= Z
- GPT
;
15584 /* The position of the first and last character that has been changed. */
15585 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15586 last_changed_charpos
= Z
- END_UNCHANGED
;
15588 /* If window starts after a line end, and the last change is in
15589 front of that newline, then changes don't affect the display.
15590 This case happens with stealth-fontification. Note that although
15591 the display is unchanged, glyph positions in the matrix have to
15592 be adjusted, of course. */
15593 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15594 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15595 && ((last_changed_charpos
< CHARPOS (start
)
15596 && CHARPOS (start
) == BEGV
)
15597 || (last_changed_charpos
< CHARPOS (start
) - 1
15598 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15600 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
15601 struct glyph_row
*r0
;
15603 /* Compute how many chars/bytes have been added to or removed
15604 from the buffer. */
15605 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15606 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15607 Z_delta
= Z
- Z_old
;
15608 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15610 /* Give up if PT is not in the window. Note that it already has
15611 been checked at the start of try_window_id that PT is not in
15612 front of the window start. */
15613 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
15616 /* If window start is unchanged, we can reuse the whole matrix
15617 as is, after adjusting glyph positions. No need to compute
15618 the window end again, since its offset from Z hasn't changed. */
15619 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15620 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
15621 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
15622 /* PT must not be in a partially visible line. */
15623 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
15624 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15626 /* Adjust positions in the glyph matrix. */
15627 if (Z_delta
|| Z_delta_bytes
)
15629 struct glyph_row
*r1
15630 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15631 increment_matrix_positions (w
->current_matrix
,
15632 MATRIX_ROW_VPOS (r0
, current_matrix
),
15633 MATRIX_ROW_VPOS (r1
, current_matrix
),
15634 Z_delta
, Z_delta_bytes
);
15637 /* Set the cursor. */
15638 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15640 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15647 /* Handle the case that changes are all below what is displayed in
15648 the window, and that PT is in the window. This shortcut cannot
15649 be taken if ZV is visible in the window, and text has been added
15650 there that is visible in the window. */
15651 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15652 /* ZV is not visible in the window, or there are no
15653 changes at ZV, actually. */
15654 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15655 || first_changed_charpos
== last_changed_charpos
))
15657 struct glyph_row
*r0
;
15659 /* Give up if PT is not in the window. Note that it already has
15660 been checked at the start of try_window_id that PT is not in
15661 front of the window start. */
15662 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15665 /* If window start is unchanged, we can reuse the whole matrix
15666 as is, without changing glyph positions since no text has
15667 been added/removed in front of the window end. */
15668 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15669 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
15670 /* PT must not be in a partially visible line. */
15671 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15672 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15674 /* We have to compute the window end anew since text
15675 could have been added/removed after it. */
15677 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15678 w
->window_end_bytepos
15679 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15681 /* Set the cursor. */
15682 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15684 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15691 /* Give up if window start is in the changed area.
15693 The condition used to read
15695 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15697 but why that was tested escapes me at the moment. */
15698 if (CHARPOS (start
) >= first_changed_charpos
15699 && CHARPOS (start
) <= last_changed_charpos
)
15702 /* Check that window start agrees with the start of the first glyph
15703 row in its current matrix. Check this after we know the window
15704 start is not in changed text, otherwise positions would not be
15706 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15707 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
15710 /* Give up if the window ends in strings. Overlay strings
15711 at the end are difficult to handle, so don't try. */
15712 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15713 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15716 /* Compute the position at which we have to start displaying new
15717 lines. Some of the lines at the top of the window might be
15718 reusable because they are not displaying changed text. Find the
15719 last row in W's current matrix not affected by changes at the
15720 start of current_buffer. Value is null if changes start in the
15721 first line of window. */
15722 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15723 if (last_unchanged_at_beg_row
)
15725 /* Avoid starting to display in the moddle of a character, a TAB
15726 for instance. This is easier than to set up the iterator
15727 exactly, and it's not a frequent case, so the additional
15728 effort wouldn't really pay off. */
15729 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15730 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15731 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15732 --last_unchanged_at_beg_row
;
15734 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15737 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15739 start_pos
= it
.current
.pos
;
15741 /* Start displaying new lines in the desired matrix at the same
15742 vpos we would use in the current matrix, i.e. below
15743 last_unchanged_at_beg_row. */
15744 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15746 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15747 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15749 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15753 /* There are no reusable lines at the start of the window.
15754 Start displaying in the first text line. */
15755 start_display (&it
, w
, start
);
15756 it
.vpos
= it
.first_vpos
;
15757 start_pos
= it
.current
.pos
;
15760 /* Find the first row that is not affected by changes at the end of
15761 the buffer. Value will be null if there is no unchanged row, in
15762 which case we must redisplay to the end of the window. delta
15763 will be set to the value by which buffer positions beginning with
15764 first_unchanged_at_end_row have to be adjusted due to text
15766 first_unchanged_at_end_row
15767 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15768 IF_DEBUG (debug_delta
= delta
);
15769 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15771 /* Set stop_pos to the buffer position up to which we will have to
15772 display new lines. If first_unchanged_at_end_row != NULL, this
15773 is the buffer position of the start of the line displayed in that
15774 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15775 that we don't stop at a buffer position. */
15777 if (first_unchanged_at_end_row
)
15779 xassert (last_unchanged_at_beg_row
== NULL
15780 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15782 /* If this is a continuation line, move forward to the next one
15783 that isn't. Changes in lines above affect this line.
15784 Caution: this may move first_unchanged_at_end_row to a row
15785 not displaying text. */
15786 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15787 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15788 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15789 < it
.last_visible_y
))
15790 ++first_unchanged_at_end_row
;
15792 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15793 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15794 >= it
.last_visible_y
))
15795 first_unchanged_at_end_row
= NULL
;
15798 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15800 first_unchanged_at_end_vpos
15801 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15802 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15805 else if (last_unchanged_at_beg_row
== NULL
)
15811 /* Either there is no unchanged row at the end, or the one we have
15812 now displays text. This is a necessary condition for the window
15813 end pos calculation at the end of this function. */
15814 xassert (first_unchanged_at_end_row
== NULL
15815 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15817 debug_last_unchanged_at_beg_vpos
15818 = (last_unchanged_at_beg_row
15819 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15821 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15823 #endif /* GLYPH_DEBUG != 0 */
15826 /* Display new lines. Set last_text_row to the last new line
15827 displayed which has text on it, i.e. might end up as being the
15828 line where the window_end_vpos is. */
15829 w
->cursor
.vpos
= -1;
15830 last_text_row
= NULL
;
15831 overlay_arrow_seen
= 0;
15832 while (it
.current_y
< it
.last_visible_y
15833 && !fonts_changed_p
15834 && (first_unchanged_at_end_row
== NULL
15835 || IT_CHARPOS (it
) < stop_pos
))
15837 if (display_line (&it
))
15838 last_text_row
= it
.glyph_row
- 1;
15841 if (fonts_changed_p
)
15845 /* Compute differences in buffer positions, y-positions etc. for
15846 lines reused at the bottom of the window. Compute what we can
15848 if (first_unchanged_at_end_row
15849 /* No lines reused because we displayed everything up to the
15850 bottom of the window. */
15851 && it
.current_y
< it
.last_visible_y
)
15854 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15856 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15857 run
.current_y
= first_unchanged_at_end_row
->y
;
15858 run
.desired_y
= run
.current_y
+ dy
;
15859 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15863 delta
= delta_bytes
= dvpos
= dy
15864 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15865 first_unchanged_at_end_row
= NULL
;
15867 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15870 /* Find the cursor if not already found. We have to decide whether
15871 PT will appear on this window (it sometimes doesn't, but this is
15872 not a very frequent case.) This decision has to be made before
15873 the current matrix is altered. A value of cursor.vpos < 0 means
15874 that PT is either in one of the lines beginning at
15875 first_unchanged_at_end_row or below the window. Don't care for
15876 lines that might be displayed later at the window end; as
15877 mentioned, this is not a frequent case. */
15878 if (w
->cursor
.vpos
< 0)
15880 /* Cursor in unchanged rows at the top? */
15881 if (PT
< CHARPOS (start_pos
)
15882 && last_unchanged_at_beg_row
)
15884 row
= row_containing_pos (w
, PT
,
15885 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15886 last_unchanged_at_beg_row
+ 1, 0);
15888 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15891 /* Start from first_unchanged_at_end_row looking for PT. */
15892 else if (first_unchanged_at_end_row
)
15894 row
= row_containing_pos (w
, PT
- delta
,
15895 first_unchanged_at_end_row
, NULL
, 0);
15897 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15898 delta_bytes
, dy
, dvpos
);
15901 /* Give up if cursor was not found. */
15902 if (w
->cursor
.vpos
< 0)
15904 clear_glyph_matrix (w
->desired_matrix
);
15909 /* Don't let the cursor end in the scroll margins. */
15911 int this_scroll_margin
, cursor_height
;
15913 this_scroll_margin
= max (0, scroll_margin
);
15914 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15915 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15916 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15918 if ((w
->cursor
.y
< this_scroll_margin
15919 && CHARPOS (start
) > BEGV
)
15920 /* Old redisplay didn't take scroll margin into account at the bottom,
15921 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15922 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15923 ? cursor_height
+ this_scroll_margin
15924 : 1)) > it
.last_visible_y
)
15926 w
->cursor
.vpos
= -1;
15927 clear_glyph_matrix (w
->desired_matrix
);
15932 /* Scroll the display. Do it before changing the current matrix so
15933 that xterm.c doesn't get confused about where the cursor glyph is
15935 if (dy
&& run
.height
)
15939 if (FRAME_WINDOW_P (f
))
15941 FRAME_RIF (f
)->update_window_begin_hook (w
);
15942 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15943 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15944 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15948 /* Terminal frame. In this case, dvpos gives the number of
15949 lines to scroll by; dvpos < 0 means scroll up. */
15951 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15952 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
15953 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15954 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15955 + window_internal_height (w
));
15957 #if defined (HAVE_GPM) || defined (MSDOS)
15958 x_clear_window_mouse_face (w
);
15960 /* Perform the operation on the screen. */
15963 /* Scroll last_unchanged_at_beg_row to the end of the
15964 window down dvpos lines. */
15965 set_terminal_window (f
, end
);
15967 /* On dumb terminals delete dvpos lines at the end
15968 before inserting dvpos empty lines. */
15969 if (!FRAME_SCROLL_REGION_OK (f
))
15970 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15972 /* Insert dvpos empty lines in front of
15973 last_unchanged_at_beg_row. */
15974 ins_del_lines (f
, from
, dvpos
);
15976 else if (dvpos
< 0)
15978 /* Scroll up last_unchanged_at_beg_vpos to the end of
15979 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15980 set_terminal_window (f
, end
);
15982 /* Delete dvpos lines in front of
15983 last_unchanged_at_beg_vpos. ins_del_lines will set
15984 the cursor to the given vpos and emit |dvpos| delete
15986 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15988 /* On a dumb terminal insert dvpos empty lines at the
15990 if (!FRAME_SCROLL_REGION_OK (f
))
15991 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15994 set_terminal_window (f
, 0);
16000 /* Shift reused rows of the current matrix to the right position.
16001 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16003 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16004 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16007 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16008 bottom_vpos
, dvpos
);
16009 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16012 else if (dvpos
> 0)
16014 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16015 bottom_vpos
, dvpos
);
16016 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16017 first_unchanged_at_end_vpos
+ dvpos
, 0);
16020 /* For frame-based redisplay, make sure that current frame and window
16021 matrix are in sync with respect to glyph memory. */
16022 if (!FRAME_WINDOW_P (f
))
16023 sync_frame_with_window_matrix_rows (w
);
16025 /* Adjust buffer positions in reused rows. */
16026 if (delta
|| delta_bytes
)
16027 increment_matrix_positions (current_matrix
,
16028 first_unchanged_at_end_vpos
+ dvpos
,
16029 bottom_vpos
, delta
, delta_bytes
);
16031 /* Adjust Y positions. */
16033 shift_glyph_matrix (w
, current_matrix
,
16034 first_unchanged_at_end_vpos
+ dvpos
,
16037 if (first_unchanged_at_end_row
)
16039 first_unchanged_at_end_row
+= dvpos
;
16040 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16041 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16042 first_unchanged_at_end_row
= NULL
;
16045 /* If scrolling up, there may be some lines to display at the end of
16047 last_text_row_at_end
= NULL
;
16050 /* Scrolling up can leave for example a partially visible line
16051 at the end of the window to be redisplayed. */
16052 /* Set last_row to the glyph row in the current matrix where the
16053 window end line is found. It has been moved up or down in
16054 the matrix by dvpos. */
16055 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16056 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16058 /* If last_row is the window end line, it should display text. */
16059 xassert (last_row
->displays_text_p
);
16061 /* If window end line was partially visible before, begin
16062 displaying at that line. Otherwise begin displaying with the
16063 line following it. */
16064 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16066 init_to_row_start (&it
, w
, last_row
);
16067 it
.vpos
= last_vpos
;
16068 it
.current_y
= last_row
->y
;
16072 init_to_row_end (&it
, w
, last_row
);
16073 it
.vpos
= 1 + last_vpos
;
16074 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16078 /* We may start in a continuation line. If so, we have to
16079 get the right continuation_lines_width and current_x. */
16080 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16081 it
.hpos
= it
.current_x
= 0;
16083 /* Display the rest of the lines at the window end. */
16084 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16085 while (it
.current_y
< it
.last_visible_y
16086 && !fonts_changed_p
)
16088 /* Is it always sure that the display agrees with lines in
16089 the current matrix? I don't think so, so we mark rows
16090 displayed invalid in the current matrix by setting their
16091 enabled_p flag to zero. */
16092 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16093 if (display_line (&it
))
16094 last_text_row_at_end
= it
.glyph_row
- 1;
16098 /* Update window_end_pos and window_end_vpos. */
16099 if (first_unchanged_at_end_row
16100 && !last_text_row_at_end
)
16102 /* Window end line if one of the preserved rows from the current
16103 matrix. Set row to the last row displaying text in current
16104 matrix starting at first_unchanged_at_end_row, after
16106 xassert (first_unchanged_at_end_row
->displays_text_p
);
16107 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16108 first_unchanged_at_end_row
);
16109 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16111 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16112 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16114 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16115 xassert (w
->window_end_bytepos
>= 0);
16116 IF_DEBUG (debug_method_add (w
, "A"));
16118 else if (last_text_row_at_end
)
16121 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16122 w
->window_end_bytepos
16123 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16125 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16126 xassert (w
->window_end_bytepos
>= 0);
16127 IF_DEBUG (debug_method_add (w
, "B"));
16129 else if (last_text_row
)
16131 /* We have displayed either to the end of the window or at the
16132 end of the window, i.e. the last row with text is to be found
16133 in the desired matrix. */
16135 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16136 w
->window_end_bytepos
16137 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16139 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16140 xassert (w
->window_end_bytepos
>= 0);
16142 else if (first_unchanged_at_end_row
== NULL
16143 && last_text_row
== NULL
16144 && last_text_row_at_end
== NULL
)
16146 /* Displayed to end of window, but no line containing text was
16147 displayed. Lines were deleted at the end of the window. */
16148 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16149 int vpos
= XFASTINT (w
->window_end_vpos
);
16150 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16151 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16154 row
== NULL
&& vpos
>= first_vpos
;
16155 --vpos
, --current_row
, --desired_row
)
16157 if (desired_row
->enabled_p
)
16159 if (desired_row
->displays_text_p
)
16162 else if (current_row
->displays_text_p
)
16166 xassert (row
!= NULL
);
16167 w
->window_end_vpos
= make_number (vpos
+ 1);
16168 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16169 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16170 xassert (w
->window_end_bytepos
>= 0);
16171 IF_DEBUG (debug_method_add (w
, "C"));
16176 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16177 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16179 /* Record that display has not been completed. */
16180 w
->window_end_valid
= Qnil
;
16181 w
->desired_matrix
->no_scrolling_p
= 1;
16189 /***********************************************************************
16190 More debugging support
16191 ***********************************************************************/
16195 void dump_glyph_row (struct glyph_row
*, int, int);
16196 void dump_glyph_matrix (struct glyph_matrix
*, int);
16197 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16200 /* Dump the contents of glyph matrix MATRIX on stderr.
16202 GLYPHS 0 means don't show glyph contents.
16203 GLYPHS 1 means show glyphs in short form
16204 GLYPHS > 1 means show glyphs in long form. */
16207 dump_glyph_matrix (matrix
, glyphs
)
16208 struct glyph_matrix
*matrix
;
16212 for (i
= 0; i
< matrix
->nrows
; ++i
)
16213 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16217 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16218 the glyph row and area where the glyph comes from. */
16221 dump_glyph (row
, glyph
, area
)
16222 struct glyph_row
*row
;
16223 struct glyph
*glyph
;
16226 if (glyph
->type
== CHAR_GLYPH
)
16229 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16230 glyph
- row
->glyphs
[TEXT_AREA
],
16233 (BUFFERP (glyph
->object
)
16235 : (STRINGP (glyph
->object
)
16238 glyph
->pixel_width
,
16240 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16244 glyph
->left_box_line_p
,
16245 glyph
->right_box_line_p
);
16247 else if (glyph
->type
== STRETCH_GLYPH
)
16250 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16251 glyph
- row
->glyphs
[TEXT_AREA
],
16254 (BUFFERP (glyph
->object
)
16256 : (STRINGP (glyph
->object
)
16259 glyph
->pixel_width
,
16263 glyph
->left_box_line_p
,
16264 glyph
->right_box_line_p
);
16266 else if (glyph
->type
== IMAGE_GLYPH
)
16269 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16270 glyph
- row
->glyphs
[TEXT_AREA
],
16273 (BUFFERP (glyph
->object
)
16275 : (STRINGP (glyph
->object
)
16278 glyph
->pixel_width
,
16282 glyph
->left_box_line_p
,
16283 glyph
->right_box_line_p
);
16285 else if (glyph
->type
== COMPOSITE_GLYPH
)
16288 " %5d %4c %6d %c %3d 0x%05x",
16289 glyph
- row
->glyphs
[TEXT_AREA
],
16292 (BUFFERP (glyph
->object
)
16294 : (STRINGP (glyph
->object
)
16297 glyph
->pixel_width
,
16299 if (glyph
->u
.cmp
.automatic
)
16302 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16303 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16305 glyph
->left_box_line_p
,
16306 glyph
->right_box_line_p
);
16311 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16312 GLYPHS 0 means don't show glyph contents.
16313 GLYPHS 1 means show glyphs in short form
16314 GLYPHS > 1 means show glyphs in long form. */
16317 dump_glyph_row (row
, vpos
, glyphs
)
16318 struct glyph_row
*row
;
16323 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16324 fprintf (stderr
, "======================================================================\n");
16326 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16327 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16329 MATRIX_ROW_START_CHARPOS (row
),
16330 MATRIX_ROW_END_CHARPOS (row
),
16331 row
->used
[TEXT_AREA
],
16332 row
->contains_overlapping_glyphs_p
,
16334 row
->truncated_on_left_p
,
16335 row
->truncated_on_right_p
,
16337 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16338 row
->displays_text_p
,
16341 row
->ends_in_middle_of_char_p
,
16342 row
->starts_in_middle_of_char_p
,
16348 row
->visible_height
,
16351 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16352 row
->end
.overlay_string_index
,
16353 row
->continuation_lines_width
);
16354 fprintf (stderr
, "%9d %5d\n",
16355 CHARPOS (row
->start
.string_pos
),
16356 CHARPOS (row
->end
.string_pos
));
16357 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16358 row
->end
.dpvec_index
);
16365 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16367 struct glyph
*glyph
= row
->glyphs
[area
];
16368 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16370 /* Glyph for a line end in text. */
16371 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16374 if (glyph
< glyph_end
)
16375 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16377 for (; glyph
< glyph_end
; ++glyph
)
16378 dump_glyph (row
, glyph
, area
);
16381 else if (glyphs
== 1)
16385 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16387 char *s
= (char *) alloca (row
->used
[area
] + 1);
16390 for (i
= 0; i
< row
->used
[area
]; ++i
)
16392 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16393 if (glyph
->type
== CHAR_GLYPH
16394 && glyph
->u
.ch
< 0x80
16395 && glyph
->u
.ch
>= ' ')
16396 s
[i
] = glyph
->u
.ch
;
16402 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16408 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16409 Sdump_glyph_matrix
, 0, 1, "p",
16410 doc
: /* Dump the current matrix of the selected window to stderr.
16411 Shows contents of glyph row structures. With non-nil
16412 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16413 glyphs in short form, otherwise show glyphs in long form. */)
16414 (Lisp_Object glyphs
)
16416 struct window
*w
= XWINDOW (selected_window
);
16417 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16419 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16420 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16421 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16422 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16423 fprintf (stderr
, "=============================================\n");
16424 dump_glyph_matrix (w
->current_matrix
,
16425 NILP (glyphs
) ? 0 : XINT (glyphs
));
16430 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16431 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16434 struct frame
*f
= XFRAME (selected_frame
);
16435 dump_glyph_matrix (f
->current_matrix
, 1);
16440 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16441 doc
: /* Dump glyph row ROW to stderr.
16442 GLYPH 0 means don't dump glyphs.
16443 GLYPH 1 means dump glyphs in short form.
16444 GLYPH > 1 or omitted means dump glyphs in long form. */)
16445 (Lisp_Object row
, Lisp_Object glyphs
)
16447 struct glyph_matrix
*matrix
;
16450 CHECK_NUMBER (row
);
16451 matrix
= XWINDOW (selected_window
)->current_matrix
;
16453 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16454 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16456 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16461 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16462 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16463 GLYPH 0 means don't dump glyphs.
16464 GLYPH 1 means dump glyphs in short form.
16465 GLYPH > 1 or omitted means dump glyphs in long form. */)
16466 (Lisp_Object row
, Lisp_Object glyphs
)
16468 struct frame
*sf
= SELECTED_FRAME ();
16469 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16472 CHECK_NUMBER (row
);
16474 if (vpos
>= 0 && vpos
< m
->nrows
)
16475 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16476 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16481 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16482 doc
: /* Toggle tracing of redisplay.
16483 With ARG, turn tracing on if and only if ARG is positive. */)
16487 trace_redisplay_p
= !trace_redisplay_p
;
16490 arg
= Fprefix_numeric_value (arg
);
16491 trace_redisplay_p
= XINT (arg
) > 0;
16498 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16499 doc
: /* Like `format', but print result to stderr.
16500 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16501 (size_t nargs
, Lisp_Object
*args
)
16503 Lisp_Object s
= Fformat (nargs
, args
);
16504 fprintf (stderr
, "%s", SDATA (s
));
16508 #endif /* GLYPH_DEBUG */
16512 /***********************************************************************
16513 Building Desired Matrix Rows
16514 ***********************************************************************/
16516 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16517 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16519 static struct glyph_row
*
16520 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16522 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16523 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16524 struct buffer
*old
= current_buffer
;
16525 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16526 int arrow_len
= SCHARS (overlay_arrow_string
);
16527 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16528 const unsigned char *p
;
16531 int n_glyphs_before
;
16533 set_buffer_temp (buffer
);
16534 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16535 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16536 SET_TEXT_POS (it
.position
, 0, 0);
16538 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
16540 while (p
< arrow_end
)
16542 Lisp_Object face
, ilisp
;
16544 /* Get the next character. */
16546 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16549 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16550 if (! ASCII_CHAR_P (it
.c
))
16551 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16555 /* Get its face. */
16556 ilisp
= make_number (p
- arrow_string
);
16557 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16558 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16560 /* Compute its width, get its glyphs. */
16561 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16562 SET_TEXT_POS (it
.position
, -1, -1);
16563 PRODUCE_GLYPHS (&it
);
16565 /* If this character doesn't fit any more in the line, we have
16566 to remove some glyphs. */
16567 if (it
.current_x
> it
.last_visible_x
)
16569 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16574 set_buffer_temp (old
);
16575 return it
.glyph_row
;
16579 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16580 glyphs are only inserted for terminal frames since we can't really
16581 win with truncation glyphs when partially visible glyphs are
16582 involved. Which glyphs to insert is determined by
16583 produce_special_glyphs. */
16586 insert_left_trunc_glyphs (struct it
*it
)
16588 struct it truncate_it
;
16589 struct glyph
*from
, *end
, *to
, *toend
;
16591 xassert (!FRAME_WINDOW_P (it
->f
));
16593 /* Get the truncation glyphs. */
16595 truncate_it
.current_x
= 0;
16596 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16597 truncate_it
.glyph_row
= &scratch_glyph_row
;
16598 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16599 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16600 truncate_it
.object
= make_number (0);
16601 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16603 /* Overwrite glyphs from IT with truncation glyphs. */
16604 if (!it
->glyph_row
->reversed_p
)
16606 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16607 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16608 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16609 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16614 /* There may be padding glyphs left over. Overwrite them too. */
16615 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16617 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16623 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16627 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
16628 that back to front. */
16629 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16630 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16631 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16632 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16634 while (from
>= end
&& to
>= toend
)
16636 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
16639 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
16640 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16641 while (from
>= end
&& to
>= toend
)
16646 /* Need to free some room before prepending additional
16648 int move_by
= from
- end
+ 1;
16649 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16650 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16652 for ( ; g
>= g0
; g
--)
16654 while (from
>= end
)
16656 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
16662 /* Compute the pixel height and width of IT->glyph_row.
16664 Most of the time, ascent and height of a display line will be equal
16665 to the max_ascent and max_height values of the display iterator
16666 structure. This is not the case if
16668 1. We hit ZV without displaying anything. In this case, max_ascent
16669 and max_height will be zero.
16671 2. We have some glyphs that don't contribute to the line height.
16672 (The glyph row flag contributes_to_line_height_p is for future
16673 pixmap extensions).
16675 The first case is easily covered by using default values because in
16676 these cases, the line height does not really matter, except that it
16677 must not be zero. */
16680 compute_line_metrics (struct it
*it
)
16682 struct glyph_row
*row
= it
->glyph_row
;
16684 if (FRAME_WINDOW_P (it
->f
))
16686 int i
, min_y
, max_y
;
16688 /* The line may consist of one space only, that was added to
16689 place the cursor on it. If so, the row's height hasn't been
16691 if (row
->height
== 0)
16693 if (it
->max_ascent
+ it
->max_descent
== 0)
16694 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16695 row
->ascent
= it
->max_ascent
;
16696 row
->height
= it
->max_ascent
+ it
->max_descent
;
16697 row
->phys_ascent
= it
->max_phys_ascent
;
16698 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16699 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16702 /* Compute the width of this line. */
16703 row
->pixel_width
= row
->x
;
16704 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16705 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16707 xassert (row
->pixel_width
>= 0);
16708 xassert (row
->ascent
>= 0 && row
->height
> 0);
16710 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16711 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16713 /* If first line's physical ascent is larger than its logical
16714 ascent, use the physical ascent, and make the row taller.
16715 This makes accented characters fully visible. */
16716 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16717 && row
->phys_ascent
> row
->ascent
)
16719 row
->height
+= row
->phys_ascent
- row
->ascent
;
16720 row
->ascent
= row
->phys_ascent
;
16723 /* Compute how much of the line is visible. */
16724 row
->visible_height
= row
->height
;
16726 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16727 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16729 if (row
->y
< min_y
)
16730 row
->visible_height
-= min_y
- row
->y
;
16731 if (row
->y
+ row
->height
> max_y
)
16732 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16736 row
->pixel_width
= row
->used
[TEXT_AREA
];
16737 if (row
->continued_p
)
16738 row
->pixel_width
-= it
->continuation_pixel_width
;
16739 else if (row
->truncated_on_right_p
)
16740 row
->pixel_width
-= it
->truncation_pixel_width
;
16741 row
->ascent
= row
->phys_ascent
= 0;
16742 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16743 row
->extra_line_spacing
= 0;
16746 /* Compute a hash code for this row. */
16750 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16751 for (i
= 0; i
< row
->used
[area
]; ++i
)
16752 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16753 + row
->glyphs
[area
][i
].u
.val
16754 + row
->glyphs
[area
][i
].face_id
16755 + row
->glyphs
[area
][i
].padding_p
16756 + (row
->glyphs
[area
][i
].type
<< 2));
16759 it
->max_ascent
= it
->max_descent
= 0;
16760 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16764 /* Append one space to the glyph row of iterator IT if doing a
16765 window-based redisplay. The space has the same face as
16766 IT->face_id. Value is non-zero if a space was added.
16768 This function is called to make sure that there is always one glyph
16769 at the end of a glyph row that the cursor can be set on under
16770 window-systems. (If there weren't such a glyph we would not know
16771 how wide and tall a box cursor should be displayed).
16773 At the same time this space let's a nicely handle clearing to the
16774 end of the line if the row ends in italic text. */
16777 append_space_for_newline (struct it
*it
, int default_face_p
)
16779 if (FRAME_WINDOW_P (it
->f
))
16781 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16783 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16784 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16786 /* Save some values that must not be changed.
16787 Must save IT->c and IT->len because otherwise
16788 ITERATOR_AT_END_P wouldn't work anymore after
16789 append_space_for_newline has been called. */
16790 enum display_element_type saved_what
= it
->what
;
16791 int saved_c
= it
->c
, saved_len
= it
->len
;
16792 int saved_char_to_display
= it
->char_to_display
;
16793 int saved_x
= it
->current_x
;
16794 int saved_face_id
= it
->face_id
;
16795 struct text_pos saved_pos
;
16796 Lisp_Object saved_object
;
16799 saved_object
= it
->object
;
16800 saved_pos
= it
->position
;
16802 it
->what
= IT_CHARACTER
;
16803 memset (&it
->position
, 0, sizeof it
->position
);
16804 it
->object
= make_number (0);
16805 it
->c
= it
->char_to_display
= ' ';
16808 if (default_face_p
)
16809 it
->face_id
= DEFAULT_FACE_ID
;
16810 else if (it
->face_before_selective_p
)
16811 it
->face_id
= it
->saved_face_id
;
16812 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16813 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16815 PRODUCE_GLYPHS (it
);
16817 it
->override_ascent
= -1;
16818 it
->constrain_row_ascent_descent_p
= 0;
16819 it
->current_x
= saved_x
;
16820 it
->object
= saved_object
;
16821 it
->position
= saved_pos
;
16822 it
->what
= saved_what
;
16823 it
->face_id
= saved_face_id
;
16824 it
->len
= saved_len
;
16826 it
->char_to_display
= saved_char_to_display
;
16835 /* Extend the face of the last glyph in the text area of IT->glyph_row
16836 to the end of the display line. Called from display_line. If the
16837 glyph row is empty, add a space glyph to it so that we know the
16838 face to draw. Set the glyph row flag fill_line_p. If the glyph
16839 row is R2L, prepend a stretch glyph to cover the empty space to the
16840 left of the leftmost glyph. */
16843 extend_face_to_end_of_line (struct it
*it
)
16846 struct frame
*f
= it
->f
;
16848 /* If line is already filled, do nothing. Non window-system frames
16849 get a grace of one more ``pixel'' because their characters are
16850 1-``pixel'' wide, so they hit the equality too early. This grace
16851 is needed only for R2L rows that are not continued, to produce
16852 one extra blank where we could display the cursor. */
16853 if (it
->current_x
>= it
->last_visible_x
16854 + (!FRAME_WINDOW_P (f
)
16855 && it
->glyph_row
->reversed_p
16856 && !it
->glyph_row
->continued_p
))
16859 /* Face extension extends the background and box of IT->face_id
16860 to the end of the line. If the background equals the background
16861 of the frame, we don't have to do anything. */
16862 if (it
->face_before_selective_p
)
16863 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16865 face
= FACE_FROM_ID (f
, it
->face_id
);
16867 if (FRAME_WINDOW_P (f
)
16868 && it
->glyph_row
->displays_text_p
16869 && face
->box
== FACE_NO_BOX
16870 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16872 && !it
->glyph_row
->reversed_p
)
16875 /* Set the glyph row flag indicating that the face of the last glyph
16876 in the text area has to be drawn to the end of the text area. */
16877 it
->glyph_row
->fill_line_p
= 1;
16879 /* If current character of IT is not ASCII, make sure we have the
16880 ASCII face. This will be automatically undone the next time
16881 get_next_display_element returns a multibyte character. Note
16882 that the character will always be single byte in unibyte
16884 if (!ASCII_CHAR_P (it
->c
))
16886 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16889 if (FRAME_WINDOW_P (f
))
16891 /* If the row is empty, add a space with the current face of IT,
16892 so that we know which face to draw. */
16893 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16895 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16896 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16897 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16899 #ifdef HAVE_WINDOW_SYSTEM
16900 if (it
->glyph_row
->reversed_p
)
16902 /* Prepend a stretch glyph to the row, such that the
16903 rightmost glyph will be drawn flushed all the way to the
16904 right margin of the window. The stretch glyph that will
16905 occupy the empty space, if any, to the left of the
16907 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16908 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16909 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16911 int row_width
, stretch_ascent
, stretch_width
;
16912 struct text_pos saved_pos
;
16913 int saved_face_id
, saved_avoid_cursor
;
16915 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16916 row_width
+= g
->pixel_width
;
16917 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
16918 if (stretch_width
> 0)
16921 (((it
->ascent
+ it
->descent
)
16922 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16923 saved_pos
= it
->position
;
16924 memset (&it
->position
, 0, sizeof it
->position
);
16925 saved_avoid_cursor
= it
->avoid_cursor_p
;
16926 it
->avoid_cursor_p
= 1;
16927 saved_face_id
= it
->face_id
;
16928 /* The last row's stretch glyph should get the default
16929 face, to avoid painting the rest of the window with
16930 the region face, if the region ends at ZV. */
16931 if (it
->glyph_row
->ends_at_zv_p
)
16932 it
->face_id
= DEFAULT_FACE_ID
;
16934 it
->face_id
= face
->id
;
16935 append_stretch_glyph (it
, make_number (0), stretch_width
,
16936 it
->ascent
+ it
->descent
, stretch_ascent
);
16937 it
->position
= saved_pos
;
16938 it
->avoid_cursor_p
= saved_avoid_cursor
;
16939 it
->face_id
= saved_face_id
;
16942 #endif /* HAVE_WINDOW_SYSTEM */
16946 /* Save some values that must not be changed. */
16947 int saved_x
= it
->current_x
;
16948 struct text_pos saved_pos
;
16949 Lisp_Object saved_object
;
16950 enum display_element_type saved_what
= it
->what
;
16951 int saved_face_id
= it
->face_id
;
16953 saved_object
= it
->object
;
16954 saved_pos
= it
->position
;
16956 it
->what
= IT_CHARACTER
;
16957 memset (&it
->position
, 0, sizeof it
->position
);
16958 it
->object
= make_number (0);
16959 it
->c
= it
->char_to_display
= ' ';
16961 /* The last row's blank glyphs should get the default face, to
16962 avoid painting the rest of the window with the region face,
16963 if the region ends at ZV. */
16964 if (it
->glyph_row
->ends_at_zv_p
)
16965 it
->face_id
= DEFAULT_FACE_ID
;
16967 it
->face_id
= face
->id
;
16969 PRODUCE_GLYPHS (it
);
16971 while (it
->current_x
<= it
->last_visible_x
)
16972 PRODUCE_GLYPHS (it
);
16974 /* Don't count these blanks really. It would let us insert a left
16975 truncation glyph below and make us set the cursor on them, maybe. */
16976 it
->current_x
= saved_x
;
16977 it
->object
= saved_object
;
16978 it
->position
= saved_pos
;
16979 it
->what
= saved_what
;
16980 it
->face_id
= saved_face_id
;
16985 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16986 trailing whitespace. */
16989 trailing_whitespace_p (EMACS_INT charpos
)
16991 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
16994 while (bytepos
< ZV_BYTE
16995 && (c
= FETCH_CHAR (bytepos
),
16996 c
== ' ' || c
== '\t'))
16999 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17001 if (bytepos
!= PT_BYTE
)
17008 /* Highlight trailing whitespace, if any, in ROW. */
17011 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17013 int used
= row
->used
[TEXT_AREA
];
17017 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17018 struct glyph
*glyph
= start
+ used
- 1;
17020 if (row
->reversed_p
)
17022 /* Right-to-left rows need to be processed in the opposite
17023 direction, so swap the edge pointers. */
17025 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17028 /* Skip over glyphs inserted to display the cursor at the
17029 end of a line, for extending the face of the last glyph
17030 to the end of the line on terminals, and for truncation
17031 and continuation glyphs. */
17032 if (!row
->reversed_p
)
17034 while (glyph
>= start
17035 && glyph
->type
== CHAR_GLYPH
17036 && INTEGERP (glyph
->object
))
17041 while (glyph
<= start
17042 && glyph
->type
== CHAR_GLYPH
17043 && INTEGERP (glyph
->object
))
17047 /* If last glyph is a space or stretch, and it's trailing
17048 whitespace, set the face of all trailing whitespace glyphs in
17049 IT->glyph_row to `trailing-whitespace'. */
17050 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17051 && BUFFERP (glyph
->object
)
17052 && (glyph
->type
== STRETCH_GLYPH
17053 || (glyph
->type
== CHAR_GLYPH
17054 && glyph
->u
.ch
== ' '))
17055 && trailing_whitespace_p (glyph
->charpos
))
17057 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17061 if (!row
->reversed_p
)
17063 while (glyph
>= start
17064 && BUFFERP (glyph
->object
)
17065 && (glyph
->type
== STRETCH_GLYPH
17066 || (glyph
->type
== CHAR_GLYPH
17067 && glyph
->u
.ch
== ' ')))
17068 (glyph
--)->face_id
= face_id
;
17072 while (glyph
<= start
17073 && BUFFERP (glyph
->object
)
17074 && (glyph
->type
== STRETCH_GLYPH
17075 || (glyph
->type
== CHAR_GLYPH
17076 && glyph
->u
.ch
== ' ')))
17077 (glyph
++)->face_id
= face_id
;
17084 /* Value is non-zero if glyph row ROW should be
17085 used to hold the cursor. */
17088 cursor_row_p (struct glyph_row
*row
)
17092 if (PT
== CHARPOS (row
->end
.pos
))
17094 /* Suppose the row ends on a string.
17095 Unless the row is continued, that means it ends on a newline
17096 in the string. If it's anything other than a display string
17097 (e.g. a before-string from an overlay), we don't want the
17098 cursor there. (This heuristic seems to give the optimal
17099 behavior for the various types of multi-line strings.) */
17100 if (CHARPOS (row
->end
.string_pos
) >= 0)
17102 if (row
->continued_p
)
17106 /* Check for `display' property. */
17107 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17108 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17109 struct glyph
*glyph
;
17112 for (glyph
= end
; glyph
>= beg
; --glyph
)
17113 if (STRINGP (glyph
->object
))
17116 = Fget_char_property (make_number (PT
),
17120 && display_prop_string_p (prop
, glyph
->object
));
17125 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17127 /* If the row ends in middle of a real character,
17128 and the line is continued, we want the cursor here.
17129 That's because CHARPOS (ROW->end.pos) would equal
17130 PT if PT is before the character. */
17131 if (!row
->ends_in_ellipsis_p
)
17132 result
= row
->continued_p
;
17134 /* If the row ends in an ellipsis, then
17135 CHARPOS (ROW->end.pos) will equal point after the
17136 invisible text. We want that position to be displayed
17137 after the ellipsis. */
17140 /* If the row ends at ZV, display the cursor at the end of that
17141 row instead of at the start of the row below. */
17142 else if (row
->ends_at_zv_p
)
17153 /* Push the display property PROP so that it will be rendered at the
17154 current position in IT. Return 1 if PROP was successfully pushed,
17158 push_display_prop (struct it
*it
, Lisp_Object prop
)
17162 if (STRINGP (prop
))
17164 if (SCHARS (prop
) == 0)
17171 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17172 it
->current
.overlay_string_index
= -1;
17173 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17174 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17175 it
->method
= GET_FROM_STRING
;
17176 it
->stop_charpos
= 0;
17178 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17180 it
->method
= GET_FROM_STRETCH
;
17183 #ifdef HAVE_WINDOW_SYSTEM
17184 else if (IMAGEP (prop
))
17186 it
->what
= IT_IMAGE
;
17187 it
->image_id
= lookup_image (it
->f
, prop
);
17188 it
->method
= GET_FROM_IMAGE
;
17190 #endif /* HAVE_WINDOW_SYSTEM */
17193 pop_it (it
); /* bogus display property, give up */
17200 /* Return the character-property PROP at the current position in IT. */
17203 get_it_property (struct it
*it
, Lisp_Object prop
)
17205 Lisp_Object position
;
17207 if (STRINGP (it
->object
))
17208 position
= make_number (IT_STRING_CHARPOS (*it
));
17209 else if (BUFFERP (it
->object
))
17210 position
= make_number (IT_CHARPOS (*it
));
17214 return Fget_char_property (position
, prop
, it
->object
);
17217 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17220 handle_line_prefix (struct it
*it
)
17222 Lisp_Object prefix
;
17223 if (it
->continuation_lines_width
> 0)
17225 prefix
= get_it_property (it
, Qwrap_prefix
);
17227 prefix
= Vwrap_prefix
;
17231 prefix
= get_it_property (it
, Qline_prefix
);
17233 prefix
= Vline_prefix
;
17235 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17237 /* If the prefix is wider than the window, and we try to wrap
17238 it, it would acquire its own wrap prefix, and so on till the
17239 iterator stack overflows. So, don't wrap the prefix. */
17240 it
->line_wrap
= TRUNCATE
;
17241 it
->avoid_cursor_p
= 1;
17247 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17248 only for R2L lines from display_line, when it decides that too many
17249 glyphs were produced by PRODUCE_GLYPHS, and the line needs to be
17252 unproduce_glyphs (struct it
*it
, int n
)
17254 struct glyph
*glyph
, *end
;
17256 xassert (it
->glyph_row
);
17257 xassert (it
->glyph_row
->reversed_p
);
17258 xassert (it
->area
== TEXT_AREA
);
17259 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17261 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17262 n
= it
->glyph_row
->used
[TEXT_AREA
];
17263 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17264 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17265 for ( ; glyph
< end
; glyph
++)
17266 glyph
[-n
] = *glyph
;
17269 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17270 and ROW->maxpos. */
17272 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17273 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17274 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17276 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17277 lines' rows is implemented for bidi-reordered rows. */
17279 /* ROW->minpos is the value of min_pos, the minimal buffer position
17282 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17284 /* We didn't find _any_ valid buffer positions in any of the
17285 glyphs, so we must trust the iterator's computed positions. */
17286 row
->minpos
= row
->start
.pos
;
17289 max_pos
= CHARPOS (it
->current
.pos
);
17290 max_bpos
= BYTEPOS (it
->current
.pos
);
17293 /* Here are the various use-cases for ending the row, and the
17294 corresponding values for ROW->maxpos:
17296 Line ends in a newline from buffer eol_pos + 1
17297 Line is continued from buffer max_pos + 1
17298 Line is truncated on right it->current.pos
17299 Line ends in a newline from string max_pos
17300 Line is continued from string max_pos
17301 Line is continued from display vector max_pos
17302 Line is entirely from a string min_pos == max_pos
17303 Line is entirely from a display vector min_pos == max_pos
17304 Line that ends at ZV ZV
17306 If you discover other use-cases, please add them here as
17308 if (row
->ends_at_zv_p
)
17309 row
->maxpos
= it
->current
.pos
;
17310 else if (row
->used
[TEXT_AREA
])
17312 if (row
->ends_in_newline_from_string_p
)
17313 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17314 else if (CHARPOS (it
->eol_pos
) > 0)
17315 SET_TEXT_POS (row
->maxpos
,
17316 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17317 else if (row
->continued_p
)
17319 /* If max_pos is different from IT's current position, it
17320 means IT->method does not belong to the display element
17321 at max_pos. However, it also means that the display
17322 element at max_pos was displayed in its entirety on this
17323 line, which is equivalent to saying that the next line
17324 starts at the next buffer position. */
17325 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17326 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17329 INC_BOTH (max_pos
, max_bpos
);
17330 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17333 else if (row
->truncated_on_right_p
)
17334 /* display_line already called reseat_at_next_visible_line_start,
17335 which puts the iterator at the beginning of the next line, in
17336 the logical order. */
17337 row
->maxpos
= it
->current
.pos
;
17338 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17339 /* A line that is entirely from a string/image/stretch... */
17340 row
->maxpos
= row
->minpos
;
17345 row
->maxpos
= it
->current
.pos
;
17348 /* Construct the glyph row IT->glyph_row in the desired matrix of
17349 IT->w from text at the current position of IT. See dispextern.h
17350 for an overview of struct it. Value is non-zero if
17351 IT->glyph_row displays text, as opposed to a line displaying ZV
17355 display_line (struct it
*it
)
17357 struct glyph_row
*row
= it
->glyph_row
;
17358 Lisp_Object overlay_arrow_string
;
17360 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17361 int wrap_row_used
= -1;
17362 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17363 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17364 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17365 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17366 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17368 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17369 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
17371 /* We always start displaying at hpos zero even if hscrolled. */
17372 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17374 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17375 >= it
->w
->desired_matrix
->nrows
)
17377 it
->w
->nrows_scale_factor
++;
17378 fonts_changed_p
= 1;
17382 /* Is IT->w showing the region? */
17383 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17385 /* Clear the result glyph row and enable it. */
17386 prepare_desired_row (row
);
17388 row
->y
= it
->current_y
;
17389 row
->start
= it
->start
;
17390 row
->continuation_lines_width
= it
->continuation_lines_width
;
17391 row
->displays_text_p
= 1;
17392 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17393 it
->starts_in_middle_of_char_p
= 0;
17395 /* Arrange the overlays nicely for our purposes. Usually, we call
17396 display_line on only one line at a time, in which case this
17397 can't really hurt too much, or we call it on lines which appear
17398 one after another in the buffer, in which case all calls to
17399 recenter_overlay_lists but the first will be pretty cheap. */
17400 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17402 /* Move over display elements that are not visible because we are
17403 hscrolled. This may stop at an x-position < IT->first_visible_x
17404 if the first glyph is partially visible or if we hit a line end. */
17405 if (it
->current_x
< it
->first_visible_x
)
17407 this_line_min_pos
= row
->start
.pos
;
17408 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17409 MOVE_TO_POS
| MOVE_TO_X
);
17410 /* Record the smallest positions seen while we moved over
17411 display elements that are not visible. This is needed by
17412 redisplay_internal for optimizing the case where the cursor
17413 stays inside the same line. The rest of this function only
17414 considers positions that are actually displayed, so
17415 RECORD_MAX_MIN_POS will not otherwise record positions that
17416 are hscrolled to the left of the left edge of the window. */
17417 min_pos
= CHARPOS (this_line_min_pos
);
17418 min_bpos
= BYTEPOS (this_line_min_pos
);
17422 /* We only do this when not calling `move_it_in_display_line_to'
17423 above, because move_it_in_display_line_to calls
17424 handle_line_prefix itself. */
17425 handle_line_prefix (it
);
17428 /* Get the initial row height. This is either the height of the
17429 text hscrolled, if there is any, or zero. */
17430 row
->ascent
= it
->max_ascent
;
17431 row
->height
= it
->max_ascent
+ it
->max_descent
;
17432 row
->phys_ascent
= it
->max_phys_ascent
;
17433 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17434 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17436 /* Utility macro to record max and min buffer positions seen until now. */
17437 #define RECORD_MAX_MIN_POS(IT) \
17440 if (IT_CHARPOS (*(IT)) < min_pos) \
17442 min_pos = IT_CHARPOS (*(IT)); \
17443 min_bpos = IT_BYTEPOS (*(IT)); \
17445 if (IT_CHARPOS (*(IT)) > max_pos) \
17447 max_pos = IT_CHARPOS (*(IT)); \
17448 max_bpos = IT_BYTEPOS (*(IT)); \
17453 /* Loop generating characters. The loop is left with IT on the next
17454 character to display. */
17457 int n_glyphs_before
, hpos_before
, x_before
;
17459 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17461 /* Retrieve the next thing to display. Value is zero if end of
17463 if (!get_next_display_element (it
))
17465 /* Maybe add a space at the end of this line that is used to
17466 display the cursor there under X. Set the charpos of the
17467 first glyph of blank lines not corresponding to any text
17469 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17470 row
->exact_window_width_line_p
= 1;
17471 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17472 || row
->used
[TEXT_AREA
] == 0)
17474 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17475 row
->displays_text_p
= 0;
17477 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
17478 && (!MINI_WINDOW_P (it
->w
)
17479 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17480 row
->indicate_empty_line_p
= 1;
17483 it
->continuation_lines_width
= 0;
17484 row
->ends_at_zv_p
= 1;
17485 /* A row that displays right-to-left text must always have
17486 its last face extended all the way to the end of line,
17487 even if this row ends in ZV, because we still write to
17488 the screen left to right. */
17489 if (row
->reversed_p
)
17490 extend_face_to_end_of_line (it
);
17494 /* Now, get the metrics of what we want to display. This also
17495 generates glyphs in `row' (which is IT->glyph_row). */
17496 n_glyphs_before
= row
->used
[TEXT_AREA
];
17499 /* Remember the line height so far in case the next element doesn't
17500 fit on the line. */
17501 if (it
->line_wrap
!= TRUNCATE
)
17503 ascent
= it
->max_ascent
;
17504 descent
= it
->max_descent
;
17505 phys_ascent
= it
->max_phys_ascent
;
17506 phys_descent
= it
->max_phys_descent
;
17508 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17510 if (IT_DISPLAYING_WHITESPACE (it
))
17516 wrap_row_used
= row
->used
[TEXT_AREA
];
17517 wrap_row_ascent
= row
->ascent
;
17518 wrap_row_height
= row
->height
;
17519 wrap_row_phys_ascent
= row
->phys_ascent
;
17520 wrap_row_phys_height
= row
->phys_height
;
17521 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17522 wrap_row_min_pos
= min_pos
;
17523 wrap_row_min_bpos
= min_bpos
;
17524 wrap_row_max_pos
= max_pos
;
17525 wrap_row_max_bpos
= max_bpos
;
17531 PRODUCE_GLYPHS (it
);
17533 /* If this display element was in marginal areas, continue with
17535 if (it
->area
!= TEXT_AREA
)
17537 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17538 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17539 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17540 row
->phys_height
= max (row
->phys_height
,
17541 it
->max_phys_ascent
+ it
->max_phys_descent
);
17542 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17543 it
->max_extra_line_spacing
);
17544 set_iterator_to_next (it
, 1);
17548 /* Does the display element fit on the line? If we truncate
17549 lines, we should draw past the right edge of the window. If
17550 we don't truncate, we want to stop so that we can display the
17551 continuation glyph before the right margin. If lines are
17552 continued, there are two possible strategies for characters
17553 resulting in more than 1 glyph (e.g. tabs): Display as many
17554 glyphs as possible in this line and leave the rest for the
17555 continuation line, or display the whole element in the next
17556 line. Original redisplay did the former, so we do it also. */
17557 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17558 hpos_before
= it
->hpos
;
17561 if (/* Not a newline. */
17563 /* Glyphs produced fit entirely in the line. */
17564 && it
->current_x
< it
->last_visible_x
)
17566 it
->hpos
+= nglyphs
;
17567 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17568 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17569 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17570 row
->phys_height
= max (row
->phys_height
,
17571 it
->max_phys_ascent
+ it
->max_phys_descent
);
17572 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17573 it
->max_extra_line_spacing
);
17574 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17575 row
->x
= x
- it
->first_visible_x
;
17576 /* Record the maximum and minimum buffer positions seen so
17577 far in glyphs that will be displayed by this row. */
17579 RECORD_MAX_MIN_POS (it
);
17584 struct glyph
*glyph
;
17586 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17588 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17589 new_x
= x
+ glyph
->pixel_width
;
17591 if (/* Lines are continued. */
17592 it
->line_wrap
!= TRUNCATE
17593 && (/* Glyph doesn't fit on the line. */
17594 new_x
> it
->last_visible_x
17595 /* Or it fits exactly on a window system frame. */
17596 || (new_x
== it
->last_visible_x
17597 && FRAME_WINDOW_P (it
->f
))))
17599 /* End of a continued line. */
17602 || (new_x
== it
->last_visible_x
17603 && FRAME_WINDOW_P (it
->f
)))
17605 /* Current glyph is the only one on the line or
17606 fits exactly on the line. We must continue
17607 the line because we can't draw the cursor
17608 after the glyph. */
17609 row
->continued_p
= 1;
17610 it
->current_x
= new_x
;
17611 it
->continuation_lines_width
+= new_x
;
17613 /* Record the maximum and minimum buffer
17614 positions seen so far in glyphs that will be
17615 displayed by this row. */
17617 RECORD_MAX_MIN_POS (it
);
17618 if (i
== nglyphs
- 1)
17620 /* If line-wrap is on, check if a previous
17621 wrap point was found. */
17622 if (wrap_row_used
> 0
17623 /* Even if there is a previous wrap
17624 point, continue the line here as
17625 usual, if (i) the previous character
17626 was a space or tab AND (ii) the
17627 current character is not. */
17629 || IT_DISPLAYING_WHITESPACE (it
)))
17632 set_iterator_to_next (it
, 1);
17633 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17635 if (!get_next_display_element (it
))
17637 row
->exact_window_width_line_p
= 1;
17638 it
->continuation_lines_width
= 0;
17639 row
->continued_p
= 0;
17640 row
->ends_at_zv_p
= 1;
17642 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17644 row
->continued_p
= 0;
17645 row
->exact_window_width_line_p
= 1;
17650 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17651 && !FRAME_WINDOW_P (it
->f
))
17653 /* A padding glyph that doesn't fit on this line.
17654 This means the whole character doesn't fit
17656 if (row
->reversed_p
)
17657 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17658 - n_glyphs_before
);
17659 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17661 /* Fill the rest of the row with continuation
17662 glyphs like in 20.x. */
17663 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17664 < row
->glyphs
[1 + TEXT_AREA
])
17665 produce_special_glyphs (it
, IT_CONTINUATION
);
17667 row
->continued_p
= 1;
17668 it
->current_x
= x_before
;
17669 it
->continuation_lines_width
+= x_before
;
17671 /* Restore the height to what it was before the
17672 element not fitting on the line. */
17673 it
->max_ascent
= ascent
;
17674 it
->max_descent
= descent
;
17675 it
->max_phys_ascent
= phys_ascent
;
17676 it
->max_phys_descent
= phys_descent
;
17678 else if (wrap_row_used
> 0)
17681 if (row
->reversed_p
)
17682 unproduce_glyphs (it
,
17683 row
->used
[TEXT_AREA
] - wrap_row_used
);
17685 it
->continuation_lines_width
+= wrap_x
;
17686 row
->used
[TEXT_AREA
] = wrap_row_used
;
17687 row
->ascent
= wrap_row_ascent
;
17688 row
->height
= wrap_row_height
;
17689 row
->phys_ascent
= wrap_row_phys_ascent
;
17690 row
->phys_height
= wrap_row_phys_height
;
17691 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17692 min_pos
= wrap_row_min_pos
;
17693 min_bpos
= wrap_row_min_bpos
;
17694 max_pos
= wrap_row_max_pos
;
17695 max_bpos
= wrap_row_max_bpos
;
17696 row
->continued_p
= 1;
17697 row
->ends_at_zv_p
= 0;
17698 row
->exact_window_width_line_p
= 0;
17699 it
->continuation_lines_width
+= x
;
17701 /* Make sure that a non-default face is extended
17702 up to the right margin of the window. */
17703 extend_face_to_end_of_line (it
);
17705 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17707 /* A TAB that extends past the right edge of the
17708 window. This produces a single glyph on
17709 window system frames. We leave the glyph in
17710 this row and let it fill the row, but don't
17711 consume the TAB. */
17712 it
->continuation_lines_width
+= it
->last_visible_x
;
17713 row
->ends_in_middle_of_char_p
= 1;
17714 row
->continued_p
= 1;
17715 glyph
->pixel_width
= it
->last_visible_x
- x
;
17716 it
->starts_in_middle_of_char_p
= 1;
17720 /* Something other than a TAB that draws past
17721 the right edge of the window. Restore
17722 positions to values before the element. */
17723 if (row
->reversed_p
)
17724 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17725 - (n_glyphs_before
+ i
));
17726 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17728 /* Display continuation glyphs. */
17729 if (!FRAME_WINDOW_P (it
->f
))
17730 produce_special_glyphs (it
, IT_CONTINUATION
);
17731 row
->continued_p
= 1;
17733 it
->current_x
= x_before
;
17734 it
->continuation_lines_width
+= x
;
17735 extend_face_to_end_of_line (it
);
17737 if (nglyphs
> 1 && i
> 0)
17739 row
->ends_in_middle_of_char_p
= 1;
17740 it
->starts_in_middle_of_char_p
= 1;
17743 /* Restore the height to what it was before the
17744 element not fitting on the line. */
17745 it
->max_ascent
= ascent
;
17746 it
->max_descent
= descent
;
17747 it
->max_phys_ascent
= phys_ascent
;
17748 it
->max_phys_descent
= phys_descent
;
17753 else if (new_x
> it
->first_visible_x
)
17755 /* Increment number of glyphs actually displayed. */
17758 /* Record the maximum and minimum buffer positions
17759 seen so far in glyphs that will be displayed by
17762 RECORD_MAX_MIN_POS (it
);
17764 if (x
< it
->first_visible_x
)
17765 /* Glyph is partially visible, i.e. row starts at
17766 negative X position. */
17767 row
->x
= x
- it
->first_visible_x
;
17771 /* Glyph is completely off the left margin of the
17772 window. This should not happen because of the
17773 move_it_in_display_line at the start of this
17774 function, unless the text display area of the
17775 window is empty. */
17776 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17780 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17781 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17782 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17783 row
->phys_height
= max (row
->phys_height
,
17784 it
->max_phys_ascent
+ it
->max_phys_descent
);
17785 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17786 it
->max_extra_line_spacing
);
17788 /* End of this display line if row is continued. */
17789 if (row
->continued_p
|| row
->ends_at_zv_p
)
17794 /* Is this a line end? If yes, we're also done, after making
17795 sure that a non-default face is extended up to the right
17796 margin of the window. */
17797 if (ITERATOR_AT_END_OF_LINE_P (it
))
17799 int used_before
= row
->used
[TEXT_AREA
];
17801 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17803 /* Add a space at the end of the line that is used to
17804 display the cursor there. */
17805 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17806 append_space_for_newline (it
, 0);
17808 /* Extend the face to the end of the line. */
17809 extend_face_to_end_of_line (it
);
17811 /* Make sure we have the position. */
17812 if (used_before
== 0)
17813 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17815 /* Record the position of the newline, for use in
17817 it
->eol_pos
= it
->current
.pos
;
17819 /* Consume the line end. This skips over invisible lines. */
17820 set_iterator_to_next (it
, 1);
17821 it
->continuation_lines_width
= 0;
17825 /* Proceed with next display element. Note that this skips
17826 over lines invisible because of selective display. */
17827 set_iterator_to_next (it
, 1);
17829 /* If we truncate lines, we are done when the last displayed
17830 glyphs reach past the right margin of the window. */
17831 if (it
->line_wrap
== TRUNCATE
17832 && (FRAME_WINDOW_P (it
->f
)
17833 ? (it
->current_x
>= it
->last_visible_x
)
17834 : (it
->current_x
> it
->last_visible_x
)))
17836 /* Maybe add truncation glyphs. */
17837 if (!FRAME_WINDOW_P (it
->f
))
17841 if (!row
->reversed_p
)
17843 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17844 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17849 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
17850 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17852 /* Remove any padding glyphs at the front of ROW, to
17853 make room for the truncation glyphs we will be
17854 adding below. The loop below always inserts at
17855 least one truncation glyph, so also remove the
17856 last glyph added to ROW. */
17857 unproduce_glyphs (it
, i
+ 1);
17858 /* Adjust i for the loop below. */
17859 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
17862 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17864 row
->used
[TEXT_AREA
] = i
;
17865 produce_special_glyphs (it
, IT_TRUNCATION
);
17868 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17870 /* Don't truncate if we can overflow newline into fringe. */
17871 if (!get_next_display_element (it
))
17873 it
->continuation_lines_width
= 0;
17874 row
->ends_at_zv_p
= 1;
17875 row
->exact_window_width_line_p
= 1;
17878 if (ITERATOR_AT_END_OF_LINE_P (it
))
17880 row
->exact_window_width_line_p
= 1;
17881 goto at_end_of_line
;
17885 row
->truncated_on_right_p
= 1;
17886 it
->continuation_lines_width
= 0;
17887 reseat_at_next_visible_line_start (it
, 0);
17888 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17889 it
->hpos
= hpos_before
;
17890 it
->current_x
= x_before
;
17895 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17896 at the left window margin. */
17897 if (it
->first_visible_x
17898 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
17900 if (!FRAME_WINDOW_P (it
->f
))
17901 insert_left_trunc_glyphs (it
);
17902 row
->truncated_on_left_p
= 1;
17905 /* Remember the position at which this line ends.
17907 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
17908 cannot be before the call to find_row_edges below, since that is
17909 where these positions are determined. */
17910 row
->end
= it
->current
;
17913 row
->minpos
= row
->start
.pos
;
17914 row
->maxpos
= row
->end
.pos
;
17918 /* ROW->minpos and ROW->maxpos must be the smallest and
17919 `1 + the largest' buffer positions in ROW. But if ROW was
17920 bidi-reordered, these two positions can be anywhere in the
17921 row, so we must determine them now. */
17922 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
17925 /* If the start of this line is the overlay arrow-position, then
17926 mark this glyph row as the one containing the overlay arrow.
17927 This is clearly a mess with variable size fonts. It would be
17928 better to let it be displayed like cursors under X. */
17929 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17930 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17931 !NILP (overlay_arrow_string
)))
17933 /* Overlay arrow in window redisplay is a fringe bitmap. */
17934 if (STRINGP (overlay_arrow_string
))
17936 struct glyph_row
*arrow_row
17937 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17938 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17939 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17940 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17941 struct glyph
*p2
, *end
;
17943 /* Copy the arrow glyphs. */
17944 while (glyph
< arrow_end
)
17947 /* Throw away padding glyphs. */
17949 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17950 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17956 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17961 xassert (INTEGERP (overlay_arrow_string
));
17962 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17964 overlay_arrow_seen
= 1;
17967 /* Compute pixel dimensions of this line. */
17968 compute_line_metrics (it
);
17970 /* Record whether this row ends inside an ellipsis. */
17971 row
->ends_in_ellipsis_p
17972 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17973 && it
->ellipsis_p
);
17975 /* Save fringe bitmaps in this row. */
17976 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17977 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17978 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17979 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17981 it
->left_user_fringe_bitmap
= 0;
17982 it
->left_user_fringe_face_id
= 0;
17983 it
->right_user_fringe_bitmap
= 0;
17984 it
->right_user_fringe_face_id
= 0;
17986 /* Maybe set the cursor. */
17987 cvpos
= it
->w
->cursor
.vpos
;
17989 /* In bidi-reordered rows, keep checking for proper cursor
17990 position even if one has been found already, because buffer
17991 positions in such rows change non-linearly with ROW->VPOS,
17992 when a line is continued. One exception: when we are at ZV,
17993 display cursor on the first suitable glyph row, since all
17994 the empty rows after that also have their position set to ZV. */
17995 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17996 lines' rows is implemented for bidi-reordered rows. */
17998 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
17999 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18000 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18001 && cursor_row_p (row
))
18002 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18004 /* Highlight trailing whitespace. */
18005 if (!NILP (Vshow_trailing_whitespace
))
18006 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18008 /* Prepare for the next line. This line starts horizontally at (X
18009 HPOS) = (0 0). Vertical positions are incremented. As a
18010 convenience for the caller, IT->glyph_row is set to the next
18012 it
->current_x
= it
->hpos
= 0;
18013 it
->current_y
+= row
->height
;
18014 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18017 /* The next row should by default use the same value of the
18018 reversed_p flag as this one. set_iterator_to_next decides when
18019 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18020 the flag accordingly. */
18021 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18022 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18023 it
->start
= row
->end
;
18024 return row
->displays_text_p
;
18026 #undef RECORD_MAX_MIN_POS
18029 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18030 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18031 doc
: /* Return paragraph direction at point in BUFFER.
18032 Value is either `left-to-right' or `right-to-left'.
18033 If BUFFER is omitted or nil, it defaults to the current buffer.
18035 Paragraph direction determines how the text in the paragraph is displayed.
18036 In left-to-right paragraphs, text begins at the left margin of the window
18037 and the reading direction is generally left to right. In right-to-left
18038 paragraphs, text begins at the right margin and is read from right to left.
18040 See also `bidi-paragraph-direction'. */)
18041 (Lisp_Object buffer
)
18043 struct buffer
*buf
= current_buffer
;
18044 struct buffer
*old
= buf
;
18046 if (! NILP (buffer
))
18048 CHECK_BUFFER (buffer
);
18049 buf
= XBUFFER (buffer
);
18052 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18053 return Qleft_to_right
;
18054 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18055 return BVAR (buf
, bidi_paragraph_direction
);
18058 /* Determine the direction from buffer text. We could try to
18059 use current_matrix if it is up to date, but this seems fast
18060 enough as it is. */
18061 struct bidi_it itb
;
18062 EMACS_INT pos
= BUF_PT (buf
);
18063 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18066 set_buffer_temp (buf
);
18067 /* bidi_paragraph_init finds the base direction of the paragraph
18068 by searching forward from paragraph start. We need the base
18069 direction of the current or _previous_ paragraph, so we need
18070 to make sure we are within that paragraph. To that end, find
18071 the previous non-empty line. */
18072 if (pos
>= ZV
&& pos
> BEGV
)
18075 bytepos
= CHAR_TO_BYTE (pos
);
18077 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18078 || c
== ' ' || c
== '\t' || c
== '\f')
18080 if (bytepos
<= BEGV_BYTE
)
18085 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18088 itb
.bytepos
= bytepos
;
18090 itb
.separator_limit
= -1;
18091 itb
.paragraph_dir
= NEUTRAL_DIR
;
18093 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18094 set_buffer_temp (old
);
18095 switch (itb
.paragraph_dir
)
18098 return Qleft_to_right
;
18101 return Qright_to_left
;
18111 /***********************************************************************
18113 ***********************************************************************/
18115 /* Redisplay the menu bar in the frame for window W.
18117 The menu bar of X frames that don't have X toolkit support is
18118 displayed in a special window W->frame->menu_bar_window.
18120 The menu bar of terminal frames is treated specially as far as
18121 glyph matrices are concerned. Menu bar lines are not part of
18122 windows, so the update is done directly on the frame matrix rows
18123 for the menu bar. */
18126 display_menu_bar (struct window
*w
)
18128 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18133 /* Don't do all this for graphical frames. */
18135 if (FRAME_W32_P (f
))
18138 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18144 if (FRAME_NS_P (f
))
18146 #endif /* HAVE_NS */
18148 #ifdef USE_X_TOOLKIT
18149 xassert (!FRAME_WINDOW_P (f
));
18150 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18151 it
.first_visible_x
= 0;
18152 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18153 #else /* not USE_X_TOOLKIT */
18154 if (FRAME_WINDOW_P (f
))
18156 /* Menu bar lines are displayed in the desired matrix of the
18157 dummy window menu_bar_window. */
18158 struct window
*menu_w
;
18159 xassert (WINDOWP (f
->menu_bar_window
));
18160 menu_w
= XWINDOW (f
->menu_bar_window
);
18161 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18163 it
.first_visible_x
= 0;
18164 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18168 /* This is a TTY frame, i.e. character hpos/vpos are used as
18170 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18172 it
.first_visible_x
= 0;
18173 it
.last_visible_x
= FRAME_COLS (f
);
18175 #endif /* not USE_X_TOOLKIT */
18177 if (! mode_line_inverse_video
)
18178 /* Force the menu-bar to be displayed in the default face. */
18179 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18181 /* Clear all rows of the menu bar. */
18182 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18184 struct glyph_row
*row
= it
.glyph_row
+ i
;
18185 clear_glyph_row (row
);
18186 row
->enabled_p
= 1;
18187 row
->full_width_p
= 1;
18190 /* Display all items of the menu bar. */
18191 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18192 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18194 Lisp_Object string
;
18196 /* Stop at nil string. */
18197 string
= AREF (items
, i
+ 1);
18201 /* Remember where item was displayed. */
18202 ASET (items
, i
+ 3, make_number (it
.hpos
));
18204 /* Display the item, pad with one space. */
18205 if (it
.current_x
< it
.last_visible_x
)
18206 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18207 SCHARS (string
) + 1, 0, 0, -1);
18210 /* Fill out the line with spaces. */
18211 if (it
.current_x
< it
.last_visible_x
)
18212 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18214 /* Compute the total height of the lines. */
18215 compute_line_metrics (&it
);
18220 /***********************************************************************
18222 ***********************************************************************/
18224 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18225 FORCE is non-zero, redisplay mode lines unconditionally.
18226 Otherwise, redisplay only mode lines that are garbaged. Value is
18227 the number of windows whose mode lines were redisplayed. */
18230 redisplay_mode_lines (Lisp_Object window
, int force
)
18234 while (!NILP (window
))
18236 struct window
*w
= XWINDOW (window
);
18238 if (WINDOWP (w
->hchild
))
18239 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18240 else if (WINDOWP (w
->vchild
))
18241 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18243 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18244 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18246 struct text_pos lpoint
;
18247 struct buffer
*old
= current_buffer
;
18249 /* Set the window's buffer for the mode line display. */
18250 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18251 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18253 /* Point refers normally to the selected window. For any
18254 other window, set up appropriate value. */
18255 if (!EQ (window
, selected_window
))
18257 struct text_pos pt
;
18259 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18260 if (CHARPOS (pt
) < BEGV
)
18261 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18262 else if (CHARPOS (pt
) > (ZV
- 1))
18263 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18265 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18268 /* Display mode lines. */
18269 clear_glyph_matrix (w
->desired_matrix
);
18270 if (display_mode_lines (w
))
18273 w
->must_be_updated_p
= 1;
18276 /* Restore old settings. */
18277 set_buffer_internal_1 (old
);
18278 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18288 /* Display the mode and/or header line of window W. Value is the
18289 sum number of mode lines and header lines displayed. */
18292 display_mode_lines (struct window
*w
)
18294 Lisp_Object old_selected_window
, old_selected_frame
;
18297 old_selected_frame
= selected_frame
;
18298 selected_frame
= w
->frame
;
18299 old_selected_window
= selected_window
;
18300 XSETWINDOW (selected_window
, w
);
18302 /* These will be set while the mode line specs are processed. */
18303 line_number_displayed
= 0;
18304 w
->column_number_displayed
= Qnil
;
18306 if (WINDOW_WANTS_MODELINE_P (w
))
18308 struct window
*sel_w
= XWINDOW (old_selected_window
);
18310 /* Select mode line face based on the real selected window. */
18311 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18312 BVAR (current_buffer
, mode_line_format
));
18316 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18318 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18319 BVAR (current_buffer
, header_line_format
));
18323 selected_frame
= old_selected_frame
;
18324 selected_window
= old_selected_window
;
18329 /* Display mode or header line of window W. FACE_ID specifies which
18330 line to display; it is either MODE_LINE_FACE_ID or
18331 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18332 display. Value is the pixel height of the mode/header line
18336 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18340 int count
= SPECPDL_INDEX ();
18342 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18343 /* Don't extend on a previously drawn mode-line.
18344 This may happen if called from pos_visible_p. */
18345 it
.glyph_row
->enabled_p
= 0;
18346 prepare_desired_row (it
.glyph_row
);
18348 it
.glyph_row
->mode_line_p
= 1;
18350 if (! mode_line_inverse_video
)
18351 /* Force the mode-line to be displayed in the default face. */
18352 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18354 record_unwind_protect (unwind_format_mode_line
,
18355 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18357 mode_line_target
= MODE_LINE_DISPLAY
;
18359 /* Temporarily make frame's keyboard the current kboard so that
18360 kboard-local variables in the mode_line_format will get the right
18362 push_kboard (FRAME_KBOARD (it
.f
));
18363 record_unwind_save_match_data ();
18364 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18367 unbind_to (count
, Qnil
);
18369 /* Fill up with spaces. */
18370 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18372 compute_line_metrics (&it
);
18373 it
.glyph_row
->full_width_p
= 1;
18374 it
.glyph_row
->continued_p
= 0;
18375 it
.glyph_row
->truncated_on_left_p
= 0;
18376 it
.glyph_row
->truncated_on_right_p
= 0;
18378 /* Make a 3D mode-line have a shadow at its right end. */
18379 face
= FACE_FROM_ID (it
.f
, face_id
);
18380 extend_face_to_end_of_line (&it
);
18381 if (face
->box
!= FACE_NO_BOX
)
18383 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18384 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18385 last
->right_box_line_p
= 1;
18388 return it
.glyph_row
->height
;
18391 /* Move element ELT in LIST to the front of LIST.
18392 Return the updated list. */
18395 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18397 register Lisp_Object tail
, prev
;
18398 register Lisp_Object tem
;
18402 while (CONSP (tail
))
18408 /* Splice out the link TAIL. */
18410 list
= XCDR (tail
);
18412 Fsetcdr (prev
, XCDR (tail
));
18414 /* Now make it the first. */
18415 Fsetcdr (tail
, list
);
18420 tail
= XCDR (tail
);
18424 /* Not found--return unchanged LIST. */
18428 /* Contribute ELT to the mode line for window IT->w. How it
18429 translates into text depends on its data type.
18431 IT describes the display environment in which we display, as usual.
18433 DEPTH is the depth in recursion. It is used to prevent
18434 infinite recursion here.
18436 FIELD_WIDTH is the number of characters the display of ELT should
18437 occupy in the mode line, and PRECISION is the maximum number of
18438 characters to display from ELT's representation. See
18439 display_string for details.
18441 Returns the hpos of the end of the text generated by ELT.
18443 PROPS is a property list to add to any string we encounter.
18445 If RISKY is nonzero, remove (disregard) any properties in any string
18446 we encounter, and ignore :eval and :propertize.
18448 The global variable `mode_line_target' determines whether the
18449 output is passed to `store_mode_line_noprop',
18450 `store_mode_line_string', or `display_string'. */
18453 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18454 Lisp_Object elt
, Lisp_Object props
, int risky
)
18456 int n
= 0, field
, prec
;
18461 elt
= build_string ("*too-deep*");
18465 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18469 /* A string: output it and check for %-constructs within it. */
18471 EMACS_INT offset
= 0;
18473 if (SCHARS (elt
) > 0
18474 && (!NILP (props
) || risky
))
18476 Lisp_Object oprops
, aelt
;
18477 oprops
= Ftext_properties_at (make_number (0), elt
);
18479 /* If the starting string's properties are not what
18480 we want, translate the string. Also, if the string
18481 is risky, do that anyway. */
18483 if (NILP (Fequal (props
, oprops
)) || risky
)
18485 /* If the starting string has properties,
18486 merge the specified ones onto the existing ones. */
18487 if (! NILP (oprops
) && !risky
)
18491 oprops
= Fcopy_sequence (oprops
);
18493 while (CONSP (tem
))
18495 oprops
= Fplist_put (oprops
, XCAR (tem
),
18496 XCAR (XCDR (tem
)));
18497 tem
= XCDR (XCDR (tem
));
18502 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18503 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18505 /* AELT is what we want. Move it to the front
18506 without consing. */
18508 mode_line_proptrans_alist
18509 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18515 /* If AELT has the wrong props, it is useless.
18516 so get rid of it. */
18518 mode_line_proptrans_alist
18519 = Fdelq (aelt
, mode_line_proptrans_alist
);
18521 elt
= Fcopy_sequence (elt
);
18522 Fset_text_properties (make_number (0), Flength (elt
),
18524 /* Add this item to mode_line_proptrans_alist. */
18525 mode_line_proptrans_alist
18526 = Fcons (Fcons (elt
, props
),
18527 mode_line_proptrans_alist
);
18528 /* Truncate mode_line_proptrans_alist
18529 to at most 50 elements. */
18530 tem
= Fnthcdr (make_number (50),
18531 mode_line_proptrans_alist
);
18533 XSETCDR (tem
, Qnil
);
18542 prec
= precision
- n
;
18543 switch (mode_line_target
)
18545 case MODE_LINE_NOPROP
:
18546 case MODE_LINE_TITLE
:
18547 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
18549 case MODE_LINE_STRING
:
18550 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18552 case MODE_LINE_DISPLAY
:
18553 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18554 0, prec
, 0, STRING_MULTIBYTE (elt
));
18561 /* Handle the non-literal case. */
18563 while ((precision
<= 0 || n
< precision
)
18564 && SREF (elt
, offset
) != 0
18565 && (mode_line_target
!= MODE_LINE_DISPLAY
18566 || it
->current_x
< it
->last_visible_x
))
18568 EMACS_INT last_offset
= offset
;
18570 /* Advance to end of string or next format specifier. */
18571 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18574 if (offset
- 1 != last_offset
)
18576 EMACS_INT nchars
, nbytes
;
18578 /* Output to end of string or up to '%'. Field width
18579 is length of string. Don't output more than
18580 PRECISION allows us. */
18583 prec
= c_string_width (SDATA (elt
) + last_offset
,
18584 offset
- last_offset
, precision
- n
,
18587 switch (mode_line_target
)
18589 case MODE_LINE_NOPROP
:
18590 case MODE_LINE_TITLE
:
18591 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
18593 case MODE_LINE_STRING
:
18595 EMACS_INT bytepos
= last_offset
;
18596 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18597 EMACS_INT endpos
= (precision
<= 0
18598 ? string_byte_to_char (elt
, offset
)
18599 : charpos
+ nchars
);
18601 n
+= store_mode_line_string (NULL
,
18602 Fsubstring (elt
, make_number (charpos
),
18603 make_number (endpos
)),
18607 case MODE_LINE_DISPLAY
:
18609 EMACS_INT bytepos
= last_offset
;
18610 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18612 if (precision
<= 0)
18613 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18614 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18616 STRING_MULTIBYTE (elt
));
18621 else /* c == '%' */
18623 EMACS_INT percent_position
= offset
;
18625 /* Get the specified minimum width. Zero means
18628 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18629 field
= field
* 10 + c
- '0';
18631 /* Don't pad beyond the total padding allowed. */
18632 if (field_width
- n
> 0 && field
> field_width
- n
)
18633 field
= field_width
- n
;
18635 /* Note that either PRECISION <= 0 or N < PRECISION. */
18636 prec
= precision
- n
;
18639 n
+= display_mode_element (it
, depth
, field
, prec
,
18640 Vglobal_mode_string
, props
,
18645 EMACS_INT bytepos
, charpos
;
18647 Lisp_Object string
;
18649 bytepos
= percent_position
;
18650 charpos
= (STRING_MULTIBYTE (elt
)
18651 ? string_byte_to_char (elt
, bytepos
)
18653 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
18654 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18656 switch (mode_line_target
)
18658 case MODE_LINE_NOPROP
:
18659 case MODE_LINE_TITLE
:
18660 n
+= store_mode_line_noprop (spec
, field
, prec
);
18662 case MODE_LINE_STRING
:
18664 int len
= strlen (spec
);
18665 Lisp_Object tem
= make_string (spec
, len
);
18666 props
= Ftext_properties_at (make_number (charpos
), elt
);
18667 /* Should only keep face property in props */
18668 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18671 case MODE_LINE_DISPLAY
:
18673 int nglyphs_before
, nwritten
;
18675 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18676 nwritten
= display_string (spec
, string
, elt
,
18681 /* Assign to the glyphs written above the
18682 string where the `%x' came from, position
18686 struct glyph
*glyph
18687 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18691 for (i
= 0; i
< nwritten
; ++i
)
18693 glyph
[i
].object
= elt
;
18694 glyph
[i
].charpos
= charpos
;
18711 /* A symbol: process the value of the symbol recursively
18712 as if it appeared here directly. Avoid error if symbol void.
18713 Special case: if value of symbol is a string, output the string
18716 register Lisp_Object tem
;
18718 /* If the variable is not marked as risky to set
18719 then its contents are risky to use. */
18720 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18723 tem
= Fboundp (elt
);
18726 tem
= Fsymbol_value (elt
);
18727 /* If value is a string, output that string literally:
18728 don't check for % within it. */
18732 if (!EQ (tem
, elt
))
18734 /* Give up right away for nil or t. */
18744 register Lisp_Object car
, tem
;
18746 /* A cons cell: five distinct cases.
18747 If first element is :eval or :propertize, do something special.
18748 If first element is a string or a cons, process all the elements
18749 and effectively concatenate them.
18750 If first element is a negative number, truncate displaying cdr to
18751 at most that many characters. If positive, pad (with spaces)
18752 to at least that many characters.
18753 If first element is a symbol, process the cadr or caddr recursively
18754 according to whether the symbol's value is non-nil or nil. */
18756 if (EQ (car
, QCeval
))
18758 /* An element of the form (:eval FORM) means evaluate FORM
18759 and use the result as mode line elements. */
18764 if (CONSP (XCDR (elt
)))
18767 spec
= safe_eval (XCAR (XCDR (elt
)));
18768 n
+= display_mode_element (it
, depth
, field_width
- n
,
18769 precision
- n
, spec
, props
,
18773 else if (EQ (car
, QCpropertize
))
18775 /* An element of the form (:propertize ELT PROPS...)
18776 means display ELT but applying properties PROPS. */
18781 if (CONSP (XCDR (elt
)))
18782 n
+= display_mode_element (it
, depth
, field_width
- n
,
18783 precision
- n
, XCAR (XCDR (elt
)),
18784 XCDR (XCDR (elt
)), risky
);
18786 else if (SYMBOLP (car
))
18788 tem
= Fboundp (car
);
18792 /* elt is now the cdr, and we know it is a cons cell.
18793 Use its car if CAR has a non-nil value. */
18796 tem
= Fsymbol_value (car
);
18803 /* Symbol's value is nil (or symbol is unbound)
18804 Get the cddr of the original list
18805 and if possible find the caddr and use that. */
18809 else if (!CONSP (elt
))
18814 else if (INTEGERP (car
))
18816 register int lim
= XINT (car
);
18820 /* Negative int means reduce maximum width. */
18821 if (precision
<= 0)
18824 precision
= min (precision
, -lim
);
18828 /* Padding specified. Don't let it be more than
18829 current maximum. */
18831 lim
= min (precision
, lim
);
18833 /* If that's more padding than already wanted, queue it.
18834 But don't reduce padding already specified even if
18835 that is beyond the current truncation point. */
18836 field_width
= max (lim
, field_width
);
18840 else if (STRINGP (car
) || CONSP (car
))
18842 Lisp_Object halftail
= elt
;
18846 && (precision
<= 0 || n
< precision
))
18848 n
+= display_mode_element (it
, depth
,
18849 /* Do padding only after the last
18850 element in the list. */
18851 (! CONSP (XCDR (elt
))
18854 precision
- n
, XCAR (elt
),
18858 if ((len
& 1) == 0)
18859 halftail
= XCDR (halftail
);
18860 /* Check for cycle. */
18861 if (EQ (halftail
, elt
))
18870 elt
= build_string ("*invalid*");
18874 /* Pad to FIELD_WIDTH. */
18875 if (field_width
> 0 && n
< field_width
)
18877 switch (mode_line_target
)
18879 case MODE_LINE_NOPROP
:
18880 case MODE_LINE_TITLE
:
18881 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18883 case MODE_LINE_STRING
:
18884 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18886 case MODE_LINE_DISPLAY
:
18887 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18896 /* Store a mode-line string element in mode_line_string_list.
18898 If STRING is non-null, display that C string. Otherwise, the Lisp
18899 string LISP_STRING is displayed.
18901 FIELD_WIDTH is the minimum number of output glyphs to produce.
18902 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18903 with spaces. FIELD_WIDTH <= 0 means don't pad.
18905 PRECISION is the maximum number of characters to output from
18906 STRING. PRECISION <= 0 means don't truncate the string.
18908 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18909 properties to the string.
18911 PROPS are the properties to add to the string.
18912 The mode_line_string_face face property is always added to the string.
18916 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
18917 int field_width
, int precision
, Lisp_Object props
)
18922 if (string
!= NULL
)
18924 len
= strlen (string
);
18925 if (precision
> 0 && len
> precision
)
18927 lisp_string
= make_string (string
, len
);
18929 props
= mode_line_string_face_prop
;
18930 else if (!NILP (mode_line_string_face
))
18932 Lisp_Object face
= Fplist_get (props
, Qface
);
18933 props
= Fcopy_sequence (props
);
18935 face
= mode_line_string_face
;
18937 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18938 props
= Fplist_put (props
, Qface
, face
);
18940 Fadd_text_properties (make_number (0), make_number (len
),
18941 props
, lisp_string
);
18945 len
= XFASTINT (Flength (lisp_string
));
18946 if (precision
> 0 && len
> precision
)
18949 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18952 if (!NILP (mode_line_string_face
))
18956 props
= Ftext_properties_at (make_number (0), lisp_string
);
18957 face
= Fplist_get (props
, Qface
);
18959 face
= mode_line_string_face
;
18961 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18962 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18964 lisp_string
= Fcopy_sequence (lisp_string
);
18967 Fadd_text_properties (make_number (0), make_number (len
),
18968 props
, lisp_string
);
18973 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18977 if (field_width
> len
)
18979 field_width
-= len
;
18980 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18982 Fadd_text_properties (make_number (0), make_number (field_width
),
18983 props
, lisp_string
);
18984 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18992 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18994 doc
: /* Format a string out of a mode line format specification.
18995 First arg FORMAT specifies the mode line format (see `mode-line-format'
18996 for details) to use.
18998 By default, the format is evaluated for the currently selected window.
19000 Optional second arg FACE specifies the face property to put on all
19001 characters for which no face is specified. The value nil means the
19002 default face. The value t means whatever face the window's mode line
19003 currently uses (either `mode-line' or `mode-line-inactive',
19004 depending on whether the window is the selected window or not).
19005 An integer value means the value string has no text
19008 Optional third and fourth args WINDOW and BUFFER specify the window
19009 and buffer to use as the context for the formatting (defaults
19010 are the selected window and the WINDOW's buffer). */)
19011 (Lisp_Object format
, Lisp_Object face
,
19012 Lisp_Object window
, Lisp_Object buffer
)
19017 struct buffer
*old_buffer
= NULL
;
19019 int no_props
= INTEGERP (face
);
19020 int count
= SPECPDL_INDEX ();
19022 int string_start
= 0;
19025 window
= selected_window
;
19026 CHECK_WINDOW (window
);
19027 w
= XWINDOW (window
);
19030 buffer
= w
->buffer
;
19031 CHECK_BUFFER (buffer
);
19033 /* Make formatting the modeline a non-op when noninteractive, otherwise
19034 there will be problems later caused by a partially initialized frame. */
19035 if (NILP (format
) || noninteractive
)
19036 return empty_unibyte_string
;
19041 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19042 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19043 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19044 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19045 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19046 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19047 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19050 if (XBUFFER (buffer
) != current_buffer
)
19051 old_buffer
= current_buffer
;
19053 /* Save things including mode_line_proptrans_alist,
19054 and set that to nil so that we don't alter the outer value. */
19055 record_unwind_protect (unwind_format_mode_line
,
19056 format_mode_line_unwind_data
19057 (old_buffer
, selected_window
, 1));
19058 mode_line_proptrans_alist
= Qnil
;
19060 Fselect_window (window
, Qt
);
19062 set_buffer_internal_1 (XBUFFER (buffer
));
19064 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19068 mode_line_target
= MODE_LINE_NOPROP
;
19069 mode_line_string_face_prop
= Qnil
;
19070 mode_line_string_list
= Qnil
;
19071 string_start
= MODE_LINE_NOPROP_LEN (0);
19075 mode_line_target
= MODE_LINE_STRING
;
19076 mode_line_string_list
= Qnil
;
19077 mode_line_string_face
= face
;
19078 mode_line_string_face_prop
19079 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19082 push_kboard (FRAME_KBOARD (it
.f
));
19083 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19088 len
= MODE_LINE_NOPROP_LEN (string_start
);
19089 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19093 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19094 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19095 empty_unibyte_string
);
19098 unbind_to (count
, Qnil
);
19102 /* Write a null-terminated, right justified decimal representation of
19103 the positive integer D to BUF using a minimal field width WIDTH. */
19106 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19108 register char *p
= buf
;
19116 *p
++ = d
% 10 + '0';
19121 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19132 /* Write a null-terminated, right justified decimal and "human
19133 readable" representation of the nonnegative integer D to BUF using
19134 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19136 static const char power_letter
[] =
19150 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19152 /* We aim to represent the nonnegative integer D as
19153 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19154 EMACS_INT quotient
= d
;
19156 /* -1 means: do not use TENTHS. */
19160 /* Length of QUOTIENT.TENTHS as a string. */
19166 if (1000 <= quotient
)
19168 /* Scale to the appropriate EXPONENT. */
19171 remainder
= quotient
% 1000;
19175 while (1000 <= quotient
);
19177 /* Round to nearest and decide whether to use TENTHS or not. */
19180 tenths
= remainder
/ 100;
19181 if (50 <= remainder
% 100)
19188 if (quotient
== 10)
19196 if (500 <= remainder
)
19198 if (quotient
< 999)
19209 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19210 if (tenths
== -1 && quotient
<= 99)
19217 p
= psuffix
= buf
+ max (width
, length
);
19219 /* Print EXPONENT. */
19220 *psuffix
++ = power_letter
[exponent
];
19223 /* Print TENTHS. */
19226 *--p
= '0' + tenths
;
19230 /* Print QUOTIENT. */
19233 int digit
= quotient
% 10;
19234 *--p
= '0' + digit
;
19236 while ((quotient
/= 10) != 0);
19238 /* Print leading spaces. */
19243 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19244 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19245 type of CODING_SYSTEM. Return updated pointer into BUF. */
19247 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19250 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19253 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19254 const unsigned char *eol_str
;
19256 /* The EOL conversion we are using. */
19257 Lisp_Object eoltype
;
19259 val
= CODING_SYSTEM_SPEC (coding_system
);
19262 if (!VECTORP (val
)) /* Not yet decided. */
19267 eoltype
= eol_mnemonic_undecided
;
19268 /* Don't mention EOL conversion if it isn't decided. */
19273 Lisp_Object eolvalue
;
19275 attrs
= AREF (val
, 0);
19276 eolvalue
= AREF (val
, 2);
19279 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19283 /* The EOL conversion that is normal on this system. */
19285 if (NILP (eolvalue
)) /* Not yet decided. */
19286 eoltype
= eol_mnemonic_undecided
;
19287 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19288 eoltype
= eol_mnemonic_undecided
;
19289 else /* eolvalue is Qunix, Qdos, or Qmac. */
19290 eoltype
= (EQ (eolvalue
, Qunix
)
19291 ? eol_mnemonic_unix
19292 : (EQ (eolvalue
, Qdos
) == 1
19293 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19299 /* Mention the EOL conversion if it is not the usual one. */
19300 if (STRINGP (eoltype
))
19302 eol_str
= SDATA (eoltype
);
19303 eol_str_len
= SBYTES (eoltype
);
19305 else if (CHARACTERP (eoltype
))
19307 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19308 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19313 eol_str
= invalid_eol_type
;
19314 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19316 memcpy (buf
, eol_str
, eol_str_len
);
19317 buf
+= eol_str_len
;
19323 /* Return a string for the output of a mode line %-spec for window W,
19324 generated by character C. FIELD_WIDTH > 0 means pad the string
19325 returned with spaces to that value. Return a Lisp string in
19326 *STRING if the resulting string is taken from that Lisp string.
19328 Note we operate on the current buffer for most purposes,
19329 the exception being w->base_line_pos. */
19331 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19333 static const char *
19334 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19335 Lisp_Object
*string
)
19338 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19339 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19340 struct buffer
*b
= current_buffer
;
19348 if (!NILP (BVAR (b
, read_only
)))
19350 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19355 /* This differs from %* only for a modified read-only buffer. */
19356 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19358 if (!NILP (BVAR (b
, read_only
)))
19363 /* This differs from %* in ignoring read-only-ness. */
19364 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19376 if (command_loop_level
> 5)
19378 p
= decode_mode_spec_buf
;
19379 for (i
= 0; i
< command_loop_level
; i
++)
19382 return decode_mode_spec_buf
;
19390 if (command_loop_level
> 5)
19392 p
= decode_mode_spec_buf
;
19393 for (i
= 0; i
< command_loop_level
; i
++)
19396 return decode_mode_spec_buf
;
19403 /* Let lots_of_dashes be a string of infinite length. */
19404 if (mode_line_target
== MODE_LINE_NOPROP
||
19405 mode_line_target
== MODE_LINE_STRING
)
19407 if (field_width
<= 0
19408 || field_width
> sizeof (lots_of_dashes
))
19410 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19411 decode_mode_spec_buf
[i
] = '-';
19412 decode_mode_spec_buf
[i
] = '\0';
19413 return decode_mode_spec_buf
;
19416 return lots_of_dashes
;
19420 obj
= BVAR (b
, name
);
19424 /* %c and %l are ignored in `frame-title-format'.
19425 (In redisplay_internal, the frame title is drawn _before_ the
19426 windows are updated, so the stuff which depends on actual
19427 window contents (such as %l) may fail to render properly, or
19428 even crash emacs.) */
19429 if (mode_line_target
== MODE_LINE_TITLE
)
19433 EMACS_INT col
= current_column ();
19434 w
->column_number_displayed
= make_number (col
);
19435 pint2str (decode_mode_spec_buf
, field_width
, col
);
19436 return decode_mode_spec_buf
;
19440 #ifndef SYSTEM_MALLOC
19442 if (NILP (Vmemory_full
))
19445 return "!MEM FULL! ";
19452 /* %F displays the frame name. */
19453 if (!NILP (f
->title
))
19454 return SSDATA (f
->title
);
19455 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19456 return SSDATA (f
->name
);
19460 obj
= BVAR (b
, filename
);
19465 EMACS_INT size
= ZV
- BEGV
;
19466 pint2str (decode_mode_spec_buf
, field_width
, size
);
19467 return decode_mode_spec_buf
;
19472 EMACS_INT size
= ZV
- BEGV
;
19473 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19474 return decode_mode_spec_buf
;
19479 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19480 EMACS_INT topline
, nlines
, height
;
19483 /* %c and %l are ignored in `frame-title-format'. */
19484 if (mode_line_target
== MODE_LINE_TITLE
)
19487 startpos
= XMARKER (w
->start
)->charpos
;
19488 startpos_byte
= marker_byte_position (w
->start
);
19489 height
= WINDOW_TOTAL_LINES (w
);
19491 /* If we decided that this buffer isn't suitable for line numbers,
19492 don't forget that too fast. */
19493 if (EQ (w
->base_line_pos
, w
->buffer
))
19495 /* But do forget it, if the window shows a different buffer now. */
19496 else if (BUFFERP (w
->base_line_pos
))
19497 w
->base_line_pos
= Qnil
;
19499 /* If the buffer is very big, don't waste time. */
19500 if (INTEGERP (Vline_number_display_limit
)
19501 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19503 w
->base_line_pos
= Qnil
;
19504 w
->base_line_number
= Qnil
;
19508 if (INTEGERP (w
->base_line_number
)
19509 && INTEGERP (w
->base_line_pos
)
19510 && XFASTINT (w
->base_line_pos
) <= startpos
)
19512 line
= XFASTINT (w
->base_line_number
);
19513 linepos
= XFASTINT (w
->base_line_pos
);
19514 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19519 linepos
= BUF_BEGV (b
);
19520 linepos_byte
= BUF_BEGV_BYTE (b
);
19523 /* Count lines from base line to window start position. */
19524 nlines
= display_count_lines (linepos_byte
,
19528 topline
= nlines
+ line
;
19530 /* Determine a new base line, if the old one is too close
19531 or too far away, or if we did not have one.
19532 "Too close" means it's plausible a scroll-down would
19533 go back past it. */
19534 if (startpos
== BUF_BEGV (b
))
19536 w
->base_line_number
= make_number (topline
);
19537 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19539 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19540 || linepos
== BUF_BEGV (b
))
19542 EMACS_INT limit
= BUF_BEGV (b
);
19543 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19544 EMACS_INT position
;
19545 EMACS_INT distance
=
19546 (height
* 2 + 30) * line_number_display_limit_width
;
19548 if (startpos
- distance
> limit
)
19550 limit
= startpos
- distance
;
19551 limit_byte
= CHAR_TO_BYTE (limit
);
19554 nlines
= display_count_lines (startpos_byte
,
19556 - (height
* 2 + 30),
19558 /* If we couldn't find the lines we wanted within
19559 line_number_display_limit_width chars per line,
19560 give up on line numbers for this window. */
19561 if (position
== limit_byte
&& limit
== startpos
- distance
)
19563 w
->base_line_pos
= w
->buffer
;
19564 w
->base_line_number
= Qnil
;
19568 w
->base_line_number
= make_number (topline
- nlines
);
19569 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19572 /* Now count lines from the start pos to point. */
19573 nlines
= display_count_lines (startpos_byte
,
19574 PT_BYTE
, PT
, &junk
);
19576 /* Record that we did display the line number. */
19577 line_number_displayed
= 1;
19579 /* Make the string to show. */
19580 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19581 return decode_mode_spec_buf
;
19584 char* p
= decode_mode_spec_buf
;
19585 int pad
= field_width
- 2;
19591 return decode_mode_spec_buf
;
19597 obj
= BVAR (b
, mode_name
);
19601 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19607 EMACS_INT pos
= marker_position (w
->start
);
19608 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19610 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19612 if (pos
<= BUF_BEGV (b
))
19617 else if (pos
<= BUF_BEGV (b
))
19621 if (total
> 1000000)
19622 /* Do it differently for a large value, to avoid overflow. */
19623 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19625 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19626 /* We can't normally display a 3-digit number,
19627 so get us a 2-digit number that is close. */
19630 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
19631 return decode_mode_spec_buf
;
19635 /* Display percentage of size above the bottom of the screen. */
19638 EMACS_INT toppos
= marker_position (w
->start
);
19639 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19640 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19642 if (botpos
>= BUF_ZV (b
))
19644 if (toppos
<= BUF_BEGV (b
))
19651 if (total
> 1000000)
19652 /* Do it differently for a large value, to avoid overflow. */
19653 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19655 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19656 /* We can't normally display a 3-digit number,
19657 so get us a 2-digit number that is close. */
19660 if (toppos
<= BUF_BEGV (b
))
19661 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
19663 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
19664 return decode_mode_spec_buf
;
19669 /* status of process */
19670 obj
= Fget_buffer_process (Fcurrent_buffer ());
19672 return "no process";
19674 obj
= Fsymbol_name (Fprocess_status (obj
));
19680 int count
= inhibit_garbage_collection ();
19681 Lisp_Object val
= call1 (intern ("file-remote-p"),
19682 BVAR (current_buffer
, directory
));
19683 unbind_to (count
, Qnil
);
19691 case 't': /* indicate TEXT or BINARY */
19695 /* coding-system (not including end-of-line format) */
19697 /* coding-system (including end-of-line type) */
19699 int eol_flag
= (c
== 'Z');
19700 char *p
= decode_mode_spec_buf
;
19702 if (! FRAME_WINDOW_P (f
))
19704 /* No need to mention EOL here--the terminal never needs
19705 to do EOL conversion. */
19706 p
= decode_mode_spec_coding (CODING_ID_NAME
19707 (FRAME_KEYBOARD_CODING (f
)->id
),
19709 p
= decode_mode_spec_coding (CODING_ID_NAME
19710 (FRAME_TERMINAL_CODING (f
)->id
),
19713 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
19716 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19717 #ifdef subprocesses
19718 obj
= Fget_buffer_process (Fcurrent_buffer ());
19719 if (PROCESSP (obj
))
19721 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19723 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19726 #endif /* subprocesses */
19729 return decode_mode_spec_buf
;
19736 return SSDATA (obj
);
19743 /* Count up to COUNT lines starting from START_BYTE.
19744 But don't go beyond LIMIT_BYTE.
19745 Return the number of lines thus found (always nonnegative).
19747 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19750 display_count_lines (EMACS_INT start_byte
,
19751 EMACS_INT limit_byte
, EMACS_INT count
,
19752 EMACS_INT
*byte_pos_ptr
)
19754 register unsigned char *cursor
;
19755 unsigned char *base
;
19757 register EMACS_INT ceiling
;
19758 register unsigned char *ceiling_addr
;
19759 EMACS_INT orig_count
= count
;
19761 /* If we are not in selective display mode,
19762 check only for newlines. */
19763 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
19764 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
19768 while (start_byte
< limit_byte
)
19770 ceiling
= BUFFER_CEILING_OF (start_byte
);
19771 ceiling
= min (limit_byte
- 1, ceiling
);
19772 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19773 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19776 if (selective_display
)
19777 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19780 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19783 if (cursor
!= ceiling_addr
)
19787 start_byte
+= cursor
- base
+ 1;
19788 *byte_pos_ptr
= start_byte
;
19792 if (++cursor
== ceiling_addr
)
19798 start_byte
+= cursor
- base
;
19803 while (start_byte
> limit_byte
)
19805 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19806 ceiling
= max (limit_byte
, ceiling
);
19807 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19808 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19811 if (selective_display
)
19812 while (--cursor
!= ceiling_addr
19813 && *cursor
!= '\n' && *cursor
!= 015)
19816 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19819 if (cursor
!= ceiling_addr
)
19823 start_byte
+= cursor
- base
+ 1;
19824 *byte_pos_ptr
= start_byte
;
19825 /* When scanning backwards, we should
19826 not count the newline posterior to which we stop. */
19827 return - orig_count
- 1;
19833 /* Here we add 1 to compensate for the last decrement
19834 of CURSOR, which took it past the valid range. */
19835 start_byte
+= cursor
- base
+ 1;
19839 *byte_pos_ptr
= limit_byte
;
19842 return - orig_count
+ count
;
19843 return orig_count
- count
;
19849 /***********************************************************************
19851 ***********************************************************************/
19853 /* Display a NUL-terminated string, starting with index START.
19855 If STRING is non-null, display that C string. Otherwise, the Lisp
19856 string LISP_STRING is displayed. There's a case that STRING is
19857 non-null and LISP_STRING is not nil. It means STRING is a string
19858 data of LISP_STRING. In that case, we display LISP_STRING while
19859 ignoring its text properties.
19861 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19862 FACE_STRING. Display STRING or LISP_STRING with the face at
19863 FACE_STRING_POS in FACE_STRING:
19865 Display the string in the environment given by IT, but use the
19866 standard display table, temporarily.
19868 FIELD_WIDTH is the minimum number of output glyphs to produce.
19869 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19870 with spaces. If STRING has more characters, more than FIELD_WIDTH
19871 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19873 PRECISION is the maximum number of characters to output from
19874 STRING. PRECISION < 0 means don't truncate the string.
19876 This is roughly equivalent to printf format specifiers:
19878 FIELD_WIDTH PRECISION PRINTF
19879 ----------------------------------------
19885 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19886 display them, and < 0 means obey the current buffer's value of
19887 enable_multibyte_characters.
19889 Value is the number of columns displayed. */
19892 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
19893 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
19894 int field_width
, int precision
, int max_x
, int multibyte
)
19896 int hpos_at_start
= it
->hpos
;
19897 int saved_face_id
= it
->face_id
;
19898 struct glyph_row
*row
= it
->glyph_row
;
19900 /* Initialize the iterator IT for iteration over STRING beginning
19901 with index START. */
19902 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19903 precision
, field_width
, multibyte
);
19904 if (string
&& STRINGP (lisp_string
))
19905 /* LISP_STRING is the one returned by decode_mode_spec. We should
19906 ignore its text properties. */
19907 it
->stop_charpos
= -1;
19909 /* If displaying STRING, set up the face of the iterator
19910 from LISP_STRING, if that's given. */
19911 if (STRINGP (face_string
))
19917 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19918 0, it
->region_beg_charpos
,
19919 it
->region_end_charpos
,
19920 &endptr
, it
->base_face_id
, 0);
19921 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19922 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19925 /* Set max_x to the maximum allowed X position. Don't let it go
19926 beyond the right edge of the window. */
19928 max_x
= it
->last_visible_x
;
19930 max_x
= min (max_x
, it
->last_visible_x
);
19932 /* Skip over display elements that are not visible. because IT->w is
19934 if (it
->current_x
< it
->first_visible_x
)
19935 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19936 MOVE_TO_POS
| MOVE_TO_X
);
19938 row
->ascent
= it
->max_ascent
;
19939 row
->height
= it
->max_ascent
+ it
->max_descent
;
19940 row
->phys_ascent
= it
->max_phys_ascent
;
19941 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19942 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19944 /* This condition is for the case that we are called with current_x
19945 past last_visible_x. */
19946 while (it
->current_x
< max_x
)
19948 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19950 /* Get the next display element. */
19951 if (!get_next_display_element (it
))
19954 /* Produce glyphs. */
19955 x_before
= it
->current_x
;
19956 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19957 PRODUCE_GLYPHS (it
);
19959 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19962 while (i
< nglyphs
)
19964 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19966 if (it
->line_wrap
!= TRUNCATE
19967 && x
+ glyph
->pixel_width
> max_x
)
19969 /* End of continued line or max_x reached. */
19970 if (CHAR_GLYPH_PADDING_P (*glyph
))
19972 /* A wide character is unbreakable. */
19973 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19974 it
->current_x
= x_before
;
19978 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19983 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19985 /* Glyph is at least partially visible. */
19987 if (x
< it
->first_visible_x
)
19988 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19992 /* Glyph is off the left margin of the display area.
19993 Should not happen. */
19997 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19998 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19999 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20000 row
->phys_height
= max (row
->phys_height
,
20001 it
->max_phys_ascent
+ it
->max_phys_descent
);
20002 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20003 it
->max_extra_line_spacing
);
20004 x
+= glyph
->pixel_width
;
20008 /* Stop if max_x reached. */
20012 /* Stop at line ends. */
20013 if (ITERATOR_AT_END_OF_LINE_P (it
))
20015 it
->continuation_lines_width
= 0;
20019 set_iterator_to_next (it
, 1);
20021 /* Stop if truncating at the right edge. */
20022 if (it
->line_wrap
== TRUNCATE
20023 && it
->current_x
>= it
->last_visible_x
)
20025 /* Add truncation mark, but don't do it if the line is
20026 truncated at a padding space. */
20027 if (IT_CHARPOS (*it
) < it
->string_nchars
)
20029 if (!FRAME_WINDOW_P (it
->f
))
20033 if (it
->current_x
> it
->last_visible_x
)
20035 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20036 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20038 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20040 row
->used
[TEXT_AREA
] = ii
;
20041 produce_special_glyphs (it
, IT_TRUNCATION
);
20044 produce_special_glyphs (it
, IT_TRUNCATION
);
20046 it
->glyph_row
->truncated_on_right_p
= 1;
20052 /* Maybe insert a truncation at the left. */
20053 if (it
->first_visible_x
20054 && IT_CHARPOS (*it
) > 0)
20056 if (!FRAME_WINDOW_P (it
->f
))
20057 insert_left_trunc_glyphs (it
);
20058 it
->glyph_row
->truncated_on_left_p
= 1;
20061 it
->face_id
= saved_face_id
;
20063 /* Value is number of columns displayed. */
20064 return it
->hpos
- hpos_at_start
;
20069 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20070 appears as an element of LIST or as the car of an element of LIST.
20071 If PROPVAL is a list, compare each element against LIST in that
20072 way, and return 1/2 if any element of PROPVAL is found in LIST.
20073 Otherwise return 0. This function cannot quit.
20074 The return value is 2 if the text is invisible but with an ellipsis
20075 and 1 if it's invisible and without an ellipsis. */
20078 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20080 register Lisp_Object tail
, proptail
;
20082 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20084 register Lisp_Object tem
;
20086 if (EQ (propval
, tem
))
20088 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20089 return NILP (XCDR (tem
)) ? 1 : 2;
20092 if (CONSP (propval
))
20094 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20096 Lisp_Object propelt
;
20097 propelt
= XCAR (proptail
);
20098 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20100 register Lisp_Object tem
;
20102 if (EQ (propelt
, tem
))
20104 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20105 return NILP (XCDR (tem
)) ? 1 : 2;
20113 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20114 doc
: /* Non-nil if the property makes the text invisible.
20115 POS-OR-PROP can be a marker or number, in which case it is taken to be
20116 a position in the current buffer and the value of the `invisible' property
20117 is checked; or it can be some other value, which is then presumed to be the
20118 value of the `invisible' property of the text of interest.
20119 The non-nil value returned can be t for truly invisible text or something
20120 else if the text is replaced by an ellipsis. */)
20121 (Lisp_Object pos_or_prop
)
20124 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20125 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20127 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20128 return (invis
== 0 ? Qnil
20130 : make_number (invis
));
20133 /* Calculate a width or height in pixels from a specification using
20134 the following elements:
20137 NUM - a (fractional) multiple of the default font width/height
20138 (NUM) - specifies exactly NUM pixels
20139 UNIT - a fixed number of pixels, see below.
20140 ELEMENT - size of a display element in pixels, see below.
20141 (NUM . SPEC) - equals NUM * SPEC
20142 (+ SPEC SPEC ...) - add pixel values
20143 (- SPEC SPEC ...) - subtract pixel values
20144 (- SPEC) - negate pixel value
20147 INT or FLOAT - a number constant
20148 SYMBOL - use symbol's (buffer local) variable binding.
20151 in - pixels per inch *)
20152 mm - pixels per 1/1000 meter *)
20153 cm - pixels per 1/100 meter *)
20154 width - width of current font in pixels.
20155 height - height of current font in pixels.
20157 *) using the ratio(s) defined in display-pixels-per-inch.
20161 left-fringe - left fringe width in pixels
20162 right-fringe - right fringe width in pixels
20164 left-margin - left margin width in pixels
20165 right-margin - right margin width in pixels
20167 scroll-bar - scroll-bar area width in pixels
20171 Pixels corresponding to 5 inches:
20174 Total width of non-text areas on left side of window (if scroll-bar is on left):
20175 '(space :width (+ left-fringe left-margin scroll-bar))
20177 Align to first text column (in header line):
20178 '(space :align-to 0)
20180 Align to middle of text area minus half the width of variable `my-image'
20181 containing a loaded image:
20182 '(space :align-to (0.5 . (- text my-image)))
20184 Width of left margin minus width of 1 character in the default font:
20185 '(space :width (- left-margin 1))
20187 Width of left margin minus width of 2 characters in the current font:
20188 '(space :width (- left-margin (2 . width)))
20190 Center 1 character over left-margin (in header line):
20191 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20193 Different ways to express width of left fringe plus left margin minus one pixel:
20194 '(space :width (- (+ left-fringe left-margin) (1)))
20195 '(space :width (+ left-fringe left-margin (- (1))))
20196 '(space :width (+ left-fringe left-margin (-1)))
20200 #define NUMVAL(X) \
20201 ((INTEGERP (X) || FLOATP (X)) \
20206 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20207 struct font
*font
, int width_p
, int *align_to
)
20211 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20212 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20215 return OK_PIXELS (0);
20217 xassert (FRAME_LIVE_P (it
->f
));
20219 if (SYMBOLP (prop
))
20221 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20223 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20225 if (unit
[0] == 'i' && unit
[1] == 'n')
20227 else if (unit
[0] == 'm' && unit
[1] == 'm')
20229 else if (unit
[0] == 'c' && unit
[1] == 'm')
20236 #ifdef HAVE_WINDOW_SYSTEM
20237 if (FRAME_WINDOW_P (it
->f
)
20239 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20240 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20242 return OK_PIXELS (ppi
/ pixels
);
20245 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20246 || (CONSP (Vdisplay_pixels_per_inch
)
20248 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20249 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20251 return OK_PIXELS (ppi
/ pixels
);
20257 #ifdef HAVE_WINDOW_SYSTEM
20258 if (EQ (prop
, Qheight
))
20259 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20260 if (EQ (prop
, Qwidth
))
20261 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20263 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20264 return OK_PIXELS (1);
20267 if (EQ (prop
, Qtext
))
20268 return OK_PIXELS (width_p
20269 ? window_box_width (it
->w
, TEXT_AREA
)
20270 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20272 if (align_to
&& *align_to
< 0)
20275 if (EQ (prop
, Qleft
))
20276 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20277 if (EQ (prop
, Qright
))
20278 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20279 if (EQ (prop
, Qcenter
))
20280 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20281 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20282 if (EQ (prop
, Qleft_fringe
))
20283 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20284 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20285 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20286 if (EQ (prop
, Qright_fringe
))
20287 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20288 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20289 : window_box_right_offset (it
->w
, TEXT_AREA
));
20290 if (EQ (prop
, Qleft_margin
))
20291 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20292 if (EQ (prop
, Qright_margin
))
20293 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20294 if (EQ (prop
, Qscroll_bar
))
20295 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20297 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20298 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20299 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20304 if (EQ (prop
, Qleft_fringe
))
20305 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20306 if (EQ (prop
, Qright_fringe
))
20307 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20308 if (EQ (prop
, Qleft_margin
))
20309 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20310 if (EQ (prop
, Qright_margin
))
20311 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20312 if (EQ (prop
, Qscroll_bar
))
20313 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20316 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20319 if (INTEGERP (prop
) || FLOATP (prop
))
20321 int base_unit
= (width_p
20322 ? FRAME_COLUMN_WIDTH (it
->f
)
20323 : FRAME_LINE_HEIGHT (it
->f
));
20324 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20329 Lisp_Object car
= XCAR (prop
);
20330 Lisp_Object cdr
= XCDR (prop
);
20334 #ifdef HAVE_WINDOW_SYSTEM
20335 if (FRAME_WINDOW_P (it
->f
)
20336 && valid_image_p (prop
))
20338 int id
= lookup_image (it
->f
, prop
);
20339 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20341 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20344 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20350 while (CONSP (cdr
))
20352 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20353 font
, width_p
, align_to
))
20356 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20361 if (EQ (car
, Qminus
))
20363 return OK_PIXELS (pixels
);
20366 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20369 if (INTEGERP (car
) || FLOATP (car
))
20372 pixels
= XFLOATINT (car
);
20374 return OK_PIXELS (pixels
);
20375 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20376 font
, width_p
, align_to
))
20377 return OK_PIXELS (pixels
* fact
);
20388 /***********************************************************************
20390 ***********************************************************************/
20392 #ifdef HAVE_WINDOW_SYSTEM
20397 dump_glyph_string (s
)
20398 struct glyph_string
*s
;
20400 fprintf (stderr
, "glyph string\n");
20401 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20402 s
->x
, s
->y
, s
->width
, s
->height
);
20403 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20404 fprintf (stderr
, " hl = %d\n", s
->hl
);
20405 fprintf (stderr
, " left overhang = %d, right = %d\n",
20406 s
->left_overhang
, s
->right_overhang
);
20407 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20408 fprintf (stderr
, " extends to end of line = %d\n",
20409 s
->extends_to_end_of_line_p
);
20410 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20411 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20414 #endif /* GLYPH_DEBUG */
20416 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20417 of XChar2b structures for S; it can't be allocated in
20418 init_glyph_string because it must be allocated via `alloca'. W
20419 is the window on which S is drawn. ROW and AREA are the glyph row
20420 and area within the row from which S is constructed. START is the
20421 index of the first glyph structure covered by S. HL is a
20422 face-override for drawing S. */
20425 #define OPTIONAL_HDC(hdc) HDC hdc,
20426 #define DECLARE_HDC(hdc) HDC hdc;
20427 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20428 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20431 #ifndef OPTIONAL_HDC
20432 #define OPTIONAL_HDC(hdc)
20433 #define DECLARE_HDC(hdc)
20434 #define ALLOCATE_HDC(hdc, f)
20435 #define RELEASE_HDC(hdc, f)
20439 init_glyph_string (struct glyph_string
*s
,
20441 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20442 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20444 memset (s
, 0, sizeof *s
);
20446 s
->f
= XFRAME (w
->frame
);
20450 s
->display
= FRAME_X_DISPLAY (s
->f
);
20451 s
->window
= FRAME_X_WINDOW (s
->f
);
20452 s
->char2b
= char2b
;
20456 s
->first_glyph
= row
->glyphs
[area
] + start
;
20457 s
->height
= row
->height
;
20458 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20459 s
->ybase
= s
->y
+ row
->ascent
;
20463 /* Append the list of glyph strings with head H and tail T to the list
20464 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20467 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20468 struct glyph_string
*h
, struct glyph_string
*t
)
20482 /* Prepend the list of glyph strings with head H and tail T to the
20483 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20487 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20488 struct glyph_string
*h
, struct glyph_string
*t
)
20502 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20503 Set *HEAD and *TAIL to the resulting list. */
20506 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20507 struct glyph_string
*s
)
20509 s
->next
= s
->prev
= NULL
;
20510 append_glyph_string_lists (head
, tail
, s
, s
);
20514 /* Get face and two-byte form of character C in face FACE_ID on frame F.
20515 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
20516 make sure that X resources for the face returned are allocated.
20517 Value is a pointer to a realized face that is ready for display if
20518 DISPLAY_P is non-zero. */
20520 static INLINE
struct face
*
20521 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20522 XChar2b
*char2b
, int display_p
)
20524 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20528 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20530 if (code
!= FONT_INVALID_CODE
)
20531 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20533 STORE_XCHAR2B (char2b
, 0, 0);
20536 /* Make sure X resources of the face are allocated. */
20537 #ifdef HAVE_X_WINDOWS
20541 xassert (face
!= NULL
);
20542 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20549 /* Get face and two-byte form of character glyph GLYPH on frame F.
20550 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20551 a pointer to a realized face that is ready for display. */
20553 static INLINE
struct face
*
20554 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20555 XChar2b
*char2b
, int *two_byte_p
)
20559 xassert (glyph
->type
== CHAR_GLYPH
);
20560 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20569 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20570 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20572 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20574 if (code
!= FONT_INVALID_CODE
)
20575 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20577 STORE_XCHAR2B (char2b
, 0, 0);
20580 /* Make sure X resources of the face are allocated. */
20581 xassert (face
!= NULL
);
20582 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20587 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20588 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
20591 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
20595 if (CHAR_BYTE8_P (c
))
20596 code
= CHAR_TO_BYTE8 (c
);
20598 code
= font
->driver
->encode_char (font
, c
);
20600 if (code
== FONT_INVALID_CODE
)
20602 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20607 /* Fill glyph string S with composition components specified by S->cmp.
20609 BASE_FACE is the base face of the composition.
20610 S->cmp_from is the index of the first component for S.
20612 OVERLAPS non-zero means S should draw the foreground only, and use
20613 its physical height for clipping. See also draw_glyphs.
20615 Value is the index of a component not in S. */
20618 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
20622 /* For all glyphs of this composition, starting at the offset
20623 S->cmp_from, until we reach the end of the definition or encounter a
20624 glyph that requires the different face, add it to S. */
20629 s
->for_overlaps
= overlaps
;
20632 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20634 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20638 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20641 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20648 s
->font
= s
->face
->font
;
20650 else if (s
->face
!= face
)
20658 /* All glyph strings for the same composition has the same width,
20659 i.e. the width set for the first component of the composition. */
20660 s
->width
= s
->first_glyph
->pixel_width
;
20662 /* If the specified font could not be loaded, use the frame's
20663 default font, but record the fact that we couldn't load it in
20664 the glyph string so that we can draw rectangles for the
20665 characters of the glyph string. */
20666 if (s
->font
== NULL
)
20668 s
->font_not_found_p
= 1;
20669 s
->font
= FRAME_FONT (s
->f
);
20672 /* Adjust base line for subscript/superscript text. */
20673 s
->ybase
+= s
->first_glyph
->voffset
;
20675 /* This glyph string must always be drawn with 16-bit functions. */
20682 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
20683 int start
, int end
, int overlaps
)
20685 struct glyph
*glyph
, *last
;
20686 Lisp_Object lgstring
;
20689 s
->for_overlaps
= overlaps
;
20690 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20691 last
= s
->row
->glyphs
[s
->area
] + end
;
20692 s
->cmp_id
= glyph
->u
.cmp
.id
;
20693 s
->cmp_from
= glyph
->slice
.cmp
.from
;
20694 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
20695 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20696 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20697 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20699 while (glyph
< last
20700 && glyph
->u
.cmp
.automatic
20701 && glyph
->u
.cmp
.id
== s
->cmp_id
20702 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
20703 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
20705 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20707 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20708 unsigned code
= LGLYPH_CODE (lglyph
);
20710 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20712 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20713 return glyph
- s
->row
->glyphs
[s
->area
];
20717 /* Fill glyph string S from a sequence glyphs for glyphless characters.
20718 See the comment of fill_glyph_string for arguments.
20719 Value is the index of the first glyph not in S. */
20723 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
20724 int start
, int end
, int overlaps
)
20726 struct glyph
*glyph
, *last
;
20729 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
20730 s
->for_overlaps
= overlaps
;
20731 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20732 last
= s
->row
->glyphs
[s
->area
] + end
;
20733 voffset
= glyph
->voffset
;
20734 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20735 s
->font
= s
->face
->font
;
20737 s
->width
= glyph
->pixel_width
;
20739 while (glyph
< last
20740 && glyph
->type
== GLYPHLESS_GLYPH
20741 && glyph
->voffset
== voffset
20742 && glyph
->face_id
== face_id
)
20745 s
->width
+= glyph
->pixel_width
;
20748 s
->ybase
+= voffset
;
20749 return glyph
- s
->row
->glyphs
[s
->area
];
20753 /* Fill glyph string S from a sequence of character glyphs.
20755 FACE_ID is the face id of the string. START is the index of the
20756 first glyph to consider, END is the index of the last + 1.
20757 OVERLAPS non-zero means S should draw the foreground only, and use
20758 its physical height for clipping. See also draw_glyphs.
20760 Value is the index of the first glyph not in S. */
20763 fill_glyph_string (struct glyph_string
*s
, int face_id
,
20764 int start
, int end
, int overlaps
)
20766 struct glyph
*glyph
, *last
;
20768 int glyph_not_available_p
;
20770 xassert (s
->f
== XFRAME (s
->w
->frame
));
20771 xassert (s
->nchars
== 0);
20772 xassert (start
>= 0 && end
> start
);
20774 s
->for_overlaps
= overlaps
;
20775 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20776 last
= s
->row
->glyphs
[s
->area
] + end
;
20777 voffset
= glyph
->voffset
;
20778 s
->padding_p
= glyph
->padding_p
;
20779 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20781 while (glyph
< last
20782 && glyph
->type
== CHAR_GLYPH
20783 && glyph
->voffset
== voffset
20784 /* Same face id implies same font, nowadays. */
20785 && glyph
->face_id
== face_id
20786 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20790 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20791 s
->char2b
+ s
->nchars
,
20793 s
->two_byte_p
= two_byte_p
;
20795 xassert (s
->nchars
<= end
- start
);
20796 s
->width
+= glyph
->pixel_width
;
20797 if (glyph
++->padding_p
!= s
->padding_p
)
20801 s
->font
= s
->face
->font
;
20803 /* If the specified font could not be loaded, use the frame's font,
20804 but record the fact that we couldn't load it in
20805 S->font_not_found_p so that we can draw rectangles for the
20806 characters of the glyph string. */
20807 if (s
->font
== NULL
|| glyph_not_available_p
)
20809 s
->font_not_found_p
= 1;
20810 s
->font
= FRAME_FONT (s
->f
);
20813 /* Adjust base line for subscript/superscript text. */
20814 s
->ybase
+= voffset
;
20816 xassert (s
->face
&& s
->face
->gc
);
20817 return glyph
- s
->row
->glyphs
[s
->area
];
20821 /* Fill glyph string S from image glyph S->first_glyph. */
20824 fill_image_glyph_string (struct glyph_string
*s
)
20826 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20827 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20829 s
->slice
= s
->first_glyph
->slice
.img
;
20830 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20831 s
->font
= s
->face
->font
;
20832 s
->width
= s
->first_glyph
->pixel_width
;
20834 /* Adjust base line for subscript/superscript text. */
20835 s
->ybase
+= s
->first_glyph
->voffset
;
20839 /* Fill glyph string S from a sequence of stretch glyphs.
20841 START is the index of the first glyph to consider,
20842 END is the index of the last + 1.
20844 Value is the index of the first glyph not in S. */
20847 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
20849 struct glyph
*glyph
, *last
;
20850 int voffset
, face_id
;
20852 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20854 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20855 last
= s
->row
->glyphs
[s
->area
] + end
;
20856 face_id
= glyph
->face_id
;
20857 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20858 s
->font
= s
->face
->font
;
20859 s
->width
= glyph
->pixel_width
;
20861 voffset
= glyph
->voffset
;
20865 && glyph
->type
== STRETCH_GLYPH
20866 && glyph
->voffset
== voffset
20867 && glyph
->face_id
== face_id
);
20869 s
->width
+= glyph
->pixel_width
;
20871 /* Adjust base line for subscript/superscript text. */
20872 s
->ybase
+= voffset
;
20874 /* The case that face->gc == 0 is handled when drawing the glyph
20875 string by calling PREPARE_FACE_FOR_DISPLAY. */
20877 return glyph
- s
->row
->glyphs
[s
->area
];
20880 static struct font_metrics
*
20881 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
20883 static struct font_metrics metrics
;
20884 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20886 if (! font
|| code
== FONT_INVALID_CODE
)
20888 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20893 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20894 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20895 assumed to be zero. */
20898 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
20900 *left
= *right
= 0;
20902 if (glyph
->type
== CHAR_GLYPH
)
20906 struct font_metrics
*pcm
;
20908 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20909 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
20911 if (pcm
->rbearing
> pcm
->width
)
20912 *right
= pcm
->rbearing
- pcm
->width
;
20913 if (pcm
->lbearing
< 0)
20914 *left
= -pcm
->lbearing
;
20917 else if (glyph
->type
== COMPOSITE_GLYPH
)
20919 if (! glyph
->u
.cmp
.automatic
)
20921 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20923 if (cmp
->rbearing
> cmp
->pixel_width
)
20924 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20925 if (cmp
->lbearing
< 0)
20926 *left
= - cmp
->lbearing
;
20930 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20931 struct font_metrics metrics
;
20933 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
20934 glyph
->slice
.cmp
.to
+ 1, &metrics
);
20935 if (metrics
.rbearing
> metrics
.width
)
20936 *right
= metrics
.rbearing
- metrics
.width
;
20937 if (metrics
.lbearing
< 0)
20938 *left
= - metrics
.lbearing
;
20944 /* Return the index of the first glyph preceding glyph string S that
20945 is overwritten by S because of S's left overhang. Value is -1
20946 if no glyphs are overwritten. */
20949 left_overwritten (struct glyph_string
*s
)
20953 if (s
->left_overhang
)
20956 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20957 int first
= s
->first_glyph
- glyphs
;
20959 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20960 x
-= glyphs
[i
].pixel_width
;
20971 /* Return the index of the first glyph preceding glyph string S that
20972 is overwriting S because of its right overhang. Value is -1 if no
20973 glyph in front of S overwrites S. */
20976 left_overwriting (struct glyph_string
*s
)
20979 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20980 int first
= s
->first_glyph
- glyphs
;
20984 for (i
= first
- 1; i
>= 0; --i
)
20987 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20990 x
-= glyphs
[i
].pixel_width
;
20997 /* Return the index of the last glyph following glyph string S that is
20998 overwritten by S because of S's right overhang. Value is -1 if
20999 no such glyph is found. */
21002 right_overwritten (struct glyph_string
*s
)
21006 if (s
->right_overhang
)
21009 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21010 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21011 int end
= s
->row
->used
[s
->area
];
21013 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21014 x
+= glyphs
[i
].pixel_width
;
21023 /* Return the index of the last glyph following glyph string S that
21024 overwrites S because of its left overhang. Value is negative
21025 if no such glyph is found. */
21028 right_overwriting (struct glyph_string
*s
)
21031 int end
= s
->row
->used
[s
->area
];
21032 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21033 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21037 for (i
= first
; i
< end
; ++i
)
21040 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21043 x
+= glyphs
[i
].pixel_width
;
21050 /* Set background width of glyph string S. START is the index of the
21051 first glyph following S. LAST_X is the right-most x-position + 1
21052 in the drawing area. */
21055 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21057 /* If the face of this glyph string has to be drawn to the end of
21058 the drawing area, set S->extends_to_end_of_line_p. */
21060 if (start
== s
->row
->used
[s
->area
]
21061 && s
->area
== TEXT_AREA
21062 && ((s
->row
->fill_line_p
21063 && (s
->hl
== DRAW_NORMAL_TEXT
21064 || s
->hl
== DRAW_IMAGE_RAISED
21065 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21066 || s
->hl
== DRAW_MOUSE_FACE
))
21067 s
->extends_to_end_of_line_p
= 1;
21069 /* If S extends its face to the end of the line, set its
21070 background_width to the distance to the right edge of the drawing
21072 if (s
->extends_to_end_of_line_p
)
21073 s
->background_width
= last_x
- s
->x
+ 1;
21075 s
->background_width
= s
->width
;
21079 /* Compute overhangs and x-positions for glyph string S and its
21080 predecessors, or successors. X is the starting x-position for S.
21081 BACKWARD_P non-zero means process predecessors. */
21084 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21090 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21091 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21101 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21102 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21112 /* The following macros are only called from draw_glyphs below.
21113 They reference the following parameters of that function directly:
21114 `w', `row', `area', and `overlap_p'
21115 as well as the following local variables:
21116 `s', `f', and `hdc' (in W32) */
21119 /* On W32, silently add local `hdc' variable to argument list of
21120 init_glyph_string. */
21121 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21122 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21124 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21125 init_glyph_string (s, char2b, w, row, area, start, hl)
21128 /* Add a glyph string for a stretch glyph to the list of strings
21129 between HEAD and TAIL. START is the index of the stretch glyph in
21130 row area AREA of glyph row ROW. END is the index of the last glyph
21131 in that glyph row area. X is the current output position assigned
21132 to the new glyph string constructed. HL overrides that face of the
21133 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21134 is the right-most x-position of the drawing area. */
21136 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21137 and below -- keep them on one line. */
21138 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21141 s = (struct glyph_string *) alloca (sizeof *s); \
21142 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21143 START = fill_stretch_glyph_string (s, START, END); \
21144 append_glyph_string (&HEAD, &TAIL, s); \
21150 /* Add a glyph string for an image glyph to the list of strings
21151 between HEAD and TAIL. START is the index of the image glyph in
21152 row area AREA of glyph row ROW. END is the index of the last glyph
21153 in that glyph row area. X is the current output position assigned
21154 to the new glyph string constructed. HL overrides that face of the
21155 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21156 is the right-most x-position of the drawing area. */
21158 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21161 s = (struct glyph_string *) alloca (sizeof *s); \
21162 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21163 fill_image_glyph_string (s); \
21164 append_glyph_string (&HEAD, &TAIL, s); \
21171 /* Add a glyph string for a sequence of character glyphs to the list
21172 of strings between HEAD and TAIL. START is the index of the first
21173 glyph in row area AREA of glyph row ROW that is part of the new
21174 glyph string. END is the index of the last glyph in that glyph row
21175 area. X is the current output position assigned to the new glyph
21176 string constructed. HL overrides that face of the glyph; e.g. it
21177 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21178 right-most x-position of the drawing area. */
21180 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21186 face_id = (row)->glyphs[area][START].face_id; \
21188 s = (struct glyph_string *) alloca (sizeof *s); \
21189 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21190 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21191 append_glyph_string (&HEAD, &TAIL, s); \
21193 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21198 /* Add a glyph string for a composite sequence to the list of strings
21199 between HEAD and TAIL. START is the index of the first glyph in
21200 row area AREA of glyph row ROW that is part of the new glyph
21201 string. END is the index of the last glyph in that glyph row area.
21202 X is the current output position assigned to the new glyph string
21203 constructed. HL overrides that face of the glyph; e.g. it is
21204 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21205 x-position of the drawing area. */
21207 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21209 int face_id = (row)->glyphs[area][START].face_id; \
21210 struct face *base_face = FACE_FROM_ID (f, face_id); \
21211 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21212 struct composition *cmp = composition_table[cmp_id]; \
21214 struct glyph_string *first_s IF_LINT (= NULL); \
21217 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21219 /* Make glyph_strings for each glyph sequence that is drawable by \
21220 the same face, and append them to HEAD/TAIL. */ \
21221 for (n = 0; n < cmp->glyph_len;) \
21223 s = (struct glyph_string *) alloca (sizeof *s); \
21224 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21225 append_glyph_string (&(HEAD), &(TAIL), s); \
21231 n = fill_composite_glyph_string (s, base_face, overlaps); \
21239 /* Add a glyph string for a glyph-string sequence to the list of strings
21240 between HEAD and TAIL. */
21242 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21246 Lisp_Object gstring; \
21248 face_id = (row)->glyphs[area][START].face_id; \
21249 gstring = (composition_gstring_from_id \
21250 ((row)->glyphs[area][START].u.cmp.id)); \
21251 s = (struct glyph_string *) alloca (sizeof *s); \
21252 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21253 * LGSTRING_GLYPH_LEN (gstring)); \
21254 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21255 append_glyph_string (&(HEAD), &(TAIL), s); \
21257 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21261 /* Add a glyph string for a sequence of glyphless character's glyphs
21262 to the list of strings between HEAD and TAIL. The meanings of
21263 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21265 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21270 face_id = (row)->glyphs[area][START].face_id; \
21272 s = (struct glyph_string *) alloca (sizeof *s); \
21273 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21274 append_glyph_string (&HEAD, &TAIL, s); \
21276 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21282 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21283 of AREA of glyph row ROW on window W between indices START and END.
21284 HL overrides the face for drawing glyph strings, e.g. it is
21285 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21286 x-positions of the drawing area.
21288 This is an ugly monster macro construct because we must use alloca
21289 to allocate glyph strings (because draw_glyphs can be called
21290 asynchronously). */
21292 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21295 HEAD = TAIL = NULL; \
21296 while (START < END) \
21298 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21299 switch (first_glyph->type) \
21302 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21306 case COMPOSITE_GLYPH: \
21307 if (first_glyph->u.cmp.automatic) \
21308 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21311 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21315 case STRETCH_GLYPH: \
21316 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21320 case IMAGE_GLYPH: \
21321 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21325 case GLYPHLESS_GLYPH: \
21326 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21336 set_glyph_string_background_width (s, START, LAST_X); \
21343 /* Draw glyphs between START and END in AREA of ROW on window W,
21344 starting at x-position X. X is relative to AREA in W. HL is a
21345 face-override with the following meaning:
21347 DRAW_NORMAL_TEXT draw normally
21348 DRAW_CURSOR draw in cursor face
21349 DRAW_MOUSE_FACE draw in mouse face.
21350 DRAW_INVERSE_VIDEO draw in mode line face
21351 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21352 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21354 If OVERLAPS is non-zero, draw only the foreground of characters and
21355 clip to the physical height of ROW. Non-zero value also defines
21356 the overlapping part to be drawn:
21358 OVERLAPS_PRED overlap with preceding rows
21359 OVERLAPS_SUCC overlap with succeeding rows
21360 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21361 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21363 Value is the x-position reached, relative to AREA of W. */
21366 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21367 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21368 enum draw_glyphs_face hl
, int overlaps
)
21370 struct glyph_string
*head
, *tail
;
21371 struct glyph_string
*s
;
21372 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21373 int i
, j
, x_reached
, last_x
, area_left
= 0;
21374 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21377 ALLOCATE_HDC (hdc
, f
);
21379 /* Let's rather be paranoid than getting a SEGV. */
21380 end
= min (end
, row
->used
[area
]);
21381 start
= max (0, start
);
21382 start
= min (end
, start
);
21384 /* Translate X to frame coordinates. Set last_x to the right
21385 end of the drawing area. */
21386 if (row
->full_width_p
)
21388 /* X is relative to the left edge of W, without scroll bars
21390 area_left
= WINDOW_LEFT_EDGE_X (w
);
21391 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21395 area_left
= window_box_left (w
, area
);
21396 last_x
= area_left
+ window_box_width (w
, area
);
21400 /* Build a doubly-linked list of glyph_string structures between
21401 head and tail from what we have to draw. Note that the macro
21402 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21403 the reason we use a separate variable `i'. */
21405 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21407 x_reached
= tail
->x
+ tail
->background_width
;
21411 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21412 the row, redraw some glyphs in front or following the glyph
21413 strings built above. */
21414 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21416 struct glyph_string
*h
, *t
;
21417 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21418 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
21419 int check_mouse_face
= 0;
21422 /* If mouse highlighting is on, we may need to draw adjacent
21423 glyphs using mouse-face highlighting. */
21424 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21426 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21428 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21429 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21431 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21433 check_mouse_face
= 1;
21434 mouse_beg_col
= (row
== mouse_beg_row
)
21435 ? hlinfo
->mouse_face_beg_col
: 0;
21436 mouse_end_col
= (row
== mouse_end_row
)
21437 ? hlinfo
->mouse_face_end_col
21438 : row
->used
[TEXT_AREA
];
21442 /* Compute overhangs for all glyph strings. */
21443 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21444 for (s
= head
; s
; s
= s
->next
)
21445 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21447 /* Prepend glyph strings for glyphs in front of the first glyph
21448 string that are overwritten because of the first glyph
21449 string's left overhang. The background of all strings
21450 prepended must be drawn because the first glyph string
21452 i
= left_overwritten (head
);
21455 enum draw_glyphs_face overlap_hl
;
21457 /* If this row contains mouse highlighting, attempt to draw
21458 the overlapped glyphs with the correct highlight. This
21459 code fails if the overlap encompasses more than one glyph
21460 and mouse-highlight spans only some of these glyphs.
21461 However, making it work perfectly involves a lot more
21462 code, and I don't know if the pathological case occurs in
21463 practice, so we'll stick to this for now. --- cyd */
21464 if (check_mouse_face
21465 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21466 overlap_hl
= DRAW_MOUSE_FACE
;
21468 overlap_hl
= DRAW_NORMAL_TEXT
;
21471 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21472 overlap_hl
, dummy_x
, last_x
);
21474 compute_overhangs_and_x (t
, head
->x
, 1);
21475 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21479 /* Prepend glyph strings for glyphs in front of the first glyph
21480 string that overwrite that glyph string because of their
21481 right overhang. For these strings, only the foreground must
21482 be drawn, because it draws over the glyph string at `head'.
21483 The background must not be drawn because this would overwrite
21484 right overhangs of preceding glyphs for which no glyph
21486 i
= left_overwriting (head
);
21489 enum draw_glyphs_face overlap_hl
;
21491 if (check_mouse_face
21492 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21493 overlap_hl
= DRAW_MOUSE_FACE
;
21495 overlap_hl
= DRAW_NORMAL_TEXT
;
21498 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21499 overlap_hl
, dummy_x
, last_x
);
21500 for (s
= h
; s
; s
= s
->next
)
21501 s
->background_filled_p
= 1;
21502 compute_overhangs_and_x (t
, head
->x
, 1);
21503 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21506 /* Append glyphs strings for glyphs following the last glyph
21507 string tail that are overwritten by tail. The background of
21508 these strings has to be drawn because tail's foreground draws
21510 i
= right_overwritten (tail
);
21513 enum draw_glyphs_face overlap_hl
;
21515 if (check_mouse_face
21516 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21517 overlap_hl
= DRAW_MOUSE_FACE
;
21519 overlap_hl
= DRAW_NORMAL_TEXT
;
21521 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21522 overlap_hl
, x
, last_x
);
21523 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21524 we don't have `end = i;' here. */
21525 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21526 append_glyph_string_lists (&head
, &tail
, h
, t
);
21530 /* Append glyph strings for glyphs following the last glyph
21531 string tail that overwrite tail. The foreground of such
21532 glyphs has to be drawn because it writes into the background
21533 of tail. The background must not be drawn because it could
21534 paint over the foreground of following glyphs. */
21535 i
= right_overwriting (tail
);
21538 enum draw_glyphs_face overlap_hl
;
21539 if (check_mouse_face
21540 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21541 overlap_hl
= DRAW_MOUSE_FACE
;
21543 overlap_hl
= DRAW_NORMAL_TEXT
;
21546 i
++; /* We must include the Ith glyph. */
21547 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21548 overlap_hl
, x
, last_x
);
21549 for (s
= h
; s
; s
= s
->next
)
21550 s
->background_filled_p
= 1;
21551 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21552 append_glyph_string_lists (&head
, &tail
, h
, t
);
21554 if (clip_head
|| clip_tail
)
21555 for (s
= head
; s
; s
= s
->next
)
21557 s
->clip_head
= clip_head
;
21558 s
->clip_tail
= clip_tail
;
21562 /* Draw all strings. */
21563 for (s
= head
; s
; s
= s
->next
)
21564 FRAME_RIF (f
)->draw_glyph_string (s
);
21567 /* When focus a sole frame and move horizontally, this sets on_p to 0
21568 causing a failure to erase prev cursor position. */
21569 if (area
== TEXT_AREA
21570 && !row
->full_width_p
21571 /* When drawing overlapping rows, only the glyph strings'
21572 foreground is drawn, which doesn't erase a cursor
21576 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21577 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21578 : (tail
? tail
->x
+ tail
->background_width
: x
));
21582 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21583 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21587 /* Value is the x-position up to which drawn, relative to AREA of W.
21588 This doesn't include parts drawn because of overhangs. */
21589 if (row
->full_width_p
)
21590 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21592 x_reached
-= area_left
;
21594 RELEASE_HDC (hdc
, f
);
21599 /* Expand row matrix if too narrow. Don't expand if area
21602 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21604 if (!fonts_changed_p \
21605 && (it->glyph_row->glyphs[area] \
21606 < it->glyph_row->glyphs[area + 1])) \
21608 it->w->ncols_scale_factor++; \
21609 fonts_changed_p = 1; \
21613 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21614 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21617 append_glyph (struct it
*it
)
21619 struct glyph
*glyph
;
21620 enum glyph_row_area area
= it
->area
;
21622 xassert (it
->glyph_row
);
21623 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21625 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21626 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21628 /* If the glyph row is reversed, we need to prepend the glyph
21629 rather than append it. */
21630 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21634 /* Make room for the additional glyph. */
21635 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21637 glyph
= it
->glyph_row
->glyphs
[area
];
21639 glyph
->charpos
= CHARPOS (it
->position
);
21640 glyph
->object
= it
->object
;
21641 if (it
->pixel_width
> 0)
21643 glyph
->pixel_width
= it
->pixel_width
;
21644 glyph
->padding_p
= 0;
21648 /* Assure at least 1-pixel width. Otherwise, cursor can't
21649 be displayed correctly. */
21650 glyph
->pixel_width
= 1;
21651 glyph
->padding_p
= 1;
21653 glyph
->ascent
= it
->ascent
;
21654 glyph
->descent
= it
->descent
;
21655 glyph
->voffset
= it
->voffset
;
21656 glyph
->type
= CHAR_GLYPH
;
21657 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21658 glyph
->multibyte_p
= it
->multibyte_p
;
21659 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21660 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21661 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21662 || it
->phys_descent
> it
->descent
);
21663 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21664 glyph
->face_id
= it
->face_id
;
21665 glyph
->u
.ch
= it
->char_to_display
;
21666 glyph
->slice
.img
= null_glyph_slice
;
21667 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21670 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21671 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21673 glyph
->bidi_type
= it
->bidi_it
.type
;
21677 glyph
->resolved_level
= 0;
21678 glyph
->bidi_type
= UNKNOWN_BT
;
21680 ++it
->glyph_row
->used
[area
];
21683 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21686 /* Store one glyph for the composition IT->cmp_it.id in
21687 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21691 append_composite_glyph (struct it
*it
)
21693 struct glyph
*glyph
;
21694 enum glyph_row_area area
= it
->area
;
21696 xassert (it
->glyph_row
);
21698 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21699 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21701 /* If the glyph row is reversed, we need to prepend the glyph
21702 rather than append it. */
21703 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
21707 /* Make room for the new glyph. */
21708 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
21710 glyph
= it
->glyph_row
->glyphs
[it
->area
];
21712 glyph
->charpos
= it
->cmp_it
.charpos
;
21713 glyph
->object
= it
->object
;
21714 glyph
->pixel_width
= it
->pixel_width
;
21715 glyph
->ascent
= it
->ascent
;
21716 glyph
->descent
= it
->descent
;
21717 glyph
->voffset
= it
->voffset
;
21718 glyph
->type
= COMPOSITE_GLYPH
;
21719 if (it
->cmp_it
.ch
< 0)
21721 glyph
->u
.cmp
.automatic
= 0;
21722 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21723 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
21727 glyph
->u
.cmp
.automatic
= 1;
21728 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21729 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
21730 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
21732 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21733 glyph
->multibyte_p
= it
->multibyte_p
;
21734 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21735 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21736 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21737 || it
->phys_descent
> it
->descent
);
21738 glyph
->padding_p
= 0;
21739 glyph
->glyph_not_available_p
= 0;
21740 glyph
->face_id
= it
->face_id
;
21741 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21744 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21745 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21747 glyph
->bidi_type
= it
->bidi_it
.type
;
21749 ++it
->glyph_row
->used
[area
];
21752 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21756 /* Change IT->ascent and IT->height according to the setting of
21760 take_vertical_position_into_account (struct it
*it
)
21764 if (it
->voffset
< 0)
21765 /* Increase the ascent so that we can display the text higher
21767 it
->ascent
-= it
->voffset
;
21769 /* Increase the descent so that we can display the text lower
21771 it
->descent
+= it
->voffset
;
21776 /* Produce glyphs/get display metrics for the image IT is loaded with.
21777 See the description of struct display_iterator in dispextern.h for
21778 an overview of struct display_iterator. */
21781 produce_image_glyph (struct it
*it
)
21785 int glyph_ascent
, crop
;
21786 struct glyph_slice slice
;
21788 xassert (it
->what
== IT_IMAGE
);
21790 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21792 /* Make sure X resources of the face is loaded. */
21793 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21795 if (it
->image_id
< 0)
21797 /* Fringe bitmap. */
21798 it
->ascent
= it
->phys_ascent
= 0;
21799 it
->descent
= it
->phys_descent
= 0;
21800 it
->pixel_width
= 0;
21805 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21807 /* Make sure X resources of the image is loaded. */
21808 prepare_image_for_display (it
->f
, img
);
21810 slice
.x
= slice
.y
= 0;
21811 slice
.width
= img
->width
;
21812 slice
.height
= img
->height
;
21814 if (INTEGERP (it
->slice
.x
))
21815 slice
.x
= XINT (it
->slice
.x
);
21816 else if (FLOATP (it
->slice
.x
))
21817 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21819 if (INTEGERP (it
->slice
.y
))
21820 slice
.y
= XINT (it
->slice
.y
);
21821 else if (FLOATP (it
->slice
.y
))
21822 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21824 if (INTEGERP (it
->slice
.width
))
21825 slice
.width
= XINT (it
->slice
.width
);
21826 else if (FLOATP (it
->slice
.width
))
21827 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21829 if (INTEGERP (it
->slice
.height
))
21830 slice
.height
= XINT (it
->slice
.height
);
21831 else if (FLOATP (it
->slice
.height
))
21832 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21834 if (slice
.x
>= img
->width
)
21835 slice
.x
= img
->width
;
21836 if (slice
.y
>= img
->height
)
21837 slice
.y
= img
->height
;
21838 if (slice
.x
+ slice
.width
>= img
->width
)
21839 slice
.width
= img
->width
- slice
.x
;
21840 if (slice
.y
+ slice
.height
> img
->height
)
21841 slice
.height
= img
->height
- slice
.y
;
21843 if (slice
.width
== 0 || slice
.height
== 0)
21846 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21848 it
->descent
= slice
.height
- glyph_ascent
;
21850 it
->descent
+= img
->vmargin
;
21851 if (slice
.y
+ slice
.height
== img
->height
)
21852 it
->descent
+= img
->vmargin
;
21853 it
->phys_descent
= it
->descent
;
21855 it
->pixel_width
= slice
.width
;
21857 it
->pixel_width
+= img
->hmargin
;
21858 if (slice
.x
+ slice
.width
== img
->width
)
21859 it
->pixel_width
+= img
->hmargin
;
21861 /* It's quite possible for images to have an ascent greater than
21862 their height, so don't get confused in that case. */
21863 if (it
->descent
< 0)
21868 if (face
->box
!= FACE_NO_BOX
)
21870 if (face
->box_line_width
> 0)
21873 it
->ascent
+= face
->box_line_width
;
21874 if (slice
.y
+ slice
.height
== img
->height
)
21875 it
->descent
+= face
->box_line_width
;
21878 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21879 it
->pixel_width
+= eabs (face
->box_line_width
);
21880 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21881 it
->pixel_width
+= eabs (face
->box_line_width
);
21884 take_vertical_position_into_account (it
);
21886 /* Automatically crop wide image glyphs at right edge so we can
21887 draw the cursor on same display row. */
21888 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21889 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21891 it
->pixel_width
-= crop
;
21892 slice
.width
-= crop
;
21897 struct glyph
*glyph
;
21898 enum glyph_row_area area
= it
->area
;
21900 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21901 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21903 glyph
->charpos
= CHARPOS (it
->position
);
21904 glyph
->object
= it
->object
;
21905 glyph
->pixel_width
= it
->pixel_width
;
21906 glyph
->ascent
= glyph_ascent
;
21907 glyph
->descent
= it
->descent
;
21908 glyph
->voffset
= it
->voffset
;
21909 glyph
->type
= IMAGE_GLYPH
;
21910 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21911 glyph
->multibyte_p
= it
->multibyte_p
;
21912 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21913 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21914 glyph
->overlaps_vertically_p
= 0;
21915 glyph
->padding_p
= 0;
21916 glyph
->glyph_not_available_p
= 0;
21917 glyph
->face_id
= it
->face_id
;
21918 glyph
->u
.img_id
= img
->id
;
21919 glyph
->slice
.img
= slice
;
21920 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21923 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21924 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21926 glyph
->bidi_type
= it
->bidi_it
.type
;
21928 ++it
->glyph_row
->used
[area
];
21931 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21936 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21937 of the glyph, WIDTH and HEIGHT are the width and height of the
21938 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21941 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
21942 int width
, int height
, int ascent
)
21944 struct glyph
*glyph
;
21945 enum glyph_row_area area
= it
->area
;
21947 xassert (ascent
>= 0 && ascent
<= height
);
21949 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21950 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21952 /* If the glyph row is reversed, we need to prepend the glyph
21953 rather than append it. */
21954 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21958 /* Make room for the additional glyph. */
21959 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21961 glyph
= it
->glyph_row
->glyphs
[area
];
21963 glyph
->charpos
= CHARPOS (it
->position
);
21964 glyph
->object
= object
;
21965 glyph
->pixel_width
= width
;
21966 glyph
->ascent
= ascent
;
21967 glyph
->descent
= height
- ascent
;
21968 glyph
->voffset
= it
->voffset
;
21969 glyph
->type
= STRETCH_GLYPH
;
21970 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21971 glyph
->multibyte_p
= it
->multibyte_p
;
21972 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21973 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21974 glyph
->overlaps_vertically_p
= 0;
21975 glyph
->padding_p
= 0;
21976 glyph
->glyph_not_available_p
= 0;
21977 glyph
->face_id
= it
->face_id
;
21978 glyph
->u
.stretch
.ascent
= ascent
;
21979 glyph
->u
.stretch
.height
= height
;
21980 glyph
->slice
.img
= null_glyph_slice
;
21981 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21984 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21985 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21987 glyph
->bidi_type
= it
->bidi_it
.type
;
21991 glyph
->resolved_level
= 0;
21992 glyph
->bidi_type
= UNKNOWN_BT
;
21994 ++it
->glyph_row
->used
[area
];
21997 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22001 /* Produce a stretch glyph for iterator IT. IT->object is the value
22002 of the glyph property displayed. The value must be a list
22003 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22006 1. `:width WIDTH' specifies that the space should be WIDTH *
22007 canonical char width wide. WIDTH may be an integer or floating
22010 2. `:relative-width FACTOR' specifies that the width of the stretch
22011 should be computed from the width of the first character having the
22012 `glyph' property, and should be FACTOR times that width.
22014 3. `:align-to HPOS' specifies that the space should be wide enough
22015 to reach HPOS, a value in canonical character units.
22017 Exactly one of the above pairs must be present.
22019 4. `:height HEIGHT' specifies that the height of the stretch produced
22020 should be HEIGHT, measured in canonical character units.
22022 5. `:relative-height FACTOR' specifies that the height of the
22023 stretch should be FACTOR times the height of the characters having
22024 the glyph property.
22026 Either none or exactly one of 4 or 5 must be present.
22028 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22029 of the stretch should be used for the ascent of the stretch.
22030 ASCENT must be in the range 0 <= ASCENT <= 100. */
22033 produce_stretch_glyph (struct it
*it
)
22035 /* (space :width WIDTH :height HEIGHT ...) */
22036 Lisp_Object prop
, plist
;
22037 int width
= 0, height
= 0, align_to
= -1;
22038 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22041 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22042 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22044 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22046 /* List should start with `space'. */
22047 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22048 plist
= XCDR (it
->object
);
22050 /* Compute the width of the stretch. */
22051 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22052 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22054 /* Absolute width `:width WIDTH' specified and valid. */
22055 zero_width_ok_p
= 1;
22058 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22061 /* Relative width `:relative-width FACTOR' specified and valid.
22062 Compute the width of the characters having the `glyph'
22065 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22068 if (it
->multibyte_p
)
22069 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22072 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22073 if (! ASCII_CHAR_P (it2
.c
))
22074 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22077 it2
.glyph_row
= NULL
;
22078 it2
.what
= IT_CHARACTER
;
22079 x_produce_glyphs (&it2
);
22080 width
= NUMVAL (prop
) * it2
.pixel_width
;
22082 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22083 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22085 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22086 align_to
= (align_to
< 0
22088 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22089 else if (align_to
< 0)
22090 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22091 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22092 zero_width_ok_p
= 1;
22095 /* Nothing specified -> width defaults to canonical char width. */
22096 width
= FRAME_COLUMN_WIDTH (it
->f
);
22098 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22101 /* Compute height. */
22102 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22103 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22106 zero_height_ok_p
= 1;
22108 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22110 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22112 height
= FONT_HEIGHT (font
);
22114 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22117 /* Compute percentage of height used for ascent. If
22118 `:ascent ASCENT' is present and valid, use that. Otherwise,
22119 derive the ascent from the font in use. */
22120 if (prop
= Fplist_get (plist
, QCascent
),
22121 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22122 ascent
= height
* NUMVAL (prop
) / 100.0;
22123 else if (!NILP (prop
)
22124 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22125 ascent
= min (max (0, (int)tem
), height
);
22127 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22129 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22130 && it
->current_x
+ width
> it
->last_visible_x
)
22131 width
= it
->last_visible_x
- it
->current_x
- 1;
22133 if (width
> 0 && height
> 0 && it
->glyph_row
)
22135 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22136 if (!STRINGP (object
))
22137 object
= it
->w
->buffer
;
22138 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22141 it
->pixel_width
= width
;
22142 it
->ascent
= it
->phys_ascent
= ascent
;
22143 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22144 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22146 take_vertical_position_into_account (it
);
22149 /* Calculate line-height and line-spacing properties.
22150 An integer value specifies explicit pixel value.
22151 A float value specifies relative value to current face height.
22152 A cons (float . face-name) specifies relative value to
22153 height of specified face font.
22155 Returns height in pixels, or nil. */
22159 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22160 int boff
, int override
)
22162 Lisp_Object face_name
= Qnil
;
22163 int ascent
, descent
, height
;
22165 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22170 face_name
= XCAR (val
);
22172 if (!NUMBERP (val
))
22173 val
= make_number (1);
22174 if (NILP (face_name
))
22176 height
= it
->ascent
+ it
->descent
;
22181 if (NILP (face_name
))
22183 font
= FRAME_FONT (it
->f
);
22184 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22186 else if (EQ (face_name
, Qt
))
22195 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22197 return make_number (-1);
22199 face
= FACE_FROM_ID (it
->f
, face_id
);
22202 return make_number (-1);
22203 boff
= font
->baseline_offset
;
22204 if (font
->vertical_centering
)
22205 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22208 ascent
= FONT_BASE (font
) + boff
;
22209 descent
= FONT_DESCENT (font
) - boff
;
22213 it
->override_ascent
= ascent
;
22214 it
->override_descent
= descent
;
22215 it
->override_boff
= boff
;
22218 height
= ascent
+ descent
;
22222 height
= (int)(XFLOAT_DATA (val
) * height
);
22223 else if (INTEGERP (val
))
22224 height
*= XINT (val
);
22226 return make_number (height
);
22230 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22231 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22232 and only if this is for a character for which no font was found.
22234 If the display method (it->glyphless_method) is
22235 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22236 length of the acronym or the hexadecimal string, UPPER_XOFF and
22237 UPPER_YOFF are pixel offsets for the upper part of the string,
22238 LOWER_XOFF and LOWER_YOFF are for the lower part.
22240 For the other display methods, LEN through LOWER_YOFF are zero. */
22243 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22244 short upper_xoff
, short upper_yoff
,
22245 short lower_xoff
, short lower_yoff
)
22247 struct glyph
*glyph
;
22248 enum glyph_row_area area
= it
->area
;
22250 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22251 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22253 /* If the glyph row is reversed, we need to prepend the glyph
22254 rather than append it. */
22255 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22259 /* Make room for the additional glyph. */
22260 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22262 glyph
= it
->glyph_row
->glyphs
[area
];
22264 glyph
->charpos
= CHARPOS (it
->position
);
22265 glyph
->object
= it
->object
;
22266 glyph
->pixel_width
= it
->pixel_width
;
22267 glyph
->ascent
= it
->ascent
;
22268 glyph
->descent
= it
->descent
;
22269 glyph
->voffset
= it
->voffset
;
22270 glyph
->type
= GLYPHLESS_GLYPH
;
22271 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22272 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22273 glyph
->u
.glyphless
.len
= len
;
22274 glyph
->u
.glyphless
.ch
= it
->c
;
22275 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22276 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22277 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22278 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22279 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22280 glyph
->multibyte_p
= it
->multibyte_p
;
22281 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22282 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22283 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22284 || it
->phys_descent
> it
->descent
);
22285 glyph
->padding_p
= 0;
22286 glyph
->glyph_not_available_p
= 0;
22287 glyph
->face_id
= face_id
;
22288 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22291 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22292 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22294 glyph
->bidi_type
= it
->bidi_it
.type
;
22296 ++it
->glyph_row
->used
[area
];
22299 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22303 /* Produce a glyph for a glyphless character for iterator IT.
22304 IT->glyphless_method specifies which method to use for displaying
22305 the character. See the description of enum
22306 glyphless_display_method in dispextern.h for the detail.
22308 FOR_NO_FONT is nonzero if and only if this is for a character for
22309 which no font was found. ACRONYM, if non-nil, is an acronym string
22310 for the character. */
22313 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22318 int base_width
, base_height
, width
, height
;
22319 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22322 /* Get the metrics of the base font. We always refer to the current
22324 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22325 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22326 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22327 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22328 base_height
= it
->ascent
+ it
->descent
;
22329 base_width
= font
->average_width
;
22331 /* Get a face ID for the glyph by utilizing a cache (the same way as
22332 doen for `escape-glyph' in get_next_display_element). */
22333 if (it
->f
== last_glyphless_glyph_frame
22334 && it
->face_id
== last_glyphless_glyph_face_id
)
22336 face_id
= last_glyphless_glyph_merged_face_id
;
22340 /* Merge the `glyphless-char' face into the current face. */
22341 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22342 last_glyphless_glyph_frame
= it
->f
;
22343 last_glyphless_glyph_face_id
= it
->face_id
;
22344 last_glyphless_glyph_merged_face_id
= face_id
;
22347 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22349 it
->pixel_width
= THIN_SPACE_WIDTH
;
22351 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22353 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22355 width
= CHAR_WIDTH (it
->c
);
22358 else if (width
> 4)
22360 it
->pixel_width
= base_width
* width
;
22362 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22368 unsigned int code
[6];
22370 int ascent
, descent
;
22371 struct font_metrics metrics_upper
, metrics_lower
;
22373 face
= FACE_FROM_ID (it
->f
, face_id
);
22374 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22375 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22377 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22379 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22380 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22381 if (CONSP (acronym
))
22382 acronym
= XCAR (acronym
);
22383 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
22387 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22388 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22391 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22392 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22393 upper_len
= (len
+ 1) / 2;
22394 font
->driver
->text_extents (font
, code
, upper_len
,
22396 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22401 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22402 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22403 upper_xoff
= upper_yoff
= 2; /* the typical case */
22404 if (base_width
>= width
)
22406 /* Align the upper to the left, the lower to the right. */
22407 it
->pixel_width
= base_width
;
22408 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22412 /* Center the shorter one. */
22413 it
->pixel_width
= width
;
22414 if (metrics_upper
.width
>= metrics_lower
.width
)
22415 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22418 /* FIXME: This code doesn't look right. It formerly was
22419 missing the "lower_xoff = 0;", which couldn't have
22420 been right since it left lower_xoff uninitialized. */
22422 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22426 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22427 top, bottom, and between upper and lower strings. */
22428 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22429 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22430 /* Center vertically.
22431 H:base_height, D:base_descent
22432 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22434 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22435 descent = D - H/2 + h/2;
22436 lower_yoff = descent - 2 - ld;
22437 upper_yoff = lower_yoff - la - 1 - ud; */
22438 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22439 descent
= it
->descent
- (base_height
- height
) / 2;
22440 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22441 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22442 - metrics_upper
.descent
);
22443 /* Don't make the height shorter than the base height. */
22444 if (height
> base_height
)
22446 it
->ascent
= ascent
;
22447 it
->descent
= descent
;
22451 it
->phys_ascent
= it
->ascent
;
22452 it
->phys_descent
= it
->descent
;
22454 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22455 upper_xoff
, upper_yoff
,
22456 lower_xoff
, lower_yoff
);
22458 take_vertical_position_into_account (it
);
22463 Produce glyphs/get display metrics for the display element IT is
22464 loaded with. See the description of struct it in dispextern.h
22465 for an overview of struct it. */
22468 x_produce_glyphs (struct it
*it
)
22470 int extra_line_spacing
= it
->extra_line_spacing
;
22472 it
->glyph_not_available_p
= 0;
22474 if (it
->what
== IT_CHARACTER
)
22477 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22478 struct font
*font
= face
->font
;
22479 struct font_metrics
*pcm
= NULL
;
22480 int boff
; /* baseline offset */
22484 /* When no suitable font is found, display this character by
22485 the method specified in the first extra slot of
22486 Vglyphless_char_display. */
22487 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22489 xassert (it
->what
== IT_GLYPHLESS
);
22490 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22494 boff
= font
->baseline_offset
;
22495 if (font
->vertical_centering
)
22496 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22498 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22504 if (it
->override_ascent
>= 0)
22506 it
->ascent
= it
->override_ascent
;
22507 it
->descent
= it
->override_descent
;
22508 boff
= it
->override_boff
;
22512 it
->ascent
= FONT_BASE (font
) + boff
;
22513 it
->descent
= FONT_DESCENT (font
) - boff
;
22516 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22518 pcm
= get_per_char_metric (font
, &char2b
);
22519 if (pcm
->width
== 0
22520 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22526 it
->phys_ascent
= pcm
->ascent
+ boff
;
22527 it
->phys_descent
= pcm
->descent
- boff
;
22528 it
->pixel_width
= pcm
->width
;
22532 it
->glyph_not_available_p
= 1;
22533 it
->phys_ascent
= it
->ascent
;
22534 it
->phys_descent
= it
->descent
;
22535 it
->pixel_width
= font
->space_width
;
22538 if (it
->constrain_row_ascent_descent_p
)
22540 if (it
->descent
> it
->max_descent
)
22542 it
->ascent
+= it
->descent
- it
->max_descent
;
22543 it
->descent
= it
->max_descent
;
22545 if (it
->ascent
> it
->max_ascent
)
22547 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22548 it
->ascent
= it
->max_ascent
;
22550 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22551 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22552 extra_line_spacing
= 0;
22555 /* If this is a space inside a region of text with
22556 `space-width' property, change its width. */
22557 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22559 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22561 /* If face has a box, add the box thickness to the character
22562 height. If character has a box line to the left and/or
22563 right, add the box line width to the character's width. */
22564 if (face
->box
!= FACE_NO_BOX
)
22566 int thick
= face
->box_line_width
;
22570 it
->ascent
+= thick
;
22571 it
->descent
+= thick
;
22576 if (it
->start_of_box_run_p
)
22577 it
->pixel_width
+= thick
;
22578 if (it
->end_of_box_run_p
)
22579 it
->pixel_width
+= thick
;
22582 /* If face has an overline, add the height of the overline
22583 (1 pixel) and a 1 pixel margin to the character height. */
22584 if (face
->overline_p
)
22585 it
->ascent
+= overline_margin
;
22587 if (it
->constrain_row_ascent_descent_p
)
22589 if (it
->ascent
> it
->max_ascent
)
22590 it
->ascent
= it
->max_ascent
;
22591 if (it
->descent
> it
->max_descent
)
22592 it
->descent
= it
->max_descent
;
22595 take_vertical_position_into_account (it
);
22597 /* If we have to actually produce glyphs, do it. */
22602 /* Translate a space with a `space-width' property
22603 into a stretch glyph. */
22604 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22605 / FONT_HEIGHT (font
));
22606 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22607 it
->ascent
+ it
->descent
, ascent
);
22612 /* If characters with lbearing or rbearing are displayed
22613 in this line, record that fact in a flag of the
22614 glyph row. This is used to optimize X output code. */
22615 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22616 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22618 if (! stretched_p
&& it
->pixel_width
== 0)
22619 /* We assure that all visible glyphs have at least 1-pixel
22621 it
->pixel_width
= 1;
22623 else if (it
->char_to_display
== '\n')
22625 /* A newline has no width, but we need the height of the
22626 line. But if previous part of the line sets a height,
22627 don't increase that height */
22629 Lisp_Object height
;
22630 Lisp_Object total_height
= Qnil
;
22632 it
->override_ascent
= -1;
22633 it
->pixel_width
= 0;
22636 height
= get_it_property (it
, Qline_height
);
22637 /* Split (line-height total-height) list */
22639 && CONSP (XCDR (height
))
22640 && NILP (XCDR (XCDR (height
))))
22642 total_height
= XCAR (XCDR (height
));
22643 height
= XCAR (height
);
22645 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
22647 if (it
->override_ascent
>= 0)
22649 it
->ascent
= it
->override_ascent
;
22650 it
->descent
= it
->override_descent
;
22651 boff
= it
->override_boff
;
22655 it
->ascent
= FONT_BASE (font
) + boff
;
22656 it
->descent
= FONT_DESCENT (font
) - boff
;
22659 if (EQ (height
, Qt
))
22661 if (it
->descent
> it
->max_descent
)
22663 it
->ascent
+= it
->descent
- it
->max_descent
;
22664 it
->descent
= it
->max_descent
;
22666 if (it
->ascent
> it
->max_ascent
)
22668 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22669 it
->ascent
= it
->max_ascent
;
22671 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22672 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22673 it
->constrain_row_ascent_descent_p
= 1;
22674 extra_line_spacing
= 0;
22678 Lisp_Object spacing
;
22680 it
->phys_ascent
= it
->ascent
;
22681 it
->phys_descent
= it
->descent
;
22683 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22684 && face
->box
!= FACE_NO_BOX
22685 && face
->box_line_width
> 0)
22687 it
->ascent
+= face
->box_line_width
;
22688 it
->descent
+= face
->box_line_width
;
22691 && XINT (height
) > it
->ascent
+ it
->descent
)
22692 it
->ascent
= XINT (height
) - it
->descent
;
22694 if (!NILP (total_height
))
22695 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
22698 spacing
= get_it_property (it
, Qline_spacing
);
22699 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
22701 if (INTEGERP (spacing
))
22703 extra_line_spacing
= XINT (spacing
);
22704 if (!NILP (total_height
))
22705 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22709 else /* i.e. (it->char_to_display == '\t') */
22711 if (font
->space_width
> 0)
22713 int tab_width
= it
->tab_width
* font
->space_width
;
22714 int x
= it
->current_x
+ it
->continuation_lines_width
;
22715 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22717 /* If the distance from the current position to the next tab
22718 stop is less than a space character width, use the
22719 tab stop after that. */
22720 if (next_tab_x
- x
< font
->space_width
)
22721 next_tab_x
+= tab_width
;
22723 it
->pixel_width
= next_tab_x
- x
;
22725 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22726 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22730 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22731 it
->ascent
+ it
->descent
, it
->ascent
);
22736 it
->pixel_width
= 0;
22741 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22743 /* A static composition.
22745 Note: A composition is represented as one glyph in the
22746 glyph matrix. There are no padding glyphs.
22748 Important note: pixel_width, ascent, and descent are the
22749 values of what is drawn by draw_glyphs (i.e. the values of
22750 the overall glyphs composed). */
22751 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22752 int boff
; /* baseline offset */
22753 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22754 int glyph_len
= cmp
->glyph_len
;
22755 struct font
*font
= face
->font
;
22759 /* If we have not yet calculated pixel size data of glyphs of
22760 the composition for the current face font, calculate them
22761 now. Theoretically, we have to check all fonts for the
22762 glyphs, but that requires much time and memory space. So,
22763 here we check only the font of the first glyph. This may
22764 lead to incorrect display, but it's very rare, and C-l
22765 (recenter-top-bottom) can correct the display anyway. */
22766 if (! cmp
->font
|| cmp
->font
!= font
)
22768 /* Ascent and descent of the font of the first character
22769 of this composition (adjusted by baseline offset).
22770 Ascent and descent of overall glyphs should not be less
22771 than these, respectively. */
22772 int font_ascent
, font_descent
, font_height
;
22773 /* Bounding box of the overall glyphs. */
22774 int leftmost
, rightmost
, lowest
, highest
;
22775 int lbearing
, rbearing
;
22776 int i
, width
, ascent
, descent
;
22777 int left_padded
= 0, right_padded
= 0;
22778 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
22780 struct font_metrics
*pcm
;
22781 int font_not_found_p
;
22784 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22785 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22787 if (glyph_len
< cmp
->glyph_len
)
22789 for (i
= 0; i
< glyph_len
; i
++)
22791 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22793 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22798 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22799 : IT_CHARPOS (*it
));
22800 /* If no suitable font is found, use the default font. */
22801 font_not_found_p
= font
== NULL
;
22802 if (font_not_found_p
)
22804 face
= face
->ascii_face
;
22807 boff
= font
->baseline_offset
;
22808 if (font
->vertical_centering
)
22809 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22810 font_ascent
= FONT_BASE (font
) + boff
;
22811 font_descent
= FONT_DESCENT (font
) - boff
;
22812 font_height
= FONT_HEIGHT (font
);
22814 cmp
->font
= (void *) font
;
22817 if (! font_not_found_p
)
22819 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22821 pcm
= get_per_char_metric (font
, &char2b
);
22824 /* Initialize the bounding box. */
22827 width
= pcm
->width
;
22828 ascent
= pcm
->ascent
;
22829 descent
= pcm
->descent
;
22830 lbearing
= pcm
->lbearing
;
22831 rbearing
= pcm
->rbearing
;
22835 width
= font
->space_width
;
22836 ascent
= FONT_BASE (font
);
22837 descent
= FONT_DESCENT (font
);
22844 lowest
= - descent
+ boff
;
22845 highest
= ascent
+ boff
;
22847 if (! font_not_found_p
22848 && font
->default_ascent
22849 && CHAR_TABLE_P (Vuse_default_ascent
)
22850 && !NILP (Faref (Vuse_default_ascent
,
22851 make_number (it
->char_to_display
))))
22852 highest
= font
->default_ascent
+ boff
;
22854 /* Draw the first glyph at the normal position. It may be
22855 shifted to right later if some other glyphs are drawn
22857 cmp
->offsets
[i
* 2] = 0;
22858 cmp
->offsets
[i
* 2 + 1] = boff
;
22859 cmp
->lbearing
= lbearing
;
22860 cmp
->rbearing
= rbearing
;
22862 /* Set cmp->offsets for the remaining glyphs. */
22863 for (i
++; i
< glyph_len
; i
++)
22865 int left
, right
, btm
, top
;
22866 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22868 struct face
*this_face
;
22872 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22873 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22874 font
= this_face
->font
;
22880 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22882 pcm
= get_per_char_metric (font
, &char2b
);
22885 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22888 width
= pcm
->width
;
22889 ascent
= pcm
->ascent
;
22890 descent
= pcm
->descent
;
22891 lbearing
= pcm
->lbearing
;
22892 rbearing
= pcm
->rbearing
;
22893 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22895 /* Relative composition with or without
22896 alternate chars. */
22897 left
= (leftmost
+ rightmost
- width
) / 2;
22898 btm
= - descent
+ boff
;
22899 if (font
->relative_compose
22900 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22901 || NILP (Faref (Vignore_relative_composition
,
22902 make_number (ch
)))))
22905 if (- descent
>= font
->relative_compose
)
22906 /* One extra pixel between two glyphs. */
22908 else if (ascent
<= 0)
22909 /* One extra pixel between two glyphs. */
22910 btm
= lowest
- 1 - ascent
- descent
;
22915 /* A composition rule is specified by an integer
22916 value that encodes global and new reference
22917 points (GREF and NREF). GREF and NREF are
22918 specified by numbers as below:
22920 0---1---2 -- ascent
22924 9--10--11 -- center
22926 ---3---4---5--- baseline
22928 6---7---8 -- descent
22930 int rule
= COMPOSITION_RULE (cmp
, i
);
22931 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22933 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22934 grefx
= gref
% 3, nrefx
= nref
% 3;
22935 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22937 xoff
= font_height
* (xoff
- 128) / 256;
22939 yoff
= font_height
* (yoff
- 128) / 256;
22942 + grefx
* (rightmost
- leftmost
) / 2
22943 - nrefx
* width
/ 2
22946 btm
= ((grefy
== 0 ? highest
22948 : grefy
== 2 ? lowest
22949 : (highest
+ lowest
) / 2)
22950 - (nrefy
== 0 ? ascent
+ descent
22951 : nrefy
== 1 ? descent
- boff
22953 : (ascent
+ descent
) / 2)
22957 cmp
->offsets
[i
* 2] = left
;
22958 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22960 /* Update the bounding box of the overall glyphs. */
22963 right
= left
+ width
;
22964 if (left
< leftmost
)
22966 if (right
> rightmost
)
22969 top
= btm
+ descent
+ ascent
;
22975 if (cmp
->lbearing
> left
+ lbearing
)
22976 cmp
->lbearing
= left
+ lbearing
;
22977 if (cmp
->rbearing
< left
+ rbearing
)
22978 cmp
->rbearing
= left
+ rbearing
;
22982 /* If there are glyphs whose x-offsets are negative,
22983 shift all glyphs to the right and make all x-offsets
22987 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22988 cmp
->offsets
[i
* 2] -= leftmost
;
22989 rightmost
-= leftmost
;
22990 cmp
->lbearing
-= leftmost
;
22991 cmp
->rbearing
-= leftmost
;
22994 if (left_padded
&& cmp
->lbearing
< 0)
22996 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22997 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22998 rightmost
-= cmp
->lbearing
;
22999 cmp
->rbearing
-= cmp
->lbearing
;
23002 if (right_padded
&& rightmost
< cmp
->rbearing
)
23004 rightmost
= cmp
->rbearing
;
23007 cmp
->pixel_width
= rightmost
;
23008 cmp
->ascent
= highest
;
23009 cmp
->descent
= - lowest
;
23010 if (cmp
->ascent
< font_ascent
)
23011 cmp
->ascent
= font_ascent
;
23012 if (cmp
->descent
< font_descent
)
23013 cmp
->descent
= font_descent
;
23017 && (cmp
->lbearing
< 0
23018 || cmp
->rbearing
> cmp
->pixel_width
))
23019 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23021 it
->pixel_width
= cmp
->pixel_width
;
23022 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23023 it
->descent
= it
->phys_descent
= cmp
->descent
;
23024 if (face
->box
!= FACE_NO_BOX
)
23026 int thick
= face
->box_line_width
;
23030 it
->ascent
+= thick
;
23031 it
->descent
+= thick
;
23036 if (it
->start_of_box_run_p
)
23037 it
->pixel_width
+= thick
;
23038 if (it
->end_of_box_run_p
)
23039 it
->pixel_width
+= thick
;
23042 /* If face has an overline, add the height of the overline
23043 (1 pixel) and a 1 pixel margin to the character height. */
23044 if (face
->overline_p
)
23045 it
->ascent
+= overline_margin
;
23047 take_vertical_position_into_account (it
);
23048 if (it
->ascent
< 0)
23050 if (it
->descent
< 0)
23054 append_composite_glyph (it
);
23056 else if (it
->what
== IT_COMPOSITION
)
23058 /* A dynamic (automatic) composition. */
23059 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23060 Lisp_Object gstring
;
23061 struct font_metrics metrics
;
23063 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23065 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23068 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23069 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23070 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23071 it
->descent
= it
->phys_descent
= metrics
.descent
;
23072 if (face
->box
!= FACE_NO_BOX
)
23074 int thick
= face
->box_line_width
;
23078 it
->ascent
+= thick
;
23079 it
->descent
+= thick
;
23084 if (it
->start_of_box_run_p
)
23085 it
->pixel_width
+= thick
;
23086 if (it
->end_of_box_run_p
)
23087 it
->pixel_width
+= thick
;
23089 /* If face has an overline, add the height of the overline
23090 (1 pixel) and a 1 pixel margin to the character height. */
23091 if (face
->overline_p
)
23092 it
->ascent
+= overline_margin
;
23093 take_vertical_position_into_account (it
);
23094 if (it
->ascent
< 0)
23096 if (it
->descent
< 0)
23100 append_composite_glyph (it
);
23102 else if (it
->what
== IT_GLYPHLESS
)
23103 produce_glyphless_glyph (it
, 0, Qnil
);
23104 else if (it
->what
== IT_IMAGE
)
23105 produce_image_glyph (it
);
23106 else if (it
->what
== IT_STRETCH
)
23107 produce_stretch_glyph (it
);
23110 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23111 because this isn't true for images with `:ascent 100'. */
23112 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23113 if (it
->area
== TEXT_AREA
)
23114 it
->current_x
+= it
->pixel_width
;
23116 if (extra_line_spacing
> 0)
23118 it
->descent
+= extra_line_spacing
;
23119 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23120 it
->max_extra_line_spacing
= extra_line_spacing
;
23123 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23124 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23125 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23126 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23130 Output LEN glyphs starting at START at the nominal cursor position.
23131 Advance the nominal cursor over the text. The global variable
23132 updated_window contains the window being updated, updated_row is
23133 the glyph row being updated, and updated_area is the area of that
23134 row being updated. */
23137 x_write_glyphs (struct glyph
*start
, int len
)
23141 xassert (updated_window
&& updated_row
);
23144 /* Write glyphs. */
23146 hpos
= start
- updated_row
->glyphs
[updated_area
];
23147 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23148 updated_row
, updated_area
,
23150 DRAW_NORMAL_TEXT
, 0);
23152 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23153 if (updated_area
== TEXT_AREA
23154 && updated_window
->phys_cursor_on_p
23155 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23156 && updated_window
->phys_cursor
.hpos
>= hpos
23157 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23158 updated_window
->phys_cursor_on_p
= 0;
23162 /* Advance the output cursor. */
23163 output_cursor
.hpos
+= len
;
23164 output_cursor
.x
= x
;
23169 Insert LEN glyphs from START at the nominal cursor position. */
23172 x_insert_glyphs (struct glyph
*start
, int len
)
23176 int line_height
, shift_by_width
, shifted_region_width
;
23177 struct glyph_row
*row
;
23178 struct glyph
*glyph
;
23179 int frame_x
, frame_y
;
23182 xassert (updated_window
&& updated_row
);
23184 w
= updated_window
;
23185 f
= XFRAME (WINDOW_FRAME (w
));
23187 /* Get the height of the line we are in. */
23189 line_height
= row
->height
;
23191 /* Get the width of the glyphs to insert. */
23192 shift_by_width
= 0;
23193 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23194 shift_by_width
+= glyph
->pixel_width
;
23196 /* Get the width of the region to shift right. */
23197 shifted_region_width
= (window_box_width (w
, updated_area
)
23202 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23203 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23205 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23206 line_height
, shift_by_width
);
23208 /* Write the glyphs. */
23209 hpos
= start
- row
->glyphs
[updated_area
];
23210 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23212 DRAW_NORMAL_TEXT
, 0);
23214 /* Advance the output cursor. */
23215 output_cursor
.hpos
+= len
;
23216 output_cursor
.x
+= shift_by_width
;
23222 Erase the current text line from the nominal cursor position
23223 (inclusive) to pixel column TO_X (exclusive). The idea is that
23224 everything from TO_X onward is already erased.
23226 TO_X is a pixel position relative to updated_area of
23227 updated_window. TO_X == -1 means clear to the end of this area. */
23230 x_clear_end_of_line (int to_x
)
23233 struct window
*w
= updated_window
;
23234 int max_x
, min_y
, max_y
;
23235 int from_x
, from_y
, to_y
;
23237 xassert (updated_window
&& updated_row
);
23238 f
= XFRAME (w
->frame
);
23240 if (updated_row
->full_width_p
)
23241 max_x
= WINDOW_TOTAL_WIDTH (w
);
23243 max_x
= window_box_width (w
, updated_area
);
23244 max_y
= window_text_bottom_y (w
);
23246 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23247 of window. For TO_X > 0, truncate to end of drawing area. */
23253 to_x
= min (to_x
, max_x
);
23255 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23257 /* Notice if the cursor will be cleared by this operation. */
23258 if (!updated_row
->full_width_p
)
23259 notice_overwritten_cursor (w
, updated_area
,
23260 output_cursor
.x
, -1,
23262 MATRIX_ROW_BOTTOM_Y (updated_row
));
23264 from_x
= output_cursor
.x
;
23266 /* Translate to frame coordinates. */
23267 if (updated_row
->full_width_p
)
23269 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23270 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23274 int area_left
= window_box_left (w
, updated_area
);
23275 from_x
+= area_left
;
23279 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23280 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23281 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23283 /* Prevent inadvertently clearing to end of the X window. */
23284 if (to_x
> from_x
&& to_y
> from_y
)
23287 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23288 to_x
- from_x
, to_y
- from_y
);
23293 #endif /* HAVE_WINDOW_SYSTEM */
23297 /***********************************************************************
23299 ***********************************************************************/
23301 /* Value is the internal representation of the specified cursor type
23302 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23303 of the bar cursor. */
23305 static enum text_cursor_kinds
23306 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23308 enum text_cursor_kinds type
;
23313 if (EQ (arg
, Qbox
))
23314 return FILLED_BOX_CURSOR
;
23316 if (EQ (arg
, Qhollow
))
23317 return HOLLOW_BOX_CURSOR
;
23319 if (EQ (arg
, Qbar
))
23326 && EQ (XCAR (arg
), Qbar
)
23327 && INTEGERP (XCDR (arg
))
23328 && XINT (XCDR (arg
)) >= 0)
23330 *width
= XINT (XCDR (arg
));
23334 if (EQ (arg
, Qhbar
))
23337 return HBAR_CURSOR
;
23341 && EQ (XCAR (arg
), Qhbar
)
23342 && INTEGERP (XCDR (arg
))
23343 && XINT (XCDR (arg
)) >= 0)
23345 *width
= XINT (XCDR (arg
));
23346 return HBAR_CURSOR
;
23349 /* Treat anything unknown as "hollow box cursor".
23350 It was bad to signal an error; people have trouble fixing
23351 .Xdefaults with Emacs, when it has something bad in it. */
23352 type
= HOLLOW_BOX_CURSOR
;
23357 /* Set the default cursor types for specified frame. */
23359 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23364 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23365 FRAME_CURSOR_WIDTH (f
) = width
;
23367 /* By default, set up the blink-off state depending on the on-state. */
23369 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23372 FRAME_BLINK_OFF_CURSOR (f
)
23373 = get_specified_cursor_type (XCDR (tem
), &width
);
23374 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23377 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23381 #ifdef HAVE_WINDOW_SYSTEM
23383 /* Return the cursor we want to be displayed in window W. Return
23384 width of bar/hbar cursor through WIDTH arg. Return with
23385 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23386 (i.e. if the `system caret' should track this cursor).
23388 In a mini-buffer window, we want the cursor only to appear if we
23389 are reading input from this window. For the selected window, we
23390 want the cursor type given by the frame parameter or buffer local
23391 setting of cursor-type. If explicitly marked off, draw no cursor.
23392 In all other cases, we want a hollow box cursor. */
23394 static enum text_cursor_kinds
23395 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23396 int *active_cursor
)
23398 struct frame
*f
= XFRAME (w
->frame
);
23399 struct buffer
*b
= XBUFFER (w
->buffer
);
23400 int cursor_type
= DEFAULT_CURSOR
;
23401 Lisp_Object alt_cursor
;
23402 int non_selected
= 0;
23404 *active_cursor
= 1;
23407 if (cursor_in_echo_area
23408 && FRAME_HAS_MINIBUF_P (f
)
23409 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23411 if (w
== XWINDOW (echo_area_window
))
23413 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
23415 *width
= FRAME_CURSOR_WIDTH (f
);
23416 return FRAME_DESIRED_CURSOR (f
);
23419 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23422 *active_cursor
= 0;
23426 /* Detect a nonselected window or nonselected frame. */
23427 else if (w
!= XWINDOW (f
->selected_window
)
23428 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23430 *active_cursor
= 0;
23432 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23438 /* Never display a cursor in a window in which cursor-type is nil. */
23439 if (NILP (BVAR (b
, cursor_type
)))
23442 /* Get the normal cursor type for this window. */
23443 if (EQ (BVAR (b
, cursor_type
), Qt
))
23445 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23446 *width
= FRAME_CURSOR_WIDTH (f
);
23449 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23451 /* Use cursor-in-non-selected-windows instead
23452 for non-selected window or frame. */
23455 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
23456 if (!EQ (Qt
, alt_cursor
))
23457 return get_specified_cursor_type (alt_cursor
, width
);
23458 /* t means modify the normal cursor type. */
23459 if (cursor_type
== FILLED_BOX_CURSOR
)
23460 cursor_type
= HOLLOW_BOX_CURSOR
;
23461 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23463 return cursor_type
;
23466 /* Use normal cursor if not blinked off. */
23467 if (!w
->cursor_off_p
)
23469 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23471 if (cursor_type
== FILLED_BOX_CURSOR
)
23473 /* Using a block cursor on large images can be very annoying.
23474 So use a hollow cursor for "large" images.
23475 If image is not transparent (no mask), also use hollow cursor. */
23476 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23477 if (img
!= NULL
&& IMAGEP (img
->spec
))
23479 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23480 where N = size of default frame font size.
23481 This should cover most of the "tiny" icons people may use. */
23483 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23484 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23485 cursor_type
= HOLLOW_BOX_CURSOR
;
23488 else if (cursor_type
!= NO_CURSOR
)
23490 /* Display current only supports BOX and HOLLOW cursors for images.
23491 So for now, unconditionally use a HOLLOW cursor when cursor is
23492 not a solid box cursor. */
23493 cursor_type
= HOLLOW_BOX_CURSOR
;
23496 return cursor_type
;
23499 /* Cursor is blinked off, so determine how to "toggle" it. */
23501 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23502 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
23503 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23505 /* Then see if frame has specified a specific blink off cursor type. */
23506 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23508 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23509 return FRAME_BLINK_OFF_CURSOR (f
);
23513 /* Some people liked having a permanently visible blinking cursor,
23514 while others had very strong opinions against it. So it was
23515 decided to remove it. KFS 2003-09-03 */
23517 /* Finally perform built-in cursor blinking:
23518 filled box <-> hollow box
23519 wide [h]bar <-> narrow [h]bar
23520 narrow [h]bar <-> no cursor
23521 other type <-> no cursor */
23523 if (cursor_type
== FILLED_BOX_CURSOR
)
23524 return HOLLOW_BOX_CURSOR
;
23526 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23529 return cursor_type
;
23537 /* Notice when the text cursor of window W has been completely
23538 overwritten by a drawing operation that outputs glyphs in AREA
23539 starting at X0 and ending at X1 in the line starting at Y0 and
23540 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23541 the rest of the line after X0 has been written. Y coordinates
23542 are window-relative. */
23545 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23546 int x0
, int x1
, int y0
, int y1
)
23548 int cx0
, cx1
, cy0
, cy1
;
23549 struct glyph_row
*row
;
23551 if (!w
->phys_cursor_on_p
)
23553 if (area
!= TEXT_AREA
)
23556 if (w
->phys_cursor
.vpos
< 0
23557 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23558 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23559 !(row
->enabled_p
&& row
->displays_text_p
)))
23562 if (row
->cursor_in_fringe_p
)
23564 row
->cursor_in_fringe_p
= 0;
23565 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23566 w
->phys_cursor_on_p
= 0;
23570 cx0
= w
->phys_cursor
.x
;
23571 cx1
= cx0
+ w
->phys_cursor_width
;
23572 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23575 /* The cursor image will be completely removed from the
23576 screen if the output area intersects the cursor area in
23577 y-direction. When we draw in [y0 y1[, and some part of
23578 the cursor is at y < y0, that part must have been drawn
23579 before. When scrolling, the cursor is erased before
23580 actually scrolling, so we don't come here. When not
23581 scrolling, the rows above the old cursor row must have
23582 changed, and in this case these rows must have written
23583 over the cursor image.
23585 Likewise if part of the cursor is below y1, with the
23586 exception of the cursor being in the first blank row at
23587 the buffer and window end because update_text_area
23588 doesn't draw that row. (Except when it does, but
23589 that's handled in update_text_area.) */
23591 cy0
= w
->phys_cursor
.y
;
23592 cy1
= cy0
+ w
->phys_cursor_height
;
23593 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23596 w
->phys_cursor_on_p
= 0;
23599 #endif /* HAVE_WINDOW_SYSTEM */
23602 /************************************************************************
23604 ************************************************************************/
23606 #ifdef HAVE_WINDOW_SYSTEM
23609 Fix the display of area AREA of overlapping row ROW in window W
23610 with respect to the overlapping part OVERLAPS. */
23613 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
23614 enum glyph_row_area area
, int overlaps
)
23621 for (i
= 0; i
< row
->used
[area
];)
23623 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23625 int start
= i
, start_x
= x
;
23629 x
+= row
->glyphs
[area
][i
].pixel_width
;
23632 while (i
< row
->used
[area
]
23633 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23635 draw_glyphs (w
, start_x
, row
, area
,
23637 DRAW_NORMAL_TEXT
, overlaps
);
23641 x
+= row
->glyphs
[area
][i
].pixel_width
;
23651 Draw the cursor glyph of window W in glyph row ROW. See the
23652 comment of draw_glyphs for the meaning of HL. */
23655 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
23656 enum draw_glyphs_face hl
)
23658 /* If cursor hpos is out of bounds, don't draw garbage. This can
23659 happen in mini-buffer windows when switching between echo area
23660 glyphs and mini-buffer. */
23661 if ((row
->reversed_p
23662 ? (w
->phys_cursor
.hpos
>= 0)
23663 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23665 int on_p
= w
->phys_cursor_on_p
;
23667 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23668 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23670 w
->phys_cursor_on_p
= on_p
;
23672 if (hl
== DRAW_CURSOR
)
23673 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23674 /* When we erase the cursor, and ROW is overlapped by other
23675 rows, make sure that these overlapping parts of other rows
23677 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23679 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23681 if (row
> w
->current_matrix
->rows
23682 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23683 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23684 OVERLAPS_ERASED_CURSOR
);
23686 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23687 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23688 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23689 OVERLAPS_ERASED_CURSOR
);
23696 Erase the image of a cursor of window W from the screen. */
23699 erase_phys_cursor (struct window
*w
)
23701 struct frame
*f
= XFRAME (w
->frame
);
23702 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23703 int hpos
= w
->phys_cursor
.hpos
;
23704 int vpos
= w
->phys_cursor
.vpos
;
23705 int mouse_face_here_p
= 0;
23706 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23707 struct glyph_row
*cursor_row
;
23708 struct glyph
*cursor_glyph
;
23709 enum draw_glyphs_face hl
;
23711 /* No cursor displayed or row invalidated => nothing to do on the
23713 if (w
->phys_cursor_type
== NO_CURSOR
)
23714 goto mark_cursor_off
;
23716 /* VPOS >= active_glyphs->nrows means that window has been resized.
23717 Don't bother to erase the cursor. */
23718 if (vpos
>= active_glyphs
->nrows
)
23719 goto mark_cursor_off
;
23721 /* If row containing cursor is marked invalid, there is nothing we
23723 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23724 if (!cursor_row
->enabled_p
)
23725 goto mark_cursor_off
;
23727 /* If line spacing is > 0, old cursor may only be partially visible in
23728 window after split-window. So adjust visible height. */
23729 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23730 window_text_bottom_y (w
) - cursor_row
->y
);
23732 /* If row is completely invisible, don't attempt to delete a cursor which
23733 isn't there. This can happen if cursor is at top of a window, and
23734 we switch to a buffer with a header line in that window. */
23735 if (cursor_row
->visible_height
<= 0)
23736 goto mark_cursor_off
;
23738 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23739 if (cursor_row
->cursor_in_fringe_p
)
23741 cursor_row
->cursor_in_fringe_p
= 0;
23742 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23743 goto mark_cursor_off
;
23746 /* This can happen when the new row is shorter than the old one.
23747 In this case, either draw_glyphs or clear_end_of_line
23748 should have cleared the cursor. Note that we wouldn't be
23749 able to erase the cursor in this case because we don't have a
23750 cursor glyph at hand. */
23751 if ((cursor_row
->reversed_p
23752 ? (w
->phys_cursor
.hpos
< 0)
23753 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23754 goto mark_cursor_off
;
23756 /* If the cursor is in the mouse face area, redisplay that when
23757 we clear the cursor. */
23758 if (! NILP (hlinfo
->mouse_face_window
)
23759 && coords_in_mouse_face_p (w
, hpos
, vpos
)
23760 /* Don't redraw the cursor's spot in mouse face if it is at the
23761 end of a line (on a newline). The cursor appears there, but
23762 mouse highlighting does not. */
23763 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
23764 mouse_face_here_p
= 1;
23766 /* Maybe clear the display under the cursor. */
23767 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23770 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23773 cursor_glyph
= get_phys_cursor_glyph (w
);
23774 if (cursor_glyph
== NULL
)
23775 goto mark_cursor_off
;
23777 width
= cursor_glyph
->pixel_width
;
23778 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23779 x
= w
->phys_cursor
.x
;
23781 width
-= left_x
- x
;
23782 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23783 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23784 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23787 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23790 /* Erase the cursor by redrawing the character underneath it. */
23791 if (mouse_face_here_p
)
23792 hl
= DRAW_MOUSE_FACE
;
23794 hl
= DRAW_NORMAL_TEXT
;
23795 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23798 w
->phys_cursor_on_p
= 0;
23799 w
->phys_cursor_type
= NO_CURSOR
;
23804 Display or clear cursor of window W. If ON is zero, clear the
23805 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23806 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23809 display_and_set_cursor (struct window
*w
, int on
,
23810 int hpos
, int vpos
, int x
, int y
)
23812 struct frame
*f
= XFRAME (w
->frame
);
23813 int new_cursor_type
;
23814 int new_cursor_width
;
23816 struct glyph_row
*glyph_row
;
23817 struct glyph
*glyph
;
23819 /* This is pointless on invisible frames, and dangerous on garbaged
23820 windows and frames; in the latter case, the frame or window may
23821 be in the midst of changing its size, and x and y may be off the
23823 if (! FRAME_VISIBLE_P (f
)
23824 || FRAME_GARBAGED_P (f
)
23825 || vpos
>= w
->current_matrix
->nrows
23826 || hpos
>= w
->current_matrix
->matrix_w
)
23829 /* If cursor is off and we want it off, return quickly. */
23830 if (!on
&& !w
->phys_cursor_on_p
)
23833 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23834 /* If cursor row is not enabled, we don't really know where to
23835 display the cursor. */
23836 if (!glyph_row
->enabled_p
)
23838 w
->phys_cursor_on_p
= 0;
23843 if (!glyph_row
->exact_window_width_line_p
23844 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
23845 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23847 xassert (interrupt_input_blocked
);
23849 /* Set new_cursor_type to the cursor we want to be displayed. */
23850 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23851 &new_cursor_width
, &active_cursor
);
23853 /* If cursor is currently being shown and we don't want it to be or
23854 it is in the wrong place, or the cursor type is not what we want,
23856 if (w
->phys_cursor_on_p
23858 || w
->phys_cursor
.x
!= x
23859 || w
->phys_cursor
.y
!= y
23860 || new_cursor_type
!= w
->phys_cursor_type
23861 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23862 && new_cursor_width
!= w
->phys_cursor_width
)))
23863 erase_phys_cursor (w
);
23865 /* Don't check phys_cursor_on_p here because that flag is only set
23866 to zero in some cases where we know that the cursor has been
23867 completely erased, to avoid the extra work of erasing the cursor
23868 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23869 still not be visible, or it has only been partly erased. */
23872 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23873 w
->phys_cursor_height
= glyph_row
->height
;
23875 /* Set phys_cursor_.* before x_draw_.* is called because some
23876 of them may need the information. */
23877 w
->phys_cursor
.x
= x
;
23878 w
->phys_cursor
.y
= glyph_row
->y
;
23879 w
->phys_cursor
.hpos
= hpos
;
23880 w
->phys_cursor
.vpos
= vpos
;
23883 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23884 new_cursor_type
, new_cursor_width
,
23885 on
, active_cursor
);
23889 /* Switch the display of W's cursor on or off, according to the value
23893 update_window_cursor (struct window
*w
, int on
)
23895 /* Don't update cursor in windows whose frame is in the process
23896 of being deleted. */
23897 if (w
->current_matrix
)
23900 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23901 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23907 /* Call update_window_cursor with parameter ON_P on all leaf windows
23908 in the window tree rooted at W. */
23911 update_cursor_in_window_tree (struct window
*w
, int on_p
)
23915 if (!NILP (w
->hchild
))
23916 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23917 else if (!NILP (w
->vchild
))
23918 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23920 update_window_cursor (w
, on_p
);
23922 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23928 Display the cursor on window W, or clear it, according to ON_P.
23929 Don't change the cursor's position. */
23932 x_update_cursor (struct frame
*f
, int on_p
)
23934 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23939 Clear the cursor of window W to background color, and mark the
23940 cursor as not shown. This is used when the text where the cursor
23941 is about to be rewritten. */
23944 x_clear_cursor (struct window
*w
)
23946 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23947 update_window_cursor (w
, 0);
23950 #endif /* HAVE_WINDOW_SYSTEM */
23952 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
23955 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
23956 int start_hpos
, int end_hpos
,
23957 enum draw_glyphs_face draw
)
23959 #ifdef HAVE_WINDOW_SYSTEM
23960 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
23962 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
23966 #if defined (HAVE_GPM) || defined (MSDOS)
23967 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
23971 /* Display the active region described by mouse_face_* according to DRAW. */
23974 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
23976 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
23977 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23979 if (/* If window is in the process of being destroyed, don't bother
23981 w
->current_matrix
!= NULL
23982 /* Don't update mouse highlight if hidden */
23983 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
23984 /* Recognize when we are called to operate on rows that don't exist
23985 anymore. This can happen when a window is split. */
23986 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23988 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23989 struct glyph_row
*row
, *first
, *last
;
23991 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23992 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23994 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23996 int start_hpos
, end_hpos
, start_x
;
23998 /* For all but the first row, the highlight starts at column 0. */
24001 /* R2L rows have BEG and END in reversed order, but the
24002 screen drawing geometry is always left to right. So
24003 we need to mirror the beginning and end of the
24004 highlighted area in R2L rows. */
24005 if (!row
->reversed_p
)
24007 start_hpos
= hlinfo
->mouse_face_beg_col
;
24008 start_x
= hlinfo
->mouse_face_beg_x
;
24010 else if (row
== last
)
24012 start_hpos
= hlinfo
->mouse_face_end_col
;
24013 start_x
= hlinfo
->mouse_face_end_x
;
24021 else if (row
->reversed_p
&& row
== last
)
24023 start_hpos
= hlinfo
->mouse_face_end_col
;
24024 start_x
= hlinfo
->mouse_face_end_x
;
24034 if (!row
->reversed_p
)
24035 end_hpos
= hlinfo
->mouse_face_end_col
;
24036 else if (row
== first
)
24037 end_hpos
= hlinfo
->mouse_face_beg_col
;
24040 end_hpos
= row
->used
[TEXT_AREA
];
24041 if (draw
== DRAW_NORMAL_TEXT
)
24042 row
->fill_line_p
= 1; /* Clear to end of line */
24045 else if (row
->reversed_p
&& row
== first
)
24046 end_hpos
= hlinfo
->mouse_face_beg_col
;
24049 end_hpos
= row
->used
[TEXT_AREA
];
24050 if (draw
== DRAW_NORMAL_TEXT
)
24051 row
->fill_line_p
= 1; /* Clear to end of line */
24054 if (end_hpos
> start_hpos
)
24056 draw_row_with_mouse_face (w
, start_x
, row
,
24057 start_hpos
, end_hpos
, draw
);
24060 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24064 #ifdef HAVE_WINDOW_SYSTEM
24065 /* When we've written over the cursor, arrange for it to
24066 be displayed again. */
24067 if (FRAME_WINDOW_P (f
)
24068 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24071 display_and_set_cursor (w
, 1,
24072 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24073 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24076 #endif /* HAVE_WINDOW_SYSTEM */
24079 #ifdef HAVE_WINDOW_SYSTEM
24080 /* Change the mouse cursor. */
24081 if (FRAME_WINDOW_P (f
))
24083 if (draw
== DRAW_NORMAL_TEXT
24084 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24085 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24086 else if (draw
== DRAW_MOUSE_FACE
)
24087 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24089 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24091 #endif /* HAVE_WINDOW_SYSTEM */
24095 Clear out the mouse-highlighted active region.
24096 Redraw it un-highlighted first. Value is non-zero if mouse
24097 face was actually drawn unhighlighted. */
24100 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24104 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24106 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24110 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24111 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24112 hlinfo
->mouse_face_window
= Qnil
;
24113 hlinfo
->mouse_face_overlay
= Qnil
;
24117 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24118 within the mouse face on that window. */
24120 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24122 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24124 /* Quickly resolve the easy cases. */
24125 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24126 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24128 if (vpos
< hlinfo
->mouse_face_beg_row
24129 || vpos
> hlinfo
->mouse_face_end_row
)
24131 if (vpos
> hlinfo
->mouse_face_beg_row
24132 && vpos
< hlinfo
->mouse_face_end_row
)
24135 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24137 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24139 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24142 else if ((vpos
== hlinfo
->mouse_face_beg_row
24143 && hpos
>= hlinfo
->mouse_face_beg_col
)
24144 || (vpos
== hlinfo
->mouse_face_end_row
24145 && hpos
< hlinfo
->mouse_face_end_col
))
24150 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24152 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24155 else if ((vpos
== hlinfo
->mouse_face_beg_row
24156 && hpos
<= hlinfo
->mouse_face_beg_col
)
24157 || (vpos
== hlinfo
->mouse_face_end_row
24158 && hpos
> hlinfo
->mouse_face_end_col
))
24166 Non-zero if physical cursor of window W is within mouse face. */
24169 cursor_in_mouse_face_p (struct window
*w
)
24171 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24176 /* Find the glyph rows START_ROW and END_ROW of window W that display
24177 characters between buffer positions START_CHARPOS and END_CHARPOS
24178 (excluding END_CHARPOS). This is similar to row_containing_pos,
24179 but is more accurate when bidi reordering makes buffer positions
24180 change non-linearly with glyph rows. */
24182 rows_from_pos_range (struct window
*w
,
24183 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24184 struct glyph_row
**start
, struct glyph_row
**end
)
24186 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24187 int last_y
= window_text_bottom_y (w
);
24188 struct glyph_row
*row
;
24193 while (!first
->enabled_p
24194 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24197 /* Find the START row. */
24199 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24202 /* A row can potentially be the START row if the range of the
24203 characters it displays intersects the range
24204 [START_CHARPOS..END_CHARPOS). */
24205 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24206 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24207 /* See the commentary in row_containing_pos, for the
24208 explanation of the complicated way to check whether
24209 some position is beyond the end of the characters
24210 displayed by a row. */
24211 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24212 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24213 && !row
->ends_at_zv_p
24214 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24215 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24216 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24217 && !row
->ends_at_zv_p
24218 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24220 /* Found a candidate row. Now make sure at least one of the
24221 glyphs it displays has a charpos from the range
24222 [START_CHARPOS..END_CHARPOS).
24224 This is not obvious because bidi reordering could make
24225 buffer positions of a row be 1,2,3,102,101,100, and if we
24226 want to highlight characters in [50..60), we don't want
24227 this row, even though [50..60) does intersect [1..103),
24228 the range of character positions given by the row's start
24229 and end positions. */
24230 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24231 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24235 if (BUFFERP (g
->object
)
24236 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24245 /* Find the END row. */
24247 /* If the last row is partially visible, start looking for END
24248 from that row, instead of starting from FIRST. */
24249 && !(row
->enabled_p
24250 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24252 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24254 struct glyph_row
*next
= row
+ 1;
24256 if (!next
->enabled_p
24257 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24258 /* The first row >= START whose range of displayed characters
24259 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24260 is the row END + 1. */
24261 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24262 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24263 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24264 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24265 && !next
->ends_at_zv_p
24266 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24267 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24268 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24269 && !next
->ends_at_zv_p
24270 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24277 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24278 but none of the characters it displays are in the range, it is
24280 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24281 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24285 if (BUFFERP (g
->object
)
24286 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24299 /* This function sets the mouse_face_* elements of HLINFO, assuming
24300 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24301 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24302 for the overlay or run of text properties specifying the mouse
24303 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24304 before-string and after-string that must also be highlighted.
24305 COVER_STRING, if non-nil, is a display string that may cover some
24306 or all of the highlighted text. */
24309 mouse_face_from_buffer_pos (Lisp_Object window
,
24310 Mouse_HLInfo
*hlinfo
,
24311 EMACS_INT mouse_charpos
,
24312 EMACS_INT start_charpos
,
24313 EMACS_INT end_charpos
,
24314 Lisp_Object before_string
,
24315 Lisp_Object after_string
,
24316 Lisp_Object cover_string
)
24318 struct window
*w
= XWINDOW (window
);
24319 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24320 struct glyph_row
*r1
, *r2
;
24321 struct glyph
*glyph
, *end
;
24322 EMACS_INT ignore
, pos
;
24325 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24326 xassert (NILP (before_string
) || STRINGP (before_string
));
24327 xassert (NILP (after_string
) || STRINGP (after_string
));
24329 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24330 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24332 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24333 /* If the before-string or display-string contains newlines,
24334 rows_from_pos_range skips to its last row. Move back. */
24335 if (!NILP (before_string
) || !NILP (cover_string
))
24337 struct glyph_row
*prev
;
24338 while ((prev
= r1
- 1, prev
>= first
)
24339 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24340 && prev
->used
[TEXT_AREA
] > 0)
24342 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24343 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24344 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24346 || !(EQ (glyph
->object
, before_string
)
24347 || EQ (glyph
->object
, cover_string
)))
24354 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24355 hlinfo
->mouse_face_past_end
= 1;
24357 else if (!NILP (after_string
))
24359 /* If the after-string has newlines, advance to its last row. */
24360 struct glyph_row
*next
;
24361 struct glyph_row
*last
24362 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24364 for (next
= r2
+ 1;
24366 && next
->used
[TEXT_AREA
] > 0
24367 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24371 /* The rest of the display engine assumes that mouse_face_beg_row is
24372 either above below mouse_face_end_row or identical to it. But
24373 with bidi-reordered continued lines, the row for START_CHARPOS
24374 could be below the row for END_CHARPOS. If so, swap the rows and
24375 store them in correct order. */
24378 struct glyph_row
*tem
= r2
;
24384 hlinfo
->mouse_face_beg_y
= r1
->y
;
24385 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24386 hlinfo
->mouse_face_end_y
= r2
->y
;
24387 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24389 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24390 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
24391 could be anywhere in the row and in any order. The strategy
24392 below is to find the leftmost and the rightmost glyph that
24393 belongs to either of these 3 strings, or whose position is
24394 between START_CHARPOS and END_CHARPOS, and highlight all the
24395 glyphs between those two. This may cover more than just the text
24396 between START_CHARPOS and END_CHARPOS if the range of characters
24397 strides the bidi level boundary, e.g. if the beginning is in R2L
24398 text while the end is in L2R text or vice versa. */
24399 if (!r1
->reversed_p
)
24401 /* This row is in a left to right paragraph. Scan it left to
24403 glyph
= r1
->glyphs
[TEXT_AREA
];
24404 end
= glyph
+ r1
->used
[TEXT_AREA
];
24407 /* Skip truncation glyphs at the start of the glyph row. */
24408 if (r1
->displays_text_p
)
24410 && INTEGERP (glyph
->object
)
24411 && glyph
->charpos
< 0;
24413 x
+= glyph
->pixel_width
;
24415 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24416 or COVER_STRING, and the first glyph from buffer whose
24417 position is between START_CHARPOS and END_CHARPOS. */
24419 && !INTEGERP (glyph
->object
)
24420 && !EQ (glyph
->object
, cover_string
)
24421 && !(BUFFERP (glyph
->object
)
24422 && (glyph
->charpos
>= start_charpos
24423 && glyph
->charpos
< end_charpos
));
24426 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24427 are present at buffer positions between START_CHARPOS and
24428 END_CHARPOS, or if they come from an overlay. */
24429 if (EQ (glyph
->object
, before_string
))
24431 pos
= string_buffer_position (before_string
,
24433 /* If pos == 0, it means before_string came from an
24434 overlay, not from a buffer position. */
24435 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24438 else if (EQ (glyph
->object
, after_string
))
24440 pos
= string_buffer_position (after_string
, end_charpos
);
24441 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24444 x
+= glyph
->pixel_width
;
24446 hlinfo
->mouse_face_beg_x
= x
;
24447 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24451 /* This row is in a right to left paragraph. Scan it right to
24455 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24456 glyph
= end
+ r1
->used
[TEXT_AREA
];
24458 /* Skip truncation glyphs at the start of the glyph row. */
24459 if (r1
->displays_text_p
)
24461 && INTEGERP (glyph
->object
)
24462 && glyph
->charpos
< 0;
24466 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24467 or COVER_STRING, and the first glyph from buffer whose
24468 position is between START_CHARPOS and END_CHARPOS. */
24470 && !INTEGERP (glyph
->object
)
24471 && !EQ (glyph
->object
, cover_string
)
24472 && !(BUFFERP (glyph
->object
)
24473 && (glyph
->charpos
>= start_charpos
24474 && glyph
->charpos
< end_charpos
));
24477 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24478 are present at buffer positions between START_CHARPOS and
24479 END_CHARPOS, or if they come from an overlay. */
24480 if (EQ (glyph
->object
, before_string
))
24482 pos
= string_buffer_position (before_string
, start_charpos
);
24483 /* If pos == 0, it means before_string came from an
24484 overlay, not from a buffer position. */
24485 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24488 else if (EQ (glyph
->object
, after_string
))
24490 pos
= string_buffer_position (after_string
, end_charpos
);
24491 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24496 glyph
++; /* first glyph to the right of the highlighted area */
24497 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24498 x
+= g
->pixel_width
;
24499 hlinfo
->mouse_face_beg_x
= x
;
24500 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24503 /* If the highlight ends in a different row, compute GLYPH and END
24504 for the end row. Otherwise, reuse the values computed above for
24505 the row where the highlight begins. */
24508 if (!r2
->reversed_p
)
24510 glyph
= r2
->glyphs
[TEXT_AREA
];
24511 end
= glyph
+ r2
->used
[TEXT_AREA
];
24516 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24517 glyph
= end
+ r2
->used
[TEXT_AREA
];
24521 if (!r2
->reversed_p
)
24523 /* Skip truncation and continuation glyphs near the end of the
24524 row, and also blanks and stretch glyphs inserted by
24525 extend_face_to_end_of_line. */
24527 && INTEGERP ((end
- 1)->object
)
24528 && (end
- 1)->charpos
<= 0)
24530 /* Scan the rest of the glyph row from the end, looking for the
24531 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24532 COVER_STRING, or whose position is between START_CHARPOS
24536 && !INTEGERP (end
->object
)
24537 && !EQ (end
->object
, cover_string
)
24538 && !(BUFFERP (end
->object
)
24539 && (end
->charpos
>= start_charpos
24540 && end
->charpos
< end_charpos
));
24543 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24544 are present at buffer positions between START_CHARPOS and
24545 END_CHARPOS, or if they come from an overlay. */
24546 if (EQ (end
->object
, before_string
))
24548 pos
= string_buffer_position (before_string
, start_charpos
);
24549 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24552 else if (EQ (end
->object
, after_string
))
24554 pos
= string_buffer_position (after_string
, end_charpos
);
24555 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24559 /* Find the X coordinate of the last glyph to be highlighted. */
24560 for (; glyph
<= end
; ++glyph
)
24561 x
+= glyph
->pixel_width
;
24563 hlinfo
->mouse_face_end_x
= x
;
24564 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24568 /* Skip truncation and continuation glyphs near the end of the
24569 row, and also blanks and stretch glyphs inserted by
24570 extend_face_to_end_of_line. */
24574 && INTEGERP (end
->object
)
24575 && end
->charpos
<= 0)
24577 x
+= end
->pixel_width
;
24580 /* Scan the rest of the glyph row from the end, looking for the
24581 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24582 COVER_STRING, or whose position is between START_CHARPOS
24586 && !INTEGERP (end
->object
)
24587 && !EQ (end
->object
, cover_string
)
24588 && !(BUFFERP (end
->object
)
24589 && (end
->charpos
>= start_charpos
24590 && end
->charpos
< end_charpos
));
24593 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24594 are present at buffer positions between START_CHARPOS and
24595 END_CHARPOS, or if they come from an overlay. */
24596 if (EQ (end
->object
, before_string
))
24598 pos
= string_buffer_position (before_string
, start_charpos
);
24599 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24602 else if (EQ (end
->object
, after_string
))
24604 pos
= string_buffer_position (after_string
, end_charpos
);
24605 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24608 x
+= end
->pixel_width
;
24610 hlinfo
->mouse_face_end_x
= x
;
24611 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
24614 hlinfo
->mouse_face_window
= window
;
24615 hlinfo
->mouse_face_face_id
24616 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
24618 !hlinfo
->mouse_face_hidden
, -1);
24619 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
24622 /* The following function is not used anymore (replaced with
24623 mouse_face_from_string_pos), but I leave it here for the time
24624 being, in case someone would. */
24626 #if 0 /* not used */
24628 /* Find the position of the glyph for position POS in OBJECT in
24629 window W's current matrix, and return in *X, *Y the pixel
24630 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
24632 RIGHT_P non-zero means return the position of the right edge of the
24633 glyph, RIGHT_P zero means return the left edge position.
24635 If no glyph for POS exists in the matrix, return the position of
24636 the glyph with the next smaller position that is in the matrix, if
24637 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
24638 exists in the matrix, return the position of the glyph with the
24639 next larger position in OBJECT.
24641 Value is non-zero if a glyph was found. */
24644 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
24645 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
24647 int yb
= window_text_bottom_y (w
);
24648 struct glyph_row
*r
;
24649 struct glyph
*best_glyph
= NULL
;
24650 struct glyph_row
*best_row
= NULL
;
24653 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24654 r
->enabled_p
&& r
->y
< yb
;
24657 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24658 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24661 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24662 if (EQ (g
->object
, object
))
24664 if (g
->charpos
== pos
)
24671 else if (best_glyph
== NULL
24672 || ((eabs (g
->charpos
- pos
)
24673 < eabs (best_glyph
->charpos
- pos
))
24676 : g
->charpos
> pos
)))
24690 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24694 *x
+= best_glyph
->pixel_width
;
24699 *vpos
= best_row
- w
->current_matrix
->rows
;
24702 return best_glyph
!= NULL
;
24704 #endif /* not used */
24706 /* Find the positions of the first and the last glyphs in window W's
24707 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
24708 (assumed to be a string), and return in HLINFO's mouse_face_*
24709 members the pixel and column/row coordinates of those glyphs. */
24712 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
24713 Lisp_Object object
,
24714 EMACS_INT startpos
, EMACS_INT endpos
)
24716 int yb
= window_text_bottom_y (w
);
24717 struct glyph_row
*r
;
24718 struct glyph
*g
, *e
;
24722 /* Find the glyph row with at least one position in the range
24723 [STARTPOS..ENDPOS], and the first glyph in that row whose
24724 position belongs to that range. */
24725 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24726 r
->enabled_p
&& r
->y
< yb
;
24729 if (!r
->reversed_p
)
24731 g
= r
->glyphs
[TEXT_AREA
];
24732 e
= g
+ r
->used
[TEXT_AREA
];
24733 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24734 if (EQ (g
->object
, object
)
24735 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24737 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24738 hlinfo
->mouse_face_beg_y
= r
->y
;
24739 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24740 hlinfo
->mouse_face_beg_x
= gx
;
24749 e
= r
->glyphs
[TEXT_AREA
];
24750 g
= e
+ r
->used
[TEXT_AREA
];
24751 for ( ; g
> e
; --g
)
24752 if (EQ ((g
-1)->object
, object
)
24753 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
24755 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24756 hlinfo
->mouse_face_beg_y
= r
->y
;
24757 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24758 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
24759 gx
+= g1
->pixel_width
;
24760 hlinfo
->mouse_face_beg_x
= gx
;
24772 /* Starting with the next row, look for the first row which does NOT
24773 include any glyphs whose positions are in the range. */
24774 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
24776 g
= r
->glyphs
[TEXT_AREA
];
24777 e
= g
+ r
->used
[TEXT_AREA
];
24779 for ( ; g
< e
; ++g
)
24780 if (EQ (g
->object
, object
)
24781 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24790 /* The highlighted region ends on the previous row. */
24793 /* Set the end row and its vertical pixel coordinate. */
24794 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
24795 hlinfo
->mouse_face_end_y
= r
->y
;
24797 /* Compute and set the end column and the end column's horizontal
24798 pixel coordinate. */
24799 if (!r
->reversed_p
)
24801 g
= r
->glyphs
[TEXT_AREA
];
24802 e
= g
+ r
->used
[TEXT_AREA
];
24803 for ( ; e
> g
; --e
)
24804 if (EQ ((e
-1)->object
, object
)
24805 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
24807 hlinfo
->mouse_face_end_col
= e
- g
;
24809 for (gx
= r
->x
; g
< e
; ++g
)
24810 gx
+= g
->pixel_width
;
24811 hlinfo
->mouse_face_end_x
= gx
;
24815 e
= r
->glyphs
[TEXT_AREA
];
24816 g
= e
+ r
->used
[TEXT_AREA
];
24817 for (gx
= r
->x
; e
< g
; ++e
)
24819 if (EQ (e
->object
, object
)
24820 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
24822 gx
+= e
->pixel_width
;
24824 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
24825 hlinfo
->mouse_face_end_x
= gx
;
24829 #ifdef HAVE_WINDOW_SYSTEM
24831 /* See if position X, Y is within a hot-spot of an image. */
24834 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
24836 if (!CONSP (hot_spot
))
24839 if (EQ (XCAR (hot_spot
), Qrect
))
24841 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24842 Lisp_Object rect
= XCDR (hot_spot
);
24846 if (!CONSP (XCAR (rect
)))
24848 if (!CONSP (XCDR (rect
)))
24850 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24852 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24854 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24856 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24860 else if (EQ (XCAR (hot_spot
), Qcircle
))
24862 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24863 Lisp_Object circ
= XCDR (hot_spot
);
24864 Lisp_Object lr
, lx0
, ly0
;
24866 && CONSP (XCAR (circ
))
24867 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24868 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24869 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24871 double r
= XFLOATINT (lr
);
24872 double dx
= XINT (lx0
) - x
;
24873 double dy
= XINT (ly0
) - y
;
24874 return (dx
* dx
+ dy
* dy
<= r
* r
);
24877 else if (EQ (XCAR (hot_spot
), Qpoly
))
24879 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24880 if (VECTORP (XCDR (hot_spot
)))
24882 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24883 Lisp_Object
*poly
= v
->contents
;
24884 int n
= v
->header
.size
;
24887 Lisp_Object lx
, ly
;
24890 /* Need an even number of coordinates, and at least 3 edges. */
24891 if (n
< 6 || n
& 1)
24894 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24895 If count is odd, we are inside polygon. Pixels on edges
24896 may or may not be included depending on actual geometry of the
24898 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24899 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24901 x0
= XINT (lx
), y0
= XINT (ly
);
24902 for (i
= 0; i
< n
; i
+= 2)
24904 int x1
= x0
, y1
= y0
;
24905 if ((lx
= poly
[i
], !INTEGERP (lx
))
24906 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24908 x0
= XINT (lx
), y0
= XINT (ly
);
24910 /* Does this segment cross the X line? */
24918 if (y
> y0
&& y
> y1
)
24920 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24930 find_hot_spot (Lisp_Object map
, int x
, int y
)
24932 while (CONSP (map
))
24934 if (CONSP (XCAR (map
))
24935 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
24943 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
24945 doc
: /* Lookup in image map MAP coordinates X and Y.
24946 An image map is an alist where each element has the format (AREA ID PLIST).
24947 An AREA is specified as either a rectangle, a circle, or a polygon:
24948 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
24949 pixel coordinates of the upper left and bottom right corners.
24950 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
24951 and the radius of the circle; r may be a float or integer.
24952 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
24953 vector describes one corner in the polygon.
24954 Returns the alist element for the first matching AREA in MAP. */)
24955 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
24963 return find_hot_spot (map
, XINT (x
), XINT (y
));
24967 /* Display frame CURSOR, optionally using shape defined by POINTER. */
24969 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
24971 /* Do not change cursor shape while dragging mouse. */
24972 if (!NILP (do_mouse_tracking
))
24975 if (!NILP (pointer
))
24977 if (EQ (pointer
, Qarrow
))
24978 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24979 else if (EQ (pointer
, Qhand
))
24980 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
24981 else if (EQ (pointer
, Qtext
))
24982 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24983 else if (EQ (pointer
, intern ("hdrag")))
24984 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24985 #ifdef HAVE_X_WINDOWS
24986 else if (EQ (pointer
, intern ("vdrag")))
24987 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
24989 else if (EQ (pointer
, intern ("hourglass")))
24990 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
24991 else if (EQ (pointer
, Qmodeline
))
24992 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
24994 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24997 if (cursor
!= No_Cursor
)
24998 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25001 #endif /* HAVE_WINDOW_SYSTEM */
25003 /* Take proper action when mouse has moved to the mode or header line
25004 or marginal area AREA of window W, x-position X and y-position Y.
25005 X is relative to the start of the text display area of W, so the
25006 width of bitmap areas and scroll bars must be subtracted to get a
25007 position relative to the start of the mode line. */
25010 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25011 enum window_part area
)
25013 struct window
*w
= XWINDOW (window
);
25014 struct frame
*f
= XFRAME (w
->frame
);
25015 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25016 #ifdef HAVE_WINDOW_SYSTEM
25017 Display_Info
*dpyinfo
;
25019 Cursor cursor
= No_Cursor
;
25020 Lisp_Object pointer
= Qnil
;
25021 int dx
, dy
, width
, height
;
25023 Lisp_Object string
, object
= Qnil
;
25024 Lisp_Object pos
, help
;
25026 Lisp_Object mouse_face
;
25027 int original_x_pixel
= x
;
25028 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25029 struct glyph_row
*row
;
25031 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25036 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25037 returns them in row/column units! */
25038 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25039 &object
, &dx
, &dy
, &width
, &height
);
25041 row
= (area
== ON_MODE_LINE
25042 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25043 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25045 /* Find the glyph under the mouse pointer. */
25046 if (row
->mode_line_p
&& row
->enabled_p
)
25048 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25049 end
= glyph
+ row
->used
[TEXT_AREA
];
25051 for (x0
= original_x_pixel
;
25052 glyph
< end
&& x0
>= glyph
->pixel_width
;
25054 x0
-= glyph
->pixel_width
;
25062 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25063 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25064 returns them in row/column units! */
25065 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25066 &object
, &dx
, &dy
, &width
, &height
);
25071 #ifdef HAVE_WINDOW_SYSTEM
25072 if (IMAGEP (object
))
25074 Lisp_Object image_map
, hotspot
;
25075 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25077 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25079 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25083 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25084 If so, we could look for mouse-enter, mouse-leave
25085 properties in PLIST (and do something...). */
25086 hotspot
= XCDR (hotspot
);
25087 if (CONSP (hotspot
)
25088 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25090 pointer
= Fplist_get (plist
, Qpointer
);
25091 if (NILP (pointer
))
25093 help
= Fplist_get (plist
, Qhelp_echo
);
25096 help_echo_string
= help
;
25097 /* Is this correct? ++kfs */
25098 XSETWINDOW (help_echo_window
, w
);
25099 help_echo_object
= w
->buffer
;
25100 help_echo_pos
= charpos
;
25104 if (NILP (pointer
))
25105 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25107 #endif /* HAVE_WINDOW_SYSTEM */
25109 if (STRINGP (string
))
25111 pos
= make_number (charpos
);
25112 /* If we're on a string with `help-echo' text property, arrange
25113 for the help to be displayed. This is done by setting the
25114 global variable help_echo_string to the help string. */
25117 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25120 help_echo_string
= help
;
25121 XSETWINDOW (help_echo_window
, w
);
25122 help_echo_object
= string
;
25123 help_echo_pos
= charpos
;
25127 #ifdef HAVE_WINDOW_SYSTEM
25128 if (FRAME_WINDOW_P (f
))
25130 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25131 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25132 if (NILP (pointer
))
25133 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25135 /* Change the mouse pointer according to what is under X/Y. */
25137 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25140 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25141 if (!KEYMAPP (map
))
25142 map
= Fget_text_property (pos
, Qkeymap
, string
);
25143 if (!KEYMAPP (map
))
25144 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25149 /* Change the mouse face according to what is under X/Y. */
25150 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25151 if (!NILP (mouse_face
)
25152 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25157 struct glyph
* tmp_glyph
;
25161 int total_pixel_width
;
25162 EMACS_INT begpos
, endpos
, ignore
;
25166 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25167 Qmouse_face
, string
, Qnil
);
25173 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25175 endpos
= SCHARS (string
);
25179 /* Calculate the glyph position GPOS of GLYPH in the
25180 displayed string, relative to the beginning of the
25181 highlighted part of the string.
25183 Note: GPOS is different from CHARPOS. CHARPOS is the
25184 position of GLYPH in the internal string object. A mode
25185 line string format has structures which are converted to
25186 a flattened string by the Emacs Lisp interpreter. The
25187 internal string is an element of those structures. The
25188 displayed string is the flattened string. */
25189 tmp_glyph
= row_start_glyph
;
25190 while (tmp_glyph
< glyph
25191 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25192 && begpos
<= tmp_glyph
->charpos
25193 && tmp_glyph
->charpos
< endpos
)))
25195 gpos
= glyph
- tmp_glyph
;
25197 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25198 the highlighted part of the displayed string to which
25199 GLYPH belongs. Note: GSEQ_LENGTH is different from
25200 SCHARS (STRING), because the latter returns the length of
25201 the internal string. */
25202 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25204 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25205 && begpos
<= tmp_glyph
->charpos
25206 && tmp_glyph
->charpos
< endpos
));
25209 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25211 /* Calculate the total pixel width of all the glyphs between
25212 the beginning of the highlighted area and GLYPH. */
25213 total_pixel_width
= 0;
25214 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25215 total_pixel_width
+= tmp_glyph
->pixel_width
;
25217 /* Pre calculation of re-rendering position. Note: X is in
25218 column units here, after the call to mode_line_string or
25219 marginal_area_string. */
25221 vpos
= (area
== ON_MODE_LINE
25222 ? (w
->current_matrix
)->nrows
- 1
25225 /* If GLYPH's position is included in the region that is
25226 already drawn in mouse face, we have nothing to do. */
25227 if ( EQ (window
, hlinfo
->mouse_face_window
)
25228 && (!row
->reversed_p
25229 ? (hlinfo
->mouse_face_beg_col
<= hpos
25230 && hpos
< hlinfo
->mouse_face_end_col
)
25231 /* In R2L rows we swap BEG and END, see below. */
25232 : (hlinfo
->mouse_face_end_col
<= hpos
25233 && hpos
< hlinfo
->mouse_face_beg_col
))
25234 && hlinfo
->mouse_face_beg_row
== vpos
)
25237 if (clear_mouse_face (hlinfo
))
25238 cursor
= No_Cursor
;
25240 if (!row
->reversed_p
)
25242 hlinfo
->mouse_face_beg_col
= hpos
;
25243 hlinfo
->mouse_face_beg_x
= original_x_pixel
25244 - (total_pixel_width
+ dx
);
25245 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25246 hlinfo
->mouse_face_end_x
= 0;
25250 /* In R2L rows, show_mouse_face expects BEG and END
25251 coordinates to be swapped. */
25252 hlinfo
->mouse_face_end_col
= hpos
;
25253 hlinfo
->mouse_face_end_x
= original_x_pixel
25254 - (total_pixel_width
+ dx
);
25255 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25256 hlinfo
->mouse_face_beg_x
= 0;
25259 hlinfo
->mouse_face_beg_row
= vpos
;
25260 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25261 hlinfo
->mouse_face_beg_y
= 0;
25262 hlinfo
->mouse_face_end_y
= 0;
25263 hlinfo
->mouse_face_past_end
= 0;
25264 hlinfo
->mouse_face_window
= window
;
25266 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25272 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25274 if (NILP (pointer
))
25277 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25278 clear_mouse_face (hlinfo
);
25280 #ifdef HAVE_WINDOW_SYSTEM
25281 if (FRAME_WINDOW_P (f
))
25282 define_frame_cursor1 (f
, cursor
, pointer
);
25288 Take proper action when the mouse has moved to position X, Y on
25289 frame F as regards highlighting characters that have mouse-face
25290 properties. Also de-highlighting chars where the mouse was before.
25291 X and Y can be negative or out of range. */
25294 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25296 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25297 enum window_part part
;
25298 Lisp_Object window
;
25300 Cursor cursor
= No_Cursor
;
25301 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25304 /* When a menu is active, don't highlight because this looks odd. */
25305 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25306 if (popup_activated ())
25310 if (NILP (Vmouse_highlight
)
25311 || !f
->glyphs_initialized_p
25312 || f
->pointer_invisible
)
25315 hlinfo
->mouse_face_mouse_x
= x
;
25316 hlinfo
->mouse_face_mouse_y
= y
;
25317 hlinfo
->mouse_face_mouse_frame
= f
;
25319 if (hlinfo
->mouse_face_defer
)
25322 if (gc_in_progress
)
25324 hlinfo
->mouse_face_deferred_gc
= 1;
25328 /* Which window is that in? */
25329 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25331 /* If we were displaying active text in another window, clear that.
25332 Also clear if we move out of text area in same window. */
25333 if (! EQ (window
, hlinfo
->mouse_face_window
)
25334 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25335 && !NILP (hlinfo
->mouse_face_window
)))
25336 clear_mouse_face (hlinfo
);
25338 /* Not on a window -> return. */
25339 if (!WINDOWP (window
))
25342 /* Reset help_echo_string. It will get recomputed below. */
25343 help_echo_string
= Qnil
;
25345 /* Convert to window-relative pixel coordinates. */
25346 w
= XWINDOW (window
);
25347 frame_to_window_pixel_xy (w
, &x
, &y
);
25349 #ifdef HAVE_WINDOW_SYSTEM
25350 /* Handle tool-bar window differently since it doesn't display a
25352 if (EQ (window
, f
->tool_bar_window
))
25354 note_tool_bar_highlight (f
, x
, y
);
25359 /* Mouse is on the mode, header line or margin? */
25360 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25361 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25363 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25367 #ifdef HAVE_WINDOW_SYSTEM
25368 if (part
== ON_VERTICAL_BORDER
)
25370 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25371 help_echo_string
= build_string ("drag-mouse-1: resize");
25373 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25374 || part
== ON_SCROLL_BAR
)
25375 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25377 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25380 /* Are we in a window whose display is up to date?
25381 And verify the buffer's text has not changed. */
25382 b
= XBUFFER (w
->buffer
);
25383 if (part
== ON_TEXT
25384 && EQ (w
->window_end_valid
, w
->buffer
)
25385 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25386 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25388 int hpos
, vpos
, i
, dx
, dy
, area
;
25390 struct glyph
*glyph
;
25391 Lisp_Object object
;
25392 Lisp_Object mouse_face
= Qnil
, position
;
25393 Lisp_Object
*overlay_vec
= NULL
;
25395 struct buffer
*obuf
;
25396 EMACS_INT obegv
, ozv
;
25399 /* Find the glyph under X/Y. */
25400 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25402 #ifdef HAVE_WINDOW_SYSTEM
25403 /* Look for :pointer property on image. */
25404 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25406 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25407 if (img
!= NULL
&& IMAGEP (img
->spec
))
25409 Lisp_Object image_map
, hotspot
;
25410 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25412 && (hotspot
= find_hot_spot (image_map
,
25413 glyph
->slice
.img
.x
+ dx
,
25414 glyph
->slice
.img
.y
+ dy
),
25416 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25420 /* Could check XCAR (hotspot) to see if we enter/leave
25422 If so, we could look for mouse-enter, mouse-leave
25423 properties in PLIST (and do something...). */
25424 hotspot
= XCDR (hotspot
);
25425 if (CONSP (hotspot
)
25426 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25428 pointer
= Fplist_get (plist
, Qpointer
);
25429 if (NILP (pointer
))
25431 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25432 if (!NILP (help_echo_string
))
25434 help_echo_window
= window
;
25435 help_echo_object
= glyph
->object
;
25436 help_echo_pos
= glyph
->charpos
;
25440 if (NILP (pointer
))
25441 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25444 #endif /* HAVE_WINDOW_SYSTEM */
25446 /* Clear mouse face if X/Y not over text. */
25448 || area
!= TEXT_AREA
25449 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25450 /* Glyph's OBJECT is an integer for glyphs inserted by the
25451 display engine for its internal purposes, like truncation
25452 and continuation glyphs and blanks beyond the end of
25453 line's text on text terminals. If we are over such a
25454 glyph, we are not over any text. */
25455 || INTEGERP (glyph
->object
)
25456 /* R2L rows have a stretch glyph at their front, which
25457 stands for no text, whereas L2R rows have no glyphs at
25458 all beyond the end of text. Treat such stretch glyphs
25459 like we do with NULL glyphs in L2R rows. */
25460 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25461 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25462 && glyph
->type
== STRETCH_GLYPH
25463 && glyph
->avoid_cursor_p
))
25465 if (clear_mouse_face (hlinfo
))
25466 cursor
= No_Cursor
;
25467 #ifdef HAVE_WINDOW_SYSTEM
25468 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25470 if (area
!= TEXT_AREA
)
25471 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25473 pointer
= Vvoid_text_area_pointer
;
25479 pos
= glyph
->charpos
;
25480 object
= glyph
->object
;
25481 if (!STRINGP (object
) && !BUFFERP (object
))
25484 /* If we get an out-of-range value, return now; avoid an error. */
25485 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25488 /* Make the window's buffer temporarily current for
25489 overlays_at and compute_char_face. */
25490 obuf
= current_buffer
;
25491 current_buffer
= b
;
25497 /* Is this char mouse-active or does it have help-echo? */
25498 position
= make_number (pos
);
25500 if (BUFFERP (object
))
25502 /* Put all the overlays we want in a vector in overlay_vec. */
25503 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25504 /* Sort overlays into increasing priority order. */
25505 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25510 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25513 cursor
= No_Cursor
;
25515 /* Check mouse-face highlighting. */
25517 /* If there exists an overlay with mouse-face overlapping
25518 the one we are currently highlighting, we have to
25519 check if we enter the overlapping overlay, and then
25520 highlight only that. */
25521 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25522 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25524 /* Find the highest priority overlay with a mouse-face. */
25525 Lisp_Object overlay
= Qnil
;
25526 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25528 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25529 if (!NILP (mouse_face
))
25530 overlay
= overlay_vec
[i
];
25533 /* If we're highlighting the same overlay as before, there's
25534 no need to do that again. */
25535 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25536 goto check_help_echo
;
25537 hlinfo
->mouse_face_overlay
= overlay
;
25539 /* Clear the display of the old active region, if any. */
25540 if (clear_mouse_face (hlinfo
))
25541 cursor
= No_Cursor
;
25543 /* If no overlay applies, get a text property. */
25544 if (NILP (overlay
))
25545 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25547 /* Next, compute the bounds of the mouse highlighting and
25549 if (!NILP (mouse_face
) && STRINGP (object
))
25551 /* The mouse-highlighting comes from a display string
25552 with a mouse-face. */
25556 s
= Fprevious_single_property_change
25557 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25558 e
= Fnext_single_property_change
25559 (position
, Qmouse_face
, object
, Qnil
);
25561 s
= make_number (0);
25563 e
= make_number (SCHARS (object
) - 1);
25564 mouse_face_from_string_pos (w
, hlinfo
, object
,
25565 XINT (s
), XINT (e
));
25566 hlinfo
->mouse_face_past_end
= 0;
25567 hlinfo
->mouse_face_window
= window
;
25568 hlinfo
->mouse_face_face_id
25569 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25570 glyph
->face_id
, 1);
25571 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25572 cursor
= No_Cursor
;
25576 /* The mouse-highlighting, if any, comes from an overlay
25577 or text property in the buffer. */
25578 Lisp_Object buffer
IF_LINT (= Qnil
);
25579 Lisp_Object cover_string
IF_LINT (= Qnil
);
25581 if (STRINGP (object
))
25583 /* If we are on a display string with no mouse-face,
25584 check if the text under it has one. */
25585 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25586 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25587 pos
= string_buffer_position (object
, start
);
25590 mouse_face
= get_char_property_and_overlay
25591 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
25592 buffer
= w
->buffer
;
25593 cover_string
= object
;
25599 cover_string
= Qnil
;
25602 if (!NILP (mouse_face
))
25604 Lisp_Object before
, after
;
25605 Lisp_Object before_string
, after_string
;
25606 /* To correctly find the limits of mouse highlight
25607 in a bidi-reordered buffer, we must not use the
25608 optimization of limiting the search in
25609 previous-single-property-change and
25610 next-single-property-change, because
25611 rows_from_pos_range needs the real start and end
25612 positions to DTRT in this case. That's because
25613 the first row visible in a window does not
25614 necessarily display the character whose position
25615 is the smallest. */
25617 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
25618 ? Fmarker_position (w
->start
)
25621 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
25622 ? make_number (BUF_Z (XBUFFER (buffer
))
25623 - XFASTINT (w
->window_end_pos
))
25626 if (NILP (overlay
))
25628 /* Handle the text property case. */
25629 before
= Fprevious_single_property_change
25630 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
25631 after
= Fnext_single_property_change
25632 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
25633 before_string
= after_string
= Qnil
;
25637 /* Handle the overlay case. */
25638 before
= Foverlay_start (overlay
);
25639 after
= Foverlay_end (overlay
);
25640 before_string
= Foverlay_get (overlay
, Qbefore_string
);
25641 after_string
= Foverlay_get (overlay
, Qafter_string
);
25643 if (!STRINGP (before_string
)) before_string
= Qnil
;
25644 if (!STRINGP (after_string
)) after_string
= Qnil
;
25647 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
25650 before_string
, after_string
,
25652 cursor
= No_Cursor
;
25659 /* Look for a `help-echo' property. */
25660 if (NILP (help_echo_string
)) {
25661 Lisp_Object help
, overlay
;
25663 /* Check overlays first. */
25664 help
= overlay
= Qnil
;
25665 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
25667 overlay
= overlay_vec
[i
];
25668 help
= Foverlay_get (overlay
, Qhelp_echo
);
25673 help_echo_string
= help
;
25674 help_echo_window
= window
;
25675 help_echo_object
= overlay
;
25676 help_echo_pos
= pos
;
25680 Lisp_Object obj
= glyph
->object
;
25681 EMACS_INT charpos
= glyph
->charpos
;
25683 /* Try text properties. */
25686 && charpos
< SCHARS (obj
))
25688 help
= Fget_text_property (make_number (charpos
),
25692 /* If the string itself doesn't specify a help-echo,
25693 see if the buffer text ``under'' it does. */
25694 struct glyph_row
*r
25695 = MATRIX_ROW (w
->current_matrix
, vpos
);
25696 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25697 EMACS_INT p
= string_buffer_position (obj
, start
);
25700 help
= Fget_char_property (make_number (p
),
25701 Qhelp_echo
, w
->buffer
);
25710 else if (BUFFERP (obj
)
25713 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
25718 help_echo_string
= help
;
25719 help_echo_window
= window
;
25720 help_echo_object
= obj
;
25721 help_echo_pos
= charpos
;
25726 #ifdef HAVE_WINDOW_SYSTEM
25727 /* Look for a `pointer' property. */
25728 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25730 /* Check overlays first. */
25731 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
25732 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
25734 if (NILP (pointer
))
25736 Lisp_Object obj
= glyph
->object
;
25737 EMACS_INT charpos
= glyph
->charpos
;
25739 /* Try text properties. */
25742 && charpos
< SCHARS (obj
))
25744 pointer
= Fget_text_property (make_number (charpos
),
25746 if (NILP (pointer
))
25748 /* If the string itself doesn't specify a pointer,
25749 see if the buffer text ``under'' it does. */
25750 struct glyph_row
*r
25751 = MATRIX_ROW (w
->current_matrix
, vpos
);
25752 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25753 EMACS_INT p
= string_buffer_position (obj
, start
);
25755 pointer
= Fget_char_property (make_number (p
),
25756 Qpointer
, w
->buffer
);
25759 else if (BUFFERP (obj
)
25762 pointer
= Fget_text_property (make_number (charpos
),
25766 #endif /* HAVE_WINDOW_SYSTEM */
25770 current_buffer
= obuf
;
25775 #ifdef HAVE_WINDOW_SYSTEM
25776 if (FRAME_WINDOW_P (f
))
25777 define_frame_cursor1 (f
, cursor
, pointer
);
25779 /* This is here to prevent a compiler error, about "label at end of
25780 compound statement". */
25787 Clear any mouse-face on window W. This function is part of the
25788 redisplay interface, and is called from try_window_id and similar
25789 functions to ensure the mouse-highlight is off. */
25792 x_clear_window_mouse_face (struct window
*w
)
25794 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25795 Lisp_Object window
;
25798 XSETWINDOW (window
, w
);
25799 if (EQ (window
, hlinfo
->mouse_face_window
))
25800 clear_mouse_face (hlinfo
);
25806 Just discard the mouse face information for frame F, if any.
25807 This is used when the size of F is changed. */
25810 cancel_mouse_face (struct frame
*f
)
25812 Lisp_Object window
;
25813 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25815 window
= hlinfo
->mouse_face_window
;
25816 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
25818 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25819 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25820 hlinfo
->mouse_face_window
= Qnil
;
25826 /***********************************************************************
25828 ***********************************************************************/
25830 #ifdef HAVE_WINDOW_SYSTEM
25832 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
25833 which intersects rectangle R. R is in window-relative coordinates. */
25836 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
25837 enum glyph_row_area area
)
25839 struct glyph
*first
= row
->glyphs
[area
];
25840 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25841 struct glyph
*last
;
25842 int first_x
, start_x
, x
;
25844 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25845 /* If row extends face to end of line write the whole line. */
25846 draw_glyphs (w
, 0, row
, area
,
25847 0, row
->used
[area
],
25848 DRAW_NORMAL_TEXT
, 0);
25851 /* Set START_X to the window-relative start position for drawing glyphs of
25852 AREA. The first glyph of the text area can be partially visible.
25853 The first glyphs of other areas cannot. */
25854 start_x
= window_box_left_offset (w
, area
);
25856 if (area
== TEXT_AREA
)
25859 /* Find the first glyph that must be redrawn. */
25861 && x
+ first
->pixel_width
< r
->x
)
25863 x
+= first
->pixel_width
;
25867 /* Find the last one. */
25871 && x
< r
->x
+ r
->width
)
25873 x
+= last
->pixel_width
;
25879 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25880 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25881 DRAW_NORMAL_TEXT
, 0);
25886 /* Redraw the parts of the glyph row ROW on window W intersecting
25887 rectangle R. R is in window-relative coordinates. Value is
25888 non-zero if mouse-face was overwritten. */
25891 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
25893 xassert (row
->enabled_p
);
25895 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25896 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25897 0, row
->used
[TEXT_AREA
],
25898 DRAW_NORMAL_TEXT
, 0);
25901 if (row
->used
[LEFT_MARGIN_AREA
])
25902 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25903 if (row
->used
[TEXT_AREA
])
25904 expose_area (w
, row
, r
, TEXT_AREA
);
25905 if (row
->used
[RIGHT_MARGIN_AREA
])
25906 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25907 draw_row_fringe_bitmaps (w
, row
);
25910 return row
->mouse_face_p
;
25914 /* Redraw those parts of glyphs rows during expose event handling that
25915 overlap other rows. Redrawing of an exposed line writes over parts
25916 of lines overlapping that exposed line; this function fixes that.
25918 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25919 row in W's current matrix that is exposed and overlaps other rows.
25920 LAST_OVERLAPPING_ROW is the last such row. */
25923 expose_overlaps (struct window
*w
,
25924 struct glyph_row
*first_overlapping_row
,
25925 struct glyph_row
*last_overlapping_row
,
25928 struct glyph_row
*row
;
25930 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
25931 if (row
->overlapping_p
)
25933 xassert (row
->enabled_p
&& !row
->mode_line_p
);
25936 if (row
->used
[LEFT_MARGIN_AREA
])
25937 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
25939 if (row
->used
[TEXT_AREA
])
25940 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
25942 if (row
->used
[RIGHT_MARGIN_AREA
])
25943 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
25949 /* Return non-zero if W's cursor intersects rectangle R. */
25952 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
25954 XRectangle cr
, result
;
25955 struct glyph
*cursor_glyph
;
25956 struct glyph_row
*row
;
25958 if (w
->phys_cursor
.vpos
>= 0
25959 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
25960 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
25962 && row
->cursor_in_fringe_p
)
25964 /* Cursor is in the fringe. */
25965 cr
.x
= window_box_right_offset (w
,
25966 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
25967 ? RIGHT_MARGIN_AREA
25970 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
25971 cr
.height
= row
->height
;
25972 return x_intersect_rectangles (&cr
, r
, &result
);
25975 cursor_glyph
= get_phys_cursor_glyph (w
);
25978 /* r is relative to W's box, but w->phys_cursor.x is relative
25979 to left edge of W's TEXT area. Adjust it. */
25980 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
25981 cr
.y
= w
->phys_cursor
.y
;
25982 cr
.width
= cursor_glyph
->pixel_width
;
25983 cr
.height
= w
->phys_cursor_height
;
25984 /* ++KFS: W32 version used W32-specific IntersectRect here, but
25985 I assume the effect is the same -- and this is portable. */
25986 return x_intersect_rectangles (&cr
, r
, &result
);
25988 /* If we don't understand the format, pretend we're not in the hot-spot. */
25994 Draw a vertical window border to the right of window W if W doesn't
25995 have vertical scroll bars. */
25998 x_draw_vertical_border (struct window
*w
)
26000 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26002 /* We could do better, if we knew what type of scroll-bar the adjacent
26003 windows (on either side) have... But we don't :-(
26004 However, I think this works ok. ++KFS 2003-04-25 */
26006 /* Redraw borders between horizontally adjacent windows. Don't
26007 do it for frames with vertical scroll bars because either the
26008 right scroll bar of a window, or the left scroll bar of its
26009 neighbor will suffice as a border. */
26010 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26013 if (!WINDOW_RIGHTMOST_P (w
)
26014 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26016 int x0
, x1
, y0
, y1
;
26018 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26021 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26024 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26026 else if (!WINDOW_LEFTMOST_P (w
)
26027 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26029 int x0
, x1
, y0
, y1
;
26031 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26034 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26037 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26042 /* Redraw the part of window W intersection rectangle FR. Pixel
26043 coordinates in FR are frame-relative. Call this function with
26044 input blocked. Value is non-zero if the exposure overwrites
26048 expose_window (struct window
*w
, XRectangle
*fr
)
26050 struct frame
*f
= XFRAME (w
->frame
);
26052 int mouse_face_overwritten_p
= 0;
26054 /* If window is not yet fully initialized, do nothing. This can
26055 happen when toolkit scroll bars are used and a window is split.
26056 Reconfiguring the scroll bar will generate an expose for a newly
26058 if (w
->current_matrix
== NULL
)
26061 /* When we're currently updating the window, display and current
26062 matrix usually don't agree. Arrange for a thorough display
26064 if (w
== updated_window
)
26066 SET_FRAME_GARBAGED (f
);
26070 /* Frame-relative pixel rectangle of W. */
26071 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26072 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26073 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26074 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26076 if (x_intersect_rectangles (fr
, &wr
, &r
))
26078 int yb
= window_text_bottom_y (w
);
26079 struct glyph_row
*row
;
26080 int cursor_cleared_p
;
26081 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26083 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26084 r
.x
, r
.y
, r
.width
, r
.height
));
26086 /* Convert to window coordinates. */
26087 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26088 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26090 /* Turn off the cursor. */
26091 if (!w
->pseudo_window_p
26092 && phys_cursor_in_rect_p (w
, &r
))
26094 x_clear_cursor (w
);
26095 cursor_cleared_p
= 1;
26098 cursor_cleared_p
= 0;
26100 /* Update lines intersecting rectangle R. */
26101 first_overlapping_row
= last_overlapping_row
= NULL
;
26102 for (row
= w
->current_matrix
->rows
;
26107 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26109 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26110 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26111 || (r
.y
>= y0
&& r
.y
< y1
)
26112 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26114 /* A header line may be overlapping, but there is no need
26115 to fix overlapping areas for them. KFS 2005-02-12 */
26116 if (row
->overlapping_p
&& !row
->mode_line_p
)
26118 if (first_overlapping_row
== NULL
)
26119 first_overlapping_row
= row
;
26120 last_overlapping_row
= row
;
26124 if (expose_line (w
, row
, &r
))
26125 mouse_face_overwritten_p
= 1;
26128 else if (row
->overlapping_p
)
26130 /* We must redraw a row overlapping the exposed area. */
26132 ? y0
+ row
->phys_height
> r
.y
26133 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26135 if (first_overlapping_row
== NULL
)
26136 first_overlapping_row
= row
;
26137 last_overlapping_row
= row
;
26145 /* Display the mode line if there is one. */
26146 if (WINDOW_WANTS_MODELINE_P (w
)
26147 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26149 && row
->y
< r
.y
+ r
.height
)
26151 if (expose_line (w
, row
, &r
))
26152 mouse_face_overwritten_p
= 1;
26155 if (!w
->pseudo_window_p
)
26157 /* Fix the display of overlapping rows. */
26158 if (first_overlapping_row
)
26159 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26162 /* Draw border between windows. */
26163 x_draw_vertical_border (w
);
26165 /* Turn the cursor on again. */
26166 if (cursor_cleared_p
)
26167 update_window_cursor (w
, 1);
26171 return mouse_face_overwritten_p
;
26176 /* Redraw (parts) of all windows in the window tree rooted at W that
26177 intersect R. R contains frame pixel coordinates. Value is
26178 non-zero if the exposure overwrites mouse-face. */
26181 expose_window_tree (struct window
*w
, XRectangle
*r
)
26183 struct frame
*f
= XFRAME (w
->frame
);
26184 int mouse_face_overwritten_p
= 0;
26186 while (w
&& !FRAME_GARBAGED_P (f
))
26188 if (!NILP (w
->hchild
))
26189 mouse_face_overwritten_p
26190 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26191 else if (!NILP (w
->vchild
))
26192 mouse_face_overwritten_p
26193 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26195 mouse_face_overwritten_p
|= expose_window (w
, r
);
26197 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26200 return mouse_face_overwritten_p
;
26205 Redisplay an exposed area of frame F. X and Y are the upper-left
26206 corner of the exposed rectangle. W and H are width and height of
26207 the exposed area. All are pixel values. W or H zero means redraw
26208 the entire frame. */
26211 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26214 int mouse_face_overwritten_p
= 0;
26216 TRACE ((stderr
, "expose_frame "));
26218 /* No need to redraw if frame will be redrawn soon. */
26219 if (FRAME_GARBAGED_P (f
))
26221 TRACE ((stderr
, " garbaged\n"));
26225 /* If basic faces haven't been realized yet, there is no point in
26226 trying to redraw anything. This can happen when we get an expose
26227 event while Emacs is starting, e.g. by moving another window. */
26228 if (FRAME_FACE_CACHE (f
) == NULL
26229 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26231 TRACE ((stderr
, " no faces\n"));
26235 if (w
== 0 || h
== 0)
26238 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26239 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26249 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26250 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26252 if (WINDOWP (f
->tool_bar_window
))
26253 mouse_face_overwritten_p
26254 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26256 #ifdef HAVE_X_WINDOWS
26258 #ifndef USE_X_TOOLKIT
26259 if (WINDOWP (f
->menu_bar_window
))
26260 mouse_face_overwritten_p
26261 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26262 #endif /* not USE_X_TOOLKIT */
26266 /* Some window managers support a focus-follows-mouse style with
26267 delayed raising of frames. Imagine a partially obscured frame,
26268 and moving the mouse into partially obscured mouse-face on that
26269 frame. The visible part of the mouse-face will be highlighted,
26270 then the WM raises the obscured frame. With at least one WM, KDE
26271 2.1, Emacs is not getting any event for the raising of the frame
26272 (even tried with SubstructureRedirectMask), only Expose events.
26273 These expose events will draw text normally, i.e. not
26274 highlighted. Which means we must redo the highlight here.
26275 Subsume it under ``we love X''. --gerd 2001-08-15 */
26276 /* Included in Windows version because Windows most likely does not
26277 do the right thing if any third party tool offers
26278 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26279 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26281 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26282 if (f
== hlinfo
->mouse_face_mouse_frame
)
26284 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26285 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26286 clear_mouse_face (hlinfo
);
26287 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26294 Determine the intersection of two rectangles R1 and R2. Return
26295 the intersection in *RESULT. Value is non-zero if RESULT is not
26299 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26301 XRectangle
*left
, *right
;
26302 XRectangle
*upper
, *lower
;
26303 int intersection_p
= 0;
26305 /* Rearrange so that R1 is the left-most rectangle. */
26307 left
= r1
, right
= r2
;
26309 left
= r2
, right
= r1
;
26311 /* X0 of the intersection is right.x0, if this is inside R1,
26312 otherwise there is no intersection. */
26313 if (right
->x
<= left
->x
+ left
->width
)
26315 result
->x
= right
->x
;
26317 /* The right end of the intersection is the minimum of the
26318 the right ends of left and right. */
26319 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26322 /* Same game for Y. */
26324 upper
= r1
, lower
= r2
;
26326 upper
= r2
, lower
= r1
;
26328 /* The upper end of the intersection is lower.y0, if this is inside
26329 of upper. Otherwise, there is no intersection. */
26330 if (lower
->y
<= upper
->y
+ upper
->height
)
26332 result
->y
= lower
->y
;
26334 /* The lower end of the intersection is the minimum of the lower
26335 ends of upper and lower. */
26336 result
->height
= (min (lower
->y
+ lower
->height
,
26337 upper
->y
+ upper
->height
)
26339 intersection_p
= 1;
26343 return intersection_p
;
26346 #endif /* HAVE_WINDOW_SYSTEM */
26349 /***********************************************************************
26351 ***********************************************************************/
26354 syms_of_xdisp (void)
26356 Vwith_echo_area_save_vector
= Qnil
;
26357 staticpro (&Vwith_echo_area_save_vector
);
26359 Vmessage_stack
= Qnil
;
26360 staticpro (&Vmessage_stack
);
26362 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26363 staticpro (&Qinhibit_redisplay
);
26365 message_dolog_marker1
= Fmake_marker ();
26366 staticpro (&message_dolog_marker1
);
26367 message_dolog_marker2
= Fmake_marker ();
26368 staticpro (&message_dolog_marker2
);
26369 message_dolog_marker3
= Fmake_marker ();
26370 staticpro (&message_dolog_marker3
);
26373 defsubr (&Sdump_frame_glyph_matrix
);
26374 defsubr (&Sdump_glyph_matrix
);
26375 defsubr (&Sdump_glyph_row
);
26376 defsubr (&Sdump_tool_bar_row
);
26377 defsubr (&Strace_redisplay
);
26378 defsubr (&Strace_to_stderr
);
26380 #ifdef HAVE_WINDOW_SYSTEM
26381 defsubr (&Stool_bar_lines_needed
);
26382 defsubr (&Slookup_image_map
);
26384 defsubr (&Sformat_mode_line
);
26385 defsubr (&Sinvisible_p
);
26386 defsubr (&Scurrent_bidi_paragraph_direction
);
26388 staticpro (&Qmenu_bar_update_hook
);
26389 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26391 staticpro (&Qoverriding_terminal_local_map
);
26392 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26394 staticpro (&Qoverriding_local_map
);
26395 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26397 staticpro (&Qwindow_scroll_functions
);
26398 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26400 staticpro (&Qwindow_text_change_functions
);
26401 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26403 staticpro (&Qredisplay_end_trigger_functions
);
26404 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26406 staticpro (&Qinhibit_point_motion_hooks
);
26407 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26409 Qeval
= intern_c_string ("eval");
26410 staticpro (&Qeval
);
26412 QCdata
= intern_c_string (":data");
26413 staticpro (&QCdata
);
26414 Qdisplay
= intern_c_string ("display");
26415 staticpro (&Qdisplay
);
26416 Qspace_width
= intern_c_string ("space-width");
26417 staticpro (&Qspace_width
);
26418 Qraise
= intern_c_string ("raise");
26419 staticpro (&Qraise
);
26420 Qslice
= intern_c_string ("slice");
26421 staticpro (&Qslice
);
26422 Qspace
= intern_c_string ("space");
26423 staticpro (&Qspace
);
26424 Qmargin
= intern_c_string ("margin");
26425 staticpro (&Qmargin
);
26426 Qpointer
= intern_c_string ("pointer");
26427 staticpro (&Qpointer
);
26428 Qleft_margin
= intern_c_string ("left-margin");
26429 staticpro (&Qleft_margin
);
26430 Qright_margin
= intern_c_string ("right-margin");
26431 staticpro (&Qright_margin
);
26432 Qcenter
= intern_c_string ("center");
26433 staticpro (&Qcenter
);
26434 Qline_height
= intern_c_string ("line-height");
26435 staticpro (&Qline_height
);
26436 QCalign_to
= intern_c_string (":align-to");
26437 staticpro (&QCalign_to
);
26438 QCrelative_width
= intern_c_string (":relative-width");
26439 staticpro (&QCrelative_width
);
26440 QCrelative_height
= intern_c_string (":relative-height");
26441 staticpro (&QCrelative_height
);
26442 QCeval
= intern_c_string (":eval");
26443 staticpro (&QCeval
);
26444 QCpropertize
= intern_c_string (":propertize");
26445 staticpro (&QCpropertize
);
26446 QCfile
= intern_c_string (":file");
26447 staticpro (&QCfile
);
26448 Qfontified
= intern_c_string ("fontified");
26449 staticpro (&Qfontified
);
26450 Qfontification_functions
= intern_c_string ("fontification-functions");
26451 staticpro (&Qfontification_functions
);
26452 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26453 staticpro (&Qtrailing_whitespace
);
26454 Qescape_glyph
= intern_c_string ("escape-glyph");
26455 staticpro (&Qescape_glyph
);
26456 Qnobreak_space
= intern_c_string ("nobreak-space");
26457 staticpro (&Qnobreak_space
);
26458 Qimage
= intern_c_string ("image");
26459 staticpro (&Qimage
);
26460 Qtext
= intern_c_string ("text");
26461 staticpro (&Qtext
);
26462 Qboth
= intern_c_string ("both");
26463 staticpro (&Qboth
);
26464 Qboth_horiz
= intern_c_string ("both-horiz");
26465 staticpro (&Qboth_horiz
);
26466 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26467 staticpro (&Qtext_image_horiz
);
26468 QCmap
= intern_c_string (":map");
26469 staticpro (&QCmap
);
26470 QCpointer
= intern_c_string (":pointer");
26471 staticpro (&QCpointer
);
26472 Qrect
= intern_c_string ("rect");
26473 staticpro (&Qrect
);
26474 Qcircle
= intern_c_string ("circle");
26475 staticpro (&Qcircle
);
26476 Qpoly
= intern_c_string ("poly");
26477 staticpro (&Qpoly
);
26478 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
26479 staticpro (&Qmessage_truncate_lines
);
26480 Qgrow_only
= intern_c_string ("grow-only");
26481 staticpro (&Qgrow_only
);
26482 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
26483 staticpro (&Qinhibit_menubar_update
);
26484 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
26485 staticpro (&Qinhibit_eval_during_redisplay
);
26486 Qposition
= intern_c_string ("position");
26487 staticpro (&Qposition
);
26488 Qbuffer_position
= intern_c_string ("buffer-position");
26489 staticpro (&Qbuffer_position
);
26490 Qobject
= intern_c_string ("object");
26491 staticpro (&Qobject
);
26492 Qbar
= intern_c_string ("bar");
26494 Qhbar
= intern_c_string ("hbar");
26495 staticpro (&Qhbar
);
26496 Qbox
= intern_c_string ("box");
26498 Qhollow
= intern_c_string ("hollow");
26499 staticpro (&Qhollow
);
26500 Qhand
= intern_c_string ("hand");
26501 staticpro (&Qhand
);
26502 Qarrow
= intern_c_string ("arrow");
26503 staticpro (&Qarrow
);
26504 Qtext
= intern_c_string ("text");
26505 staticpro (&Qtext
);
26506 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
26507 staticpro (&Qinhibit_free_realized_faces
);
26509 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26510 Fcons (intern_c_string ("void-variable"), Qnil
)),
26512 staticpro (&list_of_error
);
26514 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
26515 staticpro (&Qlast_arrow_position
);
26516 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
26517 staticpro (&Qlast_arrow_string
);
26519 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
26520 staticpro (&Qoverlay_arrow_string
);
26521 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
26522 staticpro (&Qoverlay_arrow_bitmap
);
26524 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26525 staticpro (&echo_buffer
[0]);
26526 staticpro (&echo_buffer
[1]);
26528 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26529 staticpro (&echo_area_buffer
[0]);
26530 staticpro (&echo_area_buffer
[1]);
26532 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26533 staticpro (&Vmessages_buffer_name
);
26535 mode_line_proptrans_alist
= Qnil
;
26536 staticpro (&mode_line_proptrans_alist
);
26537 mode_line_string_list
= Qnil
;
26538 staticpro (&mode_line_string_list
);
26539 mode_line_string_face
= Qnil
;
26540 staticpro (&mode_line_string_face
);
26541 mode_line_string_face_prop
= Qnil
;
26542 staticpro (&mode_line_string_face_prop
);
26543 Vmode_line_unwind_vector
= Qnil
;
26544 staticpro (&Vmode_line_unwind_vector
);
26546 help_echo_string
= Qnil
;
26547 staticpro (&help_echo_string
);
26548 help_echo_object
= Qnil
;
26549 staticpro (&help_echo_object
);
26550 help_echo_window
= Qnil
;
26551 staticpro (&help_echo_window
);
26552 previous_help_echo_string
= Qnil
;
26553 staticpro (&previous_help_echo_string
);
26554 help_echo_pos
= -1;
26556 Qright_to_left
= intern_c_string ("right-to-left");
26557 staticpro (&Qright_to_left
);
26558 Qleft_to_right
= intern_c_string ("left-to-right");
26559 staticpro (&Qleft_to_right
);
26561 #ifdef HAVE_WINDOW_SYSTEM
26562 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
26563 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26564 For example, if a block cursor is over a tab, it will be drawn as
26565 wide as that tab on the display. */);
26566 x_stretch_cursor_p
= 0;
26569 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
26570 doc
: /* *Non-nil means highlight trailing whitespace.
26571 The face used for trailing whitespace is `trailing-whitespace'. */);
26572 Vshow_trailing_whitespace
= Qnil
;
26574 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
26575 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26576 A value of t means highlight the character itself (for nobreak space,
26577 use face `nobreak-space').
26578 A value of nil means no highlighting.
26579 Other values mean display the escape glyph followed by an ordinary
26580 space or ordinary hyphen. */);
26581 Vnobreak_char_display
= Qt
;
26583 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
26584 doc
: /* *The pointer shape to show in void text areas.
26585 A value of nil means to show the text pointer. Other options are `arrow',
26586 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26587 Vvoid_text_area_pointer
= Qarrow
;
26589 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
26590 doc
: /* Non-nil means don't actually do any redisplay.
26591 This is used for internal purposes. */);
26592 Vinhibit_redisplay
= Qnil
;
26594 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
26595 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
26596 Vglobal_mode_string
= Qnil
;
26598 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
26599 doc
: /* Marker for where to display an arrow on top of the buffer text.
26600 This must be the beginning of a line in order to work.
26601 See also `overlay-arrow-string'. */);
26602 Voverlay_arrow_position
= Qnil
;
26604 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
26605 doc
: /* String to display as an arrow in non-window frames.
26606 See also `overlay-arrow-position'. */);
26607 Voverlay_arrow_string
= make_pure_c_string ("=>");
26609 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
26610 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
26611 The symbols on this list are examined during redisplay to determine
26612 where to display overlay arrows. */);
26613 Voverlay_arrow_variable_list
26614 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
26616 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
26617 doc
: /* *The number of lines to try scrolling a window by when point moves out.
26618 If that fails to bring point back on frame, point is centered instead.
26619 If this is zero, point is always centered after it moves off frame.
26620 If you want scrolling to always be a line at a time, you should set
26621 `scroll-conservatively' to a large value rather than set this to 1. */);
26623 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
26624 doc
: /* *Scroll up to this many lines, to bring point back on screen.
26625 If point moves off-screen, redisplay will scroll by up to
26626 `scroll-conservatively' lines in order to bring point just barely
26627 onto the screen again. If that cannot be done, then redisplay
26628 recenters point as usual.
26630 If the value is greater than 100, redisplay will never recenter point,
26631 but will always scroll just enough text to bring point into view, even
26632 if you move far away.
26634 A value of zero means always recenter point if it moves off screen. */);
26635 scroll_conservatively
= 0;
26637 DEFVAR_INT ("scroll-margin", scroll_margin
,
26638 doc
: /* *Number of lines of margin at the top and bottom of a window.
26639 Recenter the window whenever point gets within this many lines
26640 of the top or bottom of the window. */);
26643 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
26644 doc
: /* Pixels per inch value for non-window system displays.
26645 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
26646 Vdisplay_pixels_per_inch
= make_float (72.0);
26649 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
26652 DEFVAR_LISP ("truncate-partial-width-windows",
26653 Vtruncate_partial_width_windows
,
26654 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
26655 For an integer value, truncate lines in each window narrower than the
26656 full frame width, provided the window width is less than that integer;
26657 otherwise, respect the value of `truncate-lines'.
26659 For any other non-nil value, truncate lines in all windows that do
26660 not span the full frame width.
26662 A value of nil means to respect the value of `truncate-lines'.
26664 If `word-wrap' is enabled, you might want to reduce this. */);
26665 Vtruncate_partial_width_windows
= make_number (50);
26667 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
26668 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
26669 Any other value means to use the appropriate face, `mode-line',
26670 `header-line', or `menu' respectively. */);
26671 mode_line_inverse_video
= 1;
26673 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
26674 doc
: /* *Maximum buffer size for which line number should be displayed.
26675 If the buffer is bigger than this, the line number does not appear
26676 in the mode line. A value of nil means no limit. */);
26677 Vline_number_display_limit
= Qnil
;
26679 DEFVAR_INT ("line-number-display-limit-width",
26680 line_number_display_limit_width
,
26681 doc
: /* *Maximum line width (in characters) for line number display.
26682 If the average length of the lines near point is bigger than this, then the
26683 line number may be omitted from the mode line. */);
26684 line_number_display_limit_width
= 200;
26686 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
26687 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
26688 highlight_nonselected_windows
= 0;
26690 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
26691 doc
: /* Non-nil if more than one frame is visible on this display.
26692 Minibuffer-only frames don't count, but iconified frames do.
26693 This variable is not guaranteed to be accurate except while processing
26694 `frame-title-format' and `icon-title-format'. */);
26696 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
26697 doc
: /* Template for displaying the title bar of visible frames.
26698 \(Assuming the window manager supports this feature.)
26700 This variable has the same structure as `mode-line-format', except that
26701 the %c and %l constructs are ignored. It is used only on frames for
26702 which no explicit name has been set \(see `modify-frame-parameters'). */);
26704 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
26705 doc
: /* Template for displaying the title bar of an iconified frame.
26706 \(Assuming the window manager supports this feature.)
26707 This variable has the same structure as `mode-line-format' (which see),
26708 and is used only on frames for which no explicit name has been set
26709 \(see `modify-frame-parameters'). */);
26711 = Vframe_title_format
26712 = pure_cons (intern_c_string ("multiple-frames"),
26713 pure_cons (make_pure_c_string ("%b"),
26714 pure_cons (pure_cons (empty_unibyte_string
,
26715 pure_cons (intern_c_string ("invocation-name"),
26716 pure_cons (make_pure_c_string ("@"),
26717 pure_cons (intern_c_string ("system-name"),
26721 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
26722 doc
: /* Maximum number of lines to keep in the message log buffer.
26723 If nil, disable message logging. If t, log messages but don't truncate
26724 the buffer when it becomes large. */);
26725 Vmessage_log_max
= make_number (100);
26727 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
26728 doc
: /* Functions called before redisplay, if window sizes have changed.
26729 The value should be a list of functions that take one argument.
26730 Just before redisplay, for each frame, if any of its windows have changed
26731 size since the last redisplay, or have been split or deleted,
26732 all the functions in the list are called, with the frame as argument. */);
26733 Vwindow_size_change_functions
= Qnil
;
26735 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
26736 doc
: /* List of functions to call before redisplaying a window with scrolling.
26737 Each function is called with two arguments, the window and its new
26738 display-start position. Note that these functions are also called by
26739 `set-window-buffer'. Also note that the value of `window-end' is not
26740 valid when these functions are called. */);
26741 Vwindow_scroll_functions
= Qnil
;
26743 DEFVAR_LISP ("window-text-change-functions",
26744 Vwindow_text_change_functions
,
26745 doc
: /* Functions to call in redisplay when text in the window might change. */);
26746 Vwindow_text_change_functions
= Qnil
;
26748 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
26749 doc
: /* Functions called when redisplay of a window reaches the end trigger.
26750 Each function is called with two arguments, the window and the end trigger value.
26751 See `set-window-redisplay-end-trigger'. */);
26752 Vredisplay_end_trigger_functions
= Qnil
;
26754 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
26755 doc
: /* *Non-nil means autoselect window with mouse pointer.
26756 If nil, do not autoselect windows.
26757 A positive number means delay autoselection by that many seconds: a
26758 window is autoselected only after the mouse has remained in that
26759 window for the duration of the delay.
26760 A negative number has a similar effect, but causes windows to be
26761 autoselected only after the mouse has stopped moving. \(Because of
26762 the way Emacs compares mouse events, you will occasionally wait twice
26763 that time before the window gets selected.\)
26764 Any other value means to autoselect window instantaneously when the
26765 mouse pointer enters it.
26767 Autoselection selects the minibuffer only if it is active, and never
26768 unselects the minibuffer if it is active.
26770 When customizing this variable make sure that the actual value of
26771 `focus-follows-mouse' matches the behavior of your window manager. */);
26772 Vmouse_autoselect_window
= Qnil
;
26774 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
26775 doc
: /* *Non-nil means automatically resize tool-bars.
26776 This dynamically changes the tool-bar's height to the minimum height
26777 that is needed to make all tool-bar items visible.
26778 If value is `grow-only', the tool-bar's height is only increased
26779 automatically; to decrease the tool-bar height, use \\[recenter]. */);
26780 Vauto_resize_tool_bars
= Qt
;
26782 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
26783 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
26784 auto_raise_tool_bar_buttons_p
= 1;
26786 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
26787 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
26788 make_cursor_line_fully_visible_p
= 1;
26790 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
26791 doc
: /* *Border below tool-bar in pixels.
26792 If an integer, use it as the height of the border.
26793 If it is one of `internal-border-width' or `border-width', use the
26794 value of the corresponding frame parameter.
26795 Otherwise, no border is added below the tool-bar. */);
26796 Vtool_bar_border
= Qinternal_border_width
;
26798 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
26799 doc
: /* *Margin around tool-bar buttons in pixels.
26800 If an integer, use that for both horizontal and vertical margins.
26801 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
26802 HORZ specifying the horizontal margin, and VERT specifying the
26803 vertical margin. */);
26804 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
26806 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
26807 doc
: /* *Relief thickness of tool-bar buttons. */);
26808 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
26810 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
26811 doc
: /* Tool bar style to use.
26813 image - show images only
26814 text - show text only
26815 both - show both, text below image
26816 both-horiz - show text to the right of the image
26817 text-image-horiz - show text to the left of the image
26818 any other - use system default or image if no system default. */);
26819 Vtool_bar_style
= Qnil
;
26821 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
26822 doc
: /* *Maximum number of characters a label can have to be shown.
26823 The tool bar style must also show labels for this to have any effect, see
26824 `tool-bar-style'. */);
26825 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
26827 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
26828 doc
: /* List of functions to call to fontify regions of text.
26829 Each function is called with one argument POS. Functions must
26830 fontify a region starting at POS in the current buffer, and give
26831 fontified regions the property `fontified'. */);
26832 Vfontification_functions
= Qnil
;
26833 Fmake_variable_buffer_local (Qfontification_functions
);
26835 DEFVAR_BOOL ("unibyte-display-via-language-environment",
26836 unibyte_display_via_language_environment
,
26837 doc
: /* *Non-nil means display unibyte text according to language environment.
26838 Specifically, this means that raw bytes in the range 160-255 decimal
26839 are displayed by converting them to the equivalent multibyte characters
26840 according to the current language environment. As a result, they are
26841 displayed according to the current fontset.
26843 Note that this variable affects only how these bytes are displayed,
26844 but does not change the fact they are interpreted as raw bytes. */);
26845 unibyte_display_via_language_environment
= 0;
26847 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
26848 doc
: /* *Maximum height for resizing mini-windows.
26849 If a float, it specifies a fraction of the mini-window frame's height.
26850 If an integer, it specifies a number of lines. */);
26851 Vmax_mini_window_height
= make_float (0.25);
26853 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
26854 doc
: /* *How to resize mini-windows.
26855 A value of nil means don't automatically resize mini-windows.
26856 A value of t means resize them to fit the text displayed in them.
26857 A value of `grow-only', the default, means let mini-windows grow
26858 only, until their display becomes empty, at which point the windows
26859 go back to their normal size. */);
26860 Vresize_mini_windows
= Qgrow_only
;
26862 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
26863 doc
: /* Alist specifying how to blink the cursor off.
26864 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26865 `cursor-type' frame-parameter or variable equals ON-STATE,
26866 comparing using `equal', Emacs uses OFF-STATE to specify
26867 how to blink it off. ON-STATE and OFF-STATE are values for
26868 the `cursor-type' frame parameter.
26870 If a frame's ON-STATE has no entry in this list,
26871 the frame's other specifications determine how to blink the cursor off. */);
26872 Vblink_cursor_alist
= Qnil
;
26874 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
26875 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
26876 If non-nil, windows are automatically scrolled horizontally to make
26877 point visible. */);
26878 automatic_hscrolling_p
= 1;
26879 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
26880 staticpro (&Qauto_hscroll_mode
);
26882 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
26883 doc
: /* *How many columns away from the window edge point is allowed to get
26884 before automatic hscrolling will horizontally scroll the window. */);
26885 hscroll_margin
= 5;
26887 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
26888 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
26889 When point is less than `hscroll-margin' columns from the window
26890 edge, automatic hscrolling will scroll the window by the amount of columns
26891 determined by this variable. If its value is a positive integer, scroll that
26892 many columns. If it's a positive floating-point number, it specifies the
26893 fraction of the window's width to scroll. If it's nil or zero, point will be
26894 centered horizontally after the scroll. Any other value, including negative
26895 numbers, are treated as if the value were zero.
26897 Automatic hscrolling always moves point outside the scroll margin, so if
26898 point was more than scroll step columns inside the margin, the window will
26899 scroll more than the value given by the scroll step.
26901 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26902 and `scroll-right' overrides this variable's effect. */);
26903 Vhscroll_step
= make_number (0);
26905 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
26906 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26907 Bind this around calls to `message' to let it take effect. */);
26908 message_truncate_lines
= 0;
26910 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
26911 doc
: /* Normal hook run to update the menu bar definitions.
26912 Redisplay runs this hook before it redisplays the menu bar.
26913 This is used to update submenus such as Buffers,
26914 whose contents depend on various data. */);
26915 Vmenu_bar_update_hook
= Qnil
;
26917 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
26918 doc
: /* Frame for which we are updating a menu.
26919 The enable predicate for a menu binding should check this variable. */);
26920 Vmenu_updating_frame
= Qnil
;
26922 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
26923 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26924 inhibit_menubar_update
= 0;
26926 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
26927 doc
: /* Prefix prepended to all continuation lines at display time.
26928 The value may be a string, an image, or a stretch-glyph; it is
26929 interpreted in the same way as the value of a `display' text property.
26931 This variable is overridden by any `wrap-prefix' text or overlay
26934 To add a prefix to non-continuation lines, use `line-prefix'. */);
26935 Vwrap_prefix
= Qnil
;
26936 staticpro (&Qwrap_prefix
);
26937 Qwrap_prefix
= intern_c_string ("wrap-prefix");
26938 Fmake_variable_buffer_local (Qwrap_prefix
);
26940 DEFVAR_LISP ("line-prefix", Vline_prefix
,
26941 doc
: /* Prefix prepended to all non-continuation lines at display time.
26942 The value may be a string, an image, or a stretch-glyph; it is
26943 interpreted in the same way as the value of a `display' text property.
26945 This variable is overridden by any `line-prefix' text or overlay
26948 To add a prefix to continuation lines, use `wrap-prefix'. */);
26949 Vline_prefix
= Qnil
;
26950 staticpro (&Qline_prefix
);
26951 Qline_prefix
= intern_c_string ("line-prefix");
26952 Fmake_variable_buffer_local (Qline_prefix
);
26954 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
26955 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
26956 inhibit_eval_during_redisplay
= 0;
26958 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
26959 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
26960 inhibit_free_realized_faces
= 0;
26963 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
26964 doc
: /* Inhibit try_window_id display optimization. */);
26965 inhibit_try_window_id
= 0;
26967 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
26968 doc
: /* Inhibit try_window_reusing display optimization. */);
26969 inhibit_try_window_reusing
= 0;
26971 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
26972 doc
: /* Inhibit try_cursor_movement display optimization. */);
26973 inhibit_try_cursor_movement
= 0;
26974 #endif /* GLYPH_DEBUG */
26976 DEFVAR_INT ("overline-margin", overline_margin
,
26977 doc
: /* *Space between overline and text, in pixels.
26978 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
26979 margin to the caracter height. */);
26980 overline_margin
= 2;
26982 DEFVAR_INT ("underline-minimum-offset",
26983 underline_minimum_offset
,
26984 doc
: /* Minimum distance between baseline and underline.
26985 This can improve legibility of underlined text at small font sizes,
26986 particularly when using variable `x-use-underline-position-properties'
26987 with fonts that specify an UNDERLINE_POSITION relatively close to the
26988 baseline. The default value is 1. */);
26989 underline_minimum_offset
= 1;
26991 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
26992 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
26993 This feature only works when on a window system that can change
26994 cursor shapes. */);
26995 display_hourglass_p
= 1;
26997 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
26998 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
26999 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27001 hourglass_atimer
= NULL
;
27002 hourglass_shown_p
= 0;
27004 DEFSYM (Qglyphless_char
, "glyphless-char");
27005 DEFSYM (Qhex_code
, "hex-code");
27006 DEFSYM (Qempty_box
, "empty-box");
27007 DEFSYM (Qthin_space
, "thin-space");
27008 DEFSYM (Qzero_width
, "zero-width");
27010 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27011 /* Intern this now in case it isn't already done.
27012 Setting this variable twice is harmless.
27013 But don't staticpro it here--that is done in alloc.c. */
27014 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27015 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27017 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27018 doc
: /* Char-table defining glyphless characters.
27019 Each element, if non-nil, should be one of the following:
27020 an ASCII acronym string: display this string in a box
27021 `hex-code': display the hexadecimal code of a character in a box
27022 `empty-box': display as an empty box
27023 `thin-space': display as 1-pixel width space
27024 `zero-width': don't display
27025 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27026 display method for graphical terminals and text terminals respectively.
27027 GRAPHICAL and TEXT should each have one of the values listed above.
27029 The char-table has one extra slot to control the display of a character for
27030 which no font is found. This slot only takes effect on graphical terminals.
27031 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27032 `thin-space'. The default is `empty-box'. */);
27033 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27034 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27039 /* Initialize this module when Emacs starts. */
27044 Lisp_Object root_window
;
27045 struct window
*mini_w
;
27047 current_header_line_height
= current_mode_line_height
= -1;
27049 CHARPOS (this_line_start_pos
) = 0;
27051 mini_w
= XWINDOW (minibuf_window
);
27052 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27053 echo_area_window
= minibuf_window
;
27055 if (!noninteractive
)
27057 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27060 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27061 set_window_height (root_window
,
27062 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27064 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27065 set_window_height (minibuf_window
, 1, 0);
27067 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27068 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27070 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27071 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27072 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27074 /* The default ellipsis glyphs `...'. */
27075 for (i
= 0; i
< 3; ++i
)
27076 default_invis_vector
[i
] = make_number ('.');
27080 /* Allocate the buffer for frame titles.
27081 Also used for `format-mode-line'. */
27083 mode_line_noprop_buf
= (char *) xmalloc (size
);
27084 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27085 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27086 mode_line_target
= MODE_LINE_DISPLAY
;
27089 help_echo_showing_p
= 0;
27092 /* Since w32 does not support atimers, it defines its own implementation of
27093 the following three functions in w32fns.c. */
27096 /* Platform-independent portion of hourglass implementation. */
27098 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27100 hourglass_started (void)
27102 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27105 /* Cancel a currently active hourglass timer, and start a new one. */
27107 start_hourglass (void)
27109 #if defined (HAVE_WINDOW_SYSTEM)
27111 int secs
, usecs
= 0;
27113 cancel_hourglass ();
27115 if (INTEGERP (Vhourglass_delay
)
27116 && XINT (Vhourglass_delay
) > 0)
27117 secs
= XFASTINT (Vhourglass_delay
);
27118 else if (FLOATP (Vhourglass_delay
)
27119 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27122 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27123 secs
= XFASTINT (tem
);
27124 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27127 secs
= DEFAULT_HOURGLASS_DELAY
;
27129 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27130 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27131 show_hourglass
, NULL
);
27136 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27139 cancel_hourglass (void)
27141 #if defined (HAVE_WINDOW_SYSTEM)
27142 if (hourglass_atimer
)
27144 cancel_atimer (hourglass_atimer
);
27145 hourglass_atimer
= NULL
;
27148 if (hourglass_shown_p
)
27152 #endif /* ! WINDOWSNT */